Warnings on vc14 were eliminated
[occt.git] / src / AIS / AIS_RubberBand.hxx
1 // Created on: 2015-11-23
2 // Created by: Anastasia BORISOVA
3 // Copyright (c) 2015 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _AIS_RubberBand_HeaderFile
17 #define _AIS_RubberBand_HeaderFile
18
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>
24
25 DEFINE_STANDARD_HANDLE(AIS_RubberBand, AIS_InteractiveObject)
26
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
34 {
35 public:
36
37   DEFINE_STANDARD_RTTIEXT(AIS_RubberBand, AIS_InteractiveObject)
38
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();
42
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
52   //! Constructs the rubber band with defined filling and line parameters.
53   //! @param theLineColor [in] color of rubber band lines
54   //! @param theType [in] type of rubber band lines
55   //! @param theFillColor [in] color of rubber band filling
56   //! @param theTransparency [in] transparency of the filling. 0 is for opaque filling. By default it is transparent.
57   //! @param theLineWidth [in] width of rubber band line. By default it is 1.
58   //! @warning It binds this object with Graphic3d_ZLayerId_TopOSD layer.
59   Standard_EXPORT AIS_RubberBand (const Quantity_Color& theLineColor,
60                                   const Aspect_TypeOfLine theType,
61                                   const Quantity_Color theFillColor,
62                                   const Standard_Real theTransparency = 1.0,
63                                   const Standard_Real theLineWidth = 1.0);
64
65   Standard_EXPORT virtual ~AIS_RubberBand();
66
67   //! Sets rectangle bounds.
68   Standard_EXPORT void SetRectangle (const Standard_Integer theMinX, const Standard_Integer theMinY,
69                                      const Standard_Integer theMaxX, const Standard_Integer theMaxY);
70
71   //! Adds last point to the list of points. They are used to build polygon for rubber band.
72   //! @sa RemoveLastPoint(), GetPoints()
73   Standard_EXPORT void AddPoint (const Graphic3d_Vec2i& thePoint);
74
75   //! Remove last point from the list of points for the rubber band polygon.
76   //! @sa AddPoint(), GetPoints()
77   Standard_EXPORT void RemoveLastPoint();
78
79   //! @return points for the rubber band polygon.
80   Standard_EXPORT const NCollection_Sequence<Graphic3d_Vec2i>& Points() const;
81
82   //! Remove all points for the rubber band polygon.
83   void ClearPoints() { myPoints.Clear(); }
84
85   //! @return the Color attributes.
86   Standard_EXPORT Quantity_Color LineColor() const;
87
88   //! Sets color of lines for rubber band presentation.
89   Standard_EXPORT void SetLineColor (const Quantity_Color& theColor);
90
91   //! @return the color of rubber band filling.
92   Standard_EXPORT Quantity_Color FillColor() const;
93
94   //! Sets color of rubber band filling.
95   Standard_EXPORT void SetFillColor (const Quantity_Color& theColor);
96
97   //! Sets wodth of line for rubber band presentation.
98   Standard_EXPORT void SetLineWidth (const Standard_Real theWidth) const;
99
100   //! @return width of lines.
101   Standard_EXPORT Standard_Real LineWidth() const;
102
103   //! Sets type of line for rubber band presentation.
104   Standard_EXPORT void SetLineType (const Aspect_TypeOfLine theType);
105
106   //! @return type of lines.
107   Standard_EXPORT Aspect_TypeOfLine LineType() const;
108
109   //! Sets fill transparency.
110   //! @param theValue [in] the transparency value. 1.0 is for transparent background
111   Standard_EXPORT void SetFillTransparency (const Standard_Real theValue) const;
112
113   //! @return fill transparency.
114   Standard_EXPORT Standard_Real FillTransparency() const;
115
116   //! Enable or disable filling of rubber band.
117   Standard_EXPORT void SetFilling (const Standard_Boolean theIsFilling);
118
119   //! Enable filling of rubber band with defined parameters.
120   //! @param theColor [in] color of filling
121   //! @param theTransparency [in] transparency of the filling. 0 is for opaque filling.
122   Standard_EXPORT void SetFilling (const Quantity_Color theColor, const Standard_Real theTransparency);
123
124   //! @return true if filling of rubber band is enabled.
125   Standard_EXPORT Standard_Boolean IsFilling() const;
126
127 protected:
128
129   //! Computes presentation of rubber band.
130   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
131                                         const Handle(Prs3d_Presentation)& thePresentation,
132                                         const Standard_Integer theMode) Standard_OVERRIDE;
133
134   //! Does not fill selection primitives for rubber band.
135   virtual void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
136                                  const Standard_Integer /*aMode*/) Standard_OVERRIDE { };
137
138   //! Fills triangles primitive array for rubber band filling.
139   //! It uses Delaunay triangulation.
140   //! @return true if array of triangles is successfully filled.
141   Standard_EXPORT Standard_Boolean fillTriangles();
142
143 protected:
144
145   NCollection_Sequence<Graphic3d_Vec2i> myPoints; //!< Array of screen points
146
147   Handle(Graphic3d_ArrayOfTriangles) myTriangles; //!< Triangles for rubber band filling
148   Handle(Graphic3d_ArrayOfPolylines) myBorders; //!< Polylines for rubber band borders
149 };
150 #endif