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