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/utils/canvastools.hxx>
23 #include <comphelper/sequence.hxx>
26 using namespace com::sun::star
;
29 namespace drawinglayer
33 BasePrimitive3D::BasePrimitive3D()
34 : BasePrimitive3DImplBase(m_aMutex
)
38 BasePrimitive3D::~BasePrimitive3D()
42 bool BasePrimitive3D::operator==( const BasePrimitive3D
& rPrimitive
) const
44 return (getPrimitive3DID() == rPrimitive
.getPrimitive3DID());
47 basegfx::B3DRange
BasePrimitive3D::getB3DRange(const geometry::ViewInformation3D
& rViewInformation
) const
49 return get3DDecomposition(rViewInformation
).getB3DRange(rViewInformation
);
52 Primitive3DContainer
BasePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D
& /*rViewInformation*/) const
54 return Primitive3DContainer();
57 css::uno::Sequence
< ::css::uno::Reference
< ::css::graphic::XPrimitive3D
> > SAL_CALL
BasePrimitive3D::getDecomposition( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
)
59 const geometry::ViewInformation3D
aViewInformation(rViewParameters
);
60 return comphelper::containerToSequence(get3DDecomposition(aViewInformation
));
63 css::geometry::RealRectangle3D SAL_CALL
BasePrimitive3D::getRange( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
)
65 const geometry::ViewInformation3D
aViewInformation(rViewParameters
);
66 return basegfx::unotools::rectangle3DFromB3DRectangle(getB3DRange(aViewInformation
));
68 } // end of namespace primitive3d
69 } // end of namespace drawinglayer
72 namespace drawinglayer
76 Primitive3DContainer
BufferedDecompositionPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D
& /*rViewInformation*/) const
78 return Primitive3DContainer();
81 BufferedDecompositionPrimitive3D::BufferedDecompositionPrimitive3D()
83 maBuffered3DDecomposition()
87 Primitive3DContainer
BufferedDecompositionPrimitive3D::get3DDecomposition(const geometry::ViewInformation3D
& rViewInformation
) const
89 ::osl::MutexGuard
aGuard( m_aMutex
);
91 if(getBuffered3DDecomposition().empty())
93 const Primitive3DContainer
aNewSequence(create3DDecomposition(rViewInformation
));
94 const_cast< BufferedDecompositionPrimitive3D
* >(this)->setBuffered3DDecomposition(aNewSequence
);
97 return getBuffered3DDecomposition();
99 } // end of namespace primitive3d
100 } // end of namespace drawinglayer
105 namespace drawinglayer
107 namespace primitive3d
109 // get range3D from a given Primitive3DReference
110 basegfx::B3DRange
getB3DRangeFromPrimitive3DReference(const Primitive3DReference
& rCandidate
, const geometry::ViewInformation3D
& aViewInformation
)
112 basegfx::B3DRange aRetval
;
116 // try to get C++ implementation base
117 const BasePrimitive3D
* pCandidate(dynamic_cast< BasePrimitive3D
* >(rCandidate
.get()));
121 // use it if possible
122 aRetval
.expand(pCandidate
->getB3DRange(aViewInformation
));
126 // use UNO API call instead
127 const uno::Sequence
< beans::PropertyValue
>& rViewParameters(aViewInformation
.getViewInformationSequence());
128 aRetval
.expand(basegfx::unotools::b3DRectangleFromRealRectangle3D(rCandidate
->getRange(rViewParameters
)));
135 // get range3D from a given Primitive3DContainer
136 basegfx::B3DRange
Primitive3DContainer::getB3DRange(const geometry::ViewInformation3D
& aViewInformation
) const
138 basegfx::B3DRange aRetval
;
142 const size_t nCount(size());
144 for(size_t a(0); a
< nCount
; a
++)
146 aRetval
.expand(getB3DRangeFromPrimitive3DReference((*this)[a
], aViewInformation
));
153 bool arePrimitive3DReferencesEqual(const Primitive3DReference
& rxA
, const Primitive3DReference
& rxB
)
155 const bool bAIs(rxA
.is());
167 const BasePrimitive3D
* pA(dynamic_cast< const BasePrimitive3D
* >(rxA
.get()));
168 const BasePrimitive3D
* pB(dynamic_cast< const BasePrimitive3D
* >(rxB
.get()));
175 return pA
->operator==(*pB
);
178 bool Primitive3DContainer::operator==(const Primitive3DContainer
& rB
) const
180 const bool bAHasElements(!empty());
182 if(bAHasElements
!= !rB
.empty())
192 const size_t nCount(size());
194 if(nCount
!= rB
.size())
199 for(size_t a(0); a
< nCount
; a
++)
201 if(!arePrimitive3DReferencesEqual((*this)[a
], rB
[a
]))
210 void Primitive3DContainer::append(const Primitive3DContainer
& rSource
)
212 insert(end(), rSource
.begin(), rSource
.end());
215 } // end of namespace primitive3d
216 } // end of namespace drawinglayer
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */