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