forked from ubitux/cura-dagoma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qualities.py
97 lines (80 loc) · 3.33 KB
/
qualities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
import sys
from xml.etree import ElementTree as ET
from materials import extract_materials
from definition import extract_definition
def _write_ini(out, data):
for section_name, section_data in data.items():
out.write('[%s]\n' % section_name)
for kv in section_data.items():
out.write('%s = %s\n' % kv)
out.write('\n')
def extract_qualities(xmlroot):
qualities_data = {}
definition_data = extract_definition(xmlroot)
qualities = xmlroot.find('Bloc_Precision')
for quality in qualities.findall('Precision'):
name = quality.attrib['name']
name_id = name.split(maxsplit=1)[0].lower()
assert name_id not in ('rapide', 'fin') # french profiles not supported
name_remap = {'standard': 'normal', 'thin': 'high'}
name_id = name_remap.get(name_id, name_id)
fields_map = {
'speed_print': 'print_speed',
'speed_travel': 'travel_speed',
'speed_infill': 'infill_speed',
}
values_fields = (
('layer_height', float),
#solid_layer_thickness -> TODO
('wall_thickness', float),
('speed_print', int), # print_speed
#temp_preci -> TODO
('speed_travel', int), # travel_speed
#bottom_layer_speed -> TODO
('speed_infill', int), # infill_speed
#inset0_speed -> TODO
#insetx_speed -> TODO
)
values = {}
for field, field_type in values_fields:
dagoma_field = fields_map.get(field, field)
values[field] = field_type(quality.find(dagoma_field).text)
qualities_data[name_id] = {
'general': {
'version': 2,
'name': name,
'definition': definition_data['id'],
},
'metadata': {
'type': 'quality',
'quality_type': name_id,
},
'values': values,
}
return qualities_data
def _write_qualities(xml_filename, out_dir):
xmlroot = ET.parse(xml_filename)
qualities_data = extract_qualities(xmlroot)
materials_data = extract_materials(xmlroot)
for material_id, material_data in materials_data.items():
if 'flex' in material_id:
cfgs = ['flexible']
elif 'wood' in material_id:
cfgs = ['wood']
else:
cfgs = ['fast', 'normal', 'high']
for quality_id in cfgs:
quality_data = qualities_data[quality_id].copy()
quality_data['metadata']['material'] = material_id
printer = quality_data['general']['definition'].replace('dagoma_', '')
filename = '%s_%s_%s.inst.cfg' % (printer, material_id, quality_id)
filename = os.path.join(out_dir, filename)
print(filename)
outf = open(filename, 'w')
_write_ini(outf, quality_data)
if __name__ == '__main__':
if len(sys.argv) != 3:
print('Usage: %s <xml_config.xml> <out_dir>' % sys.argv[0])
sys.exit(0)
_write_qualities(*sys.argv[1:])