Minsky
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 TCL_obj (classdesc::TCL_obj_t &t, const std::string &d) override
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) override
 dummy template definition for use with gui executable More...
 
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 ()
 
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 =10
 
double m_height =10
 
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:224
float iWidth() const
Definition: item.h:217
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 161 of file godleyIcon.cc.

161 {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:224
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:217
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:414

◆ 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 225 of file godleyIcon.cc.

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

226  {
227  if (row>0 && row<=table.rows())
228  {
229  table.deleteRow(row-1);
230  // if shared column data is deleted, remove it from the other tables too
231  for (size_t col=1; col<table.cols(); ++col)
232  minsky().balanceDuplicateColumns(*this, col);
233  table.markEdited();
234  }
235  }
std::size_t cols() const
Definition: godleyTable.h:115
void balanceDuplicateColumns(const GodleyIcon &srcTable, int srcCol)
makes all duplicated columns consistent with srcTable, srcCol
Definition: minsky.cc:753
void deleteRow(unsigned row)
delete row at row
Definition: godleyTable.h:131
std::size_t rows() const
Definition: godleyTable.h:114
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: minskyTCL.cc:51
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 441 of file godleyIcon.cc.

References border, and minsky::latexToPango().

442  {
444  const float z=zoomFactor()*scaleFactor();
445  float w=iWidth()*z+leftMargin(), h=iHeight()*z+bottomMargin(), left=-0.5*w, top=-0.5*h;
446  double titley;
447 
448  if (m_editorMode)
449  {
450  const CairoSave cs(cairo);
451  cairo_rectangle(cairo, left, top, w, h);
452  cairo_rectangle(cairo, left-border*z, top-border*z, w+2*border*z, h+2*border*z);
453  cairo_stroke_preserve(cairo);
454  if (onBorder)
455  { // shadow the border when mouse is over it
456  const cairo::CairoSave cs(cairo);
457  cairo_set_source_rgba(cairo,0.5,0.5,0.5,0.5);
458  cairo_set_fill_rule(cairo,CAIRO_FILL_RULE_EVEN_ODD);
459  cairo_fill(cairo);
460  }
461  cairo_new_path(cairo);
462  cairo_rectangle(cairo, left, top, w, h);
463  cairo_clip(cairo);
464  cairo_translate(cairo,left+border*z+leftMargin(),top+border*z+titleOffs()/* space for title*/);
465  // render to a recording surface to determine size of editor table
466  // TODO - maybe move this stuff into update()
467  const Surface surf(cairo_recording_surface_create(CAIRO_CONTENT_COLOR, nullptr));
468  const_cast<GodleyTableEditor&>(editor).zoomFactor=1;
469  const_cast<GodleyTableEditor&>(editor).draw(surf.cairo());
470  const_cast<GodleyTableEditor&>(editor).zoomFactor=min((w-leftMargin()-2*border*z)/surf.width(),(h-bottomMargin()-2*border*z-titleOffs())/surf.height());
471  const_cast<GodleyTableEditor&>(editor).draw(cairo);
472  titley=-0.5*h;
473  w+=2*border*z;
474  h+=2*border*z;
475  left-=border*z;
476  top-=border*z;
477  }
478  else
479  {
480  const CairoSave cs(cairo);
481  cairo_translate(cairo,left+leftMargin(),top);
482  cairo_scale(cairo, (w-leftMargin())/svgRenderer.width(), (h-bottomMargin())/svgRenderer.height());
483  svgRenderer.render(cairo);
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:428
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:224
void positionVariables() const
move contained variables to correct locations within icon
Definition: godleyIcon.cc:389
virtual std::string const & tooltip() const
Definition: noteBase.h:36
virtual float zoomFactor() const
Definition: item.cc:121
double width() const
Definition: SVGItem.h:44
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
double height() const
Definition: SVGItem.h:45
float iWidth() const
Definition: item.h:217
bool onBorder
true to indicate mouse hovering over border
Definition: item.h:176
Variables m_stockVars
Definition: godleyIcon.h:176
virtual void drawResizeHandles(cairo_t *cairo) const
Definition: item.cc:343
const float border
Definition: godleyIcon.cc:40
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:60
void draw(cairo_t *cairo) const override
draw icon to context
Definition: godleyIcon.cc:441
bool mouseFocus
true if target of a mouseover
Definition: noteBase.h:31
void render(cairo_t *) const
Definition: SVGItem.cc:82
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
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 258 of file godleyIcon.cc.

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

259  {
260  map<string,double> r;
261  for (size_t row=1; row<table.rows() && col<table.cols(); ++row)
262  if (!table.initialConditionRow(row))
263  {
264  const FlowCoef fc(table.cell(row,col));
265  if (!fc.name.empty())
266  r[fc.name]+=fc.coef;
267  }
268  return r;
269  }
std::size_t cols() const
Definition: godleyTable.h:115
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:144
std::size_t rows() const
Definition: godleyTable.h:114
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 89 of file godleyIcon.cc.

References border.

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

◆ 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 238 of file godleyIcon.cc.

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

239  {
240  if (!table.cellInTable(args.srcRow, args.srcCol) || !table.cellInTable(args.destRow, args.destCol)) return;
241  if (args.srcCol!=args.destCol) // if moving between columns, we can delete and
242  // add, which ensures any linked columns are
243  // correctly updated
244  {
245  // create a copy here, as setCell may resize the array, changing
246  // what the reference referred to.
247  const string oldVal=table.cell(args.srcRow, args.srcCol);
248  setCell(args.destRow, args.destCol, oldVal);
249  setCell(args.srcRow, args.srcCol, "");
250  }
251  else // within a column, just move the data without affecting any linked column
252  {
253  table.cell(args.destRow, args.destCol)=table.cell(args.srcRow, args.srcCol);
254  table.cell(args.srcRow, args.srcCol)="";
255  }
256  }
bool cellInTable(int row, int col) const
Definition: godleyTable.h:155
void setCell(int row, int col, const string &val)
set cell(row,col) with contents val
Definition: godleyIcon.cc:209
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
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 389 of file godleyIcon.cc.

390  {
391  // position of margin in absolute canvas coordinate
392  const float z=this->zoomFactor()*scaleFactor();
393  float x= this->x() - 0.5*iWidth()*z+0.5*leftMargin();
394  float y= this->y() - 0.5*bottomMargin()-0.15*iHeight()*z;
395  for (const auto& v: m_flowVars)
396  {
397  // right justification if displayed, left otherwisw
398  v->rotation(0);
399  v->moveTo(x+v->x() - (m_variableDisplay? v->right(): v->left()), y);
400  y+=v->height();
401  }
402  x= this->x() + 0.55*leftMargin()-0.45*iWidth()*z;
403  y= this->y() + 0.5*iHeight()*z-0.5*bottomMargin();
404 
405  for (const auto& v: m_stockVars)
406  {
407  // top justification at bottom of icon if displayed, bottom justified otherwise
408  v->rotation(90);
409  v->moveTo(x, y + v->y() - (m_variableDisplay? v->top(): v->bottom()));
410  x+=v->width();
411  }
412  }
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:224
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:217
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 189 of file godleyIcon.cc.

References minsky::GroupItems::removeItem().

190  {
191  for (auto& i: m_flowVars)
192  {
193  assert(i);
194  i->deleteAttachedWires();
195  auto item=g.removeItem(*i);
196  assert(item.use_count()!=1);
197  }
198  m_flowVars.clear();
199  for (auto& i: m_stockVars)
200  {
201  assert(i);
202  i->deleteAttachedWires();
203  auto item=g.removeItem(*i);
204  assert(item.use_count()!=1);
205  }
206  m_stockVars.clear();
207  }
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 177 of file godleyIcon.cc.

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

178  {
179  const float invZ=1.0/(this->zoomFactor());
180  auto bw=abs(b.x0-b.x1), bh=abs(b.y0-b.y1);
181  if (bw<=leftMargin() || bh<=bottomMargin()) return;
182  moveTo(0.5*(b.x0+b.x1), 0.5*(b.y0+b.y1));
183  iWidth((bw-leftMargin())*invZ);
184  iHeight((bh-bottomMargin())*invZ);
185  scaleIcon(bw,bh);
187  }
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:171
float iHeight() const
Definition: item.h:224
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:217
void moveTo(float x, float y)
Definition: item.cc:256
void updateBoundingBox() override
Definition: item.h:201
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::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:115
std::string rowSum(int row) const
return the symbolic sum across a row
Definition: godleyTable.h:189
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
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
Definition: group.tcl:84
bool signConventionReversed(int col) const
The usual mathematical sign convention is reversed in double entry book keeping conventions if the as...
Definition: godleyTable.h:94
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 171 of file godleyIcon.cc.

172  {
173  update();
175  }
float iHeight() const
Definition: item.h:224
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:217
void update()
updates the variable lists with the Godley table
Definition: godleyIcon.cc:289
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 414 of file godleyIcon.cc.

415  {
416  if (m_variableDisplay) // Disable selection of stock and flow vars when they are hidden. for tickets 1217 and 1220.
417  {
418  for (const auto& v: m_flowVars)
419  if (v->contains(x,y))
420  return v;
421  for (const auto& v: m_stockVars)
422  if (v->contains(x,y))
423  return v;
424  }
425  return ItemPtr();
426  }
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:57
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 209 of file godleyIcon.cc.

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

210  {
211  if (!table.cellInTable(row,col)) return;
212  // if this operation is clearing an initial condition cell, set it to 0
213  string& c=table.cell(row,col);
214  if (newVal.empty() && !c.empty() && table.initialConditionRow(row))
215  c="0";
216  else
217  c=newVal;
218  if (row==0)
220  else
221  minsky().balanceDuplicateColumns(*this, col);
222  table.markEdited();
223  }
void importDuplicateColumn(GodleyTable &srcTable, int srcCol)
find any duplicate column, and use it as a source column for balanceDuplicateColumns ...
Definition: minsky.cc:618
void balanceDuplicateColumns(const GodleyIcon &srcTable, int srcCol)
makes all duplicated columns consistent with srcTable, srcCol
Definition: minsky.cc:753
bool cellInTable(int row, int col) const
Definition: godleyTable.h:155
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:144
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: minskyTCL.cc:51
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:352
std::size_t cols() const
Definition: godleyTable.h:115
std::string str() const
Definition: variableType.cc:33
VariableValues variableValues
Definition: minsky.h:200
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:144
const Variables & flowVars() const
Definition: godleyIcon.h:112
std::size_t rows() const
Definition: godleyTable.h:114
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:549
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 271 of file godleyIcon.cc.

272  {
273  vector<Summary> r;
274  for (auto& i: stockVars())
275  if (auto vv=i->vValue())
276  {
277  r.push_back(vv->summary());
278  r.back().godley=table.title.empty()? id(): table.title;
279  }
280  for (auto& i: flowVars())
281  if (auto vv=i->vValue())
282  {
283  r.push_back(vv->summary());
284  r.back().godley=table.title.empty()? id(): table.title;
285  }
286  return r;
287  }
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:60
const Variables & stockVars() const
Definition: godleyIcon.h:113
std::string id() const
return an id uniquely identifying this item
Definition: item.h:236

◆ 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:60
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:242
const float border
Definition: godleyIcon.cc:40

◆ 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:40
float height() const
Definition: item.h:243

◆ toggleButtons()

void minsky::GodleyIcon::toggleButtons ( )

Definition at line 162 of file godleyIcon.cc.

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

◆ toggleEditorMode()

void minsky::GodleyIcon::toggleEditorMode ( )
overridevirtual

Reimplemented from minsky::Item.

Definition at line 155 of file godleyIcon.cc.

156  {
159  }
void updateBoundingBox() override
Definition: item.h:201

◆ toggleVariableDisplay()

void minsky::GodleyIcon::toggleVariableDisplay ( )

Definition at line 149 of file godleyIcon.cc.

150  {
152  update();
153  }
void update()
updates the variable lists with the Godley table
Definition: godleyIcon.cc:289

◆ update()

void minsky::GodleyIcon::update ( )

updates the variable lists with the Godley table

Definition at line 289 of file godleyIcon.cc.

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

290  {
293 
294  // retrieve initial conditions, if any
295  for (size_t r=1; r<table.rows(); ++r)
296  if (table.initialConditionRow(r))
297  for (size_t c=1; c<table.cols(); ++c)
298  {
299  const string name=trimWS(table.cell(0,c));
300  auto vi=minsky().variableValues.find(minsky::valueId(group.lock(),name));
301  if (vi==minsky().variableValues.end()) continue;
302  VariableValue& v=*vi->second;
303  v.godleyOverridden=false;
304  const string::size_type start=table.cell(r,c).find_first_not_of(' ');
305  if (start!=string::npos)
306  {
307  const FlowCoef fc(table.cell(r,c).substr(start));
308  v.init(fc.str());
309  // set initial value of stock var to init value of flow that is defined by a parameter or a constant. for ticket 1137
310  if (auto initVar=minsky().definingVar(minsky::valueId(group.lock(),fc.str())))
311  if (initVar->inputWired() && initVar->type()==VariableType::flow)
312  if (auto* lhsVar=initVar->ports(1).lock()->wires()[0]->from()->item().variableCast()) {
313  FlowCoef fc1(lhsVar->vValue()->init());
314  fc1.coef*=fc.coef;
315  v.init(fc1.str());
316  }
317  v.godleyOverridden=true;
318  }
319  else
320  {
321  // populate cell with current variable's initial value
322  const FlowCoef fc(v.init());
323  table.cell(r,c)=fc.str();
324  v.godleyOverridden=true;
325  }
326 
327  }
328 
329  if (m_variableDisplay)
330  {
331  // determine height of variables part of icon
332  float stockH=0, flowH=0;
333  stockMargin=0;
334  flowMargin=0;
337  // allow for notches on variables
338  stockMargin+=4;
339  flowMargin+=4;
340  const float iw=this->iWidth(), ih=this->iHeight();
341  this->iWidth(max(iw, 1.8f*stockH));
342  this->iHeight(max(ih, 1.8f*flowH));
343  }
344  else
345  { // if any variables have attached wires, create a copy to carry the wire
346  for (auto& v: m_stockVars)
347  if (auto p=v->ports(0).lock())
348  if (!p->wires().empty())
349  {
350  if (auto g=group.lock())
351  {
352  auto newVar=g->addItem(v->clone());
353  if (auto w=p->wires().front())
354  if (auto from=newVar->ports(0).lock())
355  {
356  w->moveToPorts(from, w->to());
357  continue;
358  }
359  }
360  // in falling through to here, we've failed to create and wire a variable copy
361  m_variableDisplay=true;
362  throw_error("Cowardly refusing to hide a wired variable");
363  }
364 
365  for (auto& v: m_flowVars)
366  if (auto p=v->ports(1).lock())
367  if (!p->wires().empty())
368  {
369  if (auto g=group.lock())
370  {
371  auto newVar=g->addItem(v->clone());
372  if (auto w=p->wires().front())
373  if (auto to=newVar->ports(1).lock())
374  {
375  w->moveToPorts(w->from(), to);
376  continue;
377  }
378  }
379  // in falling through to here, we've failed to create and wire a variable copy
380  m_variableDisplay=true;
381  throw_error("Cowardly refusing to hide a wired variable");
382  }
383  }
384 
386  updateBB();
387  }
void updateVars(Variables &vars, const vector< string > &varNames, VariableBase::Type varType)
Definition: godleyIcon.cc:94
std::size_t cols() const
Definition: godleyTable.h:115
function f
Definition: canvas.m:1
Variables m_flowVars
Definition: godleyIcon.h:176
VariableValues variableValues
Definition: minsky.h:200
float iHeight() const
Definition: item.h:224
void positionVariables() const
move contained variables to correct locations within icon
Definition: godleyIcon.cc:389
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:144
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:114
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
float iWidth() const
Definition: item.h:217
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:205
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
Definition: group.tcl:84
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
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:74
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:195
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 94 of file godleyIcon.cc.

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

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

429  {
430  bool r=false;
431  for (auto& v: m_flowVars)
432  if (auto p=v->ports(1).lock())
433  r|=p->wires().size();
434  for (auto& v: m_stockVars)
435  if (auto p=v->ports(0).lock())
436  r|=p->wires().size();
437  return r;
438  }
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: