merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / inc / CommonConverters.hxx
blob0d55825bdf4da67d5a47ec929d2689aa04c2fee7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CommonConverters.hxx,v $
10 * $Revision: 1.10.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef __CHART_COMMON_CONVERTERS_HXX
31 #define __CHART_COMMON_CONVERTERS_HXX
33 #include <tools/poly.hxx>
34 #include <com/sun/star/awt/Point.hpp>
35 #include <com/sun/star/awt/Rectangle.hpp>
36 #include <com/sun/star/awt/Size.hpp>
37 #include <com/sun/star/drawing/Direction3D.hpp>
38 #include <com/sun/star/drawing/HomogenMatrix.hpp>
39 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
40 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
41 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
42 #include <com/sun/star/drawing/Position3D.hpp>
43 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
44 #include <com/sun/star/text/WritingMode.hpp>
45 #include <com/sun/star/chart2/data/XDataSequence.hpp>
46 #include <basegfx/matrix/b2dhommatrix.hxx>
47 #include <basegfx/point/b3dpoint.hxx>
48 #include <basegfx/vector/b3dvector.hxx>
49 #include "charttoolsdllapi.hxx"
51 #include <vector>
52 #include <algorithm>
54 //.............................................................................
55 namespace chart
57 //.............................................................................
59 //-----------------------------------------------------------------------------
60 /**
61 diverse methods for class conversions; e.g. ::basegfx::B3DHomMatrix to HomogenMatrix
62 and operations e.g drawing::Position3D + drawing::Direction3D
65 //-----------------------------------------------------------------------------
66 /** ::basegfx::B3DHomMatrix -> HomogenMatrix
68 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::HomogenMatrix
69 B3DHomMatrixToHomogenMatrix( const ::basegfx::B3DHomMatrix& rM );
71 //-----------------------------------------------------------------------------
72 /** HomogenMatrix -> ::basegfx::B3DHomMatrix
74 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DHomMatrix HomogenMatrixToB3DHomMatrix( const com::sun::star::drawing::HomogenMatrix& rHM );
76 //-----------------------------------------------------------------------------
77 /** ::basegfx::B3DHomMatrix -> B2DHomMatrix
79 OOO_DLLPUBLIC_CHARTTOOLS
80 ::basegfx::B2DHomMatrix IgnoreZ( const ::basegfx::B3DHomMatrix& rM );
82 //-----------------------------------------------------------------------------
83 /** B2DHomMatrix <-> HomogenMatrix3
85 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::HomogenMatrix3
86 B2DHomMatrixToHomogenMatrix3( const ::basegfx::B2DHomMatrix& rM );
88 //-----------------------------------------------------------------------------
89 /** Position3D -> B3DPoint
91 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DPoint Position3DToB3DPoint( const com::sun::star::drawing::Position3D& rPosition );
93 //-----------------------------------------------------------------------------
94 /** B3DVector -> Direction3D
96 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Direction3D B3DVectorToDirection3D( const ::basegfx::B3DVector& rVector);
98 //-----------------------------------------------------------------------------
99 /** B3DPoint -> Position3D
101 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D B3DPointToPosition3D( const ::basegfx::B3DPoint& rPoint);
103 //-----------------------------------------------------------------------------
104 /** Direction3D -> B3DVector
106 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DVector Direction3DToB3DVector( const com::sun::star::drawing::Direction3D& rDirection);
108 //-----------------------------------------------------------------------------
109 /** PolyPolygonShape3D + drawing::Position3D -> PolyPolygonShape3D
111 OOO_DLLPUBLIC_CHARTTOOLS
112 void AddPointToPoly( ::com::sun::star::drawing::PolyPolygonShape3D& rPoly
113 , const com::sun::star::drawing::Position3D& rPos
114 , sal_Int32 nSequenceIndex=0 );
116 //-----------------------------------------------------------------------------
117 /** get a single Point from a Polygon
119 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::drawing::Position3D getPointFromPoly(
120 const ::com::sun::star::drawing::PolyPolygonShape3D& rPolygon
121 , sal_Int32 nPointIndex, sal_Int32 nPolyIndex=0 );
123 //-----------------------------------------------------------------------------
124 OOO_DLLPUBLIC_CHARTTOOLS
125 void addPolygon( com::sun::star::drawing::PolyPolygonShape3D& rRet
126 , const com::sun::star::drawing::PolyPolygonShape3D& rAdd );
127 //-----------------------------------------------------------------------------
128 /** PolyPolygonShape3D + PolyPolygonShape3D -> PolyPolygonShape3D
130 OOO_DLLPUBLIC_CHARTTOOLS
131 void appendPoly( com::sun::star::drawing::PolyPolygonShape3D& rRet
132 , const com::sun::star::drawing::PolyPolygonShape3D& rAdd );
134 //-----------------------------------------------------------------------------
135 /** PolyPolygonBezierCoords -> PolyPolygonShape3D
137 OOO_DLLPUBLIC_CHARTTOOLS
138 com::sun::star::drawing::PolyPolygonShape3D BezierToPoly(
139 const com::sun::star::drawing::PolyPolygonBezierCoords& rBezier );
141 //-----------------------------------------------------------------------------
142 /** PolyPolygonShape3D -> drawing::PointSequenceSequence (2D)
144 OOO_DLLPUBLIC_CHARTTOOLS
145 com::sun::star::drawing::PointSequenceSequence PolyToPointSequence(
146 const com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygon );
148 //-----------------------------------------------------------------------------
149 /** drawing::PointSequenceSequence + drawing::PointSequenceSequence
151 OOO_DLLPUBLIC_CHARTTOOLS
152 void appendPointSequence( com::sun::star::drawing::PointSequenceSequence& rTarget
153 , com::sun::star::drawing::PointSequenceSequence& rAdd );
155 //-----------------------------------------------------------------------------
156 /** Position3D + Direction3D == Position3D
158 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D
159 operator+( const com::sun::star::drawing::Position3D& rPos
160 , const com::sun::star::drawing::Direction3D& rDirection);
162 //-----------------------------------------------------------------------------
163 /** Position3D - Position3D == Direction3D
165 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Direction3D
166 operator-( const com::sun::star::drawing::Position3D& rPos1
167 , const com::sun::star::drawing::Position3D& rPos2);
169 //-----------------------------------------------------------------------------
170 /** Position3D == Position3D ?
172 OOO_DLLPUBLIC_CHARTTOOLS
173 bool operator==( const com::sun::star::drawing::Position3D& rPos1
174 , const com::sun::star::drawing::Position3D& rPos2);
176 //-----------------------------------------------------------------------------
177 /** awt::Rect --> awt::Point (2D)
179 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Point ToPoint( const com::sun::star::awt::Rectangle& rRectangle );
181 //-----------------------------------------------------------------------------
182 /** awt::Rect --> awt::Size (2D)
184 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Size ToSize( const com::sun::star::awt::Rectangle& rRectangle );
186 //-----------------------------------------------------------------------------
187 /** Position3D --> awt::Point (2D)
189 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Point Position3DToAWTPoint( const com::sun::star::drawing::Position3D& rPos );
191 //-----------------------------------------------------------------------------
192 /** Direction3D --> awt::Size (2D)
194 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Size Direction3DToAWTSize( const com::sun::star::drawing::Direction3D& rDirection );
196 //-----------------------------------------------------------------------------
197 /** B3DPoint -> Sequence<double>
199 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::uno::Sequence< double > B3DPointToSequence( const ::basegfx::B3DPoint& rPoint );
201 //-----------------------------------------------------------------------------
202 /** Sequence<double> -> drawing::Position3D
204 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D
205 SequenceToPosition3D( const com::sun::star::uno::Sequence< double >& rSeq );
207 //-----------------------------------------------------------------------------
208 /** drawing::Position3D -> Sequence<double>
211 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::uno::Sequence< double >
212 Position3DToSequence( const com::sun::star::drawing::Position3D& rPosition );
214 //-----------------------------------------------------------------------------
215 /** chart2::XDataSequence -> uno::Sequence< double >
218 OOO_DLLPUBLIC_CHARTTOOLS
219 ::com::sun::star::uno::Sequence< double > DataSequenceToDoubleSequence(
220 const ::com::sun::star::uno::Reference<
221 ::com::sun::star::chart2::data::XDataSequence > & xDataSequence );
223 OOO_DLLPUBLIC_CHARTTOOLS
224 ::com::sun::star::uno::Sequence< rtl::OUString > DataSequenceToStringSequence(
225 const ::com::sun::star::uno::Reference<
226 ::com::sun::star::chart2::data::XDataSequence > & xDataSequence );
228 //-----------------------------------------------------------------------------
229 /** uno::Sequence< uno::Sequence< T > > -> uno::Sequence< T >
231 template< typename T >
232 ::com::sun::star::uno::Sequence< T >
233 FlattenSequence( const ::com::sun::star::uno::Sequence<
234 ::com::sun::star::uno::Sequence< T > > & aSeqSeq )
236 sal_Int32 nOuter, nInner, nCount = 0,
237 nResultSize = 0;
238 const sal_Int32 nOuterSize = aSeqSeq.getLength();
239 for( nOuter=0; nOuter<nOuterSize; ++nOuter )
240 nResultSize += aSeqSeq[nOuter].getLength();
241 ::com::sun::star::uno::Sequence< T > aResult( nResultSize );
243 for( nOuter=0; nOuter<nOuterSize; ++nOuter )
245 const sal_Int32 nInnerSize = aSeqSeq[nOuter].getLength();
246 for( nInner=0; nInner<nInnerSize; ++nInner, ++nCount )
247 aResult[nCount] = aSeqSeq[nOuter][nInner];
249 return aResult;
252 template< typename T >
253 ::std::vector< T >
254 FlattenVector( const ::std::vector< ::std::vector< T > > & rVecVec )
256 typedef ::std::vector< T > tFlatVec;
257 typedef ::std::vector< tFlatVec > tVecVec;
259 tFlatVec aResult;
260 typename tVecVec::const_iterator aOuterEnd( rVecVec.end());
261 for( typename tVecVec::const_iterator aOuterIt( rVecVec.begin()); aOuterIt != aOuterEnd; ++aOuterIt )
262 ::std::copy( aOuterIt->begin(), aOuterIt->end(), back_inserter( aResult ));
263 return aResult;
266 OOO_DLLPUBLIC_CHARTTOOLS
267 sal_Bool hasDoubleValue( const ::com::sun::star::uno::Any& rAny );
269 OOO_DLLPUBLIC_CHARTTOOLS
270 sal_Bool hasLongOrShortValue( const ::com::sun::star::uno::Any& rAny );
271 OOO_DLLPUBLIC_CHARTTOOLS
272 sal_Int16 getShortForLongAlso( const ::com::sun::star::uno::Any& rAny );
274 OOO_DLLPUBLIC_CHARTTOOLS
275 bool replaceParamterInString( rtl::OUString & rInOutResourceString,
276 const rtl::OUString & rParamToReplace,
277 const rtl::OUString & rReplaceWith );
279 //.............................................................................
280 } //namespace chart
281 //.............................................................................
282 #endif