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