diff --git a/src/c3nav/routing/graph/graph.py b/src/c3nav/routing/graph/graph.py index 35ded802..ba503e3f 100644 --- a/src/c3nav/routing/graph/graph.py +++ b/src/c3nav/routing/graph/graph.py @@ -8,20 +8,21 @@ from c3nav.routing.graph.level import GraphLevel class Graph(): def __init__(self): self.levels = {} + for level in Level.objects.all(): + self.levels[level.name] = GraphLevel(self, level) + self.connections = [] self.levelconnector_points = {} def build(self): - for level in Level.objects.all(): - self.levels[level.name] = GraphLevel(self, level) - for level in self.levels.values(): level.build() self.connect_levelconnectors() + def draw_pngs(self, points=True, lines=True): for level in self.levels.values(): - level.draw_png() + level.draw_png(points=points, lines=lines) def add_levelconnector_point(self, levelconnector, point): self.levelconnector_points.setdefault(levelconnector.name, []).append(point) diff --git a/src/c3nav/routing/graph/level.py b/src/c3nav/routing/graph/level.py index 8e73bab1..38b1309b 100644 --- a/src/c3nav/routing/graph/level.py +++ b/src/c3nav/routing/graph/level.py @@ -74,7 +74,7 @@ class GraphLevel(): for room in self.rooms: room.connect_points() - def draw_png(self): + def draw_png(self, points=True, lines=True): filename = os.path.join(settings.RENDER_ROOT, 'level-%s.base.png' % self.level.name) graph_filename = os.path.join(settings.RENDER_ROOT, 'level-%s.graph.png' % self.level.name) @@ -83,14 +83,17 @@ class GraphLevel(): draw = ImageDraw.Draw(im) i = 0 for room in self.rooms: - for point in room.points: - for otherpoint, connection in point.connections.items(): - draw.line(_line_coords(point, otherpoint, height), fill=(255, 100, 100)) + if lines: + for point in room.points: + for otherpoint, connection in point.connections.items(): + draw.line(_line_coords(point, otherpoint, height), fill=(255, 100, 100)) - for point in room.points: - i += 1 - draw.ellipse(_ellipse_bbox(point.x, point.y, height), (200, 0, 0)) + if points: + for point in room.points: + i += 1 + draw.ellipse(_ellipse_bbox(point.x, point.y, height), (200, 0, 0)) - print(i, 'points') + if points: + print('level %s: %d points' % (self.level.name, i)) im.save(graph_filename) diff --git a/src/c3nav/routing/management/commands/buildgraph.py b/src/c3nav/routing/management/commands/buildgraph.py index d49b822b..2637e978 100644 --- a/src/c3nav/routing/management/commands/buildgraph.py +++ b/src/c3nav/routing/management/commands/buildgraph.py @@ -6,6 +6,18 @@ from c3nav.routing.graph import Graph class Command(BaseCommand): help = 'build the routing graph' + def add_arguments(self, parser): + parser.add_argument('--draw-graph', action='store_const', const=True, default=False, + help='render a graph image') + + parser.add_argument('--dont-draw-graph-points', action='store_const', const=True, default=False, + help='dont draw points on the graph image') + + parser.add_argument('--dont-draw-graph-lines', action='store_const', const=True, default=False, + help='dont draw lines on the graph image') + def handle(self, *args, **options): - graphbuilder = Graph() - graphbuilder.build() + graph = Graph() + graph.build() + if options['draw_graph']: + graph.draw_pngs(points=not options['dont_draw_graph_points'], lines=not options['dont_draw_graph_lines'])