Skip to content

Commit

Permalink
Added input/output variable attribute to global Minsky schema to supp…
Browse files Browse the repository at this point in the history
…ort saving groups as components. For #1681.
  • Loading branch information
highperformancecoder committed Jan 17, 2024
1 parent 2c48853 commit a39a4bc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
17 changes: 17 additions & 0 deletions schema/schema3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ namespace schema3

return false;
});

// add any I/O variables
vector<int> inVars, outVars;
for (auto& i: g.inVariables)
inVars.push_back(itemMap[i.get()]);
for (auto& i: g.outVariables)
outVars.push_back(itemMap[i.get()]);
inVariables=inVars;
outVariables=outVars;

// search for and link up integrals to their variables, and Godley table ports
g.recursiveDo(&minsky::GroupItems::items,[&](const minsky::Items&,minsky::Items::const_iterator i) {
Expand Down Expand Up @@ -630,6 +639,14 @@ namespace schema3
if (newItem->variableCast())
schema3VarMap[i.id]=i;
}

if (inVariables)
for (auto i: *inVariables)
g.inVariables.push_back(itemMap[i]);
if (outVariables)
for (auto i: *outVariables)
g.outVariables.push_back(itemMap[i]);

// second loop over items to wire up integrals, and populate Godley table variables
for (const auto& i: items)
{
Expand Down
1 change: 1 addition & 0 deletions schema/schema3.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ namespace schema3
std::string minskyVersion="unknown";
vector<Wire> wires;
vector<Item> items;
Optional<vector<int>> inVariables, outVariables;
vector<Group> groups;
vector<LockGroup> lockGroups;
minsky::Simulation rungeKutta;
Expand Down
23 changes: 21 additions & 2 deletions test/testModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ SUITE(GodleyIcon)
table.resize(3,2);
table.cell(2,1)="flow1";
table.cell(0,1)="stock1";
variableDisplay=true;
toggleVariableDisplay();
update();
// TODO - shouldn't be needed, but there is some font problem causing bottomMargin to be calculated incorrectly

Expand Down Expand Up @@ -1716,6 +1716,25 @@ SUITE(GodleyTableWindow)

}


TEST_FIXTURE(TestFixture, saveAsGroup)
{
group0->inVariables.push_back(a);
group0->makeSubroutine();
save("foo.mky");
CHECK(group0->inVariables.size());
CHECK(group0->outVariables.size());
saveGroupAsFile(*group0,"group0.mky");
insertGroupFromFile("group0.mky");
Group& newGroup=dynamic_cast<Group&>(*canvas.itemFocus);
// check I/O variables
CHECK_EQUAL(group0->inVariables.size(),newGroup.inVariables.size());
CHECK_EQUAL(group0->outVariables.size(),newGroup.outVariables.size());
for (int i=0; i<group0->inVariables.size(); ++i)
CHECK_EQUAL(group0->inVariables[i]->name(), newGroup.inVariables[i]->name());
for (int i=0; i<group0->outVariables.size(); ++i)
CHECK_EQUAL(group0->outVariables[i]->name(), newGroup.outVariables[i]->name());
// check items
CHECK_EQUAL(group0->items.size(), newGroup.items.size());
}

}

0 comments on commit a39a4bc

Please sign in to comment.