Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <basegfx/polygon/b2dpolygon.hxx>
31 : : #include <basegfx/polygon/b2dpolygontools.hxx>
32 : :
33 : : #include "svx/polypolygoneditor.hxx"
34 : :
35 : : namespace sdr {
36 : :
37 : 0 : PolyPolygonEditor::PolyPolygonEditor( const basegfx::B2DPolyPolygon& rPolyPolygon, bool bClosed )
38 : : : maPolyPolygon( rPolyPolygon )
39 : 0 : , mbIsClosed( bClosed )
40 : : {
41 : 0 : }
42 : :
43 : 0 : bool PolyPolygonEditor::DeletePoints( const std::set< sal_uInt16 >& rAbsPoints )
44 : : {
45 : 0 : bool bPolyPolyChanged = false;
46 : :
47 [ # # ]: 0 : std::set< sal_uInt16 >::const_reverse_iterator aIter;( rAbsPoints.rbegin() );
48 [ # # ][ # # ]: 0 : for( aIter = rAbsPoints.rbegin(); aIter != rAbsPoints.rend(); ++aIter )
[ # # ]
49 : : {
50 : : sal_uInt32 nPoly, nPnt;
51 [ # # ][ # # ]: 0 : if( GetRelativePolyPoint(maPolyPolygon,(*aIter), nPoly, nPnt) )
[ # # ]
52 : : {
53 : : // remove point
54 [ # # ]: 0 : basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPoly));
55 : :
56 [ # # ]: 0 : aCandidate.remove(nPnt);
57 : :
58 [ # # ][ # # ]: 0 : if( ( mbIsClosed && aCandidate.count() < 3L) || (aCandidate.count() < 2L) )
[ # # ][ # # ]
[ # # ][ # # ]
59 : : {
60 [ # # ]: 0 : maPolyPolygon.remove(nPoly);
61 : : }
62 : : else
63 : : {
64 [ # # ]: 0 : maPolyPolygon.setB2DPolygon(nPoly, aCandidate);
65 : : }
66 : :
67 [ # # ]: 0 : bPolyPolyChanged = true;
68 : : }
69 : : }
70 : :
71 : 0 : return bPolyPolyChanged;
72 : : }
73 : :
74 : 0 : bool PolyPolygonEditor::SetSegmentsKind(SdrPathSegmentKind eKind, const std::set< sal_uInt16 >& rAbsPoints )
75 : : {
76 : 0 : bool bPolyPolyChanged = false;
77 : :
78 [ # # ]: 0 : std::set< sal_uInt16 >::const_reverse_iterator aIter;( rAbsPoints.rbegin() );
79 [ # # ][ # # ]: 0 : for( aIter = rAbsPoints.rbegin(); aIter != rAbsPoints.rend(); ++aIter )
[ # # ]
80 : : {
81 : : sal_uInt32 nPolyNum, nPntNum;
82 : :
83 [ # # ][ # # ]: 0 : if(PolyPolygonEditor::GetRelativePolyPoint(maPolyPolygon, (*aIter), nPolyNum, nPntNum))
[ # # ]
84 : : {
85 : : // do change at aNewPolyPolygon. Take a look at edge.
86 [ # # ]: 0 : basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPolyNum));
87 : 0 : bool bCandidateChanged(false);
88 [ # # ]: 0 : const sal_uInt32 nCount(aCandidate.count());
89 : :
90 [ # # ][ # # ]: 0 : if(nCount && (nPntNum + 1 < nCount || aCandidate.isClosed()))
[ # # ][ # # ]
[ # # ]
91 : : {
92 : : // it's a valid edge, check control point usage
93 : 0 : const sal_uInt32 nNextIndex((nPntNum + 1) % nCount);
94 [ # # ]: 0 : const bool bContolUsed(aCandidate.areControlPointsUsed()
95 [ # # ][ # # ]: 0 : && (aCandidate.isNextControlPointUsed(nPntNum) || aCandidate.isPrevControlPointUsed(nNextIndex)));
[ # # ][ # # ]
[ # # ]
96 : :
97 [ # # ]: 0 : if(bContolUsed)
98 : : {
99 [ # # ][ # # ]: 0 : if(SDRPATHSEGMENT_TOGGLE == eKind || SDRPATHSEGMENT_LINE == eKind)
100 : : {
101 : : // remove control
102 [ # # ]: 0 : aCandidate.resetNextControlPoint(nPntNum);
103 [ # # ]: 0 : aCandidate.resetPrevControlPoint(nNextIndex);
104 : 0 : bCandidateChanged = true;
105 : : }
106 : : }
107 : : else
108 : : {
109 [ # # ][ # # ]: 0 : if(SDRPATHSEGMENT_TOGGLE == eKind || SDRPATHSEGMENT_CURVE == eKind)
110 : : {
111 : : // add control
112 [ # # ]: 0 : const basegfx::B2DPoint aStart(aCandidate.getB2DPoint(nPntNum));
113 [ # # ]: 0 : const basegfx::B2DPoint aEnd(aCandidate.getB2DPoint(nNextIndex));
114 : :
115 [ # # ]: 0 : aCandidate.setNextControlPoint(nPntNum, interpolate(aStart, aEnd, (1.0 / 3.0)));
116 [ # # ]: 0 : aCandidate.setPrevControlPoint(nNextIndex, interpolate(aStart, aEnd, (2.0 / 3.0)));
117 : 0 : bCandidateChanged = true;
118 : : }
119 : : }
120 : :
121 [ # # ]: 0 : if(bCandidateChanged)
122 : : {
123 [ # # ]: 0 : maPolyPolygon.setB2DPolygon(nPolyNum, aCandidate);
124 : 0 : bPolyPolyChanged = true;
125 : : }
126 [ # # ]: 0 : }
127 : : }
128 : : }
129 : :
130 : 0 : return bPolyPolyChanged;
131 : : }
132 : :
133 : 0 : bool PolyPolygonEditor::SetPointsSmooth( basegfx::B2VectorContinuity eFlags, const std::set< sal_uInt16 >& rAbsPoints)
134 : : {
135 : 0 : bool bPolyPolygonChanged(false);
136 : :
137 [ # # ]: 0 : std::set< sal_uInt16 >::const_reverse_iterator aIter;( rAbsPoints.rbegin() );
138 [ # # ][ # # ]: 0 : for( aIter = rAbsPoints.rbegin(); aIter != rAbsPoints.rend(); ++aIter )
[ # # ]
139 : : {
140 : : sal_uInt32 nPolyNum, nPntNum;
141 : :
142 [ # # ][ # # ]: 0 : if(PolyPolygonEditor::GetRelativePolyPoint(maPolyPolygon, (*aIter), nPolyNum, nPntNum))
[ # # ]
143 : : {
144 : : // do change at aNewPolyPolygon...
145 [ # # ]: 0 : basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPolyNum));
146 : :
147 : : // set continuity in point, make sure there is a curve
148 : 0 : bool bPolygonChanged(false);
149 [ # # ]: 0 : bPolygonChanged = basegfx::tools::expandToCurveInPoint(aCandidate, nPntNum);
150 [ # # ]: 0 : bPolygonChanged |= basegfx::tools::setContinuityInPoint(aCandidate, nPntNum, eFlags);
151 : :
152 [ # # ]: 0 : if(bPolygonChanged)
153 : : {
154 [ # # ]: 0 : maPolyPolygon.setB2DPolygon(nPolyNum, aCandidate);
155 : 0 : bPolyPolygonChanged = true;
156 [ # # ]: 0 : }
157 : : }
158 : : }
159 : :
160 : 0 : return bPolyPolygonChanged;
161 : : }
162 : :
163 : 6 : bool PolyPolygonEditor::GetRelativePolyPoint( const basegfx::B2DPolyPolygon& rPoly, sal_uInt32 nAbsPnt, sal_uInt32& rPolyNum, sal_uInt32& rPointNum )
164 : : {
165 : 6 : const sal_uInt32 nPolyCount(rPoly.count());
166 : 6 : sal_uInt32 nPolyNum(0L);
167 : :
168 [ + - ]: 6 : while(nPolyNum < nPolyCount)
169 : : {
170 [ + - ]: 6 : const sal_uInt32 nPointCount(rPoly.getB2DPolygon(nPolyNum).count());
171 : :
172 [ + - ]: 6 : if(nAbsPnt < nPointCount)
173 : : {
174 : 6 : rPolyNum = nPolyNum;
175 : 6 : rPointNum = nAbsPnt;
176 : :
177 : 6 : return true;
178 : : }
179 : : else
180 : : {
181 : 0 : nPolyNum++;
182 : 0 : nAbsPnt -= nPointCount;
183 : : }
184 : : }
185 : :
186 : 6 : return false;
187 : : }
188 : :
189 : : } // end of namespace sdr
190 : :
191 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|