Minsky
minsky::Lock Class Reference

#include <lock.h>

Inheritance diagram for minsky::Lock:
Inheritance graph
Collaboration diagram for minsky::Lock:
Collaboration graph

Public Member Functions

 Lock ()
 
 Lock (const Lock &x)
 
Lockoperator= (const Lock &x)=default
 
void addPorts ()
 
bool locked () const
 
void toggleLocked ()
 
void draw (cairo_t *cairo) const override
 draw this item into a cairo context More...
 
Units units (bool) const override
 compute the dimensional units More...
 
RavelravelInput () const
 Ravel this is connected to. nullptr if not connected to a Ravel. More...
 
void applyLockedStateToRavel () const
 
- Public Member Functions inherited from minsky::ItemT< Lock >
std::string classType () const override
 
ItemTclone () const override
 
void TCL_obj (classdesc::TCL_obj_t &t, const std::string &d) override
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) override
 dummy template definition for use with gui executable More...
 
void RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) const override
 
void json_pack (classdesc::json_pack_t &j) const override
 
 ItemT ()=default
 
 ItemT (const ItemT &)=default
 
 ItemT (ItemT &&)=delete
 
ItemToperator= (const ItemT &)=default
 
ItemToperator= (ItemT &&)=delete
 
- Public Member Functions inherited from minsky::Item
 Item ()
 
virtual std::weak_ptr< Portports (std::size_t i) const
 callback to be run when item deleted from group More...
 
std::size_t portsSize () const
 number of ports More...
 
float portX (std::size_t i)
 
float portY (std::size_t i)
 
virtual bool contains (float xx, float yy) const
 
bool contains (const Point &p) const
 
void updateBoundingBox () override
 
void throw_error (const std::string &) const
 mark item on canvas, then throw More...
 
virtual bool ioVar () const
 indicates this is a group I/O variable More...
 
virtual double value () const
 current value of output port More...
 
double rotation () const
 
double rotation (const double &r)
 
std::pair< double, bool > rotationAsRadians () const
 return the rotation as radians, and whether rotation should have additional straight angle added for text that stays upright. More...
 
float iWidth () const
 
float iWidth (const float &w)
 
float iHeight () const
 
float iHeight (const float &h)
 
virtual void flip ()
 rotate icon though 180∘ More...
 
std::string id () const
 return an id uniquely identifying this item More...
 
virtual float x () const
 
virtual float y () const
 
virtual float zoomFactor () const
 
void ensureBBValid () const
 
float width () const
 
float height () const
 
virtual std::vector< Pointcorners () const
 
float left () const
 
float right () const
 
float top () const
 
float bottom () const
 
std::string bookmarkId () const
 Id of bookmark associated with this. More...
 
void adjustBookmark () const override
 adjust bookmark list to reflect current configuration More...
 
