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