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