Salome HOME
fccb8575dc8c40a51f9f05596e5391353538697c
[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   // Activates the module controls. Should be called after module creation
71   void activateModule();
72
73   // Deactivates the module controls. Should be called after module creation
74   void deactivateModule();
75
76   //! Returns main window (Desktop) of the application
77   AppElements_MainWindow* mainWindow() const
78   {
79     return myMainWindow;
80   }
81
82   //! Returns selection manager object
83   XGUI_SelectionMgr* selector() const
84   {
85     return mySelector;
86   }
87
88   //! Returns displayer
89   XGUI_Displayer* displayer() const
90   {
91     return myDisplayer;
92   }
93
94   //! ! Returns operation manager.
95   XGUI_OperationMgr* operationMgr() const
96   {
97     return myOperationMgr;
98   }
99
100   //! ! Returns an actions manager
101   XGUI_ActionsMgr* actionsMgr() const
102   {
103     return myActionsMgr;
104   }
105
106   //! Returns property panel widget
107   XGUI_PropertyPanel* propertyPanel() const
108   {
109     return myPropertyPanel;
110   }
111
112   //! Returns context menu manager object
113   XGUI_ContextMenuMgr* contextMenuMgr() const
114   {
115     return myContextMenuMgr;
116   }
117
118   //! Creates and adds a new workbench (menu group) with the given name and returns it
119   AppElements_Workbench* addWorkbench(const QString& theName);
120
121   //! Redefinition of Events_Listener method
122   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
123
124   //! Returns an object which provides interface to Salome Module (LightApp_Module)
125   XGUI_SalomeConnector* salomeConnector() const
126   {
127     return mySalomeConnector;
128   }
129
130   //! Provides an object which provides interface to Salome Viewer
131   ModuleBase_IViewer* salomeViewer() const;
132
133   //! Returns true if the application works as SALOME module
134   bool isSalomeMode() const
135   {
136     return mySalomeConnector != 0;
137   }
138
139   //! Returns Object browser
140   XGUI_ObjectsBrowser* objectBrowser() const
141   {
142     return myObjectBrowser;
143   }
144
145   /// This method is called by Salome module when selection is changed
146   void salomeViewerSelectionChanged();
147
148   /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
149   XGUI_ViewerProxy* viewer() const
150   {
151     return myViewerProxy;
152   }
153
154   /// Returns the module connectory
155   /// \returns the instance of connector
156   XGUI_ModuleConnector* moduleConnector() const
157   {
158     return myModuleConnector;
159   }
160
161   /// Returns a desktop
162   /// \return a desktop instance
163   QMainWindow* desktop() const;
164
165   //! Delete features
166   void deleteObjects();
167
168   //! Returns true if there is at least one selected body/construction/group result
169   //! \return boolean value
170   bool canChangeColor() const;
171
172   //! Change color of the features if it is possible
173   //! The operation is available for construction, body and group results
174   //! theObjects a list of selected objects
175   void changeColor(const QObjectPtrList& theObjects);
176
177   //! Show the given features in 3d Viewer
178   void showObjects(const QObjectPtrList& theList, bool isVisible);
179
180   //! Show the given features in 3d Viewer
181   void showOnlyObjects(const QObjectPtrList& theList);
182
183   /// Set display mode for the given onjects
184   /// \param theList a list of displayed objects
185   /// \param theMode a mode to set (see \ref XGUI_Displayer)
186   void setDisplayMode(const QObjectPtrList& theList, int theMode);
187
188   /// Returns current module
189   ModuleBase_IModule* module() const
190   {
191     return myModule;
192   }
193
194   /// Returns current directory whic contains data files
195   QString currentDataDir() const { return myCurrentDir; }
196
197   /// Returns current directory whic contains data files
198   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
199
200   /**
201   * Save the current document into a directory
202   * \param theName - path to the directory
203   * \param theFileNames - returned file names created in this directory
204   */
205   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
206
207   /**
208    * If there is an active (uncommited) operation shows a prompt to abort it
209    * and performs abortion if user agreed. Returns true if
210    * - operation aborted successfully
211    * - there is no active operation
212    */
213   bool isActiveOperationAborted();
214
215   //! Delete features. Delete the referenced features. There can be a question with a list of referenced
216   //! objects.
217   //! \param theList an objects to be deleted
218   //! \param theIgnoredFeatures a list of features to be ignored during delete
219   //! \param theParent a parent widget for the question message box
220   //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
221   //! objects features appear. If the user chose do not continue, the deletion is not performed
222   //! \return the success of the delete 
223   static bool deleteFeatures(const QObjectPtrList& theList,
224                              std::set<FeaturePtr> theIgnoredFeatures = std::set<FeaturePtr>(),
225                              QWidget* theParent = 0,
226                              const bool theAskAboutDeleteReferences = false);
227
228 signals:
229   /// Emitted when selection happens in Salome viewer
230   void salomeViewerSelection();
231
232   /// Emitted when error in applivation happens
233   void errorOccurred(const QString&);
234
235   //! the signal about the workshop actions states are updated.
236   void commandStatusUpdated();
237
238   //! the application is started
239   void applicationStarted();
240
241   //! Signal to update Undo history list
242   void updateUndoHistory(const QList<ActionInfo>&);
243
244   //! Signal to update Redo history list
245   void updateRedoHistory(const QList<ActionInfo>&);
246
247  public slots:
248    /// Update of commands status
249   void updateCommandStatus();
250
251   /// update history list (undo/redo commands)
252   void updateHistory();
253
254   /// Create a new dokument
255   void onNew();
256
257   /// Open document from file
258   void onOpen();
259
260   /// Save current document
261   bool onSave();
262
263   /// Save current document to a file selected by user
264   bool onSaveAs();
265
266   /// Exit application
267   void onExit();
268
269   /// Undo last command
270   void onUndo(int times = 1);
271
272   /// Redo previous command
273   void onRedo(int times = 1);
274
275   /// Rebuild data tree
276   void onRebuild();
277
278   /// Open preferences dialog box
279   void onPreferences();
280
281   /// Show property panel
282   void showPropertyPanel();
283
284   /// Hide property panel
285   void hidePropertyPanel();
286
287   /// Show object Browser
288   void showObjectBrowser();
289
290   /// Hide object Browser
291   void hideObjectBrowser();
292
293   /// Reaction on command call
294   //void onFeatureTriggered();
295
296   /// Close document
297   void closeDocument();
298
299  protected:
300   /// Find the nested features and set them into the operation
301   /// \param theOperation an operation
302   void setNestedFeatures(ModuleBase_Operation* theOperation);
303
304   /// Update the property panel content by the XML description of the operation and set the panel
305   /// into the operation
306   /// \param theOperation an operation
307   void setPropertyPanel(ModuleBase_Operation* theOperation);
308
309   /// Procedure to process postponed events
310   bool event(QEvent * theEvent);
311
312   //Event-loop processing methods:
313
314   /// Process event "Add a feature"
315   void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
316
317   /// Connect to operation signals
318   /// \param theOperation an operation
319   void connectWithOperation(ModuleBase_Operation* theOperation);
320
321   /// Process feature update message
322   void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
323
324   /// Process feature created message
325   void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
326
327   /// Process feature redisplay message
328   void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
329
330   /// Deactivates the object, if it is active and the module returns that the activation
331   /// of selection for the object is not possible currently(the current operation uses it)
332   /// \param theObject an object
333   /// \param theUpdateViewer a boolean flag to update viewer immediately
334   void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
335
336   /// Display all results
337   //void displayAllResults();
338
339   /// Displau results from document
340   /// \param theDoc a document
341   void displayDocumentResults(DocumentPtr theDoc);
342
343   /// Display results from a group
344   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
345
346  private slots:
347   /// SLOT, that is called after the operation is started. Update workshop state according to
348   /// the started operation, e.g. visualizes the property panel and connect to it.
349   /// \param theOpertion a started operation
350   void onOperationStarted(ModuleBase_Operation* theOperation);
351
352   /// SLOT, that is called after the operation is resumed. Update workshop state according to
353   /// the started operation, e.g. visualizes the property panel and connect to it.
354   /// \param theOpertion a resumed operation
355   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
356
357   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
358   /// hides the property panel and udpate the command status.
359   /// \param theOpertion a stopped operation
360   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
361
362   /// SLOT, that is called after the operation is committed.
363   /// \param theOpertion a commmitted operation
364   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
365
366   /// SLOT, that is called after the operation is aborted.
367   /// \param theOpertion an aborted operation
368   void onOperationAborted(ModuleBase_Operation* theOperation);
369
370   /// Slot, which reacts to the context popup menu call
371   /// \param theId the data value of the clicked action
372   /// \param isChecked a state of toggle if the action is checkable
373   void onContextMenuCommand(const QString& theId, bool isChecked);
374
375   /// Set waiting cursor
376   void onStartWaiting();
377
378  private:
379    /// Init menu
380   void initMenu();
381
382   /// Register validators
383   void registerValidators() const;
384
385   /// Load module from external library
386   /// \param theModule name of the module
387   ModuleBase_IModule* loadModule(const QString& theModule);
388
389   /// Create module
390   bool createModule();
391
392   /// Create object browser widget
393   /// \param theParent a parent of widget
394   QDockWidget* createObjectBrowser(QWidget* theParent);
395
396   /// Create property panel widget
397   /// \param theParent a parent of widget
398   QDockWidget* createPropertyPanel(QWidget* theParent);
399
400   // Creates Dock widgets: Object browser and Property panel
401   void createDockWidgets();
402
403   /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
404   /// Asks the module whether the object can be displayed
405   /// \param theObj an object
406   /// \return true if the object is displayed
407   bool displayObject(ObjectPtr theObj);
408
409   //! Extends undo/redo toolbutton's with history menu
410   //! \param theObject - in the OpenParts it is a QToolButton by itself,
411   //! in salome mode - QAction that creates a button.
412   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
413   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
414   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
415
416   //! Creates list of actions (commands) by given history list from session
417   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
418
419 private:
420   AppElements_MainWindow* myMainWindow;
421   ModuleBase_IModule* myModule;
422   XGUI_ObjectsBrowser* myObjectBrowser;
423   XGUI_PropertyPanel* myPropertyPanel;
424   XGUI_SelectionMgr* mySelector;
425   XGUI_Displayer* myDisplayer;
426   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
427   XGUI_ActionsMgr* myActionsMgr;
428   XGUI_SalomeConnector* mySalomeConnector;
429   XGUI_ErrorDialog* myErrorDlg;
430   XGUI_ViewerProxy* myViewerProxy;
431   XGUI_ContextMenuMgr* myContextMenuMgr;
432   XGUI_ModuleConnector* myModuleConnector;
433
434   QString myCurrentDir;
435
436   bool myUpdatePrefs;
437
438   // Flag to check that part document is in process of activating
439   bool myPartActivating;
440
441   /// The flag is true when we loading a document
442   bool myIsLoadingData;
443 };
444
445 #endif