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;
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 features 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 //! Show the given features in 3d Viewer
205 void showObjects(const QObjectPtrList& theList, bool isVisible);
207 //! Show the given features in 3d Viewer
208 void showOnlyObjects(const QObjectPtrList& theList);
210 /// Set display mode for the given objects
211 /// \param theList a list of displayed objects
212 /// \param theMode a mode to set (see \ref XGUI_Displayer)
213 void setDisplayMode(const QObjectPtrList& theList, int theMode);
215 /// Set selection mode in viewer. If theMode=-1 then activate default mode
216 /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
217 void setViewerSelectionMode(int theMode);
219 /// Activates current selection mode for the given list of objects
220 void activateObjectsSelection(const QObjectPtrList& theList);
222 /// Returns current module
223 ModuleBase_IModule* module() const
228 /// Returns current directory which contains data files
229 QString currentDataDir() const { return myCurrentDir; }
231 /// Returns current directory which contains data files
232 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
235 * Save the current document into a directory
236 * \param theName - path to the directory
237 * \param theFileNames - returned file names created in this directory
239 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
242 * If there is an active (uncommitted) operation shows a prompt to abort it
243 * and performs abortion if user agreed. Returns true if
244 * - operation aborted successfully
245 * - there is no active operation
247 bool abortAllOperations();
249 //! Delete features. Delete the referenced features. There can be a question with a list of
250 //! referenced objects.
251 //! \param theList an objects to be deleted
252 //! \param theIgnoredFeatures a list of features to be ignored during delete
253 bool deleteFeatures(const QObjectPtrList& theFeatures,
254 const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>());
256 /// Deactivates the object, if it is active and the module returns that the activation
257 /// of selection for the object is not possible currently(the current operation uses it)
258 /// \param theObject an object
259 /// \param theUpdateViewer a boolean flag to update viewer immediately
260 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
262 /// Returns true if the action of the feature is created to contain Accept/Cancel button
263 /// \param theFeature a feature
264 bool isFeatureOfNested(const FeaturePtr& theFeature);
266 /// Has to be called in order to display objects with visibility status = true
267 void synchronizeViewer();
269 /// Has to be called in order to display objects from a cpecifed group with visibility status = true
270 /// \param theDoc the document for objects synchronisation
271 /// \param theGroup the group name
272 /// \param theUpdateViewer update viewer flag
273 void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
275 /// Update the property panel content by the XML description of the operation and set the panel
276 /// into the operation
277 /// \param theOperation an operation
278 void setPropertyPanel(ModuleBase_Operation* theOperation);
280 /// Connects or disconnects to the value changed signal of the property panel widgets
281 /// \param isToConnect a boolean value whether connect or disconnect
282 void connectToPropertyPanel(const bool isToConnect);
284 /// Returns defailt selection mode in 3d viewer
285 int viewerSelectionMode() const { return myViewerSelMode; }
287 /// Highlights result objects in Object Browser according to
288 /// features found in the given list
289 void highlightResults(const QObjectPtrList& theObjects);
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;
296 /// Emitted when selection happens in Salome viewer
297 void salomeViewerSelection();
299 /// Emitted when error in application happens
300 void errorOccurred(const QString&);
302 //! the signal about the workshop actions states are updated.
303 void commandStatusUpdated();
305 //! the application is started
306 void applicationStarted();
308 //! Signal to update Undo history list
309 void updateUndoHistory(const QList<ActionInfo>&);
311 //! Signal to update Redo history list
312 void updateRedoHistory(const QList<ActionInfo>&);
315 /// Update of commands status
316 void updateCommandStatus();
318 /// update history list (undo/redo commands)
319 void updateHistory();
321 /// Save current document
324 /// Save current document to a file selected by user
327 /// Undo last command
328 void onUndo(int times = 1);
330 /// Redo previous command
331 void onRedo(int times = 1);
336 /// Validates the operation to change the "Apply" button state.
337 /// \param thePreviousState the previous state of the widget
338 void onWidgetStateChanged(int thePreviousState);
340 /// Calls activate of the current widget again. It is possible that selection filters are
341 /// differs in the new state of paged container
342 void onValuesChanged();
344 /// Listens the corresponded signal of model widget and updates Apply button state by feature
345 void onWidgetObjectUpdated();
347 /// Show property panel
348 void showPropertyPanel();
350 /// Hide property panel
351 void hidePropertyPanel();
353 /// Show object Browser
354 void showObjectBrowser();
356 /// Hide object Browser
357 void hideObjectBrowser();
360 void closeDocument();
362 /// Open document from file
365 /// Create a new document
372 /// Open preferences dialog box
373 void onPreferences();
376 /// Activates/deactivates the trihedron in the viewer AIS context
377 void onTrihedronVisibilityChanged(bool theState);
381 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
382 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
383 /// \param theOperation an operation
384 void setGrantedFeatures(ModuleBase_Operation* theOperation);
386 //! Find all referenced features. Return direct and indirect lists of referenced object
387 //! \param theList an objects to be checked
388 //! \param aDirectRefFeatures a list of direct reference features
389 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
390 void findReferences(const QObjectPtrList& theList,
391 std::set<FeaturePtr>& aDirectRefFeatures,
392 std::set<FeaturePtr>& aIndirectRefFeatures);
394 //! Shows a dialog box about references. Ask whether they should be also removed.
395 //! \param theList an objects to be checked
396 //! \param aDirectRefFeatures a list of direct reference features
397 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
398 //! \param theParent a parent widget for the question message box
399 //! \param doDeleteReferences if there are parameters between features, ask if they should be
400 //! replaced to their meaning without corresponded features remove
401 //! \return true if in message box answer is Yes
402 bool isDeleteFeatureWithReferences(const QObjectPtrList& theList,
403 const std::set<FeaturePtr>& aDirectRefFeatures,
404 const std::set<FeaturePtr>& aIndirectRefFeatures,
406 bool& doDeleteReferences);
408 //! \param theIgnoredFeatures a list of features to be ignored during delete
409 //! \param theList an objects to be checked
410 //! \param aDirectRefFeatures a list of direct reference features
411 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
412 //! \param doDeleteReferences flag if referenced features should be removed also
413 bool deleteFeaturesInternal(const QObjectPtrList& theList,
414 const std::set<FeaturePtr>& aDirectRefFeatures,
415 const std::set<FeaturePtr>& aIndirectRefFeatures,
416 const std::set<FeaturePtr>& theIgnoredFeatures,
417 const bool doDeleteReferences = true);
420 /// Display all results
421 //void displayAllResults();
423 /// Display results from document
424 /// \param theDoc a document
425 void displayDocumentResults(DocumentPtr theDoc);
427 /// Display results from a group
428 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
431 /// SLOT, that is called after the operation is started. Update workshop state according to
432 /// the started operation, e.g. visualizes the property panel and connect to it.
433 /// \param theOpertion a started operation
434 void onOperationStarted(ModuleBase_Operation* theOperation);
436 /// SLOT, that is called after the operation is resumed. Update workshop state according to
437 /// the started operation, e.g. visualizes the property panel and connect to it.
438 /// \param theOpertion a resumed operation
439 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
441 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
442 /// hides the property panel and update the command status.
443 /// \param theOpertion a stopped operation
444 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
446 /// SLOT, that is called after the operation is committed.
447 /// \param theOpertion a committed operation
448 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
450 /// SLOT, that is called after the operation is aborted.
451 /// \param theOpertion an aborted operation
452 void onOperationAborted(ModuleBase_Operation* theOperation);
454 /// Slot, which reacts to the context popup menu call
455 /// \param theId the data value of the clicked action
456 /// \param isChecked a state of toggle if the action is checkable
457 void onContextMenuCommand(const QString& theId, bool isChecked);
459 /// Set waiting cursor
460 void onStartWaiting();
462 /// Called by Ok button clicked in the property panel. Asks the error manager whether
463 /// the operation can be committed and do it if it returns true.
464 void onAcceptActionClicked();
466 /// Called by Preview button clicked in the property panel. Sends signal to model to
468 void onPreviewActionClicked();
474 /// Register validators
475 void registerValidators() const;
477 /// Load module from external library
478 /// \param theModule name of the module
479 ModuleBase_IModule* loadModule(const QString& theModule);
484 /// Create object browser widget
485 /// \param theParent a parent of widget
486 QDockWidget* createObjectBrowser(QWidget* theParent);
488 /// Create property panel widget
489 /// \param theParent a parent of widget
490 QDockWidget* createPropertyPanel(QWidget* theParent);
492 // Creates Dock widgets: Object browser and Property panel
493 void createDockWidgets();
495 //! Extends undo/redo toolbutton's with history menu
496 //! \param theObject - in the OpenParts it is a QToolButton by itself,
497 //! in salome mode - QAction that creates a button.
498 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
499 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
500 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
503 /// Calls removeFeature of the document for each object in the list
504 //! \param theList an objects to be deleted
505 //! \param theIgnoredFeatures a list of features to be ignored during delete
506 //! \param theActionId an action command key to find context menu object types enabled for remove
507 //! \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
508 bool removeFeatures(const QObjectPtrList& theList,
509 const std::set<FeaturePtr>& theIgnoredFeatures,
510 const QString& theActionId,
511 const bool theFlushRedisplay);
513 //! Creates list of actions (commands) by given history list from session
514 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
518 AppElements_MainWindow* myMainWindow;
521 ModuleBase_IModule* myModule;
522 XGUI_ErrorMgr* myErrorMgr;
523 XGUI_ObjectsBrowser* myObjectBrowser;
524 XGUI_PropertyPanel* myPropertyPanel;
525 XGUI_SelectionMgr* mySelector;
526 XGUI_Displayer* myDisplayer;
527 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
528 XGUI_ActionsMgr* myActionsMgr;
529 XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
530 XGUI_SalomeConnector* mySalomeConnector;
531 XGUI_ErrorDialog* myErrorDlg;
532 XGUI_ViewerProxy* myViewerProxy;
533 XGUI_ContextMenuMgr* myContextMenuMgr;
534 XGUI_ModuleConnector* myModuleConnector;
535 XGUI_WorkshopListener* myEventsListener;
537 QString myCurrentDir;