Skip to content

Commit

Permalink
- sort SBW interface, so non-spatial models can be send to editor if …
Browse files Browse the repository at this point in the history
…found
  • Loading branch information
fbergmann committed Jul 1, 2014
1 parent a8424f3 commit e2cf0e6
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 23 deletions.
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion SpatialSBML/setInfoFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ normalUnitVector* setNormalAngle(vector<GeometryInfo*> &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;
Expand Down
19 changes: 3 additions & 16 deletions SpatialUI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand All @@ -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)
Expand All @@ -106,7 +94,6 @@ if (ENABLE_SBW)

endif()


file(GLOB PALETTE_FILES palettes/*.txt )
file(COPY ${PALETTE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

Expand Down
65 changes: 60 additions & 5 deletions SpatialUI/spatialmainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -90,7 +98,7 @@ SpatialMainWindow::SpatialMainWindow() : thread(NULL), updating(false), pickerX(

sbwConnect();
sbwRegister();

#endif // USE_SBW_INTEGRATION


Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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;
}
Expand All @@ -1505,6 +1559,7 @@ void SpatialMainWindow::sbwSlotMenuTriggeredFinished(bool success)

void SpatialMainWindow::sbwSlotMenuTriggered(QAction * pAction)
{
if (doc == NULL) return;

mSBWActionId = mSBWActionMap[pAction];

Expand Down
2 changes: 2 additions & 0 deletions SpatialUI/spatialmainwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ private slots:;
int maxX;
int maxY;

bool mHaveEdit;

std::vector<ConcentrationPalette*> palettes;
std::vector<DisplayItem*> displayItems;

Expand Down

0 comments on commit e2cf0e6

Please sign in to comment.