1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef XGUI_WORKSHOP_H
21 #define XGUI_WORKSHOP_H
25 #include <ModelAPI_Document.h>
26 #include <ModelAPI_Feature.h>
27 #include <ModelAPI_ResultBody.h>
29 #include <ModuleBase_ActionInfo.h>
30 #include <ModuleBase_ActionType.h>
31 #include <ModuleBase_Definitions.h>
33 #include <SelectMgr_ListOfFilter.hxx>
37 #include <QKeySequence>
39 #include <QTemporaryDir>
42 class AppElements_Command;
43 class AppElements_MainWindow;
44 class AppElements_Workbench;
47 class Config_DataModelReader;
49 class XGUI_ActionsMgr;
50 class XGUI_ActiveControlMgr;
51 class XGUI_ContextMenuMgr;
53 class XGUI_ErrorDialog;
55 class XGUI_FacesPanel;
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;
69 class ModuleBase_IModule;
70 class ModuleBase_IViewer;
71 class ModuleBase_Operation;
78 /// \class XGUI_Workshop
80 /// \brief Class which defines a configuration of the application (Workshop) and launches it.
81 class XGUI_EXPORT XGUI_Workshop : public QObject
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();
91 /// Starting of the application
92 void startApplication();
94 /// Activates the module controls. Should be called after module creation
95 void activateModule();
97 /// Deactivates the module controls. Should be called after module creation
98 void deactivateModule();
101 /// Returns main window (Desktop) of the application
102 AppElements_MainWindow* mainWindow() const { return myMainWindow; }
104 /// Creates and adds a new workbench (menu group) with the given name and returns it
105 AppElements_Workbench* addWorkbench(const QString& theName);
108 /// Returns selection manager object
109 XGUI_SelectionMgr* selector() const { return mySelector; }
111 /// Returns selection activating object
112 XGUI_SelectionActivate* selectionActivate() const { return mySelectionActivate; }
114 /// Returns displayer
115 XGUI_Displayer* displayer() const { return myDisplayer; }
117 /// Returns operation manager.
118 XGUI_OperationMgr* operationMgr() const { return myOperationMgr; }
120 /// Returns error manager.
121 XGUI_ErrorMgr* errorMgr() const { return myErrorMgr; }
123 /// Returns an actions manager
124 XGUI_ActionsMgr* actionsMgr() const { return myActionsMgr; }
126 /// Returns an active control manager
127 XGUI_ActiveControlMgr* activeControlMgr() const { return myActiveControlMgr; }
129 /// Returns an actions manager
130 XGUI_MenuMgr* menuMgr() const { return myMenuMgr; }
132 /// Returns property panel widget
133 XGUI_PropertyPanel* propertyPanel() const { return myPropertyPanel; }
135 /// Returns property panel widget
136 XGUI_InspectionPanel* inspectionPanel() const { return myInspectionPanel; }
138 /// Returns panel for hide object faces
139 XGUI_FacesPanel* facesPanel() const { return myFacesPanel; }
141 /// Returns context menu manager object
142 XGUI_ContextMenuMgr* contextMenuMgr() const { return myContextMenuMgr; }
144 /// Returns an object which provides interface to Salome Module (LightApp_Module)
145 XGUI_SalomeConnector* salomeConnector() const { return mySalomeConnector; }
147 /// Provides an object which provides interface to Salome Viewer
148 ModuleBase_IViewer* salomeViewer() const;
150 /// Returns true if the application works as SALOME module
151 bool isSalomeMode() const { return mySalomeConnector != 0; }
153 /// Returns Object browser
154 XGUI_ObjectsBrowser* objectBrowser() const { return myObjectBrowser; }
156 /// This method is called by Salome module when selection is changed
157 void salomeViewerSelectionChanged();
159 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
160 XGUI_ViewerProxy* viewer() const { return myViewerProxy; }
162 /// Returns the module connector
163 /// \returns the instance of connector
164 XGUI_ModuleConnector* moduleConnector() const { return myModuleConnector; }
166 /// Returns a desktop
167 /// \return a desktop instance
168 QMainWindow* desktop() const;
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;
177 void deleteObjects();
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.
184 /// Returns true if the selected feature can be moved to the position after the current feature
185 /// \return boolean value
186 bool canMoveFeature();
188 /// Move selected features to be after the current feature
189 void moveObjects(const bool theSplit);
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;
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;
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);
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);
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);
216 /// Show the given features in 3d Viewer
217 void showObjects(const QObjectPtrList& theList, bool isVisible);
219 /// Show the given features in 3d Viewer
220 void showOnlyObjects(const QObjectPtrList& theList);
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);
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);
231 /// Activates current selection mode for the given list of objects
232 void activateObjectsSelection(const QObjectPtrList& theList);
234 /// Returns current module
235 ModuleBase_IModule* module() const { return myModule; }
237 /// Returns current file
238 QString currentDataFile() const { return myCurrentFile; }
240 /// Returns current file
241 void setCurrentDataFile(const QString& theDir) { myCurrentFile = theDir; }
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);
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();
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);
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);
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);
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);
274 /// Shows the message in the status bar
275 /// \param theMessage a message
276 void setStatusBarMessage(const QString& theMessage);
279 /// Has to be called in order to display objects with visibility status = true
280 void synchronizeViewer();
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 theUpdateViewer update viewer flag
286 void synchronizeGroupInViewer(const DocumentPtr& theDoc,
287 bool theUpdateViewer);
289 void synchronizeResultTree(const ResultBodyPtr& theRes, bool theUpdateViewer);
292 /// Update the property panel content by the XML description of the operation and set the panel
293 /// into the operation
294 /// \param theOperation an operation
295 void fillPropertyPanel(ModuleBase_Operation* theOperation);
297 /// Connects or disconnects to the value changed signal of the property panel widgets
298 /// \param isToConnect a boolean value whether connect or disconnect
299 void connectToPropertyPanel(const bool isToConnect);
301 /// Returns defailt selection mode in 3d viewer
302 QIntList viewerSelectionModes() const { return myViewerSelMode; }
304 /// Highlights result objects in Object Browser according to
305 /// features found in the given list
306 void highlightResults(const QObjectPtrList& theObjects);
308 /// Highlights feature objects in Object Browser according to
309 /// features found in the given list
310 void highlightFeature(const QObjectPtrList& theObjects);
312 /// Returns Data Model XML reader which contains information about
313 /// Data structure configuration
314 const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
316 /// A constant string used for "Move to end" command definition
317 /// It is used for specific processing of Undo/Redo for this command.
318 static QString MOVE_TO_END_COMMAND;
319 /// A constant string used for "Move to end and split" command definition
320 /// It is used for specific processing of Undo/Redo for this command.
321 static QString MOVE_TO_END_SPLIT_COMMAND;
323 /// Closes all in the current session and load the directory
324 /// \param theDirectory a path to directory
325 void openFile(const QString& theDirectory);
327 void updateAutoComputeState();
329 void deactivateCurrentSelector();
331 /// The method updates a Color Scale object in the viewer
332 void updateColorScaleVisibility();
335 /// Emitted when selection happens in Salome viewer
336 void salomeViewerSelection();
338 /// the signal about the workshop actions states are updated.
339 void commandStatusUpdated();
341 /// the application is started
342 void applicationStarted();
344 /// Signal to update Undo history list
345 void updateUndoHistory(const QList<ActionInfo>&);
347 /// Signal to update Redo history list
348 void updateRedoHistory(const QList<ActionInfo>&);
351 /// Update of commands status
352 void updateCommandStatus();
354 /// update history list (undo/redo commands)
355 void updateHistory();
357 /// Save current document
360 /// Save current document to a file selected by user
363 /// Undo last command
364 void onUndo(int times = 1);
366 /// Redo previous command
367 void onRedo(int times = 1);
369 /// Validates the operation to change the "Apply" button state.
370 /// \param thePreviousState the previous state of the widget
371 void onWidgetStateChanged(int thePreviousState);
373 /// Calls activate of the current widget again. It is possible that selection filters are
374 /// differs in the new state of paged container
375 void onValuesChanged();
377 /// Listens the corresponded signal of model widget and updates Apply button state by feature
378 void onWidgetObjectUpdated();
380 /// Show dock widget panel
381 void showPanel(QDockWidget* theDockWidget);
383 /// Hide dock widget panel
384 void hidePanel(QDockWidget* theDockWidget);
386 /// Show object Browser
387 void showObjectBrowser();
389 /// Hide object Browser
390 void hideObjectBrowser();
393 void closeDocument();
395 /// Open document from file
398 /// Create a new document
401 /// Import part structure from a file
404 /// Export features to a file
411 /// Open preferences dialog box
412 void onPreferences();
415 /// A slot calleon toggle of auto-compute button
418 /// Activates/deactivates the trihedron in the viewer AIS context
419 void onTrihedronVisibilityChanged(bool theState);
421 /// Apply the current transparency value if preview in transparency dialog is switched on
422 void onTransparencyValueChanged();
425 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
426 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
427 /// \param theOperation an operation
428 void setGrantedFeatures(ModuleBase_Operation* theOperation);
431 /// Display results from document
432 /// \param theDoc a document
433 void displayDocumentResults(DocumentPtr theDoc);
435 /// Display results from a group
436 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
438 /// Insert folder object before currently selected feature
439 void insertFeatureFolder();
441 /// Insert an object to a folder above or below
442 void insertToFolder(bool isBefore);
444 /// Insert an object to a folder above or below
445 void moveOutFolder(bool isBefore);
448 /// SLOT, that is called after the operation is resumed. Update workshop state according to
449 /// the started operation, e.g. visualizes the property panel and connect to it.
450 /// \param theOpertion a resumed operation
451 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
453 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
454 /// hides the property panel and update the command status.
455 /// \param theOpertion a stopped operation
456 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
458 /// SLOT, that is called after the operation is committed.
459 /// \param theOpertion a committed operation
460 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
462 /// SLOT, that is called after the operation is aborted.
463 /// \param theOpertion an aborted operation
464 void onOperationAborted(ModuleBase_Operation* theOperation);
466 /// Slot, which reacts to the context popup menu call
467 /// \param theId the data value of the clicked action
468 /// \param isChecked a state of toggle if the action is checkable
469 void onContextMenuCommand(const QString& theId, bool isChecked);
471 /// Set waiting cursor
472 void onStartWaiting();
474 /// Called by Ok button clicked in the property panel. Asks the error manager whether
475 /// the operation can be committed and do it if it returns true.
476 void onAcceptActionClicked();
478 /// Called by OkPlus button clicked in the property panel. Asks the error manager whether
479 /// the operation can be committed and do it if it returns true.
480 void onAcceptPlusActionClicked();
482 /// Called by Preview button clicked in the property panel. Sends signal to model to
484 void onPreviewActionClicked();
486 /// Called on help button clicked in the property panel.
487 void onHelpActionClicked();
489 //! The slot is called only once on resizing of Object Browser
490 void onDockSizeChanged();
496 /// Register validators
497 void registerValidators() const;
499 /// Load module from external library
500 /// \param theModule name of the module
501 ModuleBase_IModule* loadModule(const QString& theModule);
506 /// Create object browser widget
507 /// \param theParent a parent of widget
508 QDockWidget* createObjectBrowser(QWidget* theParent);
510 // Creates Dock widgets: Object browser and Property panel
511 void createDockWidgets();
513 /// Extends undo/redo toolbutton's with history menu
514 /// \param theObject - in the CADBuilder it is a QToolButton by itself,
515 /// in salome mode - QAction that creates a button.
516 /// \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
517 /// \param theSlot - onUndo(int) or onRedo(int) SLOT
518 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
520 /// Creates list of actions (commands) by given history list from session
521 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
523 /// Pefrom Undo/Redo and necessary workshop updates(viewer, browser, actions state)
524 /// \param theActionType a type of the action (Undo or Redo)
525 /// \param theTimes number of applies the given action
526 void processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes);
528 /// Clear content of temporary directory
529 void clearTemporaryDir();
531 /// Set current point of view normal to selected planar face
532 /// \param toInvert invert the normal vector
533 void setNormalView(bool toInvert = false);
537 AppElements_MainWindow* myMainWindow; ///< desktop window
540 ModuleBase_IModule* myModule; ///< current module
541 XGUI_ErrorMgr* myErrorMgr; ///< updator of error message
542 XGUI_ObjectsBrowser* myObjectBrowser; ///< data tree widget
543 XGUI_PropertyPanel* myPropertyPanel; ///< container of feature attributes widgets
544 XGUI_FacesPanel* myFacesPanel; ///< panel for hide object faces
545 XGUI_SelectionMgr* mySelector; ///< handler of selection processing
546 XGUI_SelectionActivate* mySelectionActivate; /// manager of selection activating
547 XGUI_Displayer* myDisplayer; ///< handler of objects display
548 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
549 XGUI_ActionsMgr* myActionsMgr; ///< manager of workshop actions
550 XGUI_ActiveControlMgr* myActiveControlMgr; ///< manager to have none or one active control
551 XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
552 XGUI_SalomeConnector* mySalomeConnector; ///< connector to SALOME module interface
553 XGUI_ErrorDialog* myErrorDlg; ///< dialog to show information of occured error events
554 XGUI_ViewerProxy* myViewerProxy; ///< connector to SALOME viewer interface
555 XGUI_ContextMenuMgr* myContextMenuMgr; ///< manager of context menu build
556 XGUI_ModuleConnector* myModuleConnector; ///< implementation of ModuleBase_IWorkshop
557 XGUI_WorkshopListener* myEventsListener; ///< processing of events
558 QString myCurrentFile; ///< cached the last open directory
559 QIntList myViewerSelMode; ///< selection modes set in the viewer
560 Config_DataModelReader* myDataModelXMLReader; ///< XML reader of data model
561 XGUI_InspectionPanel* myInspectionPanel; ///< container of feature attributes widgets
562 QTemporaryDir myTmpDir; ///< a direcory for uncompressed files