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 void AIS_Shape::DisplayBox(const Handle(Prs3d_Presentation)& aPrs,
82 const Handle(Prs3d_Drawer)& aDrawer)
84 static const Standard_Integer Indx[][3] =
85 { { 0, 0, 0 }, { 1, 0, 0 }, { 1, 0, 1 }, { 0, 0, 1 },
86 { 0, 1, 1 }, { 1, 1, 1 }, { 1, 1, 0 }, { 0, 1, 0 },
87 { 0, 0, 0 }, { 0, 0, 1 }, { 1, 0, 1 }, { 1, 1, 1 },
88 { 0, 1, 1 }, { 0, 1, 0 }, { 1, 1, 0 }, { 1, 0, 0 } };
91 return; // nothing to show
93 Standard_Real X[2],Y[2],Z[2];
94 B.Get(X[0], Y[0], Z[0], X[1], Y[1], Z[1]);
96 Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(aPrs);
100 aDrawer->LineAspect()->Aspect()->Values(Q,A,W);
102 G->SetGroupPrimitivesAspect(new Graphic3d_AspectLine3d(Q,Aspect_TOL_DOTDASH,W));
104 Handle(Graphic3d_ArrayOfPolylines) aPolyline = new Graphic3d_ArrayOfPolylines(16);
105 Standard_Integer i(0);
107 aPolyline->AddVertex(X[Indx[i][0]],Y[Indx[i][1]],Z[Indx[i][2]]);
108 G->AddPrimitiveArray(aPolyline);
111 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
113 TColStd_ListIteratorOfListOfInteger It(LL);
114 for(;It.More();It.Next()){
115 if(It.Value()==aMode)
116 return Standard_True;}
117 return Standard_False;
120 //==================================================
123 //==================================================
126 AIS_Shape(const TopoDS_Shape& shap):
127 AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
129 myCompBB(Standard_True),
132 myFirstCompute = Standard_True;
134 myDrawer->SetShadingAspectGlobal(Standard_False);
137 //=======================================================================
140 //=======================================================================
141 AIS_KindOfInteractive AIS_Shape::Type() const
142 {return AIS_KOI_Shape;}
145 //=======================================================================
146 //function : Signature
148 //=======================================================================
149 Standard_Integer AIS_Shape::Signature() const
152 //=======================================================================
153 //function : AcceptShapeDecomposition
155 //=======================================================================
156 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
157 {return Standard_True;}
159 //=======================================================================
162 //=======================================================================
163 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
164 const Handle(Prs3d_Presentation)& aPrs,
165 const Standard_Integer aMode)
168 if(myshape.IsNull()) return;
170 // wire,edge,vertex -> pas de HLR + priorite display superieure
171 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
172 if(TheType>4 && TheType<8) {
173 aPrs->SetVisual(Graphic3d_TOS_ALL);
174 aPrs->SetDisplayPriority(TheType+2);
176 // Shape vide -> Assemblage vide.
177 if (myshape.ShapeType() == TopAbs_COMPOUND) {
178 TopoDS_Iterator anExplor (myshape);
180 if (!anExplor.More()) {
185 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //not taken in account duting FITALL
188 try { OCC_CATCH_SIGNALS StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); }
189 catch (Standard_Failure) {
191 cout << "AIS_Shape::Compute() failed"<< endl;
193 cout << "a Shape should be incorrect : No Compute can be maked on it "<< endl;
194 // presentation of the bounding box is calculated
195 // Compute(aPresentationManager,aPrs,2);
201 Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
202 Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
203 Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
204 if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
205 || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
207 BRepTools::Clean (myshape);
210 //shading only on face...
211 if ((Standard_Integer) myshape.ShapeType()>4)
212 StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
214 myDrawer->SetShadingAspectGlobal(Standard_False);
215 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
220 StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
222 catch (Standard_Failure) {
224 cout << "AIS_Shape::Compute() in ShadingMode failed"<< endl;
226 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
231 Standard_Real value = Transparency() ;
233 SetTransparency( value );
240 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
241 else DisplayBox(aPrs,BoundingBox(),myDrawer);
244 aPrs->ReCompute(); // for hidden line recomputation if necessary...
247 //=======================================================================
249 //purpose : Hidden Line Removal
250 //=======================================================================
251 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
252 const Handle(Prs3d_Presentation)& aPresentation)
254 Compute(aProjector,aPresentation,myshape);
257 //=======================================================================
260 //=======================================================================
262 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
263 const Handle(Geom_Transformation)& TheTrsf,
264 const Handle(Prs3d_Presentation)& aPresentation)
266 const TopLoc_Location& loc = myshape.Location();
267 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
268 Compute(aProjector,aPresentation,shbis);
271 //=======================================================================
274 //=======================================================================
276 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
277 const Handle(Prs3d_Presentation)& aPresentation,
278 const TopoDS_Shape& SH)
280 if (SH.ShapeType() == TopAbs_COMPOUND) {
281 TopoDS_Iterator anExplor (SH);
283 if (!anExplor.More()) // Shape vide -> Assemblage vide.
287 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
288 if (defdrawer->DrawHiddenLine())
289 {myDrawer->EnableDrawHiddenLine();}
290 else {myDrawer->DisableDrawHiddenLine();}
292 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
293 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
295 // coefficients for calculation
297 Standard_Real prevangle, newangle ,prevcoeff,newcoeff ;
298 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle(newangle,prevangle);
299 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient(newcoeff,prevcoeff);
300 if (((Abs (newangle - prevangle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
301 ((Abs (newcoeff - prevcoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient)) {
303 cout << "AIS_Shape : compute"<<endl;
304 cout << "newangle : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
305 cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
307 BRepTools::Clean(SH);
313 switch (TypeOfHLR()) {
315 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
317 case Prs3d_TOH_PolyAlgo:
319 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
323 catch (Standard_Failure) {
325 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
327 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
331 defdrawer->SetTypeOfDeflection (prevdef);
334 //=======================================================================
335 //function : SelectionType
336 //purpose : gives the type according to the Index of Selection Mode
337 //=======================================================================
339 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
343 return TopAbs_VERTEX;
355 return TopAbs_COMPSOLID;
357 return TopAbs_COMPOUND;
364 //=======================================================================
365 //function : SelectionType
366 //purpose : gives the SelectionMode according to the Type od Decomposition...
367 //=======================================================================
368 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
383 case TopAbs_COMPSOLID:
385 case TopAbs_COMPOUND:
394 //=======================================================================
395 //function : ComputeSelection
397 //=======================================================================
399 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
400 const Standard_Integer aMode)
402 if(myshape.IsNull()) return;
403 if (myshape.ShapeType() == TopAbs_COMPOUND) {
404 TopoDS_Iterator anExplor (myshape);
406 if (!anExplor.More()) // empty Shape -> empty Assembly.
410 static TopAbs_ShapeEnum TypOfSel;
411 TypOfSel = AIS_Shape::SelectionType(aMode);
412 TopoDS_Shape shape = myshape;
413 if( HasTransformation() ) {
414 Handle(Geom_Transformation) trsf = Transformation();
415 shape = shape.Located(TopLoc_Location(trsf->Trsf())*shape.Location());
418 // POP protection against crash in low layers
420 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
421 Standard_Boolean autoTriangulation = Standard_True;
424 StdSelect_BRepSelectionTool::Load(aSelection,
429 myDrawer->HLRAngle(),
431 } catch ( Standard_Failure ) {
432 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
434 Bnd_Box B = BoundingBox();
435 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
436 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
437 aSelection->Add(aSensitiveBox);
441 // insert the drawer in the BrepOwners for hilight...
442 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
445 Quantity_NameOfColor AIS_Shape::Color() const {
446 Quantity_Color aColor;
448 return aColor.Name();
451 void AIS_Shape::Color( Quantity_Color& aColor ) const {
452 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
455 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
456 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
459 Standard_Real AIS_Shape::Transparency() const {
460 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
463 //=======================================================================
464 //function : SetColor
466 //=======================================================================
468 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
470 SetColor(Quantity_Color(aCol));
473 //=======================================================================
474 //function : setColor
476 //=======================================================================
478 void AIS_Shape::setColor (const Handle(AIS_Drawer)& theDrawer,
479 const Quantity_Color& theColor) const
481 if (!theDrawer->HasShadingAspect())
483 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
484 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
486 if (!theDrawer->HasLineAspect())
488 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
489 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
491 if (!theDrawer->HasWireAspect())
493 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
494 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
496 if (!theDrawer->HasPointAspect())
498 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
499 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
501 // disable dedicated line aspects
502 theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect());
503 theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect());
504 theDrawer->SetSeenLineAspect (theDrawer->LineAspect());
507 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
508 theDrawer->SetShadingAspectGlobal (Standard_False);
509 theDrawer->LineAspect()->SetColor (theColor);
510 theDrawer->WireAspect()->SetColor (theColor);
511 theDrawer->PointAspect()->SetColor (theColor);
514 //=======================================================================
515 //function : SetColor
517 //=======================================================================
519 void AIS_Shape::SetColor (const Quantity_Color& theColor)
521 setColor (myDrawer, theColor);
522 myOwnColor = theColor;
523 hasOwnColor = Standard_True;
525 // modify shading presentation without re-computation
526 const PrsMgr_Presentations& aPrsList = Presentations();
527 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
528 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
529 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
530 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
532 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
533 if (aPrsModed.Mode() != AIS_Shaded)
538 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
540 // Set aspects for presentation
541 aPrs->SetPrimitivesAspect (anAreaAspect);
542 aPrs->SetPrimitivesAspect (aLineAspect);
543 aPrs->SetPrimitivesAspect (aPointAspect);
545 // Go through all groups to change color for all primitives
546 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
548 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
550 // Check if aspect of given type is set for the group,
551 // because setting aspect for group with no already set aspect
552 // can lead to loss of presentation data
553 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
555 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
557 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
559 aGroup->SetGroupPrimitivesAspect (aLineAspect);
561 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
563 aGroup->SetGroupPrimitivesAspect (aPointAspect);
568 LoadRecomputable (AIS_WireFrame);
569 LoadRecomputable (2);
572 //=======================================================================
573 //function : UnsetColor
575 //=======================================================================
577 void AIS_Shape::UnsetColor()
581 myToRecomputeModes.Clear();
584 hasOwnColor = Standard_False;
588 Handle(Prs3d_LineAspect) anEmptyAsp;
589 myDrawer->SetLineAspect (anEmptyAsp);
590 myDrawer->SetWireAspect (anEmptyAsp);
591 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
592 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
593 myDrawer->SetSeenLineAspect (anEmptyAsp);
597 Quantity_Color aColor;
598 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
599 myDrawer->LineAspect()->SetColor (aColor);
600 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
601 myDrawer->WireAspect()->SetColor (aColor);
602 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
603 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
604 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
605 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
606 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
607 myDrawer->SeenLineAspect()->SetColor (aColor);
613 Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
616 Quantity_Color aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
617 mat.SetColor (aColor);
621 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
622 mat.SetTransparency (aTransp);
624 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
628 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
630 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
632 // modify shading presentation without re-computation
633 const PrsMgr_Presentations& aPrsList = Presentations();
634 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
635 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
636 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
638 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
639 if (aPrsModed.Mode() != AIS_Shaded)
644 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
646 aPrs->SetPrimitivesAspect (anAreaAsp);
647 aPrs->SetPrimitivesAspect (aLineAsp);
649 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
651 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
653 // Check if aspect of given type is set for the group,
654 // because setting aspect for group with no already set aspect
655 // can lead to loss of presentation data
656 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
658 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
660 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
662 aGroup->SetGroupPrimitivesAspect (aLineAsp);
667 LoadRecomputable (AIS_WireFrame);
668 LoadRecomputable (2);
671 //=======================================================================
672 //function : setWidth
674 //=======================================================================
676 void AIS_Shape::setWidth (const Handle(AIS_Drawer)& theDrawer,
677 const Standard_Real theLineWidth) const
679 if (!theDrawer->HasLineAspect())
681 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
682 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
684 if (!theDrawer->HasWireAspect())
686 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
687 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
689 // disable dedicated line aspects
690 theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect());
691 theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect());
692 theDrawer->SetSeenLineAspect (theDrawer->LineAspect());
695 theDrawer->LineAspect()->SetWidth (theLineWidth);
696 theDrawer->WireAspect()->SetWidth (theLineWidth);
699 //=======================================================================
700 //function : SetWidth
702 //=======================================================================
704 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
706 setWidth (myDrawer, theLineWidth);
707 myOwnWidth = theLineWidth;
708 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
709 LoadRecomputable (2); // and the bounding box...
712 //=======================================================================
713 //function : UnsetWidth
715 //=======================================================================
717 void AIS_Shape::UnsetWidth()
719 if (myOwnWidth == 0.0)
721 myToRecomputeModes.Clear();
727 Handle(Prs3d_LineAspect) anEmptyAsp;
731 myDrawer->SetLineAspect (anEmptyAsp);
732 myDrawer->SetWireAspect (anEmptyAsp);
733 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
734 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
735 myDrawer->SetSeenLineAspect (anEmptyAsp);
739 myDrawer->LineAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line));
740 myDrawer->WireAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire));
741 myDrawer->FreeBoundaryAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free));
742 myDrawer->UnFreeBoundaryAspect()->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree));
743 myDrawer->SeenLineAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen));
745 LoadRecomputable (AIS_WireFrame);
748 //=======================================================================
749 //function : SetMaterial
751 //=======================================================================
753 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
755 SetMaterial(Graphic3d_MaterialAspect(aMat));
758 //=======================================================================
759 //function : SetMaterial
761 //=======================================================================
763 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
765 if (!myDrawer->HasShadingAspect())
767 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
768 *myDrawer->ShadingAspect()->Aspect() = *myDrawer->Link()->ShadingAspect()->Aspect();
770 hasOwnMaterial = Standard_True;
772 myDrawer->ShadingAspect()->SetMaterial (theMat, myCurrentFacingModel);
775 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
777 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
779 // modify shading presentation without re-computation
780 const PrsMgr_Presentations& aPrsList = Presentations();
781 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
782 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
784 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
785 if (aPrsModed.Mode() != AIS_Shaded)
790 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
791 aPrs->SetPrimitivesAspect (anAreaAsp);
792 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
794 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
796 // Check if aspect of given type is set for the group,
797 // because setting aspect for group with no already set aspect
798 // can lead to loss of presentation data
799 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
801 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
806 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
807 myToRecomputeModes.Clear();
810 //=======================================================================
811 //function : UnsetMaterial
813 //=======================================================================
815 void AIS_Shape::UnsetMaterial()
825 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
826 myCurrentFacingModel);
829 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
830 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
835 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
837 hasOwnMaterial = Standard_False;
839 // modify shading presentation without re-computation
840 const PrsMgr_Presentations& aPrsList = Presentations();
841 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
842 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
844 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
845 if (aPrsModed.Mode() != AIS_Shaded)
850 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
851 aPrs->SetPrimitivesAspect (anAreaAsp);
852 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
854 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
855 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
857 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
862 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
863 myToRecomputeModes.Clear();
866 //=======================================================================
867 //function : setTransparency
869 //=======================================================================
871 void AIS_Shape::setTransparency (const Handle(AIS_Drawer)& theDrawer,
872 const Standard_Real theValue) const
874 if (!theDrawer->HasShadingAspect())
876 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
877 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
880 // override transparency
881 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
884 //=======================================================================
885 //function : SetTransparency
887 //=======================================================================
889 void AIS_Shape::SetTransparency (const Standard_Real theValue)
891 setTransparency (myDrawer, theValue);
892 myTransparency = theValue;
894 // modify shading presentation without re-computation
895 const PrsMgr_Presentations& aPrsList = Presentations();
896 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
897 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
899 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
900 if (aPrsModed.Mode() != AIS_Shaded)
905 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
906 aPrs->SetPrimitivesAspect (anAreaAsp);
907 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
908 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
910 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
911 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
913 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
918 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
919 myToRecomputeModes.Clear();
922 //=======================================================================
923 //function : UnsetTransparency
925 //=======================================================================
927 void AIS_Shape::UnsetTransparency()
929 myTransparency = 0.0;
930 if (!myDrawer->HasShadingAspect())
934 else if (HasColor() || HasMaterial())
936 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
940 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
943 // modify shading presentation without re-computation
944 const PrsMgr_Presentations& aPrsList = Presentations();
945 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
946 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
948 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
949 if (aPrsModed.Mode() != AIS_Shaded)
954 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
955 aPrs->SetPrimitivesAspect (anAreaAsp);
956 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
958 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
959 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
961 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
964 aPrs->ResetDisplayPriority();
967 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
968 myToRecomputeModes.Clear();
971 //=======================================================================
972 //function : LoadRecomputable
974 //=======================================================================
976 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
978 myRecomputeEveryPrs = Standard_False;
979 if(!IsInList(myToRecomputeModes,TheMode))
980 myToRecomputeModes.Append(TheMode);
983 //=======================================================================
984 //function : BoundingBox
986 //=======================================================================
988 const Bnd_Box& AIS_Shape::BoundingBox()
990 if (myshape.ShapeType() == TopAbs_COMPOUND) {
991 TopoDS_Iterator anExplor (myshape);
993 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1000 BRepBndLib::AddClose(myshape, myBB);
1001 myCompBB = Standard_False;
1008 //=======================================================================
1009 //function : SetOwnDeviationCoefficient
1010 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1011 // returns Standard_True if it change
1012 //=======================================================================
1014 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1016 Standard_Boolean itSet = myDrawer->IsOwnDeviationCoefficient();
1017 if(itSet) myDrawer->SetDeviationCoefficient();
1021 //=======================================================================
1022 //function : SetHLROwnDeviationCoefficient
1023 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1024 // returns Standard_True if it change
1025 //=======================================================================
1027 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1029 Standard_Boolean itSet = myDrawer->IsOwnHLRDeviationCoefficient();
1030 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1035 //=======================================================================
1036 //function : SetOwnDeviationAngle
1037 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1038 // returns Standard_True if it change
1039 //=======================================================================
1041 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1043 Standard_Boolean itSet = myDrawer->IsOwnDeviationAngle();
1044 if(itSet) myDrawer->SetDeviationAngle();
1049 //=======================================================================
1050 //function : SetOwnHLRDeviationAngle
1051 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1052 // returns Standard_True if it change
1053 //=======================================================================
1055 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1057 Standard_Boolean itSet = myDrawer->IsOwnHLRDeviationAngle();
1058 if(itSet) myDrawer->SetHLRAngle();
1063 //=======================================================================
1064 //function : SetOwnDeviationCoefficient
1066 //=======================================================================
1068 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1070 myDrawer->SetDeviationCoefficient( aCoefficient );
1071 SetToUpdate(0) ; // WireFrame
1072 SetToUpdate(1) ; // Shadding
1075 //=======================================================================
1076 //function : SetOwnHLRDeviationCoefficient
1078 //=======================================================================
1080 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1082 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1086 //=======================================================================
1087 //function : SetOwnDeviationAngle
1089 //=======================================================================
1091 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1094 myDrawer->SetDeviationAngle(anAngle );
1095 SetToUpdate(0) ; // WireFrame
1097 //=======================================================================
1098 //function : SetOwnDeviationAngle
1100 //=======================================================================
1102 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1104 Standard_Real OutAngl,OutDefl;
1105 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1106 SetOwnDeviationAngle(anAngle) ;
1107 SetOwnDeviationCoefficient(OutDefl) ;
1108 myInitAng = anAngle;
1113 //=======================================================================
1114 //function : UserAngle
1116 //=======================================================================
1118 Standard_Real AIS_Shape::UserAngle() const
1120 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1124 //=======================================================================
1125 //function : SetHLRAngleAndDeviation
1127 //=======================================================================
1129 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1131 Standard_Real OutAngl,OutDefl;
1132 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1133 SetOwnHLRDeviationAngle( OutAngl );
1134 SetOwnHLRDeviationCoefficient(OutDefl);
1137 //=======================================================================
1138 //function : SetOwnHLRDeviationAngle
1140 //=======================================================================
1142 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1144 myDrawer->SetHLRAngle( anAngle );
1148 //=======================================================================
1149 //function : OwnDeviationCoefficient
1151 //=======================================================================
1153 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1154 Standard_Real & aPreviousCoefficient ) const
1156 aCoefficient = myDrawer->DeviationCoefficient();
1157 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1158 return myDrawer->IsOwnDeviationCoefficient() ;
1161 //=======================================================================
1162 //function : OwnHLRDeviationCoefficient
1164 //=======================================================================
1166 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1167 Standard_Real & aPreviousCoefficient ) const
1169 aCoefficient = myDrawer->HLRDeviationCoefficient();
1170 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1171 return myDrawer->IsOwnHLRDeviationCoefficient();
1175 //=======================================================================
1176 //function : OwnDeviationAngle
1178 //=======================================================================
1180 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1181 Standard_Real & aPreviousAngle ) const
1183 anAngle = myDrawer->DeviationAngle();
1184 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1185 return myDrawer->IsOwnDeviationAngle();
1188 //=======================================================================
1189 //function : OwnHLRDeviationAngle
1191 //=======================================================================
1193 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1194 Standard_Real & aPreviousAngle ) const
1196 anAngle = myDrawer->HLRAngle();
1197 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1198 return myDrawer->IsOwnHLRDeviationAngle();