Minsky
minsky::Group Class Reference

#include <group.h>

Inheritance diagram for minsky::Group:
Inheritance graph
Collaboration diagram for minsky::Group:
Collaboration graph

Classes

struct  IORegion
 returns which I/O region (x,y) is in if any More...
 

Public Member Functions

std::string name () const override
 
double operator() (const std::vector< double > &p) override
 evaluate function on arbitrary number of arguments (exprtk support) More...
 
std::string formula () const
 algebraic formula representing value of first output argument of this group More...
 
std::string arguments () const
 argument declaration, to be appended to name() for function declaration More...
 
 Group ()
 
bool nocycles () const override
 tests that groups are arranged heirarchically without any recurrence More...
 
GroupPtr copy () const
 Make a copy of this as a sibling group (owned by parent). Attempting to copying minsky.model is a null operation. More...
 
GroupPtr copyUnowned () const
 make a copy of this, that is not owned by any group More...
 
Groupclone () const override
 
ItemPtr addItem (const std::shared_ptr< Item > &it, bool inSchema=false) override
 
void makeSubroutine ()
 Make all variables not present in outerscope local to this group. More...
 
void draw (cairo_t *) const override
 draw this item into a cairo context More...
 
void drawEdgeVariables (cairo_t *) const
 draw representations of edge variables around group icon More...
 
void draw1edge (const std::vector< VariablePtr > &vars, cairo_t *cairo, float x) const
 draw the variables of one of the edges More...
 
void drawIORegion (cairo_t *) const
 draw notches in the I/O region to indicate dockability of variables there More...
 
void moveContents (Group &source)
 move all items from source to this More...
 
IORegion::type inIORegion (float x, float y) const
 
void checkAddIORegion (const ItemPtr &x)
 check if item is a variable and located in an I/O region, and add it if it is More...
 
void addInputVar ()
 
void addOutputVar ()
 
void deleteItem (const Item &)
 remove item from group, and also all attached wires. More...
 
void deleteAttachedWires () override
 delete all attached wires More...
 
void resizeOnContents ()
 adjust position and size of icon to just cover contents More...
 
void resize (const LassoBox &x) override
 resize this item on the canvas More...
 
ClickType::Type clickType (float x, float y) const override
 returns the clicktype given a mouse click at x, y. More...
 
bool higher (const Group &) const
 returns true if this is higher in the heirarchy than the argument this->higher(*this) is false More...
 
unsigned level () const
 return level in the heirarchy More...
 
const GroupglobalGroup () const
 top level group More...
 
GroupglobalGroup ()
 
bool uniqueItems (std::set< void *> &idset) const
 returns true if items appear uniquely within the heirarchy. Note the map structure does not guarantee that an item doesn't appear within another group More...
 
bool uniqueItems () const
 
bool displayContents () const
 returns whether contents should be displayed. Top level group always displayed More...
 
bool displayContentsChanged () const
 true if displayContents status changed on this or any contained group last zoom More...
 
void margins (float &left, float &right) const
 margin sizes to allow space for edge variables. More...
 
std::vector< float > marginsV () const
 for debugging purposes More...
 
float computeDisplayZoom ()
 
void computeRelZoom ()
 
float localZoom () const
 
void setZoom (float factor)
 sets the zoom factor to factor. Recursively set the zoomfactor on contained objects to the computed localzoom More...
 
void zoom (float xOrigin, float yOrigin, float factor)
 
float edgeScale () const
 scale used to render io variables. Smoothly interpolates between the scale at which internal items are displayed, and the outside zoom factor More...
 
ecolab::array< double > cBounds () const
 for TCL debugging More...
 
float rotFactor () const
 scaling factor to allow a rotated icon to fit on the bitmap More...
 
ItemPtr select (float x, float y) const override
 returns the variable if point (x,y) is within a I/O variable icon, null otherwise, indicating that the Group has been selected. More...
 
void splitBoundaryCrossingWires ()
 splits any wires that cross group boundaries More...
 
void normaliseGroupRefs (const std::shared_ptr< Group > &self)
 fix up subgroup pointers self is a shared pointer ref to this More...
 
void flipContents ()
 rotate all conatined items by 180 degrees More...
 
std::vector< std::string > accessibleVars () const
 return a list of existing variables a variable in this group could be connected to More...
 
std::vector< std::string > bookmarkList ()
 returns list of bookmark names for populating menu More...
 
void addBookmarkXY (float dx, float dy, const std::string &name)
 
void addBookmark (const std::string &name)
 
void deleteBookmark (std::size_t i)
 
void gotoBookmark_b (const Bookmark &b)
 
void gotoBookmark (std::size_t i)
 
std::string defaultExtension () const
 return default extension for this group - .mky if no ravels in group, .rvl otherwise More...
 
void autoLayout ()
 automatically lay out items in this group using a graph layout algorithm More...
 
void randomLayout ()
 randomly lay out items in this group More...
 
std::vector< SummarysummariseGodleys () const
 produce a summary of godley table variables More...
 
void renameAllInstances (const std::string &valueId, const std::string &newName)
 rename all instances of a variable matching valueId to newName More...
 
ItemPtr addItem (Item *it, bool inSchema=false)
 add item, ownership is passed More...
 
virtual ItemPtr addItem (const std::shared_ptr< Item > &, bool inSchema=false)
 
- Public Member Functions inherited from minsky::ItemT< Group >
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 bool visible () const
 whether this item is visible on the canvas. More...
 
void moveTo (float x, float y)
 
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 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
 
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 ()
 
virtual Units units (bool check=false) const
 compute the dimensional units More...
 
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::GroupItems
 GroupItems ()
 
virtual ~GroupItems ()
 
 GroupItems (const GroupItems &x)
 
GroupItemsoperator= (const GroupItems &)
 
void clear ()
 
bool empty () const
 
template<class M , class C >
const M::value_type findAny (M GroupItems::*map, C c) const
 search for the first item in the heirarchy of map for which c is true. M::value_type must evaluate in a boolean environment to false if not valid C is of signature bool(M::value_type) More...
 
template<class R , class M , class C , class X >
std::vector< R > findAll (C c, M(GroupItems::*m), X xfm) const
 finds all items/wires matching criterion c. Found items are transformed by xfm More...
 
WirePtr removeWire (const Wire &)
 
GroupPtr removeGroup (const Group &)
 
ItemPtr findItem (const Item &it) const
 finds item within this group or subgroups. Returns null if not found More...
 
GroupPtr findGroup (const Group &it) const
 finds group within this group or subgroups. Returns null if not found More...
 
WirePtr findWire (const Wire &it) const
 finds wire within this group or subgroups. Returns null if not found More...
 
template<class C >
std::vector< ItemPtrfindItems (C c) const
 returns list of items matching criterion c More...
 
template<class C >
std::vector< WirePtrfindWires (C c) const
 returns list of wires matching criterion c More...
 
template<class C >
std::vector< GroupPtrfindGroups (C c) const
 returns list of groups matching criterion c More...
 
ItemPtr addItem (Item *it, bool inSchema=false)
 add item, ownership is passed More...
 
ItemPtr removeItem (const Item &)
 
GroupPtr addGroup (const std::shared_ptr< Group > &)
 
GroupPtr addGroup (Group *g)
 
WirePtr addWire (const Item &from, const Item &to, unsigned toPortIdx)
 add a wire from item from, to item to, connecting to the toIdx port of to More...
 
WirePtr addWire (const std::shared_ptr< Wire > &)
 
WirePtr addWire (Wire *w)
 
WirePtr addWire (const std::weak_ptr< Port > &from, const std::weak_ptr< Port > &to)
 
std::size_t numItems () const
 total number of items in this and child groups More...
 
std::size_t numWires () const
 total number of wires in this and child groups More...
 
std::size_t numGroups () const
 total number of groups in this and child groups More...
 
void removeDisplayPlot ()
 remove the display plot More...
 
template<class M , class O >
bool recursiveDo (M GroupItems::*map, O op) const
 Perform action heirarchically on elements of map map. If op returns true, the operation terminates. returns true if operation terminates early, false if every element processed. O has signature bool(M, M::const_iterator) More...
 
template<class M , class O >
bool recursiveDo (M GroupItems::*map, O op)
 O has signature bool(M&, M::iterator) More...
 

Public Attributes

std::string title
 
float displayZoom {1}
 computes the zoom at which to show contents, given current contentBounds and width More...
 
float relZoom {1}
 relative zoom contents of this group are displayed at 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...
 
- Public Attributes inherited from minsky::GroupItems
Items items
 
Groups groups
 
Wires wires
 
std::set< Bookmarkbookmarks
 
std::vector< VariablePtrinVariables
 
std::vector< VariablePtroutVariables
 
std::vector< VariablePtrcreatedIOvariables
 
classdesc::Exclude< std::weak_ptr< Group > > self
 weak ref to this More...
 
classdesc::Exclude< std::shared_ptr< PlotWidget > > displayPlot
 plot widget used for group icon More...
 

Static Public Attributes

static SVGRenderer svgRenderer
 

Protected Member Functions

const GroupminimalEnclosingGroup (float x0, float y0, float x1, float y1, const Item *ignore=nullptr) const
 returns the smallest group whose icon completely encloses the rectangle given by the argument. If no candidate group found, returns nullptr. Weak reference returned, no ownership. More...
 
GroupminimalEnclosingGroup (float x0, float y0, float x1, float y1, const Item *ignore=nullptr)
 
float contentBounds (double &x0, double &y0, double &x1, double &y1) const
 return bounding box coordinates for all variables, operators etc in this group. Returns the zoom scale (aka local zoom) of the contained items, or 1 if the group is empty. More...
 
- Protected Member Functions inherited from minsky::GroupItems
WirePtr addWire (const Item &from, const Item &to, unsigned toPortIdx, const std::vector< float > &coords)
 add a wire from item from, to item to, connecting to the toIdx port of to, with coordinates More...
 
WirePtr addWire (const std::weak_ptr< Port > &from, const std::weak_ptr< Port > &to, const std::vector< float > &coords)
 
void renameVar (const GroupPtr &origGroup, VariableBase &v)
 rename variable so that it maintains most general scope possible More...
 
 CLASSDESC_ACCESS (GroupItems)
 

Private Member Functions

VariablePtr addIOVar (const char *)
 

Private Attributes

bool m_displayContentsChanged =true
 

Friends

class Canvas
 

Additional Inherited Members

- Static Public Member Functions inherited from minsky::Item
static void drawSelected (cairo_t *cairo)
 
- Static Public Member Functions inherited from minsky::GroupItems
static void adjustWiresGroup (Wire &w)
 adjust wire's group to be the least common ancestor of its ports 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::Item
double m_width =10
 
double m_height =10
 
ItemPortVector m_ports
 
minsky::Item::MemoisedRotator memoisedRotator
 

Detailed Description

Definition at line 220 of file group.h.

Constructor & Destructor Documentation

◆ Group()

minsky::Group::Group ( )
inline

Definition at line 249 of file group.h.

References minsky::Item::iHeight(), and minsky::Item::iWidth().

249 {iWidth(100); iHeight(100);}
float iHeight() const
Definition: item.h:224
float iWidth() const
Definition: item.h:217
Here is the call graph for this function:

Member Function Documentation

◆ accessibleVars()

vector< string > minsky::Group::accessibleVars ( ) const

return a list of existing variables a variable in this group could be connected to

Definition at line 1221 of file group.cc.

1222 {
1223  set<string> r;
1224  // first add local variables
1225  for (auto& i: items)
1226  if (auto v=i->variableCast())
1227  r.insert(v->name());
1228  // now add variables in outer scopes, ensuring they qualified
1229  auto g=this;
1230  for (g=g->group.lock().get(); g; g=g->group.lock().get())
1231  for (auto& i: g->items)
1232  if (auto v=i->variableCast())
1233  {
1234  auto n=v->name();
1235  if (n[0]==':')
1236  r.insert(n);
1237  else
1238  r.insert(':'+n);
1239  }
1240 
1241  return vector<string>(r.begin(),r.end());
1242 }

◆ addBookmark()

void minsky::Group::addBookmark ( const std::string &  name)
inline

Definition at line 407 of file group.h.

References addBookmarkXY(), and name().

407 {addBookmarkXY(0,0,name);}
std::string name() const override
Definition: group.h:241
void addBookmarkXY(float dx, float dy, const std::string &name)
Definition: group.h:403
Here is the call graph for this function:

◆ addBookmarkXY()

void minsky::Group::addBookmarkXY ( float  dx,
float  dy,
const std::string &  name 
)
inline

Definition at line 403 of file group.h.

References minsky::GroupItems::bookmarks, name(), relZoom, minsky::Item::x(), minsky::Item::y(), and minsky::Item::zoomFactor().

Referenced by addBookmark(), and addItem().

403  {
404  bookmarks.erase(Bookmark{0,0,0,name});
405  bookmarks.emplace(x()-dx, y()-dy, relZoom*zoomFactor(), name);
406  }
std::string name() const override
Definition: group.h:241
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:348
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
std::set< Bookmark > bookmarks
Definition: group.h:81
virtual float zoomFactor() const
Definition: item.cc:121
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addInputVar()

void minsky::Group::addInputVar ( )
inline

Definition at line 294 of file group.h.

References addIOVar(), and minsky::GroupItems::inVariables.

294 {inVariables.push_back(addIOVar("input"));}
std::vector< VariablePtr > inVariables
Definition: group.h:82
VariablePtr addIOVar(const char *)
Definition: group.cc:519
Here is the call graph for this function:

◆ addIOVar()

VariablePtr minsky::Group::addIOVar ( const char *  prefix)
private

Definition at line 519 of file group.cc.

References minsky::cminsky(), minsky::to_string(), and minsky::uqName().

Referenced by addInputVar(), and addOutputVar().

520  {
521  const VariablePtr v(VariableType::flow,
522  uqName(cminsky().variableValues.newName(to_string(size_t(this))+":"+prefix)));
523  addItem(v,true);
524  createdIOvariables.push_back(v);
525  v->rotation(rotation());
526  v->controller=self;
527  bb.update(*this);
528  return v;
529  }
std::vector< VariablePtr > createdIOvariables
Definition: group.h:83
ItemPtr addItem(const std::shared_ptr< Item > &it, bool inSchema=false) override
Definition: group.h:262
std::string uqName(const std::string &name)
extract unqualified portion of name
Definition: valueId.cc:135
BoundingBox bb
canvas bounding box.
Definition: item.h:195
void update(const Item &x)
Definition: item.cc:46
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
string to_string(CONST84 char *x)
Definition: minskyTCLObj.h:33
double rotation() const
Definition: item.h:211
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addItem() [1/3]

ItemPtr minsky::GroupItems::addItem

add item.

Parameters
inSchema- if building a group from schema processing, rather than generally. Does not adjust item position within group if true.

Definition at line 331 of file group.cc.

332  {
333  if (!it) return it;
335  if (auto x=dynamic_pointer_cast<Group>(it))
336  return addGroup(x);
337 
338  // stash position
339  const float x=it->x(), y=it->y();
340  auto origGroup=it->group.lock();
341 
342  if (origGroup.get()==this) return it; // nothing to do.
343  if (origGroup)
344  origGroup->removeItem(*it);
345 
346  // stash init value to initialise new variableValue
347  string init;
348  string units;
349  if (auto v=it->variableCast())
350  {
351  init=v->init();
352  units=v->unitsStr();
353  }
354 
355  it->group=self;
356  if (!inSchema) it->moveTo(x,y);
357 
358  // take into account new scope
359  if (auto v=it->variableCast())
360  {
361  if (!inSchema && origGroup)
362  renameVar(origGroup, *v);
363  v->init(init); //NB calls ensureValueExists()
364  // if value didn't exist before, units will be empty. Do not overwrite any previous units set. For #1461.
365  if (units.length()) v->setUnits(units);
366  }
367 
368  // move wire to highest common group
369  for (size_t i=0; i<it->portsSize(); ++i)
370  {
371  auto p=it->ports(i).lock();
372  assert(p);
373  for (auto& w: p->wires())
374  {
375  assert(w);
376  adjustWiresGroup(*w);
377  }
378  }
379 
380  // need to deal with integrals especially because of the attached variable
381  if (auto intOp=dynamic_cast<IntOp*>(it.get()))
382  if (intOp->intVar)
383  {
384  if (!inSchema && origGroup)
385  renameVar(origGroup, *intOp->intVar);
386  if (auto oldG=intOp->intVar->group.lock())
387  {
388 
389  if (oldG.get()!=this)
390  addItem(oldG->removeItem(*intOp->intVar),inSchema);
391  }
392  else
393  addItem(intOp->intVar,inSchema);
394  if (intOp->coupled())
395  intOp->intVar->controller=it;
396  else
397  intOp->intVar->controller.reset();
398  }
399 
400  items.push_back(it);
401  return items.back();
402  }
virtual Units units(bool check=false) const
compute the dimensional units
Definition: item.h:352
virtual float x() const
Definition: item.cc:107
ItemPtr addItem(const std::shared_ptr< Item > &it, bool inSchema=false) override
Definition: group.h:262
virtual float y() const
Definition: item.cc:114
struct TCLcmd::trap::init_t init
GroupPtr addGroup(const std::shared_ptr< Group > &)
Definition: group.cc:659
void renameVar(const GroupPtr &origGroup, VariableBase &v)
rename variable so that it maintains most general scope possible
Definition: group.cc:303
virtual void bookmarkRefresh()
refresh the bookmark menu after changes
Definition: minsky.h:450
static void adjustWiresGroup(Wire &w)
adjust wire&#39;s group to be the least common ancestor of its ports
Definition: group.cc:404
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51

◆ addItem() [2/3]

ItemPtr minsky::GroupItems::addItem
inline

add item, ownership is passed

Definition at line 165 of file group.h.

165 {return addItem(std::shared_ptr<Item>(it),inSchema);}
ItemPtr addItem(const std::shared_ptr< Item > &it, bool inSchema=false) override
Definition: group.h:262

◆ addItem() [3/3]

ItemPtr minsky::Group::addItem ( const std::shared_ptr< Item > &  it,
bool  inSchema = false 
)
inlineoverridevirtual

add item.

Parameters
inSchema- if building a group from schema processing, rather than generally. Does not adjust item position within group if true.

Reimplemented from minsky::GroupItems.

Definition at line 262 of file group.h.

References addBookmarkXY(), and minsky::GroupItems::addItem().

Referenced by schema3::Minsky::populateGroup().

263  {
264  if (it && it->bookmark)
265  addBookmarkXY(it->left(),it->top(),it->bookmarkId());
266  return GroupItems::addItem(it,inSchema);
267  }
ItemPtr addItem(Item *it, bool inSchema=false)
add item, ownership is passed
Definition: group.h:165
void addBookmarkXY(float dx, float dy, const std::string &name)
Definition: group.h:403
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addOutputVar()

void minsky::Group::addOutputVar ( )
inline

Definition at line 295 of file group.h.

References addIOVar(), and minsky::GroupItems::outVariables.

295 {outVariables.push_back(addIOVar("output"));}
std::vector< VariablePtr > outVariables
Definition: group.h:82
VariablePtr addIOVar(const char *)
Definition: group.cc:519
Here is the call graph for this function:

◆ arguments()

string minsky::Group::arguments ( ) const

argument declaration, to be appended to name() for function declaration

Definition at line 88 of file group.cc.

References MathDAG::SystemOfEquations::getNodeFromVar(), and pyminsky::minsky.

89  {
90  MathDAG::SystemOfEquations system(minsky(), *this);
91  ostringstream r;
92  r<<"(";
93  for (auto& i: inVariables)
94  if (!i->inputWired())
95  {
96  if (r.str().size()>1) r<<",";
97  if (auto node=system.getNodeFromVar(*i))
98  node->matlab(r);
99  }
100  r<<")";
101  return r.str();
102  }
std::vector< VariablePtr > inVariables
Definition: group.h:82
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ autoLayout()

void minsky::Group::autoLayout ( )

automatically lay out items in this group using a graph layout algorithm

Definition at line 1259 of file group.cc.

References minsky::layoutGroup(), and pyminsky::minsky.

1260  {
1261  const BusyCursor busy(minsky());
1262  layoutGroup(*this);
1263  }
void layoutGroup(Group &g)
auto layout group items
Definition: autoLayout.cc:101
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ bookmarkList()

std::vector<std::string> minsky::Group::bookmarkList ( )
inline

returns list of bookmark names for populating menu

Definition at line 398 of file group.h.

References minsky::GroupItems::bookmarks.

398  {
399  std::vector<std::string> r;
400  for (auto& b: bookmarks) r.push_back(b.name);
401  return r;
402  }
std::set< Bookmark > bookmarks
Definition: group.h:81

◆ cBounds()

ecolab::array<double> minsky::Group::cBounds ( ) const
inline

for TCL debugging

Definition at line 369 of file group.h.

References contentBounds().

369  {
370  ecolab::array<double> r(4);
371  contentBounds(r[0],r[1],r[2],r[3]);
372  return r;
373  }
float contentBounds(double &x0, double &y0, double &x1, double &y1) const
return bounding box coordinates for all variables, operators etc in this group. Returns the zoom scal...
Definition: group.cc:759
Here is the call graph for this function:

◆ checkAddIORegion()

void minsky::Group::checkAddIORegion ( const ItemPtr x)

check if item is a variable and located in an I/O region, and add it if it is

Definition at line 550 of file group.cc.

551  {
552  if (auto v=dynamic_pointer_cast<VariableBase>(x))
553  {
554  remove(inVariables, v);
555  remove(outVariables, v);
556  switch (inIORegion(v->x(),v->y()))
557  {
558  case IORegion::input:
559  inVariables.push_back(v);
560  v->controller=self;
561  break;
562  case IORegion::output:
563  outVariables.push_back(v);
564  v->controller=self;
565  break;
566  default:
567  v->controller.reset();
568  break;
569  }
570  }
571  }
std::vector< VariablePtr > inVariables
Definition: group.h:82
virtual float x() const
Definition: item.cc:107
IORegion::type inIORegion(float x, float y) const
Definition: group.cc:531
std::vector< VariablePtr > outVariables
Definition: group.h:82

◆ clickType()

ClickType::Type minsky::Group::clickType ( float  x,
float  y 
) const
overridevirtual

returns the clicktype given a mouse click at x, y.

Reimplemented from minsky::Item.

Definition at line 910 of file group.cc.

References topMargin.

911  {
912  auto z=zoomFactor();
913  const double w=0.5*iWidth()*z, h=0.5*iHeight()*z;
914  if (onResizeHandle(x,y)) return ClickType::onResize;
916  return ClickType::outside;
917  if (auto item=select(x,y))
918  return item->clickType(x,y);
919  if ((abs(x-this->x())<w && abs(y-this->y())<h+topMargin*z)) // check also if (x,y) is within top and bottom margins of group. for feature 88
920  return ClickType::onItem;
921  return ClickType::outside;
922  }
virtual float x() const
Definition: item.cc:107
IORegion::type inIORegion(float x, float y) const
Definition: group.cc:531
virtual float y() const
Definition: item.cc:114
float iHeight() const
Definition: item.h:224
bool displayContents() const
returns whether contents should be displayed. Top level group always displayed
Definition: group.h:332
virtual float zoomFactor() const
Definition: item.cc:121
ItemPtr select(float x, float y) const override
returns the variable if point (x,y) is within a I/O variable icon, null otherwise, indicating that the Group has been selected.
Definition: group.cc:1184
virtual bool onResizeHandle(float x, float y) const
Definition: item.cc:228
float iWidth() const
Definition: item.h:217
static const int topMargin
Definition: group.cc:37

◆ clone()

Group* minsky::Group::clone ( ) const
inlineoverridevirtual

Reimplemented from minsky::Item.

Definition at line 258 of file group.h.

258 {throw error("Groups cannot be cloned");}

◆ computeDisplayZoom()

float minsky::Group::computeDisplayZoom ( )

Definition at line 824 of file group.cc.

References f.

825  {
826  double x0, x1, y0, y1;
827  const float z=zoomFactor();
828  const float lz=contentBounds(x0,y0,x1,y1);
829  x0=min(x0,double(x()));
830  x1=max(x1,double(x()));
831  y0=min(y0,double(y()));
832  y1=max(y1,double(y()));
833  // first compute the value assuming margins are of zero width
834  displayZoom = 2*max( max(x1-x(), x()-x0)/(iWidth()*z), max(y1-y(), y()-y0)/(iHeight()*z));
835 
836  // account for shrinking margins
837  const float readjust=zoomFactor()/edgeScale() / (displayZoom>1? displayZoom:1);
838  float l, r;
839  margins(l,r);
840  l*=readjust; r*=readjust;
841  displayZoom = max(displayZoom,
842  float(max((x1-x())/(0.5f*iWidth()*z-r), (x()-x0)/(0.5f*iWidth()*z-l))));
843 
844  displayZoom*=1.1*rotFactor()/lz;
845 
846  // displayZoom should never be less than 1
847  displayZoom=max(displayZoom, 1.0f);
848  return displayZoom;
849  }
function f
Definition: canvas.m:1
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float rotFactor() const
scaling factor to allow a rotated icon to fit on the bitmap
Definition: group.cc:1172
float iHeight() const
Definition: item.h:224
float edgeScale() const
scale used to render io variables. Smoothly interpolates between the scale at which internal items ar...
Definition: group.h:363
virtual float zoomFactor() const
Definition: item.cc:121
float displayZoom
computes the zoom at which to show contents, given current contentBounds and width ...
Definition: group.h:347
float iWidth() const
Definition: item.h:217
float contentBounds(double &x0, double &y0, double &x1, double &y1) const
return bounding box coordinates for all variables, operators etc in this group. Returns the zoom scal...
Definition: group.cc:759
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1152

◆ computeRelZoom()

void minsky::Group::computeRelZoom ( )

Definition at line 851 of file group.cc.

852  {
853  double x0, x1, y0, y1;
854  const double z=zoomFactor();
855  relZoom=1;
856  contentBounds(x0,y0,x1,y1);
857  float l, r;
858  margins(l,r);
859  const double dx=x1-x0, dy=y1-y0;
860  if (width()-l-r>0 && dx>0 && dy>0)
861  relZoom=std::min(1.0, std::min((width()-l-r)/(dx), (height()-20*z)/(dy)));
862  }
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:348
virtual float zoomFactor() const
Definition: item.cc:121
float width() const
Definition: item.h:242
float height() const
Definition: item.h:243
float contentBounds(double &x0, double &y0, double &x1, double &y1) const
return bounding box coordinates for all variables, operators etc in this group. Returns the zoom scal...
Definition: group.cc:759
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1152

◆ contentBounds()

float minsky::Group::contentBounds ( double &  x0,
double &  y0,
double &  x1,
double &  y1 
) const
protected

return bounding box coordinates for all variables, operators etc in this group. Returns the zoom scale (aka local zoom) of the contained items, or 1 if the group is empty.

Definition at line 759 of file group.cc.

Referenced by cBounds().

760  {
761  const float localZoom=1;
762  x0=numeric_limits<float>::max();
763  x1=-numeric_limits<float>::max();
764  y0=numeric_limits<float>::max();
765  y1=-numeric_limits<float>::max();
766 
767  for (auto& i: items)
768  if (!i->ioVar())
769  {
770  if (i->left()<x0) x0=i->left();
771  if (i->right()>x1) x1=i->right();
772  if (i->top()<y0) y0=i->top();
773  if (i->bottom()>y1) y1=i->bottom();
774  }
775 
776  for (auto& i: groups)
777  if (i->displayContents())
778  {
779  double left, top, right, bottom;
780  i->contentBounds(left,top,right,bottom);
781  if (left<x0) x0=left;
782  if (right>x1) x1=right;
783  if (top<y0) y0=top;
784  if (bottom>y1) y1=bottom;
785  }
786  else
787  {
788  if (i->left()<x0) x0=i->left();
789  if (i->right()>x1) x1=i->right();
790  if (i->top()<y0) y0=i->top();
791  if (i->bottom()>y1) y1=i->bottom();
792  }
793 
794  // if there are no contents, result is not finite. In this case,
795  // set the content bounds to a 10x10 sized box around the centroid of the I/O variables.
796  if (x0==numeric_limits<float>::max())
797  {
798  float cx=0, cy=0;
799  for (auto& i: inVariables)
800  {
801  cx+=i->x();
802  cy+=i->y();
803  }
804  for (auto& i: outVariables)
805  {
806  cx+=i->x();
807  cy+=i->y();
808  }
809  const int n=inVariables.size()+outVariables.size();
810  if (n>0)
811  {
812  cx/=n;
813  cy/=n;
814  }
815  x0=cx-10;
816  x1=cx+10;
817  y0=cy-10;
818  y1=cy+10;
819  }
820 
821  return localZoom;
822  }
float localZoom() const
Definition: group.h:351
std::vector< VariablePtr > inVariables
Definition: group.h:82
float right() const
Definition: item.cc:170
float top() const
Definition: item.cc:177
std::vector< VariablePtr > outVariables
Definition: group.h:82
float left() const
Definition: item.cc:163
float bottom() const
Definition: item.cc:184
Groups groups
Definition: group.h:79
Here is the caller graph for this function:

◆ copy()

GroupPtr minsky::Group::copy ( ) const

Make a copy of this as a sibling group (owned by parent). Attempting to copying minsky.model is a null operation.

Definition at line 121 of file group.cc.

