xref: /AOO41X/main/svx/source/engine3d/polygn3d.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir #include <svx/polygn3d.hxx>
31*cdf0e10cSrcweir #include <svx/svdpage.hxx>
32*cdf0e10cSrcweir #include "svx/globl3d.hxx"
33*cdf0e10cSrcweir #include <basegfx/point/b3dpoint.hxx>
34*cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofe3dpolygon.hxx>
35*cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygon.hxx>
36*cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygontools.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir TYPEINIT1(E3dPolygonObj, E3dCompoundObject);
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
41*cdf0e10cSrcweir // #110094# DrawContact section
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir sdr::contact::ViewContact* E3dPolygonObj::CreateObjectSpecificViewContact()
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir 	return new sdr::contact::ViewContactOfE3dPolygon(*this);
46*cdf0e10cSrcweir }
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir /*************************************************************************
49*cdf0e10cSrcweir |*
50*cdf0e10cSrcweir |* Konstruktor
51*cdf0e10cSrcweir |*
52*cdf0e10cSrcweir \************************************************************************/
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir E3dPolygonObj::E3dPolygonObj(
55*cdf0e10cSrcweir 	E3dDefaultAttributes& rDefault,
56*cdf0e10cSrcweir 	const basegfx::B3DPolyPolygon& rPolyPoly3D,
57*cdf0e10cSrcweir 	sal_Bool bLinOnly)
58*cdf0e10cSrcweir :	E3dCompoundObject(rDefault),
59*cdf0e10cSrcweir 	bLineOnly(bLinOnly)
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir 	// Geometrie setzen
62*cdf0e10cSrcweir 	SetPolyPolygon3D(rPolyPoly3D);
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 	// Default-Normals erzeugen
65*cdf0e10cSrcweir 	CreateDefaultNormals();
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 	// Default-Texturkoordinaten erzeugen
68*cdf0e10cSrcweir 	CreateDefaultTexture();
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir /*************************************************************************
72*cdf0e10cSrcweir |*
73*cdf0e10cSrcweir |* Konstruktor
74*cdf0e10cSrcweir |*
75*cdf0e10cSrcweir \************************************************************************/
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir E3dPolygonObj::E3dPolygonObj(
78*cdf0e10cSrcweir 	E3dDefaultAttributes& rDefault,
79*cdf0e10cSrcweir 	const basegfx::B3DPolyPolygon& rPolyPoly3D,
80*cdf0e10cSrcweir 	const basegfx::B3DPolyPolygon& rPolyNormals3D,
81*cdf0e10cSrcweir 	sal_Bool bLinOnly)
82*cdf0e10cSrcweir :	E3dCompoundObject(rDefault),
83*cdf0e10cSrcweir 	bLineOnly(bLinOnly)
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir 	// Geometrie und Normalen setzen
86*cdf0e10cSrcweir 	SetPolyPolygon3D(rPolyPoly3D);
87*cdf0e10cSrcweir 	SetPolyNormals3D(rPolyNormals3D);
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	// Default-Texturkoordinaten erzeugen
90*cdf0e10cSrcweir 	CreateDefaultTexture();
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir /*************************************************************************
94*cdf0e10cSrcweir |*
95*cdf0e10cSrcweir |* Konstruktor
96*cdf0e10cSrcweir |*
97*cdf0e10cSrcweir \************************************************************************/
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir E3dPolygonObj::E3dPolygonObj(
100*cdf0e10cSrcweir 	E3dDefaultAttributes& rDefault,
101*cdf0e10cSrcweir 	const basegfx::B3DPolyPolygon& rPolyPoly3D,
102*cdf0e10cSrcweir 	const basegfx::B3DPolyPolygon& rPolyNormals3D,
103*cdf0e10cSrcweir 	const basegfx::B2DPolyPolygon& rPolyTexture2D,
104*cdf0e10cSrcweir 	sal_Bool bLinOnly)
105*cdf0e10cSrcweir :	E3dCompoundObject(rDefault),
106*cdf0e10cSrcweir 	bLineOnly(bLinOnly)
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	SetPolyPolygon3D(rPolyPoly3D);
109*cdf0e10cSrcweir 	SetPolyNormals3D(rPolyNormals3D);
110*cdf0e10cSrcweir 	SetPolyTexture2D(rPolyTexture2D);
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir /*************************************************************************
114*cdf0e10cSrcweir |*
115*cdf0e10cSrcweir |* Leer-Konstruktor
116*cdf0e10cSrcweir |*
117*cdf0e10cSrcweir \************************************************************************/
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir E3dPolygonObj::E3dPolygonObj()
120*cdf0e10cSrcweir :	E3dCompoundObject(),
121*cdf0e10cSrcweir 	bLineOnly(false) // added missing initialisation
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	// Keine Geometrie erzeugen
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir /*************************************************************************
127*cdf0e10cSrcweir |*
128*cdf0e10cSrcweir |* Default-Normalen erzeugen
129*cdf0e10cSrcweir |*
130*cdf0e10cSrcweir \************************************************************************/
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir void E3dPolygonObj::CreateDefaultNormals()
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir 	basegfx::B3DPolyPolygon aPolyNormals;
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 	// Komplettes PolyPolygon mit den Ebenennormalen anlegen
137*cdf0e10cSrcweir 	for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++)
138*cdf0e10cSrcweir 	{
139*cdf0e10cSrcweir 		// Quellpolygon finden
140*cdf0e10cSrcweir 		const basegfx::B3DPolygon aPolygon(aPolyPoly3D.getB3DPolygon(a));
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 		// Neues Polygon fuer Normalen anlegen
143*cdf0e10cSrcweir 		basegfx::B3DPolygon aNormals;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 		// Normale holen (und umdrehen)
146*cdf0e10cSrcweir 		basegfx::B3DVector aNormal(-basegfx::tools::getNormal(aPolygon));
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 		// Neues Polygon fuellen
149*cdf0e10cSrcweir 		for(sal_uInt32 b(0L); b < aPolygon.count(); b++)
150*cdf0e10cSrcweir 		{
151*cdf0e10cSrcweir 			aNormals.append(aNormal);
152*cdf0e10cSrcweir 		}
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 		// Neues Polygon in PolyPolygon einfuegen
155*cdf0e10cSrcweir 		aPolyNormals.append(aNormals);
156*cdf0e10cSrcweir 	}
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	// Default-Normalen setzen
159*cdf0e10cSrcweir 	SetPolyNormals3D(aPolyNormals);
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir /*************************************************************************
163*cdf0e10cSrcweir |*
164*cdf0e10cSrcweir |* Default-Texturkoordinaten erzeugen
165*cdf0e10cSrcweir |*
166*cdf0e10cSrcweir \************************************************************************/
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir void E3dPolygonObj::CreateDefaultTexture()
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir 	basegfx::B2DPolyPolygon aPolyTexture;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 	// Komplettes PolyPolygon mit den Texturkoordinaten anlegen
173*cdf0e10cSrcweir 	// Die Texturkoordinaten erstrecken sich ueber X,Y und Z
174*cdf0e10cSrcweir 	// ueber die gesamten Extremwerte im Bereich 0.0 .. 1.0
175*cdf0e10cSrcweir 	for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++)
176*cdf0e10cSrcweir 	{
177*cdf0e10cSrcweir 		// Quellpolygon finden
178*cdf0e10cSrcweir 		const basegfx::B3DPolygon& aPolygon(aPolyPoly3D.getB3DPolygon(a));
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 		// Gesamtgroesse des Objektes feststellen
181*cdf0e10cSrcweir 		basegfx::B3DRange aVolume(basegfx::tools::getRange(aPolygon));
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 		// Normale holen
184*cdf0e10cSrcweir 		basegfx::B3DVector aNormal(basegfx::tools::getNormal(aPolygon));
185*cdf0e10cSrcweir 		aNormal.setX(fabs(aNormal.getX()));
186*cdf0e10cSrcweir 		aNormal.setY(fabs(aNormal.getY()));
187*cdf0e10cSrcweir 		aNormal.setZ(fabs(aNormal.getZ()));
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 		// Entscheiden, welche Koordinaten als Source fuer das
190*cdf0e10cSrcweir 		// Mapping benutzt werden sollen
191*cdf0e10cSrcweir 		sal_uInt16 nSourceMode = 0;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 		// Groessten Freiheitsgrad ermitteln
194*cdf0e10cSrcweir 		if(!(aNormal.getX() > aNormal.getY() && aNormal.getX() > aNormal.getZ()))
195*cdf0e10cSrcweir 		{
196*cdf0e10cSrcweir 			if(aNormal.getY() > aNormal.getZ())
197*cdf0e10cSrcweir 			{
198*cdf0e10cSrcweir 				// Y ist am groessten, benutze X,Z als mapping
199*cdf0e10cSrcweir 				nSourceMode = 1;
200*cdf0e10cSrcweir 			}
201*cdf0e10cSrcweir 			else
202*cdf0e10cSrcweir 			{
203*cdf0e10cSrcweir 				// Z ist am groessten, benutze X,Y als mapping
204*cdf0e10cSrcweir 				nSourceMode = 2;
205*cdf0e10cSrcweir 			}
206*cdf0e10cSrcweir 		}
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 		// Neues Polygon fuer Texturkoordinaten anlegen
209*cdf0e10cSrcweir 		basegfx::B2DPolygon aTexture;
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 		// Neues Polygon fuellen
212*cdf0e10cSrcweir 		for(sal_uInt32 b(0L); b < aPolygon.count(); b++)
213*cdf0e10cSrcweir 		{
214*cdf0e10cSrcweir 			basegfx::B2DPoint aTex;
215*cdf0e10cSrcweir 			const basegfx::B3DPoint aCandidate(aPolygon.getB3DPoint(b));
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 			switch(nSourceMode)
218*cdf0e10cSrcweir 			{
219*cdf0e10cSrcweir 				case 0:	// Quelle ist Y,Z
220*cdf0e10cSrcweir 					if(aVolume.getHeight())
221*cdf0e10cSrcweir 						aTex.setX((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
222*cdf0e10cSrcweir 					if(aVolume.getDepth())
223*cdf0e10cSrcweir 						aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
224*cdf0e10cSrcweir 					break;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 				case 1:	// Quelle ist X,Z
227*cdf0e10cSrcweir 					if(aVolume.getWidth())
228*cdf0e10cSrcweir 						aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
229*cdf0e10cSrcweir 					if(aVolume.getDepth())
230*cdf0e10cSrcweir 						aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
231*cdf0e10cSrcweir 					break;
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 				case 2:	// Quelle ist X,Y
234*cdf0e10cSrcweir 					if(aVolume.getWidth())
235*cdf0e10cSrcweir 						aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
236*cdf0e10cSrcweir 					if(aVolume.getHeight())
237*cdf0e10cSrcweir 						aTex.setY((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
238*cdf0e10cSrcweir 					break;
239*cdf0e10cSrcweir 			}
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 			aTexture.append(aTex);
242*cdf0e10cSrcweir 		}
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 		// Neues Polygon in PolyPolygon einfuegen
245*cdf0e10cSrcweir 		aPolyTexture.append(aTexture);
246*cdf0e10cSrcweir 	}
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 	// Default-Texturkoordinaten setzen
249*cdf0e10cSrcweir 	SetPolyTexture2D(aPolyTexture);
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir /*************************************************************************
253*cdf0e10cSrcweir |*
254*cdf0e10cSrcweir |* Destruktor
255*cdf0e10cSrcweir |*
256*cdf0e10cSrcweir \************************************************************************/
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir E3dPolygonObj::~E3dPolygonObj()
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir /*************************************************************************
263*cdf0e10cSrcweir |*
264*cdf0e10cSrcweir |* Identifier zurueckgeben
265*cdf0e10cSrcweir |*
266*cdf0e10cSrcweir \************************************************************************/
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir sal_uInt16 E3dPolygonObj::GetObjIdentifier() const
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir 	return E3D_POLYGONOBJ_ID;
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir /*************************************************************************
274*cdf0e10cSrcweir |*
275*cdf0e10cSrcweir |* Polygon setzen
276*cdf0e10cSrcweir |*
277*cdf0e10cSrcweir \************************************************************************/
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir void E3dPolygonObj::SetPolyPolygon3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D)
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir 	if ( aPolyPoly3D != rNewPolyPoly3D )
282*cdf0e10cSrcweir 	{
283*cdf0e10cSrcweir 		// Neues PolyPolygon; kopieren
284*cdf0e10cSrcweir 		aPolyPoly3D = rNewPolyPoly3D;
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 		// Geometrie neu erzeugen
287*cdf0e10cSrcweir 		ActionChanged();
288*cdf0e10cSrcweir 	}
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir void E3dPolygonObj::SetPolyNormals3D(const basegfx::B3DPolyPolygon& rNewPolyNormals3D)
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir 	if ( aPolyNormals3D != rNewPolyNormals3D )
294*cdf0e10cSrcweir 	{
295*cdf0e10cSrcweir 		// Neue Normalen; kopieren
296*cdf0e10cSrcweir 		aPolyNormals3D = rNewPolyNormals3D;
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 		// Geometrie neu erzeugen
299*cdf0e10cSrcweir 		ActionChanged();
300*cdf0e10cSrcweir 	}
301*cdf0e10cSrcweir }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir void E3dPolygonObj::SetPolyTexture2D(const basegfx::B2DPolyPolygon& rNewPolyTexture2D)
304*cdf0e10cSrcweir {
305*cdf0e10cSrcweir 	if ( aPolyTexture2D != rNewPolyTexture2D )
306*cdf0e10cSrcweir 	{
307*cdf0e10cSrcweir 		// Neue Texturkoordinaten; kopieren
308*cdf0e10cSrcweir 		aPolyTexture2D = rNewPolyTexture2D;
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 		// Geometrie neu erzeugen
311*cdf0e10cSrcweir 		ActionChanged();
312*cdf0e10cSrcweir 	}
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir /*************************************************************************
316*cdf0e10cSrcweir |*
317*cdf0e10cSrcweir |* Wandle das Objekt in ein Gruppenobjekt bestehend aus 6 Polygonen
318*cdf0e10cSrcweir |*
319*cdf0e10cSrcweir \************************************************************************/
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir SdrObject *E3dPolygonObj::DoConvertToPolyObj(sal_Bool /*bBezier*/) const
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir 	return NULL;
324*cdf0e10cSrcweir }
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir /*************************************************************************
327*cdf0e10cSrcweir |*
328*cdf0e10cSrcweir |* Zuweisungsoperator
329*cdf0e10cSrcweir |*
330*cdf0e10cSrcweir \************************************************************************/
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir void E3dPolygonObj::operator=(const SdrObject& rObj)
333*cdf0e10cSrcweir {
334*cdf0e10cSrcweir 	// erstmal alle Childs kopieren
335*cdf0e10cSrcweir 	E3dCompoundObject::operator=(rObj);
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir 	// weitere Parameter kopieren
338*cdf0e10cSrcweir 	const E3dPolygonObj& r3DObj = (const E3dPolygonObj&)rObj;
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 	aPolyPoly3D		 = r3DObj.aPolyPoly3D;
341*cdf0e10cSrcweir 	aPolyNormals3D	 = r3DObj.aPolyNormals3D;
342*cdf0e10cSrcweir 	aPolyTexture2D	 = r3DObj.aPolyTexture2D;
343*cdf0e10cSrcweir 	bLineOnly		 = r3DObj.bLineOnly;
344*cdf0e10cSrcweir }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir /*************************************************************************
347*cdf0e10cSrcweir |*
348*cdf0e10cSrcweir |* LineOnly setzen
349*cdf0e10cSrcweir |*
350*cdf0e10cSrcweir \************************************************************************/
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir void E3dPolygonObj::SetLineOnly(sal_Bool bNew)
353*cdf0e10cSrcweir {
354*cdf0e10cSrcweir 	if(bNew != bLineOnly)
355*cdf0e10cSrcweir 	{
356*cdf0e10cSrcweir 		bLineOnly = bNew;
357*cdf0e10cSrcweir 		ActionChanged();
358*cdf0e10cSrcweir 	}
359*cdf0e10cSrcweir }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir // eof
362