24 #include "selection.rcd" 30 void Selection::clear()
32 for (
auto& i: items) i->selected=
false;
33 for (
auto& i: groups) i->selected=
false;
37 void Selection::toggleItemMembership(
const ItemPtr& item)
40 if (removeItem(*item))
43 item->removeControlledItems(*
this);
45 else if (
auto gPtr=std::dynamic_pointer_cast<Group>(item))
47 auto it=find(groups.begin(), groups.end(),gPtr);
60 void Selection::ensureItemInserted(
const ItemPtr& item)
63 if (
auto g=dynamic_pointer_cast<Group>(item))
65 ensureGroupInserted(g);
68 auto i=find(items.begin(), items.end(), item);
73 void Selection::ensureGroupInserted(
const GroupPtr& item)
76 auto i=find(groups.begin(), groups.end(), item);
81 void Selection::insertItem(
const ItemPtr& item)
83 items.push_back(item);
84 item->insertControlled(*
this);
87 if (
auto g=item->group.lock())
88 for (
size_t i=0; i<item->portsSize(); ++i)
90 auto p=item->ports(i).lock();
91 for (
auto w: p->wires())
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;})
97 wires.push_back(g->findWire(*w));
102 bool Selection::contains(
const ItemPtr& item)
const 104 if (!item)
return false;
105 if (
auto g=std::dynamic_pointer_cast<Group>(item))
107 if (find(groups.begin(), groups.end(), g)!=groups.end())
110 else if (find(items.begin(), items.end(), item)!=items.end())
114 if (
auto gi=item->group.lock())
115 for (
auto& g: groups)
116 if (g==gi || g->higher(*gi))
represents items that have been selected
std::shared_ptr< Item > ItemPtr
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky's state cha...
CLASSDESC_ACCESS_EXPLICIT_INSTANTIATION(minsky::Selection)
std::shared_ptr< Group > GroupPtr