]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_IOperation.h
Salome HOME
0d304c0a2a7bebc1d684914ef6bba0b4bf48dc2b
[modules/shaper.git] / src / ModuleBase / ModuleBase_IOperation.h
1 /*
2  * ModuleBase_IOperation.h
3  *
4  *  Created on: May 5, 2014
5  *      Author: nds
6  */
7
8
9 #ifndef ModuleBase_IOperation_H
10 #define ModuleBase_IOperation_H
11
12 #include <ModuleBase.h>
13
14 #include <QObject>
15 #include <QString>
16 #include <QList>
17
18 #include <boost/shared_ptr.hpp>
19
20 class ModelAPI_Document;
21 class ModuleBase_OperationDescription;
22 //class ModuleBase_ModelWidget;
23
24 /*!
25  \class ModuleBase_IOperation
26  * \brief Base class for all operations
27  *
28  *  Base class for all operations. If you perform an action it is reasonable to create
29  *  operation intended for this. This is a base class for all operations which provides
30  *  mechanism for correct starting operations, starting operations above already started
31  *  ones, committing operations and so on. To create own operation it is reasonable to
32  *  inherit it from this class and redefines virtual methods to provide own behavior
33  *  Main virtual methods are
34  *  - virtual bool      isReadyToStart();
35  *  - virtual void      startOperation();
36  *  - virtual void      abortOperation();
37  *  - virtual void      commitOperation();
38  */
39
40 class MODULEBASE_EXPORT ModuleBase_IOperation: public QObject
41 {
42 Q_OBJECT
43
44 public:
45   /// Constructor
46   /// Constructs an empty operation. Constructor should work very fast because many
47   /// operators may be created after starting workshop but only several from them
48   /// may be used. As result this constructor stores given workshop in myApp field
49   /// and set Waiting status.
50   /// \param theId the operation identifier
51   /// \param theParent the QObject parent
52   ModuleBase_IOperation(const QString& theId = "", QObject* theParent = 0);
53   /// Destructor
54   virtual ~ModuleBase_IOperation();
55
56   /// Returns the operation description
57   /// /returns the instance of the description class
58   ModuleBase_OperationDescription* getDescription() const;
59
60   /// Verifies whether this operator can be commited.
61   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
62   virtual bool canBeCommitted() const;
63
64   /// Verifies whether this operator can be always started above any already running one
65   /// \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
66   /// This method must be redefined in derived operation if operation of derived class
67   /// must be always can start above any launched one. Default impl returns FALSE,
68   /// so it is being checked for IsValid, but some operations may overload IsGranted()
69   /// In this case they will always start, no matter what operation is running.
70   /// \param theOperation the previous running operation
71   virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
72
73   /// Sets a list of model widgets, according to the operation feature xml definition
74   /// \param theXmlRepresentation an xml feature definition
75   /// \param theWidgets a list of widgets
76   //void setModelWidgets(const std::string& theXmlRepresentation,
77   //                     QList<ModuleBase_ModelWidget*> theWidgets);
78
79   /// Returns True if data of its feature was modified during operation
80   virtual bool isModified() const { return myIsModified; }
81
82   /// Returns True id the current operation is launched in editing mode
83   bool isEditOperation() const { return myIsEditing; }
84
85 signals:
86   void started(); /// the operation is started
87   void aborted(); /// the operation is aborted
88   void committed(); /// the operation is committed
89   void stopped(); /// the operation is aborted or committed
90   void resumed(); /// the operation is resumed
91
92 public slots:
93   /// Starts operation
94   /// Public slot. Verifies whether operation can be started and starts operation.
95   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
96   /// to change behavior of operation. There is no point in using this method. It would
97   /// be better to inherit own operator from base one and redefine startOperation method
98   /// instead.
99   void start();
100   /// Resumes operation
101   /// Public slot. Verifies whether operation can be started and starts operation.
102   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
103   /// to change behavior of operation. There is no point in using this method. It would
104   /// be better to inherit own operator from base one and redefine startOperation method
105   /// instead.
106   void resume();
107   /// Aborts operation
108   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
109   /// Redefine abortOperation method to change behavior of operation instead
110   void abort();
111   /// Commits operation
112   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
113   /// Redefine commitOperation method to change behavior of operation instead
114   void commit();
115
116   /// Alias for start/abort slots
117   /// Public slot. Aborts operation if false, else does nothing.
118   /// Provided for S/S compatibility with QAction's toggle(bool)
119   /// \param theState th flag to abort, if it is true, do nothing, overwise abort
120   void setRunning(bool theState);
121
122   // Data model methods.
123   /// Stores a custom value in model.
124   virtual void storeCustomValue() = 0;
125
126 protected:
127   /// Virtual method called when operation started (see start() method for more description)
128   /// Default impl calls corresponding slot and commits immediately.
129   virtual void startOperation() = 0;
130   /// Virtual method called when operation stopped - committed or aborted.
131   virtual void stopOperation() = 0;
132   /// Virtual method called when operation aborted (see abort() method for more description)
133   virtual void abortOperation() = 0;
134   /// Virtual method called when operation committed (see commit() method for more description)
135   virtual void commitOperation() = 0;
136   /// Virtual method called after operation committed (see commit() method for more description)
137   /// it is important that the method is called after the stop() signal is emitted
138   virtual void afterCommitOperation() = 0;
139
140   /// Returns pointer to the root document.
141   boost::shared_ptr<ModelAPI_Document> document() const;
142
143   /// Editing feature flag
144   bool myIsEditing;
145
146   /// Modified feature flag
147   bool myIsModified;
148
149 private:
150   ModuleBase_OperationDescription* myDescription; /// the container to have the operation description
151 };
152
153 #endif