1 // Created on: 1996-12-20
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <AIS_Shape.ixx>
20 #include <Standard_ErrorHandler.hxx>
21 #include <OSD_Timer.hxx>
22 #include <TColStd_ListIteratorOfListOfInteger.hxx>
24 #include <Quantity_Color.hxx>
27 #include <Bnd_Box.hxx>
28 #include <BRep_Builder.hxx>
29 #include <BRepTools_ShapeSet.hxx>
30 #include <BRepTools.hxx>
31 #include <BRepBndLib.hxx>
33 #include <TopExp_Explorer.hxx>
35 #include <Aspect_TypeOfLine.hxx>
36 #include <Graphic3d_Structure.hxx>
37 #include <Graphic3d_Group.hxx>
38 #include <Graphic3d_AspectLine3d.hxx>
39 #include <Graphic3d_AspectText3d.hxx>
40 #include <Graphic3d_AspectMarker3d.hxx>
41 #include <Graphic3d_AspectFillArea3d.hxx>
42 #include <Graphic3d_ArrayOfPolylines.hxx>
43 #include <Graphic3d_MaterialAspect.hxx>
44 #include <Graphic3d_SequenceOfGroup.hxx>
47 #include <Prs3d_Presentation.hxx>
48 #include <Prs3d_Root.hxx>
49 #include <Prs3d_ShadingAspect.hxx>
50 #include <Prs3d_Drawer.hxx>
51 #include <Prs3d_IsoAspect.hxx>
53 #include <StdPrs_WFShape.hxx>
54 #include <StdPrs_WFDeflectionShape.hxx>
55 #include <StdPrs_ShadedShape.hxx>
56 #include <StdPrs_HLRShape.hxx>
57 #include <StdPrs_HLRPolyShape.hxx>
59 #include <PrsMgr_ModedPresentation.hxx>
61 #include <Select3D_SensitiveEntity.hxx>
62 #include <StdSelect.hxx>
63 #include <StdSelect_BRepSelectionTool.hxx>
64 #include <StdSelect_BRepOwner.hxx>
65 #include <StdSelect_DisplayMode.hxx>
67 #include <AIS_GraphicTool.hxx>
68 #include <AIS_InteractiveContext.hxx>
69 #include <HLRBRep.hxx>
70 #include <Precision.hxx>
72 #include <Standard_Failure.hxx>
73 #include <Standard_ErrorHandler.hxx>
74 #include <Select3D_SensitiveBox.hxx>
75 #include <TopoDS_Iterator.hxx>
77 static Standard_Boolean myFirstCompute;
79 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
81 TColStd_ListIteratorOfListOfInteger It(LL);
82 for(;It.More();It.Next()){
84 return Standard_True;}
85 return Standard_False;
88 //==================================================
91 //==================================================
94 AIS_Shape(const TopoDS_Shape& shap):
95 AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
99 myFirstCompute = Standard_True;
101 myDrawer->SetShadingAspectGlobal(Standard_False);
104 //=======================================================================
107 //=======================================================================
108 AIS_KindOfInteractive AIS_Shape::Type() const
109 {return AIS_KOI_Shape;}
112 //=======================================================================
113 //function : Signature
115 //=======================================================================
116 Standard_Integer AIS_Shape::Signature() const
119 //=======================================================================
120 //function : AcceptShapeDecomposition
122 //=======================================================================
123 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
124 {return Standard_True;}
126 //=======================================================================
129 //=======================================================================
130 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
131 const Handle(Prs3d_Presentation)& aPrs,
132 const Standard_Integer aMode)
135 if(myshape.IsNull()) return;
137 // wire,edge,vertex -> pas de HLR + priorite display superieure
138 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
139 if(TheType>4 && TheType<8) {
140 aPrs->SetVisual(Graphic3d_TOS_ALL);
141 aPrs->SetDisplayPriority(TheType+2);
143 // Shape vide -> Assemblage vide.
144 if (myshape.ShapeType() == TopAbs_COMPOUND) {
145 TopoDS_Iterator anExplor (myshape);
147 if (!anExplor.More()) {
152 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //not taken in account duting FITALL
155 try { OCC_CATCH_SIGNALS StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); }
156 catch (Standard_Failure) {
158 cout << "AIS_Shape::Compute() failed"<< endl;
159 cout << "a Shape should be incorrect : No Compute can be maked on it "<< endl;
161 // presentation of the bounding box is calculated
162 // Compute(aPresentationManager,aPrs,2);
168 if (myDrawer->IsAutoTriangulation())
170 Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
171 Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
172 Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
173 if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
174 || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
176 BRepTools::Clean (myshape);
180 //shading only on face...
181 if ((Standard_Integer) myshape.ShapeType()>4)
182 StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
184 myDrawer->SetShadingAspectGlobal(Standard_False);
185 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
190 StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
192 catch (Standard_Failure) {
194 cout << "AIS_Shape::Compute() in ShadingMode failed"<< endl;
196 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
201 Standard_Real value = Transparency() ;
203 SetTransparency( value );
210 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
211 else StdPrs_WFDeflectionRestrictedFace::AddBox (aPrs, BoundingBox(), myDrawer);
214 aPrs->ReCompute(); // for hidden line recomputation if necessary...
217 //=======================================================================
219 //purpose : Hidden Line Removal
220 //=======================================================================
221 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
222 const Handle(Prs3d_Presentation)& aPresentation)
224 Compute(aProjector,aPresentation,myshape);
227 //=======================================================================
230 //=======================================================================
232 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
233 const Handle(Geom_Transformation)& TheTrsf,
234 const Handle(Prs3d_Presentation)& aPresentation)
236 const TopLoc_Location& loc = myshape.Location();
237 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
238 Compute(aProjector,aPresentation,shbis);
241 //=======================================================================
244 //=======================================================================
246 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
247 const Handle(Prs3d_Presentation)& aPresentation,
248 const TopoDS_Shape& SH)
250 if (SH.ShapeType() == TopAbs_COMPOUND) {
251 TopoDS_Iterator anExplor (SH);
253 if (!anExplor.More()) // Shape vide -> Assemblage vide.
257 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
258 if (defdrawer->DrawHiddenLine())
259 {myDrawer->EnableDrawHiddenLine();}
260 else {myDrawer->DisableDrawHiddenLine();}
262 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
263 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
265 if (myDrawer->IsAutoTriangulation())
267 // coefficients for calculation
268 Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff;
269 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle);
270 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff);
271 if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
272 ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient))
274 BRepTools::Clean(SH);
281 switch (TypeOfHLR()) {
283 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
285 case Prs3d_TOH_PolyAlgo:
287 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
291 catch (Standard_Failure) {
293 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
295 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
299 defdrawer->SetTypeOfDeflection (prevdef);
302 //=======================================================================
303 //function : SelectionType
304 //purpose : gives the type according to the Index of Selection Mode
305 //=======================================================================
307 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
311 return TopAbs_VERTEX;
323 return TopAbs_COMPSOLID;
325 return TopAbs_COMPOUND;
332 //=======================================================================
333 //function : SelectionType
334 //purpose : gives the SelectionMode according to the Type od Decomposition...
335 //=======================================================================
336 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
351 case TopAbs_COMPSOLID:
353 case TopAbs_COMPOUND:
362 //=======================================================================
363 //function : ComputeSelection
365 //=======================================================================
367 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
368 const Standard_Integer aMode)
370 if(myshape.IsNull()) return;
371 if (myshape.ShapeType() == TopAbs_COMPOUND) {
372 TopoDS_Iterator anExplor (myshape);
374 if (!anExplor.More()) // empty Shape -> empty Assembly.
378 static TopAbs_ShapeEnum TypOfSel;
379 TypOfSel = AIS_Shape::SelectionType(aMode);
380 TopoDS_Shape shape = myshape;
382 // POP protection against crash in low layers
384 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
387 StdSelect_BRepSelectionTool::Load(aSelection,
392 myDrawer->HLRAngle(),
393 myDrawer->IsAutoTriangulation());
394 } catch ( Standard_Failure ) {
395 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
398 Bnd_Box B = BoundingBox();
399 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
400 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
401 aSelection->Add(aSensitiveBox);
405 // insert the drawer in the BrepOwners for hilight...
406 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
409 Quantity_NameOfColor AIS_Shape::Color() const {
410 Quantity_Color aColor;
412 return aColor.Name();
415 void AIS_Shape::Color( Quantity_Color& aColor ) const {
416 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
419 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
420 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
423 Standard_Real AIS_Shape::Transparency() const {
424 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
427 //=======================================================================
428 //function : SetColor
430 //=======================================================================
432 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
434 SetColor(Quantity_Color(aCol));
437 //=======================================================================
438 //function : setColor
440 //=======================================================================
442 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
443 const Quantity_Color& theColor) const
445 if (!theDrawer->HasOwnShadingAspect())
447 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
448 if (theDrawer->HasLink())
450 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
453 if (!theDrawer->HasOwnLineAspect())
455 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
456 if (theDrawer->HasLink())
458 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
461 if (!theDrawer->HasOwnWireAspect())
463 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
464 if (theDrawer->HasLink())
466 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
469 if (!theDrawer->HasOwnPointAspect())
471 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
472 if (theDrawer->HasLink())
474 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
477 // disable dedicated line aspects
478 theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect());
479 theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect());
480 theDrawer->SetSeenLineAspect (theDrawer->LineAspect());
483 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
484 theDrawer->SetShadingAspectGlobal (Standard_False);
485 theDrawer->LineAspect()->SetColor (theColor);
486 theDrawer->WireAspect()->SetColor (theColor);
487 theDrawer->PointAspect()->SetColor (theColor);
490 //=======================================================================
491 //function : SetColor
493 //=======================================================================
495 void AIS_Shape::SetColor (const Quantity_Color& theColor)
497 setColor (myDrawer, theColor);
498 myOwnColor = theColor;
499 hasOwnColor = Standard_True;
501 // modify shading presentation without re-computation
502 const PrsMgr_Presentations& aPrsList = Presentations();
503 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
504 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
505 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
506 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
508 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
509 if (aPrsModed.Mode() != AIS_Shaded)
514 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
516 // Set aspects for presentation
517 aPrs->SetPrimitivesAspect (anAreaAspect);
518 aPrs->SetPrimitivesAspect (aLineAspect);
519 aPrs->SetPrimitivesAspect (aPointAspect);
521 // Go through all groups to change color for all primitives
522 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
524 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
526 // Check if aspect of given type is set for the group,
527 // because setting aspect for group with no already set aspect
528 // can lead to loss of presentation data
529 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
531 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
533 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
535 aGroup->SetGroupPrimitivesAspect (aLineAspect);
537 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
539 aGroup->SetGroupPrimitivesAspect (aPointAspect);
544 LoadRecomputable (AIS_WireFrame);
545 LoadRecomputable (2);
548 //=======================================================================
549 //function : UnsetColor
551 //=======================================================================
553 void AIS_Shape::UnsetColor()
557 myToRecomputeModes.Clear();
560 hasOwnColor = Standard_False;
564 Handle(Prs3d_LineAspect) anEmptyAsp;
565 myDrawer->SetLineAspect (anEmptyAsp);
566 myDrawer->SetWireAspect (anEmptyAsp);
567 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
568 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
569 myDrawer->SetSeenLineAspect (anEmptyAsp);
573 Quantity_Color aColor = Quantity_NOC_YELLOW;
574 if (myDrawer->HasLink())
576 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
578 myDrawer->LineAspect()->SetColor (aColor);
579 aColor = Quantity_NOC_RED;
580 if (myDrawer->HasLink())
582 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
584 myDrawer->WireAspect()->SetColor (aColor);
585 aColor = Quantity_NOC_GREEN;
586 if (myDrawer->HasLink())
588 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
590 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
591 aColor = Quantity_NOC_YELLOW;
592 if (myDrawer->HasLink())
594 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
596 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
597 if (myDrawer->HasLink())
599 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
601 myDrawer->SeenLineAspect()->SetColor (aColor);
607 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
608 Graphic3d_MaterialAspect mat = aDefaultMat;
609 if (HasMaterial() || myDrawer->HasLink())
611 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
615 Quantity_Color aColor = aDefaultMat.AmbientColor();
616 if (myDrawer->HasLink())
618 aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
620 mat.SetColor (aColor);
624 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
625 mat.SetTransparency (aTransp);
627 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
631 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
633 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
635 // modify shading presentation without re-computation
636 const PrsMgr_Presentations& aPrsList = Presentations();
637 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
638 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
639 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
641 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
642 if (aPrsModed.Mode() != AIS_Shaded)
647 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
649 aPrs->SetPrimitivesAspect (anAreaAsp);
650 aPrs->SetPrimitivesAspect (aLineAsp);
652 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
654 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
656 // Check if aspect of given type is set for the group,
657 // because setting aspect for group with no already set aspect
658 // can lead to loss of presentation data
659 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
661 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
663 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
665 aGroup->SetGroupPrimitivesAspect (aLineAsp);
670 LoadRecomputable (AIS_WireFrame);
671 LoadRecomputable (2);
674 //=======================================================================
675 //function : setWidth
677 //=======================================================================
679 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
680 const Standard_Real theLineWidth) const
682 if (!theDrawer->HasOwnLineAspect())
684 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
685 if (theDrawer->HasLink())
687 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
690 if (!theDrawer->HasOwnWireAspect())
692 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
693 if (theDrawer->HasLink())
695 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
698 // disable dedicated line aspects
699 theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect());
700 theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect());
701 theDrawer->SetSeenLineAspect (theDrawer->LineAspect());
704 theDrawer->LineAspect()->SetWidth (theLineWidth);
705 theDrawer->WireAspect()->SetWidth (theLineWidth);
708 //=======================================================================
709 //function : SetWidth
711 //=======================================================================
713 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
715 setWidth (myDrawer, theLineWidth);
716 myOwnWidth = theLineWidth;
717 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
718 LoadRecomputable (2); // and the bounding box...
721 //=======================================================================
722 //function : UnsetWidth
724 //=======================================================================
726 void AIS_Shape::UnsetWidth()
728 if (myOwnWidth == 0.0)
730 myToRecomputeModes.Clear();
736 Handle(Prs3d_LineAspect) anEmptyAsp;
740 myDrawer->SetLineAspect (anEmptyAsp);
741 myDrawer->SetWireAspect (anEmptyAsp);
742 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
743 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
744 myDrawer->SetSeenLineAspect (anEmptyAsp);
748 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
749 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
750 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
751 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
752 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
753 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
754 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
755 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
756 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
757 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
759 LoadRecomputable (AIS_WireFrame);
762 //=======================================================================
763 //function : setMaterial
765 //=======================================================================
767 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
768 const Graphic3d_MaterialAspect& theMaterial,
769 const Standard_Boolean theToKeepColor,
770 const Standard_Boolean theToKeepTransp) const
772 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
773 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
774 if (!theDrawer->HasOwnShadingAspect())
776 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
777 if (theDrawer->HasLink())
779 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
782 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
786 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
790 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
794 //=======================================================================
795 //function : SetMaterial
797 //=======================================================================
799 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
801 SetMaterial(Graphic3d_MaterialAspect(aMat));
804 //=======================================================================
805 //function : SetMaterial
807 //=======================================================================
809 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
811 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
812 hasOwnMaterial = Standard_True;
814 // modify shading presentation without re-computation
815 const PrsMgr_Presentations& aPrsList = Presentations();
816 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
817 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
819 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
820 if (aPrsModed.Mode() != AIS_Shaded)
825 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
826 aPrs->SetPrimitivesAspect (anAreaAsp);
827 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
829 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
831 // Check if aspect of given type is set for the group,
832 // because setting aspect for group with no already set aspect
833 // can lead to loss of presentation data
834 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
836 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
841 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
842 myToRecomputeModes.Clear();
845 //=======================================================================
846 //function : UnsetMaterial
848 //=======================================================================
850 void AIS_Shape::UnsetMaterial()
860 if(myDrawer->HasLink())
862 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
863 myCurrentFacingModel);
867 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
868 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
873 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
875 hasOwnMaterial = Standard_False;
877 // modify shading presentation without re-computation
878 const PrsMgr_Presentations& aPrsList = Presentations();
879 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
880 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
882 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
883 if (aPrsModed.Mode() != AIS_Shaded)
888 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
889 aPrs->SetPrimitivesAspect (anAreaAsp);
890 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
892 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
893 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
895 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
900 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
901 myToRecomputeModes.Clear();
904 //=======================================================================
905 //function : setTransparency
907 //=======================================================================
909 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
910 const Standard_Real theValue) const
912 if (!theDrawer->HasOwnShadingAspect())
914 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
915 if (theDrawer->HasLink())
917 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
921 // override transparency
922 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
925 //=======================================================================
926 //function : SetTransparency
928 //=======================================================================
930 void AIS_Shape::SetTransparency (const Standard_Real theValue)
932 setTransparency (myDrawer, theValue);
933 myTransparency = theValue;
935 // modify shading presentation without re-computation
936 const PrsMgr_Presentations& aPrsList = Presentations();
937 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
938 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
940 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
941 if (aPrsModed.Mode() != AIS_Shaded)
946 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
947 aPrs->SetPrimitivesAspect (anAreaAsp);
948 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
949 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
951 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
952 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
954 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
959 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
960 myToRecomputeModes.Clear();
963 //=======================================================================
964 //function : UnsetTransparency
966 //=======================================================================
968 void AIS_Shape::UnsetTransparency()
970 myTransparency = 0.0;
971 if (!myDrawer->HasOwnShadingAspect())
975 else if (HasColor() || HasMaterial())
977 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
981 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
984 // modify shading presentation without re-computation
985 const PrsMgr_Presentations& aPrsList = Presentations();
986 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
987 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
989 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
990 if (aPrsModed.Mode() != AIS_Shaded)
995 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
996 aPrs->SetPrimitivesAspect (anAreaAsp);
997 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
999 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1000 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1002 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1005 aPrs->ResetDisplayPriority();
1008 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1009 myToRecomputeModes.Clear();
1012 //=======================================================================
1013 //function : LoadRecomputable
1015 //=======================================================================
1017 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1019 myRecomputeEveryPrs = Standard_False;
1020 if(!IsInList(myToRecomputeModes,TheMode))
1021 myToRecomputeModes.Append(TheMode);
1024 //=======================================================================
1025 //function : BoundingBox
1027 //=======================================================================
1029 const Bnd_Box& AIS_Shape::BoundingBox()
1031 if (myshape.ShapeType() == TopAbs_COMPOUND) {
1032 TopoDS_Iterator anExplor (myshape);
1034 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1041 BRepBndLib::AddClose(myshape, myBB);
1042 myCompBB = Standard_False;
1049 //=======================================================================
1050 //function : SetOwnDeviationCoefficient
1051 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1052 // returns Standard_True if it change
1053 //=======================================================================
1055 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1057 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1058 if(itSet) myDrawer->SetDeviationCoefficient();
1062 //=======================================================================
1063 //function : SetHLROwnDeviationCoefficient
1064 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1065 // returns Standard_True if it change
1066 //=======================================================================
1068 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1070 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1071 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1076 //=======================================================================
1077 //function : SetOwnDeviationAngle
1078 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1079 // returns Standard_True if it change
1080 //=======================================================================
1082 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1084 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1085 if(itSet) myDrawer->SetDeviationAngle();
1090 //=======================================================================
1091 //function : SetOwnHLRDeviationAngle
1092 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1093 // returns Standard_True if it change
1094 //=======================================================================
1096 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1098 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1099 if(itSet) myDrawer->SetHLRAngle();
1104 //=======================================================================
1105 //function : SetOwnDeviationCoefficient
1107 //=======================================================================
1109 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1111 myDrawer->SetDeviationCoefficient( aCoefficient );
1112 SetToUpdate(0) ; // WireFrame
1113 SetToUpdate(1) ; // Shadding
1116 //=======================================================================
1117 //function : SetOwnHLRDeviationCoefficient
1119 //=======================================================================
1121 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1123 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1127 //=======================================================================
1128 //function : SetOwnDeviationAngle
1130 //=======================================================================
1132 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1135 myDrawer->SetDeviationAngle(anAngle );
1136 SetToUpdate(0) ; // WireFrame
1138 //=======================================================================
1139 //function : SetOwnDeviationAngle
1141 //=======================================================================
1143 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1145 Standard_Real OutAngl,OutDefl;
1146 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1147 SetOwnDeviationAngle(anAngle) ;
1148 SetOwnDeviationCoefficient(OutDefl) ;
1149 myInitAng = anAngle;
1154 //=======================================================================
1155 //function : UserAngle
1157 //=======================================================================
1159 Standard_Real AIS_Shape::UserAngle() const
1161 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1165 //=======================================================================
1166 //function : SetHLRAngleAndDeviation
1168 //=======================================================================
1170 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1172 Standard_Real OutAngl,OutDefl;
1173 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1174 SetOwnHLRDeviationAngle( OutAngl );
1175 SetOwnHLRDeviationCoefficient(OutDefl);
1178 //=======================================================================
1179 //function : SetOwnHLRDeviationAngle
1181 //=======================================================================
1183 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1185 myDrawer->SetHLRAngle( anAngle );
1189 //=======================================================================
1190 //function : OwnDeviationCoefficient
1192 //=======================================================================
1194 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1195 Standard_Real & aPreviousCoefficient ) const
1197 aCoefficient = myDrawer->DeviationCoefficient();
1198 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1199 return myDrawer->HasOwnDeviationCoefficient() ;
1202 //=======================================================================
1203 //function : OwnHLRDeviationCoefficient
1205 //=======================================================================
1207 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1208 Standard_Real & aPreviousCoefficient ) const
1210 aCoefficient = myDrawer->HLRDeviationCoefficient();
1211 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1212 return myDrawer->HasOwnHLRDeviationCoefficient();
1216 //=======================================================================
1217 //function : OwnDeviationAngle
1219 //=======================================================================
1221 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1222 Standard_Real & aPreviousAngle ) const
1224 anAngle = myDrawer->DeviationAngle();
1225 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1226 return myDrawer->HasOwnDeviationAngle();
1229 //=======================================================================
1230 //function : OwnHLRDeviationAngle
1232 //=======================================================================
1234 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1235 Standard_Real & aPreviousAngle ) const
1237 anAngle = myDrawer->HLRAngle();
1238 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1239 return myDrawer->HasOwnHLRDeviationAngle();