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_VIEW_INC_SHAPEFACTORY_HXX
20 #define INCLUDED_CHART2_SOURCE_VIEW_INC_SHAPEFACTORY_HXX
21 
22 #include "PropertyMapper.hxx"
23 #include <basegfx/range/b2irectangle.hxx>
24 #include <com/sun/star/awt/Size.hpp>
25 #include <com/sun/star/awt/Point.hpp>
26 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
27 
28 #include <rtl/ustring.hxx>
29 
30 namespace chart { struct VLineProperties; }
31 namespace com { namespace sun { namespace star { namespace beans { class XPropertySet; } } } }
32 namespace com { namespace sun { namespace star { namespace chart2 { class XFormattedString; } } } }
33 namespace com { namespace sun { namespace star { namespace drawing { class XDrawPage; } } } }
34 namespace com { namespace sun { namespace star { namespace drawing { class XShape; } } } }
35 namespace com { namespace sun { namespace star { namespace drawing { class XShapes; } } } }
36 namespace com { namespace sun { namespace star { namespace drawing { struct HomogenMatrix; } } } }
37 namespace com { namespace sun { namespace star { namespace drawing { struct PolyPolygonShape3D; } } } }
38 namespace com { namespace sun { namespace star { namespace drawing { struct Position3D; } } } }
39 namespace com { namespace sun { namespace star { namespace graphic { class XGraphic; } } } }
40 namespace com { namespace sun { namespace star { namespace lang { class XMultiServiceFactory; } } } }
41 namespace com { namespace sun { namespace star { namespace drawing { struct Direction3D; } } } }
42 
43 
44 namespace chart
45 {
46 class Stripe;
47 
48 // Be careful here not to clash with the SYMBOL_FOO #defines in
49 // <vcl/vclenum.hxx>
50 enum SymbolEnum { Symbol_Square=0
51                  , Symbol_Diamond
52                  , Symbol_DownArrow
53                  , Symbol_UpArrow
54                  , Symbol_RightArrow
55                  , Symbol_LeftArrow
56                  , Symbol_Bowtie
57                  , Symbol_Sandglass
58                  , Symbol_Circle
59                  , Symbol_Star
60                  , Symbol_X
61                  , Symbol_Plus
62                  , Symbol_Asterisk
63                  , Symbol_HorizontalBar
64                  , Symbol_VerticalBar
65                  , Symbol_COUNT
66 };
67 
68 
69 class ShapeFactory
70 {
71     css::uno::Reference< css::lang::XMultiServiceFactory>   m_xShapeFactory;
72 
ShapeFactory(css::uno::Reference<css::lang::XMultiServiceFactory> const & xFactory)73     ShapeFactory(css::uno::Reference< css::lang::XMultiServiceFactory> const & xFactory)
74         {m_xShapeFactory = xFactory;}
75 
76 public:
77     enum class StackPosition { Top, Bottom };
78 
79     static ShapeFactory* getOrCreateShapeFactory(const css::uno::Reference< css::lang::XMultiServiceFactory>& xFactory);
80 
81     ShapeFactory() = delete;
82     css::uno::Reference< css::drawing::XShapes >
83         createGroup2D(
84             const css::uno::Reference< css::drawing::XShapes >& xTarget
85           , const OUString& aName = OUString() );
86 
87     css::uno::Reference< css::drawing::XShapes >
88         createGroup3D(
89             const css::uno::Reference< css::drawing::XShapes >& xTarget
90           , const OUString& aName = OUString() );
91 
92     css::uno::Reference< css::drawing::XShape >
93             createCube(   const css::uno::Reference< css::drawing::XShapes >& xTarget
94                         , const css::drawing::Position3D& rPosition
95                         , const css::drawing::Direction3D& rSize
96                         , sal_Int32 nRotateZAngleHundredthDegree
97                         , const css::uno::Reference< css::beans::XPropertySet >& xSourceProp
98                         , const tPropertyNameMap& rPropertyNameMap
99                         , bool bRounded = false);
100 
101     css::uno::Reference< css::drawing::XShape >
102         createCylinder(   const css::uno::Reference< css::drawing::XShapes >& xTarget
103                         , const css::drawing::Position3D& rPosition
104                         , const css::drawing::Direction3D& rSize
105                         , sal_Int32 nRotateZAngleHundredthDegree );
106 
107     css::uno::Reference< css::drawing::XShape >
108         createPyramid(    const css::uno::Reference< css::drawing::XShapes >& xTarget
109                         , const css::drawing::Position3D& rPosition
110                         , const css::drawing::Direction3D& rSize
111                         , double fTopHeight
112                         , bool bRotateZ
113                         , const css::uno::Reference< css::beans::XPropertySet >& xSourceProp
114                         , const tPropertyNameMap& rPropertyNameMap);
115 
116     css::uno::Reference< css::drawing::XShape >
117         createCone(       const css::uno::Reference< css::drawing::XShapes >& xTarget
118                         , const css::drawing::Position3D& rPosition
119                         , const css::drawing::Direction3D& rSize
120                         , double fTopHeight, sal_Int32 nRotateZAngleHundredthDegree );
121 
122     css::uno::Reference< css::drawing::XShape >
123         createPieSegment2D( const css::uno::Reference< css::drawing::XShapes >& xTarget
124                     , double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree
125                     , double fUnitCircleInnerRadius, double fUnitCircleOuterRadius
126                     , const css::drawing::Direction3D& rOffset
127                     , const css::drawing::HomogenMatrix& rUnitCircleToScene );
128 
129     css::uno::Reference< css::drawing::XShape >
130         createPieSegment( const css::uno::Reference< css::drawing::XShapes >& xTarget
131                     , double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree
132                     , double fUnitCircleInnerRadius, double fUnitCircleOuterRadius
133                     , const css::drawing::Direction3D& rOffset
134                     , const css::drawing::HomogenMatrix& rUnitCircleToScene
135                     , double fDepth );
136 
137     css::uno::Reference< css::drawing::XShape >
138         createStripe( const css::uno::Reference< css::drawing::XShapes >& xTarget
139                     , const Stripe& rStripe
140                     , const css::uno::Reference< css::beans::XPropertySet >& xSourceProp
141                     , const tPropertyNameMap& rPropertyNameMap
142                     , bool bDoubleSided
143                     , short nRotatedTexture = 0 //0 to 7 are the different possibilities
144                     , bool bFlatNormals=true );
145 
146     css::uno::Reference< css::drawing::XShape >
147         createArea3D( const css::uno::Reference< css::drawing::XShapes >& xTarget
148                     , const css::drawing::PolyPolygonShape3D& rPolyPolygon
149                     , double fDepth);
150 
151     css::uno::Reference< css::drawing::XShape >
152         createArea2D( const css::uno::Reference< css::drawing::XShapes >& xTarget
153                     , const css::drawing::PolyPolygonShape3D& rPolyPolygon);
154 
155     css::uno::Reference< css::drawing::XShape >
156         createSymbol2D( const css::uno::Reference< css::drawing::XShapes >& xTarget
157                     , const css::drawing::Position3D& rPos
158                     , const css::drawing::Direction3D& rSize
159                     , sal_Int32 nStandardSymbol
160                     , sal_Int32 nBorderColor
161                     , sal_Int32 nFillColor );
162 
163     css::uno::Reference< css::drawing::XShape >
164         createGraphic2D( const css::uno::Reference< css::drawing::XShapes >& xTarget
165                     , const css::drawing::Position3D& rPos
166                     , const css::drawing::Direction3D& rSize
167                     , const css::uno::Reference< css::graphic::XGraphic >& xGraphic );
168 
169     css::uno::Reference< css::drawing::XShape >
170         createLine2D( const css::uno::Reference< css::drawing::XShapes >& xTarget
171                     , const css::drawing::PointSequenceSequence& rPoints
172                     , const VLineProperties* pLineProperties = nullptr );
173 
174     css::uno::Reference< css::drawing::XShape >
175         createLine ( const css::uno::Reference< css::drawing::XShapes >& xTarget,
176                 const css::awt::Size& rSize, const css::awt::Point& rPosition );
177 
178     css::uno::Reference< css::drawing::XShape >
179         createLine3D( const css::uno::Reference< css::drawing::XShapes >& xTarget
180                     , const css::drawing::PolyPolygonShape3D& rPoints
181                     , const VLineProperties& rLineProperties );
182 
183     css::uno::Reference< css::drawing::XShape >
184         createCircle2D( const css::uno::Reference< css::drawing::XShapes >& xTarget
185                     , const css::drawing::Position3D& rPos
186                     , const css::drawing::Direction3D& rSize );
187 
188     css::uno::Reference< css::drawing::XShape >
189         createCircle( const css::uno::Reference< css::drawing::XShapes >& xTarget
190                     , const css::awt::Size& rSize
191                     , const css::awt::Point& rPosition );
192 
193     css::uno::Reference< css::drawing::XShape >
194         createText( const css::uno::Reference< css::drawing::XShapes >& xTarget2D
195                     , const OUString& rText
196                     , const tNameSequence& rPropNames
197                     , const tAnySequence& rPropValues
198                     , const css::uno::Any& rATransformation
199                      );
200 
201     /** This method creates a text shape made up by a set of paragraphs.
202      *  For each paragraph the related text style is passed to the method.
203      *
204      *  @param xTarget
205      *      where to append the new created text shape.
206      *
207      *  @param rTextParagraphs
208      *      the set of paragraphs which made up the text shape.
209      *
210      *  @param rParaPropNames
211      *      a collection of lists of text property names:
212      *      there must be a list of text property names for each paragraph.
213      *
214      *  @param rParaPropValues
215      *      a collection of lists of text property values:
216      *      there must be a list of text property values for each paragraph.
217      *
218      *  @param rPropNames
219      *      a list of text property names to be applied to the whole text shape.
220      *
221      *  @param rPropValues
222      *      a list of text property values to be applied to the whole text shape.
223      *
224      *  @param rATransformation
225      *      a transformation to be applied to the text shape as final step.
226      *
227      */
228     css::uno::Reference< css::drawing::XShape >
229         createText( const css::uno::Reference< css::drawing::XShapes >& xTarget
230                     , const css::uno::Sequence< OUString >& rTextParagraphs
231                     , const css::uno::Sequence< tNameSequence >& rParaPropNames
232                     , const css::uno::Sequence< tAnySequence >& rParaPropValues
233                     , const tNameSequence& rPropNames
234                     , const tAnySequence& rPropValues
235                     , const css::uno::Any& rATransformation );
236 
237     css::uno::Reference< css::drawing::XShape >
238         createText(const css::uno::Reference< css::drawing::XShapes >& xTarget
239             , css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > >& xFormattedString
240             , const tNameSequence& rPropNames
241             , const tAnySequence& rPropValues
242             , const css::uno::Any& rATransformation);
243 
244     css::uno::Reference< css::drawing::XShape >
245         createText( const css::uno::Reference< css::drawing::XShapes >& xTarget2D,
246                 const css::awt::Size& rSize,
247                 const css::awt::Point& rPosition,
248                 css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > >& xFormattedString,
249                 const css::uno::Reference< css::beans::XPropertySet > & xTextProperties,
250                 double nRotation, const OUString& aName );
251 
252     css::uno::Reference< css::drawing::XShape >
253         createInvisibleRectangle(
254             const css::uno::Reference< css::drawing::XShapes >& xTarget
255           , const css::awt::Size& rSize );
256 
257     css::uno::Reference< css::drawing::XShape >
258         createRectangle(
259             const css::uno::Reference< css::drawing::XShapes >& xTarget,
260             const css::awt::Size& rSize,
261             const css::awt::Point& rPosition,
262             const tNameSequence& rPropNames,
263             const tAnySequence& rPropValues,
264             StackPosition ePos = StackPosition::Top );
265 
266     css::uno::Reference< css::drawing::XShape >
267         createRectangle(
268             const css::uno::Reference< css::drawing::XShapes >& xTarget );
269 
270     css::uno::Reference< css::drawing::XShapes >
271          getOrCreateChartRootShape( const css::uno::Reference<
272             css::drawing::XDrawPage>& xPage );
273 
274     static void setPageSize(const css::uno::Reference<css::drawing::XShapes>& xChartShapes,
275                      const css::awt::Size& rSize);
276 
277     static css::uno::Reference< css::drawing::XShapes >
278          getChartRootShape( const css::uno::Reference< css::drawing::XDrawPage>& xPage );
279 
280     static void makeShapeInvisible( const css::uno::Reference< css::drawing::XShape >& xShape );
281 
282     static void setShapeName( const css::uno::Reference< css::drawing::XShape >& xShape
283             , const OUString& rName );
284 
285     static OUString getShapeName( const css::uno::Reference< css::drawing::XShape >& xShape );
286 
287     static css::uno::Any makeTransformation( const css::awt::Point& rScreenPosition2D, double fRotationAnglePi=0.0 );
288 
289     static OUString getStackedString( const OUString& rString, bool bStacked );
290 
291     static bool hasPolygonAnyLines( css::drawing::PolyPolygonShape3D& rPoly );
292     static bool isPolygonEmptyOrSinglePoint( css::drawing::PolyPolygonShape3D& rPoly );
293     static void closePolygon( css::drawing::PolyPolygonShape3D& rPoly );
294 
295     static css::awt::Size calculateNewSizeRespectingAspectRatio(
296             const css::awt::Size& rTargetSize
297             , const css::awt::Size& rSourceSizeWithCorrectAspectRatio );
298 
299     static css::awt::Point calculateTopLeftPositionToCenterObject(
300             const css::awt::Point& rTargetAreaPosition
301             , const css::awt::Size& rTargetAreaSize
302             , const css::awt::Size& rObjectSize );
303 
304     static ::basegfx::B2IRectangle getRectangleOfShape(
305             const css::uno::Reference< css::drawing::XShape >& xShape );
306 
307     static css::awt::Size getSizeAfterRotation(
308             const css::uno::Reference< css::drawing::XShape >& xShape, double fRotationAngleDegree );
309 
310     static void removeSubShapes( const css::uno::Reference< css::drawing::XShapes >& xShapes );
311 
getSymbolCount()312     static sal_Int32 getSymbolCount() { return Symbol_COUNT; }
313 
314 private:
315     css::uno::Reference< css::drawing::XShape >
316         impl_createCube( const css::uno::Reference< css::drawing::XShapes >& xTarget
317                     , const css::drawing::Position3D& rPosition
318                     , const css::drawing::Direction3D& rSize, sal_Int32 nRotateZAngleHundredthDegree
319                     , bool bRounded );
320 
321     css::uno::Reference< css::drawing::XShape >
322         impl_createConeOrCylinder( const css::uno::Reference< css::drawing::XShapes >& xTarget
323                     , const css::drawing::Position3D& rPosition
324                     , const css::drawing::Direction3D& rSize
325                     , double fTopHeight, sal_Int32 nRotateZAngleHundredthDegree
326                     , bool bCylinder);
327 };
328 
329 } //namespace chart
330 #endif
331 
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
333