1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Graphic3d_Structure.ixx>
17 #include <Graphic3d_Structure.pxx>
19 #include <Graphic3d_GraphicDriver.hxx>
20 #include <Graphic3d_MaterialAspect.hxx>
22 #include <Graphic3d_MapOfStructure.hxx>
23 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
25 #include <Quantity_Color.hxx>
26 #include <TColStd_Array2OfReal.hxx>
27 #include <Graphic3d_TextureMap.hxx>
29 #include <Aspect_PolygonOffsetMode.hxx>
33 //=============================================================================
34 //function : Graphic3d_Structure
36 //=============================================================================
37 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager)
38 : myStructureManager (theManager.operator->()),
39 myFirstStructureManager (theManager.operator->()),
40 myComputeVisual (Graphic3d_TOS_ALL),
41 myHighlightColor (Quantity_NOC_WHITE),
42 myHighlightMethod (Aspect_TOHM_COLOR),
44 myVisual (Graphic3d_TOS_ALL)
46 myCStructure = theManager->GraphicDriver()->Structure (theManager);
49 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
50 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
51 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
52 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
53 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
54 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
56 // update the associated CStructure
57 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
60 //=============================================================================
61 //function : Graphic3d_Structure
63 //=============================================================================
64 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
65 const Handle(Graphic3d_Structure)& thePrs)
66 : myStructureManager (theManager.operator->()),
67 myFirstStructureManager (theManager.operator->()),
68 myComputeVisual (thePrs->myComputeVisual),
69 myHighlightColor (thePrs->myHighlightColor),
70 myHighlightMethod (thePrs->myHighlightMethod),
71 myOwner (thePrs->myOwner),
72 myVisual (thePrs->myVisual)
74 myCStructure = thePrs->myCStructure->ShadowLink (theManager);
77 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
78 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
79 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
80 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
81 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
82 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
84 // update the associated CStructure
85 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
88 //=============================================================================
91 //=============================================================================
92 void Graphic3d_Structure::Destroy()
94 // as myFirstStructureManager can be already destroyed,
95 // avoid attempts to access it
96 myFirstStructureManager = NULL;
100 //=============================================================================
103 //=============================================================================
104 void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
106 if (IsDeleted()) return;
108 // clean groups in graphics driver at first
109 GraphicClear (theWithDestruction);
111 myCStructure->ContainsFacet = 0;
112 myStructureManager->Clear (this, theWithDestruction);
117 //=============================================================================
120 //=============================================================================
121 void Graphic3d_Structure::Remove()
123 if (IsDeleted()) return;
125 // clean groups in graphics driver at first; this is also should be done
126 // to avoid unwanted group cleaning in group's destructor
127 // Pass Standard_False to Clear(..) method to avoid updating in
128 // structure manager, it isn't necessary, besides of it structure manager
129 // could be already destroyed and invalid pointers used in structure;
130 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
132 aGroupIter.ChangeValue()->Clear (Standard_False);
135 Standard_Address APtr = (void *) this;
136 // It is necessary to remove the eventual pointer on the structure
137 // that can be destroyed, in the list of descendants
138 // of ancestors of this structure and in the list of ancestors
139 // of descendants of the same structure.
141 const Standard_Integer aNbDesc = myDescendants.Length();
142 for (Standard_Integer aStructIter = 1; aStructIter <= aNbDesc; ++aStructIter)
144 ((Graphic3d_Structure *)(myDescendants.ChangeValue (aStructIter)))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
147 const Standard_Integer aNbAnces = myAncestors.Length();
148 for (Standard_Integer aStructIter = 1; aStructIter <= aNbAnces; ++aStructIter)
150 ((Graphic3d_Structure *)(myAncestors.ChangeValue (aStructIter)))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
153 myCStructure->ContainsFacet = 0;
155 // Destruction of me in the graphic library
156 const Standard_Integer aStructId = myCStructure->Id;
157 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
158 myCStructure.Nullify();
160 // Liberation of the identification if the destroyed structure
161 // in the first manager that performs creation of the structure.
162 if (myFirstStructureManager != NULL)
164 myFirstStructureManager->Remove (aStructId);
168 //=============================================================================
171 //=============================================================================
172 void Graphic3d_Structure::Display()
174 if (IsDeleted()) return;
176 if (!myCStructure->stick)
178 myCStructure->stick = 1;
179 myStructureManager->Display (this);
182 myCStructure->visible = 1;
185 //=============================================================================
188 //=============================================================================
189 void Graphic3d_Structure::Display (const Standard_Integer thePriority)
191 if (IsDeleted()) return;
193 SetDisplayPriority (thePriority);
195 if (!myCStructure->stick)
197 myCStructure->stick = 1;
198 myStructureManager->Display (this);
201 myCStructure->visible = 1;
204 //=============================================================================
205 //function : SetDisplayPriority
207 //=============================================================================
208 void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
211 || thePriority == myCStructure->Priority)
216 myCStructure->PreviousPriority = myCStructure->Priority;
217 myCStructure->Priority = thePriority;
219 if (myCStructure->Priority != myCStructure->PreviousPriority)
221 Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
222 || (myCStructure->Priority < Structure_MIN_PRIORITY),
223 "Bad value for StructurePriority");
224 if (myCStructure->stick)
226 myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
231 //=============================================================================
232 //function : ResetDisplayPriority
234 //=============================================================================
235 void Graphic3d_Structure::ResetDisplayPriority()
238 || myCStructure->Priority == myCStructure->PreviousPriority)
243 const Standard_Integer aPriority = myCStructure->Priority;
244 myCStructure->Priority = myCStructure->PreviousPriority;
245 if (myCStructure->stick)
247 myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
251 //=============================================================================
252 //function : DisplayPriority
254 //=============================================================================
255 Standard_Integer Graphic3d_Structure::DisplayPriority() const
257 return myCStructure->Priority;
260 //=============================================================================
263 //=============================================================================
264 void Graphic3d_Structure::Erase()
271 if (myCStructure->stick)
273 myCStructure->stick = 0;
274 myStructureManager->Erase (this);
278 //=============================================================================
279 //function : Highlight
281 //=============================================================================
282 void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod theMethod)
289 // Highlight on already Highlighted structure.
290 if (myCStructure->highlight)
292 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
293 if (anUpdateMode == Aspect_TOU_WAIT)
299 // To avoid call of method : Update()
300 // Not useful and can be costly.
301 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
303 myStructureManager->SetUpdateMode (anUpdateMode);
307 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
309 GraphicHighlight (theMethod);
310 if (myCStructure->stick)
312 myStructureManager->Highlight (this, theMethod);
318 //=============================================================================
319 //function : SetHighlightColor
321 //=============================================================================
322 void Graphic3d_Structure::SetHighlightColor (const Quantity_Color& theColor)
329 if (!myCStructure->highlight)
331 myHighlightColor = theColor;
335 // Change highlight color on already Highlighted structure.
336 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
337 if (anUpdateMode == Aspect_TOU_WAIT)
343 // To avoid call of method : Update()
344 // Not useful and can be costly.
345 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
347 myStructureManager->SetUpdateMode (anUpdateMode);
349 myHighlightColor = theColor;
350 Highlight (myHighlightMethod);
353 //=============================================================================
354 //function : SetVisible
356 //=============================================================================
357 void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
359 if (IsDeleted()) return;
361 myCStructure->visible = theValue ? 1 : 0;
362 myCStructure->UpdateNamedStatus();
366 //=============================================================================
369 //=============================================================================
370 void Graphic3d_Structure::SetPick (const Standard_Boolean theValue)
372 if (IsDeleted ()) return;
374 myCStructure->pick = theValue ? 1 : 0;
375 myCStructure->UpdateNamedStatus();
379 myStructureManager->Detectable (this);
383 myStructureManager->Undetectable (this);
388 //=============================================================================
389 //function : UnHighlight
391 //=============================================================================
392 void Graphic3d_Structure::UnHighlight()
394 if (IsDeleted()) return;
396 if (myCStructure->highlight)
398 myCStructure->highlight = 0;
400 GraphicUnHighlight();
401 myStructureManager->UnHighlight (this);
403 ResetDisplayPriority();
408 //=============================================================================
409 //function : HighlightColor
411 //=============================================================================
412 const Quantity_Color& Graphic3d_Structure::HighlightColor() const
414 return myHighlightColor;
417 //=============================================================================
418 //function : IsDisplayed
420 //=============================================================================
421 Standard_Boolean Graphic3d_Structure::IsDisplayed() const
423 return myCStructure->stick ? Standard_True : Standard_False;
426 //=============================================================================
427 //function : IsDeleted
429 //=============================================================================
430 Standard_Boolean Graphic3d_Structure::IsDeleted() const
432 return myCStructure.IsNull();
435 //=============================================================================
436 //function : IsHighlighted
438 //=============================================================================
439 Standard_Boolean Graphic3d_Structure::IsHighlighted() const
441 return myCStructure->highlight ? Standard_True : Standard_False;
444 //=============================================================================
445 //function : IsSelectable
447 //=============================================================================
448 Standard_Boolean Graphic3d_Structure::IsSelectable() const
450 return myCStructure->pick ? Standard_True : Standard_False;
453 //=============================================================================
454 //function : IsVisible
456 //=============================================================================
457 Standard_Boolean Graphic3d_Structure::IsVisible() const
459 return myCStructure->visible ? Standard_True : Standard_False;
462 //=============================================================================
463 //function : IsRotated
465 //=============================================================================
466 Standard_Boolean Graphic3d_Structure::IsRotated() const
468 // A somewhat light test !
469 return myCStructure->Transformation[0][1] != 0.0
470 || myCStructure->Transformation[0][2] != 0.0
471 || myCStructure->Transformation[1][0] != 0.0
472 || myCStructure->Transformation[1][2] != 0.0
473 || myCStructure->Transformation[2][0] != 0.0
474 || myCStructure->Transformation[2][1] != 0.0;
477 //=============================================================================
478 //function : IsTransformed
480 //=============================================================================
481 Standard_Boolean Graphic3d_Structure::IsTransformed() const
483 Standard_Boolean aResult = Standard_False;
484 for (Standard_Integer i = 0; i <= 3 && !aResult; ++i)
486 for (Standard_Integer j = 0; j <= 3 && !aResult; ++j)
489 aResult = myCStructure->Transformation[i][j] != 1.0;
491 aResult = myCStructure->Transformation[i][j] != 0.0;
497 //=============================================================================
498 //function : ContainsFacet
500 //=============================================================================
501 Standard_Boolean Graphic3d_Structure::ContainsFacet() const
505 return Standard_False;
507 else if (myCStructure->ContainsFacet > 0)
509 // if one of groups contains at least one facet, the structure contains it too
510 return Standard_True;
513 // stop at the first descendant containing at least one facet
514 const Standard_Integer aNbDesc = myDescendants.Length();
515 for (Standard_Integer aStructIter = 1; aStructIter <= aNbDesc; ++aStructIter)
517 if (((const Graphic3d_Structure *)(myDescendants.Value (aStructIter)))->ContainsFacet())
519 return Standard_True;
522 return Standard_False;
525 //=============================================================================
528 //=============================================================================
529 Standard_Boolean Graphic3d_Structure::IsEmpty() const
533 return Standard_True;
536 // structure is empty:
537 // - if all these groups are empty
538 // - or if all groups are empty and all their descendants are empty
539 // - or if all its descendants are empty
540 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
542 if (!aGroupIter.Value()->IsEmpty())
544 return Standard_False;
548 // stop at the first non-empty descendant
549 const Standard_Integer aNbDesc = myDescendants.Length();
550 for (Standard_Integer aDescIter = 1; aDescIter <= aNbDesc; ++aDescIter)
552 if (!((const Graphic3d_Structure* )(myDescendants.Value (aDescIter)))->IsEmpty())
554 return Standard_False;
557 return Standard_True;
560 //=============================================================================
561 //function : PrimitivesAspect
563 //=============================================================================
564 void Graphic3d_Structure::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& theAspLine,
565 Handle(Graphic3d_AspectText3d)& theAspText,
566 Handle(Graphic3d_AspectMarker3d)& theAspMarker,
567 Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
569 theAspLine = Line3dAspect();
570 theAspText = Text3dAspect();
571 theAspMarker = Marker3dAspect();
572 theAspFill = FillArea3dAspect();
575 //=============================================================================
576 //function : GroupsWithFacet
578 //=============================================================================
579 void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
581 myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
582 if (myCStructure->ContainsFacet < 0)
584 myCStructure->ContainsFacet = 0;
588 //=============================================================================
591 //=============================================================================
592 void Graphic3d_Structure::Compute()
594 // Implemented by Presentation
597 //=============================================================================
600 //=============================================================================
601 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
603 // Implemented by Presentation
607 //=============================================================================
610 //=============================================================================
611 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
612 const TColStd_Array2OfReal& )
614 // Implemented by Presentation
618 //=============================================================================
621 //=============================================================================
622 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
623 Handle(Graphic3d_Structure)& )
625 // Implemented by Presentation
628 //=============================================================================
631 //=============================================================================
632 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
633 const TColStd_Array2OfReal& ,
634 Handle(Graphic3d_Structure)& )
636 // Implemented by Presentation
639 //=============================================================================
640 //function : ReCompute
642 //=============================================================================
643 void Graphic3d_Structure::ReCompute()
645 myStructureManager->ReCompute (this);
648 //=============================================================================
649 //function : ReCompute
651 //=============================================================================
652 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
654 myStructureManager->ReCompute (this, theProjector);
657 //=============================================================================
658 //function : SetInfiniteState
660 //=============================================================================
661 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
663 myCStructure->IsInfinite = theToSet ? 1 : 0;
666 //=============================================================================
667 //function : IsInfinite
669 //=============================================================================
670 Standard_Boolean Graphic3d_Structure::IsInfinite() const
673 || myCStructure->IsInfinite;
676 //=============================================================================
677 //function : GraphicClear
679 //=============================================================================
680 void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
682 if (myCStructure.IsNull())
687 // clean and empty each group
688 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
690 aGroupIter.ChangeValue()->Clear();
692 if (!theWithDestruction)
697 while (!myCStructure->Groups().IsEmpty())
699 Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
702 myCStructure->Clear();
705 //=============================================================================
706 //function : GraphicConnect
708 //=============================================================================
709 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
711 myCStructure->Connect (*theDaughter->myCStructure);
714 //=============================================================================
715 //function : GraphicDisconnect
717 //=============================================================================
718 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
720 myCStructure->Disconnect (*theDaughter->myCStructure);
723 //=============================================================================
724 //function : Line3dAspect
726 //=============================================================================
727 Handle(Graphic3d_AspectLine3d) Graphic3d_Structure::Line3dAspect() const
729 const Standard_Real anRGB[3] =
731 Standard_Real (myCStructure->ContextLine.Color.r),
732 Standard_Real (myCStructure->ContextLine.Color.g),
733 Standard_Real (myCStructure->ContextLine.Color.b)
735 Quantity_Color aColor;
736 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
737 Aspect_TypeOfLine aLType = Aspect_TypeOfLine (myCStructure->ContextLine.LineType);
738 Standard_Real aWidth = Standard_Real (myCStructure->ContextLine.Width);
740 Handle(Graphic3d_AspectLine3d) anAspLine = new Graphic3d_AspectLine3d (aColor, aLType, aWidth);
741 anAspLine->SetShaderProgram (myCStructure->ContextLine.ShaderProgram);
745 //=============================================================================
746 //function : Text3dAspect
748 //=============================================================================
749 Handle(Graphic3d_AspectText3d) Graphic3d_Structure::Text3dAspect() const
751 const Standard_Real anRGB[3] =
753 Standard_Real (myCStructure->ContextText.Color.r),
754 Standard_Real (myCStructure->ContextText.Color.g),
755 Standard_Real (myCStructure->ContextText.Color.b)
757 Quantity_Color aColor;
758 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
759 Standard_CString aFont = Standard_CString (myCStructure->ContextText.Font);
760 Standard_Real anExpansion = Standard_Real (myCStructure->ContextText.Expan);
761 Standard_Real aSpace = Standard_Real (myCStructure->ContextText.Space);
762 Aspect_TypeOfStyleText aStyle = Aspect_TypeOfStyleText (myCStructure->ContextText.Style);
763 Aspect_TypeOfDisplayText aDispType = Aspect_TypeOfDisplayText (myCStructure->ContextText.DisplayType);
765 Handle(Graphic3d_AspectText3d) anAspText = new Graphic3d_AspectText3d (aColor, aFont, anExpansion, aSpace, aStyle, aDispType);
766 anAspText->SetShaderProgram (myCStructure->ContextText.ShaderProgram);
770 //=============================================================================
771 //function : Marker3dAspect
773 //=============================================================================
774 Handle(Graphic3d_AspectMarker3d) Graphic3d_Structure::Marker3dAspect() const
776 const Standard_Real anRGB[3] =
778 Standard_Real (myCStructure->ContextMarker.Color.r),
779 Standard_Real (myCStructure->ContextMarker.Color.g),
780 Standard_Real (myCStructure->ContextMarker.Color.b)
782 Quantity_Color aColor;
783 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
784 Aspect_TypeOfMarker aMType = myCStructure->ContextMarker.MarkerType;
785 Standard_Real aScale = Standard_Real (myCStructure->ContextMarker.Scale);
787 Handle(Graphic3d_AspectMarker3d) anAspMarker = new Graphic3d_AspectMarker3d (aMType, aColor, aScale);
788 anAspMarker->SetShaderProgram (myCStructure->ContextMarker.ShaderProgram);
792 //=============================================================================
793 //function : FillArea3dAspect
795 //=============================================================================
796 Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect() const
799 Graphic3d_MaterialAspect aBack;
800 aBack.SetShininess (Standard_Real (myCStructure->ContextFillArea.Back.Shininess));
801 aBack.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Back.Ambient));
802 aBack.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Back.Diffuse));
803 aBack.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Back.Specular));
804 aBack.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Back.Transparency));
805 aBack.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Back.Emission));
806 if (myCStructure->ContextFillArea.Back.IsAmbient == 1)
807 aBack.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
809 aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
810 if (myCStructure->ContextFillArea.Back.IsDiffuse == 1)
811 aBack.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
813 aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
814 if (myCStructure->ContextFillArea.Back.IsSpecular == 1)
815 aBack.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
817 aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
818 if (myCStructure->ContextFillArea.Back.IsEmission == 1)
819 aBack.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
821 aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
823 Quantity_Color aColor (Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.r),
824 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.g),
825 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.b), Quantity_TOC_RGB);
826 aBack.SetSpecularColor (aColor);
828 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.r),
829 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.g),
830 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.b), Quantity_TOC_RGB);
831 aBack.SetAmbientColor (aColor);
833 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.r),
834 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.g),
835 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.b), Quantity_TOC_RGB);
836 aBack.SetDiffuseColor (aColor);
838 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.r),
839 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.g),
840 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.b), Quantity_TOC_RGB);
841 aBack.SetEmissiveColor (aColor);
843 aBack.SetEnvReflexion (myCStructure->ContextFillArea.Back.EnvReflexion);
844 aBack.SetMaterialType (myCStructure->ContextFillArea.Back.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
847 Graphic3d_MaterialAspect aFront;
848 aFront.SetShininess (Standard_Real (myCStructure->ContextFillArea.Front.Shininess));
849 aFront.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Front.Ambient));
850 aFront.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Front.Diffuse));
851 aFront.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Front.Specular));
852 aFront.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Front.Transparency));
853 aFront.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Front.Emission));
854 if (myCStructure->ContextFillArea.Front.IsAmbient == 1)
855 aFront.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
857 aFront.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
858 if (myCStructure->ContextFillArea.Front.IsDiffuse == 1)
859 aFront.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
861 aFront.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
862 if (myCStructure->ContextFillArea.Front.IsSpecular == 1)
863 aFront.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
865 aFront.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
866 if (myCStructure->ContextFillArea.Front.Emission == 1)
867 aFront.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
869 aFront.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
871 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.r),
872 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.g),
873 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.b), Quantity_TOC_RGB);
874 aFront.SetSpecularColor (aColor);
876 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.r),
877 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.g),
878 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.b), Quantity_TOC_RGB);
879 aFront.SetAmbientColor (aColor);
881 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.r),
882 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.g),
883 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.b), Quantity_TOC_RGB);
884 aFront.SetDiffuseColor (aColor);
886 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.r),
887 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.g),
888 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.b), Quantity_TOC_RGB);
889 aFront.SetEmissiveColor (aColor);
891 aFront.SetEnvReflexion (myCStructure->ContextFillArea.Front.EnvReflexion);
892 aFront.SetMaterialType (myCStructure->ContextFillArea.Front.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
894 Quantity_Color anIntColor (Standard_Real (myCStructure->ContextFillArea.IntColor.r),
895 Standard_Real (myCStructure->ContextFillArea.IntColor.g),
896 Standard_Real (myCStructure->ContextFillArea.IntColor.b), Quantity_TOC_RGB);
897 Quantity_Color anEdgeColor (Standard_Real (myCStructure->ContextFillArea.EdgeColor.r),
898 Standard_Real (myCStructure->ContextFillArea.EdgeColor.g),
899 Standard_Real (myCStructure->ContextFillArea.EdgeColor.b), Quantity_TOC_RGB);
900 Handle(Graphic3d_AspectFillArea3d) anAspFill = new Graphic3d_AspectFillArea3d (Aspect_InteriorStyle (myCStructure->ContextFillArea.Style),
901 anIntColor, anEdgeColor,
902 Aspect_TypeOfLine (myCStructure->ContextFillArea.LineType),
903 Standard_Real (myCStructure->ContextFillArea.Width),
907 if (myCStructure->ContextFillArea.Edge == 1)
908 anAspFill->SetEdgeOn();
910 anAspFill->SetEdgeOff();
912 anAspFill->SetHatchStyle (Aspect_HatchStyle (myCStructure->ContextFillArea.Hatch));
914 // Front and Back face
915 if (myCStructure->ContextFillArea.Distinguish == 1)
916 anAspFill->SetDistinguishOn();
918 anAspFill->SetDistinguishOff();
919 if (myCStructure->ContextFillArea.BackFace == 1)
920 anAspFill->SuppressBackFace();
922 anAspFill->AllowBackFace();
924 anAspFill->SetTextureMap (myCStructure->ContextFillArea.Texture.TextureMap);
925 if (myCStructure->ContextFillArea.Texture.doTextureMap == 1)
927 anAspFill->SetTextureMapOn();
931 anAspFill->SetTextureMapOff();
933 anAspFill->SetShaderProgram (myCStructure->ContextFillArea.ShaderProgram);
934 anAspFill->SetPolygonOffsets (myCStructure->ContextFillArea.PolygonOffsetMode,
935 myCStructure->ContextFillArea.PolygonOffsetFactor,
936 myCStructure->ContextFillArea.PolygonOffsetUnits);
940 //=============================================================================
943 //=============================================================================
944 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
946 return myCStructure->Groups();
949 //=============================================================================
950 //function : NumberOfGroups
952 //=============================================================================
953 Standard_Integer Graphic3d_Structure::NumberOfGroups() const
955 return myCStructure->Groups().Length();
958 //=============================================================================
959 //function : SetPrimitivesAspect
961 //=============================================================================
962 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
964 if (IsDeleted()) return;
966 Standard_Real aWidth;
967 Quantity_Color aColor;
968 Aspect_TypeOfLine aLType;
969 theAspLine->Values (aColor, aLType, aWidth);
971 myCStructure->ContextLine.Color.r = float (aColor.Red());
972 myCStructure->ContextLine.Color.g = float (aColor.Green());
973 myCStructure->ContextLine.Color.b = float (aColor.Blue());
974 myCStructure->ContextLine.LineType = int (aLType);
975 myCStructure->ContextLine.Width = float (aWidth);
976 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
977 myCStructure->ContextLine.IsDef = 1;
979 myCStructure->UpdateAspects();
981 // Attributes are "IsSet" during the first update of context (line, marker...)
982 myCStructure->ContextLine.IsSet = 1;
983 myCStructure->ContextFillArea.IsSet = 1;
984 myCStructure->ContextMarker.IsSet = 1;
985 myCStructure->ContextText.IsSet = 1;
990 //=============================================================================
991 //function : SetPrimitivesAspect
993 //=============================================================================
994 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
996 if (IsDeleted()) return;
998 Standard_Real anRGB[3];
999 Standard_Real aWidth;
1000 Quantity_Color anIntColor;
1001 Quantity_Color aBackIntColor;
1002 Quantity_Color anEdgeColor;
1003 Aspect_TypeOfLine aLType;
1004 Aspect_InteriorStyle aStyle;
1005 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
1007 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
1008 myCStructure->ContextFillArea.Style = aStyle;
1009 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
1010 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
1011 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
1013 if (theAspFill->Distinguish())
1015 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
1017 myCStructure->ContextFillArea.BackIntColor.r = float(anRGB[0]);
1018 myCStructure->ContextFillArea.BackIntColor.g = float(anRGB[1]);
1019 myCStructure->ContextFillArea.BackIntColor.b = float(anRGB[2]);
1022 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1 : 0;
1023 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
1024 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
1025 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
1026 myCStructure->ContextFillArea.LineType = aLType;
1027 myCStructure->ContextFillArea.Width = float (aWidth);
1028 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
1030 // Front and Back face
1031 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
1032 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
1035 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
1036 // Light specificity
1037 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
1038 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
1039 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
1040 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
1041 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
1042 myCStructure->ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
1043 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
1046 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1047 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1048 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1049 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1053 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0 );
1056 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
1057 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
1058 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
1061 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
1062 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
1063 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
1066 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
1067 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
1068 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
1071 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
1072 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
1073 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
1075 myCStructure->ContextFillArea.Back.EnvReflexion =
1076 float ((theAspFill->BackMaterial ()).EnvReflexion());
1079 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
1080 // Light specificity
1081 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
1082 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
1083 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
1084 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
1085 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
1086 myCStructure->ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
1087 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
1090 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1091 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1092 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1093 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1097 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
1100 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
1101 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
1102 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
1105 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
1106 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
1107 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
1110 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
1111 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
1112 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
1115 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
1116 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
1117 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
1119 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
1121 myCStructure->ContextFillArea.IsDef = 1; // Definition material ok
1123 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
1124 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
1125 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
1127 Standard_Integer aPolyMode;
1128 Standard_ShortReal aPolyFactor, aPolyUnits;
1129 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
1130 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
1131 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
1132 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
1134 myCStructure->UpdateAspects();
1136 // Attributes are "IsSet" during the first update of context (line, marker...)
1137 myCStructure->ContextLine.IsSet = 1;
1138 myCStructure->ContextFillArea.IsSet = 1;
1139 myCStructure->ContextMarker.IsSet = 1;
1140 myCStructure->ContextText.IsSet = 1;
1145 //=============================================================================
1146 //function : SetPrimitivesAspect
1148 //=============================================================================
1149 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
1151 if (IsDeleted()) return;
1153 Standard_CString aFont;
1154 Standard_Real aSpace, anExpansion, aTextAngle;
1155 Quantity_Color aColor, aColorSub;
1156 Aspect_TypeOfStyleText aStyle;
1157 Aspect_TypeOfDisplayText aDispType;
1158 Standard_Boolean isTextZoomable;
1159 Font_FontAspect aTextFontAspect;
1160 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDispType, aColorSub, isTextZoomable, aTextAngle, aTextFontAspect);
1162 myCStructure->ContextText.Color.r = float (aColor.Red());
1163 myCStructure->ContextText.Color.g = float (aColor.Green());
1164 myCStructure->ContextText.Color.b = float (aColor.Blue());
1165 myCStructure->ContextText.Font = aFont;
1166 myCStructure->ContextText.Expan = float (anExpansion);
1167 myCStructure->ContextText.Space = float (aSpace);
1168 myCStructure->ContextText.Style = aStyle;
1169 myCStructure->ContextText.DisplayType = aDispType;
1170 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
1171 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
1172 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
1173 myCStructure->ContextText.TextZoomable = isTextZoomable;
1174 myCStructure->ContextText.TextAngle = float (aTextAngle);
1175 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
1176 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
1178 myCStructure->ContextText.IsDef = 1;
1180 myCStructure->UpdateAspects();
1182 // Attributes are "IsSet" during the first update of a context (line, marker...)
1183 myCStructure->ContextLine.IsSet = 1;
1184 myCStructure->ContextFillArea.IsSet = 1;
1185 myCStructure->ContextMarker.IsSet = 1;
1186 myCStructure->ContextText.IsSet = 1;
1191 //=============================================================================
1192 //function : SetPrimitivesAspect
1194 //=============================================================================
1195 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
1197 if (IsDeleted()) return;
1199 Standard_Real aScale;
1200 Quantity_Color aColor;
1201 Aspect_TypeOfMarker aMType;
1202 theAspMarker->Values (aColor, aMType, aScale);
1204 myCStructure->ContextMarker.Color.r = float (aColor.Red());
1205 myCStructure->ContextMarker.Color.g = float (aColor.Green());
1206 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
1207 myCStructure->ContextMarker.MarkerType = aMType;
1208 myCStructure->ContextMarker.Scale = float (aScale);
1209 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
1210 myCStructure->ContextMarker.IsDef = 1;
1212 myCStructure->UpdateAspects();
1214 // Attributes are "IsSet" during the first update of a context (line, marker...)
1215 myCStructure->ContextLine.IsSet = 1;
1216 myCStructure->ContextFillArea.IsSet = 1;
1217 myCStructure->ContextMarker.IsSet = 1;
1218 myCStructure->ContextText.IsSet = 1;
1223 //=============================================================================
1224 //function : SetVisual
1226 //=============================================================================
1227 void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
1230 || myVisual == theVisual)
1235 if (!myCStructure->stick)
1237 myVisual = theVisual;
1238 SetComputeVisual (theVisual);
1242 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
1243 if (anUpdateMode == Aspect_TOU_WAIT)
1246 myVisual = theVisual;
1247 SetComputeVisual (theVisual);
1251 // To avoid calling method : Update ()
1252 // Not useful and can be costly.
1253 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
1255 myVisual = theVisual;
1256 SetComputeVisual (theVisual);
1257 myStructureManager->SetUpdateMode (anUpdateMode);
1263 //=============================================================================
1264 //function : SetZoomLimit
1266 //=============================================================================
1267 void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
1268 const Standard_Real theLimitSup)
1272 Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
1273 "Bad value for ZoomLimit inf");
1274 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
1275 "Bad value for ZoomLimit sup");
1276 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
1277 "ZoomLimit sup < ZoomLimit inf");
1280 //=============================================================================
1283 //=============================================================================
1284 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
1289 //=============================================================================
1290 //function : AcceptConnection
1292 //=============================================================================
1293 Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
1294 const Handle(Graphic3d_Structure)& theStructure2,
1295 const Graphic3d_TypeOfConnection theType)
1298 Graphic3d_MapOfStructure aSet;
1299 Graphic3d_Structure::Network (theStructure2, theType, aSet);
1300 return !aSet.Contains (theStructure1);
1303 //=============================================================================
1304 //function : Ancestors
1306 //=============================================================================
1307 void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
1309 const Standard_Integer aNbAnces = myAncestors.Length ();
1310 for (Standard_Integer anIter = 1; anIter <= aNbAnces; ++anIter)
1312 theSet.Add ((Graphic3d_Structure* )(myAncestors.Value (anIter)));
1316 //=============================================================================
1317 //function : SetOwner
1319 //=============================================================================
1320 void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
1325 //=============================================================================
1328 //=============================================================================
1329 Standard_Address Graphic3d_Structure::Owner() const
1334 //=============================================================================
1335 //function : Descendants
1337 //=============================================================================
1338 void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
1340 const Standard_Integer aNbDesc = myDescendants.Length ();
1341 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1343 theSet.Add ((Graphic3d_Structure* )(myDescendants.Value (anIter)));
1347 //=============================================================================
1348 //function : Connect
1350 //=============================================================================
1351 void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
1352 const Graphic3d_TypeOfConnection theType,
1353 const Standard_Boolean theWithCheck)
1355 if (IsDeleted()) return;
1359 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
1366 case Graphic3d_TOC_DESCENDANT:
1368 const Standard_Integer aNbDesc = myDescendants.Length();
1369 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1371 if (myDescendants.Value (anIter) == theStructure.operator->())
1377 myDescendants.Append (theStructure.operator->());
1378 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
1380 GraphicConnect (theStructure);
1381 myStructureManager->Connect (this, theStructure);
1386 case Graphic3d_TOC_ANCESTOR:
1388 const Standard_Integer aNbAnces = myAncestors.Length();
1389 for (Standard_Integer anIter = 1; anIter <= aNbAnces; ++anIter)
1391 if (myAncestors.Value (anIter) == theStructure.operator->())
1397 myAncestors.Append (theStructure.operator->());
1398 theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
1400 // myGraphicDriver->Connect is called in case if connection between parent and child
1406 //=============================================================================
1407 //function : Disconnect
1409 //=============================================================================
1410 void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
1412 if (IsDeleted()) return;
1414 const Standard_Integer aNbDesc = myDescendants.Length();
1415 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1417 if (myDescendants.Value (anIter) == theStructure.operator->())
1419 myDescendants.Remove (anIter);
1420 theStructure->Disconnect (this);
1422 GraphicDisconnect (theStructure);
1423 myStructureManager->Disconnect (this, theStructure);
1430 const Standard_Integer aNbAnces = myAncestors.Length();
1431 for (Standard_Integer anIter = 1; anIter <= aNbAnces; ++anIter)
1433 if (myAncestors.Value (anIter) == theStructure.operator->())
1435 myAncestors.Remove (anIter);
1436 theStructure->Disconnect (this);
1437 // no call of myGraphicDriver->Disconnect in case of an ancestor
1443 //=============================================================================
1444 //function : DisconnectAll
1446 //=============================================================================
1447 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
1449 if (IsDeleted()) return;
1453 case Graphic3d_TOC_DESCENDANT:
1455 const Standard_Integer aLength = myDescendants.Length();
1456 for (Standard_Integer anIter = 1; anIter <= aLength; ++anIter)
1458 // Value (1) instead of Value (i) as myDescendants
1460 // Graphic3d_Structure::Disconnect (AStructure)
1461 // that takes AStructure from myDescendants
1462 ((Graphic3d_Structure* )(myDescendants.Value (1)))->Disconnect (this);
1466 case Graphic3d_TOC_ANCESTOR:
1468 const Standard_Integer aLength = myAncestors.Length();
1469 for (Standard_Integer anIter = 1; anIter <= aLength; ++anIter)
1471 // Value (1) instead of Value (i) as myAncestors
1473 // Graphic3d_Structure::Disconnect (AStructure)
1474 // that takes AStructure from myAncestors
1475 ((Graphic3d_Structure* )(myAncestors.Value (1)))->Disconnect (this);
1482 //=============================================================================
1483 //function : Composition
1485 //=============================================================================
1486 Graphic3d_TypeOfComposition Graphic3d_Structure::Composition() const
1488 return myCStructure->Composition;
1491 //=============================================================================
1492 //function : SetTransform
1494 //=============================================================================
1495 void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& theMatrix,
1496 const Graphic3d_TypeOfComposition theType)
1498 if (IsDeleted()) return;
1500 Standard_Real valuetrsf;
1501 Standard_Real valueoldtrsf;
1502 Standard_Real valuenewtrsf;
1503 TColStd_Array2OfReal aNewTrsf (0, 3, 0, 3);
1504 TColStd_Array2OfReal aMatrix44 (0, 3, 0, 3);
1506 // Assign the new transformation in an array [0..3][0..3]
1507 // Avoid problemes if the user has defined matrice [1..4][1..4]
1508 // or [3..6][-1..2] !!
1509 Standard_Integer lr = theMatrix.LowerRow();
1510 Standard_Integer ur = theMatrix.UpperRow();
1511 Standard_Integer lc = theMatrix.LowerCol();
1512 Standard_Integer uc = theMatrix.UpperCol();
1514 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1516 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1521 case Graphic3d_TOC_REPLACE:
1523 myCStructure->Composition = Graphic3d_TOC_REPLACE;
1524 // Update of CStructure
1525 for (Standard_Integer i = 0; i <= 3; ++i)
1527 for (Standard_Integer j = 0; j <= 3; ++j)
1529 myCStructure->Transformation[i][j] = float (theMatrix (lr + i, lc + j));
1530 aNewTrsf (i, j) = theMatrix (lr + i, lc + j);
1535 case Graphic3d_TOC_POSTCONCATENATE:
1537 myCStructure->Composition = Graphic3d_TOC_POSTCONCATENATE;
1538 // To simplify management of indices
1539 for (Standard_Integer i = 0; i <= 3; ++i)
1541 for (Standard_Integer j = 0; j <= 3; ++j)
1543 aMatrix44 (i, j) = theMatrix (lr + i, lc + j);
1547 // Calculation of the product of matrices
1548 for (Standard_Integer i = 0; i <= 3; ++i)
1550 for (Standard_Integer j = 0; j <= 3; ++j)
1552 aNewTrsf (i, j) = 0.0;
1553 for (Standard_Integer k = 0; k <= 3; ++k)
1555 valueoldtrsf = myCStructure->Transformation[i][k];
1556 valuetrsf = aMatrix44 (k, j);
1557 valuenewtrsf = aNewTrsf (i, j) + valueoldtrsf * valuetrsf;
1558 aNewTrsf (i, j) = valuenewtrsf;
1563 // Update of CStructure
1564 for (Standard_Integer i = 0; i <= 3; ++i)
1566 for (Standard_Integer j = 0; j <= 3; ++j)
1568 myCStructure->Transformation[i][j] = float (aNewTrsf (i, j));
1575 // If transformation, no validation of hidden already calculated parts
1581 GraphicTransform (aNewTrsf);
1582 myStructureManager->SetTransform (this, aNewTrsf);
1587 //=============================================================================
1588 //function : Transform
1590 //=============================================================================
1591 void Graphic3d_Structure::Transform (TColStd_Array2OfReal& theMatrix) const
1594 Standard_Integer lr = theMatrix.LowerRow ();
1595 Standard_Integer ur = theMatrix.UpperRow ();
1596 Standard_Integer lc = theMatrix.LowerCol ();
1597 Standard_Integer uc = theMatrix.UpperCol ();
1599 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1600 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1602 for (Standard_Integer i = 0; i <= 3; ++i)
1604 for (Standard_Integer j = 0; j <= 3; ++j)
1606 theMatrix (lr + i, lc + j) = myCStructure->Transformation[i][j];
1611 //=============================================================================
1612 //function : MinMaxValues
1614 //=============================================================================
1615 void Graphic3d_Structure::MinMaxValues (Standard_Real& theXMin,
1616 Standard_Real& theYMin,
1617 Standard_Real& theZMin,
1618 Standard_Real& theXMax,
1619 Standard_Real& theYMax,
1620 Standard_Real& theZMax,
1621 const Standard_Boolean theToIgnoreInfiniteFlag) const
1628 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
1629 MinMaxCoord (aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
1631 // Infinite boundaries corresponding to empty structure or
1632 // non-empty structure, without any primitives specified
1633 if (aXMin == RealFirst() && aYMin == RealFirst() && aZMin == RealFirst() &&
1634 aXMax == RealLast() && aYMax == RealLast() && aZMax == RealLast())
1636 theXMin = RealFirst();
1637 theYMin = RealFirst();
1638 theZMin = RealFirst();
1639 theXMax = RealLast();
1640 theYMax = RealLast();
1641 theZMax = RealLast();
1645 // Handle flag, which specifies that structure should be considered as infinite
1646 if (IsInfinite() && !theToIgnoreInfiniteFlag)
1648 Graphic3d_Vertex aVertexMin (aXMin, aYMin, aZMin);
1649 Graphic3d_Vertex aVertexMax (aXMax, aYMax, aZMax);
1650 const Standard_Real aDistance = aVertexMin.Distance (aVertexMax);
1652 // Special case for infinite line:
1653 // Bounding borders of infinite line has been
1654 // calculated as own point in center of this line
1655 if (aDistance >= 500000.0)
1657 theXMin = theXMax = 0.5 * (aXMin + aXMax);
1658 theYMin = theYMax = 0.5 * (aYMin + aYMax);
1659 theZMin = theZMax = 0.5 * (aZMin + aZMax);
1663 theXMin = RealFirst();
1664 theYMin = RealFirst();
1665 theZMin = RealFirst();
1666 theXMax = RealLast();
1667 theYMax = RealLast();
1668 theZMax = RealLast();
1672 // Min-Max values of the descendant structures
1673 Standard_Real aDescXMin = RealLast();
1674 Standard_Real aDescYMin = RealLast();
1675 Standard_Real aDescZMin = RealLast();
1676 Standard_Real aDescXMax = RealFirst();
1677 Standard_Real aDescYMax = RealFirst();
1678 Standard_Real aDescZMax = RealFirst();
1679 for (Standard_Integer aStructIt = 1; aStructIt <= myDescendants.Length(); aStructIt++)
1681 Graphic3d_Structure* aStructure = (Graphic3d_Structure*) myDescendants.Value (aStructIt);
1682 aStructure->MinMaxValues (aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
1683 aDescXMin = Min (aXMin, aDescXMin);
1684 aDescYMin = Min (aYMin, aDescYMin);
1685 aDescZMin = Min (aZMin, aDescZMin);
1686 aDescXMax = Max (aXMax, aDescXMax);
1687 aDescYMax = Max (aYMax, aDescYMax);
1688 aDescZMax = Max (aZMax, aDescZMax);
1691 if (aDescXMin != RealLast() || aDescYMin != RealLast() ||
1692 aDescZMin != RealLast() || aDescXMax != RealFirst() ||
1693 aDescYMax != RealFirst() || aDescZMax != RealFirst())
1695 aXMin = Min (aDescXMin, aXMin);
1696 aYMin = Min (aDescYMin, aYMin);
1697 aZMin = Min (aDescZMin, aZMin);
1698 aXMax = Max (aDescXMax, aXMax);
1699 aYMax = Max (aDescYMax, aYMax);
1700 aZMax = Max (aDescZMax, aZMax);
1703 // Case impossible as it would mean that the structure is empty or infinite
1704 if (aXMin == RealFirst() && aYMin == RealFirst() && aZMin == RealFirst() &&
1705 aXMax == RealLast() && aYMax == RealLast() && aZMax == RealLast())
1707 theXMin = RealFirst();
1708 theYMin = RealFirst();
1709 theZMin = RealFirst();
1710 theXMax = RealLast();
1711 theYMax = RealLast();
1712 theZMax = RealLast();
1716 TColStd_Array2OfReal aTrsf(0, 3, 0, 3);
1718 TransformBoundaries (aTrsf, aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
1727 //=============================================================================
1728 //function : Identification
1730 //=============================================================================
1731 Standard_Integer Graphic3d_Structure::Identification() const
1733 return myCStructure->Id;
1736 //=============================================================================
1737 //function : SetTransformPersistence
1739 //=============================================================================
1740 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag)
1742 SetTransformPersistence (theFlag, gp_Pnt (0.0, 0.0, 0.0));
1745 //=============================================================================
1746 //function : SetTransformPersistence
1748 //=============================================================================
1749 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
1750 const gp_Pnt& thePoint)
1752 if (IsDeleted()) return;
1754 myCStructure->TransformPersistence.Flag = theFlag;
1755 myCStructure->TransformPersistence.Point.x = float (thePoint.X());
1756 myCStructure->TransformPersistence.Point.y = float (thePoint.Y());
1757 myCStructure->TransformPersistence.Point.z = float (thePoint.Z());
1758 myCStructure->UpdateAspects();
1760 myCStructure->TransformPersistence.IsSet = 1;
1763 //=============================================================================
1764 //function : TransformPersistenceMode
1766 //=============================================================================
1767 Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1769 return myCStructure->TransformPersistence.Flag;
1772 //=============================================================================
1773 //function : TransformPersistencePoint
1775 //=============================================================================
1776 gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const
1778 gp_Pnt aPnt (0.0, 0.0, 0.0);
1779 aPnt.SetX (myCStructure->TransformPersistence.Point.x);
1780 aPnt.SetY (myCStructure->TransformPersistence.Point.y);
1781 aPnt.SetZ (myCStructure->TransformPersistence.Point.z);
1785 //=============================================================================
1788 //=============================================================================
1789 void Graphic3d_Structure::Remove (const Standard_Address thePtr,
1790 const Graphic3d_TypeOfConnection theType)
1794 case Graphic3d_TOC_DESCENDANT:
1796 const Standard_Integer aNbDesc = myDescendants.Length();
1797 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1799 if (myDescendants.Value (anIter) == thePtr)
1801 myDescendants.Remove (anIter);
1807 case Graphic3d_TOC_ANCESTOR:
1809 const Standard_Integer aNbAncestors = myAncestors.Length();
1810 for (Standard_Integer anIter = 1; anIter <= aNbAncestors; ++anIter)
1812 if (myAncestors.Value (anIter) == thePtr)
1814 myAncestors.Remove (anIter);
1823 //=============================================================================
1824 //function : NewGroup
1826 //=============================================================================
1827 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
1829 return myCStructure->NewGroup (this);
1832 //=============================================================================
1835 //=============================================================================
1836 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1838 if (theGroup.IsNull()
1839 || theGroup->myStructure != this)
1844 myCStructure->RemoveGroup (theGroup);
1845 theGroup->myStructure = NULL;
1848 //=============================================================================
1849 //function : StructureManager
1851 //=============================================================================
1852 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1854 return myStructureManager;
1857 //=============================================================================
1858 //function : MinMaxCoord
1860 //=============================================================================
1861 void Graphic3d_Structure::MinMaxCoord (Standard_Real& theXMin,
1862 Standard_Real& theYMin,
1863 Standard_Real& theZMin,
1864 Standard_Real& theXMax,
1865 Standard_Real& theYMax,
1866 Standard_Real& theZMax) const
1870 theXMin = RealFirst();
1871 theYMin = RealFirst();
1872 theZMin = RealFirst();
1873 theXMax = RealLast();
1874 theYMax = RealLast();
1875 theZMax = RealLast();
1879 Standard_Real aXMin = RealLast();
1880 Standard_Real aYMin = RealLast();
1881 Standard_Real aZMin = RealLast();
1882 Standard_Real aXMax = RealFirst();
1883 Standard_Real aYMax = RealFirst();
1884 Standard_Real aZMax = RealFirst();
1885 Standard_Real aGroupXMin, aGroupYMin, aGroupZMin, aGroupXMax, aGroupYMax, aGroupZMax;
1886 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1888 const Handle(Graphic3d_Group)& aGroup = aGroupIter.Value();
1889 if (aGroup->IsEmpty())
1894 aGroup->MinMaxValues (aGroupXMin, aGroupYMin, aGroupZMin, aGroupXMax, aGroupYMax, aGroupZMax);
1895 aXMin = Min (aXMin, aGroupXMin);
1896 aYMin = Min (aYMin, aGroupYMin);
1897 aZMin = Min (aZMin, aGroupZMin);
1898 aXMax = Max (aXMax, aGroupXMax);
1899 aYMax = Max (aYMax, aGroupYMax);
1900 aZMax = Max (aZMax, aGroupZMax);
1903 // Case impossible as it would mean that the structure is empty
1904 if (aXMin == RealLast() && aYMin == RealLast() && aZMin == RealLast() &&
1905 aXMax == RealFirst() && aYMax == RealFirst() && aZMax == RealFirst())
1907 theXMin = RealFirst();
1908 theYMin = RealFirst();
1909 theZMin = RealFirst();
1910 theXMax = RealLast();
1911 theYMax = RealLast();
1912 theZMax = RealLast();
1923 //=============================================================================
1924 //function : MinMaxCoordWithDescendants
1926 //=============================================================================
1927 void Graphic3d_Structure::MinMaxCoordWithDescendants (Standard_Real& theXMin,
1928 Standard_Real& theYMin,
1929 Standard_Real& theZMin,
1930 Standard_Real& theXMax,
1931 Standard_Real& theYMax,
1932 Standard_Real& theZMax) const
1936 theXMin = RealFirst();
1937 theYMin = RealFirst();
1938 theZMin = RealFirst();
1939 theXMax = RealLast();
1940 theYMax = RealLast();
1941 theZMax = RealLast();
1945 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
1946 MinMaxCoord (aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
1948 // Min-Max of the descendant structures
1949 Standard_Real aDescXMin = RealLast();
1950 Standard_Real aDescYMin = RealLast();
1951 Standard_Real aDescZMin = RealLast();
1952 Standard_Real aDescXMax = RealFirst();
1953 Standard_Real aDescYMax = RealFirst();
1954 Standard_Real aDescZMax = RealFirst();
1955 for (Standard_Integer aStructIt = 1; aStructIt <= myDescendants.Length(); aStructIt++)
1957 Graphic3d_Structure* aStructure = (Graphic3d_Structure*) myDescendants.Value (aStructIt);
1958 if (aStructure->IsEmpty())
1963 aStructure->MinMaxCoordWithDescendants (aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
1964 aDescXMin = Min (aXMin, aDescXMin);
1965 aDescYMin = Min (aYMin, aDescYMin);
1966 aDescZMin = Min (aZMin, aDescZMin);
1967 aDescXMax = Max (aXMax, aDescXMax);
1968 aDescYMax = Max (aYMax, aDescYMax);
1969 aDescZMax = Max (aZMax, aDescZMax);
1972 if (aDescXMin != RealLast() || aDescYMin != RealLast() ||
1973 aDescZMin != RealLast() || aDescXMax != RealFirst() ||
1974 aDescYMax != RealFirst() || aDescZMax != RealFirst())
1976 TColStd_Array2OfReal aTrsf(0, 3, 0, 3);
1978 TransformBoundaries (aTrsf, aDescXMin, aDescYMin, aDescZMin, aDescXMax, aDescYMax, aDescZMax);
1980 aXMin = Min (aDescXMin, aXMin);
1981 aYMin = Min (aDescYMin, aYMin);
1982 aZMin = Min (aDescZMin, aZMin);
1983 aXMax = Max (aDescXMax, aXMax);
1984 aYMax = Max (aDescYMax, aYMax);
1985 aZMax = Max (aDescZMax, aZMax);
1988 // Case impossible as it would mean that the structure is empty
1989 if (aXMin == RealLast() && aYMin == RealLast() && aZMin == RealLast() &&
1990 aXMax == RealFirst() && aYMax == RealFirst() && aZMax == RealFirst())
1992 theXMin = RealFirst();
1993 theYMin = RealFirst();
1994 theZMin = RealFirst();
1995 theXMax = RealLast();
1996 theYMax = RealLast();
1997 theZMax = RealLast();
2008 //=============================================================================
2009 //function : Transforms
2011 //=============================================================================
2012 void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
2013 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
2014 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ)
2016 const Standard_Real aRL = RealLast();
2017 const Standard_Real aRF = RealFirst();
2018 if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
2019 || (theX == aRL) || (theY == aRL) || (theZ == aRL))
2027 Standard_Real A, B, C, D;
2032 theNewX = A * theX + B * theY + C * theZ + D;
2037 theNewY = A * theX + B * theY + C * theZ + D;
2042 theNewZ = A * theX + B * theY + C * theZ + D;
2046 //=============================================================================
2047 //function : Transforms
2049 //=============================================================================
2050 Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
2051 const Graphic3d_Vector& theCoord)
2053 Standard_Real anXYZ[3];
2054 Graphic3d_Structure::Transforms (theTrsf,
2055 theCoord.X(), theCoord.Y(), theCoord.Z(),
2056 anXYZ[0], anXYZ[1], anXYZ[2]);
2057 return Graphic3d_Vector (anXYZ[0], anXYZ[1], anXYZ[2]);
2060 //=============================================================================
2061 //function : Transforms
2063 //=============================================================================
2064 Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
2065 const Graphic3d_Vertex& theCoord)
2067 Standard_Real anXYZ[3];
2068 Graphic3d_Structure::Transforms (theTrsf,
2069 theCoord.X(), theCoord.Y(), theCoord.Z(),
2070 anXYZ[0], anXYZ[1], anXYZ[2]);
2071 return Graphic3d_Vertex (anXYZ[0], anXYZ[1], anXYZ[2]);
2074 //=============================================================================
2075 //function : Transforms
2077 //=============================================================================
2078 void Graphic3d_Structure::TransformBoundaries (const TColStd_Array2OfReal& theTrsf,
2079 Standard_Real& theXMin,
2080 Standard_Real& theYMin,
2081 Standard_Real& theZMin,
2082 Standard_Real& theXMax,
2083 Standard_Real& theYMax,
2084 Standard_Real& theZMax)
2086 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
2088 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
2089 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
2091 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
2092 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2093 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2094 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2096 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
2097 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2098 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2099 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2101 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
2102 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2103 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2104 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2106 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
2107 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2108 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2109 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2111 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
2112 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2113 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2114 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2116 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
2117 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2118 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2119 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2129 //=============================================================================
2130 //function : Network
2132 //=============================================================================
2133 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
2134 const Graphic3d_TypeOfConnection theType,
2135 Graphic3d_MapOfStructure& theSet)
2137 Graphic3d_MapOfStructure aSetD, aSetA;
2138 theStructure->Descendants (aSetD);
2139 theStructure->Ancestors (aSetA);
2140 theSet.Add (theStructure);
2143 case Graphic3d_TOC_DESCENDANT:
2144 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
2146 Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
2149 case Graphic3d_TOC_ANCESTOR:
2150 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
2152 Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
2158 //=============================================================================
2159 //function : PrintNetwork
2161 //=============================================================================
2162 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
2163 const Graphic3d_TypeOfConnection theType)
2165 Graphic3d_MapOfStructure aSet;
2166 Graphic3d_Structure::Network (theStructure, theType, aSet);
2167 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
2169 std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
2171 std::cout << std::flush;
2174 //=============================================================================
2177 //=============================================================================
2178 void Graphic3d_Structure::Update() const
2185 if (myStructureManager->UpdateMode() == Aspect_TOU_ASAP)
2187 myStructureManager->Update();
2191 //=============================================================================
2192 //function : UpdateStructure
2194 //=============================================================================
2195 void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)& theAspLine,
2196 const Handle(Graphic3d_AspectText3d)& theAspText,
2197 const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
2198 const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
2200 Standard_CString aFont;
2201 Standard_Real aSpace, anExpansion, aWidth, aScale;
2202 Quantity_Color aColor, anIntColor, aBackIntColor, anEdgeColor, aColorSub;
2203 Aspect_TypeOfLine aLType;
2204 Aspect_TypeOfMarker aMType;
2205 Aspect_InteriorStyle aStyle;
2206 Aspect_TypeOfStyleText aStyleT;
2207 Aspect_TypeOfDisplayText aDisplayType;
2208 Standard_Boolean aTextZoomable;
2209 Standard_Real aTextAngle;
2210 Font_FontAspect aTextFontAspect;
2212 theAspLine->Values (aColor, aLType, aWidth);
2213 myCStructure->ContextLine.Color.r = float (aColor.Red());
2214 myCStructure->ContextLine.Color.g = float (aColor.Green());
2215 myCStructure->ContextLine.Color.b = float (aColor.Blue());
2216 myCStructure->ContextLine.LineType = aLType;
2217 myCStructure->ContextLine.Width = float (aWidth);
2218 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
2220 theAspMarker->Values (aColor, aMType, aScale);
2221 myCStructure->ContextMarker.Color.r = float (aColor.Red());
2222 myCStructure->ContextMarker.Color.g = float (aColor.Green());
2223 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
2224 myCStructure->ContextMarker.MarkerType = aMType;
2225 myCStructure->ContextMarker.Scale = float (aScale);
2226 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
2228 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyleT, aDisplayType, aColorSub, aTextZoomable, aTextAngle, aTextFontAspect);
2229 myCStructure->ContextText.Color.r = float (aColor.Red());
2230 myCStructure->ContextText.Color.g = float (aColor.Green());
2231 myCStructure->ContextText.Color.b = float (aColor.Blue());
2232 myCStructure->ContextText.Font = aFont;
2233 myCStructure->ContextText.Expan = float (anExpansion);
2234 myCStructure->ContextText.Style = aStyleT;
2235 myCStructure->ContextText.DisplayType = aDisplayType;
2236 myCStructure->ContextText.Space = float (aSpace);
2237 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
2238 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
2239 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
2240 myCStructure->ContextText.TextZoomable = aTextZoomable;
2241 myCStructure->ContextText.TextAngle = float (aTextAngle);
2242 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
2243 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
2245 Standard_Real anRGB[3];
2246 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
2247 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2248 myCStructure->ContextFillArea.Style = aStyle;
2249 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
2250 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
2251 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
2253 if (theAspFill->Distinguish())
2255 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2257 myCStructure->ContextFillArea.BackIntColor.r = float (anRGB[0]);
2258 myCStructure->ContextFillArea.BackIntColor.g = float (anRGB[1]);
2259 myCStructure->ContextFillArea.BackIntColor.b = float (anRGB[2]);
2262 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1:0;
2263 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
2264 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
2265 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
2266 myCStructure->ContextFillArea.LineType = aLType;
2267 myCStructure->ContextFillArea.Width = float (aWidth);
2268 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
2270 // Front and Back face
2271 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
2272 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
2274 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
2275 // Light specificity
2276 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
2277 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
2278 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
2279 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
2280 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
2281 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
2284 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2285 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2286 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2287 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2290 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2293 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
2294 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
2295 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
2298 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
2299 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
2300 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
2303 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
2304 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
2305 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
2308 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
2309 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
2310 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
2312 myCStructure->ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
2315 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
2316 // Light specificity
2317 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
2318 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
2319 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
2320 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
2321 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
2322 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
2325 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2326 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2327 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2328 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2331 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2334 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
2335 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
2336 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
2339 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
2340 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
2341 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
2344 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
2345 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
2346 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
2349 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
2350 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
2351 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
2353 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
2355 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
2356 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
2357 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
2359 Standard_Integer aPolyMode;
2360 Standard_ShortReal aPolyFactor, aPolyUnits;
2361 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
2362 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
2363 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
2364 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
2367 //=============================================================================
2368 //function : GraphicHighlight
2370 //=============================================================================
2371 void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod theMethod)
2373 Standard_Real anRGB[3];
2374 myCStructure->highlight = 1;
2375 myHighlightMethod = theMethod;
2378 case Aspect_TOHM_COLOR:
2380 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2381 myCStructure->HighlightWithColor (Graphic3d_Vec3 (float (anRGB[0]), float (anRGB[1]), float (anRGB[2])), Standard_True);
2382 myCStructure->UpdateNamedStatus();
2385 case Aspect_TOHM_BOUNDBOX:
2387 Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax;
2388 if (IsEmpty() || IsInfinite())
2390 // Empty or infinite structure
2391 XMin = YMin = ZMin = 0.0;
2392 XMax = YMax = ZMax = 0.0;
2396 MinMaxCoordWithDescendants (XMin, YMin, ZMin, XMax, YMax, ZMax);
2398 myCStructure->BoundBox.Pmin.x = float (XMin);
2399 myCStructure->BoundBox.Pmin.y = float (YMin);
2400 myCStructure->BoundBox.Pmin.z = float (ZMin);
2401 myCStructure->BoundBox.Pmax.x = float (XMax);
2402 myCStructure->BoundBox.Pmax.y = float (YMax);
2403 myCStructure->BoundBox.Pmax.z = float (ZMax);
2404 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2405 myCStructure->BoundBox.Color.r = float (anRGB[0]);
2406 myCStructure->BoundBox.Color.g = float (anRGB[1]);
2407 myCStructure->BoundBox.Color.b = float (anRGB[2]);
2408 myCStructure->HighlightWithBndBox (this, Standard_True);
2414 //=============================================================================
2415 //function : GraphicTransform
2417 //=============================================================================
2418 void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& theMatrix)
2420 for (Standard_Integer i = 0; i <= 3; ++i)
2422 for (Standard_Integer j = 0; j <= 3; ++j)
2424 myCStructure->Transformation[i][j] = float (theMatrix (i, j));
2427 myCStructure->UpdateTransformation();
2430 //=============================================================================
2431 //function : GraphicUnHighlight
2433 //=============================================================================
2434 void Graphic3d_Structure::GraphicUnHighlight()
2436 myCStructure->highlight = 0;
2437 switch (myHighlightMethod)
2439 case Aspect_TOHM_COLOR:
2440 myCStructure->HighlightWithColor (Graphic3d_Vec3 (0.0f, 0.0f, 0.0f), Standard_False);
2441 myCStructure->UpdateNamedStatus();
2443 case Aspect_TOHM_BOUNDBOX:
2444 myCStructure->HighlightWithBndBox (this, Standard_False);
2445 myCStructure->UpdateNamedStatus();
2450 //=============================================================================
2451 //function : ComputeVisual
2453 //=============================================================================
2454 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
2456 return myComputeVisual;
2459 //=============================================================================
2460 //function : SetComputeVisual
2462 //=============================================================================
2463 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
2465 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
2466 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
2467 if (theVisual != Graphic3d_TOS_COMPUTED)
2469 myComputeVisual = theVisual;
2473 //=============================================================================
2474 //function : SetHLRValidation
2476 //=============================================================================
2477 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
2479 myCStructure->HLRValidation = theFlag ? 1 : 0;
2482 //=============================================================================
2483 //function : HLRValidation
2485 //=============================================================================
2486 Standard_Boolean Graphic3d_Structure::HLRValidation() const
2488 // Hidden parts stored in <me> are valid if :
2489 // 1/ the owner is defined.
2490 // 2/ they are not invalid.
2491 return myOwner != NULL
2492 && myCStructure->HLRValidation != 0;
2495 //=======================================================================
2496 //function : SetZLayer
2498 //=======================================================================
2499 void Graphic3d_Structure::SetZLayer (const Standard_Integer theLayerId)
2501 // if the structure is not displayed, unable to change its display layer
2505 myStructureManager->ChangeZLayer (this, theLayerId);
2508 //=======================================================================
2509 //function : GetZLayer
2511 //=======================================================================
2512 Standard_Integer Graphic3d_Structure::GetZLayer () const
2514 return myStructureManager->GetZLayer (this);
2517 //=======================================================================
2518 //function : SetClipPlanes
2520 //=======================================================================
2521 void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
2523 myCStructure->SetClipPlanes (thePlanes);
2526 //=======================================================================
2527 //function : GetClipPlanes
2529 //=======================================================================
2530 const Graphic3d_SequenceOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const
2532 return myCStructure->ClipPlanes();