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 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
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),
94 myDrawer->SetShadingAspectGlobal(Standard_False);
97 //=======================================================================
100 //=======================================================================
101 AIS_KindOfInteractive AIS_Shape::Type() const
102 {return AIS_KOI_Shape;}
105 //=======================================================================
106 //function : Signature
108 //=======================================================================
109 Standard_Integer AIS_Shape::Signature() const
112 //=======================================================================
113 //function : AcceptShapeDecomposition
115 //=======================================================================
116 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
117 {return Standard_True;}
119 //=======================================================================
122 //=======================================================================
123 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
124 const Handle(Prs3d_Presentation)& aPrs,
125 const Standard_Integer aMode)
128 if(myshape.IsNull()) return;
130 // wire,edge,vertex -> pas de HLR + priorite display superieure
131 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
132 if(TheType>4 && TheType<8) {
133 aPrs->SetVisual(Graphic3d_TOS_ALL);
134 aPrs->SetDisplayPriority(TheType+2);
136 // Shape vide -> Assemblage vide.
137 if (myshape.ShapeType() == TopAbs_COMPOUND) {
138 TopoDS_Iterator anExplor (myshape);
140 if (!anExplor.More()) {
147 aPrs->SetInfiniteState (Standard_True); //not taken in account duting FITALL
157 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
159 catch (Standard_Failure)
162 cout << "AIS_Shape::Compute() failed" << endl;
163 cout << "a Shape should be incorrect : No Compute can be maked on it " << endl;
165 // presentation of the bounding box is calculated
166 // Compute(aPresentationManager,aPrs,2);
172 if (myDrawer->IsAutoTriangulation())
174 Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
175 Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
176 Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
177 if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
178 || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
180 BRepTools::Clean (myshape);
184 if ((Standard_Integer) myshape.ShapeType() > 4)
186 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
190 myDrawer->SetShadingAspectGlobal (Standard_False);
193 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
200 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer);
202 catch (Standard_Failure)
205 cout << "AIS_Shape::Compute() in ShadingMode failed" << endl;
207 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
211 Standard_Real aTransparency = Transparency() ;
212 if (aTransparency > 0.0)
214 SetTransparency (aTransparency);
224 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
228 StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
233 // Recompute hidden line presentation (if necessary).
237 //=======================================================================
239 //purpose : Hidden Line Removal
240 //=======================================================================
241 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
242 const Handle(Prs3d_Presentation)& aPresentation)
244 Compute(aProjector,aPresentation,myshape);
247 //=======================================================================
250 //=======================================================================
252 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
253 const Handle(Geom_Transformation)& TheTrsf,
254 const Handle(Prs3d_Presentation)& aPresentation)
256 const TopLoc_Location& loc = myshape.Location();
257 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
258 Compute(aProjector,aPresentation,shbis);
261 //=======================================================================
264 //=======================================================================
266 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
267 const Handle(Prs3d_Presentation)& aPresentation,
268 const TopoDS_Shape& SH)
270 if (SH.ShapeType() == TopAbs_COMPOUND) {
271 TopoDS_Iterator anExplor (SH);
273 if (!anExplor.More()) // Shape vide -> Assemblage vide.
277 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
278 if (defdrawer->DrawHiddenLine())
279 {myDrawer->EnableDrawHiddenLine();}
280 else {myDrawer->DisableDrawHiddenLine();}
282 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
283 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
285 if (myDrawer->IsAutoTriangulation())
287 // coefficients for calculation
288 Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff;
289 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle);
290 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff);
291 if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
292 ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient))
294 BRepTools::Clean(SH);
301 switch (TypeOfHLR()) {
303 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
305 case Prs3d_TOH_PolyAlgo:
307 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
311 catch (Standard_Failure) {
313 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
315 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
319 defdrawer->SetTypeOfDeflection (prevdef);
322 //=======================================================================
323 //function : SelectionType
324 //purpose : gives the type according to the Index of Selection Mode
325 //=======================================================================
327 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
331 return TopAbs_VERTEX;
343 return TopAbs_COMPSOLID;
345 return TopAbs_COMPOUND;
352 //=======================================================================
353 //function : SelectionType
354 //purpose : gives the SelectionMode according to the Type od Decomposition...
355 //=======================================================================
356 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
371 case TopAbs_COMPSOLID:
373 case TopAbs_COMPOUND:
382 //=======================================================================
383 //function : ComputeSelection
385 //=======================================================================
387 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
388 const Standard_Integer aMode)
390 if(myshape.IsNull()) return;
391 if (myshape.ShapeType() == TopAbs_COMPOUND) {
392 TopoDS_Iterator anExplor (myshape);
394 if (!anExplor.More()) // empty Shape -> empty Assembly.
398 TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
399 TopoDS_Shape shape = myshape;
401 // POP protection against crash in low layers
403 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
406 StdSelect_BRepSelectionTool::Load(aSelection,
411 myDrawer->HLRAngle(),
412 myDrawer->IsAutoTriangulation());
413 } catch ( Standard_Failure ) {
414 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
417 Bnd_Box B = BoundingBox();
418 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
419 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
420 aSelection->Add(aSensitiveBox);
424 // insert the drawer in the BrepOwners for hilight...
425 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
428 Quantity_NameOfColor AIS_Shape::Color() const {
429 Quantity_Color aColor;
431 return aColor.Name();
434 void AIS_Shape::Color( Quantity_Color& aColor ) const {
435 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
438 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
439 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
442 Standard_Real AIS_Shape::Transparency() const {
443 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
446 //=======================================================================
447 //function : SetColor
449 //=======================================================================
451 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
453 SetColor(Quantity_Color(aCol));
456 //=======================================================================
457 //function : setColor
459 //=======================================================================
461 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
462 const Quantity_Color& theColor) const
464 if (!theDrawer->HasOwnShadingAspect())
466 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
467 if (theDrawer->HasLink())
469 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
472 if (!theDrawer->HasOwnLineAspect())
474 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
475 if (theDrawer->HasLink())
477 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
480 if (!theDrawer->HasOwnWireAspect())
482 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
483 if (theDrawer->HasLink())
485 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
488 if (!theDrawer->HasOwnPointAspect())
490 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
491 if (theDrawer->HasLink())
493 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
496 if (!theDrawer->HasOwnFreeBoundaryAspect())
498 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
499 if (theDrawer->HasLink())
501 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
504 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
506 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
507 if (theDrawer->HasLink())
509 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
512 if (!theDrawer->HasOwnSeenLineAspect())
514 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
515 if (theDrawer->HasLink())
517 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
522 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
523 theDrawer->SetShadingAspectGlobal (Standard_False);
524 theDrawer->LineAspect()->SetColor (theColor);
525 theDrawer->WireAspect()->SetColor (theColor);
526 theDrawer->PointAspect()->SetColor (theColor);
527 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
528 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
529 theDrawer->SeenLineAspect()->SetColor (theColor);
532 //=======================================================================
533 //function : SetColor
535 //=======================================================================
537 void AIS_Shape::SetColor (const Quantity_Color& theColor)
539 setColor (myDrawer, theColor);
540 myOwnColor = theColor;
541 hasOwnColor = Standard_True;
543 // modify shading presentation without re-computation
544 const PrsMgr_Presentations& aPrsList = Presentations();
545 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
546 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
547 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
548 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
550 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
551 if (aPrsModed.Mode() != AIS_Shaded)
556 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
558 // Set aspects for presentation
559 aPrs->SetPrimitivesAspect (anAreaAspect);
560 aPrs->SetPrimitivesAspect (aLineAspect);
561 aPrs->SetPrimitivesAspect (aPointAspect);
563 // Go through all groups to change color for all primitives
564 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
566 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
568 // Check if aspect of given type is set for the group,
569 // because setting aspect for group with no already set aspect
570 // can lead to loss of presentation data
571 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
573 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
575 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
577 aGroup->SetGroupPrimitivesAspect (aLineAspect);
579 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
581 aGroup->SetGroupPrimitivesAspect (aPointAspect);
586 LoadRecomputable (AIS_WireFrame);
587 LoadRecomputable (2);
590 //=======================================================================
591 //function : UnsetColor
593 //=======================================================================
595 void AIS_Shape::UnsetColor()
599 myToRecomputeModes.Clear();
602 hasOwnColor = Standard_False;
606 Handle(Prs3d_LineAspect) anEmptyAsp;
607 myDrawer->SetLineAspect (anEmptyAsp);
608 myDrawer->SetWireAspect (anEmptyAsp);
609 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
610 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
611 myDrawer->SetSeenLineAspect (anEmptyAsp);
615 Quantity_Color aColor = Quantity_NOC_YELLOW;
616 if (myDrawer->HasLink())
618 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
620 myDrawer->LineAspect()->SetColor (aColor);
621 aColor = Quantity_NOC_RED;
622 if (myDrawer->HasLink())
624 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
626 myDrawer->WireAspect()->SetColor (aColor);
627 aColor = Quantity_NOC_GREEN;
628 if (myDrawer->HasLink())
630 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
632 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
633 aColor = Quantity_NOC_YELLOW;
634 if (myDrawer->HasLink())
636 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
638 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
639 if (myDrawer->HasLink())
641 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
643 myDrawer->SeenLineAspect()->SetColor (aColor);
649 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
650 Graphic3d_MaterialAspect mat = aDefaultMat;
651 if (HasMaterial() || myDrawer->HasLink())
653 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
657 Quantity_Color aColor = aDefaultMat.AmbientColor();
658 if (myDrawer->HasLink())
660 aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
662 mat.SetColor (aColor);
666 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
667 mat.SetTransparency (aTransp);
669 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
673 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
675 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
677 // modify shading presentation without re-computation
678 const PrsMgr_Presentations& aPrsList = Presentations();
679 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
680 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
681 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
683 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
684 if (aPrsModed.Mode() != AIS_Shaded)
689 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
691 aPrs->SetPrimitivesAspect (anAreaAsp);
692 aPrs->SetPrimitivesAspect (aLineAsp);
694 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
696 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
698 // Check if aspect of given type is set for the group,
699 // because setting aspect for group with no already set aspect
700 // can lead to loss of presentation data
701 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
703 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
705 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
707 aGroup->SetGroupPrimitivesAspect (aLineAsp);
712 LoadRecomputable (AIS_WireFrame);
713 LoadRecomputable (2);
716 //=======================================================================
717 //function : setWidth
719 //=======================================================================
721 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
722 const Standard_Real theLineWidth) const
724 if (!theDrawer->HasOwnLineAspect())
726 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
727 if (theDrawer->HasLink())
729 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
732 if (!theDrawer->HasOwnWireAspect())
734 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
735 if (theDrawer->HasLink())
737 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
740 if (!theDrawer->HasOwnFreeBoundaryAspect())
742 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
743 if (theDrawer->HasLink())
745 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
748 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
750 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
751 if (theDrawer->HasLink())
753 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
756 if (!theDrawer->HasOwnSeenLineAspect())
758 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
759 if (theDrawer->HasLink())
761 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
766 theDrawer->LineAspect()->SetWidth (theLineWidth);
767 theDrawer->WireAspect()->SetWidth (theLineWidth);
768 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
769 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
770 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
773 //=======================================================================
774 //function : SetWidth
776 //=======================================================================
778 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
780 setWidth (myDrawer, theLineWidth);
781 myOwnWidth = theLineWidth;
782 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
783 LoadRecomputable (2); // and the bounding box...
786 //=======================================================================
787 //function : UnsetWidth
789 //=======================================================================
791 void AIS_Shape::UnsetWidth()
793 if (myOwnWidth == 0.0)
795 myToRecomputeModes.Clear();
801 Handle(Prs3d_LineAspect) anEmptyAsp;
805 myDrawer->SetLineAspect (anEmptyAsp);
806 myDrawer->SetWireAspect (anEmptyAsp);
807 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
808 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
809 myDrawer->SetSeenLineAspect (anEmptyAsp);
813 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
814 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
815 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
816 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
817 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
818 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
819 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
820 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
821 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
822 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
824 LoadRecomputable (AIS_WireFrame);
827 //=======================================================================
828 //function : setMaterial
830 //=======================================================================
832 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
833 const Graphic3d_MaterialAspect& theMaterial,
834 const Standard_Boolean theToKeepColor,
835 const Standard_Boolean theToKeepTransp) const
837 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
838 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
839 if (!theDrawer->HasOwnShadingAspect())
841 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
842 if (theDrawer->HasLink())
844 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
847 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
851 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
855 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
859 //=======================================================================
860 //function : SetMaterial
862 //=======================================================================
864 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
866 SetMaterial(Graphic3d_MaterialAspect(aMat));
869 //=======================================================================
870 //function : SetMaterial
872 //=======================================================================
874 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
876 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
877 hasOwnMaterial = Standard_True;
879 // modify shading presentation without re-computation
880 const PrsMgr_Presentations& aPrsList = Presentations();
881 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
882 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
884 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
885 if (aPrsModed.Mode() != AIS_Shaded)
890 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
891 aPrs->SetPrimitivesAspect (anAreaAsp);
892 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
894 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
896 // Check if aspect of given type is set for the group,
897 // because setting aspect for group with no already set aspect
898 // can lead to loss of presentation data
899 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
901 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
906 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
907 myToRecomputeModes.Clear();
910 //=======================================================================
911 //function : UnsetMaterial
913 //=======================================================================
915 void AIS_Shape::UnsetMaterial()
925 if(myDrawer->HasLink())
927 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
928 myCurrentFacingModel);
932 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
933 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
938 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
940 hasOwnMaterial = Standard_False;
942 // modify shading presentation without re-computation
943 const PrsMgr_Presentations& aPrsList = Presentations();
944 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
945 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
947 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
948 if (aPrsModed.Mode() != AIS_Shaded)
953 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
954 aPrs->SetPrimitivesAspect (anAreaAsp);
955 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
957 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
958 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
960 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
965 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
966 myToRecomputeModes.Clear();
969 //=======================================================================
970 //function : setTransparency
972 //=======================================================================
974 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
975 const Standard_Real theValue) const
977 if (!theDrawer->HasOwnShadingAspect())
979 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
980 if (theDrawer->HasLink())
982 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
986 // override transparency
987 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
990 //=======================================================================
991 //function : SetTransparency
993 //=======================================================================
995 void AIS_Shape::SetTransparency (const Standard_Real theValue)
997 setTransparency (myDrawer, theValue);
998 myTransparency = theValue;
1000 // modify shading presentation without re-computation
1001 const PrsMgr_Presentations& aPrsList = Presentations();
1002 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1003 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1005 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1006 if (aPrsModed.Mode() != AIS_Shaded)
1011 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1012 aPrs->SetPrimitivesAspect (anAreaAsp);
1013 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
1014 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1016 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1017 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1019 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1024 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
1025 myToRecomputeModes.Clear();
1028 //=======================================================================
1029 //function : UnsetTransparency
1031 //=======================================================================
1033 void AIS_Shape::UnsetTransparency()
1035 myTransparency = 0.0;
1036 if (!myDrawer->HasOwnShadingAspect())
1040 else if (HasColor() || HasMaterial())
1042 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
1046 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
1049 // modify shading presentation without re-computation
1050 const PrsMgr_Presentations& aPrsList = Presentations();
1051 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1052 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1054 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1055 if (aPrsModed.Mode() != AIS_Shaded)
1060 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1061 aPrs->SetPrimitivesAspect (anAreaAsp);
1062 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1064 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1065 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1067 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1070 aPrs->ResetDisplayPriority();
1073 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1074 myToRecomputeModes.Clear();
1077 //=======================================================================
1078 //function : LoadRecomputable
1080 //=======================================================================
1082 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1084 myRecomputeEveryPrs = Standard_False;
1085 if(!IsInList(myToRecomputeModes,TheMode))
1086 myToRecomputeModes.Append(TheMode);
1089 //=======================================================================
1090 //function : BoundingBox
1092 //=======================================================================
1094 const Bnd_Box& AIS_Shape::BoundingBox()
1096 if (myshape.ShapeType() == TopAbs_COMPOUND) {
1097 TopoDS_Iterator anExplor (myshape);
1099 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1106 BRepBndLib::AddClose(myshape, myBB);
1107 myCompBB = Standard_False;
1114 //=======================================================================
1115 //function : SetOwnDeviationCoefficient
1116 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1117 // returns Standard_True if it change
1118 //=======================================================================
1120 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1122 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1123 if(itSet) myDrawer->SetDeviationCoefficient();
1127 //=======================================================================
1128 //function : SetHLROwnDeviationCoefficient
1129 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1130 // returns Standard_True if it change
1131 //=======================================================================
1133 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1135 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1136 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1141 //=======================================================================
1142 //function : SetOwnDeviationAngle
1143 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1144 // returns Standard_True if it change
1145 //=======================================================================
1147 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1149 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1150 if(itSet) myDrawer->SetDeviationAngle();
1155 //=======================================================================
1156 //function : SetOwnHLRDeviationAngle
1157 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1158 // returns Standard_True if it change
1159 //=======================================================================
1161 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1163 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1164 if(itSet) myDrawer->SetHLRAngle();
1169 //=======================================================================
1170 //function : SetOwnDeviationCoefficient
1172 //=======================================================================
1174 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1176 myDrawer->SetDeviationCoefficient( aCoefficient );
1177 SetToUpdate(0) ; // WireFrame
1178 SetToUpdate(1) ; // Shadding
1181 //=======================================================================
1182 //function : SetOwnHLRDeviationCoefficient
1184 //=======================================================================
1186 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1188 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1192 //=======================================================================
1193 //function : SetOwnDeviationAngle
1195 //=======================================================================
1197 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1200 myDrawer->SetDeviationAngle(anAngle );
1201 SetToUpdate(0) ; // WireFrame
1203 //=======================================================================
1204 //function : SetOwnDeviationAngle
1206 //=======================================================================
1208 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1210 Standard_Real OutAngl,OutDefl;
1211 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1212 SetOwnDeviationAngle(anAngle) ;
1213 SetOwnDeviationCoefficient(OutDefl) ;
1214 myInitAng = anAngle;
1219 //=======================================================================
1220 //function : UserAngle
1222 //=======================================================================
1224 Standard_Real AIS_Shape::UserAngle() const
1226 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1230 //=======================================================================
1231 //function : SetHLRAngleAndDeviation
1233 //=======================================================================
1235 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1237 Standard_Real OutAngl,OutDefl;
1238 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1239 SetOwnHLRDeviationAngle( OutAngl );
1240 SetOwnHLRDeviationCoefficient(OutDefl);
1243 //=======================================================================
1244 //function : SetOwnHLRDeviationAngle
1246 //=======================================================================
1248 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1250 myDrawer->SetHLRAngle( anAngle );
1254 //=======================================================================
1255 //function : OwnDeviationCoefficient
1257 //=======================================================================
1259 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1260 Standard_Real & aPreviousCoefficient ) const
1262 aCoefficient = myDrawer->DeviationCoefficient();
1263 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1264 return myDrawer->HasOwnDeviationCoefficient() ;
1267 //=======================================================================
1268 //function : OwnHLRDeviationCoefficient
1270 //=======================================================================
1272 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1273 Standard_Real & aPreviousCoefficient ) const
1275 aCoefficient = myDrawer->HLRDeviationCoefficient();
1276 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1277 return myDrawer->HasOwnHLRDeviationCoefficient();
1281 //=======================================================================
1282 //function : OwnDeviationAngle
1284 //=======================================================================
1286 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1287 Standard_Real & aPreviousAngle ) const
1289 anAngle = myDrawer->DeviationAngle();
1290 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1291 return myDrawer->HasOwnDeviationAngle();
1294 //=======================================================================
1295 //function : OwnHLRDeviationAngle
1297 //=======================================================================
1299 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1300 Standard_Real & aPreviousAngle ) const
1302 anAngle = myDrawer->HLRAngle();
1303 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1304 return myDrawer->HasOwnHLRDeviationAngle();