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;
30 class XGUI_ModuleConnector;
31 class XGUI_ObjectsBrowser;
32 class XGUI_OperationMgr;
33 class XGUI_PropertyPanel;
34 class XGUI_SalomeConnector;
35 class XGUI_SalomeViewer;
36 class XGUI_SelectionMgr;
37 class XGUI_ViewerProxy;
38 class XGUI_WorkshopListener;
40 class ModuleBase_IModule;
41 class ModuleBase_IViewer;
42 class ModuleBase_Operation;
51 /**\class XGUI_Workshop
53 * \brief Class which defines a configuration of the application (Workshop) and launches it.
55 class XGUI_EXPORT XGUI_Workshop : public QObject
60 /// \param theConnector a Salome connector object.
61 /// Used only if the workshop is launched in Salome environment
62 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
63 virtual ~XGUI_Workshop();
65 //! Starting of the application
66 void startApplication();
68 /// Activates the module controls. Should be called after module creation
69 void activateModule();
71 /// Deactivates the module controls. Should be called after module creation
72 void deactivateModule();
75 //! Returns main window (Desktop) of the application
76 AppElements_MainWindow* mainWindow() const
81 //! Creates and adds a new workbench (menu group) with the given name and returns it
82 AppElements_Workbench* addWorkbench(const QString& theName);
85 //! Returns selection manager object
86 XGUI_SelectionMgr* selector() const
92 XGUI_Displayer* displayer() const
97 //! ! Returns operation manager.
98 XGUI_OperationMgr* operationMgr() const
100 return myOperationMgr;
103 //! ! Returns error manager.
104 XGUI_ErrorMgr* errorMgr() const
109 //! ! Returns an actions manager
110 XGUI_ActionsMgr* actionsMgr() const
115 //! Returns property panel widget
116 XGUI_PropertyPanel* propertyPanel() const
118 return myPropertyPanel;
121 //! Returns context menu manager object
122 XGUI_ContextMenuMgr* contextMenuMgr() const
124 return myContextMenuMgr;
127 //! Returns an object which provides interface to Salome Module (LightApp_Module)
128 XGUI_SalomeConnector* salomeConnector() const
130 return mySalomeConnector;
133 //! Provides an object which provides interface to Salome Viewer
134 ModuleBase_IViewer* salomeViewer() const;
136 //! Returns true if the application works as SALOME module
137 bool isSalomeMode() const
139 return mySalomeConnector != 0;
142 //! Returns Object browser
143 XGUI_ObjectsBrowser* objectBrowser() const
145 return myObjectBrowser;
148 /// This method is called by Salome module when selection is changed
149 void salomeViewerSelectionChanged();
151 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
152 XGUI_ViewerProxy* viewer() const
154 return myViewerProxy;
157 /// Returns the module connector
158 /// \returns the instance of connector
159 XGUI_ModuleConnector* moduleConnector() const
161 return myModuleConnector;
164 /// Returns a desktop
165 /// \return a desktop instance
166 QMainWindow* desktop() const;
169 void deleteObjects();
171 //! Searches for selected features unused in other (not selected) features. If one or several
172 //! selected features are found, a warning message proposes to delete them. It contains
173 //! the list of features to be deleted.
176 //! Returns true if the selected feature can be moved to the position after the current feature
177 //! \return boolean value
178 bool canMoveFeature();
180 //! Move selected features to be after the current feature
183 //! Returns true if the object can be shaded. If the object is a compsolid result, the method
184 //! checks subobjects of the result
185 //! \return boolean value
186 bool canBeShaded(const ObjectPtr& theObject) const;
188 //! Returns true if there is at least one selected body/construction/group result
189 //! \return boolean value
190 bool canChangeColor() const;
192 //! Change color of the features if it is possible
193 //! The operation is available for construction, body and group results
194 //! theObjects a list of selected objects
195 void changeColor(const QObjectPtrList& theObjects);
197 //! Show the given features in 3d Viewer
198 void showObjects(const QObjectPtrList& theList, bool isVisible);
200 //! Show the given features in 3d Viewer
201 void showOnlyObjects(const QObjectPtrList& theList);
203 /// Set display mode for the given objects
204 /// \param theList a list of displayed objects
205 /// \param theMode a mode to set (see \ref XGUI_Displayer)
206 void setDisplayMode(const QObjectPtrList& theList, int theMode);
208 /// Set selection mode in viewer. If theMode=-1 then activate default mode
209 /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
210 void setViewerSelectionMode(int theMode);
212 /// Activates current selection mode for the given list of objects
213 void activateObjectsSelection(const QObjectPtrList& theList);
215 /// Returns current module
216 ModuleBase_IModule* module() const
221 /// Returns current directory which contains data files
222 QString currentDataDir() const { return myCurrentDir; }
224 /// Returns current directory which contains data files
225 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
228 * Save the current document into a directory
229 * \param theName - path to the directory
230 * \param theFileNames - returned file names created in this directory
232 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
235 * If there is an active (uncommitted) operation shows a prompt to abort it
236 * and performs abortion if user agreed. Returns true if
237 * - operation aborted successfully
238 * - there is no active operation
240 bool abortAllOperations();
242 //! Delete features. Delete the referenced features. There can be a question with a list of
243 //! referenced objects.
244 //! \param theList an objects to be deleted
245 //! \param theIgnoredFeatures a list of features to be ignored during delete
246 bool deleteFeatures(const QObjectPtrList& theFeatures,
247 const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>());
249 /// Deactivates the object, if it is active and the module returns that the activation
250 /// of selection for the object is not possible currently(the current operation uses it)
251 /// \param theObject an object
252 /// \param theUpdateViewer a boolean flag to update viewer immediately
253 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
255 /// Returns true if the action of the feature is created to contain Accept/Cancel button
256 /// \param theFeature a feature
257 bool isFeatureOfNested(const FeaturePtr& theFeature);
259 /// Has to be called in order to display objects with visibility status = true
260 void synchronizeViewer();
262 /// Has to be called in order to display objects from a cpecifed group with visibility status = true
263 /// \param theDoc the document for objects synchronisation
264 /// \param theGroup the group name
265 /// \param theUpdateViewer update viewer flag
266 void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
268 /// Update the property panel content by the XML description of the operation and set the panel
269 /// into the operation
270 /// \param theOperation an operation
271 void setPropertyPanel(ModuleBase_Operation* theOperation);
273 /// Connects or disconnects to the value changed signal of the property panel widgets
274 /// \param isToConnect a boolean value whether connect or disconnect
275 void connectToPropertyPanel(const bool isToConnect);
277 /// Returns defailt selection mode in 3d viewer
278 int viewerSelectionMode() const { return myViewerSelMode; }
280 /// Highlights result objects in Object Browser according to
281 /// features found in the given list
282 void highlightResults(const QObjectPtrList& theObjects);
284 /// A constant string used for "Move to end" command definition
285 /// It is used for specific processing of Undo/Redo for this command.
286 static QString MOVE_TO_END_COMMAND;
289 /// Emitted when selection happens in Salome viewer
290 void salomeViewerSelection();
292 /// Emitted when error in application happens
293 void errorOccurred(const QString&);
295 //! the signal about the workshop actions states are updated.
296 void commandStatusUpdated();
298 //! the application is started
299 void applicationStarted();
301 //! Signal to update Undo history list
302 void updateUndoHistory(const QList<ActionInfo>&);
304 //! Signal to update Redo history list
305 void updateRedoHistory(const QList<ActionInfo>&);
308 /// Update of commands status
309 void updateCommandStatus();
311 /// update history list (undo/redo commands)
312 void updateHistory();
314 /// Save current document
317 /// Save current document to a file selected by user
320 /// Undo last command
321 void onUndo(int times = 1);
323 /// Redo previous command
324 void onRedo(int times = 1);
329 /// Validates the operation to change the "Apply" button state.
330 /// \param thePreviousState the previous state of the widget
331 void onWidgetStateChanged(int thePreviousState);
333 /// Calls activate of the current widget again. It is possible that selection filters are
334 /// differs in the new state of paged container
335 void onValuesChanged();
337 /// Show property panel
338 void showPropertyPanel();
340 /// Hide property panel
341 void hidePropertyPanel();
343 /// Show object Browser
344 void showObjectBrowser();
346 /// Hide object Browser
347 void hideObjectBrowser();
350 void closeDocument();
352 /// Open document from file
355 /// Create a new document
362 /// Open preferences dialog box
363 void onPreferences();
366 /// Activates/deactivates the trihedron in the viewer AIS context
367 void onTrihedronVisibilityChanged(bool theState);
371 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
372 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
373 /// \param theOperation an operation
374 void setGrantedFeatures(ModuleBase_Operation* theOperation);
376 //! Find all referenced features. Return direct and indirect lists of referenced object
377 //! \param theList an objects to be checked
378 //! \param aDirectRefFeatures a list of direct reference features
379 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
380 void findReferences(const QObjectPtrList& theList,
381 std::set<FeaturePtr>& aDirectRefFeatures,
382 std::set<FeaturePtr>& aIndirectRefFeatures);
384 //! Shows a dialog box about references. Ask whether they should be also removed.
385 //! \param theList an objects to be checked
386 //! \param aDirectRefFeatures a list of direct reference features
387 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
388 //! \param theParent a parent widget for the question message box
389 //! \param doDeleteReferences if there are parameters between features, ask if they should be
390 //! replaced to their meaning without corresponded features remove
391 //! \return true if in message box answer is Yes
392 bool isDeleteFeatureWithReferences(const QObjectPtrList& theList,
393 const std::set<FeaturePtr>& aDirectRefFeatures,
394 const std::set<FeaturePtr>& aIndirectRefFeatures,
396 bool& doDeleteReferences);
398 //! \param theIgnoredFeatures a list of features to be ignored during delete
399 //! \param theList an objects to be checked
400 //! \param aDirectRefFeatures a list of direct reference features
401 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
402 //! \param doDeleteReferences flag if referenced features should be removed also
403 bool deleteFeaturesInternal(const QObjectPtrList& theList,
404 const std::set<FeaturePtr>& aDirectRefFeatures,
405 const std::set<FeaturePtr>& aIndirectRefFeatures,
406 const std::set<FeaturePtr>& theIgnoredFeatures,
407 const bool doDeleteReferences = true);
410 /// Display all results
411 //void displayAllResults();
413 /// Display results from document
414 /// \param theDoc a document
415 void displayDocumentResults(DocumentPtr theDoc);
417 /// Display results from a group
418 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
421 /// SLOT, that is called after the operation is started. Update workshop state according to
422 /// the started operation, e.g. visualizes the property panel and connect to it.
423 /// \param theOpertion a started operation
424 void onOperationStarted(ModuleBase_Operation* theOperation);
426 /// SLOT, that is called after the operation is resumed. Update workshop state according to
427 /// the started operation, e.g. visualizes the property panel and connect to it.
428 /// \param theOpertion a resumed operation
429 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
431 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
432 /// hides the property panel and update the command status.
433 /// \param theOpertion a stopped operation
434 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
436 /// SLOT, that is called after the operation is committed.
437 /// \param theOpertion a committed operation
438 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
440 /// SLOT, that is called after the operation is aborted.
441 /// \param theOpertion an aborted operation
442 void onOperationAborted(ModuleBase_Operation* theOperation);
444 /// Slot, which reacts to the context popup menu call
445 /// \param theId the data value of the clicked action
446 /// \param isChecked a state of toggle if the action is checkable
447 void onContextMenuCommand(const QString& theId, bool isChecked);
449 /// Set waiting cursor
450 void onStartWaiting();
452 /// Called by Ok button clicked in the property panel. Asks the error manager whether
453 /// the operation can be committed and do it if it returns true.
454 void onAcceptActionClicked();
460 /// Register validators
461 void registerValidators() const;
463 /// Load module from external library
464 /// \param theModule name of the module
465 ModuleBase_IModule* loadModule(const QString& theModule);
470 /// Create object browser widget
471 /// \param theParent a parent of widget
472 QDockWidget* createObjectBrowser(QWidget* theParent);
474 /// Create property panel widget
475 /// \param theParent a parent of widget
476 QDockWidget* createPropertyPanel(QWidget* theParent);
478 // Creates Dock widgets: Object browser and Property panel
479 void createDockWidgets();
481 //! Extends undo/redo toolbutton's with history menu
482 //! \param theObject - in the OpenParts it is a QToolButton by itself,
483 //! in salome mode - QAction that creates a button.
484 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
485 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
486 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
489 /// Calls removeFeature of the document for each object in the list
490 //! \param theList an objects to be deleted
491 //! \param theIgnoredFeatures a list of features to be ignored during delete
492 //! \param theActionId an action command key to find context menu object types enabled for remove
493 bool removeFeatures(const QObjectPtrList& theList,
494 const std::set<FeaturePtr>& theIgnoredFeatures,
495 const QString& theActionId);
497 //! Creates list of actions (commands) by given history list from session
498 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
502 AppElements_MainWindow* myMainWindow;
505 ModuleBase_IModule* myModule;
506 XGUI_ErrorMgr* myErrorMgr;
507 XGUI_ObjectsBrowser* myObjectBrowser;
508 XGUI_PropertyPanel* myPropertyPanel;
509 XGUI_SelectionMgr* mySelector;
510 XGUI_Displayer* myDisplayer;
511 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
512 XGUI_ActionsMgr* myActionsMgr;
513 XGUI_SalomeConnector* mySalomeConnector;
514 XGUI_ErrorDialog* myErrorDlg;
515 XGUI_ViewerProxy* myViewerProxy;
516 XGUI_ContextMenuMgr* myContextMenuMgr;
517 XGUI_ModuleConnector* myModuleConnector;
518 XGUI_WorkshopListener* myEventsListener;
520 QString myCurrentDir;