b311480e |
1 | // Created by: NW,JPB,CAL |
2 | // Copyright (c) 1991-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <gp_Ax2.hxx> |
b64d84be |
18 | #include <gp_Pnt.hxx> |
19 | #include <Graphic3d_ArrayOfPoints.hxx> |
42cf5bc1 |
20 | #include <Graphic3d_ArrayOfPrimitives.hxx> |
21 | #include <Graphic3d_AspectFillArea3d.hxx> |
22 | #include <Graphic3d_AspectLine3d.hxx> |
23 | #include <Graphic3d_AspectMarker3d.hxx> |
24 | #include <Graphic3d_AspectText3d.hxx> |
25 | #include <Graphic3d_CStructure.hxx> |
26 | #include <Graphic3d_Group.hxx> |
27 | #include <Graphic3d_GroupDefinitionError.hxx> |
b64d84be |
28 | #include <Graphic3d_ShaderProgram.hxx> |
42cf5bc1 |
29 | #include <Graphic3d_Structure.hxx> |
19286d7c |
30 | #include "Graphic3d_Structure.pxx" |
42cf5bc1 |
31 | #include <Graphic3d_StructureManager.hxx> |
b64d84be |
32 | #include <Graphic3d_TextureMap.hxx> |
42cf5bc1 |
33 | #include <Graphic3d_TransModeFlags.hxx> |
b64d84be |
34 | #include <Message.hxx> |
35 | #include <Message_Messenger.hxx> |
36 | #include <NCollection_String.hxx> |
42cf5bc1 |
37 | #include <Standard_OutOfRange.hxx> |
38 | #include <Standard_Type.hxx> |
b64d84be |
39 | #include <TCollection_AsciiString.hxx> |
42cf5bc1 |
40 | #include <TCollection_ExtendedString.hxx> |
7fd59977 |
41 | |
b64d84be |
42 | #define MyContainsFacet myCBitFields.bool2 |
7fd59977 |
43 | |
b64d84be |
44 | // ======================================================================= |
45 | // function : Graphic3d_Group |
46 | // purpose : |
47 | // ======================================================================= |
48 | Graphic3d_Group::Graphic3d_Group (const Handle(Graphic3d_Structure)& theStruct) |
31c0e219 |
49 | : myIsClosed (Standard_False) |
b64d84be |
50 | { |
b64d84be |
51 | // A small commentary on the usage of This! |
52 | // |
53 | // Graphic3d_Group is created in a structure. Graphic3d_Structure is a |
54 | // manager of Graphic3d_Group. In the constructor of Graphic3d_Group |
55 | // a method Add of Graphic3d_Structure is called. It allows adding |
56 | // the instance of Graphic3d_Group in its manager. So there are 2 references |
57 | // to <me> and everything works well. |
58 | // |
59 | // This () is the instance of the class, the current group |
60 | //Handle(Graphic3d_Group) me = Handle(Graphic3d_Group)::DownCast (This()); |
7fd59977 |
61 | |
b64d84be |
62 | myStructure = theStruct.operator->(); |
7fd59977 |
63 | |
9cc773b5 |
64 | MyContainsFacet = Standard_False, |
7fd59977 |
65 | |
b64d84be |
66 | ContextLine.IsDef = 0; |
67 | ContextText.IsDef = 0; |
68 | ContextMarker.IsDef = 0; |
69 | ContextFillArea.IsDef = 0; |
7fd59977 |
70 | |
b64d84be |
71 | ContextLine.IsSet = 0; |
72 | ContextText.IsSet = 0; |
73 | ContextMarker.IsSet = 0; |
74 | ContextFillArea.IsSet = 0; |
75 | } |
76 | |
77 | // ======================================================================= |
78 | // function : Clear |
79 | // purpose : |
80 | // ======================================================================= |
81 | void Graphic3d_Group::Clear (Standard_Boolean theUpdateStructureMgr) |
82 | { |
83 | if (IsDeleted()) |
84 | { |
85 | return; |
86 | } |
87 | |
88 | ContextLine.IsSet = 0, |
89 | ContextText.IsSet = 0, |
90 | ContextMarker.IsSet = 0, |
91 | ContextFillArea.IsSet = 0; |
7fd59977 |
92 | |
b64d84be |
93 | ContextLine.IsDef = 0, |
94 | ContextText.IsDef = 0, |
95 | ContextMarker.IsDef = 0, |
96 | ContextFillArea.IsDef = 0; |
7fd59977 |
97 | |
b7cd4ba7 |
98 | myBounds.Clear(); |
7fd59977 |
99 | |
b64d84be |
100 | if (MyContainsFacet) |
101 | { |
102 | myStructure->GroupsWithFacet (-1); |
103 | MyContainsFacet = Standard_False; |
104 | } |
7fd59977 |
105 | |
b64d84be |
106 | // clear method could be used on Graphic3d_Structure destruction, |
107 | // and its structure manager could be already destroyed, in that |
108 | // case we don't need to update it; |
109 | if (theUpdateStructureMgr) |
110 | { |
111 | Update(); |
112 | } |
113 | } |
7fd59977 |
114 | |
b64d84be |
115 | // ======================================================================= |
116 | // function : Destroy |
117 | // purpose : |
118 | // ======================================================================= |
119 | void Graphic3d_Group::Destroy() |
120 | { |
121 | // tell graphics driver to clear internal resources of the group |
122 | Clear (Standard_False); |
123 | } |
7fd59977 |
124 | |
b64d84be |
125 | // ======================================================================= |
126 | // function : Remove |
127 | // purpose : |
128 | // ======================================================================= |
129 | void Graphic3d_Group::Remove() |
7fd59977 |
130 | { |
b64d84be |
131 | if (IsDeleted()) |
132 | { |
133 | return; |
134 | } |
7fd59977 |
135 | |
b64d84be |
136 | if (MyContainsFacet) |
137 | { |
138 | myStructure->GroupsWithFacet (-1); |
139 | MyContainsFacet = Standard_False; |
140 | } |
141 | myStructure->Remove (this); |
7fd59977 |
142 | |
b64d84be |
143 | Update(); |
7fd59977 |
144 | |
b7cd4ba7 |
145 | myBounds.Clear(); |
b64d84be |
146 | } |
147 | |
148 | // ======================================================================= |
149 | // function : IsDeleted |
150 | // purpose : |
151 | // ======================================================================= |
152 | Standard_Boolean Graphic3d_Group::IsDeleted() const |
153 | { |
154 | return myStructure == NULL |
155 | || myStructure->IsDeleted(); |
156 | } |
157 | |
158 | // ======================================================================= |
159 | // function : ContainsFacet |
160 | // purpose : |
161 | // ======================================================================= |
162 | Standard_Boolean Graphic3d_Group::ContainsFacet() const |
163 | { |
164 | return MyContainsFacet; |
165 | } |
166 | |
167 | // ======================================================================= |
168 | // function : IsEmpty |
169 | // purpose : |
170 | // ======================================================================= |
171 | Standard_Boolean Graphic3d_Group::IsEmpty() const |
172 | { |
173 | if (IsDeleted()) |
174 | { |
175 | return Standard_True; |
176 | } |
177 | |
9cc773b5 |
178 | return !myStructure->IsInfinite() |
179 | && !myBounds.IsValid(); |
b64d84be |
180 | } |
181 | |
182 | // ======================================================================= |
183 | // function : SetMinMaxValues |
184 | // purpose : |
185 | // ======================================================================= |
186 | void Graphic3d_Group::SetMinMaxValues (const Standard_Real theXMin, const Standard_Real theYMin, const Standard_Real theZMin, |
187 | const Standard_Real theXMax, const Standard_Real theYMax, const Standard_Real theZMax) |
188 | { |
ecc1d911 |
189 | myBounds = Graphic3d_BndBox4f (Graphic3d_Vec4 (static_cast<Standard_ShortReal> (theXMin), |
190 | static_cast<Standard_ShortReal> (theYMin), |
191 | static_cast<Standard_ShortReal> (theZMin), |
192 | 1.0f), |
193 | Graphic3d_Vec4 (static_cast<Standard_ShortReal> (theXMax), |
194 | static_cast<Standard_ShortReal> (theYMax), |
195 | static_cast<Standard_ShortReal> (theZMax), |
196 | 1.0f)); |
b64d84be |
197 | } |
198 | |
199 | // ======================================================================= |
200 | // function : MinMaxValues |
201 | // purpose : |
202 | // ======================================================================= |
203 | void Graphic3d_Group::MinMaxValues (Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin, |
204 | Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax) const |
205 | { |
206 | MinMaxCoord (theXMin, theYMin, theZMin, |
207 | theXMax, theYMax, theZMax); |
208 | } |
209 | |
210 | // ======================================================================= |
211 | // function : Structure |
212 | // purpose : |
213 | // ======================================================================= |
214 | Handle(Graphic3d_Structure) Graphic3d_Group::Structure() const |
215 | { |
216 | return myStructure; |
217 | } |
218 | |
219 | // ======================================================================= |
220 | // function : MinMaxCoord |
221 | // purpose : |
222 | // ======================================================================= |
223 | void Graphic3d_Group::MinMaxCoord (Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin, |
224 | Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax) const |
225 | { |
226 | if (IsEmpty()) |
227 | { |
228 | // Empty Group |
229 | theXMin = theYMin = theZMin = ShortRealFirst(); |
230 | theXMax = theYMax = theZMax = ShortRealLast(); |
231 | } |
b7cd4ba7 |
232 | else if (myBounds.IsValid()) |
233 | { |
234 | const Graphic3d_Vec4& aMinPt = myBounds.CornerMin(); |
235 | const Graphic3d_Vec4& aMaxPt = myBounds.CornerMax(); |
236 | theXMin = Standard_Real (aMinPt.x()); |
237 | theYMin = Standard_Real (aMinPt.y()); |
238 | theZMin = Standard_Real (aMinPt.z()); |
239 | theXMax = Standard_Real (aMaxPt.x()); |
240 | theYMax = Standard_Real (aMaxPt.y()); |
241 | theZMax = Standard_Real (aMaxPt.z()); |
242 | } |
b64d84be |
243 | else |
244 | { |
b7cd4ba7 |
245 | // for consistency with old API |
246 | theXMin = theYMin = theZMin = ShortRealLast(); |
247 | theXMax = theYMax = theZMax = ShortRealFirst(); |
b64d84be |
248 | } |
249 | } |
250 | |
251 | // ======================================================================= |
252 | // function : Update |
253 | // purpose : |
254 | // ======================================================================= |
255 | void Graphic3d_Group::Update() const |
256 | { |
257 | if (IsDeleted()) |
258 | { |
259 | return; |
260 | } |
261 | |
262 | if (myStructure->StructureManager()->UpdateMode() == Aspect_TOU_ASAP) |
263 | { |
264 | myStructure->StructureManager()->Update(); |
265 | } |
266 | } |
267 | |
268 | // ======================================================================= |
269 | // function : SetGroupPrimitivesAspect |
270 | // purpose : |
271 | // ======================================================================= |
272 | void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine) |
273 | { |
274 | if (IsDeleted()) |
275 | { |
276 | return; |
277 | } |
278 | |
279 | Standard_Real aWidth; |
280 | Quantity_Color aColor; |
281 | Aspect_TypeOfLine aLType; |
282 | theAspLine->Values (aColor, aLType, aWidth); |
283 | |
284 | ContextLine.IsDef = 1; |
285 | ContextLine.Color.r = float (aColor.Red()); |
286 | ContextLine.Color.g = float (aColor.Green()); |
287 | ContextLine.Color.b = float (aColor.Blue()); |
288 | ContextLine.LineType = aLType; |
289 | ContextLine.Width = float (aWidth); |
290 | ContextLine.ShaderProgram = theAspLine->ShaderProgram(); |
7fd59977 |
291 | |
b64d84be |
292 | UpdateAspectLine (Standard_True); |
7fd59977 |
293 | |
b64d84be |
294 | ContextLine.IsSet = 1; |
7fd59977 |
295 | |
b64d84be |
296 | Update(); |
297 | } |
298 | |
299 | // ======================================================================= |
300 | // function : SetGroupPrimitivesAspect |
301 | // purpose : |
302 | // ======================================================================= |
303 | void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill) |
304 | { |
305 | if (IsDeleted()) |
306 | { |
307 | return; |
308 | } |
309 | |
310 | Standard_Real anRGB[3]; |
311 | Standard_Real aWidth; |
312 | Quantity_Color anIntColor; |
313 | Quantity_Color aBackIntColor; |
314 | Quantity_Color anEdgeColor; |
315 | Aspect_TypeOfLine aLType; |
316 | Aspect_InteriorStyle aStyle; |
317 | theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth); |
318 | |
319 | anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB); |
320 | ContextFillArea.Style = aStyle; |
321 | ContextFillArea.IntColor.r = float (anRGB[0]); |
322 | ContextFillArea.IntColor.g = float (anRGB[1]); |
323 | ContextFillArea.IntColor.b = float (anRGB[2]); |
324 | |
325 | if (theAspFill->Distinguish()) |
326 | { |
327 | aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB); |
328 | } |
329 | ContextFillArea.BackIntColor.r = float (anRGB[0]); |
330 | ContextFillArea.BackIntColor.g = float (anRGB[1]); |
331 | ContextFillArea.BackIntColor.b = float (anRGB[2]); |
332 | |
333 | // Edges |
334 | ContextFillArea.Edge = theAspFill->Edge() ? 1 : 0; |
335 | ContextFillArea.EdgeColor.r = float (anEdgeColor.Red()); |
336 | ContextFillArea.EdgeColor.g = float (anEdgeColor.Green()); |
337 | ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue()); |
338 | ContextFillArea.LineType = aLType; |
339 | ContextFillArea.Width = float (aWidth); |
340 | ContextFillArea.Hatch = theAspFill->HatchStyle(); |
341 | |
342 | // Front and Back face |
343 | ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0; |
344 | ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0; |
345 | |
346 | // Back Material |
347 | const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial(); |
348 | |
189f85a3 |
349 | // Material properties |
350 | ContextFillArea.Back.Shininess = float (aBack.Shininess()); |
351 | ContextFillArea.Back.Ambient = float (aBack.Ambient()); |
352 | ContextFillArea.Back.Diffuse = float (aBack.Diffuse()); |
353 | ContextFillArea.Back.Specular = float (aBack.Specular()); |
354 | ContextFillArea.Back.Transparency = float (aBack.Transparency()); |
355 | ContextFillArea.Back.Emission = float (aBack.Emissive()); |
dc9ef964 |
356 | ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex()); |
189f85a3 |
357 | ContextFillArea.Back.BSDF = aBack.BSDF(); |
b64d84be |
358 | |
359 | // Reflection mode |
360 | ContextFillArea.Back.IsAmbient = aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0; |
361 | ContextFillArea.Back.IsDiffuse = aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0; |
362 | ContextFillArea.Back.IsSpecular = aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0; |
363 | ContextFillArea.Back.IsEmission = aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0; |
364 | |
365 | // Material type |
366 | ContextFillArea.Back.IsPhysic = aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0; |
367 | |
368 | // Specular color |
369 | ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red()); |
370 | ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green()); |
371 | ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue()); |
372 | |
373 | // Ambient color |
374 | ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red()); |
375 | ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green()); |
376 | ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue()); |
377 | |
378 | // Diffuse color |
379 | ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red()); |
380 | ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green()); |
381 | ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue()); |
382 | |
383 | // Emissive color |
384 | ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red()); |
385 | ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green()); |
386 | ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue()); |
387 | |
388 | ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion()); |
389 | |
390 | // Front Material |
391 | const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial(); |
189f85a3 |
392 | |
393 | // Material properties |
394 | ContextFillArea.Front.Shininess = float (aFront.Shininess()); |
395 | ContextFillArea.Front.Ambient = float (aFront.Ambient()); |
396 | ContextFillArea.Front.Diffuse = float (aFront.Diffuse()); |
397 | ContextFillArea.Front.Specular = float (aFront.Specular()); |
398 | ContextFillArea.Front.Transparency = float (aFront.Transparency()); |
399 | ContextFillArea.Front.Emission = float (aFront.Emissive()); |
dc9ef964 |
400 | ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex()); |
189f85a3 |
401 | ContextFillArea.Front.BSDF = aFront.BSDF(); |
b64d84be |
402 | |
403 | // Reflection mode |
404 | ContextFillArea.Front.IsAmbient = aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0; |
405 | ContextFillArea.Front.IsDiffuse = aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0; |
406 | ContextFillArea.Front.IsSpecular = aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0; |
407 | ContextFillArea.Front.IsEmission = aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0; |
408 | |
409 | // Material type |
410 | ContextFillArea.Front.IsPhysic = aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0; |
411 | |
412 | // Specular color |
413 | ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red()); |
414 | ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green()); |
415 | ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue()); |
416 | |
417 | // Ambient color |
418 | ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red()); |
419 | ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green()); |
420 | ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue()); |
421 | |
422 | // Diffuse color |
423 | ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red()); |
424 | ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green()); |
425 | ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue()); |
426 | |
427 | // Emissive color |
428 | ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red()); |
429 | ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green()); |
430 | ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue()); |
431 | |
432 | ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion()); |
433 | |
434 | ContextFillArea.IsDef = 1; // Definition material ok |
435 | |
436 | // Texture map |
437 | ContextFillArea.Texture.TextureMap = theAspFill->TextureMap(); |
438 | ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0; |
439 | |
440 | Standard_Integer aPolyMode; |
441 | Standard_ShortReal aPolyFactor, aPolyUnits; |
442 | theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits); |
443 | ContextFillArea.PolygonOffsetMode = aPolyMode; |
444 | ContextFillArea.PolygonOffsetFactor = aPolyFactor; |
445 | ContextFillArea.PolygonOffsetUnits = aPolyUnits; |
446 | |
447 | ContextFillArea.ShaderProgram = theAspFill->ShaderProgram(); |
448 | |
449 | UpdateAspectFace (Standard_True); |
450 | |
451 | ContextFillArea.IsSet = 1; |
452 | |
453 | Update(); |
454 | } |
455 | |
456 | // ======================================================================= |
457 | // function : SetGroupPrimitivesAspect |
458 | // purpose : |
459 | // ======================================================================= |
460 | void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker) |
461 | { |
462 | if (IsDeleted()) |
463 | { |
464 | return; |
465 | } |
466 | |
467 | Standard_Real aScale; |
468 | Quantity_Color aColor; |
469 | Aspect_TypeOfMarker aMarkerType; |
470 | theAspMarker->Values (aColor, aMarkerType, aScale); |
471 | |
472 | ContextMarker.IsDef = 1; |
473 | ContextMarker.Color.r = Standard_ShortReal (aColor.Red()); |
474 | ContextMarker.Color.g = Standard_ShortReal (aColor.Green()); |
475 | ContextMarker.Color.b = Standard_ShortReal (aColor.Blue()); |
476 | ContextMarker.MarkerType = aMarkerType; |
477 | ContextMarker.Scale = Standard_ShortReal (aScale); |
478 | ContextMarker.MarkerImage = theAspMarker->GetMarkerImage(); |
479 | ContextMarker.ShaderProgram = theAspMarker->ShaderProgram(); |
480 | |
481 | UpdateAspectMarker (Standard_True); |
482 | |
483 | ContextMarker.IsSet = 1; |
484 | |
485 | Update(); |
486 | } |
487 | |
488 | // ======================================================================= |
489 | // function : SetGroupPrimitivesAspect |
490 | // purpose : |
491 | // ======================================================================= |
492 | void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText) |
493 | { |
494 | if (IsDeleted()) |
495 | { |
496 | return; |
497 | } |
498 | |
499 | Standard_Real anExpansion, aSpace, aTextAngle; |
500 | Quantity_Color aColor, aColorSubTitle; |
501 | Standard_CString aFont; |
502 | Aspect_TypeOfStyleText aStyle; |
503 | Aspect_TypeOfDisplayText aDisplayType; |
504 | Standard_Boolean isTextZoomable; |
505 | Font_FontAspect aTextFontAspect; |
506 | theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDisplayType, |
507 | aColorSubTitle, isTextZoomable, aTextAngle, aTextFontAspect); |
508 | |
509 | ContextText.IsDef = 1; |
510 | ContextText.Color.r = float (aColor.Red()); |
511 | ContextText.Color.g = float (aColor.Green()); |
512 | ContextText.Color.b = float (aColor.Blue()); |
513 | ContextText.Font = (char* )aFont; |
514 | ContextText.Expan = float (anExpansion); |
515 | ContextText.Space = float (aSpace); |
516 | ContextText.Style = aStyle; |
517 | ContextText.DisplayType = aDisplayType; |
518 | ContextText.ColorSubTitle.r = float (aColorSubTitle.Red()); |
519 | ContextText.ColorSubTitle.g = float (aColorSubTitle.Green()); |
520 | ContextText.ColorSubTitle.b = float (aColorSubTitle.Blue()); |
521 | ContextText.TextZoomable = isTextZoomable; |
522 | ContextText.TextAngle = float (aTextAngle); |
523 | ContextText.TextFontAspect = aTextFontAspect; |
524 | ContextText.ShaderProgram = theAspText->ShaderProgram(); |
525 | |
526 | UpdateAspectText (Standard_True); |
527 | |
528 | ContextText.IsSet = 1; |
529 | |
530 | Update(); |
531 | } |
532 | |
533 | // ======================================================================= |
534 | // function : SetPrimitivesAspect |
535 | // purpose : |
536 | // ======================================================================= |
537 | void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine) |
538 | { |
539 | if (IsDeleted()) |
540 | { |
541 | return; |
542 | } |
7fd59977 |
543 | |
b64d84be |
544 | Standard_Real aWidth; |
545 | Quantity_Color aColor; |
546 | Aspect_TypeOfLine aLType; |
547 | theAspLine->Values (aColor, aLType, aWidth); |
7fd59977 |
548 | |
b64d84be |
549 | ContextLine.IsDef = 1; |
550 | ContextLine.Color.r = float (aColor.Red()); |
551 | ContextLine.Color.g = float (aColor.Green()); |
552 | ContextLine.Color.b = float (aColor.Blue()); |
553 | ContextLine.LineType = aLType; |
554 | ContextLine.Width = float (aWidth); |
555 | ContextLine.ShaderProgram = theAspLine->ShaderProgram(); |
7fd59977 |
556 | |
b64d84be |
557 | UpdateAspectLine (Standard_False); |
7fd59977 |
558 | |
b64d84be |
559 | ContextLine.IsSet = 1; |
7fd59977 |
560 | |
b64d84be |
561 | Update(); |
562 | } |
563 | |
564 | // ======================================================================= |
565 | // function : SetPrimitivesAspect |
566 | // purpose : |
567 | // ======================================================================= |
568 | void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill) |
569 | { |
570 | if (IsDeleted()) |
571 | { |
572 | return; |
573 | } |
574 | |
575 | Standard_Real anRGB[3]; |
576 | Standard_Real aWidth; |
577 | Quantity_Color anIntColor; |
578 | Quantity_Color aBackIntColor; |
579 | Quantity_Color anEdgeColor; |
580 | Aspect_TypeOfLine aLType; |
581 | Aspect_InteriorStyle aStyle; |
582 | theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth); |
583 | |
584 | anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB); |
585 | ContextFillArea.Style = aStyle; |
586 | ContextFillArea.IntColor.r = float (anRGB[0]); |
587 | ContextFillArea.IntColor.g = float (anRGB[1]); |
588 | ContextFillArea.IntColor.b = float (anRGB[2]); |
589 | |
590 | if (theAspFill->Distinguish()) |
591 | { |
592 | aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB); |
593 | } |
594 | ContextFillArea.BackIntColor.r = float(anRGB[0]); |
595 | ContextFillArea.BackIntColor.g = float(anRGB[1]); |
596 | ContextFillArea.BackIntColor.b = float(anRGB[2]); |
597 | |
598 | // Edges |
599 | ContextFillArea.Edge = theAspFill->Edge() ? 1 : 0; |
600 | ContextFillArea.EdgeColor.r = float (anEdgeColor.Red()); |
601 | ContextFillArea.EdgeColor.g = float (anEdgeColor.Green()); |
602 | ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue()); |
603 | ContextFillArea.LineType = aLType; |
604 | ContextFillArea.Width = float (aWidth); |
605 | ContextFillArea.Hatch = theAspFill->HatchStyle(); |
606 | |
607 | // Front and Back face |
608 | ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0; |
609 | ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0; |
610 | |
611 | // Back Material |
612 | const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial(); |
613 | // Material state |
614 | ContextFillArea.Back.Shininess = float (aBack.Shininess()); |
615 | ContextFillArea.Back.Ambient = float (aBack.Ambient()); |
616 | ContextFillArea.Back.Diffuse = float (aBack.Diffuse()); |
617 | ContextFillArea.Back.Specular = float (aBack.Specular()); |
618 | ContextFillArea.Back.Transparency = float (aBack.Transparency()); |
619 | ContextFillArea.Back.Emission = float (aBack.Emissive()); |
620 | |
621 | // Reflection mode |
622 | ContextFillArea.Back.IsAmbient = aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0; |
623 | ContextFillArea.Back.IsDiffuse = aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0; |
624 | ContextFillArea.Back.IsSpecular = aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0; |
625 | ContextFillArea.Back.IsEmission = aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0; |
626 | |
627 | // Material type |
628 | ContextFillArea.Back.IsPhysic = aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0; |
629 | |
630 | // Specular color |
631 | ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red()); |
632 | ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green()); |
633 | ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue()); |
634 | |
635 | // Ambient color |
636 | ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red()); |
637 | ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green()); |
638 | ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue()); |
639 | |
640 | // Diffuse color |
641 | ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red()); |
642 | ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green()); |
643 | ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue()); |
644 | |
645 | // Emissive color |
646 | ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red()); |
647 | ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green()); |
648 | ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue()); |
649 | |
650 | ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion()); |
651 | |
189f85a3 |
652 | ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex()); |
653 | ContextFillArea.Back.BSDF = aBack.BSDF(); |
654 | |
b64d84be |
655 | // Front Material |
656 | const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial(); |
657 | // Light specificity |
658 | ContextFillArea.Front.Shininess = float (aFront.Shininess()); |
659 | ContextFillArea.Front.Ambient = float (aFront.Ambient()); |
660 | ContextFillArea.Front.Diffuse = float (aFront.Diffuse()); |
661 | ContextFillArea.Front.Specular = float (aFront.Specular()); |
662 | ContextFillArea.Front.Transparency = float (aFront.Transparency()); |
663 | ContextFillArea.Front.Emission = float (aFront.Emissive()); |
664 | |
665 | // Reflection mode |
666 | ContextFillArea.Front.IsAmbient = aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0; |
667 | ContextFillArea.Front.IsDiffuse = aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0; |
668 | ContextFillArea.Front.IsSpecular = aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0; |
669 | ContextFillArea.Front.IsEmission = aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0; |
670 | |
671 | // Material type |
672 | ContextFillArea.Front.IsPhysic = aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0; |
673 | |
674 | // Specular color |
675 | ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red()); |
676 | ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green()); |
677 | ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue()); |
678 | |
679 | // Ambient color |
680 | ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red()); |
681 | ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green()); |
682 | ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue()); |
683 | |
684 | // Diffuse color |
685 | ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red()); |
686 | ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green()); |
687 | ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue()); |
688 | |
689 | // Emissive color |
690 | ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red()); |
691 | ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green()); |
692 | ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue()); |
693 | |
694 | ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion()); |
695 | |
189f85a3 |
696 | ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex()); |
697 | ContextFillArea.Front.BSDF = aFront.BSDF(); |
698 | |
b64d84be |
699 | ContextFillArea.IsDef = 1; // Material definition ok |
700 | |
701 | ContextFillArea.Texture.TextureMap = theAspFill->TextureMap(); |
702 | ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0; |
703 | |
704 | Standard_Integer aPolyMode; |
705 | Standard_ShortReal aPolyFactor, aPolyUnits; |
706 | theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits); |
707 | ContextFillArea.PolygonOffsetMode = aPolyMode; |
708 | ContextFillArea.PolygonOffsetFactor = aPolyFactor; |
709 | ContextFillArea.PolygonOffsetUnits = aPolyUnits; |
710 | |
711 | ContextFillArea.ShaderProgram = theAspFill->ShaderProgram(); |
712 | |
713 | UpdateAspectFace (Standard_False); |
714 | |
715 | ContextFillArea.IsSet = 1; |
716 | |
717 | Update(); |
718 | } |
719 | |
720 | // ======================================================================= |
721 | // function : SetPrimitivesAspect |
722 | // purpose : |
723 | // ======================================================================= |
724 | void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker) |
725 | { |
726 | if (IsDeleted()) |
727 | { |
728 | return; |
729 | } |
730 | |
731 | Standard_Real aScale; |
732 | Quantity_Color aColor; |
733 | Aspect_TypeOfMarker aMarkerType; |
734 | theAspMarker->Values (aColor, aMarkerType, aScale); |
735 | |
736 | ContextMarker.IsDef = 1; |
737 | ContextMarker.Color.r = Standard_ShortReal (aColor.Red()); |
738 | ContextMarker.Color.g = Standard_ShortReal (aColor.Green()); |
739 | ContextMarker.Color.b = Standard_ShortReal (aColor.Blue()); |
740 | ContextMarker.MarkerType = aMarkerType; |
741 | ContextMarker.Scale = Standard_ShortReal (aScale); |
742 | ContextMarker.MarkerImage = theAspMarker->GetMarkerImage(); |
743 | |
744 | ContextMarker.ShaderProgram = theAspMarker->ShaderProgram(); |
745 | |
746 | UpdateAspectMarker (Standard_False); |
747 | |
748 | ContextMarker.IsSet = 1; |
749 | |
750 | Update(); |
751 | } |
752 | |
753 | // ======================================================================= |
754 | // function : SetPrimitivesAspect |
755 | // purpose : |
756 | // ======================================================================= |
757 | void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText) |
758 | { |
759 | if (IsDeleted()) |
760 | { |
761 | return; |
762 | } |
763 | |
764 | Standard_CString aFont; |
765 | Standard_Real aSpace, anExpansion, aTextAngle; |
766 | Quantity_Color aColor, aColorSubTitle; |
767 | Aspect_TypeOfStyleText aStyle; |
768 | Aspect_TypeOfDisplayText aDisplayType; |
769 | Standard_Boolean aTextZoomable; |
770 | Font_FontAspect aTextFontAspect; |
771 | theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDisplayType, |
772 | aColorSubTitle, aTextZoomable, aTextAngle, aTextFontAspect); |
773 | |
774 | ContextText.IsDef = 1; |
775 | ContextText.Color.r = float (aColor.Red()); |
776 | ContextText.Color.g = float (aColor.Green()); |
777 | ContextText.Color.b = float (aColor.Blue()); |
778 | ContextText.Font = (char* )aFont; |
779 | ContextText.Expan = float (anExpansion); |
780 | ContextText.Space = float (aSpace); |
781 | ContextText.Style = aStyle; |
782 | ContextText.DisplayType = aDisplayType; |
783 | ContextText.ColorSubTitle.r = float (aColorSubTitle.Red()); |
784 | ContextText.ColorSubTitle.g = float (aColorSubTitle.Green()); |
785 | ContextText.ColorSubTitle.b = float (aColorSubTitle.Blue()); |
786 | ContextText.TextZoomable = aTextZoomable; |
787 | ContextText.TextAngle = float (aTextAngle); |
788 | ContextText.TextFontAspect = aTextFontAspect; |
789 | ContextText.ShaderProgram = theAspText->ShaderProgram(); |
790 | |
791 | UpdateAspectText (Standard_False); |
792 | |
793 | ContextText.IsSet = 1; |
794 | |
795 | Update(); |
796 | } |
797 | |
798 | // ======================================================================= |
799 | // function : IsGroupPrimitivesAspectSet |
800 | // purpose : |
801 | // ======================================================================= |
802 | Standard_Boolean Graphic3d_Group::IsGroupPrimitivesAspectSet (const Graphic3d_GroupAspect theAspect) const |
803 | { |
804 | switch (theAspect) |
805 | { |
806 | case Graphic3d_ASPECT_LINE: return ContextLine.IsSet; |
807 | case Graphic3d_ASPECT_TEXT: return ContextText.IsSet; |
808 | case Graphic3d_ASPECT_MARKER: return ContextMarker.IsSet; |
809 | case Graphic3d_ASPECT_FILL_AREA: return ContextFillArea.IsSet; |
810 | default: return Standard_False; |
811 | } |
812 | } |
813 | |
814 | // ======================================================================= |
815 | // function : GroupPrimitivesAspect |
816 | // purpose : |
817 | // ======================================================================= |
818 | void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine, |
819 | const Handle(Graphic3d_AspectText3d)& theAspText, |
820 | const Handle(Graphic3d_AspectMarker3d)& theAspMarker, |
821 | const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const |
822 | { |
823 | Quantity_Color aColor; |
824 | Graphic3d_MaterialAspect aFront, aBack; |
825 | |
826 | const CALL_DEF_CONTEXTLINE& anAspLine = ContextLine.IsSet ? ContextLine : myStructure->CStructure()->ContextLine; |
827 | aColor.SetValues (Standard_Real (anAspLine.Color.r), |
828 | Standard_Real (anAspLine.Color.g), |
829 | Standard_Real (anAspLine.Color.b), Quantity_TOC_RGB); |
830 | theAspLine->SetColor (aColor); |
831 | theAspLine->SetType (Aspect_TypeOfLine (anAspLine.LineType)); |
832 | theAspLine->SetWidth (Standard_Real (anAspLine.Width)); |
833 | theAspLine->SetShaderProgram (anAspLine.ShaderProgram); |
834 | |
835 | const CALL_DEF_CONTEXTTEXT& anAspText = ContextText.IsSet ? ContextText : myStructure->CStructure()->ContextText; |
836 | aColor.SetValues (Standard_Real (anAspText.Color.r), |
837 | Standard_Real (anAspText.Color.g), |
838 | Standard_Real (anAspText.Color.b), Quantity_TOC_RGB); |
839 | theAspText->SetColor (aColor); |
840 | aColor.SetValues (Standard_Real (anAspText.ColorSubTitle.r), |
841 | Standard_Real (anAspText.ColorSubTitle.g), |
842 | Standard_Real (anAspText.ColorSubTitle.b), Quantity_TOC_RGB); |
843 | theAspText->SetColorSubTitle (aColor); |
844 | theAspText->SetFont (anAspText.Font); |
845 | theAspText->SetSpace (Standard_Real (anAspText.Space)); |
846 | theAspText->SetExpansionFactor (Standard_Real (anAspText.Expan)); |
847 | theAspText->SetStyle (Aspect_TypeOfStyleText (anAspText.Style)); |
848 | theAspText->SetDisplayType (Aspect_TypeOfDisplayText (anAspText.DisplayType)); |
849 | theAspText->SetShaderProgram (anAspText.ShaderProgram); |
850 | |
851 | const CALL_DEF_CONTEXTMARKER& anAspMarker = ContextMarker.IsSet ? ContextMarker : myStructure->CStructure()->ContextMarker; |
852 | aColor.SetValues (Standard_Real (anAspMarker.Color.r), |
853 | Standard_Real (anAspMarker.Color.g), |
854 | Standard_Real (anAspMarker.Color.b), Quantity_TOC_RGB); |
855 | theAspMarker->SetColor (aColor); |
856 | theAspMarker->SetType (anAspMarker.MarkerType); |
857 | theAspMarker->SetScale (Standard_Real (anAspMarker.Scale)); |
858 | theAspMarker->SetShaderProgram (anAspMarker.ShaderProgram); |
859 | if (anAspMarker.MarkerType == Aspect_TOM_USERDEFINED) |
860 | { |
861 | theAspMarker->SetMarkerImage (ContextMarker.MarkerImage); |
862 | } |
863 | |
864 | const CALL_DEF_CONTEXTFILLAREA& anAspFill = ContextFillArea.IsSet ? ContextFillArea : myStructure->CStructure()->ContextFillArea; |
865 | // Interior |
866 | theAspFill->SetInteriorStyle (Aspect_InteriorStyle (anAspFill.Style)); |
867 | aColor.SetValues (Standard_Real (anAspFill.IntColor.r), |
868 | Standard_Real (anAspFill.IntColor.g), |
869 | Standard_Real (anAspFill.IntColor.b), Quantity_TOC_RGB); |
870 | theAspFill->SetInteriorColor (aColor); |
871 | |
872 | // Edges |
873 | aColor.SetValues (Standard_Real (anAspFill.EdgeColor.r), |
874 | Standard_Real (anAspFill.EdgeColor.g), |
875 | Standard_Real (anAspFill.EdgeColor.b), Quantity_TOC_RGB); |
876 | theAspFill->SetEdgeColor (aColor); |
877 | theAspFill->SetEdgeLineType (Aspect_TypeOfLine (anAspFill.LineType)); |
878 | theAspFill->SetEdgeWidth (Standard_Real (anAspFill.Width)); |
879 | |
880 | // Back Material |
881 | aBack.SetShininess (Standard_Real (anAspFill.Back.Shininess)); |
882 | aBack.SetAmbient (Standard_Real (anAspFill.Back.Ambient)); |
883 | aBack.SetDiffuse (Standard_Real (anAspFill.Back.Diffuse)); |
884 | aBack.SetSpecular (Standard_Real (anAspFill.Back.Specular)); |
885 | aBack.SetTransparency (Standard_Real (anAspFill.Back.Transparency)); |
886 | aBack.SetEmissive (Standard_Real (anAspFill.Back.Emission)); |
887 | anAspFill.Back.IsAmbient == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_AMBIENT) : aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); |
888 | anAspFill.Back.IsDiffuse == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE) : aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); |
889 | anAspFill.Back.IsSpecular == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_SPECULAR) : aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); |
890 | anAspFill.Back.IsEmission == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_EMISSION) : aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION); |
891 | |
892 | aColor.SetValues (Standard_Real (anAspFill.Back.ColorSpec.r), |
893 | Standard_Real (anAspFill.Back.ColorSpec.g), |
894 | Standard_Real (anAspFill.Back.ColorSpec.b), Quantity_TOC_RGB); |
895 | aBack.SetSpecularColor (aColor); |
896 | |
897 | aColor.SetValues (Standard_Real (anAspFill.Back.ColorAmb.r), |
898 | Standard_Real (anAspFill.Back.ColorAmb.g), |
899 | Standard_Real (anAspFill.Back.ColorAmb.b), Quantity_TOC_RGB); |
900 | aBack.SetAmbientColor (aColor); |
901 | |
902 | aColor.SetValues (Standard_Real (anAspFill.Back.ColorDif.r), |
903 | Standard_Real (anAspFill.Back.ColorDif.g), |
904 | Standard_Real (anAspFill.Back.ColorDif.b), Quantity_TOC_RGB); |
905 | aBack.SetDiffuseColor (aColor); |
906 | |
907 | aColor.SetValues (Standard_Real (anAspFill.Back.ColorEms.r), |
908 | Standard_Real (anAspFill.Back.ColorEms.g), |
909 | Standard_Real (anAspFill.Back.ColorEms.b), Quantity_TOC_RGB); |
910 | aBack.SetEmissiveColor (aColor); |
911 | |
912 | aBack.SetEnvReflexion (anAspFill.Back.EnvReflexion); |
913 | |
189f85a3 |
914 | aBack.SetRefractionIndex (Standard_Real (anAspFill.Back.RefractionIndex)); |
915 | aBack.SetBSDF (anAspFill.Back.BSDF); |
916 | |
b64d84be |
917 | // Front Material |
918 | aFront.SetShininess (Standard_Real (anAspFill.Front.Shininess)); |
919 | aFront.SetAmbient (Standard_Real (anAspFill.Front.Ambient)); |
920 | aFront.SetDiffuse (Standard_Real (anAspFill.Front.Diffuse)); |
921 | aFront.SetSpecular (Standard_Real (anAspFill.Front.Specular)); |
922 | aFront.SetTransparency (Standard_Real (anAspFill.Front.Transparency)); |
923 | aFront.SetEmissive (Standard_Real (anAspFill.Back.Emission)); |
924 | anAspFill.Front.IsAmbient == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_AMBIENT) : aFront.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); |
925 | anAspFill.Front.IsDiffuse == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE) : aFront.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); |
926 | anAspFill.Front.IsSpecular == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_SPECULAR) : aFront.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); |
927 | anAspFill.Front.IsEmission == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_EMISSION) : aFront.SetReflectionModeOff (Graphic3d_TOR_EMISSION); |
928 | |
929 | aColor.SetValues (Standard_Real (anAspFill.Front.ColorSpec.r), |
930 | Standard_Real (anAspFill.Front.ColorSpec.g), |
931 | Standard_Real (anAspFill.Front.ColorSpec.b), Quantity_TOC_RGB); |
932 | aFront.SetSpecularColor (aColor); |
933 | |
934 | aColor.SetValues (Standard_Real (anAspFill.Front.ColorAmb.r), |
935 | Standard_Real (anAspFill.Front.ColorAmb.g), |
936 | Standard_Real (anAspFill.Front.ColorAmb.b), Quantity_TOC_RGB); |
937 | aFront.SetAmbientColor (aColor); |
938 | |
939 | aColor.SetValues (Standard_Real (anAspFill.Front.ColorDif.r), |
940 | Standard_Real (anAspFill.Front.ColorDif.g), |
941 | Standard_Real (anAspFill.Front.ColorDif.b), Quantity_TOC_RGB); |
942 | aFront.SetDiffuseColor (aColor); |
943 | |
944 | aColor.SetValues (Standard_Real (anAspFill.Front.ColorEms.r), |
945 | Standard_Real (anAspFill.Front.ColorEms.g), |
946 | Standard_Real (anAspFill.Front.ColorEms.b), Quantity_TOC_RGB); |
947 | aFront.SetEmissiveColor (aColor); |
948 | |
949 | aFront.SetEnvReflexion (anAspFill.Front.EnvReflexion); |
950 | |
189f85a3 |
951 | aFront.SetRefractionIndex (Standard_Real (anAspFill.Front.RefractionIndex)); |
952 | aFront.SetBSDF (anAspFill.Front.BSDF); |
953 | |
b64d84be |
954 | // Edges |
955 | anAspFill.Edge == 1 ? theAspFill->SetEdgeOn() : theAspFill->SetEdgeOff(); |
956 | // Hatch |
957 | theAspFill->SetHatchStyle (Aspect_HatchStyle (anAspFill.Hatch)); |
958 | // Materials |
959 | // Front and Back face |
960 | anAspFill.Distinguish == 1 ? theAspFill->SetDistinguishOn() : theAspFill->SetDistinguishOff(); |
961 | anAspFill.BackFace == 1 ? theAspFill->SuppressBackFace() : theAspFill->AllowBackFace(); |
962 | // Texture |
963 | theAspFill->SetTextureMap (anAspFill.Texture.TextureMap); |
964 | anAspFill.Texture.doTextureMap == 1 ? theAspFill->SetTextureMapOn() : theAspFill->SetTextureMapOff(); |
965 | theAspFill->SetShaderProgram (anAspFill.ShaderProgram); |
966 | theAspFill->SetPolygonOffsets (anAspFill.PolygonOffsetMode, |
967 | anAspFill.PolygonOffsetFactor, |
968 | anAspFill.PolygonOffsetUnits); |
969 | theAspFill->SetBackMaterial (aBack); |
970 | theAspFill->SetFrontMaterial (aFront); |
971 | } |
972 | |
973 | // ======================================================================= |
974 | // function : PrimitivesAspect |
975 | // purpose : |
976 | // ======================================================================= |
977 | void Graphic3d_Group::PrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine, |
978 | const Handle(Graphic3d_AspectText3d)& theAspText, |
979 | const Handle(Graphic3d_AspectMarker3d)& theAspMarker, |
980 | const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const |
981 | { |
982 | GroupPrimitivesAspect (theAspLine, theAspText, theAspMarker, theAspFill); |
983 | } |
984 | |
985 | // ======================================================================= |
986 | // function : AddPrimitiveArray |
987 | // purpose : |
988 | // ======================================================================= |
989 | void Graphic3d_Group::AddPrimitiveArray (const Handle(Graphic3d_ArrayOfPrimitives)& thePrim, |
990 | const Standard_Boolean theToEvalMinMax) |
991 | { |
992 | if (IsDeleted() |
993 | || !thePrim->IsValid()) |
994 | { |
995 | return; |
996 | } |
997 | |
871fa103 |
998 | AddPrimitiveArray (thePrim->Type(), thePrim->Indices(), thePrim->Attributes(), thePrim->Bounds(), theToEvalMinMax); |
999 | } |
1000 | |
1001 | // ======================================================================= |
1002 | // function : AddPrimitiveArray |
1003 | // purpose : |
1004 | // ======================================================================= |
1005 | void Graphic3d_Group::AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType, |
1006 | const Handle(Graphic3d_IndexBuffer)& , |
1007 | const Handle(Graphic3d_Buffer)& theAttribs, |
1008 | const Handle(Graphic3d_BoundBuffer)& , |
1009 | const Standard_Boolean theToEvalMinMax) |
1010 | { |
1011 | if (IsDeleted() |
1012 | || theAttribs.IsNull()) |
1013 | { |
1014 | return; |
1015 | } |
1016 | |
b64d84be |
1017 | if (!MyContainsFacet |
871fa103 |
1018 | && theType != Graphic3d_TOPA_POLYLINES |
1019 | && theType != Graphic3d_TOPA_SEGMENTS |
1020 | && theType != Graphic3d_TOPA_POINTS) |
b64d84be |
1021 | { |
1022 | myStructure->GroupsWithFacet (1); |
1023 | MyContainsFacet = Standard_True; |
1024 | } |
1025 | |
b64d84be |
1026 | if (theToEvalMinMax) |
1027 | { |
871fa103 |
1028 | const Standard_Integer aNbVerts = theAttribs->NbElements; |
1029 | for (Standard_Integer anAttribIter = 0; anAttribIter < theAttribs->NbAttributes; ++anAttribIter) |
b64d84be |
1030 | { |
871fa103 |
1031 | const Graphic3d_Attribute& anAttrib = theAttribs->Attribute (anAttribIter); |
1032 | if (anAttrib.Id != Graphic3d_TOA_POS) |
1033 | { |
1034 | continue; |
1035 | } |
1036 | |
1037 | const size_t anOffset = theAttribs->AttributeOffset (anAttribIter); |
1038 | switch (anAttrib.DataType) |
1039 | { |
1040 | case Graphic3d_TOD_VEC2: |
1041 | { |
1042 | for (Standard_Integer aVertIter = 0; aVertIter < aNbVerts; ++aVertIter) |
1043 | { |
1044 | const Graphic3d_Vec2& aVert = *reinterpret_cast<const Graphic3d_Vec2* >(theAttribs->value (aVertIter) + anOffset); |
b7cd4ba7 |
1045 | myBounds.Add (Graphic3d_Vec4 (aVert.x(), aVert.y(), 0.0f, 1.0f)); |
871fa103 |
1046 | } |
1047 | break; |
1048 | } |
1049 | case Graphic3d_TOD_VEC3: |
1050 | case Graphic3d_TOD_VEC4: |
1051 | { |
1052 | for (Standard_Integer aVertIter = 0; aVertIter < aNbVerts; ++aVertIter) |
1053 | { |
1054 | const Graphic3d_Vec3& aVert = *reinterpret_cast<const Graphic3d_Vec3* >(theAttribs->value (aVertIter) + anOffset); |
b7cd4ba7 |
1055 | myBounds.Add (Graphic3d_Vec4 (aVert.x(), aVert.y(), aVert.z(), 1.0f)); |
871fa103 |
1056 | } |
1057 | break; |
1058 | } |
1059 | default: break; |
1060 | } |
1061 | break; |
b64d84be |
1062 | } |
1063 | } |
1064 | |
1065 | Update(); |
1066 | } |
1067 | |
1068 | // ======================================================================= |
1069 | // function : Marker |
1070 | // purpose : |
1071 | // ======================================================================= |
1072 | void Graphic3d_Group::Marker (const Graphic3d_Vertex& thePoint, |
1073 | const Standard_Boolean theToEvalMinMax) |
1074 | { |
1075 | Handle(Graphic3d_ArrayOfPoints) aPoints = new Graphic3d_ArrayOfPoints (1); |
1076 | aPoints->AddVertex (thePoint.X(), thePoint.Y(), thePoint.Z()); |
1077 | AddPrimitiveArray (aPoints, theToEvalMinMax); |
1078 | } |
1079 | |
1080 | // ======================================================================= |
1081 | // function : UserDraw |
1082 | // purpose : |
1083 | // ======================================================================= |
1084 | void Graphic3d_Group::UserDraw (const Standard_Address /*theObject*/, |
1085 | const Standard_Boolean /*theToEvalMinMax*/, |
1086 | const Standard_Boolean theContainsFacet) |
1087 | { |
1088 | if (IsDeleted()) |
1089 | { |
1090 | return; |
1091 | } |
1092 | |
1093 | // Without this modification, the group assumes the primitive contains |
1094 | // no polygons and does not require the Z-buffer for display. |
1095 | if (!MyContainsFacet && theContainsFacet) |
1096 | { |
1097 | myStructure->GroupsWithFacet (1); |
1098 | MyContainsFacet = Standard_True; |
1099 | } |
1100 | |
b64d84be |
1101 | Update(); |
1102 | } |
1103 | |
1104 | // ======================================================================= |
1105 | // function : Text |
1106 | // purpose : |
1107 | // ======================================================================= |
1108 | void Graphic3d_Group::Text (const Standard_CString /*theText*/, |
1109 | const Graphic3d_Vertex& thePoint, |
1110 | const Standard_Real /*theHeight*/, |
1111 | const Quantity_PlaneAngle /*theAngle*/, |
1112 | const Graphic3d_TextPath /*theTp*/, |
1113 | const Graphic3d_HorizontalTextAlignment /*theHta*/, |
1114 | const Graphic3d_VerticalTextAlignment /*theVta*/, |
1115 | const Standard_Boolean theToEvalMinMax) |
1116 | { |
1117 | if (IsDeleted()) |
1118 | { |
1119 | return; |
1120 | } |
1121 | |
b64d84be |
1122 | if (theToEvalMinMax) |
1123 | { |
1124 | Standard_ShortReal x, y, z; |
1125 | thePoint.Coord (x, y, z); |
b7cd4ba7 |
1126 | myStructure->CStructure()->Is2dText = Standard_True; |
1127 | myBounds.Add (Graphic3d_Vec4 (static_cast<Standard_ShortReal> (x), |
1128 | static_cast<Standard_ShortReal> (y), |
1129 | static_cast<Standard_ShortReal> (z), |
1130 | 1.0f)); |
b64d84be |
1131 | } |
1132 | Update(); |
1133 | } |
1134 | |
1135 | // ======================================================================= |
1136 | // function : Text |
1137 | // purpose : |
1138 | // ======================================================================= |
1139 | void Graphic3d_Group::Text (const Standard_CString theText, |
1140 | const Graphic3d_Vertex& thePoint, |
1141 | const Standard_Real theHeight, |
1142 | const Standard_Boolean theToEvalMinMax) |
1143 | { |
1144 | Text (theText, thePoint, theHeight, 0.0, |
1145 | Graphic3d_TP_RIGHT, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM, theToEvalMinMax); |
1146 | } |
1147 | |
1148 | // ======================================================================= |
1149 | // function : Text |
1150 | // purpose : |
1151 | // ======================================================================= |
1152 | void Graphic3d_Group::Text (const TCollection_ExtendedString& theText, |
1153 | const Graphic3d_Vertex& thePoint, |
1154 | const Standard_Real theHeight, |
1155 | const Quantity_PlaneAngle theAngle, |
1156 | const Graphic3d_TextPath theTp, |
1157 | const Graphic3d_HorizontalTextAlignment theHta, |
1158 | const Graphic3d_VerticalTextAlignment theVta, |
1159 | const Standard_Boolean theToEvalMinMax) |
1160 | { |
1161 | const NCollection_String aText ((Standard_Utf16Char* )theText.ToExtString()); |
1162 | Text (aText.ToCString(), thePoint, theHeight, theAngle, |
1163 | theTp, theHta, theVta, theToEvalMinMax); |
1164 | } |
1165 | |
1166 | // ======================================================================= |
1167 | // function : Text |
1168 | // purpose : |
1169 | // ======================================================================= |
1170 | void Graphic3d_Group::Text (const TCollection_ExtendedString& theText, |
1171 | const Graphic3d_Vertex& thePoint, |
1172 | const Standard_Real theHeight, |
1173 | const Standard_Boolean theToEvalMinMax) |
1174 | { |
1175 | const NCollection_String aText ((Standard_Utf16Char* )theText.ToExtString()); |
1176 | Text (aText.ToCString(), thePoint, theHeight, 0.0, |
1177 | Graphic3d_TP_RIGHT, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM, theToEvalMinMax); |
7fd59977 |
1178 | } |
31c0e219 |
1179 | |
1180 | // ======================================================================= |
1181 | // function : SetClosed |
1182 | // purpose : |
1183 | // ======================================================================= |
1184 | void Graphic3d_Group::SetClosed (const Standard_Boolean theIsClosed) |
1185 | { |
1186 | myIsClosed = theIsClosed; |
1187 | } |
1188 | |
1189 | // ======================================================================= |
1190 | // function : IsClosed |
1191 | // purpose : |
1192 | // ======================================================================= |
1193 | Standard_Boolean Graphic3d_Group::IsClosed() const |
1194 | { |
1195 | return myIsClosed; |
1196 | } |
b7cd4ba7 |
1197 | |
1198 | //======================================================================= |
1199 | //function : BoundingBox |
1200 | //purpose : |
1201 | //======================================================================= |
1202 | const Graphic3d_BndBox4f& Graphic3d_Group::BoundingBox() const |
1203 | { |
1204 | return myBounds; |
1205 | } |
1206 | |
1207 | //======================================================================= |
1208 | //function : ChangeBoundingBox |
1209 | //purpose : |
1210 | //======================================================================= |
1211 | Graphic3d_BndBox4f& Graphic3d_Group::ChangeBoundingBox() |
1212 | { |
1213 | return myBounds; |
1214 | } |