From e0286b2f51aa7a6e43db0d030b27c14eeeb922e5 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Mon, 25 May 2020 19:19:16 +0200 Subject: [PATCH] Implement first proof of concept --- src/example1.yml | 50 +++++++++++++++++++++++++++++++++++++++++++++ src/yaml2wireviz.py | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 src/example1.yml create mode 100644 src/yaml2wireviz.py diff --git a/src/example1.yml b/src/example1.yml new file mode 100644 index 0000000..f0c0270 --- /dev/null +++ b/src/example1.yml @@ -0,0 +1,50 @@ +nodes: + X1: + type: D-Sub + gender: female + pinout: [DCD,RX,TX,DTR,GND,DSR,RTS,CTS,RI] + random: yes + X2: + type: Molex KK 254 + gender: female + pinout: [GND, RX, TX, N/C, OUT, IN] + +wires: + W1: + mm2: 0.25 + length: 0.2 + color_code: DIN + num_wires: 3 + shield: true + +connections: + - + items: [X1,W1,X2] + X1: 5 # [5,2,3] + W1: 1 # [1,2,3] + X2: 1 # [1,3,2] + - + items: [X1,W1,X2] + X1: 2 # [5,2,3] + W1: 2 # [1,2,3] + X2: 3 # [1,3,2] + - + items: [X1,W1,X2] + X1: 3 # [5,2,3] + W1: 3 # [1,2,3] + X2: 2 # [1,3,2] + - + items: [X1,W1,X2] + X1: 5 + W1: s + X2: ~ + +options: + # for connectors + show_connector_name: true + show_num_pins: true + # for wires + show_wire_name: true + show_num_wires: true + show_wire_pinout: true + show awg_equiv: true diff --git a/src/yaml2wireviz.py b/src/yaml2wireviz.py new file mode 100644 index 0000000..292cab8 --- /dev/null +++ b/src/yaml2wireviz.py @@ -0,0 +1,43 @@ +import yaml +import wireviz + +filename = 'example1.yml' + +with open(filename, 'r') as stream: + try: + input = yaml.safe_load(stream) + except yaml.YAMLError as exc: + print(exc) + +# print(input) + +sections = ('options','nodes','wires') + +for s in sections: + print(s + ':') + for k in input[s]: + print(k + ': ', end='') + print(input[s][k]) + print() + +print('connections:') +for s in input['connections']: + print(s) +print() + +h = wireviz.Harness() +for k in input['nodes']: + n = input['nodes'][k] + h.add_node(k, type=n['type'], gender=n['gender'], pinout=n['pinout']) + +for k in input['wires']: + c = input['wires'][k] + h.add_cable(k, mm2=c['mm2'], length=c['length'], num_wires=c['num_wires'], color_code=c['color_code'], shield=c['shield']) + +for o in input['connections']: + c1 = o['items'][0] + w = o['items'][1] + c2 = o['items'][2] + h.connect(w,c1,o[c1],o[w],c2,o[c2]) + +h.output(filename='output', format=('png',), view=False)