1 // Copyright (C) 2014-2021 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;
179 //#define DEBUG_WITH_MESSAGE_REPORT
181 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
182 QString XGUI_Workshop::MOVE_TO_END_SPLIT_COMMAND = QObject::tr("Move to the end and split");
184 //#define DEBUG_DELETE
185 //#define DEBUG_FEATURE_NAME
186 //#define DEBUG_CLEAN_HISTORY
189 static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.cadbld)"));
190 static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)"));
191 static QString MyExtension(".shaper");
193 static QString MyFilter(QObject::tr("CAD Builder files (*.cadbld);;All files (*.*)"));
194 static QString MyFilter2(QObject::tr("CAD Builder files (*.cadbld)"));
195 static QString MyExtension(".cadbld");
198 static QString MyImportPartFilter(QObject::tr("Part files (*.shaperpart);;All files (*.*)"));
201 //******************************************************
202 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
209 mySalomeConnector(theConnector),
210 //myViewerSelMode(TopAbs_FACE),
213 mySelector = new XGUI_SelectionMgr(this);
214 myModuleConnector = new XGUI_ModuleConnector(this);
215 myOperationMgr = new XGUI_OperationMgr(this, myModuleConnector);
216 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
217 // Has to be defined first in order to get errors and messages from other components
218 myEventsListener = new XGUI_WorkshopListener(this);
219 mySelectionActivate = new XGUI_SelectionActivate(aWorkshop);
221 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
223 myMainWindow = new AppElements_MainWindow();
225 bool aCloc = aResMgr->booleanValue("language", "locale", true);
227 QLocale::setDefault( QLocale::c() );
229 QLocale::setDefault( QLocale::system() );
231 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
236 aLangs << "*_en.ts"; // load by default eng translations
238 /// If version of OCCT is 7.4.0 or more then it means that
239 /// this is version of SALOME older then 9.4.0
240 #if OCC_VERSION_HEX >= 0x070400
241 QString aCurrLang = aResMgr->language();
243 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
246 if(aCurrLang != "en") {
247 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
250 foreach(QString aLang, aLangs) {
251 QStringList aFilters;
253 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
254 foreach(QString aFileName, aTsFiles) {
255 Config_Translator::load(aFileName.toStdString());
259 myDataModelXMLReader = new Config_DataModelReader();
260 //myDataModelXMLReader->readAll();
262 myDisplayer = new XGUI_Displayer(this);
264 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
266 myActionsMgr = new XGUI_ActionsMgr(this);
267 myActiveControlMgr = new XGUI_ActiveControlMgr(myModuleConnector);
268 myMenuMgr = new XGUI_MenuMgr(this);
269 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
270 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
271 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
272 SLOT(onContextMenuCommand(const QString&, bool)));
274 myViewerProxy = new XGUI_ViewerProxy(this);
275 //connect(myViewerProxy, SIGNAL(selectionChanged()),
276 // myActionsMgr, SLOT(updateOnViewSelection()));
278 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
280 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
281 SLOT(onOperationResumed(ModuleBase_Operation*)));
282 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
283 SLOT(onOperationStopped(ModuleBase_Operation*)));
284 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
285 SLOT(onOperationCommitted(ModuleBase_Operation*)));
286 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
287 SLOT(onOperationAborted(ModuleBase_Operation*)));
290 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
291 myDisplayer->displayTrihedron(true);
294 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
295 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
297 Config_PropManager::registerProp("Visualization", "selection_color", "Selection color",
298 Config_Prop::Color, "255,255,255");
300 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
301 myViewerSelMode.append(TopAbs_FACE);
302 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
303 myViewerSelMode.append(TopAbs_EDGE);
304 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
305 myViewerSelMode.append(TopAbs_VERTEX);
306 //IMP: an attempt to use result selection with other selection modes
307 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
308 myViewerSelMode.append(TopAbs_COMPSOLID);
311 //******************************************************
312 XGUI_Workshop::~XGUI_Workshop(void)
315 #ifdef MISSED_TRANSLATION
316 // Save Missed translations
317 Config_Translator::saveMissedTranslations();
322 delete myDataModelXMLReader;
323 delete mySelectionActivate;
328 //******************************************************
329 void XGUI_Workshop::startApplication()
331 //Initialize event listening
332 myEventsListener->initializeEventListening();
334 myDataModelXMLReader->readAll();
337 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
338 Config_Prop::Directory, "");
340 std::string aDir = Config_XMLReader::resourcesConfigFile();
341 Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
342 Config_Prop::Directory, aDir);
345 Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start",
346 Config_Prop::Boolean, "false");
348 Config_PropManager::registerProp("Plugins", "show_hide_faces", "Show Hide Faces (on the right)",
349 Config_Prop::Boolean, "false");
351 registerValidators();
353 // Calling of loadCustomProps before activating module is required
354 // by Config_PropManger to restore user-defined path to plugins
355 ModuleBase_Preferences::loadCustomProps();
356 std::vector<int> aColor;
358 aColor = Config_PropManager::color("Visualization", "selection_color");
362 if (aColor.size() == 3)
363 myDisplayer->setSelectionColor(aColor);
368 myMainWindow->show();
369 updateCommandStatus();
374 myViewerProxy->connectViewProxy();
375 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
376 SLOT(onTrihedronVisibilityChanged(bool)));
378 emit applicationStarted();
381 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
383 module()->launchOperation("Part", false); // PartSetPlugin_Part::ID()
388 //******************************************************
389 void XGUI_Workshop::activateModule()
391 selectionActivate()->updateSelectionFilters();
393 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
394 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
395 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
396 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
398 updateCommandStatus();
400 // TODO: get default selection mode
402 // activate visualized objects in the viewer
403 activateObjectsSelection(displayer()->displayedObjects());
404 myOperationMgr->activate();
407 //******************************************************
408 void XGUI_Workshop::deactivateModule()
410 // remove internal displayer filter
411 displayer()->deactivateSelectionFilters(false);
413 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
414 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
415 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
416 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
418 XGUI_Displayer* aDisplayer = displayer();
419 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
420 aDisplayer->deactivateObjects(aDisplayed, true);
421 selectionActivate()->deactivateTrihedronInSelectionModes();
423 #ifdef BEFORE_TRIHEDRON_PATCH
424 //Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
425 /// Trihedron problem: objects stayed in the viewer, should be removed manually
426 /// otherwise in SALOME happens crash by HideAll in the viewer
427 aContext->Remove(aTrihedron->Position(), true);
428 aContext->Remove(aTrihedron->Axis(), true);
429 aContext->Remove(aTrihedron->XAxis(), true);
430 aContext->Remove(aTrihedron->YAxis(), true);
433 myOperationMgr->deactivate();
436 //******************************************************
437 void XGUI_Workshop::initMenu()
439 myContextMenuMgr->createActions();
442 // Create only Undo, Redo commands
443 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
444 tr("Undo last command"),
445 QIcon(":pictures/undo.png"),
446 QKeySequence::Undo, false,
448 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
449 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
451 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
452 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
454 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
455 QIcon(":pictures/redo.png"), QKeySequence::Redo,
456 false, "MEN_DESK_EDIT");
457 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
459 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
460 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
462 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
464 //aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
465 // tr("Blocks immediate apply of modifications"),
466 // QIcon(":pictures/autoapply.png"), QKeySequence(),
467 // false, "MEN_DESK_EDIT");
468 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
470 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onAutoApply()));
472 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
475 // Add commands to a file menu
477 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Part set..."),
478 tr("Import native file"),
479 QIcon(), QKeySequence(),
480 false, "MEN_DESK_FILE", tr("Import"), 10, 10);
481 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
483 aAction = salomeConnector()->addDesktopCommand("IMPORT_PART_CMD", tr("Part..."),
484 tr("Import structure of a part"),
485 QIcon(), QKeySequence(),
486 false, "MEN_DESK_FILE", tr("Import"), 10, 10);
487 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportPart()));
489 aAction = salomeConnector()->addDesktopCommand("IMPORT_SHAPE_CMD", tr("From CAD format..."),
490 tr("Import shape from a CAD format file"),
491 ModuleBase_IconFactory::loadIcon("icons/Exchange/import.png"),
492 QKeySequence(), false, "MEN_DESK_FILE", tr("Import"), 10, 10);
493 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportShape()));
495 aAction = salomeConnector()->addDesktopCommand("IMPORT_IMAGE_CMD", tr("Picture..."),
496 tr("Import a picture from an image file"),
498 QKeySequence(), false, "MEN_DESK_FILE", tr("Import"), 10, 10);
499 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportImage()));
502 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Part set..."),
503 tr("Export the current document into a native file"),
504 QIcon(), QKeySequence(),
505 false, "MEN_DESK_FILE", tr("Export"), 10, 11);
506 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
508 aAction = salomeConnector()->addDesktopCommand("EXPORT_PART_CMD", tr("Part..."),
509 tr("Export a part of the current document into a file"),
510 QIcon(), QKeySequence(),
511 false, "MEN_DESK_FILE", tr("Export"), 10, 11);
512 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportPart()));
514 aAction = salomeConnector()->addDesktopCommand("EXPORT_SHAPE_CMD", tr("To CAD format..."),
515 tr("Export shape to a CAD format file"),
516 ModuleBase_IconFactory::loadIcon("icons/Exchange/export.png"),
517 QKeySequence(), false, "MEN_DESK_FILE", tr("Export"), 10, 11);
518 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportShape()));
521 // File commands group
522 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
524 AppElements_Command* aCommand;
526 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
527 QIcon(":pictures/save.png"), QKeySequence::Save);
528 aCommand->connectTo(this, SLOT(onSave()));
529 //aCommand->disable();
531 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
532 QIcon(":pictures/save.png"), QKeySequence());
533 aCommand->connectTo(this, SLOT(onSaveAs()));
535 QString aUndoId = "UNDO_CMD";
536 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
537 QIcon(":pictures/undo.png"), QKeySequence::Undo);
538 aCommand->connectTo(this, SLOT(onUndo()));
539 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
540 addHistoryMenu(aUndoButton,
541 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
544 QString aRedoId = "REDO_CMD";
545 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
546 QIcon(":pictures/redo.png"), QKeySequence::Redo);
547 aCommand->connectTo(this, SLOT(onRedo()));
548 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
549 addHistoryMenu(aRedoButton,
550 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
553 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
554 QIcon(":pictures/open.png"), QKeySequence::Open);
555 aCommand->connectTo(this, SLOT(onOpen()));
558 aCommand = aGroup->addFeature("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
559 tr("Blocks immediate apply of modifications"),
560 QIcon(":pictures/autoapply_start.png"), QKeySequence());
561 aCommand->setChecked(ModelAPI_Session::get()->isAutoUpdateBlocked());
562 aCommand->connectTo(this, SLOT(onAutoApply()));
564 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
565 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
566 aCommand->connectTo(this, SLOT(onPreferences()));
568 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
569 QIcon(":pictures/close.png"), QKeySequence::Close);
570 aCommand->connectTo(this, SLOT(onExit()));
575 //******************************************************
576 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
578 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
579 return aMenuBar->addWorkbench(theName);
583 //******************************************************
584 QMainWindow* XGUI_Workshop::desktop() const
587 return salomeConnector()->desktop();
593 //******************************************************
594 void XGUI_Workshop::onStartWaiting()
596 if (Events_LongOp::isPerformed()) {
597 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
601 //******************************************************
602 void XGUI_Workshop::onAcceptActionClicked()
604 XGUI_OperationMgr* anOperationMgr = operationMgr();
605 if (anOperationMgr) {
606 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
607 (anOperationMgr->currentOperation());
609 myOperationMgr->commitOperation();
614 //******************************************************
615 void XGUI_Workshop::onAcceptPlusActionClicked()
617 XGUI_OperationMgr* anOperationMgr = operationMgr();
618 if (anOperationMgr) {
619 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
620 (anOperationMgr->currentOperation());
622 if (myOperationMgr->commitOperation())
623 module()->launchOperation(aFOperation->id(), false);
628 //******************************************************
629 void XGUI_Workshop::onPreviewActionClicked()
631 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
633 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
634 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
635 anActiveWidget->storeValue();
638 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
639 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
640 Events_Loop::loop()->send(aMsg);
644 //******************************************************
645 void XGUI_Workshop::onHelpActionClicked() const
647 XGUI_OperationMgr* anOperationMgr = operationMgr();
648 if (anOperationMgr) {
649 ModuleBase_Operation* aOperation = anOperationMgr->currentOperation();
651 showHelpPage(aOperation->helpFileName());
656 void XGUI_Workshop::showHelpPage(const QString& thePage) const
658 if (!thePage.isEmpty()) {
660 const QChar aSep = QDir::separator();
662 // SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
664 // platform = "winapplication";
666 // platform = "application";
668 // QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform);
671 QString aDir(getenv("SHAPER_ROOT_DIR"));
672 if (!aDir.isEmpty()) {
673 aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep +
674 "salome" + aSep + "gui" + aSep + "SHAPER";
677 QString aDir(getenv("CADBUILDER_ROOT_DIR"));
678 aDocDir = aDir + aSep + "doc" + aSep + "gui";
680 QString aFileName = aDocDir + aSep + thePage;
681 if (QFile::exists(aFileName)) {
683 SUIT_Application* app = SUIT_Session::session()->activeApplication();
685 app->onHelpContextModule("SHAPER", aFileName);
687 QUrl aUrl = QUrl::fromLocalFile(aFileName);
688 QDesktopServices::openUrl(aUrl);
691 QUrl aUrl = QUrl::fromLocalFile(aFileName);
692 QDesktopServices::openUrl(aUrl);
699 //******************************************************
700 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
702 if (!myModule->canActivateSelection(theObject)) {
703 if (selectionActivate()->isActive(theObject)) {
704 QObjectPtrList anObjects;
705 anObjects.append(theObject);
706 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
711 //******************************************************
712 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
714 bool aHasNested = false;
715 std::string aFeatureKind = theFeature->getKind();
717 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
718 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
721 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
722 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
723 if (aCommand && aCommand->button()->additionalButtonWidget())
729 //******************************************************
730 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
732 ModuleBase_OperationFeature* aFOperation =
733 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
737 myPropertyPanel->cleanContent();
739 QList<ModuleBase_ModelWidget*> aWidgets;
740 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
741 if (!module()->createWidgets(aFOperation->feature(), aXmlRepr, aWidgets)) {
742 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
743 aFactory.createWidget(myPropertyPanel->contentWidget());
744 aWidgets = aFactory.getModelWidgets();
747 // check compatibility of feature and widgets
748 FeaturePtr aFeature = aFOperation->feature();
749 std::string aFeatureKind = aFeature->getKind();
750 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
751 if (aWidget->usesAttribute()) {
752 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
753 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
754 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
755 .arg(aFeatureKind).arg(aWidget->attributeID())
756 .arg(aWidget->metaObject()->className()).send();
757 myPropertyPanel->cleanContent();
762 // for performance purpose, flush should be done after all controls are filled
763 bool isUpdateFlushed = false;
764 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
765 bool isStoreValue = !aFOperation->isEditOperation() &&
766 !aWidget->getDefaultValue().empty() &&
767 !aWidget->isComputedDefault();
768 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
770 aWidget->restoreValue();
771 aWidget->enableFocusProcessing();
773 // update visible state of Preview button
774 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
776 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
778 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
779 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
781 aFeatureInfo = aCommand->featureMessage();
783 bool anIsAutoPreview = true;
784 if (aFeatureInfo.get()) {
785 anIsAutoPreview = aFeatureInfo->isAutoPreview();
786 theOperation->setHelpFileName(aFeatureInfo->helpFileName().c_str());
788 std::string aXmlCfg, aDescription;
789 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
790 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
791 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
794 if (!anIsAutoPreview) {
795 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
796 // send signal about preview should not be computed automatically, click on preview
797 // button should initiate it
798 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
799 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
800 Events_Loop::loop()->send(aMsg);
802 // if update happens after preview is blocked, it does nothing when blocked
803 // it improves performance for valid objects on feature start
804 ModuleBase_Tools::flushUpdated(aFeature);
806 myPropertyPanel->setModelWidgets(aWidgets);
807 aFOperation->setPropertyPanel(myPropertyPanel);
809 myModule->propertyPanelDefined(theOperation);
811 #ifndef DEBUG_FEATURE_NAME
812 myPropertyPanel->setWindowTitle(ModuleBase_Tools::translate("workshop",
813 theOperation->getDescription()->description().toStdString()));
815 std::string aFeatureName = aFeature->name();
816 myPropertyPanel->setWindowTitle(QString("%1: %2")
817 .arg(translate(theOperation->getDescription()->description()))
818 .arg(translate(aFeatureName.c_str())));
821 myErrorMgr->setPropertyPanel(myPropertyPanel);
822 if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) {
823 theOperation->setHideFacesVisible(myFacesPanel->isVisible());
824 if (aFeatureInfo.get() && aFeatureInfo->isHideFacesPanel() && !myFacesPanel->isVisible())
825 myFacesPanel->show();
827 showPanel(myPropertyPanel);
830 //******************************************************
831 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
833 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
834 if (aPropertyPanel) {
835 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
836 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
837 myModule->connectToPropertyPanel(aWidget, isToConnect);
839 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
840 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
841 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
844 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
845 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
846 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
852 //******************************************************
853 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
855 setGrantedFeatures(theOperation);
857 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
858 fillPropertyPanel(theOperation);
859 connectToPropertyPanel(true);
860 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
863 myPropertyPanel->updateApplyPlusButton(aFOperation->feature());
865 myPropertyPanel->updateApplyPlusButton(FeaturePtr());
867 updateCommandStatus();
869 myModule->operationResumed(theOperation);
872 //******************************************************
873 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
875 updateCommandStatus();
877 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
882 ModuleBase_ISelection* aSel = mySelector->selection();
883 QObjectPtrList aObj = aSel->selectedPresentations();
884 //!< No need for property panel
885 hidePanel(myPropertyPanel);
886 myPropertyPanel->cleanContent();
888 connectToPropertyPanel(false);
889 myModule->operationStopped(aFOperation);
891 // the deactivated objects of the current operation should be activated back.
892 // They were deactivated on operation start or an object redisplay
893 QObjectPtrList anObjects;
894 FeaturePtr aFeature = aFOperation->feature();
895 if (aFeature.get()) { // feature may be not created (plugin load fail)
896 if (myDisplayer->isVisible(aFeature) && !selectionActivate()->isActive(aFeature))
897 anObjects.append(aFeature);
898 std::list<ResultPtr> aResults;
899 ModelAPI_Tools::allResults(aFeature, aResults);
900 std::list<ResultPtr>::const_iterator aIt;
901 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
902 ResultPtr anObject = *aIt;
903 if (myDisplayer->isVisible(anObject) && !selectionActivate()->isActive(anObject)) {
904 anObjects.append(anObject);
908 activateObjectsSelection(anObjects);
910 if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) {
911 if (!theOperation->isHideFacesVisible())
912 myFacesPanel->close();
916 //******************************************************
917 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
919 myModule->operationCommitted(theOperation);
922 //******************************************************
923 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
925 myModule->operationAborted(theOperation);
928 //******************************************************
929 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
931 ModuleBase_OperationFeature* aFOperation =
932 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
936 QStringList aGrantedIds;
937 if (isSalomeMode()) {
938 const std::shared_ptr<Config_FeatureMessage>& anInfo =
939 mySalomeConnector->featureInfo(theOperation->id());
941 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
942 .split(" ", QString::SkipEmptyParts);
945 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
947 ModuleBase_IModule* aModule = module();
949 aModule->grantedOperationIds(theOperation, aGrantedIds);
951 aFOperation->setGrantedOperationIds(aGrantedIds);
954 //******************************************************
955 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
957 QApplication::restoreOverrideCursor();
958 SessionPtr aMgr = ModelAPI_Session::get();
960 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
961 std::list<DocumentPtr>::const_iterator aIt;
962 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
963 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
964 (*aIt)->storeNodesState(aState);
967 aMgr->save(theName.toLatin1().constData(), theFileNames);
969 QApplication::restoreOverrideCursor();
972 //******************************************************
973 bool XGUI_Workshop::abortAllOperations()
975 return myOperationMgr->abortAllOperations();
978 //******************************************************
979 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
981 setGrantedFeatures(theOperation);
982 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
983 updateCommandStatus();
986 myModule->operationStarted(theOperation);
990 //******************************************************
991 void XGUI_Workshop::onOpen()
993 if(!abortAllOperations())
995 //save current file before close if modified
996 SessionPtr aSession = ModelAPI_Session::get();
997 if (aSession->isModified()) {
998 int anAnswer = QMessageBox::question(
999 desktop(), tr("Save current file"),
1000 tr("The document is modified, save before opening another?"),
1001 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
1002 if (anAnswer == QMessageBox::Save) {
1004 } else if (anAnswer == QMessageBox::Cancel) {
1007 myCurrentFile = QString();
1010 //show file dialog, check if readable and open
1011 qreal aRatio = ModuleBase_Tools::currentPixelRatio();
1012 // If the ratio is > 1 (HD screen) then QT has a bug in
1013 // displaying of system open file dialog (too small)
1014 QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Open file"), QString(), MyFilter,
1015 Q_NULLPTR, ((aRatio > 1)? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
1016 if (!aFile.isNull())
1020 //******************************************************
1021 void XGUI_Workshop::openFile(const QString& theDirectory)
1023 myCurrentFile = theDirectory;
1024 if (myCurrentFile.isEmpty())
1027 QFileInfo aFileInfo(myCurrentFile);
1028 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
1029 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
1030 myCurrentFile = QString();
1034 QApplication::setOverrideCursor(Qt::WaitCursor);
1035 module()->closeDocument();
1036 SessionPtr aSession = ModelAPI_Session::get();
1037 aSession->closeAll();
1039 clearTemporaryDir();
1040 if (!XGUI_CompressFiles::uncompress(myCurrentFile, myTmpDir.path()))
1043 aSession->load(myTmpDir.path().toLatin1().constData());
1044 myObjectBrowser->rebuildDataTree();
1046 // Open first level of data tree
1047 DocumentPtr aRootDoc = aSession->moduleDocument();
1048 std::list<bool> aStates;
1049 aRootDoc->restoreNodesState(aStates);
1050 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
1052 updateCommandStatus();
1054 myMainWindow->setCurrentDir(myCurrentFile, true);
1058 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
1060 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
1062 ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
1063 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
1070 QApplication::restoreOverrideCursor();
1073 //******************************************************
1074 void XGUI_Workshop::onNew()
1076 QApplication::setOverrideCursor(Qt::WaitCursor);
1077 if (objectBrowser() == 0) {
1078 createDockWidgets();
1079 mySelector->connectViewers();
1081 myViewerProxy->connectToViewer();
1082 showObjectBrowser();
1084 myMainWindow->showPythonConsole();
1085 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
1086 aWnd->showMaximized();
1087 updateCommandStatus();
1088 PyConsole_Console* aConsole = myMainWindow->pythonConsole();
1089 connect(aConsole, SIGNAL(scriptLoaded()), SLOT(updateCommandStatus()));
1091 myContextMenuMgr->connectViewer();
1092 QApplication::restoreOverrideCursor();
1096 //******************************************************
1097 void XGUI_Workshop::onExit()
1099 SessionPtr aMgr = ModelAPI_Session::get();
1100 if (aMgr->isModified()) {
1101 int anAnswer = QMessageBox::question(
1102 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
1103 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
1104 if (anAnswer == QMessageBox::Save) {
1105 bool saved = onSave();
1109 } else if (anAnswer == QMessageBox::Cancel) {
1116 //******************************************************
1117 void XGUI_Workshop::onPreferences()
1119 ModuleBase_Prefs aModif;
1120 ModuleBase_Preferences::editPreferences(aModif);
1121 if (aModif.size() > 0) {
1123 foreach (ModuleBase_Pref aPref, aModif) {
1124 aSection = aPref.first;
1125 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
1126 myMainWindow->viewer()->updateFromResources();
1127 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
1128 myMainWindow->menuObject()->updateFromResources();
1131 std::vector<int> aColor;
1133 aColor = Config_PropManager::color("Visualization", "selection_color");
1137 if (aColor.size() == 3)
1138 displayer()->setSelectionColor(aColor);
1140 displayer()->redisplayObjects();
1145 //******************************************************
1146 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
1148 XGUI_Displayer* aDisplayer = displayer();
1150 aDisplayer->displayTrihedron(theState);
1151 aDisplayer->updateViewer();
1155 //******************************************************
1156 bool XGUI_Workshop::onSave()
1158 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1160 if (myCurrentFile.isEmpty()) {
1163 SessionPtr aMgr = ModelAPI_Session::get();
1164 if (aMgr->isAutoUpdateBlocked())
1165 aMgr->blockAutoUpdate(false);
1167 std::list<std::string> aFiles;
1168 // issue #2899: create a temporary directory, save and then remove it
1170 std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("SALOME_TMP_DIR");
1172 std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("");
1174 saveDocument(QString(aTmpDir.c_str()), aFiles);
1175 bool aResult = XGUI_CompressFiles::compress(myCurrentFile, aFiles);
1176 XGUI_Tools::removeTemporaryFiles(aTmpDir, aFiles);
1179 updateCommandStatus();
1181 myMainWindow->setModifiedState(false);
1187 //******************************************************
1188 bool XGUI_Workshop::onSaveAs()
1190 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1192 qreal aRatio = ModuleBase_Tools::currentPixelRatio();
1193 myCurrentFile = QFileDialog::getSaveFileName(desktop(), tr("Select name to save file..."),
1194 QString(), MyFilter2,
1195 Q_NULLPTR, ((aRatio > 1) ? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
1196 if (!myCurrentFile.isNull()) {
1197 if (!myCurrentFile.endsWith(MyExtension)) {
1198 myCurrentFile += MyExtension;
1204 myMainWindow->setCurrentDir(myCurrentFile, false);
1205 myMainWindow->setModifiedState(false);
1210 //******************************************************
1211 void XGUI_Workshop::onUndo(int theTimes)
1213 processUndoRedo(ActionUndo, theTimes);
1214 myObjectBrowser->updateAllIndexes(1);
1217 //******************************************************
1218 void XGUI_Workshop::onRedo(int theTimes)
1220 processUndoRedo(ActionRedo, theTimes);
1221 myObjectBrowser->updateAllIndexes(1);
1224 //******************************************************
1225 void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes)
1227 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1228 if (anActiveWidget) {
1229 ActionIntParamPtr aParam(new ModuleBase_ActionIntParameter(theTimes));
1230 if (anActiveWidget->processAction(theActionType, aParam))
1235 XGUI_FacesPanel * anFacePannel = facesPanel();
1236 if(ActionUndo == theActionType && anFacePannel->isActivePanel())
1238 anFacePannel->processUndo();
1242 // the viewer update should be blocked in order to avoid the features blinking. For the created
1243 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1244 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1245 // until redo of all possible objects happens
1246 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1248 int aTimes = theTimes;
1249 SessionPtr aMgr = ModelAPI_Session::get();
1250 if (aMgr->isOperation()) {
1251 XGUI_OperationMgr* aOpMgr = operationMgr();
1252 /// this is important for nested operations
1253 /// when sketch operation is active, this condition is false and
1254 /// the sketch operation is not aborted
1255 if (aOpMgr->canStopOperation(aOpMgr->currentOperation())) {
1256 aOpMgr->abortOperation(aOpMgr->currentOperation());
1261 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1265 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1266 std::list<std::string> anActionList = theActionType == ActionUndo ? aMgr->undoList()
1268 std::list<std::string>::const_iterator aIt = anActionList.cbegin();
1269 for (int i = 0; (i < aTimes) && (aIt != anActionList.cend()); ++i, ++aIt) {
1270 if (theActionType == ActionUndo)
1275 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND ||
1276 QString((*aIt).c_str()) == MOVE_TO_END_SPLIT_COMMAND)
1277 myObjectBrowser->rebuildDataTree();
1279 operationMgr()->updateApplyOfOperations();
1280 facesPanel()->reset(true);
1281 updateCommandStatus();
1283 // unblock the viewer update functionality and make update on purpose
1284 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1285 myDisplayer->updateViewer();
1286 // Clear messages in status bar from previous operations if exists
1287 setStatusBarMessage("");
1290 //******************************************************
1291 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1293 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1294 //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1295 //if (anOperation) {
1296 // ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1298 // anActiveWidget = aPanel->activeWidget();
1301 operationMgr()->onValidateOperation();
1303 myModule->widgetStateChanged(thePreviousState);
1306 //******************************************************
1307 void XGUI_Workshop::onValuesChanged()
1309 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1310 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1313 ModuleBase_ModelWidget* anActiveWidget = 0;
1314 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1316 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1318 anActiveWidget = aPanel->activeWidget();
1320 if (anActiveWidget) {
1321 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1323 if (aWidgetValidated)
1324 aWidgetValidated->clearValidatedCash();
1328 //******************************************************
1329 void XGUI_Workshop::onWidgetObjectUpdated()
1331 operationMgr()->onValidateOperation();
1332 myDisplayer->updateViewer();
1335 //******************************************************
1336 void XGUI_Workshop::onImportPart()
1338 if (abortAllOperations()) {
1339 ModuleBase_OperationFeature* anImportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
1340 module()->createOperation(ExchangePlugin_ImportPart::ID()));
1341 anImportPartOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
1342 "importFeature.html");
1343 myPropertyPanel->updateApplyPlusButton(anImportPartOp->feature());
1344 operationMgr()->startOperation(anImportPartOp);
1348 //******************************************************
1349 void XGUI_Workshop::onImportShape()
1351 if (abortAllOperations()) {
1352 ModuleBase_OperationFeature* anImportOp = dynamic_cast<ModuleBase_OperationFeature*>(
1353 module()->createOperation(ExchangePlugin_Import::ID()));
1354 anImportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
1355 "importFeature.html");
1356 myPropertyPanel->updateApplyPlusButton(anImportOp->feature());
1357 operationMgr()->startOperation(anImportOp);
1361 //******************************************************
1362 void XGUI_Workshop::onImportImage()
1364 if (abortAllOperations()) {
1365 ModuleBase_OperationFeature* anImportOp = dynamic_cast<ModuleBase_OperationFeature*>(
1366 module()->createOperation(ExchangePlugin_Import_Image::ID()));
1367 anImportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
1368 "importFeature.html");
1369 myPropertyPanel->updateApplyPlusButton(anImportOp->feature());
1370 operationMgr()->startOperation(anImportOp);
1374 //******************************************************
1375 void XGUI_Workshop::onExportShape()
1377 if (abortAllOperations()) {
1378 ModuleBase_OperationFeature* anExportOp = dynamic_cast<ModuleBase_OperationFeature*>(
1379 module()->createOperation(ExchangePlugin_ExportFeature::ID()));
1380 anExportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
1381 "exportFeature.html");
1382 myPropertyPanel->updateApplyPlusButton(anExportOp->feature());
1383 operationMgr()->startOperation(anExportOp);
1387 //******************************************************
1388 void XGUI_Workshop::onExportPart()
1390 if (abortAllOperations()) {
1391 ModuleBase_OperationFeature* anExportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
1392 module()->createOperation(ExchangePlugin_ExportPart::ID()));
1393 anExportPartOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
1394 "exportFeature.html");
1395 myPropertyPanel->updateApplyPlusButton(anExportPartOp->feature());
1396 operationMgr()->startOperation(anExportPartOp);
1400 //******************************************************
1401 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1403 QString libName = QString::fromStdString(library(theModule.toStdString()));
1404 if (libName.isEmpty()) {
1405 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1410 CREATE_FUNC crtInst = 0;
1413 HINSTANCE modLib = ::LoadLibraryA(qPrintable(libName));
1417 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1418 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1419 QString aMsg((char*) &lpMsgBuf);
1420 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1421 ::LocalFree(lpMsgBuf);
1423 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1427 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1428 | FORMAT_MESSAGE_IGNORE_INSERTS,
1429 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1430 QString aMsg((char*) &lpMsgBuf);
1431 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1432 ::LocalFree(lpMsgBuf);
1436 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1438 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1440 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1442 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1447 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1449 if (!err.isEmpty()) {
1451 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1453 qWarning(qPrintable(err));
1459 //******************************************************
1460 bool XGUI_Workshop::createModule()
1462 Config_ModuleReader aModuleReader;
1463 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1464 myModule = loadModule(moduleName);
1468 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1469 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1470 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1471 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1473 myModule->createFeatures();
1475 salomeConnector()->createFeatureActions();
1477 //myActionsMgr->update();
1481 //******************************************************
1482 void XGUI_Workshop::updateCommandStatus()
1484 QList<QAction*> aCommands;
1486 aCommands = salomeConnector()->commandList();
1488 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1489 foreach (AppElements_Command* aCmd, aMenuBar->features())
1490 aCommands.append(aCmd);
1492 SessionPtr aMgr = ModelAPI_Session::get();
1493 if (aMgr->hasModuleDocument()) {
1494 foreach(QAction* aCmd, aCommands) {
1495 QString aId = aCmd->data().toString();
1496 if (aId == "UNDO_CMD") {
1497 bool isActionEnabled = false;
1498 // if ultimate is true -> using result of operation only, or using OR combination
1499 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1500 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled))
1501 aCmd->setEnabled(isActionEnabled);
1503 aCmd->setEnabled(myModule->canUndo());
1505 else if (aId == "REDO_CMD") {
1506 bool isActionEnabled = false;
1507 // if ultimate is true -> using result of operation only, or using OR combination
1508 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1509 if (anActiveWidget && anActiveWidget->canProcessAction(ActionRedo, isActionEnabled))
1510 aCmd->setEnabled(isActionEnabled);
1512 aCmd->setEnabled(myModule->canRedo());
1514 else if (aId == "AUTOCOMPUTE_CMD") {
1515 aCmd->setIcon(aMgr->isAutoUpdateBlocked() ?
1516 QIcon(":pictures/autoapply_stop.png") :
1517 QIcon(":pictures/autoapply_start.png"));
1520 // Enable all commands
1521 aCmd->setEnabled(true);
1525 foreach(QAction* aCmd, aCommands) {
1526 QString aId = aCmd->data().toString();
1527 if (aId == "NEW_CMD")
1528 aCmd->setEnabled(true);
1529 else if (aId == "EXIT_CMD")
1530 aCmd->setEnabled(true);
1532 aCmd->setEnabled(false);
1535 myActionsMgr->updateCommandsStatus();
1536 emit commandStatusUpdated();
1539 //******************************************************
1540 void XGUI_Workshop::updateHistory()
1542 bool isActionEnabled = false;
1543 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1544 QList<ActionInfo> aUndoRes;
1545 QList<ActionInfo> aRedoRes;
1546 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled)) {
1547 aUndoRes = anActiveWidget->actionsList(ActionUndo);
1548 aRedoRes = anActiveWidget->actionsList(ActionRedo);
1550 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1551 aUndoRes = processHistoryList(aUndoList);
1553 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1554 aRedoRes = processHistoryList(aRedoList);
1556 emit updateUndoHistory(aUndoRes);
1557 emit updateRedoHistory(aRedoRes);
1560 //******************************************************
1561 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1563 QDockWidget* aObjDock = new QDockWidget(theParent);
1564 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1565 Qt::RightDockWidgetArea);
1566 aObjDock->setWindowTitle(tr("Object browser"));
1567 aObjDock->setStyleSheet(
1568 "::title { position: relative; padding-left: 5px; text-align: left center }");
1569 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock, this);
1570 myObjectBrowser->initialize(myModule->rootNode());
1571 myModule->customizeObjectBrowser(myObjectBrowser);
1572 aObjDock->setWidget(myObjectBrowser);
1573 aObjDock->setObjectName("Object browser");
1575 connect(myObjectBrowser, SIGNAL(sizeChanged()), SLOT(onDockSizeChanged()));
1577 myContextMenuMgr->connectObjectBrowser();
1581 //******************************************************
1583 * Creates dock widgets, places them in corresponding area
1584 * and tabifies if necessary.
1586 void XGUI_Workshop::createDockWidgets()
1588 QMainWindow* aDesktop = desktop();
1589 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1590 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1591 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1592 myActiveControlMgr->addSelector(new XGUI_PropertyPanelSelector(myPropertyPanel));
1594 myPropertyPanel->setupActions(myActionsMgr);
1595 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1596 Qt::RightDockWidgetArea);
1597 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1599 hidePanel(myPropertyPanel); ///<! Invisible by default
1601 myFacesPanel = new XGUI_FacesPanel(aDesktop, this);
1602 myActiveControlMgr->addSelector(new XGUI_FacesPanelSelector(myFacesPanel));
1603 myFacesPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1604 Qt::RightDockWidgetArea |
1605 Qt::BottomDockWidgetArea);
1606 connect(myFacesPanel, SIGNAL(closed()), myFacesPanel, SLOT(onClosed()));
1608 myInspectionPanel = new XGUI_InspectionPanel(aDesktop, this);
1609 myInspectionPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1610 Qt::RightDockWidgetArea);
1611 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myInspectionPanel);
1613 myInspectionPanel->hide();
1615 aDesktop->addDockWidget(
1617 Qt::RightDockWidgetArea,
1619 Qt::LeftDockWidgetArea,
1622 hidePanel(myFacesPanel); ///<! Invisible by default
1625 bool aShowOnTheRight = Config_PropManager::boolean("Plugins", "show_hide_faces");
1626 if (aShowOnTheRight) {
1627 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myFacesPanel);
1628 showPanel(myFacesPanel);
1631 hideObjectBrowser();
1635 if (!aShowOnTheRight)
1638 aDesktop->tabifyDockWidget(myFacesPanel, aObjDock);
1643 #endif // HAVE_SALOME
1645 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1646 myPropertyPanel->installEventFilter(myOperationMgr);
1648 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1649 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1651 QAction* aOkContAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptPlus);
1652 connect(aOkContAct, SIGNAL(triggered()), this, SLOT(onAcceptPlusActionClicked()));
1654 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1655 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1657 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1658 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1660 QAction* aHelpAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Help);
1661 connect(aHelpAct, SIGNAL(triggered()), this, SLOT(onHelpActionClicked()));
1663 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1664 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1665 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1666 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1669 //******************************************************
1670 void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
1672 if (theDockWidget == myPropertyPanel) {
1673 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1674 ///<! Restore ability to close panel from the window's menu
1675 aViewAct->setEnabled(true);
1677 theDockWidget->show();
1678 theDockWidget->raise();
1680 // The next code is necessary to made the property panel the active window
1681 // in order to operation manager could process key events of the panel.
1682 // otherwise they are ignored. It happens only if the same(activateWindow) is
1683 // not happened by property panel activation(e.g. resume operation of Sketch)
1684 //ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
1687 //******************************************************
1688 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
1690 if (theDockWidget && theDockWidget == myPropertyPanel) {
1691 QAction* aViewAct = theDockWidget->toggleViewAction();
1692 ///<! Do not allow to show empty property panel
1693 aViewAct->setEnabled(false);
1695 theDockWidget->hide();
1697 // the property panel is active window of the desktop, when it is
1698 // hidden, it is undefined which window becomes active. By this reason
1699 // it is defined to perform the desktop as the active window.
1700 // in SALOME mode, work-stack made the PyConsole the active window,
1701 // set the focus on it. As a result, shortcuts of the application, like
1702 // are processed by this console. For example Undo actions.
1703 // It is possible that this code is to be moved to SHAPER package
1704 QMainWindow* aDesktop = desktop();
1705 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::hidePanel()");
1708 //******************************************************
1709 void XGUI_Workshop::showObjectBrowser()
1711 if (!isSalomeMode()) {
1712 myObjectBrowser->parentWidget()->show();
1716 //******************************************************
1717 void XGUI_Workshop::hideObjectBrowser()
1719 if (!isSalomeMode())
1720 myObjectBrowser->parentWidget()->hide();
1723 //******************************************************
1724 void XGUI_Workshop::salomeViewerSelectionChanged()
1726 emit salomeViewerSelection();
1729 //**************************************************************
1730 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1732 return mySalomeConnector->viewer();
1735 //**************************************************************
1736 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1738 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1739 if (theId == "DELETE_CMD")
1741 else if (theId == "CLEAN_HISTORY_CMD")
1743 else if (theId == "MOVE_CMD" || theId == "MOVE_SPLIT_CMD")
1744 moveObjects(theId == "MOVE_SPLIT_CMD");
1745 else if (theId == "COLOR_CMD")
1746 changeColor(anObjects);
1747 else if (theId == "AUTOCOLOR_CMD")
1748 changeAutoColor(anObjects);
1749 else if (theId == "ISOLINES_CMD")
1750 changeIsoLines(anObjects);
1751 else if (theId == "SHOW_ISOLINES_CMD") {
1752 foreach(ObjectPtr aObj, anObjects) {
1753 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1755 ModelAPI_Tools::showIsoLines(aResult, !ModelAPI_Tools::isShownIsoLines(aResult));
1757 mySelector->clearSelection();
1758 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1760 else if (theId == "DEFLECTION_CMD")
1761 changeDeflection(anObjects);
1762 else if (theId == "TRANSPARENCY_CMD")
1763 changeTransparency(anObjects);
1764 else if (theId == "SHOW_CMD") {
1765 showObjects(anObjects, true);
1766 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1767 updateCommandStatus();
1769 else if (theId == "HIDE_CMD") {
1770 showObjects(anObjects, false);
1771 updateCommandStatus();
1773 else if (theId == "SHOW_ONLY_CMD") {
1774 showOnlyObjects(anObjects);
1775 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1776 updateCommandStatus();
1778 else if (theId == "SHADING_CMD")
1779 setDisplayMode(anObjects, XGUI_Displayer::Shading);
1780 else if (theId == "WIREFRAME_CMD")
1781 setDisplayMode(anObjects, XGUI_Displayer::Wireframe);
1782 else if (theId == "HIDEALL_CMD") {
1783 QObjectPtrList aList = myDisplayer->displayedObjects();
1784 foreach (ObjectPtr aObj, aList) {
1785 if (module()->canEraseObject(aObj))
1786 aObj->setDisplayed(false);
1788 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1790 //issue #2159 Hide all incomplete behavior
1791 viewer()->eraseAll();
1793 updateCommandStatus();
1794 // Necessary for update icons in ObjectBrowser on Linux
1795 myObjectBrowser->updateAllIndexes();
1796 } else if (theId == "SELECT_VERTEX_CMD") {
1797 setViewerSelectionMode(TopAbs_VERTEX);
1798 } else if (theId == "SELECT_EDGE_CMD") {
1799 setViewerSelectionMode(TopAbs_EDGE);
1800 } else if (theId == "SELECT_FACE_CMD") {
1801 setViewerSelectionMode(TopAbs_FACE);
1802 } else if (theId == "INSERT_FOLDER_CMD") {
1803 insertFeatureFolder();
1804 } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
1805 insertToFolder(true);
1806 } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
1807 insertToFolder(false);
1808 } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
1809 moveOutFolder(true);
1810 } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
1811 moveOutFolder(false);
1812 } else if (theId == "SELECT_RESULT_CMD") {
1813 //setViewerSelectionMode(-1);
1814 //IMP: an attempt to use result selection with other selection modes
1815 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1816 setViewerSelectionMode(TopAbs_COMPSOLID);
1817 } else if (theId == "SHOW_RESULTS_CMD") {
1818 highlightResults(anObjects);
1819 } else if (theId == "SHOW_FEATURE_CMD") {
1820 highlightFeature(anObjects);
1821 } else if (theId == "SET_VIEW_NORMAL_CMD") {
1823 } else if (theId == "SET_VIEW_INVERTEDNORMAL_CMD") {
1824 setNormalView(true);
1827 else if (theId == "TINSPECTOR_VIEW") {
1828 Handle(TDocStd_Application) anApplication = ModelAPI_Session::get()->application();
1829 if (!anApplication.IsNull())
1831 if (!MyTCommunicator)
1833 MyTCommunicator = new TInspector_Communicator();
1835 NCollection_List<Handle(Standard_Transient)> aParameters;
1836 aParameters.Append(anApplication);
1837 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1838 if (!aContext.IsNull())
1839 aParameters.Append(aContext);
1841 #ifdef DEBUG_WITH_MESSAGE_REPORT
1842 Handle(Message_Report) aContextReport = aContext->GetReport();
1843 aContext->SetReportActive (Standard_True);
1844 aContextReport->SetLimit (1000);
1845 if (!aContextReport.IsNull())
1846 aParameters.Append(aContextReport);
1848 MyVCallBack = new VInspector_CallBack();
1849 myDisplayer->setCallBack(MyVCallBack);
1851 AppElements_Viewer* aViewer = mainWindow()->viewer();
1853 aViewer->setCallBack(MyVCallBack);
1855 aParameters.Append(MyVCallBack);
1857 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1858 MyTCommunicator->RegisterPlugin("TKShapeView");
1859 MyTCommunicator->RegisterPlugin("TKVInspector");
1860 #ifdef DEBUG_WITH_MESSAGE_REPORT
1861 MyTCommunicator->RegisterPlugin("TKMessageView");
1863 //MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1864 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1866 MyTCommunicator->Init(aParameters);
1867 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1868 #ifndef DEBUG_WITH_MESSAGE_REPORT
1869 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1871 MyTCommunicator->Activate("TKDFBrowser");
1873 #ifdef DEBUG_WITH_MESSAGE_REPORT
1874 MyTCommunicator->Activate("TKMessageView"); // temporary
1875 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1878 MyTCommunicator->SetVisible(true);
1884 //**************************************************************
1885 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1888 myViewerSelMode.clear();
1890 if (myViewerSelMode.contains(theMode))
1891 myViewerSelMode.removeAll(theMode);
1893 myViewerSelMode.append(theMode);
1895 selectionActivate()->updateSelectionModes();
1898 //**************************************************************
1899 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1902 module()->activeSelectionModes(aModes);
1903 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1904 aModes.append(myViewerSelMode);
1905 selectionActivate()->activateObjects(aModes, theList);
1908 //**************************************************************
1909 bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) const
1911 if (facesPanel()->isEmpty())
1914 // generate container of objects taking into account sub elments of compsolid
1915 std::set<ObjectPtr> anAllProcessedObjects;
1916 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1917 anObjectsIt != theObjects.end(); anObjectsIt++) {
1918 ObjectPtr anObject = *anObjectsIt;
1919 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
1920 if (aCompRes.get()) {
1921 std::list<ResultPtr> allRes;
1922 ModelAPI_Tools::allSubs(aCompRes, allRes);
1923 if (allRes.empty()) {
1924 anAllProcessedObjects.insert(anObject);
1926 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
1927 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
1928 if (aBody.get() && aBody->numberOfSubs() == 0)
1929 anAllProcessedObjects.insert(aBody);
1933 anAllProcessedObjects.insert(anObject);
1936 // find hidden objects in faces panel
1937 std::set<ObjectPtr> aHiddenObjects;
1938 QStringList aHiddenObjectNames;
1939 for (std::set<ObjectPtr>::const_iterator anObjectsIt = anAllProcessedObjects.begin();
1940 anObjectsIt != anAllProcessedObjects.end(); anObjectsIt++) {
1941 if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
1943 aHiddenObjects.insert(*anObjectsIt);
1944 aHiddenObjectNames.append(QString::fromStdWString((*anObjectsIt)->data()->name()));
1946 if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face
1949 int anAnswer = QMessageBox::question(
1950 desktop(), tr("Show object"),
1951 tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?")
1952 .arg(aHiddenObjectNames.join(", ")).arg(facesPanel()->windowTitle()),
1953 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1955 bool aToBeDisplayed = anAnswer == QMessageBox::Yes;
1957 facesPanel()->restoreObjects(aHiddenObjects);
1959 return aToBeDisplayed;
1962 //**************************************************************
1963 void XGUI_Workshop::deleteObjects()
1965 ModuleBase_IModule* aModule = module();
1966 // allow the module to delete objects, do nothing if it has succeed
1967 if (aModule->deleteObjects()) {
1968 updateCommandStatus();
1969 myDisplayer->updateViewer();
1973 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1974 if (anObjects.isEmpty())
1977 if (!abortAllOperations())
1980 bool hasResult = false;
1981 bool hasFeature = false;
1982 bool hasParameter = false;
1983 bool hasCompositeOwner = false;
1984 bool hasResultInHistory = false;
1985 bool hasFolder = false;
1986 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1987 hasResultInHistory, hasFolder);
1988 if (!(hasResult || hasFeature || hasParameter || hasFolder))
1991 // Remove from the list non-deletable objects: infinite constructions which are not in history
1992 bool notDelete = true;
1993 QObjectPtrList::iterator aIt;
1994 for (aIt = anObjects.begin(); aIt != anObjects.end(); aIt++) {
1995 ObjectPtr aObj = (*aIt);
1996 ResultConstructionPtr aConstr = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
1997 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1999 notDelete = (!aFeature->isInHistory()) && (aConstr && aConstr->isInfinite());
2001 anObjects.removeAll(aObj);
2007 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
2008 std::set<FeaturePtr> aFeatures;
2009 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
2010 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
2012 std::set<FolderPtr> aFolders;
2013 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
2016 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
2017 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
2018 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, module());
2020 operationMgr()->startOperation(anOpAction);
2022 std::set<FeaturePtr> aFeatureRefsToDelete;
2023 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
2024 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
2025 // It is necessary to clear selection in order to avoid selection changed event during
2026 // deletion and negative consequences connected with processing of already deleted items
2027 mySelector->clearSelection();
2029 if (!aFeatureRefsToDelete.empty())
2030 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
2031 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
2033 if (aFolders.size() > 0) {
2034 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
2035 aLast = aFolders.end();
2036 for (; anIt != aLast; anIt++) {
2037 FolderPtr aFolder = *anIt;
2038 if (aFolder.get()) {
2039 DocumentPtr aDoc = aFolder->document();
2040 aDoc->removeFolder(aFolder);
2044 // remove results selected
2045 std::list<ResultPtr> aResults;
2046 for(QObjectPtrList::const_iterator anIt = anObjects.begin(); anIt != anObjects.end(); anIt++) {
2047 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*anIt);
2048 if (aRes.get() && aRes->data()->isValid() && !aRes->data()->isDeleted() &&
2049 aRes->groupName() != ModelAPI_ResultGroup::group() && // don't remove groups and fields
2050 aRes->groupName() != ModelAPI_ResultField::group()) // because they are badly selected
2051 aResults.push_back(aRes);
2053 if (!aResults.empty()) {
2054 ModelAPI_Tools::removeResults(aResults);
2058 operationMgr()->commitOperation();
2060 operationMgr()->abortOperation(operationMgr()->currentOperation());
2062 myDisplayer->updateViewer();
2065 //**************************************************************
2066 void addRefsToFeature(const FeaturePtr& theFeature,
2067 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
2068 std::set<FeaturePtr>& theReferences)
2070 //if (theReferences.find(theFeature) != theReferences.end())
2072 if (theMainList.find(theFeature) == theMainList.end())
2073 return; // this feature is not in the selection list, so exists without references to it
2074 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
2076 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
2077 aLast = aMainReferences.end();
2078 for (; anIt != aLast; anIt++) {
2079 FeaturePtr aRefFeature = *anIt;
2080 if (theReferences.find(aRefFeature) == theReferences.end())
2081 theReferences.insert(aRefFeature);
2082 addRefsToFeature(aRefFeature, theMainList, theReferences);
2086 //**************************************************************
2087 void XGUI_Workshop::cleanHistory()
2089 if (!abortAllOperations())
2092 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2093 std::set<FeaturePtr> aFeatures;
2094 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
2096 #ifdef DEBUG_CLEAN_HISTORY
2098 std::set<FeaturePtr>::const_iterator aFIt;
2099 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
2100 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
2101 anInfo.append(aFeature->name().c_str());
2103 QString anInfoStr = anInfo.join(";\t");
2104 qDebug(QString("cleanHistory for: [%1] - %2").
2105 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
2108 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
2109 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
2110 // find for each object whether all reference values are in the map as key, that means that there
2111 // is no other reference in the model to this object, so it might be removed by cleaning history
2112 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - can't be deleted, dependency to bool_1
2113 // ext_1(bool_1, sk_3) - can't be deleted, dependency to bool_1
2115 // sk_2(ext_2) + (bool_1) - can't be deleted, dependency to bool_1
2116 // ext_2(bool_1) - can't be deleted, dependency to bool_1
2118 // Information: bool_1 is not selected
2119 std::set<FeaturePtr> anUnusedObjects;
2120 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
2121 aMainLast = aReferences.end();
2122 for (; aMainIt != aMainLast; aMainIt++) {
2123 FeaturePtr aMainListFeature = aMainIt->first;
2124 std::set<FeaturePtr> aMainRefList = aMainIt->second;
2125 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
2126 aRefLast = aMainRefList.end();
2127 bool aFeatureOutOfTheList = false;
2128 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
2129 FeaturePtr aRefFeature = *aRefIt;
2130 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
2132 if (!aFeatureOutOfTheList)
2133 anUnusedObjects.insert(aMainListFeature);
2136 #ifdef DEBUG_CLEAN_HISTORY
2138 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
2139 FeaturePtr aFeature = *aFIt;
2140 anInfo.append(aFeature->name().c_str());
2142 qDebug(QString("unused objects: [%1] - %2").
2143 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
2146 // warn about the references remove, break the delete operation if the user chose it
2147 if (!anUnusedObjects.empty()) {
2149 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
2150 aNames.append(QString::fromStdWString(aFeature->name()));
2153 QString anUnusedNames = aNames.join(", ");
2155 QString anActionId = "CLEAN_HISTORY_CMD";
2156 QString aDescription = ModuleBase_Tools::translate("workshop",
2157 contextMenuMgr()->action(anActionId)->text().toStdString());
2159 QMessageBox aMessageBox(desktop());
2160 aMessageBox.setWindowTitle(aDescription);
2161 aMessageBox.setIcon(QMessageBox::Warning);
2162 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
2163 aMessageBox.setDefaultButton(QMessageBox::No);
2165 const char* aKeyStr = "Unused features are the following: "
2166 "%1.\nThese features will be deleted.\nWould you like to continue?";
2167 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
2168 aMessageBox.setText(aText);
2169 if (aMessageBox.exec() == QMessageBox::No)
2172 // 1. start operation
2173 aDescription += "by deleting of " +
2174 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
2175 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, module());
2176 operationMgr()->startOperation(anOpAction);
2178 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
2179 // It is necessary to clear selection in order to avoid selection changed event during
2180 // deletion and negative consequences connected with processing of already deleted items
2181 mySelector->clearSelection();
2183 std::set<FeaturePtr> anIgnoredFeatures;
2184 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
2185 operationMgr()->commitOperation();
2188 operationMgr()->abortOperation(operationMgr()->currentOperation());
2192 QString anActionId = "CLEAN_HISTORY_CMD";
2193 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2195 QMessageBox aMessageBox(desktop());
2196 aMessageBox.setWindowTitle(aDescription);
2197 aMessageBox.setIcon(QMessageBox::Warning);
2198 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
2199 aMessageBox.setDefaultButton(QMessageBox::No);
2202 aMessageBox.setStandardButtons(QMessageBox::Ok);
2203 aMessageBox.setDefaultButton(QMessageBox::Ok);
2205 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
2206 aMessageBox.setText(aText);
2208 if (aMessageBox.exec() == QMessageBox::No)
2213 //**************************************************************
2214 bool compareFeature(const FeaturePtr& theF1, const FeaturePtr& theF2) {
2215 DocumentPtr aDoc = theF1->document();
2216 return aDoc->index(theF1) < aDoc->index(theF2);
2218 void XGUI_Workshop::moveObjects(const bool theSplit)
2220 if (!abortAllOperations())
2223 SessionPtr aMgr = ModelAPI_Session::get();
2225 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2226 // It is necessary to clear selection in order to avoid selection changed event during
2227 // moving and negative consequences connected with processing of already moved items
2228 mySelector->clearSelection();
2229 // check whether the object can be moved. There should not be parts which are not loaded
2230 std::set<FeaturePtr> aFeatures;
2231 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
2232 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
2235 QString anActionId = theSplit ? "MOVE_CMD" : "MOVE_SPLIT_CMD";
2236 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2237 aMgr->startOperation(aDescription.toStdString());
2239 // Sort features by index in document
2240 std::list<FeaturePtr> aFList(aFeatures.begin(), aFeatures.end());
2241 aFList.sort(compareFeature);
2243 DocumentPtr anActiveDocument = aMgr->activeDocument();
2244 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
2245 std::list<FeaturePtr>::const_iterator anIt = aFList.begin(), aLast = aFList.end();
2246 for (; anIt != aLast; anIt++) {
2247 FeaturePtr aFeature = *anIt;
2248 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
2251 anActiveDocument->moveFeature(aFeature, aCurrentFeature, theSplit);
2252 aCurrentFeature = anActiveDocument->currentFeature(true);
2254 aMgr->finishOperation();
2255 updateCommandStatus();
2256 myViewerProxy->update();
2259 //**************************************************************
2260 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
2262 std::set<FeaturePtr> aFeatures;
2263 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
2265 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
2268 //******************************************************
2269 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
2271 bool isFoundResultType = false;
2272 foreach(ObjectPtr anObj, theObjects)
2274 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2275 if (aResult.get() == NULL)
2278 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
2279 if (isFoundResultType)
2282 return isFoundResultType;
2285 //**************************************************************
2286 // Returns the list of all features for theDocument and all features of
2287 // all nested parts.
2288 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
2290 std::list<FeaturePtr> aResultList;
2291 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
2292 foreach (const FeaturePtr& aFeature, anAllFeatures) {
2293 // The order of appending features of the part and the part itself is important
2295 // Append features from a part feature
2296 std::list<ResultPtr> aResults;
2297 ModelAPI_Tools::allResults(aFeature, aResults);
2298 foreach (const ResultPtr& aResult, aResults) {
2299 ResultPartPtr aResultPart =
2300 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
2301 if (aResultPart.get() && aResultPart->partDoc().get()) {
2303 std::list<FeaturePtr> aPartFeatures = allFeatures(aResultPart->partDoc());
2304 aResultList.insert(aResultList.end(), aPartFeatures.begin(), aPartFeatures.end());
2308 aResultList.push_back(aFeature);
2313 //**************************************************************
2314 // Returns the list of features placed between theObject and the current feature
2315 // in the same document. Excludes theObject, includes the current feature.
2316 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
2318 std::list<FeaturePtr> aResult;
2319 DocumentPtr aDocument = theObject->document();
2320 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
2321 // find the object iterator
2322 std::list<FeaturePtr>::iterator anObjectIt =
2323 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
2324 if (anObjectIt == anAllFeatures.end())
2326 // find the current feature iterator
2327 std::list<FeaturePtr>::iterator aCurrentIt =
2328 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
2329 if (aCurrentIt == anAllFeatures.end())
2331 // check the right order
2332 if (std::distance(anObjectIt, anAllFeatures.end()) <=
2333 std::distance(aCurrentIt, anAllFeatures.end()))
2335 // exclude the object
2336 std::advance(anObjectIt, 1);
2337 // include the current feature
2338 std::advance(aCurrentIt, 1);
2339 return std::list<FeaturePtr>(anObjectIt, aCurrentIt);
2342 //******************************************************
2343 bool XGUI_Workshop::canMoveFeature()
2345 QString anActionId = "MOVE_CMD";
2347 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2348 QObjectPtrList aValidatedObjects;
2349 foreach (ObjectPtr anObject, anObjects) {
2350 if (!myModule->canApplyAction(anObject, anActionId))
2352 // To be moved feature should be in active document
2353 if (anObject->document() != ModelAPI_Session::get()->activeDocument())
2355 aValidatedObjects.append(anObject);
2357 if (aValidatedObjects.size() != anObjects.size())
2358 anObjects = aValidatedObjects;
2360 bool aCanMove = !anObjects.empty();
2362 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
2363 for (; anIt != aLast && aCanMove; anIt++) {
2364 ObjectPtr anObject = *anIt;
2365 if (!anObject.get() || !anObject->data().get() || !anObject->data()->isValid()) {
2369 FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
2370 // only groups can be moved to the end for now (#2451)
2371 if (aFeat.get() && aFeat->getKind() != "Group") {
2376 // 1. Get features placed between selected and current in the document
2377 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(anObject);
2378 // if aFeaturesBetween is empty it means wrong order or anObject is the current feature
2379 if (aFeaturesBetween.empty())
2382 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2383 // 2. Get all reference features to the selected object in the document
2384 std::set<FeaturePtr> aRefFeatures;
2385 ModuleBase_Tools::refsToFeatureInFeatureDocument(anObject, aRefFeatures);
2387 if (aRefFeatures.empty())
2390 // 3. Find any placed features in all reference features
2391 std::set<FeaturePtr> aIntersectionFeatures;
2392 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2393 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2394 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2395 // 4. Return false if any reference feature is placed before current feature
2396 if (!aIntersectionFeatures.empty())
2404 //**************************************************************
2405 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2407 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2408 if (!aCanBeShaded) {
2409 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
2410 if (aCompRes.get() != NULL) { // change colors for all sub-solids
2411 std::list<ResultPtr> allRes;
2412 ModelAPI_Tools::allSubs(aCompRes, allRes);
2413 std::list<ResultPtr>::iterator aRes = allRes.begin();
2414 for(; aRes != allRes.end() && !aCanBeShaded; aRes++) {
2415 aCanBeShaded = myDisplayer->canBeShaded(*aRes);
2419 return aCanBeShaded;
2422 //**************************************************************
2423 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2425 if (theActionName == "COLOR_CMD" ||
2426 theActionName == "DEFLECTION_CMD" ||
2427 theActionName == "TRANSPARENCY_CMD") {
2428 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2430 std::set<std::string> aTypes;
2431 aTypes.insert(ModelAPI_ResultGroup::group());
2432 aTypes.insert(ModelAPI_ResultConstruction::group());
2433 aTypes.insert(ModelAPI_ResultBody::group());
2434 aTypes.insert(ModelAPI_ResultPart::group());
2436 return hasResults(anObjects, aTypes);
2438 if (theActionName == "AUTOCOLOR_CMD") {
2440 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2442 std::set<std::string> aTypes;
2443 aTypes.insert(ModelAPI_ResultGroup::group());
2445 return hasResults(anObjects, aTypes);
2451 //**************************************************************
2452 void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
2453 std::vector<int>& theColor)
2456 // get default color from the preferences manager for the given result
2457 if (theColor.empty()) {
2458 std::string aSection, aName, aDefault;
2459 theObject->colorConfigInfo(aSection, aName, aDefault);
2460 if (!aSection.empty() && !aName.empty()) {
2461 theColor = Config_PropManager::color(aSection, aName);
2464 if (!isEmptyColorValid && theColor.empty()) {
2465 // all AIS objects, where the color is not set, are in black.
2466 // The color should be defined in XML or set in the attribute
2467 theColor = Config_PropManager::color("Visualization", "object_default_color");
2468 Events_InfoMessage("XGUI_CustomPrs",
2469 "A default color is not defined in the preferences for this kind of result").send();
2473 //**************************************************************
2474 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2477 AttributeIntArrayPtr aColorAttr;
2478 // 1. find the current color of the object. This is a color of AIS presentation
2479 // The objects are iterated until a first valid color is found
2480 std::vector<int> aColor;
2481 foreach(ObjectPtr anObject, theObjects) {
2482 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2483 if (aResult.get()) {
2484 ModelAPI_Tools::getColor(aResult, aColor);
2485 if (aColor.empty()) {
2486 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2487 if (anAISObj.get()) {
2489 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2492 if (aColor.empty()) {
2493 getDefaultColor(aResult, false, aColor);
2497 if (aColor.size() != 3)
2500 if (!abortAllOperations())
2502 // 2. show the dialog to change the value
2503 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2504 aDlg->setColor(aColor);
2505 aDlg->move(QCursor::pos());
2506 bool isDone = aDlg->exec() == QDialog::Accepted;
2510 bool isRandomColor = aDlg->isRandomColor();
2512 // 3. abort the previous operation and start a new one
2513 SessionPtr aMgr = ModelAPI_Session::get();
2514 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2516 aMgr->startOperation(aDescription.toStdString());
2518 // 4. set the value to all results
2519 std::vector<int> aColorResult = aDlg->getColor();
2520 foreach(ObjectPtr anObj, theObjects) {
2521 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2522 if (aResult.get() != NULL) {
2523 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2524 if (aBodyResult.get() != NULL) { // change colors for all sub-solids
2525 std::list<ResultPtr> allRes;
2526 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2527 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2528 ModelAPI_Tools::setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2531 ModelAPI_Tools::setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2534 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2535 aMgr->finishOperation();
2536 updateCommandStatus();
2537 myViewerProxy->update();
2540 //**************************************************************
2541 void XGUI_Workshop::changeAutoColor(const QObjectPtrList& theObjects)
2543 if (!abortAllOperations())
2546 std::vector<int> aColor;
2548 // abort the previous operation and start a new one
2549 SessionPtr aMgr = ModelAPI_Session::get();
2550 QString aDescription = contextMenuMgr()->action("AUTOCOLOR_CMD")->text();
2551 aMgr->startOperation(aDescription.toStdString());
2553 if (Config_PropManager::getAutoColorStatus()) {
2554 contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Auto color"));
2555 Config_PropManager::setAutoColorStatus(false);
2556 ModelAPI_Tools::findRandomColor(aColor, true);
2558 // set the value to all results
2559 foreach (ObjectPtr anObj, theObjects) {
2560 DocumentPtr aDocument = anObj->document();
2561 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
2562 // find the object iterator
2563 std::list<FeaturePtr>::iterator anObjectIt = anAllFeatures.begin();
2564 for (; anObjectIt != anAllFeatures.end(); ++ anObjectIt) {
2565 FeaturePtr aFeature = *anObjectIt;
2566 if (aFeature.get()) {
2567 std::list<ResultPtr> aResults;
2568 ModelAPI_Tools::allResults(aFeature, aResults);
2569 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2570 for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2571 ResultPtr aGroupResult = *aIt;
2572 if (aGroupResult.get() &&
2573 aGroupResult->groupName() == ModelAPI_ResultGroup::group()) {
2574 ModelAPI_Tools::findRandomColor(aColor);
2575 ModelAPI_Tools::setColor(aGroupResult, aColor);
2581 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2582 aMgr->finishOperation();
2583 updateCommandStatus();
2584 myViewerProxy->update();
2585 contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Disable auto color"));
2586 Config_PropManager::setAutoColorStatus(true);
2590 //**************************************************************
2591 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2593 foreach(ObjectPtr anObj, theObjects) {
2594 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2595 if (aResult.get() != NULL) {
2596 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2597 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2598 std::list<ResultPtr> allRes;
2599 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2600 std::list<ResultPtr>::iterator aRes;
2601 for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2602 ModelAPI_Tools::setTransparency(*aRes, theTransparency);
2605 ModelAPI_Tools::setTransparency(aResult, theTransparency);
2610 //**************************************************************
2611 double getDefaultDeflection(const ObjectPtr& theObject)
2613 double aDeflection = -1;
2614 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
2615 if (aResult.get()) {
2616 bool isConstruction = false;
2618 std::string aResultGroup = aResult->groupName();
2619 if (aResultGroup == ModelAPI_ResultConstruction::group())
2620 isConstruction = true;
2621 else if (aResultGroup == ModelAPI_ResultBody::group()) {
2622 GeomShapePtr aGeomShape = aResult->shape();
2623 if (aGeomShape.get()) {
2624 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
2625 // correction of deviation for them should not influence to the application performance
2626 GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
2627 isConstruction = !anExp.more();
2631 aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
2633 aDeflection = Config_PropManager::real("Visualization", "body_deflection");
2638 //**************************************************************
2639 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2641 AttributeDoublePtr aDoubleAttr;
2642 // 1. find the current property of the object. This is a property of AIS presentation
2643 // The objects are iterated until a first valid property is found
2644 double aDeflection = -1;
2645 foreach(ObjectPtr anObject, theObjects) {
2646 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2647 if (aResult.get()) {
2648 aDeflection = ModelAPI_Tools::getDeflection(aResult);
2649 if (aDeflection < 0)
2650 aDeflection = getDefaultDeflection(aResult);
2653 // TODO: remove the obtaining a property from the AIS object
2654 // this does not happen never because:
2655 // 1. The property can be changed only on results
2656 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2657 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2658 if (anAISObj.get()) {
2659 aDeflection = anAISObj->getDeflection();
2662 if (aDeflection > 0)
2665 if (aDeflection < 0)
2668 if (!abortAllOperations())
2670 // 2. show the dialog to change the value
2671 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2672 aDlg->setDeflection(aDeflection);
2673 aDlg->move(QCursor::pos());
2674 bool isDone = aDlg->exec() == QDialog::Accepted;
2678 // 3. abort the previous operation and start a new one
2679 SessionPtr aMgr = ModelAPI_Session::get();
2680 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2681 aMgr->startOperation(aDescription.toStdString());
2683 // 4. set the value to all results
2684 aDeflection = aDlg->getDeflection();
2685 foreach(ObjectPtr anObj, theObjects) {
2686 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2687 if (aResult.get() != NULL) {
2688 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2689 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2690 std::list<ResultPtr> allRes;
2691 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2692 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2693 ModelAPI_Tools::setDeflection(*aRes, aDeflection);
2696 ModelAPI_Tools::setDeflection(aResult, aDeflection);
2699 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2700 aMgr->finishOperation();
2701 updateCommandStatus();
2704 //**************************************************************
2705 double getDefaultTransparency(const ResultPtr& theResult)
2707 return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.;
2710 //**************************************************************
2711 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2713 AttributeDoublePtr aDoubleAttr;
2714 // 1. find the current property of the object. This is a property of AIS presentation
2715 // The objects are iterated until a first valid property is found
2716 double aCurrentValue = -1;
2717 foreach(ObjectPtr anObject, theObjects) {
2718 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2719 if (aResult.get()) {
2720 aCurrentValue = ModelAPI_Tools::getTransparency(aResult);
2721 if (aCurrentValue < 0)
2722 aCurrentValue = getDefaultTransparency(aResult);
2724 if (aCurrentValue > 0)
2727 if (aCurrentValue < 0)
2730 if (!abortAllOperations())
2733 // 2. show the dialog to change the value
2734 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2735 aDlg->setWindowTitle(tr("Transparency"));
2736 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2737 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2738 this, SLOT(onTransparencyValueChanged()));
2739 aDlg->setContent(aTransparencyWidget);
2740 aTransparencyWidget->setValue(aCurrentValue);
2742 // 3. abort the previous operation and start a new one
2743 SessionPtr aMgr = ModelAPI_Session::get();
2744 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2745 aMgr->startOperation(aDescription.toStdString());
2747 if (aDlg->exec() == QDialog::Accepted) {
2748 // 4. set the value to all results
2749 aCurrentValue = aTransparencyWidget->getValue();
2750 setTransparency(aCurrentValue, theObjects);
2751 aMgr->finishOperation();
2753 aMgr->abortOperation();
2754 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2757 updateCommandStatus();
2760 //**************************************************************
2761 void XGUI_Workshop::onTransparencyValueChanged()
2763 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2764 if (!aTransparencyWidget)
2767 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2768 setTransparency(aTransparencyWidget->getValue(), anObjects);
2769 static const Events_ID kRedisplayEvent =
2770 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2771 Events_Loop::loop()->flush(kRedisplayEvent);
2773 myViewerProxy->update();
2777 //******************************************************
2778 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2781 std::set<ObjectPtr> anObjects;
2782 foreach (ObjectPtr aObj, theList) {
2783 anObjects.insert(aObj);
2785 if (!prepareForDisplay(anObjects))
2789 foreach (ObjectPtr aObj, theList) {
2790 aObj->setDisplayed(isVisible);
2792 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2793 myObjectBrowser->updateAllIndexes();
2795 updateColorScaleVisibility();
2796 displayer()->updateViewer();
2799 //**************************************************************
2800 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2802 QObjectPtrList aSrcList = theList;
2803 // Hide all displayed objects
2804 QObjectPtrList aList = myDisplayer->displayedObjects();
2805 foreach (ObjectPtr aObj, aList) {
2806 if ((!aSrcList.contains(aObj)) && (module()->canEraseObject(aObj)))
2807 aObj->setDisplayed(false);
2809 aSrcList.removeAll(aObj);
2811 //Do not use eraseAll if you didn't send Redisplay event:
2812 //all objects are erased from viewer, but considered as displayed in displayer
2813 // Problem in bug 2218
2814 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2816 //issue #2159 Hide all incomplete behavior
2817 viewer()->eraseAll();
2820 std::set<ObjectPtr> anObjects;
2821 foreach (ObjectPtr aObj, aSrcList) {
2822 anObjects.insert(aObj);
2825 if (!prepareForDisplay(anObjects))
2828 // Show only objects from the list
2829 foreach (ObjectPtr aObj, aSrcList) {
2830 aObj->setDisplayed(true);
2832 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2834 // Necessary for update icons in ObjectBrowser on Linux
2835 myObjectBrowser->updateAllIndexes();
2836 updateColorScaleVisibility();
2837 displayer()->updateViewer();
2841 //**************************************************************
2842 void XGUI_Workshop::updateColorScaleVisibility()
2844 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2845 viewer()->setColorScaleShown(false);
2846 if (anObjects.size() == 1) {
2847 FieldStepPtr aStep =
2848 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(anObjects.first());
2849 if (aStep.get() && myDisplayer->isVisible(aStep)) {
2850 AISObjectPtr aAisPtr = myDisplayer->getAISObject(aStep);
2851 Handle(AIS_InteractiveObject) aIO = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2852 ModuleBase_IStepPrs* aPrs = dynamic_cast<ModuleBase_IStepPrs*>(aIO.get());
2854 ModelAPI_AttributeTables::ValueType aType = aPrs->dataType();
2855 if ((aType == ModelAPI_AttributeTables::DOUBLE) ||
2856 (aType == ModelAPI_AttributeTables::INTEGER) ||
2857 (aType == ModelAPI_AttributeTables::BOOLEAN)) {
2858 myViewerProxy->setupColorScale();
2859 if (aType == ModelAPI_AttributeTables::BOOLEAN) {
2860 myViewerProxy->setColorScaleIntervals(2);
2861 myViewerProxy->setColorScaleRange(0., 1.);
2865 aPrs->dataRange(aMin, aMax);
2866 myViewerProxy->setColorScaleRange(aMin, aMax);
2868 myViewerProxy->setColorScaleTitle(QString::fromStdWString(aStep->name()));
2869 myViewerProxy->setColorScaleShown(true);
2877 //**************************************************************
2878 void XGUI_Workshop::setNormalView(bool toInvert)
2880 QList<ModuleBase_ViewerPrsPtr> aPrsList =
2881 mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
2882 GeomShapePtr aPlanarFace;
2883 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
2884 GeomShapePtr aShape = aPrs->shape();
2885 if (aShape.get() && aShape->isFace() && aShape->isPlanar()) {
2886 aPlanarFace = aShape;
2890 if (aPlanarFace.get()) {
2891 GeomFacePtr aFace(new GeomAPI_Face(aPlanarFace));
2892 GeomPlanePtr aPlane = aFace->getPlane();
2893 GeomDirPtr aNormal = aPlane->direction();
2896 GeomPointPtr aPos = aPlane->location();
2898 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2899 aFace->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2901 Handle(V3d_View) aView = myViewerProxy->activeView();
2902 aView->SetAt(aPos->x(), aPos->y(), aPos->z());
2903 aView->SetProj(aNormal->x(), aNormal->y(), aNormal->z());
2905 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2906 aView->FitAll(aBox);
2910 //**************************************************************
2911 void XGUI_Workshop::registerValidators() const
2913 SessionPtr aMgr = ModelAPI_Session::get();
2914 MAYBE_UNUSED ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2917 //**************************************************************
2918 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2922 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2923 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2926 //**************************************************************
2927 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2929 for (int i = 0; i < theDoc->size(theGroup); i++)
2930 theDoc->object(theGroup, i)->setDisplayed(true);
2931 //displayObject(theDoc->object(theGroup, i));
2932 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2935 //**************************************************************
2936 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2938 foreach(ObjectPtr anObj, theList) {
2939 myDisplayer->setDisplayMode(anObj, (XGUI_Displayer::DisplayMode)theMode, false);
2941 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
2942 if (aBodyResult.get() != NULL) { // change display mode for all sub-solids
2943 std::list<ResultPtr> allRes;
2944 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2945 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2946 myDisplayer->setDisplayMode(*aRes, (XGUI_Displayer::DisplayMode)theMode, false);
2950 if (theList.size() > 0)
2951 myDisplayer->updateViewer();
2954 //**************************************************************
2955 void XGUI_Workshop::closeDocument()
2957 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2958 while (anOperation) {
2959 anOperation->abort();
2960 anOperation = operationMgr()->currentOperation();
2962 //myDisplayer->closeLocalContexts();
2963 myDisplayer->eraseAll();
2964 objectBrowser()->clearContent();
2966 module()->closeDocument();
2967 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2968 module()->clearViewer();
2971 // data model need not process the document's signals about objects modifications as
2972 // the document is closed
2973 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2975 SessionPtr aMgr = ModelAPI_Session::get();
2978 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2981 //******************************************************
2982 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2984 XGUI_HistoryMenu* aMenu = NULL;
2985 if (isSalomeMode()) {
2986 QAction* anAction = qobject_cast<QAction*>(theObject);
2989 aMenu = new XGUI_HistoryMenu(anAction);
2991 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2992 aMenu = new XGUI_HistoryMenu(aButton);
2994 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2995 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2998 //******************************************************
2999 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
3001 QList<ActionInfo> aResult;
3002 std::list<std::string>::const_iterator it = theList.cbegin();
3003 for (; it != theList.cend(); it++) {
3004 QString anId = QString::fromStdString(*it);
3005 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
3007 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
3010 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
3011 if (aContextMenuAct) {
3012 anInfo.initFrom(aContextMenuAct);
3014 anInfo = myActionsMgr->actionInfoById(anId);
3017 anInfo.text = anInfo.text.prepend("Modify ");
3024 //******************************************************
3025 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
3028 salomeConnector()->putInfo(theMessage, -1);
3030 myMainWindow->putInfo(theMessage, -1);
3035 //******************************************************
3036 void XGUI_Workshop::synchronizeViewer()
3038 SessionPtr aMgr = ModelAPI_Session::get();
3039 QList<DocumentPtr> aDocs;
3040 aDocs.append(aMgr->activeDocument());
3041 aDocs.append(aMgr->moduleDocument());
3043 foreach(DocumentPtr aDoc, aDocs) {
3044 synchronizeGroupInViewer(aDoc, false);
3048 //******************************************************
3049 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
3050 bool theUpdateViewer)
3052 FeaturePtr aFeature;
3054 int aSize = theDoc->numInternalFeatures();
3055 for (int i = 0; i < aSize; i++) {
3056 aFeature = theDoc->internalFeature(i);
3057 if (!aFeature.get())
3059 const std::list<ResultPtr>& aResults = aFeature->results();
3060 std::list<ResultPtr>::const_iterator aIt;
3061 aFeature->setDisplayed(false);
3062 for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
3064 if (aRes->isDisplayed() && !aRes->isConcealed()) {
3065 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
3066 // be changed to the object becomes visible when the shape becomes not empty
3067 if (!aRes->shape().get() || aRes->shape()->isNull())
3069 ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aRes);
3071 synchronizeResultTree(aResBody, false);
3073 if (aRes->isInHistory()) {
3074 if (aRes->isDisplayed())
3075 myDisplayer->display(aRes, false);
3077 myDisplayer->erase(aRes, false);
3080 aRes->setDisplayed(false);
3085 if (theUpdateViewer)
3086 myDisplayer->updateViewer();
3089 void XGUI_Workshop::synchronizeResultTree(const ResultBodyPtr& theRes, bool theUpdateViewer)
3091 if (theRes->numberOfSubs() > 0)
3092 for (int i = 0; i < theRes->numberOfSubs(); i++) {
3093 ResultBodyPtr aRes = theRes->subResult(i);
3095 synchronizeResultTree(aRes, theUpdateViewer);
3098 if (theRes->isDisplayed())
3099 myDisplayer->display(theRes, theUpdateViewer);
3101 myDisplayer->erase(theRes, theUpdateViewer);
3106 //******************************************************
3107 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
3109 FeaturePtr aFeature;
3110 QObjectPtrList aSelList = theObjects;
3111 QObjectPtrList aNewSel;
3112 bool aHasHidden = false;
3113 foreach(ObjectPtr aObj, theObjects) {
3114 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
3115 if (aFeature.get()) {
3116 std::list<ResultPtr> aResults;
3117 ModelAPI_Tools::allResults(aFeature, aResults);
3118 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
3119 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
3120 aHasHidden |= (*aIt)->isConcealed();
3121 aSelList.append(*aIt);
3122 aNewSel.append(*aIt);
3126 if (aSelList.count() > theObjects.count()) {
3127 // if something was found
3128 objectBrowser()->setObjectsSelected(aSelList);
3129 objectBrowser()->ensureVisible(aNewSel.first());
3132 QMessageBox::information(desktop(), tr("Find results"),
3133 tr("Results not found"), QMessageBox::Ok);
3136 //******************************************************
3137 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
3140 QObjectPtrList aSelList = theObjects;
3141 QObjectPtrList aNewSel;
3142 FeaturePtr aFeature;
3143 foreach(ObjectPtr aObj, theObjects) {
3144 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
3145 if (aResult.get()) {
3146 aFeature = ModelAPI_Feature::feature(aResult);
3147 if (aFeature.get()) {
3148 aSelList.append(aFeature);
3149 aNewSel.append(aFeature);
3153 if (aSelList.count() > theObjects.count()) {
3154 // if something was found
3155 objectBrowser()->setObjectsSelected(aSelList);
3156 objectBrowser()->ensureVisible(aNewSel.first());
3160 void XGUI_Workshop::insertFeatureFolder()
3162 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
3163 if (anObjects.isEmpty())
3165 ObjectPtr aObj = anObjects.first();
3166 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
3167 if (aFeature.get() == NULL)
3169 SessionPtr aMgr = ModelAPI_Session::get();
3170 DocumentPtr aDoc = aMgr->activeDocument();
3172 QString aDescription = contextMenuMgr()->action("INSERT_FOLDER_CMD")->text();
3174 aMgr->startOperation(aDescription.toStdString());
3175 aDoc->addFolder(aFeature);
3176 aMgr->finishOperation();
3178 updateCommandStatus();
3182 void XGUI_Workshop::insertToFolder(bool isBefore)
3184 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
3185 if (aFeatures.empty())
3188 SessionPtr aMgr = ModelAPI_Session::get();
3189 DocumentPtr aDoc = aMgr->activeDocument();
3191 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
3192 aDoc->findFolderBelow(aFeatures);
3196 QString aDescription = contextMenuMgr()->action(
3197 isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text();
3199 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
3201 aMgr->startOperation(aDescription.toStdString());
3202 aDoc->moveToFolder(aFeatures, aFolder);
3203 aMgr->finishOperation();
3205 myObjectBrowser->setFoldersState(aStates);
3207 updateCommandStatus();
3210 void XGUI_Workshop::moveOutFolder(bool isBefore)
3212 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
3213 if (aFeatures.empty())
3216 SessionPtr aMgr = ModelAPI_Session::get();
3217 DocumentPtr aDoc = aMgr->activeDocument();
3219 QString aDescription = contextMenuMgr()->action(
3220 isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text();
3222 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
3224 aMgr->startOperation(aDescription.toStdString());
3225 aDoc->removeFromFolder(aFeatures, isBefore);
3226 aMgr->finishOperation();
3228 myObjectBrowser->setFoldersState(aStates);
3230 updateCommandStatus();
3233 void XGUI_Workshop::onAutoApply()
3235 SessionPtr aMgr = ModelAPI_Session::get();
3236 bool isBlocked = aMgr->isAutoUpdateBlocked();
3237 aMgr->blockAutoUpdate(!isBlocked);
3238 myDisplayer->updateViewer();
3241 void XGUI_Workshop::updateAutoComputeState()
3243 SessionPtr aMgr = ModelAPI_Session::get();
3245 // QAction* aUpdateCmd;
3246 // QList<QAction*> aCommands = mySalomeConnector->commandList();
3247 // foreach(QAction* aCmd, aCommands) {
3248 // if (aCmd->data().toString() == "AUTOCOMPUTE_CMD") {
3249 // aUpdateCmd = aCmd;
3253 // aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
3254 // QIcon(":pictures/autoapply_start.png"));
3256 bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
3257 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
3258 AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD");
3259 aUpdateCmd->button()->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
3260 QIcon(":pictures/autoapply_start.png"));
3265 void XGUI_Workshop::clearTemporaryDir()
3267 QDir aDir(myTmpDir.path());
3268 if (!aDir.isEmpty()) {
3269 QStringList aEntries;
3270 aDir.entryList(aEntries);
3271 foreach(QString aFile, aEntries) {
3278 void XGUI_Workshop::onDockSizeChanged()
3280 QDockWidget* aDockWgt = dynamic_cast<QDockWidget*>(myObjectBrowser->parentWidget());
3281 int aObWidth = aDockWgt->size().width();
3282 if (myPropertyPanel->width() != aObWidth) {
3283 QList<QDockWidget*> aWgtList;
3284 aWgtList << myPropertyPanel << aDockWgt;
3285 QList<int> aSizeList;
3286 aSizeList << aObWidth << aObWidth;
3287 desktop()->resizeDocks(aWgtList, aSizeList, Qt::Horizontal);
3288 disconnect(myObjectBrowser, SIGNAL(sizeChanged()), this, SLOT(onDockSizeChanged()));
3292 void XGUI_Workshop::deactivateCurrentSelector()
3294 myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector());
3297 void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects)
3299 if (theObjects.isEmpty())
3302 QList<ResultPtr> aResultList;
3304 foreach(ObjectPtr aObj, theObjects) {
3305 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
3307 aResultList.append(aRes);
3310 std::vector<int> aValues;
3312 if (aResultList.size() == 1) {
3313 ResultPtr aResult = aResultList.first();
3315 ModelAPI_Tools::getIsoLines(aResult, isVisible, aValues);
3319 if (aValues.size() == 0) {
3320 aValues.push_back(1);
3321 aValues.push_back(1);
3324 if (!abortAllOperations())
3327 XGUI_PropertyDialog aDlg(desktop());
3328 aDlg.setWindowTitle(tr("Number of Iso-lines"));
3330 QWidget* aIsosWgt = new QWidget(&aDlg);
3331 QFormLayout* aLayout = new QFormLayout(aIsosWgt);
3332 ModuleBase_Tools::adjustMargins(aLayout);
3333 aDlg.setContent(aIsosWgt);
3335 QSpinBox* aUNb = new QSpinBox(&aDlg);
3336 aUNb->setValue(aValues[0]);
3337 aLayout->addRow("U:", aUNb);
3339 QSpinBox* aVNb = new QSpinBox(&aDlg);
3340 aVNb->setValue(aValues[1]);
3341 aLayout->addRow("V:", aVNb);
3343 if (aDlg.exec() == QDialog::Accepted) {
3344 SessionPtr aMgr = ModelAPI_Session::get();
3345 QString aDescription = contextMenuMgr()->action("ISOLINES_CMD")->text();
3346 aMgr->startOperation(aDescription.toStdString());
3348 aValues[0] = aUNb->value();
3349 aValues[1] = aVNb->value();
3350 foreach(ResultPtr aResult, aResultList) {
3351 ModelAPI_Tools::setIsoLines(aResult, aValues);
3353 mySelector->clearSelection();
3354 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
3355 aMgr->finishOperation();
3356 updateCommandStatus();