Minsky: 3.17.0
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 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::Item
 Item ()=default
 
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 =20
 
double m_height =20
 
ItemPortVector m_ports
 
minsky::Item::MemoisedRotator memoisedRotator
 

Detailed Description

Definition at line 218 of file group.h.

Constructor & Destructor Documentation

◆ Group()

minsky::Group::Group ( )
inline

Definition at line 247 of file group.h.

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

247 {iWidth(100); iHeight(100);}
float iHeight() const
Definition: item.h:221
float iWidth() const
Definition: item.h:214
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 1220 of file group.cc.

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

◆ addBookmark()

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

Definition at line 405 of file group.h.

References addBookmarkXY(), and name().

405 {addBookmarkXY(0,0,name);}
std::string name() const override
Definition: group.h:239
void addBookmarkXY(float dx, float dy, const std::string &name)
Definition: group.h:401
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 401 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().

401  {
402  bookmarks.erase(Bookmark{0,0,0,name});
403  bookmarks.emplace(x()-dx, y()-dy, relZoom*zoomFactor(), name);
404  }
std::string name() const override
Definition: group.h:239
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:346
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
std::set< Bookmark > bookmarks
Definition: group.h:79
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 292 of file group.h.

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

292 {inVariables.push_back(addIOVar("input"));}
std::vector< VariablePtr > inVariables
Definition: group.h:80
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(), 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:81
ItemPtr addItem(const std::shared_ptr< Item > &it, bool inSchema=false) override
Definition: group.h:260
std::string uqName(const std::string &name)
extract unqualified portion of name
Definition: valueId.cc:135
BoundingBox bb
canvas bounding box.
Definition: item.h:192
void update(const Item &x)
Definition: item.cc:46
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
double rotation() const
Definition: item.h:208
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:346
virtual float x() const
Definition: item.cc:107
ItemPtr addItem(const std::shared_ptr< Item > &it, bool inSchema=false) override
Definition: group.h:260
virtual float y() const
Definition: item.cc:114
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:436
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: addon.cc:545

◆ addItem() [2/3]

ItemPtr minsky::GroupItems::addItem
inline

add item, ownership is passed

Definition at line 163 of file group.h.

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

◆ 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 260 of file group.h.

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

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

261  {
262  if (it && it->bookmark)
263  addBookmarkXY(it->left(),it->top(),it->bookmarkId());
264  return GroupItems::addItem(it,inSchema);
265  }
ItemPtr addItem(Item *it, bool inSchema=false)
add item, ownership is passed
Definition: group.h:163
void addBookmarkXY(float dx, float dy, const std::string &name)
Definition: group.h:401
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 293 of file group.h.

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

293 {outVariables.push_back(addIOVar("output"));}
std::vector< VariablePtr > outVariables
Definition: group.h:80
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:80
Minsky & minsky()
global minsky object
Definition: addon.cc:545
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 1258 of file group.cc.

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

1259  {
1260  const BusyCursor busy(minsky());
1261  layoutGroup(*this);
1262  }
void layoutGroup(Group &g)
auto layout group items
Definition: autoLayout.cc:101
Minsky & minsky()
global minsky object
Definition: addon.cc:545
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 396 of file group.h.

References minsky::GroupItems::bookmarks.

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

◆ cBounds()

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

for TCL debugging

Definition at line 367 of file group.h.

References contentBounds().

367  {
368  ecolab::array<double> r(4);
369  contentBounds(r[0],r[1],r[2],r[3]);
370  return r;
371  }
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:80
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:80

◆ 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:221
bool displayContents() const
returns whether contents should be displayed. Top level group always displayed
Definition: group.h:330
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:1183
virtual bool onResizeHandle(float x, float y) const
Definition: item.cc:228
float iWidth() const
Definition: item.h:214
static const int topMargin
Definition: group.cc:37

◆ clone()

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

Reimplemented from minsky::Item.

