xref: /AOO41X/main/drawinglayer/source/primitive3d/baseprimitive3d.cxx (revision 464702f4578bd67db020a330afd07883930c5e07)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_drawinglayer.hxx"
26 
27 #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
28 #include <drawinglayer/geometry/viewinformation3d.hxx>
29 #include <basegfx/tools/canvastools.hxx>
30 
31 //////////////////////////////////////////////////////////////////////////////
32 
33 using namespace com::sun::star;
34 
35 //////////////////////////////////////////////////////////////////////////////
36 
37 namespace drawinglayer
38 {
39     namespace primitive3d
40     {
BasePrimitive3D()41         BasePrimitive3D::BasePrimitive3D()
42         :   BasePrimitive3DImplBase(m_aMutex)
43         {
44         }
45 
~BasePrimitive3D()46         BasePrimitive3D::~BasePrimitive3D()
47         {
48         }
49 
operator ==(const BasePrimitive3D & rPrimitive) const50         bool BasePrimitive3D::operator==( const BasePrimitive3D& rPrimitive ) const
51         {
52             return (getPrimitive3DID() == rPrimitive.getPrimitive3DID());
53         }
54 
getB3DRange(const geometry::ViewInformation3D & rViewInformation) const55         basegfx::B3DRange BasePrimitive3D::getB3DRange(const geometry::ViewInformation3D& rViewInformation) const
56         {
57             return getB3DRangeFromPrimitive3DSequence(get3DDecomposition(rViewInformation), rViewInformation);
58         }
59 
get3DDecomposition(const geometry::ViewInformation3D &) const60         Primitive3DSequence BasePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
61         {
62             return Primitive3DSequence();
63         }
64 
getDecomposition(const uno::Sequence<beans::PropertyValue> & rViewParameters)65         Primitive3DSequence SAL_CALL BasePrimitive3D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
66         {
67             const geometry::ViewInformation3D aViewInformation(rViewParameters);
68             return get3DDecomposition(rViewParameters);
69         }
70 
getRange(const uno::Sequence<beans::PropertyValue> & rViewParameters)71         com::sun::star::geometry::RealRectangle3D SAL_CALL BasePrimitive3D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
72         {
73             const geometry::ViewInformation3D aViewInformation(rViewParameters);
74             return basegfx::unotools::rectangle3DFromB3DRectangle(getB3DRange(aViewInformation));
75         }
76     } // end of namespace primitive3d
77 } // end of namespace drawinglayer
78 
79 //////////////////////////////////////////////////////////////////////////////
80 
81 namespace drawinglayer
82 {
83     namespace primitive3d
84     {
create3DDecomposition(const geometry::ViewInformation3D &) const85         Primitive3DSequence BufferedDecompositionPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
86         {
87             return Primitive3DSequence();
88         }
89 
BufferedDecompositionPrimitive3D()90         BufferedDecompositionPrimitive3D::BufferedDecompositionPrimitive3D()
91         :   BasePrimitive3D(),
92             maBuffered3DDecomposition()
93         {
94         }
95 
get3DDecomposition(const geometry::ViewInformation3D & rViewInformation) const96         Primitive3DSequence BufferedDecompositionPrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
97         {
98             ::osl::MutexGuard aGuard( m_aMutex );
99 
100             if(!getBuffered3DDecomposition().hasElements())
101             {
102                 const Primitive3DSequence aNewSequence(create3DDecomposition(rViewInformation));
103                 const_cast< BufferedDecompositionPrimitive3D* >(this)->setBuffered3DDecomposition(aNewSequence);
104             }
105 
106             return getBuffered3DDecomposition();
107         }
108     } // end of namespace primitive3d
109 } // end of namespace drawinglayer
110 
111 //////////////////////////////////////////////////////////////////////////////
112 // tooling
113 
114 namespace drawinglayer
115 {
116     namespace primitive3d
117     {
118         // get range3D from a given Primitive3DReference
getB3DRangeFromPrimitive3DReference(const Primitive3DReference & rCandidate,const geometry::ViewInformation3D & aViewInformation)119         basegfx::B3DRange getB3DRangeFromPrimitive3DReference(const Primitive3DReference& rCandidate, const geometry::ViewInformation3D& aViewInformation)
120         {
121             basegfx::B3DRange aRetval;
122 
123             if(rCandidate.is())
124             {
125                 // try to get C++ implementation base
126                 const BasePrimitive3D* pCandidate(dynamic_cast< BasePrimitive3D* >(rCandidate.get()));
127 
128                 if(pCandidate)
129                 {
130                     // use it if possible
131                     aRetval.expand(pCandidate->getB3DRange(aViewInformation));
132                 }
133                 else
134                 {
135                     // use UNO API call instead
136                     const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence());
137                     aRetval.expand(basegfx::unotools::b3DRectangleFromRealRectangle3D(rCandidate->getRange(rViewParameters)));
138                 }
139             }
140 
141             return aRetval;
142         }
143 
144         // get range3D from a given Primitive3DSequence
getB3DRangeFromPrimitive3DSequence(const Primitive3DSequence & rCandidate,const geometry::ViewInformation3D & aViewInformation)145         basegfx::B3DRange getB3DRangeFromPrimitive3DSequence(const Primitive3DSequence& rCandidate, const geometry::ViewInformation3D& aViewInformation)
146         {
147             basegfx::B3DRange aRetval;
148 
149             if(rCandidate.hasElements())
150             {
151                 const sal_Int32 nCount(rCandidate.getLength());
152 
153                 for(sal_Int32 a(0L); a < nCount; a++)
154                 {
155                     aRetval.expand(getB3DRangeFromPrimitive3DReference(rCandidate[a], aViewInformation));
156                 }
157             }
158 
159             return aRetval;
160         }
161 
arePrimitive3DReferencesEqual(const Primitive3DReference & rxA,const Primitive3DReference & rxB)162         bool arePrimitive3DReferencesEqual(const Primitive3DReference& rxA, const Primitive3DReference& rxB)
163         {
164             const sal_Bool bAIs(rxA.is());
165 
166             if(bAIs != rxB.is())
167             {
168                 return false;
169             }
170 
171             if(!bAIs)
172             {
173                 return true;
174             }
175 
176             const BasePrimitive3D* pA(dynamic_cast< const BasePrimitive3D* >(rxA.get()));
177             const BasePrimitive3D* pB(dynamic_cast< const BasePrimitive3D* >(rxB.get()));
178             const bool bAEqualZero(pA == 0L);
179 
180             if(bAEqualZero != (pB == 0L))
181             {
182                 return false;
183             }
184 
185             if(bAEqualZero)
186             {
187                 return false;
188             }
189 
190             return (pA->operator==(*pB));
191         }
192 
arePrimitive3DSequencesEqual(const Primitive3DSequence & rA,const Primitive3DSequence & rB)193         bool arePrimitive3DSequencesEqual(const Primitive3DSequence& rA, const Primitive3DSequence& rB)
194         {
195             const sal_Bool bAHasElements(rA.hasElements());
196 
197             if(bAHasElements != rB.hasElements())
198             {
199                 return false;
200             }
201 
202             if(!bAHasElements)
203             {
204                 return true;
205             }
206 
207             const sal_Int32 nCount(rA.getLength());
208 
209             if(nCount != rB.getLength())
210             {
211                 return false;
212             }
213 
214             for(sal_Int32 a(0L); a < nCount; a++)
215             {
216                 if(!arePrimitive3DReferencesEqual(rA[a], rB[a]))
217                 {
218                     return false;
219                 }
220             }
221 
222             return true;
223         }
224 
225         // concatenate sequence
appendPrimitive3DSequenceToPrimitive3DSequence(Primitive3DSequence & rDest,const Primitive3DSequence & rSource)226         void appendPrimitive3DSequenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DSequence& rSource)
227         {
228             if(rSource.hasElements())
229             {
230                 if(rDest.hasElements())
231                 {
232                     const sal_Int32 nSourceCount(rSource.getLength());
233                     const sal_Int32 nDestCount(rDest.getLength());
234                     const sal_Int32 nTargetCount(nSourceCount + nDestCount);
235                     sal_Int32 nInsertPos(nDestCount);
236 
237                     rDest.realloc(nTargetCount);
238 
239                     for(sal_Int32 a(0L); a < nSourceCount; a++)
240                     {
241                         if(rSource[a].is())
242                         {
243                             rDest[nInsertPos++] = rSource[a];
244                         }
245                     }
246 
247                     if(nInsertPos != nTargetCount)
248                     {
249                         rDest.realloc(nInsertPos);
250                     }
251                 }
252                 else
253                 {
254                     rDest = rSource;
255                 }
256             }
257         }
258 
259         // concatenate single Primitive3D
appendPrimitive3DReferenceToPrimitive3DSequence(Primitive3DSequence & rDest,const Primitive3DReference & rSource)260         void appendPrimitive3DReferenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DReference& rSource)
261         {
262             if(rSource.is())
263             {
264                 const sal_Int32 nDestCount(rDest.getLength());
265                 rDest.realloc(nDestCount + 1L);
266                 rDest[nDestCount] = rSource;
267             }
268         }
269 
270     } // end of namespace primitive3d
271 } // end of namespace drawinglayer
272 
273 //////////////////////////////////////////////////////////////////////////////
274 // eof
275