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