Skip to content

Commit

Permalink
Fix up persistence of publication tab notes. For #1697.
Browse files Browse the repository at this point in the history
  • Loading branch information
highperformancecoder committed Jan 12, 2024
1 parent 5e6a85b commit 8ad6c04
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
71 changes: 41 additions & 30 deletions schema/schema3.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
@copyright Steve Keen 2017
@author Russell Standish
This file is part of Minsky.
Expand Down Expand Up @@ -283,7 +283,7 @@ namespace schema3

struct MinskyImpl
{
IdMap itemMap; // for serialisation
IdMap itemMap, pubItemMap; // for serialisation
map<int, minsky::ItemPtr> reverseItemMap; // for deserialisation
};

Expand Down Expand Up @@ -414,37 +414,15 @@ namespace schema3
publicationTabs.emplace_back();
publicationTabs.back().name=i.name;
for (auto& j: i.items)
publicationTabs.back().items.emplace_back(itemMap[j.itemRef.get()], j);
{
// add locally added notes on publication tab to items list in schema
if (!itemMap.count(j.itemRef.get()))
itemMap.emplaceIf<minsky::Item>(publicationItems,j.itemRef.get());
publicationTabs.back().items.emplace_back(itemMap[j.itemRef.get()], j);
}
}
}

void Minsky::populatePublicationTabs(std::vector<minsky::PubTab>& pubTabs) const
{
assert(impl.get());
auto& itemMap=impl->reverseItemMap;

pubTabs.clear();
for (auto& pub: publicationTabs)
{
pubTabs.emplace_back(pub.name);
pubTabs.back().offsx=pub.x;
pubTabs.back().offsy=pub.y;
pubTabs.back().m_zoomFactor=pub.zoomFactor;

for (auto& item: pub.items)
if (itemMap[item.item])
{
pubTabs.back().items.emplace_back(itemMap[item.item]);
auto& newItem=pubTabs.back().items.back();
newItem.x=item.x;
newItem.y=item.y;
newItem.zoomFactor=item.zoomFactor;
newItem.rotation=item.rotation;
}
}
if (pubTabs.empty()) pubTabs.emplace_back("Publication");
}

void Minsky::populateMinsky(minsky::Minsky& m) const
{
minsky::LocalMinsky lm(m);
Expand Down Expand Up @@ -608,6 +586,39 @@ namespace schema3
LockGroupFactory(): shared_ptr<minsky::RavelLockGroup>(new minsky::RavelLockGroup) {}
};

void Minsky::populatePublicationTabs(std::vector<minsky::PubTab>& pubTabs) const
{
assert(impl.get());
auto& itemMap=impl->reverseItemMap;

// add in publication tab only items
MinskyItemFactory factory;
for (auto& i: publicationItems)
if (auto newItem=itemMap[i.id]=minsky::ItemPtr(factory.create(i.type)))
populateItem(*newItem,i);

pubTabs.clear();
for (auto& pub: publicationTabs)
{
pubTabs.emplace_back(pub.name);
pubTabs.back().offsx=pub.x;
pubTabs.back().offsy=pub.y;
pubTabs.back().m_zoomFactor=pub.zoomFactor;

for (auto& item: pub.items)
if (itemMap.count(item.item))
{
pubTabs.back().items.emplace_back(itemMap[item.item]);
auto& newItem=pubTabs.back().items.back();
newItem.x=item.x;
newItem.y=item.y;
newItem.zoomFactor=item.zoomFactor;
newItem.rotation=item.rotation;
}
}
if (pubTabs.empty()) pubTabs.emplace_back("Publication");
}

void Minsky::populateGroup(minsky::Group& g) const {
assert(impl.get());
auto& itemMap=impl->reverseItemMap;
Expand Down
2 changes: 1 addition & 1 deletion schema/schema3.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ namespace schema3
minsky::ConversionsMap conversions;
PhillipsDiagram phillipsDiagram;
std::vector<PublicationTab> publicationTabs;

std::vector<Item> publicationItems;

Minsky(): schemaVersion(0) {makeImpl();} // schemaVersion defined on read in
~Minsky();
Expand Down

0 comments on commit 8ad6c04

Please sign in to comment.