Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "fumorph.hxx"
21 : #include <svx/xfillit.hxx>
22 : #include <svx/xlineit.hxx>
23 : #include <vcl/msgbox.hxx>
24 : #include <svx/svdpool.hxx>
25 : #include <tools/poly.hxx>
26 : #include <svx/svdopath.hxx>
27 : #include <svx/svdogrp.hxx>
28 : #include <editeng/eeitem.hxx>
29 :
30 : #include "View.hxx"
31 : #include "ViewShell.hxx"
32 : #include "Window.hxx"
33 : #include <basegfx/polygon/b2dpolygontools.hxx>
34 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
35 : #include <basegfx/matrix/b2dhommatrix.hxx>
36 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
37 :
38 : #include "strings.hrc"
39 : #include "sdresid.hxx"
40 :
41 : #include "sdabstdlg.hxx"
42 :
43 : #include <svx/svditer.hxx>
44 :
45 : #include <basegfx/color/bcolor.hxx>
46 : #include <boost/scoped_ptr.hpp>
47 : #include <com/sun/star/drawing/LineStyle.hpp>
48 :
49 : using namespace com::sun::star;
50 :
51 : namespace sd {
52 :
53 : #define ITEMVALUE( ItemSet, Id, Cast ) ( static_cast<const Cast&>( (ItemSet).Get( (Id) ) ).GetValue() )
54 0 : TYPEINIT1( FuMorph, FuPoor );
55 :
56 0 : FuMorph::FuMorph (
57 : ViewShell* pViewSh,
58 : ::sd::Window* pWin,
59 : ::sd::View* pView,
60 : SdDrawDocument* pDoc,
61 : SfxRequest& rReq )
62 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
63 : {
64 0 : }
65 :
66 0 : rtl::Reference<FuPoor> FuMorph::Create(
67 : ViewShell* pViewSh,
68 : ::sd::Window* pWin,
69 : ::sd::View* pView,
70 : SdDrawDocument* pDoc,
71 : SfxRequest& rReq
72 : )
73 : {
74 0 : rtl::Reference<FuPoor> xFunc( new FuMorph( pViewSh, pWin, pView, pDoc, rReq ) );
75 0 : xFunc->DoExecute(rReq);
76 0 : return xFunc;
77 : }
78 :
79 0 : void FuMorph::DoExecute( SfxRequest& )
80 : {
81 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
82 :
83 0 : if(rMarkList.GetMarkCount() == 2)
84 : {
85 : // create clones
86 0 : SdrObject* pObj1 = rMarkList.GetMark(0)->GetMarkedSdrObj();
87 0 : SdrObject* pObj2 = rMarkList.GetMark(1)->GetMarkedSdrObj();
88 0 : SdrObject* pCloneObj1 = pObj1->Clone();
89 0 : SdrObject* pCloneObj2 = pObj2->Clone();
90 :
91 : // delete text at clone, otherwise we do net get a correct PathObj
92 0 : pCloneObj1->SetOutlinerParaObject(NULL);
93 0 : pCloneObj2->SetOutlinerParaObject(NULL);
94 :
95 : // create path objects
96 0 : SdrObject* pPolyObj1 = pCloneObj1->ConvertToPolyObj(false, false);
97 0 : SdrObject* pPolyObj2 = pCloneObj2->ConvertToPolyObj(false, false);
98 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
99 0 : boost::scoped_ptr<AbstractMorphDlg> pDlg(pFact ? pFact->CreateMorphDlg( static_cast< vcl::Window*>(mpWindow), pObj1, pObj2 ) : 0);
100 0 : if(pPolyObj1 && pPolyObj2 && pDlg && (pDlg->Execute() == RET_OK))
101 : {
102 0 : B2DPolyPolygonList_impl aPolyPolyList;
103 0 : ::basegfx::B2DPolyPolygon aPolyPoly1;
104 0 : ::basegfx::B2DPolyPolygon aPolyPoly2;
105 :
106 0 : pDlg->SaveSettings();
107 :
108 : // #i48168# Not always is the pPolyObj1/pPolyObj2 a SdrPathObj, it may also be a group object
109 : // containing SdrPathObjs. To get the polygons, i add two iters here
110 0 : SdrObjListIter aIter1(*pPolyObj1);
111 0 : SdrObjListIter aIter2(*pPolyObj2);
112 :
113 0 : while(aIter1.IsMore())
114 : {
115 0 : SdrObject* pObj = aIter1.Next();
116 0 : if(pObj && pObj->ISA(SdrPathObj))
117 0 : aPolyPoly1.append(static_cast<SdrPathObj*>(pObj)->GetPathPoly());
118 : }
119 :
120 0 : while(aIter2.IsMore())
121 : {
122 0 : SdrObject* pObj = aIter2.Next();
123 0 : if(pObj && pObj->ISA(SdrPathObj))
124 0 : aPolyPoly2.append(static_cast<SdrPathObj*>(pObj)->GetPathPoly());
125 : }
126 :
127 : // perform morphing
128 0 : if(aPolyPoly1.count() && aPolyPoly2.count())
129 : {
130 0 : aPolyPoly1 = ::basegfx::tools::correctOrientations(aPolyPoly1);
131 0 : aPolyPoly1.removeDoublePoints();
132 0 : ::basegfx::B2VectorOrientation eIsClockwise1(::basegfx::tools::getOrientation(aPolyPoly1.getB2DPolygon(0L)));
133 :
134 0 : aPolyPoly2 = ::basegfx::tools::correctOrientations(aPolyPoly2);
135 0 : aPolyPoly2.removeDoublePoints();
136 0 : ::basegfx::B2VectorOrientation eIsClockwise2(::basegfx::tools::getOrientation(aPolyPoly2.getB2DPolygon(0L)));
137 :
138 : // set same orientation
139 0 : if(eIsClockwise1 != eIsClockwise2)
140 0 : aPolyPoly2.flip();
141 :
142 : // force same poly count
143 0 : if(aPolyPoly1.count() < aPolyPoly2.count())
144 0 : ImpAddPolys(aPolyPoly1, aPolyPoly2);
145 0 : else if(aPolyPoly2.count() < aPolyPoly1.count())
146 0 : ImpAddPolys(aPolyPoly2, aPolyPoly1);
147 :
148 : // use orientation flag from dialog
149 0 : if(!pDlg->IsOrientationFade())
150 0 : aPolyPoly2.flip();
151 :
152 : // force same point counts
153 0 : for( sal_uInt32 a(0L); a < aPolyPoly1.count(); a++ )
154 : {
155 0 : ::basegfx::B2DPolygon aSub1(aPolyPoly1.getB2DPolygon(a));
156 0 : ::basegfx::B2DPolygon aSub2(aPolyPoly2.getB2DPolygon(a));
157 :
158 0 : if(aSub1.count() < aSub2.count())
159 0 : ImpEqualizePolyPointCount(aSub1, aSub2);
160 0 : else if(aSub2.count() < aSub1.count())
161 0 : ImpEqualizePolyPointCount(aSub2, aSub1);
162 :
163 0 : aPolyPoly1.setB2DPolygon(a, aSub1);
164 0 : aPolyPoly2.setB2DPolygon(a, aSub2);
165 0 : }
166 :
167 0 : if(ImpMorphPolygons(aPolyPoly1, aPolyPoly2, pDlg->GetFadeSteps(), aPolyPolyList))
168 : {
169 0 : OUString aString(mpView->GetDescriptionOfMarkedObjects());
170 0 : aString += " " + SD_RESSTR(STR_UNDO_MORPHING);
171 :
172 0 : mpView->BegUndo(aString);
173 0 : ImpInsertPolygons(aPolyPolyList, pDlg->IsAttributeFade(), pObj1, pObj2);
174 0 : mpView->EndUndo();
175 : }
176 :
177 0 : for( size_t i = 0, n = aPolyPolyList.size(); i < n; ++i ) {
178 0 : delete aPolyPolyList[ i ];
179 : }
180 0 : }
181 : }
182 0 : SdrObject::Free( pCloneObj1 );
183 0 : SdrObject::Free( pCloneObj2 );
184 :
185 0 : SdrObject::Free( pPolyObj1 );
186 0 : SdrObject::Free( pPolyObj2 );
187 : }
188 0 : }
189 :
190 0 : ::basegfx::B2DPolygon ImpGetExpandedPolygon(
191 : const ::basegfx::B2DPolygon& rCandidate,
192 : sal_uInt32 nNum
193 : )
194 : {
195 0 : if(rCandidate.count() && nNum && rCandidate.count() != nNum)
196 : {
197 : // length of step in dest poly
198 0 : ::basegfx::B2DPolygon aRetval;
199 0 : const double fStep(::basegfx::tools::getLength(rCandidate) / (double)(rCandidate.isClosed() ? nNum : nNum - 1L));
200 0 : double fDestPos(0.0);
201 0 : double fSrcPos(0.0);
202 0 : sal_uInt32 nSrcPos(0L);
203 0 : sal_uInt32 nSrcPosNext((nSrcPos + 1L == rCandidate.count()) ? 0L : nSrcPos + 1L);
204 0 : double fNextSrcLen(::basegfx::B2DVector(rCandidate.getB2DPoint(nSrcPos) - rCandidate.getB2DPoint(nSrcPosNext)).getLength());
205 :
206 0 : for(sal_uInt32 b(0L); b < nNum; b++)
207 : {
208 : // calc fDestPos in source
209 0 : while(fSrcPos + fNextSrcLen < fDestPos)
210 : {
211 0 : fSrcPos += fNextSrcLen;
212 0 : nSrcPos++;
213 0 : nSrcPosNext = (nSrcPos + 1L == rCandidate.count()) ? 0L : nSrcPos + 1L;
214 0 : fNextSrcLen = ::basegfx::B2DVector(rCandidate.getB2DPoint(nSrcPos) - rCandidate.getB2DPoint(nSrcPosNext)).getLength();
215 : }
216 :
217 : // fDestPos is between fSrcPos and (fSrcPos + fNextSrcLen)
218 0 : const double fLenA((fDestPos - fSrcPos) / fNextSrcLen);
219 0 : const ::basegfx::B2DPoint aOld1(rCandidate.getB2DPoint(nSrcPos));
220 0 : const ::basegfx::B2DPoint aOld2(rCandidate.getB2DPoint(nSrcPosNext));
221 0 : ::basegfx::B2DPoint aNewPoint(basegfx::interpolate(aOld1, aOld2, fLenA));
222 0 : aRetval.append(aNewPoint);
223 :
224 : // next step
225 0 : fDestPos += fStep;
226 0 : }
227 :
228 0 : if(aRetval.count() >= 3L)
229 : {
230 0 : aRetval.setClosed(rCandidate.isClosed());
231 : }
232 :
233 0 : return aRetval;
234 : }
235 : else
236 : {
237 0 : return rCandidate;
238 : }
239 : }
240 :
241 : /**
242 : * make the point count of the polygons equal in adding points
243 : */
244 0 : void FuMorph::ImpEqualizePolyPointCount(
245 : ::basegfx::B2DPolygon& rSmall,
246 : const ::basegfx::B2DPolygon& rBig
247 : )
248 : {
249 : // create poly with equal point count
250 0 : const sal_uInt32 nCnt(rBig.count());
251 0 : ::basegfx::B2DPolygon aPoly1(ImpGetExpandedPolygon(rSmall, nCnt));
252 :
253 : // create transformation for rBig to do the compare
254 0 : const ::basegfx::B2DRange aSrcSize(::basegfx::tools::getRange(rBig));
255 0 : const ::basegfx::B2DPoint aSrcPos(aSrcSize.getCenter());
256 0 : const ::basegfx::B2DRange aDstSize(::basegfx::tools::getRange(rSmall));
257 0 : const ::basegfx::B2DPoint aDstPos(aDstSize.getCenter());
258 :
259 0 : basegfx::B2DHomMatrix aTrans(basegfx::tools::createTranslateB2DHomMatrix(-aSrcPos.getX(), -aSrcPos.getY()));
260 0 : aTrans.scale(aDstSize.getWidth() / aSrcSize.getWidth(), aDstSize.getHeight() / aSrcSize.getHeight());
261 0 : aTrans.translate(aDstPos.getX(), aDstPos.getY());
262 :
263 : // transpose points to have smooth linear blending
264 0 : ::basegfx::B2DPolygon aPoly2;
265 0 : aPoly2.append(::basegfx::B2DPoint(), nCnt);
266 0 : sal_uInt32 nInd(ImpGetNearestIndex(aPoly1, aTrans * rBig.getB2DPoint(0L)));
267 :
268 0 : for(sal_uInt32 a(0L); a < nCnt; a++)
269 : {
270 0 : aPoly2.setB2DPoint((a + nCnt - nInd) % nCnt, aPoly1.getB2DPoint(a));
271 : }
272 :
273 0 : aPoly2.setClosed(rBig.isClosed());
274 0 : rSmall = aPoly2;
275 0 : }
276 :
277 0 : sal_uInt32 FuMorph::ImpGetNearestIndex(
278 : const ::basegfx::B2DPolygon& rPoly,
279 : const ::basegfx::B2DPoint& rPos
280 : )
281 : {
282 0 : double fMinDist = 0.0;
283 0 : sal_uInt32 nActInd = 0;
284 :
285 0 : for(sal_uInt32 a(0L); a < rPoly.count(); a++)
286 : {
287 0 : double fNewDist(::basegfx::B2DVector(rPoly.getB2DPoint(a) - rPos).getLength());
288 :
289 0 : if(!a || fNewDist < fMinDist)
290 : {
291 0 : fMinDist = fNewDist;
292 0 : nActInd = a;
293 : }
294 : }
295 :
296 0 : return nActInd;
297 : }
298 :
299 : /**
300 : * add to a point reduced polys until count is same
301 : */
302 0 : void FuMorph::ImpAddPolys(
303 : ::basegfx::B2DPolyPolygon& rSmaller,
304 : const ::basegfx::B2DPolyPolygon& rBigger
305 : )
306 : {
307 0 : while(rSmaller.count() < rBigger.count())
308 : {
309 0 : const ::basegfx::B2DPolygon aToBeCopied(rBigger.getB2DPolygon(rSmaller.count()));
310 0 : const ::basegfx::B2DRange aToBeCopiedPolySize(::basegfx::tools::getRange(aToBeCopied));
311 0 : ::basegfx::B2DPoint aNewPoint(aToBeCopiedPolySize.getCenter());
312 0 : ::basegfx::B2DPolygon aNewPoly;
313 :
314 0 : const ::basegfx::B2DRange aSrcSize(::basegfx::tools::getRange(rBigger.getB2DPolygon(0L)));
315 0 : const ::basegfx::B2DPoint aSrcPos(aSrcSize.getCenter());
316 0 : const ::basegfx::B2DRange aDstSize(::basegfx::tools::getRange(rSmaller.getB2DPolygon(0L)));
317 0 : const ::basegfx::B2DPoint aDstPos(aDstSize.getCenter());
318 0 : aNewPoint = aNewPoint - aSrcPos + aDstPos;
319 :
320 0 : for(sal_uInt32 a(0L); a < aToBeCopied.count(); a++)
321 : {
322 0 : aNewPoly.append(aNewPoint);
323 : }
324 :
325 0 : rSmaller.append(aNewPoly);
326 0 : }
327 0 : }
328 :
329 : /**
330 : * create group object with morphed polygons
331 : */
332 0 : void FuMorph::ImpInsertPolygons(
333 : B2DPolyPolygonList_impl& rPolyPolyList3D,
334 : bool bAttributeFade,
335 : const SdrObject* pObj1,
336 : const SdrObject* pObj2
337 : )
338 : {
339 0 : Color aStartFillCol;
340 0 : Color aEndFillCol;
341 0 : Color aStartLineCol;
342 0 : Color aEndLineCol;
343 0 : long nStartLineWidth = 0;
344 0 : long nEndLineWidth = 0;
345 0 : SdrPageView* pPageView = mpView->GetSdrPageView();
346 0 : SfxItemPool & pPool = pObj1->GetObjectItemPool();
347 0 : SfxItemSet aSet1( pPool,SDRATTR_START,SDRATTR_NOTPERSIST_FIRST-1,EE_ITEMS_START,EE_ITEMS_END,0 );
348 0 : SfxItemSet aSet2( aSet1 );
349 0 : bool bLineColor = false;
350 0 : bool bFillColor = false;
351 0 : bool bLineWidth = false;
352 0 : bool bIgnoreLine = false;
353 0 : bool bIgnoreFill = false;
354 :
355 0 : aSet1.Put(pObj1->GetMergedItemSet());
356 0 : aSet2.Put(pObj2->GetMergedItemSet());
357 :
358 0 : const drawing::LineStyle eLineStyle1 = ITEMVALUE( aSet1, XATTR_LINESTYLE, XLineStyleItem );
359 0 : const drawing::LineStyle eLineStyle2 = ITEMVALUE( aSet2, XATTR_LINESTYLE, XLineStyleItem );
360 0 : const drawing::FillStyle eFillStyle1 = ITEMVALUE( aSet1, XATTR_FILLSTYLE, XFillStyleItem );
361 0 : const drawing::FillStyle eFillStyle2 = ITEMVALUE( aSet2, XATTR_FILLSTYLE, XFillStyleItem );
362 :
363 0 : if ( bAttributeFade )
364 : {
365 0 : if ( ( eLineStyle1 != drawing::LineStyle_NONE ) && ( eLineStyle2 != drawing::LineStyle_NONE ) )
366 : {
367 0 : bLineWidth = bLineColor = true;
368 :
369 : aStartLineCol = static_cast< XLineColorItem const & >(
370 0 : aSet1.Get(XATTR_LINECOLOR)).GetColorValue();
371 : aEndLineCol = static_cast< XLineColorItem const & >(
372 0 : aSet2.Get(XATTR_LINECOLOR)).GetColorValue();
373 :
374 0 : nStartLineWidth = ITEMVALUE( aSet1, XATTR_LINEWIDTH, XLineWidthItem );
375 0 : nEndLineWidth = ITEMVALUE( aSet2, XATTR_LINEWIDTH, XLineWidthItem );
376 : }
377 0 : else if ( ( eLineStyle1 == drawing::LineStyle_NONE ) && ( eLineStyle2 == drawing::LineStyle_NONE ) )
378 0 : bIgnoreLine = true;
379 :
380 0 : if ( ( eFillStyle1 == drawing::FillStyle_SOLID ) && ( eFillStyle2 == drawing::FillStyle_SOLID ) )
381 : {
382 0 : bFillColor = true;
383 : aStartFillCol = static_cast< XFillColorItem const & >(
384 0 : aSet1.Get(XATTR_FILLCOLOR)).GetColorValue();
385 : aEndFillCol = static_cast< XFillColorItem const & >(
386 0 : aSet2.Get(XATTR_FILLCOLOR)).GetColorValue();
387 : }
388 0 : else if ( ( eFillStyle1 == drawing::FillStyle_NONE ) && ( eFillStyle2 == drawing::FillStyle_NONE ) )
389 0 : bIgnoreFill = true;
390 : }
391 :
392 0 : if ( pPageView )
393 : {
394 0 : SfxItemSet aSet( aSet1 );
395 0 : SdrObjGroup* pObjGroup = new SdrObjGroup;
396 0 : SdrObjList* pObjList = pObjGroup->GetSubList();
397 0 : const size_t nCount = rPolyPolyList3D.size();
398 0 : const double fStep = 1. / ( nCount + 1 );
399 0 : const double fDelta = nEndLineWidth - nStartLineWidth;
400 0 : double fFactor = fStep;
401 :
402 0 : aSet.Put( XLineStyleItem( drawing::LineStyle_SOLID ) );
403 0 : aSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
404 :
405 0 : for ( size_t i = 0; i < nCount; i++, fFactor += fStep )
406 : {
407 0 : const ::basegfx::B2DPolyPolygon& rPolyPoly3D = *rPolyPolyList3D[ i ];
408 0 : SdrPathObj* pNewObj = new SdrPathObj(OBJ_POLY, rPolyPoly3D);
409 :
410 : // line color
411 0 : if ( bLineColor )
412 : {
413 0 : const basegfx::BColor aLineColor(basegfx::interpolate(aStartLineCol.getBColor(), aEndLineCol.getBColor(), fFactor));
414 0 : aSet.Put( XLineColorItem( aEmptyStr, Color(aLineColor)));
415 : }
416 0 : else if ( bIgnoreLine )
417 0 : aSet.Put( XLineStyleItem( drawing::LineStyle_NONE ) );
418 :
419 : // fill color
420 0 : if ( bFillColor )
421 : {
422 0 : const basegfx::BColor aFillColor(basegfx::interpolate(aStartFillCol.getBColor(), aEndFillCol.getBColor(), fFactor));
423 0 : aSet.Put( XFillColorItem( aEmptyStr, Color(aFillColor)));
424 : }
425 0 : else if ( bIgnoreFill )
426 0 : aSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
427 :
428 : // line width
429 0 : if ( bLineWidth )
430 0 : aSet.Put( XLineWidthItem( nStartLineWidth + (long) ( fFactor * fDelta + 0.5 ) ) );
431 :
432 0 : pNewObj->SetMergedItemSetAndBroadcast(aSet);
433 :
434 0 : pObjList->InsertObject( pNewObj );
435 : }
436 :
437 0 : if ( nCount )
438 : {
439 0 : pObjList->InsertObject( pObj1->Clone(), 0 );
440 0 : pObjList->InsertObject( pObj2->Clone() );
441 0 : mpView->DeleteMarked();
442 0 : mpView->InsertObjectAtView( pObjGroup, *pPageView, SdrInsertFlags:: SETDEFLAYER );
443 0 : }
444 0 : }
445 0 : }
446 :
447 : /**
448 : * create single morphed PolyPolygon
449 : */
450 0 : ::basegfx::B2DPolyPolygon* FuMorph::ImpCreateMorphedPolygon(
451 : const ::basegfx::B2DPolyPolygon& rPolyPolyStart,
452 : const ::basegfx::B2DPolyPolygon& rPolyPolyEnd,
453 : double fMorphingFactor
454 : )
455 : {
456 0 : ::basegfx::B2DPolyPolygon* pNewPolyPolygon = new ::basegfx::B2DPolyPolygon();
457 0 : const double fFactor = 1.0 - fMorphingFactor;
458 :
459 0 : for(sal_uInt32 a(0L); a < rPolyPolyStart.count(); a++)
460 : {
461 0 : const ::basegfx::B2DPolygon aPolyStart(rPolyPolyStart.getB2DPolygon(a));
462 0 : const ::basegfx::B2DPolygon aPolyEnd(rPolyPolyEnd.getB2DPolygon(a));
463 0 : const sal_uInt32 nCount(aPolyStart.count());
464 0 : ::basegfx::B2DPolygon aNewPolygon;
465 :
466 0 : for(sal_uInt32 b(0L); b < nCount; b++)
467 : {
468 0 : const ::basegfx::B2DPoint& aPtStart(aPolyStart.getB2DPoint(b));
469 0 : const ::basegfx::B2DPoint& aPtEnd(aPolyEnd.getB2DPoint(b));
470 0 : aNewPolygon.append(aPtEnd + ((aPtStart - aPtEnd) * fFactor));
471 0 : }
472 :
473 0 : aNewPolygon.setClosed(aPolyStart.isClosed() && aPolyEnd.isClosed());
474 0 : pNewPolyPolygon->append(aNewPolygon);
475 0 : }
476 :
477 0 : return pNewPolyPolygon;
478 : }
479 :
480 : /**
481 : * create morphed PolyPolygons
482 : */
483 0 : bool FuMorph::ImpMorphPolygons(
484 : const ::basegfx::B2DPolyPolygon& rPolyPoly1,
485 : const ::basegfx::B2DPolyPolygon& rPolyPoly2,
486 : const sal_uInt16 nSteps,
487 : B2DPolyPolygonList_impl& rPolyPolyList3D
488 : )
489 : {
490 0 : if(nSteps)
491 : {
492 0 : const ::basegfx::B2DRange aStartPolySize(::basegfx::tools::getRange(rPolyPoly1));
493 0 : const ::basegfx::B2DPoint aStartCenter(aStartPolySize.getCenter());
494 0 : const ::basegfx::B2DRange aEndPolySize(::basegfx::tools::getRange(rPolyPoly2));
495 0 : const ::basegfx::B2DPoint aEndCenter(aEndPolySize.getCenter());
496 0 : const ::basegfx::B2DPoint aDelta(aEndCenter - aStartCenter);
497 0 : const double fFactor(1.0 / (nSteps + 1));
498 0 : double fValue(0.0);
499 :
500 0 : for(sal_uInt16 i(0); i < nSteps; i++)
501 : {
502 0 : fValue += fFactor;
503 0 : ::basegfx::B2DPolyPolygon* pNewPolyPoly2D = ImpCreateMorphedPolygon(rPolyPoly1, rPolyPoly2, fValue);
504 :
505 0 : const ::basegfx::B2DRange aNewPolySize(::basegfx::tools::getRange(*pNewPolyPoly2D));
506 0 : const ::basegfx::B2DPoint aNewS(aNewPolySize.getCenter());
507 0 : const ::basegfx::B2DPoint aRealS(aStartCenter + (aDelta * fValue));
508 0 : const ::basegfx::B2DPoint aDiff(aRealS - aNewS);
509 :
510 0 : pNewPolyPoly2D->transform(basegfx::tools::createTranslateB2DHomMatrix(aDiff));
511 0 : rPolyPolyList3D.push_back( pNewPolyPoly2D );
512 0 : }
513 : }
514 0 : return true;
515 : }
516 :
517 66 : } // end of namespace sd
518 :
519 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|