1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Graphic3d_Structure.ixx>
17 #include <Graphic3d_Structure.pxx>
19 #include <Graphic3d_GraphicDriver.hxx>
20 #include <Graphic3d_MaterialAspect.hxx>
22 #include <Graphic3d_MapOfStructure.hxx>
23 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
25 #include <Quantity_Color.hxx>
26 #include <TColStd_Array2OfReal.hxx>
27 #include <Graphic3d_TextureMap.hxx>
29 #include <Aspect_PolygonOffsetMode.hxx>
33 //=============================================================================
34 //function : Graphic3d_Structure
36 //=============================================================================
37 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager)
38 : myStructureManager (theManager.operator->()),
39 myFirstStructureManager (theManager.operator->()),
40 myComputeVisual (Graphic3d_TOS_ALL),
41 myHighlightColor (Quantity_NOC_WHITE),
42 myHighlightMethod (Aspect_TOHM_COLOR),
44 myVisual (Graphic3d_TOS_ALL)
46 myCStructure = theManager->GraphicDriver()->Structure (theManager);
49 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
50 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
51 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
52 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
53 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
54 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
56 // update the associated CStructure
57 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
60 //=============================================================================
61 //function : Graphic3d_Structure
63 //=============================================================================
64 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
65 const Handle(Graphic3d_Structure)& thePrs)
66 : myStructureManager (theManager.operator->()),
67 myFirstStructureManager (theManager.operator->()),
68 myComputeVisual (thePrs->myComputeVisual),
69 myHighlightColor (thePrs->myHighlightColor),
70 myHighlightMethod (thePrs->myHighlightMethod),
71 myOwner (thePrs->myOwner),
72 myVisual (thePrs->myVisual)
74 myCStructure = thePrs->myCStructure->ShadowLink (theManager);
77 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
78 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
79 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
80 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
81 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
82 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
84 // update the associated CStructure
85 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
88 //=============================================================================
91 //=============================================================================
92 void Graphic3d_Structure::Destroy()
94 // as myFirstStructureManager can be already destroyed,
95 // avoid attempts to access it
96 myFirstStructureManager = NULL;
100 //=============================================================================
103 //=============================================================================
104 void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
106 if (IsDeleted()) return;
108 // clean groups in graphics driver at first
109 GraphicClear (theWithDestruction);
111 myCStructure->ContainsFacet = 0;
112 myStructureManager->Clear (this, theWithDestruction);
117 //=======================================================================
118 //function : CalculateBoundBox
119 //purpose : Calculates AABB of a structure.
120 //=======================================================================
121 void Graphic3d_Structure::CalculateBoundBox()
123 Graphic3d_BndBox4d aBox;
124 addTransformed (aBox, Standard_True);
125 if (aBox.IsValid() && myCStructure->TransformPersistence.Flag == 0)
127 Graphic3d_Vec4 aMinPt (RealToShortReal (aBox.CornerMin().x()),
128 RealToShortReal (aBox.CornerMin().y()),
129 RealToShortReal (aBox.CornerMin().z()),
131 Graphic3d_Vec4 aMaxPt (RealToShortReal (aBox.CornerMax().x()),
132 RealToShortReal (aBox.CornerMax().y()),
133 RealToShortReal (aBox.CornerMax().z()),
135 myCStructure->ChangeBoundingBox() = Graphic3d_BndBox4f (aMinPt, aMaxPt);
139 myCStructure->ChangeBoundingBox().Clear();
143 //=============================================================================
146 //=============================================================================
147 void Graphic3d_Structure::Remove()
149 if (IsDeleted()) return;
151 // clean groups in graphics driver at first; this is also should be done
152 // to avoid unwanted group cleaning in group's destructor
153 // Pass Standard_False to Clear(..) method to avoid updating in
154 // structure manager, it isn't necessary, besides of it structure manager
155 // could be already destroyed and invalid pointers used in structure;
156 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
158 aGroupIter.ChangeValue()->Clear (Standard_False);
161 Standard_Address APtr = (void *) this;
162 // It is necessary to remove the eventual pointer on the structure
163 // that can be destroyed, in the list of descendants
164 // of ancestors of this structure and in the list of ancestors
165 // of descendants of the same structure.
167 const Standard_Integer aNbDesc = myDescendants.Length();
168 for (Standard_Integer aStructIter = 1; aStructIter <= aNbDesc; ++aStructIter)
170 ((Graphic3d_Structure *)(myDescendants.ChangeValue (aStructIter)))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
173 const Standard_Integer aNbAnces = myAncestors.Length();
174 for (Standard_Integer aStructIter = 1; aStructIter <= aNbAnces; ++aStructIter)
176 ((Graphic3d_Structure *)(myAncestors.ChangeValue (aStructIter)))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
179 // Destruction of me in the graphic library
180 const Standard_Integer aStructId = myCStructure->Id;
181 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
182 myCStructure.Nullify();
184 // Liberation of the identification if the destroyed structure
185 // in the first manager that performs creation of the structure.
186 if (myFirstStructureManager != NULL)
188 myFirstStructureManager->Remove (aStructId);
192 //=============================================================================
195 //=============================================================================
196 void Graphic3d_Structure::Display()
198 if (IsDeleted()) return;
200 if (!myCStructure->stick)
202 myCStructure->stick = 1;
203 myStructureManager->Display (this);
206 myCStructure->visible = 1;
209 //=============================================================================
210 //function : SetIsForHighlight
212 //=============================================================================
213 void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight)
215 myCStructure->IsForHighlight = isForHighlight;
218 //=============================================================================
221 //=============================================================================
222 void Graphic3d_Structure::Display (const Standard_Integer thePriority)
224 if (IsDeleted()) return;
226 SetDisplayPriority (thePriority);
228 if (!myCStructure->stick)
230 myCStructure->stick = 1;
231 myStructureManager->Display (this);
234 myCStructure->visible = 1;
237 //=============================================================================
238 //function : SetDisplayPriority
240 //=============================================================================
241 void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
244 || thePriority == myCStructure->Priority)
249 myCStructure->PreviousPriority = myCStructure->Priority;
250 myCStructure->Priority = thePriority;
252 if (myCStructure->Priority != myCStructure->PreviousPriority)
254 Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
255 || (myCStructure->Priority < Structure_MIN_PRIORITY),
256 "Bad value for StructurePriority");
257 if (myCStructure->stick)
259 myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
264 //=============================================================================
265 //function : ResetDisplayPriority
267 //=============================================================================
268 void Graphic3d_Structure::ResetDisplayPriority()
271 || myCStructure->Priority == myCStructure->PreviousPriority)
276 const Standard_Integer aPriority = myCStructure->Priority;
277 myCStructure->Priority = myCStructure->PreviousPriority;
278 if (myCStructure->stick)
280 myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
284 //=============================================================================
285 //function : DisplayPriority
287 //=============================================================================
288 Standard_Integer Graphic3d_Structure::DisplayPriority() const
290 return myCStructure->Priority;
293 //=============================================================================
296 //=============================================================================
297 void Graphic3d_Structure::Erase()
304 if (myCStructure->stick)
306 myCStructure->stick = 0;
307 myStructureManager->Erase (this);
311 //=============================================================================
312 //function : Highlight
314 //=============================================================================
315 void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod theMethod)
322 // Highlight on already Highlighted structure.
323 if (myCStructure->highlight)
325 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
326 if (anUpdateMode == Aspect_TOU_WAIT)
332 // To avoid call of method : Update()
333 // Not useful and can be costly.
334 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
336 myStructureManager->SetUpdateMode (anUpdateMode);
340 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
342 GraphicHighlight (theMethod);
343 if (myCStructure->stick)
345 myStructureManager->Highlight (this, theMethod);
351 //=============================================================================
352 //function : SetHighlightColor
354 //=============================================================================
355 void Graphic3d_Structure::SetHighlightColor (const Quantity_Color& theColor)
362 if (!myCStructure->highlight)
364 myHighlightColor = theColor;
368 // Change highlight color on already Highlighted structure.
369 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
370 if (anUpdateMode == Aspect_TOU_WAIT)
376 // To avoid call of method : Update()
377 // Not useful and can be costly.
378 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
380 myStructureManager->SetUpdateMode (anUpdateMode);
382 myHighlightColor = theColor;
383 Highlight (myHighlightMethod);
386 //=============================================================================
387 //function : SetVisible
389 //=============================================================================
390 void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
392 if (IsDeleted()) return;
394 myCStructure->visible = theValue ? 1 : 0;
395 myCStructure->UpdateNamedStatus();
399 //=============================================================================
402 //=============================================================================
403 void Graphic3d_Structure::SetPick (const Standard_Boolean theValue)
405 if (IsDeleted ()) return;
407 myCStructure->pick = theValue ? 1 : 0;
408 myCStructure->UpdateNamedStatus();
412 myStructureManager->Detectable (this);
416 myStructureManager->Undetectable (this);
421 //=============================================================================
422 //function : UnHighlight
424 //=============================================================================
425 void Graphic3d_Structure::UnHighlight()
427 if (IsDeleted()) return;
429 if (myCStructure->highlight)
431 myCStructure->highlight = 0;
433 GraphicUnHighlight();
434 myStructureManager->UnHighlight (this);
436 ResetDisplayPriority();
441 //=============================================================================
442 //function : HighlightColor
444 //=============================================================================
445 const Quantity_Color& Graphic3d_Structure::HighlightColor() const
447 return myHighlightColor;
450 //=============================================================================
451 //function : IsDisplayed
453 //=============================================================================
454 Standard_Boolean Graphic3d_Structure::IsDisplayed() const
456 return myCStructure->stick ? Standard_True : Standard_False;
459 //=============================================================================
460 //function : IsDeleted
462 //=============================================================================
463 Standard_Boolean Graphic3d_Structure::IsDeleted() const
465 return myCStructure.IsNull();
468 //=============================================================================
469 //function : IsHighlighted
471 //=============================================================================
472 Standard_Boolean Graphic3d_Structure::IsHighlighted() const
474 return myCStructure->highlight ? Standard_True : Standard_False;
477 //=============================================================================
478 //function : IsSelectable
480 //=============================================================================
481 Standard_Boolean Graphic3d_Structure::IsSelectable() const
483 return myCStructure->pick ? Standard_True : Standard_False;
486 //=============================================================================
487 //function : IsVisible
489 //=============================================================================
490 Standard_Boolean Graphic3d_Structure::IsVisible() const
492 return myCStructure->visible ? Standard_True : Standard_False;
495 //=============================================================================
496 //function : IsRotated
498 //=============================================================================
499 Standard_Boolean Graphic3d_Structure::IsRotated() const
501 // A somewhat light test !
502 return myCStructure->Transformation[0][1] != 0.0
503 || myCStructure->Transformation[0][2] != 0.0
504 || myCStructure->Transformation[1][0] != 0.0
505 || myCStructure->Transformation[1][2] != 0.0
506 || myCStructure->Transformation[2][0] != 0.0
507 || myCStructure->Transformation[2][1] != 0.0;
510 //=============================================================================
511 //function : IsTransformed
513 //=============================================================================
514 Standard_Boolean Graphic3d_Structure::IsTransformed() const
516 Standard_Boolean aResult = Standard_False;
517 for (Standard_Integer i = 0; i <= 3 && !aResult; ++i)
519 for (Standard_Integer j = 0; j <= 3 && !aResult; ++j)
522 aResult = myCStructure->Transformation[i][j] != 1.0;
524 aResult = myCStructure->Transformation[i][j] != 0.0;
530 //=============================================================================
531 //function : ContainsFacet
533 //=============================================================================
534 Standard_Boolean Graphic3d_Structure::ContainsFacet() const
538 return Standard_False;
540 else if (myCStructure->ContainsFacet > 0)
542 // if one of groups contains at least one facet, the structure contains it too
543 return Standard_True;
546 // stop at the first descendant containing at least one facet
547 const Standard_Integer aNbDesc = myDescendants.Length();
548 for (Standard_Integer aStructIter = 1; aStructIter <= aNbDesc; ++aStructIter)
550 if (((const Graphic3d_Structure *)(myDescendants.Value (aStructIter)))->ContainsFacet())
552 return Standard_True;
555 return Standard_False;
558 //=============================================================================
561 //=============================================================================
562 Standard_Boolean Graphic3d_Structure::IsEmpty() const
566 return Standard_True;
569 // structure is empty:
570 // - if all these groups are empty
571 // - or if all groups are empty and all their descendants are empty
572 // - or if all its descendants are empty
573 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
575 if (!aGroupIter.Value()->IsEmpty())
577 return Standard_False;
581 // stop at the first non-empty descendant
582 const Standard_Integer aNbDesc = myDescendants.Length();
583 for (Standard_Integer aDescIter = 1; aDescIter <= aNbDesc; ++aDescIter)
585 if (!((const Graphic3d_Structure* )(myDescendants.Value (aDescIter)))->IsEmpty())
587 return Standard_False;
590 return Standard_True;
593 //=============================================================================
594 //function : PrimitivesAspect
596 //=============================================================================
597 void Graphic3d_Structure::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& theAspLine,
598 Handle(Graphic3d_AspectText3d)& theAspText,
599 Handle(Graphic3d_AspectMarker3d)& theAspMarker,
600 Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
602 theAspLine = Line3dAspect();
603 theAspText = Text3dAspect();
604 theAspMarker = Marker3dAspect();
605 theAspFill = FillArea3dAspect();
608 //=============================================================================
609 //function : GroupsWithFacet
611 //=============================================================================
612 void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
614 myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
615 if (myCStructure->ContainsFacet < 0)
617 myCStructure->ContainsFacet = 0;
621 //=============================================================================
624 //=============================================================================
625 void Graphic3d_Structure::Compute()
627 // Implemented by Presentation
630 //=============================================================================
633 //=============================================================================
634 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
636 // Implemented by Presentation
640 //=============================================================================
643 //=============================================================================
644 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
645 const TColStd_Array2OfReal& )
647 // Implemented by Presentation
651 //=============================================================================
654 //=============================================================================
655 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
656 Handle(Graphic3d_Structure)& )
658 // Implemented by Presentation
661 //=============================================================================
664 //=============================================================================
665 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
666 const TColStd_Array2OfReal& ,
667 Handle(Graphic3d_Structure)& )
669 // Implemented by Presentation
672 //=============================================================================
673 //function : ReCompute
675 //=============================================================================
676 void Graphic3d_Structure::ReCompute()
678 myStructureManager->ReCompute (this);
681 //=============================================================================
682 //function : ReCompute
684 //=============================================================================
685 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
687 myStructureManager->ReCompute (this, theProjector);
690 //=============================================================================
691 //function : SetInfiniteState
693 //=============================================================================
694 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
696 myCStructure->IsInfinite = theToSet ? 1 : 0;
699 //=============================================================================
700 //function : IsInfinite
702 //=============================================================================
703 Standard_Boolean Graphic3d_Structure::IsInfinite() const
706 || myCStructure->IsInfinite;
709 //=============================================================================
710 //function : GraphicClear
712 //=============================================================================
713 void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
715 if (myCStructure.IsNull())
720 // clean and empty each group
721 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
723 aGroupIter.ChangeValue()->Clear();
725 if (!theWithDestruction)
730 while (!myCStructure->Groups().IsEmpty())
732 Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
735 myCStructure->Clear();
738 //=============================================================================
739 //function : GraphicConnect
741 //=============================================================================
742 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
744 myCStructure->Connect (*theDaughter->myCStructure);
747 //=============================================================================
748 //function : GraphicDisconnect
750 //=============================================================================
751 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
753 myCStructure->Disconnect (*theDaughter->myCStructure);
756 //=============================================================================
757 //function : Line3dAspect
759 //=============================================================================
760 Handle(Graphic3d_AspectLine3d) Graphic3d_Structure::Line3dAspect() const
762 const Standard_Real anRGB[3] =
764 Standard_Real (myCStructure->ContextLine.Color.r),
765 Standard_Real (myCStructure->ContextLine.Color.g),
766 Standard_Real (myCStructure->ContextLine.Color.b)
768 Quantity_Color aColor;
769 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
770 Aspect_TypeOfLine aLType = Aspect_TypeOfLine (myCStructure->ContextLine.LineType);
771 Standard_Real aWidth = Standard_Real (myCStructure->ContextLine.Width);
773 Handle(Graphic3d_AspectLine3d) anAspLine = new Graphic3d_AspectLine3d (aColor, aLType, aWidth);
774 anAspLine->SetShaderProgram (myCStructure->ContextLine.ShaderProgram);
778 //=============================================================================
779 //function : Text3dAspect
781 //=============================================================================
782 Handle(Graphic3d_AspectText3d) Graphic3d_Structure::Text3dAspect() const
784 const Standard_Real anRGB[3] =
786 Standard_Real (myCStructure->ContextText.Color.r),
787 Standard_Real (myCStructure->ContextText.Color.g),
788 Standard_Real (myCStructure->ContextText.Color.b)
790 Quantity_Color aColor;
791 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
792 Standard_CString aFont = Standard_CString (myCStructure->ContextText.Font);
793 Standard_Real anExpansion = Standard_Real (myCStructure->ContextText.Expan);
794 Standard_Real aSpace = Standard_Real (myCStructure->ContextText.Space);
795 Aspect_TypeOfStyleText aStyle = Aspect_TypeOfStyleText (myCStructure->ContextText.Style);
796 Aspect_TypeOfDisplayText aDispType = Aspect_TypeOfDisplayText (myCStructure->ContextText.DisplayType);
798 Handle(Graphic3d_AspectText3d) anAspText = new Graphic3d_AspectText3d (aColor, aFont, anExpansion, aSpace, aStyle, aDispType);
799 anAspText->SetShaderProgram (myCStructure->ContextText.ShaderProgram);
803 //=============================================================================
804 //function : Marker3dAspect
806 //=============================================================================
807 Handle(Graphic3d_AspectMarker3d) Graphic3d_Structure::Marker3dAspect() const
809 const Standard_Real anRGB[3] =
811 Standard_Real (myCStructure->ContextMarker.Color.r),
812 Standard_Real (myCStructure->ContextMarker.Color.g),
813 Standard_Real (myCStructure->ContextMarker.Color.b)
815 Quantity_Color aColor;
816 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
817 Aspect_TypeOfMarker aMType = myCStructure->ContextMarker.MarkerType;
818 Standard_Real aScale = Standard_Real (myCStructure->ContextMarker.Scale);
820 Handle(Graphic3d_AspectMarker3d) anAspMarker = new Graphic3d_AspectMarker3d (aMType, aColor, aScale);
821 anAspMarker->SetShaderProgram (myCStructure->ContextMarker.ShaderProgram);
825 //=============================================================================
826 //function : FillArea3dAspect
828 //=============================================================================
829 Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect() const
832 Graphic3d_MaterialAspect aBack;
833 aBack.SetShininess (Standard_Real (myCStructure->ContextFillArea.Back.Shininess));
834 aBack.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Back.Ambient));
835 aBack.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Back.Diffuse));
836 aBack.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Back.Specular));
837 aBack.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Back.Transparency));
838 aBack.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Back.Emission));
839 if (myCStructure->ContextFillArea.Back.IsAmbient == 1)
840 aBack.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
842 aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
843 if (myCStructure->ContextFillArea.Back.IsDiffuse == 1)
844 aBack.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
846 aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
847 if (myCStructure->ContextFillArea.Back.IsSpecular == 1)
848 aBack.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
850 aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
851 if (myCStructure->ContextFillArea.Back.IsEmission == 1)
852 aBack.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
854 aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
856 Quantity_Color aColor (Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.r),
857 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.g),
858 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.b), Quantity_TOC_RGB);
859 aBack.SetSpecularColor (aColor);
861 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.r),
862 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.g),
863 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.b), Quantity_TOC_RGB);
864 aBack.SetAmbientColor (aColor);
866 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.r),
867 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.g),
868 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.b), Quantity_TOC_RGB);
869 aBack.SetDiffuseColor (aColor);
871 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.r),
872 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.g),
873 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.b), Quantity_TOC_RGB);
874 aBack.SetEmissiveColor (aColor);
876 aBack.SetEnvReflexion (myCStructure->ContextFillArea.Back.EnvReflexion);
877 aBack.SetMaterialType (myCStructure->ContextFillArea.Back.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
880 Graphic3d_MaterialAspect aFront;
881 aFront.SetShininess (Standard_Real (myCStructure->ContextFillArea.Front.Shininess));
882 aFront.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Front.Ambient));
883 aFront.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Front.Diffuse));
884 aFront.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Front.Specular));
885 aFront.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Front.Transparency));
886 aFront.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Front.Emission));
887 if (myCStructure->ContextFillArea.Front.IsAmbient == 1)
888 aFront.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
890 aFront.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
891 if (myCStructure->ContextFillArea.Front.IsDiffuse == 1)
892 aFront.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
894 aFront.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
895 if (myCStructure->ContextFillArea.Front.IsSpecular == 1)
896 aFront.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
898 aFront.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
899 if (myCStructure->ContextFillArea.Front.Emission == 1)
900 aFront.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
902 aFront.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
904 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.r),
905 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.g),
906 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.b), Quantity_TOC_RGB);
907 aFront.SetSpecularColor (aColor);
909 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.r),
910 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.g),
911 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.b), Quantity_TOC_RGB);
912 aFront.SetAmbientColor (aColor);
914 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.r),
915 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.g),
916 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.b), Quantity_TOC_RGB);
917 aFront.SetDiffuseColor (aColor);
919 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.r),
920 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.g),
921 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.b), Quantity_TOC_RGB);
922 aFront.SetEmissiveColor (aColor);
924 aFront.SetEnvReflexion (myCStructure->ContextFillArea.Front.EnvReflexion);
925 aFront.SetMaterialType (myCStructure->ContextFillArea.Front.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
927 Quantity_Color anIntColor (Standard_Real (myCStructure->ContextFillArea.IntColor.r),
928 Standard_Real (myCStructure->ContextFillArea.IntColor.g),
929 Standard_Real (myCStructure->ContextFillArea.IntColor.b), Quantity_TOC_RGB);
930 Quantity_Color anEdgeColor (Standard_Real (myCStructure->ContextFillArea.EdgeColor.r),
931 Standard_Real (myCStructure->ContextFillArea.EdgeColor.g),
932 Standard_Real (myCStructure->ContextFillArea.EdgeColor.b), Quantity_TOC_RGB);
933 Handle(Graphic3d_AspectFillArea3d) anAspFill = new Graphic3d_AspectFillArea3d (Aspect_InteriorStyle (myCStructure->ContextFillArea.Style),
934 anIntColor, anEdgeColor,
935 Aspect_TypeOfLine (myCStructure->ContextFillArea.LineType),
936 Standard_Real (myCStructure->ContextFillArea.Width),
940 if (myCStructure->ContextFillArea.Edge == 1)
941 anAspFill->SetEdgeOn();
943 anAspFill->SetEdgeOff();
945 anAspFill->SetHatchStyle (Aspect_HatchStyle (myCStructure->ContextFillArea.Hatch));
947 // Front and Back face
948 if (myCStructure->ContextFillArea.Distinguish == 1)
949 anAspFill->SetDistinguishOn();
951 anAspFill->SetDistinguishOff();
952 if (myCStructure->ContextFillArea.BackFace == 1)
953 anAspFill->SuppressBackFace();
955 anAspFill->AllowBackFace();
957 anAspFill->SetTextureMap (myCStructure->ContextFillArea.Texture.TextureMap);
958 if (myCStructure->ContextFillArea.Texture.doTextureMap == 1)
960 anAspFill->SetTextureMapOn();
964 anAspFill->SetTextureMapOff();
966 anAspFill->SetShaderProgram (myCStructure->ContextFillArea.ShaderProgram);
967 anAspFill->SetPolygonOffsets (myCStructure->ContextFillArea.PolygonOffsetMode,
968 myCStructure->ContextFillArea.PolygonOffsetFactor,
969 myCStructure->ContextFillArea.PolygonOffsetUnits);
973 //=============================================================================
976 //=============================================================================
977 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
979 return myCStructure->Groups();
982 //=============================================================================
983 //function : NumberOfGroups
985 //=============================================================================
986 Standard_Integer Graphic3d_Structure::NumberOfGroups() const
988 return myCStructure->Groups().Length();
991 //=============================================================================
992 //function : SetPrimitivesAspect
994 //=============================================================================
995 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
997 if (IsDeleted()) return;
999 Standard_Real aWidth;
1000 Quantity_Color aColor;
1001 Aspect_TypeOfLine aLType;
1002 theAspLine->Values (aColor, aLType, aWidth);
1004 myCStructure->ContextLine.Color.r = float (aColor.Red());
1005 myCStructure->ContextLine.Color.g = float (aColor.Green());
1006 myCStructure->ContextLine.Color.b = float (aColor.Blue());
1007 myCStructure->ContextLine.LineType = int (aLType);
1008 myCStructure->ContextLine.Width = float (aWidth);
1009 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
1010 myCStructure->ContextLine.IsDef = 1;
1012 myCStructure->UpdateAspects();
1014 // Attributes are "IsSet" during the first update of context (line, marker...)
1015 myCStructure->ContextLine.IsSet = 1;
1016 myCStructure->ContextFillArea.IsSet = 1;
1017 myCStructure->ContextMarker.IsSet = 1;
1018 myCStructure->ContextText.IsSet = 1;
1023 //=============================================================================
1024 //function : SetPrimitivesAspect
1026 //=============================================================================
1027 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
1029 if (IsDeleted()) return;
1031 Standard_Real anRGB[3];
1032 Standard_Real aWidth;
1033 Quantity_Color anIntColor;
1034 Quantity_Color aBackIntColor;
1035 Quantity_Color anEdgeColor;
1036 Aspect_TypeOfLine aLType;
1037 Aspect_InteriorStyle aStyle;
1038 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
1040 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
1041 myCStructure->ContextFillArea.Style = aStyle;
1042 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
1043 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
1044 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
1046 if (theAspFill->Distinguish())
1048 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
1050 myCStructure->ContextFillArea.BackIntColor.r = float(anRGB[0]);
1051 myCStructure->ContextFillArea.BackIntColor.g = float(anRGB[1]);
1052 myCStructure->ContextFillArea.BackIntColor.b = float(anRGB[2]);
1055 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1 : 0;
1056 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
1057 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
1058 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
1059 myCStructure->ContextFillArea.LineType = aLType;
1060 myCStructure->ContextFillArea.Width = float (aWidth);
1061 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
1063 // Front and Back face
1064 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
1065 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
1068 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
1069 // Light specificity
1070 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
1071 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
1072 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
1073 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
1074 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
1075 myCStructure->ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
1076 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
1079 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1080 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1081 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1082 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1086 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0 );
1089 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
1090 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
1091 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
1094 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
1095 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
1096 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
1099 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
1100 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
1101 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
1104 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
1105 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
1106 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
1108 myCStructure->ContextFillArea.Back.EnvReflexion =
1109 float ((theAspFill->BackMaterial ()).EnvReflexion());
1112 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
1113 // Light specificity
1114 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
1115 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
1116 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
1117 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
1118 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
1119 myCStructure->ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
1120 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
1123 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1124 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1125 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1126 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1130 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
1133 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
1134 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
1135 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
1138 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
1139 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
1140 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
1143 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
1144 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
1145 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
1148 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
1149 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
1150 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
1152 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
1154 myCStructure->ContextFillArea.IsDef = 1; // Definition material ok
1156 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
1157 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
1158 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
1160 Standard_Integer aPolyMode;
1161 Standard_ShortReal aPolyFactor, aPolyUnits;
1162 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
1163 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
1164 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
1165 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
1167 myCStructure->UpdateAspects();
1169 // Attributes are "IsSet" during the first update of context (line, marker...)
1170 myCStructure->ContextLine.IsSet = 1;
1171 myCStructure->ContextFillArea.IsSet = 1;
1172 myCStructure->ContextMarker.IsSet = 1;
1173 myCStructure->ContextText.IsSet = 1;
1178 //=============================================================================
1179 //function : SetPrimitivesAspect
1181 //=============================================================================
1182 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
1184 if (IsDeleted()) return;
1186 Standard_CString aFont;
1187 Standard_Real aSpace, anExpansion, aTextAngle;
1188 Quantity_Color aColor, aColorSub;
1189 Aspect_TypeOfStyleText aStyle;
1190 Aspect_TypeOfDisplayText aDispType;
1191 Standard_Boolean isTextZoomable;
1192 Font_FontAspect aTextFontAspect;
1193 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDispType, aColorSub, isTextZoomable, aTextAngle, aTextFontAspect);
1195 myCStructure->ContextText.Color.r = float (aColor.Red());
1196 myCStructure->ContextText.Color.g = float (aColor.Green());
1197 myCStructure->ContextText.Color.b = float (aColor.Blue());
1198 myCStructure->ContextText.Font = aFont;
1199 myCStructure->ContextText.Expan = float (anExpansion);
1200 myCStructure->ContextText.Space = float (aSpace);
1201 myCStructure->ContextText.Style = aStyle;
1202 myCStructure->ContextText.DisplayType = aDispType;
1203 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
1204 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
1205 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
1206 myCStructure->ContextText.TextZoomable = isTextZoomable;
1207 myCStructure->ContextText.TextAngle = float (aTextAngle);
1208 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
1209 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
1211 myCStructure->ContextText.IsDef = 1;
1213 myCStructure->UpdateAspects();
1215 // Attributes are "IsSet" during the first update of a context (line, marker...)
1216 myCStructure->ContextLine.IsSet = 1;
1217 myCStructure->ContextFillArea.IsSet = 1;
1218 myCStructure->ContextMarker.IsSet = 1;
1219 myCStructure->ContextText.IsSet = 1;
1224 //=============================================================================
1225 //function : SetPrimitivesAspect
1227 //=============================================================================
1228 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
1230 if (IsDeleted()) return;
1232 Standard_Real aScale;
1233 Quantity_Color aColor;
1234 Aspect_TypeOfMarker aMType;
1235 theAspMarker->Values (aColor, aMType, aScale);
1237 myCStructure->ContextMarker.Color.r = float (aColor.Red());
1238 myCStructure->ContextMarker.Color.g = float (aColor.Green());
1239 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
1240 myCStructure->ContextMarker.MarkerType = aMType;
1241 myCStructure->ContextMarker.Scale = float (aScale);
1242 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
1243 myCStructure->ContextMarker.IsDef = 1;
1245 myCStructure->UpdateAspects();
1247 // Attributes are "IsSet" during the first update of a context (line, marker...)
1248 myCStructure->ContextLine.IsSet = 1;
1249 myCStructure->ContextFillArea.IsSet = 1;
1250 myCStructure->ContextMarker.IsSet = 1;
1251 myCStructure->ContextText.IsSet = 1;
1256 //=============================================================================
1257 //function : SetVisual
1259 //=============================================================================
1260 void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
1263 || myVisual == theVisual)
1268 if (!myCStructure->stick)
1270 myVisual = theVisual;
1271 SetComputeVisual (theVisual);
1275 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
1276 if (anUpdateMode == Aspect_TOU_WAIT)
1279 myVisual = theVisual;
1280 SetComputeVisual (theVisual);
1284 // To avoid calling method : Update ()
1285 // Not useful and can be costly.
1286 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
1288 myVisual = theVisual;
1289 SetComputeVisual (theVisual);
1290 myStructureManager->SetUpdateMode (anUpdateMode);
1296 //=============================================================================
1297 //function : SetZoomLimit
1299 //=============================================================================
1300 void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
1301 const Standard_Real theLimitSup)
1305 Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
1306 "Bad value for ZoomLimit inf");
1307 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
1308 "Bad value for ZoomLimit sup");
1309 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
1310 "ZoomLimit sup < ZoomLimit inf");
1313 //=============================================================================
1316 //=============================================================================
1317 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
1322 //=============================================================================
1323 //function : AcceptConnection
1325 //=============================================================================
1326 Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
1327 const Handle(Graphic3d_Structure)& theStructure2,
1328 const Graphic3d_TypeOfConnection theType)
1331 Graphic3d_MapOfStructure aSet;
1332 Graphic3d_Structure::Network (theStructure2, theType, aSet);
1333 return !aSet.Contains (theStructure1);
1336 //=============================================================================
1337 //function : Ancestors
1339 //=============================================================================
1340 void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
1342 const Standard_Integer aNbAnces = myAncestors.Length ();
1343 for (Standard_Integer anIter = 1; anIter <= aNbAnces; ++anIter)
1345 theSet.Add ((Graphic3d_Structure* )(myAncestors.Value (anIter)));
1349 //=============================================================================
1350 //function : SetOwner
1352 //=============================================================================
1353 void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
1358 //=============================================================================
1361 //=============================================================================
1362 Standard_Address Graphic3d_Structure::Owner() const
1367 //=============================================================================
1368 //function : Descendants
1370 //=============================================================================
1371 void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
1373 const Standard_Integer aNbDesc = myDescendants.Length ();
1374 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1376 theSet.Add ((Graphic3d_Structure* )(myDescendants.Value (anIter)));
1380 //=============================================================================
1381 //function : Connect
1383 //=============================================================================
1384 void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
1385 const Graphic3d_TypeOfConnection theType,
1386 const Standard_Boolean theWithCheck)
1388 if (IsDeleted()) return;
1392 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
1399 case Graphic3d_TOC_DESCENDANT:
1401 const Standard_Integer aNbDesc = myDescendants.Length();
1402 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1404 if (myDescendants.Value (anIter) == theStructure.operator->())
1410 myDescendants.Append (theStructure.operator->());
1411 CalculateBoundBox();
1412 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
1414 GraphicConnect (theStructure);
1415 myStructureManager->Connect (this, theStructure);
1420 case Graphic3d_TOC_ANCESTOR:
1422 const Standard_Integer aNbAnces = myAncestors.Length();
1423 for (Standard_Integer anIter = 1; anIter <= aNbAnces; ++anIter)
1425 if (myAncestors.Value (anIter) == theStructure.operator->())
1431 myAncestors.Append (theStructure.operator->());
1432 CalculateBoundBox();
1433 theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
1435 // myGraphicDriver->Connect is called in case if connection between parent and child
1441 //=============================================================================
1442 //function : Disconnect
1444 //=============================================================================
1445 void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
1447 if (IsDeleted()) return;
1449 const Standard_Integer aNbDesc = myDescendants.Length();
1450 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1452 if (myDescendants.Value (anIter) == theStructure.operator->())
1454 myDescendants.Remove (anIter);
1455 theStructure->Disconnect (this);
1457 GraphicDisconnect (theStructure);
1458 myStructureManager->Disconnect (this, theStructure);
1460 CalculateBoundBox();
1467 const Standard_Integer aNbAnces = myAncestors.Length();
1468 for (Standard_Integer anIter = 1; anIter <= aNbAnces; ++anIter)
1470 if (myAncestors.Value (anIter) == theStructure.operator->())
1472 myAncestors.Remove (anIter);
1473 theStructure->Disconnect (this);
1474 CalculateBoundBox();
1475 // no call of myGraphicDriver->Disconnect in case of an ancestor
1481 //=============================================================================
1482 //function : DisconnectAll
1484 //=============================================================================
1485 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
1487 if (IsDeleted()) return;
1491 case Graphic3d_TOC_DESCENDANT:
1493 const Standard_Integer aLength = myDescendants.Length();
1494 for (Standard_Integer anIter = 1; anIter <= aLength; ++anIter)
1496 // Value (1) instead of Value (i) as myDescendants
1498 // Graphic3d_Structure::Disconnect (AStructure)
1499 // that takes AStructure from myDescendants
1500 ((Graphic3d_Structure* )(myDescendants.Value (1)))->Disconnect (this);
1504 case Graphic3d_TOC_ANCESTOR:
1506 const Standard_Integer aLength = myAncestors.Length();
1507 for (Standard_Integer anIter = 1; anIter <= aLength; ++anIter)
1509 // Value (1) instead of Value (i) as myAncestors
1511 // Graphic3d_Structure::Disconnect (AStructure)
1512 // that takes AStructure from myAncestors
1513 ((Graphic3d_Structure* )(myAncestors.Value (1)))->Disconnect (this);
1520 //=============================================================================
1521 //function : Composition
1523 //=============================================================================
1524 Graphic3d_TypeOfComposition Graphic3d_Structure::Composition() const
1526 return myCStructure->Composition;
1529 //=============================================================================
1530 //function : SetTransform
1532 //=============================================================================
1533 void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& theMatrix,
1534 const Graphic3d_TypeOfComposition theType)
1536 if (IsDeleted()) return;
1538 Standard_Real valuetrsf;
1539 Standard_Real valueoldtrsf;
1540 Standard_Real valuenewtrsf;
1541 TColStd_Array2OfReal aNewTrsf (0, 3, 0, 3);
1542 TColStd_Array2OfReal aMatrix44 (0, 3, 0, 3);
1544 // Assign the new transformation in an array [0..3][0..3]
1545 // Avoid problemes if the user has defined matrice [1..4][1..4]
1546 // or [3..6][-1..2] !!
1547 Standard_Integer lr = theMatrix.LowerRow();
1548 Standard_Integer ur = theMatrix.UpperRow();
1549 Standard_Integer lc = theMatrix.LowerCol();
1550 Standard_Integer uc = theMatrix.UpperCol();
1552 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1554 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1559 case Graphic3d_TOC_REPLACE:
1561 myCStructure->Composition = Graphic3d_TOC_REPLACE;
1562 // Update of CStructure
1563 for (Standard_Integer i = 0; i <= 3; ++i)
1565 for (Standard_Integer j = 0; j <= 3; ++j)
1567 myCStructure->Transformation[i][j] = float (theMatrix (lr + i, lc + j));
1568 aNewTrsf (i, j) = theMatrix (lr + i, lc + j);
1573 case Graphic3d_TOC_POSTCONCATENATE:
1575 myCStructure->Composition = Graphic3d_TOC_POSTCONCATENATE;
1576 // To simplify management of indices
1577 for (Standard_Integer i = 0; i <= 3; ++i)
1579 for (Standard_Integer j = 0; j <= 3; ++j)
1581 aMatrix44 (i, j) = theMatrix (lr + i, lc + j);
1585 // Calculation of the product of matrices
1586 for (Standard_Integer i = 0; i <= 3; ++i)
1588 for (Standard_Integer j = 0; j <= 3; ++j)
1590 aNewTrsf (i, j) = 0.0;
1591 for (Standard_Integer k = 0; k <= 3; ++k)
1593 valueoldtrsf = myCStructure->Transformation[i][k];
1594 valuetrsf = aMatrix44 (k, j);
1595 valuenewtrsf = aNewTrsf (i, j) + valueoldtrsf * valuetrsf;
1596 aNewTrsf (i, j) = valuenewtrsf;
1601 // Update of CStructure
1602 for (Standard_Integer i = 0; i <= 3; ++i)
1604 for (Standard_Integer j = 0; j <= 3; ++j)
1606 myCStructure->Transformation[i][j] = float (aNewTrsf (i, j));
1613 // If transformation, no validation of hidden already calculated parts
1619 GraphicTransform (aNewTrsf);
1620 myStructureManager->SetTransform (this, aNewTrsf);
1625 //=============================================================================
1626 //function : Transform
1628 //=============================================================================
1629 void Graphic3d_Structure::Transform (TColStd_Array2OfReal& theMatrix) const
1632 Standard_Integer lr = theMatrix.LowerRow ();
1633 Standard_Integer ur = theMatrix.UpperRow ();
1634 Standard_Integer lc = theMatrix.LowerCol ();
1635 Standard_Integer uc = theMatrix.UpperCol ();
1637 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1638 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1640 for (Standard_Integer i = 0; i <= 3; ++i)
1642 for (Standard_Integer j = 0; j <= 3; ++j)
1644 theMatrix (lr + i, lc + j) = myCStructure->Transformation[i][j];
1650 //=============================================================================
1651 //function : MinMaxValues
1653 //=============================================================================
1654 void Graphic3d_Structure::MinMaxValues (Standard_Real& theXMin,
1655 Standard_Real& theYMin,
1656 Standard_Real& theZMin,
1657 Standard_Real& theXMax,
1658 Standard_Real& theYMax,
1659 Standard_Real& theZMax,
1660 const Standard_Boolean theToIgnoreInfiniteFlag) const
1662 Graphic3d_BndBox4d aBox;
1663 addTransformed (aBox, theToIgnoreInfiniteFlag);
1664 if (!aBox.IsValid())
1666 theXMin = RealFirst();
1667 theYMin = RealFirst();
1668 theZMin = RealFirst();
1669 theXMax = RealLast();
1670 theYMax = RealLast();
1671 theZMax = RealLast();
1675 theXMin = aBox.CornerMin().x();
1676 theYMin = aBox.CornerMin().y();
1677 theZMin = aBox.CornerMin().z();
1678 theXMax = aBox.CornerMax().x();
1679 theYMax = aBox.CornerMax().y();
1680 theZMax = aBox.CornerMax().z();
1683 //=============================================================================
1684 //function : Identification
1686 //=============================================================================
1687 Standard_Integer Graphic3d_Structure::Identification() const
1689 return myCStructure->Id;
1692 //=============================================================================
1693 //function : SetTransformPersistence
1695 //=============================================================================
1696 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag)
1698 SetTransformPersistence (theFlag, gp_Pnt (0.0, 0.0, 0.0));
1701 //=============================================================================
1702 //function : SetTransformPersistence
1704 //=============================================================================
1705 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
1706 const gp_Pnt& thePoint)
1708 if (IsDeleted()) return;
1710 myCStructure->TransformPersistence.Flag = theFlag;
1711 myCStructure->TransformPersistence.Point.x = float (thePoint.X());
1712 myCStructure->TransformPersistence.Point.y = float (thePoint.Y());
1713 myCStructure->TransformPersistence.Point.z = float (thePoint.Z());
1714 myCStructure->UpdateAspects();
1715 CalculateBoundBox();
1717 myCStructure->TransformPersistence.IsSet = 1;
1720 //=============================================================================
1721 //function : TransformPersistenceMode
1723 //=============================================================================
1724 Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1726 return myCStructure->TransformPersistence.Flag;
1729 //=============================================================================
1730 //function : TransformPersistencePoint
1732 //=============================================================================
1733 gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const
1735 gp_Pnt aPnt (0.0, 0.0, 0.0);
1736 aPnt.SetX (myCStructure->TransformPersistence.Point.x);
1737 aPnt.SetY (myCStructure->TransformPersistence.Point.y);
1738 aPnt.SetZ (myCStructure->TransformPersistence.Point.z);
1742 //=============================================================================
1745 //=============================================================================
1746 void Graphic3d_Structure::Remove (const Standard_Address thePtr,
1747 const Graphic3d_TypeOfConnection theType)
1751 case Graphic3d_TOC_DESCENDANT:
1753 const Standard_Integer aNbDesc = myDescendants.Length();
1754 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1756 if (myDescendants.Value (anIter) == thePtr)
1758 myDescendants.Remove (anIter);
1764 case Graphic3d_TOC_ANCESTOR:
1766 const Standard_Integer aNbAncestors = myAncestors.Length();
1767 for (Standard_Integer anIter = 1; anIter <= aNbAncestors; ++anIter)
1769 if (myAncestors.Value (anIter) == thePtr)
1771 myAncestors.Remove (anIter);
1780 //=============================================================================
1781 //function : NewGroup
1783 //=============================================================================
1784 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
1786 return myCStructure->NewGroup (this);
1789 //=============================================================================
1792 //=============================================================================
1793 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1795 if (theGroup.IsNull()
1796 || theGroup->myStructure != this)
1801 myCStructure->RemoveGroup (theGroup);
1802 theGroup->myStructure = NULL;
1805 //=============================================================================
1806 //function : StructureManager
1808 //=============================================================================
1809 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1811 return myStructureManager;
1814 //=============================================================================
1815 //function : minMaxCoord
1817 //=============================================================================
1818 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord (const Standard_Boolean theToIgnoreInfiniteFlag) const
1820 Graphic3d_BndBox4f aBnd;
1821 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1823 if (!theToIgnoreInfiniteFlag)
1825 aBnd.Combine (aGroupIter.Value()->BoundingBox());
1829 Graphic3d_BndBox4f aValidBnd (aGroupIter.Value()->BoundingBox().CornerMin(),
1830 aGroupIter.Value()->BoundingBox().CornerMax());
1831 aBnd.Combine (aValidBnd);
1837 //=============================================================================
1838 //function : addTransformed
1840 //=============================================================================
1841 void Graphic3d_Structure::getBox (Graphic3d_BndBox4d& theBox,
1842 const Standard_Boolean theToIgnoreInfiniteFlag) const
1844 Graphic3d_BndBox4f aBoxF = minMaxCoord (theToIgnoreInfiniteFlag);
1845 if (aBoxF.IsValid())
1847 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMin().x(),
1848 (Standard_Real )aBoxF.CornerMin().y(),
1849 (Standard_Real )aBoxF.CornerMin().z(),
1850 (Standard_Real )aBoxF.CornerMin().w()),
1851 Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMax().x(),
1852 (Standard_Real )aBoxF.CornerMax().y(),
1853 (Standard_Real )aBoxF.CornerMax().z(),
1854 (Standard_Real )aBoxF.CornerMax().w()));
1856 && !theToIgnoreInfiniteFlag)
1858 const Graphic3d_Vec4d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
1859 if (aDiagVec.xyz().SquareModulus() >= 500000.0 * 500000.0)
1861 // bounding borders of infinite line has been calculated as own point in center of this line
1862 theBox = Graphic3d_BndBox4d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
1866 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d (RealFirst(), RealFirst(), RealFirst(), 1.0),
1867 Graphic3d_Vec4d (RealLast(), RealLast(), RealLast(), 1.0));
1874 //=============================================================================
1875 //function : addTransformed
1877 //=============================================================================
1878 void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d& theBox,
1879 const Standard_Boolean theToIgnoreInfiniteFlag) const
1881 Graphic3d_BndBox4d aCombinedBox, aBox;
1882 getBox (aCombinedBox, theToIgnoreInfiniteFlag);
1884 for (Standard_Integer aStructIt = 1; aStructIt <= myDescendants.Length(); ++aStructIt)
1886 const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )myDescendants.Value (aStructIt);
1887 aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1888 aCombinedBox.Combine (aBox);
1891 aBox = aCombinedBox;
1894 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1896 TransformBoundaries (aTrsf, aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1897 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1899 // if box is still valid after transformation
1902 theBox.Combine (aBox);
1904 else // it was infinite, return untransformed
1906 theBox.Combine (aCombinedBox);
1911 //=============================================================================
1912 //function : Transforms
1914 //=============================================================================
1915 void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1916 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
1917 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ)
1919 const Standard_Real aRL = RealLast();
1920 const Standard_Real aRF = RealFirst();
1921 if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1922 || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1930 Standard_Real A, B, C, D;
1935 theNewX = A * theX + B * theY + C * theZ + D;
1940 theNewY = A * theX + B * theY + C * theZ + D;
1945 theNewZ = A * theX + B * theY + C * theZ + D;
1949 //=============================================================================
1950 //function : Transforms
1952 //=============================================================================
1953 Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1954 const Graphic3d_Vector& theCoord)
1956 Standard_Real anXYZ[3];
1957 Graphic3d_Structure::Transforms (theTrsf,
1958 theCoord.X(), theCoord.Y(), theCoord.Z(),
1959 anXYZ[0], anXYZ[1], anXYZ[2]);
1960 return Graphic3d_Vector (anXYZ[0], anXYZ[1], anXYZ[2]);
1963 //=============================================================================
1964 //function : Transforms
1966 //=============================================================================
1967 Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1968 const Graphic3d_Vertex& theCoord)
1970 Standard_Real anXYZ[3];
1971 Graphic3d_Structure::Transforms (theTrsf,
1972 theCoord.X(), theCoord.Y(), theCoord.Z(),
1973 anXYZ[0], anXYZ[1], anXYZ[2]);
1974 return Graphic3d_Vertex (anXYZ[0], anXYZ[1], anXYZ[2]);
1977 //=============================================================================
1978 //function : Transforms
1980 //=============================================================================
1981 void Graphic3d_Structure::TransformBoundaries (const TColStd_Array2OfReal& theTrsf,
1982 Standard_Real& theXMin,
1983 Standard_Real& theYMin,
1984 Standard_Real& theZMin,
1985 Standard_Real& theXMax,
1986 Standard_Real& theYMax,
1987 Standard_Real& theZMax)
1989 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1991 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1992 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1994 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
1995 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1996 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1997 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1999 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
2000 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2001 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2002 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2004 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
2005 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2006 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2007 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2009 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
2010 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2011 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2012 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2014 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
2015 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2016 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2017 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2019 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
2020 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
2021 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
2022 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
2032 //=============================================================================
2033 //function : Network
2035 //=============================================================================
2036 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
2037 const Graphic3d_TypeOfConnection theType,
2038 Graphic3d_MapOfStructure& theSet)
2040 Graphic3d_MapOfStructure aSetD, aSetA;
2041 theStructure->Descendants (aSetD);
2042 theStructure->Ancestors (aSetA);
2043 theSet.Add (theStructure);
2046 case Graphic3d_TOC_DESCENDANT:
2047 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
2049 Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
2052 case Graphic3d_TOC_ANCESTOR:
2053 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
2055 Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
2061 //=============================================================================
2062 //function : PrintNetwork
2064 //=============================================================================
2065 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
2066 const Graphic3d_TypeOfConnection theType)
2068 Graphic3d_MapOfStructure aSet;
2069 Graphic3d_Structure::Network (theStructure, theType, aSet);
2070 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
2072 std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
2074 std::cout << std::flush;
2077 //=============================================================================
2080 //=============================================================================
2081 void Graphic3d_Structure::Update() const
2088 if (myStructureManager->UpdateMode() == Aspect_TOU_ASAP)
2090 myStructureManager->Update();
2094 //=============================================================================
2095 //function : UpdateStructure
2097 //=============================================================================
2098 void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)& theAspLine,
2099 const Handle(Graphic3d_AspectText3d)& theAspText,
2100 const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
2101 const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
2103 Standard_CString aFont;
2104 Standard_Real aSpace, anExpansion, aWidth, aScale;
2105 Quantity_Color aColor, anIntColor, aBackIntColor, anEdgeColor, aColorSub;
2106 Aspect_TypeOfLine aLType;
2107 Aspect_TypeOfMarker aMType;
2108 Aspect_InteriorStyle aStyle;
2109 Aspect_TypeOfStyleText aStyleT;
2110 Aspect_TypeOfDisplayText aDisplayType;
2111 Standard_Boolean aTextZoomable;
2112 Standard_Real aTextAngle;
2113 Font_FontAspect aTextFontAspect;
2115 theAspLine->Values (aColor, aLType, aWidth);
2116 myCStructure->ContextLine.Color.r = float (aColor.Red());
2117 myCStructure->ContextLine.Color.g = float (aColor.Green());
2118 myCStructure->ContextLine.Color.b = float (aColor.Blue());
2119 myCStructure->ContextLine.LineType = aLType;
2120 myCStructure->ContextLine.Width = float (aWidth);
2121 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
2123 theAspMarker->Values (aColor, aMType, aScale);
2124 myCStructure->ContextMarker.Color.r = float (aColor.Red());
2125 myCStructure->ContextMarker.Color.g = float (aColor.Green());
2126 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
2127 myCStructure->ContextMarker.MarkerType = aMType;
2128 myCStructure->ContextMarker.Scale = float (aScale);
2129 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
2131 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyleT, aDisplayType, aColorSub, aTextZoomable, aTextAngle, aTextFontAspect);
2132 myCStructure->ContextText.Color.r = float (aColor.Red());
2133 myCStructure->ContextText.Color.g = float (aColor.Green());
2134 myCStructure->ContextText.Color.b = float (aColor.Blue());
2135 myCStructure->ContextText.Font = aFont;
2136 myCStructure->ContextText.Expan = float (anExpansion);
2137 myCStructure->ContextText.Style = aStyleT;
2138 myCStructure->ContextText.DisplayType = aDisplayType;
2139 myCStructure->ContextText.Space = float (aSpace);
2140 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
2141 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
2142 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
2143 myCStructure->ContextText.TextZoomable = aTextZoomable;
2144 myCStructure->ContextText.TextAngle = float (aTextAngle);
2145 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
2146 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
2148 Standard_Real anRGB[3];
2149 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
2150 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2151 myCStructure->ContextFillArea.Style = aStyle;
2152 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
2153 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
2154 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
2156 if (theAspFill->Distinguish())
2158 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2160 myCStructure->ContextFillArea.BackIntColor.r = float (anRGB[0]);
2161 myCStructure->ContextFillArea.BackIntColor.g = float (anRGB[1]);
2162 myCStructure->ContextFillArea.BackIntColor.b = float (anRGB[2]);
2165 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1:0;
2166 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
2167 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
2168 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
2169 myCStructure->ContextFillArea.LineType = aLType;
2170 myCStructure->ContextFillArea.Width = float (aWidth);
2171 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
2173 // Front and Back face
2174 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
2175 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
2177 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
2178 // Light specificity
2179 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
2180 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
2181 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
2182 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
2183 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
2184 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
2187 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2188 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2189 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2190 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2193 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2196 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
2197 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
2198 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
2201 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
2202 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
2203 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
2206 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
2207 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
2208 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
2211 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
2212 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
2213 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
2215 myCStructure->ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
2218 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
2219 // Light specificity
2220 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
2221 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
2222 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
2223 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
2224 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
2225 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
2228 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2229 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2230 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2231 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2234 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2237 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
2238 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
2239 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
2242 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
2243 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
2244 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
2247 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
2248 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
2249 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
2252 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
2253 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
2254 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
2256 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
2258 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
2259 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
2260 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
2262 Standard_Integer aPolyMode;
2263 Standard_ShortReal aPolyFactor, aPolyUnits;
2264 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
2265 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
2266 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
2267 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
2270 //=============================================================================
2271 //function : GraphicHighlight
2273 //=============================================================================
2274 void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod theMethod)
2276 Standard_Real anRGB[3];
2277 myCStructure->highlight = 1;
2278 myHighlightMethod = theMethod;
2281 case Aspect_TOHM_COLOR:
2283 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2284 myCStructure->HighlightWithColor (Graphic3d_Vec3 (float (anRGB[0]), float (anRGB[1]), float (anRGB[2])), Standard_True);
2285 myCStructure->UpdateNamedStatus();
2288 case Aspect_TOHM_BOUNDBOX:
2290 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2291 myCStructure->HighlightColor.r = float (anRGB[0]);
2292 myCStructure->HighlightColor.g = float (anRGB[1]);
2293 myCStructure->HighlightColor.b = float (anRGB[2]);
2294 myCStructure->HighlightWithBndBox (this, Standard_True);
2300 //=============================================================================
2301 //function : GraphicTransform
2303 //=============================================================================
2304 void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& theMatrix)
2306 for (Standard_Integer i = 0; i <= 3; ++i)
2308 for (Standard_Integer j = 0; j <= 3; ++j)
2310 myCStructure->Transformation[i][j] = float (theMatrix (i, j));
2313 myCStructure->UpdateTransformation();
2316 //=============================================================================
2317 //function : GraphicUnHighlight
2319 //=============================================================================
2320 void Graphic3d_Structure::GraphicUnHighlight()
2322 myCStructure->highlight = 0;
2323 switch (myHighlightMethod)
2325 case Aspect_TOHM_COLOR:
2326 myCStructure->HighlightWithColor (Graphic3d_Vec3 (0.0f, 0.0f, 0.0f), Standard_False);
2327 myCStructure->UpdateNamedStatus();
2329 case Aspect_TOHM_BOUNDBOX:
2330 myCStructure->HighlightWithBndBox (this, Standard_False);
2331 myCStructure->UpdateNamedStatus();
2336 //=============================================================================
2337 //function : ComputeVisual
2339 //=============================================================================
2340 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
2342 return myComputeVisual;
2345 //=============================================================================
2346 //function : SetComputeVisual
2348 //=============================================================================
2349 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
2351 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
2352 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
2353 if (theVisual != Graphic3d_TOS_COMPUTED)
2355 myComputeVisual = theVisual;
2359 //=============================================================================
2360 //function : SetHLRValidation
2362 //=============================================================================
2363 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
2365 myCStructure->HLRValidation = theFlag ? 1 : 0;
2368 //=============================================================================
2369 //function : HLRValidation
2371 //=============================================================================
2372 Standard_Boolean Graphic3d_Structure::HLRValidation() const
2374 // Hidden parts stored in <me> are valid if :
2375 // 1/ the owner is defined.
2376 // 2/ they are not invalid.
2377 return myOwner != NULL
2378 && myCStructure->HLRValidation != 0;
2381 //=======================================================================
2382 //function : SetZLayer
2384 //=======================================================================
2385 void Graphic3d_Structure::SetZLayer (const Standard_Integer theLayerId)
2387 // if the structure is not displayed, unable to change its display layer
2391 myStructureManager->ChangeZLayer (this, theLayerId);
2394 //=======================================================================
2395 //function : GetZLayer
2397 //=======================================================================
2398 Standard_Integer Graphic3d_Structure::GetZLayer () const
2400 return myStructureManager->GetZLayer (this);
2403 //=======================================================================
2404 //function : SetClipPlanes
2406 //=======================================================================
2407 void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
2409 myCStructure->SetClipPlanes (thePlanes);
2412 //=======================================================================
2413 //function : GetClipPlanes
2415 //=======================================================================
2416 const Graphic3d_SequenceOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const
2418 return myCStructure->ClipPlanes();
2421 //=======================================================================
2422 //function : SetMutable
2424 //=======================================================================
2425 void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
2427 myCStructure->IsMutable = theIsMutable;
2430 //=======================================================================
2431 //function : IsMutable
2433 //=======================================================================
2434 Standard_Boolean Graphic3d_Structure::IsMutable() const
2436 return myCStructure->IsMutable;