Salome HOME
Providing Action class to have a common approach to start/finish/abort model transact...
[modules/shaper.git] / src / ModuleBase / ModuleBase_OperationFeature.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_OperationFeature.h
5  *
6  *  Created on: Apr 2, 2014
7  *      Author: sbh
8  */
9
10 #ifndef ModuleBase_OperationFeature_H
11 #define ModuleBase_OperationFeature_H
12
13 #include <ModuleBase.h>
14 #include <ModuleBase_Operation.h>
15 #include <ModuleBase_ViewerPrs.h>
16
17 #include <ModelAPI_CompositeFeature.h>
18
19 #include <QObject>
20 #include <QString>
21 #include <QStringList>
22
23 class ModuleBase_ModelWidget;
24 class ModuleBase_ISelection;
25 class ModuleBase_IViewer;
26
27 class QKeyEvent;
28
29 /*!
30  * \class ModuleBase_OperationFeature
31  * \ingroup GUI
32  * \brief Base class for all operations
33  *
34  *  Base class for all operations. If you perform an action it is reasonable to create
35  *  operation intended for this. This is a base class for all operations which provides
36  *  mechanism for correct starting operations, starting operations above already started
37  *  ones, committing operations and so on. To create own operation it is reasonable to
38  *  inherit it from this class and redefines virtual methods to provide own behavior
39  *  Main virtual methods are
40  *  - virtual bool      isReadyToStart();
41  *  - virtual void      startOperation();
42  *  - virtual void      abortOperation();
43  *  - virtual void      commitOperation();
44  */
45
46 class MODULEBASE_EXPORT ModuleBase_OperationFeature : public ModuleBase_Operation
47 {
48 Q_OBJECT
49
50  public:
51
52   /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
53   static QString EditSuffix() { return "_E"; }
54   /// Constructor
55   /// \param theId the operation identifier
56   /// \param theParent the QObject parent
57   ModuleBase_OperationFeature(const QString& theId = "", QObject* theParent = 0);
58   /// Destructor
59   virtual ~ModuleBase_OperationFeature();
60
61   /**
62   * Must return true if this operation can be launched as nested for any current operation
63   * and it is not necessary to check this operation on validity. By default 
64   * the operation is not granted.
65   * The method has to be redefined for granted operations.
66   */
67   virtual bool isGranted(QString theId) const;
68
69   /// Returns True id the current operation is launched in editing mode
70   bool isEditOperation() const { return myIsEditing; }
71
72   /// Returns list of nested features
73   QStringList nestedFeatures() const { return myNestedFeatures; }
74
75   /// Sets list of nested features
76   void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
77
78   /// Returns the operation feature
79   /// \return the feature
80   FeaturePtr feature() const;
81
82   /**
83   * Must return True if the operation's feature is valid.
84   * Since IOperation does not have any feature returns false.
85   */
86   virtual bool isValid() const;
87
88   /// Sets the operation feature
89   void setFeature(FeaturePtr theFeature);
90
91   /// Returns True if the current operation works with the given object (feature or result)
92   virtual bool hasObject(ObjectPtr theObj) const;
93
94   /// Initialisation of operation with preliminary selection
95   /// \param theSelection an instance of Selection class
96   /// \param theViewer a viewer to have the viewer the eye position
97   virtual void initSelection(ModuleBase_ISelection* theSelection,
98                              ModuleBase_IViewer* theViewer);
99
100   /// \brief Set property pane to the operation
101   /// \param theProp a property panel instance
102   virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
103
104   /// \return Currently installed property panel
105   //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
106
107   /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
108   virtual void activateByPreselection();
109
110   /// If the operation works with feature which is sub-feature of another one
111   /// then this variable has to be initialised by parent feature 
112   /// before operation feature creating
113   void setParentFeature(CompositeFeaturePtr theParent);
114
115   /// \return Installed parent feature (can be NULL)
116   CompositeFeaturePtr parentFeature() const;
117
118 signals:
119   /// The operation is filled with existing preselection
120   void activatedByPreselection(); 
121
122  public slots:
123   /// Starts operation
124   /// Public slot. Verifies whether operation can be started and starts operation.
125   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
126   /// to change behavior of operation. There is no point in using this method. It would
127   /// be better to inherit own operator from base one and redefine startOperation method
128   /// instead.
129   void start();
130
131   /// Aborts operation
132   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
133   /// Redefine abortOperation method to change behavior of operation instead
134   void abort();
135
136   /// Commits operation
137   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
138   /// Redefine commitOperation method to change behavior of operation instead
139   bool commit();
140
141  protected:
142   /// Creates an operation new feature
143   /// \param theFlushMessage the flag whether the create message should be flushed
144   /// \returns the created feature
145   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
146
147   /// Removes the preselection information and clears the map of preselection
148   void clearPreselection();
149
150  protected:
151    /// The operation feature to be handled
152   FeaturePtr myFeature;
153
154   /// Editing feature flag
155   bool myIsEditing;
156
157   /// List of nested operations IDs
158   QStringList myNestedFeatures;
159
160   /// List of pre-selected object 
161   QList<ModuleBase_ViewerPrs> myPreSelection;
162
163   /// If the operation works with feature which is sub-feature of another one
164   /// then this variable has to be initialised by parent feature 
165   /// before operation feature creating
166   CompositeFeaturePtr myParentFeature;  
167
168   /// Last current feature before editing operation
169   FeaturePtr myCurrentFeature;
170 };
171
172 #endif