]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Workshop.h
Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / XGUI / XGUI_Workshop.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef XGUI_WORKSHOP_H
4 #define XGUI_WORKSHOP_H
5
6 #include "XGUI.h"
7 //#include "XGUI_Constants.h"
8 #include <Events_Listener.h>
9 #include <ModuleBase_Definitions.h>
10 #include <ModelAPI_Document.h>
11 #include <ModelAPI_Feature.h>
12
13 #include <QObject>
14 #include <QMap>
15 #include <QKeySequence>
16 #include <QIcon>
17
18 class AppElements_MainWindow;
19 class AppElements_Command;
20 class AppElements_Workbench;
21
22 class XGUI_SelectionMgr;
23 class XGUI_Displayer;
24 class XGUI_OperationMgr;
25 class XGUI_SalomeConnector;
26 class XGUI_ObjectsBrowser;
27 class XGUI_ActionsMgr;
28 class XGUI_ErrorDialog;
29 class XGUI_SalomeViewer;
30 class XGUI_ViewerProxy;
31 class XGUI_PropertyPanel;
32 class XGUI_ContextMenuMgr;
33 class XGUI_ModuleConnector;
34
35 class ModuleBase_Operation;
36 class ModuleBase_IModule;
37 class ModuleBase_IViewer;
38
39 class Config_FeatureMessage;
40 class Config_PointerMessage;
41
42 class QWidget;
43 class QDockWidget;
44
45 class ModelAPI_ObjectUpdatedMessage;
46 class ModelAPI_ObjectDeletedMessage;
47 class ModelAPI_ResultPart;
48 class QAction;
49
50 /**\class XGUI_Workshop
51  * \ingroup GUI
52  * \brief Class which defines a configuration of the application (Workshop) and launches it.
53  */
54 class XGUI_EXPORT XGUI_Workshop : public QObject, public Events_Listener
55 {
56 Q_OBJECT
57  public:
58
59   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
60   virtual ~XGUI_Workshop();
61
62   //! Starting of the application
63   void startApplication();
64
65   //! Returns main window (Desktop) of the application
66   AppElements_MainWindow* mainWindow() const
67   {
68     return myMainWindow;
69   }
70
71   //! Returns selection manager object
72   XGUI_SelectionMgr* selector() const
73   {
74     return mySelector;
75   }
76
77   //! Returns displayer
78   XGUI_Displayer* displayer() const
79   {
80     return myDisplayer;
81   }
82
83   //! ! Returns operation manager.
84   XGUI_OperationMgr* operationMgr() const
85   {
86     return myOperationMgr;
87   }
88
89   //! ! Returns an actions manager
90   XGUI_ActionsMgr* actionsMgr() const
91   {
92     return myActionsMgr;
93   }
94
95   //! Returns property panel widget
96   XGUI_PropertyPanel* propertyPanel() const
97   {
98     return myPropertyPanel;
99   }
100
101   //! Returns context menu manager object
102   XGUI_ContextMenuMgr* contextMenuMgr() const
103   {
104     return myContextMenuMgr;
105   }
106
107   //! Creates and adds a new workbench (menu group) with the given name and returns it
108   AppElements_Workbench* addWorkbench(const QString& theName);
109
110   //! Redefinition of Events_Listener method
111   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
112
113   //! Returns an object which provides interface to Salome Module (LightApp_Module)
114   XGUI_SalomeConnector* salomeConnector() const
115   {
116     return mySalomeConnector;
117   }
118
119   //! Provides an object which provides interface to Salome Viewer
120   ModuleBase_IViewer* salomeViewer() const;
121
122   //! Returns true if the application works as SALOME module
123   bool isSalomeMode() const
124   {
125     return mySalomeConnector != 0;
126   }
127
128   //! Returns Object browser
129   XGUI_ObjectsBrowser* objectBrowser() const
130   {
131     return myObjectBrowser;
132   }
133
134   void salomeViewerSelectionChanged();
135
136   XGUI_ViewerProxy* viewer() const
137   {
138     return myViewerProxy;
139   }
140
141   /// Returns the module connectory
142   /// \returns the instance of connector
143   XGUI_ModuleConnector* moduleConnector() const
144   {
145     return myModuleConnector;
146   }
147
148   //! Returns icon name according to feature
149   static QIcon featureIcon(const FeaturePtr& theFeature);
150
151   //! Activates or deactivates a part
152   //! If PartPtr is Null pointer then PartSet will be activated
153   void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
154
155   //! Delete features
156   void deleteObjects(const QObjectPtrList& theList);
157
158   //! Show the given features in 3d Viewer
159   void showObjects(const QObjectPtrList& theList, bool isVisible);
160
161   //! Show the given features in 3d Viewer
162   void showOnlyObjects(const QObjectPtrList& theList);
163
164   void setDisplayMode(const QObjectPtrList& theList, int theMode);
165
166   ModuleBase_IModule* module() const
167   {
168     return myModule;
169   }
170
171   /// Returns current directory whic contains data files
172   QString currentDataDir() const { return myCurrentDir; }
173
174   /// Returns current directory whic contains data files
175   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
176
177   /**
178   * Save the current document into a directory
179   * \param theName - path to the directory
180   * \param theFileNames - returned file names created in this directory
181   */
182   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
183
184   /*
185    * If there is an active (uncommited) operation shows a prompt to abort it
186    * and performs abortion if user agreed. Returns true if
187    * - operation aborted successfully
188    * - there is no active operation
189    */
190   bool isActiveOperationAborted();
191
192 signals:
193   void salomeViewerSelection();
194   void errorOccurred(const QString&);
195
196  public slots:
197   void updateCommandStatus();
198
199   void onNew();
200   void onOpen();
201   bool onSave();
202   bool onSaveAs();
203   void onExit();
204   void onUndo();
205   void onRedo();
206   void onRebuild();
207   void onPreferences();
208
209   void showPropertyPanel();
210   void hidePropertyPanel();
211   void showObjectBrowser();
212   void hideObjectBrowser();
213
214   void onFeatureTriggered();
215   void changeCurrentDocument(ObjectPtr theObj);
216
217   void activateLastPart();
218
219   void closeDocument();
220
221  protected:
222   // Find the nested features and set them into the operation
223   // \param theOperation an operation
224   void setNestedFeatures(ModuleBase_Operation* theOperation);
225   // Update the property panel content by the XML description of the operation and set the panel
226   // into the operation
227   // \param theOperation an operation
228   void setPropertyPanel(ModuleBase_Operation* theOperation);
229
230   bool event(QEvent * theEvent);
231   //Event-loop processing methods:
232   void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
233   void connectWithOperation(ModuleBase_Operation* theOperation);
234
235   void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
236   void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
237   void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
238   void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg);
239
240   void validateOperation(const QString& theOperationId);
241
242   void displayAllResults();
243   void displayDocumentResults(DocumentPtr theDoc);
244   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
245
246  private slots:
247   /// SLOT, that is called after the operation is started. Update workshop state according to
248   /// the started operation, e.g. visualizes the property panel and connect to it.
249   /// \param theOpertion a started operation
250   void onOperationStarted(ModuleBase_Operation* theOperation);
251
252   /// SLOT, that is called after the operation is resumed. Update workshop state according to
253   /// the started operation, e.g. visualizes the property panel and connect to it.
254   /// \param theOpertion a resumed operation
255   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
256
257   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
258   /// hides the property panel and udpate the command status.
259   /// \param theOpertion a stopped operation
260   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
261
262   /// SLOT, that is called after the operation is committed.
263   /// \param theOpertion a commmitted operation
264   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
265
266   /// SLOT, that is called after the operation is aborted.
267   /// \param theOpertion an aborted operation
268   void onOperationAborted(ModuleBase_Operation* theOperation);
269
270   void onContextMenuCommand(const QString& theId, bool isChecked);
271
272   void onWidgetValuesChanged();
273
274   void onStartWaiting();
275
276  private:
277   void initMenu();
278
279   void registerValidators() const;
280
281   ModuleBase_IModule* loadModule(const QString& theModule);
282   bool activateModule();
283
284   QDockWidget* createObjectBrowser(QWidget* theParent);
285   QDockWidget* createPropertyPanel(QWidget* theParent);
286
287   // Creates Dock widgets: Object browser and Property panel
288   void createDockWidgets();
289
290   AppElements_MainWindow* myMainWindow;
291   ModuleBase_IModule* myModule;
292   XGUI_ObjectsBrowser* myObjectBrowser;
293   XGUI_PropertyPanel* myPropertyPanel;
294   XGUI_SelectionMgr* mySelector;
295   XGUI_Displayer* myDisplayer;
296   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
297   XGUI_ActionsMgr* myActionsMgr;
298   XGUI_SalomeConnector* mySalomeConnector;
299   XGUI_ErrorDialog* myErrorDlg;
300   XGUI_ViewerProxy* myViewerProxy;
301   XGUI_ContextMenuMgr* myContextMenuMgr;
302   XGUI_ModuleConnector* myModuleConnector;
303
304   QString myCurrentDir;
305   static QMap<QString, QString> myIcons;
306
307   bool myUpdatePrefs;
308
309   // Flag to check that part document is in process of activating
310   bool myPartActivating;
311 };
312
313 #endif