merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / inc / CommonConverters.hxx
blob1ce032b3af69fa57f1878d1f967ddfa2aa852111
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef __CHART_COMMON_CONVERTERS_HXX
28 #define __CHART_COMMON_CONVERTERS_HXX
30 #include <tools/poly.hxx>
31 #include <com/sun/star/awt/Point.hpp>
32 #include <com/sun/star/awt/Rectangle.hpp>
33 #include <com/sun/star/awt/Size.hpp>
34 #include <com/sun/star/drawing/Direction3D.hpp>
35 #include <com/sun/star/drawing/HomogenMatrix.hpp>
36 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
37 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
38 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
39 #include <com/sun/star/drawing/Position3D.hpp>
40 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
41 #include <com/sun/star/text/WritingMode.hpp>
42 #include <com/sun/star/chart2/data/XDataSequence.hpp>
43 #include <basegfx/matrix/b2dhommatrix.hxx>
44 #include <basegfx/point/b3dpoint.hxx>
45 #include <basegfx/vector/b3dvector.hxx>
46 #include "charttoolsdllapi.hxx"
48 #include <vector>
49 #include <algorithm>
51 //.............................................................................
52 namespace chart
54 //.............................................................................
56 //-----------------------------------------------------------------------------
57 /**
58 diverse methods for class conversions; e.g. ::basegfx::B3DHomMatrix to HomogenMatrix
59 and operations e.g drawing::Position3D + drawing::Direction3D
62 //-----------------------------------------------------------------------------
63 /** ::basegfx::B3DHomMatrix -> HomogenMatrix
65 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::HomogenMatrix
66 B3DHomMatrixToHomogenMatrix( const ::basegfx::B3DHomMatrix& rM );
68 //-----------------------------------------------------------------------------
69 /** HomogenMatrix -> ::basegfx::B3DHomMatrix
71 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DHomMatrix HomogenMatrixToB3DHomMatrix( const com::sun::star::drawing::HomogenMatrix& rHM );
73 //-----------------------------------------------------------------------------
74 /** ::basegfx::B3DHomMatrix -> B2DHomMatrix
76 OOO_DLLPUBLIC_CHARTTOOLS
77 ::basegfx::B2DHomMatrix IgnoreZ( const ::basegfx::B3DHomMatrix& rM );
79 //-----------------------------------------------------------------------------
80 /** B2DHomMatrix <-> HomogenMatrix3
82 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::HomogenMatrix3
83 B2DHomMatrixToHomogenMatrix3( const ::basegfx::B2DHomMatrix& rM );
85 //-----------------------------------------------------------------------------
86 /** Position3D -> B3DPoint
88 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DPoint Position3DToB3DPoint( const com::sun::star::drawing::Position3D& rPosition );
90 //-----------------------------------------------------------------------------
91 /** B3DVector -> Direction3D
93 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Direction3D B3DVectorToDirection3D( const ::basegfx::B3DVector& rVector);
95 //-----------------------------------------------------------------------------
96 /** B3DPoint -> Position3D
98 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D B3DPointToPosition3D( const ::basegfx::B3DPoint& rPoint);
100 //-----------------------------------------------------------------------------
101 /** Direction3D -> B3DVector
103 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DVector Direction3DToB3DVector( const com::sun::star::drawing::Direction3D& rDirection);
105 //-----------------------------------------------------------------------------
106 /** PolyPolygonShape3D + drawing::Position3D -> PolyPolygonShape3D
108 OOO_DLLPUBLIC_CHARTTOOLS
109 void AddPointToPoly( ::com::sun::star::drawing::PolyPolygonShape3D& rPoly
110 , const com::sun::star::drawing::Position3D& rPos
111 , sal_Int32 nSequenceIndex=0 );
113 //-----------------------------------------------------------------------------
114 /** get a single Point from a Polygon
116 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::drawing::Position3D getPointFromPoly(
117 const ::com::sun::star::drawing::PolyPolygonShape3D& rPolygon
118 , sal_Int32 nPointIndex, sal_Int32 nPolyIndex=0 );
120 //-----------------------------------------------------------------------------
121 OOO_DLLPUBLIC_CHARTTOOLS
122 void addPolygon( com::sun::star::drawing::PolyPolygonShape3D& rRet
123 , const com::sun::star::drawing::PolyPolygonShape3D& rAdd );
124 //-----------------------------------------------------------------------------
125 /** PolyPolygonShape3D + PolyPolygonShape3D -> PolyPolygonShape3D
127 OOO_DLLPUBLIC_CHARTTOOLS
128 void appendPoly( com::sun::star::drawing::PolyPolygonShape3D& rRet
129 , const com::sun::star::drawing::PolyPolygonShape3D& rAdd );
131 //-----------------------------------------------------------------------------
132 /** PolyPolygonBezierCoords -> PolyPolygonShape3D
134 OOO_DLLPUBLIC_CHARTTOOLS
135 com::sun::star::drawing::PolyPolygonShape3D BezierToPoly(
136 const com::sun::star::drawing::PolyPolygonBezierCoords& rBezier );
138 //-----------------------------------------------------------------------------
139 /** PolyPolygonShape3D -> drawing::PointSequenceSequence (2D)
141 OOO_DLLPUBLIC_CHARTTOOLS
142 com::sun::star::drawing::PointSequenceSequence PolyToPointSequence(
143 const com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygon );
145 //-----------------------------------------------------------------------------
146 /** drawing::PointSequenceSequence + drawing::PointSequenceSequence
148 OOO_DLLPUBLIC_CHARTTOOLS
149 void appendPointSequence( com::sun::star::drawing::PointSequenceSequence& rTarget
150 , com::sun::star::drawing::PointSequenceSequence& rAdd );
152 //-----------------------------------------------------------------------------
153 /** Position3D + Direction3D == Position3D
155 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D
156 operator+( const com::sun::star::drawing::Position3D& rPos
157 , const com::sun::star::drawing::Direction3D& rDirection);
159 //-----------------------------------------------------------------------------
160 /** Position3D - Position3D == Direction3D
162 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Direction3D
163 operator-( const com::sun::star::drawing::Position3D& rPos1
164 , const com::sun::star::drawing::Position3D& rPos2);
166 //-----------------------------------------------------------------------------
167 /** Position3D == Position3D ?
169 OOO_DLLPUBLIC_CHARTTOOLS
170 bool operator==( const com::sun::star::drawing::Position3D& rPos1
171 , const com::sun::star::drawing::Position3D& rPos2);
173 //-----------------------------------------------------------------------------
174 /** awt::Rect --> awt::Point (2D)
176 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Point ToPoint( const com::sun::star::awt::Rectangle& rRectangle );
178 //-----------------------------------------------------------------------------
179 /** awt::Rect --> awt::Size (2D)
181 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Size ToSize( const com::sun::star::awt::Rectangle& rRectangle );
183 //-----------------------------------------------------------------------------
184 /** Position3D --> awt::Point (2D)
186 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Point Position3DToAWTPoint( const com::sun::star::drawing::Position3D& rPos );
188 //-----------------------------------------------------------------------------
189 /** Direction3D --> awt::Size (2D)
191 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Size Direction3DToAWTSize( const com::sun::star::drawing::Direction3D& rDirection );
193 //-----------------------------------------------------------------------------
194 /** B3DPoint -> Sequence<double>
196 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::uno::Sequence< double > B3DPointToSequence( const ::basegfx::B3DPoint& rPoint );
198 //-----------------------------------------------------------------------------
199 /** Sequence<double> -> drawing::Position3D
201 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D
202 SequenceToPosition3D( const com::sun::star::uno::Sequence< double >& rSeq );
204 //-----------------------------------------------------------------------------
205 /** drawing::Position3D -> Sequence<double>
208 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::uno::Sequence< double >
209 Position3DToSequence( const com::sun::star::drawing::Position3D& rPosition );
211 //-----------------------------------------------------------------------------
212 /** chart2::XDataSequence -> uno::Sequence< double >
215 OOO_DLLPUBLIC_CHARTTOOLS
216 ::com::sun::star::uno::Sequence< double > DataSequenceToDoubleSequence(
217 const ::com::sun::star::uno::Reference<
218 ::com::sun::star::chart2::data::XDataSequence > & xDataSequence );
220 OOO_DLLPUBLIC_CHARTTOOLS
221 ::com::sun::star::uno::Sequence< rtl::OUString > DataSequenceToStringSequence(
222 const ::com::sun::star::uno::Reference<
223 ::com::sun::star::chart2::data::XDataSequence > & xDataSequence );
225 //-----------------------------------------------------------------------------
226 /** uno::Sequence< uno::Sequence< T > > -> uno::Sequence< T >
228 template< typename T >
229 ::com::sun::star::uno::Sequence< T >
230 FlattenSequence( const ::com::sun::star::uno::Sequence<
231 ::com::sun::star::uno::Sequence< T > > & aSeqSeq )
233 sal_Int32 nOuter, nInner, nCount = 0,
234 nResultSize = 0;
235 const sal_Int32 nOuterSize = aSeqSeq.getLength();
236 for( nOuter=0; nOuter<nOuterSize; ++nOuter )
237 nResultSize += aSeqSeq[nOuter].getLength();
238 ::com::sun::star::uno::Sequence< T > aResult( nResultSize );
240 for( nOuter=0; nOuter<nOuterSize; ++nOuter )
242 const sal_Int32 nInnerSize = aSeqSeq[nOuter].getLength();
243 for( nInner=0; nInner<nInnerSize; ++nInner, ++nCount )
244 aResult[nCount] = aSeqSeq[nOuter][nInner];
246 return aResult;
249 template< typename T >
250 ::std::vector< T >
251 FlattenVector( const ::std::vector< ::std::vector< T > > & rVecVec )
253 typedef ::std::vector< T > tFlatVec;
254 typedef ::std::vector< tFlatVec > tVecVec;
256 tFlatVec aResult;
257 typename tVecVec::const_iterator aOuterEnd( rVecVec.end());
258 for( typename tVecVec::const_iterator aOuterIt( rVecVec.begin()); aOuterIt != aOuterEnd; ++aOuterIt )
259 ::std::copy( aOuterIt->begin(), aOuterIt->end(), back_inserter( aResult ));
260 return aResult;
263 OOO_DLLPUBLIC_CHARTTOOLS
264 sal_Bool hasDoubleValue( const ::com::sun::star::uno::Any& rAny );
266 OOO_DLLPUBLIC_CHARTTOOLS
267 sal_Bool hasLongOrShortValue( const ::com::sun::star::uno::Any& rAny );
268 OOO_DLLPUBLIC_CHARTTOOLS
269 sal_Int16 getShortForLongAlso( const ::com::sun::star::uno::Any& rAny );
271 OOO_DLLPUBLIC_CHARTTOOLS
272 bool replaceParamterInString( rtl::OUString & rInOutResourceString,
273 const rtl::OUString & rParamToReplace,
274 const rtl::OUString & rReplaceWith );
276 //.............................................................................
277 } //namespace chart
278 //.............................................................................
279 #endif