|
@@ -1,7 +1,7 @@
|
|
|
from enum import Enum
|
|
|
from PyQt5.QtWidgets import QGraphicsScene, QGraphicsItem, QGraphicsLineItem, QGraphicsRectItem, \
|
|
|
QGraphicsEllipseItem, QInputDialog, QGraphicsItemGroup
|
|
|
-from PyQt5.Qt import Qt, QPointF, QPen, QTransform
|
|
|
+from PyQt5.Qt import Qt, QPointF, QPen, QTransform, QApplication
|
|
|
from sketchUI.graphics_edge_item import GraphicsEdgeItem
|
|
|
from sketchUI.graphics_node_item import GraphicsNodeItem, IconType
|
|
|
from sketchUI import mvops
|
|
@@ -180,7 +180,7 @@ class SketchScene(QGraphicsScene):
|
|
|
elif isinstance(item, GraphicsNodeItem):
|
|
|
self._handle_keypress_type_on_node(item)
|
|
|
else:
|
|
|
- print("Cannot type element {}".format(item))
|
|
|
+ self._parent.plainTextEdit.appendPlainText("Error: Cannot type element {}".format(item))
|
|
|
|
|
|
else:
|
|
|
QGraphicsScene.keyPressEvent(self, event)
|
|
@@ -193,20 +193,21 @@ class SketchScene(QGraphicsScene):
|
|
|
"""
|
|
|
old_type = item.get_type()
|
|
|
node_type, ok = QInputDialog.getText(self._parent, "Retype node", "New type", text=item.get_type())
|
|
|
- if not ok:
|
|
|
- # user canceled
|
|
|
+ if not ok or not node_type:
|
|
|
+ # user canceled or node type empty
|
|
|
+ return
|
|
|
+
|
|
|
+ if node_type in mvops.get_available_types():
|
|
|
+ self._parent.plainTextEdit.appendPlainText("Error: Already such a type: {}".format(node_type))
|
|
|
return
|
|
|
- if node_type:
|
|
|
- print("Reyping item {} to type {}".format(item, node_type))
|
|
|
- if node_type in mvops.get_available_types():
|
|
|
- print("Error: Already such a type: {}".format(node_type))
|
|
|
- return
|
|
|
|
|
|
# local or global retype?
|
|
|
scope, ok = QInputDialog.getItem(self._parent, "Select scope", "Scope", ["Local", "Global"])
|
|
|
if not ok:
|
|
|
return
|
|
|
|
|
|
+ self._parent.plainTextEdit.appendPlainText("Performing retype of node {}".format(node_type))
|
|
|
+ QApplication.setOverrideCursor(Qt.WaitCursor)
|
|
|
retype_handler = NodeRetype()
|
|
|
if scope == "Global":
|
|
|
retype_handler.execute(self._cur_model, item.node_id, node_type, local=False)
|
|
@@ -214,14 +215,18 @@ class SketchScene(QGraphicsScene):
|
|
|
retype_handler.execute(self._cur_model, item.node_id, node_type, local=True)
|
|
|
|
|
|
# rename on screen
|
|
|
- for node_item in self.items():
|
|
|
- if not isinstance(node_item, GraphicsNodeItem):
|
|
|
- continue
|
|
|
- if node_item.get_type() == old_type:
|
|
|
- node_item.set_type(node_type)
|
|
|
+ if scope == "Global":
|
|
|
+ for node_item in self.items():
|
|
|
+ if not isinstance(node_item, GraphicsNodeItem):
|
|
|
+ continue
|
|
|
+ if node_item.get_type() == old_type:
|
|
|
+ node_item.set_type(node_type)
|
|
|
+ else:
|
|
|
+ item.set_type(node_type)
|
|
|
|
|
|
# update list widget
|
|
|
self._parent.populate_types()
|
|
|
+ QApplication.restoreOverrideCursor()
|
|
|
|
|
|
def _handle_keypress_type_on_group(self, group):
|
|
|
# type: (QGraphicsItemGroup) -> None
|
|
@@ -231,20 +236,21 @@ class SketchScene(QGraphicsScene):
|
|
|
"""
|
|
|
# get the type from the user
|
|
|
node_type, ok = QInputDialog.getText(self._parent, "Type node", "Enter type")
|
|
|
- if not ok:
|
|
|
- # user canceled
|
|
|
+ if not ok or not node_type:
|
|
|
+ # user canceled or empty type string
|
|
|
+ return
|
|
|
+
|
|
|
+ if node_type in mvops.get_available_types():
|
|
|
+ self._parent.plainTextEdit.appendPlainText("Error: Already such a type: {}".format(node_type))
|
|
|
return
|
|
|
- if node_type:
|
|
|
- print("Typing item {} to type {}".format(group, node_type))
|
|
|
- if node_type in mvops.get_available_types():
|
|
|
- print("Error: Already such a type: {}".format(node_type))
|
|
|
- return
|
|
|
|
|
|
# perform add local or global?
|
|
|
scope, ok = QInputDialog.getItem(self._parent, "Select scope", "Scope", ["Local", "Global"])
|
|
|
if not ok:
|
|
|
return
|
|
|
|
|
|
+ self._parent.plainTextEdit.appendPlainText("Typing group to type {}".format(node_type))
|
|
|
+ QApplication.setOverrideCursor(Qt.WaitCursor)
|
|
|
# add the node to the model
|
|
|
add_handler = NodeAdd()
|
|
|
if scope == "Global":
|
|
@@ -254,10 +260,11 @@ class SketchScene(QGraphicsScene):
|
|
|
# Get node id of newly added node in current model
|
|
|
nodeid = all_nodes_with_type(self._cur_model, node_type)[0]
|
|
|
|
|
|
+ self._parent.plainTextEdit.appendPlainText("Capturing concrete syntax of group ...")
|
|
|
# create concrete syntax model for the sketched elements
|
|
|
csm = mvops.new_concrete_syntax(node_type, IconType.PRIMITIVE)
|
|
|
if not csm:
|
|
|
- # CS for such a type already exists
|
|
|
+ self._parent.plainTextEdit.appendPlainText("Error: Concrete syntax for type {} already exists".format(node_type))
|
|
|
return
|
|
|
|
|
|
# TODO: populate CSM with sketched elements
|
|
@@ -275,16 +282,20 @@ class SketchScene(QGraphicsScene):
|
|
|
self.removeItem(group)
|
|
|
self.addItem(nodeitem)
|
|
|
self._parent.populate_types()
|
|
|
+ QApplication.restoreOverrideCursor()
|
|
|
+ self._parent.plainTextEdit.appendPlainText("OK")
|
|
|
|
|
|
def _handle_keypress_delete(self, selected):
|
|
|
del_hander = NodeDelete()
|
|
|
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)
|
|
@@ -293,6 +304,7 @@ class SketchScene(QGraphicsScene):
|
|
|
del_hander.execute(self._cur_model, item.node_id, local=True, check_if_last=True)
|
|
|
|
|
|
# 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
|
|
|
for edge in self.items():
|
|
|
if not isinstance(edge, GraphicsEdgeItem):
|
|
|
continue
|
|
@@ -309,3 +321,5 @@ class SketchScene(QGraphicsScene):
|
|
|
# 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()
|