Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModuleBase / ModuleBase_OperationFeature.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 /*
21  * ModuleBase_OperationFeature.h
22  *
23  *  Created on: Apr 2, 2014
24  *      Author: sbh
25  */
26
27 #ifndef ModuleBase_OperationFeature_H
28 #define ModuleBase_OperationFeature_H
29
30 #include <ModuleBase.h>
31 #include <ModuleBase_Operation.h>
32
33 #include <ModelAPI_Object.h>
34 #include <ModelAPI_CompositeFeature.h>
35
36 #include <QObject>
37 #include <QString>
38 #include <QStringList>
39
40 #include <set>
41
42 class ModuleBase_ModelWidget;
43 class ModuleBase_ISelection;
44 class ModuleBase_IViewer;
45 class ModuleBase_IWorkshop;
46 class ModuleBase_ViewerPrs;
47
48 class QKeyEvent;
49
50 /*!
51  * \class ModuleBase_OperationFeature
52  * \ingroup GUI
53  * \brief Base class for all operations
54  *
55  *  Base class for all operations. If you perform an action it is reasonable to create
56  *  operation intended for this. This is a base class for all operations which provides
57  *  mechanism for correct starting operations, starting operations above already started
58  *  ones, committing operations and so on. To create own operation it is reasonable to
59  *  inherit it from this class and redefines virtual methods to provide own behavior
60  *  Main virtual methods are
61  *  - virtual bool      isReadyToStart();
62  *  - virtual void      startOperation();
63  *  - virtual void      abortOperation();
64  *  - virtual void      commitOperation();
65  */
66
67 class MODULEBASE_EXPORT ModuleBase_OperationFeature : public ModuleBase_Operation
68 {
69 Q_OBJECT
70
71  public:
72
73   /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
74   static QString EditSuffix() { return "_E"; }
75   /// Constructor
76   /// \param theId the operation identifier
77   /// \param theParent the QObject parent
78   ModuleBase_OperationFeature(const QString& theId = "", QObject* theParent = 0);
79   /// Destructor
80   virtual ~ModuleBase_OperationFeature();
81
82   /// Returns True id the current operation is launched in editing mode
83   bool isEditOperation() const { return myIsEditing; }
84
85   /// Change the operation mode from create to edit.
86   /// The transaction and the operation name in the model history of transaction are the same.
87   /// It updates the edit state in the widgets of property panel
88   /// \param isEditState boolean state whether the operation should become editing or creating
89   // \param theRestartTransaction if true, the current model transaction is committed and
90   /// the new one is started
91   void setEditOperation(const bool& isEditState/*const bool theRestartTransaction*/);
92
93   /// Returns the operation feature
94   /// \return the feature
95   FeaturePtr feature() const;
96
97   /// Must return True if the operation's feature is valid.
98   /// Since IOperation does not have any feature returns false.
99   virtual bool isValid() const;
100
101   /// Sets the operation feature
102   void setFeature(FeaturePtr theFeature);
103
104   /// Returns True if the current operation works with the given object (feature or result)
105   virtual bool hasObject(ObjectPtr theObj) const;
106
107   /// Returns true if the object is displayed when the operation was started
108   /// \param theObject a feature or result of the operation feature
109   /// \return boolean value whether the object display state was changed
110   virtual bool isDisplayedOnStart(ObjectPtr theObject);
111
112   /// Initialisation of operation with preliminary selection
113   /// \param thePreSelected a container of selected presentations
114   virtual void initSelection(
115                   const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& thePreSelected);
116
117   /// Fill internal map by preselection
118   /// \param theValues a list of preselection
119   void setPreselection(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
120
121   /// \brief Set property pane to the operation
122   /// \param theProp a property panel instance
123   virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
124
125   // \return Currently installed property panel
126   //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
127
128   /// Activates widgets by preselection if it is accepted.
129   /// \param theGreedAttributeId a greed attribute id if there is in the current feature
130   /// \return last filled widget
131   virtual ModuleBase_ModelWidget* activateByPreselection(const std::string& theGreedAttributeId);
132
133   /// If the operation works with feature which is sub-feature of another one
134   /// then this variable has to be initialised by parent feature
135   /// before operation feature creating
136   void setParentFeature(CompositeFeaturePtr theParent);
137
138   /// \return Installed parent feature (can be NULL)
139   CompositeFeaturePtr parentFeature() const;
140
141   /// Stores the previous to the operation current feature
142   /// \param theFeature a feature
143   void setPreviousCurrentFeature(const FeaturePtr& theFeature);
144
145   /// Returns the previous to the operation current feature
146   /// \return theFeature a feature
147   FeaturePtr previousCurrentFeature();
148
149  public slots:
150   /// Starts operation
151   /// Public slot. Verifies whether operation can be started and starts operation.
152   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
153   /// to change behavior of operation. There is no point in using this method. It would
154   /// be better to inherit own operator from base one and redefine startOperation method
155   /// instead.
156   /// \return true if the start is successful
157   virtual bool start();
158
159   /// Aborts operation
160   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
161   /// Redefine abortOperation method to change behavior of operation instead
162   void abort();
163
164   /// Commits operation
165   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
166   /// Redefine commitOperation method to change behavior of operation instead
167   bool commit();
168
169  protected:
170   /// Displays the feature/results if it is hidden. It will be hided in stopOperation
171   virtual void startOperation();
172
173   /// Hide feature/results if they were hided on start
174   virtual void stopOperation();
175
176   /// Creates an operation new feature
177   /// \param theFlushMessage the flag whether the create message should be flushed
178   /// \returns the created feature
179   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
180
181   /// Removes the preselection information and clears the map of preselection
182   void clearPreselection();
183
184  protected:
185    /// The operation feature to be handled
186   FeaturePtr myFeature;
187
188   /// a list of hidden objects, whic are diplayed by operation start
189   /// and should be hidden by operation stop
190   std::set<ObjectPtr> myVisualizedObjects;
191
192   /// Editing feature flag
193   bool myIsEditing;
194
195   /// List of pre-selected object
196   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myPreSelection;
197
198   /// If the operation works with feature which is sub-feature of another one
199   /// then this variable has to be initialised by parent feature
200   /// before operation feature creating
201   CompositeFeaturePtr myParentFeature;
202
203   /// Last current feature before editing operation. It is cashed when Edit operation is started
204   /// in order to restore the document current feature on commit/abort this operation.
205   FeaturePtr myPreviousCurrentFeature;
206 };
207
208 #endif