有构建板,支持多模型构建,但生成支撑的切片还有bug
This commit is contained in:
50
app/tasks.py
50
app/tasks.py
@@ -8,7 +8,7 @@ huey = SqliteHuey(filename='huey_queue.db')
|
||||
import configparser
|
||||
|
||||
@huey.task()
|
||||
def slice_stl_task(file_id, stl_filepath, quality_preset=None):
|
||||
def slice_stl_task(file_id, stl_filepath, quality_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
|
||||
@@ -53,6 +53,20 @@ def slice_stl_task(file_id, stl_filepath, quality_preset=None):
|
||||
for key, val in config.items('values'):
|
||||
command.extend(['-s', f"{key}={val}"])
|
||||
|
||||
if infill_density is not None:
|
||||
command.extend(['-s', f"infill_sparse_density={infill_density}"])
|
||||
command.extend(['-s', f"infill_line_distance={100 / int(infill_density) if int(infill_density) > 0 else 9999}"])
|
||||
|
||||
if support_enable is not None:
|
||||
command.extend(['-s', f"support_enable={'true' if support_enable == 'true' or support_enable == 'buildplate' else 'false'}"])
|
||||
command.extend(['-s', f"support_type={'buildplate' if support_enable == 'buildplate' else 'everywhere'}"])
|
||||
if support_pattern == 'tree':
|
||||
command.extend(['-s', 'support_structure=tree'])
|
||||
command.extend(['-s', 'support_tree_enable=true'])
|
||||
elif support_pattern and support_pattern != 'false':
|
||||
command.extend(['-s', 'support_structure=normal'])
|
||||
command.extend(['-s', f'support_pattern={support_pattern}'])
|
||||
|
||||
command.extend([
|
||||
"-l", stl_filepath,
|
||||
"-o", gcode_filepath
|
||||
@@ -80,6 +94,40 @@ def slice_stl_task(file_id, stl_filepath, quality_preset=None):
|
||||
print_file.status = 'failed'
|
||||
app.logger.error(f"Subprocess Exception: {e}")
|
||||
|
||||
if delete_stl and os.path.exists(stl_filepath):
|
||||
try:
|
||||
os.remove(stl_filepath)
|
||||
except Exception as e:
|
||||
app.logger.error(f"Failed to delete temp STL {stl_filepath}: {e}")
|
||||
|
||||
db.session.commit()
|
||||
db.session.remove()
|
||||
|
||||
|
||||
@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):
|
||||
from app import create_app
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
from .models import PrintFile, db
|
||||
print_file = PrintFile.query.get(file_id)
|
||||
if not print_file:
|
||||
return
|
||||
|
||||
db.session.remove()
|
||||
|
||||
try:
|
||||
from stl_merger import merge_stls
|
||||
merge_stls(inputs, merged_filepath)
|
||||
|
||||
# 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)
|
||||
except Exception as e:
|
||||
print_file = PrintFile.query.get(file_id)
|
||||
if print_file:
|
||||
print_file.status = 'failed'
|
||||
db.session.commit()
|
||||
app.logger.error(f"Merge Exception: {e}")
|
||||
finally:
|
||||
db.session.remove()
|
||||
|
||||
Reference in New Issue
Block a user