1 // Created on: 2015-11-23
2 // Created by: Anastasia BORISOVA
3 // Copyright (c) 2015 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _AIS_RubberBand_HeaderFile
17 #define _AIS_RubberBand_HeaderFile
19 #include <AIS_InteractiveObject.hxx>
20 #include <Graphic3d_ArrayOfPolylines.hxx>
21 #include <Graphic3d_ArrayOfTriangles.hxx>
22 #include <Graphic3d_Vec2.hxx>
23 #include <NCollection_Sequence.hxx>
25 DEFINE_STANDARD_HANDLE(AIS_RubberBand, AIS_InteractiveObject)
27 //! Presentation for drawing rubber band selection.
28 //! It supports rectangle and polygonal selection.
29 //! It is constructed in 2d overlay.
30 //! Default configaration is built without filling.
31 //! For rectangle selection use SetRectangle() method.
32 //! For polygonal selection use AddPoint() and GetPoints() methods.
33 class AIS_RubberBand : public AIS_InteractiveObject
37 DEFINE_STANDARD_RTTIEXT(AIS_RubberBand, AIS_InteractiveObject)
39 //! Constructs rubber band with default configuration: empty filling and white solid lines.
40 //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer.
41 Standard_EXPORT AIS_RubberBand();
43 //! Consructs the rubber band with empty filling and defined line style.
44 //! @param theLineColor [in] color of rubber band lines
45 //! @param theType [in] type of rubber band lines
46 //! @param theLineWidth [in] width of rubber band line. By default it is 1.
47 //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer.
48 Standard_EXPORT AIS_RubberBand (const Quantity_Color& theLineColor,
49 const Aspect_TypeOfLine theType,
50 const Standard_Real theLineWidth = 1.0,
51 const Standard_Boolean theIsPolygonClosed = Standard_True);
53 //! Constructs the rubber band with defined filling and line parameters.
54 //! @param theLineColor [in] color of rubber band lines
55 //! @param theType [in] type of rubber band lines
56 //! @param theFillColor [in] color of rubber band filling
57 //! @param theTransparency [in] transparency of the filling. 0 is for opaque filling. By default it is transparent.
58 //! @param theLineWidth [in] width of rubber band line. By default it is 1.
59 //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer.
60 Standard_EXPORT AIS_RubberBand (const Quantity_Color& theLineColor,
61 const Aspect_TypeOfLine theType,
62 const Quantity_Color theFillColor,
63 const Standard_Real theTransparency = 1.0,
64 const Standard_Real theLineWidth = 1.0,
65 const Standard_Boolean theIsPolygonClosed = Standard_True);
67 Standard_EXPORT virtual ~AIS_RubberBand();
69 //! Sets rectangle bounds.
70 Standard_EXPORT void SetRectangle (const Standard_Integer theMinX, const Standard_Integer theMinY,
71 const Standard_Integer theMaxX, const Standard_Integer theMaxY);
73 //! Adds last point to the list of points. They are used to build polygon for rubber band.
74 //! @sa RemoveLastPoint(), GetPoints()
75 Standard_EXPORT void AddPoint (const Graphic3d_Vec2i& thePoint);
77 //! Remove last point from the list of points for the rubber band polygon.
78 //! @sa AddPoint(), GetPoints()
79 Standard_EXPORT void RemoveLastPoint();
81 //! @return points for the rubber band polygon.
82 Standard_EXPORT const NCollection_Sequence<Graphic3d_Vec2i>& Points() const;
84 //! Remove all points for the rubber band polygon.
85 void ClearPoints() { myPoints.Clear(); }
87 //! @return the Color attributes.
88 Standard_EXPORT Quantity_Color LineColor() const;
90 //! Sets color of lines for rubber band presentation.
91 Standard_EXPORT void SetLineColor (const Quantity_Color& theColor);
93 //! @return the color of rubber band filling.
94 Standard_EXPORT Quantity_Color FillColor() const;
96 //! Sets color of rubber band filling.
97 Standard_EXPORT void SetFillColor (const Quantity_Color& theColor);
99 //! Sets width of line for rubber band presentation.
100 Standard_EXPORT void SetLineWidth (const Standard_Real theWidth) const;
102 //! @return width of lines.
103 Standard_EXPORT Standard_Real LineWidth() const;
105 //! Sets type of line for rubber band presentation.
106 Standard_EXPORT void SetLineType (const Aspect_TypeOfLine theType);
108 //! @return type of lines.
109 Standard_EXPORT Aspect_TypeOfLine LineType() const;
111 //! Sets fill transparency.
112 //! @param theValue [in] the transparency value. 1.0 is for transparent background
113 Standard_EXPORT void SetFillTransparency (const Standard_Real theValue) const;
115 //! @return fill transparency.
116 Standard_EXPORT Standard_Real FillTransparency() const;
118 //! Enable or disable filling of rubber band.
119 Standard_EXPORT void SetFilling (const Standard_Boolean theIsFilling);
121 //! Enable filling of rubber band with defined parameters.
122 //! @param theColor [in] color of filling
123 //! @param theTransparency [in] transparency of the filling. 0 is for opaque filling.
124 Standard_EXPORT void SetFilling (const Quantity_Color theColor, const Standard_Real theTransparency);
126 //! @return true if filling of rubber band is enabled.
127 Standard_EXPORT Standard_Boolean IsFilling() const;
129 //! @return true if automatic closing of rubber band is enabled.
130 Standard_EXPORT Standard_Boolean IsPolygonClosed() const;
132 //! Automatically create an additional line connecting the first and
133 //! the last screen points to close the boundary polyline
134 Standard_EXPORT void SetPolygonClosed(Standard_Boolean theIsPolygonClosed);
138 //! Computes presentation of rubber band.
139 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
140 const Handle(Prs3d_Presentation)& thePresentation,
141 const Standard_Integer theMode) Standard_OVERRIDE;
143 //! Does not fill selection primitives for rubber band.
144 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
145 const Standard_Integer /*aMode*/) Standard_OVERRIDE { };
147 //! Fills triangles primitive array for rubber band filling.
148 //! It uses Delaunay triangulation.
149 //! @return true if array of triangles is successfully filled.
150 Standard_EXPORT Standard_Boolean fillTriangles();
154 NCollection_Sequence<Graphic3d_Vec2i> myPoints; //!< Array of screen points
156 Handle(Graphic3d_ArrayOfTriangles) myTriangles; //!< Triangles for rubber band filling
157 Handle(Graphic3d_ArrayOfPolylines) myBorders; //!< Polylines for rubber band borders
159 Standard_Boolean myIsPolygonClosed; //!< automatic closing of rubber-band flag