1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: baseprimitive2d.cxx,v $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:20 $
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/primitive2d/baseprimitive2d.hxx>
40 #include <drawinglayer/geometry/viewinformation2d.hxx>
41 #include <basegfx/tools/canvastools.hxx>
43 //////////////////////////////////////////////////////////////////////////////
45 using namespace com::sun::star
;
47 //////////////////////////////////////////////////////////////////////////////
49 namespace drawinglayer
53 Primitive2DSequence
BasePrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
55 return Primitive2DSequence();
58 BasePrimitive2D::BasePrimitive2D()
59 : BasePrimitive2DImplBase(m_aMutex
),
60 maLocalDecomposition()
64 bool BasePrimitive2D::operator==( const BasePrimitive2D
& rPrimitive
) const
66 return (getPrimitiveID() == rPrimitive
.getPrimitiveID());
69 basegfx::B2DRange
BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const
71 return getB2DRangeFromPrimitive2DSequence(get2DDecomposition(rViewInformation
), rViewInformation
);
74 Primitive2DSequence
BasePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
76 ::osl::MutexGuard
aGuard( m_aMutex
);
78 if(!getLocalDecomposition().hasElements())
80 const Primitive2DSequence
aNewSequence(createLocalDecomposition(rViewInformation
));
81 const_cast< BasePrimitive2D
* >(this)->setLocalDecomposition(aNewSequence
);
84 return getLocalDecomposition();
87 Primitive2DSequence SAL_CALL
BasePrimitive2D::getDecomposition( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
) throw ( uno::RuntimeException
)
89 const geometry::ViewInformation2D
aViewInformation(rViewParameters
);
90 return get2DDecomposition(aViewInformation
);
93 com::sun::star::geometry::RealRectangle2D SAL_CALL
BasePrimitive2D::getRange( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
) throw ( uno::RuntimeException
)
95 const geometry::ViewInformation2D
aViewInformation(rViewParameters
);
96 return basegfx::unotools::rectangle2DFromB2DRectangle(getB2DRange(aViewInformation
));
98 } // end of namespace primitive2d
99 } // end of namespace drawinglayer
101 //////////////////////////////////////////////////////////////////////////////
104 namespace drawinglayer
106 namespace primitive2d
108 // get B2DRange from a given Primitive2DReference
109 basegfx::B2DRange
getB2DRangeFromPrimitive2DReference(const Primitive2DReference
& rCandidate
, const geometry::ViewInformation2D
& aViewInformation
)
111 basegfx::B2DRange aRetval
;
115 // try to get C++ implementation base
116 const BasePrimitive2D
* pCandidate(dynamic_cast< BasePrimitive2D
* >(rCandidate
.get()));
120 // use it if possible
121 aRetval
.expand(pCandidate
->getB2DRange(aViewInformation
));
125 // use UNO API call instead
126 const uno::Sequence
< beans::PropertyValue
>& rViewParameters(aViewInformation
.getViewInformationSequence());
127 aRetval
.expand(basegfx::unotools::b2DRectangleFromRealRectangle2D(rCandidate
->getRange(rViewParameters
)));
134 // get B2DRange from a given Primitive2DSequence
135 basegfx::B2DRange
getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence
& rCandidate
, const geometry::ViewInformation2D
& aViewInformation
)
137 basegfx::B2DRange aRetval
;
139 if(rCandidate
.hasElements())
141 const sal_Int32
nCount(rCandidate
.getLength());
143 for(sal_Int32
a(0L); a
< nCount
; a
++)
145 aRetval
.expand(getB2DRangeFromPrimitive2DReference(rCandidate
[a
], aViewInformation
));
152 bool arePrimitive2DReferencesEqual(const Primitive2DReference
& rxA
, const Primitive2DReference
& rxB
)
154 const sal_Bool
bAIs(rxA
.is());
166 const BasePrimitive2D
* pA(dynamic_cast< const BasePrimitive2D
* >(rxA
.get()));
167 const BasePrimitive2D
* pB(dynamic_cast< const BasePrimitive2D
* >(rxB
.get()));
168 const bool bAEqualZero(pA
== 0L);
170 if(bAEqualZero
!= (pB
== 0L))
180 return (pA
->operator==(*pB
));
183 bool arePrimitive2DSequencesEqual(const Primitive2DSequence
& rA
, const Primitive2DSequence
& 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(!arePrimitive2DReferencesEqual(rA
[a
], rB
[a
]))
215 // concatenate sequence
216 void appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence
& rDest
, const Primitive2DSequence
& 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 Primitive2D
250 void appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence
& rDest
, const Primitive2DReference
& rSource
)
254 const sal_Int32
nDestCount(rDest
.getLength());
255 rDest
.realloc(nDestCount
+ 1L);
256 rDest
[nDestCount
] = rSource
;
260 } // end of namespace primitive2d
261 } // end of namespace drawinglayer
263 //////////////////////////////////////////////////////////////////////////////