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/primitive2d/primitivetools2d.hxx>
32 #include <basegfx/vector/b2dvector.hxx>
33 #include <drawinglayer/geometry/viewinformation2d.hxx>
34 
35 //////////////////////////////////////////////////////////////////////////////
36 
37 namespace drawinglayer
38 {
39 	namespace primitive2d
40 	{
41 		Primitive2DSequence DiscreteMetricDependentPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
42 		{
43 			::osl::MutexGuard aGuard( m_aMutex );
44 
45 			// get the current DiscreteUnit
46 			const double fDiscreteUnit((rViewInformation.getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 0.0)).getLength());
47 
48 			if(getBuffered2DDecomposition().hasElements() && !basegfx::fTools::equal(fDiscreteUnit, getDiscreteUnit()))
49 			{
50 				// conditions of last local decomposition have changed, delete
51 				const_cast< DiscreteMetricDependentPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence());
52 			}
53 
54 			if(!getBuffered2DDecomposition().hasElements())
55 			{
56 				// remember new valid DiscreteUnit
57 				const_cast< DiscreteMetricDependentPrimitive2D* >(this)->mfDiscreteUnit = fDiscreteUnit;
58 			}
59 
60 			// call base implementation
61 			return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
62 		}
63 	} // end of namespace primitive2d
64 } // end of namespace drawinglayer
65 
66 //////////////////////////////////////////////////////////////////////////////
67 
68 namespace drawinglayer
69 {
70 	namespace primitive2d
71 	{
72 		Primitive2DSequence ViewportDependentPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
73 		{
74 			::osl::MutexGuard aGuard( m_aMutex );
75 
76 			// get the current Viewport
77 			const basegfx::B2DRange& rViewport = rViewInformation.getViewport();
78 
79 			if(getBuffered2DDecomposition().hasElements() && !rViewport.equal(getViewport()))
80 			{
81 				// conditions of last local decomposition have changed, delete
82 				const_cast< ViewportDependentPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence());
83 			}
84 
85 			if(!getBuffered2DDecomposition().hasElements())
86 			{
87 				// remember new valid DiscreteUnit
88 				const_cast< ViewportDependentPrimitive2D* >(this)->maViewport = rViewport;
89 			}
90 
91 			// call base implementation
92 			return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
93 		}
94 	} // end of namespace primitive2d
95 } // end of namespace drawinglayer
96 
97 //////////////////////////////////////////////////////////////////////////////
98 
99 namespace drawinglayer
100 {
101 	namespace primitive2d
102 	{
103 		Primitive2DSequence ViewTransformationDependentPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
104 		{
105 			::osl::MutexGuard aGuard( m_aMutex );
106 
107 			// get the current ViewTransformation
108 			const basegfx::B2DHomMatrix& rViewTransformation = rViewInformation.getViewTransformation();
109 
110 			if(getBuffered2DDecomposition().hasElements() && rViewTransformation != getViewTransformation())
111 			{
112 				// conditions of last local decomposition have changed, delete
113 				const_cast< ViewTransformationDependentPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence());
114 			}
115 
116 			if(!getBuffered2DDecomposition().hasElements())
117 			{
118 				// remember new valid ViewTransformation
119 				const_cast< ViewTransformationDependentPrimitive2D* >(this)->maViewTransformation = rViewTransformation;
120 			}
121 
122 			// call base implementation
123 			return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
124 		}
125 	} // end of namespace primitive2d
126 } // end of namespace drawinglayer
127 
128 //////////////////////////////////////////////////////////////////////////////
129 
130 namespace drawinglayer
131 {
132 	namespace primitive2d
133 	{
134 		Primitive2DSequence ObjectAndViewTransformationDependentPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
135 		{
136 			::osl::MutexGuard aGuard( m_aMutex );
137 
138 			// get the current ViewTransfromation
139 			const basegfx::B2DHomMatrix& rViewTransformation = rViewInformation.getViewTransformation();
140 
141 			if(getBuffered2DDecomposition().hasElements() && rViewTransformation != getViewTransformation())
142 			{
143 				// conditions of last local decomposition have changed, delete
144 				const_cast< ObjectAndViewTransformationDependentPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence());
145 			}
146 
147 			// get the current ObjectTransformation
148 			const basegfx::B2DHomMatrix& rObjectTransformation = rViewInformation.getObjectTransformation();
149 
150 			if(getBuffered2DDecomposition().hasElements() && rObjectTransformation != getObjectTransformation())
151 			{
152 				// conditions of last local decomposition have changed, delete
153 				const_cast< ObjectAndViewTransformationDependentPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence());
154 			}
155 
156 			if(!getBuffered2DDecomposition().hasElements())
157 			{
158 				// remember new valid ViewTransformation, and ObjectTransformation
159 				const_cast< ObjectAndViewTransformationDependentPrimitive2D* >(this)->maViewTransformation = rViewTransformation;
160 				const_cast< ObjectAndViewTransformationDependentPrimitive2D* >(this)->maObjectTransformation = rObjectTransformation;
161 			}
162 
163 			// call base implementation
164 			return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
165 		}
166 	} // end of namespace primitive2d
167 } // end of namespace drawinglayer
168 
169 //////////////////////////////////////////////////////////////////////////////
170 // eof
171