Salome HOME
Fix compilation on Linux
[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 #include <ModelAPI_Attribute.h>\r
11 \r
12 #include <GeomAPI_Shape.h>\r
13 #include <GeomAPI_ICustomPrs.h>\r
14 \r
15 #include <QString>\r
16 #include <QObject>\r
17 #include <QMap>\r
18 #include <QList>\r
19 \r
20 #include <string>\r
21 #include <vector>\r
22 #include <map>\r
23 \r
24 class QAction;\r
25 class QMouseEvent;\r
26 class QKeyEvent;\r
27 class QMenu;\r
28 class Config_WidgetAPI;\r
29 class ModuleBase_ModelWidget;\r
30 class ModuleBase_Operation;\r
31 class ModuleBase_IWorkshop;\r
32 class ModelAPI_Result;\r
33 \r
34 class Handle_AIS_InteractiveObject;\r
35 \r
36 /**\r
37  * \ingroup GUI\r
38  * Interface to a module\r
39  */\r
40 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject\r
41 {\r
42   Q_OBJECT\r
43  public:\r
44   /// enumeration to know which objects should be customized\r
45   enum ModuleBase_CustomizeFlag {\r
46     CustomizeArguments = 0, /// references of other objects referenced to the current feature\r
47     CustomizeResults, /// results of the current feature\r
48     CustomizeHighlightedObjects /// highlighted objects of the active widget\r
49   };\r
50 \r
51    /// Constructor\r
52    /// \param theParent instance of workshop interface\r
53    ModuleBase_IModule(ModuleBase_IWorkshop* theParent);\r
54 \r
55   virtual ~ModuleBase_IModule() {}\r
56 \r
57   /// Add default selection filters of the module to the current viewer\r
58   virtual void activateSelectionFilters() {};\r
59 \r
60   /// Remove default selection filters of the module from the current viewer\r
61   virtual void deactivateSelectionFilters() {};\r
62 \r
63   // Stores the current selection\r
64   virtual void storeSelection() {};\r
65 \r
66   // Restores the current selection\r
67   virtual void restoreSelection() {};\r
68 \r
69   /// Reads description of features from XML file \r
70   virtual void createFeatures();\r
71 \r
72   /// Called on creation of menu item in desktop\r
73   virtual void actionCreated(QAction*);\r
74 \r
75   /// Launching of a edit operation on the feature \r
76   /// \param theFeature feature for editing\r
77   virtual void editFeature(FeaturePtr theFeature);\r
78 \r
79   /// Returns true if the operation can be committed. Result in default implementation is true.\r
80   /// \return boolean value\r
81   virtual bool canCommitOperation() const { return true; }\r
82 \r
83   /// Creates an operation and send it to loop\r
84   /// \param theCmdId the operation name\r
85   virtual void launchOperation(const QString& theCmdId);\r
86 \r
87   /// Executes feature as a modal dialog box\r
88   /// \param theCmdId the operation name\r
89   virtual void launchModal(const QString& theCmdId);\r
90 \r
91   /// Realizes some functionality by an operation start\r
92   /// \param theOperation a started operation\r
93   virtual void operationStarted(ModuleBase_Operation* theOperation) {}\r
94 \r
95   /// Realizes some functionality by an operation resume\r
96   /// By default it emits operationResumed signal\r
97   /// \param theOperation a resumed operation\r
98   virtual void operationResumed(ModuleBase_Operation* theOperation);\r
99 \r
100   /// Realizes some functionality by an operation stop\r
101   virtual void operationStopped(ModuleBase_Operation* theOperation) {}\r
102 \r
103   /// Realizes some functionality by an operation commit\r
104   virtual void operationCommitted(ModuleBase_Operation* theOperation) {}\r
105 \r
106   /// Realizes some functionality by an operation abort\r
107   virtual void operationAborted(ModuleBase_Operation* theOperation) {}\r
108 \r
109   /// Realizes some functionality by an operation start\r
110   virtual ModuleBase_Operation* currentOperation() const = 0;\r
111 \r
112   /// Add menu items for viewer into the actions map\r
113   /// \param theStdActions a map of standard actions\r
114   /// \param theMenuActions map of action/menu for the desirable index in the viewer menu\r
115   /// \return true if items are added and there is no necessity to provide standard menu\r
116   virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,\r
117                              QWidget* theParent,\r
118                              QMap<int, QAction*>& theMenuActions) const\r
119   { return false; }\r
120 \r
121   /// Add menu items for object browser into the given menu\r
122   /// \param theMenu a popup menu to be shown in the object browser\r
123   virtual void addObjectBrowserMenu(QMenu* theMenu) const {};\r
124 \r
125   /// Creates custom widgets for property panel\r
126   /// \param theType a type of widget\r
127   /// \param theParent the parent object\r
128   /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from\r
129   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
130                                                      Config_WidgetAPI* theWidgetApi)\r
131   {\r
132     return 0;\r
133   }\r
134 \r
135   /// Returns the active widget, by default it is the property panel active widget\r
136   virtual ModuleBase_ModelWidget* activeWidget() const = 0;\r
137 \r
138   /// Returns current workshop\r
139   ModuleBase_IWorkshop* workshop() const { return myWorkshop; }\r
140 \r
141   /// Call back forlast tuning of property panel before operation performance\r
142   /// It is called as on clearing of property panel as on filling with new widgets\r
143   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}\r
144 \r
145   /// Have an opportunity to create widgets for the current operation instead of standard creation in workshop\r
146   /// \param theOperation a started operation\r
147   /// \param theWidgets a list of created widgets\r
148   /// \return boolean result, false by default\r
149   virtual bool createWidgets(ModuleBase_Operation* theOperation,\r
150                              QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }\r
151 \r
152   //! Returns True if there are available Undos and there is not an active operation\r
153   virtual bool canUndo() const;\r
154 \r
155   //! Returns True if there are available Redos and there is not an active operation\r
156   virtual bool canRedo() const;\r
157 \r
158   /// Returns true if the action can be applyed to the object\r
159   /// \param theObject a checked object\r
160   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"\r
161   /// \return the a boolean result\r
162   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;\r
163 \r
164   /// Returns True if the current operation can be committed. By default it is true.\r
165   /// \return a boolean value\r
166   //virtual bool canCommitOperation() const;\r
167 \r
168   /// Returns whether the object can be erased. The default realization returns true.\r
169   /// \param theObject a model object\r
170   virtual bool canEraseObject(const ObjectPtr& theObject) const;\r
171 \r
172   /// Returns whether the object can be displayed. The default realization returns true.\r
173   /// \param theObject a model object\r
174   virtual bool canDisplayObject(const ObjectPtr& theObject) const;\r
175 \r
176   /// Make some functionality after the objects are hidden in viewer\r
177   /// \param theObjects a list of hidden objects\r
178   virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};\r
179 \r
180   /// Returns true if selection for the object can be activate.\r
181   /// By default a result or feature of the current operation can not be activated\r
182   /// \param theObject a model object\r
183   virtual bool canActivateSelection(const ObjectPtr& theObject) const;\r
184 \r
185   /// Reacts to the delete action in module\r
186   /// \returns true if the action is processed\r
187   virtual bool deleteObjects() { return false; };\r
188 \r
189   /// Performs functionality on closing document\r
190   virtual void closeDocument() = 0;\r
191 \r
192   /// Clears specific presentations in the viewer\r
193   virtual void clearViewer() = 0;\r
194 \r
195   /// Returns a list of modes, where the AIS objects should be activated\r
196   /// \param theModes a list of modes\r
197   virtual void activeSelectionModes(QIntList& theModes) {}\r
198 \r
199   /// Activate custom presentation for the object. Default realization is empty.\r
200   /// \param theObject an object instance\r
201   /// \param theFlag a flag of level of customization, which means that only part of sub-elements\r
202   /// \param theUpdateViewer the parameter whether the viewer should be update immediately\r
203   virtual void activateCustomPrs(const FeaturePtr& theFeature,\r
204                                  const ModuleBase_CustomizeFlag& theFlag,\r
205                                  const bool theUpdateViewer) {}\r
206 \r
207   /// Deactivate custom presentation for the object. Default realization is empty.\r
208   /// \param theFlag a flag of level of customization, which means that only part of sub-elements\r
209   /// \param theUpdateViewer the parameter whether the viewer should be update immediately\r
210   virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,\r
211                                    const bool theUpdateViewer) {}\r
212 \r
213   /// Modifies the given presentation in the custom way.\r
214   virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult, AISObjectPtr thePrs,\r
215                                      GeomCustomPrsPtr theCustomPrs) { return false; };\r
216 \r
217   /// Update the object presentable properties such as color, lines width and other\r
218   /// If the object is result with the color attribute value set, it is used,\r
219   /// otherwise the customize is applyed to the object's feature if it is a custom prs\r
220   /// \param theObject an object instance\r
221   /// \param theFlag a flag of level of customization, which means that only part of sub-elements\r
222   /// should be updated(e.g. only highlighted elements)\r
223   /// \param theUpdateViewer the parameter whether the viewer should be update immediately\r
224   /// \returns true if the object is modified\r
225   virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,\r
226                                const bool theUpdateViewer);\r
227 \r
228   /// This method is called on object browser creation for customization of module specific features\r
229   /// \param theObjectBrowser a pinter on Object Browser widget\r
230   virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}\r
231 \r
232   /// Creates a new operation\r
233   /// \param theCmdId the operation name\r
234   virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);\r
235 \r
236   /// Sends the operation for launching\r
237   /// \param theOperation the operation\r
238   virtual void sendOperation(ModuleBase_Operation* theOperation);\r
239 \r
240   /// Create specific for the module presentation\r
241   /// \param theResult an object for presentation\r
242   /// \return created presentation or NULL(default value)\r
243   virtual Handle_AIS_InteractiveObject createPresentation(\r
244                            const std::shared_ptr<ModelAPI_Result>& theResult);\r
245 \r
246   //! Returns data object by AIS\r
247   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;\r
248 \r
249   //! Returns true if the presentation can be shown in shading mode\r
250   //! \param theAIS presentation to be checked\r
251   //! \return boolean value\r
252   virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;\r
253 \r
254   /// Update state of pop-up menu items in object browser\r
255   /// \param theStdActions - a map of standard actions\r
256   virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}\r
257 \r
258   /// Update state of pop-up menu items in viewer\r
259   /// \param theStdActions - a map of standard actions\r
260   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}\r
261 \r
262   //! Returns the feature error if the current state of the feature in the module is not correct\r
263   //! If the feature is correct, it returns an empty value\r
264   //! \return string value\r
265   virtual QString getFeatureError(const FeaturePtr& theFeature);\r
266 \r
267   /// Returns list of granted operation indices\r
268   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;\r
269 \r
270   /// Connects or disconnects to the value changed signal of the property panel widgets\r
271   /// \param theWidget a property contol widget\r
272   /// \param isToConnect a boolean value whether connect or disconnect\r
273   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};\r
274 \r
275   /// Validates the operation to change the "Apply" button state.\r
276   /// \param thePreviousState the previous state of the widget\r
277   virtual void widgetStateChanged(int thePreviousState) {};\r
278 \r
279   /// Returns true if the event is processed.\r
280   /// \param thePreviousAttributeID an index of the previous active attribute\r
281   virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };\r
282 \r
283   /// Performs some GUI actions after an operation transaction is opened\r
284   /// Default realization is empty\r
285   virtual void beforeOperationStarted(ModuleBase_Operation* theOperation) {};\r
286 \r
287   /// Performs some GUI actions before an operation transaction is stopped\r
288   /// Default realization is empty\r
289   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};\r
290 \r
291   /// Finds a shape by attribute if it is possible\r
292   /// \param theAttribute an attribute\r
293   /// \return a geom shape\r
294   virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;\r
295 \r
296   /// Finds an attribute by geom shape if it is possible\r
297   /// \param theObject an object of the attribute\r
298   /// \param theGeomShape a geom shape\r
299   /// \return theAttribute\r
300   virtual AttributePtr findAttribute(const ObjectPtr& theObject,\r
301                                      const GeomShapePtr& theGeomShape) = 0;\r
302 \r
303   /// Returns XML information by the feature index\r
304   /// \param theFeatureId a feature id\r
305   /// \param theXmlCfg XML configuration\r
306   /// \param theDescription feature description\r
307   void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,\r
308                             std::string& theDescription);\r
309 \r
310 signals:\r
311   /// Signal which is emitted when operation is launched\r
312   void operationLaunched();\r
313 \r
314   /// Segnal emitted when an operation is resumed\r
315   /// \param theOp a resumed operation\r
316   void resumed(ModuleBase_Operation* theOp);\r
317 \r
318 public slots:\r
319   /// Called on call of command corresponded to a feature\r
320   virtual void onFeatureTriggered();\r
321 \r
322   /// Slot called on object display\r
323   /// \param theObject a data object\r
324   /// \param theAIS a presentation object\r
325   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
326 \r
327   /// Slot called on before object erase\r
328   /// \param theObject a data object\r
329   /// \param theAIS a presentation object\r
330   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
331 \r
332 protected slots:\r
333   /// Called on selection changed event\r
334   virtual void onSelectionChanged() {}\r
335 \r
336 protected:\r
337  /// Register validators for this module\r
338   virtual void registerValidators() {}\r
339 \r
340   /// Register selection filters for this module\r
341   virtual void registerFilters() {}\r
342 \r
343   /// Register properties of this module\r
344   virtual void registerProperties() {}\r
345 \r
346   /// Returns new instance of operation object (used in createOperation for customization)\r
347   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);\r
348 \r
349 protected:\r
350   /// Reference to workshop\r
351   ModuleBase_IWorkshop* myWorkshop;\r
352 \r
353   /// Map of features in XML\r
354   std::map<std::string, std::string> myFeaturesInFiles;\r
355 };\r
356 \r
357 \r
358 \r
359 //! This function must return a new module instance.\r
360 extern "C" {\r
361 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);\r
362 }\r
363 \r
364 #define CREATE_MODULE "createModule"\r
365 \r
366 #endif //ModuleBase_IModule\r