Salome HOME
Issue #1302 Restricting preselection to the first argument only: mirror feature has...
[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_Object.h>
18 #include <ModelAPI_CompositeFeature.h>
19
20 #include <QObject>
21 #include <QString>
22 #include <QStringList>
23
24 #include <set>
25
26 class ModuleBase_ModelWidget;
27 class ModuleBase_ISelection;
28 class ModuleBase_IViewer;
29 class ModuleBase_IWorkshop;
30
31 class QKeyEvent;
32
33 /*!
34  * \class ModuleBase_OperationFeature
35  * \ingroup GUI
36  * \brief Base class for all operations
37  *
38  *  Base class for all operations. If you perform an action it is reasonable to create
39  *  operation intended for this. This is a base class for all operations which provides
40  *  mechanism for correct starting operations, starting operations above already started
41  *  ones, committing operations and so on. To create own operation it is reasonable to
42  *  inherit it from this class and redefines virtual methods to provide own behavior
43  *  Main virtual methods are
44  *  - virtual bool      isReadyToStart();
45  *  - virtual void      startOperation();
46  *  - virtual void      abortOperation();
47  *  - virtual void      commitOperation();
48  */
49
50 class MODULEBASE_EXPORT ModuleBase_OperationFeature : public ModuleBase_Operation
51 {
52 Q_OBJECT
53
54  public:
55
56   /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
57   static QString EditSuffix() { return "_E"; }
58   /// Constructor
59   /// \param theId the operation identifier
60   /// \param theParent the QObject parent
61   ModuleBase_OperationFeature(const QString& theId = "", QObject* theParent = 0);
62   /// Destructor
63   virtual ~ModuleBase_OperationFeature();
64
65   /// Returns True id the current operation is launched in editing mode
66   bool isEditOperation() const { return myIsEditing; }
67
68   /// Change the operation mode from create to edit.
69   /// The transaction and the operation name in the model history of transaction are the same.
70   /// It updates the edit state in the widgets of property panel
71   /// \param isEditState boolean state whether the operation should become editing or creating
72   // \param theRestartTransaction if true, the current model transaction is committed and
73   /// the new one is started
74   void setEditOperation(const bool& isEditState/*const bool theRestartTransaction*/);
75
76   /// Returns the operation feature
77   /// \return the feature
78   FeaturePtr feature() const;
79
80   /// Must return True if the operation's feature is valid.
81   /// Since IOperation does not have any feature returns false.
82   virtual bool isValid() const;
83
84   /// Sets the operation feature
85   void setFeature(FeaturePtr theFeature);
86
87   /// Returns True if the current operation works with the given object (feature or result)
88   virtual bool hasObject(ObjectPtr theObj) const;
89
90   /// Returns true if the object is displayed when the operation was started
91   /// \param theObject a feature or result of the operation feature
92   /// \return boolean value whether the object display state was changed
93   virtual bool isDisplayedOnStart(ObjectPtr theObject);
94
95   /// Initialisation of operation with preliminary selection
96   /// \param theSelection an instance of Selection class
97   /// \param theViewer a viewer to have the viewer the eye position
98   virtual void initSelection(ModuleBase_ISelection* theSelection,
99                              ModuleBase_IViewer* theViewer);
100
101   /// \brief Set property pane to the operation
102   /// \param theProp a property panel instance
103   virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
104
105   /// \return Currently installed property panel
106   //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
107
108   /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
109   virtual void activateByPreselection(ModuleBase_IWorkshop* theWorkshop);
110
111   /// If the operation works with feature which is sub-feature of another one
112   /// then this variable has to be initialised by parent feature 
113   /// before operation feature creating
114   void setParentFeature(CompositeFeaturePtr theParent);
115
116   /// \return Installed parent feature (can be NULL)
117   CompositeFeaturePtr parentFeature() const;
118
119   /// Stores the previous to the operation current feature
120   /// \param theFeature a feature
121   void setPreviousCurrentFeature(const FeaturePtr& theFeature);
122
123   /// Returns the previous to the operation current feature
124   /// \return theFeature a feature
125   FeaturePtr previousCurrentFeature();
126
127 signals:
128   /// The operation is filled with existing preselection
129   void activatedByPreselection(); 
130
131  public slots:
132   /// Starts operation
133   /// Public slot. Verifies whether operation can be started and starts operation.
134   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
135   /// to change behavior of operation. There is no point in using this method. It would
136   /// be better to inherit own operator from base one and redefine startOperation method
137   /// instead.
138   /// \return true if the start is successful
139   virtual bool start();
140
141   /// Aborts operation
142   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
143   /// Redefine abortOperation method to change behavior of operation instead
144   void abort();
145
146   /// Commits operation
147   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
148   /// Redefine commitOperation method to change behavior of operation instead
149   bool commit();
150
151  protected:
152   /// Displays the feature/results if it is hidden. It will be hided in stopOperation
153   virtual void startOperation();
154
155   /// Hide feature/results if they were hided on start
156   virtual void stopOperation();
157
158   /// Creates an operation new feature
159   /// \param theFlushMessage the flag whether the create message should be flushed
160   /// \returns the created feature
161   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
162
163   /// Removes the preselection information and clears the map of preselection
164   void clearPreselection();
165
166  protected:
167    /// The operation feature to be handled
168   FeaturePtr myFeature;
169
170   /// a list of hidden objects, whic are diplayed by operation start
171   /// and should be hidden by operation stop
172   std::set<ObjectPtr> myVisualizedObjects;
173
174   /// Editing feature flag
175   bool myIsEditing;
176
177   /// List of pre-selected object 
178   QList<ModuleBase_ViewerPrs> myPreSelection;
179
180   /// If the operation works with feature which is sub-feature of another one
181   /// then this variable has to be initialised by parent feature 
182   /// before operation feature creating
183   CompositeFeaturePtr myParentFeature;
184
185   /// Last current feature before editing operation. It is cashed when Edit operation is started
186   /// in order to restore the document current feature on commit/abort this operation.
187   FeaturePtr myPreviousCurrentFeature;
188 };
189
190 #endif