xref: /aoo41x/main/svx/source/engine3d/extrud3d.cxx (revision f6e50924)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "svx/svdstr.hrc"
28cdf0e10cSrcweir #include "svx/svdglob.hxx"
29cdf0e10cSrcweir #include <svx/svdpage.hxx>
30cdf0e10cSrcweir #include "svx/globl3d.hxx"
31cdf0e10cSrcweir #include <svx/extrud3d.hxx>
32cdf0e10cSrcweir #include <svx/scene3d.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <svx/svxids.hrc>
35cdf0e10cSrcweir #include <svx/xpoly.hxx>
36cdf0e10cSrcweir #include <svx/svdopath.hxx>
37cdf0e10cSrcweir #include <svx/svdmodel.hxx>
38cdf0e10cSrcweir #include <svx/svx3ditems.hxx>
39cdf0e10cSrcweir #include <svx/sdr/properties/e3dextrudeproperties.hxx>
40cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofe3dextrude.hxx>
41cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
42cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
43cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygontools.hxx>
44cdf0e10cSrcweir #include <basegfx/polygon/b3dpolypolygontools.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
47cdf0e10cSrcweir // #110094# DrawContact section
48cdf0e10cSrcweir 
CreateObjectSpecificViewContact()49cdf0e10cSrcweir sdr::contact::ViewContact* E3dExtrudeObj::CreateObjectSpecificViewContact()
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	return new sdr::contact::ViewContactOfE3dExtrude(*this);
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
55cdf0e10cSrcweir 
CreateObjectSpecificProperties()56cdf0e10cSrcweir sdr::properties::BaseProperties* E3dExtrudeObj::CreateObjectSpecificProperties()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir 	return new sdr::properties::E3dExtrudeProperties(*this);
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
62cdf0e10cSrcweir 
63cdf0e10cSrcweir TYPEINIT1(E3dExtrudeObj, E3dCompoundObject);
64cdf0e10cSrcweir 
65cdf0e10cSrcweir /*************************************************************************
66cdf0e10cSrcweir |*
67cdf0e10cSrcweir |* Konstruktor, erzeugt zwei Deckelflaechen-PolyPolygone und (PointCount-1)
68cdf0e10cSrcweir |* Seitenflaechen-Rechtecke aus dem uebergebenen PolyPolygon
69cdf0e10cSrcweir |*
70cdf0e10cSrcweir \************************************************************************/
71cdf0e10cSrcweir 
E3dExtrudeObj(E3dDefaultAttributes & rDefault,const basegfx::B2DPolyPolygon & rPP,double fDepth)72cdf0e10cSrcweir E3dExtrudeObj::E3dExtrudeObj(E3dDefaultAttributes& rDefault, const basegfx::B2DPolyPolygon& rPP, double fDepth)
73cdf0e10cSrcweir :	E3dCompoundObject(rDefault),
74cdf0e10cSrcweir 	maExtrudePolygon(rPP)
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	// since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
77cdf0e10cSrcweir 	basegfx::B2DHomMatrix aMirrorY;
78cdf0e10cSrcweir 	aMirrorY.scale(1.0, -1.0);
79cdf0e10cSrcweir 	maExtrudePolygon.transform(aMirrorY);
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	// Defaults setzen
82cdf0e10cSrcweir 	SetDefaultAttributes(rDefault);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	// set extrude depth
85cdf0e10cSrcweir 	GetProperties().SetObjectItemDirect(Svx3DDepthItem((sal_uInt32)(fDepth + 0.5)));
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
E3dExtrudeObj()88cdf0e10cSrcweir E3dExtrudeObj::E3dExtrudeObj()
89cdf0e10cSrcweir :	E3dCompoundObject()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	// Defaults setzen
92cdf0e10cSrcweir 	E3dDefaultAttributes aDefault;
93cdf0e10cSrcweir 	SetDefaultAttributes(aDefault);
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
SetDefaultAttributes(E3dDefaultAttributes & rDefault)96cdf0e10cSrcweir void E3dExtrudeObj::SetDefaultAttributes(E3dDefaultAttributes& rDefault)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultExtrudeSmoothed()));
99cdf0e10cSrcweir 	GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultExtrudeSmoothFrontBack()));
100cdf0e10cSrcweir 	GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultExtrudeCharacterMode()));
101cdf0e10cSrcweir 	GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultExtrudeCloseFront()));
102cdf0e10cSrcweir 	GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultExtrudeCloseBack()));
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	// Bei extrudes defaultmaessig StdTexture in X und Y
105cdf0e10cSrcweir 	GetProperties().SetObjectItemDirect(Svx3DTextureProjectionXItem(1));
106cdf0e10cSrcweir 	GetProperties().SetObjectItemDirect(Svx3DTextureProjectionYItem(1));
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir /*************************************************************************
110cdf0e10cSrcweir |*
111cdf0e10cSrcweir |* Identifier zurueckgeben
112cdf0e10cSrcweir |*
113cdf0e10cSrcweir \************************************************************************/
114cdf0e10cSrcweir 
GetObjIdentifier() const115cdf0e10cSrcweir sal_uInt16 E3dExtrudeObj::GetObjIdentifier() const
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	return E3D_EXTRUDEOBJ_ID;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir /*************************************************************************
121cdf0e10cSrcweir |*
122cdf0e10cSrcweir |* Zuweisungsoperator
123cdf0e10cSrcweir |*
124cdf0e10cSrcweir \************************************************************************/
125cdf0e10cSrcweir 
operator =(const SdrObject & rObj)126cdf0e10cSrcweir void E3dExtrudeObj::operator=(const SdrObject& rObj)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	// erstmal alle Childs kopieren
129cdf0e10cSrcweir 	E3dCompoundObject::operator=(rObj);
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	// weitere Parameter kopieren
132cdf0e10cSrcweir 	const E3dExtrudeObj& r3DObj = (const E3dExtrudeObj&)rObj;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	maExtrudePolygon = r3DObj.maExtrudePolygon;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir /*************************************************************************
138cdf0e10cSrcweir |*
139cdf0e10cSrcweir |* Lokale Parameter setzen mit Geometrieneuerzeugung
140cdf0e10cSrcweir |*
141cdf0e10cSrcweir \************************************************************************/
142cdf0e10cSrcweir 
SetExtrudePolygon(const basegfx::B2DPolyPolygon & rNew)143cdf0e10cSrcweir void E3dExtrudeObj::SetExtrudePolygon(const basegfx::B2DPolyPolygon &rNew)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	if(maExtrudePolygon != rNew)
146cdf0e10cSrcweir 	{
147cdf0e10cSrcweir 		maExtrudePolygon = rNew;
148cdf0e10cSrcweir 		ActionChanged();
149cdf0e10cSrcweir 	}
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir /*************************************************************************
153cdf0e10cSrcweir |*
154cdf0e10cSrcweir |* Get the name of the object (singular)
155cdf0e10cSrcweir |*
156cdf0e10cSrcweir \************************************************************************/
157cdf0e10cSrcweir 
TakeObjNameSingul(XubString & rName) const158cdf0e10cSrcweir void E3dExtrudeObj::TakeObjNameSingul(XubString& rName) const
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	rName=ImpGetResStr(STR_ObjNameSingulExtrude3d);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	String aName( GetName() );
163cdf0e10cSrcweir 	if(aName.Len())
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		rName += sal_Unicode(' ');
166cdf0e10cSrcweir 		rName += sal_Unicode('\'');
167cdf0e10cSrcweir 		rName += aName;
168cdf0e10cSrcweir 		rName += sal_Unicode('\'');
169cdf0e10cSrcweir 	}
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir /*************************************************************************
173cdf0e10cSrcweir |*
174cdf0e10cSrcweir |* Get the name of the object (plural)
175cdf0e10cSrcweir |*
176cdf0e10cSrcweir \************************************************************************/
177cdf0e10cSrcweir 
TakeObjNamePlural(XubString & rName) const178cdf0e10cSrcweir void E3dExtrudeObj::TakeObjNamePlural(XubString& rName) const
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	rName=ImpGetResStr(STR_ObjNamePluralExtrude3d);
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir /*************************************************************************
184cdf0e10cSrcweir |*
185cdf0e10cSrcweir |* Aufbrechen
186cdf0e10cSrcweir |*
187cdf0e10cSrcweir \************************************************************************/
188cdf0e10cSrcweir 
IsBreakObjPossible()189cdf0e10cSrcweir sal_Bool E3dExtrudeObj::IsBreakObjPossible()
190cdf0e10cSrcweir {
191cdf0e10cSrcweir 	return sal_True;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
GetBreakObj()194cdf0e10cSrcweir SdrAttrObj* E3dExtrudeObj::GetBreakObj()
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	basegfx::B3DPolyPolygon aFrontSide;
197cdf0e10cSrcweir 	basegfx::B3DPolyPolygon aBackSide;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 	if(maExtrudePolygon.count())
200cdf0e10cSrcweir 	{
201cdf0e10cSrcweir 		basegfx::B2DPolyPolygon aTemp(maExtrudePolygon);
202cdf0e10cSrcweir 		aTemp.removeDoublePoints();
203cdf0e10cSrcweir 		aTemp = basegfx::tools::correctOrientations(aTemp);
204cdf0e10cSrcweir 		const basegfx::B2VectorOrientation aOrient = basegfx::tools::getOrientation(aTemp.getB2DPolygon(0L));
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 		if(basegfx::ORIENTATION_POSITIVE == aOrient)
207cdf0e10cSrcweir 		{
208cdf0e10cSrcweir 			aTemp.flip();
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 		aFrontSide = basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(aTemp);
212cdf0e10cSrcweir 	}
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     if(aFrontSide.count())
215cdf0e10cSrcweir     {
216cdf0e10cSrcweir         aBackSide = aFrontSide;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 	    if(GetExtrudeDepth())
219cdf0e10cSrcweir 	    {
220cdf0e10cSrcweir 		    basegfx::B3DHomMatrix aTransform;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir             if(100 != GetPercentBackScale())
223cdf0e10cSrcweir 		    {
224cdf0e10cSrcweir                 // scale polygon from center
225cdf0e10cSrcweir                 const double fScaleFactor(GetPercentBackScale() / 100.0);
226cdf0e10cSrcweir 	            const basegfx::B3DRange aPolyPolyRange(basegfx::tools::getRange(aBackSide));
227cdf0e10cSrcweir 	            const basegfx::B3DPoint aCenter(aPolyPolyRange.getCenter());
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	            aTransform.translate(-aCenter.getX(), -aCenter.getY(), -aCenter.getZ());
230cdf0e10cSrcweir 	            aTransform.scale(fScaleFactor, fScaleFactor, fScaleFactor);
231cdf0e10cSrcweir 	            aTransform.translate(aCenter.getX(), aCenter.getY(), aCenter.getZ());
232cdf0e10cSrcweir 		    }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir             // translate by extrude depth
235cdf0e10cSrcweir 		    aTransform.translate(0.0, 0.0, (double)GetExtrudeDepth());
236cdf0e10cSrcweir 
237cdf0e10cSrcweir             aBackSide.transform(aTransform);
238cdf0e10cSrcweir 	    }
239cdf0e10cSrcweir     }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     if(aBackSide.count())
242cdf0e10cSrcweir     {
243cdf0e10cSrcweir 	// create PathObj
244cdf0e10cSrcweir 	    basegfx::B2DPolyPolygon aPoly = TransformToScreenCoor(aBackSide);
245cdf0e10cSrcweir 		SdrPathObj* pPathObj = new SdrPathObj(OBJ_PLIN, aPoly);
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 		if(pPathObj)
248cdf0e10cSrcweir 		{
249cdf0e10cSrcweir 			SfxItemSet aSet(GetObjectItemSet());
250cdf0e10cSrcweir 			aSet.Put(XLineStyleItem(XLINE_SOLID));
251cdf0e10cSrcweir 			pPathObj->SetMergedItemSet(aSet);
252cdf0e10cSrcweir 		}
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 		return pPathObj;
255cdf0e10cSrcweir 	}
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     return 0;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir // eof
261