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 /// Returns current module
209 ModuleBase_IModule* module() const
214 /// Returns current directory which contains data files
215 QString currentDataDir() const { return myCurrentDir; }
217 /// Returns current directory which contains data files
218 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
221 * Save the current document into a directory
222 * \param theName - path to the directory
223 * \param theFileNames - returned file names created in this directory
225 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
228 * If there is an active (uncommitted) operation shows a prompt to abort it
229 * and performs abortion if user agreed. Returns true if
230 * - operation aborted successfully
231 * - there is no active operation
233 bool abortAllOperations();
235 //! Delete features. Delete the referenced features. There can be a question with a list of referenced
237 //! \param theList an objects to be deleted
238 //! \param theIgnoredFeatures a list of features to be ignored during delete
239 //! \param theParent a parent widget for the question message box
240 //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
241 //! objects features appear. If the user chose do not continue, the deletion is not performed
242 //! \return the success of the delete
243 bool deleteFeatures(const QObjectPtrList& theList,
244 const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>(),
245 QWidget* theParent = 0,
246 const bool theAskAboutDeleteReferences = false);
248 /// Deactivates the object, if it is active and the module returns that the activation
249 /// of selection for the object is not possible currently(the current operation uses it)
250 /// \param theObject an object
251 /// \param theUpdateViewer a boolean flag to update viewer immediately
252 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
254 /// Returns true if the action of the feature is created to contain Accept/Cancel button
255 /// \param theFeature a feature
256 bool isFeatureOfNested(const FeaturePtr& theFeature);
258 /// Has to be called in order to display objects with visibility status = true
259 void synchronizeViewer();
261 /// Has to be called in order to display objects from a cpecifed group with visibility status = true
262 /// \param theDoc the document for objects synchronisation
263 /// \param theGroup the group name
264 /// \param theUpdateViewer update viewer flag
265 void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
267 /// A constant string used for "Move to end" command definition
268 /// It is used for specific processing of Undo/Redo for this command.
269 static QString MOVE_TO_END_COMMAND;
272 /// Emitted when selection happens in Salome viewer
273 void salomeViewerSelection();
275 /// Emitted when error in application happens
276 void errorOccurred(const QString&);
278 //! the signal about the workshop actions states are updated.
279 void commandStatusUpdated();
281 //! the application is started
282 void applicationStarted();
284 //! Signal to update Undo history list
285 void updateUndoHistory(const QList<ActionInfo>&);
287 //! Signal to update Redo history list
288 void updateRedoHistory(const QList<ActionInfo>&);
291 /// Update of commands status
292 void updateCommandStatus();
294 /// update history list (undo/redo commands)
295 void updateHistory();
297 /// Save current document
300 /// Save current document to a file selected by user
303 /// Undo last command
304 void onUndo(int times = 1);
306 /// Redo previous command
307 void onRedo(int times = 1);
312 /// Validates the operation to change the "Apply" button state.
313 /// \param thePreviousState the previous state of the widget
314 void onWidgetStateChanged(int thePreviousState);
316 /// Show property panel
317 void showPropertyPanel();
319 /// Hide property panel
320 void hidePropertyPanel();
322 /// Show object Browser
323 void showObjectBrowser();
325 /// Hide object Browser
326 void hideObjectBrowser();
329 void closeDocument();
331 /// Open document from file
334 /// Create a new document
341 /// Open preferences dialog box
342 void onPreferences();
345 /// Activates/deactivates the trihedron in the viewer AIS context
346 void onTrihedronVisibilityChanged(bool theState);
349 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
350 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
351 /// \param theOperation an operation
352 void setGrantedFeatures(ModuleBase_Operation* theOperation);
354 /// Update the property panel content by the XML description of the operation and set the panel
355 /// into the operation
356 /// \param theOperation an operation
357 void setPropertyPanel(ModuleBase_Operation* theOperation);
359 /// Connects or disconnects to the value changed signal of the property panel widgets
360 /// \param isToConnect a boolean value whether connect or disconnect
361 void connectToPropertyPanel(const bool isToConnect);
364 /// Display all results
365 //void displayAllResults();
367 /// Display results from document
368 /// \param theDoc a document
369 void displayDocumentResults(DocumentPtr theDoc);
371 /// Display results from a group
372 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
375 /// SLOT, that is called after the operation is started. Update workshop state according to
376 /// the started operation, e.g. visualizes the property panel and connect to it.
377 /// \param theOpertion a started operation
378 void onOperationStarted(ModuleBase_Operation* theOperation);
380 /// SLOT, that is called after the operation is resumed. Update workshop state according to
381 /// the started operation, e.g. visualizes the property panel and connect to it.
382 /// \param theOpertion a resumed operation
383 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
385 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
386 /// hides the property panel and update the command status.
387 /// \param theOpertion a stopped operation
388 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
390 /// SLOT, that is called after the operation is committed.
391 /// \param theOpertion a committed operation
392 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
394 /// SLOT, that is called after the operation is aborted.
395 /// \param theOpertion an aborted operation
396 void onOperationAborted(ModuleBase_Operation* theOperation);
398 /// Slot, which reacts to the context popup menu call
399 /// \param theId the data value of the clicked action
400 /// \param isChecked a state of toggle if the action is checkable
401 void onContextMenuCommand(const QString& theId, bool isChecked);
403 /// Set waiting cursor
404 void onStartWaiting();
406 /// Called by Ok button clicked in the property panel. Asks the error manager whether
407 /// the operation can be committed and do it if it returns true.
408 void onAcceptActionClicked();
414 /// Register validators
415 void registerValidators() const;
417 /// Load module from external library
418 /// \param theModule name of the module
419 ModuleBase_IModule* loadModule(const QString& theModule);
424 /// Create object browser widget
425 /// \param theParent a parent of widget
426 QDockWidget* createObjectBrowser(QWidget* theParent);
428 /// Create property panel widget
429 /// \param theParent a parent of widget
430 QDockWidget* createPropertyPanel(QWidget* theParent);
432 // Creates Dock widgets: Object browser and Property panel
433 void createDockWidgets();
435 //! Extends undo/redo toolbutton's with history menu
436 //! \param theObject - in the OpenParts it is a QToolButton by itself,
437 //! in salome mode - QAction that creates a button.
438 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
439 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
440 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
443 /// Calls removeFeature of the document for each object in the list
444 //! \param theList an objects to be deleted
445 //! \param theIgnoredFeatures a list of features to be ignored during delete
446 //! \param theActionId an action command key to find context menu object types enabled for remove
447 bool removeFeatures(const QObjectPtrList& theList,
448 const std::set<FeaturePtr>& theIgnoredFeatures,
449 const QString& theActionId);
451 //! Creates list of actions (commands) by given history list from session
452 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
456 AppElements_MainWindow* myMainWindow;
459 ModuleBase_IModule* myModule;
460 XGUI_ErrorMgr* myErrorMgr;
461 XGUI_ObjectsBrowser* myObjectBrowser;
462 XGUI_PropertyPanel* myPropertyPanel;
463 XGUI_SelectionMgr* mySelector;
464 XGUI_Displayer* myDisplayer;
465 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
466 XGUI_ActionsMgr* myActionsMgr;
467 XGUI_SalomeConnector* mySalomeConnector;
468 XGUI_ErrorDialog* myErrorDlg;
469 XGUI_ViewerProxy* myViewerProxy;
470 XGUI_ContextMenuMgr* myContextMenuMgr;
471 XGUI_ModuleConnector* myModuleConnector;
472 XGUI_WorkshopListener* myEventsListener;
474 QString myCurrentDir;