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