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"
23 #include "XGUI_ModuleConnector.h"
25 #include <Model_Events.h>
26 #include <ModelAPI_PluginManager.h>
27 #include <ModelAPI_Feature.h>
28 #include <ModelAPI_Data.h>
29 #include <ModelAPI_AttributeDocRef.h>
30 #include <ModelAPI_Object.h>
32 #include <PartSetPlugin_Part.h>
34 #include <Events_Loop.h>
35 #include <Events_Error.h>
36 #include <ModuleBase_Operation.h>
37 #include <ModuleBase_Operation.h>
38 #include <ModuleBase_OperationDescription.h>
39 #include <Config_Common.h>
40 #include <Config_FeatureMessage.h>
41 #include <Config_PointerMessage.h>
42 #include <Config_ModuleReader.h>
44 #include <QApplication>
45 #include <QFileDialog>
46 #include <QMessageBox>
47 #include <QMdiSubWindow>
48 #include <QPushButton>
49 #include <QDockWidget>
64 QMap<QString, QString> XGUI_Workshop::myIcons;
66 QString XGUI_Workshop::featureIcon(const std::string& theId)
68 QString aId(theId.c_str());
69 if (myIcons.contains(aId))
74 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
76 myCurrentDir(QString()),
77 myPartSetModule(NULL),
78 mySalomeConnector(theConnector),
83 myMainWindow = mySalomeConnector? 0 : new XGUI_MainWindow();
85 myDisplayer = new XGUI_Displayer(this);
87 mySelector = new XGUI_SelectionMgr(this);
89 myOperationMgr = new XGUI_OperationMgr(this);
90 myActionsMgr = new XGUI_ActionsMgr(this);
91 myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
92 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
93 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)),
94 this, SLOT(onContextMenuCommand(const QString&, bool)));
96 myViewerProxy = new XGUI_ViewerProxy(this);
98 myModuleConnector = new XGUI_ModuleConnector(this);
100 connect(myOperationMgr, SIGNAL(operationStarted()), SLOT(onOperationStarted()));
101 connect(myOperationMgr, SIGNAL(operationResumed()), SLOT(onOperationStarted()));
102 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), SLOT(onOperationStopped(ModuleBase_Operation*)));
103 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
104 connect(myOperationMgr, SIGNAL(operationStarted()), myActionsMgr, SLOT(update()));
105 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), myActionsMgr, SLOT(update()));
106 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
109 //******************************************************
110 XGUI_Workshop::~XGUI_Workshop(void)
114 //******************************************************
115 void XGUI_Workshop::startApplication()
118 //Initialize event listening
119 Events_Loop* aLoop = Events_Loop::loop();
120 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
121 //TODO(sbh): Implement static method to extract event id [SEID]
122 Events_ID aFeatureId = aLoop->eventByName(EVENT_FEATURE_LOADED);
123 aLoop->registerListener(this, aFeatureId);
124 Events_ID aPartSetId = aLoop->eventByName("PartSetModuleEvent");
125 aLoop->registerListener(this, aPartSetId);
126 Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED);
127 aLoop->registerListener(this, aFeatureUpdatedId);
128 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
132 myMainWindow->show();
133 updateCommandStatus();
138 //******************************************************
139 void XGUI_Workshop::initMenu()
141 myContextMenuMgr->createActions();
143 if (isSalomeMode()) {
144 // Create only Undo, Redo commands
145 QAction* aAction = salomeConnector()->addEditCommand("UNDO_CMD",
146 tr("Undo"), tr("Undo last command"),
147 QIcon(":pictures/undo.png"),
148 QKeySequence::Undo, false);
149 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
150 aAction = salomeConnector()->addEditCommand("REDO_CMD",
151 tr("Redo"), tr("Redo last command"),
152 QIcon(":pictures/redo.png"),
153 QKeySequence::Redo, false);
154 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
155 salomeConnector()->addEditMenuSeparator();
158 XGUI_Workbench* aPage = myMainWindow->menuObject()->generalPage();
160 // File commands group
161 XGUI_MenuGroupPanel* aGroup = aPage->addGroup("Default");
163 XGUI_Command* aCommand;
165 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
166 QIcon(":pictures/save.png"), QKeySequence::Save);
167 aCommand->connectTo(this, SLOT(onSave()));
168 //aCommand->disable();
170 aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
171 QIcon(":pictures/undo.png"), QKeySequence::Undo);
172 aCommand->connectTo(this, SLOT(onUndo()));
174 aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
175 QIcon(":pictures/redo.png"), QKeySequence::Redo);
176 aCommand->connectTo(this, SLOT(onRedo()));
178 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
179 QIcon(":pictures/rebuild.png"));
181 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
182 QIcon(":pictures/save.png"));
183 aCommand->connectTo(this, SLOT(onSaveAs()));
184 //aCommand->disable();
186 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
187 QIcon(":pictures/open.png"), QKeySequence::Open);
188 aCommand->connectTo(this, SLOT(onOpen()));
190 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
191 // QIcon(":pictures/new.png"), QKeySequence::New);
192 //aCommand->connectTo(this, SLOT(onNew()));
194 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
195 QIcon(":pictures/close.png"), QKeySequence::Close);
196 aCommand->connectTo(this, SLOT(onExit()));
197 //FIXME: SBH's test action. Can be used for some GUI tests.
199 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
200 // QIcon(":pictures/close.png"));
201 // aCommand->connectTo(myActionsMgr, SLOT(update()));
205 //******************************************************
206 XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
208 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
209 return aMenuBar->addWorkbench(theName);
212 //******************************************************
213 void XGUI_Workshop::processEvent(const Events_Message* theMessage)
215 //A message to start feature creation received.
216 static Events_ID aFeatureLoadedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED);
217 if (theMessage->eventID() == aFeatureLoadedId) {
218 const Config_FeatureMessage* aFeatureMsg = dynamic_cast<const Config_FeatureMessage*>(theMessage);
219 if(!aFeatureMsg->isInternal()) {
220 addFeature(aFeatureMsg);
224 // Process creation of Part
225 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
226 const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
227 std::set<FeaturePtr> aFeatures = aUpdMsg->features();
229 std::set<FeaturePtr>::const_iterator aIt;
230 bool aHasPart = false;
231 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
232 FeaturePtr aFeature = (*aIt);
233 if (aFeature->getKind() == PARTSET_PART_KIND) {
239 //The created part will be created in Object Browser later and we have to activate it
240 // only when it is created everywere
241 QTimer::singleShot(50, this, SLOT(activateLastPart()));
245 //Update property panel on corresponding message. If there is no current operation (no
246 //property panel), or received message has different feature to the current - do nothing.
247 static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED);
248 if (theMessage->eventID() == aFeatureUpdatedId && myOperationMgr->hasOperation())
250 const Model_FeatureUpdatedMessage* anUpdateMsg =
251 dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
252 std::set<FeaturePtr> aFeatures = anUpdateMsg->features();
254 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
255 std::set<FeaturePtr>::const_iterator aIt;
256 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
257 FeaturePtr aNewFeature = (*aIt);
258 if(aNewFeature == aCurrentFeature) {
259 myPropertyPanel->updateContentWidget(aCurrentFeature);
264 //An operation passed by message. Start it, process and commit.
265 const Config_PointerMessage* aPartSetMsg = dynamic_cast<const Config_PointerMessage*>(theMessage);
267 // Clear previous content
268 myPropertyPanel->cleanContent();
269 ModuleBase_Operation* anOperation =
270 (ModuleBase_Operation*)(aPartSetMsg->pointer());
272 if (myOperationMgr->startOperation(anOperation)) {
273 myPropertyPanel->updateContentWidget(anOperation->feature());
274 if (anOperation->getDescription()->xmlRepresentation().isEmpty()) {
275 anOperation->commit();
276 updateCommandStatus();
281 //Show error dialog if error message received.
282 const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
284 emit errorOccurred(QString::fromLatin1(anAppError->description()));
289 //******************************************************
290 void XGUI_Workshop::onOperationStarted()
292 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
294 if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) { //!< No need for property panel
295 connectWithOperation(aOperation);
299 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation, myModuleConnector);
300 QWidget* aContent = myPropertyPanel->contentWidget();
301 qDeleteAll(aContent->children());
302 aFactory.createWidget(aContent);
303 myPropertyPanel->setModelWidgets(aFactory.getModelWidgets());
304 myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
306 updateCommandStatus();
309 //******************************************************
310 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
312 //!< No need for property panel
313 updateCommandStatus();
320 void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
324 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
328 // Remember features icons
329 myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
331 //Find or create Workbench
332 QString aWchName = QString::fromStdString(theMessage->workbenchId());
333 QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
334 bool isUsePropPanel = theMessage->isUseInput();
335 QString aId = QString::fromStdString(theMessage->id());
336 if (isSalomeMode()) {
337 QAction* aAction = salomeConnector()->addFeature(aWchName,
339 QString::fromStdString(theMessage->text()),
340 QString::fromStdString(theMessage->tooltip()),
341 QIcon(theMessage->icon().c_str()),
342 QKeySequence(), isUsePropPanel);
343 salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
344 myActionsMgr->addCommand(aAction);
345 myPartSetModule->featureCreated(aAction);
348 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
349 XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
351 aPage = addWorkbench(aWchName);
353 //Find or create Group
354 QString aGroupName = QString::fromStdString(theMessage->groupId());
355 XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
357 aGroup = aPage->addGroup(aGroupName);
360 XGUI_Command* aCommand = aGroup->addFeature(aId,
361 QString::fromStdString(theMessage->text()),
362 QString::fromStdString(theMessage->tooltip()),
363 QIcon(theMessage->icon().c_str()),
364 QKeySequence(), isUsePropPanel);
365 aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
366 myActionsMgr->addCommand(aCommand);
367 myPartSetModule->featureCreated(aCommand);
372 * Makes a signal/slot connections between Property Panel
373 * and given operation. The given operation becomes a
374 * current operation and previous operation if exists
376 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
378 QAction* aCommand = 0;
379 if (isSalomeMode()) {
380 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
382 XGUI_MainMenu* aMenu = myMainWindow->menuObject();
383 aCommand = aMenu->feature(theOperation->getDescription()->operationId());
385 //Abort operation on uncheck the command
386 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
390 * Saves document with given name.
392 void XGUI_Workshop::saveDocument(QString theName)
394 QApplication::restoreOverrideCursor();
395 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
396 DocumentPtr aDoc = aMgr->rootDocument();
397 aDoc->save(theName.toLatin1().constData());
398 QApplication::restoreOverrideCursor();
401 //******************************************************
402 void XGUI_Workshop::onExit()
404 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
405 DocumentPtr aDoc = aMgr->rootDocument();
406 if(aDoc->isModified()) {
407 int anAnswer = QMessageBox::question(
408 myMainWindow, tr("Save current file"),
409 tr("The document is modified, save before exit?"),
410 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
411 if(anAnswer == QMessageBox::Save) {
412 bool saved = onSave();
416 } else if (anAnswer == QMessageBox::Cancel) {
423 //******************************************************
424 void XGUI_Workshop::onNew()
426 QApplication::setOverrideCursor(Qt::WaitCursor);
427 if (objectBrowser() == 0) {
429 mySelector->connectViewers();
431 myViewerProxy->connectToViewer();
433 if (!isSalomeMode()) {
434 myMainWindow->showPythonConsole();
435 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
436 myContextMenuMgr->connectViewer();
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 updateCommandStatus();
477 myObjectBrowser->rebuildDataTree();
478 QApplication::restoreOverrideCursor();
481 //******************************************************
482 bool XGUI_Workshop::onSave()
484 if(myCurrentDir.isEmpty()) {
487 saveDocument(myCurrentDir);
488 updateCommandStatus();
492 //******************************************************
493 bool XGUI_Workshop::onSaveAs()
495 QFileDialog dialog(mainWindow());
496 dialog.setWindowTitle(tr("Select directory to save files..."));
497 dialog.setFileMode(QFileDialog::Directory);
498 dialog.setFilter(tr("Folders (*)"));
499 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
500 dialog.setViewMode(QFileDialog::Detail);
505 QString aTempDir = dialog.selectedFiles().first();
507 if(aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).isEmpty()) {
508 int answer = QMessageBox::question(myMainWindow,
509 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
511 tr("The folder already contains some files, save anyway?"),
512 QMessageBox::Save|QMessageBox::Cancel);
513 if(answer == QMessageBox::Cancel) {
517 myCurrentDir = aTempDir;
521 //******************************************************
522 void XGUI_Workshop::onUndo()
524 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
525 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
526 DocumentPtr aDoc = aMgr->rootDocument();
527 if (aDoc->isOperation())
528 operationMgr()->abortOperation();
530 updateCommandStatus();
533 //******************************************************
534 void XGUI_Workshop::onRedo()
536 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
537 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
538 DocumentPtr aDoc = aMgr->rootDocument();
539 if (aDoc->isOperation())
540 operationMgr()->abortOperation();
542 updateCommandStatus();
545 //******************************************************
546 XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
549 QString::fromStdString(library(theModule.toStdString()));
550 if (libName.isEmpty()) {
552 qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ));
557 CREATE_FUNC crtInst = 0;
560 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
564 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
565 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
566 QString aMsg((char*) &lpMsgBuf);
567 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
568 ::LocalFree(lpMsgBuf);
570 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
574 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
575 | FORMAT_MESSAGE_IGNORE_INSERTS,
576 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
577 QString aMsg((char*) &lpMsgBuf);
578 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
579 ::LocalFree(lpMsgBuf);
583 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
585 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
587 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
589 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
594 XGUI_Module* aModule = crtInst ? crtInst(this) : 0;
596 if (!err.isEmpty()) {
598 QMessageBox::warning(mainWindow(), tr("Error"), err);
600 qWarning( qPrintable( err ));
606 //******************************************************
607 bool XGUI_Workshop::activateModule()
609 Config_ModuleReader aModuleReader;
610 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
611 myPartSetModule = loadModule(moduleName);
612 if (!myPartSetModule)
614 myPartSetModule->createFeatures();
615 myActionsMgr->update();
619 //******************************************************
620 void XGUI_Workshop::updateCommandStatus()
622 QList<QAction*> aCommands;
623 if (isSalomeMode()) { // update commands in SALOME mode
624 aCommands = salomeConnector()->commandList();
626 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
627 foreach (XGUI_Command* aCmd, aMenuBar->features())
628 aCommands.append(aCmd);
630 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
631 if (aMgr->hasRootDocument()) {
634 foreach(QAction* aCmd, aCommands) {
635 QString aId = aCmd->data().toString();
636 if (aId == "UNDO_CMD")
638 else if (aId == "REDO_CMD")
640 else // Enable all commands
641 aCmd->setEnabled(true);
643 DocumentPtr aDoc = aMgr->rootDocument();
644 aUndoCmd->setEnabled(aDoc->canUndo());
645 aRedoCmd->setEnabled(aDoc->canRedo());
647 foreach(QAction* aCmd, aCommands) {
648 QString aId = aCmd->data().toString();
649 if (aId == "NEW_CMD")
650 aCmd->setEnabled(true);
651 else if (aId == "EXIT_CMD")
652 aCmd->setEnabled(true);
654 aCmd->setEnabled(false);
657 myActionsMgr->update();
660 //******************************************************
661 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
663 QDockWidget* aObjDock = new QDockWidget(theParent);
664 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
665 aObjDock->setWindowTitle(tr("Object browser"));
666 aObjDock->setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
667 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
668 connect(myObjectBrowser, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(changeCurrentDocument(FeaturePtr)));
669 aObjDock->setWidget(myObjectBrowser);
671 myContextMenuMgr->connectObjectBrowser();
675 //******************************************************
677 * Creates dock widgets, places them in corresponding area
678 * and tabifies if necessary.
680 void XGUI_Workshop::createDockWidgets()
682 QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() :
684 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
685 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
686 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
687 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
688 hidePropertyPanel(); //<! Invisible by default
690 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
692 QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
693 connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
694 QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
695 connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
697 connect(myPropertyPanel, SIGNAL(keyReleased(const std::string&, QKeyEvent*)),
698 myOperationMgr, SLOT(onKeyReleased(const std::string&, QKeyEvent*)));
701 //******************************************************
702 void XGUI_Workshop::showPropertyPanel()
704 QAction* aViewAct = myPropertyPanel->toggleViewAction();
705 //<! Restore ability to close panel from the window's menu
706 aViewAct->setEnabled(true);
707 myPropertyPanel->show();
708 myPropertyPanel->raise();
711 //******************************************************
712 void XGUI_Workshop::hidePropertyPanel()
714 QAction* aViewAct = myPropertyPanel->toggleViewAction();
715 //<! Do not allow to show empty property panel
716 aViewAct->setEnabled(false);
717 myPropertyPanel->hide();
720 //******************************************************
721 void XGUI_Workshop::showObjectBrowser()
723 myObjectBrowser->parentWidget()->show();
726 //******************************************************
727 void XGUI_Workshop::hideObjectBrowser()
729 myObjectBrowser->parentWidget()->hide();
732 //******************************************************
733 void XGUI_Workshop::onFeatureTriggered()
735 QAction* aCmd = dynamic_cast<QAction*>(sender());
737 QString aId = salomeConnector()->commandId(aCmd);
739 myPartSetModule->launchOperation(aId);
743 //******************************************************
744 void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart)
746 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
749 if (!XGUI_Tools::isModelObject(thePart)) {
750 aFeaDoc = thePart->data()->docRef("PartDocument")->value();
752 ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(thePart);
753 aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
756 aMgr->setCurrentDocument(aFeaDoc);
758 aMgr->setCurrentDocument(aMgr->rootDocument());
762 //******************************************************
763 void XGUI_Workshop::salomeViewerSelectionChanged()
765 emit salomeViewerSelection();
769 //**************************************************************
770 XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
772 return mySalomeConnector->viewer();
775 //**************************************************************
776 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
778 QFeatureList aFeatures = mySelector->selectedFeatures();
779 if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0))
780 activatePart(aFeatures.first());
781 else if (theId == "DEACTIVATE_PART_CMD")
782 activatePart(FeaturePtr());
783 else if (theId == "DELETE_CMD")
784 deleteFeatures(aFeatures);
785 else if (theId == "SHOW_CMD")
786 showFeatures(aFeatures, true);
787 else if (theId == "HIDE_CMD")
788 showFeatures(aFeatures, false);
791 //**************************************************************
792 void XGUI_Workshop::activatePart(FeaturePtr theFeature)
794 changeCurrentDocument(theFeature);
795 myObjectBrowser->activatePart(theFeature);
798 //**************************************************************
799 void XGUI_Workshop::activateLastPart()
801 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
802 DocumentPtr aDoc = aMgr->rootDocument();
803 FeaturePtr aLastPart = aDoc->feature(PARTS_GROUP, aDoc->size(PARTS_GROUP) - 1, true);
804 activatePart(aLastPart);
807 //**************************************************************
808 void XGUI_Workshop::deleteFeatures(QFeatureList theList)
810 QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() : myMainWindow;
811 QMessageBox::StandardButton aRes = QMessageBox::warning(aDesktop, tr("Delete features"),
812 tr("Seleted features will be deleted. Continue?"),
813 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
814 if (aRes == QMessageBox::Yes) {
815 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
816 aMgr->rootDocument()->startOperation();
817 foreach (FeaturePtr aFeature, theList) {
818 if (aFeature->getKind() == PARTSET_PART_KIND) {
820 if (!XGUI_Tools::isModelObject(aFeature)) {
821 aDoc = aFeature->data()->docRef("PartDocument")->value();
823 ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
824 aDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
825 aFeature = aObject->featureRef();
827 if (aDoc == aMgr->currentDocument()) {
831 if (XGUI_Tools::isModelObject(aFeature)) {
832 ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
833 aFeature = aObject->featureRef();
836 if (myDisplayer->isVisible(aFeature))
837 myDisplayer->erase(aFeature, false);
838 aFeature->document()->removeFeature(aFeature);
840 myDisplayer->updateViewer();
841 aMgr->rootDocument()->finishOperation();
845 //**************************************************************
846 void XGUI_Workshop::showFeatures(QFeatureList theList, bool isVisible)
849 foreach (FeaturePtr aFeature, theList) {
850 myDisplayer->display(aFeature, false);
853 foreach (FeaturePtr aFeature, theList) {
854 myDisplayer->erase(aFeature, false);
857 myDisplayer->updateViewer();