forked from Ghostkeeper/X3GWriter
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNGCWriter.py
More file actions
46 lines (34 loc) · 1.34 KB
/
NGCWriter.py
File metadata and controls
46 lines (34 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright (c) 2016-2018 Alexander Roessler
# NGCWriter is released under the terms of the AGPLv3 or higher.
import io # For StringIO to write the g-code to a buffer.
import os
import sys
from UM.Mesh.MeshWriter import MeshWriter
from UM.Logger import Logger
from UM.PluginRegistry import PluginRegistry
from UM.i18n import i18nCatalog
path = os.path.dirname(os.path.realpath(__file__))
if path not in sys.path:
sys.path.append(path)
from converter.gcode2ngc import GCode2Ngc
from converter.ngc2ve import Ngc2Ve
catalog = i18nCatalog("cura")
class NGCWriter(MeshWriter):
version = 3
def __init__(self):
super().__init__()
def write(self, stream, nodes, mode=MeshWriter.OutputMode.TextMode):
if mode != MeshWriter.OutputMode.TextMode:
Logger.log("e", "NGC Writer does not support non-text mode.")
self.setInformation(catalog.i18nc("@error:not supported", "NGCWriter does not support non-text mode."))
return False
# Get the g-code.
gcode = io.StringIO()
PluginRegistry.getInstance().getPluginObject("GCodeWriter").write(gcode, None)
gcode = gcode.getvalue()
gcodeConverter = GCode2Ngc()
veConverter = Ngc2Ve()
gcode = gcodeConverter.process(gcode)
gcode = veConverter.process(gcode)
stream.write(gcode)
return True