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