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