Skip to content

Commit

Permalink
Adapt to new SBMLNetwork layout/align functions.
Browse files Browse the repository at this point in the history
The functions now allow you to deal with alias nodes.  This is a first pass at that, that doesn't actually deal with alias nodes in the slightest, but at least continues to compile with the new version of the library.
  • Loading branch information
luciansmith committed Sep 24, 2024
1 parent f48bf90 commit 64cd944
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
libroadrunner_deps_owner: [ "sys-bio" ]
libroadrunner_deps_repo: [ "libroadrunner-deps" ]
libroadrunner_deps_name: [ "libroadrunner-deps" ]
libroadrunner_deps_release_version: [ "v2.2.6" ]
libroadrunner_deps_release_version: [ "v2.2.7" ]
python_version: [ "3.12" ]

runs-on: ${{ matrix.platform.os_name }}
Expand Down
30 changes: 16 additions & 14 deletions src/module-sbml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,7 @@ void Module::CreateSBMLModel(bool comp)

// Layout/Render!
if (m_autolayout.use) {
LIBSBMLNETWORK_CPP_NAMESPACE::autorender(&m_sbml);// , m_autolayout.maxNumConnectedEdges);
LIBSBMLNETWORK_CPP_NAMESPACE::autorender(&m_sbml, m_autolayout.maxNumConnectedEdges);
//For some reason, the following line is REQUIRED; otherwise I get linking errors(!) about how 'autolayout' is missing. WTF?? LS DEBUG
LIBSBMLNETWORK_CPP_NAMESPACE::getSBMLObject(&m_sbml, "S1");
if (m_layout.width != 0) {
Expand Down Expand Up @@ -2484,39 +2484,41 @@ void Module::CreateSBMLModel(bool comp)
assert(false);
}
}

LIBSBMLNETWORK_CPP_NAMESPACE::autolayout(&m_sbml, m_autolayout.maxNumConnectedEdges, m_autolayout.useNameAsTextLabel);

bool any_align = false;
if (m_layout.align_top.size()) {
LIBSBMLNETWORK_CPP_NAMESPACE::align(&m_sbml, m_layout.align_top, "top");
m_autolayout.lockedNodeIds.insert(m_layout.align_top.begin(), m_layout.align_top.end());
LIBSBMLNETWORK_CPP_NAMESPACE::align(&m_sbml, m_layout.align_top, "top", false);
any_align = true;
}
if (m_layout.align_left.size()) {
LIBSBMLNETWORK_CPP_NAMESPACE::align(&m_sbml, m_layout.align_left, "left");
m_autolayout.lockedNodeIds.insert(m_layout.align_left.begin(), m_layout.align_left.end());
any_align = true;
}
if (m_layout.align_hCenter.size()) {
LIBSBMLNETWORK_CPP_NAMESPACE::align(&m_sbml, m_layout.align_hCenter, "hCenter");
m_autolayout.lockedNodeIds.insert(m_layout.align_hCenter.begin(), m_layout.align_hCenter.end());
any_align = true;
}
if (m_layout.align_vCenter.size()) {
LIBSBMLNETWORK_CPP_NAMESPACE::align(&m_sbml, m_layout.align_vCenter, "vCenter");
m_autolayout.lockedNodeIds.insert(m_layout.align_vCenter.begin(), m_layout.align_vCenter.end());
any_align = true;
}
if (m_layout.align_right.size()) {
LIBSBMLNETWORK_CPP_NAMESPACE::align(&m_sbml, m_layout.align_right, "right");
m_autolayout.lockedNodeIds.insert(m_layout.align_right.begin(), m_layout.align_right.end());
any_align = true;
}
if (m_layout.align_bottom.size()) {
LIBSBMLNETWORK_CPP_NAMESPACE::align(&m_sbml, m_layout.align_bottom, "bottom");
m_autolayout.lockedNodeIds.insert(m_layout.align_bottom.begin(), m_layout.align_bottom.end());
any_align = true;
}
if (m_layout.align_circular.size()) {
LIBSBMLNETWORK_CPP_NAMESPACE::align(&m_sbml, m_layout.align_circular, "circular");
m_autolayout.lockedNodeIds.insert(m_layout.align_circular.begin(), m_layout.align_circular.end());
any_align = true;
}
if (any_align) {
LIBSBMLNETWORK_CPP_NAMESPACE::autolayout(&m_sbml, m_autolayout.maxNumConnectedEdges, m_autolayout.useNameAsTextLabel);
}
//double S1x = LIBSBMLNETWORK_CPP_NAMESPACE::getPositionX(&m_sbml, "S1");
LIBSBMLNETWORK_CPP_NAMESPACE::autolayout(&m_sbml, m_autolayout.maxNumConnectedEdges, m_autolayout.useNameAsTextLabel, true, m_autolayout.lockedNodeIds);
//S1x = LIBSBMLNETWORK_CPP_NAMESPACE::getPositionX(&m_sbml, "S1");
//S1x = S1x;

LIBSBMLNETWORK_CPP_NAMESPACE::freeUserData(&m_sbml);

}
Expand Down
47 changes: 26 additions & 21 deletions src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,9 +1192,9 @@ string Module::GetVariableNameDelimitedBy(string cc) const
return retval;
}

vector<string> getIntersection(set<string> set1, set<string> set2)
vector<pair<string, int> > getIntersection(set<pair<string, int> > set1, set<pair<string, int> > set2)
{
vector<string> overlap;
vector<pair<string, int> > overlap;
for (auto s1 = set1.begin(); s1 != set1.end(); s1++) {
if (set2.find(*s1) != set2.end()) {
overlap.push_back(*s1);
Expand All @@ -1203,9 +1203,9 @@ vector<string> getIntersection(set<string> set1, set<string> set2)
return overlap;
}

bool checkOverlapAndInsert(set<string>& fixed, set<string> check, string label)
bool checkOverlapAndInsert(set<pair<string, int> >& fixed, set <pair<string, int> > check, string label)
{
vector<string> intersection = getIntersection(fixed, check);
vector<pair<string, int> > intersection = getIntersection(fixed, check);
if (intersection.size() >= 2) {
string err = "Unable to set the alignment " + label + " because only one element is allowed in an alignment whose position is already known. In addition, adding an element to an alignment then establishes that element's position, so two such elements cannot be used in another alignment. In this case, the positions of elements ";
for (size_t i = 0; i < intersection.size(); i++) {
Expand All @@ -1216,7 +1216,7 @@ bool checkOverlapAndInsert(set<string>& fixed, set<string> check, string label)
err += "and ";
}
err += "'";
err += intersection[i];
err += intersection[i].first;
err += "'";
}
err += " are already known.";
Expand Down Expand Up @@ -1328,7 +1328,7 @@ bool Module::Finalize()
}

//Now check if the layout align lists are OK, i.e. don't have 2+ already-fixed nodes in them.
set<string> combo = m_autolayout.lockedNodeIds;
std::set <std::pair<std::string, int> > combo;
if (checkOverlapAndInsert(combo, m_layout.align_top, "align_top")) {
return true;
}
Expand Down Expand Up @@ -2949,11 +2949,6 @@ void Module::setUsedDistrib(bool useddistrib)
m_usedDistributions = useddistrib;
}

void Module::fixLayoutPositionOf(const std::string& id)
{
m_autolayout.lockedNodeIds.insert(id);
}

void Module::Convert(Variable* conv, Variable* cf, string modulename)
{
Module* origmod = g_registry.GetModule(m_modulename);
Expand Down Expand Up @@ -3267,7 +3262,6 @@ bool Module::SetAutoLayout(const std::string* argument, const std::vector<Variab
string id = (*values)[i]->GetNameDelimitedBy(g_registry.GetCC());
ids.insert(id);
}
m_autolayout.lockedNodeIds = ids;
ret = false;
}
delete values;
Expand Down Expand Up @@ -3456,10 +3450,10 @@ bool Module::SetLayout(const std::string* argument, const std::vector<Variable*>
return true;
}
else if (type == "idlist") {
set<string> ids;
set<pair<string, int> > ids;
for (size_t i = 0; i < values->size(); i++) {
string id = (*values)[i]->GetNameDelimitedBy(g_registry.GetCC());
ids.insert(id);
ids.insert(make_pair(id, 0));
//m_autolayout.lockedNodeIds.insert(id);
}
if (CaselessStrCmp(true, *argument, "align_top")) {
Expand Down Expand Up @@ -3668,15 +3662,26 @@ string Module::ValidateLayoutArgument(const string* argument)
return "none";
}

string getSetString(set<string> list)
string getSetString(set<pair<string, int> > list)
{
string ret = "{";
for (auto li = list.begin(); li != list.end(); li++) {
ret += " " + *li + ",";
stringstream ret;
ret << "{";
auto li = list.begin();
if (li != list.end()) {
ret << " " << li->first;
if (li->second != 0) {
ret << "." << li->second;
}
}
ret[ret.size() - 1] = ' ';
ret += "}";
return ret;
li++;
for (; li != list.end(); li++) {
ret << ", " << li->first;
if (li->second != 0) {
ret << "." << li->second;
}
}
ret << "}";
return ret.str();
}

string Module::GetAntimonyGeneralLayout(const string& indent) const
Expand Down
18 changes: 8 additions & 10 deletions src/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ struct autolayout {
//bool useBoundary = true;
bool useGrid = false;
bool useNameAsTextLabel = true;
std::set <std::string> lockedNodeIds = std::set<std::string>();
//std::set <std::string> lockedNodeIds = std::set<std::string>();
};

struct layout {
std::set <std::string> align_top = std::set<std::string>();
std::set <std::string> align_hCenter = std::set<std::string>();
std::set <std::string> align_bottom = std::set<std::string>();
std::set <std::string> align_left = std::set<std::string>();
std::set <std::string> align_vCenter = std::set<std::string>();
std::set <std::string> align_right = std::set<std::string>();
std::set <std::string> align_circular = std::set<std::string>();
std::set <std::pair<std::string, int> > align_top = std::set <std::pair<std::string, int> >();
std::set <std::pair<std::string, int> > align_hCenter = std::set <std::pair<std::string, int> >();
std::set <std::pair<std::string, int> > align_bottom = std::set <std::pair<std::string, int> >();
std::set <std::pair<std::string, int> > align_left = std::set <std::pair<std::string, int> >();
std::set <std::pair<std::string, int> > align_vCenter = std::set <std::pair<std::string, int> >();
std::set <std::pair<std::string, int> > align_right = std::set <std::pair<std::string, int> >();
std::set <std::pair<std::string, int> > align_circular = std::set <std::pair<std::string, int> >();
double height = 0.0;
double width = 0.0;
//double depth = 0.0;
Expand Down Expand Up @@ -250,8 +250,6 @@ class Module : public Annotated

void setUsedDistrib(bool useddistrib);

void fixLayoutPositionOf(const std::string& id);

#ifndef NCELLML
//Reading:
void LoadCellMLModel(iface::cellml_api::Model* model,
Expand Down

0 comments on commit 64cd944

Please sign in to comment.