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