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