xref: /AOO41X/main/drawinglayer/source/primitive2d/baseprimitive2d.cxx (revision 464702f4578bd67db020a330afd07883930c5e07)
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/primitive2d/baseprimitive2d.hxx>
28cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation2d.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 primitive2d
40cdf0e10cSrcweir 	{
41cdf0e10cSrcweir 		BasePrimitive2D::BasePrimitive2D()
42cdf0e10cSrcweir 		:	BasePrimitive2DImplBase(m_aMutex)
43cdf0e10cSrcweir 		{
44cdf0e10cSrcweir 		}
45cdf0e10cSrcweir 
46cdf0e10cSrcweir         BasePrimitive2D::~BasePrimitive2D()
47cdf0e10cSrcweir         {
48cdf0e10cSrcweir         }
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 		bool BasePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
51cdf0e10cSrcweir 		{
52cdf0e10cSrcweir 			return (getPrimitive2DID() == rPrimitive.getPrimitive2DID());
53cdf0e10cSrcweir 		}
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 		basegfx::B2DRange BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
56cdf0e10cSrcweir 		{
57cdf0e10cSrcweir 			return getB2DRangeFromPrimitive2DSequence(get2DDecomposition(rViewInformation), rViewInformation);
58cdf0e10cSrcweir 		}
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 		Primitive2DSequence BasePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
61cdf0e10cSrcweir 		{
62cdf0e10cSrcweir 			return Primitive2DSequence();
63cdf0e10cSrcweir 		}
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 		Primitive2DSequence SAL_CALL BasePrimitive2D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
66cdf0e10cSrcweir 		{
67cdf0e10cSrcweir 			const geometry::ViewInformation2D aViewInformation(rViewParameters);
68cdf0e10cSrcweir 			return get2DDecomposition(aViewInformation);
69cdf0e10cSrcweir 		}
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 		com::sun::star::geometry::RealRectangle2D SAL_CALL BasePrimitive2D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
72cdf0e10cSrcweir 		{
73cdf0e10cSrcweir 			const geometry::ViewInformation2D aViewInformation(rViewParameters);
74cdf0e10cSrcweir 			return basegfx::unotools::rectangle2DFromB2DRectangle(getB2DRange(aViewInformation));
75cdf0e10cSrcweir 		}
76cdf0e10cSrcweir 	} // end of namespace primitive2d
77cdf0e10cSrcweir } // end of namespace drawinglayer
78cdf0e10cSrcweir 
79cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
80cdf0e10cSrcweir 
81cdf0e10cSrcweir namespace drawinglayer
82cdf0e10cSrcweir {
83cdf0e10cSrcweir 	namespace primitive2d
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		Primitive2DSequence BufferedDecompositionPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
86cdf0e10cSrcweir 		{
87cdf0e10cSrcweir 			return Primitive2DSequence();
88cdf0e10cSrcweir 		}
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 		BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D()
91cdf0e10cSrcweir 		:	BasePrimitive2D(),
92cdf0e10cSrcweir             maBuffered2DDecomposition()
93cdf0e10cSrcweir 		{
94cdf0e10cSrcweir 		}
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		Primitive2DSequence BufferedDecompositionPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
97cdf0e10cSrcweir 		{
98cdf0e10cSrcweir 			::osl::MutexGuard aGuard( m_aMutex );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 			if(!getBuffered2DDecomposition().hasElements())
101cdf0e10cSrcweir 			{
102cdf0e10cSrcweir 				const Primitive2DSequence aNewSequence(create2DDecomposition(rViewInformation));
103cdf0e10cSrcweir 				const_cast< BufferedDecompositionPrimitive2D* >(this)->setBuffered2DDecomposition(aNewSequence);
104cdf0e10cSrcweir 			}
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 			return getBuffered2DDecomposition();
107cdf0e10cSrcweir 		}
108cdf0e10cSrcweir 	} // end of namespace primitive2d
109cdf0e10cSrcweir } // end of namespace drawinglayer
110cdf0e10cSrcweir 
111cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
112cdf0e10cSrcweir // tooling
113cdf0e10cSrcweir 
114cdf0e10cSrcweir namespace drawinglayer
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	namespace primitive2d
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir 		// get B2DRange from a given Primitive2DReference
119cdf0e10cSrcweir 		basegfx::B2DRange getB2DRangeFromPrimitive2DReference(const Primitive2DReference& rCandidate, const geometry::ViewInformation2D& aViewInformation)
120cdf0e10cSrcweir 		{
121cdf0e10cSrcweir 			basegfx::B2DRange aRetval;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 			if(rCandidate.is())
124cdf0e10cSrcweir 			{
125cdf0e10cSrcweir 				// try to get C++ implementation base
126cdf0e10cSrcweir 				const BasePrimitive2D* pCandidate(dynamic_cast< BasePrimitive2D* >(rCandidate.get()));
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 				if(pCandidate)
129cdf0e10cSrcweir 				{
130cdf0e10cSrcweir 					// use it if possible
131cdf0e10cSrcweir 					aRetval.expand(pCandidate->getB2DRange(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::b2DRectangleFromRealRectangle2D(rCandidate->getRange(rViewParameters)));
138cdf0e10cSrcweir 				}
139cdf0e10cSrcweir 			}
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 			return aRetval;
142cdf0e10cSrcweir 		}
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 		// get B2DRange from a given Primitive2DSequence
145cdf0e10cSrcweir 		basegfx::B2DRange getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence& rCandidate, const geometry::ViewInformation2D& aViewInformation)
146cdf0e10cSrcweir 		{
147cdf0e10cSrcweir 			basegfx::B2DRange 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(getB2DRangeFromPrimitive2DReference(rCandidate[a], aViewInformation));
156cdf0e10cSrcweir 				}
157cdf0e10cSrcweir 			}
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 			return aRetval;
160cdf0e10cSrcweir 		}
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 		bool arePrimitive2DReferencesEqual(const Primitive2DReference& rxA, const Primitive2DReference& 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 BasePrimitive2D* pA(dynamic_cast< const BasePrimitive2D* >(rxA.get()));
177cdf0e10cSrcweir 			const BasePrimitive2D* pB(dynamic_cast< const BasePrimitive2D* >(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 
193cdf0e10cSrcweir 		bool arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& 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(!arePrimitive2DReferencesEqual(rA[a], rB[a]))
217cdf0e10cSrcweir 				{
218cdf0e10cSrcweir 					return false;
219cdf0e10cSrcweir 				}
220cdf0e10cSrcweir 			}
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 			return true;
223cdf0e10cSrcweir 		}
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 		// concatenate sequence
226cdf0e10cSrcweir 		void appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DSequence& 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 Primitive2D
260cdf0e10cSrcweir 		void appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DReference& 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 primitive2d
271cdf0e10cSrcweir } // end of namespace drawinglayer
272cdf0e10cSrcweir 
273cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
274cdf0e10cSrcweir // eof
275