Update ooo320-m1
[ooovba.git] / svx / source / engine3d / polygn3d.cxx
blob68e9e3833a7103db6d66fd8a210f14d1fc839a0b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: polygn3d.cxx,v $
10 * $Revision: 1.17.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"
33 #include <svx/polygn3d.hxx>
34 #include <svx/svdpage.hxx>
35 #include "globl3d.hxx"
36 #include <basegfx/point/b3dpoint.hxx>
37 #include <svx/sdr/contact/viewcontactofe3dpolygon.hxx>
38 #include <basegfx/polygon/b3dpolygon.hxx>
39 #include <basegfx/polygon/b3dpolygontools.hxx>
41 TYPEINIT1(E3dPolygonObj, E3dCompoundObject);
43 //////////////////////////////////////////////////////////////////////////////
44 // #110094# DrawContact section
46 sdr::contact::ViewContact* E3dPolygonObj::CreateObjectSpecificViewContact()
48 return new sdr::contact::ViewContactOfE3dPolygon(*this);
51 /*************************************************************************
53 |* Konstruktor
55 \************************************************************************/
57 E3dPolygonObj::E3dPolygonObj(
58 E3dDefaultAttributes& rDefault,
59 const basegfx::B3DPolyPolygon& rPolyPoly3D,
60 BOOL bLinOnly)
61 : E3dCompoundObject(rDefault),
62 bLineOnly(bLinOnly)
64 // Geometrie setzen
65 SetPolyPolygon3D(rPolyPoly3D);
67 // Default-Normals erzeugen
68 CreateDefaultNormals();
70 // Default-Texturkoordinaten erzeugen
71 CreateDefaultTexture();
74 /*************************************************************************
76 |* Konstruktor
78 \************************************************************************/
80 E3dPolygonObj::E3dPolygonObj(
81 E3dDefaultAttributes& rDefault,
82 const basegfx::B3DPolyPolygon& rPolyPoly3D,
83 const basegfx::B3DPolyPolygon& rPolyNormals3D,
84 BOOL bLinOnly)
85 : E3dCompoundObject(rDefault),
86 bLineOnly(bLinOnly)
88 // Geometrie und Normalen setzen
89 SetPolyPolygon3D(rPolyPoly3D);
90 SetPolyNormals3D(rPolyNormals3D);
92 // Default-Texturkoordinaten erzeugen
93 CreateDefaultTexture();
96 /*************************************************************************
98 |* Konstruktor
100 \************************************************************************/
102 E3dPolygonObj::E3dPolygonObj(
103 E3dDefaultAttributes& rDefault,
104 const basegfx::B3DPolyPolygon& rPolyPoly3D,
105 const basegfx::B3DPolyPolygon& rPolyNormals3D,
106 const basegfx::B2DPolyPolygon& rPolyTexture2D,
107 BOOL bLinOnly)
108 : E3dCompoundObject(rDefault),
109 bLineOnly(bLinOnly)
111 SetPolyPolygon3D(rPolyPoly3D);
112 SetPolyNormals3D(rPolyNormals3D);
113 SetPolyTexture2D(rPolyTexture2D);
116 /*************************************************************************
118 |* Leer-Konstruktor
120 \************************************************************************/
122 E3dPolygonObj::E3dPolygonObj()
123 : E3dCompoundObject(),
124 bLineOnly(false) // added missing initialisation
126 // Keine Geometrie erzeugen
129 /*************************************************************************
131 |* Default-Normalen erzeugen
133 \************************************************************************/
135 void E3dPolygonObj::CreateDefaultNormals()
137 basegfx::B3DPolyPolygon aPolyNormals;
139 // Komplettes PolyPolygon mit den Ebenennormalen anlegen
140 for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++)
142 // Quellpolygon finden
143 const basegfx::B3DPolygon aPolygon(aPolyPoly3D.getB3DPolygon(a));
145 // Neues Polygon fuer Normalen anlegen
146 basegfx::B3DPolygon aNormals;
148 // Normale holen (und umdrehen)
149 basegfx::B3DVector aNormal(-basegfx::tools::getNormal(aPolygon));
151 // Neues Polygon fuellen
152 for(sal_uInt32 b(0L); b < aPolygon.count(); b++)
154 aNormals.append(aNormal);
157 // Neues Polygon in PolyPolygon einfuegen
158 aPolyNormals.append(aNormals);
161 // Default-Normalen setzen
162 SetPolyNormals3D(aPolyNormals);
165 /*************************************************************************
167 |* Default-Texturkoordinaten erzeugen
169 \************************************************************************/
171 void E3dPolygonObj::CreateDefaultTexture()
173 basegfx::B2DPolyPolygon aPolyTexture;
175 // Komplettes PolyPolygon mit den Texturkoordinaten anlegen
176 // Die Texturkoordinaten erstrecken sich ueber X,Y und Z
177 // ueber die gesamten Extremwerte im Bereich 0.0 .. 1.0
178 for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++)
180 // Quellpolygon finden
181 const basegfx::B3DPolygon& aPolygon(aPolyPoly3D.getB3DPolygon(a));
183 // Gesamtgroesse des Objektes feststellen
184 basegfx::B3DRange aVolume(basegfx::tools::getRange(aPolygon));
186 // Normale holen
187 basegfx::B3DVector aNormal(basegfx::tools::getNormal(aPolygon));
188 aNormal.setX(fabs(aNormal.getX()));
189 aNormal.setY(fabs(aNormal.getY()));
190 aNormal.setZ(fabs(aNormal.getZ()));
192 // Entscheiden, welche Koordinaten als Source fuer das
193 // Mapping benutzt werden sollen
194 UINT16 nSourceMode = 0;
196 // Groessten Freiheitsgrad ermitteln
197 if(!(aNormal.getX() > aNormal.getY() && aNormal.getX() > aNormal.getZ()))
199 if(aNormal.getY() > aNormal.getZ())
201 // Y ist am groessten, benutze X,Z als mapping
202 nSourceMode = 1;
204 else
206 // Z ist am groessten, benutze X,Y als mapping
207 nSourceMode = 2;
211 // Neues Polygon fuer Texturkoordinaten anlegen
212 basegfx::B2DPolygon aTexture;
214 // Neues Polygon fuellen
215 for(sal_uInt32 b(0L); b < aPolygon.count(); b++)
217 basegfx::B2DPoint aTex;
218 const basegfx::B3DPoint aCandidate(aPolygon.getB3DPoint(b));
220 switch(nSourceMode)
222 case 0: // Quelle ist Y,Z
223 if(aVolume.getHeight())
224 aTex.setX((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
225 if(aVolume.getDepth())
226 aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
227 break;
229 case 1: // Quelle ist X,Z
230 if(aVolume.getWidth())
231 aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
232 if(aVolume.getDepth())
233 aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
234 break;
236 case 2: // Quelle ist X,Y
237 if(aVolume.getWidth())
238 aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
239 if(aVolume.getHeight())
240 aTex.setY((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
241 break;
244 aTexture.append(aTex);
247 // Neues Polygon in PolyPolygon einfuegen
248 aPolyTexture.append(aTexture);
251 // Default-Texturkoordinaten setzen
252 SetPolyTexture2D(aPolyTexture);
255 /*************************************************************************
257 |* Destruktor
259 \************************************************************************/
261 E3dPolygonObj::~E3dPolygonObj()
265 /*************************************************************************
267 |* Identifier zurueckgeben
269 \************************************************************************/
271 UINT16 E3dPolygonObj::GetObjIdentifier() const
273 return E3D_POLYGONOBJ_ID;
276 /*************************************************************************
278 |* Polygon setzen
280 \************************************************************************/
282 void E3dPolygonObj::SetPolyPolygon3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D)
284 if ( aPolyPoly3D != rNewPolyPoly3D )
286 // Neues PolyPolygon; kopieren
287 aPolyPoly3D = rNewPolyPoly3D;
289 // Geometrie neu erzeugen
290 ActionChanged();
294 void E3dPolygonObj::SetPolyNormals3D(const basegfx::B3DPolyPolygon& rNewPolyNormals3D)
296 if ( aPolyNormals3D != rNewPolyNormals3D )
298 // Neue Normalen; kopieren
299 aPolyNormals3D = rNewPolyNormals3D;
301 // Geometrie neu erzeugen
302 ActionChanged();
306 void E3dPolygonObj::SetPolyTexture2D(const basegfx::B2DPolyPolygon& rNewPolyTexture2D)
308 if ( aPolyTexture2D != rNewPolyTexture2D )
310 // Neue Texturkoordinaten; kopieren
311 aPolyTexture2D = rNewPolyTexture2D;
313 // Geometrie neu erzeugen
314 ActionChanged();
318 /*************************************************************************
320 |* Wandle das Objekt in ein Gruppenobjekt bestehend aus 6 Polygonen
322 \************************************************************************/
324 SdrObject *E3dPolygonObj::DoConvertToPolyObj(BOOL /*bBezier*/) const
326 return NULL;
329 /*************************************************************************
331 |* Zuweisungsoperator
333 \************************************************************************/
335 void E3dPolygonObj::operator=(const SdrObject& rObj)
337 // erstmal alle Childs kopieren
338 E3dCompoundObject::operator=(rObj);
340 // weitere Parameter kopieren
341 const E3dPolygonObj& r3DObj = (const E3dPolygonObj&)rObj;
343 aPolyPoly3D = r3DObj.aPolyPoly3D;
344 aPolyNormals3D = r3DObj.aPolyNormals3D;
345 aPolyTexture2D = r3DObj.aPolyTexture2D;
346 bLineOnly = r3DObj.bLineOnly;
349 /*************************************************************************
351 |* LineOnly setzen
353 \************************************************************************/
355 void E3dPolygonObj::SetLineOnly(BOOL bNew)
357 if(bNew != bLineOnly)
359 bLineOnly = bNew;
360 ActionChanged();
364 // eof