xref: /trunk/main/drawinglayer/source/primitive3d/baseprimitive3d.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_drawinglayer.hxx"
30 
31 #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
32 #include <drawinglayer/geometry/viewinformation3d.hxx>
33 #include <basegfx/tools/canvastools.hxx>
34 
35 //////////////////////////////////////////////////////////////////////////////
36 
37 using namespace com::sun::star;
38 
39 //////////////////////////////////////////////////////////////////////////////
40 
41 namespace drawinglayer
42 {
43     namespace primitive3d
44     {
45         BasePrimitive3D::BasePrimitive3D()
46         :   BasePrimitive3DImplBase(m_aMutex)
47         {
48         }
49 
50         BasePrimitive3D::~BasePrimitive3D()
51         {
52         }
53 
54         bool BasePrimitive3D::operator==( const BasePrimitive3D& rPrimitive ) const
55         {
56             return (getPrimitive3DID() == rPrimitive.getPrimitive3DID());
57         }
58 
59         basegfx::B3DRange BasePrimitive3D::getB3DRange(const geometry::ViewInformation3D& rViewInformation) const
60         {
61             return getB3DRangeFromPrimitive3DSequence(get3DDecomposition(rViewInformation), rViewInformation);
62         }
63 
64         Primitive3DSequence BasePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
65         {
66             return Primitive3DSequence();
67         }
68 
69         Primitive3DSequence SAL_CALL BasePrimitive3D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
70         {
71             const geometry::ViewInformation3D aViewInformation(rViewParameters);
72             return get3DDecomposition(rViewParameters);
73         }
74 
75         com::sun::star::geometry::RealRectangle3D SAL_CALL BasePrimitive3D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
76         {
77             const geometry::ViewInformation3D aViewInformation(rViewParameters);
78             return basegfx::unotools::rectangle3DFromB3DRectangle(getB3DRange(aViewInformation));
79         }
80     } // end of namespace primitive3d
81 } // end of namespace drawinglayer
82 
83 //////////////////////////////////////////////////////////////////////////////
84 
85 namespace drawinglayer
86 {
87     namespace primitive3d
88     {
89         Primitive3DSequence BufferedDecompositionPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
90         {
91             return Primitive3DSequence();
92         }
93 
94         BufferedDecompositionPrimitive3D::BufferedDecompositionPrimitive3D()
95         :   BasePrimitive3D(),
96             maBuffered3DDecomposition()
97         {
98         }
99 
100         Primitive3DSequence BufferedDecompositionPrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
101         {
102             ::osl::MutexGuard aGuard( m_aMutex );
103 
104             if(!getBuffered3DDecomposition().hasElements())
105             {
106                 const Primitive3DSequence aNewSequence(create3DDecomposition(rViewInformation));
107                 const_cast< BufferedDecompositionPrimitive3D* >(this)->setBuffered3DDecomposition(aNewSequence);
108             }
109 
110             return getBuffered3DDecomposition();
111         }
112     } // end of namespace primitive3d
113 } // end of namespace drawinglayer
114 
115 //////////////////////////////////////////////////////////////////////////////
116 // tooling
117 
118 namespace drawinglayer
119 {
120     namespace primitive3d
121     {
122         // get range3D from a given Primitive3DReference
123         basegfx::B3DRange getB3DRangeFromPrimitive3DReference(const Primitive3DReference& rCandidate, const geometry::ViewInformation3D& aViewInformation)
124         {
125             basegfx::B3DRange aRetval;
126 
127             if(rCandidate.is())
128             {
129                 // try to get C++ implementation base
130                 const BasePrimitive3D* pCandidate(dynamic_cast< BasePrimitive3D* >(rCandidate.get()));
131 
132                 if(pCandidate)
133                 {
134                     // use it if possible
135                     aRetval.expand(pCandidate->getB3DRange(aViewInformation));
136                 }
137                 else
138                 {
139                     // use UNO API call instead
140                     const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence());
141                     aRetval.expand(basegfx::unotools::b3DRectangleFromRealRectangle3D(rCandidate->getRange(rViewParameters)));
142                 }
143             }
144 
145             return aRetval;
146         }
147 
148         // get range3D from a given Primitive3DSequence
149         basegfx::B3DRange getB3DRangeFromPrimitive3DSequence(const Primitive3DSequence& rCandidate, const geometry::ViewInformation3D& aViewInformation)
150         {
151             basegfx::B3DRange aRetval;
152 
153             if(rCandidate.hasElements())
154             {
155                 const sal_Int32 nCount(rCandidate.getLength());
156 
157                 for(sal_Int32 a(0L); a < nCount; a++)
158                 {
159                     aRetval.expand(getB3DRangeFromPrimitive3DReference(rCandidate[a], aViewInformation));
160                 }
161             }
162 
163             return aRetval;
164         }
165 
166         bool arePrimitive3DReferencesEqual(const Primitive3DReference& rxA, const Primitive3DReference& rxB)
167         {
168             const sal_Bool bAIs(rxA.is());
169 
170             if(bAIs != rxB.is())
171             {
172                 return false;
173             }
174 
175             if(!bAIs)
176             {
177                 return true;
178             }
179 
180             const BasePrimitive3D* pA(dynamic_cast< const BasePrimitive3D* >(rxA.get()));
181             const BasePrimitive3D* pB(dynamic_cast< const BasePrimitive3D* >(rxB.get()));
182             const bool bAEqualZero(pA == 0L);
183 
184             if(bAEqualZero != (pB == 0L))
185             {
186                 return false;
187             }
188 
189             if(bAEqualZero)
190             {
191                 return false;
192             }
193 
194             return (pA->operator==(*pB));
195         }
196 
197         bool arePrimitive3DSequencesEqual(const Primitive3DSequence& rA, const Primitive3DSequence& rB)
198         {
199             const sal_Bool bAHasElements(rA.hasElements());
200 
201             if(bAHasElements != rB.hasElements())
202             {
203                 return false;
204             }
205 
206             if(!bAHasElements)
207             {
208                 return true;
209             }
210 
211             const sal_Int32 nCount(rA.getLength());
212 
213             if(nCount != rB.getLength())
214             {
215                 return false;
216             }
217 
218             for(sal_Int32 a(0L); a < nCount; a++)
219             {
220                 if(!arePrimitive3DReferencesEqual(rA[a], rB[a]))
221                 {
222                     return false;
223                 }
224             }
225 
226             return true;
227         }
228 
229         // concatenate sequence
230         void appendPrimitive3DSequenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DSequence& rSource)
231         {
232             if(rSource.hasElements())
233             {
234                 if(rDest.hasElements())
235                 {
236                     const sal_Int32 nSourceCount(rSource.getLength());
237                     const sal_Int32 nDestCount(rDest.getLength());
238                     const sal_Int32 nTargetCount(nSourceCount + nDestCount);
239                     sal_Int32 nInsertPos(nDestCount);
240 
241                     rDest.realloc(nTargetCount);
242 
243                     for(sal_Int32 a(0L); a < nSourceCount; a++)
244                     {
245                         if(rSource[a].is())
246                         {
247                             rDest[nInsertPos++] = rSource[a];
248                         }
249                     }
250 
251                     if(nInsertPos != nTargetCount)
252                     {
253                         rDest.realloc(nInsertPos);
254                     }
255                 }
256                 else
257                 {
258                     rDest = rSource;
259                 }
260             }
261         }
262 
263         // concatenate single Primitive3D
264         void appendPrimitive3DReferenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DReference& rSource)
265         {
266             if(rSource.is())
267             {
268                 const sal_Int32 nDestCount(rDest.getLength());
269                 rDest.realloc(nDestCount + 1L);
270                 rDest[nDestCount] = rSource;
271             }
272         }
273 
274     } // end of namespace primitive3d
275 } // end of namespace drawinglayer
276 
277 //////////////////////////////////////////////////////////////////////////////
278 // eof
279