@@ -1,6 +1,13 @@
|
||||
from .cura_engine import CuraEngine
|
||||
from .prusa_slicer_engine import PrusaSlicerEngine
|
||||
|
||||
def get_all_engines():
|
||||
"""Returns a list of instantiated engines."""
|
||||
return [
|
||||
CuraEngine(),
|
||||
PrusaSlicerEngine()
|
||||
]
|
||||
|
||||
def get_slicer_engine(engine_name="cura"):
|
||||
"""
|
||||
Factory function to retrieve the requested slicing engine instance.
|
||||
@@ -14,4 +21,4 @@ def get_slicer_engine(engine_name="cura"):
|
||||
return PrusaSlicerEngine()
|
||||
else:
|
||||
# Default fallback
|
||||
return CuraEngine()
|
||||
return CuraEngine()
|
||||
|
||||
@@ -8,6 +8,26 @@ from app.utils.conf_parse import ConfParse
|
||||
class CuraEngine:
|
||||
def __init__(self):
|
||||
self.name = "cura"
|
||||
self.display_name = "UltiMaker Cura"
|
||||
self.is_available = self._check_available()
|
||||
|
||||
def _check_available(self):
|
||||
try:
|
||||
# check if CuraEngine is available in PATH
|
||||
result = subprocess.run(["CuraEngine", "help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
return result.returncode == 0 or b"Usage:" in result.stdout or b"Usage:" in result.stderr
|
||||
except (FileNotFoundError, OSError):
|
||||
return False
|
||||
self.display_name = "UltiMaker Cura"
|
||||
self.is_available = self._check_available()
|
||||
|
||||
def _check_available(self):
|
||||
try:
|
||||
# check if CuraEngine is available in PATH
|
||||
result = subprocess.run(["CuraEngine", "help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
return result.returncode == 0 or b"Usage:" in result.stdout or b"Usage:" in result.stderr
|
||||
except (FileNotFoundError, OSError):
|
||||
return False
|
||||
|
||||
def slice(self, app, stl_filepath, gcode_filepath, **kwargs):
|
||||
"""
|
||||
@@ -165,4 +185,31 @@ class CuraEngine:
|
||||
try:
|
||||
os.remove(tmp_def_path)
|
||||
except Exception as e:
|
||||
app.logger.error(f"Failed to delete temp JSON config {tmp_def_path}: {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')
|
||||
if not os.path.exists(path): return []
|
||||
files = [f for f in os.listdir(path) if f.endswith('.inst.cfg')]
|
||||
presets = []
|
||||
for f in files:
|
||||
presets.append({'id': f, 'name': f.replace('.inst.cfg', '')})
|
||||
presets.sort(key=lambda x: x['name'])
|
||||
return presets
|
||||
except:
|
||||
return []
|
||||
|
||||
def get_support_patterns(self):
|
||||
return [
|
||||
{'id': 'tree', 'name': 'Tree'},
|
||||
{'id': 'lines', 'name': 'Lines'},
|
||||
{'id': 'grid', 'name': 'Grid'},
|
||||
{'id': 'triangles', 'name': 'Triangles'},
|
||||
{'id': 'concentric', 'name': 'Concentric'},
|
||||
{'id': 'zigzag', 'name': 'Zig Zag'},
|
||||
{'id': 'cross', 'name': 'Cross'},
|
||||
{'id': 'gyroid', 'name': 'Gyroid'},
|
||||
{'id': 'honeycomb', 'name': 'Honeycomb'},
|
||||
{'id': 'octagon', 'name': 'Octagon'}
|
||||
]
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
import os
|
||||
import subprocess
|
||||
import configparser
|
||||
|
||||
class PrusaSlicerEngine:
|
||||
def __init__(self):
|
||||
self.name = "prusa_slicer"
|
||||
self.display_name = "PrusaSlicer"
|
||||
self.is_available = self._check_available()
|
||||
|
||||
def _check_available(self):
|
||||
try:
|
||||
result = subprocess.run(["prusa-slicer", "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
return b"Usage:" in result.stdout or b"Slic3r" in result.stdout or b"PrusaSlicer" in result.stdout or result.returncode == 0
|
||||
except (FileNotFoundError, OSError):
|
||||
return False
|
||||
|
||||
def slice(self, app, stl_filepath, gcode_filepath, **kwargs):
|
||||
"""
|
||||
@@ -55,3 +65,25 @@ class PrusaSlicerEngine:
|
||||
except Exception as e:
|
||||
app.logger.error(f"PrusaSlicer Exception: {e}")
|
||||
return False, str(e)
|
||||
|
||||
def get_quality_presets(self, app):
|
||||
all_files = [f for f in os.listdir(os.path.join(app.root_path, '..', 'print_config', 'prusa_slicer',"quality")) if f.endswith('.ini')]
|
||||
quality_presets = []
|
||||
for file in all_files:
|
||||
with open(os.path.join(app.root_path, '..', 'print_config', 'prusa_slicer', "quality", file), 'r') as f:
|
||||
config = configparser.ConfigParser()
|
||||
config.read_file(f)
|
||||
if 'metadata' in config:
|
||||
quality_presets.append({
|
||||
'id': file.replace('.ini', ''),
|
||||
'name': config['metadata'].get('show_name', file.replace('.ini', '').replace('_', ' '))
|
||||
})
|
||||
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'}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user