Salome HOME
Add tools
[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 \r
11 #include <QString>\r
12 #include <QObject>\r
13 #include <QMap>\r
14 \r
15 #include <string>\r
16 #include <map>\r
17 \r
18 class QAction;\r
19 class QMouseEvent;\r
20 class QKeyEvent;\r
21 class QMenu;\r
22 class Config_WidgetAPI;\r
23 class ModuleBase_ModelWidget;\r
24 class ModuleBase_Operation;\r
25 class ModuleBase_IWorkshop;\r
26 class ModuleBase_IDocumentDataModel;\r
27 \r
28 /**\r
29  * \ingroup GUI\r
30  * Interface to a module\r
31  */\r
32 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject\r
33 {\r
34   Q_OBJECT\r
35  public:\r
36 \r
37    /// Constructor\r
38    /// \param theParent instance of workshop interface\r
39    ModuleBase_IModule(ModuleBase_IWorkshop* theParent);\r
40 \r
41   virtual ~ModuleBase_IModule() {}\r
42 \r
43   // Add default selection filters of the module to the current viewer\r
44   virtual void activateSelectionFilters() {};\r
45 \r
46   // Remove default selection filters of the module from the current viewer\r
47   virtual void deactivateSelectionFilters() {};\r
48 \r
49   /// Reads description of features from XML file \r
50   virtual void createFeatures();\r
51 \r
52   /// Called on creation of menu item in desktop\r
53   virtual void actionCreated(QAction*);\r
54 \r
55   /// Launching of a edit operation on the feature \r
56   /// \param theFeature feature for editing\r
57   virtual void editFeature(FeaturePtr theFeature);\r
58 \r
59   /// Creates an operation and send it to loop\r
60   /// \param theCmdId the operation name\r
61   virtual void launchOperation(const QString& theCmdId);\r
62 \r
63   /// Realizes some functionality by an operation start\r
64   /// \param theOperation a started operation\r
65   virtual void onOperationStarted(ModuleBase_Operation* theOperation) {}\r
66 \r
67   /// Realizes some functionality by an operation resume\r
68   /// By default it emits operationResumed signal\r
69   /// \param theOperation a resumed operation\r
70   virtual void onOperationResumed(ModuleBase_Operation* theOperation);\r
71 \r
72   /// Realizes some functionality by an operation stop\r
73   virtual void onOperationStopped(ModuleBase_Operation* theOperation) {}\r
74 \r
75   /// Realizes some functionality by an operation commit\r
76   virtual void onOperationCommitted(ModuleBase_Operation* theOperation) {}\r
77 \r
78   /// Realizes some functionality by an operation abort\r
79   virtual void onOperationAborted(ModuleBase_Operation* theOperation) {}\r
80 \r
81   /// Realizes some functionality by an operation start\r
82   /// \param theOperation a started operation\r
83   virtual ModuleBase_Operation* currentOperation() const = 0;\r
84 \r
85   /// Add menu items for viewer into the given menu\r
86   /// \param theMenu a popup menu to be shown in the viewer\r
87   /// \param theStdActions a map of standard actions\r
88   /// \return true if items are added and there is no necessity to provide standard menu\r
89   virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }\r
90 \r
91   /// Add menu items for object browser into the given menu\r
92   /// \param theMenu a popup menu to be shown in the object browser\r
93   virtual void addObjectBrowserMenu(QMenu* theMenu) const {};\r
94 \r
95   /// Called when it is necessary to update a command state (enable or disable it)\r
96   //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;\r
97 \r
98   /// Creates custom widgets for property panel\r
99   /// \param theType a type of widget\r
100   /// \param theParent the parent object\r
101   /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from\r
102   /// \param theParentId is Id of a parent of the current attribute\r
103   /// \param theModelWidgets list of widget objects\r
104   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
105                                       Config_WidgetAPI* theWidgetApi, std::string theParentId)\r
106   {\r
107     return 0;\r
108   }\r
109 \r
110   /// Returns current workshop\r
111   ModuleBase_IWorkshop* workshop() const { return myWorkshop; }\r
112 \r
113   /// Call back forlast tuning of property panel before operation performance\r
114   /// It is called as on clearing of property panel as on filling with new widgets\r
115   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}\r
116 \r
117   //! Returns True if there are available Undos and there is not an active operation\r
118   virtual bool canUndo() const;\r
119 \r
120   //! Returns True if there are available Redos and there is not an active operation\r
121   virtual bool canRedo() const;\r
122 \r
123   /// Returns true if the action can be applyed to the object\r
124   /// \param theObject a checked object\r
125   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"\r
126   /// \return the a boolean result\r
127   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;\r
128 \r
129   /// Returns True if the current operation can be committed. By default it is true.\r
130   /// \return a boolean value\r
131   virtual bool canCommitOperation() const;\r
132 \r
133   /// Returns whether the object can be erased. The default realization returns true.\r
134   /// \param theObject a model object\r
135   virtual bool canEraseObject(const ObjectPtr& theObject) const;\r
136 \r
137   /// Returns whether the object can be displayed. The default realization returns true.\r
138   /// \param theObject a model object\r
139   virtual bool canDisplayObject(const ObjectPtr& theObject) const;\r
140 \r
141   /// Returns true if selection for the object can be activate.\r
142   /// By default a result or feature of the current operation can not be activated\r
143   /// \param theObject a model object\r
144   virtual bool canActivateSelection(const ObjectPtr& theObject) const;\r
145 \r
146   /// Reacts to the delete action in module\r
147   /// \returns true if the action is processed\r
148   virtual bool deleteObjects() { return false; };\r
149 \r
150 #ifdef ModuleDataModel\r
151   /// Returns data model object for representation of data tree in Object browser\r
152   virtual ModuleBase_IDocumentDataModel* dataModel() const = 0;\r
153 #endif\r
154 \r
155   /// Performs functionality on closing document\r
156   virtual void closeDocument() = 0;\r
157 \r
158   /// Clears specific presentations in the viewer\r
159   virtual void clearViewer() = 0;\r
160 \r
161   /// Returns a list of modes, where the AIS objects should be activated\r
162   /// \param theModes a list of modes\r
163   virtual void activeSelectionModes(QIntList& theModes) {}\r
164 \r
165   /** Update the object presentable properties such as color, lines width and other\r
166   * If the object is result with the color attribute value set, it is used,\r
167   * otherwise the customize is applyed to the object's feature if it is a custom prs\r
168   * \param theObject an object instance\r
169   * \param theUpdateViewer the parameter whether the viewer should be update immediately\r
170   * \returns true if the object is modified\r
171   */\r
172   virtual bool customizeObject(ObjectPtr theObject, const bool theUpdateViewer);\r
173 \r
174   /// This method is called on object browser creation for customization of module specific features\r
175   /// \param theObjectBrowser a pinter on Object Browser widget\r
176   virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}\r
177 \r
178   /// Creates a new operation\r
179   /// \param theCmdId the operation name\r
180   virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);\r
181 \r
182   /// Sends the operation for launching\r
183   /// \param theOperation the operation\r
184   virtual void sendOperation(ModuleBase_Operation* theOperation);\r
185 \r
186   //! Returns data object by AIS\r
187   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;\r
188 \r
189   /// Update state of pop-up menu items in object browser\r
190   /// \param theStdActions - a map of standard actions\r
191   virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}\r
192 \r
193   /// Update state of pop-up menu items in viewer\r
194   /// \param theStdActions - a map of standard actions\r
195   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}\r
196 \r
197   //! Returns the feature error if the current state of the feature in the module is not correct\r
198   //! If the feature is correct, it returns an empty value\r
199   //! \return string value\r
200   virtual QString getFeatureError(const FeaturePtr& theFeature);\r
201 \r
202 signals:\r
203   void operationLaunched();\r
204 \r
205   void operationResumed(ModuleBase_Operation* theOp);\r
206 \r
207 public slots:\r
208   /// Called on call of command corresponded to a feature\r
209   virtual void onFeatureTriggered();\r
210 \r
211   /// Slot called on object display\r
212   /// \param theObject a data object\r
213   /// \param theAIS a presentation object\r
214   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
215 \r
216   /// Slot called on before object erase\r
217   /// \param theObject a data object\r
218   /// \param theAIS a presentation object\r
219   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
220 \r
221 protected slots:\r
222   /// Called on selection changed event\r
223   virtual void onSelectionChanged() {}\r
224 \r
225  protected:\r
226   /// Register validators for this module\r
227   virtual void registerValidators() {}\r
228 \r
229   /// Register selection filters for this module\r
230   virtual void registerFilters() {}\r
231 \r
232   /// Register properties of this module\r
233   virtual void registerProperties() {}\r
234 \r
235   /// Returns new instance of operation object (used in createOperation for customization)\r
236   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);\r
237 \r
238 protected:\r
239 \r
240   /// Reference to workshop\r
241   ModuleBase_IWorkshop* myWorkshop;\r
242 \r
243   /// Map of features in XML\r
244   std::map<std::string, std::string> myFeaturesInFiles;\r
245 };\r
246 \r
247 \r
248 \r
249 //! This function must return a new module instance.\r
250 extern "C" {\r
251 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);\r
252 }\r
253 \r
254 #define CREATE_MODULE "createModule"\r
255 \r
256 #endif //ModuleBase_IModule\r