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_Object.h>
18 #include <ModelAPI_CompositeFeature.h>
22 #include <QStringList>
26 class ModuleBase_ModelWidget;
27 class ModuleBase_ISelection;
28 class ModuleBase_IViewer;
33 * \class ModuleBase_OperationFeature
35 * \brief Base class for all operations
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();
49 class MODULEBASE_EXPORT ModuleBase_OperationFeature : public ModuleBase_Operation
55 /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
56 static QString EditSuffix() { return "_E"; }
58 /// \param theId the operation identifier
59 /// \param theParent the QObject parent
60 ModuleBase_OperationFeature(const QString& theId = "", QObject* theParent = 0);
62 virtual ~ModuleBase_OperationFeature();
64 /// Returns True id the current operation is launched in editing mode
65 bool isEditOperation() const { return myIsEditing; }
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 void setEditOperation();
72 /// Returns the operation feature
73 /// \return the feature
74 FeaturePtr feature() const;
76 /// Must return True if the operation's feature is valid.
77 /// Since IOperation does not have any feature returns false.
78 virtual bool isValid() const;
80 /// Sets the operation feature
81 void setFeature(FeaturePtr theFeature);
83 /// Returns True if the current operation works with the given object (feature or result)
84 virtual bool hasObject(ObjectPtr theObj) const;
86 /// Returns true if the object is displayed when the operation was started
87 /// \param theObject a feature or result of the operation feature
88 /// \return boolean value whether the object display state was changed
89 virtual bool isDisplayedOnStart(ObjectPtr theObject);
91 /// Initialisation of operation with preliminary selection
92 /// \param theSelection an instance of Selection class
93 /// \param theViewer a viewer to have the viewer the eye position
94 virtual void initSelection(ModuleBase_ISelection* theSelection,
95 ModuleBase_IViewer* theViewer);
97 /// \brief Set property pane to the operation
98 /// \param theProp a property panel instance
99 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
101 /// \return Currently installed property panel
102 //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
104 /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
105 virtual void activateByPreselection();
107 /// If the operation works with feature which is sub-feature of another one
108 /// then this variable has to be initialised by parent feature
109 /// before operation feature creating
110 void setParentFeature(CompositeFeaturePtr theParent);
112 /// \return Installed parent feature (can be NULL)
113 CompositeFeaturePtr parentFeature() const;
115 /// Stores the previous to the operation current feature
116 /// \set theFeature a feature
117 void setPreviousCurrentFeature(const FeaturePtr& theFeature);
119 /// Returns the previous to the operation current feature
120 /// \return theFeature a feature
121 FeaturePtr previousCurrentFeature();
124 /// The operation is filled with existing preselection
125 void activatedByPreselection();
129 /// Public slot. Verifies whether operation can be started and starts operation.
130 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
131 /// to change behavior of operation. There is no point in using this method. It would
132 /// be better to inherit own operator from base one and redefine startOperation method
137 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
138 /// Redefine abortOperation method to change behavior of operation instead
141 /// Commits operation
142 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
143 /// Redefine commitOperation method to change behavior of operation instead
147 /// Displays the feature/results if it is hidden. It will be hided in stopOperation
148 virtual void startOperation();
150 /// Hide feature/results if they were hided on start
151 virtual void stopOperation();
153 /// Creates an operation new feature
154 /// \param theFlushMessage the flag whether the create message should be flushed
155 /// \returns the created feature
156 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
158 /// Removes the preselection information and clears the map of preselection
159 void clearPreselection();
162 /// The operation feature to be handled
163 FeaturePtr myFeature;
165 /// a list of hidden objects, whic are diplayed by operation start
166 /// and should be hidden by operation stop
167 std::set<ObjectPtr> myVisualizedObjects;
169 /// Editing feature flag
172 /// List of pre-selected object
173 QList<ModuleBase_ViewerPrs> myPreSelection;
175 /// If the operation works with feature which is sub-feature of another one
176 /// then this variable has to be initialised by parent feature
177 /// before operation feature creating
178 CompositeFeaturePtr myParentFeature;
180 /// Last current feature before editing operation. It is cashed when Edit operation is started
181 /// in order to restore the document current feature on commit/abort this operation.
182 FeaturePtr myPreviousCurrentFeature;