1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
21 #include <drawinglayer/geometry/viewinformation3d.hxx>
22 #include <basegfx/tools/canvastools.hxx>
24 //////////////////////////////////////////////////////////////////////////////
26 using namespace com::sun::star
;
28 //////////////////////////////////////////////////////////////////////////////
30 namespace drawinglayer
34 BasePrimitive3D::BasePrimitive3D()
35 : BasePrimitive3DImplBase(m_aMutex
)
39 BasePrimitive3D::~BasePrimitive3D()
43 bool BasePrimitive3D::operator==( const BasePrimitive3D
& rPrimitive
) const
45 return (getPrimitive3DID() == rPrimitive
.getPrimitive3DID());
48 basegfx::B3DRange
BasePrimitive3D::getB3DRange(const geometry::ViewInformation3D
& rViewInformation
) const
50 return getB3DRangeFromPrimitive3DSequence(get3DDecomposition(rViewInformation
), rViewInformation
);
53 Primitive3DSequence
BasePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D
& /*rViewInformation*/) const
55 return Primitive3DSequence();
58 Primitive3DSequence SAL_CALL
BasePrimitive3D::getDecomposition( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
) throw ( uno::RuntimeException
)
60 const geometry::ViewInformation3D
aViewInformation(rViewParameters
);
61 return get3DDecomposition(aViewInformation
);
64 com::sun::star::geometry::RealRectangle3D SAL_CALL
BasePrimitive3D::getRange( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
) throw ( uno::RuntimeException
)
66 const geometry::ViewInformation3D
aViewInformation(rViewParameters
);
67 return basegfx::unotools::rectangle3DFromB3DRectangle(getB3DRange(aViewInformation
));
69 } // end of namespace primitive3d
70 } // end of namespace drawinglayer
72 //////////////////////////////////////////////////////////////////////////////
74 namespace drawinglayer
78 Primitive3DSequence
BufferedDecompositionPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D
& /*rViewInformation*/) const
80 return Primitive3DSequence();
83 BufferedDecompositionPrimitive3D::BufferedDecompositionPrimitive3D()
85 maBuffered3DDecomposition()
89 Primitive3DSequence
BufferedDecompositionPrimitive3D::get3DDecomposition(const geometry::ViewInformation3D
& rViewInformation
) const
91 ::osl::MutexGuard
aGuard( m_aMutex
);
93 if(!getBuffered3DDecomposition().hasElements())
95 const Primitive3DSequence
aNewSequence(create3DDecomposition(rViewInformation
));
96 const_cast< BufferedDecompositionPrimitive3D
* >(this)->setBuffered3DDecomposition(aNewSequence
);
99 return getBuffered3DDecomposition();
101 } // end of namespace primitive3d
102 } // end of namespace drawinglayer
104 //////////////////////////////////////////////////////////////////////////////
107 namespace drawinglayer
109 namespace primitive3d
111 // get range3D from a given Primitive3DReference
112 basegfx::B3DRange
getB3DRangeFromPrimitive3DReference(const Primitive3DReference
& rCandidate
, const geometry::ViewInformation3D
& aViewInformation
)
114 basegfx::B3DRange aRetval
;
118 // try to get C++ implementation base
119 const BasePrimitive3D
* pCandidate(dynamic_cast< BasePrimitive3D
* >(rCandidate
.get()));
123 // use it if possible
124 aRetval
.expand(pCandidate
->getB3DRange(aViewInformation
));
128 // use UNO API call instead
129 const uno::Sequence
< beans::PropertyValue
>& rViewParameters(aViewInformation
.getViewInformationSequence());
130 aRetval
.expand(basegfx::unotools::b3DRectangleFromRealRectangle3D(rCandidate
->getRange(rViewParameters
)));
137 // get range3D from a given Primitive3DSequence
138 basegfx::B3DRange
getB3DRangeFromPrimitive3DSequence(const Primitive3DSequence
& rCandidate
, const geometry::ViewInformation3D
& aViewInformation
)
140 basegfx::B3DRange aRetval
;
142 if(rCandidate
.hasElements())
144 const sal_Int32
nCount(rCandidate
.getLength());
146 for(sal_Int32
a(0L); a
< nCount
; a
++)
148 aRetval
.expand(getB3DRangeFromPrimitive3DReference(rCandidate
[a
], aViewInformation
));
155 bool arePrimitive3DReferencesEqual(const Primitive3DReference
& rxA
, const Primitive3DReference
& rxB
)
157 const sal_Bool
bAIs(rxA
.is());
169 const BasePrimitive3D
* pA(dynamic_cast< const BasePrimitive3D
* >(rxA
.get()));
170 const BasePrimitive3D
* pB(dynamic_cast< const BasePrimitive3D
* >(rxB
.get()));
171 const bool bAEqualZero(pA
== 0L);
173 if(bAEqualZero
!= (pB
== 0L))
183 return (pA
->operator==(*pB
));
186 bool arePrimitive3DSequencesEqual(const Primitive3DSequence
& rA
, const Primitive3DSequence
& rB
)
188 const sal_Bool
bAHasElements(rA
.hasElements());
190 if(bAHasElements
!= rB
.hasElements())
200 const sal_Int32
nCount(rA
.getLength());
202 if(nCount
!= rB
.getLength())
207 for(sal_Int32
a(0L); a
< nCount
; a
++)
209 if(!arePrimitive3DReferencesEqual(rA
[a
], rB
[a
]))
218 // concatenate sequence
219 void appendPrimitive3DSequenceToPrimitive3DSequence(Primitive3DSequence
& rDest
, const Primitive3DSequence
& rSource
)
221 if(rSource
.hasElements())
223 if(rDest
.hasElements())
225 const sal_Int32
nSourceCount(rSource
.getLength());
226 const sal_Int32
nDestCount(rDest
.getLength());
227 const sal_Int32
nTargetCount(nSourceCount
+ nDestCount
);
228 sal_Int32
nInsertPos(nDestCount
);
230 rDest
.realloc(nTargetCount
);
232 for(sal_Int32
a(0L); a
< nSourceCount
; a
++)
236 rDest
[nInsertPos
++] = rSource
[a
];
240 if(nInsertPos
!= nTargetCount
)
242 rDest
.realloc(nInsertPos
);
252 // concatenate single Primitive3D
253 void appendPrimitive3DReferenceToPrimitive3DSequence(Primitive3DSequence
& rDest
, const Primitive3DReference
& rSource
)
257 const sal_Int32
nDestCount(rDest
.getLength());
258 rDest
.realloc(nDestCount
+ 1L);
259 rDest
[nDestCount
] = rSource
;
263 } // end of namespace primitive3d
264 } // end of namespace drawinglayer
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */