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