xref: /trunk/main/svx/source/engine3d/extrud3d.cxx (revision f6e50924)
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 
27 #include "svx/svdstr.hrc"
28 #include "svx/svdglob.hxx"
29 #include <svx/svdpage.hxx>
30 #include "svx/globl3d.hxx"
31 #include <svx/extrud3d.hxx>
32 #include <svx/scene3d.hxx>
33 
34 #include <svx/svxids.hrc>
35 #include <svx/xpoly.hxx>
36 #include <svx/svdopath.hxx>
37 #include <svx/svdmodel.hxx>
38 #include <svx/svx3ditems.hxx>
39 #include <svx/sdr/properties/e3dextrudeproperties.hxx>
40 #include <svx/sdr/contact/viewcontactofe3dextrude.hxx>
41 #include <basegfx/polygon/b2dpolypolygontools.hxx>
42 #include <basegfx/polygon/b2dpolygontools.hxx>
43 #include <basegfx/polygon/b3dpolygontools.hxx>
44 #include <basegfx/polygon/b3dpolypolygontools.hxx>
45 
46 //////////////////////////////////////////////////////////////////////////////
47 // #110094# DrawContact section
48 
CreateObjectSpecificViewContact()49 sdr::contact::ViewContact* E3dExtrudeObj::CreateObjectSpecificViewContact()
50 {
51 	return new sdr::contact::ViewContactOfE3dExtrude(*this);
52 }
53 
54 //////////////////////////////////////////////////////////////////////////////
55 
CreateObjectSpecificProperties()56 sdr::properties::BaseProperties* E3dExtrudeObj::CreateObjectSpecificProperties()
57 {
58 	return new sdr::properties::E3dExtrudeProperties(*this);
59 }
60 
61 //////////////////////////////////////////////////////////////////////////////
62 
63 TYPEINIT1(E3dExtrudeObj, E3dCompoundObject);
64 
65 /*************************************************************************
66 |*
67 |* Konstruktor, erzeugt zwei Deckelflaechen-PolyPolygone und (PointCount-1)
68 |* Seitenflaechen-Rechtecke aus dem uebergebenen PolyPolygon
69 |*
70 \************************************************************************/
71 
E3dExtrudeObj(E3dDefaultAttributes & rDefault,const basegfx::B2DPolyPolygon & rPP,double fDepth)72 E3dExtrudeObj::E3dExtrudeObj(E3dDefaultAttributes& rDefault, const basegfx::B2DPolyPolygon& rPP, double fDepth)
73 :	E3dCompoundObject(rDefault),
74 	maExtrudePolygon(rPP)
75 {
76 	// since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
77 	basegfx::B2DHomMatrix aMirrorY;
78 	aMirrorY.scale(1.0, -1.0);
79 	maExtrudePolygon.transform(aMirrorY);
80 
81 	// Defaults setzen
82 	SetDefaultAttributes(rDefault);
83 
84 	// set extrude depth
85 	GetProperties().SetObjectItemDirect(Svx3DDepthItem((sal_uInt32)(fDepth + 0.5)));
86 }
87 
E3dExtrudeObj()88 E3dExtrudeObj::E3dExtrudeObj()
89 :	E3dCompoundObject()
90 {
91 	// Defaults setzen
92 	E3dDefaultAttributes aDefault;
93 	SetDefaultAttributes(aDefault);
94 }
95 
SetDefaultAttributes(E3dDefaultAttributes & rDefault)96 void E3dExtrudeObj::SetDefaultAttributes(E3dDefaultAttributes& rDefault)
97 {
98 	GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultExtrudeSmoothed()));
99 	GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultExtrudeSmoothFrontBack()));
100 	GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultExtrudeCharacterMode()));
101 	GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultExtrudeCloseFront()));
102 	GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultExtrudeCloseBack()));
103 
104 	// Bei extrudes defaultmaessig StdTexture in X und Y
105 	GetProperties().SetObjectItemDirect(Svx3DTextureProjectionXItem(1));
106 	GetProperties().SetObjectItemDirect(Svx3DTextureProjectionYItem(1));
107 }
108 
109 /*************************************************************************
110 |*
111 |* Identifier zurueckgeben
112 |*
113 \************************************************************************/
114 
GetObjIdentifier() const115 sal_uInt16 E3dExtrudeObj::GetObjIdentifier() const
116 {
117 	return E3D_EXTRUDEOBJ_ID;
118 }
119 
120 /*************************************************************************
121 |*
122 |* Zuweisungsoperator
123 |*
124 \************************************************************************/
125 
operator =(const SdrObject & rObj)126 void E3dExtrudeObj::operator=(const SdrObject& rObj)
127 {
128 	// erstmal alle Childs kopieren
129 	E3dCompoundObject::operator=(rObj);
130 
131 	// weitere Parameter kopieren
132 	const E3dExtrudeObj& r3DObj = (const E3dExtrudeObj&)rObj;
133 
134 	maExtrudePolygon = r3DObj.maExtrudePolygon;
135 }
136 
137 /*************************************************************************
138 |*
139 |* Lokale Parameter setzen mit Geometrieneuerzeugung
140 |*
141 \************************************************************************/
142 
SetExtrudePolygon(const basegfx::B2DPolyPolygon & rNew)143 void E3dExtrudeObj::SetExtrudePolygon(const basegfx::B2DPolyPolygon &rNew)
144 {
145 	if(maExtrudePolygon != rNew)
146 	{
147 		maExtrudePolygon = rNew;
148 		ActionChanged();
149 	}
150 }
151 
152 /*************************************************************************
153 |*
154 |* Get the name of the object (singular)
155 |*
156 \************************************************************************/
157 
TakeObjNameSingul(XubString & rName) const158 void E3dExtrudeObj::TakeObjNameSingul(XubString& rName) const
159 {
160 	rName=ImpGetResStr(STR_ObjNameSingulExtrude3d);
161 
162 	String aName( GetName() );
163 	if(aName.Len())
164 	{
165 		rName += sal_Unicode(' ');
166 		rName += sal_Unicode('\'');
167 		rName += aName;
168 		rName += sal_Unicode('\'');
169 	}
170 }
171 
172 /*************************************************************************
173 |*
174 |* Get the name of the object (plural)
175 |*
176 \************************************************************************/
177 
TakeObjNamePlural(XubString & rName) const178 void E3dExtrudeObj::TakeObjNamePlural(XubString& rName) const
179 {
180 	rName=ImpGetResStr(STR_ObjNamePluralExtrude3d);
181 }
182 
183 /*************************************************************************
184 |*
185 |* Aufbrechen
186 |*
187 \************************************************************************/
188 
IsBreakObjPossible()189 sal_Bool E3dExtrudeObj::IsBreakObjPossible()
190 {
191 	return sal_True;
192 }
193 
GetBreakObj()194 SdrAttrObj* E3dExtrudeObj::GetBreakObj()
195 {
196 	basegfx::B3DPolyPolygon aFrontSide;
197 	basegfx::B3DPolyPolygon aBackSide;
198 
199 	if(maExtrudePolygon.count())
200 	{
201 		basegfx::B2DPolyPolygon aTemp(maExtrudePolygon);
202 		aTemp.removeDoublePoints();
203 		aTemp = basegfx::tools::correctOrientations(aTemp);
204 		const basegfx::B2VectorOrientation aOrient = basegfx::tools::getOrientation(aTemp.getB2DPolygon(0L));
205 
206 		if(basegfx::ORIENTATION_POSITIVE == aOrient)
207 		{
208 			aTemp.flip();
209 		}
210 
211 		aFrontSide = basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(aTemp);
212 	}
213 
214     if(aFrontSide.count())
215     {
216         aBackSide = aFrontSide;
217 
218 	    if(GetExtrudeDepth())
219 	    {
220 		    basegfx::B3DHomMatrix aTransform;
221 
222             if(100 != GetPercentBackScale())
223 		    {
224                 // scale polygon from center
225                 const double fScaleFactor(GetPercentBackScale() / 100.0);
226 	            const basegfx::B3DRange aPolyPolyRange(basegfx::tools::getRange(aBackSide));
227 	            const basegfx::B3DPoint aCenter(aPolyPolyRange.getCenter());
228 
229 	            aTransform.translate(-aCenter.getX(), -aCenter.getY(), -aCenter.getZ());
230 	            aTransform.scale(fScaleFactor, fScaleFactor, fScaleFactor);
231 	            aTransform.translate(aCenter.getX(), aCenter.getY(), aCenter.getZ());
232 		    }
233 
234             // translate by extrude depth
235 		    aTransform.translate(0.0, 0.0, (double)GetExtrudeDepth());
236 
237             aBackSide.transform(aTransform);
238 	    }
239     }
240 
241     if(aBackSide.count())
242     {
243 	// create PathObj
244 	    basegfx::B2DPolyPolygon aPoly = TransformToScreenCoor(aBackSide);
245 		SdrPathObj* pPathObj = new SdrPathObj(OBJ_PLIN, aPoly);
246 
247 		if(pPathObj)
248 		{
249 			SfxItemSet aSet(GetObjectItemSet());
250 			aSet.Put(XLineStyleItem(XLINE_SOLID));
251 			pPathObj->SetMergedItemSet(aSet);
252 		}
253 
254 		return pPathObj;
255 	}
256 
257     return 0;
258 }
259 
260 // eof
261