Minsky
minsky::IntOp Class Reference

#include <intOp.h>

Inheritance diagram for minsky::IntOp:
Inheritance graph
Collaboration diagram for minsky::IntOp:
Collaboration graph

Public Member Functions

 IntOp ()
 
 IntOp (const IntOp &x)
 
 ~IntOp ()
 
IntOpoperator= (const IntOp &x)
 
std::weak_ptr< Portports (std::size_t i) const override
 callback to be run when item deleted from group More...
 
std::string valueId () const
 
void draw (cairo_t *) const override
 draw this item into a cairo context More...
 
void resize (const LassoBox &b) override
 resize this item on the canvas More...
 
bool onKeyPress (int keySym, const std::string &utf8, int state) override
 respond to key press events More...
 
bool toggleCoupled ()
 toggles coupled state of integration variable. Only valid for integrate More...
 
bool coupled () const
 
Units units (bool) const override
 compute the dimensional units More...
 
void pack (classdesc::pack_t &x, const std::string &d) const override
 
void unpack (classdesc::unpack_t &x, const std::string &d) override
 
std::string description (const std::string &desc)
 name of the associated integral variable More...
 
std::string description () const
 name of the associated integral variable More...
 
- Public Member Functions inherited from minsky::ItemT< IntOp, Operation< minsky::OperationType::integrate > >
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::Operation< minsky::OperationType::integrate >
Type type () const override
 
void iconDraw (cairo_t *) const override
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *cairo) const
 visual representation of operation on the canvas More...
 
void iconDraw (cairo_t *) const
 visual representation of operation on the canvas More...
 
std::size_t numPorts () const override
 
 Operation ()
 
 Operation (const Operation &x)
 
 Operation (Operation &&x)
 
Operationoperator= (const Operation &x)
 
Operationoperator= (Operation &&x)
 
std::string classType () const override
 
- Public Member Functions inherited from minsky::ItemT< Operation< T >, OperationBase >
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
 
 ItemT ()=default
 
 ItemT (const ItemT &)=default
 
 ItemT (ItemT &&)=delete
 
ItemToperator= (const ItemT &)=default
 
ItemToperator= (ItemT &&)=delete
 
- Public Member Functions inherited from minsky::OperationBase
const OperationBaseoperationCast () const override
 
OperationBaseoperationCast () override
 
std::string portValues () const
 returns a list of values the ports currently have More...
 
bool multiWire () const
 
virtual void addPorts ()
 
void drawUserFunction (cairo_t *cairo) const
 
void draw (cairo_t *) const override
 draw this item into a cairo context More...
 
void resize (const LassoBox &b) override
 resize this item on the canvas More...
 
float scaleFactor () const override
 factor by which item has been resized More...
 
double value () const override
 current value of output port More...
 
std::vector< std::string > dimensions () const
 return dimension names of tensor object attached to input if binary op, then the union of dimension names is returned More...
 
Units units (bool check=false) const override
 compute the dimensional units 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 ()
 
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)
 
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 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 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 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 Member Functions inherited from minsky::IntOpAccessor
 IntOpAccessor ()
 

Public Attributes

VariablePtr intVar
 return reference to integration variable More...
 
- Public Attributes inherited from minsky::OperationBase
double arg =1
 operation argument. For example, the offset used in a difference operator, or binsize in a binning op More...
 
std::string axis
 axis selector in tensor operations 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 constexpr float intVarOffset =10
 
- Static Public Attributes inherited from minsky::OperationBase
static constexpr float l =-8
 
static constexpr float h =12
 
static constexpr float r =12
 

Private Types

typedef ItemT< IntOp, Operation< minsky::OperationType::integrate > > Super
 

Private Member Functions

 CLASSDESC_ACCESS (IntOp)
 integration variable associated with this op. More...
 
void insertControlled (Selection &selection) override
 
void removeControlledItems (minsky::GroupItems &) override
 

Private Attributes

bool m_coupled =true
 

Friends

struct SchemaHelper
 

Additional Inherited Members

- Public Types inherited from minsky::Operation< minsky::OperationType::integrate >
typedef OperationType::Type Type
 
- Public Types inherited from minsky::OperationBase
typedef OperationType::Type Type
 
- Public Types inherited from minsky::OperationType
enum  Type {
  constant, time, integrate, differentiate,
  data, ravel, euler, pi,
  zero, one, inf, percent,
  add, subtract, multiply, divide,
  min, max, and_, or_,
  log, pow, polygamma, lt,
  le, eq, userFunction, copy,
  sqrt, exp, ln, sin,
  cos, tan, asin, acos,
  atan, sinh, cosh, tanh,
  abs, floor, frac, not_,
  Gamma, fact, sum, product,
  infimum, supremum, any, all,
  infIndex, supIndex, runningSum, runningProduct,
  difference, differencePlus, innerProduct, outerProduct,
  index, gather, meld, merge,
  slice, size, shape, mean,
  median, stdDev, moment, histogram,
  covariance, correlation, linearRegression, numOps
}
 
enum  Group {
  general, constop, binop, function,
  reduction, scan, tensor, statistics
}
 
- Static Public Member Functions inherited from minsky::OperationBase
static OperationBasecreate (Type type)
 factory method. More...
 
- Static Public Member Functions inherited from minsky::Item
static void drawSelected (cairo_t *cairo)
 
- Static Public Member Functions inherited from minsky::OperationType
static std::string typeName (int type)
 return the symbolic name of type More...
 
static Group classify (Type t)
 
- Protected Member Functions inherited from minsky::OperationBase
void setCachedText (cairo_t *, const std::string &, double) const
 check if cachedPango is up to date, and if not recreate More...
 
- 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::OperationBase
classdesc::Exclude< std::shared_ptr< ecolab::Pango > > cachedPango
 
- 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 31 of file intOp.h.

Member Typedef Documentation

◆ Super

Definition at line 34 of file intOp.h.

Constructor & Destructor Documentation

◆ IntOp() [1/2]

minsky::IntOp::IntOp ( )
inline

Definition at line 46 of file intOp.h.

References description().

46  {
47  description("");
48  }
std::string description() const
name of the associated integral variable
Definition: intOp.h:57
Here is the call graph for this function:

◆ IntOp() [2/2]

minsky::IntOp::IntOp ( const IntOp x)
inline

Definition at line 50 of file intOp.h.

References description(), intVar, and minsky::Item::x().

50 : Super(x) {intVar.reset(); description(x.description());}
virtual float x() const
Definition: item.cc:107
std::string description() const
name of the associated integral variable
Definition: intOp.h:57
ItemT< IntOp, Operation< minsky::OperationType::integrate > > Super
Definition: intOp.h:34
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
Here is the call graph for this function:

◆ ~IntOp()

minsky::IntOp::~IntOp ( )
inline

Definition at line 51 of file intOp.h.

51 {Item::removeControlledItems();}

Member Function Documentation

◆ CLASSDESC_ACCESS()

minsky::IntOp::CLASSDESC_ACCESS ( IntOp  )
private

integration variable associated with this op.

◆ coupled()

bool minsky::IntOp::coupled ( ) const
inline

Definition at line 83 of file intOp.h.

References m_coupled.

Referenced by draw(), ports(), and toggleCoupled().

83 {return m_coupled;}
bool m_coupled
Definition: intOp.h:39
Here is the caller graph for this function:

◆ description() [1/2]

string minsky::IntOp::description ( const std::string &  desc)

name of the associated integral variable

Definition at line 214 of file intOp.cc.

References minsky::Item::bb, minsky::Minsky::convertVarType(), description(), minsky::VariableType::integral, intVar, m_coupled, minsky::minsky(), minsky::Minsky::model, minsky::VariableValues::newName(), minsky::BoundingBox::update(), minsky::valueId(), and minsky::Minsky::variableValues.

215  {
216  auto desc=a_desc;
217 
218  // set a default name if none given
219  if (desc.empty())
220  desc=minsky().variableValues.newName(minsky::valueId(group.lock(),"int"));
221 
222  // disallow global integration variables
223  if (desc[0]==':') desc=desc.substr(1);
224 
225  if (intVar && intVar->group.lock() == group.lock() && intVar->name()==desc)
226  return description(); // nothing to do
227 
228  vector<Wire> savedWires;
229  if (intVar && intVar->portsSize()>0)
230  {
231  // save any attached wires for later use
232  for (auto w: intVar->ports(0).lock()->wires())
233  savedWires.push_back(*w);
234  }
235 
236  // if the variable name exists, and already has a connected
237  // input, then it is not a candidate for being an integral
238  // variable, so generate a new name that doesn't currently
239  // exist
240 
241  const string vid=minsky::valueId(group.lock(),desc);
242  auto i=minsky().variableValues.find(vid);
243  if (i!=minsky().variableValues.end())
244  {
245  if (i->second->type()!=VariableType::integral)
246  try
247  {
249  }
250  catch (...)
251  {
252  desc=minsky().variableValues.newName(vid);
253  }
254  else
255  if (minsky().definingVar(vid)) // Also check that integral has input. for ticket 1068.
256  desc=minsky().variableValues.newName(vid);
257  else
258  desc=vid;
259  if (desc[0]==':') desc=desc.substr(1);// disallow global integration variables
260  }
261 
262 
263  ItemPtr oldIvar;
264  if (intVar)
265  oldIvar=minsky().model->removeItem(*intVar);
266 
267  intVar.reset(new Variable<VariableType::integral>(desc));
268  if (auto g=group.lock())
269  intVar->controller=g->findItem(*this); // we're managing our own display
270  // initialise in toggled state
271  m_coupled=true;
272 
273  // recreate any previously attached wires, initially in global group.
274  for (auto& w: savedWires)
275  minsky().model->addWire(new Wire(intVar->ports(0), w.to(), w.coords()));
276 
277  bb.update(*this); // adjust icon bounding box - see ticket #704
278 
279  // this should also adjust the wire's group ownership appropriately
280  if (auto g=group.lock())
281  g->addItem(intVar);
282  return description();
283  }
std::string newName(const std::string &name) const
generate a new valueId not otherwise in the system
VariableValues variableValues
Definition: minsky.h:200
std::string description() const
name of the associated integral variable
Definition: intOp.h:57
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
BoundingBox bb
canvas bounding box.
Definition: item.h:195
void update(const Item &x)
Definition: item.cc:46
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
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
bool m_coupled
Definition: intOp.h:39
GroupPtr model
Definition: minsky.h:255
Definition: group.tcl:84
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ description() [2/2]

std::string minsky::IntOp::description ( ) const
inline

name of the associated integral variable

Definition at line 57 of file intOp.h.

References intVar.

Referenced by description(), and IntOp().

57 {return intVar? intVar->name(): "";}
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
Here is the caller graph for this function:

◆ draw()

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

draw this item into a cairo context

Reimplemented from minsky::Item.

Definition at line 40 of file intOp.cc.

References coupled(), minsky::Item::displayTooltip(), minsky::RenderVariable::draw(), minsky::DrawBinOp::drawPort(), minsky::Item::drawPorts(), minsky::BottomRightResizerItem::drawResizeHandles(), minsky::Item::drawSelected(), minsky::DrawBinOp::drawSymbol(), minsky::OperationBase::h, minsky::RenderVariable::height(), minsky::Item::iHeight(), intVar, intVarOffset, minsky::Item::iWidth(), minsky::OperationBase::l, M_PI, minsky::Item::m_ports, minsky::NoteBase::mouseFocus, minsky::Operation< minsky::OperationType::integrate >::numPorts(), minsky::Item::onResizeHandles, minsky::OperationBase::r, minsky::Item::rotation(), minsky::Item::rotationAsRadians(), minsky::OperationBase::scaleFactor(), minsky::NoteBase::selected, minsky::NoteBase::tooltip(), minsky::RenderVariable::width(), minsky::Item::x(), minsky::Item::y(), and minsky::Item::zoomFactor().

41  {
42  // if rotation is in 1st or 3rd quadrant, rotate as
43  // normal, otherwise flip the text so it reads L->R
44  auto [angle,textFlipped]=rotationAsRadians();
45  double coupledIntTranslation=0;
46  const float z=zoomFactor();
47 
50 
51  if (fabs(l)<iWidth()*z) l=-iWidth()*z;
52  if (r<iWidth()*z) r=iWidth()*z;
53  if (h<iHeight()*z) h=iHeight()*z;
54 
55  if (coupled() && intVar)
56  {
57  const cairo::CairoSave cs(cairo);
58  auto& iv=*intVar;
59  const RenderVariable rv(iv,cairo);
60  // we need to add some translation if the variable is bound
61  cairo_rotate(cairo,angle);
62  coupledIntTranslation=-0.5*(intVarOffset+2*rv.width()+2+r)*z;
63  if (rv.width()<iv.iWidth()) coupledIntTranslation=-0.5*(intVarOffset+2*iv.iWidth()+2+r)*z;
64  }
65 
66 
67  {
68  const cairo::CairoSave cs(cairo);
69  cairo_rotate(cairo, angle);
70  cairo_scale(cairo,z,z);
71  if (textFlipped) cairo_rotate(cairo, M_PI);
72  const double sf = scaleFactor();
73  cairo_scale(cairo,sf,sf);
74  cairo_move_to(cairo,-7,3.5);
75  cairo_show_text(cairo,"∫dt");
76  }
77  DrawBinOp d(cairo, zoomFactor());
78  d.drawPort([&](){d.drawSymbol("0");}, l,h,rotation());
79  d.drawPort([&](){d.drawSymbol("f");}, l,-h,rotation());
80 
81  cairo_save(cairo);
82  cairo_rotate(cairo, angle);
83 
84  int intVarWidth=0;
85 
86 
87  cairo_move_to(cairo,l,h);
88  cairo_line_to(cairo,l,-h);
89  cairo_line_to(cairo,r,0);
90 
91  cairo_close_path(cairo);
92 
93  cairo_set_source_rgb(cairo,0,0,1);
94  cairo_stroke_preserve(cairo);
95 
96  if (coupled() && intVar)
97  {
98  const float ivo=intVarOffset*z;
99  cairo_new_path(cairo);
100  cairo_move_to(cairo,r,0);
101  cairo_line_to(cairo,r+ivo,0);
102  cairo_set_source_rgb(cairo,0,0,0);
103  cairo_stroke(cairo);
104 
105  // display an integration variable next to it
106  RenderVariable rv(*intVar, cairo);
107  // save the render width for later use in setting the clip
108  intVarWidth=rv.width()*z;
109  if (rv.width()<intVar->iWidth()) intVarWidth=0.5*intVar->iWidth()*z;
110  // set the port location...
111  const Rotate rot(rotation(), x(), y());
112  auto ivp=rot(x()+r+ivo+intVarWidth, y());
113  intVar->moveTo(ivp.x(), ivp.y());
114 
115  cairo_save(cairo);
116  cairo_translate(cairo,r+ivo+intVarWidth,0);
117  // to get text to render correctly, we need to set
118  // the var's rotation, then antirotate it
119  intVar->rotation(rotation());
120  cairo_rotate(cairo, -M_PI*rotation()/180.0);
121  rv.draw();
122  cairo_restore(cairo);
123 
124  // build clip path the hard way grr...
125  cairo_move_to(cairo,l,h);
126  cairo_line_to(cairo,l,-h);
127  cairo_line_to(cairo,r,0);
128  cairo_line_to(cairo,r+ivo,0);
129  float rvw=rv.width()*z, rvh=rv.height()*z;
130  if (rv.width()<intVar->iWidth()) rvw=intVar->iWidth()*z;
131  if (rv.height()<intVar->iHeight()) rvh=intVar->iHeight()*z;
132  cairo_line_to(cairo,r+ivo,-rvh);
133  cairo_line_to(cairo,r+ivo+2*rvw,-rvh);
134  cairo_line_to(cairo,r+ivo+2*rvw+2*z,0);
135  cairo_line_to(cairo,r+ivo+2*rvw,rvh);
136  cairo_line_to(cairo,r+ivo,rvh);
137  cairo_line_to(cairo,r+ivo,0);
138  cairo_line_to(cairo,r,0);
139  cairo_close_path(cairo);
140  }
141 
142  cairo::Path clipPath(cairo);
143 
144  double x0=r, y0=0, x1=l, y1=numPorts() > 2? -h+3: 0,
145  x2=l, y2=numPorts() > 2? h-3: 0;
146 
147  if (textFlipped) swap(y1,y2);
148 
149  // adjust for integration variable
150  if (coupled())
151  x0+=intVarOffset+2*intVarWidth+2;
152 
153  cairo_save(cairo);
154  cairo_identity_matrix(cairo);
155  cairo_translate(cairo, x(), y());
156  cairo_rotate(cairo, angle);
157  cairo_user_to_device(cairo, &x0, &y0);
158  cairo_user_to_device(cairo, &x1, &y1);
159  cairo_user_to_device(cairo, &x2, &y2);
160  cairo_restore(cairo);
161 
162  if (numPorts()>0)
163  m_ports[0]->moveTo(x0, y0);
164  if (numPorts()>1)
165  m_ports[1]->moveTo(x1, y1);
166  if (numPorts()>2)
167  m_ports[2]->moveTo(x2, y2);
168 
169  cairo_translate(cairo,-coupledIntTranslation,0);
170  cairo_restore(cairo); // undo rotation
171  if (mouseFocus)
172  {
173  drawPorts(cairo);
174  displayTooltip(cairo,tooltip());
175  }
176  if (onResizeHandles) drawResizeHandles(cairo);
177 
178  cairo_new_path(cairo);
179  clipPath.appendToCurrent(cairo);
180  cairo_clip(cairo);
181  if (selected) drawSelected(cairo);
182  }
#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
float iHeight() const
Definition: item.h:224
bool onResizeHandles
set to true to indicate mouse is ovcaler resize handles
Definition: item.h:175
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
virtual std::string const & tooltip() const
Definition: noteBase.h:36
virtual float zoomFactor() const
Definition: item.cc:121
bool coupled() const
Definition: intOp.h:83
static constexpr float l
Definition: operationBase.h:58
static void drawSelected(cairo_t *cairo)
Definition: item.cc:308
float iWidth() const
Definition: item.h:217
float scaleFactor() const override
factor by which item has been resized
Definition: operation.cc:135
static constexpr float h
Definition: operationBase.h:58
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
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
static constexpr float r
Definition: operationBase.h:58
static constexpr float intVarOffset
Definition: intOp.h:44
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:

◆ insertControlled()

void minsky::IntOp::insertControlled ( Selection selection)
overrideprivate

Definition at line 196 of file intOp.cc.

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

197  {
198  selection.ensureItemInserted(intVar);
199  }
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
Here is the call graph for this function:

◆ onKeyPress()

bool minsky::IntOp::onKeyPress ( int  keySym,
const std::string &  utf8,
int  state 
)
inlineoverridevirtual

respond to key press events

Returns
true if it needs to be rerendered

Reimplemented from minsky::Item.

Definition at line 75 of file intOp.h.

References intVar.

75  {
76  if (intVar) return intVar->onKeyPress(keySym, utf8, state);
77  return false;
78  }
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73

◆ operator=()

IntOp & minsky::IntOp::operator= ( const IntOp x)

Definition at line 201 of file intOp.cc.

References intVar, minsky::ItemT< IntOp, Operation< minsky::OperationType::integrate > >::operator=(), and minsky::Item::x().

202  {
204  intVar.reset(x.intVar->clone());
205  return *this;
206  }
virtual float x() const
Definition: item.cc:107
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
Here is the call graph for this function:

◆ pack()

void minsky::IntOp::pack ( classdesc::pack_t &  x,
const std::string &  d 
) const
override

Definition at line 317 of file intOp.cc.

References minsky::Item::x().

318  {::pack(x,d,*this);}
virtual float x() const
Definition: item.cc:107
void pack(classdesc::pack_t &x, const std::string &d) const override
Definition: intOp.cc:317
Here is the call graph for this function:

◆ ports()

std::weak_ptr<Port> minsky::IntOp::ports ( std::size_t  i) const
inlineoverridevirtual

callback to be run when item deleted from group

return a weak reference to the ith port

Reimplemented from minsky::Item.

Definition at line 60 of file intOp.h.

References coupled(), intVar, and minsky::Item::ports().

60  {
61  // if coupled, the output port is the intVar's output
62  if (i==0 && coupled() && intVar) return intVar->ports(0);
63  return Item::ports(i);
64  }
bool coupled() const
Definition: intOp.h:83
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
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:

◆ removeControlledItems()

void minsky::IntOp::removeControlledItems ( minsky::GroupItems g)
overrideprivate

Definition at line 208 of file intOp.cc.

References intVar, and minsky::GroupItems::removeItem().

209  {
210  if (intVar)
211  g.removeItem(*intVar);
212  }
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
ItemPtr removeItem(const Item &)
Definition: group.cc:212
Here is the call graph for this function:

◆ resize()

void minsky::IntOp::resize ( const LassoBox b)
overridevirtual

resize this item on the canvas

Reimplemented from minsky::Item.

Definition at line 184 of file intOp.cc.

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

185  {
186  const float invZ=1.0/zoomFactor();
187  this->moveTo(0.5*(b.x0+b.x1), 0.5*(b.y0+b.y1));
188  iWidth(0.5*std::abs(b.x1-b.x0)*invZ);
189  // Ensure int op height and var height similar to make gripping resize handle easier. for ticket 1203.
190  iHeight(0.25*std::abs(b.y1-b.y0)*invZ);
191  intVar->iWidth(0.5*std::abs(b.x1-b.x0)*invZ);
192  intVar->iHeight(0.5*std::abs(b.y1-b.y0)*invZ);
193  bb.update(*this);
194  }
float iHeight() const
Definition: item.h:224
BoundingBox bb
canvas bounding box.
Definition: item.h:195
virtual float zoomFactor() const
Definition: item.cc:121
void update(const Item &x)
Definition: item.cc:46
float iWidth() const
Definition: item.h:217
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
void moveTo(float x, float y)
Definition: item.cc:256
Here is the call graph for this function:

◆ toggleCoupled()

bool minsky::IntOp::toggleCoupled ( )

toggles coupled state of integration variable. Only valid for integrate

Returns
coupled state

Definition at line 285 of file intOp.cc.

References minsky::Item::bb, coupled(), minsky::OperationType::integrate, intVar, m_coupled, minsky::Item::m_ports, minsky::minsky(), minsky::Minsky::model, minsky::Item::rotation(), minsky::Operation< minsky::OperationType::integrate >::type(), and minsky::BoundingBox::update().

286  {
287  if (type()!=integrate) return false;
288 
289  assert(intVar);
290 
291  assert(m_ports.size()==3);
292  if (m_coupled)
293  {
294  const WirePtr newWire(new Wire(m_ports[0], intVar->ports(1)));
295  if (auto g=group.lock())
296  g->addWire(newWire);
297  else
298  minsky().model->addWire(newWire);
299  intVar->controller.reset();
300  intVar->rotation(rotation());
301  }
302  else
303  {
304  if (auto g=group.lock())
305  {
306  for (auto w: intVar->ports(1).lock()->wires())
307  g->removeWire(*w);
308  intVar->controller=g->findItem(*this);
309  }
310  intVar->mouseFocus=false; // prevent drawing of variable ports when coupled
311  }
313  bb.update(*this); // adjust bounding box for coupled integral operation - see ticket #1055
314  return coupled();
315  }
std::shared_ptr< Wire > WirePtr
Definition: wire.h:102
BoundingBox bb
canvas bounding box.
Definition: item.h:195
bool coupled() const
Definition: intOp.h:83
void update(const Item &x)
Definition: item.cc:46
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73
ItemPortVector m_ports
Definition: item.h:156
bool m_coupled
Definition: intOp.h:39
GroupPtr model
Definition: minsky.h:255
Definition: group.tcl:84
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
double rotation() const
Definition: item.h:211
Here is the call graph for this function:

◆ units()

Units minsky::IntOp::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 32 of file intOp.cc.

References minsky::cminsky(), minsky::Item::m_ports, minsky::OperationBase::r, minsky::Simulation::timeUnit, and minsky::timeUnit.

32  {
33  Units r=m_ports[1]->units(check);
34  if (!cminsky().timeUnit.empty())
35  r[cminsky().timeUnit]++;
36  r.normalise();
37  return r;
38  }
std::string timeUnit
Definition: simulation.h:35
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
ItemPortVector m_ports
Definition: item.h:156
static constexpr float r
Definition: operationBase.h:58
UnitsExpressionWalker timeUnit
Here is the call graph for this function:

◆ unpack()

void minsky::IntOp::unpack ( classdesc::unpack_t &  x,
const std::string &  d 
)
override

Definition at line 320 of file intOp.cc.

References minsky::Item::x().

321  {::unpack(x,d,*this);}
virtual float x() const
Definition: item.cc:107
void unpack(classdesc::unpack_t &x, const std::string &d) override
Definition: intOp.cc:320
Here is the call graph for this function:

◆ valueId()

std::string minsky::IntOp::valueId ( ) const
inline

Definition at line 66 of file intOp.h.

References intVar.

67  {return intVar->valueId();}
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:73

Friends And Related Function Documentation

◆ SchemaHelper

friend struct SchemaHelper
friend

Definition at line 38 of file intOp.h.

Member Data Documentation

◆ intVar

VariablePtr minsky::IntOp::intVar

return reference to integration variable

Definition at line 73 of file intOp.h.

Referenced by description(), draw(), insertControlled(), IntOp(), onKeyPress(), operator=(), ports(), removeControlledItems(), resize(), toggleCoupled(), and valueId().

◆ intVarOffset

constexpr float minsky::IntOp::intVarOffset =10
static

Definition at line 44 of file intOp.h.

Referenced by draw().

◆ m_coupled

bool minsky::IntOp::m_coupled =true
private

Definition at line 39 of file intOp.h.

Referenced by coupled(), description(), and toggleCoupled().


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