The API now allows to specify where on the print bed to put the sliced model's center

This commit is contained in:
Gina Häußge committed 2014-12-04 12:52:33 +01:00
1 parent b935e96448
commit 636e79672a
6 files changed
+53 -13

No files matched your search

+11 -4
View File
@@ -229,13 +229,20 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin,
self._save_profile(path, new_profile, allow_overwrite=allow_overwrite)
def do_slice(self, model_path, printer_profile, machinecode_path=None, profile_path=None, on_progress=None, on_progress_args=None, on_progress_kwargs=None):
def do_slice(self, model_path, printer_profile, machinecode_path=None, profile_path=None, position=None, on_progress=None, on_progress_args=None, on_progress_kwargs=None):
if not profile_path:
profile_path = s.get(["default_profile"])
if not machinecode_path:
path, _ = os.path.splitext(model_path)
machinecode_path = path + ".gco"
if position and isinstance(position, dict) and "x" in position and "y" in position:
posX = position["x"]
posY = position["y"]
else:
posX = None
posY = None
if on_progress:
if not on_progress_args:
on_progress_args = ()
@@ -244,7 +251,7 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin,
self._cura_logger.info("### Slicing %s to %s using profile stored at %s" % (model_path, machinecode_path, profile_path))
engine_settings = self._convert_to_engine(profile_path, printer_profile)
engine_settings = self._convert_to_engine(profile_path, printer_profile, posX, posY)
executable = s.get(["cura_engine"])
if not executable:
@@ -381,8 +388,8 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin,
with open(path, "wb") as f:
yaml.safe_dump(profile, f, default_flow_style=False, indent=" ", allow_unicode=True)
def _convert_to_engine(self, profile_path, printer_profile):
profile = Profile(self._load_profile(profile_path), printer_profile)
def _convert_to_engine(self, profile_path, printer_profile, posX, posY):
profile = Profile(self._load_profile(profile_path), printer_profile, posX, posY)
return profile.convert_to_engine()
def _sanitize_name(name):
+23 -3
View File
@@ -514,9 +514,11 @@ class Profile(object):
return result
def __init__(self, profile, printer_profile, overrides=None):
def __init__(self, profile, printer_profile, posX, posY, overrides=None):
self._profile = self.__class__.merge_profile(profile, overrides=overrides)
self._printer_profile = printer_profile
self._posX = posX
self._posY = posY
def profile(self):
import copy
@@ -796,6 +798,24 @@ class Profile(object):
return 2
return 1
def get_pos_x(self):
if self._posX:
try:
return int(float(self._posX) * 1000)
except ValueError:
pass
return int(self.get_float("machine_width") / 2.0 * 1000) if not self.get_boolean("machine_center_is_zero") else 0.0
def get_pos_y(self):
if self._posY:
try:
return int(float(self._posY) * 1000)
except ValueError:
pass
return int(self.get_float("machine_depth") / 2.0 * 1000) if not self.get_boolean("machine_center_is_zero") else 0.0
def convert_to_engine(self):
edge_width, line_count = self.calculate_edge_width_and_line_count()
@@ -844,8 +864,8 @@ class Profile(object):
"coolHeadLift": 1 if self.get_boolean("cool_head_lift") else 0,
# model positioning
"posx": int(self.get_float("machine_width") / 2.0 * 1000) if not self.get_boolean("machine_center_is_zero") else 0.0,
"posy": int(self.get_float("machine_depth") / 2.0 * 1000) if not self.get_boolean("machine_center_is_zero") else 0.0,
"posx": self.get_pos_x(),
"posy": self.get_pos_y(),
# gcodes
"startCode": self.get_gcode("start_gcode"),