瀏覽代碼

also delete concrete syntax model when deleting node globally

Lucas Heer 7 年之前
父節點
當前提交
7546bdf7cd
共有 4 個文件被更改,包括 48 次插入3 次删除
  1. 5 0
      evolution/node_ops.py
  2. 32 2
      sketchUI/exm_scene.py
  3. 10 0
      sketchUI/mvops.py
  4. 1 1
      wrappers/modelverse_SCCD.py

+ 5 - 0
evolution/node_ops.py

@@ -31,6 +31,7 @@ class NodeDelete(object):
     def __init__(self):
         self._node = ""
         self._node_type = ""
+        self._was_last = False
 
     def execute(self, model, node, local, check_if_last=False):
         self._node = node
@@ -47,6 +48,7 @@ class NodeDelete(object):
                     remaining_instances += len(all_nodes_with_type(m, self._node_type))
                 if remaining_instances == 0:
                     # it was indeed the last one, delete from instance models
+                    self._was_last = True
                     for m in all_instance_models():
                         nodes_to_delete = all_nodes_with_type(m, self._node_type)
                         for node in nodes_to_delete:
@@ -57,6 +59,9 @@ class NodeDelete(object):
                 for node in nodes_to_delete:
                     self.execute(m, node, local=True)
 
+    def was_last(self):
+        return self._was_last
+
     def _callback(self, model):
         mv.delete_element(model, "gm/"+self._node)
 

+ 32 - 2
sketchUI/exm_scene.py

@@ -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

+ 10 - 0
sketchUI/mvops.py

@@ -60,6 +60,16 @@ def new_concrete_syntax_model(type_id, icon_type):
 
     return csm
 
+def del_concrete_syntax_model(type_id):
+    """
+    Delete a concrete syntax model. Returns True if success, False otherwise.
+    """
+    csm = "models/consyn/" + type_id
+    if csm not in commons.all_consyn_models():
+        return False
+    mv.model_delete(csm)
+    return True
+
 def add_rect_to_cs(csm, rect):
     # type: (str, QRect) -> None
     rect_id = mv.instantiate(csm, "Rectangle")

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Fri Apr 27 20:13:57 2018
+Date:   Fri Apr 27 21:17:57 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server