1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 //#include "XGUI_Constants.h"
4 #include "XGUI_Workshop.h"
6 #include "XGUI_ActionsMgr.h"
7 #include "XGUI_ColorDialog.h"
8 #include "XGUI_ContextMenuMgr.h"
9 #include "XGUI_Displayer.h"
10 #include "XGUI_ErrorDialog.h"
11 #include "XGUI_ErrorMgr.h"
12 #include "XGUI_ModuleConnector.h"
13 #include "XGUI_ObjectsBrowser.h"
14 #include "XGUI_OperationMgr.h"
15 #include "XGUI_PropertyPanel.h"
16 #include "XGUI_SalomeConnector.h"
17 #include "XGUI_Selection.h"
18 #include "XGUI_SelectionMgr.h"
19 #include "XGUI_Tools.h"
20 #include "XGUI_ViewerProxy.h"
21 #include "XGUI_WorkshopListener.h"
22 #include <XGUI_CustomPrs.h>
23 #include <XGUI_HistoryMenu.h>
24 #include <XGUI_QtEvents.h>
27 #include <AppElements_Button.h>
28 #include <AppElements_Command.h>
29 #include <AppElements_MainMenu.h>
30 #include <AppElements_MainWindow.h>
31 #include <AppElements_MenuGroupPanel.h>
32 #include <AppElements_Viewer.h>
33 #include <AppElements_Workbench.h>
36 #include <ModelAPI_AttributeDocRef.h>
37 #include <ModelAPI_AttributeIntArray.h>
38 #include <ModelAPI_Data.h>
39 #include <ModelAPI_Events.h>
40 #include <ModelAPI_Feature.h>
41 #include <ModelAPI_Object.h>
42 #include <ModelAPI_ResultBody.h>
43 #include <ModelAPI_ResultConstruction.h>
44 #include <ModelAPI_ResultGroup.h>
45 #include <ModelAPI_ResultParameter.h>
46 #include <ModelAPI_Session.h>
47 #include <ModelAPI_Validator.h>
48 #include <ModelAPI_ResultCompSolid.h>
49 #include <ModelAPI_Tools.h>
51 //#include <PartSetPlugin_Part.h>
53 #include <Events_Loop.h>
54 #include <Events_Error.h>
55 #include <Events_LongOp.h>
57 #include <ModuleBase_FilterFactory.h>
58 #include <ModuleBase_IModule.h>
59 #include <ModuleBase_IViewer.h>
60 #include <ModuleBase_Operation.h>
61 #include <ModuleBase_OperationDescription.h>
62 #include <ModuleBase_PageBase.h>
63 #include <ModuleBase_Preferences.h>
64 #include <ModuleBase_SelectionValidator.h>
65 #include <ModuleBase_Tools.h>
66 #include <ModuleBase_WidgetFactory.h>
67 #include <ModuleBase_OperationFeature.h>
68 #include <ModuleBase_OperationAction.h>
69 #include <ModuleBase_PagedContainer.h>
70 #include <ModuleBase_WidgetValidated.h>
72 #include <Config_Common.h>
73 #include <Config_FeatureMessage.h>
74 #include <Config_ModuleReader.h>
75 #include <Config_PointerMessage.h>
76 #include <Config_PropManager.h>
77 #include <Config_SelectionFilterMessage.h>
79 #include <SUIT_ResourceMgr.h>
81 #include <QApplication>
82 #include <QFileDialog>
83 #include <QMessageBox>
84 #include <QMdiSubWindow>
85 #include <QMainWindow>
86 #include <QPushButton>
87 #include <QDockWidget>
92 #include <QToolButton>
94 #include <QDesktopWidget>
110 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
112 //#define DEBUG_DELETE
113 //#define DEBUG_FEATURE_NAME
115 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
117 myCurrentDir(QString()),
119 mySalomeConnector(theConnector),
123 myViewerSelMode(TopAbs_FACE)
126 myMainWindow = new AppElements_MainWindow();
128 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
129 bool aCloc = aResMgr->booleanValue("language", "locale", true);
131 QLocale::setDefault( QLocale::c() );
133 QLocale::setDefault( QLocale::system() );
136 myDisplayer = new XGUI_Displayer(this);
138 mySelector = new XGUI_SelectionMgr(this);
139 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
141 myOperationMgr = new XGUI_OperationMgr(this, 0);
142 myActionsMgr = new XGUI_ActionsMgr(this);
143 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
144 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
145 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
146 SLOT(onContextMenuCommand(const QString&, bool)));
148 myViewerProxy = new XGUI_ViewerProxy(this);
149 connect(myViewerProxy, SIGNAL(selectionChanged()),
150 myActionsMgr, SLOT(updateOnViewSelection()));
152 myModuleConnector = new XGUI_ModuleConnector(this);
154 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
155 myOperationMgr->setWorkshop(aWorkshop);
157 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
158 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
160 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
161 SLOT(onOperationStarted(ModuleBase_Operation*)));
162 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
163 SLOT(onOperationResumed(ModuleBase_Operation*)));
164 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
165 SLOT(onOperationStopped(ModuleBase_Operation*)));
166 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
167 SLOT(onOperationCommitted(ModuleBase_Operation*)));
168 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
169 SLOT(onOperationAborted(ModuleBase_Operation*)));
172 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
173 onTrihedronVisibilityChanged(true);
176 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
177 connect(myEventsListener, SIGNAL(errorOccurred(const QString&)),
178 myErrorDlg, SLOT(addError(const QString&)));
180 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
181 // Config_Prop::Color, "225,225,225");
183 Config_PropManager::registerProp("Visualization", "result_body_color", "Body color",
184 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
185 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
186 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
187 Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color",
188 Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
189 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
190 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
193 ModuleBase_Preferences::resourceMgr()->integerValue("Viewer", "selection", TopAbs_FACE);
196 //******************************************************
197 XGUI_Workshop::~XGUI_Workshop(void)
202 //******************************************************
203 void XGUI_Workshop::startApplication()
207 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
208 Config_Prop::Directory, "");
210 //Initialize event listening
211 myEventsListener->initializeEventListening();
213 registerValidators();
215 // Calling of loadCustomProps before activating module is required
216 // by Config_PropManger to restore user-defined path to plugins
217 ModuleBase_Preferences::loadCustomProps();
221 myMainWindow->show();
222 updateCommandStatus();
227 myViewerProxy->connectViewProxy();
228 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
229 SLOT(onTrihedronVisibilityChanged(bool)));
231 emit applicationStarted();
234 void XGUI_Workshop::activateModule()
236 myModule->activateSelectionFilters();
238 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
239 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
240 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
241 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
243 updateCommandStatus();
245 // TODO: get default selection mode
247 // activate visualized objects in the viewer
248 activateObjectsSelection(displayer()->displayedObjects());
249 myOperationMgr->activate();
252 void XGUI_Workshop::deactivateModule()
254 myModule->deactivateSelectionFilters();
256 // remove internal displayer filter
257 displayer()->deactivateSelectionFilters();
259 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
260 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
261 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
262 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
264 XGUI_Displayer* aDisplayer = displayer();
265 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
266 aDisplayer->deactivateObjects(aDisplayed, true);
268 myOperationMgr->deactivate();
271 //******************************************************
272 void XGUI_Workshop::initMenu()
274 myContextMenuMgr->createActions();
277 // Create only Undo, Redo commands
278 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
279 tr("Undo last command"),
280 QIcon(":pictures/undo.png"),
281 QKeySequence::Undo, false, "MEN_DESK_EDIT");
282 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
283 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
285 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
286 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
288 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
289 QIcon(":pictures/redo.png"), QKeySequence::Redo,
290 false, "MEN_DESK_EDIT");
291 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
293 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
294 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
296 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
297 //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
298 // QIcon(":pictures/rebuild.png"), QKeySequence(),
299 // false, "MEN_DESK_EDIT");
300 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
302 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
303 //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
305 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."), tr("Export the current document into a native file"),
306 QIcon(), QKeySequence(),
307 false, "MEN_DESK_FILE");
308 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
310 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."), tr("Import native file"),
311 QIcon(), QKeySequence(),
312 false, "MEN_DESK_FILE");
313 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
314 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
317 // File commands group
318 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
320 AppElements_Command* aCommand;
322 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
323 QIcon(":pictures/save.png"), QKeySequence::Save);
324 aCommand->connectTo(this, SLOT(onSave()));
325 //aCommand->disable();
327 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
328 QIcon(":pictures/save.png"), QKeySequence());
329 aCommand->connectTo(this, SLOT(onSaveAs()));
331 QString aUndoId = "UNDO_CMD";
332 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
333 QIcon(":pictures/undo.png"), QKeySequence::Undo);
334 aCommand->connectTo(this, SLOT(onUndo()));
335 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
336 addHistoryMenu(aUndoButton,
337 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
340 QString aRedoId = "REDO_CMD";
341 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
342 QIcon(":pictures/redo.png"), QKeySequence::Redo);
343 aCommand->connectTo(this, SLOT(onRedo()));
344 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
345 addHistoryMenu(aRedoButton,
346 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
349 //aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
350 // QIcon(":pictures/rebuild.png"), QKeySequence());
351 //aCommand->connectTo(this, SLOT(onRebuild()));
353 //aCommand->disable();
355 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
356 QIcon(":pictures/open.png"), QKeySequence::Open);
357 aCommand->connectTo(this, SLOT(onOpen()));
359 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
360 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
361 aCommand->connectTo(this, SLOT(onPreferences()));
363 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
364 QIcon(":pictures/close.png"), QKeySequence::Close);
365 aCommand->connectTo(this, SLOT(onExit()));
370 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
372 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
373 return aMenuBar->addWorkbench(theName);
377 //******************************************************
378 QMainWindow* XGUI_Workshop::desktop() const
381 return salomeConnector()->desktop();
387 //******************************************************
388 void XGUI_Workshop::onStartWaiting()
390 if (Events_LongOp::isPerformed()) {
391 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
395 //******************************************************
396 void XGUI_Workshop::onAcceptActionClicked()
398 QAction* anAction = dynamic_cast<QAction*>(sender());
399 XGUI_OperationMgr* anOperationMgr = operationMgr();
400 if (anOperationMgr) {
401 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
402 (anOperationMgr->currentOperation());
404 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
405 myOperationMgr->onCommitOperation();
410 //******************************************************
411 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
413 if (!myModule->canActivateSelection(theObject)) {
414 if (myDisplayer->isActive(theObject)) {
415 QObjectPtrList anObjects;
416 anObjects.append(theObject);
417 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
422 //******************************************************
423 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
425 bool aHasNested = false;
426 std::string aFeatureKind = theFeature->getKind();
428 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
429 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
432 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
433 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
434 if (aCommand && aCommand->button()->additionalButtonWidget())
440 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
442 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
447 myPropertyPanel->cleanContent();
449 QList<ModuleBase_ModelWidget*> aWidgets;
450 if (!module()->createWidgets(theOperation, aWidgets)) {
451 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
452 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
453 aFactory.createWidget(myPropertyPanel->contentWidget());
454 aWidgets = aFactory.getModelWidgets();
457 // check compatibility of feature and widgets
458 FeaturePtr aFeature = aFOperation->feature();
459 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
460 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
461 std::string anErrorMsg = "The feature '" + aFeature->getKind() + "' has no attribute '"
462 + aWidget->attributeID() + "' used by widget '"
463 + aWidget->metaObject()->className() + "'.";
464 Events_Error::send(anErrorMsg);
465 myPropertyPanel->cleanContent();
470 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
471 bool isStoreValue = !aFOperation->isEditOperation() &&
472 !aWidget->getDefaultValue().empty() &&
473 !aWidget->isComputedDefault();
474 aWidget->setFeature(aFOperation->feature(), isStoreValue);
475 aWidget->enableFocusProcessing();
478 myPropertyPanel->setModelWidgets(aWidgets);
479 aFOperation->setPropertyPanel(myPropertyPanel);
481 myModule->propertyPanelDefined(theOperation);
483 #ifndef DEBUG_FEATURE_NAME
484 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
486 std::string aFeatureName = aFeature->name();
487 myPropertyPanel->setWindowTitle(QString("%1: %2").arg(theOperation->getDescription()->description())
488 .arg(aFeatureName.c_str()));
491 myErrorMgr->setPropertyPanel(myPropertyPanel);
494 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
496 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
497 if (aPropertyPanel) {
498 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
499 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
500 myModule->connectToPropertyPanel(aWidget, isToConnect);
502 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
503 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
506 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
507 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
513 //******************************************************
514 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
516 setGrantedFeatures(theOperation);
517 myModule->operationStarted(theOperation);
520 //******************************************************
521 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
523 setGrantedFeatures(theOperation);
525 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
526 setPropertyPanel(theOperation);
527 connectToPropertyPanel(true);
529 updateCommandStatus();
531 myModule->operationResumed(theOperation);
535 //******************************************************
536 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
538 updateCommandStatus();
540 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
545 ModuleBase_ISelection* aSel = mySelector->selection();
546 QObjectPtrList aObj = aSel->selectedPresentations();
547 //!< No need for property panel
549 myPropertyPanel->cleanContent();
551 connectToPropertyPanel(false);
552 myModule->operationStopped(aFOperation);
554 // the deactivated objects of the current operation should be activated back.
555 // They were deactivated on operation start or an object redisplay
556 QObjectPtrList anObjects;
557 FeaturePtr aFeature = aFOperation->feature();
558 if (aFeature.get()) { // feature may be not created (plugin load fail)
559 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
560 anObjects.append(aFeature);
561 std::list<ResultPtr> aResults = aFeature->results();
562 std::list<ResultPtr>::const_iterator aIt;
563 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
564 ResultPtr anObject = *aIt;
565 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
566 anObjects.append(anObject);
570 activateObjectsSelection(anObjects);
574 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
576 myModule->operationCommitted(theOperation);
579 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
581 myModule->operationAborted(theOperation);
584 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
586 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
590 QStringList aGrantedIds;
592 aGrantedIds = mySalomeConnector->nestedActions(theOperation->id());
594 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
596 ModuleBase_IModule* aModule = module();
598 aModule->grantedOperationIds(theOperation, aGrantedIds);
600 aFOperation->setGrantedOperationIds(aGrantedIds);
605 * Saves document with given name.
607 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
609 QApplication::restoreOverrideCursor();
610 SessionPtr aMgr = ModelAPI_Session::get();
611 aMgr->save(theName.toLatin1().constData(), theFileNames);
612 QApplication::restoreOverrideCursor();
615 bool XGUI_Workshop::abortAllOperations()
617 return myOperationMgr->abortAllOperations();
620 //******************************************************
621 void XGUI_Workshop::onOpen()
623 if(!abortAllOperations())
625 //save current file before close if modified
626 SessionPtr aSession = ModelAPI_Session::get();
627 if (aSession->isModified()) {
628 //TODO(sbh): re-launch the app?
629 int anAnswer = QMessageBox::question(
630 desktop(), tr("Save current file"),
631 tr("The document is modified, save before opening another?"),
632 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
633 if (anAnswer == QMessageBox::Save) {
635 } else if (anAnswer == QMessageBox::Cancel) {
641 //show file dialog, check if readable and open
642 myCurrentDir = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
643 if (myCurrentDir.isEmpty())
645 QFileInfo aFileInfo(myCurrentDir);
646 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
647 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
651 QApplication::setOverrideCursor(Qt::WaitCursor);
652 aSession->closeAll();
653 aSession->load(myCurrentDir.toLatin1().constData());
654 myObjectBrowser->rebuildDataTree();
655 updateCommandStatus();
656 QApplication::restoreOverrideCursor();
659 //******************************************************
660 void XGUI_Workshop::onNew()
662 QApplication::setOverrideCursor(Qt::WaitCursor);
663 if (objectBrowser() == 0) {
665 mySelector->connectViewers();
667 myViewerProxy->connectToViewer();
670 myMainWindow->showPythonConsole();
671 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
672 aWnd->showMaximized();
673 updateCommandStatus();
675 myContextMenuMgr->connectViewer();
676 QApplication::restoreOverrideCursor();
680 //******************************************************
681 void XGUI_Workshop::onExit()
683 SessionPtr aMgr = ModelAPI_Session::get();
684 if (aMgr->isModified()) {
685 int anAnswer = QMessageBox::question(
686 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
687 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
688 if (anAnswer == QMessageBox::Save) {
689 bool saved = onSave();
693 } else if (anAnswer == QMessageBox::Cancel) {
700 //******************************************************
701 void XGUI_Workshop::onPreferences()
703 ModuleBase_Prefs aModif;
704 ModuleBase_Preferences::editPreferences(aModif);
705 if (aModif.size() > 0) {
707 foreach (ModuleBase_Pref aPref, aModif)
709 aSection = aPref.first;
710 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
711 myMainWindow->viewer()->updateFromResources();
712 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
713 myMainWindow->menuObject()->updateFromResources();
716 displayer()->redisplayObjects();
721 //******************************************************
722 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
724 XGUI_Displayer* aDisplayer = displayer();
726 aDisplayer->displayTrihedron(theState);
729 //******************************************************
730 bool XGUI_Workshop::onSave()
732 if(!abortAllOperations())
734 if (myCurrentDir.isEmpty()) {
737 std::list<std::string> aFiles;
738 saveDocument(myCurrentDir, aFiles);
739 updateCommandStatus();
741 myMainWindow->setModifiedState(false);
746 //******************************************************
747 bool XGUI_Workshop::onSaveAs()
749 if(!abortAllOperations())
751 QFileDialog dialog(desktop());
752 dialog.setWindowTitle(tr("Select directory to save files..."));
753 dialog.setFileMode(QFileDialog::Directory);
754 dialog.setFilter(tr("Directories (*)"));
755 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
756 dialog.setViewMode(QFileDialog::Detail);
758 if (!dialog.exec()) {
762 QString aTempDir = dialog.selectedFiles().first();
764 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
765 int answer = QMessageBox::question(
767 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
769 tr("The directory already contains some files, save anyway?"),
770 QMessageBox::Save | QMessageBox::Cancel);
771 if (answer == QMessageBox::Cancel) {
775 myCurrentDir = aTempDir;
777 myMainWindow->setCurrentDir(myCurrentDir, false);
778 myMainWindow->setModifiedState(false);
783 //******************************************************
784 void XGUI_Workshop::onUndo(int theTimes)
786 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
787 SessionPtr aMgr = ModelAPI_Session::get();
788 std::list<std::string> aUndoList = aMgr->undoList();
789 if (aMgr->isOperation()) {
790 /// this is important for nested operations
791 /// when sketch operation is active, this condition is false and
792 /// the sketch operation is not aborted
793 operationMgr()->onAbortOperation();
795 std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
796 for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
798 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
799 myObjectBrowser->rebuildDataTree();
802 operationMgr()->updateApplyOfOperations();
803 updateCommandStatus();
806 //******************************************************
807 void XGUI_Workshop::onRedo(int theTimes)
809 // the viewer update should be blocked in order to avoid the features blinking. For the created
810 // feature a results are created, the flush of the created signal caused the viewer redisplay for
811 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked until
812 // redo of all possible objects happens
813 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
815 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
816 SessionPtr aMgr = ModelAPI_Session::get();
817 std::list<std::string> aRedoList = aMgr->redoList();
818 if (aMgr->isOperation()) {
819 /// this is important for nested operations
820 /// when sketch operation is active, this condition is false and
821 /// the sketch operation is not aborted
822 operationMgr()->onAbortOperation();
824 std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
825 for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
827 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
828 myObjectBrowser->rebuildDataTree();
830 operationMgr()->updateApplyOfOperations();
831 updateCommandStatus();
833 // unblock the viewer update functionality and make update on purpose
834 myDisplayer->enableUpdateViewer(isUpdateEnabled);
835 myDisplayer->updateViewer();
838 //******************************************************
839 //void XGUI_Workshop::onRebuild()
841 // SessionPtr aMgr = ModelAPI_Session::get();
842 // bool aWasOperation = aMgr->isOperation(); // keep this value
843 // if (!aWasOperation) {
844 // aMgr->startOperation("Rebuild");
846 // static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
847 // Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
848 // new Events_Message(aRebuildEvent, this)));
849 // if (!aWasOperation) {
850 // aMgr->finishOperation();
852 // updateCommandStatus();
855 //******************************************************
856 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
858 ModuleBase_ModelWidget* anActiveWidget = 0;
859 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
861 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
863 anActiveWidget = aPanel->activeWidget();
866 operationMgr()->onValidateOperation();
868 myModule->widgetStateChanged(thePreviousState);
871 //******************************************************
872 void XGUI_Workshop::onValuesChanged()
874 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
875 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
878 ModuleBase_ModelWidget* anActiveWidget = 0;
879 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
881 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
883 anActiveWidget = aPanel->activeWidget();
885 if (anActiveWidget) {
886 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
888 if (aWidgetValidated)
889 aWidgetValidated->clearValidatedCash();
893 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
895 QString libName = QString::fromStdString(library(theModule.toStdString()));
896 if (libName.isEmpty()) {
897 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
902 CREATE_FUNC crtInst = 0;
905 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
909 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
910 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
911 QString aMsg((char*) &lpMsgBuf);
912 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
913 ::LocalFree(lpMsgBuf);
915 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
919 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
920 | FORMAT_MESSAGE_IGNORE_INSERTS,
921 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
922 QString aMsg((char*) &lpMsgBuf);
923 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
924 ::LocalFree(lpMsgBuf);
928 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
930 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
932 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
934 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
939 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
941 if (!err.isEmpty()) {
943 Events_Error::send(err.toStdString());
945 qWarning(qPrintable(err));
951 //******************************************************
952 bool XGUI_Workshop::createModule()
954 Config_ModuleReader aModuleReader;
955 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
956 myModule = loadModule(moduleName);
960 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
961 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
962 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
963 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
965 myModule->createFeatures();
966 //myActionsMgr->update();
970 //******************************************************
971 void XGUI_Workshop::updateCommandStatus()
973 QList<QAction*> aCommands;
975 aCommands = salomeConnector()->commandList();
977 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
978 foreach (AppElements_Command* aCmd, aMenuBar->features())
979 aCommands.append(aCmd);
981 SessionPtr aMgr = ModelAPI_Session::get();
982 if (aMgr->hasModuleDocument()) {
983 foreach(QAction* aCmd, aCommands) {
984 QString aId = aCmd->data().toString();
985 if (aId == "UNDO_CMD")
986 aCmd->setEnabled(myModule->canUndo());
987 else if (aId == "REDO_CMD")
988 aCmd->setEnabled(myModule->canRedo());
990 // Enable all commands
991 aCmd->setEnabled(true);
995 foreach(QAction* aCmd, aCommands) {
996 QString aId = aCmd->data().toString();
997 if (aId == "NEW_CMD")
998 aCmd->setEnabled(true);
999 else if (aId == "EXIT_CMD")
1000 aCmd->setEnabled(true);
1002 aCmd->setEnabled(false);
1005 myActionsMgr->updateCommandsStatus();
1006 emit commandStatusUpdated();
1009 void XGUI_Workshop::updateHistory()
1011 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1012 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1013 emit updateUndoHistory(aUndoRes);
1015 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1016 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1017 emit updateRedoHistory(aRedoRes);
1020 //******************************************************
1021 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1023 QDockWidget* aObjDock = new QDockWidget(theParent);
1024 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1025 aObjDock->setWindowTitle(tr("Object browser"));
1026 aObjDock->setStyleSheet(
1027 "::title { position: relative; padding-left: 5px; text-align: left center }");
1028 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1029 myModule->customizeObjectBrowser(myObjectBrowser);
1030 aObjDock->setWidget(myObjectBrowser);
1032 myContextMenuMgr->connectObjectBrowser();
1036 //******************************************************
1038 * Creates dock widgets, places them in corresponding area
1039 * and tabifies if necessary.
1041 void XGUI_Workshop::createDockWidgets()
1043 QMainWindow* aDesktop = desktop();
1044 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1045 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1046 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1047 myPropertyPanel->setupActions(myActionsMgr);
1048 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1049 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1050 hidePropertyPanel(); ///<! Invisible by default
1051 hideObjectBrowser();
1052 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1053 myPropertyPanel->installEventFilter(myOperationMgr);
1055 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1056 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1058 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1059 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1060 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1061 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1063 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1064 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1067 //******************************************************
1068 void XGUI_Workshop::showPropertyPanel()
1070 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1071 ///<! Restore ability to close panel from the window's menu
1072 aViewAct->setEnabled(true);
1073 myPropertyPanel->show();
1074 myPropertyPanel->raise();
1076 // The next code is necessary to made the property panel the active window
1077 // in order to operation manager could process key events of the panel.
1078 // otherwise they are ignored. It happens only if the same(activateWindow) is
1079 // not happened by property panel activation(e.g. resume operation of Sketch)
1080 ModuleBase_Tools::activateWindow(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1081 ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1084 //******************************************************
1085 void XGUI_Workshop::hidePropertyPanel()
1087 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1088 ///<! Do not allow to show empty property panel
1089 aViewAct->setEnabled(false);
1090 myPropertyPanel->hide();
1092 // the property panel is active window of the desktop, when it is
1093 // hidden, it is undefined which window becomes active. By this reason
1094 // it is defined to perform the desktop as the active window.
1095 // in SALOME mode, workstack made the PyConsole the active window,
1096 // set the focus on it. As a result, shortcuts of the application, like
1097 // are processed by this console. For example Undo actions.
1098 // It is possible that this code is to be moved to SHAPER package
1099 QMainWindow* aDesktop = desktop();
1100 ModuleBase_Tools::activateWindow(aDesktop, "XGUI_Workshop::hidePropertyPanel()");
1101 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()");
1104 //******************************************************
1105 void XGUI_Workshop::showObjectBrowser()
1107 if (!isSalomeMode())
1108 myObjectBrowser->parentWidget()->show();
1111 //******************************************************
1112 void XGUI_Workshop::hideObjectBrowser()
1114 if (!isSalomeMode())
1115 myObjectBrowser->parentWidget()->hide();
1118 //******************************************************
1119 void XGUI_Workshop::salomeViewerSelectionChanged()
1121 emit salomeViewerSelection();
1124 //**************************************************************
1125 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1127 return mySalomeConnector->viewer();
1130 //**************************************************************
1131 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1133 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1134 if (theId == "DELETE_CMD")
1136 else if (theId == "CLEAN_HISTORY_CMD")
1138 else if (theId == "MOVE_CMD")
1140 else if (theId == "COLOR_CMD")
1141 changeColor(aObjects);
1142 else if (theId == "SHOW_CMD") {
1143 showObjects(aObjects, true);
1144 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1146 else if (theId == "HIDE_CMD")
1147 showObjects(aObjects, false);
1148 else if (theId == "SHOW_ONLY_CMD") {
1149 showOnlyObjects(aObjects);
1150 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1152 else if (theId == "SHADING_CMD")
1153 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1154 else if (theId == "WIREFRAME_CMD")
1155 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1156 else if (theId == "HIDEALL_CMD") {
1157 QObjectPtrList aList = myDisplayer->displayedObjects();
1158 foreach (ObjectPtr aObj, aList) {
1159 if (module()->canEraseObject(aObj))
1160 aObj->setDisplayed(false);
1162 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1163 } else if (theId == "SELECT_VERTEX_CMD") {
1164 setViewerSelectionMode(TopAbs_VERTEX);
1165 } else if (theId == "SELECT_EDGE_CMD") {
1166 setViewerSelectionMode(TopAbs_EDGE);
1167 } else if (theId == "SELECT_FACE_CMD") {
1168 setViewerSelectionMode(TopAbs_FACE);
1169 } else if (theId == "SELECT_RESULT_CMD") {
1170 setViewerSelectionMode(-1);
1171 } else if (theId == "SHOW_RESULTS_CMD") {
1172 highlightResults(aObjects);
1176 //**************************************************************
1177 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1179 myViewerSelMode = theMode;
1180 activateObjectsSelection(myDisplayer->displayedObjects());
1183 //**************************************************************
1184 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1187 module()->activeSelectionModes(aModes);
1188 if (aModes.isEmpty() && (myViewerSelMode != -1))
1189 aModes.append(myViewerSelMode);
1190 myDisplayer->activateObjects(aModes, theList);
1194 //**************************************************************
1195 void XGUI_Workshop::deleteObjects()
1197 ModuleBase_IModule* aModule = module();
1198 // 1. allow the module to delete objects, do nothing if it has succeed
1199 if (aModule->deleteObjects()) {
1200 updateCommandStatus();
1204 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1205 if (!abortAllOperations())
1207 // check whether the object can be deleted. There should not be parts which are not loaded
1208 if (!XGUI_Tools::canRemoveOrRename(desktop(), anObjects))
1211 bool hasResult = false;
1212 bool hasFeature = false;
1213 bool hasParameter = false;
1214 bool hasCompositeOwner = false;
1215 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner);
1216 if (!(hasFeature || hasParameter))
1219 // 3. delete objects
1220 std::set<FeaturePtr> anIgnoredFeatures;
1221 std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
1222 findReferences(anObjects, aDirectRefFeatures, aIndirectRefFeatures);
1224 bool doDeleteReferences = true;
1225 if (isDeleteFeatureWithReferences(anObjects, aDirectRefFeatures, aIndirectRefFeatures,
1226 desktop(), doDeleteReferences)) {
1228 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
1229 aDescription += " " + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1230 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1231 operationMgr()->startOperation(anOpAction);
1233 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1234 // It is necessary to clear selection in order to avoid selection changed event during
1235 // deletion and negative consequences connected with processing of already deleted items
1236 mySelector->clearSelection();
1238 // delete and commit/abort operation in model
1239 if (deleteFeaturesInternal(anObjects, aDirectRefFeatures, aIndirectRefFeatures,
1240 anIgnoredFeatures, doDeleteReferences))
1241 operationMgr()->commitOperation();
1243 operationMgr()->abortOperation(operationMgr()->currentOperation());
1247 //**************************************************************
1248 void XGUI_Workshop::cleanHistory()
1250 if (!abortAllOperations())
1253 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1254 QObjectPtrList aFeatures;
1255 foreach (ObjectPtr anObject, anObjects) {
1256 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1257 // for parameter result, use the corresponded reature to be removed
1258 if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
1259 aFeature = ModelAPI_Feature::feature(anObject);
1261 aFeatures.append(aFeature);
1264 // 1. find all referenced features
1265 QList<ObjectPtr> anUnusedObjects;
1266 std::set<FeaturePtr> aDirectRefFeatures;
1267 //foreach (ObjectPtr anObject, anObjects) {
1268 foreach (ObjectPtr anObject, aFeatures) {
1269 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1270 // for parameter result, use the corresponded reature to be removed
1271 //if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
1272 // aFeature = ModelAPI_Feature::feature(anObject);
1274 if (aFeature.get()) {
1275 std::set<FeaturePtr> alreadyProcessed;
1276 aDirectRefFeatures.clear();
1277 XGUI_Tools::refsDirectToFeatureInAllDocuments(aFeature, aFeature, aFeatures,
1278 aDirectRefFeatures, alreadyProcessed);
1279 if (aDirectRefFeatures.empty() && !anUnusedObjects.contains(aFeature))
1280 anUnusedObjects.append(aFeature);
1284 // 2. warn about the references remove, break the delete operation if the user chose it
1285 if (!anUnusedObjects.empty()) {
1287 foreach (const ObjectPtr& anObject, anUnusedObjects) {
1288 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1289 aNames.append(aFeature->name().c_str());
1291 QString anUnusedNames = aNames.join(", ");
1293 QString anActionId = "CLEAN_HISTORY_CMD";
1294 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1296 QMessageBox aMessageBox(desktop());
1297 aMessageBox.setWindowTitle(aDescription);
1298 aMessageBox.setIcon(QMessageBox::Warning);
1299 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1300 aMessageBox.setDefaultButton(QMessageBox::No);
1302 QString aText = QString(tr("Unused features are the following: %1.\nThese features will be deleted.\nWould you like to continue?")
1303 .arg(anUnusedNames));
1305 if (anUnusedNames.isEmpty()) {
1306 aMessageBox.setStandardButtons(QMessageBox::Ok);
1307 aMessageBox.setDefaultButton(QMessageBox::Ok);
1309 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1312 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1313 aMessageBox.setDefaultButton(QMessageBox::No);
1315 aText = QString(tr("Unused features are the following: %1.\nThese features will be deleted.\nWould you like to continue?")
1316 .arg(anUnusedNames));
1319 aMessageBox.setText(aText);
1320 if (aMessageBox.exec() == QMessageBox::No)
1323 // 1. start operation
1324 aDescription += "by deleting of " + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1325 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1326 operationMgr()->startOperation(anOpAction);
1328 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1329 // It is necessary to clear selection in order to avoid selection changed event during
1330 // deletion and negative consequences connected with processing of already deleted items
1331 mySelector->clearSelection();
1333 std::set<FeaturePtr> anIgnoredFeatures;
1334 if (removeFeatures(anUnusedObjects, anIgnoredFeatures, anActionId)) {
1335 operationMgr()->commitOperation();
1338 operationMgr()->abortOperation(operationMgr()->currentOperation());
1342 QString anActionId = "CLEAN_HISTORY_CMD";
1343 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1345 QMessageBox aMessageBox(desktop());
1346 aMessageBox.setWindowTitle(aDescription);
1347 aMessageBox.setIcon(QMessageBox::Warning);
1348 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1349 aMessageBox.setDefaultButton(QMessageBox::No);
1352 aMessageBox.setStandardButtons(QMessageBox::Ok);
1353 aMessageBox.setDefaultButton(QMessageBox::Ok);
1355 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1356 aMessageBox.setText(aText);
1358 if (aMessageBox.exec() == QMessageBox::No)
1363 //**************************************************************
1364 void XGUI_Workshop::moveObjects()
1366 if (!abortAllOperations())
1369 SessionPtr aMgr = ModelAPI_Session::get();
1371 QString anActionId = "MOVE_CMD";
1372 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1373 aMgr->startOperation(aDescription.toStdString());
1375 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1376 // It is necessary to clear selection in order to avoid selection changed event during
1377 // moving and negative consequences connected with processing of already moved items
1378 mySelector->clearSelection();
1379 // check whether the object can be moved. There should not be parts which are not loaded
1380 if (!XGUI_Tools::canRemoveOrRename(desktop(), anObjects))
1383 DocumentPtr anActiveDocument = aMgr->activeDocument();
1384 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1385 foreach (ObjectPtr aObject, anObjects) {
1386 if (!myModule->canApplyAction(aObject, anActionId))
1389 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1390 if (aFeature.get()) {
1391 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1392 aCurrentFeature = anActiveDocument->currentFeature(true);
1395 aMgr->finishOperation();
1398 //**************************************************************
1399 void XGUI_Workshop::findReferences(const QObjectPtrList& theList,
1400 std::set<FeaturePtr>& aDirectRefFeatures,
1401 std::set<FeaturePtr>& aIndirectRefFeatures)
1403 foreach (ObjectPtr aDeletedObj, theList) {
1404 std::set<FeaturePtr> alreadyProcessed;
1405 XGUI_Tools::refsToFeatureInAllDocuments(aDeletedObj, aDeletedObj, theList, aDirectRefFeatures,
1406 aIndirectRefFeatures, alreadyProcessed);
1407 std::set<FeaturePtr> aDifference;
1408 std::set_difference(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end(),
1409 aDirectRefFeatures.begin(), aDirectRefFeatures.end(),
1410 std::inserter(aDifference, aDifference.begin()));
1411 aIndirectRefFeatures = aDifference;
1415 bool XGUI_Workshop::isDeleteFeatureWithReferences(const QObjectPtrList& theList,
1416 const std::set<FeaturePtr>& aDirectRefFeatures,
1417 const std::set<FeaturePtr>& aIndirectRefFeatures,
1419 bool& doDeleteReferences)
1421 doDeleteReferences = true;
1423 QString aDirectNames, aIndirectNames;
1424 if (!aDirectRefFeatures.empty()) {
1425 QStringList aDirectRefNames;
1426 foreach (const FeaturePtr& aFeature, aDirectRefFeatures)
1427 aDirectRefNames.append(aFeature->name().c_str());
1428 aDirectNames = aDirectRefNames.join(", ");
1430 QStringList aIndirectRefNames;
1431 foreach (const FeaturePtr& aFeature, aIndirectRefFeatures)
1432 aIndirectRefNames.append(aFeature->name().c_str());
1433 aIndirectNames = aIndirectRefNames.join(", ");
1436 bool aCanReplaceParameters = !aDirectRefFeatures.empty();
1437 QStringList aPartFeatureNames;
1438 foreach (ObjectPtr aObj, theList) {
1439 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1440 // invalid feature data means that the feature is already removed in model,
1441 // we needn't process it. E.g. delete of feature from create operation. The operation abort
1442 // will delete the operation
1443 if (!aFeature->data()->isValid())
1445 ResultPtr aFirstResult = aFeature->firstResult();
1446 if (!aFirstResult.get())
1448 std::string aResultGroupName = aFirstResult->groupName();
1449 if (aResultGroupName == ModelAPI_ResultPart::group())
1450 aPartFeatureNames.append(aFeature->name().c_str());
1452 if (aCanReplaceParameters && aResultGroupName != ModelAPI_ResultParameter::group())
1453 aCanReplaceParameters = false;
1455 QString aPartNames = aPartFeatureNames.join(", ");
1457 QMessageBox aMessageBox(theParent);
1458 aMessageBox.setWindowTitle(tr("Delete features"));
1459 aMessageBox.setIcon(QMessageBox::Warning);
1460 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1461 aMessageBox.setDefaultButton(QMessageBox::No);
1464 if (!aDirectNames.isEmpty() || !aIndirectNames.isEmpty()) {
1465 if (aCanReplaceParameters) {
1466 aText = QString(tr("Selected parameters are used in the following features: %1.\nThese features will be deleted.\nOr parameters could be replaced by their values.\n")
1467 .arg(aDirectNames));
1468 if (!aIndirectNames.isEmpty())
1469 aText += QString(tr("(Also these features will be deleted: %1)\n")).arg(aIndirectNames);
1470 QPushButton *aReplaceButton = aMessageBox.addButton(tr("Replace"), QMessageBox::ActionRole);
1472 aText = QString(tr("Selected features are used in the following features: %1.\nThese features will be deleted.\n")).arg(aDirectNames);
1473 if (!aIndirectNames.isEmpty())
1474 aText += QString(tr("(Also these features will be deleted: %1)\n")).arg(aIndirectNames);
1477 if (!aPartNames.isEmpty())
1478 aText += QString(tr("The following parts will be deleted: %1.\n")).arg(aPartNames);
1480 if (!aText.isEmpty()) {
1481 aText += "Would you like to continue?";
1482 aMessageBox.setText(aText);
1484 QMessageBox::ButtonRole aButtonRole = aMessageBox.buttonRole(aMessageBox.clickedButton());
1486 if (aButtonRole == QMessageBox::NoRole)
1489 if (aButtonRole == QMessageBox::ActionRole) {
1490 foreach (ObjectPtr aObj, theList)
1491 ModelAPI_ReplaceParameterMessage::send(aObj, this);
1492 doDeleteReferences = false;
1498 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theFeatures,
1499 const std::set<FeaturePtr>& theIgnoredFeatures)
1501 std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
1502 findReferences(theFeatures, aDirectRefFeatures, aIndirectRefFeatures);
1503 return deleteFeaturesInternal(theFeatures, aDirectRefFeatures, aIndirectRefFeatures,
1504 theIgnoredFeatures);
1507 bool XGUI_Workshop::deleteFeaturesInternal(const QObjectPtrList& theList,
1508 const std::set<FeaturePtr>& aDirectRefFeatures,
1509 const std::set<FeaturePtr>& aIndirectRefFeatures,
1510 const std::set<FeaturePtr>& theIgnoredFeatures,
1511 const bool doDeleteReferences)
1513 if (doDeleteReferences) {
1514 std::set<FeaturePtr> aFeaturesToDelete = aDirectRefFeatures;
1515 aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end());
1516 std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin(),
1517 aLast = aFeaturesToDelete.end();
1521 for (; anIt != aLast; anIt++) {
1522 FeaturePtr aFeature = (*anIt);
1523 DocumentPtr aDoc = aFeature->document();
1524 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end()) {
1525 aDoc->removeFeature(aFeature);
1527 anInfo.append(ModuleBase_Tools::objectInfo(aFeature).toStdString().c_str());
1532 qDebug(QString("remove references:%1").arg(anInfo.join("; ")).toStdString().c_str());
1537 QString anActionId = "DELETE_CMD";
1538 return removeFeatures(theList, theIgnoredFeatures, anActionId);
1541 //**************************************************************
1542 bool XGUI_Workshop::removeFeatures(const QObjectPtrList& theList,
1543 const std::set<FeaturePtr>& theIgnoredFeatures,
1544 const QString& theActionId)
1546 bool isDone = false;
1548 QString anId = QString::fromStdString(theActionId.toStdString().c_str());
1549 QStringList anObjectGroups = contextMenuMgr()->actionObjectGroups(anId);
1550 // 4. remove the parameter features
1551 foreach (ObjectPtr aObj, theList) {
1552 // features and parameters can be removed here,
1553 // the results are removed only by a corresponded feature remove
1554 std::string aGroupName = aObj->groupName();
1555 if (!anObjectGroups.contains(aGroupName.c_str()))
1558 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1560 /*// TODO: to learn the workshop to delegate the Part object deletion to the PartSet module
1561 // part features are removed in the PartSet module. This condition should be moved there
1562 if (aFeature->getKind() == "Part")
1565 DocumentPtr aDoc = aObj->document();
1566 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end()) {
1568 QString anInfoStr = ModuleBase_Tools::objectInfo(aFeature);
1569 anInfo.append(anInfoStr);
1570 qDebug(QString("remove feature :%1").arg(anInfoStr).toStdString().c_str());
1572 aDoc->removeFeature(aFeature);
1578 qDebug(QString("remove features:%1").arg(anInfo.join("; ")).toStdString().c_str());
1583 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1585 bool isFoundResultType = false;
1586 foreach(ObjectPtr anObj, theObjects)
1588 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1589 if (aResult.get() == NULL)
1592 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1593 if (isFoundResultType)
1596 return isFoundResultType;
1599 //**************************************************************
1600 // Returns the list of all features for theDocument and all features of
1601 // all nested parts.
1602 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1604 std::list<FeaturePtr> aResultList;
1605 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1606 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1607 // The order of appending features of the part and the part itself is important
1609 // Append features from a part feature
1610 foreach (const ResultPtr& aResult, aFeature->results()) {
1611 ResultPartPtr aResultPart =
1612 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1613 if (aResultPart.get() && aResultPart->partDoc().get()) {
1615 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1616 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1620 aResultList.push_back(aFeature);
1625 //**************************************************************
1626 // Returns the list of features placed between theObject and the current feature
1627 // in the same document. Excludes theObject, includes the current feature.
1628 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1630 std::list<FeaturePtr> aResult;
1631 DocumentPtr aDocument = theObject->document();
1632 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1633 // find the object iterator
1634 std::list<FeaturePtr>::iterator aObjectIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1635 if (aObjectIt == anAllFeatures.end())
1637 // find the current feature iterator
1638 std::list<FeaturePtr>::iterator aCurrentIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1639 if (aCurrentIt == anAllFeatures.end())
1641 // check the right order
1642 if (std::distance(aObjectIt, anAllFeatures.end()) <= std::distance(aCurrentIt, anAllFeatures.end()))
1644 // exclude the object
1645 std::advance(aObjectIt, 1);
1646 // include the current feature
1647 std::advance(aCurrentIt, 1);
1648 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1651 bool XGUI_Workshop::canMoveFeature()
1653 QString anActionId = "MOVE_CMD";
1655 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1656 QObjectPtrList aValidatedObjects;
1657 foreach (ObjectPtr aObject, aObjects) {
1658 if (!myModule->canApplyAction(aObject, anActionId))
1660 // To be moved feature should be in active document
1661 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1663 aValidatedObjects.append(aObject);
1665 if (aValidatedObjects.size() != aObjects.size())
1666 aObjects = aValidatedObjects;
1668 bool aCanMove = !aObjects.empty();
1670 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1671 for (; anIt != aLast && aCanMove; anIt++) {
1672 ObjectPtr aObject = *anIt;
1673 // 1. Get features placed between selected and current in the document
1674 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1675 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1676 if (aFeaturesBetween.empty())
1679 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1680 // 2. Get all reference features to the selected object in the document
1681 std::set<FeaturePtr> aRefFeatures;
1682 XGUI_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1684 if (aRefFeatures.empty())
1687 // 3. Find any placed features in all reference features
1688 std::set<FeaturePtr> aIntersectionFeatures;
1689 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1690 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1691 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1692 // 4. Return false if any reference feature is placed before current feature
1693 if (!aIntersectionFeatures.empty())
1701 //**************************************************************
1702 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1704 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1705 if (!aCanBeShaded) {
1706 ResultCompSolidPtr aCompsolidResult =
1707 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1708 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1709 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1710 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1713 return aCanBeShaded;
1716 //**************************************************************
1717 bool XGUI_Workshop::canChangeColor() const
1719 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1721 std::set<std::string> aTypes;
1722 aTypes.insert(ModelAPI_ResultGroup::group());
1723 aTypes.insert(ModelAPI_ResultConstruction::group());
1724 aTypes.insert(ModelAPI_ResultBody::group());
1725 aTypes.insert(ModelAPI_ResultPart::group());
1727 return hasResults(aObjects, aTypes);
1730 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
1732 if (!theResult.get())
1735 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1736 if (aColorAttr.get() != NULL) {
1737 if (!aColorAttr->size()) {
1738 aColorAttr->setSize(3);
1740 aColorAttr->setValue(0, theColor[0]);
1741 aColorAttr->setValue(1, theColor[1]);
1742 aColorAttr->setValue(2, theColor[2]);
1746 //**************************************************************
1747 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1750 AttributeIntArrayPtr aColorAttr;
1751 // 1. find the current color of the object. This is a color of AIS presentation
1752 // The objects are iterated until a first valid color is found
1753 std::vector<int> aColor;
1754 foreach(ObjectPtr anObject, theObjects) {
1755 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1756 if (aResult.get()) {
1757 XGUI_CustomPrs::getResultColor(aResult, aColor);
1760 // TODO: remove the obtaining a color from the AIS object
1761 // this does not happen never because:
1762 // 1. The color can be changed only on results
1763 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1764 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1765 if (anAISObj.get()) {
1767 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1770 if (!aColor.empty())
1773 if (aColor.size() != 3)
1776 if (!abortAllOperations())
1778 // 2. show the dialog to change the value
1779 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
1780 aDlg->setColor(aColor);
1781 aDlg->move(QCursor::pos());
1782 bool isDone = aDlg->exec() == QDialog::Accepted;
1786 bool isRandomColor = aDlg->isRandomColor();
1788 // 3. abort the previous operation and start a new one
1789 SessionPtr aMgr = ModelAPI_Session::get();
1790 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1791 aMgr->startOperation(aDescription.toStdString());
1793 // 4. set the value to all results
1794 std::vector<int> aColorResult = aDlg->getColor();
1795 foreach(ObjectPtr anObj, theObjects) {
1796 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1797 if (aResult.get() != NULL) {
1798 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1799 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1800 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1801 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult : aDlg->getRandomColor());
1804 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
1807 aMgr->finishOperation();
1808 updateCommandStatus();
1811 //**************************************************************
1812 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
1813 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
1814 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
1816 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1818 foreach (ObjectPtr aObj, theList) {
1820 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1822 DocumentPtr aDoc = aPartRes->partDoc();
1823 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), isVisible)
1824 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), isVisible)
1825 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), isVisible)
1828 aObj->setDisplayed(isVisible);
1831 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1834 //**************************************************************
1835 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1837 // Hide all displayed objects
1838 QObjectPtrList aList = myDisplayer->displayedObjects();
1839 foreach (ObjectPtr aObj, aList) {
1840 if (module()->canEraseObject(aObj))
1841 aObj->setDisplayed(false);
1844 // Show only objects from the list
1845 foreach (ObjectPtr aObj, theList) {
1847 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1849 DocumentPtr aDoc = aPartRes->partDoc();
1850 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), true)
1851 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), true)
1852 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), true)
1855 aObj->setDisplayed(true);
1858 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1863 //**************************************************************
1864 void XGUI_Workshop::registerValidators() const
1866 SessionPtr aMgr = ModelAPI_Session::get();
1867 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1870 //**************************************************************
1871 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1875 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1876 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1879 //**************************************************************
1880 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1882 for (int i = 0; i < theDoc->size(theGroup); i++)
1883 theDoc->object(theGroup, i)->setDisplayed(true);
1884 //displayObject(theDoc->object(theGroup, i));
1885 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1888 //**************************************************************
1889 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1891 foreach(ObjectPtr aObj, theList) {
1892 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1894 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
1895 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1896 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1897 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
1898 (XGUI_Displayer::DisplayMode)theMode, false);
1902 if (theList.size() > 0)
1903 myDisplayer->updateViewer();
1906 //**************************************************************
1907 void XGUI_Workshop::closeDocument()
1909 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1910 while (anOperation) {
1911 anOperation->abort();
1912 anOperation = operationMgr()->currentOperation();
1914 myDisplayer->closeLocalContexts();
1915 myDisplayer->eraseAll();
1916 objectBrowser()->clearContent();
1918 module()->closeDocument();
1920 SessionPtr aMgr = ModelAPI_Session::get();
1924 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1926 XGUI_HistoryMenu* aMenu = NULL;
1927 if (isSalomeMode()) {
1928 QAction* anAction = qobject_cast<QAction*>(theObject);
1931 aMenu = new XGUI_HistoryMenu(anAction);
1933 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1934 aMenu = new XGUI_HistoryMenu(aButton);
1936 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1937 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1940 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1942 QList<ActionInfo> aResult;
1943 std::list<std::string>::const_iterator it = theList.cbegin();
1944 for (; it != theList.cend(); it++) {
1945 QString anId = QString::fromStdString(*it);
1946 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
1948 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
1951 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
1952 if (aContextMenuAct) {
1953 anInfo.initFrom(aContextMenuAct);
1955 anInfo = myActionsMgr->actionInfoById(anId);
1958 anInfo.text = anInfo.text.prepend("Modify ");
1965 void XGUI_Workshop::synchronizeViewer()
1967 SessionPtr aMgr = ModelAPI_Session::get();
1968 DocumentPtr aDoc = aMgr->activeDocument();
1970 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
1971 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
1972 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
1973 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
1976 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
1977 const std::string& theGroup,
1978 bool theUpdateViewer)
1981 int aSize = theDoc->size(theGroup);
1982 for (int i = 0; i < aSize; i++) {
1983 aObj = theDoc->object(theGroup, i);
1984 if (aObj->isDisplayed()) {
1985 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
1986 // be changed to the object becomes visible when the shape becomes not empty
1987 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1988 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
1990 myDisplayer->display(aObj, false);
1993 if (theUpdateViewer)
1994 myDisplayer->updateViewer();
1997 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
1999 FeaturePtr aFeature;
2000 QObjectPtrList aSelList = theObjects;
2001 std::list<ResultPtr> aResList;
2002 foreach(ObjectPtr aObj, theObjects) {
2003 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2004 if (aFeature.get()) {
2005 aResList = aFeature->results();
2006 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2007 for(aIt = aResList.cbegin(); aIt != aResList.cend(); aIt++) {
2008 aSelList.append(*aIt);
2012 if (aSelList.count() > theObjects.count()) {
2013 // if something was found
2014 bool aBlocked = objectBrowser()->blockSignals(true);
2015 objectBrowser()->setObjectsSelected(aSelList);
2016 objectBrowser()->blockSignals(aBlocked);