|
@@ -1,6 +1,6 @@
|
|
from enum import Enum
|
|
from enum import Enum
|
|
from PyQt5.QtWidgets import QGraphicsScene, QGraphicsItem, QGraphicsLineItem, QGraphicsRectItem, \
|
|
from PyQt5.QtWidgets import QGraphicsScene, QGraphicsItem, QGraphicsLineItem, QGraphicsRectItem, \
|
|
- QGraphicsEllipseItem, QInputDialog, QTableWidgetItem
|
|
|
|
|
|
+ QGraphicsEllipseItem, QInputDialog, QTableWidgetItem, QMessageBox
|
|
from PyQt5.Qt import Qt, QPointF, QPen, QTransform, QApplication
|
|
from PyQt5.Qt import Qt, QPointF, QPen, QTransform, QApplication
|
|
from sketchUI.graphics_edge_item import GraphicsEdgeItem
|
|
from sketchUI.graphics_edge_item import GraphicsEdgeItem
|
|
from sketchUI.graphics_node_item import GraphicsNodeItem, IconType
|
|
from sketchUI.graphics_node_item import GraphicsNodeItem, IconType
|
|
@@ -283,9 +283,20 @@ class SketchScene(QGraphicsScene):
|
|
# user canceled or empty type string
|
|
# user canceled or empty type string
|
|
return
|
|
return
|
|
|
|
|
|
|
|
+ reload = False
|
|
if node_type in commons.get_available_types():
|
|
if node_type in commons.get_available_types():
|
|
- self._parent.plainTextEdit.appendPlainText("Error: Already such a type: {}".format(node_type))
|
|
|
|
- return
|
|
|
|
|
|
+ # There is already such a type registered. Overwrite its conrete syntax?
|
|
|
|
+ box = QMessageBox()
|
|
|
|
+ box.setText("Type {} already exists".format(node_type))
|
|
|
|
+ box.setInformativeText("Do you want to overwrite it?")
|
|
|
|
+ box.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
|
|
|
|
+ box.setDefaultButton(QMessageBox.No)
|
|
|
|
+ ret = box.exec_()
|
|
|
|
+ if ret == QMessageBox.Yes:
|
|
|
|
+ reload = True
|
|
|
|
+ pass
|
|
|
|
+ else:
|
|
|
|
+ return
|
|
|
|
|
|
# perform add local or global?
|
|
# perform add local or global?
|
|
scope, ok = QInputDialog.getItem(self._parent, "Select scope", "Scope", ["Local", "Global"])
|
|
scope, ok = QInputDialog.getItem(self._parent, "Select scope", "Scope", ["Local", "Global"])
|
|
@@ -306,7 +317,7 @@ class SketchScene(QGraphicsScene):
|
|
self._parent.plainTextEdit.appendPlainText("Capturing concrete syntax of group ...")
|
|
self._parent.plainTextEdit.appendPlainText("Capturing concrete syntax of group ...")
|
|
self._parent.plainTextEdit.repaint()
|
|
self._parent.plainTextEdit.repaint()
|
|
# create concrete syntax model for the sketched elements
|
|
# create concrete syntax model for the sketched elements
|
|
- csm = mvops.new_concrete_syntax_model(node_type, IconType.PRIMITIVE)
|
|
|
|
|
|
+ csm = mvops.new_concrete_syntax_model(node_type, IconType.PRIMITIVE, overwrite=True)
|
|
if not csm:
|
|
if not csm:
|
|
self._parent.plainTextEdit.appendPlainText("Error: Concrete syntax for type {} already exists".format(node_type))
|
|
self._parent.plainTextEdit.appendPlainText("Error: Concrete syntax for type {} already exists".format(node_type))
|
|
return
|
|
return
|
|
@@ -353,17 +364,22 @@ class SketchScene(QGraphicsScene):
|
|
else:
|
|
else:
|
|
print("Dont know how to capture CS of item {}".format(item))
|
|
print("Dont know how to capture CS of item {}".format(item))
|
|
|
|
|
|
- # update view: replace group by actual node item with newly populated CS
|
|
|
|
- csm_content = mvops.get_consyn_of(node_type)
|
|
|
|
- nodeitem = GraphicsNodeItem(nodeid, node_type, csm_content)
|
|
|
|
- nodeitem.setPos(group.scenePos())
|
|
|
|
- nodeitem.setFlag(QGraphicsItem.ItemIsSelectable, True)
|
|
|
|
- nodeitem.setFlag(QGraphicsItem.ItemIsMovable, True)
|
|
|
|
- self.removeItem(group)
|
|
|
|
- self.addItem(nodeitem)
|
|
|
|
- self._parent.populate_types()
|
|
|
|
- QApplication.restoreOverrideCursor()
|
|
|
|
- self._parent.plainTextEdit.appendPlainText("OK")
|
|
|
|
|
|
+ if reload:
|
|
|
|
+ # reload whole scene because concrete syntax of a type has changed
|
|
|
|
+ self._parent._load_model()
|
|
|
|
+ QApplication.restoreOverrideCursor()
|
|
|
|
+ else:
|
|
|
|
+ # update view: replace group by actual node item with newly populated CS
|
|
|
|
+ csm_content = mvops.get_consyn_of(node_type)
|
|
|
|
+ nodeitem = GraphicsNodeItem(nodeid, node_type, csm_content)
|
|
|
|
+ nodeitem.setPos(group.scenePos())
|
|
|
|
+ nodeitem.setFlag(QGraphicsItem.ItemIsSelectable, True)
|
|
|
|
+ nodeitem.setFlag(QGraphicsItem.ItemIsMovable, True)
|
|
|
|
+ self.removeItem(group)
|
|
|
|
+ self.addItem(nodeitem)
|
|
|
|
+ self._parent.populate_types()
|
|
|
|
+ QApplication.restoreOverrideCursor()
|
|
|
|
+ self._parent.plainTextEdit.appendPlainText("OK")
|
|
|
|
|
|
def _handle_keypress_delete(self, selected):
|
|
def _handle_keypress_delete(self, selected):
|
|
if len(selected) == 1 and isinstance(selected[0], GraphicsEdgeItem):
|
|
if len(selected) == 1 and isinstance(selected[0], GraphicsEdgeItem):
|