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 "Stripe.hxx"
21 : #include "CommonConverters.hxx"
22 : #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
23 : #include <com/sun/star/drawing/DoubleSequence.hpp>
24 : #include <basegfx/polygon/b3dpolygon.hxx>
25 : #include <basegfx/polygon/b3dpolygontools.hxx>
26 :
27 : using namespace ::com::sun::star;
28 :
29 : namespace chart
30 : {
31 :
32 165 : Stripe::Stripe( const drawing::Position3D& rPoint1
33 : , const drawing::Direction3D& rDirectionToPoint2
34 : , const drawing::Direction3D& rDirectionToPoint4 )
35 : : m_aPoint1(rPoint1)
36 : , m_aPoint2(rPoint1+rDirectionToPoint2)
37 165 : , m_aPoint3(m_aPoint2+rDirectionToPoint4)
38 : , m_aPoint4(rPoint1+rDirectionToPoint4)
39 : , m_bInvertNormal(false)
40 330 : , m_bManualNormalSet(false)
41 : {
42 165 : }
43 :
44 504 : Stripe::Stripe( const drawing::Position3D& rPoint1
45 : , const drawing::Position3D& rPoint2
46 : , double fDepth )
47 : : m_aPoint1(rPoint1)
48 : , m_aPoint2(rPoint2)
49 : , m_aPoint3(rPoint2)
50 : , m_aPoint4(rPoint1)
51 : , m_bInvertNormal(false)
52 504 : , m_bManualNormalSet(false)
53 : {
54 504 : m_aPoint3.PositionZ += fDepth;
55 504 : m_aPoint4.PositionZ += fDepth;
56 504 : }
57 :
58 0 : Stripe::Stripe( const drawing::Position3D& rPoint1
59 : , const drawing::Position3D& rPoint2
60 : , const drawing::Position3D& rPoint3
61 : , const drawing::Position3D& rPoint4 )
62 : : m_aPoint1(rPoint1)
63 : , m_aPoint2(rPoint2)
64 : , m_aPoint3(rPoint3)
65 : , m_aPoint4(rPoint4)
66 : , m_bInvertNormal(false)
67 0 : , m_bManualNormalSet(false)
68 : {
69 0 : }
70 :
71 0 : void Stripe::SetManualNormal( const drawing::Direction3D& rNormal )
72 : {
73 0 : m_aManualNormal = rNormal;
74 0 : m_bManualNormalSet = true;
75 0 : }
76 :
77 165 : void Stripe::InvertNormal( bool bInvertNormal )
78 : {
79 165 : m_bInvertNormal = bInvertNormal;
80 165 : }
81 :
82 417 : uno::Any Stripe::getPolyPolygonShape3D() const
83 : {
84 417 : drawing::PolyPolygonShape3D aPP;
85 :
86 417 : aPP.SequenceX.realloc(1);
87 417 : aPP.SequenceY.realloc(1);
88 417 : aPP.SequenceZ.realloc(1);
89 :
90 417 : drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
91 417 : drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
92 417 : drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
93 :
94 417 : pOuterSequenceX->realloc(4);
95 417 : pOuterSequenceY->realloc(4);
96 417 : pOuterSequenceZ->realloc(4);
97 :
98 417 : double* pInnerSequenceX = pOuterSequenceX->getArray();
99 417 : double* pInnerSequenceY = pOuterSequenceY->getArray();
100 417 : double* pInnerSequenceZ = pOuterSequenceZ->getArray();
101 :
102 417 : *pInnerSequenceX++ = m_aPoint1.PositionX;
103 417 : *pInnerSequenceY++ = m_aPoint1.PositionY;
104 417 : *pInnerSequenceZ++ = m_aPoint1.PositionZ;
105 :
106 417 : *pInnerSequenceX++ = m_aPoint2.PositionX;
107 417 : *pInnerSequenceY++ = m_aPoint2.PositionY;
108 417 : *pInnerSequenceZ++ = m_aPoint2.PositionZ;
109 :
110 417 : *pInnerSequenceX++ = m_aPoint3.PositionX;
111 417 : *pInnerSequenceY++ = m_aPoint3.PositionY;
112 417 : *pInnerSequenceZ++ = m_aPoint3.PositionZ;
113 :
114 417 : *pInnerSequenceX++ = m_aPoint4.PositionX;
115 417 : *pInnerSequenceY++ = m_aPoint4.PositionY;
116 417 : *pInnerSequenceZ++ = m_aPoint4.PositionZ;
117 :
118 417 : return uno::Any( &aPP, cppu::UnoType<drawing::PolyPolygonShape3D>::get());
119 : }
120 :
121 417 : drawing::Direction3D Stripe::getNormal() const
122 : {
123 417 : drawing::Direction3D aRet(1.0,0.0,0.0);
124 :
125 417 : if( m_bManualNormalSet )
126 0 : aRet = m_aManualNormal;
127 : else
128 : {
129 417 : ::basegfx::B3DPolygon aPolygon3D;
130 417 : aPolygon3D.append(Position3DToB3DPoint( m_aPoint1 ));
131 417 : aPolygon3D.append(Position3DToB3DPoint( m_aPoint2 ));
132 417 : aPolygon3D.append(Position3DToB3DPoint( m_aPoint3 ));
133 417 : aPolygon3D.append(Position3DToB3DPoint( m_aPoint4 ));
134 834 : ::basegfx::B3DVector aNormal(aPolygon3D.getNormal());
135 834 : aRet = B3DVectorToDirection3D(aNormal);
136 : }
137 :
138 417 : if( m_bInvertNormal )
139 : {
140 165 : aRet.DirectionX *= -1.0;
141 165 : aRet.DirectionY *= -1.0;
142 165 : aRet.DirectionZ *= -1.0;
143 : }
144 417 : return aRet;
145 : }
146 :
147 417 : uno::Any Stripe::getNormalsPolygon() const
148 : {
149 417 : drawing::PolyPolygonShape3D aPP;
150 :
151 417 : aPP.SequenceX.realloc(1);
152 417 : aPP.SequenceY.realloc(1);
153 417 : aPP.SequenceZ.realloc(1);
154 :
155 417 : drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
156 417 : drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
157 417 : drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
158 :
159 417 : pOuterSequenceX->realloc(4);
160 417 : pOuterSequenceY->realloc(4);
161 417 : pOuterSequenceZ->realloc(4);
162 :
163 417 : double* pInnerSequenceX = pOuterSequenceX->getArray();
164 417 : double* pInnerSequenceY = pOuterSequenceY->getArray();
165 417 : double* pInnerSequenceZ = pOuterSequenceZ->getArray();
166 :
167 417 : drawing::Direction3D aNormal( getNormal() );
168 :
169 2085 : for(sal_Int32 nN=4; --nN; )
170 : {
171 1251 : *pInnerSequenceX++ = aNormal.DirectionX;
172 1251 : *pInnerSequenceY++ = aNormal.DirectionY;
173 1251 : *pInnerSequenceZ++ = aNormal.DirectionZ;
174 : }
175 417 : return uno::Any( &aPP, cppu::UnoType<drawing::PolyPolygonShape3D>::get());
176 : }
177 :
178 417 : uno::Any Stripe::getTexturePolygon( short nRotatedTexture )
179 : {
180 417 : drawing::PolyPolygonShape3D aPP;
181 :
182 417 : aPP.SequenceX.realloc(1);
183 417 : aPP.SequenceY.realloc(1);
184 417 : aPP.SequenceZ.realloc(1);
185 :
186 417 : drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
187 417 : drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
188 417 : drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
189 :
190 417 : pOuterSequenceX->realloc(4);
191 417 : pOuterSequenceY->realloc(4);
192 417 : pOuterSequenceZ->realloc(4);
193 :
194 417 : double* pInnerSequenceX = pOuterSequenceX->getArray();
195 417 : double* pInnerSequenceY = pOuterSequenceY->getArray();
196 417 : double* pInnerSequenceZ = pOuterSequenceZ->getArray();
197 :
198 417 : if( nRotatedTexture==0 )
199 : {
200 110 : *pInnerSequenceX++ = 0.0;
201 110 : *pInnerSequenceY++ = 0.0;
202 110 : *pInnerSequenceZ++ = 0.0;
203 :
204 110 : *pInnerSequenceX++ = 0.0;
205 110 : *pInnerSequenceY++ = 1.0;
206 110 : *pInnerSequenceZ++ = 0.0;
207 :
208 110 : *pInnerSequenceX++ = 1.0;
209 110 : *pInnerSequenceY++ = 1.0;
210 110 : *pInnerSequenceZ++ = 0.0;
211 :
212 110 : *pInnerSequenceX++ = 1.0;
213 110 : *pInnerSequenceY++ = 0.0;
214 110 : *pInnerSequenceZ++ = 0.0;
215 : }
216 307 : else if( nRotatedTexture==1 )
217 : {
218 307 : *pInnerSequenceX++ = 1.0;
219 307 : *pInnerSequenceY++ = 0.0;
220 307 : *pInnerSequenceZ++ = 0.0;
221 :
222 307 : *pInnerSequenceX++ = 0.0;
223 307 : *pInnerSequenceY++ = 0.0;
224 307 : *pInnerSequenceZ++ = 0.0;
225 :
226 307 : *pInnerSequenceX++ = 0.0;
227 307 : *pInnerSequenceY++ = 1.0;
228 307 : *pInnerSequenceZ++ = 0.0;
229 :
230 307 : *pInnerSequenceX++ = 1.0;
231 307 : *pInnerSequenceY++ = 1.0;
232 307 : *pInnerSequenceZ++ = 0.0;
233 : }
234 0 : else if( nRotatedTexture==2 )
235 : {
236 0 : *pInnerSequenceX++ = 1.0;
237 0 : *pInnerSequenceY++ = 1.0;
238 0 : *pInnerSequenceZ++ = 0.0;
239 :
240 0 : *pInnerSequenceX++ = 1.0;
241 0 : *pInnerSequenceY++ = 0.0;
242 0 : *pInnerSequenceZ++ = 0.0;
243 :
244 0 : *pInnerSequenceX++ = 0.0;
245 0 : *pInnerSequenceY++ = 0.0;
246 0 : *pInnerSequenceZ++ = 0.0;
247 :
248 0 : *pInnerSequenceX++ = 0.0;
249 0 : *pInnerSequenceY++ = 1.0;
250 0 : *pInnerSequenceZ++ = 0.0;
251 : }
252 0 : else if( nRotatedTexture==3 )
253 : {
254 0 : *pInnerSequenceX++ = 0.0;
255 0 : *pInnerSequenceY++ = 1.0;
256 0 : *pInnerSequenceZ++ = 0.0;
257 :
258 0 : *pInnerSequenceX++ = 1.0;
259 0 : *pInnerSequenceY++ = 1.0;
260 0 : *pInnerSequenceZ++ = 0.0;
261 :
262 0 : *pInnerSequenceX++ = 1.0;
263 0 : *pInnerSequenceY++ = 0.0;
264 0 : *pInnerSequenceZ++ = 0.0;
265 :
266 0 : *pInnerSequenceX++ = 0.0;
267 0 : *pInnerSequenceY++ = 0.0;
268 0 : *pInnerSequenceZ++ = 0.0;
269 : }
270 0 : else if( nRotatedTexture==4 )
271 : {
272 0 : *pInnerSequenceX++ = 1.0;
273 0 : *pInnerSequenceY++ = 0.0;
274 0 : *pInnerSequenceZ++ = 0.0;
275 :
276 0 : *pInnerSequenceX++ = 1.0;
277 0 : *pInnerSequenceY++ = 1.0;
278 0 : *pInnerSequenceZ++ = 0.0;
279 :
280 0 : *pInnerSequenceX++ = 0.0;
281 0 : *pInnerSequenceY++ = 1.0;
282 0 : *pInnerSequenceZ++ = 0.0;
283 :
284 0 : *pInnerSequenceX++ = 0.0;
285 0 : *pInnerSequenceY++ = 0.0;
286 0 : *pInnerSequenceZ++ = 0.0;
287 : }
288 0 : else if( nRotatedTexture==5 )
289 : {
290 0 : *pInnerSequenceX++ = 0.0;
291 0 : *pInnerSequenceY++ = 0.0;
292 0 : *pInnerSequenceZ++ = 0.0;
293 :
294 0 : *pInnerSequenceX++ = 1.0;
295 0 : *pInnerSequenceY++ = 0.0;
296 0 : *pInnerSequenceZ++ = 0.0;
297 :
298 0 : *pInnerSequenceX++ = 1.0;
299 0 : *pInnerSequenceY++ = 1.0;
300 0 : *pInnerSequenceZ++ = 0.0;
301 :
302 0 : *pInnerSequenceX++ = 0.0;
303 0 : *pInnerSequenceY++ = 1.0;
304 0 : *pInnerSequenceZ++ = 0.0;
305 : }
306 0 : else if( nRotatedTexture==6 )
307 : {
308 0 : *pInnerSequenceX++ = 0.0;
309 0 : *pInnerSequenceY++ = 1.0;
310 0 : *pInnerSequenceZ++ = 0.0;
311 :
312 0 : *pInnerSequenceX++ = 0.0;
313 0 : *pInnerSequenceY++ = 0.0;
314 0 : *pInnerSequenceZ++ = 0.0;
315 :
316 0 : *pInnerSequenceX++ = 1.0;
317 0 : *pInnerSequenceY++ = 0.0;
318 0 : *pInnerSequenceZ++ = 0.0;
319 :
320 0 : *pInnerSequenceX++ = 1.0;
321 0 : *pInnerSequenceY++ = 1.0;
322 0 : *pInnerSequenceZ++ = 0.0;
323 : }
324 0 : else if( nRotatedTexture==7 )
325 : {
326 0 : *pInnerSequenceX++ = 1.0;
327 0 : *pInnerSequenceY++ = 1.0;
328 0 : *pInnerSequenceZ++ = 0.0;
329 :
330 0 : *pInnerSequenceX++ = 0.0;
331 0 : *pInnerSequenceY++ = 1.0;
332 0 : *pInnerSequenceZ++ = 0.0;
333 :
334 0 : *pInnerSequenceX++ = 0.0;
335 0 : *pInnerSequenceY++ = 0.0;
336 0 : *pInnerSequenceZ++ = 0.0;
337 :
338 0 : *pInnerSequenceX++ = 1.0;
339 0 : *pInnerSequenceY++ = 0.0;
340 0 : *pInnerSequenceZ++ = 0.0;
341 : }
342 :
343 417 : return uno::Any( &aPP, cppu::UnoType<drawing::PolyPolygonShape3D>::get());
344 : }
345 :
346 : } //namespace chart
347 :
348 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|