X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Workshop.cpp;h=f3ac95d98e222d23cba387e0a7cfba64caca25e7;hb=1faf79937e639b380c9d48fda5c1932522718548;hp=a956d04871e44558890fa789101dde8871002dd2;hpb=38718871ed5bbaacc7601df64ff137014d195bd3;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index a956d0487..f3ac95d98 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -19,6 +19,7 @@ #include "XGUI_ErrorDialog.h" #include "XGUI_ViewerProxy.h" #include "XGUI_PropertyPanel.h" +#include "XGUI_ContextMenuMgr.h" #include #include @@ -31,8 +32,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -52,6 +55,17 @@ #include #endif + +QMap XGUI_Workshop::myIcons; + +QString XGUI_Workshop::featureIcon(const std::string& theId) +{ + QString aId(theId.c_str()); + if (myIcons.contains(aId)) + return myIcons[aId]; + return QString(); +} + XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) : QObject(), myCurrentFile(QString()), @@ -66,11 +80,11 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) myDisplayer = new XGUI_Displayer(this); mySelector = new XGUI_SelectionMgr(this); - connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(changeCurrentDocument())); myOperationMgr = new XGUI_OperationMgr(this); myActionsMgr = new XGUI_ActionsMgr(this); myErrorDlg = new XGUI_ErrorDialog(myMainWindow); + myContextMenuMgr = new XGUI_ContextMenuMgr(this); myViewerProxy = new XGUI_ViewerProxy(this); @@ -165,6 +179,7 @@ void XGUI_Workshop::initMenu() QIcon(":pictures/close.png"), QKeySequence::Close); aCommand->connectTo(this, SLOT(onExit())); + myContextMenuMgr->createActions(); } //****************************************************** @@ -204,6 +219,7 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) (ModuleBase_Operation*)(aPartSetMsg->pointer()); if (myOperationMgr->startOperation(anOperation)) { + myPropertyPanel->updateContentWidget(anOperation->feature()); if (anOperation->getDescription()->xmlRepresentation().isEmpty()) { anOperation->commit(); updateCommandStatus(); @@ -246,11 +262,14 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) { ModuleBase_Operation* aOperation = myOperationMgr->currentOperation(); - if(aOperation->getDescription()->xmlRepresentation().isEmpty()) { //!< No need for property panel - updateCommandStatus(); - } else { - hidePropertyPanel(); - updateCommandStatus(); + //!< No need for property panel + updateCommandStatus(); + hidePropertyPanel(); + if(myOperationMgr->operationsCount() > 1) { + myActionsMgr->updateAction(theOperation->getDescription()->operationId()); + return; + } + if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) { myActionsMgr->restoreCommandState(); } } @@ -266,6 +285,9 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) #endif return; } + // Remember features icons + myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon()); + //Find or create Workbench QString aWchName = QString::fromStdString(theMessage->workbenchId()); QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures()); @@ -402,7 +424,7 @@ void XGUI_Workshop::onOpen() } //show file dialog, check if readable and open - myCurrentFile = QFileDialog::getOpenFileName(mainWindow()); + myCurrentFile = QFileDialog::getExistingDirectory(mainWindow()); if(myCurrentFile.isEmpty()) return; QFileInfo aFileInfo(myCurrentFile); @@ -451,6 +473,8 @@ void XGUI_Workshop::onUndo() objectBrowser()->setCurrentIndex(QModelIndex()); boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); boost::shared_ptr aDoc = aMgr->rootDocument(); + if (!operationMgr()->abortOperation()) + return; aDoc->undo(); updateCommandStatus(); } @@ -468,7 +492,8 @@ void XGUI_Workshop::onRedo() //****************************************************** XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule) { - QString libName = library(theModule); + QString libName = + QString::fromStdString(library(theModule.toStdString())); if (libName.isEmpty()) { qWarning( qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) )); @@ -479,7 +504,6 @@ XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule) CREATE_FUNC crtInst = 0; #ifdef WIN32 - HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName)); if (!modLib) { LPVOID lpMsgBuf; @@ -504,23 +528,24 @@ XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule) } #else void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY ); - if ( !modLib ) - err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() ); - else - { + if ( !modLib ) { + err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() ); + } else { crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE ); - if ( !crtInst ) - err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() ); + if ( !crtInst ) { + err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() ); + } } #endif XGUI_Module* aModule = crtInst ? crtInst(this) : 0; if (!err.isEmpty()) { - if (mainWindow() && mainWindow()->isVisible()) + if (mainWindow()) { QMessageBox::warning(mainWindow(), tr("Error"), err); - else + } else { qWarning( qPrintable( err )); + } } return aModule; } @@ -528,7 +553,9 @@ XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule) //****************************************************** bool XGUI_Workshop::activateModule() { - myPartSetModule = loadModule("PartSet"); + Config_ModuleReader aModuleReader; + QString moduleName = QString::fromStdString(aModuleReader.getModuleName()); + myPartSetModule = loadModule(moduleName); if (!myPartSetModule) return false; myPartSetModule->createFeatures(); @@ -549,25 +576,25 @@ void XGUI_Workshop::updateCommandStatus() if (aMgr->hasRootDocument()) { XGUI_Command* aUndoCmd; XGUI_Command* aRedoCmd; - for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) { - if ((*aIt)->id() == "UNDO_CMD") - aUndoCmd = (*aIt); - else if ((*aIt)->id() == "REDO_CMD") - aRedoCmd = (*aIt); + foreach(XGUI_Command* aCmd, aCommands) { + if (aCmd->id() == "UNDO_CMD") + aUndoCmd = aCmd; + else if (aCmd->id() == "REDO_CMD") + aRedoCmd = aCmd; else // Enable all commands - (*aIt)->enable(); + aCmd->enable(); } boost::shared_ptr aDoc = aMgr->rootDocument(); aUndoCmd->setEnabled(aDoc->canUndo()); aRedoCmd->setEnabled(aDoc->canRedo()); } else { - for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) { - if ((*aIt)->id() == "NEW_CMD") - (*aIt)->enable(); - else if ((*aIt)->id() == "EXIT_CMD") - (*aIt)->enable(); + foreach(XGUI_Command* aCmd, aCommands) { + if (aCmd->id() == "NEW_CMD") + aCmd->enable(); + else if (aCmd->id() == "EXIT_CMD") + aCmd->enable(); else - (*aIt)->disable(); + aCmd->disable(); } } } @@ -579,7 +606,10 @@ QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent) aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); aObjDock->setWindowTitle(tr("Object browser")); myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock); + connect(myObjectBrowser, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(changeCurrentDocument(FeaturePtr))); aObjDock->setWidget(myObjectBrowser); + + myContextMenuMgr->connectObjectBrowser(); return aObjDock; } @@ -644,18 +674,15 @@ void XGUI_Workshop::onFeatureTriggered() } //****************************************************** -void XGUI_Workshop::changeCurrentDocument() +void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart) { - QFeatureList aFeatures = objectBrowser()->selectedFeatures(); - - // Set current document - if (aFeatures.size() > 0) { - FeaturePtr aFeature = aFeatures.first(); - - boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); - boost::shared_ptr aDocRef = aFeature->data()->docRef("PartDocument"); + boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); + if (thePart) { + boost::shared_ptr aDocRef = thePart->data()->docRef("PartDocument"); if (aDocRef) aMgr->setCurrentDocument(aDocRef->value()); + } else { + aMgr->setCurrentDocument(aMgr->rootDocument()); } }