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();
548 // Set aspects for presentation
549 aPrs->SetPrimitivesAspect (anAreaAspect);
550 aPrs->SetPrimitivesAspect (aLineAspect);
551 aPrs->SetPrimitivesAspect (aPointAspect);
553 // Go through all groups to change color for all primitives
554 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
556 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
558 // Check if aspect of given type is set for the group,
559 // because setting aspect for group with no already set aspect
560 // can lead to loss of presentation data
561 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
563 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
565 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
567 aGroup->SetGroupPrimitivesAspect (aLineAspect);
569 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
571 aGroup->SetGroupPrimitivesAspect (aPointAspect);
576 LoadRecomputable (AIS_WireFrame);
577 LoadRecomputable (2);
580 //=======================================================================
581 //function : UnsetColor
583 //=======================================================================
585 void AIS_Shape::UnsetColor()
589 myToRecomputeModes.Clear();
592 hasOwnColor = Standard_False;
596 Handle(Prs3d_LineAspect) anEmptyAsp;
597 myDrawer->SetLineAspect (anEmptyAsp);
598 myDrawer->SetWireAspect (anEmptyAsp);
599 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
600 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
601 myDrawer->SetSeenLineAspect (anEmptyAsp);
605 Quantity_Color aColor = Quantity_NOC_YELLOW;
606 if (myDrawer->HasLink())
608 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
610 myDrawer->LineAspect()->SetColor (aColor);
611 aColor = Quantity_NOC_RED;
612 if (myDrawer->HasLink())
614 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
616 myDrawer->WireAspect()->SetColor (aColor);
617 aColor = Quantity_NOC_GREEN;
618 if (myDrawer->HasLink())
620 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
622 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
623 aColor = Quantity_NOC_YELLOW;
624 if (myDrawer->HasLink())
626 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
628 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
629 if (myDrawer->HasLink())
631 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
633 myDrawer->SeenLineAspect()->SetColor (aColor);
639 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
640 Graphic3d_MaterialAspect mat = aDefaultMat;
641 if (HasMaterial() || myDrawer->HasLink())
643 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
647 Quantity_Color aColor = aDefaultMat.AmbientColor();
648 if (myDrawer->HasLink())
650 aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
652 mat.SetColor (aColor);
656 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
657 mat.SetTransparency (aTransp);
659 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
663 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
665 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
667 // modify shading presentation without re-computation
668 const PrsMgr_Presentations& aPrsList = Presentations();
669 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
670 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
671 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
673 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
674 if (aPrsModed.Mode() != AIS_Shaded)
679 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
681 aPrs->SetPrimitivesAspect (anAreaAsp);
682 aPrs->SetPrimitivesAspect (aLineAsp);
684 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
686 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
688 // Check if aspect of given type is set for the group,
689 // because setting aspect for group with no already set aspect
690 // can lead to loss of presentation data
691 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
693 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
695 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
697 aGroup->SetGroupPrimitivesAspect (aLineAsp);
702 LoadRecomputable (AIS_WireFrame);
703 LoadRecomputable (2);
706 //=======================================================================
707 //function : setWidth
709 //=======================================================================
711 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
712 const Standard_Real theLineWidth) const
714 if (!theDrawer->HasOwnLineAspect())
716 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
717 if (theDrawer->HasLink())
719 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
722 if (!theDrawer->HasOwnWireAspect())
724 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
725 if (theDrawer->HasLink())
727 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
730 if (!theDrawer->HasOwnFreeBoundaryAspect())
732 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
733 if (theDrawer->HasLink())
735 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
738 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
740 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
741 if (theDrawer->HasLink())
743 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
746 if (!theDrawer->HasOwnSeenLineAspect())
748 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
749 if (theDrawer->HasLink())
751 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
756 theDrawer->LineAspect()->SetWidth (theLineWidth);
757 theDrawer->WireAspect()->SetWidth (theLineWidth);
758 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
759 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
760 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
763 //=======================================================================
764 //function : SetWidth
766 //=======================================================================
768 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
770 setWidth (myDrawer, theLineWidth);
771 myOwnWidth = theLineWidth;
772 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
773 LoadRecomputable (2); // and the bounding box...
776 //=======================================================================
777 //function : UnsetWidth
779 //=======================================================================
781 void AIS_Shape::UnsetWidth()
783 if (myOwnWidth == 0.0)
785 myToRecomputeModes.Clear();
791 Handle(Prs3d_LineAspect) anEmptyAsp;
795 myDrawer->SetLineAspect (anEmptyAsp);
796 myDrawer->SetWireAspect (anEmptyAsp);
797 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
798 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
799 myDrawer->SetSeenLineAspect (anEmptyAsp);
803 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
804 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
805 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
806 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
807 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
808 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
809 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
810 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
811 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
812 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
814 LoadRecomputable (AIS_WireFrame);
817 //=======================================================================
818 //function : setMaterial
820 //=======================================================================
822 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
823 const Graphic3d_MaterialAspect& theMaterial,
824 const Standard_Boolean theToKeepColor,
825 const Standard_Boolean theToKeepTransp) const
827 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
828 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
829 if (!theDrawer->HasOwnShadingAspect())
831 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
832 if (theDrawer->HasLink())
834 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
837 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
841 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
845 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
849 //=======================================================================
850 //function : SetMaterial
852 //=======================================================================
854 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
856 SetMaterial(Graphic3d_MaterialAspect(aMat));
859 //=======================================================================
860 //function : SetMaterial
862 //=======================================================================
864 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
866 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
867 hasOwnMaterial = Standard_True;
869 // modify shading presentation without re-computation
870 const PrsMgr_Presentations& aPrsList = Presentations();
871 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
872 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
874 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
875 if (aPrsModed.Mode() != AIS_Shaded)
880 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
881 aPrs->SetPrimitivesAspect (anAreaAsp);
882 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
884 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
886 // Check if aspect of given type is set for the group,
887 // because setting aspect for group with no already set aspect
888 // can lead to loss of presentation data
889 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
891 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
896 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
897 myToRecomputeModes.Clear();
900 //=======================================================================
901 //function : UnsetMaterial
903 //=======================================================================
905 void AIS_Shape::UnsetMaterial()
915 if(myDrawer->HasLink())
917 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
918 myCurrentFacingModel);
922 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
923 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
928 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
930 hasOwnMaterial = Standard_False;
932 // modify shading presentation without re-computation
933 const PrsMgr_Presentations& aPrsList = Presentations();
934 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
935 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
937 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
938 if (aPrsModed.Mode() != AIS_Shaded)
943 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
944 aPrs->SetPrimitivesAspect (anAreaAsp);
945 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
947 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
948 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
950 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
955 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
956 myToRecomputeModes.Clear();
959 //=======================================================================
960 //function : setTransparency
962 //=======================================================================
964 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
965 const Standard_Real theValue) const
967 if (!theDrawer->HasOwnShadingAspect())
969 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
970 if (theDrawer->HasLink())
972 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
976 // override transparency
977 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
980 //=======================================================================
981 //function : SetTransparency
983 //=======================================================================
985 void AIS_Shape::SetTransparency (const Standard_Real theValue)
987 setTransparency (myDrawer, theValue);
988 myTransparency = theValue;
990 // modify shading presentation without re-computation
991 const PrsMgr_Presentations& aPrsList = Presentations();
992 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
993 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
995 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
996 if (aPrsModed.Mode() != AIS_Shaded)
1001 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1002 aPrs->SetPrimitivesAspect (anAreaAsp);
1003 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
1004 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1006 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1007 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1009 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1014 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
1015 myToRecomputeModes.Clear();
1018 //=======================================================================
1019 //function : UnsetTransparency
1021 //=======================================================================
1023 void AIS_Shape::UnsetTransparency()
1025 myTransparency = 0.0;
1026 if (!myDrawer->HasOwnShadingAspect())
1030 else if (HasColor() || HasMaterial())
1032 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
1036 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
1039 // modify shading presentation without re-computation
1040 const PrsMgr_Presentations& aPrsList = Presentations();
1041 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1042 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1044 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1045 if (aPrsModed.Mode() != AIS_Shaded)
1050 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1051 aPrs->SetPrimitivesAspect (anAreaAsp);
1052 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1054 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1055 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1057 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1060 aPrs->ResetDisplayPriority();
1063 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1064 myToRecomputeModes.Clear();
1067 //=======================================================================
1068 //function : LoadRecomputable
1070 //=======================================================================
1072 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1074 myRecomputeEveryPrs = Standard_False;
1075 if(!IsInList(myToRecomputeModes,TheMode))
1076 myToRecomputeModes.Append(TheMode);
1079 //=======================================================================
1080 //function : BoundingBox
1082 //=======================================================================
1084 const Bnd_Box& AIS_Shape::BoundingBox()
1086 if (myshape.ShapeType() == TopAbs_COMPOUND) {
1087 TopoDS_Iterator anExplor (myshape);
1089 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1096 BRepBndLib::AddClose(myshape, myBB);
1097 myCompBB = Standard_False;
1104 //=======================================================================
1105 //function : SetOwnDeviationCoefficient
1106 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1107 // returns Standard_True if it change
1108 //=======================================================================
1110 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1112 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1113 if(itSet) myDrawer->SetDeviationCoefficient();
1117 //=======================================================================
1118 //function : SetHLROwnDeviationCoefficient
1119 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1120 // returns Standard_True if it change
1121 //=======================================================================
1123 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1125 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1126 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1131 //=======================================================================
1132 //function : SetOwnDeviationAngle
1133 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1134 // returns Standard_True if it change
1135 //=======================================================================
1137 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1139 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1140 if(itSet) myDrawer->SetDeviationAngle();
1145 //=======================================================================
1146 //function : SetOwnHLRDeviationAngle
1147 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1148 // returns Standard_True if it change
1149 //=======================================================================
1151 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1153 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1154 if(itSet) myDrawer->SetHLRAngle();
1159 //=======================================================================
1160 //function : SetOwnDeviationCoefficient
1162 //=======================================================================
1164 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1166 myDrawer->SetDeviationCoefficient( aCoefficient );
1167 SetToUpdate(0) ; // WireFrame
1168 SetToUpdate(1) ; // Shadding
1171 //=======================================================================
1172 //function : SetOwnHLRDeviationCoefficient
1174 //=======================================================================
1176 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1178 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1182 //=======================================================================
1183 //function : SetOwnDeviationAngle
1185 //=======================================================================
1187 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1190 myDrawer->SetDeviationAngle(anAngle );
1191 SetToUpdate(0) ; // WireFrame
1193 //=======================================================================
1194 //function : SetOwnDeviationAngle
1196 //=======================================================================
1198 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1200 Standard_Real OutAngl,OutDefl;
1201 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1202 SetOwnDeviationAngle(anAngle) ;
1203 SetOwnDeviationCoefficient(OutDefl) ;
1204 myInitAng = anAngle;
1209 //=======================================================================
1210 //function : UserAngle
1212 //=======================================================================
1214 Standard_Real AIS_Shape::UserAngle() const
1216 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1220 //=======================================================================
1221 //function : SetHLRAngleAndDeviation
1223 //=======================================================================
1225 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1227 Standard_Real OutAngl,OutDefl;
1228 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1229 SetOwnHLRDeviationAngle( OutAngl );
1230 SetOwnHLRDeviationCoefficient(OutDefl);
1233 //=======================================================================
1234 //function : SetOwnHLRDeviationAngle
1236 //=======================================================================
1238 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1240 myDrawer->SetHLRAngle( anAngle );
1244 //=======================================================================
1245 //function : OwnDeviationCoefficient
1247 //=======================================================================
1249 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1250 Standard_Real & aPreviousCoefficient ) const
1252 aCoefficient = myDrawer->DeviationCoefficient();
1253 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1254 return myDrawer->HasOwnDeviationCoefficient() ;
1257 //=======================================================================
1258 //function : OwnHLRDeviationCoefficient
1260 //=======================================================================
1262 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1263 Standard_Real & aPreviousCoefficient ) const
1265 aCoefficient = myDrawer->HLRDeviationCoefficient();
1266 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1267 return myDrawer->HasOwnHLRDeviationCoefficient();
1271 //=======================================================================
1272 //function : OwnDeviationAngle
1274 //=======================================================================
1276 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1277 Standard_Real & aPreviousAngle ) const
1279 anAngle = myDrawer->DeviationAngle();
1280 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1281 return myDrawer->HasOwnDeviationAngle();
1284 //=======================================================================
1285 //function : OwnHLRDeviationAngle
1287 //=======================================================================
1289 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1290 Standard_Real & aPreviousAngle ) const
1292 anAngle = myDrawer->HLRAngle();
1293 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1294 return myDrawer->HasOwnHLRDeviationAngle();