1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: baseprimitive3d.cxx,v $
9 * last change: $Author: aw $ $Date: 2008-06-10 09:29:33 $
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/primitive3d/baseprimitive3d.hxx>
40 #include <drawinglayer/geometry/viewinformation3d.hxx>
41 #include <basegfx/tools/canvastools.hxx>
43 //////////////////////////////////////////////////////////////////////////////
45 using namespace com::sun::star
;
47 //////////////////////////////////////////////////////////////////////////////
49 namespace drawinglayer
53 Primitive3DSequence
BasePrimitive3D::createLocalDecomposition(const geometry::ViewInformation3D
& /*rViewInformation*/) const
55 return Primitive3DSequence();
58 BasePrimitive3D::BasePrimitive3D()
59 : BasePrimitive3DImplBase(m_aMutex
),
60 maLocalDecomposition()
64 bool BasePrimitive3D::operator==( const BasePrimitive3D
& rPrimitive
) const
66 return (getPrimitiveID() == rPrimitive
.getPrimitiveID());
69 basegfx::B3DRange
BasePrimitive3D::getB3DRange(const geometry::ViewInformation3D
& rViewInformation
) const
71 return getB3DRangeFromPrimitive3DSequence(get3DDecomposition(rViewInformation
), rViewInformation
);
74 Primitive3DSequence
BasePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D
& rViewInformation
) const
76 ::osl::MutexGuard
aGuard( m_aMutex
);
78 if(!getLocalDecomposition().hasElements())
80 const Primitive3DSequence
aNewSequence(createLocalDecomposition(rViewInformation
));
81 const_cast< BasePrimitive3D
* >(this)->setLocalDecomposition(aNewSequence
);
84 return getLocalDecomposition();
87 Primitive3DSequence SAL_CALL
BasePrimitive3D::getDecomposition( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
) throw ( uno::RuntimeException
)
89 const geometry::ViewInformation3D
aViewInformation(rViewParameters
);
90 return get3DDecomposition(rViewParameters
);
93 com::sun::star::geometry::RealRectangle3D SAL_CALL
BasePrimitive3D::getRange( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
) throw ( uno::RuntimeException
)
95 const geometry::ViewInformation3D
aViewInformation(rViewParameters
);
96 return basegfx::unotools::rectangle3DFromB3DRectangle(getB3DRange(aViewInformation
));
98 } // end of namespace primitive3d
99 } // end of namespace drawinglayer
101 //////////////////////////////////////////////////////////////////////////////
104 namespace drawinglayer
106 namespace primitive3d
108 // get range3D from a given Primitive3DReference
109 basegfx::B3DRange
getB3DRangeFromPrimitive3DReference(const Primitive3DReference
& rCandidate
, const geometry::ViewInformation3D
& aViewInformation
)
111 basegfx::B3DRange aRetval
;
115 // try to get C++ implementation base
116 const BasePrimitive3D
* pCandidate(dynamic_cast< BasePrimitive3D
* >(rCandidate
.get()));
120 // use it if possible
121 aRetval
.expand(pCandidate
->getB3DRange(aViewInformation
));
125 // use UNO API call instead
126 const uno::Sequence
< beans::PropertyValue
>& rViewParameters(aViewInformation
.getViewInformationSequence());
127 aRetval
.expand(basegfx::unotools::b3DRectangleFromRealRectangle3D(rCandidate
->getRange(rViewParameters
)));
134 // get range3D from a given Primitive3DSequence
135 basegfx::B3DRange
getB3DRangeFromPrimitive3DSequence(const Primitive3DSequence
& rCandidate
, const geometry::ViewInformation3D
& aViewInformation
)
137 basegfx::B3DRange aRetval
;
139 if(rCandidate
.hasElements())
141 const sal_Int32
nCount(rCandidate
.getLength());
143 for(sal_Int32
a(0L); a
< nCount
; a
++)
145 aRetval
.expand(getB3DRangeFromPrimitive3DReference(rCandidate
[a
], aViewInformation
));
152 bool arePrimitive3DReferencesEqual(const Primitive3DReference
& rxA
, const Primitive3DReference
& rxB
)
154 const sal_Bool
bAIs(rxA
.is());
166 const BasePrimitive3D
* pA(dynamic_cast< const BasePrimitive3D
* >(rxA
.get()));
167 const BasePrimitive3D
* pB(dynamic_cast< const BasePrimitive3D
* >(rxB
.get()));
168 const bool bAEqualZero(pA
== 0L);
170 if(bAEqualZero
!= (pB
== 0L))
180 return (pA
->operator==(*pB
));
183 bool arePrimitive3DSequencesEqual(const Primitive3DSequence
& rA
, const Primitive3DSequence
& rB
)
185 const sal_Bool
bAHasElements(rA
.hasElements());
187 if(bAHasElements
!= rB
.hasElements())
197 const sal_Int32
nCount(rA
.getLength());
199 if(nCount
!= rB
.getLength())
204 for(sal_Int32
a(0L); a
< nCount
; a
++)
206 if(!arePrimitive3DReferencesEqual(rA
[a
], rB
[a
]))
215 // concatenate sequence
216 void appendPrimitive3DSequenceToPrimitive3DSequence(Primitive3DSequence
& rDest
, const Primitive3DSequence
& rSource
)
218 if(rSource
.hasElements())
220 if(rDest
.hasElements())
222 const sal_Int32
nSourceCount(rSource
.getLength());
223 const sal_Int32
nDestCount(rDest
.getLength());
224 const sal_Int32
nTargetCount(nSourceCount
+ nDestCount
);
225 sal_Int32
nInsertPos(nDestCount
);
227 rDest
.realloc(nTargetCount
);
229 for(sal_Int32
a(0L); a
< nSourceCount
; a
++)
233 rDest
[nInsertPos
++] = rSource
[a
];
237 if(nInsertPos
!= nTargetCount
)
239 rDest
.realloc(nInsertPos
);
249 // concatenate single Primitive3D
250 void appendPrimitive3DReferenceToPrimitive3DSequence(Primitive3DSequence
& rDest
, const Primitive3DReference
& rSource
)
254 const sal_Int32
nDestCount(rDest
.getLength());
255 rDest
.realloc(nDestCount
+ 1L);
256 rDest
[nDestCount
] = rSource
;
260 } // end of namespace primitive3d
261 } // end of namespace drawinglayer
263 //////////////////////////////////////////////////////////////////////////////