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