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,Standard_Transient)
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_BndBox3d aBox;
104 addTransformed (aBox, Standard_True);
105 myCStructure->ChangeBoundingBox() = aBox;
108 //=============================================================================
111 //=============================================================================
112 void Graphic3d_Structure::Remove()
114 if (IsDeleted()) return;
116 // clean groups in graphics driver at first; this is also should be done
117 // to avoid unwanted group cleaning in group's destructor
118 // Pass Standard_False to Clear(..) method to avoid updating in
119 // structure manager, it isn't necessary, besides of it structure manager
120 // could be already destroyed and invalid pointers used in structure;
121 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
123 aGroupIter.ChangeValue()->Clear (Standard_False);
126 Standard_Address APtr = (void *) this;
127 // It is necessary to remove the eventual pointer on the structure
128 // that can be destroyed, in the list of descendants
129 // of ancestors of this structure and in the list of ancestors
130 // of descendants of the same structure.
132 for (Standard_Integer aStructIdx = 1, aNbDesc = myDescendants.Size(); aStructIdx <= aNbDesc; ++aStructIdx)
134 ((Graphic3d_Structure *)myDescendants.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
137 for (Standard_Integer aStructIdx = 1, aNbAnces = myAncestors.Size(); aStructIdx <= aNbAnces; ++aStructIdx)
139 ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
142 // Destruction of me in the graphic library
143 const Standard_Integer aStructId = myCStructure->Id;
144 myCStructure->GraphicDriver()->RemoveIdentification(aStructId);
145 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
146 myCStructure.Nullify();
149 //=============================================================================
152 //=============================================================================
153 void Graphic3d_Structure::Display()
155 if (IsDeleted()) return;
157 if (!myCStructure->stick)
159 myCStructure->stick = 1;
160 myStructureManager->Display (this);
163 if (myCStructure->visible != 1)
165 myCStructure->visible = 1;
166 myCStructure->OnVisibilityChanged();
170 //=============================================================================
171 //function : SetIsForHighlight
173 //=============================================================================
174 void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight)
176 myCStructure->IsForHighlight = isForHighlight;
179 //=============================================================================
180 //function : SetDisplayPriority
182 //=============================================================================
183 void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
186 || thePriority == myCStructure->Priority)
191 myCStructure->PreviousPriority = myCStructure->Priority;
192 myCStructure->Priority = thePriority;
194 if (myCStructure->Priority != myCStructure->PreviousPriority)
196 Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
197 || (myCStructure->Priority < Structure_MIN_PRIORITY),
198 "Bad value for StructurePriority");
199 if (myCStructure->stick)
201 myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
206 //=============================================================================
207 //function : ResetDisplayPriority
209 //=============================================================================
210 void Graphic3d_Structure::ResetDisplayPriority()
213 || myCStructure->Priority == myCStructure->PreviousPriority)
218 const Standard_Integer aPriority = myCStructure->Priority;
219 myCStructure->Priority = myCStructure->PreviousPriority;
220 if (myCStructure->stick)
222 myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
226 //=============================================================================
227 //function : DisplayPriority
229 //=============================================================================
230 Standard_Integer Graphic3d_Structure::DisplayPriority() const
232 return myCStructure->Priority;
235 //=============================================================================
238 //=============================================================================
239 void Graphic3d_Structure::Erase()
246 if (myCStructure->stick)
248 myCStructure->stick = 0;
249 myStructureManager->Erase (this);
253 //=============================================================================
254 //function : Highlight
256 //=============================================================================
257 void Graphic3d_Structure::Highlight (const Handle(Graphic3d_PresentationAttributes)& theStyle,
258 const Standard_Boolean theToUpdateMgr)
265 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
267 myCStructure->GraphicHighlight (theStyle, this);
274 if (myCStructure->stick)
276 myStructureManager->Highlight (this);
282 //=============================================================================
283 //function : SetVisible
285 //=============================================================================
286 void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
288 if (IsDeleted()) return;
290 const unsigned isVisible = theValue ? 1 : 0;
291 if (myCStructure->visible == isVisible)
296 myCStructure->visible = isVisible;
297 myCStructure->OnVisibilityChanged();
301 //=============================================================================
302 //function : UnHighlight
304 //=============================================================================
305 void Graphic3d_Structure::UnHighlight()
307 if (IsDeleted()) return;
309 if (myCStructure->highlight)
311 myCStructure->highlight = 0;
313 myCStructure->GraphicUnhighlight();
314 myStructureManager->UnHighlight (this);
316 ResetDisplayPriority();
321 //=============================================================================
322 //function : HighlightStyle
324 //=============================================================================
325 const Handle(Graphic3d_PresentationAttributes)& Graphic3d_Structure::HighlightStyle() const
327 return myCStructure->HighlightStyle();
330 //=============================================================================
331 //function : IsDisplayed
333 //=============================================================================
334 Standard_Boolean Graphic3d_Structure::IsDisplayed() const
336 return myCStructure->stick ? Standard_True : Standard_False;
339 //=============================================================================
340 //function : IsDeleted
342 //=============================================================================
343 Standard_Boolean Graphic3d_Structure::IsDeleted() const
345 return myCStructure.IsNull();
348 //=============================================================================
349 //function : IsHighlighted
351 //=============================================================================
352 Standard_Boolean Graphic3d_Structure::IsHighlighted() const
354 return myCStructure->highlight ? Standard_True : Standard_False;
357 //=============================================================================
358 //function : IsVisible
360 //=============================================================================
361 Standard_Boolean Graphic3d_Structure::IsVisible() const
363 return myCStructure->visible ? Standard_True : Standard_False;
366 //=============================================================================
367 //function : IsTransformed
369 //=============================================================================
370 Standard_Boolean Graphic3d_Structure::IsTransformed() const
372 return !myCStructure->Transformation().IsNull()
373 && myCStructure->Transformation()->Form() != gp_Identity;
376 //=============================================================================
377 //function : ContainsFacet
379 //=============================================================================
380 Standard_Boolean Graphic3d_Structure::ContainsFacet() const
384 return Standard_False;
386 else if (myCStructure->ContainsFacet > 0)
388 // if one of groups contains at least one facet, the structure contains it too
389 return Standard_True;
392 // stop at the first descendant containing at least one facet
393 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
395 if (((const Graphic3d_Structure *)anIter.Value())->ContainsFacet())
397 return Standard_True;
400 return Standard_False;
403 //=============================================================================
406 //=============================================================================
407 Standard_Boolean Graphic3d_Structure::IsEmpty() const
411 return Standard_True;
414 // structure is empty:
415 // - if all these groups are empty
416 // - or if all groups are empty and all their descendants are empty
417 // - or if all its descendants are empty
418 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
420 if (!aGroupIter.Value()->IsEmpty())
422 return Standard_False;
426 // stop at the first non-empty descendant
427 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
429 if (!((const Graphic3d_Structure* )anIter.Value())->IsEmpty())
431 return Standard_False;
434 return Standard_True;
437 //=============================================================================
438 //function : GroupsWithFacet
440 //=============================================================================
441 void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
443 myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
444 if (myCStructure->ContainsFacet < 0)
446 myCStructure->ContainsFacet = 0;
450 //=============================================================================
453 //=============================================================================
454 void Graphic3d_Structure::Compute()
456 // Implemented by Presentation
459 //=============================================================================
462 //=============================================================================
463 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
465 // Implemented by Presentation
469 //=============================================================================
472 //=============================================================================
473 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
474 const Handle(Geom_Transformation)& )
476 // Implemented by Presentation
480 //=============================================================================
483 //=============================================================================
484 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
485 Handle(Graphic3d_Structure)& )
487 // Implemented by Presentation
490 //=============================================================================
493 //=============================================================================
494 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
495 const Handle(Geom_Transformation)& ,
496 Handle(Graphic3d_Structure)& )
498 // Implemented by Presentation
501 //=============================================================================
502 //function : ReCompute
504 //=============================================================================
505 void Graphic3d_Structure::ReCompute()
507 myStructureManager->ReCompute (this);
510 //=============================================================================
511 //function : ReCompute
513 //=============================================================================
514 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
516 myStructureManager->ReCompute (this, theProjector);
519 //=============================================================================
520 //function : SetInfiniteState
522 //=============================================================================
523 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
525 myCStructure->IsInfinite = theToSet ? 1 : 0;
528 //=============================================================================
529 //function : IsInfinite
531 //=============================================================================
532 Standard_Boolean Graphic3d_Structure::IsInfinite() const
535 || myCStructure->IsInfinite;
538 //=============================================================================
539 //function : GraphicClear
541 //=============================================================================
542 void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
544 if (myCStructure.IsNull())
549 // clean and empty each group
550 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
552 aGroupIter.ChangeValue()->Clear();
554 if (!theWithDestruction)
559 while (!myCStructure->Groups().IsEmpty())
561 Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
564 myCStructure->Clear();
567 //=============================================================================
568 //function : GraphicConnect
570 //=============================================================================
571 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
573 myCStructure->Connect (*theDaughter->myCStructure);
576 //=============================================================================
577 //function : GraphicDisconnect
579 //=============================================================================
580 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
582 myCStructure->Disconnect (*theDaughter->myCStructure);
585 //=============================================================================
588 //=============================================================================
589 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
591 return myCStructure->Groups();
594 //=============================================================================
595 //function : NumberOfGroups
597 //=============================================================================
598 Standard_Integer Graphic3d_Structure::NumberOfGroups() const
600 return myCStructure->Groups().Length();
603 //=============================================================================
604 //function : SetVisual
606 //=============================================================================
607 void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
610 || myVisual == theVisual)
615 if (!myCStructure->stick)
617 myVisual = theVisual;
618 SetComputeVisual (theVisual);
623 myVisual = theVisual;
624 SetComputeVisual (theVisual);
629 //=============================================================================
630 //function : SetZoomLimit
632 //=============================================================================
633 void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
634 const Standard_Real theLimitSup)
638 Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
639 "Bad value for ZoomLimit inf");
640 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
641 "Bad value for ZoomLimit sup");
642 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
643 "ZoomLimit sup < ZoomLimit inf");
646 //=============================================================================
649 //=============================================================================
650 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
655 //=============================================================================
656 //function : AcceptConnection
658 //=============================================================================
659 Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
660 const Handle(Graphic3d_Structure)& theStructure2,
661 const Graphic3d_TypeOfConnection theType)
664 Graphic3d_MapOfStructure aSet;
665 Graphic3d_Structure::Network (theStructure2, theType, aSet);
666 return !aSet.Contains (theStructure1);
669 //=============================================================================
670 //function : Ancestors
672 //=============================================================================
673 void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
675 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myAncestors); anIter.More(); anIter.Next())
677 theSet.Add ((Graphic3d_Structure* )anIter.Value());
681 //=============================================================================
682 //function : SetOwner
684 //=============================================================================
685 void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
690 //=============================================================================
693 //=============================================================================
694 Standard_Address Graphic3d_Structure::Owner() const
699 //=============================================================================
700 //function : Descendants
702 //=============================================================================
703 void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
705 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
707 theSet.Add ((Graphic3d_Structure* )anIter.Value());
711 //=============================================================================
712 //function : AppendAncestor
714 //=============================================================================
715 Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor)
717 const Standard_Integer aSize = myAncestors.Size();
719 return myAncestors.Add (theAncestor) > aSize; // new object
722 //=============================================================================
723 //function : AppendDescendant
725 //=============================================================================
726 Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant)
728 const Standard_Integer aSize = myDescendants.Size();
730 return myDescendants.Add (theDescendant) > aSize; // new object
733 //=============================================================================
734 //function : RemoveAncestor
736 //=============================================================================
737 Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor)
739 const Standard_Integer anIndex = myAncestors.FindIndex (theAncestor);
743 myAncestors.Swap (anIndex, myAncestors.Size());
744 myAncestors.RemoveLast();
747 return anIndex != 0; // object was found
750 //=============================================================================
751 //function : RemoveDescendant
753 //=============================================================================
754 Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant)
756 const Standard_Integer anIndex = myDescendants.FindIndex (theDescendant);
760 myDescendants.Swap (anIndex, myDescendants.Size());
761 myDescendants.RemoveLast();
764 return anIndex != 0; // object was found
767 //=============================================================================
770 //=============================================================================
771 void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
772 const Graphic3d_TypeOfConnection theType,
773 const Standard_Boolean theWithCheck)
782 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
787 const Standard_Address aStructure = theStructure.operator->();
789 if (theType == Graphic3d_TOC_DESCENDANT)
791 if (!AppendDescendant (aStructure))
797 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
799 GraphicConnect (theStructure);
800 myStructureManager->Connect (this, theStructure);
804 else // Graphic3d_TOC_ANCESTOR
806 if (!AppendAncestor (aStructure))
812 theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
814 // myStructureManager->Connect is called in case if connection between parent and child
818 //=============================================================================
819 //function : Disconnect
821 //=============================================================================
822 void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
829 const Standard_Address aStructure = theStructure.operator->();
831 if (RemoveDescendant (aStructure))
833 theStructure->Disconnect (this);
835 GraphicDisconnect (theStructure);
836 myStructureManager->Disconnect (this, theStructure);
841 else if (RemoveAncestor (aStructure))
843 theStructure->Disconnect (this);
846 // no call of myStructureManager->Disconnect in case of an ancestor
850 //=============================================================================
851 //function : DisconnectAll
853 //=============================================================================
854 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
856 if (IsDeleted()) return;
860 case Graphic3d_TOC_DESCENDANT:
862 for (Standard_Integer anIdx = 1, aLength = myDescendants.Size(); anIdx <= aLength; ++anIdx)
864 // Value (1) instead of Value (i) as myDescendants
866 // Graphic3d_Structure::Disconnect (AStructure)
867 // that takes AStructure from myDescendants
868 ((Graphic3d_Structure* )(myDescendants.FindKey (1)))->Disconnect (this);
872 case Graphic3d_TOC_ANCESTOR:
874 for (Standard_Integer anIdx = 1, aLength = myAncestors.Size(); anIdx <= aLength; ++anIdx)
876 // Value (1) instead of Value (i) as myAncestors
878 // Graphic3d_Structure::Disconnect (AStructure)
879 // that takes AStructure from myAncestors
880 ((Graphic3d_Structure* )(myAncestors.FindKey (1)))->Disconnect (this);
887 //=============================================================================
888 //function : SetTransform
890 //=============================================================================
891 void Graphic3d_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf)
893 if (IsDeleted()) return;
895 const Standard_Boolean wasTransformed = IsTransformed();
897 if (!theTrsf.IsNull()
898 && theTrsf->Trsf().Form() == gp_Identity)
900 myCStructure->SetTransformation (Handle(Geom_Transformation)());
904 myCStructure->SetTransformation (theTrsf);
907 // If transformation, no validation of hidden already calculated parts
908 if (IsTransformed() || (!IsTransformed() && wasTransformed))
913 myStructureManager->SetTransform (this, theTrsf);
918 //=============================================================================
919 //function : MinMaxValues
921 //=============================================================================
922 Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
924 Graphic3d_BndBox3d aBox;
925 addTransformed (aBox, theToIgnoreInfiniteFlag);
932 aResult.Update (aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
933 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
935 Standard_Real aLimMin = ShortRealFirst() + 1.0;
936 Standard_Real aLimMax = ShortRealLast() - 1.0;
937 gp_Pnt aMin = aResult.CornerMin();
938 gp_Pnt aMax = aResult.CornerMax();
939 if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin
940 && aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax)
942 //For structure which infinite in all three dimensions the Whole bounding box will be returned
948 //=============================================================================
949 //function : Identification
951 //=============================================================================
952 Standard_Integer Graphic3d_Structure::Identification() const
954 return myCStructure->Id;
957 //=============================================================================
958 //function : SetTransformPersistence
960 //=============================================================================
961 void Graphic3d_Structure::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
968 myCStructure->SetTransformPersistence (theTrsfPers);
971 //=============================================================================
974 //=============================================================================
975 void Graphic3d_Structure::Remove (const Standard_Address thePtr,
976 const Graphic3d_TypeOfConnection theType)
978 if (theType == Graphic3d_TOC_DESCENDANT)
980 RemoveDescendant (thePtr);
984 RemoveAncestor (thePtr);
988 //=============================================================================
989 //function : NewGroup
991 //=============================================================================
992 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
994 return myCStructure->NewGroup (this);
997 //=============================================================================
1000 //=============================================================================
1001 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1003 if (theGroup.IsNull()
1004 || theGroup->myStructure != this)
1009 myCStructure->RemoveGroup (theGroup);
1010 theGroup->myStructure = NULL;
1013 //=============================================================================
1014 //function : StructureManager
1016 //=============================================================================
1017 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1019 return myStructureManager;
1022 //=============================================================================
1023 //function : minMaxCoord
1025 //=============================================================================
1026 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
1028 Graphic3d_BndBox4f aBnd;
1029 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1031 aBnd.Combine (aGroupIter.Value()->BoundingBox());
1036 //=============================================================================
1037 //function : addTransformed
1039 //=============================================================================
1040 void Graphic3d_Structure::getBox (Graphic3d_BndBox3d& theBox,
1041 const Standard_Boolean theToIgnoreInfiniteFlag) const
1043 Graphic3d_BndBox4f aBoxF = minMaxCoord();
1044 if (aBoxF.IsValid())
1046 theBox = Graphic3d_BndBox3d (Graphic3d_Vec3d ((Standard_Real )aBoxF.CornerMin().x(),
1047 (Standard_Real )aBoxF.CornerMin().y(),
1048 (Standard_Real )aBoxF.CornerMin().z()),
1049 Graphic3d_Vec3d ((Standard_Real )aBoxF.CornerMax().x(),
1050 (Standard_Real )aBoxF.CornerMax().y(),
1051 (Standard_Real )aBoxF.CornerMax().z()));
1053 && !theToIgnoreInfiniteFlag)
1055 const Graphic3d_Vec3d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
1056 if (aDiagVec.SquareModulus() >= 500000.0 * 500000.0)
1058 // bounding borders of infinite line has been calculated as own point in center of this line
1059 theBox = Graphic3d_BndBox3d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
1063 theBox = Graphic3d_BndBox3d (Graphic3d_Vec3d (RealFirst(), RealFirst(), RealFirst()),
1064 Graphic3d_Vec3d (RealLast(), RealLast(), RealLast()));
1071 //=============================================================================
1072 //function : addTransformed
1074 //=============================================================================
1075 void Graphic3d_Structure::addTransformed (Graphic3d_BndBox3d& theBox,
1076 const Standard_Boolean theToIgnoreInfiniteFlag) const
1078 Graphic3d_BndBox3d aCombinedBox, aBox;
1079 getBox (aCombinedBox, theToIgnoreInfiniteFlag);
1081 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1083 const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )anIter.Value();
1084 aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1085 aCombinedBox.Combine (aBox);
1088 aBox = aCombinedBox;
1091 if (!myCStructure->Transformation().IsNull())
1093 TransformBoundaries (myCStructure->Transformation()->Trsf(),
1094 aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1095 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1098 // if box is still valid after transformation
1101 theBox.Combine (aBox);
1103 else // it was infinite, return untransformed
1105 theBox.Combine (aCombinedBox);
1110 //=============================================================================
1111 //function : Transforms
1113 //=============================================================================
1114 void Graphic3d_Structure::Transforms (const gp_Trsf& theTrsf,
1115 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
1116 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ)
1118 const Standard_Real aRL = RealLast();
1119 const Standard_Real aRF = RealFirst();
1123 if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1124 || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1129 theTrsf.Transforms (theNewX, theNewY, theNewZ);
1132 //=============================================================================
1133 //function : Transforms
1135 //=============================================================================
1136 void Graphic3d_Structure::TransformBoundaries (const gp_Trsf& theTrsf,
1137 Standard_Real& theXMin,
1138 Standard_Real& theYMin,
1139 Standard_Real& theZMin,
1140 Standard_Real& theXMax,
1141 Standard_Real& theYMax,
1142 Standard_Real& theZMax)
1144 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1146 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1147 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1149 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
1150 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1151 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1152 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1154 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
1155 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1156 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1157 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1159 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
1160 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1161 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1162 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1164 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
1165 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1166 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1167 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1169 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
1170 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1171 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1172 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1174 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
1175 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1176 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1177 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1187 //=============================================================================
1188 //function : Network
1190 //=============================================================================
1191 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
1192 const Graphic3d_TypeOfConnection theType,
1193 Graphic3d_MapOfStructure& theSet)
1195 Graphic3d_MapOfStructure aSetD, aSetA;
1196 theStructure->Descendants (aSetD);
1197 theStructure->Ancestors (aSetA);
1198 theSet.Add (theStructure);
1201 case Graphic3d_TOC_DESCENDANT:
1202 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
1204 Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
1207 case Graphic3d_TOC_ANCESTOR:
1208 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
1210 Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
1216 //=============================================================================
1217 //function : PrintNetwork
1219 //=============================================================================
1220 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
1221 const Graphic3d_TypeOfConnection theType)
1223 Graphic3d_MapOfStructure aSet;
1224 Graphic3d_Structure::Network (theStructure, theType, aSet);
1225 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
1227 std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
1229 std::cout << std::flush;
1232 //=============================================================================
1235 //=============================================================================
1236 void Graphic3d_Structure::Update (const bool theUpdateLayer) const
1243 myStructureManager->Update (theUpdateLayer ? myCStructure->ZLayer() : Graphic3d_ZLayerId_UNKNOWN);
1246 //=============================================================================
1247 //function : GraphicTransform
1249 //=============================================================================
1250 void Graphic3d_Structure::GraphicTransform (const Handle(Geom_Transformation)& theTrsf)
1252 myCStructure->SetTransformation (theTrsf);
1255 //=============================================================================
1256 //function : ComputeVisual
1258 //=============================================================================
1259 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
1261 return myComputeVisual;
1264 //=============================================================================
1265 //function : SetComputeVisual
1267 //=============================================================================
1268 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
1270 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
1271 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
1272 if (theVisual != Graphic3d_TOS_COMPUTED)
1274 myComputeVisual = theVisual;
1278 //=============================================================================
1279 //function : SetHLRValidation
1281 //=============================================================================
1282 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
1284 myCStructure->HLRValidation = theFlag ? 1 : 0;
1287 //=============================================================================
1288 //function : HLRValidation
1290 //=============================================================================
1291 Standard_Boolean Graphic3d_Structure::HLRValidation() const
1293 // Hidden parts stored in <me> are valid if :
1294 // 1/ the owner is defined.
1295 // 2/ they are not invalid.
1296 return myOwner != NULL
1297 && myCStructure->HLRValidation != 0;
1300 //=======================================================================
1301 //function : SetZLayer
1303 //=======================================================================
1304 void Graphic3d_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerId)
1306 // if the structure is not displayed, unable to change its display layer
1310 myStructureManager->ChangeZLayer (this, theLayerId);
1311 myCStructure->SetZLayer (theLayerId);
1314 //=======================================================================
1315 //function : GetZLayer
1317 //=======================================================================
1318 Graphic3d_ZLayerId Graphic3d_Structure::GetZLayer() const
1320 return myCStructure->ZLayer();
1323 //=======================================================================
1324 //function : SetClipPlanes
1326 //=======================================================================
1327 void Graphic3d_Structure::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
1329 myCStructure->SetClipPlanes (thePlanes);
1332 //=======================================================================
1333 //function : GetClipPlanes
1335 //=======================================================================
1336 const Handle(Graphic3d_SequenceOfHClipPlane)& Graphic3d_Structure::ClipPlanes() const
1338 return myCStructure->ClipPlanes();
1341 //=======================================================================
1342 //function : SetMutable
1344 //=======================================================================
1345 void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
1347 myCStructure->IsMutable = theIsMutable;
1350 //=======================================================================
1351 //function : IsMutable
1353 //=======================================================================
1354 Standard_Boolean Graphic3d_Structure::IsMutable() const
1356 return myCStructure->IsMutable;