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