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 "VDiagram.hxx"
21 : #include "PropertyMapper.hxx"
22 : #include "ViewDefines.hxx"
23 : #include "Stripe.hxx"
24 : #include "macros.hxx"
25 : #include "ObjectIdentifier.hxx"
26 : #include "DiagramHelper.hxx"
27 : #include "BaseGFXHelper.hxx"
28 : #include "CommonConverters.hxx"
29 : #include "ChartTypeHelper.hxx"
30 : #include "ThreeDHelper.hxx"
31 : #include "defines.hxx"
32 : #include <editeng/unoprnms.hxx>
33 : #include <com/sun/star/drawing/FillStyle.hpp>
34 : #include <com/sun/star/drawing/LineStyle.hpp>
35 : #include <com/sun/star/drawing/ProjectionMode.hpp>
36 : #include <com/sun/star/drawing/ShadeMode.hpp>
37 : #include <com/sun/star/lang/XUnoTunnel.hpp>
38 : #include <com/sun/star/lang/XTypeProvider.hpp>
39 : #include <svx/unoshape.hxx>
40 : #include <svx/scene3d.hxx>
41 : #include <svx/e3dsceneupdater.hxx>
42 :
43 : namespace chart
44 : {
45 : using namespace ::com::sun::star;
46 : using namespace ::com::sun::star::chart2;
47 :
48 544 : VDiagram::VDiagram(
49 : const uno::Reference<XDiagram> & xDiagram, const drawing::Direction3D& rPreferredAspectRatio,
50 : sal_Int32 nDimension )
51 : : m_xTarget(NULL)
52 : , m_xShapeFactory(NULL)
53 : , m_pShapeFactory(NULL)
54 : , m_xOuterGroupShape(NULL)
55 : , m_xCoordinateRegionShape(NULL)
56 : , m_xWall2D(NULL)
57 : , m_nDimensionCount(nDimension)
58 : , m_xDiagram(xDiagram)
59 : , m_aPreferredAspectRatio(rPreferredAspectRatio)
60 : , m_xAspectRatio3D()
61 : , m_fXAnglePi(0)
62 : , m_fYAnglePi(0)
63 : , m_fZAnglePi(0)
64 544 : , m_bRightAngledAxes(false)
65 : {
66 544 : if( m_nDimensionCount == 3)
67 : {
68 37 : uno::Reference< beans::XPropertySet > xSourceProp( m_xDiagram, uno::UNO_QUERY );
69 37 : ThreeDHelper::getRotationAngleFromDiagram( xSourceProp, m_fXAnglePi, m_fYAnglePi, m_fZAnglePi );
70 74 : if( ChartTypeHelper::isSupportingRightAngledAxes(
71 74 : DiagramHelper::getChartTypeByIndex( m_xDiagram, 0 ) ) )
72 : {
73 35 : if(xSourceProp.is())
74 35 : xSourceProp->getPropertyValue("RightAngledAxes") >>= m_bRightAngledAxes;
75 35 : if( m_bRightAngledAxes )
76 : {
77 16 : ThreeDHelper::adaptRadAnglesForRightAngledAxes( m_fXAnglePi, m_fYAnglePi );
78 16 : m_fZAnglePi=0.0;
79 : }
80 37 : }
81 : }
82 544 : }
83 :
84 544 : VDiagram::~VDiagram()
85 : {
86 544 : }
87 :
88 544 : void VDiagram::init(
89 : const uno::Reference< drawing::XShapes >& xTarget, const uno::Reference< lang::XMultiServiceFactory >& xFactory )
90 : {
91 : OSL_PRECOND(xFactory.is(), "no proper initialization parameters");
92 :
93 544 : m_xTarget = xTarget;
94 544 : m_xShapeFactory = xFactory;
95 544 : m_pShapeFactory = AbstractShapeFactory::getOrCreateShapeFactory(xFactory);
96 544 : }
97 :
98 544 : void VDiagram::createShapes( const awt::Point& rPos, const awt::Size& rSize )
99 : {
100 544 : m_aAvailablePosIncludingAxes = rPos;
101 544 : m_aAvailableSizeIncludingAxes = rSize;
102 :
103 544 : if( m_nDimensionCount == 3 )
104 37 : createShapes_3d();
105 : else
106 507 : createShapes_2d();
107 544 : }
108 :
109 1580 : ::basegfx::B2IRectangle VDiagram::adjustPosAndSize( const awt::Point& rPos, const awt::Size& rSize )
110 : {
111 1580 : ::basegfx::B2IRectangle aAllowedRect( BaseGFXHelper::makeRectangle(m_aAvailablePosIncludingAxes,m_aAvailableSizeIncludingAxes) );
112 1580 : ::basegfx::B2IRectangle aNewInnerRect( BaseGFXHelper::makeRectangle(rPos,rSize) );
113 1580 : aNewInnerRect.intersect( aAllowedRect );
114 :
115 1580 : if( m_nDimensionCount == 3 )
116 107 : aNewInnerRect = adjustPosAndSize_3d( BaseGFXHelper::B2IRectangleToAWTPoint(aNewInnerRect), BaseGFXHelper::B2IRectangleToAWTSize(aNewInnerRect) );
117 : else
118 1473 : aNewInnerRect = adjustPosAndSize_2d( BaseGFXHelper::B2IRectangleToAWTPoint(aNewInnerRect), BaseGFXHelper::B2IRectangleToAWTSize(aNewInnerRect) );
119 :
120 1580 : return aNewInnerRect;
121 : }
122 :
123 1980 : ::basegfx::B2IRectangle VDiagram::adjustPosAndSize_2d( const awt::Point& rPos, const awt::Size& rAvailableSize )
124 : {
125 1980 : m_aCurrentPosWithoutAxes = rPos;
126 1980 : m_aCurrentSizeWithoutAxes = rAvailableSize;
127 1980 : if( m_aPreferredAspectRatio.DirectionX > 0 && m_aPreferredAspectRatio.DirectionY > 0)
128 : {
129 : //do not change aspect ratio
130 36 : awt::Size aAspectRatio( static_cast<sal_Int32>(m_aPreferredAspectRatio.DirectionX*FIXED_SIZE_FOR_3D_CHART_VOLUME),
131 72 : static_cast<sal_Int32>(m_aPreferredAspectRatio.DirectionY*FIXED_SIZE_FOR_3D_CHART_VOLUME ));
132 : m_aCurrentSizeWithoutAxes = awt::Size( AbstractShapeFactory::calculateNewSizeRespectingAspectRatio(
133 36 : rAvailableSize, aAspectRatio ) );
134 : //center diagram position
135 : m_aCurrentPosWithoutAxes = awt::Point( AbstractShapeFactory::calculateTopLeftPositionToCenterObject(
136 36 : rPos, rAvailableSize, m_aCurrentSizeWithoutAxes ) );
137 :
138 : }
139 :
140 1980 : if( m_xWall2D.is() )
141 : {
142 1980 : m_xWall2D->setSize( m_aCurrentSizeWithoutAxes);
143 1980 : m_xWall2D->setPosition(m_aCurrentPosWithoutAxes);
144 : }
145 :
146 1980 : return ::basegfx::B2IRectangle( BaseGFXHelper::makeRectangle(m_aCurrentPosWithoutAxes,m_aCurrentSizeWithoutAxes) );
147 : }
148 :
149 507 : void VDiagram::createShapes_2d()
150 : {
151 : OSL_PRECOND(m_pShapeFactory && m_xTarget.is() && m_xShapeFactory.is(), "is not proper initialized");
152 507 : if (!m_pShapeFactory || !m_xTarget.is() || !m_xShapeFactory.is())
153 507 : return;
154 :
155 : //create group shape
156 507 : uno::Reference< drawing::XShapes > xOuterGroup_Shapes = m_pShapeFactory->createGroup2D(m_xTarget);
157 507 : m_xOuterGroupShape = uno::Reference<drawing::XShape>( xOuterGroup_Shapes, uno::UNO_QUERY );
158 :
159 1014 : uno::Reference< drawing::XShapes > xGroupForWall( m_pShapeFactory->createGroup2D(xOuterGroup_Shapes,"PlotAreaExcludingAxes") );
160 :
161 : //create independent group shape as container for datapoints and such things
162 : {
163 507 : uno::Reference< drawing::XShapes > xShapes = m_pShapeFactory->createGroup2D(xOuterGroup_Shapes,"testonly;CooContainer=XXX_CID");
164 507 : m_xCoordinateRegionShape = uno::Reference<drawing::XShape>( xShapes, uno::UNO_QUERY );
165 : }
166 :
167 507 : bool bAddFloorAndWall = DiagramHelper::isSupportingFloorAndWall( m_xDiagram );
168 :
169 : //add back wall
170 : {
171 507 : AbstractShapeFactory* pShapeFactory = AbstractShapeFactory::getOrCreateShapeFactory(m_xShapeFactory);
172 1014 : m_xWall2D = pShapeFactory->createRectangle(
173 1014 : xGroupForWall );
174 :
175 507 : uno::Reference< beans::XPropertySet > xProp( m_xWall2D, uno::UNO_QUERY );
176 507 : if( xProp.is())
177 : {
178 : try
179 : {
180 : OSL_ENSURE( m_xDiagram.is(), "Invalid Diagram model" );
181 507 : if( m_xDiagram.is() )
182 : {
183 507 : uno::Reference< beans::XPropertySet > xWallProp( m_xDiagram->getWall());
184 507 : if( xWallProp.is())
185 507 : PropertyMapper::setMappedProperties( xProp, xWallProp, PropertyMapper::getPropertyNameMapForFillAndLineProperties() );
186 : }
187 507 : if( !bAddFloorAndWall )
188 : {
189 : //we always need this object as dummy object for correct scene dimensions
190 : //but it should not be visible in this case:
191 18 : AbstractShapeFactory::makeShapeInvisible( m_xWall2D );
192 : }
193 : else
194 : {
195 : //CID for selection handling
196 489 : OUString aWallCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, OUString() ) );//@todo read CID from model
197 489 : xProp->setPropertyValue( UNO_NAME_MISC_OBJ_NAME, uno::makeAny( aWallCID ) );
198 : }
199 : }
200 0 : catch( const uno::Exception& e )
201 : {
202 : ASSERT_EXCEPTION( e );
203 : }
204 507 : }
205 :
206 : }
207 :
208 : //position and size for diagram
209 1014 : adjustPosAndSize_2d( m_aAvailablePosIncludingAxes, m_aAvailableSizeIncludingAxes );
210 : }
211 :
212 218 : E3dScene* lcl_getE3dScene( const uno::Reference< drawing::XShape >& xShape )
213 : {
214 218 : E3dScene* pRet=NULL;
215 218 : uno::Reference< lang::XUnoTunnel > xUnoTunnel( xShape, uno::UNO_QUERY );
216 436 : uno::Reference< lang::XTypeProvider > xTypeProvider( xShape, uno::UNO_QUERY );
217 218 : if(xUnoTunnel.is()&&xTypeProvider.is())
218 : {
219 218 : SvxShape* pSvxShape = reinterpret_cast<SvxShape*>(xUnoTunnel->getSomething( SvxShape::getUnoTunnelId() ));
220 218 : if(pSvxShape)
221 : {
222 218 : SdrObject* pObj = pSvxShape->GetSdrObject();
223 218 : if( pObj && pObj->ISA(E3dScene) )
224 218 : pRet = static_cast<E3dScene*>(pObj);
225 : }
226 : }
227 436 : return pRet;
228 : }
229 :
230 37 : void lcl_setLightSources(
231 : const uno::Reference< beans::XPropertySet > & xSource,
232 : const uno::Reference< beans::XPropertySet > & xDest )
233 : {
234 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_1,
235 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_1));
236 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_2,
237 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_2));
238 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_3,
239 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_3));
240 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_4,
241 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_4));
242 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_5,
243 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_5));
244 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_6,
245 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_6));
246 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_7,
247 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_7));
248 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_8,
249 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_8));
250 :
251 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_1,
252 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_1));
253 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_2,
254 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_2));
255 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_3,
256 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_3));
257 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_4,
258 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_4));
259 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_5,
260 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_5));
261 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_6,
262 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_6));
263 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_7,
264 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_7));
265 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_8,
266 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_8));
267 :
268 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_1,
269 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_1));
270 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_2,
271 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_2));
272 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_3,
273 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_3));
274 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_4,
275 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_4));
276 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_5,
277 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_5));
278 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_6,
279 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_6));
280 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_7,
281 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_7));
282 37 : xDest->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_8,
283 37 : xSource->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_8));
284 37 : }
285 :
286 : namespace
287 : {
288 :
289 140 : void lcl_ensureScaleValue( double& rfScale )
290 : {
291 : OSL_ENSURE(rfScale>0, "calculation error for automatic 3D height in chart");
292 140 : if( rfScale<0 )
293 0 : rfScale = 1.0;
294 140 : else if( rfScale<0.2 )
295 0 : rfScale = 0.2;
296 140 : else if( rfScale>5.0 )
297 0 : rfScale = 5.0;
298 140 : }
299 :
300 : }
301 :
302 144 : void VDiagram::adjustAspectRatio3d( const awt::Size& rAvailableSize )
303 : {
304 : OSL_PRECOND(m_xAspectRatio3D.is(), "created shape offers no XPropertySet");
305 144 : if( m_xAspectRatio3D.is())
306 : {
307 : try
308 : {
309 144 : double fScaleX = m_aPreferredAspectRatio.DirectionX;
310 144 : double fScaleY = m_aPreferredAspectRatio.DirectionY;
311 144 : double fScaleZ = m_aPreferredAspectRatio.DirectionZ;
312 :
313 : //normalize scale factors
314 : {
315 144 : double fMax = std::max( std::max( fScaleX, fScaleY) , fScaleZ );
316 144 : fScaleX/=fMax;
317 144 : fScaleY/=fMax;
318 144 : fScaleZ/=fMax;
319 : }
320 :
321 144 : if( fScaleX<0 || fScaleY<0 || fScaleZ<0 )
322 : {
323 : //calculate automatic 3D aspect ratio that fits good into the given 2D area
324 140 : double fW = rAvailableSize.Width;
325 140 : double fH = rAvailableSize.Height;
326 :
327 140 : double sx = fabs(sin(m_fXAnglePi));
328 140 : double sy = fabs(sin(m_fYAnglePi));
329 140 : double cz = fabs(cos(m_fZAnglePi));
330 140 : double sz = fabs(sin(m_fZAnglePi));
331 :
332 140 : if(m_bRightAngledAxes)
333 : {
334 : //base equations:
335 : //fH*zoomfactor == sx*fScaleZ + fScaleY;
336 : //fW*zoomfactor == sy*fScaleZ + fScaleX;
337 :
338 64 : if( fScaleX>0 && fScaleZ>0 )
339 : {
340 : //calculate fScaleY:
341 96 : if( !::basegfx::fTools::equalZero(fW) )
342 : {
343 48 : fScaleY = (fH/fW)*(sy*fScaleZ+fScaleX)-(sx*fScaleZ);
344 48 : lcl_ensureScaleValue( fScaleY );
345 : }
346 : else
347 0 : fScaleY = 1.0;//looking from top or bottom the height is irrelevant
348 : }
349 16 : else if( fScaleY>0 && fScaleZ>0 )
350 : {
351 : //calculate fScaleX:
352 32 : if( !::basegfx::fTools::equalZero(fH) )
353 : {
354 16 : fScaleX = (fW/fH)*(sx*fScaleZ+fScaleY)-(sy*fScaleZ);
355 16 : lcl_ensureScaleValue(fScaleX);
356 : }
357 : else
358 0 : fScaleX = 1.0;//looking from top or bottom height is irrelevant
359 : }
360 : else
361 : {
362 : //todo
363 : OSL_FAIL("not implemented yet");
364 :
365 0 : if( fScaleX<0 )
366 0 : fScaleX = 1.0;
367 0 : if( fScaleY<0 )
368 0 : fScaleY = 1.0;
369 0 : if( fScaleZ<0 )
370 0 : fScaleZ = 1.0;
371 : }
372 : }
373 : else
374 : {
375 : //base equations:
376 : //fH*zoomfactor == cz*fScaleY + sz*fScaleX;
377 : //fW*zoomfactor == cz*fScaleX + sz*fScaleY;
378 : //==> fScaleY*(fH*sz-fW*cz) == fScaleX*(fW*sz-fH*cz);
379 76 : if( fScaleX>0 && fScaleZ>0 )
380 : {
381 : //calculate fScaleY:
382 76 : double fDivide = fH*sz-fW*cz;
383 76 : if( !::basegfx::fTools::equalZero(fDivide) )
384 : {
385 76 : fScaleY = fScaleX*(fW*sz-fH*cz) / fDivide;
386 76 : lcl_ensureScaleValue(fScaleY);
387 : }
388 : else
389 0 : fScaleY = 1.0;//looking from top or bottom the height is irrelevant
390 :
391 : }
392 0 : else if( fScaleY>0 && fScaleZ>0 )
393 : {
394 : //calculate fScaleX:
395 0 : double fDivide = fW*sz-fH*cz;
396 0 : if( !::basegfx::fTools::equalZero(fDivide) )
397 : {
398 0 : fScaleX = fScaleY*(fH*sz-fW*cz) / fDivide;
399 0 : lcl_ensureScaleValue(fScaleX);
400 : }
401 : else
402 0 : fScaleX = 1.0;//looking from top or bottom height is irrelevant
403 : }
404 : else
405 : {
406 : //todo
407 : OSL_FAIL("not implemented yet");
408 :
409 0 : if( fScaleX<0 )
410 0 : fScaleX = 1.0;
411 0 : if( fScaleY<0 )
412 0 : fScaleY = 1.0;
413 0 : if( fScaleZ<0 )
414 0 : fScaleZ = 1.0;
415 : }
416 : }
417 : }
418 :
419 : //normalize scale factors
420 : {
421 144 : double fMax = std::max( std::max( fScaleX, fScaleY) , fScaleZ );
422 144 : fScaleX/=fMax;
423 144 : fScaleY/=fMax;
424 144 : fScaleZ/=fMax;
425 : }
426 :
427 : // identity matrix
428 144 : ::basegfx::B3DHomMatrix aResult;
429 : aResult.translate( -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
430 : -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
431 144 : -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0 );
432 144 : aResult.scale( fScaleX, fScaleY, fScaleZ );
433 : aResult.translate( FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
434 : FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
435 144 : FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0 );
436 :
437 : // To get the 3D aspect ratio's effect on the 2D scene size, the scene's 2D size needs to be adapted to
438 : // 3D content changes here. The tooling class remembers the current 3D transformation stack
439 : // and in its destructor, calculates a new 2D SnapRect for the scene and it's modified 3D geometry.
440 288 : E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene( m_xOuterGroupShape ));
441 :
442 144 : m_xAspectRatio3D->setPropertyValue( UNO_NAME_3D_TRANSFORM_MATRIX
443 288 : , uno::makeAny(BaseGFXHelper::B3DHomMatrixToHomogenMatrix( aResult )) );
444 : }
445 0 : catch( const uno::Exception& e )
446 : {
447 : ASSERT_EXCEPTION( e );
448 : }
449 : }
450 144 : }
451 :
452 144 : ::basegfx::B2IRectangle VDiagram::adjustPosAndSize_3d( const awt::Point& rPos, const awt::Size& rAvailableSize )
453 : {
454 144 : adjustAspectRatio3d( rAvailableSize );
455 :
456 : //do not change aspect ratio of 3D scene with 2D bound rect
457 : m_aCurrentSizeWithoutAxes = AbstractShapeFactory::calculateNewSizeRespectingAspectRatio(
458 144 : rAvailableSize, m_xOuterGroupShape->getSize() );
459 144 : m_xOuterGroupShape->setSize( m_aCurrentSizeWithoutAxes );
460 :
461 : //center diagram position
462 : m_aCurrentPosWithoutAxes= AbstractShapeFactory::calculateTopLeftPositionToCenterObject(
463 144 : rPos, rAvailableSize, m_aCurrentSizeWithoutAxes );
464 144 : m_xOuterGroupShape->setPosition(m_aCurrentPosWithoutAxes);
465 :
466 144 : return ::basegfx::B2IRectangle( BaseGFXHelper::makeRectangle(m_aCurrentPosWithoutAxes,m_aCurrentSizeWithoutAxes) );
467 : }
468 :
469 37 : void VDiagram::createShapes_3d()
470 : {
471 : OSL_PRECOND(m_pShapeFactory && m_xTarget.is() && m_xShapeFactory.is(), "is not proper initialized");
472 37 : if (!m_pShapeFactory || !m_xTarget.is() || !m_xShapeFactory.is())
473 37 : return;
474 :
475 : //create shape
476 111 : m_xOuterGroupShape = uno::Reference< drawing::XShape >(
477 74 : m_pShapeFactory->createGroup3D( m_xTarget, "PlotAreaExcludingAxes" ), uno::UNO_QUERY);
478 :
479 : uno::Reference< drawing::XShapes > xOuterGroup_Shapes =
480 37 : uno::Reference<drawing::XShapes>( m_xOuterGroupShape, uno::UNO_QUERY );
481 :
482 : //create additional group to manipulate the aspect ratio of the whole diagram:
483 37 : xOuterGroup_Shapes = m_pShapeFactory->createGroup3D( xOuterGroup_Shapes, OUString() );
484 :
485 37 : m_xAspectRatio3D = uno::Reference< beans::XPropertySet >( xOuterGroup_Shapes, uno::UNO_QUERY );
486 :
487 37 : bool bAddFloorAndWall = DiagramHelper::isSupportingFloorAndWall( m_xDiagram );
488 :
489 37 : const bool bDoubleSided = false;
490 37 : const bool bFlatNormals = true;
491 :
492 : //add walls
493 : {
494 37 : uno::Reference< beans::XPropertySet > xWallProp( NULL );
495 37 : if( m_xDiagram.is() )
496 37 : xWallProp=uno::Reference< beans::XPropertySet >( m_xDiagram->getWall());
497 :
498 74 : OUString aWallCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, OUString() ) );//@todo read CID from model
499 37 : if( !bAddFloorAndWall )
500 2 : aWallCID = OUString();
501 74 : uno::Reference< drawing::XShapes > xWallGroup_Shapes( m_pShapeFactory->createGroup3D( xOuterGroup_Shapes, aWallCID ) );
502 :
503 37 : CuboidPlanePosition eLeftWallPos( ThreeDHelper::getAutomaticCuboidPlanePositionForStandardLeftWall( uno::Reference< beans::XPropertySet >( m_xDiagram, uno::UNO_QUERY ) ) );
504 37 : CuboidPlanePosition eBackWallPos( ThreeDHelper::getAutomaticCuboidPlanePositionForStandardBackWall( uno::Reference< beans::XPropertySet >( m_xDiagram, uno::UNO_QUERY ) ) );
505 :
506 : //add left wall
507 : {
508 37 : short nRotatedTexture = ( CuboidPlanePosition_Front==eBackWallPos ) ? 3 : 1;
509 37 : double xPos = 0.0;
510 37 : if( CuboidPlanePosition_Right==eLeftWallPos )
511 0 : xPos = FIXED_SIZE_FOR_3D_CHART_VOLUME;
512 : Stripe aStripe( drawing::Position3D(xPos,FIXED_SIZE_FOR_3D_CHART_VOLUME,0)
513 : , drawing::Direction3D(0,0,FIXED_SIZE_FOR_3D_CHART_VOLUME)
514 37 : , drawing::Direction3D(0,-FIXED_SIZE_FOR_3D_CHART_VOLUME,0) );
515 37 : if( CuboidPlanePosition_Right==eLeftWallPos )
516 : {
517 0 : nRotatedTexture = ( CuboidPlanePosition_Front==eBackWallPos ) ? 2 : 0;
518 : aStripe = Stripe( drawing::Position3D(xPos,FIXED_SIZE_FOR_3D_CHART_VOLUME,0)
519 : , drawing::Direction3D(0,-FIXED_SIZE_FOR_3D_CHART_VOLUME,0)
520 0 : , drawing::Direction3D(0,0,FIXED_SIZE_FOR_3D_CHART_VOLUME) );
521 : }
522 37 : aStripe.InvertNormal(true);
523 :
524 : uno::Reference< drawing::XShape > xShape =
525 : m_pShapeFactory->createStripe( xWallGroup_Shapes, aStripe
526 37 : , xWallProp, PropertyMapper::getPropertyNameMapForFillAndLineProperties(), bDoubleSided, nRotatedTexture, bFlatNormals );
527 37 : if( !bAddFloorAndWall )
528 : {
529 : //we always need this object as dummy object for correct scene dimensions
530 : //but it should not be visible in this case:
531 2 : AbstractShapeFactory::makeShapeInvisible( xShape );
532 37 : }
533 : }
534 : //add back wall
535 : {
536 37 : short nRotatedTexture = 0;
537 37 : double zPos = 0.0;
538 37 : if( CuboidPlanePosition_Front==eBackWallPos )
539 0 : zPos = FIXED_SIZE_FOR_3D_CHART_VOLUME;
540 : Stripe aStripe( drawing::Position3D(0,FIXED_SIZE_FOR_3D_CHART_VOLUME,zPos)
541 : , drawing::Direction3D(0,-FIXED_SIZE_FOR_3D_CHART_VOLUME,0)
542 37 : , drawing::Direction3D(FIXED_SIZE_FOR_3D_CHART_VOLUME,0,0) );
543 37 : if( CuboidPlanePosition_Front==eBackWallPos )
544 : {
545 : aStripe = Stripe( drawing::Position3D(0,FIXED_SIZE_FOR_3D_CHART_VOLUME,zPos)
546 : , drawing::Direction3D(FIXED_SIZE_FOR_3D_CHART_VOLUME,0,0)
547 0 : , drawing::Direction3D(0,-FIXED_SIZE_FOR_3D_CHART_VOLUME,0) );
548 0 : nRotatedTexture = 3;
549 : }
550 37 : aStripe.InvertNormal(true);
551 :
552 : uno::Reference< drawing::XShape > xShape =
553 : m_pShapeFactory->createStripe(xWallGroup_Shapes, aStripe
554 37 : , xWallProp, PropertyMapper::getPropertyNameMapForFillAndLineProperties(), bDoubleSided, nRotatedTexture, bFlatNormals );
555 37 : if( !bAddFloorAndWall )
556 : {
557 : //we always need this object as dummy object for correct scene dimensions
558 : //but it should not be visible in this case:
559 2 : AbstractShapeFactory::makeShapeInvisible( xShape );
560 37 : }
561 37 : }
562 : }
563 :
564 : try
565 : {
566 37 : uno::Reference< beans::XPropertySet > xSourceProp( m_xDiagram, uno::UNO_QUERY_THROW );
567 74 : uno::Reference< beans::XPropertySet > xDestProp( m_xOuterGroupShape, uno::UNO_QUERY_THROW );
568 :
569 : //perspective
570 : {
571 : //ignore distance and focal length from file format and model completely
572 : //use vrp only to indicate the distance of the camera and thus influence the perspective
573 37 : xDestProp->setPropertyValue( UNO_NAME_3D_SCENE_DISTANCE, uno::makeAny(
574 37 : static_cast<sal_Int32>(ThreeDHelper::getCameraDistance( xSourceProp ))));
575 37 : xDestProp->setPropertyValue( UNO_NAME_3D_SCENE_PERSPECTIVE,
576 37 : xSourceProp->getPropertyValue( UNO_NAME_3D_SCENE_PERSPECTIVE));
577 : }
578 :
579 : //light
580 : {
581 37 : xDestProp->setPropertyValue( UNO_NAME_3D_SCENE_SHADE_MODE,
582 37 : xSourceProp->getPropertyValue( UNO_NAME_3D_SCENE_SHADE_MODE));
583 37 : xDestProp->setPropertyValue( UNO_NAME_3D_SCENE_AMBIENTCOLOR,
584 37 : xSourceProp->getPropertyValue( UNO_NAME_3D_SCENE_AMBIENTCOLOR));
585 37 : xDestProp->setPropertyValue( UNO_NAME_3D_SCENE_TWO_SIDED_LIGHTING,
586 37 : xSourceProp->getPropertyValue( UNO_NAME_3D_SCENE_TWO_SIDED_LIGHTING));
587 37 : lcl_setLightSources( xSourceProp, xDestProp );
588 : }
589 :
590 : //rotation
591 : {
592 : //set diagrams rotation is set exclusively via the transformation matrix
593 : //don't set a camera at all!
594 : //the camera's rotation is incorporated into this matrix
595 :
596 37 : ::basegfx::B3DHomMatrix aEffectiveTranformation;
597 37 : aEffectiveTranformation.translate(-FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0, -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0, -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0);
598 :
599 37 : if(!m_bRightAngledAxes)
600 21 : aEffectiveTranformation.rotate(m_fXAnglePi,m_fYAnglePi,m_fZAnglePi);
601 : else
602 16 : aEffectiveTranformation.shearXY(m_fYAnglePi,-m_fXAnglePi);
603 :
604 : //#i98497# 3D charts are rendered with wrong size
605 74 : E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene( m_xOuterGroupShape ));
606 37 : xDestProp->setPropertyValue( UNO_NAME_3D_TRANSFORM_MATRIX,
607 74 : uno::makeAny( BaseGFXHelper::B3DHomMatrixToHomogenMatrix( aEffectiveTranformation ) ) );
608 37 : }
609 : }
610 0 : catch( const uno::Exception & ex )
611 : {
612 : ASSERT_EXCEPTION( ex );
613 : }
614 :
615 : //add floor plate
616 : {
617 37 : uno::Reference< beans::XPropertySet > xFloorProp( NULL );
618 37 : if( m_xDiagram.is() )
619 37 : xFloorProp=uno::Reference< beans::XPropertySet >( m_xDiagram->getFloor());
620 :
621 : Stripe aStripe( drawing::Position3D(0,0,0)
622 : , drawing::Direction3D(0,0,FIXED_SIZE_FOR_3D_CHART_VOLUME)
623 37 : , drawing::Direction3D(FIXED_SIZE_FOR_3D_CHART_VOLUME,0,0) );
624 37 : aStripe.InvertNormal(true);
625 :
626 : uno::Reference< drawing::XShape > xShape =
627 : m_pShapeFactory->createStripe(xOuterGroup_Shapes, aStripe
628 74 : , xFloorProp, PropertyMapper::getPropertyNameMapForFillAndLineProperties(), bDoubleSided, 0, bFlatNormals );
629 :
630 37 : CuboidPlanePosition eBottomPos( ThreeDHelper::getAutomaticCuboidPlanePositionForStandardBottom( uno::Reference< beans::XPropertySet >( m_xDiagram, uno::UNO_QUERY ) ) );
631 37 : if( !bAddFloorAndWall || (CuboidPlanePosition_Bottom!=eBottomPos) )
632 : {
633 : //we always need this object as dummy object for correct scene dimensions
634 : //but it should not be visible in this case:
635 2 : AbstractShapeFactory::makeShapeInvisible( xShape );
636 : }
637 : else
638 : {
639 35 : OUString aFloorCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_FLOOR, OUString() ) );//@todo read CID from model
640 35 : AbstractShapeFactory::setShapeName( xShape, aFloorCID );
641 37 : }
642 : }
643 :
644 : //create an additional scene for the smaller inner coordinate region:
645 : {
646 37 : uno::Reference< drawing::XShapes > xShapes = m_pShapeFactory->createGroup3D( xOuterGroup_Shapes,"testonly;CooContainer=XXX_CID" );
647 37 : m_xCoordinateRegionShape = uno::Reference< drawing::XShape >( xShapes, uno::UNO_QUERY );
648 :
649 74 : uno::Reference< beans::XPropertySet > xShapeProp( m_xCoordinateRegionShape, uno::UNO_QUERY );
650 : OSL_ENSURE(xShapeProp.is(), "created shape offers no XPropertySet");
651 37 : if( xShapeProp.is())
652 : {
653 : try
654 : {
655 37 : double fXScale = (FIXED_SIZE_FOR_3D_CHART_VOLUME -GRID_TO_WALL_DISTANCE) /FIXED_SIZE_FOR_3D_CHART_VOLUME;
656 37 : double fYScale = (FIXED_SIZE_FOR_3D_CHART_VOLUME -GRID_TO_WALL_DISTANCE) /FIXED_SIZE_FOR_3D_CHART_VOLUME;
657 37 : double fZScale = (FIXED_SIZE_FOR_3D_CHART_VOLUME -GRID_TO_WALL_DISTANCE) /FIXED_SIZE_FOR_3D_CHART_VOLUME;
658 :
659 37 : ::basegfx::B3DHomMatrix aM;
660 37 : aM.translate(GRID_TO_WALL_DISTANCE/fXScale, GRID_TO_WALL_DISTANCE/fYScale, GRID_TO_WALL_DISTANCE/fZScale);
661 37 : aM.scale( fXScale, fYScale, fZScale );
662 74 : E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene( m_xOuterGroupShape ));
663 37 : xShapeProp->setPropertyValue( UNO_NAME_3D_TRANSFORM_MATRIX
664 74 : , uno::makeAny(BaseGFXHelper::B3DHomMatrixToHomogenMatrix(aM)) );
665 : }
666 0 : catch( const uno::Exception& e )
667 : {
668 : ASSERT_EXCEPTION( e );
669 : }
670 37 : }
671 : }
672 :
673 37 : m_aCurrentPosWithoutAxes = m_aAvailablePosIncludingAxes;
674 37 : m_aCurrentSizeWithoutAxes = m_aAvailableSizeIncludingAxes;
675 37 : adjustPosAndSize_3d( m_aAvailablePosIncludingAxes, m_aAvailableSizeIncludingAxes );
676 : }
677 :
678 2692 : basegfx::B2IRectangle VDiagram::getCurrentRectangle() const
679 : {
680 2692 : return BaseGFXHelper::makeRectangle(m_aCurrentPosWithoutAxes,m_aCurrentSizeWithoutAxes);
681 : }
682 :
683 520 : void VDiagram::reduceToMimimumSize()
684 : {
685 520 : if( m_xOuterGroupShape.is() )
686 : {
687 520 : awt::Size aMaxSize( m_aAvailableSizeIncludingAxes );
688 520 : awt::Point aMaxPos( m_aAvailablePosIncludingAxes );
689 :
690 520 : sal_Int32 nNewWidth = aMaxSize.Width/3;
691 520 : sal_Int32 nNewHeight = aMaxSize.Height/3;
692 520 : awt::Size aNewSize( nNewWidth, nNewHeight );
693 520 : awt::Point aNewPos( aMaxPos );
694 520 : aNewPos.X += nNewWidth;
695 520 : aNewPos.Y += nNewHeight;
696 :
697 520 : adjustPosAndSize( aNewPos, aNewSize );
698 : }
699 520 : }
700 :
701 1060 : ::basegfx::B2IRectangle VDiagram::adjustInnerSize( const ::basegfx::B2IRectangle& rConsumedOuterRect )
702 : {
703 1060 : awt::Point aNewPos = m_aCurrentPosWithoutAxes;
704 1060 : awt::Size aNewSize = m_aCurrentSizeWithoutAxes;
705 :
706 : basegfx::B2IRectangle aAvailableOuterRect =
707 1060 : BaseGFXHelper::makeRectangle(m_aAvailablePosIncludingAxes, m_aAvailableSizeIncludingAxes);
708 :
709 1060 : sal_Int32 nDeltaWidth = aAvailableOuterRect.getWidth() - rConsumedOuterRect.getWidth();
710 1060 : sal_Int32 nDeltaHeight = aAvailableOuterRect.getHeight() - rConsumedOuterRect.getHeight();
711 1060 : if( (aNewSize.Width + nDeltaWidth) < aAvailableOuterRect.getWidth()/3 )
712 0 : nDeltaWidth = aAvailableOuterRect.getWidth()/3 - aNewSize.Width;
713 1060 : aNewSize.Width += nDeltaWidth;
714 :
715 1060 : if( (aNewSize.Height + nDeltaHeight) < aAvailableOuterRect.getHeight()/3 )
716 13 : nDeltaHeight = aAvailableOuterRect.getHeight()/3 - aNewSize.Height;
717 1060 : aNewSize.Height += nDeltaHeight;
718 :
719 1060 : sal_Int32 nDiffLeft = rConsumedOuterRect.getMinX() - aAvailableOuterRect.getMinX();
720 1060 : sal_Int32 nDiffRight = aAvailableOuterRect.getMaxX() - rConsumedOuterRect.getMaxX();
721 1060 : if( nDiffLeft >= 0 )
722 1053 : aNewPos.X -= nDiffLeft;
723 7 : else if( nDiffRight >= 0 )
724 : {
725 7 : if( nDiffRight > -nDiffLeft )
726 0 : aNewPos.X += abs(nDiffLeft);
727 7 : else if( nDiffRight > abs(nDeltaWidth) )
728 0 : aNewPos.X += nDiffRight;
729 : else
730 7 : aNewPos.X += abs(nDeltaWidth);
731 : }
732 :
733 1060 : sal_Int32 nDiffUp = rConsumedOuterRect.getMinY() - aAvailableOuterRect.getMinY();
734 1060 : sal_Int32 nDiffDown = aAvailableOuterRect.getMaxY() - rConsumedOuterRect.getMaxY();
735 1060 : if( nDiffUp >= 0 )
736 983 : aNewPos.Y -= nDiffUp;
737 77 : else if( nDiffDown >= 0 )
738 : {
739 73 : if( nDiffDown > -nDiffUp )
740 39 : aNewPos.Y += abs(nDiffUp);
741 34 : else if( nDiffDown > abs(nDeltaHeight) )
742 10 : aNewPos.Y += nDiffDown;
743 : else
744 24 : aNewPos.Y += abs(nDeltaHeight);
745 : }
746 :
747 1060 : return adjustPosAndSize( aNewPos, aNewSize );
748 : }
749 :
750 108 : } //namespace chart
751 :
752 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|