1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Graphic3d_Structure.ixx>
17 #include <Graphic3d_Structure.pxx>
19 #include <Graphic3d_GraphicDriver.hxx>
20 #include <Graphic3d_MaterialAspect.hxx>
22 #include <Graphic3d_MapOfStructure.hxx>
23 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
25 #include <Quantity_Color.hxx>
26 #include <TColStd_Array2OfReal.hxx>
27 #include <Graphic3d_TextureMap.hxx>
29 #include <Aspect_PolygonOffsetMode.hxx>
33 //=============================================================================
34 //function : Graphic3d_Structure
36 //=============================================================================
37 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager)
38 : myStructureManager (theManager.operator->()),
39 myFirstStructureManager (theManager.operator->()),
40 myComputeVisual (Graphic3d_TOS_ALL),
41 myHighlightColor (Quantity_NOC_WHITE),
42 myHighlightMethod (Aspect_TOHM_COLOR),
44 myVisual (Graphic3d_TOS_ALL)
46 myCStructure = theManager->GraphicDriver()->Structure (theManager);
49 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
50 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
51 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
52 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
53 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
54 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
56 // update the associated CStructure
57 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
60 //=============================================================================
61 //function : Graphic3d_Structure
63 //=============================================================================
64 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
65 const Handle(Graphic3d_Structure)& thePrs)
66 : myStructureManager (theManager.operator->()),
67 myFirstStructureManager (theManager.operator->()),
68 myComputeVisual (thePrs->myComputeVisual),
69 myHighlightColor (thePrs->myHighlightColor),
70 myHighlightMethod (thePrs->myHighlightMethod),
71 myOwner (thePrs->myOwner),
72 myVisual (thePrs->myVisual)
74 myCStructure = thePrs->myCStructure->ShadowLink (theManager);
77 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
78 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
79 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
80 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
81 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
82 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
84 // update the associated CStructure
85 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
88 //=============================================================================
91 //=============================================================================
92 void Graphic3d_Structure::Destroy()
94 // as myFirstStructureManager can be already destroyed,
95 // avoid attempts to access it
96 myFirstStructureManager = NULL;
100 //=============================================================================
103 //=============================================================================
104 void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
106 if (IsDeleted()) return;
108 // clean groups in graphics driver at first
109 GraphicClear (theWithDestruction);
111 myCStructure->ContainsFacet = 0;
112 myStructureManager->Clear (this, theWithDestruction);
117 //=======================================================================
118 //function : CalculateBoundBox
119 //purpose : Calculates AABB of a structure.
120 //=======================================================================
121 void Graphic3d_Structure::CalculateBoundBox()
123 Graphic3d_BndBox4d aBox;
124 addTransformed (aBox, Standard_True);
125 if (aBox.IsValid() && myCStructure->TransformPersistence.Flag == 0)
127 Graphic3d_Vec4 aMinPt (RealToShortReal (aBox.CornerMin().x()),
128 RealToShortReal (aBox.CornerMin().y()),
129 RealToShortReal (aBox.CornerMin().z()),
131 Graphic3d_Vec4 aMaxPt (RealToShortReal (aBox.CornerMax().x()),
132 RealToShortReal (aBox.CornerMax().y()),
133 RealToShortReal (aBox.CornerMax().z()),
135 myCStructure->ChangeBoundingBox() = Graphic3d_BndBox4f (aMinPt, aMaxPt);
139 myCStructure->ChangeBoundingBox().Clear();
143 //=============================================================================
146 //=============================================================================
147 void Graphic3d_Structure::Remove()
149 if (IsDeleted()) return;
151 // clean groups in graphics driver at first; this is also should be done
152 // to avoid unwanted group cleaning in group's destructor
153 // Pass Standard_False to Clear(..) method to avoid updating in
154 // structure manager, it isn't necessary, besides of it structure manager
155 // could be already destroyed and invalid pointers used in structure;
156 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
158 aGroupIter.ChangeValue()->Clear (Standard_False);
161 Standard_Address APtr = (void *) this;
162 // It is necessary to remove the eventual pointer on the structure
163 // that can be destroyed, in the list of descendants
164 // of ancestors of this structure and in the list of ancestors
165 // of descendants of the same structure.
167 for (Standard_Integer aStructIdx = 1, aNbDesc = myDescendants.Size(); aStructIdx <= aNbDesc; ++aStructIdx)
169 ((Graphic3d_Structure *)myDescendants.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
172 for (Standard_Integer aStructIdx = 1, aNbAnces = myAncestors.Size(); aStructIdx <= aNbAnces; ++aStructIdx)
174 ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
177 // Destruction of me in the graphic library
178 const Standard_Integer aStructId = myCStructure->Id;
179 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
180 myCStructure.Nullify();
182 // Liberation of the identification if the destroyed structure
183 // in the first manager that performs creation of the structure.
184 if (myFirstStructureManager != NULL)
186 myFirstStructureManager->Remove (aStructId);
190 //=============================================================================
193 //=============================================================================
194 void Graphic3d_Structure::Display()
196 if (IsDeleted()) return;
198 if (!myCStructure->stick)
200 myCStructure->stick = 1;
201 myStructureManager->Display (this);
204 if (myCStructure->visible != 1)
206 myCStructure->visible = 1;
207 myCStructure->OnVisibilityChanged();
211 //=============================================================================
212 //function : SetIsForHighlight
214 //=============================================================================
215 void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight)
217 myCStructure->IsForHighlight = isForHighlight;
220 //=============================================================================
221 //function : SetDisplayPriority
223 //=============================================================================
224 void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
227 || thePriority == myCStructure->Priority)
232 myCStructure->PreviousPriority = myCStructure->Priority;
233 myCStructure->Priority = thePriority;
235 if (myCStructure->Priority != myCStructure->PreviousPriority)
237 Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
238 || (myCStructure->Priority < Structure_MIN_PRIORITY),
239 "Bad value for StructurePriority");
240 if (myCStructure->stick)
242 myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
247 //=============================================================================
248 //function : ResetDisplayPriority
250 //=============================================================================
251 void Graphic3d_Structure::ResetDisplayPriority()
254 || myCStructure->Priority == myCStructure->PreviousPriority)
259 const Standard_Integer aPriority = myCStructure->Priority;
260 myCStructure->Priority = myCStructure->PreviousPriority;
261 if (myCStructure->stick)
263 myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
267 //=============================================================================
268 //function : DisplayPriority
270 //=============================================================================
271 Standard_Integer Graphic3d_Structure::DisplayPriority() const
273 return myCStructure->Priority;
276 //=============================================================================
279 //=============================================================================
280 void Graphic3d_Structure::Erase()
287 if (myCStructure->stick)
289 myCStructure->stick = 0;
290 myStructureManager->Erase (this);
294 //=============================================================================
295 //function : Highlight
297 //=============================================================================
298 void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod theMethod,
299 const Quantity_Color& theColor,
300 const Standard_Boolean theToUpdateMgr)
307 myHighlightColor = theColor;
309 // Highlight on already Highlighted structure.
310 if (myCStructure->highlight)
312 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
313 if (anUpdateMode == Aspect_TOU_WAIT)
319 // To avoid call of method : Update()
320 // Not useful and can be costly.
321 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
323 myStructureManager->SetUpdateMode (anUpdateMode);
327 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
329 GraphicHighlight (theMethod);
336 if (myCStructure->stick)
338 myStructureManager->Highlight (this, theMethod);
344 //=============================================================================
345 //function : SetVisible
347 //=============================================================================
348 void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
350 if (IsDeleted()) return;
352 const unsigned isVisible = theValue ? 1 : 0;
353 if (myCStructure->visible == isVisible)
358 myCStructure->visible = isVisible;
359 myCStructure->OnVisibilityChanged();
363 //=============================================================================
364 //function : UnHighlight
366 //=============================================================================
367 void Graphic3d_Structure::UnHighlight()
369 if (IsDeleted()) return;
371 if (myCStructure->highlight)
373 myCStructure->highlight = 0;
375 GraphicUnHighlight();
376 myStructureManager->UnHighlight (this);
378 ResetDisplayPriority();
383 //=============================================================================
384 //function : HighlightColor
386 //=============================================================================
387 const Quantity_Color& Graphic3d_Structure::HighlightColor() const
389 return myHighlightColor;
392 //=============================================================================
393 //function : IsDisplayed
395 //=============================================================================
396 Standard_Boolean Graphic3d_Structure::IsDisplayed() const
398 return myCStructure->stick ? Standard_True : Standard_False;
401 //=============================================================================
402 //function : IsDeleted
404 //=============================================================================
405 Standard_Boolean Graphic3d_Structure::IsDeleted() const
407 return myCStructure.IsNull();
410 //=============================================================================
411 //function : IsHighlighted
413 //=============================================================================
414 Standard_Boolean Graphic3d_Structure::IsHighlighted() const
416 return myCStructure->highlight ? Standard_True : Standard_False;
419 //=============================================================================
420 //function : IsVisible
422 //=============================================================================
423 Standard_Boolean Graphic3d_Structure::IsVisible() const
425 return myCStructure->visible ? Standard_True : Standard_False;
428 //=============================================================================
429 //function : IsRotated
431 //=============================================================================
432 Standard_Boolean Graphic3d_Structure::IsRotated() const
434 // A somewhat light test !
435 return myCStructure->Transformation[0][1] != 0.0
436 || myCStructure->Transformation[0][2] != 0.0
437 || myCStructure->Transformation[1][0] != 0.0
438 || myCStructure->Transformation[1][2] != 0.0
439 || myCStructure->Transformation[2][0] != 0.0
440 || myCStructure->Transformation[2][1] != 0.0;
443 //=============================================================================
444 //function : IsTransformed
446 //=============================================================================
447 Standard_Boolean Graphic3d_Structure::IsTransformed() const
449 Standard_Boolean aResult = Standard_False;
450 for (Standard_Integer i = 0; i <= 3 && !aResult; ++i)
452 for (Standard_Integer j = 0; j <= 3 && !aResult; ++j)
455 aResult = myCStructure->Transformation[i][j] != 1.0;
457 aResult = myCStructure->Transformation[i][j] != 0.0;
463 //=============================================================================
464 //function : ContainsFacet
466 //=============================================================================
467 Standard_Boolean Graphic3d_Structure::ContainsFacet() const
471 return Standard_False;
473 else if (myCStructure->ContainsFacet > 0)
475 // if one of groups contains at least one facet, the structure contains it too
476 return Standard_True;
479 // stop at the first descendant containing at least one facet
480 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
482 if (((const Graphic3d_Structure *)anIter.Value())->ContainsFacet())
484 return Standard_True;
487 return Standard_False;
490 //=============================================================================
493 //=============================================================================
494 Standard_Boolean Graphic3d_Structure::IsEmpty() const
498 return Standard_True;
501 // structure is empty:
502 // - if all these groups are empty
503 // - or if all groups are empty and all their descendants are empty
504 // - or if all its descendants are empty
505 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
507 if (!aGroupIter.Value()->IsEmpty())
509 return Standard_False;
513 // stop at the first non-empty descendant
514 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
516 if (!((const Graphic3d_Structure* )anIter.Value())->IsEmpty())
518 return Standard_False;
521 return Standard_True;
524 //=============================================================================
525 //function : PrimitivesAspect
527 //=============================================================================
528 void Graphic3d_Structure::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& theAspLine,
529 Handle(Graphic3d_AspectText3d)& theAspText,
530 Handle(Graphic3d_AspectMarker3d)& theAspMarker,
531 Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
533 theAspLine = Line3dAspect();
534 theAspText = Text3dAspect();
535 theAspMarker = Marker3dAspect();
536 theAspFill = FillArea3dAspect();
539 //=============================================================================
540 //function : GroupsWithFacet
542 //=============================================================================
543 void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
545 myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
546 if (myCStructure->ContainsFacet < 0)
548 myCStructure->ContainsFacet = 0;
552 //=============================================================================
555 //=============================================================================
556 void Graphic3d_Structure::Compute()
558 // Implemented by Presentation
561 //=============================================================================
564 //=============================================================================
565 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
567 // Implemented by Presentation
571 //=============================================================================
574 //=============================================================================
575 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
576 const TColStd_Array2OfReal& )
578 // Implemented by Presentation
582 //=============================================================================
585 //=============================================================================
586 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
587 Handle(Graphic3d_Structure)& )
589 // Implemented by Presentation
592 //=============================================================================
595 //=============================================================================
596 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
597 const TColStd_Array2OfReal& ,
598 Handle(Graphic3d_Structure)& )
600 // Implemented by Presentation
603 //=============================================================================
604 //function : ReCompute
606 //=============================================================================
607 void Graphic3d_Structure::ReCompute()
609 myStructureManager->ReCompute (this);
612 //=============================================================================
613 //function : ReCompute
615 //=============================================================================
616 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
618 myStructureManager->ReCompute (this, theProjector);
621 //=============================================================================
622 //function : SetInfiniteState
624 //=============================================================================
625 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
627 myCStructure->IsInfinite = theToSet ? 1 : 0;
630 //=============================================================================
631 //function : IsInfinite
633 //=============================================================================
634 Standard_Boolean Graphic3d_Structure::IsInfinite() const
637 || myCStructure->IsInfinite;
640 //=============================================================================
641 //function : GraphicClear
643 //=============================================================================
644 void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
646 if (myCStructure.IsNull())
651 // clean and empty each group
652 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
654 aGroupIter.ChangeValue()->Clear();
656 if (!theWithDestruction)
661 while (!myCStructure->Groups().IsEmpty())
663 Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
666 myCStructure->Clear();
669 //=============================================================================
670 //function : GraphicConnect
672 //=============================================================================
673 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
675 myCStructure->Connect (*theDaughter->myCStructure);
678 //=============================================================================
679 //function : GraphicDisconnect
681 //=============================================================================
682 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
684 myCStructure->Disconnect (*theDaughter->myCStructure);
687 //=============================================================================
688 //function : Line3dAspect
690 //=============================================================================
691 Handle(Graphic3d_AspectLine3d) Graphic3d_Structure::Line3dAspect() const
693 const Standard_Real anRGB[3] =
695 Standard_Real (myCStructure->ContextLine.Color.r),
696 Standard_Real (myCStructure->ContextLine.Color.g),
697 Standard_Real (myCStructure->ContextLine.Color.b)
699 Quantity_Color aColor;
700 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
701 Aspect_TypeOfLine aLType = Aspect_TypeOfLine (myCStructure->ContextLine.LineType);
702 Standard_Real aWidth = Standard_Real (myCStructure->ContextLine.Width);
704 Handle(Graphic3d_AspectLine3d) anAspLine = new Graphic3d_AspectLine3d (aColor, aLType, aWidth);
705 anAspLine->SetShaderProgram (myCStructure->ContextLine.ShaderProgram);
709 //=============================================================================
710 //function : Text3dAspect
712 //=============================================================================
713 Handle(Graphic3d_AspectText3d) Graphic3d_Structure::Text3dAspect() const
715 const Standard_Real anRGB[3] =
717 Standard_Real (myCStructure->ContextText.Color.r),
718 Standard_Real (myCStructure->ContextText.Color.g),
719 Standard_Real (myCStructure->ContextText.Color.b)
721 Quantity_Color aColor;
722 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
723 Standard_CString aFont = Standard_CString (myCStructure->ContextText.Font);
724 Standard_Real anExpansion = Standard_Real (myCStructure->ContextText.Expan);
725 Standard_Real aSpace = Standard_Real (myCStructure->ContextText.Space);
726 Aspect_TypeOfStyleText aStyle = Aspect_TypeOfStyleText (myCStructure->ContextText.Style);
727 Aspect_TypeOfDisplayText aDispType = Aspect_TypeOfDisplayText (myCStructure->ContextText.DisplayType);
729 Handle(Graphic3d_AspectText3d) anAspText = new Graphic3d_AspectText3d (aColor, aFont, anExpansion, aSpace, aStyle, aDispType);
730 anAspText->SetShaderProgram (myCStructure->ContextText.ShaderProgram);
734 //=============================================================================
735 //function : Marker3dAspect
737 //=============================================================================
738 Handle(Graphic3d_AspectMarker3d) Graphic3d_Structure::Marker3dAspect() const
740 const Standard_Real anRGB[3] =
742 Standard_Real (myCStructure->ContextMarker.Color.r),
743 Standard_Real (myCStructure->ContextMarker.Color.g),
744 Standard_Real (myCStructure->ContextMarker.Color.b)
746 Quantity_Color aColor;
747 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
748 Aspect_TypeOfMarker aMType = myCStructure->ContextMarker.MarkerType;
749 Standard_Real aScale = Standard_Real (myCStructure->ContextMarker.Scale);
751 Handle(Graphic3d_AspectMarker3d) anAspMarker = new Graphic3d_AspectMarker3d (aMType, aColor, aScale);
752 anAspMarker->SetShaderProgram (myCStructure->ContextMarker.ShaderProgram);
756 //=============================================================================
757 //function : FillArea3dAspect
759 //=============================================================================
760 Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect() const
763 Graphic3d_MaterialAspect aBack;
764 aBack.SetShininess (Standard_Real (myCStructure->ContextFillArea.Back.Shininess));
765 aBack.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Back.Ambient));
766 aBack.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Back.Diffuse));
767 aBack.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Back.Specular));
768 aBack.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Back.Transparency));
769 aBack.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Back.Emission));
770 if (myCStructure->ContextFillArea.Back.IsAmbient == 1)
771 aBack.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
773 aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
774 if (myCStructure->ContextFillArea.Back.IsDiffuse == 1)
775 aBack.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
777 aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
778 if (myCStructure->ContextFillArea.Back.IsSpecular == 1)
779 aBack.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
781 aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
782 if (myCStructure->ContextFillArea.Back.IsEmission == 1)
783 aBack.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
785 aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
787 Quantity_Color aColor (Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.r),
788 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.g),
789 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.b), Quantity_TOC_RGB);
790 aBack.SetSpecularColor (aColor);
792 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.r),
793 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.g),
794 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.b), Quantity_TOC_RGB);
795 aBack.SetAmbientColor (aColor);
797 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.r),
798 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.g),
799 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.b), Quantity_TOC_RGB);
800 aBack.SetDiffuseColor (aColor);
802 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.r),
803 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.g),
804 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.b), Quantity_TOC_RGB);
805 aBack.SetEmissiveColor (aColor);
807 aBack.SetEnvReflexion (myCStructure->ContextFillArea.Back.EnvReflexion);
808 aBack.SetMaterialType (myCStructure->ContextFillArea.Back.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
811 Graphic3d_MaterialAspect aFront;
812 aFront.SetShininess (Standard_Real (myCStructure->ContextFillArea.Front.Shininess));
813 aFront.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Front.Ambient));
814 aFront.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Front.Diffuse));
815 aFront.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Front.Specular));
816 aFront.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Front.Transparency));
817 aFront.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Front.Emission));
818 if (myCStructure->ContextFillArea.Front.IsAmbient == 1)
819 aFront.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
821 aFront.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
822 if (myCStructure->ContextFillArea.Front.IsDiffuse == 1)
823 aFront.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
825 aFront.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
826 if (myCStructure->ContextFillArea.Front.IsSpecular == 1)
827 aFront.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
829 aFront.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
830 if (myCStructure->ContextFillArea.Front.Emission == 1)
831 aFront.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
833 aFront.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
835 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.r),
836 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.g),
837 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.b), Quantity_TOC_RGB);
838 aFront.SetSpecularColor (aColor);
840 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.r),
841 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.g),
842 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.b), Quantity_TOC_RGB);
843 aFront.SetAmbientColor (aColor);
845 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.r),
846 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.g),
847 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.b), Quantity_TOC_RGB);
848 aFront.SetDiffuseColor (aColor);
850 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.r),
851 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.g),
852 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.b), Quantity_TOC_RGB);
853 aFront.SetEmissiveColor (aColor);
855 aFront.SetEnvReflexion (myCStructure->ContextFillArea.Front.EnvReflexion);
856 aFront.SetMaterialType (myCStructure->ContextFillArea.Front.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
858 Quantity_Color anIntColor (Standard_Real (myCStructure->ContextFillArea.IntColor.r),
859 Standard_Real (myCStructure->ContextFillArea.IntColor.g),
860 Standard_Real (myCStructure->ContextFillArea.IntColor.b), Quantity_TOC_RGB);
861 Quantity_Color anEdgeColor (Standard_Real (myCStructure->ContextFillArea.EdgeColor.r),
862 Standard_Real (myCStructure->ContextFillArea.EdgeColor.g),
863 Standard_Real (myCStructure->ContextFillArea.EdgeColor.b), Quantity_TOC_RGB);
864 Handle(Graphic3d_AspectFillArea3d) anAspFill = new Graphic3d_AspectFillArea3d (Aspect_InteriorStyle (myCStructure->ContextFillArea.Style),
865 anIntColor, anEdgeColor,
866 Aspect_TypeOfLine (myCStructure->ContextFillArea.LineType),
867 Standard_Real (myCStructure->ContextFillArea.Width),
871 if (myCStructure->ContextFillArea.Edge == 1)
872 anAspFill->SetEdgeOn();
874 anAspFill->SetEdgeOff();
876 anAspFill->SetHatchStyle (Aspect_HatchStyle (myCStructure->ContextFillArea.Hatch));
878 // Front and Back face
879 if (myCStructure->ContextFillArea.Distinguish == 1)
880 anAspFill->SetDistinguishOn();
882 anAspFill->SetDistinguishOff();
883 if (myCStructure->ContextFillArea.BackFace == 1)
884 anAspFill->SuppressBackFace();
886 anAspFill->AllowBackFace();
888 anAspFill->SetTextureMap (myCStructure->ContextFillArea.Texture.TextureMap);
889 if (myCStructure->ContextFillArea.Texture.doTextureMap == 1)
891 anAspFill->SetTextureMapOn();
895 anAspFill->SetTextureMapOff();
897 anAspFill->SetShaderProgram (myCStructure->ContextFillArea.ShaderProgram);
898 anAspFill->SetPolygonOffsets (myCStructure->ContextFillArea.PolygonOffsetMode,
899 myCStructure->ContextFillArea.PolygonOffsetFactor,
900 myCStructure->ContextFillArea.PolygonOffsetUnits);
904 //=============================================================================
907 //=============================================================================
908 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
910 return myCStructure->Groups();
913 //=============================================================================
914 //function : NumberOfGroups
916 //=============================================================================
917 Standard_Integer Graphic3d_Structure::NumberOfGroups() const
919 return myCStructure->Groups().Length();
922 //=============================================================================
923 //function : SetPrimitivesAspect
925 //=============================================================================
926 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
928 if (IsDeleted()) return;
930 Standard_Real aWidth;
931 Quantity_Color aColor;
932 Aspect_TypeOfLine aLType;
933 theAspLine->Values (aColor, aLType, aWidth);
935 myCStructure->ContextLine.Color.r = float (aColor.Red());
936 myCStructure->ContextLine.Color.g = float (aColor.Green());
937 myCStructure->ContextLine.Color.b = float (aColor.Blue());
938 myCStructure->ContextLine.LineType = int (aLType);
939 myCStructure->ContextLine.Width = float (aWidth);
940 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
941 myCStructure->ContextLine.IsDef = 1;
943 myCStructure->UpdateAspects();
945 // Attributes are "IsSet" during the first update of context (line, marker...)
946 myCStructure->ContextLine.IsSet = 1;
947 myCStructure->ContextFillArea.IsSet = 1;
948 myCStructure->ContextMarker.IsSet = 1;
949 myCStructure->ContextText.IsSet = 1;
954 //=============================================================================
955 //function : SetPrimitivesAspect
957 //=============================================================================
958 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
960 if (IsDeleted()) return;
962 Standard_Real anRGB[3];
963 Standard_Real aWidth;
964 Quantity_Color anIntColor;
965 Quantity_Color aBackIntColor;
966 Quantity_Color anEdgeColor;
967 Aspect_TypeOfLine aLType;
968 Aspect_InteriorStyle aStyle;
969 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
971 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
972 myCStructure->ContextFillArea.Style = aStyle;
973 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
974 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
975 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
977 if (theAspFill->Distinguish())
979 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
981 myCStructure->ContextFillArea.BackIntColor.r = float(anRGB[0]);
982 myCStructure->ContextFillArea.BackIntColor.g = float(anRGB[1]);
983 myCStructure->ContextFillArea.BackIntColor.b = float(anRGB[2]);
986 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1 : 0;
987 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
988 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
989 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
990 myCStructure->ContextFillArea.LineType = aLType;
991 myCStructure->ContextFillArea.Width = float (aWidth);
992 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
994 // Front and Back face
995 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
996 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
999 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
1000 // Light specificity
1001 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
1002 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
1003 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
1004 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
1005 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
1006 myCStructure->ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
1007 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
1010 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1011 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1012 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1013 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1017 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0 );
1020 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
1021 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
1022 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
1025 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
1026 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
1027 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
1030 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
1031 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
1032 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
1035 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
1036 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
1037 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
1039 myCStructure->ContextFillArea.Back.EnvReflexion =
1040 float ((theAspFill->BackMaterial ()).EnvReflexion());
1043 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
1044 // Light specificity
1045 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
1046 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
1047 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
1048 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
1049 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
1050 myCStructure->ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
1051 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
1054 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1055 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1056 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1057 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1061 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
1064 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
1065 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
1066 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
1069 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
1070 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
1071 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
1074 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
1075 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
1076 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
1079 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
1080 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
1081 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
1083 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
1085 myCStructure->ContextFillArea.IsDef = 1; // Definition material ok
1087 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
1088 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
1089 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
1091 Standard_Integer aPolyMode;
1092 Standard_ShortReal aPolyFactor, aPolyUnits;
1093 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
1094 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
1095 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
1096 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
1098 myCStructure->UpdateAspects();
1100 // Attributes are "IsSet" during the first update of context (line, marker...)
1101 myCStructure->ContextLine.IsSet = 1;
1102 myCStructure->ContextFillArea.IsSet = 1;
1103 myCStructure->ContextMarker.IsSet = 1;
1104 myCStructure->ContextText.IsSet = 1;
1109 //=============================================================================
1110 //function : SetPrimitivesAspect
1112 //=============================================================================
1113 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
1115 if (IsDeleted()) return;
1117 Standard_CString aFont;
1118 Standard_Real aSpace, anExpansion, aTextAngle;
1119 Quantity_Color aColor, aColorSub;
1120 Aspect_TypeOfStyleText aStyle;
1121 Aspect_TypeOfDisplayText aDispType;
1122 Standard_Boolean isTextZoomable;
1123 Font_FontAspect aTextFontAspect;
1124 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDispType, aColorSub, isTextZoomable, aTextAngle, aTextFontAspect);
1126 myCStructure->ContextText.Color.r = float (aColor.Red());
1127 myCStructure->ContextText.Color.g = float (aColor.Green());
1128 myCStructure->ContextText.Color.b = float (aColor.Blue());
1129 myCStructure->ContextText.Font = aFont;
1130 myCStructure->ContextText.Expan = float (anExpansion);
1131 myCStructure->ContextText.Space = float (aSpace);
1132 myCStructure->ContextText.Style = aStyle;
1133 myCStructure->ContextText.DisplayType = aDispType;
1134 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
1135 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
1136 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
1137 myCStructure->ContextText.TextZoomable = isTextZoomable;
1138 myCStructure->ContextText.TextAngle = float (aTextAngle);
1139 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
1140 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
1142 myCStructure->ContextText.IsDef = 1;
1144 myCStructure->UpdateAspects();
1146 // Attributes are "IsSet" during the first update of a context (line, marker...)
1147 myCStructure->ContextLine.IsSet = 1;
1148 myCStructure->ContextFillArea.IsSet = 1;
1149 myCStructure->ContextMarker.IsSet = 1;
1150 myCStructure->ContextText.IsSet = 1;
1155 //=============================================================================
1156 //function : SetPrimitivesAspect
1158 //=============================================================================
1159 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
1161 if (IsDeleted()) return;
1163 Standard_Real aScale;
1164 Quantity_Color aColor;
1165 Aspect_TypeOfMarker aMType;
1166 theAspMarker->Values (aColor, aMType, aScale);
1168 myCStructure->ContextMarker.Color.r = float (aColor.Red());
1169 myCStructure->ContextMarker.Color.g = float (aColor.Green());
1170 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
1171 myCStructure->ContextMarker.MarkerType = aMType;
1172 myCStructure->ContextMarker.Scale = float (aScale);
1173 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
1174 myCStructure->ContextMarker.IsDef = 1;
1176 myCStructure->UpdateAspects();
1178 // Attributes are "IsSet" during the first update of a context (line, marker...)
1179 myCStructure->ContextLine.IsSet = 1;
1180 myCStructure->ContextFillArea.IsSet = 1;
1181 myCStructure->ContextMarker.IsSet = 1;
1182 myCStructure->ContextText.IsSet = 1;
1187 //=============================================================================
1188 //function : SetVisual
1190 //=============================================================================
1191 void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
1194 || myVisual == theVisual)
1199 if (!myCStructure->stick)
1201 myVisual = theVisual;
1202 SetComputeVisual (theVisual);
1206 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
1207 if (anUpdateMode == Aspect_TOU_WAIT)
1210 myVisual = theVisual;
1211 SetComputeVisual (theVisual);
1215 // To avoid calling method : Update ()
1216 // Not useful and can be costly.
1217 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
1219 myVisual = theVisual;
1220 SetComputeVisual (theVisual);
1221 myStructureManager->SetUpdateMode (anUpdateMode);
1227 //=============================================================================
1228 //function : SetZoomLimit
1230 //=============================================================================
1231 void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
1232 const Standard_Real theLimitSup)
1236 Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
1237 "Bad value for ZoomLimit inf");
1238 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
1239 "Bad value for ZoomLimit sup");
1240 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
1241 "ZoomLimit sup < ZoomLimit inf");
1244 //=============================================================================
1247 //=============================================================================
1248 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
1253 //=============================================================================
1254 //function : AcceptConnection
1256 //=============================================================================
1257 Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
1258 const Handle(Graphic3d_Structure)& theStructure2,
1259 const Graphic3d_TypeOfConnection theType)
1262 Graphic3d_MapOfStructure aSet;
1263 Graphic3d_Structure::Network (theStructure2, theType, aSet);
1264 return !aSet.Contains (theStructure1);
1267 //=============================================================================
1268 //function : Ancestors
1270 //=============================================================================
1271 void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
1273 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myAncestors); anIter.More(); anIter.Next())
1275 theSet.Add ((Graphic3d_Structure* )anIter.Value());
1279 //=============================================================================
1280 //function : SetOwner
1282 //=============================================================================
1283 void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
1288 //=============================================================================
1291 //=============================================================================
1292 Standard_Address Graphic3d_Structure::Owner() const
1297 //=============================================================================
1298 //function : Descendants
1300 //=============================================================================
1301 void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
1303 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1305 theSet.Add ((Graphic3d_Structure* )anIter.Value());
1309 //=============================================================================
1310 //function : AppendAncestor
1312 //=============================================================================
1313 Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor)
1315 const Standard_Integer aSize = myAncestors.Size();
1317 return myAncestors.Add (theAncestor) > aSize; // new object
1320 //=============================================================================
1321 //function : AppendDescendant
1323 //=============================================================================
1324 Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant)
1326 const Standard_Integer aSize = myDescendants.Size();
1328 return myDescendants.Add (theDescendant) > aSize; // new object
1331 //=============================================================================
1332 //function : RemoveAncestor
1334 //=============================================================================
1335 Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor)
1337 const Standard_Integer anIndex = myAncestors.FindIndex (theAncestor);
1341 myAncestors.Swap (anIndex, myAncestors.Size());
1342 myAncestors.RemoveLast();
1345 return anIndex != 0; // object was found
1348 //=============================================================================
1349 //function : RemoveDescendant
1351 //=============================================================================
1352 Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant)
1354 const Standard_Integer anIndex = myDescendants.FindIndex (theDescendant);
1358 myDescendants.Swap (anIndex, myDescendants.Size());
1359 myDescendants.RemoveLast();
1362 return anIndex != 0; // object was found
1365 //=============================================================================
1366 //function : Connect
1368 //=============================================================================
1369 void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
1370 const Graphic3d_TypeOfConnection theType,
1371 const Standard_Boolean theWithCheck)
1380 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
1385 const Standard_Address aStructure = theStructure.operator->();
1387 if (theType == Graphic3d_TOC_DESCENDANT)
1389 if (!AppendDescendant (aStructure))
1394 CalculateBoundBox();
1395 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
1397 GraphicConnect (theStructure);
1398 myStructureManager->Connect (this, theStructure);
1402 else // Graphic3d_TOC_ANCESTOR
1404 if (!AppendAncestor (aStructure))
1409 CalculateBoundBox();
1410 theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
1412 // myStructureManager->Connect is called in case if connection between parent and child
1416 //=============================================================================
1417 //function : Disconnect
1419 //=============================================================================
1420 void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
1427 const Standard_Address aStructure = theStructure.operator->();
1429 if (RemoveDescendant (aStructure))
1431 theStructure->Disconnect (this);
1433 GraphicDisconnect (theStructure);
1434 myStructureManager->Disconnect (this, theStructure);
1436 CalculateBoundBox();
1439 else if (RemoveAncestor (aStructure))
1441 theStructure->Disconnect (this);
1442 CalculateBoundBox();
1444 // no call of myStructureManager->Disconnect in case of an ancestor
1448 //=============================================================================
1449 //function : DisconnectAll
1451 //=============================================================================
1452 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
1454 if (IsDeleted()) return;
1458 case Graphic3d_TOC_DESCENDANT:
1460 for (Standard_Integer anIdx = 1, aLength = myDescendants.Size(); anIdx <= aLength; ++anIdx)
1462 // Value (1) instead of Value (i) as myDescendants
1464 // Graphic3d_Structure::Disconnect (AStructure)
1465 // that takes AStructure from myDescendants
1466 ((Graphic3d_Structure* )(myDescendants.FindKey (1)))->Disconnect (this);
1470 case Graphic3d_TOC_ANCESTOR:
1472 for (Standard_Integer anIdx = 1, aLength = myAncestors.Size(); anIdx <= aLength; ++anIdx)
1474 // Value (1) instead of Value (i) as myAncestors
1476 // Graphic3d_Structure::Disconnect (AStructure)
1477 // that takes AStructure from myAncestors
1478 ((Graphic3d_Structure* )(myAncestors.FindKey (1)))->Disconnect (this);
1485 //=============================================================================
1486 //function : Composition
1488 //=============================================================================
1489 Graphic3d_TypeOfComposition Graphic3d_Structure::Composition() const
1491 return myCStructure->Composition;
1494 //=============================================================================
1495 //function : SetTransform
1497 //=============================================================================
1498 void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& theMatrix,
1499 const Graphic3d_TypeOfComposition theType)
1501 if (IsDeleted()) return;
1503 Standard_Real valuetrsf;
1504 Standard_Real valueoldtrsf;
1505 Standard_Real valuenewtrsf;
1506 TColStd_Array2OfReal aNewTrsf (0, 3, 0, 3);
1507 TColStd_Array2OfReal aMatrix44 (0, 3, 0, 3);
1509 // Assign the new transformation in an array [0..3][0..3]
1510 // Avoid problems if the user has defined matrix [1..4][1..4]
1511 // or [3..6][-1..2] !!
1512 Standard_Integer lr = theMatrix.LowerRow();
1513 Standard_Integer ur = theMatrix.UpperRow();
1514 Standard_Integer lc = theMatrix.LowerCol();
1515 Standard_Integer uc = theMatrix.UpperCol();
1517 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1519 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1524 case Graphic3d_TOC_REPLACE:
1526 myCStructure->Composition = Graphic3d_TOC_REPLACE;
1527 // Update of CStructure
1528 for (Standard_Integer i = 0; i <= 3; ++i)
1530 for (Standard_Integer j = 0; j <= 3; ++j)
1532 myCStructure->Transformation[i][j] = float (theMatrix (lr + i, lc + j));
1533 aNewTrsf (i, j) = theMatrix (lr + i, lc + j);
1538 case Graphic3d_TOC_POSTCONCATENATE:
1540 myCStructure->Composition = Graphic3d_TOC_POSTCONCATENATE;
1541 // To simplify management of indices
1542 for (Standard_Integer i = 0; i <= 3; ++i)
1544 for (Standard_Integer j = 0; j <= 3; ++j)
1546 aMatrix44 (i, j) = theMatrix (lr + i, lc + j);
1550 // Calculation of the product of matrices
1551 for (Standard_Integer i = 0; i <= 3; ++i)
1553 for (Standard_Integer j = 0; j <= 3; ++j)
1555 aNewTrsf (i, j) = 0.0;
1556 for (Standard_Integer k = 0; k <= 3; ++k)
1558 valueoldtrsf = myCStructure->Transformation[i][k];
1559 valuetrsf = aMatrix44 (k, j);
1560 valuenewtrsf = aNewTrsf (i, j) + valueoldtrsf * valuetrsf;
1561 aNewTrsf (i, j) = valuenewtrsf;
1566 // Update of CStructure
1567 for (Standard_Integer i = 0; i <= 3; ++i)
1569 for (Standard_Integer j = 0; j <= 3; ++j)
1571 myCStructure->Transformation[i][j] = float (aNewTrsf (i, j));
1578 // If transformation, no validation of hidden already calculated parts
1584 myCStructure->UpdateTransformation();
1585 myStructureManager->SetTransform (this, aNewTrsf);
1590 //=============================================================================
1591 //function : Transform
1593 //=============================================================================
1594 void Graphic3d_Structure::Transform (TColStd_Array2OfReal& theMatrix) const
1597 Standard_Integer lr = theMatrix.LowerRow ();
1598 Standard_Integer ur = theMatrix.UpperRow ();
1599 Standard_Integer lc = theMatrix.LowerCol ();
1600 Standard_Integer uc = theMatrix.UpperCol ();
1602 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1603 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1605 for (Standard_Integer i = 0; i <= 3; ++i)
1607 for (Standard_Integer j = 0; j <= 3; ++j)
1609 theMatrix (lr + i, lc + j) = myCStructure->Transformation[i][j];
1615 //=============================================================================
1616 //function : MinMaxValues
1618 //=============================================================================
1619 Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
1621 Graphic3d_BndBox4d aBox;
1623 addTransformed (aBox, theToIgnoreInfiniteFlag);
1626 aResult.Add (gp_Pnt (aBox.CornerMin().x(),
1627 aBox.CornerMin().y(),
1628 aBox.CornerMin().z()));
1629 aResult.Add (gp_Pnt (aBox.CornerMax().x(),
1630 aBox.CornerMax().y(),
1631 aBox.CornerMax().z()));
1633 Standard_Real aLimMin = ShortRealFirst() + 1.0;
1634 Standard_Real aLimMax = ShortRealLast() - 1.0;
1635 gp_Pnt aMin = aResult.CornerMin();
1636 gp_Pnt aMax = aResult.CornerMax();
1637 if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin &&
1638 aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax)
1640 //For structure which infinite in all three dimensions the Whole bounding box will be returned
1647 //=============================================================================
1648 //function : Identification
1650 //=============================================================================
1651 Standard_Integer Graphic3d_Structure::Identification() const
1653 return myCStructure->Id;
1656 //=============================================================================
1657 //function : SetTransformPersistence
1659 //=============================================================================
1660 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag)
1662 SetTransformPersistence (theFlag, gp_Pnt (0.0, 0.0, 0.0));
1665 //=============================================================================
1666 //function : SetTransformPersistence
1668 //=============================================================================
1669 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
1670 const gp_Pnt& thePoint)
1672 if (IsDeleted()) return;
1674 myCStructure->TransformPersistence.Flag = theFlag;
1675 myCStructure->TransformPersistence.Point.x = float (thePoint.X());
1676 myCStructure->TransformPersistence.Point.y = float (thePoint.Y());
1677 myCStructure->TransformPersistence.Point.z = float (thePoint.Z());
1678 myCStructure->UpdateAspects();
1679 CalculateBoundBox();
1681 myCStructure->TransformPersistence.IsSet = 1;
1684 //=============================================================================
1685 //function : TransformPersistenceMode
1687 //=============================================================================
1688 Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1690 return myCStructure->TransformPersistence.Flag;
1693 //=============================================================================
1694 //function : TransformPersistencePoint
1696 //=============================================================================
1697 gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const
1699 gp_Pnt aPnt (0.0, 0.0, 0.0);
1700 aPnt.SetX (myCStructure->TransformPersistence.Point.x);
1701 aPnt.SetY (myCStructure->TransformPersistence.Point.y);
1702 aPnt.SetZ (myCStructure->TransformPersistence.Point.z);
1706 //=============================================================================
1709 //=============================================================================
1710 void Graphic3d_Structure::Remove (const Standard_Address thePtr,
1711 const Graphic3d_TypeOfConnection theType)
1713 if (theType == Graphic3d_TOC_DESCENDANT)
1715 RemoveDescendant (thePtr);
1719 RemoveAncestor (thePtr);
1723 //=============================================================================
1724 //function : NewGroup
1726 //=============================================================================
1727 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
1729 return myCStructure->NewGroup (this);
1732 //=============================================================================
1735 //=============================================================================
1736 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1738 if (theGroup.IsNull()
1739 || theGroup->myStructure != this)
1744 myCStructure->RemoveGroup (theGroup);
1745 theGroup->myStructure = NULL;
1748 //=============================================================================
1749 //function : StructureManager
1751 //=============================================================================
1752 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1754 return myStructureManager;
1757 //=============================================================================
1758 //function : minMaxCoord
1760 //=============================================================================
1761 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
1763 Graphic3d_BndBox4f aBnd;
1764 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1766 aBnd.Combine (aGroupIter.Value()->BoundingBox());
1771 //=============================================================================
1772 //function : addTransformed
1774 //=============================================================================
1775 void Graphic3d_Structure::getBox (Graphic3d_BndBox4d& theBox,
1776 const Standard_Boolean theToIgnoreInfiniteFlag) const
1778 Graphic3d_BndBox4f aBoxF = minMaxCoord();
1779 if (aBoxF.IsValid())
1781 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMin().x(),
1782 (Standard_Real )aBoxF.CornerMin().y(),
1783 (Standard_Real )aBoxF.CornerMin().z(),
1784 (Standard_Real )aBoxF.CornerMin().w()),
1785 Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMax().x(),
1786 (Standard_Real )aBoxF.CornerMax().y(),
1787 (Standard_Real )aBoxF.CornerMax().z(),
1788 (Standard_Real )aBoxF.CornerMax().w()));
1790 && !theToIgnoreInfiniteFlag)
1792 const Graphic3d_Vec4d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
1793 if (aDiagVec.xyz().SquareModulus() >= 500000.0 * 500000.0)
1795 // bounding borders of infinite line has been calculated as own point in center of this line
1796 theBox = Graphic3d_BndBox4d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
1800 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d (RealFirst(), RealFirst(), RealFirst(), 1.0),
1801 Graphic3d_Vec4d (RealLast(), RealLast(), RealLast(), 1.0));
1808 //=============================================================================
1809 //function : addTransformed
1811 //=============================================================================
1812 void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d& theBox,
1813 const Standard_Boolean theToIgnoreInfiniteFlag) const
1815 Graphic3d_BndBox4d aCombinedBox, aBox;
1816 getBox (aCombinedBox, theToIgnoreInfiniteFlag);
1818 for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next())
1820 const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )anIter.Value();
1821 aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1822 aCombinedBox.Combine (aBox);
1825 aBox = aCombinedBox;
1828 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1830 TransformBoundaries (aTrsf, aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1831 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1833 // if box is still valid after transformation
1836 theBox.Combine (aBox);
1838 else // it was infinite, return untransformed
1840 theBox.Combine (aCombinedBox);
1845 //=============================================================================
1846 //function : Transforms
1848 //=============================================================================
1849 void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1850 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
1851 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ)
1853 const Standard_Real aRL = RealLast();
1854 const Standard_Real aRF = RealFirst();
1855 if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1856 || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1864 Standard_Real A, B, C, D;
1869 theNewX = A * theX + B * theY + C * theZ + D;
1874 theNewY = A * theX + B * theY + C * theZ + D;
1879 theNewZ = A * theX + B * theY + C * theZ + D;
1883 //=============================================================================
1884 //function : Transforms
1886 //=============================================================================
1887 Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1888 const Graphic3d_Vector& theCoord)
1890 Standard_Real anXYZ[3];
1891 Graphic3d_Structure::Transforms (theTrsf,
1892 theCoord.X(), theCoord.Y(), theCoord.Z(),
1893 anXYZ[0], anXYZ[1], anXYZ[2]);
1894 return Graphic3d_Vector (anXYZ[0], anXYZ[1], anXYZ[2]);
1897 //=============================================================================
1898 //function : Transforms
1900 //=============================================================================
1901 Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1902 const Graphic3d_Vertex& theCoord)
1904 Standard_Real anXYZ[3];
1905 Graphic3d_Structure::Transforms (theTrsf,
1906 theCoord.X(), theCoord.Y(), theCoord.Z(),
1907 anXYZ[0], anXYZ[1], anXYZ[2]);
1908 return Graphic3d_Vertex (anXYZ[0], anXYZ[1], anXYZ[2]);
1911 //=============================================================================
1912 //function : Transforms
1914 //=============================================================================
1915 void Graphic3d_Structure::TransformBoundaries (const TColStd_Array2OfReal& theTrsf,
1916 Standard_Real& theXMin,
1917 Standard_Real& theYMin,
1918 Standard_Real& theZMin,
1919 Standard_Real& theXMax,
1920 Standard_Real& theYMax,
1921 Standard_Real& theZMax)
1923 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1925 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1926 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1928 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
1929 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1930 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1931 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1933 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
1934 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1935 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1936 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1938 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
1939 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1940 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1941 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1943 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
1944 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1945 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1946 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1948 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
1949 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1950 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1951 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1953 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
1954 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1955 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1956 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1966 //=============================================================================
1967 //function : Network
1969 //=============================================================================
1970 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
1971 const Graphic3d_TypeOfConnection theType,
1972 Graphic3d_MapOfStructure& theSet)
1974 Graphic3d_MapOfStructure aSetD, aSetA;
1975 theStructure->Descendants (aSetD);
1976 theStructure->Ancestors (aSetA);
1977 theSet.Add (theStructure);
1980 case Graphic3d_TOC_DESCENDANT:
1981 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
1983 Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
1986 case Graphic3d_TOC_ANCESTOR:
1987 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
1989 Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
1995 //=============================================================================
1996 //function : PrintNetwork
1998 //=============================================================================
1999 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
2000 const Graphic3d_TypeOfConnection theType)
2002 Graphic3d_MapOfStructure aSet;
2003 Graphic3d_Structure::Network (theStructure, theType, aSet);
2004 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
2006 std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
2008 std::cout << std::flush;
2011 //=============================================================================
2014 //=============================================================================
2015 void Graphic3d_Structure::Update() const
2022 if (myStructureManager->UpdateMode() == Aspect_TOU_ASAP)
2024 myStructureManager->Update();
2028 //=============================================================================
2029 //function : UpdateStructure
2031 //=============================================================================
2032 void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)& theAspLine,
2033 const Handle(Graphic3d_AspectText3d)& theAspText,
2034 const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
2035 const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
2037 Standard_CString aFont;
2038 Standard_Real aSpace, anExpansion, aWidth, aScale;
2039 Quantity_Color aColor, anIntColor, aBackIntColor, anEdgeColor, aColorSub;
2040 Aspect_TypeOfLine aLType;
2041 Aspect_TypeOfMarker aMType;
2042 Aspect_InteriorStyle aStyle;
2043 Aspect_TypeOfStyleText aStyleT;
2044 Aspect_TypeOfDisplayText aDisplayType;
2045 Standard_Boolean aTextZoomable;
2046 Standard_Real aTextAngle;
2047 Font_FontAspect aTextFontAspect;
2049 theAspLine->Values (aColor, aLType, aWidth);
2050 myCStructure->ContextLine.Color.r = float (aColor.Red());
2051 myCStructure->ContextLine.Color.g = float (aColor.Green());
2052 myCStructure->ContextLine.Color.b = float (aColor.Blue());
2053 myCStructure->ContextLine.LineType = aLType;
2054 myCStructure->ContextLine.Width = float (aWidth);
2055 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
2057 theAspMarker->Values (aColor, aMType, aScale);
2058 myCStructure->ContextMarker.Color.r = float (aColor.Red());
2059 myCStructure->ContextMarker.Color.g = float (aColor.Green());
2060 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
2061 myCStructure->ContextMarker.MarkerType = aMType;
2062 myCStructure->ContextMarker.Scale = float (aScale);
2063 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
2065 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyleT, aDisplayType, aColorSub, aTextZoomable, aTextAngle, aTextFontAspect);
2066 myCStructure->ContextText.Color.r = float (aColor.Red());
2067 myCStructure->ContextText.Color.g = float (aColor.Green());
2068 myCStructure->ContextText.Color.b = float (aColor.Blue());
2069 myCStructure->ContextText.Font = aFont;
2070 myCStructure->ContextText.Expan = float (anExpansion);
2071 myCStructure->ContextText.Style = aStyleT;
2072 myCStructure->ContextText.DisplayType = aDisplayType;
2073 myCStructure->ContextText.Space = float (aSpace);
2074 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
2075 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
2076 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
2077 myCStructure->ContextText.TextZoomable = aTextZoomable;
2078 myCStructure->ContextText.TextAngle = float (aTextAngle);
2079 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
2080 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
2082 Standard_Real anRGB[3];
2083 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
2084 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2085 myCStructure->ContextFillArea.Style = aStyle;
2086 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
2087 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
2088 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
2090 if (theAspFill->Distinguish())
2092 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2094 myCStructure->ContextFillArea.BackIntColor.r = float (anRGB[0]);
2095 myCStructure->ContextFillArea.BackIntColor.g = float (anRGB[1]);
2096 myCStructure->ContextFillArea.BackIntColor.b = float (anRGB[2]);
2099 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1:0;
2100 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
2101 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
2102 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
2103 myCStructure->ContextFillArea.LineType = aLType;
2104 myCStructure->ContextFillArea.Width = float (aWidth);
2105 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
2107 // Front and Back face
2108 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
2109 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
2111 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
2112 // Light specificity
2113 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
2114 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
2115 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
2116 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
2117 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
2118 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
2121 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2122 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2123 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2124 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2127 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2130 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
2131 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
2132 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
2135 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
2136 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
2137 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
2140 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
2141 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
2142 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
2145 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
2146 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
2147 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
2149 myCStructure->ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
2152 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
2153 // Light specificity
2154 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
2155 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
2156 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
2157 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
2158 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
2159 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
2162 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2163 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2164 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2165 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2168 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2171 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
2172 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
2173 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
2176 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
2177 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
2178 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
2181 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
2182 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
2183 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
2186 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
2187 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
2188 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
2190 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
2192 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
2193 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
2194 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
2196 Standard_Integer aPolyMode;
2197 Standard_ShortReal aPolyFactor, aPolyUnits;
2198 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
2199 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
2200 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
2201 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
2204 //=============================================================================
2205 //function : GraphicHighlight
2207 //=============================================================================
2208 void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod theMethod)
2210 Standard_Real anRGB[3];
2211 myCStructure->highlight = 1;
2212 myHighlightMethod = theMethod;
2215 case Aspect_TOHM_COLOR:
2217 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2218 myCStructure->HighlightWithColor (Graphic3d_Vec3 (float (anRGB[0]), float (anRGB[1]), float (anRGB[2])), Standard_True);
2221 case Aspect_TOHM_BOUNDBOX:
2223 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2224 myCStructure->HighlightColor.r = float (anRGB[0]);
2225 myCStructure->HighlightColor.g = float (anRGB[1]);
2226 myCStructure->HighlightColor.b = float (anRGB[2]);
2227 myCStructure->HighlightWithBndBox (this, Standard_True);
2233 //=============================================================================
2234 //function : GraphicTransform
2236 //=============================================================================
2237 void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& theMatrix)
2239 for (Standard_Integer i = 0; i <= 3; ++i)
2241 for (Standard_Integer j = 0; j <= 3; ++j)
2243 myCStructure->Transformation[i][j] = float (theMatrix (i, j));
2246 myCStructure->UpdateTransformation();
2249 //=============================================================================
2250 //function : GraphicUnHighlight
2252 //=============================================================================
2253 void Graphic3d_Structure::GraphicUnHighlight()
2255 myCStructure->highlight = 0;
2256 switch (myHighlightMethod)
2258 case Aspect_TOHM_COLOR:
2259 myCStructure->HighlightWithColor (Graphic3d_Vec3 (0.0f, 0.0f, 0.0f), Standard_False);
2261 case Aspect_TOHM_BOUNDBOX:
2262 myCStructure->HighlightWithBndBox (this, Standard_False);
2267 //=============================================================================
2268 //function : ComputeVisual
2270 //=============================================================================
2271 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
2273 return myComputeVisual;
2276 //=============================================================================
2277 //function : SetComputeVisual
2279 //=============================================================================
2280 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
2282 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
2283 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
2284 if (theVisual != Graphic3d_TOS_COMPUTED)
2286 myComputeVisual = theVisual;
2290 //=============================================================================
2291 //function : SetHLRValidation
2293 //=============================================================================
2294 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
2296 myCStructure->HLRValidation = theFlag ? 1 : 0;
2299 //=============================================================================
2300 //function : HLRValidation
2302 //=============================================================================
2303 Standard_Boolean Graphic3d_Structure::HLRValidation() const
2305 // Hidden parts stored in <me> are valid if :
2306 // 1/ the owner is defined.
2307 // 2/ they are not invalid.
2308 return myOwner != NULL
2309 && myCStructure->HLRValidation != 0;
2312 //=======================================================================
2313 //function : SetZLayer
2315 //=======================================================================
2316 void Graphic3d_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerId)
2318 // if the structure is not displayed, unable to change its display layer
2322 myStructureManager->ChangeZLayer (this, theLayerId);
2323 myCStructure->SetZLayer (theLayerId);
2326 //=======================================================================
2327 //function : GetZLayer
2329 //=======================================================================
2330 Graphic3d_ZLayerId Graphic3d_Structure::GetZLayer() const
2332 return myCStructure->ZLayer();
2335 //=======================================================================
2336 //function : SetClipPlanes
2338 //=======================================================================
2339 void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
2341 myCStructure->SetClipPlanes (thePlanes);
2344 //=======================================================================
2345 //function : GetClipPlanes
2347 //=======================================================================
2348 const Graphic3d_SequenceOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const
2350 return myCStructure->ClipPlanes();
2353 //=======================================================================
2354 //function : SetMutable
2356 //=======================================================================
2357 void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
2359 myCStructure->IsMutable = theIsMutable;
2362 //=======================================================================
2363 //function : IsMutable
2365 //=======================================================================
2366 Standard_Boolean Graphic3d_Structure::IsMutable() const
2368 return myCStructure->IsMutable;