update dev300-m58
[ooovba.git] / basegfx / source / polygon / b3dpolypolygon.cxx
blob4dcc2b2fa36361429874e095d70661cc36865b30
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: b3dpolypolygon.cxx,v $
10 * $Revision: 1.12 $
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_basegfx.hxx"
33 #include <osl/diagnose.h>
34 #include <basegfx/polygon/b3dpolypolygon.hxx>
35 #include <basegfx/polygon/b3dpolygon.hxx>
36 #include <rtl/instance.hxx>
37 #include <basegfx/matrix/b2dhommatrix.hxx>
38 #include <basegfx/matrix/b3dhommatrix.hxx>
39 #include <functional>
40 #include <vector>
41 #include <algorithm>
43 //////////////////////////////////////////////////////////////////////////////
45 class ImplB3DPolyPolygon
47 typedef ::std::vector< ::basegfx::B3DPolygon > PolygonVector;
49 PolygonVector maPolygons;
51 public:
52 ImplB3DPolyPolygon() : maPolygons()
56 ImplB3DPolyPolygon(const ::basegfx::B3DPolygon& rToBeCopied) :
57 maPolygons(1,rToBeCopied)
61 bool operator==(const ImplB3DPolyPolygon& rPolygonList) const
63 // same polygon count?
64 if(maPolygons.size() != rPolygonList.maPolygons.size())
65 return false;
67 // compare polygon content
68 if(maPolygons != rPolygonList.maPolygons)
69 return false;
71 return true;
74 const ::basegfx::B3DPolygon& getB3DPolygon(sal_uInt32 nIndex) const
76 return maPolygons[nIndex];
79 void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon)
81 maPolygons[nIndex] = rPolygon;
84 void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon, sal_uInt32 nCount)
86 if(nCount)
88 // add nCount copies of rPolygon
89 PolygonVector::iterator aIndex(maPolygons.begin());
90 aIndex += nIndex;
91 maPolygons.insert(aIndex, nCount, rPolygon);
95 void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolyPolygon& rPolyPolygon)
97 const sal_uInt32 nCount = rPolyPolygon.count();
99 if(nCount)
101 // add nCount polygons from rPolyPolygon
102 maPolygons.reserve(maPolygons.size() + nCount);
103 PolygonVector::iterator aIndex(maPolygons.begin());
104 aIndex += nIndex;
106 for(sal_uInt32 a(0L); a < nCount; a++)
108 maPolygons.insert(aIndex, rPolyPolygon.getB3DPolygon(a));
109 aIndex++;
114 void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
116 if(nCount)
118 // remove polygon data
119 PolygonVector::iterator aStart(maPolygons.begin());
120 aStart += nIndex;
121 const PolygonVector::iterator aEnd(aStart + nCount);
123 maPolygons.erase(aStart, aEnd);
127 sal_uInt32 count() const
129 return maPolygons.size();
132 void setClosed(bool bNew)
134 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
136 maPolygons[a].setClosed(bNew);
140 void flip()
142 std::for_each( maPolygons.begin(),
143 maPolygons.end(),
144 std::mem_fun_ref( &::basegfx::B3DPolygon::flip ));
147 void removeDoublePoints()
149 std::for_each( maPolygons.begin(),
150 maPolygons.end(),
151 std::mem_fun_ref( &::basegfx::B3DPolygon::removeDoublePoints ));
154 void transform(const ::basegfx::B3DHomMatrix& rMatrix)
156 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
158 maPolygons[a].transform(rMatrix);
162 void clearBColors()
164 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
166 maPolygons[a].clearBColors();
170 void transformNormals(const ::basegfx::B3DHomMatrix& rMatrix)
172 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
174 maPolygons[a].transformNormals(rMatrix);
178 void clearNormals()
180 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
182 maPolygons[a].clearNormals();
186 void transformTextureCoordiantes(const ::basegfx::B2DHomMatrix& rMatrix)
188 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
190 maPolygons[a].transformTextureCoordiantes(rMatrix);
194 void clearTextureCoordinates()
196 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
198 maPolygons[a].clearTextureCoordinates();
202 void makeUnique()
204 std::for_each( maPolygons.begin(),
205 maPolygons.end(),
206 std::mem_fun_ref( &::basegfx::B3DPolygon::makeUnique ));
210 //////////////////////////////////////////////////////////////////////////////
212 namespace basegfx
214 namespace { struct DefaultPolyPolygon : public rtl::Static<B3DPolyPolygon::ImplType,
215 DefaultPolyPolygon> {}; }
217 B3DPolyPolygon::B3DPolyPolygon() :
218 mpPolyPolygon(DefaultPolyPolygon::get())
222 B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon& rPolyPolygon) :
223 mpPolyPolygon(rPolyPolygon.mpPolyPolygon)
227 B3DPolyPolygon::B3DPolyPolygon(const B3DPolygon& rPolygon) :
228 mpPolyPolygon( ImplB3DPolyPolygon(rPolygon) )
232 B3DPolyPolygon::~B3DPolyPolygon()
236 B3DPolyPolygon& B3DPolyPolygon::operator=(const B3DPolyPolygon& rPolyPolygon)
238 mpPolyPolygon = rPolyPolygon.mpPolyPolygon;
239 return *this;
242 void B3DPolyPolygon::makeUnique()
244 mpPolyPolygon.make_unique();
245 mpPolyPolygon->makeUnique();
248 bool B3DPolyPolygon::operator==(const B3DPolyPolygon& rPolyPolygon) const
250 if(mpPolyPolygon.same_object(rPolyPolygon.mpPolyPolygon))
251 return true;
253 return ((*mpPolyPolygon) == (*rPolyPolygon.mpPolyPolygon));
256 bool B3DPolyPolygon::operator!=(const B3DPolyPolygon& rPolyPolygon) const
258 return !(*this == rPolyPolygon);
261 sal_uInt32 B3DPolyPolygon::count() const
263 return mpPolyPolygon->count();
266 B3DPolygon B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex) const
268 OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
270 return mpPolyPolygon->getB3DPolygon(nIndex);
273 void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon)
275 OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
277 if(getB3DPolygon(nIndex) != rPolygon)
278 mpPolyPolygon->setB3DPolygon(nIndex, rPolygon);
281 bool B3DPolyPolygon::areBColorsUsed() const
283 for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
285 if((mpPolyPolygon->getB3DPolygon(a)).areBColorsUsed())
287 return true;
291 return false;
294 void B3DPolyPolygon::clearBColors()
296 if(areBColorsUsed())
297 mpPolyPolygon->clearBColors();
300 void B3DPolyPolygon::transformNormals(const B3DHomMatrix& rMatrix)
302 if(!rMatrix.isIdentity())
303 mpPolyPolygon->transformNormals(rMatrix);
306 bool B3DPolyPolygon::areNormalsUsed() const
308 for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
310 if((mpPolyPolygon->getB3DPolygon(a)).areNormalsUsed())
312 return true;
316 return false;
319 void B3DPolyPolygon::clearNormals()
321 if(areNormalsUsed())
322 mpPolyPolygon->clearNormals();
325 void B3DPolyPolygon::transformTextureCoordiantes(const B2DHomMatrix& rMatrix)
327 if(!rMatrix.isIdentity())
328 mpPolyPolygon->transformTextureCoordiantes(rMatrix);
331 bool B3DPolyPolygon::areTextureCoordinatesUsed() const
333 for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
335 if((mpPolyPolygon->getB3DPolygon(a)).areTextureCoordinatesUsed())
337 return true;
341 return false;
344 void B3DPolyPolygon::clearTextureCoordinates()
346 if(areTextureCoordinatesUsed())
347 mpPolyPolygon->clearTextureCoordinates();
350 void B3DPolyPolygon::insert(sal_uInt32 nIndex, const B3DPolygon& rPolygon, sal_uInt32 nCount)
352 OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B3DPolyPolygon Insert outside range (!)");
354 if(nCount)
355 mpPolyPolygon->insert(nIndex, rPolygon, nCount);
358 void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount)
360 if(nCount)
361 mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount);
364 void B3DPolyPolygon::insert(sal_uInt32 nIndex, const B3DPolyPolygon& rPolyPolygon)
366 OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B3DPolyPolygon Insert outside range (!)");
368 if(rPolyPolygon.count())
369 mpPolyPolygon->insert(nIndex, rPolyPolygon);
372 void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon)
374 if(rPolyPolygon.count())
375 mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon);
378 void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
380 OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B3DPolyPolygon Remove outside range (!)");
382 if(nCount)
383 mpPolyPolygon->remove(nIndex, nCount);
386 void B3DPolyPolygon::clear()
388 mpPolyPolygon = DefaultPolyPolygon::get();
391 bool B3DPolyPolygon::isClosed() const
393 bool bRetval(true);
395 // PolyPOlygon is closed when all contained Polygons are closed or
396 // no Polygon exists.
397 for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++)
399 if(!(mpPolyPolygon->getB3DPolygon(a)).isClosed())
401 bRetval = false;
405 return bRetval;
408 void B3DPolyPolygon::setClosed(bool bNew)
410 if(bNew != isClosed())
411 mpPolyPolygon->setClosed(bNew);
414 void B3DPolyPolygon::flip()
416 mpPolyPolygon->flip();
419 bool B3DPolyPolygon::hasDoublePoints() const
421 bool bRetval(false);
423 for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++)
425 if((mpPolyPolygon->getB3DPolygon(a)).hasDoublePoints())
427 bRetval = true;
431 return bRetval;
434 void B3DPolyPolygon::removeDoublePoints()
436 if(hasDoublePoints())
437 mpPolyPolygon->removeDoublePoints();
440 void B3DPolyPolygon::transform(const B3DHomMatrix& rMatrix)
442 if(mpPolyPolygon->count() && !rMatrix.isIdentity())
444 mpPolyPolygon->transform(rMatrix);
447 } // end of namespace basegfx
449 // eof