|
@@ -1,9 +1,11 @@
|
|
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, QGraphicsItemGroup, QTableWidgetItem
|
|
|
|
|
|
+ QGraphicsEllipseItem, QInputDialog, QTableWidgetItem
|
|
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
|
|
|
|
+from sketchUI.graphics_sketch_group import SketchGroup
|
|
|
|
+from sketchUI.graphics_sketch_line import SketchedLineItem
|
|
from sketchUI import mvops
|
|
from sketchUI import mvops
|
|
from evolution.node_ops import NodeAdd, NodeDelete, NodeRetype
|
|
from evolution.node_ops import NodeAdd, NodeDelete, NodeRetype
|
|
import commons
|
|
import commons
|
|
@@ -115,7 +117,7 @@ class SketchScene(QGraphicsScene):
|
|
end_point = event.scenePos()
|
|
end_point = event.scenePos()
|
|
|
|
|
|
if self._mode == Mode.LINE:
|
|
if self._mode == Mode.LINE:
|
|
- line = QGraphicsLineItem(self._orig_point.x(), self._orig_point.y(),
|
|
|
|
|
|
+ line = SketchedLineItem(self._orig_point.x(), self._orig_point.y(),
|
|
end_point.x(), end_point.y())
|
|
end_point.x(), end_point.y())
|
|
line.setPen(QPen(Qt.black, 2, Qt.SolidLine))
|
|
line.setPen(QPen(Qt.black, 2, Qt.SolidLine))
|
|
self.addItem(line)
|
|
self.addItem(line)
|
|
@@ -186,11 +188,15 @@ class SketchScene(QGraphicsScene):
|
|
selected = self.selectedItems()
|
|
selected = self.selectedItems()
|
|
self.clearSelection()
|
|
self.clearSelection()
|
|
|
|
|
|
- group = self.createItemGroup(selected)
|
|
|
|
|
|
+ group = SketchGroup()
|
|
|
|
+ for item in selected:
|
|
|
|
+ group.addToGroup(item)
|
|
|
|
+
|
|
bb_rect = QGraphicsRectItem(group.boundingRect())
|
|
bb_rect = QGraphicsRectItem(group.boundingRect())
|
|
bb_rect.setData(0, "groupBBox") # identifier for "does not belong to the actual sketch"
|
|
bb_rect.setData(0, "groupBBox") # identifier for "does not belong to the actual sketch"
|
|
bb_rect.setPen(QPen(Qt.gray, 1, Qt.DashLine))
|
|
bb_rect.setPen(QPen(Qt.gray, 1, Qt.DashLine))
|
|
group.addToGroup(bb_rect)
|
|
group.addToGroup(bb_rect)
|
|
|
|
+ self.addItem(group)
|
|
group.setFlag(QGraphicsItem.ItemIsSelectable, True)
|
|
group.setFlag(QGraphicsItem.ItemIsSelectable, True)
|
|
group.setFlag(QGraphicsItem.ItemIsMovable, True)
|
|
group.setFlag(QGraphicsItem.ItemIsMovable, True)
|
|
|
|
|
|
@@ -201,7 +207,7 @@ class SketchScene(QGraphicsScene):
|
|
if len(selected) != 1:
|
|
if len(selected) != 1:
|
|
return
|
|
return
|
|
item = selected[0]
|
|
item = selected[0]
|
|
- if isinstance(item, QGraphicsItemGroup):
|
|
|
|
|
|
+ if isinstance(item, SketchGroup):
|
|
self._handle_keypress_type_on_group(item)
|
|
self._handle_keypress_type_on_group(item)
|
|
elif isinstance(item, GraphicsNodeItem):
|
|
elif isinstance(item, GraphicsNodeItem):
|
|
self._handle_keypress_type_on_node(item)
|
|
self._handle_keypress_type_on_node(item)
|
|
@@ -257,7 +263,7 @@ class SketchScene(QGraphicsScene):
|
|
QApplication.restoreOverrideCursor()
|
|
QApplication.restoreOverrideCursor()
|
|
|
|
|
|
def _handle_keypress_type_on_group(self, group):
|
|
def _handle_keypress_type_on_group(self, group):
|
|
- # type: (QGraphicsItemGroup) -> None
|
|
|
|
|
|
+ # type: (SketchGroup) -> None
|
|
"""
|
|
"""
|
|
type the selected group = make a real node out of it and store it in the model
|
|
type the selected group = make a real node out of it and store it in the model
|
|
also capture its concrete syntax and store it in the modelverse
|
|
also capture its concrete syntax and store it in the modelverse
|
|
@@ -289,6 +295,7 @@ class SketchScene(QGraphicsScene):
|
|
nodeid = commons.all_nodes_with_type(self._cur_model, node_type)[0]
|
|
nodeid = commons.all_nodes_with_type(self._cur_model, node_type)[0]
|
|
|
|
|
|
self._parent.plainTextEdit.appendPlainText("Capturing concrete syntax of group ...")
|
|
self._parent.plainTextEdit.appendPlainText("Capturing concrete syntax of group ...")
|
|
|
|
+ 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)
|
|
if not csm:
|
|
if not csm:
|
|
@@ -300,8 +307,19 @@ class SketchScene(QGraphicsScene):
|
|
if item.data(0) == "groupBBox":
|
|
if item.data(0) == "groupBBox":
|
|
# just the bounding box from the group, ignore
|
|
# just the bounding box from the group, ignore
|
|
continue
|
|
continue
|
|
|
|
+ if isinstance(item, QGraphicsRectItem):
|
|
|
|
+ rect = group.get_item_coord_relative(item)
|
|
|
|
+ mvops.add_rect_to_cs(csm, rect)
|
|
|
|
+ elif isinstance(item, QGraphicsEllipseItem):
|
|
|
|
+ rect = group.get_item_coord_relative(item)
|
|
|
|
+ mvops.add_ellipse_to_cs(csm, rect)
|
|
|
|
+ elif isinstance(item, SketchedLineItem):
|
|
|
|
+ p1, p2 = group.get_item_coord_relative(item)
|
|
|
|
+ mvops.add_line_to_cs(csm, p1, p2)
|
|
|
|
+ else:
|
|
|
|
+ print("Dont know how to capture CS of item {}".format(item))
|
|
|
|
|
|
- # update view
|
|
|
|
|
|
+ # update view: replace group by actual node item with newly populated CS
|
|
csm_content = mvops.get_consyn_of(node_type)
|
|
csm_content = mvops.get_consyn_of(node_type)
|
|
nodeitem = GraphicsNodeItem(nodeid, node_type, csm_content)
|
|
nodeitem = GraphicsNodeItem(nodeid, node_type, csm_content)
|
|
nodeitem.setPos(group.scenePos())
|
|
nodeitem.setPos(group.scenePos())
|