Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/gaphas
diff options
context:
space:
mode:
authorgaphor@gmail.com <gaphor@gmail.com@a8418922-720d-0410-834f-a69b97ada669>2009-01-04 20:19:00 (GMT)
committer gaphor@gmail.com <gaphor@gmail.com@a8418922-720d-0410-834f-a69b97ada669>2009-01-04 20:19:00 (GMT)
commita5b06444c0abbcfdde12fc8a4e3b95aadc523ea7 (patch)
tree52babdf61f9c81ad87d19aa2214b749bede310b0 /gaphas
parent7140f70d5680aa9de962d86d84aab4a893702372 (diff)
moved Canvas._normalize() meat to Item.normalize()
git-svn-id: http://svn.devjavu.com/gaphor/gaphas/trunk@2563 a8418922-720d-0410-834f-a69b97ada669
Diffstat (limited to 'gaphas')
-rw-r--r--gaphas/canvas.py21
-rw-r--r--gaphas/item.py35
2 files changed, 42 insertions, 14 deletions
diff --git a/gaphas/canvas.py b/gaphas/canvas.py
index b656748..8ba2be5 100644
--- a/gaphas/canvas.py
+++ b/gaphas/canvas.py
@@ -544,6 +544,11 @@ class Canvas(object):
for h in item.handles():
request_resolve(h.x, projections_only=True)
request_resolve(h.y, projections_only=True)
+ # TODO: force updates for ports. Keep in mind the types:
+ # PointPort and LinePort
+ #for p in item.ports():
+ # request_resolve(p.x, projections_only=True)
+ # request_resolve(p.y, projections_only=True)
# solve all constraints
self._solver.solve()
@@ -583,21 +588,9 @@ class Canvas(object):
"""
dirty_matrix_items = set()
for item in items:
- handles = item.handles()
- if not handles:
- continue
- x, y = map(float, handles[0].pos)
- if x:
- item.matrix._matrix.translate(x, 0)
- dirty_matrix_items.add(item)
- for h in handles:
- h.x._value -= x
- if y:
- item.matrix._matrix.translate(0, y)
+ if item.normalize():
dirty_matrix_items.add(item)
- for h in handles:
- h.y._value -= y
-
+
return dirty_matrix_items
diff --git a/gaphas/item.py b/gaphas/item.py
index 85a5070..9cb84e9 100644
--- a/gaphas/item.py
+++ b/gaphas/item.py
@@ -143,6 +143,41 @@ class Item(object):
"""
pass
+
+ def normalize(self):
+ """
+ Update handle positions of the item, so the first handle is always
+ located at (0, 0).
+
+ Note that, since this method basically does some housekeeping during
+ the update phase, there's no need to keep track of the changes.
+
+ Alternative implementation can also be created, e.g. set (0, 0) in
+ the center of a circle or change it depending on the location of a
+ rotation poiny.
+
+ Returns ``True`` if some updates have been done, ``False`` otherwise.
+
+ TODO: Add a decorator that prevents the matrix and handle position to
+ be observed.
+ """
+ updated = False
+ handles = self._handles
+ if handles:
+ x, y = map(float, handles[0].pos)
+ if x:
+ self.matrix._matrix.translate(x, 0)
+ updated = True
+ for h in handles:
+ h.x._value -= x
+ if y:
+ self.matrix._matrix.translate(0, y)
+ updated = True
+ for h in handles:
+ h.y._value -= y
+ return updated
+
+
def draw(self, context):
"""
Render the item to a canvas view.