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