From 4877a1fc2861abe6075c4b3cab7ab7adb09cbce1 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Thu, 6 Aug 2015 00:46:29 +0300 Subject: [PATCH] Process file; icons test drawing; new icons. --- icons.svg | 361 +++++++++++++++++++++++++++++++++++++++++++++++++---- mapper.py | 78 +----------- process.py | 69 ++++++++++ test.py | 62 +++++---- 4 files changed, 441 insertions(+), 129 deletions(-) create mode 100644 process.py diff --git a/icons.svg b/icons.svg index 1f81dc1..bd4cc27 100644 --- a/icons.svg +++ b/icons.svg @@ -13,7 +13,7 @@ height="600px" id="svg2987" version="1.1" - inkscape:version="0.48.5 r10040" + inkscape:version="0.48.3.1 r9886" sodipodi:docname="icons.svg"> @@ -24,9 +24,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="22.627417" - inkscape:cx="140.48624" - inkscape:cy="438.6732" + inkscape:zoom="8" + inkscape:cx="241.75393" + inkscape:cy="525.66607" inkscape:current-layer="layer1" inkscape:document-units="px" showgrid="true" @@ -34,10 +34,10 @@ inkscape:guide-bbox="true" inkscape:object-paths="true" inkscape:snap-bbox="true" - inkscape:window-width="1440" + inkscape:window-width="1045" inkscape:window-height="969" - inkscape:window-x="29" - inkscape:window-y="46" + inkscape:window-x="68" + inkscape:window-y="110" inkscape:window-maximized="0"> + inkscape:label="#d_traffic_signal" + style="fill:#d40000" /> + d="M 129.5 101 C 129.223 101 129 101.223 129 101.5 L 129 108.5 C 129 108.777 129.223 109 129.5 109 L 130.5 109 C 130.777 109 131 108.777 131 108.5 L 131 101.5 C 131 101.223 130.777 101 130.5 101 L 129.5 101 z M 140.5 101 C 140.223 101 140 101.223 140 101.5 L 140 108.5 C 140 108.777 140.223 109 140.5 109 L 141.5 109 C 141.777 109 142 108.777 142 108.5 L 142 101.5 C 142 101.223 141.777 101 141.5 101 L 140.5 101 z M 132.5 102 C 132.223 102 132 102.223 132 102.5 L 132 105.5 L 132 107.5 C 132 107.777 132.223 108 132.5 108 C 132.777 108 133 107.777 133 107.5 L 133 106 L 134.5 106 C 134.777 106 135 105.777 135 105.5 L 135 102.5 C 135 102.223 134.777 102 134.5 102 L 132.5 102 z M 136.5 102 C 136.223 102 136 102.223 136 102.5 L 136 105.5 C 136 105.777 136.223 106 136.5 106 L 138 106 L 138 107.5 C 138 107.777 138.223 108 138.5 108 C 138.777 108 139 107.777 139 107.5 L 139 105.5 L 139 102.5 C 139 102.223 138.777 102 138.5 102 L 136.5 102 z " + id="turnstile" /> @@ -2316,7 +2315,7 @@ inkscape:label="#path3428" /> @@ -2494,7 +2493,7 @@ rx="0.5" /> @@ -2532,7 +2531,7 @@ inkscape:label="#path3411" /> @@ -2813,7 +2812,8 @@ + id="muslim" + inkscape:label="#path4443" /> + d="m 246,65 0,2 -2,0 0,1 c 1.10457,0 2,0.895431 2,2 l 0,1 -2,0 0,1 c 1.10457,0 2,0.895431 2,2 l 0,1 -2,0 0,1 c 1.10457,0 2,0.895431 2,2 l 0,1 4,0 0,-1 c 0,-1.104569 0.89543,-2 2,-2 l 0,-1 -2,0 0,-1 c 0,-1.104569 0.89543,-2 2,-2 l 0,-1 -2,0 0,-1 c 0,-1.104569 0.89543,-2 2,-2 l 0,-1 -2,0 0,-2 -4,0 z m 1,2 2,0 0,2 -2,0 0,-2 z m 0,4 2,0 0,2 -2,0 0,-2 z m 0,4 2,0 0,2 -2,0 0,-2 z" + id="traffic_signals" + inkscape:connector-curvature="0" /> + + + + + + + + + + + + + + + + + + + + + + + + + film + + + + + + + + + + + + + + + diff --git a/mapper.py b/mapper.py index f8246e1..bca30e7 100644 --- a/mapper.py +++ b/mapper.py @@ -10,6 +10,7 @@ Author: Sergey Vartanov (me@enzet.ru). import copy import datetime import os +import process import re import sys import xml.dom.minidom @@ -82,7 +83,7 @@ def get_d_from_file(file_name): if path: return path, x, y else: - print 'No such icon: ' + file_name + # print 'No such icon: ' + file_name # TODO: add to missed icons return 'M 4,4 L 4,10 10,10 10,4 z', 0, 0 @@ -395,7 +396,7 @@ def draw_ways(show_missed_tags=False): #floors = float(way['tags']['building:levels']) draw_path(way['nodes'], 'fill:#' + building_color + ';stroke:#' + building_border_color + ';opacity:1.0;') c = line_center(way['nodes']) - shapes, fill, processed = get_icon(way['tags'], scheme, '444444') + shapes, fill, processed = process.get_icon(way['tags'], scheme, '444444') draw_shapes(shapes, True, points, c.x, c.y, fill, show_missed_tags, way['tags'], processed) icons_to_draw.append({'shapes': shapes, 'x': c.x, 'y': c.y, 'fill': fill, 'priority': 1}) for way in layer['le']: @@ -446,73 +447,6 @@ def to_write(key): return True return False -def get_color(color, scheme): - if color in scheme['colors']: - return scheme['colors'][color] - else: - m = re.match('^(\\#)?(?P[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])' + \ - '(?P[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])?$', color) - if m: - if 'color2' in m.groups(): - return m.group('color1') + m.group('color2') - else: - return ''.join(map(lambda x: x + x, m.group('color1'))) - return '444444' - -def get_icon(tags, scheme, fill='444444'): - tags_hash = ','.join(tags.keys()) + ':' + \ - ','.join(map(lambda x: str(x), tags.values())) - if tags_hash in scheme['cache']: - return scheme['cache'][tags_hash] - main_icon = None - extra_icons = [] - processed = set() - for element in scheme['tags']: - matched = True - for tag in element['tags']: - if not tag in tags: - matched = False - break - if element['tags'][tag] != '*' and element['tags'][tag] != tags[tag]: - matched = False - break - if 'no_tags' in element: - for no_tag in element['no_tags']: - if no_tag in tags.keys(): - matched = False - break - if matched: - if 'draw' in element and not element['draw']: - processed = set(element['tags'].keys()) - if 'icon' in element: - main_icon = copy.deepcopy(element['icon']) - processed = set(element['tags'].keys()) - if 'over_icon' in element: - main_icon += element['over_icon'] - for key in element['tags'].keys(): - processed.add(key) - if 'add_icon' in element: - extra_icons += element['add_icon'] - for key in element['tags'].keys(): - processed.add(key) - if 'color' in element: - fill = scheme['colors'][element['color']] - for key in element['tags'].keys(): - processed.add(key) - for color_name in ['color', 'colour', 'building:colour']: - if color_name in tags: - fill = get_color(tags[color_name], scheme) - if fill != '444444': - processed.add(color_name) - else: - print 'No color ' + tags[color_name] + '.' - if main_icon: - returned = [main_icon] + extra_icons, fill, processed - else: - returned = [], fill, processed - scheme['cache'][tags_hash] = returned - return returned - def draw_shapes(shapes, overlap, points, x, y, fill, show_missed_tags, tags, processed): text_y = 0 xxx = -(len(shapes) - 1) * 8 @@ -563,7 +497,7 @@ def draw_nodes(show_missed_tags=False, overlap=14, draw=True): else: tags = {} - shapes, fill, processed = get_icon(tags, scheme) + shapes, fill, processed = process.get_icon(tags, scheme) for k in tags: if k in processed or no_draw(k): @@ -661,8 +595,8 @@ draw_nodes(show_missed_tags=options['show_missed_tags'], overlap=options['overlap'], draw=options['draw_nodes']) if flinger.space.x == 0: - output_file.rect(0, 0, w, flinger.space.y, color='AAAAAA') - output_file.rect(0, h - flinger.space.y, w, flinger.space.y, color='AAAAAA') + output_file.rect(0, 0, w, flinger.space.y, color='FFFFFF') + output_file.rect(0, h - flinger.space.y, w, flinger.space.y, color='FFFFFF') output_file.end() diff --git a/process.py b/process.py new file mode 100644 index 0000000..3744130 --- /dev/null +++ b/process.py @@ -0,0 +1,69 @@ +import copy + +def get_color(color, scheme): + if color in scheme['colors']: + return scheme['colors'][color] + else: + m = re.match('^(\\#)?(?P[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])' + \ + '(?P[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])?$', color) + if m: + if 'color2' in m.groups(): + return m.group('color1') + m.group('color2') + else: + return ''.join(map(lambda x: x + x, m.group('color1'))) + return '444444' + +def get_icon(tags, scheme, fill='444444'): + tags_hash = ','.join(tags.keys()) + ':' + \ + ','.join(map(lambda x: str(x), tags.values())) + if tags_hash in scheme['cache']: + return scheme['cache'][tags_hash] + main_icon = None + extra_icons = [] + processed = set() + for matcher in scheme['tags']: + matched = True + for key in matcher['tags']: + if not key in tags: + matched = False + break + if matcher['tags'][key] != '*' and matcher['tags'][key] != tags[key]: + matched = False + break + if 'no_tags' in matcher: + for no_tag in matcher['no_tags']: + if no_tag in tags.keys(): + matched = False + break + if matched: + if 'draw' in matcher and not matcher['draw']: + processed = set(matcher['tags'].keys()) + if 'icon' in matcher: + main_icon = copy.deepcopy(matcher['icon']) + processed = set(matcher['tags'].keys()) + if 'over_icon' in matcher: + main_icon += matcher['over_icon'] + for key in matcher['tags'].keys(): + processed.add(key) + if 'add_icon' in matcher: + extra_icons += matcher['add_icon'] + for key in matcher['tags'].keys(): + processed.add(key) + if 'color' in matcher: + fill = scheme['colors'][matcher['color']] + for key in matcher['tags'].keys(): + processed.add(key) + for color_name in ['color', 'colour', 'building:colour']: + if color_name in tags: + fill = get_color(tags[color_name], scheme) + if fill != '444444': + processed.add(color_name) + else: + print 'No color ' + tags[color_name] + '.' + if main_icon: + returned = [main_icon] + extra_icons, fill, processed + else: + returned = [], fill, processed + scheme['cache'][tags_hash] = returned + return returned + diff --git a/test.py b/test.py index 0427287..a7481f3 100644 --- a/test.py +++ b/test.py @@ -4,6 +4,8 @@ Author: Sergey Vartanov (me@enzet.ru). import copy import extract_icon +import process +import os import sys import yaml @@ -13,38 +15,13 @@ sys.path.append('lib') import svg -def get_icon(tags): - main_icon = None - extra_icons = [] - for element in scheme['tags']: - matched = True - for tag in element['tags']: - if not tag in tags: - matched = False - break - if element['tags'][tag] != '*' and \ - element['tags'][tag] != tags[tag]: - matched = False - break - if matched: - print 'matched', element - if 'icon' in element: - main_icon = copy.deepcopy(element['icon']) - if 'over_icon' in element: - main_icon += element['over_icon'] - if 'add_icon' in element: - extra_icons += element['add_icon'] - if main_icon: - return [main_icon] + extra_icons - else: - return [] - def draw_icon(icon): output_file.write('\n') + # Actions step = 24 @@ -56,23 +33,37 @@ extracter = extract_icon.IconExtractor('icons.svg') x = step / 2 y = step / 2 -to_draw = {} +to_draw = [] for element in scheme['tags']: if 'icon' in element: - to_draw[','.join(element['icon'])] = element['icon'] + if not (set(element['icon']) in to_draw): + to_draw.append(set(element['icon'])) if 'add_icon' in element: - to_draw[','.join(element['add_icon'])] = element['add_icon'] + if not (set(element['add_icon']) in to_draw): + to_draw.append(set(element['add_icon'])) if 'over_icon' in element: - for icon in element['under_icon']: - to_draw[','.join([icon] + element['over_icon'])] = [icon] + \ - element['over_icon'] + with_icons = [] + if 'under_icon' in element: + for icon in element['under_icon']: + if not (set([icon] + element['over_icon']) in to_draw): + to_draw.append(set([icon] + element['over_icon'])) + if 'under_icon' in element and 'with_icon' in element: + for icon in element['under_icon']: + for icon2 in element['with_icon']: + if not (set([icon] + [icon2] + element['over_icon']) in to_draw): + to_draw.append(set([icon] + [icon2] + element['over_icon'])) + for icon2 in element['with_icon']: + for icon3 in element['with_icon']: + if icon2 != icon3 and icon2 != icon and icon3 != icon: + if not (set([icon] + [icon2] + [icon3] + element['over_icon']) in to_draw): + to_draw.append(set([icon] + [icon2] + [icon3] + element['over_icon'])) icons = [] height = 24 +number = 0 -for icon_key in to_draw.keys(): - icons_to_draw = to_draw[icon_key] +for icons_to_draw in to_draw: drawed = False for icon in icons_to_draw: path, xx, yy = extracter.get_path(icon) @@ -84,6 +75,7 @@ for icon_key in to_draw.keys(): else: print '\033[31m' + icon + '\033[0m' if drawed: + number += 1 x += step if x > width - 8: x = step / 2 @@ -96,4 +88,6 @@ output_file.begin(width, height) for icon in icons: draw_icon(icon) +print 'Icons: ' + str(number) + '.' + output_file.end()