]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Workshop.h
Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / XGUI / XGUI_Workshop.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef XGUI_WORKSHOP_H
22 #define XGUI_WORKSHOP_H
23
24 #include "XGUI.h"
25 //#include "XGUI_Constants.h"
26 #include <ModuleBase_Definitions.h>
27 #include <ModelAPI_Document.h>
28 #include <ModelAPI_Feature.h>
29
30 #include <ModuleBase_ActionInfo.h>
31
32 #include <QObject>
33 #include <QMap>
34 #include <QKeySequence>
35 #include <QIcon>
36
37 #ifndef HAVE_SALOME
38 class AppElements_MainWindow;
39 class AppElements_Command;
40 class AppElements_Workbench;
41 #endif
42
43 class XGUI_ActionsMgr;
44 class XGUI_ContextMenuMgr;
45 class XGUI_Displayer;
46 class XGUI_ErrorDialog;
47 class XGUI_ErrorMgr;
48 class XGUI_MenuMgr;
49 class XGUI_ModuleConnector;
50 class XGUI_ObjectsBrowser;
51 class XGUI_OperationMgr;
52 class XGUI_PropertyPanel;
53 class XGUI_SalomeConnector;
54 class XGUI_SalomeViewer;
55 class XGUI_SelectionMgr;
56 class XGUI_ViewerProxy;
57 class XGUI_WorkshopListener;
58
59 class ModuleBase_IModule;
60 class ModuleBase_IViewer;
61 class ModuleBase_Operation;
62
63 class QWidget;
64 class QDockWidget;
65 class QMainWindow;
66
67 class QAction;
68 class Config_DataModelReader;
69
70 /**\class XGUI_Workshop
71  * \ingroup GUI
72  * \brief Class which defines a configuration of the application (Workshop) and launches it.
73  */
74 class XGUI_EXPORT XGUI_Workshop : public QObject
75 {
76 Q_OBJECT
77  public:
78   /// Constructor
79   /// \param theConnector a Salome connector object.
80   /// Used only if the workshop is launched in Salome environment
81   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
82   virtual ~XGUI_Workshop();
83
84   //! Starting of the application
85   void startApplication();
86
87   /// Activates the module controls. Should be called after module creation
88   void activateModule();
89
90   /// Deactivates the module controls. Should be called after module creation
91   void deactivateModule();
92
93 #ifndef HAVE_SALOME
94   //! Returns main window (Desktop) of the application
95   AppElements_MainWindow* mainWindow() const
96   {
97     return myMainWindow;
98   }
99
100   //! Creates and adds a new workbench (menu group) with the given name and returns it
101   AppElements_Workbench* addWorkbench(const QString& theName);
102 #endif
103
104   //! Returns selection manager object
105   XGUI_SelectionMgr* selector() const
106   {
107     return mySelector;
108   }
109
110   //! Returns displayer
111   XGUI_Displayer* displayer() const
112   {
113     return myDisplayer;
114   }
115
116   //! ! Returns operation manager.
117   XGUI_OperationMgr* operationMgr() const
118   {
119     return myOperationMgr;
120   }
121
122   //! ! Returns error manager.
123   XGUI_ErrorMgr* errorMgr() const
124   {
125     return myErrorMgr;
126   }
127
128   //! ! Returns an actions manager
129   XGUI_ActionsMgr* actionsMgr() const
130   {
131     return myActionsMgr;
132   }
133
134   //! ! Returns an actions manager
135   XGUI_MenuMgr* menuMgr() const
136   {
137     return myMenuMgr;
138   }
139
140   //! Returns property panel widget
141   XGUI_PropertyPanel* propertyPanel() const
142   {
143     return myPropertyPanel;
144   }
145
146   //! Returns context menu manager object
147   XGUI_ContextMenuMgr* contextMenuMgr() const
148   {
149     return myContextMenuMgr;
150   }
151
152   //! Returns an object which provides interface to Salome Module (LightApp_Module)
153   XGUI_SalomeConnector* salomeConnector() const
154   {
155     return mySalomeConnector;
156   }
157
158   //! Provides an object which provides interface to Salome Viewer
159   ModuleBase_IViewer* salomeViewer() const;
160
161   //! Returns true if the application works as SALOME module
162   bool isSalomeMode() const
163   {
164     return mySalomeConnector != 0;
165   }
166
167   //! Returns Object browser
168   XGUI_ObjectsBrowser* objectBrowser() const
169   {
170     return myObjectBrowser;
171   }
172
173   /// This method is called by Salome module when selection is changed
174   void salomeViewerSelectionChanged();
175
176   /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
177   XGUI_ViewerProxy* viewer() const
178   {
179     return myViewerProxy;
180   }
181
182   /// Returns the module connector
183   /// \returns the instance of connector
184   XGUI_ModuleConnector* moduleConnector() const
185   {
186     return myModuleConnector;
187   }
188
189   /// Returns a desktop
190   /// \return a desktop instance
191   QMainWindow* desktop() const;
192
193   //! Delete features
194   void deleteObjects();
195
196   //! Searches for selected features unused in other (not selected) features. If one or several
197   //! selected features are found, a warning message proposes to delete them. It contains
198   //! the list of features to be deleted.
199   void cleanHistory();
200
201   //! Returns true if the selected feature can be moved to the position after the current feature
202   //! \return boolean value
203   bool canMoveFeature();
204
205   //! Move selected features to be after the current feature
206   void moveObjects();
207
208   //! Returns true if the object can be shaded. If the object is a compsolid result, the method
209   //! checks subobjects of the result
210   //! \return boolean value
211   bool canBeShaded(const ObjectPtr& theObject) const;
212
213   //! Returns true if there is at least one selected body/construction/group result
214   //! \return boolean value
215   bool canChangeColor() const;
216
217   //! Change color of the results if it is possible
218   //! The operation is available for construction, body and group results
219   //! theObjects a list of selected objects
220   void changeColor(const QObjectPtrList& theObjects);
221
222   //! Returns true if there is at least one selected body/construction/group result
223   //! \return boolean value
224   bool canChangeDeflection() const;
225
226   //! Change deflection of the results if it is possible
227   //! The operation is available for construction, body and group results
228   //! theObjects a list of selected objects
229   void changeDeflection(const QObjectPtrList& theObjects);
230
231   //! Show the given features in 3d Viewer
232   void showObjects(const QObjectPtrList& theList, bool isVisible);
233
234   //! Show the given features in 3d Viewer
235   void showOnlyObjects(const QObjectPtrList& theList);
236
237   /// Set display mode for the given objects
238   /// \param theList a list of displayed objects
239   /// \param theMode a mode to set (see \ref XGUI_Displayer)
240   void setDisplayMode(const QObjectPtrList& theList, int theMode);
241
242   /// Set selection mode in viewer. If theMode=-1 then activate default mode
243   /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
244   void setViewerSelectionMode(int theMode);
245
246   /// Activates current selection mode for the given list of objects
247   void activateObjectsSelection(const QObjectPtrList& theList);
248
249   /// Returns current module
250   ModuleBase_IModule* module() const
251   {
252     return myModule;
253   }
254
255   /// Returns current directory which contains data files
256   QString currentDataDir() const { return myCurrentDir; }
257
258   /// Returns current directory which contains data files
259   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
260
261   /**
262   * Save the current document into a directory
263   * \param theName - path to the directory
264   * \param theFileNames - returned file names created in this directory
265   */
266   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
267
268   /// Updates workshop state according to the started operation, e.g. visualizes the property panel
269   /// and connect to it.
270   /// \param theOpertion a started operation
271   void operationStarted(ModuleBase_Operation* theOperation);
272
273   //! Delete features. Delete the referenced features. There can be a question with a list of
274   //! referenced objects.
275   //! \param theFeatures a list of objects to be deleted
276   bool deleteFeatures(const QObjectPtrList& theFeatures);
277
278   /// Deactivates the object, if it is active and the module returns that the activation
279   /// of selection for the object is not possible currently(the current operation uses it)
280   /// \param theObject an object
281   /// \param theUpdateViewer a boolean flag to update viewer immediately
282   void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
283
284   /// Returns true if the action of the feature is created to contain Accept/Cancel button
285   /// \param theFeature a feature
286   bool isFeatureOfNested(const FeaturePtr& theFeature);
287
288   //! Shows the message in the status bar
289   //! \param theMessage a message
290   void setStatusBarMessage(const QString& theMessage);
291
292   /// Has to be called in order to display objects with visibility status = true
293   void synchronizeViewer();
294
295   /// Has to be called in order to display objects from a specifed group
296   /// with visibility status = true
297   /// \param theDoc the document for objects synchronisation
298   /// \param theGroup the group name
299   /// \param theUpdateViewer update viewer flag
300   void synchronizeGroupInViewer(const DocumentPtr& theDoc,
301                                 const std::string& theGroup,
302                                 bool theUpdateViewer);
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 fillPropertyPanel(ModuleBase_Operation* theOperation);
308
309   /// Connects or disconnects to the value changed signal of the property panel widgets
310   /// \param isToConnect a boolean value whether connect or disconnect
311   void connectToPropertyPanel(const bool isToConnect);
312
313   /// Returns defailt selection mode in 3d viewer
314   QIntList viewerSelectionModes() const { return myViewerSelMode; }
315
316   /// Highlights result objects in Object Browser according to
317   /// features found in the given list
318   void highlightResults(const QObjectPtrList& theObjects);
319
320   /// Highlights feature objects in Object Browser according to
321   /// features found in the given list
322   void highlightFeature(const QObjectPtrList& theObjects);
323
324   /// Returns Data Model XML reader which contains information about
325   /// Data structure configuration
326   const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
327
328   /// A constant string used for "Move to end" command definition
329   /// It is used for specific processing of Undo/Redo for this command.
330   static QString MOVE_TO_END_COMMAND;
331
332   //! Closes all in the current session and load the directory
333   //! \param theDirectory a path to directory
334   void openDirectory(const QString& theDirectory);
335
336 signals:
337   /// Emitted when selection happens in Salome viewer
338   void salomeViewerSelection();
339
340   //! the signal about the workshop actions states are updated.
341   void commandStatusUpdated();
342
343   //! the application is started
344   void applicationStarted();
345
346   //! Signal to update Undo history list
347   void updateUndoHistory(const QList<ActionInfo>&);
348
349   //! Signal to update Redo history list
350   void updateRedoHistory(const QList<ActionInfo>&);
351
352  public slots:
353    /// Update of commands status
354   void updateCommandStatus();
355
356   /// update history list (undo/redo commands)
357   void updateHistory();
358
359   /// Save current document
360   bool onSave();
361
362   /// Save current document to a file selected by user
363   bool onSaveAs();
364
365   /// Undo last command
366   void onUndo(int times = 1);
367
368   /// Redo previous command
369   void onRedo(int times = 1);
370
371   // Rebuild data tree
372   //void onRebuild();
373
374   /// Validates the operation to change the "Apply" button state.
375   /// \param thePreviousState the previous state of the widget
376   void onWidgetStateChanged(int thePreviousState);
377
378   /// Calls activate of the current widget again. It is possible that selection filters are
379   /// differs in the new state of paged container
380   void onValuesChanged();
381
382   /// Listens the corresponded signal of model widget and updates Apply button state by feature
383   void onWidgetObjectUpdated();
384
385   /// Show property panel
386   void showPropertyPanel();
387
388   /// Hide property panel
389   void hidePropertyPanel();
390
391   /// Show object Browser
392   void showObjectBrowser();
393
394   /// Hide object Browser
395   void hideObjectBrowser();
396
397   /// Close document
398   void closeDocument();
399
400   /// Open document from file
401   void onOpen();
402
403   /// Create a new document
404   void onNew();
405
406 #ifndef HAVE_SALOME
407   /// Exit application
408   void onExit();
409
410   /// Open preferences dialog box
411   void onPreferences();
412 #endif
413
414   /// Activates/deactivates the trihedron in the viewer AIS context
415   void onTrihedronVisibilityChanged(bool theState);
416
417
418  protected:
419   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
420   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
421   /// \param theOperation an operation
422    void setGrantedFeatures(ModuleBase_Operation* theOperation);
423
424 private:
425   /// Display all results
426   //void displayAllResults();
427
428   /// Display results from document
429   /// \param theDoc a document
430   void displayDocumentResults(DocumentPtr theDoc);
431
432   /// Display results from a group
433   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
434
435  private slots:
436   /// SLOT, that is called after the operation is started. Update workshop state according to
437   /// the started operation, e.g. visualizes the property panel and connect to it.
438   /// \param theOpertion a started operation
439   // void onOperationStarted(ModuleBase_Operation* theOperation);
440
441   /// SLOT, that is called after the operation is resumed. Update workshop state according to
442   /// the started operation, e.g. visualizes the property panel and connect to it.
443   /// \param theOpertion a resumed operation
444   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
445
446   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
447   /// hides the property panel and update the command status.
448   /// \param theOpertion a stopped operation
449   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
450
451   /// SLOT, that is called after the operation is committed.
452   /// \param theOpertion a committed operation
453   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
454
455   /// SLOT, that is called after the operation is aborted.
456   /// \param theOpertion an aborted operation
457   void onOperationAborted(ModuleBase_Operation* theOperation);
458
459   /// Slot, which reacts to the context popup menu call
460   /// \param theId the data value of the clicked action
461   /// \param isChecked a state of toggle if the action is checkable
462   void onContextMenuCommand(const QString& theId, bool isChecked);
463
464   /// Set waiting cursor
465   void onStartWaiting();
466
467   /// Called by Ok button clicked in the property panel. Asks the error manager whether
468   /// the operation can be committed and do it if it returns true.
469   void onAcceptActionClicked();
470
471   /// Called by Preview button clicked in the property panel. Sends signal to model to
472   /// compute preview.
473   void onPreviewActionClicked();
474
475  private:
476    /// Init menu
477   void initMenu();
478
479   /// Register validators
480   void registerValidators() const;
481
482   /// Load module from external library
483   /// \param theModule name of the module
484   ModuleBase_IModule* loadModule(const QString& theModule);
485
486   /// Create module
487   bool createModule();
488
489   /// Create object browser widget
490   /// \param theParent a parent of widget
491   QDockWidget* createObjectBrowser(QWidget* theParent);
492
493   /// Create property panel widget
494   /// \param theParent a parent of widget
495   QDockWidget* createPropertyPanel(QWidget* theParent);
496
497   // Creates Dock widgets: Object browser and Property panel
498   void createDockWidgets();
499
500   //! Extends undo/redo toolbutton's with history menu
501   //! \param theObject - in the OpenParts it is a QToolButton by itself,
502   //! in salome mode - QAction that creates a button.
503   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
504   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
505   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
506
507   //! Creates list of actions (commands) by given history list from session
508   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
509
510 private:
511 #ifndef HAVE_SALOME
512   AppElements_MainWindow* myMainWindow;
513 #endif
514
515   ModuleBase_IModule* myModule;
516   XGUI_ErrorMgr* myErrorMgr;
517   XGUI_ObjectsBrowser* myObjectBrowser;
518   XGUI_PropertyPanel* myPropertyPanel;
519   XGUI_SelectionMgr* mySelector;
520   XGUI_Displayer* myDisplayer;
521   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
522   XGUI_ActionsMgr* myActionsMgr;
523   XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
524   XGUI_SalomeConnector* mySalomeConnector;
525   XGUI_ErrorDialog* myErrorDlg;
526   XGUI_ViewerProxy* myViewerProxy;
527   XGUI_ContextMenuMgr* myContextMenuMgr;
528   XGUI_ModuleConnector* myModuleConnector;
529   XGUI_WorkshopListener* myEventsListener;
530
531   QString myCurrentDir;
532
533   QIntList myViewerSelMode;
534
535   Config_DataModelReader* myDataModelXMLReader;
536 };
537
538 #endif