1 // Created on: 1996-12-20
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <AIS_Shape.ixx>
25 #include <Standard_ErrorHandler.hxx>
26 #include <OSD_Timer.hxx>
27 #include <TColStd_ListIteratorOfListOfInteger.hxx>
29 #include <Quantity_Color.hxx>
32 #include <Bnd_Box.hxx>
33 #include <BRep_Builder.hxx>
34 #include <BRepTools_ShapeSet.hxx>
35 #include <BRepTools.hxx>
36 #include <BRepBndLib.hxx>
38 #include <TopExp_Explorer.hxx>
40 #include <Aspect_TypeOfLine.hxx>
41 #include <Graphic3d_Structure.hxx>
42 #include <Graphic3d_Group.hxx>
43 #include <Graphic3d_AspectLine3d.hxx>
44 #include <Graphic3d_AspectText3d.hxx>
45 #include <Graphic3d_AspectMarker3d.hxx>
46 #include <Graphic3d_AspectFillArea3d.hxx>
47 #include <Graphic3d_ArrayOfPolylines.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_WFShape.hxx>
57 #include <StdPrs_WFDeflectionShape.hxx>
58 #include <StdPrs_ShadedShape.hxx>
59 #include <StdPrs_HLRShape.hxx>
60 #include <StdPrs_HLRPolyShape.hxx>
62 #include <PrsMgr_ModedPresentation.hxx>
64 #include <Select3D_SensitiveEntity.hxx>
65 #include <StdSelect.hxx>
66 #include <StdSelect_BRepSelectionTool.hxx>
67 #include <StdSelect_BRepOwner.hxx>
68 #include <StdSelect_DisplayMode.hxx>
70 #include <AIS_GraphicTool.hxx>
71 #include <AIS_InteractiveContext.hxx>
72 #include <AIS_Drawer.hxx>
73 #include <HLRBRep.hxx>
74 #include <Precision.hxx>
76 #include <Standard_Failure.hxx>
77 #include <Standard_ErrorHandler.hxx>
78 #include <Select3D_SensitiveBox.hxx>
79 #include <TopoDS_Iterator.hxx>
81 static Standard_Boolean myFirstCompute;
83 Standard_Real AIS_Shape::GetDeflection(const TopoDS_Shape& aShape,
84 const Handle(Prs3d_Drawer)& aDrawer)
86 // WARNING: this same piece of code appears several times in Prs3d classes
87 Standard_Real aDeflection = aDrawer->MaximalChordialDeviation();
88 if (aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) {
90 BRepBndLib::Add(aShape, B, Standard_False);
93 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
94 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
95 aDeflection = Max( aXmax-aXmin, Max(aYmax-aYmin, aZmax-aZmin)) *
96 aDrawer->DeviationCoefficient() * 4;
102 void AIS_Shape::DisplayBox(const Handle(Prs3d_Presentation)& aPrs,
104 const Handle(Prs3d_Drawer)& aDrawer)
106 static const Standard_Integer Indx[][3] =
107 { { 0, 0, 0 }, { 1, 0, 0 }, { 1, 0, 1 }, { 0, 0, 1 },
108 { 0, 1, 1 }, { 1, 1, 1 }, { 1, 1, 0 }, { 0, 1, 0 },
109 { 0, 0, 0 }, { 0, 0, 1 }, { 1, 0, 1 }, { 1, 1, 1 },
110 { 0, 1, 1 }, { 0, 1, 0 }, { 1, 1, 0 }, { 1, 0, 0 } };
113 return; // nothing to show
115 Standard_Real X[2],Y[2],Z[2];
116 B.Get(X[0], Y[0], Z[0], X[1], Y[1], Z[1]);
118 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(aPrs);
122 aDrawer->LineAspect()->Aspect()->Values(Q,A,W);
124 G->SetGroupPrimitivesAspect(new Graphic3d_AspectLine3d(Q,Aspect_TOL_DOTDASH,W));
126 Handle(Graphic3d_ArrayOfPolylines) aPolyline = new Graphic3d_ArrayOfPolylines(16);
127 Standard_Integer i(0);
129 aPolyline->AddVertex(X[Indx[i][0]],Y[Indx[i][1]],Z[Indx[i][2]]);
130 G->AddPrimitiveArray(aPolyline);
133 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
135 TColStd_ListIteratorOfListOfInteger It(LL);
136 for(;It.More();It.Next()){
137 if(It.Value()==aMode)
138 return Standard_True;}
139 return Standard_False;
142 //==================================================
145 //==================================================
148 AIS_Shape(const TopoDS_Shape& shap):
149 AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
151 myCompBB(Standard_True),
154 myFirstCompute = Standard_True;
156 myDrawer->SetShadingAspectGlobal(Standard_False);
159 //=======================================================================
162 //=======================================================================
163 AIS_KindOfInteractive AIS_Shape::Type() const
164 {return AIS_KOI_Shape;}
167 //=======================================================================
168 //function : Signature
170 //=======================================================================
171 Standard_Integer AIS_Shape::Signature() const
174 //=======================================================================
175 //function : AcceptShapeDecomposition
177 //=======================================================================
178 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
179 {return Standard_True;}
181 //=======================================================================
184 //=======================================================================
185 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
186 const Handle(Prs3d_Presentation)& aPrs,
187 const Standard_Integer aMode)
190 if(myshape.IsNull()) return;
192 // wire,edge,vertex -> pas de HLR + priorite display superieure
193 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
194 if(TheType>4 && TheType<8) {
195 aPrs->SetVisual(Graphic3d_TOS_ALL);
196 aPrs->SetDisplayPriority(TheType+2);
198 // Shape vide -> Assemblage vide.
199 if (myshape.ShapeType() == TopAbs_COMPOUND) {
200 TopoDS_Iterator anExplor (myshape);
202 if (!anExplor.More()) {
207 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //not taken in account duting FITALL
210 try { OCC_CATCH_SIGNALS StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); }
211 catch (Standard_Failure) {
213 cout << "AIS_Shape::Compute() failed"<< endl;
215 cout << "a Shape should be incorrect : No Compute can be maked on it "<< endl;
216 // presentation of the bounding box is calculated
217 // Compute(aPresentationManager,aPrs,2);
223 Standard_Real prevangle ;
224 Standard_Real newangle ;
225 Standard_Real prevcoeff ;
226 Standard_Real newcoeff ;
229 if (OwnDeviationAngle(newangle,prevangle) ||
230 OwnDeviationCoefficient(newcoeff,prevcoeff))
231 if (Abs (newangle - prevangle) > Precision::Angular() ||
232 Abs (newcoeff - prevcoeff) > Precision::Confusion() ) {
234 cout << "AIS_Shape : compute"<<endl;
235 cout << "newangl : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
236 cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
238 BRepTools::Clean(myshape);
241 //shading only on face...
242 if ((Standard_Integer) myshape.ShapeType()>4)
243 StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
245 myDrawer->SetShadingAspectGlobal(Standard_False);
246 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
251 StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
253 catch (Standard_Failure) {
255 cout << "AIS_Shape::Compute() in ShadingMode failed"<< endl;
257 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
262 Standard_Real value = Transparency() ;
264 SetTransparency( value );
271 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
272 else DisplayBox(aPrs,BoundingBox(),myDrawer);
275 aPrs->ReCompute(); // for hidden line recomputation if necessary...
278 //=======================================================================
280 //purpose : Hidden Line Removal
281 //=======================================================================
282 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
283 const Handle(Prs3d_Presentation)& aPresentation)
285 Compute(aProjector,aPresentation,myshape);
288 //=======================================================================
291 //=======================================================================
293 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
294 const Handle(Geom_Transformation)& TheTrsf,
295 const Handle(Prs3d_Presentation)& aPresentation)
297 const TopLoc_Location& loc = myshape.Location();
298 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
299 Compute(aProjector,aPresentation,shbis);
302 //=======================================================================
305 //=======================================================================
307 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
308 const Handle(Prs3d_Presentation)& aPresentation,
309 const TopoDS_Shape& SH)
311 if (SH.ShapeType() == TopAbs_COMPOUND) {
312 TopoDS_Iterator anExplor (SH);
314 if (!anExplor.More()) // Shape vide -> Assemblage vide.
318 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
319 if (defdrawer->DrawHiddenLine())
320 {myDrawer->EnableDrawHiddenLine();}
321 else {myDrawer->DisableDrawHiddenLine();}
323 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
324 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
326 // coefficients for calculation
328 Standard_Real prevangle, newangle ,prevcoeff,newcoeff ;
329 if (OwnHLRDeviationAngle(newangle,prevangle) || OwnHLRDeviationCoefficient(newcoeff, prevcoeff))
330 if (Abs (newangle - prevangle) > Precision::Angular() ||
331 Abs (newcoeff - prevcoeff) > Precision::Confusion() ) {
333 cout << "AIS_Shape : compute"<<endl;
334 cout << "newangle : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
335 cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
337 BRepTools::Clean(SH);
343 switch (TypeOfHLR()) {
345 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
347 case Prs3d_TOH_PolyAlgo:
349 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
353 catch (Standard_Failure) {
355 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
357 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
361 defdrawer->SetTypeOfDeflection (prevdef);
364 //=======================================================================
365 //function : SelectionType
366 //purpose : gives the type according to the Index of Selection Mode
367 //=======================================================================
369 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
373 return TopAbs_VERTEX;
385 return TopAbs_COMPSOLID;
387 return TopAbs_COMPOUND;
394 //=======================================================================
395 //function : SelectionType
396 //purpose : gives the SelectionMode according to the Type od Decomposition...
397 //=======================================================================
398 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
413 case TopAbs_COMPSOLID:
415 case TopAbs_COMPOUND:
424 //=======================================================================
425 //function : ComputeSelection
427 //=======================================================================
429 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
430 const Standard_Integer aMode)
432 if(myshape.IsNull()) return;
433 if (myshape.ShapeType() == TopAbs_COMPOUND) {
434 TopoDS_Iterator anExplor (myshape);
436 if (!anExplor.More()) // empty Shape -> empty Assembly.
440 static TopAbs_ShapeEnum TypOfSel;
441 TypOfSel = AIS_Shape::SelectionType(aMode);
442 TopoDS_Shape shape = myshape;
443 if( HasTransformation() ) {
444 Handle(Geom_Transformation) trsf = Transformation();
445 shape = shape.Located(TopLoc_Location(trsf->Trsf())*shape.Location());
448 // POP protection against crash in low layers
450 Standard_Real aDeflection = GetDeflection(shape, myDrawer);
451 Standard_Boolean autoTriangulation = Standard_True;
454 StdSelect_BRepSelectionTool::Load(aSelection,
459 myDrawer->HLRAngle(),
461 } catch ( Standard_Failure ) {
462 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
464 Bnd_Box B = BoundingBox();
465 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
466 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
467 aSelection->Add(aSensitiveBox);
471 // insert the drawer in the BrepOwners for hilight...
472 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
475 Quantity_NameOfColor AIS_Shape::Color() const {
476 Quantity_Color aColor;
478 return aColor.Name();
481 void AIS_Shape::Color( Quantity_Color& aColor ) const {
482 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
485 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
486 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
489 Standard_Real AIS_Shape::Transparency() const {
490 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
493 //=======================================================================
494 //function : SetColor
496 //=======================================================================
498 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
500 SetColor(Quantity_Color(aCol));
503 //=======================================================================
504 //function : SetColor
506 //=======================================================================
508 void AIS_Shape::SetColor(const Quantity_Color &aCol)
510 if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
511 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
513 hasOwnColor = Standard_True;
515 myDrawer->ShadingAspect()->SetColor(aCol,myCurrentFacingModel);
516 myDrawer->ShadingAspect()->SetTransparency(myTransparency,myCurrentFacingModel);
517 myDrawer->SetShadingAspectGlobal(Standard_False);
520 const Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
522 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
523 myDrawer->SetWireAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
524 myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
525 myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
526 myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
528 // fast shading modification...
529 if(!GetContext().IsNull()){
530 if( GetContext()->MainPrsMgr()->HasPresentation(this,1)){
531 Handle(Prs3d_Presentation) aPresentation =
532 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
533 Handle(Graphic3d_Group) aCurGroup = Prs3d_Root::CurrentGroup(aPresentation);
534 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
535 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
537 // Set aspects for presentation and for group
538 aPresentation->SetPrimitivesAspect(anAreaAspect);
539 aPresentation->SetPrimitivesAspect(aLineAspect);
540 // Check if aspect of given type is set for the group,
541 // because setting aspect for group with no already set aspect
542 // can lead to loss of presentation data
543 if (aCurGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
544 aCurGroup->SetGroupPrimitivesAspect(anAreaAspect);
545 if (aCurGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_LINE))
546 aCurGroup->SetGroupPrimitivesAspect(aLineAspect);
554 //=======================================================================
555 //function : UnsetColor
557 //=======================================================================
559 void AIS_Shape::UnsetColor()
563 myToRecomputeModes.Clear();
566 hasOwnColor = Standard_False;
568 Handle(Prs3d_LineAspect) NullAsp;
569 Handle(Prs3d_ShadingAspect) NullShA;
572 myDrawer->SetLineAspect(NullAsp);
573 myDrawer->SetWireAspect(NullAsp);
574 myDrawer->SetFreeBoundaryAspect(NullAsp);
575 myDrawer->SetUnFreeBoundaryAspect(NullAsp);
576 myDrawer->SetSeenLineAspect(NullAsp);
580 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
581 myDrawer->LineAspect()->SetColor(CC);
582 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire,CC);
583 myDrawer->WireAspect()->SetColor(CC);
584 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free,CC);
585 myDrawer->FreeBoundaryAspect()->SetColor(CC);
586 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree,CC);
587 myDrawer->UnFreeBoundaryAspect()->SetColor(CC);
588 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen,CC);
589 myDrawer->SeenLineAspect()->SetColor(CC);
592 if( HasMaterial() || IsTransparent()) {
593 Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
594 if( HasMaterial() ) {
595 Quantity_Color color = myDrawer->Link()->ShadingAspect()->Color(myCurrentFacingModel);
598 if( IsTransparent() ) {
599 Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
600 mat.SetTransparency(trans);
602 myDrawer->ShadingAspect()->SetMaterial(mat,myCurrentFacingModel);
605 myDrawer->SetShadingAspect(NullShA);
608 if(!GetContext().IsNull()){
609 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
610 Handle(Prs3d_Presentation) aPresentation =
611 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
612 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
614 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
615 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
617 AIS_GraphicTool::GetInteriorColor(myDrawer->Link(),CC);
618 anAreaAsp->SetInteriorColor(CC);
619 aPresentation->SetPrimitivesAspect(anAreaAsp);
620 aPresentation->SetPrimitivesAspect(aLineAsp);
621 // Check if aspect of given type is set for the group,
622 // because setting aspect for group with no already set aspect
623 // can lead to loss of presentation data
624 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
625 aGroup->SetGroupPrimitivesAspect(anAreaAsp);
626 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_LINE))
627 aGroup->SetGroupPrimitivesAspect(aLineAsp);
634 //=======================================================================
635 //function : SetWidth
637 //=======================================================================
639 void AIS_Shape::SetWidth(const Standard_Real W)
641 if(HasColor() || HasWidth()){
642 myDrawer->LineAspect()->SetWidth(W);
643 myDrawer->WireAspect()->SetWidth(W);
644 myDrawer->FreeBoundaryAspect()->SetWidth(W);
645 myDrawer->UnFreeBoundaryAspect()->SetWidth(W);
646 myDrawer->SeenLineAspect()->SetWidth(W);
650 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
651 myDrawer->SetLineAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
652 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire,CC);
653 myDrawer->SetWireAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
654 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free,CC);
655 myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
656 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree,CC);
657 myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
658 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen,CC);
659 myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
662 LoadRecomputable(0); // means that it is necessary to recompute only the wireframe....
663 LoadRecomputable(2); // and the bounding box...
666 //=======================================================================
667 //function : UnsetWidth
669 //=======================================================================
671 void AIS_Shape::UnsetWidth()
673 if(myOwnWidth == 0.0)
675 myToRecomputeModes.Clear();
680 Handle(Prs3d_LineAspect) NullAsp;
683 myDrawer->SetLineAspect(NullAsp);
684 myDrawer->SetWireAspect(NullAsp);
685 myDrawer->SetFreeBoundaryAspect(NullAsp);
686 myDrawer->SetUnFreeBoundaryAspect(NullAsp);
687 myDrawer->SetSeenLineAspect(NullAsp);
690 myDrawer->LineAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line));
691 myDrawer->WireAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Wire));
692 myDrawer->FreeBoundaryAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Free));
693 myDrawer->UnFreeBoundaryAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_UnFree));
694 myDrawer->SeenLineAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Seen));
699 //=======================================================================
700 //function : SetMaterial
702 //=======================================================================
704 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
706 SetMaterial(Graphic3d_MaterialAspect(aMat));
709 //=======================================================================
710 //function : SetMaterial
712 //=======================================================================
714 void AIS_Shape::SetMaterial(const Graphic3d_MaterialAspect& aMat)
716 if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
717 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
719 hasOwnMaterial = Standard_True;
721 myDrawer->ShadingAspect()->SetMaterial(aMat,myCurrentFacingModel);
722 myDrawer->ShadingAspect()->SetTransparency(myTransparency,myCurrentFacingModel);
724 if(!GetContext().IsNull()){
725 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
726 Handle(Prs3d_Presentation) aPresentation =
727 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
728 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
730 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
731 aPresentation->SetPrimitivesAspect(anAreaAsp);
732 // Check if aspect of given type is set for the group,
733 // because setting aspect for group with no already set aspect
734 // can lead to loss of presentation data
735 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
736 aGroup->SetGroupPrimitivesAspect(anAreaAsp);
738 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
739 myToRecomputeModes.Clear();
742 //=======================================================================
743 //function : UnsetMaterial
745 //=======================================================================
747 void AIS_Shape::UnsetMaterial()
749 if( !HasMaterial() ) return;
751 if( HasColor() || IsTransparent()) {
752 Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(myDrawer->Link());
754 Quantity_Color color = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
757 if( IsTransparent() ) {
758 Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
759 mat.SetTransparency(trans);
761 myDrawer->ShadingAspect()->SetMaterial(mat,myCurrentFacingModel);
763 Handle(Prs3d_ShadingAspect) SA;
764 myDrawer->SetShadingAspect(SA);
766 hasOwnMaterial = Standard_False;
767 if(!GetContext().IsNull()){
768 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
769 Handle(Prs3d_Presentation) aPresentation =
770 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
771 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
772 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
773 aPresentation->SetPrimitivesAspect(anAreaAsp);
774 // Check if aspect of given type is set for the group,
775 // because setting aspect for group with no already set aspect
776 // can lead to loss of presentation data
777 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
778 aGroup->SetGroupPrimitivesAspect(anAreaAsp);
781 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
782 myToRecomputeModes.Clear();
785 //=======================================================================
786 //function : SetTransparency
788 //=======================================================================
790 void AIS_Shape::SetTransparency(const Standard_Real AValue)
792 if ( !HasColor() && !HasMaterial() ) {
793 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
795 myDrawer->ShadingAspect()->SetTransparency(AValue,myCurrentFacingModel);
796 myTransparency = AValue;
798 if(!GetContext().IsNull()){
799 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
800 Handle(Prs3d_Presentation) aPresentation =
801 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
802 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
803 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
804 aPresentation->SetPrimitivesAspect(anAreaAsp);
805 //force highest priority for transparent objects
806 aPresentation->SetDisplayPriority(10);
807 // Check if aspect of given type is set for the group,
808 // because setting aspect for group with no already set aspect
809 // can lead to loss of presentation data
810 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
811 aGroup->SetGroupPrimitivesAspect(anAreaAsp);
814 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
815 myToRecomputeModes.Clear();
818 //=======================================================================
819 //function : UnsetTransparency
821 //=======================================================================
823 void AIS_Shape::UnsetTransparency()
825 if( HasColor() || HasMaterial() ) {
826 myDrawer->ShadingAspect()->SetTransparency(0.0,myCurrentFacingModel);
828 Handle(Prs3d_ShadingAspect) SA;
829 myDrawer->SetShadingAspect(SA);
832 myTransparency = 0.0;
834 if(!GetContext().IsNull()){
835 if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
836 Handle(Prs3d_Presentation) aPresentation =
837 GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
838 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
839 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
840 aPresentation->SetPrimitivesAspect(anAreaAsp);
841 // Check if aspect of given type is set for the group,
842 // because setting aspect for group with no already set aspect
843 // can lead to loss of presentation data
844 if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
845 aGroup->SetGroupPrimitivesAspect(anAreaAsp);
847 aPresentation->ResetDisplayPriority();
850 myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
851 myToRecomputeModes.Clear();
854 //=======================================================================
855 //function : LoadRecomputable
857 //=======================================================================
859 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
861 myRecomputeEveryPrs = Standard_False;
862 if(!IsInList(myToRecomputeModes,TheMode))
863 myToRecomputeModes.Append(TheMode);
866 //=======================================================================
867 //function : BoundingBox
869 //=======================================================================
871 const Bnd_Box& AIS_Shape::BoundingBox()
873 if (myshape.ShapeType() == TopAbs_COMPOUND) {
874 TopoDS_Iterator anExplor (myshape);
876 if (!anExplor.More()) { // empty Shape -> empty Assembly.
883 BRepBndLib::AddClose(myshape, myBB);
884 myCompBB = Standard_False;
891 //=======================================================================
892 //function : SetOwnDeviationCoefficient
893 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
894 // returns Standard_True if it change
895 //=======================================================================
897 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
899 Standard_Boolean itSet = myDrawer->IsOwnDeviationCoefficient();
900 if(itSet) myDrawer->SetDeviationCoefficient();
904 //=======================================================================
905 //function : SetHLROwnDeviationCoefficient
906 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
907 // returns Standard_True if it change
908 //=======================================================================
910 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
912 Standard_Boolean itSet = myDrawer->IsOwnHLRDeviationCoefficient();
913 if(itSet) myDrawer->SetHLRDeviationCoefficient();
918 //=======================================================================
919 //function : SetOwnDeviationAngle
920 //purpose : resets myhasOwnDeviationAngle to Standard_False and
921 // returns Standard_True if it change
922 //=======================================================================
924 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
926 Standard_Boolean itSet = myDrawer->IsOwnDeviationAngle();
927 if(itSet) myDrawer->SetDeviationAngle();
932 //=======================================================================
933 //function : SetOwnHLRDeviationAngle
934 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
935 // returns Standard_True if it change
936 //=======================================================================
938 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
940 Standard_Boolean itSet = myDrawer->IsOwnHLRDeviationAngle();
941 if(itSet) myDrawer->SetHLRAngle();
946 //=======================================================================
947 //function : SetOwnDeviationCoefficient
949 //=======================================================================
951 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
953 myDrawer->SetDeviationCoefficient( aCoefficient );
954 SetToUpdate(0) ; // WireFrame
955 SetToUpdate(1) ; // Shadding
958 //=======================================================================
959 //function : SetOwnHLRDeviationCoefficient
961 //=======================================================================
963 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
965 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
969 //=======================================================================
970 //function : SetOwnDeviationAngle
972 //=======================================================================
974 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
977 myDrawer->SetDeviationAngle(anAngle );
978 SetToUpdate(0) ; // WireFrame
980 //=======================================================================
981 //function : SetOwnDeviationAngle
983 //=======================================================================
985 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
987 Standard_Real OutAngl,OutDefl;
988 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
989 SetOwnDeviationAngle(anAngle) ;
990 SetOwnDeviationCoefficient(OutDefl) ;
996 //=======================================================================
997 //function : UserAngle
999 //=======================================================================
1001 Standard_Real AIS_Shape::UserAngle() const
1003 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1007 //=======================================================================
1008 //function : SetHLRAngleAndDeviation
1010 //=======================================================================
1012 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1014 Standard_Real OutAngl,OutDefl;
1015 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1016 SetOwnHLRDeviationAngle( OutAngl );
1017 SetOwnHLRDeviationCoefficient(OutDefl);
1020 //=======================================================================
1021 //function : SetOwnHLRDeviationAngle
1023 //=======================================================================
1025 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1027 myDrawer->SetHLRAngle( anAngle );
1031 //=======================================================================
1032 //function : OwnDeviationCoefficient
1034 //=======================================================================
1036 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1037 Standard_Real & aPreviousCoefficient ) const
1039 aCoefficient = myDrawer->DeviationCoefficient();
1040 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1041 return myDrawer->IsOwnDeviationCoefficient() ;
1044 //=======================================================================
1045 //function : OwnHLRDeviationCoefficient
1047 //=======================================================================
1049 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1050 Standard_Real & aPreviousCoefficient ) const
1052 aCoefficient = myDrawer->HLRDeviationCoefficient();
1053 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1054 return myDrawer->IsOwnHLRDeviationCoefficient();
1058 //=======================================================================
1059 //function : OwnDeviationAngle
1061 //=======================================================================
1063 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1064 Standard_Real & aPreviousAngle ) const
1066 anAngle = myDrawer->DeviationAngle();
1067 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1068 return myDrawer->IsOwnDeviationAngle();
1071 //=======================================================================
1072 //function : OwnHLRDeviationAngle
1074 //=======================================================================
1076 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1077 Standard_Real & aPreviousAngle ) const
1079 anAngle = myDrawer->HLRAngle();
1080 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1081 return myDrawer->IsOwnHLRDeviationAngle();