Definition at line 256 of file group.h.

256 {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:1171
float iHeight() const
Definition: item.h:221
float edgeScale() const
scale used to render io variables. Smoothly interpolates between the scale at which internal items ar...
Definition: group.h:361
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:345
float iWidth() const
Definition: item.h:214
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:1151

◆ 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:346
virtual float zoomFactor() const
Definition: item.cc:121
float width() const
Definition: item.h:239
float height() const
Definition: item.h:240
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:1151

◆ 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:349
std::vector< VariablePtr > inVariables
Definition: group.h:80
float right() const
Definition: item.cc:170
float top() const
Definition: item.cc:177
std::vector< VariablePtr > outVariables
Definition: group.h:80
float left() const
Definition: item.cc:163
float bottom() const
Definition: item.cc:184
Groups groups
Definition: group.h:77
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.

References minsky::group.

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

◆ 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(), f, and minsky::group.

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:80
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
std::vector< VariablePtr > outVariables
Definition: group.h:80
void asgClonedPort(shared_ptr< Port > &p, const map< Item *, ItemPtr > &cloneMap)
Definition: group.cc:106
Groups groups
Definition: group.h:77
std::shared_ptr< Group > GroupPtr
Definition: port.h:32
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 1251 of file group.cc.

1252  {
1253  if (findAny(&GroupItems::items, [](const ItemPtr& i){return dynamic_cast<Ravel*>(i.get());}))
1254  return ".rvl";
1255  return ".mky";
1256  }
std::shared_ptr< Item > ItemPtr
Definition: item.h:55
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:440

◆ deleteAttachedWires()

void minsky::Group::deleteAttachedWires ( )
inlineoverridevirtual

delete all attached wires

Reimplemented from minsky::Item.

Definition at line 298 of file group.h.

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

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

◆ deleteBookmark()

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

Definition at line 406 of file group.h.

References minsky::GroupItems::bookmarks.

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

◆ 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:445
virtual void bookmarkRefresh()
refresh the bookmark menu after changes
Definition: minsky.h:436
Minsky & minsky()
global minsky object
Definition: addon.cc:545
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 330 of file group.h.

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

Referenced by localZoom().

330 {return !group.lock() || zoomFactor()*relZoom>1;}
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:346
virtual float zoomFactor() const
Definition: item.cc:121
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 333 of file group.h.

References m_displayContentsChanged.

333 {return m_displayContentsChanged;}
bool m_displayContentsChanged
Definition: group.h:220

◆ 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_rectangle(cairo,0, 0,width, height);
990  cairo_clip(cairo);
991  svgRenderer.render(cairo,width, height);
992  }
993  }
994  }
995 
996  drawEdgeVariables(cairo);
997 
998 
999  // display text label
1000  if (!title.empty())
1001  {
1002  const cairo::CairoSave cs(cairo);
1003  cairo_scale(cairo, z, z);
1004  cairo_select_font_face
1005  (cairo, "sans-serif", CAIRO_FONT_SLANT_ITALIC,
1006  CAIRO_FONT_WEIGHT_NORMAL);
1007  cairo_set_font_size(cairo,12);
1008 
1009  // extract the bounding box of the text
1010  cairo_text_extents_t bbox;
1011  cairo_text_extents(cairo,title.c_str(),&bbox);
1012  const double w=0.5*bbox.width+2;
1013  const double h=0.5*bbox.height+5;
1014 
1015  // if rotation is in 1st or 3rd quadrant, rotate as
1016  // normal, otherwise flip the text so it reads L->R
1017  if (flipped)
1018  cairo_rotate(cairo, M_PI);
1019 
1020  // prepare a background for the text, partially obscuring graphic
1021  const double transparency=displayContents()? 0.25: 1;
1022 
1023  // display text
1024  cairo_move_to(cairo, -w+1, h-12-0.5*(height)/z);
1025  cairo_set_source_rgba(cairo,0,0,0,transparency);
1026  cairo_show_text(cairo,title.c_str());
1027  }
1028 
1029  if (mouseFocus)
1030  {
1031  displayTooltip(cairo,tooltip());
1032  // Resize handles always visible on mousefocus. For ticket 92.
1033  drawResizeHandles(cairo);
1034  }
1035 
1036  cairo_rectangle(cairo,-0.5*width,-0.5*height,width,height);
1037  cairo_clip(cairo);
1038  if (selected)
1039  drawSelected(cairo);
1040 
1041  }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
static SVGRenderer svgRenderer
Definition: group.h:257
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:221
bool displayContents() const
returns whether contents should be displayed. Top level group always displayed
Definition: group.h:330
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
classdesc::Exclude< std::shared_ptr< PlotWidget > > displayPlot
plot widget used for group icon
Definition: group.h:192
static void drawSelected(cairo_t *cairo)
Definition: item.cc:308
float width() const
Definition: item.h:239
float iWidth() const
Definition: item.h:214
static const int topMargin
Definition: group.cc:37
std::string title
Definition: group.h:238
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:240
bool mouseFocus
true if target of a mouseover
Definition: noteBase.h:31
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1151
void drawEdgeVariables(cairo_t *) const
draw representations of edge variables around group icon
Definition: group.cc:1075
void render(cairo_t *, double width, double height) const
render SVG into region of size width height
Definition: SVGItem.cc:84
void drawIORegion(cairo_t *) const
draw notches in the I/O region to indicate dockability of variables there
Definition: group.cc:1104
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 1043 of file group.cc.

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

1045  {
1046  float top=0, bottom=0;
1047  const double angle=rotation() * M_PI / 180.0;
1048  for (size_t i=0; i<vars.size(); ++i)
1049  {
1050  const Rotate r(rotation(),0,0);
1051  auto& v=vars[i];
1052  float y=0;
1053  auto z=v->zoomFactor();
1054  auto t=v->bb.top()*z, b=v->bb.bottom()*z;
1055  if (i>0) y = i%2? top-b: bottom-t;
1056  v->moveTo(r.x(x,y)+this->x(), r.y(x,y)+this->y());
1057  const cairo::CairoSave cs(cairo);
1058  cairo_translate(cairo,x,y);
1059  // cairo context is already rotated, so antirotate
1060  cairo_rotate(cairo,-angle);
1061  v->rotation(rotation());
1062  v->draw(cairo);
1063  if (i==0)
1064  {
1065  bottom=b;
1066  top=t;
1067  }
1068  else if (i%2)
1069  top-=v->height();
1070  else
1071  bottom+=v->height();
1072  }
1073  }
#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:208
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 1075 of file group.cc.

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

◆ 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 1104 of file group.cc.

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

1105  {
1106  const cairo::CairoSave cs(cairo);
1107  float left, right;
1108  margins(left,right);
1109  const float z=zoomFactor();
1110  float y=notchY(inVariables), dy=topMargin*edgeScale();
1111  cairo_set_source_rgba(cairo,0,1,1,0.5);
1112  const float w=0.5*z*iWidth(), h=0.5*z*iHeight();
1113 
1114  cairo_move_to(cairo,-w,-h);
1115  // create notch in input region
1116  cairo_line_to(cairo,-w,y-dy);
1117  cairo_line_to(cairo,left-w-4*z,y-dy);
1118  cairo_line_to(cairo,left-w,y);
1119  cairo_line_to(cairo,left-w-4*z,y+dy);
1120  cairo_line_to(cairo,-w,y+dy);
1121  cairo_line_to(cairo,-w,h);
1122  cairo_line_to(cairo,left-w,h);
1123  cairo_line_to(cairo,left-w,-h);
1124  cairo_close_path(cairo);
1125  cairo_fill(cairo);
1126 
1128  cairo_move_to(cairo,w,-h);
1129  // create notch in output region
1130  cairo_line_to(cairo,w,y-dy);
1131  cairo_line_to(cairo,w-right-2*z,y-dy);
1132  cairo_line_to(cairo,w-right+2*z,y);
1133  cairo_line_to(cairo,w-right-2*z,y+dy);
1134  cairo_line_to(cairo,w,y+dy);
1135  cairo_line_to(cairo,w,h);
1136  cairo_line_to(cairo,w-right,h);
1137  cairo_line_to(cairo,w-right,-h);
1138  cairo_close_path(cairo);
1139  cairo_fill(cairo);
1140 
1141  // draw top margin. for feature 88
1142  cairo_rectangle(cairo,-w,-h,2*w,-topMargin*z);
1143  cairo_fill(cairo);
1144 
1145  // draw bottom margin. for feature 88
1146  cairo_rectangle(cairo,-w,h,2*w,topMargin*z);
1147  cairo_fill(cairo);
1148  }
std::vector< VariablePtr > inVariables
Definition: group.h:80
float right() const
Definition: item.cc:170
virtual float y() const
Definition: item.cc:114
float iHeight() const
Definition: item.h:221
float notchY(const vector< VariablePtr > &vars)
Definition: group.cc:1087
float edgeScale() const
scale used to render io variables. Smoothly interpolates between the scale at which internal items ar...
Definition: group.h:361
virtual float zoomFactor() const
Definition: item.cc:121
std::vector< VariablePtr > outVariables
Definition: group.h:80
float left() const
Definition: item.cc:163
float iWidth() const
Definition: item.h:214
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:1151
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 361 of file group.h.

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

361  {
362  float z=zoomFactor();
363  return z*relZoom>1? z*relZoom: z>1? 1: z;
364  }
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:346
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 1206 of file group.cc.

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

◆ 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:80
Minsky & minsky()
global minsky object
Definition: addon.cc:545
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 415 of file group.h.

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

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

◆ gotoBookmark_b()

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

Definition at line 1243 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::zoom(), and minsky::Bookmark::zoom.

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

1244  {
1245  moveTo(b.x, b.y);
1246  zoom(x(),y(),b.zoom/(relZoom*zoomFactor()));
1247  // TODO add canvas::gotoBookmark to avoid dependency inversion
1248  if (this==cminsky().canvas.model.get()) minsky().canvas.requestRedraw();
1249  }
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:346
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:243
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
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:242
Minsky & minsky()
global minsky object
Definition: addon.cc:545
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:77
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:130
Expr cos(const Expr &x)
Definition: expr.h:136
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:221
virtual float zoomFactor() const
Definition: item.cc:121
float left() const
Definition: item.cc:163
float iWidth() const
Definition: item.h:214
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:1151
double rotation() const
Definition: item.h:208
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.

References minsky::group.

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

◆ localZoom()

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

Definition at line 349 of file group.h.

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

349  {
350  return (displayZoom>0 && displayContents())
351  ? zoomFactor()/displayZoom: 1;
352  }
bool displayContents() const
returns whether contents should be displayed. Top level group always displayed
Definition: group.h:330
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:345
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.

References minsky::group.

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:109
std::vector< ItemPtr > Items
Definition: item.h:360

◆ margins()

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

margin sizes to allow space for edge variables.

Definition at line 1151 of file group.cc.

Referenced by marginsV().

1152  {
1153  left=right=10;
1154  auto tmpMouseFocus=mouseFocus;
1155  mouseFocus=false; // disable mouseFocus for this calculation
1156  for (auto& i: inVariables)
1157  {
1158  assert(i->type()!=VariableType::undefined);
1159  i->bb.update(*i);
1160  if (i->width()>left) left=i->width();
1161  }
1162  for (auto& i: outVariables)
1163  {
1164  assert(i->type()!=VariableType::undefined);
1165  i->bb.update(*i);
1166  if (i->width()>right) right=i->width();
1167  }
1168  mouseFocus=tmpMouseFocus;
1169  }
std::vector< VariablePtr > inVariables
Definition: group.h:80
float right() const
Definition: item.cc:170
std::vector< VariablePtr > outVariables
Definition: group.h:80
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 339 of file group.h.

References margins().

339  {
340  float l, r; margins(l,r); return {l,r};
341  }
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
Definition: group.cc:1151
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:221
virtual float zoomFactor() const
Definition: item.cc:121
float iWidth() const
Definition: item.h:214
Groups groups
Definition: group.h:77
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 228 of file group.h.

References minimalEnclosingGroup().

229  {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:260
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 239 of file group.h.

References title.

Referenced by addBookmark(), and addBookmarkXY().

239 {return title;}
std::string title
Definition: group.h:238
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.

References minsky::group.

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  }

◆ 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 1194 of file group.cc.

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

◆ 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:80
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:80
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: addon.cc:545
Here is the call graph for this function:

◆ randomLayout()

void minsky::Group::randomLayout ( )

randomly lay out items in this group

Definition at line 1264 of file group.cc.

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

1265  {
1266  const BusyCursor busy(minsky());
1267  randomizeLayout(*this);
1268  }
void randomizeLayout(Group &g)
randomly place items on canvas
Definition: autoLayout.cc:88
Minsky & minsky()
global minsky object
Definition: addon.cc:545
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 1284 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().

1285  {
1286  // unqualified versions of the names
1287  auto p=valueId.find(':');
1288  string uqFromName=(p!=string::npos)? valueId.substr(p+1): valueId;
1289  string uqNewName = newName.substr(newName[0]==':'? 1: 0);
1290  set<GodleyIcon*> godleysToUpdate;
1291 #ifndef NDEBUG
1292  auto numItems=this->numItems();
1293 #endif
1294  recursiveDo
1295  (&GroupItems::items, [&](Items&,Items::iterator i)
1296  {
1297  if (auto v=(*i)->variableCast())
1298  if (v->valueId()==valueId)
1299  {
1300  auto varScope=scope(v->group.lock(), valueId);
1301  if (auto g=dynamic_cast<GodleyIcon*>(v->controller.lock().get()))
1302  {
1303  if (varScope==g->group.lock() ||
1304  (!varScope && g->group.lock()==cminsky().model)) // fix local variables
1305  g->table.rename(uqFromName, uqNewName);
1306 
1307  // scope of an external ref in the Godley Table
1308  auto externalVarScope=scope(g->group.lock(), ':'+uqNewName);
1309  // if we didn't find it, perhaps the outerscope variable hasn't been changed
1310  if (!externalVarScope)
1311  externalVarScope=scope(g->group.lock(), ':'+uqFromName);
1312 
1313  if (varScope==externalVarScope || (isGlobal(varScope) && isGlobal(externalVarScope)))
1314  // fix external variable references
1315  g->table.rename(':'+uqFromName, ':'+uqNewName);
1316  // GodleyIcon::update invalidates the iterator, so postpone update
1317  godleysToUpdate.insert(g);
1318  }
1319  else
1320  {
1321  // ensure locality is preserved across the rename
1322  v->name(varScope==v->group.lock()? uqNewName: (':'+uqNewName));
1323  if (auto vv=v->vValue())
1324  v->retype(vv->type()); // ensure correct type. Note this invalidates v.
1325  }
1326  }
1327  return false;
1328  });
1329  assert(this->numItems()==numItems);
1330  for (auto g: godleysToUpdate)
1331  {
1332  g->update();
1333  assert(this->numItems()==numItems);
1334  }
1335  minsky().requestReset(); // Updates model after variables rename. For ticket 1109.
1336  }
std::size_t numItems() const
total number of items in this and child groups
Definition: group.cc:477
void requestReset()
Definition: minsky.cc:466
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:109
std::vector< ItemPtr > Items
Definition: item.h:360
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
GroupPtr model
Definition: minsky.h:242
bool isGlobal(const GroupPtr &g)
Definition: group.cc:46
Minsky & minsky()
global minsky object
Definition: addon.cc:545
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: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
void recentreItems(const T &items, float xc, float yc)
Definition: group.cc:611
float iWidth() const
Definition: item.h:214
static const int topMargin
Definition: group.cc:37
void computeRelZoom()
Definition: group.cc:851
Groups groups
Definition: group.h:77
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:1151
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:192
double m_height
Definition: item.h:153
virtual float zoomFactor() const
Definition: item.cc:121
void update(const Item &x)
Definition: item.cc:46
double m_width
Definition: item.h:153
Groups groups
Definition: group.h:77
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:1151

◆ rotFactor()

float minsky::Group::rotFactor ( ) const

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

Definition at line 1171 of file group.cc.

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

1172  {
1173  float rotFactor;
1174  const float ac=abs(cos(rotation()*M_PI/180));
1175  static const float invSqrt2=1/sqrt(2);
1176  if (ac>=invSqrt2)
1177  rotFactor=1.15/ac; //use |1/cos(angle)| as rotation factor
1178  else
1179  rotFactor=1.15/sqrt(1-ac*ac);//use |1/sin(angle)| as rotation factor
1180  return rotFactor;
1181  }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
Expr cos(const Expr &x)
Definition: expr.h:136
Expr sqrt(const Expr &x)
Definition: expr.h:153
float rotFactor() const
scaling factor to allow a rotated icon to fit on the bitmap
Definition: group.cc:1171
double rotation() const
Definition: item.h:208
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 1183 of file group.cc.

References minsky::RenderVariable::inImage().

1184  {
1185  for (auto& v: inVariables)
1186  if (RenderVariable(*v).inImage(x,y))
1187  return v;
1188  for (auto& v: outVariables)
1189  if (RenderVariable(*v).inImage(x,y))
1190  return v;
1191  return nullptr;
1192  }
std::vector< VariablePtr > inVariables
Definition: group.h:80
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
std::vector< VariablePtr > outVariables
Definition: group.h:80
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.

References minsky::group.

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:349
bool m_displayContentsChanged
Definition: group.h:220
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:346
bool displayContents() const
returns whether contents should be displayed. Top level group always displayed
Definition: group.h:330
void computeRelZoom()
Definition: group.cc:851
Groups groups
Definition: group.h:77

◆ 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:81
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:61
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 1270 of file group.cc.

1271  {
1272  vector<Summary> r;
1273  recursiveDo(&GroupItems::items, [&](const Items&,Items::const_iterator i) {
1274  if (auto g=dynamic_cast<GodleyIcon*>(i->get()))
1275  {
1276  auto summary=g->summarise();
1277  r.insert(r.end(),summary.begin(), summary.end());
1278  }
1279  return false;
1280  });
1281  return r;
1282  }
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:109
std::vector< ItemPtr > Items
Definition: item.h:360

◆ 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:77

◆ uniqueItems() [2/2]

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

Definition at line 324 of file group.h.

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

◆ zoom()

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

Definition at line 894 of file group.cc.

References minsky::group, and 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:220
float relZoom
relative zoom contents of this group are displayed at
Definition: group.h:346
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:330
Groups groups
Definition: group.h:77
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:170
float m_x
Definition: item.h:170
Here is the call graph for this function:

Friends And Related Function Documentation

◆ Canvas

friend class Canvas
friend

Definition at line 230 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 345 of file group.h.

Referenced by localZoom().

◆ m_displayContentsChanged

bool minsky::Group::m_displayContentsChanged =true
private

Definition at line 220 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 346 of file group.h.

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

◆ svgRenderer

SVGRenderer minsky::Group::svgRenderer
static

Definition at line 257 of file group.h.

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

◆ title

std::string minsky::Group::title

Definition at line 238 of file group.h.

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


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