]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_OperationEditConstraint.h
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_OperationEditConstraint.h
1 // File:        PartSet_OperationEditConstraint.h
2 // Created:     05 May 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef PartSet_OperationEditConstraint_H
6 #define PartSet_OperationEditConstraint_H
7
8 #include "PartSet.h"
9
10 #include <PartSet_OperationSketchBase.h>
11 #include <QObject>
12
13 class PartSet_EditLine;
14 class PartSet_FeaturePrs;
15 class QMouseEvent;
16
17 /*!
18  \class PartSet_OperationEditConstraint
19  * \brief The operation for the sketch feature creation
20 */
21 class PARTSET_EXPORT PartSet_OperationEditConstraint : public PartSet_OperationSketchBase                                                 
22 {
23   Q_OBJECT
24   /// Struct to define gp point, with the state is the point is initialized
25   struct Point
26   {
27     /// Constructor
28     Point() {}
29     /// Constructor
30     /// \param thePoint the point
31     Point(gp_Pnt thePoint)
32     {
33       setPoint(thePoint);
34     }
35     ~Point() {}
36
37     /// clear the initialized flag.
38     void clear() { myIsInitialized = false; }
39     /// set the point and switch on the initialized flag
40     /// \param thePoint the point
41     void setPoint(const gp_Pnt& thePoint)
42     {
43       myIsInitialized = true;
44       myPoint = thePoint;
45     }
46
47     bool myIsInitialized; /// the state whether the point is set
48     gp_Pnt myPoint; /// the point
49   };
50
51 public:
52   /// Returns the operation type key
53   static std::string Type() { return "EditConstraint"; }
54
55 public:
56   /// Constructor
57   /// \param theId the feature identifier
58   /// \param theFeatureId the feature identifier
59   /// \param theParent the operation parent
60   /// \param theFeature the parent feature
61   PartSet_OperationEditConstraint(const QString& theId, const std::string& theFeatureKind,
62                             QObject* theParent, FeaturePtr theFeature);
63   /// Destructor
64   virtual ~PartSet_OperationEditConstraint();
65
66   /// Returns that this operator can be started above already running one.
67   /// The runned operation should be the sketch feature modified operation
68   /// \param theOperation the previous running operation
69   virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
70
71   /// Returns the operation local selection mode
72   /// \param theFeature the feature object to get the selection mode
73   /// \return the selection mode
74   virtual std::list<int> getSelectionModes(FeaturePtr theFeature) const;
75
76   /// Initializes some fields accorging to the feature
77   /// \param theFeature the feature
78   /// \param theSelected the list of selected presentations
79   /// \param theHighlighted the list of highlighted presentations
80   virtual void init(FeaturePtr theFeature,
81                     const std::list<XGUI_ViewerPrs>& theSelected,
82                     const std::list<XGUI_ViewerPrs>& theHighlighted);
83
84   /// Returns the operation sketch feature
85   /// \returns the sketch instance
86   virtual FeaturePtr sketch() const;
87
88   /// Processes the mouse pressed in the point
89   /// \param theEvent the mouse event
90   /// \param theView a viewer to have the viewer the eye position
91   /// \param theSelected the list of selected presentations
92   /// \param theHighlighted the list of highlighted presentations
93   virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
94                             const std::list<XGUI_ViewerPrs>& theSelected,
95                             const std::list<XGUI_ViewerPrs>& theHighlighted);
96   /// Gives the current mouse point in the viewer
97   /// \param theEvent the mouse event
98   /// \param theView a viewer to have the viewer the eye position
99   virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
100   /// Gives the current selected objects to be processed by the operation
101   /// \param thePoint a point clicked in the viewer
102   /// \param theEvent the mouse event
103   /// \param theSelected the list of selected presentations
104   /// \param theHighlighted the list of highlighted presentations
105  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
106                             const std::list<XGUI_ViewerPrs>& theSelected,
107                             const std::list<XGUI_ViewerPrs>& theHighlighted);
108   /// Processes the mouse double click in the point
109   /// \param theEvent the mouse event
110   /// \param theView a viewer to have the viewer the eye position
111   /// \param theSelected the list of selected presentations
112   /// \param theHighlighted the list of highlighted presentations
113   virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
114                                 const std::list<XGUI_ViewerPrs>& theSelected,
115                                 const std::list<XGUI_ViewerPrs>& theHighlighted);
116
117 protected:
118   /// \brief Virtual method called when operation is started
119   /// Virtual method called when operation started (see start() method for more description)
120   /// Switch off the multi selection state
121   virtual void startOperation();
122
123   /// Virtual method called when operation stopped - committed or aborted.
124   /// Restore the multi selection state
125   virtual void stopOperation();
126
127   /// Creates an operation new feature
128   /// Returns NULL feature. This is an operation of edition, not creation.
129   /// \param theFlushMessage the flag whether the create message should be flushed
130   /// \returns the created feature
131   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
132
133 protected:
134   /// Emits a signal about the selection blocking. Emits a signal to change the selection.
135   /// If the block is true, the signal clear selection, otherwise if restore selection flag allows,
136   /// the internal operation features are to be selected
137   /// \param isBlocked the state whether the operation is blocked or unblocked
138   /// \param isRestoreSelection the state whether the selected objects should be reselected
139   void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
140
141   /// Sends the features
142   void sendFeatures();
143
144 protected slots:
145   /// SLOT, that listens the value edited signal and set the new value to the feature
146   /// \param theValue the editor value
147   void onEditStopped(double theValue);
148
149 private:
150   PartSet_EditLine* myEditor; ///< the constraint value editor
151   boost::shared_ptr<PartSet_FeaturePrs> myFeaturePrs; ///< the feature presentation
152   //std::list<XGUI_ViewerPrs> myFeatures; ///< the features to apply the edit operation
153   Point myCurPoint; ///< the current 3D point clicked or moved
154   bool myIsBlockedSelection; ///< the state of the last state of selection blocked signal
155 };
156
157 #endif