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 error manager.
96 XGUI_ErrorMgr* errorMgr() const
101 //! ! Returns an actions manager
102 XGUI_ActionsMgr* actionsMgr() const
107 //! Returns property panel widget
108 XGUI_PropertyPanel* propertyPanel() const
110 return myPropertyPanel;
113 //! Returns context menu manager object
114 XGUI_ContextMenuMgr* contextMenuMgr() const
116 return myContextMenuMgr;
119 //! Creates and adds a new workbench (menu group) with the given name and returns it
120 AppElements_Workbench* addWorkbench(const QString& theName);
122 //! Returns an object which provides interface to Salome Module (LightApp_Module)
123 XGUI_SalomeConnector* salomeConnector() const
125 return mySalomeConnector;
128 //! Provides an object which provides interface to Salome Viewer
129 ModuleBase_IViewer* salomeViewer() const;
131 //! Returns true if the application works as SALOME module
132 bool isSalomeMode() const
134 return mySalomeConnector != 0;
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 the object can be shaded. If the object is a compsolid result, the method
174 //! checks subobjects of the result
175 //! \return boolean value
176 bool canBeShaded(const ObjectPtr& theObject) const;
178 //! Returns true if there is at least one selected body/construction/group result
179 //! \return boolean value
180 bool canChangeColor() const;
182 //! Change color of the features if it is possible
183 //! The operation is available for construction, body and group results
184 //! theObjects a list of selected objects
185 void changeColor(const QObjectPtrList& theObjects);
187 //! Show the given features in 3d Viewer
188 void showObjects(const QObjectPtrList& theList, bool isVisible);
190 //! Show the given features in 3d Viewer
191 void showOnlyObjects(const QObjectPtrList& theList);
193 /// Set display mode for the given onjects
194 /// \param theList a list of displayed objects
195 /// \param theMode a mode to set (see \ref XGUI_Displayer)
196 void setDisplayMode(const QObjectPtrList& theList, int theMode);
198 /// Returns current module
199 ModuleBase_IModule* module() const
204 /// Returns current directory whic contains data files
205 QString currentDataDir() const { return myCurrentDir; }
207 /// Returns current directory whic contains data files
208 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
211 * Save the current document into a directory
212 * \param theName - path to the directory
213 * \param theFileNames - returned file names created in this directory
215 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
218 * If there is an active (uncommited) operation shows a prompt to abort it
219 * and performs abortion if user agreed. Returns true if
220 * - operation aborted successfully
221 * - there is no active operation
223 bool abortAllOperations();
225 //! Delete features. Delete the referenced features. There can be a question with a list of referenced
227 //! \param theList an objects to be deleted
228 //! \param theIgnoredFeatures a list of features to be ignored during delete
229 //! \param theParent a parent widget for the question message box
230 //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
231 //! objects features appear. If the user chose do not continue, the deletion is not performed
232 //! \return the success of the delete
233 bool deleteFeatures(const QObjectPtrList& theList,
234 const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>(),
235 QWidget* theParent = 0,
236 const bool theAskAboutDeleteReferences = false);
238 /// Deactivates the object, if it is active and the module returns that the activation
239 /// of selection for the object is not possible currently(the current operation uses it)
240 /// \param theObject an object
241 /// \param theUpdateViewer a boolean flag to update viewer immediately
242 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
244 /// Returns true if the action of the feature is created to contain Accept/Cancel button
245 /// \param theFeature a feature
246 bool isFeatureOfNested(const FeaturePtr& theFeature);
249 /// Emitted when selection happens in Salome viewer
250 void salomeViewerSelection();
252 /// Emitted when error in applivation happens
253 void errorOccurred(const QString&);
255 //! the signal about the workshop actions states are updated.
256 void commandStatusUpdated();
258 //! the application is started
259 void applicationStarted();
261 //! Signal to update Undo history list
262 void updateUndoHistory(const QList<ActionInfo>&);
264 //! Signal to update Redo history list
265 void updateRedoHistory(const QList<ActionInfo>&);
268 /// Update of commands status
269 void updateCommandStatus();
271 /// update history list (undo/redo commands)
272 void updateHistory();
274 /// Create a new dokument
277 /// Open document from file
280 /// Save current document
283 /// Save current document to a file selected by user
289 /// Undo last command
290 void onUndo(int times = 1);
292 /// Redo previous command
293 void onRedo(int times = 1);
295 /// Rebuild data tree
298 /// Open preferences dialog box
299 void onPreferences();
301 /// Show property panel
302 void showPropertyPanel();
304 /// Hide property panel
305 void hidePropertyPanel();
307 /// Show object Browser
308 void showObjectBrowser();
310 /// Hide object Browser
311 void hideObjectBrowser();
314 void closeDocument();
317 /// Sets the granted operations for the parameter operation. Firtsly, it finds the nested features
318 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
319 /// \param theOperation an operation
320 void setGrantedFeatures(ModuleBase_Operation* theOperation);
322 /// Update the property panel content by the XML description of the operation and set the panel
323 /// into the operation
324 /// \param theOperation an operation
325 void setPropertyPanel(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();
370 /// Called by Ok button clicked in the property panel. Asks the error manager whether
371 /// the operation can be commited and do it if it returns true.
372 void onAcceptActionClicked();
374 /// Listens the corresponded signal from operation manager and send it with the Ok
375 /// action to operation manager.
376 /// \param theEnabled an enabled state for the action
377 //void onValidationStateChanged(bool theEnabled);
379 //connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
380 // aOkAct, SLOT(setEnabled(bool)));
387 /// Register validators
388 void registerValidators() const;
390 /// Load module from external library
391 /// \param theModule name of the module
392 ModuleBase_IModule* loadModule(const QString& theModule);
397 /// Create object browser widget
398 /// \param theParent a parent of widget
399 QDockWidget* createObjectBrowser(QWidget* theParent);
401 /// Create property panel widget
402 /// \param theParent a parent of widget
403 QDockWidget* createPropertyPanel(QWidget* theParent);
405 // Creates Dock widgets: Object browser and Property panel
406 void createDockWidgets();
408 //! Extends undo/redo toolbutton's with history menu
409 //! \param theObject - in the OpenParts it is a QToolButton by itself,
410 //! in salome mode - QAction that creates a button.
411 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
412 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
413 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
415 //! Creates list of actions (commands) by given history list from session
416 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
419 AppElements_MainWindow* myMainWindow;
420 ModuleBase_IModule* myModule;
421 XGUI_ErrorMgr* myErrorMgr;
422 XGUI_ObjectsBrowser* myObjectBrowser;
423 XGUI_PropertyPanel* myPropertyPanel;
424 XGUI_SelectionMgr* mySelector;
425 XGUI_Displayer* myDisplayer;
426 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
427 XGUI_ActionsMgr* myActionsMgr;
428 XGUI_SalomeConnector* mySalomeConnector;
429 XGUI_ErrorDialog* myErrorDlg;
430 XGUI_ViewerProxy* myViewerProxy;
431 XGUI_ContextMenuMgr* myContextMenuMgr;
432 XGUI_ModuleConnector* myModuleConnector;
433 XGUI_WorkshopListener* myEventsListener;
435 QString myCurrentDir;