1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_OperationFeature.h
6 * Created on: Apr 2, 2014
10 #ifndef ModuleBase_OperationFeature_H
11 #define ModuleBase_OperationFeature_H
13 #include <ModuleBase.h>
14 #include <ModuleBase_Operation.h>
15 #include <ModuleBase_ViewerPrs.h>
17 #include <ModelAPI_CompositeFeature.h>
21 #include <QStringList>
23 class ModuleBase_ModelWidget;
24 class ModuleBase_ISelection;
25 class ModuleBase_IViewer;
30 * \class ModuleBase_OperationFeature
32 * \brief Base class for all operations
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();
46 class MODULEBASE_EXPORT ModuleBase_OperationFeature : public ModuleBase_Operation
52 /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
53 static QString EditSuffix() { return "_E"; }
55 /// \param theId the operation identifier
56 /// \param theParent the QObject parent
57 ModuleBase_OperationFeature(const QString& theId = "", QObject* theParent = 0);
59 virtual ~ModuleBase_OperationFeature();
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.
67 virtual bool isGranted(QString theId) const;
69 /// Returns True id the current operation is launched in editing mode
70 bool isEditOperation() const { return myIsEditing; }
72 /// Returns list of nested features
73 QStringList nestedFeatures() const { return myNestedFeatures; }
75 /// Sets list of nested features
76 void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
78 /// Returns the operation feature
79 /// \return the feature
80 FeaturePtr feature() const;
83 * Must return True if the operation's feature is valid.
84 * Since IOperation does not have any feature returns false.
86 virtual bool isValid() const;
88 /// Sets the operation feature
89 void setFeature(FeaturePtr theFeature);
91 /// Returns True if the current operation works with the given object (feature or result)
92 virtual bool hasObject(ObjectPtr theObj) const;
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);
100 /// \brief Set property pane to the operation
101 /// \param theProp a property panel instance
102 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
104 /// \return Currently installed property panel
105 //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
107 /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
108 virtual void activateByPreselection();
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);
115 /// \return Installed parent feature (can be NULL)
116 CompositeFeaturePtr parentFeature() const;
119 /// The operation is filled with existing preselection
120 void activatedByPreselection();
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
132 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
133 /// Redefine abortOperation method to change behavior of operation instead
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
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);
147 /// Removes the preselection information and clears the map of preselection
148 void clearPreselection();
151 /// The operation feature to be handled
152 FeaturePtr myFeature;
154 /// Editing feature flag
157 /// List of nested operations IDs
158 QStringList myNestedFeatures;
160 /// List of pre-selected object
161 QList<ModuleBase_ViewerPrs> myPreSelection;
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;
168 /// Last current feature before editing operation
169 FeaturePtr myCurrentFeature;