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