1 // Copyright (C) 2014-2022 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
20 #include "XGUI_Workshop.h"
22 #include "XGUI_ActionsMgr.h"
23 #include "XGUI_ActiveControlMgr.h"
24 #include "XGUI_ActiveControlSelector.h"
25 #include "XGUI_MenuMgr.h"
26 #include "XGUI_ColorDialog.h"
27 #include "XGUI_DeflectionDialog.h"
28 #include "XGUI_TransparencyWidget.h"
29 #include "XGUI_ContextMenuMgr.h"
30 #include "XGUI_Displayer.h"
31 #include "XGUI_ErrorDialog.h"
32 #include "XGUI_ErrorMgr.h"
33 #include "XGUI_FacesPanel.h"
34 #include "XGUI_FacesPanelSelector.h"
35 #include "XGUI_ModuleConnector.h"
36 #include "XGUI_ObjectsBrowser.h"
37 #include "XGUI_OperationMgr.h"
38 #include "XGUI_PropertyPanel.h"
39 #include "XGUI_PropertyPanelSelector.h"
40 #include "XGUI_PropertyDialog.h"
41 #include "XGUI_SalomeConnector.h"
42 #include "XGUI_Selection.h"
43 #include "XGUI_SelectionActivate.h"
44 #include "XGUI_SelectionMgr.h"
45 #include "XGUI_Tools.h"
46 #include "XGUI_ViewerProxy.h"
47 #include "XGUI_WorkshopListener.h"
48 #include <XGUI_HistoryMenu.h>
49 #include <XGUI_QtEvents.h>
50 #include <XGUI_DataModel.h>
51 #include <XGUI_InspectionPanel.h>
52 #include <XGUI_CompressFiles.h>
55 #include <SUIT_Application.h>
56 #include <SUIT_Session.h>
58 #include <AppElements_Button.h>
59 #include <AppElements_Command.h>
60 #include <AppElements_MainMenu.h>
61 #include <AppElements_MainWindow.h>
62 #include <AppElements_MenuGroupPanel.h>
63 #include <AppElements_Viewer.h>
64 #include <AppElements_Workbench.h>
67 #include <Config_XMLReader.h>
69 #include <ModelAPI_AttributeDocRef.h>
70 #include <ModelAPI_AttributeIntArray.h>
71 #include <ModelAPI_AttributeDouble.h>
72 #include <ModelAPI_AttributeString.h>
73 #include <ModelAPI_Data.h>
74 #include <ModelAPI_Events.h>
75 #include <ModelAPI_Feature.h>
76 #include <ModelAPI_Object.h>
77 #include <ModelAPI_ResultBody.h>
78 #include <ModelAPI_ResultConstruction.h>
79 #include <ModelAPI_ResultGroup.h>
80 #include <ModelAPI_ResultParameter.h>
81 #include <ModelAPI_ResultField.h>
82 #include <ModelAPI_Session.h>
83 #include <ModelAPI_Validator.h>
84 #include <ModelAPI_Tools.h>
85 #include <ModelAPI_ResultField.h>
86 #include <ModuleBase_IconFactory.h>
88 //#include <PartSetPlugin_Part.h>
90 #include <Events_Loop.h>
91 #include <Events_InfoMessage.h>
92 #include <Events_LongOp.h>
94 #include <ExchangePlugin_ExportPart.h>
95 #include <ExchangePlugin_ImportPart.h>
96 #include <ExchangePlugin_Import.h>
97 #include <ExchangePlugin_ExportFeature.h>
99 #include <GeomAPI_Pnt.h>
100 #include <GeomAPI_ShapeExplorer.h>
102 #include <ModuleBase_IModule.h>
103 #include <ModuleBase_IViewer.h>
104 #include <ModuleBase_Operation.h>
105 #include <ModuleBase_OperationDescription.h>
106 #include <ModuleBase_PageBase.h>
107 #include <ModuleBase_Preferences.h>
108 #include <ModuleBase_SelectionValidator.h>
109 #include <ModuleBase_Tools.h>
110 #include <ModuleBase_WidgetFactory.h>
111 #include <ModuleBase_OperationFeature.h>
112 #include <ModuleBase_PagedContainer.h>
113 #include <ModuleBase_WidgetValidated.h>
114 #include <ModuleBase_ModelWidget.h>
115 #include <ModuleBase_ResultPrs.h>
116 #include <ModuleBase_ActionIntParameter.h>
117 #include <ModuleBase_IStepPrs.h>
119 #include <Config_Common.h>
120 #include <Config_FeatureMessage.h>
121 #include <Config_ModuleReader.h>
122 #include <Config_PointerMessage.h>
123 #include <Config_PropManager.h>
124 #include <Config_DataModelReader.h>
125 #include <Config_Translator.h>
126 #include <Config_WidgetAPI.h>
127 #include <Config_Keywords.h>
129 #include <SUIT_ResourceMgr.h>
131 #include <AIS_Trihedron.hxx>
132 #ifdef BEFORE_TRIHEDRON_PATCH
133 #include <AIS_Point.hxx>
134 #include <AIS_Axis.hxx>
137 #include <QApplication>
138 #include <QFileDialog>
139 #include <QMessageBox>
140 #include <QMdiSubWindow>
141 #include <QMainWindow>
142 #include <QPushButton>
143 #include <QDockWidget>
148 #include <QToolButton>
150 #include <QDesktopWidget>
152 #include <QDesktopServices>
153 #include <QFormLayout>
155 #include <QDialogButtonBox>
161 #include <TDocStd_Application.hxx>
162 #include <inspector/TInspector_Communicator.hxx>
163 #include <inspector/VInspector_CallBack.hxx>
164 static TInspector_Communicator* MyTCommunicator;
165 static Handle(VInspector_CallBack) MyVCallBack;
175 #pragma warning(disable : 4456) // for nested foreach
176 #pragma warning(disable : 4189) // for declaration of unused variables (MAYBE_UNUSED)
181 //#define DEBUG_WITH_MESSAGE_REPORT
183 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
184 QString XGUI_Workshop::MOVE_TO_END_SPLIT_COMMAND = QObject::tr("Move to the end and split");
186 //#define DEBUG_DELETE
187 //#define DEBUG_FEATURE_NAME
188 //#define DEBUG_CLEAN_HISTORY
191 static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.cadbld)"));
192 static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)"));
193 static QString MyExtension(".shaper");
195 static QString MyFilter(QObject::tr("CAD Builder files (*.cadbld);;All files (*.*)"));
196 static QString MyFilter2(QObject::tr("CAD Builder files (*.cadbld)"));
197 static QString MyExtension(".cadbld");
200 static QString MyImportPartFilter(QObject::tr("Part files (*.shaperpart);;All files (*.*)"));
203 //******************************************************
204 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
211 mySalomeConnector(theConnector),
212 //myViewerSelMode(TopAbs_FACE),
215 mySelector = new XGUI_SelectionMgr(this);
216 myModuleConnector = new XGUI_ModuleConnector(this);
217 myOperationMgr = new XGUI_OperationMgr(this, myModuleConnector);
218 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
219 // Has to be defined first in order to get errors and messages from other components
220 myEventsListener = new XGUI_WorkshopListener(this);
221 mySelectionActivate = new XGUI_SelectionActivate(aWorkshop);
223 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
225 myMainWindow = new AppElements_MainWindow();
227 bool aCloc = aResMgr->booleanValue("language", "locale", true);
229 QLocale::setDefault( QLocale::c() );
231 QLocale::setDefault( QLocale::system() );
233 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
238 aLangs << "*_en.ts"; // load by default eng translations
240 /// If version of OCCT is 7.4.0 or more then it means that
241 /// this is version of SALOME older then 9.4.0
242 #if OCC_VERSION_HEX >= 0x070400
243 QString aCurrLang = aResMgr->language();
245 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
248 if(aCurrLang != "en") {
249 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
252 foreach(QString aLang, aLangs) {
253 QStringList aFilters;
255 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
256 foreach(QString aFileName, aTsFiles) {
257 Config_Translator::load(aFileName.toStdString());
261 myDataModelXMLReader = new Config_DataModelReader();
262 //myDataModelXMLReader->readAll();
264 myDisplayer = new XGUI_Displayer(this);
266 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
268 myActionsMgr = new XGUI_ActionsMgr(this);
269 myActiveControlMgr = new XGUI_ActiveControlMgr(myModuleConnector);
270 myMenuMgr = new XGUI_MenuMgr(this);
271 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
272 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
273 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
274 SLOT(onContextMenuCommand(const QString&, bool)));
276 myViewerProxy = new XGUI_ViewerProxy(this);
277 //connect(myViewerProxy, SIGNAL(selectionChanged()),
278 // myActionsMgr, SLOT(updateOnViewSelection()));
280 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
282 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
283 SLOT(onOperationResumed(ModuleBase_Operation*)));
284 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
285 SLOT(onOperationStopped(ModuleBase_Operation*)));
286 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
287 SLOT(onOperationCommitted(ModuleBase_Operation*)));
288 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
289 SLOT(onOperationAborted(ModuleBase_Operation*)));
292 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
293 myDisplayer->displayTrihedron(true);
296 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
297 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
299 Config_PropManager::registerProp("Visualization", "selection_color", "Selection color",
300 Config_Prop::Color, "255,255,255");
302 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
303 myViewerSelMode.append(TopAbs_FACE);
304 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
305 myViewerSelMode.append(TopAbs_EDGE);
306 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
307 myViewerSelMode.append(TopAbs_VERTEX);
308 //IMP: an attempt to use result selection with other selection modes
309 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
310 myViewerSelMode.append(TopAbs_COMPSOLID);
313 //******************************************************
314 XGUI_Workshop::~XGUI_Workshop(void)
317 #ifdef MISSED_TRANSLATION
318 // Save Missed translations
319 Config_Translator::saveMissedTranslations();
324 delete myDataModelXMLReader;
325 delete mySelectionActivate;
330 //******************************************************
331 void XGUI_Workshop::startApplication()
333 //Initialize event listening
334 myEventsListener->initializeEventListening();
336 myDataModelXMLReader->readAll();
339 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
340 Config_Prop::Directory, "");
342 std::string aDir = Config_XMLReader::resourcesConfigFile();
343 Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
344 Config_Prop::Directory, aDir);
347 Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start",
348 Config_Prop::Boolean, "false");
350 Config_PropManager::registerProp("Plugins", "show_hide_faces", "Show Hide Faces (on the right)",
351 Config_Prop::Boolean, "false");
353 registerValidators();
355 // Calling of loadCustomProps before activating module is required
356 // by Config_PropManger to restore user-defined path to plugins
357 ModuleBase_Preferences::loadCustomProps();
358 std::vector<int> aColor;
360 aColor = Config_PropManager::color("Visualization", "selection_color");
364 if (aColor.size() == 3)
365 myDisplayer->setSelectionColor(aColor);
370 myMainWindow->show();
371 updateCommandStatus();
376 myViewerProxy->connectViewProxy();
377 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
378 SLOT(onTrihedronVisibilityChanged(bool)));
380 emit applicationStarted();
383 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
385 module()->launchOperation("Part", false); // PartSetPlugin_Part::ID()
390 //******************************************************
391 void XGUI_Workshop::activateModule()
393 selectionActivate()->updateSelectionFilters();
395 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
396 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
397 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
398 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
400 updateCommandStatus();
402 // TODO: get default selection mode
404 // activate visualized objects in the viewer
405 activateObjectsSelection(displayer()->displayedObjects());
406 myOperationMgr->activate();
409 //******************************************************
410 void XGUI_Workshop::deactivateModule()
412 // remove internal displayer filter
413 displayer()->deactivateSelectionFilters(false);
415 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
416 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
417 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
418 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
420 XGUI_Displayer* aDisplayer = displayer();
421 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
422 aDisplayer->deactivateObjects(aDisplayed, true);
423 selectionActivate()->deactivateTrihedronInSelectionModes();
425 #ifdef BEFORE_TRIHEDRON_PATCH
426 //Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
427 /// Trihedron problem: objects stayed in the viewer, should be removed manually
428 /// otherwise in SALOME happens crash by HideAll in the viewer
429 aContext->Remove(aTrihedron->Position(), true);
430 aContext->Remove(aTrihedron->Axis(), true);
431 aContext->Remove(aTrihedron->XAxis(), true);
432 aContext->Remove(aTrihedron->YAxis(), true);
435 myOperationMgr->deactivate();
438 //******************************************************
439 void XGUI_Workshop::initMenu()
441 myContextMenuMgr->createActions();
444 // Create only Undo, Redo commands
445 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
446 tr("Undo last command"),
447 QIcon(":pictures/undo.png"),
448 QKeySequence::Undo, false,
450 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
451 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
453 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
454 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
456 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
457 QIcon(":pictures/redo.png"), QKeySequence::Redo,
458 false, "MEN_DESK_EDIT");
459 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
461 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
462 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
464 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
466 //aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
467 // tr("Blocks immediate apply of modifications"),
468 // QIcon(":pictures/autoapply.png"), QKeySequence(),
469 // false, "MEN_DESK_EDIT");
470 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
472 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onAutoApply()));
474 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
477 // Add commands to a file menu
479 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Part set..."),
480 tr("Import native file"),
481 QIcon(), QKeySequence(),
482 false, "MEN_DESK_FILE", tr("Import"), 10, 10);
483 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
485 aAction = salomeConnector()->addDesktopCommand("IMPORT_PART_CMD", tr("Part..."),
486 tr("Import structure of a part"),
487 QIcon(), QKeySequence(),
488 false, "MEN_DESK_FILE", tr("Import"), 10, 10);
489 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportPart()));
491 aAction = salomeConnector()->addDesktopCommand("IMPORT_SHAPE_CMD", tr("From CAD format..."),
492 tr("Import shape from a CAD format file"),
493 ModuleBase_IconFactory::loadIcon("icons/Exchange/import.png"),
494 QKeySequence(), false, "MEN_DESK_FILE", tr("Import"), 10, 10);
495 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportShape()));
497 aAction = salomeConnector()->addDesktopCommand("IMPORT_IMAGE_CMD", tr("Picture..."),
498 tr("Import a picture from an image file"),
500 QKeySequence(), false, "MEN_DESK_FILE", tr("Import"), 10, 10);
501 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportImage()));
504 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Part set..."),
505 tr("Export the current document into a native file"),
506 QIcon(), QKeySequence(),
507 false, "MEN_DESK_FILE", tr("Export"), 10, 11);
508 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
510 aAction = salomeConnector()->addDesktopCommand("EXPORT_PART_CMD", tr("Part..."),
511 tr("Export a part of the current document into a file"),
512 QIcon(), QKeySequence(),
513 false, "MEN_DESK_FILE", tr("Export"), 10, 11);
514 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportPart()));
516 aAction = salomeConnector()->addDesktopCommand("EXPORT_SHAPE_CMD", tr("To CAD format..."),
517 tr("Export shape to a CAD format file"),
518 ModuleBase_IconFactory::loadIcon("icons/Exchange/export.png"),
519 QKeySequence(), false, "MEN_DESK_FILE", tr("Export"), 10, 11);
520 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportShape()));
523 // File commands group
524 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
526 AppElements_Command* aCommand;
528 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
529 QIcon(":pictures/save.png"), QKeySequence::Save);
530 aCommand->connectTo(this, SLOT(onSave()));
531 //aCommand->disable();
533 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
534 QIcon(":pictures/save.png"), QKeySequence());
535 aCommand->connectTo(this, SLOT(onSaveAs()));
537 QString aUndoId = "UNDO_CMD";
538 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
539 QIcon(":pictures/undo.png"), QKeySequence::Undo);
540 aCommand->connectTo(this, SLOT(onUndo()));
541 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
542 addHistoryMenu(aUndoButton,
543 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
546 QString aRedoId = "REDO_CMD";
547 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
548 QIcon(":pictures/redo.png"), QKeySequence::Redo);
549 aCommand->connectTo(this, SLOT(onRedo()));
550 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
551 addHistoryMenu(aRedoButton,
552 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
555 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
556 QIcon(":pictures/open.png"), QKeySequence::Open);
557 aCommand->connectTo(this, SLOT(onOpen()));
560 aCommand = aGroup->addFeature("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
561 tr("Blocks immediate apply of modifications"),
562 QIcon(":pictures/autoapply_start.png"), QKeySequence());
563 aCommand->setChecked(ModelAPI_Session::get()->isAutoUpdateBlocked());
564 aCommand->connectTo(this, SLOT(onAutoApply()));
566 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
567 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
568 aCommand->connectTo(this, SLOT(onPreferences()));
570 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
571 QIcon(":pictures/close.png"), QKeySequence::Close);
572 aCommand->connectTo(this, SLOT(onExit()));
577 //******************************************************
578 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
580 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
581 return aMenuBar->addWorkbench(theName);
585 //******************************************************
586 QMainWindow* XGUI_Workshop::desktop() const
589 return salomeConnector()->desktop();
595 //******************************************************
596 void XGUI_Workshop::onStartWaiting()
598 if (Events_LongOp::isPerformed()) {
599 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
603 //******************************************************
604 void XGUI_Workshop::onAcceptActionClicked()
606 XGUI_OperationMgr* anOperationMgr = operationMgr();
607 if (anOperationMgr) {
608 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
609 (anOperationMgr->currentOperation());
611 myOperationMgr->commitOperation();
616 //******************************************************
617 void XGUI_Workshop::onAcceptPlusActionClicked()
619 XGUI_OperationMgr* anOperationMgr = operationMgr();
620 if (anOperationMgr) {
621 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
622 (anOperationMgr->currentOperation());
624 if (myOperationMgr->commitOperation())
625 module()->launchOperation(aFOperation->id(), false);
630 //******************************************************
631 void XGUI_Workshop::onPreviewActionClicked()
633 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
635 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
636 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
637 anActiveWidget->storeValue();
640 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
641 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
642 Events_Loop::loop()->send(aMsg);
646 //******************************************************
647 void XGUI_Workshop::onHelpActionClicked() const
649 XGUI_OperationMgr* anOperationMgr = operationMgr();
650 if (anOperationMgr) {
651 ModuleBase_Operation* aOperation = anOperationMgr->currentOperation();
653 showHelpPage(aOperation->helpFileName());
658 void XGUI_Workshop::showHelpPage(const QString& thePage) const
660 if (!thePage.isEmpty()) {
662 const QChar aSep = QDir::separator();
664 // SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
666 // platform = "winapplication";
668 // platform = "application";
670 // QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform);
673 QString aDir(getenv("SHAPER_ROOT_DIR"));
674 if (!aDir.isEmpty()) {
675 aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep +
676 "salome" + aSep + "gui" + aSep + "SHAPER";
679 QString aDir(getenv("CADBUILDER_ROOT_DIR"));
680 aDocDir = aDir + aSep + "doc" + aSep + "gui";
682 QString aFileName = aDocDir + aSep + thePage;
683 if (QFile::exists(aFileName)) {
685 SUIT_Application* app = SUIT_Session::session()->activeApplication();
687 app->onHelpContextModule("SHAPER", aFileName);
689 QUrl aUrl = QUrl::fromLocalFile(aFileName);
690 QDesktopServices::openUrl(aUrl);
693 QUrl aUrl = QUrl::fromLocalFile(aFileName);
694 QDesktopServices::openUrl(aUrl);
701 //******************************************************
702 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
704 if (!myModule->canActivateSelection(theObject)) {
705 if (selectionActivate()->isActive(theObject)) {
706 QObjectPtrList anObjects;
707 anObjects.append(theObject);
708 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
713 //******************************************************
714 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
716 bool aHasNested = false;
717 std::string aFeatureKind = theFeature->getKind();
719 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
720 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
723 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
724 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
725 if (aCommand && aCommand->button()->additionalButtonWidget())
731 //******************************************************
732 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
734 ModuleBase_OperationFeature* aFOperation =
735 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
739 myPropertyPanel->cleanContent();
741 QList<ModuleBase_ModelWidget*> aWidgets;
742 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
743 if (!module()->createWidgets(aFOperation->feature(), aXmlRepr, aWidgets)) {
744 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
745 aFactory.createWidget(myPropertyPanel->contentWidget());
746 aWidgets = aFactory.getModelWidgets();
749 // check compatibility of feature and widgets
750 FeaturePtr aFeature = aFOperation->feature();
751 std::string aFeatureKind = aFeature->getKind();
752 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
753 if (aWidget->usesAttribute()) {
754 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
755 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
756 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
757 .arg(aFeatureKind).arg(aWidget->attributeID())
758 .arg(aWidget->metaObject()->className()).send();
759 myPropertyPanel->cleanContent();
764 // for performance purpose, flush should be done after all controls are filled
765 bool isUpdateFlushed = false;
766 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
767 bool isStoreValue = !aFOperation->isEditOperation() &&
768 !aWidget->getDefaultValue().empty() &&
769 !aWidget->isComputedDefault();
770 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
772 aWidget->restoreValue();
773 aWidget->enableFocusProcessing();
775 // update visible state of Preview button
776 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
778 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
780 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
781 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
783 aFeatureInfo = aCommand->featureMessage();
785 bool anIsAutoPreview = true;
786 if (aFeatureInfo.get()) {
787 anIsAutoPreview = aFeatureInfo->isAutoPreview();
788 theOperation->setHelpFileName(aFeatureInfo->helpFileName().c_str());
790 std::string aXmlCfg, aDescription;
791 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
792 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
793 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
796 if (!anIsAutoPreview) {
797 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
798 // send signal about preview should not be computed automatically, click on preview
799 // button should initiate it
800 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
801 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
802 Events_Loop::loop()->send(aMsg);
804 // if update happens after preview is blocked, it does nothing when blocked
805 // it improves performance for valid objects on feature start
806 ModuleBase_Tools::flushUpdated(aFeature);
808 myPropertyPanel->setModelWidgets(aWidgets);
809 aFOperation->setPropertyPanel(myPropertyPanel);
811 myModule->propertyPanelDefined(theOperation);
813 #ifndef DEBUG_FEATURE_NAME
814 myPropertyPanel->setWindowTitle(ModuleBase_Tools::translate("workshop",
815 theOperation->getDescription()->description().toStdString()));
817 std::string aFeatureName = aFeature->name();
818 myPropertyPanel->setWindowTitle(QString("%1: %2")
819 .arg(translate(theOperation->getDescription()->description()))
820 .arg(translate(aFeatureName.c_str())));
823 myErrorMgr->setPropertyPanel(myPropertyPanel);
824 if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) {
825 theOperation->setHideFacesVisible(myFacesPanel->isVisible());
826 if (aFeatureInfo.get() && aFeatureInfo->isHideFacesPanel() && !myFacesPanel->isVisible())
827 myFacesPanel->show();
829 showPanel(myPropertyPanel);
832 //******************************************************
833 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
835 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
836 if (aPropertyPanel) {
837 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
838 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
839 myModule->connectToPropertyPanel(aWidget, isToConnect);
841 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
842 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
843 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
846 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
847 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
848 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
854 //******************************************************
855 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
857 setGrantedFeatures(theOperation);
859 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
860 fillPropertyPanel(theOperation);
861 connectToPropertyPanel(true);
862 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
865 myPropertyPanel->updateApplyPlusButton(aFOperation->feature());
867 myPropertyPanel->updateApplyPlusButton(FeaturePtr());
869 updateCommandStatus();
871 myModule->operationResumed(theOperation);
874 //******************************************************
875 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
877 updateCommandStatus();
879 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
884 ModuleBase_ISelection* aSel = mySelector->selection();
885 QObjectPtrList aObj = aSel->selectedPresentations();
886 //!< No need for property panel
887 hidePanel(myPropertyPanel);
888 myPropertyPanel->cleanContent();
890 connectToPropertyPanel(false);
891 myModule->operationStopped(aFOperation);
893 // the deactivated objects of the current operation should be activated back.
894 // They were deactivated on operation start or an object redisplay
895 QObjectPtrList anObjects;
896 FeaturePtr aFeature = aFOperation->feature();
897 if (aFeature.get()) { // feature may be not created (plugin load fail)
898 if (myDisplayer->isVisible(aFeature) && !selectionActivate()->isActive(aFeature))
899 anObjects.append(aFeature);
900 std::list<ResultPtr> aResults;
901 ModelAPI_Tools::allResults(aFeature, aResults);
902 std::list<ResultPtr>::const_iterator aIt;
903 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
904 ResultPtr anObject = *aIt;
905 if (myDisplayer->isVisible(anObject) && !selectionActivate()->isActive(anObject)) {
906 anObjects.append(anObject);
910 activateObjectsSelection(anObjects);
912 if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) {
913 if (!theOperation->isHideFacesVisible())
914 myFacesPanel->close();
918 //******************************************************
919 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
921 myModule->operationCommitted(theOperation);
924 //******************************************************
925 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
927 myModule->operationAborted(theOperation);
930 //******************************************************
931 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
933 ModuleBase_OperationFeature* aFOperation =
934 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
938 QStringList aGrantedIds;
939 if (isSalomeMode()) {
940 const std::shared_ptr<Config_FeatureMessage>& anInfo =
941 mySalomeConnector->featureInfo(theOperation->id());
943 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
944 .split(" ", QString::SkipEmptyParts);
947 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
949 ModuleBase_IModule* aModule = module();
951 aModule->grantedOperationIds(theOperation, aGrantedIds);
953 aFOperation->setGrantedOperationIds(aGrantedIds);
956 //******************************************************
957 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
959 QApplication::restoreOverrideCursor();
960 SessionPtr aMgr = ModelAPI_Session::get();
962 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
963 std::list<DocumentPtr>::const_iterator aIt;
964 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
965 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
966 (*aIt)->storeNodesState(aState);
969 aMgr->save(theName.toLatin1().constData(), theFileNames);
971 QApplication::restoreOverrideCursor();
974 //******************************************************
975 bool XGUI_Workshop::abortAllOperations()
977 return myOperationMgr->abortAllOperations();
980 //******************************************************
981 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
983 setGrantedFeatures(theOperation);
984 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
985 updateCommandStatus();
988 myModule->operationStarted(theOperation);
992 //******************************************************
993 void XGUI_Workshop::onOpen()
995 if(!abortAllOperations())
997 //save current file before close if modified
998 SessionPtr aSession = ModelAPI_Session::get();
999 if (aSession->isModified()) {
1000 int anAnswer = QMessageBox::question(
1001 desktop(), tr("Save current file"),
1002 tr("The document is modified, save before opening another?"),
1003 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
1004 if (anAnswer == QMessageBox::Save) {
1006 } else if (anAnswer == QMessageBox::Cancel) {
1009 myCurrentFile = QString();
1012 //show file dialog, check if readable and open
1013 qreal aRatio = ModuleBase_Tools::currentPixelRatio();
1014 // If the ratio is > 1 (HD screen) then QT has a bug in
1015 // displaying of system open file dialog (too small)
1016 QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Open file"), QString(), MyFilter,
1017 Q_NULLPTR, ((aRatio > 1)? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
1018 if (!aFile.isNull())
1022 //******************************************************
1023 void XGUI_Workshop::openFile(const QString& theDirectory)
1025 myCurrentFile = theDirectory;
1026 if (myCurrentFile.isEmpty())
1029 QFileInfo aFileInfo(myCurrentFile);
1030 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
1031 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
1032 myCurrentFile = QString();
1036 QApplication::setOverrideCursor(Qt::WaitCursor);
1037 module()->closeDocument();
1038 SessionPtr aSession = ModelAPI_Session::get();
1039 aSession->closeAll();
1041 clearTemporaryDir();
1042 if (!XGUI_CompressFiles::uncompress(myCurrentFile, myTmpDir.path()))
1045 aSession->load(myTmpDir.path().toLatin1().constData());
1046 myObjectBrowser->rebuildDataTree();
1048 // Open first level of data tree
1049 DocumentPtr aRootDoc = aSession->moduleDocument();
1050 std::list<bool> aStates;
1051 aRootDoc->restoreNodesState(aStates);
1052 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
1054 updateCommandStatus();
1056 myMainWindow->setCurrentDir(myCurrentFile, true);
1060 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
1062 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
1064 ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
1065 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
1072 int anActivationId =
1073 ModuleBase_Preferences::resourceMgr()->integerValue("General", "part_activation_study", -1);
1074 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
1076 if (anActivationId == 0 && aSize > 0) {
1077 ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), aSize - 1);
1078 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
1081 ModuleBase_Tools::setDisplaying(aPart);
1084 else if (anActivationId == 1) {
1085 for (int anIndex = 0; anIndex < aSize; ++anIndex) {
1086 ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), anIndex);
1087 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
1090 ModuleBase_Tools::setDisplaying(aPart);
1092 if (anIndex < aSize - 1) {
1093 SessionPtr aMgr = ModelAPI_Session::get();
1094 aMgr->startOperation("Activation");
1095 aMgr->setActiveDocument(aMgr->moduleDocument());
1096 aMgr->finishOperation();
1097 updateCommandStatus();
1103 QApplication::restoreOverrideCursor();
1106 //******************************************************
1107 void XGUI_Workshop::onNew()
1109 QApplication::setOverrideCursor(Qt::WaitCursor);
1110 if (objectBrowser() == 0) {
1111 createDockWidgets();
1112 mySelector->connectViewers();
1114 myViewerProxy->connectToViewer();
1115 showObjectBrowser();
1117 myMainWindow->showPythonConsole();
1118 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
1119 aWnd->showMaximized();
1120 updateCommandStatus();
1121 PyConsole_Console* aConsole = myMainWindow->pythonConsole();
1122 connect(aConsole, SIGNAL(scriptLoaded()), SLOT(updateCommandStatus()));
1124 myContextMenuMgr->connectViewer();
1125 QApplication::restoreOverrideCursor();
1129 //******************************************************
1130 void XGUI_Workshop::onExit()
1132 SessionPtr aMgr = ModelAPI_Session::get();
1133 if (aMgr->isModified()) {
1134 int anAnswer = QMessageBox::question(
1135 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
1136 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
1137 if (anAnswer == QMessageBox::Save) {
1138 bool saved = onSave();
1142 } else if (anAnswer == QMessageBox::Cancel) {
1149 //******************************************************
1150 void XGUI_Workshop::onPreferences()
1152 ModuleBase_Prefs aModif;
1153 ModuleBase_Preferences::editPreferences(aModif);
1154 if (aModif.size() > 0) {
1156 foreach (ModuleBase_Pref aPref, aModif) {
1157 aSection = aPref.first;
1158 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
1159 myMainWindow->viewer()->updateFromResources();
1160 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
1161 myMainWindow->menuObject()->updateFromResources();
1164 std::vector<int> aColor;
1166 aColor = Config_PropManager::color("Visualization", "selection_color");
1170 if (aColor.size() == 3)
1171 displayer()->setSelectionColor(aColor);
1173 displayer()->redisplayObjects();
1178 //******************************************************
1179 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
1181 XGUI_Displayer* aDisplayer = displayer();
1183 aDisplayer->displayTrihedron(theState);
1184 aDisplayer->updateViewer();
1188 //******************************************************
1189 bool XGUI_Workshop::onSave()
1191 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1193 if (myCurrentFile.isEmpty()) {
1196 SessionPtr aMgr = ModelAPI_Session::get();
1197 if (aMgr->isAutoUpdateBlocked())
1198 aMgr->blockAutoUpdate(false);
1200 std::list<std::string> aFiles;
1201 // issue #2899: create a temporary directory, save and then remove it
1203 std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("SALOME_TMP_DIR");
1205 std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("");
1207 saveDocument(QString(aTmpDir.c_str()), aFiles);
1208 bool aResult = XGUI_CompressFiles::compress(myCurrentFile, aFiles);
1209 XGUI_Tools::removeTemporaryFiles(aTmpDir, aFiles);
1212 updateCommandStatus();
1214 myMainWindow->setModifiedState(false);
1220 //******************************************************
1221 bool XGUI_Workshop::onSaveAs()
1223 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1225 qreal aRatio = ModuleBase_Tools::currentPixelRatio();
1226 myCurrentFile = QFileDialog::getSaveFileName(desktop(), tr("Select name to save file..."),
1227 QString(), MyFilter2,
1228 Q_NULLPTR, ((aRatio > 1) ? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
1229 if (!myCurrentFile.isNull()) {
1230 if (!myCurrentFile.endsWith(MyExtension)) {
1231 myCurrentFile += MyExtension;
1237 myMainWindow->setCurrentDir(myCurrentFile, false);
1238 myMainWindow->setModifiedState(false);
1243 //******************************************************
1244 void XGUI_Workshop::onUndo(int theTimes)
1246 processUndoRedo(ActionUndo, theTimes);
1247 myObjectBrowser->updateAllIndexes(1);
1250 //******************************************************
1251 void XGUI_Workshop::onRedo(int theTimes)
1253 processUndoRedo(ActionRedo, theTimes);
1254 myObjectBrowser->updateAllIndexes(1);
1257 //******************************************************
1258 void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes)
1260 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1261 if (anActiveWidget) {
1262 ActionIntParamPtr aParam(new ModuleBase_ActionIntParameter(theTimes));
1263 if (anActiveWidget->processAction(theActionType, aParam))
1268 XGUI_FacesPanel * anFacePannel = facesPanel();
1269 if(ActionUndo == theActionType && anFacePannel->isActivePanel())
1271 anFacePannel->processUndo();
1275 // the viewer update should be blocked in order to avoid the features blinking. For the created
1276 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1277 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1278 // until redo of all possible objects happens
1279 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1281 int aTimes = theTimes;
1282 SessionPtr aMgr = ModelAPI_Session::get();
1283 if (aMgr->isOperation()) {
1284 XGUI_OperationMgr* aOpMgr = operationMgr();
1285 /// this is important for nested operations
1286 /// when sketch operation is active, this condition is false and
1287 /// the sketch operation is not aborted
1288 if (aOpMgr->canStopOperation(aOpMgr->currentOperation())) {
1289 aOpMgr->abortOperation(aOpMgr->currentOperation());
1294 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1298 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1299 std::list<std::string> anActionList = theActionType == ActionUndo ? aMgr->undoList()
1301 std::list<std::string>::const_iterator aIt = anActionList.cbegin();
1302 for (int i = 0; (i < aTimes) && (aIt != anActionList.cend()); ++i, ++aIt) {
1303 if (theActionType == ActionUndo)
1308 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND ||
1309 QString((*aIt).c_str()) == MOVE_TO_END_SPLIT_COMMAND)
1310 myObjectBrowser->rebuildDataTree();
1312 operationMgr()->updateApplyOfOperations();
1313 facesPanel()->reset(true);
1314 updateCommandStatus();
1316 // unblock the viewer update functionality and make update on purpose
1317 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1318 myDisplayer->updateViewer();
1319 // Clear messages in status bar from previous operations if exists
1320 setStatusBarMessage("");
1323 //******************************************************
1324 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1326 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1327 //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1328 //if (anOperation) {
1329 // ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1331 // anActiveWidget = aPanel->activeWidget();
1334 operationMgr()->onValidateOperation();
1336 myModule->widgetStateChanged(thePreviousState);
1339 //******************************************************
1340 void XGUI_Workshop::onValuesChanged()
1342 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1343 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1346 ModuleBase_ModelWidget* anActiveWidget = 0;
1347 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1349 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1351 anActiveWidget = aPanel->activeWidget();
1353 if (anActiveWidget) {
1354 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1356 if (aWidgetValidated)
1357 aWidgetValidated->clearValidatedCash();
1361 //******************************************************
1362 void XGUI_Workshop::onWidgetObjectUpdated()
1364 operationMgr()->onValidateOperation();
1365 myDisplayer->updateViewer();
1368 //******************************************************
1369 void XGUI_Workshop::onImportPart()
1371 if (abortAllOperations()) {
1372 ModuleBase_OperationFeature* anImportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
1373 module()->createOperation(ExchangePlugin_ImportPart::ID()));
1374 anImportPartOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
1375 "importFeature.html");
1376 myPropertyPanel->updateApplyPlusButton(anImportPartOp->feature());
1377 operationMgr()->startOperation(anImportPartOp);
1381 //******************************************************
1382 void XGUI_Workshop::onImportShape()
1384 if (abortAllOperations()) {
1385 ModuleBase_OperationFeature* anImportOp = dynamic_cast<ModuleBase_OperationFeature*>(
1386 module()->createOperation(ExchangePlugin_Import::ID()));
1387 anImportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
1388 "importFeature.html");
1389 myPropertyPanel->updateApplyPlusButton(anImportOp->feature());
1390 operationMgr()->startOperation(anImportOp);
1394 //******************************************************
1395 void XGUI_Workshop::onImportImage()
1397 if (abortAllOperations()) {
1398 ModuleBase_OperationFeature* anImportOp = dynamic_cast<ModuleBase_OperationFeature*>(
1399 module()->createOperation(ExchangePlugin_Import_Image::ID()));
1400 anImportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
1401 "importFeature.html");
1402 myPropertyPanel->updateApplyPlusButton(anImportOp->feature());
1403 operationMgr()->startOperation(anImportOp);
1407 //******************************************************
1408 void XGUI_Workshop::onExportShape()
1410 if (abortAllOperations()) {
1411 ModuleBase_OperationFeature* anExportOp = dynamic_cast<ModuleBase_OperationFeature*>(
1412 module()->createOperation(ExchangePlugin_ExportFeature::ID()));
1413 anExportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
1414 "exportFeature.html");
1415 myPropertyPanel->updateApplyPlusButton(anExportOp->feature());
1416 operationMgr()->startOperation(anExportOp);
1420 //******************************************************
1421 void XGUI_Workshop::onExportPart()
1423 if (abortAllOperations()) {
1424 ModuleBase_OperationFeature* anExportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
1425 module()->createOperation(ExchangePlugin_ExportPart::ID()));
1426 anExportPartOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
1427 "exportFeature.html");
1428 myPropertyPanel->updateApplyPlusButton(anExportPartOp->feature());
1429 operationMgr()->startOperation(anExportPartOp);
1433 //******************************************************
1434 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1436 QString libName = QString::fromStdString(library(theModule.toStdString()));
1437 if (libName.isEmpty()) {
1438 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1443 CREATE_FUNC crtInst = 0;
1446 HINSTANCE modLib = ::LoadLibraryA(qPrintable(libName));
1450 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1451 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1452 QString aMsg((char*) &lpMsgBuf);
1453 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1454 ::LocalFree(lpMsgBuf);
1456 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1460 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1461 | FORMAT_MESSAGE_IGNORE_INSERTS,
1462 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1463 QString aMsg((char*) &lpMsgBuf);
1464 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1465 ::LocalFree(lpMsgBuf);
1469 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1471 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1473 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1475 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1480 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1482 if (!err.isEmpty()) {
1484 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1486 qWarning(qPrintable(err));
1492 //******************************************************
1493 bool XGUI_Workshop::createModule()
1495 Config_ModuleReader aModuleReader;
1496 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1497 myModule = loadModule(moduleName);
1501 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1502 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1503 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1504 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1506 myModule->createFeatures();
1508 salomeConnector()->createFeatureActions();
1510 //myActionsMgr->update();
1514 //******************************************************
1515 void XGUI_Workshop::updateCommandStatus()
1517 QList<QAction*> aCommands;
1519 aCommands = salomeConnector()->commandList();
1521 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1522 foreach (AppElements_Command* aCmd, aMenuBar->features())
1523 aCommands.append(aCmd);
1525 SessionPtr aMgr = ModelAPI_Session::get();
1526 if (aMgr->hasModuleDocument()) {
1527 foreach(QAction* aCmd, aCommands) {
1528 QString aId = aCmd->data().toString();
1529 if (aId == "UNDO_CMD") {
1530 bool isActionEnabled = false;
1531 // if ultimate is true -> using result of operation only, or using OR combination
1532 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1533 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled))
1534 aCmd->setEnabled(isActionEnabled);
1536 aCmd->setEnabled(myModule->canUndo());
1538 else if (aId == "REDO_CMD") {
1539 bool isActionEnabled = false;
1540 // if ultimate is true -> using result of operation only, or using OR combination
1541 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1542 if (anActiveWidget && anActiveWidget->canProcessAction(ActionRedo, isActionEnabled))
1543 aCmd->setEnabled(isActionEnabled);
1545 aCmd->setEnabled(myModule->canRedo());
1547 else if (aId == "AUTOCOMPUTE_CMD") {
1548 aCmd->setIcon(aMgr->isAutoUpdateBlocked() ?
1549 QIcon(":pictures/autoapply_stop.png") :
1550 QIcon(":pictures/autoapply_start.png"));
1553 // Enable all commands
1554 aCmd->setEnabled(true);
1558 foreach(QAction* aCmd, aCommands) {
1559 QString aId = aCmd->data().toString();
1560 if (aId == "NEW_CMD")
1561 aCmd->setEnabled(true);
1562 else if (aId == "EXIT_CMD")
1563 aCmd->setEnabled(true);
1565 aCmd->setEnabled(false);
1568 myActionsMgr->updateCommandsStatus();
1569 emit commandStatusUpdated();
1572 //******************************************************
1573 void XGUI_Workshop::updateHistory()
1575 bool isActionEnabled = false;
1576 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1577 QList<ActionInfo> aUndoRes;
1578 QList<ActionInfo> aRedoRes;
1579 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled)) {
1580 aUndoRes = anActiveWidget->actionsList(ActionUndo);
1581 aRedoRes = anActiveWidget->actionsList(ActionRedo);
1583 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1584 aUndoRes = processHistoryList(aUndoList);
1586 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1587 aRedoRes = processHistoryList(aRedoList);
1589 emit updateUndoHistory(aUndoRes);
1590 emit updateRedoHistory(aRedoRes);
1593 //******************************************************
1594 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1596 QDockWidget* aObjDock = new QDockWidget(theParent);
1597 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1598 Qt::RightDockWidgetArea);
1599 aObjDock->setWindowTitle(tr("Object browser"));
1600 aObjDock->setStyleSheet(
1601 "::title { position: relative; padding-left: 5px; text-align: left center }");
1602 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock, this);
1603 myObjectBrowser->initialize(myModule->rootNode());
1604 myModule->customizeObjectBrowser(myObjectBrowser);
1605 aObjDock->setWidget(myObjectBrowser);
1606 aObjDock->setObjectName("Object browser");
1608 connect(myObjectBrowser, SIGNAL(sizeChanged()), SLOT(onDockSizeChanged()));
1610 myContextMenuMgr->connectObjectBrowser();
1614 //******************************************************
1616 * Creates dock widgets, places them in corresponding area
1617 * and tabifies if necessary.
1619 void XGUI_Workshop::createDockWidgets()
1621 QMainWindow* aDesktop = desktop();
1622 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1623 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1624 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1625 myActiveControlMgr->addSelector(new XGUI_PropertyPanelSelector(myPropertyPanel));
1627 myPropertyPanel->setupActions(myActionsMgr);
1628 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1629 Qt::RightDockWidgetArea);
1630 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1632 hidePanel(myPropertyPanel); ///<! Invisible by default
1634 myFacesPanel = new XGUI_FacesPanel(aDesktop, this);
1635 myActiveControlMgr->addSelector(new XGUI_FacesPanelSelector(myFacesPanel));
1636 myFacesPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1637 Qt::RightDockWidgetArea |
1638 Qt::BottomDockWidgetArea);
1639 connect(myFacesPanel, SIGNAL(closed()), myFacesPanel, SLOT(onClosed()));
1641 myInspectionPanel = new XGUI_InspectionPanel(aDesktop, this);
1642 myInspectionPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1643 Qt::RightDockWidgetArea);
1644 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myInspectionPanel);
1646 myInspectionPanel->hide();
1648 aDesktop->addDockWidget(
1650 Qt::RightDockWidgetArea,
1652 Qt::LeftDockWidgetArea,
1655 hidePanel(myFacesPanel); ///<! Invisible by default
1658 bool aShowOnTheRight = Config_PropManager::boolean("Plugins", "show_hide_faces");
1659 if (aShowOnTheRight) {
1660 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myFacesPanel);
1661 showPanel(myFacesPanel);
1664 hideObjectBrowser();
1668 if (!aShowOnTheRight)
1671 aDesktop->tabifyDockWidget(myFacesPanel, aObjDock);
1676 #endif // HAVE_SALOME
1678 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1679 myPropertyPanel->installEventFilter(myOperationMgr);
1681 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1682 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1684 QAction* aOkContAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptPlus);
1685 connect(aOkContAct, SIGNAL(triggered()), this, SLOT(onAcceptPlusActionClicked()));
1687 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1688 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1690 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1691 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1693 QAction* aHelpAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Help);
1694 connect(aHelpAct, SIGNAL(triggered()), this, SLOT(onHelpActionClicked()));
1696 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1697 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1698 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1699 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1702 //******************************************************
1703 void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
1705 if (theDockWidget == myPropertyPanel) {
1706 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1707 ///<! Restore ability to close panel from the window's menu
1708 aViewAct->setEnabled(true);
1710 theDockWidget->show();
1711 theDockWidget->raise();
1713 // The next code is necessary to made the property panel the active window
1714 // in order to operation manager could process key events of the panel.
1715 // otherwise they are ignored. It happens only if the same(activateWindow) is
1716 // not happened by property panel activation(e.g. resume operation of Sketch)
1717 //ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
1720 //******************************************************
1721 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
1723 if (theDockWidget && theDockWidget == myPropertyPanel) {
1724 QAction* aViewAct = theDockWidget->toggleViewAction();
1725 ///<! Do not allow to show empty property panel
1726 aViewAct->setEnabled(false);
1728 theDockWidget->hide();
1730 // the property panel is active window of the desktop, when it is
1731 // hidden, it is undefined which window becomes active. By this reason
1732 // it is defined to perform the desktop as the active window.
1733 // in SALOME mode, work-stack made the PyConsole the active window,
1734 // set the focus on it. As a result, shortcuts of the application, like
1735 // are processed by this console. For example Undo actions.
1736 // It is possible that this code is to be moved to SHAPER package
1737 QMainWindow* aDesktop = desktop();
1738 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::hidePanel()");
1741 //******************************************************
1742 void XGUI_Workshop::showObjectBrowser()
1744 if (!isSalomeMode()) {
1745 myObjectBrowser->parentWidget()->show();
1749 //******************************************************
1750 void XGUI_Workshop::hideObjectBrowser()
1752 if (!isSalomeMode())
1753 myObjectBrowser->parentWidget()->hide();
1756 //******************************************************
1757 void XGUI_Workshop::salomeViewerSelectionChanged()
1759 emit salomeViewerSelection();
1762 //**************************************************************
1763 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1765 return mySalomeConnector->viewer();
1768 //**************************************************************
1769 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1771 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1772 if (theId == "DELETE_CMD")
1774 else if (theId == "CLEAN_HISTORY_CMD")
1776 else if (theId == "MOVE_CMD" || theId == "MOVE_SPLIT_CMD")
1777 moveObjects(theId == "MOVE_SPLIT_CMD");
1778 else if (theId == "RECOVER_CMD")
1780 else if (theId == "COLOR_CMD")
1781 changeColor(anObjects);
1782 else if (theId == "AUTOCOLOR_CMD")
1783 changeAutoColor(anObjects);
1784 else if (theId == "ISOLINES_CMD")
1785 changeIsoLines(anObjects);
1786 else if (theId == "SHOW_ISOLINES_CMD") {
1787 foreach(ObjectPtr aObj, anObjects) {
1788 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1790 ModelAPI_Tools::showIsoLines(aResult, !ModelAPI_Tools::isShownIsoLines(aResult));
1792 mySelector->clearSelection();
1793 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1795 else if (theId == "DEFLECTION_CMD")
1796 changeDeflection(anObjects);
1797 else if (theId == "TRANSPARENCY_CMD")
1798 changeTransparency(anObjects);
1799 else if (theId == "SHOW_CMD") {
1800 showObjects(anObjects, true);
1801 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1802 updateCommandStatus();
1804 else if (theId == "HIDE_CMD") {
1805 showObjects(anObjects, false);
1806 updateCommandStatus();
1808 else if (theId == "SHOW_ONLY_CMD") {
1809 showOnlyObjects(anObjects);
1810 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1811 updateCommandStatus();
1813 else if (theId == "SHADING_CMD")
1814 setDisplayMode(anObjects, XGUI_Displayer::Shading);
1815 else if (theId == "WIREFRAME_CMD")
1816 setDisplayMode(anObjects, XGUI_Displayer::Wireframe);
1817 else if (theId == "HIDEALL_CMD") {
1818 QObjectPtrList aList = myDisplayer->displayedObjects();
1819 foreach (ObjectPtr aObj, aList) {
1820 if (module()->canEraseObject(aObj))
1821 aObj->setDisplayed(false);
1823 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1825 //issue #2159 Hide all incomplete behavior
1826 viewer()->eraseAll();
1828 updateCommandStatus();
1829 // Necessary for update icons in ObjectBrowser on Linux
1830 myObjectBrowser->updateAllIndexes();
1831 } else if (theId == "SELECT_VERTEX_CMD") {
1832 setViewerSelectionMode(TopAbs_VERTEX);
1833 } else if (theId == "SELECT_EDGE_CMD") {
1834 setViewerSelectionMode(TopAbs_EDGE);
1835 } else if (theId == "SELECT_FACE_CMD") {
1836 setViewerSelectionMode(TopAbs_FACE);
1837 } else if (theId == "INSERT_FOLDER_CMD") {
1838 insertFeatureFolder();
1839 } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
1840 insertToFolder(true);
1841 } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
1842 insertToFolder(false);
1843 } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
1844 moveOutFolder(true);
1845 } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
1846 moveOutFolder(false);
1847 } else if (theId == "SELECT_RESULT_CMD") {
1848 //setViewerSelectionMode(-1);
1849 //IMP: an attempt to use result selection with other selection modes
1850 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1851 setViewerSelectionMode(TopAbs_COMPSOLID);
1852 } else if (theId == "SHOW_RESULTS_CMD") {
1853 highlightResults(anObjects);
1854 } else if (theId == "SHOW_FEATURE_CMD") {
1855 highlightFeature(anObjects);
1856 } else if (theId == "SET_VIEW_NORMAL_CMD") {
1858 } else if (theId == "SET_VIEW_INVERTEDNORMAL_CMD") {
1859 setNormalView(true);
1862 else if (theId == "TINSPECTOR_VIEW") {
1863 Handle(TDocStd_Application) anApplication = ModelAPI_Session::get()->application();
1864 if (!anApplication.IsNull())
1866 if (!MyTCommunicator)
1868 MyTCommunicator = new TInspector_Communicator();
1870 NCollection_List<Handle(Standard_Transient)> aParameters;
1871 aParameters.Append(anApplication);
1872 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1873 if (!aContext.IsNull())
1874 aParameters.Append(aContext);
1876 #ifdef DEBUG_WITH_MESSAGE_REPORT
1877 Handle(Message_Report) aContextReport = aContext->GetReport();
1878 aContext->SetReportActive (Standard_True);
1879 aContextReport->SetLimit (1000);
1880 if (!aContextReport.IsNull())
1881 aParameters.Append(aContextReport);
1883 MyVCallBack = new VInspector_CallBack();
1884 myDisplayer->setCallBack(MyVCallBack);
1886 AppElements_Viewer* aViewer = mainWindow()->viewer();
1888 aViewer->setCallBack(MyVCallBack);
1890 aParameters.Append(MyVCallBack);
1892 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1893 MyTCommunicator->RegisterPlugin("TKShapeView");
1894 MyTCommunicator->RegisterPlugin("TKVInspector");
1895 #ifdef DEBUG_WITH_MESSAGE_REPORT
1896 MyTCommunicator->RegisterPlugin("TKMessageView");
1898 //MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1899 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1901 MyTCommunicator->Init(aParameters);
1902 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1903 #ifndef DEBUG_WITH_MESSAGE_REPORT
1904 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1906 MyTCommunicator->Activate("TKDFBrowser");
1908 #ifdef DEBUG_WITH_MESSAGE_REPORT
1909 MyTCommunicator->Activate("TKMessageView"); // temporary
1910 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1913 MyTCommunicator->SetVisible(true);
1919 //**************************************************************
1920 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1923 myViewerSelMode.clear();
1925 if (myViewerSelMode.contains(theMode))
1926 myViewerSelMode.removeAll(theMode);
1928 myViewerSelMode.append(theMode);
1930 selectionActivate()->updateSelectionModes();
1933 //**************************************************************
1934 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1937 module()->activeSelectionModes(aModes);
1938 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1939 aModes.append(myViewerSelMode);
1940 selectionActivate()->activateObjects(aModes, theList);
1943 //**************************************************************
1944 bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) const
1946 if (facesPanel()->isEmpty())
1949 // generate container of objects taking into account sub elments of compsolid
1950 std::set<ObjectPtr> anAllProcessedObjects;
1951 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1952 anObjectsIt != theObjects.end(); anObjectsIt++) {
1953 ObjectPtr anObject = *anObjectsIt;
1954 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
1955 if (aCompRes.get()) {
1956 std::list<ResultPtr> allRes;
1957 ModelAPI_Tools::allSubs(aCompRes, allRes);
1958 if (allRes.empty()) {
1959 anAllProcessedObjects.insert(anObject);
1961 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
1962 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
1963 if (aBody.get() && aBody->numberOfSubs() == 0)
1964 anAllProcessedObjects.insert(aBody);
1968 anAllProcessedObjects.insert(anObject);
1971 // find hidden objects in faces panel
1972 std::set<ObjectPtr> aHiddenObjects;
1973 QStringList aHiddenObjectNames;
1974 for (std::set<ObjectPtr>::const_iterator anObjectsIt = anAllProcessedObjects.begin();
1975 anObjectsIt != anAllProcessedObjects.end(); anObjectsIt++) {
1976 if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
1978 aHiddenObjects.insert(*anObjectsIt);
1979 aHiddenObjectNames.append(QString::fromStdWString((*anObjectsIt)->data()->name()));
1981 if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face
1984 int anAnswer = QMessageBox::question(
1985 desktop(), tr("Show object"),
1986 tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?")
1987 .arg(aHiddenObjectNames.join(", ")).arg(facesPanel()->windowTitle()),
1988 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1990 bool aToBeDisplayed = anAnswer == QMessageBox::Yes;
1992 facesPanel()->restoreObjects(aHiddenObjects);
1994 return aToBeDisplayed;
1997 //**************************************************************
1998 void XGUI_Workshop::deleteObjects()
2000 ModuleBase_IModule* aModule = module();
2001 // allow the module to delete objects, do nothing if it has succeed
2002 if (aModule->deleteObjects()) {
2003 updateCommandStatus();
2004 myDisplayer->updateViewer();
2008 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2009 if (anObjects.isEmpty())
2012 if (!abortAllOperations())
2015 bool hasResult = false;
2016 bool hasFeature = false;
2017 bool hasParameter = false;
2018 bool hasCompositeOwner = false;
2019 bool hasResultInHistory = false;
2020 bool hasFolder = false;
2021 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
2022 hasResultInHistory, hasFolder);
2023 if (!(hasResult || hasFeature || hasParameter || hasFolder))
2026 // Remove from the list non-deletable objects: infinite constructions which are not in history
2027 bool notDelete = true;
2028 QObjectPtrList::iterator aIt;
2029 for (aIt = anObjects.begin(); aIt != anObjects.end(); aIt++) {
2030 ObjectPtr aObj = (*aIt);
2031 ResultConstructionPtr aConstr = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
2032 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
2034 notDelete = (!aFeature->isInHistory()) && (aConstr && aConstr->isInfinite());
2036 anObjects.removeAll(aObj);
2042 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
2043 std::set<FeaturePtr> aFeatures;
2044 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
2045 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
2047 std::set<FolderPtr> aFolders;
2048 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
2051 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
2052 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
2053 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, module());
2055 operationMgr()->startOperation(anOpAction);
2057 std::set<FeaturePtr> aFeatureRefsToDelete;
2058 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
2059 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
2060 // It is necessary to clear selection in order to avoid selection changed event during
2061 // deletion and negative consequences connected with processing of already deleted items
2062 mySelector->clearSelection();
2064 if (!aFeatureRefsToDelete.empty())
2065 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
2066 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
2068 if (aFolders.size() > 0) {
2069 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
2070 aLast = aFolders.end();
2071 for (; anIt != aLast; anIt++) {
2072 FolderPtr aFolder = *anIt;
2073 if (aFolder.get()) {
2074 DocumentPtr aDoc = aFolder->document();
2075 aDoc->removeFolder(aFolder);
2079 // remove results selected
2080 std::list<ResultPtr> aResults;
2081 for(QObjectPtrList::const_iterator anIt = anObjects.begin(); anIt != anObjects.end(); anIt++) {
2082 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*anIt);
2083 if (aRes.get() && aRes->data()->isValid() && !aRes->data()->isDeleted() &&
2084 aRes->groupName() != ModelAPI_ResultGroup::group() && // don't remove groups and fields
2085 aRes->groupName() != ModelAPI_ResultField::group()) // because they are badly selected
2086 aResults.push_back(aRes);
2088 if (!aResults.empty()) {
2089 ModelAPI_Tools::removeResults(aResults);
2093 operationMgr()->commitOperation();
2095 operationMgr()->abortOperation(operationMgr()->currentOperation());
2097 myDisplayer->updateViewer();
2100 //**************************************************************
2101 void addRefsToFeature(const FeaturePtr& theFeature,
2102 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
2103 std::set<FeaturePtr>& theReferences)
2105 //if (theReferences.find(theFeature) != theReferences.end())
2107 if (theMainList.find(theFeature) == theMainList.end())
2108 return; // this feature is not in the selection list, so exists without references to it
2109 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
2111 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
2112 aLast = aMainReferences.end();
2113 for (; anIt != aLast; anIt++) {
2114 FeaturePtr aRefFeature = *anIt;
2115 if (theReferences.find(aRefFeature) == theReferences.end())
2116 theReferences.insert(aRefFeature);
2117 addRefsToFeature(aRefFeature, theMainList, theReferences);
2121 //**************************************************************
2122 void XGUI_Workshop::cleanHistory()
2124 if (!abortAllOperations())
2127 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2128 std::set<FeaturePtr> aFeatures;
2129 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
2131 #ifdef DEBUG_CLEAN_HISTORY
2133 std::set<FeaturePtr>::const_iterator aFIt;
2134 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
2135 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
2136 anInfo.append(aFeature->name().c_str());
2138 QString anInfoStr = anInfo.join(";\t");
2139 qDebug(QString("cleanHistory for: [%1] - %2").
2140 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
2143 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
2144 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
2145 // find for each object whether all reference values are in the map as key, that means that there
2146 // is no other reference in the model to this object, so it might be removed by cleaning history
2147 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - can't be deleted, dependency to bool_1
2148 // ext_1(bool_1, sk_3) - can't be deleted, dependency to bool_1
2150 // sk_2(ext_2) + (bool_1) - can't be deleted, dependency to bool_1
2151 // ext_2(bool_1) - can't be deleted, dependency to bool_1
2153 // Information: bool_1 is not selected
2154 std::set<FeaturePtr> anUnusedObjects;
2155 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
2156 aMainLast = aReferences.end();
2157 for (; aMainIt != aMainLast; aMainIt++) {
2158 FeaturePtr aMainListFeature = aMainIt->first;
2159 std::set<FeaturePtr> aMainRefList = aMainIt->second;
2160 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
2161 aRefLast = aMainRefList.end();
2162 bool aFeatureOutOfTheList = false;
2163 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
2164 FeaturePtr aRefFeature = *aRefIt;
2165 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
2167 if (!aFeatureOutOfTheList)
2168 anUnusedObjects.insert(aMainListFeature);
2171 #ifdef DEBUG_CLEAN_HISTORY
2173 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
2174 FeaturePtr aFeature = *aFIt;
2175 anInfo.append(aFeature->name().c_str());
2177 qDebug(QString("unused objects: [%1] - %2").
2178 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
2181 // warn about the references remove, break the delete operation if the user chose it
2182 if (!anUnusedObjects.empty()) {
2184 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
2185 aNames.append(QString::fromStdWString(aFeature->name()));
2188 QString anUnusedNames = aNames.join(", ");
2190 QString anActionId = "CLEAN_HISTORY_CMD";
2191 QString aDescription = ModuleBase_Tools::translate("workshop",
2192 contextMenuMgr()->action(anActionId)->text().toStdString());
2194 QMessageBox aMessageBox(desktop());
2195 aMessageBox.setWindowTitle(aDescription);
2196 aMessageBox.setIcon(QMessageBox::Warning);
2197 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
2198 aMessageBox.setDefaultButton(QMessageBox::No);
2200 const char* aKeyStr = "Unused features are the following: "
2201 "%1.\nThese features will be deleted.\nWould you like to continue?";
2202 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
2203 aMessageBox.setText(aText);
2204 if (aMessageBox.exec() == QMessageBox::No)
2207 // 1. start operation
2208 aDescription += "by deleting of " +
2209 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
2210 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, module());
2211 operationMgr()->startOperation(anOpAction);
2213 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
2214 // It is necessary to clear selection in order to avoid selection changed event during
2215 // deletion and negative consequences connected with processing of already deleted items
2216 mySelector->clearSelection();
2218 std::set<FeaturePtr> anIgnoredFeatures;
2219 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
2220 operationMgr()->commitOperation();
2223 operationMgr()->abortOperation(operationMgr()->currentOperation());
2227 QString anActionId = "CLEAN_HISTORY_CMD";
2228 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2230 QMessageBox aMessageBox(desktop());
2231 aMessageBox.setWindowTitle(aDescription);
2232 aMessageBox.setIcon(QMessageBox::Warning);
2233 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
2234 aMessageBox.setDefaultButton(QMessageBox::No);
2237 aMessageBox.setStandardButtons(QMessageBox::Ok);
2238 aMessageBox.setDefaultButton(QMessageBox::Ok);
2240 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
2241 aMessageBox.setText(aText);
2243 if (aMessageBox.exec() == QMessageBox::No)
2248 //**************************************************************
2249 bool compareFeature(const FeaturePtr& theF1, const FeaturePtr& theF2) {
2250 DocumentPtr aDoc = theF1->document();
2251 return aDoc->index(theF1) < aDoc->index(theF2);
2253 void XGUI_Workshop::moveObjects(const bool theSplit)
2255 if (!abortAllOperations())
2258 SessionPtr aMgr = ModelAPI_Session::get();
2260 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2261 // It is necessary to clear selection in order to avoid selection changed event during
2262 // moving and negative consequences connected with processing of already moved items
2263 mySelector->clearSelection();
2264 // check whether the object can be moved. There should not be parts which are not loaded
2265 std::set<FeaturePtr> aFeatures;
2266 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
2267 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
2270 QString anActionId = theSplit ? "MOVE_CMD" : "MOVE_SPLIT_CMD";
2271 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2272 aMgr->startOperation(aDescription.toStdString());
2274 // Sort features by index in document
2275 std::list<FeaturePtr> aFList(aFeatures.begin(), aFeatures.end());
2276 aFList.sort(compareFeature);
2278 DocumentPtr anActiveDocument = aMgr->activeDocument();
2279 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
2280 std::list<FeaturePtr>::const_iterator anIt = aFList.begin(), aLast = aFList.end();
2281 for (; anIt != aLast; anIt++) {
2282 FeaturePtr aFeature = *anIt;
2283 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
2286 anActiveDocument->moveFeature(aFeature, aCurrentFeature, theSplit);
2287 aCurrentFeature = anActiveDocument->currentFeature(true);
2289 aMgr->finishOperation();
2290 updateCommandStatus();
2291 myViewerProxy->update();
2294 void XGUI_Workshop::recoverFeature()
2296 if (!abortAllOperations())
2299 static const QString RECOVER_OP_NAME = "Recover";
2300 module()->launchOperation(RECOVER_OP_NAME, false);
2303 //**************************************************************
2304 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
2306 std::set<FeaturePtr> aFeatures;
2307 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
2309 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
2312 //******************************************************
2313 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
2315 bool isFoundResultType = false;
2316 foreach(ObjectPtr anObj, theObjects)
2318 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2319 if (aResult.get() == NULL)
2322 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
2323 if (isFoundResultType)
2326 return isFoundResultType;
2329 //**************************************************************
2330 // Returns the list of all features for theDocument and all features of
2331 // all nested parts.
2332 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
2334 std::list<FeaturePtr> aResultList;
2335 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
2336 foreach (const FeaturePtr& aFeature, anAllFeatures) {
2337 // The order of appending features of the part and the part itself is important
2339 // Append features from a part feature
2340 std::list<ResultPtr> aResults;
2341 ModelAPI_Tools::allResults(aFeature, aResults);
2342 foreach (const ResultPtr& aResult, aResults) {
2343 ResultPartPtr aResultPart =
2344 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
2345 if (aResultPart.get() && aResultPart->partDoc().get()) {
2347 std::list<FeaturePtr> aPartFeatures = allFeatures(aResultPart->partDoc());
2348 aResultList.insert(aResultList.end(), aPartFeatures.begin(), aPartFeatures.end());
2352 aResultList.push_back(aFeature);
2357 //**************************************************************
2358 // Returns the list of features placed between theObject and the current feature
2359 // in the same document. Excludes theObject, includes the current feature.
2360 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
2362 std::list<FeaturePtr> aResult;
2363 DocumentPtr aDocument = theObject->document();
2364 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
2365 // find the object iterator
2366 std::list<FeaturePtr>::iterator anObjectIt =
2367 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
2368 if (anObjectIt == anAllFeatures.end())
2370 // find the current feature iterator
2371 std::list<FeaturePtr>::iterator aCurrentIt =
2372 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
2373 if (aCurrentIt == anAllFeatures.end())
2375 // check the right order
2376 if (std::distance(anObjectIt, anAllFeatures.end()) <=
2377 std::distance(aCurrentIt, anAllFeatures.end()))
2379 // exclude the object
2380 std::advance(anObjectIt, 1);
2381 // include the current feature
2382 std::advance(aCurrentIt, 1);
2383 return std::list<FeaturePtr>(anObjectIt, aCurrentIt);
2386 //******************************************************
2387 bool XGUI_Workshop::canMoveFeature()
2389 QString anActionId = "MOVE_CMD";
2391 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2392 QObjectPtrList aValidatedObjects;
2393 foreach (ObjectPtr anObject, anObjects) {
2394 if (!myModule->canApplyAction(anObject, anActionId))
2396 // To be moved feature should be in active document
2397 if (anObject->document() != ModelAPI_Session::get()->activeDocument())
2399 aValidatedObjects.append(anObject);
2401 if (aValidatedObjects.size() != anObjects.size())
2402 anObjects = aValidatedObjects;
2404 bool aCanMove = !anObjects.empty();
2406 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
2407 for (; anIt != aLast && aCanMove; anIt++) {
2408 ObjectPtr anObject = *anIt;
2409 if (!anObject.get() || !anObject->data().get() || !anObject->data()->isValid()) {
2413 FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
2414 // only groups can be moved to the end for now (#2451)
2415 if (aFeat.get() && aFeat->getKind() != "Group") {
2420 // 1. Get features placed between selected and current in the document
2421 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(anObject);
2422 // if aFeaturesBetween is empty it means wrong order or anObject is the current feature
2423 if (aFeaturesBetween.empty())
2426 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2427 // 2. Get all reference features to the selected object in the document
2428 std::set<FeaturePtr> aRefFeatures;
2429 ModuleBase_Tools::refsToFeatureInFeatureDocument(anObject, aRefFeatures);
2431 if (aRefFeatures.empty())
2434 // 3. Find any placed features in all reference features
2435 std::set<FeaturePtr> aIntersectionFeatures;
2436 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2437 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2438 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2439 // 4. Return false if any reference feature is placed before current feature
2440 if (!aIntersectionFeatures.empty())
2448 //**************************************************************
2449 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2451 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2452 if (!aCanBeShaded) {
2453 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
2454 if (aCompRes.get() != NULL) { // change colors for all sub-solids
2455 std::list<ResultPtr> allRes;
2456 ModelAPI_Tools::allSubs(aCompRes, allRes);
2457 std::list<ResultPtr>::iterator aRes = allRes.begin();
2458 for(; aRes != allRes.end() && !aCanBeShaded; aRes++) {
2459 aCanBeShaded = myDisplayer->canBeShaded(*aRes);
2463 return aCanBeShaded;
2466 //**************************************************************
2467 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2469 if (theActionName == "COLOR_CMD" ||
2470 theActionName == "DEFLECTION_CMD" ||
2471 theActionName == "TRANSPARENCY_CMD") {
2472 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2474 std::set<std::string> aTypes;
2475 aTypes.insert(ModelAPI_ResultGroup::group());
2476 aTypes.insert(ModelAPI_ResultConstruction::group());
2477 aTypes.insert(ModelAPI_ResultBody::group());
2478 aTypes.insert(ModelAPI_ResultPart::group());
2480 return hasResults(anObjects, aTypes);
2482 if (theActionName == "AUTOCOLOR_CMD") {
2484 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2486 std::set<std::string> aTypes;
2487 aTypes.insert(ModelAPI_ResultGroup::group());
2489 return hasResults(anObjects, aTypes);
2495 //**************************************************************
2496 void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
2497 std::vector<int>& theColor)
2500 // get default color from the preferences manager for the given result
2501 if (theColor.empty()) {
2502 std::string aSection, aName, aDefault;
2503 theObject->colorConfigInfo(aSection, aName, aDefault);
2504 if (!aSection.empty() && !aName.empty()) {
2505 theColor = Config_PropManager::color(aSection, aName);
2508 if (!isEmptyColorValid && theColor.empty()) {
2509 // all AIS objects, where the color is not set, are in black.
2510 // The color should be defined in XML or set in the attribute
2511 theColor = Config_PropManager::color("Visualization", "object_default_color");
2512 Events_InfoMessage("XGUI_CustomPrs",
2513 "A default color is not defined in the preferences for this kind of result").send();
2517 //**************************************************************
2518 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2521 AttributeIntArrayPtr aColorAttr;
2522 // 1. find the current color of the object. This is a color of AIS presentation
2523 // The objects are iterated until a first valid color is found
2524 std::vector<int> aColor;
2525 foreach(ObjectPtr anObject, theObjects) {
2526 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2527 if (aResult.get()) {
2528 ModelAPI_Tools::getColor(aResult, aColor);
2529 if (aColor.empty()) {
2530 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2531 if (anAISObj.get()) {
2533 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2536 if (aColor.empty()) {
2537 getDefaultColor(aResult, false, aColor);
2541 if (aColor.size() != 3)
2544 if (!abortAllOperations())
2546 // 2. show the dialog to change the value
2547 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2548 aDlg->setColor(aColor);
2549 aDlg->move(QCursor::pos());
2550 bool isDone = aDlg->exec() == QDialog::Accepted;
2554 bool isRandomColor = aDlg->isRandomColor();
2556 // 3. abort the previous operation and start a new one
2557 SessionPtr aMgr = ModelAPI_Session::get();
2558 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2560 aMgr->startOperation(aDescription.toStdString());
2562 // 4. set the value to all results
2563 std::vector<int> aColorResult = aDlg->getColor();
2564 foreach(ObjectPtr anObj, theObjects) {
2565 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2566 if (aResult.get() != NULL) {
2567 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2568 if (aBodyResult.get() != NULL) { // change colors for all sub-solids
2569 std::list<ResultPtr> allRes;
2570 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2571 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2572 ModelAPI_Tools::setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2575 ModelAPI_Tools::setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2578 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2579 aMgr->finishOperation();
2580 updateCommandStatus();
2581 myViewerProxy->update();
2584 //**************************************************************
2585 void XGUI_Workshop::changeAutoColor(const QObjectPtrList& theObjects)
2587 if (!abortAllOperations())
2590 std::vector<int> aColor;
2592 // abort the previous operation and start a new one
2593 SessionPtr aMgr = ModelAPI_Session::get();
2594 QString aDescription = contextMenuMgr()->action("AUTOCOLOR_CMD")->text();
2595 aMgr->startOperation(aDescription.toStdString());
2597 if (Config_PropManager::getAutoColorStatus()) {
2598 contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Auto color"));
2599 Config_PropManager::setAutoColorStatus(false);
2600 ModelAPI_Tools::findRandomColor(aColor, true);
2602 // set the value to all results
2603 foreach (ObjectPtr anObj, theObjects) {
2604 DocumentPtr aDocument = anObj->document();
2605 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
2606 // find the object iterator
2607 std::list<FeaturePtr>::iterator anObjectIt = anAllFeatures.begin();
2608 for (; anObjectIt != anAllFeatures.end(); ++ anObjectIt) {
2609 FeaturePtr aFeature = *anObjectIt;
2610 if (aFeature.get()) {
2611 std::list<ResultPtr> aResults;
2612 ModelAPI_Tools::allResults(aFeature, aResults);
2613 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2614 for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2615 ResultPtr aGroupResult = *aIt;
2616 if (aGroupResult.get() &&
2617 aGroupResult->groupName() == ModelAPI_ResultGroup::group()) {
2618 ModelAPI_Tools::findRandomColor(aColor);
2619 ModelAPI_Tools::setColor(aGroupResult, aColor);
2625 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2626 aMgr->finishOperation();
2627 updateCommandStatus();
2628 myViewerProxy->update();
2629 contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Disable auto color"));
2630 Config_PropManager::setAutoColorStatus(true);
2634 //**************************************************************
2635 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2637 foreach(ObjectPtr anObj, theObjects) {
2638 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2639 if (aResult.get() != NULL) {
2640 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2641 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2642 std::list<ResultPtr> allRes;
2643 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2644 std::list<ResultPtr>::iterator aRes;
2645 for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2646 ModelAPI_Tools::setTransparency(*aRes, theTransparency);
2649 ModelAPI_Tools::setTransparency(aResult, theTransparency);
2654 //**************************************************************
2655 double getDefaultDeflection(const ObjectPtr& theObject)
2657 double aDeflection = -1;
2658 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
2659 if (aResult.get()) {
2660 bool isConstruction = false;
2662 std::string aResultGroup = aResult->groupName();
2663 if (aResultGroup == ModelAPI_ResultConstruction::group())
2664 isConstruction = true;
2665 else if (aResultGroup == ModelAPI_ResultBody::group()) {
2666 GeomShapePtr aGeomShape = aResult->shape();
2667 if (aGeomShape.get()) {
2668 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
2669 // correction of deviation for them should not influence to the application performance
2670 GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
2671 isConstruction = !anExp.more();
2675 aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
2677 aDeflection = Config_PropManager::real("Visualization", "body_deflection");
2682 //**************************************************************
2683 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2685 AttributeDoublePtr aDoubleAttr;
2686 // 1. find the current property of the object. This is a property of AIS presentation
2687 // The objects are iterated until a first valid property is found
2688 double aDeflection = -1;
2689 foreach(ObjectPtr anObject, theObjects) {
2690 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2691 if (aResult.get()) {
2692 aDeflection = ModelAPI_Tools::getDeflection(aResult);
2693 if (aDeflection < 0)
2694 aDeflection = getDefaultDeflection(aResult);
2697 // TODO: remove the obtaining a property from the AIS object
2698 // this does not happen never because:
2699 // 1. The property can be changed only on results
2700 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2701 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2702 if (anAISObj.get()) {
2703 aDeflection = anAISObj->getDeflection();
2706 if (aDeflection > 0)
2709 if (aDeflection < 0)
2712 if (!abortAllOperations())
2714 // 2. show the dialog to change the value
2715 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2716 aDlg->setDeflection(aDeflection);
2717 aDlg->move(QCursor::pos());
2718 bool isDone = aDlg->exec() == QDialog::Accepted;
2722 // 3. abort the previous operation and start a new one
2723 SessionPtr aMgr = ModelAPI_Session::get();
2724 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2725 aMgr->startOperation(aDescription.toStdString());
2727 // 4. set the value to all results
2728 aDeflection = aDlg->getDeflection();
2729 foreach(ObjectPtr anObj, theObjects) {
2730 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2731 if (aResult.get() != NULL) {
2732 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2733 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2734 std::list<ResultPtr> allRes;
2735 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2736 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2737 ModelAPI_Tools::setDeflection(*aRes, aDeflection);
2740 ModelAPI_Tools::setDeflection(aResult, aDeflection);
2743 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2744 aMgr->finishOperation();
2745 updateCommandStatus();
2748 //**************************************************************
2749 double getDefaultTransparency(const ResultPtr& theResult)
2751 return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.;
2754 //**************************************************************
2755 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2757 AttributeDoublePtr aDoubleAttr;
2758 // 1. find the current property of the object. This is a property of AIS presentation
2759 // The objects are iterated until a first valid property is found
2760 double aCurrentValue = -1;
2761 foreach(ObjectPtr anObject, theObjects) {
2762 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2763 if (aResult.get()) {
2764 aCurrentValue = ModelAPI_Tools::getTransparency(aResult);
2765 if (aCurrentValue < 0)
2766 aCurrentValue = getDefaultTransparency(aResult);
2768 if (aCurrentValue > 0)
2771 if (aCurrentValue < 0)
2774 if (!abortAllOperations())
2777 // 2. show the dialog to change the value
2778 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2779 aDlg->setWindowTitle(tr("Transparency"));
2780 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2781 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2782 this, SLOT(onTransparencyValueChanged()));
2783 aDlg->setContent(aTransparencyWidget);
2784 aTransparencyWidget->setValue(aCurrentValue);
2786 // 3. abort the previous operation and start a new one
2787 SessionPtr aMgr = ModelAPI_Session::get();
2788 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2789 aMgr->startOperation(aDescription.toStdString());
2791 if (aDlg->exec() == QDialog::Accepted) {
2792 // 4. set the value to all results
2793 aCurrentValue = aTransparencyWidget->getValue();
2794 setTransparency(aCurrentValue, theObjects);
2795 aMgr->finishOperation();
2797 aMgr->abortOperation();
2798 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2801 updateCommandStatus();
2804 //**************************************************************
2805 void XGUI_Workshop::onTransparencyValueChanged()
2807 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2808 if (!aTransparencyWidget)
2811 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2812 setTransparency(aTransparencyWidget->getValue(), anObjects);
2813 static const Events_ID kRedisplayEvent =
2814 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2815 Events_Loop::loop()->flush(kRedisplayEvent);
2817 myViewerProxy->update();
2821 //******************************************************
2822 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2825 std::set<ObjectPtr> anObjects;
2826 foreach (ObjectPtr aObj, theList) {
2827 anObjects.insert(aObj);
2829 if (!prepareForDisplay(anObjects))
2833 foreach (ObjectPtr aObj, theList) {
2834 aObj->setDisplayed(isVisible);
2836 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2837 myObjectBrowser->updateAllIndexes();
2839 updateColorScaleVisibility();
2840 displayer()->updateViewer();
2843 //**************************************************************
2844 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2846 QObjectPtrList aSrcList = theList;
2847 // Hide all displayed objects
2848 QObjectPtrList aList = myDisplayer->displayedObjects();
2849 foreach (ObjectPtr aObj, aList) {
2850 if ((!aSrcList.contains(aObj)) && (module()->canEraseObject(aObj)))
2851 aObj->setDisplayed(false);
2853 aSrcList.removeAll(aObj);
2855 //Do not use eraseAll if you didn't send Redisplay event:
2856 //all objects are erased from viewer, but considered as displayed in displayer
2857 // Problem in bug 2218
2858 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2860 //issue #2159 Hide all incomplete behavior
2861 viewer()->eraseAll();
2864 std::set<ObjectPtr> anObjects;
2865 foreach (ObjectPtr aObj, aSrcList) {
2866 anObjects.insert(aObj);
2869 if (!prepareForDisplay(anObjects))
2872 // Show only objects from the list
2873 foreach (ObjectPtr aObj, aSrcList) {
2874 aObj->setDisplayed(true);
2876 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2878 // Necessary for update icons in ObjectBrowser on Linux
2879 myObjectBrowser->updateAllIndexes();
2880 updateColorScaleVisibility();
2881 displayer()->updateViewer();
2885 //**************************************************************
2886 void XGUI_Workshop::updateColorScaleVisibility()
2888 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2889 viewer()->setColorScaleShown(false);
2890 if (anObjects.size() == 1) {
2891 FieldStepPtr aStep =
2892 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(anObjects.first());
2893 if (aStep.get() && myDisplayer->isVisible(aStep)) {
2894 AISObjectPtr aAisPtr = myDisplayer->getAISObject(aStep);
2895 Handle(AIS_InteractiveObject) aIO = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2896 ModuleBase_IStepPrs* aPrs = dynamic_cast<ModuleBase_IStepPrs*>(aIO.get());
2898 ModelAPI_AttributeTables::ValueType aType = aPrs->dataType();
2899 if ((aType == ModelAPI_AttributeTables::DOUBLE) ||
2900 (aType == ModelAPI_AttributeTables::INTEGER) ||
2901 (aType == ModelAPI_AttributeTables::BOOLEAN)) {
2902 myViewerProxy->setupColorScale();
2903 if (aType == ModelAPI_AttributeTables::BOOLEAN) {
2904 myViewerProxy->setColorScaleIntervals(2);
2905 myViewerProxy->setColorScaleRange(0., 1.);
2909 aPrs->dataRange(aMin, aMax);
2910 myViewerProxy->setColorScaleRange(aMin, aMax);
2912 myViewerProxy->setColorScaleTitle(QString::fromStdWString(aStep->name()));
2913 myViewerProxy->setColorScaleShown(true);
2921 //**************************************************************
2922 void XGUI_Workshop::setNormalView(bool toInvert)
2924 QList<ModuleBase_ViewerPrsPtr> aPrsList =
2925 mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
2926 GeomShapePtr aPlanarFace;
2927 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
2928 GeomShapePtr aShape = aPrs->shape();
2929 if (aShape.get() && aShape->isFace() && aShape->isPlanar()) {
2930 aPlanarFace = aShape;
2934 if (aPlanarFace.get()) {
2935 GeomFacePtr aFace(new GeomAPI_Face(aPlanarFace));
2936 GeomPlanePtr aPlane = aFace->getPlane();
2937 GeomDirPtr aNormal = aPlane->direction();
2940 GeomPointPtr aPos = aPlane->location();
2942 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2943 aFace->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2945 Handle(V3d_View) aView = myViewerProxy->activeView();
2946 aView->SetAt(aPos->x(), aPos->y(), aPos->z());
2947 aView->SetProj(aNormal->x(), aNormal->y(), aNormal->z());
2949 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2950 aView->FitAll(aBox);
2954 //**************************************************************
2955 void XGUI_Workshop::registerValidators() const
2957 SessionPtr aMgr = ModelAPI_Session::get();
2958 MAYBE_UNUSED ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2961 //**************************************************************
2962 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2966 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2967 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2970 //**************************************************************
2971 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2973 for (int i = 0; i < theDoc->size(theGroup); i++)
2974 theDoc->object(theGroup, i)->setDisplayed(true);
2975 //displayObject(theDoc->object(theGroup, i));
2976 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2979 //**************************************************************
2980 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2982 foreach(ObjectPtr anObj, theList) {
2983 myDisplayer->setDisplayMode(anObj, (XGUI_Displayer::DisplayMode)theMode, false);
2985 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
2986 if (aBodyResult.get() != NULL) { // change display mode for all sub-solids
2987 std::list<ResultPtr> allRes;
2988 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2989 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2990 myDisplayer->setDisplayMode(*aRes, (XGUI_Displayer::DisplayMode)theMode, false);
2994 if (theList.size() > 0)
2995 myDisplayer->updateViewer();
2998 //**************************************************************
2999 void XGUI_Workshop::closeDocument()
3001 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
3002 while (anOperation) {
3003 anOperation->abort();
3004 anOperation = operationMgr()->currentOperation();
3006 //myDisplayer->closeLocalContexts();
3007 myDisplayer->eraseAll();
3008 objectBrowser()->clearContent();
3010 module()->closeDocument();
3011 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
3012 module()->clearViewer();
3015 // data model need not process the document's signals about objects modifications as
3016 // the document is closed
3017 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
3019 SessionPtr aMgr = ModelAPI_Session::get();
3022 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
3025 //******************************************************
3026 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
3028 XGUI_HistoryMenu* aMenu = NULL;
3029 if (isSalomeMode()) {
3030 QAction* anAction = qobject_cast<QAction*>(theObject);
3033 aMenu = new XGUI_HistoryMenu(anAction);
3035 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
3036 aMenu = new XGUI_HistoryMenu(aButton);
3038 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
3039 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
3042 //******************************************************
3043 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
3045 QList<ActionInfo> aResult;
3046 std::list<std::string>::const_iterator it = theList.cbegin();
3047 for (; it != theList.cend(); it++) {
3048 QString anId = QString::fromStdString(*it);
3049 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
3051 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
3054 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
3055 if (aContextMenuAct) {
3056 anInfo.initFrom(aContextMenuAct);
3058 anInfo = myActionsMgr->actionInfoById(anId);
3061 anInfo.text = anInfo.text.prepend("Modify ");
3068 //******************************************************
3069 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
3072 salomeConnector()->putInfo(theMessage, -1);
3074 myMainWindow->putInfo(theMessage, -1);
3079 //******************************************************
3080 void XGUI_Workshop::synchronizeViewer()
3082 SessionPtr aMgr = ModelAPI_Session::get();
3083 QList<DocumentPtr> aDocs;
3084 aDocs.append(aMgr->activeDocument());
3085 aDocs.append(aMgr->moduleDocument());
3087 foreach(DocumentPtr aDoc, aDocs) {
3088 synchronizeGroupInViewer(aDoc, false);
3092 //******************************************************
3093 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
3094 bool theUpdateViewer)
3096 FeaturePtr aFeature;
3098 int aSize = theDoc->numInternalFeatures();
3099 for (int i = 0; i < aSize; i++) {
3100 aFeature = theDoc->internalFeature(i);
3101 if (!aFeature.get())
3103 const std::list<ResultPtr>& aResults = aFeature->results();
3104 std::list<ResultPtr>::const_iterator aIt;
3105 aFeature->setDisplayed(false);
3106 for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
3108 if (aRes->isDisplayed() && !aRes->isConcealed()) {
3109 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
3110 // be changed to the object becomes visible when the shape becomes not empty
3111 if (!aRes->shape().get() || aRes->shape()->isNull())
3113 ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aRes);
3115 synchronizeResultTree(aResBody, false);
3117 if (aRes->isInHistory()) {
3118 if (aRes->isDisplayed())
3119 myDisplayer->display(aRes, false);
3121 myDisplayer->erase(aRes, false);
3124 aRes->setDisplayed(false);
3129 if (theUpdateViewer)
3130 myDisplayer->updateViewer();
3133 void XGUI_Workshop::synchronizeResultTree(const ResultBodyPtr& theRes, bool theUpdateViewer)
3135 if (theRes->numberOfSubs() > 0)
3136 for (int i = 0; i < theRes->numberOfSubs(); i++) {
3137 ResultBodyPtr aRes = theRes->subResult(i);
3139 synchronizeResultTree(aRes, theUpdateViewer);
3142 if (theRes->isDisplayed())
3143 myDisplayer->display(theRes, theUpdateViewer);
3145 myDisplayer->erase(theRes, theUpdateViewer);
3150 //******************************************************
3151 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
3153 FeaturePtr aFeature;
3154 QObjectPtrList aSelList = theObjects;
3155 QObjectPtrList aNewSel;
3156 bool aHasHidden = false;
3157 foreach(ObjectPtr aObj, theObjects) {
3158 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
3159 if (aFeature.get()) {
3160 std::list<ResultPtr> aResults;
3161 ModelAPI_Tools::allResults(aFeature, aResults);
3162 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
3163 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
3164 aHasHidden |= (*aIt)->isConcealed();
3165 aSelList.append(*aIt);
3166 aNewSel.append(*aIt);
3170 if (aSelList.count() > theObjects.count()) {
3171 // if something was found
3172 objectBrowser()->setObjectsSelected(aSelList);
3173 objectBrowser()->ensureVisible(aNewSel.first());
3176 QMessageBox::information(desktop(), tr("Find results"),
3177 tr("Results not found"), QMessageBox::Ok);
3180 //******************************************************
3181 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
3184 QObjectPtrList aSelList = theObjects;
3185 QObjectPtrList aNewSel;
3186 FeaturePtr aFeature;
3187 foreach(ObjectPtr aObj, theObjects) {
3188 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
3189 if (aResult.get()) {
3190 aFeature = ModelAPI_Feature::feature(aResult);
3191 if (aFeature.get()) {
3192 aSelList.append(aFeature);
3193 aNewSel.append(aFeature);
3197 if (aSelList.count() > theObjects.count()) {
3198 // if something was found
3199 objectBrowser()->setObjectsSelected(aSelList);
3200 objectBrowser()->ensureVisible(aNewSel.first());
3204 void XGUI_Workshop::insertFeatureFolder()
3206 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
3207 if (anObjects.isEmpty())
3209 ObjectPtr aObj = anObjects.first();
3210 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
3211 if (aFeature.get() == NULL)
3213 SessionPtr aMgr = ModelAPI_Session::get();
3214 DocumentPtr aDoc = aMgr->activeDocument();
3216 QString aDescription = contextMenuMgr()->action("INSERT_FOLDER_CMD")->text();
3218 aMgr->startOperation(aDescription.toStdString());
3219 aDoc->addFolder(aFeature);
3220 aMgr->finishOperation();
3222 updateCommandStatus();
3226 void XGUI_Workshop::insertToFolder(bool isBefore)
3228 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
3229 if (aFeatures.empty())
3232 SessionPtr aMgr = ModelAPI_Session::get();
3233 DocumentPtr aDoc = aMgr->activeDocument();
3235 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
3236 aDoc->findFolderBelow(aFeatures);
3240 QString aDescription = contextMenuMgr()->action(
3241 isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text();
3243 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
3245 aMgr->startOperation(aDescription.toStdString());
3246 aDoc->moveToFolder(aFeatures, aFolder);
3247 aMgr->finishOperation();
3249 myObjectBrowser->setFoldersState(aStates);
3251 updateCommandStatus();
3254 void XGUI_Workshop::moveOutFolder(bool isBefore)
3256 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
3257 if (aFeatures.empty())
3260 SessionPtr aMgr = ModelAPI_Session::get();
3261 DocumentPtr aDoc = aMgr->activeDocument();
3263 QString aDescription = contextMenuMgr()->action(
3264 isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text();
3266 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
3268 aMgr->startOperation(aDescription.toStdString());
3269 aDoc->removeFromFolder(aFeatures, isBefore);
3270 aMgr->finishOperation();
3272 myObjectBrowser->setFoldersState(aStates);
3274 updateCommandStatus();
3277 void XGUI_Workshop::onAutoApply()
3279 SessionPtr aMgr = ModelAPI_Session::get();
3280 bool isBlocked = aMgr->isAutoUpdateBlocked();
3281 aMgr->blockAutoUpdate(!isBlocked);
3282 myDisplayer->updateViewer();
3285 void XGUI_Workshop::updateAutoComputeState()
3287 SessionPtr aMgr = ModelAPI_Session::get();
3289 // QAction* aUpdateCmd;
3290 // QList<QAction*> aCommands = mySalomeConnector->commandList();
3291 // foreach(QAction* aCmd, aCommands) {
3292 // if (aCmd->data().toString() == "AUTOCOMPUTE_CMD") {
3293 // aUpdateCmd = aCmd;
3297 // aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
3298 // QIcon(":pictures/autoapply_start.png"));
3300 bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
3301 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
3302 AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD");
3303 aUpdateCmd->button()->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
3304 QIcon(":pictures/autoapply_start.png"));
3309 void XGUI_Workshop::clearTemporaryDir()
3311 QDir aDir(myTmpDir.path());
3312 if (!aDir.isEmpty()) {
3313 QStringList aEntries;
3314 aDir.entryList(aEntries);
3315 foreach(QString aFile, aEntries) {
3322 void XGUI_Workshop::onDockSizeChanged()
3324 QDockWidget* aDockWgt = dynamic_cast<QDockWidget*>(myObjectBrowser->parentWidget());
3325 int aObWidth = aDockWgt->size().width();
3326 if (myPropertyPanel->width() != aObWidth) {
3327 QList<QDockWidget*> aWgtList;
3328 aWgtList << myPropertyPanel << aDockWgt;
3329 QList<int> aSizeList;
3330 aSizeList << aObWidth << aObWidth;
3331 desktop()->resizeDocks(aWgtList, aSizeList, Qt::Horizontal);
3332 disconnect(myObjectBrowser, SIGNAL(sizeChanged()), this, SLOT(onDockSizeChanged()));
3336 void XGUI_Workshop::deactivateCurrentSelector()
3338 myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector());
3341 void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects)
3343 if (theObjects.isEmpty())
3346 QList<ResultPtr> aResultList;
3348 foreach(ObjectPtr aObj, theObjects) {
3349 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
3351 aResultList.append(aRes);
3354 std::vector<int> aValues;
3356 if (aResultList.size() == 1) {
3357 ResultPtr aResult = aResultList.first();
3359 ModelAPI_Tools::getIsoLines(aResult, isVisible, aValues);
3363 if (aValues.size() == 0) {
3364 aValues.push_back(1);
3365 aValues.push_back(1);
3368 if (!abortAllOperations())
3371 XGUI_PropertyDialog aDlg(desktop());
3372 aDlg.setWindowTitle(tr("Number of Iso-lines"));
3374 QWidget* aIsosWgt = new QWidget(&aDlg);
3375 QFormLayout* aLayout = new QFormLayout(aIsosWgt);
3376 ModuleBase_Tools::adjustMargins(aLayout);
3377 aDlg.setContent(aIsosWgt);
3379 QSpinBox* aUNb = new QSpinBox(&aDlg);
3380 aUNb->setValue(aValues[0]);
3381 aLayout->addRow("U:", aUNb);
3383 QSpinBox* aVNb = new QSpinBox(&aDlg);
3384 aVNb->setValue(aValues[1]);
3385 aLayout->addRow("V:", aVNb);
3387 if (aDlg.exec() == QDialog::Accepted) {
3388 SessionPtr aMgr = ModelAPI_Session::get();
3389 QString aDescription = contextMenuMgr()->action("ISOLINES_CMD")->text();
3390 aMgr->startOperation(aDescription.toStdString());
3392 aValues[0] = aUNb->value();
3393 aValues[1] = aVNb->value();
3394 foreach(ResultPtr aResult, aResultList) {
3395 ModelAPI_Tools::setIsoLines(aResult, aValues);
3397 mySelector->clearSelection();
3398 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
3399 aMgr->finishOperation();
3400 updateCommandStatus();