|
@@ -1,14 +1,14 @@
|
|
|
import sys
|
|
|
sys.path.append("../wrappers")
|
|
|
from wrappers import modelverse as mv
|
|
|
-from commons import *
|
|
|
+import commons
|
|
|
|
|
|
|
|
|
class NodeAdd(object):
|
|
|
def __init__(self):
|
|
|
self._node_type = ""
|
|
|
|
|
|
- def execute(self, model, node_type, local):
|
|
|
+ def execute(self, model, node_type, local, check_if_last=False):
|
|
|
"""
|
|
|
Add a new node with type node_type to model model.
|
|
|
If local is true, the node is only added to the model.
|
|
@@ -18,8 +18,16 @@ class NodeAdd(object):
|
|
|
if local:
|
|
|
mv.transformation_execute_MANUAL("graph_ops/add_node", {"gm":model}, {"gm":model},
|
|
|
callback=self._callback)
|
|
|
+ # Local add can make a type mandatory and therefore break conformance
|
|
|
+ if check_if_last:
|
|
|
+ if commons.is_type_mandatory(node_type):
|
|
|
+ print("Type {} just became mandatory, adding it to instance models ...".format(node_type))
|
|
|
+ # local add made type mandatory, so need to add to instance models
|
|
|
+ for im in commons.all_instance_models():
|
|
|
+ self.execute(im, node_type, local=True, check_if_last=False)
|
|
|
+
|
|
|
else:
|
|
|
- for m in all_models():
|
|
|
+ for m in commons.all_models():
|
|
|
self.execute(m, node_type, local=True)
|
|
|
|
|
|
def _callback(self, model):
|
|
@@ -35,7 +43,7 @@ class NodeDelete(object):
|
|
|
|
|
|
def execute(self, model, node, local, check_if_last=False):
|
|
|
self._node = node
|
|
|
- self._node_type = get_node_type(model, node)
|
|
|
+ self._node_type = commons.get_node_type(model, node)
|
|
|
|
|
|
if local:
|
|
|
mv.transformation_execute_MANUAL("graph_ops/del_node", {"gm":model}, {"gm":model},
|
|
@@ -44,18 +52,18 @@ class NodeDelete(object):
|
|
|
# check if we just deleted the last instance of the node in all example models
|
|
|
# if yes, delete it in instance models as well to preserve their validity
|
|
|
remaining_instances = 0
|
|
|
- for m in all_example_models():
|
|
|
- remaining_instances += len(all_nodes_with_type(m, self._node_type))
|
|
|
+ for m in commons.all_example_models():
|
|
|
+ remaining_instances += len(commons.all_nodes_with_type(m, self._node_type))
|
|
|
if remaining_instances == 0:
|
|
|
# it was indeed the last one, delete from instance models
|
|
|
self._was_last = True
|
|
|
- for m in all_instance_models():
|
|
|
- nodes_to_delete = all_nodes_with_type(m, self._node_type)
|
|
|
+ for m in commons.all_instance_models():
|
|
|
+ nodes_to_delete = commons.all_nodes_with_type(m, self._node_type)
|
|
|
for node in nodes_to_delete:
|
|
|
self.execute(m, node, local=True)
|
|
|
else:
|
|
|
- for m in all_models():
|
|
|
- nodes_to_delete = all_nodes_with_type(m, self._node_type)
|
|
|
+ for m in commons.all_models():
|
|
|
+ nodes_to_delete = commons.all_nodes_with_type(m, self._node_type)
|
|
|
for node in nodes_to_delete:
|
|
|
self.execute(m, node, local=True)
|
|
|
|
|
@@ -83,9 +91,9 @@ class NodeRetype(object):
|
|
|
mv.transformation_execute_MANUAL("graph_ops/retype_node", {"gm":model}, {"gm":model},
|
|
|
callback=self._callback)
|
|
|
else:
|
|
|
- node_type = get_node_type(model, node)
|
|
|
- for m in all_models():
|
|
|
- for node in all_nodes_with_type(m, node_type):
|
|
|
+ node_type = commons.get_node_type(model, node)
|
|
|
+ for m in commons.all_models():
|
|
|
+ for node in commons.all_nodes_with_type(m, node_type):
|
|
|
self.execute(m, node, new_type, local=True)
|
|
|
|
|
|
def _callback(self, model):
|