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