Skip to content

Commit

Permalink
Rename element command to draw.
Browse files Browse the repository at this point in the history
And add node drawing.
  • Loading branch information
enzet committed Aug 17, 2022
1 parent 6dd9bc2 commit 692997f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion doc/grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion map_machine/doc/moire_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def options(self, arg: Arguments) -> str:
elif command == "map":
cli.add_map_arguments(parser)
elif command == "element":
cli.add_element_arguments(parser)
cli.add_draw_arguments(parser)
elif command == "mapcss":
cli.add_mapcss_arguments(parser)
else:
Expand Down
24 changes: 14 additions & 10 deletions map_machine/element/element.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import sys
import argparse
from pathlib import Path

from map_machine.element.grid import Grid
from map_machine.osm.osm_reader import Tags, OSMNode


def draw_node():
pass
def draw_node(tags: Tags, path: Path):
grid: Grid = Grid(x_step=0.0003, show_credit=False, margin=0.5)
grid.add_node(tags, 0, 0)
grid.draw(path)


def draw_way():
Expand All @@ -24,13 +26,15 @@ def draw_area(tags: Tags, path: Path):
node,
]
grid.add_way(tags, nodes)

grid.draw(path)


if __name__ == "__main__":
tags: str = sys.argv[1]
path: str = sys.argv[2]
draw_area(
{x.split("=")[0]: x.split("=")[1] for x in tags.split(",")}, Path(path)
)
def draw_element(options: argparse.Namespace):

tags_description: Tags = {
x.split("=")[0]: x.split("=")[1] for x in options.tags.split(",")
}
if options.type == "area":
draw_area(tags_description, Path(options.output_file))
elif options.type == "node":
draw_node(tags_description, Path(options.output_file))
4 changes: 2 additions & 2 deletions map_machine/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def main() -> None:

mapcss.generate_mapcss(arguments)

elif arguments.command == "element":
from map_machine.element.node import draw_element
elif arguments.command == "draw":
from map_machine.element.element import draw_element

draw_element(arguments)

Expand Down
14 changes: 7 additions & 7 deletions map_machine/ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"icons": ["icons"],
"mapcss": ["mapcss"],
"element": ["element", "--node", "amenity=bench,material=wood"],
"draw": ["draw", "node", "amenity=bench,material=wood"],
"tile": ["tile", "--coordinates", "50.000,40.000"],
}
COMMANDS: list[str] = [
Expand Down Expand Up @@ -85,9 +85,9 @@ def parse_arguments(args: list[str]) -> argparse.Namespace:
help="run tile server",
)
)
add_element_arguments(
add_draw_arguments(
subparser.add_parser(
"element",
"draw",
description="Draw map element separately.",
help="draw OSM element: node, way, relation",
)
Expand Down Expand Up @@ -274,11 +274,11 @@ def add_server_arguments(parser: argparse.ArgumentParser) -> None:
)


def add_element_arguments(parser: argparse.ArgumentParser) -> None:
def add_draw_arguments(parser: argparse.ArgumentParser) -> None:
"""Add arguments for element command."""
parser.add_argument("-n", "--node")
parser.add_argument("-w", "--way")
parser.add_argument("-r", "--relation")
parser.add_argument("type")
parser.add_argument("tags")
parser.add_argument("-o", "--output-file", default="out/element.svg")


def add_render_arguments(parser: argparse.ArgumentParser) -> None:
Expand Down
2 changes: 1 addition & 1 deletion map_machine/ui/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def completion_commands() -> str:
cli.add_tile_arguments(parser)
cli.add_map_arguments(parser)
elif command == "element":
cli.add_element_arguments(parser)
cli.add_draw_arguments(parser)
elif command == "mapcss":
cli.add_mapcss_arguments(parser)
else:
Expand Down
14 changes: 7 additions & 7 deletions tests/test_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ def test_mapcss() -> None:
assert (out_path / "icons" / "LICENSE").is_file()


def test_element() -> None:
"""Test `element` command."""
def test_draw() -> None:
"""Test `draw` command."""
run(
COMMAND_LINES["element"],
b"INFO Element is written to out/element.svg.\n",
COMMAND_LINES["draw"],
LOG + b"INFO Map is drawn to out/element.svg.\n",
)
assert (OUTPUT_PATH / "element.svg").is_file()


def test_unwrapped_element() -> None:
def test_unwrapped_draw() -> None:
"""Test `element` command from inside the project."""
arguments: argparse.Namespace = parse_arguments(
["map_machine"] + COMMAND_LINES["element"]
["map_machine"] + COMMAND_LINES["draw"]
)
from map_machine.element.node import draw_element
from map_machine.element.element import draw_element

draw_element(arguments)

Expand Down

0 comments on commit 692997f

Please sign in to comment.