1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "Stripe.hxx"
27 #include "CommonConverters.hxx"
28 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
29 #include <com/sun/star/drawing/DoubleSequence.hpp>
30 #include <basegfx/polygon/b3dpolygon.hxx>
31 #include <basegfx/polygon/b3dpolygontools.hxx>
32
33 using namespace ::com::sun::star;
34
35 //.............................................................................
36 namespace chart
37 {
38 //.............................................................................
39
Stripe(const drawing::Position3D & rPoint1,const drawing::Direction3D & rDirectionToPoint2,const drawing::Direction3D & rDirectionToPoint4)40 Stripe::Stripe( const drawing::Position3D& rPoint1
41 , const drawing::Direction3D& rDirectionToPoint2
42 , const drawing::Direction3D& rDirectionToPoint4 )
43 : m_aPoint1(rPoint1)
44 , m_aPoint2(rPoint1+rDirectionToPoint2)
45 , m_aPoint3(m_aPoint2+rDirectionToPoint4)
46 , m_aPoint4(rPoint1+rDirectionToPoint4)
47 , m_bInvertNormal(false)
48 , m_bManualNormalSet(false)
49 {
50 }
51
Stripe(const drawing::Position3D & rPoint1,const drawing::Position3D & rPoint2,double fDepth)52 Stripe::Stripe( const drawing::Position3D& rPoint1
53 , const drawing::Position3D& rPoint2
54 , double fDepth )
55 : m_aPoint1(rPoint1)
56 , m_aPoint2(rPoint2)
57 , m_aPoint3(rPoint2)
58 , m_aPoint4(rPoint1)
59 , m_bInvertNormal(false)
60 , m_bManualNormalSet(false)
61 {
62 m_aPoint3.PositionZ += fDepth;
63 m_aPoint4.PositionZ += fDepth;
64 }
65
Stripe(const drawing::Position3D & rPoint1,const drawing::Position3D & rPoint2,const drawing::Position3D & rPoint3,const drawing::Position3D & rPoint4)66 Stripe::Stripe( const drawing::Position3D& rPoint1
67 , const drawing::Position3D& rPoint2
68 , const drawing::Position3D& rPoint3
69 , const drawing::Position3D& rPoint4 )
70 : m_aPoint1(rPoint1)
71 , m_aPoint2(rPoint2)
72 , m_aPoint3(rPoint3)
73 , m_aPoint4(rPoint4)
74 , m_bInvertNormal(false)
75 , m_bManualNormalSet(false)
76 {
77 }
78
SetManualNormal(const drawing::Direction3D & rNormal)79 void Stripe::SetManualNormal( const drawing::Direction3D& rNormal )
80 {
81 m_aManualNormal = rNormal;
82 m_bManualNormalSet = true;
83 }
84
InvertNormal(bool bInvertNormal)85 void Stripe::InvertNormal( bool bInvertNormal )
86 {
87 m_bInvertNormal = bInvertNormal;
88 }
89
getPolyPolygonShape3D() const90 uno::Any Stripe::getPolyPolygonShape3D() const
91 {
92 drawing::PolyPolygonShape3D aPP;
93
94 aPP.SequenceX.realloc(1);
95 aPP.SequenceY.realloc(1);
96 aPP.SequenceZ.realloc(1);
97
98 drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
99 drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
100 drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
101
102 pOuterSequenceX->realloc(4);
103 pOuterSequenceY->realloc(4);
104 pOuterSequenceZ->realloc(4);
105
106 double* pInnerSequenceX = pOuterSequenceX->getArray();
107 double* pInnerSequenceY = pOuterSequenceY->getArray();
108 double* pInnerSequenceZ = pOuterSequenceZ->getArray();
109
110 *pInnerSequenceX++ = m_aPoint1.PositionX;
111 *pInnerSequenceY++ = m_aPoint1.PositionY;
112 *pInnerSequenceZ++ = m_aPoint1.PositionZ;
113
114 *pInnerSequenceX++ = m_aPoint2.PositionX;
115 *pInnerSequenceY++ = m_aPoint2.PositionY;
116 *pInnerSequenceZ++ = m_aPoint2.PositionZ;
117
118 *pInnerSequenceX++ = m_aPoint3.PositionX;
119 *pInnerSequenceY++ = m_aPoint3.PositionY;
120 *pInnerSequenceZ++ = m_aPoint3.PositionZ;
121
122 *pInnerSequenceX++ = m_aPoint4.PositionX;
123 *pInnerSequenceY++ = m_aPoint4.PositionY;
124 *pInnerSequenceZ++ = m_aPoint4.PositionZ;
125
126 return uno::Any( &aPP, ::getCppuType((const drawing::PolyPolygonShape3D*)0) );
127 }
128
getNormal() const129 drawing::Direction3D Stripe::getNormal() const
130 {
131 drawing::Direction3D aRet(1.0,0.0,0.0);
132
133 if( m_bManualNormalSet )
134 aRet = m_aManualNormal;
135 else
136 {
137 ::basegfx::B3DPolygon aPolygon3D;
138 aPolygon3D.append(Position3DToB3DPoint( m_aPoint1 ));
139 aPolygon3D.append(Position3DToB3DPoint( m_aPoint2 ));
140 aPolygon3D.append(Position3DToB3DPoint( m_aPoint3 ));
141 aPolygon3D.append(Position3DToB3DPoint( m_aPoint4 ));
142 ::basegfx::B3DVector aNormal(::basegfx::tools::getNormal(aPolygon3D));
143 aRet = B3DVectorToDirection3D(aNormal);
144 }
145
146 if( m_bInvertNormal )
147 {
148 aRet.DirectionX *= -1.0;
149 aRet.DirectionY *= -1.0;
150 aRet.DirectionZ *= -1.0;
151 }
152 return aRet;
153 }
154
getNormalsPolygon() const155 uno::Any Stripe::getNormalsPolygon() const
156 {
157 drawing::PolyPolygonShape3D aPP;
158
159 aPP.SequenceX.realloc(1);
160 aPP.SequenceY.realloc(1);
161 aPP.SequenceZ.realloc(1);
162
163 drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
164 drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
165 drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
166
167 pOuterSequenceX->realloc(4);
168 pOuterSequenceY->realloc(4);
169 pOuterSequenceZ->realloc(4);
170
171 double* pInnerSequenceX = pOuterSequenceX->getArray();
172 double* pInnerSequenceY = pOuterSequenceY->getArray();
173 double* pInnerSequenceZ = pOuterSequenceZ->getArray();
174
175 drawing::Direction3D aNormal( getNormal() );
176
177 for(sal_Int32 nN=4; --nN; )
178 {
179 *pInnerSequenceX++ = aNormal.DirectionX;
180 *pInnerSequenceY++ = aNormal.DirectionY;
181 *pInnerSequenceZ++ = aNormal.DirectionZ;
182 }
183 return uno::Any( &aPP, ::getCppuType((const drawing::PolyPolygonShape3D*)0) );
184 }
185
getTexturePolygon(short nRotatedTexture) const186 uno::Any Stripe::getTexturePolygon( short nRotatedTexture ) const
187 {
188 drawing::PolyPolygonShape3D aPP;
189
190 aPP.SequenceX.realloc(1);
191 aPP.SequenceY.realloc(1);
192 aPP.SequenceZ.realloc(1);
193
194 drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
195 drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
196 drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
197
198 pOuterSequenceX->realloc(4);
199 pOuterSequenceY->realloc(4);
200 pOuterSequenceZ->realloc(4);
201
202 double* pInnerSequenceX = pOuterSequenceX->getArray();
203 double* pInnerSequenceY = pOuterSequenceY->getArray();
204 double* pInnerSequenceZ = pOuterSequenceZ->getArray();
205
206 if( nRotatedTexture==0 )
207 {
208 *pInnerSequenceX++ = 0.0;
209 *pInnerSequenceY++ = 0.0;
210 *pInnerSequenceZ++ = 0.0;
211
212 *pInnerSequenceX++ = 0.0;
213 *pInnerSequenceY++ = 1.0;
214 *pInnerSequenceZ++ = 0.0;
215
216 *pInnerSequenceX++ = 1.0;
217 *pInnerSequenceY++ = 1.0;
218 *pInnerSequenceZ++ = 0.0;
219
220 *pInnerSequenceX++ = 1.0;
221 *pInnerSequenceY++ = 0.0;
222 *pInnerSequenceZ++ = 0.0;
223 }
224 else if( nRotatedTexture==1 )
225 {
226 *pInnerSequenceX++ = 1.0;
227 *pInnerSequenceY++ = 0.0;
228 *pInnerSequenceZ++ = 0.0;
229
230 *pInnerSequenceX++ = 0.0;
231 *pInnerSequenceY++ = 0.0;
232 *pInnerSequenceZ++ = 0.0;
233
234 *pInnerSequenceX++ = 0.0;
235 *pInnerSequenceY++ = 1.0;
236 *pInnerSequenceZ++ = 0.0;
237
238 *pInnerSequenceX++ = 1.0;
239 *pInnerSequenceY++ = 1.0;
240 *pInnerSequenceZ++ = 0.0;
241 }
242 else if( nRotatedTexture==2 )
243 {
244 *pInnerSequenceX++ = 1.0;
245 *pInnerSequenceY++ = 1.0;
246 *pInnerSequenceZ++ = 0.0;
247
248 *pInnerSequenceX++ = 1.0;
249 *pInnerSequenceY++ = 0.0;
250 *pInnerSequenceZ++ = 0.0;
251
252 *pInnerSequenceX++ = 0.0;
253 *pInnerSequenceY++ = 0.0;
254 *pInnerSequenceZ++ = 0.0;
255
256 *pInnerSequenceX++ = 0.0;
257 *pInnerSequenceY++ = 1.0;
258 *pInnerSequenceZ++ = 0.0;
259 }
260 else if( nRotatedTexture==3 )
261 {
262 *pInnerSequenceX++ = 0.0;
263 *pInnerSequenceY++ = 1.0;
264 *pInnerSequenceZ++ = 0.0;
265
266 *pInnerSequenceX++ = 1.0;
267 *pInnerSequenceY++ = 1.0;
268 *pInnerSequenceZ++ = 0.0;
269
270 *pInnerSequenceX++ = 1.0;
271 *pInnerSequenceY++ = 0.0;
272 *pInnerSequenceZ++ = 0.0;
273
274 *pInnerSequenceX++ = 0.0;
275 *pInnerSequenceY++ = 0.0;
276 *pInnerSequenceZ++ = 0.0;
277 }
278 else if( nRotatedTexture==4 )
279 {
280 *pInnerSequenceX++ = 1.0;
281 *pInnerSequenceY++ = 0.0;
282 *pInnerSequenceZ++ = 0.0;
283
284 *pInnerSequenceX++ = 1.0;
285 *pInnerSequenceY++ = 1.0;
286 *pInnerSequenceZ++ = 0.0;
287
288 *pInnerSequenceX++ = 0.0;
289 *pInnerSequenceY++ = 1.0;
290 *pInnerSequenceZ++ = 0.0;
291
292 *pInnerSequenceX++ = 0.0;
293 *pInnerSequenceY++ = 0.0;
294 *pInnerSequenceZ++ = 0.0;
295 }
296 else if( nRotatedTexture==5 )
297 {
298 *pInnerSequenceX++ = 0.0;
299 *pInnerSequenceY++ = 0.0;
300 *pInnerSequenceZ++ = 0.0;
301
302 *pInnerSequenceX++ = 1.0;
303 *pInnerSequenceY++ = 0.0;
304 *pInnerSequenceZ++ = 0.0;
305
306 *pInnerSequenceX++ = 1.0;
307 *pInnerSequenceY++ = 1.0;
308 *pInnerSequenceZ++ = 0.0;
309
310 *pInnerSequenceX++ = 0.0;
311 *pInnerSequenceY++ = 1.0;
312 *pInnerSequenceZ++ = 0.0;
313 }
314 else if( nRotatedTexture==6 )
315 {
316 *pInnerSequenceX++ = 0.0;
317 *pInnerSequenceY++ = 1.0;
318 *pInnerSequenceZ++ = 0.0;
319
320 *pInnerSequenceX++ = 0.0;
321 *pInnerSequenceY++ = 0.0;
322 *pInnerSequenceZ++ = 0.0;
323
324 *pInnerSequenceX++ = 1.0;
325 *pInnerSequenceY++ = 0.0;
326 *pInnerSequenceZ++ = 0.0;
327
328 *pInnerSequenceX++ = 1.0;
329 *pInnerSequenceY++ = 1.0;
330 *pInnerSequenceZ++ = 0.0;
331 }
332 else if( nRotatedTexture==7 )
333 {
334 *pInnerSequenceX++ = 1.0;
335 *pInnerSequenceY++ = 1.0;
336 *pInnerSequenceZ++ = 0.0;
337
338 *pInnerSequenceX++ = 0.0;
339 *pInnerSequenceY++ = 1.0;
340 *pInnerSequenceZ++ = 0.0;
341
342 *pInnerSequenceX++ = 0.0;
343 *pInnerSequenceY++ = 0.0;
344 *pInnerSequenceZ++ = 0.0;
345
346 *pInnerSequenceX++ = 1.0;
347 *pInnerSequenceY++ = 0.0;
348 *pInnerSequenceZ++ = 0.0;
349 }
350
351 return uno::Any( &aPP, ::getCppuType((const drawing::PolyPolygonShape3D*)0) );
352 }
353
354 //.............................................................................
355 } //namespace chart
356 //.............................................................................
357