From b3560cfdc75657b610fd7ec5966fd814242be7b3 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Tue, 31 Aug 2021 01:17:13 +0300 Subject: [PATCH] Add set_opacity command for icons. --- roentgen/constructor.py | 2 +- roentgen/icon.py | 12 ++++++++---- roentgen/point.py | 2 +- roentgen/scheme.py | 6 ++++++ roentgen/ui.py | 2 +- scheme/default.yml | 36 ++++++++++++++++++++++++------------ 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/roentgen/constructor.py b/roentgen/constructor.py index 2af24c7..8853154 100644 --- a/roentgen/constructor.py +++ b/roentgen/constructor.py @@ -220,7 +220,7 @@ class Constructor: if not line.tags: return - building_mode: BuildingMode = self.configuration.building_mode + building_mode: str = self.configuration.building_mode if "building" in line.tags or ( building_mode == BuildingMode.ISOMETRIC and "building:part" in line.tags diff --git a/roentgen/icon.py b/roentgen/icon.py index a6a63e4..0020132 100644 --- a/roentgen/icon.py +++ b/roentgen/icon.py @@ -329,6 +329,7 @@ class Icon: """ shape_specifications: list[ShapeSpecification] + opacity: float = 1.0 def get_shape_ids(self) -> list[str]: """Get all shape identifiers in the icon.""" @@ -356,16 +357,19 @@ class Icon: :param tags: tags to be displayed as hint :param outline: draw outline for the icon """ - bright: bool = is_bright(self.shape_specifications[0].color) - opacity: float = 0.7 if bright else 0.5 + target = Group(opacity=self.opacity) if self.opacity != 1.0 else svg if outline: + bright: bool = is_bright(self.shape_specifications[0].color) + opacity: float = 0.7 if bright else 0.5 outline_group: Group = Group(opacity=opacity) for shape_specification in self.shape_specifications: shape_specification.draw(outline_group, point, tags, True) - svg.add(outline_group) + target.add(outline_group) else: for shape_specification in self.shape_specifications: - shape_specification.draw(svg, point, tags) + shape_specification.draw(target, point, tags) + if self.opacity != 1.0: + svg.add(target) def draw_to_file( self, diff --git a/roentgen/point.py b/roentgen/point.py index bcdc6bf..bb75d00 100644 --- a/roentgen/point.py +++ b/roentgen/point.py @@ -159,7 +159,7 @@ class Point(Tagged): self, svg: svgwrite.Drawing, occupied: Optional[Occupied] = None, - label_mode: LabelMode = LabelMode.MAIN, + label_mode: str = LabelMode.MAIN, ) -> None: """Draw all labels.""" labels: list[Label] diff --git a/roentgen/scheme.py b/roentgen/scheme.py index 91ef8bf..e7c21d2 100644 --- a/roentgen/scheme.py +++ b/roentgen/scheme.py @@ -201,6 +201,10 @@ class NodeMatcher(Matcher): if "set_main_color" in structure: self.set_main_color = structure["set_main_color"] + self.set_opacity: Optional[float] = None + if "set_opacity" in structure: + self.set_opacity = structure["set_opacity"] + self.under_icon: Optional[IconDescription] = None if "under_icon" in structure: self.under_icon = structure["under_icon"] @@ -408,6 +412,8 @@ class Scheme: processed |= matcher_tags if matcher.set_main_color and main_icon: main_icon.recolor(self.get_color(matcher.set_main_color)) + if matcher.set_opacity and main_icon: + main_icon.opacity = matcher.set_opacity index += 1 diff --git a/roentgen/ui.py b/roentgen/ui.py index 44f510a..4ad4b05 100644 --- a/roentgen/ui.py +++ b/roentgen/ui.py @@ -14,7 +14,7 @@ BOXES: str = " ▏▎▍▌▋▊▉" BOXES_LENGTH: int = len(BOXES) -def parse_options(args: argparse.Namespace) -> argparse.Namespace: +def parse_options(args: list[str]) -> argparse.Namespace: """Parse Röntgen command-line options.""" parser: argparse.ArgumentParser = argparse.ArgumentParser( description="Röntgen. OpenStreetMap renderer with custom icon set" diff --git a/scheme/default.yml b/scheme/default.yml index 3a525bf..4bdb798 100644 --- a/scheme/default.yml +++ b/scheme/default.yml @@ -949,30 +949,42 @@ node_icons: shapes: [lander] - tags: {man_made: rover, condition: landed} - shapes: [{shape: lunokhod, opacity: 0.8}] + shapes: [lunokhod] + set_opacity: 0.8 - tags: {man_made: probe, condition: landed} - shapes: [{shape: probe, opacity: 0.8}] + shapes: [probe] + set_opacity: 0.8 - tags: {man_made: orbiter, condition: landed} - shapes: [{shape: orbiter, opacity: 0.8}] + shapes: [orbiter] + set_opacity: 0.8 - tags: {man_made: descent_stage, condition: landed} - shapes: [{shape: descent_stage, opacity: 0.8}] + shapes: [descent_stage] + set_opacity: 0.8 - tags: {man_made: third_stage, condition: landed} - shapes: [{shape: third_stage, opacity: 0.8}] + shapes: [third_stage] + set_opacity: 0.8 - tags: {man_made: lander, condition: landed} - shapes: [{shape: lander, opacity: 0.8}] + shapes: [lander] + set_opacity: 0.8 - tags: {man_made: rover, condition: crashed} - shapes: [{shape: lunokhod, opacity: 0.5}] + shapes: [lunokhod] + set_opacity: 0.5 - tags: {man_made: probe, condition: crashed} - shapes: [{shape: probe, opacity: 0.5}] + shapes: [probe] + set_opacity: 0.5 - tags: {man_made: orbiter, condition: crashed} - shapes: [{shape: orbiter, opacity: 0.5}] + shapes: [orbiter] + set_opacity: 0.5 - tags: {man_made: descent_stage, condition: crashed} - shapes: [{shape: descent_stage, opacity: 0.5}] + shapes: [descent_stage] + set_opacity: 0.5 - tags: {man_made: third_stage, condition: crashed} - shapes: [{shape: third_stage, opacity: 0.5}] + shapes: [third_stage] + set_opacity: 0.5 - tags: {man_made: lander, condition: crashed} - shapes: [{shape: lander, opacity: 0.5}] + shapes: [lander] + set_opacity: 0.5 - group: "Important small objects" start_zoom_level: 17