Salome HOME
1. CanStopOperation knows which operation is stopped. Scenario: Unpress Sketch in...
[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   /// Returns True id the current operation is launched in editing mode
62   bool isEditOperation() const { return myIsEditing; }
63
64   /// Returns the operation feature
65   /// \return the feature
66   FeaturePtr feature() const;
67
68   /// Must return True if the operation's feature is valid.
69   /// Since IOperation does not have any feature returns false.
70   virtual bool isValid() const;
71
72   /// Sets the operation feature
73   void setFeature(FeaturePtr theFeature);
74
75   /// Returns True if the current operation works with the given object (feature or result)
76   virtual bool hasObject(ObjectPtr theObj) const;
77
78   /// Initialisation of operation with preliminary selection
79   /// \param theSelection an instance of Selection class
80   /// \param theViewer a viewer to have the viewer the eye position
81   virtual void initSelection(ModuleBase_ISelection* theSelection,
82                              ModuleBase_IViewer* theViewer);
83
84   /// \brief Set property pane to the operation
85   /// \param theProp a property panel instance
86   virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
87
88   /// \return Currently installed property panel
89   //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
90
91   /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
92   virtual void activateByPreselection();
93
94   /// If the operation works with feature which is sub-feature of another one
95   /// then this variable has to be initialised by parent feature 
96   /// before operation feature creating
97   void setParentFeature(CompositeFeaturePtr theParent);
98
99   /// \return Installed parent feature (can be NULL)
100   CompositeFeaturePtr parentFeature() const;
101
102 signals:
103   /// The operation is filled with existing preselection
104   void activatedByPreselection(); 
105
106  public slots:
107   /// Starts operation
108   /// Public slot. Verifies whether operation can be started and starts operation.
109   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
110   /// to change behavior of operation. There is no point in using this method. It would
111   /// be better to inherit own operator from base one and redefine startOperation method
112   /// instead.
113   void start();
114
115   /// Aborts operation
116   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
117   /// Redefine abortOperation method to change behavior of operation instead
118   void abort();
119
120   /// Commits operation
121   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
122   /// Redefine commitOperation method to change behavior of operation instead
123   bool commit();
124
125  protected:
126   /// Creates an operation new feature
127   /// \param theFlushMessage the flag whether the create message should be flushed
128   /// \returns the created feature
129   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
130
131   /// Removes the preselection information and clears the map of preselection
132   void clearPreselection();
133
134  protected:
135    /// The operation feature to be handled
136   FeaturePtr myFeature;
137
138   /// Editing feature flag
139   bool myIsEditing;
140
141   /// List of pre-selected object 
142   QList<ModuleBase_ViewerPrs> myPreSelection;
143
144   /// If the operation works with feature which is sub-feature of another one
145   /// then this variable has to be initialised by parent feature 
146   /// before operation feature creating
147   CompositeFeaturePtr myParentFeature;  
148
149   /// Last current feature before editing operation. It is cashed when Edit operation is started
150   /// in order to restore the document current feature on commit/abort this operation.
151   FeaturePtr myPreviousCurrentFeature;
152 };
153
154 #endif