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 36 : 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 36 : , m_aPoint3(m_aPoint2+rDirectionToPoint4)
38 : , m_aPoint4(rPoint1+rDirectionToPoint4)
39 : , m_bInvertNormal(false)
40 72 : , m_bManualNormalSet(false)
41 : {
42 36 : }
43 :
44 216 : 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 216 : , m_bManualNormalSet(false)
53 : {
54 216 : m_aPoint3.PositionZ += fDepth;
55 216 : m_aPoint4.PositionZ += fDepth;
56 216 : }
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 36 : void Stripe::InvertNormal( bool bInvertNormal )
78 : {
79 36 : m_bInvertNormal = bInvertNormal;
80 36 : }
81 :
82 144 : uno::Any Stripe::getPolyPolygonShape3D() const
83 : {
84 144 : drawing::PolyPolygonShape3D aPP;
85 :
86 144 : aPP.SequenceX.realloc(1);
87 144 : aPP.SequenceY.realloc(1);
88 144 : aPP.SequenceZ.realloc(1);
89 :
90 144 : drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
91 144 : drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
92 144 : drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
93 :
94 144 : pOuterSequenceX->realloc(4);
95 144 : pOuterSequenceY->realloc(4);
96 144 : pOuterSequenceZ->realloc(4);
97 :
98 144 : double* pInnerSequenceX = pOuterSequenceX->getArray();
99 144 : double* pInnerSequenceY = pOuterSequenceY->getArray();
100 144 : double* pInnerSequenceZ = pOuterSequenceZ->getArray();
101 :
102 144 : *pInnerSequenceX++ = m_aPoint1.PositionX;
103 144 : *pInnerSequenceY++ = m_aPoint1.PositionY;
104 144 : *pInnerSequenceZ++ = m_aPoint1.PositionZ;
105 :
106 144 : *pInnerSequenceX++ = m_aPoint2.PositionX;
107 144 : *pInnerSequenceY++ = m_aPoint2.PositionY;
108 144 : *pInnerSequenceZ++ = m_aPoint2.PositionZ;
109 :
110 144 : *pInnerSequenceX++ = m_aPoint3.PositionX;
111 144 : *pInnerSequenceY++ = m_aPoint3.PositionY;
112 144 : *pInnerSequenceZ++ = m_aPoint3.PositionZ;
113 :
114 144 : *pInnerSequenceX++ = m_aPoint4.PositionX;
115 144 : *pInnerSequenceY++ = m_aPoint4.PositionY;
116 144 : *pInnerSequenceZ++ = m_aPoint4.PositionZ;
117 :
118 144 : return uno::Any( &aPP, ::getCppuType((const drawing::PolyPolygonShape3D*)0) );
119 : }
120 :
121 144 : drawing::Direction3D Stripe::getNormal() const
122 : {
123 144 : drawing::Direction3D aRet(1.0,0.0,0.0);
124 :
125 144 : if( m_bManualNormalSet )
126 0 : aRet = m_aManualNormal;
127 : else
128 : {
129 144 : ::basegfx::B3DPolygon aPolygon3D;
130 144 : aPolygon3D.append(Position3DToB3DPoint( m_aPoint1 ));
131 144 : aPolygon3D.append(Position3DToB3DPoint( m_aPoint2 ));
132 144 : aPolygon3D.append(Position3DToB3DPoint( m_aPoint3 ));
133 144 : aPolygon3D.append(Position3DToB3DPoint( m_aPoint4 ));
134 288 : ::basegfx::B3DVector aNormal(::basegfx::tools::getNormal(aPolygon3D));
135 288 : aRet = B3DVectorToDirection3D(aNormal);
136 : }
137 :
138 144 : if( m_bInvertNormal )
139 : {
140 36 : aRet.DirectionX *= -1.0;
141 36 : aRet.DirectionY *= -1.0;
142 36 : aRet.DirectionZ *= -1.0;
143 : }
144 144 : return aRet;
145 : }
146 :
147 144 : uno::Any Stripe::getNormalsPolygon() const
148 : {
149 144 : drawing::PolyPolygonShape3D aPP;
150 :
151 144 : aPP.SequenceX.realloc(1);
152 144 : aPP.SequenceY.realloc(1);
153 144 : aPP.SequenceZ.realloc(1);
154 :
155 144 : drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
156 144 : drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
157 144 : drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
158 :
159 144 : pOuterSequenceX->realloc(4);
160 144 : pOuterSequenceY->realloc(4);
161 144 : pOuterSequenceZ->realloc(4);
162 :
163 144 : double* pInnerSequenceX = pOuterSequenceX->getArray();
164 144 : double* pInnerSequenceY = pOuterSequenceY->getArray();
165 144 : double* pInnerSequenceZ = pOuterSequenceZ->getArray();
166 :
167 144 : drawing::Direction3D aNormal( getNormal() );
168 :
169 720 : for(sal_Int32 nN=4; --nN; )
170 : {
171 432 : *pInnerSequenceX++ = aNormal.DirectionX;
172 432 : *pInnerSequenceY++ = aNormal.DirectionY;
173 432 : *pInnerSequenceZ++ = aNormal.DirectionZ;
174 : }
175 144 : return uno::Any( &aPP, ::getCppuType((const drawing::PolyPolygonShape3D*)0) );
176 : }
177 :
178 144 : uno::Any Stripe::getTexturePolygon( short nRotatedTexture ) const
179 : {
180 144 : drawing::PolyPolygonShape3D aPP;
181 :
182 144 : aPP.SequenceX.realloc(1);
183 144 : aPP.SequenceY.realloc(1);
184 144 : aPP.SequenceZ.realloc(1);
185 :
186 144 : drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
187 144 : drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
188 144 : drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
189 :
190 144 : pOuterSequenceX->realloc(4);
191 144 : pOuterSequenceY->realloc(4);
192 144 : pOuterSequenceZ->realloc(4);
193 :
194 144 : double* pInnerSequenceX = pOuterSequenceX->getArray();
195 144 : double* pInnerSequenceY = pOuterSequenceY->getArray();
196 144 : double* pInnerSequenceZ = pOuterSequenceZ->getArray();
197 :
198 144 : if( nRotatedTexture==0 )
199 : {
200 24 : *pInnerSequenceX++ = 0.0;
201 24 : *pInnerSequenceY++ = 0.0;
202 24 : *pInnerSequenceZ++ = 0.0;
203 :
204 24 : *pInnerSequenceX++ = 0.0;
205 24 : *pInnerSequenceY++ = 1.0;
206 24 : *pInnerSequenceZ++ = 0.0;
207 :
208 24 : *pInnerSequenceX++ = 1.0;
209 24 : *pInnerSequenceY++ = 1.0;
210 24 : *pInnerSequenceZ++ = 0.0;
211 :
212 24 : *pInnerSequenceX++ = 1.0;
213 24 : *pInnerSequenceY++ = 0.0;
214 24 : *pInnerSequenceZ++ = 0.0;
215 : }
216 120 : else if( nRotatedTexture==1 )
217 : {
218 120 : *pInnerSequenceX++ = 1.0;
219 120 : *pInnerSequenceY++ = 0.0;
220 120 : *pInnerSequenceZ++ = 0.0;
221 :
222 120 : *pInnerSequenceX++ = 0.0;
223 120 : *pInnerSequenceY++ = 0.0;
224 120 : *pInnerSequenceZ++ = 0.0;
225 :
226 120 : *pInnerSequenceX++ = 0.0;
227 120 : *pInnerSequenceY++ = 1.0;
228 120 : *pInnerSequenceZ++ = 0.0;
229 :
230 120 : *pInnerSequenceX++ = 1.0;
231 120 : *pInnerSequenceY++ = 1.0;
232 120 : *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 144 : return uno::Any( &aPP, ::getCppuType((const drawing::PolyPolygonShape3D*)0) );
344 : }
345 :
346 : } //namespace chart
347 :
348 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|