2 // Created: Fri Dec 20 17:18:37 1996
3 // Author: Robert COUBLANC
4 // <rob@robox.paris1.matra-dtv.fr>
6 #define BUC60577 //GG_191099 Draw correct bounding box and Menage ...
8 #define BUC60547 //GG_091299 Enable to show a Shape of type COMPOUND
10 #define GER61351 //GG_171199 Enable to set an object RGB color
11 // instead a restricted object NameOfColor.
12 // Redefines the Color(),Material(),Transparency() methods .
13 // enable to get separately the shape attributes.
15 #define IMP040200 //GG Enable to compute selection after transformation
17 #define BUC60918 //GG 31/05/01 To avoid transparency bug between
18 // transparent and non transparent objects,
19 // increase display priority for transparent objects
21 #include <AIS_Shape.ixx>
24 #include <Standard_ErrorHandler.hxx>
25 #include <OSD_Timer.hxx>
26 #include <TColStd_ListIteratorOfListOfInteger.hxx>
28 #include <Quantity_Color.hxx>
31 #include <Bnd_Box.hxx>
32 #include <BRep_Builder.hxx>
33 #include <BRepTools_ShapeSet.hxx>
34 #include <BRepTools.hxx>
35 #include <BRepBndLib.hxx>
37 #include <TopExp_Explorer.hxx>
39 #include <Aspect_TypeOfLine.hxx>
40 #include <Graphic3d_Structure.hxx>
41 #include <Graphic3d_Group.hxx>
42 #include <Graphic3d_AspectLine3d.hxx>
43 #include <Graphic3d_AspectText3d.hxx>
44 #include <Graphic3d_AspectMarker3d.hxx>
45 #include <Graphic3d_AspectFillArea3d.hxx>
46 #include <Graphic3d_Array1OfVertex.hxx>
47 #include <Graphic3d_ArrayOfPrimitives.hxx>
48 #include <Graphic3d_MaterialAspect.hxx>
50 #include <Prs3d_Presentation.hxx>
51 #include <Prs3d_Root.hxx>
52 #include <Prs3d_ShadingAspect.hxx>
53 #include <Prs3d_Drawer.hxx>
54 #include <Prs3d_IsoAspect.hxx>
56 //#include <StdPrs_WFSectionShape.hxx>
57 #include <StdPrs_WFShape.hxx>
58 #include <StdPrs_WFDeflectionShape.hxx>
59 #include <StdPrs_ShadedShape.hxx>
60 #include <StdPrs_HLRShape.hxx>
61 #include <StdPrs_HLRPolyShape.hxx>
63 #include <PrsMgr_ModedPresentation.hxx>
65 #include <Select3D_SensitiveEntity.hxx>
66 #include <StdSelect.hxx>
67 #include <StdSelect_BRepSelectionTool.hxx>
68 #include <StdSelect_BRepOwner.hxx>
69 #include <StdSelect_DisplayMode.hxx>
71 #include <AIS_GraphicTool.hxx>
72 #include <AIS_InteractiveContext.hxx>
73 #include <AIS_Drawer.hxx>
74 #include <HLRBRep.hxx>
75 #include <Precision.hxx>
77 #include <Standard_Failure.hxx>
78 #include <Standard_ErrorHandler.hxx>
79 #include <Select3D_SensitiveBox.hxx>
81 #include <TopoDS_Iterator.hxx>
84 static Standard_Boolean myFirstCompute;
86 Standard_Real AIS_Shape::GetDeflection(const TopoDS_Shape& aShape,
87 const Handle(Prs3d_Drawer)& aDrawer)
89 // WARNING: this same piece of code appears several times in Prs3d classes
90 Standard_Real aDeflection = aDrawer->MaximalChordialDeviation();
91 if (aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) {
93 BRepBndLib::Add(aShape, B, Standard_False);
96 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
97 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
98 aDeflection = Max( aXmax-aXmin, Max(aYmax-aYmin, aZmax-aZmin)) *
99 aDrawer->DeviationCoefficient() * 4;
105 void AIS_Shape::DisplayBox(const Handle(Prs3d_Presentation)& aPrs,
107 const Handle(Prs3d_Drawer)& aDrawer)
109 Standard_Real X[2],Y[2],Z[2];
110 Standard_Integer Indx [16] ;
112 return; // nothing to show
115 Indx [0]=1;Indx [1]=2;Indx [2]=4;Indx [3]=3;
116 Indx [4]=5;Indx [5]=6;Indx [6]=8;Indx [7]=7;
117 Indx [8]=1;Indx [9]=3;Indx [10]=7;Indx [11]=5;
118 Indx [12]=2;Indx [13]=4;Indx [14]=8;Indx [15]=6;
119 B.Get(X[0], Y[0], Z[0], X[1], Y[1], Z[1]);
121 Indx [0]=1;Indx [1]=2;Indx [2]=3;Indx [3]=4;Indx [4]=5;Indx [5]=6;Indx [6]=7;
122 Indx [7]=8;Indx [8]=1;Indx [9]=2;Indx [10]=6;Indx [10]=5;Indx [10]=3;
123 Indx [10]=4;Indx [10]=8;Indx [10]=7;
124 B.Get(X[1], Y[1], Z[1], X[2], Y[2], Z[2]);
127 Graphic3d_Array1OfVertex V(1,8);
128 Standard_Integer Rank(0);
129 for(Standard_Integer k=0;k<=1;k++)
130 for(Standard_Integer j=0;j<=1;j++)
131 for(Standard_Integer i=0;i<=1;i++)
132 V(++Rank) = Graphic3d_Vertex(X[i],Y[j],Z[k]);
135 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(aPrs);
139 aDrawer->LineAspect()->Aspect()->Values(Q,A,W);
142 G->SetGroupPrimitivesAspect(new Graphic3d_AspectLine3d(Q,Aspect_TOL_DOTDASH,W));
144 G->BeginPrimitives();Standard_Integer I,J;
145 Graphic3d_Array1OfVertex VVV (1,5);
148 VVV.SetValue(J,V(Indx[J+4*I-5]));
150 VVV.SetValue(5,VVV(1));
156 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
158 TColStd_ListIteratorOfListOfInteger It(LL);
159 for(;It.More();It.Next()){
160 if(It.Value()==aMode)
161 return Standard_True;}
162 return Standard_False;
165 //==================================================
168 //==================================================
171 AIS_Shape(const TopoDS_Shape& shap):
172 AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
174 myCompBB(Standard_True),
177 myFirstCompute = Standard_True;
179 myDrawer->SetShadingAspectGlobal(Standard_False);
182 //=======================================================================
185 //=======================================================================
186 AIS_KindOfInteractive AIS_Shape::Type() const
187 {return AIS_KOI_Shape;}
190 //=======================================================================
191 //function : Signature
193 //=======================================================================
194 Standard_Integer AIS_Shape::Signature() const
197 //=======================================================================
198 //function : AcceptShapeDecomposition
200 //=======================================================================
201 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
202 {return Standard_True;}
204 //=======================================================================
207 //=======================================================================
208 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
209 const Handle(Prs3d_Presentation)& aPrs,
210 const Standard_Integer aMode)
213 if(myshape.IsNull()) return;
215 // wire,edge,vertex -> pas de HLR + priorite display superieure
216 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
217 if(TheType>4 && TheType<8) {
218 aPrs->SetVisual(Graphic3d_TOS_ALL);
219 aPrs->SetDisplayPriority(TheType+2);
221 // Shape vide -> Assemblage vide.
222 if (myshape.ShapeType() == TopAbs_COMPOUND) {
224 TopoDS_Iterator anExplor (myshape);
226 TopExp_Explorer anExplor (myshape, TopAbs_VERTEX);
228 if (!anExplor.More()) {
234 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //not taken in account duting FITALL
237 try { OCC_CATCH_SIGNALS StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); }
238 catch (Standard_Failure) {
240 cout << "AIS_Shape::Compute() failed"<< endl;
242 cout << "a Shape should be incorrect : No Compute can be maked on it "<< endl;
243 // presentation of the bounding box is calculated
244 // Compute(aPresentationManager,aPrs,2);
250 Standard_Real prevangle ;
251 Standard_Real newangle ;
252 Standard_Real prevcoeff ;
253 Standard_Real newcoeff ;
256 if (OwnDeviationAngle(newangle,prevangle) ||
257 OwnDeviationCoefficient(newcoeff,prevcoeff))
258 if (Abs (newangle - prevangle) > Precision::Angular() ||
259 Abs (newcoeff - prevcoeff) > Precision::Confusion() ) {
261 cout << "AIS_Shape : compute"<<endl;
262 cout << "newangl : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
263 cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
265 BRepTools::Clean(myshape);
268 //shading only on face...
269 if ((Standard_Integer) myshape.ShapeType()>4)
270 StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
272 myDrawer->SetShadingAspectGlobal(Standard_False);
273 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
278 StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
280 catch (Standard_Failure) {
282 cout << "AIS_Shape::Compute() in ShadingMode failed"<< endl;
284 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
290 Standard_Real value = Transparency() ;
292 SetTransparency( value );
300 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
301 else DisplayBox(aPrs,BoundingBox(),myDrawer);
306 aPrs->ReCompute(); // for hidden line recomputation if necessary...
310 //=======================================================================
313 //=======================================================================
315 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager2d)& /*aPresentationManager*/,
316 const Handle(Graphic2d_GraphicObject)& /*aGRO*/,
317 const Standard_Integer /*aMode*/)
321 //=======================================================================
323 //purpose : Hidden Line Removal
324 //=======================================================================
325 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
326 const Handle(Prs3d_Presentation)& aPresentation)
328 Compute(aProjector,aPresentation,myshape);
331 //=======================================================================
334 //=======================================================================
336 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
337 const Handle(Geom_Transformation)& TheTrsf,
338 const Handle(Prs3d_Presentation)& aPresentation)
340 const TopLoc_Location& loc = myshape.Location();
341 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
342 Compute(aProjector,aPresentation,shbis);
345 //=======================================================================
348 //=======================================================================
350 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
351 const Handle(Prs3d_Presentation)& aPresentation,
352 const TopoDS_Shape& SH)
354 if (SH.ShapeType() == TopAbs_COMPOUND) {
356 TopoDS_Iterator anExplor (SH);
358 TopExp_Explorer anExplor (SH, TopAbs_VERTEX);
360 if (!anExplor.More()) // Shape vide -> Assemblage vide.
364 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
365 if (defdrawer->DrawHiddenLine())
366 {myDrawer->EnableDrawHiddenLine();}
367 else {myDrawer->DisableDrawHiddenLine();}
369 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
370 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
372 // coefficients for calculation
374 Standard_Real prevangle, newangle ,prevcoeff,newcoeff ;
375 if (OwnHLRDeviationAngle(newangle,prevangle) || OwnHLRDeviationCoefficient(newcoeff, prevcoeff))
377 if (Abs (newangle - prevangle) > Precision::Angular() ||
378 Abs (newcoeff - prevcoeff) > Precision::Confusion() ) {
380 cout << "AIS_Shape : compute"<<endl;
381 cout << "newangle : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
382 cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
384 BRepTools::Clean(SH);
390 StdPrs_HLRPolyShape::Add(aPresentation,SH,myDrawer,aProjector);
392 catch (Standard_Failure) {
394 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
396 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
401 defdrawer->SetTypeOfDeflection (prevdef);
404 //=======================================================================
405 //function : SelectionType
406 //purpose : gives the type according to the Index of Selection Mode
407 //=======================================================================
409 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
413 return TopAbs_VERTEX;
425 return TopAbs_COMPSOLID;
427 return TopAbs_COMPOUND;
434 //=======================================================================
435 //function : SelectionType
436 //purpose : gives the SelectionMode according to the Type od Decomposition...
437 //=======================================================================
438 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
453 case TopAbs_COMPSOLID:
455 case TopAbs_COMPOUND:
464 //=======================================================================
465 //function : ComputeSelection
467 //=======================================================================
469 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
470 const Standard_Integer aMode)
472 if(myshape.IsNull()) return;
473 if (myshape.ShapeType() == TopAbs_COMPOUND) {
475 TopoDS_Iterator anExplor (myshape);
477 TopExp_Explorer anExplor (myshape, TopAbs_VERTEX);
479 if (!anExplor.More()) // empty Shape -> empty Assembly.
483 static TopAbs_ShapeEnum TypOfSel;
484 TypOfSel = AIS_Shape::SelectionType(aMode);
485 TopoDS_Shape shape = myshape;
487 if( HasTransformation() ) {
488 Handle(Geom_Transformation) trsf = Transformation();
489 shape = shape.Located(TopLoc_Location(trsf->Trsf())*shape.Location());
493 // POP protection against crash in low layers
495 Standard_Real aDeflection = GetDeflection(shape, myDrawer);
496 Standard_Boolean autoTriangulation = Standard_True;
499 StdSelect_BRepSelectionTool::Load(aSelection,
504 myDrawer->HLRAngle(),
506 } catch ( Standard_Failure ) {
507 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
509 Bnd_Box B = BoundingBox();
510 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
511 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
512 aSelection->Add(aSensitiveBox);
516 // insert the drawer in the BrepOwners for hilight...
517 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
521 Quantity_NameOfColor AIS_Shape::Color() const {
522 Quantity_Color aColor;
524 return aColor.Name();
527 void AIS_Shape::Color( Quantity_Color& aColor ) const {
528 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
531 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
532 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
535 Standard_Real AIS_Shape::Transparency() const {
536 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
540 //=======================================================================
541 //function : SetColor
543 //=======================================================================
545 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
548 SetColor(Quantity_Color(aCol));
551 void AIS_Shape::SetColor(const Quantity_Color &aCol)
554 hasOwnColor = Standard_True;
556 if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
557 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
561 if(!myDrawer->HasShadingAspect()){
562 Handle(Prs3d_ShadingAspect) asp = new Prs3d_ShadingAspect();
563 // retrieve the reference materials...
564 if(myDrawer->HasLink()){
565 const Handle(Prs3d_Drawer)& refdr = myDrawer->Link();
566 Graphic3d_MaterialAspect theRefMat =
567 refdr->ShadingAspect()->Aspect()->FrontMaterial();
568 theRefMat.SetTransparency(myTransparency);
569 asp->SetMaterial(theRefMat);
572 myDrawer->SetShadingAspect(asp);
577 myDrawer->ShadingAspect()->SetColor(aCol,myCurrentFacingModel);
579 myDrawer->ShadingAspect()->SetColor(aCol);
581 myDrawer->SetShadingAspectGlobal(Standard_False);
583 Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
585 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
586 myDrawer->SetWireAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
587 myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
588 myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
589 myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
591 // fast shading modification...
592 if(!GetContext().IsNull()){
593 if( GetContext()->MainPrsMgr()->HasPresentation(this,1)){
594 Handle(Prs3d_Presentation) P = GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
595 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(P);
596 Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
598 P->SetPrimitivesAspect(a4bis);
599 G->SetGroupPrimitivesAspect(a4bis);
601 a4bis->SetInteriorColor(Quantity_Color(aCol)); // Already done above in SetColor(...)
603 P->SetPrimitivesAspect(myDrawer->ShadingAspect()->Aspect());
604 G->SetGroupPrimitivesAspect(myDrawer->ShadingAspect()->Aspect());
612 //=======================================================================
613 //function : UnsetColor
615 //=======================================================================
617 void AIS_Shape::UnsetColor()
619 if(!HasColor() ){ myToRecomputeModes.Clear();
622 hasOwnColor = Standard_False;
624 Handle(Prs3d_LineAspect) NullAsp;
625 Handle(Prs3d_ShadingAspect) NullShA;
628 myDrawer->SetLineAspect(NullAsp);
629 myDrawer->SetWireAspect(NullAsp);
630 myDrawer->SetFreeBoundaryAspect(NullAsp);
631 myDrawer->SetUnFreeBoundaryAspect(NullAsp);
632 myDrawer->SetSeenLineAspect(NullAsp);
637 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
638 myDrawer->LineAspect()->SetColor(CC);
639 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire,CC);
640 myDrawer->WireAspect()->SetColor(CC);
641 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free,CC);
642 myDrawer->FreeBoundaryAspect()->SetColor(CC);
643 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree,CC);
644 myDrawer->UnFreeBoundaryAspect()->SetColor(CC);
645 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen,CC);
646 myDrawer->SeenLineAspect()->SetColor(CC);
648 myDrawer->LineAspect()->SetColor(AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line));
649 myDrawer->WireAspect()->SetColor(AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire));
650 myDrawer->FreeBoundaryAspect()->SetColor(AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free));
651 myDrawer->UnFreeBoundaryAspect()->SetColor(AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree));
652 myDrawer->SeenLineAspect()->SetColor(AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen));
656 if(myDrawer->HasShadingAspect()){
657 myDrawer->SetShadingAspect(NullShA);
660 if(!GetContext().IsNull()){
661 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
662 Handle(Prs3d_Presentation) P = GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
663 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(P);
665 Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->Link()->ShadingAspect()->Aspect();
668 AIS_GraphicTool::GetInteriorColor(myDrawer->Link(),CC);
669 a4bis->SetInteriorColor(CC);
671 Quantity_NameOfColor KOL = AIS_GraphicTool::GetInteriorColor(myDrawer->Link());
672 a4bis->SetInteriorColor(Quantity_Color(KOL));
674 P->SetPrimitivesAspect(a4bis);
675 G->SetGroupPrimitivesAspect(a4bis);
684 //=======================================================================
685 //function : SetWidth
687 //=======================================================================
689 void AIS_Shape::SetWidth(const Standard_Real W)
691 if(HasColor() || HasWidth()){
692 myDrawer->LineAspect()->SetWidth(W);
693 myDrawer->WireAspect()->SetWidth(W);
694 myDrawer->FreeBoundaryAspect()->SetWidth(W);
695 myDrawer->UnFreeBoundaryAspect()->SetWidth(W);
696 myDrawer->SeenLineAspect()->SetWidth(W);
701 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
702 myDrawer->SetLineAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
703 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire,CC);
704 myDrawer->SetWireAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
705 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free,CC);
706 myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
707 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree,CC);
708 myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
709 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen,CC);
710 myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
712 Quantity_NameOfColor KOL = AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line);
713 myDrawer->SetLineAspect(new Prs3d_LineAspect(KOL,Aspect_TOL_SOLID,W));
715 KOL = AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire);
716 myDrawer->SetWireAspect(new Prs3d_LineAspect(KOL,Aspect_TOL_SOLID,W));
718 KOL = AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free);
719 myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(KOL,Aspect_TOL_SOLID,W));
721 KOL = AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree);
722 myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(KOL,Aspect_TOL_SOLID,W));
724 KOL = AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen);
725 myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(KOL,Aspect_TOL_SOLID,W));
729 LoadRecomputable(0); // means that it is necessary to recompute only the wireframe....
730 LoadRecomputable(2); // and the bounding box...
734 //=======================================================================
735 //function : UnsetWidth
737 //=======================================================================
739 void AIS_Shape::UnsetWidth()
741 if(myOwnWidth== 0.0){ myToRecomputeModes.Clear();
744 Handle(Prs3d_LineAspect) NullAsp;
747 myDrawer->SetLineAspect(NullAsp);
748 myDrawer->SetWireAspect(NullAsp);
749 myDrawer->SetFreeBoundaryAspect(NullAsp);
750 myDrawer->SetUnFreeBoundaryAspect(NullAsp);
751 myDrawer->SetSeenLineAspect(NullAsp);
754 myDrawer->LineAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line));
755 myDrawer->WireAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Wire));
756 myDrawer->FreeBoundaryAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Free));
757 myDrawer->UnFreeBoundaryAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_UnFree));
758 myDrawer->SeenLineAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Seen));
764 //=======================================================================
765 //function : SetMaterial
767 //=======================================================================
768 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
771 if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
772 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
774 myDrawer->ShadingAspect()->SetMaterial(aMat,myCurrentFacingModel);
775 hasOwnMaterial = Standard_True;
777 AIS_InteractiveObject::SetMaterial(aMat);
779 if(!GetContext().IsNull()){
780 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
781 Handle(Prs3d_Presentation) P = GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
782 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(P);
784 Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
785 P->SetPrimitivesAspect(a4bis);
786 G->SetGroupPrimitivesAspect(a4bis);
789 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
790 myToRecomputeModes.Clear();
792 //=======================================================================
793 //function : SetMaterial
795 //=======================================================================
796 void AIS_Shape::SetMaterial(const Graphic3d_MaterialAspect& aMat)
799 if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
800 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
802 myDrawer->ShadingAspect()->SetMaterial(aMat,myCurrentFacingModel);
803 hasOwnMaterial = Standard_True;
805 AIS_InteractiveObject::SetMaterial(aMat);
807 if(!GetContext().IsNull()){
808 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
809 Handle(Prs3d_Presentation) P = GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
810 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(P);
812 Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
813 P->SetPrimitivesAspect(a4bis);
814 G->SetGroupPrimitivesAspect(a4bis);
817 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
818 myToRecomputeModes.Clear();
821 //=======================================================================
822 //function : UnsetMaterial
824 //=======================================================================
825 void AIS_Shape::UnsetMaterial()
828 if( !HasMaterial() ) return;
829 if( HasColor() || IsTransparent()) {
830 Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(myDrawer->Link());
832 Quantity_Color color = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
835 if( IsTransparent() ) {
836 Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
837 mat.SetTransparency(trans);
839 myDrawer->ShadingAspect()->SetMaterial(mat,myCurrentFacingModel);
841 Handle(Prs3d_ShadingAspect) SA;
842 myDrawer->SetShadingAspect(SA);
844 hasOwnMaterial = Standard_False;
846 AIS_InteractiveObject::UnsetMaterial();
848 if(!GetContext().IsNull()){
850 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
851 Handle(Prs3d_Presentation) P = GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
852 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(P);
854 Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
855 P->SetPrimitivesAspect(a4bis);
856 G->SetGroupPrimitivesAspect(a4bis);
859 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
860 myToRecomputeModes.Clear();
863 //=======================================================================
864 //function : SetTransparency
866 //=======================================================================
868 void AIS_Shape::SetTransparency(const Standard_Real AValue)
871 if(!HasColor() && !HasMaterial() ) {
872 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
874 myDrawer->ShadingAspect()->SetTransparency(AValue,myCurrentFacingModel);
875 myTransparency = AValue;
877 AIS_InteractiveObject::SetTransparency(AValue);
879 if(!GetContext().IsNull()){
880 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
881 Handle(Prs3d_Presentation) P = GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
882 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(P);
884 Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
885 P->SetPrimitivesAspect(a4bis);
886 #ifdef BUC60918 //force highest priority for transparent objects
887 P->SetDisplayPriority(10);
889 G->SetGroupPrimitivesAspect(a4bis);
892 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
893 myToRecomputeModes.Clear();
897 //=======================================================================
898 //function : UnsetTransparency
900 //=======================================================================
901 void AIS_Shape::UnsetTransparency()
904 if(HasColor() || HasMaterial() ) {
905 myDrawer->ShadingAspect()->SetTransparency(0.0,myCurrentFacingModel);
907 Handle(Prs3d_ShadingAspect) SA;
908 myDrawer->SetShadingAspect(SA);
910 myTransparency = 0.0;
912 AIS_InteractiveObject::UnsetTransparency();
914 if(!GetContext().IsNull()){
916 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
917 Handle(Prs3d_Presentation) P = GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
918 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(P);
920 Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
921 P->SetPrimitivesAspect(a4bis);
922 G->SetGroupPrimitivesAspect(a4bis);
924 P->ResetDisplayPriority();
928 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
929 myToRecomputeModes.Clear();
933 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
935 myRecomputeEveryPrs =Standard_False;
936 if(!IsInList(myToRecomputeModes,TheMode))
937 myToRecomputeModes.Append(TheMode);
942 //=======================================================================
943 //function : BoundingBox
945 //=======================================================================
947 const Bnd_Box& AIS_Shape::BoundingBox()
949 if (myshape.ShapeType() == TopAbs_COMPOUND) {
951 TopoDS_Iterator anExplor (myshape);
953 TopExp_Explorer anExplor (myshape, TopAbs_VERTEX);
955 if (!anExplor.More()) { // empty Shape -> empty Assembly.
962 BRepBndLib::AddClose(myshape, myBB);
963 myCompBB = Standard_False;
970 //=======================================================================
971 //function : SetOwnDeviationCoefficient
972 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
973 // returns Standard_True if it change
974 //=======================================================================
976 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
978 Standard_Boolean itSet = myDrawer->IsOwnDeviationCoefficient();
979 if(itSet) myDrawer->SetDeviationCoefficient();
985 //=======================================================================
986 //function : SetHLROwnDeviationCoefficient
987 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
988 // returns Standard_True if it change
989 //=======================================================================
991 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
993 Standard_Boolean itSet = myDrawer->IsOwnHLRDeviationCoefficient();
994 if(itSet) myDrawer->SetHLRDeviationCoefficient();
999 //=======================================================================
1000 //function : SetOwnDeviationAngle
1001 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1002 // returns Standard_True if it change
1003 //=======================================================================
1005 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1007 Standard_Boolean itSet = myDrawer->IsOwnDeviationAngle();
1008 if(itSet) myDrawer->SetDeviationAngle();
1013 //=======================================================================
1014 //function : SetOwnHLRDeviationAngle
1015 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1016 // returns Standard_True if it change
1017 //=======================================================================
1019 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1021 Standard_Boolean itSet = myDrawer->IsOwnHLRDeviationAngle();
1022 if(itSet) myDrawer->SetHLRAngle();
1027 //=======================================================================
1028 //function : SetOwnDeviationCoefficient
1030 //=======================================================================
1032 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1034 myDrawer->SetDeviationCoefficient( aCoefficient );
1035 SetToUpdate(0) ; // WireFrame
1036 SetToUpdate(1) ; // Shadding
1039 //=======================================================================
1040 //function : SetOwnHLRDeviationCoefficient
1042 //=======================================================================
1044 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1046 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1050 //=======================================================================
1051 //function : SetOwnDeviationAngle
1053 //=======================================================================
1055 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1058 myDrawer->SetDeviationAngle(anAngle );
1059 SetToUpdate(0) ; // WireFrame
1061 //=======================================================================
1062 //function : SetOwnDeviationAngle
1064 //=======================================================================
1066 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1068 Standard_Real OutAngl,OutDefl;
1069 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1070 SetOwnDeviationAngle(anAngle) ;
1071 // SetOwnDeviationAngle(OutAngl) ;
1072 SetOwnDeviationCoefficient(OutDefl) ;
1073 myInitAng = anAngle;
1078 //=======================================================================
1079 //function : UserAngle
1081 //=======================================================================
1083 Standard_Real AIS_Shape::UserAngle() const
1085 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1089 //=======================================================================
1090 //function : SetHLRAngleAndDeviation
1092 //=======================================================================
1094 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1096 Standard_Real OutAngl,OutDefl;
1097 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1098 SetOwnHLRDeviationAngle( OutAngl );
1099 SetOwnHLRDeviationCoefficient(OutDefl);
1102 //=======================================================================
1103 //function : SetOwnHLRDeviationAngle
1105 //=======================================================================
1107 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1109 myDrawer->SetHLRAngle( anAngle );
1113 //=======================================================================
1114 //function : OwnDeviationCoefficient
1116 //=======================================================================
1118 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1119 Standard_Real & aPreviousCoefficient ) const
1121 aCoefficient = myDrawer->DeviationCoefficient();
1122 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1123 return myDrawer->IsOwnDeviationCoefficient() ;
1126 //=======================================================================
1127 //function : OwnHLRDeviationCoefficient
1129 //=======================================================================
1131 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1132 Standard_Real & aPreviousCoefficient ) const
1134 aCoefficient = myDrawer->HLRDeviationCoefficient();
1135 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1136 return myDrawer->IsOwnHLRDeviationCoefficient();
1140 //=======================================================================
1141 //function : OwnDeviationAngle
1143 //=======================================================================
1145 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1146 Standard_Real & aPreviousAngle ) const
1148 anAngle = myDrawer->DeviationAngle();
1149 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1150 return myDrawer->IsOwnDeviationAngle();
1153 //=======================================================================
1154 //function : OwnHLRDeviationAngle
1156 //=======================================================================
1158 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1159 Standard_Real & aPreviousAngle ) const
1161 anAngle = myDrawer->HLRAngle();
1162 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1163 return myDrawer->IsOwnHLRDeviationAngle();