summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/utils.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-01-23 01:19:30 +0100
committerjaseg <git@jaseg.de>2022-01-23 01:19:30 +0100
commitdeb2bb2bbfc13e6dce8adf493221a4fe4929a344 (patch)
treeef1356afa3036f231bc460dacf186d035646c443 /gerbonara/gerber/utils.py
parent07d279f89faefde4793ae2de4d3a629dc87da63e (diff)
downloadgerbonara-deb2bb2bbfc13e6dce8adf493221a4fe4929a344.tar.gz
gerbonara-deb2bb2bbfc13e6dce8adf493221a4fe4929a344.tar.bz2
gerbonara-deb2bb2bbfc13e6dce8adf493221a4fe4929a344.zip
Squash some more bugs
Diffstat (limited to 'gerbonara/gerber/utils.py')
-rw-r--r--gerbonara/gerber/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/gerbonara/gerber/utils.py b/gerbonara/gerber/utils.py
index 100e968..e17b99b 100644
--- a/gerbonara/gerber/utils.py
+++ b/gerbonara/gerber/utils.py
@@ -25,6 +25,7 @@ files.
import os
import re
+import textwrap
from enum import Enum
from math import radians, sin, cos, sqrt, atan2, pi
@@ -194,4 +195,19 @@ def sq_distance(point1, point2):
diff2 = point1[1] - point2[1]
return diff1 * diff1 + diff2 * diff2
+class Tag:
+ def __init__(self, name, children=None, root=False, **attrs):
+ self.name, self.attrs = name, attrs
+ self.children = children or []
+ self.root = root
+
+ def __str__(self):
+ prefix = '<?xml version="1.0" encoding="utf-8"?>\n' if self.root else ''
+ opening = ' '.join([self.name] + [f'{key.replace("__", ":")}="{value}"' for key, value in self.attrs.items()])
+ if self.children:
+ children = '\n'.join(textwrap.indent(str(c), ' ') for c in self.children)
+ return f'{prefix}<{opening}>\n{children}\n</{self.name}>'
+ else:
+ return f'{prefix}<{opening}/>'
+