chiark / gitweb /
Preparing to split out nozzle sizes. Clearly I'm doing something wrong. This does...
[cura.git] / Cura / util / simpleModeSettings.py
1 from Cura.util.settings import lulzbot_mini_settings, \
2                 lulzbot_taz4_settings, \
3                 lulzbot_taz5_nozzle35_settings
4
5 import ConfigParser as configparser
6 from Cura.util import profile
7 from Cura.util import resources
8
9 class SimpleModeSettings(object):
10         # Set the Quickprint settings:
11         #
12         # Settings Format : Dictionary[machine_type] = machine_settings
13         #                                       Dictionary[None] = other_machine_settings
14         #
15         # Machine settings Format : List of setting dictionaries
16         # Setting dictionary Format: Dictionary['Material'] = material ini filename
17         #                                                        Dictionary['Profile'] = profile ini filename
18         #                                                        Dictionary['Options'] = list of other options ini filenames
19         #                                                        Dictionary['Ini'] = Ini filename to load from extra/ subdir
20         #                                                        Dictionary['Settings'] = Option settings
21         # Option settings format : List of tuples ('profile setting', 'value')
22         #                                                                                 ('profile setting', callable function)
23         # Example :
24         # settings['prusa_i3'] = [
25         #                                                       {'Material': '1_pla', 'Profile': '2_normal', 'Ini': 'normal_pla'},
26         #                                                       {'Material': '2_abs', 'Profile': '1_high', 'Ini': 'prusa_i3/high_abs'},
27         #                                                       {'Material': '1_pla', 'Options': ['brim', 'support'],
28         #                                                         'Settings': [('support', _('Everywhere')), ('platform_adhesion', 'Brim')]
29         #                                                       }
30         #                                               ]
31         #
32         #
33         # All the settings in the list of machine settings will be checked. For
34         # each of those settings, the list of options will be verified and only the
35         # settings in which all the options match will be applied.
36         # The 'Settings' key in the dictionary will contain the settings to apply.
37         # Those settings will be a a list a tuples of key:value in which the value
38         # can be a callable function for greater control
39         #
40         # For example, a Dictionary with only 'Settings' will always be applied
41         # while a setting with {'Brim':True} will only be applied if the printBrim
42         # option is enabled, and settings with {'MaterialABS':True, 'TypeHigh':False}
43         # will only be applied for Low and Normal quality prints in ABS
44
45         settings = {"lulzbot_mini": lulzbot_mini_settings,
46                                 "lulzbot_TAZ_4": lulzbot_taz4_settings,
47                                 "lulzbot_TAZ_5_nozzle35": lulzbot_taz5_nozzle35_settings,
48                                 None: {}}
49
50
51         @staticmethod
52         def getSimpleSettings(profile_setting, material_setting, other_settings):
53                 simple_settings = {}
54                 machine_type = profile.getMachineSetting('machine_type')
55                 if SimpleModeSettings.settings.has_key(machine_type):
56                         machine_settings = SimpleModeSettings.settings[machine_type]
57                 else:
58                         machine_settings = SimpleModeSettings.settings[None]
59
60                 for setting_dict in machine_settings:
61                         settings = setting_dict.get('Settings', None)
62                         ini = setting_dict.get('Ini', None)
63                         print_material = setting_dict.get('Material', None)
64                         print_profile = setting_dict.get('Profile', None)
65                         print_others = setting_dict.get('Options', None)
66                         # Check if the material/profile/other options match the settings
67                         if (print_material is None or print_material == material_setting) and \
68                            (print_profile is None or print_profile == profile_setting) and \
69                            (print_others is None or len(set(print_others)) == len(set(print_others).intersection(set(other_settings)))):
70                                 if settings:
71                                         for item in settings:
72                                                 if len(item) != 2 or not profile.isProfileSetting(item[0]):
73                                                         continue
74                                                 if hasattr(item[1], '__call__'):
75                                                         simple_settings[item[0]] = item[1]()
76                                                 else:
77                                                         simple_settings[item[0]] = item[1]
78                                 if ini:
79                                         ini_file = resources.getSimpleModeIniFiles('extra', ini + '.ini')
80                                         if len(ini_file) > 0:
81                                                 cp = configparser.ConfigParser()
82                                                 cp.read(ini_file[0])
83                                                 for setting in profile.settingsList:
84                                                         if setting.isProfile() or setting.isAlteration():
85                                                                 if cp.has_option('profile', setting.getName()):
86                                                                         simple_settings[setting.getName()] = cp.get('profile', setting.getName())
87
88                 return simple_settings