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 myCurrentFile(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 addFeature(aFeatureMsg);
210 // Process creation of Part
211 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
212 const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
213 FeaturePtr aFeature = aUpdMsg->feature();
214 if (aFeature->getKind() == "Part") {
215 //The created part will be created in Object Browser later and we have to activate it
216 // only when it is created everywere
217 QTimer::singleShot(50, this, SLOT(activateLastPart()));
221 // Process deletion of a part
222 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) {
223 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
224 if (aMgr->currentDocument() == aMgr->rootDocument())
225 activatePart(FeaturePtr()); // Activate PartSet
228 //Update property panel on corresponding message. If there is no current operation (no
229 //property panel), or received message has different feature to the current - do nothing.
230 static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED);
231 if (theMessage->eventID() == aFeatureUpdatedId && myOperationMgr->hasOperation())
233 const Model_FeatureUpdatedMessage* anUpdateMsg =
234 dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
235 FeaturePtr aNewFeature = anUpdateMsg->feature();
236 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
237 if(aNewFeature == aCurrentFeature) {
238 myPropertyPanel->updateContentWidget(aCurrentFeature);
241 //An operation passed by message. Start it, process and commit.
242 const Config_PointerMessage* aPartSetMsg = dynamic_cast<const Config_PointerMessage*>(theMessage);
244 ModuleBase_Operation* anOperation =
245 (ModuleBase_Operation*)(aPartSetMsg->pointer());
247 if (myOperationMgr->startOperation(anOperation)) {
248 myPropertyPanel->updateContentWidget(anOperation->feature());
249 if (anOperation->getDescription()->xmlRepresentation().isEmpty()) {
250 anOperation->commit();
251 updateCommandStatus();
256 //Show error dialog if error message received.
257 const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
259 emit errorOccurred(QString::fromLatin1(anAppError->description()));
262 myErrorDlg->activateWindow();
267 //******************************************************
268 void XGUI_Workshop::onOperationStarted()
270 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
272 if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) { //!< No need for property panel
273 connectWithOperation(aOperation);
277 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation);
278 QWidget* aContent = myPropertyPanel->contentWidget();
279 qDeleteAll(aContent->children());
280 aFactory.createWidget(aContent);
281 myPropertyPanel->setModelWidgets(aFactory.getModelWidgets());
282 myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
286 //******************************************************
287 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
289 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
291 //!< No need for property panel
292 updateCommandStatus();
294 if(myOperationMgr->operationsCount() > 1) {
295 myActionsMgr->updateAction(theOperation->getDescription()->operationId());
298 if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) {
299 myActionsMgr->restoreCommandState();
306 void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
310 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
314 // Remember features icons
315 myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
317 //Find or create Workbench
318 QString aWchName = QString::fromStdString(theMessage->workbenchId());
319 QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
320 bool isUsePropPanel = theMessage->isUseInput();
321 if (isSalomeMode()) {
322 QString aId = QString::fromStdString(theMessage->id());
323 QAction* aAction = salomeConnector()->addFeature(aWchName,
325 QString::fromStdString(theMessage->text()),
326 QString::fromStdString(theMessage->tooltip()),
327 QIcon(theMessage->icon().c_str()),
328 QKeySequence(), isUsePropPanel);
329 myActionsMgr->addCommand(aAction);
330 salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
331 myPartSetModule->featureCreated(aAction);
334 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
335 XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
337 aPage = addWorkbench(aWchName);
339 //Find or create Group
340 QString aGroupName = QString::fromStdString(theMessage->groupId());
341 XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
343 aGroup = aPage->addGroup(aGroupName);
346 XGUI_Command* aCommand = aGroup->addFeature(QString::fromStdString(theMessage->id()),
347 QString::fromStdString(theMessage->text()),
348 QString::fromStdString(theMessage->tooltip()),
349 QIcon(theMessage->icon().c_str()),
350 QKeySequence(), isUsePropPanel);
351 aCommand->setUnblockableCommands(aNestedFeatures.split(" "));
352 myActionsMgr->addCommand(aCommand);
353 myPartSetModule->featureCreated(aCommand);
358 * Makes a signal/slot connections between Property Panel
359 * and given operation. The given operation becomes a
360 * current operation and previous operation if exists
362 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
364 QAction* aCommand = 0;
365 if (isSalomeMode()) {
366 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
368 XGUI_MainMenu* aMenu = myMainWindow->menuObject();
369 aCommand = aMenu->feature(theOperation->getDescription()->operationId());
371 //Abort operation on uncheck the command
372 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
376 * Saves document with given name.
378 void XGUI_Workshop::saveDocument(QString theName)
380 QApplication::restoreOverrideCursor();
381 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
382 DocumentPtr aDoc = aMgr->rootDocument();
383 aDoc->save(theName.toLatin1().constData());
384 QApplication::restoreOverrideCursor();
387 //******************************************************
388 void XGUI_Workshop::onExit()
390 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
391 DocumentPtr aDoc = aMgr->rootDocument();
392 if(aDoc->isModified()) {
393 int anAnswer = QMessageBox::question(
394 myMainWindow, tr("Save current file"),
395 tr("The document is modified, save before exit?"),
396 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
397 if(anAnswer == QMessageBox::Save) {
399 } else if (anAnswer == QMessageBox::Cancel) {
406 //******************************************************
407 void XGUI_Workshop::onNew()
409 QApplication::setOverrideCursor(Qt::WaitCursor);
410 if (objectBrowser() == 0) {
412 mySelector->connectViewers();
414 myViewerProxy->connectToViewer();
416 if (!isSalomeMode()) {
417 myMainWindow->showPythonConsole();
418 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
419 aWnd->showMaximized();
420 updateCommandStatus();
422 QApplication::restoreOverrideCursor();
425 //******************************************************
426 void XGUI_Workshop::onOpen()
428 //save current file before close if modified
429 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
430 DocumentPtr aDoc = aMgr->rootDocument();
431 if(aDoc->isModified()) {
432 //TODO(sbh): re-launch the app?
433 int anAnswer = QMessageBox::question(
434 myMainWindow, tr("Save current file"),
435 tr("The document is modified, save before opening another?"),
436 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
437 if(anAnswer == QMessageBox::Save) {
439 } else if (anAnswer == QMessageBox::Cancel) {
446 //show file dialog, check if readable and open
447 myCurrentFile = QFileDialog::getExistingDirectory(mainWindow());
448 if(myCurrentFile.isEmpty())
450 QFileInfo aFileInfo(myCurrentFile);
451 if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
452 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
456 QApplication::setOverrideCursor(Qt::WaitCursor);
457 aDoc->load(myCurrentFile.toLatin1().constData());
458 QApplication::restoreOverrideCursor();
459 updateCommandStatus();
462 //******************************************************
463 void XGUI_Workshop::onSave()
465 if(myCurrentFile.isEmpty()) {
469 saveDocument(myCurrentFile);
470 updateCommandStatus();
473 //******************************************************
474 void XGUI_Workshop::onSaveAs()
476 QString aTemp = myCurrentFile;
477 myCurrentFile = QFileDialog::getSaveFileName(mainWindow());
478 if(myCurrentFile.isEmpty()) {
479 myCurrentFile = aTemp;
482 QFileInfo aFileInfo(myCurrentFile);
483 if(aFileInfo.exists() && !aFileInfo.isWritable()) {
484 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to save the file."));
490 //******************************************************
491 void XGUI_Workshop::onUndo()
493 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
494 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
495 DocumentPtr aDoc = aMgr->rootDocument();
496 if (aDoc->isOperation())
497 operationMgr()->abortOperation();
499 updateCommandStatus();
502 //******************************************************
503 void XGUI_Workshop::onRedo()
505 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
506 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
507 DocumentPtr aDoc = aMgr->rootDocument();
509 updateCommandStatus();
512 //******************************************************
513 XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
516 QString::fromStdString(library(theModule.toStdString()));
517 if (libName.isEmpty()) {
519 qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ));
524 CREATE_FUNC crtInst = 0;
527 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
531 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
532 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
533 QString aMsg((char*) &lpMsgBuf);
534 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
535 ::LocalFree(lpMsgBuf);
537 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
541 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
542 | FORMAT_MESSAGE_IGNORE_INSERTS,
543 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
544 QString aMsg((char*) &lpMsgBuf);
545 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
546 ::LocalFree(lpMsgBuf);
550 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY );
552 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
554 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
556 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
561 XGUI_Module* aModule = crtInst ? crtInst(this) : 0;
563 if (!err.isEmpty()) {
565 QMessageBox::warning(mainWindow(), tr("Error"), err);
567 qWarning( qPrintable( err ));
573 //******************************************************
574 bool XGUI_Workshop::activateModule()
576 Config_ModuleReader aModuleReader;
577 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
578 myPartSetModule = loadModule(moduleName);
579 if (!myPartSetModule)
581 myPartSetModule->createFeatures();
585 //******************************************************
586 void XGUI_Workshop::updateCommandStatus()
588 QList<QAction*> aCommands;
589 if (isSalomeMode()) { // update commands in SALOME mode
590 aCommands = salomeConnector()->commandList();
592 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
593 foreach (XGUI_Command* aCmd, aMenuBar->features())
594 aCommands.append(aCmd);
596 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
597 if (aMgr->hasRootDocument()) {
600 foreach(QAction* aCmd, aCommands) {
601 QString aId = aCmd->data().toString();
602 if (aId == "UNDO_CMD")
604 else if (aId == "REDO_CMD")
606 else // Enable all commands
607 aCmd->setEnabled(true);
609 DocumentPtr aDoc = aMgr->rootDocument();
610 aUndoCmd->setEnabled(aDoc->canUndo());
611 aRedoCmd->setEnabled(aDoc->canRedo());
613 foreach(QAction* aCmd, aCommands) {
614 QString aId = aCmd->data().toString();
615 if (aId == "NEW_CMD")
616 aCmd->setEnabled(true);
617 else if (aId == "EXIT_CMD")
618 aCmd->setEnabled(true);
620 aCmd->setEnabled(false);
625 //******************************************************
626 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
628 QDockWidget* aObjDock = new QDockWidget(theParent);
629 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
630 aObjDock->setWindowTitle(tr("Object browser"));
631 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
632 connect(myObjectBrowser, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(changeCurrentDocument(FeaturePtr)));
633 aObjDock->setWidget(myObjectBrowser);
635 myContextMenuMgr->connectObjectBrowser();
639 //******************************************************
641 * Creates dock widgets, places them in corresponding area
642 * and tabifies if necessary.
644 void XGUI_Workshop::createDockWidgets()
646 QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() :
648 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
649 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
650 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
651 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
652 hidePropertyPanel(); //<! Invisible by default
654 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
656 QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
657 connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
658 QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
659 connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
662 //******************************************************
663 void XGUI_Workshop::showPropertyPanel()
665 QAction* aViewAct = myPropertyPanel->toggleViewAction();
666 //<! Restore ability to close panel from the window's menu
667 aViewAct->setEnabled(true);
668 myPropertyPanel->show();
669 myPropertyPanel->raise();
672 //******************************************************
673 void XGUI_Workshop::hidePropertyPanel()
675 QAction* aViewAct = myPropertyPanel->toggleViewAction();
676 //<! Do not allow to show empty property panel
677 aViewAct->setEnabled(false);
678 myPropertyPanel->hide();
681 //******************************************************
682 void XGUI_Workshop::showObjectBrowser()
684 myObjectBrowser->parentWidget()->show();
687 //******************************************************
688 void XGUI_Workshop::hideObjectBrowser()
690 myObjectBrowser->parentWidget()->hide();
693 //******************************************************
694 void XGUI_Workshop::onFeatureTriggered()
696 QAction* aCmd = dynamic_cast<QAction*>(sender());
698 QString aId = salomeConnector()->commandId(aCmd);
700 myPartSetModule->launchOperation(aId);
704 //******************************************************
705 void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart)
707 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
709 boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = thePart->data()->docRef("PartDocument");
711 aMgr->setCurrentDocument(aDocRef->value());
713 aMgr->setCurrentDocument(aMgr->rootDocument());
717 //******************************************************
718 void XGUI_Workshop::salomeViewerSelectionChanged()
720 emit salomeViewerSelection();
724 //**************************************************************
725 XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
727 return mySalomeConnector->viewer();
730 //**************************************************************
731 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
733 QFeatureList aFeatures = mySelector->selectedFeatures();
734 if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0))
735 activatePart(aFeatures.first());
736 else if (theId == "DEACTIVATE_PART_CMD")
737 activatePart(FeaturePtr());
738 else if (theId == "DELETE_CMD")
739 deleteFeatures(aFeatures);
742 //**************************************************************
743 void XGUI_Workshop::activatePart(FeaturePtr theFeature)
745 changeCurrentDocument(theFeature);
746 myObjectBrowser->activatePart(theFeature);
749 //**************************************************************
750 void XGUI_Workshop::activateLastPart()
752 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
753 DocumentPtr aDoc = aMgr->rootDocument();
754 FeaturePtr aLastPart = aDoc->feature(PARTS_GROUP, aDoc->size(PARTS_GROUP) - 1, true);
755 activatePart(aLastPart);
758 //**************************************************************
759 void XGUI_Workshop::deleteFeatures(QFeatureList theList)
761 QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() : myMainWindow;
762 QMessageBox::StandardButton aRes = QMessageBox::warning(aDesktop, tr("Delete features"),
763 tr("Seleted features will be deleted. Continue?"),
764 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
765 if (aRes == QMessageBox::Yes) {
766 foreach (FeaturePtr aFeature, theList) {
767 DocumentPtr aDoc = aFeature->data()->docRef("PartDocument")->value();
768 aDoc->removeFeature(aFeature);