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_MenuMgr.h"
8 #include "XGUI_ColorDialog.h"
9 #include "XGUI_ContextMenuMgr.h"
10 #include "XGUI_Displayer.h"
11 #include "XGUI_ErrorDialog.h"
12 #include "XGUI_ErrorMgr.h"
13 #include "XGUI_ModuleConnector.h"
14 #include "XGUI_ObjectsBrowser.h"
15 #include "XGUI_OperationMgr.h"
16 #include "XGUI_PropertyPanel.h"
17 #include "XGUI_SalomeConnector.h"
18 #include "XGUI_Selection.h"
19 #include "XGUI_SelectionMgr.h"
20 #include "XGUI_Tools.h"
21 #include "XGUI_ViewerProxy.h"
22 #include "XGUI_WorkshopListener.h"
23 #include <XGUI_CustomPrs.h>
24 #include <XGUI_HistoryMenu.h>
25 #include <XGUI_QtEvents.h>
28 #include <AppElements_Button.h>
29 #include <AppElements_Command.h>
30 #include <AppElements_MainMenu.h>
31 #include <AppElements_MainWindow.h>
32 #include <AppElements_MenuGroupPanel.h>
33 #include <AppElements_Viewer.h>
34 #include <AppElements_Workbench.h>
37 #include <ModelAPI_AttributeDocRef.h>
38 #include <ModelAPI_AttributeIntArray.h>
39 #include <ModelAPI_Data.h>
40 #include <ModelAPI_Events.h>
41 #include <ModelAPI_Feature.h>
42 #include <ModelAPI_Object.h>
43 #include <ModelAPI_ResultBody.h>
44 #include <ModelAPI_ResultConstruction.h>
45 #include <ModelAPI_ResultGroup.h>
46 #include <ModelAPI_ResultParameter.h>
47 #include <ModelAPI_Session.h>
48 #include <ModelAPI_Validator.h>
49 #include <ModelAPI_ResultCompSolid.h>
50 #include <ModelAPI_Tools.h>
52 //#include <PartSetPlugin_Part.h>
54 #include <Events_Loop.h>
55 #include <Events_Error.h>
56 #include <Events_LongOp.h>
58 #include <ModuleBase_FilterFactory.h>
59 #include <ModuleBase_IModule.h>
60 #include <ModuleBase_IViewer.h>
61 #include <ModuleBase_Operation.h>
62 #include <ModuleBase_OperationDescription.h>
63 #include <ModuleBase_PageBase.h>
64 #include <ModuleBase_Preferences.h>
65 #include <ModuleBase_SelectionValidator.h>
66 #include <ModuleBase_Tools.h>
67 #include <ModuleBase_WidgetFactory.h>
68 #include <ModuleBase_OperationFeature.h>
69 #include <ModuleBase_OperationAction.h>
70 #include <ModuleBase_PagedContainer.h>
71 #include <ModuleBase_WidgetValidated.h>
72 #include <ModuleBase_ModelWidget.h>
74 #include <Config_Common.h>
75 #include <Config_FeatureMessage.h>
76 #include <Config_ModuleReader.h>
77 #include <Config_PointerMessage.h>
78 #include <Config_PropManager.h>
79 #include <Config_SelectionFilterMessage.h>
80 #include <Config_DataModelReader.h>
82 #include <SUIT_ResourceMgr.h>
84 #include <QApplication>
85 #include <QFileDialog>
86 #include <QMessageBox>
87 #include <QMdiSubWindow>
88 #include <QMainWindow>
89 #include <QPushButton>
90 #include <QDockWidget>
95 #include <QToolButton>
97 #include <QDesktopWidget>
113 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
115 //#define DEBUG_DELETE
116 //#define DEBUG_FEATURE_NAME
118 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
120 myCurrentDir(QString()),
122 mySalomeConnector(theConnector),
126 myViewerSelMode(TopAbs_FACE)
129 myMainWindow = new AppElements_MainWindow();
131 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
132 bool aCloc = aResMgr->booleanValue("language", "locale", true);
134 QLocale::setDefault( QLocale::c() );
136 QLocale::setDefault( QLocale::system() );
139 myDataModelXMLReader = new Config_DataModelReader();
140 myDataModelXMLReader->readAll();
142 myDisplayer = new XGUI_Displayer(this);
144 mySelector = new XGUI_SelectionMgr(this);
145 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
147 myOperationMgr = new XGUI_OperationMgr(this, 0);
148 myActionsMgr = new XGUI_ActionsMgr(this);
149 myMenuMgr = new XGUI_MenuMgr(this);
150 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
151 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
152 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
153 SLOT(onContextMenuCommand(const QString&, bool)));
155 myViewerProxy = new XGUI_ViewerProxy(this);
156 //connect(myViewerProxy, SIGNAL(selectionChanged()),
157 // myActionsMgr, SLOT(updateOnViewSelection()));
159 myModuleConnector = new XGUI_ModuleConnector(this);
161 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
162 myOperationMgr->setWorkshop(aWorkshop);
164 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
165 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
167 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
168 SLOT(onOperationStarted(ModuleBase_Operation*)));
169 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
170 SLOT(onOperationResumed(ModuleBase_Operation*)));
171 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
172 SLOT(onOperationStopped(ModuleBase_Operation*)));
173 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
174 SLOT(onOperationCommitted(ModuleBase_Operation*)));
175 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
176 SLOT(onOperationAborted(ModuleBase_Operation*)));
179 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
180 onTrihedronVisibilityChanged(true);
183 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
184 connect(myEventsListener, SIGNAL(errorOccurred(const QString&)),
185 myErrorDlg, SLOT(addError(const QString&)));
187 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
188 // Config_Prop::Color, "225,225,225");
190 Config_PropManager::registerProp("Visualization", "result_body_color", "Body color",
191 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
192 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
193 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
194 Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color",
195 Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
196 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
197 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
200 ModuleBase_Preferences::resourceMgr()->integerValue("Viewer", "selection", TopAbs_FACE);
203 //******************************************************
204 XGUI_Workshop::~XGUI_Workshop(void)
207 delete myDataModelXMLReader;
210 //******************************************************
211 void XGUI_Workshop::startApplication()
215 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
216 Config_Prop::Directory, "");
218 //Initialize event listening
219 myEventsListener->initializeEventListening();
221 registerValidators();
223 // Calling of loadCustomProps before activating module is required
224 // by Config_PropManger to restore user-defined path to plugins
225 ModuleBase_Preferences::loadCustomProps();
229 myMainWindow->show();
230 updateCommandStatus();
235 myViewerProxy->connectViewProxy();
236 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
237 SLOT(onTrihedronVisibilityChanged(bool)));
239 emit applicationStarted();
242 void XGUI_Workshop::activateModule()
244 myModule->activateSelectionFilters();
246 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
247 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
248 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
249 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
251 updateCommandStatus();
253 // TODO: get default selection mode
255 // activate visualized objects in the viewer
256 activateObjectsSelection(displayer()->displayedObjects());
257 myOperationMgr->activate();
260 void XGUI_Workshop::deactivateModule()
262 myModule->deactivateSelectionFilters();
264 // remove internal displayer filter
265 displayer()->deactivateSelectionFilters();
267 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
268 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
269 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
270 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
272 XGUI_Displayer* aDisplayer = displayer();
273 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
274 aDisplayer->deactivateObjects(aDisplayed, true);
276 myOperationMgr->deactivate();
279 //******************************************************
280 void XGUI_Workshop::initMenu()
282 myContextMenuMgr->createActions();
285 // Create only Undo, Redo commands
286 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
287 tr("Undo last command"),
288 QIcon(":pictures/undo.png"),
289 QKeySequence::Undo, false, "MEN_DESK_EDIT");
290 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
291 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
293 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
294 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
296 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
297 QIcon(":pictures/redo.png"), QKeySequence::Redo,
298 false, "MEN_DESK_EDIT");
299 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
301 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
302 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
304 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
305 //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
306 // QIcon(":pictures/rebuild.png"), QKeySequence(),
307 // false, "MEN_DESK_EDIT");
308 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
310 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
311 //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
313 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."), tr("Export the current document into a native file"),
314 QIcon(), QKeySequence(),
315 false, "MEN_DESK_FILE");
316 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
318 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."), tr("Import native file"),
319 QIcon(), QKeySequence(),
320 false, "MEN_DESK_FILE");
321 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
322 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
325 // File commands group
326 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
328 AppElements_Command* aCommand;
330 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
331 QIcon(":pictures/save.png"), QKeySequence::Save);
332 aCommand->connectTo(this, SLOT(onSave()));
333 //aCommand->disable();
335 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
336 QIcon(":pictures/save.png"), QKeySequence());
337 aCommand->connectTo(this, SLOT(onSaveAs()));
339 QString aUndoId = "UNDO_CMD";
340 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
341 QIcon(":pictures/undo.png"), QKeySequence::Undo);
342 aCommand->connectTo(this, SLOT(onUndo()));
343 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
344 addHistoryMenu(aUndoButton,
345 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
348 QString aRedoId = "REDO_CMD";
349 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
350 QIcon(":pictures/redo.png"), QKeySequence::Redo);
351 aCommand->connectTo(this, SLOT(onRedo()));
352 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
353 addHistoryMenu(aRedoButton,
354 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
357 //aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
358 // QIcon(":pictures/rebuild.png"), QKeySequence());
359 //aCommand->connectTo(this, SLOT(onRebuild()));
361 //aCommand->disable();
363 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
364 QIcon(":pictures/open.png"), QKeySequence::Open);
365 aCommand->connectTo(this, SLOT(onOpen()));
367 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
368 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
369 aCommand->connectTo(this, SLOT(onPreferences()));
371 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
372 QIcon(":pictures/close.png"), QKeySequence::Close);
373 aCommand->connectTo(this, SLOT(onExit()));
378 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
380 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
381 return aMenuBar->addWorkbench(theName);
385 //******************************************************
386 QMainWindow* XGUI_Workshop::desktop() const
389 return salomeConnector()->desktop();
395 //******************************************************
396 void XGUI_Workshop::onStartWaiting()
398 if (Events_LongOp::isPerformed()) {
399 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
403 //******************************************************
404 void XGUI_Workshop::onAcceptActionClicked()
406 QAction* anAction = dynamic_cast<QAction*>(sender());
407 XGUI_OperationMgr* anOperationMgr = operationMgr();
408 if (anOperationMgr) {
409 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
410 (anOperationMgr->currentOperation());
412 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
413 myOperationMgr->onCommitOperation();
418 //******************************************************
419 void XGUI_Workshop::onPreviewActionClicked()
421 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
423 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
424 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
425 anActiveWidget->storeValue();
428 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
429 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
430 Events_Loop::loop()->send(aMsg);
433 //******************************************************
434 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
436 if (!myModule->canActivateSelection(theObject)) {
437 if (myDisplayer->isActive(theObject)) {
438 QObjectPtrList anObjects;
439 anObjects.append(theObject);
440 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
445 //******************************************************
446 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
448 bool aHasNested = false;
449 std::string aFeatureKind = theFeature->getKind();
451 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
452 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
455 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
456 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
457 if (aCommand && aCommand->button()->additionalButtonWidget())
463 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
465 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
470 myPropertyPanel->cleanContent();
472 QList<ModuleBase_ModelWidget*> aWidgets;
473 if (!module()->createWidgets(theOperation, aWidgets)) {
474 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
475 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
476 aFactory.createWidget(myPropertyPanel->contentWidget());
477 aWidgets = aFactory.getModelWidgets();
480 // check compatibility of feature and widgets
481 FeaturePtr aFeature = aFOperation->feature();
482 std::string aFeatureKind = aFeature->getKind();
483 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
484 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
485 std::string anErrorMsg = "The feature '" + aFeatureKind + "' has no attribute '"
486 + aWidget->attributeID() + "' used by widget '"
487 + aWidget->metaObject()->className() + "'.";
488 Events_Error::send(anErrorMsg);
489 myPropertyPanel->cleanContent();
493 // for performance purpose, flush should be done after all controls are filled
494 bool isUpdateFlushed = false;
495 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
496 bool isStoreValue = !aFOperation->isEditOperation() &&
497 !aWidget->getDefaultValue().empty() &&
498 !aWidget->isComputedDefault();
499 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
501 aWidget->restoreValue();
502 aWidget->enableFocusProcessing();
504 ModuleBase_Tools::flushUpdated(aFeature);
506 // update visible state of Preview button
508 bool anIsAutoPreview = mySalomeConnector->featureInfo(aFeatureKind.c_str())->isAutoPreview();
510 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
511 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
512 bool anIsAutoPreview = aCommand && aCommand->featureMessage()->isAutoPreview();
514 if (!anIsAutoPreview) {
515 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
516 // send signal about preview should not be computed automatically, click on preview
517 // button should initiate it
518 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
519 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
520 Events_Loop::loop()->send(aMsg);
522 myPropertyPanel->setModelWidgets(aWidgets);
523 aFOperation->setPropertyPanel(myPropertyPanel);
525 myModule->propertyPanelDefined(theOperation);
527 #ifndef DEBUG_FEATURE_NAME
528 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
530 std::string aFeatureName = aFeature->name();
531 myPropertyPanel->setWindowTitle(QString("%1: %2").arg(theOperation->getDescription()->description())
532 .arg(aFeatureName.c_str()));
535 myErrorMgr->setPropertyPanel(myPropertyPanel);
538 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
540 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
541 if (aPropertyPanel) {
542 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
543 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
544 myModule->connectToPropertyPanel(aWidget, isToConnect);
546 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
547 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
548 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
551 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
552 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
553 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
559 //******************************************************
560 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
562 setGrantedFeatures(theOperation);
563 myModule->operationStarted(theOperation);
566 //******************************************************
567 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
569 setGrantedFeatures(theOperation);
571 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
572 setPropertyPanel(theOperation);
573 connectToPropertyPanel(true);
575 updateCommandStatus();
577 myModule->operationResumed(theOperation);
581 //******************************************************
582 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
584 updateCommandStatus();
586 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
591 ModuleBase_ISelection* aSel = mySelector->selection();
592 QObjectPtrList aObj = aSel->selectedPresentations();
593 //!< No need for property panel
595 myPropertyPanel->cleanContent();
597 connectToPropertyPanel(false);
598 myModule->operationStopped(aFOperation);
600 // the deactivated objects of the current operation should be activated back.
601 // They were deactivated on operation start or an object redisplay
602 QObjectPtrList anObjects;
603 FeaturePtr aFeature = aFOperation->feature();
604 if (aFeature.get()) { // feature may be not created (plugin load fail)
605 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
606 anObjects.append(aFeature);
607 std::list<ResultPtr> aResults = aFeature->results();
608 std::list<ResultPtr>::const_iterator aIt;
609 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
610 ResultPtr anObject = *aIt;
611 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
612 anObjects.append(anObject);
616 activateObjectsSelection(anObjects);
620 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
622 myModule->operationCommitted(theOperation);
625 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
627 myModule->operationAborted(theOperation);
630 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
632 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
636 QStringList aGrantedIds;
637 if (isSalomeMode()) {
638 const std::shared_ptr<Config_FeatureMessage>& anInfo =
639 mySalomeConnector->featureInfo(theOperation->id());
641 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
642 .split(" ", QString::SkipEmptyParts);
645 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
647 ModuleBase_IModule* aModule = module();
649 aModule->grantedOperationIds(theOperation, aGrantedIds);
651 aFOperation->setGrantedOperationIds(aGrantedIds);
656 * Saves document with given name.
658 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
660 QApplication::restoreOverrideCursor();
661 SessionPtr aMgr = ModelAPI_Session::get();
662 aMgr->save(theName.toLatin1().constData(), theFileNames);
663 QApplication::restoreOverrideCursor();
666 bool XGUI_Workshop::abortAllOperations()
668 return myOperationMgr->abortAllOperations();
671 //******************************************************
672 void XGUI_Workshop::onOpen()
674 if(!abortAllOperations())
676 //save current file before close if modified
677 SessionPtr aSession = ModelAPI_Session::get();
678 if (aSession->isModified()) {
679 //TODO(sbh): re-launch the app?
680 int anAnswer = QMessageBox::question(
681 desktop(), tr("Save current file"),
682 tr("The document is modified, save before opening another?"),
683 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
684 if (anAnswer == QMessageBox::Save) {
686 } else if (anAnswer == QMessageBox::Cancel) {
692 //show file dialog, check if readable and open
693 myCurrentDir = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
694 if (myCurrentDir.isEmpty())
696 QFileInfo aFileInfo(myCurrentDir);
697 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
698 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
702 QApplication::setOverrideCursor(Qt::WaitCursor);
703 aSession->closeAll();
704 aSession->load(myCurrentDir.toLatin1().constData());
705 myObjectBrowser->rebuildDataTree();
706 updateCommandStatus();
707 QApplication::restoreOverrideCursor();
710 //******************************************************
711 void XGUI_Workshop::onNew()
713 QApplication::setOverrideCursor(Qt::WaitCursor);
714 if (objectBrowser() == 0) {
716 mySelector->connectViewers();
718 myViewerProxy->connectToViewer();
721 myMainWindow->showPythonConsole();
722 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
723 aWnd->showMaximized();
724 updateCommandStatus();
726 myContextMenuMgr->connectViewer();
727 QApplication::restoreOverrideCursor();
731 //******************************************************
732 void XGUI_Workshop::onExit()
734 SessionPtr aMgr = ModelAPI_Session::get();
735 if (aMgr->isModified()) {
736 int anAnswer = QMessageBox::question(
737 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
738 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
739 if (anAnswer == QMessageBox::Save) {
740 bool saved = onSave();
744 } else if (anAnswer == QMessageBox::Cancel) {
751 //******************************************************
752 void XGUI_Workshop::onPreferences()
754 ModuleBase_Prefs aModif;
755 ModuleBase_Preferences::editPreferences(aModif);
756 if (aModif.size() > 0) {
758 foreach (ModuleBase_Pref aPref, aModif)
760 aSection = aPref.first;
761 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
762 myMainWindow->viewer()->updateFromResources();
763 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
764 myMainWindow->menuObject()->updateFromResources();
767 displayer()->redisplayObjects();
772 //******************************************************
773 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
775 XGUI_Displayer* aDisplayer = displayer();
777 aDisplayer->displayTrihedron(theState);
780 //******************************************************
781 bool XGUI_Workshop::onSave()
783 if(!abortAllOperations())
785 if (myCurrentDir.isEmpty()) {
788 std::list<std::string> aFiles;
789 saveDocument(myCurrentDir, aFiles);
790 updateCommandStatus();
792 myMainWindow->setModifiedState(false);
797 //******************************************************
798 bool XGUI_Workshop::onSaveAs()
800 if(!abortAllOperations())
802 QFileDialog dialog(desktop());
803 dialog.setWindowTitle(tr("Select directory to save files..."));
804 dialog.setFileMode(QFileDialog::Directory);
805 dialog.setFilter(tr("Directories (*)"));
806 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
807 dialog.setViewMode(QFileDialog::Detail);
809 if (!dialog.exec()) {
813 QString aTempDir = dialog.selectedFiles().first();
815 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
816 int answer = QMessageBox::question(
818 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
820 tr("The directory already contains some files, save anyway?"),
821 QMessageBox::Save | QMessageBox::Cancel);
822 if (answer == QMessageBox::Cancel) {
826 myCurrentDir = aTempDir;
828 myMainWindow->setCurrentDir(myCurrentDir, false);
829 myMainWindow->setModifiedState(false);
834 //******************************************************
835 void XGUI_Workshop::onUndo(int theTimes)
837 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
838 SessionPtr aMgr = ModelAPI_Session::get();
839 std::list<std::string> aUndoList = aMgr->undoList();
840 if (aMgr->isOperation()) {
841 /// this is important for nested operations
842 /// when sketch operation is active, this condition is false and
843 /// the sketch operation is not aborted
844 operationMgr()->onAbortOperation();
846 std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
847 for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
849 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
850 myObjectBrowser->rebuildDataTree();
853 operationMgr()->updateApplyOfOperations();
854 updateCommandStatus();
857 //******************************************************
858 void XGUI_Workshop::onRedo(int theTimes)
860 // the viewer update should be blocked in order to avoid the features blinking. For the created
861 // feature a results are created, the flush of the created signal caused the viewer redisplay for
862 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked until
863 // redo of all possible objects happens
864 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
866 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
867 SessionPtr aMgr = ModelAPI_Session::get();
868 std::list<std::string> aRedoList = aMgr->redoList();
869 if (aMgr->isOperation()) {
870 /// this is important for nested operations
871 /// when sketch operation is active, this condition is false and
872 /// the sketch operation is not aborted
873 operationMgr()->onAbortOperation();
875 std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
876 for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
878 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
879 myObjectBrowser->rebuildDataTree();
881 operationMgr()->updateApplyOfOperations();
882 updateCommandStatus();
884 // unblock the viewer update functionality and make update on purpose
885 myDisplayer->enableUpdateViewer(isUpdateEnabled);
886 myDisplayer->updateViewer();
889 //******************************************************
890 //void XGUI_Workshop::onRebuild()
892 // SessionPtr aMgr = ModelAPI_Session::get();
893 // bool aWasOperation = aMgr->isOperation(); // keep this value
894 // if (!aWasOperation) {
895 // aMgr->startOperation("Rebuild");
897 // static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
898 // Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
899 // new Events_Message(aRebuildEvent, this)));
900 // if (!aWasOperation) {
901 // aMgr->finishOperation();
903 // updateCommandStatus();
906 //******************************************************
907 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
909 ModuleBase_ModelWidget* anActiveWidget = 0;
910 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
912 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
914 anActiveWidget = aPanel->activeWidget();
917 operationMgr()->onValidateOperation();
919 myModule->widgetStateChanged(thePreviousState);
922 //******************************************************
923 void XGUI_Workshop::onValuesChanged()
925 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
926 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
929 ModuleBase_ModelWidget* anActiveWidget = 0;
930 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
932 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
934 anActiveWidget = aPanel->activeWidget();
936 if (anActiveWidget) {
937 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
939 if (aWidgetValidated)
940 aWidgetValidated->clearValidatedCash();
944 void XGUI_Workshop::onWidgetObjectUpdated()
946 operationMgr()->onValidateOperation();
949 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
951 QString libName = QString::fromStdString(library(theModule.toStdString()));
952 if (libName.isEmpty()) {
953 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
958 CREATE_FUNC crtInst = 0;
961 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
965 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
966 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
967 QString aMsg((char*) &lpMsgBuf);
968 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
969 ::LocalFree(lpMsgBuf);
971 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
975 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
976 | FORMAT_MESSAGE_IGNORE_INSERTS,
977 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
978 QString aMsg((char*) &lpMsgBuf);
979 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
980 ::LocalFree(lpMsgBuf);
984 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
986 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
988 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
990 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
995 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
997 if (!err.isEmpty()) {
999 Events_Error::send(err.toStdString());
1001 qWarning(qPrintable(err));
1007 //******************************************************
1008 bool XGUI_Workshop::createModule()
1010 Config_ModuleReader aModuleReader;
1011 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1012 myModule = loadModule(moduleName);
1016 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1017 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1018 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1019 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1021 myModule->createFeatures();
1023 salomeConnector()->createFeatureActions();
1025 //myActionsMgr->update();
1029 //******************************************************
1030 void XGUI_Workshop::updateCommandStatus()
1032 QList<QAction*> aCommands;
1034 aCommands = salomeConnector()->commandList();
1036 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1037 foreach (AppElements_Command* aCmd, aMenuBar->features())
1038 aCommands.append(aCmd);
1040 SessionPtr aMgr = ModelAPI_Session::get();
1041 if (aMgr->hasModuleDocument()) {
1042 foreach(QAction* aCmd, aCommands) {
1043 QString aId = aCmd->data().toString();
1044 if (aId == "UNDO_CMD")
1045 aCmd->setEnabled(myModule->canUndo());
1046 else if (aId == "REDO_CMD")
1047 aCmd->setEnabled(myModule->canRedo());
1049 // Enable all commands
1050 aCmd->setEnabled(true);
1054 foreach(QAction* aCmd, aCommands) {
1055 QString aId = aCmd->data().toString();
1056 if (aId == "NEW_CMD")
1057 aCmd->setEnabled(true);
1058 else if (aId == "EXIT_CMD")
1059 aCmd->setEnabled(true);
1061 aCmd->setEnabled(false);
1064 myActionsMgr->updateCommandsStatus();
1065 emit commandStatusUpdated();
1068 void XGUI_Workshop::updateHistory()
1070 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1071 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1072 emit updateUndoHistory(aUndoRes);
1074 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1075 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1076 emit updateRedoHistory(aRedoRes);
1079 //******************************************************
1080 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1082 QDockWidget* aObjDock = new QDockWidget(theParent);
1083 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1084 aObjDock->setWindowTitle(tr("Object browser"));
1085 aObjDock->setStyleSheet(
1086 "::title { position: relative; padding-left: 5px; text-align: left center }");
1087 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1088 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1089 myModule->customizeObjectBrowser(myObjectBrowser);
1090 aObjDock->setWidget(myObjectBrowser);
1092 myContextMenuMgr->connectObjectBrowser();
1096 //******************************************************
1098 * Creates dock widgets, places them in corresponding area
1099 * and tabifies if necessary.
1101 void XGUI_Workshop::createDockWidgets()
1103 QMainWindow* aDesktop = desktop();
1104 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1105 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1106 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1107 myPropertyPanel->setupActions(myActionsMgr);
1108 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1109 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1110 hidePropertyPanel(); ///<! Invisible by default
1111 hideObjectBrowser();
1112 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1113 myPropertyPanel->installEventFilter(myOperationMgr);
1115 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1116 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1118 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1119 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1121 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1122 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1124 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1125 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1126 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1127 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1130 //******************************************************
1131 void XGUI_Workshop::showPropertyPanel()
1133 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1134 ///<! Restore ability to close panel from the window's menu
1135 aViewAct->setEnabled(true);
1136 myPropertyPanel->show();
1137 myPropertyPanel->raise();
1139 // The next code is necessary to made the property panel the active window
1140 // in order to operation manager could process key events of the panel.
1141 // otherwise they are ignored. It happens only if the same(activateWindow) is
1142 // not happened by property panel activation(e.g. resume operation of Sketch)
1143 ModuleBase_Tools::activateWindow(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1144 ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1147 //******************************************************
1148 void XGUI_Workshop::hidePropertyPanel()
1150 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1151 ///<! Do not allow to show empty property panel
1152 aViewAct->setEnabled(false);
1153 myPropertyPanel->hide();
1155 // the property panel is active window of the desktop, when it is
1156 // hidden, it is undefined which window becomes active. By this reason
1157 // it is defined to perform the desktop as the active window.
1158 // in SALOME mode, workstack made the PyConsole the active window,
1159 // set the focus on it. As a result, shortcuts of the application, like
1160 // are processed by this console. For example Undo actions.
1161 // It is possible that this code is to be moved to SHAPER package
1162 QMainWindow* aDesktop = desktop();
1163 ModuleBase_Tools::activateWindow(aDesktop, "XGUI_Workshop::hidePropertyPanel()");
1164 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()");
1167 //******************************************************
1168 void XGUI_Workshop::showObjectBrowser()
1170 if (!isSalomeMode())
1171 myObjectBrowser->parentWidget()->show();
1174 //******************************************************
1175 void XGUI_Workshop::hideObjectBrowser()
1177 if (!isSalomeMode())
1178 myObjectBrowser->parentWidget()->hide();
1181 //******************************************************
1182 void XGUI_Workshop::salomeViewerSelectionChanged()
1184 emit salomeViewerSelection();
1187 //**************************************************************
1188 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1190 return mySalomeConnector->viewer();
1193 //**************************************************************
1194 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1196 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1197 if (theId == "DELETE_CMD")
1199 else if (theId == "CLEAN_HISTORY_CMD")
1201 else if (theId == "MOVE_CMD")
1203 else if (theId == "COLOR_CMD")
1204 changeColor(aObjects);
1205 else if (theId == "SHOW_CMD") {
1206 showObjects(aObjects, true);
1207 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1209 else if (theId == "HIDE_CMD")
1210 showObjects(aObjects, false);
1211 else if (theId == "SHOW_ONLY_CMD") {
1212 showOnlyObjects(aObjects);
1213 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1215 else if (theId == "SHADING_CMD")
1216 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1217 else if (theId == "WIREFRAME_CMD")
1218 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1219 else if (theId == "HIDEALL_CMD") {
1220 QObjectPtrList aList = myDisplayer->displayedObjects();
1221 foreach (ObjectPtr aObj, aList) {
1222 if (module()->canEraseObject(aObj))
1223 aObj->setDisplayed(false);
1225 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1226 } else if (theId == "SELECT_VERTEX_CMD") {
1227 setViewerSelectionMode(TopAbs_VERTEX);
1228 } else if (theId == "SELECT_EDGE_CMD") {
1229 setViewerSelectionMode(TopAbs_EDGE);
1230 } else if (theId == "SELECT_FACE_CMD") {
1231 setViewerSelectionMode(TopAbs_FACE);
1232 } else if (theId == "SELECT_RESULT_CMD") {
1233 setViewerSelectionMode(-1);
1234 } else if (theId == "SHOW_RESULTS_CMD") {
1235 highlightResults(aObjects);
1236 } else if (theId == "SHOW_FEATURE_CMD") {
1237 highlightFeature(aObjects);
1241 //**************************************************************
1242 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1244 myViewerSelMode = theMode;
1245 activateObjectsSelection(myDisplayer->displayedObjects());
1248 //**************************************************************
1249 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1252 module()->activeSelectionModes(aModes);
1253 if (aModes.isEmpty() && (myViewerSelMode != -1))
1254 aModes.append(myViewerSelMode);
1255 myDisplayer->activateObjects(aModes, theList);
1259 //**************************************************************
1260 void XGUI_Workshop::deleteObjects()
1262 ModuleBase_IModule* aModule = module();
1263 // 1. allow the module to delete objects, do nothing if it has succeed
1264 if (aModule->deleteObjects()) {
1265 updateCommandStatus();
1269 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1270 if (!abortAllOperations())
1272 // check whether the object can be deleted. There should not be parts which are not loaded
1273 if (!XGUI_Tools::canRemoveOrRename(desktop(), anObjects))
1276 bool hasResult = false;
1277 bool hasFeature = false;
1278 bool hasParameter = false;
1279 bool hasCompositeOwner = false;
1280 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner);
1281 if (!(hasFeature || hasParameter))
1284 // 3. delete objects
1285 std::set<FeaturePtr> anIgnoredFeatures;
1286 std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
1287 ModuleBase_Tools::findReferences(anObjects, aDirectRefFeatures, aIndirectRefFeatures);
1289 bool doDeleteReferences = true;
1290 if (ModuleBase_Tools::isDeleteFeatureWithReferences(anObjects, aDirectRefFeatures,
1291 aIndirectRefFeatures, desktop(), doDeleteReferences)) {
1293 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1294 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1295 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1296 operationMgr()->startOperation(anOpAction);
1298 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1299 // It is necessary to clear selection in order to avoid selection changed event during
1300 // deletion and negative consequences connected with processing of already deleted items
1301 mySelector->clearSelection();
1303 // delete and commit/abort operation in model
1304 if (deleteFeaturesInternal(anObjects, aDirectRefFeatures, aIndirectRefFeatures,
1305 anIgnoredFeatures, doDeleteReferences))
1306 operationMgr()->commitOperation();
1308 operationMgr()->abortOperation(operationMgr()->currentOperation());
1312 //**************************************************************
1313 void XGUI_Workshop::cleanHistory()
1315 if (!abortAllOperations())
1318 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1319 QObjectPtrList aFeatures;
1320 foreach (ObjectPtr anObject, anObjects) {
1321 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1322 // for parameter result, use the corresponded reature to be removed
1323 if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
1324 aFeature = ModelAPI_Feature::feature(anObject);
1326 aFeatures.append(aFeature);
1329 // 1. find all referenced features
1330 QList<ObjectPtr> anUnusedObjects;
1331 std::set<FeaturePtr> aDirectRefFeatures;
1332 //foreach (ObjectPtr anObject, anObjects) {
1333 foreach (ObjectPtr anObject, aFeatures) {
1334 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1335 // for parameter result, use the corresponded reature to be removed
1336 //if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
1337 // aFeature = ModelAPI_Feature::feature(anObject);
1339 if (aFeature.get()) {
1340 std::set<FeaturePtr> alreadyProcessed;
1341 aDirectRefFeatures.clear();
1342 ModuleBase_Tools::refsDirectToFeatureInAllDocuments(aFeature, aFeature, aFeatures,
1343 aDirectRefFeatures, alreadyProcessed);
1344 if (aDirectRefFeatures.empty() && !anUnusedObjects.contains(aFeature))
1345 anUnusedObjects.append(aFeature);
1349 // 2. warn about the references remove, break the delete operation if the user chose it
1350 if (!anUnusedObjects.empty()) {
1352 foreach (const ObjectPtr& anObject, anUnusedObjects) {
1353 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1354 aNames.append(aFeature->name().c_str());
1356 QString anUnusedNames = aNames.join(", ");
1358 QString anActionId = "CLEAN_HISTORY_CMD";
1359 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1361 QMessageBox aMessageBox(desktop());
1362 aMessageBox.setWindowTitle(aDescription);
1363 aMessageBox.setIcon(QMessageBox::Warning);
1364 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1365 aMessageBox.setDefaultButton(QMessageBox::No);
1367 QString aText = QString(tr("Unused features are the following: %1.\nThese features will be deleted.\nWould you like to continue?")
1368 .arg(anUnusedNames));
1370 if (anUnusedNames.isEmpty()) {
1371 aMessageBox.setStandardButtons(QMessageBox::Ok);
1372 aMessageBox.setDefaultButton(QMessageBox::Ok);
1374 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1377 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1378 aMessageBox.setDefaultButton(QMessageBox::No);
1380 aText = QString(tr("Unused features are the following: %1.\nThese features will be deleted.\nWould you like to continue?")
1381 .arg(anUnusedNames));
1384 aMessageBox.setText(aText);
1385 if (aMessageBox.exec() == QMessageBox::No)
1388 // 1. start operation
1389 aDescription += "by deleting of " + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1390 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1391 operationMgr()->startOperation(anOpAction);
1393 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1394 // It is necessary to clear selection in order to avoid selection changed event during
1395 // deletion and negative consequences connected with processing of already deleted items
1396 mySelector->clearSelection();
1398 std::set<FeaturePtr> anIgnoredFeatures;
1399 if (removeFeatures(anUnusedObjects, anIgnoredFeatures, anActionId, true)) {
1400 operationMgr()->commitOperation();
1403 operationMgr()->abortOperation(operationMgr()->currentOperation());
1407 QString anActionId = "CLEAN_HISTORY_CMD";
1408 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1410 QMessageBox aMessageBox(desktop());
1411 aMessageBox.setWindowTitle(aDescription);
1412 aMessageBox.setIcon(QMessageBox::Warning);
1413 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1414 aMessageBox.setDefaultButton(QMessageBox::No);
1417 aMessageBox.setStandardButtons(QMessageBox::Ok);
1418 aMessageBox.setDefaultButton(QMessageBox::Ok);
1420 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1421 aMessageBox.setText(aText);
1423 if (aMessageBox.exec() == QMessageBox::No)
1428 //**************************************************************
1429 void XGUI_Workshop::moveObjects()
1431 if (!abortAllOperations())
1434 SessionPtr aMgr = ModelAPI_Session::get();
1436 QString anActionId = "MOVE_CMD";
1437 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1438 aMgr->startOperation(aDescription.toStdString());
1440 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1441 // It is necessary to clear selection in order to avoid selection changed event during
1442 // moving and negative consequences connected with processing of already moved items
1443 mySelector->clearSelection();
1444 // check whether the object can be moved. There should not be parts which are not loaded
1445 if (!XGUI_Tools::canRemoveOrRename(desktop(), anObjects))
1448 DocumentPtr anActiveDocument = aMgr->activeDocument();
1449 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1450 foreach (ObjectPtr aObject, anObjects) {
1451 if (!myModule->canApplyAction(aObject, anActionId))
1454 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1455 if (aFeature.get()) {
1456 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1457 aCurrentFeature = anActiveDocument->currentFeature(true);
1460 aMgr->finishOperation();
1463 //**************************************************************
1464 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theFeatures,
1465 const std::set<FeaturePtr>& theIgnoredFeatures)
1467 std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
1468 ModuleBase_Tools::findReferences(theFeatures, aDirectRefFeatures, aIndirectRefFeatures);
1469 return deleteFeaturesInternal(theFeatures, aDirectRefFeatures, aIndirectRefFeatures,
1470 theIgnoredFeatures);
1473 bool XGUI_Workshop::deleteFeaturesInternal(const QObjectPtrList& theList,
1474 const std::set<FeaturePtr>& aDirectRefFeatures,
1475 const std::set<FeaturePtr>& aIndirectRefFeatures,
1476 const std::set<FeaturePtr>& theIgnoredFeatures,
1477 const bool doDeleteReferences)
1479 bool isDone = false;
1480 if (doDeleteReferences) {
1481 std::set<FeaturePtr> aFeaturesToDelete = aDirectRefFeatures;
1482 aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end());
1483 std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin(),
1484 aLast = aFeaturesToDelete.end();
1488 for (; anIt != aLast; anIt++) {
1489 FeaturePtr aFeature = (*anIt);
1490 DocumentPtr aDoc = aFeature->document();
1491 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end()) {
1492 // flush REDISPLAY signal after remove feature
1493 aDoc->removeFeature(aFeature);
1496 anInfo.append(ModuleBase_Tools::objectInfo(aFeature).toStdString().c_str());
1501 qDebug(QString("remove references:%1").arg(anInfo.join("; ")).toStdString().c_str());
1506 QString anActionId = "DELETE_CMD";
1507 isDone = removeFeatures(theList, theIgnoredFeatures, anActionId, false) || isDone;
1510 // the redisplay signal should be flushed in order to erase the feature presentation in the viewer
1511 // if should be done after removeFeature() of document
1512 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
1517 //**************************************************************
1518 bool XGUI_Workshop::removeFeatures(const QObjectPtrList& theList,
1519 const std::set<FeaturePtr>& theIgnoredFeatures,
1520 const QString& theActionId,
1521 const bool theFlushRedisplay)
1523 bool isDone = false;
1525 QString anId = QString::fromStdString(theActionId.toStdString().c_str());
1526 QStringList anObjectGroups = contextMenuMgr()->actionObjectGroups(anId);
1527 // 4. remove the parameter features
1528 foreach (ObjectPtr aObj, theList) {
1529 // features and parameters can be removed here,
1530 // the results are removed only by a corresponded feature remove
1531 std::string aGroupName = aObj->groupName();
1532 if (!anObjectGroups.contains(aGroupName.c_str()))
1535 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1537 /*// TODO: to learn the workshop to delegate the Part object deletion to the PartSet module
1538 // part features are removed in the PartSet module. This condition should be moved there
1539 if (aFeature->getKind() == "Part")
1542 DocumentPtr aDoc = aObj->document();
1543 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end()) {
1545 QString anInfoStr = ModuleBase_Tools::objectInfo(aFeature);
1546 anInfo.append(anInfoStr);
1547 qDebug(QString("remove feature :%1").arg(anInfoStr).toStdString().c_str());
1549 // flush REDISPLAY signal after remove feature
1550 aDoc->removeFeature(aFeature);
1555 if (isDone && theFlushRedisplay) {
1556 // the redisplay signal should be flushed in order to erase the feature presentation in the viewer
1557 // if should be done after removeFeature() of document
1558 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
1562 qDebug(QString("remove features:%1").arg(anInfo.join("; ")).toStdString().c_str());
1567 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1569 bool isFoundResultType = false;
1570 foreach(ObjectPtr anObj, theObjects)
1572 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1573 if (aResult.get() == NULL)
1576 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1577 if (isFoundResultType)
1580 return isFoundResultType;
1583 //**************************************************************
1584 // Returns the list of all features for theDocument and all features of
1585 // all nested parts.
1586 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1588 std::list<FeaturePtr> aResultList;
1589 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1590 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1591 // The order of appending features of the part and the part itself is important
1593 // Append features from a part feature
1594 foreach (const ResultPtr& aResult, aFeature->results()) {
1595 ResultPartPtr aResultPart =
1596 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1597 if (aResultPart.get() && aResultPart->partDoc().get()) {
1599 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1600 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1604 aResultList.push_back(aFeature);
1609 //**************************************************************
1610 // Returns the list of features placed between theObject and the current feature
1611 // in the same document. Excludes theObject, includes the current feature.
1612 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1614 std::list<FeaturePtr> aResult;
1615 DocumentPtr aDocument = theObject->document();
1616 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1617 // find the object iterator
1618 std::list<FeaturePtr>::iterator aObjectIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1619 if (aObjectIt == anAllFeatures.end())
1621 // find the current feature iterator
1622 std::list<FeaturePtr>::iterator aCurrentIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1623 if (aCurrentIt == anAllFeatures.end())
1625 // check the right order
1626 if (std::distance(aObjectIt, anAllFeatures.end()) <= std::distance(aCurrentIt, anAllFeatures.end()))
1628 // exclude the object
1629 std::advance(aObjectIt, 1);
1630 // include the current feature
1631 std::advance(aCurrentIt, 1);
1632 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1635 bool XGUI_Workshop::canMoveFeature()
1637 QString anActionId = "MOVE_CMD";
1639 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1640 QObjectPtrList aValidatedObjects;
1641 foreach (ObjectPtr aObject, aObjects) {
1642 if (!myModule->canApplyAction(aObject, anActionId))
1644 // To be moved feature should be in active document
1645 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1647 aValidatedObjects.append(aObject);
1649 if (aValidatedObjects.size() != aObjects.size())
1650 aObjects = aValidatedObjects;
1652 bool aCanMove = !aObjects.empty();
1654 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1655 for (; anIt != aLast && aCanMove; anIt++) {
1656 ObjectPtr aObject = *anIt;
1657 // 1. Get features placed between selected and current in the document
1658 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1659 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1660 if (aFeaturesBetween.empty())
1663 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1664 // 2. Get all reference features to the selected object in the document
1665 std::set<FeaturePtr> aRefFeatures;
1666 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1668 if (aRefFeatures.empty())
1671 // 3. Find any placed features in all reference features
1672 std::set<FeaturePtr> aIntersectionFeatures;
1673 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1674 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1675 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1676 // 4. Return false if any reference feature is placed before current feature
1677 if (!aIntersectionFeatures.empty())
1685 //**************************************************************
1686 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1688 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1689 if (!aCanBeShaded) {
1690 ResultCompSolidPtr aCompsolidResult =
1691 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1692 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1693 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1694 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1697 return aCanBeShaded;
1700 //**************************************************************
1701 bool XGUI_Workshop::canChangeColor() const
1703 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1705 std::set<std::string> aTypes;
1706 aTypes.insert(ModelAPI_ResultGroup::group());
1707 aTypes.insert(ModelAPI_ResultConstruction::group());
1708 aTypes.insert(ModelAPI_ResultBody::group());
1709 aTypes.insert(ModelAPI_ResultPart::group());
1711 return hasResults(aObjects, aTypes);
1714 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
1716 if (!theResult.get())
1719 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1720 if (aColorAttr.get() != NULL) {
1721 if (!aColorAttr->size()) {
1722 aColorAttr->setSize(3);
1724 aColorAttr->setValue(0, theColor[0]);
1725 aColorAttr->setValue(1, theColor[1]);
1726 aColorAttr->setValue(2, theColor[2]);
1730 //**************************************************************
1731 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1734 AttributeIntArrayPtr aColorAttr;
1735 // 1. find the current color of the object. This is a color of AIS presentation
1736 // The objects are iterated until a first valid color is found
1737 std::vector<int> aColor;
1738 foreach(ObjectPtr anObject, theObjects) {
1739 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1740 if (aResult.get()) {
1741 XGUI_CustomPrs::getResultColor(aResult, aColor);
1744 // TODO: remove the obtaining a color from the AIS object
1745 // this does not happen never because:
1746 // 1. The color can be changed only on results
1747 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1748 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1749 if (anAISObj.get()) {
1751 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1754 if (!aColor.empty())
1757 if (aColor.size() != 3)
1760 if (!abortAllOperations())
1762 // 2. show the dialog to change the value
1763 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
1764 aDlg->setColor(aColor);
1765 aDlg->move(QCursor::pos());
1766 bool isDone = aDlg->exec() == QDialog::Accepted;
1770 bool isRandomColor = aDlg->isRandomColor();
1772 // 3. abort the previous operation and start a new one
1773 SessionPtr aMgr = ModelAPI_Session::get();
1774 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1775 aMgr->startOperation(aDescription.toStdString());
1777 // 4. set the value to all results
1778 std::vector<int> aColorResult = aDlg->getColor();
1779 foreach(ObjectPtr anObj, theObjects) {
1780 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1781 if (aResult.get() != NULL) {
1782 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1783 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1784 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1785 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult : aDlg->getRandomColor());
1788 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
1791 aMgr->finishOperation();
1792 updateCommandStatus();
1795 //**************************************************************
1796 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
1797 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
1798 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
1800 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1802 foreach (ObjectPtr aObj, theList) {
1804 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1806 DocumentPtr aDoc = aPartRes->partDoc();
1807 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), isVisible)
1808 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), isVisible)
1809 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), isVisible)
1812 aObj->setDisplayed(isVisible);
1815 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1818 //**************************************************************
1819 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1821 // Hide all displayed objects
1822 QObjectPtrList aList = myDisplayer->displayedObjects();
1823 foreach (ObjectPtr aObj, aList) {
1824 if (module()->canEraseObject(aObj))
1825 aObj->setDisplayed(false);
1828 // Show only objects from the list
1829 foreach (ObjectPtr aObj, theList) {
1831 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1833 DocumentPtr aDoc = aPartRes->partDoc();
1834 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), true)
1835 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), true)
1836 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), true)
1839 aObj->setDisplayed(true);
1842 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1847 //**************************************************************
1848 void XGUI_Workshop::registerValidators() const
1850 SessionPtr aMgr = ModelAPI_Session::get();
1851 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1854 //**************************************************************
1855 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1859 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1860 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1863 //**************************************************************
1864 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1866 for (int i = 0; i < theDoc->size(theGroup); i++)
1867 theDoc->object(theGroup, i)->setDisplayed(true);
1868 //displayObject(theDoc->object(theGroup, i));
1869 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1872 //**************************************************************
1873 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1875 foreach(ObjectPtr aObj, theList) {
1876 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1878 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
1879 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1880 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1881 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
1882 (XGUI_Displayer::DisplayMode)theMode, false);
1886 if (theList.size() > 0)
1887 myDisplayer->updateViewer();
1890 //**************************************************************
1891 void XGUI_Workshop::closeDocument()
1893 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1894 while (anOperation) {
1895 anOperation->abort();
1896 anOperation = operationMgr()->currentOperation();
1898 myDisplayer->closeLocalContexts();
1899 myDisplayer->eraseAll();
1900 objectBrowser()->clearContent();
1902 module()->closeDocument();
1904 SessionPtr aMgr = ModelAPI_Session::get();
1908 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1910 XGUI_HistoryMenu* aMenu = NULL;
1911 if (isSalomeMode()) {
1912 QAction* anAction = qobject_cast<QAction*>(theObject);
1915 aMenu = new XGUI_HistoryMenu(anAction);
1917 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1918 aMenu = new XGUI_HistoryMenu(aButton);
1920 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1921 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1924 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1926 QList<ActionInfo> aResult;
1927 std::list<std::string>::const_iterator it = theList.cbegin();
1928 for (; it != theList.cend(); it++) {
1929 QString anId = QString::fromStdString(*it);
1930 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
1932 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
1935 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
1936 if (aContextMenuAct) {
1937 anInfo.initFrom(aContextMenuAct);
1939 anInfo = myActionsMgr->actionInfoById(anId);
1942 anInfo.text = anInfo.text.prepend("Modify ");
1949 void XGUI_Workshop::synchronizeViewer()
1951 SessionPtr aMgr = ModelAPI_Session::get();
1952 DocumentPtr aDoc = aMgr->activeDocument();
1954 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
1955 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
1956 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
1957 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
1960 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
1961 const std::string& theGroup,
1962 bool theUpdateViewer)
1965 int aSize = theDoc->size(theGroup);
1966 for (int i = 0; i < aSize; i++) {
1967 aObj = theDoc->object(theGroup, i);
1968 if (aObj->isDisplayed()) {
1969 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
1970 // be changed to the object becomes visible when the shape becomes not empty
1971 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1972 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
1974 myDisplayer->display(aObj, false);
1977 if (theUpdateViewer)
1978 myDisplayer->updateViewer();
1981 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
1983 FeaturePtr aFeature;
1984 QObjectPtrList aSelList = theObjects;
1985 std::list<ResultPtr> aResList;
1986 foreach(ObjectPtr aObj, theObjects) {
1987 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1988 if (aFeature.get()) {
1989 aResList = aFeature->results();
1990 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
1991 for(aIt = aResList.cbegin(); aIt != aResList.cend(); aIt++) {
1992 aSelList.append(*aIt);
1996 if (aSelList.count() > theObjects.count()) {
1997 // if something was found
1998 bool aBlocked = objectBrowser()->blockSignals(true);
1999 objectBrowser()->setObjectsSelected(aSelList);
2000 objectBrowser()->blockSignals(aBlocked);
2004 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2007 QObjectPtrList aSelList = theObjects;
2008 FeaturePtr aFeature;
2009 foreach(ObjectPtr aObj, theObjects) {
2010 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2011 if (aResult.get()) {
2012 aFeature = ModelAPI_Feature::feature(aResult);
2013 if (aFeature.get()) {
2014 aSelList.append(aFeature);
2018 if (aSelList.count() > theObjects.count()) {
2019 // if something was found
2020 bool aBlocked = objectBrowser()->blockSignals(true);
2021 objectBrowser()->setObjectsSelected(aSelList);
2022 objectBrowser()->blockSignals(aBlocked);