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