xref: /trunk/main/svx/source/customshapes/EnhancedCustomShape3d.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_svx.hxx"
30*cdf0e10cSrcweir #include "EnhancedCustomShape3d.hxx"
31*cdf0e10cSrcweir #include <svx/svdetc.hxx>
32*cdf0e10cSrcweir #include <svx/svdmodel.hxx>
33*cdf0e10cSrcweir #include <tools/poly.hxx>
34*cdf0e10cSrcweir #include <svx/svditer.hxx>
35*cdf0e10cSrcweir #include <svx/svdobj.hxx>
36*cdf0e10cSrcweir #include <svx/svdoashp.hxx>
37*cdf0e10cSrcweir #include <svl/poolitem.hxx>
38*cdf0e10cSrcweir #include <svl/itemset.hxx>
39*cdf0e10cSrcweir #include <svx/xfillit0.hxx>
40*cdf0e10cSrcweir #include <svx/xsflclit.hxx>
41*cdf0e10cSrcweir #include <svx/xit.hxx>
42*cdf0e10cSrcweir #include <svx/xbtmpit.hxx>
43*cdf0e10cSrcweir #include <svx/xflclit.hxx>
44*cdf0e10cSrcweir #include <svx/svdopath.hxx>
45*cdf0e10cSrcweir #include <svx/svdogrp.hxx>
46*cdf0e10cSrcweir #include <svx/svdpage.hxx>
47*cdf0e10cSrcweir #include <svx/polysc3d.hxx>
48*cdf0e10cSrcweir #include <svx/svddef.hxx>
49*cdf0e10cSrcweir #include <svx/svx3ditems.hxx>
50*cdf0e10cSrcweir #include <svx/extrud3d.hxx>
51*cdf0e10cSrcweir #include <svx/xflbmtit.hxx>
52*cdf0e10cSrcweir #include <vcl/svapp.hxx>
53*cdf0e10cSrcweir #include <svx/xlnclit.hxx>
54*cdf0e10cSrcweir #include <svx/sdasitm.hxx>
55*cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/drawing/Position3D.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/drawing/Direction3D.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/drawing/ShadeMode.hpp>
59*cdf0e10cSrcweir #include <svx/sdr/properties/properties.hxx>
60*cdf0e10cSrcweir #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
61*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
62*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #define ITEMVALUE(ItemSet,Id,Cast)  ((const Cast&)(ItemSet).Get(Id)).GetValue()
65*cdf0e10cSrcweir using namespace com::sun::star;
66*cdf0e10cSrcweir using namespace com::sun::star::uno;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir const rtl::OUString sExtrusion( RTL_CONSTASCII_USTRINGPARAM ( "Extrusion" ) );
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir void GetOrigin( SdrCustomShapeGeometryItem& rItem, double& rOriginX, double& rOriginY )
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir     ::com::sun::star::drawing::EnhancedCustomShapeParameterPair aOriginParaPair;
73*cdf0e10cSrcweir     const rtl::OUString sOrigin( RTL_CONSTASCII_USTRINGPARAM ( "Origin" ) );
74*cdf0e10cSrcweir     Any* pAny = rItem.GetPropertyValueByName( sExtrusion, sOrigin );
75*cdf0e10cSrcweir     if ( ! ( pAny && ( *pAny >>= aOriginParaPair ) && ( aOriginParaPair.First.Value >>= rOriginX ) && ( aOriginParaPair.Second.Value >>= rOriginY ) ) )
76*cdf0e10cSrcweir     {
77*cdf0e10cSrcweir         rOriginX = 0.50;
78*cdf0e10cSrcweir         rOriginY =-0.50;
79*cdf0e10cSrcweir     }
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir void GetRotateAngle( SdrCustomShapeGeometryItem& rItem, double& rAngleX, double& rAngleY )
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir     ::com::sun::star::drawing::EnhancedCustomShapeParameterPair aRotateAngleParaPair;
85*cdf0e10cSrcweir     const rtl::OUString sRotateAngle( RTL_CONSTASCII_USTRINGPARAM ( "RotateAngle" ) );
86*cdf0e10cSrcweir     Any* pAny = rItem.GetPropertyValueByName( sExtrusion, sRotateAngle );
87*cdf0e10cSrcweir     if ( ! ( pAny && ( *pAny >>= aRotateAngleParaPair ) && ( aRotateAngleParaPair.First.Value >>= rAngleX ) && ( aRotateAngleParaPair.Second.Value >>= rAngleY ) ) )
88*cdf0e10cSrcweir     {
89*cdf0e10cSrcweir         rAngleX = 0.0;
90*cdf0e10cSrcweir         rAngleY = 0.0;
91*cdf0e10cSrcweir     }
92*cdf0e10cSrcweir     rAngleX *= F_PI180;
93*cdf0e10cSrcweir     rAngleY *= F_PI180;
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir void GetSkew( SdrCustomShapeGeometryItem& rItem, double& rSkewAmount, double& rSkewAngle )
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir     ::com::sun::star::drawing::EnhancedCustomShapeParameterPair aSkewParaPair;
99*cdf0e10cSrcweir     const rtl::OUString sSkew( RTL_CONSTASCII_USTRINGPARAM ( "Skew" ) );
100*cdf0e10cSrcweir     Any* pAny = rItem.GetPropertyValueByName( sExtrusion, sSkew );
101*cdf0e10cSrcweir     if ( ! ( pAny && ( *pAny >>= aSkewParaPair ) && ( aSkewParaPair.First.Value >>= rSkewAmount ) && ( aSkewParaPair.Second.Value >>= rSkewAngle ) ) )
102*cdf0e10cSrcweir     {
103*cdf0e10cSrcweir         rSkewAmount = 50;
104*cdf0e10cSrcweir         rSkewAngle = -135;
105*cdf0e10cSrcweir     }
106*cdf0e10cSrcweir     rSkewAngle *= F_PI180;
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir void GetExtrusionDepth( SdrCustomShapeGeometryItem& rItem, const double* pMap, double& rBackwardDepth, double& rForwardDepth )
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir     ::com::sun::star::drawing::EnhancedCustomShapeParameterPair aDepthParaPair;
112*cdf0e10cSrcweir     double fDepth = 0, fFraction = 0;
113*cdf0e10cSrcweir     const rtl::OUString sDepth( RTL_CONSTASCII_USTRINGPARAM ( "Depth" ) );
114*cdf0e10cSrcweir     Any* pAny = rItem.GetPropertyValueByName( sExtrusion, sDepth );
115*cdf0e10cSrcweir     if ( pAny && ( *pAny >>= aDepthParaPair ) && ( aDepthParaPair.First.Value >>= fDepth ) && ( aDepthParaPair.Second.Value >>= fFraction ) )
116*cdf0e10cSrcweir     {
117*cdf0e10cSrcweir         rForwardDepth = fDepth * fFraction;
118*cdf0e10cSrcweir         rBackwardDepth = fDepth - rForwardDepth;
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir     else
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         rBackwardDepth = 1270;
123*cdf0e10cSrcweir         rForwardDepth = 0;
124*cdf0e10cSrcweir     }
125*cdf0e10cSrcweir     if ( pMap )
126*cdf0e10cSrcweir     {
127*cdf0e10cSrcweir         double fMap = *pMap;
128*cdf0e10cSrcweir         rBackwardDepth *= fMap;
129*cdf0e10cSrcweir         rForwardDepth *= fMap;
130*cdf0e10cSrcweir     }
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir double GetDouble( SdrCustomShapeGeometryItem& rItem, const rtl::OUString& rPropertyName, double fDefault, const double* pMap )
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir     double fRetValue = fDefault;
136*cdf0e10cSrcweir     Any* pAny = rItem.GetPropertyValueByName( sExtrusion, rPropertyName );
137*cdf0e10cSrcweir     if ( pAny )
138*cdf0e10cSrcweir         *pAny >>= fRetValue;
139*cdf0e10cSrcweir     if ( pMap )
140*cdf0e10cSrcweir         fRetValue *= *pMap;
141*cdf0e10cSrcweir     return fRetValue;
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir drawing::ShadeMode GetShadeMode( SdrCustomShapeGeometryItem& rItem, const drawing::ShadeMode eDefault )
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     drawing::ShadeMode eRet( eDefault );
147*cdf0e10cSrcweir     const rtl::OUString sShadeMode( RTL_CONSTASCII_USTRINGPARAM ( "ShadeMode" ) );
148*cdf0e10cSrcweir     Any* pAny = rItem.GetPropertyValueByName( sExtrusion, sShadeMode );
149*cdf0e10cSrcweir     if ( pAny )
150*cdf0e10cSrcweir         *pAny >>= eRet;
151*cdf0e10cSrcweir     return eRet;
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir sal_Int32 GetInt32( SdrCustomShapeGeometryItem& rItem, const rtl::OUString& rPropertyName, const sal_Int32 nDefault )
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir     sal_Int32 nRetValue = nDefault;
157*cdf0e10cSrcweir     Any* pAny = rItem.GetPropertyValueByName( sExtrusion, rPropertyName );
158*cdf0e10cSrcweir     if ( pAny )
159*cdf0e10cSrcweir         *pAny >>= nRetValue;
160*cdf0e10cSrcweir     return nRetValue;
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir sal_Bool GetBool( SdrCustomShapeGeometryItem& rItem, const rtl::OUString& rPropertyName, const sal_Bool bDefault )
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir     sal_Bool bRetValue = bDefault;
166*cdf0e10cSrcweir     const Any* pAny = rItem.GetPropertyValueByName( sExtrusion, rPropertyName );
167*cdf0e10cSrcweir     if ( pAny )
168*cdf0e10cSrcweir         *pAny >>= bRetValue;
169*cdf0e10cSrcweir     return bRetValue;
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir awt::Point GetPoint( SdrCustomShapeGeometryItem& rItem, const rtl::OUString& rPropertyName, const awt::Point& rDefault )
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir     awt::Point aRetValue( rDefault );
175*cdf0e10cSrcweir     const Any* pAny = rItem.GetPropertyValueByName( sExtrusion, rPropertyName );
176*cdf0e10cSrcweir     if ( pAny )
177*cdf0e10cSrcweir         *pAny >>= aRetValue;
178*cdf0e10cSrcweir     return aRetValue;
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir drawing::Position3D GetPosition3D( SdrCustomShapeGeometryItem& rItem, const rtl::OUString& rPropertyName,
182*cdf0e10cSrcweir                                     const drawing::Position3D& rDefault, const double* pMap )
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     drawing::Position3D aRetValue( rDefault );
185*cdf0e10cSrcweir     const Any* pAny = rItem.GetPropertyValueByName( sExtrusion, rPropertyName );
186*cdf0e10cSrcweir     if ( pAny )
187*cdf0e10cSrcweir         *pAny >>= aRetValue;
188*cdf0e10cSrcweir     if ( pMap )
189*cdf0e10cSrcweir     {
190*cdf0e10cSrcweir         aRetValue.PositionX *= *pMap;
191*cdf0e10cSrcweir         aRetValue.PositionY *= *pMap;
192*cdf0e10cSrcweir         aRetValue.PositionZ *= *pMap;
193*cdf0e10cSrcweir     }
194*cdf0e10cSrcweir     return aRetValue;
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir drawing::Direction3D GetDirection3D( SdrCustomShapeGeometryItem& rItem, const rtl::OUString& rPropertyName, const drawing::Direction3D& rDefault )
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir     drawing::Direction3D aRetValue( rDefault );
200*cdf0e10cSrcweir     const Any* pAny = rItem.GetPropertyValueByName( sExtrusion, rPropertyName );
201*cdf0e10cSrcweir     if ( pAny )
202*cdf0e10cSrcweir         *pAny >>= aRetValue;
203*cdf0e10cSrcweir     return aRetValue;
204*cdf0e10cSrcweir }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir EnhancedCustomShape3d::Transformation2D::Transformation2D( const SdrObject* pCustomShape, const Rectangle& /*rBoundRect*/, const double *pM )
207*cdf0e10cSrcweir :   aCenter( pCustomShape->GetSnapRect().Center() )
208*cdf0e10cSrcweir ,   eProjectionMode( drawing::ProjectionMode_PARALLEL )
209*cdf0e10cSrcweir ,   pMap( pM )
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     SdrCustomShapeGeometryItem& rGeometryItem = (SdrCustomShapeGeometryItem&)pCustomShape->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
212*cdf0e10cSrcweir     const rtl::OUString sProjectionMode( RTL_CONSTASCII_USTRINGPARAM ( "ProjectionMode" ) );
213*cdf0e10cSrcweir     Any* pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, sProjectionMode );
214*cdf0e10cSrcweir     if ( pAny )
215*cdf0e10cSrcweir         *pAny >>= eProjectionMode;
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir     if ( eProjectionMode == drawing::ProjectionMode_PARALLEL )
218*cdf0e10cSrcweir         GetSkew( rGeometryItem, fSkew, fSkewAngle );
219*cdf0e10cSrcweir     else
220*cdf0e10cSrcweir     {
221*cdf0e10cSrcweir         fZScreen = 0.0;
222*cdf0e10cSrcweir         GetOrigin( rGeometryItem, fOriginX, fOriginY );
223*cdf0e10cSrcweir         fOriginX = fOriginX * pCustomShape->GetLogicRect().GetWidth();
224*cdf0e10cSrcweir         fOriginY = fOriginY * pCustomShape->GetLogicRect().GetHeight();
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir         const rtl::OUString sViewPoint( RTL_CONSTASCII_USTRINGPARAM ( "ViewPoint" ) );
227*cdf0e10cSrcweir         drawing::Position3D aViewPointDefault( 3472, -3472, 25000 );
228*cdf0e10cSrcweir         drawing::Position3D aViewPoint( GetPosition3D( rGeometryItem, sViewPoint, aViewPointDefault, pMap ) );
229*cdf0e10cSrcweir         fViewPoint.setX(aViewPoint.PositionX);
230*cdf0e10cSrcweir         fViewPoint.setY(aViewPoint.PositionY);
231*cdf0e10cSrcweir         fViewPoint.setZ(-aViewPoint.PositionZ);
232*cdf0e10cSrcweir     }
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir basegfx::B3DPolygon EnhancedCustomShape3d::Transformation2D::ApplySkewSettings( const basegfx::B3DPolygon& rPoly3D ) const
236*cdf0e10cSrcweir {
237*cdf0e10cSrcweir     basegfx::B3DPolygon aRetval;
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     sal_uInt32 j;
240*cdf0e10cSrcweir     for ( j = 0L; j < rPoly3D.count(); j++ )
241*cdf0e10cSrcweir     {
242*cdf0e10cSrcweir         const basegfx::B3DPoint aPoint(rPoly3D.getB3DPoint(j));
243*cdf0e10cSrcweir         double fDepth(-( aPoint.getZ() * fSkew ) / 100.0);
244*cdf0e10cSrcweir         aRetval.append(basegfx::B3DPoint(
245*cdf0e10cSrcweir             aPoint.getX() + (fDepth * cos( fSkewAngle )),
246*cdf0e10cSrcweir             aPoint.getY() - (fDepth * sin( fSkewAngle )),
247*cdf0e10cSrcweir             aPoint.getZ()));
248*cdf0e10cSrcweir     }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     return aRetval;
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir Point EnhancedCustomShape3d::Transformation2D::Transform2D( const basegfx::B3DPoint& rPoint3D ) const
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir     Point aPoint2D;
256*cdf0e10cSrcweir     if ( eProjectionMode == drawing::ProjectionMode_PARALLEL )
257*cdf0e10cSrcweir     {
258*cdf0e10cSrcweir         aPoint2D.X() = (sal_Int32)rPoint3D.getX();
259*cdf0e10cSrcweir         aPoint2D.Y() = (sal_Int32)rPoint3D.getY();
260*cdf0e10cSrcweir     }
261*cdf0e10cSrcweir     else
262*cdf0e10cSrcweir     {
263*cdf0e10cSrcweir         double fX = rPoint3D.getX() - fOriginX;
264*cdf0e10cSrcweir         double fY = rPoint3D.getY() - fOriginY;
265*cdf0e10cSrcweir         double f = ( fZScreen - fViewPoint.getZ() ) / ( rPoint3D.getZ() - fViewPoint.getZ() );
266*cdf0e10cSrcweir         aPoint2D.X() = (sal_Int32)(( fX - fViewPoint.getX() ) * f + fViewPoint.getX() + fOriginX );
267*cdf0e10cSrcweir         aPoint2D.Y() = (sal_Int32)(( fY - fViewPoint.getY() ) * f + fViewPoint.getY() + fOriginY );
268*cdf0e10cSrcweir     }
269*cdf0e10cSrcweir     aPoint2D.Move( aCenter.X(), aCenter.Y() );
270*cdf0e10cSrcweir     return aPoint2D;
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir sal_Bool EnhancedCustomShape3d::Transformation2D::IsParallel() const
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir     return eProjectionMode == com::sun::star::drawing::ProjectionMode_PARALLEL;
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir SdrObject* EnhancedCustomShape3d::Create3DObject( const SdrObject* pShape2d, const SdrObject* pCustomShape )
279*cdf0e10cSrcweir {
280*cdf0e10cSrcweir     SdrObject*  pRet = NULL;
281*cdf0e10cSrcweir     SdrModel*   pModel = pCustomShape->GetModel();
282*cdf0e10cSrcweir     SdrCustomShapeGeometryItem& rGeometryItem = (SdrCustomShapeGeometryItem&)pCustomShape->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir     double      fMap, *pMap = NULL;
285*cdf0e10cSrcweir     if ( pModel )
286*cdf0e10cSrcweir     {
287*cdf0e10cSrcweir         fMap = 1.0;
288*cdf0e10cSrcweir         Fraction aFraction( pModel->GetScaleFraction() );
289*cdf0e10cSrcweir         if ( ( aFraction.GetNumerator() ) != 1 || ( aFraction.GetDenominator() != 1 ) )
290*cdf0e10cSrcweir         {
291*cdf0e10cSrcweir             fMap *= aFraction.GetNumerator();
292*cdf0e10cSrcweir             fMap /= aFraction.GetDenominator();
293*cdf0e10cSrcweir             pMap = &fMap;
294*cdf0e10cSrcweir         }
295*cdf0e10cSrcweir         if ( pModel->GetScaleUnit() != MAP_100TH_MM )
296*cdf0e10cSrcweir         {
297*cdf0e10cSrcweir             DBG_ASSERT( pModel->GetScaleUnit() == MAP_TWIP, "EnhancedCustomShape3d::Current MapMode is Unsupported" );
298*cdf0e10cSrcweir             fMap *= 1440.0 / 2540.0;
299*cdf0e10cSrcweir             pMap = &fMap;
300*cdf0e10cSrcweir         }
301*cdf0e10cSrcweir     }
302*cdf0e10cSrcweir     if ( GetBool( rGeometryItem, sExtrusion, sal_False ) )
303*cdf0e10cSrcweir     {
304*cdf0e10cSrcweir         sal_Bool bIsMirroredX = ((SdrObjCustomShape*)pCustomShape)->IsMirroredX();
305*cdf0e10cSrcweir         sal_Bool bIsMirroredY = ((SdrObjCustomShape*)pCustomShape)->IsMirroredY();
306*cdf0e10cSrcweir         Rectangle aSnapRect( pCustomShape->GetLogicRect() );
307*cdf0e10cSrcweir         long nObjectRotation = pCustomShape->GetRotateAngle();
308*cdf0e10cSrcweir         if ( nObjectRotation )
309*cdf0e10cSrcweir         {
310*cdf0e10cSrcweir             double a = ( 36000 - nObjectRotation ) * nPi180;
311*cdf0e10cSrcweir             long dx = aSnapRect.Right() - aSnapRect.Left();
312*cdf0e10cSrcweir             long dy = aSnapRect.Bottom()- aSnapRect.Top();
313*cdf0e10cSrcweir             Point aP( aSnapRect.TopLeft() );
314*cdf0e10cSrcweir             RotatePoint( aP, pCustomShape->GetSnapRect().Center(), sin( a ), cos( a ) );
315*cdf0e10cSrcweir             aSnapRect.Left() = aP.X();
316*cdf0e10cSrcweir             aSnapRect.Top() = aP.Y();
317*cdf0e10cSrcweir             aSnapRect.Right() = aSnapRect.Left() + dx;
318*cdf0e10cSrcweir             aSnapRect.Bottom() = aSnapRect.Top() + dy;
319*cdf0e10cSrcweir         }
320*cdf0e10cSrcweir         Point aCenter( aSnapRect.Center() );
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir         SfxItemSet aSet( pCustomShape->GetMergedItemSet() );
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir         //SJ: vertical writing is not required, by removing this item no outliner is created
325*cdf0e10cSrcweir         aSet.ClearItem( SDRATTR_TEXTDIRECTION );
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir         // #i105323# For 3D AutoShapes, the shadow attribute has to be applied to each
328*cdf0e10cSrcweir         // created visualisation helper model shape individually. The shadow itself
329*cdf0e10cSrcweir         // will then be rendered from the 3D renderer correctly for the whole 3D scene
330*cdf0e10cSrcweir         // (and thus behind all objects of which the visualisation may be built). So,
331*cdf0e10cSrcweir         // dio NOT remove it from the ItemSet here.
332*cdf0e10cSrcweir         // aSet.ClearItem(SDRATTR_SHADOW);
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir         std::vector< E3dCompoundObject* > aPlaceholderObjectList;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir         double fExtrusionBackward, fExtrusionForward;
337*cdf0e10cSrcweir         GetExtrusionDepth( rGeometryItem, pMap, fExtrusionBackward, fExtrusionForward );
338*cdf0e10cSrcweir         double fDepth = fExtrusionBackward - fExtrusionForward;
339*cdf0e10cSrcweir         if ( fDepth < 1.0 )
340*cdf0e10cSrcweir             fDepth = 1.0;
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir         drawing::ProjectionMode eProjectionMode( drawing::ProjectionMode_PARALLEL );
343*cdf0e10cSrcweir         const rtl::OUString sProjectionMode( RTL_CONSTASCII_USTRINGPARAM ( "ProjectionMode" ) );
344*cdf0e10cSrcweir         Any* pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, sProjectionMode );
345*cdf0e10cSrcweir         if ( pAny )
346*cdf0e10cSrcweir             *pAny >>= eProjectionMode;
347*cdf0e10cSrcweir         ProjectionType eProjectionType( eProjectionMode == drawing::ProjectionMode_PARALLEL ? PR_PARALLEL : PR_PERSPECTIVE );
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir         // pShape2d Umwandeln in Szene mit 3D Objekt
350*cdf0e10cSrcweir         E3dDefaultAttributes a3DDefaultAttr;
351*cdf0e10cSrcweir         a3DDefaultAttr.SetDefaultLatheCharacterMode( sal_True );
352*cdf0e10cSrcweir         a3DDefaultAttr.SetDefaultExtrudeCharacterMode( sal_True );
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir         E3dScene* pScene = new E3dPolyScene( a3DDefaultAttr );
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir         sal_Bool bSceneHasObjects ( sal_False );
357*cdf0e10cSrcweir         sal_Bool bUseTwoFillStyles( sal_False );
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir         drawing::ShadeMode eShadeMode( GetShadeMode( rGeometryItem, drawing::ShadeMode_FLAT ) );
360*cdf0e10cSrcweir         const rtl::OUString sExtrusionColor( RTL_CONSTASCII_USTRINGPARAM ( "Color" ) );
361*cdf0e10cSrcweir         sal_Bool bUseExtrusionColor = GetBool( rGeometryItem, sExtrusionColor, sal_False );
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir         XFillStyle eFillStyle( ITEMVALUE( aSet, XATTR_FILLSTYLE, XFillStyleItem ) );
364*cdf0e10cSrcweir         pScene->GetProperties().SetObjectItem( Svx3DShadeModeItem( 0 ) );
365*cdf0e10cSrcweir         aSet.Put( Svx3DPercentDiagonalItem( 0 ) );
366*cdf0e10cSrcweir         aSet.Put( Svx3DTextureModeItem( 1 ) );
367*cdf0e10cSrcweir         aSet.Put( Svx3DNormalsKindItem( 1 ) );
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir         if ( eShadeMode == drawing::ShadeMode_DRAFT )
370*cdf0e10cSrcweir         {
371*cdf0e10cSrcweir             aSet.Put( XLineStyleItem( XLINE_SOLID ) );
372*cdf0e10cSrcweir             aSet.Put( XFillStyleItem ( XFILL_NONE ) );
373*cdf0e10cSrcweir             aSet.Put( Svx3DDoubleSidedItem( sal_True ) );
374*cdf0e10cSrcweir         }
375*cdf0e10cSrcweir         else
376*cdf0e10cSrcweir         {
377*cdf0e10cSrcweir             aSet.Put( XLineStyleItem( XLINE_NONE ) );
378*cdf0e10cSrcweir             if ( eFillStyle == XFILL_NONE )
379*cdf0e10cSrcweir                 aSet.Put( XFillStyleItem( XFILL_SOLID ) );
380*cdf0e10cSrcweir             else if ( ( eFillStyle == XFILL_BITMAP ) || ( eFillStyle == XFILL_GRADIENT ) || bUseExtrusionColor )
381*cdf0e10cSrcweir                 bUseTwoFillStyles = sal_True;
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir             // #116336#
384*cdf0e10cSrcweir             // If shapes are mirrored once (mirroring two times correct geometry again)
385*cdf0e10cSrcweir             // double-sided at the object and two-sided-lighting at the scene need to be set.
386*cdf0e10cSrcweir             if((bIsMirroredX && !bIsMirroredY) || (!bIsMirroredX && bIsMirroredY))
387*cdf0e10cSrcweir             {
388*cdf0e10cSrcweir                 aSet.Put( Svx3DDoubleSidedItem( sal_True ) );
389*cdf0e10cSrcweir                 pScene->GetProperties().SetObjectItem( Svx3DTwoSidedLightingItem( sal_True ) );
390*cdf0e10cSrcweir             }
391*cdf0e10cSrcweir         }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir         Rectangle aBoundRect2d;
394*cdf0e10cSrcweir         SdrObjListIter aIter( *pShape2d, IM_DEEPWITHGROUPS );
395*cdf0e10cSrcweir         while( aIter.IsMore() )
396*cdf0e10cSrcweir         {
397*cdf0e10cSrcweir             const SdrObject* pNext = aIter.Next();
398*cdf0e10cSrcweir             sal_Bool bIsPlaceholderObject = (((XFillStyleItem&)pNext->GetMergedItem( XATTR_FILLSTYLE )).GetValue() == XFILL_NONE )
399*cdf0e10cSrcweir                                         && (((XLineStyleItem&)pNext->GetMergedItem( XATTR_LINESTYLE )).GetValue() == XLINE_NONE );
400*cdf0e10cSrcweir             basegfx::B2DPolyPolygon aPolyPoly;
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir             if ( pNext->ISA( SdrPathObj ) )
403*cdf0e10cSrcweir             {
404*cdf0e10cSrcweir                 aPolyPoly = ((SdrPathObj*)pNext)->GetPathPoly();
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir                 if(aPolyPoly.areControlPointsUsed())
407*cdf0e10cSrcweir                 {
408*cdf0e10cSrcweir                     aPolyPoly = basegfx::tools::adaptiveSubdivideByAngle(aPolyPoly);
409*cdf0e10cSrcweir                 }
410*cdf0e10cSrcweir             }
411*cdf0e10cSrcweir             else
412*cdf0e10cSrcweir             {
413*cdf0e10cSrcweir                 SdrObject* pNewObj = pNext->ConvertToPolyObj( sal_False, sal_False );
414*cdf0e10cSrcweir                 SdrPathObj* pPath = PTR_CAST( SdrPathObj, pNewObj );
415*cdf0e10cSrcweir                 if ( pPath )
416*cdf0e10cSrcweir                     aPolyPoly = pPath->GetPathPoly();
417*cdf0e10cSrcweir                 SdrObject::Free( pNewObj );
418*cdf0e10cSrcweir             }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir             if( aPolyPoly.count() )
421*cdf0e10cSrcweir             {
422*cdf0e10cSrcweir                 const basegfx::B2DRange aTempRange(basegfx::tools::getRange(aPolyPoly));
423*cdf0e10cSrcweir                 const Rectangle aBoundRect(basegfx::fround(aTempRange.getMinX()), basegfx::fround(aTempRange.getMinY()), basegfx::fround(aTempRange.getMaxX()), basegfx::fround(aTempRange.getMaxY()));
424*cdf0e10cSrcweir                 aBoundRect2d.Union( aBoundRect );
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir                 E3dCompoundObject* p3DObj = new E3dExtrudeObj( a3DDefaultAttr, aPolyPoly, bUseTwoFillStyles ? 10 : fDepth );
427*cdf0e10cSrcweir                 p3DObj->NbcSetLayer( pShape2d->GetLayer() );
428*cdf0e10cSrcweir                 p3DObj->SetMergedItemSet( aSet );
429*cdf0e10cSrcweir                 if ( bIsPlaceholderObject )
430*cdf0e10cSrcweir                     aPlaceholderObjectList.push_back( p3DObj );
431*cdf0e10cSrcweir                 else if ( bUseTwoFillStyles )
432*cdf0e10cSrcweir                 {
433*cdf0e10cSrcweir                     Bitmap aFillBmp;
434*cdf0e10cSrcweir                     sal_Bool bFillBmpTile = ((XFillBmpTileItem&)p3DObj->GetMergedItem( XATTR_FILLBMP_TILE )).GetValue();
435*cdf0e10cSrcweir                     if ( bFillBmpTile )
436*cdf0e10cSrcweir                     {
437*cdf0e10cSrcweir                         const XFillBitmapItem& rBmpItm = (XFillBitmapItem&)p3DObj->GetMergedItem( XATTR_FILLBITMAP );
438*cdf0e10cSrcweir                         const XOBitmap& rXOBmp = rBmpItm.GetBitmapValue();
439*cdf0e10cSrcweir                         aFillBmp = rXOBmp.GetBitmap();
440*cdf0e10cSrcweir                         Size aLogicalSize = aFillBmp.GetPrefSize();
441*cdf0e10cSrcweir                         if ( aFillBmp.GetPrefMapMode() == MAP_PIXEL )
442*cdf0e10cSrcweir                             aLogicalSize = Application::GetDefaultDevice()->PixelToLogic( aLogicalSize, MAP_100TH_MM );
443*cdf0e10cSrcweir                         else
444*cdf0e10cSrcweir                             aLogicalSize = OutputDevice::LogicToLogic( aLogicalSize, aFillBmp.GetPrefMapMode(), MAP_100TH_MM );
445*cdf0e10cSrcweir                         aLogicalSize.Width()  *= 5;         ;//             :-(     nice scaling, look at engine3d/obj3d.cxx
446*cdf0e10cSrcweir                         aLogicalSize.Height() *= 5;
447*cdf0e10cSrcweir                         aFillBmp.SetPrefSize( aLogicalSize );
448*cdf0e10cSrcweir                         aFillBmp.SetPrefMapMode( MAP_100TH_MM );
449*cdf0e10cSrcweir                         p3DObj->SetMergedItem( XFillBitmapItem( String(), aFillBmp ) );
450*cdf0e10cSrcweir                     }
451*cdf0e10cSrcweir                     else
452*cdf0e10cSrcweir                     {
453*cdf0e10cSrcweir                         if ( aSnapRect != aBoundRect )
454*cdf0e10cSrcweir                         {
455*cdf0e10cSrcweir                             const XFillBitmapItem& rBmpItm = (XFillBitmapItem&)p3DObj->GetMergedItem( XATTR_FILLBITMAP );
456*cdf0e10cSrcweir                             const XOBitmap& rXOBmp = rBmpItm.GetBitmapValue();
457*cdf0e10cSrcweir                             aFillBmp = rXOBmp.GetBitmap();
458*cdf0e10cSrcweir                             Size aBmpSize( aFillBmp.GetSizePixel() );
459*cdf0e10cSrcweir                             double fXScale = (double)aBoundRect.GetWidth() / (double)aSnapRect.GetWidth();
460*cdf0e10cSrcweir                             double fYScale = (double)aBoundRect.GetHeight() / (double)aSnapRect.GetHeight();
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir                             Point aPt( (sal_Int32)( (double)( aBoundRect.Left() - aSnapRect.Left() )* (double)aBmpSize.Width() / (double)aSnapRect.GetWidth() ),
463*cdf0e10cSrcweir                                                 (sal_Int32)( (double)( aBoundRect.Top() - aSnapRect.Top() ) * (double)aBmpSize.Height() / (double)aSnapRect.GetHeight() ) );
464*cdf0e10cSrcweir                             Size aSize( (sal_Int32)( aBmpSize.Width() * fXScale ),
465*cdf0e10cSrcweir                                                     (sal_Int32)( aBmpSize.Height() * fYScale ) );
466*cdf0e10cSrcweir                             Rectangle aCropRect( aPt, aSize );
467*cdf0e10cSrcweir                             aFillBmp.Crop( aCropRect );
468*cdf0e10cSrcweir                             p3DObj->SetMergedItem( XFillBitmapItem( String(), aFillBmp ) );
469*cdf0e10cSrcweir                         }
470*cdf0e10cSrcweir                     }
471*cdf0e10cSrcweir                     pScene->Insert3DObj( p3DObj );
472*cdf0e10cSrcweir                     p3DObj = new E3dExtrudeObj( a3DDefaultAttr, aPolyPoly, fDepth );
473*cdf0e10cSrcweir                     p3DObj->NbcSetLayer( pShape2d->GetLayer() );
474*cdf0e10cSrcweir                     p3DObj->SetMergedItemSet( aSet );
475*cdf0e10cSrcweir                     if ( bUseExtrusionColor )
476*cdf0e10cSrcweir                         p3DObj->SetMergedItem( XFillColorItem( String(), ((XSecondaryFillColorItem&)pCustomShape->GetMergedItem( XATTR_SECONDARYFILLCOLOR )).GetColorValue() ) );
477*cdf0e10cSrcweir                     p3DObj->SetMergedItem( XFillStyleItem( XFILL_SOLID ) );
478*cdf0e10cSrcweir                     p3DObj->SetMergedItem( Svx3DCloseFrontItem( sal_False ) );
479*cdf0e10cSrcweir                     p3DObj->SetMergedItem( Svx3DCloseBackItem( sal_False ) );
480*cdf0e10cSrcweir                     pScene->Insert3DObj( p3DObj );
481*cdf0e10cSrcweir                     p3DObj = new E3dExtrudeObj( a3DDefaultAttr, aPolyPoly, 10 );
482*cdf0e10cSrcweir                     p3DObj->NbcSetLayer( pShape2d->GetLayer() );
483*cdf0e10cSrcweir                     p3DObj->SetMergedItemSet( aSet );
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir                     basegfx::B3DHomMatrix aFrontTransform( p3DObj->GetTransform() );
486*cdf0e10cSrcweir                     aFrontTransform.translate( 0.0, 0.0, fDepth );
487*cdf0e10cSrcweir                     p3DObj->NbcSetTransform( aFrontTransform );
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir                     if ( ( eFillStyle == XFILL_BITMAP ) && !aFillBmp.IsEmpty() )
490*cdf0e10cSrcweir                         p3DObj->SetMergedItem( XFillBitmapItem( String(), aFillBmp ) );
491*cdf0e10cSrcweir                 }
492*cdf0e10cSrcweir                 else if ( eFillStyle == XFILL_NONE )
493*cdf0e10cSrcweir                 {
494*cdf0e10cSrcweir                     XLineColorItem& rLineColor = (XLineColorItem&)p3DObj->GetMergedItem( XATTR_LINECOLOR );
495*cdf0e10cSrcweir                     p3DObj->SetMergedItem( XFillColorItem( String(), rLineColor.GetColorValue() ) );
496*cdf0e10cSrcweir                     p3DObj->SetMergedItem( Svx3DDoubleSidedItem( sal_True ) );
497*cdf0e10cSrcweir                     p3DObj->SetMergedItem( Svx3DCloseFrontItem( sal_False ) );
498*cdf0e10cSrcweir                     p3DObj->SetMergedItem( Svx3DCloseBackItem( sal_False ) );
499*cdf0e10cSrcweir                 }
500*cdf0e10cSrcweir                 pScene->Insert3DObj( p3DObj );
501*cdf0e10cSrcweir                 bSceneHasObjects = sal_True;
502*cdf0e10cSrcweir             }
503*cdf0e10cSrcweir         }
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir         if ( bSceneHasObjects ) // is the SdrObject properly converted
506*cdf0e10cSrcweir         {
507*cdf0e10cSrcweir             // then we can change the return value
508*cdf0e10cSrcweir             pRet = pScene;
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir             // Kameraeinstellungen, Perspektive ...
511*cdf0e10cSrcweir             Camera3D& rCamera = (Camera3D&)pScene->GetCamera();
512*cdf0e10cSrcweir             const basegfx::B3DRange& rVolume = pScene->GetBoundVolume();
513*cdf0e10cSrcweir             pScene->NbcSetSnapRect( aSnapRect );
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir             // InitScene replacement
516*cdf0e10cSrcweir             double fW = rVolume.getWidth();
517*cdf0e10cSrcweir             double fH = rVolume.getHeight();
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir             rCamera.SetAutoAdjustProjection( sal_False );
520*cdf0e10cSrcweir             rCamera.SetViewWindow( -fW / 2, - fH / 2, fW, fH);
521*cdf0e10cSrcweir             basegfx::B3DPoint aLookAt( 0.0, 0.0, 0.0 );
522*cdf0e10cSrcweir             basegfx::B3DPoint aCamPos( 0.0, 0.0, 100.0 );
523*cdf0e10cSrcweir             rCamera.SetDefaults( basegfx::B3DPoint( 0.0, 0.0, 100.0 ), aLookAt, 100.0 );
524*cdf0e10cSrcweir             rCamera.SetPosAndLookAt( aCamPos, aLookAt );
525*cdf0e10cSrcweir             rCamera.SetFocalLength( 1.0 );
526*cdf0e10cSrcweir             rCamera.SetProjection( eProjectionType );
527*cdf0e10cSrcweir             pScene->SetCamera( rCamera );
528*cdf0e10cSrcweir             pScene->SetRectsDirty();
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir             double fOriginX, fOriginY;
531*cdf0e10cSrcweir             GetOrigin( rGeometryItem, fOriginX, fOriginY );
532*cdf0e10cSrcweir             fOriginX = fOriginX * aSnapRect.GetWidth();
533*cdf0e10cSrcweir             fOriginY = fOriginY * aSnapRect.GetHeight();
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir             basegfx::B3DHomMatrix aNewTransform( pScene->GetTransform() );
536*cdf0e10cSrcweir             aNewTransform.translate( -aCenter.X(), aCenter.Y(), -pScene->GetBoundVolume().getDepth() );
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir             double fXRotate, fYRotate;
539*cdf0e10cSrcweir             GetRotateAngle( rGeometryItem, fXRotate, fYRotate );
540*cdf0e10cSrcweir             double fZRotate = ((SdrObjCustomShape*)pCustomShape)->GetObjectRotation() * F_PI180;
541*cdf0e10cSrcweir             if ( fZRotate != 0.0 )
542*cdf0e10cSrcweir                 aNewTransform.rotate( 0.0, 0.0, fZRotate );
543*cdf0e10cSrcweir             if ( bIsMirroredX )
544*cdf0e10cSrcweir                 aNewTransform.scale( -1.0, 1, 1 );
545*cdf0e10cSrcweir             if ( bIsMirroredY )
546*cdf0e10cSrcweir                 aNewTransform.scale( 1, -1.0, 1 );
547*cdf0e10cSrcweir             if( fYRotate != 0.0 )
548*cdf0e10cSrcweir                 aNewTransform.rotate( 0.0, -fYRotate, 0.0 );
549*cdf0e10cSrcweir             if( fXRotate != 0.0 )
550*cdf0e10cSrcweir                 aNewTransform.rotate( -fXRotate, 0.0, 0.0 );
551*cdf0e10cSrcweir             if ( eProjectionType == PR_PARALLEL )
552*cdf0e10cSrcweir             {
553*cdf0e10cSrcweir                 double fSkew, fAlpha;
554*cdf0e10cSrcweir                 GetSkew( rGeometryItem, fSkew, fAlpha );
555*cdf0e10cSrcweir                 if ( fSkew != 0.0 )
556*cdf0e10cSrcweir                 {
557*cdf0e10cSrcweir                     double fInvTanBeta( fSkew / 100.0 );
558*cdf0e10cSrcweir                     if(fInvTanBeta)
559*cdf0e10cSrcweir                     {
560*cdf0e10cSrcweir                         aNewTransform.shearXY(
561*cdf0e10cSrcweir                             fInvTanBeta * cos(fAlpha),
562*cdf0e10cSrcweir                             fInvTanBeta * sin(fAlpha));
563*cdf0e10cSrcweir                     }
564*cdf0e10cSrcweir                 }
565*cdf0e10cSrcweir                 basegfx::B3DPoint _aLookAt( 0.0, 0.0, 0.0 );
566*cdf0e10cSrcweir                 basegfx::B3DPoint _aNewCamPos( 0.0, 0.0, 25000.0 );
567*cdf0e10cSrcweir                 rCamera.SetPosAndLookAt( _aNewCamPos, _aLookAt );
568*cdf0e10cSrcweir                 pScene->SetCamera( rCamera );
569*cdf0e10cSrcweir             }
570*cdf0e10cSrcweir             else
571*cdf0e10cSrcweir             {
572*cdf0e10cSrcweir                 aNewTransform.translate( -fOriginX, fOriginY, 0.0 );
573*cdf0e10cSrcweir                 // now set correct camera position
574*cdf0e10cSrcweir                 const rtl::OUString sViewPoint( RTL_CONSTASCII_USTRINGPARAM ( "ViewPoint" ) );
575*cdf0e10cSrcweir                 drawing::Position3D aViewPointDefault( 3472, -3472, 25000 );
576*cdf0e10cSrcweir                 drawing::Position3D aViewPoint( GetPosition3D( rGeometryItem, sViewPoint, aViewPointDefault, pMap ) );
577*cdf0e10cSrcweir                 double fViewPointX = aViewPoint.PositionX;
578*cdf0e10cSrcweir                 double fViewPointY = aViewPoint.PositionY;
579*cdf0e10cSrcweir                 double fViewPointZ = aViewPoint.PositionZ;
580*cdf0e10cSrcweir                 basegfx::B3DPoint _aLookAt( fViewPointX, -fViewPointY, 0.0 );
581*cdf0e10cSrcweir                 basegfx::B3DPoint aNewCamPos( fViewPointX, -fViewPointY, fViewPointZ );
582*cdf0e10cSrcweir                 rCamera.SetPosAndLookAt( aNewCamPos, _aLookAt );
583*cdf0e10cSrcweir                 pScene->SetCamera( rCamera );
584*cdf0e10cSrcweir             }
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir             pScene->NbcSetTransform( aNewTransform );
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir             ///////////
589*cdf0e10cSrcweir             // light //
590*cdf0e10cSrcweir             ///////////
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir             const rtl::OUString sBrightness( RTL_CONSTASCII_USTRINGPARAM ( "Brightness" ) );
593*cdf0e10cSrcweir             double fAmbientIntensity = GetDouble( rGeometryItem, sBrightness, 22178.0 / 655.36, NULL ) / 100.0;
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir             const rtl::OUString sFirstLightDirection( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightDirection" ) );
597*cdf0e10cSrcweir             drawing::Direction3D aFirstLightDirectionDefault( 50000, 0, 10000 );
598*cdf0e10cSrcweir             drawing::Direction3D aFirstLightDirection( GetDirection3D( rGeometryItem, sFirstLightDirection, aFirstLightDirectionDefault ) );
599*cdf0e10cSrcweir             if ( aFirstLightDirection.DirectionZ == 0.0 )
600*cdf0e10cSrcweir                 aFirstLightDirection.DirectionZ = 1.0;
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir             const rtl::OUString sFirstLightLevel( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightLevel" ) );
603*cdf0e10cSrcweir             double fLightIntensity = GetDouble( rGeometryItem, sFirstLightLevel, 43712.0 / 655.36, NULL ) / 100.0;
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir             const rtl::OUString sFirstLightHarsh( RTL_CONSTASCII_USTRINGPARAM ( "FirstLightHarsh" ) );
606*cdf0e10cSrcweir             /* sal_Bool bFirstLightHarsh = */ GetBool( rGeometryItem, sFirstLightHarsh, sal_False );
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir             const rtl::OUString sSecondLightDirection( RTL_CONSTASCII_USTRINGPARAM ( "SecondLightDirection" ) );
609*cdf0e10cSrcweir             drawing::Direction3D aSecondLightDirectionDefault( -50000, 0, 10000 );
610*cdf0e10cSrcweir             drawing::Direction3D aSecondLightDirection( GetDirection3D( rGeometryItem, sSecondLightDirection, aSecondLightDirectionDefault ) );
611*cdf0e10cSrcweir             if ( aSecondLightDirection.DirectionZ == 0.0 )
612*cdf0e10cSrcweir                 aSecondLightDirection.DirectionZ = -1;
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir             const rtl::OUString sSecondLightLevel( RTL_CONSTASCII_USTRINGPARAM ( "SecondLightLevel" ) );
615*cdf0e10cSrcweir             double fLight2Intensity = GetDouble( rGeometryItem, sSecondLightLevel, 43712.0 / 655.36, NULL ) / 100.0;
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir             const rtl::OUString sSecondLightHarsh( RTL_CONSTASCII_USTRINGPARAM ( "SecondLightHarsh" ) );
618*cdf0e10cSrcweir             const rtl::OUString sLightFace( RTL_CONSTASCII_USTRINGPARAM ( "LightFace" ) );
619*cdf0e10cSrcweir             /* sal_Bool bLight2Harsh = */ GetBool( rGeometryItem, sSecondLightHarsh, sal_False );
620*cdf0e10cSrcweir             /* sal_Bool bLightFace = */ GetBool( rGeometryItem, sLightFace, sal_False );
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir             sal_uInt16 nAmbientColor = (sal_uInt16)( fAmbientIntensity * 255.0 );
623*cdf0e10cSrcweir             if ( nAmbientColor > 255 )
624*cdf0e10cSrcweir                 nAmbientColor = 255;
625*cdf0e10cSrcweir             Color aGlobalAmbientColor( (sal_uInt8)nAmbientColor, (sal_uInt8)nAmbientColor, (sal_uInt8)nAmbientColor );
626*cdf0e10cSrcweir             pScene->GetProperties().SetObjectItem( Svx3DAmbientcolorItem( aGlobalAmbientColor ) );
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir             sal_uInt8 nSpotLight1 = (sal_uInt8)( fLightIntensity * 255.0 );
629*cdf0e10cSrcweir             basegfx::B3DVector aSpotLight1( aFirstLightDirection.DirectionX, - ( aFirstLightDirection.DirectionY ), -( aFirstLightDirection.DirectionZ ) );
630*cdf0e10cSrcweir             aSpotLight1.normalize();
631*cdf0e10cSrcweir             pScene->GetProperties().SetObjectItem( Svx3DLightOnOff1Item( sal_True ) );
632*cdf0e10cSrcweir             Color aAmbientSpot1Color( nSpotLight1, nSpotLight1, nSpotLight1 );
633*cdf0e10cSrcweir             pScene->GetProperties().SetObjectItem( Svx3DLightcolor1Item( aAmbientSpot1Color ) );
634*cdf0e10cSrcweir             pScene->GetProperties().SetObjectItem( Svx3DLightDirection1Item( aSpotLight1 ) );
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir             sal_uInt8 nSpotLight2 = (sal_uInt8)( fLight2Intensity * 255.0 );
637*cdf0e10cSrcweir             basegfx::B3DVector aSpotLight2( aSecondLightDirection.DirectionX, -aSecondLightDirection.DirectionY, -aSecondLightDirection.DirectionZ );
638*cdf0e10cSrcweir             aSpotLight2.normalize();
639*cdf0e10cSrcweir             pScene->GetProperties().SetObjectItem( Svx3DLightOnOff2Item( sal_True ) );
640*cdf0e10cSrcweir             Color aAmbientSpot2Color( nSpotLight2, nSpotLight2, nSpotLight2 );
641*cdf0e10cSrcweir             pScene->GetProperties().SetObjectItem( Svx3DLightcolor2Item( aAmbientSpot2Color ) );
642*cdf0e10cSrcweir             pScene->GetProperties().SetObjectItem( Svx3DLightDirection2Item( aSpotLight2 ) );
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir                 sal_uInt8 nSpotLight3 = 70;
645*cdf0e10cSrcweir                 basegfx::B3DVector aSpotLight3( 0.0, 0.0, 1.0 );
646*cdf0e10cSrcweir                 pScene->GetProperties().SetObjectItem( Svx3DLightOnOff3Item( sal_True ) );
647*cdf0e10cSrcweir                 Color aAmbientSpot3Color( nSpotLight3, nSpotLight3, nSpotLight3 );
648*cdf0e10cSrcweir                 pScene->GetProperties().SetObjectItem( Svx3DLightcolor3Item( aAmbientSpot3Color ) );
649*cdf0e10cSrcweir                 pScene->GetProperties().SetObjectItem( Svx3DLightDirection3Item( aSpotLight3 ) );
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir             const rtl::OUString sSpecularity( RTL_CONSTASCII_USTRINGPARAM ( "Specularity" ) );
652*cdf0e10cSrcweir             const rtl::OUString sDiffusion( RTL_CONSTASCII_USTRINGPARAM ( "Diffusion" ) );
653*cdf0e10cSrcweir             const rtl::OUString sShininess( RTL_CONSTASCII_USTRINGPARAM ( "Shininess" ) );
654*cdf0e10cSrcweir             const rtl::OUString sMetal( RTL_CONSTASCII_USTRINGPARAM ( "Metal" ) );
655*cdf0e10cSrcweir             double fSpecular = GetDouble( rGeometryItem, sSpecularity, 0, NULL ) / 100;
656*cdf0e10cSrcweir             sal_Bool bMetal = GetBool( rGeometryItem, sMetal, sal_False );
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir             Color aSpecularCol( 225,225,225 );
659*cdf0e10cSrcweir             if ( bMetal )
660*cdf0e10cSrcweir             {
661*cdf0e10cSrcweir                 aSpecularCol = Color( 200, 200, 200 );
662*cdf0e10cSrcweir                 fSpecular += 0.15;
663*cdf0e10cSrcweir             }
664*cdf0e10cSrcweir             sal_Int32 nIntensity = (sal_Int32)fSpecular * 100;
665*cdf0e10cSrcweir             if ( nIntensity > 100 )
666*cdf0e10cSrcweir                 nIntensity = 100;
667*cdf0e10cSrcweir             else if ( nIntensity < 0 )
668*cdf0e10cSrcweir                 nIntensity = 0;
669*cdf0e10cSrcweir             nIntensity = 100 - nIntensity;
670*cdf0e10cSrcweir             pScene->GetProperties().SetObjectItem( Svx3DMaterialSpecularItem( aSpecularCol ) );
671*cdf0e10cSrcweir             pScene->GetProperties().SetObjectItem( Svx3DMaterialSpecularIntensityItem( (sal_uInt16)nIntensity ) );
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir             pScene->SetLogicRect( CalculateNewSnapRect( pCustomShape, aSnapRect, aBoundRect2d, pMap ) );
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir             // removing placeholder objects
676*cdf0e10cSrcweir             std::vector< E3dCompoundObject* >::iterator aObjectListIter( aPlaceholderObjectList.begin() );
677*cdf0e10cSrcweir             while ( aObjectListIter != aPlaceholderObjectList.end() )
678*cdf0e10cSrcweir             {
679*cdf0e10cSrcweir                 pScene->Remove3DObj( *aObjectListIter );
680*cdf0e10cSrcweir                 delete *aObjectListIter++;
681*cdf0e10cSrcweir             }
682*cdf0e10cSrcweir         }
683*cdf0e10cSrcweir         else
684*cdf0e10cSrcweir             delete pScene;
685*cdf0e10cSrcweir     }
686*cdf0e10cSrcweir     return pRet;
687*cdf0e10cSrcweir }
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir Rectangle EnhancedCustomShape3d::CalculateNewSnapRect( const SdrObject* pCustomShape, const Rectangle& rSnapRect, const Rectangle& rBoundRect, const double* pMap )
690*cdf0e10cSrcweir {
691*cdf0e10cSrcweir     SdrCustomShapeGeometryItem& rGeometryItem = (SdrCustomShapeGeometryItem&)pCustomShape->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
692*cdf0e10cSrcweir     const Point aCenter( rSnapRect.Center() );
693*cdf0e10cSrcweir     double fExtrusionBackward, fExtrusionForward;
694*cdf0e10cSrcweir     GetExtrusionDepth( rGeometryItem, pMap, fExtrusionBackward, fExtrusionForward );
695*cdf0e10cSrcweir     sal_uInt32 i;
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir     // creating initial bound volume ( without rotation. skewing.and camera )
698*cdf0e10cSrcweir     basegfx::B3DPolygon aBoundVolume;
699*cdf0e10cSrcweir     const Polygon aPolygon( rBoundRect );
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir     for ( i = 0L; i < 4L; i++ )
702*cdf0e10cSrcweir     {
703*cdf0e10cSrcweir         aBoundVolume.append(basegfx::B3DPoint(aPolygon[ (sal_uInt16)i ].X() - aCenter.X(), aPolygon[ (sal_uInt16)i ].Y() - aCenter.Y(), fExtrusionForward));
704*cdf0e10cSrcweir     }
705*cdf0e10cSrcweir 
706*cdf0e10cSrcweir     for ( i = 0L; i < 4L; i++ )
707*cdf0e10cSrcweir     {
708*cdf0e10cSrcweir         aBoundVolume.append(basegfx::B3DPoint(aPolygon[ (sal_uInt16)i ].X() - aCenter.X(), aPolygon[ (sal_uInt16)i ].Y() - aCenter.Y(), fExtrusionBackward));
709*cdf0e10cSrcweir     }
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir     const rtl::OUString sRotationCenter( RTL_CONSTASCII_USTRINGPARAM ( "RotationCenter" ) );
712*cdf0e10cSrcweir     drawing::Direction3D aRotationCenterDefault( 0, 0, 0 ); // default seems to be wrong, a fractional size of shape has to be used!!
713*cdf0e10cSrcweir     drawing::Direction3D aRotationCenter( GetDirection3D( rGeometryItem, sRotationCenter, aRotationCenterDefault ) );
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir     // double XCenterInGUnits = rPropSet.GetPropertyValue( DFF_Prop_c3DRotationCenterX, 0 );
716*cdf0e10cSrcweir     // double YCenterInGUnits = rPropSet.GetPropertyValue( DFF_Prop_c3DRotationCenterY, 0 );
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir     // sal_Int32 nRotationXAxisInProz = rPropSet.GetPropertyValue( DFF_Prop_c3DRotationAxisX, 100 );
719*cdf0e10cSrcweir     // sal_Int32 nRotationYAxisInProz = rPropSet.GetPropertyValue( DFF_Prop_c3DRotationAxisY, 0 );
720*cdf0e10cSrcweir     // sal_Int32 nRotationZAxisInProz = rPropSet.GetPropertyValue( DFF_Prop_c3DRotationAxisZ, 0 );
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir     double fXRotate, fYRotate;
724*cdf0e10cSrcweir     GetRotateAngle( rGeometryItem, fXRotate, fYRotate );
725*cdf0e10cSrcweir     double fZRotate = - ((SdrObjCustomShape*)pCustomShape)->GetObjectRotation() * F_PI180;
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir     // rotating bound volume
728*cdf0e10cSrcweir     basegfx::B3DHomMatrix aMatrix;
729*cdf0e10cSrcweir     aMatrix.translate(-aRotationCenter.DirectionX, -aRotationCenter.DirectionY, -aRotationCenter.DirectionZ);
730*cdf0e10cSrcweir     if ( fZRotate != 0.0 )
731*cdf0e10cSrcweir         aMatrix.rotate( 0.0, 0.0, fZRotate );
732*cdf0e10cSrcweir     if ( ((SdrObjCustomShape*)pCustomShape)->IsMirroredX() )
733*cdf0e10cSrcweir         aMatrix.scale( -1.0, 1, 1 );
734*cdf0e10cSrcweir     if ( ((SdrObjCustomShape*)pCustomShape)->IsMirroredY() )
735*cdf0e10cSrcweir         aMatrix.scale( 1, -1.0, 1 );
736*cdf0e10cSrcweir     if( fYRotate != 0.0 )
737*cdf0e10cSrcweir         aMatrix.rotate( 0.0, fYRotate, 0.0 );
738*cdf0e10cSrcweir     if( fXRotate != 0.0 )
739*cdf0e10cSrcweir         aMatrix.rotate( -fXRotate, 0.0, 0.0 );
740*cdf0e10cSrcweir     aMatrix.translate(aRotationCenter.DirectionX, aRotationCenter.DirectionY, aRotationCenter.DirectionZ);
741*cdf0e10cSrcweir     aBoundVolume.transform(aMatrix);
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir     Transformation2D aTransformation2D( pCustomShape, rSnapRect, pMap );
744*cdf0e10cSrcweir     if ( aTransformation2D.IsParallel() )
745*cdf0e10cSrcweir         aBoundVolume = aTransformation2D.ApplySkewSettings( aBoundVolume );
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir     Polygon aTransformed( 8 );
748*cdf0e10cSrcweir     for ( i = 0L; i < 8L; i++ )
749*cdf0e10cSrcweir         aTransformed[ (sal_uInt16)i ] = aTransformation2D.Transform2D( aBoundVolume.getB3DPoint( i ) );
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir     return aTransformed.GetBoundRect();
752*cdf0e10cSrcweir }
753