]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_IModule.h
Salome HOME
Imrove multi-selector control to provide items multi-selection. Division of the opera...
[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 \r
27 /**\r
28  * \ingroup GUI\r
29  * Interface to a module\r
30  */\r
31 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject\r
32 {\r
33   Q_OBJECT\r
34  public:\r
35   /// enumeration to know which objects should be customized\r
36   enum ModuleBase_CustomizeFlag {\r
37     CustomizeDependedAndResults = 0x00000000,\r
38     CustomizeHighlightedObjects = 0x00000001\r
39   };\r
40 \r
41    /// Constructor\r
42    /// \param theParent instance of workshop interface\r
43    ModuleBase_IModule(ModuleBase_IWorkshop* theParent);\r
44 \r
45   virtual ~ModuleBase_IModule() {}\r
46 \r
47   /// Add default selection filters of the module to the current viewer\r
48   virtual void activateSelectionFilters() {};\r
49 \r
50   /// Remove default selection filters of the module from the current viewer\r
51   virtual void deactivateSelectionFilters() {};\r
52 \r
53   /// Reads description of features from XML file \r
54   virtual void createFeatures();\r
55 \r
56   /// Called on creation of menu item in desktop\r
57   virtual void actionCreated(QAction*);\r
58 \r
59   /// Launching of a edit operation on the feature \r
60   /// \param theFeature feature for editing\r
61   virtual void editFeature(FeaturePtr theFeature);\r
62 \r
63   /// Creates an operation and send it to loop\r
64   /// \param theCmdId the operation name\r
65   virtual void launchOperation(const QString& theCmdId);\r
66 \r
67   /// Realizes some functionality by an operation start\r
68   /// \param theOperation a started operation\r
69   virtual void operationStarted(ModuleBase_Operation* theOperation) {}\r
70 \r
71   /// Realizes some functionality by an operation resume\r
72   /// By default it emits operationResumed signal\r
73   /// \param theOperation a resumed operation\r
74   virtual void operationResumed(ModuleBase_Operation* theOperation);\r
75 \r
76   /// Realizes some functionality by an operation stop\r
77   virtual void operationStopped(ModuleBase_Operation* theOperation) {}\r
78 \r
79   /// Realizes some functionality by an operation commit\r
80   virtual void operationCommitted(ModuleBase_Operation* theOperation) {}\r
81 \r
82   /// Realizes some functionality by an operation abort\r
83   virtual void operationAborted(ModuleBase_Operation* theOperation) {}\r
84 \r
85   /// Realizes some functionality by an operation start\r
86   virtual ModuleBase_Operation* currentOperation() const = 0;\r
87 \r
88   /// Add menu items for viewer into the given menu\r
89   /// \param theMenu a popup menu to be shown in the viewer\r
90   /// \param theStdActions a map of standard actions\r
91   /// \return true if items are added and there is no necessity to provide standard menu\r
92   virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }\r
93 \r
94   /// Add menu items for object browser into the given menu\r
95   /// \param theMenu a popup menu to be shown in the object browser\r
96   virtual void addObjectBrowserMenu(QMenu* theMenu) const {};\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   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
104                                       Config_WidgetAPI* theWidgetApi, std::string theParentId)\r
105   {\r
106     return 0;\r
107   }\r
108 \r
109   /// Returns the active widget, by default it is the property panel active widget\r
110   virtual ModuleBase_ModelWidget* activeWidget() const = 0;\r
111 \r
112   /// Returns current workshop\r
113   ModuleBase_IWorkshop* workshop() const { return myWorkshop; }\r
114 \r
115   /// Call back forlast tuning of property panel before operation performance\r
116   /// It is called as on clearing of property panel as on filling with new widgets\r
117   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}\r
118 \r
119   //! Returns True if there are available Undos and there is not an active operation\r
120   virtual bool canUndo() const;\r
121 \r
122   //! Returns True if there are available Redos and there is not an active operation\r
123   virtual bool canRedo() const;\r
124 \r
125   /// Returns true if the action can be applyed to the object\r
126   /// \param theObject a checked object\r
127   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"\r
128   /// \return the a boolean result\r
129   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;\r
130 \r
131   /// Returns True if the current operation can be committed. By default it is true.\r
132   /// \return a boolean value\r
133   //virtual bool canCommitOperation() const;\r
134 \r
135   /// Returns whether the object can be erased. The default realization returns true.\r
136   /// \param theObject a model object\r
137   virtual bool canEraseObject(const ObjectPtr& theObject) const;\r
138 \r
139   /// Returns whether the object can be displayed. The default realization returns true.\r
140   /// \param theObject a model object\r
141   virtual bool canDisplayObject(const ObjectPtr& theObject) const;\r
142 \r
143   /// Returns true if selection for the object can be activate.\r
144   /// By default a result or feature of the current operation can not be activated\r
145   /// \param theObject a model object\r
146   virtual bool canActivateSelection(const ObjectPtr& theObject) const;\r
147 \r
148   /// Reacts to the delete action in module\r
149   /// \returns true if the action is processed\r
150   virtual bool deleteObjects() { return false; };\r
151 \r
152   /// Performs functionality on closing document\r
153   virtual void closeDocument() = 0;\r
154 \r
155   /// Clears specific presentations in the viewer\r
156   virtual void clearViewer() = 0;\r
157 \r
158   /// Returns a list of modes, where the AIS objects should be activated\r
159   /// \param theModes a list of modes\r
160   virtual void activeSelectionModes(QIntList& theModes) {}\r
161 \r
162   /** Update the object presentable properties such as color, lines width and other\r
163   * If the object is result with the color attribute value set, it is used,\r
164   * otherwise the customize is applyed to the object's feature if it is a custom prs\r
165   * \param theObject an object instance\r
166   * \param theFlag a flag of level of customization, which means that only part of sub-elements\r
167   * should be updated(e.g. only highlighted elements)\r
168   * \param theUpdateViewer the parameter whether the viewer should be update immediately\r
169   * \returns true if the object is modified\r
170   */\r
171   virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,\r
172                                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   /// Returns list of granted operation indices\r
203   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;\r
204 \r
205   /// Connects or disconnects to the value changed signal of the property panel widgets\r
206   /// \param theWidget a property contol widget\r
207   /// \param isToConnect a boolean value whether connect or disconnect\r
208   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};\r
209 \r
210   /// Validates the operation to change the "Apply" button state.\r
211   /// \param thePreviousState the previous state of the widget\r
212   virtual void widgetStateChanged(int thePreviousState) {};\r
213 \r
214   /// Returns true if the event is processed.\r
215   /// \param thePreviousAttributeID an index of the previous active attribute\r
216   virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };\r
217 \r
218   /// Performs some GUI actions after an operation transaction is opened\r
219   /// Default realization is empty\r
220   virtual void beforeOperationStarted(ModuleBase_Operation* theOperation) {};\r
221 \r
222   /// Performs some GUI actions before an operation transaction is stopped\r
223   /// Default realization is empty\r
224   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};\r
225 \r
226 signals:\r
227   /// Signal which is emitted when operation is launched\r
228   void operationLaunched();\r
229 \r
230   /// Segnal emitted when an operation is resumed\r
231   /// \param theOp a resumed operation\r
232   void resumed(ModuleBase_Operation* theOp);\r
233 \r
234 public slots:\r
235   /// Called on call of command corresponded to a feature\r
236   virtual void onFeatureTriggered();\r
237 \r
238   /// Slot called on object display\r
239   /// \param theObject a data object\r
240   /// \param theAIS a presentation object\r
241   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
242 \r
243   /// Slot called on before object erase\r
244   /// \param theObject a data object\r
245   /// \param theAIS a presentation object\r
246   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
247 \r
248 protected slots:\r
249   /// Called on selection changed event\r
250   virtual void onSelectionChanged() {}\r
251 \r
252  protected:\r
253   /// Register validators for this module\r
254   virtual void registerValidators() {}\r
255 \r
256   /// Register selection filters for this module\r
257   virtual void registerFilters() {}\r
258 \r
259   /// Register properties of this module\r
260   virtual void registerProperties() {}\r
261 \r
262   /// Returns new instance of operation object (used in createOperation for customization)\r
263   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);\r
264 \r
265 protected:\r
266 \r
267   /// Reference to workshop\r
268   ModuleBase_IWorkshop* myWorkshop;\r
269 \r
270   /// Map of features in XML\r
271   std::map<std::string, std::string> myFeaturesInFiles;\r
272 };\r
273 \r
274 \r
275 \r
276 //! This function must return a new module instance.\r
277 extern "C" {\r
278 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);\r
279 }\r
280 \r
281 #define CREATE_MODULE "createModule"\r
282 \r
283 #endif //ModuleBase_IModule\r