1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: extrud3d.cxx,v $
10 * $Revision: 1.25.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
35 #include "svdglob.hxx"
36 #include <svx/svdpage.hxx>
37 #include "globl3d.hxx"
38 #include <svx/extrud3d.hxx>
39 #include <svx/scene3d.hxx>
41 #include <svx/svxids.hrc>
42 #include <svx/xpoly.hxx>
43 #include <svx/svdopath.hxx>
44 #include <svx/svdmodel.hxx>
45 #include <svx/svx3ditems.hxx>
46 #include <svx/sdr/properties/e3dextrudeproperties.hxx>
47 #include <svx/sdr/contact/viewcontactofe3dextrude.hxx>
48 #include <basegfx/polygon/b2dpolypolygontools.hxx>
49 #include <basegfx/polygon/b2dpolygontools.hxx>
50 #include <basegfx/polygon/b3dpolygontools.hxx>
51 #include <basegfx/polygon/b3dpolypolygontools.hxx>
53 //////////////////////////////////////////////////////////////////////////////
54 // #110094# DrawContact section
56 sdr::contact::ViewContact
* E3dExtrudeObj::CreateObjectSpecificViewContact()
58 return new sdr::contact::ViewContactOfE3dExtrude(*this);
61 //////////////////////////////////////////////////////////////////////////////
63 sdr::properties::BaseProperties
* E3dExtrudeObj::CreateObjectSpecificProperties()
65 return new sdr::properties::E3dExtrudeProperties(*this);
68 //////////////////////////////////////////////////////////////////////////////
70 TYPEINIT1(E3dExtrudeObj
, E3dCompoundObject
);
72 /*************************************************************************
74 |* Konstruktor, erzeugt zwei Deckelflaechen-PolyPolygone und (PointCount-1)
75 |* Seitenflaechen-Rechtecke aus dem uebergebenen PolyPolygon
77 \************************************************************************/
79 E3dExtrudeObj::E3dExtrudeObj(E3dDefaultAttributes
& rDefault
, const basegfx::B2DPolyPolygon
& rPP
, double fDepth
)
80 : E3dCompoundObject(rDefault
),
83 // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
84 basegfx::B2DHomMatrix aMirrorY
;
85 aMirrorY
.scale(1.0, -1.0);
86 maExtrudePolygon
.transform(aMirrorY
);
89 SetDefaultAttributes(rDefault
);
92 GetProperties().SetObjectItemDirect(Svx3DDepthItem((sal_uInt32
)(fDepth
+ 0.5)));
95 E3dExtrudeObj::E3dExtrudeObj()
99 E3dDefaultAttributes aDefault
;
100 SetDefaultAttributes(aDefault
);
103 void E3dExtrudeObj::SetDefaultAttributes(E3dDefaultAttributes
& rDefault
)
105 GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault
.GetDefaultExtrudeSmoothed()));
106 GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault
.GetDefaultExtrudeSmoothFrontBack()));
107 GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault
.GetDefaultExtrudeCharacterMode()));
108 GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault
.GetDefaultExtrudeCloseFront()));
109 GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault
.GetDefaultExtrudeCloseBack()));
111 // Bei extrudes defaultmaessig StdTexture in X und Y
112 GetProperties().SetObjectItemDirect(Svx3DTextureProjectionXItem(1));
113 GetProperties().SetObjectItemDirect(Svx3DTextureProjectionYItem(1));
116 /*************************************************************************
118 |* Identifier zurueckgeben
120 \************************************************************************/
122 UINT16
E3dExtrudeObj::GetObjIdentifier() const
124 return E3D_EXTRUDEOBJ_ID
;
127 /*************************************************************************
129 |* Zuweisungsoperator
131 \************************************************************************/
133 void E3dExtrudeObj::operator=(const SdrObject
& rObj
)
135 // erstmal alle Childs kopieren
136 E3dCompoundObject::operator=(rObj
);
138 // weitere Parameter kopieren
139 const E3dExtrudeObj
& r3DObj
= (const E3dExtrudeObj
&)rObj
;
141 maExtrudePolygon
= r3DObj
.maExtrudePolygon
;
144 /*************************************************************************
146 |* Lokale Parameter setzen mit Geometrieneuerzeugung
148 \************************************************************************/
150 void E3dExtrudeObj::SetExtrudePolygon(const basegfx::B2DPolyPolygon
&rNew
)
152 if(maExtrudePolygon
!= rNew
)
154 maExtrudePolygon
= rNew
;
159 /*************************************************************************
161 |* Get the name of the object (singular)
163 \************************************************************************/
165 void E3dExtrudeObj::TakeObjNameSingul(XubString
& rName
) const
167 rName
=ImpGetResStr(STR_ObjNameSingulExtrude3d
);
169 String
aName( GetName() );
172 rName
+= sal_Unicode(' ');
173 rName
+= sal_Unicode('\'');
175 rName
+= sal_Unicode('\'');
179 /*************************************************************************
181 |* Get the name of the object (plural)
183 \************************************************************************/
185 void E3dExtrudeObj::TakeObjNamePlural(XubString
& rName
) const
187 rName
=ImpGetResStr(STR_ObjNamePluralExtrude3d
);
190 /*************************************************************************
194 \************************************************************************/
196 BOOL
E3dExtrudeObj::IsBreakObjPossible()
201 SdrAttrObj
* E3dExtrudeObj::GetBreakObj()
203 basegfx::B3DPolyPolygon aFrontSide
;
204 basegfx::B3DPolyPolygon aBackSide
;
206 if(maExtrudePolygon
.count())
208 basegfx::B2DPolyPolygon
aTemp(maExtrudePolygon
);
209 aTemp
.removeDoublePoints();
210 aTemp
= basegfx::tools::correctOrientations(aTemp
);
211 const basegfx::B2VectorOrientation aOrient
= basegfx::tools::getOrientation(aTemp
.getB2DPolygon(0L));
213 if(basegfx::ORIENTATION_POSITIVE
== aOrient
)
218 aFrontSide
= basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(aTemp
);
221 if(aFrontSide
.count())
223 aBackSide
= aFrontSide
;
225 if(GetExtrudeDepth())
227 basegfx::B3DHomMatrix aTransform
;
229 if(100 != GetPercentBackScale())
231 // scale polygon from center
232 const double fScaleFactor(GetPercentBackScale() / 100.0);
233 const basegfx::B3DRange
aPolyPolyRange(basegfx::tools::getRange(aBackSide
));
234 const basegfx::B3DPoint
aCenter(aPolyPolyRange
.getCenter());
236 aTransform
.translate(-aCenter
.getX(), -aCenter
.getY(), -aCenter
.getZ());
237 aTransform
.scale(fScaleFactor
, fScaleFactor
, fScaleFactor
);
238 aTransform
.translate(aCenter
.getX(), aCenter
.getY(), aCenter
.getZ());
241 // translate by extrude depth
242 aTransform
.translate(0.0, 0.0, (double)GetExtrudeDepth());
244 aBackSide
.transform(aTransform
);
248 if(aBackSide
.count())
251 basegfx::B2DPolyPolygon aPoly
= TransformToScreenCoor(aBackSide
);
252 SdrPathObj
* pPathObj
= new SdrPathObj(OBJ_PLIN
, aPoly
);
256 SfxItemSet
aSet(GetObjectItemSet());
257 aSet
.Put(XLineStyleItem(XLINE_SOLID
));
258 pPathObj
->SetMergedItemSet(aSet
);