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),
95 //=======================================================================
98 //=======================================================================
99 AIS_KindOfInteractive AIS_Shape::Type() const
100 {return AIS_KOI_Shape;}
103 //=======================================================================
104 //function : Signature
106 //=======================================================================
107 Standard_Integer AIS_Shape::Signature() const
110 //=======================================================================
111 //function : AcceptShapeDecomposition
113 //=======================================================================
114 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
115 {return Standard_True;}
117 //=======================================================================
120 //=======================================================================
121 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
122 const Handle(Prs3d_Presentation)& aPrs,
123 const Standard_Integer theMode)
125 if(myshape.IsNull()) return;
127 // wire,edge,vertex -> pas de HLR + priorite display superieure
128 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
129 if(TheType>4 && TheType<8) {
130 aPrs->SetVisual(Graphic3d_TOS_ALL);
131 aPrs->SetDisplayPriority(TheType+2);
133 // Shape vide -> Assemblage vide.
134 if (myshape.ShapeType() == TopAbs_COMPOUND) {
135 TopoDS_Iterator anExplor (myshape);
137 if (!anExplor.More()) {
144 aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
151 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
155 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
157 catch (Standard_Failure)
160 cout << "AIS_Shape::Compute() failed" << endl;
161 cout << "a Shape should be incorrect : No Compute can be maked on it " << endl;
163 // presentation of the bounding box is calculated
164 // Compute(aPresentationManager,aPrs,2);
170 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
171 if ((Standard_Integer) myshape.ShapeType() > 4)
173 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
179 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
186 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer);
188 catch (Standard_Failure)
191 cout << "AIS_Shape::Compute() in ShadingMode failed" << endl;
193 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
197 Standard_Real aTransparency = Transparency() ;
198 if (aTransparency > 0.0)
200 SetTransparency (aTransparency);
210 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
214 StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
219 // Recompute hidden line presentation (if necessary).
223 //=======================================================================
225 //purpose : Hidden Line Removal
226 //=======================================================================
227 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
228 const Handle(Prs3d_Presentation)& aPresentation)
230 Compute(aProjector,aPresentation,myshape);
233 //=======================================================================
236 //=======================================================================
238 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
239 const Handle(Geom_Transformation)& TheTrsf,
240 const Handle(Prs3d_Presentation)& aPresentation)
242 const TopLoc_Location& loc = myshape.Location();
243 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
244 Compute(aProjector,aPresentation,shbis);
247 //=======================================================================
250 //=======================================================================
252 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
253 const Handle(Prs3d_Presentation)& aPresentation,
254 const TopoDS_Shape& SH)
256 if (SH.ShapeType() == TopAbs_COMPOUND) {
257 TopoDS_Iterator anExplor (SH);
259 if (!anExplor.More()) // Shape vide -> Assemblage vide.
263 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
264 if (defdrawer->DrawHiddenLine())
265 {myDrawer->EnableDrawHiddenLine();}
266 else {myDrawer->DisableDrawHiddenLine();}
268 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
269 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
271 if (myDrawer->IsAutoTriangulation())
273 // coefficients for calculation
274 Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff;
275 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle);
276 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff);
277 if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
278 ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient))
280 BRepTools::Clean(SH);
287 switch (TypeOfHLR()) {
289 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
291 case Prs3d_TOH_PolyAlgo:
293 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
297 catch (Standard_Failure) {
299 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
301 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
305 defdrawer->SetTypeOfDeflection (prevdef);
308 //=======================================================================
309 //function : SelectionType
310 //purpose : gives the type according to the Index of Selection Mode
311 //=======================================================================
313 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
317 return TopAbs_VERTEX;
329 return TopAbs_COMPSOLID;
331 return TopAbs_COMPOUND;
338 //=======================================================================
339 //function : SelectionType
340 //purpose : gives the SelectionMode according to the Type od Decomposition...
341 //=======================================================================
342 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
357 case TopAbs_COMPSOLID:
359 case TopAbs_COMPOUND:
368 //=======================================================================
369 //function : ComputeSelection
371 //=======================================================================
373 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
374 const Standard_Integer aMode)
376 if(myshape.IsNull()) return;
377 if (myshape.ShapeType() == TopAbs_COMPOUND) {
378 TopoDS_Iterator anExplor (myshape);
380 if (!anExplor.More()) // empty Shape -> empty Assembly.
384 TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
385 TopoDS_Shape shape = myshape;
387 // POP protection against crash in low layers
389 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
392 StdSelect_BRepSelectionTool::Load(aSelection,
397 myDrawer->HLRAngle(),
398 myDrawer->IsAutoTriangulation());
399 } catch ( Standard_Failure ) {
400 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
403 Bnd_Box B = BoundingBox();
404 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
405 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
406 aSelection->Add(aSensitiveBox);
410 // insert the drawer in the BrepOwners for hilight...
411 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
414 Quantity_NameOfColor AIS_Shape::Color() const {
415 Quantity_Color aColor;
417 return aColor.Name();
420 void AIS_Shape::Color( Quantity_Color& aColor ) const {
421 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
424 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
425 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
428 Standard_Real AIS_Shape::Transparency() const {
429 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
432 //=======================================================================
433 //function : SetColor
435 //=======================================================================
437 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
439 SetColor(Quantity_Color(aCol));
442 //=======================================================================
443 //function : setColor
445 //=======================================================================
447 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
448 const Quantity_Color& theColor) const
450 if (!theDrawer->HasOwnShadingAspect())
452 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
453 if (theDrawer->HasLink())
455 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
458 if (!theDrawer->HasOwnLineAspect())
460 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
461 if (theDrawer->HasLink())
463 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
466 if (!theDrawer->HasOwnWireAspect())
468 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
469 if (theDrawer->HasLink())
471 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
474 if (!theDrawer->HasOwnPointAspect())
476 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
477 if (theDrawer->HasLink())
479 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
482 if (!theDrawer->HasOwnFreeBoundaryAspect())
484 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
485 if (theDrawer->HasLink())
487 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
490 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
492 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
493 if (theDrawer->HasLink())
495 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
498 if (!theDrawer->HasOwnSeenLineAspect())
500 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
501 if (theDrawer->HasLink())
503 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
508 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
509 theDrawer->LineAspect()->SetColor (theColor);
510 theDrawer->WireAspect()->SetColor (theColor);
511 theDrawer->PointAspect()->SetColor (theColor);
512 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
513 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
514 theDrawer->SeenLineAspect()->SetColor (theColor);
517 //=======================================================================
518 //function : SetColor
520 //=======================================================================
522 void AIS_Shape::SetColor (const Quantity_Color& theColor)
524 setColor (myDrawer, theColor);
525 myDrawer->SetColor (theColor);
526 hasOwnColor = Standard_True;
528 // modify shading presentation without re-computation
529 const PrsMgr_Presentations& aPrsList = Presentations();
530 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
531 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
532 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
533 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
535 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
536 if (aPrsModed.Mode() != AIS_Shaded)
541 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
542 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
544 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
546 // Check if aspect of given type is set for the group,
547 // because setting aspect for group with no already set aspect
548 // can lead to loss of presentation data
549 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
551 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
553 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
555 aGroup->SetGroupPrimitivesAspect (aLineAspect);
557 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
559 aGroup->SetGroupPrimitivesAspect (aPointAspect);
564 LoadRecomputable (AIS_WireFrame);
565 LoadRecomputable (2);
568 //=======================================================================
569 //function : UnsetColor
571 //=======================================================================
573 void AIS_Shape::UnsetColor()
577 myToRecomputeModes.Clear();
580 hasOwnColor = Standard_False;
584 Handle(Prs3d_LineAspect) anEmptyAsp;
585 myDrawer->SetLineAspect (anEmptyAsp);
586 myDrawer->SetWireAspect (anEmptyAsp);
587 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
588 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
589 myDrawer->SetSeenLineAspect (anEmptyAsp);
593 Quantity_Color aColor = Quantity_NOC_YELLOW;
594 if (myDrawer->HasLink())
596 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
598 myDrawer->LineAspect()->SetColor (aColor);
599 aColor = Quantity_NOC_RED;
600 if (myDrawer->HasLink())
602 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
604 myDrawer->WireAspect()->SetColor (aColor);
605 aColor = Quantity_NOC_GREEN;
606 if (myDrawer->HasLink())
608 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
610 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
611 aColor = Quantity_NOC_YELLOW;
612 if (myDrawer->HasLink())
614 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
616 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
617 if (myDrawer->HasLink())
619 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
621 myDrawer->SeenLineAspect()->SetColor (aColor);
627 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
628 Graphic3d_MaterialAspect mat = aDefaultMat;
629 if (HasMaterial() || myDrawer->HasLink())
631 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
635 Quantity_Color aColor = aDefaultMat.AmbientColor();
636 if (myDrawer->HasLink())
638 aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
640 mat.SetColor (aColor);
644 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
645 mat.SetTransparency (aTransp);
647 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
651 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
653 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
655 // modify shading presentation without re-computation
656 const PrsMgr_Presentations& aPrsList = Presentations();
657 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
658 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
659 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
661 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
662 if (aPrsModed.Mode() != AIS_Shaded)
667 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
668 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
670 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
672 // Check if aspect of given type is set for the group,
673 // because setting aspect for group with no already set aspect
674 // can lead to loss of presentation data
675 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
677 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
679 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
681 aGroup->SetGroupPrimitivesAspect (aLineAsp);
686 LoadRecomputable (AIS_WireFrame);
687 LoadRecomputable (2);
690 //=======================================================================
691 //function : setWidth
693 //=======================================================================
695 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
696 const Standard_Real theLineWidth) const
698 if (!theDrawer->HasOwnLineAspect())
700 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
701 if (theDrawer->HasLink())
703 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
706 if (!theDrawer->HasOwnWireAspect())
708 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
709 if (theDrawer->HasLink())
711 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
714 if (!theDrawer->HasOwnFreeBoundaryAspect())
716 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
717 if (theDrawer->HasLink())
719 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
722 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
724 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
725 if (theDrawer->HasLink())
727 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
730 if (!theDrawer->HasOwnSeenLineAspect())
732 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
733 if (theDrawer->HasLink())
735 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
740 theDrawer->LineAspect()->SetWidth (theLineWidth);
741 theDrawer->WireAspect()->SetWidth (theLineWidth);
742 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
743 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
744 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
747 //=======================================================================
748 //function : SetWidth
750 //=======================================================================
752 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
754 setWidth (myDrawer, theLineWidth);
755 myOwnWidth = theLineWidth;
756 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
757 LoadRecomputable (2); // and the bounding box...
760 //=======================================================================
761 //function : UnsetWidth
763 //=======================================================================
765 void AIS_Shape::UnsetWidth()
767 if (myOwnWidth == 0.0)
769 myToRecomputeModes.Clear();
775 Handle(Prs3d_LineAspect) anEmptyAsp;
779 myDrawer->SetLineAspect (anEmptyAsp);
780 myDrawer->SetWireAspect (anEmptyAsp);
781 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
782 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
783 myDrawer->SetSeenLineAspect (anEmptyAsp);
787 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
788 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
789 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
790 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
791 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
792 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
793 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
794 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
795 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
796 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
798 LoadRecomputable (AIS_WireFrame);
801 //=======================================================================
802 //function : setMaterial
804 //=======================================================================
806 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
807 const Graphic3d_MaterialAspect& theMaterial,
808 const Standard_Boolean theToKeepColor,
809 const Standard_Boolean theToKeepTransp) const
811 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
812 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
813 if (!theDrawer->HasOwnShadingAspect())
815 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
816 if (theDrawer->HasLink())
818 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
821 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
825 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
829 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
833 //=======================================================================
834 //function : SetMaterial
836 //=======================================================================
838 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
840 SetMaterial(Graphic3d_MaterialAspect(aMat));
843 //=======================================================================
844 //function : SetMaterial
846 //=======================================================================
848 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
850 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
851 hasOwnMaterial = Standard_True;
853 // modify shading presentation without re-computation
854 const PrsMgr_Presentations& aPrsList = Presentations();
855 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
856 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
858 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
859 if (aPrsModed.Mode() != AIS_Shaded)
864 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
865 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
867 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
869 // Check if aspect of given type is set for the group,
870 // because setting aspect for group with no already set aspect
871 // can lead to loss of presentation data
872 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
874 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
879 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
880 myToRecomputeModes.Clear();
883 //=======================================================================
884 //function : UnsetMaterial
886 //=======================================================================
888 void AIS_Shape::UnsetMaterial()
898 if(myDrawer->HasLink())
900 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
901 myCurrentFacingModel);
905 myDrawer->ShadingAspect()->SetColor (myDrawer->Color(), myCurrentFacingModel);
906 myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
911 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
913 hasOwnMaterial = Standard_False;
915 // modify shading presentation without re-computation
916 const PrsMgr_Presentations& aPrsList = Presentations();
917 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
918 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
920 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
921 if (aPrsModed.Mode() != AIS_Shaded)
926 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
927 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
929 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
930 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
932 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
937 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
938 myToRecomputeModes.Clear();
941 //=======================================================================
942 //function : setTransparency
944 //=======================================================================
946 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
947 const Standard_Real theValue) const
949 if (!theDrawer->HasOwnShadingAspect())
951 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
952 if (theDrawer->HasLink())
954 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
958 // override transparency
959 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
962 //=======================================================================
963 //function : SetTransparency
965 //=======================================================================
967 void AIS_Shape::SetTransparency (const Standard_Real theValue)
969 setTransparency (myDrawer, theValue);
970 myDrawer->SetTransparency ((Standard_ShortReal )theValue);
972 // modify shading presentation without re-computation
973 const PrsMgr_Presentations& aPrsList = Presentations();
974 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
975 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
977 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
978 if (aPrsModed.Mode() != AIS_Shaded)
983 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
984 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
985 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
987 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
988 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
990 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
995 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
996 myToRecomputeModes.Clear();
999 //=======================================================================
1000 //function : UnsetTransparency
1002 //=======================================================================
1004 void AIS_Shape::UnsetTransparency()
1006 myDrawer->SetTransparency (0.0f);
1007 if (!myDrawer->HasOwnShadingAspect())
1011 else if (HasColor() || HasMaterial())
1013 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
1017 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
1020 // modify shading presentation without re-computation
1021 const PrsMgr_Presentations& aPrsList = Presentations();
1022 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1023 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1025 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1026 if (aPrsModed.Mode() != AIS_Shaded)
1031 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1032 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1034 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1035 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1037 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1040 aPrs->ResetDisplayPriority();
1043 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1044 myToRecomputeModes.Clear();
1047 //=======================================================================
1048 //function : LoadRecomputable
1050 //=======================================================================
1052 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1054 myRecomputeEveryPrs = Standard_False;
1055 if(!IsInList(myToRecomputeModes,TheMode))
1056 myToRecomputeModes.Append(TheMode);
1059 //=======================================================================
1060 //function : BoundingBox
1062 //=======================================================================
1064 const Bnd_Box& AIS_Shape::BoundingBox()
1066 if (myshape.ShapeType() == TopAbs_COMPOUND) {
1067 TopoDS_Iterator anExplor (myshape);
1069 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1076 BRepBndLib::AddClose(myshape, myBB);
1077 myCompBB = Standard_False;
1084 //=======================================================================
1085 //function : SetOwnDeviationCoefficient
1086 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1087 // returns Standard_True if it change
1088 //=======================================================================
1090 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1092 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1093 if(itSet) myDrawer->SetDeviationCoefficient();
1097 //=======================================================================
1098 //function : SetHLROwnDeviationCoefficient
1099 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1100 // returns Standard_True if it change
1101 //=======================================================================
1103 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1105 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1106 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1111 //=======================================================================
1112 //function : SetOwnDeviationAngle
1113 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1114 // returns Standard_True if it change
1115 //=======================================================================
1117 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1119 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1120 if(itSet) myDrawer->SetDeviationAngle();
1125 //=======================================================================
1126 //function : SetOwnHLRDeviationAngle
1127 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1128 // returns Standard_True if it change
1129 //=======================================================================
1131 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1133 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1134 if(itSet) myDrawer->SetHLRAngle();
1139 //=======================================================================
1140 //function : SetOwnDeviationCoefficient
1142 //=======================================================================
1144 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1146 myDrawer->SetDeviationCoefficient( aCoefficient );
1147 SetToUpdate(0) ; // WireFrame
1148 SetToUpdate(1) ; // Shadding
1151 //=======================================================================
1152 //function : SetOwnHLRDeviationCoefficient
1154 //=======================================================================
1156 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1158 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1162 //=======================================================================
1163 //function : SetOwnDeviationAngle
1165 //=======================================================================
1167 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1170 myDrawer->SetDeviationAngle(anAngle );
1171 SetToUpdate(0) ; // WireFrame
1173 //=======================================================================
1174 //function : SetOwnDeviationAngle
1176 //=======================================================================
1178 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1180 Standard_Real OutAngl,OutDefl;
1181 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1182 SetOwnDeviationAngle(anAngle) ;
1183 SetOwnDeviationCoefficient(OutDefl) ;
1184 myInitAng = anAngle;
1189 //=======================================================================
1190 //function : UserAngle
1192 //=======================================================================
1194 Standard_Real AIS_Shape::UserAngle() const
1196 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1200 //=======================================================================
1201 //function : SetHLRAngleAndDeviation
1203 //=======================================================================
1205 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1207 Standard_Real OutAngl,OutDefl;
1208 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1209 SetOwnHLRDeviationAngle( OutAngl );
1210 SetOwnHLRDeviationCoefficient(OutDefl);
1213 //=======================================================================
1214 //function : SetOwnHLRDeviationAngle
1216 //=======================================================================
1218 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1220 myDrawer->SetHLRAngle( anAngle );
1224 //=======================================================================
1225 //function : OwnDeviationCoefficient
1227 //=======================================================================
1229 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1230 Standard_Real & aPreviousCoefficient ) const
1232 aCoefficient = myDrawer->DeviationCoefficient();
1233 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1234 return myDrawer->HasOwnDeviationCoefficient() ;
1237 //=======================================================================
1238 //function : OwnHLRDeviationCoefficient
1240 //=======================================================================
1242 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1243 Standard_Real & aPreviousCoefficient ) const
1245 aCoefficient = myDrawer->HLRDeviationCoefficient();
1246 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1247 return myDrawer->HasOwnHLRDeviationCoefficient();
1251 //=======================================================================
1252 //function : OwnDeviationAngle
1254 //=======================================================================
1256 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1257 Standard_Real & aPreviousAngle ) const
1259 anAngle = myDrawer->DeviationAngle();
1260 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1261 return myDrawer->HasOwnDeviationAngle();
1264 //=======================================================================
1265 //function : OwnHLRDeviationAngle
1267 //=======================================================================
1269 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1270 Standard_Real & aPreviousAngle ) const
1272 anAngle = myDrawer->HLRAngle();
1273 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1274 return myDrawer->HasOwnHLRDeviationAngle();