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