]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_IModule.h
Salome HOME
Merge remote-tracking branch 'origin/DISPLAY_FIELD_STEP'
[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   /// This method is called on object browser creation for customization of module specific features
294   /// \param theObjectBrowser a pinter on Object Browser widget
295   virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
296
297   /// Creates a new operation
298   /// \param theCmdId the operation name
299   virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
300
301   /// Create specific for the module presentation
302   /// \param theResult an object for presentation
303   /// \return created presentation or NULL(default value)
304   virtual Handle(AIS_InteractiveObject) createPresentation(const ObjectPtr& theResult);
305
306   //! Returns data object by AIS
307   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
308
309   //! Returns true if the presentation can be shown in shading mode
310   //! \param theAIS presentation to be checked
311   //! \return boolean value
312   virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
313
314   /// Update state of pop-up menu items in object browser
315   /// \param theStdActions - a map of standard actions
316   virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
317
318   /// Update state of pop-up menu items in viewer
319   /// \param theStdActions - a map of standard actions
320   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
321
322   /// Returns true if the action should be always enabled
323   /// \param theActionId an action index: Accept or Accept All
324   /// \return boolean value
325   virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
326
327   //! Returns the feature error if the current state of the feature in the module is not correct
328   //! If the feature is correct, it returns an empty value
329   //! \return string value
330   virtual QString getFeatureError(const FeaturePtr& theFeature);
331
332   /// Returns list of granted operation indices
333   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
334
335   /// Connects or disconnects to the value changed signal of the property panel widgets
336   /// \param theWidget a property contol widget
337   /// \param isToConnect a boolean value whether connect or disconnect
338   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
339
340   /// Validates the operation to change the "Apply" button state.
341   /// \param thePreviousState the previous state of the widget
342   virtual void widgetStateChanged(int thePreviousState) {};
343
344   /// Returns true if the event is processed.
345   /// \param thePreviousAttributeID an index of the previous active attribute
346   virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
347
348   /// Performs some GUI actions before an operation transaction is stopped
349   /// Default realization is empty
350   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
351
352   /// Finds a shape by attribute if it is possible
353   /// \param theAttribute an attribute
354   /// \return a geom shape
355   virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
356
357   /// Finds an attribute by geom shape if it is possible
358   /// \param theObject an object of the attribute
359   /// \param theGeomShape a geom shape
360   /// \return theAttribute
361   virtual AttributePtr findAttribute(const ObjectPtr& theObject,
362                                      const GeomShapePtr& theGeomShape) = 0;
363
364   /// Returns reentrant message if it was accepted
365   virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
366
367   /// Put current selection into reentrant message
368   /// \param theMessage a message of reentrant operation
369   virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
370
371   /// Returns XML information by the feature index
372   /// \param theFeatureId a feature id
373   /// \param theXmlCfg XML configuration
374   /// \param theDescription feature description
375   void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
376                             std::string& theDescription);
377
378   /// Returns root tree node which represents a data model
379   virtual ModuleBase_ITreeNode* rootNode() const = 0;
380
381 signals:
382   /// Segnal emitted when an operation is resumed
383   /// \param theOp a resumed operation
384   void resumed(ModuleBase_Operation* theOp);
385
386 public slots:
387   /// Called on call of command corresponded to a feature
388   virtual void onFeatureTriggered();
389
390   /// Slot called on object display
391   /// \param theObject a data object
392   /// \param theAIS a presentation object
393   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
394
395   /// Slot called on before object erase
396   /// \param theObject a data object
397   /// \param theAIS a presentation object
398   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
399
400 protected slots:
401   /// Called on selection changed event
402   virtual void onSelectionChanged() {}
403
404 protected:
405  /// Register validators for this module
406   virtual void registerValidators() {}
407
408   /// Register properties of this module
409   virtual void registerProperties() {}
410
411   /// Returns new instance of operation object (used in createOperation for customization)
412   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
413
414 protected:
415   /// Reference to workshop
416   ModuleBase_IWorkshop* myWorkshop;
417
418   /// Map of features in XML
419   std::map<std::string, std::string> myFeaturesInFiles;
420 };
421
422
423
424 //! This function must return a new module instance.
425 extern "C" {
426 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
427 }
428
429 #define CREATE_MODULE "createModule"
430
431 #endif //ModuleBase_IModule