Fix icon drawing.

This commit is contained in:
Sergey Vartanov 2021-11-28 12:03:01 +03:00
parent ad2284e69a
commit 3c9054e7fc
3 changed files with 14 additions and 73 deletions

View file

@ -14,7 +14,7 @@ from svgwrite.shapes import Line, Rect
from map_machine.map_configuration import MapConfiguration
from map_machine.osm.osm_reader import Tags
from map_machine.pictogram.icon import ShapeExtractor, Icon, IconSet
from map_machine.pictogram.icon import ShapeExtractor, IconSet
from map_machine.scheme import Scheme
from map_machine.workspace import Workspace
@ -62,67 +62,6 @@ class Collection:
)
class WikiTable:
"""SVG table with icon combinations."""
def __init__(self, collection: Collection, page_name: str):
self.collection: Collection = collection
self.page_name: str = page_name
def generate_wiki_table(self) -> tuple[str, list[Icon]]:
"""
Generate Röntgen icon table for the OpenStreetMap wiki page.
"""
icons: list[Icon] = []
text: str = '{| class="wikitable"\n'
if self.collection.column_key is not None:
text += f"! {{{{Key|{self.collection.column_key}}}}}"
else:
text += "! Tag || Icon"
if not self.collection.column_values:
self.collection.column_values = [""]
else:
for column_value in self.collection.column_values:
text += " ||"
if column_value:
text += (
f" {{{{vert header|{{{{TagValue|"
f"{self.collection.column_key}|{column_value}}}}}}}}}"
)
text += "\n"
processed: set[str] = set()
for row_value in self.collection.row_values:
text += "|-\n"
if row_value:
text += f"| {{{{Tag|{self.collection.row_key}|{row_value}}}}}\n"
else:
text += "|\n"
for column_value in self.collection.column_values:
current_tags: Tags = dict(self.collection.tags) | {
self.collection.row_key: row_value
}
if column_value:
current_tags |= {self.collection.column_key: column_value}
icon, _ = SCHEME.get_icon(
EXTRACTOR, current_tags, processed, MapConfiguration()
)
if not icon:
print("Icon was not constructed.")
text += (
"| "
f"[[Image:Röntgen {icon.main_icon.get_name()}.svg|32px]]\n"
)
icons.append(icon.main_icon)
text += "|}\n"
return text, icons
class SVGTable:
"""SVG table with icon combinations."""

View file

@ -419,11 +419,7 @@ class Icon:
if len(names) == 1:
return names[0]
if len(names) == 2:
return names[0] + " and " + names[1]
if len(names) > 2:
return ", ".join(names[:-1]) + " and " + names[-1]
return ", ".join(names[:-1]) + " and " + names[-1]
def has_categories(self) -> bool:
"""Check whether oll shape categories are known."""

View file

@ -211,17 +211,23 @@ def draw_icons() -> None:
)
collection: IconCollection = IconCollection.from_scheme(scheme, extractor)
collection.sort()
for icon in collection.icons:
icon.recolor(Color("#444444"))
icon_grid_path: Path = workspace.get_icon_grid_path()
collection.draw_grid(workspace.GRID_PATH)
collection.draw_grid(icon_grid_path)
logging.info(f"Icon grid is written to {icon_grid_path}.")
# Draw individual icons.
icons_by_id_path: Path = workspace.get_icons_by_id_path()
icons_by_name_path: Path = workspace.get_icons_by_name_path()
collection.draw_icons(icons_by_id_path)
collection.draw_icons(icons_by_name_path, by_name=True)
logging.info(
f"Icons are written to {icons_by_name_path} and {icons_by_id_path}."
)
# Draw grid.
for icon in collection.icons:
icon.recolor(Color("#444444"))
for path in workspace.get_icon_grid_path(), workspace.GRID_PATH:
collection.draw_grid(path)
logging.info(f"Icon grid is written to {path}.")