Salome HOME
Fix for crash and invisible bodies on Debian Squeeze SALOME version.
[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_Document.h>
9
10 #include <QObject>
11 #include <QMap>
12 #include <QIcon>
13 #include <QKeySequence>
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 class ModuleBase_IViewer;
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 ModelAPI_ResultPart;
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
69   {
70     return mySelector;
71   }
72
73   //! Returns displayer
74   XGUI_Displayer* displayer() const
75   {
76     return myDisplayer;
77   }
78
79   //! ! Returns operation manager.
80   XGUI_OperationMgr* operationMgr() const
81   {
82     return myOperationMgr;
83   }
84
85   //! ! Returns an actions manager
86   XGUI_ActionsMgr* actionsMgr() const
87   {
88     return myActionsMgr;
89   }
90   ;
91
92   //! Returns property panel widget
93   XGUI_PropertyPanel* propertyPanel() const
94   {
95     return myPropertyPanel;
96   }
97
98   //! Returns context menu manager object
99   XGUI_ContextMenuMgr* contextMenuMgr() const
100   {
101     return myContextMenuMgr;
102   }
103
104   //! Creates and adds a new workbench (menu group) with the given name and returns it
105   XGUI_Workbench* addWorkbench(const QString& theName);
106
107   //! Redefinition of Events_Listener method
108   virtual void processEvent(const boost::shared_ptr<Events_Message>& theMessage);
109
110   //! Returns an object which provides interface to Salome Module (LightApp_Module)
111   XGUI_SalomeConnector* salomeConnector() const
112   {
113     return mySalomeConnector;
114   }
115
116   //! Provides an object which provides interface to Salome Viewer
117   ModuleBase_IViewer* salomeViewer() const;
118
119   //! Returns true if the application works as SALOME module
120   bool isSalomeMode() const
121   {
122     return mySalomeConnector != 0;
123   }
124
125   //! Returns Object browser
126   XGUI_ObjectsBrowser* objectBrowser() const
127   {
128     return myObjectBrowser;
129   }
130
131   void salomeViewerSelectionChanged();
132
133   XGUI_ViewerProxy* viewer() const
134   {
135     return myViewerProxy;
136   }
137
138   /// Returns the module connectory
139   /// \returns the instance of connector
140   XGUI_ModuleConnector* moduleConnector() const
141   {
142     return myModuleConnector;
143   }
144
145   //! Returns icon name according to feature Id
146   static QString featureIcon(const std::string& theId);
147
148   //! Activates or deactivates a part
149   //! If PartPtr is Null pointer then PartSet will be activated
150   void activatePart(boost::shared_ptr<ModelAPI_ResultPart> theFeature);
151
152   //! Delete features
153   void deleteObjects(const QList<ObjectPtr>& theList);
154
155   //! Show the given features in 3d Viewer
156   void showObjects(const QList<ObjectPtr>& theList, bool isVisible);
157
158   //! Show the given features in 3d Viewer
159   void showOnlyObjects(const QList<ObjectPtr>& theList);
160
161   void setDisplayMode(const QList<ObjectPtr>& theList, int theMode);
162
163   ModuleBase_IModule* module() const
164   {
165     return myModule;
166   }
167
168   /// Returns current directory whic contains data files
169   QString currentDataDir() const { return myCurrentDir; }
170
171   /// Returns current directory whic contains data files
172   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
173
174   /**
175   * Save the current document into a directory
176   * \param theName - path to the directory
177   * \param theFileNames - returned file names created in this directory
178   */
179   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
180
181   /*
182    * If there is an active (uncommited) operation shows a prompt to abort it
183    * and performs abortion if user agreed. Returns true if
184    * - operation aborted successfully
185    * - there is no active operation
186    */
187   bool isActiveOperationAborted();
188
189 signals:
190   void salomeViewerSelection();
191   void errorOccurred(const QString&);
192
193  public slots:
194   void updateCommandStatus();
195   void updateCommandsOnViewSelection();
196
197   void onNew();
198   void onOpen();
199   bool onSave();
200   bool onSaveAs();
201   void onExit();
202   void onUndo();
203   void onRedo();
204   void onRebuild();
205   void onPreferences();
206
207   void showPropertyPanel();
208   void hidePropertyPanel();
209   void showObjectBrowser();
210   void hideObjectBrowser();
211
212   void onFeatureTriggered();
213   void changeCurrentDocument(ObjectPtr theObj);
214
215   void activateLastPart();
216
217   void closeDocument();
218
219  protected:
220   bool event(QEvent * theEvent);
221   //Event-loop processing methods:
222   void addFeature(const boost::shared_ptr<Config_FeatureMessage>&);
223   void connectWithOperation(ModuleBase_Operation* theOperation);
224
225   void onFeatureUpdatedMsg(const boost::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
226   void onFeatureCreatedMsg(const boost::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
227   void onFeatureRedisplayMsg(const boost::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
228   void onObjectDeletedMsg(const boost::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg);
229
230   void validateOperation(const QString& theOperationId);
231
232   QList<QAction*> getModuleCommands() const;
233
234   void displayAllResults();
235   void displayDocumentResults(DocumentPtr theDoc);
236   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
237
238  private slots:
239   /// SLOT, that is called after the operation is started. Update workshop state according to
240   /// the started operation, e.g. visualizes the property panel and connect to it.
241   void onOperationStarted();
242   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
243   /// hides the property panel and udpate the command status.
244   /// \param theOpertion a stopped operation
245   void onOperationStopped(ModuleBase_Operation* theOperation);
246
247   void onContextMenuCommand(const QString& theId, bool isChecked);
248
249   void onWidgetValuesChanged();
250
251   void onStartWaiting();
252
253  private:
254   void initMenu();
255
256   void registerValidators() const;
257
258   ModuleBase_IModule* loadModule(const QString& theModule);
259   bool activateModule();
260
261   QDockWidget* createObjectBrowser(QWidget* theParent);
262   QDockWidget* createPropertyPanel(QWidget* theParent);
263
264   // Creates Dock widgets: Object browser and Property panel
265   void createDockWidgets();
266
267   XGUI_MainWindow* myMainWindow;
268   ModuleBase_IModule* myModule;
269   XGUI_ObjectsBrowser* myObjectBrowser;
270   XGUI_PropertyPanel* myPropertyPanel;
271   XGUI_SelectionMgr* mySelector;
272   XGUI_Displayer* myDisplayer;
273   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
274   XGUI_ActionsMgr* myActionsMgr;
275   XGUI_SalomeConnector* mySalomeConnector;
276   XGUI_ErrorDialog* myErrorDlg;
277   XGUI_ViewerProxy* myViewerProxy;
278   XGUI_ContextMenuMgr* myContextMenuMgr;
279   XGUI_ModuleConnector* myModuleConnector;
280
281   QString myCurrentDir;
282   static QMap<QString, QString> myIcons;
283
284   bool myUpdatePrefs;
285
286   // Flag to check that part document is in process of activating
287   bool myPartActivating;
288 };
289
290 #endif