Salome HOME
Create check box "Show constraints"
[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
12 #include <AIS_InteractiveObject.hxx>
13 #include <GeomAPI_Ax3.h>
14 #include <Graphic3d_ArrayOfPoints.hxx>
15 #include <Graphic3d_AspectMarker3d.hxx>
16 #include <Image_AlienPixMap.hxx>
17 #include <SelectMgr_EntityOwner.hxx>
18 #include <Select3D_SensitiveEntitySequence.hxx>
19
20 #include <Standard_DefineHandle.hxx>
21 #include <map>
22
23 #include <OpenGl_Workspace.hxx>
24
25 class SketchPlugin_Constraint;
26 class OpenGl_Context;
27
28
29 DEFINE_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject)
30
31 /**
32 * \ingroup GUI
33 * A base class of constraint presentation which is represented by an icon
34 */
35 class SketcherPrs_SymbolPrs: public AIS_InteractiveObject
36 {
37 public:
38   /// Constructor
39   /// \param theConstraint a constraint feature
40   /// \param thePlane a coordinate plane of current sketch
41   Standard_EXPORT SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstraint, 
42                         const std::shared_ptr<GeomAPI_Ax3>& thePlane);
43   
44   virtual ~SketcherPrs_SymbolPrs();
45
46   //! Method which clear all selected owners belonging
47   //! to this selectable object ( for fast presentation draw )
48   Standard_EXPORT virtual void ClearSelected();
49
50
51   //! Method which draws selected owners ( for fast presentation draw )
52   Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
53                                                const SelectMgr_SequenceOfOwner& theOwners);
54   
55   //! Method which hilight an owner belonging to
56   //! this selectable object  ( for fast presentation draw )
57   Standard_EXPORT virtual void HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, 
58                                                      const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner);
59
60   Standard_EXPORT std::shared_ptr<GeomAPI_Ax3> plane() const { return myPlane; }
61
62   Standard_EXPORT SketchPlugin_Constraint* feature() const { return myConstraint; }
63
64
65   Handle(Graphic3d_ArrayOfPoints) pointsArray() const { return myPntArray; }
66
67   void Render(const Handle(OpenGl_Workspace)& theWorkspace) const;
68
69   void Release (OpenGl_Context* theContext);
70
71   DEFINE_STANDARD_RTTI(SketcherPrs_SymbolPrs)
72
73 protected:
74   /// Redefinition of virtual function
75   Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
76     const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
77
78   /// Redefinition of virtual function
79   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
80     const Standard_Integer aMode);
81
82   /// Returns an icon file name. Has to be redefined in successors
83   virtual const char* iconName() const = 0;
84
85   /// Check and creates if it is necessary myAspect member.
86   /// It has to be called before the object computation
87   virtual void prepareAspect();
88
89   /// Returns icon corresponded to the current constraint type
90   Handle(Image_AlienPixMap) icon();
91
92   /// Add a line into the given group
93   /// \param theGroup a group for drawing
94   /// \param theAttrName an attribute name which corresponds to referenced line
95   void addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const;
96
97   /// Redefine this function in order to add additiona lines of constraint base
98   /// \param thePrs a presentation
99   /// \param theColor a color of additiona lines
100   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const {}
101
102   /// Update myPntArray according to presentation positions
103   /// \return true in case of success
104   virtual bool updatePoints(double theStep) const { return true; }
105
106 protected:
107   /// Constraint feature
108   SketchPlugin_Constraint* myConstraint;
109
110   /// Plane of the current sketcher
111   std::shared_ptr<GeomAPI_Ax3> myPlane;
112
113   /// Aspect for entities drawing
114   Handle(Graphic3d_AspectMarker3d) myAspect;
115
116   /// Array of symbols positions
117   mutable Handle(Graphic3d_ArrayOfPoints) myPntArray;
118
119   Handle(SelectMgr_EntityOwner) myOwner;
120
121 private: 
122   /// Static map to collect constraints icons {IconName : IconPixMap}
123   static std::map<const char*, Handle(Image_AlienPixMap)> myIconsMap;
124
125   mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
126
127   Select3D_SensitiveEntitySequence mySPoints;
128 };
129
130 #endif