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 //=============================================================================
44 //function : Graphic3d_Structure
46 //=============================================================================
47 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager)
48 : myStructureManager (theManager.operator->()),
49 myFirstStructureManager (theManager.operator->()),
50 myComputeVisual (Graphic3d_TOS_ALL),
51 myHighlightColor (Quantity_NOC_WHITE),
52 myHighlightMethod (Aspect_TOHM_COLOR),
54 myVisual (Graphic3d_TOS_ALL)
56 myCStructure = theManager->GraphicDriver()->CreateStructure (theManager);
59 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
60 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
61 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
62 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
63 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
64 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
66 // update the associated CStructure
67 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
70 //=============================================================================
71 //function : Graphic3d_Structure
73 //=============================================================================
74 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
75 const Handle(Graphic3d_Structure)& thePrs)
76 : myStructureManager (theManager.operator->()),
77 myFirstStructureManager (theManager.operator->()),
78 myComputeVisual (thePrs->myComputeVisual),
79 myHighlightColor (thePrs->myHighlightColor),
80 myHighlightMethod (thePrs->myHighlightMethod),
81 myOwner (thePrs->myOwner),
82 myVisual (thePrs->myVisual)
84 myCStructure = thePrs->myCStructure->ShadowLink (theManager);
87 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
88 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
89 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
90 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
91 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
92 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
94 // update the associated CStructure
95 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
98 //=============================================================================
101 //=============================================================================
102 void Graphic3d_Structure::Destroy()
104 // as myFirstStructureManager can be already destroyed,
105 // avoid attempts to access it
106 myFirstStructureManager = NULL;
110 //=============================================================================
113 //=============================================================================
114 void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
116 if (IsDeleted()) return;
118 // clean groups in graphics driver at first
119 GraphicClear (theWithDestruction);
121 myCStructure->ContainsFacet = 0;
122 myStructureManager->Clear (this, theWithDestruction);
127 //=======================================================================
128 //function : CalculateBoundBox
129 //purpose : Calculates AABB of a structure.
130 //=======================================================================
131 void Graphic3d_Structure::CalculateBoundBox()
133 Graphic3d_BndBox4d aBox;
134 addTransformed (aBox, Standard_True);
137 Graphic3d_Vec4 aMinPt (RealToShortReal (aBox.CornerMin().x()),
138 RealToShortReal (aBox.CornerMin().y()),
139 RealToShortReal (aBox.CornerMin().z()),
141 Graphic3d_Vec4 aMaxPt (RealToShortReal (aBox.CornerMax().x()),
142 RealToShortReal (aBox.CornerMax().y()),
143 RealToShortReal (aBox.CornerMax().z()),
145 myCStructure->ChangeBoundingBox() = Graphic3d_BndBox4f (aMinPt, aMaxPt);
149 myCStructure->ChangeBoundingBox().Clear();
153 //=============================================================================
156 //=============================================================================
157 void Graphic3d_Structure::Remove()
159 if (IsDeleted()) return;
161 // clean groups in graphics driver at first; this is also should be done
162 // to avoid unwanted group cleaning in group's destructor
163 // Pass Standard_False to Clear(..) method to avoid updating in
164 // structure manager, it isn't necessary, besides of it structure manager
165 // could be already destroyed and invalid pointers used in structure;
166 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
168 aGroupIter.ChangeValue()->Clear (Standard_False);
171 Standard_Address APtr = (void *) this;
172 // It is necessary to remove the eventual pointer on the structure
173 // that can be destroyed, in the list of descendants
174 // of ancestors of this structure and in the list of ancestors
175 // of descendants of the same structure.
177 for (Standard_Integer aStructIdx = 1, aNbDesc = myDescendants.Size(); aStructIdx <= aNbDesc; ++aStructIdx)
179 ((Graphic3d_Structure *)myDescendants.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
182 for (Standard_Integer aStructIdx = 1, aNbAnces = myAncestors.Size(); aStructIdx <= aNbAnces; ++aStructIdx)
184 ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
187 // Destruction of me in the graphic library
188 const Standard_Integer aStructId = myCStructure->Id;
189 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
190 myCStructure.Nullify();
192 // Liberation of the identification if the destroyed structure
193 // in the first manager that performs creation of the structure.
194 if (myFirstStructureManager != NULL)
196 myFirstStructureManager->Remove (aStructId);
200 //=============================================================================
203 //=============================================================================
204 void Graphic3d_Structure::Display()
206 if (IsDeleted()) return;
208 if (!myCStructure->stick)
210 myCStructure->stick = 1;
211 myStructureManager->Display (this);
214 if (myCStructure->visible != 1)
216 myCStructure->visible = 1;
217 myCStructure->OnVisibilityChanged();
221 //=============================================================================
222 //function : SetIsForHighlight
224 //=============================================================================
225 void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight)
227 myCStructure->IsForHighlight = isForHighlight;
230 //=============================================================================
231 //function : SetDisplayPriority
233 //=============================================================================
234 void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
237 || thePriority == myCStructure->Priority)
242 myCStructure->PreviousPriority = myCStructure->Priority;
243 myCStructure->Priority = thePriority;
245 if (myCStructure->Priority != myCStructure->PreviousPriority)
247 Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
248 || (myCStructure->Priority < Structure_MIN_PRIORITY),
249 "Bad value for StructurePriority");
250 if (myCStructure->stick)
252 myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
257 //=============================================================================
258 //function : ResetDisplayPriority
260 //=============================================================================
261 void Graphic3d_Structure::ResetDisplayPriority()
264 || myCStructure->Priority == myCStructure->PreviousPriority)
269 const Standard_Integer aPriority = myCStructure->Priority;
270 myCStructure->Priority = myCStructure->PreviousPriority;
271 if (myCStructure->stick)
273 myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
277 //=============================================================================
278 //function : DisplayPriority
280 //=============================================================================
281 Standard_Integer Graphic3d_Structure::DisplayPriority() const
283 return myCStructure->Priority;
286 //=============================================================================
289 //=============================================================================
290 void Graphic3d_Structure::Erase()
297 if (myCStructure->stick)
299 myCStructure->stick = 0;
300 myStructureManager->Erase (this);
304 //=============================================================================
305 //function : Highlight
307 //=============================================================================
308 void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod theMethod,
309 const Quantity_Color& theColor,
310 const Standard_Boolean theToUpdateMgr)
317 myHighlightColor = theColor;
319 // Highlight on already Highlighted structure.
320 if (myCStructure->highlight)
322 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
323 if (anUpdateMode == Aspect_TOU_WAIT)
329 // To avoid call of method : Update()
330 // Not useful and can be costly.
331 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
333 myStructureManager->SetUpdateMode (anUpdateMode);
337 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
339 GraphicHighlight (theMethod);
346 if (myCStructure->stick)
348 myStructureManager->Highlight (this, theMethod);
354 //=============================================================================
355 //function : SetVisible
357 //=============================================================================
358 void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
360 if (IsDeleted()) return;
362 const unsigned isVisible = theValue ? 1 : 0;
363 if (myCStructure->visible == isVisible)
368 myCStructure->visible = isVisible;
369 myCStructure->OnVisibilityChanged();
373 //=============================================================================
374 //function : UnHighlight
376 //=============================================================================
377 void Graphic3d_Structure::UnHighlight()
379 if (IsDeleted()) return;
381 if (myCStructure->highlight)
383 myCStructure->highlight = 0;
385 GraphicUnHighlight();
386 myStructureManager->UnHighlight (this);
388 ResetDisplayPriority();
393 //=============================================================================
394 //function : HighlightColor
396 //=============================================================================
397 const Quantity_Color& Graphic3d_Structure::HighlightColor() const
399 return myHighlightColor;
402 //=============================================================================
403 //function : IsDisplayed
405 //=============================================================================
406 Standard_Boolean Graphic3d_Structure::IsDisplayed() const
408 return myCStructure->stick ? Standard_True : Standard_False;
411 //=============================================================================
412 //function : IsDeleted
414 //=============================================================================
415 Standard_Boolean Graphic3d_Structure::IsDeleted() const
417 return myCStructure.IsNull();
420 //=============================================================================
421 //function : IsHighlighted
423 //=============================================================================
424 Standard_Boolean Graphic3d_Structure::IsHighlighted() const
426 return myCStructure->highlight ? Standard_True : Standard_False;
429 //=============================================================================
430 //function : IsVisible
432 //=============================================================================
433 Standard_Boolean Graphic3d_Structure::IsVisible() const
435 return myCStructure->visible ? Standard_True : Standard_False;
438 //=============================================================================
439 //function : IsTransformed
441 //=============================================================================
442 Standard_Boolean Graphic3d_Structure::IsTransformed() const
444 return !myCStructure->Transformation.IsIdentity();
447 //=============================================================================
448 //function : ContainsFacet
450 //=============================================================================
451 Standard_Boolean Graphic3d_Structure::ContainsFacet() const
455 return Standard_False;
457 else if (myCStructure->ContainsFacet > 0)
459 // if one of groups contains at least one facet, the structure contains it too
460 return Standard_True;
463 // stop at the first descendant containing at least one facet
464 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
466 if (((const Graphic3d_Structure *)anIter.Value())->ContainsFacet())
468 return Standard_True;
471 return Standard_False;
474 //=============================================================================
477 //=============================================================================
478 Standard_Boolean Graphic3d_Structure::IsEmpty() const
482 return Standard_True;
485 // structure is empty:
486 // - if all these groups are empty
487 // - or if all groups are empty and all their descendants are empty
488 // - or if all its descendants are empty
489 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
491 if (!aGroupIter.Value()->IsEmpty())
493 return Standard_False;
497 // stop at the first non-empty descendant
498 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
500 if (!((const Graphic3d_Structure* )anIter.Value())->IsEmpty())
502 return Standard_False;
505 return Standard_True;
508 //=============================================================================
509 //function : PrimitivesAspect
511 //=============================================================================
512 void Graphic3d_Structure::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& theAspLine,
513 Handle(Graphic3d_AspectText3d)& theAspText,
514 Handle(Graphic3d_AspectMarker3d)& theAspMarker,
515 Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
517 theAspLine = Line3dAspect();
518 theAspText = Text3dAspect();
519 theAspMarker = Marker3dAspect();
520 theAspFill = FillArea3dAspect();
523 //=============================================================================
524 //function : GroupsWithFacet
526 //=============================================================================
527 void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
529 myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
530 if (myCStructure->ContainsFacet < 0)
532 myCStructure->ContainsFacet = 0;
536 //=============================================================================
539 //=============================================================================
540 void Graphic3d_Structure::Compute()
542 // Implemented by Presentation
545 //=============================================================================
548 //=============================================================================
549 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
551 // Implemented by Presentation
555 //=============================================================================
558 //=============================================================================
559 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
560 const TColStd_Array2OfReal& )
562 // Implemented by Presentation
566 //=============================================================================
569 //=============================================================================
570 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
571 Handle(Graphic3d_Structure)& )
573 // Implemented by Presentation
576 //=============================================================================
579 //=============================================================================
580 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
581 const TColStd_Array2OfReal& ,
582 Handle(Graphic3d_Structure)& )
584 // Implemented by Presentation
587 //=============================================================================
588 //function : ReCompute
590 //=============================================================================
591 void Graphic3d_Structure::ReCompute()
593 myStructureManager->ReCompute (this);
596 //=============================================================================
597 //function : ReCompute
599 //=============================================================================
600 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
602 myStructureManager->ReCompute (this, theProjector);
605 //=============================================================================
606 //function : SetInfiniteState
608 //=============================================================================
609 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
611 myCStructure->IsInfinite = theToSet ? 1 : 0;
614 //=============================================================================
615 //function : IsInfinite
617 //=============================================================================
618 Standard_Boolean Graphic3d_Structure::IsInfinite() const
621 || myCStructure->IsInfinite;
624 //=============================================================================
625 //function : GraphicClear
627 //=============================================================================
628 void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
630 if (myCStructure.IsNull())
635 // clean and empty each group
636 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
638 aGroupIter.ChangeValue()->Clear();
640 if (!theWithDestruction)
645 while (!myCStructure->Groups().IsEmpty())
647 Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
650 myCStructure->Clear();
653 //=============================================================================
654 //function : GraphicConnect
656 //=============================================================================
657 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
659 myCStructure->Connect (*theDaughter->myCStructure);
662 //=============================================================================
663 //function : GraphicDisconnect
665 //=============================================================================
666 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
668 myCStructure->Disconnect (*theDaughter->myCStructure);
671 //=============================================================================
672 //function : Line3dAspect
674 //=============================================================================
675 Handle(Graphic3d_AspectLine3d) Graphic3d_Structure::Line3dAspect() const
677 const Standard_Real anRGB[3] =
679 Standard_Real (myCStructure->ContextLine.Color.r),
680 Standard_Real (myCStructure->ContextLine.Color.g),
681 Standard_Real (myCStructure->ContextLine.Color.b)
683 Quantity_Color aColor;
684 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
685 Aspect_TypeOfLine aLType = Aspect_TypeOfLine (myCStructure->ContextLine.LineType);
686 Standard_Real aWidth = Standard_Real (myCStructure->ContextLine.Width);
688 Handle(Graphic3d_AspectLine3d) anAspLine = new Graphic3d_AspectLine3d (aColor, aLType, aWidth);
689 anAspLine->SetShaderProgram (myCStructure->ContextLine.ShaderProgram);
693 //=============================================================================
694 //function : Text3dAspect
696 //=============================================================================
697 Handle(Graphic3d_AspectText3d) Graphic3d_Structure::Text3dAspect() const
699 const Standard_Real anRGB[3] =
701 Standard_Real (myCStructure->ContextText.Color.r),
702 Standard_Real (myCStructure->ContextText.Color.g),
703 Standard_Real (myCStructure->ContextText.Color.b)
705 Quantity_Color aColor;
706 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
707 Standard_CString aFont = Standard_CString (myCStructure->ContextText.Font);
708 Standard_Real anExpansion = Standard_Real (myCStructure->ContextText.Expan);
709 Standard_Real aSpace = Standard_Real (myCStructure->ContextText.Space);
710 Aspect_TypeOfStyleText aStyle = Aspect_TypeOfStyleText (myCStructure->ContextText.Style);
711 Aspect_TypeOfDisplayText aDispType = Aspect_TypeOfDisplayText (myCStructure->ContextText.DisplayType);
713 Handle(Graphic3d_AspectText3d) anAspText = new Graphic3d_AspectText3d (aColor, aFont, anExpansion, aSpace, aStyle, aDispType);
714 anAspText->SetShaderProgram (myCStructure->ContextText.ShaderProgram);
718 //=============================================================================
719 //function : Marker3dAspect
721 //=============================================================================
722 Handle(Graphic3d_AspectMarker3d) Graphic3d_Structure::Marker3dAspect() const
724 const Standard_Real anRGB[3] =
726 Standard_Real (myCStructure->ContextMarker.Color.r),
727 Standard_Real (myCStructure->ContextMarker.Color.g),
728 Standard_Real (myCStructure->ContextMarker.Color.b)
730 Quantity_Color aColor;
731 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
732 Aspect_TypeOfMarker aMType = myCStructure->ContextMarker.MarkerType;
733 Standard_Real aScale = Standard_Real (myCStructure->ContextMarker.Scale);
735 Handle(Graphic3d_AspectMarker3d) anAspMarker = new Graphic3d_AspectMarker3d (aMType, aColor, aScale);
736 anAspMarker->SetShaderProgram (myCStructure->ContextMarker.ShaderProgram);
740 //=============================================================================
741 //function : FillArea3dAspect
743 //=============================================================================
744 Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect() const
747 Graphic3d_MaterialAspect aBack;
748 aBack.SetShininess (Standard_Real (myCStructure->ContextFillArea.Back.Shininess));
749 aBack.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Back.Ambient));
750 aBack.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Back.Diffuse));
751 aBack.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Back.Specular));
752 aBack.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Back.Transparency));
753 aBack.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Back.Emission));
754 if (myCStructure->ContextFillArea.Back.IsAmbient == 1)
755 aBack.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
757 aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
758 if (myCStructure->ContextFillArea.Back.IsDiffuse == 1)
759 aBack.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
761 aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
762 if (myCStructure->ContextFillArea.Back.IsSpecular == 1)
763 aBack.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
765 aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
766 if (myCStructure->ContextFillArea.Back.IsEmission == 1)
767 aBack.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
769 aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
771 Quantity_Color aColor (Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.r),
772 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.g),
773 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.b), Quantity_TOC_RGB);
774 aBack.SetSpecularColor (aColor);
776 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.r),
777 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.g),
778 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.b), Quantity_TOC_RGB);
779 aBack.SetAmbientColor (aColor);
781 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.r),
782 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.g),
783 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.b), Quantity_TOC_RGB);
784 aBack.SetDiffuseColor (aColor);
786 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.r),
787 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.g),
788 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.b), Quantity_TOC_RGB);
789 aBack.SetEmissiveColor (aColor);
791 aBack.SetEnvReflexion (myCStructure->ContextFillArea.Back.EnvReflexion);
792 aBack.SetMaterialType (myCStructure->ContextFillArea.Back.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
794 aBack.SetRefractionIndex (Standard_Real (myCStructure->ContextFillArea.Back.RefractionIndex));
795 aBack.SetBSDF (myCStructure->ContextFillArea.Back.BSDF);
798 Graphic3d_MaterialAspect aFront;
799 aFront.SetShininess (Standard_Real (myCStructure->ContextFillArea.Front.Shininess));
800 aFront.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Front.Ambient));
801 aFront.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Front.Diffuse));
802 aFront.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Front.Specular));
803 aFront.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Front.Transparency));
804 aFront.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Front.Emission));
805 if (myCStructure->ContextFillArea.Front.IsAmbient == 1)
806 aFront.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
808 aFront.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
809 if (myCStructure->ContextFillArea.Front.IsDiffuse == 1)
810 aFront.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
812 aFront.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
813 if (myCStructure->ContextFillArea.Front.IsSpecular == 1)
814 aFront.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
816 aFront.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
817 if (myCStructure->ContextFillArea.Front.Emission == 1)
818 aFront.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
820 aFront.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
822 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.r),
823 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.g),
824 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.b), Quantity_TOC_RGB);
825 aFront.SetSpecularColor (aColor);
827 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.r),
828 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.g),
829 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.b), Quantity_TOC_RGB);
830 aFront.SetAmbientColor (aColor);
832 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.r),
833 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.g),
834 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.b), Quantity_TOC_RGB);
835 aFront.SetDiffuseColor (aColor);
837 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.r),
838 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.g),
839 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.b), Quantity_TOC_RGB);
840 aFront.SetEmissiveColor (aColor);
842 aFront.SetEnvReflexion (myCStructure->ContextFillArea.Front.EnvReflexion);
843 aFront.SetMaterialType (myCStructure->ContextFillArea.Front.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
845 aFront.SetRefractionIndex (Standard_Real (myCStructure->ContextFillArea.Front.RefractionIndex));
846 aFront.SetBSDF (myCStructure->ContextFillArea.Front.BSDF);
848 Quantity_Color anIntColor (Standard_Real (myCStructure->ContextFillArea.IntColor.r),
849 Standard_Real (myCStructure->ContextFillArea.IntColor.g),
850 Standard_Real (myCStructure->ContextFillArea.IntColor.b), Quantity_TOC_RGB);
851 Quantity_Color anEdgeColor (Standard_Real (myCStructure->ContextFillArea.EdgeColor.r),
852 Standard_Real (myCStructure->ContextFillArea.EdgeColor.g),
853 Standard_Real (myCStructure->ContextFillArea.EdgeColor.b), Quantity_TOC_RGB);
854 Handle(Graphic3d_AspectFillArea3d) anAspFill = new Graphic3d_AspectFillArea3d (Aspect_InteriorStyle (myCStructure->ContextFillArea.Style),
855 anIntColor, anEdgeColor,
856 Aspect_TypeOfLine (myCStructure->ContextFillArea.LineType),
857 Standard_Real (myCStructure->ContextFillArea.Width),
861 if (myCStructure->ContextFillArea.Edge == 1)
862 anAspFill->SetEdgeOn();
864 anAspFill->SetEdgeOff();
866 anAspFill->SetHatchStyle (Aspect_HatchStyle (myCStructure->ContextFillArea.Hatch));
868 // Front and Back face
869 if (myCStructure->ContextFillArea.Distinguish == 1)
870 anAspFill->SetDistinguishOn();
872 anAspFill->SetDistinguishOff();
873 if (myCStructure->ContextFillArea.BackFace == 1)
874 anAspFill->SuppressBackFace();
876 anAspFill->AllowBackFace();
878 anAspFill->SetTextureMap (myCStructure->ContextFillArea.Texture.TextureMap);
879 if (myCStructure->ContextFillArea.Texture.doTextureMap == 1)
881 anAspFill->SetTextureMapOn();
885 anAspFill->SetTextureMapOff();
887 anAspFill->SetShaderProgram (myCStructure->ContextFillArea.ShaderProgram);
888 anAspFill->SetPolygonOffsets (myCStructure->ContextFillArea.PolygonOffsetMode,
889 myCStructure->ContextFillArea.PolygonOffsetFactor,
890 myCStructure->ContextFillArea.PolygonOffsetUnits);
894 //=============================================================================
897 //=============================================================================
898 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
900 return myCStructure->Groups();
903 //=============================================================================
904 //function : NumberOfGroups
906 //=============================================================================
907 Standard_Integer Graphic3d_Structure::NumberOfGroups() const
909 return myCStructure->Groups().Length();
912 //=============================================================================
913 //function : SetPrimitivesAspect
915 //=============================================================================
916 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
918 if (IsDeleted()) return;
920 Standard_Real aWidth;
921 Quantity_Color aColor;
922 Aspect_TypeOfLine aLType;
923 theAspLine->Values (aColor, aLType, aWidth);
925 myCStructure->ContextLine.Color.r = float (aColor.Red());
926 myCStructure->ContextLine.Color.g = float (aColor.Green());
927 myCStructure->ContextLine.Color.b = float (aColor.Blue());
928 myCStructure->ContextLine.LineType = int (aLType);
929 myCStructure->ContextLine.Width = float (aWidth);
930 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
931 myCStructure->ContextLine.IsDef = 1;
933 myCStructure->UpdateAspects();
935 // Attributes are "IsSet" during the first update of context (line, marker...)
936 myCStructure->ContextLine.IsSet = 1;
937 myCStructure->ContextFillArea.IsSet = 1;
938 myCStructure->ContextMarker.IsSet = 1;
939 myCStructure->ContextText.IsSet = 1;
944 //=============================================================================
945 //function : SetPrimitivesAspect
947 //=============================================================================
948 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
950 if (IsDeleted()) return;
952 Standard_Real anRGB[3];
953 Standard_Real aWidth;
954 Quantity_Color anIntColor;
955 Quantity_Color aBackIntColor;
956 Quantity_Color anEdgeColor;
957 Aspect_TypeOfLine aLType;
958 Aspect_InteriorStyle aStyle;
959 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
961 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
962 myCStructure->ContextFillArea.Style = aStyle;
963 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
964 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
965 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
967 if (theAspFill->Distinguish())
969 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
971 myCStructure->ContextFillArea.BackIntColor.r = float(anRGB[0]);
972 myCStructure->ContextFillArea.BackIntColor.g = float(anRGB[1]);
973 myCStructure->ContextFillArea.BackIntColor.b = float(anRGB[2]);
976 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1 : 0;
977 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
978 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
979 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
980 myCStructure->ContextFillArea.LineType = aLType;
981 myCStructure->ContextFillArea.Width = float (aWidth);
982 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
984 // Front and Back face
985 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
986 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
989 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
991 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
992 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
993 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
994 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
995 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
996 myCStructure->ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
997 myCStructure->ContextFillArea.Back.BSDF = aBack.BSDF();
998 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
1001 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1002 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1003 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1004 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1008 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0 );
1011 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
1012 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
1013 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
1016 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
1017 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
1018 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
1021 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
1022 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
1023 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
1026 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
1027 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
1028 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
1030 myCStructure->ContextFillArea.Back.EnvReflexion =
1031 float ((theAspFill->BackMaterial ()).EnvReflexion());
1034 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
1035 // Light specificity
1036 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
1037 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
1038 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
1039 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
1040 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
1041 myCStructure->ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
1042 myCStructure->ContextFillArea.Front.BSDF = aFront.BSDF();
1043 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
1046 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1047 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1048 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1049 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1053 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
1056 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
1057 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
1058 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
1061 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
1062 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
1063 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
1066 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
1067 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
1068 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
1071 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
1072 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
1073 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
1075 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
1077 myCStructure->ContextFillArea.IsDef = 1; // Definition material ok
1079 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
1080 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
1081 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
1083 Standard_Integer aPolyMode;
1084 Standard_ShortReal aPolyFactor, aPolyUnits;
1085 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
1086 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
1087 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
1088 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
1090 myCStructure->UpdateAspects();
1092 // Attributes are "IsSet" during the first update of context (line, marker...)
1093 myCStructure->ContextLine.IsSet = 1;
1094 myCStructure->ContextFillArea.IsSet = 1;
1095 myCStructure->ContextMarker.IsSet = 1;
1096 myCStructure->ContextText.IsSet = 1;
1101 //=============================================================================
1102 //function : SetPrimitivesAspect
1104 //=============================================================================
1105 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
1107 if (IsDeleted()) return;
1109 Standard_CString aFont;
1110 Standard_Real aSpace, anExpansion, aTextAngle;
1111 Quantity_Color aColor, aColorSub;
1112 Aspect_TypeOfStyleText aStyle;
1113 Aspect_TypeOfDisplayText aDispType;
1114 Standard_Boolean isTextZoomable;
1115 Font_FontAspect aTextFontAspect;
1116 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDispType, aColorSub, isTextZoomable, aTextAngle, aTextFontAspect);
1118 myCStructure->ContextText.Color.r = float (aColor.Red());
1119 myCStructure->ContextText.Color.g = float (aColor.Green());
1120 myCStructure->ContextText.Color.b = float (aColor.Blue());
1121 myCStructure->ContextText.Font = aFont;
1122 myCStructure->ContextText.Expan = float (anExpansion);
1123 myCStructure->ContextText.Space = float (aSpace);
1124 myCStructure->ContextText.Style = aStyle;
1125 myCStructure->ContextText.DisplayType = aDispType;
1126 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
1127 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
1128 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
1129 myCStructure->ContextText.TextZoomable = isTextZoomable;
1130 myCStructure->ContextText.TextAngle = float (aTextAngle);
1131 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
1132 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
1134 myCStructure->ContextText.IsDef = 1;
1136 myCStructure->UpdateAspects();
1138 // Attributes are "IsSet" during the first update of a context (line, marker...)
1139 myCStructure->ContextLine.IsSet = 1;
1140 myCStructure->ContextFillArea.IsSet = 1;
1141 myCStructure->ContextMarker.IsSet = 1;
1142 myCStructure->ContextText.IsSet = 1;
1147 //=============================================================================
1148 //function : SetPrimitivesAspect
1150 //=============================================================================
1151 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
1153 if (IsDeleted()) return;
1155 Standard_Real aScale;
1156 Quantity_Color aColor;
1157 Aspect_TypeOfMarker aMType;
1158 theAspMarker->Values (aColor, aMType, aScale);
1160 myCStructure->ContextMarker.Color.r = float (aColor.Red());
1161 myCStructure->ContextMarker.Color.g = float (aColor.Green());
1162 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
1163 myCStructure->ContextMarker.MarkerType = aMType;
1164 myCStructure->ContextMarker.Scale = float (aScale);
1165 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
1166 myCStructure->ContextMarker.IsDef = 1;
1168 myCStructure->UpdateAspects();
1170 // Attributes are "IsSet" during the first update of a context (line, marker...)
1171 myCStructure->ContextLine.IsSet = 1;
1172 myCStructure->ContextFillArea.IsSet = 1;
1173 myCStructure->ContextMarker.IsSet = 1;
1174 myCStructure->ContextText.IsSet = 1;
1179 //=============================================================================
1180 //function : SetVisual
1182 //=============================================================================
1183 void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
1186 || myVisual == theVisual)
1191 if (!myCStructure->stick)
1193 myVisual = theVisual;
1194 SetComputeVisual (theVisual);
1198 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
1199 if (anUpdateMode == Aspect_TOU_WAIT)
1202 myVisual = theVisual;
1203 SetComputeVisual (theVisual);
1207 // To avoid calling method : Update ()
1208 // Not useful and can be costly.
1209 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
1211 myVisual = theVisual;
1212 SetComputeVisual (theVisual);
1213 myStructureManager->SetUpdateMode (anUpdateMode);
1219 //=============================================================================
1220 //function : SetZoomLimit
1222 //=============================================================================
1223 void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
1224 const Standard_Real theLimitSup)
1228 Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
1229 "Bad value for ZoomLimit inf");
1230 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
1231 "Bad value for ZoomLimit sup");
1232 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
1233 "ZoomLimit sup < ZoomLimit inf");
1236 //=============================================================================
1239 //=============================================================================
1240 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
1245 //=============================================================================
1246 //function : AcceptConnection
1248 //=============================================================================
1249 Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
1250 const Handle(Graphic3d_Structure)& theStructure2,
1251 const Graphic3d_TypeOfConnection theType)
1254 Graphic3d_MapOfStructure aSet;
1255 Graphic3d_Structure::Network (theStructure2, theType, aSet);
1256 return !aSet.Contains (theStructure1);
1259 //=============================================================================
1260 //function : Ancestors
1262 //=============================================================================
1263 void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
1265 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myAncestors); anIter.More(); anIter.Next())
1267 theSet.Add ((Graphic3d_Structure* )anIter.Value());
1271 //=============================================================================
1272 //function : SetOwner
1274 //=============================================================================
1275 void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
1280 //=============================================================================
1283 //=============================================================================
1284 Standard_Address Graphic3d_Structure::Owner() const
1289 //=============================================================================
1290 //function : Descendants
1292 //=============================================================================
1293 void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
1295 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1297 theSet.Add ((Graphic3d_Structure* )anIter.Value());
1301 //=============================================================================
1302 //function : AppendAncestor
1304 //=============================================================================
1305 Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor)
1307 const Standard_Integer aSize = myAncestors.Size();
1309 return myAncestors.Add (theAncestor) > aSize; // new object
1312 //=============================================================================
1313 //function : AppendDescendant
1315 //=============================================================================
1316 Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant)
1318 const Standard_Integer aSize = myDescendants.Size();
1320 return myDescendants.Add (theDescendant) > aSize; // new object
1323 //=============================================================================
1324 //function : RemoveAncestor
1326 //=============================================================================
1327 Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor)
1329 const Standard_Integer anIndex = myAncestors.FindIndex (theAncestor);
1333 myAncestors.Swap (anIndex, myAncestors.Size());
1334 myAncestors.RemoveLast();
1337 return anIndex != 0; // object was found
1340 //=============================================================================
1341 //function : RemoveDescendant
1343 //=============================================================================
1344 Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant)
1346 const Standard_Integer anIndex = myDescendants.FindIndex (theDescendant);
1350 myDescendants.Swap (anIndex, myDescendants.Size());
1351 myDescendants.RemoveLast();
1354 return anIndex != 0; // object was found
1357 //=============================================================================
1358 //function : Connect
1360 //=============================================================================
1361 void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
1362 const Graphic3d_TypeOfConnection theType,
1363 const Standard_Boolean theWithCheck)
1372 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
1377 const Standard_Address aStructure = theStructure.operator->();
1379 if (theType == Graphic3d_TOC_DESCENDANT)
1381 if (!AppendDescendant (aStructure))
1386 CalculateBoundBox();
1387 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
1389 GraphicConnect (theStructure);
1390 myStructureManager->Connect (this, theStructure);
1394 else // Graphic3d_TOC_ANCESTOR
1396 if (!AppendAncestor (aStructure))
1401 CalculateBoundBox();
1402 theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
1404 // myStructureManager->Connect is called in case if connection between parent and child
1408 //=============================================================================
1409 //function : Disconnect
1411 //=============================================================================
1412 void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
1419 const Standard_Address aStructure = theStructure.operator->();
1421 if (RemoveDescendant (aStructure))
1423 theStructure->Disconnect (this);
1425 GraphicDisconnect (theStructure);
1426 myStructureManager->Disconnect (this, theStructure);
1428 CalculateBoundBox();
1431 else if (RemoveAncestor (aStructure))
1433 theStructure->Disconnect (this);
1434 CalculateBoundBox();
1436 // no call of myStructureManager->Disconnect in case of an ancestor
1440 //=============================================================================
1441 //function : DisconnectAll
1443 //=============================================================================
1444 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
1446 if (IsDeleted()) return;
1450 case Graphic3d_TOC_DESCENDANT:
1452 for (Standard_Integer anIdx = 1, aLength = myDescendants.Size(); anIdx <= aLength; ++anIdx)
1454 // Value (1) instead of Value (i) as myDescendants
1456 // Graphic3d_Structure::Disconnect (AStructure)
1457 // that takes AStructure from myDescendants
1458 ((Graphic3d_Structure* )(myDescendants.FindKey (1)))->Disconnect (this);
1462 case Graphic3d_TOC_ANCESTOR:
1464 for (Standard_Integer anIdx = 1, aLength = myAncestors.Size(); anIdx <= aLength; ++anIdx)
1466 // Value (1) instead of Value (i) as myAncestors
1468 // Graphic3d_Structure::Disconnect (AStructure)
1469 // that takes AStructure from myAncestors
1470 ((Graphic3d_Structure* )(myAncestors.FindKey (1)))->Disconnect (this);
1477 //=============================================================================
1478 //function : SetTransform
1480 //=============================================================================
1481 void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& theMatrix,
1482 const Graphic3d_TypeOfComposition theType)
1484 if (IsDeleted()) return;
1486 Standard_Real valuetrsf;
1487 Standard_Real valueoldtrsf;
1488 Standard_Real valuenewtrsf;
1489 TColStd_Array2OfReal aNewTrsf (0, 3, 0, 3);
1490 TColStd_Array2OfReal aMatrix44 (0, 3, 0, 3);
1492 // Assign the new transformation in an array [0..3][0..3]
1493 // Avoid problems if the user has defined matrix [1..4][1..4]
1494 // or [3..6][-1..2] !!
1495 Standard_Integer lr = theMatrix.LowerRow();
1496 Standard_Integer ur = theMatrix.UpperRow();
1497 Standard_Integer lc = theMatrix.LowerCol();
1498 Standard_Integer uc = theMatrix.UpperCol();
1500 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1502 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1505 const Standard_Boolean wasTransformed = IsTransformed();
1508 case Graphic3d_TOC_REPLACE:
1510 // Update of CStructure
1511 for (Standard_Integer i = 0; i <= 3; ++i)
1513 for (Standard_Integer j = 0; j <= 3; ++j)
1515 myCStructure->Transformation.ChangeValue (i, j) = float (theMatrix (lr + i, lc + j));
1516 aNewTrsf (i, j) = theMatrix (lr + i, lc + j);
1521 case Graphic3d_TOC_POSTCONCATENATE:
1523 // To simplify management of indices
1524 for (Standard_Integer i = 0; i <= 3; ++i)
1526 for (Standard_Integer j = 0; j <= 3; ++j)
1528 aMatrix44 (i, j) = theMatrix (lr + i, lc + j);
1532 // Calculation of the product of matrices
1533 for (Standard_Integer i = 0; i <= 3; ++i)
1535 for (Standard_Integer j = 0; j <= 3; ++j)
1537 aNewTrsf (i, j) = 0.0;
1538 for (Standard_Integer k = 0; k <= 3; ++k)
1540 valueoldtrsf = myCStructure->Transformation.GetValue (i, k);
1541 valuetrsf = aMatrix44 (k, j);
1542 valuenewtrsf = aNewTrsf (i, j) + valueoldtrsf * valuetrsf;
1543 aNewTrsf (i, j) = valuenewtrsf;
1548 // Update of CStructure
1549 for (Standard_Integer i = 0; i <= 3; ++i)
1551 for (Standard_Integer j = 0; j <= 3; ++j)
1553 myCStructure->Transformation.ChangeValue (i, j) = float (aNewTrsf (i, j));
1560 // If transformation, no validation of hidden already calculated parts
1561 if (IsTransformed() || (!IsTransformed() && wasTransformed))
1566 myCStructure->UpdateTransformation();
1567 myStructureManager->SetTransform (this, aNewTrsf);
1572 //=============================================================================
1573 //function : Transform
1575 //=============================================================================
1576 void Graphic3d_Structure::Transform (TColStd_Array2OfReal& theMatrix) const
1579 Standard_Integer lr = theMatrix.LowerRow ();
1580 Standard_Integer ur = theMatrix.UpperRow ();
1581 Standard_Integer lc = theMatrix.LowerCol ();
1582 Standard_Integer uc = theMatrix.UpperCol ();
1584 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1585 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1587 for (Standard_Integer i = 0; i <= 3; ++i)
1589 for (Standard_Integer j = 0; j <= 3; ++j)
1591 theMatrix (lr + i, lc + j) = myCStructure->Transformation.GetValue (i, j);
1597 //=============================================================================
1598 //function : MinMaxValues
1600 //=============================================================================
1601 Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
1603 Graphic3d_BndBox4d aBox;
1605 addTransformed (aBox, theToIgnoreInfiniteFlag);
1608 aResult.Add (gp_Pnt (aBox.CornerMin().x(),
1609 aBox.CornerMin().y(),
1610 aBox.CornerMin().z()));
1611 aResult.Add (gp_Pnt (aBox.CornerMax().x(),
1612 aBox.CornerMax().y(),
1613 aBox.CornerMax().z()));
1615 Standard_Real aLimMin = ShortRealFirst() + 1.0;
1616 Standard_Real aLimMax = ShortRealLast() - 1.0;
1617 gp_Pnt aMin = aResult.CornerMin();
1618 gp_Pnt aMax = aResult.CornerMax();
1619 if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin &&
1620 aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax)
1622 //For structure which infinite in all three dimensions the Whole bounding box will be returned
1629 //=============================================================================
1630 //function : Identification
1632 //=============================================================================
1633 Standard_Integer Graphic3d_Structure::Identification() const
1635 return myCStructure->Id;
1638 //=============================================================================
1639 //function : SetTransformPersistence
1641 //=============================================================================
1642 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag)
1644 SetTransformPersistence (theFlag, gp_Pnt (0.0, 0.0, 0.0));
1647 //=============================================================================
1648 //function : SetTransformPersistence
1650 //=============================================================================
1651 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
1652 const gp_Pnt& thePoint)
1654 if (IsDeleted()) return;
1656 myCStructure->TransformPersistence.Flags = theFlag;
1657 myCStructure->TransformPersistence.Point.x() = thePoint.X();
1658 myCStructure->TransformPersistence.Point.y() = thePoint.Y();
1659 myCStructure->TransformPersistence.Point.z() = thePoint.Z();
1662 //=============================================================================
1663 //function : TransformPersistenceMode
1665 //=============================================================================
1666 Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1668 return myCStructure->TransformPersistence.Flags;
1671 //=============================================================================
1672 //function : TransformPersistencePoint
1674 //=============================================================================
1675 gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const
1677 gp_Pnt aPnt (0.0, 0.0, 0.0);
1678 aPnt.SetX (myCStructure->TransformPersistence.Point.x());
1679 aPnt.SetY (myCStructure->TransformPersistence.Point.y());
1680 aPnt.SetZ (myCStructure->TransformPersistence.Point.z());
1684 //=============================================================================
1687 //=============================================================================
1688 void Graphic3d_Structure::Remove (const Standard_Address thePtr,
1689 const Graphic3d_TypeOfConnection theType)
1691 if (theType == Graphic3d_TOC_DESCENDANT)
1693 RemoveDescendant (thePtr);
1697 RemoveAncestor (thePtr);
1701 //=============================================================================
1702 //function : NewGroup
1704 //=============================================================================
1705 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
1707 return myCStructure->NewGroup (this);
1710 //=============================================================================
1713 //=============================================================================
1714 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1716 if (theGroup.IsNull()
1717 || theGroup->myStructure != this)
1722 myCStructure->RemoveGroup (theGroup);
1723 theGroup->myStructure = NULL;
1726 //=============================================================================
1727 //function : StructureManager
1729 //=============================================================================
1730 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1732 return myStructureManager;
1735 //=============================================================================
1736 //function : minMaxCoord
1738 //=============================================================================
1739 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
1741 Graphic3d_BndBox4f aBnd;
1742 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1744 aBnd.Combine (aGroupIter.Value()->BoundingBox());
1749 //=============================================================================
1750 //function : addTransformed
1752 //=============================================================================
1753 void Graphic3d_Structure::getBox (Graphic3d_BndBox4d& theBox,
1754 const Standard_Boolean theToIgnoreInfiniteFlag) const
1756 Graphic3d_BndBox4f aBoxF = minMaxCoord();
1757 if (aBoxF.IsValid())
1759 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMin().x(),
1760 (Standard_Real )aBoxF.CornerMin().y(),
1761 (Standard_Real )aBoxF.CornerMin().z(),
1762 (Standard_Real )aBoxF.CornerMin().w()),
1763 Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMax().x(),
1764 (Standard_Real )aBoxF.CornerMax().y(),
1765 (Standard_Real )aBoxF.CornerMax().z(),
1766 (Standard_Real )aBoxF.CornerMax().w()));
1768 && !theToIgnoreInfiniteFlag)
1770 const Graphic3d_Vec4d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
1771 if (aDiagVec.xyz().SquareModulus() >= 500000.0 * 500000.0)
1773 // bounding borders of infinite line has been calculated as own point in center of this line
1774 theBox = Graphic3d_BndBox4d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
1778 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d (RealFirst(), RealFirst(), RealFirst(), 1.0),
1779 Graphic3d_Vec4d (RealLast(), RealLast(), RealLast(), 1.0));
1786 //=============================================================================
1787 //function : addTransformed
1789 //=============================================================================
1790 void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d& theBox,
1791 const Standard_Boolean theToIgnoreInfiniteFlag) const
1793 Graphic3d_BndBox4d aCombinedBox, aBox;
1794 getBox (aCombinedBox, theToIgnoreInfiniteFlag);
1796 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1798 const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )anIter.Value();
1799 aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1800 aCombinedBox.Combine (aBox);
1803 aBox = aCombinedBox;
1806 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1808 TransformBoundaries (aTrsf, aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1809 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1811 // if box is still valid after transformation
1814 theBox.Combine (aBox);
1816 else // it was infinite, return untransformed
1818 theBox.Combine (aCombinedBox);
1823 //=============================================================================
1824 //function : Transforms
1826 //=============================================================================
1827 void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1828 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
1829 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ)
1831 const Standard_Real aRL = RealLast();
1832 const Standard_Real aRF = RealFirst();
1833 if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1834 || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1842 Standard_Real A, B, C, D;
1847 theNewX = A * theX + B * theY + C * theZ + D;
1852 theNewY = A * theX + B * theY + C * theZ + D;
1857 theNewZ = A * theX + B * theY + C * theZ + D;
1861 //=============================================================================
1862 //function : Transforms
1864 //=============================================================================
1865 Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1866 const Graphic3d_Vector& theCoord)
1868 Standard_Real anXYZ[3];
1869 Graphic3d_Structure::Transforms (theTrsf,
1870 theCoord.X(), theCoord.Y(), theCoord.Z(),
1871 anXYZ[0], anXYZ[1], anXYZ[2]);
1872 return Graphic3d_Vector (anXYZ[0], anXYZ[1], anXYZ[2]);
1875 //=============================================================================
1876 //function : Transforms
1878 //=============================================================================
1879 Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1880 const Graphic3d_Vertex& theCoord)
1882 Standard_Real anXYZ[3];
1883 Graphic3d_Structure::Transforms (theTrsf,
1884 theCoord.X(), theCoord.Y(), theCoord.Z(),
1885 anXYZ[0], anXYZ[1], anXYZ[2]);
1886 return Graphic3d_Vertex (anXYZ[0], anXYZ[1], anXYZ[2]);
1889 //=============================================================================
1890 //function : Transforms
1892 //=============================================================================
1893 void Graphic3d_Structure::TransformBoundaries (const TColStd_Array2OfReal& theTrsf,
1894 Standard_Real& theXMin,
1895 Standard_Real& theYMin,
1896 Standard_Real& theZMin,
1897 Standard_Real& theXMax,
1898 Standard_Real& theYMax,
1899 Standard_Real& theZMax)
1901 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1903 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1904 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1906 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
1907 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1908 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1909 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1911 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
1912 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1913 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1914 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1916 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
1917 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1918 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1919 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1921 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
1922 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1923 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1924 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1926 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
1927 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1928 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1929 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1931 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
1932 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1933 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1934 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1944 //=============================================================================
1945 //function : Network
1947 //=============================================================================
1948 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
1949 const Graphic3d_TypeOfConnection theType,
1950 Graphic3d_MapOfStructure& theSet)
1952 Graphic3d_MapOfStructure aSetD, aSetA;
1953 theStructure->Descendants (aSetD);
1954 theStructure->Ancestors (aSetA);
1955 theSet.Add (theStructure);
1958 case Graphic3d_TOC_DESCENDANT:
1959 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
1961 Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
1964 case Graphic3d_TOC_ANCESTOR:
1965 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
1967 Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
1973 //=============================================================================
1974 //function : PrintNetwork
1976 //=============================================================================
1977 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
1978 const Graphic3d_TypeOfConnection theType)
1980 Graphic3d_MapOfStructure aSet;
1981 Graphic3d_Structure::Network (theStructure, theType, aSet);
1982 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
1984 std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
1986 std::cout << std::flush;
1989 //=============================================================================
1992 //=============================================================================
1993 void Graphic3d_Structure::Update() const
2000 myStructureManager->Update (myStructureManager->UpdateMode());
2003 //=============================================================================
2004 //function : UpdateStructure
2006 //=============================================================================
2007 void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)& theAspLine,
2008 const Handle(Graphic3d_AspectText3d)& theAspText,
2009 const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
2010 const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
2012 Standard_CString aFont;
2013 Standard_Real aSpace, anExpansion, aWidth, aScale;
2014 Quantity_Color aColor, anIntColor, aBackIntColor, anEdgeColor, aColorSub;
2015 Aspect_TypeOfLine aLType;
2016 Aspect_TypeOfMarker aMType;
2017 Aspect_InteriorStyle aStyle;
2018 Aspect_TypeOfStyleText aStyleT;
2019 Aspect_TypeOfDisplayText aDisplayType;
2020 Standard_Boolean aTextZoomable;
2021 Standard_Real aTextAngle;
2022 Font_FontAspect aTextFontAspect;
2024 theAspLine->Values (aColor, aLType, aWidth);
2025 myCStructure->ContextLine.Color.r = float (aColor.Red());
2026 myCStructure->ContextLine.Color.g = float (aColor.Green());
2027 myCStructure->ContextLine.Color.b = float (aColor.Blue());
2028 myCStructure->ContextLine.LineType = aLType;
2029 myCStructure->ContextLine.Width = float (aWidth);
2030 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
2032 theAspMarker->Values (aColor, aMType, aScale);
2033 myCStructure->ContextMarker.Color.r = float (aColor.Red());
2034 myCStructure->ContextMarker.Color.g = float (aColor.Green());
2035 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
2036 myCStructure->ContextMarker.MarkerType = aMType;
2037 myCStructure->ContextMarker.Scale = float (aScale);
2038 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
2040 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyleT, aDisplayType, aColorSub, aTextZoomable, aTextAngle, aTextFontAspect);
2041 myCStructure->ContextText.Color.r = float (aColor.Red());
2042 myCStructure->ContextText.Color.g = float (aColor.Green());
2043 myCStructure->ContextText.Color.b = float (aColor.Blue());
2044 myCStructure->ContextText.Font = aFont;
2045 myCStructure->ContextText.Expan = float (anExpansion);
2046 myCStructure->ContextText.Style = aStyleT;
2047 myCStructure->ContextText.DisplayType = aDisplayType;
2048 myCStructure->ContextText.Space = float (aSpace);
2049 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
2050 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
2051 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
2052 myCStructure->ContextText.TextZoomable = aTextZoomable;
2053 myCStructure->ContextText.TextAngle = float (aTextAngle);
2054 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
2055 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
2057 Standard_Real anRGB[3];
2058 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
2059 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2060 myCStructure->ContextFillArea.Style = aStyle;
2061 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
2062 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
2063 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
2065 if (theAspFill->Distinguish())
2067 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2069 myCStructure->ContextFillArea.BackIntColor.r = float (anRGB[0]);
2070 myCStructure->ContextFillArea.BackIntColor.g = float (anRGB[1]);
2071 myCStructure->ContextFillArea.BackIntColor.b = float (anRGB[2]);
2074 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1:0;
2075 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
2076 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
2077 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
2078 myCStructure->ContextFillArea.LineType = aLType;
2079 myCStructure->ContextFillArea.Width = float (aWidth);
2080 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
2082 // Front and Back face
2083 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
2084 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
2086 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
2087 // Light specificity
2088 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
2089 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
2090 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
2091 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
2092 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
2093 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
2096 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2097 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2098 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2099 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2102 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2105 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
2106 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
2107 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
2110 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
2111 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
2112 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
2115 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
2116 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
2117 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
2120 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
2121 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
2122 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
2124 myCStructure->ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
2127 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
2128 // Light specificity
2129 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
2130 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
2131 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
2132 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
2133 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
2134 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
2137 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2138 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2139 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2140 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2143 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2146 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
2147 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
2148 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
2151 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
2152 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
2153 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
2156 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
2157 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
2158 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
2161 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
2162 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
2163 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
2165 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
2167 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
2168 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
2169 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
2171 Standard_Integer aPolyMode;
2172 Standard_ShortReal aPolyFactor, aPolyUnits;
2173 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
2174 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
2175 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
2176 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
2179 //=============================================================================
2180 //function : GraphicHighlight
2182 //=============================================================================
2183 void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod theMethod)
2185 Standard_Real anRGB[3];
2186 myCStructure->highlight = 1;
2187 myHighlightMethod = theMethod;
2190 case Aspect_TOHM_COLOR:
2192 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2193 myCStructure->HighlightWithColor (Graphic3d_Vec3 (float (anRGB[0]), float (anRGB[1]), float (anRGB[2])), Standard_True);
2196 case Aspect_TOHM_BOUNDBOX:
2198 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2199 myCStructure->HighlightColor.r = float (anRGB[0]);
2200 myCStructure->HighlightColor.g = float (anRGB[1]);
2201 myCStructure->HighlightColor.b = float (anRGB[2]);
2202 myCStructure->HighlightWithBndBox (this, Standard_True);
2208 //=============================================================================
2209 //function : GraphicTransform
2211 //=============================================================================
2212 void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& theMatrix)
2214 for (Standard_Integer i = 0; i <= 3; ++i)
2216 for (Standard_Integer j = 0; j <= 3; ++j)
2218 myCStructure->Transformation.ChangeValue (i, j) = float (theMatrix (i, j));
2221 myCStructure->UpdateTransformation();
2224 //=============================================================================
2225 //function : GraphicUnHighlight
2227 //=============================================================================
2228 void Graphic3d_Structure::GraphicUnHighlight()
2230 myCStructure->highlight = 0;
2231 switch (myHighlightMethod)
2233 case Aspect_TOHM_COLOR:
2234 myCStructure->HighlightWithColor (Graphic3d_Vec3 (0.0f, 0.0f, 0.0f), Standard_False);
2236 case Aspect_TOHM_BOUNDBOX:
2237 myCStructure->HighlightWithBndBox (this, Standard_False);
2242 //=============================================================================
2243 //function : ComputeVisual
2245 //=============================================================================
2246 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
2248 return myComputeVisual;
2251 //=============================================================================
2252 //function : SetComputeVisual
2254 //=============================================================================
2255 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
2257 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
2258 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
2259 if (theVisual != Graphic3d_TOS_COMPUTED)
2261 myComputeVisual = theVisual;
2265 //=============================================================================
2266 //function : SetHLRValidation
2268 //=============================================================================
2269 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
2271 myCStructure->HLRValidation = theFlag ? 1 : 0;
2274 //=============================================================================
2275 //function : HLRValidation
2277 //=============================================================================
2278 Standard_Boolean Graphic3d_Structure::HLRValidation() const
2280 // Hidden parts stored in <me> are valid if :
2281 // 1/ the owner is defined.
2282 // 2/ they are not invalid.
2283 return myOwner != NULL
2284 && myCStructure->HLRValidation != 0;
2287 //=======================================================================
2288 //function : SetZLayer
2290 //=======================================================================
2291 void Graphic3d_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerId)
2293 // if the structure is not displayed, unable to change its display layer
2297 myStructureManager->ChangeZLayer (this, theLayerId);
2298 myCStructure->SetZLayer (theLayerId);
2301 //=======================================================================
2302 //function : GetZLayer
2304 //=======================================================================
2305 Graphic3d_ZLayerId Graphic3d_Structure::GetZLayer() const
2307 return myCStructure->ZLayer();
2310 //=======================================================================
2311 //function : SetClipPlanes
2313 //=======================================================================
2314 void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
2316 myCStructure->SetClipPlanes (thePlanes);
2319 //=======================================================================
2320 //function : GetClipPlanes
2322 //=======================================================================
2323 const Graphic3d_SequenceOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const
2325 return myCStructure->ClipPlanes();
2328 //=======================================================================
2329 //function : SetMutable
2331 //=======================================================================
2332 void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
2334 myCStructure->IsMutable = theIsMutable;
2337 //=======================================================================
2338 //function : IsMutable
2340 //=======================================================================
2341 Standard_Boolean Graphic3d_Structure::IsMutable() const
2343 return myCStructure->IsMutable;