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