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.hxx>
18 #include <Bnd_Box.hxx>
20 #include <Graphic3d_DataStructureManager.hxx>
21 #include <Graphic3d_GraphicDriver.hxx>
22 #include <Graphic3d_Group.hxx>
23 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
24 #include <Graphic3d_MapOfStructure.hxx>
25 #include <Graphic3d_PriorityDefinitionError.hxx>
26 #include <Graphic3d_StructureDefinitionError.hxx>
27 #include <Graphic3d_StructureManager.hxx>
28 #include <Graphic3d_TransformError.hxx>
29 #include <Graphic3d_Vector.hxx>
30 #include <Quantity_Color.hxx>
31 #include <Standard_Type.hxx>
33 #include "Graphic3d_Structure.pxx"
37 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Structure,MMgt_TShared)
39 //=============================================================================
40 //function : Graphic3d_Structure
42 //=============================================================================
43 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager)
44 : myStructureManager (theManager.operator->()),
45 myFirstStructureManager (theManager.operator->()),
46 myComputeVisual (Graphic3d_TOS_ALL),
48 myVisual (Graphic3d_TOS_ALL)
50 myCStructure = theManager->GraphicDriver()->CreateStructure (theManager);
53 //=============================================================================
54 //function : Graphic3d_Structure
56 //=============================================================================
57 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
58 const Handle(Graphic3d_Structure)& thePrs)
59 : myStructureManager (theManager.operator->()),
60 myFirstStructureManager (theManager.operator->()),
61 myComputeVisual (thePrs->myComputeVisual),
62 myOwner (thePrs->myOwner),
63 myVisual (thePrs->myVisual)
65 myCStructure = thePrs->myCStructure->ShadowLink (theManager);
68 //=============================================================================
69 //function : ~Graphic3d_Structure
71 //=============================================================================
72 Graphic3d_Structure::~Graphic3d_Structure()
74 // as myFirstStructureManager can be already destroyed,
75 // avoid attempts to access it
76 myFirstStructureManager = NULL;
80 //=============================================================================
83 //=============================================================================
84 void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
86 if (IsDeleted()) return;
88 // clean groups in graphics driver at first
89 GraphicClear (theWithDestruction);
91 myCStructure->ContainsFacet = 0;
92 myStructureManager->Clear (this, theWithDestruction);
97 //=======================================================================
98 //function : CalculateBoundBox
99 //purpose : Calculates AABB of a structure.
100 //=======================================================================
101 void Graphic3d_Structure::CalculateBoundBox()
103 Graphic3d_BndBox4d aBox;
104 addTransformed (aBox, Standard_True);
107 Graphic3d_Vec4 aMinPt (RealToShortReal (aBox.CornerMin().x()),
108 RealToShortReal (aBox.CornerMin().y()),
109 RealToShortReal (aBox.CornerMin().z()),
111 Graphic3d_Vec4 aMaxPt (RealToShortReal (aBox.CornerMax().x()),
112 RealToShortReal (aBox.CornerMax().y()),
113 RealToShortReal (aBox.CornerMax().z()),
115 myCStructure->ChangeBoundingBox() = Graphic3d_BndBox4f (aMinPt, aMaxPt);
119 myCStructure->ChangeBoundingBox().Clear();
123 //=============================================================================
126 //=============================================================================
127 void Graphic3d_Structure::Remove()
129 if (IsDeleted()) return;
131 // clean groups in graphics driver at first; this is also should be done
132 // to avoid unwanted group cleaning in group's destructor
133 // Pass Standard_False to Clear(..) method to avoid updating in
134 // structure manager, it isn't necessary, besides of it structure manager
135 // could be already destroyed and invalid pointers used in structure;
136 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
138 aGroupIter.ChangeValue()->Clear (Standard_False);
141 Standard_Address APtr = (void *) this;
142 // It is necessary to remove the eventual pointer on the structure
143 // that can be destroyed, in the list of descendants
144 // of ancestors of this structure and in the list of ancestors
145 // of descendants of the same structure.
147 for (Standard_Integer aStructIdx = 1, aNbDesc = myDescendants.Size(); aStructIdx <= aNbDesc; ++aStructIdx)
149 ((Graphic3d_Structure *)myDescendants.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
152 for (Standard_Integer aStructIdx = 1, aNbAnces = myAncestors.Size(); aStructIdx <= aNbAnces; ++aStructIdx)
154 ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
157 // Destruction of me in the graphic library
158 const Standard_Integer aStructId = myCStructure->Id;
159 myCStructure->GraphicDriver()->RemoveIdentification(aStructId);
160 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
161 myCStructure.Nullify();
164 //=============================================================================
167 //=============================================================================
168 void Graphic3d_Structure::Display()
170 if (IsDeleted()) return;
172 if (!myCStructure->stick)
174 myCStructure->stick = 1;
175 myStructureManager->Display (this);
178 if (myCStructure->visible != 1)
180 myCStructure->visible = 1;
181 myCStructure->OnVisibilityChanged();
185 //=============================================================================
186 //function : SetIsForHighlight
188 //=============================================================================
189 void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight)
191 myCStructure->IsForHighlight = isForHighlight;
194 //=============================================================================
195 //function : SetDisplayPriority
197 //=============================================================================
198 void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
201 || thePriority == myCStructure->Priority)
206 myCStructure->PreviousPriority = myCStructure->Priority;
207 myCStructure->Priority = thePriority;
209 if (myCStructure->Priority != myCStructure->PreviousPriority)
211 Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
212 || (myCStructure->Priority < Structure_MIN_PRIORITY),
213 "Bad value for StructurePriority");
214 if (myCStructure->stick)
216 myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
221 //=============================================================================
222 //function : ResetDisplayPriority
224 //=============================================================================
225 void Graphic3d_Structure::ResetDisplayPriority()
228 || myCStructure->Priority == myCStructure->PreviousPriority)
233 const Standard_Integer aPriority = myCStructure->Priority;
234 myCStructure->Priority = myCStructure->PreviousPriority;
235 if (myCStructure->stick)
237 myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
241 //=============================================================================
242 //function : DisplayPriority
244 //=============================================================================
245 Standard_Integer Graphic3d_Structure::DisplayPriority() const
247 return myCStructure->Priority;
250 //=============================================================================
253 //=============================================================================
254 void Graphic3d_Structure::Erase()
261 if (myCStructure->stick)
263 myCStructure->stick = 0;
264 myStructureManager->Erase (this);
268 //=============================================================================
269 //function : Highlight
271 //=============================================================================
272 void Graphic3d_Structure::Highlight (const Handle(Graphic3d_HighlightStyle)& theStyle,
273 const Standard_Boolean theToUpdateMgr)
280 // Highlight on already Highlighted structure.
281 if (myCStructure->highlight)
283 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
284 if (anUpdateMode == Aspect_TOU_WAIT)
290 // To avoid call of method : Update()
291 // Not useful and can be costly.
292 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
294 myStructureManager->SetUpdateMode (anUpdateMode);
298 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
300 myCStructure->GraphicHighlight (theStyle, this);
307 if (myCStructure->stick)
309 myStructureManager->Highlight (this);
315 //=============================================================================
316 //function : SetVisible
318 //=============================================================================
319 void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
321 if (IsDeleted()) return;
323 const unsigned isVisible = theValue ? 1 : 0;
324 if (myCStructure->visible == isVisible)
329 myCStructure->visible = isVisible;
330 myCStructure->OnVisibilityChanged();
334 //=============================================================================
335 //function : UnHighlight
337 //=============================================================================
338 void Graphic3d_Structure::UnHighlight()
340 if (IsDeleted()) return;
342 if (myCStructure->highlight)
344 myCStructure->highlight = 0;
346 myCStructure->GraphicUnhighlight();
347 myStructureManager->UnHighlight (this);
349 ResetDisplayPriority();
354 //=============================================================================
355 //function : HighlightStyle
357 //=============================================================================
358 const Handle(Graphic3d_HighlightStyle)& Graphic3d_Structure::HighlightStyle() const
360 return myCStructure->HighlightStyle();
363 //=============================================================================
364 //function : IsDisplayed
366 //=============================================================================
367 Standard_Boolean Graphic3d_Structure::IsDisplayed() const
369 return myCStructure->stick ? Standard_True : Standard_False;
372 //=============================================================================
373 //function : IsDeleted
375 //=============================================================================
376 Standard_Boolean Graphic3d_Structure::IsDeleted() const
378 return myCStructure.IsNull();
381 //=============================================================================
382 //function : IsHighlighted
384 //=============================================================================
385 Standard_Boolean Graphic3d_Structure::IsHighlighted() const
387 return myCStructure->highlight ? Standard_True : Standard_False;
390 //=============================================================================
391 //function : IsVisible
393 //=============================================================================
394 Standard_Boolean Graphic3d_Structure::IsVisible() const
396 return myCStructure->visible ? Standard_True : Standard_False;
399 //=============================================================================
400 //function : IsTransformed
402 //=============================================================================
403 Standard_Boolean Graphic3d_Structure::IsTransformed() const
405 return !myCStructure->Transformation().IsNull()
406 && myCStructure->Transformation()->Form() != gp_Identity;
409 //=============================================================================
410 //function : ContainsFacet
412 //=============================================================================
413 Standard_Boolean Graphic3d_Structure::ContainsFacet() const
417 return Standard_False;
419 else if (myCStructure->ContainsFacet > 0)
421 // if one of groups contains at least one facet, the structure contains it too
422 return Standard_True;
425 // stop at the first descendant containing at least one facet
426 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
428 if (((const Graphic3d_Structure *)anIter.Value())->ContainsFacet())
430 return Standard_True;
433 return Standard_False;
436 //=============================================================================
439 //=============================================================================
440 Standard_Boolean Graphic3d_Structure::IsEmpty() const
444 return Standard_True;
447 // structure is empty:
448 // - if all these groups are empty
449 // - or if all groups are empty and all their descendants are empty
450 // - or if all its descendants are empty
451 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
453 if (!aGroupIter.Value()->IsEmpty())
455 return Standard_False;
459 // stop at the first non-empty descendant
460 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
462 if (!((const Graphic3d_Structure* )anIter.Value())->IsEmpty())
464 return Standard_False;
467 return Standard_True;
470 //=============================================================================
471 //function : GroupsWithFacet
473 //=============================================================================
474 void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
476 myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
477 if (myCStructure->ContainsFacet < 0)
479 myCStructure->ContainsFacet = 0;
483 //=============================================================================
486 //=============================================================================
487 void Graphic3d_Structure::Compute()
489 // Implemented by Presentation
492 //=============================================================================
495 //=============================================================================
496 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
498 // Implemented by Presentation
502 //=============================================================================
505 //=============================================================================
506 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
507 const Handle(Geom_Transformation)& )
509 // Implemented by Presentation
513 //=============================================================================
516 //=============================================================================
517 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
518 Handle(Graphic3d_Structure)& )
520 // Implemented by Presentation
523 //=============================================================================
526 //=============================================================================
527 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
528 const Handle(Geom_Transformation)& ,
529 Handle(Graphic3d_Structure)& )
531 // Implemented by Presentation
534 //=============================================================================
535 //function : ReCompute
537 //=============================================================================
538 void Graphic3d_Structure::ReCompute()
540 myStructureManager->ReCompute (this);
543 //=============================================================================
544 //function : ReCompute
546 //=============================================================================
547 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
549 myStructureManager->ReCompute (this, theProjector);
552 //=============================================================================
553 //function : SetInfiniteState
555 //=============================================================================
556 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
558 myCStructure->IsInfinite = theToSet ? 1 : 0;
561 //=============================================================================
562 //function : IsInfinite
564 //=============================================================================
565 Standard_Boolean Graphic3d_Structure::IsInfinite() const
568 || myCStructure->IsInfinite;
571 //=============================================================================
572 //function : GraphicClear
574 //=============================================================================
575 void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
577 if (myCStructure.IsNull())
582 // clean and empty each group
583 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
585 aGroupIter.ChangeValue()->Clear();
587 if (!theWithDestruction)
592 while (!myCStructure->Groups().IsEmpty())
594 Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
597 myCStructure->Clear();
600 //=============================================================================
601 //function : GraphicConnect
603 //=============================================================================
604 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
606 myCStructure->Connect (*theDaughter->myCStructure);
609 //=============================================================================
610 //function : GraphicDisconnect
612 //=============================================================================
613 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
615 myCStructure->Disconnect (*theDaughter->myCStructure);
618 //=============================================================================
621 //=============================================================================
622 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
624 return myCStructure->Groups();
627 //=============================================================================
628 //function : NumberOfGroups
630 //=============================================================================
631 Standard_Integer Graphic3d_Structure::NumberOfGroups() const
633 return myCStructure->Groups().Length();
636 //=============================================================================
637 //function : SetVisual
639 //=============================================================================
640 void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
643 || myVisual == theVisual)
648 if (!myCStructure->stick)
650 myVisual = theVisual;
651 SetComputeVisual (theVisual);
655 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
656 if (anUpdateMode == Aspect_TOU_WAIT)
659 myVisual = theVisual;
660 SetComputeVisual (theVisual);
664 // To avoid calling method : Update ()
665 // Not useful and can be costly.
666 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
668 myVisual = theVisual;
669 SetComputeVisual (theVisual);
670 myStructureManager->SetUpdateMode (anUpdateMode);
676 //=============================================================================
677 //function : SetZoomLimit
679 //=============================================================================
680 void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
681 const Standard_Real theLimitSup)
685 Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
686 "Bad value for ZoomLimit inf");
687 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
688 "Bad value for ZoomLimit sup");
689 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
690 "ZoomLimit sup < ZoomLimit inf");
693 //=============================================================================
696 //=============================================================================
697 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
702 //=============================================================================
703 //function : AcceptConnection
705 //=============================================================================
706 Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
707 const Handle(Graphic3d_Structure)& theStructure2,
708 const Graphic3d_TypeOfConnection theType)
711 Graphic3d_MapOfStructure aSet;
712 Graphic3d_Structure::Network (theStructure2, theType, aSet);
713 return !aSet.Contains (theStructure1);
716 //=============================================================================
717 //function : Ancestors
719 //=============================================================================
720 void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
722 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myAncestors); anIter.More(); anIter.Next())
724 theSet.Add ((Graphic3d_Structure* )anIter.Value());
728 //=============================================================================
729 //function : SetOwner
731 //=============================================================================
732 void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
737 //=============================================================================
740 //=============================================================================
741 Standard_Address Graphic3d_Structure::Owner() const
746 //=============================================================================
747 //function : Descendants
749 //=============================================================================
750 void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
752 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
754 theSet.Add ((Graphic3d_Structure* )anIter.Value());
758 //=============================================================================
759 //function : AppendAncestor
761 //=============================================================================
762 Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor)
764 const Standard_Integer aSize = myAncestors.Size();
766 return myAncestors.Add (theAncestor) > aSize; // new object
769 //=============================================================================
770 //function : AppendDescendant
772 //=============================================================================
773 Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant)
775 const Standard_Integer aSize = myDescendants.Size();
777 return myDescendants.Add (theDescendant) > aSize; // new object
780 //=============================================================================
781 //function : RemoveAncestor
783 //=============================================================================
784 Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor)
786 const Standard_Integer anIndex = myAncestors.FindIndex (theAncestor);
790 myAncestors.Swap (anIndex, myAncestors.Size());
791 myAncestors.RemoveLast();
794 return anIndex != 0; // object was found
797 //=============================================================================
798 //function : RemoveDescendant
800 //=============================================================================
801 Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant)
803 const Standard_Integer anIndex = myDescendants.FindIndex (theDescendant);
807 myDescendants.Swap (anIndex, myDescendants.Size());
808 myDescendants.RemoveLast();
811 return anIndex != 0; // object was found
814 //=============================================================================
817 //=============================================================================
818 void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
819 const Graphic3d_TypeOfConnection theType,
820 const Standard_Boolean theWithCheck)
829 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
834 const Standard_Address aStructure = theStructure.operator->();
836 if (theType == Graphic3d_TOC_DESCENDANT)
838 if (!AppendDescendant (aStructure))
844 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
846 GraphicConnect (theStructure);
847 myStructureManager->Connect (this, theStructure);
851 else // Graphic3d_TOC_ANCESTOR
853 if (!AppendAncestor (aStructure))
859 theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
861 // myStructureManager->Connect is called in case if connection between parent and child
865 //=============================================================================
866 //function : Disconnect
868 //=============================================================================
869 void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
876 const Standard_Address aStructure = theStructure.operator->();
878 if (RemoveDescendant (aStructure))
880 theStructure->Disconnect (this);
882 GraphicDisconnect (theStructure);
883 myStructureManager->Disconnect (this, theStructure);
888 else if (RemoveAncestor (aStructure))
890 theStructure->Disconnect (this);
893 // no call of myStructureManager->Disconnect in case of an ancestor
897 //=============================================================================
898 //function : DisconnectAll
900 //=============================================================================
901 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
903 if (IsDeleted()) return;
907 case Graphic3d_TOC_DESCENDANT:
909 for (Standard_Integer anIdx = 1, aLength = myDescendants.Size(); anIdx <= aLength; ++anIdx)
911 // Value (1) instead of Value (i) as myDescendants
913 // Graphic3d_Structure::Disconnect (AStructure)
914 // that takes AStructure from myDescendants
915 ((Graphic3d_Structure* )(myDescendants.FindKey (1)))->Disconnect (this);
919 case Graphic3d_TOC_ANCESTOR:
921 for (Standard_Integer anIdx = 1, aLength = myAncestors.Size(); anIdx <= aLength; ++anIdx)
923 // Value (1) instead of Value (i) as myAncestors
925 // Graphic3d_Structure::Disconnect (AStructure)
926 // that takes AStructure from myAncestors
927 ((Graphic3d_Structure* )(myAncestors.FindKey (1)))->Disconnect (this);
934 //=============================================================================
935 //function : SetTransform
937 //=============================================================================
938 void Graphic3d_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf)
940 if (IsDeleted()) return;
942 const Standard_Boolean wasTransformed = IsTransformed();
944 if (!theTrsf.IsNull()
945 && theTrsf->Trsf().Form() == gp_Identity)
947 myCStructure->SetTransformation (Handle(Geom_Transformation)());
951 myCStructure->SetTransformation (theTrsf);
954 // If transformation, no validation of hidden already calculated parts
955 if (IsTransformed() || (!IsTransformed() && wasTransformed))
960 myStructureManager->SetTransform (this, theTrsf);
965 //=============================================================================
966 //function : MinMaxValues
968 //=============================================================================
969 Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
971 Graphic3d_BndBox4d aBox;
973 addTransformed (aBox, theToIgnoreInfiniteFlag);
976 aResult.Add (gp_Pnt (aBox.CornerMin().x(),
977 aBox.CornerMin().y(),
978 aBox.CornerMin().z()));
979 aResult.Add (gp_Pnt (aBox.CornerMax().x(),
980 aBox.CornerMax().y(),
981 aBox.CornerMax().z()));
983 Standard_Real aLimMin = ShortRealFirst() + 1.0;
984 Standard_Real aLimMax = ShortRealLast() - 1.0;
985 gp_Pnt aMin = aResult.CornerMin();
986 gp_Pnt aMax = aResult.CornerMax();
987 if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin &&
988 aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax)
990 //For structure which infinite in all three dimensions the Whole bounding box will be returned
997 //=============================================================================
998 //function : Identification
1000 //=============================================================================
1001 Standard_Integer Graphic3d_Structure::Identification() const
1003 return myCStructure->Id;
1006 //=============================================================================
1007 //function : SetTransformPersistence
1009 //=============================================================================
1010 void Graphic3d_Structure::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
1017 myCStructure->SetTransformPersistence (theTrsfPers);
1020 //=============================================================================
1023 //=============================================================================
1024 void Graphic3d_Structure::Remove (const Standard_Address thePtr,
1025 const Graphic3d_TypeOfConnection theType)
1027 if (theType == Graphic3d_TOC_DESCENDANT)
1029 RemoveDescendant (thePtr);
1033 RemoveAncestor (thePtr);
1037 //=============================================================================
1038 //function : NewGroup
1040 //=============================================================================
1041 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
1043 return myCStructure->NewGroup (this);
1046 //=============================================================================
1049 //=============================================================================
1050 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1052 if (theGroup.IsNull()
1053 || theGroup->myStructure != this)
1058 myCStructure->RemoveGroup (theGroup);
1059 theGroup->myStructure = NULL;
1062 //=============================================================================
1063 //function : StructureManager
1065 //=============================================================================
1066 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1068 return myStructureManager;
1071 //=============================================================================
1072 //function : minMaxCoord
1074 //=============================================================================
1075 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
1077 Graphic3d_BndBox4f aBnd;
1078 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1080 aBnd.Combine (aGroupIter.Value()->BoundingBox());
1085 //=============================================================================
1086 //function : addTransformed
1088 //=============================================================================
1089 void Graphic3d_Structure::getBox (Graphic3d_BndBox4d& theBox,
1090 const Standard_Boolean theToIgnoreInfiniteFlag) const
1092 Graphic3d_BndBox4f aBoxF = minMaxCoord();
1093 if (aBoxF.IsValid())
1095 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMin().x(),
1096 (Standard_Real )aBoxF.CornerMin().y(),
1097 (Standard_Real )aBoxF.CornerMin().z(),
1098 (Standard_Real )aBoxF.CornerMin().w()),
1099 Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMax().x(),
1100 (Standard_Real )aBoxF.CornerMax().y(),
1101 (Standard_Real )aBoxF.CornerMax().z(),
1102 (Standard_Real )aBoxF.CornerMax().w()));
1104 && !theToIgnoreInfiniteFlag)
1106 const Graphic3d_Vec4d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
1107 if (aDiagVec.xyz().SquareModulus() >= 500000.0 * 500000.0)
1109 // bounding borders of infinite line has been calculated as own point in center of this line
1110 theBox = Graphic3d_BndBox4d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
1114 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d (RealFirst(), RealFirst(), RealFirst(), 1.0),
1115 Graphic3d_Vec4d (RealLast(), RealLast(), RealLast(), 1.0));
1122 //=============================================================================
1123 //function : addTransformed
1125 //=============================================================================
1126 void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d& theBox,
1127 const Standard_Boolean theToIgnoreInfiniteFlag) const
1129 Graphic3d_BndBox4d aCombinedBox, aBox;
1130 getBox (aCombinedBox, theToIgnoreInfiniteFlag);
1132 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1134 const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )anIter.Value();
1135 aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1136 aCombinedBox.Combine (aBox);
1139 aBox = aCombinedBox;
1142 if (!myCStructure->Transformation().IsNull())
1144 TransformBoundaries (myCStructure->Transformation()->Trsf(),
1145 aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1146 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1149 // if box is still valid after transformation
1152 theBox.Combine (aBox);
1154 else // it was infinite, return untransformed
1156 theBox.Combine (aCombinedBox);
1161 //=============================================================================
1162 //function : Transforms
1164 //=============================================================================
1165 void Graphic3d_Structure::Transforms (const gp_Trsf& theTrsf,
1166 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
1167 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ)
1169 const Standard_Real aRL = RealLast();
1170 const Standard_Real aRF = RealFirst();
1174 if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1175 || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1180 theTrsf.Transforms (theNewX, theNewY, theNewZ);
1183 //=============================================================================
1184 //function : Transforms
1186 //=============================================================================
1187 void Graphic3d_Structure::TransformBoundaries (const gp_Trsf& theTrsf,
1188 Standard_Real& theXMin,
1189 Standard_Real& theYMin,
1190 Standard_Real& theZMin,
1191 Standard_Real& theXMax,
1192 Standard_Real& theYMax,
1193 Standard_Real& theZMax)
1195 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1197 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1198 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1200 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
1201 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1202 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1203 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1205 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
1206 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1207 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1208 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1210 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
1211 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1212 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1213 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1215 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
1216 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1217 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1218 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1220 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
1221 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1222 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1223 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1225 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
1226 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1227 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1228 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1238 //=============================================================================
1239 //function : Network
1241 //=============================================================================
1242 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
1243 const Graphic3d_TypeOfConnection theType,
1244 Graphic3d_MapOfStructure& theSet)
1246 Graphic3d_MapOfStructure aSetD, aSetA;
1247 theStructure->Descendants (aSetD);
1248 theStructure->Ancestors (aSetA);
1249 theSet.Add (theStructure);
1252 case Graphic3d_TOC_DESCENDANT:
1253 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
1255 Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
1258 case Graphic3d_TOC_ANCESTOR:
1259 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
1261 Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
1267 //=============================================================================
1268 //function : PrintNetwork
1270 //=============================================================================
1271 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
1272 const Graphic3d_TypeOfConnection theType)
1274 Graphic3d_MapOfStructure aSet;
1275 Graphic3d_Structure::Network (theStructure, theType, aSet);
1276 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
1278 std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
1280 std::cout << std::flush;
1283 //=============================================================================
1286 //=============================================================================
1287 void Graphic3d_Structure::Update (const bool theUpdateLayer) const
1294 myStructureManager->Update (myStructureManager->UpdateMode(),
1295 theUpdateLayer ? myCStructure->ZLayer() : Graphic3d_ZLayerId_UNKNOWN);
1298 //=============================================================================
1299 //function : GraphicTransform
1301 //=============================================================================
1302 void Graphic3d_Structure::GraphicTransform (const Handle(Geom_Transformation)& theTrsf)
1304 myCStructure->SetTransformation (theTrsf);
1307 //=============================================================================
1308 //function : ComputeVisual
1310 //=============================================================================
1311 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
1313 return myComputeVisual;
1316 //=============================================================================
1317 //function : SetComputeVisual
1319 //=============================================================================
1320 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
1322 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
1323 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
1324 if (theVisual != Graphic3d_TOS_COMPUTED)
1326 myComputeVisual = theVisual;
1330 //=============================================================================
1331 //function : SetHLRValidation
1333 //=============================================================================
1334 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
1336 myCStructure->HLRValidation = theFlag ? 1 : 0;
1339 //=============================================================================
1340 //function : HLRValidation
1342 //=============================================================================
1343 Standard_Boolean Graphic3d_Structure::HLRValidation() const
1345 // Hidden parts stored in <me> are valid if :
1346 // 1/ the owner is defined.
1347 // 2/ they are not invalid.
1348 return myOwner != NULL
1349 && myCStructure->HLRValidation != 0;
1352 //=======================================================================
1353 //function : SetZLayer
1355 //=======================================================================
1356 void Graphic3d_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerId)
1358 // if the structure is not displayed, unable to change its display layer
1362 myStructureManager->ChangeZLayer (this, theLayerId);
1363 myCStructure->SetZLayer (theLayerId);
1366 //=======================================================================
1367 //function : GetZLayer
1369 //=======================================================================
1370 Graphic3d_ZLayerId Graphic3d_Structure::GetZLayer() const
1372 return myCStructure->ZLayer();
1375 //=======================================================================
1376 //function : SetClipPlanes
1378 //=======================================================================
1379 void Graphic3d_Structure::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
1381 myCStructure->SetClipPlanes (thePlanes);
1384 //=======================================================================
1385 //function : GetClipPlanes
1387 //=======================================================================
1388 const Handle(Graphic3d_SequenceOfHClipPlane)& Graphic3d_Structure::ClipPlanes() const
1390 return myCStructure->ClipPlanes();
1393 //=======================================================================
1394 //function : SetMutable
1396 //=======================================================================
1397 void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
1399 myCStructure->IsMutable = theIsMutable;
1402 //=======================================================================
1403 //function : IsMutable
1405 //=======================================================================
1406 Standard_Boolean Graphic3d_Structure::IsMutable() const
1408 return myCStructure->IsMutable;