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/deflt3d.hxx>
22 #include <svx/svdetc.hxx>
23 #include <svx/svdmodel.hxx>
24 #include <tools/poly.hxx>
25 #include <svx/svditer.hxx>
26 #include <svx/svdobj.hxx>
27 #include <svx/svdoashp.hxx>
28 #include <svl/poolitem.hxx>
29 #include <svl/itemset.hxx>
30 #include <svx/xfillit0.hxx>
31 #include <svx/xlineit0.hxx>
32 #include <svx/xsflclit.hxx>
33 #include <svx/xit.hxx>
34 #include <svx/xbtmpit.hxx>
35 #include <svx/xflclit.hxx>
36 #include <svx/svdopath.hxx>
37 #include <svx/svdogrp.hxx>
38 #include <svx/svdpage.hxx>
39 #include <svx/svddef.hxx>
40 #include <svx/svx3ditems.hxx>
41 #include <svx/extrud3d.hxx>
42 #include <svx/xflbmtit.hxx>
43 #include <vcl/svapp.hxx>
44 #include <svx/xlnclit.hxx>
45 #include <svx/sdasitm.hxx>
46 #include <svx/scene3d.hxx>
47 #include <com/sun/star/awt/Point.hpp>
48 #include <com/sun/star/drawing/Position3D.hpp>
49 #include <com/sun/star/drawing/Direction3D.hpp>
50 #include <com/sun/star/drawing/ShadeMode.hpp>
51 #include <svx/sdr/properties/properties.hxx>
52 #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
53 #include <basegfx/polygon/b2dpolypolygontools.hxx>
54 #include <basegfx/range/b2drange.hxx>
55 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
56 #include <drawinglayer/attribute/sdrlineattribute.hxx>
57 #include <drawinglayer/attribute/sdrlinestartendattribute.hxx>
58 #include <svx/xlnwtit.hxx>
59 #include <svx/xlntrit.hxx>
60 #include <svx/xfltrit.hxx>
62 using namespace com::sun::star
;
63 using namespace com::sun::star::uno
;
67 void GetOrigin( const SdrCustomShapeGeometryItem
& rItem
, double& rOriginX
, double& rOriginY
)
69 css::drawing::EnhancedCustomShapeParameterPair aOriginParaPair
;
70 const Any
* pAny
= rItem
.GetPropertyValueByName( "Extrusion", "Origin" );
71 if ( ! ( pAny
&& ( *pAny
>>= aOriginParaPair
) && ( aOriginParaPair
.First
.Value
>>= rOriginX
) && ( aOriginParaPair
.Second
.Value
>>= rOriginY
) ) )
78 void GetRotateAngle( const SdrCustomShapeGeometryItem
& rItem
, double& rAngleX
, double& rAngleY
)
80 css::drawing::EnhancedCustomShapeParameterPair aRotateAngleParaPair
;
81 const Any
* pAny
= rItem
.GetPropertyValueByName( "Extrusion", "RotateAngle" );
82 if ( ! ( pAny
&& ( *pAny
>>= aRotateAngleParaPair
) && ( aRotateAngleParaPair
.First
.Value
>>= rAngleX
) && ( aRotateAngleParaPair
.Second
.Value
>>= rAngleY
) ) )
87 rAngleX
= basegfx::deg2rad(rAngleX
);
88 rAngleY
= basegfx::deg2rad(rAngleY
);
91 void GetSkew( const SdrCustomShapeGeometryItem
& rItem
, double& rSkewAmount
, double& rSkewAngle
)
93 css::drawing::EnhancedCustomShapeParameterPair aSkewParaPair
;
94 const Any
* pAny
= rItem
.GetPropertyValueByName( "Extrusion", "Skew" );
95 if ( ! ( pAny
&& ( *pAny
>>= aSkewParaPair
) && ( aSkewParaPair
.First
.Value
>>= rSkewAmount
) && ( aSkewParaPair
.Second
.Value
>>= rSkewAngle
) ) )
100 rSkewAngle
= basegfx::deg2rad(rSkewAngle
);
103 void GetExtrusionDepth( const SdrCustomShapeGeometryItem
& rItem
, const double* pMap
, double& rBackwardDepth
, double& rForwardDepth
)
105 css::drawing::EnhancedCustomShapeParameterPair aDepthParaPair
;
106 double fDepth
= 0, fFraction
= 0;
107 const Any
* pAny
= rItem
.GetPropertyValueByName( "Extrusion", "Depth" );
108 if ( pAny
&& ( *pAny
>>= aDepthParaPair
) && ( aDepthParaPair
.First
.Value
>>= fDepth
) && ( aDepthParaPair
.Second
.Value
>>= fFraction
) )
110 rForwardDepth
= fDepth
* fFraction
;
111 rBackwardDepth
= fDepth
- rForwardDepth
;
115 rBackwardDepth
= 1270;
121 rBackwardDepth
*= fMap
;
122 rForwardDepth
*= fMap
;
126 double GetDouble( const SdrCustomShapeGeometryItem
& rItem
, const OUString
& rPropertyName
, double fDefault
)
128 double fRetValue
= fDefault
;
129 const Any
* pAny
= rItem
.GetPropertyValueByName( "Extrusion", rPropertyName
);
135 drawing::ShadeMode
GetShadeMode( const SdrCustomShapeGeometryItem
& rItem
, const drawing::ShadeMode eDefault
)
137 drawing::ShadeMode
eRet( eDefault
);
138 const Any
* pAny
= rItem
.GetPropertyValueByName( "Extrusion", "ShadeMode" );
144 bool GetBool( const SdrCustomShapeGeometryItem
& rItem
, const OUString
& rPropertyName
, const bool bDefault
)
146 bool bRetValue
= bDefault
;
147 const Any
* pAny
= rItem
.GetPropertyValueByName( "Extrusion", rPropertyName
);
153 drawing::Position3D
GetPosition3D( const SdrCustomShapeGeometryItem
& rItem
, const OUString
& rPropertyName
,
154 const drawing::Position3D
& rDefault
, const double* pMap
)
156 drawing::Position3D
aRetValue( rDefault
);
157 const Any
* pAny
= rItem
.GetPropertyValueByName( "Extrusion", rPropertyName
);
162 aRetValue
.PositionX
*= *pMap
;
163 aRetValue
.PositionY
*= *pMap
;
164 aRetValue
.PositionZ
*= *pMap
;
169 drawing::Direction3D
GetDirection3D( const SdrCustomShapeGeometryItem
& rItem
, const OUString
& rPropertyName
, const drawing::Direction3D
& rDefault
)
171 drawing::Direction3D
aRetValue( rDefault
);
172 const Any
* pAny
= rItem
.GetPropertyValueByName( "Extrusion", rPropertyName
);
180 EnhancedCustomShape3d::Transformation2D::Transformation2D(
181 const SdrObjCustomShape
& rSdrObjCustomShape
,
183 : aCenter(rSdrObjCustomShape
.GetSnapRect().Center())
184 , eProjectionMode( drawing::ProjectionMode_PARALLEL
)
191 const SdrCustomShapeGeometryItem
& rGeometryItem(rSdrObjCustomShape
.GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
));
192 const Any
* pAny
= rGeometryItem
.GetPropertyValueByName( "Extrusion", "ProjectionMode" );
194 *pAny
>>= eProjectionMode
;
196 if ( eProjectionMode
== drawing::ProjectionMode_PARALLEL
)
197 GetSkew( rGeometryItem
, fSkew
, fSkewAngle
);
200 GetOrigin( rGeometryItem
, fOriginX
, fOriginY
);
201 fOriginX
= fOriginX
* rSdrObjCustomShape
.GetLogicRect().GetWidth();
202 fOriginY
= fOriginY
* rSdrObjCustomShape
.GetLogicRect().GetHeight();
204 drawing::Position3D
aViewPointDefault( 3472, -3472, 25000 );
205 drawing::Position3D
aViewPoint( GetPosition3D( rGeometryItem
, "ViewPoint", aViewPointDefault
, pMap
) );
206 fViewPoint
.setX(aViewPoint
.PositionX
);
207 fViewPoint
.setY(aViewPoint
.PositionY
);
208 fViewPoint
.setZ(-aViewPoint
.PositionZ
);
212 basegfx::B3DPolygon
EnhancedCustomShape3d::Transformation2D::ApplySkewSettings( const basegfx::B3DPolygon
& rPoly3D
) const
214 basegfx::B3DPolygon aRetval
;
217 for ( j
= 0; j
< rPoly3D
.count(); j
++ )
219 const basegfx::B3DPoint
aPoint(rPoly3D
.getB3DPoint(j
));
220 double fDepth(-( aPoint
.getZ() * fSkew
) / 100.0);
221 aRetval
.append(basegfx::B3DPoint(
222 aPoint
.getX() + (fDepth
* cos( fSkewAngle
)),
223 aPoint
.getY() - (fDepth
* sin( fSkewAngle
)),
230 Point
EnhancedCustomShape3d::Transformation2D::Transform2D( const basegfx::B3DPoint
& rPoint3D
) const
233 if ( eProjectionMode
== drawing::ProjectionMode_PARALLEL
)
235 aPoint2D
.setX( static_cast<sal_Int32
>(rPoint3D
.getX()) );
236 aPoint2D
.setY( static_cast<sal_Int32
>(rPoint3D
.getY()) );
240 double fX
= rPoint3D
.getX() - fOriginX
;
241 double fY
= rPoint3D
.getY() - fOriginY
;
242 double f
= ( - fViewPoint
.getZ() ) / ( rPoint3D
.getZ() - fViewPoint
.getZ() );
243 aPoint2D
.setX( static_cast<sal_Int32
>(( fX
- fViewPoint
.getX() ) * f
+ fViewPoint
.getX() + fOriginX
) );
244 aPoint2D
.setY( static_cast<sal_Int32
>(( fY
- fViewPoint
.getY() ) * f
+ fViewPoint
.getY() + fOriginY
) );
246 aPoint2D
.Move( aCenter
.X(), aCenter
.Y() );
250 bool EnhancedCustomShape3d::Transformation2D::IsParallel() const
252 return eProjectionMode
== css::drawing::ProjectionMode_PARALLEL
;
255 SdrObject
* EnhancedCustomShape3d::Create3DObject(
256 const SdrObject
* pShape2d
,
257 const SdrObjCustomShape
& rSdrObjCustomShape
)
259 SdrObject
* pRet(nullptr);
260 const SdrCustomShapeGeometryItem
& rGeometryItem(rSdrObjCustomShape
.GetMergedItem(SDRATTR_CUSTOMSHAPE_GEOMETRY
));
261 double fMap(1.0), *pMap
= nullptr;
262 Fraction
aFraction( rSdrObjCustomShape
.getSdrModelFromSdrObject().GetScaleFraction() );
264 if ( aFraction
.GetNumerator() != 1 || aFraction
.GetDenominator() != 1 )
266 fMap
*= double(aFraction
);
270 if ( rSdrObjCustomShape
.getSdrModelFromSdrObject().GetScaleUnit() != MapUnit::Map100thMM
)
272 DBG_ASSERT( rSdrObjCustomShape
.getSdrModelFromSdrObject().GetScaleUnit() == MapUnit::MapTwip
, "EnhancedCustomShape3d::Current MapMode is Unsupported" );
273 fMap
*= 1440.0 / 2540.0;
277 if ( GetBool( rGeometryItem
, "Extrusion", false ) )
279 bool bIsMirroredX(rSdrObjCustomShape
.IsMirroredX());
280 bool bIsMirroredY(rSdrObjCustomShape
.IsMirroredY());
281 tools::Rectangle
aSnapRect(rSdrObjCustomShape
.GetLogicRect());
282 long nObjectRotation(rSdrObjCustomShape
.GetRotateAngle());
283 if ( nObjectRotation
)
285 double a
= (36000 - nObjectRotation
) * F_PI18000
;
286 long dx
= aSnapRect
.Right() - aSnapRect
.Left();
287 long dy
= aSnapRect
.Bottom()- aSnapRect
.Top();
288 Point
aP( aSnapRect
.TopLeft() );
289 RotatePoint( aP
, rSdrObjCustomShape
.GetSnapRect().Center(), sin( a
), cos( a
) );
290 aSnapRect
.SetLeft( aP
.X() );
291 aSnapRect
.SetTop( aP
.Y() );
292 aSnapRect
.SetRight( aSnapRect
.Left() + dx
);
293 aSnapRect
.SetBottom( aSnapRect
.Top() + dy
);
295 Point
aCenter( aSnapRect
.Center() );
297 SfxItemSet
aSet( rSdrObjCustomShape
.GetMergedItemSet() );
299 //SJ: vertical writing is not required, by removing this item no outliner is created
300 aSet
.ClearItem( SDRATTR_TEXTDIRECTION
);
302 // #i105323# For 3D AutoShapes, the shadow attribute has to be applied to each
303 // created visualisation helper model shape individually. The shadow itself
304 // will then be rendered from the 3D renderer correctly for the whole 3D scene
305 // (and thus behind all objects of which the visualisation may be built). So,
306 // do NOT remove it from the ItemSet here.
307 // aSet.ClearItem(SDRATTR_SHADOW);
309 std::vector
< E3dCompoundObject
* > aPlaceholderObjectList
;
311 double fExtrusionBackward
, fExtrusionForward
;
312 GetExtrusionDepth( rGeometryItem
, pMap
, fExtrusionBackward
, fExtrusionForward
);
313 double fDepth
= fExtrusionBackward
- fExtrusionForward
;
317 drawing::ProjectionMode
eProjectionMode( drawing::ProjectionMode_PARALLEL
);
318 const Any
* pAny
= rGeometryItem
.GetPropertyValueByName( "Extrusion", "ProjectionMode" );
320 *pAny
>>= eProjectionMode
;
321 ProjectionType
eProjectionType( eProjectionMode
== drawing::ProjectionMode_PARALLEL
? ProjectionType::Parallel
: ProjectionType::Perspective
);
322 // pShape2d Convert in scenes which include 3D Objects
323 E3dDefaultAttributes a3DDefaultAttr
;
324 a3DDefaultAttr
.SetDefaultLatheCharacterMode( true );
325 a3DDefaultAttr
.SetDefaultExtrudeCharacterMode( true );
327 E3dScene
* pScene
= new E3dScene(rSdrObjCustomShape
.getSdrModelFromSdrObject());
329 bool bSceneHasObjects ( false );
330 bool bUseTwoFillStyles( false );
332 drawing::ShadeMode
eShadeMode( GetShadeMode( rGeometryItem
, drawing::ShadeMode_FLAT
) );
333 bool bUseExtrusionColor
= GetBool( rGeometryItem
, "Color", false );
335 drawing::FillStyle
eFillStyle( aSet
.Get(XATTR_FILLSTYLE
).GetValue() );
336 pScene
->GetProperties().SetObjectItem( Svx3DShadeModeItem( 0 ) );
337 aSet
.Put( makeSvx3DPercentDiagonalItem( 0 ) );
338 aSet
.Put( Svx3DTextureModeItem( 1 ) );
339 aSet
.Put( Svx3DNormalsKindItem( 1 ) );
341 if ( eShadeMode
== drawing::ShadeMode_DRAFT
)
343 aSet
.Put( XLineStyleItem( drawing::LineStyle_SOLID
) );
344 aSet
.Put( XFillStyleItem ( drawing::FillStyle_NONE
) );
345 aSet
.Put( makeSvx3DDoubleSidedItem( true ) );
349 aSet
.Put( XLineStyleItem( drawing::LineStyle_NONE
) );
350 if ( eFillStyle
== drawing::FillStyle_NONE
)
351 aSet
.Put( XFillStyleItem( drawing::FillStyle_SOLID
) );
352 else if ( ( eFillStyle
== drawing::FillStyle_BITMAP
) || ( eFillStyle
== drawing::FillStyle_GRADIENT
) || bUseExtrusionColor
)
353 bUseTwoFillStyles
= true;
355 // If shapes are mirrored once (mirroring two times correct geometry again)
356 // double-sided at the object and two-sided-lighting at the scene need to be set.
358 // #i122777# Also use double sided for two fill styles since there several 3d objects get
359 // created with a depth of 0; one of them is the backside which needs double-sided to
361 if(bUseTwoFillStyles
|| (bIsMirroredX
&& !bIsMirroredY
) || (!bIsMirroredX
&& bIsMirroredY
))
363 aSet
.Put( makeSvx3DDoubleSidedItem( true ) );
364 pScene
->GetProperties().SetObjectItem( makeSvx3DTwoSidedLightingItem( true ) );
368 tools::Rectangle aBoundRect2d
;
369 SdrObjListIter
aIter( *pShape2d
, SdrIterMode::DeepNoGroups
);
370 const bool bMultipleSubObjects(aIter
.Count() > 1);
372 while( aIter
.IsMore() )
374 const SdrObject
* pNext
= aIter
.Next();
375 bool bIsPlaceholderObject
= (pNext
->GetMergedItem( XATTR_FILLSTYLE
).GetValue() == drawing::FillStyle_NONE
)
376 && (pNext
->GetMergedItem( XATTR_LINESTYLE
).GetValue() == drawing::LineStyle_NONE
);
377 basegfx::B2DPolyPolygon aPolyPoly
;
378 SfxItemSet
aLocalSet(aSet
);
379 drawing::FillStyle
aLocalFillStyle(eFillStyle
);
381 if ( auto pPathObj
= dynamic_cast<const SdrPathObj
*>(pNext
) )
383 const SfxItemSet
& rSet
= pNext
->GetMergedItemSet();
384 bool bNeedToConvertToContour(false);
386 // do conversion only for single line objects; for all others a fill and a
387 // line object get created. When we have fill, we want no line. That line has
388 // always been there, but since it was never converted to contour, it kept
389 // invisible (all this 'hidden' logic should be migrated to primitives).
390 if(!bMultipleSubObjects
)
392 const drawing::FillStyle
eStyle(rSet
.Get(XATTR_FILLSTYLE
).GetValue());
394 if(drawing::FillStyle_NONE
== eStyle
)
396 const drawinglayer::attribute::SdrLineAttribute
aLine(
397 drawinglayer::primitive2d::createNewSdrLineAttribute(rSet
));
399 bNeedToConvertToContour
= (0.0 < aLine
.getWidth() || 0.0 != aLine
.getFullDotDashLen());
401 if(!bNeedToConvertToContour
&& !aLine
.isDefault())
403 const drawinglayer::attribute::SdrLineStartEndAttribute
aLineStartEnd(
404 drawinglayer::primitive2d::createNewSdrLineStartEndAttribute(rSet
, aLine
.getWidth()));
406 if((aLineStartEnd
.getStartWidth() && aLineStartEnd
.isStartActive())
407 || (aLineStartEnd
.getEndWidth() && aLineStartEnd
.isEndActive()))
409 bNeedToConvertToContour
= true;
415 if(bNeedToConvertToContour
)
417 SdrObject
* pNewObj
= pNext
->ConvertToContourObj(const_cast< SdrObject
* >(pNext
));
418 SdrPathObj
* pNewPathObj
= dynamic_cast< SdrPathObj
* >(pNewObj
);
422 aPolyPoly
= pNewPathObj
->GetPathPoly();
424 if(aPolyPoly
.isClosed())
426 // correct item properties from line to fill style
427 if(eShadeMode
== drawing::ShadeMode_DRAFT
)
429 // for draft, create wireframe with fixed line width
430 aLocalSet
.Put(XLineStyleItem(drawing::LineStyle_SOLID
));
431 aLocalSet
.Put(XLineWidthItem(40));
432 aLocalFillStyle
= drawing::FillStyle_NONE
;
436 // switch from line to fill, copy line attr to fill attr (color, transparence)
437 aLocalSet
.Put(XLineWidthItem(0));
438 aLocalSet
.Put(XLineStyleItem(drawing::LineStyle_NONE
));
439 aLocalSet
.Put(XFillColorItem(OUString(), aLocalSet
.Get(XATTR_LINECOLOR
).GetColorValue()));
440 aLocalSet
.Put(XFillStyleItem(drawing::FillStyle_SOLID
));
441 aLocalSet
.Put(XFillTransparenceItem(aLocalSet
.Get(XATTR_LINETRANSPARENCE
).GetValue()));
442 aLocalFillStyle
= drawing::FillStyle_SOLID
;
447 // correct item properties to hairlines
448 aLocalSet
.Put(XLineWidthItem(0));
449 aLocalSet
.Put(XLineStyleItem(drawing::LineStyle_SOLID
));
453 SdrObject::Free(pNewObj
);
457 aPolyPoly
= pPathObj
->GetPathPoly();
462 SdrObjectUniquePtr pNewObj
= pNext
->ConvertToPolyObj( false, false );
463 SdrPathObj
* pPath
= dynamic_cast<SdrPathObj
*>( pNewObj
.get() );
465 aPolyPoly
= pPath
->GetPathPoly();
468 if( aPolyPoly
.count() )
470 if(aPolyPoly
.areControlPointsUsed())
472 aPolyPoly
= basegfx::utils::adaptiveSubdivideByAngle(aPolyPoly
);
475 const basegfx::B2DRange
aTempRange(basegfx::utils::getRange(aPolyPoly
));
476 const tools::Rectangle
aBoundRect(basegfx::fround(aTempRange
.getMinX()), basegfx::fround(aTempRange
.getMinY()), basegfx::fround(aTempRange
.getMaxX()), basegfx::fround(aTempRange
.getMaxY()));
477 aBoundRect2d
.Union( aBoundRect
);
479 // #i122777# depth 0 is okay for planes when using double-sided
480 E3dCompoundObject
* p3DObj
= new E3dExtrudeObj(
481 rSdrObjCustomShape
.getSdrModelFromSdrObject(),
484 bUseTwoFillStyles
? 0 : fDepth
);
486 p3DObj
->NbcSetLayer( pShape2d
->GetLayer() );
487 p3DObj
->SetMergedItemSet( aLocalSet
);
489 if ( bIsPlaceholderObject
)
490 aPlaceholderObjectList
.push_back( p3DObj
);
491 else if ( bUseTwoFillStyles
)
494 bool bFillBmpTile
= p3DObj
->GetMergedItem( XATTR_FILLBMP_TILE
).GetValue();
497 const XFillBitmapItem
& rBmpItm
= p3DObj
->GetMergedItem(XATTR_FILLBITMAP
);
498 aFillBmp
= rBmpItm
.GetGraphicObject().GetGraphic().GetBitmapEx();
500 // #i122777# old adaptation of FillStyle bitmap size to 5-times the original size; this is not needed
501 // anymore and was used in old times to male the fill look better when converting to 3D. Removed
502 // from regular 3D objects for some time, also needs to be removed from CustomShapes
504 //Size aLogicalSize = aFillBmp.GetPrefSize();
505 //if ( aFillBmp.GetPrefMapMode() == MapUnit::MapPixel )
506 // aLogicalSize = Application::GetDefaultDevice()->PixelToLogic( aLogicalSize, MapUnit::Map100thMM );
508 // aLogicalSize = OutputDevice::LogicToLogic( aLogicalSize, aFillBmp.GetPrefMapMode(), MapUnit::Map100thMM );
509 //aLogicalSize.Width() *= 5; ;// :-( nice scaling, look at engine3d/obj3d.cxx
510 //aLogicalSize.Height() *= 5;
511 //aFillBmp.SetPrefSize( aLogicalSize );
512 //aFillBmp.SetPrefMapMode( MapUnit::Map100thMM );
513 //p3DObj->SetMergedItem(XFillBitmapItem(String(), Graphic(aFillBmp)));
517 if ( aSnapRect
!= aBoundRect
&& aSnapRect
.GetWidth() > 0 && aSnapRect
.GetHeight() > 0)
519 const XFillBitmapItem
& rBmpItm
= p3DObj
->GetMergedItem(XATTR_FILLBITMAP
);
520 aFillBmp
= rBmpItm
.GetGraphicObject().GetGraphic().GetBitmapEx();
521 Size
aBmpSize( aFillBmp
.GetSizePixel() );
522 double fXScale
= static_cast<double>(aBoundRect
.GetWidth()) / static_cast<double>(aSnapRect
.GetWidth());
523 double fYScale
= static_cast<double>(aBoundRect
.GetHeight()) / static_cast<double>(aSnapRect
.GetHeight());
525 Point
aPt( static_cast<sal_Int32
>( static_cast<double>( aBoundRect
.Left() - aSnapRect
.Left() )* static_cast<double>(aBmpSize
.Width()) / static_cast<double>(aSnapRect
.GetWidth()) ),
526 static_cast<sal_Int32
>( static_cast<double>( aBoundRect
.Top() - aSnapRect
.Top() ) * static_cast<double>(aBmpSize
.Height()) / static_cast<double>(aSnapRect
.GetHeight()) ) );
527 Size
aSize( static_cast<sal_Int32
>( aBmpSize
.Width() * fXScale
),
528 static_cast<sal_Int32
>( aBmpSize
.Height() * fYScale
) );
529 tools::Rectangle
aCropRect( aPt
, aSize
);
530 aFillBmp
.Crop( aCropRect
);
531 p3DObj
->SetMergedItem(XFillBitmapItem(OUString(), Graphic(aFillBmp
)));
534 pScene
->InsertObject( p3DObj
);
535 p3DObj
= new E3dExtrudeObj(
536 rSdrObjCustomShape
.getSdrModelFromSdrObject(),
540 p3DObj
->NbcSetLayer( pShape2d
->GetLayer() );
541 p3DObj
->SetMergedItemSet( aLocalSet
);
542 if ( bUseExtrusionColor
)
543 p3DObj
->SetMergedItem( XFillColorItem( "", rSdrObjCustomShape
.GetMergedItem( XATTR_SECONDARYFILLCOLOR
).GetColorValue() ) );
544 p3DObj
->SetMergedItem( XFillStyleItem( drawing::FillStyle_SOLID
) );
545 p3DObj
->SetMergedItem( Svx3DCloseFrontItem( false ) );
546 p3DObj
->SetMergedItem( Svx3DCloseBackItem( false ) );
547 pScene
->InsertObject( p3DObj
);
549 // #i122777# depth 0 is okay for planes when using double-sided
550 p3DObj
= new E3dExtrudeObj(
551 rSdrObjCustomShape
.getSdrModelFromSdrObject(),
556 p3DObj
->NbcSetLayer( pShape2d
->GetLayer() );
557 p3DObj
->SetMergedItemSet( aLocalSet
);
559 basegfx::B3DHomMatrix
aFrontTransform( p3DObj
->GetTransform() );
560 aFrontTransform
.translate( 0.0, 0.0, fDepth
);
561 p3DObj
->NbcSetTransform( aFrontTransform
);
563 if ( ( aLocalFillStyle
== drawing::FillStyle_BITMAP
) && !aFillBmp
.IsEmpty() )
565 p3DObj
->SetMergedItem(XFillBitmapItem(OUString(), Graphic(aFillBmp
)));
568 else if ( aLocalFillStyle
== drawing::FillStyle_NONE
)
570 const XLineColorItem
& rLineColor
= p3DObj
->GetMergedItem( XATTR_LINECOLOR
);
571 p3DObj
->SetMergedItem( XFillColorItem( "", rLineColor
.GetColorValue() ) );
572 p3DObj
->SetMergedItem( makeSvx3DDoubleSidedItem( true ) );
573 p3DObj
->SetMergedItem( Svx3DCloseFrontItem( false ) );
574 p3DObj
->SetMergedItem( Svx3DCloseBackItem( false ) );
576 pScene
->InsertObject( p3DObj
);
577 bSceneHasObjects
= true;
581 if ( bSceneHasObjects
) // is the SdrObject properly converted
583 // then we can change the return value
586 // Camera settings, Perspective ...
587 Camera3D rCamera
= pScene
->GetCamera();
588 const basegfx::B3DRange
& rVolume
= pScene
->GetBoundVolume();
589 pScene
->NbcSetSnapRect( aSnapRect
);
591 // InitScene replacement
592 double fW
= rVolume
.getWidth();
593 double fH
= rVolume
.getHeight();
595 rCamera
.SetAutoAdjustProjection( false );
596 rCamera
.SetViewWindow( -fW
/ 2, - fH
/ 2, fW
, fH
);
597 basegfx::B3DPoint
aLookAt( 0.0, 0.0, 0.0 );
598 basegfx::B3DPoint
aCamPos( 0.0, 0.0, 100.0 );
599 rCamera
.SetPosAndLookAt( aCamPos
, aLookAt
);
600 rCamera
.SetFocalLength( 1.0 );
601 rCamera
.SetProjection( eProjectionType
);
602 pScene
->SetCamera( rCamera
);
603 pScene
->SetRectsDirty();
605 double fOriginX
, fOriginY
;
606 GetOrigin( rGeometryItem
, fOriginX
, fOriginY
);
607 fOriginX
= fOriginX
* aSnapRect
.GetWidth();
608 fOriginY
= fOriginY
* aSnapRect
.GetHeight();
610 basegfx::B3DHomMatrix
aNewTransform( pScene
->GetTransform() );
611 aNewTransform
.translate( -aCenter
.X(), aCenter
.Y(), -pScene
->GetBoundVolume().getDepth() );
613 double fXRotate
, fYRotate
;
614 GetRotateAngle( rGeometryItem
, fXRotate
, fYRotate
);
615 double fZRotate(basegfx::deg2rad(rSdrObjCustomShape
.GetObjectRotation()));
616 if ( fZRotate
!= 0.0 )
617 aNewTransform
.rotate( 0.0, 0.0, fZRotate
);
619 aNewTransform
.scale( -1.0, 1, 1 );
621 aNewTransform
.scale( 1, -1.0, 1 );
622 if( fYRotate
!= 0.0 )
623 aNewTransform
.rotate( 0.0, -fYRotate
, 0.0 );
624 if( fXRotate
!= 0.0 )
625 aNewTransform
.rotate( -fXRotate
, 0.0, 0.0 );
626 if ( eProjectionType
== ProjectionType::Parallel
)
628 double fSkew
, fAlpha
;
629 GetSkew( rGeometryItem
, fSkew
, fAlpha
);
632 double fInvTanBeta( fSkew
/ 100.0 );
635 aNewTransform
.shearXY(
636 fInvTanBeta
* cos(fAlpha
),
637 fInvTanBeta
* sin(fAlpha
));
640 basegfx::B3DPoint
_aLookAt( 0.0, 0.0, 0.0 );
641 basegfx::B3DPoint
_aNewCamPos( 0.0, 0.0, 25000.0 );
642 rCamera
.SetPosAndLookAt( _aNewCamPos
, _aLookAt
);
643 pScene
->SetCamera( rCamera
);
647 aNewTransform
.translate( -fOriginX
, fOriginY
, 0.0 );
648 // now set correct camera position
649 drawing::Position3D
aViewPointDefault( 3472, -3472, 25000 );
650 drawing::Position3D
aViewPoint( GetPosition3D( rGeometryItem
, "ViewPoint", aViewPointDefault
, pMap
) );
651 double fViewPointX
= aViewPoint
.PositionX
;
652 double fViewPointY
= aViewPoint
.PositionY
;
653 double fViewPointZ
= aViewPoint
.PositionZ
;
654 basegfx::B3DPoint
_aLookAt( fViewPointX
, -fViewPointY
, 0.0 );
655 basegfx::B3DPoint
aNewCamPos( fViewPointX
, -fViewPointY
, fViewPointZ
);
656 rCamera
.SetPosAndLookAt( aNewCamPos
, _aLookAt
);
657 pScene
->SetCamera( rCamera
);
660 pScene
->NbcSetTransform( aNewTransform
);
665 double fAmbientIntensity
= GetDouble( rGeometryItem
, "Brightness", 22178.0 / 655.36 ) / 100.0;
667 drawing::Direction3D
aFirstLightDirectionDefault( 50000, 0, 10000 );
668 drawing::Direction3D
aFirstLightDirection( GetDirection3D( rGeometryItem
, "FirstLightDirection", aFirstLightDirectionDefault
) );
669 if ( aFirstLightDirection
.DirectionZ
== 0.0 )
670 aFirstLightDirection
.DirectionZ
= 1.0;
672 double fLightIntensity
= GetDouble( rGeometryItem
, "FirstLightLevel", 43712.0 / 655.36 ) / 100.0;
674 /* sal_Bool bFirstLightHarsh = */ GetBool( rGeometryItem
, "FirstLightHarsh", false );
676 drawing::Direction3D
aSecondLightDirectionDefault( -50000, 0, 10000 );
677 drawing::Direction3D
aSecondLightDirection( GetDirection3D( rGeometryItem
, "SecondLightDirection", aSecondLightDirectionDefault
) );
678 if ( aSecondLightDirection
.DirectionZ
== 0.0 )
679 aSecondLightDirection
.DirectionZ
= -1;
681 double fLight2Intensity
= GetDouble( rGeometryItem
, "SecondLightLevel", 43712.0 / 655.36 ) / 100.0;
683 /* sal_Bool bLight2Harsh = */ GetBool( rGeometryItem
, "SecondLightHarsh", false );
684 /* sal_Bool bLightFace = */ GetBool( rGeometryItem
, "LightFace", false );
686 sal_uInt16 nAmbientColor
= static_cast<sal_uInt16
>( fAmbientIntensity
* 255.0 );
687 if ( nAmbientColor
> 255 )
689 Color
aGlobalAmbientColor( static_cast<sal_uInt8
>(nAmbientColor
), static_cast<sal_uInt8
>(nAmbientColor
), static_cast<sal_uInt8
>(nAmbientColor
) );
690 pScene
->GetProperties().SetObjectItem( makeSvx3DAmbientcolorItem( aGlobalAmbientColor
) );
692 sal_uInt8 nSpotLight1
= static_cast<sal_uInt8
>( fLightIntensity
* 255.0 );
693 basegfx::B3DVector
aSpotLight1( aFirstLightDirection
.DirectionX
, - ( aFirstLightDirection
.DirectionY
), -( aFirstLightDirection
.DirectionZ
) );
694 aSpotLight1
.normalize();
695 pScene
->GetProperties().SetObjectItem( makeSvx3DLightOnOff1Item( true ) );
696 Color
aAmbientSpot1Color( nSpotLight1
, nSpotLight1
, nSpotLight1
);
697 pScene
->GetProperties().SetObjectItem( makeSvx3DLightcolor1Item( aAmbientSpot1Color
) );
698 pScene
->GetProperties().SetObjectItem( makeSvx3DLightDirection1Item( aSpotLight1
) );
700 sal_uInt8 nSpotLight2
= static_cast<sal_uInt8
>( fLight2Intensity
* 255.0 );
701 basegfx::B3DVector
aSpotLight2( aSecondLightDirection
.DirectionX
, -aSecondLightDirection
.DirectionY
, -aSecondLightDirection
.DirectionZ
);
702 aSpotLight2
.normalize();
703 pScene
->GetProperties().SetObjectItem( makeSvx3DLightOnOff2Item( true ) );
704 Color
aAmbientSpot2Color( nSpotLight2
, nSpotLight2
, nSpotLight2
);
705 pScene
->GetProperties().SetObjectItem( makeSvx3DLightcolor2Item( aAmbientSpot2Color
) );
706 pScene
->GetProperties().SetObjectItem( makeSvx3DLightDirection2Item( aSpotLight2
) );
708 sal_uInt8 nSpotLight3
= 70;
709 basegfx::B3DVector
aSpotLight3( 0.0, 0.0, 1.0 );
710 pScene
->GetProperties().SetObjectItem( makeSvx3DLightOnOff3Item( true ) );
711 Color
aAmbientSpot3Color( nSpotLight3
, nSpotLight3
, nSpotLight3
);
712 pScene
->GetProperties().SetObjectItem( makeSvx3DLightcolor3Item( aAmbientSpot3Color
) );
713 pScene
->GetProperties().SetObjectItem( makeSvx3DLightDirection3Item( aSpotLight3
) );
715 double fSpecular
= GetDouble( rGeometryItem
, "Specularity", 0 ) / 100;
716 bool bMetal
= GetBool( rGeometryItem
, "Metal", false );
718 Color
aSpecularCol( 225,225,225 );
721 aSpecularCol
= Color( 200, 200, 200 );
724 sal_Int32 nIntensity
= static_cast<sal_Int32
>(fSpecular
) * 100;
725 if ( nIntensity
> 100 )
727 else if ( nIntensity
< 0 )
729 nIntensity
= 100 - nIntensity
;
730 pScene
->GetProperties().SetObjectItem( makeSvx3DMaterialSpecularItem( aSpecularCol
) );
731 pScene
->GetProperties().SetObjectItem( makeSvx3DMaterialSpecularIntensityItem( static_cast<sal_uInt16
>(nIntensity
) ) );
733 pScene
->SetLogicRect(
734 CalculateNewSnapRect(
740 // removing placeholder objects
741 for (E3dCompoundObject
* pTemp
: aPlaceholderObjectList
)
743 pScene
->RemoveObject( pTemp
->GetOrdNum() );
744 // always use SdrObject::Free(...) for SdrObjects (!)
745 SdrObject
* pTemp2(pTemp
);
746 SdrObject::Free(pTemp2
);
751 // always use SdrObject::Free(...) for SdrObjects (!)
752 SdrObject
* pTemp(pScene
);
753 SdrObject::Free(pTemp
);
759 tools::Rectangle
EnhancedCustomShape3d::CalculateNewSnapRect(
760 const SdrObjCustomShape
& rSdrObjCustomShape
,
761 const tools::Rectangle
& rSnapRect
,
762 const tools::Rectangle
& rBoundRect
,
765 const SdrCustomShapeGeometryItem
& rGeometryItem(rSdrObjCustomShape
.GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
));
766 const Point
aCenter( rSnapRect
.Center() );
767 double fExtrusionBackward
, fExtrusionForward
;
768 GetExtrusionDepth( rGeometryItem
, pMap
, fExtrusionBackward
, fExtrusionForward
);
771 // creating initial bound volume ( without rotation. skewing.and camera )
772 basegfx::B3DPolygon aBoundVolume
;
773 const tools::Polygon
aPolygon( rBoundRect
);
775 for ( i
= 0; i
< 4; i
++ )
777 aBoundVolume
.append(basegfx::B3DPoint(aPolygon
[ static_cast<sal_uInt16
>(i
) ].X() - aCenter
.X(), aPolygon
[ static_cast<sal_uInt16
>(i
) ].Y() - aCenter
.Y(), fExtrusionForward
));
780 for ( i
= 0; i
< 4; i
++ )
782 aBoundVolume
.append(basegfx::B3DPoint(aPolygon
[ static_cast<sal_uInt16
>(i
) ].X() - aCenter
.X(), aPolygon
[ static_cast<sal_uInt16
>(i
) ].Y() - aCenter
.Y(), fExtrusionBackward
));
785 drawing::Direction3D
aRotationCenterDefault( 0, 0, 0 ); // default seems to be wrong, a fractional size of shape has to be used!!
786 drawing::Direction3D
aRotationCenter( GetDirection3D( rGeometryItem
, "RotationCenter", aRotationCenterDefault
) );
788 double fXRotate
, fYRotate
;
789 GetRotateAngle( rGeometryItem
, fXRotate
, fYRotate
);
790 double fZRotate(basegfx::deg2rad(rSdrObjCustomShape
.GetObjectRotation()));
792 // rotating bound volume
793 basegfx::B3DHomMatrix aMatrix
;
794 aMatrix
.translate(-aRotationCenter
.DirectionX
, -aRotationCenter
.DirectionY
, -aRotationCenter
.DirectionZ
);
795 if ( fZRotate
!= 0.0 )
796 aMatrix
.rotate( 0.0, 0.0, fZRotate
);
797 if (rSdrObjCustomShape
.IsMirroredX())
798 aMatrix
.scale( -1.0, 1, 1 );
799 if (rSdrObjCustomShape
.IsMirroredY())
800 aMatrix
.scale( 1, -1.0, 1 );
801 if( fYRotate
!= 0.0 )
802 aMatrix
.rotate( 0.0, fYRotate
, 0.0 );
803 if( fXRotate
!= 0.0 )
804 aMatrix
.rotate( -fXRotate
, 0.0, 0.0 );
805 aMatrix
.translate(aRotationCenter
.DirectionX
, aRotationCenter
.DirectionY
, aRotationCenter
.DirectionZ
);
806 aBoundVolume
.transform(aMatrix
);
808 Transformation2D
aTransformation2D(
812 if ( aTransformation2D
.IsParallel() )
813 aBoundVolume
= aTransformation2D
.ApplySkewSettings( aBoundVolume
);
815 tools::Polygon
aTransformed( 8 );
816 for ( i
= 0; i
< 8; i
++ )
817 aTransformed
[ static_cast<sal_uInt16
>(i
) ] = aTransformation2D
.Transform2D( aBoundVolume
.getB3DPoint( i
) );
819 return aTransformed
.GetBoundRect();
822 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */