From 0dd158155c074113ec1cc6a3de7ecdd2be7d65e8 Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Tue, 19 Aug 2014 17:02:33 +0200
Subject: grc: snap-to-grid (WIP)

---
 grc/gui/Utils.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

(limited to 'grc/gui/Utils.py')

diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index ebd5aefca7..9a0a59cda7 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
-- 
cgit v1.2.3