svgmapviewer-tools-floors 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/inkscape/extensions/Attic/fix_guides.inx +17 -0
- package/inkscape/extensions/Attic/fix_guides.py +30 -0
- package/inkscape/extensions/Attic/fix_symbol_links.inx +17 -0
- package/inkscape/extensions/Attic/fix_symbol_links.py +71 -0
- package/inkscape/extensions/Attic/flatten_style.inx +17 -0
- package/inkscape/extensions/Attic/flatten_style.py +31 -0
- package/inkscape/extensions/Attic/load_markers.inx +17 -0
- package/inkscape/extensions/Attic/load_markers.py +117 -0
- package/inkscape/extensions/Attic/load_patterns.inx +17 -0
- package/inkscape/extensions/Attic/load_patterns.py +116 -0
- package/inkscape/extensions/Attic/load_symbols.inx +17 -0
- package/inkscape/extensions/Attic/load_symbols.py +164 -0
- package/inkscape/extensions/Attic/renumber_tree.inx +24 -0
- package/inkscape/extensions/Attic/renumber_tree.py +39 -0
- package/inkscape/extensions/Attic/repeat_path.inx +17 -0
- package/inkscape/extensions/Attic/repeat_path.py +58 -0
- package/inkscape/extensions/Attic/resolve_facility_links.inx +19 -0
- package/inkscape/extensions/Attic/resolve_facility_links.py +16 -0
- package/inkscape/extensions/Attic/sort_symbols.inx +17 -0
- package/inkscape/extensions/Attic/sort_symbols.py +48 -0
- package/inkscape/extensions/Attic/symbol_load.inx +17 -0
- package/inkscape/extensions/Attic/symbol_load.py +99 -0
- package/inkscape/extensions/Attic/tidy_tree.inx +22 -0
- package/inkscape/extensions/Attic/tidy_tree.py +178 -0
- package/inkscape/extensions/Attic/use_shop.inx +22 -0
- package/inkscape/extensions/Attic/use_shop.py +26 -0
- package/inkscape/extensions/README.md +34 -0
- package/inkscape/extensions/daijimaps/__init__.py +72 -0
- package/inkscape/extensions/daijimaps/address_tree.py +231 -0
- package/inkscape/extensions/daijimaps/common.py +49 -0
- package/inkscape/extensions/daijimaps/generate_addresses.py +41 -0
- package/inkscape/extensions/daijimaps/guards.py +47 -0
- package/inkscape/extensions/daijimaps/map_layer.py +47 -0
- package/inkscape/extensions/daijimaps/name.py +167 -0
- package/inkscape/extensions/daijimaps/renumber.py +38 -0
- package/inkscape/extensions/daijimaps/resolve_labels.py +65 -0
- package/inkscape/extensions/daijimaps/resolve_names.py +170 -0
- package/inkscape/extensions/daijimaps/save_addresses.py +274 -0
- package/inkscape/extensions/daijimaps/types.py +128 -0
- package/inkscape/extensions/daijimaps/visit_parents.py +37 -0
- package/inkscape/extensions/extract_labels.py +79 -0
- package/inkscape/extensions/fixup_floor_svg.py +28 -0
- package/inkscape/extensions/fixup_texts.inx +15 -0
- package/inkscape/extensions/fixup_texts.py +110 -0
- package/inkscape/extensions/fixup_tree.inx +15 -0
- package/inkscape/extensions/fixup_tree.py +17 -0
- package/inkscape/extensions/flatten_transform.inx +17 -0
- package/inkscape/extensions/flatten_transform.py +63 -0
- package/inkscape/extensions/import_labels.inx +20 -0
- package/inkscape/extensions/import_labels.py +52 -0
- package/inkscape/extensions/import_shops.inx +20 -0
- package/inkscape/extensions/import_shops.py +47 -0
- package/inkscape/extensions/install.sh +14 -0
- package/inkscape/extensions/load_shops.inx +20 -0
- package/inkscape/extensions/load_shops.py +86 -0
- package/inkscape/extensions/renumber_group.inx +15 -0
- package/inkscape/extensions/renumber_group.py +17 -0
- package/inkscape/extensions/resolve_labels.inx +20 -0
- package/inkscape/extensions/resolve_labels.py +142 -0
- package/inkscape/extensions/resolve_shops.inx +20 -0
- package/inkscape/extensions/resolve_shops.py +73 -0
- package/inkscape/extensions/unresolve_labels.inx +20 -0
- package/inkscape/extensions/unresolve_labels.py +53 -0
- package/inkscape/extensions/unresolve_shops.inx +20 -0
- package/inkscape/extensions/unresolve_shops.py +56 -0
- package/inkscape/templates/floors.svg +665 -0
- package/map-extract-floors.js +821 -0
- package/package.json +19 -0
- package/pyproject.toml +20 -0
- package/scripts/inkex-inkscape +14 -0
- package/scripts/inkex-python +14 -0
- package/scripts/inkex-setup +6 -0
- package/scripts/labels.sh +18 -0
- package/scripts/regen.py +77 -0
- package/scripts/regen.sh +24 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
import inkex
|
|
5
|
+
|
|
6
|
+
from daijimaps.guards import isGroup, isTextElement, isTspan
|
|
7
|
+
from daijimaps.types import TextInfoJson, TspanInfoJson
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
layer_label_re = re.compile("^[^(].*$")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
type Labels = list[TextInfoJson]
|
|
14
|
+
type FloorLabels = dict[str, Labels]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ExtractLabels(inkex.OutputExtension):
|
|
18
|
+
def add_arguments(self, pars) -> None:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
def _textToInfo(self, e: inkex.TextElement) -> TextInfoJson:
|
|
22
|
+
children = []
|
|
23
|
+
for child in list(e):
|
|
24
|
+
if not isTspan(child):
|
|
25
|
+
continue
|
|
26
|
+
info: TspanInfoJson = {
|
|
27
|
+
"attrs": dict(child.attrib.items()),
|
|
28
|
+
"text": child.text,
|
|
29
|
+
}
|
|
30
|
+
children.append(info)
|
|
31
|
+
info: TextInfoJson = {
|
|
32
|
+
"attrs": dict(e.attrib.items()),
|
|
33
|
+
"children": children,
|
|
34
|
+
}
|
|
35
|
+
return info
|
|
36
|
+
|
|
37
|
+
def _collectLabels(self, layer: inkex.Group) -> Labels | None:
|
|
38
|
+
j = []
|
|
39
|
+
xs = layer.xpath(
|
|
40
|
+
'./*[@*[name()="inkscape:label"]="Content"]/*[@*[name()="inkscape:label"]="(Labels)"]'
|
|
41
|
+
)
|
|
42
|
+
if not isinstance(xs, list) or len(xs) != 1:
|
|
43
|
+
xs = layer.xpath(
|
|
44
|
+
'./*[@*[name()="inkscape:label"]="(Labels)"]'
|
|
45
|
+
)
|
|
46
|
+
if not isinstance(xs, list) or len(xs) != 1:
|
|
47
|
+
return None
|
|
48
|
+
x = xs[0]
|
|
49
|
+
if not isGroup(x):
|
|
50
|
+
return None
|
|
51
|
+
for child in list(x):
|
|
52
|
+
if not isTextElement(child):
|
|
53
|
+
continue
|
|
54
|
+
j.append(self._textToInfo(child))
|
|
55
|
+
return j
|
|
56
|
+
|
|
57
|
+
def _collectFloors(self) -> FloorLabels:
|
|
58
|
+
j: FloorLabels = {}
|
|
59
|
+
layers = self.svg.xpath('/*/*[@*[name()="inkscape:groupmode"]="layer"]')
|
|
60
|
+
for layer in list(layers):
|
|
61
|
+
if not isGroup(layer):
|
|
62
|
+
continue
|
|
63
|
+
label = layer.label
|
|
64
|
+
if label is None or not layer_label_re.match(label):
|
|
65
|
+
continue
|
|
66
|
+
labels = self._collectLabels(layer)
|
|
67
|
+
if labels is None:
|
|
68
|
+
continue
|
|
69
|
+
j[label] = labels
|
|
70
|
+
return j
|
|
71
|
+
|
|
72
|
+
def save(self, stream) -> None:
|
|
73
|
+
j: FloorLabels = self._collectFloors()
|
|
74
|
+
b = json.dumps(j, indent=2).encode("utf-8")
|
|
75
|
+
stream.write(b)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
ExtractLabels().run()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import inkex
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class FixupFloorSvg(inkex.EffectExtension):
|
|
5
|
+
def effect(self) -> None:
|
|
6
|
+
xs = self.svg.xpath('/*/*/*[@*[name()="inkscape:label"]="Content"]')
|
|
7
|
+
if isinstance(xs, list) and len(xs) == 1:
|
|
8
|
+
content = xs[0]
|
|
9
|
+
if isinstance(content, inkex.Group):
|
|
10
|
+
# 1. delete display:none
|
|
11
|
+
floor = content.getparent()
|
|
12
|
+
if isinstance(floor, inkex.Group):
|
|
13
|
+
if "display" in floor.style:
|
|
14
|
+
del floor.style["display"]
|
|
15
|
+
|
|
16
|
+
# 2. remove Shops
|
|
17
|
+
for child in list(content):
|
|
18
|
+
if child.label == "Shops":
|
|
19
|
+
content.remove(child)
|
|
20
|
+
|
|
21
|
+
# 3. remove (Labels)
|
|
22
|
+
for child in list(content):
|
|
23
|
+
if child.label == "(Labels)":
|
|
24
|
+
content.remove(child)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
FixupFloorSvg().run()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
|
3
|
+
<name>Fixup: Text: Fixup text/tspan</name>
|
|
4
|
+
<id>daijimaps.fixup_texts</id>
|
|
5
|
+
<label>Fixup: Text: Fixup text/tspan.</label>
|
|
6
|
+
<effect needs-live-preview="false">
|
|
7
|
+
<object-type>all</object-type>
|
|
8
|
+
<effects-menu>
|
|
9
|
+
<submenu name="Daiji Maps"/>
|
|
10
|
+
</effects-menu>
|
|
11
|
+
</effect>
|
|
12
|
+
<script>
|
|
13
|
+
<command location="inx" interpreter="python">fixup_texts.py</command>
|
|
14
|
+
</script>
|
|
15
|
+
</inkscape-extension>
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
import inkex
|
|
4
|
+
|
|
5
|
+
from daijimaps.guards import isTextElement, isTspan
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
names_label_re = re.compile("^[(].*Names.*[)]$")
|
|
9
|
+
labels_label_re = re.compile("^[(].*Names.*[)]$")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# - fix nested tspans
|
|
13
|
+
# - remove tspan's style
|
|
14
|
+
# - remove tspan's dy
|
|
15
|
+
# - trim whitespaces in tspan
|
|
16
|
+
# - remove non-tspan elements (if exists)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class FixupTexts(inkex.EffectExtension):
|
|
20
|
+
def _joinTextTail(self, elem: inkex.Tspan) -> str:
|
|
21
|
+
texts = []
|
|
22
|
+
text = elem.text
|
|
23
|
+
if isinstance(text, str) and len(text) > 0:
|
|
24
|
+
texts.append(elem.text)
|
|
25
|
+
tail = elem.tail
|
|
26
|
+
if isinstance(tail, str) and len(tail) > 0:
|
|
27
|
+
texts.append(elem.tail)
|
|
28
|
+
return " ".join(texts)
|
|
29
|
+
|
|
30
|
+
def _collectTexts(self, elem: inkex.Tspan) -> str:
|
|
31
|
+
subtexts: list[str] = []
|
|
32
|
+
for child in list(elem):
|
|
33
|
+
self.msg(f"! tspan child (text={child.text} tail={child.tail})")
|
|
34
|
+
if isTspan(child):
|
|
35
|
+
text = self._collectTexts(child)
|
|
36
|
+
self.msg(f"! tspan child (text={text})")
|
|
37
|
+
if isinstance(text, str) and len(text) > 0:
|
|
38
|
+
subtexts.append(text)
|
|
39
|
+
if len(subtexts) > 0:
|
|
40
|
+
text = self._joinTextTail(elem)
|
|
41
|
+
subtexts.append(text)
|
|
42
|
+
res = " ".join(subtexts)
|
|
43
|
+
self.msg(f"! merged tspan (res={res})")
|
|
44
|
+
return res
|
|
45
|
+
else:
|
|
46
|
+
res = self._joinTextTail(elem)
|
|
47
|
+
self.msg(f"! unmerged tspan (res={res})")
|
|
48
|
+
return res
|
|
49
|
+
|
|
50
|
+
def _fixupTspan(self, elem: inkex.Tspan, idx: int) -> None:
|
|
51
|
+
text = self._collectTexts(elem)
|
|
52
|
+
text = trim(text)
|
|
53
|
+
self.msg(f"tspan: {text}")
|
|
54
|
+
elem.style = None
|
|
55
|
+
for a in ["x", "y", "dy"]:
|
|
56
|
+
if a in elem.attrib:
|
|
57
|
+
del elem.attrib[a]
|
|
58
|
+
elem.set("x", "0")
|
|
59
|
+
elem.set("y", f"{idx * 1.25}em")
|
|
60
|
+
for child in list(elem):
|
|
61
|
+
self.msg(f"! removing children (id={elem.get_id()})")
|
|
62
|
+
elem.remove(child)
|
|
63
|
+
if elem.text != text:
|
|
64
|
+
self.msg(f"! updating text ({elem.text} -> {text})")
|
|
65
|
+
elem.text = text
|
|
66
|
+
|
|
67
|
+
def _fixupTextElement(self, elem: inkex.TextElement) -> None:
|
|
68
|
+
parent = elem.getparent()
|
|
69
|
+
plabel = parent.label
|
|
70
|
+
if plabel is None:
|
|
71
|
+
self.msg(f"skipping unknown text (id={elem.get_id()}, label={elem.label})")
|
|
72
|
+
return
|
|
73
|
+
self.msg(f"fixing text (id={elem.get_id()}, label={elem.label})")
|
|
74
|
+
xs = list(elem)
|
|
75
|
+
if xs == []:
|
|
76
|
+
t = elem.get_text()
|
|
77
|
+
if t is not None:
|
|
78
|
+
e = inkex.Tspan()
|
|
79
|
+
e.text = t
|
|
80
|
+
elem.append(e)
|
|
81
|
+
for i, child in enumerate(xs):
|
|
82
|
+
self.msg(
|
|
83
|
+
f"fixing text (id={elem.get_id()}, label={elem.label}) child={child}"
|
|
84
|
+
)
|
|
85
|
+
if not isTspan(child):
|
|
86
|
+
# XXX msg
|
|
87
|
+
self.msg("! not tspan!")
|
|
88
|
+
elem.remove(child)
|
|
89
|
+
continue
|
|
90
|
+
self._fixupTspan(child, i)
|
|
91
|
+
elem.text = None
|
|
92
|
+
|
|
93
|
+
def effect(self):
|
|
94
|
+
xs = self.svg.xpath('//*[name()="text"]')
|
|
95
|
+
if isinstance(xs, list):
|
|
96
|
+
for elem in list(xs):
|
|
97
|
+
if not isTextElement(elem):
|
|
98
|
+
continue
|
|
99
|
+
self._fixupTextElement(elem)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def trim(s: str) -> str:
|
|
103
|
+
s = re.sub(r"^ +", "", s)
|
|
104
|
+
s = re.sub(r" +$", "", s)
|
|
105
|
+
s = re.sub(r" +", " ", s)
|
|
106
|
+
return s
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
FixupTexts().run()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
|
3
|
+
<name>Fixup: Tree: Fixup tree</name>
|
|
4
|
+
<id>daijimaps.fixup_tree</id>
|
|
5
|
+
<label>Fixup: Tree: Fixup tree (group/layer).</label>
|
|
6
|
+
<effect needs-live-preview="false">
|
|
7
|
+
<object-type>all</object-type>
|
|
8
|
+
<effects-menu>
|
|
9
|
+
<submenu name="Daiji Maps"/>
|
|
10
|
+
</effects-menu>
|
|
11
|
+
</effect>
|
|
12
|
+
<script>
|
|
13
|
+
<command location="inx" interpreter="python">fixup_tree.py</command>
|
|
14
|
+
</script>
|
|
15
|
+
</inkscape-extension>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import inkex
|
|
2
|
+
|
|
3
|
+
import daijimaps.address_tree
|
|
4
|
+
import daijimaps.map_layer
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class FixupTree(daijimaps.address_tree.AddressTree):
|
|
8
|
+
def _post_layers(self):
|
|
9
|
+
for layer in self._layers:
|
|
10
|
+
daijimaps.map_layer.fixup_tree_layer(layer)
|
|
11
|
+
for child in list(layer):
|
|
12
|
+
if isinstance(child, inkex.Group) and child.label == "Content":
|
|
13
|
+
daijimaps.map_layer.fixup_tree_layer_content(child)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
FixupTree().run()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
|
3
|
+
<name>Flatten Transform</name>
|
|
4
|
+
<id>daijimaps.flatten_transform</id>
|
|
5
|
+
<label>Flatteen tree by merging transforms into leaves.</label>
|
|
6
|
+
<effect needs-live-preview="false">
|
|
7
|
+
<object-type>all</object-type>
|
|
8
|
+
<effects-menu>
|
|
9
|
+
<submenu name="Daiji Maps">
|
|
10
|
+
<submenu name="Fixup" />
|
|
11
|
+
</submenu>
|
|
12
|
+
</effects-menu>
|
|
13
|
+
</effect>
|
|
14
|
+
<script>
|
|
15
|
+
<command location="inx" interpreter="python">flatten_transform.py</command>
|
|
16
|
+
</script>
|
|
17
|
+
</inkscape-extension>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
import math
|
|
5
|
+
|
|
6
|
+
import inkex
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _is_translate(t: inkex.Transform):
|
|
10
|
+
return not (math.isclose(t.e, 0) and math.isclose(t.f, 0))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _is_translate_only(t: inkex.Transform):
|
|
14
|
+
p = [t.a, t.b, t.c, t.d]
|
|
15
|
+
q = [1, 0, 0, 1]
|
|
16
|
+
is_unit = all(map(math.isclose, p, q))
|
|
17
|
+
return is_unit and _is_translate(t)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _translate_x_y(node, t, ax="x", ay="y"):
|
|
21
|
+
x = node.get(ax) or 0
|
|
22
|
+
y = node.get(ay) or 0
|
|
23
|
+
node.set(ax, f"{float(x) + t.e:.3g}")
|
|
24
|
+
node.set(ay, f"{float(y) + t.f:.3g}")
|
|
25
|
+
if node.transform:
|
|
26
|
+
del node.attrib["transform"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _translate_cx_cy(node, t):
|
|
30
|
+
_translate_x_y(node, t, "cx", "cy")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class FlattenTransform(inkex.EffectExtension):
|
|
34
|
+
def _flatten_translate(self, node):
|
|
35
|
+
t = node.transform
|
|
36
|
+
translate_only = _is_translate_only(t)
|
|
37
|
+
if translate_only:
|
|
38
|
+
if isinstance(node, inkex.Use) or isinstance(node, inkex.Rectangle):
|
|
39
|
+
_translate_x_y(node, t)
|
|
40
|
+
elif isinstance(node, inkex.Circle) or isinstance(node, inkex.Ellipse):
|
|
41
|
+
_translate_cx_cy(node, t)
|
|
42
|
+
elif isinstance(node, inkex.TextElement):
|
|
43
|
+
_translate_x_y(node, t)
|
|
44
|
+
for child in list(node):
|
|
45
|
+
if isinstance(child, inkex.Tspan) and translate_only:
|
|
46
|
+
_translate_x_y(child, t)
|
|
47
|
+
if isinstance(node, inkex.Group):
|
|
48
|
+
for child in list(node):
|
|
49
|
+
self._flatten_translate(child)
|
|
50
|
+
|
|
51
|
+
def _flatten_Transform(self, node):
|
|
52
|
+
node.bake_transforms_recursively()
|
|
53
|
+
return True
|
|
54
|
+
|
|
55
|
+
def effect(self):
|
|
56
|
+
if self.svg.selection:
|
|
57
|
+
for node in self.svg.selection.values():
|
|
58
|
+
self._flatten_Transform(node)
|
|
59
|
+
self._flatten_translate(node)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
if __name__ == "__main__":
|
|
63
|
+
FlattenTransform().run()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
|
3
|
+
<name>Address: Import: Import labels</name>
|
|
4
|
+
<id>daijimaps.import_labels</id>
|
|
5
|
+
<label>Address: Import: Import labels.</label>
|
|
6
|
+
<param name="tab" type="notebook">
|
|
7
|
+
<page name="Options" gui-text="Options">
|
|
8
|
+
<param name="floor" type="string" gui-text="Target floor (regular expression)">.</param>
|
|
9
|
+
</page>
|
|
10
|
+
</param>
|
|
11
|
+
<effect needs-live-preview="false">
|
|
12
|
+
<object-type>all</object-type>
|
|
13
|
+
<effects-menu>
|
|
14
|
+
<submenu name="Daiji Maps"/>
|
|
15
|
+
</effects-menu>
|
|
16
|
+
</effect>
|
|
17
|
+
<script>
|
|
18
|
+
<command location="inx" interpreter="python">import_labels.py</command>
|
|
19
|
+
</script>
|
|
20
|
+
</inkscape-extension>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
import inkex
|
|
5
|
+
|
|
6
|
+
import daijimaps
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ImportLabels(daijimaps.GenerateAddresses):
|
|
10
|
+
_group_label = "(Unresolved Labels)"
|
|
11
|
+
_font_size = 5
|
|
12
|
+
|
|
13
|
+
def _get_labels_txt(self, layer_name: str) -> str | None:
|
|
14
|
+
p = self._get_path(layer_name=layer_name, prefix="labels", suffix="txt")
|
|
15
|
+
if p is not None:
|
|
16
|
+
return p
|
|
17
|
+
return self._get_path(layer_name=layer_name, prefix="names", suffix="txt")
|
|
18
|
+
|
|
19
|
+
def _draw_labels(self, aparent, text):
|
|
20
|
+
g = daijimaps.draw_label(text, self._font_size)
|
|
21
|
+
aparent.append(g)
|
|
22
|
+
|
|
23
|
+
def _generate_addresses(self, layer, layer_name: str):
|
|
24
|
+
self.msg("=== import labels: _generate_addresses")
|
|
25
|
+
|
|
26
|
+
aparent = self._find_or_make_group(layer, self._group_label)
|
|
27
|
+
|
|
28
|
+
path = self._get_labels_txt(layer_name)
|
|
29
|
+
if path is None:
|
|
30
|
+
self.msg("labels.txt not found!")
|
|
31
|
+
return
|
|
32
|
+
with open(path, "r", encoding="utf-8") as fh:
|
|
33
|
+
texts = [text for text in [line.strip() for line in fh.readlines()]]
|
|
34
|
+
for text in texts:
|
|
35
|
+
self._draw_labels(aparent, text)
|
|
36
|
+
|
|
37
|
+
layer.append(aparent)
|
|
38
|
+
|
|
39
|
+
def _post_process_addresses(self, node: inkex.Group) -> None:
|
|
40
|
+
super()._post_process_addresses(node)
|
|
41
|
+
self.msg("=== import labels: _post_process_addresses")
|
|
42
|
+
for addresses in list(node):
|
|
43
|
+
if not isinstance(addresses, inkex.Group):
|
|
44
|
+
continue
|
|
45
|
+
label = addresses.label
|
|
46
|
+
if label is not None and label == self._group_label:
|
|
47
|
+
self._sort_children(addresses)
|
|
48
|
+
# return super()._post_process_addresses(layer)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
ImportLabels().run()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
|
3
|
+
<name>Address: Import: Import shops</name>
|
|
4
|
+
<id>daijimaps.import_shops</id>
|
|
5
|
+
<label>Address: Import: Import shop names.</label>
|
|
6
|
+
<param name="tab" type="notebook">
|
|
7
|
+
<page name="Options" gui-text="Options">
|
|
8
|
+
<param name="floor" type="string" gui-text="Target floor (regular expression)">.</param>
|
|
9
|
+
</page>
|
|
10
|
+
</param>
|
|
11
|
+
<effect needs-live-preview="false">
|
|
12
|
+
<object-type>all</object-type>
|
|
13
|
+
<effects-menu>
|
|
14
|
+
<submenu name="Daiji Maps"/>
|
|
15
|
+
</effects-menu>
|
|
16
|
+
</effect>
|
|
17
|
+
<script>
|
|
18
|
+
<command location="inx" interpreter="python">import_shops.py</command>
|
|
19
|
+
</script>
|
|
20
|
+
</inkscape-extension>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
import inkex
|
|
5
|
+
|
|
6
|
+
import daijimaps
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ImportShops(daijimaps.GenerateAddresses):
|
|
10
|
+
_group_label = "(Unresolved Names)"
|
|
11
|
+
|
|
12
|
+
def _get_shops_txt(self, layer_name: str):
|
|
13
|
+
p = self._get_path(layer_name, "names", "txt")
|
|
14
|
+
if p is None:
|
|
15
|
+
p = self._get_path(layer_name, "shops", "txt")
|
|
16
|
+
return p
|
|
17
|
+
|
|
18
|
+
def _draw_shop_names(self, aparent, text):
|
|
19
|
+
g = daijimaps.draw_name(text)
|
|
20
|
+
aparent.append(g)
|
|
21
|
+
|
|
22
|
+
def _generate_addresses(self, layer, layer_name):
|
|
23
|
+
self.msg("=== import shops: _generate_addresses")
|
|
24
|
+
|
|
25
|
+
aparent = self._find_or_make_group(layer, self._group_label)
|
|
26
|
+
|
|
27
|
+
path = self._get_shops_txt(layer_name)
|
|
28
|
+
if path is None:
|
|
29
|
+
self.msg("shops.txt not found!")
|
|
30
|
+
return
|
|
31
|
+
with open(path, "r", encoding="utf-8") as fh:
|
|
32
|
+
texts = [text for text in [line.strip() for line in fh.readlines()]]
|
|
33
|
+
for text in texts:
|
|
34
|
+
self._draw_shop_names(aparent, text)
|
|
35
|
+
|
|
36
|
+
layer.append(aparent)
|
|
37
|
+
|
|
38
|
+
def _post_process_addresses(self, node) -> None:
|
|
39
|
+
super()._post_process_addresses(node)
|
|
40
|
+
self.msg("=== import shops: _post_process_addresses")
|
|
41
|
+
for addresses in list(node):
|
|
42
|
+
if "label" in addresses and addresses.label == self._group_label:
|
|
43
|
+
self._sort_children(addresses)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
ImportShops().run()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
DIR=$( inkscape --user-data-directory )/extensions
|
|
2
|
+
|
|
3
|
+
#rm "${DIR}"/*.inx "${DIR}"/*.py
|
|
4
|
+
cp -p *.inx *.py "${DIR}"
|
|
5
|
+
|
|
6
|
+
subdirs='
|
|
7
|
+
daijimaps
|
|
8
|
+
'
|
|
9
|
+
|
|
10
|
+
for subdir in ${subdirs}; do
|
|
11
|
+
mkdir -p "${DIR}/${subdir}"
|
|
12
|
+
#rm "${DIR}/${subdir}/"*.py
|
|
13
|
+
cp -p ${subdir}/*.py "${DIR}/${subdir}"
|
|
14
|
+
done
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
|
3
|
+
<name>Address: Load: Load shops</name>
|
|
4
|
+
<id>daijimaps.load_shops</id>
|
|
5
|
+
<label>Address: Load: Load shop names to addresses.</label>
|
|
6
|
+
<param name="tab" type="notebook">
|
|
7
|
+
<page name="Options" gui-text="Options">
|
|
8
|
+
<param name="floor" type="string" gui-text="Target floor (regular expression)">.</param>
|
|
9
|
+
</page>
|
|
10
|
+
</param>
|
|
11
|
+
<effect needs-live-preview="false">
|
|
12
|
+
<object-type>all</object-type>
|
|
13
|
+
<effects-menu>
|
|
14
|
+
<submenu name="Daiji Maps"/>
|
|
15
|
+
</effects-menu>
|
|
16
|
+
</effect>
|
|
17
|
+
<script>
|
|
18
|
+
<command location="inx" interpreter="python">load_shops.py</command>
|
|
19
|
+
</script>
|
|
20
|
+
</inkscape-extension>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
import inkex
|
|
7
|
+
|
|
8
|
+
import daijimaps
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class LoadShops(daijimaps.ResolveNames):
|
|
12
|
+
def _move_resolved_name(
|
|
13
|
+
self,
|
|
14
|
+
names_group: inkex.Group,
|
|
15
|
+
unresolved_names_group: inkex.Group,
|
|
16
|
+
astr: str,
|
|
17
|
+
name: str,
|
|
18
|
+
) -> None:
|
|
19
|
+
label = f"{name} @ {astr}"
|
|
20
|
+
((x, y), _bb, _href) = self._addresses[astr]
|
|
21
|
+
daijimaps.move_name(unresolved_names_group, names_group, name, label, x, y)
|
|
22
|
+
|
|
23
|
+
def _move_resolved_names(
|
|
24
|
+
self, names_group: inkex.Group, unresolved_names_group: inkex.Group
|
|
25
|
+
) -> None:
|
|
26
|
+
self.msg(f"drawing result {self._tmp_resolved_names}")
|
|
27
|
+
for name, astrs in self._tmp_resolved_names.items():
|
|
28
|
+
for astr in astrs:
|
|
29
|
+
self._move_resolved_name(
|
|
30
|
+
names_group, unresolved_names_group, astr, name
|
|
31
|
+
)
|
|
32
|
+
self._sort_children(names_group)
|
|
33
|
+
|
|
34
|
+
def _load_resolved_names(self) -> None:
|
|
35
|
+
with open(self._layerPaths["floorsNames"], mode="r", encoding="utf-8") as f:
|
|
36
|
+
j = json.load(f)
|
|
37
|
+
if not isinstance(j, dict):
|
|
38
|
+
self.msg("invalid floorsNames.json")
|
|
39
|
+
return
|
|
40
|
+
for name in j:
|
|
41
|
+
if not isinstance(name, str):
|
|
42
|
+
self.msg("invalid floorsNames.json: name is not string")
|
|
43
|
+
return
|
|
44
|
+
astrs = j[name]
|
|
45
|
+
if not isinstance(astrs, list):
|
|
46
|
+
self.msg("invalid floorsNames.json: astrs is not list")
|
|
47
|
+
return
|
|
48
|
+
for astr in astrs:
|
|
49
|
+
if not isinstance(astr, str):
|
|
50
|
+
self.msg(
|
|
51
|
+
"invalid floorsNames.json: astr is not string (name={name})"
|
|
52
|
+
)
|
|
53
|
+
return
|
|
54
|
+
self._tmp_resolved_names = j
|
|
55
|
+
|
|
56
|
+
def _process_addresses(self, node) -> None:
|
|
57
|
+
self.msg("=== load: start")
|
|
58
|
+
|
|
59
|
+
names_group = self._prepare_names_group(node)
|
|
60
|
+
unresolved_names_group = self._prepare_unresolved_names_group(node)
|
|
61
|
+
|
|
62
|
+
if names_group is None:
|
|
63
|
+
self.msg("(Names) group does not exist!")
|
|
64
|
+
return
|
|
65
|
+
if unresolved_names_group is None:
|
|
66
|
+
self.msg("(Unresolved Names) group does not exist!")
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
# load names!
|
|
70
|
+
self._load_resolved_names()
|
|
71
|
+
|
|
72
|
+
self._move_resolved_names(names_group, unresolved_names_group)
|
|
73
|
+
|
|
74
|
+
self._read_resolved_names(names_group)
|
|
75
|
+
self._save_resolved_names()
|
|
76
|
+
self._read_unresolved_names(unresolved_names_group)
|
|
77
|
+
self._save_unresolved_names()
|
|
78
|
+
|
|
79
|
+
self._save_floors_addresses()
|
|
80
|
+
self._save_floors_names()
|
|
81
|
+
|
|
82
|
+
self.msg("=== load: end")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if __name__ == "__main__":
|
|
86
|
+
LoadShops().run()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
|
3
|
+
<name>Address: Renumber: Renumber group</name>
|
|
4
|
+
<id>daijimaps.renumber_group</id>
|
|
5
|
+
<label>Renumber groups under the selected group.</label>
|
|
6
|
+
<effect needs-live-preview="false">
|
|
7
|
+
<object-type>all</object-type>
|
|
8
|
+
<effects-menu>
|
|
9
|
+
<submenu name="Daiji Maps"/>
|
|
10
|
+
</effects-menu>
|
|
11
|
+
</effect>
|
|
12
|
+
<script>
|
|
13
|
+
<command location="inx" interpreter="python">renumber_group.py</command>
|
|
14
|
+
</script>
|
|
15
|
+
</inkscape-extension>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
import inkex
|
|
5
|
+
|
|
6
|
+
from daijimaps import renumber_group
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RenumberGroup(inkex.EffectExtension):
|
|
10
|
+
def effect(self):
|
|
11
|
+
if self.svg.selection:
|
|
12
|
+
for node in self.svg.selection.values():
|
|
13
|
+
renumber_group(node)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
RenumberGroup().run()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
|
3
|
+
<name>Address: Resolve: Resolve labels</name>
|
|
4
|
+
<id>daijimaps.resolve_labels</id>
|
|
5
|
+
<label>Address: Resolve: Resolve labels to names.</label>
|
|
6
|
+
<param name="tab" type="notebook">
|
|
7
|
+
<page name="Options" gui-text="Options">
|
|
8
|
+
<param name="floor" type="string" gui-text="Target floor (regular expression)">.</param>
|
|
9
|
+
</page>
|
|
10
|
+
</param>
|
|
11
|
+
<effect needs-live-preview="false">
|
|
12
|
+
<object-type>all</object-type>
|
|
13
|
+
<effects-menu>
|
|
14
|
+
<submenu name="Daiji Maps"/>
|
|
15
|
+
</effects-menu>
|
|
16
|
+
</effect>
|
|
17
|
+
<script>
|
|
18
|
+
<command location="inx" interpreter="python">resolve_labels.py</command>
|
|
19
|
+
</script>
|
|
20
|
+
</inkscape-extension>
|