-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig.py
More file actions
298 lines (275 loc) · 11.4 KB
/
Copy pathconfig.py
File metadata and controls
298 lines (275 loc) · 11.4 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
"""
Configuration management for Machine Shop Suite - 3D Printing Quote Engine
"""
import os
import json
from pathlib import Path
class Config:
"""Application configuration with support for JSON file storage"""
# Default PrusaSlicer path (overridden by environment variable or config file)
DEFAULT_SLICER_PATH = "prusa-slicer" # Assumes prusa-slicer is in PATH
def __init__(self, config_file='config.json'):
"""Initialize configuration from file or defaults"""
self.config_file = config_file
self.config_data = self._load_config()
def _load_config(self):
"""Load configuration from JSON file or return defaults"""
if os.path.exists(self.config_file):
try:
with open(self.config_file, 'r') as f:
return json.load(f)
except Exception as e:
print(f"Error loading config file: {e}")
return self._default_config()
return self._default_config()
def _default_config(self):
"""Return default configuration"""
return {
"application": {
"name": "Machine Shop Suite",
"version": "1.0.0",
"description": "3D Printing Quote Engine"
},
"slicer": {
"path": os.getenv("PRUSA_SLICER_PATH", self.DEFAULT_SLICER_PATH),
"timeout_seconds": 300
},
"materials": {
"pla": {
"name": "PLA (Polylactic Acid)",
"description": "Easy to print, biodegradable, good for prototypes",
"density_g_cm3": 1.24,
"price_per_kg": 800,
"per_gram_price": 1.0,
"bed_temp": 55,
"extruder_temp": 215,
"perimeter_speed": 100,
"infill_speed": 180,
"solid_infill_speed": 160,
"colors": ["White", "Black", "Red", "Blue", "Green", "Yellow", "Orange", "Gray"]
},
"abs": {
"name": "ABS (Acrylonitrile Butadiene Styrene)",
"description": "Strong and durable, heat resistant, good for functional parts",
"density_g_cm3": 1.04,
"price_per_kg": 1000,
"per_gram_price": 1.2,
"bed_temp": 90,
"extruder_temp": 245,
"perimeter_speed": 80,
"infill_speed": 160,
"solid_infill_speed": 140,
"colors": ["White", "Black", "Red", "Blue", "Natural"]
},
"petg": {
"name": "PETG (Polyethylene Terephthalate Glycol)",
"description": "Strong, flexible, chemical resistant, food-safe option",
"density_g_cm3": 1.27,
"price_per_kg": 1000,
"per_gram_price": 1.2,
"bed_temp": 70,
"extruder_temp": 240,
"perimeter_speed": 70,
"infill_speed": 150,
"solid_infill_speed": 120,
"colors": ["Clear", "White", "Black", "Blue", "Red"]
},
"tpu": {
"name": "TPU (Thermoplastic Polyurethane)",
"description": "Flexible and elastic, excellent for grips and cushioning",
"density_g_cm3": 1.21,
"price_per_kg": 1500,
"per_gram_price": 2.0,
"bed_temp": 60,
"extruder_temp": 230,
"perimeter_speed": 30,
"infill_speed": 40,
"solid_infill_speed": 35,
"colors": ["Black", "White", "Red", "Blue", "Clear"]
},
"nylon": {
"name": "Nylon (Polyamide)",
"description": "Very strong and durable, excellent layer adhesion",
"density_g_cm3": 1.14,
"price_per_kg": 1800,
"per_gram_price": 2.5,
"bed_temp": 80,
"extruder_temp": 250,
"perimeter_speed": 60,
"infill_speed": 100,
"solid_infill_speed": 80,
"colors": ["Natural", "Black", "White"]
}
},
"print_quality": {
"draft": {
"name": "Draft (Fast)",
"layer_height": 0.3,
"description": "Fastest print, visible layers, good for prototypes"
},
"standard": {
"name": "Standard (Balanced)",
"layer_height": 0.2,
"description": "Good balance of speed and quality"
},
"fine": {
"name": "Fine (Detailed)",
"layer_height": 0.15,
"description": "Higher detail, longer print time"
},
"ultra_fine": {
"name": "Ultra Fine (Maximum Detail)",
"layer_height": 0.1,
"description": "Best quality, slowest print, minimal layer lines"
}
},
"infill_options": {
"min_percentage": 5,
"max_percentage": 100,
"default_percentage": 20,
"recommended": {
"prototype": 10,
"standard": 20,
"functional": 40,
"structural": 80,
"solid": 100
}
},
"pricing": {
"pricing_mode": "custom",
"base_cost": 150,
"electricity_rate_per_kwh": 7,
"printer_power_watts": 1000,
"depreciation_per_hour": 50,
"other_costs_per_print": 20,
"gst_rate": 0.18,
"currency": "INR",
"currency_symbol": "₹"
},
"printers": {
"prusa_mk3s": {
"name": "Prusa i3 MK3S+",
"description": "Original Prusa i3 MK3S+ FDM printer",
"bed_size_mm": [250, 210, 210],
"nozzle_diameter_mm": 0.4,
"max_print_speed_mm_s": 200,
"markup_multiplier": 1.3,
"enabled": True
},
"ender3_v2": {
"name": "Creality Ender 3 V2",
"description": "Creality Ender 3 V2 budget FDM printer",
"bed_size_mm": [220, 220, 250],
"nozzle_diameter_mm": 0.4,
"max_print_speed_mm_s": 180,
"markup_multiplier": 1.25,
"enabled": True
},
"bambu_x1": {
"name": "Bambu Lab X1 Carbon",
"description": "Bambu Lab X1 Carbon high-speed printer",
"bed_size_mm": [256, 256, 256],
"nozzle_diameter_mm": 0.4,
"max_print_speed_mm_s": 500,
"markup_multiplier": 1.4,
"enabled": True
}
},
"post_processing": {
"sanding": {
"name": "Sanding & Smoothing",
"description": "Manual sanding for smooth surface finish",
"price": 500,
"enabled": True
},
"painting": {
"name": "Painting",
"description": "Professional spray painting with primer and topcoat",
"price": 1500,
"enabled": True
},
"polishing": {
"name": "Polishing",
"description": "High-gloss polishing for aesthetic finish",
"price": 800,
"enabled": True
},
"threading": {
"name": "Threading/Tapping",
"description": "Adding threads to holes for screws/bolts",
"price": 300,
"enabled": True
}
},
"file_settings": {
"max_file_size_mb": 100,
"allowed_extensions": ["stl"],
"upload_timeout_seconds": 300
}
}
def save(self):
"""Save current configuration to JSON file"""
try:
with open(self.config_file, 'w') as f:
json.dump(self.config_data, f, indent=2)
return True
except Exception as e:
print(f"Error saving config: {e}")
return False
def get(self, *keys, default=None):
"""Get nested configuration value using dot notation or keys"""
data = self.config_data
for key in keys:
if isinstance(data, dict) and key in data:
data = data[key]
else:
return default
return data
def set(self, value, *keys):
"""Set nested configuration value"""
data = self.config_data
for key in keys[:-1]:
if key not in data:
data[key] = {}
data = data[key]
data[keys[-1]] = value
def get_materials(self):
"""Get all available materials"""
return self.config_data.get('materials', {})
def get_material(self, material_key):
"""Get specific material configuration"""
return self.config_data.get('materials', {}).get(material_key)
def get_print_qualities(self):
"""Get all print quality options"""
return self.config_data.get('print_quality', {})
def get_pricing_config(self):
"""Get pricing configuration"""
return self.config_data.get('pricing', {})
def get_pricing_mode(self):
"""Get pricing mode (custom or per_gram)"""
return self.config_data.get('pricing', {}).get('pricing_mode', 'custom')
def get_slicer_path(self):
"""Get PrusaSlicer executable path"""
return self.config_data.get('slicer', {}).get('path', self.DEFAULT_SLICER_PATH)
def get_printers(self):
"""Get all available printers"""
return self.config_data.get('printers', {})
def get_enabled_printers(self):
"""Get only enabled printers"""
all_printers = self.get_printers()
return {key: printer for key, printer in all_printers.items() if printer.get('enabled', True)}
def get_printer(self, printer_key):
"""Get specific printer configuration"""
return self.config_data.get('printers', {}).get(printer_key)
def get_post_processing_options(self):
"""Get all available post-processing options"""
return self.config_data.get('post_processing', {})
def get_enabled_post_processing(self):
"""Get only enabled post-processing options"""
all_options = self.get_post_processing_options()
return {key: option for key, option in all_options.items() if option.get('enabled', True)}
def get_post_processing(self, key):
"""Get specific post-processing option"""
return self.config_data.get('post_processing', {}).get(key)
# Global configuration instance
config = Config()