xref: /AOO41X/main/chart2/source/tools/CommonConverters.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir #include "CommonConverters.hxx"
31*cdf0e10cSrcweir #include <com/sun/star/drawing/DoubleSequence.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/text/WritingMode2.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
35*cdf0e10cSrcweir #include <rtl/math.hxx>
36*cdf0e10cSrcweir #include <basegfx/matrix/b3dhommatrix.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <cstdarg>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir //.............................................................................
42*cdf0e10cSrcweir namespace chart
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir //.............................................................................
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir using namespace ::com::sun::star;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir //-----------------------------------------------------------------------------
49*cdf0e10cSrcweir //-----------------------------------------------------------------------------
50*cdf0e10cSrcweir //  diverse methods for class conversions; e.g. ::basegfx::B3DHomMatrix to HomogenMatrix
51*cdf0e10cSrcweir //-----------------------------------------------------------------------------
52*cdf0e10cSrcweir //-----------------------------------------------------------------------------
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir drawing::HomogenMatrix B3DHomMatrixToHomogenMatrix( const ::basegfx::B3DHomMatrix& rM )
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir     drawing::HomogenMatrix aHM;
57*cdf0e10cSrcweir     aHM.Line1.Column1 = rM.get(0, 0);
58*cdf0e10cSrcweir 	aHM.Line1.Column2 = rM.get(0, 1);
59*cdf0e10cSrcweir 	aHM.Line1.Column3 = rM.get(0, 2);
60*cdf0e10cSrcweir 	aHM.Line1.Column4 = rM.get(0, 3);
61*cdf0e10cSrcweir 	aHM.Line2.Column1 = rM.get(1, 0);
62*cdf0e10cSrcweir 	aHM.Line2.Column2 = rM.get(1, 1);
63*cdf0e10cSrcweir 	aHM.Line2.Column3 = rM.get(1, 2);
64*cdf0e10cSrcweir 	aHM.Line2.Column4 = rM.get(1, 3);
65*cdf0e10cSrcweir 	aHM.Line3.Column1 = rM.get(2, 0);
66*cdf0e10cSrcweir 	aHM.Line3.Column2 = rM.get(2, 1);
67*cdf0e10cSrcweir 	aHM.Line3.Column3 = rM.get(2, 2);
68*cdf0e10cSrcweir 	aHM.Line3.Column4 = rM.get(2, 3);
69*cdf0e10cSrcweir 	aHM.Line4.Column1 = rM.get(3, 0);
70*cdf0e10cSrcweir 	aHM.Line4.Column2 = rM.get(3, 1);
71*cdf0e10cSrcweir 	aHM.Line4.Column3 = rM.get(3, 2);
72*cdf0e10cSrcweir 	aHM.Line4.Column4 = rM.get(3, 3);
73*cdf0e10cSrcweir     return aHM;
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir ::basegfx::B3DHomMatrix HomogenMatrixToB3DHomMatrix( const drawing::HomogenMatrix& rHM )
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     ::basegfx::B3DHomMatrix aM;
79*cdf0e10cSrcweir     aM.set(0, 0, rHM.Line1.Column1);
80*cdf0e10cSrcweir 	aM.set(0, 1, rHM.Line1.Column2);
81*cdf0e10cSrcweir 	aM.set(0, 2, rHM.Line1.Column3);
82*cdf0e10cSrcweir 	aM.set(0, 3, rHM.Line1.Column4);
83*cdf0e10cSrcweir 	aM.set(1, 0, rHM.Line2.Column1);
84*cdf0e10cSrcweir 	aM.set(1, 1, rHM.Line2.Column2);
85*cdf0e10cSrcweir 	aM.set(1, 2, rHM.Line2.Column3);
86*cdf0e10cSrcweir 	aM.set(1, 3, rHM.Line2.Column4);
87*cdf0e10cSrcweir 	aM.set(2, 0, rHM.Line3.Column1);
88*cdf0e10cSrcweir 	aM.set(2, 1, rHM.Line3.Column2);
89*cdf0e10cSrcweir 	aM.set(2, 2, rHM.Line3.Column3);
90*cdf0e10cSrcweir 	aM.set(2, 3, rHM.Line3.Column4);
91*cdf0e10cSrcweir 	aM.set(3, 0, rHM.Line4.Column1);
92*cdf0e10cSrcweir 	aM.set(3, 1, rHM.Line4.Column2);
93*cdf0e10cSrcweir 	aM.set(3, 2, rHM.Line4.Column3);
94*cdf0e10cSrcweir 	aM.set(3, 3, rHM.Line4.Column4);
95*cdf0e10cSrcweir     return aM;
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir ::basegfx::B2DHomMatrix IgnoreZ( const ::basegfx::B3DHomMatrix& rM )
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir 	::basegfx::B2DHomMatrix aM;
101*cdf0e10cSrcweir     aM.set(0, 0, rM.get(0, 0));
102*cdf0e10cSrcweir 	aM.set(0, 1, rM.get(0, 1));
103*cdf0e10cSrcweir 	aM.set(0, 2, rM.get(0, 3));
104*cdf0e10cSrcweir 	aM.set(1, 0, rM.get(1, 0));
105*cdf0e10cSrcweir 	aM.set(1, 1, rM.get(1, 1));
106*cdf0e10cSrcweir 	aM.set(1, 2, rM.get(1, 3));
107*cdf0e10cSrcweir 	aM.set(2, 0, rM.get(3, 0));
108*cdf0e10cSrcweir 	aM.set(2, 1, rM.get(3, 1));
109*cdf0e10cSrcweir 	aM.set(2, 2, rM.get(3, 3));
110*cdf0e10cSrcweir     return aM;
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir drawing::HomogenMatrix3 B2DHomMatrixToHomogenMatrix3( const ::basegfx::B2DHomMatrix& rM )
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     drawing::HomogenMatrix3 aHM;
117*cdf0e10cSrcweir     aHM.Line1.Column1 = rM.get(0, 0);
118*cdf0e10cSrcweir 	aHM.Line1.Column2 = rM.get(0, 1);
119*cdf0e10cSrcweir 	aHM.Line1.Column3 = rM.get(0, 2);
120*cdf0e10cSrcweir 	aHM.Line2.Column1 = rM.get(1, 0);
121*cdf0e10cSrcweir 	aHM.Line2.Column2 = rM.get(1, 1);
122*cdf0e10cSrcweir 	aHM.Line2.Column3 = rM.get(1, 2);
123*cdf0e10cSrcweir 	aHM.Line3.Column1 = rM.get(2, 0);
124*cdf0e10cSrcweir 	aHM.Line3.Column2 = rM.get(2, 1);
125*cdf0e10cSrcweir 	aHM.Line3.Column3 = rM.get(2, 2);
126*cdf0e10cSrcweir     return aHM;
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir ::basegfx::B3DPoint Position3DToB3DPoint( const drawing::Position3D& rPosition )
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir     return ::basegfx::B3DPoint(
132*cdf0e10cSrcweir 		rPosition.PositionX ,
133*cdf0e10cSrcweir 		rPosition.PositionY ,
134*cdf0e10cSrcweir 		rPosition.PositionZ );
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir drawing::Direction3D B3DVectorToDirection3D( const ::basegfx::B3DVector& rVector)
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir     return drawing::Direction3D(
140*cdf0e10cSrcweir           rVector.getX()
141*cdf0e10cSrcweir         , rVector.getY()
142*cdf0e10cSrcweir         , rVector.getZ()
143*cdf0e10cSrcweir         );
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir drawing::Position3D B3DPointToPosition3D( const ::basegfx::B3DPoint& rPoint)
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir         return drawing::Position3D(
149*cdf0e10cSrcweir           rPoint.getX()
150*cdf0e10cSrcweir         , rPoint.getY()
151*cdf0e10cSrcweir         , rPoint.getZ()
152*cdf0e10cSrcweir         );
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir ::basegfx::B3DVector Direction3DToB3DVector( const drawing::Direction3D& rDirection)
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir     return ::basegfx::B3DVector(
158*cdf0e10cSrcweir           rDirection.DirectionX
159*cdf0e10cSrcweir         , rDirection.DirectionY
160*cdf0e10cSrcweir         , rDirection.DirectionZ
161*cdf0e10cSrcweir         );
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir void AddPointToPoly( drawing::PolyPolygonShape3D& rPoly, const drawing::Position3D& rPos, sal_Int32 nPolygonIndex )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir     if(nPolygonIndex<0)
167*cdf0e10cSrcweir     {
168*cdf0e10cSrcweir         OSL_ENSURE( false, "The polygon index needs to be > 0");
169*cdf0e10cSrcweir         nPolygonIndex=0;
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     //make sure that we have enough polygons
173*cdf0e10cSrcweir     if(nPolygonIndex >= rPoly.SequenceX.getLength() )
174*cdf0e10cSrcweir     {
175*cdf0e10cSrcweir         rPoly.SequenceX.realloc(nPolygonIndex+1);
176*cdf0e10cSrcweir         rPoly.SequenceY.realloc(nPolygonIndex+1);
177*cdf0e10cSrcweir         rPoly.SequenceZ.realloc(nPolygonIndex+1);
178*cdf0e10cSrcweir     }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     drawing::DoubleSequence* pOuterSequenceX = &rPoly.SequenceX.getArray()[nPolygonIndex];
181*cdf0e10cSrcweir     drawing::DoubleSequence* pOuterSequenceY = &rPoly.SequenceY.getArray()[nPolygonIndex];
182*cdf0e10cSrcweir     drawing::DoubleSequence* pOuterSequenceZ = &rPoly.SequenceZ.getArray()[nPolygonIndex];
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     sal_Int32 nOldPointCount = pOuterSequenceX->getLength();
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     pOuterSequenceX->realloc(nOldPointCount+1);
187*cdf0e10cSrcweir     pOuterSequenceY->realloc(nOldPointCount+1);
188*cdf0e10cSrcweir     pOuterSequenceZ->realloc(nOldPointCount+1);
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     double* pInnerSequenceX = pOuterSequenceX->getArray();
191*cdf0e10cSrcweir     double* pInnerSequenceY = pOuterSequenceY->getArray();
192*cdf0e10cSrcweir     double* pInnerSequenceZ = pOuterSequenceZ->getArray();
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     pInnerSequenceX[nOldPointCount] = rPos.PositionX;
195*cdf0e10cSrcweir     pInnerSequenceY[nOldPointCount] = rPos.PositionY;
196*cdf0e10cSrcweir     pInnerSequenceZ[nOldPointCount] = rPos.PositionZ;
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir drawing::Position3D getPointFromPoly( const drawing::PolyPolygonShape3D& rPolygon, sal_Int32 nPointIndex, sal_Int32 nPolyIndex )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     drawing::Position3D aRet(0.0,0.0,0.0);
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir     if( nPolyIndex>=0 && nPolyIndex<rPolygon.SequenceX.getLength())
204*cdf0e10cSrcweir     {
205*cdf0e10cSrcweir         if(nPointIndex<rPolygon.SequenceX[nPolyIndex].getLength())
206*cdf0e10cSrcweir         {
207*cdf0e10cSrcweir             aRet.PositionX = rPolygon.SequenceX[nPolyIndex][nPointIndex];
208*cdf0e10cSrcweir             aRet.PositionY = rPolygon.SequenceY[nPolyIndex][nPointIndex];
209*cdf0e10cSrcweir             aRet.PositionZ = rPolygon.SequenceZ[nPolyIndex][nPointIndex];
210*cdf0e10cSrcweir         }
211*cdf0e10cSrcweir         else
212*cdf0e10cSrcweir         {
213*cdf0e10cSrcweir             ;DBG_ERROR("polygon was accessed with a wrong index");
214*cdf0e10cSrcweir         }
215*cdf0e10cSrcweir     }
216*cdf0e10cSrcweir     else
217*cdf0e10cSrcweir     {
218*cdf0e10cSrcweir         ;DBG_ERROR("polygon was accessed with a wrong index");
219*cdf0e10cSrcweir     }
220*cdf0e10cSrcweir     return aRet;
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir void addPolygon( drawing::PolyPolygonShape3D& rRet, const drawing::PolyPolygonShape3D& rAdd )
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     sal_Int32 nAddOuterCount = rAdd.SequenceX.getLength();
226*cdf0e10cSrcweir     sal_Int32 nOuterCount = rRet.SequenceX.getLength() + nAddOuterCount;
227*cdf0e10cSrcweir     rRet.SequenceX.realloc( nOuterCount );
228*cdf0e10cSrcweir     rRet.SequenceY.realloc( nOuterCount );
229*cdf0e10cSrcweir     rRet.SequenceZ.realloc( nOuterCount );
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     sal_Int32 nIndex = 0;
232*cdf0e10cSrcweir     sal_Int32 nOuter = nOuterCount - nAddOuterCount;
233*cdf0e10cSrcweir     for( ; nOuter < nOuterCount; nOuter++ )
234*cdf0e10cSrcweir     {
235*cdf0e10cSrcweir         if( nIndex >= nAddOuterCount )
236*cdf0e10cSrcweir             break;
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir         rRet.SequenceX[nOuter] = rAdd.SequenceX[nIndex];
239*cdf0e10cSrcweir         rRet.SequenceY[nOuter] = rAdd.SequenceY[nIndex];
240*cdf0e10cSrcweir         rRet.SequenceZ[nOuter] = rAdd.SequenceZ[nIndex];
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir         nIndex++;
243*cdf0e10cSrcweir     }
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir void appendPoly( drawing::PolyPolygonShape3D& rRet, const drawing::PolyPolygonShape3D& rAdd )
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir     sal_Int32 nOuterCount = Max( rRet.SequenceX.getLength(), rAdd.SequenceX.getLength() );
249*cdf0e10cSrcweir 	rRet.SequenceX.realloc(nOuterCount);
250*cdf0e10cSrcweir 	rRet.SequenceY.realloc(nOuterCount);
251*cdf0e10cSrcweir 	rRet.SequenceZ.realloc(nOuterCount);
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     for( sal_Int32 nOuter=0;nOuter<nOuterCount;nOuter++ )
254*cdf0e10cSrcweir     {
255*cdf0e10cSrcweir         sal_Int32 nOldPointCount = rRet.SequenceX[nOuter].getLength();
256*cdf0e10cSrcweir         sal_Int32 nAddPointCount = 0;
257*cdf0e10cSrcweir         if(nOuter<rAdd.SequenceX.getLength())
258*cdf0e10cSrcweir             nAddPointCount = rAdd.SequenceX[nOuter].getLength();
259*cdf0e10cSrcweir         if(!nAddPointCount)
260*cdf0e10cSrcweir             continue;
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir         sal_Int32 nNewPointCount = nOldPointCount + nAddPointCount;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir         rRet.SequenceX[nOuter].realloc(nNewPointCount);
265*cdf0e10cSrcweir         rRet.SequenceY[nOuter].realloc(nNewPointCount);
266*cdf0e10cSrcweir 	    rRet.SequenceZ[nOuter].realloc(nNewPointCount);
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir         sal_Int32 nPointTarget=nOldPointCount;
269*cdf0e10cSrcweir         sal_Int32 nPointSource=nAddPointCount;
270*cdf0e10cSrcweir         for( ; nPointSource-- ; nPointTarget++ )
271*cdf0e10cSrcweir         {
272*cdf0e10cSrcweir 	        rRet.SequenceX[nOuter][nPointTarget] = rAdd.SequenceX[nOuter][nPointSource];
273*cdf0e10cSrcweir             rRet.SequenceY[nOuter][nPointTarget] = rAdd.SequenceY[nOuter][nPointSource];
274*cdf0e10cSrcweir             rRet.SequenceZ[nOuter][nPointTarget] = rAdd.SequenceZ[nOuter][nPointSource];
275*cdf0e10cSrcweir         }
276*cdf0e10cSrcweir     }
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir drawing::PolyPolygonShape3D BezierToPoly(
280*cdf0e10cSrcweir     const drawing::PolyPolygonBezierCoords& rBezier )
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir     const drawing::PointSequenceSequence& rPointSequence = rBezier.Coordinates;
283*cdf0e10cSrcweir //     const drawing::FlagSequenceSequence& rFlags = rBezier.Flags;
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir     drawing::PolyPolygonShape3D aRet;
286*cdf0e10cSrcweir     aRet.SequenceX.realloc( rPointSequence.getLength() );
287*cdf0e10cSrcweir     aRet.SequenceY.realloc( rPointSequence.getLength() );
288*cdf0e10cSrcweir     aRet.SequenceZ.realloc( rPointSequence.getLength() );
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir     sal_Int32 nRealOuter = 0;
291*cdf0e10cSrcweir     for(sal_Int32 nN = 0; nN < rPointSequence.getLength(); nN++)
292*cdf0e10cSrcweir     {
293*cdf0e10cSrcweir         sal_Int32 nInnerLength = rPointSequence[nN].getLength();
294*cdf0e10cSrcweir         aRet.SequenceX[nN].realloc( nInnerLength );
295*cdf0e10cSrcweir         aRet.SequenceY[nN].realloc( nInnerLength );
296*cdf0e10cSrcweir         aRet.SequenceZ[nN].realloc( nInnerLength );
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir         bool bHasOuterFlags = nN < rBezier.Flags.getLength();
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir         sal_Int32 nRealInner = 0;
301*cdf0e10cSrcweir         for( sal_Int32 nM = 0; nM < nInnerLength; nM++)
302*cdf0e10cSrcweir         {
303*cdf0e10cSrcweir             bool bHasInnerFlags = bHasOuterFlags && (nM < rBezier.Flags[nN].getLength());
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir             if( !bHasInnerFlags || (rBezier.Flags[nN][nM] == drawing::PolygonFlags_NORMAL) )
306*cdf0e10cSrcweir             {
307*cdf0e10cSrcweir                 aRet.SequenceX[nRealOuter][nRealInner] = rPointSequence[nN][nM].X;
308*cdf0e10cSrcweir                 aRet.SequenceY[nRealOuter][nRealInner] = rPointSequence[nN][nM].Y;
309*cdf0e10cSrcweir                 aRet.SequenceZ[nRealOuter][nRealInner] = 0.0;
310*cdf0e10cSrcweir                 nRealInner++;
311*cdf0e10cSrcweir             }
312*cdf0e10cSrcweir         }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir         aRet.SequenceX[nRealOuter].realloc( nRealInner );
315*cdf0e10cSrcweir         aRet.SequenceY[nRealOuter].realloc( nRealInner );
316*cdf0e10cSrcweir         aRet.SequenceZ[nRealOuter].realloc( nRealInner );
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir         if( nRealInner>0 )
319*cdf0e10cSrcweir             nRealOuter++;
320*cdf0e10cSrcweir     }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir     aRet.SequenceX.realloc( nRealOuter );
323*cdf0e10cSrcweir     aRet.SequenceY.realloc( nRealOuter );
324*cdf0e10cSrcweir     aRet.SequenceZ.realloc( nRealOuter );
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     return aRet;
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir drawing::PointSequenceSequence PolyToPointSequence(
330*cdf0e10cSrcweir                 const drawing::PolyPolygonShape3D& rPolyPolygon )
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir     drawing::PointSequenceSequence aRet;
333*cdf0e10cSrcweir     aRet.realloc( rPolyPolygon.SequenceX.getLength() );
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir     for(sal_Int32 nN = 0; nN < rPolyPolygon.SequenceX.getLength(); nN++)
336*cdf0e10cSrcweir     {
337*cdf0e10cSrcweir         sal_Int32 nInnerLength = rPolyPolygon.SequenceX[nN].getLength();
338*cdf0e10cSrcweir         aRet[nN].realloc( nInnerLength );
339*cdf0e10cSrcweir         for( sal_Int32 nM = 0; nM < nInnerLength; nM++)
340*cdf0e10cSrcweir         {
341*cdf0e10cSrcweir             aRet[nN][nM].X = static_cast<sal_Int32>(rPolyPolygon.SequenceX[nN][nM]);
342*cdf0e10cSrcweir             aRet[nN][nM].Y = static_cast<sal_Int32>(rPolyPolygon.SequenceY[nN][nM]);
343*cdf0e10cSrcweir         }
344*cdf0e10cSrcweir     }
345*cdf0e10cSrcweir     return aRet;
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir void appendPointSequence( drawing::PointSequenceSequence& rTarget
349*cdf0e10cSrcweir                         , drawing::PointSequenceSequence& rAdd )
350*cdf0e10cSrcweir {
351*cdf0e10cSrcweir     sal_Int32 nAddCount = rAdd.getLength();
352*cdf0e10cSrcweir     if(!nAddCount)
353*cdf0e10cSrcweir         return;
354*cdf0e10cSrcweir     sal_Int32 nOldCount = rTarget.getLength();
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir     rTarget.realloc(nOldCount+nAddCount);
357*cdf0e10cSrcweir     for(sal_Int32 nS=0; nS<nAddCount; nS++ )
358*cdf0e10cSrcweir         rTarget[nOldCount+nS]=rAdd[nS];
359*cdf0e10cSrcweir }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir drawing::Position3D  operator+( const drawing::Position3D& rPos
362*cdf0e10cSrcweir                            , const drawing::Direction3D& rDirection)
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir     return drawing::Position3D(
365*cdf0e10cSrcweir           rPos.PositionX + rDirection.DirectionX
366*cdf0e10cSrcweir         , rPos.PositionY + rDirection.DirectionY
367*cdf0e10cSrcweir         , rPos.PositionZ + rDirection.DirectionZ
368*cdf0e10cSrcweir         );
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir drawing::Direction3D  operator-( const drawing::Position3D& rPos1
372*cdf0e10cSrcweir                            , const drawing::Position3D& rPos2)
373*cdf0e10cSrcweir {
374*cdf0e10cSrcweir     return drawing::Direction3D(
375*cdf0e10cSrcweir           rPos1.PositionX - rPos2.PositionX
376*cdf0e10cSrcweir         , rPos1.PositionY - rPos2.PositionY
377*cdf0e10cSrcweir         , rPos1.PositionZ - rPos2.PositionZ
378*cdf0e10cSrcweir         );
379*cdf0e10cSrcweir }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir bool operator==( const drawing::Position3D& rPos1
382*cdf0e10cSrcweir                            , const drawing::Position3D& rPos2)
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir     return rPos1.PositionX == rPos2.PositionX
385*cdf0e10cSrcweir         && rPos1.PositionY == rPos2.PositionY
386*cdf0e10cSrcweir         && rPos1.PositionZ == rPos2.PositionZ;
387*cdf0e10cSrcweir }
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir awt::Point Position3DToAWTPoint( const drawing::Position3D& rPos )
390*cdf0e10cSrcweir {
391*cdf0e10cSrcweir     awt::Point aRet;
392*cdf0e10cSrcweir     aRet.X = static_cast<sal_Int32>(rPos.PositionX);
393*cdf0e10cSrcweir     aRet.Y = static_cast<sal_Int32>(rPos.PositionY);
394*cdf0e10cSrcweir     return aRet;
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir awt::Point ToPoint( const awt::Rectangle& rRectangle )
398*cdf0e10cSrcweir {
399*cdf0e10cSrcweir     return awt::Point( rRectangle.X, rRectangle.Y );
400*cdf0e10cSrcweir }
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir awt::Size ToSize( const awt::Rectangle& rRectangle )
403*cdf0e10cSrcweir {
404*cdf0e10cSrcweir     return awt::Size( rRectangle.Width, rRectangle.Height );
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir awt::Size Direction3DToAWTSize( const drawing::Direction3D& rDirection )
408*cdf0e10cSrcweir {
409*cdf0e10cSrcweir     awt::Size aRet;
410*cdf0e10cSrcweir     aRet.Width = static_cast<sal_Int32>(rDirection.DirectionX);
411*cdf0e10cSrcweir     aRet.Height = static_cast<sal_Int32>(rDirection.DirectionY);
412*cdf0e10cSrcweir     return aRet;
413*cdf0e10cSrcweir }
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir uno::Sequence< double > B3DPointToSequence( const ::basegfx::B3DPoint& rPoint )
416*cdf0e10cSrcweir {
417*cdf0e10cSrcweir     uno::Sequence< double > aRet(3);
418*cdf0e10cSrcweir     aRet[0] = rPoint.getX();
419*cdf0e10cSrcweir     aRet[1] = rPoint.getY();
420*cdf0e10cSrcweir     aRet[2] = rPoint.getZ();
421*cdf0e10cSrcweir     return aRet;
422*cdf0e10cSrcweir }
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir drawing::Position3D SequenceToPosition3D( const uno::Sequence< double >& rSeq )
425*cdf0e10cSrcweir {
426*cdf0e10cSrcweir     OSL_ENSURE(rSeq.getLength()==3,"The sequence needs to have length 3 for conversion into vector");
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir     drawing::Position3D aRet;
429*cdf0e10cSrcweir     aRet.PositionX = rSeq.getLength()>0?rSeq[0]:0.0;
430*cdf0e10cSrcweir     aRet.PositionY = rSeq.getLength()>1?rSeq[1]:0.0;
431*cdf0e10cSrcweir     aRet.PositionZ = rSeq.getLength()>2?rSeq[2]:0.0;
432*cdf0e10cSrcweir     return aRet;
433*cdf0e10cSrcweir }
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir uno::Sequence< double > Position3DToSequence( const drawing::Position3D& rPosition )
436*cdf0e10cSrcweir {
437*cdf0e10cSrcweir     uno::Sequence< double > aRet(3);
438*cdf0e10cSrcweir     aRet[0] = rPosition.PositionX;
439*cdf0e10cSrcweir     aRet[1] = rPosition.PositionY;
440*cdf0e10cSrcweir     aRet[2] = rPosition.PositionZ;
441*cdf0e10cSrcweir     return aRet;
442*cdf0e10cSrcweir }
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir uno::Sequence< double > DataSequenceToDoubleSequence(
447*cdf0e10cSrcweir     const uno::Reference< data::XDataSequence >& xDataSequence )
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir     uno::Sequence< double > aResult;
450*cdf0e10cSrcweir     OSL_ASSERT( xDataSequence.is());
451*cdf0e10cSrcweir     if(!xDataSequence.is())
452*cdf0e10cSrcweir         return aResult;
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir     uno::Reference< data::XNumericalDataSequence > xNumericalDataSequence( xDataSequence, uno::UNO_QUERY );
455*cdf0e10cSrcweir     if( xNumericalDataSequence.is() )
456*cdf0e10cSrcweir     {
457*cdf0e10cSrcweir         aResult = xNumericalDataSequence->getNumericalData();
458*cdf0e10cSrcweir     }
459*cdf0e10cSrcweir     else
460*cdf0e10cSrcweir     {
461*cdf0e10cSrcweir         uno::Sequence< uno::Any > aValues = xDataSequence->getData();
462*cdf0e10cSrcweir         aResult.realloc(aValues.getLength());
463*cdf0e10cSrcweir         for(sal_Int32 nN=aValues.getLength();nN--;)
464*cdf0e10cSrcweir         {
465*cdf0e10cSrcweir             if( !(aValues[nN] >>= aResult[nN]) )
466*cdf0e10cSrcweir                 ::rtl::math::setNan( &aResult[nN] );
467*cdf0e10cSrcweir         }
468*cdf0e10cSrcweir     }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir     return aResult;
471*cdf0e10cSrcweir }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir uno::Sequence< rtl::OUString > DataSequenceToStringSequence(
474*cdf0e10cSrcweir     const uno::Reference< data::XDataSequence >& xDataSequence )
475*cdf0e10cSrcweir {
476*cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aResult;
477*cdf0e10cSrcweir     if(!xDataSequence.is())
478*cdf0e10cSrcweir         return aResult;
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir     uno::Reference< data::XTextualDataSequence > xTextualDataSequence( xDataSequence, uno::UNO_QUERY );
481*cdf0e10cSrcweir     if( xTextualDataSequence.is() )
482*cdf0e10cSrcweir     {
483*cdf0e10cSrcweir         aResult = xTextualDataSequence->getTextualData();
484*cdf0e10cSrcweir     }
485*cdf0e10cSrcweir     else
486*cdf0e10cSrcweir     {
487*cdf0e10cSrcweir         uno::Sequence< uno::Any > aValues = xDataSequence->getData();
488*cdf0e10cSrcweir         aResult.realloc(aValues.getLength());
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir         for(sal_Int32 nN=aValues.getLength();nN--;)
491*cdf0e10cSrcweir             aValues[nN] >>= aResult[nN];
492*cdf0e10cSrcweir     }
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir     return aResult;
495*cdf0e10cSrcweir }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir sal_Bool hasDoubleValue( const uno::Any& rAny )
498*cdf0e10cSrcweir {
499*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
500*cdf0e10cSrcweir     double fValue = 0.0;
501*cdf0e10cSrcweir     if( rAny >>= fValue )
502*cdf0e10cSrcweir         bRet = sal_True;
503*cdf0e10cSrcweir     return bRet;
504*cdf0e10cSrcweir }
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir sal_Bool hasLongOrShortValue( const uno::Any& rAny )
507*cdf0e10cSrcweir {
508*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
509*cdf0e10cSrcweir     sal_Int32 n32 = 0;
510*cdf0e10cSrcweir     if( rAny >>= n32 )
511*cdf0e10cSrcweir         bRet = sal_True;
512*cdf0e10cSrcweir     else
513*cdf0e10cSrcweir     {
514*cdf0e10cSrcweir         sal_Int16 n16 = 0;
515*cdf0e10cSrcweir         if( rAny >>= n16 )
516*cdf0e10cSrcweir             bRet = sal_True;
517*cdf0e10cSrcweir     }
518*cdf0e10cSrcweir     return bRet;
519*cdf0e10cSrcweir }
520*cdf0e10cSrcweir sal_Int16 getShortForLongAlso( const uno::Any& rAny )
521*cdf0e10cSrcweir {
522*cdf0e10cSrcweir     sal_Int16 nRet = 0;
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir     if( !(rAny >>= nRet) )
525*cdf0e10cSrcweir     {
526*cdf0e10cSrcweir         sal_Int32 n32 = 0;
527*cdf0e10cSrcweir         if( rAny >>= n32 )
528*cdf0e10cSrcweir             nRet = static_cast<sal_Int16>(n32);
529*cdf0e10cSrcweir     }
530*cdf0e10cSrcweir     return nRet;
531*cdf0e10cSrcweir }
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir bool replaceParamterInString( rtl::OUString & rInOutResourceString,
534*cdf0e10cSrcweir                             const rtl::OUString & rParamToReplace,
535*cdf0e10cSrcweir                             const rtl::OUString & rReplaceWith )
536*cdf0e10cSrcweir {
537*cdf0e10cSrcweir     sal_Int32 nPos = rInOutResourceString.indexOf( rParamToReplace );
538*cdf0e10cSrcweir     if( nPos == -1 )
539*cdf0e10cSrcweir         return false;
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir     rInOutResourceString = rInOutResourceString.replaceAt( nPos
542*cdf0e10cSrcweir                         , rParamToReplace.getLength(), rReplaceWith );
543*cdf0e10cSrcweir     return true;
544*cdf0e10cSrcweir }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir //.............................................................................
547*cdf0e10cSrcweir } //namespace chart
548*cdf0e10cSrcweir //.............................................................................
549