Minsky
minsky::GroupItems Class Referenceabstract

#include <group.h>

Inheritance diagram for minsky::GroupItems:
Inheritance graph
Collaboration diagram for minsky::GroupItems:
Collaboration graph

Public Member Functions

 GroupItems ()
 
virtual ~GroupItems ()
 
 GroupItems (const GroupItems &x)
 
GroupItemsoperator= (const GroupItems &)
 
void clear ()
 
bool empty () const
 
virtual bool nocycles () const =0
 tests that groups are arranged heirarchically without any recurrence More...
 
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...
 
virtual ItemPtr addItem (const std::shared_ptr< Item > &, bool inSchema=false)
 
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...
 

Static Public Member Functions

static void adjustWiresGroup (Wire &w)
 adjust wire's group to be the least common ancestor of its ports More...
 

Public Attributes

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...
 

Protected Member Functions

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 Attributes

bool inDestructor =false
 

Friends

class Canvas
 

Detailed Description

Definition at line 57 of file group.h.

Constructor & Destructor Documentation

◆ GroupItems() [1/2]

minsky::GroupItems::GroupItems ( )
inline

Definition at line 84 of file group.h.

84 {}

◆ ~GroupItems()

virtual minsky::GroupItems::~GroupItems ( )
inlinevirtual

Definition at line 85 of file group.h.

References clear(), and inDestructor.

85 {inDestructor=true; clear();}
bool inDestructor
Definition: group.h:59
void clear()
Definition: group.h:91
Here is the call graph for this function:

◆ GroupItems() [2/2]

minsky::GroupItems::GroupItems ( const GroupItems x)
inline

Definition at line 87 of file group.h.

87 {};

Member Function Documentation

◆ addGroup() [1/2]

GroupPtr minsky::GroupItems::addGroup ( const std::shared_ptr< Group > &  g)

Definition at line 659 of file group.cc.

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

660  {
661  assert(g);
662  auto origGroup=g->group.lock();
663  if (origGroup.get()==this) return g; // nothing to do
664  if (origGroup)
665  origGroup->removeGroup(*g);
666  groups.push_back(g);
667  g->group=self;
668  g->self=groups.back();
669  assert(nocycles());
670  return groups.back();
671  }
virtual bool nocycles() const =0
tests that groups are arranged heirarchically without any recurrence
Groups groups
Definition: group.h:79
Here is the caller graph for this function:

◆ addGroup() [2/2]

GroupPtr minsky::GroupItems::addGroup ( Group g)
inline

Definition at line 173 of file group.h.

References addGroup().

Referenced by addGroup().

173 {return addGroup(std::shared_ptr<Group>(g));}
GroupPtr addGroup(const std::shared_ptr< Group > &)
Definition: group.cc:659
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addItem() [1/2]

ItemPtr minsky::GroupItems::addItem ( Item it,
bool  inSchema = false 
)
inline

add item, ownership is passed

Definition at line 165 of file group.h.

References addItem().

Referenced by addItem(), and minsky::Group::addItem().

165 {return addItem(std::shared_ptr<Item>(it),inSchema);}
ItemPtr addItem(Item *it, bool inSchema=false)
add item, ownership is passed
Definition: group.h:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addItem() [2/2]

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

add item.

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

Reimplemented in minsky::Group.

Definition at line 331 of file group.cc.

References minsky::Minsky::bookmarkRefresh(), TCLcmd::trap::init, and pyminsky::minsky.

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  }
ItemPtr addItem(Item *it, bool inSchema=false)
add item, ownership is passed
Definition: group.h:165
struct TCLcmd::trap::init_t init
GroupPtr addGroup(const std::shared_ptr< Group > &)
Definition: group.cc:659
void renameVar(const GroupPtr &origGroup, VariableBase &v)
rename variable so that it maintains most general scope possible
Definition: group.cc:303
virtual void bookmarkRefresh()
refresh the bookmark menu after changes
Definition: minsky.h:450
static void adjustWiresGroup(Wire &w)
adjust wire&#39;s group to be the least common ancestor of its ports
Definition: group.cc:404
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ addWire() [1/6]

WirePtr minsky::GroupItems::addWire ( const Item from,
const Item to,
unsigned  toPortIdx,
const std::vector< float > &  coords 
)
inlineprotected

add a wire from item from, to item to, connecting to the toIdx port of to, with coordinates

Definition at line 63 of file group.h.

References minsky::Item::ports(), and minsky::Item::portsSize().

Referenced by addWire(), minsky::Wire::moveIntoGroup(), and schema3::Minsky::populateGroup().

65  {
66  if (toPortIdx>=to.portsSize()) return WirePtr();
67  return addWire(from.ports(0), to.ports(toPortIdx), coords);
68  }
std::shared_ptr< Wire > WirePtr
Definition: wire.h:102
WirePtr addWire(const Item &from, const Item &to, unsigned toPortIdx, const std::vector< float > &coords)
add a wire from item from, to item to, connecting to the toIdx port of to, with coordinates ...
Definition: group.h:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addWire() [2/6]

WirePtr minsky::GroupItems::addWire ( const std::weak_ptr< Port > &  from,
const std::weak_ptr< Port > &  to,
const std::vector< float > &  coords 
)
protected

Definition at line 680 of file group.cc.

References minsky::cminsky(), and minsky::Minsky::inputWired().

681  {
682  auto fromP=fromPw.lock(), toP=toPw.lock();
683  // disallow self-wiring
684  if (!fromP || !toP || &fromP->item()==&toP->item())
685  return WirePtr();
686 
687  // wire must go from an output port to an input port
688  if (fromP->input() || !toP->input())
689  return WirePtr();
690 
691  // check that multiple input wires are only to binary ops.
692  if (!toP->wires().empty() && !toP->multiWireAllowed())
693  return WirePtr();
694 
695  // check that a wire doesn't already exist connecting these two ports
696  for (auto& w: toP->wires())
697  if (w->from()==fromP)
698  return WirePtr();
699 
700  // disallow wiring the input of an already defined variable
701  if (auto v=toP->item().variableCast())
702  if (cminsky().inputWired(v->valueId()))
703  return {};
704 
705  auto w=addWire(new Wire(fromP, toP, coords));
706  adjustWiresGroup(*w);
707 
708  return w;
709  }
bool inputWired(const std::string &name) const
returns true if any variable of name name has a wired input
Definition: minsky.h:399
std::shared_ptr< Wire > WirePtr
Definition: wire.h:102
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
static void adjustWiresGroup(Wire &w)
adjust wire&#39;s group to be the least common ancestor of its ports
Definition: group.cc:404
WirePtr addWire(const Item &from, const Item &to, unsigned toPortIdx, const std::vector< float > &coords)
add a wire from item from, to item to, connecting to the toIdx port of to, with coordinates ...
Definition: group.h:63
Here is the call graph for this function:

◆ addWire() [3/6]

WirePtr minsky::GroupItems::addWire ( const Item from,
const Item to,
unsigned  toPortIdx 
)
inline

add a wire from item from, to item to, connecting to the toIdx port of to

Definition at line 177 of file group.h.

References addWire().

178  {return addWire(from, to, toPortIdx, {});}
WirePtr addWire(const Item &from, const Item &to, unsigned toPortIdx, const std::vector< float > &coords)
add a wire from item from, to item to, connecting to the toIdx port of to, with coordinates ...
Definition: group.h:63
Here is the call graph for this function:

◆ addWire() [4/6]

WirePtr minsky::GroupItems::addWire ( const std::shared_ptr< Wire > &  w)

Definition at line 673 of file group.cc.

674  {
675  assert(w->from() && w->to());
676  wires.push_back(w);
677  return wires.back();
678  }

◆ addWire() [5/6]

WirePtr minsky::GroupItems::addWire ( Wire w)
inline

Definition at line 180 of file group.h.

References addWire().

Referenced by addWire().

180 {return addWire(std::shared_ptr<Wire>(w));}
WirePtr addWire(const Item &from, const Item &to, unsigned toPortIdx, const std::vector< float > &coords)
add a wire from item from, to item to, connecting to the toIdx port of to, with coordinates ...
Definition: group.h:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addWire() [6/6]

WirePtr minsky::GroupItems::addWire ( const std::weak_ptr< Port > &  from,
const std::weak_ptr< Port > &  to 
)
inline

Definition at line 181 of file group.h.

References addWire().

182  {return addWire(from,to,{});}
WirePtr addWire(const Item &from, const Item &to, unsigned toPortIdx, const std::vector< float > &coords)
add a wire from item from, to item to, connecting to the toIdx port of to, with coordinates ...
Definition: group.h:63
Here is the call graph for this function:

◆ adjustWiresGroup()

void minsky::GroupItems::adjustWiresGroup ( Wire w)
static

adjust wire's group to be the least common ancestor of its ports

Definition at line 404 of file group.cc.

405  {
406  // Find common ancestor group, and move wire to it
407  assert(w.from() && w.to());
408  shared_ptr<Group> p1=w.from()->item().group.lock(), p2=w.to()->item().group.lock();
409  assert(p1 && p2);
410  unsigned l1=p1->level(), l2=p2->level();
411  for (; p1 && l1>l2; l1--) p1=p1->group.lock();
412  for (; p2 && l2>l1; l2--) p2=p2->group.lock();
413 
414  while (p1 && p2 && p1!=p2)
415  {
416  assert(p1 && p2);
417  p1=p1->group.lock();
418  p2=p2->group.lock();
419  }
420  if (!p1 || !p2) return;
421  w.moveIntoGroup(*p1);
422  }

◆ CLASSDESC_ACCESS()

minsky::GroupItems::CLASSDESC_ACCESS ( GroupItems  )
protected

◆ clear()

void minsky::GroupItems::clear ( )
inline

Definition at line 91 of file group.h.

References bookmarks, groups, inVariables, items, outVariables, and wires.

Referenced by minsky::Group::moveContents(), and ~GroupItems().

91  {
92  // controlled items need to be removed from a copy
93  auto itemsCopy=items;
94  for (auto& i: itemsCopy) i->removeControlledItems(*this);
95  items.clear();
96  groups.clear();
97  wires.clear();
98  inVariables.clear();
99  outVariables.clear();
100  bookmarks.clear();
101  }
std::vector< VariablePtr > inVariables
Definition: group.h:82
std::set< Bookmark > bookmarks
Definition: group.h:81
std::vector< VariablePtr > outVariables
Definition: group.h:82
Groups groups
Definition: group.h:79
Here is the caller graph for this function:

◆ empty()

bool minsky::GroupItems::empty ( ) const
inline

Definition at line 102 of file group.h.

References groups, items, and wires.

102 {return items.empty() && groups.empty() && wires.empty();}
Groups groups
Definition: group.h:79

◆ findAll()

template<class R , class M , class C , class X >
std::vector< R > minsky::GroupItems::findAll ( c,
M GroupItems::*  m,
xfm 
) const

finds all items/wires matching criterion c. Found items are transformed by xfm

Definition at line 454 of file group.h.

References groups, and items.

454  {
455  std::vector<R> r;
456  for (auto& i: this->*m)
457  {
458  assert(i);
459  if (c(i)) r.push_back(xfm(i));
460  }
461 
462  for (auto& i: groups)
463  {
464  assert(i);
465  auto items=i->findAll<R>(c,m,xfm);
466  r.insert(r.end(), items.begin(), items.end());
467  }
468  return r;
469  }
Groups groups
Definition: group.h:79

◆ findAny()

template<class M , class C >
const M::value_type minsky::GroupItems::findAny ( M GroupItems::*  map,
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)

Definition at line 442 of file group.h.

References groups.

Referenced by findGroup(), and findWire().

443  {
444  for (auto& i: this->*map)
445  if (c(i))
446  return i;
447  for (auto& g: groups)
448  if (auto& r=g->findAny(map, c))
449  return r;
450  return typename M::value_type();
451  }
Groups groups
Definition: group.h:79
Here is the caller graph for this function:

◆ findGroup()

GroupPtr minsky::GroupItems::findGroup ( const Group it) const
inline

finds group within this group or subgroups. Returns null if not found

Definition at line 139 of file group.h.

References findAny(), and groups.

140  {return findAny(&GroupItems::groups, [&](const GroupPtr& x){return &*x==&it;});}
Groups groups
Definition: group.h:79
const M::value_type findAny(M GroupItems::*map, C c) const
search for the first item in the heirarchy of map for which c is true. M::value_type must evaluate in...
Definition: group.h:442
std::shared_ptr< Group > GroupPtr
Definition: port.h:32
Here is the call graph for this function:

◆ findGroups()

template<class C >
std::vector<GroupPtr> minsky::GroupItems::findGroups ( c) const
inline

returns list of groups matching criterion c

Definition at line 160 of file group.h.

References groups.

160  {
161  return findAll<GroupPtr>(c,&GroupItems::groups,[](GroupPtr x){return x;});
162  }
Groups groups
Definition: group.h:79
std::shared_ptr< Group > GroupPtr
Definition: port.h:32

◆ findItem()

ItemPtr minsky::GroupItems::findItem ( const Item it) const

finds item within this group or subgroups. Returns null if not found

Definition at line 291 of file group.cc.

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

292  {
293  // start by looking in the group it thnks it belongs to
294  if (auto g=it.group.lock())
295  if (g.get()!=this)
296  {
297  auto i=g->findItem(it);
298  if (i) return i;
299  }
300  return findAny(&Group::items, [&](const ItemPtr& x){return x.get()==&it;});
301  }
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
const M::value_type findAny(M GroupItems::*map, C c) const
search for the first item in the heirarchy of map for which c is true. M::value_type must evaluate in...
Definition: group.h:442
Here is the caller graph for this function:

◆ findItems()

template<class C >
std::vector<ItemPtr> minsky::GroupItems::findItems ( c) const
inline

returns list of items matching criterion c

Definition at line 148 of file group.h.

References items.

148  {
149  return findAll<ItemPtr>(c,&GroupItems::items,[](ItemPtr x){return x;});
150  }
std::shared_ptr< Item > ItemPtr
Definition: item.h:57

◆ findWire()

WirePtr minsky::GroupItems::findWire ( const Wire it) const
inline

finds wire within this group or subgroups. Returns null if not found

Definition at line 143 of file group.h.

References findAny(), and wires.

144  {return findAny(&GroupItems::wires, [&](const WirePtr& x){return x.get()==&it;});}
std::shared_ptr< Wire > WirePtr
Definition: wire.h:102
const M::value_type findAny(M GroupItems::*map, C c) const
search for the first item in the heirarchy of map for which c is true. M::value_type must evaluate in...
Definition: group.h:442
Here is the call graph for this function:

◆ findWires()

template<class C >
std::vector<WirePtr> minsky::GroupItems::findWires ( c) const
inline

returns list of wires matching criterion c

Definition at line 154 of file group.h.

References wires.

154  {
155  return findAll<WirePtr>(c,&GroupItems::wires,[](WirePtr x){return x;});
156  }
std::shared_ptr< Wire > WirePtr
Definition: wire.h:102

◆ nocycles()

virtual bool minsky::GroupItems::nocycles ( ) const
pure virtual

tests that groups are arranged heirarchically without any recurrence

Implemented in minsky::Group.

◆ numGroups()

size_t minsky::GroupItems::numGroups ( ) const

total number of groups in this and child groups

Definition at line 491 of file group.cc.

492  {
493  size_t count=groups.size();
494  for (auto& i: groups) count+=i->numGroups();
495  return count;
496  }
Groups groups
Definition: group.h:79

◆ numItems()

size_t minsky::GroupItems::numItems ( ) const

total number of items in this and child groups

Definition at line 477 of file group.cc.

478  {
479  size_t count=items.size();
480  for (auto& i: groups) count+=i->numItems();
481  return count;
482  }
Groups groups
Definition: group.h:79

◆ numWires()

size_t minsky::GroupItems::numWires ( ) const

total number of wires in this and child groups

Definition at line 484 of file group.cc.

485  {
486  size_t count=wires.size();
487  for (auto& i: groups) count+=i->numWires();
488  return count;
489  }
Groups groups
Definition: group.h:79

◆ operator=()

GroupItems& minsky::GroupItems::operator= ( const GroupItems )
inline

Definition at line 88 of file group.h.

88 {return *this;}

◆ recursiveDo() [1/2]

template<class M , class O >
bool minsky::GroupItems::recursiveDo ( M GroupItems::*  map,
op 
) const
inline

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)

Definition at line 111 of file group.h.

References minsky::GroupRecursiveDo(), and minsky::op.

Referenced by schema3::Minsky::Minsky(), minsky::Wire::moveIntoGroup(), and minsky::VariableInstanceList::VariableInstanceList().

112  {return GroupRecursiveDo(*this,map,op);}
bool GroupRecursiveDo(G &gp, M GroupItems::*map, O op)
Definition: group.h:203
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recursiveDo() [2/2]

template<class M , class O >
bool minsky::GroupItems::recursiveDo ( M GroupItems::*  map,
op 
)
inline

O has signature bool(M&, M::iterator)

Definition at line 115 of file group.h.

References minsky::GroupRecursiveDo(), and minsky::op.

116  {return GroupRecursiveDo(*this,map,op);}
bool GroupRecursiveDo(G &gp, M GroupItems::*map, O op)
Definition: group.h:203
Here is the call graph for this function:

◆ removeDisplayPlot()

void minsky::GroupItems::removeDisplayPlot ( )
inline

remove the display plot

Definition at line 196 of file group.h.

References displayPlot.

196  {
197  displayPlot.reset();
198  }
classdesc::Exclude< std::shared_ptr< PlotWidget > > displayPlot
plot widget used for group icon
Definition: group.h:194

◆ removeGroup()

GroupPtr minsky::GroupItems::removeGroup ( const Group group)

Definition at line 275 of file group.cc.

References minsky::group.

276  {
277  for (auto i=groups.begin(); i!=groups.end(); ++i)
278  if (i->get()==&group)
279  {
280  GroupPtr r=*i;
281  groups.erase(i);
282  return r;
283  }
284 
285  for (auto& g: groups)
286  if (GroupPtr r=g->removeGroup(group))
287  return r;
288  return GroupPtr();
289  }
Groups groups
Definition: group.h:79
std::shared_ptr< Group > GroupPtr
Definition: port.h:32
Definition: group.tcl:84

◆ removeItem()

ItemPtr minsky::GroupItems::removeItem ( const Item it)

Definition at line 212 of file group.cc.

References minsky::Item::bookmarkId(), and minsky::VariableBase::controller.

Referenced by schema3::Minsky::populateGroup(), minsky::IntOp::removeControlledItems(), and minsky::GodleyIcon::removeControlledItems().

213  {
214  if (it.plotWidgetCast()==displayPlot.get()) removeDisplayPlot();
215  if (!inDestructor) bookmarks.erase(it.bookmarkId());
216  for (auto i=items.begin(); i!=items.end(); ++i)
217  if (i->get()==&it)
218  {
219  ItemPtr r=*i;
220  items.erase(i);
221  if (auto v=r->variableCast())
222  if (v->ioVar())
223  {
224  remove(inVariables, r);
225  remove(outVariables, r);
226  remove(createdIOvariables, r);
227  v->controller.reset();
228  }
229  return r;
230  }
231 
232  for (auto i=groups.begin(); i!=groups.end(); ++i)
233  if (i->get()==&it)
234  {
235  ItemPtr r=*i;
236  groups.erase(i);
237  return r;
238  }
239 
240 
241  for (auto& g: groups)
242  if (ItemPtr r=g->removeItem(it))
243  return r;
244  return ItemPtr();
245  }
std::vector< VariablePtr > inVariables
Definition: group.h:82
bool inDestructor
Definition: group.h:59
std::vector< VariablePtr > createdIOvariables
Definition: group.h:83
std::set< Bookmark > bookmarks
Definition: group.h:81
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
std::vector< VariablePtr > outVariables
Definition: group.h:82
classdesc::Exclude< std::shared_ptr< PlotWidget > > displayPlot
plot widget used for group icon
Definition: group.h:194
Groups groups
Definition: group.h:79
void removeDisplayPlot()
remove the display plot
Definition: group.h:196
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeWire()

WirePtr minsky::GroupItems::removeWire ( const Wire w)

Definition at line 259 of file group.cc.

260  {
261  for (auto i=wires.begin(); i!=wires.end(); ++i)
262  if (i->get()==&w)
263  {
264  WirePtr r=*i;
265  wires.erase(i);
266  return r;
267  }
268 
269  for (auto& g: groups)
270  if (WirePtr r=g->removeWire(w))
271  return r;
272  return WirePtr();
273  }
std::shared_ptr< Wire > WirePtr
Definition: wire.h:102
Groups groups
Definition: group.h:79

◆ renameVar()

void minsky::GroupItems::renameVar ( const GroupPtr origGroup,
VariableBase v 
)
protected

rename variable so that it maintains most general scope possible

Definition at line 303 of file group.cc.

References minsky::VariableBase::name(), minsky::VariableBase::rawName(), and minsky::valueId().

304  {
305  if (auto thisGroup=self.lock())
306  {
307  if (origGroup->higher(*thisGroup))
308  {
309  // moving local var into an inner group, make global
310  if (v.rawName()[0]!=':')
311  v.name(':'+v.rawName());
312  }
313  else if (thisGroup->higher(*origGroup))
314  {
315  // moving global var into an outer group, link up with variable of same name (if existing)
316  if (v.name()[0]==':')
317  for (auto& i: items)
318  if (auto vv=i->variableCast())
319  if (vv->name()==v.name().substr(1))
320  v.name(v.name().substr(1));
321  }
322  else
323  // moving between unrelated groups
324  if (v.name()[0]==':' && valueId(thisGroup,v.name()) != valueId(origGroup,v.name()))
325  // maintain linkage if possible, otherwise make local
326  v.name(v.name().substr(1));
327  }
328  }
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
Here is the call graph for this function:

Friends And Related Function Documentation

◆ Canvas

friend class Canvas
friend

Definition at line 76 of file group.h.

Member Data Documentation

◆ bookmarks

std::set<Bookmark> minsky::GroupItems::bookmarks

◆ createdIOvariables

std::vector<VariablePtr> minsky::GroupItems::createdIOvariables

Definition at line 83 of file group.h.

◆ displayPlot

classdesc::Exclude<std::shared_ptr<PlotWidget> > minsky::GroupItems::displayPlot

plot widget used for group icon

Definition at line 194 of file group.h.

Referenced by removeDisplayPlot().

◆ groups

◆ inDestructor

bool minsky::GroupItems::inDestructor =false
private

Definition at line 59 of file group.h.

Referenced by ~GroupItems().

◆ inVariables

std::vector<VariablePtr> minsky::GroupItems::inVariables

◆ items

◆ outVariables

std::vector<VariablePtr> minsky::GroupItems::outVariables

◆ self

classdesc::Exclude<std::weak_ptr<Group> > minsky::GroupItems::self

weak ref to this

Definition at line 89 of file group.h.

◆ wires

Wires minsky::GroupItems::wires

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