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);
369 updateCommandStatus();
371 myModule->onOperationStarted(theOperation);
373 // the objects of the current operation should be deactivated
374 QObjectPtrList anObjects;
375 FeaturePtr aFeature = theOperation->feature();
376 anObjects.append(aFeature);
377 std::list<ResultPtr> aResults = aFeature->results();
378 std::list<ResultPtr>::const_iterator aIt;
379 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
380 anObjects.append(*aIt);
382 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
383 for (; anIt != aLast; anIt++)
384 deactivateActiveObject(*anIt, false);
385 if (anObjects.size() > 0)
386 myDisplayer->updateViewer();
389 //******************************************************
390 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
392 setNestedFeatures(theOperation);
394 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
395 // connectWithOperation(theOperation); already connected
396 setPropertyPanel(theOperation);
398 updateCommandStatus();
400 myModule->onOperationResumed(theOperation);
404 //******************************************************
405 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
407 ModuleBase_ISelection* aSel = mySelector->selection();
408 QObjectPtrList aObj = aSel->selectedPresentations();
409 //!< No need for property panel
410 updateCommandStatus();
412 myPropertyPanel->cleanContent();
414 myModule->onOperationStopped(theOperation);
416 // the deactivated objects of the current operation should be activated back.
417 // They were deactivated on operation start or an object redisplay
418 QObjectPtrList anObjects;
419 FeaturePtr aFeature = theOperation->feature();
420 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
421 anObjects.append(aFeature);
422 std::list<ResultPtr> aResults = aFeature->results();
423 std::list<ResultPtr>::const_iterator aIt;
424 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
425 ResultPtr anObject = *aIt;
426 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
427 anObjects.append(anObject);
431 module()->activeSelectionModes(aModes);
432 myDisplayer->activateObjects(aModes, anObjects);
436 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
438 myModule->onOperationCommitted(theOperation);
441 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
443 myModule->onOperationAborted(theOperation);
446 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
448 if (this->isSalomeMode())
449 theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
451 theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
454 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
457 QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
458 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
461 myPropertyPanel->cleanContent();
462 aFactory.createWidget(myPropertyPanel->contentWidget());
464 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
465 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
466 bool isStoreValue = !theOperation->isEditOperation() &&
467 !aWidget->getDefaultValue().empty() &&
468 !aWidget->isComputedDefault();
469 aWidget->setFeature(theOperation->feature(), isStoreValue);
470 aWidget->enableFocusProcessing();
473 myPropertyPanel->setModelWidgets(aWidgets);
474 theOperation->setPropertyPanel(myPropertyPanel);
476 myModule->propertyPanelDefined(theOperation);
478 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
482 * Makes a signal/slot connections between Property Panel
483 * and given operation. The given operation becomes a
484 * current operation and previous operation if exists
486 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
488 QAction* aCommand = 0;
489 if (isSalomeMode()) {
490 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
492 AppElements_MainMenu* aMenu = myMainWindow->menuObject();
493 FeaturePtr aFeature = theOperation->feature();
495 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
497 //Abort operation on uncheck the command
499 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
504 * Saves document with given name.
506 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
508 QApplication::restoreOverrideCursor();
509 SessionPtr aMgr = ModelAPI_Session::get();
510 aMgr->save(theName.toLatin1().constData(), theFileNames);
511 QApplication::restoreOverrideCursor();
514 bool XGUI_Workshop::isActiveOperationAborted()
516 return myOperationMgr->abortAllOperations();
519 //******************************************************
520 void XGUI_Workshop::onExit()
522 SessionPtr aMgr = ModelAPI_Session::get();
523 if (aMgr->isModified()) {
524 int anAnswer = QMessageBox::question(
525 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
526 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
527 if (anAnswer == QMessageBox::Save) {
528 bool saved = onSave();
532 } else if (anAnswer == QMessageBox::Cancel) {
539 //******************************************************
540 void XGUI_Workshop::onNew()
542 QApplication::setOverrideCursor(Qt::WaitCursor);
543 if (objectBrowser() == 0) {
545 mySelector->connectViewers();
547 myViewerProxy->connectToViewer();
549 if (!isSalomeMode()) {
550 myMainWindow->showPythonConsole();
551 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
552 aWnd->showMaximized();
553 updateCommandStatus();
555 myContextMenuMgr->connectViewer();
556 QApplication::restoreOverrideCursor();
559 //******************************************************
560 void XGUI_Workshop::onOpen()
562 if(!isActiveOperationAborted())
564 //save current file before close if modified
565 SessionPtr aSession = ModelAPI_Session::get();
566 if (aSession->isModified()) {
567 //TODO(sbh): re-launch the app?
568 int anAnswer = QMessageBox::question(
569 myMainWindow, tr("Save current file"),
570 tr("The document is modified, save before opening another?"),
571 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
572 if (anAnswer == QMessageBox::Save) {
574 } else if (anAnswer == QMessageBox::Cancel) {
580 //show file dialog, check if readable and open
581 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow(), tr("Select directory"));
582 if (myCurrentDir.isEmpty())
584 QFileInfo aFileInfo(myCurrentDir);
585 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
586 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
590 QApplication::setOverrideCursor(Qt::WaitCursor);
591 aSession->closeAll();
592 aSession->load(myCurrentDir.toLatin1().constData());
593 myObjectBrowser->rebuildDataTree();
594 //displayAllResults();
595 updateCommandStatus();
596 QApplication::restoreOverrideCursor();
599 //******************************************************
600 bool XGUI_Workshop::onSave()
602 if(!isActiveOperationAborted())
604 if (myCurrentDir.isEmpty()) {
607 std::list<std::string> aFiles;
608 saveDocument(myCurrentDir, aFiles);
609 updateCommandStatus();
611 myMainWindow->setModifiedState(false);
615 //******************************************************
616 bool XGUI_Workshop::onSaveAs()
618 if(!isActiveOperationAborted())
620 QFileDialog dialog(mainWindow());
621 dialog.setWindowTitle(tr("Select directory to save files..."));
622 dialog.setFileMode(QFileDialog::Directory);
623 dialog.setFilter(tr("Directories (*)"));
624 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
625 dialog.setViewMode(QFileDialog::Detail);
627 if (!dialog.exec()) {
631 QString aTempDir = dialog.selectedFiles().first();
633 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
634 int answer = QMessageBox::question(
636 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
638 tr("The directory already contains some files, save anyway?"),
639 QMessageBox::Save | QMessageBox::Cancel);
640 if (answer == QMessageBox::Cancel) {
644 myCurrentDir = aTempDir;
645 if (!isSalomeMode()) {
646 myMainWindow->setCurrentDir(myCurrentDir, false);
647 myMainWindow->setModifiedState(false);
652 //******************************************************
653 void XGUI_Workshop::onUndo(int theTimes)
655 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
656 SessionPtr aMgr = ModelAPI_Session::get();
657 if (aMgr->isOperation())
658 operationMgr()->onAbortOperation();
659 for (int i = 0; i < theTimes; ++i) {
662 updateCommandStatus();
665 //******************************************************
666 void XGUI_Workshop::onRedo(int theTimes)
668 // the viewer update should be blocked in order to avoid the features blinking. For the created
669 // feature a results are created, the flush of the created signal caused the viewer redisplay for
670 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked until
671 // redo of all possible objects happens
672 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
674 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
675 SessionPtr aMgr = ModelAPI_Session::get();
676 if (aMgr->isOperation())
677 operationMgr()->onAbortOperation();
678 for (int i = 0; i < theTimes; ++i) {
681 updateCommandStatus();
683 // unblock the viewer update functionality and make update on purpose
684 myDisplayer->enableUpdateViewer(isUpdateEnabled);
685 myDisplayer->updateViewer();
688 //******************************************************
689 void XGUI_Workshop::onRebuild()
691 SessionPtr aMgr = ModelAPI_Session::get();
692 bool aWasOperation = aMgr->isOperation(); // keep this value
693 if (!aWasOperation) {
694 aMgr->startOperation("Rebuild");
696 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
697 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
698 new Events_Message(aRebuildEvent, this)));
699 if (!aWasOperation) {
700 aMgr->finishOperation();
702 updateCommandStatus();
705 //******************************************************
706 void XGUI_Workshop::onPreferences()
708 ModuleBase_Prefs aModif;
709 ModuleBase_Preferences::editPreferences(aModif);
710 if (aModif.size() > 0) {
712 foreach (ModuleBase_Pref aPref, aModif)
714 aSection = aPref.first;
715 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
717 myMainWindow->viewer()->updateFromResources();
718 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
720 myMainWindow->menuObject()->updateFromResources();
726 //******************************************************
727 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
729 QString libName = QString::fromStdString(library(theModule.toStdString()));
730 if (libName.isEmpty()) {
731 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
736 CREATE_FUNC crtInst = 0;
739 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
743 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
744 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
745 QString aMsg((char*) &lpMsgBuf);
746 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
747 ::LocalFree(lpMsgBuf);
749 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
753 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
754 | FORMAT_MESSAGE_IGNORE_INSERTS,
755 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
756 QString aMsg((char*) &lpMsgBuf);
757 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
758 ::LocalFree(lpMsgBuf);
762 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
764 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
766 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
768 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
773 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
775 if (!err.isEmpty()) {
777 Events_Error::send(err.toStdString());
779 qWarning(qPrintable(err));
785 //******************************************************
786 bool XGUI_Workshop::createModule()
788 Config_ModuleReader aModuleReader;
789 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
790 myModule = loadModule(moduleName);
794 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
795 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
796 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
797 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
799 myModule->createFeatures();
800 //myActionsMgr->update();
804 //******************************************************
805 void XGUI_Workshop::updateCommandStatus()
807 QList<QAction*> aCommands;
808 if (isSalomeMode()) { // update commands in SALOME mode
809 aCommands = salomeConnector()->commandList();
811 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
812 foreach (AppElements_Command* aCmd, aMenuBar->features())
813 aCommands.append(aCmd);
815 SessionPtr aMgr = ModelAPI_Session::get();
816 if (aMgr->hasModuleDocument()) {
817 foreach(QAction* aCmd, aCommands) {
818 QString aId = aCmd->data().toString();
819 if (aId == "UNDO_CMD")
820 aCmd->setEnabled(myModule->canUndo());
821 else if (aId == "REDO_CMD")
822 aCmd->setEnabled(myModule->canRedo());
824 // Enable all commands
825 aCmd->setEnabled(true);
829 foreach(QAction* aCmd, aCommands) {
830 QString aId = aCmd->data().toString();
831 if (aId == "NEW_CMD")
832 aCmd->setEnabled(true);
833 else if (aId == "EXIT_CMD")
834 aCmd->setEnabled(true);
836 aCmd->setEnabled(false);
839 myActionsMgr->update();
840 emit commandStatusUpdated();
843 void XGUI_Workshop::updateHistory()
845 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
846 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
847 emit updateUndoHistory(aUndoRes);
849 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
850 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
851 emit updateRedoHistory(aRedoRes);
854 //******************************************************
855 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
857 QDockWidget* aObjDock = new QDockWidget(theParent);
858 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
859 aObjDock->setWindowTitle(tr("Object browser"));
860 aObjDock->setStyleSheet(
861 "::title { position: relative; padding-left: 5px; text-align: left center }");
862 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
863 myObjectBrowser->setDataModel(myModule->dataModel());
864 myModule->customizeObjectBrowser(myObjectBrowser);
865 aObjDock->setWidget(myObjectBrowser);
867 myContextMenuMgr->connectObjectBrowser();
871 //******************************************************
873 * Creates dock widgets, places them in corresponding area
874 * and tabifies if necessary.
876 void XGUI_Workshop::createDockWidgets()
878 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
879 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
880 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
881 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
882 myPropertyPanel->setupActions(myActionsMgr);
883 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
884 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
885 hidePropertyPanel(); ///<! Invisible by default
887 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
888 myPropertyPanel->installEventFilter(myOperationMgr);
890 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
891 connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation()));
892 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
893 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
894 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
895 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
896 myOperationMgr, SLOT(onKeyReleased(QKeyEvent*)));
897 connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
898 aOkAct, SLOT(setEnabled(bool)));
899 QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
900 connect(myOperationMgr, SIGNAL(nestedStateChanged(bool)),
901 aAcceptAllAct, SLOT(setEnabled(bool)));
905 //******************************************************
906 void XGUI_Workshop::showPropertyPanel()
908 QAction* aViewAct = myPropertyPanel->toggleViewAction();
909 ///<! Restore ability to close panel from the window's menu
910 aViewAct->setEnabled(true);
911 myPropertyPanel->show();
912 myPropertyPanel->raise();
915 //******************************************************
916 void XGUI_Workshop::hidePropertyPanel()
918 QAction* aViewAct = myPropertyPanel->toggleViewAction();
919 ///<! Do not allow to show empty property panel
920 aViewAct->setEnabled(false);
921 myPropertyPanel->hide();
924 //******************************************************
925 void XGUI_Workshop::showObjectBrowser()
927 myObjectBrowser->parentWidget()->show();
930 //******************************************************
931 void XGUI_Workshop::hideObjectBrowser()
933 myObjectBrowser->parentWidget()->hide();
936 //******************************************************
937 //void XGUI_Workshop::onFeatureTriggered()
939 // QAction* aCmd = dynamic_cast<QAction*>(sender());
941 // QString aId = salomeConnector()->commandId(aCmd);
942 // if (!aId.isNull())
943 // myModule->launchOperation(aId);
947 //******************************************************
948 void XGUI_Workshop::salomeViewerSelectionChanged()
950 emit salomeViewerSelection();
953 //**************************************************************
954 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
956 return mySalomeConnector->viewer();
959 //**************************************************************
960 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
962 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
963 if (theId == "DELETE_CMD")
965 if (theId == "MOVE_CMD")
967 else if (theId == "COLOR_CMD")
968 changeColor(aObjects);
969 else if (theId == "SHOW_CMD")
970 showObjects(aObjects, true);
971 else if (theId == "HIDE_CMD")
972 showObjects(aObjects, false);
973 else if (theId == "SHOW_ONLY_CMD")
974 showOnlyObjects(aObjects);
975 else if (theId == "SHADING_CMD")
976 setDisplayMode(aObjects, XGUI_Displayer::Shading);
977 else if (theId == "WIREFRAME_CMD")
978 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
979 else if (theId == "HIDEALL_CMD") {
980 QObjectPtrList aList = myDisplayer->displayedObjects();
981 foreach (ObjectPtr aObj, aList)
982 aObj->setDisplayed(false);
983 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
987 //**************************************************************
988 void XGUI_Workshop::deleteObjects()
990 ModuleBase_IModule* aModule = module();
991 // 1. allow the module to delete objects, do nothing if it has succeed
992 if (aModule->deleteObjects()) {
993 updateCommandStatus();
997 if (!isActiveOperationAborted())
999 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1000 bool hasResult = false;
1001 bool hasFeature = false;
1002 bool hasParameter = false;
1003 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter);
1004 if (!(hasFeature || hasParameter))
1007 // 1. start operation
1008 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
1009 aDescription += tr(" %1");
1010 QStringList aObjectNames;
1011 foreach (ObjectPtr aObj, anObjects) {
1012 if (!aObj->data()->isValid())
1014 aObjectNames << QString::fromStdString(aObj->data()->name());
1016 aDescription = aDescription.arg(aObjectNames.join(", "));
1018 SessionPtr aMgr = ModelAPI_Session::get();
1019 aMgr->startOperation(aDescription.toStdString());
1020 // 2. close the documents of the removed parts if the result part is in a list of selected objects
1021 // this is performed in the RemoveFeature of Part object.
1022 /*foreach (ObjectPtr aObj, anObjects)
1024 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1026 DocumentPtr aDoc = aObj->document();
1027 if (aDoc == aMgr->activeDocument()) {
1032 // 3. delete objects
1033 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1034 std::set<FeaturePtr> anIgnoredFeatures;
1035 if (deleteFeatures(anObjects, anIgnoredFeatures, aDesktop, true)) {
1036 myDisplayer->updateViewer();
1037 aMgr->finishOperation();
1038 updateCommandStatus();
1041 aMgr->abortOperation();
1045 //**************************************************************
1046 void XGUI_Workshop::moveObjects()
1048 if (!isActiveOperationAborted())
1051 SessionPtr aMgr = ModelAPI_Session::get();
1053 QString aDescription = contextMenuMgr()->action("MOVE_CMD")->text();
1054 aMgr->startOperation(aDescription.toStdString());
1056 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1057 DocumentPtr anActiveDocument = aMgr->activeDocument();
1059 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1060 foreach (ObjectPtr aObj, anObjects) {
1061 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1062 if (aFeature.get()) {
1063 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1064 aCurrentFeature = anActiveDocument->currentFeature(true);
1067 aMgr->finishOperation();
1070 //**************************************************************
1071 std::set<FeaturePtr> refFeatures(const ObjectPtr& theObject, bool checkAllDocuments = true)
1073 std::set<FeaturePtr> aRefFeatures;
1074 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1075 if (!aFeature.get())
1076 return aRefFeatures;
1078 DocumentPtr aFeatureDoc = aFeature->document();
1079 // 1. find references in the current document
1080 aFeatureDoc->refsToFeature(aFeature, aRefFeatures, false);
1082 // 2. find references in all documents if the document of the feature is
1083 // "PartSet". Features of this document can be used in all other documents
1084 if (checkAllDocuments) {
1085 SessionPtr aMgr = ModelAPI_Session::get();
1086 DocumentPtr aModuleDoc = aMgr->moduleDocument();
1087 if (aFeatureDoc == aModuleDoc) {
1088 // the feature and results of the feature should be found in references
1089 std::list<ObjectPtr> aDeletedObjects;
1090 aDeletedObjects.push_back(aFeature);
1091 typedef std::list<std::shared_ptr<ModelAPI_Result> > ResultsList;
1092 const ResultsList& aResults = aFeature->results();
1093 ResultsList::const_iterator aRIter = aResults.begin();
1094 for (; aRIter != aResults.cend(); aRIter++) {
1095 ResultPtr aRes = *aRIter;
1097 aDeletedObjects.push_back(aRes);
1099 // get all opened documents; found features in the documents;
1100 // get a list of objects where a feature refers;
1101 // search in these objects the deleted objects.
1102 std::list<DocumentPtr> anOpenedDocs = aMgr->allOpenedDocuments();
1103 std::list<DocumentPtr>::const_iterator anIt = anOpenedDocs.begin(),
1104 aLast = anOpenedDocs.end();
1105 std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
1106 for (; anIt != aLast; anIt++) {
1107 DocumentPtr aDocument = *anIt;
1108 if (aDocument == aFeatureDoc)
1109 continue; // this document has been already processed in 1.1
1111 int aFeaturesCount = aDocument->size(ModelAPI_Feature::group());
1112 for (int aId = 0; aId < aFeaturesCount; aId++) {
1113 ObjectPtr anObject = aDocument->object(ModelAPI_Feature::group(), aId);
1114 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1115 if (!aFeature.get())
1119 aFeature->data()->referencesToObjects(aRefs);
1120 std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRef = aRefs.begin();
1121 bool aHasReferenceToObjetc = false;
1122 for(; aRef != aRefs.end() && !aHasReferenceToObjetc; aRef++) {
1123 std::list<ObjectPtr>::iterator aRefObj = aRef->second.begin();
1124 for(; aRefObj != aRef->second.end() && !aHasReferenceToObjetc; aRefObj++) {
1125 std::list<ObjectPtr>::const_iterator aObjIt = aDeletedObjects.begin();
1126 for(; aObjIt != aDeletedObjects.end() && !aHasReferenceToObjetc; aObjIt++) {
1127 aHasReferenceToObjetc = *aObjIt == *aRefObj;
1131 if (aHasReferenceToObjetc)
1132 aRefFeatures.insert(aFeature);
1137 return aRefFeatures;
1140 //**************************************************************
1141 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
1142 const std::set<FeaturePtr>& theIgnoredFeatures,
1144 const bool theAskAboutDeleteReferences)
1146 // 1. find all referenced features
1147 std::set<FeaturePtr> aRefFeatures;
1148 foreach (ObjectPtr aDeletedObj, theList) {
1149 std::set<FeaturePtr> aFeatures = refFeatures(aDeletedObj);
1150 aRefFeatures.insert(aFeatures.begin(), aFeatures.end());
1152 // 2. warn about the references remove, break the delete operation if the user chose it
1153 if (theAskAboutDeleteReferences && !aRefFeatures.empty()) {
1154 QStringList aRefNames;
1155 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1156 aLast = aRefFeatures.end();
1157 for (; anIt != aLast; anIt++) {
1158 aRefNames.append((*anIt)->name().c_str());
1160 QString aNames = aRefNames.join(", ");
1162 QMessageBox::StandardButton aRes = QMessageBox::warning(
1163 theParent, tr("Delete features"),
1164 QString(tr("Selected features are used in the following features: %1.\
1165 These features will be deleted also. Would you like to continue?")).arg(aNames),
1166 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1167 if (aRes != QMessageBox::Yes)
1171 // 3. remove referenced features
1172 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1173 aLast = aRefFeatures.end();
1177 for (; anIt != aLast; anIt++) {
1178 FeaturePtr aFeature = (*anIt);
1179 DocumentPtr aDoc = aFeature->document();
1180 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end()) {
1181 aDoc->removeFeature(aFeature);
1183 anInfo.append(ModuleBase_Tools::objectInfo(aFeature).toStdString().c_str());
1188 qDebug(QString("remove references:%1").arg(anInfo.join("; ")).toStdString().c_str());
1192 QString anId = QString::fromStdString("DELETE_CMD");
1193 QStringList anObjectGroups = contextMenuMgr()->actionObjectGroups(anId);
1194 // 4. remove the parameter features
1195 foreach (ObjectPtr aObj, theList) {
1196 // features and parameters can be removed here,
1197 // the results are removed only by a corresponded feature remove
1198 std::string aGroupName = aObj->groupName();
1199 if (!anObjectGroups.contains(aGroupName.c_str()))
1202 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1204 // TODO: to learn the workshop to delegate the Part object deletion to the PartSet module
1205 // part features are removed in the PartSet module. This condition should be moved there
1206 if (aFeature->getKind() == "Part")
1209 DocumentPtr aDoc = aObj->document();
1210 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end()) {
1211 aDoc->removeFeature(aFeature);
1213 QString anInfoStr = ModuleBase_Tools::objectInfo(aFeature);
1214 anInfo.append(anInfoStr);
1215 qDebug(QString("remove feature :%1").arg(anInfoStr).toStdString().c_str());
1221 qDebug(QString("remove features:%1").arg(anInfo.join("; ")).toStdString().c_str());
1226 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1228 bool isFoundResultType = false;
1229 foreach(ObjectPtr anObj, theObjects)
1231 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1232 if (aResult.get() == NULL)
1235 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1236 if (isFoundResultType)
1239 return isFoundResultType;
1242 //**************************************************************
1243 bool XGUI_Workshop::canMoveFeature()
1245 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1246 std::set<FeaturePtr> aRefFeatures;
1247 foreach (ObjectPtr aObject, aObjects) {
1248 std::set<FeaturePtr> aFeatures = refFeatures(aObject, false);
1249 aRefFeatures.insert(aFeatures.begin(), aFeatures.end());
1251 return aRefFeatures.empty();
1254 //**************************************************************
1255 bool XGUI_Workshop::canChangeColor() const
1257 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1259 std::set<std::string> aTypes;
1260 aTypes.insert(ModelAPI_ResultGroup::group());
1261 aTypes.insert(ModelAPI_ResultConstruction::group());
1262 aTypes.insert(ModelAPI_ResultBody::group());
1263 aTypes.insert(ModelAPI_ResultPart::group());
1265 return hasResults(aObjects, aTypes);
1268 void setColor(ResultPtr theResult, std::vector<int>& theColor)
1270 if (!theResult.get())
1273 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1274 if (aColorAttr.get() != NULL) {
1275 if (!aColorAttr->size()) {
1276 aColorAttr->setSize(3);
1278 aColorAttr->setValue(0, theColor[0]);
1279 aColorAttr->setValue(1, theColor[1]);
1280 aColorAttr->setValue(2, theColor[2]);
1284 //**************************************************************
1285 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1287 AttributeIntArrayPtr aColorAttr;
1288 // 1. find the current color of the object. This is a color of AIS presentation
1289 // The objects are iterated until a first valid color is found
1290 std::vector<int> aColor;
1291 foreach(ObjectPtr anObject, theObjects) {
1292 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1294 XGUI_CustomPrs::getResultColor(aResult, aColor);
1296 // TODO: remove the obtaining a color from the AIS object
1297 // this does not happen never because:
1298 // 1. The color can be changed only on results
1299 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1300 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1301 if (anAISObj.get()) {
1303 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1306 if (!aColor.empty())
1309 if (aColor.size() != 3)
1312 // 2. show the dialog to change the value
1313 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(mainWindow());
1314 aDlg->setColor(aColor);
1315 aDlg->move(QCursor::pos());
1316 bool isDone = aDlg->exec() == QDialog::Accepted;
1320 bool isRandomColor = aDlg->isRandomColor();
1322 // 3. abort the previous operation and start a new one
1323 SessionPtr aMgr = ModelAPI_Session::get();
1324 bool aWasOperation = aMgr->isOperation(); // keep this value
1325 if (!aWasOperation) {
1326 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1327 aMgr->startOperation(aDescription.toStdString());
1330 // 4. set the value to all results
1331 foreach(ObjectPtr anObj, theObjects) {
1332 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1333 if (aResult.get() != NULL) {
1334 std::vector<int> aColorResult = aDlg->getColor();
1335 setColor(aResult, aColorResult);
1339 aMgr->finishOperation();
1340 updateCommandStatus();
1343 //**************************************************************
1344 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
1345 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
1346 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
1348 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1350 foreach (ObjectPtr aObj, theList) {
1352 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1354 DocumentPtr aDoc = aPartRes->partDoc();
1355 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), isVisible)
1356 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), isVisible)
1357 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), isVisible)
1360 aObj->setDisplayed(isVisible);
1363 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1366 //**************************************************************
1367 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1369 // Hide all displayed objects
1370 QObjectPtrList aList = myDisplayer->displayedObjects();
1371 foreach (ObjectPtr aObj, aList)
1372 aObj->setDisplayed(false);
1374 // Show only objects from the list
1375 foreach (ObjectPtr aObj, theList) {
1377 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1379 DocumentPtr aDoc = aPartRes->partDoc();
1380 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), true)
1381 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), true)
1382 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), true)
1385 aObj->setDisplayed(true);
1388 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1393 //**************************************************************
1394 void XGUI_Workshop::registerValidators() const
1396 SessionPtr aMgr = ModelAPI_Session::get();
1397 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1400 //**************************************************************
1401 /*void XGUI_Workshop::displayAllResults()
1403 SessionPtr aMgr = ModelAPI_Session::get();
1404 DocumentPtr aRootDoc = aMgr->moduleDocument();
1405 displayDocumentResults(aRootDoc);
1406 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1407 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1408 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1409 displayDocumentResults(aPart->partDoc());
1411 myDisplayer->updateViewer();
1414 //**************************************************************
1415 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1419 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1420 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1423 //**************************************************************
1424 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1426 for (int i = 0; i < theDoc->size(theGroup); i++)
1427 theDoc->object(theGroup, i)->setDisplayed(true);
1428 //displayObject(theDoc->object(theGroup, i));
1429 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1432 //**************************************************************
1433 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1435 foreach(ObjectPtr aObj, theList) {
1436 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1438 if (theList.size() > 0)
1439 myDisplayer->updateViewer();
1442 //**************************************************************
1443 void XGUI_Workshop::closeDocument()
1445 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1446 while (anOperation) {
1447 anOperation->abort();
1448 anOperation = operationMgr()->currentOperation();
1450 myDisplayer->closeLocalContexts();
1451 myDisplayer->eraseAll();
1452 objectBrowser()->clearContent();
1454 SessionPtr aMgr = ModelAPI_Session::get();
1458 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1460 XGUI_HistoryMenu* aMenu = NULL;
1461 if (isSalomeMode()) {
1462 QAction* anAction = qobject_cast<QAction*>(theObject);
1465 aMenu = new XGUI_HistoryMenu(anAction);
1467 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1468 aMenu = new XGUI_HistoryMenu(aButton);
1470 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1471 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1474 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1476 QList<ActionInfo> aResult;
1477 std::list<std::string>::const_iterator it = theList.cbegin();
1478 for (; it != theList.cend(); it++) {
1479 QString anId = QString::fromStdString(*it);
1480 bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix());
1482 anId.chop(ModuleBase_Operation::EditSuffix().size());
1485 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
1486 if (aContextMenuAct) {
1487 anInfo.initFrom(aContextMenuAct);
1489 anInfo = myActionsMgr->actionInfoById(anId);
1492 anInfo.text = anInfo.text.prepend("Modify ");