Salome HOME
Task 5.1.7: To be able to export a part to a file and import it into an existing...
[modules/shaper.git] / src / XGUI / XGUI_Workshop.h
1 // Copyright (C) 2014-2019  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();
190
191   /// Returns true if the object can be shaded. If the object is a compsolid result, the method
192   /// checks subobjects of the result
193   /// \return boolean value
194   bool canBeShaded(const ObjectPtr& theObject) const;
195
196   /// Returns true if there is at least one selected body/construction/group result
197   /// \param theActionName text of the checked action
198   /// \return boolean value
199   bool canChangeProperty(const QString& theActionName) const;
200
201   /// Change color 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 changeColor(const QObjectPtrList& theObjects);
205
206   /// Change deflection 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 changeDeflection(const QObjectPtrList& theObjects);
210
211   /// Change transparency of the results if it is possible
212   /// The operation is available for construction, body and group results
213   /// theObjects a list of selected objects
214   void changeTransparency(const QObjectPtrList& theObjects);
215
216   /// Show the given features in 3d Viewer
217   void showObjects(const QObjectPtrList& theList, bool isVisible);
218
219   /// Show the given features in 3d Viewer
220   void showOnlyObjects(const QObjectPtrList& theList);
221
222   /// Set display mode for the given objects
223   /// \param theList a list of displayed objects
224   /// \param theMode a mode to set (see \ref XGUI_Displayer)
225   void setDisplayMode(const QObjectPtrList& theList, int theMode);
226
227   /// Set selection mode in viewer. If theMode=-1 then activate default mode
228   /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
229   void setViewerSelectionMode(int theMode);
230
231   /// Activates current selection mode for the given list of objects
232   void activateObjectsSelection(const QObjectPtrList& theList);
233
234   /// Returns current module
235   ModuleBase_IModule* module() const { return myModule; }
236
237   /// Returns current file
238   QString currentDataFile() const { return myCurrentFile; }
239
240   /// Returns current file
241   void setCurrentDataFile(const QString& theDir) { myCurrentFile = theDir; }
242
243   /// Save the current document into a directory
244   /// \param theName - path to the directory
245   /// \param theFileNames - returned file names created in this directory
246   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
247
248   /// If there is an active (uncommitted) operation shows a prompt to abort it
249   /// and performs abortion if user agreed. Returns true if
250   /// - operation aborted successfully
251   /// - there is no active operation
252   bool abortAllOperations();
253
254   /// Updates workshop state according to the started operation, e.g. visualizes the property panel
255   /// and connect to it.
256   /// \param theOpertion a started operation
257   void operationStarted(ModuleBase_Operation* theOperation);
258
259   /// Delete features. Delete the referenced features. There can be a question with a list of
260   /// referenced objects.
261   /// \param theFeatures a list of objects to be deleted
262   bool deleteFeatures(const QObjectPtrList& theFeatures);
263
264   /// Deactivates the object, if it is active and the module returns that the activation
265   /// of selection for the object is not possible currently(the current operation uses it)
266   /// \param theObject an object
267   /// \param theUpdateViewer a boolean flag to update viewer immediately
268   void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
269
270   /// Returns true if the action of the feature is created to contain Accept/Cancel button
271   /// \param theFeature a feature
272   bool isFeatureOfNested(const FeaturePtr& theFeature);
273
274   /// Shows the message in the status bar
275   /// \param theMessage a message
276   void setStatusBarMessage(const QString& theMessage);
277
278 #ifdef HAVE_SALOME
279   /// Has to be called in order to display objects with visibility status = true
280   void synchronizeViewer();
281
282   /// Has to be called in order to display objects from a specifed group
283   /// with visibility status = true
284   /// \param theDoc the document for objects synchronisation
285   /// \param theGroup the group name
286   /// \param theUpdateViewer update viewer flag
287   void synchronizeGroupInViewer(const DocumentPtr& theDoc,
288                                 const std::string& theGroup,
289                                 bool theUpdateViewer);
290
291   void synchronizeResultTree(const ResultBodyPtr& theRes, bool theUpdateViewer);
292
293 #endif
294   /// Update the property panel content by the XML description of the operation and set the panel
295   /// into the operation
296   /// \param theOperation an operation
297   void fillPropertyPanel(ModuleBase_Operation* theOperation);
298
299   /// Connects or disconnects to the value changed signal of the property panel widgets
300   /// \param isToConnect a boolean value whether connect or disconnect
301   void connectToPropertyPanel(const bool isToConnect);
302
303   /// Returns defailt selection mode in 3d viewer
304   QIntList viewerSelectionModes() const { return myViewerSelMode; }
305
306   /// Highlights result objects in Object Browser according to
307   /// features found in the given list
308   void highlightResults(const QObjectPtrList& theObjects);
309
310   /// Highlights feature objects in Object Browser according to
311   /// features found in the given list
312   void highlightFeature(const QObjectPtrList& theObjects);
313
314   /// Returns Data Model XML reader which contains information about
315   /// Data structure configuration
316   const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
317
318   /// A constant string used for "Move to end" command definition
319   /// It is used for specific processing of Undo/Redo for this command.
320   static QString MOVE_TO_END_COMMAND;
321
322   /// Closes all in the current session and load the directory
323   /// \param theDirectory a path to directory
324   void openFile(const QString& theDirectory);
325
326   void updateAutoComputeState();
327
328   void deactivateCurrentSelector();
329
330   /// The method updates a Color Scale object in the viewer
331   void updateColorScaleVisibility();
332
333 signals:
334   /// Emitted when selection happens in Salome viewer
335   void salomeViewerSelection();
336
337   /// the signal about the workshop actions states are updated.
338   void commandStatusUpdated();
339
340   /// the application is started
341   void applicationStarted();
342
343   /// Signal to update Undo history list
344   void updateUndoHistory(const QList<ActionInfo>&);
345
346   /// Signal to update Redo history list
347   void updateRedoHistory(const QList<ActionInfo>&);
348
349  public slots:
350    /// Update of commands status
351   void updateCommandStatus();
352
353   /// update history list (undo/redo commands)
354   void updateHistory();
355
356   /// Save current document
357   bool onSave();
358
359   /// Save current document to a file selected by user
360   bool onSaveAs();
361
362   /// Undo last command
363   void onUndo(int times = 1);
364
365   /// Redo previous command
366   void onRedo(int times = 1);
367
368   /// Validates the operation to change the "Apply" button state.
369   /// \param thePreviousState the previous state of the widget
370   void onWidgetStateChanged(int thePreviousState);
371
372   /// Calls activate of the current widget again. It is possible that selection filters are
373   /// differs in the new state of paged container
374   void onValuesChanged();
375
376   /// Listens the corresponded signal of model widget and updates Apply button state by feature
377   void onWidgetObjectUpdated();
378
379   /// Show dock widget panel
380   void showPanel(QDockWidget* theDockWidget);
381
382   /// Hide dock widget panel
383   void hidePanel(QDockWidget* theDockWidget);
384
385   /// Show object Browser
386   void showObjectBrowser();
387
388   /// Hide object Browser
389   void hideObjectBrowser();
390
391   /// Close document
392   void closeDocument();
393
394   /// Open document from file
395   void onOpen();
396
397   /// Create a new document
398   void onNew();
399
400   /// Import part structure from a file
401   void onImportPart();
402
403   /// Export features to a file
404   void onExportPart();
405
406 #ifndef HAVE_SALOME
407   /// Exit application
408   void onExit();
409
410   /// Open preferences dialog box
411   void onPreferences();
412 #endif
413
414   /// A slot calleon toggle of auto-compute button
415   void onAutoApply();
416
417   /// Activates/deactivates the trihedron in the viewer AIS context
418   void onTrihedronVisibilityChanged(bool theState);
419
420   /// Apply the current transparency value if preview in transparency dialog is switched on
421   void onTransparencyValueChanged();
422
423  protected:
424   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
425   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
426   /// \param theOperation an operation
427    void setGrantedFeatures(ModuleBase_Operation* theOperation);
428
429 private:
430   /// Display results from document
431   /// \param theDoc a document
432   void displayDocumentResults(DocumentPtr theDoc);
433
434   /// Display results from a group
435   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
436
437   /// Insert folder object before currently selected feature
438   void insertFeatureFolder();
439
440   /// Insert an object to a folder above or below
441   void insertToFolder(bool isBefore);
442
443   /// Insert an object to a folder above or below
444   void moveOutFolder(bool isBefore);
445
446  private slots:
447   /// SLOT, that is called after the operation is resumed. Update workshop state according to
448   /// the started operation, e.g. visualizes the property panel and connect to it.
449   /// \param theOpertion a resumed operation
450   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
451
452   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
453   /// hides the property panel and update the command status.
454   /// \param theOpertion a stopped operation
455   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
456
457   /// SLOT, that is called after the operation is committed.
458   /// \param theOpertion a committed operation
459   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
460
461   /// SLOT, that is called after the operation is aborted.
462   /// \param theOpertion an aborted operation
463   void onOperationAborted(ModuleBase_Operation* theOperation);
464
465   /// Slot, which reacts to the context popup menu call
466   /// \param theId the data value of the clicked action
467   /// \param isChecked a state of toggle if the action is checkable
468   void onContextMenuCommand(const QString& theId, bool isChecked);
469
470   /// Set waiting cursor
471   void onStartWaiting();
472
473   /// Called by Ok button clicked in the property panel. Asks the error manager whether
474   /// the operation can be committed and do it if it returns true.
475   void onAcceptActionClicked();
476
477   /// Called by OkPlus button clicked in the property panel. Asks the error manager whether
478   /// the operation can be committed and do it if it returns true.
479   void onAcceptPlusActionClicked();
480
481   /// Called by Preview button clicked in the property panel. Sends signal to model to
482   /// compute preview.
483   void onPreviewActionClicked();
484
485   /// Called on help button clicked in the property panel.
486   void onHelpActionClicked();
487
488   //! The slot is called only once on resizing of Object Browser
489   void onDockSizeChanged();
490
491  private:
492   /// Init menu
493   void initMenu();
494
495   /// Register validators
496   void registerValidators() const;
497
498   /// Load module from external library
499   /// \param theModule name of the module
500   ModuleBase_IModule* loadModule(const QString& theModule);
501
502   /// Create module
503   bool createModule();
504
505   /// Create object browser widget
506   /// \param theParent a parent of widget
507   QDockWidget* createObjectBrowser(QWidget* theParent);
508
509   // Creates Dock widgets: Object browser and Property panel
510   void createDockWidgets();
511
512   /// Extends undo/redo toolbutton's with history menu
513   /// \param theObject - in the CADBuilder it is a QToolButton by itself,
514   /// in salome mode - QAction that creates a button.
515   /// \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
516   /// \param theSlot - onUndo(int) or onRedo(int) SLOT
517   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
518
519   /// Creates list of actions (commands) by given history list from session
520   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
521
522   /// Pefrom Undo/Redo and necessary workshop updates(viewer, browser, actions state)
523   /// \param theActionType a type of the action (Undo or Redo)
524   /// \param theTimes number of applies the given action
525   void processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes);
526
527   /// Clear content of temporary directory
528   void clearTemporaryDir();
529
530   /// Set current point of view normal to selected planar face
531   /// \param toInvert invert the normal vector
532   void setNormalView(bool toInvert = false);
533
534 private:
535 #ifndef HAVE_SALOME
536   AppElements_MainWindow* myMainWindow; ///< desktop window
537 #endif
538
539   ModuleBase_IModule* myModule; ///< current module
540   XGUI_ErrorMgr* myErrorMgr; ///< updator of error message
541   XGUI_ObjectsBrowser* myObjectBrowser; ///< data tree widget
542   XGUI_PropertyPanel* myPropertyPanel; ///< container of feature attributes widgets
543   XGUI_FacesPanel* myFacesPanel; ///< panel for hide object faces
544   XGUI_SelectionMgr* mySelector; ///< handler of selection processing
545   XGUI_SelectionActivate* mySelectionActivate; /// manager of selection activating
546   XGUI_Displayer* myDisplayer; ///< handler of objects display
547   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
548   XGUI_ActionsMgr* myActionsMgr; ///< manager of workshop actions
549   XGUI_ActiveControlMgr* myActiveControlMgr; ///< manager to have none or one active control
550   XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
551   XGUI_SalomeConnector* mySalomeConnector; ///< connector to SALOME module interface
552   XGUI_ErrorDialog* myErrorDlg; ///< dialog to show information of occured error events
553   XGUI_ViewerProxy* myViewerProxy; ///< connector to SALOME viewer interface
554   XGUI_ContextMenuMgr* myContextMenuMgr; ///< manager of context menu build
555   XGUI_ModuleConnector* myModuleConnector; ///< implementation of ModuleBase_IWorkshop
556   XGUI_WorkshopListener* myEventsListener; ///< processing of events
557   QString myCurrentFile; ///< cached the last open directory
558   QIntList myViewerSelMode; ///< selection modes set in the viewer
559   Config_DataModelReader* myDataModelXMLReader; ///< XML reader of data model
560   XGUI_InspectionPanel* myInspectionPanel; ///< container of feature attributes widgets
561   QTemporaryDir myTmpDir; ///< a direcory for uncompressed files
562 };
563
564 #endif