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