Bump for 3.6-28
[LibreOffice.git] / chart2 / source / inc / CommonConverters.hxx
blob883e3ff2f00eebe470c4f8f0917e4f64b4f1672f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
28 #ifndef __CHART_COMMON_CONVERTERS_HXX
29 #define __CHART_COMMON_CONVERTERS_HXX
31 #include <tools/poly.hxx>
32 #include <com/sun/star/awt/Point.hpp>
33 #include <com/sun/star/awt/Rectangle.hpp>
34 #include <com/sun/star/awt/Size.hpp>
35 #include <com/sun/star/drawing/Direction3D.hpp>
36 #include <com/sun/star/drawing/HomogenMatrix.hpp>
37 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
38 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
39 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
40 #include <com/sun/star/drawing/Position3D.hpp>
41 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
42 #include <com/sun/star/text/WritingMode.hpp>
43 #include <com/sun/star/chart2/data/XDataSequence.hpp>
44 #include <basegfx/matrix/b2dhommatrix.hxx>
45 #include <basegfx/point/b3dpoint.hxx>
46 #include <basegfx/vector/b3dvector.hxx>
47 #include "charttoolsdllapi.hxx"
49 #include <vector>
50 #include <algorithm>
52 //.............................................................................
53 namespace chart
55 //.............................................................................
57 //-----------------------------------------------------------------------------
58 /**
59 diverse methods for class conversions; e.g. ::basegfx::B3DHomMatrix to HomogenMatrix
60 and operations e.g drawing::Position3D + drawing::Direction3D
63 //-----------------------------------------------------------------------------
64 /** ::basegfx::B3DHomMatrix -> HomogenMatrix
66 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::HomogenMatrix
67 B3DHomMatrixToHomogenMatrix( const ::basegfx::B3DHomMatrix& rM );
69 //-----------------------------------------------------------------------------
70 /** HomogenMatrix -> ::basegfx::B3DHomMatrix
72 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DHomMatrix HomogenMatrixToB3DHomMatrix( const com::sun::star::drawing::HomogenMatrix& rHM );
74 //-----------------------------------------------------------------------------
75 /** ::basegfx::B3DHomMatrix -> B2DHomMatrix
77 OOO_DLLPUBLIC_CHARTTOOLS
78 ::basegfx::B2DHomMatrix IgnoreZ( const ::basegfx::B3DHomMatrix& rM );
80 //-----------------------------------------------------------------------------
81 /** B2DHomMatrix <-> HomogenMatrix3
83 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::HomogenMatrix3
84 B2DHomMatrixToHomogenMatrix3( const ::basegfx::B2DHomMatrix& rM );
86 //-----------------------------------------------------------------------------
87 /** Position3D -> B3DPoint
89 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DPoint Position3DToB3DPoint( const com::sun::star::drawing::Position3D& rPosition );
91 //-----------------------------------------------------------------------------
92 /** B3DVector -> Direction3D
94 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Direction3D B3DVectorToDirection3D( const ::basegfx::B3DVector& rVector);
96 //-----------------------------------------------------------------------------
97 /** B3DPoint -> Position3D
99 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D B3DPointToPosition3D( const ::basegfx::B3DPoint& rPoint);
101 //-----------------------------------------------------------------------------
102 /** Direction3D -> B3DVector
104 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DVector Direction3DToB3DVector( const com::sun::star::drawing::Direction3D& rDirection);
106 //-----------------------------------------------------------------------------
107 /** PolyPolygonShape3D + drawing::Position3D -> PolyPolygonShape3D
109 OOO_DLLPUBLIC_CHARTTOOLS
110 void AddPointToPoly( ::com::sun::star::drawing::PolyPolygonShape3D& rPoly
111 , const com::sun::star::drawing::Position3D& rPos
112 , sal_Int32 nSequenceIndex=0 );
114 //-----------------------------------------------------------------------------
115 /** get a single Point from a Polygon
117 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::drawing::Position3D getPointFromPoly(
118 const ::com::sun::star::drawing::PolyPolygonShape3D& rPolygon
119 , sal_Int32 nPointIndex, sal_Int32 nPolyIndex=0 );
121 //-----------------------------------------------------------------------------
122 OOO_DLLPUBLIC_CHARTTOOLS
123 void addPolygon( com::sun::star::drawing::PolyPolygonShape3D& rRet
124 , const com::sun::star::drawing::PolyPolygonShape3D& rAdd );
125 //-----------------------------------------------------------------------------
126 /** PolyPolygonShape3D + PolyPolygonShape3D -> PolyPolygonShape3D
128 OOO_DLLPUBLIC_CHARTTOOLS
129 void appendPoly( com::sun::star::drawing::PolyPolygonShape3D& rRet
130 , const com::sun::star::drawing::PolyPolygonShape3D& rAdd );
132 //-----------------------------------------------------------------------------
133 /** PolyPolygonBezierCoords -> PolyPolygonShape3D
135 OOO_DLLPUBLIC_CHARTTOOLS
136 com::sun::star::drawing::PolyPolygonShape3D BezierToPoly(
137 const com::sun::star::drawing::PolyPolygonBezierCoords& rBezier );
139 //-----------------------------------------------------------------------------
140 /** PolyPolygonShape3D -> drawing::PointSequenceSequence (2D)
142 OOO_DLLPUBLIC_CHARTTOOLS
143 com::sun::star::drawing::PointSequenceSequence PolyToPointSequence(
144 const com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygon );
146 //-----------------------------------------------------------------------------
147 /** drawing::PointSequenceSequence + drawing::PointSequenceSequence
149 OOO_DLLPUBLIC_CHARTTOOLS
150 void appendPointSequence( com::sun::star::drawing::PointSequenceSequence& rTarget
151 , com::sun::star::drawing::PointSequenceSequence& rAdd );
153 //-----------------------------------------------------------------------------
154 /** Position3D + Direction3D == Position3D
156 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D
157 operator+( const com::sun::star::drawing::Position3D& rPos
158 , const com::sun::star::drawing::Direction3D& rDirection);
160 //-----------------------------------------------------------------------------
161 /** Position3D - Position3D == Direction3D
163 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Direction3D
164 operator-( const com::sun::star::drawing::Position3D& rPos1
165 , const com::sun::star::drawing::Position3D& rPos2);
167 //-----------------------------------------------------------------------------
168 /** Position3D == Position3D ?
170 OOO_DLLPUBLIC_CHARTTOOLS
171 bool operator==( const com::sun::star::drawing::Position3D& rPos1
172 , const com::sun::star::drawing::Position3D& rPos2);
174 //-----------------------------------------------------------------------------
175 /** awt::Rect --> awt::Point (2D)
177 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Point ToPoint( const com::sun::star::awt::Rectangle& rRectangle );
179 //-----------------------------------------------------------------------------
180 /** awt::Rect --> awt::Size (2D)
182 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Size ToSize( const com::sun::star::awt::Rectangle& rRectangle );
184 //-----------------------------------------------------------------------------
185 /** Position3D --> awt::Point (2D)
187 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Point Position3DToAWTPoint( const com::sun::star::drawing::Position3D& rPos );
189 //-----------------------------------------------------------------------------
190 /** Direction3D --> awt::Size (2D)
192 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Size Direction3DToAWTSize( const com::sun::star::drawing::Direction3D& rDirection );
194 //-----------------------------------------------------------------------------
195 /** B3DPoint -> Sequence<double>
197 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::uno::Sequence< double > B3DPointToSequence( const ::basegfx::B3DPoint& rPoint );
199 //-----------------------------------------------------------------------------
200 /** Sequence<double> -> drawing::Position3D
202 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D
203 SequenceToPosition3D( const com::sun::star::uno::Sequence< double >& rSeq );
205 //-----------------------------------------------------------------------------
206 /** drawing::Position3D -> Sequence<double>
209 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::uno::Sequence< double >
210 Position3DToSequence( const com::sun::star::drawing::Position3D& rPosition );
212 //-----------------------------------------------------------------------------
213 /** chart2::XDataSequence -> uno::Sequence< double >
216 OOO_DLLPUBLIC_CHARTTOOLS
217 ::com::sun::star::uno::Sequence< double > DataSequenceToDoubleSequence(
218 const ::com::sun::star::uno::Reference<
219 ::com::sun::star::chart2::data::XDataSequence > & xDataSequence );
221 OOO_DLLPUBLIC_CHARTTOOLS
222 ::com::sun::star::uno::Sequence< rtl::OUString > DataSequenceToStringSequence(
223 const ::com::sun::star::uno::Reference<
224 ::com::sun::star::chart2::data::XDataSequence > & xDataSequence );
226 //-----------------------------------------------------------------------------
227 /** uno::Sequence< uno::Sequence< T > > -> uno::Sequence< T >
229 template< typename T >
230 ::com::sun::star::uno::Sequence< T >
231 FlattenSequence( const ::com::sun::star::uno::Sequence<
232 ::com::sun::star::uno::Sequence< T > > & aSeqSeq )
234 sal_Int32 nOuter, nInner, nCount = 0,
235 nResultSize = 0;
236 const sal_Int32 nOuterSize = aSeqSeq.getLength();
237 for( nOuter=0; nOuter<nOuterSize; ++nOuter )
238 nResultSize += aSeqSeq[nOuter].getLength();
239 ::com::sun::star::uno::Sequence< T > aResult( nResultSize );
241 for( nOuter=0; nOuter<nOuterSize; ++nOuter )
243 const sal_Int32 nInnerSize = aSeqSeq[nOuter].getLength();
244 for( nInner=0; nInner<nInnerSize; ++nInner, ++nCount )
245 aResult[nCount] = aSeqSeq[nOuter][nInner];
247 return aResult;
250 template< typename T >
251 ::std::vector< T >
252 FlattenVector( const ::std::vector< ::std::vector< T > > & rVecVec )
254 typedef ::std::vector< T > tFlatVec;
255 typedef ::std::vector< tFlatVec > tVecVec;
257 tFlatVec aResult;
258 typename tVecVec::const_iterator aOuterEnd( rVecVec.end());
259 for( typename tVecVec::const_iterator aOuterIt( rVecVec.begin()); aOuterIt != aOuterEnd; ++aOuterIt )
260 ::std::copy( aOuterIt->begin(), aOuterIt->end(), back_inserter( aResult ));
261 return aResult;
264 OOO_DLLPUBLIC_CHARTTOOLS
265 sal_Bool hasDoubleValue( const ::com::sun::star::uno::Any& rAny );
267 OOO_DLLPUBLIC_CHARTTOOLS
268 sal_Bool hasLongOrShortValue( const ::com::sun::star::uno::Any& rAny );
269 OOO_DLLPUBLIC_CHARTTOOLS
270 sal_Int16 getShortForLongAlso( const ::com::sun::star::uno::Any& rAny );
272 OOO_DLLPUBLIC_CHARTTOOLS
273 bool replaceParamterInString( rtl::OUString & rInOutResourceString,
274 const rtl::OUString & rParamToReplace,
275 const rtl::OUString & rReplaceWith );
277 //.............................................................................
278 } //namespace chart
279 //.............................................................................
280 #endif
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */