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 <Quantity_Color.hxx>
31 #include "Graphic3d_Structure.pxx"
35 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Structure,Standard_Transient)
37 //=============================================================================
38 //function : Graphic3d_Structure
40 //=============================================================================
41 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager)
42 : myStructureManager(theManager.operator->()),
43 myComputeVisual (Graphic3d_TOS_ALL),
45 myVisual (Graphic3d_TOS_ALL)
47 myCStructure = theManager->GraphicDriver()->CreateStructure (theManager);
50 //=============================================================================
51 //function : Graphic3d_Structure
53 //=============================================================================
54 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
55 const Handle(Graphic3d_Structure)& thePrs)
56 : myStructureManager(theManager.operator->()),
57 myComputeVisual (thePrs->myComputeVisual),
58 myOwner (thePrs->myOwner),
59 myVisual (thePrs->myVisual)
61 myCStructure = thePrs->myCStructure->ShadowLink (theManager);
64 //=============================================================================
65 //function : ~Graphic3d_Structure
67 //=============================================================================
68 Graphic3d_Structure::~Graphic3d_Structure()
70 // as myStructureManager can be already destroyed,
71 // avoid attempts to access it
72 myStructureManager = NULL;
76 //=============================================================================
79 //=============================================================================
80 void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
82 if (IsDeleted()) return;
84 // clean groups in graphics driver at first
85 GraphicClear (theWithDestruction);
87 myCStructure->ContainsFacet = 0;
88 myStructureManager->Clear (this, theWithDestruction);
93 //=======================================================================
94 //function : CalculateBoundBox
95 //purpose : Calculates AABB of a structure.
96 //=======================================================================
97 void Graphic3d_Structure::CalculateBoundBox()
99 Graphic3d_BndBox3d aBox;
100 addTransformed (aBox, Standard_True);
101 myCStructure->ChangeBoundingBox() = aBox;
104 //=============================================================================
107 //=============================================================================
108 void Graphic3d_Structure::Remove()
110 if (IsDeleted()) return;
112 // clean groups in graphics driver at first; this is also should be done
113 // to avoid unwanted group cleaning in group's destructor
114 // Pass Standard_False to Clear(..) method to avoid updating in
115 // structure manager, it isn't necessary, besides of it structure manager
116 // could be already destroyed and invalid pointers used in structure;
117 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
119 aGroupIter.ChangeValue()->Clear (Standard_False);
122 Standard_Address APtr = (void *) this;
123 // It is necessary to remove the eventual pointer on the structure
124 // that can be destroyed, in the list of descendants
125 // of ancestors of this structure and in the list of ancestors
126 // of descendants of the same structure.
128 for (Standard_Integer aStructIdx = 1, aNbDesc = myDescendants.Size(); aStructIdx <= aNbDesc; ++aStructIdx)
130 ((Graphic3d_Structure *)myDescendants.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
133 for (Standard_Integer aStructIdx = 1, aNbAnces = myAncestors.Size(); aStructIdx <= aNbAnces; ++aStructIdx)
135 ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
138 // Destruction of me in the graphic library
139 const Standard_Integer aStructId = myCStructure->Id;
140 myCStructure->GraphicDriver()->RemoveIdentification(aStructId);
141 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
142 myCStructure.Nullify();
145 //=============================================================================
148 //=============================================================================
149 void Graphic3d_Structure::Display()
151 if (IsDeleted()) return;
153 if (!myCStructure->stick)
155 myCStructure->stick = 1;
156 myStructureManager->Display (this);
159 if (myCStructure->visible != 1)
161 myCStructure->visible = 1;
162 myCStructure->OnVisibilityChanged();
166 //=============================================================================
167 //function : SetIsForHighlight
169 //=============================================================================
170 void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight)
172 myCStructure->IsForHighlight = isForHighlight;
175 //=============================================================================
176 //function : SetDisplayPriority
178 //=============================================================================
179 void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
182 || thePriority == myCStructure->Priority)
187 myCStructure->PreviousPriority = myCStructure->Priority;
188 myCStructure->Priority = thePriority;
190 if (myCStructure->Priority != myCStructure->PreviousPriority)
192 Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
193 || (myCStructure->Priority < Structure_MIN_PRIORITY),
194 "Bad value for StructurePriority");
195 if (myCStructure->stick)
197 myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
202 //=============================================================================
203 //function : ResetDisplayPriority
205 //=============================================================================
206 void Graphic3d_Structure::ResetDisplayPriority()
209 || myCStructure->Priority == myCStructure->PreviousPriority)
214 const Standard_Integer aPriority = myCStructure->Priority;
215 myCStructure->Priority = myCStructure->PreviousPriority;
216 if (myCStructure->stick)
218 myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
222 //=============================================================================
223 //function : DisplayPriority
225 //=============================================================================
226 Standard_Integer Graphic3d_Structure::DisplayPriority() const
228 return myCStructure->Priority;
231 //=============================================================================
234 //=============================================================================
235 void Graphic3d_Structure::Erase()
242 if (myCStructure->stick)
244 myCStructure->stick = 0;
245 myStructureManager->Erase (this);
249 //=============================================================================
250 //function : Highlight
252 //=============================================================================
253 void Graphic3d_Structure::Highlight (const Handle(Graphic3d_PresentationAttributes)& theStyle,
254 const Standard_Boolean theToUpdateMgr)
261 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
263 myCStructure->GraphicHighlight (theStyle);
270 if (myCStructure->stick)
272 myStructureManager->Highlight (this);
278 //=============================================================================
279 //function : SetVisible
281 //=============================================================================
282 void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
284 if (IsDeleted()) return;
286 const unsigned isVisible = theValue ? 1 : 0;
287 if (myCStructure->visible == isVisible)
292 myCStructure->visible = isVisible;
293 myCStructure->OnVisibilityChanged();
297 //=============================================================================
298 //function : UnHighlight
300 //=============================================================================
301 void Graphic3d_Structure::UnHighlight()
303 if (IsDeleted()) return;
305 if (myCStructure->highlight)
307 myCStructure->highlight = 0;
309 myCStructure->GraphicUnhighlight();
310 myStructureManager->UnHighlight (this);
312 ResetDisplayPriority();
317 //=============================================================================
318 //function : HighlightStyle
320 //=============================================================================
321 const Handle(Graphic3d_PresentationAttributes)& Graphic3d_Structure::HighlightStyle() const
323 return myCStructure->HighlightStyle();
326 //=============================================================================
327 //function : IsDisplayed
329 //=============================================================================
330 Standard_Boolean Graphic3d_Structure::IsDisplayed() const
332 return myCStructure->stick ? Standard_True : Standard_False;
335 //=============================================================================
336 //function : IsDeleted
338 //=============================================================================
339 Standard_Boolean Graphic3d_Structure::IsDeleted() const
341 return myCStructure.IsNull();
344 //=============================================================================
345 //function : IsHighlighted
347 //=============================================================================
348 Standard_Boolean Graphic3d_Structure::IsHighlighted() const
350 return myCStructure->highlight ? Standard_True : Standard_False;
353 //=============================================================================
354 //function : IsVisible
356 //=============================================================================
357 Standard_Boolean Graphic3d_Structure::IsVisible() const
359 return myCStructure->visible ? Standard_True : Standard_False;
362 //=============================================================================
363 //function : IsTransformed
365 //=============================================================================
366 Standard_Boolean Graphic3d_Structure::IsTransformed() const
368 return !myCStructure->Transformation().IsNull()
369 && myCStructure->Transformation()->Form() != gp_Identity;
372 //=============================================================================
373 //function : ContainsFacet
375 //=============================================================================
376 Standard_Boolean Graphic3d_Structure::ContainsFacet() const
380 return Standard_False;
382 else if (myCStructure->ContainsFacet > 0)
384 // if one of groups contains at least one facet, the structure contains it too
385 return Standard_True;
388 // stop at the first descendant containing at least one facet
389 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
391 if (((const Graphic3d_Structure *)anIter.Value())->ContainsFacet())
393 return Standard_True;
396 return Standard_False;
399 //=============================================================================
402 //=============================================================================
403 Standard_Boolean Graphic3d_Structure::IsEmpty() const
407 return Standard_True;
410 // structure is empty:
411 // - if all these groups are empty
412 // - or if all groups are empty and all their descendants are empty
413 // - or if all its descendants are empty
414 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
416 if (!aGroupIter.Value()->IsEmpty())
418 return Standard_False;
422 // stop at the first non-empty descendant
423 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
425 if (!((const Graphic3d_Structure* )anIter.Value())->IsEmpty())
427 return Standard_False;
430 return Standard_True;
433 //=============================================================================
434 //function : GroupsWithFacet
436 //=============================================================================
437 void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
439 myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
440 if (myCStructure->ContainsFacet < 0)
442 myCStructure->ContainsFacet = 0;
446 //=============================================================================
449 //=============================================================================
450 void Graphic3d_Structure::Compute()
452 // Implemented by Presentation
455 //=============================================================================
458 //=============================================================================
459 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
461 // Implemented by Presentation
465 //=============================================================================
468 //=============================================================================
469 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
470 const Handle(Geom_Transformation)& )
472 // Implemented by Presentation
476 //=============================================================================
479 //=============================================================================
480 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
481 Handle(Graphic3d_Structure)& )
483 // Implemented by Presentation
486 //=============================================================================
489 //=============================================================================
490 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
491 const Handle(Geom_Transformation)& ,
492 Handle(Graphic3d_Structure)& )
494 // Implemented by Presentation
497 //=============================================================================
498 //function : ReCompute
500 //=============================================================================
501 void Graphic3d_Structure::ReCompute()
503 myStructureManager->ReCompute (this);
506 //=============================================================================
507 //function : ReCompute
509 //=============================================================================
510 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
512 myStructureManager->ReCompute (this, theProjector);
515 //=============================================================================
516 //function : SetInfiniteState
518 //=============================================================================
519 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
521 myCStructure->IsInfinite = theToSet ? 1 : 0;
524 //=============================================================================
525 //function : IsInfinite
527 //=============================================================================
528 Standard_Boolean Graphic3d_Structure::IsInfinite() const
531 || myCStructure->IsInfinite;
534 //=============================================================================
535 //function : GraphicClear
537 //=============================================================================
538 void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
540 if (myCStructure.IsNull())
545 // clean and empty each group
546 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
548 aGroupIter.ChangeValue()->Clear();
550 if (!theWithDestruction)
555 while (!myCStructure->Groups().IsEmpty())
557 Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
560 myCStructure->Clear();
563 //=============================================================================
564 //function : GraphicConnect
566 //=============================================================================
567 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
569 myCStructure->Connect (*theDaughter->myCStructure);
572 //=============================================================================
573 //function : GraphicDisconnect
575 //=============================================================================
576 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
578 myCStructure->Disconnect (*theDaughter->myCStructure);
581 //=============================================================================
584 //=============================================================================
585 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
587 return myCStructure->Groups();
590 //=============================================================================
591 //function : NumberOfGroups
593 //=============================================================================
594 Standard_Integer Graphic3d_Structure::NumberOfGroups() const
596 return myCStructure->Groups().Length();
599 //=============================================================================
600 //function : SetVisual
602 //=============================================================================
603 void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
606 || myVisual == theVisual)
611 if (!myCStructure->stick)
613 myVisual = theVisual;
614 SetComputeVisual (theVisual);
619 myVisual = theVisual;
620 SetComputeVisual (theVisual);
625 //=============================================================================
626 //function : SetZoomLimit
628 //=============================================================================
629 void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
630 const Standard_Real theLimitSup)
634 Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
635 "Bad value for ZoomLimit inf");
636 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
637 "Bad value for ZoomLimit sup");
638 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
639 "ZoomLimit sup < ZoomLimit inf");
642 //=============================================================================
645 //=============================================================================
646 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
651 //=============================================================================
652 //function : AcceptConnection
654 //=============================================================================
655 Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
656 const Handle(Graphic3d_Structure)& theStructure2,
657 const Graphic3d_TypeOfConnection theType)
660 Graphic3d_MapOfStructure aSet;
661 Graphic3d_Structure::Network (theStructure2, theType, aSet);
662 return !aSet.Contains (theStructure1);
665 //=============================================================================
666 //function : Ancestors
668 //=============================================================================
669 void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
671 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myAncestors); anIter.More(); anIter.Next())
673 theSet.Add ((Graphic3d_Structure* )anIter.Value());
677 //=============================================================================
678 //function : SetOwner
680 //=============================================================================
681 void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
686 //=============================================================================
689 //=============================================================================
690 Standard_Address Graphic3d_Structure::Owner() const
695 //=============================================================================
696 //function : Descendants
698 //=============================================================================
699 void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
701 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
703 theSet.Add ((Graphic3d_Structure* )anIter.Value());
707 //=============================================================================
708 //function : AppendAncestor
710 //=============================================================================
711 Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor)
713 const Standard_Integer aSize = myAncestors.Size();
715 return myAncestors.Add (theAncestor) > aSize; // new object
718 //=============================================================================
719 //function : AppendDescendant
721 //=============================================================================
722 Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant)
724 const Standard_Integer aSize = myDescendants.Size();
726 return myDescendants.Add (theDescendant) > aSize; // new object
729 //=============================================================================
730 //function : RemoveAncestor
732 //=============================================================================
733 Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor)
735 const Standard_Integer anIndex = myAncestors.FindIndex (theAncestor);
739 myAncestors.Swap (anIndex, myAncestors.Size());
740 myAncestors.RemoveLast();
743 return anIndex != 0; // object was found
746 //=============================================================================
747 //function : RemoveDescendant
749 //=============================================================================
750 Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant)
752 const Standard_Integer anIndex = myDescendants.FindIndex (theDescendant);
756 myDescendants.Swap (anIndex, myDescendants.Size());
757 myDescendants.RemoveLast();
760 return anIndex != 0; // object was found
763 //=============================================================================
766 //=============================================================================
767 void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
768 const Graphic3d_TypeOfConnection theType,
769 const Standard_Boolean theWithCheck)
778 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
783 const Standard_Address aStructure = theStructure.operator->();
785 if (theType == Graphic3d_TOC_DESCENDANT)
787 if (!AppendDescendant (aStructure))
793 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
795 GraphicConnect (theStructure);
796 myStructureManager->Connect (this, theStructure);
800 else // Graphic3d_TOC_ANCESTOR
802 if (!AppendAncestor (aStructure))
808 theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
810 // myStructureManager->Connect is called in case if connection between parent and child
814 //=============================================================================
815 //function : Disconnect
817 //=============================================================================
818 void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
825 const Standard_Address aStructure = theStructure.operator->();
827 if (RemoveDescendant (aStructure))
829 theStructure->Disconnect (this);
831 GraphicDisconnect (theStructure);
832 myStructureManager->Disconnect (this, theStructure);
837 else if (RemoveAncestor (aStructure))
839 theStructure->Disconnect (this);
842 // no call of myStructureManager->Disconnect in case of an ancestor
846 //=============================================================================
847 //function : DisconnectAll
849 //=============================================================================
850 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
852 if (IsDeleted()) return;
856 case Graphic3d_TOC_DESCENDANT:
858 for (Standard_Integer anIdx = 1, aLength = myDescendants.Size(); anIdx <= aLength; ++anIdx)
860 // Value (1) instead of Value (i) as myDescendants
862 // Graphic3d_Structure::Disconnect (AStructure)
863 // that takes AStructure from myDescendants
864 ((Graphic3d_Structure* )(myDescendants.FindKey (1)))->Disconnect (this);
868 case Graphic3d_TOC_ANCESTOR:
870 for (Standard_Integer anIdx = 1, aLength = myAncestors.Size(); anIdx <= aLength; ++anIdx)
872 // Value (1) instead of Value (i) as myAncestors
874 // Graphic3d_Structure::Disconnect (AStructure)
875 // that takes AStructure from myAncestors
876 ((Graphic3d_Structure* )(myAncestors.FindKey (1)))->Disconnect (this);
883 //=============================================================================
884 //function : SetTransform
886 //=============================================================================
887 void Graphic3d_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf)
889 if (IsDeleted()) return;
891 const Standard_Boolean wasTransformed = IsTransformed();
893 if (!theTrsf.IsNull()
894 && theTrsf->Trsf().Form() == gp_Identity)
896 myCStructure->SetTransformation (Handle(Geom_Transformation)());
900 myCStructure->SetTransformation (theTrsf);
903 // If transformation, no validation of hidden already calculated parts
904 if (IsTransformed() || (!IsTransformed() && wasTransformed))
909 myStructureManager->SetTransform (this, theTrsf);
914 //=============================================================================
915 //function : MinMaxValues
917 //=============================================================================
918 Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
920 Graphic3d_BndBox3d aBox;
921 addTransformed (aBox, theToIgnoreInfiniteFlag);
928 aResult.Update (aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
929 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
931 Standard_Real aLimMin = ShortRealFirst() + 1.0;
932 Standard_Real aLimMax = ShortRealLast() - 1.0;
933 gp_Pnt aMin = aResult.CornerMin();
934 gp_Pnt aMax = aResult.CornerMax();
935 if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin
936 && aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax)
938 //For structure which infinite in all three dimensions the Whole bounding box will be returned
944 //=============================================================================
945 //function : Identification
947 //=============================================================================
948 Standard_Integer Graphic3d_Structure::Identification() const
950 return myCStructure->Id;
953 //=============================================================================
954 //function : SetTransformPersistence
956 //=============================================================================
957 void Graphic3d_Structure::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
964 myCStructure->SetTransformPersistence (theTrsfPers);
967 //=============================================================================
970 //=============================================================================
971 void Graphic3d_Structure::Remove (const Standard_Address thePtr,
972 const Graphic3d_TypeOfConnection theType)
974 if (theType == Graphic3d_TOC_DESCENDANT)
976 RemoveDescendant (thePtr);
980 RemoveAncestor (thePtr);
984 //=============================================================================
985 //function : NewGroup
987 //=============================================================================
988 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
990 return myCStructure->NewGroup (this);
993 //=============================================================================
996 //=============================================================================
997 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
999 if (theGroup.IsNull()
1000 || theGroup->myStructure != this)
1005 myCStructure->RemoveGroup (theGroup);
1006 theGroup->myStructure = NULL;
1009 //=============================================================================
1010 //function : StructureManager
1012 //=============================================================================
1013 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1015 return myStructureManager;
1018 //=============================================================================
1019 //function : minMaxCoord
1021 //=============================================================================
1022 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
1024 Graphic3d_BndBox4f aBnd;
1025 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1027 aBnd.Combine (aGroupIter.Value()->BoundingBox());
1032 //=============================================================================
1033 //function : addTransformed
1035 //=============================================================================
1036 void Graphic3d_Structure::getBox (Graphic3d_BndBox3d& theBox,
1037 const Standard_Boolean theToIgnoreInfiniteFlag) const
1039 Graphic3d_BndBox4f aBoxF = minMaxCoord();
1040 if (aBoxF.IsValid())
1042 theBox = Graphic3d_BndBox3d (Graphic3d_Vec3d ((Standard_Real )aBoxF.CornerMin().x(),
1043 (Standard_Real )aBoxF.CornerMin().y(),
1044 (Standard_Real )aBoxF.CornerMin().z()),
1045 Graphic3d_Vec3d ((Standard_Real )aBoxF.CornerMax().x(),
1046 (Standard_Real )aBoxF.CornerMax().y(),
1047 (Standard_Real )aBoxF.CornerMax().z()));
1049 && !theToIgnoreInfiniteFlag)
1051 const Graphic3d_Vec3d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
1052 if (aDiagVec.SquareModulus() >= 500000.0 * 500000.0)
1054 // bounding borders of infinite line has been calculated as own point in center of this line
1055 theBox = Graphic3d_BndBox3d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
1059 theBox = Graphic3d_BndBox3d (Graphic3d_Vec3d (RealFirst(), RealFirst(), RealFirst()),
1060 Graphic3d_Vec3d (RealLast(), RealLast(), RealLast()));
1067 //=============================================================================
1068 //function : addTransformed
1070 //=============================================================================
1071 void Graphic3d_Structure::addTransformed (Graphic3d_BndBox3d& theBox,
1072 const Standard_Boolean theToIgnoreInfiniteFlag) const
1074 Graphic3d_BndBox3d aCombinedBox, aBox;
1075 getBox (aCombinedBox, theToIgnoreInfiniteFlag);
1077 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1079 const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )anIter.Value();
1080 aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1081 aCombinedBox.Combine (aBox);
1084 aBox = aCombinedBox;
1087 if (!myCStructure->Transformation().IsNull())
1089 TransformBoundaries (myCStructure->Transformation()->Trsf(),
1090 aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1091 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1094 // if box is still valid after transformation
1097 theBox.Combine (aBox);
1099 else // it was infinite, return untransformed
1101 theBox.Combine (aCombinedBox);
1106 //=============================================================================
1107 //function : Transforms
1109 //=============================================================================
1110 void Graphic3d_Structure::Transforms (const gp_Trsf& theTrsf,
1111 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
1112 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ)
1114 const Standard_Real aRL = RealLast();
1115 const Standard_Real aRF = RealFirst();
1119 if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1120 || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1125 theTrsf.Transforms (theNewX, theNewY, theNewZ);
1128 //=============================================================================
1129 //function : Transforms
1131 //=============================================================================
1132 void Graphic3d_Structure::TransformBoundaries (const gp_Trsf& theTrsf,
1133 Standard_Real& theXMin,
1134 Standard_Real& theYMin,
1135 Standard_Real& theZMin,
1136 Standard_Real& theXMax,
1137 Standard_Real& theYMax,
1138 Standard_Real& theZMax)
1140 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1142 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1143 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1145 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
1146 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1147 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1148 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1150 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
1151 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1152 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1153 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1155 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
1156 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1157 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1158 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1160 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
1161 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1162 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1163 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1165 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
1166 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1167 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1168 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1170 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
1171 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1172 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1173 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1183 //=============================================================================
1184 //function : Network
1186 //=============================================================================
1187 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
1188 const Graphic3d_TypeOfConnection theType,
1189 Graphic3d_MapOfStructure& theSet)
1191 Graphic3d_MapOfStructure aSetD, aSetA;
1192 theStructure->Descendants (aSetD);
1193 theStructure->Ancestors (aSetA);
1194 theSet.Add (theStructure);
1197 case Graphic3d_TOC_DESCENDANT:
1198 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
1200 Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
1203 case Graphic3d_TOC_ANCESTOR:
1204 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
1206 Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
1212 //=============================================================================
1213 //function : PrintNetwork
1215 //=============================================================================
1216 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
1217 const Graphic3d_TypeOfConnection theType)
1219 Graphic3d_MapOfStructure aSet;
1220 Graphic3d_Structure::Network (theStructure, theType, aSet);
1221 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
1223 std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
1225 std::cout << std::flush;
1228 //=============================================================================
1231 //=============================================================================
1232 void Graphic3d_Structure::Update (const bool theUpdateLayer) const
1239 myStructureManager->Update (theUpdateLayer ? myCStructure->ZLayer() : Graphic3d_ZLayerId_UNKNOWN);
1242 //=============================================================================
1243 //function : GraphicTransform
1245 //=============================================================================
1246 void Graphic3d_Structure::GraphicTransform (const Handle(Geom_Transformation)& theTrsf)
1248 myCStructure->SetTransformation (theTrsf);
1251 //=============================================================================
1252 //function : ComputeVisual
1254 //=============================================================================
1255 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
1257 return myComputeVisual;
1260 //=============================================================================
1261 //function : SetComputeVisual
1263 //=============================================================================
1264 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
1266 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
1267 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
1268 if (theVisual != Graphic3d_TOS_COMPUTED)
1270 myComputeVisual = theVisual;
1274 //=============================================================================
1275 //function : SetHLRValidation
1277 //=============================================================================
1278 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
1280 myCStructure->HLRValidation = theFlag ? 1 : 0;
1283 //=============================================================================
1284 //function : HLRValidation
1286 //=============================================================================
1287 Standard_Boolean Graphic3d_Structure::HLRValidation() const
1289 // Hidden parts stored in <me> are valid if :
1290 // 1/ the owner is defined.
1291 // 2/ they are not invalid.
1292 return myOwner != NULL
1293 && myCStructure->HLRValidation != 0;
1296 //=======================================================================
1297 //function : SetZLayer
1299 //=======================================================================
1300 void Graphic3d_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerId)
1302 // if the structure is not displayed, unable to change its display layer
1306 myStructureManager->ChangeZLayer (this, theLayerId);
1307 myCStructure->SetZLayer (theLayerId);
1310 //=======================================================================
1311 //function : GetZLayer
1313 //=======================================================================
1314 Graphic3d_ZLayerId Graphic3d_Structure::GetZLayer() const
1316 return myCStructure->ZLayer();
1319 //=======================================================================
1320 //function : SetClipPlanes
1322 //=======================================================================
1323 void Graphic3d_Structure::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
1325 myCStructure->SetClipPlanes (thePlanes);
1328 //=======================================================================
1329 //function : GetClipPlanes
1331 //=======================================================================
1332 const Handle(Graphic3d_SequenceOfHClipPlane)& Graphic3d_Structure::ClipPlanes() const
1334 return myCStructure->ClipPlanes();
1337 //=======================================================================
1338 //function : SetMutable
1340 //=======================================================================
1341 void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
1343 myCStructure->IsMutable = theIsMutable;
1346 //=======================================================================
1347 //function : IsMutable
1349 //=======================================================================
1350 Standard_Boolean Graphic3d_Structure::IsMutable() const
1352 return myCStructure->IsMutable;