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);
267 /// Update the property panel content by the XML description of the operation and set the panel
268 /// into the operation
269 /// \param theOperation an operation
270 void fillPropertyPanel(ModuleBase_Operation* theOperation);
272 /// Connects or disconnects to the value changed signal of the property panel widgets
273 /// \param isToConnect a boolean value whether connect or disconnect
274 void connectToPropertyPanel(const bool isToConnect);
276 /// Returns defailt selection mode in 3d viewer
277 QIntList viewerSelectionModes() const { return myViewerSelMode; }
279 /// Highlights result objects in Object Browser according to
280 /// features found in the given list
281 void highlightResults(const QObjectPtrList& theObjects);
283 /// Highlights feature objects in Object Browser according to
284 /// features found in the given list
285 void highlightFeature(const QObjectPtrList& theObjects);
287 /// Returns Data Model XML reader which contains information about
288 /// Data structure configuration
289 const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
291 /// A constant string used for "Move to end" command definition
292 /// It is used for specific processing of Undo/Redo for this command.
293 static QString MOVE_TO_END_COMMAND;
295 /// Closes all in the current session and load the directory
296 /// \param theDirectory a path to directory
297 void openDirectory(const QString& theDirectory);
300 /// Emitted when selection happens in Salome viewer
301 void salomeViewerSelection();
303 /// the signal about the workshop actions states are updated.
304 void commandStatusUpdated();
306 /// the application is started
307 void applicationStarted();
309 /// Signal to update Undo history list
310 void updateUndoHistory(const QList<ActionInfo>&);
312 /// Signal to update Redo history list
313 void updateRedoHistory(const QList<ActionInfo>&);
316 /// Update of commands status
317 void updateCommandStatus();
319 /// update history list (undo/redo commands)
320 void updateHistory();
322 /// Save current document
325 /// Save current document to a file selected by user
328 /// Undo last command
329 void onUndo(int times = 1);
331 /// Redo previous command
332 void onRedo(int times = 1);
334 /// Validates the operation to change the "Apply" button state.
335 /// \param thePreviousState the previous state of the widget
336 void onWidgetStateChanged(int thePreviousState);
338 /// Calls activate of the current widget again. It is possible that selection filters are
339 /// differs in the new state of paged container
340 void onValuesChanged();
342 /// Listens the corresponded signal of model widget and updates Apply button state by feature
343 void onWidgetObjectUpdated();
345 /// Show dock widget panel
346 void showPanel(QDockWidget* theDockWidget);
348 /// Hide dock widget panel
349 void hidePanel(QDockWidget* theDockWidget);
351 /// Show object Browser
352 void showObjectBrowser();
354 /// Hide object Browser
355 void hideObjectBrowser();
358 void closeDocument();
360 /// Open document from file
363 /// Create a new document
370 /// Open preferences dialog box
371 void onPreferences();
374 /// Activates/deactivates the trihedron in the viewer AIS context
375 void onTrihedronVisibilityChanged(bool theState);
377 /// Apply the current transparency value if preview in transparency dialog is switched on
378 void onTransparencyValueChanged();
380 /// Switch on/off preview of transparency change
381 void onPreviewStateChanged();
384 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
385 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
386 /// \param theOperation an operation
387 void setGrantedFeatures(ModuleBase_Operation* theOperation);
390 /// Display results from document
391 /// \param theDoc a document
392 void displayDocumentResults(DocumentPtr theDoc);
394 /// Display results from a group
395 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
397 /// Insert folder object before currently selected feature
398 void insertFeatureFolder();
400 /// Insert an object to a folder above or below
401 void insertToFolder(bool isBefore);
403 /// Insert an object to a folder above or below
404 void moveOutFolder(bool isBefore);
407 /// SLOT, that is called after the operation is resumed. Update workshop state according to
408 /// the started operation, e.g. visualizes the property panel and connect to it.
409 /// \param theOpertion a resumed operation
410 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
412 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
413 /// hides the property panel and update the command status.
414 /// \param theOpertion a stopped operation
415 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
417 /// SLOT, that is called after the operation is committed.
418 /// \param theOpertion a committed operation
419 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
421 /// SLOT, that is called after the operation is aborted.
422 /// \param theOpertion an aborted operation
423 void onOperationAborted(ModuleBase_Operation* theOperation);
425 /// Slot, which reacts to the context popup menu call
426 /// \param theId the data value of the clicked action
427 /// \param isChecked a state of toggle if the action is checkable
428 void onContextMenuCommand(const QString& theId, bool isChecked);
430 /// Set waiting cursor
431 void onStartWaiting();
433 /// Called by Ok button clicked in the property panel. Asks the error manager whether
434 /// the operation can be committed and do it if it returns true.
435 void onAcceptActionClicked();
437 /// Called by Preview button clicked in the property panel. Sends signal to model to
439 void onPreviewActionClicked();
445 /// Register validators
446 void registerValidators() const;
448 /// Load module from external library
449 /// \param theModule name of the module
450 ModuleBase_IModule* loadModule(const QString& theModule);
455 /// Create object browser widget
456 /// \param theParent a parent of widget
457 QDockWidget* createObjectBrowser(QWidget* theParent);
459 /// Create property panel widget
460 /// \param theParent a parent of widget
461 QDockWidget* createPropertyPanel(QWidget* theParent);
463 // Creates Dock widgets: Object browser and Property panel
464 void createDockWidgets();
466 /// Extends undo/redo toolbutton's with history menu
467 /// \param theObject - in the OpenParts it is a QToolButton by itself,
468 /// in salome mode - QAction that creates a button.
469 /// \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
470 /// \param theSlot - onUndo(int) or onRedo(int) SLOT
471 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
473 /// Creates list of actions (commands) by given history list from session
474 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
476 /// Pefrom Undo/Redo and necessary workshop updates(viewer, browser, actions state)
477 /// \param theActionType a type of the action (Undo or Redo)
478 /// \param theTimes number of applies the given action
479 void processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes);
483 AppElements_MainWindow* myMainWindow; ///< desktop window
486 ModuleBase_IModule* myModule; ///< current module
487 XGUI_ErrorMgr* myErrorMgr; ///< updator of error message
488 XGUI_ObjectsBrowser* myObjectBrowser; ///< data tree widget
489 XGUI_PropertyPanel* myPropertyPanel; ///< container of feature attributes widgets
490 XGUI_FacesPanel* myFacesPanel; ///< panel for hide object faces
491 XGUI_SelectionMgr* mySelector; ///< handler of selection processing
492 XGUI_Displayer* myDisplayer; ///< handler of objects display
493 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
494 XGUI_ActionsMgr* myActionsMgr; ///< manager of workshop actions
495 XGUI_ActiveControlMgr* myActiveControlMgr; ///< manager to have none or one active control
496 XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
497 XGUI_SalomeConnector* mySalomeConnector; ///< connector to SALOME module interface
498 XGUI_ErrorDialog* myErrorDlg; ///< dialog to show information of occured error events
499 XGUI_ViewerProxy* myViewerProxy; ///< connector to SALOME viewer interface
500 XGUI_ContextMenuMgr* myContextMenuMgr; ///< manager of context menu build
501 XGUI_ModuleConnector* myModuleConnector; ///< implementation of ModuleBase_IWorkshop
502 XGUI_WorkshopListener* myEventsListener; ///< processing of events
503 QString myCurrentDir; ///< cached the last open directory
504 QIntList myViewerSelMode; ///< selection modes set in the viewer
505 Config_DataModelReader* myDataModelXMLReader; ///< XML reader of data model