1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef ModuleBase_OperationFeature_H
22 #define ModuleBase_OperationFeature_H
24 #include <ModuleBase.h>
25 #include <ModuleBase_Operation.h>
27 #include <ModelAPI_Object.h>
28 #include <ModelAPI_CompositeFeature.h>
32 #include <QStringList>
36 class ModuleBase_ModelWidget;
37 class ModuleBase_ISelection;
38 class ModuleBase_IViewer;
39 class ModuleBase_IWorkshop;
40 class ModuleBase_ViewerPrs;
45 * \class ModuleBase_OperationFeature
47 * \brief Base class for all operations
49 * Base class for all operations. If you perform an action it is reasonable to create
50 * operation intended for this. This is a base class for all operations which provides
51 * mechanism for correct starting operations, starting operations above already started
52 * ones, committing operations and so on. To create own operation it is reasonable to
53 * inherit it from this class and redefines virtual methods to provide own behavior
54 * Main virtual methods are
55 * - virtual bool isReadyToStart();
56 * - virtual void startOperation();
57 * - virtual void abortOperation();
58 * - virtual void commitOperation();
61 class MODULEBASE_EXPORT ModuleBase_OperationFeature : public ModuleBase_Operation
67 /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
68 static QString EditSuffix() { return "_E"; }
70 /// \param theId the operation identifier
71 /// \param theParent the QObject parent
72 ModuleBase_OperationFeature(const QString& theId = "", QObject* theParent = 0);
74 virtual ~ModuleBase_OperationFeature();
76 /// Returns True id the current operation is launched in editing mode
77 bool isEditOperation() const { return myIsEditing; }
79 /// Change the operation mode from create to edit.
80 /// The transaction and the operation name in the model history of transaction are the same.
81 /// It updates the edit state in the widgets of property panel
82 /// \param isEditState boolean state whether the operation should become editing or creating
83 // \param theRestartTransaction if true, the current model transaction is committed and
84 /// the new one is started
85 void setEditOperation(const bool& isEditState/*const bool theRestartTransaction*/);
87 /// Returns the operation feature
88 /// \return the feature
89 FeaturePtr feature() const;
91 /// Must return True if the operation's feature is valid.
92 /// Since IOperation does not have any feature returns false.
93 virtual bool isValid() const;
95 /// Sets the operation feature
96 void setFeature(FeaturePtr theFeature);
98 /// Returns True if the current operation works with the given object (feature or result)
99 virtual bool hasObject(ObjectPtr theObj) const;
101 /// Returns true if the object is displayed when the operation was started
102 /// \param theObject a feature or result of the operation feature
103 /// \return boolean value whether the object display state was changed
104 virtual bool isDisplayedOnStart(ObjectPtr theObject);
106 /// Initialisation of operation with preliminary selection
107 /// \param thePreSelected a container of selected presentations
108 virtual void initSelection(
109 const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& thePreSelected);
111 /// Fill internal map by preselection
112 /// \param theValues a list of preselection
113 void setPreselection(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
115 /// \brief Set property pane to the operation
116 /// \param theProp a property panel instance
117 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
119 // \return Currently installed property panel
120 //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
122 /// Activates widgets by preselection if it is accepted.
123 /// \param theGreedAttributeId a greed attribute id if there is in the current feature
124 /// \return last filled widget
125 virtual ModuleBase_ModelWidget* activateByPreselection(const std::string& theGreedAttributeId);
127 /// If the operation works with feature which is sub-feature of another one
128 /// then this variable has to be initialised by parent feature
129 /// before operation feature creating
130 void setParentFeature(CompositeFeaturePtr theParent);
132 /// \return Installed parent feature (can be NULL)
133 CompositeFeaturePtr parentFeature() const;
135 /// Stores the previous to the operation current feature
136 /// \param theFeature a feature
137 void setPreviousCurrentFeature(const FeaturePtr& theFeature);
139 /// Returns the previous to the operation current feature
140 /// \return theFeature a feature
141 FeaturePtr previousCurrentFeature();
145 /// Public slot. Verifies whether operation can be started and starts operation.
146 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
147 /// to change behavior of operation. There is no point in using this method. It would
148 /// be better to inherit own operator from base one and redefine startOperation method
150 /// \return true if the start is successful
151 virtual bool start();
154 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
155 /// Redefine abortOperation method to change behavior of operation instead
158 /// Commits operation
159 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
160 /// Redefine commitOperation method to change behavior of operation instead
164 /// Displays the feature/results if it is hidden. It will be hided in stopOperation
165 virtual void startOperation();
167 /// Hide feature/results if they were hided on start
168 virtual void stopOperation();
170 /// Creates an operation new feature
171 /// \param theFlushMessage the flag whether the create message should be flushed
172 /// \returns the created feature
173 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
175 /// Removes the preselection information and clears the map of preselection
176 void clearPreselection();
179 /// The operation feature to be handled
180 FeaturePtr myFeature;
182 /// a list of hidden objects, whic are diplayed by operation start
183 /// and should be hidden by operation stop
184 std::set<ObjectPtr> myVisualizedObjects;
186 /// Editing feature flag
189 /// List of pre-selected object
190 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myPreSelection;
192 /// If the operation works with feature which is sub-feature of another one
193 /// then this variable has to be initialised by parent feature
194 /// before operation feature creating
195 CompositeFeaturePtr myParentFeature;
197 /// Last current feature before editing operation. It is cashed when Edit operation is started
198 /// in order to restore the document current feature on commit/abort this operation.
199 FeaturePtr myPreviousCurrentFeature;