1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
54 #include <drawinglayer/attribute/sdrlineattribute.hxx>
55 #include <drawinglayer/attribute/sdrlinestartendattribute.hxx>
56 #include <svx/xlnwtit.hxx>
57 #include <svx/xlntrit.hxx>
58 #include <svx/xfltrit.hxx>
60 #define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()
61 using namespace com::sun::star
;
62 using namespace com::sun::star::uno
;
64 const char aExtrusion
[] = "Extrusion";
68 void GetOrigin( SdrCustomShapeGeometryItem
& rItem
, double& rOriginX
, double& rOriginY
)
70 ::com::sun::star::drawing::EnhancedCustomShapeParameterPair aOriginParaPair
;
71 const OUString
sOrigin( "Origin" );
72 Any
* pAny
= rItem
.GetPropertyValueByName( OUString(aExtrusion
), sOrigin
);
73 if ( ! ( pAny
&& ( *pAny
>>= aOriginParaPair
) && ( aOriginParaPair
.First
.Value
>>= rOriginX
) && ( aOriginParaPair
.Second
.Value
>>= rOriginY
) ) )
80 void GetRotateAngle( SdrCustomShapeGeometryItem
& rItem
, double& rAngleX
, double& rAngleY
)
82 ::com::sun::star::drawing::EnhancedCustomShapeParameterPair aRotateAngleParaPair
;
83 const OUString
sRotateAngle( "RotateAngle" );
84 Any
* pAny
= rItem
.GetPropertyValueByName( OUString(aExtrusion
), sRotateAngle
);
85 if ( ! ( pAny
&& ( *pAny
>>= aRotateAngleParaPair
) && ( aRotateAngleParaPair
.First
.Value
>>= rAngleX
) && ( aRotateAngleParaPair
.Second
.Value
>>= rAngleY
) ) )
94 void GetSkew( SdrCustomShapeGeometryItem
& rItem
, double& rSkewAmount
, double& rSkewAngle
)
96 ::com::sun::star::drawing::EnhancedCustomShapeParameterPair aSkewParaPair
;
97 const OUString
sSkew( "Skew" );
98 Any
* pAny
= rItem
.GetPropertyValueByName( OUString(aExtrusion
), sSkew
);
99 if ( ! ( pAny
&& ( *pAny
>>= aSkewParaPair
) && ( aSkewParaPair
.First
.Value
>>= rSkewAmount
) && ( aSkewParaPair
.Second
.Value
>>= rSkewAngle
) ) )
104 rSkewAngle
*= F_PI180
;
107 void GetExtrusionDepth( SdrCustomShapeGeometryItem
& rItem
, const double* pMap
, double& rBackwardDepth
, double& rForwardDepth
)
109 ::com::sun::star::drawing::EnhancedCustomShapeParameterPair aDepthParaPair
;
110 double fDepth
= 0, fFraction
= 0;
111 const OUString
sDepth( "Depth" );
112 Any
* pAny
= rItem
.GetPropertyValueByName( OUString(aExtrusion
), sDepth
);
113 if ( pAny
&& ( *pAny
>>= aDepthParaPair
) && ( aDepthParaPair
.First
.Value
>>= fDepth
) && ( aDepthParaPair
.Second
.Value
>>= fFraction
) )
115 rForwardDepth
= fDepth
* fFraction
;
116 rBackwardDepth
= fDepth
- rForwardDepth
;
120 rBackwardDepth
= 1270;
126 rBackwardDepth
*= fMap
;
127 rForwardDepth
*= fMap
;
131 double GetDouble( SdrCustomShapeGeometryItem
& rItem
, const OUString
& rPropertyName
, double fDefault
, const double* pMap
)
133 double fRetValue
= fDefault
;
134 Any
* pAny
= rItem
.GetPropertyValueByName( OUString(aExtrusion
), rPropertyName
);
142 drawing::ShadeMode
GetShadeMode( SdrCustomShapeGeometryItem
& rItem
, const drawing::ShadeMode eDefault
)
144 drawing::ShadeMode
eRet( eDefault
);
145 const OUString
sShadeMode( "ShadeMode" );
146 Any
* pAny
= rItem
.GetPropertyValueByName( OUString(aExtrusion
), sShadeMode
);
152 sal_Bool
GetBool( SdrCustomShapeGeometryItem
& rItem
, const OUString
& rPropertyName
, const sal_Bool bDefault
)
154 sal_Bool bRetValue
= bDefault
;
155 const Any
* pAny
= rItem
.GetPropertyValueByName( OUString(aExtrusion
), rPropertyName
);
161 drawing::Position3D
GetPosition3D( SdrCustomShapeGeometryItem
& rItem
, const OUString
& rPropertyName
,
162 const drawing::Position3D
& rDefault
, const double* pMap
)
164 drawing::Position3D
aRetValue( rDefault
);
165 const Any
* pAny
= rItem
.GetPropertyValueByName( OUString(aExtrusion
), rPropertyName
);
170 aRetValue
.PositionX
*= *pMap
;
171 aRetValue
.PositionY
*= *pMap
;
172 aRetValue
.PositionZ
*= *pMap
;
177 drawing::Direction3D
GetDirection3D( SdrCustomShapeGeometryItem
& rItem
, const OUString
& rPropertyName
, const drawing::Direction3D
& rDefault
)
179 drawing::Direction3D
aRetValue( rDefault
);
180 const Any
* pAny
= rItem
.GetPropertyValueByName( OUString(aExtrusion
), rPropertyName
);
188 EnhancedCustomShape3d::Transformation2D::Transformation2D( const SdrObject
* pCustomShape
, const Rectangle
& /*rBoundRect*/, const double *pM
)
189 : aCenter( pCustomShape
->GetSnapRect().Center() )
190 , eProjectionMode( drawing::ProjectionMode_PARALLEL
)
193 SdrCustomShapeGeometryItem
& rGeometryItem
= (SdrCustomShapeGeometryItem
&)pCustomShape
->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
);
194 const OUString
sProjectionMode( "ProjectionMode" );
195 Any
* pAny
= rGeometryItem
.GetPropertyValueByName( OUString(aExtrusion
), sProjectionMode
);
197 *pAny
>>= eProjectionMode
;
199 if ( eProjectionMode
== drawing::ProjectionMode_PARALLEL
)
200 GetSkew( rGeometryItem
, fSkew
, fSkewAngle
);
204 GetOrigin( rGeometryItem
, fOriginX
, fOriginY
);
205 fOriginX
= fOriginX
* pCustomShape
->GetLogicRect().GetWidth();
206 fOriginY
= fOriginY
* pCustomShape
->GetLogicRect().GetHeight();
208 const OUString
sViewPoint( "ViewPoint" );
209 drawing::Position3D
aViewPointDefault( 3472, -3472, 25000 );
210 drawing::Position3D
aViewPoint( GetPosition3D( rGeometryItem
, sViewPoint
, aViewPointDefault
, pMap
) );
211 fViewPoint
.setX(aViewPoint
.PositionX
);
212 fViewPoint
.setY(aViewPoint
.PositionY
);
213 fViewPoint
.setZ(-aViewPoint
.PositionZ
);
217 basegfx::B3DPolygon
EnhancedCustomShape3d::Transformation2D::ApplySkewSettings( const basegfx::B3DPolygon
& rPoly3D
) const
219 basegfx::B3DPolygon aRetval
;
222 for ( j
= 0L; j
< rPoly3D
.count(); j
++ )
224 const basegfx::B3DPoint
aPoint(rPoly3D
.getB3DPoint(j
));
225 double fDepth(-( aPoint
.getZ() * fSkew
) / 100.0);
226 aRetval
.append(basegfx::B3DPoint(
227 aPoint
.getX() + (fDepth
* cos( fSkewAngle
)),
228 aPoint
.getY() - (fDepth
* sin( fSkewAngle
)),
235 Point
EnhancedCustomShape3d::Transformation2D::Transform2D( const basegfx::B3DPoint
& rPoint3D
) const
238 if ( eProjectionMode
== drawing::ProjectionMode_PARALLEL
)
240 aPoint2D
.X() = (sal_Int32
)rPoint3D
.getX();
241 aPoint2D
.Y() = (sal_Int32
)rPoint3D
.getY();
245 double fX
= rPoint3D
.getX() - fOriginX
;
246 double fY
= rPoint3D
.getY() - fOriginY
;
247 double f
= ( fZScreen
- fViewPoint
.getZ() ) / ( rPoint3D
.getZ() - fViewPoint
.getZ() );
248 aPoint2D
.X() = (sal_Int32
)(( fX
- fViewPoint
.getX() ) * f
+ fViewPoint
.getX() + fOriginX
);
249 aPoint2D
.Y() = (sal_Int32
)(( fY
- fViewPoint
.getY() ) * f
+ fViewPoint
.getY() + fOriginY
);
251 aPoint2D
.Move( aCenter
.X(), aCenter
.Y() );
255 bool EnhancedCustomShape3d::Transformation2D::IsParallel() const
257 return eProjectionMode
== com::sun::star::drawing::ProjectionMode_PARALLEL
;
260 SdrObject
* EnhancedCustomShape3d::Create3DObject( const SdrObject
* pShape2d
, const SdrObject
* pCustomShape
)
262 SdrObject
* pRet
= NULL
;
263 SdrModel
* pModel
= pCustomShape
->GetModel();
264 SdrCustomShapeGeometryItem
& rGeometryItem
= (SdrCustomShapeGeometryItem
&)pCustomShape
->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
);
266 double fMap
, *pMap
= NULL
;
270 Fraction
aFraction( pModel
->GetScaleFraction() );
271 if ( ( aFraction
.GetNumerator() ) != 1 || ( aFraction
.GetDenominator() != 1 ) )
273 fMap
*= aFraction
.GetNumerator();
274 fMap
/= aFraction
.GetDenominator();
277 if ( pModel
->GetScaleUnit() != MAP_100TH_MM
)
279 DBG_ASSERT( pModel
->GetScaleUnit() == MAP_TWIP
, "EnhancedCustomShape3d::Current MapMode is Unsupported" );
280 fMap
*= 1440.0 / 2540.0;
284 if ( GetBool( rGeometryItem
, aExtrusion
, sal_False
) )
286 sal_Bool bIsMirroredX
= ((SdrObjCustomShape
*)pCustomShape
)->IsMirroredX();
287 sal_Bool bIsMirroredY
= ((SdrObjCustomShape
*)pCustomShape
)->IsMirroredY();
288 Rectangle
aSnapRect( pCustomShape
->GetLogicRect() );
289 long nObjectRotation
= pCustomShape
->GetRotateAngle();
290 if ( nObjectRotation
)
292 double a
= ( 36000 - nObjectRotation
) * nPi180
;
293 long dx
= aSnapRect
.Right() - aSnapRect
.Left();
294 long dy
= aSnapRect
.Bottom()- aSnapRect
.Top();
295 Point
aP( aSnapRect
.TopLeft() );
296 RotatePoint( aP
, pCustomShape
->GetSnapRect().Center(), sin( a
), cos( a
) );
297 aSnapRect
.Left() = aP
.X();
298 aSnapRect
.Top() = aP
.Y();
299 aSnapRect
.Right() = aSnapRect
.Left() + dx
;
300 aSnapRect
.Bottom() = aSnapRect
.Top() + dy
;
302 Point
aCenter( aSnapRect
.Center() );
304 SfxItemSet
aSet( pCustomShape
->GetMergedItemSet() );
306 //SJ: vertical writing is not required, by removing this item no outliner is created
307 aSet
.ClearItem( SDRATTR_TEXTDIRECTION
);
309 // #i105323# For 3D AutoShapes, the shadow attribute has to be applied to each
310 // created visualisation helper model shape individually. The shadow itself
311 // will then be rendered from the 3D renderer correctly for the whole 3D scene
312 // (and thus behind all objects of which the visualisation may be built). So,
313 // dio NOT remove it from the ItemSet here.
314 // aSet.ClearItem(SDRATTR_SHADOW);
316 std::vector
< E3dCompoundObject
* > aPlaceholderObjectList
;
318 double fExtrusionBackward
, fExtrusionForward
;
319 GetExtrusionDepth( rGeometryItem
, pMap
, fExtrusionBackward
, fExtrusionForward
);
320 double fDepth
= fExtrusionBackward
- fExtrusionForward
;
324 drawing::ProjectionMode
eProjectionMode( drawing::ProjectionMode_PARALLEL
);
325 const OUString
sProjectionMode( "ProjectionMode" );
326 Any
* pAny
= rGeometryItem
.GetPropertyValueByName( aExtrusion
, sProjectionMode
);
328 *pAny
>>= eProjectionMode
;
329 ProjectionType
eProjectionType( eProjectionMode
== drawing::ProjectionMode_PARALLEL
? PR_PARALLEL
: PR_PERSPECTIVE
);
330 // pShape2d Convert in scenes which include 3D Objects
331 E3dDefaultAttributes a3DDefaultAttr
;
332 a3DDefaultAttr
.SetDefaultLatheCharacterMode( sal_True
);
333 a3DDefaultAttr
.SetDefaultExtrudeCharacterMode( sal_True
);
335 E3dScene
* pScene
= new E3dPolyScene( a3DDefaultAttr
);
337 bool bSceneHasObjects ( false );
338 bool bUseTwoFillStyles( false );
340 drawing::ShadeMode
eShadeMode( GetShadeMode( rGeometryItem
, drawing::ShadeMode_FLAT
) );
341 const OUString
aExtrusionColor( "Color" );
342 sal_Bool bUseExtrusionColor
= GetBool( rGeometryItem
, aExtrusionColor
, sal_False
);
344 XFillStyle
eFillStyle( ITEMVALUE( aSet
, XATTR_FILLSTYLE
, XFillStyleItem
) );
345 pScene
->GetProperties().SetObjectItem( Svx3DShadeModeItem( 0 ) );
346 aSet
.Put( Svx3DPercentDiagonalItem( 0 ) );
347 aSet
.Put( Svx3DTextureModeItem( 1 ) );
348 aSet
.Put( Svx3DNormalsKindItem( 1 ) );
350 if ( eShadeMode
== drawing::ShadeMode_DRAFT
)
352 aSet
.Put( XLineStyleItem( XLINE_SOLID
) );
353 aSet
.Put( XFillStyleItem ( XFILL_NONE
) );
354 aSet
.Put( Svx3DDoubleSidedItem( sal_True
) );
358 aSet
.Put( XLineStyleItem( XLINE_NONE
) );
359 if ( eFillStyle
== XFILL_NONE
)
360 aSet
.Put( XFillStyleItem( XFILL_SOLID
) );
361 else if ( ( eFillStyle
== XFILL_BITMAP
) || ( eFillStyle
== XFILL_GRADIENT
) || bUseExtrusionColor
)
362 bUseTwoFillStyles
= true;
365 // If shapes are mirrored once (mirroring two times correct geometry again)
366 // double-sided at the object and two-sided-lighting at the scene need to be set.
367 if((bIsMirroredX
&& !bIsMirroredY
) || (!bIsMirroredX
&& bIsMirroredY
))
369 aSet
.Put( Svx3DDoubleSidedItem( sal_True
) );
370 pScene
->GetProperties().SetObjectItem( Svx3DTwoSidedLightingItem( sal_True
) );
374 Rectangle aBoundRect2d
;
375 SdrObjListIter
aIter( *pShape2d
, IM_DEEPNOGROUPS
);
376 const bool bMultipleSubObjects(aIter
.Count() > 1);
378 while( aIter
.IsMore() )
380 const SdrObject
* pNext
= aIter
.Next();
381 bool bIsPlaceholderObject
= (((XFillStyleItem
&)pNext
->GetMergedItem( XATTR_FILLSTYLE
)).GetValue() == XFILL_NONE
)
382 && (((XLineStyleItem
&)pNext
->GetMergedItem( XATTR_LINESTYLE
)).GetValue() == XLINE_NONE
);
383 basegfx::B2DPolyPolygon aPolyPoly
;
384 SfxItemSet
aLocalSet(aSet
);
385 XFillStyle
aLocalFillStyle(eFillStyle
);
387 if ( pNext
->ISA( SdrPathObj
) )
389 const SfxItemSet
& rSet
= pNext
->GetMergedItemSet();
390 bool bNeedToConvertToContour(false);
392 // do conversion only for single line objects; for all others a fill and a
393 // line object get created. When we have fill, we want no line. That line has
394 // always been there, but since it was never converted to contour, it kept
395 // invisible (all this 'hidden' logic should be migrated to primitives).
396 if(!bMultipleSubObjects
)
398 const XFillStyle
eStyle(((XFillStyleItem
&)(rSet
.Get(XATTR_FILLSTYLE
))).GetValue());
400 if(XFILL_NONE
== eStyle
)
402 const drawinglayer::attribute::SdrLineAttribute
aLine(
403 drawinglayer::primitive2d::createNewSdrLineAttribute(rSet
));
405 bNeedToConvertToContour
= (0.0 < aLine
.getWidth() || 0.0 != aLine
.getFullDotDashLen());
407 if(!bNeedToConvertToContour
&& !aLine
.isDefault())
409 const drawinglayer::attribute::SdrLineStartEndAttribute
aLineStartEnd(
410 drawinglayer::primitive2d::createNewSdrLineStartEndAttribute(rSet
, aLine
.getWidth()));
412 if((aLineStartEnd
.getStartWidth() && aLineStartEnd
.isStartActive())
413 || (aLineStartEnd
.getEndWidth() && aLineStartEnd
.isEndActive()))
415 bNeedToConvertToContour
= true;
421 if(bNeedToConvertToContour
)
423 SdrObject
* pNewObj
= pNext
->ConvertToContourObj(const_cast< SdrObject
* >(pNext
));
424 SdrPathObj
* pNewPathObj
= dynamic_cast< SdrPathObj
* >(pNewObj
);
428 aPolyPoly
= pNewPathObj
->GetPathPoly();
430 if(aPolyPoly
.isClosed())
432 // correct item properties from line to fill style
433 if(eShadeMode
== drawing::ShadeMode_DRAFT
)
435 // for draft, create wireframe with fixed line width
436 aLocalSet
.Put(XLineStyleItem(XLINE_SOLID
));
437 aLocalSet
.Put(XLineWidthItem(40));
438 aLocalFillStyle
= XFILL_NONE
;
442 // switch from line to fill, copy line attr to fill attr (color, transparence)
443 aLocalSet
.Put(XLineWidthItem(0));
444 aLocalSet
.Put(XLineStyleItem(XLINE_NONE
));
445 aLocalSet
.Put(XFillColorItem(XubString(), ((const XLineColorItem
&)(aLocalSet
.Get(XATTR_LINECOLOR
))).GetColorValue()));
446 aLocalSet
.Put(XFillStyleItem(XFILL_SOLID
));
447 aLocalSet
.Put(XFillTransparenceItem(((const XLineTransparenceItem
&)(aLocalSet
.Get(XATTR_LINETRANSPARENCE
))).GetValue()));
448 aLocalFillStyle
= XFILL_SOLID
;
453 // correct item properties to hairlines
454 aLocalSet
.Put(XLineWidthItem(0));
455 aLocalSet
.Put(XLineStyleItem(XLINE_SOLID
));
459 SdrObject::Free(pNewObj
);
463 aPolyPoly
= ((SdrPathObj
*)pNext
)->GetPathPoly();
468 SdrObject
* pNewObj
= pNext
->ConvertToPolyObj( sal_False
, sal_False
);
469 SdrPathObj
* pPath
= PTR_CAST( SdrPathObj
, pNewObj
);
471 aPolyPoly
= pPath
->GetPathPoly();
472 SdrObject::Free( pNewObj
);
475 if( aPolyPoly
.count() )
477 if(aPolyPoly
.areControlPointsUsed())
479 aPolyPoly
= basegfx::tools::adaptiveSubdivideByAngle(aPolyPoly
);
482 const basegfx::B2DRange
aTempRange(basegfx::tools::getRange(aPolyPoly
));
483 const Rectangle
aBoundRect(basegfx::fround(aTempRange
.getMinX()), basegfx::fround(aTempRange
.getMinY()), basegfx::fround(aTempRange
.getMaxX()), basegfx::fround(aTempRange
.getMaxY()));
484 aBoundRect2d
.Union( aBoundRect
);
486 E3dCompoundObject
* p3DObj
= new E3dExtrudeObj( a3DDefaultAttr
, aPolyPoly
, bUseTwoFillStyles
? 10 : fDepth
);
487 p3DObj
->NbcSetLayer( pShape2d
->GetLayer() );
488 p3DObj
->SetMergedItemSet( aLocalSet
);
489 if ( bIsPlaceholderObject
)
490 aPlaceholderObjectList
.push_back( p3DObj
);
491 else if ( bUseTwoFillStyles
)
494 sal_Bool bFillBmpTile
= ((XFillBmpTileItem
&)p3DObj
->GetMergedItem( XATTR_FILLBMP_TILE
)).GetValue();
497 const XFillBitmapItem
& rBmpItm
= (XFillBitmapItem
&)p3DObj
->GetMergedItem(XATTR_FILLBITMAP
);
498 aFillBmp
= rBmpItm
.GetGraphicObject().GetGraphic().GetBitmapEx();
499 Size aLogicalSize
= aFillBmp
.GetPrefSize();
500 if ( aFillBmp
.GetPrefMapMode() == MAP_PIXEL
)
501 aLogicalSize
= Application::GetDefaultDevice()->PixelToLogic( aLogicalSize
, MAP_100TH_MM
);
503 aLogicalSize
= OutputDevice::LogicToLogic( aLogicalSize
, aFillBmp
.GetPrefMapMode(), MAP_100TH_MM
);
504 aLogicalSize
.Width() *= 5; ;// :-( nice scaling, look at engine3d/obj3d.cxx
505 aLogicalSize
.Height() *= 5;
506 aFillBmp
.SetPrefSize( aLogicalSize
);
507 aFillBmp
.SetPrefMapMode( MAP_100TH_MM
);
508 p3DObj
->SetMergedItem(XFillBitmapItem(String(), Graphic(aFillBmp
)));
512 if ( aSnapRect
!= aBoundRect
)
514 const XFillBitmapItem
& rBmpItm
= (XFillBitmapItem
&)p3DObj
->GetMergedItem(XATTR_FILLBITMAP
);
515 aFillBmp
= rBmpItm
.GetGraphicObject().GetGraphic().GetBitmapEx();
516 Size
aBmpSize( aFillBmp
.GetSizePixel() );
517 double fXScale
= (double)aBoundRect
.GetWidth() / (double)aSnapRect
.GetWidth();
518 double fYScale
= (double)aBoundRect
.GetHeight() / (double)aSnapRect
.GetHeight();
520 Point
aPt( (sal_Int32
)( (double)( aBoundRect
.Left() - aSnapRect
.Left() )* (double)aBmpSize
.Width() / (double)aSnapRect
.GetWidth() ),
521 (sal_Int32
)( (double)( aBoundRect
.Top() - aSnapRect
.Top() ) * (double)aBmpSize
.Height() / (double)aSnapRect
.GetHeight() ) );
522 Size
aSize( (sal_Int32
)( aBmpSize
.Width() * fXScale
),
523 (sal_Int32
)( aBmpSize
.Height() * fYScale
) );
524 Rectangle
aCropRect( aPt
, aSize
);
525 aFillBmp
.Crop( aCropRect
);
526 p3DObj
->SetMergedItem(XFillBitmapItem(String(), Graphic(aFillBmp
)));
529 pScene
->Insert3DObj( p3DObj
);
530 p3DObj
= new E3dExtrudeObj( a3DDefaultAttr
, aPolyPoly
, fDepth
);
531 p3DObj
->NbcSetLayer( pShape2d
->GetLayer() );
532 p3DObj
->SetMergedItemSet( aLocalSet
);
533 if ( bUseExtrusionColor
)
534 p3DObj
->SetMergedItem( XFillColorItem( String(), ((XSecondaryFillColorItem
&)pCustomShape
->GetMergedItem( XATTR_SECONDARYFILLCOLOR
)).GetColorValue() ) );
535 p3DObj
->SetMergedItem( XFillStyleItem( XFILL_SOLID
) );
536 p3DObj
->SetMergedItem( Svx3DCloseFrontItem( sal_False
) );
537 p3DObj
->SetMergedItem( Svx3DCloseBackItem( sal_False
) );
538 pScene
->Insert3DObj( p3DObj
);
539 p3DObj
= new E3dExtrudeObj( a3DDefaultAttr
, aPolyPoly
, 10 );
540 p3DObj
->NbcSetLayer( pShape2d
->GetLayer() );
541 p3DObj
->SetMergedItemSet( aLocalSet
);
543 basegfx::B3DHomMatrix
aFrontTransform( p3DObj
->GetTransform() );
544 aFrontTransform
.translate( 0.0, 0.0, fDepth
);
545 p3DObj
->NbcSetTransform( aFrontTransform
);
547 if ( ( aLocalFillStyle
== XFILL_BITMAP
) && !aFillBmp
.IsEmpty() )
549 p3DObj
->SetMergedItem(XFillBitmapItem(String(), Graphic(aFillBmp
)));
552 else if ( aLocalFillStyle
== XFILL_NONE
)
554 XLineColorItem
& rLineColor
= (XLineColorItem
&)p3DObj
->GetMergedItem( XATTR_LINECOLOR
);
555 p3DObj
->SetMergedItem( XFillColorItem( String(), rLineColor
.GetColorValue() ) );
556 p3DObj
->SetMergedItem( Svx3DDoubleSidedItem( sal_True
) );
557 p3DObj
->SetMergedItem( Svx3DCloseFrontItem( sal_False
) );
558 p3DObj
->SetMergedItem( Svx3DCloseBackItem( sal_False
) );
560 pScene
->Insert3DObj( p3DObj
);
561 bSceneHasObjects
= true;
565 if ( bSceneHasObjects
) // is the SdrObject properly converted
567 // then we can change the return value
570 // Camera settings, Perspective ...
571 Camera3D
& rCamera
= (Camera3D
&)pScene
->GetCamera();
572 const basegfx::B3DRange
& rVolume
= pScene
->GetBoundVolume();
573 pScene
->NbcSetSnapRect( aSnapRect
);
575 // InitScene replacement
576 double fW
= rVolume
.getWidth();
577 double fH
= rVolume
.getHeight();
579 rCamera
.SetAutoAdjustProjection( sal_False
);
580 rCamera
.SetViewWindow( -fW
/ 2, - fH
/ 2, fW
, fH
);
581 basegfx::B3DPoint
aLookAt( 0.0, 0.0, 0.0 );
582 basegfx::B3DPoint
aCamPos( 0.0, 0.0, 100.0 );
583 rCamera
.SetDefaults( basegfx::B3DPoint( 0.0, 0.0, 100.0 ), aLookAt
, 100.0 );
584 rCamera
.SetPosAndLookAt( aCamPos
, aLookAt
);
585 rCamera
.SetFocalLength( 1.0 );
586 rCamera
.SetProjection( eProjectionType
);
587 pScene
->SetCamera( rCamera
);
588 pScene
->SetRectsDirty();
590 double fOriginX
, fOriginY
;
591 GetOrigin( rGeometryItem
, fOriginX
, fOriginY
);
592 fOriginX
= fOriginX
* aSnapRect
.GetWidth();
593 fOriginY
= fOriginY
* aSnapRect
.GetHeight();
595 basegfx::B3DHomMatrix
aNewTransform( pScene
->GetTransform() );
596 aNewTransform
.translate( -aCenter
.X(), aCenter
.Y(), -pScene
->GetBoundVolume().getDepth() );
598 double fXRotate
, fYRotate
;
599 GetRotateAngle( rGeometryItem
, fXRotate
, fYRotate
);
600 double fZRotate
= ((SdrObjCustomShape
*)pCustomShape
)->GetObjectRotation() * F_PI180
;
601 if ( fZRotate
!= 0.0 )
602 aNewTransform
.rotate( 0.0, 0.0, fZRotate
);
604 aNewTransform
.scale( -1.0, 1, 1 );
606 aNewTransform
.scale( 1, -1.0, 1 );
607 if( fYRotate
!= 0.0 )
608 aNewTransform
.rotate( 0.0, -fYRotate
, 0.0 );
609 if( fXRotate
!= 0.0 )
610 aNewTransform
.rotate( -fXRotate
, 0.0, 0.0 );
611 if ( eProjectionType
== PR_PARALLEL
)
613 double fSkew
, fAlpha
;
614 GetSkew( rGeometryItem
, fSkew
, fAlpha
);
617 double fInvTanBeta( fSkew
/ 100.0 );
620 aNewTransform
.shearXY(
621 fInvTanBeta
* cos(fAlpha
),
622 fInvTanBeta
* sin(fAlpha
));
625 basegfx::B3DPoint
_aLookAt( 0.0, 0.0, 0.0 );
626 basegfx::B3DPoint
_aNewCamPos( 0.0, 0.0, 25000.0 );
627 rCamera
.SetPosAndLookAt( _aNewCamPos
, _aLookAt
);
628 pScene
->SetCamera( rCamera
);
632 aNewTransform
.translate( -fOriginX
, fOriginY
, 0.0 );
633 // now set correct camera position
634 const OUString
sViewPoint( "ViewPoint" );
635 drawing::Position3D
aViewPointDefault( 3472, -3472, 25000 );
636 drawing::Position3D
aViewPoint( GetPosition3D( rGeometryItem
, sViewPoint
, aViewPointDefault
, pMap
) );
637 double fViewPointX
= aViewPoint
.PositionX
;
638 double fViewPointY
= aViewPoint
.PositionY
;
639 double fViewPointZ
= aViewPoint
.PositionZ
;
640 basegfx::B3DPoint
_aLookAt( fViewPointX
, -fViewPointY
, 0.0 );
641 basegfx::B3DPoint
aNewCamPos( fViewPointX
, -fViewPointY
, fViewPointZ
);
642 rCamera
.SetPosAndLookAt( aNewCamPos
, _aLookAt
);
643 pScene
->SetCamera( rCamera
);
646 pScene
->NbcSetTransform( aNewTransform
);
652 const OUString
sBrightness( "Brightness" );
653 double fAmbientIntensity
= GetDouble( rGeometryItem
, sBrightness
, 22178.0 / 655.36, NULL
) / 100.0;
656 const OUString
sFirstLightDirection( "FirstLightDirection" );
657 drawing::Direction3D
aFirstLightDirectionDefault( 50000, 0, 10000 );
658 drawing::Direction3D
aFirstLightDirection( GetDirection3D( rGeometryItem
, sFirstLightDirection
, aFirstLightDirectionDefault
) );
659 if ( aFirstLightDirection
.DirectionZ
== 0.0 )
660 aFirstLightDirection
.DirectionZ
= 1.0;
662 const OUString
sFirstLightLevel( "FirstLightLevel" );
663 double fLightIntensity
= GetDouble( rGeometryItem
, sFirstLightLevel
, 43712.0 / 655.36, NULL
) / 100.0;
665 const OUString
sFirstLightHarsh( "FirstLightHarsh" );
666 /* sal_Bool bFirstLightHarsh = */ GetBool( rGeometryItem
, sFirstLightHarsh
, sal_False
);
668 const OUString
sSecondLightDirection( "SecondLightDirection" );
669 drawing::Direction3D
aSecondLightDirectionDefault( -50000, 0, 10000 );
670 drawing::Direction3D
aSecondLightDirection( GetDirection3D( rGeometryItem
, sSecondLightDirection
, aSecondLightDirectionDefault
) );
671 if ( aSecondLightDirection
.DirectionZ
== 0.0 )
672 aSecondLightDirection
.DirectionZ
= -1;
674 const OUString
sSecondLightLevel( "SecondLightLevel" );
675 double fLight2Intensity
= GetDouble( rGeometryItem
, sSecondLightLevel
, 43712.0 / 655.36, NULL
) / 100.0;
677 const OUString
sSecondLightHarsh( "SecondLightHarsh" );
678 const OUString
sLightFace( "LightFace" );
679 /* sal_Bool bLight2Harsh = */ GetBool( rGeometryItem
, sSecondLightHarsh
, sal_False
);
680 /* sal_Bool bLightFace = */ GetBool( rGeometryItem
, sLightFace
, sal_False
);
682 sal_uInt16 nAmbientColor
= (sal_uInt16
)( fAmbientIntensity
* 255.0 );
683 if ( nAmbientColor
> 255 )
685 Color
aGlobalAmbientColor( (sal_uInt8
)nAmbientColor
, (sal_uInt8
)nAmbientColor
, (sal_uInt8
)nAmbientColor
);
686 pScene
->GetProperties().SetObjectItem( Svx3DAmbientcolorItem( aGlobalAmbientColor
) );
688 sal_uInt8 nSpotLight1
= (sal_uInt8
)( fLightIntensity
* 255.0 );
689 basegfx::B3DVector
aSpotLight1( aFirstLightDirection
.DirectionX
, - ( aFirstLightDirection
.DirectionY
), -( aFirstLightDirection
.DirectionZ
) );
690 aSpotLight1
.normalize();
691 pScene
->GetProperties().SetObjectItem( Svx3DLightOnOff1Item( sal_True
) );
692 Color
aAmbientSpot1Color( nSpotLight1
, nSpotLight1
, nSpotLight1
);
693 pScene
->GetProperties().SetObjectItem( Svx3DLightcolor1Item( aAmbientSpot1Color
) );
694 pScene
->GetProperties().SetObjectItem( Svx3DLightDirection1Item( aSpotLight1
) );
696 sal_uInt8 nSpotLight2
= (sal_uInt8
)( fLight2Intensity
* 255.0 );
697 basegfx::B3DVector
aSpotLight2( aSecondLightDirection
.DirectionX
, -aSecondLightDirection
.DirectionY
, -aSecondLightDirection
.DirectionZ
);
698 aSpotLight2
.normalize();
699 pScene
->GetProperties().SetObjectItem( Svx3DLightOnOff2Item( sal_True
) );
700 Color
aAmbientSpot2Color( nSpotLight2
, nSpotLight2
, nSpotLight2
);
701 pScene
->GetProperties().SetObjectItem( Svx3DLightcolor2Item( aAmbientSpot2Color
) );
702 pScene
->GetProperties().SetObjectItem( Svx3DLightDirection2Item( aSpotLight2
) );
704 sal_uInt8 nSpotLight3
= 70;
705 basegfx::B3DVector
aSpotLight3( 0.0, 0.0, 1.0 );
706 pScene
->GetProperties().SetObjectItem( Svx3DLightOnOff3Item( sal_True
) );
707 Color
aAmbientSpot3Color( nSpotLight3
, nSpotLight3
, nSpotLight3
);
708 pScene
->GetProperties().SetObjectItem( Svx3DLightcolor3Item( aAmbientSpot3Color
) );
709 pScene
->GetProperties().SetObjectItem( Svx3DLightDirection3Item( aSpotLight3
) );
711 const OUString
sSpecularity( "Specularity" );
712 const OUString
sMetal( "Metal" );
713 double fSpecular
= GetDouble( rGeometryItem
, sSpecularity
, 0, NULL
) / 100;
714 sal_Bool bMetal
= GetBool( rGeometryItem
, sMetal
, sal_False
);
716 Color
aSpecularCol( 225,225,225 );
719 aSpecularCol
= Color( 200, 200, 200 );
722 sal_Int32 nIntensity
= (sal_Int32
)fSpecular
* 100;
723 if ( nIntensity
> 100 )
725 else if ( nIntensity
< 0 )
727 nIntensity
= 100 - nIntensity
;
728 pScene
->GetProperties().SetObjectItem( Svx3DMaterialSpecularItem( aSpecularCol
) );
729 pScene
->GetProperties().SetObjectItem( Svx3DMaterialSpecularIntensityItem( (sal_uInt16
)nIntensity
) );
731 pScene
->SetLogicRect( CalculateNewSnapRect( pCustomShape
, aSnapRect
, aBoundRect2d
, pMap
) );
733 // removing placeholder objects
734 std::vector
< E3dCompoundObject
* >::iterator
aObjectListIter( aPlaceholderObjectList
.begin() );
735 while ( aObjectListIter
!= aPlaceholderObjectList
.end() )
737 pScene
->Remove3DObj( *aObjectListIter
);
738 delete *aObjectListIter
++;
747 Rectangle
EnhancedCustomShape3d::CalculateNewSnapRect( const SdrObject
* pCustomShape
, const Rectangle
& rSnapRect
, const Rectangle
& rBoundRect
, const double* pMap
)
749 SdrCustomShapeGeometryItem
& rGeometryItem
= (SdrCustomShapeGeometryItem
&)pCustomShape
->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
);
750 const Point
aCenter( rSnapRect
.Center() );
751 double fExtrusionBackward
, fExtrusionForward
;
752 GetExtrusionDepth( rGeometryItem
, pMap
, fExtrusionBackward
, fExtrusionForward
);
755 // creating initial bound volume ( without rotation. skewing.and camera )
756 basegfx::B3DPolygon aBoundVolume
;
757 const Polygon
aPolygon( rBoundRect
);
759 for ( i
= 0L; i
< 4L; i
++ )
761 aBoundVolume
.append(basegfx::B3DPoint(aPolygon
[ (sal_uInt16
)i
].X() - aCenter
.X(), aPolygon
[ (sal_uInt16
)i
].Y() - aCenter
.Y(), fExtrusionForward
));
764 for ( i
= 0L; i
< 4L; i
++ )
766 aBoundVolume
.append(basegfx::B3DPoint(aPolygon
[ (sal_uInt16
)i
].X() - aCenter
.X(), aPolygon
[ (sal_uInt16
)i
].Y() - aCenter
.Y(), fExtrusionBackward
));
769 const OUString
sRotationCenter( "RotationCenter" );
770 drawing::Direction3D
aRotationCenterDefault( 0, 0, 0 ); // default seems to be wrong, a fractional size of shape has to be used!!
771 drawing::Direction3D
aRotationCenter( GetDirection3D( rGeometryItem
, sRotationCenter
, aRotationCenterDefault
) );
773 double fXRotate
, fYRotate
;
774 GetRotateAngle( rGeometryItem
, fXRotate
, fYRotate
);
775 double fZRotate
= - ((SdrObjCustomShape
*)pCustomShape
)->GetObjectRotation() * F_PI180
;
777 // rotating bound volume
778 basegfx::B3DHomMatrix aMatrix
;
779 aMatrix
.translate(-aRotationCenter
.DirectionX
, -aRotationCenter
.DirectionY
, -aRotationCenter
.DirectionZ
);
780 if ( fZRotate
!= 0.0 )
781 aMatrix
.rotate( 0.0, 0.0, fZRotate
);
782 if ( ((SdrObjCustomShape
*)pCustomShape
)->IsMirroredX() )
783 aMatrix
.scale( -1.0, 1, 1 );
784 if ( ((SdrObjCustomShape
*)pCustomShape
)->IsMirroredY() )
785 aMatrix
.scale( 1, -1.0, 1 );
786 if( fYRotate
!= 0.0 )
787 aMatrix
.rotate( 0.0, fYRotate
, 0.0 );
788 if( fXRotate
!= 0.0 )
789 aMatrix
.rotate( -fXRotate
, 0.0, 0.0 );
790 aMatrix
.translate(aRotationCenter
.DirectionX
, aRotationCenter
.DirectionY
, aRotationCenter
.DirectionZ
);
791 aBoundVolume
.transform(aMatrix
);
793 Transformation2D
aTransformation2D( pCustomShape
, rSnapRect
, pMap
);
794 if ( aTransformation2D
.IsParallel() )
795 aBoundVolume
= aTransformation2D
.ApplySkewSettings( aBoundVolume
);
797 Polygon
aTransformed( 8 );
798 for ( i
= 0L; i
< 8L; i
++ )
799 aTransformed
[ (sal_uInt16
)i
] = aTransformation2D
.Transform2D( aBoundVolume
.getB3DPoint( i
) );
801 return aTransformed
.GetBoundRect();
804 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */