Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions model/godleyIcon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ namespace minsky
{
float h=0;
for (auto& v: vars)
{
RenderVariable rv(*v);
h+=2*rv.height();
{
h+=v->height();
if (h>height) height=h;
float w=2*rv.width();
float w=v->width();
if (w>width) width=w;
}
}
Expand Down Expand Up @@ -161,27 +160,26 @@ namespace minsky
else
editor->enableButtons();
}
}
}

double GodleyIcon::schema1ZoomFactor() const
{
if (auto g=group.lock())
return iconScale()*g->zoomFactor();
return scaleFactor()*g->zoomFactor();
else
return iconScale();
return scaleFactor();
}

void GodleyIcon::resize(const LassoBox& b)
{
float z=zoomFactor(), iw=this->iWidth(svgRenderer.width()), ih=this->iHeight(svgRenderer.height()), is=iconScale();
float minusLeftMargin=iw*z*is, minusBottomMargin=ih*z*is;
float invZ=1.0/this->zoomFactor();
auto bw=abs(b.x0-b.x1), bh=abs(b.y0-b.y1);
if (bw<=leftMargin() || bh<=bottomMargin()) return;
this->iWidth(iw*(bw-leftMargin())/(minusLeftMargin));
this->iHeight(ih*(bh-bottomMargin())/(minusBottomMargin));
scaleIconForHeight(bh);
update();
moveTo(0.5*(b.x0+b.x1), 0.5*(b.y0+b.y1));
this->iWidth(0.5*(bw-leftMargin())*invZ);
this->iHeight(0.5*(bh-bottomMargin())*invZ);
scaleIcon(bw,bh);
update();
updateBB();
}

Expand Down Expand Up @@ -267,25 +265,26 @@ namespace minsky
if (table.initialConditionRow(r))
for (size_t c=1; c<table.cols(); ++c)
{
string name=trimWS(table.cell(0,c));
string name=trimWS(table.cell(0,c));
auto vi=minsky().variableValues.find(VariableValue::valueId(group.lock(),name));
if (vi==minsky().variableValues.end()) continue;
VariableValue& v=*vi->second;
VariableValue& v=*vi->second;
v.godleyOverridden=false;
string::size_type start=table.cell(r,c).find_first_not_of(" ");
if (start!=string::npos)
{
FlowCoef fc(table.cell(r,c).substr(start));
v.init=fc.str();
FlowCoef fc(table.cell(r,c).substr(start));
v.init=fc.str();
v.godleyOverridden=true;
}
else
{
{
// populate cell with current variable's initial value
FlowCoef fc(v.init);
FlowCoef fc(v.init);
table.cell(r,c)=fc.str();
v.godleyOverridden=true;
}

}


Expand All @@ -297,7 +296,7 @@ namespace minsky
flowMargin=0;
accumulateWidthHeight(m_stockVars, stockH, stockMargin);
accumulateWidthHeight(m_flowVars, flowH, flowMargin);
float iw=this->iWidth(), ih=this->iHeight();
float iw=this->iWidth()*this->zoomFactor(), ih=this->iHeight()*this->zoomFactor();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm comparing with the sum of all v->width() or all v->height() with g->iWidth() or g->iHeight(). I added the zoomFactor in item::width() and item::height() for ticket 1204, so I need to multiply iWdith() and iHeight() by the zoomFactor here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a mistake, The fact that v->width() and height() now contain the zoomFactor causes problems, as shown in ticket 1221. I'm reverting it to RenderVariable width() and height() and removing the zoomFactors here.

this->iWidth(max(iw, 1.8f*stockH));
this->iHeight(max(ih, 1.8f*flowH));
}
Expand All @@ -309,7 +308,7 @@ namespace minsky
void GodleyIcon::positionVariables() const
{
// position of margin in absolute canvas coordinate
float z=iconScale()*this->zoomFactor();
float z=scaleFactor()*this->zoomFactor();
float vdf=variableDisplay? 1: -1; // variable display factor
float x= this->x() - 0.5*iWidth()*z+0.5*leftMargin();
float y= this->y() - 0.5*bottomMargin()-0.15*iHeight()*z;
Expand Down Expand Up @@ -346,7 +345,7 @@ namespace minsky
void GodleyIcon::draw(cairo_t* cairo) const
{

float z=zoomFactor()*iconScale();
float z=zoomFactor()*scaleFactor();
positionVariables();
double titley;

Expand Down Expand Up @@ -375,7 +374,7 @@ namespace minsky
CairoSave cs(cairo);
Pango pango(cairo);
pango.setMarkup("<b>"+latexToPango(table.title)+"</b>");
pango.setFontSize(12*zoomFactor());
pango.setFontSize(12*this->zoomFactor());
cairo_move_to(cairo,-0.5*(pango.width()-leftMargin()), titley);
pango.show();
}
Expand Down Expand Up @@ -452,8 +451,8 @@ namespace minsky
auto z=zoomFactor();
double w=iWidth()*z, h=iHeight()*z;
// check if (x,y) is within portradius of the 4 corners
if ((abs(x-Item::left()) < portRadiusMult*z || abs(x-Item::right()) < portRadiusMult*z) &&
(abs(y-Item::top()) < portRadiusMult*z || abs(y-Item::bottom()) < portRadiusMult*z))
if ((abs(x-left()) < portRadiusMult*z || abs(x-right()) < portRadiusMult*z) &&
(abs(y-top()) < portRadiusMult*z || abs(y-bottom()) < portRadiusMult*z))
return ClickType::onResize;
// Make it possible to pull wires from variables attached to Godley icons. For ticket 940
if (auto item=select(x,y))
Expand Down
13 changes: 4 additions & 9 deletions model/godleyIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ namespace minsky
{
/// for placement of bank icon within complex
float flowMargin=0, stockMargin=0;
/// icon scale is adjusted when Godley icon is resized
float m_iconScale=1;
CLASSDESC_ACCESS(GodleyIcon);
friend struct SchemaHelper;

Expand Down Expand Up @@ -78,17 +76,14 @@ namespace minsky
bool variableDisplay=true;
void toggleVariableDisplay() {variableDisplay=!variableDisplay;}

/// scale icon until it's height matches \a h
void scaleIconForHeight(float h) {update(); m_iconScale*=h/(bottomMargin()+iHeight()*iconScale()*zoomFactor());}
/// scale icon until it's height or width matches \a h or \a w depending on which is minimum
void scaleIcon(float w, float h) {update(); scaleFactor(scaleFactor()*min(w/(leftMargin()+iWidth()*scaleFactor()*zoomFactor()),h/(bottomMargin()+iHeight()*scaleFactor()*zoomFactor())));}

/// left margin of bank icon with Godley icon
float leftMargin() const {return variableDisplay? flowMargin*iconScale()*zoomFactor(): 0;}
float leftMargin() const {return variableDisplay? flowMargin*scaleFactor()*zoomFactor(): 0;}
/// bottom margin of bank icon with Godley icon
float bottomMargin() const {return variableDisplay? stockMargin*iconScale()*zoomFactor(): 0;}
float bottomMargin() const {return variableDisplay? stockMargin*scaleFactor()*zoomFactor(): 0;}

/// icon scale is adjusted when Godley icon is resized
float iconScale() const {return m_iconScale;}

/// helper for schema1
double schema1ZoomFactor() const;

Expand Down
4 changes: 2 additions & 2 deletions model/variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ float VariableBase::zoomFactor() const
if (ioVar())
if (auto g=group.lock())
return g->edgeScale();
// scale by GodleyIcon::iconScale if part of an Godley icon
// scale by GodleyIcon::scaleFactor if part of an Godley icon
if (auto g=dynamic_cast<GodleyIcon*>(controller.lock().get()))
return g->iconScale() * Item::zoomFactor();
return g->scaleFactor() * Item::zoomFactor();
return Item::zoomFactor();
}

Expand Down
12 changes: 1 addition & 11 deletions schema/schema3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,9 @@ namespace schema3
{
std::vector<std::vector<std::string>> data;
std::vector<minsky::GodleyAssetClass::AssetClass> assetClasses;
float iconScale=1;
if (y.data) data=*y.data;
if (y.assetClasses) assetClasses=*y.assetClasses;
if (y.iconScale) iconScale=*y.iconScale;
SchemaHelper::setPrivates(*x1,data,assetClasses,iconScale);
SchemaHelper::setPrivates(*x1,data,assetClasses);
try
{
x1->table.orderAssetClasses();
Expand Down Expand Up @@ -575,15 +573,7 @@ namespace schema3
SchemaHelper::setStockAndFlow(*godley, flowVars, stockVars);
try
{

godley->update();
if (!godley->editorMode())
{
if (i.height)
godley->scaleIconForHeight(*i.height*godley->zoomFactor());
else if (i.iconScale) //legacy schema handling
godley->scaleIconForHeight(*i.iconScale * godley->iHeight());
}
}
catch (...) {} //ignore exceptions: ticket #1045
}
Expand Down
7 changes: 3 additions & 4 deletions schema/schema3.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ namespace schema3
// Godley Icon specific fields
Optional<std::vector<std::vector<std::string>>> data;
Optional<std::vector<minsky::GodleyAssetClass::AssetClass>> assetClasses;
Optional<float> iconScale; // for handling legacy schemas
Optional<bool> editorMode, buttonDisplay, variableDisplay;
// Plot specific fields
Optional<bool> logx, logy, ypercent;
Expand Down Expand Up @@ -142,8 +141,8 @@ namespace schema3
axis(o.axis), arg(o.arg) {}
Item(int id, const minsky::GodleyIcon& g, const std::vector<int>& ports):
ItemBase(id,static_cast<const minsky::Item&>(g),ports),
width(g.iWidth()/g.zoomFactor()), height(g.iHeight()/g.zoomFactor()), name(g.table.title), data(g.table.getData()),
assetClasses(g.table._assetClass()), iconScale(g.iconScale()),
width(g.iWidth()), height(g.iHeight()), name(g.table.title), data(g.table.getData()),
assetClasses(g.table._assetClass()),
editorMode(g.editorMode()),
buttonDisplay(g.buttonDisplay()), variableDisplay(g.variableDisplay) {}
Item(int id, const minsky::PlotWidget& p, const std::vector<int>& ports):
Expand Down Expand Up @@ -175,7 +174,7 @@ namespace schema3
slider(it.slider), intVar(it.intVar), dataOpData(it.dataOpData), filename(it.filename),
ravelState(it.ravelState), lockGroup(it.lockGroup), dimensions(it.dimensions),
axis(it.axis), arg(it.arg), data(it.data), assetClasses(it.assetClasses),
iconScale(it.iconScale), logx(it.logx), logy(it.logy), ypercent(it.ypercent),
logx(it.logx), logy(it.logy), ypercent(it.ypercent),
plotType(minsky::PlotWidget::PlotType(it.plotType? int(*it.plotType): 0)),
xlabel(it.xlabel), ylabel(it.ylabel), y1label(it.y1label),
nxTicks(it.nxTicks), nyTicks(it.nyTicks), xtickAngle(it.xtickAngle),
Expand Down
5 changes: 2 additions & 3 deletions schema/schemaHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ namespace minsky
}
static void setPrivates
(minsky::GodleyIcon& g, const vector<vector<string> >& data,
const vector<GodleyTable::AssetClass>& assetClass,float iconScale)
const vector<GodleyTable::AssetClass>& assetClass)
{
setPrivates(g.table, data, assetClass);
g.m_iconScale=iconScale;
}
Comment on lines 74 to 79
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can now get rid if this helper function too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried this and it caused the variables attached to GodleyIcons to disappear. So, I've left it in.


static void setStockAndFlow(minsky::GodleyIcon& g,
const minsky::GodleyIcon::Variables& flowVars,
const minsky::GodleyIcon::Variables& stockVars)
Expand Down
2 changes: 1 addition & 1 deletion test/testModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ SUITE(GodleyIcon)
update();
// TODO - shouldn't be needed, but there is some font problem causing bottomMargin to be calculated incorrectly

scaleIconForHeight(2.5*bottomMargin());
scaleIcon(2.5*bottomMargin(),2.5*leftMargin());
update();
CHECK_EQUAL(1,flowVars().size());
CHECK_EQUAL(1,stockVars().size());
Expand Down