Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / view / main / OpenglShapeFactory.cxx
blobe6c4980b8017045863d35ce6eb9c21a593546e67
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include <Stripe.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;
58 namespace chart
61 extern "C" {
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;
71 namespace opengl {
73 namespace {
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 );
80 if( xShapes.is() )
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 )
89 OUString aRet;
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();
96 break;
101 return xRet;
106 uno::Reference< drawing::XShapes > OpenglShapeFactory::getOrCreateChartRootShape(
107 const uno::Reference< drawing::XDrawPage>& xDrawPage )
109 uno::Reference< drawing::XShapes > xRet( getChartShape( xDrawPage ) );
110 if( !xRet.is() )
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));
118 xRet = pChart;
119 xDrawPage->add(pContainer);
121 return xRet;
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
136 , sal_Int32
137 , const uno::Reference< beans::XPropertySet >& xSourceProp
138 , const tPropertyNameMap& rPropertyNameMap
139 , bool )
141 dummy::DummyCube* pCube = new dummy::DummyCube(rPosition, rSize,
142 xSourceProp,
143 rPropertyNameMap);
144 xTarget->add(pCube);
145 return pCube;
148 uno::Reference<drawing::XShape>
149 OpenglShapeFactory::createCylinder(
150 const uno::Reference<drawing::XShapes>& xTarget
151 , const drawing::Position3D& rPosition, const drawing::Direction3D& rSize
152 , sal_Int32 )
154 dummy::DummyCylinder* pCylinder = new dummy::DummyCylinder( rPosition, rSize );
155 xTarget->add(pCylinder);
156 return 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
163 , double, bool
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);
170 return 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);
180 xTarget->add(pCone);
181 return pCone;
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);
196 return pSegment;
199 uno::Reference< drawing::XShape >
200 OpenglShapeFactory::createPieSegment(
201 const uno::Reference< drawing::XShapes >& xTarget
202 , double, double
203 , double, double
204 , const drawing::Direction3D&
205 , const drawing::HomogenMatrix&
206 , double )
208 dummy::DummyPieSegment* pSegment = new dummy::DummyPieSegment;
210 xTarget->add(pSegment);
211 return pSegment;
214 uno::Reference< drawing::XShape >
215 OpenglShapeFactory::createStripe( const uno::Reference< drawing::XShapes >& xTarget
216 , const Stripe&
217 , const uno::Reference< beans::XPropertySet >& xSourceProp
218 , const tPropertyNameMap& rPropertyNameMap
219 , bool
220 , short
221 , bool )
223 dummy::DummyStripe* pStripe = new dummy::DummyStripe(
224 xSourceProp, rPropertyNameMap);
225 xTarget->add(pStripe);
226 return pStripe;
229 uno::Reference< drawing::XShape >
230 OpenglShapeFactory::createArea3D( const uno::Reference< drawing::XShapes >& xTarget
231 , const drawing::PolyPolygonShape3D&
232 , double )
234 dummy::DummyArea3D* pArea = new dummy::DummyArea3D;
235 xTarget->add(pArea);
236 return pArea;
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));
244 xTarget->add(pArea);
245 return pArea;
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
254 , sal_Int32
255 , sal_Int32 nFillColor )
257 dummy::DummySymbol2D* pSymbol = new dummy::DummySymbol2D(rPosition, rSize,
258 nStandardSymbol, nFillColor);
259 xTarget->add(pSymbol);
260 return 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);
272 return 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);
281 return 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);
290 return 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);
305 return 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);
315 return 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);
324 xTarget->add(pLine);
325 return pLine;
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);
334 xTarget->add(pLine);
336 return pLine;
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);
344 xTarget->add(pLine);
345 return pLine;
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);
355 return 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);
371 return 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);
381 return 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 );
393 return pText;
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 );
407 return pText;
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 );
419 return pText;
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);
461 return pText;
464 void OpenglShapeFactory::render(uno::Reference< drawing::XShapes > xRootShape, bool bInitOpenGL)
466 dummy::DummyChart& rChart = dynamic_cast<dummy::DummyChart&>(*xRootShape.get());
467 if(bInitOpenGL)
469 rChart.invalidateInit();
471 rChart.render();
474 bool OpenglShapeFactory::preRender(uno::Reference< drawing::XShapes > xRootShape, OpenGLWindow* pWindow)
476 if(!pWindow)
477 return false;
479 pWindow->Show();
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());
485 return true;
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());
496 rChart.clear();
499 } //namespace dummy
501 } //namespace chart
503 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */