commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/09: grc: snap-to-grid (WIP)


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/09: grc: snap-to-grid (WIP)
Date: Wed, 20 Aug 2014 20:18:46 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 0dd158155c074113ec1cc6a3de7ecdd2be7d65e8
Author: Sebastian Koslowski <address@hidden>
Date:   Tue Aug 19 17:02:33 2014 +0200

    grc: snap-to-grid (WIP)
---
 grc/gui/Block.py     |  8 ++++++--
 grc/gui/Constants.py |  5 ++++-
 grc/gui/FlowGraph.py | 11 +++++++----
 grc/gui/Port.py      | 10 +++++-----
 grc/gui/Utils.py     | 10 +++++++++-
 5 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 0afb351..589ed34 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -43,6 +43,8 @@ class Block(Element):
         Block contructor.
         Add graphics related params to the block.
         """
+        self.W = 0
+        self.H = 0
         #add the position param
         self.get_params().append(self.get_parent().get_parent().Param(
             block=self,
@@ -85,6 +87,9 @@ class Block(Element):
                 y = 0
             elif y >= fgH - BORDER_PROXIMITY_SENSITIVITY:
                 y = fgH - BORDER_PROXIMITY_SENSITIVITY
+            offset_x, offset_y = (0, self.H/2) if self.is_horizontal() else 
(self.H/2, 0)
+            x = Utils.align_to_grid(x + offset_x) - offset_x
+            y = Utils.align_to_grid(y + offset_y) - offset_y
             return (x, y)
         except:
             self.set_coordinate((0, 0))
@@ -179,8 +184,7 @@ class Block(Element):
                 self.label_height + 2 * BLOCK_LABEL_PADDING
             ] +
             [  # ports
-                2 * PORT_BORDER_SEPARATION +
-                sum([port.H + PORT_SEPARATION for port in ports if not 
port.get_hide()]) - PORT_SEPARATION
+                PORT_SEPARATION * len(filter(lambda p: not p.get_hide(), 
ports))
                 for ports in (self.get_sources_gui(), self.get_sinks_gui())
             ] +
             [  # bus ports only
diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py
index 7fabcfc..c82449b 100644
--- a/grc/gui/Constants.py
+++ b/grc/gui/Constants.py
@@ -53,7 +53,7 @@ BLOCK_LABEL_PADDING = 7
 PORT_LABEL_PADDING = 2
 
 #port constraint dimensions
-PORT_SEPARATION = 17
+PORT_SEPARATION = 32
 PORT_BORDER_SEPARATION = 9
 PORT_MIN_WIDTH = 20
 
@@ -81,3 +81,6 @@ SCROLL_DISTANCE = 15
 
 #How close the mouse click can be to a line and register a connection select.
 LINE_SELECT_SENSITIVITY = 5
+
+# canvas grid size
+CANVAS_GRID_SIZE = 8
\ No newline at end of file
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index bfe8fbf..4d2b1b6 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -574,7 +574,7 @@ class FlowGraph(Element):
                 self.create_shapes()
                 self.queue_draw()
         else:
-            #perform autoscrolling
+            #perform auto-scrolling
             width, height = self.get_size()
             x, y = coordinate
             h_adj = self.get_scroll_pane().get_hadjustment()
@@ -594,8 +594,11 @@ class FlowGraph(Element):
             if len(self.get_selected_elements()) == 1 and 
self.get_selected_element().is_connection():
                 Actions.ELEMENT_DELETE()
             #move the selected elements and record the new coordinate
-            X, Y = self.get_coordinate()
-            if not self.get_ctrl_mask(): self.move_selected((int(x - X), int(y 
- Y)))
-            self.set_coordinate((x, y))
+            if not self.get_ctrl_mask():
+                X, Y = self.get_coordinate()
+                dX, dY = int(x - X), int(y - Y)
+                if abs(dX) >= Utils.CANVAS_GRID_SIZE or abs(dY) >= 
Utils.CANVAS_GRID_SIZE:
+                    self.move_selected((dX, dY))
+                    self.set_coordinate((x, y))
             #queue draw for animation
             self.queue_draw()
diff --git a/grc/gui/Port.py b/grc/gui/Port.py
index b81b162..c56432d 100644
--- a/grc/gui/Port.py
+++ b/grc/gui/Port.py
@@ -70,26 +70,26 @@ class Port(Element):
         length = len(filter(lambda p: not p.get_hide(), ports))
         #reverse the order of ports for these rotations
         if rotation in (180, 270): index = length-index-1
-        offset = (self.get_parent().H - length*self.H - 
(length-1)*PORT_SEPARATION)/2
+        offset = (self.get_parent().H - (length-1)*PORT_SEPARATION - self.H)/2
         #create areas and connector coordinates
         if (self.is_sink() and rotation == 0) or (self.is_source() and 
rotation == 180):
             x = -1*W
-            y = (PORT_SEPARATION+self.H)*index+offset
+            y = PORT_SEPARATION*index+offset
             self.add_area((x, y), (W, self.H))
             self._connector_coordinate = (x-1, y+self.H/2)
         elif (self.is_source() and rotation == 0) or (self.is_sink() and 
rotation == 180):
             x = self.get_parent().W
-            y = (PORT_SEPARATION+self.H)*index+offset
+            y = PORT_SEPARATION*index+offset
             self.add_area((x, y), (W, self.H))
             self._connector_coordinate = (x+1+W, y+self.H/2)
         elif (self.is_source() and rotation == 90) or (self.is_sink() and 
rotation == 270):
             y = -1*W
-            x = (PORT_SEPARATION+self.H)*index+offset
+            x = PORT_SEPARATION*index+offset
             self.add_area((x, y), (self.H, W))
             self._connector_coordinate = (x+self.H/2, y-1)
         elif (self.is_sink() and rotation == 90) or (self.is_source() and 
rotation == 270):
             y = self.get_parent().W
-            x = (PORT_SEPARATION+self.H)*index+offset
+            x = PORT_SEPARATION*index+offset
             self.add_area((x, y), (self.H, W))
             self._connector_coordinate = (x+self.H/2, y+1+W)
         #the connector length
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index ebd5aef..9a0a59c 100644
--- a/grc/gui/Utils.py
+++ b/grc/gui/Utils.py
@@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
-from Constants import POSSIBLE_ROTATIONS
+from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE
 from Cheetah.Template import Template
 import pygtk
 pygtk.require('2.0')
@@ -108,3 +108,11 @@ def parse_template(tmpl_str, **kwargs):
     #   print tmpl_str
     #   print str(kwargs['param'].get_error_messages())
     return str(Template(tmpl_str, kwargs))
+
+def align_to_grid(coor):
+    _align = lambda: int(round(x / (1.0 * CANVAS_GRID_SIZE)) * 
CANVAS_GRID_SIZE)
+    try:
+        return [_align() for x in coor]
+    except TypeError:
+        x = coor
+        return _align()
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]