float resizeHandleSize () const
 resize handles should be at least a percentage if the icon size (#1025) More...
 
virtual bool onResizeHandle (float x, float y) const
 
virtual bool 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 void drawResizeHandles (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

ravel::RavelState lockedState
 
- Public Attributes inherited from minsky::Item
float m_x =0
 
float m_y =0
 position in canvas, or within group More...
 
float m_sf =1
 scale factor of item on canvas, or within group More...
 
bool onResizeHandles =false
 set to true to indicate mouse is ovcaler resize handles More...
 
bool onBorder =false
 true to indicate mouse hovering over border More...
 
std::string deleteCallback
 
BoundingBox bb
 canvas bounding box. More...
 
- Public Attributes inherited from minsky::NoteBase
bool mouseFocus =false
 true if target of a mouseover More...
 
bool selected =false
 true if selected for cut, copy or group operation More...
 
bool bookmark =false
 Is this item also a bookmark? More...
 

Static Public Attributes

static SVGRenderer lockedIcon
 
static SVGRenderer unlockedIcon
 

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 30 of file lock.h.

Constructor & Destructor Documentation

◆ Lock() [1/2]

minsky::Lock::Lock ( )

Definition at line 38 of file lock.cc.

39  {
40  tooltip("Double click to lock/unlock");
41  iWidth(30);
42  iHeight(30);
43  addPorts();
44  }
float iHeight() const
Definition: item.h:224
virtual std::string const & tooltip() const
Definition: noteBase.h:36
float iWidth() const
Definition: item.h:217
void addPorts()
Definition: lock.cc:46

◆ Lock() [2/2]

minsky::Lock::Lock ( const Lock x)
inline

Definition at line 34 of file lock.h.

References addPorts().

34 : ItemT<Lock>(x) {addPorts();}
virtual float x() const
Definition: item.cc:107
void addPorts()
Definition: lock.cc:46
Here is the call graph for this function:

Member Function Documentation

◆ addPorts()

void minsky::Lock::addPorts ( )

Definition at line 46 of file lock.cc.

Referenced by Lock().

47  {
48  m_ports.clear();
49  m_ports.emplace_back(make_shared<Port>(*this));
50  m_ports[0]->moveTo(x()+15,y());
51  m_ports.emplace_back(make_shared<InputPort>(*this));
52  m_ports[1]->moveTo(x()-15,y());
53  }
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
ItemPortVector m_ports
Definition: item.h:156
Here is the caller graph for this function:

◆ applyLockedStateToRavel()

void minsky::Lock::applyLockedStateToRavel ( ) const

Definition at line 142 of file lock.cc.

143  {
144  if (auto ravel=ravelInput())
145  ravel->applyState(lockedState);
146  }
Ravel * ravelInput() const
Ravel this is connected to. nullptr if not connected to a Ravel.
Definition: lock.cc:55
ravel::RavelState lockedState
Definition: lock.h:37

◆ draw()

void minsky::Lock::draw ( cairo_t *  cairo) const
overridevirtual

draw this item into a cairo context

Reimplemented from minsky::Item.

Definition at line 81 of file lock.cc.

References minsky::SVGRenderer::height(), minsky::SVGRenderer::render(), and minsky::SVGRenderer::width().

82  {
83  const float z=zoomFactor()*scaleFactor();
84  const float w=iWidth()*z, h=iHeight()*z;
85 
86  {
87  const ecolab::cairo::CairoSave cs(cairo);
88  cairo_translate(cairo,-0.5*w,-0.5*h);
89  SVGRenderer* icon=locked()? &lockedIcon: &unlockedIcon;
90  cairo_scale(cairo, w/icon->width(), h/icon->height());
91  icon->render(cairo);
92  }
93 
94  if (mouseFocus)
95  {
96  drawPorts(cairo);
97  displayTooltip(cairo,tooltip());
99  }
100 
101  // add 8 pt margin to allow for ports
102  cairo_rectangle(cairo,-0.5*w-8,-0.5*h-8,w+16,h+8);
103  cairo_clip(cairo);
104  if (selected) drawSelected(cairo);
105  }
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
float iHeight() const
Definition: item.h:224
bool onResizeHandles
set to true to indicate mouse is ovcaler resize handles
Definition: item.h:175
virtual std::string const & tooltip() const
Definition: noteBase.h:36
virtual float zoomFactor() const
Definition: item.cc:121
bool locked() const
Definition: lock.h:39
static SVGRenderer lockedIcon
Definition: lock.h:42
static void drawSelected(cairo_t *cairo)
Definition: item.cc:308
float iWidth() const
Definition: item.h:217
virtual void drawResizeHandles(cairo_t *cairo) const
Definition: item.cc:343
bool selected
true if selected for cut, copy or group operation
Definition: noteBase.h:32
virtual float scaleFactor() const
factor by which item has been resized
Definition: item.cc:128
bool mouseFocus
true if target of a mouseover
Definition: noteBase.h:31
static SVGRenderer unlockedIcon
Definition: lock.h:43
void render(cairo_t *) const
Definition: SVGItem.cc:82
Here is the call graph for this function:

◆ locked()

bool minsky::Lock::locked ( ) const
inline

Definition at line 39 of file lock.h.

References lockedState.

Referenced by MathDAG::LockDAG::addEvalOps(), and MathDAG::SystemOfEquations::makeDAG().

39 {return !lockedState.empty();}
ravel::RavelState lockedState
Definition: lock.h:37
Here is the caller graph for this function:

◆ operator=()

Lock& minsky::Lock::operator= ( const Lock x)
default

◆ ravelInput()

Ravel * minsky::Lock::ravelInput ( ) const

Ravel this is connected to. nullptr if not connected to a Ravel.

Definition at line 55 of file lock.cc.

Referenced by MathDAG::SystemOfEquations::makeDAG().

56  {
57  if (auto inputPort=ports(1).lock())
58  if (!inputPort->wires().empty())
59  if (auto fromPort=inputPort->wires()[0]->from())
60  return dynamic_cast<Ravel*>(&fromPort->item());
61  return nullptr;
62  }
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 caller graph for this function:

◆ toggleLocked()

void minsky::Lock::toggleLocked ( )

Definition at line 65 of file lock.cc.

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

66  {
67  if (locked())
68  lockedState.clear();
69  else
70  if (auto* r=ravelInput())
71  {
72  // need to a full reset at this point, not delayed
74  lockedState=r->getState();
75  tooltip(ravel::Ravel::description(lockedState));
76  }
77  else
78  throw_error("Locks can only be applied to Ravels");
79  }
Ravel * ravelInput() const
Ravel this is connected to. nullptr if not connected to a Ravel.
Definition: lock.cc:55
void reset()
resets the variables back to their initial values
Definition: minsky.cc:866
virtual std::string const & tooltip() const
Definition: noteBase.h:36
ravel::RavelState lockedState
Definition: lock.h:37
bool locked() const
Definition: lock.h:39
void throw_error(const std::string &) const
mark item on canvas, then throw
Definition: item.cc:86
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ units()

Units minsky::Lock::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 107 of file lock.cc.

108  {
109  if (locked())
110  {
111  if (auto* r=ravelInput())
112  if (auto p=r->ports(1).lock())
113  {
114  Units inputUnits=p->units(check);
115  if (inputUnits.empty()) return inputUnits;
116  size_t multiplier=1;
117  // at this stage, gross up exponents by the handle size of each
118  // reduced by product handles
119  for (const auto& h: lockedState.handleStates)
120  if (h.collapsed && h.reductionOp==ravel::Op::prod)
121  {
122  // find which handle number this is
123  // TODO - is there a way of avoiding this second loop?
124  size_t i=0;
125  for (; i<r->maxRank(); ++i)
126  if (r->handleDescription(i)==h.description)
127  {
128  multiplier*=r->numSliceLabels(i);
129  break;
130  }
131  }
132  if (multiplier>1)
133  for (auto& u: inputUnits)
134  u.second*=multiplier;
135  return inputUnits;
136  }
137  return {};
138  }
139  return m_ports[1]->units(check);
140  }
Ravel * ravelInput() const
Ravel this is connected to. nullptr if not connected to a Ravel.
Definition: lock.cc:55
ravel::RavelState lockedState
Definition: lock.h:37
bool locked() const
Definition: lock.h:39
ItemPortVector m_ports
Definition: item.h:156

Member Data Documentation

◆ lockedIcon

SVGRenderer minsky::Lock::lockedIcon
static

Definition at line 42 of file lock.h.

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

◆ lockedState

ravel::RavelState minsky::Lock::lockedState

Definition at line 37 of file lock.h.

Referenced by MathDAG::LockDAG::addEvalOps(), and locked().

◆ unlockedIcon

SVGRenderer minsky::Lock::unlockedIcon
static

Definition at line 43 of file lock.h.

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


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