@@ -68,12 +68,17 @@ class CuraEngine:
|
||||
preset_path = os.path.join(presets_path, 'creality', 'presets', quality_preset)
|
||||
if os.path.exists(preset_path):
|
||||
config.read(preset_path)
|
||||
material_type = config.get('metadata', 'material', fallback=None)
|
||||
material_type_from_preset = config.get('metadata', 'material', fallback=None)
|
||||
variant_type = config.get('metadata', 'variant', fallback=None)
|
||||
quality_type = config.get('metadata', 'quality_type', fallback=None)
|
||||
|
||||
# Use explicit material if provided, otherwise fallback to preset's material
|
||||
material_type = kwargs.get('material_preset') or material_type_from_preset
|
||||
|
||||
if material_type:
|
||||
m_path = os.path.join(materials_path, f"{material_type}.inst.cfg")
|
||||
if not os.path.exists(m_path) and kwargs.get('material_preset'):
|
||||
m_path = os.path.join(materials_path, f"{kwargs.get('material_preset')}")
|
||||
if os.path.exists(m_path): inst_files_list.append(m_path)
|
||||
if variant_type:
|
||||
variant_d = variant_type.split("mm")[0]
|
||||
@@ -186,7 +191,7 @@ class CuraEngine:
|
||||
os.remove(tmp_def_path)
|
||||
except Exception as e:
|
||||
app.logger.error(f"Failed to delete temp JSON config {tmp_def_path}: {e}")
|
||||
|
||||
|
||||
def get_quality_presets(self, app):
|
||||
try:
|
||||
path = os.path.join(app.root_path, '..', 'print_config', 'cura_engine', 'quality', 'creality', 'presets')
|
||||
@@ -200,7 +205,7 @@ class CuraEngine:
|
||||
except:
|
||||
return []
|
||||
|
||||
def get_support_patterns(self):
|
||||
def get_support_patterns(self, app):
|
||||
return [
|
||||
{'id': 'tree', 'name': 'Tree'},
|
||||
{'id': 'lines', 'name': 'Lines'},
|
||||
@@ -213,3 +218,16 @@ class CuraEngine:
|
||||
{'id': 'honeycomb', 'name': 'Honeycomb'},
|
||||
{'id': 'octagon', 'name': 'Octagon'}
|
||||
]
|
||||
|
||||
def get_materials(self, app):
|
||||
try:
|
||||
path = os.path.join(app.root_path, '..', 'print_config', 'cura_engine', 'materials')
|
||||
if not os.path.exists(path): return []
|
||||
files = [f for f in os.listdir(path) if f.endswith('.inst.cfg')]
|
||||
materials = []
|
||||
for f in files:
|
||||
materials.append({'id': f, 'name': f.replace('.inst.cfg', '').replace('generic_', 'Generic ').replace('_', ' ').title()})
|
||||
materials.sort(key=lambda x: x['name'])
|
||||
return materials
|
||||
except:
|
||||
return []
|
||||
|
||||
@@ -30,10 +30,21 @@ class PrusaSlicerEngine:
|
||||
# Map quality, infill, supports to PrusaSlicer CLI arguments.
|
||||
# Example defaults, normally these would load from an .ini or be dynamically matched.
|
||||
quality_preset = kwargs.get('quality_preset')
|
||||
material_preset = kwargs.get('material_preset')
|
||||
infill_density = kwargs.get('infill_density')
|
||||
support_enable = kwargs.get('support_enable')
|
||||
support_pattern = kwargs.get('support_pattern')
|
||||
|
||||
if quality_preset:
|
||||
q_ini = os.path.join(app.root_path, '..', 'print_config', 'prusa_slicer', 'quality', f"{quality_preset}.ini")
|
||||
if os.path.exists(q_ini):
|
||||
command.extend(['--load', q_ini])
|
||||
|
||||
if material_preset:
|
||||
m_ini = os.path.join(app.root_path, '..', 'print_config', 'prusa_slicer', 'materials', f"{material_preset}.ini")
|
||||
if os.path.exists(m_ini):
|
||||
command.extend(['--load', m_ini])
|
||||
|
||||
if infill_density is not None:
|
||||
command.extend(["--fill-density", f"{infill_density}%"])
|
||||
|
||||
@@ -80,10 +91,29 @@ class PrusaSlicerEngine:
|
||||
})
|
||||
return quality_presets
|
||||
|
||||
def get_support_patterns(self):
|
||||
return [
|
||||
{'id': 'rectilinear', 'name': 'Rectilinear'},
|
||||
{'id': 'grid', 'name': 'Grid'},
|
||||
{'id': 'organic', 'name': 'Organic (Tree)'},
|
||||
{'id': 'snug', 'name': 'Snug'}
|
||||
]
|
||||
def get_support_patterns(self, app):
|
||||
all_files = [f for f in os.listdir(os.path.join(app.root_path, '..', 'print_config', 'prusa_slicer',"supports")) if f.endswith('.ini')]
|
||||
support_presets = []
|
||||
for file in all_files:
|
||||
with open(os.path.join(app.root_path, '..', 'print_config', 'prusa_slicer', "supports", file), 'r') as f:
|
||||
config = configparser.ConfigParser()
|
||||
config.read_file(f)
|
||||
if 'metadata' in config:
|
||||
support_presets.append({
|
||||
'id': file.replace('.ini', ''),
|
||||
'name': config['metadata'].get('show_name', file.replace('.ini', '').replace('_', ' '))
|
||||
})
|
||||
return support_presets
|
||||
|
||||
def get_materials(self, app):
|
||||
try:
|
||||
path = os.path.join(app.root_path, '..', 'print_config', 'prusa_slicer', 'materials')
|
||||
if not os.path.exists(path): return []
|
||||
files = [f for f in os.listdir(path) if f.endswith('.ini')]
|
||||
materials = []
|
||||
for f in files:
|
||||
materials.append({'id': f.replace('.ini', ''), 'name': f.replace('.ini', '').replace('_', ' ')})
|
||||
materials.sort(key=lambda x: x['name'])
|
||||
return materials
|
||||
except:
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user