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 Object browser
131 XGUI_ObjectsBrowser* objectBrowser() const
133 return myObjectBrowser;
136 /// This method is called by Salome module when selection is changed
137 void salomeViewerSelectionChanged();
139 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
140 XGUI_ViewerProxy* viewer() const
142 return myViewerProxy;
145 /// Returns the module connectory
146 /// \returns the instance of connector
147 XGUI_ModuleConnector* moduleConnector() const
149 return myModuleConnector;
152 /// Returns a desktop
153 /// \return a desktop instance
154 QMainWindow* desktop() const;
157 void deleteObjects();
159 //! Returns true if the selected feature can be moved to the position after the current feature
160 //! \return boolean value
161 bool canMoveFeature();
163 //! Move selected features to be after the current feature
166 //! Returns true if there is at least one selected body/construction/group result
167 //! \return boolean value
168 bool canChangeColor() const;
170 //! Change color of the features if it is possible
171 //! The operation is available for construction, body and group results
172 //! theObjects a list of selected objects
173 void changeColor(const QObjectPtrList& theObjects);
175 //! Show the given features in 3d Viewer
176 void showObjects(const QObjectPtrList& theList, bool isVisible);
178 //! Show the given features in 3d Viewer
179 void showOnlyObjects(const QObjectPtrList& theList);
181 /// Set display mode for the given onjects
182 /// \param theList a list of displayed objects
183 /// \param theMode a mode to set (see \ref XGUI_Displayer)
184 void setDisplayMode(const QObjectPtrList& theList, int theMode);
186 /// Returns current module
187 ModuleBase_IModule* module() const
192 /// Returns current directory whic contains data files
193 QString currentDataDir() const { return myCurrentDir; }
195 /// Returns current directory whic contains data files
196 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
199 * Save the current document into a directory
200 * \param theName - path to the directory
201 * \param theFileNames - returned file names created in this directory
203 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
206 * If there is an active (uncommited) operation shows a prompt to abort it
207 * and performs abortion if user agreed. Returns true if
208 * - operation aborted successfully
209 * - there is no active operation
211 bool isActiveOperationAborted();
213 //! Delete features. Delete the referenced features. There can be a question with a list of referenced
215 //! \param theList an objects to be deleted
216 //! \param theIgnoredFeatures a list of features to be ignored during delete
217 //! \param theParent a parent widget for the question message box
218 //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
219 //! objects features appear. If the user chose do not continue, the deletion is not performed
220 //! \return the success of the delete
221 bool deleteFeatures(const QObjectPtrList& theList,
222 const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>(),
223 QWidget* theParent = 0,
224 const bool theAskAboutDeleteReferences = false);
226 /// Deactivates the object, if it is active and the module returns that the activation
227 /// of selection for the object is not possible currently(the current operation uses it)
228 /// \param theObject an object
229 /// \param theUpdateViewer a boolean flag to update viewer immediately
230 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
233 /// Emitted when selection happens in Salome viewer
234 void salomeViewerSelection();
236 /// Emitted when error in applivation happens
237 void errorOccurred(const QString&);
239 //! the signal about the workshop actions states are updated.
240 void commandStatusUpdated();
242 //! the application is started
243 void applicationStarted();
245 //! Signal to update Undo history list
246 void updateUndoHistory(const QList<ActionInfo>&);
248 //! Signal to update Redo history list
249 void updateRedoHistory(const QList<ActionInfo>&);
252 /// Update of commands status
253 void updateCommandStatus();
255 // Update enable state of accept all button. It is enabled if the the parent operation is
256 // valid and there are modifications in sesstion(undo can be performed).
257 void updateCompositeActionState();
259 /// update history list (undo/redo commands)
260 void updateHistory();
262 /// Create a new dokument
265 /// Open document from file
268 /// Save current document
271 /// Save current document to a file selected by user
277 /// Undo last command
278 void onUndo(int times = 1);
280 /// Redo previous command
281 void onRedo(int times = 1);
283 /// Rebuild data tree
286 /// Open preferences dialog box
287 void onPreferences();
289 /// Show property panel
290 void showPropertyPanel();
292 /// Hide property panel
293 void hidePropertyPanel();
295 /// Show object Browser
296 void showObjectBrowser();
298 /// Hide object Browser
299 void hideObjectBrowser();
301 /// Reaction on command call
302 //void onFeatureTriggered();
305 void closeDocument();
308 /// Find the nested features and set them into the operation
309 /// \param theOperation an operation
310 void setNestedFeatures(ModuleBase_Operation* theOperation);
312 /// Update the property panel content by the XML description of the operation and set the panel
313 /// into the operation
314 /// \param theOperation an operation
315 void setPropertyPanel(ModuleBase_Operation* theOperation);
317 /// Connect to operation signals
318 /// \param theOperation an operation
319 void connectWithOperation(ModuleBase_Operation* theOperation);
322 /// Display all results
323 //void displayAllResults();
325 /// Displau results from document
326 /// \param theDoc a document
327 void displayDocumentResults(DocumentPtr theDoc);
329 /// Display results from a group
330 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
333 /// SLOT, that is called after the operation is started. Update workshop state according to
334 /// the started operation, e.g. visualizes the property panel and connect to it.
335 /// \param theOpertion a started operation
336 void onOperationStarted(ModuleBase_Operation* theOperation);
338 /// SLOT, that is called after the operation is resumed. Update workshop state according to
339 /// the started operation, e.g. visualizes the property panel and connect to it.
340 /// \param theOpertion a resumed operation
341 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
343 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
344 /// hides the property panel and udpate the command status.
345 /// \param theOpertion a stopped operation
346 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
348 /// SLOT, that is called after the operation is committed.
349 /// \param theOpertion a commmitted operation
350 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
352 /// SLOT, that is called after the operation is aborted.
353 /// \param theOpertion an aborted operation
354 void onOperationAborted(ModuleBase_Operation* theOperation);
356 /// Slot, which reacts to the context popup menu call
357 /// \param theId the data value of the clicked action
358 /// \param isChecked a state of toggle if the action is checkable
359 void onContextMenuCommand(const QString& theId, bool isChecked);
361 /// Set waiting cursor
362 void onStartWaiting();
368 /// Register validators
369 void registerValidators() const;
371 /// Load module from external library
372 /// \param theModule name of the module
373 ModuleBase_IModule* loadModule(const QString& theModule);
378 /// Create object browser widget
379 /// \param theParent a parent of widget
380 QDockWidget* createObjectBrowser(QWidget* theParent);
382 /// Create property panel widget
383 /// \param theParent a parent of widget
384 QDockWidget* createPropertyPanel(QWidget* theParent);
386 // Creates Dock widgets: Object browser and Property panel
387 void createDockWidgets();
389 //! Extends undo/redo toolbutton's with history menu
390 //! \param theObject - in the OpenParts it is a QToolButton by itself,
391 //! in salome mode - QAction that creates a button.
392 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
393 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
394 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
396 //! Creates list of actions (commands) by given history list from session
397 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
400 AppElements_MainWindow* myMainWindow;
401 ModuleBase_IModule* myModule;
402 XGUI_ObjectsBrowser* myObjectBrowser;
403 XGUI_PropertyPanel* myPropertyPanel;
404 XGUI_SelectionMgr* mySelector;
405 XGUI_Displayer* myDisplayer;
406 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
407 XGUI_ActionsMgr* myActionsMgr;
408 XGUI_SalomeConnector* mySalomeConnector;
409 XGUI_ErrorDialog* myErrorDlg;
410 XGUI_ViewerProxy* myViewerProxy;
411 XGUI_ContextMenuMgr* myContextMenuMgr;
412 XGUI_ModuleConnector* myModuleConnector;
413 XGUI_WorkshopListener* myEventsListener;
415 QString myCurrentDir;