Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
21 : : #include <drawinglayer/geometry/viewinformation3d.hxx>
22 : : #include <basegfx/tools/canvastools.hxx>
23 : :
24 : : //////////////////////////////////////////////////////////////////////////////
25 : :
26 : : using namespace com::sun::star;
27 : :
28 : : //////////////////////////////////////////////////////////////////////////////
29 : :
30 : : namespace drawinglayer
31 : : {
32 : : namespace primitive3d
33 : : {
34 : 21641 : BasePrimitive3D::BasePrimitive3D()
35 [ + - ]: 21641 : : BasePrimitive3DImplBase(m_aMutex)
36 : : {
37 : 21641 : }
38 : :
39 [ + - ][ + - ]: 21641 : BasePrimitive3D::~BasePrimitive3D()
40 : : {
41 [ - + ]: 21641 : }
42 : :
43 : 11452 : bool BasePrimitive3D::operator==( const BasePrimitive3D& rPrimitive ) const
44 : : {
45 : 11452 : return (getPrimitive3DID() == rPrimitive.getPrimitive3DID());
46 : : }
47 : :
48 : 0 : basegfx::B3DRange BasePrimitive3D::getB3DRange(const geometry::ViewInformation3D& rViewInformation) const
49 : : {
50 [ # # ]: 0 : return getB3DRangeFromPrimitive3DSequence(get3DDecomposition(rViewInformation), rViewInformation);
51 : : }
52 : :
53 : 0 : Primitive3DSequence BasePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
54 : : {
55 : 0 : return Primitive3DSequence();
56 : : }
57 : :
58 : 0 : Primitive3DSequence SAL_CALL BasePrimitive3D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
59 : : {
60 [ # # ]: 0 : const geometry::ViewInformation3D aViewInformation(rViewParameters);
61 [ # # ][ # # ]: 0 : return get3DDecomposition(aViewInformation);
62 : : }
63 : :
64 : 0 : com::sun::star::geometry::RealRectangle3D SAL_CALL BasePrimitive3D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
65 : : {
66 [ # # ]: 0 : const geometry::ViewInformation3D aViewInformation(rViewParameters);
67 [ # # ][ # # ]: 0 : return basegfx::unotools::rectangle3DFromB3DRectangle(getB3DRange(aViewInformation));
[ # # ]
68 : : }
69 : : } // end of namespace primitive3d
70 : : } // end of namespace drawinglayer
71 : :
72 : : //////////////////////////////////////////////////////////////////////////////
73 : :
74 : : namespace drawinglayer
75 : : {
76 : : namespace primitive3d
77 : : {
78 : 0 : Primitive3DSequence BufferedDecompositionPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
79 : : {
80 : 0 : return Primitive3DSequence();
81 : : }
82 : :
83 : 13409 : BufferedDecompositionPrimitive3D::BufferedDecompositionPrimitive3D()
84 : : : BasePrimitive3D(),
85 [ + - ]: 13409 : maBuffered3DDecomposition()
86 : : {
87 : 13409 : }
88 : :
89 : 1134 : Primitive3DSequence BufferedDecompositionPrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
90 : : {
91 [ + - ]: 1134 : ::osl::MutexGuard aGuard( m_aMutex );
92 : :
93 [ + + ]: 1134 : if(!getBuffered3DDecomposition().hasElements())
94 : : {
95 [ + - ]: 321 : const Primitive3DSequence aNewSequence(create3DDecomposition(rViewInformation));
96 [ + - ][ + - ]: 321 : const_cast< BufferedDecompositionPrimitive3D* >(this)->setBuffered3DDecomposition(aNewSequence);
97 : : }
98 : :
99 [ + - ][ + - ]: 1134 : return getBuffered3DDecomposition();
100 : : }
101 : : } // end of namespace primitive3d
102 : : } // end of namespace drawinglayer
103 : :
104 : : //////////////////////////////////////////////////////////////////////////////
105 : : // tooling
106 : :
107 : : namespace drawinglayer
108 : : {
109 : : namespace primitive3d
110 : : {
111 : : // get range3D from a given Primitive3DReference
112 : 21143 : basegfx::B3DRange getB3DRangeFromPrimitive3DReference(const Primitive3DReference& rCandidate, const geometry::ViewInformation3D& aViewInformation)
113 : : {
114 : 21143 : basegfx::B3DRange aRetval;
115 : :
116 [ + - ]: 21143 : if(rCandidate.is())
117 : : {
118 : : // try to get C++ implementation base
119 [ + - ]: 21143 : const BasePrimitive3D* pCandidate(dynamic_cast< BasePrimitive3D* >(rCandidate.get()));
120 : :
121 [ + - ]: 21143 : if(pCandidate)
122 : : {
123 : : // use it if possible
124 [ + - ]: 21143 : aRetval.expand(pCandidate->getB3DRange(aViewInformation));
125 : : }
126 : : else
127 : : {
128 : : // use UNO API call instead
129 : 0 : const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence());
130 [ # # ][ # # ]: 0 : aRetval.expand(basegfx::unotools::b3DRectangleFromRealRectangle3D(rCandidate->getRange(rViewParameters)));
131 : : }
132 : : }
133 : :
134 : 21143 : return aRetval;
135 : : }
136 : :
137 : : // get range3D from a given Primitive3DSequence
138 : 11295 : basegfx::B3DRange getB3DRangeFromPrimitive3DSequence(const Primitive3DSequence& rCandidate, const geometry::ViewInformation3D& aViewInformation)
139 : : {
140 : 11295 : basegfx::B3DRange aRetval;
141 : :
142 [ + + ]: 11295 : if(rCandidate.hasElements())
143 : : {
144 : 9981 : const sal_Int32 nCount(rCandidate.getLength());
145 : :
146 [ + + ]: 31124 : for(sal_Int32 a(0L); a < nCount; a++)
147 : : {
148 [ + - ]: 21143 : aRetval.expand(getB3DRangeFromPrimitive3DReference(rCandidate[a], aViewInformation));
149 : : }
150 : : }
151 : :
152 : 11295 : return aRetval;
153 : : }
154 : :
155 : 11452 : bool arePrimitive3DReferencesEqual(const Primitive3DReference& rxA, const Primitive3DReference& rxB)
156 : : {
157 : 11452 : const sal_Bool bAIs(rxA.is());
158 : :
159 [ - + ]: 11452 : if(bAIs != rxB.is())
160 : : {
161 : 0 : return false;
162 : : }
163 : :
164 [ - + ]: 11452 : if(!bAIs)
165 : : {
166 : 0 : return true;
167 : : }
168 : :
169 [ - + ]: 11452 : const BasePrimitive3D* pA(dynamic_cast< const BasePrimitive3D* >(rxA.get()));
170 [ - + ]: 11452 : const BasePrimitive3D* pB(dynamic_cast< const BasePrimitive3D* >(rxB.get()));
171 : 11452 : const bool bAEqualZero(pA == 0L);
172 : :
173 [ - + ]: 11452 : if(bAEqualZero != (pB == 0L))
174 : : {
175 : 0 : return false;
176 : : }
177 : :
178 [ - + ]: 11452 : if(bAEqualZero)
179 : : {
180 : 0 : return false;
181 : : }
182 : :
183 : 11452 : return (pA->operator==(*pB));
184 : : }
185 : :
186 : 13391 : bool arePrimitive3DSequencesEqual(const Primitive3DSequence& rA, const Primitive3DSequence& rB)
187 : : {
188 : 13391 : const sal_Bool bAHasElements(rA.hasElements());
189 : :
190 [ + + ]: 13391 : if(bAHasElements != rB.hasElements())
191 : : {
192 : 1939 : return false;
193 : : }
194 : :
195 [ - + ]: 11452 : if(!bAHasElements)
196 : : {
197 : 0 : return true;
198 : : }
199 : :
200 : 11452 : const sal_Int32 nCount(rA.getLength());
201 : :
202 [ - + ]: 11452 : if(nCount != rB.getLength())
203 : : {
204 : 0 : return false;
205 : : }
206 : :
207 [ + + ]: 20970 : for(sal_Int32 a(0L); a < nCount; a++)
208 : : {
209 [ + + ]: 11452 : if(!arePrimitive3DReferencesEqual(rA[a], rB[a]))
210 : : {
211 : 1934 : return false;
212 : : }
213 : : }
214 : :
215 : 13391 : return true;
216 : : }
217 : :
218 : : // concatenate sequence
219 : 10542 : void appendPrimitive3DSequenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DSequence& rSource)
220 : : {
221 [ + - ]: 10542 : if(rSource.hasElements())
222 : : {
223 [ + + ]: 10542 : if(rDest.hasElements())
224 : : {
225 : 8863 : const sal_Int32 nSourceCount(rSource.getLength());
226 : 8863 : const sal_Int32 nDestCount(rDest.getLength());
227 : 8863 : const sal_Int32 nTargetCount(nSourceCount + nDestCount);
228 : 8863 : sal_Int32 nInsertPos(nDestCount);
229 : :
230 : 8863 : rDest.realloc(nTargetCount);
231 : :
232 [ + + ]: 17726 : for(sal_Int32 a(0L); a < nSourceCount; a++)
233 : : {
234 [ + - ]: 8863 : if(rSource[a].is())
235 : : {
236 : 8863 : rDest[nInsertPos++] = rSource[a];
237 : : }
238 : : }
239 : :
240 [ - + ]: 8863 : if(nInsertPos != nTargetCount)
241 : : {
242 : 0 : rDest.realloc(nInsertPos);
243 : : }
244 : : }
245 : : else
246 : : {
247 : 1679 : rDest = rSource;
248 : : }
249 : : }
250 : 10542 : }
251 : :
252 : : // concatenate single Primitive3D
253 : 5504 : void appendPrimitive3DReferenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DReference& rSource)
254 : : {
255 [ + - ]: 5504 : if(rSource.is())
256 : : {
257 : 5504 : const sal_Int32 nDestCount(rDest.getLength());
258 : 5504 : rDest.realloc(nDestCount + 1L);
259 : 5504 : rDest[nDestCount] = rSource;
260 : : }
261 : 5504 : }
262 : :
263 : : } // end of namespace primitive3d
264 : : } // end of namespace drawinglayer
265 : :
266 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|