1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: viewinformation2d.cxx,v $
9 * last change: $Author: aw $ $Date: 2008-06-24 15:31:07 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/geometry/viewinformation2d.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/range/b2drange.hxx>
42 #include <osl/mutex.hxx>
43 #include <basegfx/tools/canvastools.hxx>
44 #include <com/sun/star/geometry/AffineMatrix2D.hpp>
45 #include <com/sun/star/geometry/RealRectangle2D.hpp>
47 //////////////////////////////////////////////////////////////////////////////
49 using namespace com::sun::star
;
51 //////////////////////////////////////////////////////////////////////////////
53 namespace drawinglayer
57 class ImpViewInformation2D
60 // ViewInformation2D implementation can change refcount, so we have only
61 // two memory regions for pairs of ViewInformation2D/ImpViewInformation2D
62 friend class ::drawinglayer::geometry::ViewInformation2D
;
64 // the refcounter. 0 means exclusively used
65 sal_uInt32 mnRefCount
;
68 // the object transformation
69 basegfx::B2DHomMatrix maObjectTransformation
;
71 // the view transformation
72 basegfx::B2DHomMatrix maViewTransformation
;
74 // the ObjectToView and it's inverse, both on demand from ObjectTransformation
75 // and ViewTransformation
76 basegfx::B2DHomMatrix maObjectToViewTransformation
;
77 basegfx::B2DHomMatrix maInverseObjectToViewTransformation
;
79 // the visible range and the on-demand one in ViewCoordinates
80 basegfx::B2DRange maViewport
;
81 basegfx::B2DRange maDiscreteViewport
;
83 // the DrawPage which is target of visualisation. This is needed e.g. for
84 // the view-dependent decomposition of PageNumber TextFields
85 uno::Reference
< drawing::XDrawPage
> mxVisualizedPage
;
90 // the complete PropertyValue representation (if already created)
91 uno::Sequence
< beans::PropertyValue
> mxViewInformation
;
93 // the extra PropertyValues; not represented by ViewTransformation,
94 // Viewport, VisualizedPage or ViewTime
95 uno::Sequence
< beans::PropertyValue
> mxExtendedInformation
;
97 // the local UNO API strings
98 const ::rtl::OUString
& getNamePropertyObjectTransformation()
100 static ::rtl::OUString
s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("ObjectTransformation"));
101 return s_sNameProperty
;
104 const ::rtl::OUString
& getNamePropertyViewTransformation()
106 static ::rtl::OUString
s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("ViewTransformation"));
107 return s_sNameProperty
;
110 const ::rtl::OUString
& getNamePropertyViewport()
112 static ::rtl::OUString
s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("Viewport"));
113 return s_sNameProperty
;
116 const ::rtl::OUString
& getNamePropertyTime()
118 static ::rtl::OUString
s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("Time"));
119 return s_sNameProperty
;
122 const ::rtl::OUString
& getNamePropertyVisualizedPage()
124 static ::rtl::OUString
s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("VisualizedPage"));
125 return s_sNameProperty
;
128 void impInterpretPropertyValues(const uno::Sequence
< beans::PropertyValue
>& rViewParameters
)
130 if(rViewParameters
.hasElements())
132 const sal_Int32
nCount(rViewParameters
.getLength());
133 sal_Int32
nExtendedInsert(0);
135 // prepare extended information for filtering. Maximum size is nCount
136 mxExtendedInformation
.realloc(nCount
);
138 for(sal_Int32
a(0); a
< nCount
; a
++)
140 const beans::PropertyValue
& rProp
= rViewParameters
[a
];
142 if(rProp
.Name
== getNamePropertyObjectTransformation())
144 com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D
;
145 rProp
.Value
>>= aAffineMatrix2D
;
146 basegfx::unotools::homMatrixFromAffineMatrix(maObjectTransformation
, aAffineMatrix2D
);
148 else if(rProp
.Name
== getNamePropertyViewTransformation())
150 com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D
;
151 rProp
.Value
>>= aAffineMatrix2D
;
152 basegfx::unotools::homMatrixFromAffineMatrix(maViewTransformation
, aAffineMatrix2D
);
154 else if(rProp
.Name
== getNamePropertyViewport())
156 com::sun::star::geometry::RealRectangle2D aViewport
;
157 rProp
.Value
>>= aViewport
;
158 maViewport
= basegfx::unotools::b2DRectangleFromRealRectangle2D(aViewport
);
160 else if(rProp
.Name
== getNamePropertyTime())
162 rProp
.Value
>>= mfViewTime
;
164 else if(rProp
.Name
== getNamePropertyVisualizedPage())
166 rProp
.Value
>>= mxVisualizedPage
;
170 // extra information; add to filtered information
171 mxExtendedInformation
[nExtendedInsert
++] = rProp
;
175 // extra information size is now known; realloc to final size
176 mxExtendedInformation
.realloc(nExtendedInsert
);
180 void impFillViewInformationFromContent()
182 uno::Sequence
< beans::PropertyValue
> xRetval
;
183 const bool bObjectTransformationUsed(!maObjectTransformation
.isIdentity());
184 const bool bViewTransformationUsed(!maViewTransformation
.isIdentity());
185 const bool bViewportUsed(!maViewport
.isEmpty());
186 const bool bTimeUsed(0.0 < mfViewTime
);
187 const bool bVisualizedPageUsed(mxVisualizedPage
.is());
188 const bool bExtraInformation(mxExtendedInformation
.hasElements());
189 sal_uInt32
nIndex(0);
190 const sal_uInt32
nCount(
191 (bObjectTransformationUsed
? 1 : 0) +
192 (bViewTransformationUsed
? 1 : 0) +
193 (bViewportUsed
? 1 : 0) +
194 (bTimeUsed
? 1 : 0) +
195 (bVisualizedPageUsed
? 1 : 0) +
196 (bExtraInformation
? mxExtendedInformation
.getLength() : 0));
198 mxViewInformation
.realloc(nCount
);
200 if(bObjectTransformationUsed
)
202 com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D
;
203 basegfx::unotools::affineMatrixFromHomMatrix(aAffineMatrix2D
, maObjectTransformation
);
204 mxViewInformation
[nIndex
].Name
= getNamePropertyObjectTransformation();
205 mxViewInformation
[nIndex
].Value
<<= aAffineMatrix2D
;
209 if(bViewTransformationUsed
)
211 com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D
;
212 basegfx::unotools::affineMatrixFromHomMatrix(aAffineMatrix2D
, maViewTransformation
);
213 mxViewInformation
[nIndex
].Name
= getNamePropertyViewTransformation();
214 mxViewInformation
[nIndex
].Value
<<= aAffineMatrix2D
;
220 const com::sun::star::geometry::RealRectangle2D
aViewport(basegfx::unotools::rectangle2DFromB2DRectangle(maViewport
));
221 mxViewInformation
[nIndex
].Name
= getNamePropertyViewport();
222 mxViewInformation
[nIndex
].Value
<<= aViewport
;
228 mxViewInformation
[nIndex
].Name
= getNamePropertyTime();
229 mxViewInformation
[nIndex
].Value
<<= mfViewTime
;
233 if(bVisualizedPageUsed
)
235 mxViewInformation
[nIndex
].Name
= getNamePropertyVisualizedPage();
236 mxViewInformation
[nIndex
].Value
<<= mxVisualizedPage
;
240 if(bExtraInformation
)
242 const sal_Int32
nExtra(mxExtendedInformation
.getLength());
244 for(sal_Int32
a(0); a
< nExtra
; a
++)
246 mxViewInformation
[nIndex
++] = mxExtendedInformation
[a
];
252 ImpViewInformation2D(
253 const basegfx::B2DHomMatrix
& rObjectTransformation
,
254 const basegfx::B2DHomMatrix
& rViewTransformation
,
255 const basegfx::B2DRange
& rViewport
,
256 const uno::Reference
< drawing::XDrawPage
>& rxDrawPage
,
258 const uno::Sequence
< beans::PropertyValue
>& rExtendedParameters
)
260 maObjectTransformation(rObjectTransformation
),
261 maViewTransformation(rViewTransformation
),
262 maObjectToViewTransformation(),
263 maInverseObjectToViewTransformation(),
264 maViewport(rViewport
),
265 maDiscreteViewport(),
266 mxVisualizedPage(rxDrawPage
),
267 mfViewTime(fViewTime
),
269 mxExtendedInformation()
271 impInterpretPropertyValues(rExtendedParameters
);
274 ImpViewInformation2D(const uno::Sequence
< beans::PropertyValue
>& rViewParameters
)
276 maObjectTransformation(),
277 maViewTransformation(),
278 maObjectToViewTransformation(),
279 maInverseObjectToViewTransformation(),
281 maDiscreteViewport(),
284 mxViewInformation(rViewParameters
),
285 mxExtendedInformation()
287 impInterpretPropertyValues(rViewParameters
);
290 const basegfx::B2DHomMatrix
& getObjectTransformation() const
292 return maObjectTransformation
;
295 const basegfx::B2DHomMatrix
& getViewTransformation() const
297 return maViewTransformation
;
300 const basegfx::B2DRange
& getViewport() const
305 const basegfx::B2DRange
& getDiscreteViewport() const
307 ::osl::Mutex m_mutex
;
309 if(maDiscreteViewport
.isEmpty() && !maViewport
.isEmpty())
311 basegfx::B2DRange
aDiscreteViewport(maViewport
);
312 aDiscreteViewport
.transform(getViewTransformation());
313 const_cast< ImpViewInformation2D
* >(this)->maDiscreteViewport
= aDiscreteViewport
;
316 return maDiscreteViewport
;
319 const basegfx::B2DHomMatrix
& getObjectToViewTransformation() const
321 ::osl::Mutex m_mutex
;
323 if(maObjectToViewTransformation
.isIdentity() &&
324 (!maObjectTransformation
.isIdentity() || !maViewTransformation
.isIdentity()))
326 basegfx::B2DHomMatrix
aObjectToView(maViewTransformation
* maObjectTransformation
);
327 const_cast< ImpViewInformation2D
* >(this)->maObjectToViewTransformation
= aObjectToView
;
330 return maObjectToViewTransformation
;
333 const basegfx::B2DHomMatrix
& getInverseObjectToViewTransformation() const
335 ::osl::Mutex m_mutex
;
337 if(maInverseObjectToViewTransformation
.isIdentity() &&
338 (!maObjectTransformation
.isIdentity() || !maViewTransformation
.isIdentity()))
340 basegfx::B2DHomMatrix
aInverseObjectToView(maViewTransformation
* maObjectTransformation
);
341 aInverseObjectToView
.invert();
342 const_cast< ImpViewInformation2D
* >(this)->maInverseObjectToViewTransformation
= aInverseObjectToView
;
345 return maInverseObjectToViewTransformation
;
348 double getViewTime() const
353 const uno::Reference
< drawing::XDrawPage
>& getVisualizedPage() const
355 return mxVisualizedPage
;
358 const uno::Sequence
< beans::PropertyValue
>& getViewInformationSequence() const
360 if(!mxViewInformation
.hasElements())
362 const_cast< ImpViewInformation2D
* >(this)->impFillViewInformationFromContent();
365 return mxViewInformation
;
368 const uno::Sequence
< beans::PropertyValue
>& getExtendedInformationSequence() const
370 return mxExtendedInformation
;
373 bool operator==(const ImpViewInformation2D
& rCandidate
) const
375 return (maObjectTransformation
== rCandidate
.maObjectTransformation
376 && maViewTransformation
== rCandidate
.maViewTransformation
377 && maViewport
== rCandidate
.maViewport
378 && mxVisualizedPage
== rCandidate
.mxVisualizedPage
379 && mfViewTime
== rCandidate
.mfViewTime
380 && mxExtendedInformation
== rCandidate
.mxExtendedInformation
);
383 } // end of anonymous namespace
384 } // end of namespace drawinglayer
386 //////////////////////////////////////////////////////////////////////////////
388 namespace drawinglayer
392 ViewInformation2D::ViewInformation2D(
393 const basegfx::B2DHomMatrix
& rObjectTransformation
,
394 const basegfx::B2DHomMatrix
& rViewTransformation
,
395 const basegfx::B2DRange
& rViewport
,
396 const uno::Reference
< drawing::XDrawPage
>& rxDrawPage
,
398 const uno::Sequence
< beans::PropertyValue
>& rExtendedParameters
)
399 : mpViewInformation2D(new ImpViewInformation2D(
400 rObjectTransformation
,
405 rExtendedParameters
))
409 ViewInformation2D::ViewInformation2D(const uno::Sequence
< beans::PropertyValue
>& rViewParameters
)
410 : mpViewInformation2D(new ImpViewInformation2D(rViewParameters
))
414 ViewInformation2D::ViewInformation2D(const ViewInformation2D
& rCandidate
)
415 : mpViewInformation2D(rCandidate
.mpViewInformation2D
)
417 ::osl::Mutex m_mutex
;
418 mpViewInformation2D
->mnRefCount
++;
421 ViewInformation2D::~ViewInformation2D()
423 ::osl::Mutex m_mutex
;
425 if(mpViewInformation2D
->mnRefCount
)
427 mpViewInformation2D
->mnRefCount
--;
431 delete mpViewInformation2D
;
435 ViewInformation2D
& ViewInformation2D::operator=(const ViewInformation2D
& rCandidate
)
437 ::osl::Mutex m_mutex
;
439 if(mpViewInformation2D
->mnRefCount
)
441 mpViewInformation2D
->mnRefCount
--;
445 delete mpViewInformation2D
;
448 mpViewInformation2D
= rCandidate
.mpViewInformation2D
;
449 mpViewInformation2D
->mnRefCount
++;
454 bool ViewInformation2D::operator==(const ViewInformation2D
& rCandidate
) const
456 if(rCandidate
.mpViewInformation2D
== mpViewInformation2D
)
461 return (*rCandidate
.mpViewInformation2D
== *mpViewInformation2D
);
464 const basegfx::B2DHomMatrix
& ViewInformation2D::getObjectTransformation() const
466 return mpViewInformation2D
->getObjectTransformation();
469 const basegfx::B2DHomMatrix
& ViewInformation2D::getViewTransformation() const
471 return mpViewInformation2D
->getViewTransformation();
474 const basegfx::B2DRange
& ViewInformation2D::getViewport() const
476 return mpViewInformation2D
->getViewport();
479 double ViewInformation2D::getViewTime() const
481 return mpViewInformation2D
->getViewTime();
484 const uno::Reference
< drawing::XDrawPage
>& ViewInformation2D::getVisualizedPage() const
486 return mpViewInformation2D
->getVisualizedPage();
489 const basegfx::B2DHomMatrix
& ViewInformation2D::getObjectToViewTransformation() const
491 return mpViewInformation2D
->getObjectToViewTransformation();
494 const basegfx::B2DHomMatrix
& ViewInformation2D::getInverseObjectToViewTransformation() const
496 return mpViewInformation2D
->getInverseObjectToViewTransformation();
499 const basegfx::B2DRange
& ViewInformation2D::getDiscreteViewport() const
501 return mpViewInformation2D
->getDiscreteViewport();
504 const uno::Sequence
< beans::PropertyValue
>& ViewInformation2D::getViewInformationSequence() const
506 return mpViewInformation2D
->getViewInformationSequence();
509 const uno::Sequence
< beans::PropertyValue
>& ViewInformation2D::getExtendedInformationSequence() const
511 return mpViewInformation2D
->getExtendedInformationSequence();
513 } // end of namespace geometry
514 } // end of namespace drawinglayer
516 //////////////////////////////////////////////////////////////////////////////