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