Minsky
minsky::SwitchIcon Class Reference

#include <switchIcon.h>

Inheritance diagram for minsky::SwitchIcon:
Inheritance graph
Collaboration diagram for minsky::SwitchIcon:
Collaboration graph

Public Member Functions

 SwitchIcon ()
 default to if/then More...
 
 SwitchIcon (const SwitchIcon &x)
 
 SwitchIcon (SwitchIcon &&x)
 
SwitchIconoperator= (const SwitchIcon &x)
 
SwitchIconoperator= (SwitchIcon &&x)
 
unsigned switchValue () const
 value of switch according to current inputs More...
 
double value () const override
 current value of output port More...
 
const SwitchIconswitchIconCast () const override
 
SwitchIconswitchIconCast () override
 
Units units (bool) const override
 compute the dimensional units More...
 
void draw (cairo_t *context) const override
 draw icon to context More...
 
void flip () override
 rotate icon though 180∘ More...
 
unsigned numCases () const
 
void setNumCases (unsigned)
 
- Public Member Functions inherited from minsky::ItemT< SwitchIcon, BottomRightResizerItem >
std::string classType () const override
 
ItemTclone () const override
 
void TCL_obj (classdesc::TCL_obj_t &t, const std::string &d) override
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) override
 dummy template definition for use with gui executable More...
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) const override
 
void json_pack (classdesc::json_pack_t &j) const override
 
 ItemT ()=default
 
 ItemT (const ItemT &)=default
 
 ItemT (ItemT &&)=delete
 
ItemToperator= (const ItemT &)=default
 
ItemToperator= (ItemT &&)=delete
 
- Public Member Functions inherited from minsky::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...
 
virtual bool ioVar () const
 indicates this is a group I/O variable 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)
 
std::string id () const
 return an id uniquely identifying this item More...
 
virtual float x () const
 
virtual float y () const
 
virtual float zoomFactor () const
 
void ensureBBValid () const
 
float width () const
 
float height () const
 
virtual std::vector< Pointcorners () const
 
float left () const
 
float right () const
 
float top () const
 
float bottom () const
 
std::string bookmarkId () const
 Id of bookmark associated with this. More...
 
void adjustBookmark () const override
 adjust bookmark list to reflect current configuration More...
 
float resizeHandleSize () const
 resize handles should be at least a percentage if the icon size (#1025) More...
 
virtual bool 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 onMouseMotion (float x, float y)
 respond to mouse motion events with button pressed 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 bool onKeyPress (int keySym, const std::string &utf8, int state)
 respond to key press events More...
 
virtual void deleteAttachedWires ()
 delete all attached wires More...
 
virtual bool visible () const
 whether this item is visible on the canvas. More...
 
void moveTo (float x, float y)
 
virtual void resize (const LassoBox &b)
 resize this item on the canvas More...
 
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 ClickType::Type clickType (float x, float y) const
 returns the clicktype given a mouse click at x, y. More...
 
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...
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) override
 runs the RESTProcess descriptor suitable for this type More...
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) const override
 
virtual void displayDelayedTooltip (float x, float y)
 enable extended tooltip help message appropriate for mouse at (x,y) More...
 
virtual void disableDelayedTooltip ()
 
virtual 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...
 
virtual void destroyFrame ()
 destroy any popup windows associated with this More...
 
- Public Member Functions inherited from minsky::NoteBase
virtual std::string const & detailedText () const
 
virtual std::string const & detailedText (const std::string &x)
 
virtual std::string const & tooltip () const
 
virtual std::string const & tooltip (const std::string &x)
 
virtual ~NoteBase ()=default
 

Public Attributes

bool flipped =false
 whether icon is oriented so input ports are on the rhs, and output on the lhs 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...
 

Private Types

using Super = ItemT< SwitchIcon, BottomRightResizerItem >
 

Private Member Functions

 CLASSDESC_ACCESS (SwitchIcon)
 

Friends

struct SchemaHelper
 

Additional Inherited Members

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

Detailed Description

Definition at line 27 of file switchIcon.h.

Member Typedef Documentation

◆ Super

Definition at line 29 of file switchIcon.h.

Constructor & Destructor Documentation

◆ SwitchIcon() [1/3]

minsky::SwitchIcon::SwitchIcon ( )
inline

default to if/then

Definition at line 33 of file switchIcon.h.

References setNumCases().

Here is the call graph for this function:

◆ SwitchIcon() [2/3]

minsky::SwitchIcon::SwitchIcon ( const SwitchIcon x)
inline

Definition at line 34 of file switchIcon.h.

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

34 : Super(x), flipped(x.flipped) {setNumCases(x.numCases());}
void setNumCases(unsigned)
Definition: switchIcon.cc:31
virtual float x() const
Definition: item.cc:107
ItemT< SwitchIcon, BottomRightResizerItem > Super
Definition: switchIcon.h:29
bool flipped
whether icon is oriented so input ports are on the rhs, and output on the lhs
Definition: switchIcon.h:70
Here is the call graph for this function:

◆ SwitchIcon() [3/3]

minsky::SwitchIcon::SwitchIcon ( SwitchIcon &&  x)
inline

Definition at line 35 of file switchIcon.h.

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

35 : Super(x), flipped(x.flipped) {setNumCases(x.numCases());}
void setNumCases(unsigned)
Definition: switchIcon.cc:31
virtual float x() const
Definition: item.cc:107
ItemT< SwitchIcon, BottomRightResizerItem > Super
Definition: switchIcon.h:29
bool flipped
whether icon is oriented so input ports are on the rhs, and output on the lhs
Definition: switchIcon.h:70
Here is the call graph for this function:

Member Function Documentation

◆ CLASSDESC_ACCESS()

minsky::SwitchIcon::CLASSDESC_ACCESS ( SwitchIcon  )
private

◆ draw()

void minsky::SwitchIcon::draw ( cairo_t *  context) const
overridevirtual

draw icon to context

Reimplemented from minsky::Item.

Definition at line 75 of file switchIcon.cc.

References minsky::drawTriangle(), minsky::flipped(), and M_PI.

76  {
77  auto z=zoomFactor();
78  // following the draw method in the Sheet class, iWidth() and iHeight() have been changed to m_width and m_height,
79  // since the former largely play a role in the VariableBase and OperationBase classes. for ticket 1250
80  const float width=m_width*z, height=m_height*z;
81  cairo_set_line_width(cairo,1);
82  cairo_rectangle(cairo,-0.5*width,-0.5*height,width,height);
83  cairo_stroke(cairo);
84 
85  const float w=flipped? -width: width;
86  const float o=flipped? -8: 8;
87  // output port
88  drawTriangle(cairo, 0.5*w, 0, palette[0], flipped? M_PI: 0);
89  m_ports[0]->moveTo(x()+0.5*w, y());
90  // control port
91  drawTriangle(cairo, 0, -0.5*height-8, palette[0], M_PI/2);
92  m_ports[1]->moveTo(x(), y()-0.5*height-8);
93  const float dy=height/numCases();
94  float y1=-0.5*height+0.5*dy;
95  // case ports
96  for (size_t i=2; i<m_ports.size(); ++i, y1+=dy)
97  {
98  drawTriangle(cairo, -0.5*w-o, y1, palette[(i-2)%paletteSz], flipped? M_PI: 0);
99  m_ports[i]->moveTo(x()+-0.5*w-o, y()+y1);
100  }
101  // draw indicating arrow
102  cairo_move_to(cairo,0.5*w, 0);
103  try
104  {
105  y1=-0.5*width+0.5*dy+switchValue()*dy;
106  }
107  catch (const std::exception&)
108  {
109  y1=-0.5*width+0.5*dy;
110  }
111  cairo_line_to(cairo,-0.45*w,0.9*y1);
112  cairo_stroke(cairo);
113 
114  if (mouseFocus)
115  {
116  drawPorts(cairo);
117  displayTooltip(cairo,tooltip());
119  }
120 
121  // add 8 pt margin to allow for ports
122  cairo_rectangle(cairo,-0.5*width-8,-0.5*height-8,width+16,height+8);
123  cairo_clip(cairo);
124  if (selected) drawSelected(cairo);
125  }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
void drawPorts(cairo_t *cairo) const
Definition: item.cc:294
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
unsigned switchValue() const
value of switch according to current inputs
Definition: switchIcon.cc:45
bool onResizeHandles
set to true to indicate mouse is ovcaler resize handles
Definition: item.h:175
double m_height
Definition: item.h:155
virtual std::string const & tooltip() const
Definition: noteBase.h:36
virtual float zoomFactor() const
Definition: item.cc:121
static void drawSelected(cairo_t *cairo)
Definition: item.cc:308
float width() const
Definition: item.h:242
double m_width
Definition: item.h:155
ItemPortVector m_ports
Definition: item.h:156
bool selected
true if selected for cut, copy or group operation
Definition: noteBase.h:32
float height() const
Definition: item.h:243
bool mouseFocus
true if target of a mouseover
Definition: noteBase.h:31
void drawTriangle(cairo_t *cairo, double x, double y, const ecolab::cairo::Colour &col, double angle=0)
unsigned numCases() const
Definition: switchIcon.h:53
bool flipped
whether icon is oriented so input ports are on the rhs, and output on the lhs
Definition: switchIcon.h:70
void drawResizeHandles(cairo_t *cairo) const override
Definition: item.cc:355
Here is the call graph for this function:

◆ flip()

void minsky::SwitchIcon::flip ( )
inlineoverridevirtual

rotate icon though 180∘

Reimplemented from minsky::Item.

Definition at line 71 of file switchIcon.h.

References flipped.

71 {flipped=!flipped;}
bool flipped
whether icon is oriented so input ports are on the rhs, and output on the lhs
Definition: switchIcon.h:70

◆ numCases()

unsigned minsky::SwitchIcon::numCases ( ) const
inline

number of cases switched between. If input <1, case 0 is chosen, if input >=numCases-1, case numCases-1 is chosen

Definition at line 53 of file switchIcon.h.

References minsky::Item::m_ports.

53 {return m_ports.size()-2;}
ItemPortVector m_ports
Definition: item.h:156

◆ operator=() [1/2]

SwitchIcon& minsky::SwitchIcon::operator= ( const SwitchIcon x)
inline

Definition at line 36 of file switchIcon.h.

References flipped, minsky::ItemT< SwitchIcon, BottomRightResizerItem >::operator=(), setNumCases(), and minsky::Item::x().

36  {
38  flipped=x.flipped;
39  setNumCases(x.numCases());
40  return *this;
41  }
void setNumCases(unsigned)
Definition: switchIcon.cc:31
virtual float x() const
Definition: item.cc:107
bool flipped
whether icon is oriented so input ports are on the rhs, and output on the lhs
Definition: switchIcon.h:70
Here is the call graph for this function:

◆ operator=() [2/2]

SwitchIcon& minsky::SwitchIcon::operator= ( SwitchIcon &&  x)
inline

Definition at line 42 of file switchIcon.h.

References flipped, minsky::ItemT< SwitchIcon, BottomRightResizerItem >::operator=(), setNumCases(), and minsky::Item::x().

42  {
44  flipped=x.flipped;
45  setNumCases(x.numCases());
46  return *this;
47  }
void setNumCases(unsigned)
Definition: switchIcon.cc:31
virtual float x() const
Definition: item.cc:107
bool flipped
whether icon is oriented so input ports are on the rhs, and output on the lhs
Definition: switchIcon.h:70
Here is the call graph for this function:

◆ setNumCases()

void minsky::SwitchIcon::setNumCases ( unsigned  n)

number of cases switched between. If input <1, case 0 is chosen, if input >=numCases-1, case numCases-1 is chosen

Definition at line 31 of file switchIcon.cc.

Referenced by operator=(), and SwitchIcon().

32  {
33  if (n<2) throw error("switches need at least two cases");
34 
35  m_ports.clear();
36  m_ports.emplace_back(make_shared<Port>(*this));
37  // output port, selector port and n case ports
38  for (unsigned i=m_ports.size(); i<n+2; ++i)
39  m_ports.emplace_back(make_shared<InputPort>(*this));
40  const float width=8*numCases();
41  if (width>iWidth()) iWidth(width);
42  if (width>iHeight()) iHeight(width);
43  }
float iHeight() const
Definition: item.h:224
float width() const
Definition: item.h:242
float iWidth() const
Definition: item.h:217
ItemPortVector m_ports
Definition: item.h:156
unsigned numCases() const
Definition: switchIcon.h:53
Here is the caller graph for this function:

◆ switchIconCast() [1/2]

const SwitchIcon* minsky::SwitchIcon::switchIconCast ( ) const
inlineoverride

Definition at line 61 of file switchIcon.h.

61 {return this;}

◆ switchIconCast() [2/2]

SwitchIcon* minsky::SwitchIcon::switchIconCast ( )
inlineoverride

Definition at line 62 of file switchIcon.h.

62 {return this;}

◆ switchValue()

unsigned minsky::SwitchIcon::switchValue ( ) const

value of switch according to current inputs

Definition at line 45 of file switchIcon.cc.

Referenced by value().

46  {
47  const double x=m_ports[1]->value();
48  if (x<1)
49  return 0;
50  if (x>=numCases()-1)
51  return numCases()-1;
52  return unsigned(x);
53  }
virtual float x() const
Definition: item.cc:107
ItemPortVector m_ports
Definition: item.h:156
unsigned numCases() const
Definition: switchIcon.h:53
Here is the caller graph for this function:

◆ units()

Units minsky::SwitchIcon::units ( bool  check) const
overridevirtual

compute the dimensional units

Parameters
check- if true, then perform consistency checks
Exceptions
ifcheck=true and dimensions inconsistent

Reimplemented from minsky::Item.

Definition at line 55 of file switchIcon.cc.

References minsky::Units::str().

56  {
57  bool inputFound=false;
58  Units r;
59  for (size_t i=2; i<m_ports.size(); ++i)
60  for (auto w: m_ports[i]->wires())
61  if (check && inputFound)
62  {
63  auto tmp=w->units(check);
64  if (tmp!=r)
65  throw_error("incompatible units: "+tmp.str()+"≠"+r.str());
66  }
67  else
68  {
69  inputFound=true;
70  r=w->units(check);
71  }
72  return r;
73  }
void throw_error(const std::string &) const
mark item on canvas, then throw
Definition: item.cc:86
ItemPortVector m_ports
Definition: item.h:156
Here is the call graph for this function:

◆ value()

double minsky::SwitchIcon::value ( ) const
inlineoverridevirtual

current value of output port

Reimplemented from minsky::Item.

Definition at line 59 of file switchIcon.h.

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

59 {return m_ports[switchValue()+2]->value();}
unsigned switchValue() const
value of switch according to current inputs
Definition: switchIcon.cc:45
ItemPortVector m_ports
Definition: item.h:156
Here is the call graph for this function:

Friends And Related Function Documentation

◆ SchemaHelper

friend struct SchemaHelper
friend

Definition at line 31 of file switchIcon.h.

Member Data Documentation

◆ flipped

bool minsky::SwitchIcon::flipped =false

whether icon is oriented so input ports are on the rhs, and output on the lhs

Definition at line 70 of file switchIcon.h.

Referenced by flip(), and operator=().


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