Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_OperationFeatureCreate.h
1 // File:        PartSet_OperationFeatureCreate.h
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef PartSet_OperationFeatureCreate_H
6 #define PartSet_OperationFeatureCreate_H
7
8 #include "PartSet.h"
9
10 #include <PartSet_OperationSketchBase.h>
11 #include <PartSet_Constants.h>
12
13 #include <QObject>
14
15 class GeomDataAPI_Point2D;
16 class QMouseEvent;
17 class QKeyEvent;
18
19 /*!
20  \class PartSet_OperationFeatureCreate
21  * \brief The operation for the sketch feature creation
22 */
23 class PARTSET_EXPORT PartSet_OperationFeatureCreate : public PartSet_OperationSketchBase
24 {
25   Q_OBJECT
26
27 public:
28   /// Returns true if the feature with the given kind can be created by this operation
29   /// \param theId the feature kind
30   /// \return the boolean result
31   static bool canProcessKind(const std::string& theId);
32
33 public:
34   /// Constructor
35   /// \param theId the feature identifier
36   /// \param theParent the operation parent
37   /// \param theSketch the parent feature
38   PartSet_OperationFeatureCreate(const QString& theId, QObject* theParent,
39                                  FeaturePtr theSketch);
40   /// Destructor
41   virtual ~PartSet_OperationFeatureCreate();
42
43   /// Verifies whether this operator can be commited.
44   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
45   virtual bool canBeCommitted() const;
46
47   /// Returns that this operator can be started above already running one.
48    /// The runned operation should be the sketch feature modified operation
49   /// \param theOperation the previous running operation
50   virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
51
52   /// Returns the operation local selection mode
53   /// \param theFeature the feature object to get the selection mode
54   /// \return the selection mode
55   virtual std::list<int> getSelectionModes(FeaturePtr theFeature) const;
56
57   /// Initializes some fields accorging to the feature
58   /// \param theSelected the list of selected presentations
59   /// \param theHighlighted the list of highlighted presentations
60   virtual void init(FeaturePtr theFeature,
61                     const std::list<XGUI_ViewerPrs>& theSelected,
62                     const std::list<XGUI_ViewerPrs>& theHighlighted);
63
64   /// Returns the operation sketch feature
65   /// \returns the sketch instance
66   virtual FeaturePtr sketch() const;
67
68   /// Gives the current selected objects to be processed by the operation
69   /// \param theEvent the mouse event
70   /// \param theView a viewer to have the viewer the eye position
71   /// \param theSelected the list of selected presentations
72   /// \param theHighlighted the list of highlighted presentations
73  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
74                             const std::list<XGUI_ViewerPrs>& theSelected,
75                             const std::list<XGUI_ViewerPrs>& theHighlighted);
76   /// Gives the current mouse point in the viewer
77   /// \param thePoint a point clicked in the viewer
78   /// \param theEvent the mouse event
79   virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
80   /// Processes the key pressed in the view
81   /// \param theKey a key value
82   virtual void keyReleased(const int theKey);
83
84   virtual void keyReleased(std::string theName, QKeyEvent* theEvent);
85
86 public slots:
87   /// Slots which listen the mode widget activation
88   /// \param theWidget the model widget
89   virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
90
91 protected:
92   /// \brief Virtual method called when operation is started
93   /// Virtual method called when operation started (see start() method for more description)
94   /// After the parent operation body perform, set sketch feature to the created line feature
95   virtual void startOperation();
96
97   /// Virtual method called when operation aborted (see abort() method for more description)
98   /// Before the feature is aborted, it should be hidden from the viewer
99   virtual void abortOperation();
100
101   /// Virtual method called when operation stopped - committed or aborted.
102   /// Restore the multi selection state
103   virtual void stopOperation();
104
105   /// Virtual method called after operation committed (see commit() method for more description)
106   virtual void afterCommitOperation();
107
108   /// Creates an operation new feature
109   /// In addition to the default realization it appends the created line feature to
110   /// the sketch feature
111   /// \param theFlushMessage the flag whether the create message should be flushed
112   /// \returns the created feature
113   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
114
115 protected:
116   /// Returns true if the active widget is the point selector widget
117   /// \return the boolean value
118   bool isPointWidget() const;
119
120   /// Set the point to the active widget
121   /// \param theX the horizontal coordinate
122   /// \param theY the vertical coordinate
123   /// \return true if the point is set
124   bool setWidgetPoint(double theX, double theY);
125
126   /// Set the feature to the active widget
127   /// \param theFeature a feature
128   /// \return true if the feature is set
129   bool setWidgetFeature(const FeaturePtr& theFeature);
130
131 private:
132   FeaturePtr myInitFeature; ///< the initial feature
133   FeaturePtr mySketch; ///< the sketch of the feature
134
135   ModuleBase_ModelWidget* myActiveWidget; ///< the active widget
136 };
137
138 #endif