Implement first proof of concept
This commit is contained in:
parent
6b2da96865
commit
e0286b2f51
50
src/example1.yml
Normal file
50
src/example1.yml
Normal file
@ -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
|
||||||
43
src/yaml2wireviz.py
Normal file
43
src/yaml2wireviz.py
Normal file
@ -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)
|
||||||
Loading…
x
Reference in New Issue
Block a user