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