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