1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef XGUI_WORKSHOP_H
22 #define XGUI_WORKSHOP_H
26 #include <ModelAPI_Document.h>
27 #include <ModelAPI_Feature.h>
29 #include <ModuleBase_ActionInfo.h>
30 #include <ModuleBase_ActionType.h>
31 #include <ModuleBase_Definitions.h>
33 #include <SelectMgr_ListOfFilter.hxx>
37 #include <QKeySequence>
41 class AppElements_Command;
42 class AppElements_MainWindow;
43 class AppElements_Workbench;
46 class Config_DataModelReader;
48 class XGUI_ActionsMgr;
49 class XGUI_ActiveControlMgr;
50 class XGUI_ContextMenuMgr;
52 class XGUI_ErrorDialog;
54 class XGUI_FacesPanel;
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 class XGUI_InspectionPanel;
68 class ModuleBase_IModule;
69 class ModuleBase_IViewer;
70 class ModuleBase_Operation;
77 /// \class XGUI_Workshop
79 /// \brief Class which defines a configuration of the application (Workshop) and launches it.
80 class XGUI_EXPORT XGUI_Workshop : public QObject
85 /// \param theConnector a Salome connector object.
86 /// Used only if the workshop is launched in Salome environment
87 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
88 virtual ~XGUI_Workshop();
90 /// Starting of the application
91 void startApplication();
93 /// Activates the module controls. Should be called after module creation
94 void activateModule();
96 /// Deactivates the module controls. Should be called after module creation
97 void deactivateModule();
100 /// Returns main window (Desktop) of the application
101 AppElements_MainWindow* mainWindow() const { return myMainWindow; }
103 /// Creates and adds a new workbench (menu group) with the given name and returns it
104 AppElements_Workbench* addWorkbench(const QString& theName);
107 /// Returns selection manager object
108 XGUI_SelectionMgr* selector() const { return mySelector; }
110 /// Returns selection activating object
111 XGUI_SelectionActivate* selectionActivate() const { return mySelectionActivate; }
113 /// Returns displayer
114 XGUI_Displayer* displayer() const { return myDisplayer; }
116 /// Returns operation manager.
117 XGUI_OperationMgr* operationMgr() const { return myOperationMgr; }
119 /// Returns error manager.
120 XGUI_ErrorMgr* errorMgr() const { return myErrorMgr; }
122 /// Returns an actions manager
123 XGUI_ActionsMgr* actionsMgr() const { return myActionsMgr; }
125 /// Returns an active control manager
126 XGUI_ActiveControlMgr* activeControlMgr() const { return myActiveControlMgr; }
128 /// Returns an actions manager
129 XGUI_MenuMgr* menuMgr() const { return myMenuMgr; }
131 /// Returns property panel widget
132 XGUI_PropertyPanel* propertyPanel() const { return myPropertyPanel; }
134 /// Returns property panel widget
135 XGUI_InspectionPanel* inspectionPanel() const { return myInspectionPanel; }
137 /// Returns panel for hide object faces
138 XGUI_FacesPanel* facesPanel() const { return myFacesPanel; }
140 /// Returns context menu manager object
141 XGUI_ContextMenuMgr* contextMenuMgr() const { return myContextMenuMgr; }
143 /// Returns an object which provides interface to Salome Module (LightApp_Module)
144 XGUI_SalomeConnector* salomeConnector() const { return mySalomeConnector; }
146 /// Provides an object which provides interface to Salome Viewer
147 ModuleBase_IViewer* salomeViewer() const;
149 /// Returns true if the application works as SALOME module
150 bool isSalomeMode() const { return mySalomeConnector != 0; }
152 /// Returns Object browser
153 XGUI_ObjectsBrowser* objectBrowser() const { return myObjectBrowser; }
155 /// This method is called by Salome module when selection is changed
156 void salomeViewerSelectionChanged();
158 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
159 XGUI_ViewerProxy* viewer() const { return myViewerProxy; }
161 /// Returns the module connector
162 /// \returns the instance of connector
163 XGUI_ModuleConnector* moduleConnector() const { return myModuleConnector; }
165 /// Returns a desktop
166 /// \return a desktop instance
167 QMainWindow* desktop() const;
169 /// If faces panel made the object hidden, show message box whether the object should be
170 /// restored (removed from the panel) and displayed, if answer is No, returns false
171 /// \param theObject a model object
172 /// \return boolean state if the object should not be displayed
173 virtual bool prepareForDisplay(const std::set<ObjectPtr>& theObjects) const;
176 void deleteObjects();
178 /// Searches for selected features unused in other (not selected) features. If one or several
179 /// selected features are found, a warning message proposes to delete them. It contains
180 /// the list of features to be deleted.
183 /// Returns true if the selected feature can be moved to the position after the current feature
184 /// \return boolean value
185 bool canMoveFeature();
187 /// Move selected features to be after the current feature
190 /// Returns true if the object can be shaded. If the object is a compsolid result, the method
191 /// checks subobjects of the result
192 /// \return boolean value
193 bool canBeShaded(const ObjectPtr& theObject) const;
195 /// Returns true if there is at least one selected body/construction/group result
196 /// \param theActionName text of the checked action
197 /// \return boolean value
198 bool canChangeProperty(const QString& theActionName) const;
200 /// Change color 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 changeColor(const QObjectPtrList& theObjects);
205 /// Change deflection of the results if it is possible
206 /// The operation is available for construction, body and group results
207 /// theObjects a list of selected objects
208 void changeDeflection(const QObjectPtrList& theObjects);
210 /// Change transparency of the results if it is possible
211 /// The operation is available for construction, body and group results
212 /// theObjects a list of selected objects
213 void changeTransparency(const QObjectPtrList& theObjects);
215 /// Show the given features in 3d Viewer
216 void showObjects(const QObjectPtrList& theList, bool isVisible);
218 /// Show the given features in 3d Viewer
219 void showOnlyObjects(const QObjectPtrList& theList);
221 /// Set display mode for the given objects
222 /// \param theList a list of displayed objects
223 /// \param theMode a mode to set (see \ref XGUI_Displayer)
224 void setDisplayMode(const QObjectPtrList& theList, int theMode);
226 /// Set selection mode in viewer. If theMode=-1 then activate default mode
227 /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
228 void setViewerSelectionMode(int theMode);
230 /// Activates current selection mode for the given list of objects
231 void activateObjectsSelection(const QObjectPtrList& theList);
233 /// Returns current module
234 ModuleBase_IModule* module() const { return myModule; }
236 /// Returns current directory which contains data files
237 QString currentDataDir() const { return myCurrentDir; }
239 /// Returns current directory which contains data files
240 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
242 /// Save the current document into a directory
243 /// \param theName - path to the directory
244 /// \param theFileNames - returned file names created in this directory
245 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
247 /// If there is an active (uncommitted) operation shows a prompt to abort it
248 /// and performs abortion if user agreed. Returns true if
249 /// - operation aborted successfully
250 /// - there is no active operation
251 bool abortAllOperations();
253 /// Updates workshop state according to the started operation, e.g. visualizes the property panel
254 /// and connect to it.
255 /// \param theOpertion a started operation
256 void operationStarted(ModuleBase_Operation* theOperation);
258 /// Delete features. Delete the referenced features. There can be a question with a list of
259 /// referenced objects.
260 /// \param theFeatures a list of objects to be deleted
261 bool deleteFeatures(const QObjectPtrList& theFeatures);
263 /// Deactivates the object, if it is active and the module returns that the activation
264 /// of selection for the object is not possible currently(the current operation uses it)
265 /// \param theObject an object
266 /// \param theUpdateViewer a boolean flag to update viewer immediately
267 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
269 /// Returns true if the action of the feature is created to contain Accept/Cancel button
270 /// \param theFeature a feature
271 bool isFeatureOfNested(const FeaturePtr& theFeature);
273 /// Shows the message in the status bar
274 /// \param theMessage a message
275 void setStatusBarMessage(const QString& theMessage);
278 /// Has to be called in order to display objects with visibility status = true
279 void synchronizeViewer();
281 /// Has to be called in order to display objects from a specifed group
282 /// with visibility status = true
283 /// \param theDoc the document for objects synchronisation
284 /// \param theGroup the group name
285 /// \param theUpdateViewer update viewer flag
286 void synchronizeGroupInViewer(const DocumentPtr& theDoc,
287 const std::string& theGroup,
288 bool theUpdateViewer);
291 /// Update the property panel content by the XML description of the operation and set the panel
292 /// into the operation
293 /// \param theOperation an operation
294 void fillPropertyPanel(ModuleBase_Operation* theOperation);
296 /// Connects or disconnects to the value changed signal of the property panel widgets
297 /// \param isToConnect a boolean value whether connect or disconnect
298 void connectToPropertyPanel(const bool isToConnect);
300 /// Returns defailt selection mode in 3d viewer
301 QIntList viewerSelectionModes() const { return myViewerSelMode; }
303 /// Highlights result objects in Object Browser according to
304 /// features found in the given list
305 void highlightResults(const QObjectPtrList& theObjects);
307 /// Highlights feature objects in Object Browser according to
308 /// features found in the given list
309 void highlightFeature(const QObjectPtrList& theObjects);
311 /// Returns Data Model XML reader which contains information about
312 /// Data structure configuration
313 const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
315 /// A constant string used for "Move to end" command definition
316 /// It is used for specific processing of Undo/Redo for this command.
317 static QString MOVE_TO_END_COMMAND;
319 /// Closes all in the current session and load the directory
320 /// \param theDirectory a path to directory
321 void openDirectory(const QString& theDirectory);
324 /// Emitted when selection happens in Salome viewer
325 void salomeViewerSelection();
327 /// the signal about the workshop actions states are updated.
328 void commandStatusUpdated();
330 /// the application is started
331 void applicationStarted();
333 /// Signal to update Undo history list
334 void updateUndoHistory(const QList<ActionInfo>&);
336 /// Signal to update Redo history list
337 void updateRedoHistory(const QList<ActionInfo>&);
340 /// Update of commands status
341 void updateCommandStatus();
343 /// update history list (undo/redo commands)
344 void updateHistory();
346 /// Save current document
349 /// Save current document to a file selected by user
352 /// Undo last command
353 void onUndo(int times = 1);
355 /// Redo previous command
356 void onRedo(int times = 1);
358 /// Validates the operation to change the "Apply" button state.
359 /// \param thePreviousState the previous state of the widget
360 void onWidgetStateChanged(int thePreviousState);
362 /// Calls activate of the current widget again. It is possible that selection filters are
363 /// differs in the new state of paged container
364 void onValuesChanged();
366 /// Listens the corresponded signal of model widget and updates Apply button state by feature
367 void onWidgetObjectUpdated();
369 /// Show dock widget panel
370 void showPanel(QDockWidget* theDockWidget);
372 /// Hide dock widget panel
373 void hidePanel(QDockWidget* theDockWidget);
375 /// Show object Browser
376 void showObjectBrowser();
378 /// Hide object Browser
379 void hideObjectBrowser();
382 void closeDocument();
384 /// Open document from file
387 /// Create a new document
394 /// Open preferences dialog box
395 void onPreferences();
398 /// Activates/deactivates the trihedron in the viewer AIS context
399 void onTrihedronVisibilityChanged(bool theState);
401 /// Apply the current transparency value if preview in transparency dialog is switched on
402 void onTransparencyValueChanged();
404 /// Switch on/off preview of transparency change
405 void onPreviewStateChanged();
408 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
409 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
410 /// \param theOperation an operation
411 void setGrantedFeatures(ModuleBase_Operation* theOperation);
414 /// Display results from document
415 /// \param theDoc a document
416 void displayDocumentResults(DocumentPtr theDoc);
418 /// Display results from a group
419 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
421 /// Insert folder object before currently selected feature
422 void insertFeatureFolder();
424 /// Insert an object to a folder above or below
425 void insertToFolder(bool isBefore);
427 /// Insert an object to a folder above or below
428 void moveOutFolder(bool isBefore);
431 /// SLOT, that is called after the operation is resumed. Update workshop state according to
432 /// the started operation, e.g. visualizes the property panel and connect to it.
433 /// \param theOpertion a resumed operation
434 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
436 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
437 /// hides the property panel and update the command status.
438 /// \param theOpertion a stopped operation
439 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
441 /// SLOT, that is called after the operation is committed.
442 /// \param theOpertion a committed operation
443 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
445 /// SLOT, that is called after the operation is aborted.
446 /// \param theOpertion an aborted operation
447 void onOperationAborted(ModuleBase_Operation* theOperation);
449 /// Slot, which reacts to the context popup menu call
450 /// \param theId the data value of the clicked action
451 /// \param isChecked a state of toggle if the action is checkable
452 void onContextMenuCommand(const QString& theId, bool isChecked);
454 /// Set waiting cursor
455 void onStartWaiting();
457 /// Called by Ok 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 onAcceptActionClicked();
461 /// Called by OkPlus button clicked in the property panel. Asks the error manager whether
462 /// the operation can be committed and do it if it returns true.
463 void onAcceptPlusActionClicked();
465 /// Called by Preview button clicked in the property panel. Sends signal to model to
467 void onPreviewActionClicked();
469 /// Called on help button clicked in the property panel.
470 void onHelpActionClicked();
476 /// Register validators
477 void registerValidators() const;
479 /// Load module from external library
480 /// \param theModule name of the module
481 ModuleBase_IModule* loadModule(const QString& theModule);
486 /// Create object browser widget
487 /// \param theParent a parent of widget
488 QDockWidget* createObjectBrowser(QWidget* theParent);
490 // Creates Dock widgets: Object browser and Property panel
491 void createDockWidgets();
493 /// Extends undo/redo toolbutton's with history menu
494 /// \param theObject - in the OpenParts it is a QToolButton by itself,
495 /// in salome mode - QAction that creates a button.
496 /// \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
497 /// \param theSlot - onUndo(int) or onRedo(int) SLOT
498 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
500 /// Creates list of actions (commands) by given history list from session
501 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
503 /// Pefrom Undo/Redo and necessary workshop updates(viewer, browser, actions state)
504 /// \param theActionType a type of the action (Undo or Redo)
505 /// \param theTimes number of applies the given action
506 void processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes);
510 AppElements_MainWindow* myMainWindow; ///< desktop window
513 ModuleBase_IModule* myModule; ///< current module
514 XGUI_ErrorMgr* myErrorMgr; ///< updator of error message
515 XGUI_ObjectsBrowser* myObjectBrowser; ///< data tree widget
516 XGUI_PropertyPanel* myPropertyPanel; ///< container of feature attributes widgets
517 XGUI_FacesPanel* myFacesPanel; ///< panel for hide object faces
518 XGUI_SelectionMgr* mySelector; ///< handler of selection processing
519 XGUI_SelectionActivate* mySelectionActivate; /// manager of selection activating
520 XGUI_Displayer* myDisplayer; ///< handler of objects display
521 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
522 XGUI_ActionsMgr* myActionsMgr; ///< manager of workshop actions
523 XGUI_ActiveControlMgr* myActiveControlMgr; ///< manager to have none or one active control
524 XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
525 XGUI_SalomeConnector* mySalomeConnector; ///< connector to SALOME module interface
526 XGUI_ErrorDialog* myErrorDlg; ///< dialog to show information of occured error events
527 XGUI_ViewerProxy* myViewerProxy; ///< connector to SALOME viewer interface
528 XGUI_ContextMenuMgr* myContextMenuMgr; ///< manager of context menu build
529 XGUI_ModuleConnector* myModuleConnector; ///< implementation of ModuleBase_IWorkshop
530 XGUI_WorkshopListener* myEventsListener; ///< processing of events
531 QString myCurrentDir; ///< cached the last open directory
532 QIntList myViewerSelMode; ///< selection modes set in the viewer
533 Config_DataModelReader* myDataModelXMLReader; ///< XML reader of data model
534 XGUI_InspectionPanel* myInspectionPanel; ///< container of feature attributes widgets