Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_Workshop.h
1 #ifndef XGUI_WORKSHOP_H
2 #define XGUI_WORKSHOP_H
3
4 #include "XGUI.h"
5 #include "XGUI_Constants.h"
6 #include <Events_Listener.h>
7 #include <ModuleBase_Definitions.h>
8 #include <ModelAPI_ResultPart.h>
9 #include <ModelAPI_Document.h>
10
11 #include <QObject>
12 #include <QMap>
13 #include <QIcon>
14 #include <QKeySequence>
15
16
17 class XGUI_MainWindow;
18 class XGUI_Command;
19 class XGUI_Workbench;
20 class XGUI_SelectionMgr;
21 class XGUI_Displayer;
22 class XGUI_OperationMgr;
23 class XGUI_SalomeConnector;
24 class XGUI_ObjectsBrowser;
25 class XGUI_ActionsMgr;
26 class XGUI_ErrorDialog;
27 class XGUI_SalomeViewer;
28 class XGUI_ViewerProxy;
29 class XGUI_PropertyPanel;
30 class XGUI_ContextMenuMgr;
31 class XGUI_ModuleConnector;
32
33 class ModuleBase_Operation;
34 class ModuleBase_IModule;
35
36 class Config_FeatureMessage;
37 class Config_PointerMessage;
38
39 class QWidget;
40 class QDockWidget;
41
42 class ModelAPI_ObjectUpdatedMessage;
43 class ModelAPI_ObjectDeletedMessage;
44 class QAction;
45
46 /**\class XGUI_Workshop
47  * \ingroup GUI
48  * \brief Class which defines a configuration of the application (Workshop) and launches it.
49  */
50 class XGUI_EXPORT XGUI_Workshop: public QObject, public Events_Listener
51 {
52 Q_OBJECT
53 public:
54
55   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
56   virtual ~XGUI_Workshop();
57
58   //! Starting of the application
59   void startApplication();
60
61   //! Returns main window (Desktop) of the application
62   XGUI_MainWindow* mainWindow() const
63   {
64     return myMainWindow;
65   }
66
67   //! Returns selection manager object
68   XGUI_SelectionMgr* selector() const { return mySelector; }
69
70   //! Returns displayer
71   XGUI_Displayer* displayer() const { return myDisplayer; }
72
73   //! ! Returns operation manager.
74   XGUI_OperationMgr* operationMgr() const { return myOperationMgr; }
75
76   //! ! Returns an actions manager
77   XGUI_ActionsMgr* actionsMgr() const { return myActionsMgr; };
78
79   //! Returns property panel widget
80   XGUI_PropertyPanel* propertyPanel() const { return myPropertyPanel; }
81
82   //! Returns context menu manager object
83   XGUI_ContextMenuMgr* contextMenuMgr() const { return myContextMenuMgr; }
84
85   //! Creates and adds a new workbench (menu group) with the given name and returns it
86   XGUI_Workbench* addWorkbench(const QString& theName);
87
88   //! Redefinition of Events_Listener method
89   virtual void processEvent(const Events_Message* theMessage);
90
91   //! Returns an object which provides interface to Salome Module (LightApp_Module)
92   XGUI_SalomeConnector* salomeConnector() const { return mySalomeConnector; }
93
94   //! Provides an object which provides interface to Salome Viewer
95   XGUI_SalomeViewer* salomeViewer() const;
96
97   //! Returns true if the application works as SALOME module
98   bool isSalomeMode() const { return mySalomeConnector != 0; }
99
100   //! Returns Object browser
101   XGUI_ObjectsBrowser* objectBrowser() const { return myObjectBrowser; }
102
103   void salomeViewerSelectionChanged();
104
105   XGUI_ViewerProxy* viewer() const { return myViewerProxy; }
106
107   /// Returns the module connectory
108   /// \returns the instance of connector
109   XGUI_ModuleConnector* moduleConnector() const { return myModuleConnector; }
110
111   //! Returns icon name according to feature Id
112   static QString featureIcon(const std::string& theId);
113
114   //! Activates or deactivates a part
115   //! If PartPtr is Null pointer then PartSet will be activated
116   void activatePart(ResultPartPtr theFeature);
117
118   //! Delete features
119   void deleteObjects(const QList<ObjectPtr>& theList);
120
121   //! Show the given features in 3d Viewer
122   void showObjects(const QList<ObjectPtr>& theList, bool isVisible);
123
124   ModuleBase_IModule* module() const { return myModule; }
125
126 signals:
127   void salomeViewerSelection();
128   void errorOccurred(const QString&);
129
130 public slots:
131   void updateCommandStatus();
132   void updateCommandsOnViewSelection();
133
134   void onNew();
135   void onOpen();
136   bool onSave();
137   bool onSaveAs();
138   void onExit();
139   void onUndo();
140   void onRedo();
141   void onPreferences();
142
143   void showPropertyPanel();
144   void hidePropertyPanel();
145   void showObjectBrowser();
146   void hideObjectBrowser();
147
148   void onFeatureTriggered();
149   void changeCurrentDocument(ObjectPtr theObj);
150
151   void activateLastPart();
152
153 protected:
154   //Event-loop processing methods:
155   void addFeature(const Config_FeatureMessage*);
156   void connectWithOperation(ModuleBase_Operation* theOperation);
157   void saveDocument(QString theName);
158
159   void onFeatureUpdatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg);
160   void onFeatureCreatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg);
161   void onFeatureRedisplayMsg(const ModelAPI_ObjectUpdatedMessage* theMsg);
162   void onObjectDeletedMsg(const ModelAPI_ObjectDeletedMessage* theMsg);
163
164   QList<QAction*> getModuleCommands() const;
165
166   void displayAllResults();
167   void displayDocumentResults(DocumentPtr theDoc);
168   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
169
170 protected slots:
171   /// SLOT, that is called after the operation is started. Update workshop state according to
172   /// the started operation, e.g. visualizes the property panel and connect to it.
173   void onOperationStarted();
174   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
175   /// hides the property panel and udpate the command status.
176   /// \param theOpertion a stopped operation
177   void onOperationStopped(ModuleBase_Operation* theOperation);
178
179   void onContextMenuCommand(const QString& theId, bool isChecked);
180
181   void onWidgetValuesChanged();
182
183   void onStartWaiting();
184
185 private:
186   void initMenu();
187
188   void registerValidators() const;
189
190
191   ModuleBase_IModule* loadModule(const QString& theModule);
192   bool activateModule();
193
194   QDockWidget* createObjectBrowser(QWidget* theParent);
195   QDockWidget* createPropertyPanel(QWidget* theParent);
196
197   // Creates Dock widgets: Object browser and Property panel
198   void createDockWidgets();
199
200   XGUI_MainWindow* myMainWindow;
201   ModuleBase_IModule* myModule;
202   XGUI_ObjectsBrowser* myObjectBrowser;
203   XGUI_PropertyPanel* myPropertyPanel;
204   XGUI_SelectionMgr* mySelector;
205   XGUI_Displayer* myDisplayer;
206   XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
207   XGUI_ActionsMgr* myActionsMgr;
208   XGUI_SalomeConnector* mySalomeConnector;
209   XGUI_ErrorDialog* myErrorDlg;
210   XGUI_ViewerProxy* myViewerProxy;
211   XGUI_ContextMenuMgr* myContextMenuMgr;
212   XGUI_ModuleConnector* myModuleConnector;
213
214   QString myCurrentDir;
215   static QMap<QString, QString> myIcons;
216 };
217
218 #endif