1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation3d.hxx>
32*cdf0e10cSrcweir #include <basegfx/range/b3drange.hxx>
33*cdf0e10cSrcweir #include <basegfx/matrix/b3dhommatrix.hxx>
34*cdf0e10cSrcweir #include <com/sun/star/geometry/AffineMatrix3D.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/geometry/RealRectangle3D.hpp>
36*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir using namespace com::sun::star;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace drawinglayer
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir 	namespace geometry
47*cdf0e10cSrcweir 	{
48*cdf0e10cSrcweir         /** Implementation class for ViewInformation3D
49*cdf0e10cSrcweir         */
50*cdf0e10cSrcweir 		class ImpViewInformation3D
51*cdf0e10cSrcweir 		{
52*cdf0e10cSrcweir 		private:
53*cdf0e10cSrcweir 			// ViewInformation3D implementation can change refcount, so we have only
54*cdf0e10cSrcweir 			// two memory regions for pairs of ViewInformation3D/ImpViewInformation3D
55*cdf0e10cSrcweir 			friend class ::drawinglayer::geometry::ViewInformation3D;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 			// the refcounter. 0 means exclusively used
58*cdf0e10cSrcweir 			sal_uInt32									mnRefCount;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 			// the 3D transformations
61*cdf0e10cSrcweir 			// Object to World. This may change and being adapted when entering 3D transformation
62*cdf0e10cSrcweir 			// groups
63*cdf0e10cSrcweir 			basegfx::B3DHomMatrix						maObjectTransformation;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 			// World to Camera. This includes VRP, VPN and VUV camera coordinate system
66*cdf0e10cSrcweir 			basegfx::B3DHomMatrix						maOrientation;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 			// Camera to Device with X,Y and Z [-1.0 .. 1.0]. This is the
69*cdf0e10cSrcweir 			// 3D to 2D projection which may be parallell or perspective. When it is perspective,
70*cdf0e10cSrcweir 			// the last line of the homogen matrix will NOT be unused
71*cdf0e10cSrcweir 			basegfx::B3DHomMatrix						maProjection;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 			// Device to View with X,Y and Z [0.0 .. 1.0]. This converts from -1 to 1 coordinates
74*cdf0e10cSrcweir 			// in camera coordinate system to 0 to 1 in unit 2D coordinates. This way it stays
75*cdf0e10cSrcweir 			// view-independent. To get discrete coordinates, the 2D transformation of a scene
76*cdf0e10cSrcweir 			// as 2D object needs to be involved
77*cdf0e10cSrcweir 			basegfx::B3DHomMatrix						maDeviceToView;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 			// Object to View is the linear combination of all four transformations. It's
80*cdf0e10cSrcweir 			// buffered to avoid too much matrix multiplying and created on demand
81*cdf0e10cSrcweir 			basegfx::B3DHomMatrix						maObjectToView;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 			// the point in time
84*cdf0e10cSrcweir 			double										mfViewTime;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 			// the complete PropertyValue representation (if already created)
87*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue >		mxViewInformation;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 			// the extra PropertyValues; does not contain the transformations
90*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue >		mxExtendedInformation;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 			// the local UNO API strings
93*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyObjectTransformation()
94*cdf0e10cSrcweir 			{
95*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("ObjectTransformation"));
96*cdf0e10cSrcweir 				return s_sNameProperty;
97*cdf0e10cSrcweir 			}
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyOrientation()
100*cdf0e10cSrcweir 			{
101*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("Orientation"));
102*cdf0e10cSrcweir 				return s_sNameProperty;
103*cdf0e10cSrcweir 			}
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyProjection()
106*cdf0e10cSrcweir 			{
107*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("Projection"));
108*cdf0e10cSrcweir 				return s_sNameProperty;
109*cdf0e10cSrcweir 			}
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyProjection_30()
112*cdf0e10cSrcweir 			{
113*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("Projection30"));
114*cdf0e10cSrcweir 				return s_sNameProperty;
115*cdf0e10cSrcweir 			}
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyProjection_31()
118*cdf0e10cSrcweir 			{
119*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("Projection31"));
120*cdf0e10cSrcweir 				return s_sNameProperty;
121*cdf0e10cSrcweir 			}
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyProjection_32()
124*cdf0e10cSrcweir 			{
125*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("Projection32"));
126*cdf0e10cSrcweir 				return s_sNameProperty;
127*cdf0e10cSrcweir 			}
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyProjection_33()
130*cdf0e10cSrcweir 			{
131*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("Projection33"));
132*cdf0e10cSrcweir 				return s_sNameProperty;
133*cdf0e10cSrcweir 			}
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyDeviceToView()
136*cdf0e10cSrcweir 			{
137*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("DeviceToView"));
138*cdf0e10cSrcweir 				return s_sNameProperty;
139*cdf0e10cSrcweir 			}
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyTime()
142*cdf0e10cSrcweir 			{
143*cdf0e10cSrcweir 				static ::rtl::OUString s_sNamePropertyTime(RTL_CONSTASCII_USTRINGPARAM("Time"));
144*cdf0e10cSrcweir 				return s_sNamePropertyTime;
145*cdf0e10cSrcweir 			}
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir             // a central PropertyValue parsing method to allow transportatin of
148*cdf0e10cSrcweir             // all ViewParameters using UNO API
149*cdf0e10cSrcweir 			void impInterpretPropertyValues(const uno::Sequence< beans::PropertyValue >& rViewParameters)
150*cdf0e10cSrcweir 			{
151*cdf0e10cSrcweir 				if(rViewParameters.hasElements())
152*cdf0e10cSrcweir 				{
153*cdf0e10cSrcweir 					const sal_Int32 nCount(rViewParameters.getLength());
154*cdf0e10cSrcweir 					sal_Int32 nExtendedInsert(0);
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 					// prepare extended information for filtering. Maximum size is nCount
157*cdf0e10cSrcweir 					mxExtendedInformation.realloc(nCount);
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 					for(sal_Int32 a(0); a < nCount; a++)
160*cdf0e10cSrcweir 					{
161*cdf0e10cSrcweir 						const beans::PropertyValue& rProp = rViewParameters[a];
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 						if(rProp.Name == getNamePropertyObjectTransformation())
164*cdf0e10cSrcweir 						{
165*cdf0e10cSrcweir 							com::sun::star::geometry::AffineMatrix3D aAffineMatrix3D;
166*cdf0e10cSrcweir 							rProp.Value >>= aAffineMatrix3D;
167*cdf0e10cSrcweir 							maObjectTransformation = basegfx::unotools::homMatrixFromAffineMatrix3D(aAffineMatrix3D);
168*cdf0e10cSrcweir 						}
169*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyOrientation())
170*cdf0e10cSrcweir 						{
171*cdf0e10cSrcweir 							com::sun::star::geometry::AffineMatrix3D aAffineMatrix3D;
172*cdf0e10cSrcweir 							rProp.Value >>= aAffineMatrix3D;
173*cdf0e10cSrcweir 							maOrientation = basegfx::unotools::homMatrixFromAffineMatrix3D(aAffineMatrix3D);
174*cdf0e10cSrcweir 						}
175*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyProjection())
176*cdf0e10cSrcweir 						{
177*cdf0e10cSrcweir 							// projection may be defined using a frustum in which case the last line of
178*cdf0e10cSrcweir 							// the 4x4 matrix is not (0,0,0,1). Since AffineMatrix3D does not support that,
179*cdf0e10cSrcweir 							// these four values need to be treated extra
180*cdf0e10cSrcweir 							const double f_30(maProjection.get(3, 0));
181*cdf0e10cSrcweir 							const double f_31(maProjection.get(3, 1));
182*cdf0e10cSrcweir 							const double f_32(maProjection.get(3, 2));
183*cdf0e10cSrcweir 							const double f_33(maProjection.get(3, 3));
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 							com::sun::star::geometry::AffineMatrix3D aAffineMatrix3D;
186*cdf0e10cSrcweir 							rProp.Value >>= aAffineMatrix3D;
187*cdf0e10cSrcweir 							maProjection = basegfx::unotools::homMatrixFromAffineMatrix3D(aAffineMatrix3D);
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 							maProjection.set(3, 0, f_30);
190*cdf0e10cSrcweir 							maProjection.set(3, 1, f_31);
191*cdf0e10cSrcweir 							maProjection.set(3, 2, f_32);
192*cdf0e10cSrcweir 							maProjection.set(3, 3, f_33);
193*cdf0e10cSrcweir 						}
194*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyProjection_30())
195*cdf0e10cSrcweir 						{
196*cdf0e10cSrcweir 							double f_30(0.0);
197*cdf0e10cSrcweir 							rProp.Value >>= f_30;
198*cdf0e10cSrcweir 							maProjection.set(3, 0, f_30);
199*cdf0e10cSrcweir 						}
200*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyProjection_31())
201*cdf0e10cSrcweir 						{
202*cdf0e10cSrcweir 							double f_31(0.0);
203*cdf0e10cSrcweir 							rProp.Value >>= f_31;
204*cdf0e10cSrcweir 							maProjection.set(3, 1, f_31);
205*cdf0e10cSrcweir 						}
206*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyProjection_32())
207*cdf0e10cSrcweir 						{
208*cdf0e10cSrcweir 							double f_32(0.0);
209*cdf0e10cSrcweir 							rProp.Value >>= f_32;
210*cdf0e10cSrcweir 							maProjection.set(3, 2, f_32);
211*cdf0e10cSrcweir 						}
212*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyProjection_33())
213*cdf0e10cSrcweir 						{
214*cdf0e10cSrcweir 							double f_33(1.0);
215*cdf0e10cSrcweir 							rProp.Value >>= f_33;
216*cdf0e10cSrcweir 							maProjection.set(3, 3, f_33);
217*cdf0e10cSrcweir 						}
218*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyDeviceToView())
219*cdf0e10cSrcweir 						{
220*cdf0e10cSrcweir 							com::sun::star::geometry::AffineMatrix3D aAffineMatrix3D;
221*cdf0e10cSrcweir 							rProp.Value >>= aAffineMatrix3D;
222*cdf0e10cSrcweir 							maDeviceToView = basegfx::unotools::homMatrixFromAffineMatrix3D(aAffineMatrix3D);
223*cdf0e10cSrcweir 						}
224*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyTime())
225*cdf0e10cSrcweir 						{
226*cdf0e10cSrcweir 							rProp.Value >>= mfViewTime;
227*cdf0e10cSrcweir 						}
228*cdf0e10cSrcweir 						else
229*cdf0e10cSrcweir 						{
230*cdf0e10cSrcweir 							// extra information; add to filtered information
231*cdf0e10cSrcweir 							mxExtendedInformation[nExtendedInsert++] = rProp;
232*cdf0e10cSrcweir 						}
233*cdf0e10cSrcweir 					}
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 					// extra information size is now known; realloc to final size
236*cdf0e10cSrcweir 					mxExtendedInformation.realloc(nExtendedInsert);
237*cdf0e10cSrcweir 				}
238*cdf0e10cSrcweir 			}
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir             // central method to create a Sequence of PropertyValues containing he complete
241*cdf0e10cSrcweir             // data set
242*cdf0e10cSrcweir 			void impFillViewInformationFromContent()
243*cdf0e10cSrcweir 			{
244*cdf0e10cSrcweir 				uno::Sequence< beans::PropertyValue > xRetval;
245*cdf0e10cSrcweir 				const bool bObjectTransformationUsed(!maObjectTransformation.isIdentity());
246*cdf0e10cSrcweir 				const bool bOrientationUsed(!maOrientation.isIdentity());
247*cdf0e10cSrcweir 				const bool bProjectionUsed(!maProjection.isIdentity());
248*cdf0e10cSrcweir 				const bool bDeviceToViewUsed(!maDeviceToView.isIdentity());
249*cdf0e10cSrcweir 				const bool bTimeUsed(0.0 < mfViewTime);
250*cdf0e10cSrcweir 				const bool bExtraInformation(mxExtendedInformation.hasElements());
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 				// projection may be defined using a frustum in which case the last line of
253*cdf0e10cSrcweir 				// the 4x4 matrix is not (0,0,0,1). Since AffineMatrix3D does not support that,
254*cdf0e10cSrcweir 				// these four values need to be treated extra
255*cdf0e10cSrcweir 				const bool bProjectionUsed_30(bProjectionUsed && !basegfx::fTools::equalZero(maProjection.get(3, 0)));
256*cdf0e10cSrcweir 				const bool bProjectionUsed_31(bProjectionUsed && !basegfx::fTools::equalZero(maProjection.get(3, 1)));
257*cdf0e10cSrcweir 				const bool bProjectionUsed_32(bProjectionUsed && !basegfx::fTools::equalZero(maProjection.get(3, 2)));
258*cdf0e10cSrcweir 				const bool bProjectionUsed_33(bProjectionUsed && !basegfx::fTools::equal(maProjection.get(3, 3), 1.0));
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 				sal_uInt32 nIndex(0);
261*cdf0e10cSrcweir 				const sal_uInt32 nCount(
262*cdf0e10cSrcweir 					(bObjectTransformationUsed ? 1 : 0) +
263*cdf0e10cSrcweir 					(bOrientationUsed ? 1 : 0) +
264*cdf0e10cSrcweir 					(bProjectionUsed ? 1 : 0) +
265*cdf0e10cSrcweir 					(bProjectionUsed_30 ? 1 : 0) +
266*cdf0e10cSrcweir 					(bProjectionUsed_31 ? 1 : 0) +
267*cdf0e10cSrcweir 					(bProjectionUsed_32 ? 1 : 0) +
268*cdf0e10cSrcweir 					(bProjectionUsed_33 ? 1 : 0) +
269*cdf0e10cSrcweir 					(bDeviceToViewUsed ? 1 : 0) +
270*cdf0e10cSrcweir 					(bTimeUsed ? 1 : 0) +
271*cdf0e10cSrcweir 					(bExtraInformation ? mxExtendedInformation.getLength() : 0));
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 				mxViewInformation.realloc(nCount);
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 				if(bObjectTransformationUsed)
276*cdf0e10cSrcweir 				{
277*cdf0e10cSrcweir 					com::sun::star::geometry::AffineMatrix3D aAffineMatrix3D;
278*cdf0e10cSrcweir 					basegfx::unotools::affineMatrixFromHomMatrix3D(aAffineMatrix3D, maObjectTransformation);
279*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyObjectTransformation();
280*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= aAffineMatrix3D;
281*cdf0e10cSrcweir 					nIndex++;
282*cdf0e10cSrcweir 				}
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 				if(bOrientationUsed)
285*cdf0e10cSrcweir 				{
286*cdf0e10cSrcweir 					com::sun::star::geometry::AffineMatrix3D aAffineMatrix3D;
287*cdf0e10cSrcweir 					basegfx::unotools::affineMatrixFromHomMatrix3D(aAffineMatrix3D, maOrientation);
288*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyOrientation();
289*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= aAffineMatrix3D;
290*cdf0e10cSrcweir 					nIndex++;
291*cdf0e10cSrcweir 				}
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 				if(bProjectionUsed)
294*cdf0e10cSrcweir 				{
295*cdf0e10cSrcweir 					com::sun::star::geometry::AffineMatrix3D aAffineMatrix3D;
296*cdf0e10cSrcweir 					basegfx::unotools::affineMatrixFromHomMatrix3D(aAffineMatrix3D, maProjection);
297*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyProjection();
298*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= aAffineMatrix3D;
299*cdf0e10cSrcweir 					nIndex++;
300*cdf0e10cSrcweir 				}
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir 				if(bProjectionUsed_30)
303*cdf0e10cSrcweir 				{
304*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyProjection_30();
305*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= maProjection.get(3, 0);
306*cdf0e10cSrcweir 					nIndex++;
307*cdf0e10cSrcweir 				}
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 				if(bProjectionUsed_31)
310*cdf0e10cSrcweir 				{
311*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyProjection_31();
312*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= maProjection.get(3, 1);
313*cdf0e10cSrcweir 					nIndex++;
314*cdf0e10cSrcweir 				}
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 				if(bProjectionUsed_32)
317*cdf0e10cSrcweir 				{
318*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyProjection_32();
319*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= maProjection.get(3, 2);
320*cdf0e10cSrcweir 					nIndex++;
321*cdf0e10cSrcweir 				}
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 				if(bProjectionUsed_33)
324*cdf0e10cSrcweir 				{
325*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyProjection_33();
326*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= maProjection.get(3, 3);
327*cdf0e10cSrcweir 					nIndex++;
328*cdf0e10cSrcweir 				}
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 				if(bDeviceToViewUsed)
331*cdf0e10cSrcweir 				{
332*cdf0e10cSrcweir 					com::sun::star::geometry::AffineMatrix3D aAffineMatrix3D;
333*cdf0e10cSrcweir 					basegfx::unotools::affineMatrixFromHomMatrix3D(aAffineMatrix3D, maDeviceToView);
334*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyDeviceToView();
335*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= aAffineMatrix3D;
336*cdf0e10cSrcweir 					nIndex++;
337*cdf0e10cSrcweir 				}
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 				if(bTimeUsed)
340*cdf0e10cSrcweir 				{
341*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyTime();
342*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= mfViewTime;
343*cdf0e10cSrcweir 					nIndex++;
344*cdf0e10cSrcweir 				}
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir 				if(bExtraInformation)
347*cdf0e10cSrcweir 				{
348*cdf0e10cSrcweir 					const sal_Int32 nExtra(mxExtendedInformation.getLength());
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 					for(sal_Int32 a(0); a < nExtra; a++)
351*cdf0e10cSrcweir 					{
352*cdf0e10cSrcweir 						mxViewInformation[nIndex++] = mxExtendedInformation[a];
353*cdf0e10cSrcweir 					}
354*cdf0e10cSrcweir 				}
355*cdf0e10cSrcweir 			}
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 		public:
358*cdf0e10cSrcweir 			ImpViewInformation3D(
359*cdf0e10cSrcweir 				const basegfx::B3DHomMatrix& rObjectTransformation,
360*cdf0e10cSrcweir 				const basegfx::B3DHomMatrix& rOrientation,
361*cdf0e10cSrcweir 				const basegfx::B3DHomMatrix& rProjection,
362*cdf0e10cSrcweir 				const basegfx::B3DHomMatrix& rDeviceToView,
363*cdf0e10cSrcweir 				double fViewTime,
364*cdf0e10cSrcweir 				const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
365*cdf0e10cSrcweir 			:	mnRefCount(0),
366*cdf0e10cSrcweir 				maObjectTransformation(rObjectTransformation),
367*cdf0e10cSrcweir 				maOrientation(rOrientation),
368*cdf0e10cSrcweir 				maProjection(rProjection),
369*cdf0e10cSrcweir 				maDeviceToView(rDeviceToView),
370*cdf0e10cSrcweir 				mfViewTime(fViewTime),
371*cdf0e10cSrcweir 				mxViewInformation(),
372*cdf0e10cSrcweir 				mxExtendedInformation()
373*cdf0e10cSrcweir 			{
374*cdf0e10cSrcweir 				impInterpretPropertyValues(rExtendedParameters);
375*cdf0e10cSrcweir 			}
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 			ImpViewInformation3D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
378*cdf0e10cSrcweir 			:	mnRefCount(0),
379*cdf0e10cSrcweir 				maObjectTransformation(),
380*cdf0e10cSrcweir 				maOrientation(),
381*cdf0e10cSrcweir 				maProjection(),
382*cdf0e10cSrcweir 				maDeviceToView(),
383*cdf0e10cSrcweir 				mfViewTime(),
384*cdf0e10cSrcweir 				mxViewInformation(rViewParameters),
385*cdf0e10cSrcweir 				mxExtendedInformation()
386*cdf0e10cSrcweir 			{
387*cdf0e10cSrcweir 				impInterpretPropertyValues(rViewParameters);
388*cdf0e10cSrcweir 			}
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir 			ImpViewInformation3D()
391*cdf0e10cSrcweir 			:	mnRefCount(0),
392*cdf0e10cSrcweir 				maObjectTransformation(),
393*cdf0e10cSrcweir 				maOrientation(),
394*cdf0e10cSrcweir 				maProjection(),
395*cdf0e10cSrcweir 				maDeviceToView(),
396*cdf0e10cSrcweir 				mfViewTime(),
397*cdf0e10cSrcweir 				mxViewInformation(),
398*cdf0e10cSrcweir 				mxExtendedInformation()
399*cdf0e10cSrcweir 			{
400*cdf0e10cSrcweir 			}
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 			const basegfx::B3DHomMatrix& getObjectTransformation() const { return maObjectTransformation; }
403*cdf0e10cSrcweir 			const basegfx::B3DHomMatrix& getOrientation() const { return maOrientation; }
404*cdf0e10cSrcweir 			const basegfx::B3DHomMatrix& getProjection() const { return maProjection; }
405*cdf0e10cSrcweir 			const basegfx::B3DHomMatrix& getDeviceToView() const { return maDeviceToView; }
406*cdf0e10cSrcweir 			double getViewTime() const { return mfViewTime; }
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 			const basegfx::B3DHomMatrix& getObjectToView() const
409*cdf0e10cSrcweir 			{
410*cdf0e10cSrcweir 				// on demand WorldToView creation
411*cdf0e10cSrcweir 			    ::osl::Mutex m_mutex;
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 				if(maObjectToView.isIdentity())
414*cdf0e10cSrcweir 				{
415*cdf0e10cSrcweir 					const_cast< ImpViewInformation3D* >(this)->maObjectToView = maDeviceToView * maProjection * maOrientation * maObjectTransformation;
416*cdf0e10cSrcweir 				}
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 				return maObjectToView;
419*cdf0e10cSrcweir 			}
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 			const uno::Sequence< beans::PropertyValue >& getViewInformationSequence() const
422*cdf0e10cSrcweir 			{
423*cdf0e10cSrcweir 			    ::osl::Mutex m_mutex;
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir                 if(!mxViewInformation.hasElements())
426*cdf0e10cSrcweir 				{
427*cdf0e10cSrcweir 					const_cast< ImpViewInformation3D* >(this)->impFillViewInformationFromContent();
428*cdf0e10cSrcweir 				}
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 				return mxViewInformation;
431*cdf0e10cSrcweir 			}
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 			const uno::Sequence< beans::PropertyValue >& getExtendedInformationSequence() const
434*cdf0e10cSrcweir 			{
435*cdf0e10cSrcweir 				return mxExtendedInformation;
436*cdf0e10cSrcweir 			}
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir 			bool operator==(const ImpViewInformation3D& rCandidate) const
439*cdf0e10cSrcweir 			{
440*cdf0e10cSrcweir 				return (maObjectTransformation == rCandidate.maObjectTransformation
441*cdf0e10cSrcweir 					&& maOrientation == rCandidate.maOrientation
442*cdf0e10cSrcweir 					&& maProjection == rCandidate.maProjection
443*cdf0e10cSrcweir 					&& maDeviceToView == rCandidate.maDeviceToView
444*cdf0e10cSrcweir 					&& mfViewTime == rCandidate.mfViewTime
445*cdf0e10cSrcweir 					&& mxExtendedInformation == rCandidate.mxExtendedInformation);
446*cdf0e10cSrcweir 			}
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 			static ImpViewInformation3D* get_global_default()
449*cdf0e10cSrcweir             {
450*cdf0e10cSrcweir                 static ImpViewInformation3D* pDefault = 0;
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir                 if(!pDefault)
453*cdf0e10cSrcweir                 {
454*cdf0e10cSrcweir                     pDefault = new ImpViewInformation3D();
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
457*cdf0e10cSrcweir     			    pDefault->mnRefCount++;
458*cdf0e10cSrcweir                 }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir                 return pDefault;
461*cdf0e10cSrcweir             }
462*cdf0e10cSrcweir 		};
463*cdf0e10cSrcweir 	} // end of anonymous namespace
464*cdf0e10cSrcweir } // end of namespace drawinglayer
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir namespace drawinglayer
469*cdf0e10cSrcweir {
470*cdf0e10cSrcweir 	namespace geometry
471*cdf0e10cSrcweir 	{
472*cdf0e10cSrcweir 		ViewInformation3D::ViewInformation3D(
473*cdf0e10cSrcweir 			const basegfx::B3DHomMatrix& rObjectObjectTransformation,
474*cdf0e10cSrcweir 			const basegfx::B3DHomMatrix& rOrientation,
475*cdf0e10cSrcweir 			const basegfx::B3DHomMatrix& rProjection,
476*cdf0e10cSrcweir 			const basegfx::B3DHomMatrix& rDeviceToView,
477*cdf0e10cSrcweir 			double fViewTime,
478*cdf0e10cSrcweir 			const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
479*cdf0e10cSrcweir 		:	mpViewInformation3D(new ImpViewInformation3D(
480*cdf0e10cSrcweir 				rObjectObjectTransformation, rOrientation, rProjection,
481*cdf0e10cSrcweir 				rDeviceToView, fViewTime, rExtendedParameters))
482*cdf0e10cSrcweir 		{
483*cdf0e10cSrcweir 		}
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir 		ViewInformation3D::ViewInformation3D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
486*cdf0e10cSrcweir 		:	mpViewInformation3D(new ImpViewInformation3D(rViewParameters))
487*cdf0e10cSrcweir 		{
488*cdf0e10cSrcweir 		}
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir 		ViewInformation3D::ViewInformation3D()
491*cdf0e10cSrcweir         :	mpViewInformation3D(ImpViewInformation3D::get_global_default())
492*cdf0e10cSrcweir 		{
493*cdf0e10cSrcweir 			mpViewInformation3D->mnRefCount++;
494*cdf0e10cSrcweir 		}
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir 		ViewInformation3D::ViewInformation3D(const ViewInformation3D& rCandidate)
497*cdf0e10cSrcweir 		:	mpViewInformation3D(rCandidate.mpViewInformation3D)
498*cdf0e10cSrcweir 		{
499*cdf0e10cSrcweir 		    ::osl::Mutex m_mutex;
500*cdf0e10cSrcweir 			mpViewInformation3D->mnRefCount++;
501*cdf0e10cSrcweir 		}
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir 		ViewInformation3D::~ViewInformation3D()
504*cdf0e10cSrcweir 		{
505*cdf0e10cSrcweir 		    ::osl::Mutex m_mutex;
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir 			if(mpViewInformation3D->mnRefCount)
508*cdf0e10cSrcweir 			{
509*cdf0e10cSrcweir 				mpViewInformation3D->mnRefCount--;
510*cdf0e10cSrcweir 			}
511*cdf0e10cSrcweir 			else
512*cdf0e10cSrcweir 			{
513*cdf0e10cSrcweir 				delete mpViewInformation3D;
514*cdf0e10cSrcweir 			}
515*cdf0e10cSrcweir 		}
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir         bool ViewInformation3D::isDefault() const
518*cdf0e10cSrcweir         {
519*cdf0e10cSrcweir             return mpViewInformation3D == ImpViewInformation3D::get_global_default();
520*cdf0e10cSrcweir         }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir 		ViewInformation3D& ViewInformation3D::operator=(const ViewInformation3D& rCandidate)
523*cdf0e10cSrcweir 		{
524*cdf0e10cSrcweir 		    ::osl::Mutex m_mutex;
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir 			if(mpViewInformation3D->mnRefCount)
527*cdf0e10cSrcweir 			{
528*cdf0e10cSrcweir 				mpViewInformation3D->mnRefCount--;
529*cdf0e10cSrcweir 			}
530*cdf0e10cSrcweir 			else
531*cdf0e10cSrcweir 			{
532*cdf0e10cSrcweir 				delete mpViewInformation3D;
533*cdf0e10cSrcweir 			}
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 			mpViewInformation3D = rCandidate.mpViewInformation3D;
536*cdf0e10cSrcweir 			mpViewInformation3D->mnRefCount++;
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 			return *this;
539*cdf0e10cSrcweir 		}
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir 		bool ViewInformation3D::operator==(const ViewInformation3D& rCandidate) const
542*cdf0e10cSrcweir 		{
543*cdf0e10cSrcweir 			if(rCandidate.mpViewInformation3D == mpViewInformation3D)
544*cdf0e10cSrcweir 			{
545*cdf0e10cSrcweir 				return true;
546*cdf0e10cSrcweir 			}
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
549*cdf0e10cSrcweir 			{
550*cdf0e10cSrcweir 				return false;
551*cdf0e10cSrcweir 			}
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 			return (*rCandidate.mpViewInformation3D == *mpViewInformation3D);
554*cdf0e10cSrcweir 		}
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 		const basegfx::B3DHomMatrix& ViewInformation3D::getObjectTransformation() const
557*cdf0e10cSrcweir 		{
558*cdf0e10cSrcweir 			return mpViewInformation3D->getObjectTransformation();
559*cdf0e10cSrcweir 		}
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir 		const basegfx::B3DHomMatrix& ViewInformation3D::getOrientation() const
562*cdf0e10cSrcweir 		{
563*cdf0e10cSrcweir 			return mpViewInformation3D->getOrientation();
564*cdf0e10cSrcweir 		}
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir 		const basegfx::B3DHomMatrix& ViewInformation3D::getProjection() const
567*cdf0e10cSrcweir 		{
568*cdf0e10cSrcweir 			return mpViewInformation3D->getProjection();
569*cdf0e10cSrcweir 		}
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 		const basegfx::B3DHomMatrix& ViewInformation3D::getDeviceToView() const
572*cdf0e10cSrcweir 		{
573*cdf0e10cSrcweir 			return mpViewInformation3D->getDeviceToView();
574*cdf0e10cSrcweir 		}
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir 		const basegfx::B3DHomMatrix& ViewInformation3D::getObjectToView() const
577*cdf0e10cSrcweir 		{
578*cdf0e10cSrcweir 			return mpViewInformation3D->getObjectToView();
579*cdf0e10cSrcweir 		}
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir 		double ViewInformation3D::getViewTime() const
582*cdf0e10cSrcweir 		{
583*cdf0e10cSrcweir 			return mpViewInformation3D->getViewTime();
584*cdf0e10cSrcweir 		}
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir 		const uno::Sequence< beans::PropertyValue >& ViewInformation3D::getViewInformationSequence() const
587*cdf0e10cSrcweir 		{
588*cdf0e10cSrcweir 			return mpViewInformation3D->getViewInformationSequence();
589*cdf0e10cSrcweir 		}
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir 		const uno::Sequence< beans::PropertyValue >& ViewInformation3D::getExtendedInformationSequence() const
592*cdf0e10cSrcweir 		{
593*cdf0e10cSrcweir 			return mpViewInformation3D->getExtendedInformationSequence();
594*cdf0e10cSrcweir 		}
595*cdf0e10cSrcweir 	} // end of namespace geometry
596*cdf0e10cSrcweir } // end of namespace drawinglayer
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
599*cdf0e10cSrcweir // eof
600