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