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;
67 class ModuleBase_IModule;
68 class ModuleBase_IViewer;
69 class ModuleBase_Operation;
76 /// \class XGUI_Workshop
78 /// \brief Class which defines a configuration of the application (Workshop) and launches it.
79 class XGUI_EXPORT XGUI_Workshop : public QObject
84 /// \param theConnector a Salome connector object.
85 /// Used only if the workshop is launched in Salome environment
86 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
87 virtual ~XGUI_Workshop();
89 /// Starting of the application
90 void startApplication();
92 /// Activates the module controls. Should be called after module creation
93 void activateModule();
95 /// Deactivates the module controls. Should be called after module creation
96 void deactivateModule();
99 /// Returns main window (Desktop) of the application
100 AppElements_MainWindow* mainWindow() const { return myMainWindow; }
102 /// Creates and adds a new workbench (menu group) with the given name and returns it
103 AppElements_Workbench* addWorkbench(const QString& theName);
106 /// Returns selection manager object
107 XGUI_SelectionMgr* selector() const { return mySelector; }
109 /// Returns selection activating object
110 XGUI_SelectionActivate* selectionActivate() const { return mySelectionActivate; }
112 /// Returns displayer
113 XGUI_Displayer* displayer() const { return myDisplayer; }
115 /// Returns operation manager.
116 XGUI_OperationMgr* operationMgr() const { return myOperationMgr; }
118 /// Returns error manager.
119 XGUI_ErrorMgr* errorMgr() const { return myErrorMgr; }
121 /// Returns an actions manager
122 XGUI_ActionsMgr* actionsMgr() const { return myActionsMgr; }
124 /// Returns an active control manager
125 XGUI_ActiveControlMgr* activeControlMgr() const { return myActiveControlMgr; }
127 /// Returns an actions manager
128 XGUI_MenuMgr* menuMgr() const { return myMenuMgr; }
130 /// Returns property panel widget
131 XGUI_PropertyPanel* propertyPanel() const { return myPropertyPanel; }
133 /// Returns panel for hide object faces
134 XGUI_FacesPanel* facesPanel() const { return myFacesPanel; }
136 /// Returns context menu manager object
137 XGUI_ContextMenuMgr* contextMenuMgr() const { return myContextMenuMgr; }
139 /// Returns an object which provides interface to Salome Module (LightApp_Module)
140 XGUI_SalomeConnector* salomeConnector() const { return mySalomeConnector; }
142 /// Provides an object which provides interface to Salome Viewer
143 ModuleBase_IViewer* salomeViewer() const;
145 /// Returns true if the application works as SALOME module
146 bool isSalomeMode() const { return mySalomeConnector != 0; }
148 /// Returns Object browser
149 XGUI_ObjectsBrowser* objectBrowser() const { return myObjectBrowser; }
151 /// This method is called by Salome module when selection is changed
152 void salomeViewerSelectionChanged();
154 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
155 XGUI_ViewerProxy* viewer() const { return myViewerProxy; }
157 /// Returns the module connector
158 /// \returns the instance of connector
159 XGUI_ModuleConnector* moduleConnector() const { return myModuleConnector; }
161 /// Returns a desktop
162 /// \return a desktop instance
163 QMainWindow* desktop() const;
165 /// If faces panel made the object hidden, show message box whether the object should be
166 /// restored (removed from the panel) and displayed, if answer is No, returns false
167 /// \param theObject a model object
168 /// \return boolean state if the object should not be displayed
169 virtual bool prepareForDisplay(const std::set<ObjectPtr>& theObjects) const;
172 void deleteObjects();
174 /// Searches for selected features unused in other (not selected) features. If one or several
175 /// selected features are found, a warning message proposes to delete them. It contains
176 /// the list of features to be deleted.
179 /// Returns true if the selected feature can be moved to the position after the current feature
180 /// \return boolean value
181 bool canMoveFeature();
183 /// Move selected features to be after the current feature
186 /// Returns true if the object can be shaded. If the object is a compsolid result, the method
187 /// checks subobjects of the result
188 /// \return boolean value
189 bool canBeShaded(const ObjectPtr& theObject) const;
191 /// Returns true if there is at least one selected body/construction/group result
192 /// \param theActionName text of the checked action
193 /// \return boolean value
194 bool canChangeProperty(const QString& theActionName) const;
196 /// Change color of the results if it is possible
197 /// The operation is available for construction, body and group results
198 /// theObjects a list of selected objects
199 void changeColor(const QObjectPtrList& theObjects);
201 /// Change deflection 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 changeDeflection(const QObjectPtrList& theObjects);
206 /// Change transparency 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 changeTransparency(const QObjectPtrList& theObjects);
211 /// Show the given features in 3d Viewer
212 void showObjects(const QObjectPtrList& theList, bool isVisible);
214 /// Show the given features in 3d Viewer
215 void showOnlyObjects(const QObjectPtrList& theList);
217 /// Set display mode for the given objects
218 /// \param theList a list of displayed objects
219 /// \param theMode a mode to set (see \ref XGUI_Displayer)
220 void setDisplayMode(const QObjectPtrList& theList, int theMode);
222 /// Set selection mode in viewer. If theMode=-1 then activate default mode
223 /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
224 void setViewerSelectionMode(int theMode);
226 /// Activates current selection mode for the given list of objects
227 void activateObjectsSelection(const QObjectPtrList& theList);
229 /// Returns current module
230 ModuleBase_IModule* module() const { return myModule; }
232 /// Returns current directory which contains data files
233 QString currentDataDir() const { return myCurrentDir; }
235 /// Returns current directory which contains data files
236 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
238 /// Save the current document into a directory
239 /// \param theName - path to the directory
240 /// \param theFileNames - returned file names created in this directory
241 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
243 /// If there is an active (uncommitted) operation shows a prompt to abort it
244 /// and performs abortion if user agreed. Returns true if
245 /// - operation aborted successfully
246 /// - there is no active operation
247 bool abortAllOperations();
249 /// Updates workshop state according to the started operation, e.g. visualizes the property panel
250 /// and connect to it.
251 /// \param theOpertion a started operation
252 void operationStarted(ModuleBase_Operation* theOperation);
254 /// Delete features. Delete the referenced features. There can be a question with a list of
255 /// referenced objects.
256 /// \param theFeatures a list of objects to be deleted
257 bool deleteFeatures(const QObjectPtrList& theFeatures);
259 /// Deactivates the object, if it is active and the module returns that the activation
260 /// of selection for the object is not possible currently(the current operation uses it)
261 /// \param theObject an object
262 /// \param theUpdateViewer a boolean flag to update viewer immediately
263 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
265 /// Returns true if the action of the feature is created to contain Accept/Cancel button
266 /// \param theFeature a feature
267 bool isFeatureOfNested(const FeaturePtr& theFeature);
269 /// Shows the message in the status bar
270 /// \param theMessage a message
271 void setStatusBarMessage(const QString& theMessage);
274 /// Has to be called in order to display objects with visibility status = true
275 void synchronizeViewer();
277 /// Has to be called in order to display objects from a specifed group
278 /// with visibility status = true
279 /// \param theDoc the document for objects synchronisation
280 /// \param theGroup the group name
281 /// \param theUpdateViewer update viewer flag
282 void synchronizeGroupInViewer(const DocumentPtr& theDoc,
283 const std::string& theGroup,
284 bool theUpdateViewer);
287 /// Update the property panel content by the XML description of the operation and set the panel
288 /// into the operation
289 /// \param theOperation an operation
290 void fillPropertyPanel(ModuleBase_Operation* theOperation);
292 /// Connects or disconnects to the value changed signal of the property panel widgets
293 /// \param isToConnect a boolean value whether connect or disconnect
294 void connectToPropertyPanel(const bool isToConnect);
296 /// Returns defailt selection mode in 3d viewer
297 QIntList viewerSelectionModes() const { return myViewerSelMode; }
299 /// Highlights result objects in Object Browser according to
300 /// features found in the given list
301 void highlightResults(const QObjectPtrList& theObjects);
303 /// Highlights feature objects in Object Browser according to
304 /// features found in the given list
305 void highlightFeature(const QObjectPtrList& theObjects);
307 /// Returns Data Model XML reader which contains information about
308 /// Data structure configuration
309 const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
311 /// A constant string used for "Move to end" command definition
312 /// It is used for specific processing of Undo/Redo for this command.
313 static QString MOVE_TO_END_COMMAND;
315 /// Closes all in the current session and load the directory
316 /// \param theDirectory a path to directory
317 void openDirectory(const QString& theDirectory);
320 /// Emitted when selection happens in Salome viewer
321 void salomeViewerSelection();
323 /// the signal about the workshop actions states are updated.
324 void commandStatusUpdated();
326 /// the application is started
327 void applicationStarted();
329 /// Signal to update Undo history list
330 void updateUndoHistory(const QList<ActionInfo>&);
332 /// Signal to update Redo history list
333 void updateRedoHistory(const QList<ActionInfo>&);
336 /// Update of commands status
337 void updateCommandStatus();
339 /// update history list (undo/redo commands)
340 void updateHistory();
342 /// Save current document
345 /// Save current document to a file selected by user
348 /// Undo last command
349 void onUndo(int times = 1);
351 /// Redo previous command
352 void onRedo(int times = 1);
354 /// Validates the operation to change the "Apply" button state.
355 /// \param thePreviousState the previous state of the widget
356 void onWidgetStateChanged(int thePreviousState);
358 /// Calls activate of the current widget again. It is possible that selection filters are
359 /// differs in the new state of paged container
360 void onValuesChanged();
362 /// Listens the corresponded signal of model widget and updates Apply button state by feature
363 void onWidgetObjectUpdated();
365 /// Show dock widget panel
366 void showPanel(QDockWidget* theDockWidget);
368 /// Hide dock widget panel
369 void hidePanel(QDockWidget* theDockWidget);
371 /// Show object Browser
372 void showObjectBrowser();
374 /// Hide object Browser
375 void hideObjectBrowser();
378 void closeDocument();
380 /// Open document from file
383 /// Create a new document
390 /// Open preferences dialog box
391 void onPreferences();
394 /// Activates/deactivates the trihedron in the viewer AIS context
395 void onTrihedronVisibilityChanged(bool theState);
397 /// Apply the current transparency value if preview in transparency dialog is switched on
398 void onTransparencyValueChanged();
400 /// Switch on/off preview of transparency change
401 void onPreviewStateChanged();
404 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
405 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
406 /// \param theOperation an operation
407 void setGrantedFeatures(ModuleBase_Operation* theOperation);
410 /// Display results from document
411 /// \param theDoc a document
412 void displayDocumentResults(DocumentPtr theDoc);
414 /// Display results from a group
415 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
417 /// Insert folder object before currently selected feature
418 void insertFeatureFolder();
420 /// Insert an object to a folder above or below
421 void insertToFolder(bool isBefore);
423 /// Insert an object to a folder above or below
424 void moveOutFolder(bool isBefore);
427 /// SLOT, that is called after the operation is resumed. Update workshop state according to
428 /// the started operation, e.g. visualizes the property panel and connect to it.
429 /// \param theOpertion a resumed operation
430 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
432 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
433 /// hides the property panel and update the command status.
434 /// \param theOpertion a stopped operation
435 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
437 /// SLOT, that is called after the operation is committed.
438 /// \param theOpertion a committed operation
439 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
441 /// SLOT, that is called after the operation is aborted.
442 /// \param theOpertion an aborted operation
443 void onOperationAborted(ModuleBase_Operation* theOperation);
445 /// Slot, which reacts to the context popup menu call
446 /// \param theId the data value of the clicked action
447 /// \param isChecked a state of toggle if the action is checkable
448 void onContextMenuCommand(const QString& theId, bool isChecked);
450 /// Set waiting cursor
451 void onStartWaiting();
453 /// Called by Ok button clicked in the property panel. Asks the error manager whether
454 /// the operation can be committed and do it if it returns true.
455 void onAcceptActionClicked();
457 /// Called by OkPlus 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 onAcceptPlusActionClicked();
461 /// Called by Preview button clicked in the property panel. Sends signal to model to
463 void onPreviewActionClicked();
469 /// Register validators
470 void registerValidators() const;
472 /// Load module from external library
473 /// \param theModule name of the module
474 ModuleBase_IModule* loadModule(const QString& theModule);
479 /// Create object browser widget
480 /// \param theParent a parent of widget
481 QDockWidget* createObjectBrowser(QWidget* theParent);
483 /// Create property panel widget
484 /// \param theParent a parent of widget
485 QDockWidget* createPropertyPanel(QWidget* theParent);
487 // Creates Dock widgets: Object browser and Property panel
488 void createDockWidgets();
490 /// Extends undo/redo toolbutton's with history menu
491 /// \param theObject - in the OpenParts it is a QToolButton by itself,
492 /// in salome mode - QAction that creates a button.
493 /// \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
494 /// \param theSlot - onUndo(int) or onRedo(int) SLOT
495 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
497 /// Creates list of actions (commands) by given history list from session
498 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
500 /// Pefrom Undo/Redo and necessary workshop updates(viewer, browser, actions state)
501 /// \param theActionType a type of the action (Undo or Redo)
502 /// \param theTimes number of applies the given action
503 void processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes);
507 AppElements_MainWindow* myMainWindow; ///< desktop window
510 ModuleBase_IModule* myModule; ///< current module
511 XGUI_ErrorMgr* myErrorMgr; ///< updator of error message
512 XGUI_ObjectsBrowser* myObjectBrowser; ///< data tree widget
513 XGUI_PropertyPanel* myPropertyPanel; ///< container of feature attributes widgets
514 XGUI_FacesPanel* myFacesPanel; ///< panel for hide object faces
515 XGUI_SelectionMgr* mySelector; ///< handler of selection processing
516 XGUI_SelectionActivate* mySelectionActivate; /// manager of selection activating
517 XGUI_Displayer* myDisplayer; ///< handler of objects display
518 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
519 XGUI_ActionsMgr* myActionsMgr; ///< manager of workshop actions
520 XGUI_ActiveControlMgr* myActiveControlMgr; ///< manager to have none or one active control
521 XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
522 XGUI_SalomeConnector* mySalomeConnector; ///< connector to SALOME module interface
523 XGUI_ErrorDialog* myErrorDlg; ///< dialog to show information of occured error events
524 XGUI_ViewerProxy* myViewerProxy; ///< connector to SALOME viewer interface
525 XGUI_ContextMenuMgr* myContextMenuMgr; ///< manager of context menu build
526 XGUI_ModuleConnector* myModuleConnector; ///< implementation of ModuleBase_IWorkshop
527 XGUI_WorkshopListener* myEventsListener; ///< processing of events
528 QString myCurrentDir; ///< cached the last open directory
529 QIntList myViewerSelMode; ///< selection modes set in the viewer
530 Config_DataModelReader* myDataModelXMLReader; ///< XML reader of data model