1 // Copyright (C) 2014-2019 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 <AppElements_Button.h>
56 #include <AppElements_Command.h>
57 #include <AppElements_MainMenu.h>
58 #include <AppElements_MainWindow.h>
59 #include <AppElements_MenuGroupPanel.h>
60 #include <AppElements_Viewer.h>
61 #include <AppElements_Workbench.h>
64 #include <Config_XMLReader.h>
66 #include <ModelAPI_AttributeDocRef.h>
67 #include <ModelAPI_AttributeIntArray.h>
68 #include <ModelAPI_AttributeDouble.h>
69 #include <ModelAPI_AttributeString.h>
70 #include <ModelAPI_Data.h>
71 #include <ModelAPI_Events.h>
72 #include <ModelAPI_Feature.h>
73 #include <ModelAPI_Object.h>
74 #include <ModelAPI_ResultBody.h>
75 #include <ModelAPI_ResultConstruction.h>
76 #include <ModelAPI_ResultGroup.h>
77 #include <ModelAPI_ResultParameter.h>
78 #include <ModelAPI_ResultField.h>
79 #include <ModelAPI_Session.h>
80 #include <ModelAPI_Validator.h>
81 #include <ModelAPI_Tools.h>
82 #include <ModelAPI_ResultField.h>
84 //#include <PartSetPlugin_Part.h>
86 #include <Events_Loop.h>
87 #include <Events_InfoMessage.h>
88 #include <Events_LongOp.h>
90 #include <ExchangePlugin_ExportPart.h>
91 #include <ExchangePlugin_ImportPart.h>
93 #include <GeomAPI_Pnt.h>
94 #include <GeomAPI_ShapeExplorer.h>
96 #include <ModuleBase_IModule.h>
97 #include <ModuleBase_IViewer.h>
98 #include <ModuleBase_Operation.h>
99 #include <ModuleBase_OperationDescription.h>
100 #include <ModuleBase_PageBase.h>
101 #include <ModuleBase_Preferences.h>
102 #include <ModuleBase_SelectionValidator.h>
103 #include <ModuleBase_Tools.h>
104 #include <ModuleBase_WidgetFactory.h>
105 #include <ModuleBase_OperationFeature.h>
106 #include <ModuleBase_PagedContainer.h>
107 #include <ModuleBase_WidgetValidated.h>
108 #include <ModuleBase_ModelWidget.h>
109 #include <ModuleBase_ResultPrs.h>
110 #include <ModuleBase_ActionIntParameter.h>
111 #include <ModuleBase_IStepPrs.h>
113 #include <Config_Common.h>
114 #include <Config_FeatureMessage.h>
115 #include <Config_ModuleReader.h>
116 #include <Config_PointerMessage.h>
117 #include <Config_PropManager.h>
118 #include <Config_DataModelReader.h>
119 #include <Config_Translator.h>
120 #include <Config_WidgetAPI.h>
121 #include <Config_Keywords.h>
123 #include <SUIT_ResourceMgr.h>
125 #include <AIS_Trihedron.hxx>
126 #ifdef BEFORE_TRIHEDRON_PATCH
127 #include <AIS_Point.hxx>
128 #include <AIS_Axis.hxx>
131 #include <QApplication>
132 #include <QFileDialog>
133 #include <QMessageBox>
134 #include <QMdiSubWindow>
135 #include <QMainWindow>
136 #include <QPushButton>
137 #include <QDockWidget>
142 #include <QToolButton>
144 #include <QDesktopWidget>
146 #include <QDesktopServices>
151 #include <CDF_Session.hxx>
152 #include <CDF_Application.hxx>
153 #include <inspector/TInspector_Communicator.hxx>
154 #include <inspector/VInspector_CallBack.hxx>
155 static TInspector_Communicator* MyTCommunicator;
156 static Handle(VInspector_CallBack) MyVCallBack;
171 //#define DEBUG_WITH_MESSAGE_REPORT
173 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
174 QString XGUI_Workshop::MOVE_TO_END_SPLIT_COMMAND = QObject::tr("Move to the end and split");
176 //#define DEBUG_DELETE
177 //#define DEBUG_FEATURE_NAME
178 //#define DEBUG_CLEAN_HISTORY
181 static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.cadbld)"));
182 static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)"));
183 static QString MyExtension(".shaper");
185 static QString MyFilter(QObject::tr("CAD Builder files (*.cadbld);;All files (*.*)"));
186 static QString MyFilter2(QObject::tr("CAD Builder files (*.cadbld)"));
187 static QString MyExtension(".cadbld");
190 static QString MyImportPartFilter(QObject::tr("Part files (*.shaperpart);;All files (*.*)"));
193 //******************************************************
194 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
197 mySalomeConnector(theConnector),
199 myInspectionPanel(0),
203 //myViewerSelMode(TopAbs_FACE)
205 mySelector = new XGUI_SelectionMgr(this);
206 myModuleConnector = new XGUI_ModuleConnector(this);
207 myOperationMgr = new XGUI_OperationMgr(this, 0);
208 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
209 // Has to be defined first in order to get errors and messages from other components
210 myEventsListener = new XGUI_WorkshopListener(this);
211 mySelectionActivate = new XGUI_SelectionActivate(aWorkshop);
213 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
215 myMainWindow = new AppElements_MainWindow();
217 bool aCloc = aResMgr->booleanValue("language", "locale", true);
219 QLocale::setDefault( QLocale::c() );
221 QLocale::setDefault( QLocale::system() );
223 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
228 aLangs << "*_en.ts"; // load by default eng translations
229 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
230 if(aCurrLang != "en") {
231 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
234 foreach(QString aLang, aLangs) {
235 QStringList aFilters;
237 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
238 foreach(QString aFileName, aTsFiles) {
239 Config_Translator::load(aFileName.toStdString());
243 myDataModelXMLReader = new Config_DataModelReader();
244 //myDataModelXMLReader->readAll();
246 myDisplayer = new XGUI_Displayer(this);
248 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
250 myActionsMgr = new XGUI_ActionsMgr(this);
251 myActiveControlMgr = new XGUI_ActiveControlMgr(myModuleConnector);
252 myMenuMgr = new XGUI_MenuMgr(this);
253 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
254 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
255 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
256 SLOT(onContextMenuCommand(const QString&, bool)));
258 myViewerProxy = new XGUI_ViewerProxy(this);
259 //connect(myViewerProxy, SIGNAL(selectionChanged()),
260 // myActionsMgr, SLOT(updateOnViewSelection()));
262 myOperationMgr->setWorkshop(aWorkshop);
264 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
266 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
267 SLOT(onOperationResumed(ModuleBase_Operation*)));
268 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
269 SLOT(onOperationStopped(ModuleBase_Operation*)));
270 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
271 SLOT(onOperationCommitted(ModuleBase_Operation*)));
272 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
273 SLOT(onOperationAborted(ModuleBase_Operation*)));
276 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
277 myDisplayer->displayTrihedron(true);
280 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
281 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
283 Config_PropManager::registerProp("Visualization", "selection_color", "Selection color",
284 Config_Prop::Color, "255,255,255");
286 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
287 myViewerSelMode.append(TopAbs_FACE);
288 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
289 myViewerSelMode.append(TopAbs_EDGE);
290 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
291 myViewerSelMode.append(TopAbs_VERTEX);
292 //IMP: an attempt to use result selection with other selection modes
293 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
294 myViewerSelMode.append(TopAbs_COMPSOLID);
297 //******************************************************
298 XGUI_Workshop::~XGUI_Workshop(void)
301 #ifdef MISSED_TRANSLATION
302 // Save Missed translations
303 Config_Translator::saveMissedTranslations();
308 delete myDataModelXMLReader;
309 delete mySelectionActivate;
314 //******************************************************
315 void XGUI_Workshop::startApplication()
317 //Initialize event listening
318 myEventsListener->initializeEventListening();
320 myDataModelXMLReader->readAll();
323 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
324 Config_Prop::Directory, "");
326 std::string aDir = Config_XMLReader::resourcesConfigFile();
327 Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
328 Config_Prop::Directory, aDir);
331 Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start",
332 Config_Prop::Boolean, "false");
334 Config_PropManager::registerProp("Plugins", "show_hide_faces", "Show Hide Faces (on the right)",
335 Config_Prop::Boolean, "false");
337 registerValidators();
339 // Calling of loadCustomProps before activating module is required
340 // by Config_PropManger to restore user-defined path to plugins
341 ModuleBase_Preferences::loadCustomProps();
342 std::vector<int> aColor;
344 aColor = Config_PropManager::color("Visualization", "selection_color");
348 if (aColor.size() == 3)
349 myDisplayer->setSelectionColor(aColor);
354 myMainWindow->show();
355 updateCommandStatus();
360 myViewerProxy->connectViewProxy();
361 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
362 SLOT(onTrihedronVisibilityChanged(bool)));
364 emit applicationStarted();
367 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
369 module()->launchOperation("Part", false); // PartSetPlugin_Part::ID()
374 //******************************************************
375 void XGUI_Workshop::activateModule()
377 selectionActivate()->updateSelectionFilters();
379 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
380 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
381 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
382 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
384 updateCommandStatus();
386 // TODO: get default selection mode
388 // activate visualized objects in the viewer
389 activateObjectsSelection(displayer()->displayedObjects());
390 myOperationMgr->activate();
393 //******************************************************
394 void XGUI_Workshop::deactivateModule()
396 // remove internal displayer filter
397 displayer()->deactivateSelectionFilters(false);
399 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
400 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
401 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
402 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
404 XGUI_Displayer* aDisplayer = displayer();
405 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
406 aDisplayer->deactivateObjects(aDisplayed, true);
407 selectionActivate()->deactivateTrihedronInSelectionModes();
409 #ifdef BEFORE_TRIHEDRON_PATCH
410 //Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
411 /// Trihedron problem: objects stayed in the viewer, should be removed manually
412 /// otherwise in SALOME happens crash by HideAll in the viewer
413 aContext->Remove(aTrihedron->Position(), true);
414 aContext->Remove(aTrihedron->Axis(), true);
415 aContext->Remove(aTrihedron->XAxis(), true);
416 aContext->Remove(aTrihedron->YAxis(), true);
419 myOperationMgr->deactivate();
422 //******************************************************
423 void XGUI_Workshop::initMenu()
425 myContextMenuMgr->createActions();
428 // Create only Undo, Redo commands
429 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
430 tr("Undo last command"),
431 QIcon(":pictures/undo.png"),
432 QKeySequence::Undo, false,
434 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
435 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
437 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
438 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
440 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
441 QIcon(":pictures/redo.png"), QKeySequence::Redo,
442 false, "MEN_DESK_EDIT");
443 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
445 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
446 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
448 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
450 //aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
451 // tr("Blocks immediate apply of modifications"),
452 // QIcon(":pictures/autoapply.png"), QKeySequence(),
453 // false, "MEN_DESK_EDIT");
454 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
456 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onAutoApply()));
458 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
461 // Add commands to a file menu
462 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
463 tr("Export the current document into a native file"),
464 QIcon(), QKeySequence(),
465 false, "MEN_DESK_FILE");
466 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
468 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
469 tr("Import native file"),
470 QIcon(), QKeySequence(),
471 false, "MEN_DESK_FILE");
472 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
473 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
475 aAction = salomeConnector()->addDesktopCommand("EXPORT_PART_CMD", tr("Export part..."),
476 tr("Export a part of the current document into a file"),
477 QIcon(), QKeySequence(),
478 false, "MEN_DESK_FILE");
479 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportPart()));
481 aAction = salomeConnector()->addDesktopCommand("IMPORT_PART_CMD", tr("Import part..."),
482 tr("Import structure of a part"),
483 QIcon(), QKeySequence(),
484 false, "MEN_DESK_FILE");
485 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportPart()));
486 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
489 // File commands group
490 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
492 AppElements_Command* aCommand;
494 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
495 QIcon(":pictures/save.png"), QKeySequence::Save);
496 aCommand->connectTo(this, SLOT(onSave()));
497 //aCommand->disable();
499 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
500 QIcon(":pictures/save.png"), QKeySequence());
501 aCommand->connectTo(this, SLOT(onSaveAs()));
503 QString aUndoId = "UNDO_CMD";
504 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
505 QIcon(":pictures/undo.png"), QKeySequence::Undo);
506 aCommand->connectTo(this, SLOT(onUndo()));
507 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
508 addHistoryMenu(aUndoButton,
509 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
512 QString aRedoId = "REDO_CMD";
513 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
514 QIcon(":pictures/redo.png"), QKeySequence::Redo);
515 aCommand->connectTo(this, SLOT(onRedo()));
516 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
517 addHistoryMenu(aRedoButton,
518 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
521 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
522 QIcon(":pictures/open.png"), QKeySequence::Open);
523 aCommand->connectTo(this, SLOT(onOpen()));
526 aCommand = aGroup->addFeature("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
527 tr("Blocks immediate apply of modifications"),
528 QIcon(":pictures/autoapply_start.png"), QKeySequence());
529 aCommand->setChecked(ModelAPI_Session::get()->isAutoUpdateBlocked());
530 aCommand->connectTo(this, SLOT(onAutoApply()));
532 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
533 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
534 aCommand->connectTo(this, SLOT(onPreferences()));
536 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
537 QIcon(":pictures/close.png"), QKeySequence::Close);
538 aCommand->connectTo(this, SLOT(onExit()));
543 //******************************************************
544 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
546 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
547 return aMenuBar->addWorkbench(theName);
551 //******************************************************
552 QMainWindow* XGUI_Workshop::desktop() const
555 return salomeConnector()->desktop();
561 //******************************************************
562 void XGUI_Workshop::onStartWaiting()
564 if (Events_LongOp::isPerformed()) {
565 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
569 //******************************************************
570 void XGUI_Workshop::onAcceptActionClicked()
572 QAction* anAction = dynamic_cast<QAction*>(sender());
573 XGUI_OperationMgr* anOperationMgr = operationMgr();
574 if (anOperationMgr) {
575 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
576 (anOperationMgr->currentOperation());
578 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
579 myOperationMgr->commitOperation();
584 //******************************************************
585 void XGUI_Workshop::onAcceptPlusActionClicked()
587 QAction* anAction = dynamic_cast<QAction*>(sender());
588 XGUI_OperationMgr* anOperationMgr = operationMgr();
589 if (anOperationMgr) {
590 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
591 (anOperationMgr->currentOperation());
593 if (myOperationMgr->commitOperation())
594 module()->launchOperation(aFOperation->id(), false);
599 //******************************************************
600 void XGUI_Workshop::onPreviewActionClicked()
602 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
604 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
605 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
606 anActiveWidget->storeValue();
609 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
610 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
611 Events_Loop::loop()->send(aMsg);
615 //******************************************************
616 void XGUI_Workshop::onHelpActionClicked()
618 XGUI_OperationMgr* anOperationMgr = operationMgr();
619 if (anOperationMgr) {
620 ModuleBase_Operation* aOperation = anOperationMgr->currentOperation();
622 QString aHelpPage = aOperation->helpFileName();
623 if (!aHelpPage.isEmpty()) {
625 const QChar aSep = QDir::separator();
627 // SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
629 // platform = "winapplication";
631 // platform = "application";
633 // QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform);
636 QString aDir(getenv("SHAPER_ROOT_DIR"));
637 if (!aDir.isEmpty()) {
638 aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep +
639 "salome" + aSep + "gui" + aSep + "SHAPER";
642 QString aDir(getenv("CADBUILDER_ROOT_DIR"));
643 aDocDir = aDir + aSep + "doc" + aSep + "gui";
645 QString aFileName = aDocDir + aSep + aHelpPage;
646 if (QFile::exists(aFileName)) {
647 QUrl aUrl = QUrl::fromLocalFile(aFileName);
648 QDesktopServices::openUrl(aUrl);
656 //******************************************************
657 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
659 if (!myModule->canActivateSelection(theObject)) {
660 if (selectionActivate()->isActive(theObject)) {
661 QObjectPtrList anObjects;
662 anObjects.append(theObject);
663 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
668 //******************************************************
669 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
671 bool aHasNested = false;
672 std::string aFeatureKind = theFeature->getKind();
674 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
675 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
678 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
679 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
680 if (aCommand && aCommand->button()->additionalButtonWidget())
686 //******************************************************
687 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
689 ModuleBase_OperationFeature* aFOperation =
690 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
694 myPropertyPanel->cleanContent();
696 QList<ModuleBase_ModelWidget*> aWidgets;
697 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
698 if (!module()->createWidgets(aFOperation->feature(), aXmlRepr, aWidgets)) {
699 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
700 aFactory.createWidget(myPropertyPanel->contentWidget());
701 aWidgets = aFactory.getModelWidgets();
704 // check compatibility of feature and widgets
705 FeaturePtr aFeature = aFOperation->feature();
706 std::string aFeatureKind = aFeature->getKind();
707 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
708 if (aWidget->usesAttribute()) {
709 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
710 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
711 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
712 .arg(aFeatureKind).arg(aWidget->attributeID())
713 .arg(aWidget->metaObject()->className()).send();
714 myPropertyPanel->cleanContent();
719 // for performance purpose, flush should be done after all controls are filled
720 bool isUpdateFlushed = false;
721 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
722 bool isStoreValue = !aFOperation->isEditOperation() &&
723 !aWidget->getDefaultValue().empty() &&
724 !aWidget->isComputedDefault();
725 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
727 aWidget->restoreValue();
728 aWidget->enableFocusProcessing();
730 // update visible state of Preview button
731 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
733 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
735 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
736 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
738 aFeatureInfo = aCommand->featureMessage();
740 bool anIsAutoPreview = true;
741 if (aFeatureInfo.get()) {
742 anIsAutoPreview = aFeatureInfo->isAutoPreview();
743 theOperation->setHelpFileName(aFeatureInfo->helpFileName().c_str());
745 std::string aXmlCfg, aDescription;
746 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
747 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
748 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
751 if (!anIsAutoPreview) {
752 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
753 // send signal about preview should not be computed automatically, click on preview
754 // button should initiate it
755 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
756 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
757 Events_Loop::loop()->send(aMsg);
759 // if update happens after preview is blocked, it does nothing when blocked
760 // it improves performance for valid objects on feature start
761 ModuleBase_Tools::flushUpdated(aFeature);
763 myPropertyPanel->setModelWidgets(aWidgets);
764 aFOperation->setPropertyPanel(myPropertyPanel);
766 myModule->propertyPanelDefined(theOperation);
768 #ifndef DEBUG_FEATURE_NAME
769 myPropertyPanel->setWindowTitle(ModuleBase_Tools::translate("workshop",
770 theOperation->getDescription()->description().toStdString()));
772 std::string aFeatureName = aFeature->name();
773 myPropertyPanel->setWindowTitle(QString("%1: %2")
774 .arg(translate(theOperation->getDescription()->description()))
775 .arg(translate(aFeatureName.c_str())));
778 myErrorMgr->setPropertyPanel(myPropertyPanel);
779 if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) {
780 theOperation->setHideFacesVisible(myFacesPanel->isVisible());
781 if (aFeatureInfo.get() && aFeatureInfo->isHideFacesPanel() && !myFacesPanel->isVisible())
782 myFacesPanel->show();
784 showPanel(myPropertyPanel);
787 //******************************************************
788 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
790 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
791 if (aPropertyPanel) {
792 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
793 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
794 myModule->connectToPropertyPanel(aWidget, isToConnect);
796 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
797 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
798 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
801 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
802 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
803 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
809 //******************************************************
810 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
812 setGrantedFeatures(theOperation);
814 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
815 fillPropertyPanel(theOperation);
816 connectToPropertyPanel(true);
817 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
820 myPropertyPanel->updateApplyPlusButton(aFOperation->feature());
822 myPropertyPanel->updateApplyPlusButton(FeaturePtr());
824 updateCommandStatus();
826 myModule->operationResumed(theOperation);
829 //******************************************************
830 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
832 updateCommandStatus();
834 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
839 ModuleBase_ISelection* aSel = mySelector->selection();
840 QObjectPtrList aObj = aSel->selectedPresentations();
841 //!< No need for property panel
842 hidePanel(myPropertyPanel);
843 myPropertyPanel->cleanContent();
845 connectToPropertyPanel(false);
846 myModule->operationStopped(aFOperation);
848 // the deactivated objects of the current operation should be activated back.
849 // They were deactivated on operation start or an object redisplay
850 QObjectPtrList anObjects;
851 FeaturePtr aFeature = aFOperation->feature();
852 if (aFeature.get()) { // feature may be not created (plugin load fail)
853 if (myDisplayer->isVisible(aFeature) && !selectionActivate()->isActive(aFeature))
854 anObjects.append(aFeature);
855 std::list<ResultPtr> aResults;
856 ModelAPI_Tools::allResults(aFeature, aResults);
857 std::list<ResultPtr>::const_iterator aIt;
858 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
859 ResultPtr anObject = *aIt;
860 if (myDisplayer->isVisible(anObject) && !selectionActivate()->isActive(anObject)) {
861 anObjects.append(anObject);
865 activateObjectsSelection(anObjects);
867 if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) {
868 if (!theOperation->isHideFacesVisible())
869 myFacesPanel->close();
873 //******************************************************
874 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
876 myModule->operationCommitted(theOperation);
879 //******************************************************
880 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
882 myModule->operationAborted(theOperation);
885 //******************************************************
886 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
888 ModuleBase_OperationFeature* aFOperation =
889 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
893 QStringList aGrantedIds;
894 if (isSalomeMode()) {
895 const std::shared_ptr<Config_FeatureMessage>& anInfo =
896 mySalomeConnector->featureInfo(theOperation->id());
898 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
899 .split(" ", QString::SkipEmptyParts);
902 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
904 ModuleBase_IModule* aModule = module();
906 aModule->grantedOperationIds(theOperation, aGrantedIds);
908 aFOperation->setGrantedOperationIds(aGrantedIds);
911 //******************************************************
912 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
914 QApplication::restoreOverrideCursor();
915 SessionPtr aMgr = ModelAPI_Session::get();
917 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
918 std::list<DocumentPtr>::const_iterator aIt;
919 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
920 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
921 (*aIt)->storeNodesState(aState);
924 aMgr->save(theName.toLatin1().constData(), theFileNames);
926 QApplication::restoreOverrideCursor();
929 //******************************************************
930 bool XGUI_Workshop::abortAllOperations()
932 return myOperationMgr->abortAllOperations();
935 //******************************************************
936 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
938 setGrantedFeatures(theOperation);
939 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
940 updateCommandStatus();
943 myModule->operationStarted(theOperation);
947 //******************************************************
948 void XGUI_Workshop::onOpen()
950 if(!abortAllOperations())
952 //save current file before close if modified
953 SessionPtr aSession = ModelAPI_Session::get();
954 if (aSession->isModified()) {
955 int anAnswer = QMessageBox::question(
956 desktop(), tr("Save current file"),
957 tr("The document is modified, save before opening another?"),
958 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
959 if (anAnswer == QMessageBox::Save) {
961 } else if (anAnswer == QMessageBox::Cancel) {
964 myCurrentFile = QString();
967 //show file dialog, check if readable and open
968 qreal aRatio = ModuleBase_Tools::currentPixelRatio();
969 // If the ratio is > 1 (HD screen) then QT has a bug in
970 // displaying of system open file dialog (too small)
971 QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Open file"), QString(), MyFilter,
972 Q_NULLPTR, ((aRatio > 1)? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
977 //******************************************************
978 void XGUI_Workshop::openFile(const QString& theDirectory)
980 myCurrentFile = theDirectory;
981 if (myCurrentFile.isEmpty())
984 QFileInfo aFileInfo(myCurrentFile);
985 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
986 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
987 myCurrentFile = QString();
991 QApplication::setOverrideCursor(Qt::WaitCursor);
992 module()->closeDocument();
993 SessionPtr aSession = ModelAPI_Session::get();
994 aSession->closeAll();
997 if (!XGUI_CompressFiles::uncompress(myCurrentFile, myTmpDir.path()))
1000 aSession->load(myTmpDir.path().toLatin1().constData());
1001 myObjectBrowser->rebuildDataTree();
1003 // Open first level of data tree
1004 DocumentPtr aRootDoc = aSession->moduleDocument();
1005 std::list<bool> aStates;
1006 aRootDoc->restoreNodesState(aStates);
1007 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
1009 updateCommandStatus();
1011 myMainWindow->setCurrentDir(myCurrentFile, true);
1015 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
1018 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1019 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
1021 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
1022 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1029 QApplication::restoreOverrideCursor();
1032 //******************************************************
1033 void XGUI_Workshop::onNew()
1035 QApplication::setOverrideCursor(Qt::WaitCursor);
1036 if (objectBrowser() == 0) {
1037 createDockWidgets();
1038 mySelector->connectViewers();
1040 myViewerProxy->connectToViewer();
1041 showObjectBrowser();
1043 myMainWindow->showPythonConsole();
1044 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
1045 aWnd->showMaximized();
1046 updateCommandStatus();
1047 PyConsole_Console* aConsole = myMainWindow->pythonConsole();
1048 connect(aConsole, SIGNAL(scriptLoaded()), SLOT(updateCommandStatus()));
1050 myContextMenuMgr->connectViewer();
1051 QApplication::restoreOverrideCursor();
1055 //******************************************************
1056 void XGUI_Workshop::onExit()
1058 SessionPtr aMgr = ModelAPI_Session::get();
1059 if (aMgr->isModified()) {
1060 int anAnswer = QMessageBox::question(
1061 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
1062 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
1063 if (anAnswer == QMessageBox::Save) {
1064 bool saved = onSave();
1068 } else if (anAnswer == QMessageBox::Cancel) {
1075 //******************************************************
1076 void XGUI_Workshop::onPreferences()
1078 ModuleBase_Prefs aModif;
1079 ModuleBase_Preferences::editPreferences(aModif);
1080 if (aModif.size() > 0) {
1082 foreach (ModuleBase_Pref aPref, aModif) {
1083 aSection = aPref.first;
1084 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
1085 myMainWindow->viewer()->updateFromResources();
1086 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
1087 myMainWindow->menuObject()->updateFromResources();
1090 std::vector<int> aColor;
1092 aColor = Config_PropManager::color("Visualization", "selection_color");
1096 if (aColor.size() == 3)
1097 displayer()->setSelectionColor(aColor);
1099 displayer()->redisplayObjects();
1104 //******************************************************
1105 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
1107 XGUI_Displayer* aDisplayer = displayer();
1109 aDisplayer->displayTrihedron(theState);
1110 aDisplayer->updateViewer();
1114 //******************************************************
1115 bool XGUI_Workshop::onSave()
1117 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1119 if (myCurrentFile.isEmpty()) {
1122 SessionPtr aMgr = ModelAPI_Session::get();
1123 if (aMgr->isAutoUpdateBlocked())
1124 aMgr->blockAutoUpdate(false);
1126 std::list<std::string> aFiles;
1127 // issue #2899: create a temporary directory, save and then remove it
1129 std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("SALOME_TMP_DIR");
1131 std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("");
1133 saveDocument(QString(aTmpDir.c_str()), aFiles);
1134 bool aResult = XGUI_CompressFiles::compress(myCurrentFile, aFiles);
1135 XGUI_Tools::removeTemporaryFiles(aTmpDir, aFiles);
1138 updateCommandStatus();
1140 myMainWindow->setModifiedState(false);
1146 //******************************************************
1147 bool XGUI_Workshop::onSaveAs()
1149 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1151 qreal aRatio = ModuleBase_Tools::currentPixelRatio();
1152 myCurrentFile = QFileDialog::getSaveFileName(desktop(), tr("Select name to save file..."),
1153 QString(), MyFilter2,
1154 Q_NULLPTR, ((aRatio > 1) ? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
1155 if (!myCurrentFile.isNull()) {
1156 if (!myCurrentFile.endsWith(MyExtension)) {
1157 myCurrentFile += MyExtension;
1163 myMainWindow->setCurrentDir(myCurrentFile, false);
1164 myMainWindow->setModifiedState(false);
1169 //******************************************************
1170 void XGUI_Workshop::onUndo(int theTimes)
1172 processUndoRedo(ActionUndo, theTimes);
1173 myObjectBrowser->updateAllIndexes(1);
1176 //******************************************************
1177 void XGUI_Workshop::onRedo(int theTimes)
1179 processUndoRedo(ActionRedo, theTimes);
1180 myObjectBrowser->updateAllIndexes(1);
1183 //******************************************************
1184 void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes)
1186 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1187 if (anActiveWidget) {
1188 ActionIntParamPtr aParam(new ModuleBase_ActionIntParameter(theTimes));
1189 if (anActiveWidget->processAction(theActionType, aParam))
1192 // the viewer update should be blocked in order to avoid the features blinking. For the created
1193 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1194 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1195 // until redo of all possible objects happens
1196 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1198 SessionPtr aMgr = ModelAPI_Session::get();
1199 if (aMgr->isOperation()) {
1200 XGUI_OperationMgr* aOpMgr = operationMgr();
1201 /// this is important for nested operations
1202 /// when sketch operation is active, this condition is false and
1203 /// the sketch operation is not aborted
1204 if (aOpMgr->canStopOperation(aOpMgr->currentOperation()))
1205 aOpMgr->abortOperation(aOpMgr->currentOperation());
1208 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1212 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1213 std::list<std::string> anActionList = theActionType == ActionUndo ? aMgr->undoList()
1215 std::list<std::string>::const_iterator aIt = anActionList.cbegin();
1216 for (int i = 0; (i < theTimes) && (aIt != anActionList.cend()); ++i, ++aIt) {
1217 if (theActionType == ActionUndo)
1222 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND ||
1223 QString((*aIt).c_str()) == MOVE_TO_END_SPLIT_COMMAND)
1224 myObjectBrowser->rebuildDataTree();
1226 operationMgr()->updateApplyOfOperations();
1227 facesPanel()->reset(true);
1228 updateCommandStatus();
1230 // unblock the viewer update functionality and make update on purpose
1231 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1232 myDisplayer->updateViewer();
1233 // Clear messages in status bar from previous operations if exists
1234 setStatusBarMessage("");
1237 //******************************************************
1238 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1240 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1241 //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1242 //if (anOperation) {
1243 // ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1245 // anActiveWidget = aPanel->activeWidget();
1248 operationMgr()->onValidateOperation();
1250 myModule->widgetStateChanged(thePreviousState);
1253 //******************************************************
1254 void XGUI_Workshop::onValuesChanged()
1256 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1257 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1260 ModuleBase_ModelWidget* anActiveWidget = 0;
1261 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1263 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1265 anActiveWidget = aPanel->activeWidget();
1267 if (anActiveWidget) {
1268 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1270 if (aWidgetValidated)
1271 aWidgetValidated->clearValidatedCash();
1275 //******************************************************
1276 void XGUI_Workshop::onWidgetObjectUpdated()
1278 operationMgr()->onValidateOperation();
1279 myDisplayer->updateViewer();
1282 //******************************************************
1283 void XGUI_Workshop::onImportPart()
1285 if (abortAllOperations()) {
1286 ModuleBase_OperationFeature* anImportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
1287 module()->createOperation(ExchangePlugin_ImportPart::ID()));
1288 operationMgr()->startOperation(anImportPartOp);
1292 //******************************************************
1293 void XGUI_Workshop::onExportPart()
1295 if (abortAllOperations()) {
1296 ModuleBase_OperationFeature* anExportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
1297 module()->createOperation(ExchangePlugin_ExportPart::ID()));
1298 operationMgr()->startOperation(anExportPartOp);
1302 //******************************************************
1303 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1305 QString libName = QString::fromStdString(library(theModule.toStdString()));
1306 if (libName.isEmpty()) {
1307 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1312 CREATE_FUNC crtInst = 0;
1315 HINSTANCE modLib = ::LoadLibraryA(qPrintable(libName));
1319 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1320 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1321 QString aMsg((char*) &lpMsgBuf);
1322 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1323 ::LocalFree(lpMsgBuf);
1325 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1329 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1330 | FORMAT_MESSAGE_IGNORE_INSERTS,
1331 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1332 QString aMsg((char*) &lpMsgBuf);
1333 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1334 ::LocalFree(lpMsgBuf);
1338 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1340 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1342 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1344 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1349 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1351 if (!err.isEmpty()) {
1353 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1355 qWarning(qPrintable(err));
1361 //******************************************************
1362 bool XGUI_Workshop::createModule()
1364 Config_ModuleReader aModuleReader;
1365 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1366 myModule = loadModule(moduleName);
1370 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1371 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1372 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1373 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1375 myModule->createFeatures();
1377 salomeConnector()->createFeatureActions();
1379 //myActionsMgr->update();
1383 //******************************************************
1384 void XGUI_Workshop::updateCommandStatus()
1386 QList<QAction*> aCommands;
1388 aCommands = salomeConnector()->commandList();
1390 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1391 foreach (AppElements_Command* aCmd, aMenuBar->features())
1392 aCommands.append(aCmd);
1394 SessionPtr aMgr = ModelAPI_Session::get();
1395 if (aMgr->hasModuleDocument()) {
1396 foreach(QAction* aCmd, aCommands) {
1397 QString aId = aCmd->data().toString();
1398 if (aId == "UNDO_CMD") {
1399 bool isActionEnabled = false;
1400 // if ultimate is true -> using result of operation only, or using OR combination
1401 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1402 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled))
1403 aCmd->setEnabled(isActionEnabled);
1405 aCmd->setEnabled(myModule->canUndo());
1407 else if (aId == "REDO_CMD") {
1408 bool isActionEnabled = false;
1409 // if ultimate is true -> using result of operation only, or using OR combination
1410 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1411 if (anActiveWidget && anActiveWidget->canProcessAction(ActionRedo, isActionEnabled))
1412 aCmd->setEnabled(isActionEnabled);
1414 aCmd->setEnabled(myModule->canRedo());
1416 else if (aId == "AUTOCOMPUTE_CMD") {
1417 aCmd->setIcon(aMgr->isAutoUpdateBlocked() ?
1418 QIcon(":pictures/autoapply_stop.png") :
1419 QIcon(":pictures/autoapply_start.png"));
1422 // Enable all commands
1423 aCmd->setEnabled(true);
1427 foreach(QAction* aCmd, aCommands) {
1428 QString aId = aCmd->data().toString();
1429 if (aId == "NEW_CMD")
1430 aCmd->setEnabled(true);
1431 else if (aId == "EXIT_CMD")
1432 aCmd->setEnabled(true);
1434 aCmd->setEnabled(false);
1437 myActionsMgr->updateCommandsStatus();
1438 emit commandStatusUpdated();
1441 //******************************************************
1442 void XGUI_Workshop::updateHistory()
1444 bool isActionEnabled = false;
1445 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1446 QList<ActionInfo> aUndoRes;
1447 QList<ActionInfo> aRedoRes;
1448 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled)) {
1449 aUndoRes = anActiveWidget->actionsList(ActionUndo);
1450 aRedoRes = anActiveWidget->actionsList(ActionRedo);
1452 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1453 aUndoRes = processHistoryList(aUndoList);
1455 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1456 aRedoRes = processHistoryList(aRedoList);
1458 emit updateUndoHistory(aUndoRes);
1459 emit updateRedoHistory(aRedoRes);
1462 //******************************************************
1463 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1465 QDockWidget* aObjDock = new QDockWidget(theParent);
1466 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1467 Qt::RightDockWidgetArea);
1468 aObjDock->setWindowTitle(tr("Object browser"));
1469 aObjDock->setStyleSheet(
1470 "::title { position: relative; padding-left: 5px; text-align: left center }");
1471 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock, this);
1472 myObjectBrowser->initialize(myModule->rootNode());
1473 myModule->customizeObjectBrowser(myObjectBrowser);
1474 aObjDock->setWidget(myObjectBrowser);
1475 aObjDock->setObjectName("Object browser");
1477 connect(myObjectBrowser, SIGNAL(sizeChanged()), SLOT(onDockSizeChanged()));
1479 myContextMenuMgr->connectObjectBrowser();
1483 //******************************************************
1485 * Creates dock widgets, places them in corresponding area
1486 * and tabifies if necessary.
1488 void XGUI_Workshop::createDockWidgets()
1490 QMainWindow* aDesktop = desktop();
1491 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1492 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1493 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1494 myActiveControlMgr->addSelector(new XGUI_PropertyPanelSelector(myPropertyPanel));
1496 myPropertyPanel->setupActions(myActionsMgr);
1497 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1498 Qt::RightDockWidgetArea);
1499 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1501 hidePanel(myPropertyPanel); ///<! Invisible by default
1503 myFacesPanel = new XGUI_FacesPanel(aDesktop, this);
1504 myActiveControlMgr->addSelector(new XGUI_FacesPanelSelector(myFacesPanel));
1505 myFacesPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1506 Qt::RightDockWidgetArea |
1507 Qt::BottomDockWidgetArea);
1508 connect(myFacesPanel, SIGNAL(closed()), myFacesPanel, SLOT(onClosed()));
1510 myInspectionPanel = new XGUI_InspectionPanel(aDesktop, this);
1511 myInspectionPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1512 Qt::RightDockWidgetArea);
1513 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myInspectionPanel);
1515 myInspectionPanel->hide();
1517 aDesktop->addDockWidget(
1519 Qt::RightDockWidgetArea,
1521 Qt::LeftDockWidgetArea,
1524 hidePanel(myFacesPanel); ///<! Invisible by default
1527 bool aShowOnTheRight = Config_PropManager::boolean("Plugins", "show_hide_faces");
1528 if (aShowOnTheRight) {
1529 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myFacesPanel);
1530 showPanel(myFacesPanel);
1533 hideObjectBrowser();
1537 if (!aShowOnTheRight)
1540 aDesktop->tabifyDockWidget(myFacesPanel, aObjDock);
1545 #endif // HAVE_SALOME
1547 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1548 myPropertyPanel->installEventFilter(myOperationMgr);
1550 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1551 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1553 QAction* aOkContAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptPlus);
1554 connect(aOkContAct, SIGNAL(triggered()), this, SLOT(onAcceptPlusActionClicked()));
1556 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1557 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1559 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1560 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1562 QAction* aHelpAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Help);
1563 connect(aHelpAct, SIGNAL(triggered()), this, SLOT(onHelpActionClicked()));
1565 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1566 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1567 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1568 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1571 //******************************************************
1572 void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
1574 if (theDockWidget == myPropertyPanel) {
1575 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1576 ///<! Restore ability to close panel from the window's menu
1577 aViewAct->setEnabled(true);
1579 theDockWidget->show();
1580 theDockWidget->raise();
1582 // The next code is necessary to made the property panel the active window
1583 // in order to operation manager could process key events of the panel.
1584 // otherwise they are ignored. It happens only if the same(activateWindow) is
1585 // not happened by property panel activation(e.g. resume operation of Sketch)
1586 //ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
1589 //******************************************************
1590 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
1592 if (theDockWidget && theDockWidget == myPropertyPanel) {
1593 QAction* aViewAct = theDockWidget->toggleViewAction();
1594 ///<! Do not allow to show empty property panel
1595 aViewAct->setEnabled(false);
1597 theDockWidget->hide();
1599 // the property panel is active window of the desktop, when it is
1600 // hidden, it is undefined which window becomes active. By this reason
1601 // it is defined to perform the desktop as the active window.
1602 // in SALOME mode, work-stack made the PyConsole the active window,
1603 // set the focus on it. As a result, shortcuts of the application, like
1604 // are processed by this console. For example Undo actions.
1605 // It is possible that this code is to be moved to SHAPER package
1606 QMainWindow* aDesktop = desktop();
1607 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::hidePanel()");
1610 //******************************************************
1611 void XGUI_Workshop::showObjectBrowser()
1613 if (!isSalomeMode()) {
1614 myObjectBrowser->parentWidget()->show();
1618 //******************************************************
1619 void XGUI_Workshop::hideObjectBrowser()
1621 if (!isSalomeMode())
1622 myObjectBrowser->parentWidget()->hide();
1625 //******************************************************
1626 void XGUI_Workshop::salomeViewerSelectionChanged()
1628 emit salomeViewerSelection();
1631 //**************************************************************
1632 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1634 return mySalomeConnector->viewer();
1637 //**************************************************************
1638 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1640 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1641 if (theId == "DELETE_CMD")
1643 else if (theId == "CLEAN_HISTORY_CMD")
1645 else if (theId == "MOVE_CMD" || theId == "MOVE_SPLIT_CMD")
1646 moveObjects(theId == "MOVE_SPLIT_CMD");
1647 else if (theId == "COLOR_CMD")
1648 changeColor(aObjects);
1649 else if (theId == "DEFLECTION_CMD")
1650 changeDeflection(aObjects);
1651 else if (theId == "TRANSPARENCY_CMD")
1652 changeTransparency(aObjects);
1653 else if (theId == "SHOW_CMD") {
1654 showObjects(aObjects, true);
1655 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1656 updateCommandStatus();
1658 else if (theId == "HIDE_CMD") {
1659 showObjects(aObjects, false);
1660 updateCommandStatus();
1662 else if (theId == "SHOW_ONLY_CMD") {
1663 showOnlyObjects(aObjects);
1664 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1665 updateCommandStatus();
1667 else if (theId == "SHADING_CMD")
1668 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1669 else if (theId == "WIREFRAME_CMD")
1670 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1671 else if (theId == "HIDEALL_CMD") {
1672 QObjectPtrList aList = myDisplayer->displayedObjects();
1673 foreach (ObjectPtr aObj, aList) {
1674 if (module()->canEraseObject(aObj))
1675 aObj->setDisplayed(false);
1677 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1679 //issue #2159 Hide all incomplete behavior
1680 viewer()->eraseAll();
1682 updateCommandStatus();
1683 // Necessary for update icons in ObjectBrowser on Linux
1684 myObjectBrowser->updateAllIndexes();
1685 } else if (theId == "SELECT_VERTEX_CMD") {
1686 setViewerSelectionMode(TopAbs_VERTEX);
1687 } else if (theId == "SELECT_EDGE_CMD") {
1688 setViewerSelectionMode(TopAbs_EDGE);
1689 } else if (theId == "SELECT_FACE_CMD") {
1690 setViewerSelectionMode(TopAbs_FACE);
1691 } else if (theId == "INSERT_FOLDER_CMD") {
1692 insertFeatureFolder();
1693 } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
1694 insertToFolder(true);
1695 } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
1696 insertToFolder(false);
1697 } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
1698 moveOutFolder(true);
1699 } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
1700 moveOutFolder(false);
1701 } else if (theId == "SELECT_RESULT_CMD") {
1702 //setViewerSelectionMode(-1);
1703 //IMP: an attempt to use result selection with other selection modes
1704 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1705 setViewerSelectionMode(TopAbs_COMPSOLID);
1706 } else if (theId == "SHOW_RESULTS_CMD") {
1707 highlightResults(aObjects);
1708 } else if (theId == "SHOW_FEATURE_CMD") {
1709 highlightFeature(aObjects);
1710 } else if (theId == "SET_VIEW_NORMAL_CMD") {
1712 } else if (theId == "SET_VIEW_INVERTEDNORMAL_CMD") {
1713 setNormalView(true);
1716 else if (theId == "TINSPECTOR_VIEW") {
1717 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1718 if (!anApplication.IsNull())
1720 if (!MyTCommunicator)
1722 MyTCommunicator = new TInspector_Communicator();
1724 NCollection_List<Handle(Standard_Transient)> aParameters;
1725 aParameters.Append(anApplication);
1726 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1727 if (!aContext.IsNull())
1728 aParameters.Append(aContext);
1730 #ifdef DEBUG_WITH_MESSAGE_REPORT
1731 Handle(Message_Report) aContextReport = aContext->GetReport();
1732 aContext->SetReportActive (Standard_True);
1733 aContextReport->SetLimit (1000);
1734 if (!aContextReport.IsNull())
1735 aParameters.Append(aContextReport);
1737 MyVCallBack = new VInspector_CallBack();
1738 myDisplayer->setCallBack(MyVCallBack);
1740 AppElements_Viewer* aViewer = mainWindow()->viewer();
1742 aViewer->setCallBack(MyVCallBack);
1744 aParameters.Append(MyVCallBack);
1746 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1747 MyTCommunicator->RegisterPlugin("TKShapeView");
1748 MyTCommunicator->RegisterPlugin("TKVInspector");
1749 #ifdef DEBUG_WITH_MESSAGE_REPORT
1750 MyTCommunicator->RegisterPlugin("TKMessageView");
1752 //MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1753 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1755 MyTCommunicator->Init(aParameters);
1756 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1757 #ifndef DEBUG_WITH_MESSAGE_REPORT
1758 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1760 MyTCommunicator->Activate("TKDFBrowser");
1762 #ifdef DEBUG_WITH_MESSAGE_REPORT
1763 MyTCommunicator->Activate("TKMessageView"); // temporary
1764 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1767 MyTCommunicator->SetVisible(true);
1773 //**************************************************************
1774 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1777 myViewerSelMode.clear();
1779 if (myViewerSelMode.contains(theMode))
1780 myViewerSelMode.removeAll(theMode);
1782 myViewerSelMode.append(theMode);
1784 selectionActivate()->updateSelectionModes();
1787 //**************************************************************
1788 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1791 module()->activeSelectionModes(aModes);
1792 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1793 aModes.append(myViewerSelMode);
1794 selectionActivate()->activateObjects(aModes, theList);
1797 //**************************************************************
1798 bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) const
1800 if (facesPanel()->isEmpty())
1803 // generate container of objects taking into account sub elments of compsolid
1804 std::set<ObjectPtr> anAllProcessedObjects;
1805 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1806 anObjectsIt != theObjects.end(); anObjectsIt++) {
1807 ObjectPtr anObject = *anObjectsIt;
1808 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
1809 if (aCompRes.get()) {
1810 std::list<ResultPtr> allRes;
1811 ModelAPI_Tools::allSubs(aCompRes, allRes);
1812 if (allRes.empty()) {
1813 anAllProcessedObjects.insert(anObject);
1815 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
1816 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
1817 if (aBody.get() && aBody->numberOfSubs() == 0)
1818 anAllProcessedObjects.insert(aBody);
1822 anAllProcessedObjects.insert(anObject);
1825 // find hidden objects in faces panel
1826 std::set<ObjectPtr> aHiddenObjects;
1827 QStringList aHiddenObjectNames;
1828 for (std::set<ObjectPtr>::const_iterator anObjectsIt = anAllProcessedObjects.begin();
1829 anObjectsIt != anAllProcessedObjects.end(); anObjectsIt++) {
1830 if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
1832 aHiddenObjects.insert(*anObjectsIt);
1833 aHiddenObjectNames.append((*anObjectsIt)->data()->name().c_str());
1835 if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face
1838 int anAnswer = QMessageBox::question(
1839 desktop(), tr("Show object"),
1840 tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?")
1841 .arg(aHiddenObjectNames.join(", ")).arg(facesPanel()->windowTitle()),
1842 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1844 bool aToBeDisplayed = anAnswer == QMessageBox::Yes;
1846 facesPanel()->restoreObjects(aHiddenObjects);
1848 return aToBeDisplayed;
1851 //**************************************************************
1852 void XGUI_Workshop::deleteObjects()
1854 ModuleBase_IModule* aModule = module();
1855 // allow the module to delete objects, do nothing if it has succeed
1856 if (aModule->deleteObjects()) {
1857 updateCommandStatus();
1858 myDisplayer->updateViewer();
1862 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1863 if (anObjects.isEmpty())
1866 if (!abortAllOperations())
1869 bool hasResult = false;
1870 bool hasFeature = false;
1871 bool hasParameter = false;
1872 bool hasCompositeOwner = false;
1873 bool hasResultInHistory = false;
1874 bool hasFolder = false;
1875 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1876 hasResultInHistory, hasFolder);
1877 if (!(hasResult || hasFeature || hasParameter || hasFolder))
1880 // Remove from the list non-deletable objects: infinite constructions which are not in history
1881 bool notDelete = true;
1882 QObjectPtrList::iterator aIt;
1883 for (aIt = anObjects.begin(); aIt != anObjects.end(); aIt++) {
1884 ObjectPtr aObj = (*aIt);
1885 ResultConstructionPtr aConstr = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
1886 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1888 notDelete = (!aFeature->isInHistory()) && aConstr->isInfinite();
1890 anObjects.removeAll(aObj);
1896 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1897 std::set<FeaturePtr> aFeatures;
1898 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1899 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1901 std::set<FolderPtr> aFolders;
1902 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
1905 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1906 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1907 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, module());
1909 operationMgr()->startOperation(anOpAction);
1911 std::set<FeaturePtr> aFeatureRefsToDelete;
1912 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1913 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1914 // It is necessary to clear selection in order to avoid selection changed event during
1915 // deletion and negative consequences connected with processing of already deleted items
1916 mySelector->clearSelection();
1918 if (!aFeatureRefsToDelete.empty())
1919 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1920 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1922 if (aFolders.size() > 0) {
1923 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
1924 aLast = aFolders.end();
1925 for (; anIt != aLast; anIt++) {
1926 FolderPtr aFolder = *anIt;
1927 if (aFolder.get()) {
1928 DocumentPtr aDoc = aFolder->document();
1929 aDoc->removeFolder(aFolder);
1933 // remove results selected
1934 std::list<ResultPtr> aResults;
1935 for(QObjectPtrList::const_iterator anIt = anObjects.begin(); anIt != anObjects.end(); anIt++) {
1936 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*anIt);
1937 if (aRes.get() && aRes->data()->isValid() && !aRes->data()->isDeleted() &&
1938 aRes->groupName() != ModelAPI_ResultGroup::group() && // don't remove groups and fields
1939 aRes->groupName() != ModelAPI_ResultField::group()) // because they are badly selected
1940 aResults.push_back(aRes);
1942 if (!aResults.empty()) {
1943 ModelAPI_Tools::removeResults(aResults);
1947 operationMgr()->commitOperation();
1949 operationMgr()->abortOperation(operationMgr()->currentOperation());
1951 myDisplayer->updateViewer();
1954 //**************************************************************
1955 void addRefsToFeature(const FeaturePtr& theFeature,
1956 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1957 std::set<FeaturePtr>& theReferences)
1959 //if (theReferences.find(theFeature) != theReferences.end())
1961 if (theMainList.find(theFeature) == theMainList.end())
1962 return; // this feature is not in the selection list, so exists without references to it
1963 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1965 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1966 aLast = aMainReferences.end();
1967 for (; anIt != aLast; anIt++) {
1968 FeaturePtr aRefFeature = *anIt;
1969 if (theReferences.find(aRefFeature) == theReferences.end())
1970 theReferences.insert(aRefFeature);
1971 addRefsToFeature(aRefFeature, theMainList, theReferences);
1975 //**************************************************************
1976 void XGUI_Workshop::cleanHistory()
1978 if (!abortAllOperations())
1981 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1982 std::set<FeaturePtr> aFeatures;
1983 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1985 #ifdef DEBUG_CLEAN_HISTORY
1987 std::set<FeaturePtr>::const_iterator aFIt;
1988 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1989 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1990 anInfo.append(aFeature->name().c_str());
1992 QString anInfoStr = anInfo.join(";\t");
1993 qDebug(QString("cleanHistory for: [%1] - %2").
1994 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1997 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1998 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1999 // find for each object whether all reference values are in the map as key, that means that there
2000 // is no other reference in the model to this object, so it might be removed by cleaning history
2001 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - can't be deleted, dependency to bool_1
2002 // ext_1(bool_1, sk_3) - can't be deleted, dependency to bool_1
2004 // sk_2(ext_2) + (bool_1) - can't be deleted, dependency to bool_1
2005 // ext_2(bool_1) - can't be deleted, dependency to bool_1
2007 // Information: bool_1 is not selected
2008 std::set<FeaturePtr> anUnusedObjects;
2009 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
2010 aMainLast = aReferences.end();
2011 for (; aMainIt != aMainLast; aMainIt++) {
2012 FeaturePtr aMainListFeature = aMainIt->first;
2013 std::set<FeaturePtr> aMainRefList = aMainIt->second;
2014 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
2015 aRefLast = aMainRefList.end();
2016 bool aFeatureOutOfTheList = false;
2017 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
2018 FeaturePtr aRefFeature = *aRefIt;
2019 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
2021 if (!aFeatureOutOfTheList)
2022 anUnusedObjects.insert(aMainListFeature);
2025 #ifdef DEBUG_CLEAN_HISTORY
2027 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
2028 FeaturePtr aFeature = *aFIt;
2029 anInfo.append(aFeature->name().c_str());
2031 qDebug(QString("unused objects: [%1] - %2").
2032 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
2035 // warn about the references remove, break the delete operation if the user chose it
2036 if (!anUnusedObjects.empty()) {
2038 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
2039 aNames.append(aFeature->name().c_str());
2042 QString anUnusedNames = aNames.join(", ");
2044 QString anActionId = "CLEAN_HISTORY_CMD";
2045 QString aDescription = ModuleBase_Tools::translate("workshop",
2046 contextMenuMgr()->action(anActionId)->text().toStdString());
2048 QMessageBox aMessageBox(desktop());
2049 aMessageBox.setWindowTitle(aDescription);
2050 aMessageBox.setIcon(QMessageBox::Warning);
2051 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
2052 aMessageBox.setDefaultButton(QMessageBox::No);
2054 const char* aKeyStr = "Unused features are the following: "
2055 "%1.\nThese features will be deleted.\nWould you like to continue?";
2056 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
2057 aMessageBox.setText(aText);
2058 if (aMessageBox.exec() == QMessageBox::No)
2061 // 1. start operation
2062 aDescription += "by deleting of " +
2063 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
2064 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, module());
2065 operationMgr()->startOperation(anOpAction);
2067 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
2068 // It is necessary to clear selection in order to avoid selection changed event during
2069 // deletion and negative consequences connected with processing of already deleted items
2070 mySelector->clearSelection();
2072 std::set<FeaturePtr> anIgnoredFeatures;
2073 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
2074 operationMgr()->commitOperation();
2077 operationMgr()->abortOperation(operationMgr()->currentOperation());
2081 QString anActionId = "CLEAN_HISTORY_CMD";
2082 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2084 QMessageBox aMessageBox(desktop());
2085 aMessageBox.setWindowTitle(aDescription);
2086 aMessageBox.setIcon(QMessageBox::Warning);
2087 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
2088 aMessageBox.setDefaultButton(QMessageBox::No);
2091 aMessageBox.setStandardButtons(QMessageBox::Ok);
2092 aMessageBox.setDefaultButton(QMessageBox::Ok);
2094 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
2095 aMessageBox.setText(aText);
2097 if (aMessageBox.exec() == QMessageBox::No)
2102 //**************************************************************
2103 bool compareFeature(const FeaturePtr& theF1, const FeaturePtr& theF2) {
2104 DocumentPtr aDoc = theF1->document();
2105 return aDoc->index(theF1) < aDoc->index(theF2);
2107 void XGUI_Workshop::moveObjects(const bool theSplit)
2109 if (!abortAllOperations())
2112 SessionPtr aMgr = ModelAPI_Session::get();
2114 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2115 // It is necessary to clear selection in order to avoid selection changed event during
2116 // moving and negative consequences connected with processing of already moved items
2117 mySelector->clearSelection();
2118 // check whether the object can be moved. There should not be parts which are not loaded
2119 std::set<FeaturePtr> aFeatures;
2120 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
2121 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
2124 QString anActionId = theSplit ? "MOVE_CMD" : "MOVE_SPLIT_CMD";
2125 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2126 aMgr->startOperation(aDescription.toStdString());
2128 // Sort features by index in document
2129 std::list<FeaturePtr> aFList(aFeatures.begin(), aFeatures.end());
2130 aFList.sort(compareFeature);
2132 DocumentPtr anActiveDocument = aMgr->activeDocument();
2133 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
2134 std::list<FeaturePtr>::const_iterator anIt = aFList.begin(), aLast = aFList.end();
2135 for (; anIt != aLast; anIt++) {
2136 FeaturePtr aFeature = *anIt;
2137 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
2140 anActiveDocument->moveFeature(aFeature, aCurrentFeature, theSplit);
2141 aCurrentFeature = anActiveDocument->currentFeature(true);
2143 aMgr->finishOperation();
2144 updateCommandStatus();
2145 myViewerProxy->update();
2148 //**************************************************************
2149 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
2151 std::set<FeaturePtr> aFeatures;
2152 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
2154 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
2157 //******************************************************
2158 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
2160 bool isFoundResultType = false;
2161 foreach(ObjectPtr anObj, theObjects)
2163 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2164 if (aResult.get() == NULL)
2167 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
2168 if (isFoundResultType)
2171 return isFoundResultType;
2174 //**************************************************************
2175 // Returns the list of all features for theDocument and all features of
2176 // all nested parts.
2177 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
2179 std::list<FeaturePtr> aResultList;
2180 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
2181 foreach (const FeaturePtr& aFeature, anAllFeatures) {
2182 // The order of appending features of the part and the part itself is important
2184 // Append features from a part feature
2185 std::list<ResultPtr> aResults;
2186 ModelAPI_Tools::allResults(aFeature, aResults);
2187 foreach (const ResultPtr& aResult, aResults) {
2188 ResultPartPtr aResultPart =
2189 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
2190 if (aResultPart.get() && aResultPart->partDoc().get()) {
2192 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
2193 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
2197 aResultList.push_back(aFeature);
2202 //**************************************************************
2203 // Returns the list of features placed between theObject and the current feature
2204 // in the same document. Excludes theObject, includes the current feature.
2205 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
2207 std::list<FeaturePtr> aResult;
2208 DocumentPtr aDocument = theObject->document();
2209 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
2210 // find the object iterator
2211 std::list<FeaturePtr>::iterator aObjectIt =
2212 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
2213 if (aObjectIt == anAllFeatures.end())
2215 // find the current feature iterator
2216 std::list<FeaturePtr>::iterator aCurrentIt =
2217 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
2218 if (aCurrentIt == anAllFeatures.end())
2220 // check the right order
2221 if (std::distance(aObjectIt, anAllFeatures.end()) <=
2222 std::distance(aCurrentIt, anAllFeatures.end()))
2224 // exclude the object
2225 std::advance(aObjectIt, 1);
2226 // include the current feature
2227 std::advance(aCurrentIt, 1);
2228 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
2231 //******************************************************
2232 bool XGUI_Workshop::canMoveFeature()
2234 QString anActionId = "MOVE_CMD";
2236 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2237 QObjectPtrList aValidatedObjects;
2238 foreach (ObjectPtr aObject, aObjects) {
2239 if (!myModule->canApplyAction(aObject, anActionId))
2241 // To be moved feature should be in active document
2242 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
2244 aValidatedObjects.append(aObject);
2246 if (aValidatedObjects.size() != aObjects.size())
2247 aObjects = aValidatedObjects;
2249 bool aCanMove = !aObjects.empty();
2251 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
2252 for (; anIt != aLast && aCanMove; anIt++) {
2253 ObjectPtr aObject = *anIt;
2254 if (!aObject.get() || !aObject->data().get() || !aObject->data()->isValid()) {
2258 FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
2259 // only groups can be moved to the end for now (#2451)
2260 if (aFeat.get() && aFeat->getKind() != "Group") {
2265 // 1. Get features placed between selected and current in the document
2266 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
2267 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
2268 if (aFeaturesBetween.empty())
2271 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2272 // 2. Get all reference features to the selected object in the document
2273 std::set<FeaturePtr> aRefFeatures;
2274 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
2276 if (aRefFeatures.empty())
2279 // 3. Find any placed features in all reference features
2280 std::set<FeaturePtr> aIntersectionFeatures;
2281 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2282 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2283 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2284 // 4. Return false if any reference feature is placed before current feature
2285 if (!aIntersectionFeatures.empty())
2293 //**************************************************************
2294 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2296 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2297 if (!aCanBeShaded) {
2298 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
2299 if (aCompRes.get() != NULL) { // change colors for all sub-solids
2300 std::list<ResultPtr> allRes;
2301 ModelAPI_Tools::allSubs(aCompRes, allRes);
2302 std::list<ResultPtr>::iterator aRes = allRes.begin();
2303 for(; aRes != allRes.end() && !aCanBeShaded; aRes++) {
2304 aCanBeShaded = myDisplayer->canBeShaded(*aRes);
2308 return aCanBeShaded;
2311 //**************************************************************
2312 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2314 if (theActionName == "COLOR_CMD" ||
2315 theActionName == "DEFLECTION_CMD" ||
2316 theActionName == "TRANSPARENCY_CMD") {
2317 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2319 std::set<std::string> aTypes;
2320 aTypes.insert(ModelAPI_ResultGroup::group());
2321 aTypes.insert(ModelAPI_ResultConstruction::group());
2322 aTypes.insert(ModelAPI_ResultBody::group());
2323 aTypes.insert(ModelAPI_ResultPart::group());
2325 return hasResults(aObjects, aTypes);
2330 //******************************************************
2331 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
2333 if (!theResult.get())
2336 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
2337 if (aColorAttr.get() != NULL) {
2338 if (!aColorAttr->size()) {
2339 aColorAttr->setSize(3);
2341 aColorAttr->setValue(0, theColor[0]);
2342 aColorAttr->setValue(1, theColor[1]);
2343 aColorAttr->setValue(2, theColor[2]);
2347 //**************************************************************
2348 void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
2349 std::vector<int>& theColor)
2352 // get default color from the preferences manager for the given result
2353 if (theColor.empty()) {
2354 std::string aSection, aName, aDefault;
2355 theObject->colorConfigInfo(aSection, aName, aDefault);
2356 if (!aSection.empty() && !aName.empty()) {
2357 theColor = Config_PropManager::color(aSection, aName);
2360 if (!isEmptyColorValid && theColor.empty()) {
2361 // all AIS objects, where the color is not set, are in black.
2362 // The color should be defined in XML or set in the attribute
2363 theColor = Config_PropManager::color("Visualization", "object_default_color");
2364 Events_InfoMessage("XGUI_CustomPrs",
2365 "A default color is not defined in the preferences for this kind of result").send();
2369 //**************************************************************
2370 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2373 AttributeIntArrayPtr aColorAttr;
2374 // 1. find the current color of the object. This is a color of AIS presentation
2375 // The objects are iterated until a first valid color is found
2376 std::vector<int> aColor;
2377 foreach(ObjectPtr anObject, theObjects) {
2378 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2379 if (aResult.get()) {
2380 ModelAPI_Tools::getColor(aResult, aColor);
2382 getDefaultColor(aResult, false, aColor);
2385 // TODO: remove the obtaining a color from the AIS object
2386 // this does not happen never because:
2387 // 1. The color can be changed only on results
2388 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2389 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2390 if (anAISObj.get()) {
2392 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2395 if (!aColor.empty())
2398 if (aColor.size() != 3)
2401 if (!abortAllOperations())
2403 // 2. show the dialog to change the value
2404 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2405 aDlg->setColor(aColor);
2406 aDlg->move(QCursor::pos());
2407 bool isDone = aDlg->exec() == QDialog::Accepted;
2411 bool isRandomColor = aDlg->isRandomColor();
2413 // 3. abort the previous operation and start a new one
2414 SessionPtr aMgr = ModelAPI_Session::get();
2415 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2416 aMgr->startOperation(aDescription.toStdString());
2418 // 4. set the value to all results
2419 std::vector<int> aColorResult = aDlg->getColor();
2420 foreach(ObjectPtr anObj, theObjects) {
2421 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2422 if (aResult.get() != NULL) {
2423 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2424 if (aBodyResult.get() != NULL) { // change colors for all sub-solids
2425 std::list<ResultPtr> allRes;
2426 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2427 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2428 setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2431 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2434 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2435 aMgr->finishOperation();
2436 updateCommandStatus();
2437 myViewerProxy->update();
2440 //**************************************************************
2441 void setDeflection(ResultPtr theResult, const double theDeflection)
2443 if (!theResult.get())
2446 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
2447 if (aDeflectionAttr.get() != NULL) {
2448 aDeflectionAttr->setValue(theDeflection);
2452 //**************************************************************
2453 void setTransparency(ResultPtr theResult, double theTransparency)
2455 if (!theResult.get())
2458 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
2459 if (anAttribute.get() != NULL) {
2460 anAttribute->setValue(theTransparency);
2464 //**************************************************************
2465 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2467 foreach(ObjectPtr anObj, theObjects) {
2468 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2469 if (aResult.get() != NULL) {
2470 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2471 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2472 std::list<ResultPtr> allRes;
2473 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2474 std::list<ResultPtr>::iterator aRes;
2475 for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2476 setTransparency(*aRes, theTransparency);
2479 setTransparency(aResult, theTransparency);
2484 //**************************************************************
2485 double getDefaultDeflection(const ObjectPtr& theObject)
2487 double aDeflection = -1;
2488 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
2489 if (aResult.get()) {
2490 bool isConstruction = false;
2492 std::string aResultGroup = aResult->groupName();
2493 if (aResultGroup == ModelAPI_ResultConstruction::group())
2494 isConstruction = true;
2495 else if (aResultGroup == ModelAPI_ResultBody::group()) {
2496 GeomShapePtr aGeomShape = aResult->shape();
2497 if (aGeomShape.get()) {
2498 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
2499 // correction of deviation for them should not influence to the application performance
2500 GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
2501 isConstruction = !anExp.more();
2505 aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
2507 aDeflection = Config_PropManager::real("Visualization", "body_deflection");
2512 //**************************************************************
2513 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2515 AttributeDoublePtr aDoubleAttr;
2516 // 1. find the current property of the object. This is a property of AIS presentation
2517 // The objects are iterated until a first valid property is found
2518 double aDeflection = -1;
2519 foreach(ObjectPtr anObject, theObjects) {
2520 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2521 if (aResult.get()) {
2522 aDeflection = ModelAPI_Tools::getDeflection(aResult);
2523 if (aDeflection < 0)
2524 aDeflection = getDefaultDeflection(aResult);
2527 // TODO: remove the obtaining a property from the AIS object
2528 // this does not happen never because:
2529 // 1. The property can be changed only on results
2530 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2531 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2532 if (anAISObj.get()) {
2533 aDeflection = anAISObj->getDeflection();
2536 if (aDeflection > 0)
2539 if (aDeflection < 0)
2542 if (!abortAllOperations())
2544 // 2. show the dialog to change the value
2545 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2546 aDlg->setDeflection(aDeflection);
2547 aDlg->move(QCursor::pos());
2548 bool isDone = aDlg->exec() == QDialog::Accepted;
2552 // 3. abort the previous operation and start a new one
2553 SessionPtr aMgr = ModelAPI_Session::get();
2554 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2555 aMgr->startOperation(aDescription.toStdString());
2557 // 4. set the value to all results
2558 aDeflection = aDlg->getDeflection();
2559 foreach(ObjectPtr anObj, theObjects) {
2560 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2561 if (aResult.get() != NULL) {
2562 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2563 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2564 std::list<ResultPtr> allRes;
2565 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2566 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2567 setDeflection(*aRes, aDeflection);
2570 setDeflection(aResult, aDeflection);
2573 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2574 aMgr->finishOperation();
2575 updateCommandStatus();
2578 //**************************************************************
2579 double getDefaultTransparency(const ResultPtr& theResult)
2581 return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.;
2584 //**************************************************************
2585 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2587 AttributeDoublePtr aDoubleAttr;
2588 // 1. find the current property of the object. This is a property of AIS presentation
2589 // The objects are iterated until a first valid property is found
2590 double aCurrentValue = -1;
2591 foreach(ObjectPtr anObject, theObjects) {
2592 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2593 if (aResult.get()) {
2594 aCurrentValue = ModelAPI_Tools::getTransparency(aResult);
2595 if (aCurrentValue < 0)
2596 aCurrentValue = getDefaultTransparency(aResult);
2598 if (aCurrentValue > 0)
2601 if (aCurrentValue < 0)
2604 if (!abortAllOperations())
2607 // 2. show the dialog to change the value
2608 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2609 aDlg->setWindowTitle(tr("Transparency"));
2610 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2611 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2612 this, SLOT(onTransparencyValueChanged()));
2613 aDlg->setContent(aTransparencyWidget);
2614 aTransparencyWidget->setValue(aCurrentValue);
2616 // 3. abort the previous operation and start a new one
2617 SessionPtr aMgr = ModelAPI_Session::get();
2618 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2619 aMgr->startOperation(aDescription.toStdString());
2621 if (aDlg->exec() == QDialog::Accepted) {
2622 // 4. set the value to all results
2623 aCurrentValue = aTransparencyWidget->getValue();
2624 setTransparency(aCurrentValue, theObjects);
2625 aMgr->finishOperation();
2627 aMgr->abortOperation();
2628 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2631 updateCommandStatus();
2634 //**************************************************************
2635 void XGUI_Workshop::onTransparencyValueChanged()
2637 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2638 if (!aTransparencyWidget)
2641 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2642 setTransparency(aTransparencyWidget->getValue(), anObjects);
2643 static const Events_ID kRedisplayEvent =
2644 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2645 Events_Loop::loop()->flush(kRedisplayEvent);
2647 myViewerProxy->update();
2651 //******************************************************
2652 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2655 std::set<ObjectPtr> anObjects;
2656 foreach (ObjectPtr aObj, theList) {
2657 anObjects.insert(aObj);
2659 if (!prepareForDisplay(anObjects))
2663 foreach (ObjectPtr aObj, theList) {
2664 aObj->setDisplayed(isVisible);
2666 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2667 myObjectBrowser->updateAllIndexes();
2669 updateColorScaleVisibility();
2670 displayer()->updateViewer();
2673 //**************************************************************
2674 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2676 QObjectPtrList aSrcList = theList;
2677 // Hide all displayed objects
2678 QObjectPtrList aList = myDisplayer->displayedObjects();
2679 foreach (ObjectPtr aObj, aList) {
2680 if ((!aSrcList.contains(aObj)) && (module()->canEraseObject(aObj)))
2681 aObj->setDisplayed(false);
2683 aSrcList.removeAll(aObj);
2685 //Do not use eraseAll if you didn't send Redisplay event:
2686 //all objects are erased from viewer, but considered as displayed in displayer
2687 // Problem in bug 2218
2688 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2690 //issue #2159 Hide all incomplete behavior
2691 viewer()->eraseAll();
2694 std::set<ObjectPtr> anObjects;
2695 foreach (ObjectPtr aObj, aSrcList) {
2696 anObjects.insert(aObj);
2699 if (!prepareForDisplay(anObjects))
2702 // Show only objects from the list
2703 foreach (ObjectPtr aObj, aSrcList) {
2704 aObj->setDisplayed(true);
2706 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2708 // Necessary for update icons in ObjectBrowser on Linux
2709 myObjectBrowser->updateAllIndexes();
2710 updateColorScaleVisibility();
2711 displayer()->updateViewer();
2715 //**************************************************************
2716 void XGUI_Workshop::updateColorScaleVisibility()
2718 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2719 viewer()->setColorScaleShown(false);
2720 if (aObjects.size() == 1) {
2721 FieldStepPtr aStep =
2722 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObjects.first());
2723 if (aStep.get() && myDisplayer->isVisible(aStep)) {
2724 AISObjectPtr aAisPtr = myDisplayer->getAISObject(aStep);
2725 Handle(AIS_InteractiveObject) aIO = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2726 ModuleBase_IStepPrs* aPrs = dynamic_cast<ModuleBase_IStepPrs*>(aIO.get());
2728 ModelAPI_AttributeTables::ValueType aType = aPrs->dataType();
2729 if ((aType == ModelAPI_AttributeTables::DOUBLE) ||
2730 (aType == ModelAPI_AttributeTables::INTEGER) ||
2731 (aType == ModelAPI_AttributeTables::BOOLEAN)) {
2732 myViewerProxy->setupColorScale();
2733 if (aType == ModelAPI_AttributeTables::BOOLEAN) {
2734 myViewerProxy->setColorScaleIntervals(2);
2735 myViewerProxy->setColorScaleRange(0., 1.);
2739 aPrs->dataRange(aMin, aMax);
2740 myViewerProxy->setColorScaleRange(aMin, aMax);
2742 myViewerProxy->setColorScaleTitle(aStep->name().c_str());
2743 myViewerProxy->setColorScaleShown(true);
2751 //**************************************************************
2752 void XGUI_Workshop::setNormalView(bool toInvert)
2754 QList<ModuleBase_ViewerPrsPtr> aPrsList =
2755 mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
2756 GeomShapePtr aPlanarFace;
2757 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
2758 GeomShapePtr aShape = aPrs->shape();
2759 if (aShape.get() && aShape->isPlanar()) {
2760 aPlanarFace = aShape;
2764 if (aPlanarFace.get()) {
2765 GeomFacePtr aFace(new GeomAPI_Face(aPlanarFace));
2766 GeomPlanePtr aPlane = aFace->getPlane();
2767 GeomDirPtr aNormal = aPlane->direction();
2770 GeomPointPtr aPos = aPlane->location();
2772 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2773 aFace->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2775 Handle(V3d_View) aView = myViewerProxy->activeView();
2776 double aScale = aView->Scale();
2777 aView->SetAt(aPos->x(), aPos->y(), aPos->z());
2778 aView->SetProj(aNormal->x(), aNormal->y(), aNormal->z());
2780 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2781 aView->FitAll(aBox);
2785 //**************************************************************
2786 void XGUI_Workshop::registerValidators() const
2788 SessionPtr aMgr = ModelAPI_Session::get();
2789 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2792 //**************************************************************
2793 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2797 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2798 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2801 //**************************************************************
2802 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2804 for (int i = 0; i < theDoc->size(theGroup); i++)
2805 theDoc->object(theGroup, i)->setDisplayed(true);
2806 //displayObject(theDoc->object(theGroup, i));
2807 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2810 //**************************************************************
2811 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2813 foreach(ObjectPtr anObj, theList) {
2814 myDisplayer->setDisplayMode(anObj, (XGUI_Displayer::DisplayMode)theMode, false);
2816 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
2817 if (aBodyResult.get() != NULL) { // change display mode for all sub-solids
2818 std::list<ResultPtr> allRes;
2819 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2820 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2821 myDisplayer->setDisplayMode(*aRes, (XGUI_Displayer::DisplayMode)theMode, false);
2825 if (theList.size() > 0)
2826 myDisplayer->updateViewer();
2829 //**************************************************************
2830 void XGUI_Workshop::closeDocument()
2832 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2833 while (anOperation) {
2834 anOperation->abort();
2835 anOperation = operationMgr()->currentOperation();
2837 //myDisplayer->closeLocalContexts();
2838 myDisplayer->eraseAll();
2839 objectBrowser()->clearContent();
2841 module()->closeDocument();
2842 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2843 module()->clearViewer();
2846 // data model need not process the document's signals about objects modifications as
2847 // the document is closed
2848 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2850 SessionPtr aMgr = ModelAPI_Session::get();
2853 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2856 //******************************************************
2857 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2859 XGUI_HistoryMenu* aMenu = NULL;
2860 if (isSalomeMode()) {
2861 QAction* anAction = qobject_cast<QAction*>(theObject);
2864 aMenu = new XGUI_HistoryMenu(anAction);
2866 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2867 aMenu = new XGUI_HistoryMenu(aButton);
2869 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2870 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2873 //******************************************************
2874 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2876 QList<ActionInfo> aResult;
2877 std::list<std::string>::const_iterator it = theList.cbegin();
2878 for (; it != theList.cend(); it++) {
2879 QString anId = QString::fromStdString(*it);
2880 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2882 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2885 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2886 if (aContextMenuAct) {
2887 anInfo.initFrom(aContextMenuAct);
2889 anInfo = myActionsMgr->actionInfoById(anId);
2892 anInfo.text = anInfo.text.prepend("Modify ");
2899 //******************************************************
2900 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2903 salomeConnector()->putInfo(theMessage, -1);
2905 myMainWindow->putInfo(theMessage, -1);
2910 //******************************************************
2911 void XGUI_Workshop::synchronizeViewer()
2913 SessionPtr aMgr = ModelAPI_Session::get();
2914 QList<DocumentPtr> aDocs;
2915 aDocs.append(aMgr->activeDocument());
2916 aDocs.append(aMgr->moduleDocument());
2918 foreach(DocumentPtr aDoc, aDocs) {
2919 synchronizeGroupInViewer(aDoc, false);
2923 //******************************************************
2924 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2925 bool theUpdateViewer)
2927 FeaturePtr aFeature;
2929 int aSize = theDoc->numInternalFeatures();
2930 for (int i = 0; i < aSize; i++) {
2931 aFeature = theDoc->internalFeature(i);
2932 if (!aFeature.get())
2934 const std::list<ResultPtr>& aResults = aFeature->results();
2935 std::list<ResultPtr>::const_iterator aIt;
2936 aFeature->setDisplayed(false);
2937 for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2939 if (aRes->isDisplayed() && !aRes->isConcealed()) {
2940 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2941 // be changed to the object becomes visible when the shape becomes not empty
2942 if (!aRes->shape().get() || aRes->shape()->isNull())
2944 ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aRes);
2946 synchronizeResultTree(aResBody, false);
2948 if (aRes->isInHistory()) {
2949 if (aRes->isDisplayed())
2950 myDisplayer->display(aRes, false);
2952 myDisplayer->erase(aRes, false);
2955 aRes->setDisplayed(false);
2960 if (theUpdateViewer)
2961 myDisplayer->updateViewer();
2964 void XGUI_Workshop::synchronizeResultTree(const ResultBodyPtr& theRes, bool theUpdateViewer)
2966 if (theRes->numberOfSubs() > 0)
2967 for (int i = 0; i < theRes->numberOfSubs(); i++) {
2968 ResultBodyPtr aRes = theRes->subResult(i);
2970 synchronizeResultTree(aRes, theUpdateViewer);
2973 if (theRes->isDisplayed())
2974 myDisplayer->display(theRes, theUpdateViewer);
2976 myDisplayer->erase(theRes, theUpdateViewer);
2981 //******************************************************
2982 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2984 FeaturePtr aFeature;
2985 QObjectPtrList aSelList = theObjects;
2986 QObjectPtrList aNewSel;
2987 bool aHasHidden = false;
2988 foreach(ObjectPtr aObj, theObjects) {
2989 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2990 if (aFeature.get()) {
2991 std::list<ResultPtr> aResults;
2992 ModelAPI_Tools::allResults(aFeature, aResults);
2993 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2994 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2995 aHasHidden |= (*aIt)->isConcealed();
2996 aSelList.append(*aIt);
2997 aNewSel.append(*aIt);
3001 if (aSelList.count() > theObjects.count()) {
3002 // if something was found
3003 objectBrowser()->setObjectsSelected(aSelList);
3004 objectBrowser()->ensureVisible(aNewSel.first());
3007 QMessageBox::information(desktop(), tr("Find results"),
3008 tr("Results not found"), QMessageBox::Ok);
3011 //******************************************************
3012 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
3015 QObjectPtrList aSelList = theObjects;
3016 QObjectPtrList aNewSel;
3017 FeaturePtr aFeature;
3018 foreach(ObjectPtr aObj, theObjects) {
3019 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
3020 if (aResult.get()) {
3021 aFeature = ModelAPI_Feature::feature(aResult);
3022 if (aFeature.get()) {
3023 aSelList.append(aFeature);
3024 aNewSel.append(aFeature);
3028 if (aSelList.count() > theObjects.count()) {
3029 // if something was found
3030 objectBrowser()->setObjectsSelected(aSelList);
3031 objectBrowser()->ensureVisible(aNewSel.first());
3035 void XGUI_Workshop::insertFeatureFolder()
3037 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
3038 if (aObjects.isEmpty())
3040 ObjectPtr aObj = aObjects.first();
3041 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
3042 if (aFeature.get() == NULL)
3044 SessionPtr aMgr = ModelAPI_Session::get();
3045 DocumentPtr aDoc = aMgr->activeDocument();
3047 QString aDescription = contextMenuMgr()->action("INSERT_FOLDER_CMD")->text();
3049 aMgr->startOperation(aDescription.toStdString());
3050 aDoc->addFolder(aFeature);
3051 aMgr->finishOperation();
3053 updateCommandStatus();
3057 void XGUI_Workshop::insertToFolder(bool isBefore)
3059 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
3060 if (aFeatures.empty())
3063 SessionPtr aMgr = ModelAPI_Session::get();
3064 DocumentPtr aDoc = aMgr->activeDocument();
3066 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
3067 aDoc->findFolderBelow(aFeatures);
3071 QString aDescription = contextMenuMgr()->action(
3072 isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text();
3074 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
3076 aMgr->startOperation(aDescription.toStdString());
3077 aDoc->moveToFolder(aFeatures, aFolder);
3078 aMgr->finishOperation();
3080 myObjectBrowser->setFoldersState(aStates);
3082 updateCommandStatus();
3085 void XGUI_Workshop::moveOutFolder(bool isBefore)
3087 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
3088 if (aFeatures.empty())
3091 SessionPtr aMgr = ModelAPI_Session::get();
3092 DocumentPtr aDoc = aMgr->activeDocument();
3094 QString aDescription = contextMenuMgr()->action(
3095 isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text();
3097 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
3099 aMgr->startOperation(aDescription.toStdString());
3100 aDoc->removeFromFolder(aFeatures, isBefore);
3101 aMgr->finishOperation();
3103 myObjectBrowser->setFoldersState(aStates);
3105 updateCommandStatus();
3108 void XGUI_Workshop::onAutoApply()
3110 SessionPtr aMgr = ModelAPI_Session::get();
3111 bool isBlocked = aMgr->isAutoUpdateBlocked();
3112 aMgr->blockAutoUpdate(!isBlocked);
3115 void XGUI_Workshop::updateAutoComputeState()
3117 SessionPtr aMgr = ModelAPI_Session::get();
3118 bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
3120 // QAction* aUpdateCmd;
3121 // QList<QAction*> aCommands = mySalomeConnector->commandList();
3122 // foreach(QAction* aCmd, aCommands) {
3123 // if (aCmd->data().toString() == "AUTOCOMPUTE_CMD") {
3124 // aUpdateCmd = aCmd;
3128 // aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
3129 // QIcon(":pictures/autoapply_start.png"));
3131 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
3132 AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD");
3133 aUpdateCmd->button()->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
3134 QIcon(":pictures/autoapply_start.png"));
3139 void XGUI_Workshop::clearTemporaryDir()
3141 QDir aDir(myTmpDir.path());
3142 if (!aDir.isEmpty()) {
3143 QStringList aEntries;
3144 aDir.entryList(aEntries);
3145 foreach(QString aFile, aEntries) {
3152 void XGUI_Workshop::onDockSizeChanged()
3154 QDockWidget* aDockWgt = dynamic_cast<QDockWidget*>(myObjectBrowser->parentWidget());
3155 int aObWidth = aDockWgt->size().width();
3156 if (myPropertyPanel->width() != aObWidth) {
3157 QList<QDockWidget*> aWgtList;
3158 aWgtList << myPropertyPanel << aDockWgt;
3159 QList<int> aSizeList;
3160 aSizeList << aObWidth << aObWidth;
3161 desktop()->resizeDocks(aWgtList, aSizeList, Qt::Horizontal);
3162 disconnect(myObjectBrowser, SIGNAL(sizeChanged()), this, SLOT(onDockSizeChanged()));
3166 void XGUI_Workshop::deactivateCurrentSelector()
3168 myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector());