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>
19 class AppElements_MainWindow;
20 class AppElements_Command;
21 class AppElements_Workbench;
23 class XGUI_SelectionMgr;
25 class XGUI_OperationMgr;
26 class XGUI_SalomeConnector;
27 class XGUI_ObjectsBrowser;
28 class XGUI_ActionsMgr;
29 class XGUI_ErrorDialog;
30 class XGUI_SalomeViewer;
31 class XGUI_ViewerProxy;
32 class XGUI_PropertyPanel;
33 class XGUI_ContextMenuMgr;
34 class XGUI_ModuleConnector;
35 class XGUI_WorkshopListener;
37 class ModuleBase_Operation;
38 class ModuleBase_IModule;
39 class ModuleBase_IViewer;
47 /**\class XGUI_Workshop
49 * \brief Class which defines a configuration of the application (Workshop) and launches it.
51 class XGUI_EXPORT XGUI_Workshop : public QObject
56 /// \param theConnector a Salome connector object.
57 /// Used only if the workshop is launched in Salome environment
58 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
59 virtual ~XGUI_Workshop();
61 //! Starting of the application
62 void startApplication();
64 // Activates the module controls. Should be called after module creation
65 void activateModule();
67 // Deactivates the module controls. Should be called after module creation
68 void deactivateModule();
70 //! Returns main window (Desktop) of the application
71 AppElements_MainWindow* mainWindow() const
76 //! Returns selection manager object
77 XGUI_SelectionMgr* selector() const
83 XGUI_Displayer* displayer() const
88 //! ! Returns operation manager.
89 XGUI_OperationMgr* operationMgr() const
91 return myOperationMgr;
94 //! ! Returns an actions manager
95 XGUI_ActionsMgr* actionsMgr() const
100 //! Returns property panel widget
101 XGUI_PropertyPanel* propertyPanel() const
103 return myPropertyPanel;
106 //! Returns context menu manager object
107 XGUI_ContextMenuMgr* contextMenuMgr() const
109 return myContextMenuMgr;
112 //! Creates and adds a new workbench (menu group) with the given name and returns it
113 AppElements_Workbench* addWorkbench(const QString& theName);
115 //! Returns an object which provides interface to Salome Module (LightApp_Module)
116 XGUI_SalomeConnector* salomeConnector() const
118 return mySalomeConnector;
121 //! Provides an object which provides interface to Salome Viewer
122 ModuleBase_IViewer* salomeViewer() const;
124 //! Returns true if the application works as SALOME module
125 bool isSalomeMode() const
127 return mySalomeConnector != 0;
130 /// Returns true if the loading data process is started and has not been finished yet
131 /// \return boolean result
132 bool isLoadingData() const
134 return myIsLoadingData;
137 //! Returns Object browser
138 XGUI_ObjectsBrowser* objectBrowser() const
140 return myObjectBrowser;
143 /// This method is called by Salome module when selection is changed
144 void salomeViewerSelectionChanged();
146 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
147 XGUI_ViewerProxy* viewer() const
149 return myViewerProxy;
152 /// Returns the module connectory
153 /// \returns the instance of connector
154 XGUI_ModuleConnector* moduleConnector() const
156 return myModuleConnector;
159 /// Returns a desktop
160 /// \return a desktop instance
161 QMainWindow* desktop() const;
164 void deleteObjects();
166 //! Move selected features to be after the current feature
169 //! Returns true if there is at least one selected body/construction/group result
170 //! \return boolean value
171 bool canChangeColor() const;
173 //! Change color of the features if it is possible
174 //! The operation is available for construction, body and group results
175 //! theObjects a list of selected objects
176 void changeColor(const QObjectPtrList& theObjects);
178 //! Show the given features in 3d Viewer
179 void showObjects(const QObjectPtrList& theList, bool isVisible);
181 //! Show the given features in 3d Viewer
182 void showOnlyObjects(const QObjectPtrList& theList);
184 /// Set display mode for the given onjects
185 /// \param theList a list of displayed objects
186 /// \param theMode a mode to set (see \ref XGUI_Displayer)
187 void setDisplayMode(const QObjectPtrList& theList, int theMode);
189 /// Returns current module
190 ModuleBase_IModule* module() const
195 /// Returns current directory whic contains data files
196 QString currentDataDir() const { return myCurrentDir; }
198 /// Returns current directory whic contains data files
199 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
202 * Save the current document into a directory
203 * \param theName - path to the directory
204 * \param theFileNames - returned file names created in this directory
206 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
209 * If there is an active (uncommited) operation shows a prompt to abort it
210 * and performs abortion if user agreed. Returns true if
211 * - operation aborted successfully
212 * - there is no active operation
214 bool isActiveOperationAborted();
216 //! Delete features. Delete the referenced features. There can be a question with a list of referenced
218 //! \param theList an objects to be deleted
219 //! \param theIgnoredFeatures a list of features to be ignored during delete
220 //! \param theParent a parent widget for the question message box
221 //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
222 //! objects features appear. If the user chose do not continue, the deletion is not performed
223 //! \return the success of the delete
224 bool deleteFeatures(const QObjectPtrList& theList,
225 const std::set<FeaturePtr>& theIgnoredFeatures,
226 QWidget* theParent = 0,
227 const bool theAskAboutDeleteReferences = false);
229 /// Deactivates the object, if it is active and the module returns that the activation
230 /// of selection for the object is not possible currently(the current operation uses it)
231 /// \param theObject an object
232 /// \param theUpdateViewer a boolean flag to update viewer immediately
233 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
236 /// Emitted when selection happens in Salome viewer
237 void salomeViewerSelection();
239 /// Emitted when error in applivation happens
240 void errorOccurred(const QString&);
242 //! the signal about the workshop actions states are updated.
243 void commandStatusUpdated();
245 //! the application is started
246 void applicationStarted();
248 //! Signal to update Undo history list
249 void updateUndoHistory(const QList<ActionInfo>&);
251 //! Signal to update Redo history list
252 void updateRedoHistory(const QList<ActionInfo>&);
255 /// Update of commands status
256 void updateCommandStatus();
258 /// update history list (undo/redo commands)
259 void updateHistory();
261 /// Create a new dokument
264 /// Open document from file
267 /// Save current document
270 /// Save current document to a file selected by user
276 /// Undo last command
277 void onUndo(int times = 1);
279 /// Redo previous command
280 void onRedo(int times = 1);
282 /// Rebuild data tree
285 /// Open preferences dialog box
286 void onPreferences();
288 /// Show property panel
289 void showPropertyPanel();
291 /// Hide property panel
292 void hidePropertyPanel();
294 /// Show object Browser
295 void showObjectBrowser();
297 /// Hide object Browser
298 void hideObjectBrowser();
300 /// Reaction on command call
301 //void onFeatureTriggered();
304 void closeDocument();
307 /// Find the nested features and set them into the operation
308 /// \param theOperation an operation
309 void setNestedFeatures(ModuleBase_Operation* theOperation);
311 /// Update the property panel content by the XML description of the operation and set the panel
312 /// into the operation
313 /// \param theOperation an operation
314 void setPropertyPanel(ModuleBase_Operation* theOperation);
316 /// Connect to operation signals
317 /// \param theOperation an operation
318 void connectWithOperation(ModuleBase_Operation* theOperation);
321 /// Display all results
322 //void displayAllResults();
324 /// Displau results from document
325 /// \param theDoc a document
326 void displayDocumentResults(DocumentPtr theDoc);
328 /// Display results from a group
329 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
332 /// SLOT, that is called after the operation is started. Update workshop state according to
333 /// the started operation, e.g. visualizes the property panel and connect to it.
334 /// \param theOpertion a started operation
335 void onOperationStarted(ModuleBase_Operation* theOperation);
337 /// SLOT, that is called after the operation is resumed. Update workshop state according to
338 /// the started operation, e.g. visualizes the property panel and connect to it.
339 /// \param theOpertion a resumed operation
340 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
342 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
343 /// hides the property panel and udpate the command status.
344 /// \param theOpertion a stopped operation
345 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
347 /// SLOT, that is called after the operation is committed.
348 /// \param theOpertion a commmitted operation
349 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
351 /// SLOT, that is called after the operation is aborted.
352 /// \param theOpertion an aborted operation
353 void onOperationAborted(ModuleBase_Operation* theOperation);
355 /// Slot, which reacts to the context popup menu call
356 /// \param theId the data value of the clicked action
357 /// \param isChecked a state of toggle if the action is checkable
358 void onContextMenuCommand(const QString& theId, bool isChecked);
360 /// Set waiting cursor
361 void onStartWaiting();
367 /// Register validators
368 void registerValidators() const;
370 /// Load module from external library
371 /// \param theModule name of the module
372 ModuleBase_IModule* loadModule(const QString& theModule);
377 /// Create object browser widget
378 /// \param theParent a parent of widget
379 QDockWidget* createObjectBrowser(QWidget* theParent);
381 /// Create property panel widget
382 /// \param theParent a parent of widget
383 QDockWidget* createPropertyPanel(QWidget* theParent);
385 // Creates Dock widgets: Object browser and Property panel
386 void createDockWidgets();
388 //! Extends undo/redo toolbutton's with history menu
389 //! \param theObject - in the OpenParts it is a QToolButton by itself,
390 //! in salome mode - QAction that creates a button.
391 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
392 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
393 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
395 //! Creates list of actions (commands) by given history list from session
396 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
399 AppElements_MainWindow* myMainWindow;
400 ModuleBase_IModule* myModule;
401 XGUI_ObjectsBrowser* myObjectBrowser;
402 XGUI_PropertyPanel* myPropertyPanel;
403 XGUI_SelectionMgr* mySelector;
404 XGUI_Displayer* myDisplayer;
405 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
406 XGUI_ActionsMgr* myActionsMgr;
407 XGUI_SalomeConnector* mySalomeConnector;
408 XGUI_ErrorDialog* myErrorDlg;
409 XGUI_ViewerProxy* myViewerProxy;
410 XGUI_ContextMenuMgr* myContextMenuMgr;
411 XGUI_ModuleConnector* myModuleConnector;
412 XGUI_WorkshopListener* myEventsListener;
414 QString myCurrentDir;
416 /// The flag is true when we loading a document
417 bool myIsLoadingData;