能用prusa切片和预览了,添加了缺失的翻译

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-24 01:51:08 +08:00
parent 22a6493e24
commit 366372da6e
15 changed files with 394 additions and 38 deletions

View File

@@ -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 []

View File

@@ -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 []

View File

@@ -26,7 +26,7 @@ def get_gcode_dir(app):
@huey.task()
def slice_stl_task(file_id, stl_filepath, quality_preset=None, infill_density=None, support_enable=None, support_pattern=None, delete_stl=False):
def slice_stl_task(file_id, stl_filepath, quality_preset=None, material_preset=None, infill_density=None, support_enable=None, support_pattern=None, delete_stl=False):
# This is run by the Huey worker
# We need to create an app context to interact with the database
from app import create_app
@@ -61,6 +61,7 @@ def slice_stl_task(file_id, stl_filepath, quality_preset=None, infill_density=No
stl_filepath=stl_filepath,
gcode_filepath=gcode_filepath,
quality_preset=quality_preset,
material_preset=material_preset,
infill_density=infill_density,
support_enable=support_enable,
support_pattern=support_pattern
@@ -95,7 +96,7 @@ def slice_stl_task(file_id, stl_filepath, quality_preset=None, infill_density=No
@huey.task()
def merge_and_slice_task(file_id, inputs, merged_filepath, quality_preset=None, infill_density=None, support_enable=None, support_pattern=None, delete_stl=False):
def merge_and_slice_task(file_id, inputs, merged_filepath, quality_preset=None, material_preset=None, infill_density=None, support_enable=None, support_pattern=None, delete_stl=False):
from app import create_app
app = create_app()
with app.app_context():
@@ -112,7 +113,7 @@ def merge_and_slice_task(file_id, inputs, merged_filepath, quality_preset=None,
# Now trigger the regular slicing task
# We can just call the slicing logic or enqueue it
slice_stl_task(file_id, merged_filepath, quality_preset, infill_density, support_enable, support_pattern, delete_stl=delete_stl)
slice_stl_task(file_id, merged_filepath, quality_preset, material_preset, infill_density, support_enable, support_pattern, delete_stl=delete_stl)
except Exception as e:
print_file = PrintFile.query.get(file_id)
if print_file: