Skip to content

Commit

Permalink
- for now flip order on load, as the simulator is still the old one
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Dec 4, 2013
1 parent 48880ef commit 1b7b206
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 47 deletions.
50 changes: 50 additions & 0 deletions SpatialSBML/spatialsimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3597,6 +3597,56 @@ const Model* SpatialSimulator::getModel() const
return model;
}

struct sort_pair
{
bool operator() (std::pair<int, int> i, std::pair<int, int> j)
{
return (i.second < j.second);
}
} sorter;


void flipOrder(AnalyticGeometry& geometry)
{
if (geometry.getNumAnalyticVolumes() == 0) return;

std::vector<std::pair<int, int>> list;
for (size_t i = 0; i < geometry.getNumAnalyticVolumes(); ++i)
{
AnalyticVolume* current = geometry.getAnalyticVolume(i);
list.push_back(std::pair<int, int>((int)i, (int)current->getOrdinal()));
}

std::sort(list.begin(), list.end(), sorter);

for (std::vector<std::pair<int, int>>::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<SpatialModelPlugin*>(model->getPlugin("spatial"));
if (plugin == NULL)
return;

Geometry* geometry = plugin->getGeometry();

for (size_t i = 0; i < geometry->getNumGeometryDefinitions(); ++i)
{
AnalyticGeometry* definition = dynamic_cast<AnalyticGeometry*>(geometry->getGeometryDefinition(i));
if (definition == NULL)
continue;
flipOrder(*definition);
}
}

int SpatialSimulator::getIndexForPosition(double x, double y)
{
for (int Y = 0; Y < Yindex; Y += 2 ) {
Expand Down
7 changes: 7 additions & 0 deletions SpatialSBML/spatialsimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
48 changes: 2 additions & 46 deletions SpatialUI/geometryeditwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,57 +267,13 @@ void GeometryEditWidget::handleButtons(QAbstractButton * button)

}

struct sort_pair
{
bool operator() (std::pair<int, int> i, std::pair<int, int> j)
{
return (i.second < j.second);
}
} sorter;

void flipOrder(AnalyticGeometry& geometry)
{
if (geometry.getNumAnalyticVolumes() == 0) return;

std::vector<std::pair<int, int>> list;
for (size_t i = 0; i < geometry.getNumAnalyticVolumes(); ++i)
{
AnalyticVolume* current = geometry.getAnalyticVolume(i);
list.push_back(std::pair<int, int>((int)i, (int)current->getOrdinal()));
}

std::sort(list.begin(), list.end(), sorter);

for (std::vector<std::pair<int, int>>::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<Model*>(mpSimulator->getModel());
if (model == NULL)
return;
SpatialModelPlugin* plugin = dynamic_cast<SpatialModelPlugin*>(model->getPlugin("spatial"));
if (plugin == NULL)
return;

Geometry* geometry = plugin->getGeometry();

for (size_t i = 0; i < geometry->getNumGeometryDefinitions(); ++i)
{
AnalyticGeometry* definition = dynamic_cast<AnalyticGeometry*>(geometry->getGeometryDefinition(i));
if (definition == NULL)
continue;
flipOrder(*definition);
mNeedReload = true;
}
mpSimulator->flipVolumeOrder();
mNeedReload = true;
}

void GeometryEditWidget::updateUI()
Expand Down
3 changes: 2 additions & 1 deletion SpatialUI/spatialmainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ void SpatialMainWindow::loadFromDocument(SBMLDocument* toLoad)
return;
}


lstSpecies->clear();
ui->lstDose->clear();

Expand Down Expand Up @@ -573,6 +572,8 @@ void SpatialMainWindow::loadFromDocument(SBMLDocument* toLoad)



restart();
thread->mpSimulator->flipVolumeOrder();
restart();

ui->tblParameters->clear();
Expand Down

0 comments on commit 1b7b206

Please sign in to comment.