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