1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 //#include "XGUI_Constants.h"
4 #include "XGUI_Workshop.h"
6 #include "XGUI_ActionsMgr.h"
7 #include "XGUI_ColorDialog.h"
8 #include "XGUI_ContextMenuMgr.h"
9 #include "XGUI_Displayer.h"
10 #include "XGUI_ErrorDialog.h"
11 #include "XGUI_ErrorMgr.h"
12 #include "XGUI_ModuleConnector.h"
13 #include "XGUI_ObjectsBrowser.h"
14 #include "XGUI_OperationMgr.h"
15 #include "XGUI_PropertyPanel.h"
16 #include "XGUI_SalomeConnector.h"
17 #include "XGUI_Selection.h"
18 #include "XGUI_SelectionMgr.h"
19 #include "XGUI_Tools.h"
20 #include "XGUI_ViewerProxy.h"
21 #include "XGUI_WorkshopListener.h"
22 #include <XGUI_CustomPrs.h>
23 #include <XGUI_HistoryMenu.h>
24 #include <XGUI_QtEvents.h>
26 #include <AppElements_Button.h>
27 #include <AppElements_Command.h>
28 #include <AppElements_MainMenu.h>
29 #include <AppElements_MainWindow.h>
30 #include <AppElements_MenuGroupPanel.h>
31 #include <AppElements_Viewer.h>
32 #include <AppElements_Workbench.h>
34 #include <ModelAPI_AttributeDocRef.h>
35 #include <ModelAPI_AttributeIntArray.h>
36 #include <ModelAPI_Data.h>
37 #include <ModelAPI_Events.h>
38 #include <ModelAPI_Feature.h>
39 #include <ModelAPI_Object.h>
40 #include <ModelAPI_ResultBody.h>
41 #include <ModelAPI_ResultConstruction.h>
42 #include <ModelAPI_ResultGroup.h>
43 #include <ModelAPI_ResultParameter.h>
44 #include <ModelAPI_Session.h>
45 #include <ModelAPI_Validator.h>
46 #include <ModelAPI_ResultCompSolid.h>
47 #include <ModelAPI_Tools.h>
49 //#include <PartSetPlugin_Part.h>
51 #include <Events_Loop.h>
52 #include <Events_Error.h>
53 #include <Events_LongOp.h>
55 #include <ModuleBase_FilterFactory.h>
56 #include <ModuleBase_IModule.h>
57 #include <ModuleBase_IViewer.h>
58 #include <ModuleBase_Operation.h>
59 #include <ModuleBase_OperationDescription.h>
60 #include <ModuleBase_PageBase.h>
61 #include <ModuleBase_Preferences.h>
62 #include <ModuleBase_SelectionValidator.h>
63 #include <ModuleBase_Tools.h>
64 #include <ModuleBase_WidgetFactory.h>
65 #include <ModuleBase_OperationFeature.h>
67 #include <Config_Common.h>
68 #include <Config_FeatureMessage.h>
69 #include <Config_ModuleReader.h>
70 #include <Config_PointerMessage.h>
71 #include <Config_PropManager.h>
72 #include <Config_SelectionFilterMessage.h>
74 #include <SUIT_ResourceMgr.h>
76 #include <QApplication>
77 #include <QFileDialog>
78 #include <QMessageBox>
79 #include <QMdiSubWindow>
80 #include <QPushButton>
81 #include <QDockWidget>
86 #include <QToolButton>
88 #include <QDesktopWidget>
103 //#define DEBUG_DELETE
105 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
107 myCurrentDir(QString()),
109 mySalomeConnector(theConnector),
114 myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
117 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
118 bool aCloc = aResMgr->booleanValue("language", "locale", true);
120 QLocale::setDefault( QLocale::c() );
122 QLocale::setDefault( QLocale::system() );
125 myDisplayer = new XGUI_Displayer(this);
127 mySelector = new XGUI_SelectionMgr(this);
128 //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
130 myOperationMgr = new XGUI_OperationMgr(this, 0);
131 myActionsMgr = new XGUI_ActionsMgr(this);
132 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
133 myErrorMgr = new XGUI_ErrorMgr(this);
134 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
135 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
136 SLOT(onContextMenuCommand(const QString&, bool)));
138 myViewerProxy = new XGUI_ViewerProxy(this);
139 connect(myViewerProxy, SIGNAL(selectionChanged()),
140 myActionsMgr, SLOT(updateOnViewSelection()));
142 myModuleConnector = new XGUI_ModuleConnector(this);
144 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
145 myOperationMgr->setWorkshop(aWorkshop);
147 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
149 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
150 SLOT(onOperationStarted(ModuleBase_Operation*)));
151 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
152 SLOT(onOperationResumed(ModuleBase_Operation*)));
153 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
154 SLOT(onOperationStopped(ModuleBase_Operation*)));
155 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
156 SLOT(onOperationCommitted(ModuleBase_Operation*)));
157 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
158 SLOT(onOperationAborted(ModuleBase_Operation*)));
159 connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
160 myErrorMgr, SLOT(onValidationStateChanged()));
163 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
164 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
165 connect(myEventsListener, SIGNAL(errorOccurred(const QString&)),
166 myErrorDlg, SLOT(addError(const QString&)));
168 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
169 // Config_Prop::Color, "225,225,225");
171 Config_PropManager::registerProp("Visualization", "result_body_color", "Body color",
172 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
173 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
174 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
175 Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color",
176 Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
177 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
178 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
181 //******************************************************
182 XGUI_Workshop::~XGUI_Workshop(void)
187 //******************************************************
188 void XGUI_Workshop::startApplication()
192 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
193 Config_Prop::Directory, "");
195 //Initialize event listening
196 myEventsListener->initializeEventListening();
198 registerValidators();
200 // Calling of loadCustomProps before activating module is required
201 // by Config_PropManger to restore user-defined path to plugins
202 ModuleBase_Preferences::loadCustomProps();
205 myMainWindow->show();
206 updateCommandStatus();
211 emit applicationStarted();
214 void XGUI_Workshop::activateModule()
216 myModule->activateSelectionFilters();
218 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
219 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
220 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
221 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
223 myActionsMgr->update();
227 void XGUI_Workshop::deactivateModule()
229 myModule->deactivateSelectionFilters();
231 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
232 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
233 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
234 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
237 //******************************************************
238 void XGUI_Workshop::initMenu()
240 myContextMenuMgr->createActions();
242 if (isSalomeMode()) {
243 // Create only Undo, Redo commands
244 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
245 tr("Undo last command"),
246 QIcon(":pictures/undo.png"),
247 QKeySequence::Undo, false, "MEN_DESK_EDIT");
248 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
249 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
251 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
252 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
254 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
255 QIcon(":pictures/redo.png"), QKeySequence::Redo,
256 false, "MEN_DESK_EDIT");
257 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
259 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
260 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
262 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
263 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
264 QIcon(":pictures/rebuild.png"), QKeySequence(),
265 false, "MEN_DESK_EDIT");
266 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
268 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
269 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
271 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
272 QIcon(), QKeySequence(),
273 false, "MEN_DESK_FILE");
274 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
276 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
277 QIcon(), QKeySequence(),
278 false, "MEN_DESK_FILE");
279 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
280 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
284 // File commands group
285 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
287 AppElements_Command* aCommand;
289 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
290 QIcon(":pictures/save.png"), QKeySequence::Save);
291 aCommand->connectTo(this, SLOT(onSave()));
292 //aCommand->disable();
294 QString aUndoId = "UNDO_CMD";
295 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
296 QIcon(":pictures/undo.png"), QKeySequence::Undo);
297 aCommand->connectTo(this, SLOT(onUndo()));
298 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
299 addHistoryMenu(aUndoButton,
300 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
303 QString aRedoId = "REDO_CMD";
304 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
305 QIcon(":pictures/redo.png"), QKeySequence::Redo);
306 aCommand->connectTo(this, SLOT(onRedo()));
307 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
308 addHistoryMenu(aRedoButton,
309 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
312 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
313 QIcon(":pictures/rebuild.png"), QKeySequence());
314 aCommand->connectTo(this, SLOT(onRebuild()));
316 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
317 QIcon(":pictures/save.png"), QKeySequence());
318 aCommand->connectTo(this, SLOT(onSaveAs()));
319 //aCommand->disable();
321 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
322 QIcon(":pictures/open.png"), QKeySequence::Open);
323 aCommand->connectTo(this, SLOT(onOpen()));
325 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
326 // QIcon(":pictures/new.png"), QKeySequence::New);
327 //aCommand->connectTo(this, SLOT(onNew()));
329 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
330 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
331 aCommand->connectTo(this, SLOT(onPreferences()));
333 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
334 QIcon(":pictures/close.png"), QKeySequence::Close);
335 aCommand->connectTo(this, SLOT(onExit()));
336 //FIXME: SBH's test action. Can be used for some GUI tests.
338 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
339 // QIcon(":pictures/close.png"), QKeySequence(), true);
340 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
344 //******************************************************
345 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
347 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
348 return aMenuBar->addWorkbench(theName);
351 //******************************************************
352 QMainWindow* XGUI_Workshop::desktop() const
354 return isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
357 //******************************************************
358 void XGUI_Workshop::onStartWaiting()
360 if (Events_LongOp::isPerformed()) {
361 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
366 //******************************************************
367 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
369 if (!myModule->canActivateSelection(theObject)) {
370 if (myDisplayer->isActive(theObject))
371 myDisplayer->deactivate(theObject, theUpdateViewer);
375 //******************************************************
376 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
378 setNestedFeatures(theOperation);
380 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
385 if (aFOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
386 setPropertyPanel(aFOperation);
387 // filling the operation values by the current selection
388 // if the operation can be commited after the controls filling, the method perform should
389 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
390 if (!aFOperation->isEditOperation()) {
391 aFOperation->activateByPreselection();
392 if (operationMgr()->currentOperation() != aFOperation)
396 updateCommandStatus();
398 myModule->onOperationStarted(aFOperation);
400 // the objects of the current operation should be deactivated
401 QObjectPtrList anObjects;
402 FeaturePtr aFeature = aFOperation->feature();
403 anObjects.append(aFeature);
404 std::list<ResultPtr> aResults = aFeature->results();
405 std::list<ResultPtr>::const_iterator aIt;
406 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
407 anObjects.append(*aIt);
409 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
410 for (; anIt != aLast; anIt++)
411 deactivateActiveObject(*anIt, false);
412 if (anObjects.size() > 0)
413 myDisplayer->updateViewer();
416 //******************************************************
417 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
419 setNestedFeatures(theOperation);
421 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
422 setPropertyPanel(theOperation);
424 updateCommandStatus();
426 myModule->onOperationResumed(theOperation);
430 //******************************************************
431 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
433 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
438 ModuleBase_ISelection* aSel = mySelector->selection();
439 QObjectPtrList aObj = aSel->selectedPresentations();
440 //!< No need for property panel
441 updateCommandStatus();
443 myPropertyPanel->cleanContent();
445 myModule->onOperationStopped(aFOperation);
447 // the deactivated objects of the current operation should be activated back.
448 // They were deactivated on operation start or an object redisplay
449 QObjectPtrList anObjects;
450 FeaturePtr aFeature = aFOperation->feature();
451 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
452 anObjects.append(aFeature);
453 std::list<ResultPtr> aResults = aFeature->results();
454 std::list<ResultPtr>::const_iterator aIt;
455 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
456 ResultPtr anObject = *aIt;
457 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
458 anObjects.append(anObject);
462 module()->activeSelectionModes(aModes);
463 myDisplayer->activateObjects(aModes, anObjects);
467 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
469 myModule->onOperationCommitted(theOperation);
472 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
474 myModule->onOperationAborted(theOperation);
477 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
479 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
484 aFOperation->setGrantedOperationIds(mySalomeConnector->nestedActions(theOperation->id()));
486 aFOperation->setGrantedOperationIds(myActionsMgr->nestedCommands(theOperation->id()));
489 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
491 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
496 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
497 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
500 myPropertyPanel->cleanContent();
501 aFactory.createWidget(myPropertyPanel->contentWidget());
503 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
504 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
505 bool isStoreValue = !aFOperation->isEditOperation() &&
506 !aWidget->getDefaultValue().empty() &&
507 !aWidget->isComputedDefault();
508 aWidget->setFeature(aFOperation->feature(), isStoreValue);
509 aWidget->enableFocusProcessing();
512 myPropertyPanel->setModelWidgets(aWidgets);
513 aFOperation->setPropertyPanel(myPropertyPanel);
515 myModule->propertyPanelDefined(theOperation);
517 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
519 myErrorMgr->setPropertyPanel(myPropertyPanel);
523 * Saves document with given name.
525 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
527 QApplication::restoreOverrideCursor();
528 SessionPtr aMgr = ModelAPI_Session::get();
529 aMgr->save(theName.toLatin1().constData(), theFileNames);
530 QApplication::restoreOverrideCursor();
533 bool XGUI_Workshop::isActiveOperationAborted()
535 return myOperationMgr->abortAllOperations();
538 //******************************************************
539 void XGUI_Workshop::onExit()
541 SessionPtr aMgr = ModelAPI_Session::get();
542 if (aMgr->isModified()) {
543 int anAnswer = QMessageBox::question(
544 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
545 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
546 if (anAnswer == QMessageBox::Save) {
547 bool saved = onSave();
551 } else if (anAnswer == QMessageBox::Cancel) {
558 //******************************************************
559 void XGUI_Workshop::onNew()
561 QApplication::setOverrideCursor(Qt::WaitCursor);
562 if (objectBrowser() == 0) {
564 mySelector->connectViewers();
566 myViewerProxy->connectToViewer();
568 if (!isSalomeMode()) {
569 myMainWindow->showPythonConsole();
570 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
571 aWnd->showMaximized();
572 updateCommandStatus();
574 myContextMenuMgr->connectViewer();
575 QApplication::restoreOverrideCursor();
578 //******************************************************
579 void XGUI_Workshop::onOpen()
581 if(!isActiveOperationAborted())
583 //save current file before close if modified
584 SessionPtr aSession = ModelAPI_Session::get();
585 if (aSession->isModified()) {
586 //TODO(sbh): re-launch the app?
587 int anAnswer = QMessageBox::question(
588 myMainWindow, tr("Save current file"),
589 tr("The document is modified, save before opening another?"),
590 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
591 if (anAnswer == QMessageBox::Save) {
593 } else if (anAnswer == QMessageBox::Cancel) {
599 //show file dialog, check if readable and open
600 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow(), tr("Select directory"));
601 if (myCurrentDir.isEmpty())
603 QFileInfo aFileInfo(myCurrentDir);
604 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
605 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
609 QApplication::setOverrideCursor(Qt::WaitCursor);
610 aSession->closeAll();
611 aSession->load(myCurrentDir.toLatin1().constData());
612 myObjectBrowser->rebuildDataTree();
613 //displayAllResults();
614 updateCommandStatus();
615 QApplication::restoreOverrideCursor();
618 //******************************************************
619 bool XGUI_Workshop::onSave()
621 if(!isActiveOperationAborted())
623 if (myCurrentDir.isEmpty()) {
626 std::list<std::string> aFiles;
627 saveDocument(myCurrentDir, aFiles);
628 updateCommandStatus();
630 myMainWindow->setModifiedState(false);
634 //******************************************************
635 bool XGUI_Workshop::onSaveAs()
637 if(!isActiveOperationAborted())
639 QFileDialog dialog(mainWindow());
640 dialog.setWindowTitle(tr("Select directory to save files..."));
641 dialog.setFileMode(QFileDialog::Directory);
642 dialog.setFilter(tr("Directories (*)"));
643 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
644 dialog.setViewMode(QFileDialog::Detail);
646 if (!dialog.exec()) {
650 QString aTempDir = dialog.selectedFiles().first();
652 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
653 int answer = QMessageBox::question(
655 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
657 tr("The directory already contains some files, save anyway?"),
658 QMessageBox::Save | QMessageBox::Cancel);
659 if (answer == QMessageBox::Cancel) {
663 myCurrentDir = aTempDir;
664 if (!isSalomeMode()) {
665 myMainWindow->setCurrentDir(myCurrentDir, false);
666 myMainWindow->setModifiedState(false);
671 //******************************************************
672 void XGUI_Workshop::onUndo(int theTimes)
674 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
675 SessionPtr aMgr = ModelAPI_Session::get();
676 if (aMgr->isOperation()) {
677 /// this is important for nested operrations
678 /// when sketch opeation is active, this condition is false and
679 /// the sketch operation is not aborted
680 operationMgr()->onAbortOperation();
682 for (int i = 0; i < theTimes; ++i) {
686 operationMgr()->updateApplyOfOperations();
687 updateCommandStatus();
690 //******************************************************
691 void XGUI_Workshop::onRedo(int theTimes)
693 // the viewer update should be blocked in order to avoid the features blinking. For the created
694 // feature a results are created, the flush of the created signal caused the viewer redisplay for
695 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked until
696 // redo of all possible objects happens
697 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
699 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
700 SessionPtr aMgr = ModelAPI_Session::get();
701 if (aMgr->isOperation()) {
702 /// this is important for nested operrations
703 /// when sketch opeation is active, this condition is false and
704 /// the sketch operation is not aborted
705 operationMgr()->onAbortOperation();
707 for (int i = 0; i < theTimes; ++i) {
710 operationMgr()->updateApplyOfOperations();
711 updateCommandStatus();
713 // unblock the viewer update functionality and make update on purpose
714 myDisplayer->enableUpdateViewer(isUpdateEnabled);
715 myDisplayer->updateViewer();
718 //******************************************************
719 void XGUI_Workshop::onRebuild()
721 SessionPtr aMgr = ModelAPI_Session::get();
722 bool aWasOperation = aMgr->isOperation(); // keep this value
723 if (!aWasOperation) {
724 aMgr->startOperation("Rebuild");
726 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
727 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
728 new Events_Message(aRebuildEvent, this)));
729 if (!aWasOperation) {
730 aMgr->finishOperation();
732 updateCommandStatus();
735 //******************************************************
736 void XGUI_Workshop::onPreferences()
738 ModuleBase_Prefs aModif;
739 ModuleBase_Preferences::editPreferences(aModif);
740 if (aModif.size() > 0) {
742 foreach (ModuleBase_Pref aPref, aModif)
744 aSection = aPref.first;
745 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
747 myMainWindow->viewer()->updateFromResources();
748 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
750 myMainWindow->menuObject()->updateFromResources();
756 //******************************************************
757 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
759 QString libName = QString::fromStdString(library(theModule.toStdString()));
760 if (libName.isEmpty()) {
761 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
766 CREATE_FUNC crtInst = 0;
769 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
773 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
774 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
775 QString aMsg((char*) &lpMsgBuf);
776 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
777 ::LocalFree(lpMsgBuf);
779 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
783 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
784 | FORMAT_MESSAGE_IGNORE_INSERTS,
785 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
786 QString aMsg((char*) &lpMsgBuf);
787 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
788 ::LocalFree(lpMsgBuf);
792 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
794 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
796 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
798 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
803 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
805 if (!err.isEmpty()) {
807 Events_Error::send(err.toStdString());
809 qWarning(qPrintable(err));
815 //******************************************************
816 bool XGUI_Workshop::createModule()
818 Config_ModuleReader aModuleReader;
819 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
820 myModule = loadModule(moduleName);
824 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
825 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
826 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
827 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
829 myModule->createFeatures();
830 //myActionsMgr->update();
834 //******************************************************
835 void XGUI_Workshop::updateCommandStatus()
837 QList<QAction*> aCommands;
838 if (isSalomeMode()) { // update commands in SALOME mode
839 aCommands = salomeConnector()->commandList();
841 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
842 foreach (AppElements_Command* aCmd, aMenuBar->features())
843 aCommands.append(aCmd);
845 SessionPtr aMgr = ModelAPI_Session::get();
846 if (aMgr->hasModuleDocument()) {
847 foreach(QAction* aCmd, aCommands) {
848 QString aId = aCmd->data().toString();
849 if (aId == "UNDO_CMD")
850 aCmd->setEnabled(myModule->canUndo());
851 else if (aId == "REDO_CMD")
852 aCmd->setEnabled(myModule->canRedo());
854 // Enable all commands
855 aCmd->setEnabled(true);
859 foreach(QAction* aCmd, aCommands) {
860 QString aId = aCmd->data().toString();
861 if (aId == "NEW_CMD")
862 aCmd->setEnabled(true);
863 else if (aId == "EXIT_CMD")
864 aCmd->setEnabled(true);
866 aCmd->setEnabled(false);
869 myActionsMgr->update();
870 emit commandStatusUpdated();
873 void XGUI_Workshop::updateHistory()
875 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
876 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
877 emit updateUndoHistory(aUndoRes);
879 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
880 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
881 emit updateRedoHistory(aRedoRes);
884 //******************************************************
885 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
887 QDockWidget* aObjDock = new QDockWidget(theParent);
888 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
889 aObjDock->setWindowTitle(tr("Object browser"));
890 aObjDock->setStyleSheet(
891 "::title { position: relative; padding-left: 5px; text-align: left center }");
892 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
893 #ifdef ModuleDataModel
894 myObjectBrowser->setDataModel(myModule->dataModel());
896 myModule->customizeObjectBrowser(myObjectBrowser);
897 aObjDock->setWidget(myObjectBrowser);
899 myContextMenuMgr->connectObjectBrowser();
903 //******************************************************
905 * Creates dock widgets, places them in corresponding area
906 * and tabifies if necessary.
908 void XGUI_Workshop::createDockWidgets()
910 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
911 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
912 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
913 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
914 myPropertyPanel->setupActions(myActionsMgr);
915 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
916 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
917 hidePropertyPanel(); ///<! Invisible by default
919 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
920 myPropertyPanel->installEventFilter(myOperationMgr);
922 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
923 connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation()));
924 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
925 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
926 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
927 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
928 myOperationMgr, SLOT(onKeyReleased(QKeyEvent*)));
929 connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
930 aOkAct, SLOT(setEnabled(bool)));
933 //******************************************************
934 void XGUI_Workshop::showPropertyPanel()
936 QAction* aViewAct = myPropertyPanel->toggleViewAction();
937 ///<! Restore ability to close panel from the window's menu
938 aViewAct->setEnabled(true);
939 myPropertyPanel->show();
940 myPropertyPanel->raise();
943 //******************************************************
944 void XGUI_Workshop::hidePropertyPanel()
946 QAction* aViewAct = myPropertyPanel->toggleViewAction();
947 ///<! Do not allow to show empty property panel
948 aViewAct->setEnabled(false);
949 myPropertyPanel->hide();
952 //******************************************************
953 void XGUI_Workshop::showObjectBrowser()
955 myObjectBrowser->parentWidget()->show();
958 //******************************************************
959 void XGUI_Workshop::hideObjectBrowser()
961 myObjectBrowser->parentWidget()->hide();
964 //******************************************************
965 void XGUI_Workshop::salomeViewerSelectionChanged()
967 emit salomeViewerSelection();
970 //**************************************************************
971 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
973 return mySalomeConnector->viewer();
976 //**************************************************************
977 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
979 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
980 if (theId == "DELETE_CMD")
982 else if (theId == "MOVE_CMD")
984 else if (theId == "COLOR_CMD")
985 changeColor(aObjects);
986 else if (theId == "SHOW_CMD")
987 showObjects(aObjects, true);
988 else if (theId == "HIDE_CMD")
989 showObjects(aObjects, false);
990 else if (theId == "SHOW_ONLY_CMD")
991 showOnlyObjects(aObjects);
992 else if (theId == "SHADING_CMD")
993 setDisplayMode(aObjects, XGUI_Displayer::Shading);
994 else if (theId == "WIREFRAME_CMD")
995 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
996 else if (theId == "HIDEALL_CMD") {
997 QObjectPtrList aList = myDisplayer->displayedObjects();
998 foreach (ObjectPtr aObj, aList)
999 aObj->setDisplayed(false);
1000 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1004 //**************************************************************
1005 void XGUI_Workshop::deleteObjects()
1007 ModuleBase_IModule* aModule = module();
1008 // 1. allow the module to delete objects, do nothing if it has succeed
1009 if (aModule->deleteObjects()) {
1010 updateCommandStatus();
1014 if (!isActiveOperationAborted())
1016 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1017 // It is necessary to clear selection in order to avoid selection changed event during
1018 // deleteion and negative consequences connected with processing of already deleted items
1019 mySelector->clearSelection();
1020 // check whether the object can be deleted. There should not be parts which are not loaded
1021 if (!XGUI_Tools::canRemoveOrRename(myMainWindow, anObjects))
1024 bool hasResult = false;
1025 bool hasFeature = false;
1026 bool hasParameter = false;
1027 bool hasSubFeature = false;
1028 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
1029 if (!(hasFeature || hasParameter))
1032 // 1. start operation
1033 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
1034 aDescription += tr(" %1");
1035 QStringList aObjectNames;
1036 foreach (ObjectPtr aObj, anObjects) {
1037 if (!aObj->data()->isValid())
1039 aObjectNames << QString::fromStdString(aObj->data()->name());
1041 aDescription = aDescription.arg(aObjectNames.join(", "));
1043 SessionPtr aMgr = ModelAPI_Session::get();
1044 aMgr->startOperation(aDescription.toStdString());
1045 // 2. close the documents of the removed parts if the result part is in a list of selected objects
1046 // this is performed in the RemoveFeature of Part object.
1047 /*foreach (ObjectPtr aObj, anObjects)
1049 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1051 DocumentPtr aDoc = aObj->document();
1052 if (aDoc == aMgr->activeDocument()) {
1057 // 3. delete objects
1058 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1059 std::set<FeaturePtr> anIgnoredFeatures;
1060 if (deleteFeatures(anObjects, anIgnoredFeatures, aDesktop, true)) {
1061 myDisplayer->updateViewer();
1062 aMgr->finishOperation();
1063 operationMgr()->updateApplyOfOperations();
1064 updateCommandStatus();
1067 aMgr->abortOperation();
1071 //**************************************************************
1072 void XGUI_Workshop::moveObjects()
1074 if (!isActiveOperationAborted())
1077 SessionPtr aMgr = ModelAPI_Session::get();
1079 QString anActionId = "MOVE_CMD";
1080 QString aDescription = contextMenuMgr()->action(anActionId)->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 aObject, anObjects) {
1088 if (!myModule->canApplyAction(aObject, anActionId))
1091 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1092 if (aFeature.get()) {
1093 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1094 aCurrentFeature = anActiveDocument->currentFeature(true);
1097 aMgr->finishOperation();
1100 //**************************************************************
1101 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
1102 const std::set<FeaturePtr>& theIgnoredFeatures,
1104 const bool theAskAboutDeleteReferences)
1108 QObjectPtrList::const_iterator aDIt = theList.begin(), aDLast = theList.end();
1109 for (; aDIt != aDLast; ++aDIt) {
1110 aDInfo.append(ModuleBase_Tools::objectInfo((*aDIt)));
1112 QString anInfoStr = aDInfo.join(", ");
1113 qDebug(QString("deleteFeatures: %1, %2").arg(theList.size()).arg(anInfoStr).toStdString().c_str());
1116 // 1. find all referenced features
1117 std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
1118 foreach (ObjectPtr aDeletedObj, theList) {
1119 XGUI_Tools::refsToFeatureInAllDocuments(aDeletedObj, aDeletedObj, aDirectRefFeatures, aIndirectRefFeatures);
1120 std::set<FeaturePtr> aDifference;
1121 std::set_difference(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end(),
1122 aDirectRefFeatures.begin(), aDirectRefFeatures.end(),
1123 std::inserter(aDifference, aDifference.begin()));
1124 aIndirectRefFeatures = aDifference;
1126 // 2. warn about the references remove, break the delete operation if the user chose it
1127 if (theAskAboutDeleteReferences && !aDirectRefFeatures.empty()) {
1128 QStringList aDirectRefNames;
1129 foreach(const FeaturePtr& aFeature, aDirectRefFeatures)
1130 aDirectRefNames.append(aFeature->name().c_str());
1131 QString aDirectNames = aDirectRefNames.join(", ");
1133 QStringList aIndirectRefNames;
1134 foreach(const FeaturePtr& aFeature, aIndirectRefFeatures)
1135 aIndirectRefNames.append(aFeature->name().c_str());
1136 QString aIndirectNames = aIndirectRefNames.join(", ");
1138 QMessageBox::StandardButton aRes = QMessageBox::warning(
1139 theParent, tr("Delete features"),
1140 QString(tr("Selected features are used in the following features: %1.\
1141 These features will be deleted.\n%2Would you like to continue?")).arg(aDirectNames)
1142 .arg(aIndirectNames.isEmpty() ? QString() : QString("Also these features will be deleted: %1.\n").arg(aIndirectNames)),
1143 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1144 if (aRes != QMessageBox::Yes)
1148 // 3. remove referenced features
1149 std::set<FeaturePtr> aFeaturesToDelete = aDirectRefFeatures;
1150 aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end());
1151 std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin(),
1152 aLast = aFeaturesToDelete.end();
1156 for (; anIt != aLast; anIt++) {
1157 FeaturePtr aFeature = (*anIt);
1158 DocumentPtr aDoc = aFeature->document();
1159 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end()) {
1160 aDoc->removeFeature(aFeature);
1162 anInfo.append(ModuleBase_Tools::objectInfo(aFeature).toStdString().c_str());
1167 qDebug(QString("remove references:%1").arg(anInfo.join("; ")).toStdString().c_str());
1171 QString anActionId = "DELETE_CMD";
1172 QString anId = QString::fromStdString(anActionId.toStdString().c_str());
1173 QStringList anObjectGroups = contextMenuMgr()->actionObjectGroups(anId);
1174 // 4. remove the parameter features
1175 foreach (ObjectPtr aObj, theList) {
1176 // features and parameters can be removed here,
1177 // the results are removed only by a corresponded feature remove
1178 std::string aGroupName = aObj->groupName();
1179 if (!anObjectGroups.contains(aGroupName.c_str()))
1182 if (!myModule->canApplyAction(aObj, anActionId))
1185 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1187 /*// TODO: to learn the workshop to delegate the Part object deletion to the PartSet module
1188 // part features are removed in the PartSet module. This condition should be moved there
1189 if (aFeature->getKind() == "Part")
1192 DocumentPtr aDoc = aObj->document();
1193 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end()) {
1195 QString anInfoStr = ModuleBase_Tools::objectInfo(aFeature);
1196 anInfo.append(anInfoStr);
1197 qDebug(QString("remove feature :%1").arg(anInfoStr).toStdString().c_str());
1199 aDoc->removeFeature(aFeature);
1204 qDebug(QString("remove features:%1").arg(anInfo.join("; ")).toStdString().c_str());
1209 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1211 bool isFoundResultType = false;
1212 foreach(ObjectPtr anObj, theObjects)
1214 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1215 if (aResult.get() == NULL)
1218 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1219 if (isFoundResultType)
1222 return isFoundResultType;
1225 //**************************************************************
1226 // Returns the list of features placed between theObject and the current feature
1227 // in the same document. Excludes theObject, includes the current feature.
1228 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1230 std::list<FeaturePtr> aResult;
1231 DocumentPtr aDocument = theObject->document();
1232 std::list<FeaturePtr> anAllFeatures = aDocument->allFeatures();
1233 // find the object iterator
1234 std::list<FeaturePtr>::iterator aObjectIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1235 if (aObjectIt == anAllFeatures.end())
1237 // find the current feature iterator
1238 std::list<FeaturePtr>::iterator aCurrentIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1239 if (aCurrentIt == anAllFeatures.end())
1241 // check the right order
1242 if (std::distance(aObjectIt, anAllFeatures.end()) <= std::distance(aCurrentIt, anAllFeatures.end()))
1244 // exclude the object
1245 std::advance(aObjectIt, 1);
1246 // include the current feature
1247 std::advance(aCurrentIt, 1);
1248 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1251 bool XGUI_Workshop::canMoveFeature()
1253 QString anActionId = "MOVE_CMD";
1255 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1256 QObjectPtrList aValidatedObjects;
1257 foreach (ObjectPtr aObject, aObjects) {
1258 if (myModule->canApplyAction(aObject, anActionId))
1259 aValidatedObjects.append(aObject);
1261 if (aValidatedObjects.size() != aObjects.size())
1262 aObjects = aValidatedObjects;
1264 bool aCanMove = !aObjects.empty();
1266 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1267 for (; anIt != aLast && aCanMove; anIt++) {
1268 ObjectPtr aObject = *anIt;
1269 // 1. Get features placed between selected and current in the document
1270 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1271 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1272 if (aFeaturesBetween.empty())
1275 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1276 // 2. Get all reference features to the selected object in the document
1277 std::set<FeaturePtr> aRefFeatures;
1278 XGUI_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1280 if (aRefFeatures.empty())
1283 // 3. Find any placed features in all reference features
1284 std::set<FeaturePtr> aIntersectionFeatures;
1285 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1286 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1287 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1288 // 4. Return false if any reference feature is placed before curent feature
1289 if (!aIntersectionFeatures.empty())
1297 //**************************************************************
1298 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1300 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1301 if (!aCanBeShaded) {
1302 ResultCompSolidPtr aCompsolidResult =
1303 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1304 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1305 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1306 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1309 return aCanBeShaded;
1312 //**************************************************************
1313 bool XGUI_Workshop::canChangeColor() const
1315 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1317 std::set<std::string> aTypes;
1318 aTypes.insert(ModelAPI_ResultGroup::group());
1319 aTypes.insert(ModelAPI_ResultConstruction::group());
1320 aTypes.insert(ModelAPI_ResultBody::group());
1321 aTypes.insert(ModelAPI_ResultPart::group());
1323 return hasResults(aObjects, aTypes);
1326 void setColor(ResultPtr theResult, std::vector<int>& theColor)
1328 if (!theResult.get())
1331 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1332 if (aColorAttr.get() != NULL) {
1333 if (!aColorAttr->size()) {
1334 aColorAttr->setSize(3);
1336 aColorAttr->setValue(0, theColor[0]);
1337 aColorAttr->setValue(1, theColor[1]);
1338 aColorAttr->setValue(2, theColor[2]);
1342 //**************************************************************
1343 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1345 AttributeIntArrayPtr aColorAttr;
1346 // 1. find the current color of the object. This is a color of AIS presentation
1347 // The objects are iterated until a first valid color is found
1348 std::vector<int> aColor;
1349 foreach(ObjectPtr anObject, theObjects) {
1350 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1351 if (aResult.get()) {
1352 XGUI_CustomPrs::getResultColor(aResult, aColor);
1355 // TODO: remove the obtaining a color from the AIS object
1356 // this does not happen never because:
1357 // 1. The color can be changed only on results
1358 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1359 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1360 if (anAISObj.get()) {
1362 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1365 if (!aColor.empty())
1368 if (aColor.size() != 3)
1371 // 2. show the dialog to change the value
1372 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(mainWindow());
1373 aDlg->setColor(aColor);
1374 aDlg->move(QCursor::pos());
1375 bool isDone = aDlg->exec() == QDialog::Accepted;
1379 bool isRandomColor = aDlg->isRandomColor();
1381 // 3. abort the previous operation and start a new one
1382 SessionPtr aMgr = ModelAPI_Session::get();
1383 bool aWasOperation = aMgr->isOperation(); // keep this value
1384 if (!aWasOperation) {
1385 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1386 aMgr->startOperation(aDescription.toStdString());
1389 // 4. set the value to all results
1390 std::vector<int> aColorResult = aDlg->getColor();
1391 foreach(ObjectPtr anObj, theObjects) {
1392 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1393 if (aResult.get() != NULL) {
1394 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1395 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1396 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++)
1397 setColor(aCompsolidResult->subResult(i), aColorResult);
1399 setColor(aResult, aColorResult);
1403 aMgr->finishOperation();
1404 updateCommandStatus();
1407 //**************************************************************
1408 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
1409 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
1410 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
1412 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1414 foreach (ObjectPtr aObj, theList) {
1416 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1418 DocumentPtr aDoc = aPartRes->partDoc();
1419 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), isVisible)
1420 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), isVisible)
1421 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), isVisible)
1424 aObj->setDisplayed(isVisible);
1427 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1430 //**************************************************************
1431 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1433 // Hide all displayed objects
1434 QObjectPtrList aList = myDisplayer->displayedObjects();
1435 foreach (ObjectPtr aObj, aList)
1436 aObj->setDisplayed(false);
1438 // Show only objects from the list
1439 foreach (ObjectPtr aObj, theList) {
1441 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1443 DocumentPtr aDoc = aPartRes->partDoc();
1444 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), true)
1445 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), true)
1446 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), true)
1449 aObj->setDisplayed(true);
1452 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1457 //**************************************************************
1458 void XGUI_Workshop::registerValidators() const
1460 SessionPtr aMgr = ModelAPI_Session::get();
1461 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1464 //**************************************************************
1465 /*void XGUI_Workshop::displayAllResults()
1467 SessionPtr aMgr = ModelAPI_Session::get();
1468 DocumentPtr aRootDoc = aMgr->moduleDocument();
1469 displayDocumentResults(aRootDoc);
1470 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1471 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1472 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1473 displayDocumentResults(aPart->partDoc());
1475 myDisplayer->updateViewer();
1478 //**************************************************************
1479 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1483 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1484 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1487 //**************************************************************
1488 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1490 for (int i = 0; i < theDoc->size(theGroup); i++)
1491 theDoc->object(theGroup, i)->setDisplayed(true);
1492 //displayObject(theDoc->object(theGroup, i));
1493 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1496 //**************************************************************
1497 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1499 foreach(ObjectPtr aObj, theList) {
1500 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1502 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
1503 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1504 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1505 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
1506 (XGUI_Displayer::DisplayMode)theMode, false);
1510 if (theList.size() > 0)
1511 myDisplayer->updateViewer();
1514 //**************************************************************
1515 void XGUI_Workshop::closeDocument()
1517 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1518 while (anOperation) {
1519 anOperation->abort();
1520 anOperation = operationMgr()->currentOperation();
1522 myDisplayer->closeLocalContexts();
1523 myDisplayer->eraseAll();
1524 objectBrowser()->clearContent();
1526 SessionPtr aMgr = ModelAPI_Session::get();
1530 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1532 XGUI_HistoryMenu* aMenu = NULL;
1533 if (isSalomeMode()) {
1534 QAction* anAction = qobject_cast<QAction*>(theObject);
1537 aMenu = new XGUI_HistoryMenu(anAction);
1539 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1540 aMenu = new XGUI_HistoryMenu(aButton);
1542 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1543 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1546 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1548 QList<ActionInfo> aResult;
1549 std::list<std::string>::const_iterator it = theList.cbegin();
1550 for (; it != theList.cend(); it++) {
1551 QString anId = QString::fromStdString(*it);
1552 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
1554 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
1557 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
1558 if (aContextMenuAct) {
1559 anInfo.initFrom(aContextMenuAct);
1561 anInfo = myActionsMgr->actionInfoById(anId);
1564 anInfo.text = anInfo.text.prepend("Modify ");