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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #ifndef XGUI_WORKSHOP_H
21 #define XGUI_WORKSHOP_H
24 //#include "XGUI_Constants.h"
25 #include <ModuleBase_Definitions.h>
26 #include <ModelAPI_Document.h>
27 #include <ModelAPI_Feature.h>
29 #include <ModuleBase_ActionInfo.h>
33 #include <QKeySequence>
37 class AppElements_MainWindow;
38 class AppElements_Command;
39 class AppElements_Workbench;
42 class XGUI_ActionsMgr;
43 class XGUI_ContextMenuMgr;
45 class XGUI_ErrorDialog;
48 class XGUI_ModuleConnector;
49 class XGUI_ObjectsBrowser;
50 class XGUI_OperationMgr;
51 class XGUI_PropertyPanel;
52 class XGUI_SalomeConnector;
53 class XGUI_SalomeViewer;
54 class XGUI_SelectionMgr;
55 class XGUI_ViewerProxy;
56 class XGUI_WorkshopListener;
58 class ModuleBase_IModule;
59 class ModuleBase_IViewer;
60 class ModuleBase_Operation;
67 class Config_DataModelReader;
69 /**\class XGUI_Workshop
71 * \brief Class which defines a configuration of the application (Workshop) and launches it.
73 class XGUI_EXPORT XGUI_Workshop : public QObject
78 /// \param theConnector a Salome connector object.
79 /// Used only if the workshop is launched in Salome environment
80 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
81 virtual ~XGUI_Workshop();
83 //! Starting of the application
84 void startApplication();
86 /// Activates the module controls. Should be called after module creation
87 void activateModule();
89 /// Deactivates the module controls. Should be called after module creation
90 void deactivateModule();
93 //! Returns main window (Desktop) of the application
94 AppElements_MainWindow* mainWindow() const
99 //! Creates and adds a new workbench (menu group) with the given name and returns it
100 AppElements_Workbench* addWorkbench(const QString& theName);
103 //! Returns selection manager object
104 XGUI_SelectionMgr* selector() const
109 //! Returns displayer
110 XGUI_Displayer* displayer() const
115 //! ! Returns operation manager.
116 XGUI_OperationMgr* operationMgr() const
118 return myOperationMgr;
121 //! ! Returns error manager.
122 XGUI_ErrorMgr* errorMgr() const
127 //! ! Returns an actions manager
128 XGUI_ActionsMgr* actionsMgr() const
133 //! ! Returns an actions manager
134 XGUI_MenuMgr* menuMgr() const
139 //! Returns property panel widget
140 XGUI_PropertyPanel* propertyPanel() const
142 return myPropertyPanel;
145 //! Returns context menu manager object
146 XGUI_ContextMenuMgr* contextMenuMgr() const
148 return myContextMenuMgr;
151 //! Returns an object which provides interface to Salome Module (LightApp_Module)
152 XGUI_SalomeConnector* salomeConnector() const
154 return mySalomeConnector;
157 //! Provides an object which provides interface to Salome Viewer
158 ModuleBase_IViewer* salomeViewer() const;
160 //! Returns true if the application works as SALOME module
161 bool isSalomeMode() const
163 return mySalomeConnector != 0;
166 //! Returns Object browser
167 XGUI_ObjectsBrowser* objectBrowser() const
169 return myObjectBrowser;
172 /// This method is called by Salome module when selection is changed
173 void salomeViewerSelectionChanged();
175 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
176 XGUI_ViewerProxy* viewer() const
178 return myViewerProxy;
181 /// Returns the module connector
182 /// \returns the instance of connector
183 XGUI_ModuleConnector* moduleConnector() const
185 return myModuleConnector;
188 /// Returns a desktop
189 /// \return a desktop instance
190 QMainWindow* desktop() const;
193 void deleteObjects();
195 //! Searches for selected features unused in other (not selected) features. If one or several
196 //! selected features are found, a warning message proposes to delete them. It contains
197 //! the list of features to be deleted.
200 //! Returns true if the selected feature can be moved to the position after the current feature
201 //! \return boolean value
202 bool canMoveFeature();
204 //! Move selected features to be after the current feature
207 //! Returns true if the object can be shaded. If the object is a compsolid result, the method
208 //! checks subobjects of the result
209 //! \return boolean value
210 bool canBeShaded(const ObjectPtr& theObject) const;
212 //! Returns true if there is at least one selected body/construction/group result
213 //! \return boolean value
214 bool canChangeColor() const;
216 //! Change color of the results if it is possible
217 //! The operation is available for construction, body and group results
218 //! theObjects a list of selected objects
219 void changeColor(const QObjectPtrList& theObjects);
221 //! Returns true if there is at least one selected body/construction/group result
222 //! \return boolean value
223 bool canChangeDeflection() const;
225 //! Change deflection of the results if it is possible
226 //! The operation is available for construction, body and group results
227 //! theObjects a list of selected objects
228 void changeDeflection(const QObjectPtrList& theObjects);
230 //! Show the given features in 3d Viewer
231 void showObjects(const QObjectPtrList& theList, bool isVisible);
233 //! Show the given features in 3d Viewer
234 void showOnlyObjects(const QObjectPtrList& theList);
236 /// Set display mode for the given objects
237 /// \param theList a list of displayed objects
238 /// \param theMode a mode to set (see \ref XGUI_Displayer)
239 void setDisplayMode(const QObjectPtrList& theList, int theMode);
241 /// Set selection mode in viewer. If theMode=-1 then activate default mode
242 /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
243 void setViewerSelectionMode(int theMode);
245 /// Activates current selection mode for the given list of objects
246 void activateObjectsSelection(const QObjectPtrList& theList);
248 /// Returns current module
249 ModuleBase_IModule* module() const
254 /// Returns current directory which contains data files
255 QString currentDataDir() const { return myCurrentDir; }
257 /// Returns current directory which contains data files
258 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
261 * Save the current document into a directory
262 * \param theName - path to the directory
263 * \param theFileNames - returned file names created in this directory
265 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
268 * If there is an active (uncommitted) operation shows a prompt to abort it
269 * and performs abortion if user agreed. Returns true if
270 * - operation aborted successfully
271 * - there is no active operation
273 bool abortAllOperations();
275 /// Updates workshop state according to the started operation, e.g. visualizes the property panel
276 /// and connect to it.
277 /// \param theOpertion a started operation
278 void operationStarted(ModuleBase_Operation* theOperation);
281 //! Delete features. Delete the referenced features. There can be a question with a list of
282 //! referenced objects.
283 //! \param theFeatures a list of objects to be deleted
284 bool deleteFeatures(const QObjectPtrList& theFeatures);
286 /// Deactivates the object, if it is active and the module returns that the activation
287 /// of selection for the object is not possible currently(the current operation uses it)
288 /// \param theObject an object
289 /// \param theUpdateViewer a boolean flag to update viewer immediately
290 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
292 /// Returns true if the action of the feature is created to contain Accept/Cancel button
293 /// \param theFeature a feature
294 bool isFeatureOfNested(const FeaturePtr& theFeature);
296 //! Shows the message in the status bar
297 //! \param theMessage a message
298 void setStatusBarMessage(const QString& theMessage);
300 /// Has to be called in order to display objects with visibility status = true
301 void synchronizeViewer();
303 /// Has to be called in order to display objects from a specifed group
304 /// with visibility status = true
305 /// \param theDoc the document for objects synchronisation
306 /// \param theGroup the group name
307 /// \param theUpdateViewer update viewer flag
308 void synchronizeGroupInViewer(const DocumentPtr& theDoc,
309 const std::string& theGroup,
310 bool theUpdateViewer);
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 fillPropertyPanel(ModuleBase_Operation* theOperation);
317 /// Connects or disconnects to the value changed signal of the property panel widgets
318 /// \param isToConnect a boolean value whether connect or disconnect
319 void connectToPropertyPanel(const bool isToConnect);
321 /// Returns defailt selection mode in 3d viewer
322 QIntList viewerSelectionModes() const { return myViewerSelMode; }
324 /// Highlights result objects in Object Browser according to
325 /// features found in the given list
326 void highlightResults(const QObjectPtrList& theObjects);
328 /// Highlights feature objects in Object Browser according to
329 /// features found in the given list
330 void highlightFeature(const QObjectPtrList& theObjects);
332 /// Returns Data Model XML reader which contains information about
333 /// Data structure configuration
334 const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
336 /// A constant string used for "Move to end" command definition
337 /// It is used for specific processing of Undo/Redo for this command.
338 static QString MOVE_TO_END_COMMAND;
340 //! Closes all in the current session and load the directory
341 //! \param theDirectory a path to directory
342 void openDirectory(const QString& theDirectory);
345 /// Emitted when selection happens in Salome viewer
346 void salomeViewerSelection();
348 //! the signal about the workshop actions states are updated.
349 void commandStatusUpdated();
351 //! the application is started
352 void applicationStarted();
354 //! Signal to update Undo history list
355 void updateUndoHistory(const QList<ActionInfo>&);
357 //! Signal to update Redo history list
358 void updateRedoHistory(const QList<ActionInfo>&);
361 /// Update of commands status
362 void updateCommandStatus();
364 /// update history list (undo/redo commands)
365 void updateHistory();
367 /// Save current document
370 /// Save current document to a file selected by user
373 /// Undo last command
374 void onUndo(int times = 1);
376 /// Redo previous command
377 void onRedo(int times = 1);
382 /// Validates the operation to change the "Apply" button state.
383 /// \param thePreviousState the previous state of the widget
384 void onWidgetStateChanged(int thePreviousState);
386 /// Calls activate of the current widget again. It is possible that selection filters are
387 /// differs in the new state of paged container
388 void onValuesChanged();
390 /// Listens the corresponded signal of model widget and updates Apply button state by feature
391 void onWidgetObjectUpdated();
393 /// Show property panel
394 void showPropertyPanel();
396 /// Hide property panel
397 void hidePropertyPanel();
399 /// Show object Browser
400 void showObjectBrowser();
402 /// Hide object Browser
403 void hideObjectBrowser();
406 void closeDocument();
408 /// Open document from file
411 /// Create a new document
418 /// Open preferences dialog box
419 void onPreferences();
422 /// Activates/deactivates the trihedron in the viewer AIS context
423 void onTrihedronVisibilityChanged(bool theState);
427 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
428 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
429 /// \param theOperation an operation
430 void setGrantedFeatures(ModuleBase_Operation* theOperation);
433 /// Display all results
434 //void displayAllResults();
436 /// Display results from document
437 /// \param theDoc a document
438 void displayDocumentResults(DocumentPtr theDoc);
440 /// Display results from a group
441 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
444 /// SLOT, that is called after the operation is started. Update workshop state according to
445 /// the started operation, e.g. visualizes the property panel and connect to it.
446 /// \param theOpertion a started operation
447 // void onOperationStarted(ModuleBase_Operation* theOperation);
449 /// SLOT, that is called after the operation is resumed. Update workshop state according to
450 /// the started operation, e.g. visualizes the property panel and connect to it.
451 /// \param theOpertion a resumed operation
452 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
454 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
455 /// hides the property panel and update the command status.
456 /// \param theOpertion a stopped operation
457 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
459 /// SLOT, that is called after the operation is committed.
460 /// \param theOpertion a committed operation
461 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
463 /// SLOT, that is called after the operation is aborted.
464 /// \param theOpertion an aborted operation
465 void onOperationAborted(ModuleBase_Operation* theOperation);
467 /// Slot, which reacts to the context popup menu call
468 /// \param theId the data value of the clicked action
469 /// \param isChecked a state of toggle if the action is checkable
470 void onContextMenuCommand(const QString& theId, bool isChecked);
472 /// Set waiting cursor
473 void onStartWaiting();
475 /// Called by Ok button clicked in the property panel. Asks the error manager whether
476 /// the operation can be committed and do it if it returns true.
477 void onAcceptActionClicked();
479 /// Called by Preview button clicked in the property panel. Sends signal to model to
481 void onPreviewActionClicked();
487 /// Register validators
488 void registerValidators() const;
490 /// Load module from external library
491 /// \param theModule name of the module
492 ModuleBase_IModule* loadModule(const QString& theModule);
497 /// Create object browser widget
498 /// \param theParent a parent of widget
499 QDockWidget* createObjectBrowser(QWidget* theParent);
501 /// Create property panel widget
502 /// \param theParent a parent of widget
503 QDockWidget* createPropertyPanel(QWidget* theParent);
505 // Creates Dock widgets: Object browser and Property panel
506 void createDockWidgets();
508 //! Extends undo/redo toolbutton's with history menu
509 //! \param theObject - in the OpenParts it is a QToolButton by itself,
510 //! in salome mode - QAction that creates a button.
511 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
512 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
513 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
515 //! Creates list of actions (commands) by given history list from session
516 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
520 AppElements_MainWindow* myMainWindow;
523 ModuleBase_IModule* myModule;
524 XGUI_ErrorMgr* myErrorMgr;
525 XGUI_ObjectsBrowser* myObjectBrowser;
526 XGUI_PropertyPanel* myPropertyPanel;
527 XGUI_SelectionMgr* mySelector;
528 XGUI_Displayer* myDisplayer;
529 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
530 XGUI_ActionsMgr* myActionsMgr;
531 XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
532 XGUI_SalomeConnector* mySalomeConnector;
533 XGUI_ErrorDialog* myErrorDlg;
534 XGUI_ViewerProxy* myViewerProxy;
535 XGUI_ContextMenuMgr* myContextMenuMgr;
536 XGUI_ModuleConnector* myModuleConnector;
537 XGUI_WorkshopListener* myEventsListener;
539 QString myCurrentDir;
541 QIntList myViewerSelMode;
543 Config_DataModelReader* myDataModelXMLReader;