1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 //#include "XGUI_Constants.h"
4 #include "XGUI_Tools.h"
5 #include "XGUI_Workshop.h"
6 #include "XGUI_SelectionMgr.h"
7 #include "XGUI_Selection.h"
8 #include "XGUI_ObjectsBrowser.h"
9 #include "XGUI_Displayer.h"
10 #include "XGUI_OperationMgr.h"
11 #include "XGUI_SalomeConnector.h"
12 #include "XGUI_ActionsMgr.h"
13 #include "XGUI_ErrorDialog.h"
14 #include "XGUI_ColorDialog.h"
15 #include "XGUI_ViewerProxy.h"
16 #include "XGUI_PropertyPanel.h"
17 #include "XGUI_ContextMenuMgr.h"
18 #include "XGUI_ModuleConnector.h"
19 #include "XGUI_WorkshopListener.h"
21 #include <XGUI_QtEvents.h>
22 #include <XGUI_HistoryMenu.h>
23 #include <XGUI_CustomPrs.h>
25 #include <AppElements_Workbench.h>
26 #include <AppElements_Viewer.h>
27 #include <AppElements_Command.h>
28 #include <AppElements_MainMenu.h>
29 #include <AppElements_MainWindow.h>
30 #include <AppElements_MenuGroupPanel.h>
31 #include <AppElements_Button.h>
33 #include <ModuleBase_IModule.h>
34 #include <ModuleBase_Preferences.h>
36 #include <ModelAPI_Events.h>
37 #include <ModelAPI_Session.h>
38 #include <ModelAPI_Feature.h>
39 #include <ModelAPI_Data.h>
40 #include <ModelAPI_AttributeDocRef.h>
41 #include <ModelAPI_Object.h>
42 #include <ModelAPI_Validator.h>
43 #include <ModelAPI_ResultGroup.h>
44 #include <ModelAPI_ResultConstruction.h>
45 #include <ModelAPI_ResultBody.h>
46 #include <ModelAPI_AttributeIntArray.h>
47 #include <ModelAPI_ResultParameter.h>
49 //#include <PartSetPlugin_Part.h>
51 #include <Events_Loop.h>
52 #include <Events_Error.h>
53 #include <Events_LongOp.h>
55 #include <ModuleBase_Operation.h>
56 #include <ModuleBase_OperationDescription.h>
57 #include <ModuleBase_SelectionValidator.h>
58 #include <ModuleBase_WidgetFactory.h>
59 #include <ModuleBase_Tools.h>
60 #include <ModuleBase_IViewer.h>
61 #include <ModuleBase_FilterFactory.h>
62 #include <ModuleBase_PageBase.h>
63 #include <ModuleBase_Tools.h>
65 #include <Config_Common.h>
66 #include <Config_FeatureMessage.h>
67 #include <Config_PointerMessage.h>
68 #include <Config_ModuleReader.h>
69 #include <Config_PropManager.h>
70 #include <Config_SelectionFilterMessage.h>
72 #include <SUIT_ResourceMgr.h>
74 #include <QApplication>
75 #include <QFileDialog>
76 #include <QMessageBox>
77 #include <QMdiSubWindow>
78 #include <QPushButton>
79 #include <QDockWidget>
84 #include <QToolButton>
86 #include <QDesktopWidget>
99 //#define DEBUG_DELETE
101 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
103 myCurrentDir(QString()),
105 mySalomeConnector(theConnector),
110 myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
113 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
114 bool aCloc = aResMgr->booleanValue("language", "locale", true);
116 QLocale::setDefault( QLocale::c() );
118 QLocale::setDefault( QLocale::system() );
121 myDisplayer = new XGUI_Displayer(this);
123 mySelector = new XGUI_SelectionMgr(this);
124 //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
126 myOperationMgr = new XGUI_OperationMgr(this, 0);
127 myActionsMgr = new XGUI_ActionsMgr(this);
128 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
129 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
130 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
131 SLOT(onContextMenuCommand(const QString&, bool)));
133 myViewerProxy = new XGUI_ViewerProxy(this);
134 connect(myViewerProxy, SIGNAL(selectionChanged()),
135 myActionsMgr, SLOT(updateOnViewSelection()));
137 myModuleConnector = new XGUI_ModuleConnector(this);
139 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
140 myOperationMgr->setWorkshop(aWorkshop);
142 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
144 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
145 SLOT(onOperationStarted(ModuleBase_Operation*)));
146 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
147 SLOT(onOperationResumed(ModuleBase_Operation*)));
148 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
149 SLOT(onOperationStopped(ModuleBase_Operation*)));
150 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
151 SLOT(onOperationCommitted(ModuleBase_Operation*)));
152 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
153 SLOT(onOperationAborted(ModuleBase_Operation*)));
155 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
156 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
157 connect(myEventsListener, SIGNAL(errorOccurred(const QString&)),
158 myErrorDlg, SLOT(addError(const QString&)));
160 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
161 // Config_Prop::Color, "225,225,225");
163 Config_PropManager::registerProp("Visualization", "result_body_color", "Body color",
164 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
165 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
166 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
167 Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color",
168 Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
169 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
170 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
173 //******************************************************
174 XGUI_Workshop::~XGUI_Workshop(void)
179 //******************************************************
180 void XGUI_Workshop::startApplication()
184 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
185 Config_Prop::Directory, "");
187 //Initialize event listening
188 myEventsListener->initializeEventListening();
190 registerValidators();
192 // Calling of loadCustomProps before activating module is required
193 // by Config_PropManger to restore user-defined path to plugins
194 ModuleBase_Preferences::loadCustomProps();
197 myMainWindow->show();
198 updateCommandStatus();
203 emit applicationStarted();
206 void XGUI_Workshop::activateModule()
208 myModule->activateSelectionFilters();
210 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
211 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
212 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
213 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
215 myActionsMgr->update();
219 void XGUI_Workshop::deactivateModule()
221 myModule->deactivateSelectionFilters();
223 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
224 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
225 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
226 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
229 //******************************************************
230 void XGUI_Workshop::initMenu()
232 myContextMenuMgr->createActions();
234 if (isSalomeMode()) {
235 // Create only Undo, Redo commands
236 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
237 tr("Undo last command"),
238 QIcon(":pictures/undo.png"),
239 QKeySequence::Undo, false, "MEN_DESK_EDIT");
240 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
241 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
243 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
244 QIcon(":pictures/redo.png"), QKeySequence::Redo,
245 false, "MEN_DESK_EDIT");
246 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
247 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
249 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
250 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
251 QIcon(":pictures/rebuild.png"), QKeySequence(),
252 false, "MEN_DESK_EDIT");
253 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
254 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
256 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
257 QIcon(), QKeySequence(),
258 false, "MEN_DESK_FILE");
259 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
261 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
262 QIcon(), QKeySequence(),
263 false, "MEN_DESK_FILE");
264 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
265 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
269 // File commands group
270 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
272 AppElements_Command* aCommand;
274 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
275 QIcon(":pictures/save.png"), QKeySequence::Save);
276 aCommand->connectTo(this, SLOT(onSave()));
277 //aCommand->disable();
279 QString aUndoId = "UNDO_CMD";
280 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
281 QIcon(":pictures/undo.png"), QKeySequence::Undo);
282 aCommand->connectTo(this, SLOT(onUndo()));
283 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
284 addHistoryMenu(aUndoButton,
285 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
288 QString aRedoId = "REDO_CMD";
289 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
290 QIcon(":pictures/redo.png"), QKeySequence::Redo);
291 aCommand->connectTo(this, SLOT(onRedo()));
292 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
293 addHistoryMenu(aRedoButton,
294 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
297 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
298 QIcon(":pictures/rebuild.png"), QKeySequence());
299 aCommand->connectTo(this, SLOT(onRebuild()));
301 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
302 QIcon(":pictures/save.png"), QKeySequence());
303 aCommand->connectTo(this, SLOT(onSaveAs()));
304 //aCommand->disable();
306 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
307 QIcon(":pictures/open.png"), QKeySequence::Open);
308 aCommand->connectTo(this, SLOT(onOpen()));
310 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
311 // QIcon(":pictures/new.png"), QKeySequence::New);
312 //aCommand->connectTo(this, SLOT(onNew()));
314 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
315 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
316 aCommand->connectTo(this, SLOT(onPreferences()));
318 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
319 QIcon(":pictures/close.png"), QKeySequence::Close);
320 aCommand->connectTo(this, SLOT(onExit()));
321 //FIXME: SBH's test action. Can be used for some GUI tests.
323 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
324 // QIcon(":pictures/close.png"), QKeySequence(), true);
325 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
329 //******************************************************
330 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
332 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
333 return aMenuBar->addWorkbench(theName);
336 //******************************************************
337 QMainWindow* XGUI_Workshop::desktop() const
339 return isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
342 //******************************************************
343 void XGUI_Workshop::onStartWaiting()
345 if (Events_LongOp::isPerformed()) {
346 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
351 //******************************************************
352 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
354 if (!myModule->canActivateSelection(theObject)) {
355 if (myDisplayer->isActive(theObject))
356 myDisplayer->deactivate(theObject, theUpdateViewer);
360 //******************************************************
361 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
363 setNestedFeatures(theOperation);
365 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
366 connectWithOperation(theOperation);
367 setPropertyPanel(theOperation);
368 // filling the operation values by the current selection
369 // if the operation can be commited after the controls filling, the method perform should
370 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
371 if (!theOperation->isEditOperation()) {
372 theOperation->activateByPreselection();
373 if (operationMgr()->currentOperation() != theOperation)
377 updateCommandStatus();
379 myModule->onOperationStarted(theOperation);
381 // the objects of the current operation should be deactivated
382 QObjectPtrList anObjects;
383 FeaturePtr aFeature = theOperation->feature();
384 anObjects.append(aFeature);
385 std::list<ResultPtr> aResults = aFeature->results();
386 std::list<ResultPtr>::const_iterator aIt;
387 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
388 anObjects.append(*aIt);
390 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
391 for (; anIt != aLast; anIt++)
392 deactivateActiveObject(*anIt, false);
393 if (anObjects.size() > 0)
394 myDisplayer->updateViewer();
397 //******************************************************
398 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
400 setNestedFeatures(theOperation);
402 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
403 // connectWithOperation(theOperation); already connected
404 setPropertyPanel(theOperation);
406 updateCommandStatus();
408 myModule->onOperationResumed(theOperation);
412 //******************************************************
413 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
415 ModuleBase_ISelection* aSel = mySelector->selection();
416 QObjectPtrList aObj = aSel->selectedPresentations();
417 //!< No need for property panel
418 updateCommandStatus();
420 myPropertyPanel->cleanContent();
422 myModule->onOperationStopped(theOperation);
424 // the deactivated objects of the current operation should be activated back.
425 // They were deactivated on operation start or an object redisplay
426 QObjectPtrList anObjects;
427 FeaturePtr aFeature = theOperation->feature();
428 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
429 anObjects.append(aFeature);
430 std::list<ResultPtr> aResults = aFeature->results();
431 std::list<ResultPtr>::const_iterator aIt;
432 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
433 ResultPtr anObject = *aIt;
434 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
435 anObjects.append(anObject);
439 module()->activeSelectionModes(aModes);
440 myDisplayer->activateObjects(aModes, anObjects);
444 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
446 myModule->onOperationCommitted(theOperation);
449 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
451 myModule->onOperationAborted(theOperation);
454 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
456 if (this->isSalomeMode())
457 theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
459 theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
462 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
465 QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
466 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
469 myPropertyPanel->cleanContent();
470 aFactory.createWidget(myPropertyPanel->contentWidget());
472 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
473 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
474 bool isStoreValue = !theOperation->isEditOperation() &&
475 !aWidget->getDefaultValue().empty() &&
476 !aWidget->isComputedDefault();
477 aWidget->setFeature(theOperation->feature(), isStoreValue);
478 aWidget->enableFocusProcessing();
481 myPropertyPanel->setModelWidgets(aWidgets);
482 theOperation->setPropertyPanel(myPropertyPanel);
484 myModule->propertyPanelDefined(theOperation);
486 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
490 * Makes a signal/slot connections between Property Panel
491 * and given operation. The given operation becomes a
492 * current operation and previous operation if exists
494 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
496 QAction* aCommand = 0;
497 if (isSalomeMode()) {
498 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
500 AppElements_MainMenu* aMenu = myMainWindow->menuObject();
501 FeaturePtr aFeature = theOperation->feature();
503 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
505 //Abort operation on uncheck the command
507 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
512 * Saves document with given name.
514 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
516 QApplication::restoreOverrideCursor();
517 SessionPtr aMgr = ModelAPI_Session::get();
518 aMgr->save(theName.toLatin1().constData(), theFileNames);
519 QApplication::restoreOverrideCursor();
522 bool XGUI_Workshop::isActiveOperationAborted()
524 return myOperationMgr->abortAllOperations();
527 //******************************************************
528 void XGUI_Workshop::onExit()
530 SessionPtr aMgr = ModelAPI_Session::get();
531 if (aMgr->isModified()) {
532 int anAnswer = QMessageBox::question(
533 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
534 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
535 if (anAnswer == QMessageBox::Save) {
536 bool saved = onSave();
540 } else if (anAnswer == QMessageBox::Cancel) {
547 //******************************************************
548 void XGUI_Workshop::onNew()
550 QApplication::setOverrideCursor(Qt::WaitCursor);
551 if (objectBrowser() == 0) {
553 mySelector->connectViewers();
555 myViewerProxy->connectToViewer();
557 if (!isSalomeMode()) {
558 myMainWindow->showPythonConsole();
559 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
560 aWnd->showMaximized();
561 updateCommandStatus();
563 myContextMenuMgr->connectViewer();
564 QApplication::restoreOverrideCursor();
567 //******************************************************
568 void XGUI_Workshop::onOpen()
570 if(!isActiveOperationAborted())
572 //save current file before close if modified
573 SessionPtr aSession = ModelAPI_Session::get();
574 if (aSession->isModified()) {
575 //TODO(sbh): re-launch the app?
576 int anAnswer = QMessageBox::question(
577 myMainWindow, tr("Save current file"),
578 tr("The document is modified, save before opening another?"),
579 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
580 if (anAnswer == QMessageBox::Save) {
582 } else if (anAnswer == QMessageBox::Cancel) {
588 //show file dialog, check if readable and open
589 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow(), tr("Select directory"));
590 if (myCurrentDir.isEmpty())
592 QFileInfo aFileInfo(myCurrentDir);
593 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
594 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
598 QApplication::setOverrideCursor(Qt::WaitCursor);
599 aSession->closeAll();
600 aSession->load(myCurrentDir.toLatin1().constData());
601 myObjectBrowser->rebuildDataTree();
602 //displayAllResults();
603 updateCommandStatus();
604 QApplication::restoreOverrideCursor();
607 //******************************************************
608 bool XGUI_Workshop::onSave()
610 if(!isActiveOperationAborted())
612 if (myCurrentDir.isEmpty()) {
615 std::list<std::string> aFiles;
616 saveDocument(myCurrentDir, aFiles);
617 updateCommandStatus();
619 myMainWindow->setModifiedState(false);
623 //******************************************************
624 bool XGUI_Workshop::onSaveAs()
626 if(!isActiveOperationAborted())
628 QFileDialog dialog(mainWindow());
629 dialog.setWindowTitle(tr("Select directory to save files..."));
630 dialog.setFileMode(QFileDialog::Directory);
631 dialog.setFilter(tr("Directories (*)"));
632 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
633 dialog.setViewMode(QFileDialog::Detail);
635 if (!dialog.exec()) {
639 QString aTempDir = dialog.selectedFiles().first();
641 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
642 int answer = QMessageBox::question(
644 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
646 tr("The directory already contains some files, save anyway?"),
647 QMessageBox::Save | QMessageBox::Cancel);
648 if (answer == QMessageBox::Cancel) {
652 myCurrentDir = aTempDir;
653 if (!isSalomeMode()) {
654 myMainWindow->setCurrentDir(myCurrentDir, false);
655 myMainWindow->setModifiedState(false);
660 //******************************************************
661 void XGUI_Workshop::onUndo(int theTimes)
663 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
664 SessionPtr aMgr = ModelAPI_Session::get();
665 if (aMgr->isOperation())
666 operationMgr()->onAbortOperation();
667 for (int i = 0; i < theTimes; ++i) {
670 updateCompositeActionState();
671 updateCommandStatus();
674 //******************************************************
675 void XGUI_Workshop::onRedo(int theTimes)
677 // the viewer update should be blocked in order to avoid the features blinking. For the created
678 // feature a results are created, the flush of the created signal caused the viewer redisplay for
679 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked until
680 // redo of all possible objects happens
681 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
683 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
684 SessionPtr aMgr = ModelAPI_Session::get();
685 if (aMgr->isOperation())
686 operationMgr()->onAbortOperation();
687 for (int i = 0; i < theTimes; ++i) {
690 updateCompositeActionState();
691 updateCommandStatus();
693 // unblock the viewer update functionality and make update on purpose
694 myDisplayer->enableUpdateViewer(isUpdateEnabled);
695 myDisplayer->updateViewer();
698 //******************************************************
699 void XGUI_Workshop::onRebuild()
701 SessionPtr aMgr = ModelAPI_Session::get();
702 bool aWasOperation = aMgr->isOperation(); // keep this value
703 if (!aWasOperation) {
704 aMgr->startOperation("Rebuild");
706 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
707 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
708 new Events_Message(aRebuildEvent, this)));
709 if (!aWasOperation) {
710 aMgr->finishOperation();
712 updateCommandStatus();
715 //******************************************************
716 void XGUI_Workshop::onPreferences()
718 ModuleBase_Prefs aModif;
719 ModuleBase_Preferences::editPreferences(aModif);
720 if (aModif.size() > 0) {
722 foreach (ModuleBase_Pref aPref, aModif)
724 aSection = aPref.first;
725 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
727 myMainWindow->viewer()->updateFromResources();
728 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
730 myMainWindow->menuObject()->updateFromResources();
736 //******************************************************
737 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
739 QString libName = QString::fromStdString(library(theModule.toStdString()));
740 if (libName.isEmpty()) {
741 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
746 CREATE_FUNC crtInst = 0;
749 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
753 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
754 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
755 QString aMsg((char*) &lpMsgBuf);
756 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
757 ::LocalFree(lpMsgBuf);
759 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
763 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
764 | FORMAT_MESSAGE_IGNORE_INSERTS,
765 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
766 QString aMsg((char*) &lpMsgBuf);
767 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
768 ::LocalFree(lpMsgBuf);
772 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
774 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
776 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
778 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
783 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
785 if (!err.isEmpty()) {
787 Events_Error::send(err.toStdString());
789 qWarning(qPrintable(err));
795 //******************************************************
796 bool XGUI_Workshop::createModule()
798 Config_ModuleReader aModuleReader;
799 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
800 myModule = loadModule(moduleName);
804 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
805 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
806 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
807 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
809 myModule->createFeatures();
810 //myActionsMgr->update();
814 //******************************************************
815 void XGUI_Workshop::updateCommandStatus()
817 QList<QAction*> aCommands;
818 if (isSalomeMode()) { // update commands in SALOME mode
819 aCommands = salomeConnector()->commandList();
821 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
822 foreach (AppElements_Command* aCmd, aMenuBar->features())
823 aCommands.append(aCmd);
825 SessionPtr aMgr = ModelAPI_Session::get();
826 if (aMgr->hasModuleDocument()) {
827 foreach(QAction* aCmd, aCommands) {
828 QString aId = aCmd->data().toString();
829 if (aId == "UNDO_CMD")
830 aCmd->setEnabled(myModule->canUndo());
831 else if (aId == "REDO_CMD")
832 aCmd->setEnabled(myModule->canRedo());
834 // Enable all commands
835 aCmd->setEnabled(true);
839 foreach(QAction* aCmd, aCommands) {
840 QString aId = aCmd->data().toString();
841 if (aId == "NEW_CMD")
842 aCmd->setEnabled(true);
843 else if (aId == "EXIT_CMD")
844 aCmd->setEnabled(true);
846 aCmd->setEnabled(false);
849 myActionsMgr->update();
850 emit commandStatusUpdated();
853 //******************************************************
854 void XGUI_Workshop::updateCompositeActionState()
856 // in order to apply is enabled only if there are modifications in the model
857 // e.g. sketch can be applyed only if at least one nested element create is finished
858 bool aCanUndo = ModelAPI_Session::get()->canUndo();
859 bool aParentValid = operationMgr()->isParentOperationValid();
861 QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
862 aAcceptAllAct->setEnabled(aParentValid && aCanUndo);
865 void XGUI_Workshop::updateHistory()
867 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
868 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
869 emit updateUndoHistory(aUndoRes);
871 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
872 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
873 emit updateRedoHistory(aRedoRes);
876 //******************************************************
877 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
879 QDockWidget* aObjDock = new QDockWidget(theParent);
880 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
881 aObjDock->setWindowTitle(tr("Object browser"));
882 aObjDock->setStyleSheet(
883 "::title { position: relative; padding-left: 5px; text-align: left center }");
884 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
885 myObjectBrowser->setDataModel(myModule->dataModel());
886 myModule->customizeObjectBrowser(myObjectBrowser);
887 aObjDock->setWidget(myObjectBrowser);
889 myContextMenuMgr->connectObjectBrowser();
893 //******************************************************
895 * Creates dock widgets, places them in corresponding area
896 * and tabifies if necessary.
898 void XGUI_Workshop::createDockWidgets()
900 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
901 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
902 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
903 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
904 myPropertyPanel->setupActions(myActionsMgr);
905 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
906 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
907 hidePropertyPanel(); ///<! Invisible by default
909 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
910 myPropertyPanel->installEventFilter(myOperationMgr);
912 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
913 connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation()));
914 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
915 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
916 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
917 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
918 myOperationMgr, SLOT(onKeyReleased(QKeyEvent*)));
919 connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
920 aOkAct, SLOT(setEnabled(bool)));
921 QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
922 connect(myOperationMgr, SIGNAL(nestedStateChanged(bool)),
923 aAcceptAllAct, SLOT(setEnabled(bool)));
927 //******************************************************
928 void XGUI_Workshop::showPropertyPanel()
930 QAction* aViewAct = myPropertyPanel->toggleViewAction();
931 ///<! Restore ability to close panel from the window's menu
932 aViewAct->setEnabled(true);
933 myPropertyPanel->show();
934 myPropertyPanel->raise();
937 //******************************************************
938 void XGUI_Workshop::hidePropertyPanel()
940 QAction* aViewAct = myPropertyPanel->toggleViewAction();
941 ///<! Do not allow to show empty property panel
942 aViewAct->setEnabled(false);
943 myPropertyPanel->hide();
946 //******************************************************
947 void XGUI_Workshop::showObjectBrowser()
949 myObjectBrowser->parentWidget()->show();
952 //******************************************************
953 void XGUI_Workshop::hideObjectBrowser()
955 myObjectBrowser->parentWidget()->hide();
958 //******************************************************
959 //void XGUI_Workshop::onFeatureTriggered()
961 // QAction* aCmd = dynamic_cast<QAction*>(sender());
963 // QString aId = salomeConnector()->commandId(aCmd);
964 // if (!aId.isNull())
965 // myModule->launchOperation(aId);
969 //******************************************************
970 void XGUI_Workshop::salomeViewerSelectionChanged()
972 emit salomeViewerSelection();
975 //**************************************************************
976 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
978 return mySalomeConnector->viewer();
981 //**************************************************************
982 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
984 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
985 if (theId == "DELETE_CMD")
987 if (theId == "MOVE_CMD")
989 else if (theId == "COLOR_CMD")
990 changeColor(aObjects);
991 else if (theId == "SHOW_CMD")
992 showObjects(aObjects, true);
993 else if (theId == "HIDE_CMD")
994 showObjects(aObjects, false);
995 else if (theId == "SHOW_ONLY_CMD")
996 showOnlyObjects(aObjects);
997 else if (theId == "SHADING_CMD")
998 setDisplayMode(aObjects, XGUI_Displayer::Shading);
999 else if (theId == "WIREFRAME_CMD")
1000 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1001 else if (theId == "HIDEALL_CMD") {
1002 QObjectPtrList aList = myDisplayer->displayedObjects();
1003 foreach (ObjectPtr aObj, aList)
1004 aObj->setDisplayed(false);
1005 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1009 //**************************************************************
1010 void XGUI_Workshop::deleteObjects()
1012 ModuleBase_IModule* aModule = module();
1013 // 1. allow the module to delete objects, do nothing if it has succeed
1014 if (aModule->deleteObjects()) {
1015 updateCommandStatus();
1019 if (!isActiveOperationAborted())
1021 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1022 // check whether the object can be deleted. There should not be parts which are not loaded
1023 if (!XGUI_Tools::canRemoveOrRename(myMainWindow, anObjects))
1026 bool hasResult = false;
1027 bool hasFeature = false;
1028 bool hasParameter = false;
1029 bool hasSubFeature = false;
1030 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
1031 if (!(hasFeature || hasParameter))
1034 // 1. start operation
1035 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
1036 aDescription += tr(" %1");
1037 QStringList aObjectNames;
1038 foreach (ObjectPtr aObj, anObjects) {
1039 if (!aObj->data()->isValid())
1041 aObjectNames << QString::fromStdString(aObj->data()->name());
1043 aDescription = aDescription.arg(aObjectNames.join(", "));
1045 SessionPtr aMgr = ModelAPI_Session::get();
1046 aMgr->startOperation(aDescription.toStdString());
1047 // 2. close the documents of the removed parts if the result part is in a list of selected objects
1048 // this is performed in the RemoveFeature of Part object.
1049 /*foreach (ObjectPtr aObj, anObjects)
1051 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1053 DocumentPtr aDoc = aObj->document();
1054 if (aDoc == aMgr->activeDocument()) {
1059 // 3. delete objects
1060 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1061 std::set<FeaturePtr> anIgnoredFeatures;
1062 if (deleteFeatures(anObjects, anIgnoredFeatures, aDesktop, true)) {
1063 myDisplayer->updateViewer();
1064 aMgr->finishOperation();
1065 updateCommandStatus();
1068 aMgr->abortOperation();
1072 //**************************************************************
1073 void XGUI_Workshop::moveObjects()
1075 if (!isActiveOperationAborted())
1078 SessionPtr aMgr = ModelAPI_Session::get();
1080 QString aDescription = contextMenuMgr()->action("MOVE_CMD")->text();
1081 aMgr->startOperation(aDescription.toStdString());
1083 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1084 DocumentPtr anActiveDocument = aMgr->activeDocument();
1086 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1087 foreach (ObjectPtr aObj, anObjects) {
1088 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1089 if (aFeature.get()) {
1090 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1091 aCurrentFeature = anActiveDocument->currentFeature(true);
1094 aMgr->finishOperation();
1097 //**************************************************************
1098 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
1099 const std::set<FeaturePtr>& theIgnoredFeatures,
1101 const bool theAskAboutDeleteReferences)
1105 QObjectPtrList::const_iterator aDIt = theList.begin(), aDLast = theList.end();
1106 for (; aDIt != aDLast; ++aDIt) {
1107 aDInfo.append(ModuleBase_Tools::objectInfo((*aDIt)));
1109 QString anInfoStr = aDInfo.join(", ");
1110 qDebug(QString("deleteFeatures: %1, %2").arg(theList.size()).arg(anInfoStr).toStdString().c_str());
1113 // 1. find all referenced features
1114 std::set<FeaturePtr> aRefFeatures;
1115 foreach (ObjectPtr aDeletedObj, theList) {
1116 XGUI_Tools::refsToFeatureInAllDocuments(aDeletedObj, aDeletedObj, aRefFeatures);
1118 // 2. warn about the references remove, break the delete operation if the user chose it
1119 if (theAskAboutDeleteReferences && !aRefFeatures.empty()) {
1120 QStringList aRefNames;
1121 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1122 aLast = aRefFeatures.end();
1123 for (; anIt != aLast; anIt++) {
1124 aRefNames.append((*anIt)->name().c_str());
1126 QString aNames = aRefNames.join(", ");
1128 QMessageBox::StandardButton aRes = QMessageBox::warning(
1129 theParent, tr("Delete features"),
1130 QString(tr("Selected features are used in the following features: %1.\
1131 These features will be deleted also. Would you like to continue?")).arg(aNames),
1132 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1133 if (aRes != QMessageBox::Yes)
1137 // 3. remove referenced features
1138 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1139 aLast = aRefFeatures.end();
1143 for (; anIt != aLast; anIt++) {
1144 FeaturePtr aFeature = (*anIt);
1145 DocumentPtr aDoc = aFeature->document();
1146 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end()) {
1147 aDoc->removeFeature(aFeature);
1149 anInfo.append(ModuleBase_Tools::objectInfo(aFeature).toStdString().c_str());
1154 qDebug(QString("remove references:%1").arg(anInfo.join("; ")).toStdString().c_str());
1158 QString anId = QString::fromStdString("DELETE_CMD");
1159 QStringList anObjectGroups = contextMenuMgr()->actionObjectGroups(anId);
1160 // 4. remove the parameter features
1161 foreach (ObjectPtr aObj, theList) {
1162 // features and parameters can be removed here,
1163 // the results are removed only by a corresponded feature remove
1164 std::string aGroupName = aObj->groupName();
1165 if (!anObjectGroups.contains(aGroupName.c_str()))
1168 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1170 // TODO: to learn the workshop to delegate the Part object deletion to the PartSet module
1171 // part features are removed in the PartSet module. This condition should be moved there
1172 if (aFeature->getKind() == "Part")
1175 DocumentPtr aDoc = aObj->document();
1176 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end()) {
1178 QString anInfoStr = ModuleBase_Tools::objectInfo(aFeature);
1179 anInfo.append(anInfoStr);
1180 qDebug(QString("remove feature :%1").arg(anInfoStr).toStdString().c_str());
1182 aDoc->removeFeature(aFeature);
1187 qDebug(QString("remove features:%1").arg(anInfo.join("; ")).toStdString().c_str());
1192 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1194 bool isFoundResultType = false;
1195 foreach(ObjectPtr anObj, theObjects)
1197 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1198 if (aResult.get() == NULL)
1201 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1202 if (isFoundResultType)
1205 return isFoundResultType;
1208 //**************************************************************
1209 // Returns the list of features placed between theObject and the current feature
1210 // in the same document. Excludes theObject, includes the current feature.
1211 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1213 std::list<FeaturePtr> aResult;
1214 DocumentPtr aDocument = theObject->document();
1215 std::list<FeaturePtr> anAllFeatures = aDocument->allFeatures();
1216 // find the object iterator
1217 std::list<FeaturePtr>::iterator aObjectIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1218 if (aObjectIt == anAllFeatures.end())
1220 // find the current feature iterator
1221 std::list<FeaturePtr>::iterator aCurrentIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1222 if (aCurrentIt == anAllFeatures.end())
1224 // check the right order
1225 if (std::distance(aObjectIt, anAllFeatures.end()) <= std::distance(aCurrentIt, anAllFeatures.end()))
1227 // exclude the object
1228 std::advance(aObjectIt, 1);
1229 // include the current feature
1230 std::advance(aCurrentIt, 1);
1231 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1234 bool XGUI_Workshop::canMoveFeature()
1236 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1237 foreach (ObjectPtr aObject, aObjects) {
1238 // 1. Get features placed between selected and current in the document
1239 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1240 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1241 if (aFeaturesBetween.empty())
1243 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1244 // 2. Get all reference features to the selected object in the document
1245 std::set<FeaturePtr> aRefFeatures;
1246 XGUI_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1248 if (aRefFeatures.empty())
1250 // 3. Find any placed features in all reference features
1251 std::set<FeaturePtr> aIntersectionFeatures;
1252 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1253 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1254 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1255 // 4. Return false if any reference feature is placed before curent feature
1256 if (!aIntersectionFeatures.empty())
1262 //**************************************************************
1263 bool XGUI_Workshop::canChangeColor() const
1265 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1267 std::set<std::string> aTypes;
1268 aTypes.insert(ModelAPI_ResultGroup::group());
1269 aTypes.insert(ModelAPI_ResultConstruction::group());
1270 aTypes.insert(ModelAPI_ResultBody::group());
1271 aTypes.insert(ModelAPI_ResultPart::group());
1273 return hasResults(aObjects, aTypes);
1276 void setColor(ResultPtr theResult, std::vector<int>& theColor)
1278 if (!theResult.get())
1281 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1282 if (aColorAttr.get() != NULL) {
1283 if (!aColorAttr->size()) {
1284 aColorAttr->setSize(3);
1286 aColorAttr->setValue(0, theColor[0]);
1287 aColorAttr->setValue(1, theColor[1]);
1288 aColorAttr->setValue(2, theColor[2]);
1292 //**************************************************************
1293 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1295 AttributeIntArrayPtr aColorAttr;
1296 // 1. find the current color of the object. This is a color of AIS presentation
1297 // The objects are iterated until a first valid color is found
1298 std::vector<int> aColor;
1299 foreach(ObjectPtr anObject, theObjects) {
1300 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1302 XGUI_CustomPrs::getResultColor(aResult, aColor);
1304 // TODO: remove the obtaining a color from the AIS object
1305 // this does not happen never because:
1306 // 1. The color can be changed only on results
1307 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1308 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1309 if (anAISObj.get()) {
1311 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1314 if (!aColor.empty())
1317 if (aColor.size() != 3)
1320 // 2. show the dialog to change the value
1321 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(mainWindow());
1322 aDlg->setColor(aColor);
1323 aDlg->move(QCursor::pos());
1324 bool isDone = aDlg->exec() == QDialog::Accepted;
1328 bool isRandomColor = aDlg->isRandomColor();
1330 // 3. abort the previous operation and start a new one
1331 SessionPtr aMgr = ModelAPI_Session::get();
1332 bool aWasOperation = aMgr->isOperation(); // keep this value
1333 if (!aWasOperation) {
1334 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1335 aMgr->startOperation(aDescription.toStdString());
1338 // 4. set the value to all results
1339 foreach(ObjectPtr anObj, theObjects) {
1340 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1341 if (aResult.get() != NULL) {
1342 std::vector<int> aColorResult = aDlg->getColor();
1343 setColor(aResult, aColorResult);
1347 aMgr->finishOperation();
1348 updateCommandStatus();
1351 //**************************************************************
1352 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
1353 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
1354 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
1356 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1358 foreach (ObjectPtr aObj, theList) {
1360 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1362 DocumentPtr aDoc = aPartRes->partDoc();
1363 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), isVisible)
1364 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), isVisible)
1365 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), isVisible)
1368 aObj->setDisplayed(isVisible);
1371 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1374 //**************************************************************
1375 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1377 // Hide all displayed objects
1378 QObjectPtrList aList = myDisplayer->displayedObjects();
1379 foreach (ObjectPtr aObj, aList)
1380 aObj->setDisplayed(false);
1382 // Show only objects from the list
1383 foreach (ObjectPtr aObj, theList) {
1385 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1387 DocumentPtr aDoc = aPartRes->partDoc();
1388 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), true)
1389 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), true)
1390 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), true)
1393 aObj->setDisplayed(true);
1396 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1401 //**************************************************************
1402 void XGUI_Workshop::registerValidators() const
1404 SessionPtr aMgr = ModelAPI_Session::get();
1405 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1408 //**************************************************************
1409 /*void XGUI_Workshop::displayAllResults()
1411 SessionPtr aMgr = ModelAPI_Session::get();
1412 DocumentPtr aRootDoc = aMgr->moduleDocument();
1413 displayDocumentResults(aRootDoc);
1414 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1415 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1416 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1417 displayDocumentResults(aPart->partDoc());
1419 myDisplayer->updateViewer();
1422 //**************************************************************
1423 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1427 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1428 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1431 //**************************************************************
1432 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1434 for (int i = 0; i < theDoc->size(theGroup); i++)
1435 theDoc->object(theGroup, i)->setDisplayed(true);
1436 //displayObject(theDoc->object(theGroup, i));
1437 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1440 //**************************************************************
1441 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1443 foreach(ObjectPtr aObj, theList) {
1444 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1446 if (theList.size() > 0)
1447 myDisplayer->updateViewer();
1450 //**************************************************************
1451 void XGUI_Workshop::closeDocument()
1453 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1454 while (anOperation) {
1455 anOperation->abort();
1456 anOperation = operationMgr()->currentOperation();
1458 myDisplayer->closeLocalContexts();
1459 myDisplayer->eraseAll();
1460 objectBrowser()->clearContent();
1462 SessionPtr aMgr = ModelAPI_Session::get();
1466 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1468 XGUI_HistoryMenu* aMenu = NULL;
1469 if (isSalomeMode()) {
1470 QAction* anAction = qobject_cast<QAction*>(theObject);
1473 aMenu = new XGUI_HistoryMenu(anAction);
1475 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1476 aMenu = new XGUI_HistoryMenu(aButton);
1478 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1479 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1482 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1484 QList<ActionInfo> aResult;
1485 std::list<std::string>::const_iterator it = theList.cbegin();
1486 for (; it != theList.cend(); it++) {
1487 QString anId = QString::fromStdString(*it);
1488 bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix());
1490 anId.chop(ModuleBase_Operation::EditSuffix().size());
1493 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
1494 if (aContextMenuAct) {
1495 anInfo.initFrom(aContextMenuAct);
1497 anInfo = myActionsMgr->actionInfoById(anId);
1500 anInfo.text = anInfo.text.prepend("Modify ");