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.
18 #include <AIS_GraphicTool.hxx>
19 #include <AIS_InteractiveContext.hxx>
20 #include <AIS_Shape.hxx>
21 #include <Aspect_TypeOfLine.hxx>
22 #include <Bnd_Box.hxx>
23 #include <BRep_Builder.hxx>
24 #include <BRepBndLib.hxx>
25 #include <BRepTools.hxx>
26 #include <BRepTools_ShapeSet.hxx>
27 #include <Geom_Transformation.hxx>
29 #include <Graphic3d_ArrayOfPolylines.hxx>
30 #include <Graphic3d_AspectFillArea3d.hxx>
31 #include <Graphic3d_AspectLine3d.hxx>
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_AspectText3d.hxx>
34 #include <Graphic3d_Group.hxx>
35 #include <Graphic3d_MaterialAspect.hxx>
36 #include <Graphic3d_SequenceOfGroup.hxx>
37 #include <Graphic3d_Structure.hxx>
38 #include <HLRBRep.hxx>
39 #include <OSD_Timer.hxx>
40 #include <Precision.hxx>
42 #include <Prs3d_Drawer.hxx>
43 #include <Prs3d_IsoAspect.hxx>
44 #include <Prs3d_Presentation.hxx>
45 #include <Prs3d_Projector.hxx>
46 #include <Prs3d_Root.hxx>
47 #include <Prs3d_ShadingAspect.hxx>
48 #include <StdPrs_BndBox.hxx>
49 #include <StdPrs_ToolTriangulatedShape.hxx>
50 #include <PrsMgr_ModedPresentation.hxx>
51 #include <Quantity_Color.hxx>
52 #include <Select3D_SensitiveBox.hxx>
53 #include <Select3D_SensitiveEntity.hxx>
54 #include <Standard_ErrorHandler.hxx>
55 #include <Standard_Failure.hxx>
56 #include <Standard_Type.hxx>
57 #include <StdPrs_HLRPolyShape.hxx>
58 #include <StdPrs_HLRShape.hxx>
59 #include <StdPrs_ShadedShape.hxx>
60 #include <StdPrs_WFShape.hxx>
61 #include <StdSelect.hxx>
62 #include <StdSelect_BRepOwner.hxx>
63 #include <StdSelect_BRepSelectionTool.hxx>
64 #include <StdSelect_DisplayMode.hxx>
65 #include <TColStd_ListIteratorOfListOfInteger.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Iterator.hxx>
69 #include <TopoDS_Shape.hxx>
71 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
73 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
75 TColStd_ListIteratorOfListOfInteger It(LL);
76 for(;It.More();It.Next()){
78 return Standard_True;}
79 return Standard_False;
82 //==================================================
85 //==================================================
88 AIS_Shape(const TopoDS_Shape& shap):
89 AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
94 myDrawer->SetShadingAspectGlobal(Standard_False);
97 //=======================================================================
100 //=======================================================================
101 AIS_KindOfInteractive AIS_Shape::Type() const
102 {return AIS_KOI_Shape;}
105 //=======================================================================
106 //function : Signature
108 //=======================================================================
109 Standard_Integer AIS_Shape::Signature() const
112 //=======================================================================
113 //function : AcceptShapeDecomposition
115 //=======================================================================
116 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
117 {return Standard_True;}
119 //=======================================================================
122 //=======================================================================
123 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
124 const Handle(Prs3d_Presentation)& aPrs,
125 const Standard_Integer theMode)
128 if(myshape.IsNull()) return;
130 // wire,edge,vertex -> pas de HLR + priorite display superieure
131 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
132 if(TheType>4 && TheType<8) {
133 aPrs->SetVisual(Graphic3d_TOS_ALL);
134 aPrs->SetDisplayPriority(TheType+2);
136 // Shape vide -> Assemblage vide.
137 if (myshape.ShapeType() == TopAbs_COMPOUND) {
138 TopoDS_Iterator anExplor (myshape);
140 if (!anExplor.More()) {
147 aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
154 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
158 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
160 catch (Standard_Failure)
163 cout << "AIS_Shape::Compute() failed" << endl;
164 cout << "a Shape should be incorrect : No Compute can be maked on it " << endl;
166 // presentation of the bounding box is calculated
167 // Compute(aPresentationManager,aPrs,2);
173 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
174 if ((Standard_Integer) myshape.ShapeType() > 4)
176 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
180 myDrawer->SetShadingAspectGlobal (Standard_False);
183 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
190 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer);
192 catch (Standard_Failure)
195 cout << "AIS_Shape::Compute() in ShadingMode failed" << endl;
197 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
201 Standard_Real aTransparency = Transparency() ;
202 if (aTransparency > 0.0)
204 SetTransparency (aTransparency);
214 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
218 StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
223 // Recompute hidden line presentation (if necessary).
227 //=======================================================================
229 //purpose : Hidden Line Removal
230 //=======================================================================
231 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
232 const Handle(Prs3d_Presentation)& aPresentation)
234 Compute(aProjector,aPresentation,myshape);
237 //=======================================================================
240 //=======================================================================
242 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
243 const Handle(Geom_Transformation)& TheTrsf,
244 const Handle(Prs3d_Presentation)& aPresentation)
246 const TopLoc_Location& loc = myshape.Location();
247 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
248 Compute(aProjector,aPresentation,shbis);
251 //=======================================================================
254 //=======================================================================
256 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
257 const Handle(Prs3d_Presentation)& aPresentation,
258 const TopoDS_Shape& SH)
260 if (SH.ShapeType() == TopAbs_COMPOUND) {
261 TopoDS_Iterator anExplor (SH);
263 if (!anExplor.More()) // Shape vide -> Assemblage vide.
267 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
268 if (defdrawer->DrawHiddenLine())
269 {myDrawer->EnableDrawHiddenLine();}
270 else {myDrawer->DisableDrawHiddenLine();}
272 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
273 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
275 if (myDrawer->IsAutoTriangulation())
277 // coefficients for calculation
278 Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff;
279 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle);
280 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff);
281 if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
282 ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient))
284 BRepTools::Clean(SH);
291 switch (TypeOfHLR()) {
293 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
295 case Prs3d_TOH_PolyAlgo:
297 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
301 catch (Standard_Failure) {
303 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
305 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
309 defdrawer->SetTypeOfDeflection (prevdef);
312 //=======================================================================
313 //function : SelectionType
314 //purpose : gives the type according to the Index of Selection Mode
315 //=======================================================================
317 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
321 return TopAbs_VERTEX;
333 return TopAbs_COMPSOLID;
335 return TopAbs_COMPOUND;
342 //=======================================================================
343 //function : SelectionType
344 //purpose : gives the SelectionMode according to the Type od Decomposition...
345 //=======================================================================
346 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
361 case TopAbs_COMPSOLID:
363 case TopAbs_COMPOUND:
372 //=======================================================================
373 //function : ComputeSelection
375 //=======================================================================
377 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
378 const Standard_Integer aMode)
380 if(myshape.IsNull()) return;
381 if (myshape.ShapeType() == TopAbs_COMPOUND) {
382 TopoDS_Iterator anExplor (myshape);
384 if (!anExplor.More()) // empty Shape -> empty Assembly.
388 TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
389 TopoDS_Shape shape = myshape;
391 // POP protection against crash in low layers
393 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
396 StdSelect_BRepSelectionTool::Load(aSelection,
401 myDrawer->HLRAngle(),
402 myDrawer->IsAutoTriangulation());
403 } catch ( Standard_Failure ) {
404 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
407 Bnd_Box B = BoundingBox();
408 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
409 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
410 aSelection->Add(aSensitiveBox);
414 // insert the drawer in the BrepOwners for hilight...
415 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
418 Quantity_NameOfColor AIS_Shape::Color() const {
419 Quantity_Color aColor;
421 return aColor.Name();
424 void AIS_Shape::Color( Quantity_Color& aColor ) const {
425 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
428 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
429 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
432 Standard_Real AIS_Shape::Transparency() const {
433 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
436 //=======================================================================
437 //function : SetColor
439 //=======================================================================
441 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
443 SetColor(Quantity_Color(aCol));
446 //=======================================================================
447 //function : setColor
449 //=======================================================================
451 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
452 const Quantity_Color& theColor) const
454 if (!theDrawer->HasOwnShadingAspect())
456 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
457 if (theDrawer->HasLink())
459 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
462 if (!theDrawer->HasOwnLineAspect())
464 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
465 if (theDrawer->HasLink())
467 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
470 if (!theDrawer->HasOwnWireAspect())
472 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
473 if (theDrawer->HasLink())
475 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
478 if (!theDrawer->HasOwnPointAspect())
480 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
481 if (theDrawer->HasLink())
483 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
486 if (!theDrawer->HasOwnFreeBoundaryAspect())
488 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
489 if (theDrawer->HasLink())
491 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
494 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
496 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
497 if (theDrawer->HasLink())
499 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
502 if (!theDrawer->HasOwnSeenLineAspect())
504 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
505 if (theDrawer->HasLink())
507 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
512 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
513 theDrawer->SetShadingAspectGlobal (Standard_False);
514 theDrawer->LineAspect()->SetColor (theColor);
515 theDrawer->WireAspect()->SetColor (theColor);
516 theDrawer->PointAspect()->SetColor (theColor);
517 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
518 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
519 theDrawer->SeenLineAspect()->SetColor (theColor);
522 //=======================================================================
523 //function : SetColor
525 //=======================================================================
527 void AIS_Shape::SetColor (const Quantity_Color& theColor)
529 setColor (myDrawer, theColor);
530 myOwnColor = theColor;
531 hasOwnColor = Standard_True;
533 // modify shading presentation without re-computation
534 const PrsMgr_Presentations& aPrsList = Presentations();
535 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
536 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
537 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
538 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
540 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
541 if (aPrsModed.Mode() != AIS_Shaded)
546 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
547 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
549 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
551 // Check if aspect of given type is set for the group,
552 // because setting aspect for group with no already set aspect
553 // can lead to loss of presentation data
554 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
556 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
558 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
560 aGroup->SetGroupPrimitivesAspect (aLineAspect);
562 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
564 aGroup->SetGroupPrimitivesAspect (aPointAspect);
569 LoadRecomputable (AIS_WireFrame);
570 LoadRecomputable (2);
573 //=======================================================================
574 //function : UnsetColor
576 //=======================================================================
578 void AIS_Shape::UnsetColor()
582 myToRecomputeModes.Clear();
585 hasOwnColor = Standard_False;
589 Handle(Prs3d_LineAspect) anEmptyAsp;
590 myDrawer->SetLineAspect (anEmptyAsp);
591 myDrawer->SetWireAspect (anEmptyAsp);
592 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
593 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
594 myDrawer->SetSeenLineAspect (anEmptyAsp);
598 Quantity_Color aColor = Quantity_NOC_YELLOW;
599 if (myDrawer->HasLink())
601 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
603 myDrawer->LineAspect()->SetColor (aColor);
604 aColor = Quantity_NOC_RED;
605 if (myDrawer->HasLink())
607 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
609 myDrawer->WireAspect()->SetColor (aColor);
610 aColor = Quantity_NOC_GREEN;
611 if (myDrawer->HasLink())
613 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
615 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
616 aColor = Quantity_NOC_YELLOW;
617 if (myDrawer->HasLink())
619 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
621 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
622 if (myDrawer->HasLink())
624 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
626 myDrawer->SeenLineAspect()->SetColor (aColor);
632 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
633 Graphic3d_MaterialAspect mat = aDefaultMat;
634 if (HasMaterial() || myDrawer->HasLink())
636 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
640 Quantity_Color aColor = aDefaultMat.AmbientColor();
641 if (myDrawer->HasLink())
643 aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
645 mat.SetColor (aColor);
649 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
650 mat.SetTransparency (aTransp);
652 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
656 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
658 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
660 // modify shading presentation without re-computation
661 const PrsMgr_Presentations& aPrsList = Presentations();
662 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
663 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
664 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
666 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
667 if (aPrsModed.Mode() != AIS_Shaded)
672 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
673 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
675 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
677 // Check if aspect of given type is set for the group,
678 // because setting aspect for group with no already set aspect
679 // can lead to loss of presentation data
680 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
682 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
684 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
686 aGroup->SetGroupPrimitivesAspect (aLineAsp);
691 LoadRecomputable (AIS_WireFrame);
692 LoadRecomputable (2);
695 //=======================================================================
696 //function : setWidth
698 //=======================================================================
700 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
701 const Standard_Real theLineWidth) const
703 if (!theDrawer->HasOwnLineAspect())
705 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
706 if (theDrawer->HasLink())
708 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
711 if (!theDrawer->HasOwnWireAspect())
713 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
714 if (theDrawer->HasLink())
716 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
719 if (!theDrawer->HasOwnFreeBoundaryAspect())
721 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
722 if (theDrawer->HasLink())
724 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
727 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
729 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
730 if (theDrawer->HasLink())
732 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
735 if (!theDrawer->HasOwnSeenLineAspect())
737 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
738 if (theDrawer->HasLink())
740 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
745 theDrawer->LineAspect()->SetWidth (theLineWidth);
746 theDrawer->WireAspect()->SetWidth (theLineWidth);
747 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
748 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
749 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
752 //=======================================================================
753 //function : SetWidth
755 //=======================================================================
757 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
759 setWidth (myDrawer, theLineWidth);
760 myOwnWidth = theLineWidth;
761 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
762 LoadRecomputable (2); // and the bounding box...
765 //=======================================================================
766 //function : UnsetWidth
768 //=======================================================================
770 void AIS_Shape::UnsetWidth()
772 if (myOwnWidth == 0.0)
774 myToRecomputeModes.Clear();
780 Handle(Prs3d_LineAspect) anEmptyAsp;
784 myDrawer->SetLineAspect (anEmptyAsp);
785 myDrawer->SetWireAspect (anEmptyAsp);
786 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
787 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
788 myDrawer->SetSeenLineAspect (anEmptyAsp);
792 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
793 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
794 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
795 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
796 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
797 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
798 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
799 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
800 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
801 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
803 LoadRecomputable (AIS_WireFrame);
806 //=======================================================================
807 //function : setMaterial
809 //=======================================================================
811 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
812 const Graphic3d_MaterialAspect& theMaterial,
813 const Standard_Boolean theToKeepColor,
814 const Standard_Boolean theToKeepTransp) const
816 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
817 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
818 if (!theDrawer->HasOwnShadingAspect())
820 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
821 if (theDrawer->HasLink())
823 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
826 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
830 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
834 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
838 //=======================================================================
839 //function : SetMaterial
841 //=======================================================================
843 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
845 SetMaterial(Graphic3d_MaterialAspect(aMat));
848 //=======================================================================
849 //function : SetMaterial
851 //=======================================================================
853 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
855 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
856 hasOwnMaterial = Standard_True;
858 // modify shading presentation without re-computation
859 const PrsMgr_Presentations& aPrsList = Presentations();
860 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
861 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
863 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
864 if (aPrsModed.Mode() != AIS_Shaded)
869 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
870 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
872 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
874 // Check if aspect of given type is set for the group,
875 // because setting aspect for group with no already set aspect
876 // can lead to loss of presentation data
877 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
879 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
884 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
885 myToRecomputeModes.Clear();
888 //=======================================================================
889 //function : UnsetMaterial
891 //=======================================================================
893 void AIS_Shape::UnsetMaterial()
903 if(myDrawer->HasLink())
905 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
906 myCurrentFacingModel);
910 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
911 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
916 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
918 hasOwnMaterial = Standard_False;
920 // modify shading presentation without re-computation
921 const PrsMgr_Presentations& aPrsList = Presentations();
922 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
923 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
925 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
926 if (aPrsModed.Mode() != AIS_Shaded)
931 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
932 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
934 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
935 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
937 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
942 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
943 myToRecomputeModes.Clear();
946 //=======================================================================
947 //function : setTransparency
949 //=======================================================================
951 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
952 const Standard_Real theValue) const
954 if (!theDrawer->HasOwnShadingAspect())
956 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
957 if (theDrawer->HasLink())
959 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
963 // override transparency
964 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
967 //=======================================================================
968 //function : SetTransparency
970 //=======================================================================
972 void AIS_Shape::SetTransparency (const Standard_Real theValue)
974 setTransparency (myDrawer, theValue);
975 myTransparency = theValue;
977 // modify shading presentation without re-computation
978 const PrsMgr_Presentations& aPrsList = Presentations();
979 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
980 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
982 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
983 if (aPrsModed.Mode() != AIS_Shaded)
988 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
989 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
990 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
992 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
993 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
995 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1000 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
1001 myToRecomputeModes.Clear();
1004 //=======================================================================
1005 //function : UnsetTransparency
1007 //=======================================================================
1009 void AIS_Shape::UnsetTransparency()
1011 myTransparency = 0.0;
1012 if (!myDrawer->HasOwnShadingAspect())
1016 else if (HasColor() || HasMaterial())
1018 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
1022 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
1025 // modify shading presentation without re-computation
1026 const PrsMgr_Presentations& aPrsList = Presentations();
1027 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1028 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1030 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1031 if (aPrsModed.Mode() != AIS_Shaded)
1036 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1037 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1039 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1040 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1042 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1045 aPrs->ResetDisplayPriority();
1048 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1049 myToRecomputeModes.Clear();
1052 //=======================================================================
1053 //function : LoadRecomputable
1055 //=======================================================================
1057 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1059 myRecomputeEveryPrs = Standard_False;
1060 if(!IsInList(myToRecomputeModes,TheMode))
1061 myToRecomputeModes.Append(TheMode);
1064 //=======================================================================
1065 //function : BoundingBox
1067 //=======================================================================
1069 const Bnd_Box& AIS_Shape::BoundingBox()
1071 if (myshape.ShapeType() == TopAbs_COMPOUND) {
1072 TopoDS_Iterator anExplor (myshape);
1074 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1081 BRepBndLib::AddClose(myshape, myBB);
1082 myCompBB = Standard_False;
1089 //=======================================================================
1090 //function : SetOwnDeviationCoefficient
1091 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1092 // returns Standard_True if it change
1093 //=======================================================================
1095 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1097 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1098 if(itSet) myDrawer->SetDeviationCoefficient();
1102 //=======================================================================
1103 //function : SetHLROwnDeviationCoefficient
1104 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1105 // returns Standard_True if it change
1106 //=======================================================================
1108 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1110 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1111 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1116 //=======================================================================
1117 //function : SetOwnDeviationAngle
1118 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1119 // returns Standard_True if it change
1120 //=======================================================================
1122 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1124 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1125 if(itSet) myDrawer->SetDeviationAngle();
1130 //=======================================================================
1131 //function : SetOwnHLRDeviationAngle
1132 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1133 // returns Standard_True if it change
1134 //=======================================================================
1136 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1138 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1139 if(itSet) myDrawer->SetHLRAngle();
1144 //=======================================================================
1145 //function : SetOwnDeviationCoefficient
1147 //=======================================================================
1149 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1151 myDrawer->SetDeviationCoefficient( aCoefficient );
1152 SetToUpdate(0) ; // WireFrame
1153 SetToUpdate(1) ; // Shadding
1156 //=======================================================================
1157 //function : SetOwnHLRDeviationCoefficient
1159 //=======================================================================
1161 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1163 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1167 //=======================================================================
1168 //function : SetOwnDeviationAngle
1170 //=======================================================================
1172 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1175 myDrawer->SetDeviationAngle(anAngle );
1176 SetToUpdate(0) ; // WireFrame
1178 //=======================================================================
1179 //function : SetOwnDeviationAngle
1181 //=======================================================================
1183 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1185 Standard_Real OutAngl,OutDefl;
1186 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1187 SetOwnDeviationAngle(anAngle) ;
1188 SetOwnDeviationCoefficient(OutDefl) ;
1189 myInitAng = anAngle;
1194 //=======================================================================
1195 //function : UserAngle
1197 //=======================================================================
1199 Standard_Real AIS_Shape::UserAngle() const
1201 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1205 //=======================================================================
1206 //function : SetHLRAngleAndDeviation
1208 //=======================================================================
1210 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1212 Standard_Real OutAngl,OutDefl;
1213 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1214 SetOwnHLRDeviationAngle( OutAngl );
1215 SetOwnHLRDeviationCoefficient(OutDefl);
1218 //=======================================================================
1219 //function : SetOwnHLRDeviationAngle
1221 //=======================================================================
1223 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1225 myDrawer->SetHLRAngle( anAngle );
1229 //=======================================================================
1230 //function : OwnDeviationCoefficient
1232 //=======================================================================
1234 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1235 Standard_Real & aPreviousCoefficient ) const
1237 aCoefficient = myDrawer->DeviationCoefficient();
1238 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1239 return myDrawer->HasOwnDeviationCoefficient() ;
1242 //=======================================================================
1243 //function : OwnHLRDeviationCoefficient
1245 //=======================================================================
1247 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1248 Standard_Real & aPreviousCoefficient ) const
1250 aCoefficient = myDrawer->HLRDeviationCoefficient();
1251 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1252 return myDrawer->HasOwnHLRDeviationCoefficient();
1256 //=======================================================================
1257 //function : OwnDeviationAngle
1259 //=======================================================================
1261 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1262 Standard_Real & aPreviousAngle ) const
1264 anAngle = myDrawer->DeviationAngle();
1265 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1266 return myDrawer->HasOwnDeviationAngle();
1269 //=======================================================================
1270 //function : OwnHLRDeviationAngle
1272 //=======================================================================
1274 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1275 Standard_Real & aPreviousAngle ) const
1277 anAngle = myDrawer->HLRAngle();
1278 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1279 return myDrawer->HasOwnHLRDeviationAngle();