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