Line data Source code
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 :
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>
45 :
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>
52 :
53 : #include <basegfx/point/b2dpoint.hxx>
54 : #include <basegfx/matrix/b3dhommatrix.hxx>
55 :
56 : #include "RelativeSizeHelper.hxx"
57 :
58 : using namespace ::com::sun::star;
59 :
60 : namespace chart
61 : {
62 :
63 : extern "C" {
64 0 : SAL_DLLPUBLIC_EXPORT opengl::OpenglShapeFactory* getOpenglShapeFactory()
65 0 : { return new opengl::OpenglShapeFactory();}
66 : }
67 :
68 : using dummy::DummyXShape;
69 : using dummy::DummyXShapes;
70 : using dummy::DummyCylinder;
71 : using dummy::DummyRectangle;
72 : using dummy::DummyPyramid;
73 : using dummy::DummyCone;
74 :
75 : namespace opengl {
76 :
77 : namespace {
78 :
79 0 : uno::Reference< drawing::XShapes > getChartShape(
80 : const uno::Reference< drawing::XDrawPage>& xDrawPage )
81 : {
82 0 : uno::Reference< drawing::XShapes > xRet;
83 0 : uno::Reference< drawing::XShapes > xShapes( xDrawPage, uno::UNO_QUERY );
84 0 : if( xShapes.is() )
85 : {
86 0 : sal_Int32 nCount = xShapes->getCount();
87 0 : uno::Reference< drawing::XShape > xShape;
88 0 : for( sal_Int32 nN = nCount; nN--; )
89 : {
90 0 : if( xShapes->getByIndex( nN ) >>= xShape )
91 : {
92 :
93 0 : OUString aRet;
94 :
95 0 : uno::Reference< beans::XPropertySet > xProp( xShape, uno::UNO_QUERY );
96 0 : xProp->getPropertyValue( UNO_NAME_MISC_OBJ_NAME ) >>= aRet;
97 0 : if( aRet == "com.sun.star.chart2.shapes" )
98 : {
99 0 : xRet = dynamic_cast<SvxDummyShapeContainer&>(*xShape.get()).getWrappedShape();
100 0 : break;
101 0 : }
102 : }
103 0 : }
104 : }
105 0 : return xRet;
106 : }
107 :
108 : }
109 :
110 0 : uno::Reference< drawing::XShapes > OpenglShapeFactory::getOrCreateChartRootShape(
111 : const uno::Reference< drawing::XDrawPage>& xDrawPage )
112 : {
113 0 : uno::Reference< drawing::XShapes > xRet( getChartShape( xDrawPage ) );
114 0 : if( !xRet.is() )
115 : {
116 : //create the root shape
117 : SAL_WARN("chart2.opengl", "getOrCreateChartRootShape");
118 :
119 0 : dummy::DummyChart *pChart = new dummy::DummyChart();
120 0 : SvxDummyShapeContainer* pContainer = new SvxDummyShapeContainer(pChart);
121 0 : pContainer->setSize(awt::Size(0,0));
122 0 : xRet = pChart;
123 0 : xDrawPage->add(pContainer);
124 : }
125 0 : return xRet;
126 : }
127 :
128 0 : void OpenglShapeFactory::setPageSize( uno::Reference < drawing::XShapes > xChartShapes, const awt::Size& rSize )
129 : {
130 0 : uno::Reference< drawing::XShape > xShape(xChartShapes, uno::UNO_QUERY_THROW);
131 0 : xShape->setSize(rSize);
132 0 : }
133 :
134 : // methods for 3D shape creation
135 :
136 : uno::Reference<drawing::XShape>
137 0 : 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 )
144 : {
145 : dummy::DummyCube* pCube = new dummy::DummyCube(rPosition, rSize,
146 : xSourceProp,
147 0 : rPropertyNameMap);
148 0 : xTarget->add(pCube);
149 0 : return pCube;
150 : }
151 :
152 : uno::Reference<drawing::XShape>
153 0 : OpenglShapeFactory::createCylinder(
154 : const uno::Reference<drawing::XShapes>& xTarget
155 : , const drawing::Position3D& rPosition, const drawing::Direction3D& rSize
156 : , sal_Int32 )
157 : {
158 0 : dummy::DummyCylinder* pCylinder = new dummy::DummyCylinder( rPosition, rSize );
159 0 : xTarget->add(pCylinder);
160 0 : return pCylinder;
161 : }
162 :
163 : uno::Reference<drawing::XShape>
164 0 : 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 )
170 : {
171 : dummy::DummyPyramid* pPyramid = new dummy::DummyPyramid(rPosition, rSize,
172 0 : xSourceProp, rPropertyNameMap );
173 0 : xTarget->add(pPyramid);
174 0 : return pPyramid;
175 : }
176 :
177 : uno::Reference<drawing::XShape>
178 0 : OpenglShapeFactory::createCone(
179 : const uno::Reference<drawing::XShapes>& xTarget
180 : , const drawing::Position3D& rPosition, const drawing::Direction3D& rSize
181 : , double, sal_Int32 )
182 : {
183 0 : dummy::DummyCone* pCone = new dummy::DummyCone(rPosition, rSize);
184 0 : xTarget->add(pCone);
185 0 : return pCone;
186 : }
187 :
188 : uno::Reference< drawing::XShape >
189 0 : 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 )
195 : {
196 : dummy::DummyPieSegment2D* pSegment = new dummy::DummyPieSegment2D(fUnitCircleStartAngleDegree,
197 : fUnitCircleWidthAngleDegree, fUnitCircleInnerRadius, fUnitCircleOuterRadius,
198 0 : rOffset, rUnitCircleToScene);
199 0 : xTarget->add(pSegment);
200 0 : return pSegment;
201 : }
202 :
203 : uno::Reference< drawing::XShape >
204 0 : 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 )
211 : {
212 : dummy::DummyPieSegment* pSegment = new dummy::DummyPieSegment(
213 0 : rOffset, rUnitCircleToScene);
214 :
215 0 : xTarget->add(pSegment);
216 0 : return pSegment;
217 : }
218 :
219 : uno::Reference< drawing::XShape >
220 0 : 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 )
227 : {
228 : dummy::DummyStripe* pStripe = new dummy::DummyStripe(rStripe,
229 0 : xSourceProp, rPropertyNameMap);
230 0 : xTarget->add(pStripe);
231 0 : return pStripe;
232 : }
233 :
234 : uno::Reference< drawing::XShape >
235 0 : OpenglShapeFactory::createArea3D( const uno::Reference< drawing::XShapes >& xTarget
236 : , const drawing::PolyPolygonShape3D& rPolyPolygon
237 : , double )
238 : {
239 0 : dummy::DummyArea3D* pArea = new dummy::DummyArea3D(rPolyPolygon);
240 0 : xTarget->add(pArea);
241 0 : return pArea;
242 : }
243 :
244 : uno::Reference< drawing::XShape >
245 0 : OpenglShapeFactory::createArea2D( const uno::Reference< drawing::XShapes >& xTarget
246 : , const drawing::PolyPolygonShape3D& rPolyPolygon )
247 : {
248 0 : dummy::DummyArea2D* pArea = new dummy::DummyArea2D(PolyToPointSequence(rPolyPolygon));
249 0 : xTarget->add(pArea);
250 0 : return pArea;
251 : }
252 :
253 : uno::Reference< drawing::XShape >
254 0 : 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 )
261 : {
262 : dummy::DummySymbol2D* pSymbol = new dummy::DummySymbol2D(rPosition, rSize,
263 0 : nStandardSymbol, nFillColor);
264 0 : xTarget->add(pSymbol);
265 0 : return pSymbol;
266 : }
267 :
268 : uno::Reference< drawing::XShape >
269 0 : 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 )
274 : {
275 : dummy::DummyGraphic2D* pGraphic = new dummy::DummyGraphic2D(rPosition, rSize,
276 0 : xGraphic);
277 0 : xTarget->add(pGraphic);
278 0 : return pGraphic;
279 : }
280 :
281 : uno::Reference< drawing::XShapes >
282 0 : OpenglShapeFactory::createGroup2D( const uno::Reference< drawing::XShapes >& xTarget
283 : , const OUString& aName)
284 : {
285 0 : dummy::DummyGroup2D* pNewShape = new dummy::DummyGroup2D(aName);
286 0 : xTarget->add(pNewShape);
287 0 : return pNewShape;
288 : }
289 :
290 : uno::Reference< drawing::XShapes >
291 0 : OpenglShapeFactory::createGroup3D( const uno::Reference< drawing::XShapes >& xTarget
292 : , const OUString& aName )
293 : {
294 0 : dummy::DummyGroup3D* pNewShape = new dummy::DummyGroup3D(aName);
295 0 : xTarget->add(pNewShape);
296 0 : return pNewShape;
297 : }
298 :
299 : uno::Reference< drawing::XShape >
300 0 : OpenglShapeFactory::createCircle2D( const uno::Reference< drawing::XShapes >& xTarget
301 : , const drawing::Position3D& rPosition
302 : , const drawing::Direction3D& rSize )
303 : {
304 : drawing::Position3D aCenterPosition(
305 0 : rPosition.PositionX - (rSize.DirectionX / 2.0),
306 0 : rPosition.PositionY - (rSize.DirectionY / 2.0),
307 0 : rPosition.PositionZ );
308 : dummy::DummyCircle* pCircle = new dummy::DummyCircle(Position3DToAWTPoint( aCenterPosition ),
309 0 : Direction3DToAWTSize( rSize ));
310 0 : xTarget->add(pCircle);
311 0 : return pCircle;
312 : }
313 :
314 : uno::Reference< drawing::XShape >
315 0 : OpenglShapeFactory::createCircle( const uno::Reference< drawing::XShapes >& xTarget
316 : , const awt::Size& rSize
317 : , const awt::Point& rPosition )
318 : {
319 0 : dummy::DummyCircle* pCircle = new dummy::DummyCircle(rPosition, rSize);
320 0 : xTarget->add(pCircle);
321 0 : return pCircle;
322 : }
323 :
324 : uno::Reference< drawing::XShape >
325 0 : OpenglShapeFactory::createLine3D( const uno::Reference< drawing::XShapes >& xTarget
326 : , const drawing::PolyPolygonShape3D& rPoints
327 : , const VLineProperties& rLineProperties )
328 : {
329 0 : dummy::DummyLine3D* pLine = new dummy::DummyLine3D(rPoints, rLineProperties);
330 0 : xTarget->add(pLine);
331 0 : return pLine;
332 : }
333 :
334 : uno::Reference< drawing::XShape >
335 0 : OpenglShapeFactory::createLine2D( const uno::Reference< drawing::XShapes >& xTarget
336 : , const drawing::PointSequenceSequence& rPoints
337 : , const VLineProperties* pLineProperties )
338 : {
339 0 : dummy::DummyLine2D* pLine = new dummy::DummyLine2D(rPoints, pLineProperties);
340 0 : xTarget->add(pLine);
341 :
342 0 : return pLine;
343 : }
344 :
345 : uno::Reference< drawing::XShape >
346 0 : OpenglShapeFactory::createLine ( const uno::Reference< drawing::XShapes >& xTarget,
347 : const awt::Size& rSize, const awt::Point& rPosition )
348 : {
349 0 : dummy::DummyLine2D* pLine = new dummy::DummyLine2D(rSize, rPosition);
350 0 : xTarget->add(pLine);
351 0 : return pLine;
352 : }
353 :
354 0 : uno::Reference< drawing::XShape > OpenglShapeFactory::createInvisibleRectangle(
355 : const uno::Reference< drawing::XShapes >& xTarget
356 : , const awt::Size& rSize )
357 : {
358 0 : dummy::DummyRectangle* pRectangle = new dummy::DummyRectangle(rSize);
359 0 : pRectangle->setPropertyValue("Invisible", uno::makeAny(sal_True));
360 0 : xTarget->add(pRectangle);
361 0 : return pRectangle;
362 : }
363 :
364 0 : 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*/ )
371 : {
372 : dummy::DummyRectangle* pRectangle = new dummy::DummyRectangle(rSize, rPosition,
373 0 : rPropNames, rPropValues);
374 :
375 : // TODO : Honor stack position.
376 0 : xTarget->add(pRectangle);
377 0 : return pRectangle;
378 : }
379 :
380 : uno::Reference< drawing::XShape >
381 0 : OpenglShapeFactory::createRectangle(
382 : const uno::Reference<
383 : drawing::XShapes >& xTarget)
384 : {
385 0 : dummy::DummyRectangle* pRectangle = new dummy::DummyRectangle();
386 0 : xTarget->add(pRectangle);
387 0 : return pRectangle;
388 : }
389 :
390 : uno::Reference< drawing::XShape >
391 0 : 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 )
396 : {
397 : dummy::DummyText* pText = new dummy::DummyText( rText, rPropNames, rPropValues,
398 0 : rATransformation, xTarget, 0 );
399 0 : return pText;
400 : }
401 :
402 : uno::Reference< drawing::XShape >
403 0 : 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)
408 : {
409 0 : tPropertyNameValueMap aValueMap;
410 : //fill line-, fill- and paragraph-properties into the ValueMap
411 : {
412 0 : tMakePropertyNameMap aNameMap = PropertyMapper::getPropertyNameMapForParagraphProperties();
413 0 : aNameMap( PropertyMapper::getPropertyNameMapForFillAndLineProperties() );
414 :
415 0 : PropertyMapper::getValueMap( aValueMap, aNameMap, xTextProperties );
416 : }
417 :
418 : //fill some more shape properties into the ValueMap
419 : {
420 0 : drawing::TextHorizontalAdjust eHorizontalAdjust = drawing::TextHorizontalAdjust_CENTER;
421 0 : drawing::TextVerticalAdjust eVerticalAdjust = drawing::TextVerticalAdjust_CENTER;
422 :
423 0 : aValueMap.insert( tPropertyNameValueMap::value_type( "TextHorizontalAdjust", uno::makeAny(eHorizontalAdjust) ) ); // drawing::TextHorizontalAdjust
424 0 : aValueMap.insert( tPropertyNameValueMap::value_type( "TextVerticalAdjust", uno::makeAny(eVerticalAdjust) ) ); //drawing::TextVerticalAdjust
425 0 : aValueMap.insert( tPropertyNameValueMap::value_type( "TextAutoGrowHeight", uno::makeAny(sal_True) ) ); // sal_Bool
426 0 : aValueMap.insert( tPropertyNameValueMap::value_type( "TextAutoGrowWidth", uno::makeAny(sal_True) ) ); // sal_Bool
427 :
428 : }
429 :
430 : //set global title properties
431 0 : tNameSequence aPropNames;
432 0 : tAnySequence aPropValues;
433 0 : PropertyMapper::getMultiPropertyListsFromValueMap( aPropNames, aPropValues, aValueMap );
434 :
435 0 : OUString aString = rFormattedString[0]->getString();
436 :
437 0 : sal_Int32 nXPos = rPos.X;
438 0 : sal_Int32 nYPos = rPos.Y;
439 0 : ::basegfx::B2DHomMatrix aM;
440 0 : aM.rotate( -nRotation*F_PI/180.0 );//#i78696#->#i80521#
441 0 : aM.translate( nXPos, nYPos );
442 :
443 : dummy::DummyText* pText = new dummy::DummyText(aString, aPropNames, aPropValues,
444 0 : uno::makeAny(B2DHomMatrixToHomogenMatrix3(aM)), xTarget, nRotation);
445 0 : pText->setName(rName);
446 0 : return pText;
447 : }
448 :
449 0 : void OpenglShapeFactory::render(uno::Reference< drawing::XShapes > xRootShape, bool bInitOpenGL)
450 : {
451 0 : dummy::DummyChart& rChart = dynamic_cast<dummy::DummyChart&>(*xRootShape.get());
452 0 : if(bInitOpenGL)
453 : {
454 0 : rChart.invalidateInit();
455 : }
456 0 : rChart.render();
457 0 : }
458 :
459 0 : bool OpenglShapeFactory::preRender(uno::Reference< drawing::XShapes > xRootShape, OpenGLWindow* pWindow)
460 : {
461 0 : if(!pWindow)
462 0 : return false;
463 :
464 0 : pWindow->Show();
465 0 : pWindow->getContext().makeCurrent();
466 0 : Size aSize = pWindow->GetSizePixel();
467 0 : pWindow->getContext().setWinSize(aSize);
468 0 : dummy::DummyChart& rChart = dynamic_cast<dummy::DummyChart&>(*xRootShape.get());
469 0 : rChart.getRenderer().SetSizePixel(aSize.Width(), aSize.Height());
470 0 : return true;
471 : }
472 :
473 0 : void OpenglShapeFactory::postRender(OpenGLWindow* pWindow)
474 : {
475 0 : pWindow->getContext().swapBuffers();
476 0 : }
477 :
478 0 : void OpenglShapeFactory::clearPage(uno::Reference< drawing::XShapes > xRootShape)
479 : {
480 0 : dummy::DummyChart& rChart = dynamic_cast<dummy::DummyChart&>(*xRootShape.get());
481 0 : rChart.clear();
482 0 : }
483 :
484 : } //namespace dummy
485 :
486 0 : } //namespace chart
487 :
488 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|