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 //! Returns true if the selected feature can be moved to the position after the current feature
167 //! \return boolean value
168 bool canMoveFeature();
170 //! Move selected features to be after the current feature
173 //! Returns true if there is at least one selected body/construction/group result
174 //! \return boolean value
175 bool canChangeColor() const;
177 //! Change color of the features if it is possible
178 //! The operation is available for construction, body and group results
179 //! theObjects a list of selected objects
180 void changeColor(const QObjectPtrList& theObjects);
182 //! Show the given features in 3d Viewer
183 void showObjects(const QObjectPtrList& theList, bool isVisible);
185 //! Show the given features in 3d Viewer
186 void showOnlyObjects(const QObjectPtrList& theList);
188 /// Set display mode for the given onjects
189 /// \param theList a list of displayed objects
190 /// \param theMode a mode to set (see \ref XGUI_Displayer)
191 void setDisplayMode(const QObjectPtrList& theList, int theMode);
193 /// Returns current module
194 ModuleBase_IModule* module() const
199 /// Returns current directory whic contains data files
200 QString currentDataDir() const { return myCurrentDir; }
202 /// Returns current directory whic contains data files
203 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
206 * Save the current document into a directory
207 * \param theName - path to the directory
208 * \param theFileNames - returned file names created in this directory
210 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
213 * If there is an active (uncommited) operation shows a prompt to abort it
214 * and performs abortion if user agreed. Returns true if
215 * - operation aborted successfully
216 * - there is no active operation
218 bool isActiveOperationAborted();
220 //! Delete features. Delete the referenced features. There can be a question with a list of referenced
222 //! \param theList an objects to be deleted
223 //! \param theIgnoredFeatures a list of features to be ignored during delete
224 //! \param theParent a parent widget for the question message box
225 //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
226 //! objects features appear. If the user chose do not continue, the deletion is not performed
227 //! \return the success of the delete
228 bool deleteFeatures(const QObjectPtrList& theList,
229 const std::set<FeaturePtr>& theIgnoredFeatures,
230 QWidget* theParent = 0,
231 const bool theAskAboutDeleteReferences = false);
233 /// Deactivates the object, if it is active and the module returns that the activation
234 /// of selection for the object is not possible currently(the current operation uses it)
235 /// \param theObject an object
236 /// \param theUpdateViewer a boolean flag to update viewer immediately
237 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
240 /// Emitted when selection happens in Salome viewer
241 void salomeViewerSelection();
243 /// Emitted when error in applivation happens
244 void errorOccurred(const QString&);
246 //! the signal about the workshop actions states are updated.
247 void commandStatusUpdated();
249 //! the application is started
250 void applicationStarted();
252 //! Signal to update Undo history list
253 void updateUndoHistory(const QList<ActionInfo>&);
255 //! Signal to update Redo history list
256 void updateRedoHistory(const QList<ActionInfo>&);
259 /// Update of commands status
260 void updateCommandStatus();
262 /// update history list (undo/redo commands)
263 void updateHistory();
265 /// Create a new dokument
268 /// Open document from file
271 /// Save current document
274 /// Save current document to a file selected by user
280 /// Undo last command
281 void onUndo(int times = 1);
283 /// Redo previous command
284 void onRedo(int times = 1);
286 /// Rebuild data tree
289 /// Open preferences dialog box
290 void onPreferences();
292 /// Show property panel
293 void showPropertyPanel();
295 /// Hide property panel
296 void hidePropertyPanel();
298 /// Show object Browser
299 void showObjectBrowser();
301 /// Hide object Browser
302 void hideObjectBrowser();
304 /// Reaction on command call
305 //void onFeatureTriggered();
308 void closeDocument();
311 /// Find the nested features and set them into the operation
312 /// \param theOperation an operation
313 void setNestedFeatures(ModuleBase_Operation* theOperation);
315 /// Update the property panel content by the XML description of the operation and set the panel
316 /// into the operation
317 /// \param theOperation an operation
318 void setPropertyPanel(ModuleBase_Operation* theOperation);
320 /// Connect to operation signals
321 /// \param theOperation an operation
322 void connectWithOperation(ModuleBase_Operation* theOperation);
325 /// Display all results
326 //void displayAllResults();
328 /// Displau results from document
329 /// \param theDoc a document
330 void displayDocumentResults(DocumentPtr theDoc);
332 /// Display results from a group
333 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
336 /// SLOT, that is called after the operation is started. Update workshop state according to
337 /// the started operation, e.g. visualizes the property panel and connect to it.
338 /// \param theOpertion a started operation
339 void onOperationStarted(ModuleBase_Operation* theOperation);
341 /// SLOT, that is called after the operation is resumed. Update workshop state according to
342 /// the started operation, e.g. visualizes the property panel and connect to it.
343 /// \param theOpertion a resumed operation
344 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
346 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
347 /// hides the property panel and udpate the command status.
348 /// \param theOpertion a stopped operation
349 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
351 /// SLOT, that is called after the operation is committed.
352 /// \param theOpertion a commmitted operation
353 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
355 /// SLOT, that is called after the operation is aborted.
356 /// \param theOpertion an aborted operation
357 void onOperationAborted(ModuleBase_Operation* theOperation);
359 /// Slot, which reacts to the context popup menu call
360 /// \param theId the data value of the clicked action
361 /// \param isChecked a state of toggle if the action is checkable
362 void onContextMenuCommand(const QString& theId, bool isChecked);
364 /// Set waiting cursor
365 void onStartWaiting();
371 /// Register validators
372 void registerValidators() const;
374 /// Load module from external library
375 /// \param theModule name of the module
376 ModuleBase_IModule* loadModule(const QString& theModule);
381 /// Create object browser widget
382 /// \param theParent a parent of widget
383 QDockWidget* createObjectBrowser(QWidget* theParent);
385 /// Create property panel widget
386 /// \param theParent a parent of widget
387 QDockWidget* createPropertyPanel(QWidget* theParent);
389 // Creates Dock widgets: Object browser and Property panel
390 void createDockWidgets();
392 //! Extends undo/redo toolbutton's with history menu
393 //! \param theObject - in the OpenParts it is a QToolButton by itself,
394 //! in salome mode - QAction that creates a button.
395 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
396 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
397 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
399 //! Creates list of actions (commands) by given history list from session
400 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
403 AppElements_MainWindow* myMainWindow;
404 ModuleBase_IModule* myModule;
405 XGUI_ObjectsBrowser* myObjectBrowser;
406 XGUI_PropertyPanel* myPropertyPanel;
407 XGUI_SelectionMgr* mySelector;
408 XGUI_Displayer* myDisplayer;
409 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
410 XGUI_ActionsMgr* myActionsMgr;
411 XGUI_SalomeConnector* mySalomeConnector;
412 XGUI_ErrorDialog* myErrorDlg;
413 XGUI_ViewerProxy* myViewerProxy;
414 XGUI_ContextMenuMgr* myContextMenuMgr;
415 XGUI_ModuleConnector* myModuleConnector;
416 XGUI_WorkshopListener* myEventsListener;
418 QString myCurrentDir;
420 /// The flag is true when we loading a document
421 bool myIsLoadingData;