Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / tools / ThreeDHelper.cxx
blob5733c6f44ba2e6f0a72a3f5db6f577db80761706
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <ThreeDHelper.hxx>
21 #include <Diagram.hxx>
22 #include <DiagramHelper.hxx>
23 #include <ChartTypeHelper.hxx>
24 #include <ChartType.hxx>
25 #include <BaseGFXHelper.hxx>
26 #include <DataSeries.hxx>
27 #include <DataSeriesHelper.hxx>
28 #include <defines.hxx>
30 #include <editeng/unoprnms.hxx>
31 #include <com/sun/star/drawing/LineStyle.hpp>
32 #include <com/sun/star/drawing/ShadeMode.hpp>
33 #include <comphelper/diagnose_ex.hxx>
34 #include <tools/helpers.hxx>
35 #include <rtl/math.hxx>
37 namespace chart
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::chart2;
42 using ::com::sun::star::uno::Reference;
43 using ::rtl::math::cos;
44 using ::rtl::math::sin;
45 using ::rtl::math::tan;
47 namespace
50 bool lcl_isRightAngledAxesSetAndSupported( const rtl::Reference< Diagram >& xDiagram )
52 if( xDiagram.is() )
54 bool bRightAngledAxes = false;
55 xDiagram->getPropertyValue( "RightAngledAxes") >>= bRightAngledAxes;
56 if(bRightAngledAxes)
58 if( ChartTypeHelper::isSupportingRightAngledAxes(
59 xDiagram->getChartTypeByIndex( 0 ) ) )
61 return true;
65 return false;
68 } //end anonymous namespace
70 drawing::CameraGeometry ThreeDHelper::getDefaultCameraGeometry( bool bPie )
72 // ViewReferencePoint (Point on the View plane)
73 drawing::Position3D vrp(17634.6218373783, 10271.4823817647, 24594.8639082739);
74 // ViewPlaneNormal (Normal to the View Plane)
75 drawing::Direction3D vpn(0.416199821709347, 0.173649045905254, 0.892537795986984);
76 // ViewUpVector (determines the v-axis direction on the view plane as
77 // projection of VUP parallel to VPN onto th view pane)
78 drawing::Direction3D vup(-0.0733876362771618, 0.984807599917971, -0.157379306090273);
80 if( bPie )
82 vrp = drawing::Position3D( 0.0, 0.0, 87591.2408759124 );//--> 5 percent perspective
83 vpn = drawing::Direction3D( 0.0, 0.0, 1.0 );
84 vup = drawing::Direction3D( 0.0, 1.0, 0.0 );
87 return drawing::CameraGeometry( vrp, vpn, vup );
90 namespace
92 void lcl_ensureIntervalMinus1To1( double& rSinOrCos )
94 if (rSinOrCos < -1.0)
95 rSinOrCos = -1.0;
96 else if (rSinOrCos > 1.0)
97 rSinOrCos = 1.0;
100 bool lcl_isSinZero( double fAngleRad )
102 return ::basegfx::fTools::equalZero( sin(fAngleRad), 0.0000001 );
104 bool lcl_isCosZero( double fAngleRad )
106 return ::basegfx::fTools::equalZero( cos(fAngleRad), 0.0000001 );
111 void ThreeDHelper::convertElevationRotationDegToXYZAngleRad(
112 sal_Int32 nElevationDeg, sal_Int32 nRotationDeg,
113 double& rfXAngleRad, double& rfYAngleRad, double& rfZAngleRad)
115 // for a description of the algorithm see issue 72994
116 //https://bz.apache.org/ooo/show_bug.cgi?id=72994
117 //https://bz.apache.org/ooo/attachment.cgi?id=50608
119 nElevationDeg = NormAngle360(nElevationDeg);
120 nRotationDeg = NormAngle360(nRotationDeg);
122 double& x = rfXAngleRad;
123 double& y = rfYAngleRad;
124 double& z = rfZAngleRad;
126 double E = basegfx::deg2rad(nElevationDeg); //elevation in Rad
127 double R = basegfx::deg2rad(nRotationDeg); //rotation in Rad
129 if( (nRotationDeg == 0 || nRotationDeg == 180 )
130 && ( nElevationDeg == 90 || nElevationDeg == 270 ) )
132 //sR==0 && cE==0
133 z = 0.0;
134 //element 23
135 double f23 = cos(R)*sin(E);
136 if(f23>0)
137 x = M_PI_2;
138 else
139 x = -M_PI_2;
140 y = R;
142 else if( ( nRotationDeg == 90 || nRotationDeg == 270 )
143 && ( nElevationDeg == 90 || nElevationDeg == 270 ) )
145 //cR==0 && cE==0
146 z = M_PI_2;
147 if( sin(R)>0 )
148 x = M_PI_2;
149 else
150 x = -M_PI_2;
152 if( (sin(R)*sin(E))>0 )
153 y = 0.0;
154 else
155 y = M_PI;
157 else if( (nRotationDeg == 0 || nRotationDeg == 180 )
158 && ( nElevationDeg == 0 || nElevationDeg == 180 ) )
160 //sR==0 && sE==0
161 z = 0.0;
162 y = R;
163 x = E;
165 else if( ( nRotationDeg == 90 || nRotationDeg == 270 )
166 && ( nElevationDeg == 0 || nElevationDeg == 180 ) )
168 //cR==0 && sE==0
169 z = 0.0;
171 if( (sin(R)/cos(E))>0 )
172 y = M_PI_2;
173 else
174 y = -M_PI_2;
176 if( (cos(E))>0 )
177 x = 0;
178 else
179 x = M_PI;
181 else if ( nElevationDeg == 0 || nElevationDeg == 180 )
183 //sR!=0 cR!=0 sE==0
184 z = 0.0;
185 x = E;
186 y = R;
187 //use element 13 for sign
188 if((cos(x)*sin(y)*sin(R))<0.0)
189 y *= -1.0;
191 else if ( nElevationDeg == 90 || nElevationDeg == 270 )
193 //sR!=0 cR!=0 cE==0
194 //element 12 + 22 --> y=0 or M_PI and x=+-M_PI/2
195 //-->element 13/23:
196 z = atan(sin(R)/(cos(R)*sin(E)));
197 //use element 13 for sign for x
198 if( (sin(R)*sin(z))>0.0 )
199 x = M_PI_2;
200 else
201 x = -M_PI_2;
202 //use element 21 for y
203 if( (sin(R)*sin(E)*sin(z))>0.0)
204 y = 0.0;
205 else
206 y = M_PI;
208 else if ( nRotationDeg == 0 || nRotationDeg == 180 )
210 //sE!=0 cE!=0 sR==0
211 z = 0.0;
212 x = E;
213 y = R;
214 double f23 = cos(R)*sin(E);
215 if( (f23 * sin(x)) < 0.0 )
216 x *= -1.0; //todo ??
218 else if (nRotationDeg == 90 || nRotationDeg == 270)
220 //sE!=0 cE!=0 cR==0
221 //z = +- M_PI/2;
222 //x = +- M_PI/2;
223 z = M_PI_2;
224 x = M_PI_2;
225 double sR = sin(R);
226 if( sR<0.0 )
227 x *= -1.0; //different signs for x and z
229 //use element 21:
230 double cy = sR*sin(E)/sin(z);
231 lcl_ensureIntervalMinus1To1(cy);
232 y = acos(cy);
234 //use element 22 for sign:
235 if( (sin(x)*sin(y)*sin(z)*cos(E))<0.0)
236 y *= -1.0;
238 else
240 z = atan(tan(R) * sin(E));
241 if(cos(z)==0.0)
243 OSL_FAIL("calculation error in ThreeDHelper::convertElevationRotationDegToXYZAngleRad");
244 return;
246 double cy = cos(R)/cos(z);
247 lcl_ensureIntervalMinus1To1(cy);
248 y = acos(cy);
250 //element 12 in 23
251 double fDenominator = cos(z)*(1.0-pow(sin(y),2));
252 if(fDenominator==0.0)
254 OSL_FAIL("calculation error in ThreeDHelper::convertElevationRotationDegToXYZAngleRad");
255 return;
257 double sx = cos(R)*sin(E)/fDenominator;
258 lcl_ensureIntervalMinus1To1(sx);
259 x = asin( sx );
261 //use element 13 for sign:
262 double f13a = cos(x)*cos(z)*sin(y);
263 double f13b = sin(R)-sx*sin(z);
264 if( (f13b*f13a)<0.0 )
266 //change x or y
267 //use element 22 for further investigations:
268 //try
269 y *= -1;
270 double f22a = cos(x)*cos(z);
271 double f22b = cos(E)-(sx*sin(y)*sin(z));
272 if( (f22a*f22b)<0.0 )
274 y *= -1;
275 x=(M_PI-x);
278 else
280 //change nothing or both
281 //use element 22 for further investigations:
282 double f22a = cos(x)*cos(z);
283 double f22b = cos(E)-(sx*sin(y)*sin(z));
284 if( (f22a*f22b)<0.0 )
286 y *= -1;
287 x=(M_PI-x);
293 void ThreeDHelper::convertXYZAngleRadToElevationRotationDeg(
294 sal_Int32& rnElevationDeg, sal_Int32& rnRotationDeg,
295 double fXRad, double fYRad, double fZRad)
297 // for a description of the algorithm see issue 72994
298 //https://bz.apache.org/ooo/show_bug.cgi?id=72994
299 //https://bz.apache.org/ooo/attachment.cgi?id=50608
301 double R = 0.0; //Rotation in Rad
302 double E = 0.0; //Elevation in Rad
304 double& x = fXRad;
305 double& y = fYRad;
306 double& z = fZRad;
308 double f11 = cos(y)*cos(z);
310 if( lcl_isSinZero(y) )
312 //siny == 0
314 if( lcl_isCosZero(x) )
316 //siny == 0 && cosx == 0
318 if( lcl_isSinZero(z) )
320 //siny == 0 && cosx == 0 && sinz == 0
321 //example: x=+-90 y=0oder180 z=0(oder180)
323 //element 13+11
324 if( f11 > 0 )
325 R = 0.0;
326 else
327 R = M_PI;
329 //element 23
330 double f23 = cos(z)*sin(x) / cos(R);
331 if( f23 > 0 )
332 E = M_PI_2;
333 else
334 E = -M_PI_2;
336 else if( lcl_isCosZero(z) )
338 //siny == 0 && cosx == 0 && cosz == 0
339 //example: x=+-90 y=0oder180 z=+-90
341 double f13 = sin(x)*sin(z);
342 //element 13+11
343 if( f13 > 0 )
344 R = M_PI_2;
345 else
346 R = -M_PI_2;
348 //element 21
349 double f21 = cos(y)*sin(z) / sin(R);
350 if( f21 > 0 )
351 E = M_PI_2;
352 else
353 E = -M_PI_2;
355 else
357 //siny == 0 && cosx == 0 && cosz != 0 && sinz != 0
358 //element 11 && 13
359 double f13 = sin(x)*sin(z);
360 R = atan( f13/f11 );
362 if(f11<0)
363 R+=M_PI;
365 //element 23
366 double f23 = cos(z)*sin(x);
367 if( f23/cos(R) > 0 )
368 E = M_PI_2;
369 else
370 E = -M_PI_2;
373 else if( lcl_isSinZero(x) )
375 //sinY==0 sinX==0
376 //element 13+11
377 if( f11 > 0 )
378 R = 0.0;
379 else
380 R = M_PI;
382 double f22 = cos(x)*cos(z);
383 if( f22 > 0 )
384 E = 0.0;
385 else
386 E = M_PI;
388 else if( lcl_isSinZero(z) )
390 //sinY==0 sinZ==0 sinx!=0 cosx!=0
391 //element 13+11
392 if( f11 > 0 )
393 R = 0.0;
394 else
395 R = M_PI;
397 //element 22 && 23
398 double f22 = cos(x)*cos(z);
399 double f23 = cos(z)*sin(x);
400 E = atan( f23/(f22*cos(R)) );
401 if( (f22*cos(E))<0 )
402 E+=M_PI;
404 else if( lcl_isCosZero(z) )
406 //sinY == 0 && cosZ == 0 && cosx != 0 && sinx != 0
407 double f13 = sin(x)*sin(z);
408 //element 13+11
409 if( f13 > 0 )
410 R = M_PI_2;
411 else
412 R = -M_PI_2;
414 //element 21+22
415 double f21 = cos(y)*sin(z);
416 if( f21/sin(R) > 0 )
417 E = M_PI_2;
418 else
419 E = -M_PI_2;
421 else
423 //sinY == 0 && all other !=0
424 double f13 = sin(x)*sin(z);
425 R = atan( f13/f11 );
426 if( (f11*cos(R))<0.0 )
427 R+=M_PI;
429 double f22 = cos(x)*cos(z);
430 if( !lcl_isCosZero(R) )
431 E = atan( cos(z)*sin(x) /( f22*cos(R) ) );
432 else
433 E = atan( cos(y)*sin(z) /( f22*sin(R) ) );
434 if( (f22*cos(E))<0 )
435 E+=M_PI;
438 else if( lcl_isCosZero(y) )
440 //cosY==0
442 double f13 = sin(x)*sin(z)+cos(x)*cos(z)*sin(y);
443 if( f13 >= 0 )
444 R = M_PI_2;
445 else
446 R = -M_PI_2;
448 double f22 = cos(x)*cos(z)+sin(x)*sin(y)*sin(z);
449 if( f22 >= 0 )
450 E = 0.0;
451 else
452 E = M_PI;
454 else if( lcl_isSinZero(x) )
456 //cosY!=0 sinY!=0 sinX=0
457 if( lcl_isSinZero(z) )
459 //cosY!=0 sinY!=0 sinX=0 sinZ=0
460 double f13 = cos(x)*cos(z)*sin(y);
461 R = atan( f13/f11 );
462 //R = asin(f13);
463 if( f11<0 )
464 R+=M_PI;
466 double f22 = cos(x)*cos(z);
467 if( f22>0 )
468 E = 0.0;
469 else
470 E = M_PI;
472 else if( lcl_isCosZero(z) )
474 //cosY!=0 sinY!=0 sinX=0 cosZ=0
475 R = x;
476 E = y;//or -y
477 //use 23 for 'signs'
478 double f23 = -1.0*cos(x)*sin(y)*sin(z);
479 if( (f23*cos(R)*sin(E))<0.0 )
481 //change R or E
482 E = -y;
485 else
487 //cosY!=0 sinY!=0 sinX=0 sinZ!=0 cosZ!=0
488 double f13 = cos(x)*cos(z)*sin(y);
489 R = atan( f13/f11 );
491 if( f11<0 )
492 R+=M_PI;
494 double f21 = cos(y)*sin(z);
495 double f22 = cos(x)*cos(z);
496 E = atan(f21/(f22*sin(R)) );
498 if( (f22*cos(E))<0.0 )
499 E+=M_PI;
502 else if( lcl_isCosZero(x) )
504 //cosY!=0 sinY!=0 cosX=0
506 if( lcl_isSinZero(z) )
508 //cosY!=0 sinY!=0 cosX=0 sinZ=0
509 R=0;//13 -> R=0 or M_PI
510 if( f11<0.0 )
511 R=M_PI;
512 E=M_PI_2;//22 -> E=+-M_PI/2
513 //use element 11 and 23 for sign
514 double f23 = cos(z)*sin(x);
515 if( (f11*f23*sin(E))<0.0 )
516 E=-M_PI_2;
518 else if( lcl_isCosZero(z) )
520 //cosY!=0 sinY!=0 cosX=0 cosZ=0
521 //element 11 & 13:
522 if( (sin(x)*sin(z))>0.0 )
523 R=M_PI_2;
524 else
525 R=-M_PI_2;
526 //element 22:
527 E=acos( sin(x)*sin(y)*sin(z));
528 //use element 21 for sign:
529 if( (cos(y)*sin(z)*sin(R)*sin(E))<0.0 )
530 E*=-1.0;
532 else
534 //cosY!=0 sinY!=0 cosX=0 sinZ!=0 cosZ!=0
535 //element 13/11
536 R = atan( sin(x)*sin(z)/(cos(y)*cos(z)) );
537 //use 13 for 'sign'
538 if( (sin(x)*sin(z))<0.0 )
539 R += M_PI;
540 //element 22
541 E = acos(sin(x)*sin(y)*sin(z) );
542 //use 21 for sign
543 if( (cos(y)*sin(z)*sin(R)*sin(E))<0.0 )
544 E*=-1.0;
547 else if( lcl_isSinZero(z) )
549 //cosY!=0 sinY!=0 sinX!=0 cosX!=0 sinZ=0
550 //element 11
551 R=y;
552 //use element 13 for sign
553 if( (cos(x)*cos(z)*sin(y)*sin(R))<0.0 )
554 R*=-1.0;
555 //element 22
556 E = acos( cos(x)*cos(z) );
557 //use element 23 for sign
558 if( (cos(z)*sin(x)*cos(R)*sin(E))<0.0 )
559 E*=-1.0;
561 else if( lcl_isCosZero(z) )
563 //cosY!=0 sinY!=0 sinX!=0 cosX!=0 cosZ=0
564 //element 21/23
565 R=atan(-cos(y)/(cos(x)*sin(y)));
566 //use element 13 for 'sign'
567 if( (sin(x)*sin(z)*sin(R))<0.0 )
568 R+=M_PI;
569 //element 21/22
570 E=atan( cos(y)*sin(z)/(sin(R)*sin(x)*sin(y)*sin(z)) );
571 //use element 23 for 'sign'
572 if( (-cos(x)*sin(y)*sin(z)*cos(R)*sin(E))<0.0 )
573 E+=M_PI;
575 else
577 //cosY!=0 sinY!=0 sinX!=0 cosX!=0 sinZ!=0 cosZ!=0
578 //13/11:
579 double f13 = sin(x)*sin(z)+cos(x)*cos(z)*sin(y);
580 R = atan( f13/ f11 );
581 if(f11<0.0)
582 R+=M_PI;
583 double f22 = cos(x)*cos(z)+sin(x)*sin(y)*sin(z);
584 double f23 = cos(x)*sin(y)*sin(z)-cos(z)*sin(x);
585 //23/22:
586 E = atan( -1.0*f23/(f22*cos(R)) );
587 if(f22<0.0)
588 E+=M_PI;
591 rnElevationDeg = basegfx::fround(basegfx::rad2deg(E));
592 rnRotationDeg = basegfx::fround(basegfx::rad2deg(R));
595 double ThreeDHelper::getValueClippedToRange( double fAngle, const double& fPositivLimit )
597 if( fAngle<-1*fPositivLimit )
598 fAngle=-1*fPositivLimit;
599 else if( fAngle>fPositivLimit )
600 fAngle=fPositivLimit;
601 return fAngle;
604 void ThreeDHelper::adaptRadAnglesForRightAngledAxes( double& rfXAngleRad, double& rfYAngleRad )
606 rfXAngleRad = ThreeDHelper::getValueClippedToRange(rfXAngleRad, basegfx::deg2rad(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()) );
607 rfYAngleRad = ThreeDHelper::getValueClippedToRange(rfYAngleRad, basegfx::deg2rad(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()) );
611 void ThreeDHelper::getCameraDistanceRange( double& rfMinimumDistance, double& rfMaximumDistance )
613 rfMinimumDistance = 3.0/4.0*FIXED_SIZE_FOR_3D_CHART_VOLUME;//empiric value
614 rfMaximumDistance = 20.0*FIXED_SIZE_FOR_3D_CHART_VOLUME;//empiric value
617 void ThreeDHelper::ensureCameraDistanceRange( double& rfCameraDistance )
619 double fMin, fMax;
620 getCameraDistanceRange( fMin, fMax );
621 if( rfCameraDistance < fMin )
622 rfCameraDistance = fMin;
623 if( rfCameraDistance > fMax )
624 rfCameraDistance = fMax;
627 double ThreeDHelper::CameraDistanceToPerspective( double fCameraDistance )
629 double fMin, fMax;
630 ThreeDHelper::getCameraDistanceRange( fMin, fMax );
631 //fMax <-> 0; fMin <->100
632 //a/x + b = y
633 double a = 100.0*fMax*fMin/(fMax-fMin);
634 double b = -a/fMax;
636 double fRet = a/fCameraDistance + b;
638 return fRet;
641 double ThreeDHelper::PerspectiveToCameraDistance( double fPerspective )
643 double fMin, fMax;
644 ThreeDHelper::getCameraDistanceRange( fMin, fMax );
645 //fMax <-> 0; fMin <->100
646 //a/x + b = y
647 double a = 100.0*fMax*fMin/(fMax-fMin);
648 double b = -a/fMax;
650 double fRet = a/(fPerspective - b);
652 return fRet;
655 void ThreeDHelper::getRoundedEdgesAndObjectLines(
656 const rtl::Reference< Diagram > & xDiagram
657 , sal_Int32& rnRoundedEdges, sal_Int32& rnObjectLines )
659 rnRoundedEdges = -1;
660 rnObjectLines = -1;
663 bool bDifferentRoundedEdges = false;
664 bool bDifferentObjectLines = false;
666 drawing::LineStyle aLineStyle( drawing::LineStyle_SOLID );
668 std::vector< rtl::Reference< DataSeries > > aSeriesList =
669 xDiagram->getDataSeries();
670 sal_Int32 nSeriesCount = static_cast<sal_Int32>( aSeriesList.size() );
672 OUString aPercentDiagonalPropertyName( "PercentDiagonal" );
673 OUString aBorderStylePropertyName( "BorderStyle" );
675 for( sal_Int32 nS = 0; nS < nSeriesCount; ++nS )
677 rtl::Reference< DataSeries > xSeries( aSeriesList[nS] );
678 if(!nS)
680 rnRoundedEdges = 0;
683 sal_Int16 nPercentDiagonal = 0;
685 xSeries->getPropertyValue( aPercentDiagonalPropertyName ) >>= nPercentDiagonal;
686 rnRoundedEdges = static_cast< sal_Int32 >( nPercentDiagonal );
688 if( DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries
689 , aPercentDiagonalPropertyName, uno::Any(nPercentDiagonal) ) )
690 bDifferentRoundedEdges = true;
692 catch( const uno::Exception& )
694 TOOLS_WARN_EXCEPTION("chart2", "" );
695 bDifferentRoundedEdges = true;
699 xSeries->getPropertyValue( aBorderStylePropertyName ) >>= aLineStyle;
701 if( DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries
702 , aBorderStylePropertyName, uno::Any(aLineStyle) ) )
703 bDifferentObjectLines = true;
705 catch( const uno::Exception& )
707 TOOLS_WARN_EXCEPTION("chart2", "" );
708 bDifferentObjectLines = true;
711 else
713 if( !bDifferentRoundedEdges )
715 sal_Int16 nPercentDiagonal = 0;
716 xSeries->getPropertyValue( aPercentDiagonalPropertyName ) >>= nPercentDiagonal;
717 sal_Int32 nCurrentRoundedEdges = static_cast< sal_Int32 >( nPercentDiagonal );
718 if(nCurrentRoundedEdges!=rnRoundedEdges
719 || DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries
720 , aPercentDiagonalPropertyName, uno::Any( static_cast< sal_Int16 >(rnRoundedEdges) ) ) )
722 bDifferentRoundedEdges = true;
726 if( !bDifferentObjectLines )
728 drawing::LineStyle aCurrentLineStyle;
729 xSeries->getPropertyValue( aBorderStylePropertyName ) >>= aCurrentLineStyle;
730 if(aCurrentLineStyle!=aLineStyle
731 || DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries
732 , aBorderStylePropertyName, uno::Any(aLineStyle) ) )
733 bDifferentObjectLines = true;
736 if( bDifferentRoundedEdges && bDifferentObjectLines )
737 break;
740 //set rnObjectLines
741 rnObjectLines = 0;
742 if( bDifferentObjectLines )
743 rnObjectLines = -1;
744 else if( aLineStyle == drawing::LineStyle_SOLID )
745 rnObjectLines = 1;
747 catch( const uno::Exception& )
749 TOOLS_WARN_EXCEPTION("chart2", "" );
753 void ThreeDHelper::setRoundedEdgesAndObjectLines(
754 const rtl::Reference< Diagram > & xDiagram
755 , sal_Int32 nRoundedEdges, sal_Int32 nObjectLines )
757 if( (nRoundedEdges<0||nRoundedEdges>100) && nObjectLines!=0 && nObjectLines!=1 )
758 return;
760 drawing::LineStyle aLineStyle( drawing::LineStyle_NONE );
761 if(nObjectLines==1)
762 aLineStyle = drawing::LineStyle_SOLID;
764 uno::Any aALineStyle( aLineStyle);
765 uno::Any aARoundedEdges( static_cast< sal_Int16 >( nRoundedEdges ));
767 std::vector< rtl::Reference< DataSeries > > aSeriesList =
768 xDiagram->getDataSeries();
769 for( auto const& xSeries : aSeriesList)
771 if( nRoundedEdges>=0 && nRoundedEdges<=100 )
772 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "PercentDiagonal", aARoundedEdges );
774 if( nObjectLines==0 || nObjectLines==1 )
775 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "BorderStyle", aALineStyle );
779 CuboidPlanePosition ThreeDHelper::getAutomaticCuboidPlanePositionForStandardLeftWall( const rtl::Reference< ::chart::Diagram >& xDiagram )
781 CuboidPlanePosition eRet(CuboidPlanePosition_Left);
783 double fXAngleRad=0.0; double fYAngleRad=0.0; double fZAngleRad=0.0;
784 xDiagram->getRotationAngle( fXAngleRad, fYAngleRad, fZAngleRad );
785 if( lcl_isRightAngledAxesSetAndSupported( xDiagram ) )
787 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fXAngleRad, fYAngleRad );
789 if( sin(fYAngleRad)>0.0 )
790 eRet = CuboidPlanePosition_Right;
791 return eRet;
794 CuboidPlanePosition ThreeDHelper::getAutomaticCuboidPlanePositionForStandardBackWall( const rtl::Reference< Diagram >& xDiagram )
796 CuboidPlanePosition eRet(CuboidPlanePosition_Back);
798 double fXAngleRad=0.0; double fYAngleRad=0.0; double fZAngleRad=0.0;
799 xDiagram->getRotationAngle( fXAngleRad, fYAngleRad, fZAngleRad );
800 if( lcl_isRightAngledAxesSetAndSupported( xDiagram ) )
802 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fXAngleRad, fYAngleRad );
804 if( cos(fXAngleRad)*cos(fYAngleRad)<0.0 )
805 eRet = CuboidPlanePosition_Front;
806 return eRet;
809 CuboidPlanePosition ThreeDHelper::getAutomaticCuboidPlanePositionForStandardBottom( const rtl::Reference< Diagram >& xDiagram )
811 CuboidPlanePosition eRet(CuboidPlanePosition_Bottom);
813 double fXAngleRad=0.0; double fYAngleRad=0.0; double fZAngleRad=0.0;
814 xDiagram->getRotationAngle( fXAngleRad, fYAngleRad, fZAngleRad );
815 if( lcl_isRightAngledAxesSetAndSupported( xDiagram ) )
817 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fXAngleRad, fYAngleRad );
819 if( sin(fXAngleRad)*cos(fYAngleRad)<0.0 )
820 eRet = CuboidPlanePosition_Top;
821 return eRet;
824 } //namespace chart
826 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */