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