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()), 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));
124 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
128 myMainWindow->show();
129 updateCommandStatus();
134 //******************************************************
135 void XGUI_Workshop::initMenu()
137 myContextMenuMgr->createActions();
139 if (isSalomeMode()) {
140 // Create only Undo, Redo commands
141 QAction* aAction = salomeConnector()->addEditCommand("UNDO_CMD",
142 tr("Undo"), tr("Undo last command"),
143 QIcon(":pictures/undo.png"),
144 QKeySequence::Undo, false);
145 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
146 aAction = salomeConnector()->addEditCommand("REDO_CMD",
147 tr("Redo"), tr("Redo last command"),
148 QIcon(":pictures/redo.png"),
149 QKeySequence::Redo, false);
150 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
151 salomeConnector()->addEditMenuSeparator();
154 XGUI_Workbench* aPage = myMainWindow->menuObject()->generalPage();
156 // File commands group
157 XGUI_MenuGroupPanel* aGroup = aPage->addGroup("Default");
159 XGUI_Command* aCommand;
161 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
162 QIcon(":pictures/save.png"), QKeySequence::Save);
163 aCommand->connectTo(this, SLOT(onSave()));
164 //aCommand->disable();
166 aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
167 QIcon(":pictures/undo.png"), QKeySequence::Undo);
168 aCommand->connectTo(this, SLOT(onUndo()));
170 aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
171 QIcon(":pictures/redo.png"), QKeySequence::Redo);
172 aCommand->connectTo(this, SLOT(onRedo()));
174 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
175 QIcon(":pictures/rebuild.png"));
177 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
178 QIcon(":pictures/save.png"));
179 aCommand->connectTo(this, SLOT(onSaveAs()));
180 //aCommand->disable();
182 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
183 QIcon(":pictures/open.png"), QKeySequence::Open);
184 aCommand->connectTo(this, SLOT(onOpen()));
186 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
187 // QIcon(":pictures/new.png"), QKeySequence::New);
188 //aCommand->connectTo(this, SLOT(onNew()));
190 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
191 QIcon(":pictures/close.png"), QKeySequence::Close);
192 aCommand->connectTo(this, SLOT(onExit()));
193 //FIXME: SBH's test action. Can be used for some GUI tests.
195 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
196 // QIcon(":pictures/close.png"));
197 // aCommand->connectTo(myActionsMgr, SLOT(update()));
201 //******************************************************
202 XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
204 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
205 return aMenuBar->addWorkbench(theName);
208 //******************************************************
209 void XGUI_Workshop::processEvent(const Events_Message* theMessage)
211 //A message to start feature creation received.
212 static Events_ID aFeatureLoadedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED);
213 if (theMessage->eventID() == aFeatureLoadedId) {
214 const Config_FeatureMessage* aFeatureMsg = dynamic_cast<const Config_FeatureMessage*>(theMessage);
215 if(!aFeatureMsg->isInternal()) {
216 addFeature(aFeatureMsg);
220 // Process creation of Part
221 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
222 const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
223 std::set<FeaturePtr> aFeatures = aUpdMsg->features();
225 std::set<FeaturePtr>::const_iterator aIt;
226 bool aHasPart = false;
227 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
228 FeaturePtr aFeature = (*aIt);
229 if (aFeature->getKind() == "Part") {
235 //The created part will be created in Object Browser later and we have to activate it
236 // only when it is created everywere
237 QTimer::singleShot(50, this, SLOT(activateLastPart()));
241 // Process deletion of a part
242 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) {
243 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
244 if (aMgr->currentDocument() == aMgr->rootDocument())
245 activatePart(FeaturePtr()); // Activate PartSet
248 //Update property panel on corresponding message. If there is no current operation (no
249 //property panel), or received message has different feature to the current - do nothing.
250 static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED);
251 if (theMessage->eventID() == aFeatureUpdatedId && myOperationMgr->hasOperation())
253 const Model_FeatureUpdatedMessage* anUpdateMsg =
254 dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
255 std::set<FeaturePtr> aFeatures = anUpdateMsg->features();
257 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
258 std::set<FeaturePtr>::const_iterator aIt;
259 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
260 FeaturePtr aNewFeature = (*aIt);
261 if(aNewFeature == aCurrentFeature) {
262 myPropertyPanel->updateContentWidget(aCurrentFeature);
267 //An operation passed by message. Start it, process and commit.
268 const Config_PointerMessage* aPartSetMsg = dynamic_cast<const Config_PointerMessage*>(theMessage);
270 ModuleBase_Operation* anOperation =
271 (ModuleBase_Operation*)(aPartSetMsg->pointer());
273 if (myOperationMgr->startOperation(anOperation)) {
274 myPropertyPanel->updateContentWidget(anOperation->feature());
275 if (anOperation->getDescription()->xmlRepresentation().isEmpty()) {
276 anOperation->commit();
277 updateCommandStatus();
282 //Show error dialog if error message received.
283 const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
285 emit errorOccurred(QString::fromLatin1(anAppError->description()));
288 myErrorDlg->activateWindow();
293 //******************************************************
294 void XGUI_Workshop::onOperationStarted()
296 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
298 if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) { //!< No need for property panel
299 connectWithOperation(aOperation);
303 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation);
304 QWidget* aContent = myPropertyPanel->contentWidget();
305 qDeleteAll(aContent->children());
306 aFactory.createWidget(aContent);
307 myPropertyPanel->setModelWidgets(aFactory.getModelWidgets());
308 myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
312 //******************************************************
313 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
315 //!< No need for property panel
316 updateCommandStatus();
323 void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
327 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
331 // Remember features icons
332 myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
334 //Find or create Workbench
335 QString aWchName = QString::fromStdString(theMessage->workbenchId());
336 QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
337 bool isUsePropPanel = theMessage->isUseInput();
338 QString aId = QString::fromStdString(theMessage->id());
339 if (isSalomeMode()) {
340 QAction* aAction = salomeConnector()->addFeature(aWchName,
342 QString::fromStdString(theMessage->text()),
343 QString::fromStdString(theMessage->tooltip()),
344 QIcon(theMessage->icon().c_str()),
345 QKeySequence(), isUsePropPanel);
346 myActionsMgr->addCommand(aAction);
347 salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
348 myPartSetModule->featureCreated(aAction);
351 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
352 XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
354 aPage = addWorkbench(aWchName);
356 //Find or create Group
357 QString aGroupName = QString::fromStdString(theMessage->groupId());
358 XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
360 aGroup = aPage->addGroup(aGroupName);
363 XGUI_Command* aCommand = aGroup->addFeature(aId,
364 QString::fromStdString(theMessage->text()),
365 QString::fromStdString(theMessage->tooltip()),
366 QIcon(theMessage->icon().c_str()),
367 QKeySequence(), isUsePropPanel);
368 aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
369 myActionsMgr->addCommand(aCommand);
370 myPartSetModule->featureCreated(aCommand);
375 * Makes a signal/slot connections between Property Panel
376 * and given operation. The given operation becomes a
377 * current operation and previous operation if exists
379 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
381 QAction* aCommand = 0;
382 if (isSalomeMode()) {
383 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
385 XGUI_MainMenu* aMenu = myMainWindow->menuObject();
386 aCommand = aMenu->feature(theOperation->getDescription()->operationId());
388 //Abort operation on uncheck the command
389 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
393 * Saves document with given name.
395 void XGUI_Workshop::saveDocument(QString theName)
397 QApplication::restoreOverrideCursor();
398 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
399 DocumentPtr aDoc = aMgr->rootDocument();
400 aDoc->save(theName.toLatin1().constData());
401 QApplication::restoreOverrideCursor();
404 //******************************************************
405 void XGUI_Workshop::onExit()
407 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
408 DocumentPtr aDoc = aMgr->rootDocument();
409 if(aDoc->isModified()) {
410 int anAnswer = QMessageBox::question(
411 myMainWindow, tr("Save current file"),
412 tr("The document is modified, save before exit?"),
413 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
414 if(anAnswer == QMessageBox::Save) {
415 bool saved = onSave();
419 } else if (anAnswer == QMessageBox::Cancel) {
426 //******************************************************
427 void XGUI_Workshop::onNew()
429 QApplication::setOverrideCursor(Qt::WaitCursor);
430 if (objectBrowser() == 0) {
432 mySelector->connectViewers();
434 myViewerProxy->connectToViewer();
436 if (!isSalomeMode()) {
437 myMainWindow->showPythonConsole();
438 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
439 aWnd->showMaximized();
440 updateCommandStatus();
442 QApplication::restoreOverrideCursor();
445 //******************************************************
446 void XGUI_Workshop::onOpen()
448 //save current file before close if modified
449 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
450 DocumentPtr aDoc = aMgr->rootDocument();
451 if(aDoc->isModified()) {
452 //TODO(sbh): re-launch the app?
453 int anAnswer = QMessageBox::question(
454 myMainWindow, tr("Save current file"),
455 tr("The document is modified, save before opening another?"),
456 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
457 if(anAnswer == QMessageBox::Save) {
459 } else if (anAnswer == QMessageBox::Cancel) {
466 //show file dialog, check if readable and open
467 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
468 if(myCurrentDir.isEmpty())
470 QFileInfo aFileInfo(myCurrentDir);
471 if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
472 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
476 QApplication::setOverrideCursor(Qt::WaitCursor);
477 aDoc->load(myCurrentDir.toLatin1().constData());
478 QApplication::restoreOverrideCursor();
479 updateCommandStatus();
482 //******************************************************
483 bool XGUI_Workshop::onSave()
485 if(myCurrentDir.isEmpty()) {
488 saveDocument(myCurrentDir);
489 updateCommandStatus();
493 //******************************************************
494 bool XGUI_Workshop::onSaveAs()
496 QFileDialog dialog(mainWindow());
497 dialog.setWindowTitle(tr("Select directory to save files..."));
498 dialog.setFileMode(QFileDialog::Directory);
499 dialog.setFilter(tr("Folders (*)"));
500 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
501 dialog.setViewMode(QFileDialog::Detail);
506 QString aTempDir = dialog.selectedFiles().first();
508 if(aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).isEmpty()) {
509 int answer = QMessageBox::question(myMainWindow,
510 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
512 tr("The folder already contains some files, save anyway?"),
513 QMessageBox::Save|QMessageBox::Cancel);
514 if(answer == QMessageBox::Cancel) {
518 myCurrentDir = aTempDir;
522 //******************************************************
523 void XGUI_Workshop::onUndo()
525 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
526 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
527 DocumentPtr aDoc = aMgr->rootDocument();
528 if (aDoc->isOperation())
529 operationMgr()->abortOperation();
531 updateCommandStatus();
534 //******************************************************
535 void XGUI_Workshop::onRedo()
537 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
538 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
539 DocumentPtr aDoc = aMgr->rootDocument();
541 updateCommandStatus();
544 //******************************************************
545 XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
548 QString::fromStdString(library(theModule.toStdString()));
549 if (libName.isEmpty()) {
551 qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ));
556 CREATE_FUNC crtInst = 0;
559 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
563 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
564 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
565 QString aMsg((char*) &lpMsgBuf);
566 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
567 ::LocalFree(lpMsgBuf);
569 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
573 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
574 | FORMAT_MESSAGE_IGNORE_INSERTS,
575 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
576 QString aMsg((char*) &lpMsgBuf);
577 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
578 ::LocalFree(lpMsgBuf);
582 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
584 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
586 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
588 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
593 XGUI_Module* aModule = crtInst ? crtInst(this) : 0;
595 if (!err.isEmpty()) {
597 QMessageBox::warning(mainWindow(), tr("Error"), err);
599 qWarning( qPrintable( err ));
605 //******************************************************
606 bool XGUI_Workshop::activateModule()
608 Config_ModuleReader aModuleReader;
609 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
610 myPartSetModule = loadModule(moduleName);
611 if (!myPartSetModule)
613 myPartSetModule->createFeatures();
614 myActionsMgr->update();
618 //******************************************************
619 void XGUI_Workshop::updateCommandStatus()
621 QList<QAction*> aCommands;
622 if (isSalomeMode()) { // update commands in SALOME mode
623 aCommands = salomeConnector()->commandList();
625 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
626 foreach (XGUI_Command* aCmd, aMenuBar->features())
627 aCommands.append(aCmd);
629 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
630 if (aMgr->hasRootDocument()) {
633 foreach(QAction* aCmd, aCommands) {
634 QString aId = aCmd->data().toString();
635 if (aId == "UNDO_CMD")
637 else if (aId == "REDO_CMD")
639 else // Enable all commands
640 aCmd->setEnabled(true);
642 DocumentPtr aDoc = aMgr->rootDocument();
643 aUndoCmd->setEnabled(aDoc->canUndo());
644 aRedoCmd->setEnabled(aDoc->canRedo());
646 foreach(QAction* aCmd, aCommands) {
647 QString aId = aCmd->data().toString();
648 if (aId == "NEW_CMD")
649 aCmd->setEnabled(true);
650 else if (aId == "EXIT_CMD")
651 aCmd->setEnabled(true);
653 aCmd->setEnabled(false);
656 myActionsMgr->update();
659 //******************************************************
660 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
662 QDockWidget* aObjDock = new QDockWidget(theParent);
663 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
664 aObjDock->setWindowTitle(tr("Object browser"));
665 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
666 connect(myObjectBrowser, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(changeCurrentDocument(FeaturePtr)));
667 aObjDock->setWidget(myObjectBrowser);
669 myContextMenuMgr->connectObjectBrowser();
673 //******************************************************
675 * Creates dock widgets, places them in corresponding area
676 * and tabifies if necessary.
678 void XGUI_Workshop::createDockWidgets()
680 QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() :
682 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
683 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
684 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
685 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
686 hidePropertyPanel(); //<! Invisible by default
688 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
690 QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
691 connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
692 QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
693 connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
696 //******************************************************
697 void XGUI_Workshop::showPropertyPanel()
699 QAction* aViewAct = myPropertyPanel->toggleViewAction();
700 //<! Restore ability to close panel from the window's menu
701 aViewAct->setEnabled(true);
702 myPropertyPanel->show();
703 myPropertyPanel->raise();
706 //******************************************************
707 void XGUI_Workshop::hidePropertyPanel()
709 QAction* aViewAct = myPropertyPanel->toggleViewAction();
710 //<! Do not allow to show empty property panel
711 aViewAct->setEnabled(false);
712 myPropertyPanel->hide();
715 //******************************************************
716 void XGUI_Workshop::showObjectBrowser()
718 myObjectBrowser->parentWidget()->show();
721 //******************************************************
722 void XGUI_Workshop::hideObjectBrowser()
724 myObjectBrowser->parentWidget()->hide();
727 //******************************************************
728 void XGUI_Workshop::onFeatureTriggered()
730 QAction* aCmd = dynamic_cast<QAction*>(sender());
732 QString aId = salomeConnector()->commandId(aCmd);
734 myPartSetModule->launchOperation(aId);
738 //******************************************************
739 void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart)
741 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
743 boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = thePart->data()->docRef("PartDocument");
745 aMgr->setCurrentDocument(aDocRef->value());
747 aMgr->setCurrentDocument(aMgr->rootDocument());
751 //******************************************************
752 void XGUI_Workshop::salomeViewerSelectionChanged()
754 emit salomeViewerSelection();
758 //**************************************************************
759 XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
761 return mySalomeConnector->viewer();
764 //**************************************************************
765 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
767 QFeatureList aFeatures = mySelector->selectedFeatures();
768 if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0))
769 activatePart(aFeatures.first());
770 else if (theId == "DEACTIVATE_PART_CMD")
771 activatePart(FeaturePtr());
772 else if (theId == "DELETE_CMD")
773 deleteFeatures(aFeatures);
776 //**************************************************************
777 void XGUI_Workshop::activatePart(FeaturePtr theFeature)
779 changeCurrentDocument(theFeature);
780 myObjectBrowser->activatePart(theFeature);
783 //**************************************************************
784 void XGUI_Workshop::activateLastPart()
786 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
787 DocumentPtr aDoc = aMgr->rootDocument();
788 FeaturePtr aLastPart = aDoc->feature(PARTS_GROUP, aDoc->size(PARTS_GROUP) - 1, true);
789 activatePart(aLastPart);
792 //**************************************************************
793 void XGUI_Workshop::deleteFeatures(QFeatureList theList)
795 QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() : myMainWindow;
796 QMessageBox::StandardButton aRes = QMessageBox::warning(aDesktop, tr("Delete features"),
797 tr("Seleted features will be deleted. Continue?"),
798 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
799 if (aRes == QMessageBox::Yes) {
800 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
801 aMgr->rootDocument()->startOperation();
802 foreach (FeaturePtr aFeature, theList) {
803 if (aFeature->getKind() == "Part") {
804 DocumentPtr aDoc = aFeature->data()->docRef("PartDocument")->value();
805 if (aDoc == aMgr->currentDocument()) {
809 //aDoc = aFeature->document();
810 aMgr->rootDocument()->removeFeature(aFeature);
812 aMgr->rootDocument()->finishOperation();