0027067: Avoid use of virtual methods for implementation of destructors in legacy...
[occt.git] / src / Graphic3d / Graphic3d_Structure.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 <Aspect_PolygonOffsetMode.hxx>
18 #include <Bnd_Box.hxx>
19 #include <gp_Pnt.hxx>
20 #include <Graphic3d_AspectFillArea3d.hxx>
21 #include <Graphic3d_AspectLine3d.hxx>
22 #include <Graphic3d_AspectMarker3d.hxx>
23 #include <Graphic3d_AspectText3d.hxx>
24 #include <Graphic3d_DataStructureManager.hxx>
25 #include <Graphic3d_GraphicDriver.hxx>
26 #include <Graphic3d_Group.hxx>
27 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
28 #include <Graphic3d_MapOfStructure.hxx>
29 #include <Graphic3d_MaterialAspect.hxx>
30 #include <Graphic3d_PriorityDefinitionError.hxx>
31 #include <Graphic3d_Structure.hxx>
32 #include "Graphic3d_Structure.pxx"
33 #include <Graphic3d_StructureDefinitionError.hxx>
34 #include <Graphic3d_StructureManager.hxx>
35 #include <Graphic3d_TextureMap.hxx>
36 #include <Graphic3d_TransformError.hxx>
37 #include <Graphic3d_Vector.hxx>
38 #include <Quantity_Color.hxx>
39 #include <Standard_Type.hxx>
40 #include <TColStd_Array2OfReal.hxx>
41
42 #include <stdio.h>
43 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Structure,MMgt_TShared)
44
45 //=============================================================================
46 //function : Graphic3d_Structure
47 //purpose  :
48 //=============================================================================
49 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager)
50 : myStructureManager      (theManager.operator->()),
51   myFirstStructureManager (theManager.operator->()),
52   myComputeVisual         (Graphic3d_TOS_ALL),
53   myHighlightColor        (Quantity_NOC_WHITE),
54   myHighlightMethod       (Aspect_TOHM_COLOR),
55   myOwner                 (NULL),
56   myVisual                (Graphic3d_TOS_ALL)
57 {
58   myCStructure = theManager->GraphicDriver()->CreateStructure (theManager);
59
60   // default aspects
61   Handle(Graphic3d_AspectLine3d)     aAspectLine3d     = new Graphic3d_AspectLine3d();
62   Handle(Graphic3d_AspectText3d)     aAspectText3d     = new Graphic3d_AspectText3d();
63   Handle(Graphic3d_AspectMarker3d)   aAspectMarker3d   = new Graphic3d_AspectMarker3d();
64   Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
65   theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
66   aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
67
68   // update the associated CStructure
69   UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
70 }
71
72 //=============================================================================
73 //function : Graphic3d_Structure
74 //purpose  :
75 //=============================================================================
76 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
77                                           const Handle(Graphic3d_Structure)&        thePrs)
78 : myStructureManager      (theManager.operator->()),
79   myFirstStructureManager (theManager.operator->()),
80   myComputeVisual         (thePrs->myComputeVisual),
81   myHighlightColor        (thePrs->myHighlightColor),
82   myHighlightMethod       (thePrs->myHighlightMethod),
83   myOwner                 (thePrs->myOwner),
84   myVisual                (thePrs->myVisual)
85 {
86   myCStructure = thePrs->myCStructure->ShadowLink (theManager);
87
88   // default aspects
89   Handle(Graphic3d_AspectLine3d)     aAspectLine3d     = new Graphic3d_AspectLine3d();
90   Handle(Graphic3d_AspectText3d)     aAspectText3d     = new Graphic3d_AspectText3d();
91   Handle(Graphic3d_AspectMarker3d)   aAspectMarker3d   = new Graphic3d_AspectMarker3d();
92   Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
93   theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
94   aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
95
96   // update the associated CStructure
97   UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
98 }
99
100 //=============================================================================
101 //function : ~Graphic3d_Structure
102 //purpose  :
103 //=============================================================================
104 Graphic3d_Structure::~Graphic3d_Structure()
105 {
106   // as myFirstStructureManager can be already destroyed,
107   // avoid attempts to access it
108   myFirstStructureManager = NULL;
109   Remove();
110 }
111
112 //=============================================================================
113 //function : Clear
114 //purpose  :
115 //=============================================================================
116 void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
117 {
118   if (IsDeleted()) return;
119
120   // clean groups in graphics driver at first
121   GraphicClear (theWithDestruction);
122
123   myCStructure->ContainsFacet = 0;
124   myStructureManager->Clear (this, theWithDestruction);
125
126   Update();
127 }
128
129 //=======================================================================
130 //function : CalculateBoundBox
131 //purpose  : Calculates AABB of a structure.
132 //=======================================================================
133 void Graphic3d_Structure::CalculateBoundBox()
134 {
135   Graphic3d_BndBox4d aBox;
136   addTransformed (aBox, Standard_True);
137   if (aBox.IsValid())
138   {
139     Graphic3d_Vec4 aMinPt (RealToShortReal (aBox.CornerMin().x()),
140                            RealToShortReal (aBox.CornerMin().y()),
141                            RealToShortReal (aBox.CornerMin().z()),
142                            1.0f);
143     Graphic3d_Vec4 aMaxPt (RealToShortReal (aBox.CornerMax().x()),
144                            RealToShortReal (aBox.CornerMax().y()),
145                            RealToShortReal (aBox.CornerMax().z()),
146                            1.0f);
147     myCStructure->ChangeBoundingBox() = Graphic3d_BndBox4f (aMinPt, aMaxPt);
148   }
149   else
150   {
151     myCStructure->ChangeBoundingBox().Clear();
152   }
153 }
154
155 //=============================================================================
156 //function : Remove
157 //purpose  :
158 //=============================================================================
159 void Graphic3d_Structure::Remove()
160 {
161   if (IsDeleted()) return;
162
163   // clean groups in graphics driver at first; this is also should be done
164   // to avoid unwanted group cleaning in group's destructor
165   // Pass Standard_False to Clear(..) method to avoid updating in
166   // structure manager, it isn't necessary, besides of it structure manager
167   // could be already destroyed and invalid pointers used in structure;
168   for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
169   {
170     aGroupIter.ChangeValue()->Clear (Standard_False);
171   }
172
173   Standard_Address APtr = (void *) this;
174   // It is necessary to remove the eventual pointer on the structure
175   // that can be destroyed, in the list of descendants
176   // of ancestors of this structure and in the list of ancestors
177   // of descendants of the same structure.
178
179   for (Standard_Integer aStructIdx = 1, aNbDesc = myDescendants.Size(); aStructIdx <= aNbDesc; ++aStructIdx)
180   {
181     ((Graphic3d_Structure *)myDescendants.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
182   }
183
184   for (Standard_Integer aStructIdx = 1, aNbAnces = myAncestors.Size(); aStructIdx <= aNbAnces; ++aStructIdx)
185   {
186     ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
187   }
188
189   // Destruction of me in the graphic library
190   const Standard_Integer aStructId = myCStructure->Id;
191   myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
192   myCStructure.Nullify();
193
194   // Liberation of the identification if the destroyed structure
195   // in the first manager that performs creation of the structure.
196   if (myFirstStructureManager != NULL)
197   {
198     myFirstStructureManager->Remove (aStructId);
199   }
200 }
201
202 //=============================================================================
203 //function : Display
204 //purpose  :
205 //=============================================================================
206 void Graphic3d_Structure::Display()
207 {
208   if (IsDeleted()) return;
209
210   if (!myCStructure->stick)
211   {
212     myCStructure->stick = 1;
213     myStructureManager->Display (this);
214   }
215
216   if (myCStructure->visible != 1)
217   {
218     myCStructure->visible = 1;
219     myCStructure->OnVisibilityChanged();
220   }
221 }
222
223 //=============================================================================
224 //function : SetIsForHighlight
225 //purpose  :
226 //=============================================================================
227 void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight)
228 {
229   myCStructure->IsForHighlight = isForHighlight;
230 }
231
232 //=============================================================================
233 //function : SetDisplayPriority
234 //purpose  :
235 //=============================================================================
236 void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
237 {
238   if (IsDeleted()
239    || thePriority == myCStructure->Priority)
240   {
241     return;
242   }
243
244   myCStructure->PreviousPriority = myCStructure->Priority;
245   myCStructure->Priority         = thePriority;
246
247   if (myCStructure->Priority != myCStructure->PreviousPriority)
248   {
249     Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
250                                              || (myCStructure->Priority < Structure_MIN_PRIORITY),
251                                                 "Bad value for StructurePriority");
252     if (myCStructure->stick)
253     {
254       myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
255     }
256   }
257 }
258
259 //=============================================================================
260 //function : ResetDisplayPriority
261 //purpose  :
262 //=============================================================================
263 void Graphic3d_Structure::ResetDisplayPriority()
264 {
265   if (IsDeleted()
266    || myCStructure->Priority == myCStructure->PreviousPriority)
267   {
268     return;
269   }
270
271   const Standard_Integer aPriority = myCStructure->Priority;
272   myCStructure->Priority = myCStructure->PreviousPriority;
273   if (myCStructure->stick)
274   {
275     myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
276   }
277 }
278
279 //=============================================================================
280 //function : DisplayPriority
281 //purpose  :
282 //=============================================================================
283 Standard_Integer Graphic3d_Structure::DisplayPriority() const
284 {
285   return myCStructure->Priority;
286 }
287
288 //=============================================================================
289 //function : Erase
290 //purpose  :
291 //=============================================================================
292 void Graphic3d_Structure::Erase()
293 {
294   if (IsDeleted())
295   {
296     return;
297   }
298
299   if (myCStructure->stick)
300   {
301     myCStructure->stick = 0;
302     myStructureManager->Erase (this);
303   }
304 }
305
306 //=============================================================================
307 //function : Highlight
308 //purpose  :
309 //=============================================================================
310 void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod theMethod,
311                                      const Quantity_Color&              theColor,
312                                      const Standard_Boolean             theToUpdateMgr)
313 {
314   if (IsDeleted())
315   {
316     return;
317   }
318
319   myHighlightColor = theColor;
320
321   // Highlight on already Highlighted structure.
322   if (myCStructure->highlight)
323   {
324     Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
325     if (anUpdateMode == Aspect_TOU_WAIT)
326     {
327       UnHighlight();
328     }
329     else
330     {
331       // To avoid call of method : Update()
332       // Not useful and can be costly.
333       myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
334       UnHighlight();
335       myStructureManager->SetUpdateMode (anUpdateMode);
336     }
337   }
338
339   SetDisplayPriority (Structure_MAX_PRIORITY - 1);
340
341   GraphicHighlight (theMethod);
342
343   if (!theToUpdateMgr)
344   {
345     return;
346   }
347
348   if (myCStructure->stick)
349   {
350     myStructureManager->Highlight (this, theMethod);
351   }
352
353   Update();
354 }
355
356 //=============================================================================
357 //function : SetVisible
358 //purpose  :
359 //=============================================================================
360 void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
361 {
362   if (IsDeleted()) return;
363
364   const unsigned isVisible = theValue ? 1 : 0;
365   if (myCStructure->visible == isVisible)
366   {
367     return;
368   }
369
370   myCStructure->visible = isVisible;
371   myCStructure->OnVisibilityChanged();
372   Update();
373 }
374
375 //=============================================================================
376 //function : UnHighlight
377 //purpose  :
378 //=============================================================================
379 void Graphic3d_Structure::UnHighlight()
380 {
381   if (IsDeleted()) return;
382
383   if (myCStructure->highlight)
384   {
385     myCStructure->highlight = 0;
386
387     GraphicUnHighlight();
388     myStructureManager->UnHighlight (this);
389
390     ResetDisplayPriority();
391     Update();
392   }
393 }
394
395 //=============================================================================
396 //function : HighlightColor
397 //purpose  :
398 //=============================================================================
399 const Quantity_Color& Graphic3d_Structure::HighlightColor() const
400 {
401   return myHighlightColor;
402 }
403
404 //=============================================================================
405 //function : IsDisplayed
406 //purpose  :
407 //=============================================================================
408 Standard_Boolean Graphic3d_Structure::IsDisplayed() const
409 {
410   return myCStructure->stick ? Standard_True : Standard_False;
411 }
412
413 //=============================================================================
414 //function : IsDeleted
415 //purpose  :
416 //=============================================================================
417 Standard_Boolean Graphic3d_Structure::IsDeleted() const
418 {
419   return myCStructure.IsNull();
420 }
421
422 //=============================================================================
423 //function : IsHighlighted
424 //purpose  :
425 //=============================================================================
426 Standard_Boolean Graphic3d_Structure::IsHighlighted() const
427 {
428   return myCStructure->highlight ? Standard_True : Standard_False;
429 }
430
431 //=============================================================================
432 //function : IsVisible
433 //purpose  :
434 //=============================================================================
435 Standard_Boolean Graphic3d_Structure::IsVisible() const
436 {
437   return myCStructure->visible ? Standard_True : Standard_False;
438 }
439
440 //=============================================================================
441 //function : IsTransformed
442 //purpose  :
443 //=============================================================================
444 Standard_Boolean Graphic3d_Structure::IsTransformed() const
445 {
446   return !myCStructure->Transformation.IsIdentity();
447 }
448
449 //=============================================================================
450 //function : ContainsFacet
451 //purpose  :
452 //=============================================================================
453 Standard_Boolean Graphic3d_Structure::ContainsFacet() const
454 {
455   if (IsDeleted())
456   {
457     return Standard_False;
458   }
459   else if (myCStructure->ContainsFacet > 0)
460   {
461     // if one of groups contains at least one facet, the structure contains it too
462     return Standard_True;
463   }
464
465   // stop at the first descendant containing at least one facet
466   for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
467   {
468     if (((const Graphic3d_Structure *)anIter.Value())->ContainsFacet())
469     {
470       return Standard_True;
471     }
472   }
473   return Standard_False;
474 }
475
476 //=============================================================================
477 //function : IsEmpty
478 //purpose  :
479 //=============================================================================
480 Standard_Boolean Graphic3d_Structure::IsEmpty() const
481 {
482   if (IsDeleted())
483   {
484     return Standard_True;
485   }
486
487   // structure is empty:
488   // - if all these groups are empty
489   // - or if all groups are empty and all their descendants are empty
490   // - or if all its descendants are empty
491   for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
492   {
493     if (!aGroupIter.Value()->IsEmpty())
494     {
495       return Standard_False;
496     }
497   }
498
499   // stop at the first non-empty descendant
500   for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
501   {
502     if (!((const Graphic3d_Structure* )anIter.Value())->IsEmpty())
503     {
504       return Standard_False;
505     }
506   }
507   return Standard_True;
508 }
509
510 //=============================================================================
511 //function : PrimitivesAspect
512 //purpose  :
513 //=============================================================================
514 void Graphic3d_Structure::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)&     theAspLine,
515                                             Handle(Graphic3d_AspectText3d)&     theAspText,
516                                             Handle(Graphic3d_AspectMarker3d)&   theAspMarker,
517                                             Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
518 {
519   theAspLine   = Line3dAspect();
520   theAspText   = Text3dAspect();
521   theAspMarker = Marker3dAspect();
522   theAspFill   = FillArea3dAspect();
523 }
524
525 //=============================================================================
526 //function : GroupsWithFacet
527 //purpose  :
528 //=============================================================================
529 void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
530 {
531   myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
532   if (myCStructure->ContainsFacet < 0)
533   {
534     myCStructure->ContainsFacet = 0;
535   }
536 }
537
538 //=============================================================================
539 //function : Compute
540 //purpose  :
541 //=============================================================================
542 void Graphic3d_Structure::Compute()
543 {
544   // Implemented by Presentation
545 }
546
547 //=============================================================================
548 //function : Compute
549 //purpose  :
550 //=============================================================================
551 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
552 {
553   // Implemented by Presentation
554   return this;
555 }
556
557 //=============================================================================
558 //function : Compute
559 //purpose  :
560 //=============================================================================
561 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
562                                                           const TColStd_Array2OfReal& )
563 {
564   // Implemented by Presentation
565   return this;
566 }
567
568 //=============================================================================
569 //function : Compute
570 //purpose  :
571 //=============================================================================
572 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
573                                    Handle(Graphic3d_Structure)& )
574 {
575   // Implemented by Presentation
576 }
577
578 //=============================================================================
579 //function : Compute
580 //purpose  :
581 //=============================================================================
582 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
583                                    const TColStd_Array2OfReal& ,
584                                    Handle(Graphic3d_Structure)& )
585 {
586   // Implemented by Presentation
587 }
588
589 //=============================================================================
590 //function : ReCompute
591 //purpose  :
592 //=============================================================================
593 void Graphic3d_Structure::ReCompute()
594 {
595   myStructureManager->ReCompute (this);
596 }
597
598 //=============================================================================
599 //function : ReCompute
600 //purpose  :
601 //=============================================================================
602 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
603 {
604   myStructureManager->ReCompute (this, theProjector);
605 }
606
607 //=============================================================================
608 //function : SetInfiniteState
609 //purpose  :
610 //=============================================================================
611 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
612 {
613   myCStructure->IsInfinite = theToSet ? 1 : 0;
614 }
615
616 //=============================================================================
617 //function : IsInfinite
618 //purpose  :
619 //=============================================================================
620 Standard_Boolean Graphic3d_Structure::IsInfinite() const
621 {
622   return IsDeleted()
623        || myCStructure->IsInfinite;
624 }
625
626 //=============================================================================
627 //function : GraphicClear
628 //purpose  :
629 //=============================================================================
630 void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
631 {
632   if (myCStructure.IsNull())
633   {
634     return;
635   }
636
637   // clean and empty each group
638   for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
639   {
640     aGroupIter.ChangeValue()->Clear();
641   }
642   if (!theWithDestruction)
643   {
644     return;
645   }
646
647   while (!myCStructure->Groups().IsEmpty())
648   {
649     Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
650     aGroup->Remove();
651   }
652   myCStructure->Clear();
653 }
654
655 //=============================================================================
656 //function : GraphicConnect
657 //purpose  :
658 //=============================================================================
659 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
660 {
661   myCStructure->Connect (*theDaughter->myCStructure);
662 }
663
664 //=============================================================================
665 //function : GraphicDisconnect
666 //purpose  :
667 //=============================================================================
668 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
669 {
670   myCStructure->Disconnect (*theDaughter->myCStructure);
671 }
672
673 //=============================================================================
674 //function : Line3dAspect
675 //purpose  :
676 //=============================================================================
677 Handle(Graphic3d_AspectLine3d) Graphic3d_Structure::Line3dAspect() const
678 {
679   const Standard_Real anRGB[3] =
680   {
681     Standard_Real (myCStructure->ContextLine.Color.r),
682     Standard_Real (myCStructure->ContextLine.Color.g),
683     Standard_Real (myCStructure->ContextLine.Color.b)
684   };
685   Quantity_Color aColor;
686   aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
687   Aspect_TypeOfLine aLType = Aspect_TypeOfLine (myCStructure->ContextLine.LineType);
688   Standard_Real     aWidth = Standard_Real     (myCStructure->ContextLine.Width);
689
690   Handle(Graphic3d_AspectLine3d) anAspLine = new Graphic3d_AspectLine3d (aColor, aLType, aWidth);
691   anAspLine->SetShaderProgram (myCStructure->ContextLine.ShaderProgram);
692   return anAspLine;
693 }
694
695 //=============================================================================
696 //function : Text3dAspect
697 //purpose  :
698 //=============================================================================
699 Handle(Graphic3d_AspectText3d) Graphic3d_Structure::Text3dAspect() const
700 {
701   const Standard_Real anRGB[3] =
702   {
703     Standard_Real (myCStructure->ContextText.Color.r),
704     Standard_Real (myCStructure->ContextText.Color.g),
705     Standard_Real (myCStructure->ContextText.Color.b)
706   };
707   Quantity_Color aColor;
708   aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
709   Standard_CString         aFont       = Standard_CString         (myCStructure->ContextText.Font);
710   Standard_Real            anExpansion = Standard_Real            (myCStructure->ContextText.Expan);
711   Standard_Real            aSpace      = Standard_Real            (myCStructure->ContextText.Space);
712   Aspect_TypeOfStyleText   aStyle      = Aspect_TypeOfStyleText   (myCStructure->ContextText.Style);
713   Aspect_TypeOfDisplayText aDispType   = Aspect_TypeOfDisplayText (myCStructure->ContextText.DisplayType);
714
715   Handle(Graphic3d_AspectText3d) anAspText = new Graphic3d_AspectText3d (aColor, aFont, anExpansion, aSpace, aStyle, aDispType);
716   anAspText->SetShaderProgram (myCStructure->ContextText.ShaderProgram);
717   return anAspText;
718 }
719
720 //=============================================================================
721 //function : Marker3dAspect
722 //purpose  :
723 //=============================================================================
724 Handle(Graphic3d_AspectMarker3d) Graphic3d_Structure::Marker3dAspect() const
725 {
726   const Standard_Real anRGB[3] =
727   {
728     Standard_Real (myCStructure->ContextMarker.Color.r),
729     Standard_Real (myCStructure->ContextMarker.Color.g),
730     Standard_Real (myCStructure->ContextMarker.Color.b)
731   };
732   Quantity_Color aColor;
733   aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
734   Aspect_TypeOfMarker aMType = myCStructure->ContextMarker.MarkerType;
735   Standard_Real       aScale = Standard_Real (myCStructure->ContextMarker.Scale);
736
737   Handle(Graphic3d_AspectMarker3d) anAspMarker = new Graphic3d_AspectMarker3d (aMType, aColor, aScale);
738   anAspMarker->SetShaderProgram (myCStructure->ContextMarker.ShaderProgram);
739   return anAspMarker;
740 }
741
742 //=============================================================================
743 //function : FillArea3dAspect
744 //purpose  :
745 //=============================================================================
746 Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect() const
747 {
748   // Back Material
749   Graphic3d_MaterialAspect aBack;
750   aBack.SetShininess    (Standard_Real (myCStructure->ContextFillArea.Back.Shininess));
751   aBack.SetAmbient      (Standard_Real (myCStructure->ContextFillArea.Back.Ambient));
752   aBack.SetDiffuse      (Standard_Real (myCStructure->ContextFillArea.Back.Diffuse));
753   aBack.SetSpecular     (Standard_Real (myCStructure->ContextFillArea.Back.Specular));
754   aBack.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Back.Transparency));
755   aBack.SetEmissive     (Standard_Real (myCStructure->ContextFillArea.Back.Emission));
756   if (myCStructure->ContextFillArea.Back.IsAmbient == 1)
757     aBack.SetReflectionModeOn  (Graphic3d_TOR_AMBIENT);
758   else
759     aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
760   if (myCStructure->ContextFillArea.Back.IsDiffuse == 1)
761     aBack.SetReflectionModeOn  (Graphic3d_TOR_DIFFUSE);
762   else
763     aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
764   if (myCStructure->ContextFillArea.Back.IsSpecular == 1)
765     aBack.SetReflectionModeOn  (Graphic3d_TOR_SPECULAR);
766   else
767     aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
768   if (myCStructure->ContextFillArea.Back.IsEmission == 1)
769     aBack.SetReflectionModeOn  (Graphic3d_TOR_EMISSION);
770   else
771     aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
772
773   Quantity_Color aColor (Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.r),
774                          Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.g),
775                          Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.b), Quantity_TOC_RGB);
776   aBack.SetSpecularColor (aColor);
777
778   aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.r),
779                     Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.g),
780                     Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.b), Quantity_TOC_RGB);
781   aBack.SetAmbientColor (aColor);
782
783   aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.r),
784                     Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.g),
785                     Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.b), Quantity_TOC_RGB);
786   aBack.SetDiffuseColor (aColor);
787
788   aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.r),
789                     Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.g),
790                     Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.b), Quantity_TOC_RGB);
791   aBack.SetEmissiveColor (aColor);
792
793   aBack.SetEnvReflexion (myCStructure->ContextFillArea.Back.EnvReflexion);
794   aBack.SetMaterialType (myCStructure->ContextFillArea.Back.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
795
796   aBack.SetRefractionIndex (Standard_Real (myCStructure->ContextFillArea.Back.RefractionIndex));
797   aBack.SetBSDF (myCStructure->ContextFillArea.Back.BSDF);
798
799   // Front Material
800   Graphic3d_MaterialAspect aFront;
801   aFront.SetShininess    (Standard_Real (myCStructure->ContextFillArea.Front.Shininess));
802   aFront.SetAmbient      (Standard_Real (myCStructure->ContextFillArea.Front.Ambient));
803   aFront.SetDiffuse      (Standard_Real (myCStructure->ContextFillArea.Front.Diffuse));
804   aFront.SetSpecular     (Standard_Real (myCStructure->ContextFillArea.Front.Specular));
805   aFront.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Front.Transparency));
806   aFront.SetEmissive     (Standard_Real (myCStructure->ContextFillArea.Front.Emission));
807   if (myCStructure->ContextFillArea.Front.IsAmbient == 1)
808     aFront.SetReflectionModeOn  (Graphic3d_TOR_AMBIENT);
809   else
810     aFront.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
811   if (myCStructure->ContextFillArea.Front.IsDiffuse == 1)
812     aFront.SetReflectionModeOn  (Graphic3d_TOR_DIFFUSE);
813   else
814     aFront.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
815   if (myCStructure->ContextFillArea.Front.IsSpecular == 1)
816     aFront.SetReflectionModeOn  (Graphic3d_TOR_SPECULAR);
817   else
818     aFront.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
819   if (myCStructure->ContextFillArea.Front.Emission == 1)
820     aFront.SetReflectionModeOn  (Graphic3d_TOR_EMISSION);
821   else
822     aFront.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
823
824   aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.r),
825                     Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.g),
826                     Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.b), Quantity_TOC_RGB);
827   aFront.SetSpecularColor (aColor);
828
829   aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.r),
830                     Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.g),
831                     Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.b), Quantity_TOC_RGB);
832   aFront.SetAmbientColor (aColor);
833
834   aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.r),
835                     Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.g),
836                     Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.b), Quantity_TOC_RGB);
837   aFront.SetDiffuseColor (aColor);
838
839   aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.r),
840                     Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.g),
841                     Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.b), Quantity_TOC_RGB);
842   aFront.SetEmissiveColor (aColor);
843
844   aFront.SetEnvReflexion (myCStructure->ContextFillArea.Front.EnvReflexion);
845   aFront.SetMaterialType (myCStructure->ContextFillArea.Front.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
846
847   aFront.SetRefractionIndex (Standard_Real (myCStructure->ContextFillArea.Front.RefractionIndex));
848   aFront.SetBSDF (myCStructure->ContextFillArea.Front.BSDF);
849
850   Quantity_Color anIntColor  (Standard_Real (myCStructure->ContextFillArea.IntColor.r),
851                               Standard_Real (myCStructure->ContextFillArea.IntColor.g),
852                               Standard_Real (myCStructure->ContextFillArea.IntColor.b), Quantity_TOC_RGB);
853   Quantity_Color anEdgeColor (Standard_Real (myCStructure->ContextFillArea.EdgeColor.r),
854                               Standard_Real (myCStructure->ContextFillArea.EdgeColor.g),
855                               Standard_Real (myCStructure->ContextFillArea.EdgeColor.b), Quantity_TOC_RGB);
856   Handle(Graphic3d_AspectFillArea3d) anAspFill = new Graphic3d_AspectFillArea3d (Aspect_InteriorStyle (myCStructure->ContextFillArea.Style),
857                                                                                  anIntColor, anEdgeColor,
858                                                                                  Aspect_TypeOfLine    (myCStructure->ContextFillArea.LineType),
859                                                                                  Standard_Real        (myCStructure->ContextFillArea.Width),
860                                                                                  aFront, aBack);
861
862   // Edges
863   if (myCStructure->ContextFillArea.Edge == 1)
864     anAspFill->SetEdgeOn();
865   else
866     anAspFill->SetEdgeOff();
867   // Hatch
868   anAspFill->SetHatchStyle (Aspect_HatchStyle (myCStructure->ContextFillArea.Hatch));
869   // Materials
870   // Front and Back face
871   if (myCStructure->ContextFillArea.Distinguish == 1)
872     anAspFill->SetDistinguishOn();
873   else
874     anAspFill->SetDistinguishOff();
875   if (myCStructure->ContextFillArea.BackFace == 1)
876     anAspFill->SuppressBackFace();
877   else
878     anAspFill->AllowBackFace();
879   // Texture
880   anAspFill->SetTextureMap (myCStructure->ContextFillArea.Texture.TextureMap);
881   if (myCStructure->ContextFillArea.Texture.doTextureMap == 1)
882   {
883     anAspFill->SetTextureMapOn();
884   }
885   else
886   {
887     anAspFill->SetTextureMapOff();
888   }
889   anAspFill->SetShaderProgram  (myCStructure->ContextFillArea.ShaderProgram);
890   anAspFill->SetPolygonOffsets (myCStructure->ContextFillArea.PolygonOffsetMode,
891                                 myCStructure->ContextFillArea.PolygonOffsetFactor,
892                                 myCStructure->ContextFillArea.PolygonOffsetUnits);
893   return anAspFill;
894 }
895
896 //=============================================================================
897 //function : Groups
898 //purpose  :
899 //=============================================================================
900 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
901 {
902   return myCStructure->Groups();
903 }
904
905 //=============================================================================
906 //function : NumberOfGroups
907 //purpose  :
908 //=============================================================================
909 Standard_Integer Graphic3d_Structure::NumberOfGroups() const
910 {
911   return myCStructure->Groups().Length();
912 }
913
914 //=============================================================================
915 //function : SetPrimitivesAspect
916 //purpose  :
917 //=============================================================================
918 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
919 {
920   if (IsDeleted()) return;
921
922   Standard_Real     aWidth;
923   Quantity_Color    aColor;
924   Aspect_TypeOfLine aLType;
925   theAspLine->Values (aColor, aLType, aWidth);
926
927   myCStructure->ContextLine.Color.r        = float (aColor.Red());
928   myCStructure->ContextLine.Color.g        = float (aColor.Green());
929   myCStructure->ContextLine.Color.b        = float (aColor.Blue());
930   myCStructure->ContextLine.LineType       = int   (aLType);
931   myCStructure->ContextLine.Width          = float (aWidth);
932   myCStructure->ContextLine.ShaderProgram  = theAspLine->ShaderProgram();
933   myCStructure->ContextLine.IsDef          = 1;
934
935   myCStructure->UpdateAspects();
936
937   // Attributes are "IsSet" during the first update of context (line, marker...)
938   myCStructure->ContextLine.IsSet     = 1;
939   myCStructure->ContextFillArea.IsSet = 1;
940   myCStructure->ContextMarker.IsSet   = 1;
941   myCStructure->ContextText.IsSet     = 1;
942
943   Update();
944 }
945
946 //=============================================================================
947 //function : SetPrimitivesAspect
948 //purpose  :
949 //=============================================================================
950 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
951 {
952   if (IsDeleted()) return;
953
954   Standard_Real        anRGB[3];
955   Standard_Real        aWidth;
956   Quantity_Color       anIntColor;
957   Quantity_Color       aBackIntColor;
958   Quantity_Color       anEdgeColor;
959   Aspect_TypeOfLine    aLType;
960   Aspect_InteriorStyle aStyle;
961   theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
962
963   anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
964   myCStructure->ContextFillArea.Style      = aStyle;
965   myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
966   myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
967   myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
968
969   if (theAspFill->Distinguish())
970   {
971     aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
972   }
973   myCStructure->ContextFillArea.BackIntColor.r = float(anRGB[0]);
974   myCStructure->ContextFillArea.BackIntColor.g = float(anRGB[1]);
975   myCStructure->ContextFillArea.BackIntColor.b = float(anRGB[2]);
976
977   // Edges
978   myCStructure->ContextFillArea.Edge        = theAspFill->Edge () ? 1 : 0;
979   myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
980   myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
981   myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
982   myCStructure->ContextFillArea.LineType    = aLType;
983   myCStructure->ContextFillArea.Width       = float (aWidth);
984   myCStructure->ContextFillArea.Hatch       = theAspFill->HatchStyle();
985
986   // Front and Back face
987   myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
988   myCStructure->ContextFillArea.BackFace    = theAspFill->BackFace()    ? 1 : 0;
989
990   // Back Material
991   const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
992   // Light specificity
993   myCStructure->ContextFillArea.Back.Shininess       = float (aBack.Shininess());
994   myCStructure->ContextFillArea.Back.Ambient         = float (aBack.Ambient());
995   myCStructure->ContextFillArea.Back.Diffuse         = float (aBack.Diffuse());
996   myCStructure->ContextFillArea.Back.Specular        = float (aBack.Specular());
997   myCStructure->ContextFillArea.Back.Transparency    = float (aBack.Transparency());
998   myCStructure->ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
999   myCStructure->ContextFillArea.Back.BSDF            = aBack.BSDF();
1000   myCStructure->ContextFillArea.Back.Emission        = float (aBack.Emissive());
1001
1002   // Reflection mode
1003   myCStructure->ContextFillArea.Back.IsAmbient    = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT)  ? 1 : 0);
1004   myCStructure->ContextFillArea.Back.IsDiffuse    = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE)  ? 1 : 0);
1005   myCStructure->ContextFillArea.Back.IsSpecular   = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1006   myCStructure->ContextFillArea.Back.IsEmission   = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1007
1008   // Material type
1009   //JR/Hp
1010   myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0 );
1011
1012   // Specular Color
1013   myCStructure->ContextFillArea.Back.ColorSpec.r  = float (aBack.SpecularColor().Red());
1014   myCStructure->ContextFillArea.Back.ColorSpec.g  = float (aBack.SpecularColor().Green());
1015   myCStructure->ContextFillArea.Back.ColorSpec.b  = float (aBack.SpecularColor().Blue());
1016
1017   // Ambient color
1018   myCStructure->ContextFillArea.Back.ColorAmb.r   = float (aBack.AmbientColor().Red());
1019   myCStructure->ContextFillArea.Back.ColorAmb.g   = float (aBack.AmbientColor().Green());
1020   myCStructure->ContextFillArea.Back.ColorAmb.b   = float (aBack.AmbientColor().Blue());
1021
1022   // Diffuse color
1023   myCStructure->ContextFillArea.Back.ColorDif.r   = float (aBack.DiffuseColor().Red());
1024   myCStructure->ContextFillArea.Back.ColorDif.g   = float (aBack.DiffuseColor().Green());
1025   myCStructure->ContextFillArea.Back.ColorDif.b   = float (aBack.DiffuseColor().Blue());
1026
1027   // Emissive color
1028   myCStructure->ContextFillArea.Back.ColorEms.r   = float (aBack.EmissiveColor().Red());
1029   myCStructure->ContextFillArea.Back.ColorEms.g   = float (aBack.EmissiveColor().Green());
1030   myCStructure->ContextFillArea.Back.ColorEms.b   = float (aBack.EmissiveColor().Blue());
1031
1032   myCStructure->ContextFillArea.Back.EnvReflexion =
1033     float ((theAspFill->BackMaterial ()).EnvReflexion());
1034
1035   // Front Material
1036   const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
1037   // Light specificity
1038   myCStructure->ContextFillArea.Front.Shininess       = float (aFront.Shininess());
1039   myCStructure->ContextFillArea.Front.Ambient         = float (aFront.Ambient());
1040   myCStructure->ContextFillArea.Front.Diffuse         = float (aFront.Diffuse());
1041   myCStructure->ContextFillArea.Front.Specular        = float (aFront.Specular());
1042   myCStructure->ContextFillArea.Front.Transparency    = float (aFront.Transparency());
1043   myCStructure->ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
1044   myCStructure->ContextFillArea.Front.BSDF            = aFront.BSDF();
1045   myCStructure->ContextFillArea.Front.Emission        = float (aFront.Emissive());
1046
1047   // Reflection mode
1048   myCStructure->ContextFillArea.Front.IsAmbient    = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT)  ? 1 : 0);
1049   myCStructure->ContextFillArea.Front.IsDiffuse    = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE)  ? 1 : 0);
1050   myCStructure->ContextFillArea.Front.IsSpecular   = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1051   myCStructure->ContextFillArea.Front.IsEmission   = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1052
1053   // Materail type
1054   //JR/Hp
1055   myCStructure->ContextFillArea.Front.IsPhysic     = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
1056
1057   // Specular Color
1058   myCStructure->ContextFillArea.Front.ColorSpec.r  = float (aFront.SpecularColor().Red());
1059   myCStructure->ContextFillArea.Front.ColorSpec.g  = float (aFront.SpecularColor().Green());
1060   myCStructure->ContextFillArea.Front.ColorSpec.b  = float (aFront.SpecularColor().Blue());
1061
1062   // Ambient color
1063   myCStructure->ContextFillArea.Front.ColorAmb.r   = float (aFront.AmbientColor().Red());
1064   myCStructure->ContextFillArea.Front.ColorAmb.g   = float (aFront.AmbientColor().Green());
1065   myCStructure->ContextFillArea.Front.ColorAmb.b   = float (aFront.AmbientColor().Blue());
1066
1067   // Diffuse color
1068   myCStructure->ContextFillArea.Front.ColorDif.r   = float (aFront.DiffuseColor().Red());
1069   myCStructure->ContextFillArea.Front.ColorDif.g   = float (aFront.DiffuseColor().Green());
1070   myCStructure->ContextFillArea.Front.ColorDif.b   = float (aFront.DiffuseColor().Blue());
1071
1072   // Emissive color
1073   myCStructure->ContextFillArea.Front.ColorEms.r   = float (aFront.EmissiveColor().Red());
1074   myCStructure->ContextFillArea.Front.ColorEms.g   = float (aFront.EmissiveColor().Green());
1075   myCStructure->ContextFillArea.Front.ColorEms.b   = float (aFront.EmissiveColor().Blue());
1076
1077   myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
1078
1079   myCStructure->ContextFillArea.IsDef = 1; // Definition material ok
1080
1081   myCStructure->ContextFillArea.Texture.TextureMap   = theAspFill->TextureMap();
1082   myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
1083   myCStructure->ContextFillArea.ShaderProgram        = theAspFill->ShaderProgram();
1084
1085   Standard_Integer   aPolyMode;
1086   Standard_ShortReal aPolyFactor, aPolyUnits;
1087   theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
1088   myCStructure->ContextFillArea.PolygonOffsetMode   = aPolyMode;
1089   myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
1090   myCStructure->ContextFillArea.PolygonOffsetUnits  = aPolyUnits;
1091
1092   myCStructure->UpdateAspects();
1093
1094   // Attributes are "IsSet" during the first update of context (line, marker...)
1095   myCStructure->ContextLine.IsSet     = 1;
1096   myCStructure->ContextFillArea.IsSet = 1;
1097   myCStructure->ContextMarker.IsSet   = 1;
1098   myCStructure->ContextText.IsSet     = 1;
1099
1100   Update();
1101 }
1102
1103 //=============================================================================
1104 //function : SetPrimitivesAspect
1105 //purpose  :
1106 //=============================================================================
1107 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
1108 {
1109   if (IsDeleted()) return;
1110
1111   Standard_CString         aFont;
1112   Standard_Real            aSpace, anExpansion, aTextAngle;
1113   Quantity_Color           aColor, aColorSub;
1114   Aspect_TypeOfStyleText   aStyle;
1115   Aspect_TypeOfDisplayText aDispType;
1116   Standard_Boolean         isTextZoomable;
1117   Font_FontAspect          aTextFontAspect;
1118   theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDispType, aColorSub, isTextZoomable, aTextAngle, aTextFontAspect);
1119
1120   myCStructure->ContextText.Color.r         = float (aColor.Red());
1121   myCStructure->ContextText.Color.g         = float (aColor.Green());
1122   myCStructure->ContextText.Color.b         = float (aColor.Blue());
1123   myCStructure->ContextText.Font            = aFont;
1124   myCStructure->ContextText.Expan           = float (anExpansion);
1125   myCStructure->ContextText.Space           = float (aSpace);
1126   myCStructure->ContextText.Style           = aStyle;
1127   myCStructure->ContextText.DisplayType     = aDispType;
1128   myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
1129   myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
1130   myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
1131   myCStructure->ContextText.TextZoomable    = isTextZoomable;
1132   myCStructure->ContextText.TextAngle       = float (aTextAngle);
1133   myCStructure->ContextText.TextFontAspect  = aTextFontAspect;
1134   myCStructure->ContextText.ShaderProgram   = theAspText->ShaderProgram();
1135
1136   myCStructure->ContextText.IsDef = 1;
1137
1138   myCStructure->UpdateAspects();
1139
1140   // Attributes are "IsSet" during the first update of a context (line, marker...)
1141   myCStructure->ContextLine.IsSet     = 1;
1142   myCStructure->ContextFillArea.IsSet = 1;
1143   myCStructure->ContextMarker.IsSet   = 1;
1144   myCStructure->ContextText.IsSet     = 1;
1145
1146   Update();
1147 }
1148
1149 //=============================================================================
1150 //function : SetPrimitivesAspect
1151 //purpose  :
1152 //=============================================================================
1153 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
1154 {
1155   if (IsDeleted()) return;
1156
1157   Standard_Real       aScale;
1158   Quantity_Color      aColor;
1159   Aspect_TypeOfMarker aMType;
1160   theAspMarker->Values (aColor, aMType, aScale);
1161
1162   myCStructure->ContextMarker.Color.r       = float (aColor.Red());
1163   myCStructure->ContextMarker.Color.g       = float (aColor.Green());
1164   myCStructure->ContextMarker.Color.b       = float (aColor.Blue());
1165   myCStructure->ContextMarker.MarkerType    = aMType;
1166   myCStructure->ContextMarker.Scale         = float (aScale);
1167   myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
1168   myCStructure->ContextMarker.IsDef         = 1;
1169
1170   myCStructure->UpdateAspects();
1171
1172   // Attributes are "IsSet" during the first update of a context (line, marker...)
1173   myCStructure->ContextLine.IsSet     = 1;
1174   myCStructure->ContextFillArea.IsSet = 1;
1175   myCStructure->ContextMarker.IsSet   = 1;
1176   myCStructure->ContextText.IsSet     = 1;
1177
1178   Update();
1179 }
1180
1181 //=============================================================================
1182 //function : SetVisual
1183 //purpose  :
1184 //=============================================================================
1185 void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
1186 {
1187   if (IsDeleted()
1188    || myVisual == theVisual)
1189   {
1190     return;
1191   }
1192
1193   if (!myCStructure->stick)
1194   {
1195     myVisual = theVisual;
1196     SetComputeVisual (theVisual);
1197   }
1198   else
1199   {
1200     Aspect_TypeOfUpdate anUpdateMode  = myStructureManager->UpdateMode();
1201     if (anUpdateMode == Aspect_TOU_WAIT)
1202     {
1203       Erase();
1204       myVisual = theVisual;
1205       SetComputeVisual (theVisual);
1206       Display();
1207     }
1208     else {
1209       // To avoid calling method : Update ()
1210       // Not useful and can be costly.
1211       myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
1212       Erase();
1213       myVisual = theVisual;
1214       SetComputeVisual (theVisual);
1215       myStructureManager->SetUpdateMode (anUpdateMode);
1216       Display();
1217     }
1218   }
1219 }
1220
1221 //=============================================================================
1222 //function : SetZoomLimit
1223 //purpose  :
1224 //=============================================================================
1225 void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
1226                                         const Standard_Real theLimitSup)
1227 {
1228   (void )theLimitInf;
1229   (void )theLimitSup;
1230   Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
1231                                                "Bad value for ZoomLimit inf");
1232   Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
1233                                                "Bad value for ZoomLimit sup");
1234   Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
1235                                                "ZoomLimit sup < ZoomLimit inf");
1236 }
1237
1238 //=============================================================================
1239 //function : Visual
1240 //purpose  :
1241 //=============================================================================
1242 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
1243 {
1244   return myVisual;
1245 }
1246
1247 //=============================================================================
1248 //function : AcceptConnection
1249 //purpose  :
1250 //=============================================================================
1251 Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
1252                                                         const Handle(Graphic3d_Structure)& theStructure2,
1253                                                         const Graphic3d_TypeOfConnection   theType)
1254 {
1255   // cycle detection
1256   Graphic3d_MapOfStructure aSet;
1257   Graphic3d_Structure::Network (theStructure2, theType, aSet);
1258   return !aSet.Contains (theStructure1);
1259 }
1260
1261 //=============================================================================
1262 //function : Ancestors
1263 //purpose  :
1264 //=============================================================================
1265 void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
1266 {
1267   for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myAncestors); anIter.More(); anIter.Next())
1268   {
1269     theSet.Add ((Graphic3d_Structure* )anIter.Value());
1270   }
1271 }
1272
1273 //=============================================================================
1274 //function : SetOwner
1275 //purpose  :
1276 //=============================================================================
1277 void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
1278 {
1279   myOwner = theOwner;
1280 }
1281
1282 //=============================================================================
1283 //function : Owner
1284 //purpose  :
1285 //=============================================================================
1286 Standard_Address Graphic3d_Structure::Owner() const
1287 {
1288   return myOwner;
1289 }
1290
1291 //=============================================================================
1292 //function : Descendants
1293 //purpose  :
1294 //=============================================================================
1295 void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
1296 {
1297   for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1298   {
1299     theSet.Add ((Graphic3d_Structure* )anIter.Value());
1300   }
1301 }
1302
1303 //=============================================================================
1304 //function : AppendAncestor
1305 //purpose  :
1306 //=============================================================================
1307 Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor)
1308 {
1309   const Standard_Integer aSize = myAncestors.Size();
1310
1311   return myAncestors.Add (theAncestor) > aSize; // new object
1312 }
1313
1314 //=============================================================================
1315 //function : AppendDescendant
1316 //purpose  :
1317 //=============================================================================
1318 Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant)
1319 {
1320   const Standard_Integer aSize = myDescendants.Size();
1321
1322   return myDescendants.Add (theDescendant) > aSize; // new object
1323 }
1324
1325 //=============================================================================
1326 //function : RemoveAncestor
1327 //purpose  :
1328 //=============================================================================
1329 Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor)
1330 {
1331   const Standard_Integer anIndex = myAncestors.FindIndex (theAncestor);
1332
1333   if (anIndex != 0)
1334   {
1335     myAncestors.Swap (anIndex, myAncestors.Size());
1336     myAncestors.RemoveLast();
1337   }
1338
1339   return anIndex != 0; // object was found
1340 }
1341
1342 //=============================================================================
1343 //function : RemoveDescendant
1344 //purpose  :
1345 //=============================================================================
1346 Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant)
1347 {
1348   const Standard_Integer anIndex = myDescendants.FindIndex (theDescendant);
1349
1350   if (anIndex != 0)
1351   {
1352     myDescendants.Swap (anIndex, myDescendants.Size());
1353     myDescendants.RemoveLast();
1354   }
1355
1356   return anIndex != 0; // object was found
1357 }
1358
1359 //=============================================================================
1360 //function : Connect
1361 //purpose  :
1362 //=============================================================================
1363 void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
1364                                    const Graphic3d_TypeOfConnection   theType,
1365                                    const Standard_Boolean             theWithCheck)
1366 {
1367   if (IsDeleted())
1368   {
1369     return;
1370   }
1371
1372   // cycle detection
1373   if (theWithCheck
1374    && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
1375   {
1376     return;
1377   }
1378
1379   const Standard_Address aStructure = theStructure.operator->();
1380
1381   if (theType == Graphic3d_TOC_DESCENDANT)
1382   {
1383     if (!AppendDescendant (aStructure))
1384     {
1385       return;
1386     }
1387
1388     CalculateBoundBox();
1389     theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
1390
1391     GraphicConnect (theStructure);
1392     myStructureManager->Connect (this, theStructure);
1393
1394     Update();
1395   }
1396   else // Graphic3d_TOC_ANCESTOR
1397   {
1398     if (!AppendAncestor (aStructure))
1399     {
1400       return;
1401     }
1402
1403     CalculateBoundBox();
1404     theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
1405
1406     // myStructureManager->Connect is called in case if connection between parent and child
1407   }
1408 }
1409
1410 //=============================================================================
1411 //function : Disconnect
1412 //purpose  :
1413 //=============================================================================
1414 void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
1415 {
1416   if (IsDeleted())
1417   {
1418     return;
1419   }
1420
1421   const Standard_Address aStructure = theStructure.operator->();
1422
1423   if (RemoveDescendant (aStructure))
1424   {
1425     theStructure->Disconnect (this);
1426
1427     GraphicDisconnect (theStructure);
1428     myStructureManager->Disconnect (this, theStructure);
1429
1430     CalculateBoundBox();
1431     Update();
1432   }
1433   else if (RemoveAncestor (aStructure))
1434   {
1435     theStructure->Disconnect (this);
1436     CalculateBoundBox();
1437
1438     // no call of myStructureManager->Disconnect in case of an ancestor
1439   }
1440 }
1441
1442 //=============================================================================
1443 //function : DisconnectAll
1444 //purpose  :
1445 //=============================================================================
1446 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
1447 {
1448   if (IsDeleted()) return;
1449
1450   switch (theType)
1451   {
1452     case Graphic3d_TOC_DESCENDANT:
1453     {
1454       for (Standard_Integer anIdx = 1, aLength = myDescendants.Size(); anIdx <= aLength; ++anIdx)
1455       {
1456         // Value (1) instead of Value (i) as myDescendants
1457         // is modified by :
1458         // Graphic3d_Structure::Disconnect (AStructure)
1459         // that takes AStructure from myDescendants
1460         ((Graphic3d_Structure* )(myDescendants.FindKey (1)))->Disconnect (this);
1461       }
1462       break;
1463     }
1464     case Graphic3d_TOC_ANCESTOR:
1465     {
1466       for (Standard_Integer anIdx = 1, aLength = myAncestors.Size(); anIdx <= aLength; ++anIdx)
1467       {
1468         // Value (1) instead of Value (i) as myAncestors
1469         // is modified by :
1470         // Graphic3d_Structure::Disconnect (AStructure)
1471         // that takes AStructure from myAncestors
1472         ((Graphic3d_Structure* )(myAncestors.FindKey (1)))->Disconnect (this);
1473       }
1474       break;
1475     }
1476   }
1477 }
1478
1479 //=============================================================================
1480 //function : SetTransform
1481 //purpose  :
1482 //=============================================================================
1483 void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal&       theMatrix,
1484                                         const Graphic3d_TypeOfComposition theType)
1485 {
1486   if (IsDeleted()) return;
1487
1488   Standard_Real valuetrsf;
1489   Standard_Real valueoldtrsf;
1490   Standard_Real valuenewtrsf;
1491   TColStd_Array2OfReal aNewTrsf  (0, 3, 0, 3);
1492   TColStd_Array2OfReal aMatrix44 (0, 3, 0, 3);
1493
1494   // Assign the new transformation in an array [0..3][0..3]
1495   // Avoid problems if the user has defined matrix [1..4][1..4]
1496   //                                            or [3..6][-1..2] !!
1497   Standard_Integer lr = theMatrix.LowerRow();
1498   Standard_Integer ur = theMatrix.UpperRow();
1499   Standard_Integer lc = theMatrix.LowerCol();
1500   Standard_Integer uc = theMatrix.UpperCol();
1501
1502   if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1503   {
1504     Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1505   }
1506
1507   const Standard_Boolean wasTransformed = IsTransformed();
1508   switch (theType)
1509   {
1510     case Graphic3d_TOC_REPLACE:
1511     {
1512       // Update of CStructure
1513       for (Standard_Integer i = 0; i <= 3; ++i)
1514       {
1515         for (Standard_Integer j = 0; j <= 3; ++j)
1516         {
1517           myCStructure->Transformation.ChangeValue (i, j) = float (theMatrix (lr + i, lc + j));
1518           aNewTrsf (i, j) = theMatrix (lr + i, lc + j);
1519         }
1520       }
1521       break;
1522     }
1523     case Graphic3d_TOC_POSTCONCATENATE:
1524     {
1525       // To simplify management of indices
1526       for (Standard_Integer i = 0; i <= 3; ++i)
1527       {
1528         for (Standard_Integer j = 0; j <= 3; ++j)
1529         {
1530           aMatrix44 (i, j) = theMatrix (lr + i, lc + j);
1531         }
1532       }
1533
1534       // Calculation of the product of matrices
1535       for (Standard_Integer i = 0; i <= 3; ++i)
1536       {
1537         for (Standard_Integer j = 0; j <= 3; ++j)
1538         {
1539           aNewTrsf (i, j) = 0.0;
1540           for (Standard_Integer k = 0; k <= 3; ++k)
1541           {
1542             valueoldtrsf = myCStructure->Transformation.GetValue (i, k);
1543             valuetrsf    = aMatrix44 (k, j);
1544             valuenewtrsf = aNewTrsf (i, j) + valueoldtrsf * valuetrsf;
1545             aNewTrsf (i, j) = valuenewtrsf;
1546           }
1547         }
1548       }
1549
1550       // Update of CStructure
1551       for (Standard_Integer i = 0; i <= 3; ++i)
1552       {
1553         for (Standard_Integer j = 0; j <= 3; ++j)
1554         {
1555           myCStructure->Transformation.ChangeValue (i, j) = float (aNewTrsf (i, j));
1556         }
1557       }
1558       break;
1559     }
1560   }
1561
1562   // If transformation, no validation of hidden already calculated parts
1563   if (IsTransformed() || (!IsTransformed() && wasTransformed))
1564   {
1565     ReCompute();
1566   }
1567
1568   myCStructure->UpdateTransformation();
1569   myStructureManager->SetTransform (this, aNewTrsf);
1570
1571   Update();
1572 }
1573
1574 //=============================================================================
1575 //function : Transform
1576 //purpose  :
1577 //=============================================================================
1578 void Graphic3d_Structure::Transform (TColStd_Array2OfReal& theMatrix) const
1579 {
1580
1581   Standard_Integer lr = theMatrix.LowerRow ();
1582   Standard_Integer ur = theMatrix.UpperRow ();
1583   Standard_Integer lc = theMatrix.LowerCol ();
1584   Standard_Integer uc = theMatrix.UpperCol ();
1585
1586   if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1587     Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1588
1589   for (Standard_Integer i = 0; i <= 3; ++i)
1590   {
1591     for (Standard_Integer j = 0; j <= 3; ++j)
1592     {
1593       theMatrix (lr + i, lc + j) = myCStructure->Transformation.GetValue (i, j);
1594     }
1595   }
1596 }
1597
1598
1599 //=============================================================================
1600 //function : MinMaxValues
1601 //purpose  :
1602 //=============================================================================
1603 Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
1604 {
1605   Graphic3d_BndBox4d aBox;
1606   Bnd_Box aResult;
1607   addTransformed (aBox, theToIgnoreInfiniteFlag);
1608   if (aBox.IsValid())
1609   {
1610     aResult.Add (gp_Pnt (aBox.CornerMin().x(),
1611                          aBox.CornerMin().y(),
1612                          aBox.CornerMin().z()));
1613     aResult.Add (gp_Pnt (aBox.CornerMax().x(),
1614                          aBox.CornerMax().y(),
1615                          aBox.CornerMax().z()));
1616
1617     Standard_Real aLimMin = ShortRealFirst() + 1.0;
1618     Standard_Real aLimMax = ShortRealLast() - 1.0;
1619     gp_Pnt aMin = aResult.CornerMin();
1620     gp_Pnt aMax = aResult.CornerMax();
1621     if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin &&
1622         aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax)
1623     {
1624       //For structure which infinite in all three dimensions the Whole bounding box will be returned
1625       aResult.SetWhole();
1626     }
1627   }
1628   return aResult;
1629 }
1630
1631 //=============================================================================
1632 //function : Identification
1633 //purpose  :
1634 //=============================================================================
1635 Standard_Integer Graphic3d_Structure::Identification() const
1636 {
1637   return myCStructure->Id;
1638 }
1639
1640 //=============================================================================
1641 //function : SetTransformPersistence
1642 //purpose  :
1643 //=============================================================================
1644 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag)
1645 {
1646   SetTransformPersistence (theFlag, gp_Pnt (0.0, 0.0, 0.0));
1647 }
1648
1649 //=============================================================================
1650 //function : SetTransformPersistence
1651 //purpose  :
1652 //=============================================================================
1653 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
1654                                                    const gp_Pnt&                   thePoint)
1655 {
1656   if (IsDeleted()) return;
1657
1658   myCStructure->TransformPersistence.Flags     = theFlag;
1659   myCStructure->TransformPersistence.Point.x() = thePoint.X();
1660   myCStructure->TransformPersistence.Point.y() = thePoint.Y();
1661   myCStructure->TransformPersistence.Point.z() = thePoint.Z();
1662 }
1663
1664 //=============================================================================
1665 //function : TransformPersistenceMode
1666 //purpose  :
1667 //=============================================================================
1668 Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1669 {
1670   return myCStructure->TransformPersistence.Flags;
1671 }
1672
1673 //=============================================================================
1674 //function : TransformPersistencePoint
1675 //purpose  :
1676 //=============================================================================
1677 gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const
1678 {
1679   gp_Pnt aPnt (0.0, 0.0, 0.0);
1680   aPnt.SetX (myCStructure->TransformPersistence.Point.x());
1681   aPnt.SetY (myCStructure->TransformPersistence.Point.y());
1682   aPnt.SetZ (myCStructure->TransformPersistence.Point.z());
1683   return aPnt;
1684 }
1685
1686 //=============================================================================
1687 //function : Remove
1688 //purpose  :
1689 //=============================================================================
1690 void Graphic3d_Structure::Remove (const Standard_Address           thePtr,
1691                                   const Graphic3d_TypeOfConnection theType)
1692 {
1693   if (theType == Graphic3d_TOC_DESCENDANT)
1694   {
1695     RemoveDescendant (thePtr);
1696   }
1697   else
1698   {
1699     RemoveAncestor (thePtr);
1700   }
1701 }
1702
1703 //=============================================================================
1704 //function : NewGroup
1705 //purpose  :
1706 //=============================================================================
1707 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
1708 {
1709   return myCStructure->NewGroup (this);
1710 }
1711
1712 //=============================================================================
1713 //function : Remove
1714 //purpose  :
1715 //=============================================================================
1716 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1717 {
1718   if (theGroup.IsNull()
1719    || theGroup->myStructure != this)
1720   {
1721     return;
1722   }
1723
1724   myCStructure->RemoveGroup (theGroup);
1725   theGroup->myStructure = NULL;
1726 }
1727
1728 //=============================================================================
1729 //function : StructureManager
1730 //purpose  :
1731 //=============================================================================
1732 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1733 {
1734   return myStructureManager;
1735 }
1736
1737 //=============================================================================
1738 //function : minMaxCoord
1739 //purpose  :
1740 //=============================================================================
1741 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
1742 {
1743   Graphic3d_BndBox4f aBnd;
1744   for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1745   {
1746     aBnd.Combine (aGroupIter.Value()->BoundingBox());
1747   }
1748   return aBnd;
1749 }
1750
1751 //=============================================================================
1752 //function : addTransformed
1753 //purpose  :
1754 //=============================================================================
1755 void Graphic3d_Structure::getBox (Graphic3d_BndBox4d&    theBox,
1756                                   const Standard_Boolean theToIgnoreInfiniteFlag) const
1757 {
1758   Graphic3d_BndBox4f aBoxF = minMaxCoord();
1759   if (aBoxF.IsValid())
1760   {
1761     theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMin().x(),
1762                                                   (Standard_Real )aBoxF.CornerMin().y(),
1763                                                   (Standard_Real )aBoxF.CornerMin().z(),
1764                                                   (Standard_Real )aBoxF.CornerMin().w()),
1765                                  Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMax().x(),
1766                                                   (Standard_Real )aBoxF.CornerMax().y(),
1767                                                   (Standard_Real )aBoxF.CornerMax().z(),
1768                                                   (Standard_Real )aBoxF.CornerMax().w()));
1769     if (IsInfinite()
1770     && !theToIgnoreInfiniteFlag)
1771     {
1772       const Graphic3d_Vec4d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
1773       if (aDiagVec.xyz().SquareModulus() >= 500000.0 * 500000.0)
1774       {
1775         // bounding borders of infinite line has been calculated as own point in center of this line
1776         theBox = Graphic3d_BndBox4d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
1777       }
1778       else
1779       {
1780         theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d (RealFirst(), RealFirst(), RealFirst(), 1.0),
1781                                      Graphic3d_Vec4d (RealLast(),  RealLast(),  RealLast(),  1.0));
1782         return;
1783       }
1784     }
1785   }
1786 }
1787
1788 //=============================================================================
1789 //function : addTransformed
1790 //purpose  :
1791 //=============================================================================
1792 void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d&    theBox,
1793                                           const Standard_Boolean theToIgnoreInfiniteFlag) const
1794 {
1795   Graphic3d_BndBox4d aCombinedBox, aBox;
1796   getBox (aCombinedBox, theToIgnoreInfiniteFlag);
1797
1798   for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1799   {
1800     const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )anIter.Value();
1801     aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1802     aCombinedBox.Combine (aBox);
1803   }
1804
1805   aBox = aCombinedBox;
1806   if (aBox.IsValid())
1807   {
1808     TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1809     Transform (aTrsf);
1810     TransformBoundaries (aTrsf, aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1811                                 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1812
1813     // if box is still valid after transformation
1814     if (aBox.IsValid())
1815     {
1816       theBox.Combine (aBox);
1817     }
1818     else // it was infinite, return untransformed
1819     {
1820       theBox.Combine (aCombinedBox);
1821     }
1822   }
1823 }
1824
1825 //=============================================================================
1826 //function : Transforms
1827 //purpose  :
1828 //=============================================================================
1829 void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1830                                       const Standard_Real theX,    const Standard_Real theY,    const Standard_Real theZ,
1831                                       Standard_Real&      theNewX, Standard_Real&      theNewY, Standard_Real&      theNewZ)
1832 {
1833   const Standard_Real aRL = RealLast();
1834   const Standard_Real aRF = RealFirst();
1835   if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1836    || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1837   {
1838     theNewX = theX;
1839     theNewY = theY;
1840     theNewZ = theZ;
1841   }
1842   else
1843   {
1844     Standard_Real A, B, C, D;
1845     A       = theTrsf (0, 0);
1846     B       = theTrsf (0, 1);
1847     C       = theTrsf (0, 2);
1848     D       = theTrsf (0, 3);
1849     theNewX = A * theX + B * theY + C * theZ + D;
1850     A       = theTrsf (1, 0);
1851     B       = theTrsf (1, 1);
1852     C       = theTrsf (1, 2);
1853     D       = theTrsf (1, 3);
1854     theNewY = A * theX + B * theY + C * theZ + D;
1855     A       = theTrsf (2, 0);
1856     B       = theTrsf (2, 1);
1857     C       = theTrsf (2, 2);
1858     D       = theTrsf (2, 3);
1859     theNewZ = A * theX + B * theY + C * theZ + D;
1860   }
1861 }
1862
1863 //=============================================================================
1864 //function : Transforms
1865 //purpose  :
1866 //=============================================================================
1867 Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1868                                                   const Graphic3d_Vector&     theCoord)
1869 {
1870   Standard_Real anXYZ[3];
1871   Graphic3d_Structure::Transforms (theTrsf,
1872                                    theCoord.X(), theCoord.Y(), theCoord.Z(),
1873                                    anXYZ[0], anXYZ[1], anXYZ[2]);
1874   return Graphic3d_Vector (anXYZ[0], anXYZ[1], anXYZ[2]);
1875 }
1876
1877 //=============================================================================
1878 //function : Transforms
1879 //purpose  :
1880 //=============================================================================
1881 Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1882                                                   const Graphic3d_Vertex&     theCoord)
1883 {
1884   Standard_Real anXYZ[3];
1885   Graphic3d_Structure::Transforms (theTrsf,
1886                                    theCoord.X(), theCoord.Y(), theCoord.Z(),
1887                                    anXYZ[0], anXYZ[1], anXYZ[2]);
1888   return Graphic3d_Vertex (anXYZ[0], anXYZ[1], anXYZ[2]);
1889 }
1890
1891 //=============================================================================
1892 //function : Transforms
1893 //purpose  :
1894 //=============================================================================
1895 void Graphic3d_Structure::TransformBoundaries (const TColStd_Array2OfReal& theTrsf,
1896                                                Standard_Real& theXMin,
1897                                                Standard_Real& theYMin,
1898                                                Standard_Real& theZMin,
1899                                                Standard_Real& theXMax,
1900                                                Standard_Real& theYMax,
1901                                                Standard_Real& theZMax)
1902 {
1903   Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1904
1905   Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1906   Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1907
1908   Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
1909   aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1910   aYMin = Min (aV,  aYMin); aYMax = Max (aV,  aYMax);
1911   aZMin = Min (aW,  aZMin); aZMax = Max (aW,  aZMax);
1912
1913   Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
1914   aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1915   aYMin = Min (aV,  aYMin); aYMax = Max (aV,  aYMax);
1916   aZMin = Min (aW,  aZMin); aZMax = Max (aW,  aZMax);
1917
1918   Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
1919   aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1920   aYMin = Min (aV,  aYMin); aYMax = Max (aV,  aYMax);
1921   aZMin = Min (aW,  aZMin); aZMax = Max (aW,  aZMax);
1922
1923   Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
1924   aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1925   aYMin = Min (aV,  aYMin); aYMax = Max (aV,  aYMax);
1926   aZMin = Min (aW,  aZMin); aZMax = Max (aW,  aZMax);
1927
1928   Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
1929   aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1930   aYMin = Min (aV,  aYMin); aYMax = Max (aV,  aYMax);
1931   aZMin = Min (aW,  aZMin); aZMax = Max (aW,  aZMax);
1932
1933   Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
1934   aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1935   aYMin = Min (aV,  aYMin); aYMax = Max (aV,  aYMax);
1936   aZMin = Min (aW,  aZMin); aZMax = Max (aW,  aZMax);
1937
1938   theXMin = aXMin;
1939   theYMin = aYMin;
1940   theZMin = aZMin;
1941   theXMax = aXMax;
1942   theYMax = aYMax;
1943   theZMax = aZMax;
1944 }
1945
1946 //=============================================================================
1947 //function : Network
1948 //purpose  :
1949 //=============================================================================
1950 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
1951                                    const Graphic3d_TypeOfConnection   theType,
1952                                    Graphic3d_MapOfStructure&          theSet)
1953 {
1954   Graphic3d_MapOfStructure aSetD, aSetA;
1955   theStructure->Descendants (aSetD);
1956   theStructure->Ancestors   (aSetA);
1957   theSet.Add (theStructure);
1958   switch (theType)
1959   {
1960     case Graphic3d_TOC_DESCENDANT:
1961       for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
1962       {
1963         Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
1964       }
1965       break;
1966     case Graphic3d_TOC_ANCESTOR:
1967       for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
1968       {
1969         Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
1970       }
1971       break;
1972   }
1973 }
1974
1975 //=============================================================================
1976 //function : PrintNetwork
1977 //purpose  :
1978 //=============================================================================
1979 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
1980                                         const Graphic3d_TypeOfConnection   theType)
1981 {
1982   Graphic3d_MapOfStructure aSet;
1983   Graphic3d_Structure::Network (theStructure, theType, aSet);
1984   for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
1985   {
1986     std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
1987   }
1988   std::cout << std::flush;
1989 }
1990
1991 //=============================================================================
1992 //function : Update
1993 //purpose  :
1994 //=============================================================================
1995 void Graphic3d_Structure::Update() const
1996 {
1997   if (IsDeleted())
1998   {
1999     return;
2000   }
2001
2002   myStructureManager->Update (myStructureManager->UpdateMode());
2003 }
2004
2005 //=============================================================================
2006 //function : UpdateStructure
2007 //purpose  :
2008 //=============================================================================
2009 void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)&     theAspLine,
2010                                            const Handle(Graphic3d_AspectText3d)&     theAspText,
2011                                            const Handle(Graphic3d_AspectMarker3d)&   theAspMarker,
2012                                            const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
2013 {
2014   Standard_CString          aFont;
2015   Standard_Real             aSpace, anExpansion, aWidth, aScale;
2016   Quantity_Color            aColor, anIntColor, aBackIntColor, anEdgeColor, aColorSub;
2017   Aspect_TypeOfLine         aLType;
2018   Aspect_TypeOfMarker       aMType;
2019   Aspect_InteriorStyle      aStyle;
2020   Aspect_TypeOfStyleText    aStyleT;
2021   Aspect_TypeOfDisplayText  aDisplayType;
2022   Standard_Boolean          aTextZoomable;
2023   Standard_Real             aTextAngle;
2024   Font_FontAspect           aTextFontAspect;
2025
2026   theAspLine->Values (aColor, aLType, aWidth);
2027   myCStructure->ContextLine.Color.r        = float (aColor.Red());
2028   myCStructure->ContextLine.Color.g        = float (aColor.Green());
2029   myCStructure->ContextLine.Color.b        = float (aColor.Blue());
2030   myCStructure->ContextLine.LineType       = aLType;
2031   myCStructure->ContextLine.Width          = float (aWidth);
2032   myCStructure->ContextLine.ShaderProgram  = theAspLine->ShaderProgram();
2033
2034   theAspMarker->Values (aColor, aMType, aScale);
2035   myCStructure->ContextMarker.Color.r      = float (aColor.Red());
2036   myCStructure->ContextMarker.Color.g      = float (aColor.Green());
2037   myCStructure->ContextMarker.Color.b      = float (aColor.Blue());
2038   myCStructure->ContextMarker.MarkerType   = aMType;
2039   myCStructure->ContextMarker.Scale        = float (aScale);
2040   myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
2041
2042   theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyleT, aDisplayType, aColorSub, aTextZoomable, aTextAngle, aTextFontAspect);
2043   myCStructure->ContextText.Color.r          = float (aColor.Red());
2044   myCStructure->ContextText.Color.g          = float (aColor.Green());
2045   myCStructure->ContextText.Color.b          = float (aColor.Blue());
2046   myCStructure->ContextText.Font             = aFont;
2047   myCStructure->ContextText.Expan            = float (anExpansion);
2048   myCStructure->ContextText.Style            = aStyleT;
2049   myCStructure->ContextText.DisplayType      = aDisplayType;
2050   myCStructure->ContextText.Space            = float (aSpace);
2051   myCStructure->ContextText.ColorSubTitle.r  = float (aColorSub.Red());
2052   myCStructure->ContextText.ColorSubTitle.g  = float (aColorSub.Green());
2053   myCStructure->ContextText.ColorSubTitle.b  = float (aColorSub.Blue());
2054   myCStructure->ContextText.TextZoomable     = aTextZoomable;
2055   myCStructure->ContextText.TextAngle        = float (aTextAngle);
2056   myCStructure->ContextText.TextFontAspect   = aTextFontAspect;
2057   myCStructure->ContextText.ShaderProgram    = theAspText->ShaderProgram();
2058
2059   Standard_Real anRGB[3];
2060   theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
2061   anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2062   myCStructure->ContextFillArea.Style      = aStyle;
2063   myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
2064   myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
2065   myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
2066
2067   if (theAspFill->Distinguish())
2068   {
2069     aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2070   }
2071   myCStructure->ContextFillArea.BackIntColor.r = float (anRGB[0]);
2072   myCStructure->ContextFillArea.BackIntColor.g = float (anRGB[1]);
2073   myCStructure->ContextFillArea.BackIntColor.b = float (anRGB[2]);
2074
2075   // Edges
2076   myCStructure->ContextFillArea.Edge               = theAspFill->Edge () ? 1:0;
2077   myCStructure->ContextFillArea.EdgeColor.r        = float (anEdgeColor.Red());
2078   myCStructure->ContextFillArea.EdgeColor.g        = float (anEdgeColor.Green());
2079   myCStructure->ContextFillArea.EdgeColor.b        = float (anEdgeColor.Blue());
2080   myCStructure->ContextFillArea.LineType           = aLType;
2081   myCStructure->ContextFillArea.Width              = float (aWidth);
2082   myCStructure->ContextFillArea.Hatch              = theAspFill->HatchStyle();
2083
2084   // Front and Back face
2085   myCStructure->ContextFillArea.Distinguish        = theAspFill->Distinguish() ? 1 : 0;
2086   myCStructure->ContextFillArea.BackFace           = theAspFill->BackFace()    ? 1 : 0;
2087   // Back Material
2088   const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
2089   // Light specificity
2090   myCStructure->ContextFillArea.Back.Shininess     = float (aBack.Shininess());
2091   myCStructure->ContextFillArea.Back.Ambient       = float (aBack.Ambient());
2092   myCStructure->ContextFillArea.Back.Diffuse       = float (aBack.Diffuse());
2093   myCStructure->ContextFillArea.Back.Specular      = float (aBack.Specular());
2094   myCStructure->ContextFillArea.Back.Transparency  = float (aBack.Transparency());
2095   myCStructure->ContextFillArea.Back.Emission      = float (aBack.Emissive());
2096
2097   // Reflection mode
2098   myCStructure->ContextFillArea.Back.IsAmbient     = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT)  ? 1 : 0);
2099   myCStructure->ContextFillArea.Back.IsDiffuse     = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE)  ? 1 : 0);
2100   myCStructure->ContextFillArea.Back.IsSpecular    = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2101   myCStructure->ContextFillArea.Back.IsEmission    = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2102
2103   // Material type
2104   myCStructure->ContextFillArea.Back.IsPhysic      = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2105
2106   // Specular color
2107   myCStructure->ContextFillArea.Back.ColorSpec.r   = float (aBack.SpecularColor().Red());
2108   myCStructure->ContextFillArea.Back.ColorSpec.g   = float (aBack.SpecularColor().Green());
2109   myCStructure->ContextFillArea.Back.ColorSpec.b   = float (aBack.SpecularColor().Blue());
2110
2111   // Ambient color
2112   myCStructure->ContextFillArea.Back.ColorAmb.r    = float (aBack.AmbientColor().Red());
2113   myCStructure->ContextFillArea.Back.ColorAmb.g    = float (aBack.AmbientColor().Green());
2114   myCStructure->ContextFillArea.Back.ColorAmb.b    = float (aBack.AmbientColor().Blue());
2115
2116   // Diffuse color
2117   myCStructure->ContextFillArea.Back.ColorDif.r    = float (aBack.DiffuseColor().Red());
2118   myCStructure->ContextFillArea.Back.ColorDif.g    = float (aBack.DiffuseColor().Green());
2119   myCStructure->ContextFillArea.Back.ColorDif.b    = float (aBack.DiffuseColor().Blue());
2120
2121   // Emissive color
2122   myCStructure->ContextFillArea.Back.ColorEms.r    = float (aBack.EmissiveColor().Red());
2123   myCStructure->ContextFillArea.Back.ColorEms.g    = float (aBack.EmissiveColor().Green());
2124   myCStructure->ContextFillArea.Back.ColorEms.b    = float (aBack.EmissiveColor().Blue());
2125
2126   myCStructure->ContextFillArea.Back.EnvReflexion  = float (aBack.EnvReflexion());
2127
2128   // Front Material
2129   const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
2130   // Light specificity
2131   myCStructure->ContextFillArea.Front.Shininess    = float (aFront.Shininess());
2132   myCStructure->ContextFillArea.Front.Ambient      = float (aFront.Ambient());
2133   myCStructure->ContextFillArea.Front.Diffuse      = float (aFront.Diffuse());
2134   myCStructure->ContextFillArea.Front.Specular     = float (aFront.Specular());
2135   myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
2136   myCStructure->ContextFillArea.Front.Emission     = float (aFront.Emissive());
2137
2138   // Reflection mode
2139   myCStructure->ContextFillArea.Front.IsAmbient    = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT)  ? 1 : 0);
2140   myCStructure->ContextFillArea.Front.IsDiffuse    = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE)  ? 1 : 0);
2141   myCStructure->ContextFillArea.Front.IsSpecular   = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2142   myCStructure->ContextFillArea.Front.IsEmission   = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2143
2144   // Material type
2145   myCStructure->ContextFillArea.Front.IsPhysic     = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2146
2147   // Specular color
2148   myCStructure->ContextFillArea.Front.ColorSpec.r  = float (aFront.SpecularColor().Red());
2149   myCStructure->ContextFillArea.Front.ColorSpec.g  = float (aFront.SpecularColor().Green());
2150   myCStructure->ContextFillArea.Front.ColorSpec.b  = float (aFront.SpecularColor().Blue());
2151
2152   // Ambient color
2153   myCStructure->ContextFillArea.Front.ColorAmb.r   = float (aFront.AmbientColor().Red());
2154   myCStructure->ContextFillArea.Front.ColorAmb.g   = float (aFront.AmbientColor().Green());
2155   myCStructure->ContextFillArea.Front.ColorAmb.b   = float (aFront.AmbientColor().Blue());
2156
2157   // Diffuse color
2158   myCStructure->ContextFillArea.Front.ColorDif.r   = float (aFront.DiffuseColor().Red());
2159   myCStructure->ContextFillArea.Front.ColorDif.g   = float (aFront.DiffuseColor().Green());
2160   myCStructure->ContextFillArea.Front.ColorDif.b   = float (aFront.DiffuseColor().Blue());
2161
2162   // Emissive color
2163   myCStructure->ContextFillArea.Front.ColorEms.r   = float (aFront.EmissiveColor().Red());
2164   myCStructure->ContextFillArea.Front.ColorEms.g   = float (aFront.EmissiveColor().Green());
2165   myCStructure->ContextFillArea.Front.ColorEms.b   = float (aFront.EmissiveColor().Blue());
2166
2167   myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
2168
2169   myCStructure->ContextFillArea.Texture.TextureMap   = theAspFill->TextureMap();
2170   myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
2171   myCStructure->ContextFillArea.ShaderProgram        = theAspFill->ShaderProgram();
2172
2173   Standard_Integer   aPolyMode;
2174   Standard_ShortReal aPolyFactor, aPolyUnits;
2175   theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
2176   myCStructure->ContextFillArea.PolygonOffsetMode   = aPolyMode;
2177   myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
2178   myCStructure->ContextFillArea.PolygonOffsetUnits  = aPolyUnits;
2179 }
2180
2181 //=============================================================================
2182 //function : GraphicHighlight
2183 //purpose  :
2184 //=============================================================================
2185 void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod theMethod)
2186 {
2187   Standard_Real anRGB[3];
2188   myCStructure->highlight = 1;
2189   myHighlightMethod = theMethod;
2190   switch (theMethod)
2191   {
2192     case Aspect_TOHM_COLOR:
2193     {
2194       myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2195       myCStructure->HighlightWithColor (Graphic3d_Vec3 (float (anRGB[0]), float (anRGB[1]), float (anRGB[2])), Standard_True);
2196       break;
2197     }
2198     case Aspect_TOHM_BOUNDBOX:
2199     {
2200       myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2201       myCStructure->HighlightColor.r = float (anRGB[0]);
2202       myCStructure->HighlightColor.g = float (anRGB[1]);
2203       myCStructure->HighlightColor.b = float (anRGB[2]);
2204       myCStructure->HighlightWithBndBox (this, Standard_True);
2205       break;
2206     }
2207   }
2208 }
2209
2210 //=============================================================================
2211 //function : GraphicTransform
2212 //purpose  :
2213 //=============================================================================
2214 void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& theMatrix)
2215 {
2216   for (Standard_Integer i = 0; i <= 3; ++i)
2217   {
2218     for (Standard_Integer j = 0; j <= 3; ++j)
2219     {
2220       myCStructure->Transformation.ChangeValue (i, j) = float (theMatrix (i, j));
2221     }
2222   }
2223   myCStructure->UpdateTransformation();
2224 }
2225
2226 //=============================================================================
2227 //function : GraphicUnHighlight
2228 //purpose  :
2229 //=============================================================================
2230 void Graphic3d_Structure::GraphicUnHighlight()
2231 {
2232   myCStructure->highlight = 0;
2233   switch (myHighlightMethod)
2234   {
2235     case Aspect_TOHM_COLOR:
2236       myCStructure->HighlightWithColor (Graphic3d_Vec3 (0.0f, 0.0f, 0.0f), Standard_False);
2237       break;
2238     case Aspect_TOHM_BOUNDBOX:
2239       myCStructure->HighlightWithBndBox (this, Standard_False);
2240       break;
2241   }
2242 }
2243
2244 //=============================================================================
2245 //function : ComputeVisual
2246 //purpose  :
2247 //=============================================================================
2248 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
2249 {
2250   return myComputeVisual;
2251 }
2252
2253 //=============================================================================
2254 //function : SetComputeVisual
2255 //purpose  :
2256 //=============================================================================
2257 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
2258 {
2259   // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
2260   // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
2261   if (theVisual != Graphic3d_TOS_COMPUTED)
2262   {
2263     myComputeVisual = theVisual;
2264   }
2265 }
2266
2267 //=============================================================================
2268 //function : SetHLRValidation
2269 //purpose  :
2270 //=============================================================================
2271 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
2272 {
2273   myCStructure->HLRValidation = theFlag ? 1 : 0;
2274 }
2275
2276 //=============================================================================
2277 //function : HLRValidation
2278 //purpose  :
2279 //=============================================================================
2280 Standard_Boolean Graphic3d_Structure::HLRValidation() const
2281 {
2282   // Hidden parts stored in <me> are valid if :
2283   // 1/ the owner is defined.
2284   // 2/ they are not invalid.
2285   return myOwner != NULL
2286       && myCStructure->HLRValidation != 0;
2287 }
2288
2289 //=======================================================================
2290 //function : SetZLayer
2291 //purpose  :
2292 //=======================================================================
2293 void Graphic3d_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerId)
2294 {
2295   // if the structure is not displayed, unable to change its display layer
2296   if (IsDeleted ())
2297     return;
2298
2299   myStructureManager->ChangeZLayer (this, theLayerId);
2300   myCStructure->SetZLayer (theLayerId);
2301 }
2302
2303 //=======================================================================
2304 //function : GetZLayer
2305 //purpose  :
2306 //=======================================================================
2307 Graphic3d_ZLayerId Graphic3d_Structure::GetZLayer() const
2308 {
2309   return myCStructure->ZLayer();
2310 }
2311
2312 //=======================================================================
2313 //function : SetClipPlanes
2314 //purpose  :
2315 //=======================================================================
2316 void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
2317 {
2318   myCStructure->SetClipPlanes (thePlanes);
2319 }
2320
2321 //=======================================================================
2322 //function : GetClipPlanes
2323 //purpose  :
2324 //=======================================================================
2325 const Graphic3d_SequenceOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const
2326 {
2327   return myCStructure->ClipPlanes();
2328 }
2329
2330 //=======================================================================
2331 //function : SetMutable
2332 //purpose  :
2333 //=======================================================================
2334 void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
2335 {
2336   myCStructure->IsMutable = theIsMutable;
2337 }
2338
2339 //=======================================================================
2340 //function : IsMutable
2341 //purpose  :
2342 //=======================================================================
2343 Standard_Boolean Graphic3d_Structure::IsMutable() const
2344 {
2345   return myCStructure->IsMutable;
2346 }