Added virtual routes to template system to allow related islands
authorW. Trevor King <wking@drexel.edu>
Sun, 28 Mar 2010 00:13:28 +0000 (20:13 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 28 Mar 2010 00:13:28 +0000 (20:13 -0400)
pyrisk/graphics.py

index 4a758cb89c131df2ee6fc229bef76c83d6331221..6ca4aa22142f47732babe16ee80021c7c9364bc7 100644 (file)
@@ -39,7 +39,7 @@ class TemplateLibrary (object):
 
     TODO: explain template data format.
     """
-    def __init__(self, template_dir='/usr/share/pyrisk/templates/'):
+    def __init__(self, template_dir='share/templates/'):
         self.template_dir = os.path.abspath(os.path.expanduser(template_dir))
     def get(self, name):
         region_pointlists,route_pointlists = self._get_pointlists(name)
@@ -58,8 +58,9 @@ class TemplateLibrary (object):
             name,extension = filename.rsplit('.', 1)
             if extension == 'reg':
                 region_pointlists[name] = self._read_file(path)
-            elif extension == 'rt':
-                route_pointlists[name] = self._read_file(path)
+            elif extension in ['rt', 'vrt']:
+                route_pointlists[name] = (self._read_file(path),
+                                          extension == 'vrt')
         return (region_pointlists, route_pointlists)
     def _read_file(self, filename):
         pointlist = []
@@ -85,11 +86,13 @@ class TemplateLibrary (object):
                 all_boundaries, pointlist)
             regions.append(Region(name, boundaries, head_to_tail))
             r = regions[-1]
-        for name,pointlist in route_pointlists.items():
+        for name,v_pointlist in route_pointlists.items():
+            pointlist,virtual = v_pointlist
             boundaries,head_to_tail = self._pointlist_to_array_of_boundaries(
                 all_boundaries, pointlist)
             assert len(boundaries) == 1, boundaries
             route = boundaries[0]
+            route.virtual = virtual
             for terminal in [route[0], route[-1]]:
                 for r in regions:
                     for point in r.outline:
@@ -299,7 +302,7 @@ class Region (ID_CmpMixin, list):
             self.starts.append(pos)
             for p in new:
                 points.append(pos+p)
-        assert points[-1] == points[0], points
+        assert points[-1] == points[0], '%s: %s' % (self.name, points)
         self.outline = points
     def locate_routes(self):
         self.route_starts = []
@@ -359,7 +362,7 @@ class WorldRenderer (object):
                                 for p in r.outline[:-1]])
                     ])
             for rt,rt_start in zip(r.routes, r.route_starts):
-                if id(rt) in drawn_rts:
+                if id(rt) in drawn_rts or rt.virtual == True:
                     continue
                 drawn_rts[id(rt)] = rt
                 lines.extend([