1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef XGUI_WORKSHOP_H
22 #define XGUI_WORKSHOP_H
25 //#include "XGUI_Constants.h"
26 #include <ModuleBase_Definitions.h>
27 #include <ModelAPI_Document.h>
28 #include <ModelAPI_Feature.h>
30 #include <ModuleBase_ActionInfo.h>
34 #include <QKeySequence>
38 class AppElements_MainWindow;
39 class AppElements_Command;
40 class AppElements_Workbench;
43 class XGUI_ActionsMgr;
44 class XGUI_ContextMenuMgr;
46 class XGUI_ErrorDialog;
49 class XGUI_ModuleConnector;
50 class XGUI_ObjectsBrowser;
51 class XGUI_OperationMgr;
52 class XGUI_PropertyPanel;
53 class XGUI_SalomeConnector;
54 class XGUI_SalomeViewer;
55 class XGUI_SelectionMgr;
56 class XGUI_ViewerProxy;
57 class XGUI_WorkshopListener;
59 class ModuleBase_IModule;
60 class ModuleBase_IViewer;
61 class ModuleBase_Operation;
68 class Config_DataModelReader;
70 /**\class XGUI_Workshop
72 * \brief Class which defines a configuration of the application (Workshop) and launches it.
74 class XGUI_EXPORT XGUI_Workshop : public QObject
79 /// \param theConnector a Salome connector object.
80 /// Used only if the workshop is launched in Salome environment
81 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
82 virtual ~XGUI_Workshop();
84 //! Starting of the application
85 void startApplication();
87 /// Activates the module controls. Should be called after module creation
88 void activateModule();
90 /// Deactivates the module controls. Should be called after module creation
91 void deactivateModule();
94 //! Returns main window (Desktop) of the application
95 AppElements_MainWindow* mainWindow() const
100 //! Creates and adds a new workbench (menu group) with the given name and returns it
101 AppElements_Workbench* addWorkbench(const QString& theName);
104 //! Returns selection manager object
105 XGUI_SelectionMgr* selector() const
110 //! Returns displayer
111 XGUI_Displayer* displayer() const
116 //! ! Returns operation manager.
117 XGUI_OperationMgr* operationMgr() const
119 return myOperationMgr;
122 //! ! Returns error manager.
123 XGUI_ErrorMgr* errorMgr() const
128 //! ! Returns an actions manager
129 XGUI_ActionsMgr* actionsMgr() const
134 //! ! Returns an actions manager
135 XGUI_MenuMgr* menuMgr() const
140 //! Returns property panel widget
141 XGUI_PropertyPanel* propertyPanel() const
143 return myPropertyPanel;
146 //! Returns context menu manager object
147 XGUI_ContextMenuMgr* contextMenuMgr() const
149 return myContextMenuMgr;
152 //! Returns an object which provides interface to Salome Module (LightApp_Module)
153 XGUI_SalomeConnector* salomeConnector() const
155 return mySalomeConnector;
158 //! Provides an object which provides interface to Salome Viewer
159 ModuleBase_IViewer* salomeViewer() const;
161 //! Returns true if the application works as SALOME module
162 bool isSalomeMode() const
164 return mySalomeConnector != 0;
167 //! Returns Object browser
168 XGUI_ObjectsBrowser* objectBrowser() const
170 return myObjectBrowser;
173 /// This method is called by Salome module when selection is changed
174 void salomeViewerSelectionChanged();
176 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
177 XGUI_ViewerProxy* viewer() const
179 return myViewerProxy;
182 /// Returns the module connector
183 /// \returns the instance of connector
184 XGUI_ModuleConnector* moduleConnector() const
186 return myModuleConnector;
189 /// Returns a desktop
190 /// \return a desktop instance
191 QMainWindow* desktop() const;
194 void deleteObjects();
196 //! Searches for selected features unused in other (not selected) features. If one or several
197 //! selected features are found, a warning message proposes to delete them. It contains
198 //! the list of features to be deleted.
201 //! Returns true if the selected feature can be moved to the position after the current feature
202 //! \return boolean value
203 bool canMoveFeature();
205 //! Move selected features to be after the current feature
208 //! Returns true if the object can be shaded. If the object is a compsolid result, the method
209 //! checks subobjects of the result
210 //! \return boolean value
211 bool canBeShaded(const ObjectPtr& theObject) const;
213 //! Returns true if there is at least one selected body/construction/group result
214 //! \param theActionName text of the checked action
215 //! \return boolean value
216 bool canChangeProperty(const QString& theActionName) const;
218 //! Change color of the results if it is possible
219 //! The operation is available for construction, body and group results
220 //! theObjects a list of selected objects
221 void changeColor(const QObjectPtrList& theObjects);
223 //! Change deflection of the results if it is possible
224 //! The operation is available for construction, body and group results
225 //! theObjects a list of selected objects
226 void changeDeflection(const QObjectPtrList& theObjects);
228 //! Change transparency of the results if it is possible
229 //! The operation is available for construction, body and group results
230 //! theObjects a list of selected objects
231 void changeTransparency(const QObjectPtrList& theObjects);
233 //! Show the given features in 3d Viewer
234 void showObjects(const QObjectPtrList& theList, bool isVisible);
236 //! Show the given features in 3d Viewer
237 void showOnlyObjects(const QObjectPtrList& theList);
239 /// Set display mode for the given objects
240 /// \param theList a list of displayed objects
241 /// \param theMode a mode to set (see \ref XGUI_Displayer)
242 void setDisplayMode(const QObjectPtrList& theList, int theMode);
244 /// Set selection mode in viewer. If theMode=-1 then activate default mode
245 /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
246 void setViewerSelectionMode(int theMode);
248 /// Activates current selection mode for the given list of objects
249 void activateObjectsSelection(const QObjectPtrList& theList);
251 /// Returns current module
252 ModuleBase_IModule* module() const
257 /// Returns current directory which contains data files
258 QString currentDataDir() const { return myCurrentDir; }
260 /// Returns current directory which contains data files
261 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
264 * Save the current document into a directory
265 * \param theName - path to the directory
266 * \param theFileNames - returned file names created in this directory
268 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
271 * If there is an active (uncommitted) operation shows a prompt to abort it
272 * and performs abortion if user agreed. Returns true if
273 * - operation aborted successfully
274 * - there is no active operation
276 bool abortAllOperations();
278 /// Updates workshop state according to the started operation, e.g. visualizes the property panel
279 /// and connect to it.
280 /// \param theOpertion a started operation
281 void operationStarted(ModuleBase_Operation* theOperation);
284 //! Delete features. Delete the referenced features. There can be a question with a list of
285 //! referenced objects.
286 //! \param theFeatures a list of objects to be deleted
287 bool deleteFeatures(const QObjectPtrList& theFeatures);
289 /// Deactivates the object, if it is active and the module returns that the activation
290 /// of selection for the object is not possible currently(the current operation uses it)
291 /// \param theObject an object
292 /// \param theUpdateViewer a boolean flag to update viewer immediately
293 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
295 /// Returns true if the action of the feature is created to contain Accept/Cancel button
296 /// \param theFeature a feature
297 bool isFeatureOfNested(const FeaturePtr& theFeature);
299 //! Shows the message in the status bar
300 //! \param theMessage a message
301 void setStatusBarMessage(const QString& theMessage);
303 /// Has to be called in order to display objects with visibility status = true
304 void synchronizeViewer();
306 /// Has to be called in order to display objects from a specifed group
307 /// with visibility status = true
308 /// \param theDoc the document for objects synchronisation
309 /// \param theGroup the group name
310 /// \param theUpdateViewer update viewer flag
311 void synchronizeGroupInViewer(const DocumentPtr& theDoc,
312 const std::string& theGroup,
313 bool theUpdateViewer);
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 fillPropertyPanel(ModuleBase_Operation* theOperation);
320 /// Connects or disconnects to the value changed signal of the property panel widgets
321 /// \param isToConnect a boolean value whether connect or disconnect
322 void connectToPropertyPanel(const bool isToConnect);
324 /// Returns defailt selection mode in 3d viewer
325 QIntList viewerSelectionModes() const { return myViewerSelMode; }
327 /// Highlights result objects in Object Browser according to
328 /// features found in the given list
329 void highlightResults(const QObjectPtrList& theObjects);
331 /// Highlights feature objects in Object Browser according to
332 /// features found in the given list
333 void highlightFeature(const QObjectPtrList& theObjects);
335 /// Returns Data Model XML reader which contains information about
336 /// Data structure configuration
337 const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
339 /// A constant string used for "Move to end" command definition
340 /// It is used for specific processing of Undo/Redo for this command.
341 static QString MOVE_TO_END_COMMAND;
343 //! Closes all in the current session and load the directory
344 //! \param theDirectory a path to directory
345 void openDirectory(const QString& theDirectory);
348 /// Emitted when selection happens in Salome viewer
349 void salomeViewerSelection();
351 //! the signal about the workshop actions states are updated.
352 void commandStatusUpdated();
354 //! the application is started
355 void applicationStarted();
357 //! Signal to update Undo history list
358 void updateUndoHistory(const QList<ActionInfo>&);
360 //! Signal to update Redo history list
361 void updateRedoHistory(const QList<ActionInfo>&);
364 /// Update of commands status
365 void updateCommandStatus();
367 /// update history list (undo/redo commands)
368 void updateHistory();
370 /// Save current document
373 /// Save current document to a file selected by user
376 /// Undo last command
377 void onUndo(int times = 1);
379 /// Redo previous command
380 void onRedo(int times = 1);
385 /// Validates the operation to change the "Apply" button state.
386 /// \param thePreviousState the previous state of the widget
387 void onWidgetStateChanged(int thePreviousState);
389 /// Calls activate of the current widget again. It is possible that selection filters are
390 /// differs in the new state of paged container
391 void onValuesChanged();
393 /// Listens the corresponded signal of model widget and updates Apply button state by feature
394 void onWidgetObjectUpdated();
396 /// Show property panel
397 void showPropertyPanel();
399 /// Hide property panel
400 void hidePropertyPanel();
402 /// Show object Browser
403 void showObjectBrowser();
405 /// Hide object Browser
406 void hideObjectBrowser();
409 void closeDocument();
411 /// Open document from file
414 /// Create a new document
421 /// Open preferences dialog box
422 void onPreferences();
425 /// Activates/deactivates the trihedron in the viewer AIS context
426 void onTrihedronVisibilityChanged(bool theState);
428 /// Apply the current transparency value if preview in transparency dialog is switched on
429 void onTransparencyValueChanged();
431 /// Switch on/off preview of transparency change
432 void onPreviewStateChanged();
435 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
436 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
437 /// \param theOperation an operation
438 void setGrantedFeatures(ModuleBase_Operation* theOperation);
441 /// Display all results
442 //void displayAllResults();
444 /// Display results from document
445 /// \param theDoc a document
446 void displayDocumentResults(DocumentPtr theDoc);
448 /// Display results from a group
449 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
451 /// Insert folder object before currently selected feature
452 void insertFeatureFolder();
454 /// Insert an object to a folder above
455 void insertToFolderBefore();
457 /// Insert an object to a folder below
458 void insertToFolderAfter();
461 /// SLOT, that is called after the operation is started. Update workshop state according to
462 /// the started operation, e.g. visualizes the property panel and connect to it.
463 /// \param theOpertion a started operation
464 // void onOperationStarted(ModuleBase_Operation* theOperation);
466 /// SLOT, that is called after the operation is resumed. Update workshop state according to
467 /// the started operation, e.g. visualizes the property panel and connect to it.
468 /// \param theOpertion a resumed operation
469 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
471 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
472 /// hides the property panel and update the command status.
473 /// \param theOpertion a stopped operation
474 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
476 /// SLOT, that is called after the operation is committed.
477 /// \param theOpertion a committed operation
478 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
480 /// SLOT, that is called after the operation is aborted.
481 /// \param theOpertion an aborted operation
482 void onOperationAborted(ModuleBase_Operation* theOperation);
484 /// Slot, which reacts to the context popup menu call
485 /// \param theId the data value of the clicked action
486 /// \param isChecked a state of toggle if the action is checkable
487 void onContextMenuCommand(const QString& theId, bool isChecked);
489 /// Set waiting cursor
490 void onStartWaiting();
492 /// Called by Ok button clicked in the property panel. Asks the error manager whether
493 /// the operation can be committed and do it if it returns true.
494 void onAcceptActionClicked();
496 /// Called by Preview button clicked in the property panel. Sends signal to model to
498 void onPreviewActionClicked();
504 /// Register validators
505 void registerValidators() const;
507 /// Load module from external library
508 /// \param theModule name of the module
509 ModuleBase_IModule* loadModule(const QString& theModule);
514 /// Create object browser widget
515 /// \param theParent a parent of widget
516 QDockWidget* createObjectBrowser(QWidget* theParent);
518 /// Create property panel widget
519 /// \param theParent a parent of widget
520 QDockWidget* createPropertyPanel(QWidget* theParent);
522 // Creates Dock widgets: Object browser and Property panel
523 void createDockWidgets();
525 //! Extends undo/redo toolbutton's with history menu
526 //! \param theObject - in the OpenParts it is a QToolButton by itself,
527 //! in salome mode - QAction that creates a button.
528 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
529 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
530 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
532 //! Creates list of actions (commands) by given history list from session
533 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
537 AppElements_MainWindow* myMainWindow;
540 ModuleBase_IModule* myModule;
541 XGUI_ErrorMgr* myErrorMgr;
542 XGUI_ObjectsBrowser* myObjectBrowser;
543 XGUI_PropertyPanel* myPropertyPanel;
544 XGUI_SelectionMgr* mySelector;
545 XGUI_Displayer* myDisplayer;
546 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
547 XGUI_ActionsMgr* myActionsMgr;
548 XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
549 XGUI_SalomeConnector* mySalomeConnector;
550 XGUI_ErrorDialog* myErrorDlg;
551 XGUI_ViewerProxy* myViewerProxy;
552 XGUI_ContextMenuMgr* myContextMenuMgr;
553 XGUI_ModuleConnector* myModuleConnector;
554 XGUI_WorkshopListener* myEventsListener;
556 QString myCurrentDir;
558 QIntList myViewerSelMode;
560 Config_DataModelReader* myDataModelXMLReader;