Minsky: 3.17.0
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 RESTProcess (classdesc::RESTProcess_t &rp, const std::string &d) override
 
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
 
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 ()=default
 
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 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 =20
 
double m_height =20
 
ItemPortVector m_ports
 
minsky::Item::MemoisedRotator memoisedRotator
 

Detailed Description

Definition at line 29 of file intOp.h.

Member Typedef Documentation

◆ Super

Definition at line 31 of file intOp.h.

Constructor & Destructor Documentation

◆ IntOp() [1/2]

minsky::IntOp::IntOp ( )
inline

Definition at line 43 of file intOp.h.

References description().

43  {
44  description("");
45  }
std::string description() const
name of the associated integral variable
Definition: intOp.h:54
Here is the call graph for this function:

◆ IntOp() [2/2]

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

Definition at line 47 of file intOp.h.

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

47 : 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:54
ItemT< IntOp, Operation< minsky::OperationType::integrate > > Super
Definition: intOp.h:31
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:70
Here is the call graph for this function:

◆ ~IntOp()

minsky::IntOp::~IntOp ( )
inline

Definition at line 48 of file intOp.h.

48 {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 80 of file intOp.h.

References m_coupled.

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

80 {return m_coupled;}
bool m_coupled
Definition: intOp.h:36
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 211 of file intOp.cc.

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

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

References intVar.

Referenced by description(), and IntOp().

54 {return intVar? intVar->name(): "";}
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:70
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 37 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().

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

◆ insertControlled()

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

Definition at line 193 of file intOp.cc.

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

194  {
195  selection.ensureItemInserted(intVar);
196  }
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:70
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 72 of file intOp.h.

References intVar.

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

◆ operator=()

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

Definition at line 198 of file intOp.cc.

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

199  {
201  intVar.reset(x.intVar->clone());
202  return *this;
203  }
virtual float x() const
Definition: item.cc:107
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:70
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 314 of file intOp.cc.

References minsky::Item::x().

315  {::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:314
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 57 of file intOp.h.

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

57  {
58  // if coupled, the output port is the intVar's output
59  if (i==0 && coupled() && intVar) return intVar->ports(0);
60  return Item::ports(i);
61  }
bool coupled() const
Definition: intOp.h:80
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:70
virtual std::weak_ptr< Port > ports(std::size_t i) const
callback to be run when item deleted from group
Definition: item.h:177
Here is the call graph for this function:

◆ removeControlledItems()

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

Definition at line 205 of file intOp.cc.

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

206  {
207  if (intVar)
208  g.removeItem(*intVar);
209  }
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:70
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 181 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().

182  {
183  const float invZ=1.0/zoomFactor();
184  this->moveTo(0.5*(b.x0+b.x1), 0.5*(b.y0+b.y1));
185  iWidth(0.5*std::abs(b.x1-b.x0)*invZ);
186  // Ensure int op height and var height similar to make gripping resize handle easier. for ticket 1203.
187  iHeight(0.25*std::abs(b.y1-b.y0)*invZ);
188  intVar->iWidth(0.5*std::abs(b.x1-b.x0)*invZ);
189  intVar->iHeight(0.5*std::abs(b.y1-b.y0)*invZ);
190  bb.update(*this);
191  }
float iHeight() const
Definition: item.h:221
BoundingBox bb
canvas bounding box.
Definition: item.h:192
virtual float zoomFactor() const
Definition: item.cc:121
void update(const Item &x)
Definition: item.cc:46
float iWidth() const
Definition: item.h:214
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:70
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 282 of file intOp.cc.

References minsky::Item::bb, coupled(), minsky::group, 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().

283  {
284  if (type()!=integrate) return false;
285 
286  assert(intVar);
287 
288  assert(m_ports.size()==3);
289  if (m_coupled)
290  {
291  const WirePtr newWire(new Wire(m_ports[0], intVar->ports(1)));
292  if (auto g=group.lock())
293  g->addWire(newWire);
294  else
295  minsky().model->addWire(newWire);
296  intVar->controller.reset();
297  intVar->rotation(rotation());
298  }
299  else
300  {
301  if (auto g=group.lock())
302  {
303  for (auto w: intVar->ports(1).lock()->wires())
304  g->removeWire(*w);
305  intVar->controller=g->findItem(*this);
306  }
307  intVar->mouseFocus=false; // prevent drawing of variable ports when coupled
308  }
310  bb.update(*this); // adjust bounding box for coupled integral operation - see ticket #1055
311  return coupled();
312  }
std::shared_ptr< Wire > WirePtr
Definition: wire.h:98
BoundingBox bb
canvas bounding box.
Definition: item.h:192
bool coupled() const
Definition: intOp.h:80
void update(const Item &x)
Definition: item.cc:46
VariablePtr intVar
return reference to integration variable
Definition: intOp.h:70
ItemPortVector m_ports
Definition: item.h:154
bool m_coupled
Definition: intOp.h:36
GroupPtr model
Definition: minsky.h:242
Minsky & minsky()
global minsky object
Definition: addon.cc:545
double rotation() const
Definition: item.h:208
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 29 of file intOp.cc.

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

29  {
30  Units r=m_ports[1]->units(check);
31  if (!cminsky().timeUnit.empty())
32  r[cminsky().timeUnit]++;
33  r.normalise();
34  return r;
35  }
std::string timeUnit
Definition: simulation.h:35
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
ItemPortVector m_ports
Definition: item.h:154
static constexpr float r
Definition: operationBase.h:53
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 317 of file intOp.cc.

References minsky::Item::x().

318  {::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:317
Here is the call graph for this function:

◆ valueId()

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

Definition at line 63 of file intOp.h.

References intVar.

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

Friends And Related Function Documentation

◆ SchemaHelper

friend struct SchemaHelper
friend

Definition at line 35 of file intOp.h.

Member Data Documentation

◆ intVar

VariablePtr minsky::IntOp::intVar

return reference to integration variable

Definition at line 70 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 41 of file intOp.h.

Referenced by draw().

◆ m_coupled

bool minsky::IntOp::m_coupled =true
private

Definition at line 36 of file intOp.h.

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


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