0025332: Visualization - rewrite MinMaxValues methods to using of Bnd_Box
[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   myCStructure->UpdateTransformation();
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 Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
1655 {
1656   Graphic3d_BndBox4d aBox;
1657   Bnd_Box aResult;
1658   addTransformed (aBox, theToIgnoreInfiniteFlag);
1659   if (aBox.IsValid())
1660   {
1661     aResult.Add (gp_Pnt (aBox.CornerMin().x(),
1662                          aBox.CornerMin().y(),
1663                          aBox.CornerMin().z()));
1664     aResult.Add (gp_Pnt (aBox.CornerMax().x(),
1665                          aBox.CornerMax().y(),
1666                          aBox.CornerMax().z()));
1667
1668     Standard_Real aLimMin = ShortRealFirst() + 1.0;
1669     Standard_Real aLimMax = ShortRealLast() - 1.0;
1670     gp_Pnt aMin = aResult.CornerMin();
1671     gp_Pnt aMax = aResult.CornerMax();
1672     if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin &&
1673         aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax)
1674     {
1675       //For structure which infinite in all three dimensions the Whole bounding box will be returned
1676       aResult.SetWhole();
1677     }
1678   }
1679   return aResult;
1680 }
1681
1682 //=============================================================================
1683 //function : Identification
1684 //purpose  :
1685 //=============================================================================
1686 Standard_Integer Graphic3d_Structure::Identification() const
1687 {
1688   return myCStructure->Id;
1689 }
1690
1691 //=============================================================================
1692 //function : SetTransformPersistence
1693 //purpose  :
1694 //=============================================================================
1695 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag)
1696 {
1697   SetTransformPersistence (theFlag, gp_Pnt (0.0, 0.0, 0.0));
1698 }
1699
1700 //=============================================================================
1701 //function : SetTransformPersistence
1702 //purpose  :
1703 //=============================================================================
1704 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
1705                                                    const gp_Pnt&                   thePoint)
1706 {
1707   if (IsDeleted()) return;
1708
1709   myCStructure->TransformPersistence.Flag    = theFlag;
1710   myCStructure->TransformPersistence.Point.x = float (thePoint.X());
1711   myCStructure->TransformPersistence.Point.y = float (thePoint.Y());
1712   myCStructure->TransformPersistence.Point.z = float (thePoint.Z());
1713   myCStructure->UpdateAspects();
1714   CalculateBoundBox();
1715
1716   myCStructure->TransformPersistence.IsSet = 1;
1717 }
1718
1719 //=============================================================================
1720 //function : TransformPersistenceMode
1721 //purpose  :
1722 //=============================================================================
1723 Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1724 {
1725   return myCStructure->TransformPersistence.Flag;
1726 }
1727
1728 //=============================================================================
1729 //function : TransformPersistencePoint
1730 //purpose  :
1731 //=============================================================================
1732 gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const
1733 {
1734   gp_Pnt aPnt (0.0, 0.0, 0.0);
1735   aPnt.SetX (myCStructure->TransformPersistence.Point.x);
1736   aPnt.SetY (myCStructure->TransformPersistence.Point.y);
1737   aPnt.SetZ (myCStructure->TransformPersistence.Point.z);
1738   return aPnt;
1739 }
1740
1741 //=============================================================================
1742 //function : Remove
1743 //purpose  :
1744 //=============================================================================
1745 void Graphic3d_Structure::Remove (const Standard_Address           thePtr,
1746                                   const Graphic3d_TypeOfConnection theType)
1747 {
1748   switch (theType)
1749   {
1750     case Graphic3d_TOC_DESCENDANT:
1751     {
1752       const Standard_Integer aNbDesc = myDescendants.Length();
1753       for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1754       {
1755         if (myDescendants.Value (anIter) == thePtr)
1756         {
1757           myDescendants.Remove (anIter);
1758           return;
1759         }
1760       }
1761       break;
1762     }
1763     case Graphic3d_TOC_ANCESTOR:
1764     {
1765       const Standard_Integer aNbAncestors = myAncestors.Length();
1766       for (Standard_Integer anIter = 1; anIter <= aNbAncestors; ++anIter)
1767       {
1768         if (myAncestors.Value (anIter) == thePtr)
1769         {
1770           myAncestors.Remove (anIter);
1771           return;
1772         }
1773       }
1774       break;
1775     }
1776   }
1777 }
1778
1779 //=============================================================================
1780 //function : NewGroup
1781 //purpose  :
1782 //=============================================================================
1783 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
1784 {
1785   return myCStructure->NewGroup (this);
1786 }
1787
1788 //=============================================================================
1789 //function : Remove
1790 //purpose  :
1791 //=============================================================================
1792 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1793 {
1794   if (theGroup.IsNull()
1795    || theGroup->myStructure != this)
1796   {
1797     return;
1798   }
1799
1800   myCStructure->RemoveGroup (theGroup);
1801   theGroup->myStructure = NULL;
1802 }
1803
1804 //=============================================================================
1805 //function : StructureManager
1806 //purpose  :
1807 //=============================================================================
1808 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1809 {
1810   return myStructureManager;
1811 }
1812
1813 //=============================================================================
1814 //function : minMaxCoord
1815 //purpose  :
1816 //=============================================================================
1817 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord (const Standard_Boolean theToIgnoreInfiniteFlag) const
1818 {
1819   Graphic3d_BndBox4f aBnd;
1820   for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1821   {
1822     if (!theToIgnoreInfiniteFlag)
1823     {
1824       aBnd.Combine (aGroupIter.Value()->BoundingBox());
1825     }
1826     else
1827     {
1828       Graphic3d_BndBox4f aValidBnd (aGroupIter.Value()->BoundingBox().CornerMin(),
1829                                     aGroupIter.Value()->BoundingBox().CornerMax());
1830       aBnd.Combine (aValidBnd);
1831     }
1832   }
1833   return aBnd;
1834 }
1835
1836 //=============================================================================
1837 //function : addTransformed
1838 //purpose  :
1839 //=============================================================================
1840 void Graphic3d_Structure::getBox (Graphic3d_BndBox4d&    theBox,
1841                                   const Standard_Boolean theToIgnoreInfiniteFlag) const
1842 {
1843   Graphic3d_BndBox4f aBoxF = minMaxCoord (theToIgnoreInfiniteFlag);
1844   if (aBoxF.IsValid())
1845   {
1846     theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMin().x(),
1847                                                   (Standard_Real )aBoxF.CornerMin().y(),
1848                                                   (Standard_Real )aBoxF.CornerMin().z(),
1849                                                   (Standard_Real )aBoxF.CornerMin().w()),
1850                                  Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMax().x(),
1851                                                   (Standard_Real )aBoxF.CornerMax().y(),
1852                                                   (Standard_Real )aBoxF.CornerMax().z(),
1853                                                   (Standard_Real )aBoxF.CornerMax().w()));
1854     if (IsInfinite()
1855     && !theToIgnoreInfiniteFlag)
1856     {
1857       const Graphic3d_Vec4d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
1858       if (aDiagVec.xyz().SquareModulus() >= 500000.0 * 500000.0)
1859       {
1860         // bounding borders of infinite line has been calculated as own point in center of this line
1861         theBox = Graphic3d_BndBox4d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
1862       }
1863       else
1864       {
1865         theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d (RealFirst(), RealFirst(), RealFirst(), 1.0),
1866                                      Graphic3d_Vec4d (RealLast(),  RealLast(),  RealLast(),  1.0));
1867         return;
1868       }
1869     }
1870   }
1871 }
1872
1873 //=============================================================================
1874 //function : addTransformed
1875 //purpose  :
1876 //=============================================================================
1877 void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d&    theBox,
1878                                           const Standard_Boolean theToIgnoreInfiniteFlag) const
1879 {
1880   Graphic3d_BndBox4d aCombinedBox, aBox;
1881   getBox (aCombinedBox, theToIgnoreInfiniteFlag);
1882
1883   for (Standard_Integer aStructIt = 1; aStructIt <= myDescendants.Length(); ++aStructIt)
1884   {
1885     const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )myDescendants.Value (aStructIt);
1886     aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1887     aCombinedBox.Combine (aBox);
1888   }
1889
1890   aBox = aCombinedBox;
1891   if (aBox.IsValid())
1892   {
1893     TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1894     Transform (aTrsf);
1895     TransformBoundaries (aTrsf, aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1896                                 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1897
1898     // if box is still valid after transformation
1899     if (aBox.IsValid())
1900     {
1901       theBox.Combine (aBox);
1902     }
1903     else // it was infinite, return untransformed
1904     {
1905       theBox.Combine (aCombinedBox);
1906     }
1907   }
1908 }
1909
1910 //=============================================================================
1911 //function : Transforms
1912 //purpose  :
1913 //=============================================================================
1914 void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1915                                       const Standard_Real theX,    const Standard_Real theY,    const Standard_Real theZ,
1916                                       Standard_Real&      theNewX, Standard_Real&      theNewY, Standard_Real&      theNewZ)
1917 {
1918   const Standard_Real aRL = RealLast();
1919   const Standard_Real aRF = RealFirst();
1920   if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1921    || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1922   {
1923     theNewX = theX;
1924     theNewY = theY;
1925     theNewZ = theZ;
1926   }
1927   else
1928   {
1929     Standard_Real A, B, C, D;
1930     A       = theTrsf (0, 0);
1931     B       = theTrsf (0, 1);
1932     C       = theTrsf (0, 2);
1933     D       = theTrsf (0, 3);
1934     theNewX = A * theX + B * theY + C * theZ + D;
1935     A       = theTrsf (1, 0);
1936     B       = theTrsf (1, 1);
1937     C       = theTrsf (1, 2);
1938     D       = theTrsf (1, 3);
1939     theNewY = A * theX + B * theY + C * theZ + D;
1940     A       = theTrsf (2, 0);
1941     B       = theTrsf (2, 1);
1942     C       = theTrsf (2, 2);
1943     D       = theTrsf (2, 3);
1944     theNewZ = A * theX + B * theY + C * theZ + D;
1945   }
1946 }
1947
1948 //=============================================================================
1949 //function : Transforms
1950 //purpose  :
1951 //=============================================================================
1952 Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1953                                                   const Graphic3d_Vector&     theCoord)
1954 {
1955   Standard_Real anXYZ[3];
1956   Graphic3d_Structure::Transforms (theTrsf,
1957                                    theCoord.X(), theCoord.Y(), theCoord.Z(),
1958                                    anXYZ[0], anXYZ[1], anXYZ[2]);
1959   return Graphic3d_Vector (anXYZ[0], anXYZ[1], anXYZ[2]);
1960 }
1961
1962 //=============================================================================
1963 //function : Transforms
1964 //purpose  :
1965 //=============================================================================
1966 Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1967                                                   const Graphic3d_Vertex&     theCoord)
1968 {
1969   Standard_Real anXYZ[3];
1970   Graphic3d_Structure::Transforms (theTrsf,
1971                                    theCoord.X(), theCoord.Y(), theCoord.Z(),
1972                                    anXYZ[0], anXYZ[1], anXYZ[2]);
1973   return Graphic3d_Vertex (anXYZ[0], anXYZ[1], anXYZ[2]);
1974 }
1975
1976 //=============================================================================
1977 //function : Transforms
1978 //purpose  :
1979 //=============================================================================
1980 void Graphic3d_Structure::TransformBoundaries (const TColStd_Array2OfReal& theTrsf,
1981                                                Standard_Real& theXMin,
1982                                                Standard_Real& theYMin,
1983                                                Standard_Real& theZMin,
1984                                                Standard_Real& theXMax,
1985                                                Standard_Real& theYMax,
1986                                                Standard_Real& theZMax)
1987 {
1988   Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1989
1990   Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1991   Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1992
1993   Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, 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, theXMax, theYMin, theZMax, 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   Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
2004   aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2005   aYMin = Min (aV,  aYMin); aYMax = Max (aV,  aYMax);
2006   aZMin = Min (aW,  aZMin); aZMax = Max (aW,  aZMax);
2007
2008   Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
2009   aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2010   aYMin = Min (aV,  aYMin); aYMax = Max (aV,  aYMax);
2011   aZMin = Min (aW,  aZMin); aZMax = Max (aW,  aZMax);
2012
2013   Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
2014   aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2015   aYMin = Min (aV,  aYMin); aYMax = Max (aV,  aYMax);
2016   aZMin = Min (aW,  aZMin); aZMax = Max (aW,  aZMax);
2017
2018   Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
2019   aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2020   aYMin = Min (aV,  aYMin); aYMax = Max (aV,  aYMax);
2021   aZMin = Min (aW,  aZMin); aZMax = Max (aW,  aZMax);
2022
2023   theXMin = aXMin;
2024   theYMin = aYMin;
2025   theZMin = aZMin;
2026   theXMax = aXMax;
2027   theYMax = aYMax;
2028   theZMax = aZMax;
2029 }
2030
2031 //=============================================================================
2032 //function : Network
2033 //purpose  :
2034 //=============================================================================
2035 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
2036                                    const Graphic3d_TypeOfConnection   theType,
2037                                    Graphic3d_MapOfStructure&          theSet)
2038 {
2039   Graphic3d_MapOfStructure aSetD, aSetA;
2040   theStructure->Descendants (aSetD);
2041   theStructure->Ancestors   (aSetA);
2042   theSet.Add (theStructure);
2043   switch (theType)
2044   {
2045     case Graphic3d_TOC_DESCENDANT:
2046       for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
2047       {
2048         Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
2049       }
2050       break;
2051     case Graphic3d_TOC_ANCESTOR:
2052       for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
2053       {
2054         Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
2055       }
2056       break;
2057   }
2058 }
2059
2060 //=============================================================================
2061 //function : PrintNetwork
2062 //purpose  :
2063 //=============================================================================
2064 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
2065                                         const Graphic3d_TypeOfConnection   theType)
2066 {
2067   Graphic3d_MapOfStructure aSet;
2068   Graphic3d_Structure::Network (theStructure, theType, aSet);
2069   for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
2070   {
2071     std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
2072   }
2073   std::cout << std::flush;
2074 }
2075
2076 //=============================================================================
2077 //function : Update
2078 //purpose  :
2079 //=============================================================================
2080 void Graphic3d_Structure::Update() const
2081 {
2082   if (IsDeleted())
2083   {
2084     return;
2085   }
2086
2087   if (myStructureManager->UpdateMode() == Aspect_TOU_ASAP)
2088   {
2089     myStructureManager->Update();
2090   }
2091 }
2092
2093 //=============================================================================
2094 //function : UpdateStructure
2095 //purpose  :
2096 //=============================================================================
2097 void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)&     theAspLine,
2098                                            const Handle(Graphic3d_AspectText3d)&     theAspText,
2099                                            const Handle(Graphic3d_AspectMarker3d)&   theAspMarker,
2100                                            const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
2101 {
2102   Standard_CString          aFont;
2103   Standard_Real             aSpace, anExpansion, aWidth, aScale;
2104   Quantity_Color            aColor, anIntColor, aBackIntColor, anEdgeColor, aColorSub;
2105   Aspect_TypeOfLine         aLType;
2106   Aspect_TypeOfMarker       aMType;
2107   Aspect_InteriorStyle      aStyle;
2108   Aspect_TypeOfStyleText    aStyleT;
2109   Aspect_TypeOfDisplayText  aDisplayType;
2110   Standard_Boolean          aTextZoomable;
2111   Standard_Real             aTextAngle;
2112   Font_FontAspect           aTextFontAspect;
2113
2114   theAspLine->Values (aColor, aLType, aWidth);
2115   myCStructure->ContextLine.Color.r        = float (aColor.Red());
2116   myCStructure->ContextLine.Color.g        = float (aColor.Green());
2117   myCStructure->ContextLine.Color.b        = float (aColor.Blue());
2118   myCStructure->ContextLine.LineType       = aLType;
2119   myCStructure->ContextLine.Width          = float (aWidth);
2120   myCStructure->ContextLine.ShaderProgram  = theAspLine->ShaderProgram();
2121
2122   theAspMarker->Values (aColor, aMType, aScale);
2123   myCStructure->ContextMarker.Color.r      = float (aColor.Red());
2124   myCStructure->ContextMarker.Color.g      = float (aColor.Green());
2125   myCStructure->ContextMarker.Color.b      = float (aColor.Blue());
2126   myCStructure->ContextMarker.MarkerType   = aMType;
2127   myCStructure->ContextMarker.Scale        = float (aScale);
2128   myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
2129
2130   theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyleT, aDisplayType, aColorSub, aTextZoomable, aTextAngle, aTextFontAspect);
2131   myCStructure->ContextText.Color.r          = float (aColor.Red());
2132   myCStructure->ContextText.Color.g          = float (aColor.Green());
2133   myCStructure->ContextText.Color.b          = float (aColor.Blue());
2134   myCStructure->ContextText.Font             = aFont;
2135   myCStructure->ContextText.Expan            = float (anExpansion);
2136   myCStructure->ContextText.Style            = aStyleT;
2137   myCStructure->ContextText.DisplayType      = aDisplayType;
2138   myCStructure->ContextText.Space            = float (aSpace);
2139   myCStructure->ContextText.ColorSubTitle.r  = float (aColorSub.Red());
2140   myCStructure->ContextText.ColorSubTitle.g  = float (aColorSub.Green());
2141   myCStructure->ContextText.ColorSubTitle.b  = float (aColorSub.Blue());
2142   myCStructure->ContextText.TextZoomable     = aTextZoomable;
2143   myCStructure->ContextText.TextAngle        = float (aTextAngle);
2144   myCStructure->ContextText.TextFontAspect   = aTextFontAspect;
2145   myCStructure->ContextText.ShaderProgram    = theAspText->ShaderProgram();
2146
2147   Standard_Real anRGB[3];
2148   theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
2149   anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2150   myCStructure->ContextFillArea.Style      = aStyle;
2151   myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
2152   myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
2153   myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
2154
2155   if (theAspFill->Distinguish())
2156   {
2157     aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2158   }
2159   myCStructure->ContextFillArea.BackIntColor.r = float (anRGB[0]);
2160   myCStructure->ContextFillArea.BackIntColor.g = float (anRGB[1]);
2161   myCStructure->ContextFillArea.BackIntColor.b = float (anRGB[2]);
2162
2163   // Edges
2164   myCStructure->ContextFillArea.Edge               = theAspFill->Edge () ? 1:0;
2165   myCStructure->ContextFillArea.EdgeColor.r        = float (anEdgeColor.Red());
2166   myCStructure->ContextFillArea.EdgeColor.g        = float (anEdgeColor.Green());
2167   myCStructure->ContextFillArea.EdgeColor.b        = float (anEdgeColor.Blue());
2168   myCStructure->ContextFillArea.LineType           = aLType;
2169   myCStructure->ContextFillArea.Width              = float (aWidth);
2170   myCStructure->ContextFillArea.Hatch              = theAspFill->HatchStyle();
2171
2172   // Front and Back face
2173   myCStructure->ContextFillArea.Distinguish        = theAspFill->Distinguish() ? 1 : 0;
2174   myCStructure->ContextFillArea.BackFace           = theAspFill->BackFace()    ? 1 : 0;
2175   // Back Material
2176   const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
2177   // Light specificity
2178   myCStructure->ContextFillArea.Back.Shininess     = float (aBack.Shininess());
2179   myCStructure->ContextFillArea.Back.Ambient       = float (aBack.Ambient());
2180   myCStructure->ContextFillArea.Back.Diffuse       = float (aBack.Diffuse());
2181   myCStructure->ContextFillArea.Back.Specular      = float (aBack.Specular());
2182   myCStructure->ContextFillArea.Back.Transparency  = float (aBack.Transparency());
2183   myCStructure->ContextFillArea.Back.Emission      = float (aBack.Emissive());
2184
2185   // Reflection mode
2186   myCStructure->ContextFillArea.Back.IsAmbient     = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT)  ? 1 : 0);
2187   myCStructure->ContextFillArea.Back.IsDiffuse     = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE)  ? 1 : 0);
2188   myCStructure->ContextFillArea.Back.IsSpecular    = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2189   myCStructure->ContextFillArea.Back.IsEmission    = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2190
2191   // Material type
2192   myCStructure->ContextFillArea.Back.IsPhysic      = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2193
2194   // Specular color
2195   myCStructure->ContextFillArea.Back.ColorSpec.r   = float (aBack.SpecularColor().Red());
2196   myCStructure->ContextFillArea.Back.ColorSpec.g   = float (aBack.SpecularColor().Green());
2197   myCStructure->ContextFillArea.Back.ColorSpec.b   = float (aBack.SpecularColor().Blue());
2198
2199   // Ambient color
2200   myCStructure->ContextFillArea.Back.ColorAmb.r    = float (aBack.AmbientColor().Red());
2201   myCStructure->ContextFillArea.Back.ColorAmb.g    = float (aBack.AmbientColor().Green());
2202   myCStructure->ContextFillArea.Back.ColorAmb.b    = float (aBack.AmbientColor().Blue());
2203
2204   // Diffuse color
2205   myCStructure->ContextFillArea.Back.ColorDif.r    = float (aBack.DiffuseColor().Red());
2206   myCStructure->ContextFillArea.Back.ColorDif.g    = float (aBack.DiffuseColor().Green());
2207   myCStructure->ContextFillArea.Back.ColorDif.b    = float (aBack.DiffuseColor().Blue());
2208
2209   // Emissive color
2210   myCStructure->ContextFillArea.Back.ColorEms.r    = float (aBack.EmissiveColor().Red());
2211   myCStructure->ContextFillArea.Back.ColorEms.g    = float (aBack.EmissiveColor().Green());
2212   myCStructure->ContextFillArea.Back.ColorEms.b    = float (aBack.EmissiveColor().Blue());
2213
2214   myCStructure->ContextFillArea.Back.EnvReflexion  = float (aBack.EnvReflexion());
2215
2216   // Front Material
2217   const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
2218   // Light specificity
2219   myCStructure->ContextFillArea.Front.Shininess    = float (aFront.Shininess());
2220   myCStructure->ContextFillArea.Front.Ambient      = float (aFront.Ambient());
2221   myCStructure->ContextFillArea.Front.Diffuse      = float (aFront.Diffuse());
2222   myCStructure->ContextFillArea.Front.Specular     = float (aFront.Specular());
2223   myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
2224   myCStructure->ContextFillArea.Front.Emission     = float (aFront.Emissive());
2225
2226   // Reflection mode
2227   myCStructure->ContextFillArea.Front.IsAmbient    = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT)  ? 1 : 0);
2228   myCStructure->ContextFillArea.Front.IsDiffuse    = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE)  ? 1 : 0);
2229   myCStructure->ContextFillArea.Front.IsSpecular   = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2230   myCStructure->ContextFillArea.Front.IsEmission   = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2231
2232   // Material type
2233   myCStructure->ContextFillArea.Front.IsPhysic     = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2234
2235   // Specular color
2236   myCStructure->ContextFillArea.Front.ColorSpec.r  = float (aFront.SpecularColor().Red());
2237   myCStructure->ContextFillArea.Front.ColorSpec.g  = float (aFront.SpecularColor().Green());
2238   myCStructure->ContextFillArea.Front.ColorSpec.b  = float (aFront.SpecularColor().Blue());
2239
2240   // Ambient color
2241   myCStructure->ContextFillArea.Front.ColorAmb.r   = float (aFront.AmbientColor().Red());
2242   myCStructure->ContextFillArea.Front.ColorAmb.g   = float (aFront.AmbientColor().Green());
2243   myCStructure->ContextFillArea.Front.ColorAmb.b   = float (aFront.AmbientColor().Blue());
2244
2245   // Diffuse color
2246   myCStructure->ContextFillArea.Front.ColorDif.r   = float (aFront.DiffuseColor().Red());
2247   myCStructure->ContextFillArea.Front.ColorDif.g   = float (aFront.DiffuseColor().Green());
2248   myCStructure->ContextFillArea.Front.ColorDif.b   = float (aFront.DiffuseColor().Blue());
2249
2250   // Emissive color
2251   myCStructure->ContextFillArea.Front.ColorEms.r   = float (aFront.EmissiveColor().Red());
2252   myCStructure->ContextFillArea.Front.ColorEms.g   = float (aFront.EmissiveColor().Green());
2253   myCStructure->ContextFillArea.Front.ColorEms.b   = float (aFront.EmissiveColor().Blue());
2254
2255   myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
2256
2257   myCStructure->ContextFillArea.Texture.TextureMap   = theAspFill->TextureMap();
2258   myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
2259   myCStructure->ContextFillArea.ShaderProgram        = theAspFill->ShaderProgram();
2260
2261   Standard_Integer   aPolyMode;
2262   Standard_ShortReal aPolyFactor, aPolyUnits;
2263   theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
2264   myCStructure->ContextFillArea.PolygonOffsetMode   = aPolyMode;
2265   myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
2266   myCStructure->ContextFillArea.PolygonOffsetUnits  = aPolyUnits;
2267 }
2268
2269 //=============================================================================
2270 //function : GraphicHighlight
2271 //purpose  :
2272 //=============================================================================
2273 void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod theMethod)
2274 {
2275   Standard_Real anRGB[3];
2276   myCStructure->highlight = 1;
2277   myHighlightMethod = theMethod;
2278   switch (theMethod)
2279   {
2280     case Aspect_TOHM_COLOR:
2281     {
2282       myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2283       myCStructure->HighlightWithColor (Graphic3d_Vec3 (float (anRGB[0]), float (anRGB[1]), float (anRGB[2])), Standard_True);
2284       myCStructure->UpdateNamedStatus();
2285       break;
2286     }
2287     case Aspect_TOHM_BOUNDBOX:
2288     {
2289       myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2290       myCStructure->HighlightColor.r = float (anRGB[0]);
2291       myCStructure->HighlightColor.g = float (anRGB[1]);
2292       myCStructure->HighlightColor.b = float (anRGB[2]);
2293       myCStructure->HighlightWithBndBox (this, Standard_True);
2294       break;
2295     }
2296   }
2297 }
2298
2299 //=============================================================================
2300 //function : GraphicTransform
2301 //purpose  :
2302 //=============================================================================
2303 void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& theMatrix)
2304 {
2305   for (Standard_Integer i = 0; i <= 3; ++i)
2306   {
2307     for (Standard_Integer j = 0; j <= 3; ++j)
2308     {
2309       myCStructure->Transformation[i][j] = float (theMatrix (i, j));
2310     }
2311   }
2312   myCStructure->UpdateTransformation();
2313 }
2314
2315 //=============================================================================
2316 //function : GraphicUnHighlight
2317 //purpose  :
2318 //=============================================================================
2319 void Graphic3d_Structure::GraphicUnHighlight()
2320 {
2321   myCStructure->highlight = 0;
2322   switch (myHighlightMethod)
2323   {
2324     case Aspect_TOHM_COLOR:
2325       myCStructure->HighlightWithColor (Graphic3d_Vec3 (0.0f, 0.0f, 0.0f), Standard_False);
2326       myCStructure->UpdateNamedStatus();
2327       break;
2328     case Aspect_TOHM_BOUNDBOX:
2329       myCStructure->HighlightWithBndBox (this, Standard_False);
2330       myCStructure->UpdateNamedStatus();
2331       break;
2332   }
2333 }
2334
2335 //=============================================================================
2336 //function : ComputeVisual
2337 //purpose  :
2338 //=============================================================================
2339 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
2340 {
2341   return myComputeVisual;
2342 }
2343
2344 //=============================================================================
2345 //function : SetComputeVisual
2346 //purpose  :
2347 //=============================================================================
2348 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
2349 {
2350   // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
2351   // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
2352   if (theVisual != Graphic3d_TOS_COMPUTED)
2353   {
2354     myComputeVisual = theVisual;
2355   }
2356 }
2357
2358 //=============================================================================
2359 //function : SetHLRValidation
2360 //purpose  :
2361 //=============================================================================
2362 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
2363 {
2364   myCStructure->HLRValidation = theFlag ? 1 : 0;
2365 }
2366
2367 //=============================================================================
2368 //function : HLRValidation
2369 //purpose  :
2370 //=============================================================================
2371 Standard_Boolean Graphic3d_Structure::HLRValidation() const
2372 {
2373   // Hidden parts stored in <me> are valid if :
2374   // 1/ the owner is defined.
2375   // 2/ they are not invalid.
2376   return myOwner != NULL
2377       && myCStructure->HLRValidation != 0;
2378 }
2379
2380 //=======================================================================
2381 //function : SetZLayer
2382 //purpose  :
2383 //=======================================================================
2384 void Graphic3d_Structure::SetZLayer (const Standard_Integer theLayerId)
2385 {
2386   // if the structure is not displayed, unable to change its display layer
2387   if (IsDeleted ())
2388     return;
2389
2390   myStructureManager->ChangeZLayer (this, theLayerId);
2391 }
2392
2393 //=======================================================================
2394 //function : GetZLayer
2395 //purpose  :
2396 //=======================================================================
2397 Standard_Integer Graphic3d_Structure::GetZLayer () const
2398 {
2399   return myStructureManager->GetZLayer (this);
2400 }
2401
2402 //=======================================================================
2403 //function : SetClipPlanes
2404 //purpose  :
2405 //=======================================================================
2406 void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
2407 {
2408   myCStructure->SetClipPlanes (thePlanes);
2409 }
2410
2411 //=======================================================================
2412 //function : GetClipPlanes
2413 //purpose  :
2414 //=======================================================================
2415 const Graphic3d_SequenceOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const
2416 {
2417   return myCStructure->ClipPlanes();
2418 }
2419
2420 //=======================================================================
2421 //function : SetMutable
2422 //purpose  :
2423 //=======================================================================
2424 void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
2425 {
2426   myCStructure->IsMutable = theIsMutable;
2427 }
2428
2429 //=======================================================================
2430 //function : IsMutable
2431 //purpose  :
2432 //=======================================================================
2433 Standard_Boolean Graphic3d_Structure::IsMutable() const
2434 {
2435   return myCStructure->IsMutable;
2436 }