fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / view / main / OpenglShapeFactory.cxx
blob55774a97738f6cae8c2cf5ebde382b40e833cb37
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 "macros.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;
60 namespace chart
63 extern "C" {
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;
75 namespace opengl {
77 namespace {
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 );
84 if( xShapes.is() )
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 )
93 OUString aRet;
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();
100 break;
105 return xRet;
110 uno::Reference< drawing::XShapes > OpenglShapeFactory::getOrCreateChartRootShape(
111 const uno::Reference< drawing::XDrawPage>& xDrawPage )
113 uno::Reference< drawing::XShapes > xRet( getChartShape( xDrawPage ) );
114 if( !xRet.is() )
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));
122 xRet = pChart;
123 xDrawPage->add(pContainer);
125 return xRet;
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
140 , sal_Int32
141 , const uno::Reference< beans::XPropertySet >& xSourceProp
142 , const tPropertyNameMap& rPropertyNameMap
143 , bool )
145 dummy::DummyCube* pCube = new dummy::DummyCube(rPosition, rSize,
146 xSourceProp,
147 rPropertyNameMap);
148 xTarget->add(pCube);
149 return pCube;
152 uno::Reference<drawing::XShape>
153 OpenglShapeFactory::createCylinder(
154 const uno::Reference<drawing::XShapes>& xTarget
155 , const drawing::Position3D& rPosition, const drawing::Direction3D& rSize
156 , sal_Int32 )
158 dummy::DummyCylinder* pCylinder = new dummy::DummyCylinder( rPosition, rSize );
159 xTarget->add(pCylinder);
160 return 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
167 , double, bool
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);
174 return 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);
184 xTarget->add(pCone);
185 return pCone;
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);
200 return pSegment;
203 uno::Reference< drawing::XShape >
204 OpenglShapeFactory::createPieSegment(
205 const uno::Reference< drawing::XShapes >& xTarget
206 , double, double
207 , double, double
208 , const drawing::Direction3D& rOffset
209 , const drawing::HomogenMatrix& rUnitCircleToScene
210 , double )
212 dummy::DummyPieSegment* pSegment = new dummy::DummyPieSegment(
213 rOffset, rUnitCircleToScene);
215 xTarget->add(pSegment);
216 return 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
224 , bool
225 , short
226 , bool )
228 dummy::DummyStripe* pStripe = new dummy::DummyStripe(rStripe,
229 xSourceProp, rPropertyNameMap);
230 xTarget->add(pStripe);
231 return pStripe;
234 uno::Reference< drawing::XShape >
235 OpenglShapeFactory::createArea3D( const uno::Reference< drawing::XShapes >& xTarget
236 , const drawing::PolyPolygonShape3D& rPolyPolygon
237 , double )
239 dummy::DummyArea3D* pArea = new dummy::DummyArea3D(rPolyPolygon);
240 xTarget->add(pArea);
241 return pArea;
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));
249 xTarget->add(pArea);
250 return pArea;
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
259 , sal_Int32
260 , sal_Int32 nFillColor )
262 dummy::DummySymbol2D* pSymbol = new dummy::DummySymbol2D(rPosition, rSize,
263 nStandardSymbol, nFillColor);
264 xTarget->add(pSymbol);
265 return 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,
276 xGraphic);
277 xTarget->add(pGraphic);
278 return 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);
287 return 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);
296 return 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);
311 return 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);
321 return 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);
330 xTarget->add(pLine);
331 return pLine;
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);
340 xTarget->add(pLine);
342 return pLine;
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);
350 xTarget->add(pLine);
351 return pLine;
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);
361 return 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);
377 return 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);
387 return 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 );
399 return pText;
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);
446 return pText;
449 void OpenglShapeFactory::render(uno::Reference< drawing::XShapes > xRootShape, bool bInitOpenGL)
451 dummy::DummyChart& rChart = dynamic_cast<dummy::DummyChart&>(*xRootShape.get());
452 if(bInitOpenGL)
454 rChart.invalidateInit();
456 rChart.render();
459 bool OpenglShapeFactory::preRender(uno::Reference< drawing::XShapes > xRootShape, OpenGLWindow* pWindow)
461 if(!pWindow)
462 return false;
464 pWindow->Show();
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());
470 return true;
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());
481 rChart.clear();
484 } //namespace dummy
486 } //namespace chart
488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */