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.
17 #include <Aspect_PolygonOffsetMode.hxx>
18 #include <Bnd_Box.hxx>
20 #include <Graphic3d_AspectFillArea3d.hxx>
21 #include <Graphic3d_AspectLine3d.hxx>
22 #include <Graphic3d_AspectMarker3d.hxx>
23 #include <Graphic3d_AspectText3d.hxx>
24 #include <Graphic3d_DataStructureManager.hxx>
25 #include <Graphic3d_GraphicDriver.hxx>
26 #include <Graphic3d_Group.hxx>
27 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
28 #include <Graphic3d_MapOfStructure.hxx>
29 #include <Graphic3d_MaterialAspect.hxx>
30 #include <Graphic3d_PriorityDefinitionError.hxx>
31 #include <Graphic3d_Structure.hxx>
32 #include "Graphic3d_Structure.pxx"
33 #include <Graphic3d_StructureDefinitionError.hxx>
34 #include <Graphic3d_StructureManager.hxx>
35 #include <Graphic3d_TextureMap.hxx>
36 #include <Graphic3d_TransformError.hxx>
37 #include <Graphic3d_Vector.hxx>
38 #include <Quantity_Color.hxx>
39 #include <Standard_Type.hxx>
40 #include <TColStd_Array2OfReal.hxx>
43 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Structure,MMgt_TShared)
45 //=============================================================================
46 //function : Graphic3d_Structure
48 //=============================================================================
49 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager)
50 : myStructureManager (theManager.operator->()),
51 myFirstStructureManager (theManager.operator->()),
52 myComputeVisual (Graphic3d_TOS_ALL),
53 myHighlightColor (Quantity_NOC_WHITE),
54 myHighlightMethod (Aspect_TOHM_COLOR),
56 myVisual (Graphic3d_TOS_ALL)
58 myCStructure = theManager->GraphicDriver()->CreateStructure (theManager);
61 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
62 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
63 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
64 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
65 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
66 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
68 // update the associated CStructure
69 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
72 //=============================================================================
73 //function : Graphic3d_Structure
75 //=============================================================================
76 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
77 const Handle(Graphic3d_Structure)& thePrs)
78 : myStructureManager (theManager.operator->()),
79 myFirstStructureManager (theManager.operator->()),
80 myComputeVisual (thePrs->myComputeVisual),
81 myHighlightColor (thePrs->myHighlightColor),
82 myHighlightMethod (thePrs->myHighlightMethod),
83 myOwner (thePrs->myOwner),
84 myVisual (thePrs->myVisual)
86 myCStructure = thePrs->myCStructure->ShadowLink (theManager);
89 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
90 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
91 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
92 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
93 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
94 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
96 // update the associated CStructure
97 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
100 //=============================================================================
101 //function : ~Graphic3d_Structure
103 //=============================================================================
104 Graphic3d_Structure::~Graphic3d_Structure()
106 // as myFirstStructureManager can be already destroyed,
107 // avoid attempts to access it
108 myFirstStructureManager = NULL;
112 //=============================================================================
115 //=============================================================================
116 void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
118 if (IsDeleted()) return;
120 // clean groups in graphics driver at first
121 GraphicClear (theWithDestruction);
123 myCStructure->ContainsFacet = 0;
124 myStructureManager->Clear (this, theWithDestruction);
129 //=======================================================================
130 //function : CalculateBoundBox
131 //purpose : Calculates AABB of a structure.
132 //=======================================================================
133 void Graphic3d_Structure::CalculateBoundBox()
135 Graphic3d_BndBox4d aBox;
136 addTransformed (aBox, Standard_True);
139 Graphic3d_Vec4 aMinPt (RealToShortReal (aBox.CornerMin().x()),
140 RealToShortReal (aBox.CornerMin().y()),
141 RealToShortReal (aBox.CornerMin().z()),
143 Graphic3d_Vec4 aMaxPt (RealToShortReal (aBox.CornerMax().x()),
144 RealToShortReal (aBox.CornerMax().y()),
145 RealToShortReal (aBox.CornerMax().z()),
147 myCStructure->ChangeBoundingBox() = Graphic3d_BndBox4f (aMinPt, aMaxPt);
151 myCStructure->ChangeBoundingBox().Clear();
155 //=============================================================================
158 //=============================================================================
159 void Graphic3d_Structure::Remove()
161 if (IsDeleted()) return;
163 // clean groups in graphics driver at first; this is also should be done
164 // to avoid unwanted group cleaning in group's destructor
165 // Pass Standard_False to Clear(..) method to avoid updating in
166 // structure manager, it isn't necessary, besides of it structure manager
167 // could be already destroyed and invalid pointers used in structure;
168 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
170 aGroupIter.ChangeValue()->Clear (Standard_False);
173 Standard_Address APtr = (void *) this;
174 // It is necessary to remove the eventual pointer on the structure
175 // that can be destroyed, in the list of descendants
176 // of ancestors of this structure and in the list of ancestors
177 // of descendants of the same structure.
179 for (Standard_Integer aStructIdx = 1, aNbDesc = myDescendants.Size(); aStructIdx <= aNbDesc; ++aStructIdx)
181 ((Graphic3d_Structure *)myDescendants.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
184 for (Standard_Integer aStructIdx = 1, aNbAnces = myAncestors.Size(); aStructIdx <= aNbAnces; ++aStructIdx)
186 ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
189 // Destruction of me in the graphic library
190 const Standard_Integer aStructId = myCStructure->Id;
191 myCStructure->GraphicDriver()->RemoveIdentification(aStructId);
192 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
193 myCStructure.Nullify();
196 //=============================================================================
199 //=============================================================================
200 void Graphic3d_Structure::Display()
202 if (IsDeleted()) return;
204 if (!myCStructure->stick)
206 myCStructure->stick = 1;
207 myStructureManager->Display (this);
210 if (myCStructure->visible != 1)
212 myCStructure->visible = 1;
213 myCStructure->OnVisibilityChanged();
217 //=============================================================================
218 //function : SetIsForHighlight
220 //=============================================================================
221 void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight)
223 myCStructure->IsForHighlight = isForHighlight;
226 //=============================================================================
227 //function : SetDisplayPriority
229 //=============================================================================
230 void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
233 || thePriority == myCStructure->Priority)
238 myCStructure->PreviousPriority = myCStructure->Priority;
239 myCStructure->Priority = thePriority;
241 if (myCStructure->Priority != myCStructure->PreviousPriority)
243 Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
244 || (myCStructure->Priority < Structure_MIN_PRIORITY),
245 "Bad value for StructurePriority");
246 if (myCStructure->stick)
248 myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
253 //=============================================================================
254 //function : ResetDisplayPriority
256 //=============================================================================
257 void Graphic3d_Structure::ResetDisplayPriority()
260 || myCStructure->Priority == myCStructure->PreviousPriority)
265 const Standard_Integer aPriority = myCStructure->Priority;
266 myCStructure->Priority = myCStructure->PreviousPriority;
267 if (myCStructure->stick)
269 myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
273 //=============================================================================
274 //function : DisplayPriority
276 //=============================================================================
277 Standard_Integer Graphic3d_Structure::DisplayPriority() const
279 return myCStructure->Priority;
282 //=============================================================================
285 //=============================================================================
286 void Graphic3d_Structure::Erase()
293 if (myCStructure->stick)
295 myCStructure->stick = 0;
296 myStructureManager->Erase (this);
300 //=============================================================================
301 //function : Highlight
303 //=============================================================================
304 void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod theMethod,
305 const Quantity_Color& theColor,
306 const Standard_Boolean theToUpdateMgr)
313 myHighlightColor = theColor;
315 // Highlight on already Highlighted structure.
316 if (myCStructure->highlight)
318 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
319 if (anUpdateMode == Aspect_TOU_WAIT)
325 // To avoid call of method : Update()
326 // Not useful and can be costly.
327 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
329 myStructureManager->SetUpdateMode (anUpdateMode);
333 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
335 GraphicHighlight (theMethod);
342 if (myCStructure->stick)
344 myStructureManager->Highlight (this, theMethod);
350 //=============================================================================
351 //function : SetVisible
353 //=============================================================================
354 void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
356 if (IsDeleted()) return;
358 const unsigned isVisible = theValue ? 1 : 0;
359 if (myCStructure->visible == isVisible)
364 myCStructure->visible = isVisible;
365 myCStructure->OnVisibilityChanged();
369 //=============================================================================
370 //function : UnHighlight
372 //=============================================================================
373 void Graphic3d_Structure::UnHighlight()
375 if (IsDeleted()) return;
377 if (myCStructure->highlight)
379 myCStructure->highlight = 0;
381 GraphicUnHighlight();
382 myStructureManager->UnHighlight (this);
384 ResetDisplayPriority();
389 //=============================================================================
390 //function : HighlightColor
392 //=============================================================================
393 const Quantity_Color& Graphic3d_Structure::HighlightColor() const
395 return myHighlightColor;
398 //=============================================================================
399 //function : IsDisplayed
401 //=============================================================================
402 Standard_Boolean Graphic3d_Structure::IsDisplayed() const
404 return myCStructure->stick ? Standard_True : Standard_False;
407 //=============================================================================
408 //function : IsDeleted
410 //=============================================================================
411 Standard_Boolean Graphic3d_Structure::IsDeleted() const
413 return myCStructure.IsNull();
416 //=============================================================================
417 //function : IsHighlighted
419 //=============================================================================
420 Standard_Boolean Graphic3d_Structure::IsHighlighted() const
422 return myCStructure->highlight ? Standard_True : Standard_False;
425 //=============================================================================
426 //function : IsVisible
428 //=============================================================================
429 Standard_Boolean Graphic3d_Structure::IsVisible() const
431 return myCStructure->visible ? Standard_True : Standard_False;
434 //=============================================================================
435 //function : IsTransformed
437 //=============================================================================
438 Standard_Boolean Graphic3d_Structure::IsTransformed() const
440 return !myCStructure->Transformation.IsIdentity();
443 //=============================================================================
444 //function : ContainsFacet
446 //=============================================================================
447 Standard_Boolean Graphic3d_Structure::ContainsFacet() const
451 return Standard_False;
453 else if (myCStructure->ContainsFacet > 0)
455 // if one of groups contains at least one facet, the structure contains it too
456 return Standard_True;
459 // stop at the first descendant containing at least one facet
460 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
462 if (((const Graphic3d_Structure *)anIter.Value())->ContainsFacet())
464 return Standard_True;
467 return Standard_False;
470 //=============================================================================
473 //=============================================================================
474 Standard_Boolean Graphic3d_Structure::IsEmpty() const
478 return Standard_True;
481 // structure is empty:
482 // - if all these groups are empty
483 // - or if all groups are empty and all their descendants are empty
484 // - or if all its descendants are empty
485 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
487 if (!aGroupIter.Value()->IsEmpty())
489 return Standard_False;
493 // stop at the first non-empty descendant
494 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
496 if (!((const Graphic3d_Structure* )anIter.Value())->IsEmpty())
498 return Standard_False;
501 return Standard_True;
504 //=============================================================================
505 //function : PrimitivesAspect
507 //=============================================================================
508 void Graphic3d_Structure::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& theAspLine,
509 Handle(Graphic3d_AspectText3d)& theAspText,
510 Handle(Graphic3d_AspectMarker3d)& theAspMarker,
511 Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
513 theAspLine = Line3dAspect();
514 theAspText = Text3dAspect();
515 theAspMarker = Marker3dAspect();
516 theAspFill = FillArea3dAspect();
519 //=============================================================================
520 //function : GroupsWithFacet
522 //=============================================================================
523 void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
525 myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
526 if (myCStructure->ContainsFacet < 0)
528 myCStructure->ContainsFacet = 0;
532 //=============================================================================
535 //=============================================================================
536 void Graphic3d_Structure::Compute()
538 // Implemented by Presentation
541 //=============================================================================
544 //=============================================================================
545 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
547 // Implemented by Presentation
551 //=============================================================================
554 //=============================================================================
555 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
556 const TColStd_Array2OfReal& )
558 // Implemented by Presentation
562 //=============================================================================
565 //=============================================================================
566 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
567 Handle(Graphic3d_Structure)& )
569 // Implemented by Presentation
572 //=============================================================================
575 //=============================================================================
576 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
577 const TColStd_Array2OfReal& ,
578 Handle(Graphic3d_Structure)& )
580 // Implemented by Presentation
583 //=============================================================================
584 //function : ReCompute
586 //=============================================================================
587 void Graphic3d_Structure::ReCompute()
589 myStructureManager->ReCompute (this);
592 //=============================================================================
593 //function : ReCompute
595 //=============================================================================
596 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
598 myStructureManager->ReCompute (this, theProjector);
601 //=============================================================================
602 //function : SetInfiniteState
604 //=============================================================================
605 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
607 myCStructure->IsInfinite = theToSet ? 1 : 0;
610 //=============================================================================
611 //function : IsInfinite
613 //=============================================================================
614 Standard_Boolean Graphic3d_Structure::IsInfinite() const
617 || myCStructure->IsInfinite;
620 //=============================================================================
621 //function : GraphicClear
623 //=============================================================================
624 void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
626 if (myCStructure.IsNull())
631 // clean and empty each group
632 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
634 aGroupIter.ChangeValue()->Clear();
636 if (!theWithDestruction)
641 while (!myCStructure->Groups().IsEmpty())
643 Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
646 myCStructure->Clear();
649 //=============================================================================
650 //function : GraphicConnect
652 //=============================================================================
653 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
655 myCStructure->Connect (*theDaughter->myCStructure);
658 //=============================================================================
659 //function : GraphicDisconnect
661 //=============================================================================
662 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
664 myCStructure->Disconnect (*theDaughter->myCStructure);
667 //=============================================================================
668 //function : Line3dAspect
670 //=============================================================================
671 Handle(Graphic3d_AspectLine3d) Graphic3d_Structure::Line3dAspect() const
673 const Standard_Real anRGB[3] =
675 Standard_Real (myCStructure->ContextLine.Color.r),
676 Standard_Real (myCStructure->ContextLine.Color.g),
677 Standard_Real (myCStructure->ContextLine.Color.b)
679 Quantity_Color aColor;
680 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
681 Aspect_TypeOfLine aLType = Aspect_TypeOfLine (myCStructure->ContextLine.LineType);
682 Standard_Real aWidth = Standard_Real (myCStructure->ContextLine.Width);
684 Handle(Graphic3d_AspectLine3d) anAspLine = new Graphic3d_AspectLine3d (aColor, aLType, aWidth);
685 anAspLine->SetShaderProgram (myCStructure->ContextLine.ShaderProgram);
689 //=============================================================================
690 //function : Text3dAspect
692 //=============================================================================
693 Handle(Graphic3d_AspectText3d) Graphic3d_Structure::Text3dAspect() const
695 const Standard_Real anRGB[3] =
697 Standard_Real (myCStructure->ContextText.Color.r),
698 Standard_Real (myCStructure->ContextText.Color.g),
699 Standard_Real (myCStructure->ContextText.Color.b)
701 Quantity_Color aColor;
702 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
703 Standard_CString aFont = Standard_CString (myCStructure->ContextText.Font);
704 Standard_Real anExpansion = Standard_Real (myCStructure->ContextText.Expan);
705 Standard_Real aSpace = Standard_Real (myCStructure->ContextText.Space);
706 Aspect_TypeOfStyleText aStyle = Aspect_TypeOfStyleText (myCStructure->ContextText.Style);
707 Aspect_TypeOfDisplayText aDispType = Aspect_TypeOfDisplayText (myCStructure->ContextText.DisplayType);
709 Handle(Graphic3d_AspectText3d) anAspText = new Graphic3d_AspectText3d (aColor, aFont, anExpansion, aSpace, aStyle, aDispType);
710 anAspText->SetShaderProgram (myCStructure->ContextText.ShaderProgram);
714 //=============================================================================
715 //function : Marker3dAspect
717 //=============================================================================
718 Handle(Graphic3d_AspectMarker3d) Graphic3d_Structure::Marker3dAspect() const
720 const Standard_Real anRGB[3] =
722 Standard_Real (myCStructure->ContextMarker.Color.r),
723 Standard_Real (myCStructure->ContextMarker.Color.g),
724 Standard_Real (myCStructure->ContextMarker.Color.b)
726 Quantity_Color aColor;
727 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
728 Aspect_TypeOfMarker aMType = myCStructure->ContextMarker.MarkerType;
729 Standard_Real aScale = Standard_Real (myCStructure->ContextMarker.Scale);
731 Handle(Graphic3d_AspectMarker3d) anAspMarker = new Graphic3d_AspectMarker3d (aMType, aColor, aScale);
732 anAspMarker->SetShaderProgram (myCStructure->ContextMarker.ShaderProgram);
736 //=============================================================================
737 //function : FillArea3dAspect
739 //=============================================================================
740 Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect() const
743 Graphic3d_MaterialAspect aBack;
744 aBack.SetShininess (Standard_Real (myCStructure->ContextFillArea.Back.Shininess));
745 aBack.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Back.Ambient));
746 aBack.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Back.Diffuse));
747 aBack.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Back.Specular));
748 aBack.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Back.Transparency));
749 aBack.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Back.Emission));
750 if (myCStructure->ContextFillArea.Back.IsAmbient == 1)
751 aBack.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
753 aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
754 if (myCStructure->ContextFillArea.Back.IsDiffuse == 1)
755 aBack.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
757 aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
758 if (myCStructure->ContextFillArea.Back.IsSpecular == 1)
759 aBack.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
761 aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
762 if (myCStructure->ContextFillArea.Back.IsEmission == 1)
763 aBack.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
765 aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
767 Quantity_Color aColor (Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.r),
768 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.g),
769 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.b), Quantity_TOC_RGB);
770 aBack.SetSpecularColor (aColor);
772 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.r),
773 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.g),
774 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.b), Quantity_TOC_RGB);
775 aBack.SetAmbientColor (aColor);
777 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.r),
778 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.g),
779 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.b), Quantity_TOC_RGB);
780 aBack.SetDiffuseColor (aColor);
782 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.r),
783 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.g),
784 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.b), Quantity_TOC_RGB);
785 aBack.SetEmissiveColor (aColor);
787 aBack.SetEnvReflexion (myCStructure->ContextFillArea.Back.EnvReflexion);
788 aBack.SetMaterialType (myCStructure->ContextFillArea.Back.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
790 aBack.SetRefractionIndex (Standard_Real (myCStructure->ContextFillArea.Back.RefractionIndex));
791 aBack.SetBSDF (myCStructure->ContextFillArea.Back.BSDF);
794 Graphic3d_MaterialAspect aFront;
795 aFront.SetShininess (Standard_Real (myCStructure->ContextFillArea.Front.Shininess));
796 aFront.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Front.Ambient));
797 aFront.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Front.Diffuse));
798 aFront.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Front.Specular));
799 aFront.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Front.Transparency));
800 aFront.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Front.Emission));
801 if (myCStructure->ContextFillArea.Front.IsAmbient == 1)
802 aFront.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
804 aFront.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
805 if (myCStructure->ContextFillArea.Front.IsDiffuse == 1)
806 aFront.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
808 aFront.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
809 if (myCStructure->ContextFillArea.Front.IsSpecular == 1)
810 aFront.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
812 aFront.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
813 if (myCStructure->ContextFillArea.Front.Emission == 1)
814 aFront.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
816 aFront.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
818 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.r),
819 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.g),
820 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.b), Quantity_TOC_RGB);
821 aFront.SetSpecularColor (aColor);
823 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.r),
824 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.g),
825 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.b), Quantity_TOC_RGB);
826 aFront.SetAmbientColor (aColor);
828 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.r),
829 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.g),
830 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.b), Quantity_TOC_RGB);
831 aFront.SetDiffuseColor (aColor);
833 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.r),
834 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.g),
835 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.b), Quantity_TOC_RGB);
836 aFront.SetEmissiveColor (aColor);
838 aFront.SetEnvReflexion (myCStructure->ContextFillArea.Front.EnvReflexion);
839 aFront.SetMaterialType (myCStructure->ContextFillArea.Front.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
841 aFront.SetRefractionIndex (Standard_Real (myCStructure->ContextFillArea.Front.RefractionIndex));
842 aFront.SetBSDF (myCStructure->ContextFillArea.Front.BSDF);
844 Quantity_Color anIntColor (Standard_Real (myCStructure->ContextFillArea.IntColor.r),
845 Standard_Real (myCStructure->ContextFillArea.IntColor.g),
846 Standard_Real (myCStructure->ContextFillArea.IntColor.b), Quantity_TOC_RGB);
847 Quantity_Color anEdgeColor (Standard_Real (myCStructure->ContextFillArea.EdgeColor.r),
848 Standard_Real (myCStructure->ContextFillArea.EdgeColor.g),
849 Standard_Real (myCStructure->ContextFillArea.EdgeColor.b), Quantity_TOC_RGB);
850 Handle(Graphic3d_AspectFillArea3d) anAspFill = new Graphic3d_AspectFillArea3d (Aspect_InteriorStyle (myCStructure->ContextFillArea.Style),
851 anIntColor, anEdgeColor,
852 Aspect_TypeOfLine (myCStructure->ContextFillArea.LineType),
853 Standard_Real (myCStructure->ContextFillArea.Width),
857 if (myCStructure->ContextFillArea.Edge == 1)
858 anAspFill->SetEdgeOn();
860 anAspFill->SetEdgeOff();
862 anAspFill->SetHatchStyle (Aspect_HatchStyle (myCStructure->ContextFillArea.Hatch));
864 // Front and Back face
865 if (myCStructure->ContextFillArea.Distinguish == 1)
866 anAspFill->SetDistinguishOn();
868 anAspFill->SetDistinguishOff();
869 if (myCStructure->ContextFillArea.BackFace == 1)
870 anAspFill->SuppressBackFace();
872 anAspFill->AllowBackFace();
874 anAspFill->SetTextureMap (myCStructure->ContextFillArea.Texture.TextureMap);
875 if (myCStructure->ContextFillArea.Texture.doTextureMap == 1)
877 anAspFill->SetTextureMapOn();
881 anAspFill->SetTextureMapOff();
883 anAspFill->SetShaderProgram (myCStructure->ContextFillArea.ShaderProgram);
884 anAspFill->SetPolygonOffsets (myCStructure->ContextFillArea.PolygonOffsetMode,
885 myCStructure->ContextFillArea.PolygonOffsetFactor,
886 myCStructure->ContextFillArea.PolygonOffsetUnits);
890 //=============================================================================
893 //=============================================================================
894 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
896 return myCStructure->Groups();
899 //=============================================================================
900 //function : NumberOfGroups
902 //=============================================================================
903 Standard_Integer Graphic3d_Structure::NumberOfGroups() const
905 return myCStructure->Groups().Length();
908 //=============================================================================
909 //function : SetPrimitivesAspect
911 //=============================================================================
912 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
914 if (IsDeleted()) return;
916 Standard_Real aWidth;
917 Quantity_Color aColor;
918 Aspect_TypeOfLine aLType;
919 theAspLine->Values (aColor, aLType, aWidth);
921 myCStructure->ContextLine.Color.r = float (aColor.Red());
922 myCStructure->ContextLine.Color.g = float (aColor.Green());
923 myCStructure->ContextLine.Color.b = float (aColor.Blue());
924 myCStructure->ContextLine.LineType = int (aLType);
925 myCStructure->ContextLine.Width = float (aWidth);
926 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
927 myCStructure->ContextLine.IsDef = 1;
929 myCStructure->UpdateAspects();
931 // Attributes are "IsSet" during the first update of context (line, marker...)
932 myCStructure->ContextLine.IsSet = 1;
933 myCStructure->ContextFillArea.IsSet = 1;
934 myCStructure->ContextMarker.IsSet = 1;
935 myCStructure->ContextText.IsSet = 1;
940 //=============================================================================
941 //function : SetPrimitivesAspect
943 //=============================================================================
944 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
946 if (IsDeleted()) return;
948 Standard_Real anRGB[3];
949 Standard_Real aWidth;
950 Quantity_Color anIntColor;
951 Quantity_Color aBackIntColor;
952 Quantity_Color anEdgeColor;
953 Aspect_TypeOfLine aLType;
954 Aspect_InteriorStyle aStyle;
955 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
957 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
958 myCStructure->ContextFillArea.Style = aStyle;
959 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
960 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
961 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
963 if (theAspFill->Distinguish())
965 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
967 myCStructure->ContextFillArea.BackIntColor.r = float(anRGB[0]);
968 myCStructure->ContextFillArea.BackIntColor.g = float(anRGB[1]);
969 myCStructure->ContextFillArea.BackIntColor.b = float(anRGB[2]);
972 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1 : 0;
973 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
974 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
975 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
976 myCStructure->ContextFillArea.LineType = aLType;
977 myCStructure->ContextFillArea.Width = float (aWidth);
978 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
980 // Front and Back face
981 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
982 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
985 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
987 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
988 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
989 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
990 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
991 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
992 myCStructure->ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
993 myCStructure->ContextFillArea.Back.BSDF = aBack.BSDF();
994 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
997 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
998 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
999 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1000 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1004 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0 );
1007 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
1008 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
1009 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
1012 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
1013 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
1014 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
1017 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
1018 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
1019 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
1022 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
1023 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
1024 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
1026 myCStructure->ContextFillArea.Back.EnvReflexion =
1027 float ((theAspFill->BackMaterial ()).EnvReflexion());
1030 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
1031 // Light specificity
1032 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
1033 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
1034 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
1035 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
1036 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
1037 myCStructure->ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
1038 myCStructure->ContextFillArea.Front.BSDF = aFront.BSDF();
1039 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
1042 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1043 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1044 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1045 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1049 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
1052 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
1053 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
1054 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
1057 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
1058 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
1059 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
1062 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
1063 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
1064 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
1067 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
1068 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
1069 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
1071 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
1073 myCStructure->ContextFillArea.IsDef = 1; // Definition material ok
1075 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
1076 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
1077 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
1079 Standard_Integer aPolyMode;
1080 Standard_ShortReal aPolyFactor, aPolyUnits;
1081 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
1082 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
1083 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
1084 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
1086 myCStructure->UpdateAspects();
1088 // Attributes are "IsSet" during the first update of context (line, marker...)
1089 myCStructure->ContextLine.IsSet = 1;
1090 myCStructure->ContextFillArea.IsSet = 1;
1091 myCStructure->ContextMarker.IsSet = 1;
1092 myCStructure->ContextText.IsSet = 1;
1097 //=============================================================================
1098 //function : SetPrimitivesAspect
1100 //=============================================================================
1101 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
1103 if (IsDeleted()) return;
1105 Standard_CString aFont;
1106 Standard_Real aSpace, anExpansion, aTextAngle;
1107 Quantity_Color aColor, aColorSub;
1108 Aspect_TypeOfStyleText aStyle;
1109 Aspect_TypeOfDisplayText aDispType;
1110 Standard_Boolean isTextZoomable;
1111 Font_FontAspect aTextFontAspect;
1112 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDispType, aColorSub, isTextZoomable, aTextAngle, aTextFontAspect);
1114 myCStructure->ContextText.Color.r = float (aColor.Red());
1115 myCStructure->ContextText.Color.g = float (aColor.Green());
1116 myCStructure->ContextText.Color.b = float (aColor.Blue());
1117 myCStructure->ContextText.Font = aFont;
1118 myCStructure->ContextText.Expan = float (anExpansion);
1119 myCStructure->ContextText.Space = float (aSpace);
1120 myCStructure->ContextText.Style = aStyle;
1121 myCStructure->ContextText.DisplayType = aDispType;
1122 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
1123 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
1124 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
1125 myCStructure->ContextText.TextZoomable = isTextZoomable;
1126 myCStructure->ContextText.TextAngle = float (aTextAngle);
1127 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
1128 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
1130 myCStructure->ContextText.IsDef = 1;
1132 myCStructure->UpdateAspects();
1134 // Attributes are "IsSet" during the first update of a context (line, marker...)
1135 myCStructure->ContextLine.IsSet = 1;
1136 myCStructure->ContextFillArea.IsSet = 1;
1137 myCStructure->ContextMarker.IsSet = 1;
1138 myCStructure->ContextText.IsSet = 1;
1143 //=============================================================================
1144 //function : SetPrimitivesAspect
1146 //=============================================================================
1147 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
1149 if (IsDeleted()) return;
1151 Standard_Real aScale;
1152 Quantity_Color aColor;
1153 Aspect_TypeOfMarker aMType;
1154 theAspMarker->Values (aColor, aMType, aScale);
1156 myCStructure->ContextMarker.Color.r = float (aColor.Red());
1157 myCStructure->ContextMarker.Color.g = float (aColor.Green());
1158 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
1159 myCStructure->ContextMarker.MarkerType = aMType;
1160 myCStructure->ContextMarker.Scale = float (aScale);
1161 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
1162 myCStructure->ContextMarker.IsDef = 1;
1164 myCStructure->UpdateAspects();
1166 // Attributes are "IsSet" during the first update of a context (line, marker...)
1167 myCStructure->ContextLine.IsSet = 1;
1168 myCStructure->ContextFillArea.IsSet = 1;
1169 myCStructure->ContextMarker.IsSet = 1;
1170 myCStructure->ContextText.IsSet = 1;
1175 //=============================================================================
1176 //function : SetVisual
1178 //=============================================================================
1179 void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
1182 || myVisual == theVisual)
1187 if (!myCStructure->stick)
1189 myVisual = theVisual;
1190 SetComputeVisual (theVisual);
1194 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
1195 if (anUpdateMode == Aspect_TOU_WAIT)
1198 myVisual = theVisual;
1199 SetComputeVisual (theVisual);
1203 // To avoid calling method : Update ()
1204 // Not useful and can be costly.
1205 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
1207 myVisual = theVisual;
1208 SetComputeVisual (theVisual);
1209 myStructureManager->SetUpdateMode (anUpdateMode);
1215 //=============================================================================
1216 //function : SetZoomLimit
1218 //=============================================================================
1219 void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
1220 const Standard_Real theLimitSup)
1224 Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
1225 "Bad value for ZoomLimit inf");
1226 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
1227 "Bad value for ZoomLimit sup");
1228 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
1229 "ZoomLimit sup < ZoomLimit inf");
1232 //=============================================================================
1235 //=============================================================================
1236 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
1241 //=============================================================================
1242 //function : AcceptConnection
1244 //=============================================================================
1245 Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
1246 const Handle(Graphic3d_Structure)& theStructure2,
1247 const Graphic3d_TypeOfConnection theType)
1250 Graphic3d_MapOfStructure aSet;
1251 Graphic3d_Structure::Network (theStructure2, theType, aSet);
1252 return !aSet.Contains (theStructure1);
1255 //=============================================================================
1256 //function : Ancestors
1258 //=============================================================================
1259 void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
1261 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myAncestors); anIter.More(); anIter.Next())
1263 theSet.Add ((Graphic3d_Structure* )anIter.Value());
1267 //=============================================================================
1268 //function : SetOwner
1270 //=============================================================================
1271 void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
1276 //=============================================================================
1279 //=============================================================================
1280 Standard_Address Graphic3d_Structure::Owner() const
1285 //=============================================================================
1286 //function : Descendants
1288 //=============================================================================
1289 void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
1291 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1293 theSet.Add ((Graphic3d_Structure* )anIter.Value());
1297 //=============================================================================
1298 //function : AppendAncestor
1300 //=============================================================================
1301 Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor)
1303 const Standard_Integer aSize = myAncestors.Size();
1305 return myAncestors.Add (theAncestor) > aSize; // new object
1308 //=============================================================================
1309 //function : AppendDescendant
1311 //=============================================================================
1312 Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant)
1314 const Standard_Integer aSize = myDescendants.Size();
1316 return myDescendants.Add (theDescendant) > aSize; // new object
1319 //=============================================================================
1320 //function : RemoveAncestor
1322 //=============================================================================
1323 Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor)
1325 const Standard_Integer anIndex = myAncestors.FindIndex (theAncestor);
1329 myAncestors.Swap (anIndex, myAncestors.Size());
1330 myAncestors.RemoveLast();
1333 return anIndex != 0; // object was found
1336 //=============================================================================
1337 //function : RemoveDescendant
1339 //=============================================================================
1340 Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant)
1342 const Standard_Integer anIndex = myDescendants.FindIndex (theDescendant);
1346 myDescendants.Swap (anIndex, myDescendants.Size());
1347 myDescendants.RemoveLast();
1350 return anIndex != 0; // object was found
1353 //=============================================================================
1354 //function : Connect
1356 //=============================================================================
1357 void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
1358 const Graphic3d_TypeOfConnection theType,
1359 const Standard_Boolean theWithCheck)
1368 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
1373 const Standard_Address aStructure = theStructure.operator->();
1375 if (theType == Graphic3d_TOC_DESCENDANT)
1377 if (!AppendDescendant (aStructure))
1382 CalculateBoundBox();
1383 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
1385 GraphicConnect (theStructure);
1386 myStructureManager->Connect (this, theStructure);
1390 else // Graphic3d_TOC_ANCESTOR
1392 if (!AppendAncestor (aStructure))
1397 CalculateBoundBox();
1398 theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
1400 // myStructureManager->Connect is called in case if connection between parent and child
1404 //=============================================================================
1405 //function : Disconnect
1407 //=============================================================================
1408 void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
1415 const Standard_Address aStructure = theStructure.operator->();
1417 if (RemoveDescendant (aStructure))
1419 theStructure->Disconnect (this);
1421 GraphicDisconnect (theStructure);
1422 myStructureManager->Disconnect (this, theStructure);
1424 CalculateBoundBox();
1427 else if (RemoveAncestor (aStructure))
1429 theStructure->Disconnect (this);
1430 CalculateBoundBox();
1432 // no call of myStructureManager->Disconnect in case of an ancestor
1436 //=============================================================================
1437 //function : DisconnectAll
1439 //=============================================================================
1440 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
1442 if (IsDeleted()) return;
1446 case Graphic3d_TOC_DESCENDANT:
1448 for (Standard_Integer anIdx = 1, aLength = myDescendants.Size(); anIdx <= aLength; ++anIdx)
1450 // Value (1) instead of Value (i) as myDescendants
1452 // Graphic3d_Structure::Disconnect (AStructure)
1453 // that takes AStructure from myDescendants
1454 ((Graphic3d_Structure* )(myDescendants.FindKey (1)))->Disconnect (this);
1458 case Graphic3d_TOC_ANCESTOR:
1460 for (Standard_Integer anIdx = 1, aLength = myAncestors.Size(); anIdx <= aLength; ++anIdx)
1462 // Value (1) instead of Value (i) as myAncestors
1464 // Graphic3d_Structure::Disconnect (AStructure)
1465 // that takes AStructure from myAncestors
1466 ((Graphic3d_Structure* )(myAncestors.FindKey (1)))->Disconnect (this);
1473 //=============================================================================
1474 //function : SetTransform
1476 //=============================================================================
1477 void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& theMatrix,
1478 const Graphic3d_TypeOfComposition theType)
1480 if (IsDeleted()) return;
1482 Standard_Real valuetrsf;
1483 Standard_Real valueoldtrsf;
1484 Standard_Real valuenewtrsf;
1485 TColStd_Array2OfReal aNewTrsf (0, 3, 0, 3);
1486 TColStd_Array2OfReal aMatrix44 (0, 3, 0, 3);
1488 // Assign the new transformation in an array [0..3][0..3]
1489 // Avoid problems if the user has defined matrix [1..4][1..4]
1490 // or [3..6][-1..2] !!
1491 Standard_Integer lr = theMatrix.LowerRow();
1492 Standard_Integer ur = theMatrix.UpperRow();
1493 Standard_Integer lc = theMatrix.LowerCol();
1494 Standard_Integer uc = theMatrix.UpperCol();
1496 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1498 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1501 const Standard_Boolean wasTransformed = IsTransformed();
1504 case Graphic3d_TOC_REPLACE:
1506 // Update of CStructure
1507 for (Standard_Integer i = 0; i <= 3; ++i)
1509 for (Standard_Integer j = 0; j <= 3; ++j)
1511 myCStructure->Transformation.ChangeValue (i, j) = float (theMatrix (lr + i, lc + j));
1512 aNewTrsf (i, j) = theMatrix (lr + i, lc + j);
1517 case Graphic3d_TOC_POSTCONCATENATE:
1519 // To simplify management of indices
1520 for (Standard_Integer i = 0; i <= 3; ++i)
1522 for (Standard_Integer j = 0; j <= 3; ++j)
1524 aMatrix44 (i, j) = theMatrix (lr + i, lc + j);
1528 // Calculation of the product of matrices
1529 for (Standard_Integer i = 0; i <= 3; ++i)
1531 for (Standard_Integer j = 0; j <= 3; ++j)
1533 aNewTrsf (i, j) = 0.0;
1534 for (Standard_Integer k = 0; k <= 3; ++k)
1536 valueoldtrsf = myCStructure->Transformation.GetValue (i, k);
1537 valuetrsf = aMatrix44 (k, j);
1538 valuenewtrsf = aNewTrsf (i, j) + valueoldtrsf * valuetrsf;
1539 aNewTrsf (i, j) = valuenewtrsf;
1544 // Update of CStructure
1545 for (Standard_Integer i = 0; i <= 3; ++i)
1547 for (Standard_Integer j = 0; j <= 3; ++j)
1549 myCStructure->Transformation.ChangeValue (i, j) = float (aNewTrsf (i, j));
1556 // If transformation, no validation of hidden already calculated parts
1557 if (IsTransformed() || (!IsTransformed() && wasTransformed))
1562 myCStructure->UpdateTransformation();
1563 myStructureManager->SetTransform (this, aNewTrsf);
1568 //=============================================================================
1569 //function : Transform
1571 //=============================================================================
1572 void Graphic3d_Structure::Transform (TColStd_Array2OfReal& theMatrix) const
1575 Standard_Integer lr = theMatrix.LowerRow ();
1576 Standard_Integer ur = theMatrix.UpperRow ();
1577 Standard_Integer lc = theMatrix.LowerCol ();
1578 Standard_Integer uc = theMatrix.UpperCol ();
1580 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1581 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1583 for (Standard_Integer i = 0; i <= 3; ++i)
1585 for (Standard_Integer j = 0; j <= 3; ++j)
1587 theMatrix (lr + i, lc + j) = myCStructure->Transformation.GetValue (i, j);
1593 //=============================================================================
1594 //function : MinMaxValues
1596 //=============================================================================
1597 Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
1599 Graphic3d_BndBox4d aBox;
1601 addTransformed (aBox, theToIgnoreInfiniteFlag);
1604 aResult.Add (gp_Pnt (aBox.CornerMin().x(),
1605 aBox.CornerMin().y(),
1606 aBox.CornerMin().z()));
1607 aResult.Add (gp_Pnt (aBox.CornerMax().x(),
1608 aBox.CornerMax().y(),
1609 aBox.CornerMax().z()));
1611 Standard_Real aLimMin = ShortRealFirst() + 1.0;
1612 Standard_Real aLimMax = ShortRealLast() - 1.0;
1613 gp_Pnt aMin = aResult.CornerMin();
1614 gp_Pnt aMax = aResult.CornerMax();
1615 if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin &&
1616 aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax)
1618 //For structure which infinite in all three dimensions the Whole bounding box will be returned
1625 //=============================================================================
1626 //function : Identification
1628 //=============================================================================
1629 Standard_Integer Graphic3d_Structure::Identification() const
1631 return myCStructure->Id;
1634 //=============================================================================
1635 //function : SetTransformPersistence
1637 //=============================================================================
1638 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag)
1640 SetTransformPersistence (theFlag, gp_Pnt (0.0, 0.0, 0.0));
1643 //=============================================================================
1644 //function : SetTransformPersistence
1646 //=============================================================================
1647 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
1648 const gp_Pnt& thePoint)
1650 if (IsDeleted()) return;
1652 myCStructure->TransformPersistence.Flags = theFlag;
1653 myCStructure->TransformPersistence.Point.x() = thePoint.X();
1654 myCStructure->TransformPersistence.Point.y() = thePoint.Y();
1655 myCStructure->TransformPersistence.Point.z() = thePoint.Z();
1658 //=============================================================================
1659 //function : TransformPersistenceMode
1661 //=============================================================================
1662 Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1664 return myCStructure->TransformPersistence.Flags;
1667 //=============================================================================
1668 //function : TransformPersistencePoint
1670 //=============================================================================
1671 gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const
1673 gp_Pnt aPnt (0.0, 0.0, 0.0);
1674 aPnt.SetX (myCStructure->TransformPersistence.Point.x());
1675 aPnt.SetY (myCStructure->TransformPersistence.Point.y());
1676 aPnt.SetZ (myCStructure->TransformPersistence.Point.z());
1680 //=============================================================================
1683 //=============================================================================
1684 void Graphic3d_Structure::Remove (const Standard_Address thePtr,
1685 const Graphic3d_TypeOfConnection theType)
1687 if (theType == Graphic3d_TOC_DESCENDANT)
1689 RemoveDescendant (thePtr);
1693 RemoveAncestor (thePtr);
1697 //=============================================================================
1698 //function : NewGroup
1700 //=============================================================================
1701 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
1703 return myCStructure->NewGroup (this);
1706 //=============================================================================
1709 //=============================================================================
1710 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1712 if (theGroup.IsNull()
1713 || theGroup->myStructure != this)
1718 myCStructure->RemoveGroup (theGroup);
1719 theGroup->myStructure = NULL;
1722 //=============================================================================
1723 //function : StructureManager
1725 //=============================================================================
1726 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1728 return myStructureManager;
1731 //=============================================================================
1732 //function : minMaxCoord
1734 //=============================================================================
1735 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
1737 Graphic3d_BndBox4f aBnd;
1738 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1740 aBnd.Combine (aGroupIter.Value()->BoundingBox());
1745 //=============================================================================
1746 //function : addTransformed
1748 //=============================================================================
1749 void Graphic3d_Structure::getBox (Graphic3d_BndBox4d& theBox,
1750 const Standard_Boolean theToIgnoreInfiniteFlag) const
1752 Graphic3d_BndBox4f aBoxF = minMaxCoord();
1753 if (aBoxF.IsValid())
1755 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMin().x(),
1756 (Standard_Real )aBoxF.CornerMin().y(),
1757 (Standard_Real )aBoxF.CornerMin().z(),
1758 (Standard_Real )aBoxF.CornerMin().w()),
1759 Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMax().x(),
1760 (Standard_Real )aBoxF.CornerMax().y(),
1761 (Standard_Real )aBoxF.CornerMax().z(),
1762 (Standard_Real )aBoxF.CornerMax().w()));
1764 && !theToIgnoreInfiniteFlag)
1766 const Graphic3d_Vec4d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
1767 if (aDiagVec.xyz().SquareModulus() >= 500000.0 * 500000.0)
1769 // bounding borders of infinite line has been calculated as own point in center of this line
1770 theBox = Graphic3d_BndBox4d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
1774 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d (RealFirst(), RealFirst(), RealFirst(), 1.0),
1775 Graphic3d_Vec4d (RealLast(), RealLast(), RealLast(), 1.0));
1782 //=============================================================================
1783 //function : addTransformed
1785 //=============================================================================
1786 void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d& theBox,
1787 const Standard_Boolean theToIgnoreInfiniteFlag) const
1789 Graphic3d_BndBox4d aCombinedBox, aBox;
1790 getBox (aCombinedBox, theToIgnoreInfiniteFlag);
1792 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1794 const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )anIter.Value();
1795 aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1796 aCombinedBox.Combine (aBox);
1799 aBox = aCombinedBox;
1802 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1804 TransformBoundaries (aTrsf, aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1805 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1807 // if box is still valid after transformation
1810 theBox.Combine (aBox);
1812 else // it was infinite, return untransformed
1814 theBox.Combine (aCombinedBox);
1819 //=============================================================================
1820 //function : Transforms
1822 //=============================================================================
1823 void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1824 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
1825 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ)
1827 const Standard_Real aRL = RealLast();
1828 const Standard_Real aRF = RealFirst();
1829 if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1830 || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1838 Standard_Real A, B, C, D;
1843 theNewX = A * theX + B * theY + C * theZ + D;
1848 theNewY = A * theX + B * theY + C * theZ + D;
1853 theNewZ = A * theX + B * theY + C * theZ + D;
1857 //=============================================================================
1858 //function : Transforms
1860 //=============================================================================
1861 Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1862 const Graphic3d_Vector& theCoord)
1864 Standard_Real anXYZ[3];
1865 Graphic3d_Structure::Transforms (theTrsf,
1866 theCoord.X(), theCoord.Y(), theCoord.Z(),
1867 anXYZ[0], anXYZ[1], anXYZ[2]);
1868 return Graphic3d_Vector (anXYZ[0], anXYZ[1], anXYZ[2]);
1871 //=============================================================================
1872 //function : Transforms
1874 //=============================================================================
1875 Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1876 const Graphic3d_Vertex& theCoord)
1878 Standard_Real anXYZ[3];
1879 Graphic3d_Structure::Transforms (theTrsf,
1880 theCoord.X(), theCoord.Y(), theCoord.Z(),
1881 anXYZ[0], anXYZ[1], anXYZ[2]);
1882 return Graphic3d_Vertex (anXYZ[0], anXYZ[1], anXYZ[2]);
1885 //=============================================================================
1886 //function : Transforms
1888 //=============================================================================
1889 void Graphic3d_Structure::TransformBoundaries (const TColStd_Array2OfReal& theTrsf,
1890 Standard_Real& theXMin,
1891 Standard_Real& theYMin,
1892 Standard_Real& theZMin,
1893 Standard_Real& theXMax,
1894 Standard_Real& theYMax,
1895 Standard_Real& theZMax)
1897 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1899 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1900 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1902 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
1903 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1904 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1905 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1907 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
1908 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1909 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1910 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1912 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
1913 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1914 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1915 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1917 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
1918 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1919 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1920 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1922 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
1923 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1924 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1925 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1927 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
1928 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1929 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1930 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1940 //=============================================================================
1941 //function : Network
1943 //=============================================================================
1944 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
1945 const Graphic3d_TypeOfConnection theType,
1946 Graphic3d_MapOfStructure& theSet)
1948 Graphic3d_MapOfStructure aSetD, aSetA;
1949 theStructure->Descendants (aSetD);
1950 theStructure->Ancestors (aSetA);
1951 theSet.Add (theStructure);
1954 case Graphic3d_TOC_DESCENDANT:
1955 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
1957 Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
1960 case Graphic3d_TOC_ANCESTOR:
1961 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
1963 Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
1969 //=============================================================================
1970 //function : PrintNetwork
1972 //=============================================================================
1973 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
1974 const Graphic3d_TypeOfConnection theType)
1976 Graphic3d_MapOfStructure aSet;
1977 Graphic3d_Structure::Network (theStructure, theType, aSet);
1978 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
1980 std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
1982 std::cout << std::flush;
1985 //=============================================================================
1988 //=============================================================================
1989 void Graphic3d_Structure::Update (const bool theUpdateLayer) const
1996 myStructureManager->Update (myStructureManager->UpdateMode(),
1997 theUpdateLayer ? myCStructure->ZLayer() : Graphic3d_ZLayerId_UNKNOWN);
2000 //=============================================================================
2001 //function : UpdateStructure
2003 //=============================================================================
2004 void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)& theAspLine,
2005 const Handle(Graphic3d_AspectText3d)& theAspText,
2006 const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
2007 const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
2009 Standard_CString aFont;
2010 Standard_Real aSpace, anExpansion, aWidth, aScale;
2011 Quantity_Color aColor, anIntColor, aBackIntColor, anEdgeColor, aColorSub;
2012 Aspect_TypeOfLine aLType;
2013 Aspect_TypeOfMarker aMType;
2014 Aspect_InteriorStyle aStyle;
2015 Aspect_TypeOfStyleText aStyleT;
2016 Aspect_TypeOfDisplayText aDisplayType;
2017 Standard_Boolean aTextZoomable;
2018 Standard_Real aTextAngle;
2019 Font_FontAspect aTextFontAspect;
2021 theAspLine->Values (aColor, aLType, aWidth);
2022 myCStructure->ContextLine.Color.r = float (aColor.Red());
2023 myCStructure->ContextLine.Color.g = float (aColor.Green());
2024 myCStructure->ContextLine.Color.b = float (aColor.Blue());
2025 myCStructure->ContextLine.LineType = aLType;
2026 myCStructure->ContextLine.Width = float (aWidth);
2027 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
2029 theAspMarker->Values (aColor, aMType, aScale);
2030 myCStructure->ContextMarker.Color.r = float (aColor.Red());
2031 myCStructure->ContextMarker.Color.g = float (aColor.Green());
2032 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
2033 myCStructure->ContextMarker.MarkerType = aMType;
2034 myCStructure->ContextMarker.Scale = float (aScale);
2035 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
2037 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyleT, aDisplayType, aColorSub, aTextZoomable, aTextAngle, aTextFontAspect);
2038 myCStructure->ContextText.Color.r = float (aColor.Red());
2039 myCStructure->ContextText.Color.g = float (aColor.Green());
2040 myCStructure->ContextText.Color.b = float (aColor.Blue());
2041 myCStructure->ContextText.Font = aFont;
2042 myCStructure->ContextText.Expan = float (anExpansion);
2043 myCStructure->ContextText.Style = aStyleT;
2044 myCStructure->ContextText.DisplayType = aDisplayType;
2045 myCStructure->ContextText.Space = float (aSpace);
2046 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
2047 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
2048 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
2049 myCStructure->ContextText.TextZoomable = aTextZoomable;
2050 myCStructure->ContextText.TextAngle = float (aTextAngle);
2051 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
2052 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
2054 Standard_Real anRGB[3];
2055 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
2056 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2057 myCStructure->ContextFillArea.Style = aStyle;
2058 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
2059 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
2060 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
2062 if (theAspFill->Distinguish())
2064 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2066 myCStructure->ContextFillArea.BackIntColor.r = float (anRGB[0]);
2067 myCStructure->ContextFillArea.BackIntColor.g = float (anRGB[1]);
2068 myCStructure->ContextFillArea.BackIntColor.b = float (anRGB[2]);
2071 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1:0;
2072 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
2073 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
2074 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
2075 myCStructure->ContextFillArea.LineType = aLType;
2076 myCStructure->ContextFillArea.Width = float (aWidth);
2077 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
2079 // Front and Back face
2080 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
2081 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
2083 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
2084 // Light specificity
2085 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
2086 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
2087 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
2088 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
2089 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
2090 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
2093 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2094 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2095 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2096 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2099 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2102 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
2103 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
2104 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
2107 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
2108 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
2109 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
2112 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
2113 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
2114 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
2117 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
2118 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
2119 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
2121 myCStructure->ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
2124 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
2125 // Light specificity
2126 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
2127 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
2128 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
2129 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
2130 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
2131 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
2134 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2135 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2136 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2137 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2140 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2143 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
2144 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
2145 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
2148 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
2149 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
2150 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
2153 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
2154 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
2155 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
2158 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
2159 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
2160 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
2162 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
2164 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
2165 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
2166 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
2168 Standard_Integer aPolyMode;
2169 Standard_ShortReal aPolyFactor, aPolyUnits;
2170 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
2171 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
2172 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
2173 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
2176 //=============================================================================
2177 //function : GraphicHighlight
2179 //=============================================================================
2180 void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod theMethod)
2182 Standard_Real anRGB[3];
2183 myCStructure->highlight = 1;
2184 myHighlightMethod = theMethod;
2187 case Aspect_TOHM_COLOR:
2189 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2190 myCStructure->HighlightWithColor (Graphic3d_Vec3 (float (anRGB[0]), float (anRGB[1]), float (anRGB[2])), Standard_True);
2193 case Aspect_TOHM_BOUNDBOX:
2195 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2196 myCStructure->HighlightColor.r = float (anRGB[0]);
2197 myCStructure->HighlightColor.g = float (anRGB[1]);
2198 myCStructure->HighlightColor.b = float (anRGB[2]);
2199 myCStructure->HighlightWithBndBox (this, Standard_True);
2205 //=============================================================================
2206 //function : GraphicTransform
2208 //=============================================================================
2209 void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& theMatrix)
2211 for (Standard_Integer i = 0; i <= 3; ++i)
2213 for (Standard_Integer j = 0; j <= 3; ++j)
2215 myCStructure->Transformation.ChangeValue (i, j) = float (theMatrix (i, j));
2218 myCStructure->UpdateTransformation();
2221 //=============================================================================
2222 //function : GraphicUnHighlight
2224 //=============================================================================
2225 void Graphic3d_Structure::GraphicUnHighlight()
2227 myCStructure->highlight = 0;
2228 switch (myHighlightMethod)
2230 case Aspect_TOHM_COLOR:
2231 myCStructure->HighlightWithColor (Graphic3d_Vec3 (0.0f, 0.0f, 0.0f), Standard_False);
2233 case Aspect_TOHM_BOUNDBOX:
2234 myCStructure->HighlightWithBndBox (this, Standard_False);
2239 //=============================================================================
2240 //function : ComputeVisual
2242 //=============================================================================
2243 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
2245 return myComputeVisual;
2248 //=============================================================================
2249 //function : SetComputeVisual
2251 //=============================================================================
2252 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
2254 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
2255 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
2256 if (theVisual != Graphic3d_TOS_COMPUTED)
2258 myComputeVisual = theVisual;
2262 //=============================================================================
2263 //function : SetHLRValidation
2265 //=============================================================================
2266 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
2268 myCStructure->HLRValidation = theFlag ? 1 : 0;
2271 //=============================================================================
2272 //function : HLRValidation
2274 //=============================================================================
2275 Standard_Boolean Graphic3d_Structure::HLRValidation() const
2277 // Hidden parts stored in <me> are valid if :
2278 // 1/ the owner is defined.
2279 // 2/ they are not invalid.
2280 return myOwner != NULL
2281 && myCStructure->HLRValidation != 0;
2284 //=======================================================================
2285 //function : SetZLayer
2287 //=======================================================================
2288 void Graphic3d_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerId)
2290 // if the structure is not displayed, unable to change its display layer
2294 myStructureManager->ChangeZLayer (this, theLayerId);
2295 myCStructure->SetZLayer (theLayerId);
2298 //=======================================================================
2299 //function : GetZLayer
2301 //=======================================================================
2302 Graphic3d_ZLayerId Graphic3d_Structure::GetZLayer() const
2304 return myCStructure->ZLayer();
2307 //=======================================================================
2308 //function : SetClipPlanes
2310 //=======================================================================
2311 void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
2313 myCStructure->SetClipPlanes (thePlanes);
2316 //=======================================================================
2317 //function : GetClipPlanes
2319 //=======================================================================
2320 const Graphic3d_SequenceOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const
2322 return myCStructure->ClipPlanes();
2325 //=======================================================================
2326 //function : SetMutable
2328 //=======================================================================
2329 void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
2331 myCStructure->IsMutable = theIsMutable;
2334 //=======================================================================
2335 //function : IsMutable
2337 //=======================================================================
2338 Standard_Boolean Graphic3d_Structure::IsMutable() const
2340 return myCStructure->IsMutable;