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 bool GetBool( SdrCustomShapeGeometryItem
& rItem
, const OUString
& rPropertyName
, const bool bDefault
)
154 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
)
198 SdrCustomShapeGeometryItem
& rGeometryItem
= (SdrCustomShapeGeometryItem
&)pCustomShape
->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
);
199 const OUString
sProjectionMode( "ProjectionMode" );
200 Any
* pAny
= rGeometryItem
.GetPropertyValueByName( OUString(aExtrusion
), sProjectionMode
);
202 *pAny
>>= eProjectionMode
;
204 if ( eProjectionMode
== drawing::ProjectionMode_PARALLEL
)
205 GetSkew( rGeometryItem
, fSkew
, fSkewAngle
);
208 GetOrigin( rGeometryItem
, fOriginX
, fOriginY
);
209 fOriginX
= fOriginX
* pCustomShape
->GetLogicRect().GetWidth();
210 fOriginY
= fOriginY
* pCustomShape
->GetLogicRect().GetHeight();
212 const OUString
sViewPoint( "ViewPoint" );
213 drawing::Position3D
aViewPointDefault( 3472, -3472, 25000 );
214 drawing::Position3D
aViewPoint( GetPosition3D( rGeometryItem
, sViewPoint
, aViewPointDefault
, pMap
) );
215 fViewPoint
.setX(aViewPoint
.PositionX
);
216 fViewPoint
.setY(aViewPoint
.PositionY
);
217 fViewPoint
.setZ(-aViewPoint
.PositionZ
);
221 basegfx::B3DPolygon
EnhancedCustomShape3d::Transformation2D::ApplySkewSettings( const basegfx::B3DPolygon
& rPoly3D
) const
223 basegfx::B3DPolygon aRetval
;
226 for ( j
= 0L; j
< rPoly3D
.count(); j
++ )
228 const basegfx::B3DPoint
aPoint(rPoly3D
.getB3DPoint(j
));
229 double fDepth(-( aPoint
.getZ() * fSkew
) / 100.0);
230 aRetval
.append(basegfx::B3DPoint(
231 aPoint
.getX() + (fDepth
* cos( fSkewAngle
)),
232 aPoint
.getY() - (fDepth
* sin( fSkewAngle
)),
239 Point
EnhancedCustomShape3d::Transformation2D::Transform2D( const basegfx::B3DPoint
& rPoint3D
) const
242 if ( eProjectionMode
== drawing::ProjectionMode_PARALLEL
)
244 aPoint2D
.X() = (sal_Int32
)rPoint3D
.getX();
245 aPoint2D
.Y() = (sal_Int32
)rPoint3D
.getY();
249 double fX
= rPoint3D
.getX() - fOriginX
;
250 double fY
= rPoint3D
.getY() - fOriginY
;
251 double f
= ( fZScreen
- fViewPoint
.getZ() ) / ( rPoint3D
.getZ() - fViewPoint
.getZ() );
252 aPoint2D
.X() = (sal_Int32
)(( fX
- fViewPoint
.getX() ) * f
+ fViewPoint
.getX() + fOriginX
);
253 aPoint2D
.Y() = (sal_Int32
)(( fY
- fViewPoint
.getY() ) * f
+ fViewPoint
.getY() + fOriginY
);
255 aPoint2D
.Move( aCenter
.X(), aCenter
.Y() );
259 bool EnhancedCustomShape3d::Transformation2D::IsParallel() const
261 return eProjectionMode
== com::sun::star::drawing::ProjectionMode_PARALLEL
;
264 SdrObject
* EnhancedCustomShape3d::Create3DObject( const SdrObject
* pShape2d
, const SdrObject
* pCustomShape
)
266 SdrObject
* pRet
= NULL
;
267 SdrModel
* pModel
= pCustomShape
->GetModel();
268 SdrCustomShapeGeometryItem
& rGeometryItem
= (SdrCustomShapeGeometryItem
&)pCustomShape
->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
);
270 double fMap
, *pMap
= NULL
;
274 Fraction
aFraction( pModel
->GetScaleFraction() );
275 if ( ( aFraction
.GetNumerator() ) != 1 || ( aFraction
.GetDenominator() != 1 ) )
277 fMap
*= aFraction
.GetNumerator();
278 fMap
/= aFraction
.GetDenominator();
281 if ( pModel
->GetScaleUnit() != MAP_100TH_MM
)
283 DBG_ASSERT( pModel
->GetScaleUnit() == MAP_TWIP
, "EnhancedCustomShape3d::Current MapMode is Unsupported" );
284 fMap
*= 1440.0 / 2540.0;
288 if ( GetBool( rGeometryItem
, aExtrusion
, false ) )
290 bool bIsMirroredX
= ((SdrObjCustomShape
*)pCustomShape
)->IsMirroredX();
291 bool bIsMirroredY
= ((SdrObjCustomShape
*)pCustomShape
)->IsMirroredY();
292 Rectangle
aSnapRect( pCustomShape
->GetLogicRect() );
293 long nObjectRotation
= pCustomShape
->GetRotateAngle();
294 if ( nObjectRotation
)
296 double a
= ( 36000 - nObjectRotation
) * nPi180
;
297 long dx
= aSnapRect
.Right() - aSnapRect
.Left();
298 long dy
= aSnapRect
.Bottom()- aSnapRect
.Top();
299 Point
aP( aSnapRect
.TopLeft() );
300 RotatePoint( aP
, pCustomShape
->GetSnapRect().Center(), sin( a
), cos( a
) );
301 aSnapRect
.Left() = aP
.X();
302 aSnapRect
.Top() = aP
.Y();
303 aSnapRect
.Right() = aSnapRect
.Left() + dx
;
304 aSnapRect
.Bottom() = aSnapRect
.Top() + dy
;
306 Point
aCenter( aSnapRect
.Center() );
308 SfxItemSet
aSet( pCustomShape
->GetMergedItemSet() );
310 //SJ: vertical writing is not required, by removing this item no outliner is created
311 aSet
.ClearItem( SDRATTR_TEXTDIRECTION
);
313 // #i105323# For 3D AutoShapes, the shadow attribute has to be applied to each
314 // created visualisation helper model shape individually. The shadow itself
315 // will then be rendered from the 3D renderer correctly for the whole 3D scene
316 // (and thus behind all objects of which the visualisation may be built). So,
317 // dio NOT remove it from the ItemSet here.
318 // aSet.ClearItem(SDRATTR_SHADOW);
320 std::vector
< E3dCompoundObject
* > aPlaceholderObjectList
;
322 double fExtrusionBackward
, fExtrusionForward
;
323 GetExtrusionDepth( rGeometryItem
, pMap
, fExtrusionBackward
, fExtrusionForward
);
324 double fDepth
= fExtrusionBackward
- fExtrusionForward
;
328 drawing::ProjectionMode
eProjectionMode( drawing::ProjectionMode_PARALLEL
);
329 const OUString
sProjectionMode( "ProjectionMode" );
330 Any
* pAny
= rGeometryItem
.GetPropertyValueByName( aExtrusion
, sProjectionMode
);
332 *pAny
>>= eProjectionMode
;
333 ProjectionType
eProjectionType( eProjectionMode
== drawing::ProjectionMode_PARALLEL
? PR_PARALLEL
: PR_PERSPECTIVE
);
334 // pShape2d Convert in scenes which include 3D Objects
335 E3dDefaultAttributes a3DDefaultAttr
;
336 a3DDefaultAttr
.SetDefaultLatheCharacterMode( true );
337 a3DDefaultAttr
.SetDefaultExtrudeCharacterMode( true );
339 E3dScene
* pScene
= new E3dPolyScene( a3DDefaultAttr
);
341 bool bSceneHasObjects ( false );
342 bool bUseTwoFillStyles( false );
344 drawing::ShadeMode
eShadeMode( GetShadeMode( rGeometryItem
, drawing::ShadeMode_FLAT
) );
345 const OUString
aExtrusionColor( "Color" );
346 bool bUseExtrusionColor
= GetBool( rGeometryItem
, aExtrusionColor
, false );
348 XFillStyle
eFillStyle( ITEMVALUE( aSet
, XATTR_FILLSTYLE
, XFillStyleItem
) );
349 pScene
->GetProperties().SetObjectItem( Svx3DShadeModeItem( 0 ) );
350 aSet
.Put( Svx3DPercentDiagonalItem( 0 ) );
351 aSet
.Put( Svx3DTextureModeItem( 1 ) );
352 aSet
.Put( Svx3DNormalsKindItem( 1 ) );
354 if ( eShadeMode
== drawing::ShadeMode_DRAFT
)
356 aSet
.Put( XLineStyleItem( XLINE_SOLID
) );
357 aSet
.Put( XFillStyleItem ( XFILL_NONE
) );
358 aSet
.Put( Svx3DDoubleSidedItem( true ) );
362 aSet
.Put( XLineStyleItem( XLINE_NONE
) );
363 if ( eFillStyle
== XFILL_NONE
)
364 aSet
.Put( XFillStyleItem( XFILL_SOLID
) );
365 else if ( ( eFillStyle
== XFILL_BITMAP
) || ( eFillStyle
== XFILL_GRADIENT
) || bUseExtrusionColor
)
366 bUseTwoFillStyles
= true;
369 // If shapes are mirrored once (mirroring two times correct geometry again)
370 // double-sided at the object and two-sided-lighting at the scene need to be set.
372 // #i122777# Also use double sided for two fill styles since there several 3d objects get
373 // created with a depth of 0; one of them is the backside which needs double-sided to
375 if(bUseTwoFillStyles
|| (bIsMirroredX
&& !bIsMirroredY
) || (!bIsMirroredX
&& bIsMirroredY
))
377 aSet
.Put( Svx3DDoubleSidedItem( true ) );
378 pScene
->GetProperties().SetObjectItem( Svx3DTwoSidedLightingItem( true ) );
382 Rectangle aBoundRect2d
;
383 SdrObjListIter
aIter( *pShape2d
, IM_DEEPNOGROUPS
);
384 const bool bMultipleSubObjects(aIter
.Count() > 1);
386 while( aIter
.IsMore() )
388 const SdrObject
* pNext
= aIter
.Next();
389 bool bIsPlaceholderObject
= (((XFillStyleItem
&)pNext
->GetMergedItem( XATTR_FILLSTYLE
)).GetValue() == XFILL_NONE
)
390 && (((XLineStyleItem
&)pNext
->GetMergedItem( XATTR_LINESTYLE
)).GetValue() == XLINE_NONE
);
391 basegfx::B2DPolyPolygon aPolyPoly
;
392 SfxItemSet
aLocalSet(aSet
);
393 XFillStyle
aLocalFillStyle(eFillStyle
);
395 if ( pNext
->ISA( SdrPathObj
) )
397 const SfxItemSet
& rSet
= pNext
->GetMergedItemSet();
398 bool bNeedToConvertToContour(false);
400 // do conversion only for single line objects; for all others a fill and a
401 // line object get created. When we have fill, we want no line. That line has
402 // always been there, but since it was never converted to contour, it kept
403 // invisible (all this 'hidden' logic should be migrated to primitives).
404 if(!bMultipleSubObjects
)
406 const XFillStyle
eStyle(((XFillStyleItem
&)(rSet
.Get(XATTR_FILLSTYLE
))).GetValue());
408 if(XFILL_NONE
== eStyle
)
410 const drawinglayer::attribute::SdrLineAttribute
aLine(
411 drawinglayer::primitive2d::createNewSdrLineAttribute(rSet
));
413 bNeedToConvertToContour
= (0.0 < aLine
.getWidth() || 0.0 != aLine
.getFullDotDashLen());
415 if(!bNeedToConvertToContour
&& !aLine
.isDefault())
417 const drawinglayer::attribute::SdrLineStartEndAttribute
aLineStartEnd(
418 drawinglayer::primitive2d::createNewSdrLineStartEndAttribute(rSet
, aLine
.getWidth()));
420 if((aLineStartEnd
.getStartWidth() && aLineStartEnd
.isStartActive())
421 || (aLineStartEnd
.getEndWidth() && aLineStartEnd
.isEndActive()))
423 bNeedToConvertToContour
= true;
429 if(bNeedToConvertToContour
)
431 SdrObject
* pNewObj
= pNext
->ConvertToContourObj(const_cast< SdrObject
* >(pNext
));
432 SdrPathObj
* pNewPathObj
= dynamic_cast< SdrPathObj
* >(pNewObj
);
436 aPolyPoly
= pNewPathObj
->GetPathPoly();
438 if(aPolyPoly
.isClosed())
440 // correct item properties from line to fill style
441 if(eShadeMode
== drawing::ShadeMode_DRAFT
)
443 // for draft, create wireframe with fixed line width
444 aLocalSet
.Put(XLineStyleItem(XLINE_SOLID
));
445 aLocalSet
.Put(XLineWidthItem(40));
446 aLocalFillStyle
= XFILL_NONE
;
450 // switch from line to fill, copy line attr to fill attr (color, transparence)
451 aLocalSet
.Put(XLineWidthItem(0));
452 aLocalSet
.Put(XLineStyleItem(XLINE_NONE
));
453 aLocalSet
.Put(XFillColorItem(OUString(), ((const XLineColorItem
&)(aLocalSet
.Get(XATTR_LINECOLOR
))).GetColorValue()));
454 aLocalSet
.Put(XFillStyleItem(XFILL_SOLID
));
455 aLocalSet
.Put(XFillTransparenceItem(((const XLineTransparenceItem
&)(aLocalSet
.Get(XATTR_LINETRANSPARENCE
))).GetValue()));
456 aLocalFillStyle
= XFILL_SOLID
;
461 // correct item properties to hairlines
462 aLocalSet
.Put(XLineWidthItem(0));
463 aLocalSet
.Put(XLineStyleItem(XLINE_SOLID
));
467 SdrObject::Free(pNewObj
);
471 aPolyPoly
= ((SdrPathObj
*)pNext
)->GetPathPoly();
476 SdrObject
* pNewObj
= pNext
->ConvertToPolyObj( false, false );
477 SdrPathObj
* pPath
= PTR_CAST( SdrPathObj
, pNewObj
);
479 aPolyPoly
= pPath
->GetPathPoly();
480 SdrObject::Free( pNewObj
);
483 if( aPolyPoly
.count() )
485 if(aPolyPoly
.areControlPointsUsed())
487 aPolyPoly
= basegfx::tools::adaptiveSubdivideByAngle(aPolyPoly
);
490 const basegfx::B2DRange
aTempRange(basegfx::tools::getRange(aPolyPoly
));
491 const Rectangle
aBoundRect(basegfx::fround(aTempRange
.getMinX()), basegfx::fround(aTempRange
.getMinY()), basegfx::fround(aTempRange
.getMaxX()), basegfx::fround(aTempRange
.getMaxY()));
492 aBoundRect2d
.Union( aBoundRect
);
494 // #i122777# depth 0 is okay for planes when using double-sided
495 E3dCompoundObject
* p3DObj
= new E3dExtrudeObj( a3DDefaultAttr
, aPolyPoly
, bUseTwoFillStyles
? 0 : fDepth
);
497 p3DObj
->NbcSetLayer( pShape2d
->GetLayer() );
498 p3DObj
->SetMergedItemSet( aLocalSet
);
499 if ( bIsPlaceholderObject
)
500 aPlaceholderObjectList
.push_back( p3DObj
);
501 else if ( bUseTwoFillStyles
)
504 bool bFillBmpTile
= ((XFillBmpTileItem
&)p3DObj
->GetMergedItem( XATTR_FILLBMP_TILE
)).GetValue();
507 const XFillBitmapItem
& rBmpItm
= (XFillBitmapItem
&)p3DObj
->GetMergedItem(XATTR_FILLBITMAP
);
508 aFillBmp
= rBmpItm
.GetGraphicObject().GetGraphic().GetBitmapEx();
510 // #i122777# old adaption of FillStyle bitmap size to 5-times the original size; this is not needed
511 // anymore and was used in old times to male the fill look better when converting to 3D. Removed
512 // from regular 3D objects for some time, also needs to be removed from CustomShapes
514 //Size aLogicalSize = aFillBmp.GetPrefSize();
515 //if ( aFillBmp.GetPrefMapMode() == MAP_PIXEL )
516 // aLogicalSize = Application::GetDefaultDevice()->PixelToLogic( aLogicalSize, MAP_100TH_MM );
518 // aLogicalSize = OutputDevice::LogicToLogic( aLogicalSize, aFillBmp.GetPrefMapMode(), MAP_100TH_MM );
519 //aLogicalSize.Width() *= 5; ;// :-( nice scaling, look at engine3d/obj3d.cxx
520 //aLogicalSize.Height() *= 5;
521 //aFillBmp.SetPrefSize( aLogicalSize );
522 //aFillBmp.SetPrefMapMode( MAP_100TH_MM );
523 //p3DObj->SetMergedItem(XFillBitmapItem(String(), Graphic(aFillBmp)));
527 if ( aSnapRect
!= aBoundRect
)
529 const XFillBitmapItem
& rBmpItm
= (XFillBitmapItem
&)p3DObj
->GetMergedItem(XATTR_FILLBITMAP
);
530 aFillBmp
= rBmpItm
.GetGraphicObject().GetGraphic().GetBitmapEx();
531 Size
aBmpSize( aFillBmp
.GetSizePixel() );
532 double fXScale
= (double)aBoundRect
.GetWidth() / (double)aSnapRect
.GetWidth();
533 double fYScale
= (double)aBoundRect
.GetHeight() / (double)aSnapRect
.GetHeight();
535 Point
aPt( (sal_Int32
)( (double)( aBoundRect
.Left() - aSnapRect
.Left() )* (double)aBmpSize
.Width() / (double)aSnapRect
.GetWidth() ),
536 (sal_Int32
)( (double)( aBoundRect
.Top() - aSnapRect
.Top() ) * (double)aBmpSize
.Height() / (double)aSnapRect
.GetHeight() ) );
537 Size
aSize( (sal_Int32
)( aBmpSize
.Width() * fXScale
),
538 (sal_Int32
)( aBmpSize
.Height() * fYScale
) );
539 Rectangle
aCropRect( aPt
, aSize
);
540 aFillBmp
.Crop( aCropRect
);
541 p3DObj
->SetMergedItem(XFillBitmapItem(OUString(), Graphic(aFillBmp
)));
544 pScene
->Insert3DObj( p3DObj
);
545 p3DObj
= new E3dExtrudeObj( a3DDefaultAttr
, aPolyPoly
, fDepth
);
546 p3DObj
->NbcSetLayer( pShape2d
->GetLayer() );
547 p3DObj
->SetMergedItemSet( aLocalSet
);
548 if ( bUseExtrusionColor
)
549 p3DObj
->SetMergedItem( XFillColorItem( "", ((XSecondaryFillColorItem
&)pCustomShape
->GetMergedItem( XATTR_SECONDARYFILLCOLOR
)).GetColorValue() ) );
550 p3DObj
->SetMergedItem( XFillStyleItem( XFILL_SOLID
) );
551 p3DObj
->SetMergedItem( Svx3DCloseFrontItem( false ) );
552 p3DObj
->SetMergedItem( Svx3DCloseBackItem( false ) );
553 pScene
->Insert3DObj( p3DObj
);
555 // #i122777# depth 0 is okay for planes when using double-sided
556 p3DObj
= new E3dExtrudeObj( a3DDefaultAttr
, aPolyPoly
, 0 );
558 p3DObj
->NbcSetLayer( pShape2d
->GetLayer() );
559 p3DObj
->SetMergedItemSet( aLocalSet
);
561 basegfx::B3DHomMatrix
aFrontTransform( p3DObj
->GetTransform() );
562 aFrontTransform
.translate( 0.0, 0.0, fDepth
);
563 p3DObj
->NbcSetTransform( aFrontTransform
);
565 if ( ( aLocalFillStyle
== XFILL_BITMAP
) && !aFillBmp
.IsEmpty() )
567 p3DObj
->SetMergedItem(XFillBitmapItem(OUString(), Graphic(aFillBmp
)));
570 else if ( aLocalFillStyle
== XFILL_NONE
)
572 XLineColorItem
& rLineColor
= (XLineColorItem
&)p3DObj
->GetMergedItem( XATTR_LINECOLOR
);
573 p3DObj
->SetMergedItem( XFillColorItem( "", rLineColor
.GetColorValue() ) );
574 p3DObj
->SetMergedItem( Svx3DDoubleSidedItem( true ) );
575 p3DObj
->SetMergedItem( Svx3DCloseFrontItem( false ) );
576 p3DObj
->SetMergedItem( Svx3DCloseBackItem( false ) );
578 pScene
->Insert3DObj( p3DObj
);
579 bSceneHasObjects
= true;
583 if ( bSceneHasObjects
) // is the SdrObject properly converted
585 // then we can change the return value
588 // Camera settings, Perspective ...
589 Camera3D
& rCamera
= (Camera3D
&)pScene
->GetCamera();
590 const basegfx::B3DRange
& rVolume
= pScene
->GetBoundVolume();
591 pScene
->NbcSetSnapRect( aSnapRect
);
593 // InitScene replacement
594 double fW
= rVolume
.getWidth();
595 double fH
= rVolume
.getHeight();
597 rCamera
.SetAutoAdjustProjection( false );
598 rCamera
.SetViewWindow( -fW
/ 2, - fH
/ 2, fW
, fH
);
599 basegfx::B3DPoint
aLookAt( 0.0, 0.0, 0.0 );
600 basegfx::B3DPoint
aCamPos( 0.0, 0.0, 100.0 );
601 rCamera
.SetDefaults( basegfx::B3DPoint( 0.0, 0.0, 100.0 ), aLookAt
, 100.0 );
602 rCamera
.SetPosAndLookAt( aCamPos
, aLookAt
);
603 rCamera
.SetFocalLength( 1.0 );
604 rCamera
.SetProjection( eProjectionType
);
605 pScene
->SetCamera( rCamera
);
606 pScene
->SetRectsDirty();
608 double fOriginX
, fOriginY
;
609 GetOrigin( rGeometryItem
, fOriginX
, fOriginY
);
610 fOriginX
= fOriginX
* aSnapRect
.GetWidth();
611 fOriginY
= fOriginY
* aSnapRect
.GetHeight();
613 basegfx::B3DHomMatrix
aNewTransform( pScene
->GetTransform() );
614 aNewTransform
.translate( -aCenter
.X(), aCenter
.Y(), -pScene
->GetBoundVolume().getDepth() );
616 double fXRotate
, fYRotate
;
617 GetRotateAngle( rGeometryItem
, fXRotate
, fYRotate
);
618 double fZRotate
= ((SdrObjCustomShape
*)pCustomShape
)->GetObjectRotation() * F_PI180
;
619 if ( fZRotate
!= 0.0 )
620 aNewTransform
.rotate( 0.0, 0.0, fZRotate
);
622 aNewTransform
.scale( -1.0, 1, 1 );
624 aNewTransform
.scale( 1, -1.0, 1 );
625 if( fYRotate
!= 0.0 )
626 aNewTransform
.rotate( 0.0, -fYRotate
, 0.0 );
627 if( fXRotate
!= 0.0 )
628 aNewTransform
.rotate( -fXRotate
, 0.0, 0.0 );
629 if ( eProjectionType
== PR_PARALLEL
)
631 double fSkew
, fAlpha
;
632 GetSkew( rGeometryItem
, fSkew
, fAlpha
);
635 double fInvTanBeta( fSkew
/ 100.0 );
638 aNewTransform
.shearXY(
639 fInvTanBeta
* cos(fAlpha
),
640 fInvTanBeta
* sin(fAlpha
));
643 basegfx::B3DPoint
_aLookAt( 0.0, 0.0, 0.0 );
644 basegfx::B3DPoint
_aNewCamPos( 0.0, 0.0, 25000.0 );
645 rCamera
.SetPosAndLookAt( _aNewCamPos
, _aLookAt
);
646 pScene
->SetCamera( rCamera
);
650 aNewTransform
.translate( -fOriginX
, fOriginY
, 0.0 );
651 // now set correct camera position
652 const OUString
sViewPoint( "ViewPoint" );
653 drawing::Position3D
aViewPointDefault( 3472, -3472, 25000 );
654 drawing::Position3D
aViewPoint( GetPosition3D( rGeometryItem
, sViewPoint
, aViewPointDefault
, pMap
) );
655 double fViewPointX
= aViewPoint
.PositionX
;
656 double fViewPointY
= aViewPoint
.PositionY
;
657 double fViewPointZ
= aViewPoint
.PositionZ
;
658 basegfx::B3DPoint
_aLookAt( fViewPointX
, -fViewPointY
, 0.0 );
659 basegfx::B3DPoint
aNewCamPos( fViewPointX
, -fViewPointY
, fViewPointZ
);
660 rCamera
.SetPosAndLookAt( aNewCamPos
, _aLookAt
);
661 pScene
->SetCamera( rCamera
);
664 pScene
->NbcSetTransform( aNewTransform
);
670 const OUString
sBrightness( "Brightness" );
671 double fAmbientIntensity
= GetDouble( rGeometryItem
, sBrightness
, 22178.0 / 655.36, NULL
) / 100.0;
674 const OUString
sFirstLightDirection( "FirstLightDirection" );
675 drawing::Direction3D
aFirstLightDirectionDefault( 50000, 0, 10000 );
676 drawing::Direction3D
aFirstLightDirection( GetDirection3D( rGeometryItem
, sFirstLightDirection
, aFirstLightDirectionDefault
) );
677 if ( aFirstLightDirection
.DirectionZ
== 0.0 )
678 aFirstLightDirection
.DirectionZ
= 1.0;
680 const OUString
sFirstLightLevel( "FirstLightLevel" );
681 double fLightIntensity
= GetDouble( rGeometryItem
, sFirstLightLevel
, 43712.0 / 655.36, NULL
) / 100.0;
683 const OUString
sFirstLightHarsh( "FirstLightHarsh" );
684 /* sal_Bool bFirstLightHarsh = */ GetBool( rGeometryItem
, sFirstLightHarsh
, false );
686 const OUString
sSecondLightDirection( "SecondLightDirection" );
687 drawing::Direction3D
aSecondLightDirectionDefault( -50000, 0, 10000 );
688 drawing::Direction3D
aSecondLightDirection( GetDirection3D( rGeometryItem
, sSecondLightDirection
, aSecondLightDirectionDefault
) );
689 if ( aSecondLightDirection
.DirectionZ
== 0.0 )
690 aSecondLightDirection
.DirectionZ
= -1;
692 const OUString
sSecondLightLevel( "SecondLightLevel" );
693 double fLight2Intensity
= GetDouble( rGeometryItem
, sSecondLightLevel
, 43712.0 / 655.36, NULL
) / 100.0;
695 const OUString
sSecondLightHarsh( "SecondLightHarsh" );
696 const OUString
sLightFace( "LightFace" );
697 /* sal_Bool bLight2Harsh = */ GetBool( rGeometryItem
, sSecondLightHarsh
, false );
698 /* sal_Bool bLightFace = */ GetBool( rGeometryItem
, sLightFace
, false );
700 sal_uInt16 nAmbientColor
= (sal_uInt16
)( fAmbientIntensity
* 255.0 );
701 if ( nAmbientColor
> 255 )
703 Color
aGlobalAmbientColor( (sal_uInt8
)nAmbientColor
, (sal_uInt8
)nAmbientColor
, (sal_uInt8
)nAmbientColor
);
704 pScene
->GetProperties().SetObjectItem( Svx3DAmbientcolorItem( aGlobalAmbientColor
) );
706 sal_uInt8 nSpotLight1
= (sal_uInt8
)( fLightIntensity
* 255.0 );
707 basegfx::B3DVector
aSpotLight1( aFirstLightDirection
.DirectionX
, - ( aFirstLightDirection
.DirectionY
), -( aFirstLightDirection
.DirectionZ
) );
708 aSpotLight1
.normalize();
709 pScene
->GetProperties().SetObjectItem( Svx3DLightOnOff1Item( true ) );
710 Color
aAmbientSpot1Color( nSpotLight1
, nSpotLight1
, nSpotLight1
);
711 pScene
->GetProperties().SetObjectItem( Svx3DLightcolor1Item( aAmbientSpot1Color
) );
712 pScene
->GetProperties().SetObjectItem( Svx3DLightDirection1Item( aSpotLight1
) );
714 sal_uInt8 nSpotLight2
= (sal_uInt8
)( fLight2Intensity
* 255.0 );
715 basegfx::B3DVector
aSpotLight2( aSecondLightDirection
.DirectionX
, -aSecondLightDirection
.DirectionY
, -aSecondLightDirection
.DirectionZ
);
716 aSpotLight2
.normalize();
717 pScene
->GetProperties().SetObjectItem( Svx3DLightOnOff2Item( true ) );
718 Color
aAmbientSpot2Color( nSpotLight2
, nSpotLight2
, nSpotLight2
);
719 pScene
->GetProperties().SetObjectItem( Svx3DLightcolor2Item( aAmbientSpot2Color
) );
720 pScene
->GetProperties().SetObjectItem( Svx3DLightDirection2Item( aSpotLight2
) );
722 sal_uInt8 nSpotLight3
= 70;
723 basegfx::B3DVector
aSpotLight3( 0.0, 0.0, 1.0 );
724 pScene
->GetProperties().SetObjectItem( Svx3DLightOnOff3Item( true ) );
725 Color
aAmbientSpot3Color( nSpotLight3
, nSpotLight3
, nSpotLight3
);
726 pScene
->GetProperties().SetObjectItem( Svx3DLightcolor3Item( aAmbientSpot3Color
) );
727 pScene
->GetProperties().SetObjectItem( Svx3DLightDirection3Item( aSpotLight3
) );
729 const OUString
sSpecularity( "Specularity" );
730 const OUString
sMetal( "Metal" );
731 double fSpecular
= GetDouble( rGeometryItem
, sSpecularity
, 0, NULL
) / 100;
732 bool bMetal
= GetBool( rGeometryItem
, sMetal
, false );
734 Color
aSpecularCol( 225,225,225 );
737 aSpecularCol
= Color( 200, 200, 200 );
740 sal_Int32 nIntensity
= (sal_Int32
)fSpecular
* 100;
741 if ( nIntensity
> 100 )
743 else if ( nIntensity
< 0 )
745 nIntensity
= 100 - nIntensity
;
746 pScene
->GetProperties().SetObjectItem( Svx3DMaterialSpecularItem( aSpecularCol
) );
747 pScene
->GetProperties().SetObjectItem( Svx3DMaterialSpecularIntensityItem( (sal_uInt16
)nIntensity
) );
749 pScene
->SetLogicRect( CalculateNewSnapRect( pCustomShape
, aSnapRect
, aBoundRect2d
, pMap
) );
751 // removing placeholder objects
752 std::vector
< E3dCompoundObject
* >::iterator
aObjectListIter( aPlaceholderObjectList
.begin() );
753 while ( aObjectListIter
!= aPlaceholderObjectList
.end() )
755 pScene
->Remove3DObj( *aObjectListIter
);
756 delete *aObjectListIter
++;
765 Rectangle
EnhancedCustomShape3d::CalculateNewSnapRect( const SdrObject
* pCustomShape
, const Rectangle
& rSnapRect
, const Rectangle
& rBoundRect
, const double* pMap
)
767 SdrCustomShapeGeometryItem
& rGeometryItem
= (SdrCustomShapeGeometryItem
&)pCustomShape
->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
);
768 const Point
aCenter( rSnapRect
.Center() );
769 double fExtrusionBackward
, fExtrusionForward
;
770 GetExtrusionDepth( rGeometryItem
, pMap
, fExtrusionBackward
, fExtrusionForward
);
773 // creating initial bound volume ( without rotation. skewing.and camera )
774 basegfx::B3DPolygon aBoundVolume
;
775 const Polygon
aPolygon( rBoundRect
);
777 for ( i
= 0L; i
< 4L; i
++ )
779 aBoundVolume
.append(basegfx::B3DPoint(aPolygon
[ (sal_uInt16
)i
].X() - aCenter
.X(), aPolygon
[ (sal_uInt16
)i
].Y() - aCenter
.Y(), fExtrusionForward
));
782 for ( i
= 0L; i
< 4L; i
++ )
784 aBoundVolume
.append(basegfx::B3DPoint(aPolygon
[ (sal_uInt16
)i
].X() - aCenter
.X(), aPolygon
[ (sal_uInt16
)i
].Y() - aCenter
.Y(), fExtrusionBackward
));
787 const OUString
sRotationCenter( "RotationCenter" );
788 drawing::Direction3D
aRotationCenterDefault( 0, 0, 0 ); // default seems to be wrong, a fractional size of shape has to be used!!
789 drawing::Direction3D
aRotationCenter( GetDirection3D( rGeometryItem
, sRotationCenter
, aRotationCenterDefault
) );
791 double fXRotate
, fYRotate
;
792 GetRotateAngle( rGeometryItem
, fXRotate
, fYRotate
);
793 double fZRotate
= - ((SdrObjCustomShape
*)pCustomShape
)->GetObjectRotation() * F_PI180
;
795 // rotating bound volume
796 basegfx::B3DHomMatrix aMatrix
;
797 aMatrix
.translate(-aRotationCenter
.DirectionX
, -aRotationCenter
.DirectionY
, -aRotationCenter
.DirectionZ
);
798 if ( fZRotate
!= 0.0 )
799 aMatrix
.rotate( 0.0, 0.0, fZRotate
);
800 if ( ((SdrObjCustomShape
*)pCustomShape
)->IsMirroredX() )
801 aMatrix
.scale( -1.0, 1, 1 );
802 if ( ((SdrObjCustomShape
*)pCustomShape
)->IsMirroredY() )
803 aMatrix
.scale( 1, -1.0, 1 );
804 if( fYRotate
!= 0.0 )
805 aMatrix
.rotate( 0.0, fYRotate
, 0.0 );
806 if( fXRotate
!= 0.0 )
807 aMatrix
.rotate( -fXRotate
, 0.0, 0.0 );
808 aMatrix
.translate(aRotationCenter
.DirectionX
, aRotationCenter
.DirectionY
, aRotationCenter
.DirectionZ
);
809 aBoundVolume
.transform(aMatrix
);
811 Transformation2D
aTransformation2D( pCustomShape
, rSnapRect
, pMap
);
812 if ( aTransformation2D
.IsParallel() )
813 aBoundVolume
= aTransformation2D
.ApplySkewSettings( aBoundVolume
);
815 Polygon
aTransformed( 8 );
816 for ( i
= 0L; i
< 8L; i
++ )
817 aTransformed
[ (sal_uInt16
)i
] = aTransformation2D
.Transform2D( aBoundVolume
.getB3DPoint( i
) );
819 return aTransformed
.GetBoundRect();
822 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */