Minsky
minsky::Selection Struct Reference

represents items that have been selected More...

#include <selection.h>

Inheritance diagram for minsky::Selection:
Inheritance graph
Collaboration diagram for minsky::Selection:
Collaboration graph

Public Member Functions

void clear ()
 
void toggleItemMembership (const ItemPtr &item)
 add item to selection if not present, or removes it if present groups handled as well More...
 
void ensureItemInserted (const ItemPtr &item)
 check if item already present, and if not, inserts item delegates to ensureGroupInserted if passed a group More...
 
void ensureGroupInserted (const GroupPtr &item)
 check if group already present, and if not, inserts it More...
 
void insertItem (const ItemPtr &item)
 
void insertGroup (const GroupPtr &g)
 
bool contains (const ItemPtr &item) const
 return if item is contained in selection More...
 
virtual bool contains (float xx, float yy) const
 
bool contains (const Point &p) const
 
- Public Member Functions inherited from minsky::Group
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...
 

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...
 
- Public Attributes inherited from minsky::Group
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 inherited from minsky::Group
static SVGRenderer svgRenderer
 
- Protected Member Functions inherited from minsky::Group
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)
 
- 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

represents items that have been selected

Definition at line 32 of file selection.h.

Member Function Documentation

◆ clear()

void minsky::Selection::clear ( )

Definition at line 30 of file selection.cc.

Referenced by minsky::VariableInstanceList::gotoInstance().

31  {
32  for (auto& i: items) i->selected=false;
33  for (auto& i: groups) i->selected=false;
34  Group::clear();
35  }
void clear()
Definition: group.h:91
Groups groups
Definition: group.h:79
Here is the caller graph for this function:

◆ contains() [1/3]

bool minsky::Selection::contains ( const ItemPtr item) const

return if item is contained in selection

Definition at line 102 of file selection.cc.

103  {
104  if (!item) return false;
105  if (auto g=std::dynamic_pointer_cast<Group>(item))
106  {
107  if (find(groups.begin(), groups.end(), g)!=groups.end())
108  return true;
109  }
110  else if (find(items.begin(), items.end(), item)!=items.end())
111  return true;
112  // at this point, we need to check if item is contained in any of
113  // the selected groups
114  if (auto gi=item->group.lock())
115  for (auto& g: groups)
116  if (g==gi || g->higher(*gi))
117  return true;
118  return false;
119  }
Groups groups
Definition: group.h:79

◆ contains() [2/3]

virtual bool minsky::Item::contains
inline

Definition at line 196 of file item.h.

196  {
197  auto hz=resizeHandleSize(); // extend by resize handle size (which is also portRadius)
198  return left()-hz<=xx && right()+hz>=xx && top()-hz<=yy && bottom()+hz>=yy;
199  }
float top() const
Definition: item.cc:177
float left() const
Definition: item.cc:163
float resizeHandleSize() const
resize handles should be at least a percentage if the icon size (#1025)
Definition: item.h:255

◆ contains() [3/3]

bool minsky::Item::contains
inline

Definition at line 200 of file item.h.

200 {return contains(p.x(),p.y());}
bool contains(const ItemPtr &item) const
return if item is contained in selection
Definition: selection.cc:102

◆ ensureGroupInserted()

void minsky::Selection::ensureGroupInserted ( const GroupPtr item)

check if group already present, and if not, inserts it

Definition at line 73 of file selection.cc.

74  {
75  if (!item) return; //nothing to do
76  auto i=find(groups.begin(), groups.end(), item);
77  if (i==groups.end())
78  insertGroup(item);
79  }
void insertGroup(const GroupPtr &g)
Definition: selection.h:49
Groups groups
Definition: group.h:79

◆ ensureItemInserted()

void minsky::Selection::ensureItemInserted ( const ItemPtr item)

check if item already present, and if not, inserts item delegates to ensureGroupInserted if passed a group

Definition at line 60 of file selection.cc.

Referenced by minsky::VariableInstanceList::gotoInstance(), minsky::IntOp::insertControlled(), minsky::VariableBase::insertControlled(), and minsky::GodleyIcon::insertControlled().

61  {
62  if (!item) return; //nothing to do
63  if (auto g=dynamic_pointer_cast<Group>(item))
64  {
66  return;
67  }
68  auto i=find(items.begin(), items.end(), item);
69  if (i==items.end())
70  insertItem(item);
71  }
void insertItem(const ItemPtr &item)
Definition: selection.cc:81
void ensureGroupInserted(const GroupPtr &item)
check if group already present, and if not, inserts it
Definition: selection.cc:73
Here is the caller graph for this function:

◆ insertGroup()

void minsky::Selection::insertGroup ( const GroupPtr g)
inline

Definition at line 49 of file selection.h.

References minsky::GroupItems::groups.

49  {
50  groups.push_back(g);
51  g->selected=true;
52  }
Groups groups
Definition: group.h:79

◆ insertItem()

void minsky::Selection::insertItem ( const ItemPtr item)

Definition at line 81 of file selection.cc.

82  {
83  items.push_back(item);
84  item->insertControlled(*this);
85  item->selected=true;
86  // insert any attached wires that connect to already selected items
87  if (auto g=item->group.lock())
88  for (size_t i=0; i<item->portsSize(); ++i)
89  {
90  auto p=item->ports(i).lock();
91  for (auto w: p->wires())
92  {
93  auto& other_end=p->input()? w->from()->item(): w->to()->item();
94  if (find_if(items.begin(), items.end(),
95  [&](const ItemPtr& i) {return i.get()==&other_end;})
96  !=items.end())
97  wires.push_back(g->findWire(*w));
98  }
99  }
100  }
std::shared_ptr< Item > ItemPtr
Definition: item.h:57

◆ toggleItemMembership()

void minsky::Selection::toggleItemMembership ( const ItemPtr item)

add item to selection if not present, or removes it if present groups handled as well

Definition at line 37 of file selection.cc.

38  {
39  if (!item) return;
40  if (removeItem(*item))
41  {
42  item->selected=false;
43  item->removeControlledItems(*this);
44  }
45  else if (auto gPtr=std::dynamic_pointer_cast<Group>(item))
46  {
47  auto it=find(groups.begin(), groups.end(),gPtr);
48  if (it!=groups.end())
49  {
50  groups.erase(it);
51  gPtr->selected=false;
52  }
53  else
54  insertGroup(gPtr);
55  }
56  else
57  insertItem(item);
58  }
void insertItem(const ItemPtr &item)
Definition: selection.cc:81
void insertGroup(const GroupPtr &g)
Definition: selection.h:49
Groups groups
Definition: group.h:79
ItemPtr removeItem(const Item &)
Definition: group.cc:212

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