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"
27 #include "PropertyMapper.hxx"
28 #include <comphelper/InlineContainer.hxx>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/drawing/CircleKind.hpp>
31 #include <com/sun/star/drawing/DoubleSequence.hpp>
32 #include <com/sun/star/drawing/FlagSequence.hpp>
33 #include <com/sun/star/drawing/FillStyle.hpp>
34 #include <com/sun/star/drawing/LineStyle.hpp>
35 #include <com/sun/star/drawing/NormalsKind.hpp>
36 #include <com/sun/star/drawing/PointSequence.hpp>
37 #include <com/sun/star/drawing/PolygonKind.hpp>
38 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
39 #include <com/sun/star/drawing/ProjectionMode.hpp>
40 #include <com/sun/star/drawing/ShadeMode.hpp>
41 #include <com/sun/star/drawing/TextFitToSizeType.hpp>
42 #include <com/sun/star/drawing/TextureProjectionMode.hpp>
43 #include <com/sun/star/text/XText.hpp>
44 #include <com/sun/star/uno/Any.hxx>
46 #include <editeng/unoprnms.hxx>
47 #include <rtl/math.hxx>
48 #include <svx/svdocirc.hxx>
49 #include <svx/svdopath.hxx>
50 #include <vcl/opengl/IOpenGLRenderer.hxx>
51 #include <vcl/openglwin.hxx>
53 #include <basegfx/point/b2dpoint.hxx>
54 #include <basegfx/matrix/b3dhommatrix.hxx>
56 #include "RelativeSizeHelper.hxx"
58 using namespace ::com::sun::star
;
64 SAL_DLLPUBLIC_EXPORT
opengl::OpenglShapeFactory
* getOpenglShapeFactory()
65 { return new opengl::OpenglShapeFactory();}
68 using dummy::DummyXShape
;
69 using dummy::DummyXShapes
;
70 using dummy::DummyCylinder
;
71 using dummy::DummyRectangle
;
72 using dummy::DummyPyramid
;
73 using dummy::DummyCone
;
79 uno::Reference
< drawing::XShapes
> getChartShape(
80 const uno::Reference
< drawing::XDrawPage
>& xDrawPage
)
82 uno::Reference
< drawing::XShapes
> xRet
;
83 uno::Reference
< drawing::XShapes
> xShapes( xDrawPage
, uno::UNO_QUERY
);
86 sal_Int32 nCount
= xShapes
->getCount();
87 uno::Reference
< drawing::XShape
> xShape
;
88 for( sal_Int32 nN
= nCount
; nN
--; )
90 if( xShapes
->getByIndex( nN
) >>= xShape
)
95 uno::Reference
< beans::XPropertySet
> xProp( xShape
, uno::UNO_QUERY
);
96 xProp
->getPropertyValue( UNO_NAME_MISC_OBJ_NAME
) >>= aRet
;
97 if( aRet
== "com.sun.star.chart2.shapes" )
99 xRet
= dynamic_cast<SvxDummyShapeContainer
&>(*xShape
.get()).getWrappedShape();
110 uno::Reference
< drawing::XShapes
> OpenglShapeFactory::getOrCreateChartRootShape(
111 const uno::Reference
< drawing::XDrawPage
>& xDrawPage
)
113 uno::Reference
< drawing::XShapes
> xRet( getChartShape( xDrawPage
) );
116 //create the root shape
117 SAL_WARN("chart2.opengl", "getOrCreateChartRootShape");
119 dummy::DummyChart
*pChart
= new dummy::DummyChart();
120 SvxDummyShapeContainer
* pContainer
= new SvxDummyShapeContainer(pChart
);
121 pContainer
->setSize(awt::Size(0,0));
123 xDrawPage
->add(pContainer
);
128 void OpenglShapeFactory::setPageSize( uno::Reference
< drawing::XShapes
> xChartShapes
, const awt::Size
& rSize
)
130 uno::Reference
< drawing::XShape
> xShape(xChartShapes
, uno::UNO_QUERY_THROW
);
131 xShape
->setSize(rSize
);
134 // methods for 3D shape creation
136 uno::Reference
<drawing::XShape
>
137 OpenglShapeFactory::createCube(
138 const uno::Reference
<drawing::XShapes
>& xTarget
139 , const drawing::Position3D
& rPosition
, const drawing::Direction3D
& rSize
141 , const uno::Reference
< beans::XPropertySet
>& xSourceProp
142 , const tPropertyNameMap
& rPropertyNameMap
145 dummy::DummyCube
* pCube
= new dummy::DummyCube(rPosition
, rSize
,
152 uno::Reference
<drawing::XShape
>
153 OpenglShapeFactory::createCylinder(
154 const uno::Reference
<drawing::XShapes
>& xTarget
155 , const drawing::Position3D
& rPosition
, const drawing::Direction3D
& rSize
158 dummy::DummyCylinder
* pCylinder
= new dummy::DummyCylinder( rPosition
, rSize
);
159 xTarget
->add(pCylinder
);
163 uno::Reference
<drawing::XShape
>
164 OpenglShapeFactory::createPyramid(
165 const uno::Reference
<drawing::XShapes
>& xTarget
166 , const drawing::Position3D
& rPosition
, const drawing::Direction3D
& rSize
168 , const uno::Reference
< beans::XPropertySet
>& xSourceProp
169 , const tPropertyNameMap
& rPropertyNameMap
)
171 dummy::DummyPyramid
* pPyramid
= new dummy::DummyPyramid(rPosition
, rSize
,
172 xSourceProp
, rPropertyNameMap
);
173 xTarget
->add(pPyramid
);
177 uno::Reference
<drawing::XShape
>
178 OpenglShapeFactory::createCone(
179 const uno::Reference
<drawing::XShapes
>& xTarget
180 , const drawing::Position3D
& rPosition
, const drawing::Direction3D
& rSize
181 , double, sal_Int32
)
183 dummy::DummyCone
* pCone
= new dummy::DummyCone(rPosition
, rSize
);
188 uno::Reference
< drawing::XShape
>
189 OpenglShapeFactory::createPieSegment2D(
190 const uno::Reference
< drawing::XShapes
>& xTarget
191 , double fUnitCircleStartAngleDegree
, double fUnitCircleWidthAngleDegree
192 , double fUnitCircleInnerRadius
, double fUnitCircleOuterRadius
193 , const drawing::Direction3D
& rOffset
194 , const drawing::HomogenMatrix
& rUnitCircleToScene
)
196 dummy::DummyPieSegment2D
* pSegment
= new dummy::DummyPieSegment2D(fUnitCircleStartAngleDegree
,
197 fUnitCircleWidthAngleDegree
, fUnitCircleInnerRadius
, fUnitCircleOuterRadius
,
198 rOffset
, rUnitCircleToScene
);
199 xTarget
->add(pSegment
);
203 uno::Reference
< drawing::XShape
>
204 OpenglShapeFactory::createPieSegment(
205 const uno::Reference
< drawing::XShapes
>& xTarget
208 , const drawing::Direction3D
& rOffset
209 , const drawing::HomogenMatrix
& rUnitCircleToScene
212 dummy::DummyPieSegment
* pSegment
= new dummy::DummyPieSegment(
213 rOffset
, rUnitCircleToScene
);
215 xTarget
->add(pSegment
);
219 uno::Reference
< drawing::XShape
>
220 OpenglShapeFactory::createStripe( const uno::Reference
< drawing::XShapes
>& xTarget
221 , const Stripe
& rStripe
222 , const uno::Reference
< beans::XPropertySet
>& xSourceProp
223 , const tPropertyNameMap
& rPropertyNameMap
228 dummy::DummyStripe
* pStripe
= new dummy::DummyStripe(rStripe
,
229 xSourceProp
, rPropertyNameMap
);
230 xTarget
->add(pStripe
);
234 uno::Reference
< drawing::XShape
>
235 OpenglShapeFactory::createArea3D( const uno::Reference
< drawing::XShapes
>& xTarget
236 , const drawing::PolyPolygonShape3D
& rPolyPolygon
239 dummy::DummyArea3D
* pArea
= new dummy::DummyArea3D(rPolyPolygon
);
244 uno::Reference
< drawing::XShape
>
245 OpenglShapeFactory::createArea2D( const uno::Reference
< drawing::XShapes
>& xTarget
246 , const drawing::PolyPolygonShape3D
& rPolyPolygon
)
248 dummy::DummyArea2D
* pArea
= new dummy::DummyArea2D(PolyToPointSequence(rPolyPolygon
));
253 uno::Reference
< drawing::XShape
>
254 OpenglShapeFactory::createSymbol2D(
255 const uno::Reference
< drawing::XShapes
>& xTarget
256 , const drawing::Position3D
& rPosition
257 , const drawing::Direction3D
& rSize
258 , sal_Int32 nStandardSymbol
260 , sal_Int32 nFillColor
)
262 dummy::DummySymbol2D
* pSymbol
= new dummy::DummySymbol2D(rPosition
, rSize
,
263 nStandardSymbol
, nFillColor
);
264 xTarget
->add(pSymbol
);
268 uno::Reference
< drawing::XShape
>
269 OpenglShapeFactory::createGraphic2D(
270 const uno::Reference
< drawing::XShapes
>& xTarget
271 , const drawing::Position3D
& rPosition
272 , const drawing::Direction3D
& rSize
273 , const uno::Reference
< graphic::XGraphic
>& xGraphic
)
275 dummy::DummyGraphic2D
* pGraphic
= new dummy::DummyGraphic2D(rPosition
, rSize
,
277 xTarget
->add(pGraphic
);
281 uno::Reference
< drawing::XShapes
>
282 OpenglShapeFactory::createGroup2D( const uno::Reference
< drawing::XShapes
>& xTarget
283 , const OUString
& aName
)
285 dummy::DummyGroup2D
* pNewShape
= new dummy::DummyGroup2D(aName
);
286 xTarget
->add(pNewShape
);
290 uno::Reference
< drawing::XShapes
>
291 OpenglShapeFactory::createGroup3D( const uno::Reference
< drawing::XShapes
>& xTarget
292 , const OUString
& aName
)
294 dummy::DummyGroup3D
* pNewShape
= new dummy::DummyGroup3D(aName
);
295 xTarget
->add(pNewShape
);
299 uno::Reference
< drawing::XShape
>
300 OpenglShapeFactory::createCircle2D( const uno::Reference
< drawing::XShapes
>& xTarget
301 , const drawing::Position3D
& rPosition
302 , const drawing::Direction3D
& rSize
)
304 drawing::Position3D
aCenterPosition(
305 rPosition
.PositionX
- (rSize
.DirectionX
/ 2.0),
306 rPosition
.PositionY
- (rSize
.DirectionY
/ 2.0),
307 rPosition
.PositionZ
);
308 dummy::DummyCircle
* pCircle
= new dummy::DummyCircle(Position3DToAWTPoint( aCenterPosition
),
309 Direction3DToAWTSize( rSize
));
310 xTarget
->add(pCircle
);
314 uno::Reference
< drawing::XShape
>
315 OpenglShapeFactory::createCircle( const uno::Reference
< drawing::XShapes
>& xTarget
316 , const awt::Size
& rSize
317 , const awt::Point
& rPosition
)
319 dummy::DummyCircle
* pCircle
= new dummy::DummyCircle(rPosition
, rSize
);
320 xTarget
->add(pCircle
);
324 uno::Reference
< drawing::XShape
>
325 OpenglShapeFactory::createLine3D( const uno::Reference
< drawing::XShapes
>& xTarget
326 , const drawing::PolyPolygonShape3D
& rPoints
327 , const VLineProperties
& rLineProperties
)
329 dummy::DummyLine3D
* pLine
= new dummy::DummyLine3D(rPoints
, rLineProperties
);
334 uno::Reference
< drawing::XShape
>
335 OpenglShapeFactory::createLine2D( const uno::Reference
< drawing::XShapes
>& xTarget
336 , const drawing::PointSequenceSequence
& rPoints
337 , const VLineProperties
* pLineProperties
)
339 dummy::DummyLine2D
* pLine
= new dummy::DummyLine2D(rPoints
, pLineProperties
);
345 uno::Reference
< drawing::XShape
>
346 OpenglShapeFactory::createLine ( const uno::Reference
< drawing::XShapes
>& xTarget
,
347 const awt::Size
& rSize
, const awt::Point
& rPosition
)
349 dummy::DummyLine2D
* pLine
= new dummy::DummyLine2D(rSize
, rPosition
);
354 uno::Reference
< drawing::XShape
> OpenglShapeFactory::createInvisibleRectangle(
355 const uno::Reference
< drawing::XShapes
>& xTarget
356 , const awt::Size
& rSize
)
358 dummy::DummyRectangle
* pRectangle
= new dummy::DummyRectangle(rSize
);
359 pRectangle
->setPropertyValue("Invisible", uno::makeAny(sal_True
));
360 xTarget
->add(pRectangle
);
364 uno::Reference
< drawing::XShape
> OpenglShapeFactory::createRectangle(
365 const uno::Reference
< drawing::XShapes
>& xTarget
,
366 const awt::Size
& rSize
,
367 const awt::Point
& rPosition
,
368 const tNameSequence
& rPropNames
,
369 const tAnySequence
& rPropValues
,
370 StackPosition
/*ePos*/ )
372 dummy::DummyRectangle
* pRectangle
= new dummy::DummyRectangle(rSize
, rPosition
,
373 rPropNames
, rPropValues
);
375 // TODO : Honor stack position.
376 xTarget
->add(pRectangle
);
380 uno::Reference
< drawing::XShape
>
381 OpenglShapeFactory::createRectangle(
382 const uno::Reference
<
383 drawing::XShapes
>& xTarget
)
385 dummy::DummyRectangle
* pRectangle
= new dummy::DummyRectangle();
386 xTarget
->add(pRectangle
);
390 uno::Reference
< drawing::XShape
>
391 OpenglShapeFactory::createText( const uno::Reference
< drawing::XShapes
>& xTarget
392 , const OUString
& rText
393 , const tNameSequence
& rPropNames
394 , const tAnySequence
& rPropValues
395 , const uno::Any
& rATransformation
)
397 dummy::DummyText
* pText
= new dummy::DummyText( rText
, rPropNames
, rPropValues
,
398 rATransformation
, xTarget
, 0 );
402 uno::Reference
< drawing::XShape
>
403 OpenglShapeFactory::createText( const uno::Reference
< drawing::XShapes
>& xTarget
,
404 const awt::Size
& , const awt::Point
& rPos
,
405 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> >& rFormattedString
,
406 const uno::Reference
< beans::XPropertySet
> & xTextProperties
,
407 double nRotation
, const OUString
& rName
)
409 tPropertyNameValueMap aValueMap
;
410 //fill line-, fill- and paragraph-properties into the ValueMap
412 tMakePropertyNameMap aNameMap
= PropertyMapper::getPropertyNameMapForParagraphProperties();
413 aNameMap( PropertyMapper::getPropertyNameMapForFillAndLineProperties() );
415 PropertyMapper::getValueMap( aValueMap
, aNameMap
, xTextProperties
);
418 //fill some more shape properties into the ValueMap
420 drawing::TextHorizontalAdjust eHorizontalAdjust
= drawing::TextHorizontalAdjust_CENTER
;
421 drawing::TextVerticalAdjust eVerticalAdjust
= drawing::TextVerticalAdjust_CENTER
;
423 aValueMap
.insert( tPropertyNameValueMap::value_type( "TextHorizontalAdjust", uno::makeAny(eHorizontalAdjust
) ) ); // drawing::TextHorizontalAdjust
424 aValueMap
.insert( tPropertyNameValueMap::value_type( "TextVerticalAdjust", uno::makeAny(eVerticalAdjust
) ) ); //drawing::TextVerticalAdjust
425 aValueMap
.insert( tPropertyNameValueMap::value_type( "TextAutoGrowHeight", uno::makeAny(sal_True
) ) ); // sal_Bool
426 aValueMap
.insert( tPropertyNameValueMap::value_type( "TextAutoGrowWidth", uno::makeAny(sal_True
) ) ); // sal_Bool
430 //set global title properties
431 tNameSequence aPropNames
;
432 tAnySequence aPropValues
;
433 PropertyMapper::getMultiPropertyListsFromValueMap( aPropNames
, aPropValues
, aValueMap
);
435 OUString aString
= rFormattedString
[0]->getString();
437 sal_Int32 nXPos
= rPos
.X
;
438 sal_Int32 nYPos
= rPos
.Y
;
439 ::basegfx::B2DHomMatrix aM
;
440 aM
.rotate( -nRotation
*F_PI
/180.0 );//#i78696#->#i80521#
441 aM
.translate( nXPos
, nYPos
);
443 dummy::DummyText
* pText
= new dummy::DummyText(aString
, aPropNames
, aPropValues
,
444 uno::makeAny(B2DHomMatrixToHomogenMatrix3(aM
)), xTarget
, nRotation
);
445 pText
->setName(rName
);
449 void OpenglShapeFactory::render(uno::Reference
< drawing::XShapes
> xRootShape
, bool bInitOpenGL
)
451 dummy::DummyChart
& rChart
= dynamic_cast<dummy::DummyChart
&>(*xRootShape
.get());
454 rChart
.invalidateInit();
459 bool OpenglShapeFactory::preRender(uno::Reference
< drawing::XShapes
> xRootShape
, OpenGLWindow
* pWindow
)
465 pWindow
->getContext().makeCurrent();
466 Size aSize
= pWindow
->GetSizePixel();
467 pWindow
->getContext().setWinSize(aSize
);
468 dummy::DummyChart
& rChart
= dynamic_cast<dummy::DummyChart
&>(*xRootShape
.get());
469 rChart
.getRenderer().SetSizePixel(aSize
.Width(), aSize
.Height());
473 void OpenglShapeFactory::postRender(OpenGLWindow
* pWindow
)
475 pWindow
->getContext().swapBuffers();
478 void OpenglShapeFactory::clearPage(uno::Reference
< drawing::XShapes
> xRootShape
)
480 dummy::DummyChart
& rChart
= dynamic_cast<dummy::DummyChart
&>(*xRootShape
.get());
488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */