Minsky
minsky::Wire Class Reference

#include <wire.h>

Inheritance diagram for minsky::Wire:
Inheritance graph
Collaboration diagram for minsky::Wire:
Collaboration graph

Public Member Functions

 Wire ()
 
 Wire (const std::weak_ptr< Port > &from, const std::weak_ptr< Port > &to, const std::vector< float > &a_coords=std::vector< float >())
 
 ~Wire ()
 
std::shared_ptr< Portfrom () const
 
std::shared_ptr< Portto () const
 
void moveToPorts (const std::shared_ptr< Port > &from, const std::shared_ptr< Port > &to)
 switch ports this wire links to More...
 
void storeCairoCoords (cairo_t *cairo) const
 stash all the internal cairo coordinates along a wire More...
 
void draw (cairo_t *cairo, bool reverseArrow=false) const
 draw this item into a cairo context More...
 
std::vector< float > coords () const
 display coordinates More...
 
std::vector< float > coords (const std::vector< float > &coords)
 
bool near (float x, float y) const
 returns true if coordinates are near this wire More...
 
unsigned nearestHandle (float x, float y)
 returns the index into the coordinate list if x,y is close to it. Otherwise inserts midpoints and returns that. Wire endpoints are not returned More...
 
void insertHandle (unsigned position, float x, float y)
 
void deleteHandle (float x, float y)
 
void editHandle (unsigned position, float x, float y)
 
void straighten ()
 
bool visible () const
 whether this wire is visible or not More...
 
void moveIntoGroup (Group &dest)
 move this from its group into dest More...
 
void split ()
 splits wires crossing group boundaries More...
 
Units units (bool) const
 units (dimensional analysis) of data flowing across wire 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 void adjustBookmark () const
 adjust bookmark list to reflect current configuration More...
 
virtual void updateBoundingBox ()
 
virtual ~NoteBase ()=default
 
- Public Member Functions inherited from minsky::WireAccessor
 WireAccessor ()
 

Private Member Functions

 CLASSDESC_ACCESS (Wire)
 

Private Attributes

std::vector< float > m_coords
 
std::weak_ptr< Portm_from
 ports this wire connects More...
 
std::weak_ptr< Portm_to
 
int unitsCtr =0
 for detecting wiring loops in units() More...
 
std::vector< std::pair< float, float > > cairoCoords
 contains all the internal cairo coordinates used to draw a wire More...
 

Static Private Attributes

static constexpr float handleRadius =3
 

Friends

struct SchemaHelper
 

Additional Inherited Members

- 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...
 

Detailed Description

Definition at line 43 of file wire.h.

Constructor & Destructor Documentation

◆ Wire() [1/2]

minsky::Wire::Wire ( )
inline

Definition at line 58 of file wire.h.

Referenced by split().

58 {}
Here is the caller graph for this function:

◆ Wire() [2/2]

minsky::Wire::Wire ( const std::weak_ptr< Port > &  from,
const std::weak_ptr< Port > &  to,
const std::vector< float > &  a_coords = std::vector<float>() 
)

Definition at line 90 of file wire.cc.

References coords(), from(), m_from, m_to, and to().

91  :
92  m_from(from), m_to(to)
93  {
94  if (!from.lock() || !to.lock()) throw error("wiring defunct ports");
95  if (from.lock()->input() || !to.lock()->input()) throw error("invalid ports for wire");
96  coords(a_coords);
97  m_from.lock()->m_wires.push_back(this);
98  m_to.lock()->m_wires.push_back(this);
99  }
std::shared_ptr< Port > from() const
Definition: wire.h:63
std::shared_ptr< Port > to() const
Definition: wire.h:64
std::vector< float > coords() const
display coordinates
Definition: wire.cc:45
std::weak_ptr< Port > m_to
Definition: wire.h:51
std::weak_ptr< Port > m_from
ports this wire connects
Definition: wire.h:51
Here is the call graph for this function:

◆ ~Wire()

minsky::Wire::~Wire ( )

Definition at line 101 of file wire.cc.

References from(), and to().

102  {
103  if (auto toPort=to())
104  toPort->eraseWire(this);
105  if (auto fromPort=from())
106  fromPort->eraseWire(this);
107  }
std::shared_ptr< Port > from() const
Definition: wire.h:63
std::shared_ptr< Port > to() const
Definition: wire.h:64
Here is the call graph for this function:

Member Function Documentation

◆ CLASSDESC_ACCESS()

minsky::Wire::CLASSDESC_ACCESS ( Wire  )
private

◆ coords() [1/2]

vector< float > minsky::Wire::coords ( ) const

display coordinates

Definition at line 45 of file wire.cc.

References f, from(), m_coords, minsky::sqr(), MathDAG::sqrt(), and to().

Referenced by coords(), deleteHandle(), draw(), editHandle(), insertHandle(), near(), nearestHandle(), schema3::populateWire(), and Wire().

46  {
47  vector<float> c;
48  assert(from() && to());
49  assert(m_coords.size() % 2 == 0);
50  if (auto f=from())
51  if (auto t=to())
52  {
53  c.push_back(f->x());
54  c.push_back(f->y());
55  const float d=sqrt
56  (sqr(f->x()-t->x())+sqr(f->y()-t->y()));
57 
58  for (size_t i=0; m_coords.size()>1 && i<m_coords.size()-1; i+=2)
59  {
60  c.push_back(f->x() + d*m_coords[i]);
61  c.push_back(f->y() + d*m_coords[i+1]);
62  }
63  c.push_back(t->x());
64  c.push_back(t->y());
65  }
66  return c;
67  }
function f
Definition: canvas.m:1
std::shared_ptr< Port > from() const
Definition: wire.h:63
Expr sqrt(const Expr &x)
Definition: expr.h:154
std::shared_ptr< Port > to() const
Definition: wire.h:64
std::vector< float > m_coords
Definition: wire.h:49
T sqr(T x)
Definition: geometry.h:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ coords() [2/2]

vector< float > minsky::Wire::coords ( const std::vector< float > &  coords)

Definition at line 69 of file wire.cc.

References coords(), m_coords, minsky::sqr(), and MathDAG::sqrt().

70  {
71  if (coords.size()<6)
72  m_coords.clear();
73  else
74  {
75  assert(coords.size() % 2 == 0);
76 
77  const float d=1/sqrt
78  (sqr(coords[coords.size()-2]-coords[0])+sqr(coords[coords.size()-1]-coords[1]));
79  m_coords.resize(coords.size()-4);
80  for (size_t i=2; i<coords.size()-3; i+=2)
81  {
82  m_coords[i-2] = (coords[i]-coords[0])*d;
83  m_coords[i-1] = (coords[i+1]-coords[1])*d;
84  }
85  }
86  return this->coords();
87  }
Expr sqrt(const Expr &x)
Definition: expr.h:154
std::vector< float > m_coords
Definition: wire.h:49
std::vector< float > coords() const
display coordinates
Definition: wire.cc:45
T sqr(T x)
Definition: geometry.h:36
Here is the call graph for this function:

◆ deleteHandle()

void minsky::Wire::deleteHandle ( float  x,
float  y 
)

Definition at line 655 of file wire.cc.

References coords(), and minsky::anonymous_namespace{wire.cc}::d2().

656  {
657  auto c=coords();
658  auto n=c.begin(); // nearest index
659  float closestD=d2(c[0],c[1],x,y);
660  for (auto i=c.begin()+2; i<c.end()-1; i+=2)
661  {
662  const float d=d2(*i,*(i+1),x,y);
663  if (d<closestD)
664  {
665  closestD=d;
666  n=i;
667  }
668  }
669  assert(n<c.end()-1);
670  c.erase(n, n+2);
671  coords(c);
672  }
std::vector< float > coords() const
display coordinates
Definition: wire.cc:45
float d2(float x0, float y0, float x1, float y1)
Definition: wire.cc:568
Here is the call graph for this function:

◆ draw()

void minsky::Wire::draw ( cairo_t *  cairo,
bool  reverseArrow = false 
) const

draw this item into a cairo context

Two control points are inserted between two adjacent handles (knots) of the curved wires on the canvas. The first and second derivatives of the cubic Bezier curves, representing curved segments of wires, and spanning adjacent knots, are matched at the common knots. The second derivatives are set to zero at the ends to absorb the extra degrees of freedom, thus leading to a matrix equation relating control points \(c_i\) to the knots \(k_i\):

\[ \left(\begin{array}{c} b_1 & a_1 & 0 \\ d_1 & b_2 & a_2 \\ 0 & d_2 & b_3 \end{array}\right) \left(\begin{array}{c} c_1 \\ c_2 \\ c_3 \end{array}\right) = \left(\begin{array}{c} k_1 \\ k_2 \\ k_3 \end{array}\right) \]

Definition at line 374 of file wire.cc.

References cairoCoords, minsky::anonymous_namespace{wire.cc}::computeControlPoints(), minsky::anonymous_namespace{wire.cc}::constructTargetVector(), minsky::anonymous_namespace{wire.cc}::constructTriDiag(), coords(), handleRadius, minsky::latexToPango(), M_PI, minsky::NoteBase::mouseFocus, storeCairoCoords(), minsky::anonymous_namespace{wire.cc}::toCoordPair(), minsky::NoteBase::tooltip(), and visible().

Referenced by minsky::PhillipsFlow::draw().

375  {
376  auto coords=this->coords();
377  if (coords.size()<4 || !visible()) return;
378 
379  float angle, lastx, lasty;
380  if (coords.size()==4)
381  {
382  cairo_move_to(cairo,coords[0],coords[1]);
383  cairo_line_to(cairo, coords[2], coords[3]);
384  if (reverseArrow)
385  {
386  angle=atan2(coords[3]-coords[1], coords[2]-coords[0])+M_PI;
387  lastx=coords[0]; lasty=coords[1];
388  }
389  else
390  {
391  angle=atan2(coords[3]-coords[1], coords[2]-coords[0]) + (reverseArrow? M_PI:0);
392  lastx=coords[2]; lasty=coords[3];
393  }
394  }
395  else
396  {
397  cairo_move_to(cairo, coords[0], coords[1]);
398 
413  // For ticket 991/1092. Convert to coordinate pairs.
414  vector<pair<float,float>> points = toCoordPair(coords);
415 
416  const int n = points.size()-1;
417 
418  // Initial vector of knots in the matrix equation Ac = k
419  const vector<pair<float,float>> target = constructTargetVector(n, points);
420 
421  vector<vector<float>> A(n,vector<float>(n));
422  // Initial matrix A which relates control points c_i to knots k_i by matching first and second derivatives of cubic Bezier curves at common points (knots) between curves.
423  A = constructTriDiag(n);
424 
425  // For ticket 991. Apply Thomas' algorithm to matrix equation Ac=k
426  vector<pair<float,float>> controlPoints = computeControlPoints(A, points, target);
427 
428  // Decrease tolerance a bit, since it's going to be magnified
429  cairo_set_tolerance (cairo, 0.01);
430 
431  for (int i = 0; i < n; i++) {
432  cairo_curve_to(cairo, controlPoints[i].first,controlPoints[i].second,controlPoints[n+i].first,controlPoints[n+i].second,points[i+1].first,points[i+1].second);
433  }
434 
435  // Stash the internal cairo coordinates used to draw curved wires. for ticket 1079.
436  if (coords.size()>4) storeCairoCoords(cairo);
437 
438  cairo_stroke(cairo);
439  angle=atan2(coords[coords.size()-1]-coords[coords.size()-3],
440  coords[coords.size()-2]-coords[coords.size()-4]);
441  lastx=coords[coords.size()-2]; lasty=coords[coords.size()-1];
442  }
443  cairo_stroke(cairo);
444 
445  // draw arrow
446  {
447  const CairoSave cs(cairo);
448  auto lw=cairo_get_line_width(cairo);
449  cairo_translate(cairo, lastx, lasty);
450  cairo_rotate(cairo,angle);
451  cairo_move_to(cairo,0,0);
452  cairo_line_to(cairo,-5*lw,-3*lw);
453  cairo_line_to(cairo,-3*lw,0);
454  cairo_line_to(cairo,-5*lw,3*lw);
455  cairo_close_path(cairo);
456  cairo_fill(cairo);
457  }
458 
459  // draw handles
460  if (mouseFocus)
461  {
462  const cairo::CairoSave cs(cairo);
463  cairo_set_source_rgb(cairo,0,0,1);
464  if (cairoCoords.empty() || coords.size()==4)
465  {
466  const double midx=0.5*(coords[0]+coords[2]);
467  const double midy=0.5*(coords[1]+coords[3]);
468  cairo_arc(cairo,midx,midy,1.5*handleRadius, 0, 2*M_PI);
469  cairo_fill(cairo);
470  }
471  else
472  {
473  const size_t numSmallHandles=0.5*(coords.size()-4)+1, numCairoCoords=cairoCoords.size()-1;
474  for (size_t i=0; i<coords.size()-3; i+=2)
475  {
476  const double midx=cairoCoords[(i+1)*numCairoCoords/(2*numSmallHandles)].first;
477  const double midy=cairoCoords[(i+1)*numCairoCoords/(2*numSmallHandles)].second;
478  cairo_arc(cairo,midx,midy,handleRadius, 0, 2*M_PI);
479  if (i>0) // draw existing interior gripping handle
480  cairo_arc(cairo,coords[i],coords[i+1],1.5*handleRadius, 0, 2*M_PI);
481  cairo_fill(cairo);
482  }
483  }
484  }
485  if (mouseFocus && !tooltip().empty())
486  {
487  const cairo::CairoSave cs(cairo);
488  const string toolTipText=latexToPango(tooltip());
489  ecolab::Pango pango(cairo);
490  pango.setMarkup(toolTipText);
491  // place tooltip on centre dot if an odd number of control points, or halfway between otherwise
492  auto dd=div(coords.size(),4);
493  assert(dd.rem%2==0);
494  if (dd.quot&1) dd.quot+=dd.rem-1; // adjust so the dd.quot points to an x coordinate
495  double midx=coords[dd.quot], midy=coords[dd.quot+1];
496  if (dd.rem==0)
497  {
498  midx=0.5*(coords[dd.quot]+coords[dd.quot+2]);
499  midy=0.5*(coords[dd.quot+1]+coords[dd.quot+3]);
500  }
501  cairo_translate(cairo,midx,midy);
502  cairo_rectangle(cairo,0,0,pango.width(),pango.height());
503  cairo_set_source_rgb(cairo,1,1,1);
504  cairo_fill_preserve(cairo);
505  cairo_set_source_rgb(cairo,0,0,0);
506  cairo_set_line_width(cairo,1);
507  cairo_set_dash(cairo,nullptr,0,0);
508  pango.show();
509  cairo_stroke(cairo);
510  }
511  }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
bool visible() const
whether this wire is visible or not
Definition: wire.cc:109
std::string latexToPango(const char *s)
Definition: latexMarkup.h:30
vector< vector< float > > constructTriDiag(int length)
Definition: wire.cc:185
std::vector< std::pair< float, float > > cairoCoords
contains all the internal cairo coordinates used to draw a wire
Definition: wire.h:55
static constexpr float handleRadius
Definition: wire.h:53
vector< pair< float, float > > constructTargetVector(int n, const vector< pair< float, float >> &knots)
Definition: wire.cc:212
virtual std::string const & tooltip() const
Definition: noteBase.h:36
void storeCairoCoords(cairo_t *cairo) const
stash all the internal cairo coordinates along a wire
Definition: wire.cc:350
std::vector< float > coords() const
display coordinates
Definition: wire.cc:45
vector< pair< float, float > > toCoordPair(vector< float > coords)
Definition: wire.cc:173
vector< pair< float, float > > computeControlPoints(vector< vector< float >> triDiag, const vector< pair< float, float >> &knots, vector< pair< float, float >> target)
Definition: wire.cc:287
bool mouseFocus
true if target of a mouseover
Definition: noteBase.h:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ editHandle()

void minsky::Wire::editHandle ( unsigned  position,
float  x,
float  y 
)

Definition at line 674 of file wire.cc.

References coords().

Referenced by minsky::PhillipsDiagram::mouseMove().

675  {
676  position++;
677  position*=2;
678  auto c=coords();
679  assert(position<c.size()-2);
680  c[position]=x;
681  c[position+1]=y;
682  coords(c);
683  }
std::vector< float > coords() const
display coordinates
Definition: wire.cc:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ from()

std::shared_ptr<Port> minsky::Wire::from ( ) const
inline

Definition at line 63 of file wire.h.

References m_from.

Referenced by coords(), moveToPorts(), split(), units(), visible(), Wire(), and ~Wire().

63 {return m_from.lock();}
std::weak_ptr< Port > m_from
ports this wire connects
Definition: wire.h:51
Here is the caller graph for this function:

◆ insertHandle()

void minsky::Wire::insertHandle ( unsigned  position,
float  x,
float  y 
)

Definition at line 643 of file wire.cc.

References coords().

Referenced by nearestHandle().

644  {
645  n++;
646  n*=2;
647  auto c=coords();
648  assert(n<c.size()-1);
649  vector<float> h{x,y};
650  c.insert(c.begin()+n,h.begin(), h.end());
651  coords(c);
652  }
std::vector< float > coords() const
display coordinates
Definition: wire.cc:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveIntoGroup()

void minsky::Wire::moveIntoGroup ( Group dest)

move this from its group into dest

Definition at line 131 of file wire.cc.

References minsky::GroupItems::addWire(), minsky::Group::globalGroup(), minsky::GroupItems::recursiveDo(), and minsky::GroupItems::wires.

132  {
133  WirePtr wp;
134  // one hit find and remove wire from its map, saving the wire
135  dest.globalGroup().recursiveDo
136  (&Group::wires,
137  [&](Wires& wires, Wires::iterator i) {
138  if (i->get()==this)
139  {
140  wp=*i;
141  wires.erase(i);
142  return true;
143  }
144  return false;
145  });
146  if (wp)
147  dest.addWire(wp);
148  }
std::vector< WirePtr > Wires
Definition: wire.h:103
std::shared_ptr< Wire > WirePtr
Definition: wire.h:102
Here is the call graph for this function:

◆ moveToPorts()

void minsky::Wire::moveToPorts ( const std::shared_ptr< Port > &  from,
const std::shared_ptr< Port > &  to 
)

switch ports this wire links to

Definition at line 118 of file wire.cc.

References f, from(), m_from, m_to, and to().

Referenced by split().

119  {
120  if (auto f=this->from())
121  f->m_wires.erase(remove(f->m_wires.begin(), f->m_wires.end(), this), f->m_wires.end());
122  if (auto t=this->to())
123  t->m_wires.erase(remove(t->m_wires.begin(), t->m_wires.end(), this), t->m_wires.end());
124  m_from=from;
125  m_to=to;
126  from->m_wires.push_back(this);
127  to->m_wires.push_back(this);
128  }
function f
Definition: canvas.m:1
std::shared_ptr< Port > from() const
Definition: wire.h:63
std::shared_ptr< Port > to() const
Definition: wire.h:64
std::weak_ptr< Port > m_to
Definition: wire.h:51
std::weak_ptr< Port > m_from
ports this wire connects
Definition: wire.h:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ near()

bool minsky::Wire::near ( float  x,
float  y 
) const

returns true if coordinates are near this wire

Definition at line 574 of file wire.cc.

References minsky::anonymous_namespace{wire.cc}::allHandleCoords(), cairoCoords, coords(), minsky::anonymous_namespace{wire.cc}::d2(), and minsky::anonymous_namespace{wire.cc}::segNear().

575  {
576  auto c=coords();
577  assert(c.size()>=4);
578  if (c.size()==4)
579  return segNear(c[0],c[1],c[2],c[3],x,y);
580 
581  // fixes for tickets 991/1095
582  vector<pair<float,float>> p=allHandleCoords(c);
583  if (!cairoCoords.empty()) p=cairoCoords;
584 
585  unsigned k=0; // nearest index
586  float closestD=d2(p[0].first,p[0].second,x,y);
587  for (size_t i=0; i<p.size(); i++)
588  {
589  const float d=d2(p[i].first,p[i].second,x,y);
590  if (d<=closestD)
591  {
592  closestD=d;
593  k=i;
594  }
595  }
596 
597  // Check for proximity to line segments about index k
598  if (k>0 && k<p.size()-1)
599  return (segNear(p[k-1].first,p[k-1].second,p[k].first,p[k].second,x,y) || segNear(p[k].first,p[k].second,p[k+1].first,p[k+1].second,x,y));
600  return false;
601  }
bool segNear(float x0, float y0, float x1, float y1, float x, float y)
Definition: wire.cc:561
std::vector< std::pair< float, float > > cairoCoords
contains all the internal cairo coordinates used to draw a wire
Definition: wire.h:55
std::vector< float > coords() const
display coordinates
Definition: wire.cc:45
vector< pair< float, float > > allHandleCoords(vector< float > coords)
Definition: wire.cc:154
float d2(float x0, float y0, float x1, float y1)
Definition: wire.cc:568
Here is the call graph for this function:

◆ nearestHandle()

unsigned minsky::Wire::nearestHandle ( float  x,
float  y 
)

returns the index into the coordinate list if x,y is close to it. Otherwise inserts midpoints and returns that. Wire endpoints are not returned

Definition at line 603 of file wire.cc.

References coords(), minsky::anonymous_namespace{wire.cc}::d2(), and insertHandle().

604  {
605  auto c=coords();
606 
607  unsigned n=0; // nearest index
608  float closestD=d2(c[0],c[1],x,y);
609  for (size_t i=2; i<c.size()-1; i+=2)
610  {
611  const float d=d2(c[i],c[i+1],x,y);
612  if (d<=closestD)
613  {
614  closestD=d;
615  n=i;
616  }
617  }
618 
619  // now work out if we need to insert a midpoint handle
620  if (n>0)
621  {
622  const float mx=0.5*(c[n]+c[n-2]), my=0.5*(c[n+1]+c[n-1]);
623  const float d=d2(mx,my,x,y);
624  if (n==c.size()-2 || d<closestD)
625  {
626  insertHandle((n>>1)-1, mx, my);
627  return (n>>1)-1;
628  }
629  }
630  if (n<c.size()-3)
631  {
632  const float mx=0.5*(c[n+2]+c[n]), my=0.5*(c[n+3]+c[n+1]);
633  const float d=d2(mx,my,x,y);
634  if (n==0 || d<closestD)
635  {
636  insertHandle(n>>1, mx, my);
637  return (n>>1);
638  }
639  }
640  return (n>>1)-1;
641  }
void insertHandle(unsigned position, float x, float y)
Definition: wire.cc:643
std::vector< float > coords() const
display coordinates
Definition: wire.cc:45
float d2(float x0, float y0, float x1, float y1)
Definition: wire.cc:568
Here is the call graph for this function:

◆ split()

void minsky::Wire::split ( )

splits wires crossing group boundaries

Definition at line 513 of file wire.cc.

References from(), moveToPorts(), to(), and Wire().

514  {
515  // add I/O variables if this wire crosses a group boundary
516  if (auto fg=from()->item().group.lock())
517  if (auto tg=to()->item().group.lock())
518  if (fg!=tg && !from()->item().ioVar() && !to()->item().ioVar()) // crosses boundary
519  {
520  // check if this wire is in from group
521  auto cmp=[&](const WirePtr& w) {return w.get()==this;};
522  auto i=find_if(fg->wires.begin(), fg->wires.end(), cmp);
523  if (i==fg->wires.end())
524  {
525  fg->addOutputVar();
526  assert(fg->outVariables.back()->portsSize()>1);
527  fg->addWire(new Wire(from(),fg->outVariables.back()->ports(1)));
528  moveToPorts(fg->outVariables.back()->ports(0).lock(), to());
529  }
530  // check if this wire is in to group
531  i=find_if(tg->wires.begin(), tg->wires.end(), cmp);
532  if (i==tg->wires.end())
533  {
534  tg->addInputVar();
535  assert(tg->inVariables.back()->portsSize()>1);
536  tg->addWire(new Wire(tg->inVariables.back()->ports(0),to()));
537  moveToPorts(from(), tg->inVariables.back()->ports(1).lock());
538  }
539  }
540  }
std::shared_ptr< Port > from() const
Definition: wire.h:63
std::shared_ptr< Port > to() const
Definition: wire.h:64
Wire()
Definition: wire.h:58
std::shared_ptr< Wire > WirePtr
Definition: wire.h:102
void moveToPorts(const std::shared_ptr< Port > &from, const std::shared_ptr< Port > &to)
switch ports this wire links to
Definition: wire.cc:118
Definition: group.tcl:84
Here is the call graph for this function:

◆ storeCairoCoords()

void minsky::Wire::storeCairoCoords ( cairo_t *  cairo) const

stash all the internal cairo coordinates along a wire

Definition at line 350 of file wire.cc.

References cairoCoords.

Referenced by draw().

351  {
352  cairoCoords.clear();
353  cairo_path_t *path;
354  cairo_path_data_t *data;
355 
356  path = cairo_copy_path_flat(cairo);
357 
358  for (int j=0; j < path->num_data; j += path->data[j].header.length) {
359  data = &path->data[j];
360  switch (data->header.type) {
361  case CAIRO_PATH_MOVE_TO:
362  break;
363  case CAIRO_PATH_LINE_TO:
364  cairoCoords.push_back(make_pair(data[1].point.x,data[1].point.y));
365  break;
366  case CAIRO_PATH_CURVE_TO:
367  case CAIRO_PATH_CLOSE_PATH:
368  break;
369  }
370  }
371  cairo_path_destroy (path);
372  }
std::vector< std::pair< float, float > > cairoCoords
contains all the internal cairo coordinates used to draw a wire
Definition: wire.h:55
Here is the caller graph for this function:

◆ straighten()

void minsky::Wire::straighten ( )
inline

Definition at line 90 of file wire.h.

References m_coords.

90 {m_coords.clear();}
std::vector< float > m_coords
Definition: wire.h:49

◆ to()

std::shared_ptr<Port> minsky::Wire::to ( ) const
inline

Definition at line 64 of file wire.h.

References m_to.

Referenced by coords(), moveToPorts(), split(), visible(), Wire(), and ~Wire().

64 {return m_to.lock();}
std::weak_ptr< Port > m_to
Definition: wire.h:51
Here is the caller graph for this function:

◆ units()

Units minsky::Wire::units ( bool  check) const

units (dimensional analysis) of data flowing across wire

Definition at line 542 of file wire.cc.

References f, from(), and unitsCtr.

543  {
544 
545  if (auto f=from())
546  {
547  // we allow possible traversing twice over a wire, to allow an
548  // integral to break the cycle
549  if (unitsCtr>2)
550  f->item().throw_error("wiring loop detected");
551  const IncrDecrCounter idc(unitsCtr);
552  return f->item().units(check);
553  }
554  return {};
555  }
function f
Definition: canvas.m:1
std::shared_ptr< Port > from() const
Definition: wire.h:63
int unitsCtr
for detecting wiring loops in units()
Definition: wire.h:54
Here is the call graph for this function:

◆ visible()

bool minsky::Wire::visible ( ) const

whether this wire is visible or not

Definition at line 109 of file wire.cc.

References f, from(), and to().

Referenced by draw().

110  {
111  auto f=from(), t=to();
112  auto fgroup=f->item().group.lock(), tgroup=t->item().group.lock();
113  return f && t &&
114  (!fgroup || fgroup->displayContents() ||
115  !tgroup || tgroup->displayContents());
116  }
function f
Definition: canvas.m:1
std::shared_ptr< Port > from() const
Definition: wire.h:63
std::shared_ptr< Port > to() const
Definition: wire.h:64
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ SchemaHelper

friend struct SchemaHelper
friend

Definition at line 46 of file wire.h.

Member Data Documentation

◆ cairoCoords

std::vector<std::pair<float,float> > minsky::Wire::cairoCoords
mutableprivate

contains all the internal cairo coordinates used to draw a wire

Definition at line 55 of file wire.h.

Referenced by draw(), near(), and storeCairoCoords().

◆ handleRadius

constexpr float minsky::Wire::handleRadius =3
staticprivate

Definition at line 53 of file wire.h.

Referenced by draw().

◆ m_coords

std::vector<float> minsky::Wire::m_coords
private

Definition at line 49 of file wire.h.

Referenced by coords(), and straighten().

◆ m_from

std::weak_ptr<Port> minsky::Wire::m_from
private

ports this wire connects

Definition at line 51 of file wire.h.

Referenced by from(), moveToPorts(), and Wire().

◆ m_to

std::weak_ptr<Port> minsky::Wire::m_to
private

Definition at line 51 of file wire.h.

Referenced by moveToPorts(), to(), and Wire().

◆ unitsCtr

int minsky::Wire::unitsCtr =0
mutableprivate

for detecting wiring loops in units()

Definition at line 54 of file wire.h.

Referenced by units().


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