1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #ifndef XGUI_WORKSHOP_H
4 #define XGUI_WORKSHOP_H
7 //#include "XGUI_Constants.h"
8 #include <ModuleBase_Definitions.h>
9 #include <ModelAPI_Document.h>
10 #include <ModelAPI_Feature.h>
12 #include <ModuleBase_ActionInfo.h>
16 #include <QKeySequence>
20 class AppElements_MainWindow;
21 class AppElements_Command;
22 class AppElements_Workbench;
25 class XGUI_ActionsMgr;
26 class XGUI_ContextMenuMgr;
28 class XGUI_ErrorDialog;
31 class XGUI_ModuleConnector;
32 class XGUI_ObjectsBrowser;
33 class XGUI_OperationMgr;
34 class XGUI_PropertyPanel;
35 class XGUI_SalomeConnector;
36 class XGUI_SalomeViewer;
37 class XGUI_SelectionMgr;
38 class XGUI_ViewerProxy;
39 class XGUI_WorkshopListener;
41 class ModuleBase_IModule;
42 class ModuleBase_IViewer;
43 class ModuleBase_Operation;
50 class Config_DataModelReader;
52 /**\class XGUI_Workshop
54 * \brief Class which defines a configuration of the application (Workshop) and launches it.
56 class XGUI_EXPORT XGUI_Workshop : public QObject
61 /// \param theConnector a Salome connector object.
62 /// Used only if the workshop is launched in Salome environment
63 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
64 virtual ~XGUI_Workshop();
66 //! Starting of the application
67 void startApplication();
69 /// Activates the module controls. Should be called after module creation
70 void activateModule();
72 /// Deactivates the module controls. Should be called after module creation
73 void deactivateModule();
76 //! Returns main window (Desktop) of the application
77 AppElements_MainWindow* mainWindow() const
82 //! Creates and adds a new workbench (menu group) with the given name and returns it
83 AppElements_Workbench* addWorkbench(const QString& theName);
86 //! Returns selection manager object
87 XGUI_SelectionMgr* selector() const
93 XGUI_Displayer* displayer() const
98 //! ! Returns operation manager.
99 XGUI_OperationMgr* operationMgr() const
101 return myOperationMgr;
104 //! ! Returns error manager.
105 XGUI_ErrorMgr* errorMgr() const
110 //! ! Returns an actions manager
111 XGUI_ActionsMgr* actionsMgr() const
116 //! ! Returns an actions manager
117 XGUI_MenuMgr* menuMgr() const
122 //! Returns property panel widget
123 XGUI_PropertyPanel* propertyPanel() const
125 return myPropertyPanel;
128 //! Returns context menu manager object
129 XGUI_ContextMenuMgr* contextMenuMgr() const
131 return myContextMenuMgr;
134 //! Returns an object which provides interface to Salome Module (LightApp_Module)
135 XGUI_SalomeConnector* salomeConnector() const
137 return mySalomeConnector;
140 //! Provides an object which provides interface to Salome Viewer
141 ModuleBase_IViewer* salomeViewer() const;
143 //! Returns true if the application works as SALOME module
144 bool isSalomeMode() const
146 return mySalomeConnector != 0;
149 //! Returns Object browser
150 XGUI_ObjectsBrowser* objectBrowser() const
152 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
161 return myViewerProxy;
164 /// Returns the module connector
165 /// \returns the instance of connector
166 XGUI_ModuleConnector* moduleConnector() const
168 return myModuleConnector;
171 /// Returns a desktop
172 /// \return a desktop instance
173 QMainWindow* desktop() 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 //! \return boolean value
197 bool canChangeColor() const;
199 //! Change color of the results if it is possible
200 //! The operation is available for construction, body and group results
201 //! theObjects a list of selected objects
202 void changeColor(const QObjectPtrList& theObjects);
204 //! Returns true if there is at least one selected body/construction/group result
205 //! \return boolean value
206 bool canChangeDeflection() const;
208 //! Change deflection of the results if it is possible
209 //! The operation is available for construction, body and group results
210 //! theObjects a list of selected objects
211 void changeDeflection(const QObjectPtrList& theObjects);
213 //! Show the given features in 3d Viewer
214 void showObjects(const QObjectPtrList& theList, bool isVisible);
216 //! Show the given features in 3d Viewer
217 void showOnlyObjects(const QObjectPtrList& theList);
219 /// Set display mode for the given objects
220 /// \param theList a list of displayed objects
221 /// \param theMode a mode to set (see \ref XGUI_Displayer)
222 void setDisplayMode(const QObjectPtrList& theList, int theMode);
224 /// Set selection mode in viewer. If theMode=-1 then activate default mode
225 /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
226 void setViewerSelectionMode(int theMode);
228 /// Activates current selection mode for the given list of objects
229 void activateObjectsSelection(const QObjectPtrList& theList);
231 /// Returns current module
232 ModuleBase_IModule* module() const
237 /// Returns current directory which contains data files
238 QString currentDataDir() const { return myCurrentDir; }
240 /// Returns current directory which contains data files
241 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
244 * Save the current document into a directory
245 * \param theName - path to the directory
246 * \param theFileNames - returned file names created in this directory
248 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
250 /// Updates workshop state according to the started operation, e.g. visualizes the property panel
251 /// and connect to it.
252 /// \param theOpertion a started operation
253 void operationStarted(ModuleBase_Operation* theOperation);
255 //! Delete features. Delete the referenced features. There can be a question with a list of
256 //! referenced objects.
257 //! \param theFeatures a list of objects to be deleted
258 bool deleteFeatures(const QObjectPtrList& theFeatures);
260 /// Deactivates the object, if it is active and the module returns that the activation
261 /// of selection for the object is not possible currently(the current operation uses it)
262 /// \param theObject an object
263 /// \param theUpdateViewer a boolean flag to update viewer immediately
264 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
266 /// Returns true if the action of the feature is created to contain Accept/Cancel button
267 /// \param theFeature a feature
268 bool isFeatureOfNested(const FeaturePtr& theFeature);
270 //! Shows the message in the status bar
271 //! \param theMessage a message
272 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);
286 /// Update the property panel content by the XML description of the operation and set the panel
287 /// into the operation
288 /// \param theOperation an operation
289 void fillPropertyPanel(ModuleBase_Operation* theOperation);
291 /// Connects or disconnects to the value changed signal of the property panel widgets
292 /// \param isToConnect a boolean value whether connect or disconnect
293 void connectToPropertyPanel(const bool isToConnect);
295 /// Returns defailt selection mode in 3d viewer
296 QIntList viewerSelectionModes() const { return myViewerSelMode; }
298 /// Highlights result objects in Object Browser according to
299 /// features found in the given list
300 void highlightResults(const QObjectPtrList& theObjects);
302 /// Highlights feature objects in Object Browser according to
303 /// features found in the given list
304 void highlightFeature(const QObjectPtrList& theObjects);
306 /// Returns Data Model XML reader which contains information about
307 /// Data structure configuration
308 const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
310 /// A constant string used for "Move to end" command definition
311 /// It is used for specific processing of Undo/Redo for this command.
312 static QString MOVE_TO_END_COMMAND;
314 //! Closes all in the current session and load the directory
315 //! \param theDirectory a path to directory
316 void openDirectory(const QString& theDirectory);
319 /// Emitted when selection happens in Salome viewer
320 void salomeViewerSelection();
322 //! the signal about the workshop actions states are updated.
323 void commandStatusUpdated();
325 //! the application is started
326 void applicationStarted();
328 //! Signal to update Undo history list
329 void updateUndoHistory(const QList<ActionInfo>&);
331 //! Signal to update Redo history list
332 void updateRedoHistory(const QList<ActionInfo>&);
335 /// Update of commands status
336 void updateCommandStatus();
338 /// update history list (undo/redo commands)
339 void updateHistory();
341 /// Save current document
344 /// Save current document to a file selected by user
347 /// Undo last command
348 void onUndo(int times = 1);
350 /// Redo previous command
351 void onRedo(int times = 1);
356 /// Validates the operation to change the "Apply" button state.
357 /// \param thePreviousState the previous state of the widget
358 void onWidgetStateChanged(int thePreviousState);
360 /// Calls activate of the current widget again. It is possible that selection filters are
361 /// differs in the new state of paged container
362 void onValuesChanged();
364 /// Listens the corresponded signal of model widget and updates Apply button state by feature
365 void onWidgetObjectUpdated();
367 /// Show property panel
368 void showPropertyPanel();
370 /// Hide property panel
371 void hidePropertyPanel();
373 /// Show object Browser
374 void showObjectBrowser();
376 /// Hide object Browser
377 void hideObjectBrowser();
380 void closeDocument();
382 /// Open document from file
385 /// Create a new document
392 /// Open preferences dialog box
393 void onPreferences();
396 /// Activates/deactivates the trihedron in the viewer AIS context
397 void onTrihedronVisibilityChanged(bool theState);
401 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
402 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
403 /// \param theOperation an operation
404 void setGrantedFeatures(ModuleBase_Operation* theOperation);
407 /// Display all results
408 //void displayAllResults();
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);
418 /// SLOT, that is called after the operation is started. Update workshop state according to
419 /// the started operation, e.g. visualizes the property panel and connect to it.
420 /// \param theOpertion a started operation
421 // void onOperationStarted(ModuleBase_Operation* theOperation);
423 /// SLOT, that is called after the operation is resumed. Update workshop state according to
424 /// the started operation, e.g. visualizes the property panel and connect to it.
425 /// \param theOpertion a resumed operation
426 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
428 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
429 /// hides the property panel and update the command status.
430 /// \param theOpertion a stopped operation
431 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
433 /// SLOT, that is called after the operation is committed.
434 /// \param theOpertion a committed operation
435 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
437 /// SLOT, that is called after the operation is aborted.
438 /// \param theOpertion an aborted operation
439 void onOperationAborted(ModuleBase_Operation* theOperation);
441 /// Slot, which reacts to the context popup menu call
442 /// \param theId the data value of the clicked action
443 /// \param isChecked a state of toggle if the action is checkable
444 void onContextMenuCommand(const QString& theId, bool isChecked);
446 /// Set waiting cursor
447 void onStartWaiting();
449 /// Called by Ok button clicked in the property panel. Asks the error manager whether
450 /// the operation can be committed and do it if it returns true.
451 void onAcceptActionClicked();
453 /// Called by Preview button clicked in the property panel. Sends signal to model to
455 void onPreviewActionClicked();
461 /// Register validators
462 void registerValidators() const;
464 /// Load module from external library
465 /// \param theModule name of the module
466 ModuleBase_IModule* loadModule(const QString& theModule);
471 /// Create object browser widget
472 /// \param theParent a parent of widget
473 QDockWidget* createObjectBrowser(QWidget* theParent);
475 /// Create property panel widget
476 /// \param theParent a parent of widget
477 QDockWidget* createPropertyPanel(QWidget* theParent);
479 // Creates Dock widgets: Object browser and Property panel
480 void createDockWidgets();
482 //! Extends undo/redo toolbutton's with history menu
483 //! \param theObject - in the OpenParts it is a QToolButton by itself,
484 //! in salome mode - QAction that creates a button.
485 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
486 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
487 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
489 //! Creates list of actions (commands) by given history list from session
490 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
494 AppElements_MainWindow* myMainWindow;
497 ModuleBase_IModule* myModule;
498 XGUI_ErrorMgr* myErrorMgr;
499 XGUI_ObjectsBrowser* myObjectBrowser;
500 XGUI_PropertyPanel* myPropertyPanel;
501 XGUI_SelectionMgr* mySelector;
502 XGUI_Displayer* myDisplayer;
503 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
504 XGUI_ActionsMgr* myActionsMgr;
505 XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
506 XGUI_SalomeConnector* mySalomeConnector;
507 XGUI_ErrorDialog* myErrorDlg;
508 XGUI_ViewerProxy* myViewerProxy;
509 XGUI_ContextMenuMgr* myContextMenuMgr;
510 XGUI_ModuleConnector* myModuleConnector;
511 XGUI_WorkshopListener* myEventsListener;
513 QString myCurrentDir;
515 QIntList myViewerSelMode;
517 Config_DataModelReader* myDataModelXMLReader;