Minsky
minsky::VariableBase Class Referenceabstract

#include <variable.h>

Inheritance diagram for minsky::VariableBase:
Inheritance graph
Collaboration diagram for minsky::VariableBase:
Collaboration graph

Public Types

typedef VariableType::Type Type
 
- Public Types inherited from minsky::VariableType
enum  Type {
  undefined, constant, parameter, flow,
  integral, stock, tempFlow, numVarTypes
}
 

Public Member Functions

virtual std::size_t numPorts () const =0
 
virtual Type type () const =0
 
void retype (VariableType::Type type)
 attempt to replace this variable with variable of type. More...
 
bool visible () const override
 whether this item is visible on the canvas. More...
 
const VariableBasevariableCast () const override
 
VariableBasevariableCast () override
 
float zoomFactor () const override
 
bool local () const
 
void toggleLocal ()
 toggle local status More...
 
const std::string & rawName () const
 accessor for the name member (may differ from name() with top level variables) More...
 
bool ioVar () const override
 indicates this is a group I/O variable More...
 
void ensureValueExists (VariableValue *vv, const std::string &name) const
 ensure an associated variableValue exists More...
 
virtual std::string valueId () const
 string used to link to the VariableValue associated with this More...
 
std::string valueIdInCurrentScope (const std::string &nm) const
 returns valueId for nm. If nm is not qualified, this variable's scope is used More...
 
std::shared_ptr< VariableValuevValue () const
 variableValue associated with this. nullptr if not associated with a variableValue More...
 
std::vector< unsigned > dims () const
 variable's tensor shape More...
 
std::vector< std::string > dimLabels () const
 labels along each axis More...
 
std::pair< std::string, std::string > getDimLabelsPicked () const
 
std::pair< std::string, std::string > setDimLabelsPicked (const std::string &dimLabel1, const std::string &dimLabel2)
 
const std::string & detailedText () const override
 
const std::string & detailedText (const std::string &x) override
 
const std::string & tooltip () const override
 
const std::string & tooltip (const std::string &x) override
 
bool sliderVisible () const
 returns true if slider is to be drawn More...
 
Units units (bool check) const override
 sets/gets the units associated with this type More...
 
Units units () const
 
void setUnits (const std::string &) const
 
std::string unitsStr () const
 
bool onKeyPress (int, const std::string &, int) override
 respond to key press events More...
 
bool lhs () const
 variable is on left hand side of flow calculation More...
 
bool temp () const
 variable is temporary More...
 
virtual VariableBaseclone () const override=0
 
bool isStock () const
 
std::string definition () const
 formula defining this variable More...
 
void draw (cairo_t *) const override
 
void resize (const LassoBox &b) override
 resize this item on the canvas More...
 
ClickType::Type clickType (float x, float y) const override
 returns the clicktype given a mouse click at x, y. More...
 
bool defined () const
 
bool inputWired () const
 
std::vector< std::string > accessibleVars () const
 return a list of existing variables this could be connected to More...
 
EngNotation engExp () const
 return formatted mantissa and exponent in engineering format More...
 
std::string mantissa (const EngNotation &e, int digits=3) const
 
void exportAsCSV (const std::string &filename, bool tabular) const
 export this variable as a CSV file More...
 
void importFromCSV (const std::vector< std::string > &filenames, const DataSpecSchema &spec) const
 import CSV files, using spec More...
 
void destroyFrame () override
 clean up popup window structures on window close More...
 
bool miniPlotEnabled () const
 
bool miniPlotEnabled (bool)
 
void resetMiniPlot ()
 
bool onMouseMotion (float x, float y) override
 respond to mouse motion events with button pressed More...
 
void adjustSliderBounds ()
 
virtual std::string name () const
 variable displayed name More...
 
virtual std::string name (const std::string &nm)
 variable displayed name More...
 
const std::string & canonicalName () const
 variable displayed name More...
 
std::string init () const
 the initial value of this variable More...
 
std::string init (const std::string &)
 < return initial value for this variable More...
 
virtual double value (const double &)
 < set the initial value for this variable More...
 
virtual double value () const override
 < set the initial value for this variable More...
 
double sliderMin () const
 slider parameters More...
 
double sliderMin (double) const
 slider parameters More...
 
double sliderMax () const
 slider parameters More...
 
double sliderMax (double) const
 slider parameters More...
 
double sliderStep () const
 slider parameters More...
 
double sliderStep (double) const
 slider parameters More...
 
bool sliderStepRel () const
 slider parameters More...
 
bool sliderStepRel (bool) const
 slider parameters More...
 
bool enableSlider () const
 slider parameters More...
 
bool enableSlider (bool)
 slider parameters More...
 
- Public Member Functions inherited from minsky::BottomRightResizerItem
bool onResizeHandle (float x, float y) const override
 
void drawResizeHandles (cairo_t *cairo) const override
 
virtual Point resizeHandleCoords () const
 returns coordinates of the resizer handle More...
 
- 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...
 
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...
 
virtual std::string classType () const
 
std::string id () const
 return an id uniquely identifying this item More...
 
virtual float x () const
 
virtual float y () 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 inItem (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 onMouseDown (float x, float y)
 respond to mouse down events More...
 
virtual void onMouseUp (float x, float y)
 respond to mouse up events More...
 
virtual bool onMouseOver (float x, float y)
 respond to mouse motion events (hover) without button pressed More...
 
virtual void onMouseLeave ()
 respond to mouse leave events (when mouse leaves item) More...
 
virtual void deleteAttachedWires ()
 delete all attached wires 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 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
 
virtual std::shared_ptr< Itemselect (float x, float y) const
 returns the variable if point (x,y) is within a visible variable icon, null otherwise. More...
 
virtual void TCL_obj (classdesc::TCL_obj_t &t, const std::string &d)
 runs the TCL_obj descriptor suitable for this type More...
 
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 json_pack (classdesc::json_pack_t &j) const
 
virtual void displayDelayedTooltip (float x, float y)
 enable extended tooltip help message appropriate for mouse at (x,y) More...
 
virtual void disableDelayedTooltip ()
 
virtual bool editorMode () const
 some items have an editor mode attribute More...
 
virtual void toggleEditorMode ()
 
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 ~NoteBase ()=default
 
- Public Member Functions inherited from minsky::VarAccessors::NameAccessor
 NameAccessor ()
 
- Public Member Functions inherited from minsky::VarAccessors::InitAccessor
 InitAccessor ()
 
- Public Member Functions inherited from minsky::VarAccessors::ValueAccessor
 ValueAccessor ()
 
- Public Member Functions inherited from minsky::VariableCaches
 VariableCaches ()=default
 
 VariableCaches (const VariableCaches &)
 
VariableCachesoperator= (const VariableCaches &)
 

Static Public Member Functions

static VariableBasecreate (Type type)
 
- Static Public Member Functions inherited from minsky::Item
static void drawSelected (cairo_t *cairo)
 
- Static Public Member Functions inherited from minsky::VariableType
static std::string typeName (int t)
 

Public Attributes

classdesc::Exclude< std::weak_ptr< Item > > controller
 reference to a controlling item - eg GodleyIcon, IntOp or a Group if an IOVar. More...
 
- 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 int varsPassed =0
 for caching units calculation factory method More...
 

Protected Member Functions

void addPorts ()
 

Private Member Functions

 CLASSDESC_ACCESS (VariableBase)
 
void insertControlled (Selection &selection) override
 

Private Attributes

std::string m_name
 
std::string m_canonicalName
 latex processed and active stripped version of name More...
 
std::pair< std::string, std::string > m_dimLabelsPicked
 
int unitsCtr =0
 for detecting reentrancy in units() More...
 
classdesc::Exclude< std::shared_ptr< ecolab::Plot > > miniPlot
 miniature plot feature More...
 

Static Private Attributes

static int stockVarsPassed =0
 for detecting reentrancy in units() More...
 

Friends

struct minsky::SchemaHelper
 

Additional Inherited Members

- 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
 
- Protected Attributes inherited from minsky::VariableCaches
classdesc::Exclude< std::shared_ptr< RenderVariable > > cachedNameRender
 cached Pango objects More...
 
classdesc::Exclude< std::shared_ptr< ecolab::Pango > > cachedMantissa
 
classdesc::Exclude< std::shared_ptr< ecolab::Pango > > cachedExponent
 
double cachedValue
 
double cachedTime
 

Detailed Description

Definition at line 87 of file variable.h.

Member Typedef Documentation

◆ Type

Definition at line 96 of file variable.h.

Member Function Documentation

◆ accessibleVars()

std::vector< std::string > VariableBase::accessibleVars ( ) const

return a list of existing variables this could be connected to

Definition at line 89 of file variable.cc.

90 {
91  if (auto g=group.lock())
92  return g->accessibleVars();
93  return {};
94 }
Definition: group.tcl:84

◆ addPorts()

void VariableBase::addPorts ( )
protected

Definition at line 69 of file variable.cc.

References minsky::Item::m_ports, and numPorts().

Referenced by minsky::Variable< VariableType::constant >::operator=(), minsky::PhillipsStock::PhillipsStock(), and minsky::Variable< VariableType::constant >::Variable().

70 {
71 #ifndef NDEBUG
72  for (auto& i: m_ports)
73  assert(i.use_count()==1);
74 #endif
75  m_ports.clear();
76  if (numPorts()>0)
77  m_ports.emplace_back(make_shared<Port>(*this));
78  for (size_t i=1; i<numPorts(); ++i)
79  m_ports.emplace_back(make_shared<InputPort>(*this));
80 }
virtual std::size_t numPorts() const =0
ItemPortVector m_ports
Definition: item.h:156
Here is the call graph for this function:
Here is the caller graph for this function:

◆ adjustSliderBounds()

void VariableBase::adjustSliderBounds ( )

Definition at line 555 of file variable.cc.

References vValue().

556 {
557  if (auto vv=vValue())
558  vv->adjustSliderBounds();
559 }
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ canonicalName()

const std::string& minsky::VariableBase::canonicalName ( ) const
inline

variable displayed name

Definition at line 145 of file variable.h.

References m_canonicalName.

145 {return m_canonicalName;}
std::string m_canonicalName
latex processed and active stripped version of name
Definition: variable.h:102

◆ CLASSDESC_ACCESS()

minsky::VariableBase::CLASSDESC_ACCESS ( VariableBase  )
private

◆ clickType()

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

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

Reimplemented from minsky::Item.

Definition at line 97 of file variable.cc.

References minsky::Item::clickType(), minsky::VariableType::constant, minsky::flipped(), minsky::RenderVariable::handlePos(), minsky::RenderVariable::height(), minsky::Item::iHeight(), minsky::ClickType::inItem, minsky::Item::rotation(), type(), minsky::Rotate::x(), minsky::Item::x(), minsky::Rotate::y(), minsky::Item::y(), and zoomFactor().

98 {
99  const Rotate r(rotation()+(flipped(rotation())? 180: 0),0,0); // rotate into variable's frame of reference
100  const RenderVariable rv(*this);
101  const double z=zoomFactor();
102  try
103  {
104  const double hpx=z*rv.handlePos();
105  double hpy=-z*rv.height();
106  if (rv.height()<0.5*iHeight()) hpy=-z*0.5*iHeight();
107  const double dx=xx-x(), dy=yy-y();
108  if (type()!=constant && hypot(dx - r.x(hpx,hpy), dy-r.y(hpx,hpy)) < 5)
109  return ClickType::inItem;
110  }
111  catch (...) {}
112  return Item::clickType(xx,yy);
113 }
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float iHeight() const
Definition: item.h:224
rotate (x,y) by rot (in degrees) around the origin (x0, y0) can be used for rotating multiple points ...
Definition: geometry.h:44
virtual Type type() const =0
bool flipped(double rotation)
returns if the angle (in degrees) is in the second or third quadrant
Definition: geometry.h:102
virtual ClickType::Type clickType(float x, float y) const
returns the clicktype given a mouse click at x, y.
Definition: item.cc:275
float zoomFactor() const override
Definition: variable.cc:150
double rotation() const
Definition: item.h:211
Here is the call graph for this function:

◆ clone()

virtual VariableBase* minsky::VariableBase::clone ( ) const
overridepure virtual

◆ create()

VariableBase * VariableBase::create ( VariableType::Type  type)
static

Definition at line 116 of file variable.cc.

References minsky::VariableType::constant, minsky::VariableType::flow, minsky::VariableType::integral, minsky::VariableType::parameter, minsky::VariableType::stock, minsky::VariableType::tempFlow, type(), minsky::VariableType::typeName(), and minsky::VariableType::undefined.

Referenced by schema3::MinskyItemFactory::create(), and minsky::VariablePtr::retype().

117 {
118  switch (type)
119  {
120  case undefined: return new Variable<undefined>; break;
121  case constant: return new VarConstant; break;
122  case parameter: return new Variable<parameter>; break;
123  case flow: return new Variable<flow>; break;
124  case stock: return new Variable<stock>; break;
125  case tempFlow: return new Variable<tempFlow>; break;
126  case integral: return new Variable<integral>; break;
127  default:
128  throw error("unknown variable type %s", typeName(type).c_str());
129  }
130 }
virtual Type type() const =0
static std::string typeName(int t)
Definition: variableType.cc:30
Here is the call graph for this function:
Here is the caller graph for this function:

◆ defined()

bool minsky::VariableBase::defined ( ) const
inline
Returns
true if variable is defined (inputWired() || isStock() && controlled)

Definition at line 219 of file variable.h.

References controller, inputWired(), and isStock().

219 {return inputWired() || (isStock() && controller.lock());}
bool inputWired() const
Definition: variable.cc:82
classdesc::Exclude< std::weak_ptr< Item > > controller
reference to a controlling item - eg GodleyIcon, IntOp or a Group if an IOVar.
Definition: variable.h:129
bool isStock() const
Definition: variable.h:206
Here is the call graph for this function:

◆ definition()

std::string VariableBase::definition ( ) const

formula defining this variable

Definition at line 578 of file variable.cc.

References minsky::cminsky(), minsky::VariableType::constant, MathDAG::SystemOfEquations::getDefFromIntVar(), MathDAG::SystemOfEquations::getNodeFromVar(), minsky::VariableType::integral, minsky::VariableType::parameter, and type().

579 {
581  ostringstream o;
582 
583  auto varDAG=system.getNodeFromVar(*this);
584 
586  {
587  if (varDAG && varDAG->rhs && varDAG->type!=VariableType::constant && varDAG->type!=VariableType::integral)
588  o << varDAG->rhs->latex();
589  else return system.getDefFromIntVar(*this).str();
590  }
591 
592  return o.str();
593 }
virtual Type type() const =0
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
Here is the call graph for this function:

◆ destroyFrame()

void VariableBase::destroyFrame ( )
overridevirtual

clean up popup window structures on window close

Reimplemented from minsky::Item.

Definition at line 492 of file variable.cc.

References vValue().

493 {
494  if (auto vv=vValue())
495  vv->csvDialog.destroyFrame();
496 }
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ detailedText() [1/2]

const std::string & VariableBase::detailedText ( ) const
overridevirtual

Reimplemented from minsky::NoteBase.

Definition at line 353 of file variable.cc.

References emptyString, and vValue().

354 {
355  if (auto vv=vValue())
356  return vv->detailedText;
357  return emptyString ;
358 }
static string emptyString
Definition: variable.cc:351
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ detailedText() [2/2]

const std::string & VariableBase::detailedText ( const std::string &  x)
overridevirtual

Reimplemented from minsky::NoteBase.

Definition at line 360 of file variable.cc.

References emptyString, vValue(), and minsky::Item::x().

361 {
362  if (auto vv=vValue())
363  return vv->detailedText=x;
364  return emptyString ;
365 }
virtual float x() const
Definition: item.cc:107
static string emptyString
Definition: variable.cc:351
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ dimLabels()

vector< string > VariableBase::dimLabels ( ) const

labels along each axis

Definition at line 179 of file variable.cc.

References vValue().

180 {
181  if (auto v=vValue()) return v->hypercube().dimLabels();
182  return {};
183 }
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ dims()

vector< unsigned > VariableBase::dims ( ) const

variable's tensor shape

Definition at line 169 of file variable.cc.

References vValue().

170 {
171  try
172  {
173  if (auto v=vValue()) return v->hypercube().dims();
174  }
175  catch (...) {} // ignore any exceptions caused by evaluating RHS.
176  return {};
177 }
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ draw()

void VariableBase::draw ( cairo_t *  cairo) const
overridevirtual

draws the icon onto the given cairo context

Returns
cairo path of icon outline

Reimplemented from minsky::Item.

Definition at line 704 of file variable.cc.

References minsky::VariableCaches::cachedExponent, minsky::VariableCaches::cachedMantissa, minsky::VariableCaches::cachedNameRender, minsky::VariableCaches::cachedTime, minsky::VariableCaches::cachedValue, minsky::cminsky(), minsky::VariableType::constant, MathDAG::cos(), minsky::Item::displayTooltip(), minsky::Item::drawPorts(), minsky::BottomRightResizerItem::drawResizeHandles(), minsky::Item::drawSelected(), engExp(), minsky::expMultiplier(), minsky::flipped(), minsky::Item::iHeight(), ioVar(), minsky::anonymous_namespace{userFunction.cc}::isinf(), minsky::anonymous_namespace{userFunction.cc}::isnan(), minsky::Item::iWidth(), lhs(), local(), M_PI, minsky::Item::m_ports, mantissa(), miniPlot, minsky::NoteBase::mouseFocus, minsky::Item::moveTo(), minsky::Item::onResizeHandles, minsky::VariableType::parameter, minsky::Item::rotation(), minsky::Item::rotationAsRadians(), minsky::NoteBase::selected, MathDAG::sin(), minsky::sliderHandleRadius, sliderVisible(), minsky::RungeKutta::t, tooltip(), type(), value(), vValue(), minsky::Rotate::x(), minsky::Item::x(), minsky::Rotate::y(), minsky::Item::y(), and zoomFactor().

Referenced by minsky::RenderVariable::draw(), minsky::PhillipsStock::draw(), and minsky::anonymous_namespace{godleyIcon.cc}::DrawVars::operator()().

705 {
706  auto [angle,flipped]=rotationAsRadians();
707  const float z=zoomFactor();
708 
709  // grab a thread local copy of the renderer caches, as MacOSX does
710  // rendering on a different thread, and this avoids a race condition
711  // when the cache is invalidated
712  auto l_cachedNameRender=cachedNameRender;
713  if (!l_cachedNameRender || cairo!=cachedNameRender->cairoContext())
714  {
715  l_cachedNameRender=cachedNameRender=std::make_shared<RenderVariable>(*this,cairo);
716  l_cachedNameRender->setFontSize(12.0);
717  }
718 
719  // if rotation is in 1st or 3rd quadrant, rotate as
720  // normal, otherwise flip the text so it reads L->R
721  const Rotate r(rotation() + (flipped? 180:0),0,0);
722  l_cachedNameRender->angle=angle+(flipped? M_PI:0);
723 
724  // parameters of icon in userspace (unscaled) coordinates
725  const double w=std::max(l_cachedNameRender->width(), 0.5f*iWidth());
726  const double h=std::max(l_cachedNameRender->height(), 0.5f*iHeight());
727  const double hoffs=l_cachedNameRender->top();
728 
729  unique_ptr<cairo::Path> clipPath;
730  {
731  const CairoSave cs(cairo);
732  cairo_scale(cairo, z,z);
733  cairo_move_to(cairo,r.x(-w+1,-h-hoffs+2), r.y(-w+1,-h-hoffs+2));
734  {
735  const CairoSave cs(cairo);
736  if (local())
737  cairo_set_source_rgb(cairo,0,0,1);
738  l_cachedNameRender->show();
739  }
740 
741  auto vv=vValue();
742  if (miniPlot && vv && vv->size()==1)
743  try
744  {
745  if (cachedTime!=cminsky().t)
746  {
747  cachedTime=cminsky().t;
748  miniPlot->addPt(0,cachedTime,vv->value());
749  miniPlot->setMinMax();
750  }
751  const CairoSave cs(cairo);
752  cairo_translate(cairo,-w,-h);
753  miniPlot->draw(cairo,2*w,2*h);
754  }
755  catch (...) {} // ignore errors in obtaining values
756 
757  // For feature 47
758  try
759  {
760  if (type()!=constant && !ioVar() && vv && vv->size()==1 && vv->idxInRange())
761  {
762  auto l_cachedMantissa=cachedMantissa;
763  auto l_cachedExponent=cachedExponent;
764  if (!l_cachedMantissa || l_cachedMantissa->cairoContext()!=cairo)
765  {
766  l_cachedMantissa=cachedMantissa=make_shared<Pango>(cairo);
767  l_cachedMantissa->setFontSize(6.0);
768  l_cachedExponent=cachedExponent=make_shared<Pango>(cairo);
769  l_cachedExponent->setFontSize(6.0);
770  cachedValue=nan("");
771  }
772 
773  auto val=engExp();
774  if (value()!=cachedValue)
775  {
776  cachedValue=value();
777  if (!isnan(value())) {
778  if (sliderVisible())
779  l_cachedMantissa->setMarkup
780  (mantissa(val,
781  int(1+
782  (vv->sliderStepRel?
783  -log10(vv->maxSliderSteps()):
784  log10(vv->value()/vv->maxSliderSteps())
785  ))));
786  else
787  l_cachedMantissa->setMarkup(mantissa(val));
788  }
789  else if (isinf(value())) { // Display non-zero divide by zero as infinity. For ticket 1155
790  if (signbit(value())) l_cachedMantissa->setMarkup("-∞");
791  else l_cachedMantissa->setMarkup("∞");
792  }
793  else // Display all other NaN cases as ???. For ticket 1155
794  l_cachedMantissa->setMarkup("???");
795  l_cachedExponent->setMarkup(expMultiplier(val.engExp));
796  }
797  l_cachedMantissa->angle=angle+(flipped? M_PI:0);
798 
799  cairo_move_to(cairo,r.x(w-l_cachedMantissa->width()-2,-h-hoffs+2),
800  r.y(w-l_cachedMantissa->width()-2,-h-hoffs+2));
801  l_cachedMantissa->show();
802 
803  if (val.engExp!=0 && !isnan(value())) // Avoid large exponential number in variable value display. For ticket 1155
804  {
805  cairo_move_to(cairo,r.x(w-l_cachedExponent->width()-2,0),r.y(w-l_cachedExponent->width()-2,0));
806  l_cachedExponent->show();
807  }
808  }
809  }
810  catch (...) {} // ignore errors in obtaining values
811 
812  {
813  const cairo::CairoSave cs(cairo);
814  cairo_rotate(cairo, angle);
815  // constants and parameters should be rendered in blue, all others in red
816  switch (type())
817  {
818  case constant: case parameter:
819  cairo_set_source_rgb(cairo,0,0,1);
820  break;
821  default:
822  cairo_set_source_rgb(cairo,1,0,0);
823  break;
824  }
825  cairo_move_to(cairo,-w,-h);
826  if (lhs())
827  cairo_line_to(cairo,-w+2,0);
828  cairo_line_to(cairo,-w,h);
829  cairo_line_to(cairo,w,h);
830  cairo_line_to(cairo,w+2,0);
831  cairo_line_to(cairo,w,-h);
832  cairo_close_path(cairo);
833  clipPath.reset(new cairo::Path(cairo));
834  cairo_stroke(cairo);
835  if (sliderVisible())
836  {
837  // draw slider
838  const CairoSave cs(cairo);
839  cairo_set_source_rgb(cairo,0,0,0);
840  try
841  {
842  cairo_arc(cairo,(flipped?-1.0:1.0)*l_cachedNameRender->handlePos(), (flipped? h: -h), sliderHandleRadius, 0, 2*M_PI);
843  }
844  catch (const error&) {} // handlePos() may throw.
845  cairo_fill(cairo);
846  }
847  }// undo rotation
848 
849  const double x0=z*w, y0=0, x1=-z*w+2, y1=0;
850  const double sa=sin(angle), ca=cos(angle);
851  if (!m_ports.empty())
852  m_ports[0]->moveTo(x()+(x0*ca-y0*sa),
853  y()+(y0*ca+x0*sa));
854  if (m_ports.size()>1)
855  m_ports[1]->moveTo(x()+(x1*ca-y1*sa),
856  y()+(y1*ca+x1*sa));
857  }
858 
859  auto g=group.lock();
860  if (mouseFocus || (ioVar() && g && g->mouseFocus))
861  {
862  const cairo::CairoSave cs(cairo);
863  drawPorts(cairo);
864  displayTooltip(cairo,tooltip());
866  }
867 
868  cairo_new_path(cairo);
869  clipPath->appendToCurrent(cairo);
870  // Rescale size of variable attached to intop. For ticket 94
871  cairo_clip(cairo);
872  if (selected) drawSelected(cairo);
873 }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
std::string expMultiplier(int exp)
void drawPorts(cairo_t *cairo) const
Definition: item.cc:294
Expr sin(const Expr &x)
Definition: expr.h:131
classdesc::Exclude< std::shared_ptr< ecolab::Pango > > cachedExponent
Definition: variable.h:79
Expr cos(const Expr &x)
Definition: expr.h:137
virtual void displayTooltip(cairo_t *, const std::string &) const
display tooltip text, eg on mouseover
Definition: item.cc:398
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float iHeight() const
Definition: item.h:224
bool onResizeHandles
set to true to indicate mouse is ovcaler resize handles
Definition: item.h:175
virtual double value() const override
< set the initial value for this variable
Definition: variable.cc:332
constexpr float sliderHandleRadius
Definition: slider.h:24
std::pair< double, bool > rotationAsRadians() const
return the rotation as radians, and whether rotation should have additional straight angle added for ...
Definition: item.cc:92
rotate (x,y) by rot (in degrees) around the origin (x0, y0) can be used for rotating multiple points ...
Definition: geometry.h:44
const std::string & tooltip() const override
Definition: variable.cc:367
virtual Type type() const =0
bool flipped(double rotation)
returns if the angle (in degrees) is in the second or third quadrant
Definition: geometry.h:102
bool sliderVisible() const
returns true if slider is to be drawn
Definition: variable.cc:544
float zoomFactor() const override
Definition: variable.cc:150
static void drawSelected(cairo_t *cairo)
Definition: item.cc:308
float iWidth() const
Definition: item.h:217
bool ioVar() const override
indicates this is a group I/O variable
Definition: variable.cc:258
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
EngNotation engExp() const
return formatted mantissa and exponent in engineering format
Definition: variable.h:227
ItemPortVector m_ports
Definition: item.h:156
bool selected
true if selected for cut, copy or group operation
Definition: noteBase.h:32
bool mouseFocus
true if target of a mouseover
Definition: noteBase.h:31
std::string mantissa(const EngNotation &e, int digits=3) const
Definition: variable.h:229
classdesc::Exclude< std::shared_ptr< ecolab::Pango > > cachedMantissa
Definition: variable.h:78
classdesc::Exclude< std::shared_ptr< RenderVariable > > cachedNameRender
cached Pango objects
Definition: variable.h:77
double t
time
Definition: rungeKutta.h:57
void moveTo(float x, float y)
Definition: item.cc:256
bool local() const
Definition: variable.cc:196
Definition: group.tcl:84
bool lhs() const
variable is on left hand side of flow calculation
Definition: variable.h:202
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
classdesc::Exclude< std::shared_ptr< ecolab::Plot > > miniPlot
miniature plot feature
Definition: variable.h:110
void drawResizeHandles(cairo_t *cairo) const override
Definition: item.cc:355
double rotation() const
Definition: item.h:211
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enableSlider() [1/2]

bool VariableBase::enableSlider ( ) const

slider parameters

Definition at line 689 of file variable.cc.

References vValue().

Referenced by schema3::Item::Item(), and sliderVisible().

690 {
691  if (auto vv=vValue())
692  return vv->enableSlider;
693  return false;
694 }
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enableSlider() [2/2]

bool VariableBase::enableSlider ( bool  x)

slider parameters

Definition at line 696 of file variable.cc.

References vValue(), and minsky::Item::x().

697 {
698  if (auto vv=vValue())
699  return vv->enableSlider=x;
700  return false;
701 }
virtual float x() const
Definition: item.cc:107
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ engExp()

EngNotation minsky::VariableBase::engExp ( ) const
inline

return formatted mantissa and exponent in engineering format

Definition at line 227 of file variable.h.

References minsky::engExp(), and value().

Referenced by draw(), and minsky::RenderVariable::RenderVariable().

228  {return minsky::engExp(value());}
EngNotation engExp(double value)
return formatted mantissa and exponent in engineering format
virtual double value() const override
< set the initial value for this variable
Definition: variable.cc:332
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensureValueExists()

void VariableBase::ensureValueExists ( VariableValue vv,
const std::string &  name 
) const

ensure an associated variableValue exists

Definition at line 262 of file variable.cc.

References minsky::isValueId(), m_name, minsky::minsky(), minsky::scope(), type(), valueId(), and minsky::Minsky::variableValues.

Referenced by init(), MathDAG::SystemOfEquations::makeDAG(), name(), minsky::VarConstant::name(), and minsky::VarConstant::VarConstant().

263 {
264  string valueId=this->valueId();
265  // disallow blank names
266  if (valueId.length()>1 && valueId.substr(valueId.length()-2)!=":_" &&
267  minsky().variableValues.count(valueId)==0)
268  {
269  assert(isValueId(valueId));
270  // Ensure value of variable is preserved after rename.
271  if (vv==nullptr)
273  first->second->m_scope=minsky::scope(group.lock(),m_name);
274  // Ensure variable names are updated correctly everywhere they appear.
275  else
276  {
277  auto iter=minsky().variableValues.emplace(valueId,VariableValuePtr(type(),*vv)).first->second;
278  iter->name=m_name;
279  iter->m_scope=minsky::scope(group.lock(),m_name);
280  }
281 
282  }
283 }
VariableValues variableValues
Definition: minsky.h:200
size_t scope(const string &name)
extract scope from a qualified variable name
Definition: valueId.cc:83
a shared_ptr that default constructs a default target, and is always valid
virtual Type type() const =0
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
bool isValueId(const string &name)
check that name is a valid valueId (useful for assertions)
Definition: valueId.cc:33
std::string m_name
Definition: variable.h:101
Definition: group.tcl:84
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ exportAsCSV()

void VariableBase::exportAsCSV ( const std::string &  filename,
bool  tabular 
) const

export this variable as a CSV file

Parameters
tabular- if true, the longest dimension is split across columns as a horizontal dimension

Definition at line 472 of file variable.cc.

References minsky::minsky(), name(), value(), valueId(), and minsky::Minsky::variableValues.

473 {
474  auto value=minsky().variableValues.find(valueId());
475  if (value!=minsky().variableValues.end())
476  value->second->exportAsCSV(filename, name(), tabular);
477 }
VariableValues variableValues
Definition: minsky.h:200
virtual double value() const override
< set the initial value for this variable
Definition: variable.cc:332
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
virtual std::string name() const
variable displayed name
Definition: variable.cc:201
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ getDimLabelsPicked()

std::pair<std::string,std::string> minsky::VariableBase::getDimLabelsPicked ( ) const
inline

Definition at line 169 of file variable.h.

References m_dimLabelsPicked.

169 {return m_dimLabelsPicked;}
std::pair< std::string, std::string > m_dimLabelsPicked
Definition: variable.h:103

◆ importFromCSV()

void VariableBase::importFromCSV ( const std::vector< std::string > &  filenames,
const DataSpecSchema spec 
) const

import CSV files, using spec

Definition at line 479 of file variable.cc.

References minsky::loadValueFromCSVFile(), minsky::minsky(), minsky::Minsky::populateMissingDimensionsFromVariable(), minsky::Item::throw_error(), and vValue().

480 {
481  if (auto v=vValue()) {
482  v->csvDialog.spec=spec;
483  if (!filenames.empty())
484  v->csvDialog.url=filenames[0];
485  loadValueFromCSVFile(*v, filenames, v->csvDialog.spec);
487  if (!v->hypercube().dimsAreDistinct())
488  throw_error("Axes of imported data should all have distinct names");
489  }
490 }
void throw_error(const std::string &) const
mark item on canvas, then throw
Definition: item.cc:86
void loadValueFromCSVFile(VariableValue &v, const vector< string > &filenames, const DataSpec &spec)
load a variableValue from a list of files according to data spec
Definition: CSVParser.cc:1058
void populateMissingDimensionsFromVariable(const VariableValue &, bool &incompatibleMessageDisplayed)
populate missing dimensions from a variableValue
Definition: minsky.cc:516
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ init() [1/2]

string VariableBase::init ( ) const

the initial value of this variable

Definition at line 285 of file variable.cc.

References controller, minsky::VariableType::integral, minsky::Item::m_ports, minsky::minsky(), type(), value(), valueId(), minsky::Minsky::variableValues, and vValue().

Referenced by minsky::VarConstant::name(), units(), and minsky::VarConstant::value().

286 {
287  auto value=minsky().variableValues.find(valueId());
288  if (value!=minsky().variableValues.end()) {
289  // set initial value of int var to init value of input to second port. for ticket 1137
290  if (type()==integral)
291  {
292  // find attached integral
293  auto i=dynamic_cast<IntOp*>(controller.lock().get());
294  if (!i && !m_ports[1]->wires().empty())
295  i=dynamic_cast<IntOp*>(&(m_ports[1]->wires()[0]->from()->item()));
296  if (i && i->portsSize()>2 && !i->ports(2).lock()->wires().empty())
297  if (auto lhsVar=i->ports(2).lock()->wires()[0]->from()->item().variableCast())
298  if (auto vv=vValue())
299  if (auto lhsVv=lhsVar->vValue())
300  // Since integral takes initial value from second port, the intVar should have the same intial value.
301  if (vv->init()!=lhsVv->init()) vv->init(lhsVv->init());
302  }
303  return value->second->init();
304  }
305  return "0";
306 }
VariableValues variableValues
Definition: minsky.h:200
virtual double value() const override
< set the initial value for this variable
Definition: variable.cc:332
virtual Type type() const =0
classdesc::Exclude< std::weak_ptr< Item > > controller
reference to a controlling item - eg GodleyIcon, IntOp or a Group if an IOVar.
Definition: variable.h:129
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
ItemPortVector m_ports
Definition: item.h:156
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init() [2/2]

string VariableBase::init ( const std::string &  x)

< return initial value for this variable

Definition at line 308 of file variable.cc.

References minsky::VariableCaches::cachedNameRender, minsky::cminsky(), minsky::VariableType::constant, ensureValueExists(), minsky::VariableType::flow, minsky::VariableValue::init(), minsky::isValueId(), minsky::minsky(), minsky::VariableType::parameter, minsky::VariableValues::resetValue(), type(), minsky::Item::updateBoundingBox(), valueId(), minsky::Minsky::variableValues, and minsky::Item::x().

309 {
310  ensureValueExists(nullptr,"");
311  if (isValueId(valueId()))
312  {
314  val.init(x);
315  // for constant types, we may as well set the current value. See ticket #433. Also ignore errors (for now), as they will reappear at reset time.
316  try
317  {
318  if (type()==constant || type()==parameter ||
319  (type()==flow && !cminsky().definingVar(valueId())))
320  {
322  cachedNameRender.reset(); // for constants
323  }
324  }
325  catch (...)
326  {}
328  }
329  return x;
330 }
void resetValue(VariableValue &) const
reset a give variable value to it&#39;s initial condition, in this context
virtual float x() const
Definition: item.cc:107
VariableValues variableValues
Definition: minsky.h:200
const std::string & init() const
virtual Type type() const =0
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
void ensureValueExists(VariableValue *vv, const std::string &name) const
ensure an associated variableValue exists
Definition: variable.cc:262
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
bool isValueId(const string &name)
check that name is a valid valueId (useful for assertions)
Definition: valueId.cc:33
classdesc::Exclude< std::shared_ptr< RenderVariable > > cachedNameRender
cached Pango objects
Definition: variable.h:77
void updateBoundingBox() override
Definition: item.h:201
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ inputWired()

bool VariableBase::inputWired ( ) const

Definition at line 82 of file variable.cc.

References minsky::Item::ports().

Referenced by defined(), and sliderVisible().

83 {
84  if (auto p=ports(1).lock())
85  return !p->wires().empty();
86  return false;
87 }
virtual std::weak_ptr< Port > ports(std::size_t i) const
callback to be run when item deleted from group
Definition: item.h:180
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertControlled()

void VariableBase::insertControlled ( Selection selection)
overrideprivate

Definition at line 498 of file variable.cc.

References controller, and minsky::Selection::ensureItemInserted().

499 {
500  selection.ensureItemInserted(controller.lock());
501 }
classdesc::Exclude< std::weak_ptr< Item > > controller
reference to a controlling item - eg GodleyIcon, IntOp or a Group if an IOVar.
Definition: variable.h:129
void ensureItemInserted(const ItemPtr &item)
check if item already present, and if not, inserts item delegates to ensureGroupInserted if passed a ...
Definition: selection.cc:60
Here is the call graph for this function:

◆ ioVar()

bool VariableBase::ioVar ( ) const
overridevirtual

indicates this is a group I/O variable

Reimplemented from minsky::Item.

Definition at line 258 of file variable.cc.

References controller.

Referenced by draw(), minsky::RenderVariable::RenderVariable(), and zoomFactor().

259 {return dynamic_cast<Group*>(controller.lock().get());}
classdesc::Exclude< std::weak_ptr< Item > > controller
reference to a controlling item - eg GodleyIcon, IntOp or a Group if an IOVar.
Definition: variable.h:129
Here is the caller graph for this function:

◆ isStock()

bool minsky::VariableBase::isStock ( ) const
inline

Definition at line 206 of file variable.h.

References minsky::VariableType::integral, minsky::VariableType::stock, and type().

Referenced by defined(), and units().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lhs()

bool minsky::VariableBase::lhs ( ) const
inline

variable is on left hand side of flow calculation

Definition at line 202 of file variable.h.

References minsky::VariableType::flow, minsky::VariableType::tempFlow, and type().

Referenced by draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ local()

bool VariableBase::local ( ) const
Returns
true if variable is local to its group

Definition at line 196 of file variable.cc.

References minsky::Minsky::canvas, minsky::cminsky(), m_name, and minsky::Canvas::model.

Referenced by draw().

197 {
198  return m_name[0]!=':' && group.lock()!=cminsky().canvas.model;
199 }
Model model
Definition: canvas.h:103
Canvas canvas
Definition: minsky.h:256
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
std::string m_name
Definition: variable.h:101
Definition: group.tcl:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mantissa()

std::string minsky::VariableBase::mantissa ( const EngNotation e,
int  digits = 3 
) const
inline

Definition at line 229 of file variable.h.

References minsky::mantissa(), and value().

Referenced by draw(), and minsky::RenderVariable::RenderVariable().

230  {return minsky::mantissa(value(),e, digits);}
virtual double value() const override
< set the initial value for this variable
Definition: variable.cc:332
std::string mantissa(double value, const EngNotation &, int digits=3)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ miniPlotEnabled() [1/2]

bool minsky::VariableBase::miniPlotEnabled ( ) const
inline

Definition at line 242 of file variable.h.

References miniPlot.

Referenced by resetMiniPlot().

242 {return bool(miniPlot);}
classdesc::Exclude< std::shared_ptr< ecolab::Plot > > miniPlot
miniature plot feature
Definition: variable.h:110
Here is the caller graph for this function:

◆ miniPlotEnabled() [2/2]

bool VariableBase::miniPlotEnabled ( bool  enabled)

Definition at line 595 of file variable.cc.

References miniPlot.

596 {
597  if (enabled)
598  {
599  miniPlot=make_shared<ecolab::Plot>();
600  miniPlot->plotType=ecolab::Plot::PlotType::bar;
601  }
602  else
603  miniPlot=nullptr;
604  return enabled;
605 }
classdesc::Exclude< std::shared_ptr< ecolab::Plot > > miniPlot
miniature plot feature
Definition: variable.h:110

◆ name() [1/2]

string VariableBase::name ( ) const
virtual

variable displayed name

Reimplemented in minsky::VarConstant.

Definition at line 201 of file variable.cc.

References m_name.

Referenced by exportAsCSV(), MathDAG::SystemOfEquations::makeDAG(), name(), minsky::GroupItems::renameVar(), minsky::RenderVariable::RenderVariable(), toggleLocal(), units(), and minsky::Variable< VariableType::constant >::Variable().

202 {
203  if (m_name==":_") return "";
204  // hide any leading ':' in upper level
205  if (m_name[0]==':')
206  {
207  return m_name.substr(1);
208  }
209  return utf_to_utf<char>(m_name);
210 }
std::string m_name
Definition: variable.h:101
Here is the caller graph for this function:

◆ name() [2/2]

string VariableBase::name ( const std::string &  nm)
virtual

variable displayed name

Reimplemented in minsky::VarConstant.

Definition at line 233 of file variable.cc.

References minsky::Item::bb, minsky::VariableCaches::cachedNameRender, minsky::canonicalName(), controller, ensureValueExists(), m_canonicalName, m_name, name(), anonymous_namespace{variable.cc}::quoteLaTeX(), anonymous_namespace{variable.cc}::specialLatex, minsky::BoundingBox::update(), valueId(), and vValue().

234 {
235  // cowardly refuse to set a blank name
236  if (name.empty() || name==":") return name;
237 
238  // check if we need to quote certain characters that have meaning in LaTeX
239  for (auto p=name.find_first_of(specialLatex); p!=string::npos;
240  p=name.find_first_of(specialLatex,p+1))
241  if (p==0||name[p-1]!='\\')
242  return this->name(quoteLaTeX(name));
243 
244  // Ensure value of variable is preserved after rename. For ticket 1106.
245  auto tmpVV=vValue();
246  m_name=name;
248  ensureValueExists(tmpVV.get(),name);
249  assert(vValue()->valueId()==valueId());
250  cachedNameRender.reset();
251  bb.update(*this); // adjust bounding box for new name - see ticket #704
252  if (auto controllingItem=controller.lock())
253  // integrals in particular may have had their size changed with intVar changing name
254  controllingItem->updateBoundingBox();
255  return this->name();
256 }
string quoteLaTeX(const std::string &x)
Definition: variable.cc:216
BoundingBox bb
canvas bounding box.
Definition: item.h:195
void update(const Item &x)
Definition: item.cc:46
classdesc::Exclude< std::weak_ptr< Item > > controller
reference to a controlling item - eg GodleyIcon, IntOp or a Group if an IOVar.
Definition: variable.h:129
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
void ensureValueExists(VariableValue *vv, const std::string &name) const
ensure an associated variableValue exists
Definition: variable.cc:262
std::string m_canonicalName
latex processed and active stripped version of name
Definition: variable.h:102
string canonicalName(const string &name)
convert a raw name into a canonical name - this is not idempotent.
Definition: valueId.cc:63
virtual std::string name() const
variable displayed name
Definition: variable.cc:201
std::string m_name
Definition: variable.h:101
classdesc::Exclude< std::shared_ptr< RenderVariable > > cachedNameRender
cached Pango objects
Definition: variable.h:77
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ numPorts()

◆ onKeyPress()

bool VariableBase::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 561 of file variable.cc.

References minsky::minsky(), minsky::Minsky::requestReset(), and vValue().

562 {
563  switch (keySym)
564  {
565  case 0xff52: case 0xff53: //Right, Up
566  if (auto vv=vValue()) vv->incrSlider(1);
567  if (!minsky().running) minsky().requestReset();
568  return true;
569  case 0xff51: case 0xff54: //Left, Down
570  if (auto vv=vValue()) vv->incrSlider(-1);
571  if (!minsky().running) minsky().requestReset();
572  return true;
573  default:
574  return false;
575  }
576 }
void requestReset()
Definition: minsky.cc:467
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ onMouseMotion()

bool VariableBase::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 613 of file variable.cc.

References MathDAG::cos(), minsky::RungeKutta::evalEquations(), minsky::Item::iWidth(), M_PI, minsky::minsky(), minsky::Minsky::pushHistory(), minsky::Minsky::requestReset(), minsky::Item::rotation(), vValue(), minsky::RenderVariable::width(), minsky::Item::x(), and zoomFactor().

614 {
615  if (auto vv=vValue())
616  {
617  const RenderVariable rv(*this);
618  const double rw=fabs(zoomFactor()*(rv.width()<iWidth()? 0.5*iWidth() : rv.width())*cos(rotation()*M_PI/180));
619  const double sliderPos=(x-this->x())* (vv->sliderMax-vv->sliderMin)/rw+0.5*(vv->sliderMin+vv->sliderMax);
620  const double sliderHatch=sliderPos-fmod(sliderPos,vv->sliderStep); // matches slider's hatch marks to sliderStep value. for ticket 1258
621  vv->sliderSet(sliderHatch);
622  }
623  // push History to prevent an unnecessary reset when
624  // adjusting the slider whilst paused. See ticket #812
625  minsky().pushHistory();
626  if (minsky().reset_flag())
627  minsky().requestReset();
628  minsky().evalEquations();
629  return true;
630 }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
Expr cos(const Expr &x)
Definition: expr.h:137
void requestReset()
Definition: minsky.cc:467
virtual float x() const
Definition: item.cc:107
bool pushHistory()
push current model state onto history if it differs from previous
Definition: minsky.cc:1265
float zoomFactor() const override
Definition: variable.cc:150
float width() const
Definition: item.h:242
float iWidth() const
Definition: item.h:217
void evalEquations(double result[], double, const double vars[])
Definition: rungeKutta.cc:248
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
double rotation() const
Definition: item.h:211
Here is the call graph for this function:

◆ rawName()

const std::string& minsky::VariableBase::rawName ( ) const
inline

accessor for the name member (may differ from name() with top level variables)

Definition at line 150 of file variable.h.

References m_name.

Referenced by schema3::Item::Item(), and minsky::GroupItems::renameVar().

150 {return m_name;}
std::string m_name
Definition: variable.h:101
Here is the caller graph for this function:

◆ resetMiniPlot()

void VariableBase::resetMiniPlot ( )

Definition at line 607 of file variable.cc.

References miniPlot, and miniPlotEnabled().

608 {
609  if (miniPlotEnabled())
610  miniPlot->clear();
611 }
bool miniPlotEnabled() const
Definition: variable.h:242
classdesc::Exclude< std::shared_ptr< ecolab::Plot > > miniPlot
miniature plot feature
Definition: variable.h:110
Here is the call graph for this function:

◆ resize()

void VariableBase::resize ( const LassoBox b)
overridevirtual

resize this item on the canvas

Reimplemented from minsky::Item.

Definition at line 875 of file variable.cc.

References minsky::Item::iHeight(), minsky::Item::iWidth(), minsky::Item::moveTo(), minsky::LassoBox::x0, minsky::LassoBox::x1, minsky::LassoBox::y0, minsky::LassoBox::y1, and zoomFactor().

876 {
877  const float invZ=1/zoomFactor();
878  moveTo(0.5*(b.x0+b.x1), 0.5*(b.y0+b.y1));
879  iWidth(abs(b.x1-b.x0)*invZ);
880  iHeight(abs(b.y1-b.y0)*invZ);
881 }
float iHeight() const
Definition: item.h:224
float zoomFactor() const override
Definition: variable.cc:150
float iWidth() const
Definition: item.h:217
float x0
Definition: lasso.h:30
float y1
Definition: lasso.h:30
float x1
Definition: lasso.h:30
void moveTo(float x, float y)
Definition: item.cc:256
float y0
Definition: lasso.h:30
Here is the call graph for this function:

◆ retype()

void VariableBase::retype ( VariableType::Type  type)

attempt to replace this variable with variable of type.

Exceptions
ifnot possible

Definition at line 132 of file variable.cc.

References minsky::Minsky::convertVarType(), minsky::minsky(), minsky::VariablePtr::retype(), type(), valueId(), and vValue().

133 {
134  if (type==this->type()) return; // nothing to do
135  if (auto vv=vValue())
136  if (type==vv->type())
137  if (auto g=group.lock())
138  for (auto& i: g->items)
139  if (i.get()==this)
140  {
141  VariablePtr vp{i};
142  vp.retype(type);
143  i=vp;
144  return;
145  }
147 }
void retype(VariableBase::Type type)
changes type of variable to type
Definition: variable.cc:516
virtual Type type() const =0
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
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::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ setDimLabelsPicked()

std::pair<std::string,std::string> minsky::VariableBase::setDimLabelsPicked ( const std::string &  dimLabel1,
const std::string &  dimLabel2 
)
inline

Definition at line 170 of file variable.h.

References m_dimLabelsPicked.

170  {
171  m_dimLabelsPicked=std::make_pair(dimLabel1,dimLabel2);
172  return m_dimLabelsPicked;
173  }
std::pair< std::string, std::string > m_dimLabelsPicked
Definition: variable.h:103

◆ setUnits()

void VariableBase::setUnits ( const std::string &  x) const

Definition at line 464 of file variable.cc.

References minsky::isValueId(), minsky::minsky(), valueId(), minsky::Minsky::variableValues, and minsky::Item::x().

465 {
466  if (isValueId(valueId()))
467  minsky().variableValues[valueId()]->units=Units(x);
468 }
virtual float x() const
Definition: item.cc:107
VariableValues variableValues
Definition: minsky.h:200
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
represents the units (in sense of dimensional analysis) of a variable.
Definition: units.h:34
bool isValueId(const string &name)
check that name is a valid valueId (useful for assertions)
Definition: valueId.cc:33
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ sliderMax() [1/2]

double VariableBase::sliderMax ( ) const

slider parameters

Definition at line 647 of file variable.cc.

References vValue().

Referenced by schema3::Item::Item().

648 {
649  if (auto vv=vValue())
650  return vv->sliderMax;
651  return 0;
652 }
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sliderMax() [2/2]

double VariableBase::sliderMax ( double  x) const

slider parameters

Definition at line 654 of file variable.cc.

References vValue(), and minsky::Item::x().

655 {
656  if (auto vv=vValue())
657  return vv->sliderMax=x;
658  return 0;
659 }
virtual float x() const
Definition: item.cc:107
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ sliderMin() [1/2]

double VariableBase::sliderMin ( ) const

slider parameters

Definition at line 632 of file variable.cc.

References vValue().

Referenced by schema3::Item::Item().

633 {
634  if (auto vv=vValue())
635  return vv->sliderMin;
636  return 0;
637 }
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sliderMin() [2/2]

double VariableBase::sliderMin ( double  x) const

slider parameters

Definition at line 640 of file variable.cc.

References vValue(), and minsky::Item::x().

641 {
642  if (auto vv=vValue())
643  return vv->sliderMin=x;
644  return 0;
645 }
virtual float x() const
Definition: item.cc:107
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ sliderStep() [1/2]

double VariableBase::sliderStep ( ) const

slider parameters

Definition at line 661 of file variable.cc.

References vValue().

Referenced by schema3::Item::Item().

662 {
663  if (auto vv=vValue())
664  return vv->sliderStep;
665  return 0;
666 }
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sliderStep() [2/2]

double VariableBase::sliderStep ( double  x) const

slider parameters

Definition at line 668 of file variable.cc.

References vValue(), and minsky::Item::x().

669 {
670  if (auto vv=vValue())
671  return vv->sliderStep=x;
672  return 0;
673 }
virtual float x() const
Definition: item.cc:107
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ sliderStepRel() [1/2]

bool VariableBase::sliderStepRel ( ) const

slider parameters

Definition at line 675 of file variable.cc.

References vValue().

Referenced by schema3::Item::Item().

676 {
677  if (auto vv=vValue())
678  return vv->sliderStepRel;
679  return false;
680 }
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sliderStepRel() [2/2]

bool VariableBase::sliderStepRel ( bool  x) const

slider parameters

Definition at line 682 of file variable.cc.

References vValue(), and minsky::Item::x().

683  {
684  if (auto vv=vValue())
685  return vv->sliderStepRel=x;
686  return false;
687 }
virtual float x() const
Definition: item.cc:107
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ sliderVisible()

bool VariableBase::sliderVisible ( ) const

returns true if slider is to be drawn

Definition at line 544 of file variable.cc.

References minsky::cminsky(), minsky::Minsky::definingVar(), enableSlider(), minsky::VariableType::flow, inputWired(), minsky::VariableType::parameter, type(), valueId(), and vValue().

Referenced by draw().

545 {
546  auto vv=vValue();
547  return enableSlider() &&
548  ((!vv && type()==parameter) ||
549  (vv && vv->size()==1 &&
550  (type()==parameter ||
551  // !inputWired() short circuits the more expensive definingVar operation.
552  (type()==flow && !inputWired() && !cminsky().definingVar(valueId())))));
553 }
bool inputWired() const
Definition: variable.cc:82
virtual Type type() const =0
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
VariablePtr definingVar(const std::string &valueId) const
returns reference to variable defining (ie input wired) for valueId
Definition: minsky.cc:205
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
bool enableSlider() const
slider parameters
Definition: variable.cc:689
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:
Here is the caller graph for this function:

◆ temp()

bool minsky::VariableBase::temp ( ) const
inline

variable is temporary

Definition at line 204 of file variable.h.

References minsky::VariableType::tempFlow, type(), and minsky::VariableType::undefined.

Here is the call graph for this function:

◆ toggleLocal()

void minsky::VariableBase::toggleLocal ( )
inline

toggle local status

Definition at line 140 of file variable.h.

References m_name, and name().

140 {name(m_name[0]==':'? m_name.substr(1): ':'+m_name);}
virtual std::string name() const
variable displayed name
Definition: variable.cc:201
std::string m_name
Definition: variable.h:101
Here is the call graph for this function:

◆ tooltip() [1/2]

const std::string & VariableBase::tooltip ( ) const
overridevirtual

Reimplemented from minsky::NoteBase.

Definition at line 367 of file variable.cc.

References emptyString, and vValue().

Referenced by draw().

368 {
369  if (auto vv=vValue())
370  return vv->tooltip;
371  return emptyString ;
372 }
static string emptyString
Definition: variable.cc:351
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tooltip() [2/2]

const std::string & VariableBase::tooltip ( const std::string &  x)
overridevirtual

Reimplemented from minsky::NoteBase.

Definition at line 374 of file variable.cc.

References emptyString, vValue(), and minsky::Item::x().

375 {
376  if (auto vv=vValue())
377  return vv->tooltip=x;
378  return emptyString ;
379 }
virtual float x() const
Definition: item.cc:107
static string emptyString
Definition: variable.cc:351
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:

◆ type()

virtual Type minsky::VariableBase::type ( ) const
pure virtual

◆ units() [1/2]

Units VariableBase::units ( bool  check) const
overridevirtual

sets/gets the units associated with this type

Reimplemented from minsky::Item.

Definition at line 384 of file variable.cc.

References minsky::cminsky(), controller, init(), isStock(), minsky::GroupItems::items, minsky::Item::m_ports, minsky::minsky(), minsky::Minsky::model, minsky::FlowCoef::name, name(), minsky::VariableValues::resetUnitsCache(), stockVarsPassed, minsky::Units::str(), minsky::Item::throw_error(), units(), unitsCtr, minsky::valueId(), valueId(), minsky::Minsky::variableValues, and varsPassed.

385 {
387  // we allow possible traversing twice, to allow
388  // stock variable to break the cycle
389  if (unitsCtr-stockVarsPassed>=1)
390  {
391  if (check)
392  throw_error("Cycle detected on wiring network");
393  else
394  return {};
395  }
396 
397  auto it=minsky().variableValues.find(valueId());
398  if (it!=minsky().variableValues.end())
399  {
400  auto& vv=it->second;
401  if (vv->unitsCached) return vv->units;
402 
403 
404  const IncrDecrCounter ucIdc(unitsCtr);
405  const IncrDecrCounter vpIdc(varsPassed);
406  // use a unique ptr here to only increment counter inside a stockVar
407  unique_ptr<IncrDecrCounter> svp;
408 
409  if (isStock()) // we use user defined units
410  {
411  if (unitsCtr==1)
412  {
413  svp.reset(new IncrDecrCounter(stockVarsPassed));
414  // check that input units match output units
415  Units units;
416  if (auto i=dynamic_cast<IntOp*>(controller.lock().get()))
417  units=i->units(check);
418  else if (auto g=dynamic_cast<GodleyIcon*>(controller.lock().get()))
419  units=g->stockVarUnits(name(),check);
420  else // I/O variable
421  units=vv->units;
422  if (check && units.str()!=vv->units.str())
423  {
424  if (auto i=controller.lock())
425  i->throw_error("Inconsistent units "+units.str()+"≠"+vv->units.str());
426  }
427 
428  if (check && controller.lock())
429  {
430  const FlowCoef fc(init());
431  if (!fc.name.empty())
432  {
433  // extract the valueid corresponding to the initialisation variable
434  auto vid=minsky::valueId(vv->m_scope.lock(), fc.name);
435  // find the first variable matching vid, and check that the units match
436  if (auto initVar=cminsky().model->findAny
437  (&GroupItems::items, [&vid](const ItemPtr& i){
438  if (auto v=i->variableCast())
439  return v->valueId()==vid;
440  return false;}))
441  if (units!=initVar->units(check))
442  throw_error("Inconsistent units in initial conditions");
443  }
444  }
445  }
446  }
447  else
448  // updates units in the process
449  if (m_ports.size()>1 && !m_ports[1]->wires().empty())
450  {
451  assert(m_ports[1]->wires()[0]->from());
452  vv->units=m_ports[1]->wires()[0]->from()->item().units(check);
453  }
454  else if (auto v=cminsky().definingVar(valueId()))
455  vv->units=v->units(check);
456 
457  vv->units.normalise();
458  vv->unitsCached=true;
459  return vv->units;
460  }
461  return Units();
462 }
Units units() const
Definition: variable.h:195
std::string str() const
Definition: variableType.cc:33
static int stockVarsPassed
for detecting reentrancy in units()
Definition: variable.h:105
VariableValues variableValues
Definition: minsky.h:200
exception-safe increment/decrement of a counter in a block
Definition: variable.h:56
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
int unitsCtr
for detecting reentrancy in units()
Definition: variable.h:104
classdesc::Exclude< std::weak_ptr< Item > > controller
reference to a controlling item - eg GodleyIcon, IntOp or a Group if an IOVar.
Definition: variable.h:129
static int varsPassed
for caching units calculation factory method
Definition: variable.h:116
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
represents the units (in sense of dimensional analysis) of a variable.
Definition: units.h:34
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
ItemPortVector m_ports
Definition: item.h:156
represents a numerical coefficient times a variable (a "flow")
Definition: flowCoef.h:27
bool isStock() const
Definition: variable.h:206
std::string init() const
the initial value of this variable
Definition: variable.cc:285
virtual std::string name() const
variable displayed name
Definition: variable.cc:201
GroupPtr model
Definition: minsky.h:255
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ units() [2/2]

Units minsky::VariableBase::units ( ) const
inline

Definition at line 195 of file variable.h.

References units().

Referenced by minsky::PhillipsStock::draw(), units(), and unitsStr().

195 {return units(false);}
Units units() const
Definition: variable.h:195
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unitsStr()

std::string minsky::VariableBase::unitsStr ( ) const
inline

Definition at line 197 of file variable.h.

References minsky::Units::str(), and units().

197 {return units().str();}
Units units() const
Definition: variable.h:195
std::string str() const
Definition: variableType.cc:33
Here is the call graph for this function:

◆ value() [1/2]

double VariableBase::value ( const double &  x)
virtual

< set the initial value for this variable

current value associated with this variable

Reimplemented in minsky::VarConstant.

Definition at line 340 of file variable.cc.

References minsky::VariableCaches::cachedNameRender, minsky::VariableType::constant, minsky::isValueId(), m_name, minsky::minsky(), type(), valueId(), minsky::Minsky::variableValues, and minsky::Item::x().

341 {
342  if (!m_name.empty() && isValueId(valueId()))
343  {
344  (*minsky().variableValues[valueId()])[0]=x;
345  if (type()==constant)
346  cachedNameRender.reset();
347  }
348  return x;
349 }
virtual float x() const
Definition: item.cc:107
VariableValues variableValues
Definition: minsky.h:200
virtual Type type() const =0
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
bool isValueId(const string &name)
check that name is a valid valueId (useful for assertions)
Definition: valueId.cc:33
std::string m_name
Definition: variable.h:101
classdesc::Exclude< std::shared_ptr< RenderVariable > > cachedNameRender
cached Pango objects
Definition: variable.h:77
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ value() [2/2]

double VariableBase::value ( ) const
overridevirtual

< set the initial value for this variable

current value associated with this variable

Reimplemented from minsky::Item.

Definition at line 332 of file variable.cc.

References minsky::cminsky(), valueId(), and minsky::Minsky::variableValues.

Referenced by minsky::PhillipsStock::draw(), draw(), engExp(), exportAsCSV(), init(), and mantissa().

333 {
334  auto& vvs=minsky::cminsky().variableValues;
335  auto v=vvs.find(valueId());
336  if (v==vvs.end() || !v->second) return 0;
337  return v->second->value();
338 }
VariableValues variableValues
Definition: minsky.h:200
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
Here is the call graph for this function:
Here is the caller graph for this function:

◆ valueId()

string VariableBase::valueId ( ) const
virtual

string used to link to the VariableValue associated with this

Reimplemented in minsky::VarConstant.

Definition at line 186 of file variable.cc.

References m_name, and minsky::valueId().

Referenced by ensureValueExists(), exportAsCSV(), MathDAG::SystemOfEquations::getDefFromIntVar(), init(), MathDAG::SubexpressionCache::key(), MathDAG::SystemOfEquations::makeDAG(), name(), schema3::PhillipsDiagram::populatePhillipsDiagram(), retype(), setUnits(), sliderVisible(), units(), value(), and vValue().

187 {
188  return minsky::valueId(group.lock(), m_name);
189 }
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
std::string m_name
Definition: variable.h:101
Definition: group.tcl:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ valueIdInCurrentScope()

std::string VariableBase::valueIdInCurrentScope ( const std::string &  nm) const

returns valueId for nm. If nm is not qualified, this variable's scope is used

Definition at line 191 of file variable.cc.

References minsky::valueId().

192 {
193  return minsky::valueId(group.lock(), nm);
194 }
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:

◆ variableCast() [1/2]

const VariableBase* minsky::VariableBase::variableCast ( ) const
inlineoverride

Definition at line 132 of file variable.h.

132 {return this;}

◆ variableCast() [2/2]

VariableBase* minsky::VariableBase::variableCast ( )
inlineoverride

Definition at line 133 of file variable.h.

133 {return this;}

◆ visible()

bool VariableBase::visible ( ) const
overridevirtual

whether this item is visible on the canvas.

Reimplemented from minsky::Item.

Definition at line 535 of file variable.cc.

References controller, and minsky::Item::visible().

536 {
537  auto g=group.lock();
538  //toplevel i/o items always visible
539  if ((!g || !g->group.lock()) && g==controller.lock()) return true;
540  if (controller.lock()) return false;
541  return Item::visible();
542 }
virtual bool visible() const
whether this item is visible on the canvas.
Definition: item.cc:250
classdesc::Exclude< std::weak_ptr< Item > > controller
reference to a controlling item - eg GodleyIcon, IntOp or a Group if an IOVar.
Definition: variable.h:129
Definition: group.tcl:84
Here is the call graph for this function:

◆ vValue()

shared_ptr< VariableValue > VariableBase::vValue ( ) const

variableValue associated with this. nullptr if not associated with a variableValue

Definition at line 161 of file variable.cc.

References minsky::cminsky(), minsky::minsky(), valueId(), and minsky::Minsky::variableValues.

Referenced by adjustSliderBounds(), destroyFrame(), detailedText(), dimLabels(), dims(), draw(), enableSlider(), minsky::RenderVariable::handlePos(), importFromCSV(), init(), schema3::Item::Item(), MathDAG::SystemOfEquations::makeDAG(), name(), onKeyPress(), onMouseMotion(), schema3::Item::packTensorInit(), retype(), sliderMax(), sliderMin(), sliderStep(), sliderStepRel(), sliderVisible(), and tooltip().

162 {
163  auto vv=cminsky().variableValues.find(valueId());
164  if (vv!=minsky().variableValues.end())
165  return vv->second;
166  return {};
167 }
VariableValues variableValues
Definition: minsky.h:200
virtual std::string valueId() const
string used to link to the VariableValue associated with this
Definition: variable.cc:186
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zoomFactor()

float VariableBase::zoomFactor ( ) const
overridevirtual

Reimplemented from minsky::Item.

Definition at line 150 of file variable.cc.

References controller, ioVar(), and minsky::Item::zoomFactor().

Referenced by clickType(), minsky::PhillipsStock::draw(), draw(), onMouseMotion(), and resize().

151 {
152  if (ioVar())
153  if (auto g=group.lock())
154  return g->edgeScale();
155  // scale by GodleyIcon::scaleFactor if part of an Godley icon
156  if (auto g=dynamic_cast<GodleyIcon*>(controller.lock().get()))
157  return g->scaleFactor() * Item::zoomFactor();
158  return Item::zoomFactor();
159 }
virtual float zoomFactor() const
Definition: item.cc:121
classdesc::Exclude< std::weak_ptr< Item > > controller
reference to a controlling item - eg GodleyIcon, IntOp or a Group if an IOVar.
Definition: variable.h:129
bool ioVar() const override
indicates this is a group I/O variable
Definition: variable.cc:258
Definition: group.tcl:84
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ minsky::SchemaHelper

friend struct minsky::SchemaHelper
friend

Definition at line 97 of file variable.h.

Member Data Documentation

◆ controller

classdesc::Exclude<std::weak_ptr<Item> > minsky::VariableBase::controller

◆ m_canonicalName

std::string minsky::VariableBase::m_canonicalName
private

latex processed and active stripped version of name

Definition at line 102 of file variable.h.

Referenced by canonicalName(), and name().

◆ m_dimLabelsPicked

std::pair<std::string,std::string> minsky::VariableBase::m_dimLabelsPicked
private

Definition at line 103 of file variable.h.

Referenced by getDimLabelsPicked(), and setDimLabelsPicked().

◆ m_name

std::string minsky::VariableBase::m_name
private

Definition at line 101 of file variable.h.

Referenced by ensureValueExists(), local(), name(), rawName(), toggleLocal(), value(), and valueId().

◆ miniPlot

classdesc::Exclude<std::shared_ptr<ecolab::Plot> > minsky::VariableBase::miniPlot
private

miniature plot feature

Definition at line 110 of file variable.h.

Referenced by draw(), miniPlotEnabled(), and resetMiniPlot().

◆ stockVarsPassed

int VariableBase::stockVarsPassed =0
staticprivate

for detecting reentrancy in units()

Definition at line 105 of file variable.h.

Referenced by units().

◆ unitsCtr

int minsky::VariableBase::unitsCtr =0
mutableprivate

for detecting reentrancy in units()

Definition at line 104 of file variable.h.

Referenced by units().

◆ varsPassed

int VariableBase::varsPassed =0
static

for caching units calculation factory method

Definition at line 116 of file variable.h.

Referenced by units().


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