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