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()), this, SLOT(onOperationStarted()));
96 connect(myOperationMgr, SIGNAL(operationResumed()), this, SLOT(onOperationStarted()));
97 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
98 this, SLOT(onOperationStopped(ModuleBase_Operation*)));
99 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
102 //******************************************************
103 XGUI_Workshop::~XGUI_Workshop(void)
107 //******************************************************
108 void XGUI_Workshop::startApplication()
111 //Initialize event listening
112 Events_Loop* aLoop = Events_Loop::loop();
113 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
114 //TODO(sbh): Implement static method to extract event id [SEID]
115 Events_ID aFeatureId = aLoop->eventByName(EVENT_FEATURE_LOADED);
116 aLoop->registerListener(this, aFeatureId);
117 Events_ID aPartSetId = aLoop->eventByName("PartSetModuleEvent");
118 aLoop->registerListener(this, aPartSetId);
119 Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED);
120 aLoop->registerListener(this, aFeatureUpdatedId);
121 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
122 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
126 myMainWindow->show();
127 updateCommandStatus();
132 //******************************************************
133 void XGUI_Workshop::initMenu()
135 myContextMenuMgr->createActions();
137 if (isSalomeMode()) {
138 // Create only Undo, Redo commands
139 QAction* aAction = salomeConnector()->addEditCommand("UNDO_CMD",
140 tr("Undo"), tr("Undo last command"),
141 QIcon(":pictures/undo.png"),
142 QKeySequence::Undo, false);
143 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
144 aAction = salomeConnector()->addEditCommand("REDO_CMD",
145 tr("Redo"), tr("Redo last command"),
146 QIcon(":pictures/redo.png"),
147 QKeySequence::Redo, false);
148 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
149 salomeConnector()->addEditMenuSeparator();
152 XGUI_Workbench* aPage = myMainWindow->menuObject()->generalPage();
154 // File commands group
155 XGUI_MenuGroupPanel* aGroup = aPage->addGroup("Default");
157 XGUI_Command* aCommand;
159 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
160 QIcon(":pictures/save.png"), QKeySequence::Save);
161 aCommand->connectTo(this, SLOT(onSave()));
162 //aCommand->disable();
164 aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
165 QIcon(":pictures/undo.png"), QKeySequence::Undo);
166 aCommand->connectTo(this, SLOT(onUndo()));
168 aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
169 QIcon(":pictures/redo.png"), QKeySequence::Redo);
170 aCommand->connectTo(this, SLOT(onRedo()));
172 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
173 QIcon(":pictures/rebuild.png"));
175 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
176 QIcon(":pictures/save.png"));
177 aCommand->connectTo(this, SLOT(onSaveAs()));
178 //aCommand->disable();
180 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
181 QIcon(":pictures/open.png"), QKeySequence::Open);
182 aCommand->connectTo(this, SLOT(onOpen()));
184 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
185 // QIcon(":pictures/new.png"), QKeySequence::New);
186 //aCommand->connectTo(this, SLOT(onNew()));
188 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
189 QIcon(":pictures/close.png"), QKeySequence::Close);
190 aCommand->connectTo(this, SLOT(onExit()));
193 //******************************************************
194 XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
196 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
197 return aMenuBar->addWorkbench(theName);
200 //******************************************************
201 void XGUI_Workshop::processEvent(const Events_Message* theMessage)
203 //A message to start feature creation received.
204 static Events_ID aFeatureLoadedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED);
205 if (theMessage->eventID() == aFeatureLoadedId) {
206 const Config_FeatureMessage* aFeatureMsg = dynamic_cast<const Config_FeatureMessage*>(theMessage);
207 if(!aFeatureMsg->isInternal()) {
208 addFeature(aFeatureMsg);
212 // Process creation of Part
213 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
214 const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
215 std::set<FeaturePtr> aFeatures = aUpdMsg->features();
217 std::set<FeaturePtr>::const_iterator aIt;
218 bool aHasPart = false;
219 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
220 FeaturePtr aFeature = (*aIt);
221 if (aFeature->getKind() == "Part") {
227 //The created part will be created in Object Browser later and we have to activate it
228 // only when it is created everywere
229 QTimer::singleShot(50, this, SLOT(activateLastPart()));
233 // Process deletion of a part
234 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) {
235 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
236 if (aMgr->currentDocument() == aMgr->rootDocument())
237 activatePart(FeaturePtr()); // Activate PartSet
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());
304 //******************************************************
305 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
307 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
309 //!< No need for property panel
310 updateCommandStatus();
312 if(myOperationMgr->operationsCount() > 1) {
313 myActionsMgr->updateAction(theOperation->getDescription()->operationId());
316 if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) {
317 myActionsMgr->restoreCommandState();
324 void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
328 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
332 // Remember features icons
333 myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
335 //Find or create Workbench
336 QString aWchName = QString::fromStdString(theMessage->workbenchId());
337 QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
338 bool isUsePropPanel = theMessage->isUseInput();
339 QString aId = QString::fromStdString(theMessage->id());
340 if (isSalomeMode()) {
341 QAction* aAction = salomeConnector()->addFeature(aWchName,
343 QString::fromStdString(theMessage->text()),
344 QString::fromStdString(theMessage->tooltip()),
345 QIcon(theMessage->icon().c_str()),
346 QKeySequence(), isUsePropPanel);
347 myActionsMgr->addCommand(aAction);
348 salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
349 myPartSetModule->featureCreated(aAction);
352 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
353 XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
355 aPage = addWorkbench(aWchName);
357 //Find or create Group
358 QString aGroupName = QString::fromStdString(theMessage->groupId());
359 XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
361 aGroup = aPage->addGroup(aGroupName);
364 XGUI_Command* aCommand = aGroup->addFeature(aId,
365 QString::fromStdString(theMessage->text()),
366 QString::fromStdString(theMessage->tooltip()),
367 QIcon(theMessage->icon().c_str()),
368 QKeySequence(), isUsePropPanel);
369 aCommand->setUnblockableCommands(aNestedFeatures.split(" "));
370 myActionsMgr->addCommand(aCommand);
371 myPartSetModule->featureCreated(aCommand);
376 * Makes a signal/slot connections between Property Panel
377 * and given operation. The given operation becomes a
378 * current operation and previous operation if exists
380 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
382 QAction* aCommand = 0;
383 if (isSalomeMode()) {
384 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
386 XGUI_MainMenu* aMenu = myMainWindow->menuObject();
387 aCommand = aMenu->feature(theOperation->getDescription()->operationId());
389 //Abort operation on uncheck the command
390 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
394 * Saves document with given name.
396 void XGUI_Workshop::saveDocument(QString theName)
398 QApplication::restoreOverrideCursor();
399 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
400 DocumentPtr aDoc = aMgr->rootDocument();
401 aDoc->save(theName.toLatin1().constData());
402 QApplication::restoreOverrideCursor();
405 //******************************************************
406 void XGUI_Workshop::onExit()
408 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
409 DocumentPtr aDoc = aMgr->rootDocument();
410 if(aDoc->isModified()) {
411 int anAnswer = QMessageBox::question(
412 myMainWindow, tr("Save current file"),
413 tr("The document is modified, save before exit?"),
414 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
415 if(anAnswer == QMessageBox::Save) {
417 } else if (anAnswer == QMessageBox::Cancel) {
424 //******************************************************
425 void XGUI_Workshop::onNew()
427 QApplication::setOverrideCursor(Qt::WaitCursor);
428 if (objectBrowser() == 0) {
430 mySelector->connectViewers();
432 myViewerProxy->connectToViewer();
434 if (!isSalomeMode()) {
435 myMainWindow->showPythonConsole();
436 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
437 aWnd->showMaximized();
438 updateCommandStatus();
440 QApplication::restoreOverrideCursor();
443 //******************************************************
444 void XGUI_Workshop::onOpen()
446 //save current file before close if modified
447 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
448 DocumentPtr aDoc = aMgr->rootDocument();
449 if(aDoc->isModified()) {
450 //TODO(sbh): re-launch the app?
451 int anAnswer = QMessageBox::question(
452 myMainWindow, tr("Save current file"),
453 tr("The document is modified, save before opening another?"),
454 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
455 if(anAnswer == QMessageBox::Save) {
457 } else if (anAnswer == QMessageBox::Cancel) {
464 //show file dialog, check if readable and open
465 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
466 if(myCurrentDir.isEmpty())
468 QFileInfo aFileInfo(myCurrentDir);
469 if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
470 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
474 QApplication::setOverrideCursor(Qt::WaitCursor);
475 aDoc->load(myCurrentDir.toLatin1().constData());
476 QApplication::restoreOverrideCursor();
477 updateCommandStatus();
480 //******************************************************
481 void XGUI_Workshop::onSave()
483 if(myCurrentDir.isEmpty()) {
487 saveDocument(myCurrentDir);
488 updateCommandStatus();
491 //******************************************************
492 void XGUI_Workshop::onSaveAs()
494 QFileDialog dialog(mainWindow());
495 dialog.setWindowTitle(tr("Select directory to save files..."));
496 dialog.setFileMode(QFileDialog::Directory);
497 dialog.setFilter(tr("Folders (*)"));
498 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
499 dialog.setViewMode(QFileDialog::Detail);
504 QString aTempDir = dialog.selectedFiles().first();
506 if(aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).isEmpty()) {
507 int answer = QMessageBox::question(myMainWindow,
509 tr("The folder already contains some files, save anyway?"),
510 QMessageBox::Save|QMessageBox::Cancel);
511 if(answer == QMessageBox::Cancel)
514 myCurrentDir = aTempDir;
518 //******************************************************
519 void XGUI_Workshop::onUndo()
521 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
522 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
523 DocumentPtr aDoc = aMgr->rootDocument();
524 if (aDoc->isOperation())
525 operationMgr()->abortOperation();
527 updateCommandStatus();
530 //******************************************************
531 void XGUI_Workshop::onRedo()
533 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
534 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
535 DocumentPtr aDoc = aMgr->rootDocument();
537 updateCommandStatus();
540 //******************************************************
541 XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
544 QString::fromStdString(library(theModule.toStdString()));
545 if (libName.isEmpty()) {
547 qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ));
552 CREATE_FUNC crtInst = 0;
555 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
559 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
560 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
561 QString aMsg((char*) &lpMsgBuf);
562 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
563 ::LocalFree(lpMsgBuf);
565 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
569 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
570 | FORMAT_MESSAGE_IGNORE_INSERTS,
571 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
572 QString aMsg((char*) &lpMsgBuf);
573 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
574 ::LocalFree(lpMsgBuf);
578 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
580 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
582 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
584 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
589 XGUI_Module* aModule = crtInst ? crtInst(this) : 0;
591 if (!err.isEmpty()) {
593 QMessageBox::warning(mainWindow(), tr("Error"), err);
595 qWarning( qPrintable( err ));
601 //******************************************************
602 bool XGUI_Workshop::activateModule()
604 Config_ModuleReader aModuleReader;
605 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
606 myPartSetModule = loadModule(moduleName);
607 if (!myPartSetModule)
609 myPartSetModule->createFeatures();
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);
653 //******************************************************
654 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
656 QDockWidget* aObjDock = new QDockWidget(theParent);
657 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
658 aObjDock->setWindowTitle(tr("Object browser"));
659 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
660 connect(myObjectBrowser, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(changeCurrentDocument(FeaturePtr)));
661 aObjDock->setWidget(myObjectBrowser);
663 myContextMenuMgr->connectObjectBrowser();
667 //******************************************************
669 * Creates dock widgets, places them in corresponding area
670 * and tabifies if necessary.
672 void XGUI_Workshop::createDockWidgets()
674 QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() :
676 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
677 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
678 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
679 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
680 hidePropertyPanel(); //<! Invisible by default
682 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
684 QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
685 connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
686 QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
687 connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
690 //******************************************************
691 void XGUI_Workshop::showPropertyPanel()
693 QAction* aViewAct = myPropertyPanel->toggleViewAction();
694 //<! Restore ability to close panel from the window's menu
695 aViewAct->setEnabled(true);
696 myPropertyPanel->show();
697 myPropertyPanel->raise();
700 //******************************************************
701 void XGUI_Workshop::hidePropertyPanel()
703 QAction* aViewAct = myPropertyPanel->toggleViewAction();
704 //<! Do not allow to show empty property panel
705 aViewAct->setEnabled(false);
706 myPropertyPanel->hide();
709 //******************************************************
710 void XGUI_Workshop::showObjectBrowser()
712 myObjectBrowser->parentWidget()->show();
715 //******************************************************
716 void XGUI_Workshop::hideObjectBrowser()
718 myObjectBrowser->parentWidget()->hide();
721 //******************************************************
722 void XGUI_Workshop::onFeatureTriggered()
724 QAction* aCmd = dynamic_cast<QAction*>(sender());
726 QString aId = salomeConnector()->commandId(aCmd);
728 myPartSetModule->launchOperation(aId);
732 //******************************************************
733 void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart)
735 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
737 boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = thePart->data()->docRef("PartDocument");
739 aMgr->setCurrentDocument(aDocRef->value());
741 aMgr->setCurrentDocument(aMgr->rootDocument());
745 //******************************************************
746 void XGUI_Workshop::salomeViewerSelectionChanged()
748 emit salomeViewerSelection();
752 //**************************************************************
753 XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
755 return mySalomeConnector->viewer();
758 //**************************************************************
759 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
761 QFeatureList aFeatures = mySelector->selectedFeatures();
762 if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0))
763 activatePart(aFeatures.first());
764 else if (theId == "DEACTIVATE_PART_CMD")
765 activatePart(FeaturePtr());
766 else if (theId == "DELETE_CMD")
767 deleteFeatures(aFeatures);
770 //**************************************************************
771 void XGUI_Workshop::activatePart(FeaturePtr theFeature)
773 changeCurrentDocument(theFeature);
774 myObjectBrowser->activatePart(theFeature);
777 //**************************************************************
778 void XGUI_Workshop::activateLastPart()
780 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
781 DocumentPtr aDoc = aMgr->rootDocument();
782 FeaturePtr aLastPart = aDoc->feature(PARTS_GROUP, aDoc->size(PARTS_GROUP) - 1, true);
783 activatePart(aLastPart);
786 //**************************************************************
787 void XGUI_Workshop::deleteFeatures(QFeatureList theList)
789 QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() : myMainWindow;
790 QMessageBox::StandardButton aRes = QMessageBox::warning(aDesktop, tr("Delete features"),
791 tr("Seleted features will be deleted. Continue?"),
792 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
793 if (aRes == QMessageBox::Yes) {
794 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
795 aMgr->rootDocument()->startOperation();
796 foreach (FeaturePtr aFeature, theList) {
797 if (aFeature->getKind() == "Part") {
798 DocumentPtr aDoc = aFeature->data()->docRef("PartDocument")->value();
799 if (aDoc == aMgr->currentDocument()) {
803 //aDoc = aFeature->document();
804 aMgr->rootDocument()->removeFeature(aFeature);
806 aMgr->rootDocument()->finishOperation();