From e2cf0e61aa66eb9fdd95df82fafb6bb9f4b30890 Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Tue, 1 Jul 2014 13:35:35 +0200 Subject: [PATCH] - sort SBW interface, so non-spatial models can be send to editor if found --- CMakeLists.txt | 16 +++++++- SpatialSBML/setInfoFunction.cpp | 2 +- SpatialUI/CMakeLists.txt | 19 ++-------- SpatialUI/spatialmainwidget.cpp | 65 ++++++++++++++++++++++++++++++--- SpatialUI/spatialmainwidget.h | 2 + 5 files changed, 81 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81a1aa3..90e58cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,11 +106,25 @@ endif() ############################################################################### # -# SBW Integration +# SBW Integration # option(ENABLE_SBW "Enable SBW Integration." ON) +SET(USE_SBW_INTEGRATION 0) if (ENABLE_SBW) +SET(USE_SBW_INTEGRATION 1) +add_definitions(-DUSE_SBW_INTEGRATION) + + +if (APPLE) +add_definitions(-DDARWIN) +endif() + +if (UNIX) +add_definitions(-DLINUX) +endif() + + find_library(SBW_LIBRARY NAMES SBW-static.lib SBW-static SBW PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 diff --git a/SpatialSBML/setInfoFunction.cpp b/SpatialSBML/setInfoFunction.cpp index a30e954..b57cd15 100644 --- a/SpatialSBML/setInfoFunction.cpp +++ b/SpatialSBML/setInfoFunction.cpp @@ -513,7 +513,7 @@ normalUnitVector* setNormalAngle(vector &geoInfoList, double Xsiz //X = X; Y = Y - 2; preD = S; - } else if (isD[Z * Yindex * Xindex + (Y - 1) * Xindex + (X - 1)] == 1 && preD != NE) {//southwest + } else if ((Y - 1) >= 0 && isD[Z * Yindex * Xindex + (Y - 1) * Xindex + (X - 1)] == 1 && preD != NE) {//southwest X = X - 1; Y = Y - 1; preD = SW; diff --git a/SpatialUI/CMakeLists.txt b/SpatialUI/CMakeLists.txt index e8fb59e..7fb27f1 100644 --- a/SpatialUI/CMakeLists.txt +++ b/SpatialUI/CMakeLists.txt @@ -11,7 +11,7 @@ cmake_policy(SET CMP0020 NEW) if (PREFIX_PATH) -set (CMAKE_PREFIX_PATH "${PREFIX_PATH}") +set (CMAKE_PREFIX_PATH "${PREFIX_PATH}") endif() include(${CMAKE_CURRENT_SOURCE_DIR}/ChooseQtVersion.cmake) @@ -70,20 +70,6 @@ set(MACOSX_BUNDLE_COPYRIGHT ${MACOSX_BUNDLE_INFO_STRING}) endif(APPLE) -if (ENABLE_SBW) - -include_directories(${SBW_INCLUDE_DIR}) -add_definitions(-DUSE_SBW_INTEGRATION) - -if (APPLE) -add_definitions(-DDARWIN) -endif() - -if (UNIX) -add_definitions(-DLINUX) -endif() -endif() - add_executable(SpatialUI ${EXECUTABLE_FLAGS} ${CPP_FILES} ${H_FILES} @@ -98,6 +84,8 @@ QT_BIND_TO_TARGET(SpatialUI) target_link_libraries(SpatialUI ${EXTRA_LIBS} SpatialSBML) if (ENABLE_SBW) + include_directories(${SBW_INCLUDE_DIR}) + #set_target_properties(SpatialUI PROPERTIES AUTOMOC_MOC_OPTIONS -DUSE_SBW_INTEGRATION) target_link_libraries(SpatialUI ${EXTRA_LIBS} SpatialSBML ${SBW_LIBRARY}) if (WIN32) @@ -106,7 +94,6 @@ if (ENABLE_SBW) endif() - file(GLOB PALETTE_FILES palettes/*.txt ) file(COPY ${PALETTE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/SpatialUI/spatialmainwidget.cpp b/SpatialUI/spatialmainwidget.cpp index 96d15e3..dbfb938 100644 --- a/SpatialUI/spatialmainwidget.cpp +++ b/SpatialUI/spatialmainwidget.cpp @@ -41,7 +41,15 @@ using namespace std; LIBSBML_CPP_NAMESPACE_USE; -SpatialMainWindow::SpatialMainWindow() : thread(NULL), updating(false), pickerX(0), pickerY(0), maxX(501), maxY(501) +SpatialMainWindow::SpatialMainWindow() + : thread(NULL) + , doc(NULL) + , updating(false) + , pickerX(0) + , pickerY(0) + , maxX(501) + , maxY(501) + , mHaveEdit(false) #ifdef USE_SBW_INTEGRATION , mpSBWModule(NULL) , mSBWAnalyzerModules() @@ -90,7 +98,7 @@ SpatialMainWindow::SpatialMainWindow() : thread(NULL), updating(false), pickerX( sbwConnect(); sbwRegister(); - + #endif // USE_SBW_INTEGRATION @@ -937,10 +945,44 @@ bool SpatialMainWindow::loadFromDocument(SBMLDocument* toLoad) if (!haveSpatial) { +#if USE_SBW_INTEGRATION + if (mHaveEdit) + { + if (QMessageBox::question(this, tr("Spatial UI"), + tr("It would seem that the given model '%1' does not use the spatial package. Would you like to add a spatial description to it?\n") + .arg(curFile), QMessageBox::Yes | QMessageBox::Default , QMessageBox::No) == + QMessageBox::Yes) + { + try + { + int nModule = SBWLowLevel::getModuleInstance("EditSpatial"); + int nService = SBWLowLevel::moduleFindServiceByName(nModule, "analysis"); + int nMethod = SBWLowLevel::serviceGetMethod(nModule, nService, "void doAnalysis(string)"); + + DataBlockWriter args; + args << writeSBMLToString(doc); + SBWLowLevel::methodSend(nModule, nService, nMethod, args); + + } + + catch (SBWException * pE) + { + QMessageBox::critical(this, "SBW Error", + pE->getMessage().c_str(), + QMessageBox::Ok | QMessageBox::Default, + QMessageBox::NoButton); + } + } + + } + else +#endif + { QMessageBox::critical(this, tr("Spatial UI"), tr("It would seem that the given model '%1' does not use the spatial package. Please load one that does. \n") .arg(curFile) ); + } return false; } @@ -1016,13 +1058,20 @@ void SpatialMainWindow::loadFromString(const std::string& sbml) updating = true; stop(); - doc = readSBMLFromString(sbml.c_str()); + QString current = curFile; setCurrentFile("fromSBW.xml"); + doc = readSBMLFromString(sbml.c_str()); + if (loadFromDocument(doc)) + { statusBar()->showMessage(tr("File loaded"), 2000); + } else + { statusBar()->showMessage(tr("File could not be loaded"), 2000); + setCurrentFile("invalid.xml"); + } updating = false; @@ -1043,16 +1092,17 @@ void SpatialMainWindow::loadFile(const QString &fileName) } lastDir = QFileInfo(fileName).absoluteDir().absolutePath(); + setCurrentFile(fileName); doc = readSBMLFromFile(fileName.toStdString().c_str()); if (loadFromDocument(doc)) { statusBar()->showMessage(tr("File loaded"), 2000); - setCurrentFile(fileName); } else { statusBar()->showMessage(tr("File could not be loaded"), 2000); + setCurrentFile("invalid.xml"); } updating = false; @@ -1456,6 +1506,8 @@ void SpatialMainWindow::sbwRefreshMenu() } } + mHaveEdit |= mHaveEdit || ModuleName == "EditSpatial"; + SortedNames[MenuName.c_str()] = i++; ModuleList.append(ModuleName.c_str()); ServiceList.append(ServiceName.c_str()); @@ -1479,11 +1531,13 @@ void SpatialMainWindow::sbwRefreshMenu() mSBWAnalyzerModules.append(ModuleList[itMap.value()]); mSBWAnalyzerServices.append(ServiceList[itMap.value()]); - pAction = new QAction(itMap.key(), mpSBWActionGroup); + pAction = mpSBWActionGroup->addAction(itMap.key()); mpSBWMenu->addAction(pAction); mSBWActionMap[pAction] = i; + } + if (mSBWAnalyzerModules.empty()) Visible = false; } @@ -1505,6 +1559,7 @@ void SpatialMainWindow::sbwSlotMenuTriggeredFinished(bool success) void SpatialMainWindow::sbwSlotMenuTriggered(QAction * pAction) { + if (doc == NULL) return; mSBWActionId = mSBWActionMap[pAction]; diff --git a/SpatialUI/spatialmainwidget.h b/SpatialUI/spatialmainwidget.h index 1a90e34..66d984b 100644 --- a/SpatialUI/spatialmainwidget.h +++ b/SpatialUI/spatialmainwidget.h @@ -173,6 +173,8 @@ private slots:; int maxX; int maxY; + bool mHaveEdit; + std::vector palettes; std::vector displayItems;