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