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 _CHART2_VIEW_SHAPEFACTORY_HXX
28 #define _CHART2_VIEW_SHAPEFACTORY_HXX
29 
30 #include "PropertyMapper.hxx"
31 #include "VLineProperties.hxx"
32 #include "BaseGFXHelper.hxx"
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/drawing/Direction3D.hpp>
35 #include <com/sun/star/drawing/HomogenMatrix.hpp>
36 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
37 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
38 #include <com/sun/star/drawing/Position3D.hpp>
39 #include <com/sun/star/drawing/XDrawPage.hpp>
40 #include <com/sun/star/drawing/XShapes.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/graphic/XGraphic.hpp>
43 
44 //.............................................................................
45 namespace chart
46 {
47 //.............................................................................
48 
49 class Stripe;
50 class ShapeFactory
51 {
52 public:
53     ShapeFactory(::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory> xFactory)
54         {m_xShapeFactory = xFactory;}
55 
56     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >
57         createGroup2D(
58             const ::com::sun::star::uno::Reference<
59                 ::com::sun::star::drawing::XShapes >& xTarget
60                 , ::rtl::OUString aName = ::rtl::OUString() );
61 
62 
63     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >
64         createGroup3D(
65             const ::com::sun::star::uno::Reference<
66                 ::com::sun::star::drawing::XShapes >& xTarget
67                 , ::rtl::OUString aName = ::rtl::OUString() );
68 
69     //------
70 
71     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
72             createCube(   const ::com::sun::star::uno::Reference<
73                                 ::com::sun::star::drawing::XShapes >& xTarget
74                         , const ::com::sun::star::drawing::Position3D& rPosition
75                         , const ::com::sun::star::drawing::Direction3D& rSize
76                         , sal_Int32 nRotateZAngleHundredthDegree
77                         , const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSourceProp
78                         , const tPropertyNameMap& rPropertyNameMap
79                         , bool bRounded = false);
80 
81     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
82         createCylinder(   const ::com::sun::star::uno::Reference<
83                                 ::com::sun::star::drawing::XShapes >& xTarget
84                         , const ::com::sun::star::drawing::Position3D& rPosition
85                         , const ::com::sun::star::drawing::Direction3D& rSize
86                         , sal_Int32 nRotateZAngleHundredthDegree );
87 
88     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
89         createPyramid(    const ::com::sun::star::uno::Reference<
90                                 ::com::sun::star::drawing::XShapes >& xTarget
91                         , const ::com::sun::star::drawing::Position3D& rPosition
92                         , const ::com::sun::star::drawing::Direction3D& rSize
93                         , double fTopHeight
94                         , bool bRotateZ
95                         , const ::com::sun::star::uno::Reference<
96                             ::com::sun::star::beans::XPropertySet >& xSourceProp
97                         , const tPropertyNameMap& rPropertyNameMap);
98 
99     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
100         createCone(       const ::com::sun::star::uno::Reference<
101                                 ::com::sun::star::drawing::XShapes >& xTarget
102                         , const ::com::sun::star::drawing::Position3D& rPosition
103                         , const ::com::sun::star::drawing::Direction3D& rSize
104                         , double fTopHeight, sal_Int32 nRotateZAngleHundredthDegree );
105 
106     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
107         createPieSegment2D( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
108                     , double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree
109                     , double fUnitCircleInnerRadius, double fUnitCircleOuterRadius
110                     , const ::com::sun::star::drawing::Direction3D& rOffset
111                     , const ::com::sun::star::drawing::HomogenMatrix& rUnitCircleToScene );
112 
113     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
114         createPieSegment( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
115                     , double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree
116                     , double fUnitCircleInnerRadius, double fUnitCircleOuterRadius
117                     , const ::com::sun::star::drawing::Direction3D& rOffset
118                     , const ::com::sun::star::drawing::HomogenMatrix& rUnitCircleToScene
119                     , double fDepth );
120 
121     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
122         createStripe( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
123                     , const Stripe& rStripe
124                     , const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSourceProp
125                     , const tPropertyNameMap& rPropertyNameMap
126                     , sal_Bool bDoubleSided = true
127                     , short nRotatedTexture = 0 //0 to 7 are the different possibilities
128                     , bool bFlatNormals=true );
129 
130     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
131         createArea3D( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
132                     , const ::com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygon
133                     , double fDepth);
134 
135     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
136         createArea2D( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
137                     , const ::com::sun::star::drawing::PolyPolygonShape3D& rPolyPolygon);
138 
139     static sal_Int32 getSymbolCount();
140 
141     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
142         createSymbol2D( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
143                     , const ::com::sun::star::drawing::Position3D& rPos
144                     , const ::com::sun::star::drawing::Direction3D& rSize
145                     , sal_Int32 nStandardSymbol
146                     , sal_Int32 nBorderColor=0
147                     , sal_Int32 nFillColor=0 );
148 
149     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
150         createGraphic2D( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
151                     , const ::com::sun::star::drawing::Position3D& rPos
152                     , const ::com::sun::star::drawing::Direction3D& rSize
153                     , const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >& xGraphic );
154 
155     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
156         createLine2D( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
157                     , const ::com::sun::star::drawing::PointSequenceSequence& rPoints
158                     , const VLineProperties* pLineProperties = NULL );
159 
160     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
161         createLine3D( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
162                     , const ::com::sun::star::drawing::PolyPolygonShape3D& rPoints
163                     , const VLineProperties& rLineProperties );
164 
165     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
166         createCircle2D( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
167                     , const ::com::sun::star::drawing::Position3D& rPos
168                     , const ::com::sun::star::drawing::Direction3D& rSize );
169 
170     //------------------- create 2D elements:
171 
172     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
173         createText( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget2D
174                     , const ::rtl::OUString& rText
175                     , const tNameSequence& rPropNames
176                     , const tAnySequence& rPropValues
177                     , const ::com::sun::star::uno::Any& rATransformation
178                      );
179 
180     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
181         createInvisibleRectangle(
182             const ::com::sun::star::uno::Reference<
183                 ::com::sun::star::drawing::XShapes >& xTarget
184                 , const ::com::sun::star::awt::Size& rSize );
185 
186     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >
187          getOrCreateChartRootShape( const ::com::sun::star::uno::Reference<
188             ::com::sun::star::drawing::XDrawPage>& xPage );
189 
190     static ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >
191          getChartRootShape( const ::com::sun::star::uno::Reference<
192             ::com::sun::star::drawing::XDrawPage>& xPage );
193 
194     //------
195     static void makeShapeInvisible( const ::com::sun::star::uno::Reference<
196                                      ::com::sun::star::drawing::XShape >& xShape );
197 
198      static void setShapeName( const ::com::sun::star::uno::Reference<
199                                      ::com::sun::star::drawing::XShape >& xShape
200                              , const rtl::OUString& rName );
201 
202      static rtl::OUString getShapeName( const ::com::sun::star::uno::Reference<
203                                      ::com::sun::star::drawing::XShape >& xShape );
204 
205      static ::com::sun::star::uno::Any makeTransformation( const ::com::sun::star::awt::Point& rScreenPosition2D, double fRotationAnglePi=0.0 );
206 
207      static rtl::OUString getStackedString( const rtl::OUString& rString, bool bStacked=true );
208 
209      static bool hasPolygonAnyLines( ::com::sun::star::drawing::PolyPolygonShape3D& rPoly );
210      static bool isPolygonEmptyOrSinglePoint( ::com::sun::star::drawing::PolyPolygonShape3D& rPoly );
211      static void closePolygon( ::com::sun::star::drawing::PolyPolygonShape3D& rPoly );
212 
213      static ::com::sun::star::awt::Size calculateNewSizeRespectingAspectRatio(
214            const ::com::sun::star::awt::Size& rTargetSize
215          , const ::com::sun::star::awt::Size& rSourceSizeWithCorrectAspectRatio );
216 
217      static ::com::sun::star::awt::Point calculateTopLeftPositionToCenterObject(
218            const ::com::sun::star::awt::Point& rTargetAreaPosition
219          , const ::com::sun::star::awt::Size& rTargetAreaSize
220          , const ::com::sun::star::awt::Size& rObjectSize );
221 
222      static ::basegfx::B2IRectangle getRectangleOfShape(
223          const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape );
224 
225      static ::com::sun::star::awt::Size getSizeAfterRotation(
226          const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape, double fRotationAngleDegree );
227 
228      static void removeSubShapes( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xShapes );
229 
230 private:
231     ShapeFactory();
232 
233     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
234         impl_createCube( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
235                     , const ::com::sun::star::drawing::Position3D& rPosition
236                     , const ::com::sun::star::drawing::Direction3D& rSize, sal_Int32 nRotateZAngleHundredthDegree
237                     , bool bRounded );
238 
239     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
240         impl_createConeOrCylinder( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget
241                     , const ::com::sun::star::drawing::Position3D& rPosition
242                     , const ::com::sun::star::drawing::Direction3D& rSize
243                     , double fTopHeight, sal_Int32 nRotateZAngleHundredthDegree
244                     , bool bCylinder = false);
245 
246     //member:
247     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>
248         m_xShapeFactory;
249 };
250 
251 //.............................................................................
252 } //namespace chart
253 //.............................................................................
254 #endif
255