1 // Created on: 1996-12-20
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <AIS_Shape.hxx>
19 #include <AIS_GraphicTool.hxx>
20 #include <AIS_InteractiveContext.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 void AIS_Shape::Color( Quantity_Color& aColor ) const {
415 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
418 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
419 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
422 Standard_Real AIS_Shape::Transparency() const {
423 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
426 //=======================================================================
427 //function : setColor
429 //=======================================================================
431 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
432 const Quantity_Color& theColor) const
434 if (!theDrawer->HasOwnShadingAspect())
436 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
437 if (theDrawer->HasLink())
439 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
442 if (!theDrawer->HasOwnLineAspect())
444 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
445 if (theDrawer->HasLink())
447 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
450 if (!theDrawer->HasOwnWireAspect())
452 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
453 if (theDrawer->HasLink())
455 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
458 if (!theDrawer->HasOwnPointAspect())
460 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
461 if (theDrawer->HasLink())
463 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
466 if (!theDrawer->HasOwnFreeBoundaryAspect())
468 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
469 if (theDrawer->HasLink())
471 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
474 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
476 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
477 if (theDrawer->HasLink())
479 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
482 if (!theDrawer->HasOwnSeenLineAspect())
484 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
485 if (theDrawer->HasLink())
487 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
492 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
493 theDrawer->LineAspect()->SetColor (theColor);
494 theDrawer->WireAspect()->SetColor (theColor);
495 theDrawer->PointAspect()->SetColor (theColor);
496 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
497 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
498 theDrawer->SeenLineAspect()->SetColor (theColor);
501 //=======================================================================
502 //function : SetColor
504 //=======================================================================
506 void AIS_Shape::SetColor (const Quantity_Color& theColor)
508 setColor (myDrawer, theColor);
509 myDrawer->SetColor (theColor);
510 hasOwnColor = Standard_True;
512 // modify shading presentation without re-computation
513 const PrsMgr_Presentations& aPrsList = Presentations();
514 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
515 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
516 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
517 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
519 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
520 if (aPrsModed.Mode() != AIS_Shaded)
525 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
526 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
528 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
530 // Check if aspect of given type is set for the group,
531 // because setting aspect for group with no already set aspect
532 // can lead to loss of presentation data
533 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
535 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
537 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
539 aGroup->SetGroupPrimitivesAspect (aLineAspect);
541 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
543 aGroup->SetGroupPrimitivesAspect (aPointAspect);
548 LoadRecomputable (AIS_WireFrame);
549 LoadRecomputable (2);
552 //=======================================================================
553 //function : UnsetColor
555 //=======================================================================
557 void AIS_Shape::UnsetColor()
561 myToRecomputeModes.Clear();
564 hasOwnColor = Standard_False;
568 Handle(Prs3d_LineAspect) anEmptyAsp;
569 myDrawer->SetLineAspect (anEmptyAsp);
570 myDrawer->SetWireAspect (anEmptyAsp);
571 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
572 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
573 myDrawer->SetSeenLineAspect (anEmptyAsp);
577 Quantity_Color aColor = Quantity_NOC_YELLOW;
578 if (myDrawer->HasLink())
580 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
582 myDrawer->LineAspect()->SetColor (aColor);
583 aColor = Quantity_NOC_RED;
584 if (myDrawer->HasLink())
586 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
588 myDrawer->WireAspect()->SetColor (aColor);
589 aColor = Quantity_NOC_GREEN;
590 if (myDrawer->HasLink())
592 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
594 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
595 aColor = Quantity_NOC_YELLOW;
596 if (myDrawer->HasLink())
598 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
600 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
601 if (myDrawer->HasLink())
603 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
605 myDrawer->SeenLineAspect()->SetColor (aColor);
611 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
612 Graphic3d_MaterialAspect mat = aDefaultMat;
613 if (HasMaterial() || myDrawer->HasLink())
615 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
619 Quantity_Color aColor = aDefaultMat.AmbientColor();
620 if (myDrawer->HasLink())
622 aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
624 mat.SetColor (aColor);
628 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
629 mat.SetTransparency (Standard_ShortReal(aTransp));
631 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
635 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
637 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
639 // modify shading presentation without re-computation
640 const PrsMgr_Presentations& aPrsList = Presentations();
641 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
642 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
643 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
645 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
646 if (aPrsModed.Mode() != AIS_Shaded)
651 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
652 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
654 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
656 // Check if aspect of given type is set for the group,
657 // because setting aspect for group with no already set aspect
658 // can lead to loss of presentation data
659 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
661 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
663 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
665 aGroup->SetGroupPrimitivesAspect (aLineAsp);
670 LoadRecomputable (AIS_WireFrame);
671 LoadRecomputable (2);
674 //=======================================================================
675 //function : setWidth
677 //=======================================================================
679 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
680 const Standard_Real theLineWidth) const
682 if (!theDrawer->HasOwnLineAspect())
684 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
685 if (theDrawer->HasLink())
687 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
690 if (!theDrawer->HasOwnWireAspect())
692 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
693 if (theDrawer->HasLink())
695 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
698 if (!theDrawer->HasOwnFreeBoundaryAspect())
700 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
701 if (theDrawer->HasLink())
703 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
706 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
708 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
709 if (theDrawer->HasLink())
711 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
714 if (!theDrawer->HasOwnSeenLineAspect())
716 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
717 if (theDrawer->HasLink())
719 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
724 theDrawer->LineAspect()->SetWidth (theLineWidth);
725 theDrawer->WireAspect()->SetWidth (theLineWidth);
726 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
727 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
728 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
731 //=======================================================================
732 //function : SetWidth
734 //=======================================================================
736 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
738 setWidth (myDrawer, theLineWidth);
739 myOwnWidth = theLineWidth;
740 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
741 LoadRecomputable (2); // and the bounding box...
744 //=======================================================================
745 //function : UnsetWidth
747 //=======================================================================
749 void AIS_Shape::UnsetWidth()
751 if (myOwnWidth == 0.0)
753 myToRecomputeModes.Clear();
759 Handle(Prs3d_LineAspect) anEmptyAsp;
763 myDrawer->SetLineAspect (anEmptyAsp);
764 myDrawer->SetWireAspect (anEmptyAsp);
765 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
766 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
767 myDrawer->SetSeenLineAspect (anEmptyAsp);
771 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
772 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
773 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
774 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
775 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
776 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
777 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
778 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
779 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
780 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
782 LoadRecomputable (AIS_WireFrame);
785 //=======================================================================
786 //function : setMaterial
788 //=======================================================================
790 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
791 const Graphic3d_MaterialAspect& theMaterial,
792 const Standard_Boolean theToKeepColor,
793 const Standard_Boolean theToKeepTransp) const
795 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
796 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
797 if (!theDrawer->HasOwnShadingAspect())
799 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
800 if (theDrawer->HasLink())
802 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
805 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
809 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
813 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
817 //=======================================================================
818 //function : SetMaterial
820 //=======================================================================
822 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
824 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
825 hasOwnMaterial = Standard_True;
827 // modify shading presentation without re-computation
828 const PrsMgr_Presentations& aPrsList = Presentations();
829 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
830 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
832 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
833 if (aPrsModed.Mode() != AIS_Shaded)
838 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
839 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
841 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
843 // Check if aspect of given type is set for the group,
844 // because setting aspect for group with no already set aspect
845 // can lead to loss of presentation data
846 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
848 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
853 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
854 myToRecomputeModes.Clear();
857 //=======================================================================
858 //function : UnsetMaterial
860 //=======================================================================
862 void AIS_Shape::UnsetMaterial()
872 if(myDrawer->HasLink())
874 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
875 myCurrentFacingModel);
879 myDrawer->ShadingAspect()->SetColor (myDrawer->Color(), myCurrentFacingModel);
880 myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
885 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
887 hasOwnMaterial = Standard_False;
889 // modify shading presentation without re-computation
890 const PrsMgr_Presentations& aPrsList = Presentations();
891 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
892 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
894 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
895 if (aPrsModed.Mode() != AIS_Shaded)
900 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
901 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
903 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
904 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
906 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
911 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
912 myToRecomputeModes.Clear();
915 //=======================================================================
916 //function : setTransparency
918 //=======================================================================
920 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
921 const Standard_Real theValue) const
923 if (!theDrawer->HasOwnShadingAspect())
925 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
926 if (theDrawer->HasLink())
928 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
932 // override transparency
933 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
936 //=======================================================================
937 //function : SetTransparency
939 //=======================================================================
941 void AIS_Shape::SetTransparency (const Standard_Real theValue)
943 setTransparency (myDrawer, theValue);
944 myDrawer->SetTransparency ((Standard_ShortReal )theValue);
946 // modify shading presentation without re-computation
947 const PrsMgr_Presentations& aPrsList = Presentations();
948 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
949 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
951 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
952 if (aPrsModed.Mode() != AIS_Shaded)
957 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
958 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
960 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
961 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
963 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
968 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
969 myToRecomputeModes.Clear();
972 //=======================================================================
973 //function : UnsetTransparency
975 //=======================================================================
977 void AIS_Shape::UnsetTransparency()
979 myDrawer->SetTransparency (0.0f);
980 if (!myDrawer->HasOwnShadingAspect())
984 else if (HasColor() || HasMaterial())
986 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
990 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
993 // modify shading presentation without re-computation
994 const PrsMgr_Presentations& aPrsList = Presentations();
995 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
996 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
998 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
999 if (aPrsModed.Mode() != AIS_Shaded)
1004 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1005 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1007 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1008 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1010 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1015 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1016 myToRecomputeModes.Clear();
1019 //=======================================================================
1020 //function : LoadRecomputable
1022 //=======================================================================
1024 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1026 myRecomputeEveryPrs = Standard_False;
1027 if(!IsInList(myToRecomputeModes,TheMode))
1028 myToRecomputeModes.Append(TheMode);
1031 //=======================================================================
1032 //function : BoundingBox
1034 //=======================================================================
1036 const Bnd_Box& AIS_Shape::BoundingBox()
1038 if (myshape.ShapeType() == TopAbs_COMPOUND) {
1039 TopoDS_Iterator anExplor (myshape);
1041 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1048 BRepBndLib::AddClose(myshape, myBB);
1049 myCompBB = Standard_False;
1056 //=======================================================================
1057 //function : SetOwnDeviationCoefficient
1058 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1059 // returns Standard_True if it change
1060 //=======================================================================
1062 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1064 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1065 if(itSet) myDrawer->SetDeviationCoefficient();
1069 //=======================================================================
1070 //function : SetHLROwnDeviationCoefficient
1071 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1072 // returns Standard_True if it change
1073 //=======================================================================
1075 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1077 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1078 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1083 //=======================================================================
1084 //function : SetOwnDeviationAngle
1085 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1086 // returns Standard_True if it change
1087 //=======================================================================
1089 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1091 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1092 if(itSet) myDrawer->SetDeviationAngle();
1097 //=======================================================================
1098 //function : SetOwnHLRDeviationAngle
1099 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1100 // returns Standard_True if it change
1101 //=======================================================================
1103 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1105 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1106 if(itSet) myDrawer->SetHLRAngle();
1111 //=======================================================================
1112 //function : SetOwnDeviationCoefficient
1114 //=======================================================================
1116 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1118 myDrawer->SetDeviationCoefficient( aCoefficient );
1119 SetToUpdate(0) ; // WireFrame
1120 SetToUpdate(1) ; // Shadding
1123 //=======================================================================
1124 //function : SetOwnHLRDeviationCoefficient
1126 //=======================================================================
1128 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1130 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1134 //=======================================================================
1135 //function : SetOwnDeviationAngle
1137 //=======================================================================
1139 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1142 myDrawer->SetDeviationAngle(anAngle );
1143 SetToUpdate(0) ; // WireFrame
1145 //=======================================================================
1146 //function : SetOwnDeviationAngle
1148 //=======================================================================
1150 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1152 Standard_Real OutAngl,OutDefl;
1153 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1154 SetOwnDeviationAngle(anAngle) ;
1155 SetOwnDeviationCoefficient(OutDefl) ;
1156 myInitAng = anAngle;
1161 //=======================================================================
1162 //function : UserAngle
1164 //=======================================================================
1166 Standard_Real AIS_Shape::UserAngle() const
1168 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1172 //=======================================================================
1173 //function : SetHLRAngleAndDeviation
1175 //=======================================================================
1177 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1179 Standard_Real OutAngl,OutDefl;
1180 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1181 SetOwnHLRDeviationAngle( OutAngl );
1182 SetOwnHLRDeviationCoefficient(OutDefl);
1185 //=======================================================================
1186 //function : SetOwnHLRDeviationAngle
1188 //=======================================================================
1190 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1192 myDrawer->SetHLRAngle( anAngle );
1196 //=======================================================================
1197 //function : OwnDeviationCoefficient
1199 //=======================================================================
1201 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1202 Standard_Real & aPreviousCoefficient ) const
1204 aCoefficient = myDrawer->DeviationCoefficient();
1205 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1206 return myDrawer->HasOwnDeviationCoefficient() ;
1209 //=======================================================================
1210 //function : OwnHLRDeviationCoefficient
1212 //=======================================================================
1214 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1215 Standard_Real & aPreviousCoefficient ) const
1217 aCoefficient = myDrawer->HLRDeviationCoefficient();
1218 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1219 return myDrawer->HasOwnHLRDeviationCoefficient();
1223 //=======================================================================
1224 //function : OwnDeviationAngle
1226 //=======================================================================
1228 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1229 Standard_Real & aPreviousAngle ) const
1231 anAngle = myDrawer->DeviationAngle();
1232 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1233 return myDrawer->HasOwnDeviationAngle();
1236 //=======================================================================
1237 //function : OwnHLRDeviationAngle
1239 //=======================================================================
1241 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1242 Standard_Real & aPreviousAngle ) const
1244 anAngle = myDrawer->HLRAngle();
1245 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1246 return myDrawer->HasOwnHLRDeviationAngle();