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 <HLRBRep.hxx>
70 #include <Precision.hxx>
72 #include <Standard_Failure.hxx>
73 #include <Standard_ErrorHandler.hxx>
74 #include <Select3D_SensitiveBox.hxx>
75 #include <TopoDS_Iterator.hxx>
77 static Standard_Boolean myFirstCompute;
79 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
81 TColStd_ListIteratorOfListOfInteger It(LL);
82 for(;It.More();It.Next()){
84 return Standard_True;}
85 return Standard_False;
88 //==================================================
91 //==================================================
94 AIS_Shape(const TopoDS_Shape& shap):
95 AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
99 myFirstCompute = Standard_True;
101 myDrawer->SetShadingAspectGlobal(Standard_False);
104 //=======================================================================
107 //=======================================================================
108 AIS_KindOfInteractive AIS_Shape::Type() const
109 {return AIS_KOI_Shape;}
112 //=======================================================================
113 //function : Signature
115 //=======================================================================
116 Standard_Integer AIS_Shape::Signature() const
119 //=======================================================================
120 //function : AcceptShapeDecomposition
122 //=======================================================================
123 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
124 {return Standard_True;}
126 //=======================================================================
129 //=======================================================================
130 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
131 const Handle(Prs3d_Presentation)& aPrs,
132 const Standard_Integer aMode)
135 if(myshape.IsNull()) return;
137 // wire,edge,vertex -> pas de HLR + priorite display superieure
138 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
139 if(TheType>4 && TheType<8) {
140 aPrs->SetVisual(Graphic3d_TOS_ALL);
141 aPrs->SetDisplayPriority(TheType+2);
143 // Shape vide -> Assemblage vide.
144 if (myshape.ShapeType() == TopAbs_COMPOUND) {
145 TopoDS_Iterator anExplor (myshape);
147 if (!anExplor.More()) {
152 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //not taken in account duting FITALL
155 try { OCC_CATCH_SIGNALS StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); }
156 catch (Standard_Failure) {
158 cout << "AIS_Shape::Compute() failed"<< endl;
159 cout << "a Shape should be incorrect : No Compute can be maked on it "<< endl;
161 // presentation of the bounding box is calculated
162 // Compute(aPresentationManager,aPrs,2);
168 Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
169 Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
170 Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
171 if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
172 || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
174 BRepTools::Clean (myshape);
177 //shading only on face...
178 if ((Standard_Integer) myshape.ShapeType()>4)
179 StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
181 myDrawer->SetShadingAspectGlobal(Standard_False);
182 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
187 StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
189 catch (Standard_Failure) {
191 cout << "AIS_Shape::Compute() in ShadingMode failed"<< endl;
193 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
198 Standard_Real value = Transparency() ;
200 SetTransparency( value );
207 if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
208 else StdPrs_WFDeflectionRestrictedFace::AddBox (aPrs, BoundingBox(), myDrawer);
211 aPrs->ReCompute(); // for hidden line recomputation if necessary...
214 //=======================================================================
216 //purpose : Hidden Line Removal
217 //=======================================================================
218 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
219 const Handle(Prs3d_Presentation)& aPresentation)
221 Compute(aProjector,aPresentation,myshape);
224 //=======================================================================
227 //=======================================================================
229 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
230 const Handle(Geom_Transformation)& TheTrsf,
231 const Handle(Prs3d_Presentation)& aPresentation)
233 const TopLoc_Location& loc = myshape.Location();
234 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
235 Compute(aProjector,aPresentation,shbis);
238 //=======================================================================
241 //=======================================================================
243 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
244 const Handle(Prs3d_Presentation)& aPresentation,
245 const TopoDS_Shape& SH)
247 if (SH.ShapeType() == TopAbs_COMPOUND) {
248 TopoDS_Iterator anExplor (SH);
250 if (!anExplor.More()) // Shape vide -> Assemblage vide.
254 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
255 if (defdrawer->DrawHiddenLine())
256 {myDrawer->EnableDrawHiddenLine();}
257 else {myDrawer->DisableDrawHiddenLine();}
259 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
260 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
262 // coefficients for calculation
264 Standard_Real prevangle, newangle ,prevcoeff,newcoeff ;
265 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle(newangle,prevangle);
266 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient(newcoeff,prevcoeff);
267 if (((Abs (newangle - prevangle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
268 ((Abs (newcoeff - prevcoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient)) {
270 cout << "AIS_Shape : compute"<<endl;
271 cout << "newangle : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
272 cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
274 BRepTools::Clean(SH);
280 switch (TypeOfHLR()) {
282 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
284 case Prs3d_TOH_PolyAlgo:
286 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
290 catch (Standard_Failure) {
292 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
294 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
298 defdrawer->SetTypeOfDeflection (prevdef);
301 //=======================================================================
302 //function : SelectionType
303 //purpose : gives the type according to the Index of Selection Mode
304 //=======================================================================
306 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
310 return TopAbs_VERTEX;
322 return TopAbs_COMPSOLID;
324 return TopAbs_COMPOUND;
331 //=======================================================================
332 //function : SelectionType
333 //purpose : gives the SelectionMode according to the Type od Decomposition...
334 //=======================================================================
335 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
350 case TopAbs_COMPSOLID:
352 case TopAbs_COMPOUND:
361 //=======================================================================
362 //function : ComputeSelection
364 //=======================================================================
366 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
367 const Standard_Integer aMode)
369 if(myshape.IsNull()) return;
370 if (myshape.ShapeType() == TopAbs_COMPOUND) {
371 TopoDS_Iterator anExplor (myshape);
373 if (!anExplor.More()) // empty Shape -> empty Assembly.
377 static TopAbs_ShapeEnum TypOfSel;
378 TypOfSel = AIS_Shape::SelectionType(aMode);
379 TopoDS_Shape shape = myshape;
381 // POP protection against crash in low layers
383 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
384 Standard_Boolean autoTriangulation = Standard_True;
387 StdSelect_BRepSelectionTool::Load(aSelection,
392 myDrawer->HLRAngle(),
394 } catch ( Standard_Failure ) {
395 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
397 Bnd_Box B = BoundingBox();
398 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
399 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
400 aSelection->Add(aSensitiveBox);
404 // insert the drawer in the BrepOwners for hilight...
405 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
408 Quantity_NameOfColor AIS_Shape::Color() const {
409 Quantity_Color aColor;
411 return aColor.Name();
414 void AIS_Shape::Color( Quantity_Color& aColor ) const {
415 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
418 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
419 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
422 Standard_Real AIS_Shape::Transparency() const {
423 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
426 //=======================================================================
427 //function : SetColor
429 //=======================================================================
431 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
433 SetColor(Quantity_Color(aCol));
436 //=======================================================================
437 //function : setColor
439 //=======================================================================
441 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
442 const Quantity_Color& theColor) const
444 if (!theDrawer->HasOwnShadingAspect())
446 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
447 if (theDrawer->HasLink())
449 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
452 if (!theDrawer->HasOwnLineAspect())
454 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
455 if (theDrawer->HasLink())
457 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
460 if (!theDrawer->HasOwnWireAspect())
462 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
463 if (theDrawer->HasLink())
465 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
468 if (!theDrawer->HasOwnPointAspect())
470 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
471 if (theDrawer->HasLink())
473 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
476 // disable dedicated line aspects
477 theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect());
478 theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect());
479 theDrawer->SetSeenLineAspect (theDrawer->LineAspect());
482 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
483 theDrawer->SetShadingAspectGlobal (Standard_False);
484 theDrawer->LineAspect()->SetColor (theColor);
485 theDrawer->WireAspect()->SetColor (theColor);
486 theDrawer->PointAspect()->SetColor (theColor);
489 //=======================================================================
490 //function : SetColor
492 //=======================================================================
494 void AIS_Shape::SetColor (const Quantity_Color& theColor)
496 setColor (myDrawer, theColor);
497 myOwnColor = theColor;
498 hasOwnColor = Standard_True;
500 // modify shading presentation without re-computation
501 const PrsMgr_Presentations& aPrsList = Presentations();
502 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
503 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
504 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
505 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
507 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
508 if (aPrsModed.Mode() != AIS_Shaded)
513 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
515 // Set aspects for presentation
516 aPrs->SetPrimitivesAspect (anAreaAspect);
517 aPrs->SetPrimitivesAspect (aLineAspect);
518 aPrs->SetPrimitivesAspect (aPointAspect);
520 // Go through all groups to change color for all primitives
521 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
523 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
525 // Check if aspect of given type is set for the group,
526 // because setting aspect for group with no already set aspect
527 // can lead to loss of presentation data
528 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
530 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
532 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
534 aGroup->SetGroupPrimitivesAspect (aLineAspect);
536 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
538 aGroup->SetGroupPrimitivesAspect (aPointAspect);
543 LoadRecomputable (AIS_WireFrame);
544 LoadRecomputable (2);
547 //=======================================================================
548 //function : UnsetColor
550 //=======================================================================
552 void AIS_Shape::UnsetColor()
556 myToRecomputeModes.Clear();
559 hasOwnColor = Standard_False;
563 Handle(Prs3d_LineAspect) anEmptyAsp;
564 myDrawer->SetLineAspect (anEmptyAsp);
565 myDrawer->SetWireAspect (anEmptyAsp);
566 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
567 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
568 myDrawer->SetSeenLineAspect (anEmptyAsp);
572 Quantity_Color aColor = Quantity_NOC_YELLOW;
573 if (myDrawer->HasLink())
575 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
577 myDrawer->LineAspect()->SetColor (aColor);
578 aColor = Quantity_NOC_RED;
579 if (myDrawer->HasLink())
581 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
583 myDrawer->WireAspect()->SetColor (aColor);
584 aColor = Quantity_NOC_GREEN;
585 if (myDrawer->HasLink())
587 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
589 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
590 aColor = Quantity_NOC_YELLOW;
591 if (myDrawer->HasLink())
593 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
595 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
596 if (myDrawer->HasLink())
598 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
600 myDrawer->SeenLineAspect()->SetColor (aColor);
606 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
607 Graphic3d_MaterialAspect mat = aDefaultMat;
608 if (HasMaterial() || myDrawer->HasLink())
610 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
614 Quantity_Color aColor = aDefaultMat.AmbientColor();
615 if (myDrawer->HasLink())
617 Quantity_Color aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
619 mat.SetColor (aColor);
623 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
624 mat.SetTransparency (aTransp);
626 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
630 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
632 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
634 // modify shading presentation without re-computation
635 const PrsMgr_Presentations& aPrsList = Presentations();
636 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
637 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
638 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
640 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
641 if (aPrsModed.Mode() != AIS_Shaded)
646 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
648 aPrs->SetPrimitivesAspect (anAreaAsp);
649 aPrs->SetPrimitivesAspect (aLineAsp);
651 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
653 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
655 // Check if aspect of given type is set for the group,
656 // because setting aspect for group with no already set aspect
657 // can lead to loss of presentation data
658 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
660 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
662 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
664 aGroup->SetGroupPrimitivesAspect (aLineAsp);
669 LoadRecomputable (AIS_WireFrame);
670 LoadRecomputable (2);
673 //=======================================================================
674 //function : setWidth
676 //=======================================================================
678 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
679 const Standard_Real theLineWidth) const
681 if (!theDrawer->HasOwnLineAspect())
683 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
684 if (theDrawer->HasLink())
686 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
689 if (!theDrawer->HasOwnWireAspect())
691 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
692 if (theDrawer->HasLink())
694 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
697 // disable dedicated line aspects
698 theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect());
699 theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect());
700 theDrawer->SetSeenLineAspect (theDrawer->LineAspect());
703 theDrawer->LineAspect()->SetWidth (theLineWidth);
704 theDrawer->WireAspect()->SetWidth (theLineWidth);
707 //=======================================================================
708 //function : SetWidth
710 //=======================================================================
712 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
714 setWidth (myDrawer, theLineWidth);
715 myOwnWidth = theLineWidth;
716 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
717 LoadRecomputable (2); // and the bounding box...
720 //=======================================================================
721 //function : UnsetWidth
723 //=======================================================================
725 void AIS_Shape::UnsetWidth()
727 if (myOwnWidth == 0.0)
729 myToRecomputeModes.Clear();
735 Handle(Prs3d_LineAspect) anEmptyAsp;
739 myDrawer->SetLineAspect (anEmptyAsp);
740 myDrawer->SetWireAspect (anEmptyAsp);
741 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
742 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
743 myDrawer->SetSeenLineAspect (anEmptyAsp);
747 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
748 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
749 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
750 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
751 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
752 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
753 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
754 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
755 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
756 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
758 LoadRecomputable (AIS_WireFrame);
761 //=======================================================================
762 //function : setMaterial
764 //=======================================================================
766 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
767 const Graphic3d_MaterialAspect& theMaterial,
768 const Standard_Boolean theToKeepColor,
769 const Standard_Boolean theToKeepTransp) const
771 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
772 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
773 if (!theDrawer->HasOwnShadingAspect())
775 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
776 if (theDrawer->HasLink())
778 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
781 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
785 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
789 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
793 //=======================================================================
794 //function : SetMaterial
796 //=======================================================================
798 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
800 SetMaterial(Graphic3d_MaterialAspect(aMat));
803 //=======================================================================
804 //function : SetMaterial
806 //=======================================================================
808 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
810 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
811 hasOwnMaterial = Standard_True;
813 // modify shading presentation without re-computation
814 const PrsMgr_Presentations& aPrsList = Presentations();
815 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
816 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
818 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
819 if (aPrsModed.Mode() != AIS_Shaded)
824 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
825 aPrs->SetPrimitivesAspect (anAreaAsp);
826 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
828 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
830 // Check if aspect of given type is set for the group,
831 // because setting aspect for group with no already set aspect
832 // can lead to loss of presentation data
833 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
835 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
840 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
841 myToRecomputeModes.Clear();
844 //=======================================================================
845 //function : UnsetMaterial
847 //=======================================================================
849 void AIS_Shape::UnsetMaterial()
859 if(myDrawer->HasLink())
861 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
862 myCurrentFacingModel);
866 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
867 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
872 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
874 hasOwnMaterial = Standard_False;
876 // modify shading presentation without re-computation
877 const PrsMgr_Presentations& aPrsList = Presentations();
878 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
879 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
881 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
882 if (aPrsModed.Mode() != AIS_Shaded)
887 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
888 aPrs->SetPrimitivesAspect (anAreaAsp);
889 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
891 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
892 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
894 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
899 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
900 myToRecomputeModes.Clear();
903 //=======================================================================
904 //function : setTransparency
906 //=======================================================================
908 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
909 const Standard_Real theValue) const
911 if (!theDrawer->HasOwnShadingAspect())
913 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
914 if (theDrawer->HasLink())
916 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
920 // override transparency
921 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
924 //=======================================================================
925 //function : SetTransparency
927 //=======================================================================
929 void AIS_Shape::SetTransparency (const Standard_Real theValue)
931 setTransparency (myDrawer, theValue);
932 myTransparency = theValue;
934 // modify shading presentation without re-computation
935 const PrsMgr_Presentations& aPrsList = Presentations();
936 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
937 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
939 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
940 if (aPrsModed.Mode() != AIS_Shaded)
945 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
946 aPrs->SetPrimitivesAspect (anAreaAsp);
947 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
948 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
950 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
951 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
953 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
958 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
959 myToRecomputeModes.Clear();
962 //=======================================================================
963 //function : UnsetTransparency
965 //=======================================================================
967 void AIS_Shape::UnsetTransparency()
969 myTransparency = 0.0;
970 if (!myDrawer->HasOwnShadingAspect())
974 else if (HasColor() || HasMaterial())
976 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
980 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
983 // modify shading presentation without re-computation
984 const PrsMgr_Presentations& aPrsList = Presentations();
985 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
986 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
988 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
989 if (aPrsModed.Mode() != AIS_Shaded)
994 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
995 aPrs->SetPrimitivesAspect (anAreaAsp);
996 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
998 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
999 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1001 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1004 aPrs->ResetDisplayPriority();
1007 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1008 myToRecomputeModes.Clear();
1011 //=======================================================================
1012 //function : LoadRecomputable
1014 //=======================================================================
1016 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1018 myRecomputeEveryPrs = Standard_False;
1019 if(!IsInList(myToRecomputeModes,TheMode))
1020 myToRecomputeModes.Append(TheMode);
1023 //=======================================================================
1024 //function : BoundingBox
1026 //=======================================================================
1028 const Bnd_Box& AIS_Shape::BoundingBox()
1030 if (myshape.ShapeType() == TopAbs_COMPOUND) {
1031 TopoDS_Iterator anExplor (myshape);
1033 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1040 BRepBndLib::AddClose(myshape, myBB);
1041 myCompBB = Standard_False;
1048 //=======================================================================
1049 //function : SetOwnDeviationCoefficient
1050 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1051 // returns Standard_True if it change
1052 //=======================================================================
1054 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1056 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1057 if(itSet) myDrawer->SetDeviationCoefficient();
1061 //=======================================================================
1062 //function : SetHLROwnDeviationCoefficient
1063 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1064 // returns Standard_True if it change
1065 //=======================================================================
1067 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1069 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1070 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1075 //=======================================================================
1076 //function : SetOwnDeviationAngle
1077 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1078 // returns Standard_True if it change
1079 //=======================================================================
1081 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1083 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1084 if(itSet) myDrawer->SetDeviationAngle();
1089 //=======================================================================
1090 //function : SetOwnHLRDeviationAngle
1091 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1092 // returns Standard_True if it change
1093 //=======================================================================
1095 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1097 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1098 if(itSet) myDrawer->SetHLRAngle();
1103 //=======================================================================
1104 //function : SetOwnDeviationCoefficient
1106 //=======================================================================
1108 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1110 myDrawer->SetDeviationCoefficient( aCoefficient );
1111 SetToUpdate(0) ; // WireFrame
1112 SetToUpdate(1) ; // Shadding
1115 //=======================================================================
1116 //function : SetOwnHLRDeviationCoefficient
1118 //=======================================================================
1120 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1122 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1126 //=======================================================================
1127 //function : SetOwnDeviationAngle
1129 //=======================================================================
1131 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1134 myDrawer->SetDeviationAngle(anAngle );
1135 SetToUpdate(0) ; // WireFrame
1137 //=======================================================================
1138 //function : SetOwnDeviationAngle
1140 //=======================================================================
1142 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1144 Standard_Real OutAngl,OutDefl;
1145 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1146 SetOwnDeviationAngle(anAngle) ;
1147 SetOwnDeviationCoefficient(OutDefl) ;
1148 myInitAng = anAngle;
1153 //=======================================================================
1154 //function : UserAngle
1156 //=======================================================================
1158 Standard_Real AIS_Shape::UserAngle() const
1160 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1164 //=======================================================================
1165 //function : SetHLRAngleAndDeviation
1167 //=======================================================================
1169 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1171 Standard_Real OutAngl,OutDefl;
1172 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1173 SetOwnHLRDeviationAngle( OutAngl );
1174 SetOwnHLRDeviationCoefficient(OutDefl);
1177 //=======================================================================
1178 //function : SetOwnHLRDeviationAngle
1180 //=======================================================================
1182 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1184 myDrawer->SetHLRAngle( anAngle );
1188 //=======================================================================
1189 //function : OwnDeviationCoefficient
1191 //=======================================================================
1193 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1194 Standard_Real & aPreviousCoefficient ) const
1196 aCoefficient = myDrawer->DeviationCoefficient();
1197 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1198 return myDrawer->HasOwnDeviationCoefficient() ;
1201 //=======================================================================
1202 //function : OwnHLRDeviationCoefficient
1204 //=======================================================================
1206 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1207 Standard_Real & aPreviousCoefficient ) const
1209 aCoefficient = myDrawer->HLRDeviationCoefficient();
1210 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1211 return myDrawer->HasOwnHLRDeviationCoefficient();
1215 //=======================================================================
1216 //function : OwnDeviationAngle
1218 //=======================================================================
1220 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1221 Standard_Real & aPreviousAngle ) const
1223 anAngle = myDrawer->DeviationAngle();
1224 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1225 return myDrawer->HasOwnDeviationAngle();
1228 //=======================================================================
1229 //function : OwnHLRDeviationAngle
1231 //=======================================================================
1233 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1234 Standard_Real & aPreviousAngle ) const
1236 anAngle = myDrawer->HLRAngle();
1237 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1238 return myDrawer->HasOwnHLRDeviationAngle();