Salome HOME
7ba5cfe1e09693d931618d6f73c189f268fdc02e
[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 intrface\r
38    ModuleBase_IModule(ModuleBase_IWorkshop* theParent);\r
39 \r
40   virtual ~ModuleBase_IModule() {}\r
41 \r
42   /// Reads description of features from XML file \r
43   virtual void createFeatures();\r
44 \r
45   /// Called on creation of menu item in desktop\r
46   virtual void actionCreated(QAction*);\r
47 \r
48   /// Launching of a edit operation on the feature \r
49   /// \param theFeature feature for editing\r
50   virtual void editFeature(FeaturePtr theFeature);\r
51 \r
52   /// Creates an operation and send it to loop\r
53   /// \param theCmdId the operation name\r
54   virtual void launchOperation(const QString& theCmdId);\r
55 \r
56   /// Realizes some functionality by an operation start\r
57   /// \param theOperation a started operation\r
58   virtual void operationStarted(ModuleBase_Operation* theOperation) {}\r
59 \r
60   /// Realizes some functionality by an operation resume\r
61   /// \param theOperation a resumed operation\r
62   virtual void operationResumed(ModuleBase_Operation* theOperation) {}\r
63 \r
64   /// Realizes some functionality by an operation stop\r
65   virtual void operationStopped(ModuleBase_Operation* theOperation) {}\r
66 \r
67   /// Realizes some functionality by an operation commit\r
68   virtual void operationCommitted(ModuleBase_Operation* theOperation) {}\r
69 \r
70   /// Realizes some functionality by an operation abort\r
71   virtual void operationAborted(ModuleBase_Operation* theOperation) {}\r
72 \r
73   /// Realizes some functionality by an operation start\r
74   /// \param theOperation a started operation\r
75   virtual ModuleBase_Operation* currentOperation() const = 0;\r
76 \r
77   /// Add menu atems for viewer into the given menu\r
78   /// \param theMenu a popup menu to be shown in the viewer\r
79   /// \param theStdActions a map of standard actions\r
80   /// \return true if items are added and there is no necessity to provide standard menu\r
81   virtual bool addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }\r
82 \r
83   /// Add menu atems for object browser into the given menu\r
84   /// \param theMenu a popup menu to be shown in the object browser\r
85   virtual void addObjectBrowserItems(QMenu* theMenu) const {};\r
86 \r
87   /// Called when it is necessary to update a command state (enable or disable it)\r
88   //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;\r
89 \r
90   /// Creates custom widgets for property panel\r
91   /// \param theType a type of widget\r
92   /// \param theParent the parent object\r
93   /// \param theWidgetApi the widget configuation. The attribute of the model widget is obtained from\r
94   /// \param theParentId is Id of a parent of the current attribute\r
95   /// \param theModelWidgets list of widget objects\r
96   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
97                                       Config_WidgetAPI* theWidgetApi, std::string theParentId)\r
98   {\r
99     return 0;\r
100   }\r
101 \r
102   /// Returns current workshop\r
103   ModuleBase_IWorkshop* workshop() const { return myWorkshop; }\r
104 \r
105   /// Call back forlast tuning of property panel before operation performance\r
106   /// It is called as on clearing of property panel as on filling with new widgets\r
107   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}\r
108 \r
109   //! Returns True if there are available Undos and there is not an active operation\r
110   virtual bool canUndo() const;\r
111 \r
112   //! Returns True if there are available Redos and there is not an active operation\r
113   virtual bool canRedo() const;\r
114 \r
115   /// Returns whether the object can be displayed. The default realization returns true.\r
116   /// \param theObject a model object\r
117   virtual bool canDisplayObject(const ObjectPtr& theObject) const;\r
118 \r
119   /// Reacts to the delete action in module\r
120   /// \returns true if the action is processed\r
121   virtual bool deleteObjects() { return false; };\r
122 \r
123 public slots:\r
124   /// Called on call of command corresponded to a feature\r
125   void onFeatureTriggered();\r
126 \r
127   /// Slolt called on object display\r
128   /// \param theObject a data object\r
129   /// \param theAIS a presentation object\r
130   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
131 \r
132   /// Slot called on before object erase\r
133   /// \param theObject a data object\r
134   /// \param theAIS a presentation object\r
135   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
136 \r
137 protected slots:\r
138   /// Called on selection changed event\r
139   virtual void onSelectionChanged() {}\r
140 \r
141  protected:\r
142   /// Sends the operation for launching\r
143   /// \param theOperation the operation\r
144   virtual void sendOperation(ModuleBase_Operation* theOperation);\r
145 \r
146   /// Creates a new operation\r
147   /// \param theCmdId the operation name\r
148   virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);\r
149 \r
150   /// Register validators for this module\r
151   virtual void registerValidators() {}\r
152 \r
153   /// Register selection filters for this module\r
154   virtual void registerFilters() {}\r
155 \r
156   /// Register properties of this module\r
157   virtual void registerProperties() {}\r
158 \r
159   /// Returns new instance of operation object (used in createOperation for customization)\r
160   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);\r
161 \r
162 protected:\r
163 \r
164   /// Reference to workshop\r
165   ModuleBase_IWorkshop* myWorkshop;\r
166 \r
167   /// Map of features in XML\r
168   std::map<std::string, std::string> myFeaturesInFiles;\r
169 };\r
170 \r
171 \r
172 \r
173 //! This function must return a new module instance.\r
174 extern "C" {\r
175 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);\r
176 }\r
177 \r
178 #define CREATE_MODULE "createModule"\r
179 \r
180 #endif //ModuleBase_IModule\r