Minsky: 3.17.0
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
 

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 39 of file wire.h.

Constructor & Destructor Documentation

◆ Wire() [1/2]

minsky::Wire::Wire ( )
inline

Definition at line 54 of file wire.h.

Referenced by split().

54 {}
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 86 of file wire.cc.

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

87  :
88  m_from(from), m_to(to)
89  {
90  if (!from.lock() || !to.lock()) throw error("wiring defunct ports");
91  if (from.lock()->input() || !to.lock()->input()) throw error("invalid ports for wire");
92  coords(a_coords);
93  m_from.lock()->m_wires.push_back(this);
94  m_to.lock()->m_wires.push_back(this);
95  }
std::shared_ptr< Port > from() const
Definition: wire.h:59
std::shared_ptr< Port > to() const
Definition: wire.h:60
std::vector< float > coords() const
display coordinates
Definition: wire.cc:41
std::weak_ptr< Port > m_to
Definition: wire.h:47
std::weak_ptr< Port > m_from
ports this wire connects
Definition: wire.h:47
Here is the call graph for this function:

◆ ~Wire()

minsky::Wire::~Wire ( )

Definition at line 97 of file wire.cc.

References from(), and to().

98  {
99  if (auto toPort=to())
100  toPort->eraseWire(this);
101  if (auto fromPort=from())
102  fromPort->eraseWire(this);
103  }
std::shared_ptr< Port > from() const
Definition: wire.h:59
std::shared_ptr< Port > to() const
Definition: wire.h:60
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 41 of file wire.cc.

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

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

42  {
43  vector<float> c;
44  assert(from() && to());
45  assert(m_coords.size() % 2 == 0);
46  if (auto f=from())
47  if (auto t=to())
48  {
49  c.push_back(f->x());
50  c.push_back(f->y());
51  const float d=sqrt
52  (sqr(f->x()-t->x())+sqr(f->y()-t->y()));
53 
54  for (size_t i=0; m_coords.size()>1 && i<m_coords.size()-1; i+=2)
55  {
56  c.push_back(f->x() + d*m_coords[i]);
57  c.push_back(f->y() + d*m_coords[i+1]);
58  }
59  c.push_back(t->x());
60  c.push_back(t->y());
61  }
62  return c;
63  }
function f
Definition: canvas.m:1
std::shared_ptr< Port > from() const
Definition: wire.h:59
Expr sqrt(const Expr &x)
Definition: expr.h:153
std::shared_ptr< Port > to() const
Definition: wire.h:60
std::vector< float > m_coords
Definition: wire.h:45
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 65 of file wire.cc.

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

66  {
67  if (coords.size()<6)
68  m_coords.clear();
69  else
70  {
71  assert(coords.size() % 2 == 0);
72 
73  const float d=1/sqrt
74  (sqr(coords[coords.size()-2]-coords[0])+sqr(coords[coords.size()-1]-coords[1]));
75  m_coords.resize(coords.size()-4);
76  for (size_t i=2; i<coords.size()-3; i+=2)
77  {
78  m_coords[i-2] = (coords[i]-coords[0])*d;
79  m_coords[i-1] = (coords[i+1]-coords[1])*d;
80  }
81  }
82  return this->coords();
83  }
Expr sqrt(const Expr &x)
Definition: expr.h:153
std::vector< float > m_coords
Definition: wire.h:45
std::vector< float > coords() const
display coordinates
Definition: wire.cc:41
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 651 of file wire.cc.

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

652  {
653  auto c=coords();
654  auto n=c.begin(); // nearest index
655  float closestD=d2(c[0],c[1],x,y);
656  for (auto i=c.begin()+2; i<c.end()-1; i+=2)
657  {
658  const float d=d2(*i,*(i+1),x,y);
659  if (d<closestD)
660  {
661  closestD=d;
662  n=i;
663  }
664  }
665  assert(n<c.end()-1);
666  c.erase(n, n+2);
667  coords(c);
668  }
std::vector< float > coords() const
display coordinates
Definition: wire.cc:41
float d2(float x0, float y0, float x1, float y1)
Definition: wire.cc:564
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 370 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().

371  {
372  auto coords=this->coords();
373  if (coords.size()<4 || !visible()) return;
374 
375  float angle, lastx, lasty;
376  if (coords.size()==4)
377  {
378  cairo_move_to(cairo,coords[0],coords[1]);
379  cairo_line_to(cairo, coords[2], coords[3]);
380  if (reverseArrow)
381  {
382  angle=atan2(coords[3]-coords[1], coords[2]-coords[0])+M_PI;
383  lastx=coords[0]; lasty=coords[1];
384  }
385  else
386  {
387  angle=atan2(coords[3]-coords[1], coords[2]-coords[0]) + (reverseArrow? M_PI:0);
388  lastx=coords[2]; lasty=coords[3];
389  }
390  }
391  else
392  {
393  cairo_move_to(cairo, coords[0], coords[1]);
394 
409  // For ticket 991/1092. Convert to coordinate pairs.
410  vector<pair<float,float>> points = toCoordPair(coords);
411 
412  const int n = points.size()-1;
413 
414  // Initial vector of knots in the matrix equation Ac = k
415  const vector<pair<float,float>> target = constructTargetVector(n, points);
416 
417  vector<vector<float>> A(n,vector<float>(n));
418  // 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.
419  A = constructTriDiag(n);
420 
421  // For ticket 991. Apply Thomas' algorithm to matrix equation Ac=k
422  vector<pair<float,float>> controlPoints = computeControlPoints(A, points, target);
423 
424  // Decrease tolerance a bit, since it's going to be magnified
425  cairo_set_tolerance (cairo, 0.01);
426 
427  for (int i = 0; i < n; i++) {
428  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);
429  }
430 
431  // Stash the internal cairo coordinates used to draw curved wires. for ticket 1079.
432  if (coords.size()>4) storeCairoCoords(cairo);
433 
434  cairo_stroke(cairo);
435  angle=atan2(coords[coords.size()-1]-coords[coords.size()-3],
436  coords[coords.size()-2]-coords[coords.size()-4]);
437  lastx=coords[coords.size()-2]; lasty=coords[coords.size()-1];
438  }
439  cairo_stroke(cairo);
440 
441  // draw arrow
442  {
443  const CairoSave cs(cairo);
444  auto lw=cairo_get_line_width(cairo);
445  cairo_translate(cairo, lastx, lasty);
446  cairo_rotate(cairo,angle);
447  cairo_move_to(cairo,0,0);
448  cairo_line_to(cairo,-5*lw,-3*lw);
449  cairo_line_to(cairo,-3*lw,0);
450  cairo_line_to(cairo,-5*lw,3*lw);
451  cairo_close_path(cairo);
452  cairo_fill(cairo);
453  }
454 
455  // draw handles
456  if (mouseFocus)
457  {
458  const cairo::CairoSave cs(cairo);
459  cairo_set_source_rgb(cairo,0,0,1);
460  if (cairoCoords.empty() || coords.size()==4)
461  {
462  const double midx=0.5*(coords[0]+coords[2]);
463  const double midy=0.5*(coords[1]+coords[3]);
464  cairo_arc(cairo,midx,midy,1.5*handleRadius, 0, 2*M_PI);
465  cairo_fill(cairo);
466  }
467  else
468  {
469  const size_t numSmallHandles=0.5*(coords.size()-4)+1, numCairoCoords=cairoCoords.size()-1;
470  for (size_t i=0; i<coords.size()-3; i+=2)
471  {
472  const double midx=cairoCoords[(i+1)*numCairoCoords/(2*numSmallHandles)].first;
473  const double midy=cairoCoords[(i+1)*numCairoCoords/(2*numSmallHandles)].second;
474  cairo_arc(cairo,midx,midy,handleRadius, 0, 2*M_PI);
475  if (i>0) // draw existing interior gripping handle
476  cairo_arc(cairo,coords[i],coords[i+1],1.5*handleRadius, 0, 2*M_PI);
477  cairo_fill(cairo);
478  }
479  }
480  }
481  if (mouseFocus && !tooltip().empty())
482  {
483  const cairo::CairoSave cs(cairo);
484  const string toolTipText=latexToPango(tooltip());
485  ecolab::Pango pango(cairo);
486  pango.setMarkup(toolTipText);
487  // place tooltip on centre dot if an odd number of control points, or halfway between otherwise
488  auto dd=div(coords.size(),4);
489  assert(dd.rem%2==0);
490  if (dd.quot&1) dd.quot+=dd.rem-1; // adjust so the dd.quot points to an x coordinate
491  double midx=coords[dd.quot], midy=coords[dd.quot+1];
492  if (dd.rem==0)
493  {
494  midx=0.5*(coords[dd.quot]+coords[dd.quot+2]);
495  midy=0.5*(coords[dd.quot+1]+coords[dd.quot+3]);
496  }
497  cairo_translate(cairo,midx,midy);
498  cairo_rectangle(cairo,0,0,pango.width(),pango.height());
499  cairo_set_source_rgb(cairo,1,1,1);
500  cairo_fill_preserve(cairo);
501  cairo_set_source_rgb(cairo,0,0,0);
502  cairo_set_line_width(cairo,1);
503  cairo_set_dash(cairo,nullptr,0,0);
504  pango.show();
505  cairo_stroke(cairo);
506  }
507  }
#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:105
std::string latexToPango(const char *s)
Definition: latexMarkup.h:30
vector< vector< float > > constructTriDiag(int length)
Definition: wire.cc:181
std::vector< std::pair< float, float > > cairoCoords
contains all the internal cairo coordinates used to draw a wire
Definition: wire.h:51
static constexpr float handleRadius
Definition: wire.h:49
vector< pair< float, float > > constructTargetVector(int n, const vector< pair< float, float >> &knots)
Definition: wire.cc:208
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:346
std::vector< float > coords() const
display coordinates
Definition: wire.cc:41
vector< pair< float, float > > toCoordPair(vector< float > coords)
Definition: wire.cc:169
vector< pair< float, float > > computeControlPoints(vector< vector< float >> triDiag, const vector< pair< float, float >> &knots, vector< pair< float, float >> target)
Definition: wire.cc:283
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 670 of file wire.cc.

References coords().

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

671  {
672  position++;
673  position*=2;
674  auto c=coords();
675  assert(position<c.size()-2);
676  c[position]=x;
677  c[position+1]=y;
678  coords(c);
679  }
std::vector< float > coords() const
display coordinates
Definition: wire.cc:41
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 59 of file wire.h.

References m_from.

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

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

◆ insertHandle()

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

Definition at line 639 of file wire.cc.

References coords().

Referenced by nearestHandle().

640  {
641  n++;
642  n*=2;
643  auto c=coords();
644  assert(n<c.size()-1);
645  vector<float> h{x,y};
646  c.insert(c.begin()+n,h.begin(), h.end());
647  coords(c);
648  }
std::vector< float > coords() const
display coordinates
Definition: wire.cc:41
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 127 of file wire.cc.

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

128  {
129  WirePtr wp;
130  // one hit find and remove wire from its map, saving the wire
131  dest.globalGroup().recursiveDo
132  (&Group::wires,
133  [&](Wires& wires, Wires::iterator i) {
134  if (i->get()==this)
135  {
136  wp=*i;
137  wires.erase(i);
138  return true;
139  }
140  return false;
141  });
142  if (wp)
143  dest.addWire(wp);
144  }
std::vector< WirePtr > Wires
Definition: wire.h:99
std::shared_ptr< Wire > WirePtr
Definition: wire.h:98
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 114 of file wire.cc.

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

Referenced by split().

115  {
116  if (auto f=this->from())
117  f->m_wires.erase(remove(f->m_wires.begin(), f->m_wires.end(), this), f->m_wires.end());
118  if (auto t=this->to())
119  t->m_wires.erase(remove(t->m_wires.begin(), t->m_wires.end(), this), t->m_wires.end());
120  m_from=from;
121  m_to=to;
122  from->m_wires.push_back(this);
123  to->m_wires.push_back(this);
124  }
function f
Definition: canvas.m:1
std::shared_ptr< Port > from() const
Definition: wire.h:59
std::shared_ptr< Port > to() const
Definition: wire.h:60
std::weak_ptr< Port > m_to
Definition: wire.h:47
std::weak_ptr< Port > m_from
ports this wire connects
Definition: wire.h:47
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 570 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().

571  {
572  auto c=coords();
573  assert(c.size()>=4);
574  if (c.size()==4)
575  return segNear(c[0],c[1],c[2],c[3],x,y);
576 
577  // fixes for tickets 991/1095
578  vector<pair<float,float>> p=allHandleCoords(c);
579  if (!cairoCoords.empty()) p=cairoCoords;
580 
581  unsigned k=0; // nearest index
582  float closestD=d2(p[0].first,p[0].second,x,y);
583  for (size_t i=0; i<p.size(); i++)
584  {
585  const float d=d2(p[i].first,p[i].second,x,y);
586  if (d<=closestD)
587  {
588  closestD=d;
589  k=i;
590  }
591  }
592 
593  // Check for proximity to line segments about index k
594  if (k>0 && k<p.size()-1)
595  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));
596  return false;
597  }
bool segNear(float x0, float y0, float x1, float y1, float x, float y)
Definition: wire.cc:557
std::vector< std::pair< float, float > > cairoCoords
contains all the internal cairo coordinates used to draw a wire
Definition: wire.h:51
std::vector< float > coords() const
display coordinates
Definition: wire.cc:41
vector< pair< float, float > > allHandleCoords(vector< float > coords)
Definition: wire.cc:150
float d2(float x0, float y0, float x1, float y1)
Definition: wire.cc:564
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 599 of file wire.cc.

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

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

◆ split()

void minsky::Wire::split ( )

splits wires crossing group boundaries

Definition at line 509 of file wire.cc.

References from(), minsky::group, moveToPorts(), to(), and Wire().

510  {
511  // add I/O variables if this wire crosses a group boundary
512  if (auto fg=from()->item().group.lock())
513  if (auto tg=to()->item().group.lock())
514  if (fg!=tg && !from()->item().ioVar() && !to()->item().ioVar()) // crosses boundary
515  {
516  // check if this wire is in from group
517  auto cmp=[&](const WirePtr& w) {return w.get()==this;};
518  auto i=find_if(fg->wires.begin(), fg->wires.end(), cmp);
519  if (i==fg->wires.end())
520  {
521  fg->addOutputVar();
522  assert(fg->outVariables.back()->portsSize()>1);
523  fg->addWire(new Wire(from(),fg->outVariables.back()->ports(1)));
524  moveToPorts(fg->outVariables.back()->ports(0).lock(), to());
525  }
526  // check if this wire is in to group
527  i=find_if(tg->wires.begin(), tg->wires.end(), cmp);
528  if (i==tg->wires.end())
529  {
530  tg->addInputVar();
531  assert(tg->inVariables.back()->portsSize()>1);
532  tg->addWire(new Wire(tg->inVariables.back()->ports(0),to()));
533  moveToPorts(from(), tg->inVariables.back()->ports(1).lock());
534  }
535  }
536  }
std::shared_ptr< Port > from() const
Definition: wire.h:59
std::shared_ptr< Port > to() const
Definition: wire.h:60
Wire()
Definition: wire.h:54
std::shared_ptr< Wire > WirePtr
Definition: wire.h:98
void moveToPorts(const std::shared_ptr< Port > &from, const std::shared_ptr< Port > &to)
switch ports this wire links to
Definition: wire.cc:114
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 346 of file wire.cc.

References cairoCoords.

Referenced by draw().

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

◆ straighten()

void minsky::Wire::straighten ( )
inline

Definition at line 86 of file wire.h.

References m_coords.

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

◆ to()

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

Definition at line 60 of file wire.h.

References m_to.

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

60 {return m_to.lock();}
std::weak_ptr< Port > m_to
Definition: wire.h:47
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 538 of file wire.cc.

References f, from(), and unitsCtr.

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

◆ visible()

bool minsky::Wire::visible ( ) const

whether this wire is visible or not

Definition at line 105 of file wire.cc.

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

Referenced by draw().

106  {
107  auto f=from(), t=to();
108  auto fgroup=f->item().group.lock(), tgroup=t->item().group.lock();
109  return f && t &&
110  (!fgroup || fgroup->displayContents() ||
111  !tgroup || tgroup->displayContents());
112  }
function f
Definition: canvas.m:1
std::shared_ptr< Port > from() const
Definition: wire.h:59
std::shared_ptr< Port > to() const
Definition: wire.h:60
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 42 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 51 of file wire.h.

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

◆ handleRadius

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

Definition at line 49 of file wire.h.

Referenced by draw().

◆ m_coords

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

Definition at line 45 of file wire.h.

Referenced by straighten().

◆ m_from

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

ports this wire connects

Definition at line 47 of file wire.h.

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

◆ m_to

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

Definition at line 47 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 50 of file wire.h.

Referenced by units().


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