Salome HOME
2.5. Select the point of a sketch entity must display the editing point panel
[modules/shaper.git] / src / ModuleBase / ModuleBase_IModule.h
1  // Copyright (C) 2014-20xx CEA/DEN, EDF R&D\r
2 \r
3 #ifndef ModuleBase_IModule_H\r
4 #define ModuleBase_IModule_H\r
5 \r
6 #include "ModuleBase.h"\r
7 #include "ModuleBase_IWorkshop.h"\r
8 \r
9 #include <ModelAPI_Feature.h>\r
10 #include <ModelAPI_Attribute.h>\r
11 \r
12 #include <GeomAPI_Shape.h>\r
13 #include <GeomAPI_ICustomPrs.h>\r
14 \r
15 #include <QString>\r
16 #include <QObject>\r
17 #include <QMap>\r
18 #include <QList>\r
19 \r
20 #include <string>\r
21 #include <vector>\r
22 #include <map>\r
23 \r
24 class QAction;\r
25 class QMouseEvent;\r
26 class QKeyEvent;\r
27 class QMenu;\r
28 class Config_WidgetAPI;\r
29 class ModuleBase_ModelWidget;\r
30 class ModuleBase_Operation;\r
31 class ModuleBase_IWorkshop;\r
32 \r
33 /**\r
34  * \ingroup GUI\r
35  * Interface to a module\r
36  */\r
37 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject\r
38 {\r
39   Q_OBJECT\r
40  public:\r
41   /// enumeration to know which objects should be customized\r
42   enum ModuleBase_CustomizeFlag {\r
43     CustomizeArguments = 0, /// references of other objects referenced to the current feature\r
44     CustomizeResults, /// results of the current feature\r
45     CustomizeHighlightedObjects /// highlighted objects of the active widget\r
46   };\r
47 \r
48    /// Constructor\r
49    /// \param theParent instance of workshop interface\r
50    ModuleBase_IModule(ModuleBase_IWorkshop* theParent);\r
51 \r
52   virtual ~ModuleBase_IModule() {}\r
53 \r
54   /// Add default selection filters of the module to the current viewer\r
55   virtual void activateSelectionFilters() {};\r
56 \r
57   /// Remove default selection filters of the module from the current viewer\r
58   virtual void deactivateSelectionFilters() {};\r
59 \r
60   /// Reads description of features from XML file \r
61   virtual void createFeatures();\r
62 \r
63   /// Called on creation of menu item in desktop\r
64   virtual void actionCreated(QAction*);\r
65 \r
66   /// Launching of a edit operation on the feature \r
67   /// \param theFeature feature for editing\r
68   virtual void editFeature(FeaturePtr theFeature);\r
69 \r
70   /// Creates an operation and send it to loop\r
71   /// \param theCmdId the operation name\r
72   virtual void launchOperation(const QString& theCmdId);\r
73 \r
74   /// Realizes some functionality by an operation start\r
75   /// \param theOperation a started operation\r
76   virtual void operationStarted(ModuleBase_Operation* theOperation) {}\r
77 \r
78   /// Realizes some functionality by an operation resume\r
79   /// By default it emits operationResumed signal\r
80   /// \param theOperation a resumed operation\r
81   virtual void operationResumed(ModuleBase_Operation* theOperation);\r
82 \r
83   /// Realizes some functionality by an operation stop\r
84   virtual void operationStopped(ModuleBase_Operation* theOperation) {}\r
85 \r
86   /// Realizes some functionality by an operation commit\r
87   virtual void operationCommitted(ModuleBase_Operation* theOperation) {}\r
88 \r
89   /// Realizes some functionality by an operation abort\r
90   virtual void operationAborted(ModuleBase_Operation* theOperation) {}\r
91 \r
92   /// Realizes some functionality by an operation start\r
93   virtual ModuleBase_Operation* currentOperation() const = 0;\r
94 \r
95   /// Add menu items for viewer into the given menu\r
96   /// \param theMenu a popup menu to be shown in the viewer\r
97   /// \param theStdActions a map of standard actions\r
98   /// \return true if items are added and there is no necessity to provide standard menu\r
99   virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }\r
100 \r
101   /// Add menu items for object browser into the given menu\r
102   /// \param theMenu a popup menu to be shown in the object browser\r
103   virtual void addObjectBrowserMenu(QMenu* theMenu) const {};\r
104 \r
105   /// Creates custom widgets for property panel\r
106   /// \param theType a type of widget\r
107   /// \param theParent the parent object\r
108   /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from\r
109   /// \param theParentId is Id of a parent of the current attribute\r
110   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
111                                       Config_WidgetAPI* theWidgetApi, std::string theParentId)\r
112   {\r
113     return 0;\r
114   }\r
115 \r
116   /// Returns the active widget, by default it is the property panel active widget\r
117   virtual ModuleBase_ModelWidget* activeWidget() const = 0;\r
118 \r
119   /// Returns current workshop\r
120   ModuleBase_IWorkshop* workshop() const { return myWorkshop; }\r
121 \r
122   /// Call back forlast tuning of property panel before operation performance\r
123   /// It is called as on clearing of property panel as on filling with new widgets\r
124   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}\r
125 \r
126   /// Have an opportunity to create widgets for the current operation instead of standard creation in workshop\r
127   /// \param theOperation a started operation\r
128   /// \param theWidgets a list of created widgets\r
129   /// \return boolean result, false by default\r
130   virtual bool createWidgets(ModuleBase_Operation* theOperation,\r
131                              QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }\r
132 \r
133   //! Returns True if there are available Undos and there is not an active operation\r
134   virtual bool canUndo() const;\r
135 \r
136   //! Returns True if there are available Redos and there is not an active operation\r
137   virtual bool canRedo() const;\r
138 \r
139   /// Returns true if the action can be applyed to the object\r
140   /// \param theObject a checked object\r
141   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"\r
142   /// \return the a boolean result\r
143   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;\r
144 \r
145   /// Returns True if the current operation can be committed. By default it is true.\r
146   /// \return a boolean value\r
147   //virtual bool canCommitOperation() const;\r
148 \r
149   /// Returns whether the object can be erased. The default realization returns true.\r
150   /// \param theObject a model object\r
151   virtual bool canEraseObject(const ObjectPtr& theObject) const;\r
152 \r
153   /// Returns whether the object can be displayed. The default realization returns true.\r
154   /// \param theObject a model object\r
155   virtual bool canDisplayObject(const ObjectPtr& theObject) const;\r
156 \r
157   /// Make some functionality after the objects are hidden in viewer\r
158   /// \param theObjects a list of hidden objects\r
159   virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};\r
160 \r
161   /// Returns true if selection for the object can be activate.\r
162   /// By default a result or feature of the current operation can not be activated\r
163   /// \param theObject a model object\r
164   virtual bool canActivateSelection(const ObjectPtr& theObject) const;\r
165 \r
166   /// Reacts to the delete action in module\r
167   /// \returns true if the action is processed\r
168   virtual bool deleteObjects() { return false; };\r
169 \r
170   /// Performs functionality on closing document\r
171   virtual void closeDocument() = 0;\r
172 \r
173   /// Clears specific presentations in the viewer\r
174   virtual void clearViewer() = 0;\r
175 \r
176   /// Returns a list of modes, where the AIS objects should be activated\r
177   /// \param theModes a list of modes\r
178   virtual void activeSelectionModes(QIntList& theModes) {}\r
179 \r
180   /// Activate custom presentation for the object. Default realization is empty.\r
181   /// \param theObject an object instance\r
182   /// \param theFlag a flag of level of customization, which means that only part of sub-elements\r
183   /// \param theUpdateViewer the parameter whether the viewer should be update immediately\r
184   virtual void activateCustomPrs(const FeaturePtr& theFeature,\r
185                                  const ModuleBase_CustomizeFlag& theFlag,\r
186                                  const bool theUpdateViewer) {}\r
187 \r
188   /// Deactivate custom presentation for the object. Default realization is empty.\r
189   /// \param theFlag a flag of level of customization, which means that only part of sub-elements\r
190   /// \param theUpdateViewer the parameter whether the viewer should be update immediately\r
191   virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,\r
192                                    const bool theUpdateViewer) {}\r
193 \r
194   /// Modifies the given presentation in the custom way.\r
195   virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,\r
196                                      GeomCustomPrsPtr theCustomPrs) { return false; };\r
197 \r
198   /// Update the object presentable properties such as color, lines width and other\r
199   /// If the object is result with the color attribute value set, it is used,\r
200   /// otherwise the customize is applyed to the object's feature if it is a custom prs\r
201   /// \param theObject an object instance\r
202   /// \param theFlag a flag of level of customization, which means that only part of sub-elements\r
203   /// should be updated(e.g. only highlighted elements)\r
204   /// \param theUpdateViewer the parameter whether the viewer should be update immediately\r
205   /// \returns true if the object is modified\r
206   virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,\r
207                                const bool theUpdateViewer);\r
208 \r
209   /// This method is called on object browser creation for customization of module specific features\r
210   /// \param theObjectBrowser a pinter on Object Browser widget\r
211   virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}\r
212 \r
213   /// Creates a new operation\r
214   /// \param theCmdId the operation name\r
215   virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);\r
216 \r
217   /// Sends the operation for launching\r
218   /// \param theOperation the operation\r
219   virtual void sendOperation(ModuleBase_Operation* theOperation);\r
220 \r
221   //! Returns data object by AIS\r
222   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;\r
223 \r
224   /// Update state of pop-up menu items in object browser\r
225   /// \param theStdActions - a map of standard actions\r
226   virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}\r
227 \r
228   /// Update state of pop-up menu items in viewer\r
229   /// \param theStdActions - a map of standard actions\r
230   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}\r
231 \r
232   //! Returns the feature error if the current state of the feature in the module is not correct\r
233   //! If the feature is correct, it returns an empty value\r
234   //! \return string value\r
235   virtual QString getFeatureError(const FeaturePtr& theFeature);\r
236 \r
237   /// Returns list of granted operation indices\r
238   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;\r
239 \r
240   /// Connects or disconnects to the value changed signal of the property panel widgets\r
241   /// \param theWidget a property contol widget\r
242   /// \param isToConnect a boolean value whether connect or disconnect\r
243   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};\r
244 \r
245   /// Validates the operation to change the "Apply" button state.\r
246   /// \param thePreviousState the previous state of the widget\r
247   virtual void widgetStateChanged(int thePreviousState) {};\r
248 \r
249   /// Returns true if the event is processed.\r
250   /// \param thePreviousAttributeID an index of the previous active attribute\r
251   virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };\r
252 \r
253   /// Performs some GUI actions after an operation transaction is opened\r
254   /// Default realization is empty\r
255   virtual void beforeOperationStarted(ModuleBase_Operation* theOperation) {};\r
256 \r
257   /// Performs some GUI actions before an operation transaction is stopped\r
258   /// Default realization is empty\r
259   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};\r
260 \r
261   /// Finds a shape by attribute if it is possible\r
262   /// \param theAttribute an attribute\r
263   /// \return a geom shape\r
264   virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;\r
265 \r
266   /// Finds an attribute by geom shape if it is possible\r
267   /// \param theObject an object of the attribute\r
268   /// \param theGeomShape a geom shape\r
269   /// \return theAttribute\r
270   virtual AttributePtr findAttribute(const ObjectPtr& theObject,\r
271                                      const GeomShapePtr& theGeomShape) = 0;\r
272 \r
273   /// Returns XML information by the feature index\r
274   /// \param theFeatureId a feature id\r
275   /// \param theXmlCfg XML configuration\r
276   /// \param theDescription feature description\r
277   void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,\r
278                             std::string& theDescription);\r
279 \r
280 signals:\r
281   /// Signal which is emitted when operation is launched\r
282   void operationLaunched();\r
283 \r
284   /// Segnal emitted when an operation is resumed\r
285   /// \param theOp a resumed operation\r
286   void resumed(ModuleBase_Operation* theOp);\r
287 \r
288 public slots:\r
289   /// Called on call of command corresponded to a feature\r
290   virtual void onFeatureTriggered();\r
291 \r
292   /// Slot called on object display\r
293   /// \param theObject a data object\r
294   /// \param theAIS a presentation object\r
295   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
296 \r
297   /// Slot called on before object erase\r
298   /// \param theObject a data object\r
299   /// \param theAIS a presentation object\r
300   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
301 \r
302 protected slots:\r
303   /// Called on selection changed event\r
304   virtual void onSelectionChanged() {}\r
305 \r
306  protected:\r
307   /// Register validators for this module\r
308   virtual void registerValidators() {}\r
309 \r
310   /// Register selection filters for this module\r
311   virtual void registerFilters() {}\r
312 \r
313   /// Register properties of this module\r
314   virtual void registerProperties() {}\r
315 \r
316   /// Returns new instance of operation object (used in createOperation for customization)\r
317   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);\r
318 \r
319 protected:\r
320   /// Reference to workshop\r
321   ModuleBase_IWorkshop* myWorkshop;\r
322 \r
323   /// Map of features in XML\r
324   std::map<std::string, std::string> myFeaturesInFiles;\r
325 };\r
326 \r
327 \r
328 \r
329 //! This function must return a new module instance.\r
330 extern "C" {\r
331 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);\r
332 }\r
333 \r
334 #define CREATE_MODULE "createModule"\r
335 \r
336 #endif //ModuleBase_IModule\r