31 #include "TCL_obj_stl.h" 35 #include "classdesc.h" 41 #include "tensorVal.h" 49 namespace minsky {
class PlotWidget; }
50 namespace minsky {
struct LassoBox; }
54 typedef std::vector<GroupPtr>
Groups;
64 const std::vector<float>& coords)
71 const std::weak_ptr<Port>& to,
72 const std::vector<float>& coords);
89 classdesc::Exclude<std::weak_ptr<Group>>
self;
94 for (
auto& i: itemsCopy) i->removeControlledItems(*
this);
110 template <
class M,
class O>
114 template <
class M,
class O>
123 template <
class M,
class C>
128 template <
class R,
class M,
class C,
class X>
169 virtual ItemPtr addItem(
const std::shared_ptr<Item>&,
bool inSchema=
false);
178 {
return addWire(from, to, toPortIdx, {});}
202 template <
class G,
class M,
class O>
205 for (
auto i=(gp.*map).begin(); i!=(gp.*map).end(); ++i)
211 for (
auto& g: gp.groups)
214 if (g->recursiveDo(map,
op))
237 float contentBounds(
double& x0,
double& y0,
double& x1,
double& y1)
const;
243 double operator()(
const std::vector<double>& p)
override;
258 Group*
clone()
const override {
throw error(
"Groups cannot be cloned");}
264 if (it && it->bookmark)
273 void draw(cairo_t*)
const override;
278 void draw1edge(
const std::vector<VariablePtr>& vars, cairo_t* cairo,
301 for (
auto& i:
inVariables) i->deleteAttachedWires();
316 unsigned level()
const;
327 std::set<void*> idset;
342 float l, r;
margins(l,r);
return {l,r};
358 void zoom(
float xOrigin,
float yOrigin,
float factor);
370 ecolab::array<double> r(4);
399 std::vector<std::string> r;
400 for (
auto& b:
bookmarks) r.push_back(b.name);
441 template <
class M,
class C>
444 for (
auto& i: this->*map)
448 if (
auto& r=g->findAny(map, c))
450 return typename M::value_type();
453 template <
class R,
class M,
class C,
class X>
456 for (
auto& i: this->*m)
459 if (c(i)) r.push_back(xfm(i));
465 auto items=i->findAll<R>(c,m,xfm);
466 r.insert(r.end(),
items.begin(),
items.end());
476 #pragma omit pack minsky::Group 477 #pragma omit unpack minsky::Group 482 public classdesc::NullDescriptor<classdesc::pack_t> {};
484 public classdesc::NullDescriptor<classdesc::unpack_t> {};
ItemPtr addItem(Item *it, bool inSchema=false)
add item, ownership is passed
void deleteBookmark(std::size_t i)
static SVGRenderer svgRenderer
returns which I/O region (x,y) is in if any
WirePtr removeWire(const Wire &)
std::vector< WirePtr > Wires
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
std::string name() const override
GroupPtr copyUnowned() const
make a copy of this, that is not owned by any group
std::size_t numItems() const
total number of items in this and child groups
void addBookmark(const std::string &name)
std::vector< WirePtr > findWires(C c) const
returns list of wires matching criterion c
std::vector< VariablePtr > inVariables
std::vector< float > marginsV() const
for debugging purposes
std::size_t portsSize() const
number of ports
void checkAddIORegion(const ItemPtr &x)
check if item is a variable and located in an I/O region, and add it if it is
std::vector< VariablePtr > createdIOvariables
bool m_displayContentsChanged
float relZoom
relative zoom contents of this group are displayed at
ItemPtr addItem(const std::shared_ptr< Item > &it, bool inSchema=false) override
IORegion::type inIORegion(float x, float y) const
std::vector< std::string > accessibleVars() const
return a list of existing variables a variable in this group could be connected to ...
bool nocycles() const override
tests that groups are arranged heirarchically without any recurrence
float rotFactor() const
scaling factor to allow a rotated icon to fit on the bitmap
GroupPtr removeGroup(const Group &)
represents rectangular region of a lasso operation
void resize(const LassoBox &x) override
resize this item on the canvas
bool displayContents() const
returns whether contents should be displayed. Top level group always displayed
std::vector< Summary > summariseGodleys() const
produce a summary of godley table variables
std::set< Bookmark > bookmarks
std::shared_ptr< Item > ItemPtr
GroupItems & operator=(const GroupItems &)
std::shared_ptr< Wire > WirePtr
bool displayContentsChanged() const
true if displayContents status changed on this or any contained group last zoom
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Group * minimalEnclosingGroup(float x0, float y0, float x1, float y1, const Item *ignore=nullptr)
bool recursiveDo(M GroupItems::*map, O op) const
Perform action heirarchically on elements of map map. If op returns true, the operation terminates...
float edgeScale() const
scale used to render io variables. Smoothly interpolates between the scale at which internal items ar...
void deleteItem(const Item &)
remove item from group, and also all attached wires.
void moveContents(Group &source)
move all items from source to this
ecolab::array< double > cBounds() const
for TCL debugging
void resizeOnContents()
adjust position and size of icon to just cover contents
virtual float zoomFactor() const
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.
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...
void flipContents()
rotate all conatined items by 180 degrees
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
std::vector< VariablePtr > outVariables
float displayZoom
computes the zoom at which to show contents, given current contentBounds and width ...
void setZoom(float factor)
sets the zoom factor to factor. Recursively set the zoomfactor on contained objects to the computed l...
classdesc::Exclude< std::shared_ptr< PlotWidget > > displayPlot
plot widget used for group icon
GroupPtr findGroup(const Group &it) const
finds group within this group or subgroups. Returns null if not found
ItemPtr findItem(const Item &it) const
finds item within this group or subgroups. Returns null if not found
std::string formula() const
algebraic formula representing value of first output argument of this group
void normaliseGroupRefs(const std::shared_ptr< Group > &self)
fix up subgroup pointers self is a shared pointer ref to this
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky's state cha...
GroupPtr addGroup(const std::shared_ptr< Group > &)
void gotoBookmark(std::size_t i)
std::vector< GroupPtr > findGroups(C c) const
returns list of groups matching criterion c
std::vector< ItemPtr > Items
bool GroupRecursiveDo(G &gp, M GroupItems::*map, O op)
void deleteAttachedWires() override
delete all attached wires
void randomLayout()
randomly lay out items in this group
GroupPtr addGroup(Group *g)
void renameVar(const GroupPtr &origGroup, VariableBase &v)
rename variable so that it maintains most general scope possible
WirePtr addWire(const std::weak_ptr< Port > &from, const std::weak_ptr< Port > &to)
void splitBoundaryCrossingWires()
splits any wires that cross group boundaries
std::vector< GroupPtr > Groups
unsigned level() const
return level in the heirarchy
double operator()(const std::vector< double > &p) override
evaluate function on arbitrary number of arguments (exprtk support)
void gotoBookmark_b(const Bookmark &b)
static void adjustWiresGroup(Wire &w)
adjust wire's group to be the least common ancestor of its ports
WirePtr findWire(const Wire &it) const
finds wire within this group or subgroups. Returns null if not found
virtual bool nocycles() const =0
tests that groups are arranged heirarchically without any recurrence
GroupPtr copy() const
Make a copy of this as a sibling group (owned by parent). Attempting to copying minsky.model is a null operation.
void addBookmarkXY(float dx, float dy, const std::string &name)
float computeDisplayZoom()
const Group & globalGroup() const
top level group
void draw1edge(const std::vector< VariablePtr > &vars, cairo_t *cairo, float x) const
draw the variables of one of the edges
bool higher(const Group &) const
returns true if this is higher in the heirarchy than the argument this->higher(*this) is false ...
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 ...
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...
CLASSDESC_ACCESS(GroupItems)
bool recursiveDo(M GroupItems::*map, O op)
O has signature bool(M&, M::iterator)
std::shared_ptr< Group > GroupPtr
GroupItems(const GroupItems &x)
Group * clone() const override
ClickType::Type clickType(float x, float y) const override
returns the clicktype given a mouse click at x, y.
VariablePtr addIOVar(const char *)
virtual std::weak_ptr< Port > ports(std::size_t i) const
callback to be run when item deleted from group
std::size_t numGroups() const
total number of groups in this and child groups
void removeDisplayPlot()
remove the display plot
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...
std::vector< std::string > bookmarkList()
returns list of bookmark names for populating menu
void makeSubroutine()
Make all variables not present in outerscope local to this group.
void margins(float &left, float &right) const
margin sizes to allow space for edge variables.
std::string arguments() const
argument declaration, to be appended to name() for function declaration
void autoLayout()
automatically lay out items in this group using a graph layout algorithm
void renameAllInstances(const std::string &valueId, const std::string &newName)
rename all instances of a variable matching valueId to newName
void drawEdgeVariables(cairo_t *) const
draw representations of edge variables around group icon
void draw(cairo_t *) const override
draw this item into a cairo context
std::size_t numWires() const
total number of wires in this and child groups
void zoom(float xOrigin, float yOrigin, float factor)
std::string defaultExtension() const
return default extension for this group - .mky if no ravels in group, .rvl otherwise ...
ItemPtr removeItem(const Item &)
void drawIORegion(cairo_t *) const
draw notches in the I/O region to indicate dockability of variables there
std::vector< ItemPtr > findItems(C c) const
returns list of items matching criterion c