]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Workshop.h
Salome HOME
Update code documentation
[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   /// Constructor
59   /// \param theConnector a Salome connector object. 
60   /// Used only if the workshop is launched in Salome environment
61   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
62   virtual ~XGUI_Workshop();
63
64   //! Starting of the application
65   void startApplication();
66
67   //! Returns main window (Desktop) of the application
68   AppElements_MainWindow* mainWindow() const
69   {
70     return myMainWindow;
71   }
72
73   //! Returns selection manager object
74   XGUI_SelectionMgr* selector() const
75   {
76     return mySelector;
77   }
78
79   //! Returns displayer
80   XGUI_Displayer* displayer() const
81   {
82     return myDisplayer;
83   }
84
85   //! ! Returns operation manager.
86   XGUI_OperationMgr* operationMgr() const
87   {
88     return myOperationMgr;
89   }
90
91   //! ! Returns an actions manager
92   XGUI_ActionsMgr* actionsMgr() const
93   {
94     return myActionsMgr;
95   }
96
97   //! Returns property panel widget
98   XGUI_PropertyPanel* propertyPanel() const
99   {
100     return myPropertyPanel;
101   }
102
103   //! Returns context menu manager object
104   XGUI_ContextMenuMgr* contextMenuMgr() const
105   {
106     return myContextMenuMgr;
107   }
108
109   //! Creates and adds a new workbench (menu group) with the given name and returns it
110   AppElements_Workbench* addWorkbench(const QString& theName);
111
112   //! Redefinition of Events_Listener method
113   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
114
115   //! Returns an object which provides interface to Salome Module (LightApp_Module)
116   XGUI_SalomeConnector* salomeConnector() const
117   {
118     return mySalomeConnector;
119   }
120
121   //! Provides an object which provides interface to Salome Viewer
122   ModuleBase_IViewer* salomeViewer() const;
123
124   //! Returns true if the application works as SALOME module
125   bool isSalomeMode() const
126   {
127     return mySalomeConnector != 0;
128   }
129
130   //! Returns Object browser
131   XGUI_ObjectsBrowser* objectBrowser() const
132   {
133     return myObjectBrowser;
134   }
135
136   /// This method is called by Salome module when selection is changed
137   void salomeViewerSelectionChanged();
138
139   /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
140   XGUI_ViewerProxy* viewer() const
141   {
142     return myViewerProxy;
143   }
144
145   /// Returns the module connectory
146   /// \returns the instance of connector
147   XGUI_ModuleConnector* moduleConnector() const
148   {
149     return myModuleConnector;
150   }
151
152   //! Returns icon name according to feature
153   static QIcon featureIcon(const FeaturePtr& theFeature);
154
155   //! Activates or deactivates a part
156   //! If PartPtr is Null pointer then PartSet will be activated
157   void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
158
159   //! Delete features
160   void deleteObjects(const QObjectPtrList& theList);
161
162   //! Show the given features in 3d Viewer
163   void showObjects(const QObjectPtrList& theList, bool isVisible);
164
165   //! Show the given features in 3d Viewer
166   void showOnlyObjects(const QObjectPtrList& theList);
167
168   /// Set display mode for the given onjects
169   /// \param theList a list of displayed objects
170   /// \param theMode a mode to set (see \ref XGUI_Displayer)
171   void setDisplayMode(const QObjectPtrList& theList, int theMode);
172
173   /// Returns current module
174   ModuleBase_IModule* module() const
175   {
176     return myModule;
177   }
178
179   /// Returns current directory whic contains data files
180   QString currentDataDir() const { return myCurrentDir; }
181
182   /// Returns current directory whic contains data files
183   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
184
185   /**
186   * Save the current document into a directory
187   * \param theName - path to the directory
188   * \param theFileNames - returned file names created in this directory
189   */
190   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
191
192   /**
193    * If there is an active (uncommited) operation shows a prompt to abort it
194    * and performs abortion if user agreed. Returns true if
195    * - operation aborted successfully
196    * - there is no active operation
197    */
198   bool isActiveOperationAborted();
199
200 signals:
201   /// Emitted when selection happens in Salome viewer
202   void salomeViewerSelection();
203
204   /// Emitted when error in applivation happens
205   void errorOccurred(const QString&);
206
207   //! the signal about the workshop actions states are updated.
208   void commandStatusUpdated();
209
210   //! the application is started
211   void applicationStarted();
212
213  public slots:
214    /// Update of commands status
215   void updateCommandStatus();
216
217   /// Create a new dokument
218   void onNew();
219
220   /// Open document from file
221   void onOpen();
222
223   /// Save current document
224   bool onSave();
225
226   /// Save current document to a file selected by user
227   bool onSaveAs();
228
229   /// Exit application
230   void onExit();
231
232   /// Undo last command
233   void onUndo();
234
235   /// Redo previous command
236   void onRedo();
237
238   /// Rebuild data tree
239   void onRebuild();
240
241   /// Open preferences dialog box
242   void onPreferences();
243
244   /// Show property panel
245   void showPropertyPanel();
246
247   /// Hide property panel
248   void hidePropertyPanel();
249
250   /// Show object Browser
251   void showObjectBrowser();
252
253   /// Hide object Browser
254   void hideObjectBrowser();
255
256   /// Reaction on command call
257   void onFeatureTriggered();
258
259   /// Change active document
260   /// \param theObj a part object. If it is NULL then active document is a main document
261   void changeCurrentDocument(ObjectPtr theObj);
262
263   //void activateLastPart();
264
265   /// Close document
266   void closeDocument();
267
268  protected:
269   /// Find the nested features and set them into the operation
270   /// \param theOperation an operation
271   void setNestedFeatures(ModuleBase_Operation* theOperation);
272
273   /// Update the property panel content by the XML description of the operation and set the panel
274   /// into the operation
275   /// \param theOperation an operation
276   void setPropertyPanel(ModuleBase_Operation* theOperation);
277
278   /// Procedure to process postponed events
279   bool event(QEvent * theEvent);
280
281   //Event-loop processing methods:
282
283   /// Process event "Add a feature"
284   void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
285
286   /// Connect to operation signals
287   /// \param theOperation an operation
288   void connectWithOperation(ModuleBase_Operation* theOperation);
289
290   /// Process feature update message
291   void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
292
293   ///Process feature created message
294   void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
295
296   /// Process feature redisplay message
297   void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
298
299   /// Process feature delete message
300   void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& );
301
302   /// Display all results
303   void displayAllResults();
304
305   /// Displau results from document
306   /// \param theDoc a document
307   void displayDocumentResults(DocumentPtr theDoc);
308
309   /// Display results from a group
310   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
311
312  private slots:
313   /// SLOT, that is called after the operation is started. Update workshop state according to
314   /// the started operation, e.g. visualizes the property panel and connect to it.
315   /// \param theOpertion a started operation
316   void onOperationStarted(ModuleBase_Operation* theOperation);
317
318   /// SLOT, that is called after the operation is resumed. Update workshop state according to
319   /// the started operation, e.g. visualizes the property panel and connect to it.
320   /// \param theOpertion a resumed operation
321   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
322
323   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
324   /// hides the property panel and udpate the command status.
325   /// \param theOpertion a stopped operation
326   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
327
328   /// SLOT, that is called after the operation is committed.
329   /// \param theOpertion a commmitted operation
330   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
331
332   /// SLOT, that is called after the operation is aborted.
333   /// \param theOpertion an aborted operation
334   void onOperationAborted(ModuleBase_Operation* theOperation);
335
336   /// Process context menu command
337   /// \param theId id of the command
338   /// \param isChecked is checked flag
339   void onContextMenuCommand(const QString& theId, bool isChecked);
340
341   /// Processing of values changed in model widget
342   void onWidgetValuesChanged();
343
344   /// Set waiting cursor
345   void onStartWaiting();
346
347  private:
348    /// Init menu
349   void initMenu();
350
351   /// Register validators
352   void registerValidators() const;
353
354   /// Load module from external library
355   /// \param theModule name of the module
356   ModuleBase_IModule* loadModule(const QString& theModule);
357
358   /// Activate module
359   bool activateModule();
360
361   /// Create object browser widget
362   /// \param theParent a parent of widget
363   QDockWidget* createObjectBrowser(QWidget* theParent);
364
365   /// Create property panel widget
366   /// \param theParent a parent of widget
367   QDockWidget* createPropertyPanel(QWidget* theParent);
368
369   // Creates Dock widgets: Object browser and Property panel
370   void createDockWidgets();
371
372   /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
373   void displayObject(ObjectPtr theObj);
374
375 private:
376   AppElements_MainWindow* myMainWindow;
377   ModuleBase_IModule* myModule;
378   XGUI_ObjectsBrowser* myObjectBrowser;
379   XGUI_PropertyPanel* myPropertyPanel;
380   XGUI_SelectionMgr* mySelector;
381   XGUI_Displayer* myDisplayer;
382   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
383   XGUI_ActionsMgr* myActionsMgr;
384   XGUI_SalomeConnector* mySalomeConnector;
385   XGUI_ErrorDialog* myErrorDlg;
386   XGUI_ViewerProxy* myViewerProxy;
387   XGUI_ContextMenuMgr* myContextMenuMgr;
388   XGUI_ModuleConnector* myModuleConnector;
389
390   QString myCurrentDir;
391   static QMap<QString, QString> myIcons;
392
393   bool myUpdatePrefs;
394
395   // Flag to check that part document is in process of activating
396   bool myPartActivating;
397 };
398
399 #endif