xref: /trunk/main/chart2/source/inc/CommonConverters.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*de7b3f82SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*de7b3f82SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*de7b3f82SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*de7b3f82SAndrew Rist  * distributed with this work for additional information
6*de7b3f82SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*de7b3f82SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*de7b3f82SAndrew Rist  * "License"); you may not use this file except in compliance
9*de7b3f82SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*de7b3f82SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*de7b3f82SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*de7b3f82SAndrew Rist  * software distributed under the License is distributed on an
15*de7b3f82SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*de7b3f82SAndrew Rist  * KIND, either express or implied.  See the License for the
17*de7b3f82SAndrew Rist  * specific language governing permissions and limitations
18*de7b3f82SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*de7b3f82SAndrew Rist  *************************************************************/
21*de7b3f82SAndrew Rist 
22*de7b3f82SAndrew Rist 
23cdf0e10cSrcweir #ifndef __CHART_COMMON_CONVERTERS_HXX
24cdf0e10cSrcweir #define __CHART_COMMON_CONVERTERS_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <tools/poly.hxx>
27cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp>
28cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp>
29cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
30cdf0e10cSrcweir #include <com/sun/star/drawing/Direction3D.hpp>
31cdf0e10cSrcweir #include <com/sun/star/drawing/HomogenMatrix.hpp>
32cdf0e10cSrcweir #include <com/sun/star/drawing/HomogenMatrix3.hpp>
33cdf0e10cSrcweir #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
34cdf0e10cSrcweir #include <com/sun/star/drawing/PointSequenceSequence.hpp>
35cdf0e10cSrcweir #include <com/sun/star/drawing/Position3D.hpp>
36cdf0e10cSrcweir #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
37cdf0e10cSrcweir #include <com/sun/star/text/WritingMode.hpp>
38cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSequence.hpp>
39cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
40cdf0e10cSrcweir #include <basegfx/point/b3dpoint.hxx>
41cdf0e10cSrcweir #include <basegfx/vector/b3dvector.hxx>
42cdf0e10cSrcweir #include "charttoolsdllapi.hxx"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <vector>
45cdf0e10cSrcweir #include <algorithm>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //.............................................................................
48cdf0e10cSrcweir namespace chart
49cdf0e10cSrcweir {
50cdf0e10cSrcweir //.............................................................................
51cdf0e10cSrcweir 
52cdf0e10cSrcweir //-----------------------------------------------------------------------------
53cdf0e10cSrcweir /**
54cdf0e10cSrcweir diverse methods for class conversions; e.g. ::basegfx::B3DHomMatrix to HomogenMatrix
55cdf0e10cSrcweir and operations e.g  drawing::Position3D + drawing::Direction3D
56cdf0e10cSrcweir */
57cdf0e10cSrcweir 
58cdf0e10cSrcweir //-----------------------------------------------------------------------------
59cdf0e10cSrcweir /** ::basegfx::B3DHomMatrix -> HomogenMatrix
60cdf0e10cSrcweir */
61cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::HomogenMatrix
62cdf0e10cSrcweir                  B3DHomMatrixToHomogenMatrix( const ::basegfx::B3DHomMatrix& rM );
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //-----------------------------------------------------------------------------
65cdf0e10cSrcweir /** HomogenMatrix -> ::basegfx::B3DHomMatrix
66cdf0e10cSrcweir */
67cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DHomMatrix HomogenMatrixToB3DHomMatrix( const com::sun::star::drawing::HomogenMatrix& rHM );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //-----------------------------------------------------------------------------
70cdf0e10cSrcweir /** ::basegfx::B3DHomMatrix -> B2DHomMatrix
71cdf0e10cSrcweir */
72cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
73cdf0e10cSrcweir ::basegfx::B2DHomMatrix IgnoreZ( const ::basegfx::B3DHomMatrix& rM );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir //-----------------------------------------------------------------------------
76cdf0e10cSrcweir /** B2DHomMatrix <-> HomogenMatrix3
77cdf0e10cSrcweir */
78cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::HomogenMatrix3
79cdf0e10cSrcweir                 B2DHomMatrixToHomogenMatrix3( const ::basegfx::B2DHomMatrix& rM );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir //-----------------------------------------------------------------------------
82cdf0e10cSrcweir /** Position3D -> B3DPoint
83cdf0e10cSrcweir */
84cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DPoint Position3DToB3DPoint( const com::sun::star::drawing::Position3D& rPosition );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //-----------------------------------------------------------------------------
87cdf0e10cSrcweir /** B3DVector -> Direction3D
88cdf0e10cSrcweir */
89cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Direction3D B3DVectorToDirection3D( const ::basegfx::B3DVector& rVector);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir //-----------------------------------------------------------------------------
92cdf0e10cSrcweir /** B3DPoint -> Position3D
93cdf0e10cSrcweir */
94cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D B3DPointToPosition3D( const ::basegfx::B3DPoint& rPoint);
95cdf0e10cSrcweir 
96cdf0e10cSrcweir //-----------------------------------------------------------------------------
97cdf0e10cSrcweir /** Direction3D -> B3DVector
98cdf0e10cSrcweir */
99cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DVector Direction3DToB3DVector( const com::sun::star::drawing::Direction3D& rDirection);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir //-----------------------------------------------------------------------------
102cdf0e10cSrcweir /** PolyPolygonShape3D + drawing::Position3D -> PolyPolygonShape3D
103cdf0e10cSrcweir */
104cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
105cdf0e10cSrcweir void AddPointToPoly( ::com::sun::star::drawing::PolyPolygonShape3D& rPoly
106cdf0e10cSrcweir                 , const com::sun::star::drawing::Position3D& rPos
107cdf0e10cSrcweir                 , sal_Int32 nSequenceIndex=0 );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir //-----------------------------------------------------------------------------
110cdf0e10cSrcweir /** get a single Point from a Polygon
111cdf0e10cSrcweir */
112cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::drawing::Position3D getPointFromPoly(
113cdf0e10cSrcweir                   const ::com::sun::star::drawing::PolyPolygonShape3D& rPolygon
114cdf0e10cSrcweir                 , sal_Int32 nPointIndex, sal_Int32 nPolyIndex=0 );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir //-----------------------------------------------------------------------------
117cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
118cdf0e10cSrcweir void addPolygon( com::sun::star::drawing::PolyPolygonShape3D& rRet
119cdf0e10cSrcweir                 , const com::sun::star::drawing::PolyPolygonShape3D& rAdd );
120cdf0e10cSrcweir //-----------------------------------------------------------------------------
121cdf0e10cSrcweir /** PolyPolygonShape3D + PolyPolygonShape3D -> PolyPolygonShape3D
122cdf0e10cSrcweir */
123cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
124cdf0e10cSrcweir void appendPoly( com::sun::star::drawing::PolyPolygonShape3D& rRet
125cdf0e10cSrcweir                 , const com::sun::star::drawing::PolyPolygonShape3D& rAdd );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir //-----------------------------------------------------------------------------
128cdf0e10cSrcweir /** PolyPolygonBezierCoords -> PolyPolygonShape3D
129cdf0e10cSrcweir */
130cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
131cdf0e10cSrcweir com::sun::star::drawing::PolyPolygonShape3D BezierToPoly(
132cdf0e10cSrcweir     const com::sun::star::drawing::PolyPolygonBezierCoords& rBezier );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir //-----------------------------------------------------------------------------
135cdf0e10cSrcweir /** PolyPolygonShape3D -> drawing::PointSequenceSequence (2D)
136cdf0e10cSrcweir */
137cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
138cdf0e10cSrcweir com::sun::star::drawing::PointSequenceSequence PolyToPointSequence(
139cdf0e10cSrcweir                 const com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygon );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //-----------------------------------------------------------------------------
142cdf0e10cSrcweir /** drawing::PointSequenceSequence + drawing::PointSequenceSequence
143cdf0e10cSrcweir */
144cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
145cdf0e10cSrcweir void appendPointSequence( com::sun::star::drawing::PointSequenceSequence& rTarget
146cdf0e10cSrcweir                         , com::sun::star::drawing::PointSequenceSequence& rAdd );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir //-----------------------------------------------------------------------------
149cdf0e10cSrcweir /** Position3D + Direction3D == Position3D
150cdf0e10cSrcweir */
151cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D
152cdf0e10cSrcweir                 operator+( const com::sun::star::drawing::Position3D& rPos
153cdf0e10cSrcweir                            , const com::sun::star::drawing::Direction3D& rDirection);
154cdf0e10cSrcweir 
155cdf0e10cSrcweir //-----------------------------------------------------------------------------
156cdf0e10cSrcweir /** Position3D - Position3D == Direction3D
157cdf0e10cSrcweir */
158cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Direction3D
159cdf0e10cSrcweir                 operator-( const com::sun::star::drawing::Position3D& rPos1
160cdf0e10cSrcweir                            , const com::sun::star::drawing::Position3D& rPos2);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //-----------------------------------------------------------------------------
163cdf0e10cSrcweir /** Position3D == Position3D ?
164cdf0e10cSrcweir */
165cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
166cdf0e10cSrcweir bool            operator==( const com::sun::star::drawing::Position3D& rPos1
167cdf0e10cSrcweir                            , const com::sun::star::drawing::Position3D& rPos2);
168cdf0e10cSrcweir 
169cdf0e10cSrcweir //-----------------------------------------------------------------------------
170cdf0e10cSrcweir /** awt::Rect --> awt::Point (2D)
171cdf0e10cSrcweir */
172cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Point ToPoint( const com::sun::star::awt::Rectangle& rRectangle );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir //-----------------------------------------------------------------------------
175cdf0e10cSrcweir /** awt::Rect --> awt::Size (2D)
176cdf0e10cSrcweir */
177cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Size ToSize( const com::sun::star::awt::Rectangle& rRectangle );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir //-----------------------------------------------------------------------------
180cdf0e10cSrcweir /** Position3D --> awt::Point (2D)
181cdf0e10cSrcweir */
182cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Point Position3DToAWTPoint( const com::sun::star::drawing::Position3D& rPos );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir //-----------------------------------------------------------------------------
185cdf0e10cSrcweir /** Direction3D --> awt::Size (2D)
186cdf0e10cSrcweir */
187cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Size Direction3DToAWTSize( const com::sun::star::drawing::Direction3D& rDirection );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir //-----------------------------------------------------------------------------
190cdf0e10cSrcweir /** B3DPoint -> Sequence<double>
191cdf0e10cSrcweir */
192cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::uno::Sequence< double > B3DPointToSequence( const ::basegfx::B3DPoint& rPoint );
193cdf0e10cSrcweir 
194cdf0e10cSrcweir //-----------------------------------------------------------------------------
195cdf0e10cSrcweir /** Sequence<double> -> drawing::Position3D
196cdf0e10cSrcweir */
197cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D
198cdf0e10cSrcweir                 SequenceToPosition3D( const com::sun::star::uno::Sequence< double >& rSeq );
199cdf0e10cSrcweir 
200cdf0e10cSrcweir //-----------------------------------------------------------------------------
201cdf0e10cSrcweir /** drawing::Position3D -> Sequence<double>
202cdf0e10cSrcweir */
203cdf0e10cSrcweir 
204cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::uno::Sequence< double >
205cdf0e10cSrcweir                 Position3DToSequence( const com::sun::star::drawing::Position3D& rPosition );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir //-----------------------------------------------------------------------------
208cdf0e10cSrcweir /** chart2::XDataSequence -> uno::Sequence< double >
209cdf0e10cSrcweir */
210cdf0e10cSrcweir 
211cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
212cdf0e10cSrcweir ::com::sun::star::uno::Sequence< double > DataSequenceToDoubleSequence(
213cdf0e10cSrcweir     const ::com::sun::star::uno::Reference<
214cdf0e10cSrcweir         ::com::sun::star::chart2::data::XDataSequence > & xDataSequence );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
217cdf0e10cSrcweir ::com::sun::star::uno::Sequence< rtl::OUString > DataSequenceToStringSequence(
218cdf0e10cSrcweir     const ::com::sun::star::uno::Reference<
219cdf0e10cSrcweir         ::com::sun::star::chart2::data::XDataSequence > & xDataSequence );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir //-----------------------------------------------------------------------------
222cdf0e10cSrcweir /** uno::Sequence< uno::Sequence< T > > -> uno::Sequence< T >
223cdf0e10cSrcweir  */
224cdf0e10cSrcweir template< typename T >
225cdf0e10cSrcweir ::com::sun::star::uno::Sequence< T >
FlattenSequence(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Sequence<T>> & aSeqSeq)226cdf0e10cSrcweir     FlattenSequence( const ::com::sun::star::uno::Sequence<
227cdf0e10cSrcweir                          ::com::sun::star::uno::Sequence< T > > & aSeqSeq )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     sal_Int32 nOuter, nInner, nCount = 0,
230cdf0e10cSrcweir         nResultSize = 0;
231cdf0e10cSrcweir     const sal_Int32 nOuterSize = aSeqSeq.getLength();
232cdf0e10cSrcweir     for( nOuter=0; nOuter<nOuterSize; ++nOuter )
233cdf0e10cSrcweir         nResultSize += aSeqSeq[nOuter].getLength();
234cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< T > aResult( nResultSize );
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     for( nOuter=0; nOuter<nOuterSize; ++nOuter )
237cdf0e10cSrcweir     {
238cdf0e10cSrcweir         const sal_Int32 nInnerSize = aSeqSeq[nOuter].getLength();
239cdf0e10cSrcweir         for( nInner=0; nInner<nInnerSize; ++nInner, ++nCount )
240cdf0e10cSrcweir             aResult[nCount] = aSeqSeq[nOuter][nInner];
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir     return aResult;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir template< typename T >
246cdf0e10cSrcweir     ::std::vector< T >
FlattenVector(const::std::vector<::std::vector<T>> & rVecVec)247cdf0e10cSrcweir     FlattenVector( const ::std::vector< ::std::vector< T > > & rVecVec )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir     typedef ::std::vector< T > tFlatVec;
250cdf0e10cSrcweir     typedef ::std::vector< tFlatVec > tVecVec;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     tFlatVec aResult;
253cdf0e10cSrcweir     typename tVecVec::const_iterator aOuterEnd( rVecVec.end());
254cdf0e10cSrcweir     for( typename tVecVec::const_iterator aOuterIt( rVecVec.begin()); aOuterIt != aOuterEnd; ++aOuterIt )
255cdf0e10cSrcweir         ::std::copy( aOuterIt->begin(), aOuterIt->end(), back_inserter( aResult ));
256cdf0e10cSrcweir     return aResult;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
260cdf0e10cSrcweir sal_Bool hasDoubleValue( const ::com::sun::star::uno::Any& rAny );
261cdf0e10cSrcweir 
262cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
263cdf0e10cSrcweir sal_Bool  hasLongOrShortValue( const ::com::sun::star::uno::Any& rAny );
264cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
265cdf0e10cSrcweir sal_Int16 getShortForLongAlso( const ::com::sun::star::uno::Any& rAny );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
268cdf0e10cSrcweir bool replaceParamterInString( rtl::OUString & rInOutResourceString,
269cdf0e10cSrcweir                             const rtl::OUString & rParamToReplace,
270cdf0e10cSrcweir                             const rtl::OUString & rReplaceWith );
271cdf0e10cSrcweir 
272cdf0e10cSrcweir //.............................................................................
273cdf0e10cSrcweir } //namespace chart
274cdf0e10cSrcweir //.............................................................................
275cdf0e10cSrcweir #endif
276