Salome HOME
Issue #591 - Highlight of the first argument of constraints
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_Operation.h
5  *
6  *  Created on: Apr 2, 2014
7  *      Author: sbh
8  */
9
10 #ifndef ModuleBase_Operation_H
11 #define ModuleBase_Operation_H
12
13 #include <ModuleBase.h>
14 #include <ModuleBase_ViewerPrs.h>
15
16 #include <ModelAPI_CompositeFeature.h>
17 #include <ModelAPI_Document.h>
18
19 #include <QObject>
20 #include <QString>
21 #include <QStringList>
22
23 class ModuleBase_ModelWidget;
24 class ModuleBase_OperationDescription;
25 class ModuleBase_IPropertyPanel;
26 class ModuleBase_ISelection;
27 class ModuleBase_IViewer;
28
29 class QKeyEvent;
30
31 /*!
32  * \class ModuleBase_Operation
33  * \ingroup GUI
34  * \brief Base class for all operations
35  *
36  *  Base class for all operations. If you perform an action it is reasonable to create
37  *  operation intended for this. This is a base class for all operations which provides
38  *  mechanism for correct starting operations, starting operations above already started
39  *  ones, committing operations and so on. To create own operation it is reasonable to
40  *  inherit it from this class and redefines virtual methods to provide own behavior
41  *  Main virtual methods are
42  *  - virtual bool      isReadyToStart();
43  *  - virtual void      startOperation();
44  *  - virtual void      abortOperation();
45  *  - virtual void      commitOperation();
46  */
47
48 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
49 {
50 Q_OBJECT
51
52  public:
53
54   /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
55   static QString EditSuffix() { return "_E"; }
56   /// Constructor
57   /// \param theId the operation identifier
58   /// \param theParent the QObject parent
59   ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
60   /// Destructor
61   virtual ~ModuleBase_Operation();
62
63   /// Returns the operation description
64   /// /returns the instance of the description class
65   ModuleBase_OperationDescription* getDescription() const { return myDescription; }
66
67   /**
68   * Must return true if this operation can be launched as nested for any current operation
69   * and it is not necessary to check this operation on validity. By default 
70   * the operation is not granted.
71   * The method has to be redefined for granted operations.
72   */
73   virtual bool isGranted(QString theId) const;
74
75
76   /// Returns True if data of its feature was modified during operation
77   virtual bool isModified() const { return myIsModified; }
78
79   /// Change the modified state of the operation
80   void setIsModified(const bool theIsModified) { myIsModified = theIsModified;  }
81
82   /// Returns True id the current operation is launched in editing mode
83   bool isEditOperation() const { return myIsEditing; }
84
85   /// Returns list of nested features
86   QStringList nestedFeatures() const { return myNestedFeatures; }
87
88   /// Sets list of nested features
89   void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
90
91
92   /// Returns operations Id from it's description
93   QString id() const;
94
95   /// Returns the operation feature
96   /// \return the feature
97   FeaturePtr feature() const;
98
99   /**
100   * Must return True if the operation's feature is valid.
101   * Since IOperation does not have any feature returns false.
102   */
103   virtual bool isValid() const;
104
105   /// Sets the operation feature
106   void setFeature(FeaturePtr theFeature);
107
108   /// Returns True if the current operation works with the given object (feature or result)
109   virtual bool hasObject(ObjectPtr theObj) const;
110
111   /// Initialisation of operation with preliminary selection
112   /// \param theSelection an instance of Selection class
113   /// \param theViewer a viewer to have the viewer the eye position
114   virtual void initSelection(ModuleBase_ISelection* theSelection,
115                              ModuleBase_IViewer* theViewer);
116
117   /// \brief Set property pane to the operation
118   /// \param theProp a property panel instance
119   virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
120
121   /// \return Currently installed property panel
122   ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
123
124   /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
125   virtual void activateByPreselection();
126
127   /// If the operation works with feature which is sub-feature of another one
128   /// then this variable has to be initialised by parent feature 
129   /// before operation feature creating
130   void setParentFeature(CompositeFeaturePtr theParent);
131
132   /// \return Installed parent feature (can be NULL)
133   CompositeFeaturePtr parentFeature() const;
134
135 signals:
136   /// The operation is started
137   void started();  
138
139   /// The operation is aborted
140   void aborted();  
141
142   /// The operation is committed
143   void committed();  
144
145   /// The operation is aborted or committed
146   void stopped();  
147
148   /// The operation is resumed
149   void resumed();  
150
151   /// The operation is postponed
152   void postponed();  
153
154   /// The operation is triggered
155   /// \param theState a new triggered state
156   void triggered(bool theState);
157
158   /// The operation is filled with existing preselection
159   void activatedByPreselection(); 
160
161  public slots:
162   /// Starts operation
163   /// Public slot. Verifies whether operation can be started and starts operation.
164   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
165   /// to change behavior of operation. There is no point in using this method. It would
166   /// be better to inherit own operator from base one and redefine startOperation method
167   /// instead.
168   void start();
169
170   /// Deactivates current operation which can be resumed later.
171   void postpone();
172
173   /// Resumes operation
174   /// Public slot. Verifies whether operation can be started and starts operation.
175   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
176   /// to change behavior of operation. There is no point in using this method. It would
177   /// be better to inherit own operator from base one and redefine startOperation method
178   /// instead.
179   void resume();
180
181   /// Aborts operation
182   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
183   /// Redefine abortOperation method to change behavior of operation instead
184   void abort();
185
186   /// Commits operation
187   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
188   /// Redefine commitOperation method to change behavior of operation instead
189   bool commit();
190
191   /// Alias for start/abort slots
192   /// Public slot. Aborts operation if false, else does nothing.
193   /// Provided for S/S compatibility with QAction's toggle(bool)
194   /// \param theState th flag to abort, if it is true, do nothing, overwise abort
195   void setRunning(bool theState);
196
197   /// Changes the modified flag of the operation
198   void onValuesChanged();
199
200  protected:
201   /// Virtual method called when operation started (see start() method for more description)
202   /// Default impl calls corresponding slot and commits immediately.
203    virtual void startOperation() {}
204
205   /// Implementation of specific steps on postpone operation
206   virtual void postponeOperation() {}
207
208   /// Virtual method called when operation stopped - committed or aborted.
209   virtual void stopOperation() {}
210
211   /// Virtual method called when operation aborted (see abort() method for more description)
212   virtual void abortOperation() {}
213
214   /// Virtual method called when operation committed (see commit() method for more description)
215   virtual void commitOperation();
216
217   /// Virtual method called after operation committed (see commit() method for more description)
218   virtual void afterCommitOperation() {}
219
220   /// Virtual method called after operation resume (see resume() method for more description)
221   virtual void resumeOperation() {}
222
223   /// Creates an operation new feature
224   /// \param theFlushMessage the flag whether the create message should be flushed
225   /// \returns the created feature
226   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
227
228   /// Verifies whether this operator can be commited.
229   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
230   virtual bool canBeCommitted() const;
231
232   /// Return a widget value point by the selection and the viewer position
233   /// The default realization returns false
234   /// \param thePrs the presentation
235   /// \param theViewer a viewer to have the viewer the eye position
236   /// \param theX the horizontal coordinate
237   /// \param theY the vertical coordinate
238   /// \return true if the point exits in the selection
239   virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
240                                    ModuleBase_IViewer* theViewer,
241                                    double& theX, double& theY);
242
243   /// Removes the preselection information and clears the map of preselection
244   void clearPreselection();
245
246  protected:
247    /// The operation feature to be handled
248   FeaturePtr myFeature;  
249
250   /// the container to have the operation description
251   ModuleBase_OperationDescription* myDescription;  
252
253   /// Editing feature flag
254   bool myIsEditing;
255
256   /// Modified feature flag
257   bool myIsModified;
258
259   /// List of nested operations IDs
260   QStringList myNestedFeatures;
261
262   /// List of pre-selected object 
263   QList<ModuleBase_ViewerPrs> myPreSelection;
264
265   /// Access to property panel
266   ModuleBase_IPropertyPanel* myPropertyPanel;
267
268   /// If the operation works with feature which is sub-feature of another one
269   /// then this variable has to be initialised by parent feature 
270   /// before operation feature creating
271   CompositeFeaturePtr myParentFeature;  
272
273   /// Last current feature before editing operation
274   FeaturePtr myCurrentFeature;
275 };
276
277 #endif