122  {
123  // make new group owned by the top level group to prevent
124  if (auto g=group.lock())
125  return g->addGroup(copyUnowned());
126  return GroupPtr(); // do nothing if we attempt to clone the entire model
127  }
GroupPtr copyUnowned() const
make a copy of this, that is not owned by any group
Definition: group.cc:129
std::shared_ptr< Group > GroupPtr
Definition: port.h:32
Definition: group.tcl:84

◆ copyUnowned()

GroupPtr minsky::Group::copyUnowned ( ) const

make a copy of this, that is not owned by any group

Definition at line 129 of file group.cc.

References minsky::asgClonedPort(), and f.

130  {
131  auto r=make_shared<Group>();
132  r->self=r;
133  r->moveTo(x(),y());
134  // make new group owned by the top level group to prevent snarlups when called recursively
135  if (group.lock())
136  const_cast<Group*>(this)->globalGroup().addGroup(r);
137  else
138  return GroupPtr(); // do nothing if we attempt to clone the entire model
139 
140  // a map of original to cloned items (weak references)
141  map<Item*,ItemPtr> cloneMap;
142  map<IntOp*,bool> integrals;
143  // cloning IntOps mutates items, as intVars get inserted and removed
144  auto itemsCopy=items;
145  for (auto& i: itemsCopy)
146  if (auto integ=dynamic_cast<IntOp*>(i.get()))
147  integrals.emplace(integ, integ->coupled());
148  for (auto& i: itemsCopy)
149  cloneMap[i.get()]=r->addItem(i->clone(),true);
150  for (auto& i: groups)
151  cloneMap[i.get()]=r->addGroup(i->copyUnowned());
152  for (auto& w: wires)
153  {
154  auto f=w->from(), t=w->to();
155  asgClonedPort(f,cloneMap);
156  asgClonedPort(t,cloneMap);
157  r->addWire(new Wire(f,t,w->coords()));
158  }
159 
160  for (auto& v: inVariables)
161  {
162  assert(cloneMap.count(v.get()));
163  r->inVariables.push_back(dynamic_pointer_cast<VariableBase>(cloneMap[v.get()]));
164  r->inVariables.back()->controller=self;
165  }
166  for (auto& v: outVariables)
167  {
168  assert(cloneMap.count(v.get()));
169  r->outVariables.push_back(dynamic_pointer_cast<VariableBase>(cloneMap[v.get()]));
170  r->outVariables.back()->controller=self;
171  }
172  // reattach integral variables to their cloned counterparts
173  for (auto i: integrals)
174  {
175  if (auto newIntegral=dynamic_cast<IntOp*>(cloneMap[i.first].get()))
176  {
177  auto newIntVar=dynamic_pointer_cast<VariableBase>(cloneMap[i.first->intVar.get()]);
178  if (newIntVar && newIntegral->intVar != newIntVar)
179  {
180  r->removeItem(*newIntegral->intVar);
181  newIntegral->intVar=newIntVar;
182  }
183  if (i.second != newIntegral->coupled())
184  newIntegral->toggleCoupled();
185  }
186  }
187  r->computeRelZoom();
188  return r;
189  }
function f
Definition: canvas.m:1
std::vector< VariablePtr > inVariables
Definition: group.h:82
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
std::vector< VariablePtr > outVariables
Definition: group.h:82
void asgClonedPort(shared_ptr< Port > &p, const map< Item *, ItemPtr > &cloneMap)
Definition: group.cc:106
Groups groups
Definition: group.h:79
std::shared_ptr< Group > GroupPtr
Definition: port.h:32
Definition: group.tcl:84
Here is the call graph for this function:

◆ defaultExtension()

std::string minsky::Group::defaultExtension ( ) const

return default extension for this group - .mky if no ravels in group, .rvl otherwise

Definition at line 1252 of file group.cc.

1253  {
1254  if (findAny(&GroupItems::items, [](const ItemPtr& i){return dynamic_cast<Ravel*>(i.get());}))
1255  return ".rvl";
1256  return ".mky";
1257  }
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
const M::value_type findAny(M GroupItems::*map, C c) const
search for the first item in the heirarchy of map for which c is true. M::value_type must evaluate in...
Definition: group.h:442

◆ deleteAttachedWires()

void minsky::Group::deleteAttachedWires ( )
inlineoverridevirtual

delete all attached wires

Reimplemented from minsky::Item.

Definition at line 300 of file group.h.

References minsky::GroupItems::inVariables, and minsky::GroupItems::outVariables.

300  {
301  for (auto& i: inVariables) i->deleteAttachedWires();
302  for (auto& i: outVariables) i->deleteAttachedWires();
303  }
std::vector< VariablePtr > inVariables
Definition: group.h:82
std::vector< VariablePtr > outVariables
Definition: group.h:82

◆ deleteBookmark()

void minsky::Group::deleteBookmark ( std::size_t  i)
inline

Definition at line 408 of file group.h.

References minsky::GroupItems::bookmarks.

408  {
409  if (i<bookmarks.size())
410  {
411  auto j=bookmarks.begin();
412  std::advance(j, i);
413  bookmarks.erase(j);
414  }
415  }
std::set< Bookmark > bookmarks
Definition: group.h:81

◆ deleteItem()

void minsky::Group::deleteItem ( const Item i)

remove item from group, and also all attached wires.

Definition at line 247 of file group.cc.

References minsky::Minsky::bookmarkRefresh(), pyminsky::minsky, and minsky::Minsky::runItemDeletedCallback().

248  {
249  if (auto r=removeItem(i))
250  {
251  r->deleteAttachedWires();
252  r->removeControlledItems();
255  }
256  }
virtual void runItemDeletedCallback(const Item &)
run callback attached to item
Definition: minsky.h:459
virtual void bookmarkRefresh()
refresh the bookmark menu after changes
Definition: minsky.h:450
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
ItemPtr removeItem(const Item &)
Definition: group.cc:212
Here is the call graph for this function:

◆ displayContents()

bool minsky::Group::displayContents ( ) const
inline

returns whether contents should be displayed. Top level group always displayed

Definition at line 332 of file group.h.

References relZoom, and minsky::Item::zoomFactor().

Referenced by localZoom().

332 {return !group.lock() || zoomFactor()*relZoom>1;}
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:348
virtual float zoomFactor() const
Definition: item.cc:121
Definition: group.tcl:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ displayContentsChanged()

bool minsky::Group::displayContentsChanged ( ) const
inline

true if displayContents status changed on this or any contained group last zoom

Definition at line 335 of file group.h.

References m_displayContentsChanged.

335 {return m_displayContentsChanged;}
bool m_displayContentsChanged
Definition: group.h:222

◆ draw()

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

draw this item into a cairo context

Reimplemented from minsky::Item.

Definition at line 924 of file group.cc.

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

925  {
926  auto [angle,flipped]=rotationAsRadians();
927 
928  // determine how big the group icon should be to allow
929  // sufficient space around the side for the edge variables
930  float leftMargin, rightMargin;
931  margins(leftMargin, rightMargin);
932  const float z=zoomFactor();
933 
934  const unsigned width=z*this->iWidth(), height=z*this->iHeight();
935  const cairo::CairoSave cs(cairo);
936  cairo_rotate(cairo,angle);
937 
938  // In docker environments, something invisible gets drawn outside
939  // the horizontal dimensions, stuffing up the bb.width()
940  // calculation, and then causing the groupResize test to
941  // fail. This extra clip path fixes the problem.
942  cairo_rectangle(cairo,-0.5*width,-0.5*height-topMargin*z, width, height+2*topMargin*z);
943  cairo_clip(cairo);
944 
945  // draw default group icon
946 
947  // display I/O region in grey
948  drawIORegion(cairo);
949 
950  {
951  const cairo::CairoSave cs(cairo);
952  cairo_translate(cairo, -0.5*width+leftMargin, -0.5*height);
953 
954 
955  const double scalex=double(width-leftMargin-rightMargin)/width;
956  cairo_scale(cairo, scalex, 1);
957 
958  // draw a simple frame
959  cairo_rectangle(cairo,0,0,width,height);
960  {
961  const cairo::CairoSave cs(cairo);
962  cairo_identity_matrix(cairo);
963  cairo_set_line_width(cairo,1);
964  cairo_stroke(cairo);
965  }
966 
967  if (!displayContents())
968  {
969  if (displayPlot)
970  {
971  const cairo::CairoSave cs(cairo);
972  if (flipped)
973  {
974  cairo_translate(cairo,width,height);
975  cairo_rotate(cairo,M_PI); // rotate plot to keep it right way up.
976  }
977  // propagate plot type to underling ecolab::Plot
978  auto& pt=const_cast<Plot*>(static_cast<const Plot*>(displayPlot.get()))->plotType;
979  switch (displayPlot->plotType)
980  {
981  case PlotWidget::line: pt=Plot::line; break;
982  case PlotWidget::bar: pt=Plot::bar; break;
983  default: break;
984  }
985  displayPlot->Plot::draw(cairo, width, height);
986  }
987  else
988  {
989  cairo_scale(cairo,width/svgRenderer.width(),height/svgRenderer.height());
990  cairo_rectangle(cairo,0, 0,svgRenderer.width(), svgRenderer.height());
991  cairo_clip(cairo);
992  svgRenderer.render(cairo);
993  }
994  }
995  }
996 
997  drawEdgeVariables(cairo);
998 
999 
1000  // display text label
1001  if (!title.empty())
1002  {
1003  const cairo::CairoSave cs(cairo);
1004  cairo_scale(cairo, z, z);
1005  cairo_select_font_face
1006  (cairo, "sans-serif", CAIRO_FONT_SLANT_ITALIC,
1007  CAIRO_FONT_WEIGHT_NORMAL);
1008  cairo_set_font_size(cairo,12);
1009 
1010  // extract the bounding box of the text
1011  cairo_text_extents_t bbox;
1012  cairo_text_extents(cairo,title.c_str(),&bbox);
1013  const double w=0.5*bbox.width+2;
1014  const double h=0.5*bbox.height+5;
1015 
1016  // if rotation is in 1st or 3rd quadrant, rotate as
1017  // normal, otherwise flip the text so it reads L->R
1018  if (flipped)
1019  cairo_rotate(cairo, M_PI);
1020 
1021  // prepare a background for the text, partially obscuring graphic
1022  const double transparency=displayContents()? 0.25: 1;
1023 
1024  // display text
1025  cairo_move_to(cairo, -w+1, h-12-0.5*(height)/z);
1026  cairo_set_source_rgba(cairo,0,0,0,transparency);
1027  cairo_show_text(cairo,title.c_str());
1028  }
1029 
1030  if (mouseFocus)
1031  {
1032  displayTooltip(cairo,tooltip());
1033  // Resize handles always visible on mousefocus. For ticket 92.
1034  drawResizeHandles(cairo);
1035  }
1036 
1037  cairo_rectangle(cairo,-0.5*width,-0.5*height,width,height);
1038  cairo_clip(cairo);
1039  if (selected)
1040  drawSelected(cairo);
1041 
1042  }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
static SVGRenderer svgRenderer
Definition: group.h:259
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 displayContents() const
returns whether contents should be displayed. Top level group always displayed
Definition: group.h:332
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 flipped(double rotation)
returns if the angle (in degrees) is in the second or third quadrant
Definition: geometry.h:102
double width() const
Definition: SVGItem.h:44
classdesc::Exclude< std::shared_ptr< PlotWidget > > displayPlot
plot widget used for group icon
Definition: group.h:194
static void drawSelected(cairo_t *cairo)
Definition: item.cc:308
float width() const
Definition: item.h:242
double height() const
Definition: SVGItem.h:45
float iWidth() const
Definition: item.h:217
static const int topMargin
Definition: group.cc:37
std::string title
Definition: group.h:240
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
float height() const
Definition: item.h:243
bool mouseFocus
true if target of a mouseover
Definition: noteBase.h:31
void render(cairo_t *) const
Definition: SVGItem.cc:82
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1152
void drawEdgeVariables(cairo_t *) const
draw representations of edge variables around group icon
Definition: group.cc:1076
void drawIORegion(cairo_t *) const
draw notches in the I/O region to indicate dockability of variables there
Definition: group.cc:1105
Here is the call graph for this function:

◆ draw1edge()

void minsky::Group::draw1edge ( const std::vector< VariablePtr > &  vars,
cairo_t *  cairo,
float  x 
) const

draw the variables of one of the edges

Definition at line 1044 of file group.cc.

References M_PI, minsky::Rotate::x(), and minsky::Rotate::y().

1046  {
1047  float top=0, bottom=0;
1048  const double angle=rotation() * M_PI / 180.0;
1049  for (size_t i=0; i<vars.size(); ++i)
1050  {
1051  const Rotate r(rotation(),0,0);
1052  auto& v=vars[i];
1053  float y=0;
1054  auto z=v->zoomFactor();
1055  auto t=v->bb.top()*z, b=v->bb.bottom()*z;
1056  if (i>0) y = i%2? top-b: bottom-t;
1057  v->moveTo(r.x(x,y)+this->x(), r.y(x,y)+this->y());
1058  const cairo::CairoSave cs(cairo);
1059  cairo_translate(cairo,x,y);
1060  // cairo context is already rotated, so antirotate
1061  cairo_rotate(cairo,-angle);
1062  v->rotation(rotation());
1063  v->draw(cairo);
1064  if (i==0)
1065  {
1066  bottom=b;
1067  top=t;
1068  }
1069  else if (i%2)
1070  top-=v->height();
1071  else
1072  bottom+=v->height();
1073  }
1074  }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float top() const
Definition: item.cc:177
float bottom() const
Definition: item.cc:184
double rotation() const
Definition: item.h:211
Here is the call graph for this function:

◆ drawEdgeVariables()

void minsky::Group::drawEdgeVariables ( cairo_t *  cairo) const

draw representations of edge variables around group icon

Definition at line 1076 of file group.cc.

1077  {
1078  float left, right; margins(left,right);
1079  const cairo::CairoSave cs(cairo);
1080  const float z=zoomFactor();
1081  draw1edge(inVariables, cairo, -0.5*(iWidth()*z-left));
1082  draw1edge(outVariables, cairo, 0.5*(iWidth()*z-right));
1083  }
std::vector< VariablePtr > inVariables
Definition: group.h:82
float right() const
Definition: item.cc:170
virtual float zoomFactor() const
Definition: item.cc:121
std::vector< VariablePtr > outVariables
Definition: group.h:82
float left() const
Definition: item.cc:163
float iWidth() const
Definition: item.h:217
void draw1edge(const std::vector< VariablePtr > &vars, cairo_t *cairo, float x) const
draw the variables of one of the edges
Definition: group.cc:1044
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1152

◆ drawIORegion()

void minsky::Group::drawIORegion ( cairo_t *  cairo) const

draw notches in the I/O region to indicate dockability of variables there

Definition at line 1105 of file group.cc.

References minsky::anonymous_namespace{group.cc}::notchY(), and topMargin.

1106  {
1107  const cairo::CairoSave cs(cairo);
1108  float left, right;
1109  margins(left,right);
1110  const float z=zoomFactor();
1111  float y=notchY(inVariables), dy=topMargin*edgeScale();
1112  cairo_set_source_rgba(cairo,0,1,1,0.5);
1113  const float w=0.5*z*iWidth(), h=0.5*z*iHeight();
1114 
1115  cairo_move_to(cairo,-w,-h);
1116  // create notch in input region
1117  cairo_line_to(cairo,-w,y-dy);
1118  cairo_line_to(cairo,left-w-4*z,y-dy);
1119  cairo_line_to(cairo,left-w,y);
1120  cairo_line_to(cairo,left-w-4*z,y+dy);
1121  cairo_line_to(cairo,-w,y+dy);
1122  cairo_line_to(cairo,-w,h);
1123  cairo_line_to(cairo,left-w,h);
1124  cairo_line_to(cairo,left-w,-h);
1125  cairo_close_path(cairo);
1126  cairo_fill(cairo);
1127 
1129  cairo_move_to(cairo,w,-h);
1130  // create notch in output region
1131  cairo_line_to(cairo,w,y-dy);
1132  cairo_line_to(cairo,w-right-2*z,y-dy);
1133  cairo_line_to(cairo,w-right+2*z,y);
1134  cairo_line_to(cairo,w-right-2*z,y+dy);
1135  cairo_line_to(cairo,w,y+dy);
1136  cairo_line_to(cairo,w,h);
1137  cairo_line_to(cairo,w-right,h);
1138  cairo_line_to(cairo,w-right,-h);
1139  cairo_close_path(cairo);
1140  cairo_fill(cairo);
1141 
1142  // draw top margin. for feature 88
1143  cairo_rectangle(cairo,-w,-h,2*w,-topMargin*z);
1144  cairo_fill(cairo);
1145 
1146  // draw bottom margin. for feature 88
1147  cairo_rectangle(cairo,-w,h,2*w,topMargin*z);
1148  cairo_fill(cairo);
1149  }
std::vector< VariablePtr > inVariables
Definition: group.h:82
float right() const
Definition: item.cc:170
virtual float y() const
Definition: item.cc:114
float iHeight() const
Definition: item.h:224
float notchY(const vector< VariablePtr > &vars)
Definition: group.cc:1088
float edgeScale() const
scale used to render io variables. Smoothly interpolates between the scale at which internal items ar...
Definition: group.h:363
virtual float zoomFactor() const
Definition: item.cc:121
std::vector< VariablePtr > outVariables
Definition: group.h:82
float left() const
Definition: item.cc:163
float iWidth() const
Definition: item.h:217
static const int topMargin
Definition: group.cc:37
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1152
Here is the call graph for this function:

◆ edgeScale()

float minsky::Group::edgeScale ( ) const
inline

scale used to render io variables. Smoothly interpolates between the scale at which internal items are displayed, and the outside zoom factor

Definition at line 363 of file group.h.

References relZoom, and minsky::Item::zoomFactor().

363  {
364  float z=zoomFactor();
365  return z*relZoom>1? z*relZoom: z>1? 1: z;
366  }
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:348
virtual float zoomFactor() const
Definition: item.cc:121
Here is the call graph for this function:

◆ flipContents()

void minsky::Group::flipContents ( )

rotate all conatined items by 180 degrees

Definition at line 1207 of file group.cc.

1208  {
1209  for (auto& i: items)
1210  {
1211  i->moveTo(x()-i->m_x,i->y());
1212  i->flip();
1213  }
1214  for (auto& i: groups)
1215  {
1216  i->moveTo(x()-i->m_x,i->y());
1217  i->flip();
1218  }
1219  }
virtual float x() const
Definition: item.cc:107
Groups groups
Definition: group.h:79

◆ formula()

std::string minsky::Group::formula ( ) const

algebraic formula representing value of first output argument of this group

Definition at line 74 of file group.cc.

References MathDAG::SystemOfEquations::getNodeFromVar(), and pyminsky::minsky.

75  {
76  if (outVariables.empty()) return "0";
77  MathDAG::SystemOfEquations system(minsky(), *this);
78  ostringstream o;
79  auto node=system.getNodeFromVar(*outVariables[0]);
80  if (!node) return "0";
81  if (node->rhs)
82  node->rhs->matlab(o);
83  else
84  node->matlab(o);
85  return o.str();
86  }
std::vector< VariablePtr > outVariables
Definition: group.h:82
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ globalGroup() [1/2]

const Group & minsky::Group::globalGroup ( ) const

top level group

Definition at line 739 of file group.cc.

References minsky::anonymous_namespace{group.cc}::globalGroup().

Referenced by minsky::Wire::moveIntoGroup().

740  {return minsky::globalGroup(*this);}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ globalGroup() [2/2]

Group & minsky::Group::globalGroup ( )

Definition at line 741 of file group.cc.

References minsky::anonymous_namespace{group.cc}::globalGroup().

742  {return minsky::globalGroup(*this);}
Here is the call graph for this function:

◆ gotoBookmark()

void minsky::Group::gotoBookmark ( std::size_t  i)
inline

Definition at line 417 of file group.h.

References minsky::GroupItems::bookmarks, and gotoBookmark_b().

417  {
418  if (i<bookmarks.size()) {
419  auto j=bookmarks.begin();
420  std::advance(j, i);
421  gotoBookmark_b(*j);
422  }
423  }
std::set< Bookmark > bookmarks
Definition: group.h:81
void gotoBookmark_b(const Bookmark &b)
Definition: group.cc:1244
Here is the call graph for this function:

◆ gotoBookmark_b()

void minsky::Group::gotoBookmark_b ( const Bookmark b)

Definition at line 1244 of file group.cc.

References minsky::Minsky::canvas, minsky::cminsky(), pyminsky::minsky, minsky::Minsky::model, minsky::Canvas::requestRedraw(), minsky::Bookmark::x, minsky::Bookmark::y, minsky::Bookmark::zoom, and zoom().

Referenced by gotoBookmark(), and minsky::VariableInstanceList::gotoInstance().

1245  {
1246  moveTo(b.x, b.y);
1247  zoom(x(),y(),b.zoom/(relZoom*zoomFactor()));
1248  // TODO add canvas::gotoBookmark to avoid dependency inversion
1249  if (this==cminsky().canvas.model.get()) minsky().canvas.requestRedraw();
1250  }
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:348
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
virtual float zoomFactor() const
Definition: item.cc:121
Canvas canvas
Definition: minsky.h:256
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
void moveTo(float x, float y)
Definition: item.cc:256
GroupPtr model
Definition: minsky.h:255
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
void zoom(float xOrigin, float yOrigin, float factor)
Definition: group.cc:894
Here is the call graph for this function:
Here is the caller graph for this function:

◆ higher()

bool minsky::Group::higher ( const Group x) const

returns true if this is higher in the heirarchy than the argument this->higher(*this) is false

Definition at line 712 of file group.cc.

Referenced by moveContents().

713  {
714  for (auto& i: groups)
715  if (i.get()==&x) return true;
716  return any_of(groups.begin(), groups.end(), [&](const GroupPtr& i){return i->higher(x);});
717  }
virtual float x() const
Definition: item.cc:107
Groups groups
Definition: group.h:79
std::shared_ptr< Group > GroupPtr
Definition: port.h:32
Here is the caller graph for this function:

◆ inIORegion()

Group::IORegion::type minsky::Group::inIORegion ( float  x,
float  y 
) const

Definition at line 531 of file group.cc.

References MathDAG::cos(), M_PI, MathDAG::sin(), and topMargin.

532  {
533  float left, right;
534  const float z=zoomFactor();
535  margins(left,right);
536  const float dx=(x-this->x())*cos(rotation()*M_PI/180)-
537  (y-this->y())*sin(rotation()*M_PI/180);
538  const float dy=(x-this->x())*sin(rotation()*M_PI/180)+
539  (y-this->y())*cos(rotation()*M_PI/180);
540  const float w=0.5*iWidth()*z,h=0.5*iHeight()*z;
541  if (w-right<dx)
542  return IORegion::output;
543  if (-w+left>dx)
544  return IORegion::input;
545  if ((-h+topMargin*z>dy && dy<0) || (h-topMargin*z<dy && dy>0))
546  return IORegion::topBottom;
547  return IORegion::none;
548  }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
Expr sin(const Expr &x)
Definition: expr.h:131
Expr cos(const Expr &x)
Definition: expr.h:137
float right() const
Definition: item.cc:170
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float iHeight() const
Definition: item.h:224
virtual float zoomFactor() const
Definition: item.cc:121
float left() const
Definition: item.cc:163
float iWidth() const
Definition: item.h:217
static const int topMargin
Definition: group.cc:37
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1152
double rotation() const
Definition: item.h:211
Here is the call graph for this function:

◆ level()

unsigned minsky::Group::level ( ) const

return level in the heirarchy

Definition at line 719 of file group.cc.

720  {
721  assert(nocycles());
722  unsigned l=0;
723  for (auto i=group.lock(); i; i=i->group.lock()) l++;
724  return l;
725  }
bool nocycles() const override
tests that groups are arranged heirarchically without any recurrence
Definition: group.cc:649
Definition: group.tcl:84

◆ localZoom()

float minsky::Group::localZoom ( ) const
inline

Definition at line 351 of file group.h.

References displayContents(), displayZoom, and minsky::Item::zoomFactor().

351  {
352  return (displayZoom>0 && displayContents())
353  ? zoomFactor()/displayZoom: 1;
354  }
bool displayContents() const
returns whether contents should be displayed. Top level group always displayed
Definition: group.h:332
virtual float zoomFactor() const
Definition: item.cc:121
float displayZoom
computes the zoom at which to show contents, given current contentBounds and width ...
Definition: group.h:347
Here is the call graph for this function:

◆ makeSubroutine()

void minsky::Group::makeSubroutine ( )

Make all variables not present in outerscope local to this group.

Definition at line 191 of file group.cc.

192  {
193  recursiveDo(&GroupItems::items, [this](Items&,Items::iterator i)
194  {
195  if (auto v=(*i)->variableCast())
196  if (v->rawName()[0]==':')
197  {
198  // walk up parent groups to see if this variable is mentioned
199  for (auto g=group.lock(); g; g=g->group.lock())
200  for (auto& item: g->items)
201  if (auto vi=item->variableCast())
202  if (vi->valueId()==v->valueId())
203  goto outer_scope_variable_found;
204  v->name(v->rawName().substr(1)); // make variable local
205  }
206  outer_scope_variable_found:
207  return false;
208  });
209  }
bool recursiveDo(M GroupItems::*map, O op) const
Perform action heirarchically on elements of map map. If op returns true, the operation terminates...
Definition: group.h:111
std::vector< ItemPtr > Items
Definition: item.h:366
Definition: group.tcl:84

◆ margins()

void minsky::Group::margins ( float &  left,
float &  right 
) const

margin sizes to allow space for edge variables.

Definition at line 1152 of file group.cc.

Referenced by marginsV().

1153  {
1154  left=right=10;
1155  auto tmpMouseFocus=mouseFocus;
1156  mouseFocus=false; // disable mouseFocus for this calculation
1157  for (auto& i: inVariables)
1158  {
1159  assert(i->type()!=VariableType::undefined);
1160  i->bb.update(*i);
1161  if (i->width()>left) left=i->width();
1162  }
1163  for (auto& i: outVariables)
1164  {
1165  assert(i->type()!=VariableType::undefined);
1166  i->bb.update(*i);
1167  if (i->width()>right) right=i->width();
1168  }
1169  mouseFocus=tmpMouseFocus;
1170  }
std::vector< VariablePtr > inVariables
Definition: group.h:82
float right() const
Definition: item.cc:170
std::vector< VariablePtr > outVariables
Definition: group.h:82
float left() const
Definition: item.cc:163
bool mouseFocus
true if target of a mouseover
Definition: noteBase.h:31
Here is the caller graph for this function:

◆ marginsV()

std::vector<float> minsky::Group::marginsV ( ) const
inline

for debugging purposes

Definition at line 341 of file group.h.

References margins().

341  {
342  float l, r; margins(l,r); return {l,r};
343  }
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1152
Here is the call graph for this function:

◆ minimalEnclosingGroup() [1/2]

const Group * minsky::Group::minimalEnclosingGroup ( float  x0,
float  y0,
float  x1,
float  y1,
const Item ignore = nullptr 
) const
protected

returns the smallest group whose icon completely encloses the rectangle given by the argument. If no candidate group found, returns nullptr. Weak reference returned, no ownership.

Parameters
ignore- do not return group ignore, even if it encloses the rectangle

Definition at line 864 of file group.cc.

Referenced by minimalEnclosingGroup().

865  {
866  const float z=zoomFactor();
867  if (x0<x()-0.5*z*iWidth() || x1>x()+0.5*z*iWidth() ||
868  y0<y()-0.5*z*iHeight() || y1>y()+0.5*z*iHeight())
869  return nullptr;
870  // at this point, this is a candidate. Check if any child groups are also
871  for (auto& g: groups)
872  if (auto mg=g->minimalEnclosingGroup(x0,y0,x1,y1, ignore))
873  if (mg->visible())
874  return mg;
875  return this!=ignore? this: nullptr;
876  }
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float iHeight() const
Definition: item.h:224
virtual float zoomFactor() const
Definition: item.cc:121
float iWidth() const
Definition: item.h:217
Groups groups
Definition: group.h:79
Here is the caller graph for this function:

◆ minimalEnclosingGroup() [2/2]

Group* minsky::Group::minimalEnclosingGroup ( float  x0,
float  y0,
float  x1,
float  y1,
const Item ignore = nullptr 
)
inlineprotected

Definition at line 230 of file group.h.

References minimalEnclosingGroup().

231  {return const_cast<Group*>(const_cast<const Group*>(this)->minimalEnclosingGroup(x0,y0,x1,y1,ignore));}
const Group * minimalEnclosingGroup(float x0, float y0, float x1, float y1, const Item *ignore=nullptr) const
returns the smallest group whose icon completely encloses the rectangle given by the argument...
Definition: group.cc:864
Here is the call graph for this function:

◆ moveContents()

void minsky::Group::moveContents ( Group source)

move all items from source to this

no need to move wires, as these are handled above

Definition at line 499 of file group.cc.

References minsky::GroupItems::clear(), minsky::GroupItems::groups, higher(), and minsky::GroupItems::items.

499  {
500  if (&source!=this)
501  {
502  if (source.higher(*this))
503  throw error("attempt to move a group into itself");
504  // make temporary copies as addItem removes originals
505  auto copyOfItems=source.items;
506  for (auto& i: copyOfItems)
507  {
508  addItem(i);
509  assert(!i->ioVar());
510  }
511  auto copyOfGroups=source.groups;
512  for (auto& i: copyOfGroups)
513  addGroup(i);
515  source.clear();
516  }
517  }
ItemPtr addItem(const std::shared_ptr< Item > &it, bool inSchema=false) override
Definition: group.h:262
GroupPtr addGroup(const std::shared_ptr< Group > &)
Definition: group.cc:659
Here is the call graph for this function:

◆ name()

std:: string minsky::Group::name ( ) const
inlineoverridevirtual

Implements minsky::CallableFunction.

Definition at line 241 of file group.h.

References title.

Referenced by addBookmark(), and addBookmarkXY().

241 {return title;}
std::string title
Definition: group.h:240
Here is the caller graph for this function:

◆ nocycles()

bool minsky::Group::nocycles ( ) const
overridevirtual

tests that groups are arranged heirarchically without any recurrence

Implements minsky::GroupItems.

Definition at line 649 of file group.cc.

650  {
651  set<const Group*> sg;
652  sg.insert(this);
653  for (auto i=group.lock(); i; i=i->group.lock())
654  if (!sg.insert(i.get()).second)
655  return false;
656  return true;
657  }
Definition: group.tcl:84

◆ normaliseGroupRefs()

void minsky::Group::normaliseGroupRefs ( const std::shared_ptr< Group > &  self)

fix up subgroup pointers self is a shared pointer ref to this

Definition at line 1195 of file group.cc.

1196  {
1197  for (auto& i: items)
1198  i->group=self;
1199  for (auto& g: groups)
1200  {
1201  g->group=self;
1202  g->normaliseGroupRefs(g);
1203  }
1204  }
Groups groups
Definition: group.h:79

◆ operator()()

double minsky::Group::operator() ( const std::vector< double > &  p)
overridevirtual

evaluate function on arbitrary number of arguments (exprtk support)

Implements minsky::CallableFunction.

Definition at line 50 of file group.cc.

References pyminsky::minsky, and MathDAG::SystemOfEquations::populateEvalOpVector().

51  {
52  if (outVariables.empty()) return nan("");
53 
54  MathDAG::SystemOfEquations system(minsky(), *this);
55  EvalOpVector equations;
56  vector<Integral> integrals;
57  system.populateEvalOpVector(equations, integrals);
58  auto flow(ValueVector::flowVars);
59 
60  // assign values to unattached input variables
61  auto iVar=inVariables.begin();
62  for (auto v: p)
63  {
64  while (iVar!=inVariables.end() && (*iVar)->inputWired()) ++iVar;
65  if (iVar==inVariables.end()) break;
66  flow[(*iVar)->vValue()->idx()]=v;
67  }
68 
69  for (auto& i: equations)
70  i->eval(flow.data(), flow.size(),ValueVector::stockVars.data());
71  return flow[outVariables[0]->vValue()->idx()];
72  }
std::vector< VariablePtr > inVariables
Definition: group.h:82
static std::vector< double, CIVITA_ALLOCATOR< double > > stockVars
vector of variables that are integrated via Runge-Kutta. These variables label the columns of the God...
std::vector< VariablePtr > outVariables
Definition: group.h:82
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ randomLayout()

void minsky::Group::randomLayout ( )

randomly lay out items in this group

Definition at line 1265 of file group.cc.

References pyminsky::minsky, and minsky::randomizeLayout().

1266  {
1267  const BusyCursor busy(minsky());
1268  randomizeLayout(*this);
1269  }
void randomizeLayout(Group &g)
randomly place items on canvas
Definition: autoLayout.cc:88
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ renameAllInstances()

void minsky::Group::renameAllInstances ( const std::string &  valueId,
const std::string &  newName 
)

rename all instances of a variable matching valueId to newName

Definition at line 1285 of file group.cc.

References minsky::cminsky(), minsky::anonymous_namespace{group.cc}::isGlobal(), pyminsky::minsky, minsky::Minsky::model, minsky::Minsky::requestReset(), minsky::scope(), and minsky::valueId().

1286  {
1287  // unqualified versions of the names
1288  auto p=valueId.find(':');
1289  string uqFromName=(p!=string::npos)? valueId.substr(p+1): valueId;
1290  string uqNewName = newName.substr(newName[0]==':'? 1: 0);
1291  set<GodleyIcon*> godleysToUpdate;
1292 #ifndef NDEBUG
1293  auto numItems=this->numItems();
1294 #endif
1295  recursiveDo
1296  (&GroupItems::items, [&](Items&,Items::iterator i)
1297  {
1298  if (auto v=(*i)->variableCast())
1299  if (v->valueId()==valueId)
1300  {
1301  auto varScope=scope(v->group.lock(), valueId);
1302  if (auto g=dynamic_cast<GodleyIcon*>(v->controller.lock().get()))
1303  {
1304  if (varScope==g->group.lock() ||
1305  (!varScope && g->group.lock()==cminsky().model)) // fix local variables
1306  g->table.rename(uqFromName, uqNewName);
1307 
1308  // scope of an external ref in the Godley Table
1309  auto externalVarScope=scope(g->group.lock(), ':'+uqNewName);
1310  // if we didn't find it, perhaps the outerscope variable hasn't been changed
1311  if (!externalVarScope)
1312  externalVarScope=scope(g->group.lock(), ':'+uqFromName);
1313 
1314  if (varScope==externalVarScope || (isGlobal(varScope) && isGlobal(externalVarScope)))
1315  // fix external variable references
1316  g->table.rename(':'+uqFromName, ':'+uqNewName);
1317  // GodleyIcon::update invalidates the iterator, so postpone update
1318  godleysToUpdate.insert(g);
1319  }
1320  else
1321  {
1322  // ensure locality is preserved across the rename
1323  v->name(varScope==v->group.lock()? uqNewName: (':'+uqNewName));
1324  if (auto vv=v->vValue())
1325  v->retype(vv->type()); // ensure correct type. Note this invalidates v.
1326  }
1327  }
1328  return false;
1329  });
1330  assert(this->numItems()==numItems);
1331  for (auto g: godleysToUpdate)
1332  {
1333  g->update();
1334  assert(this->numItems()==numItems);
1335  }
1336  minsky().requestReset(); // Updates model after variables rename. For ticket 1109.
1337  }
std::size_t numItems() const
total number of items in this and child groups
Definition: group.cc:477
void requestReset()
Definition: minsky.cc:467
size_t scope(const string &name)
extract scope from a qualified variable name
Definition: valueId.cc:83
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
bool recursiveDo(M GroupItems::*map, O op) const
Perform action heirarchically on elements of map map. If op returns true, the operation terminates...
Definition: group.h:111
std::vector< ItemPtr > Items
Definition: item.h:366
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
GroupPtr model
Definition: minsky.h:255
bool isGlobal(const GroupPtr &g)
Definition: group.cc:46
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ resize()

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

resize this item on the canvas

Reimplemented from minsky::Item.

Definition at line 624 of file group.cc.

References minsky::anonymous_namespace{group.cc}::recentreItems(), minsky::anonymous_namespace{group.cc}::resizeItems(), topMargin, minsky::LassoBox::x0, minsky::LassoBox::x1, minsky::LassoBox::y0, and minsky::LassoBox::y1.

625  {
626  float z=zoomFactor();
627  // account for margins
628  float l, r;
629  margins(l,r);
630  if (fabs(b.x0-b.x1) < l+r || fabs(b.y0-b.y1)<2*z*topMargin) return;
631  iWidth(fabs(b.x0-b.x1)/z);
632  iHeight((fabs(b.y0-b.y1)-2*topMargin)/z);
633  // TODO - it is wasteful to call contentBounds within computeRelZoom, then again a few lines later
634  computeRelZoom(); // needed to ensure grouped items scale properly with resize operation. for ticket 1243
635  z=zoomFactor(); // recalculate zoomFactor because relZoom changed above. for ticket 1243
636  double x0, x1, y0, y1;
637  contentBounds(x0,y0,x1,y1);
638  recentreItems(items,0.5*(x0+x1)-x(),0.5*(y0+y1)-y());
639  recentreItems(groups,0.5*(x0+x1)-x(),0.5*(y0+y1)-y());
640  double sx=(fabs(b.x0-b.x1)-z*(l+r))/(x1-x0), sy=(fabs(b.y0-b.y1)-2*z*topMargin)/(y1-y0);
641  sx=std::min(sx,sy);
642  resizeItems(items,sx,sx);
643  resizeItems(groups,sx,sx);
644 
645  moveTo(0.5*(b.x0+b.x1), 0.5*(b.y0+b.y1));
646  bb.update(*this);
647  }
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
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
void recentreItems(const T &items, float xc, float yc)
Definition: group.cc:611
float iWidth() const
Definition: item.h:217
static const int topMargin
Definition: group.cc:37
void computeRelZoom()
Definition: group.cc:851
Groups groups
Definition: group.h:79
void resizeItems(T &items, double sx, double sy)
Definition: group.cc:598
void moveTo(float x, float y)
Definition: item.cc:256
float contentBounds(double &x0, double &y0, double &x1, double &y1) const
return bounding box coordinates for all variables, operators etc in this group. Returns the zoom scal...
Definition: group.cc:759
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1152
Here is the call graph for this function:

◆ resizeOnContents()

void minsky::Group::resizeOnContents ( )

adjust position and size of icon to just cover contents

Definition at line 574 of file group.cc.

575  {
576  double x0, x1, y0, y1;
577  contentBounds(x0,y0,x1,y1);
578  const double xx=0.5*(x0+x1), yy=0.5*(y0+y1);
579  const double dx=xx-x(), dy=yy-y();
580  float l,r; margins(l,r);
581  const float z=zoomFactor();
582  m_width=((x1-x0)+l+r)/z;
583  m_height=((y1-y0)+20*z)/z;
584 
585  // adjust contents by the offset
586  for (auto& i: items)
587  i->moveTo(i->x()-dx, i->y()-dy);
588  for (auto& i: groups)
589  i->moveTo(i->x()-dx, i->y()-dy);
590 
591  moveTo(xx,yy);
592  bb.update(*this);
593  }
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
BoundingBox bb
canvas bounding box.
Definition: item.h:195
double m_height
Definition: item.h:155
virtual float zoomFactor() const
Definition: item.cc:121
void update(const Item &x)
Definition: item.cc:46
double m_width
Definition: item.h:155
Groups groups
Definition: group.h:79
void moveTo(float x, float y)
Definition: item.cc:256
float contentBounds(double &x0, double &y0, double &x1, double &y1) const
return bounding box coordinates for all variables, operators etc in this group. Returns the zoom scal...
Definition: group.cc:759
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1152

◆ rotFactor()

float minsky::Group::rotFactor ( ) const

scaling factor to allow a rotated icon to fit on the bitmap

Definition at line 1172 of file group.cc.

References MathDAG::cos(), M_PI, and MathDAG::sqrt().

1173  {
1174  float rotFactor;
1175  const float ac=abs(cos(rotation()*M_PI/180));
1176  static const float invSqrt2=1/sqrt(2);
1177  if (ac>=invSqrt2)
1178  rotFactor=1.15/ac; //use |1/cos(angle)| as rotation factor
1179  else
1180  rotFactor=1.15/sqrt(1-ac*ac);//use |1/sin(angle)| as rotation factor
1181  return rotFactor;
1182  }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
Expr cos(const Expr &x)
Definition: expr.h:137
Expr sqrt(const Expr &x)
Definition: expr.h:154
float rotFactor() const
scaling factor to allow a rotated icon to fit on the bitmap
Definition: group.cc:1172
double rotation() const
Definition: item.h:211
Here is the call graph for this function:

◆ select()

ItemPtr minsky::Group::select ( float  x,
float  y 
) const
overridevirtual

returns the variable if point (x,y) is within a I/O variable icon, null otherwise, indicating that the Group has been selected.

Reimplemented from minsky::Item.

Definition at line 1184 of file group.cc.

References minsky::RenderVariable::inImage().

1185  {
1186  for (auto& v: inVariables)
1187  if (RenderVariable(*v).inImage(x,y))
1188  return v;
1189  for (auto& v: outVariables)
1190  if (RenderVariable(*v).inImage(x,y))
1191  return v;
1192  return nullptr;
1193  }
std::vector< VariablePtr > inVariables
Definition: group.h:82
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
std::vector< VariablePtr > outVariables
Definition: group.h:82
Here is the call graph for this function:

◆ setZoom()

void minsky::Group::setZoom ( float  factor)

sets the zoom factor to factor. Recursively set the zoomfactor on contained objects to the computed localzoom

Definition at line 878 of file group.cc.

879  {
880  const bool dpc=displayContents();
881  if (!group.lock())
882  relZoom=factor;
883  else
884  computeRelZoom();
885  const float lzoom=localZoom();
887  for (auto& i: groups)
888  {
889  i->setZoom(lzoom);
890  m_displayContentsChanged|=i->displayContentsChanged();
891  }
892  }
float localZoom() const
Definition: group.h:351
bool m_displayContentsChanged
Definition: group.h:222
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:348
bool displayContents() const
returns whether contents should be displayed. Top level group always displayed
Definition: group.h:332
void computeRelZoom()
Definition: group.cc:851
Groups groups
Definition: group.h:79
Definition: group.tcl:84

◆ splitBoundaryCrossingWires()

void minsky::Group::splitBoundaryCrossingWires ( )

splits any wires that cross group boundaries

Definition at line 424 of file group.cc.

References minsky::anonymous_namespace{group.cc}::globalGroup().

425  {
426  // Wire::split will invalidate the Items::iterator, so collect
427  // wires to split first
428  set<Wire*> wiresToSplit;
429  for (auto& i: items)
430  for (size_t p=0; p<i->portsSize(); ++p)
431  for (auto w: i->ports(p).lock()->wires())
432  wiresToSplit.insert(w);
433 
434  for (auto w: wiresToSplit)
435  w->split();
436 
437  // check if any created I/O variables can be removed
438  auto varsToCheck=createdIOvariables;
439  for (auto& iv: varsToCheck)
440  {
441  assert(iv->ports(1).lock()->input() && !iv->ports(1).lock()->multiWireAllowed());
442  // firstly join wires that don't cross boundaries
443  // determine if this is input or output var
444  if (!iv->ports(1).lock()->wires().empty())
445  {
446  auto fromGroup=iv->ports(1).lock()->wires()[0]->from()->item().group.lock();
447  if (fromGroup.get() == this)
448  {
449  // not an input var
450  for (auto& w: iv->ports(0).lock()->wires())
451  if (w->to()->item().group.lock().get() == this)
452  // join wires, as not crossing boundary
453  {
454  auto to=w->to();
455  iv->ports(0).lock()->eraseWire(w);
456  removeWire(*w);
457  addWire(iv->ports(1).lock()->wires()[0]->from(), to);
458  }
459  }
460  else
461  for (auto& w: iv->ports(0).lock()->wires())
462  if (w->to()->item().group.lock() == fromGroup)
463  // join wires, as not crossing boundary
464  {
465  auto to=w->to();
466  iv->ports(0).lock()->eraseWire(w);
467  globalGroup().removeWire(*w);
468  adjustWiresGroup(*addWire(iv->ports(1).lock()->wires()[0]->from(), to));
469  }
470  }
471 
472  if (iv->ports(0).lock()->wires().empty() || iv->ports(1).lock()->wires().empty())
473  removeItem(*iv);
474  }
475  }
WirePtr removeWire(const Wire &)
Definition: group.cc:259
std::vector< VariablePtr > createdIOvariables
Definition: group.h:83
static void adjustWiresGroup(Wire &w)
adjust wire&#39;s group to be the least common ancestor of its ports
Definition: group.cc:404
const Group & globalGroup() const
top level group
Definition: group.cc:739
WirePtr addWire(const Item &from, const Item &to, unsigned toPortIdx, const std::vector< float > &coords)
add a wire from item from, to item to, connecting to the toIdx port of to, with coordinates ...
Definition: group.h:63
ItemPtr removeItem(const Item &)
Definition: group.cc:212
Here is the call graph for this function:

◆ summariseGodleys()

vector< Summary > minsky::Group::summariseGodleys ( ) const

produce a summary of godley table variables

Definition at line 1271 of file group.cc.

1272  {
1273  vector<Summary> r;
1274  recursiveDo(&GroupItems::items, [&](const Items&,Items::const_iterator i) {
1275  if (auto g=dynamic_cast<GodleyIcon*>(i->get()))
1276  {
1277  auto summary=g->summarise();
1278  r.insert(r.end(),summary.begin(), summary.end());
1279  }
1280  return false;
1281  });
1282  return r;
1283  }
bool recursiveDo(M GroupItems::*map, O op) const
Perform action heirarchically on elements of map map. If op returns true, the operation terminates...
Definition: group.h:111
std::vector< ItemPtr > Items
Definition: item.h:366

◆ uniqueItems() [1/2]

bool minsky::Group::uniqueItems ( std::set< void *> &  idset) const

returns true if items appear uniquely within the heirarchy. Note the map structure does not guarantee that an item doesn't appear within another group

Definition at line 747 of file group.cc.

748  {
749  for (auto& i: items)
750  if (!idset.insert(i.get()).second) return false;
751  for (auto& i: wires)
752  if (!idset.insert(i.get()).second) return false;
753  for (auto& i: groups)
754  if (!idset.insert(i.get()).second || !i->uniqueItems(idset))
755  return false;
756  return true;
757  }
Groups groups
Definition: group.h:79

◆ uniqueItems() [2/2]

bool minsky::Group::uniqueItems ( ) const
inline

Definition at line 326 of file group.h.

326  {
327  std::set<void*> idset;
328  return uniqueItems(idset);
329  }
bool uniqueItems() const
Definition: group.h:326

◆ zoom()

void minsky::Group::zoom ( float  xOrigin,
float  yOrigin,
float  factor 
)

Definition at line 894 of file group.cc.

References minsky::zoom().

895  {
896  const bool dpc=displayContents();
897  minsky::zoom(m_x,xOrigin+m_x-x(),factor);
898  minsky::zoom(m_y,yOrigin+m_y-y(),factor);
900  if (!group.lock())
901  relZoom*=factor;
902  for (auto& i: groups)
903  {
905  i->zoom(i->x(), i->y(), factor);
906  m_displayContentsChanged|=i->displayContentsChanged();
907  }
908  }
bool m_displayContentsChanged
Definition: group.h:222
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:348
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
bool displayContents() const
returns whether contents should be displayed. Top level group always displayed
Definition: group.h:332
Groups groups
Definition: group.h:79
Definition: group.tcl:84
void zoom(float &val, float origin, float factor)
base zooming transformation
Definition: zoom.h:26
float m_y
position in canvas, or within group
Definition: item.h:173
float m_x
Definition: item.h:173
Here is the call graph for this function:

Friends And Related Function Documentation

◆ Canvas

friend class Canvas
friend

Definition at line 232 of file group.h.

Member Data Documentation

◆ displayZoom

float minsky::Group::displayZoom {1}

computes the zoom at which to show contents, given current contentBounds and width

extra zoom at which contents are displayed

Definition at line 347 of file group.h.

Referenced by localZoom().

◆ m_displayContentsChanged

bool minsky::Group::m_displayContentsChanged =true
private

Definition at line 222 of file group.h.

Referenced by displayContentsChanged().

◆ relZoom

float minsky::Group::relZoom {1}

relative zoom contents of this group are displayed at

Definition at line 348 of file group.h.

Referenced by addBookmarkXY(), displayContents(), and edgeScale().

◆ svgRenderer

SVGRenderer minsky::Group::svgRenderer
static

Definition at line 259 of file group.h.

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

◆ title

std::string minsky::Group::title

Definition at line 240 of file group.h.

Referenced by schema3::Item::Item(), and name().


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