1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Graphic3d_Structure.ixx>
17 #include <Graphic3d_Structure.pxx>
19 #include <Graphic3d_GraphicDriver.hxx>
20 #include <Graphic3d_MaterialAspect.hxx>
22 #include <Graphic3d_MapOfStructure.hxx>
23 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
25 #include <Quantity_Color.hxx>
26 #include <TColStd_Array2OfReal.hxx>
27 #include <Graphic3d_TextureMap.hxx>
29 #include <Aspect_PolygonOffsetMode.hxx>
33 //=============================================================================
34 //function : Graphic3d_Structure
36 //=============================================================================
37 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager)
38 : myStructureManager (theManager.operator->()),
39 myFirstStructureManager (theManager.operator->()),
40 myComputeVisual (Graphic3d_TOS_ALL),
41 myHighlightColor (Quantity_NOC_WHITE),
42 myHighlightMethod (Aspect_TOHM_COLOR),
44 myVisual (Graphic3d_TOS_ALL)
46 myCStructure = theManager->GraphicDriver()->Structure (theManager);
49 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
50 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
51 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
52 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
53 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
54 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
56 // update the associated CStructure
57 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
60 //=============================================================================
61 //function : Graphic3d_Structure
63 //=============================================================================
64 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
65 const Handle(Graphic3d_Structure)& thePrs)
66 : myStructureManager (theManager.operator->()),
67 myFirstStructureManager (theManager.operator->()),
68 myComputeVisual (thePrs->myComputeVisual),
69 myHighlightColor (thePrs->myHighlightColor),
70 myHighlightMethod (thePrs->myHighlightMethod),
71 myOwner (thePrs->myOwner),
72 myVisual (thePrs->myVisual)
74 myCStructure = thePrs->myCStructure->ShadowLink (theManager);
77 Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d();
78 Handle(Graphic3d_AspectText3d) aAspectText3d = new Graphic3d_AspectText3d();
79 Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = new Graphic3d_AspectMarker3d();
80 Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = new Graphic3d_AspectFillArea3d();
81 theManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
82 aAspectFillArea3d->SetPolygonOffsets (Aspect_POM_Fill, 1.0, 0.0);
84 // update the associated CStructure
85 UpdateStructure (aAspectLine3d, aAspectText3d, aAspectMarker3d, aAspectFillArea3d);
88 //=============================================================================
91 //=============================================================================
92 void Graphic3d_Structure::Destroy()
94 // as myFirstStructureManager can be already destroyed,
95 // avoid attempts to access it
96 myFirstStructureManager = NULL;
100 //=============================================================================
103 //=============================================================================
104 void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
106 if (IsDeleted()) return;
108 // clean groups in graphics driver at first
109 GraphicClear (theWithDestruction);
111 myCStructure->ContainsFacet = 0;
112 myStructureManager->Clear (this, theWithDestruction);
117 //=======================================================================
118 //function : CalculateBoundBox
119 //purpose : Calculates AABB of a structure.
120 //=======================================================================
121 void Graphic3d_Structure::CalculateBoundBox()
123 Graphic3d_BndBox4d aBox;
124 addTransformed (aBox, Standard_True);
125 if (aBox.IsValid() && myCStructure->TransformPersistence.Flag == 0)
127 Graphic3d_Vec4 aMinPt (RealToShortReal (aBox.CornerMin().x()),
128 RealToShortReal (aBox.CornerMin().y()),
129 RealToShortReal (aBox.CornerMin().z()),
131 Graphic3d_Vec4 aMaxPt (RealToShortReal (aBox.CornerMax().x()),
132 RealToShortReal (aBox.CornerMax().y()),
133 RealToShortReal (aBox.CornerMax().z()),
135 myCStructure->ChangeBoundingBox() = Graphic3d_BndBox4f (aMinPt, aMaxPt);
139 myCStructure->ChangeBoundingBox().Clear();
143 //=============================================================================
146 //=============================================================================
147 void Graphic3d_Structure::Remove()
149 if (IsDeleted()) return;
151 // clean groups in graphics driver at first; this is also should be done
152 // to avoid unwanted group cleaning in group's destructor
153 // Pass Standard_False to Clear(..) method to avoid updating in
154 // structure manager, it isn't necessary, besides of it structure manager
155 // could be already destroyed and invalid pointers used in structure;
156 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
158 aGroupIter.ChangeValue()->Clear (Standard_False);
161 Standard_Address APtr = (void *) this;
162 // It is necessary to remove the eventual pointer on the structure
163 // that can be destroyed, in the list of descendants
164 // of ancestors of this structure and in the list of ancestors
165 // of descendants of the same structure.
167 const Standard_Integer aNbDesc = myDescendants.Length();
168 for (Standard_Integer aStructIter = 1; aStructIter <= aNbDesc; ++aStructIter)
170 ((Graphic3d_Structure *)(myDescendants.ChangeValue (aStructIter)))->Remove (APtr, Graphic3d_TOC_ANCESTOR);
173 const Standard_Integer aNbAnces = myAncestors.Length();
174 for (Standard_Integer aStructIter = 1; aStructIter <= aNbAnces; ++aStructIter)
176 ((Graphic3d_Structure *)(myAncestors.ChangeValue (aStructIter)))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
179 // Destruction of me in the graphic library
180 const Standard_Integer aStructId = myCStructure->Id;
181 myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
182 myCStructure.Nullify();
184 // Liberation of the identification if the destroyed structure
185 // in the first manager that performs creation of the structure.
186 if (myFirstStructureManager != NULL)
188 myFirstStructureManager->Remove (aStructId);
192 //=============================================================================
195 //=============================================================================
196 void Graphic3d_Structure::Display()
198 if (IsDeleted()) return;
200 if (!myCStructure->stick)
202 myCStructure->stick = 1;
203 myStructureManager->Display (this);
206 if (myCStructure->visible != 1)
208 myCStructure->visible = 1;
209 myCStructure->OnVisibilityChanged();
213 //=============================================================================
214 //function : SetIsForHighlight
216 //=============================================================================
217 void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight)
219 myCStructure->IsForHighlight = isForHighlight;
222 //=============================================================================
223 //function : SetDisplayPriority
225 //=============================================================================
226 void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority)
229 || thePriority == myCStructure->Priority)
234 myCStructure->PreviousPriority = myCStructure->Priority;
235 myCStructure->Priority = thePriority;
237 if (myCStructure->Priority != myCStructure->PreviousPriority)
239 Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY)
240 || (myCStructure->Priority < Structure_MIN_PRIORITY),
241 "Bad value for StructurePriority");
242 if (myCStructure->stick)
244 myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority);
249 //=============================================================================
250 //function : ResetDisplayPriority
252 //=============================================================================
253 void Graphic3d_Structure::ResetDisplayPriority()
256 || myCStructure->Priority == myCStructure->PreviousPriority)
261 const Standard_Integer aPriority = myCStructure->Priority;
262 myCStructure->Priority = myCStructure->PreviousPriority;
263 if (myCStructure->stick)
265 myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority);
269 //=============================================================================
270 //function : DisplayPriority
272 //=============================================================================
273 Standard_Integer Graphic3d_Structure::DisplayPriority() const
275 return myCStructure->Priority;
278 //=============================================================================
281 //=============================================================================
282 void Graphic3d_Structure::Erase()
289 if (myCStructure->stick)
291 myCStructure->stick = 0;
292 myStructureManager->Erase (this);
296 //=============================================================================
297 //function : Highlight
299 //=============================================================================
300 void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod theMethod,
301 const Quantity_Color& theColor,
302 const Standard_Boolean theToUpdateMgr)
309 myHighlightColor = theColor;
311 // Highlight on already Highlighted structure.
312 if (myCStructure->highlight)
314 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
315 if (anUpdateMode == Aspect_TOU_WAIT)
321 // To avoid call of method : Update()
322 // Not useful and can be costly.
323 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
325 myStructureManager->SetUpdateMode (anUpdateMode);
329 SetDisplayPriority (Structure_MAX_PRIORITY - 1);
331 GraphicHighlight (theMethod);
338 if (myCStructure->stick)
340 myStructureManager->Highlight (this, theMethod);
346 //=============================================================================
347 //function : SetVisible
349 //=============================================================================
350 void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
352 if (IsDeleted()) return;
354 const unsigned isVisible = theValue ? 1 : 0;
355 if (myCStructure->visible == isVisible)
360 myCStructure->visible = isVisible;
361 myCStructure->OnVisibilityChanged();
365 //=============================================================================
366 //function : UnHighlight
368 //=============================================================================
369 void Graphic3d_Structure::UnHighlight()
371 if (IsDeleted()) return;
373 if (myCStructure->highlight)
375 myCStructure->highlight = 0;
377 GraphicUnHighlight();
378 myStructureManager->UnHighlight (this);
380 ResetDisplayPriority();
385 //=============================================================================
386 //function : HighlightColor
388 //=============================================================================
389 const Quantity_Color& Graphic3d_Structure::HighlightColor() const
391 return myHighlightColor;
394 //=============================================================================
395 //function : IsDisplayed
397 //=============================================================================
398 Standard_Boolean Graphic3d_Structure::IsDisplayed() const
400 return myCStructure->stick ? Standard_True : Standard_False;
403 //=============================================================================
404 //function : IsDeleted
406 //=============================================================================
407 Standard_Boolean Graphic3d_Structure::IsDeleted() const
409 return myCStructure.IsNull();
412 //=============================================================================
413 //function : IsHighlighted
415 //=============================================================================
416 Standard_Boolean Graphic3d_Structure::IsHighlighted() const
418 return myCStructure->highlight ? Standard_True : Standard_False;
421 //=============================================================================
422 //function : IsVisible
424 //=============================================================================
425 Standard_Boolean Graphic3d_Structure::IsVisible() const
427 return myCStructure->visible ? Standard_True : Standard_False;
430 //=============================================================================
431 //function : IsRotated
433 //=============================================================================
434 Standard_Boolean Graphic3d_Structure::IsRotated() const
436 // A somewhat light test !
437 return myCStructure->Transformation[0][1] != 0.0
438 || myCStructure->Transformation[0][2] != 0.0
439 || myCStructure->Transformation[1][0] != 0.0
440 || myCStructure->Transformation[1][2] != 0.0
441 || myCStructure->Transformation[2][0] != 0.0
442 || myCStructure->Transformation[2][1] != 0.0;
445 //=============================================================================
446 //function : IsTransformed
448 //=============================================================================
449 Standard_Boolean Graphic3d_Structure::IsTransformed() const
451 Standard_Boolean aResult = Standard_False;
452 for (Standard_Integer i = 0; i <= 3 && !aResult; ++i)
454 for (Standard_Integer j = 0; j <= 3 && !aResult; ++j)
457 aResult = myCStructure->Transformation[i][j] != 1.0;
459 aResult = myCStructure->Transformation[i][j] != 0.0;
465 //=============================================================================
466 //function : ContainsFacet
468 //=============================================================================
469 Standard_Boolean Graphic3d_Structure::ContainsFacet() const
473 return Standard_False;
475 else if (myCStructure->ContainsFacet > 0)
477 // if one of groups contains at least one facet, the structure contains it too
478 return Standard_True;
481 // stop at the first descendant containing at least one facet
482 const Standard_Integer aNbDesc = myDescendants.Length();
483 for (Standard_Integer aStructIter = 1; aStructIter <= aNbDesc; ++aStructIter)
485 if (((const Graphic3d_Structure *)(myDescendants.Value (aStructIter)))->ContainsFacet())
487 return Standard_True;
490 return Standard_False;
493 //=============================================================================
496 //=============================================================================
497 Standard_Boolean Graphic3d_Structure::IsEmpty() const
501 return Standard_True;
504 // structure is empty:
505 // - if all these groups are empty
506 // - or if all groups are empty and all their descendants are empty
507 // - or if all its descendants are empty
508 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
510 if (!aGroupIter.Value()->IsEmpty())
512 return Standard_False;
516 // stop at the first non-empty descendant
517 const Standard_Integer aNbDesc = myDescendants.Length();
518 for (Standard_Integer aDescIter = 1; aDescIter <= aNbDesc; ++aDescIter)
520 if (!((const Graphic3d_Structure* )(myDescendants.Value (aDescIter)))->IsEmpty())
522 return Standard_False;
525 return Standard_True;
528 //=============================================================================
529 //function : PrimitivesAspect
531 //=============================================================================
532 void Graphic3d_Structure::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& theAspLine,
533 Handle(Graphic3d_AspectText3d)& theAspText,
534 Handle(Graphic3d_AspectMarker3d)& theAspMarker,
535 Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
537 theAspLine = Line3dAspect();
538 theAspText = Text3dAspect();
539 theAspMarker = Marker3dAspect();
540 theAspFill = FillArea3dAspect();
543 //=============================================================================
544 //function : GroupsWithFacet
546 //=============================================================================
547 void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta)
549 myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta;
550 if (myCStructure->ContainsFacet < 0)
552 myCStructure->ContainsFacet = 0;
556 //=============================================================================
559 //=============================================================================
560 void Graphic3d_Structure::Compute()
562 // Implemented by Presentation
565 //=============================================================================
568 //=============================================================================
569 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& )
571 // Implemented by Presentation
575 //=============================================================================
578 //=============================================================================
579 Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
580 const TColStd_Array2OfReal& )
582 // Implemented by Presentation
586 //=============================================================================
589 //=============================================================================
590 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
591 Handle(Graphic3d_Structure)& )
593 // Implemented by Presentation
596 //=============================================================================
599 //=============================================================================
600 void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ,
601 const TColStd_Array2OfReal& ,
602 Handle(Graphic3d_Structure)& )
604 // Implemented by Presentation
607 //=============================================================================
608 //function : ReCompute
610 //=============================================================================
611 void Graphic3d_Structure::ReCompute()
613 myStructureManager->ReCompute (this);
616 //=============================================================================
617 //function : ReCompute
619 //=============================================================================
620 void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector)
622 myStructureManager->ReCompute (this, theProjector);
625 //=============================================================================
626 //function : SetInfiniteState
628 //=============================================================================
629 void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet)
631 myCStructure->IsInfinite = theToSet ? 1 : 0;
634 //=============================================================================
635 //function : IsInfinite
637 //=============================================================================
638 Standard_Boolean Graphic3d_Structure::IsInfinite() const
641 || myCStructure->IsInfinite;
644 //=============================================================================
645 //function : GraphicClear
647 //=============================================================================
648 void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction)
650 if (myCStructure.IsNull())
655 // clean and empty each group
656 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
658 aGroupIter.ChangeValue()->Clear();
660 if (!theWithDestruction)
665 while (!myCStructure->Groups().IsEmpty())
667 Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First();
670 myCStructure->Clear();
673 //=============================================================================
674 //function : GraphicConnect
676 //=============================================================================
677 void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
679 myCStructure->Connect (*theDaughter->myCStructure);
682 //=============================================================================
683 //function : GraphicDisconnect
685 //=============================================================================
686 void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
688 myCStructure->Disconnect (*theDaughter->myCStructure);
691 //=============================================================================
692 //function : Line3dAspect
694 //=============================================================================
695 Handle(Graphic3d_AspectLine3d) Graphic3d_Structure::Line3dAspect() const
697 const Standard_Real anRGB[3] =
699 Standard_Real (myCStructure->ContextLine.Color.r),
700 Standard_Real (myCStructure->ContextLine.Color.g),
701 Standard_Real (myCStructure->ContextLine.Color.b)
703 Quantity_Color aColor;
704 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
705 Aspect_TypeOfLine aLType = Aspect_TypeOfLine (myCStructure->ContextLine.LineType);
706 Standard_Real aWidth = Standard_Real (myCStructure->ContextLine.Width);
708 Handle(Graphic3d_AspectLine3d) anAspLine = new Graphic3d_AspectLine3d (aColor, aLType, aWidth);
709 anAspLine->SetShaderProgram (myCStructure->ContextLine.ShaderProgram);
713 //=============================================================================
714 //function : Text3dAspect
716 //=============================================================================
717 Handle(Graphic3d_AspectText3d) Graphic3d_Structure::Text3dAspect() const
719 const Standard_Real anRGB[3] =
721 Standard_Real (myCStructure->ContextText.Color.r),
722 Standard_Real (myCStructure->ContextText.Color.g),
723 Standard_Real (myCStructure->ContextText.Color.b)
725 Quantity_Color aColor;
726 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
727 Standard_CString aFont = Standard_CString (myCStructure->ContextText.Font);
728 Standard_Real anExpansion = Standard_Real (myCStructure->ContextText.Expan);
729 Standard_Real aSpace = Standard_Real (myCStructure->ContextText.Space);
730 Aspect_TypeOfStyleText aStyle = Aspect_TypeOfStyleText (myCStructure->ContextText.Style);
731 Aspect_TypeOfDisplayText aDispType = Aspect_TypeOfDisplayText (myCStructure->ContextText.DisplayType);
733 Handle(Graphic3d_AspectText3d) anAspText = new Graphic3d_AspectText3d (aColor, aFont, anExpansion, aSpace, aStyle, aDispType);
734 anAspText->SetShaderProgram (myCStructure->ContextText.ShaderProgram);
738 //=============================================================================
739 //function : Marker3dAspect
741 //=============================================================================
742 Handle(Graphic3d_AspectMarker3d) Graphic3d_Structure::Marker3dAspect() const
744 const Standard_Real anRGB[3] =
746 Standard_Real (myCStructure->ContextMarker.Color.r),
747 Standard_Real (myCStructure->ContextMarker.Color.g),
748 Standard_Real (myCStructure->ContextMarker.Color.b)
750 Quantity_Color aColor;
751 aColor.SetValues (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
752 Aspect_TypeOfMarker aMType = myCStructure->ContextMarker.MarkerType;
753 Standard_Real aScale = Standard_Real (myCStructure->ContextMarker.Scale);
755 Handle(Graphic3d_AspectMarker3d) anAspMarker = new Graphic3d_AspectMarker3d (aMType, aColor, aScale);
756 anAspMarker->SetShaderProgram (myCStructure->ContextMarker.ShaderProgram);
760 //=============================================================================
761 //function : FillArea3dAspect
763 //=============================================================================
764 Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect() const
767 Graphic3d_MaterialAspect aBack;
768 aBack.SetShininess (Standard_Real (myCStructure->ContextFillArea.Back.Shininess));
769 aBack.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Back.Ambient));
770 aBack.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Back.Diffuse));
771 aBack.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Back.Specular));
772 aBack.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Back.Transparency));
773 aBack.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Back.Emission));
774 if (myCStructure->ContextFillArea.Back.IsAmbient == 1)
775 aBack.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
777 aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
778 if (myCStructure->ContextFillArea.Back.IsDiffuse == 1)
779 aBack.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
781 aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
782 if (myCStructure->ContextFillArea.Back.IsSpecular == 1)
783 aBack.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
785 aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
786 if (myCStructure->ContextFillArea.Back.IsEmission == 1)
787 aBack.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
789 aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
791 Quantity_Color aColor (Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.r),
792 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.g),
793 Standard_Real (myCStructure->ContextFillArea.Back.ColorSpec.b), Quantity_TOC_RGB);
794 aBack.SetSpecularColor (aColor);
796 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.r),
797 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.g),
798 Standard_Real (myCStructure->ContextFillArea.Back.ColorAmb.b), Quantity_TOC_RGB);
799 aBack.SetAmbientColor (aColor);
801 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.r),
802 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.g),
803 Standard_Real (myCStructure->ContextFillArea.Back.ColorDif.b), Quantity_TOC_RGB);
804 aBack.SetDiffuseColor (aColor);
806 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.r),
807 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.g),
808 Standard_Real (myCStructure->ContextFillArea.Back.ColorEms.b), Quantity_TOC_RGB);
809 aBack.SetEmissiveColor (aColor);
811 aBack.SetEnvReflexion (myCStructure->ContextFillArea.Back.EnvReflexion);
812 aBack.SetMaterialType (myCStructure->ContextFillArea.Back.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
815 Graphic3d_MaterialAspect aFront;
816 aFront.SetShininess (Standard_Real (myCStructure->ContextFillArea.Front.Shininess));
817 aFront.SetAmbient (Standard_Real (myCStructure->ContextFillArea.Front.Ambient));
818 aFront.SetDiffuse (Standard_Real (myCStructure->ContextFillArea.Front.Diffuse));
819 aFront.SetSpecular (Standard_Real (myCStructure->ContextFillArea.Front.Specular));
820 aFront.SetTransparency (Standard_Real (myCStructure->ContextFillArea.Front.Transparency));
821 aFront.SetEmissive (Standard_Real (myCStructure->ContextFillArea.Front.Emission));
822 if (myCStructure->ContextFillArea.Front.IsAmbient == 1)
823 aFront.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
825 aFront.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
826 if (myCStructure->ContextFillArea.Front.IsDiffuse == 1)
827 aFront.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
829 aFront.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
830 if (myCStructure->ContextFillArea.Front.IsSpecular == 1)
831 aFront.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
833 aFront.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
834 if (myCStructure->ContextFillArea.Front.Emission == 1)
835 aFront.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
837 aFront.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
839 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.r),
840 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.g),
841 Standard_Real (myCStructure->ContextFillArea.Front.ColorSpec.b), Quantity_TOC_RGB);
842 aFront.SetSpecularColor (aColor);
844 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.r),
845 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.g),
846 Standard_Real (myCStructure->ContextFillArea.Front.ColorAmb.b), Quantity_TOC_RGB);
847 aFront.SetAmbientColor (aColor);
849 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.r),
850 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.g),
851 Standard_Real (myCStructure->ContextFillArea.Front.ColorDif.b), Quantity_TOC_RGB);
852 aFront.SetDiffuseColor (aColor);
854 aColor.SetValues (Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.r),
855 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.g),
856 Standard_Real (myCStructure->ContextFillArea.Front.ColorEms.b), Quantity_TOC_RGB);
857 aFront.SetEmissiveColor (aColor);
859 aFront.SetEnvReflexion (myCStructure->ContextFillArea.Front.EnvReflexion);
860 aFront.SetMaterialType (myCStructure->ContextFillArea.Front.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
862 Quantity_Color anIntColor (Standard_Real (myCStructure->ContextFillArea.IntColor.r),
863 Standard_Real (myCStructure->ContextFillArea.IntColor.g),
864 Standard_Real (myCStructure->ContextFillArea.IntColor.b), Quantity_TOC_RGB);
865 Quantity_Color anEdgeColor (Standard_Real (myCStructure->ContextFillArea.EdgeColor.r),
866 Standard_Real (myCStructure->ContextFillArea.EdgeColor.g),
867 Standard_Real (myCStructure->ContextFillArea.EdgeColor.b), Quantity_TOC_RGB);
868 Handle(Graphic3d_AspectFillArea3d) anAspFill = new Graphic3d_AspectFillArea3d (Aspect_InteriorStyle (myCStructure->ContextFillArea.Style),
869 anIntColor, anEdgeColor,
870 Aspect_TypeOfLine (myCStructure->ContextFillArea.LineType),
871 Standard_Real (myCStructure->ContextFillArea.Width),
875 if (myCStructure->ContextFillArea.Edge == 1)
876 anAspFill->SetEdgeOn();
878 anAspFill->SetEdgeOff();
880 anAspFill->SetHatchStyle (Aspect_HatchStyle (myCStructure->ContextFillArea.Hatch));
882 // Front and Back face
883 if (myCStructure->ContextFillArea.Distinguish == 1)
884 anAspFill->SetDistinguishOn();
886 anAspFill->SetDistinguishOff();
887 if (myCStructure->ContextFillArea.BackFace == 1)
888 anAspFill->SuppressBackFace();
890 anAspFill->AllowBackFace();
892 anAspFill->SetTextureMap (myCStructure->ContextFillArea.Texture.TextureMap);
893 if (myCStructure->ContextFillArea.Texture.doTextureMap == 1)
895 anAspFill->SetTextureMapOn();
899 anAspFill->SetTextureMapOff();
901 anAspFill->SetShaderProgram (myCStructure->ContextFillArea.ShaderProgram);
902 anAspFill->SetPolygonOffsets (myCStructure->ContextFillArea.PolygonOffsetMode,
903 myCStructure->ContextFillArea.PolygonOffsetFactor,
904 myCStructure->ContextFillArea.PolygonOffsetUnits);
908 //=============================================================================
911 //=============================================================================
912 const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const
914 return myCStructure->Groups();
917 //=============================================================================
918 //function : NumberOfGroups
920 //=============================================================================
921 Standard_Integer Graphic3d_Structure::NumberOfGroups() const
923 return myCStructure->Groups().Length();
926 //=============================================================================
927 //function : SetPrimitivesAspect
929 //=============================================================================
930 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
932 if (IsDeleted()) return;
934 Standard_Real aWidth;
935 Quantity_Color aColor;
936 Aspect_TypeOfLine aLType;
937 theAspLine->Values (aColor, aLType, aWidth);
939 myCStructure->ContextLine.Color.r = float (aColor.Red());
940 myCStructure->ContextLine.Color.g = float (aColor.Green());
941 myCStructure->ContextLine.Color.b = float (aColor.Blue());
942 myCStructure->ContextLine.LineType = int (aLType);
943 myCStructure->ContextLine.Width = float (aWidth);
944 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
945 myCStructure->ContextLine.IsDef = 1;
947 myCStructure->UpdateAspects();
949 // Attributes are "IsSet" during the first update of context (line, marker...)
950 myCStructure->ContextLine.IsSet = 1;
951 myCStructure->ContextFillArea.IsSet = 1;
952 myCStructure->ContextMarker.IsSet = 1;
953 myCStructure->ContextText.IsSet = 1;
958 //=============================================================================
959 //function : SetPrimitivesAspect
961 //=============================================================================
962 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
964 if (IsDeleted()) return;
966 Standard_Real anRGB[3];
967 Standard_Real aWidth;
968 Quantity_Color anIntColor;
969 Quantity_Color aBackIntColor;
970 Quantity_Color anEdgeColor;
971 Aspect_TypeOfLine aLType;
972 Aspect_InteriorStyle aStyle;
973 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
975 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
976 myCStructure->ContextFillArea.Style = aStyle;
977 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
978 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
979 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
981 if (theAspFill->Distinguish())
983 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
985 myCStructure->ContextFillArea.BackIntColor.r = float(anRGB[0]);
986 myCStructure->ContextFillArea.BackIntColor.g = float(anRGB[1]);
987 myCStructure->ContextFillArea.BackIntColor.b = float(anRGB[2]);
990 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1 : 0;
991 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
992 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
993 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
994 myCStructure->ContextFillArea.LineType = aLType;
995 myCStructure->ContextFillArea.Width = float (aWidth);
996 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
998 // Front and Back face
999 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
1000 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
1003 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
1004 // Light specificity
1005 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
1006 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
1007 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
1008 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
1009 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
1010 myCStructure->ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
1011 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
1014 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1015 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1016 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1017 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1021 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0 );
1024 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
1025 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
1026 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
1029 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
1030 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
1031 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
1034 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
1035 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
1036 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
1039 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
1040 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
1041 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
1043 myCStructure->ContextFillArea.Back.EnvReflexion =
1044 float ((theAspFill->BackMaterial ()).EnvReflexion());
1047 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
1048 // Light specificity
1049 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
1050 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
1051 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
1052 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
1053 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
1054 myCStructure->ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
1055 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
1058 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
1059 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
1060 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
1061 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
1065 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
1068 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
1069 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
1070 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
1073 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
1074 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
1075 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
1078 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
1079 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
1080 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
1083 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
1084 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
1085 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
1087 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
1089 myCStructure->ContextFillArea.IsDef = 1; // Definition material ok
1091 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
1092 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
1093 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
1095 Standard_Integer aPolyMode;
1096 Standard_ShortReal aPolyFactor, aPolyUnits;
1097 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
1098 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
1099 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
1100 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
1102 myCStructure->UpdateAspects();
1104 // Attributes are "IsSet" during the first update of context (line, marker...)
1105 myCStructure->ContextLine.IsSet = 1;
1106 myCStructure->ContextFillArea.IsSet = 1;
1107 myCStructure->ContextMarker.IsSet = 1;
1108 myCStructure->ContextText.IsSet = 1;
1113 //=============================================================================
1114 //function : SetPrimitivesAspect
1116 //=============================================================================
1117 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
1119 if (IsDeleted()) return;
1121 Standard_CString aFont;
1122 Standard_Real aSpace, anExpansion, aTextAngle;
1123 Quantity_Color aColor, aColorSub;
1124 Aspect_TypeOfStyleText aStyle;
1125 Aspect_TypeOfDisplayText aDispType;
1126 Standard_Boolean isTextZoomable;
1127 Font_FontAspect aTextFontAspect;
1128 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDispType, aColorSub, isTextZoomable, aTextAngle, aTextFontAspect);
1130 myCStructure->ContextText.Color.r = float (aColor.Red());
1131 myCStructure->ContextText.Color.g = float (aColor.Green());
1132 myCStructure->ContextText.Color.b = float (aColor.Blue());
1133 myCStructure->ContextText.Font = aFont;
1134 myCStructure->ContextText.Expan = float (anExpansion);
1135 myCStructure->ContextText.Space = float (aSpace);
1136 myCStructure->ContextText.Style = aStyle;
1137 myCStructure->ContextText.DisplayType = aDispType;
1138 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
1139 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
1140 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
1141 myCStructure->ContextText.TextZoomable = isTextZoomable;
1142 myCStructure->ContextText.TextAngle = float (aTextAngle);
1143 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
1144 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
1146 myCStructure->ContextText.IsDef = 1;
1148 myCStructure->UpdateAspects();
1150 // Attributes are "IsSet" during the first update of a context (line, marker...)
1151 myCStructure->ContextLine.IsSet = 1;
1152 myCStructure->ContextFillArea.IsSet = 1;
1153 myCStructure->ContextMarker.IsSet = 1;
1154 myCStructure->ContextText.IsSet = 1;
1159 //=============================================================================
1160 //function : SetPrimitivesAspect
1162 //=============================================================================
1163 void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
1165 if (IsDeleted()) return;
1167 Standard_Real aScale;
1168 Quantity_Color aColor;
1169 Aspect_TypeOfMarker aMType;
1170 theAspMarker->Values (aColor, aMType, aScale);
1172 myCStructure->ContextMarker.Color.r = float (aColor.Red());
1173 myCStructure->ContextMarker.Color.g = float (aColor.Green());
1174 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
1175 myCStructure->ContextMarker.MarkerType = aMType;
1176 myCStructure->ContextMarker.Scale = float (aScale);
1177 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
1178 myCStructure->ContextMarker.IsDef = 1;
1180 myCStructure->UpdateAspects();
1182 // Attributes are "IsSet" during the first update of a context (line, marker...)
1183 myCStructure->ContextLine.IsSet = 1;
1184 myCStructure->ContextFillArea.IsSet = 1;
1185 myCStructure->ContextMarker.IsSet = 1;
1186 myCStructure->ContextText.IsSet = 1;
1191 //=============================================================================
1192 //function : SetVisual
1194 //=============================================================================
1195 void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual)
1198 || myVisual == theVisual)
1203 if (!myCStructure->stick)
1205 myVisual = theVisual;
1206 SetComputeVisual (theVisual);
1210 Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode();
1211 if (anUpdateMode == Aspect_TOU_WAIT)
1214 myVisual = theVisual;
1215 SetComputeVisual (theVisual);
1219 // To avoid calling method : Update ()
1220 // Not useful and can be costly.
1221 myStructureManager->SetUpdateMode (Aspect_TOU_WAIT);
1223 myVisual = theVisual;
1224 SetComputeVisual (theVisual);
1225 myStructureManager->SetUpdateMode (anUpdateMode);
1231 //=============================================================================
1232 //function : SetZoomLimit
1234 //=============================================================================
1235 void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf,
1236 const Standard_Real theLimitSup)
1240 Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0,
1241 "Bad value for ZoomLimit inf");
1242 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0,
1243 "Bad value for ZoomLimit sup");
1244 Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf,
1245 "ZoomLimit sup < ZoomLimit inf");
1248 //=============================================================================
1251 //=============================================================================
1252 Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const
1257 //=============================================================================
1258 //function : AcceptConnection
1260 //=============================================================================
1261 Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1,
1262 const Handle(Graphic3d_Structure)& theStructure2,
1263 const Graphic3d_TypeOfConnection theType)
1266 Graphic3d_MapOfStructure aSet;
1267 Graphic3d_Structure::Network (theStructure2, theType, aSet);
1268 return !aSet.Contains (theStructure1);
1271 //=============================================================================
1272 //function : Ancestors
1274 //=============================================================================
1275 void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const
1277 const Standard_Integer aNbAnces = myAncestors.Length ();
1278 for (Standard_Integer anIter = 1; anIter <= aNbAnces; ++anIter)
1280 theSet.Add ((Graphic3d_Structure* )(myAncestors.Value (anIter)));
1284 //=============================================================================
1285 //function : SetOwner
1287 //=============================================================================
1288 void Graphic3d_Structure::SetOwner (const Standard_Address theOwner)
1293 //=============================================================================
1296 //=============================================================================
1297 Standard_Address Graphic3d_Structure::Owner() const
1302 //=============================================================================
1303 //function : Descendants
1305 //=============================================================================
1306 void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const
1308 const Standard_Integer aNbDesc = myDescendants.Length ();
1309 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1311 theSet.Add ((Graphic3d_Structure* )(myDescendants.Value (anIter)));
1315 //=============================================================================
1316 //function : Connect
1318 //=============================================================================
1319 void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure,
1320 const Graphic3d_TypeOfConnection theType,
1321 const Standard_Boolean theWithCheck)
1323 if (IsDeleted()) return;
1327 && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType))
1334 case Graphic3d_TOC_DESCENDANT:
1336 const Standard_Integer aNbDesc = myDescendants.Length();
1337 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1339 if (myDescendants.Value (anIter) == theStructure.operator->())
1345 myDescendants.Append (theStructure.operator->());
1346 CalculateBoundBox();
1347 theStructure->Connect (this, Graphic3d_TOC_ANCESTOR);
1349 GraphicConnect (theStructure);
1350 myStructureManager->Connect (this, theStructure);
1355 case Graphic3d_TOC_ANCESTOR:
1357 const Standard_Integer aNbAnces = myAncestors.Length();
1358 for (Standard_Integer anIter = 1; anIter <= aNbAnces; ++anIter)
1360 if (myAncestors.Value (anIter) == theStructure.operator->())
1366 myAncestors.Append (theStructure.operator->());
1367 CalculateBoundBox();
1368 theStructure->Connect (this, Graphic3d_TOC_DESCENDANT);
1370 // myGraphicDriver->Connect is called in case if connection between parent and child
1376 //=============================================================================
1377 //function : Disconnect
1379 //=============================================================================
1380 void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure)
1382 if (IsDeleted()) return;
1384 const Standard_Integer aNbDesc = myDescendants.Length();
1385 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1387 if (myDescendants.Value (anIter) == theStructure.operator->())
1389 myDescendants.Remove (anIter);
1390 theStructure->Disconnect (this);
1392 GraphicDisconnect (theStructure);
1393 myStructureManager->Disconnect (this, theStructure);
1395 CalculateBoundBox();
1402 const Standard_Integer aNbAnces = myAncestors.Length();
1403 for (Standard_Integer anIter = 1; anIter <= aNbAnces; ++anIter)
1405 if (myAncestors.Value (anIter) == theStructure.operator->())
1407 myAncestors.Remove (anIter);
1408 theStructure->Disconnect (this);
1409 CalculateBoundBox();
1410 // no call of myGraphicDriver->Disconnect in case of an ancestor
1416 //=============================================================================
1417 //function : DisconnectAll
1419 //=============================================================================
1420 void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType)
1422 if (IsDeleted()) return;
1426 case Graphic3d_TOC_DESCENDANT:
1428 const Standard_Integer aLength = myDescendants.Length();
1429 for (Standard_Integer anIter = 1; anIter <= aLength; ++anIter)
1431 // Value (1) instead of Value (i) as myDescendants
1433 // Graphic3d_Structure::Disconnect (AStructure)
1434 // that takes AStructure from myDescendants
1435 ((Graphic3d_Structure* )(myDescendants.Value (1)))->Disconnect (this);
1439 case Graphic3d_TOC_ANCESTOR:
1441 const Standard_Integer aLength = myAncestors.Length();
1442 for (Standard_Integer anIter = 1; anIter <= aLength; ++anIter)
1444 // Value (1) instead of Value (i) as myAncestors
1446 // Graphic3d_Structure::Disconnect (AStructure)
1447 // that takes AStructure from myAncestors
1448 ((Graphic3d_Structure* )(myAncestors.Value (1)))->Disconnect (this);
1455 //=============================================================================
1456 //function : Composition
1458 //=============================================================================
1459 Graphic3d_TypeOfComposition Graphic3d_Structure::Composition() const
1461 return myCStructure->Composition;
1464 //=============================================================================
1465 //function : SetTransform
1467 //=============================================================================
1468 void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& theMatrix,
1469 const Graphic3d_TypeOfComposition theType)
1471 if (IsDeleted()) return;
1473 Standard_Real valuetrsf;
1474 Standard_Real valueoldtrsf;
1475 Standard_Real valuenewtrsf;
1476 TColStd_Array2OfReal aNewTrsf (0, 3, 0, 3);
1477 TColStd_Array2OfReal aMatrix44 (0, 3, 0, 3);
1479 // Assign the new transformation in an array [0..3][0..3]
1480 // Avoid problemes if the user has defined matrice [1..4][1..4]
1481 // or [3..6][-1..2] !!
1482 Standard_Integer lr = theMatrix.LowerRow();
1483 Standard_Integer ur = theMatrix.UpperRow();
1484 Standard_Integer lc = theMatrix.LowerCol();
1485 Standard_Integer uc = theMatrix.UpperCol();
1487 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1489 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1494 case Graphic3d_TOC_REPLACE:
1496 myCStructure->Composition = Graphic3d_TOC_REPLACE;
1497 // Update of CStructure
1498 for (Standard_Integer i = 0; i <= 3; ++i)
1500 for (Standard_Integer j = 0; j <= 3; ++j)
1502 myCStructure->Transformation[i][j] = float (theMatrix (lr + i, lc + j));
1503 aNewTrsf (i, j) = theMatrix (lr + i, lc + j);
1508 case Graphic3d_TOC_POSTCONCATENATE:
1510 myCStructure->Composition = Graphic3d_TOC_POSTCONCATENATE;
1511 // To simplify management of indices
1512 for (Standard_Integer i = 0; i <= 3; ++i)
1514 for (Standard_Integer j = 0; j <= 3; ++j)
1516 aMatrix44 (i, j) = theMatrix (lr + i, lc + j);
1520 // Calculation of the product of matrices
1521 for (Standard_Integer i = 0; i <= 3; ++i)
1523 for (Standard_Integer j = 0; j <= 3; ++j)
1525 aNewTrsf (i, j) = 0.0;
1526 for (Standard_Integer k = 0; k <= 3; ++k)
1528 valueoldtrsf = myCStructure->Transformation[i][k];
1529 valuetrsf = aMatrix44 (k, j);
1530 valuenewtrsf = aNewTrsf (i, j) + valueoldtrsf * valuetrsf;
1531 aNewTrsf (i, j) = valuenewtrsf;
1536 // Update of CStructure
1537 for (Standard_Integer i = 0; i <= 3; ++i)
1539 for (Standard_Integer j = 0; j <= 3; ++j)
1541 myCStructure->Transformation[i][j] = float (aNewTrsf (i, j));
1548 // If transformation, no validation of hidden already calculated parts
1554 myCStructure->UpdateTransformation();
1555 myStructureManager->SetTransform (this, aNewTrsf);
1560 //=============================================================================
1561 //function : Transform
1563 //=============================================================================
1564 void Graphic3d_Structure::Transform (TColStd_Array2OfReal& theMatrix) const
1567 Standard_Integer lr = theMatrix.LowerRow ();
1568 Standard_Integer ur = theMatrix.UpperRow ();
1569 Standard_Integer lc = theMatrix.LowerCol ();
1570 Standard_Integer uc = theMatrix.UpperCol ();
1572 if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
1573 Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
1575 for (Standard_Integer i = 0; i <= 3; ++i)
1577 for (Standard_Integer j = 0; j <= 3; ++j)
1579 theMatrix (lr + i, lc + j) = myCStructure->Transformation[i][j];
1585 //=============================================================================
1586 //function : MinMaxValues
1588 //=============================================================================
1589 Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
1591 Graphic3d_BndBox4d aBox;
1593 addTransformed (aBox, theToIgnoreInfiniteFlag);
1596 aResult.Add (gp_Pnt (aBox.CornerMin().x(),
1597 aBox.CornerMin().y(),
1598 aBox.CornerMin().z()));
1599 aResult.Add (gp_Pnt (aBox.CornerMax().x(),
1600 aBox.CornerMax().y(),
1601 aBox.CornerMax().z()));
1603 Standard_Real aLimMin = ShortRealFirst() + 1.0;
1604 Standard_Real aLimMax = ShortRealLast() - 1.0;
1605 gp_Pnt aMin = aResult.CornerMin();
1606 gp_Pnt aMax = aResult.CornerMax();
1607 if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin &&
1608 aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax)
1610 //For structure which infinite in all three dimensions the Whole bounding box will be returned
1617 //=============================================================================
1618 //function : Identification
1620 //=============================================================================
1621 Standard_Integer Graphic3d_Structure::Identification() const
1623 return myCStructure->Id;
1626 //=============================================================================
1627 //function : SetTransformPersistence
1629 //=============================================================================
1630 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag)
1632 SetTransformPersistence (theFlag, gp_Pnt (0.0, 0.0, 0.0));
1635 //=============================================================================
1636 //function : SetTransformPersistence
1638 //=============================================================================
1639 void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
1640 const gp_Pnt& thePoint)
1642 if (IsDeleted()) return;
1644 myCStructure->TransformPersistence.Flag = theFlag;
1645 myCStructure->TransformPersistence.Point.x = float (thePoint.X());
1646 myCStructure->TransformPersistence.Point.y = float (thePoint.Y());
1647 myCStructure->TransformPersistence.Point.z = float (thePoint.Z());
1648 myCStructure->UpdateAspects();
1649 CalculateBoundBox();
1651 myCStructure->TransformPersistence.IsSet = 1;
1654 //=============================================================================
1655 //function : TransformPersistenceMode
1657 //=============================================================================
1658 Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const
1660 return myCStructure->TransformPersistence.Flag;
1663 //=============================================================================
1664 //function : TransformPersistencePoint
1666 //=============================================================================
1667 gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const
1669 gp_Pnt aPnt (0.0, 0.0, 0.0);
1670 aPnt.SetX (myCStructure->TransformPersistence.Point.x);
1671 aPnt.SetY (myCStructure->TransformPersistence.Point.y);
1672 aPnt.SetZ (myCStructure->TransformPersistence.Point.z);
1676 //=============================================================================
1679 //=============================================================================
1680 void Graphic3d_Structure::Remove (const Standard_Address thePtr,
1681 const Graphic3d_TypeOfConnection theType)
1685 case Graphic3d_TOC_DESCENDANT:
1687 const Standard_Integer aNbDesc = myDescendants.Length();
1688 for (Standard_Integer anIter = 1; anIter <= aNbDesc; ++anIter)
1690 if (myDescendants.Value (anIter) == thePtr)
1692 myDescendants.Remove (anIter);
1698 case Graphic3d_TOC_ANCESTOR:
1700 const Standard_Integer aNbAncestors = myAncestors.Length();
1701 for (Standard_Integer anIter = 1; anIter <= aNbAncestors; ++anIter)
1703 if (myAncestors.Value (anIter) == thePtr)
1705 myAncestors.Remove (anIter);
1714 //=============================================================================
1715 //function : NewGroup
1717 //=============================================================================
1718 Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup()
1720 return myCStructure->NewGroup (this);
1723 //=============================================================================
1726 //=============================================================================
1727 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup)
1729 if (theGroup.IsNull()
1730 || theGroup->myStructure != this)
1735 myCStructure->RemoveGroup (theGroup);
1736 theGroup->myStructure = NULL;
1739 //=============================================================================
1740 //function : StructureManager
1742 //=============================================================================
1743 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
1745 return myStructureManager;
1748 //=============================================================================
1749 //function : minMaxCoord
1751 //=============================================================================
1752 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
1754 Graphic3d_BndBox4f aBnd;
1755 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
1757 aBnd.Combine (aGroupIter.Value()->BoundingBox());
1762 //=============================================================================
1763 //function : addTransformed
1765 //=============================================================================
1766 void Graphic3d_Structure::getBox (Graphic3d_BndBox4d& theBox,
1767 const Standard_Boolean theToIgnoreInfiniteFlag) const
1769 Graphic3d_BndBox4f aBoxF = minMaxCoord();
1770 if (aBoxF.IsValid())
1772 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMin().x(),
1773 (Standard_Real )aBoxF.CornerMin().y(),
1774 (Standard_Real )aBoxF.CornerMin().z(),
1775 (Standard_Real )aBoxF.CornerMin().w()),
1776 Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMax().x(),
1777 (Standard_Real )aBoxF.CornerMax().y(),
1778 (Standard_Real )aBoxF.CornerMax().z(),
1779 (Standard_Real )aBoxF.CornerMax().w()));
1781 && !theToIgnoreInfiniteFlag)
1783 const Graphic3d_Vec4d aDiagVec = theBox.CornerMax() - theBox.CornerMin();
1784 if (aDiagVec.xyz().SquareModulus() >= 500000.0 * 500000.0)
1786 // bounding borders of infinite line has been calculated as own point in center of this line
1787 theBox = Graphic3d_BndBox4d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5);
1791 theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d (RealFirst(), RealFirst(), RealFirst(), 1.0),
1792 Graphic3d_Vec4d (RealLast(), RealLast(), RealLast(), 1.0));
1799 //=============================================================================
1800 //function : addTransformed
1802 //=============================================================================
1803 void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d& theBox,
1804 const Standard_Boolean theToIgnoreInfiniteFlag) const
1806 Graphic3d_BndBox4d aCombinedBox, aBox;
1807 getBox (aCombinedBox, theToIgnoreInfiniteFlag);
1809 for (Standard_Integer aStructIt = 1; aStructIt <= myDescendants.Length(); ++aStructIt)
1811 const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )myDescendants.Value (aStructIt);
1812 aStruct->getBox (aBox, theToIgnoreInfiniteFlag);
1813 aCombinedBox.Combine (aBox);
1816 aBox = aCombinedBox;
1819 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1821 TransformBoundaries (aTrsf, aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
1822 aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
1824 // if box is still valid after transformation
1827 theBox.Combine (aBox);
1829 else // it was infinite, return untransformed
1831 theBox.Combine (aCombinedBox);
1836 //=============================================================================
1837 //function : Transforms
1839 //=============================================================================
1840 void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1841 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
1842 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ)
1844 const Standard_Real aRL = RealLast();
1845 const Standard_Real aRF = RealFirst();
1846 if ((theX == aRF) || (theY == aRF) || (theZ == aRF)
1847 || (theX == aRL) || (theY == aRL) || (theZ == aRL))
1855 Standard_Real A, B, C, D;
1860 theNewX = A * theX + B * theY + C * theZ + D;
1865 theNewY = A * theX + B * theY + C * theZ + D;
1870 theNewZ = A * theX + B * theY + C * theZ + D;
1874 //=============================================================================
1875 //function : Transforms
1877 //=============================================================================
1878 Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1879 const Graphic3d_Vector& theCoord)
1881 Standard_Real anXYZ[3];
1882 Graphic3d_Structure::Transforms (theTrsf,
1883 theCoord.X(), theCoord.Y(), theCoord.Z(),
1884 anXYZ[0], anXYZ[1], anXYZ[2]);
1885 return Graphic3d_Vector (anXYZ[0], anXYZ[1], anXYZ[2]);
1888 //=============================================================================
1889 //function : Transforms
1891 //=============================================================================
1892 Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf,
1893 const Graphic3d_Vertex& theCoord)
1895 Standard_Real anXYZ[3];
1896 Graphic3d_Structure::Transforms (theTrsf,
1897 theCoord.X(), theCoord.Y(), theCoord.Z(),
1898 anXYZ[0], anXYZ[1], anXYZ[2]);
1899 return Graphic3d_Vertex (anXYZ[0], anXYZ[1], anXYZ[2]);
1902 //=============================================================================
1903 //function : Transforms
1905 //=============================================================================
1906 void Graphic3d_Structure::TransformBoundaries (const TColStd_Array2OfReal& theTrsf,
1907 Standard_Real& theXMin,
1908 Standard_Real& theYMin,
1909 Standard_Real& theZMin,
1910 Standard_Real& theXMax,
1911 Standard_Real& theYMax,
1912 Standard_Real& theZMax)
1914 Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW;
1916 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin);
1917 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax);
1919 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW);
1920 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1921 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1922 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1924 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW);
1925 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1926 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1927 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1929 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW);
1930 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1931 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1932 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1934 Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW);
1935 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1936 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1937 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1939 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW);
1940 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1941 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1942 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1944 Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW);
1945 aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax);
1946 aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax);
1947 aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax);
1957 //=============================================================================
1958 //function : Network
1960 //=============================================================================
1961 void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure,
1962 const Graphic3d_TypeOfConnection theType,
1963 Graphic3d_MapOfStructure& theSet)
1965 Graphic3d_MapOfStructure aSetD, aSetA;
1966 theStructure->Descendants (aSetD);
1967 theStructure->Ancestors (aSetA);
1968 theSet.Add (theStructure);
1971 case Graphic3d_TOC_DESCENDANT:
1972 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next())
1974 Graphic3d_Structure::Network (anIter.Key(), theType, theSet);
1977 case Graphic3d_TOC_ANCESTOR:
1978 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next())
1980 Graphic3d_Structure::Network (anIter.Key (), theType, theSet);
1986 //=============================================================================
1987 //function : PrintNetwork
1989 //=============================================================================
1990 void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure,
1991 const Graphic3d_TypeOfConnection theType)
1993 Graphic3d_MapOfStructure aSet;
1994 Graphic3d_Structure::Network (theStructure, theType, aSet);
1995 for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next())
1997 std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n";
1999 std::cout << std::flush;
2002 //=============================================================================
2005 //=============================================================================
2006 void Graphic3d_Structure::Update() const
2013 if (myStructureManager->UpdateMode() == Aspect_TOU_ASAP)
2015 myStructureManager->Update();
2019 //=============================================================================
2020 //function : UpdateStructure
2022 //=============================================================================
2023 void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)& theAspLine,
2024 const Handle(Graphic3d_AspectText3d)& theAspText,
2025 const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
2026 const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
2028 Standard_CString aFont;
2029 Standard_Real aSpace, anExpansion, aWidth, aScale;
2030 Quantity_Color aColor, anIntColor, aBackIntColor, anEdgeColor, aColorSub;
2031 Aspect_TypeOfLine aLType;
2032 Aspect_TypeOfMarker aMType;
2033 Aspect_InteriorStyle aStyle;
2034 Aspect_TypeOfStyleText aStyleT;
2035 Aspect_TypeOfDisplayText aDisplayType;
2036 Standard_Boolean aTextZoomable;
2037 Standard_Real aTextAngle;
2038 Font_FontAspect aTextFontAspect;
2040 theAspLine->Values (aColor, aLType, aWidth);
2041 myCStructure->ContextLine.Color.r = float (aColor.Red());
2042 myCStructure->ContextLine.Color.g = float (aColor.Green());
2043 myCStructure->ContextLine.Color.b = float (aColor.Blue());
2044 myCStructure->ContextLine.LineType = aLType;
2045 myCStructure->ContextLine.Width = float (aWidth);
2046 myCStructure->ContextLine.ShaderProgram = theAspLine->ShaderProgram();
2048 theAspMarker->Values (aColor, aMType, aScale);
2049 myCStructure->ContextMarker.Color.r = float (aColor.Red());
2050 myCStructure->ContextMarker.Color.g = float (aColor.Green());
2051 myCStructure->ContextMarker.Color.b = float (aColor.Blue());
2052 myCStructure->ContextMarker.MarkerType = aMType;
2053 myCStructure->ContextMarker.Scale = float (aScale);
2054 myCStructure->ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
2056 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyleT, aDisplayType, aColorSub, aTextZoomable, aTextAngle, aTextFontAspect);
2057 myCStructure->ContextText.Color.r = float (aColor.Red());
2058 myCStructure->ContextText.Color.g = float (aColor.Green());
2059 myCStructure->ContextText.Color.b = float (aColor.Blue());
2060 myCStructure->ContextText.Font = aFont;
2061 myCStructure->ContextText.Expan = float (anExpansion);
2062 myCStructure->ContextText.Style = aStyleT;
2063 myCStructure->ContextText.DisplayType = aDisplayType;
2064 myCStructure->ContextText.Space = float (aSpace);
2065 myCStructure->ContextText.ColorSubTitle.r = float (aColorSub.Red());
2066 myCStructure->ContextText.ColorSubTitle.g = float (aColorSub.Green());
2067 myCStructure->ContextText.ColorSubTitle.b = float (aColorSub.Blue());
2068 myCStructure->ContextText.TextZoomable = aTextZoomable;
2069 myCStructure->ContextText.TextAngle = float (aTextAngle);
2070 myCStructure->ContextText.TextFontAspect = aTextFontAspect;
2071 myCStructure->ContextText.ShaderProgram = theAspText->ShaderProgram();
2073 Standard_Real anRGB[3];
2074 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
2075 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2076 myCStructure->ContextFillArea.Style = aStyle;
2077 myCStructure->ContextFillArea.IntColor.r = float (anRGB[0]);
2078 myCStructure->ContextFillArea.IntColor.g = float (anRGB[1]);
2079 myCStructure->ContextFillArea.IntColor.b = float (anRGB[2]);
2081 if (theAspFill->Distinguish())
2083 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2085 myCStructure->ContextFillArea.BackIntColor.r = float (anRGB[0]);
2086 myCStructure->ContextFillArea.BackIntColor.g = float (anRGB[1]);
2087 myCStructure->ContextFillArea.BackIntColor.b = float (anRGB[2]);
2090 myCStructure->ContextFillArea.Edge = theAspFill->Edge () ? 1:0;
2091 myCStructure->ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
2092 myCStructure->ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
2093 myCStructure->ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
2094 myCStructure->ContextFillArea.LineType = aLType;
2095 myCStructure->ContextFillArea.Width = float (aWidth);
2096 myCStructure->ContextFillArea.Hatch = theAspFill->HatchStyle();
2098 // Front and Back face
2099 myCStructure->ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
2100 myCStructure->ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
2102 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
2103 // Light specificity
2104 myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess());
2105 myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient());
2106 myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
2107 myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
2108 myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
2109 myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
2112 myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2113 myCStructure->ContextFillArea.Back.IsDiffuse = (aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2114 myCStructure->ContextFillArea.Back.IsSpecular = (aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2115 myCStructure->ContextFillArea.Back.IsEmission = (aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2118 myCStructure->ContextFillArea.Back.IsPhysic = (aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2121 myCStructure->ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
2122 myCStructure->ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
2123 myCStructure->ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
2126 myCStructure->ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
2127 myCStructure->ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
2128 myCStructure->ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
2131 myCStructure->ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
2132 myCStructure->ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
2133 myCStructure->ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
2136 myCStructure->ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
2137 myCStructure->ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
2138 myCStructure->ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
2140 myCStructure->ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
2143 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
2144 // Light specificity
2145 myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess());
2146 myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient());
2147 myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
2148 myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
2149 myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
2150 myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
2153 myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0);
2154 myCStructure->ContextFillArea.Front.IsDiffuse = (aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0);
2155 myCStructure->ContextFillArea.Front.IsSpecular = (aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0);
2156 myCStructure->ContextFillArea.Front.IsEmission = (aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0);
2159 myCStructure->ContextFillArea.Front.IsPhysic = (aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0);
2162 myCStructure->ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
2163 myCStructure->ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
2164 myCStructure->ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
2167 myCStructure->ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
2168 myCStructure->ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
2169 myCStructure->ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
2172 myCStructure->ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
2173 myCStructure->ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
2174 myCStructure->ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
2177 myCStructure->ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
2178 myCStructure->ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
2179 myCStructure->ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
2181 myCStructure->ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
2183 myCStructure->ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
2184 myCStructure->ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
2185 myCStructure->ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
2187 Standard_Integer aPolyMode;
2188 Standard_ShortReal aPolyFactor, aPolyUnits;
2189 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
2190 myCStructure->ContextFillArea.PolygonOffsetMode = aPolyMode;
2191 myCStructure->ContextFillArea.PolygonOffsetFactor = aPolyFactor;
2192 myCStructure->ContextFillArea.PolygonOffsetUnits = aPolyUnits;
2195 //=============================================================================
2196 //function : GraphicHighlight
2198 //=============================================================================
2199 void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod theMethod)
2201 Standard_Real anRGB[3];
2202 myCStructure->highlight = 1;
2203 myHighlightMethod = theMethod;
2206 case Aspect_TOHM_COLOR:
2208 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2209 myCStructure->HighlightWithColor (Graphic3d_Vec3 (float (anRGB[0]), float (anRGB[1]), float (anRGB[2])), Standard_True);
2212 case Aspect_TOHM_BOUNDBOX:
2214 myHighlightColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
2215 myCStructure->HighlightColor.r = float (anRGB[0]);
2216 myCStructure->HighlightColor.g = float (anRGB[1]);
2217 myCStructure->HighlightColor.b = float (anRGB[2]);
2218 myCStructure->HighlightWithBndBox (this, Standard_True);
2224 //=============================================================================
2225 //function : GraphicTransform
2227 //=============================================================================
2228 void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& theMatrix)
2230 for (Standard_Integer i = 0; i <= 3; ++i)
2232 for (Standard_Integer j = 0; j <= 3; ++j)
2234 myCStructure->Transformation[i][j] = float (theMatrix (i, j));
2237 myCStructure->UpdateTransformation();
2240 //=============================================================================
2241 //function : GraphicUnHighlight
2243 //=============================================================================
2244 void Graphic3d_Structure::GraphicUnHighlight()
2246 myCStructure->highlight = 0;
2247 switch (myHighlightMethod)
2249 case Aspect_TOHM_COLOR:
2250 myCStructure->HighlightWithColor (Graphic3d_Vec3 (0.0f, 0.0f, 0.0f), Standard_False);
2252 case Aspect_TOHM_BOUNDBOX:
2253 myCStructure->HighlightWithBndBox (this, Standard_False);
2258 //=============================================================================
2259 //function : ComputeVisual
2261 //=============================================================================
2262 Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const
2264 return myComputeVisual;
2267 //=============================================================================
2268 //function : SetComputeVisual
2270 //=============================================================================
2271 void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
2273 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
2274 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
2275 if (theVisual != Graphic3d_TOS_COMPUTED)
2277 myComputeVisual = theVisual;
2281 //=============================================================================
2282 //function : SetHLRValidation
2284 //=============================================================================
2285 void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag)
2287 myCStructure->HLRValidation = theFlag ? 1 : 0;
2290 //=============================================================================
2291 //function : HLRValidation
2293 //=============================================================================
2294 Standard_Boolean Graphic3d_Structure::HLRValidation() const
2296 // Hidden parts stored in <me> are valid if :
2297 // 1/ the owner is defined.
2298 // 2/ they are not invalid.
2299 return myOwner != NULL
2300 && myCStructure->HLRValidation != 0;
2303 //=======================================================================
2304 //function : SetZLayer
2306 //=======================================================================
2307 void Graphic3d_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerId)
2309 // if the structure is not displayed, unable to change its display layer
2313 myStructureManager->ChangeZLayer (this, theLayerId);
2314 myCStructure->SetZLayer (theLayerId);
2317 //=======================================================================
2318 //function : GetZLayer
2320 //=======================================================================
2321 Graphic3d_ZLayerId Graphic3d_Structure::GetZLayer() const
2323 return myCStructure->ZLayer();
2326 //=======================================================================
2327 //function : SetClipPlanes
2329 //=======================================================================
2330 void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
2332 myCStructure->SetClipPlanes (thePlanes);
2335 //=======================================================================
2336 //function : GetClipPlanes
2338 //=======================================================================
2339 const Graphic3d_SequenceOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const
2341 return myCStructure->ClipPlanes();
2344 //=======================================================================
2345 //function : SetMutable
2347 //=======================================================================
2348 void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable)
2350 myCStructure->IsMutable = theIsMutable;
2353 //=======================================================================
2354 //function : IsMutable
2356 //=======================================================================
2357 Standard_Boolean Graphic3d_Structure::IsMutable() const
2359 return myCStructure->IsMutable;