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 #include <svx/polygn3d.hxx>
27 #include <svx/svdpage.hxx>
28 #include "svx/globl3d.hxx"
29 #include <basegfx/point/b3dpoint.hxx>
30 #include <svx/sdr/contact/viewcontactofe3dpolygon.hxx>
31 #include <basegfx/polygon/b3dpolygon.hxx>
32 #include <basegfx/polygon/b3dpolygontools.hxx>
33
34 TYPEINIT1(E3dPolygonObj, E3dCompoundObject);
35
36 //////////////////////////////////////////////////////////////////////////////
37 // #110094# DrawContact section
38
CreateObjectSpecificViewContact()39 sdr::contact::ViewContact* E3dPolygonObj::CreateObjectSpecificViewContact()
40 {
41 return new sdr::contact::ViewContactOfE3dPolygon(*this);
42 }
43
44 /*************************************************************************
45 |*
46 |* Konstruktor
47 |*
48 \************************************************************************/
49
E3dPolygonObj(E3dDefaultAttributes & rDefault,const basegfx::B3DPolyPolygon & rPolyPoly3D,sal_Bool bLinOnly)50 E3dPolygonObj::E3dPolygonObj(
51 E3dDefaultAttributes& rDefault,
52 const basegfx::B3DPolyPolygon& rPolyPoly3D,
53 sal_Bool bLinOnly)
54 : E3dCompoundObject(rDefault),
55 bLineOnly(bLinOnly)
56 {
57 // Geometrie setzen
58 SetPolyPolygon3D(rPolyPoly3D);
59
60 // Default-Normals erzeugen
61 CreateDefaultNormals();
62
63 // Default-Texturkoordinaten erzeugen
64 CreateDefaultTexture();
65 }
66
67 /*************************************************************************
68 |*
69 |* Konstruktor
70 |*
71 \************************************************************************/
72
E3dPolygonObj(E3dDefaultAttributes & rDefault,const basegfx::B3DPolyPolygon & rPolyPoly3D,const basegfx::B3DPolyPolygon & rPolyNormals3D,sal_Bool bLinOnly)73 E3dPolygonObj::E3dPolygonObj(
74 E3dDefaultAttributes& rDefault,
75 const basegfx::B3DPolyPolygon& rPolyPoly3D,
76 const basegfx::B3DPolyPolygon& rPolyNormals3D,
77 sal_Bool bLinOnly)
78 : E3dCompoundObject(rDefault),
79 bLineOnly(bLinOnly)
80 {
81 // Geometrie und Normalen setzen
82 SetPolyPolygon3D(rPolyPoly3D);
83 SetPolyNormals3D(rPolyNormals3D);
84
85 // Default-Texturkoordinaten erzeugen
86 CreateDefaultTexture();
87 }
88
89 /*************************************************************************
90 |*
91 |* Konstruktor
92 |*
93 \************************************************************************/
94
E3dPolygonObj(E3dDefaultAttributes & rDefault,const basegfx::B3DPolyPolygon & rPolyPoly3D,const basegfx::B3DPolyPolygon & rPolyNormals3D,const basegfx::B2DPolyPolygon & rPolyTexture2D,sal_Bool bLinOnly)95 E3dPolygonObj::E3dPolygonObj(
96 E3dDefaultAttributes& rDefault,
97 const basegfx::B3DPolyPolygon& rPolyPoly3D,
98 const basegfx::B3DPolyPolygon& rPolyNormals3D,
99 const basegfx::B2DPolyPolygon& rPolyTexture2D,
100 sal_Bool bLinOnly)
101 : E3dCompoundObject(rDefault),
102 bLineOnly(bLinOnly)
103 {
104 SetPolyPolygon3D(rPolyPoly3D);
105 SetPolyNormals3D(rPolyNormals3D);
106 SetPolyTexture2D(rPolyTexture2D);
107 }
108
109 /*************************************************************************
110 |*
111 |* Leer-Konstruktor
112 |*
113 \************************************************************************/
114
E3dPolygonObj()115 E3dPolygonObj::E3dPolygonObj()
116 : E3dCompoundObject(),
117 bLineOnly(false) // added missing initialisation
118 {
119 // Keine Geometrie erzeugen
120 }
121
122 /*************************************************************************
123 |*
124 |* Default-Normalen erzeugen
125 |*
126 \************************************************************************/
127
CreateDefaultNormals()128 void E3dPolygonObj::CreateDefaultNormals()
129 {
130 basegfx::B3DPolyPolygon aPolyNormals;
131
132 // Komplettes PolyPolygon mit den Ebenennormalen anlegen
133 for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++)
134 {
135 // Quellpolygon finden
136 const basegfx::B3DPolygon aPolygon(aPolyPoly3D.getB3DPolygon(a));
137
138 // Neues Polygon fuer Normalen anlegen
139 basegfx::B3DPolygon aNormals;
140
141 // Normale holen (und umdrehen)
142 basegfx::B3DVector aNormal(-basegfx::tools::getNormal(aPolygon));
143
144 // Neues Polygon fuellen
145 for(sal_uInt32 b(0L); b < aPolygon.count(); b++)
146 {
147 aNormals.append(aNormal);
148 }
149
150 // Neues Polygon in PolyPolygon einfuegen
151 aPolyNormals.append(aNormals);
152 }
153
154 // Default-Normalen setzen
155 SetPolyNormals3D(aPolyNormals);
156 }
157
158 /*************************************************************************
159 |*
160 |* Default-Texturkoordinaten erzeugen
161 |*
162 \************************************************************************/
163
CreateDefaultTexture()164 void E3dPolygonObj::CreateDefaultTexture()
165 {
166 basegfx::B2DPolyPolygon aPolyTexture;
167
168 // Komplettes PolyPolygon mit den Texturkoordinaten anlegen
169 // Die Texturkoordinaten erstrecken sich ueber X,Y und Z
170 // ueber die gesamten Extremwerte im Bereich 0.0 .. 1.0
171 for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++)
172 {
173 // Quellpolygon finden
174 const basegfx::B3DPolygon& aPolygon(aPolyPoly3D.getB3DPolygon(a));
175
176 // Gesamtgroesse des Objektes feststellen
177 basegfx::B3DRange aVolume(basegfx::tools::getRange(aPolygon));
178
179 // Normale holen
180 basegfx::B3DVector aNormal(basegfx::tools::getNormal(aPolygon));
181 aNormal.setX(fabs(aNormal.getX()));
182 aNormal.setY(fabs(aNormal.getY()));
183 aNormal.setZ(fabs(aNormal.getZ()));
184
185 // Entscheiden, welche Koordinaten als Source fuer das
186 // Mapping benutzt werden sollen
187 sal_uInt16 nSourceMode = 0;
188
189 // Groessten Freiheitsgrad ermitteln
190 if(!(aNormal.getX() > aNormal.getY() && aNormal.getX() > aNormal.getZ()))
191 {
192 if(aNormal.getY() > aNormal.getZ())
193 {
194 // Y ist am groessten, benutze X,Z als mapping
195 nSourceMode = 1;
196 }
197 else
198 {
199 // Z ist am groessten, benutze X,Y als mapping
200 nSourceMode = 2;
201 }
202 }
203
204 // Neues Polygon fuer Texturkoordinaten anlegen
205 basegfx::B2DPolygon aTexture;
206
207 // Neues Polygon fuellen
208 for(sal_uInt32 b(0L); b < aPolygon.count(); b++)
209 {
210 basegfx::B2DPoint aTex;
211 const basegfx::B3DPoint aCandidate(aPolygon.getB3DPoint(b));
212
213 switch(nSourceMode)
214 {
215 case 0: // Quelle ist Y,Z
216 if(aVolume.getHeight())
217 aTex.setX((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
218 if(aVolume.getDepth())
219 aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
220 break;
221
222 case 1: // Quelle ist X,Z
223 if(aVolume.getWidth())
224 aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
225 if(aVolume.getDepth())
226 aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
227 break;
228
229 case 2: // Quelle ist X,Y
230 if(aVolume.getWidth())
231 aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
232 if(aVolume.getHeight())
233 aTex.setY((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
234 break;
235 }
236
237 aTexture.append(aTex);
238 }
239
240 // Neues Polygon in PolyPolygon einfuegen
241 aPolyTexture.append(aTexture);
242 }
243
244 // Default-Texturkoordinaten setzen
245 SetPolyTexture2D(aPolyTexture);
246 }
247
248 /*************************************************************************
249 |*
250 |* Destruktor
251 |*
252 \************************************************************************/
253
~E3dPolygonObj()254 E3dPolygonObj::~E3dPolygonObj()
255 {
256 }
257
258 /*************************************************************************
259 |*
260 |* Identifier zurueckgeben
261 |*
262 \************************************************************************/
263
GetObjIdentifier() const264 sal_uInt16 E3dPolygonObj::GetObjIdentifier() const
265 {
266 return E3D_POLYGONOBJ_ID;
267 }
268
269 /*************************************************************************
270 |*
271 |* Polygon setzen
272 |*
273 \************************************************************************/
274
SetPolyPolygon3D(const basegfx::B3DPolyPolygon & rNewPolyPoly3D)275 void E3dPolygonObj::SetPolyPolygon3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D)
276 {
277 if ( aPolyPoly3D != rNewPolyPoly3D )
278 {
279 // Neues PolyPolygon; kopieren
280 aPolyPoly3D = rNewPolyPoly3D;
281
282 // Geometrie neu erzeugen
283 ActionChanged();
284 }
285 }
286
SetPolyNormals3D(const basegfx::B3DPolyPolygon & rNewPolyNormals3D)287 void E3dPolygonObj::SetPolyNormals3D(const basegfx::B3DPolyPolygon& rNewPolyNormals3D)
288 {
289 if ( aPolyNormals3D != rNewPolyNormals3D )
290 {
291 // Neue Normalen; kopieren
292 aPolyNormals3D = rNewPolyNormals3D;
293
294 // Geometrie neu erzeugen
295 ActionChanged();
296 }
297 }
298
SetPolyTexture2D(const basegfx::B2DPolyPolygon & rNewPolyTexture2D)299 void E3dPolygonObj::SetPolyTexture2D(const basegfx::B2DPolyPolygon& rNewPolyTexture2D)
300 {
301 if ( aPolyTexture2D != rNewPolyTexture2D )
302 {
303 // Neue Texturkoordinaten; kopieren
304 aPolyTexture2D = rNewPolyTexture2D;
305
306 // Geometrie neu erzeugen
307 ActionChanged();
308 }
309 }
310
311 /*************************************************************************
312 |*
313 |* Wandle das Objekt in ein Gruppenobjekt bestehend aus 6 Polygonen
314 |*
315 \************************************************************************/
316
DoConvertToPolyObj(sal_Bool,bool) const317 SdrObject *E3dPolygonObj::DoConvertToPolyObj(sal_Bool /*bBezier*/, bool /*bAddText*/) const
318 {
319 return NULL;
320 }
321
322 /*************************************************************************
323 |*
324 |* Zuweisungsoperator
325 |*
326 \************************************************************************/
327
operator =(const SdrObject & rObj)328 void E3dPolygonObj::operator=(const SdrObject& rObj)
329 {
330 // erstmal alle Childs kopieren
331 E3dCompoundObject::operator=(rObj);
332
333 // weitere Parameter kopieren
334 const E3dPolygonObj& r3DObj = (const E3dPolygonObj&)rObj;
335
336 aPolyPoly3D = r3DObj.aPolyPoly3D;
337 aPolyNormals3D = r3DObj.aPolyNormals3D;
338 aPolyTexture2D = r3DObj.aPolyTexture2D;
339 bLineOnly = r3DObj.bLineOnly;
340 }
341
342 /*************************************************************************
343 |*
344 |* LineOnly setzen
345 |*
346 \************************************************************************/
347
SetLineOnly(sal_Bool bNew)348 void E3dPolygonObj::SetLineOnly(sal_Bool bNew)
349 {
350 if(bNew != bLineOnly)
351 {
352 bLineOnly = bNew;
353 ActionChanged();
354 }
355 }
356
357 // eof
358