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>
16 #include <ModelAPI_Object.h>
17 #include <ModelAPI_CompositeFeature.h>
21 #include <QStringList>
25 class ModuleBase_ModelWidget;
26 class ModuleBase_ISelection;
27 class ModuleBase_IViewer;
28 class ModuleBase_IWorkshop;
29 class ModuleBase_ViewerPrs;
34 * \class ModuleBase_OperationFeature
36 * \brief Base class for all operations
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();
50 class MODULEBASE_EXPORT ModuleBase_OperationFeature : public ModuleBase_Operation
56 /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
57 static QString EditSuffix() { return "_E"; }
59 /// \param theId the operation identifier
60 /// \param theParent the QObject parent
61 ModuleBase_OperationFeature(const QString& theId = "", QObject* theParent = 0);
63 virtual ~ModuleBase_OperationFeature();
65 /// Returns True id the current operation is launched in editing mode
66 bool isEditOperation() const { return myIsEditing; }
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*/);
76 /// Returns the operation feature
77 /// \return the feature
78 FeaturePtr feature() const;
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;
84 /// Sets the operation feature
85 void setFeature(FeaturePtr theFeature);
87 /// Returns True if the current operation works with the given object (feature or result)
88 virtual bool hasObject(ObjectPtr theObj) const;
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);
95 /// Initialisation of operation with preliminary selection
96 /// \param thePreSelected a container of selected presentations
97 virtual void initSelection(
98 const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& thePreSelected);
100 /// Fill internal map by preselection
101 /// \param theValues a list of preselection
102 void setPreselection(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
104 /// \brief Set property pane to the operation
105 /// \param theProp a property panel instance
106 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
108 // \return Currently installed property panel
109 //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
111 /// Activates widgets by preselection if it is accepted.
112 /// \param theGreedAttributeId a greed attribute id if there is in the current feature
113 /// \return last filled widget
114 virtual ModuleBase_ModelWidget* activateByPreselection(const std::string& theGreedAttributeId);
116 /// If the operation works with feature which is sub-feature of another one
117 /// then this variable has to be initialised by parent feature
118 /// before operation feature creating
119 void setParentFeature(CompositeFeaturePtr theParent);
121 /// \return Installed parent feature (can be NULL)
122 CompositeFeaturePtr parentFeature() const;
124 /// Stores the previous to the operation current feature
125 /// \param theFeature a feature
126 void setPreviousCurrentFeature(const FeaturePtr& theFeature);
128 /// Returns the previous to the operation current feature
129 /// \return theFeature a feature
130 FeaturePtr previousCurrentFeature();
134 /// Public slot. Verifies whether operation can be started and starts operation.
135 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
136 /// to change behavior of operation. There is no point in using this method. It would
137 /// be better to inherit own operator from base one and redefine startOperation method
139 /// \return true if the start is successful
140 virtual bool start();
143 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
144 /// Redefine abortOperation method to change behavior of operation instead
147 /// Commits operation
148 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
149 /// Redefine commitOperation method to change behavior of operation instead
153 /// Displays the feature/results if it is hidden. It will be hided in stopOperation
154 virtual void startOperation();
156 /// Hide feature/results if they were hided on start
157 virtual void stopOperation();
159 /// Creates an operation new feature
160 /// \param theFlushMessage the flag whether the create message should be flushed
161 /// \returns the created feature
162 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
164 /// Removes the preselection information and clears the map of preselection
165 void clearPreselection();
168 /// The operation feature to be handled
169 FeaturePtr myFeature;
171 /// a list of hidden objects, whic are diplayed by operation start
172 /// and should be hidden by operation stop
173 std::set<ObjectPtr> myVisualizedObjects;
175 /// Editing feature flag
178 /// List of pre-selected object
179 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myPreSelection;
181 /// If the operation works with feature which is sub-feature of another one
182 /// then this variable has to be initialised by parent feature
183 /// before operation feature creating
184 CompositeFeaturePtr myParentFeature;
186 /// Last current feature before editing operation. It is cashed when Edit operation is started
187 /// in order to restore the document current feature on commit/abort this operation.
188 FeaturePtr myPreviousCurrentFeature;