|
@@ -8,6 +8,7 @@ from sketchUI.graphics_sketch_group import SketchGroup
|
|
|
from sketchUI.graphics_sketch_line import SketchedLineItem
|
|
|
from sketchUI import mvops
|
|
|
from evolution.node_ops import NodeAdd, NodeDelete, NodeRetype
|
|
|
+from evolution.attribute_ops import AttributeAdd
|
|
|
import commons
|
|
|
|
|
|
|
|
@@ -358,58 +359,72 @@ class SketchScene(QGraphicsScene):
|
|
|
self._parent.plainTextEdit.appendPlainText("OK")
|
|
|
|
|
|
def _handle_keypress_delete(self, selected):
|
|
|
- del_hander = NodeDelete()
|
|
|
-
|
|
|
if len(selected) == 1 and isinstance(selected[0], GraphicsEdgeItem):
|
|
|
+ # an edge is to be deleted
|
|
|
+ # TODO: use evolution code
|
|
|
self._parent.plainTextEdit.appendPlainText("Deleting edge")
|
|
|
edge = selected[0]
|
|
|
mvops.delete_node(self._cur_model, edge.edge_id)
|
|
|
self.removeItem(edge)
|
|
|
return
|
|
|
|
|
|
- for item in selected:
|
|
|
- # only delete nodes, edges are taken care of later
|
|
|
- if isinstance(item, GraphicsNodeItem):
|
|
|
- self._parent.plainTextEdit.appendPlainText("Deleting node of type {}".format(item.get_type()))
|
|
|
- # when deleting a node, local or global?
|
|
|
- scope, ok = QInputDialog.getItem(self._parent, "Select scope", "Scope", ["Local", "Global"])
|
|
|
- if not ok:
|
|
|
- return
|
|
|
- QApplication.setOverrideCursor(Qt.WaitCursor)
|
|
|
- if scope == "Global":
|
|
|
- # global language evolution, so delete node with same type everywhere
|
|
|
- del_hander.execute(self._cur_model, item.node_id, local=False, check_if_last=False)
|
|
|
- # also delete its associated CS model
|
|
|
- mvops.del_concrete_syntax_model(item.get_type())
|
|
|
- else:
|
|
|
- # just local, delete from this model only
|
|
|
- del_hander.execute(self._cur_model, item.node_id, local=True, check_if_last=True)
|
|
|
- if del_hander.was_last():
|
|
|
- # it was the last node, so delete its CS model as well
|
|
|
- mvops.del_concrete_syntax_model(item.get_type())
|
|
|
-
|
|
|
- # in view, delete edges that were connected to this node as well
|
|
|
- # modelverse does this on its own so do not delete edges explicitly here
|
|
|
+ elif len(selected) == 1 and isinstance(selected[0], GraphicsNodeItem):
|
|
|
+ del_hander = NodeDelete()
|
|
|
+ node = selected[0]
|
|
|
+ # a node is to be deleted
|
|
|
+ self._parent.plainTextEdit.appendPlainText("Deleting node of type {}".format(node.get_type()))
|
|
|
+ # when deleting a node, local or global?
|
|
|
+ scope, ok = QInputDialog.getItem(self._parent, "Select scope", "Scope", ["Local", "Global"])
|
|
|
+ if not ok:
|
|
|
+ return
|
|
|
+ QApplication.setOverrideCursor(Qt.WaitCursor)
|
|
|
+ if scope == "Global":
|
|
|
+ # global language evolution, so delete node with same type everywhere
|
|
|
+ del_hander.execute(self._cur_model, node.node_id, local=False, check_if_last=False)
|
|
|
+ # also delete its associated CS model
|
|
|
+ mvops.del_concrete_syntax_model(node.get_type())
|
|
|
+
|
|
|
+ # delete all nodes of type from view
|
|
|
+ for item in self.items():
|
|
|
+ if not isinstance(item, GraphicsNodeItem):
|
|
|
+ continue
|
|
|
+ if item.get_type() == node.get_type():
|
|
|
+ self.removeItem(item)
|
|
|
+
|
|
|
+ else:
|
|
|
+ # just local, delete from this model only
|
|
|
+ del_hander.execute(self._cur_model, node.node_id, local=True, check_if_last=True)
|
|
|
+ if del_hander.was_last():
|
|
|
+ # it was the last node in the language, so delete its CS model as well
|
|
|
+ mvops.del_concrete_syntax_model(node.get_type())
|
|
|
+ # delete this node from view
|
|
|
+ self.removeItem(node)
|
|
|
+
|
|
|
+ # in view, delete edges that were connected to this node as well
|
|
|
+ # modelverse does this on its own so do not delete edges explicitly here
|
|
|
+ if scope == "Local":
|
|
|
for edge in self.items():
|
|
|
if not isinstance(edge, GraphicsEdgeItem):
|
|
|
continue
|
|
|
- if edge.from_item.node_id == item.node_id or edge.to_item.node_id == item.node_id:
|
|
|
+ if edge.from_item.node_id == node.node_id or edge.to_item.node_id == node.node_id:
|
|
|
+ self.removeItem(edge)
|
|
|
+ else:
|
|
|
+ # have to remove all edges connected to this type in model
|
|
|
+ for edge in self.items():
|
|
|
+ if not isinstance(edge, GraphicsEdgeItem):
|
|
|
+ continue
|
|
|
+ if edge.from_item.get_type() == node.get_type() or edge.to_item.get_type() == node.get_type():
|
|
|
self.removeItem(edge)
|
|
|
|
|
|
- self.removeItem(item)
|
|
|
-
|
|
|
- elif isinstance(item, GraphicsEdgeItem):
|
|
|
- continue
|
|
|
+ # repopulate available types just in case
|
|
|
+ self._parent.populate_types()
|
|
|
|
|
|
- else:
|
|
|
- # no NodeItem -> untyped sketch, simply remove
|
|
|
+ else:
|
|
|
+ if not any(isinstance(x, GraphicsNodeItem) for x in selected) and not any(isinstance(x, GraphicsEdgeItem) for x in selected):
|
|
|
+ # neither NodeItem nor EdgeItem in selected -> untyped sketch item, simply remove
|
|
|
for obj in selected:
|
|
|
self.removeItem(obj)
|
|
|
|
|
|
- # if any node was deleted, repopulate list of available items
|
|
|
- if any(isinstance(item, GraphicsNodeItem) for item in selected):
|
|
|
- self._parent.populate_types()
|
|
|
-
|
|
|
QApplication.restoreOverrideCursor()
|
|
|
|
|
|
def _handle_keypress_attribute(self, selected):
|
|
@@ -431,7 +446,20 @@ class SketchScene(QGraphicsScene):
|
|
|
self._parent.plainTextEdit.appendPlainText("Error: Already such a key for the node: {}".format(key))
|
|
|
return
|
|
|
|
|
|
- self._parent.add_new_attribute(key)
|
|
|
+ # ask of global or local add attribute
|
|
|
+ scope, ok = QInputDialog.getItem(self._parent, "Select scope", "Scope", ["Local", "Global"])
|
|
|
+ if not ok:
|
|
|
+ return
|
|
|
+
|
|
|
+ add_handler = AttributeAdd()
|
|
|
+
|
|
|
+ if scope == "Global":
|
|
|
+ add_handler.execute(self._cur_model, item.node_id, key, "unknown", local=False)
|
|
|
+ else:
|
|
|
+ add_handler.execute(self._cur_model, item.node_id, key, "unknown", local=True)
|
|
|
+
|
|
|
+ # add to view
|
|
|
+ self._parent.add_new_attribute(key, "unknown")
|
|
|
|
|
|
def highlight_node(self, node_id, color):
|
|
|
for item in self.items():
|