1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- """
- Modelverse operations used by the UI
- """
- import sys
- sys.path.append("..")
- import wrappers.modelverse as mv
- import commons
- def get_available_types():
- """ Returns a list of all types of nodes in all example models """
- types = []
- for m in commons.all_example_models():
- nodes = mv.all_instances(m, "Node")
- for node in nodes:
- typ = commons.get_node_type(m, node)
- types.append(typ)
- return list(set(types))
- def is_edge_supported(from_type, to_type):
- """
- True if an association between from_type and to_type exists in any example model
- False otherwise
- """
- for m in commons.all_example_models():
- nodes_from = commons.all_nodes_with_type(m, from_type)
- nodes_to = commons.all_nodes_with_type(m, to_type)
- for nf in nodes_from:
- for nt in nodes_to:
- assocs = commons.get_associations_between(m, nf, nt)
- if assocs:
- # somewhere in an example model, there is such an association
- return True
- return False
- def add_node(model, node_type):
- """ Adds new node to model "model" with type attribute "node_type" """
- node_id = mv.instantiate(model, "Node")
- mv.attr_assign(model, node_id, "typeID", node_type)
- print("Added node with id {} and type {} to model {}".format(node_id, node_type, model))
- return node_id
- def add_edge(model, from_id, to_id, directed=False):
- """ Adds an edge to model "model" between the nodes "from_id" and "to_id" """
- edge_id = mv.instantiate(model, "Edge", (from_id, to_id))
- mv.attr_assign(model, edge_id, "directed", directed)
- print("Added edge between {} and {} to model".format(from_id, to_id))
- return edge_id
|