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