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.
18 #include <AIS_GraphicTool.hxx>
19 #include <AIS_InteractiveContext.hxx>
20 #include <AIS_Shape.hxx>
21 #include <Aspect_TypeOfLine.hxx>
22 #include <Bnd_Box.hxx>
23 #include <BRep_Builder.hxx>
24 #include <BRepBndLib.hxx>
25 #include <BRepTools.hxx>
26 #include <BRepTools_ShapeSet.hxx>
27 #include <Geom_Transformation.hxx>
29 #include <Graphic3d_ArrayOfPolylines.hxx>
30 #include <Graphic3d_AspectFillArea3d.hxx>
31 #include <Graphic3d_AspectLine3d.hxx>
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_AspectText3d.hxx>
34 #include <Graphic3d_Group.hxx>
35 #include <Graphic3d_MaterialAspect.hxx>
36 #include <Graphic3d_SequenceOfGroup.hxx>
37 #include <Graphic3d_Structure.hxx>
38 #include <HLRBRep.hxx>
39 #include <OSD_Timer.hxx>
40 #include <Precision.hxx>
42 #include <Prs3d_Drawer.hxx>
43 #include <Prs3d_IsoAspect.hxx>
44 #include <Prs3d_Presentation.hxx>
45 #include <Prs3d_Projector.hxx>
46 #include <Prs3d_Root.hxx>
47 #include <Prs3d_ShadingAspect.hxx>
48 #include <StdPrs_BndBox.hxx>
49 #include <StdPrs_ToolTriangulatedShape.hxx>
50 #include <PrsMgr_ModedPresentation.hxx>
51 #include <Quantity_Color.hxx>
52 #include <Select3D_SensitiveBox.hxx>
53 #include <Select3D_SensitiveEntity.hxx>
54 #include <Standard_ErrorHandler.hxx>
55 #include <Standard_Failure.hxx>
56 #include <Standard_Type.hxx>
57 #include <StdPrs_HLRPolyShape.hxx>
58 #include <StdPrs_HLRShape.hxx>
59 #include <StdPrs_ShadedShape.hxx>
60 #include <StdPrs_WFShape.hxx>
61 #include <StdSelect.hxx>
62 #include <StdSelect_BRepOwner.hxx>
63 #include <StdSelect_BRepSelectionTool.hxx>
64 #include <StdSelect_DisplayMode.hxx>
65 #include <TColStd_ListIteratorOfListOfInteger.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Iterator.hxx>
69 #include <TopoDS_Shape.hxx>
71 static Standard_Boolean myFirstCompute;
73 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
75 TColStd_ListIteratorOfListOfInteger It(LL);
76 for(;It.More();It.Next()){
78 return Standard_True;}
79 return Standard_False;
82 //==================================================
85 //==================================================
88 AIS_Shape(const TopoDS_Shape& shap):
89 AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
93 myFirstCompute = Standard_True;
95 myDrawer->SetShadingAspectGlobal(Standard_False);
98 //=======================================================================
101 //=======================================================================
102 AIS_KindOfInteractive AIS_Shape::Type() const
103 {return AIS_KOI_Shape;}
106 //=======================================================================
107 //function : Signature
109 //=======================================================================
110 Standard_Integer AIS_Shape::Signature() const
113 //=======================================================================
114 //function : AcceptShapeDecomposition
116 //=======================================================================
117 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
118 {return Standard_True;}
120 //=======================================================================
123 //=======================================================================
124 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
125 const Handle(Prs3d_Presentation)& aPrs,
126 const Standard_Integer aMode)
129 if(myshape.IsNull()) return;
131 // wire,edge,vertex -> pas de HLR + priorite display superieure
132 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
133 if(TheType>4 && TheType<8) {
134 aPrs->SetVisual(Graphic3d_TOS_ALL);
135 aPrs->SetDisplayPriority(TheType+2);
137 // Shape vide -> Assemblage vide.
138 if (myshape.ShapeType() == TopAbs_COMPOUND) {
139 TopoDS_Iterator anExplor (myshape);
141 if (!anExplor.More()) {
148 aPrs->SetInfiniteState (Standard_True); //not taken in account duting FITALL
158 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
160 catch (Standard_Failure)
163 cout << "AIS_Shape::Compute() failed" << endl;
164 cout << "a Shape should be incorrect : No Compute can be maked on it " << endl;
166 // presentation of the bounding box is calculated
167 // Compute(aPresentationManager,aPrs,2);
173 if (myDrawer->IsAutoTriangulation())
175 Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
176 Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
177 Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
178 if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
179 || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
181 BRepTools::Clean (myshape);
185 if ((Standard_Integer) myshape.ShapeType() > 4)
187 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
191 myDrawer->SetShadingAspectGlobal (Standard_False);
194 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
201 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer);
203 catch (Standard_Failure)
206 cout << "AIS_Shape::Compute() in ShadingMode failed" << endl;
208 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
212 Standard_Real aTransparency = Transparency() ;
213 if (aTransparency > 0.0)
215 SetTransparency (aTransparency);
225 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
229 StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
234 // Recompute hidden line presentation (if necessary).
238 //=======================================================================
240 //purpose : Hidden Line Removal
241 //=======================================================================
242 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
243 const Handle(Prs3d_Presentation)& aPresentation)
245 Compute(aProjector,aPresentation,myshape);
248 //=======================================================================
251 //=======================================================================
253 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
254 const Handle(Geom_Transformation)& TheTrsf,
255 const Handle(Prs3d_Presentation)& aPresentation)
257 const TopLoc_Location& loc = myshape.Location();
258 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
259 Compute(aProjector,aPresentation,shbis);
262 //=======================================================================
265 //=======================================================================
267 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
268 const Handle(Prs3d_Presentation)& aPresentation,
269 const TopoDS_Shape& SH)
271 if (SH.ShapeType() == TopAbs_COMPOUND) {
272 TopoDS_Iterator anExplor (SH);
274 if (!anExplor.More()) // Shape vide -> Assemblage vide.
278 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
279 if (defdrawer->DrawHiddenLine())
280 {myDrawer->EnableDrawHiddenLine();}
281 else {myDrawer->DisableDrawHiddenLine();}
283 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
284 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
286 if (myDrawer->IsAutoTriangulation())
288 // coefficients for calculation
289 Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff;
290 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle);
291 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff);
292 if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
293 ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient))
295 BRepTools::Clean(SH);
302 switch (TypeOfHLR()) {
304 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
306 case Prs3d_TOH_PolyAlgo:
308 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
312 catch (Standard_Failure) {
314 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
316 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
320 defdrawer->SetTypeOfDeflection (prevdef);
323 //=======================================================================
324 //function : SelectionType
325 //purpose : gives the type according to the Index of Selection Mode
326 //=======================================================================
328 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
332 return TopAbs_VERTEX;
344 return TopAbs_COMPSOLID;
346 return TopAbs_COMPOUND;
353 //=======================================================================
354 //function : SelectionType
355 //purpose : gives the SelectionMode according to the Type od Decomposition...
356 //=======================================================================
357 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
372 case TopAbs_COMPSOLID:
374 case TopAbs_COMPOUND:
383 //=======================================================================
384 //function : ComputeSelection
386 //=======================================================================
388 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
389 const Standard_Integer aMode)
391 if(myshape.IsNull()) return;
392 if (myshape.ShapeType() == TopAbs_COMPOUND) {
393 TopoDS_Iterator anExplor (myshape);
395 if (!anExplor.More()) // empty Shape -> empty Assembly.
399 static TopAbs_ShapeEnum TypOfSel;
400 TypOfSel = AIS_Shape::SelectionType(aMode);
401 TopoDS_Shape shape = myshape;
403 // POP protection against crash in low layers
405 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
408 StdSelect_BRepSelectionTool::Load(aSelection,
413 myDrawer->HLRAngle(),
414 myDrawer->IsAutoTriangulation());
415 } catch ( Standard_Failure ) {
416 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
419 Bnd_Box B = BoundingBox();
420 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
421 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
422 aSelection->Add(aSensitiveBox);
426 // insert the drawer in the BrepOwners for hilight...
427 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
430 Quantity_NameOfColor AIS_Shape::Color() const {
431 Quantity_Color aColor;
433 return aColor.Name();
436 void AIS_Shape::Color( Quantity_Color& aColor ) const {
437 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
440 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
441 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
444 Standard_Real AIS_Shape::Transparency() const {
445 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
448 //=======================================================================
449 //function : SetColor
451 //=======================================================================
453 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
455 SetColor(Quantity_Color(aCol));
458 //=======================================================================
459 //function : setColor
461 //=======================================================================
463 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
464 const Quantity_Color& theColor) const
466 if (!theDrawer->HasOwnShadingAspect())
468 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
469 if (theDrawer->HasLink())
471 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
474 if (!theDrawer->HasOwnLineAspect())
476 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
477 if (theDrawer->HasLink())
479 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
482 if (!theDrawer->HasOwnWireAspect())
484 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
485 if (theDrawer->HasLink())
487 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
490 if (!theDrawer->HasOwnPointAspect())
492 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
493 if (theDrawer->HasLink())
495 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
498 if (!theDrawer->HasOwnFreeBoundaryAspect())
500 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
501 if (theDrawer->HasLink())
503 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
506 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
508 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
509 if (theDrawer->HasLink())
511 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
514 if (!theDrawer->HasOwnSeenLineAspect())
516 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
517 if (theDrawer->HasLink())
519 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
524 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
525 theDrawer->SetShadingAspectGlobal (Standard_False);
526 theDrawer->LineAspect()->SetColor (theColor);
527 theDrawer->WireAspect()->SetColor (theColor);
528 theDrawer->PointAspect()->SetColor (theColor);
529 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
530 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
531 theDrawer->SeenLineAspect()->SetColor (theColor);
534 //=======================================================================
535 //function : SetColor
537 //=======================================================================
539 void AIS_Shape::SetColor (const Quantity_Color& theColor)
541 setColor (myDrawer, theColor);
542 myOwnColor = theColor;
543 hasOwnColor = Standard_True;
545 // modify shading presentation without re-computation
546 const PrsMgr_Presentations& aPrsList = Presentations();
547 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
548 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
549 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
550 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
552 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
553 if (aPrsModed.Mode() != AIS_Shaded)
558 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
560 // Set aspects for presentation
561 aPrs->SetPrimitivesAspect (anAreaAspect);
562 aPrs->SetPrimitivesAspect (aLineAspect);
563 aPrs->SetPrimitivesAspect (aPointAspect);
565 // Go through all groups to change color for all primitives
566 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
568 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
570 // Check if aspect of given type is set for the group,
571 // because setting aspect for group with no already set aspect
572 // can lead to loss of presentation data
573 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
575 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
577 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
579 aGroup->SetGroupPrimitivesAspect (aLineAspect);
581 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
583 aGroup->SetGroupPrimitivesAspect (aPointAspect);
588 LoadRecomputable (AIS_WireFrame);
589 LoadRecomputable (2);
592 //=======================================================================
593 //function : UnsetColor
595 //=======================================================================
597 void AIS_Shape::UnsetColor()
601 myToRecomputeModes.Clear();
604 hasOwnColor = Standard_False;
608 Handle(Prs3d_LineAspect) anEmptyAsp;
609 myDrawer->SetLineAspect (anEmptyAsp);
610 myDrawer->SetWireAspect (anEmptyAsp);
611 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
612 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
613 myDrawer->SetSeenLineAspect (anEmptyAsp);
617 Quantity_Color aColor = Quantity_NOC_YELLOW;
618 if (myDrawer->HasLink())
620 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
622 myDrawer->LineAspect()->SetColor (aColor);
623 aColor = Quantity_NOC_RED;
624 if (myDrawer->HasLink())
626 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
628 myDrawer->WireAspect()->SetColor (aColor);
629 aColor = Quantity_NOC_GREEN;
630 if (myDrawer->HasLink())
632 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
634 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
635 aColor = Quantity_NOC_YELLOW;
636 if (myDrawer->HasLink())
638 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
640 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
641 if (myDrawer->HasLink())
643 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
645 myDrawer->SeenLineAspect()->SetColor (aColor);
651 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
652 Graphic3d_MaterialAspect mat = aDefaultMat;
653 if (HasMaterial() || myDrawer->HasLink())
655 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
659 Quantity_Color aColor = aDefaultMat.AmbientColor();
660 if (myDrawer->HasLink())
662 aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
664 mat.SetColor (aColor);
668 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
669 mat.SetTransparency (aTransp);
671 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
675 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
677 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
679 // modify shading presentation without re-computation
680 const PrsMgr_Presentations& aPrsList = Presentations();
681 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
682 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
683 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
685 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
686 if (aPrsModed.Mode() != AIS_Shaded)
691 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
693 aPrs->SetPrimitivesAspect (anAreaAsp);
694 aPrs->SetPrimitivesAspect (aLineAsp);
696 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
698 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
700 // Check if aspect of given type is set for the group,
701 // because setting aspect for group with no already set aspect
702 // can lead to loss of presentation data
703 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
705 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
707 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
709 aGroup->SetGroupPrimitivesAspect (aLineAsp);
714 LoadRecomputable (AIS_WireFrame);
715 LoadRecomputable (2);
718 //=======================================================================
719 //function : setWidth
721 //=======================================================================
723 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
724 const Standard_Real theLineWidth) const
726 if (!theDrawer->HasOwnLineAspect())
728 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
729 if (theDrawer->HasLink())
731 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
734 if (!theDrawer->HasOwnWireAspect())
736 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
737 if (theDrawer->HasLink())
739 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
742 if (!theDrawer->HasOwnFreeBoundaryAspect())
744 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
745 if (theDrawer->HasLink())
747 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
750 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
752 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
753 if (theDrawer->HasLink())
755 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
758 if (!theDrawer->HasOwnSeenLineAspect())
760 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
761 if (theDrawer->HasLink())
763 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
768 theDrawer->LineAspect()->SetWidth (theLineWidth);
769 theDrawer->WireAspect()->SetWidth (theLineWidth);
770 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
771 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
772 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
775 //=======================================================================
776 //function : SetWidth
778 //=======================================================================
780 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
782 setWidth (myDrawer, theLineWidth);
783 myOwnWidth = theLineWidth;
784 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
785 LoadRecomputable (2); // and the bounding box...
788 //=======================================================================
789 //function : UnsetWidth
791 //=======================================================================
793 void AIS_Shape::UnsetWidth()
795 if (myOwnWidth == 0.0)
797 myToRecomputeModes.Clear();
803 Handle(Prs3d_LineAspect) anEmptyAsp;
807 myDrawer->SetLineAspect (anEmptyAsp);
808 myDrawer->SetWireAspect (anEmptyAsp);
809 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
810 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
811 myDrawer->SetSeenLineAspect (anEmptyAsp);
815 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
816 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
817 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
818 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
819 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
820 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
821 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
822 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
823 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
824 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
826 LoadRecomputable (AIS_WireFrame);
829 //=======================================================================
830 //function : setMaterial
832 //=======================================================================
834 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
835 const Graphic3d_MaterialAspect& theMaterial,
836 const Standard_Boolean theToKeepColor,
837 const Standard_Boolean theToKeepTransp) const
839 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
840 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
841 if (!theDrawer->HasOwnShadingAspect())
843 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
844 if (theDrawer->HasLink())
846 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
849 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
853 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
857 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
861 //=======================================================================
862 //function : SetMaterial
864 //=======================================================================
866 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
868 SetMaterial(Graphic3d_MaterialAspect(aMat));
871 //=======================================================================
872 //function : SetMaterial
874 //=======================================================================
876 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
878 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
879 hasOwnMaterial = Standard_True;
881 // modify shading presentation without re-computation
882 const PrsMgr_Presentations& aPrsList = Presentations();
883 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
884 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
886 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
887 if (aPrsModed.Mode() != AIS_Shaded)
892 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
893 aPrs->SetPrimitivesAspect (anAreaAsp);
894 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
896 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
898 // Check if aspect of given type is set for the group,
899 // because setting aspect for group with no already set aspect
900 // can lead to loss of presentation data
901 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
903 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
908 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
909 myToRecomputeModes.Clear();
912 //=======================================================================
913 //function : UnsetMaterial
915 //=======================================================================
917 void AIS_Shape::UnsetMaterial()
927 if(myDrawer->HasLink())
929 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
930 myCurrentFacingModel);
934 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
935 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
940 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
942 hasOwnMaterial = Standard_False;
944 // modify shading presentation without re-computation
945 const PrsMgr_Presentations& aPrsList = Presentations();
946 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
947 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
949 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
950 if (aPrsModed.Mode() != AIS_Shaded)
955 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
956 aPrs->SetPrimitivesAspect (anAreaAsp);
957 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
959 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
960 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
962 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
967 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
968 myToRecomputeModes.Clear();
971 //=======================================================================
972 //function : setTransparency
974 //=======================================================================
976 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
977 const Standard_Real theValue) const
979 if (!theDrawer->HasOwnShadingAspect())
981 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
982 if (theDrawer->HasLink())
984 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
988 // override transparency
989 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
992 //=======================================================================
993 //function : SetTransparency
995 //=======================================================================
997 void AIS_Shape::SetTransparency (const Standard_Real theValue)
999 setTransparency (myDrawer, theValue);
1000 myTransparency = theValue;
1002 // modify shading presentation without re-computation
1003 const PrsMgr_Presentations& aPrsList = Presentations();
1004 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1005 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1007 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1008 if (aPrsModed.Mode() != AIS_Shaded)
1013 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1014 aPrs->SetPrimitivesAspect (anAreaAsp);
1015 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
1016 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1018 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1019 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1021 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1026 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
1027 myToRecomputeModes.Clear();
1030 //=======================================================================
1031 //function : UnsetTransparency
1033 //=======================================================================
1035 void AIS_Shape::UnsetTransparency()
1037 myTransparency = 0.0;
1038 if (!myDrawer->HasOwnShadingAspect())
1042 else if (HasColor() || HasMaterial())
1044 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
1048 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
1051 // modify shading presentation without re-computation
1052 const PrsMgr_Presentations& aPrsList = Presentations();
1053 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1054 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1056 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1057 if (aPrsModed.Mode() != AIS_Shaded)
1062 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1063 aPrs->SetPrimitivesAspect (anAreaAsp);
1064 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1066 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1067 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1069 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1072 aPrs->ResetDisplayPriority();
1075 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1076 myToRecomputeModes.Clear();
1079 //=======================================================================
1080 //function : LoadRecomputable
1082 //=======================================================================
1084 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1086 myRecomputeEveryPrs = Standard_False;
1087 if(!IsInList(myToRecomputeModes,TheMode))
1088 myToRecomputeModes.Append(TheMode);
1091 //=======================================================================
1092 //function : BoundingBox
1094 //=======================================================================
1096 const Bnd_Box& AIS_Shape::BoundingBox()
1098 if (myshape.ShapeType() == TopAbs_COMPOUND) {
1099 TopoDS_Iterator anExplor (myshape);
1101 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1108 BRepBndLib::AddClose(myshape, myBB);
1109 myCompBB = Standard_False;
1116 //=======================================================================
1117 //function : SetOwnDeviationCoefficient
1118 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1119 // returns Standard_True if it change
1120 //=======================================================================
1122 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1124 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1125 if(itSet) myDrawer->SetDeviationCoefficient();
1129 //=======================================================================
1130 //function : SetHLROwnDeviationCoefficient
1131 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1132 // returns Standard_True if it change
1133 //=======================================================================
1135 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1137 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1138 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1143 //=======================================================================
1144 //function : SetOwnDeviationAngle
1145 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1146 // returns Standard_True if it change
1147 //=======================================================================
1149 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1151 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1152 if(itSet) myDrawer->SetDeviationAngle();
1157 //=======================================================================
1158 //function : SetOwnHLRDeviationAngle
1159 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1160 // returns Standard_True if it change
1161 //=======================================================================
1163 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1165 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1166 if(itSet) myDrawer->SetHLRAngle();
1171 //=======================================================================
1172 //function : SetOwnDeviationCoefficient
1174 //=======================================================================
1176 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1178 myDrawer->SetDeviationCoefficient( aCoefficient );
1179 SetToUpdate(0) ; // WireFrame
1180 SetToUpdate(1) ; // Shadding
1183 //=======================================================================
1184 //function : SetOwnHLRDeviationCoefficient
1186 //=======================================================================
1188 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1190 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1194 //=======================================================================
1195 //function : SetOwnDeviationAngle
1197 //=======================================================================
1199 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1202 myDrawer->SetDeviationAngle(anAngle );
1203 SetToUpdate(0) ; // WireFrame
1205 //=======================================================================
1206 //function : SetOwnDeviationAngle
1208 //=======================================================================
1210 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1212 Standard_Real OutAngl,OutDefl;
1213 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1214 SetOwnDeviationAngle(anAngle) ;
1215 SetOwnDeviationCoefficient(OutDefl) ;
1216 myInitAng = anAngle;
1221 //=======================================================================
1222 //function : UserAngle
1224 //=======================================================================
1226 Standard_Real AIS_Shape::UserAngle() const
1228 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1232 //=======================================================================
1233 //function : SetHLRAngleAndDeviation
1235 //=======================================================================
1237 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1239 Standard_Real OutAngl,OutDefl;
1240 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1241 SetOwnHLRDeviationAngle( OutAngl );
1242 SetOwnHLRDeviationCoefficient(OutDefl);
1245 //=======================================================================
1246 //function : SetOwnHLRDeviationAngle
1248 //=======================================================================
1250 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1252 myDrawer->SetHLRAngle( anAngle );
1256 //=======================================================================
1257 //function : OwnDeviationCoefficient
1259 //=======================================================================
1261 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1262 Standard_Real & aPreviousCoefficient ) const
1264 aCoefficient = myDrawer->DeviationCoefficient();
1265 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1266 return myDrawer->HasOwnDeviationCoefficient() ;
1269 //=======================================================================
1270 //function : OwnHLRDeviationCoefficient
1272 //=======================================================================
1274 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1275 Standard_Real & aPreviousCoefficient ) const
1277 aCoefficient = myDrawer->HLRDeviationCoefficient();
1278 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1279 return myDrawer->HasOwnHLRDeviationCoefficient();
1283 //=======================================================================
1284 //function : OwnDeviationAngle
1286 //=======================================================================
1288 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1289 Standard_Real & aPreviousAngle ) const
1291 anAngle = myDrawer->DeviationAngle();
1292 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1293 return myDrawer->HasOwnDeviationAngle();
1296 //=======================================================================
1297 //function : OwnHLRDeviationAngle
1299 //=======================================================================
1301 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1302 Standard_Real & aPreviousAngle ) const
1304 anAngle = myDrawer->HLRAngle();
1305 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1306 return myDrawer->HasOwnHLRDeviationAngle();