1 #include "XGUI_Module.h"
2 #include "XGUI_Constants.h"
3 #include "XGUI_Command.h"
4 #include "XGUI_MainMenu.h"
5 #include "XGUI_MainWindow.h"
6 #include "XGUI_MenuGroupPanel.h"
7 #include "XGUI_Tools.h"
8 #include "XGUI_Workbench.h"
9 #include "XGUI_Workshop.h"
10 #include "XGUI_Viewer.h"
11 #include "ModuleBase_WidgetFactory.h"
12 #include "XGUI_SelectionMgr.h"
13 #include "XGUI_ObjectsBrowser.h"
14 #include "XGUI_Displayer.h"
15 #include "XGUI_OperationMgr.h"
16 #include "XGUI_SalomeConnector.h"
17 #include "XGUI_SalomeViewer.h"
18 #include "XGUI_ActionsMgr.h"
19 #include "XGUI_ErrorDialog.h"
20 #include "XGUI_ViewerProxy.h"
21 #include "XGUI_PropertyPanel.h"
22 #include "XGUI_ContextMenuMgr.h"
24 #include <Model_Events.h>
25 #include <ModelAPI_PluginManager.h>
26 #include <ModelAPI_Feature.h>
27 #include <ModelAPI_Data.h>
28 #include <ModelAPI_AttributeDocRef.h>
29 #include <ModelAPI_Object.h>
31 #include <Events_Loop.h>
32 #include <Events_Error.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_Operation.h>
35 #include <ModuleBase_OperationDescription.h>
36 #include <Config_Common.h>
37 #include <Config_FeatureMessage.h>
38 #include <Config_PointerMessage.h>
39 #include <Config_ModuleReader.h>
41 #include <QApplication>
42 #include <QFileDialog>
43 #include <QMessageBox>
44 #include <QMdiSubWindow>
45 #include <QPushButton>
46 #include <QDockWidget>
61 QMap<QString, QString> XGUI_Workshop::myIcons;
63 QString XGUI_Workshop::featureIcon(const std::string& theId)
65 QString aId(theId.c_str());
66 if (myIcons.contains(aId))
71 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
73 myCurrentDir(QString()),
74 myPartSetModule(NULL),
75 mySalomeConnector(theConnector),
80 myMainWindow = mySalomeConnector? 0 : new XGUI_MainWindow();
82 myDisplayer = new XGUI_Displayer(this);
84 mySelector = new XGUI_SelectionMgr(this);
86 myOperationMgr = new XGUI_OperationMgr(this);
87 myActionsMgr = new XGUI_ActionsMgr(this);
88 myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
89 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
90 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)),
91 this, SLOT(onContextMenuCommand(const QString&, bool)));
93 myViewerProxy = new XGUI_ViewerProxy(this);
95 connect(myOperationMgr, SIGNAL(operationStarted()), SLOT(onOperationStarted()));
96 connect(myOperationMgr, SIGNAL(operationResumed()), SLOT(onOperationStarted()));
97 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), SLOT(onOperationStopped(ModuleBase_Operation*)));
98 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
99 connect(myOperationMgr, SIGNAL(operationStarted()), myActionsMgr, SLOT(update()));
100 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), myActionsMgr, SLOT(update()));
101 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
104 //******************************************************
105 XGUI_Workshop::~XGUI_Workshop(void)
109 //******************************************************
110 void XGUI_Workshop::startApplication()
113 //Initialize event listening
114 Events_Loop* aLoop = Events_Loop::loop();
115 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
116 //TODO(sbh): Implement static method to extract event id [SEID]
117 Events_ID aFeatureId = aLoop->eventByName(EVENT_FEATURE_LOADED);
118 aLoop->registerListener(this, aFeatureId);
119 Events_ID aPartSetId = aLoop->eventByName("PartSetModuleEvent");
120 aLoop->registerListener(this, aPartSetId);
121 Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED);
122 aLoop->registerListener(this, aFeatureUpdatedId);
123 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
127 myMainWindow->show();
128 updateCommandStatus();
133 //******************************************************
134 void XGUI_Workshop::initMenu()
136 myContextMenuMgr->createActions();
138 if (isSalomeMode()) {
139 // Create only Undo, Redo commands
140 QAction* aAction = salomeConnector()->addEditCommand("UNDO_CMD",
141 tr("Undo"), tr("Undo last command"),
142 QIcon(":pictures/undo.png"),
143 QKeySequence::Undo, false);
144 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
145 aAction = salomeConnector()->addEditCommand("REDO_CMD",
146 tr("Redo"), tr("Redo last command"),
147 QIcon(":pictures/redo.png"),
148 QKeySequence::Redo, false);
149 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
150 salomeConnector()->addEditMenuSeparator();
153 XGUI_Workbench* aPage = myMainWindow->menuObject()->generalPage();
155 // File commands group
156 XGUI_MenuGroupPanel* aGroup = aPage->addGroup("Default");
158 XGUI_Command* aCommand;
160 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
161 QIcon(":pictures/save.png"), QKeySequence::Save);
162 aCommand->connectTo(this, SLOT(onSave()));
163 //aCommand->disable();
165 aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
166 QIcon(":pictures/undo.png"), QKeySequence::Undo);
167 aCommand->connectTo(this, SLOT(onUndo()));
169 aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
170 QIcon(":pictures/redo.png"), QKeySequence::Redo);
171 aCommand->connectTo(this, SLOT(onRedo()));
173 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
174 QIcon(":pictures/rebuild.png"));
176 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
177 QIcon(":pictures/save.png"));
178 aCommand->connectTo(this, SLOT(onSaveAs()));
179 //aCommand->disable();
181 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
182 QIcon(":pictures/open.png"), QKeySequence::Open);
183 aCommand->connectTo(this, SLOT(onOpen()));
185 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
186 // QIcon(":pictures/new.png"), QKeySequence::New);
187 //aCommand->connectTo(this, SLOT(onNew()));
189 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
190 QIcon(":pictures/close.png"), QKeySequence::Close);
191 aCommand->connectTo(this, SLOT(onExit()));
192 //FIXME: SBH's test action. Can be used for some GUI tests.
194 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
195 // QIcon(":pictures/close.png"));
196 // aCommand->connectTo(myActionsMgr, SLOT(update()));
200 //******************************************************
201 XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
203 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
204 return aMenuBar->addWorkbench(theName);
207 //******************************************************
208 void XGUI_Workshop::processEvent(const Events_Message* theMessage)
210 //A message to start feature creation received.
211 static Events_ID aFeatureLoadedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED);
212 if (theMessage->eventID() == aFeatureLoadedId) {
213 const Config_FeatureMessage* aFeatureMsg = dynamic_cast<const Config_FeatureMessage*>(theMessage);
214 if(!aFeatureMsg->isInternal()) {
215 addFeature(aFeatureMsg);
219 // Process creation of Part
220 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
221 const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
222 std::set<FeaturePtr> aFeatures = aUpdMsg->features();
224 std::set<FeaturePtr>::const_iterator aIt;
225 bool aHasPart = false;
226 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
227 FeaturePtr aFeature = (*aIt);
228 if (aFeature->getKind() == "Part") {
234 //The created part will be created in Object Browser later and we have to activate it
235 // only when it is created everywere
236 QTimer::singleShot(50, this, SLOT(activateLastPart()));
240 //Update property panel on corresponding message. If there is no current operation (no
241 //property panel), or received message has different feature to the current - do nothing.
242 static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED);
243 if (theMessage->eventID() == aFeatureUpdatedId && myOperationMgr->hasOperation())
245 const Model_FeatureUpdatedMessage* anUpdateMsg =
246 dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
247 std::set<FeaturePtr> aFeatures = anUpdateMsg->features();
249 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
250 std::set<FeaturePtr>::const_iterator aIt;
251 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
252 FeaturePtr aNewFeature = (*aIt);
253 if(aNewFeature == aCurrentFeature) {
254 myPropertyPanel->updateContentWidget(aCurrentFeature);
259 //An operation passed by message. Start it, process and commit.
260 const Config_PointerMessage* aPartSetMsg = dynamic_cast<const Config_PointerMessage*>(theMessage);
262 ModuleBase_Operation* anOperation =
263 (ModuleBase_Operation*)(aPartSetMsg->pointer());
265 if (myOperationMgr->startOperation(anOperation)) {
266 myPropertyPanel->updateContentWidget(anOperation->feature());
267 if (anOperation->getDescription()->xmlRepresentation().isEmpty()) {
268 anOperation->commit();
269 updateCommandStatus();
274 //Show error dialog if error message received.
275 const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
277 emit errorOccurred(QString::fromLatin1(anAppError->description()));
280 myErrorDlg->activateWindow();
285 //******************************************************
286 void XGUI_Workshop::onOperationStarted()
288 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
290 if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) { //!< No need for property panel
291 connectWithOperation(aOperation);
295 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation);
296 QWidget* aContent = myPropertyPanel->contentWidget();
297 qDeleteAll(aContent->children());
298 aFactory.createWidget(aContent);
299 myPropertyPanel->setModelWidgets(aFactory.getModelWidgets());
300 myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
302 updateCommandStatus();
305 //******************************************************
306 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
308 //!< No need for property panel
309 updateCommandStatus();
316 void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
320 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
324 // Remember features icons
325 myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
327 //Find or create Workbench
328 QString aWchName = QString::fromStdString(theMessage->workbenchId());
329 QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
330 bool isUsePropPanel = theMessage->isUseInput();
331 QString aId = QString::fromStdString(theMessage->id());
332 if (isSalomeMode()) {
333 QAction* aAction = salomeConnector()->addFeature(aWchName,
335 QString::fromStdString(theMessage->text()),
336 QString::fromStdString(theMessage->tooltip()),
337 QIcon(theMessage->icon().c_str()),
338 QKeySequence(), isUsePropPanel);
339 myActionsMgr->addCommand(aAction);
340 salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
341 myPartSetModule->featureCreated(aAction);
344 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
345 XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
347 aPage = addWorkbench(aWchName);
349 //Find or create Group
350 QString aGroupName = QString::fromStdString(theMessage->groupId());
351 XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
353 aGroup = aPage->addGroup(aGroupName);
356 XGUI_Command* aCommand = aGroup->addFeature(aId,
357 QString::fromStdString(theMessage->text()),
358 QString::fromStdString(theMessage->tooltip()),
359 QIcon(theMessage->icon().c_str()),
360 QKeySequence(), isUsePropPanel);
361 aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
362 myActionsMgr->addCommand(aCommand);
363 myPartSetModule->featureCreated(aCommand);
368 * Makes a signal/slot connections between Property Panel
369 * and given operation. The given operation becomes a
370 * current operation and previous operation if exists
372 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
374 QAction* aCommand = 0;
375 if (isSalomeMode()) {
376 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
378 XGUI_MainMenu* aMenu = myMainWindow->menuObject();
379 aCommand = aMenu->feature(theOperation->getDescription()->operationId());
381 //Abort operation on uncheck the command
382 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
386 * Saves document with given name.
388 void XGUI_Workshop::saveDocument(QString theName)
390 QApplication::restoreOverrideCursor();
391 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
392 DocumentPtr aDoc = aMgr->rootDocument();
393 aDoc->save(theName.toLatin1().constData());
394 QApplication::restoreOverrideCursor();
397 //******************************************************
398 void XGUI_Workshop::onExit()
400 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
401 DocumentPtr aDoc = aMgr->rootDocument();
402 if(aDoc->isModified()) {
403 int anAnswer = QMessageBox::question(
404 myMainWindow, tr("Save current file"),
405 tr("The document is modified, save before exit?"),
406 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
407 if(anAnswer == QMessageBox::Save) {
408 bool saved = onSave();
412 } else if (anAnswer == QMessageBox::Cancel) {
419 //******************************************************
420 void XGUI_Workshop::onNew()
422 QApplication::setOverrideCursor(Qt::WaitCursor);
423 if (objectBrowser() == 0) {
425 mySelector->connectViewers();
427 myViewerProxy->connectToViewer();
429 if (!isSalomeMode()) {
430 myMainWindow->showPythonConsole();
431 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
432 aWnd->showMaximized();
433 updateCommandStatus();
435 QApplication::restoreOverrideCursor();
438 //******************************************************
439 void XGUI_Workshop::onOpen()
441 //save current file before close if modified
442 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
443 DocumentPtr aDoc = aMgr->rootDocument();
444 if(aDoc->isModified()) {
445 //TODO(sbh): re-launch the app?
446 int anAnswer = QMessageBox::question(
447 myMainWindow, tr("Save current file"),
448 tr("The document is modified, save before opening another?"),
449 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
450 if(anAnswer == QMessageBox::Save) {
452 } else if (anAnswer == QMessageBox::Cancel) {
459 //show file dialog, check if readable and open
460 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
461 if(myCurrentDir.isEmpty())
463 QFileInfo aFileInfo(myCurrentDir);
464 if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
465 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
469 QApplication::setOverrideCursor(Qt::WaitCursor);
470 aDoc->load(myCurrentDir.toLatin1().constData());
471 QApplication::restoreOverrideCursor();
472 updateCommandStatus();
475 //******************************************************
476 bool XGUI_Workshop::onSave()
478 if(myCurrentDir.isEmpty()) {
481 saveDocument(myCurrentDir);
482 updateCommandStatus();
486 //******************************************************
487 bool XGUI_Workshop::onSaveAs()
489 QFileDialog dialog(mainWindow());
490 dialog.setWindowTitle(tr("Select directory to save files..."));
491 dialog.setFileMode(QFileDialog::Directory);
492 dialog.setFilter(tr("Folders (*)"));
493 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
494 dialog.setViewMode(QFileDialog::Detail);
499 QString aTempDir = dialog.selectedFiles().first();
501 if(aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).isEmpty()) {
502 int answer = QMessageBox::question(myMainWindow,
503 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
505 tr("The folder already contains some files, save anyway?"),
506 QMessageBox::Save|QMessageBox::Cancel);
507 if(answer == QMessageBox::Cancel) {
511 myCurrentDir = aTempDir;
515 //******************************************************
516 void XGUI_Workshop::onUndo()
518 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
519 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
520 DocumentPtr aDoc = aMgr->rootDocument();
521 if (aDoc->isOperation())
522 operationMgr()->abortOperation();
524 updateCommandStatus();
527 //******************************************************
528 void XGUI_Workshop::onRedo()
530 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
531 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
532 DocumentPtr aDoc = aMgr->rootDocument();
533 if (aDoc->isOperation())
534 operationMgr()->abortOperation();
536 updateCommandStatus();
539 //******************************************************
540 XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
543 QString::fromStdString(library(theModule.toStdString()));
544 if (libName.isEmpty()) {
546 qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ));
551 CREATE_FUNC crtInst = 0;
554 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
558 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
559 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
560 QString aMsg((char*) &lpMsgBuf);
561 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
562 ::LocalFree(lpMsgBuf);
564 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
568 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
569 | FORMAT_MESSAGE_IGNORE_INSERTS,
570 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
571 QString aMsg((char*) &lpMsgBuf);
572 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
573 ::LocalFree(lpMsgBuf);
577 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
579 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
581 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
583 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
588 XGUI_Module* aModule = crtInst ? crtInst(this) : 0;
590 if (!err.isEmpty()) {
592 QMessageBox::warning(mainWindow(), tr("Error"), err);
594 qWarning( qPrintable( err ));
600 //******************************************************
601 bool XGUI_Workshop::activateModule()
603 Config_ModuleReader aModuleReader;
604 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
605 myPartSetModule = loadModule(moduleName);
606 if (!myPartSetModule)
608 myPartSetModule->createFeatures();
609 myActionsMgr->update();
613 //******************************************************
614 void XGUI_Workshop::updateCommandStatus()
616 QList<QAction*> aCommands;
617 if (isSalomeMode()) { // update commands in SALOME mode
618 aCommands = salomeConnector()->commandList();
620 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
621 foreach (XGUI_Command* aCmd, aMenuBar->features())
622 aCommands.append(aCmd);
624 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
625 if (aMgr->hasRootDocument()) {
628 foreach(QAction* aCmd, aCommands) {
629 QString aId = aCmd->data().toString();
630 if (aId == "UNDO_CMD")
632 else if (aId == "REDO_CMD")
634 else // Enable all commands
635 aCmd->setEnabled(true);
637 DocumentPtr aDoc = aMgr->rootDocument();
638 aUndoCmd->setEnabled(aDoc->canUndo());
639 aRedoCmd->setEnabled(aDoc->canRedo());
641 foreach(QAction* aCmd, aCommands) {
642 QString aId = aCmd->data().toString();
643 if (aId == "NEW_CMD")
644 aCmd->setEnabled(true);
645 else if (aId == "EXIT_CMD")
646 aCmd->setEnabled(true);
648 aCmd->setEnabled(false);
651 myActionsMgr->update();
654 //******************************************************
655 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
657 QDockWidget* aObjDock = new QDockWidget(theParent);
658 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
659 aObjDock->setWindowTitle(tr("Object browser"));
660 aObjDock->setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
661 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
662 connect(myObjectBrowser, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(changeCurrentDocument(FeaturePtr)));
663 aObjDock->setWidget(myObjectBrowser);
665 myContextMenuMgr->connectObjectBrowser();
669 //******************************************************
671 * Creates dock widgets, places them in corresponding area
672 * and tabifies if necessary.
674 void XGUI_Workshop::createDockWidgets()
676 QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() :
678 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
679 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
680 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
681 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
682 hidePropertyPanel(); //<! Invisible by default
684 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
686 QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
687 connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
688 QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
689 connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
692 //******************************************************
693 void XGUI_Workshop::showPropertyPanel()
695 QAction* aViewAct = myPropertyPanel->toggleViewAction();
696 //<! Restore ability to close panel from the window's menu
697 aViewAct->setEnabled(true);
698 myPropertyPanel->show();
699 myPropertyPanel->raise();
702 //******************************************************
703 void XGUI_Workshop::hidePropertyPanel()
705 QAction* aViewAct = myPropertyPanel->toggleViewAction();
706 //<! Do not allow to show empty property panel
707 aViewAct->setEnabled(false);
708 myPropertyPanel->hide();
711 //******************************************************
712 void XGUI_Workshop::showObjectBrowser()
714 myObjectBrowser->parentWidget()->show();
717 //******************************************************
718 void XGUI_Workshop::hideObjectBrowser()
720 myObjectBrowser->parentWidget()->hide();
723 //******************************************************
724 void XGUI_Workshop::onFeatureTriggered()
726 QAction* aCmd = dynamic_cast<QAction*>(sender());
728 QString aId = salomeConnector()->commandId(aCmd);
730 myPartSetModule->launchOperation(aId);
734 //******************************************************
735 void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart)
737 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
740 if (thePart->data()) {
741 aFeaDoc = thePart->data()->docRef("PartDocument")->value();
743 ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(thePart);
744 aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
747 aMgr->setCurrentDocument(aFeaDoc);
749 aMgr->setCurrentDocument(aMgr->rootDocument());
753 //******************************************************
754 void XGUI_Workshop::salomeViewerSelectionChanged()
756 emit salomeViewerSelection();
760 //**************************************************************
761 XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
763 return mySalomeConnector->viewer();
766 //**************************************************************
767 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
769 QFeatureList aFeatures = mySelector->selectedFeatures();
770 if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0))
771 activatePart(aFeatures.first());
772 else if (theId == "DEACTIVATE_PART_CMD")
773 activatePart(FeaturePtr());
774 else if (theId == "DELETE_CMD")
775 deleteFeatures(aFeatures);
778 //**************************************************************
779 void XGUI_Workshop::activatePart(FeaturePtr theFeature)
781 changeCurrentDocument(theFeature);
782 myObjectBrowser->activatePart(theFeature);
785 //**************************************************************
786 void XGUI_Workshop::activateLastPart()
788 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
789 DocumentPtr aDoc = aMgr->rootDocument();
790 FeaturePtr aLastPart = aDoc->feature(PARTS_GROUP, aDoc->size(PARTS_GROUP) - 1, true);
791 activatePart(aLastPart);
794 //**************************************************************
795 void XGUI_Workshop::deleteFeatures(QFeatureList theList)
797 QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() : myMainWindow;
798 QMessageBox::StandardButton aRes = QMessageBox::warning(aDesktop, tr("Delete features"),
799 tr("Seleted features will be deleted. Continue?"),
800 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
801 if (aRes == QMessageBox::Yes) {
802 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
803 aMgr->rootDocument()->startOperation();
804 foreach (FeaturePtr aFeature, theList) {
805 if (aFeature->getKind() == "Part") {
807 if (aFeature->data()) {
808 aDoc = aFeature->data()->docRef("PartDocument")->value();
810 ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
811 aDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
812 aFeature = aObject->featureRef();
814 if (aDoc == aMgr->currentDocument()) {
818 if (!aFeature->data()) {
819 ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
820 aFeature = aObject->featureRef();
823 aFeature->document()->removeFeature(aFeature);
825 aMgr->rootDocument()->finishOperation();