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 //! Presentation for drawing rubber band selection.
26 //! It supports rectangle and polygonal selection.
27 //! It is constructed in 2d overlay.
28 //! Default configaration is built without filling.
29 //! For rectangle selection use SetRectangle() method.
30 //! For polygonal selection use AddPoint() and GetPoints() methods.
31 class AIS_RubberBand : public AIS_InteractiveObject
35 DEFINE_STANDARD_RTTIEXT(AIS_RubberBand, AIS_InteractiveObject)
37 //! Constructs rubber band with default configuration: empty filling and white solid lines.
38 //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer.
39 Standard_EXPORT AIS_RubberBand();
41 //! Consructs the rubber band with empty filling and defined line style.
42 //! @param theLineColor [in] color of rubber band lines
43 //! @param theType [in] type of rubber band lines
44 //! @param theLineWidth [in] width of rubber band line. By default it is 1.
45 //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer.
46 Standard_EXPORT AIS_RubberBand (const Quantity_Color& theLineColor,
47 const Aspect_TypeOfLine theType,
48 const Standard_Real theLineWidth = 1.0);
50 //! Constructs the rubber band with defined filling and line parameters.
51 //! @param theLineColor [in] color of rubber band lines
52 //! @param theType [in] type of rubber band lines
53 //! @param theFillColor [in] color of rubber band filling
54 //! @param theTransparency [in] transparency of the filling. 0 is for opaque filling. By default it is transparent.
55 //! @param theLineWidth [in] width of rubber band line. By default it is 1.
56 //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer.
57 Standard_EXPORT AIS_RubberBand (const Quantity_Color& theLineColor,
58 const Aspect_TypeOfLine theType,
59 const Quantity_Color theFillColor,
60 const Standard_Real theTransparency = 1.0,
61 const Standard_Real theLineWidth = 1.0);
63 Standard_EXPORT virtual ~AIS_RubberBand();
65 //! Sets rectangle bounds.
66 Standard_EXPORT void SetRectangle (const Standard_Integer theMinX, const Standard_Integer theMinY,
67 const Standard_Integer theMaxX, const Standard_Integer theMaxY);
69 //! Adds last point to the list of points. They are used to build polygon for rubber band.
70 //! @sa RemoveLastPoint(), GetPoints()
71 Standard_EXPORT void AddPoint (const Graphic3d_Vec2i& thePoint);
73 //! Remove last point from the list of points for the rubber band polygon.
74 //! @sa AddPoint(), GetPoints()
75 Standard_EXPORT void RemoveLastPoint();
77 //! @return points for the rubber band polygon.
78 Standard_EXPORT const NCollection_Sequence<Graphic3d_Vec2i>& Points() const;
80 //! Remove all points for the rubber band polygon.
81 void ClearPoints() { myPoints.Clear(); }
83 //! @return the Color attributes.
84 Standard_EXPORT Quantity_Color LineColor() const;
86 //! Sets color of lines for rubber band presentation.
87 Standard_EXPORT void SetLineColor (const Quantity_Color& theColor);
89 //! @return the color of rubber band filling.
90 Standard_EXPORT Quantity_Color FillColor() const;
92 //! Sets color of rubber band filling.
93 Standard_EXPORT void SetFillColor (const Quantity_Color& theColor);
95 //! Sets wodth of line for rubber band presentation.
96 Standard_EXPORT void SetLineWidth (const Standard_Real theWidth) const;
98 //! @return width of lines.
99 Standard_EXPORT Standard_Real LineWidth() const;
101 //! Sets type of line for rubber band presentation.
102 Standard_EXPORT void SetLineType (const Aspect_TypeOfLine theType);
104 //! @return type of lines.
105 Standard_EXPORT Aspect_TypeOfLine LineType() const;
107 //! Sets fill transparency.
108 //! @param theValue [in] the transparency value. 1.0 is for transparent background
109 Standard_EXPORT void SetFillTransparency (const Standard_Real theValue) const;
111 //! @return fill transparency.
112 Standard_EXPORT Standard_Real FillTransparency() const;
114 //! Enable or disable filling of rubber band.
115 Standard_EXPORT void SetFilling (const Standard_Boolean theIsFilling);
117 //! Enable filling of rubber band with defined parameters.
118 //! @param theColor [in] color of filling
119 //! @param theTransparency [in] transparency of the filling. 0 is for opaque filling.
120 Standard_EXPORT void SetFilling (const Quantity_Color theColor, const Standard_Real theTransparency);
122 //! @return true if filling of rubber band is enabled.
123 Standard_EXPORT Standard_Boolean IsFilling() const;
127 //! Computes presentation of rubber band.
128 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
129 const Handle(Prs3d_Presentation)& thePresentation,
130 const Standard_Integer theMode) Standard_OVERRIDE;
132 //! Does not fill selection primitives for rubber band.
133 void virtual ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
134 const Standard_Integer /*aMode*/) Standard_OVERRIDE { };
136 //! Fills triangles primitive array for rubber band filling.
137 //! It uses Delaunay triangulation.
138 //! @return true if array of triangles is successfully filled.
139 Standard_EXPORT Standard_Boolean fillTriangles();
143 NCollection_Sequence<Graphic3d_Vec2i> myPoints; //!< Array of screen points
145 Handle(Graphic3d_ArrayOfTriangles) myTriangles; //!< Triangles for rubber band filling
146 Handle(Graphic3d_ArrayOfPolylines) myBorders; //!< Polylines for rubber band borders