1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: polypolygoneditor.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <basegfx/polygon/b2dpolygon.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
37 #include "svx/polypolygoneditor.hxx"
41 PolyPolygonEditor::PolyPolygonEditor( const basegfx::B2DPolyPolygon
& rPolyPolygon
, bool bClosed
)
42 : maPolyPolygon( rPolyPolygon
)
43 , mbIsClosed( bClosed
)
47 bool PolyPolygonEditor::DeletePoints( const std::set
< sal_uInt16
>& rAbsPoints
)
49 bool bPolyPolyChanged
= false;
51 std::set
< sal_uInt16
>::const_reverse_iterator aIter
;( rAbsPoints
.rbegin() );
52 for( aIter
= rAbsPoints
.rbegin(); aIter
!= rAbsPoints
.rend(); aIter
++ )
54 sal_uInt32 nPoly
, nPnt
;
55 if( GetRelativePolyPoint(maPolyPolygon
,(*aIter
), nPoly
, nPnt
) )
58 basegfx::B2DPolygon
aCandidate(maPolyPolygon
.getB2DPolygon(nPoly
));
60 aCandidate
.remove(nPnt
);
62 if( ( mbIsClosed
&& aCandidate
.count() < 3L) || (aCandidate
.count() < 2L) )
64 maPolyPolygon
.remove(nPoly
);
68 maPolyPolygon
.setB2DPolygon(nPoly
, aCandidate
);
71 bPolyPolyChanged
= true;
75 return bPolyPolyChanged
;
78 bool PolyPolygonEditor::SetSegmentsKind(SdrPathSegmentKind eKind
, const std::set
< sal_uInt16
>& rAbsPoints
)
80 bool bPolyPolyChanged
= false;
82 std::set
< sal_uInt16
>::const_reverse_iterator aIter
;( rAbsPoints
.rbegin() );
83 for( aIter
= rAbsPoints
.rbegin(); aIter
!= rAbsPoints
.rend(); aIter
++ )
85 sal_uInt32 nPolyNum
, nPntNum
;
87 if(PolyPolygonEditor::GetRelativePolyPoint(maPolyPolygon
, (*aIter
), nPolyNum
, nPntNum
))
89 // do change at aNewPolyPolygon. Take a look at edge.
90 basegfx::B2DPolygon
aCandidate(maPolyPolygon
.getB2DPolygon(nPolyNum
));
91 bool bCandidateChanged(false);
92 const sal_uInt32
nCount(aCandidate
.count());
94 if(nCount
&& (nPntNum
+ 1 < nCount
|| aCandidate
.isClosed()))
96 // it's a valid edge, check control point usage
97 const sal_uInt32
nNextIndex((nPntNum
+ 1) % nCount
);
98 const bool bContolUsed(aCandidate
.areControlPointsUsed()
99 && (aCandidate
.isNextControlPointUsed(nPntNum
) || aCandidate
.isPrevControlPointUsed(nNextIndex
)));
103 if(SDRPATHSEGMENT_TOGGLE
== eKind
|| SDRPATHSEGMENT_LINE
== eKind
)
106 aCandidate
.resetNextControlPoint(nPntNum
);
107 aCandidate
.resetPrevControlPoint(nNextIndex
);
108 bCandidateChanged
= true;
113 if(SDRPATHSEGMENT_TOGGLE
== eKind
|| SDRPATHSEGMENT_CURVE
== eKind
)
116 const basegfx::B2DPoint
aStart(aCandidate
.getB2DPoint(nPntNum
));
117 const basegfx::B2DPoint
aEnd(aCandidate
.getB2DPoint(nNextIndex
));
119 aCandidate
.setNextControlPoint(nPntNum
, interpolate(aStart
, aEnd
, (1.0 / 3.0)));
120 aCandidate
.setPrevControlPoint(nNextIndex
, interpolate(aStart
, aEnd
, (2.0 / 3.0)));
121 bCandidateChanged
= true;
125 if(bCandidateChanged
)
127 maPolyPolygon
.setB2DPolygon(nPolyNum
, aCandidate
);
128 bPolyPolyChanged
= true;
134 return bPolyPolyChanged
;
137 bool PolyPolygonEditor::SetPointsSmooth( basegfx::B2VectorContinuity eFlags
, const std::set
< sal_uInt16
>& rAbsPoints
)
139 bool bPolyPolygonChanged(false);
141 std::set
< sal_uInt16
>::const_reverse_iterator aIter
;( rAbsPoints
.rbegin() );
142 for( aIter
= rAbsPoints
.rbegin(); aIter
!= rAbsPoints
.rend(); aIter
++ )
144 sal_uInt32 nPolyNum
, nPntNum
;
146 if(PolyPolygonEditor::GetRelativePolyPoint(maPolyPolygon
, (*aIter
), nPolyNum
, nPntNum
))
148 // do change at aNewPolyPolygon...
149 basegfx::B2DPolygon
aCandidate(maPolyPolygon
.getB2DPolygon(nPolyNum
));
151 // set continuity in point, make sure there is a curve
152 bool bPolygonChanged(false);
153 bPolygonChanged
= basegfx::tools::expandToCurveInPoint(aCandidate
, nPntNum
);
154 bPolygonChanged
|= basegfx::tools::setContinuityInPoint(aCandidate
, nPntNum
, eFlags
);
158 maPolyPolygon
.setB2DPolygon(nPolyNum
, aCandidate
);
159 bPolyPolygonChanged
= true;
164 return bPolyPolygonChanged
;
167 bool PolyPolygonEditor::GetRelativePolyPoint( const basegfx::B2DPolyPolygon
& rPoly
, sal_uInt32 nAbsPnt
, sal_uInt32
& rPolyNum
, sal_uInt32
& rPointNum
)
169 const sal_uInt32
nPolyCount(rPoly
.count());
170 sal_uInt32
nPolyNum(0L);
172 while(nPolyNum
< nPolyCount
)
174 const sal_uInt32
nPointCount(rPoly
.getB2DPolygon(nPolyNum
).count());
176 if(nAbsPnt
< nPointCount
)
186 nAbsPnt
-= nPointCount
;
193 } // end of namespace sdr