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.ixx>
20 #include <Standard_ErrorHandler.hxx>
21 #include <OSD_Timer.hxx>
22 #include <TColStd_ListIteratorOfListOfInteger.hxx>
24 #include <Quantity_Color.hxx>
27 #include <Bnd_Box.hxx>
28 #include <BRep_Builder.hxx>
29 #include <BRepTools_ShapeSet.hxx>
30 #include <BRepTools.hxx>
31 #include <BRepBndLib.hxx>
33 #include <TopExp_Explorer.hxx>
35 #include <Aspect_TypeOfLine.hxx>
36 #include <Graphic3d_Structure.hxx>
37 #include <Graphic3d_Group.hxx>
38 #include <Graphic3d_AspectLine3d.hxx>
39 #include <Graphic3d_AspectText3d.hxx>
40 #include <Graphic3d_AspectMarker3d.hxx>
41 #include <Graphic3d_AspectFillArea3d.hxx>
42 #include <Graphic3d_ArrayOfPolylines.hxx>
43 #include <Graphic3d_MaterialAspect.hxx>
44 #include <Graphic3d_SequenceOfGroup.hxx>
47 #include <Prs3d_Presentation.hxx>
48 #include <Prs3d_Root.hxx>
49 #include <Prs3d_ShadingAspect.hxx>
50 #include <Prs3d_Drawer.hxx>
51 #include <Prs3d_IsoAspect.hxx>
53 #include <StdPrs_WFShape.hxx>
54 #include <StdPrs_WFDeflectionShape.hxx>
55 #include <StdPrs_ShadedShape.hxx>
56 #include <StdPrs_HLRShape.hxx>
57 #include <StdPrs_HLRPolyShape.hxx>
59 #include <PrsMgr_ModedPresentation.hxx>
61 #include <Select3D_SensitiveEntity.hxx>
62 #include <StdSelect.hxx>
63 #include <StdSelect_BRepSelectionTool.hxx>
64 #include <StdSelect_BRepOwner.hxx>
65 #include <StdSelect_DisplayMode.hxx>
67 #include <AIS_GraphicTool.hxx>
68 #include <AIS_InteractiveContext.hxx>
69 #include <AIS_Drawer.hxx>
70 #include <HLRBRep.hxx>
71 #include <Precision.hxx>
73 #include <Standard_Failure.hxx>
74 #include <Standard_ErrorHandler.hxx>
75 #include <Select3D_SensitiveBox.hxx>
76 #include <TopoDS_Iterator.hxx>
78 static Standard_Boolean myFirstCompute;
80 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
82 TColStd_ListIteratorOfListOfInteger It(LL);
83 for(;It.More();It.Next()){
85 return Standard_True;}
86 return Standard_False;
89 //==================================================
92 //==================================================
95 AIS_Shape(const TopoDS_Shape& shap):
96 AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
98 myCompBB(Standard_True),
101 myFirstCompute = Standard_True;
103 myDrawer->SetShadingAspectGlobal(Standard_False);
106 //=======================================================================
109 //=======================================================================
110 AIS_KindOfInteractive AIS_Shape::Type() const
111 {return AIS_KOI_Shape;}
114 //=======================================================================
115 //function : Signature
117 //=======================================================================
118 Standard_Integer AIS_Shape::Signature() const
121 //=======================================================================
122 //function : AcceptShapeDecomposition
124 //=======================================================================
125 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
126 {return Standard_True;}
128 //=======================================================================
131 //=======================================================================
132 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
133 const Handle(Prs3d_Presentation)& aPrs,
134 const Standard_Integer aMode)
137 if(myshape.IsNull()) return;
139 // wire,edge,vertex -> pas de HLR + priorite display superieure
140 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
141 if(TheType>4 && TheType<8) {
142 aPrs->SetVisual(Graphic3d_TOS_ALL);
143 aPrs->SetDisplayPriority(TheType+2);
145 // Shape vide -> Assemblage vide.
146 if (myshape.ShapeType() == TopAbs_COMPOUND) {
147 TopoDS_Iterator anExplor (myshape);
149 if (!anExplor.More()) {
154 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //not taken in account duting FITALL
157 try { OCC_CATCH_SIGNALS StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); }
158 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 Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
171 Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
172 Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
173 if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
174 || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
176 BRepTools::Clean (myshape);
179 //shading only on face...
180 if ((Standard_Integer) myshape.ShapeType()>4)
181 StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
183 myDrawer->SetShadingAspectGlobal(Standard_False);
184 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
189 StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
191 catch (Standard_Failure) {
193 cout << "AIS_Shape::Compute() in ShadingMode failed"<< endl;
195 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
200 Standard_Real value = Transparency() ;
202 SetTransparency( value );
209 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
210 else StdPrs_WFDeflectionRestrictedFace::AddBox (aPrs, BoundingBox(), myDrawer);
213 aPrs->ReCompute(); // for hidden line recomputation if necessary...
216 //=======================================================================
218 //purpose : Hidden Line Removal
219 //=======================================================================
220 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
221 const Handle(Prs3d_Presentation)& aPresentation)
223 Compute(aProjector,aPresentation,myshape);
226 //=======================================================================
229 //=======================================================================
231 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
232 const Handle(Geom_Transformation)& TheTrsf,
233 const Handle(Prs3d_Presentation)& aPresentation)
235 const TopLoc_Location& loc = myshape.Location();
236 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
237 Compute(aProjector,aPresentation,shbis);
240 //=======================================================================
243 //=======================================================================
245 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
246 const Handle(Prs3d_Presentation)& aPresentation,
247 const TopoDS_Shape& SH)
249 if (SH.ShapeType() == TopAbs_COMPOUND) {
250 TopoDS_Iterator anExplor (SH);
252 if (!anExplor.More()) // Shape vide -> Assemblage vide.
256 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
257 if (defdrawer->DrawHiddenLine())
258 {myDrawer->EnableDrawHiddenLine();}
259 else {myDrawer->DisableDrawHiddenLine();}
261 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
262 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
264 // coefficients for calculation
266 Standard_Real prevangle, newangle ,prevcoeff,newcoeff ;
267 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle(newangle,prevangle);
268 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient(newcoeff,prevcoeff);
269 if (((Abs (newangle - prevangle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
270 ((Abs (newcoeff - prevcoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient)) {
272 cout << "AIS_Shape : compute"<<endl;
273 cout << "newangle : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
274 cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
276 BRepTools::Clean(SH);
282 switch (TypeOfHLR()) {
284 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
286 case Prs3d_TOH_PolyAlgo:
288 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
292 catch (Standard_Failure) {
294 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
296 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
300 defdrawer->SetTypeOfDeflection (prevdef);
303 //=======================================================================
304 //function : SelectionType
305 //purpose : gives the type according to the Index of Selection Mode
306 //=======================================================================
308 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
312 return TopAbs_VERTEX;
324 return TopAbs_COMPSOLID;
326 return TopAbs_COMPOUND;
333 //=======================================================================
334 //function : SelectionType
335 //purpose : gives the SelectionMode according to the Type od Decomposition...
336 //=======================================================================
337 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
352 case TopAbs_COMPSOLID:
354 case TopAbs_COMPOUND:
363 //=======================================================================
364 //function : ComputeSelection
366 //=======================================================================
368 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
369 const Standard_Integer aMode)
371 if(myshape.IsNull()) return;
372 if (myshape.ShapeType() == TopAbs_COMPOUND) {
373 TopoDS_Iterator anExplor (myshape);
375 if (!anExplor.More()) // empty Shape -> empty Assembly.
379 static TopAbs_ShapeEnum TypOfSel;
380 TypOfSel = AIS_Shape::SelectionType(aMode);
381 TopoDS_Shape shape = myshape;
383 // POP protection against crash in low layers
385 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
386 Standard_Boolean autoTriangulation = Standard_True;
389 StdSelect_BRepSelectionTool::Load(aSelection,
394 myDrawer->HLRAngle(),
396 } catch ( Standard_Failure ) {
397 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
399 Bnd_Box B = BoundingBox();
400 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
401 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
402 aSelection->Add(aSensitiveBox);
406 // insert the drawer in the BrepOwners for hilight...
407 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
410 Quantity_NameOfColor AIS_Shape::Color() const {
411 Quantity_Color aColor;
413 return aColor.Name();
416 void AIS_Shape::Color( Quantity_Color& aColor ) const {
417 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
420 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
421 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
424 Standard_Real AIS_Shape::Transparency() const {
425 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
428 //=======================================================================
429 //function : SetColor
431 //=======================================================================
433 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
435 SetColor(Quantity_Color(aCol));
438 //=======================================================================
439 //function : setColor
441 //=======================================================================
443 void AIS_Shape::setColor (const Handle(AIS_Drawer)& theDrawer,
444 const Quantity_Color& theColor) const
446 if (!theDrawer->HasShadingAspect())
448 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
449 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
451 if (!theDrawer->HasLineAspect())
453 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
454 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
456 if (!theDrawer->HasWireAspect())
458 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
459 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
461 if (!theDrawer->HasPointAspect())
463 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
464 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
466 // disable dedicated line aspects
467 theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect());
468 theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect());
469 theDrawer->SetSeenLineAspect (theDrawer->LineAspect());
472 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
473 theDrawer->SetShadingAspectGlobal (Standard_False);
474 theDrawer->LineAspect()->SetColor (theColor);
475 theDrawer->WireAspect()->SetColor (theColor);
476 theDrawer->PointAspect()->SetColor (theColor);
479 //=======================================================================
480 //function : SetColor
482 //=======================================================================
484 void AIS_Shape::SetColor (const Quantity_Color& theColor)
486 setColor (myDrawer, theColor);
487 myOwnColor = theColor;
488 hasOwnColor = Standard_True;
490 // modify shading presentation without re-computation
491 const PrsMgr_Presentations& aPrsList = Presentations();
492 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
493 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
494 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
495 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
497 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
498 if (aPrsModed.Mode() != AIS_Shaded)
503 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
505 // Set aspects for presentation
506 aPrs->SetPrimitivesAspect (anAreaAspect);
507 aPrs->SetPrimitivesAspect (aLineAspect);
508 aPrs->SetPrimitivesAspect (aPointAspect);
510 // Go through all groups to change color for all primitives
511 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
513 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
515 // Check if aspect of given type is set for the group,
516 // because setting aspect for group with no already set aspect
517 // can lead to loss of presentation data
518 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
520 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
522 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
524 aGroup->SetGroupPrimitivesAspect (aLineAspect);
526 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
528 aGroup->SetGroupPrimitivesAspect (aPointAspect);
533 LoadRecomputable (AIS_WireFrame);
534 LoadRecomputable (2);
537 //=======================================================================
538 //function : UnsetColor
540 //=======================================================================
542 void AIS_Shape::UnsetColor()
546 myToRecomputeModes.Clear();
549 hasOwnColor = Standard_False;
553 Handle(Prs3d_LineAspect) anEmptyAsp;
554 myDrawer->SetLineAspect (anEmptyAsp);
555 myDrawer->SetWireAspect (anEmptyAsp);
556 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
557 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
558 myDrawer->SetSeenLineAspect (anEmptyAsp);
562 Quantity_Color aColor;
563 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
564 myDrawer->LineAspect()->SetColor (aColor);
565 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
566 myDrawer->WireAspect()->SetColor (aColor);
567 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
568 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
569 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
570 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
571 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
572 myDrawer->SeenLineAspect()->SetColor (aColor);
578 Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
581 Quantity_Color aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
582 mat.SetColor (aColor);
586 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
587 mat.SetTransparency (aTransp);
589 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
593 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
595 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
597 // modify shading presentation without re-computation
598 const PrsMgr_Presentations& aPrsList = Presentations();
599 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
600 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
601 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
603 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
604 if (aPrsModed.Mode() != AIS_Shaded)
609 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
611 aPrs->SetPrimitivesAspect (anAreaAsp);
612 aPrs->SetPrimitivesAspect (aLineAsp);
614 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
616 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
618 // Check if aspect of given type is set for the group,
619 // because setting aspect for group with no already set aspect
620 // can lead to loss of presentation data
621 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
623 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
625 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
627 aGroup->SetGroupPrimitivesAspect (aLineAsp);
632 LoadRecomputable (AIS_WireFrame);
633 LoadRecomputable (2);
636 //=======================================================================
637 //function : setWidth
639 //=======================================================================
641 void AIS_Shape::setWidth (const Handle(AIS_Drawer)& theDrawer,
642 const Standard_Real theLineWidth) const
644 if (!theDrawer->HasLineAspect())
646 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
647 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
649 if (!theDrawer->HasWireAspect())
651 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
652 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
654 // disable dedicated line aspects
655 theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect());
656 theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect());
657 theDrawer->SetSeenLineAspect (theDrawer->LineAspect());
660 theDrawer->LineAspect()->SetWidth (theLineWidth);
661 theDrawer->WireAspect()->SetWidth (theLineWidth);
664 //=======================================================================
665 //function : SetWidth
667 //=======================================================================
669 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
671 setWidth (myDrawer, theLineWidth);
672 myOwnWidth = theLineWidth;
673 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
674 LoadRecomputable (2); // and the bounding box...
677 //=======================================================================
678 //function : UnsetWidth
680 //=======================================================================
682 void AIS_Shape::UnsetWidth()
684 if (myOwnWidth == 0.0)
686 myToRecomputeModes.Clear();
692 Handle(Prs3d_LineAspect) anEmptyAsp;
696 myDrawer->SetLineAspect (anEmptyAsp);
697 myDrawer->SetWireAspect (anEmptyAsp);
698 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
699 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
700 myDrawer->SetSeenLineAspect (anEmptyAsp);
704 myDrawer->LineAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line));
705 myDrawer->WireAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire));
706 myDrawer->FreeBoundaryAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free));
707 myDrawer->UnFreeBoundaryAspect()->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree));
708 myDrawer->SeenLineAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen));
710 LoadRecomputable (AIS_WireFrame);
713 //=======================================================================
714 //function : setMaterial
716 //=======================================================================
718 void AIS_Shape::setMaterial (const Handle(AIS_Drawer)& theDrawer,
719 const Graphic3d_MaterialAspect& theMaterial,
720 const Standard_Boolean theToKeepColor,
721 const Standard_Boolean theToKeepTransp) const
723 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
724 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
725 if (!theDrawer->HasShadingAspect())
727 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
728 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
730 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
734 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
738 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
742 //=======================================================================
743 //function : SetMaterial
745 //=======================================================================
747 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
749 SetMaterial(Graphic3d_MaterialAspect(aMat));
752 //=======================================================================
753 //function : SetMaterial
755 //=======================================================================
757 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
759 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
760 hasOwnMaterial = Standard_True;
762 // modify shading presentation without re-computation
763 const PrsMgr_Presentations& aPrsList = Presentations();
764 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
765 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
767 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
768 if (aPrsModed.Mode() != AIS_Shaded)
773 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
774 aPrs->SetPrimitivesAspect (anAreaAsp);
775 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
777 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
779 // Check if aspect of given type is set for the group,
780 // because setting aspect for group with no already set aspect
781 // can lead to loss of presentation data
782 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
784 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
789 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
790 myToRecomputeModes.Clear();
793 //=======================================================================
794 //function : UnsetMaterial
796 //=======================================================================
798 void AIS_Shape::UnsetMaterial()
808 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
809 myCurrentFacingModel);
812 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
813 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
818 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
820 hasOwnMaterial = Standard_False;
822 // modify shading presentation without re-computation
823 const PrsMgr_Presentations& aPrsList = Presentations();
824 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
825 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
827 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
828 if (aPrsModed.Mode() != AIS_Shaded)
833 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
834 aPrs->SetPrimitivesAspect (anAreaAsp);
835 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
837 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
838 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
840 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
845 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
846 myToRecomputeModes.Clear();
849 //=======================================================================
850 //function : setTransparency
852 //=======================================================================
854 void AIS_Shape::setTransparency (const Handle(AIS_Drawer)& theDrawer,
855 const Standard_Real theValue) const
857 if (!theDrawer->HasShadingAspect())
859 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
860 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
863 // override transparency
864 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
867 //=======================================================================
868 //function : SetTransparency
870 //=======================================================================
872 void AIS_Shape::SetTransparency (const Standard_Real theValue)
874 setTransparency (myDrawer, theValue);
875 myTransparency = theValue;
877 // modify shading presentation without re-computation
878 const PrsMgr_Presentations& aPrsList = Presentations();
879 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
880 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
882 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
883 if (aPrsModed.Mode() != AIS_Shaded)
888 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
889 aPrs->SetPrimitivesAspect (anAreaAsp);
890 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
891 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
893 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
894 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
896 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
901 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
902 myToRecomputeModes.Clear();
905 //=======================================================================
906 //function : UnsetTransparency
908 //=======================================================================
910 void AIS_Shape::UnsetTransparency()
912 myTransparency = 0.0;
913 if (!myDrawer->HasShadingAspect())
917 else if (HasColor() || HasMaterial())
919 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
923 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
926 // modify shading presentation without re-computation
927 const PrsMgr_Presentations& aPrsList = Presentations();
928 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
929 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
931 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
932 if (aPrsModed.Mode() != AIS_Shaded)
937 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
938 aPrs->SetPrimitivesAspect (anAreaAsp);
939 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
941 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
942 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
944 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
947 aPrs->ResetDisplayPriority();
950 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
951 myToRecomputeModes.Clear();
954 //=======================================================================
955 //function : LoadRecomputable
957 //=======================================================================
959 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
961 myRecomputeEveryPrs = Standard_False;
962 if(!IsInList(myToRecomputeModes,TheMode))
963 myToRecomputeModes.Append(TheMode);
966 //=======================================================================
967 //function : BoundingBox
969 //=======================================================================
971 const Bnd_Box& AIS_Shape::BoundingBox()
973 if (myshape.ShapeType() == TopAbs_COMPOUND) {
974 TopoDS_Iterator anExplor (myshape);
976 if (!anExplor.More()) { // empty Shape -> empty Assembly.
983 BRepBndLib::AddClose(myshape, myBB);
984 myCompBB = Standard_False;
991 //=======================================================================
992 //function : SetOwnDeviationCoefficient
993 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
994 // returns Standard_True if it change
995 //=======================================================================
997 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
999 Standard_Boolean itSet = myDrawer->IsOwnDeviationCoefficient();
1000 if(itSet) myDrawer->SetDeviationCoefficient();
1004 //=======================================================================
1005 //function : SetHLROwnDeviationCoefficient
1006 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1007 // returns Standard_True if it change
1008 //=======================================================================
1010 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1012 Standard_Boolean itSet = myDrawer->IsOwnHLRDeviationCoefficient();
1013 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1018 //=======================================================================
1019 //function : SetOwnDeviationAngle
1020 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1021 // returns Standard_True if it change
1022 //=======================================================================
1024 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1026 Standard_Boolean itSet = myDrawer->IsOwnDeviationAngle();
1027 if(itSet) myDrawer->SetDeviationAngle();
1032 //=======================================================================
1033 //function : SetOwnHLRDeviationAngle
1034 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1035 // returns Standard_True if it change
1036 //=======================================================================
1038 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1040 Standard_Boolean itSet = myDrawer->IsOwnHLRDeviationAngle();
1041 if(itSet) myDrawer->SetHLRAngle();
1046 //=======================================================================
1047 //function : SetOwnDeviationCoefficient
1049 //=======================================================================
1051 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1053 myDrawer->SetDeviationCoefficient( aCoefficient );
1054 SetToUpdate(0) ; // WireFrame
1055 SetToUpdate(1) ; // Shadding
1058 //=======================================================================
1059 //function : SetOwnHLRDeviationCoefficient
1061 //=======================================================================
1063 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1065 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1069 //=======================================================================
1070 //function : SetOwnDeviationAngle
1072 //=======================================================================
1074 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1077 myDrawer->SetDeviationAngle(anAngle );
1078 SetToUpdate(0) ; // WireFrame
1080 //=======================================================================
1081 //function : SetOwnDeviationAngle
1083 //=======================================================================
1085 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1087 Standard_Real OutAngl,OutDefl;
1088 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1089 SetOwnDeviationAngle(anAngle) ;
1090 SetOwnDeviationCoefficient(OutDefl) ;
1091 myInitAng = anAngle;
1096 //=======================================================================
1097 //function : UserAngle
1099 //=======================================================================
1101 Standard_Real AIS_Shape::UserAngle() const
1103 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1107 //=======================================================================
1108 //function : SetHLRAngleAndDeviation
1110 //=======================================================================
1112 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1114 Standard_Real OutAngl,OutDefl;
1115 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1116 SetOwnHLRDeviationAngle( OutAngl );
1117 SetOwnHLRDeviationCoefficient(OutDefl);
1120 //=======================================================================
1121 //function : SetOwnHLRDeviationAngle
1123 //=======================================================================
1125 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1127 myDrawer->SetHLRAngle( anAngle );
1131 //=======================================================================
1132 //function : OwnDeviationCoefficient
1134 //=======================================================================
1136 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1137 Standard_Real & aPreviousCoefficient ) const
1139 aCoefficient = myDrawer->DeviationCoefficient();
1140 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1141 return myDrawer->IsOwnDeviationCoefficient() ;
1144 //=======================================================================
1145 //function : OwnHLRDeviationCoefficient
1147 //=======================================================================
1149 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1150 Standard_Real & aPreviousCoefficient ) const
1152 aCoefficient = myDrawer->HLRDeviationCoefficient();
1153 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1154 return myDrawer->IsOwnHLRDeviationCoefficient();
1158 //=======================================================================
1159 //function : OwnDeviationAngle
1161 //=======================================================================
1163 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1164 Standard_Real & aPreviousAngle ) const
1166 anAngle = myDrawer->DeviationAngle();
1167 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1168 return myDrawer->IsOwnDeviationAngle();
1171 //=======================================================================
1172 //function : OwnHLRDeviationAngle
1174 //=======================================================================
1176 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1177 Standard_Real & aPreviousAngle ) const
1179 anAngle = myDrawer->HLRAngle();
1180 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1181 return myDrawer->IsOwnHLRDeviationAngle();