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