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