|
@@ -302,19 +302,44 @@ class SketchScene(QGraphicsScene):
|
|
|
self._parent.plainTextEdit.appendPlainText("Error: Concrete syntax for type {} already exists".format(node_type))
|
|
|
return
|
|
|
|
|
|
- # TODO: populate CSM with sketched elements
|
|
|
+ # check if we need to scale the group items down first to 100x100
|
|
|
+ group_brect = group.boundingRect()
|
|
|
+ need_scale = False
|
|
|
+ scale_factor = 1.0
|
|
|
+ if group_brect.width() > 100 or group_brect.height() > 100:
|
|
|
+ need_scale = True
|
|
|
+ scale_factor = 100.0 / max(group_brect.width(), group_brect.height())
|
|
|
+
|
|
|
+ # populate CSM with sketched elements
|
|
|
for item in group.childItems():
|
|
|
if item.data(0) == "groupBBox":
|
|
|
# just the bounding box from the group, ignore
|
|
|
continue
|
|
|
if isinstance(item, QGraphicsRectItem):
|
|
|
rect = group.get_item_coord_relative(item)
|
|
|
+ if need_scale:
|
|
|
+ new_top_left = rect.topLeft() * scale_factor
|
|
|
+ new_width = rect.width() * scale_factor
|
|
|
+ new_height = rect.height() * scale_factor
|
|
|
+ rect.setTopLeft(new_top_left)
|
|
|
+ rect.setWidth(new_width)
|
|
|
+ rect.setHeight(new_height)
|
|
|
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)
|
|
|
+ if need_scale:
|
|
|
+ new_top_left = rect.topLeft() * scale_factor
|
|
|
+ new_width = rect.width() * scale_factor
|
|
|
+ new_height = rect.height() * scale_factor
|
|
|
+ rect.setTopLeft(new_top_left)
|
|
|
+ rect.setWidth(new_width)
|
|
|
+ rect.setHeight(new_height)
|
|
|
+ mvops.add_rect_to_cs(csm, rect)
|
|
|
elif isinstance(item, SketchedLineItem):
|
|
|
p1, p2 = group.get_item_coord_relative(item)
|
|
|
+ if need_scale:
|
|
|
+ p1 *= scale_factor
|
|
|
+ p2 *= scale_factor
|
|
|
mvops.add_line_to_cs(csm, p1, p2)
|
|
|
else:
|
|
|
print("Dont know how to capture CS of item {}".format(item))
|
|
@@ -353,9 +378,14 @@ class SketchScene(QGraphicsScene):
|
|
|
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
|