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