1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 #ifndef __CHART_COMMON_CONVERTERS_HXX 28 #define __CHART_COMMON_CONVERTERS_HXX 29 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" 47 48 #include <vector> 49 #include <algorithm> 50 51 //............................................................................. 52 namespace chart 53 { 54 //............................................................................. 55 56 //----------------------------------------------------------------------------- 57 /** 58 diverse methods for class conversions; e.g. ::basegfx::B3DHomMatrix to HomogenMatrix 59 and operations e.g drawing::Position3D + drawing::Direction3D 60 */ 61 62 //----------------------------------------------------------------------------- 63 /** ::basegfx::B3DHomMatrix -> HomogenMatrix 64 */ 65 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::HomogenMatrix 66 B3DHomMatrixToHomogenMatrix( const ::basegfx::B3DHomMatrix& rM ); 67 68 //----------------------------------------------------------------------------- 69 /** HomogenMatrix -> ::basegfx::B3DHomMatrix 70 */ 71 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DHomMatrix HomogenMatrixToB3DHomMatrix( const com::sun::star::drawing::HomogenMatrix& rHM ); 72 73 //----------------------------------------------------------------------------- 74 /** ::basegfx::B3DHomMatrix -> B2DHomMatrix 75 */ 76 OOO_DLLPUBLIC_CHARTTOOLS 77 ::basegfx::B2DHomMatrix IgnoreZ( const ::basegfx::B3DHomMatrix& rM ); 78 79 //----------------------------------------------------------------------------- 80 /** B2DHomMatrix <-> HomogenMatrix3 81 */ 82 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::HomogenMatrix3 83 B2DHomMatrixToHomogenMatrix3( const ::basegfx::B2DHomMatrix& rM ); 84 85 //----------------------------------------------------------------------------- 86 /** Position3D -> B3DPoint 87 */ 88 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DPoint Position3DToB3DPoint( const com::sun::star::drawing::Position3D& rPosition ); 89 90 //----------------------------------------------------------------------------- 91 /** B3DVector -> Direction3D 92 */ 93 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Direction3D B3DVectorToDirection3D( const ::basegfx::B3DVector& rVector); 94 95 //----------------------------------------------------------------------------- 96 /** B3DPoint -> Position3D 97 */ 98 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D B3DPointToPosition3D( const ::basegfx::B3DPoint& rPoint); 99 100 //----------------------------------------------------------------------------- 101 /** Direction3D -> B3DVector 102 */ 103 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DVector Direction3DToB3DVector( const com::sun::star::drawing::Direction3D& rDirection); 104 105 //----------------------------------------------------------------------------- 106 /** PolyPolygonShape3D + drawing::Position3D -> PolyPolygonShape3D 107 */ 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 ); 112 113 //----------------------------------------------------------------------------- 114 /** get a single Point from a Polygon 115 */ 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 ); 119 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 126 */ 127 OOO_DLLPUBLIC_CHARTTOOLS 128 void appendPoly( com::sun::star::drawing::PolyPolygonShape3D& rRet 129 , const com::sun::star::drawing::PolyPolygonShape3D& rAdd ); 130 131 //----------------------------------------------------------------------------- 132 /** PolyPolygonBezierCoords -> PolyPolygonShape3D 133 */ 134 OOO_DLLPUBLIC_CHARTTOOLS 135 com::sun::star::drawing::PolyPolygonShape3D BezierToPoly( 136 const com::sun::star::drawing::PolyPolygonBezierCoords& rBezier ); 137 138 //----------------------------------------------------------------------------- 139 /** PolyPolygonShape3D -> drawing::PointSequenceSequence (2D) 140 */ 141 OOO_DLLPUBLIC_CHARTTOOLS 142 com::sun::star::drawing::PointSequenceSequence PolyToPointSequence( 143 const com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygon ); 144 145 //----------------------------------------------------------------------------- 146 /** drawing::PointSequenceSequence + drawing::PointSequenceSequence 147 */ 148 OOO_DLLPUBLIC_CHARTTOOLS 149 void appendPointSequence( com::sun::star::drawing::PointSequenceSequence& rTarget 150 , com::sun::star::drawing::PointSequenceSequence& rAdd ); 151 152 //----------------------------------------------------------------------------- 153 /** Position3D + Direction3D == Position3D 154 */ 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); 158 159 //----------------------------------------------------------------------------- 160 /** Position3D - Position3D == Direction3D 161 */ 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); 165 166 //----------------------------------------------------------------------------- 167 /** Position3D == Position3D ? 168 */ 169 OOO_DLLPUBLIC_CHARTTOOLS 170 bool operator==( const com::sun::star::drawing::Position3D& rPos1 171 , const com::sun::star::drawing::Position3D& rPos2); 172 173 //----------------------------------------------------------------------------- 174 /** awt::Rect --> awt::Point (2D) 175 */ 176 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Point ToPoint( const com::sun::star::awt::Rectangle& rRectangle ); 177 178 //----------------------------------------------------------------------------- 179 /** awt::Rect --> awt::Size (2D) 180 */ 181 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Size ToSize( const com::sun::star::awt::Rectangle& rRectangle ); 182 183 //----------------------------------------------------------------------------- 184 /** Position3D --> awt::Point (2D) 185 */ 186 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Point Position3DToAWTPoint( const com::sun::star::drawing::Position3D& rPos ); 187 188 //----------------------------------------------------------------------------- 189 /** Direction3D --> awt::Size (2D) 190 */ 191 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::awt::Size Direction3DToAWTSize( const com::sun::star::drawing::Direction3D& rDirection ); 192 193 //----------------------------------------------------------------------------- 194 /** B3DPoint -> Sequence<double> 195 */ 196 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::uno::Sequence< double > B3DPointToSequence( const ::basegfx::B3DPoint& rPoint ); 197 198 //----------------------------------------------------------------------------- 199 /** Sequence<double> -> drawing::Position3D 200 */ 201 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::drawing::Position3D 202 SequenceToPosition3D( const com::sun::star::uno::Sequence< double >& rSeq ); 203 204 //----------------------------------------------------------------------------- 205 /** drawing::Position3D -> Sequence<double> 206 */ 207 208 OOO_DLLPUBLIC_CHARTTOOLS com::sun::star::uno::Sequence< double > 209 Position3DToSequence( const com::sun::star::drawing::Position3D& rPosition ); 210 211 //----------------------------------------------------------------------------- 212 /** chart2::XDataSequence -> uno::Sequence< double > 213 */ 214 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 ); 219 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 ); 224 225 //----------------------------------------------------------------------------- 226 /** uno::Sequence< uno::Sequence< T > > -> uno::Sequence< T > 227 */ 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 ) 232 { 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 ); 239 240 for( nOuter=0; nOuter<nOuterSize; ++nOuter ) 241 { 242 const sal_Int32 nInnerSize = aSeqSeq[nOuter].getLength(); 243 for( nInner=0; nInner<nInnerSize; ++nInner, ++nCount ) 244 aResult[nCount] = aSeqSeq[nOuter][nInner]; 245 } 246 return aResult; 247 } 248 249 template< typename T > 250 ::std::vector< T > 251 FlattenVector( const ::std::vector< ::std::vector< T > > & rVecVec ) 252 { 253 typedef ::std::vector< T > tFlatVec; 254 typedef ::std::vector< tFlatVec > tVecVec; 255 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; 261 } 262 263 OOO_DLLPUBLIC_CHARTTOOLS 264 sal_Bool hasDoubleValue( const ::com::sun::star::uno::Any& rAny ); 265 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 ); 270 271 OOO_DLLPUBLIC_CHARTTOOLS 272 bool replaceParamterInString( rtl::OUString & rInOutResourceString, 273 const rtl::OUString & rParamToReplace, 274 const rtl::OUString & rReplaceWith ); 275 276 //............................................................................. 277 } //namespace chart 278 //............................................................................. 279 #endif 280