diff --git a/model/godleyIcon.cc b/model/godleyIcon.cc
index b86a5ea6f..b4c87d2d0 100644
--- a/model/godleyIcon.cc
+++ b/model/godleyIcon.cc
@@ -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;
}
}
@@ -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();
}
@@ -267,25 +265,26 @@ namespace minsky
if (table.initialConditionRow(r))
for (size_t c=1; c
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;
}
+
}
@@ -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();
this->iWidth(max(iw, 1.8f*stockH));
this->iHeight(max(ih, 1.8f*flowH));
}
@@ -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;
@@ -346,7 +345,7 @@ namespace minsky
void GodleyIcon::draw(cairo_t* cairo) const
{
- float z=zoomFactor()*iconScale();
+ float z=zoomFactor()*scaleFactor();
positionVariables();
double titley;
@@ -375,7 +374,7 @@ namespace minsky
CairoSave cs(cairo);
Pango pango(cairo);
pango.setMarkup(""+latexToPango(table.title)+"");
- pango.setFontSize(12*zoomFactor());
+ pango.setFontSize(12*this->zoomFactor());
cairo_move_to(cairo,-0.5*(pango.width()-leftMargin()), titley);
pango.show();
}
@@ -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))
diff --git a/model/godleyIcon.h b/model/godleyIcon.h
index daa0115c2..f190d40c8 100644
--- a/model/godleyIcon.h
+++ b/model/godleyIcon.h
@@ -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;
@@ -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;
diff --git a/model/variable.cc b/model/variable.cc
index 81bb32b07..e3b4a97da 100644
--- a/model/variable.cc
+++ b/model/variable.cc
@@ -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(controller.lock().get()))
- return g->iconScale() * Item::zoomFactor();
+ return g->scaleFactor() * Item::zoomFactor();
return Item::zoomFactor();
}
diff --git a/schema/schema3.cc b/schema/schema3.cc
index 40eafe998..9a83d21aa 100644
--- a/schema/schema3.cc
+++ b/schema/schema3.cc
@@ -431,11 +431,9 @@ namespace schema3
{
std::vector> data;
std::vector 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();
@@ -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
}
diff --git a/schema/schema3.h b/schema/schema3.h
index cbd29be4c..de2aecee8 100644
--- a/schema/schema3.h
+++ b/schema/schema3.h
@@ -109,7 +109,6 @@ namespace schema3
// Godley Icon specific fields
Optional>> data;
Optional> assetClasses;
- Optional iconScale; // for handling legacy schemas
Optional editorMode, buttonDisplay, variableDisplay;
// Plot specific fields
Optional logx, logy, ypercent;
@@ -142,8 +141,8 @@ namespace schema3
axis(o.axis), arg(o.arg) {}
Item(int id, const minsky::GodleyIcon& g, const std::vector& ports):
ItemBase(id,static_cast(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& ports):
@@ -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),
diff --git a/schema/schemaHelper.h b/schema/schemaHelper.h
index 4fa172839..79e340aae 100644
--- a/schema/schemaHelper.h
+++ b/schema/schemaHelper.h
@@ -73,12 +73,11 @@ namespace minsky
}
static void setPrivates
(minsky::GodleyIcon& g, const vector >& data,
- const vector& assetClass,float iconScale)
+ const vector& assetClass)
{
setPrivates(g.table, data, assetClass);
- g.m_iconScale=iconScale;
}
-
+
static void setStockAndFlow(minsky::GodleyIcon& g,
const minsky::GodleyIcon::Variables& flowVars,
const minsky::GodleyIcon::Variables& stockVars)
diff --git a/test/testModel.cc b/test/testModel.cc
index 53dbbeb73..bad7478eb 100644
--- a/test/testModel.cc
+++ b/test/testModel.cc
@@ -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());