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),
96 //=======================================================================
99 //=======================================================================
100 AIS_KindOfInteractive AIS_Shape::Type() const
101 {return AIS_KOI_Shape;}
104 //=======================================================================
105 //function : Signature
107 //=======================================================================
108 Standard_Integer AIS_Shape::Signature() const
111 //=======================================================================
112 //function : AcceptShapeDecomposition
114 //=======================================================================
115 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
116 {return Standard_True;}
118 //=======================================================================
121 //=======================================================================
122 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
123 const Handle(Prs3d_Presentation)& aPrs,
124 const Standard_Integer theMode)
126 if(myshape.IsNull()) return;
128 // wire,edge,vertex -> pas de HLR + priorite display superieure
129 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
130 if(TheType>4 && TheType<8) {
131 aPrs->SetVisual(Graphic3d_TOS_ALL);
132 aPrs->SetDisplayPriority(TheType+2);
134 // Shape vide -> Assemblage vide.
135 if (myshape.ShapeType() == TopAbs_COMPOUND) {
136 TopoDS_Iterator anExplor (myshape);
138 if (!anExplor.More()) {
145 aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
152 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
156 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
158 catch (Standard_Failure)
161 cout << "AIS_Shape::Compute() failed" << endl;
162 cout << "a Shape should be incorrect : No Compute can be maked on it " << endl;
164 // presentation of the bounding box is calculated
165 // Compute(aPresentationManager,aPrs,2);
171 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
172 if ((Standard_Integer) myshape.ShapeType() > 4)
174 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
180 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
187 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer);
189 catch (Standard_Failure)
192 cout << "AIS_Shape::Compute() in ShadingMode failed" << endl;
194 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
198 Standard_Real aTransparency = Transparency() ;
199 if (aTransparency > 0.0)
201 SetTransparency (aTransparency);
211 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
215 StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
220 // Recompute hidden line presentation (if necessary).
224 //=======================================================================
226 //purpose : Hidden Line Removal
227 //=======================================================================
228 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
229 const Handle(Prs3d_Presentation)& aPresentation)
231 Compute(aProjector,aPresentation,myshape);
234 //=======================================================================
237 //=======================================================================
239 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
240 const Handle(Geom_Transformation)& TheTrsf,
241 const Handle(Prs3d_Presentation)& aPresentation)
243 const TopLoc_Location& loc = myshape.Location();
244 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
245 Compute(aProjector,aPresentation,shbis);
248 //=======================================================================
251 //=======================================================================
253 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
254 const Handle(Prs3d_Presentation)& aPresentation,
255 const TopoDS_Shape& SH)
257 if (SH.ShapeType() == TopAbs_COMPOUND) {
258 TopoDS_Iterator anExplor (SH);
260 if (!anExplor.More()) // Shape vide -> Assemblage vide.
264 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
265 if (defdrawer->DrawHiddenLine())
266 {myDrawer->EnableDrawHiddenLine();}
267 else {myDrawer->DisableDrawHiddenLine();}
269 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
270 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
272 if (myDrawer->IsAutoTriangulation())
274 // coefficients for calculation
275 Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff;
276 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle);
277 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff);
278 if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
279 ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient))
281 BRepTools::Clean(SH);
288 switch (TypeOfHLR()) {
290 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
292 case Prs3d_TOH_PolyAlgo:
294 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
298 catch (Standard_Failure) {
300 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
302 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
306 defdrawer->SetTypeOfDeflection (prevdef);
309 //=======================================================================
310 //function : SelectionType
311 //purpose : gives the type according to the Index of Selection Mode
312 //=======================================================================
314 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
318 return TopAbs_VERTEX;
330 return TopAbs_COMPSOLID;
332 return TopAbs_COMPOUND;
339 //=======================================================================
340 //function : SelectionType
341 //purpose : gives the SelectionMode according to the Type od Decomposition...
342 //=======================================================================
343 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
358 case TopAbs_COMPSOLID:
360 case TopAbs_COMPOUND:
369 //=======================================================================
370 //function : ComputeSelection
372 //=======================================================================
374 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
375 const Standard_Integer aMode)
377 if(myshape.IsNull()) return;
378 if (myshape.ShapeType() == TopAbs_COMPOUND) {
379 TopoDS_Iterator anExplor (myshape);
381 if (!anExplor.More()) // empty Shape -> empty Assembly.
385 TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
386 TopoDS_Shape shape = myshape;
388 // POP protection against crash in low layers
390 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
393 StdSelect_BRepSelectionTool::Load(aSelection,
398 myDrawer->HLRAngle(),
399 myDrawer->IsAutoTriangulation());
400 } catch ( Standard_Failure ) {
401 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
404 Bnd_Box B = BoundingBox();
405 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
406 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
407 aSelection->Add(aSensitiveBox);
411 // insert the drawer in the BrepOwners for hilight...
412 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
415 Quantity_NameOfColor AIS_Shape::Color() const {
416 Quantity_Color aColor;
418 return aColor.Name();
421 void AIS_Shape::Color( Quantity_Color& aColor ) const {
422 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
425 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
426 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
429 Standard_Real AIS_Shape::Transparency() const {
430 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
433 //=======================================================================
434 //function : SetColor
436 //=======================================================================
438 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
440 SetColor(Quantity_Color(aCol));
443 //=======================================================================
444 //function : setColor
446 //=======================================================================
448 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
449 const Quantity_Color& theColor) const
451 if (!theDrawer->HasOwnShadingAspect())
453 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
454 if (theDrawer->HasLink())
456 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
459 if (!theDrawer->HasOwnLineAspect())
461 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
462 if (theDrawer->HasLink())
464 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
467 if (!theDrawer->HasOwnWireAspect())
469 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
470 if (theDrawer->HasLink())
472 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
475 if (!theDrawer->HasOwnPointAspect())
477 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
478 if (theDrawer->HasLink())
480 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
483 if (!theDrawer->HasOwnFreeBoundaryAspect())
485 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
486 if (theDrawer->HasLink())
488 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
491 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
493 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
494 if (theDrawer->HasLink())
496 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
499 if (!theDrawer->HasOwnSeenLineAspect())
501 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
502 if (theDrawer->HasLink())
504 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
509 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
510 theDrawer->LineAspect()->SetColor (theColor);
511 theDrawer->WireAspect()->SetColor (theColor);
512 theDrawer->PointAspect()->SetColor (theColor);
513 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
514 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
515 theDrawer->SeenLineAspect()->SetColor (theColor);
518 //=======================================================================
519 //function : SetColor
521 //=======================================================================
523 void AIS_Shape::SetColor (const Quantity_Color& theColor)
525 setColor (myDrawer, theColor);
526 myOwnColor = theColor;
527 hasOwnColor = Standard_True;
529 // modify shading presentation without re-computation
530 const PrsMgr_Presentations& aPrsList = Presentations();
531 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
532 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
533 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
534 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
536 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
537 if (aPrsModed.Mode() != AIS_Shaded)
542 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
543 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
545 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
547 // Check if aspect of given type is set for the group,
548 // because setting aspect for group with no already set aspect
549 // can lead to loss of presentation data
550 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
552 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
554 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
556 aGroup->SetGroupPrimitivesAspect (aLineAspect);
558 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
560 aGroup->SetGroupPrimitivesAspect (aPointAspect);
565 LoadRecomputable (AIS_WireFrame);
566 LoadRecomputable (2);
569 //=======================================================================
570 //function : UnsetColor
572 //=======================================================================
574 void AIS_Shape::UnsetColor()
578 myToRecomputeModes.Clear();
581 hasOwnColor = Standard_False;
585 Handle(Prs3d_LineAspect) anEmptyAsp;
586 myDrawer->SetLineAspect (anEmptyAsp);
587 myDrawer->SetWireAspect (anEmptyAsp);
588 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
589 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
590 myDrawer->SetSeenLineAspect (anEmptyAsp);
594 Quantity_Color aColor = Quantity_NOC_YELLOW;
595 if (myDrawer->HasLink())
597 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
599 myDrawer->LineAspect()->SetColor (aColor);
600 aColor = Quantity_NOC_RED;
601 if (myDrawer->HasLink())
603 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
605 myDrawer->WireAspect()->SetColor (aColor);
606 aColor = Quantity_NOC_GREEN;
607 if (myDrawer->HasLink())
609 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
611 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
612 aColor = Quantity_NOC_YELLOW;
613 if (myDrawer->HasLink())
615 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
617 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
618 if (myDrawer->HasLink())
620 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
622 myDrawer->SeenLineAspect()->SetColor (aColor);
628 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
629 Graphic3d_MaterialAspect mat = aDefaultMat;
630 if (HasMaterial() || myDrawer->HasLink())
632 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
636 Quantity_Color aColor = aDefaultMat.AmbientColor();
637 if (myDrawer->HasLink())
639 aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
641 mat.SetColor (aColor);
645 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
646 mat.SetTransparency (aTransp);
648 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
652 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
654 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
656 // modify shading presentation without re-computation
657 const PrsMgr_Presentations& aPrsList = Presentations();
658 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
659 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
660 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
662 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
663 if (aPrsModed.Mode() != AIS_Shaded)
668 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
669 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
671 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
673 // Check if aspect of given type is set for the group,
674 // because setting aspect for group with no already set aspect
675 // can lead to loss of presentation data
676 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
678 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
680 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
682 aGroup->SetGroupPrimitivesAspect (aLineAsp);
687 LoadRecomputable (AIS_WireFrame);
688 LoadRecomputable (2);
691 //=======================================================================
692 //function : setWidth
694 //=======================================================================
696 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
697 const Standard_Real theLineWidth) const
699 if (!theDrawer->HasOwnLineAspect())
701 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
702 if (theDrawer->HasLink())
704 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
707 if (!theDrawer->HasOwnWireAspect())
709 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
710 if (theDrawer->HasLink())
712 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
715 if (!theDrawer->HasOwnFreeBoundaryAspect())
717 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
718 if (theDrawer->HasLink())
720 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
723 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
725 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
726 if (theDrawer->HasLink())
728 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
731 if (!theDrawer->HasOwnSeenLineAspect())
733 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
734 if (theDrawer->HasLink())
736 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
741 theDrawer->LineAspect()->SetWidth (theLineWidth);
742 theDrawer->WireAspect()->SetWidth (theLineWidth);
743 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
744 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
745 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
748 //=======================================================================
749 //function : SetWidth
751 //=======================================================================
753 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
755 setWidth (myDrawer, theLineWidth);
756 myOwnWidth = theLineWidth;
757 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
758 LoadRecomputable (2); // and the bounding box...
761 //=======================================================================
762 //function : UnsetWidth
764 //=======================================================================
766 void AIS_Shape::UnsetWidth()
768 if (myOwnWidth == 0.0)
770 myToRecomputeModes.Clear();
776 Handle(Prs3d_LineAspect) anEmptyAsp;
780 myDrawer->SetLineAspect (anEmptyAsp);
781 myDrawer->SetWireAspect (anEmptyAsp);
782 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
783 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
784 myDrawer->SetSeenLineAspect (anEmptyAsp);
788 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
789 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
790 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
791 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
792 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
793 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
794 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
795 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
796 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
797 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
799 LoadRecomputable (AIS_WireFrame);
802 //=======================================================================
803 //function : setMaterial
805 //=======================================================================
807 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
808 const Graphic3d_MaterialAspect& theMaterial,
809 const Standard_Boolean theToKeepColor,
810 const Standard_Boolean theToKeepTransp) const
812 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
813 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
814 if (!theDrawer->HasOwnShadingAspect())
816 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
817 if (theDrawer->HasLink())
819 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
822 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
826 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
830 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
834 //=======================================================================
835 //function : SetMaterial
837 //=======================================================================
839 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
841 SetMaterial(Graphic3d_MaterialAspect(aMat));
844 //=======================================================================
845 //function : SetMaterial
847 //=======================================================================
849 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
851 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
852 hasOwnMaterial = Standard_True;
854 // modify shading presentation without re-computation
855 const PrsMgr_Presentations& aPrsList = Presentations();
856 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
857 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
859 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
860 if (aPrsModed.Mode() != AIS_Shaded)
865 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
866 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
868 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
870 // Check if aspect of given type is set for the group,
871 // because setting aspect for group with no already set aspect
872 // can lead to loss of presentation data
873 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
875 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
880 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
881 myToRecomputeModes.Clear();
884 //=======================================================================
885 //function : UnsetMaterial
887 //=======================================================================
889 void AIS_Shape::UnsetMaterial()
899 if(myDrawer->HasLink())
901 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
902 myCurrentFacingModel);
906 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
907 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
912 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
914 hasOwnMaterial = Standard_False;
916 // modify shading presentation without re-computation
917 const PrsMgr_Presentations& aPrsList = Presentations();
918 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
919 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
921 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
922 if (aPrsModed.Mode() != AIS_Shaded)
927 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
928 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
930 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
931 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
933 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
938 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
939 myToRecomputeModes.Clear();
942 //=======================================================================
943 //function : setTransparency
945 //=======================================================================
947 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
948 const Standard_Real theValue) const
950 if (!theDrawer->HasOwnShadingAspect())
952 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
953 if (theDrawer->HasLink())
955 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
959 // override transparency
960 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
963 //=======================================================================
964 //function : SetTransparency
966 //=======================================================================
968 void AIS_Shape::SetTransparency (const Standard_Real theValue)
970 setTransparency (myDrawer, theValue);
971 myTransparency = theValue;
973 // modify shading presentation without re-computation
974 const PrsMgr_Presentations& aPrsList = Presentations();
975 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
976 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
978 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
979 if (aPrsModed.Mode() != AIS_Shaded)
984 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
985 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
986 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
988 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
989 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
991 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
996 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
997 myToRecomputeModes.Clear();
1000 //=======================================================================
1001 //function : UnsetTransparency
1003 //=======================================================================
1005 void AIS_Shape::UnsetTransparency()
1007 myTransparency = 0.0;
1008 if (!myDrawer->HasOwnShadingAspect())
1012 else if (HasColor() || HasMaterial())
1014 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
1018 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
1021 // modify shading presentation without re-computation
1022 const PrsMgr_Presentations& aPrsList = Presentations();
1023 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1024 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1026 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1027 if (aPrsModed.Mode() != AIS_Shaded)
1032 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1033 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1035 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1036 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1038 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1041 aPrs->ResetDisplayPriority();
1044 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1045 myToRecomputeModes.Clear();
1048 //=======================================================================
1049 //function : LoadRecomputable
1051 //=======================================================================
1053 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1055 myRecomputeEveryPrs = Standard_False;
1056 if(!IsInList(myToRecomputeModes,TheMode))
1057 myToRecomputeModes.Append(TheMode);
1060 //=======================================================================
1061 //function : BoundingBox
1063 //=======================================================================
1065 const Bnd_Box& AIS_Shape::BoundingBox()
1067 if (myshape.ShapeType() == TopAbs_COMPOUND) {
1068 TopoDS_Iterator anExplor (myshape);
1070 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1077 BRepBndLib::AddClose(myshape, myBB);
1078 myCompBB = Standard_False;
1085 //=======================================================================
1086 //function : SetOwnDeviationCoefficient
1087 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1088 // returns Standard_True if it change
1089 //=======================================================================
1091 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1093 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1094 if(itSet) myDrawer->SetDeviationCoefficient();
1098 //=======================================================================
1099 //function : SetHLROwnDeviationCoefficient
1100 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1101 // returns Standard_True if it change
1102 //=======================================================================
1104 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1106 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1107 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1112 //=======================================================================
1113 //function : SetOwnDeviationAngle
1114 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1115 // returns Standard_True if it change
1116 //=======================================================================
1118 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1120 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1121 if(itSet) myDrawer->SetDeviationAngle();
1126 //=======================================================================
1127 //function : SetOwnHLRDeviationAngle
1128 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1129 // returns Standard_True if it change
1130 //=======================================================================
1132 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1134 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1135 if(itSet) myDrawer->SetHLRAngle();
1140 //=======================================================================
1141 //function : SetOwnDeviationCoefficient
1143 //=======================================================================
1145 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1147 myDrawer->SetDeviationCoefficient( aCoefficient );
1148 SetToUpdate(0) ; // WireFrame
1149 SetToUpdate(1) ; // Shadding
1152 //=======================================================================
1153 //function : SetOwnHLRDeviationCoefficient
1155 //=======================================================================
1157 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1159 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1163 //=======================================================================
1164 //function : SetOwnDeviationAngle
1166 //=======================================================================
1168 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1171 myDrawer->SetDeviationAngle(anAngle );
1172 SetToUpdate(0) ; // WireFrame
1174 //=======================================================================
1175 //function : SetOwnDeviationAngle
1177 //=======================================================================
1179 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1181 Standard_Real OutAngl,OutDefl;
1182 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1183 SetOwnDeviationAngle(anAngle) ;
1184 SetOwnDeviationCoefficient(OutDefl) ;
1185 myInitAng = anAngle;
1190 //=======================================================================
1191 //function : UserAngle
1193 //=======================================================================
1195 Standard_Real AIS_Shape::UserAngle() const
1197 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1201 //=======================================================================
1202 //function : SetHLRAngleAndDeviation
1204 //=======================================================================
1206 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1208 Standard_Real OutAngl,OutDefl;
1209 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1210 SetOwnHLRDeviationAngle( OutAngl );
1211 SetOwnHLRDeviationCoefficient(OutDefl);
1214 //=======================================================================
1215 //function : SetOwnHLRDeviationAngle
1217 //=======================================================================
1219 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1221 myDrawer->SetHLRAngle( anAngle );
1225 //=======================================================================
1226 //function : OwnDeviationCoefficient
1228 //=======================================================================
1230 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1231 Standard_Real & aPreviousCoefficient ) const
1233 aCoefficient = myDrawer->DeviationCoefficient();
1234 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1235 return myDrawer->HasOwnDeviationCoefficient() ;
1238 //=======================================================================
1239 //function : OwnHLRDeviationCoefficient
1241 //=======================================================================
1243 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1244 Standard_Real & aPreviousCoefficient ) const
1246 aCoefficient = myDrawer->HLRDeviationCoefficient();
1247 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1248 return myDrawer->HasOwnHLRDeviationCoefficient();
1252 //=======================================================================
1253 //function : OwnDeviationAngle
1255 //=======================================================================
1257 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1258 Standard_Real & aPreviousAngle ) const
1260 anAngle = myDrawer->DeviationAngle();
1261 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1262 return myDrawer->HasOwnDeviationAngle();
1265 //=======================================================================
1266 //function : OwnHLRDeviationAngle
1268 //=======================================================================
1270 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1271 Standard_Real & aPreviousAngle ) const
1273 anAngle = myDrawer->HLRAngle();
1274 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1275 return myDrawer->HasOwnHLRDeviationAngle();