Prechádzať zdrojové kódy

disable freehand sketching, always scale captured primitives

Lucas Heer 7 rokov pred
rodič
commit
718c6d620f
2 zmenil súbory, kde vykonal 18 pridanie a 23 odobranie
  1. 1 1
      sketchUI/exm_mainwindow.py
  2. 17 22
      sketchUI/exm_scene.py

+ 1 - 1
sketchUI/exm_mainwindow.py

@@ -90,7 +90,7 @@ class EXMMainWindow(QMainWindow, Ui_MainWindow):
         action_group.addAction(self.line_action)
         action_group.addAction(self.rect_action)
         action_group.addAction(self.circle_action)
-        action_group.addAction(self.pen_action)
+        #action_group.addAction(self.pen_action)
 
         for item in action_group.actions():
             self.toolBar.addAction(item)

+ 17 - 22
sketchUI/exm_scene.py

@@ -333,13 +333,11 @@ class SketchScene(QGraphicsScene):
             self._parent.plainTextEdit.appendPlainText("Error: Concrete syntax for type {} already exists".format(node_type))
             return
 
-        # check if we need to scale the group items down to 100x100 first
+        # scale group to fit 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())
+        scale_factor = 100.0 / max(group_brect.width(), group_brect.height())
+        print("Scaling group by {}".format(scale_factor))
 
         #  populate CSM with sketched elements
         for item in group.childItems():
@@ -348,29 +346,26 @@ class SketchScene(QGraphicsScene):
                 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)
+                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)
-                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)
+                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_ellipse_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
+                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))