Salome HOME
Issue #2204 Display a sketch plane - highlight only source plane, do not create wrapp...
[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 <QString>
36 #include <QObject>
37 #include <QMap>
38 #include <QList>
39
40 #include <string>
41 #include <vector>
42 #include <map>
43
44 class QAction;
45 class QMouseEvent;
46 class QKeyEvent;
47 class QMenu;
48 class Config_WidgetAPI;
49 class ModuleBase_ModelWidget;
50 class ModuleBase_Operation;
51 class ModuleBase_ViewerPrs;
52
53 class ModuleBase_IWorkshop;
54 class ModelAPI_Result;
55 class Events_Message;
56
57 class AIS_InteractiveObject;
58
59 /**
60  * \ingroup GUI
61  * Interface to a module
62  */
63 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
64 {
65   Q_OBJECT
66  public:
67   /// enumeration to know which objects should be customized
68   enum ModuleBase_CustomizeFlag {
69     CustomizeArguments = 0, /// references of other objects referenced to the current feature
70     CustomizeResults, /// results of the current feature
71     CustomizeHighlightedObjects /// highlighted objects of the active widget
72   };
73
74    /// Constructor
75    /// \param theParent instance of workshop interface
76    ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
77
78   virtual ~ModuleBase_IModule() {}
79
80   /// Add default selection filters of the module to the current viewer
81   virtual void activateSelectionFilters() {}
82
83   /// Remove default selection filters of the module from the current viewer
84   virtual void deactivateSelectionFilters() {}
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 theOperation a started operation
177   /// \param theWidgets a list of created widgets
178   /// \return boolean result, false by default
179   virtual bool createWidgets(ModuleBase_Operation* theOperation,
180                              QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
181
182   //! Returns True if there are available Undos and there is not an active operation
183   virtual bool canUndo() const;
184
185   //! Returns True if there are available Redos and there is not an active operation
186   virtual bool canRedo() const;
187
188   /// Returns true if the action can be applyed to the object
189   /// \param theObject a checked object
190   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
191   /// \return the a boolean result
192   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
193
194   /// Returns True if the current operation can be committed. By default it is true.
195   /// \return a boolean value
196   //virtual bool canCommitOperation() const;
197
198   /// Returns whether the object can be erased. The default realization returns true.
199   /// \param theObject a model object
200   virtual bool canEraseObject(const ObjectPtr& theObject) const;
201
202   /// Returns whether the object can be displayed. The default realization returns true.
203   /// \param theObject a model object
204   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
205
206   /// Returns whether the started operation may use preselection of the previous one
207   /// Cases are: previous operation is null, edit operation, previuos and started operations
208   /// kinds are the same
209   /// \param thePreviousOperationKind a kind of previous operation
210   /// \param theStartedOperationKind a kind of a started operation
211   virtual bool canUsePreselection(const QString& thePreviousOperationKind,
212                                   const QString& theStartedOperationKind);
213
214   /// Make some functionality after the objects are hidden in viewer
215   /// \param theObjects a list of hidden objects
216   //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
217
218   /// Returns true if selection for the object can be activate.
219   /// By default a result or feature of the current operation can not be activated
220   /// \param theObject a model object
221   virtual bool canActivateSelection(const ObjectPtr& theObject) const;
222
223   /// Reacts to the delete action in module
224   /// \returns true if the action is processed
225   virtual bool deleteObjects() { return false; };
226
227   /// Performs functionality on closing document
228   virtual void closeDocument() = 0;
229
230   /// Clears specific presentations in the viewer
231   virtual void clearViewer() = 0;
232
233   /// Returns a list of modes, where the AIS objects should be activated
234   /// \param theModes a list of modes
235   virtual void activeSelectionModes(QIntList& theModes) {}
236
237   /// Appends specific selection modes for the module to the list of types
238   /// \param theTypes a selection modes to be extended
239   virtual void customSubShapesSelectionModes(QIntList& theTypes) {}
240
241   /// Return true if the custom presentation is activated
242   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
243   /// \return boolean value
244   virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
245   { return false; };
246
247   /// Activate custom presentation for the object. Default realization is empty.
248   /// \param theFeature a feature instance
249   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
250   /// \param theUpdateViewer the parameter whether the viewer should be update immediately
251   virtual void activateCustomPrs(const FeaturePtr& theFeature,
252                                  const ModuleBase_CustomizeFlag& theFlag,
253                                  const bool theUpdateViewer) {}
254
255   /// Deactivate custom presentation for the object. Default realization is empty.
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 deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
259                                    const bool theUpdateViewer) {}
260
261   /// Modifies the given presentation in the custom way.
262   virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
263                                      AISObjectPtr thePrs,
264                                      GeomCustomPrsPtr theCustomPrs) { return false; };
265
266   /// Modifies the given presentation in the custom way after usual customize is performed.
267   virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
268                                      AISObjectPtr thePrs,
269                                      GeomCustomPrsPtr theCustomPrs) { return false; };
270
271   /// Update the object presentable properties such as color, lines width and other
272   /// If the object is result with the color attribute value set, it is used,
273   /// otherwise the customize is applyed to the object's feature if it is a custom prs
274   /// \param theObject an object instance
275   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
276   /// should be updated(e.g. only highlighted elements)
277   /// \param theUpdateViewer the parameter whether the viewer should be update immediately
278   /// \returns true if the object is modified
279   virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
280                                const bool theUpdateViewer);
281
282   /// This method is called on object browser creation for customization of module specific features
283   /// \param theObjectBrowser a pinter on Object Browser widget
284   virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
285
286   /// Creates a new operation
287   /// \param theCmdId the operation name
288   virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
289
290   /// Create specific for the module presentation
291   /// \param theResult an object for presentation
292   /// \return created presentation or NULL(default value)
293   virtual Handle(AIS_InteractiveObject) createPresentation(
294                            const std::shared_ptr<ModelAPI_Result>& theResult);
295
296   //! Returns data object by AIS
297   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
298
299   //! Returns true if the presentation can be shown in shading mode
300   //! \param theAIS presentation to be checked
301   //! \return boolean value
302   virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
303
304   /// Update state of pop-up menu items in object browser
305   /// \param theStdActions - a map of standard actions
306   virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
307
308   /// Update state of pop-up menu items in viewer
309   /// \param theStdActions - a map of standard actions
310   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
311
312   /// Returns true if the action should be always enabled
313   /// \param theActionId an action index: Accept or Accept All
314   /// \return boolean value
315   virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
316
317   //! Returns the feature error if the current state of the feature in the module is not correct
318   //! If the feature is correct, it returns an empty value
319   //! \return string value
320   virtual QString getFeatureError(const FeaturePtr& theFeature);
321
322   /// Returns list of granted operation indices
323   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
324
325   /// Connects or disconnects to the value changed signal of the property panel widgets
326   /// \param theWidget a property contol widget
327   /// \param isToConnect a boolean value whether connect or disconnect
328   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
329
330   /// Validates the operation to change the "Apply" button state.
331   /// \param thePreviousState the previous state of the widget
332   virtual void widgetStateChanged(int thePreviousState) {};
333
334   /// Returns true if the event is processed.
335   /// \param thePreviousAttributeID an index of the previous active attribute
336   virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
337
338   /// Performs some GUI actions before an operation transaction is stopped
339   /// Default realization is empty
340   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
341
342   /// Finds a shape by attribute if it is possible
343   /// \param theAttribute an attribute
344   /// \return a geom shape
345   virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
346
347   /// Finds an attribute by geom shape if it is possible
348   /// \param theObject an object of the attribute
349   /// \param theGeomShape a geom shape
350   /// \return theAttribute
351   virtual AttributePtr findAttribute(const ObjectPtr& theObject,
352                                      const GeomShapePtr& theGeomShape) = 0;
353
354   /// Returns reentrant message if it was accepted
355   virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
356
357   /// Put current selection into reentrant message
358   /// \param theMessage a message of reentrant operation
359   virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
360
361   /// Returns XML information by the feature index
362   /// \param theFeatureId a feature id
363   /// \param theXmlCfg XML configuration
364   /// \param theDescription feature description
365   void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
366                             std::string& theDescription);
367
368 signals:
369   /// Signal which is emitted when operation is launched
370   void operationLaunched();
371
372   /// Segnal emitted when an operation is resumed
373   /// \param theOp a resumed operation
374   void resumed(ModuleBase_Operation* theOp);
375
376 public slots:
377   /// Called on call of command corresponded to a feature
378   virtual void onFeatureTriggered();
379
380   /// Slot called on object display
381   /// \param theObject a data object
382   /// \param theAIS a presentation object
383   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
384
385   /// Slot called on before object erase
386   /// \param theObject a data object
387   /// \param theAIS a presentation object
388   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
389
390 protected slots:
391   /// Called on selection changed event
392   virtual void onSelectionChanged() {}
393
394 protected:
395  /// Register validators for this module
396   virtual void registerValidators() {}
397
398   /// Register properties of this module
399   virtual void registerProperties() {}
400
401   /// Returns new instance of operation object (used in createOperation for customization)
402   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
403
404 protected:
405   /// Reference to workshop
406   ModuleBase_IWorkshop* myWorkshop;
407
408   /// Map of features in XML
409   std::map<std::string, std::string> myFeaturesInFiles;
410 };
411
412
413
414 //! This function must return a new module instance.
415 extern "C" {
416 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
417 }
418
419 #define CREATE_MODULE "createModule"
420
421 #endif //ModuleBase_IModule