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