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