Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cura 11777 yeet sketch to makerbot #19029

Merged
merged 12 commits into from
May 17, 2024
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
26 changes: 18 additions & 8 deletions plugins/MakerbotWriter/MakerbotWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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,6 +39,13 @@ def __init__(self) -> None:
suffixes=["makerbot"]
)
)
MimeTypeDatabase.addMimeType(
MimeType(
name="application/x-makerbot-sketch",
comment="Makerbot Toolpath Package",
suffixes=["makerbot"]
)
)

_PNG_FORMATS = [
{"prefix": "isometric_thumbnail", "width": 120, "height": 120},
Expand Down Expand Up @@ -74,6 +81,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 +100,16 @@ 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)
if file_format == "application/x-makerbot-sketch":
filename, filedata = "print.gcode", gcode_text_io.getvalue()
else:
filename, filedata = "print.jsontoolpath", du.gcode_2_miracle_jtp(gcode_text_io.getvalue())

png_files = []
for png_format in self._PNG_FORMATS:
Expand All @@ -116,7 +126,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 +137,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 +153,7 @@ def _getMeta(self, root_nodes: List[SceneNode]) -> Dict[str, any]:
nodes.append(node)

meta = dict()

file_format = global_stack.definition.getMetaDataEntry("file_formats")
casperlamboo marked this conversation as resolved.
Show resolved Hide resolved
meta["bot_type"] = global_stack.definition.getMetaDataEntry("reference_machine_id")

bounds: Optional[AxisAlignedBox] = None
Expand Down Expand Up @@ -245,7 +255,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
Loading