1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Graphic3d_Group.ixx>
19 #include <Graphic3d_ArrayOfPoints.hxx>
20 #include <Graphic3d_StructureManager.hxx>
21 #include <Graphic3d_ShaderProgram.hxx>
22 #include <Graphic3d_TransModeFlags.hxx>
23 #include <Graphic3d_TextureMap.hxx>
24 #include <Message.hxx>
25 #include <Message_Messenger.hxx>
26 #include <NCollection_String.hxx>
27 #include <TCollection_AsciiString.hxx>
29 #include <Graphic3d_CStructure.hxx>
30 #include <Graphic3d_Structure.pxx>
32 #define MyIsEmpty myCBitFields.bool1
33 #define MyContainsFacet myCBitFields.bool2
35 // =======================================================================
36 // function : Graphic3d_Group
38 // =======================================================================
39 Graphic3d_Group::Graphic3d_Group (const Handle(Graphic3d_Structure)& theStruct)
41 myBounds.XMin = ShortRealLast();
42 myBounds.YMin = ShortRealLast();
43 myBounds.ZMin = ShortRealLast();
44 myBounds.XMax = ShortRealFirst();
45 myBounds.YMax = ShortRealFirst();
46 myBounds.ZMax = ShortRealFirst();
49 // A small commentary on the usage of This!
51 // Graphic3d_Group is created in a structure. Graphic3d_Structure is a
52 // manager of Graphic3d_Group. In the constructor of Graphic3d_Group
53 // a method Add of Graphic3d_Structure is called. It allows adding
54 // the instance of Graphic3d_Group in its manager. So there are 2 references
55 // to <me> and everything works well.
57 // This () is the instance of the class, the current group
58 //Handle(Graphic3d_Group) me = Handle(Graphic3d_Group)::DownCast (This());
60 myStructure = theStruct.operator->();
62 MyContainsFacet = Standard_False,
63 MyIsEmpty = Standard_True;
65 ContextLine.IsDef = 0;
66 ContextText.IsDef = 0;
67 ContextMarker.IsDef = 0;
68 ContextFillArea.IsDef = 0;
70 ContextLine.IsSet = 0;
71 ContextText.IsSet = 0;
72 ContextMarker.IsSet = 0;
73 ContextFillArea.IsSet = 0;
76 // =======================================================================
79 // =======================================================================
80 void Graphic3d_Group::Clear (Standard_Boolean theUpdateStructureMgr)
87 ContextLine.IsSet = 0,
88 ContextText.IsSet = 0,
89 ContextMarker.IsSet = 0,
90 ContextFillArea.IsSet = 0;
92 ContextLine.IsDef = 0,
93 ContextText.IsDef = 0,
94 ContextMarker.IsDef = 0,
95 ContextFillArea.IsDef = 0;
97 myBounds.XMin = ShortRealLast();
98 myBounds.YMin = ShortRealLast();
99 myBounds.ZMin = ShortRealLast();
100 myBounds.XMax = ShortRealFirst();
101 myBounds.YMax = ShortRealFirst();
102 myBounds.ZMax = ShortRealFirst();
106 myStructure->GroupsWithFacet (-1);
107 MyContainsFacet = Standard_False;
109 MyIsEmpty = Standard_True;
111 // clear method could be used on Graphic3d_Structure destruction,
112 // and its structure manager could be already destroyed, in that
113 // case we don't need to update it;
114 if (theUpdateStructureMgr)
120 // =======================================================================
121 // function : Destroy
123 // =======================================================================
124 void Graphic3d_Group::Destroy()
126 // tell graphics driver to clear internal resources of the group
127 Clear (Standard_False);
130 // =======================================================================
133 // =======================================================================
134 void Graphic3d_Group::Remove()
143 myStructure->GroupsWithFacet (-1);
144 MyContainsFacet = Standard_False;
146 myStructure->Remove (this);
150 myBounds.XMin = ShortRealLast();
151 myBounds.YMin = ShortRealLast();
152 myBounds.ZMin = ShortRealLast();
153 myBounds.XMax = ShortRealFirst();
154 myBounds.YMax = ShortRealFirst();
155 myBounds.ZMax = ShortRealFirst();
157 MyIsEmpty = Standard_True;
160 // =======================================================================
161 // function : IsDeleted
163 // =======================================================================
164 Standard_Boolean Graphic3d_Group::IsDeleted() const
166 return myStructure == NULL
167 || myStructure->IsDeleted();
170 // =======================================================================
171 // function : ContainsFacet
173 // =======================================================================
174 Standard_Boolean Graphic3d_Group::ContainsFacet() const
176 return MyContainsFacet;
179 // =======================================================================
180 // function : IsEmpty
182 // =======================================================================
183 Standard_Boolean Graphic3d_Group::IsEmpty() const
187 return Standard_True;
190 const Standard_ShortReal RL = ShortRealLast();
191 const Standard_ShortReal RF = ShortRealFirst();
192 const Standard_Boolean isEmpty = ((myBounds.XMin == RL) && (myBounds.YMin == RL)
193 && (myBounds.ZMin == RL) && (myBounds.XMax == RF)
194 && (myBounds.YMax == RF) && (myBounds.ZMax == RF));
195 if (isEmpty != MyIsEmpty)
197 ::Message::DefaultMessenger()->Send ("Graphic3d_Group: MyIsEmpty != IsEmpty()", Message_Trace);
202 // =======================================================================
203 // function : SetMinMaxValues
205 // =======================================================================
206 void Graphic3d_Group::SetMinMaxValues (const Standard_Real theXMin, const Standard_Real theYMin, const Standard_Real theZMin,
207 const Standard_Real theXMax, const Standard_Real theYMax, const Standard_Real theZMax)
209 myBounds.XMin = Standard_ShortReal (theXMin);
210 myBounds.YMin = Standard_ShortReal (theYMin);
211 myBounds.ZMin = Standard_ShortReal (theZMin);
212 myBounds.XMax = Standard_ShortReal (theXMax);
213 myBounds.YMax = Standard_ShortReal (theYMax);
214 myBounds.ZMax = Standard_ShortReal (theZMax);
217 // =======================================================================
218 // function : MinMaxValues
220 // =======================================================================
221 void Graphic3d_Group::MinMaxValues (Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin,
222 Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax) const
224 MinMaxCoord (theXMin, theYMin, theZMin,
225 theXMax, theYMax, theZMax);
228 // =======================================================================
229 // function : Structure
231 // =======================================================================
232 Handle(Graphic3d_Structure) Graphic3d_Group::Structure() const
237 // =======================================================================
238 // function : MinMaxCoord
240 // =======================================================================
241 void Graphic3d_Group::MinMaxCoord (Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin,
242 Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax) const
247 theXMin = theYMin = theZMin = ShortRealFirst();
248 theXMax = theYMax = theZMax = ShortRealLast();
252 theXMin = Standard_Real (myBounds.XMin);
253 theYMin = Standard_Real (myBounds.YMin);
254 theZMin = Standard_Real (myBounds.ZMin);
255 theXMax = Standard_Real (myBounds.XMax);
256 theYMax = Standard_Real (myBounds.YMax);
257 theZMax = Standard_Real (myBounds.ZMax);
261 // =======================================================================
264 // =======================================================================
265 void Graphic3d_Group::Update() const
272 if (myStructure->StructureManager()->UpdateMode() == Aspect_TOU_ASAP)
274 myStructure->StructureManager()->Update();
278 // =======================================================================
279 // function : SetGroupPrimitivesAspect
281 // =======================================================================
282 void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
289 Standard_Real aWidth;
290 Quantity_Color aColor;
291 Aspect_TypeOfLine aLType;
292 theAspLine->Values (aColor, aLType, aWidth);
294 ContextLine.IsDef = 1;
295 ContextLine.Color.r = float (aColor.Red());
296 ContextLine.Color.g = float (aColor.Green());
297 ContextLine.Color.b = float (aColor.Blue());
298 ContextLine.LineType = aLType;
299 ContextLine.Width = float (aWidth);
300 ContextLine.ShaderProgram = theAspLine->ShaderProgram();
302 UpdateAspectLine (Standard_True);
304 ContextLine.IsSet = 1;
309 // =======================================================================
310 // function : SetGroupPrimitivesAspect
312 // =======================================================================
313 void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
320 Standard_Real anRGB[3];
321 Standard_Real aWidth;
322 Quantity_Color anIntColor;
323 Quantity_Color aBackIntColor;
324 Quantity_Color anEdgeColor;
325 Aspect_TypeOfLine aLType;
326 Aspect_InteriorStyle aStyle;
327 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
329 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
330 ContextFillArea.Style = aStyle;
331 ContextFillArea.IntColor.r = float (anRGB[0]);
332 ContextFillArea.IntColor.g = float (anRGB[1]);
333 ContextFillArea.IntColor.b = float (anRGB[2]);
335 if (theAspFill->Distinguish())
337 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
339 ContextFillArea.BackIntColor.r = float (anRGB[0]);
340 ContextFillArea.BackIntColor.g = float (anRGB[1]);
341 ContextFillArea.BackIntColor.b = float (anRGB[2]);
344 ContextFillArea.Edge = theAspFill->Edge() ? 1 : 0;
345 ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
346 ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
347 ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
348 ContextFillArea.LineType = aLType;
349 ContextFillArea.Width = float (aWidth);
350 ContextFillArea.Hatch = theAspFill->HatchStyle();
352 // Front and Back face
353 ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
354 ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
357 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
360 ContextFillArea.Back.Shininess = float (aBack.Shininess());
361 ContextFillArea.Back.Ambient = float (aBack.Ambient());
362 ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
363 ContextFillArea.Back.Specular = float (aBack.Specular());
364 ContextFillArea.Back.Transparency = float (aBack.Transparency());
365 ContextFillArea.Back.Emission = float (aBack.Emissive());
368 ContextFillArea.Back.IsAmbient = aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0;
369 ContextFillArea.Back.IsDiffuse = aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0;
370 ContextFillArea.Back.IsSpecular = aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0;
371 ContextFillArea.Back.IsEmission = aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0;
374 ContextFillArea.Back.IsPhysic = aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0;
377 ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
378 ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
379 ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
382 ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
383 ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
384 ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
387 ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
388 ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
389 ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
392 ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
393 ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
394 ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
396 ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
399 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
401 ContextFillArea.Front.Shininess = float (aFront.Shininess());
402 ContextFillArea.Front.Ambient = float (aFront.Ambient());
403 ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
404 ContextFillArea.Front.Specular = float (aFront.Specular());
405 ContextFillArea.Front.Transparency = float (aFront.Transparency());
406 ContextFillArea.Front.Emission = float (aFront.Emissive());
409 ContextFillArea.Front.IsAmbient = aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0;
410 ContextFillArea.Front.IsDiffuse = aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0;
411 ContextFillArea.Front.IsSpecular = aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0;
412 ContextFillArea.Front.IsEmission = aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0;
415 ContextFillArea.Front.IsPhysic = aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0;
418 ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
419 ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
420 ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
423 ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
424 ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
425 ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
428 ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
429 ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
430 ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
433 ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
434 ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
435 ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
437 ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
439 ContextFillArea.IsDef = 1; // Definition material ok
442 ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
443 ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
445 Standard_Integer aPolyMode;
446 Standard_ShortReal aPolyFactor, aPolyUnits;
447 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
448 ContextFillArea.PolygonOffsetMode = aPolyMode;
449 ContextFillArea.PolygonOffsetFactor = aPolyFactor;
450 ContextFillArea.PolygonOffsetUnits = aPolyUnits;
452 ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
454 UpdateAspectFace (Standard_True);
456 ContextFillArea.IsSet = 1;
461 // =======================================================================
462 // function : SetGroupPrimitivesAspect
464 // =======================================================================
465 void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
472 Standard_Real aScale;
473 Quantity_Color aColor;
474 Aspect_TypeOfMarker aMarkerType;
475 theAspMarker->Values (aColor, aMarkerType, aScale);
477 ContextMarker.IsDef = 1;
478 ContextMarker.Color.r = Standard_ShortReal (aColor.Red());
479 ContextMarker.Color.g = Standard_ShortReal (aColor.Green());
480 ContextMarker.Color.b = Standard_ShortReal (aColor.Blue());
481 ContextMarker.MarkerType = aMarkerType;
482 ContextMarker.Scale = Standard_ShortReal (aScale);
483 ContextMarker.MarkerImage = theAspMarker->GetMarkerImage();
484 ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
486 UpdateAspectMarker (Standard_True);
488 ContextMarker.IsSet = 1;
493 // =======================================================================
494 // function : SetGroupPrimitivesAspect
496 // =======================================================================
497 void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
504 Standard_Real anExpansion, aSpace, aTextAngle;
505 Quantity_Color aColor, aColorSubTitle;
506 Standard_CString aFont;
507 Aspect_TypeOfStyleText aStyle;
508 Aspect_TypeOfDisplayText aDisplayType;
509 Standard_Boolean isTextZoomable;
510 Font_FontAspect aTextFontAspect;
511 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDisplayType,
512 aColorSubTitle, isTextZoomable, aTextAngle, aTextFontAspect);
514 ContextText.IsDef = 1;
515 ContextText.Color.r = float (aColor.Red());
516 ContextText.Color.g = float (aColor.Green());
517 ContextText.Color.b = float (aColor.Blue());
518 ContextText.Font = (char* )aFont;
519 ContextText.Expan = float (anExpansion);
520 ContextText.Space = float (aSpace);
521 ContextText.Style = aStyle;
522 ContextText.DisplayType = aDisplayType;
523 ContextText.ColorSubTitle.r = float (aColorSubTitle.Red());
524 ContextText.ColorSubTitle.g = float (aColorSubTitle.Green());
525 ContextText.ColorSubTitle.b = float (aColorSubTitle.Blue());
526 ContextText.TextZoomable = isTextZoomable;
527 ContextText.TextAngle = float (aTextAngle);
528 ContextText.TextFontAspect = aTextFontAspect;
529 ContextText.ShaderProgram = theAspText->ShaderProgram();
531 UpdateAspectText (Standard_True);
533 ContextText.IsSet = 1;
538 // =======================================================================
539 // function : SetPrimitivesAspect
541 // =======================================================================
542 void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
549 Standard_Real aWidth;
550 Quantity_Color aColor;
551 Aspect_TypeOfLine aLType;
552 theAspLine->Values (aColor, aLType, aWidth);
554 ContextLine.IsDef = 1;
555 ContextLine.Color.r = float (aColor.Red());
556 ContextLine.Color.g = float (aColor.Green());
557 ContextLine.Color.b = float (aColor.Blue());
558 ContextLine.LineType = aLType;
559 ContextLine.Width = float (aWidth);
560 ContextLine.ShaderProgram = theAspLine->ShaderProgram();
562 UpdateAspectLine (Standard_False);
564 ContextLine.IsSet = 1;
569 // =======================================================================
570 // function : SetPrimitivesAspect
572 // =======================================================================
573 void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
580 Standard_Real anRGB[3];
581 Standard_Real aWidth;
582 Quantity_Color anIntColor;
583 Quantity_Color aBackIntColor;
584 Quantity_Color anEdgeColor;
585 Aspect_TypeOfLine aLType;
586 Aspect_InteriorStyle aStyle;
587 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
589 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
590 ContextFillArea.Style = aStyle;
591 ContextFillArea.IntColor.r = float (anRGB[0]);
592 ContextFillArea.IntColor.g = float (anRGB[1]);
593 ContextFillArea.IntColor.b = float (anRGB[2]);
595 if (theAspFill->Distinguish())
597 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
599 ContextFillArea.BackIntColor.r = float(anRGB[0]);
600 ContextFillArea.BackIntColor.g = float(anRGB[1]);
601 ContextFillArea.BackIntColor.b = float(anRGB[2]);
604 ContextFillArea.Edge = theAspFill->Edge() ? 1 : 0;
605 ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
606 ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
607 ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
608 ContextFillArea.LineType = aLType;
609 ContextFillArea.Width = float (aWidth);
610 ContextFillArea.Hatch = theAspFill->HatchStyle();
612 // Front and Back face
613 ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
614 ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
617 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
619 ContextFillArea.Back.Shininess = float (aBack.Shininess());
620 ContextFillArea.Back.Ambient = float (aBack.Ambient());
621 ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
622 ContextFillArea.Back.Specular = float (aBack.Specular());
623 ContextFillArea.Back.Transparency = float (aBack.Transparency());
624 ContextFillArea.Back.Emission = float (aBack.Emissive());
627 ContextFillArea.Back.IsAmbient = aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0;
628 ContextFillArea.Back.IsDiffuse = aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0;
629 ContextFillArea.Back.IsSpecular = aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0;
630 ContextFillArea.Back.IsEmission = aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0;
633 ContextFillArea.Back.IsPhysic = aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0;
636 ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
637 ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
638 ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
641 ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
642 ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
643 ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
646 ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
647 ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
648 ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
651 ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
652 ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
653 ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
655 ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
658 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
660 ContextFillArea.Front.Shininess = float (aFront.Shininess());
661 ContextFillArea.Front.Ambient = float (aFront.Ambient());
662 ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
663 ContextFillArea.Front.Specular = float (aFront.Specular());
664 ContextFillArea.Front.Transparency = float (aFront.Transparency());
665 ContextFillArea.Front.Emission = float (aFront.Emissive());
668 ContextFillArea.Front.IsAmbient = aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0;
669 ContextFillArea.Front.IsDiffuse = aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0;
670 ContextFillArea.Front.IsSpecular = aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0;
671 ContextFillArea.Front.IsEmission = aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0;
674 ContextFillArea.Front.IsPhysic = aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0;
677 ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
678 ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
679 ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
682 ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
683 ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
684 ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
687 ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
688 ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
689 ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
692 ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
693 ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
694 ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
696 ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
698 ContextFillArea.IsDef = 1; // Material definition ok
700 ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
701 ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
703 Standard_Integer aPolyMode;
704 Standard_ShortReal aPolyFactor, aPolyUnits;
705 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
706 ContextFillArea.PolygonOffsetMode = aPolyMode;
707 ContextFillArea.PolygonOffsetFactor = aPolyFactor;
708 ContextFillArea.PolygonOffsetUnits = aPolyUnits;
710 ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
712 UpdateAspectFace (Standard_False);
714 ContextFillArea.IsSet = 1;
719 // =======================================================================
720 // function : SetPrimitivesAspect
722 // =======================================================================
723 void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
730 Standard_Real aScale;
731 Quantity_Color aColor;
732 Aspect_TypeOfMarker aMarkerType;
733 theAspMarker->Values (aColor, aMarkerType, aScale);
735 ContextMarker.IsDef = 1;
736 ContextMarker.Color.r = Standard_ShortReal (aColor.Red());
737 ContextMarker.Color.g = Standard_ShortReal (aColor.Green());
738 ContextMarker.Color.b = Standard_ShortReal (aColor.Blue());
739 ContextMarker.MarkerType = aMarkerType;
740 ContextMarker.Scale = Standard_ShortReal (aScale);
741 ContextMarker.MarkerImage = theAspMarker->GetMarkerImage();
743 ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
745 UpdateAspectMarker (Standard_False);
747 ContextMarker.IsSet = 1;
752 // =======================================================================
753 // function : SetPrimitivesAspect
755 // =======================================================================
756 void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
763 Standard_CString aFont;
764 Standard_Real aSpace, anExpansion, aTextAngle;
765 Quantity_Color aColor, aColorSubTitle;
766 Aspect_TypeOfStyleText aStyle;
767 Aspect_TypeOfDisplayText aDisplayType;
768 Standard_Boolean aTextZoomable;
769 Font_FontAspect aTextFontAspect;
770 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDisplayType,
771 aColorSubTitle, aTextZoomable, aTextAngle, aTextFontAspect);
773 ContextText.IsDef = 1;
774 ContextText.Color.r = float (aColor.Red());
775 ContextText.Color.g = float (aColor.Green());
776 ContextText.Color.b = float (aColor.Blue());
777 ContextText.Font = (char* )aFont;
778 ContextText.Expan = float (anExpansion);
779 ContextText.Space = float (aSpace);
780 ContextText.Style = aStyle;
781 ContextText.DisplayType = aDisplayType;
782 ContextText.ColorSubTitle.r = float (aColorSubTitle.Red());
783 ContextText.ColorSubTitle.g = float (aColorSubTitle.Green());
784 ContextText.ColorSubTitle.b = float (aColorSubTitle.Blue());
785 ContextText.TextZoomable = aTextZoomable;
786 ContextText.TextAngle = float (aTextAngle);
787 ContextText.TextFontAspect = aTextFontAspect;
788 ContextText.ShaderProgram = theAspText->ShaderProgram();
790 UpdateAspectText (Standard_False);
792 ContextText.IsSet = 1;
797 // =======================================================================
798 // function : IsGroupPrimitivesAspectSet
800 // =======================================================================
801 Standard_Boolean Graphic3d_Group::IsGroupPrimitivesAspectSet (const Graphic3d_GroupAspect theAspect) const
805 case Graphic3d_ASPECT_LINE: return ContextLine.IsSet;
806 case Graphic3d_ASPECT_TEXT: return ContextText.IsSet;
807 case Graphic3d_ASPECT_MARKER: return ContextMarker.IsSet;
808 case Graphic3d_ASPECT_FILL_AREA: return ContextFillArea.IsSet;
809 default: return Standard_False;
813 // =======================================================================
814 // function : GroupPrimitivesAspect
816 // =======================================================================
817 void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine,
818 const Handle(Graphic3d_AspectText3d)& theAspText,
819 const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
820 const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
822 Quantity_Color aColor;
823 Graphic3d_MaterialAspect aFront, aBack;
825 const CALL_DEF_CONTEXTLINE& anAspLine = ContextLine.IsSet ? ContextLine : myStructure->CStructure()->ContextLine;
826 aColor.SetValues (Standard_Real (anAspLine.Color.r),
827 Standard_Real (anAspLine.Color.g),
828 Standard_Real (anAspLine.Color.b), Quantity_TOC_RGB);
829 theAspLine->SetColor (aColor);
830 theAspLine->SetType (Aspect_TypeOfLine (anAspLine.LineType));
831 theAspLine->SetWidth (Standard_Real (anAspLine.Width));
832 theAspLine->SetShaderProgram (anAspLine.ShaderProgram);
834 const CALL_DEF_CONTEXTTEXT& anAspText = ContextText.IsSet ? ContextText : myStructure->CStructure()->ContextText;
835 aColor.SetValues (Standard_Real (anAspText.Color.r),
836 Standard_Real (anAspText.Color.g),
837 Standard_Real (anAspText.Color.b), Quantity_TOC_RGB);
838 theAspText->SetColor (aColor);
839 aColor.SetValues (Standard_Real (anAspText.ColorSubTitle.r),
840 Standard_Real (anAspText.ColorSubTitle.g),
841 Standard_Real (anAspText.ColorSubTitle.b), Quantity_TOC_RGB);
842 theAspText->SetColorSubTitle (aColor);
843 theAspText->SetFont (anAspText.Font);
844 theAspText->SetSpace (Standard_Real (anAspText.Space));
845 theAspText->SetExpansionFactor (Standard_Real (anAspText.Expan));
846 theAspText->SetStyle (Aspect_TypeOfStyleText (anAspText.Style));
847 theAspText->SetDisplayType (Aspect_TypeOfDisplayText (anAspText.DisplayType));
848 theAspText->SetShaderProgram (anAspText.ShaderProgram);
850 const CALL_DEF_CONTEXTMARKER& anAspMarker = ContextMarker.IsSet ? ContextMarker : myStructure->CStructure()->ContextMarker;
851 aColor.SetValues (Standard_Real (anAspMarker.Color.r),
852 Standard_Real (anAspMarker.Color.g),
853 Standard_Real (anAspMarker.Color.b), Quantity_TOC_RGB);
854 theAspMarker->SetColor (aColor);
855 theAspMarker->SetType (anAspMarker.MarkerType);
856 theAspMarker->SetScale (Standard_Real (anAspMarker.Scale));
857 theAspMarker->SetShaderProgram (anAspMarker.ShaderProgram);
858 if (anAspMarker.MarkerType == Aspect_TOM_USERDEFINED)
860 theAspMarker->SetMarkerImage (ContextMarker.MarkerImage);
863 const CALL_DEF_CONTEXTFILLAREA& anAspFill = ContextFillArea.IsSet ? ContextFillArea : myStructure->CStructure()->ContextFillArea;
865 theAspFill->SetInteriorStyle (Aspect_InteriorStyle (anAspFill.Style));
866 aColor.SetValues (Standard_Real (anAspFill.IntColor.r),
867 Standard_Real (anAspFill.IntColor.g),
868 Standard_Real (anAspFill.IntColor.b), Quantity_TOC_RGB);
869 theAspFill->SetInteriorColor (aColor);
872 aColor.SetValues (Standard_Real (anAspFill.EdgeColor.r),
873 Standard_Real (anAspFill.EdgeColor.g),
874 Standard_Real (anAspFill.EdgeColor.b), Quantity_TOC_RGB);
875 theAspFill->SetEdgeColor (aColor);
876 theAspFill->SetEdgeLineType (Aspect_TypeOfLine (anAspFill.LineType));
877 theAspFill->SetEdgeWidth (Standard_Real (anAspFill.Width));
880 aBack.SetShininess (Standard_Real (anAspFill.Back.Shininess));
881 aBack.SetAmbient (Standard_Real (anAspFill.Back.Ambient));
882 aBack.SetDiffuse (Standard_Real (anAspFill.Back.Diffuse));
883 aBack.SetSpecular (Standard_Real (anAspFill.Back.Specular));
884 aBack.SetTransparency (Standard_Real (anAspFill.Back.Transparency));
885 aBack.SetEmissive (Standard_Real (anAspFill.Back.Emission));
886 anAspFill.Back.IsAmbient == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_AMBIENT) : aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
887 anAspFill.Back.IsDiffuse == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE) : aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
888 anAspFill.Back.IsSpecular == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_SPECULAR) : aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
889 anAspFill.Back.IsEmission == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_EMISSION) : aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
891 aColor.SetValues (Standard_Real (anAspFill.Back.ColorSpec.r),
892 Standard_Real (anAspFill.Back.ColorSpec.g),
893 Standard_Real (anAspFill.Back.ColorSpec.b), Quantity_TOC_RGB);
894 aBack.SetSpecularColor (aColor);
896 aColor.SetValues (Standard_Real (anAspFill.Back.ColorAmb.r),
897 Standard_Real (anAspFill.Back.ColorAmb.g),
898 Standard_Real (anAspFill.Back.ColorAmb.b), Quantity_TOC_RGB);
899 aBack.SetAmbientColor (aColor);
901 aColor.SetValues (Standard_Real (anAspFill.Back.ColorDif.r),
902 Standard_Real (anAspFill.Back.ColorDif.g),
903 Standard_Real (anAspFill.Back.ColorDif.b), Quantity_TOC_RGB);
904 aBack.SetDiffuseColor (aColor);
906 aColor.SetValues (Standard_Real (anAspFill.Back.ColorEms.r),
907 Standard_Real (anAspFill.Back.ColorEms.g),
908 Standard_Real (anAspFill.Back.ColorEms.b), Quantity_TOC_RGB);
909 aBack.SetEmissiveColor (aColor);
911 aBack.SetEnvReflexion (anAspFill.Back.EnvReflexion);
914 aFront.SetShininess (Standard_Real (anAspFill.Front.Shininess));
915 aFront.SetAmbient (Standard_Real (anAspFill.Front.Ambient));
916 aFront.SetDiffuse (Standard_Real (anAspFill.Front.Diffuse));
917 aFront.SetSpecular (Standard_Real (anAspFill.Front.Specular));
918 aFront.SetTransparency (Standard_Real (anAspFill.Front.Transparency));
919 aFront.SetEmissive (Standard_Real (anAspFill.Back.Emission));
920 anAspFill.Front.IsAmbient == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_AMBIENT) : aFront.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
921 anAspFill.Front.IsDiffuse == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE) : aFront.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
922 anAspFill.Front.IsSpecular == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_SPECULAR) : aFront.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
923 anAspFill.Front.IsEmission == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_EMISSION) : aFront.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
925 aColor.SetValues (Standard_Real (anAspFill.Front.ColorSpec.r),
926 Standard_Real (anAspFill.Front.ColorSpec.g),
927 Standard_Real (anAspFill.Front.ColorSpec.b), Quantity_TOC_RGB);
928 aFront.SetSpecularColor (aColor);
930 aColor.SetValues (Standard_Real (anAspFill.Front.ColorAmb.r),
931 Standard_Real (anAspFill.Front.ColorAmb.g),
932 Standard_Real (anAspFill.Front.ColorAmb.b), Quantity_TOC_RGB);
933 aFront.SetAmbientColor (aColor);
935 aColor.SetValues (Standard_Real (anAspFill.Front.ColorDif.r),
936 Standard_Real (anAspFill.Front.ColorDif.g),
937 Standard_Real (anAspFill.Front.ColorDif.b), Quantity_TOC_RGB);
938 aFront.SetDiffuseColor (aColor);
940 aColor.SetValues (Standard_Real (anAspFill.Front.ColorEms.r),
941 Standard_Real (anAspFill.Front.ColorEms.g),
942 Standard_Real (anAspFill.Front.ColorEms.b), Quantity_TOC_RGB);
943 aFront.SetEmissiveColor (aColor);
945 aFront.SetEnvReflexion (anAspFill.Front.EnvReflexion);
948 anAspFill.Edge == 1 ? theAspFill->SetEdgeOn() : theAspFill->SetEdgeOff();
950 theAspFill->SetHatchStyle (Aspect_HatchStyle (anAspFill.Hatch));
952 // Front and Back face
953 anAspFill.Distinguish == 1 ? theAspFill->SetDistinguishOn() : theAspFill->SetDistinguishOff();
954 anAspFill.BackFace == 1 ? theAspFill->SuppressBackFace() : theAspFill->AllowBackFace();
956 theAspFill->SetTextureMap (anAspFill.Texture.TextureMap);
957 anAspFill.Texture.doTextureMap == 1 ? theAspFill->SetTextureMapOn() : theAspFill->SetTextureMapOff();
958 theAspFill->SetShaderProgram (anAspFill.ShaderProgram);
959 theAspFill->SetPolygonOffsets (anAspFill.PolygonOffsetMode,
960 anAspFill.PolygonOffsetFactor,
961 anAspFill.PolygonOffsetUnits);
962 theAspFill->SetBackMaterial (aBack);
963 theAspFill->SetFrontMaterial (aFront);
966 // =======================================================================
967 // function : PrimitivesAspect
969 // =======================================================================
970 void Graphic3d_Group::PrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine,
971 const Handle(Graphic3d_AspectText3d)& theAspText,
972 const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
973 const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
975 GroupPrimitivesAspect (theAspLine, theAspText, theAspMarker, theAspFill);
978 // =======================================================================
979 // function : AddPrimitiveArray
981 // =======================================================================
982 void Graphic3d_Group::AddPrimitiveArray (const Handle(Graphic3d_ArrayOfPrimitives)& thePrim,
983 const Standard_Boolean theToEvalMinMax)
986 || !thePrim->IsValid())
992 && thePrim->Type() != Graphic3d_TOPA_POLYLINES
993 && thePrim->Type() != Graphic3d_TOPA_SEGMENTS
994 && thePrim->Type() != Graphic3d_TOPA_POINTS)
996 myStructure->GroupsWithFacet (1);
997 MyContainsFacet = Standard_True;
1000 MyIsEmpty = Standard_False;
1001 myListOfPArray.Append (thePrim);
1002 if (theToEvalMinMax)
1004 Standard_Real x, y, z;
1005 const Standard_Integer aNbVerts = thePrim->VertexNumber();
1006 for (Standard_Integer aVertIter = 1; aVertIter <= aNbVerts; ++aVertIter)
1008 thePrim->Vertice (aVertIter, x, y, z);
1009 if (x < myBounds.XMin) myBounds.XMin = Standard_ShortReal (x);
1010 if (y < myBounds.YMin) myBounds.YMin = Standard_ShortReal (y);
1011 if (z < myBounds.ZMin) myBounds.ZMin = Standard_ShortReal (z);
1012 if (x > myBounds.XMax) myBounds.XMax = Standard_ShortReal (x);
1013 if (y > myBounds.YMax) myBounds.YMax = Standard_ShortReal (y);
1014 if (z > myBounds.ZMax) myBounds.ZMax = Standard_ShortReal (z);
1021 // =======================================================================
1022 // function : Marker
1024 // =======================================================================
1025 void Graphic3d_Group::Marker (const Graphic3d_Vertex& thePoint,
1026 const Standard_Boolean theToEvalMinMax)
1028 Handle(Graphic3d_ArrayOfPoints) aPoints = new Graphic3d_ArrayOfPoints (1);
1029 aPoints->AddVertex (thePoint.X(), thePoint.Y(), thePoint.Z());
1030 AddPrimitiveArray (aPoints, theToEvalMinMax);
1033 // =======================================================================
1034 // function : UserDraw
1036 // =======================================================================
1037 void Graphic3d_Group::UserDraw (const Standard_Address /*theObject*/,
1038 const Standard_Boolean /*theToEvalMinMax*/,
1039 const Standard_Boolean theContainsFacet)
1046 // Without this modification, the group assumes the primitive contains
1047 // no polygons and does not require the Z-buffer for display.
1048 if (!MyContainsFacet && theContainsFacet)
1050 myStructure->GroupsWithFacet (1);
1051 MyContainsFacet = Standard_True;
1054 MyIsEmpty = Standard_False;
1058 // =======================================================================
1061 // =======================================================================
1062 void Graphic3d_Group::Text (const Standard_CString /*theText*/,
1063 const Graphic3d_Vertex& thePoint,
1064 const Standard_Real /*theHeight*/,
1065 const Quantity_PlaneAngle /*theAngle*/,
1066 const Graphic3d_TextPath /*theTp*/,
1067 const Graphic3d_HorizontalTextAlignment /*theHta*/,
1068 const Graphic3d_VerticalTextAlignment /*theVta*/,
1069 const Standard_Boolean theToEvalMinMax)
1076 MyIsEmpty = Standard_False;
1077 if (theToEvalMinMax)
1079 Standard_ShortReal x, y, z;
1080 thePoint.Coord (x, y, z);
1081 if (x < myBounds.XMin) myBounds.XMin = x;
1082 if (y < myBounds.YMin) myBounds.YMin = y;
1083 if (z < myBounds.ZMin) myBounds.ZMin = z;
1084 if (x > myBounds.XMax) myBounds.XMax = x;
1085 if (y > myBounds.YMax) myBounds.YMax = y;
1086 if (z > myBounds.ZMax) myBounds.ZMax = z;
1091 // =======================================================================
1094 // =======================================================================
1095 void Graphic3d_Group::Text (const Standard_CString theText,
1096 const Graphic3d_Vertex& thePoint,
1097 const Standard_Real theHeight,
1098 const Standard_Boolean theToEvalMinMax)
1100 Text (theText, thePoint, theHeight, 0.0,
1101 Graphic3d_TP_RIGHT, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM, theToEvalMinMax);
1104 // =======================================================================
1107 // =======================================================================
1108 void Graphic3d_Group::Text (const TCollection_ExtendedString& 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)
1117 const NCollection_String aText ((Standard_Utf16Char* )theText.ToExtString());
1118 Text (aText.ToCString(), thePoint, theHeight, theAngle,
1119 theTp, theHta, theVta, theToEvalMinMax);
1122 // =======================================================================
1125 // =======================================================================
1126 void Graphic3d_Group::Text (const TCollection_ExtendedString& theText,
1127 const Graphic3d_Vertex& thePoint,
1128 const Standard_Real theHeight,
1129 const Standard_Boolean theToEvalMinMax)
1131 const NCollection_String aText ((Standard_Utf16Char* )theText.ToExtString());
1132 Text (aText.ToCString(), thePoint, theHeight, 0.0,
1133 Graphic3d_TP_RIGHT, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM, theToEvalMinMax);