1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <osl/diagnose.h>
21 #include <basegfx/polygon/b3dpolypolygon.hxx>
22 #include <basegfx/polygon/b3dpolygon.hxx>
23 #include <rtl/instance.hxx>
24 #include <basegfx/matrix/b2dhommatrix.hxx>
25 #include <basegfx/matrix/b3dhommatrix.hxx>
30 //////////////////////////////////////////////////////////////////////////////
32 class ImplB3DPolyPolygon
34 typedef ::std::vector
< ::basegfx::B3DPolygon
> PolygonVector
;
36 PolygonVector maPolygons
;
39 ImplB3DPolyPolygon() : maPolygons()
43 explicit ImplB3DPolyPolygon(const ::basegfx::B3DPolygon
& rToBeCopied
) :
44 maPolygons(1,rToBeCopied
)
48 bool operator==(const ImplB3DPolyPolygon
& rPolygonList
) const
50 // same polygon count?
51 if(maPolygons
.size() != rPolygonList
.maPolygons
.size())
54 // compare polygon content
55 if(maPolygons
!= rPolygonList
.maPolygons
)
61 const ::basegfx::B3DPolygon
& getB3DPolygon(sal_uInt32 nIndex
) const
63 return maPolygons
[nIndex
];
66 void setB3DPolygon(sal_uInt32 nIndex
, const ::basegfx::B3DPolygon
& rPolygon
)
68 maPolygons
[nIndex
] = rPolygon
;
71 void insert(sal_uInt32 nIndex
, const ::basegfx::B3DPolygon
& rPolygon
, sal_uInt32 nCount
)
75 // add nCount copies of rPolygon
76 PolygonVector::iterator
aIndex(maPolygons
.begin());
79 maPolygons
.insert(aIndex
, nCount
, rPolygon
);
83 void insert(sal_uInt32 nIndex
, const ::basegfx::B3DPolyPolygon
& rPolyPolygon
)
85 // add all polygons from rPolyPolygon
86 PolygonVector::iterator
aIndex(maPolygons
.begin());
89 maPolygons
.insert(aIndex
, rPolyPolygon
.begin(), rPolyPolygon
.end());
92 void remove(sal_uInt32 nIndex
, sal_uInt32 nCount
)
96 // remove polygon data
97 PolygonVector::iterator
aStart(maPolygons
.begin());
99 const PolygonVector::iterator
aEnd(aStart
+ nCount
);
101 maPolygons
.erase(aStart
, aEnd
);
105 sal_uInt32
count() const
107 return maPolygons
.size();
110 void setClosed(bool bNew
)
112 for(sal_uInt32
a(0L); a
< maPolygons
.size(); a
++)
114 maPolygons
[a
].setClosed(bNew
);
120 std::for_each( maPolygons
.begin(),
122 std::mem_fun_ref( &::basegfx::B3DPolygon::flip
));
125 void removeDoublePoints()
127 std::for_each( maPolygons
.begin(),
129 std::mem_fun_ref( &::basegfx::B3DPolygon::removeDoublePoints
));
132 void transform(const ::basegfx::B3DHomMatrix
& rMatrix
)
134 for(sal_uInt32
a(0L); a
< maPolygons
.size(); a
++)
136 maPolygons
[a
].transform(rMatrix
);
142 for(sal_uInt32
a(0L); a
< maPolygons
.size(); a
++)
144 maPolygons
[a
].clearBColors();
148 void transformNormals(const ::basegfx::B3DHomMatrix
& rMatrix
)
150 for(sal_uInt32
a(0L); a
< maPolygons
.size(); a
++)
152 maPolygons
[a
].transformNormals(rMatrix
);
158 for(sal_uInt32
a(0L); a
< maPolygons
.size(); a
++)
160 maPolygons
[a
].clearNormals();
164 void transformTextureCoordiantes(const ::basegfx::B2DHomMatrix
& rMatrix
)
166 for(sal_uInt32
a(0L); a
< maPolygons
.size(); a
++)
168 maPolygons
[a
].transformTextureCoordiantes(rMatrix
);
172 void clearTextureCoordinates()
174 for(sal_uInt32
a(0L); a
< maPolygons
.size(); a
++)
176 maPolygons
[a
].clearTextureCoordinates();
180 const basegfx::B3DPolygon
* begin() const
182 if(maPolygons
.empty())
185 return &maPolygons
.front();
188 const basegfx::B3DPolygon
* end() const
190 if(maPolygons
.empty())
193 return (&maPolygons
.back())+1;
196 basegfx::B3DPolygon
* begin()
198 if(maPolygons
.empty())
201 return &maPolygons
.front();
204 basegfx::B3DPolygon
* end()
206 if(maPolygons
.empty())
209 return &(maPolygons
.back())+1;
213 //////////////////////////////////////////////////////////////////////////////
217 namespace { struct DefaultPolyPolygon
: public rtl::Static
<B3DPolyPolygon::ImplType
,
218 DefaultPolyPolygon
> {}; }
220 B3DPolyPolygon::B3DPolyPolygon() :
221 mpPolyPolygon(DefaultPolyPolygon::get())
225 B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon
& rPolyPolygon
) :
226 mpPolyPolygon(rPolyPolygon
.mpPolyPolygon
)
230 B3DPolyPolygon::B3DPolyPolygon(const B3DPolygon
& rPolygon
) :
231 mpPolyPolygon( ImplB3DPolyPolygon(rPolygon
) )
235 B3DPolyPolygon::~B3DPolyPolygon()
239 B3DPolyPolygon
& B3DPolyPolygon::operator=(const B3DPolyPolygon
& rPolyPolygon
)
241 mpPolyPolygon
= rPolyPolygon
.mpPolyPolygon
;
245 bool B3DPolyPolygon::operator==(const B3DPolyPolygon
& rPolyPolygon
) const
247 if(mpPolyPolygon
.same_object(rPolyPolygon
.mpPolyPolygon
))
250 return ((*mpPolyPolygon
) == (*rPolyPolygon
.mpPolyPolygon
));
253 bool B3DPolyPolygon::operator!=(const B3DPolyPolygon
& rPolyPolygon
) const
255 return !(*this == rPolyPolygon
);
258 sal_uInt32
B3DPolyPolygon::count() const
260 return mpPolyPolygon
->count();
263 B3DPolygon
B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex
) const
265 OSL_ENSURE(nIndex
< mpPolyPolygon
->count(), "B3DPolyPolygon access outside range (!)");
267 return mpPolyPolygon
->getB3DPolygon(nIndex
);
270 void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex
, const B3DPolygon
& rPolygon
)
272 OSL_ENSURE(nIndex
< mpPolyPolygon
->count(), "B3DPolyPolygon access outside range (!)");
274 if(getB3DPolygon(nIndex
) != rPolygon
)
275 mpPolyPolygon
->setB3DPolygon(nIndex
, rPolygon
);
278 bool B3DPolyPolygon::areBColorsUsed() const
280 for(sal_uInt32
a(0L); a
< mpPolyPolygon
->count(); a
++)
282 if((mpPolyPolygon
->getB3DPolygon(a
)).areBColorsUsed())
291 void B3DPolyPolygon::clearBColors()
294 mpPolyPolygon
->clearBColors();
297 void B3DPolyPolygon::transformNormals(const B3DHomMatrix
& rMatrix
)
299 if(!rMatrix
.isIdentity())
300 mpPolyPolygon
->transformNormals(rMatrix
);
303 bool B3DPolyPolygon::areNormalsUsed() const
305 for(sal_uInt32
a(0L); a
< mpPolyPolygon
->count(); a
++)
307 if((mpPolyPolygon
->getB3DPolygon(a
)).areNormalsUsed())
316 void B3DPolyPolygon::clearNormals()
319 mpPolyPolygon
->clearNormals();
322 void B3DPolyPolygon::transformTextureCoordiantes(const B2DHomMatrix
& rMatrix
)
324 if(!rMatrix
.isIdentity())
325 mpPolyPolygon
->transformTextureCoordiantes(rMatrix
);
328 bool B3DPolyPolygon::areTextureCoordinatesUsed() const
330 for(sal_uInt32
a(0L); a
< mpPolyPolygon
->count(); a
++)
332 if((mpPolyPolygon
->getB3DPolygon(a
)).areTextureCoordinatesUsed())
341 void B3DPolyPolygon::clearTextureCoordinates()
343 if(areTextureCoordinatesUsed())
344 mpPolyPolygon
->clearTextureCoordinates();
347 void B3DPolyPolygon::append(const B3DPolygon
& rPolygon
, sal_uInt32 nCount
)
350 mpPolyPolygon
->insert(mpPolyPolygon
->count(), rPolygon
, nCount
);
353 void B3DPolyPolygon::append(const B3DPolyPolygon
& rPolyPolygon
)
355 if(rPolyPolygon
.count())
356 mpPolyPolygon
->insert(mpPolyPolygon
->count(), rPolyPolygon
);
359 void B3DPolyPolygon::remove(sal_uInt32 nIndex
, sal_uInt32 nCount
)
361 OSL_ENSURE(nIndex
+ nCount
<= mpPolyPolygon
->count(), "B3DPolyPolygon Remove outside range (!)");
364 mpPolyPolygon
->remove(nIndex
, nCount
);
367 void B3DPolyPolygon::clear()
369 mpPolyPolygon
= DefaultPolyPolygon::get();
372 void B3DPolyPolygon::flip()
374 mpPolyPolygon
->flip();
377 bool B3DPolyPolygon::hasDoublePoints() const
381 for(sal_uInt32
a(0L); !bRetval
&& a
< mpPolyPolygon
->count(); a
++)
383 if((mpPolyPolygon
->getB3DPolygon(a
)).hasDoublePoints())
392 void B3DPolyPolygon::removeDoublePoints()
394 if(hasDoublePoints())
395 mpPolyPolygon
->removeDoublePoints();
398 void B3DPolyPolygon::transform(const B3DHomMatrix
& rMatrix
)
400 if(mpPolyPolygon
->count() && !rMatrix
.isIdentity())
402 mpPolyPolygon
->transform(rMatrix
);
406 const B3DPolygon
* B3DPolyPolygon::begin() const
408 return mpPolyPolygon
->begin();
411 const B3DPolygon
* B3DPolyPolygon::end() const
413 return mpPolyPolygon
->end();
416 B3DPolygon
* B3DPolyPolygon::begin()
418 return mpPolyPolygon
->begin();
421 B3DPolygon
* B3DPolyPolygon::end()
423 return mpPolyPolygon
->end();
425 } // end of namespace basegfx
427 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */