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_ActionsMgr;
24 class XGUI_ContextMenuMgr;
26 class XGUI_ErrorDialog;
28 class XGUI_ModuleConnector;
29 class XGUI_ObjectsBrowser;
30 class XGUI_OperationMgr;
31 class XGUI_PropertyPanel;
32 class XGUI_SalomeConnector;
33 class XGUI_SalomeViewer;
34 class XGUI_SelectionMgr;
35 class XGUI_ViewerProxy;
36 class XGUI_WorkshopListener;
38 class ModuleBase_IModule;
39 class ModuleBase_IViewer;
40 class ModuleBase_Operation;
48 /**\class XGUI_Workshop
50 * \brief Class which defines a configuration of the application (Workshop) and launches it.
52 class XGUI_EXPORT XGUI_Workshop : public QObject
57 /// \param theConnector a Salome connector object.
58 /// Used only if the workshop is launched in Salome environment
59 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
60 virtual ~XGUI_Workshop();
62 //! Starting of the application
63 void startApplication();
65 // Activates the module controls. Should be called after module creation
66 void activateModule();
68 // Deactivates the module controls. Should be called after module creation
69 void deactivateModule();
71 //! Returns main window (Desktop) of the application
72 AppElements_MainWindow* mainWindow() const
77 //! Returns selection manager object
78 XGUI_SelectionMgr* selector() const
84 XGUI_Displayer* displayer() const
89 //! ! Returns operation manager.
90 XGUI_OperationMgr* operationMgr() const
92 return myOperationMgr;
95 //! ! Returns an actions manager
96 XGUI_ActionsMgr* actionsMgr() const
101 //! Returns property panel widget
102 XGUI_PropertyPanel* propertyPanel() const
104 return myPropertyPanel;
107 //! Returns context menu manager object
108 XGUI_ContextMenuMgr* contextMenuMgr() const
110 return myContextMenuMgr;
113 //! Creates and adds a new workbench (menu group) with the given name and returns it
114 AppElements_Workbench* addWorkbench(const QString& theName);
116 //! Returns an object which provides interface to Salome Module (LightApp_Module)
117 XGUI_SalomeConnector* salomeConnector() const
119 return mySalomeConnector;
122 //! Provides an object which provides interface to Salome Viewer
123 ModuleBase_IViewer* salomeViewer() const;
125 //! Returns true if the application works as SALOME module
126 bool isSalomeMode() const
128 return mySalomeConnector != 0;
131 //! Returns Object browser
132 XGUI_ObjectsBrowser* objectBrowser() const
134 return myObjectBrowser;
137 /// This method is called by Salome module when selection is changed
138 void salomeViewerSelectionChanged();
140 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
141 XGUI_ViewerProxy* viewer() const
143 return myViewerProxy;
146 /// Returns the module connectory
147 /// \returns the instance of connector
148 XGUI_ModuleConnector* moduleConnector() const
150 return myModuleConnector;
153 /// Returns a desktop
154 /// \return a desktop instance
155 QMainWindow* desktop() const;
158 void deleteObjects();
160 //! Returns true if the selected feature can be moved to the position after the current feature
161 //! \return boolean value
162 bool canMoveFeature();
164 //! Move selected features to be after the current feature
167 //! Returns true if the object can be shaded. If the object is a compsolid result, the method
168 //! checks subobjects of the result
169 //! \return boolean value
170 bool canBeShaded(const ObjectPtr& theObject) const;
172 //! Returns true if there is at least one selected body/construction/group result
173 //! \return boolean value
174 bool canChangeColor() const;
176 //! Change color of the features if it is possible
177 //! The operation is available for construction, body and group results
178 //! theObjects a list of selected objects
179 void changeColor(const QObjectPtrList& theObjects);
181 //! Show the given features in 3d Viewer
182 void showObjects(const QObjectPtrList& theList, bool isVisible);
184 //! Show the given features in 3d Viewer
185 void showOnlyObjects(const QObjectPtrList& theList);
187 /// Set display mode for the given onjects
188 /// \param theList a list of displayed objects
189 /// \param theMode a mode to set (see \ref XGUI_Displayer)
190 void setDisplayMode(const QObjectPtrList& theList, int theMode);
192 /// Returns current module
193 ModuleBase_IModule* module() const
198 /// Returns current directory whic contains data files
199 QString currentDataDir() const { return myCurrentDir; }
201 /// Returns current directory whic contains data files
202 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
205 * Save the current document into a directory
206 * \param theName - path to the directory
207 * \param theFileNames - returned file names created in this directory
209 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
212 * If there is an active (uncommited) operation shows a prompt to abort it
213 * and performs abortion if user agreed. Returns true if
214 * - operation aborted successfully
215 * - there is no active operation
217 bool isActiveOperationAborted();
219 //! Delete features. Delete the referenced features. There can be a question with a list of referenced
221 //! \param theList an objects to be deleted
222 //! \param theIgnoredFeatures a list of features to be ignored during delete
223 //! \param theParent a parent widget for the question message box
224 //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
225 //! objects features appear. If the user chose do not continue, the deletion is not performed
226 //! \return the success of the delete
227 bool deleteFeatures(const QObjectPtrList& theList,
228 const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>(),
229 QWidget* theParent = 0,
230 const bool theAskAboutDeleteReferences = false);
232 /// Deactivates the object, if it is active and the module returns that the activation
233 /// of selection for the object is not possible currently(the current operation uses it)
234 /// \param theObject an object
235 /// \param theUpdateViewer a boolean flag to update viewer immediately
236 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
239 /// Emitted when selection happens in Salome viewer
240 void salomeViewerSelection();
242 /// Emitted when error in applivation happens
243 void errorOccurred(const QString&);
245 //! the signal about the workshop actions states are updated.
246 void commandStatusUpdated();
248 //! the application is started
249 void applicationStarted();
251 //! Signal to update Undo history list
252 void updateUndoHistory(const QList<ActionInfo>&);
254 //! Signal to update Redo history list
255 void updateRedoHistory(const QList<ActionInfo>&);
258 /// Update of commands status
259 void updateCommandStatus();
261 // Update enable state of accept all button. It is enabled if the the parent operation is
262 // valid and there are modifications in sesstion(undo can be performed).
263 void updateCompositeActionState();
265 /// update history list (undo/redo commands)
266 void updateHistory();
268 /// Create a new dokument
271 /// Open document from file
274 /// Save current document
277 /// Save current document to a file selected by user
283 /// Undo last command
284 void onUndo(int times = 1);
286 /// Redo previous command
287 void onRedo(int times = 1);
289 /// Rebuild data tree
292 /// Open preferences dialog box
293 void onPreferences();
295 /// Show property panel
296 void showPropertyPanel();
298 /// Hide property panel
299 void hidePropertyPanel();
301 /// Show object Browser
302 void showObjectBrowser();
304 /// Hide object Browser
305 void hideObjectBrowser();
307 /// Reaction on command call
308 //void onFeatureTriggered();
311 void closeDocument();
314 /// Find the nested features and set them into the operation
315 /// \param theOperation an operation
316 void setNestedFeatures(ModuleBase_Operation* theOperation);
318 /// Update the property panel content by the XML description of the operation and set the panel
319 /// into the operation
320 /// \param theOperation an operation
321 void setPropertyPanel(ModuleBase_Operation* theOperation);
323 /// Connect to operation signals
324 /// \param theOperation an operation
325 void connectWithOperation(ModuleBase_Operation* theOperation);
328 /// Display all results
329 //void displayAllResults();
331 /// Displau results from document
332 /// \param theDoc a document
333 void displayDocumentResults(DocumentPtr theDoc);
335 /// Display results from a group
336 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
339 /// SLOT, that is called after the operation is started. Update workshop state according to
340 /// the started operation, e.g. visualizes the property panel and connect to it.
341 /// \param theOpertion a started operation
342 void onOperationStarted(ModuleBase_Operation* theOperation);
344 /// SLOT, that is called after the operation is resumed. Update workshop state according to
345 /// the started operation, e.g. visualizes the property panel and connect to it.
346 /// \param theOpertion a resumed operation
347 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
349 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
350 /// hides the property panel and udpate the command status.
351 /// \param theOpertion a stopped operation
352 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
354 /// SLOT, that is called after the operation is committed.
355 /// \param theOpertion a commmitted operation
356 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
358 /// SLOT, that is called after the operation is aborted.
359 /// \param theOpertion an aborted operation
360 void onOperationAborted(ModuleBase_Operation* theOperation);
362 /// Slot, which reacts to the context popup menu call
363 /// \param theId the data value of the clicked action
364 /// \param isChecked a state of toggle if the action is checkable
365 void onContextMenuCommand(const QString& theId, bool isChecked);
367 /// Set waiting cursor
368 void onStartWaiting();
374 /// Register validators
375 void registerValidators() const;
377 /// Load module from external library
378 /// \param theModule name of the module
379 ModuleBase_IModule* loadModule(const QString& theModule);
384 /// Create object browser widget
385 /// \param theParent a parent of widget
386 QDockWidget* createObjectBrowser(QWidget* theParent);
388 /// Create property panel widget
389 /// \param theParent a parent of widget
390 QDockWidget* createPropertyPanel(QWidget* theParent);
392 // Creates Dock widgets: Object browser and Property panel
393 void createDockWidgets();
395 //! Extends undo/redo toolbutton's with history menu
396 //! \param theObject - in the OpenParts it is a QToolButton by itself,
397 //! in salome mode - QAction that creates a button.
398 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
399 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
400 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
402 //! Creates list of actions (commands) by given history list from session
403 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
406 AppElements_MainWindow* myMainWindow;
407 ModuleBase_IModule* myModule;
408 XGUI_ErrorMgr* myErrorMgr;
409 XGUI_ObjectsBrowser* myObjectBrowser;
410 XGUI_PropertyPanel* myPropertyPanel;
411 XGUI_SelectionMgr* mySelector;
412 XGUI_Displayer* myDisplayer;
413 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
414 XGUI_ActionsMgr* myActionsMgr;
415 XGUI_SalomeConnector* mySalomeConnector;
416 XGUI_ErrorDialog* myErrorDlg;
417 XGUI_ViewerProxy* myViewerProxy;
418 XGUI_ContextMenuMgr* myContextMenuMgr;
419 XGUI_ModuleConnector* myModuleConnector;
420 XGUI_WorkshopListener* myEventsListener;
422 QString myCurrentDir;