Salome HOME
Display all objects on document opening
[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
142   void showPropertyPanel();
143   void hidePropertyPanel();
144   void showObjectBrowser();
145   void hideObjectBrowser();
146
147   void onFeatureTriggered();
148   void changeCurrentDocument(ObjectPtr theObj);
149
150   void activateLastPart();
151
152 protected:
153   //Event-loop processing methods:
154   void addFeature(const Config_FeatureMessage*);
155   void connectWithOperation(ModuleBase_Operation* theOperation);
156   void saveDocument(QString theName);
157
158   void onFeatureUpdatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg);
159   void onFeatureCreatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg);
160   void onFeatureRedisplayMsg(const ModelAPI_ObjectUpdatedMessage* theMsg);
161   void onObjectDeletedMsg(const ModelAPI_ObjectDeletedMessage* theMsg);
162
163   QList<QAction*> getModuleCommands() const;
164
165   void displayAllResults();
166   void displayDocumentResults(DocumentPtr theDoc);
167   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
168
169 protected slots:
170   /// SLOT, that is called after the operation is started. Update workshop state according to
171   /// the started operation, e.g. visualizes the property panel and connect to it.
172   void onOperationStarted();
173   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
174   /// hides the property panel and udpate the command status.
175   /// \param theOpertion a stopped operation
176   void onOperationStopped(ModuleBase_Operation* theOperation);
177
178   void onContextMenuCommand(const QString& theId, bool isChecked);
179
180   void onWidgetValuesChanged();
181
182 private:
183   void initMenu();
184
185   void registerValidators() const;
186
187
188   ModuleBase_IModule* loadModule(const QString& theModule);
189   bool activateModule();
190
191   QDockWidget* createObjectBrowser(QWidget* theParent);
192   QDockWidget* createPropertyPanel(QWidget* theParent);
193
194   // Creates Dock widgets: Object browser and Property panel
195   void createDockWidgets();
196
197   XGUI_MainWindow* myMainWindow;
198   ModuleBase_IModule* myModule;
199   XGUI_ObjectsBrowser* myObjectBrowser;
200   XGUI_PropertyPanel* myPropertyPanel;
201   XGUI_SelectionMgr* mySelector;
202   XGUI_Displayer* myDisplayer;
203   XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
204   XGUI_ActionsMgr* myActionsMgr;
205   XGUI_SalomeConnector* mySalomeConnector;
206   XGUI_ErrorDialog* myErrorDlg;
207   XGUI_ViewerProxy* myViewerProxy;
208   XGUI_ContextMenuMgr* myContextMenuMgr;
209   XGUI_ModuleConnector* myModuleConnector;
210
211   QString myCurrentDir;
212   static QMap<QString, QString> myIcons;
213
214 };
215
216 #endif