1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/unoshape.hxx>
21 #include <OpenglShapeFactory.hxx>
22 #include "DummyXShape.hxx"
23 #include <ViewDefines.hxx>
25 #include <CommonConverters.hxx>
26 #include <PropertyMapper.hxx>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/drawing/CircleKind.hpp>
29 #include <com/sun/star/drawing/DoubleSequence.hpp>
30 #include <com/sun/star/drawing/FlagSequence.hpp>
31 #include <com/sun/star/drawing/FillStyle.hpp>
32 #include <com/sun/star/drawing/LineStyle.hpp>
33 #include <com/sun/star/drawing/NormalsKind.hpp>
34 #include <com/sun/star/drawing/PointSequence.hpp>
35 #include <com/sun/star/drawing/PolygonKind.hpp>
36 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
37 #include <com/sun/star/drawing/ProjectionMode.hpp>
38 #include <com/sun/star/drawing/ShadeMode.hpp>
39 #include <com/sun/star/drawing/TextFitToSizeType.hpp>
40 #include <com/sun/star/drawing/TextureProjectionMode.hpp>
41 #include <com/sun/star/text/XText.hpp>
42 #include <com/sun/star/uno/Sequence.hxx>
43 #include <com/sun/star/uno/Any.hxx>
45 #include <editeng/unoprnms.hxx>
46 #include <rtl/math.hxx>
47 #include <svx/svdocirc.hxx>
48 #include <svx/svdopath.hxx>
49 #include <vcl/openglwin.hxx>
51 #include <basegfx/point/b2dpoint.hxx>
52 #include <basegfx/matrix/b3dhommatrix.hxx>
54 #include <RelativeSizeHelper.hxx>
56 using namespace ::com::sun::star
;
62 SAL_DLLPUBLIC_EXPORT
opengl::OpenglShapeFactory
* getOpenglShapeFactory()
63 { return new opengl::OpenglShapeFactory
;}
66 using dummy::DummyCylinder
;
67 using dummy::DummyRectangle
;
68 using dummy::DummyPyramid
;
69 using dummy::DummyCone
;
75 uno::Reference
< drawing::XShapes
> getChartShape(
76 const uno::Reference
< drawing::XDrawPage
>& xDrawPage
)
78 uno::Reference
< drawing::XShapes
> xRet
;
79 uno::Reference
< drawing::XShapes
> xShapes( xDrawPage
, uno::UNO_QUERY
);
82 sal_Int32 nCount
= xShapes
->getCount();
83 uno::Reference
< drawing::XShape
> xShape
;
84 for( sal_Int32 nN
= nCount
; nN
--; )
86 if( xShapes
->getByIndex( nN
) >>= xShape
)
91 uno::Reference
< beans::XPropertySet
> xProp( xShape
, uno::UNO_QUERY
);
92 xProp
->getPropertyValue( UNO_NAME_MISC_OBJ_NAME
) >>= aRet
;
93 if( aRet
== "com.sun.star.chart2.shapes" )
95 xRet
= dynamic_cast<SvxDummyShapeContainer
&>(*xShape
.get()).getWrappedShape();
106 uno::Reference
< drawing::XShapes
> OpenglShapeFactory::getOrCreateChartRootShape(
107 const uno::Reference
< drawing::XDrawPage
>& xDrawPage
)
109 uno::Reference
< drawing::XShapes
> xRet( getChartShape( xDrawPage
) );
112 //create the root shape
113 SAL_WARN("chart2.opengl", "getOrCreateChartRootShape");
115 dummy::DummyChart
*pChart
= new dummy::DummyChart();
116 SvxDummyShapeContainer
* pContainer
= new SvxDummyShapeContainer(pChart
);
117 pContainer
->setSize(awt::Size(0,0));
119 xDrawPage
->add(pContainer
);
124 void OpenglShapeFactory::setPageSize( uno::Reference
< drawing::XShapes
> xChartShapes
, const awt::Size
& rSize
)
126 uno::Reference
< drawing::XShape
> xShape(xChartShapes
, uno::UNO_QUERY_THROW
);
127 xShape
->setSize(rSize
);
130 // methods for 3D shape creation
132 uno::Reference
<drawing::XShape
>
133 OpenglShapeFactory::createCube(
134 const uno::Reference
<drawing::XShapes
>& xTarget
135 , const drawing::Position3D
& rPosition
, const drawing::Direction3D
& rSize
137 , const uno::Reference
< beans::XPropertySet
>& xSourceProp
138 , const tPropertyNameMap
& rPropertyNameMap
141 dummy::DummyCube
* pCube
= new dummy::DummyCube(rPosition
, rSize
,
148 uno::Reference
<drawing::XShape
>
149 OpenglShapeFactory::createCylinder(
150 const uno::Reference
<drawing::XShapes
>& xTarget
151 , const drawing::Position3D
& rPosition
, const drawing::Direction3D
& rSize
154 dummy::DummyCylinder
* pCylinder
= new dummy::DummyCylinder( rPosition
, rSize
);
155 xTarget
->add(pCylinder
);
159 uno::Reference
<drawing::XShape
>
160 OpenglShapeFactory::createPyramid(
161 const uno::Reference
<drawing::XShapes
>& xTarget
162 , const drawing::Position3D
& rPosition
, const drawing::Direction3D
& rSize
164 , const uno::Reference
< beans::XPropertySet
>& xSourceProp
165 , const tPropertyNameMap
& rPropertyNameMap
)
167 dummy::DummyPyramid
* pPyramid
= new dummy::DummyPyramid(rPosition
, rSize
,
168 xSourceProp
, rPropertyNameMap
);
169 xTarget
->add(pPyramid
);
173 uno::Reference
<drawing::XShape
>
174 OpenglShapeFactory::createCone(
175 const uno::Reference
<drawing::XShapes
>& xTarget
176 , const drawing::Position3D
& rPosition
, const drawing::Direction3D
& rSize
177 , double, sal_Int32
)
179 dummy::DummyCone
* pCone
= new dummy::DummyCone(rPosition
, rSize
);
184 uno::Reference
< drawing::XShape
>
185 OpenglShapeFactory::createPieSegment2D(
186 const uno::Reference
< drawing::XShapes
>& xTarget
187 , double fUnitCircleStartAngleDegree
, double fUnitCircleWidthAngleDegree
188 , double fUnitCircleInnerRadius
, double fUnitCircleOuterRadius
189 , const drawing::Direction3D
& rOffset
190 , const drawing::HomogenMatrix
& rUnitCircleToScene
)
192 dummy::DummyPieSegment2D
* pSegment
= new dummy::DummyPieSegment2D(fUnitCircleStartAngleDegree
,
193 fUnitCircleWidthAngleDegree
, fUnitCircleInnerRadius
, fUnitCircleOuterRadius
,
194 rOffset
, rUnitCircleToScene
);
195 xTarget
->add(pSegment
);
199 uno::Reference
< drawing::XShape
>
200 OpenglShapeFactory::createPieSegment(
201 const uno::Reference
< drawing::XShapes
>& xTarget
204 , const drawing::Direction3D
&
205 , const drawing::HomogenMatrix
&
208 dummy::DummyPieSegment
* pSegment
= new dummy::DummyPieSegment
;
210 xTarget
->add(pSegment
);
214 uno::Reference
< drawing::XShape
>
215 OpenglShapeFactory::createStripe( const uno::Reference
< drawing::XShapes
>& xTarget
217 , const uno::Reference
< beans::XPropertySet
>& xSourceProp
218 , const tPropertyNameMap
& rPropertyNameMap
223 dummy::DummyStripe
* pStripe
= new dummy::DummyStripe(
224 xSourceProp
, rPropertyNameMap
);
225 xTarget
->add(pStripe
);
229 uno::Reference
< drawing::XShape
>
230 OpenglShapeFactory::createArea3D( const uno::Reference
< drawing::XShapes
>& xTarget
231 , const drawing::PolyPolygonShape3D
&
234 dummy::DummyArea3D
* pArea
= new dummy::DummyArea3D
;
239 uno::Reference
< drawing::XShape
>
240 OpenglShapeFactory::createArea2D( const uno::Reference
< drawing::XShapes
>& xTarget
241 , const drawing::PolyPolygonShape3D
& rPolyPolygon
)
243 dummy::DummyArea2D
* pArea
= new dummy::DummyArea2D(PolyToPointSequence(rPolyPolygon
));
248 uno::Reference
< drawing::XShape
>
249 OpenglShapeFactory::createSymbol2D(
250 const uno::Reference
< drawing::XShapes
>& xTarget
251 , const drawing::Position3D
& rPosition
252 , const drawing::Direction3D
& rSize
253 , sal_Int32 nStandardSymbol
255 , sal_Int32 nFillColor
)
257 dummy::DummySymbol2D
* pSymbol
= new dummy::DummySymbol2D(rPosition
, rSize
,
258 nStandardSymbol
, nFillColor
);
259 xTarget
->add(pSymbol
);
263 uno::Reference
< drawing::XShape
>
264 OpenglShapeFactory::createGraphic2D(
265 const uno::Reference
< drawing::XShapes
>& xTarget
266 , const drawing::Position3D
& rPosition
267 , const drawing::Direction3D
& rSize
268 , const uno::Reference
< graphic::XGraphic
>& )
270 dummy::DummyGraphic2D
* pGraphic
= new dummy::DummyGraphic2D(rPosition
, rSize
);
271 xTarget
->add(pGraphic
);
275 uno::Reference
< drawing::XShapes
>
276 OpenglShapeFactory::createGroup2D( const uno::Reference
< drawing::XShapes
>& xTarget
277 , const OUString
& aName
)
279 dummy::DummyGroup2D
* pNewShape
= new dummy::DummyGroup2D(aName
);
280 xTarget
->add(pNewShape
);
284 uno::Reference
< drawing::XShapes
>
285 OpenglShapeFactory::createGroup3D( const uno::Reference
< drawing::XShapes
>& xTarget
286 , const OUString
& aName
)
288 dummy::DummyGroup3D
* pNewShape
= new dummy::DummyGroup3D(aName
);
289 xTarget
->add(pNewShape
);
293 uno::Reference
< drawing::XShape
>
294 OpenglShapeFactory::createCircle2D( const uno::Reference
< drawing::XShapes
>& xTarget
295 , const drawing::Position3D
& rPosition
296 , const drawing::Direction3D
& rSize
)
298 drawing::Position3D
aCenterPosition(
299 rPosition
.PositionX
- (rSize
.DirectionX
/ 2.0),
300 rPosition
.PositionY
- (rSize
.DirectionY
/ 2.0),
301 rPosition
.PositionZ
);
302 dummy::DummyCircle
* pCircle
= new dummy::DummyCircle(Position3DToAWTPoint( aCenterPosition
),
303 Direction3DToAWTSize( rSize
));
304 xTarget
->add(pCircle
);
308 uno::Reference
< drawing::XShape
>
309 OpenglShapeFactory::createCircle( const uno::Reference
< drawing::XShapes
>& xTarget
310 , const awt::Size
& rSize
311 , const awt::Point
& rPosition
)
313 dummy::DummyCircle
* pCircle
= new dummy::DummyCircle(rPosition
, rSize
);
314 xTarget
->add(pCircle
);
318 uno::Reference
< drawing::XShape
>
319 OpenglShapeFactory::createLine3D( const uno::Reference
< drawing::XShapes
>& xTarget
320 , const drawing::PolyPolygonShape3D
&
321 , const VLineProperties
& rLineProperties
)
323 dummy::DummyLine3D
* pLine
= new dummy::DummyLine3D(rLineProperties
);
328 uno::Reference
< drawing::XShape
>
329 OpenglShapeFactory::createLine2D( const uno::Reference
< drawing::XShapes
>& xTarget
330 , const drawing::PointSequenceSequence
& rPoints
331 , const VLineProperties
* pLineProperties
)
333 dummy::DummyLine2D
* pLine
= new dummy::DummyLine2D(rPoints
, pLineProperties
);
339 uno::Reference
< drawing::XShape
>
340 OpenglShapeFactory::createLine ( const uno::Reference
< drawing::XShapes
>& xTarget
,
341 const awt::Size
& rSize
, const awt::Point
& rPosition
)
343 dummy::DummyLine2D
* pLine
= new dummy::DummyLine2D(rSize
, rPosition
);
348 uno::Reference
< drawing::XShape
> OpenglShapeFactory::createInvisibleRectangle(
349 const uno::Reference
< drawing::XShapes
>& xTarget
350 , const awt::Size
& rSize
)
352 dummy::DummyRectangle
* pRectangle
= new dummy::DummyRectangle(rSize
);
353 pRectangle
->setPropertyValue("Invisible", uno::Any(true));
354 xTarget
->add(pRectangle
);
358 uno::Reference
< drawing::XShape
> OpenglShapeFactory::createRectangle(
359 const uno::Reference
< drawing::XShapes
>& xTarget
,
360 const awt::Size
& rSize
,
361 const awt::Point
& rPosition
,
362 const tNameSequence
& rPropNames
,
363 const tAnySequence
& rPropValues
,
364 StackPosition
/*ePos*/ )
366 dummy::DummyRectangle
* pRectangle
= new dummy::DummyRectangle(rSize
, rPosition
,
367 rPropNames
, rPropValues
);
369 // TODO : Honor stack position.
370 xTarget
->add(pRectangle
);
374 uno::Reference
< drawing::XShape
>
375 OpenglShapeFactory::createRectangle(
376 const uno::Reference
<
377 drawing::XShapes
>& xTarget
)
379 dummy::DummyRectangle
* pRectangle
= new dummy::DummyRectangle();
380 xTarget
->add(pRectangle
);
384 uno::Reference
< drawing::XShape
>
385 OpenglShapeFactory::createText( const uno::Reference
< drawing::XShapes
>& xTarget
386 , const OUString
& rText
387 , const tNameSequence
& rPropNames
388 , const tAnySequence
& rPropValues
389 , const uno::Any
& rATransformation
)
391 dummy::DummyText
* pText
= new dummy::DummyText( rText
, rPropNames
, rPropValues
,
392 rATransformation
, xTarget
, 0 );
396 uno::Reference
< drawing::XShape
>
397 OpenglShapeFactory::createText( const uno::Reference
< drawing::XShapes
>& xTarget
398 , const uno::Sequence
< OUString
>& rTextParagraphs
399 , const uno::Sequence
< tNameSequence
>& /*rParaPropNames*/
400 , const uno::Sequence
< tAnySequence
>& /*rParaPropValues*/
401 , const tNameSequence
& rPropNames
402 , const tAnySequence
& rPropValues
403 , const uno::Any
& rATransformation
)
405 dummy::DummyText
* pText
= new dummy::DummyText( rTextParagraphs
[0], rPropNames
, rPropValues
,
406 rATransformation
, xTarget
, 0 );
410 uno::Reference
< drawing::XShape
>
411 OpenglShapeFactory::createText( const uno::Reference
< drawing::XShapes
>& xTarget
412 , uno::Sequence
< uno::Reference
< chart2::XFormattedString
> >& rFormattedString
413 , const tNameSequence
& rPropNames
414 , const tAnySequence
& rPropValues
415 , const uno::Any
& rATransformation
)
417 dummy::DummyText
* pText
= new dummy::DummyText( rFormattedString
[0]->getString(), rPropNames
, rPropValues
,
418 rATransformation
, xTarget
, 0 );
422 uno::Reference
< drawing::XShape
>
423 OpenglShapeFactory::createText( const uno::Reference
< drawing::XShapes
>& xTarget
,
424 const awt::Size
& , const awt::Point
& rPos
,
425 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> >& rFormattedString
,
426 const uno::Reference
< beans::XPropertySet
> & xTextProperties
,
427 double nRotation
, const OUString
& rName
)
429 tPropertyNameValueMap aValueMap
;
430 //fill line-, fill- and paragraph-properties into the ValueMap
432 tPropertyNameMap aNameMap
= PropertyMapper::getPropertyNameMapForParagraphProperties();
433 auto const & add
= PropertyMapper::getPropertyNameMapForFillAndLineProperties();
434 aNameMap
.insert(add
.begin(), add
.end());
436 PropertyMapper::getValueMap( aValueMap
, aNameMap
, xTextProperties
);
439 //fill some more shape properties into the ValueMap
440 aValueMap
.insert( { "TextHorizontalAdjust", uno::Any(drawing::TextHorizontalAdjust_CENTER
) } );
441 aValueMap
.insert( { "TextVerticalAdjust", uno::Any(drawing::TextVerticalAdjust_CENTER
) } );
442 aValueMap
.insert( { "TextAutoGrowHeight", uno::Any(true) } );
443 aValueMap
.insert( { "TextAutoGrowWidth", uno::Any(true) } );
445 //set global title properties
446 tNameSequence aPropNames
;
447 tAnySequence aPropValues
;
448 PropertyMapper::getMultiPropertyListsFromValueMap( aPropNames
, aPropValues
, aValueMap
);
450 OUString aString
= rFormattedString
[0]->getString();
452 sal_Int32 nXPos
= rPos
.X
;
453 sal_Int32 nYPos
= rPos
.Y
;
454 ::basegfx::B2DHomMatrix aM
;
455 aM
.rotate( -nRotation
*F_PI
/180.0 );//#i78696#->#i80521#
456 aM
.translate( nXPos
, nYPos
);
458 dummy::DummyText
* pText
= new dummy::DummyText(aString
, aPropNames
, aPropValues
,
459 uno::Any(B2DHomMatrixToHomogenMatrix3(aM
)), xTarget
, nRotation
);
460 pText
->setName(rName
);
464 void OpenglShapeFactory::render(uno::Reference
< drawing::XShapes
> xRootShape
, bool bInitOpenGL
)
466 dummy::DummyChart
& rChart
= dynamic_cast<dummy::DummyChart
&>(*xRootShape
.get());
469 rChart
.invalidateInit();
474 bool OpenglShapeFactory::preRender(uno::Reference
< drawing::XShapes
> xRootShape
, OpenGLWindow
* pWindow
)
480 pWindow
->getContext().makeCurrent();
481 Size aSize
= pWindow
->GetSizePixel();
482 pWindow
->getContext().setWinSize(aSize
);
483 dummy::DummyChart
& rChart
= dynamic_cast<dummy::DummyChart
&>(*xRootShape
.get());
484 rChart
.getRenderer().SetSizePixel(aSize
.Width(), aSize
.Height());
488 void OpenglShapeFactory::postRender(OpenGLWindow
* pWindow
)
490 pWindow
->getContext().swapBuffers();
493 void OpenglShapeFactory::clearPage(uno::Reference
< drawing::XShapes
> xRootShape
)
495 dummy::DummyChart
& rChart
= dynamic_cast<dummy::DummyChart
&>(*xRootShape
.get());
503 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */