Bump for 3.6-28
[LibreOffice.git] / drawinglayer / source / primitive3d / baseprimitive3d.cxx
blob6f51aaa5dd861c98352a9bc338804c538ccaf003
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
30 #include <drawinglayer/geometry/viewinformation3d.hxx>
31 #include <basegfx/tools/canvastools.hxx>
33 //////////////////////////////////////////////////////////////////////////////
35 using namespace com::sun::star;
37 //////////////////////////////////////////////////////////////////////////////
39 namespace drawinglayer
41 namespace primitive3d
43 BasePrimitive3D::BasePrimitive3D()
44 : BasePrimitive3DImplBase(m_aMutex)
48 BasePrimitive3D::~BasePrimitive3D()
52 bool BasePrimitive3D::operator==( const BasePrimitive3D& rPrimitive ) const
54 return (getPrimitive3DID() == rPrimitive.getPrimitive3DID());
57 basegfx::B3DRange BasePrimitive3D::getB3DRange(const geometry::ViewInformation3D& rViewInformation) const
59 return getB3DRangeFromPrimitive3DSequence(get3DDecomposition(rViewInformation), rViewInformation);
62 Primitive3DSequence BasePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
64 return Primitive3DSequence();
67 Primitive3DSequence SAL_CALL BasePrimitive3D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
69 const geometry::ViewInformation3D aViewInformation(rViewParameters);
70 return get3DDecomposition(rViewParameters);
73 com::sun::star::geometry::RealRectangle3D SAL_CALL BasePrimitive3D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
75 const geometry::ViewInformation3D aViewInformation(rViewParameters);
76 return basegfx::unotools::rectangle3DFromB3DRectangle(getB3DRange(aViewInformation));
78 } // end of namespace primitive3d
79 } // end of namespace drawinglayer
81 //////////////////////////////////////////////////////////////////////////////
83 namespace drawinglayer
85 namespace primitive3d
87 Primitive3DSequence BufferedDecompositionPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
89 return Primitive3DSequence();
92 BufferedDecompositionPrimitive3D::BufferedDecompositionPrimitive3D()
93 : BasePrimitive3D(),
94 maBuffered3DDecomposition()
98 Primitive3DSequence BufferedDecompositionPrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
100 ::osl::MutexGuard aGuard( m_aMutex );
102 if(!getBuffered3DDecomposition().hasElements())
104 const Primitive3DSequence aNewSequence(create3DDecomposition(rViewInformation));
105 const_cast< BufferedDecompositionPrimitive3D* >(this)->setBuffered3DDecomposition(aNewSequence);
108 return getBuffered3DDecomposition();
110 } // end of namespace primitive3d
111 } // end of namespace drawinglayer
113 //////////////////////////////////////////////////////////////////////////////
114 // tooling
116 namespace drawinglayer
118 namespace primitive3d
120 // get range3D from a given Primitive3DReference
121 basegfx::B3DRange getB3DRangeFromPrimitive3DReference(const Primitive3DReference& rCandidate, const geometry::ViewInformation3D& aViewInformation)
123 basegfx::B3DRange aRetval;
125 if(rCandidate.is())
127 // try to get C++ implementation base
128 const BasePrimitive3D* pCandidate(dynamic_cast< BasePrimitive3D* >(rCandidate.get()));
130 if(pCandidate)
132 // use it if possible
133 aRetval.expand(pCandidate->getB3DRange(aViewInformation));
135 else
137 // use UNO API call instead
138 const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence());
139 aRetval.expand(basegfx::unotools::b3DRectangleFromRealRectangle3D(rCandidate->getRange(rViewParameters)));
143 return aRetval;
146 // get range3D from a given Primitive3DSequence
147 basegfx::B3DRange getB3DRangeFromPrimitive3DSequence(const Primitive3DSequence& rCandidate, const geometry::ViewInformation3D& aViewInformation)
149 basegfx::B3DRange aRetval;
151 if(rCandidate.hasElements())
153 const sal_Int32 nCount(rCandidate.getLength());
155 for(sal_Int32 a(0L); a < nCount; a++)
157 aRetval.expand(getB3DRangeFromPrimitive3DReference(rCandidate[a], aViewInformation));
161 return aRetval;
164 bool arePrimitive3DReferencesEqual(const Primitive3DReference& rxA, const Primitive3DReference& rxB)
166 const sal_Bool bAIs(rxA.is());
168 if(bAIs != rxB.is())
170 return false;
173 if(!bAIs)
175 return true;
178 const BasePrimitive3D* pA(dynamic_cast< const BasePrimitive3D* >(rxA.get()));
179 const BasePrimitive3D* pB(dynamic_cast< const BasePrimitive3D* >(rxB.get()));
180 const bool bAEqualZero(pA == 0L);
182 if(bAEqualZero != (pB == 0L))
184 return false;
187 if(bAEqualZero)
189 return false;
192 return (pA->operator==(*pB));
195 bool arePrimitive3DSequencesEqual(const Primitive3DSequence& rA, const Primitive3DSequence& rB)
197 const sal_Bool bAHasElements(rA.hasElements());
199 if(bAHasElements != rB.hasElements())
201 return false;
204 if(!bAHasElements)
206 return true;
209 const sal_Int32 nCount(rA.getLength());
211 if(nCount != rB.getLength())
213 return false;
216 for(sal_Int32 a(0L); a < nCount; a++)
218 if(!arePrimitive3DReferencesEqual(rA[a], rB[a]))
220 return false;
224 return true;
227 // concatenate sequence
228 void appendPrimitive3DSequenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DSequence& rSource)
230 if(rSource.hasElements())
232 if(rDest.hasElements())
234 const sal_Int32 nSourceCount(rSource.getLength());
235 const sal_Int32 nDestCount(rDest.getLength());
236 const sal_Int32 nTargetCount(nSourceCount + nDestCount);
237 sal_Int32 nInsertPos(nDestCount);
239 rDest.realloc(nTargetCount);
241 for(sal_Int32 a(0L); a < nSourceCount; a++)
243 if(rSource[a].is())
245 rDest[nInsertPos++] = rSource[a];
249 if(nInsertPos != nTargetCount)
251 rDest.realloc(nInsertPos);
254 else
256 rDest = rSource;
261 // concatenate single Primitive3D
262 void appendPrimitive3DReferenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DReference& rSource)
264 if(rSource.is())
266 const sal_Int32 nDestCount(rDest.getLength());
267 rDest.realloc(nDestCount + 1L);
268 rDest[nDestCount] = rSource;
272 } // end of namespace primitive3d
273 } // end of namespace drawinglayer
275 //////////////////////////////////////////////////////////////////////////////
276 // eof
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */