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>
20 class AppElements_MainWindow;
21 class AppElements_Command;
22 class AppElements_Workbench;
25 class XGUI_ActionsMgr;
26 class XGUI_ContextMenuMgr;
28 class XGUI_ErrorDialog;
30 class XGUI_ModuleConnector;
31 class XGUI_ObjectsBrowser;
32 class XGUI_OperationMgr;
33 class XGUI_PropertyPanel;
34 class XGUI_SalomeConnector;
35 class XGUI_SalomeViewer;
36 class XGUI_SelectionMgr;
37 class XGUI_ViewerProxy;
38 class XGUI_WorkshopListener;
40 class ModuleBase_IModule;
41 class ModuleBase_IViewer;
42 class ModuleBase_Operation;
51 /**\class XGUI_Workshop
53 * \brief Class which defines a configuration of the application (Workshop) and launches it.
55 class XGUI_EXPORT XGUI_Workshop : public QObject
60 /// \param theConnector a Salome connector object.
61 /// Used only if the workshop is launched in Salome environment
62 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
63 virtual ~XGUI_Workshop();
65 //! Starting of the application
66 void startApplication();
68 /// Activates the module controls. Should be called after module creation
69 void activateModule();
71 /// Deactivates the module controls. Should be called after module creation
72 void deactivateModule();
75 //! Returns main window (Desktop) of the application
76 AppElements_MainWindow* mainWindow() const
81 //! Creates and adds a new workbench (menu group) with the given name and returns it
82 AppElements_Workbench* addWorkbench(const QString& theName);
85 //! Returns selection manager object
86 XGUI_SelectionMgr* selector() const
92 XGUI_Displayer* displayer() const
97 //! ! Returns operation manager.
98 XGUI_OperationMgr* operationMgr() const
100 return myOperationMgr;
103 //! ! Returns error manager.
104 XGUI_ErrorMgr* errorMgr() const
109 //! ! Returns an actions manager
110 XGUI_ActionsMgr* actionsMgr() const
115 //! Returns property panel widget
116 XGUI_PropertyPanel* propertyPanel() const
118 return myPropertyPanel;
121 //! Returns context menu manager object
122 XGUI_ContextMenuMgr* contextMenuMgr() const
124 return myContextMenuMgr;
127 //! Returns an object which provides interface to Salome Module (LightApp_Module)
128 XGUI_SalomeConnector* salomeConnector() const
130 return mySalomeConnector;
133 //! Provides an object which provides interface to Salome Viewer
134 ModuleBase_IViewer* salomeViewer() const;
136 //! Returns true if the application works as SALOME module
137 bool isSalomeMode() const
139 return mySalomeConnector != 0;
142 //! Returns Object browser
143 XGUI_ObjectsBrowser* objectBrowser() const
145 return myObjectBrowser;
148 /// This method is called by Salome module when selection is changed
149 void salomeViewerSelectionChanged();
151 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
152 XGUI_ViewerProxy* viewer() const
154 return myViewerProxy;
157 /// Returns the module connector
158 /// \returns the instance of connector
159 XGUI_ModuleConnector* moduleConnector() const
161 return myModuleConnector;
164 /// Returns a desktop
165 /// \return a desktop instance
166 QMainWindow* desktop() const;
169 void deleteObjects();
171 //! Searches for selected features unused in other (not selected) features. If one or several
172 //! selected features are found, a warning message proposes to delete them. It contains
173 //! the list of features to be deleted.
176 //! Returns true if the selected feature can be moved to the position after the current feature
177 //! \return boolean value
178 bool canMoveFeature();
180 //! Move selected features to be after the current feature
183 //! Returns true if the object can be shaded. If the object is a compsolid result, the method
184 //! checks subobjects of the result
185 //! \return boolean value
186 bool canBeShaded(const ObjectPtr& theObject) const;
188 //! Returns true if there is at least one selected body/construction/group result
189 //! \return boolean value
190 bool canChangeColor() const;
192 //! Change color of the features if it is possible
193 //! The operation is available for construction, body and group results
194 //! theObjects a list of selected objects
195 void changeColor(const QObjectPtrList& theObjects);
197 //! Show the given features in 3d Viewer
198 void showObjects(const QObjectPtrList& theList, bool isVisible);
200 //! Show the given features in 3d Viewer
201 void showOnlyObjects(const QObjectPtrList& theList);
203 /// Set display mode for the given objects
204 /// \param theList a list of displayed objects
205 /// \param theMode a mode to set (see \ref XGUI_Displayer)
206 void setDisplayMode(const QObjectPtrList& theList, int theMode);
208 /// Returns current module
209 ModuleBase_IModule* module() const
214 /// Returns current directory which contains data files
215 QString currentDataDir() const { return myCurrentDir; }
217 /// Returns current directory which contains data files
218 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
221 * Save the current document into a directory
222 * \param theName - path to the directory
223 * \param theFileNames - returned file names created in this directory
225 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
228 * If there is an active (uncommitted) operation shows a prompt to abort it
229 * and performs abortion if user agreed. Returns true if
230 * - operation aborted successfully
231 * - there is no active operation
233 bool abortAllOperations();
235 //! Delete features. Delete the referenced features. There can be a question with a list of
236 //! referenced objects.
237 //! \param theList an objects to be deleted
238 //! \param theIgnoredFeatures a list of features to be ignored during delete
239 bool deleteFeatures(const QObjectPtrList& theFeatures,
240 const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>());
242 /// Deactivates the object, if it is active and the module returns that the activation
243 /// of selection for the object is not possible currently(the current operation uses it)
244 /// \param theObject an object
245 /// \param theUpdateViewer a boolean flag to update viewer immediately
246 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
248 /// Returns true if the action of the feature is created to contain Accept/Cancel button
249 /// \param theFeature a feature
250 bool isFeatureOfNested(const FeaturePtr& theFeature);
252 /// Has to be called in order to display objects with visibility status = true
253 void synchronizeViewer();
255 /// Has to be called in order to display objects from a cpecifed group with visibility status = true
256 /// \param theDoc the document for objects synchronisation
257 /// \param theGroup the group name
258 /// \param theUpdateViewer update viewer flag
259 void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
261 /// A constant string used for "Move to end" command definition
262 /// It is used for specific processing of Undo/Redo for this command.
263 static QString MOVE_TO_END_COMMAND;
266 /// Emitted when selection happens in Salome viewer
267 void salomeViewerSelection();
269 /// Emitted when error in application happens
270 void errorOccurred(const QString&);
272 //! the signal about the workshop actions states are updated.
273 void commandStatusUpdated();
275 //! the application is started
276 void applicationStarted();
278 //! Signal to update Undo history list
279 void updateUndoHistory(const QList<ActionInfo>&);
281 //! Signal to update Redo history list
282 void updateRedoHistory(const QList<ActionInfo>&);
285 /// Update of commands status
286 void updateCommandStatus();
288 /// update history list (undo/redo commands)
289 void updateHistory();
291 /// Save current document
294 /// Save current document to a file selected by user
297 /// Undo last command
298 void onUndo(int times = 1);
300 /// Redo previous command
301 void onRedo(int times = 1);
306 /// Validates the operation to change the "Apply" button state.
307 /// \param thePreviousState the previous state of the widget
308 void onWidgetStateChanged(int thePreviousState);
310 /// Calls activate of the current widget again. It is possible that selection filters are
311 /// differs in the new state of paged container
312 void onValuesChanged();
314 /// Show property panel
315 void showPropertyPanel();
317 /// Hide property panel
318 void hidePropertyPanel();
320 /// Show object Browser
321 void showObjectBrowser();
323 /// Hide object Browser
324 void hideObjectBrowser();
327 void closeDocument();
329 /// Open document from file
332 /// Create a new document
339 /// Open preferences dialog box
340 void onPreferences();
343 /// Activates/deactivates the trihedron in the viewer AIS context
344 void onTrihedronVisibilityChanged(bool theState);
347 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
348 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
349 /// \param theOperation an operation
350 void setGrantedFeatures(ModuleBase_Operation* theOperation);
352 /// Update the property panel content by the XML description of the operation and set the panel
353 /// into the operation
354 /// \param theOperation an operation
355 void setPropertyPanel(ModuleBase_Operation* theOperation);
357 /// Connects or disconnects to the value changed signal of the property panel widgets
358 /// \param isToConnect a boolean value whether connect or disconnect
359 void connectToPropertyPanel(const bool isToConnect);
361 //! Find all referenced features. Return direct and indirect lists of referenced object
362 //! \param theList an objects to be checked
363 //! \param aDirectRefFeatures a list of direct reference features
364 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
365 void findReferences(const QObjectPtrList& theList,
366 std::set<FeaturePtr>& aDirectRefFeatures,
367 std::set<FeaturePtr>& aIndirectRefFeatures);
369 //! Shows a dialog box about references. Ask whether they should be also removed.
370 //! \param theList an objects to be checked
371 //! \param aDirectRefFeatures a list of direct reference features
372 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
373 //! \param theParent a parent widget for the question message box
374 //! \param doDeleteReferences if there are parameters between features, ask if they should be
375 //! replaced to their meaning without corresponded features remove
376 //! \return true if in message box answer is Yes
377 bool isDeleteFeatureWithReferences(const QObjectPtrList& theList,
378 const std::set<FeaturePtr>& aDirectRefFeatures,
379 const std::set<FeaturePtr>& aIndirectRefFeatures,
381 bool& doDeleteReferences);
383 //! \param theIgnoredFeatures a list of features to be ignored during delete
384 //! \param theList an objects to be checked
385 //! \param aDirectRefFeatures a list of direct reference features
386 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
387 //! \param doDeleteReferences flag if referenced features should be removed also
388 bool deleteFeaturesInternal(const QObjectPtrList& theList,
389 const std::set<FeaturePtr>& aDirectRefFeatures,
390 const std::set<FeaturePtr>& aIndirectRefFeatures,
391 const std::set<FeaturePtr>& theIgnoredFeatures,
392 const bool doDeleteReferences = true);
395 /// Display all results
396 //void displayAllResults();
398 /// Display results from document
399 /// \param theDoc a document
400 void displayDocumentResults(DocumentPtr theDoc);
402 /// Display results from a group
403 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
406 /// SLOT, that is called after the operation is started. Update workshop state according to
407 /// the started operation, e.g. visualizes the property panel and connect to it.
408 /// \param theOpertion a started operation
409 void onOperationStarted(ModuleBase_Operation* theOperation);
411 /// SLOT, that is called after the operation is resumed. Update workshop state according to
412 /// the started operation, e.g. visualizes the property panel and connect to it.
413 /// \param theOpertion a resumed operation
414 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
416 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
417 /// hides the property panel and update the command status.
418 /// \param theOpertion a stopped operation
419 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
421 /// SLOT, that is called after the operation is committed.
422 /// \param theOpertion a committed operation
423 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
425 /// SLOT, that is called after the operation is aborted.
426 /// \param theOpertion an aborted operation
427 void onOperationAborted(ModuleBase_Operation* theOperation);
429 /// Slot, which reacts to the context popup menu call
430 /// \param theId the data value of the clicked action
431 /// \param isChecked a state of toggle if the action is checkable
432 void onContextMenuCommand(const QString& theId, bool isChecked);
434 /// Set waiting cursor
435 void onStartWaiting();
437 /// Called by Ok button clicked in the property panel. Asks the error manager whether
438 /// the operation can be committed and do it if it returns true.
439 void onAcceptActionClicked();
445 /// Register validators
446 void registerValidators() const;
448 /// Load module from external library
449 /// \param theModule name of the module
450 ModuleBase_IModule* loadModule(const QString& theModule);
455 /// Create object browser widget
456 /// \param theParent a parent of widget
457 QDockWidget* createObjectBrowser(QWidget* theParent);
459 /// Create property panel widget
460 /// \param theParent a parent of widget
461 QDockWidget* createPropertyPanel(QWidget* theParent);
463 // Creates Dock widgets: Object browser and Property panel
464 void createDockWidgets();
466 //! Extends undo/redo toolbutton's with history menu
467 //! \param theObject - in the OpenParts it is a QToolButton by itself,
468 //! in salome mode - QAction that creates a button.
469 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
470 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
471 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
474 /// Calls removeFeature of the document for each object in the list
475 //! \param theList an objects to be deleted
476 //! \param theIgnoredFeatures a list of features to be ignored during delete
477 //! \param theActionId an action command key to find context menu object types enabled for remove
478 bool removeFeatures(const QObjectPtrList& theList,
479 const std::set<FeaturePtr>& theIgnoredFeatures,
480 const QString& theActionId);
482 //! Creates list of actions (commands) by given history list from session
483 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
487 AppElements_MainWindow* myMainWindow;
490 ModuleBase_IModule* myModule;
491 XGUI_ErrorMgr* myErrorMgr;
492 XGUI_ObjectsBrowser* myObjectBrowser;
493 XGUI_PropertyPanel* myPropertyPanel;
494 XGUI_SelectionMgr* mySelector;
495 XGUI_Displayer* myDisplayer;
496 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
497 XGUI_ActionsMgr* myActionsMgr;
498 XGUI_SalomeConnector* mySalomeConnector;
499 XGUI_ErrorDialog* myErrorDlg;
500 XGUI_ViewerProxy* myViewerProxy;
501 XGUI_ContextMenuMgr* myContextMenuMgr;
502 XGUI_ModuleConnector* myModuleConnector;
503 XGUI_WorkshopListener* myEventsListener;
505 QString myCurrentDir;