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