diff --git a/src/AIS/AIS_RubberBand.cxx b/src/AIS/AIS_RubberBand.cxx index b822316486..1d7f1ab9d1 100644 --- a/src/AIS/AIS_RubberBand.cxx +++ b/src/AIS/AIS_RubberBand.cxx @@ -39,6 +39,7 @@ IMPLEMENT_STANDARD_RTTIEXT(AIS_RubberBand, AIS_InteractiveObject) //purpose : //======================================================================= AIS_RubberBand::AIS_RubberBand() +: myIsPolygonClosed(Standard_True) { myDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0)); myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); @@ -57,7 +58,9 @@ AIS_RubberBand::AIS_RubberBand() //======================================================================= AIS_RubberBand::AIS_RubberBand (const Quantity_Color& theLineColor, const Aspect_TypeOfLine theLineType, - const Standard_Real theWidth) + const Standard_Real theWidth, + const Standard_Boolean theIsPolygonClosed) +: myIsPolygonClosed(theIsPolygonClosed) { myDrawer->SetLineAspect (new Prs3d_LineAspect (theLineColor, theLineType, theWidth)); myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); @@ -78,7 +81,9 @@ AIS_RubberBand::AIS_RubberBand (const Quantity_Color& theLineColor, const Aspect_TypeOfLine theLineType, const Quantity_Color theFillColor, const Standard_Real theTransparency, - const Standard_Real theLineWidth) + const Standard_Real theLineWidth, + const Standard_Boolean theIsPolygonClosed) +: myIsPolygonClosed (theIsPolygonClosed) { myDrawer->SetLineAspect (new Prs3d_LineAspect (theLineColor, theLineType, theLineWidth)); myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); @@ -263,6 +268,24 @@ Standard_Boolean AIS_RubberBand::IsFilling() const return aStyle != Aspect_IS_EMPTY; } +//======================================================================= +//function : IsPolygonClosed +//purpose : +//======================================================================= +Standard_Boolean AIS_RubberBand::IsPolygonClosed() const +{ + return myIsPolygonClosed; +} + +//======================================================================= +//function : SetPolygonClosed +//purpose : +//======================================================================= +void AIS_RubberBand::SetPolygonClosed(Standard_Boolean theIsPolygonClosed) +{ + myIsPolygonClosed = theIsPolygonClosed; +} + //======================================================================= //function : fillTriangles //purpose : @@ -376,17 +399,20 @@ void AIS_RubberBand::Compute (const Handle(PrsMgr_PresentationManager3d)& /*theP } // Draw frame - if (myBorders.IsNull() || myBorders->VertexNumber() != myPoints.Length() + 1) + if (myBorders.IsNull() || myBorders->VertexNumber() != myPoints.Length() + (myIsPolygonClosed ? 1 : 0)) { - myBorders = new Graphic3d_ArrayOfPolylines (myPoints.Length() + 1); + myBorders = new Graphic3d_ArrayOfPolylines(myPoints.Length() + (myIsPolygonClosed ? 1 : 0)); for (Standard_Integer anIt = 1; anIt <= myPoints.Length(); anIt++) { myBorders->AddVertex ((Standard_Real)myPoints.Value (anIt).x(), (Standard_Real)myPoints.Value (anIt).y(), 0.0); } - myBorders->AddVertex ((Standard_Real)myPoints.Value(1).x(), - (Standard_Real)myPoints.Value(1).y(), 0.0); + if (myIsPolygonClosed) + { + myBorders->AddVertex((Standard_Real)myPoints.Value(1).x(), + (Standard_Real)myPoints.Value(1).y(), 0.0); + } } else @@ -397,8 +423,11 @@ void AIS_RubberBand::Compute (const Handle(PrsMgr_PresentationManager3d)& /*theP (Standard_ShortReal)myPoints.Value (anIt).y(), 0.0f); } - myBorders->SetVertice (myPoints.Length() + 1, (Standard_ShortReal)myPoints.Value(1).x(), + if (myIsPolygonClosed) + { + myBorders->SetVertice(myPoints.Length() + 1, (Standard_ShortReal)myPoints.Value(1).x(), (Standard_ShortReal)myPoints.Value(1).y(), 0.0f); + } } aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect()); diff --git a/src/AIS/AIS_RubberBand.hxx b/src/AIS/AIS_RubberBand.hxx index dc1000cb46..7ef181f000 100644 --- a/src/AIS/AIS_RubberBand.hxx +++ b/src/AIS/AIS_RubberBand.hxx @@ -47,7 +47,8 @@ public: //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer. Standard_EXPORT AIS_RubberBand (const Quantity_Color& theLineColor, const Aspect_TypeOfLine theType, - const Standard_Real theLineWidth = 1.0); + const Standard_Real theLineWidth = 1.0, + const Standard_Boolean theIsPolygonClosed = Standard_True); //! Constructs the rubber band with defined filling and line parameters. //! @param theLineColor [in] color of rubber band lines @@ -60,7 +61,8 @@ public: const Aspect_TypeOfLine theType, const Quantity_Color theFillColor, const Standard_Real theTransparency = 1.0, - const Standard_Real theLineWidth = 1.0); + const Standard_Real theLineWidth = 1.0, + const Standard_Boolean theIsPolygonClosed = Standard_True); Standard_EXPORT virtual ~AIS_RubberBand(); @@ -94,7 +96,7 @@ public: //! Sets color of rubber band filling. Standard_EXPORT void SetFillColor (const Quantity_Color& theColor); - //! Sets wodth of line for rubber band presentation. + //! Sets width of line for rubber band presentation. Standard_EXPORT void SetLineWidth (const Standard_Real theWidth) const; //! @return width of lines. @@ -124,6 +126,13 @@ public: //! @return true if filling of rubber band is enabled. Standard_EXPORT Standard_Boolean IsFilling() const; + //! @return true if automatic closing of rubber band is enabled. + Standard_EXPORT Standard_Boolean IsPolygonClosed() const; + + //! Automatically create an additional line connecting the first and + //! the last screen points to close the boundary polyline + Standard_EXPORT void SetPolygonClosed(Standard_Boolean theIsPolygonClosed); + protected: //! Computes presentation of rubber band. @@ -146,5 +155,7 @@ protected: Handle(Graphic3d_ArrayOfTriangles) myTriangles; //!< Triangles for rubber band filling Handle(Graphic3d_ArrayOfPolylines) myBorders; //!< Polylines for rubber band borders + + Standard_Boolean myIsPolygonClosed; //!< automatic closing of rubber-band flag }; #endif