]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_IModule.h
Salome HOME
Imrove multi-selector control to provide items multi-selection. Activate/deactivate...
[modules/shaper.git] / src / ModuleBase / ModuleBase_IModule.h
1  // Copyright (C) 2014-20xx CEA/DEN, EDF R&D\r
2 \r
3 #ifndef ModuleBase_IModule_H\r
4 #define ModuleBase_IModule_H\r
5 \r
6 #include "ModuleBase.h"\r
7 #include "ModuleBase_IWorkshop.h"\r
8 \r
9 #include <ModelAPI_Feature.h>\r
10 \r
11 #include <QString>\r
12 #include <QObject>\r
13 #include <QMap>\r
14 \r
15 #include <string>\r
16 #include <map>\r
17 \r
18 class QAction;\r
19 class QMouseEvent;\r
20 class QKeyEvent;\r
21 class QMenu;\r
22 class Config_WidgetAPI;\r
23 class ModuleBase_ModelWidget;\r
24 class ModuleBase_Operation;\r
25 class ModuleBase_IWorkshop;\r
26 \r
27 /**\r
28  * \ingroup GUI\r
29  * Interface to a module\r
30  */\r
31 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject\r
32 {\r
33   Q_OBJECT\r
34  public:\r
35   /// enumeration to know which objects should be customized\r
36   enum ModuleBase_CustomizeFlag {\r
37     CustomizeArguments = 0, /// references of other objects referenced to the current feature\r
38     CustomizeResults, /// results of the current feature\r
39     CustomizeHighlightedObjects /// highlighted objects of the active widget\r
40   };\r
41 \r
42    /// Constructor\r
43    /// \param theParent instance of workshop interface\r
44    ModuleBase_IModule(ModuleBase_IWorkshop* theParent);\r
45 \r
46   virtual ~ModuleBase_IModule() {}\r
47 \r
48   /// Add default selection filters of the module to the current viewer\r
49   virtual void activateSelectionFilters() {};\r
50 \r
51   /// Remove default selection filters of the module from the current viewer\r
52   virtual void deactivateSelectionFilters() {};\r
53 \r
54   /// Reads description of features from XML file \r
55   virtual void createFeatures();\r
56 \r
57   /// Called on creation of menu item in desktop\r
58   virtual void actionCreated(QAction*);\r
59 \r
60   /// Launching of a edit operation on the feature \r
61   /// \param theFeature feature for editing\r
62   virtual void editFeature(FeaturePtr theFeature);\r
63 \r
64   /// Creates an operation and send it to loop\r
65   /// \param theCmdId the operation name\r
66   virtual void launchOperation(const QString& theCmdId);\r
67 \r
68   /// Realizes some functionality by an operation start\r
69   /// \param theOperation a started operation\r
70   virtual void operationStarted(ModuleBase_Operation* theOperation) {}\r
71 \r
72   /// Realizes some functionality by an operation resume\r
73   /// By default it emits operationResumed signal\r
74   /// \param theOperation a resumed operation\r
75   virtual void operationResumed(ModuleBase_Operation* theOperation);\r
76 \r
77   /// Realizes some functionality by an operation stop\r
78   virtual void operationStopped(ModuleBase_Operation* theOperation) {}\r
79 \r
80   /// Realizes some functionality by an operation commit\r
81   virtual void operationCommitted(ModuleBase_Operation* theOperation) {}\r
82 \r
83   /// Realizes some functionality by an operation abort\r
84   virtual void operationAborted(ModuleBase_Operation* theOperation) {}\r
85 \r
86   /// Realizes some functionality by an operation start\r
87   virtual ModuleBase_Operation* currentOperation() const = 0;\r
88 \r
89   /// Add menu items for viewer into the given menu\r
90   /// \param theMenu a popup menu to be shown in the viewer\r
91   /// \param theStdActions a map of standard actions\r
92   /// \return true if items are added and there is no necessity to provide standard menu\r
93   virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }\r
94 \r
95   /// Add menu items for object browser into the given menu\r
96   /// \param theMenu a popup menu to be shown in the object browser\r
97   virtual void addObjectBrowserMenu(QMenu* theMenu) const {};\r
98 \r
99   /// Creates custom widgets for property panel\r
100   /// \param theType a type of widget\r
101   /// \param theParent the parent object\r
102   /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from\r
103   /// \param theParentId is Id of a parent of the current attribute\r
104   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
105                                       Config_WidgetAPI* theWidgetApi, std::string theParentId)\r
106   {\r
107     return 0;\r
108   }\r
109 \r
110   /// Returns the active widget, by default it is the property panel active widget\r
111   virtual ModuleBase_ModelWidget* activeWidget() const = 0;\r
112 \r
113   /// Returns current workshop\r
114   ModuleBase_IWorkshop* workshop() const { return myWorkshop; }\r
115 \r
116   /// Call back forlast tuning of property panel before operation performance\r
117   /// It is called as on clearing of property panel as on filling with new widgets\r
118   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}\r
119 \r
120   //! Returns True if there are available Undos and there is not an active operation\r
121   virtual bool canUndo() const;\r
122 \r
123   //! Returns True if there are available Redos and there is not an active operation\r
124   virtual bool canRedo() const;\r
125 \r
126   /// Returns true if the action can be applyed to the object\r
127   /// \param theObject a checked object\r
128   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"\r
129   /// \return the a boolean result\r
130   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;\r
131 \r
132   /// Returns True if the current operation can be committed. By default it is true.\r
133   /// \return a boolean value\r
134   //virtual bool canCommitOperation() const;\r
135 \r
136   /// Returns whether the object can be erased. The default realization returns true.\r
137   /// \param theObject a model object\r
138   virtual bool canEraseObject(const ObjectPtr& theObject) const;\r
139 \r
140   /// Returns whether the object can be displayed. The default realization returns true.\r
141   /// \param theObject a model object\r
142   virtual bool canDisplayObject(const ObjectPtr& theObject) const;\r
143 \r
144   /// Returns true if selection for the object can be activate.\r
145   /// By default a result or feature of the current operation can not be activated\r
146   /// \param theObject a model object\r
147   virtual bool canActivateSelection(const ObjectPtr& theObject) const;\r
148 \r
149   /// Reacts to the delete action in module\r
150   /// \returns true if the action is processed\r
151   virtual bool deleteObjects() { return false; };\r
152 \r
153   /// Performs functionality on closing document\r
154   virtual void closeDocument() = 0;\r
155 \r
156   /// Clears specific presentations in the viewer\r
157   virtual void clearViewer() = 0;\r
158 \r
159   /// Returns a list of modes, where the AIS objects should be activated\r
160   /// \param theModes a list of modes\r
161   virtual void activeSelectionModes(QIntList& theModes) {}\r
162 \r
163   /// Activate custom presentation for the object. Default realization is empty.\r
164   /// \param theObject an object instance\r
165   /// \param theFlag a flag of level of customization, which means that only part of sub-elements\r
166   /// \param theUpdateViewer the parameter whether the viewer should be update immediately\r
167   virtual void activateCustomPrs(const FeaturePtr& theFeature,\r
168                                  const ModuleBase_CustomizeFlag& theFlag,\r
169                                  const bool theUpdateViewer) {}\r
170 \r
171   /// Deactivate custom presentation for the object. Default realization is empty.\r
172   /// \param theFlag a flag of level of customization, which means that only part of sub-elements\r
173   /// \param theUpdateViewer the parameter whether the viewer should be update immediately\r
174   virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,\r
175                                    const bool theUpdateViewer) {}\r
176 \r
177   /// Update the object presentable properties such as color, lines width and other\r
178   /// If the object is result with the color attribute value set, it is used,\r
179   /// otherwise the customize is applyed to the object's feature if it is a custom prs\r
180   /// \param theObject an object instance\r
181   /// \param theFlag a flag of level of customization, which means that only part of sub-elements\r
182   /// should be updated(e.g. only highlighted elements)\r
183   /// \param theUpdateViewer the parameter whether the viewer should be update immediately\r
184   /// \returns true if the object is modified\r
185   virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,\r
186                                const bool theUpdateViewer);\r
187 \r
188   /// This method is called on object browser creation for customization of module specific features\r
189   /// \param theObjectBrowser a pinter on Object Browser widget\r
190   virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}\r
191 \r
192   /// Creates a new operation\r
193   /// \param theCmdId the operation name\r
194   virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);\r
195 \r
196   /// Sends the operation for launching\r
197   /// \param theOperation the operation\r
198   virtual void sendOperation(ModuleBase_Operation* theOperation);\r
199 \r
200   //! Returns data object by AIS\r
201   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;\r
202 \r
203   /// Update state of pop-up menu items in object browser\r
204   /// \param theStdActions - a map of standard actions\r
205   virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}\r
206 \r
207   /// Update state of pop-up menu items in viewer\r
208   /// \param theStdActions - a map of standard actions\r
209   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}\r
210 \r
211   //! Returns the feature error if the current state of the feature in the module is not correct\r
212   //! If the feature is correct, it returns an empty value\r
213   //! \return string value\r
214   virtual QString getFeatureError(const FeaturePtr& theFeature);\r
215 \r
216   /// Returns list of granted operation indices\r
217   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;\r
218 \r
219   /// Connects or disconnects to the value changed signal of the property panel widgets\r
220   /// \param theWidget a property contol widget\r
221   /// \param isToConnect a boolean value whether connect or disconnect\r
222   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};\r
223 \r
224   /// Validates the operation to change the "Apply" button state.\r
225   /// \param thePreviousState the previous state of the widget\r
226   virtual void widgetStateChanged(int thePreviousState) {};\r
227 \r
228   /// Returns true if the event is processed.\r
229   /// \param thePreviousAttributeID an index of the previous active attribute\r
230   virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };\r
231 \r
232   /// Performs some GUI actions after an operation transaction is opened\r
233   /// Default realization is empty\r
234   virtual void beforeOperationStarted(ModuleBase_Operation* theOperation) {};\r
235 \r
236   /// Performs some GUI actions before an operation transaction is stopped\r
237   /// Default realization is empty\r
238   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};\r
239 \r
240 signals:\r
241   /// Signal which is emitted when operation is launched\r
242   void operationLaunched();\r
243 \r
244   /// Segnal emitted when an operation is resumed\r
245   /// \param theOp a resumed operation\r
246   void resumed(ModuleBase_Operation* theOp);\r
247 \r
248 public slots:\r
249   /// Called on call of command corresponded to a feature\r
250   virtual void onFeatureTriggered();\r
251 \r
252   /// Slot called on object display\r
253   /// \param theObject a data object\r
254   /// \param theAIS a presentation object\r
255   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
256 \r
257   /// Slot called on before object erase\r
258   /// \param theObject a data object\r
259   /// \param theAIS a presentation object\r
260   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
261 \r
262 protected slots:\r
263   /// Called on selection changed event\r
264   virtual void onSelectionChanged() {}\r
265 \r
266  protected:\r
267   /// Register validators for this module\r
268   virtual void registerValidators() {}\r
269 \r
270   /// Register selection filters for this module\r
271   virtual void registerFilters() {}\r
272 \r
273   /// Register properties of this module\r
274   virtual void registerProperties() {}\r
275 \r
276   /// Returns new instance of operation object (used in createOperation for customization)\r
277   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);\r
278 \r
279 protected:\r
280 \r
281   /// Reference to workshop\r
282   ModuleBase_IWorkshop* myWorkshop;\r
283 \r
284   /// Map of features in XML\r
285   std::map<std::string, std::string> myFeaturesInFiles;\r
286 };\r
287 \r
288 \r
289 \r
290 //! This function must return a new module instance.\r
291 extern "C" {\r
292 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);\r
293 }\r
294 \r
295 #define CREATE_MODULE "createModule"\r
296 \r
297 #endif //ModuleBase_IModule\r