From 1b7b206cae69001c80bad8d17bb0c42f5a01e576 Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Wed, 4 Dec 2013 15:51:36 +0100 Subject: [PATCH] - for now flip order on load, as the simulator is still the old one --- SpatialSBML/spatialsimulator.cpp | 50 ++++++++++++++++++++++++++++++++ SpatialSBML/spatialsimulator.h | 7 +++++ SpatialUI/geometryeditwidget.cpp | 48 ++---------------------------- SpatialUI/spatialmainwidget.cpp | 3 +- 4 files changed, 61 insertions(+), 47 deletions(-) diff --git a/SpatialSBML/spatialsimulator.cpp b/SpatialSBML/spatialsimulator.cpp index b614972..7a3e6c9 100644 --- a/SpatialSBML/spatialsimulator.cpp +++ b/SpatialSBML/spatialsimulator.cpp @@ -3597,6 +3597,56 @@ const Model* SpatialSimulator::getModel() const return model; } +struct sort_pair +{ + bool operator() (std::pair i, std::pair j) + { + return (i.second < j.second); + } +} sorter; + + +void flipOrder(AnalyticGeometry& geometry) +{ + if (geometry.getNumAnalyticVolumes() == 0) return; + + std::vector> list; + for (size_t i = 0; i < geometry.getNumAnalyticVolumes(); ++i) + { + AnalyticVolume* current = geometry.getAnalyticVolume(i); + list.push_back(std::pair((int)i, (int)current->getOrdinal())); + } + + std::sort(list.begin(), list.end(), sorter); + + for (std::vector>::iterator it=list.begin(); it!=list.end(); ++it) + { + AnalyticVolume* current = geometry.getAnalyticVolume(it->first); + current->setOrdinal((geometry.getNumAnalyticVolumes()-1)-it->second); + } + + +} + +void SpatialSimulator::flipVolumeOrder() +{ + if (model == NULL) + return; + SpatialModelPlugin* plugin = dynamic_cast(model->getPlugin("spatial")); + if (plugin == NULL) + return; + + Geometry* geometry = plugin->getGeometry(); + + for (size_t i = 0; i < geometry->getNumGeometryDefinitions(); ++i) + { + AnalyticGeometry* definition = dynamic_cast(geometry->getGeometryDefinition(i)); + if (definition == NULL) + continue; + flipOrder(*definition); + } +} + int SpatialSimulator::getIndexForPosition(double x, double y) { for (int Y = 0; Y < Yindex; Y += 2 ) { diff --git a/SpatialSBML/spatialsimulator.h b/SpatialSBML/spatialsimulator.h index c2abf66..3322f81 100644 --- a/SpatialSBML/spatialsimulator.h +++ b/SpatialSBML/spatialsimulator.h @@ -185,6 +185,13 @@ class SpatialSimulator */ const Model* getModel() const; + /** + * flips the order of analytic volumes + */ + void flipVolumeOrder(); + + + /** * Sets the specified value uniformly on the provided variable info * structure. diff --git a/SpatialUI/geometryeditwidget.cpp b/SpatialUI/geometryeditwidget.cpp index e4938ff..d2df1e2 100644 --- a/SpatialUI/geometryeditwidget.cpp +++ b/SpatialUI/geometryeditwidget.cpp @@ -267,57 +267,13 @@ void GeometryEditWidget::handleButtons(QAbstractButton * button) } -struct sort_pair -{ - bool operator() (std::pair i, std::pair j) - { - return (i.second < j.second); - } -} sorter; - -void flipOrder(AnalyticGeometry& geometry) -{ - if (geometry.getNumAnalyticVolumes() == 0) return; - - std::vector> list; - for (size_t i = 0; i < geometry.getNumAnalyticVolumes(); ++i) - { - AnalyticVolume* current = geometry.getAnalyticVolume(i); - list.push_back(std::pair((int)i, (int)current->getOrdinal())); - } - - std::sort(list.begin(), list.end(), sorter); - - for (std::vector>::iterator it=list.begin(); it!=list.end(); ++it) - { - AnalyticVolume* current = geometry.getAnalyticVolume(it->first); - current->setOrdinal((geometry.getNumAnalyticVolumes()-1)-it->second); - } - - -} void GeometryEditWidget::flipVolumeOrder() { if (mpSimulator == NULL) return; - Model* model = const_cast(mpSimulator->getModel()); - if (model == NULL) - return; - SpatialModelPlugin* plugin = dynamic_cast(model->getPlugin("spatial")); - if (plugin == NULL) - return; - - Geometry* geometry = plugin->getGeometry(); - - for (size_t i = 0; i < geometry->getNumGeometryDefinitions(); ++i) - { - AnalyticGeometry* definition = dynamic_cast(geometry->getGeometryDefinition(i)); - if (definition == NULL) - continue; - flipOrder(*definition); - mNeedReload = true; - } + mpSimulator->flipVolumeOrder(); + mNeedReload = true; } void GeometryEditWidget::updateUI() diff --git a/SpatialUI/spatialmainwidget.cpp b/SpatialUI/spatialmainwidget.cpp index db20e95..7307f78 100644 --- a/SpatialUI/spatialmainwidget.cpp +++ b/SpatialUI/spatialmainwidget.cpp @@ -535,7 +535,6 @@ void SpatialMainWindow::loadFromDocument(SBMLDocument* toLoad) return; } - lstSpecies->clear(); ui->lstDose->clear(); @@ -573,6 +572,8 @@ void SpatialMainWindow::loadFromDocument(SBMLDocument* toLoad) + restart(); + thread->mpSimulator->flipVolumeOrder(); restart(); ui->tblParameters->clear();