Salome HOME
Issue #1860: fix end lines with spaces
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_SymbolPrs.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_SymbolPrs.h
4 // Created:     12 March 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef SketcherPrs_SymbolPrs_H
8 #define SketcherPrs_SymbolPrs_H
9
10 #include "SketcherPrs_SensitivePoint.h"
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_AttributeRefList.h>
13
14 #include <AIS_InteractiveObject.hxx>
15 #include <GeomAPI_Ax3.h>
16 #include <Graphic3d_ArrayOfPoints.hxx>
17 #include <Graphic3d_AspectMarker3d.hxx>
18 #include <Image_AlienPixMap.hxx>
19 #include <SelectMgr_EntityOwner.hxx>
20 #include <Select3D_EntitySequence.hxx>
21
22 #include <Standard_DefineHandle.hxx>
23 #include <map>
24
25 #include <OpenGl_Workspace.hxx>
26
27 class OpenGl_Context;
28
29
30 DEFINE_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject)
31
32 /**
33 * \ingroup GUI
34 * A base class of constraint presentation which is represented by an icon
35 */
36 class SketcherPrs_SymbolPrs: public AIS_InteractiveObject
37 {
38 public:
39   /// Constructor
40   /// \param theConstraint a constraint feature
41   /// \param thePlane a coordinate plane of current sketch
42   Standard_EXPORT SketcherPrs_SymbolPrs(ModelAPI_Feature* theConstraint,
43                         const std::shared_ptr<GeomAPI_Ax3>& thePlane);
44
45   virtual ~SketcherPrs_SymbolPrs();
46
47   //! Method which draws selected owners ( for fast presentation draw )
48   Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
49                                                const SelectMgr_SequenceOfOwner& theOwners);
50
51   //! Method which hilight an owner belonging to
52   //! this selectable object  ( for fast presentation draw )
53   Standard_EXPORT virtual void HilightOwnerWithColor(
54     const Handle(PrsMgr_PresentationManager3d)& thePM,
55     const Quantity_NameOfColor theColor,
56     const Handle(SelectMgr_EntityOwner)& theOwner);
57
58   /// Returns sketcher plane
59   Standard_EXPORT std::shared_ptr<GeomAPI_Ax3> plane() const { return myPlane; }
60
61   /// Returns feature object
62   Standard_EXPORT ModelAPI_Feature* feature() const { return myConstraint; }
63
64   /// Return array of points where symbols will be placed
65   const Handle(Graphic3d_ArrayOfPoints)& pointsArray() const { return myPntArray; }
66
67   /// Set state of the presentation, in case of conflicting state, the icon of the presentation is
68   /// visualized in error color. The state is stored in an internal field, so should be changed
69   /// when constraint become not conflicting
70   /// \param theConflicting a state
71   /// \param theColor a color for conflicting object
72   Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting,
73                                                 const std::vector<int>& theColor);
74
75   /// Render of the presentation
76   /// \param theWorkspace is OpenGl workspace
77   void Render(const Handle(OpenGl_Workspace)& theWorkspace) const;
78
79   /// Release used OpenGl resources
80   /// \param theContext is an OpenGL context
81   void Release (OpenGl_Context* theContext);
82
83   /// Add a bounding box of the presentation to common bounding box
84   /// \param theBndBox the common bounding box to update
85   Standard_EXPORT virtual void BoundingBox (Bnd_Box& theBndBox) Standard_OVERRIDE;
86
87   DEFINE_STANDARD_RTTI(SketcherPrs_SymbolPrs)
88
89 protected:
90   /// Redefinition of virtual function
91   Standard_EXPORT virtual void Compute(
92     const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
93     const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
94
95   /// Redefinition of virtual function
96   /// \param aSelection selection
97   /// \param aMode compute mode
98   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
99     const Standard_Integer aMode);
100
101   /// Returns an icon file name. Has to be redefined in successors
102   virtual const char* iconName() const = 0;
103
104   /// Check and creates if it is necessary myAspect member.
105   /// It has to be called before the object computation
106   virtual void prepareAspect();
107
108   /// Returns icon corresponded to the current constraint type
109   Handle(Image_AlienPixMap) icon();
110
111   /// Add a line into the given group
112   /// \param theGroup a group for drawing
113   /// \param theAttrName an attribute name which corresponds to referenced line
114   void addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const;
115
116   /// Redefine this function in order to add additiona lines of constraint base
117   /// \param thePrs a presentation
118   /// \param theColor a color of additiona lines
119   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const {}
120
121   /// Update myPntArray according to presentation positions
122   /// \return true in case of success
123   virtual bool updateIfReadyToDisplay(double theStep) const { return true; }
124
125   /// Draw a shape into the given presentation scene
126   /// \param theShape the shape to draw
127   /// \param thePrs the presentation scene
128   void drawShape(const std::shared_ptr<GeomAPI_Shape>& theShape,
129     const Handle(Prs3d_Presentation)& thePrs) const;
130
131   /// Draw a list of shapes stored in a RefListAttribute
132   /// \param theListAttr the attribute of reference3s list
133   /// \param thePrs the presentation scene
134   void drawListOfShapes(const std::shared_ptr<ModelAPI_AttributeRefList>& theListAttr,
135                         const Handle(Prs3d_Presentation)& thePrs) const;
136
137 protected:
138   /// Constraint feature
139   ModelAPI_Feature* myConstraint;
140
141   /// Plane of the current sketcher
142   std::shared_ptr<GeomAPI_Ax3> myPlane;
143
144   /// Aspect for entities drawing
145   Handle(Graphic3d_AspectMarker3d) myAspect;
146
147   /// Array of symbols positions
148   mutable Handle(Graphic3d_ArrayOfPoints) myPntArray;
149
150   /// An owner object of the presentation
151   Handle(SelectMgr_EntityOwner) myOwner;
152
153 private:
154   /// Static map to collect constraints icons {IconName : IconPixMap}
155   static std::map<const char*, Handle(Image_AlienPixMap)> myIconsMap;
156
157   mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
158
159   Select3D_EntitySequence mySPoints;
160
161   bool myIsConflicting; /// state if the presentation is visualized in error state
162   Handle(Image_AlienPixMap) myErrorIcon;
163   Handle(Graphic3d_MarkerImage) myErrorImage;
164 };
165
166 #endif