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