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