Skip to content

Commit

Permalink
Merge pull request #19029 from Ultimaker/CURA-11777-yeet-sketch-to-ma…
Browse files Browse the repository at this point in the history
…kerbot

Cura 11777 yeet sketch to makerbot
  • Loading branch information
HellAholic committed May 17, 2024
2 parents f381185 + 21b8694 commit 328af07
Show file tree
Hide file tree
Showing 14 changed files with 12,793 additions and 31 deletions.
3 changes: 2 additions & 1 deletion cura/PrinterOutput/NetworkedPrinterOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ def applyPrinterTypeMapping(printer_type):
_PRINTER_TYPE_NAME = {
"fire_e": "ultimaker_method",
"lava_f": "ultimaker_methodx",
"magma_10": "ultimaker_methodxl"
"magma_10": "ultimaker_methodxl",
"sketch": "ultimaker_sketch"
}
if printer_type in _PRINTER_TYPE_NAME:
return _PRINTER_TYPE_NAME[printer_type]
Expand Down
59 changes: 39 additions & 20 deletions plugins/MakerbotWriter/MakerbotWriter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Copyright (c) 2023 UltiMaker
# Cura is released under the terms of the LGPLv3 or higher.

from io import StringIO, BufferedIOBase
import json
from typing import cast, List, Optional, Dict
from typing import cast, List, Optional, Dict, Tuple
from zipfile import BadZipFile, ZipFile, ZIP_DEFLATED
import pyDulcificum as du

Expand Down Expand Up @@ -39,16 +38,27 @@ def __init__(self) -> None:
suffixes=["makerbot"]
)
)
MimeTypeDatabase.addMimeType(
MimeType(
name="application/x-makerbot-sketch",
comment="Makerbot Toolpath Package",
suffixes=["makerbot"]
)
)

_PNG_FORMATS = [
_PNG_FORMAT = [
{"prefix": "isometric_thumbnail", "width": 120, "height": 120},
{"prefix": "isometric_thumbnail", "width": 320, "height": 320},
{"prefix": "isometric_thumbnail", "width": 640, "height": 640},
{"prefix": "thumbnail", "width": 90, "height": 90},
]

_PNG_FORMAT_METHOD = [
{"prefix": "thumbnail", "width": 140, "height": 106},
{"prefix": "thumbnail", "width": 212, "height": 300},
{"prefix": "thumbnail", "width": 960, "height": 1460},
{"prefix": "thumbnail", "width": 90, "height": 90},
]

_META_VERSION = "3.0.0"

# must be called from the main thread because of OpenGL
Expand All @@ -74,6 +84,7 @@ def _createThumbnail(width: int, height: int) -> Optional[QBuffer]:
return None

def write(self, stream: BufferedIOBase, nodes: List[SceneNode], mode=MeshWriter.OutputMode.BinaryMode) -> bool:
metadata, file_format = self._getMeta(nodes)
if mode != MeshWriter.OutputMode.BinaryMode:
Logger.log("e", "MakerbotWriter does not support text mode.")
self.setInformation(catalog.i18nc("@error:not supported", "MakerbotWriter does not support text mode."))
Expand All @@ -92,14 +103,20 @@ def write(self, stream: BufferedIOBase, nodes: List[SceneNode], mode=MeshWriter.

gcode_text_io = StringIO()
success = gcode_writer.write(gcode_text_io, None)

filename, filedata = "", ""
# Writing the g-code failed. Then I can also not write the gzipped g-code.
if not success:
self.setInformation(gcode_writer.getInformation())
return False

json_toolpaths = du.gcode_2_miracle_jtp(gcode_text_io.getvalue())
metadata = self._getMeta(nodes)
match file_format:
case "application/x-makerbot-sketch":
filename, filedata = "print.gcode", gcode_text_io.getvalue()
self._PNG_FORMATS = self._PNG_FORMAT
case "application/x-makerbot":
filename, filedata = "print.jsontoolpath", du.gcode_2_miracle_jtp(gcode_text_io.getvalue())
self._PNG_FORMATS = self._PNG_FORMAT + self._PNG_FORMAT_METHOD
case _:
raise Exception("Unsupported Mime type")

png_files = []
for png_format in self._PNG_FORMATS:
Expand All @@ -116,7 +133,7 @@ def write(self, stream: BufferedIOBase, nodes: List[SceneNode], mode=MeshWriter.
try:
with ZipFile(stream, "w", compression=ZIP_DEFLATED) as zip_stream:
zip_stream.writestr("meta.json", json.dumps(metadata, indent=4))
zip_stream.writestr("print.jsontoolpath", json_toolpaths)
zip_stream.writestr(filename, filedata)
for png_file in png_files:
file, data = png_file["file"], png_file["data"]
zip_stream.writestr(file, data)
Expand All @@ -127,7 +144,7 @@ def write(self, stream: BufferedIOBase, nodes: List[SceneNode], mode=MeshWriter.

return True

def _getMeta(self, root_nodes: List[SceneNode]) -> Dict[str, any]:
def _getMeta(self, root_nodes: List[SceneNode]) -> Tuple[Dict[str, any], str]:
application = CuraApplication.getInstance()
machine_manager = application.getMachineManager()
global_stack = machine_manager.activeMachine
Expand All @@ -143,7 +160,9 @@ def _getMeta(self, root_nodes: List[SceneNode]) -> Dict[str, any]:
nodes.append(node)

meta = dict()

# This is a bit of a "hack", the mime type should be passed through with the export writer but
# since this is not the case we get the mime type from the global stack instead
file_format = global_stack.definition.getMetaDataEntry("file_formats")
meta["bot_type"] = global_stack.definition.getMetaDataEntry("reference_machine_id")

bounds: Optional[AxisAlignedBox] = None
Expand All @@ -155,7 +174,8 @@ def _getMeta(self, root_nodes: List[SceneNode]) -> Dict[str, any]:
bounds = node_bounds
else:
bounds = bounds + node_bounds

if file_format == "application/x-makerbot-sketch":
bounds = None
if bounds is not None:
meta["bounding_box"] = {
"x_min": bounds.left,
Expand Down Expand Up @@ -196,7 +216,7 @@ def _getMeta(self, root_nodes: List[SceneNode]) -> Dict[str, any]:
meta["extruder_temperature"] = materials_temps[0]
meta["extruder_temperatures"] = materials_temps

meta["model_counts"] = [{"count": 1, "name": node.getName()} for node in nodes]
meta["model_counts"] = [{"count": len(nodes), "name": "instance0"}]

tool_types = [extruder.variant.getMetaDataEntry("reference_extruder_id") for extruder in extruders]
meta["tool_type"] = tool_types[0]
Expand All @@ -205,12 +225,11 @@ def _getMeta(self, root_nodes: List[SceneNode]) -> Dict[str, any]:
meta["version"] = MakerbotWriter._META_VERSION

meta["preferences"] = dict()
for node in nodes:
bounds = node.getBoundingBox()
meta["preferences"][str(node.getName())] = {
"machineBounds": [bounds.right, bounds.back, bounds.left, bounds.front] if bounds is not None else None,
"printMode": CuraApplication.getInstance().getIntentManager().currentIntentCategory,
}
bounds = application.getBuildVolume().getBoundingBox()
meta["preferences"]["instance0"] = {
"machineBounds": [bounds.right, bounds.back, bounds.left, bounds.front] if bounds is not None else None,
"printMode": CuraApplication.getInstance().getIntentManager().currentIntentCategory,
}

meta["miracle_config"] = {"gaggles": {str(node.getName()): {} for node in nodes}}

Expand Down Expand Up @@ -245,7 +264,7 @@ def _getMeta(self, root_nodes: List[SceneNode]) -> Dict[str, any]:
# platform_temperature
# total_commands

return meta
return meta, file_format


def meterToMillimeter(value: float) -> float:
Expand Down
25 changes: 17 additions & 8 deletions plugins/MakerbotWriter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@
def getMetaData():
file_extension = "makerbot"
return {
"mesh_writer": {
"output": [{
"extension": file_extension,
"description": catalog.i18nc("@item:inlistbox", "Makerbot Printfile"),
"mime_type": "application/x-makerbot",
"mode": MakerbotWriter.MakerbotWriter.OutputMode.BinaryMode,
}],
}
"mesh_writer":
{
"output": [
{
"extension": file_extension,
"description": catalog.i18nc("@item:inlistbox", "Makerbot Printfile"),
"mime_type": "application/x-makerbot",
"mode": MakerbotWriter.MakerbotWriter.OutputMode.BinaryMode,
},
{
"extension": file_extension,
"description": catalog.i18nc("@item:inlistbox", "Makerbot Sketch Printfile"),
"mime_type": "application/x-makerbot-sketch",
"mode": MakerbotWriter.MakerbotWriter.OutputMode.BinaryMode,
}
]
},
}


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def isMethod(self) -> bool:
return False

[printer, *_] = self._printers
return printer.type in ("MakerBot Method X", "MakerBot Method XL")
return printer.type in ("MakerBot Method X", "MakerBot Method XL", "MakerBot Sketch")

@pyqtProperty(bool, notify=_cloudClusterPrintersChanged)
def supportsPrintJobActions(self) -> bool:
Expand Down
3 changes: 2 additions & 1 deletion plugins/UM3NetworkPrinting/src/Cloud/machine_id_to_name.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"ultimaker_method": "MakerBot Method",
"ultimaker_methodx": "MakerBot Method X",
"ultimaker_methodxl": "MakerBot Method XL",
"ultimaker_factor4": "Ultimaker Factor 4"
"ultimaker_factor4": "Ultimaker Factor 4",
"ultimaker_sketch": "MakerBot Sketch"
}
Loading

0 comments on commit 328af07

Please sign in to comment.