Minsky: 3.17.0
minsky::GodleyIcon Class Reference

#include <godleyIcon.h>

Inheritance diagram for minsky::GodleyIcon:
Inheritance graph
Collaboration diagram for minsky::GodleyIcon:
Collaboration graph

Classes

struct  MoveCellArgs
 move the contents of cell at (srcRow, srcCol) to (destRow, destCol). More...
 

Public Types

typedef std::vector< VariablePtrVariables
 

Public Member Functions

 GodleyIcon ()
 
 GodleyIcon (const GodleyIcon &)=default
 
 ~GodleyIcon ()
 
bool editorMode () const override
 indicate whether icon is in editor mode or icon mode More...
 
void toggleEditorMode () override
 
bool buttonDisplay () const
 enable/disable drawing buttons in table on canvas display More...
 
void toggleButtons ()
 
bool variableDisplay () const
 
void toggleVariableDisplay ()
 
void adjustPopupWidgets ()
 
void scaleIcon (float w, float h)
 scale icon until it's height or width matches h or w depending on which is minimum More...
 
float leftMargin () const
 left margin of bank icon with Godley icon More...
 
float bottomMargin () const
 bottom margin of bank icon with Godley icon More...
 
void resize (const LassoBox &) override
 resize this item on the canvas More...
 
void removeControlledItems (GroupItems &) override
 
void setCell (int row, int col, const string &val)
 set cell(row,col) with contents val More...
 
void deleteRow (unsigned row)
 delete row before row More...
 
void moveCell (const GodleyIcon::MoveCellArgs &)
 
std::map< string, double > flowSignature (unsigned col) const
 flows, along with multipliers, appearing in col More...
 
const VariablesflowVars () const
 
const VariablesstockVars () const
 
std::vector< Summarysummarise () const
 summary of variables in this godley table More...
 
void update ()
 updates the variable lists with the Godley table More...
 
GodleyIconclone () const override
 
ItemPtr select (float x, float y) const override
 returns the variable if point (x,y) is within a variable icon, null otherwise, indicating that the Godley table has been selected. More...
 
ClickType::Type clickType (float x, float y) const override
 returns the clicktype given a mouse click at x, y. More...
 
void draw (cairo_t *cairo) const override
 draw icon to context More...
 
std::string rowSum (int row) const
 return the A-L-E row sum for row More...
 
std::string valueId (const std::string &x) const
 returns valueid for variable reference in table More...
 
Units stockVarUnits (const std::string &stockName, bool check) const
 performs dimensional analysis on stock var column stockName More...
 
void setCurrency (const std::string &currency)
 
void insertControlled (Selection &selection) override
 
void onMouseDown (float, float) override
 respond to mouse down events More...
 
void onMouseUp (float, float) override
 respond to mouse up events More...
 
bool onMouseMotion (float, float) override
 respond to mouse motion events with button pressed More...
 
bool onMouseOver (float, float) override
 respond to mouse motion events (hover) without button pressed More...
 
void onMouseLeave () override
 respond to mouse leave events (when mouse leaves item) More...
 
bool onKeyPress (int, const std::string &, int) override
 respond to key press events More...
 
bool inItem (float, float) const override
 
void destroyFrame () override
 clean up popup window structures on window close More...
 
bool wiresAttached () const
 return true if any wires are attached to the variables More...
 
const GodleyIcongodleyIconCast () const override
 
GodleyIcongodleyIconCast () override
 
- Public Member Functions inherited from minsky::ItemT< GodleyIcon >
std::string classType () const override
 
ItemTclone () const override
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) override
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) const override
 
void json_pack (classdesc::json_pack_t &j) const override
 
 ItemT ()=default
 
 ItemT (const ItemT &)=default
 
 ItemT (ItemT &&)=delete
 
ItemToperator= (const ItemT &)=default
 
ItemToperator= (ItemT &&)=delete
 
- Public Member Functions inherited from minsky::Item
 Item ()=default
 
virtual std::weak_ptr< Portports (std::size_t i) const
 callback to be run when item deleted from group More...
 
std::size_t portsSize () const
 number of ports More...
 
float portX (std::size_t i)
 
float portY (std::size_t i)
 
virtual bool contains (float xx, float yy) const
 
bool contains (const Point &p) const
 
void updateBoundingBox () override
 
void throw_error (const std::string &) const
 mark item on canvas, then throw More...
 
virtual bool ioVar () const
 indicates this is a group I/O variable More...
 
virtual double value () const
 current value of output port More...
 
double rotation () const
 
double rotation (const double &r)
 
std::pair< double, bool > rotationAsRadians () const
 return the rotation as radians, and whether rotation should have additional straight angle added for text that stays upright. More...
 
float iWidth () const
 
float iWidth (const float &w)
 
float iHeight () const
 
float iHeight (const float &h)
 
virtual void flip ()
 rotate icon though 180∘ More...
 
std::string id () const
 return an id uniquely identifying this item More...
 
virtual float x () const
 
virtual float y () const
 
virtual float zoomFactor () const
 
void ensureBBValid () const
 
float width () const
 
float height () const
 
virtual std::vector< Pointcorners () const
 
float left () const
 
float right () const
 
float top () const
 
float bottom () const
 
std::string bookmarkId () const
 Id of bookmark associated with this. More...
 
void adjustBookmark () const override
 adjust bookmark list to reflect current configuration More...
 
float resizeHandleSize () const
 resize handles should be at least a percentage if the icon size (#1025) More...
 
virtual bool onResizeHandle (float x, float y) const
 
virtual bool onItem (float x, float y) const
 returns true if (x,y) is on the icon More...
 
virtual void deleteAttachedWires ()
 delete all attached wires More...
 
virtual bool visible () const
 whether this item is visible on the canvas. More...
 
void moveTo (float x, float y)
 
virtual float scaleFactor () const
 factor by which item has been resized More...
 
virtual float scaleFactor (const float &sf)
 
void dummyDraw () const
 draw into a dummy cairo context, for purposes of calculating port positions More...
 
virtual void displayTooltip (cairo_t *, const std::string &) const
 display tooltip text, eg on mouseover More...
 
virtual void updateIcon (double t)
 update display after a step() More...
 
 Item (const Item &)=default
 
Itemoperator= (const Item &)=default
 
virtual ~Item ()
 
void drawPorts (cairo_t *cairo) const
 
virtual void drawResizeHandles (cairo_t *cairo) const
 
virtual std::shared_ptr< PortclosestOutPort (float x, float y) const
 returns closest output port to x,y More...
 
virtual std::shared_ptr< PortclosestInPort (float x, float y) const
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) override
 runs the RESTProcess descriptor suitable for this type More...
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) const override
 
virtual void displayDelayedTooltip (float x, float y)
 enable extended tooltip help message appropriate for mouse at (x,y) More...
 
virtual void disableDelayedTooltip ()
 
virtual Units units (bool check=false) const
 compute the dimensional units More...
 
Units checkUnits () const
 perform units consistency checks More...
 
ItemPtr itemPtrFromThis () const
 return a shared_ptr to this More...
 
- Public Member Functions inherited from minsky::NoteBase
virtual std::string const & detailedText () const
 
virtual std::string const & detailedText (const std::string &x)
 
virtual std::string const & tooltip () const
 
virtual std::string const & tooltip (const std::string &x)
 
virtual ~NoteBase ()=default
 

Public Attributes

GodleyTable table
 table data. Must be declared before editor More...
 
GodleyTableEditor editor {*this}
 rendering as a godley table More...
 
GodleyTableWindow popup {*this}
 for rendering the popup window More...
 
std::string currency
 
- Public Attributes inherited from minsky::Item
float m_x =0
 
float m_y =0
 position in canvas, or within group More...
 
float m_sf =1
 scale factor of item on canvas, or within group More...
 
bool onResizeHandles =false
 set to true to indicate mouse is ovcaler resize handles More...
 
bool onBorder =false
 true to indicate mouse hovering over border More...
 
std::string deleteCallback
 
BoundingBox bb
 canvas bounding box. More...
 
- Public Attributes inherited from minsky::NoteBase
bool mouseFocus =false
 true if target of a mouseover More...
 
bool selected =false
 true if selected for cut, copy or group operation More...
 
bool bookmark =false
 Is this item also a bookmark? More...
 

Static Public Attributes

static SVGRenderer svgRenderer
 SVG icon to display when not in editor mode. More...
 

Private Member Functions

 CLASSDESC_ACCESS (GodleyIcon)
 
void updateBB ()
 
double titleOffs () const
 
void updateVars (Variables &vars, const vector< string > &varNames, VariableBase::Type varType)
 
void positionVariables () const
 move contained variables to correct locations within icon More...
 
float toEditorX (float) const
 convert mouse coordinates into editor coords More...
 
float toEditorY (float) const
 convert mouse coordinates into editor coords More...
 

Private Attributes

float flowMargin =0
 for placement of bank icon within complex More...
 
float stockMargin =0
 
bool m_editorMode =false
 
bool m_variableDisplay =false
 
Variables m_flowVars
 
Variables m_stockVars
 

Friends

struct SchemaHelper
 

Additional Inherited Members

- Static Public Member Functions inherited from minsky::Item
static void drawSelected (cairo_t *cairo)
 
- Static Protected Member Functions inherited from minsky::Item
static void drawResizeHandle (cairo_t *cairo, double x, double y, double sf, double angle)
 
- Protected Attributes inherited from minsky::Item
double m_width =20
 
double m_height =20
 
ItemPortVector m_ports
 
minsky::Item::MemoisedRotator memoisedRotator
 

Detailed Description

Definition at line 41 of file godleyIcon.h.

Member Typedef Documentation

◆ Variables

Definition at line 111 of file godleyIcon.h.

Constructor & Destructor Documentation

◆ GodleyIcon() [1/2]

minsky::GodleyIcon::GodleyIcon ( )
inline

Definition at line 64 of file godleyIcon.h.

References minsky::GodleyTableEditor::adjustWidgets(), minsky::GodleyTableEditor::disableButtons(), editor, minsky::Item::iHeight(), and minsky::Item::iWidth().

Referenced by clone().

void adjustWidgets()
ensure button widgets are synced with current table data
float iHeight() const
Definition: item.h:221
float iWidth() const
Definition: item.h:214
GodleyTableEditor editor
rendering as a godley table
Definition: godleyIcon.h:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GodleyIcon() [2/2]

minsky::GodleyIcon::GodleyIcon ( const GodleyIcon )
default

◆ ~GodleyIcon()

minsky::GodleyIcon::~GodleyIcon ( )
inline

Definition at line 66 of file godleyIcon.h.

66 {Item::removeControlledItems();}

Member Function Documentation

◆ adjustPopupWidgets()

void minsky::GodleyIcon::adjustPopupWidgets ( )
inline

Definition at line 85 of file godleyIcon.h.

References minsky::GodleyTableEditor::adjustWidgets(), and popup.

void adjustWidgets()
ensure button widgets are synced with current table data
GodleyTableWindow popup
for rendering the popup window
Definition: godleyIcon.h:84
Here is the call graph for this function:

◆ bottomMargin()

float minsky::GodleyIcon::bottomMargin ( ) const
inline

bottom margin of bank icon with Godley icon

Definition at line 93 of file godleyIcon.h.

References minsky::Item::scaleFactor(), stockMargin, variableDisplay(), and minsky::Item::zoomFactor().

virtual float zoomFactor() const
Definition: item.cc:121
bool variableDisplay() const
Definition: godleyIcon.h:76
virtual float scaleFactor() const
factor by which item has been resized
Definition: item.cc:128
Here is the call graph for this function:

◆ buttonDisplay()

bool minsky::GodleyIcon::buttonDisplay ( ) const

enable/disable drawing buttons in table on canvas display

Definition at line 162 of file godleyIcon.cc.

162 {return m_editorMode && editor.drawButtons;}
bool drawButtons
whether to draw row/column buttons
GodleyTableEditor editor
rendering as a godley table
Definition: godleyIcon.h:82

◆ CLASSDESC_ACCESS()

minsky::GodleyIcon::CLASSDESC_ACCESS ( GodleyIcon  )
private

◆ clickType()

ClickType::Type minsky::GodleyIcon::clickType ( float  x,
float  y 
) const
overridevirtual

returns the clicktype given a mouse click at x, y.

Reimplemented from minsky::Item.

Definition at line 589 of file godleyIcon.cc.

590  {
591  if (m_editorMode) return Item::clickType(x,y);
592  const double dx=fabs(x-this->x()), dy=fabs(y-this->y());
593  auto z=zoomFactor()*scaleFactor();
594  const double w=0.5*iWidth()*z, h=0.5*iHeight()*z;
595  if (onResizeHandle(x,y)) return ClickType::onResize;
596  // Make it possible to pull wires from variables attached to Godley icons. For ticket 940
597  if (auto item=select(x,y))
598  return item->clickType(x,y);
599  if (dx < w && dy < h)
600  return ClickType::onItem;
601  return ClickType::outside;
602  }
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float iHeight() const
Definition: item.h:221
virtual float zoomFactor() const
Definition: item.cc:121
virtual bool onResizeHandle(float x, float y) const
Definition: item.cc:228
virtual ClickType::Type clickType(float x, float y) const
returns the clicktype given a mouse click at x, y.
Definition: item.cc:275
float iWidth() const
Definition: item.h:214
virtual float scaleFactor() const
factor by which item has been resized
Definition: item.cc:128
ItemPtr select(float x, float y) const override
returns the variable if point (x,y) is within a variable icon, null otherwise, indicating that the Go...
Definition: godleyIcon.cc:415

◆ clone()

GodleyIcon* minsky::GodleyIcon::clone ( ) const
inlineoverridevirtual

Reimplemented from minsky::Item.

Definition at line 121 of file godleyIcon.h.

References GodleyIcon().

121  {
122  auto r=new GodleyIcon(*this);
123  r->update();
124  r->group.reset();
125  return r;
126  }
Here is the call graph for this function:

◆ deleteRow()

void minsky::GodleyIcon::deleteRow ( unsigned  row)

delete row before row

Definition at line 226 of file godleyIcon.cc.

References minsky::Minsky::balanceDuplicateColumns(), and pyminsky::minsky.

227  {
228  if (row>0 && row<=table.rows())
229  {
230  table.deleteRow(row-1);
231  // if shared column data is deleted, remove it from the other tables too
232  for (size_t col=1; col<table.cols(); ++col)
233  minsky().balanceDuplicateColumns(*this, col);
234  table.markEdited();
235  }
236  }
std::size_t cols() const
Definition: godleyTable.h:105
void balanceDuplicateColumns(const GodleyIcon &srcTable, int srcCol)
makes all duplicated columns consistent with srcTable, srcCol
Definition: minsky.cc:752
void deleteRow(unsigned row)
delete row at row
Definition: godleyTable.h:121
std::size_t rows() const
Definition: godleyTable.h:104
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
static void markEdited()
mark model as having changed
Definition: godleyTable.cc:32
Minsky & minsky()
global minsky object
Definition: addon.cc:545
Here is the call graph for this function:

◆ destroyFrame()

void minsky::GodleyIcon::destroyFrame ( )
inlineoverridevirtual

clean up popup window structures on window close

Reimplemented from minsky::Item.

Definition at line 162 of file godleyIcon.h.

References minsky::RenderNativeWindow::destroyFrame(), and popup.

162 {popup.destroyFrame();}
GodleyTableWindow popup
for rendering the popup window
Definition: godleyIcon.h:84
Here is the call graph for this function:

◆ draw()

void minsky::GodleyIcon::draw ( cairo_t *  cairo) const
overridevirtual

draw icon to context

Reimplemented from minsky::Item.

Definition at line 442 of file godleyIcon.cc.

References border, and minsky::latexToPango().

443  {
445  const float z=zoomFactor()*scaleFactor();
446  float w=iWidth()*z+leftMargin(), h=iHeight()*z+bottomMargin(), left=-0.5*w, top=-0.5*h;
447  double titley;
448 
449  if (m_editorMode)
450  {
451  const CairoSave cs(cairo);
452  cairo_rectangle(cairo, left, top, w, h);
453  cairo_rectangle(cairo, left-border*z, top-border*z, w+2*border*z, h+2*border*z);
454  cairo_stroke_preserve(cairo);
455  if (onBorder)
456  { // shadow the border when mouse is over it
457  const cairo::CairoSave cs(cairo);
458  cairo_set_source_rgba(cairo,0.5,0.5,0.5,0.5);
459  cairo_set_fill_rule(cairo,CAIRO_FILL_RULE_EVEN_ODD);
460  cairo_fill(cairo);
461  }
462  cairo_new_path(cairo);
463  cairo_rectangle(cairo, left, top, w, h);
464  cairo_clip(cairo);
465  cairo_translate(cairo,left+border*z+leftMargin(),top+border*z+titleOffs()/* space for title*/);
466  // render to a recording surface to determine size of editor table
467  // TODO - maybe move this stuff into update()
468  const Surface surf(cairo_recording_surface_create(CAIRO_CONTENT_COLOR, nullptr));
469  const_cast<GodleyTableEditor&>(editor).zoomFactor=1;
470  const_cast<GodleyTableEditor&>(editor).draw(surf.cairo());
471  const_cast<GodleyTableEditor&>(editor).zoomFactor=min((w-leftMargin()-2*border*z)/surf.width(),(h-bottomMargin()-2*border*z-titleOffs())/surf.height());
472  const_cast<GodleyTableEditor&>(editor).draw(cairo);
473  titley=-0.5*h;
474  w+=2*border*z;
475  h+=2*border*z;
476  left-=border*z;
477  top-=border*z;
478  }
479  else
480  {
481  const CairoSave cs(cairo);
482  cairo_translate(cairo,left+leftMargin(),top);
483  svgRenderer.render(cairo, w-leftMargin(), h-bottomMargin());
484  titley=top+0.1*(h-bottomMargin());
485  }
486 
487  if (!table.title.empty())
488  {
489  const CairoSave cs(cairo);
490  Pango pango(cairo);
491  pango.setMarkup("<b>"+latexToPango(table.title)+"</b>");
492  pango.setFontSize(titleOffs());
493  cairo_move_to(cairo,-0.5*(pango.width()-leftMargin()), titley);
494  pango.show();
495  }
496 
497 
498 
500  {
501  // render the variables
502  const DrawVars drawVars(cairo,x(),y());
503  drawVars(m_flowVars);
504  drawVars(m_stockVars);
505  }
506 
507  if (mouseFocus)
508  {
509  drawPorts(cairo);
510  displayTooltip(cairo,tooltip());
511  drawResizeHandles(cairo);
512  }
513 
514  cairo_rectangle(cairo, left,top, w, h);
515  cairo_clip(cairo);
516  if (selected)
517  {
518  drawSelected(cairo);
519  }
520  }
std::string latexToPango(const char *s)
Definition: latexMarkup.h:30
void drawPorts(cairo_t *cairo) const
Definition: item.cc:294
bool wiresAttached() const
return true if any wires are attached to the variables
Definition: godleyIcon.cc:429
double titleOffs() const
Definition: godleyIcon.h:59
virtual void displayTooltip(cairo_t *, const std::string &) const
display tooltip text, eg on mouseover
Definition: item.cc:398
Variables m_flowVars
Definition: godleyIcon.h:176
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float top() const
Definition: item.cc:177
float iHeight() const
Definition: item.h:221
void positionVariables() const
move contained variables to correct locations within icon
Definition: godleyIcon.cc:390
virtual std::string const & tooltip() const
Definition: noteBase.h:36
virtual float zoomFactor() const
Definition: item.cc:121
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
float leftMargin() const
left margin of bank icon with Godley icon
Definition: godleyIcon.h:91
static SVGRenderer svgRenderer
SVG icon to display when not in editor mode.
Definition: godleyIcon.h:62
float left() const
Definition: item.cc:163
static void drawSelected(cairo_t *cairo)
Definition: item.cc:308
float iWidth() const
Definition: item.h:214
bool onBorder
true to indicate mouse hovering over border
Definition: item.h:173
Variables m_stockVars
Definition: godleyIcon.h:176
virtual void drawResizeHandles(cairo_t *cairo) const
Definition: item.cc:343
const float border
Definition: godleyIcon.cc:41
bool selected
true if selected for cut, copy or group operation
Definition: noteBase.h:32
virtual float scaleFactor() const
factor by which item has been resized
Definition: item.cc:128
std::string title
Definition: godleyTable.h:58
void draw(cairo_t *cairo) const override
draw icon to context
Definition: godleyIcon.cc:442
bool mouseFocus
true if target of a mouseover
Definition: noteBase.h:31
GodleyTableEditor editor
rendering as a godley table
Definition: godleyIcon.h:82
float bottomMargin() const
bottom margin of bank icon with Godley icon
Definition: godleyIcon.h:93
void render(cairo_t *, double width, double height) const
render SVG into region of size width height
Definition: SVGItem.cc:84
Here is the call graph for this function:

◆ editorMode()

bool minsky::GodleyIcon::editorMode ( ) const
inlineoverridevirtual

indicate whether icon is in editor mode or icon mode

Reimplemented from minsky::Item.

Definition at line 69 of file godleyIcon.h.

References m_editorMode.

69 {return m_editorMode;}

◆ flowSignature()

map< string, double > minsky::GodleyIcon::flowSignature ( unsigned  col) const

flows, along with multipliers, appearing in col

Definition at line 259 of file godleyIcon.cc.

Referenced by minsky::Minsky::balanceColumns().

260  {
261  map<string,double> r;
262  for (size_t row=1; row<table.rows() && col<table.cols(); ++row)
263  if (!table.initialConditionRow(row))
264  {
265  const FlowCoef fc(table.cell(row,col));
266  if (!fc.name.empty())
267  r[fc.name]+=fc.coef;
268  }
269  return r;
270  }
std::size_t cols() const
Definition: godleyTable.h:105
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
Definition: godleyTable.cc:37
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::size_t rows() const
Definition: godleyTable.h:104
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
Here is the caller graph for this function:

◆ flowVars()

const Variables& minsky::GodleyIcon::flowVars ( ) const
inline

Definition at line 112 of file godleyIcon.h.

References m_flowVars.

112 {return m_flowVars;}
Variables m_flowVars
Definition: godleyIcon.h:176

◆ godleyIconCast() [1/2]

const GodleyIcon* minsky::GodleyIcon::godleyIconCast ( ) const
inlineoverride

Definition at line 167 of file godleyIcon.h.

167 {return this;}

◆ godleyIconCast() [2/2]

GodleyIcon* minsky::GodleyIcon::godleyIconCast ( )
inlineoverride

Definition at line 168 of file godleyIcon.h.

168 {return this;}

◆ inItem()

bool minsky::GodleyIcon::inItem ( float  x,
float  y 
) const
overridevirtual
Returns
true if item internally responds to the mouse, and (x,y) is within editable area

Reimplemented from minsky::Item.

Definition at line 90 of file godleyIcon.cc.

References border.

91  {
92  return abs(xx-x())<0.5*width()-border && abs(yy-y())<0.5*height()-border;
93  }
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float width() const
Definition: item.h:239
const float border
Definition: godleyIcon.cc:41
float height() const
Definition: item.h:240

◆ insertControlled()

void minsky::GodleyIcon::insertControlled ( Selection selection)
override

Definition at line 581 of file godleyIcon.cc.

References minsky::Selection::ensureItemInserted().

582  {
583  for (const auto& i: flowVars())
584  selection.ensureItemInserted(i);
585  for (const auto& i: stockVars())
586  selection.ensureItemInserted(i);
587  }
const Variables & flowVars() const
Definition: godleyIcon.h:112
const Variables & stockVars() const
Definition: godleyIcon.h:113
Here is the call graph for this function:

◆ leftMargin()

float minsky::GodleyIcon::leftMargin ( ) const
inline

left margin of bank icon with Godley icon

Definition at line 91 of file godleyIcon.h.

References flowMargin, minsky::Item::scaleFactor(), variableDisplay(), and minsky::Item::zoomFactor().

float flowMargin
for placement of bank icon within complex
Definition: godleyIcon.h:45
virtual float zoomFactor() const
Definition: item.cc:121
bool variableDisplay() const
Definition: godleyIcon.h:76
virtual float scaleFactor() const
factor by which item has been resized
Definition: item.cc:128
Here is the call graph for this function:

◆ moveCell()

void minsky::GodleyIcon::moveCell ( const GodleyIcon::MoveCellArgs args)

Definition at line 239 of file godleyIcon.cc.

References minsky::GodleyIcon::MoveCellArgs::destCol, minsky::GodleyIcon::MoveCellArgs::destRow, minsky::GodleyIcon::MoveCellArgs::srcCol, and minsky::GodleyIcon::MoveCellArgs::srcRow.

240  {
241  if (!table.cellInTable(args.srcRow, args.srcCol) || !table.cellInTable(args.destRow, args.destCol)) return;
242  if (args.srcCol!=args.destCol) // if moving between columns, we can delete and
243  // add, which ensures any linked columns are
244  // correctly updated
245  {
246  // create a copy here, as setCell may resize the array, changing
247  // what the reference referred to.
248  const string oldVal=table.cell(args.srcRow, args.srcCol);
249  setCell(args.destRow, args.destCol, oldVal);
250  setCell(args.srcRow, args.srcCol, "");
251  }
252  else // within a column, just move the data without affecting any linked column
253  {
254  table.cell(args.destRow, args.destCol)=table.cell(args.srcRow, args.srcCol);
255  table.cell(args.srcRow, args.srcCol)="";
256  }
257  }
bool cellInTable(int row, int col) const
Definition: godleyTable.h:145
void setCell(int row, int col, const string &val)
set cell(row,col) with contents val
Definition: godleyIcon.cc:210
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80

◆ onKeyPress()

bool minsky::GodleyIcon::onKeyPress ( int  keySym,
const std::string &  utf8,
int  state 
)
overridevirtual

respond to key press events

Returns
true if it needs to be rerendered

Reimplemented from minsky::Item.

Definition at line 639 of file godleyIcon.cc.

640  {
641  if (m_editorMode) editor.keyPress(keySym, utf8);
642  return m_editorMode;
643  }
void keyPress(int keySym, const std::string &utf8)
GodleyTableEditor editor
rendering as a godley table
Definition: godleyIcon.h:82

◆ onMouseDown()

void minsky::GodleyIcon::onMouseDown ( float  x,
float  y 
)
overridevirtual

respond to mouse down events

Reimplemented from minsky::Item.

Definition at line 609 of file godleyIcon.cc.

virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float toEditorY(float) const
convert mouse coordinates into editor coords
Definition: godleyIcon.cc:606
float toEditorX(float) const
convert mouse coordinates into editor coords
Definition: godleyIcon.cc:604
GodleyTableEditor editor
rendering as a godley table
Definition: godleyIcon.h:82
void mouseDown(double x, double y)
event handling

◆ onMouseLeave()

void minsky::GodleyIcon::onMouseLeave ( )
overridevirtual

respond to mouse leave events (when mouse leaves item)

Reimplemented from minsky::Item.

Definition at line 627 of file godleyIcon.cc.

628  {
629  if (m_editorMode)
630  {
631  editor.mouseMove(-1,-1);
632  // May be a bit overzealous, but it solves bug 1273, which is caused by a flow which has not yet fully come into existence....
633  editor.selectedCol=-1;
634  editor.selectedRow=-1;
635  editor.update();
636  }
637  }
void update()
update canvas godleyIcon, and any related godley icons. Can throw
void mouseMove(double x, double y)
int selectedRow
which cell is active, none initially
GodleyTableEditor editor
rendering as a godley table
Definition: godleyIcon.h:82

◆ onMouseMotion()

bool minsky::GodleyIcon::onMouseMotion ( float  x,
float  y 
)
overridevirtual

respond to mouse motion events with button pressed

Returns
true if it needs to be rerendered

Reimplemented from minsky::Item.

Definition at line 615 of file godleyIcon.cc.

616  {
618  return false;
619  }
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float toEditorY(float) const
convert mouse coordinates into editor coords
Definition: godleyIcon.cc:606
void mouseMoveB1(double x, double y)
mouse motion with button 1 pressed
float toEditorX(float) const
convert mouse coordinates into editor coords
Definition: godleyIcon.cc:604
GodleyTableEditor editor
rendering as a godley table
Definition: godleyIcon.h:82

◆ onMouseOver()

bool minsky::GodleyIcon::onMouseOver ( float  x,
float  y 
)
overridevirtual

respond to mouse motion events (hover) without button pressed

Returns
true if it needs to be rerendered

Reimplemented from minsky::Item.

Definition at line 621 of file godleyIcon.cc.

622  {
624  return false;
625  }
virtual float x() const
Definition: item.cc:107
void mouseMove(double x, double y)
virtual float y() const
Definition: item.cc:114
float toEditorY(float) const
convert mouse coordinates into editor coords
Definition: godleyIcon.cc:606
float toEditorX(float) const
convert mouse coordinates into editor coords
Definition: godleyIcon.cc:604
GodleyTableEditor editor
rendering as a godley table
Definition: godleyIcon.h:82

◆ onMouseUp()

void minsky::GodleyIcon::onMouseUp ( float  x,
float  y 
)
overridevirtual

respond to mouse up events

Reimplemented from minsky::Item.

Definition at line 612 of file godleyIcon.cc.

virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float toEditorY(float) const
convert mouse coordinates into editor coords
Definition: godleyIcon.cc:606
float toEditorX(float) const
convert mouse coordinates into editor coords
Definition: godleyIcon.cc:604
void mouseUp(double x, double y)
GodleyTableEditor editor
rendering as a godley table
Definition: godleyIcon.h:82

◆ positionVariables()

void minsky::GodleyIcon::positionVariables ( ) const
private

move contained variables to correct locations within icon

Definition at line 390 of file godleyIcon.cc.

391  {
392  // position of margin in absolute canvas coordinate
393  const float z=this->zoomFactor()*scaleFactor();
394  float x= this->x() - 0.5*iWidth()*z+0.5*leftMargin();
395  float y= this->y() - 0.5*bottomMargin()-0.15*iHeight()*z;
396  for (const auto& v: m_flowVars)
397  {
398  // right justification if displayed, left otherwisw
399  v->rotation(0);
400  v->moveTo(x+v->x() - (m_variableDisplay? v->right(): v->left()), y);
401  y+=v->height();
402  }
403  x= this->x() + 0.55*leftMargin()-0.45*iWidth()*z;
404  y= this->y() + 0.5*iHeight()*z-0.5*bottomMargin();
405 
406  for (const auto& v: m_stockVars)
407  {
408  // top justification at bottom of icon if displayed, bottom justified otherwise
409  v->rotation(90);
410  v->moveTo(x, y + v->y() - (m_variableDisplay? v->top(): v->bottom()));
411  x+=v->width();
412  }
413  }
Variables m_flowVars
Definition: godleyIcon.h:176
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float iHeight() const
Definition: item.h:221
virtual float zoomFactor() const
Definition: item.cc:121
float leftMargin() const
left margin of bank icon with Godley icon
Definition: godleyIcon.h:91
float iWidth() const
Definition: item.h:214
Variables m_stockVars
Definition: godleyIcon.h:176
virtual float scaleFactor() const
factor by which item has been resized
Definition: item.cc:128
float bottomMargin() const
bottom margin of bank icon with Godley icon
Definition: godleyIcon.h:93

◆ removeControlledItems()

void minsky::GodleyIcon::removeControlledItems ( GroupItems g)
override

Definition at line 190 of file godleyIcon.cc.

References minsky::GroupItems::removeItem().

191  {
192  for (auto& i: m_flowVars)
193  {
194  assert(i);
195  i->deleteAttachedWires();
196  auto item=g.removeItem(*i);
197  assert(item.use_count()!=1);
198  }
199  m_flowVars.clear();
200  for (auto& i: m_stockVars)
201  {
202  assert(i);
203  i->deleteAttachedWires();
204  auto item=g.removeItem(*i);
205  assert(item.use_count()!=1);
206  }
207  m_stockVars.clear();
208  }
Variables m_flowVars
Definition: godleyIcon.h:176
Variables m_stockVars
Definition: godleyIcon.h:176
Here is the call graph for this function:

◆ resize()

void minsky::GodleyIcon::resize ( const LassoBox b)
overridevirtual

resize this item on the canvas

Reimplemented from minsky::Item.

Definition at line 178 of file godleyIcon.cc.

References minsky::LassoBox::x0, minsky::LassoBox::x1, minsky::LassoBox::y0, and minsky::LassoBox::y1.

179  {
180  const float invZ=1.0/(this->zoomFactor());
181  auto bw=abs(b.x0-b.x1), bh=abs(b.y0-b.y1);
182  if (bw<=leftMargin() || bh<=bottomMargin()) return;
183  moveTo(0.5*(b.x0+b.x1), 0.5*(b.y0+b.y1));
184  iWidth((bw-leftMargin())*invZ);
185  iHeight((bh-bottomMargin())*invZ);
186  scaleIcon(bw,bh);
188  }
void scaleIcon(float w, float h)
scale icon until it&#39;s height or width matches h or w depending on which is minimum ...
Definition: godleyIcon.cc:172
float iHeight() const
Definition: item.h:221
virtual float zoomFactor() const
Definition: item.cc:121
float leftMargin() const
left margin of bank icon with Godley icon
Definition: godleyIcon.h:91
float iWidth() const
Definition: item.h:214
void moveTo(float x, float y)
Definition: item.cc:256
void updateBoundingBox() override
Definition: item.h:198
float bottomMargin() const
bottom margin of bank icon with Godley icon
Definition: godleyIcon.h:93

◆ rowSum()

string minsky::GodleyIcon::rowSum ( int  row) const

return the A-L-E row sum for row

Definition at line 522 of file godleyIcon.cc.

References minsky::group, minsky::str(), minsky::trimWS(), and minsky::valueId().

523  {
524  if (row==0) // A-L-E sum values across stockvars
525  {
526  map<string,VariablePtr> stockVars;
527  for (const auto& i: m_stockVars)
528  stockVars[i->valueId()]=i;
529  double sum=0, absSum=0;
530  for (size_t c=1; c<table.cols(); ++c)
531  {
532  auto i=stockVars.find(minsky::valueId(group.lock(), trimWS(table.cell(0,c))));
533  if (i!=stockVars.end())
534  {
535  sum+=(table.signConventionReversed(c)? -1: 1)*i->second->value();
536  absSum+=abs(i->second->value());
537  }
538  }
539  if (sum<1E-4*absSum) sum=0; // eschew excess precision. For #1328
540  return str(sum);
541  }
542  return table.rowSum(row);
543  }
std::size_t cols() const
Definition: godleyTable.h:105
std::string rowSum(int row) const
return the symbolic sum across a row
Definition: godleyTable.h:179
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::string trimWS(const std::string &s)
Definition: str.h:49
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
Variables m_stockVars
Definition: godleyIcon.h:176
const Variables & stockVars() const
Definition: godleyIcon.h:113
bool signConventionReversed(int col) const
The usual mathematical sign convention is reversed in double entry book keeping conventions if the as...
Definition: godleyTable.h:92
Here is the call graph for this function:

◆ scaleIcon()

void minsky::GodleyIcon::scaleIcon ( float  w,
float  h 
)

scale icon until it's height or width matches h or w depending on which is minimum

Definition at line 172 of file godleyIcon.cc.

173  {
174  update();
176  }
float iHeight() const
Definition: item.h:221
virtual float zoomFactor() const
Definition: item.cc:121
float leftMargin() const
left margin of bank icon with Godley icon
Definition: godleyIcon.h:91
float iWidth() const
Definition: item.h:214
void update()
updates the variable lists with the Godley table
Definition: godleyIcon.cc:290
virtual float scaleFactor() const
factor by which item has been resized
Definition: item.cc:128
float bottomMargin() const
bottom margin of bank icon with Godley icon
Definition: godleyIcon.h:93

◆ select()

ItemPtr minsky::GodleyIcon::select ( float  x,
float  y 
) const
overridevirtual

returns the variable if point (x,y) is within a variable icon, null otherwise, indicating that the Godley table has been selected.

Reimplemented from minsky::Item.

Definition at line 415 of file godleyIcon.cc.

416  {
417  if (m_variableDisplay) // Disable selection of stock and flow vars when they are hidden. for tickets 1217 and 1220.
418  {
419  for (const auto& v: m_flowVars)
420  if (v->contains(x,y))
421  return v;
422  for (const auto& v: m_stockVars)
423  if (v->contains(x,y))
424  return v;
425  }
426  return ItemPtr();
427  }
Variables m_flowVars
Definition: godleyIcon.h:176
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
std::shared_ptr< Item > ItemPtr
Definition: item.h:55
Variables m_stockVars
Definition: godleyIcon.h:176

◆ setCell()

void minsky::GodleyIcon::setCell ( int  row,
int  col,
const string &  val 
)

set cell(row,col) with contents val

Definition at line 210 of file godleyIcon.cc.

References minsky::Minsky::balanceDuplicateColumns(), minsky::Minsky::importDuplicateColumn(), and pyminsky::minsky.

211  {
212  if (!table.cellInTable(row,col)) return;
213  // if this operation is clearing an initial condition cell, set it to 0
214  string& c=table.cell(row,col);
215  if (newVal.empty() && !c.empty() && table.initialConditionRow(row))
216  c="0";
217  else
218  c=newVal;
219  if (row==0)
221  else
222  minsky().balanceDuplicateColumns(*this, col);
223  table.markEdited();
224  }
void importDuplicateColumn(GodleyTable &srcTable, int srcCol)
find any duplicate column, and use it as a source column for balanceDuplicateColumns ...
Definition: minsky.cc:617
void balanceDuplicateColumns(const GodleyIcon &srcTable, int srcCol)
makes all duplicated columns consistent with srcTable, srcCol
Definition: minsky.cc:752
bool cellInTable(int row, int col) const
Definition: godleyTable.h:145
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
Definition: godleyTable.cc:37
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
static void markEdited()
mark model as having changed
Definition: godleyTable.cc:32
Minsky & minsky()
global minsky object
Definition: addon.cc:545
Here is the call graph for this function:

◆ setCurrency()

void minsky::GodleyIcon::setCurrency ( const std::string &  currency)
inline

Definition at line 148 of file godleyIcon.h.

References currency, and m_stockVars.

149  {this->currency=currency; for (auto& i: m_stockVars) i->setUnits(currency);}
Variables m_stockVars
Definition: godleyIcon.h:176
std::string currency
Definition: godleyIcon.h:147

◆ stockVars()

const Variables& minsky::GodleyIcon::stockVars ( ) const
inline

Definition at line 113 of file godleyIcon.h.

References m_stockVars.

113 {return m_stockVars;}
Variables m_stockVars
Definition: godleyIcon.h:176

◆ stockVarUnits()

Units minsky::GodleyIcon::stockVarUnits ( const std::string &  stockName,
bool  check 
) const

performs dimensional analysis on stock var column stockName

Parameters
checkindicates whether a consistency check is applied

Definition at line 545 of file godleyIcon.cc.

References minsky::cminsky(), minsky::Units::str(), minsky::Simulation::timeUnit, minsky::valueId(), and minsky::Minsky::variableValues.

546  {
547  unsigned stockCol=1;
548  auto valId=valueId(stockName);
549  for (; stockCol<table.cols(); ++stockCol)
550  if (valueId(table.cell(0,stockCol))==valId)
551  break;
552 
553  if (stockCol>=table.cols()) return {};
554 
555  bool foundFlow=false;
556  Units units;
557  for (unsigned row=1; row<table.rows(); ++row)
558  {
559  if (table.initialConditionRow(row)) continue;
560  const FlowCoef fc(table.cell(row,stockCol));
561  if (fc.coef!=0)
562  {
563  auto vid=valueId(fc.name);
564  // find variable assciated with this flow
565  for (const auto& v: flowVars())
566  if (v->valueId()==vid)
567  {
568  auto flowUnits=v->units(check);
569  if (check && foundFlow && units!=flowUnits)
570  throw_error("incompatible units: "+flowUnits.str()+"≠"+units.str()+" on stock "+stockName);
571  foundFlow=true;
572  units=flowUnits;
573  }
574  }
575  }
576  if (!cminsky().timeUnit.empty())
577  units[cminsky().timeUnit]++;
578  return foundFlow? units: cminsky().variableValues[valId]->units;
579  }
virtual Units units(bool check=false) const
compute the dimensional units
Definition: item.h:346
std::size_t cols() const
Definition: godleyTable.h:105
std::string str() const
Definition: variableType.cc:33
VariableValues variableValues
Definition: minsky.h:188
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
Definition: godleyTable.cc:37
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
const Variables & flowVars() const
Definition: godleyIcon.h:112
std::size_t rows() const
Definition: godleyTable.h:104
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::string valueId(const std::string &x) const
returns valueid for variable reference in table
Definition: godleyIcon.h:142
std::string timeUnit
Definition: simulation.h:35
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
void throw_error(const std::string &) const
mark item on canvas, then throw
Definition: item.cc:86
Here is the call graph for this function:

◆ summarise()

vector< Summary > minsky::GodleyIcon::summarise ( ) const

summary of variables in this godley table

Definition at line 272 of file godleyIcon.cc.

273  {
274  vector<Summary> r;
275  for (auto& i: stockVars())
276  if (auto vv=i->vValue())
277  {
278  r.push_back(vv->summary());
279  r.back().godley=table.title.empty()? id(): table.title;
280  }
281  for (auto& i: flowVars())
282  if (auto vv=i->vValue())
283  {
284  r.push_back(vv->summary());
285  r.back().godley=table.title.empty()? id(): table.title;
286  }
287  return r;
288  }
const Variables & flowVars() const
Definition: godleyIcon.h:112
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::string title
Definition: godleyTable.h:58
const Variables & stockVars() const
Definition: godleyIcon.h:113
std::string id() const
return an id uniquely identifying this item
Definition: item.h:233

◆ titleOffs()

double minsky::GodleyIcon::titleOffs ( ) const
inlineprivate

Definition at line 59 of file godleyIcon.h.

References table, minsky::GodleyTable::title, and minsky::Item::zoomFactor().

59 {return !table.title.empty()? 15*zoomFactor(): 0;}
virtual float zoomFactor() const
Definition: item.cc:121
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::string title
Definition: godleyTable.h:58
Here is the call graph for this function:

◆ toEditorX()

float minsky::GodleyIcon::toEditorX ( float  xx) const
private

convert mouse coordinates into editor coords

Definition at line 604 of file godleyIcon.cc.

References border.

605  {return xx-x()+0.5f*width()-2*border*zoomFactor()-leftMargin();}
virtual float x() const
Definition: item.cc:107
virtual float zoomFactor() const
Definition: item.cc:121
float leftMargin() const
left margin of bank icon with Godley icon
Definition: godleyIcon.h:91
float width() const
Definition: item.h:239
const float border
Definition: godleyIcon.cc:41

◆ toEditorY()

float minsky::GodleyIcon::toEditorY ( float  yy) const
private

convert mouse coordinates into editor coords

Definition at line 606 of file godleyIcon.cc.

References border.

607  {return yy-y()+0.5f*height()-2*border*zoomFactor()-titleOffs();}
double titleOffs() const
Definition: godleyIcon.h:59
virtual float y() const
Definition: item.cc:114
virtual float zoomFactor() const
Definition: item.cc:121
const float border
Definition: godleyIcon.cc:41
float height() const
Definition: item.h:240

◆ toggleButtons()

void minsky::GodleyIcon::toggleButtons ( )

Definition at line 163 of file godleyIcon.cc.

164  {
165  if (editor.drawButtons)
167  else
170  }
bool drawButtons
whether to draw row/column buttons
void updateBoundingBox() override
Definition: item.h:198
GodleyTableEditor editor
rendering as a godley table
Definition: godleyIcon.h:82

◆ toggleEditorMode()

void minsky::GodleyIcon::toggleEditorMode ( )
overridevirtual

Reimplemented from minsky::Item.

Definition at line 156 of file godleyIcon.cc.

157  {
160  }
void updateBoundingBox() override
Definition: item.h:198

◆ toggleVariableDisplay()

void minsky::GodleyIcon::toggleVariableDisplay ( )

Definition at line 150 of file godleyIcon.cc.

151  {
153  update();
154  }
void update()
updates the variable lists with the Godley table
Definition: godleyIcon.cc:290

◆ update()

void minsky::GodleyIcon::update ( )

updates the variable lists with the Godley table

Definition at line 290 of file godleyIcon.cc.

References minsky::anonymous_namespace{godleyIcon.cc}::accumulateWidthHeight(), minsky::FlowCoef::coef, minsky::Minsky::definingVar(), f, minsky::VariableValueData::godleyOverridden, minsky::group, minsky::VariableValue::init(), pyminsky::minsky, minsky::FlowCoef::str(), minsky::trimWS(), minsky::valueId(), and minsky::Minsky::variableValues.

291  {
294 
295  // retrieve initial conditions, if any
296  for (size_t r=1; r<table.rows(); ++r)
297  if (table.initialConditionRow(r))
298  for (size_t c=1; c<table.cols(); ++c)
299  {
300  const string name=trimWS(table.cell(0,c));
301  auto vi=minsky().variableValues.find(minsky::valueId(group.lock(),name));
302  if (vi==minsky().variableValues.end()) continue;
303  VariableValue& v=*vi->second;
304  v.godleyOverridden=false;
305  const string::size_type start=table.cell(r,c).find_first_not_of(' ');
306  if (start!=string::npos)
307  {
308  const FlowCoef fc(table.cell(r,c).substr(start));
309  v.init(fc.str());
310  // set initial value of stock var to init value of flow that is defined by a parameter or a constant. for ticket 1137
311  if (auto initVar=minsky().definingVar(minsky::valueId(group.lock(),fc.str())))
312  if (initVar->inputWired() && initVar->type()==VariableType::flow)
313  if (auto* lhsVar=initVar->ports(1).lock()->wires()[0]->from()->item().variableCast()) {
314  FlowCoef fc1(lhsVar->vValue()->init());
315  fc1.coef*=fc.coef;
316  v.init(fc1.str());
317  }
318  v.godleyOverridden=true;
319  }
320  else
321  {
322  // populate cell with current variable's initial value
323  const FlowCoef fc(v.init());
324  table.cell(r,c)=fc.str();
325  v.godleyOverridden=true;
326  }
327 
328  }
329 
330  if (m_variableDisplay)
331  {
332  // determine height of variables part of icon
333  float stockH=0, flowH=0;
334  stockMargin=0;
335  flowMargin=0;
338  // allow for notches on variables
339  stockMargin+=4;
340  flowMargin+=4;
341  const float iw=this->iWidth(), ih=this->iHeight();
342  this->iWidth(max(iw, 1.8f*stockH));
343  this->iHeight(max(ih, 1.8f*flowH));
344  }
345  else
346  { // if any variables have attached wires, create a copy to carry the wire
347  for (auto& v: m_stockVars)
348  if (auto p=v->ports(0).lock())
349  if (!p->wires().empty())
350  {
351  if (auto g=group.lock())
352  {
353  auto newVar=g->addItem(v->clone());
354  if (auto w=p->wires().front())
355  if (auto from=newVar->ports(0).lock())
356  {
357  w->moveToPorts(from, w->to());
358  continue;
359  }
360  }
361  // in falling through to here, we've failed to create and wire a variable copy
362  m_variableDisplay=true;
363  throw_error("Cowardly refusing to hide a wired variable");
364  }
365 
366  for (auto& v: m_flowVars)
367  if (auto p=v->ports(1).lock())
368  if (!p->wires().empty())
369  {
370  if (auto g=group.lock())
371  {
372  auto newVar=g->addItem(v->clone());
373  if (auto w=p->wires().front())
374  if (auto to=newVar->ports(1).lock())
375  {
376  w->moveToPorts(w->from(), to);
377  continue;
378  }
379  }
380  // in falling through to here, we've failed to create and wire a variable copy
381  m_variableDisplay=true;
382  throw_error("Cowardly refusing to hide a wired variable");
383  }
384  }
385 
387  updateBB();
388  }
void updateVars(Variables &vars, const vector< string > &varNames, VariableBase::Type varType)
Definition: godleyIcon.cc:95
std::size_t cols() const
Definition: godleyTable.h:105
function f
Definition: canvas.m:1
Variables m_flowVars
Definition: godleyIcon.h:176
VariableValues variableValues
Definition: minsky.h:188
float iHeight() const
Definition: item.h:221
void positionVariables() const
move contained variables to correct locations within icon
Definition: godleyIcon.cc:390
float flowMargin
for placement of bank icon within complex
Definition: godleyIcon.h:45
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
Definition: godleyTable.cc:37
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
std::size_t rows() const
Definition: godleyTable.h:104
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
float iWidth() const
Definition: item.h:214
std::string trimWS(const std::string &s)
Definition: str.h:49
Variables m_stockVars
Definition: godleyIcon.h:176
VariablePtr definingVar(const std::string &valueId) const
returns reference to variable defining (ie input wired) for valueId
Definition: minsky.cc:204
void throw_error(const std::string &) const
mark item on canvas, then throw
Definition: item.cc:86
std::vector< std::string > getColumnVariables() const
get the set of column labels, in column order
Definition: godleyTable.cc:146
Minsky & minsky()
global minsky object
Definition: addon.cc:545
std::vector< std::string > getVariables() const
get the vector of unique variable names from the interior of the table, in row, then column order ...
Definition: godleyTable.cc:164
void accumulateWidthHeight(const GodleyIcon::Variables &vars, float &height, float &width)
Definition: godleyIcon.cc:75
Here is the call graph for this function:

◆ updateBB()

void minsky::GodleyIcon::updateBB ( )
inlineprivate

Definition at line 52 of file godleyIcon.h.

References minsky::Item::bb, minsky::NoteBase::selected, and minsky::BoundingBox::update().

52  {
53  auto wasSelected=selected;
54  selected=true; // ensure bounding box is set to the entire icon
55  bb.update(*this);
56  selected=wasSelected;
57  }
BoundingBox bb
canvas bounding box.
Definition: item.h:192
void update(const Item &x)
Definition: item.cc:46
bool selected
true if selected for cut, copy or group operation
Definition: noteBase.h:32
Here is the call graph for this function:

◆ updateVars()

void minsky::GodleyIcon::updateVars ( GodleyIcon::Variables vars,
const vector< string > &  varNames,
VariableBase::Type  varType 
)
private

Definition at line 95 of file godleyIcon.cc.

References minsky::Minsky::convertVarType(), minsky::group, and minsky::minsky().

98  {
99  // update the map of variables from the Godley table
100  set<VariablePtr, OrderByName> oldVars(vars.begin(), vars.end());
101  set<string> alreadyAdded;
102 
103  vars.clear();
104  shared_ptr<GodleyIcon> self;
105  if (auto g=group.lock())
106  self=dynamic_pointer_cast<GodleyIcon>(g->findItem(*this));
107 
108  for (vector<string>::const_iterator nm=varNames.begin(); nm!=varNames.end(); ++nm)
109  {
110  const VariablePtr newVar(varType, *nm);
111  auto myGroup=group.lock();
112  if (myGroup) myGroup->addItem(newVar); // get scope right
113  auto v=oldVars.find(newVar);
114 
115  if (v==oldVars.end())
116  {
117  // allow for the possibility that multiple names map to the same valueId
118  if (!alreadyAdded.contains(newVar->valueId()))
119  {
120  // add new variable
121  vars.push_back(newVar);
122  alreadyAdded.insert(newVar->valueId());
123  if (varType==VariableType::stock) // newly added variables should take the default dimension
124  newVar->setUnits(currency);
125  }
126  else
127  if (myGroup)
128  myGroup->removeItem(*newVar);
129  }
130  else
131  {
132  // move existing variable
133  assert(*v);
134  vars.push_back(*v);
135  alreadyAdded.insert(newVar->valueId());
136  oldVars.erase(v);
137  if (myGroup) myGroup->removeItem(*newVar);
138  }
139  if (myGroup) myGroup->addItem(vars.back(),true);
140  vars.back()->controller=self;
141  // ensure variable type is consistent
142  minsky::minsky().convertVarType(vars.back()->valueId(), varType);
143  }
144  // remove any previously existing variables
145  if (auto g=group.lock())
146  for (const auto& v: oldVars)
147  g->deleteItem(*v);
148  }
void convertVarType(const std::string &name, VariableType::Type type)
Converts variable(s) named by name into a variable of type type.
Definition: minsky.cc:1456
Minsky & minsky()
global minsky object
Definition: addon.cc:545
std::string currency
Definition: godleyIcon.h:147
Here is the call graph for this function:

◆ valueId()

std::string minsky::GodleyIcon::valueId ( const std::string &  x) const
inline

returns valueid for variable reference in table

Definition at line 142 of file godleyIcon.h.

References minsky::group, minsky::valueId(), and minsky::Item::x().

Referenced by minsky::Minsky::balanceColumns(), and minsky::Minsky::balanceDuplicateColumns().

142 {return minsky::valueId(group.lock(), x);}
virtual float x() const
Definition: item.cc:107
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ variableDisplay()

bool minsky::GodleyIcon::variableDisplay ( ) const
inline

Definition at line 76 of file godleyIcon.h.

References m_variableDisplay.

Referenced by bottomMargin(), and leftMargin().

76 {return m_variableDisplay;}
Here is the caller graph for this function:

◆ wiresAttached()

bool minsky::GodleyIcon::wiresAttached ( ) const

return true if any wires are attached to the variables

Definition at line 429 of file godleyIcon.cc.

430  {
431  bool r=false;
432  for (auto& v: m_flowVars)
433  if (auto p=v->ports(1).lock())
434  r|=p->wires().size();
435  for (auto& v: m_stockVars)
436  if (auto p=v->ports(0).lock())
437  r|=p->wires().size();
438  return r;
439  }
Variables m_flowVars
Definition: godleyIcon.h:176
Variables m_stockVars
Definition: godleyIcon.h:176

Friends And Related Function Documentation

◆ SchemaHelper

friend struct SchemaHelper
friend

Definition at line 49 of file godleyIcon.h.

Member Data Documentation

◆ currency

std::string minsky::GodleyIcon::currency

Definition at line 147 of file godleyIcon.h.

Referenced by setCurrency().

◆ editor

GodleyTableEditor minsky::GodleyIcon::editor {*this}

rendering as a godley table

Definition at line 82 of file godleyIcon.h.

Referenced by GodleyIcon().

◆ flowMargin

float minsky::GodleyIcon::flowMargin =0
private

for placement of bank icon within complex

Definition at line 45 of file godleyIcon.h.

Referenced by leftMargin().

◆ m_editorMode

bool minsky::GodleyIcon::m_editorMode =false
private

Definition at line 46 of file godleyIcon.h.

Referenced by editorMode().

◆ m_flowVars

Variables minsky::GodleyIcon::m_flowVars
private

Definition at line 176 of file godleyIcon.h.

Referenced by flowVars(), and minsky::SchemaHelper::setStockAndFlow().

◆ m_stockVars

Variables minsky::GodleyIcon::m_stockVars
private

Definition at line 176 of file godleyIcon.h.

Referenced by setCurrency(), minsky::SchemaHelper::setStockAndFlow(), and stockVars().

◆ m_variableDisplay

bool minsky::GodleyIcon::m_variableDisplay =false
private

Definition at line 47 of file godleyIcon.h.

Referenced by minsky::SchemaHelper::setVariableDisplay(), and variableDisplay().

◆ popup

GodleyTableWindow minsky::GodleyIcon::popup {*this}

for rendering the popup window

Definition at line 84 of file godleyIcon.h.

Referenced by adjustPopupWidgets(), and destroyFrame().

◆ stockMargin

float minsky::GodleyIcon::stockMargin =0
private

Definition at line 45 of file godleyIcon.h.

Referenced by bottomMargin().

◆ svgRenderer

SVGRenderer minsky::GodleyIcon::svgRenderer
static

SVG icon to display when not in editor mode.

Definition at line 62 of file godleyIcon.h.

Referenced by minsky::Minsky::setGodleyIconResource().

◆ table


The documentation for this class was generated from the following files: