-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFisnarCSVWriter.py
More file actions
75 lines (56 loc) · 3.34 KB
/
FisnarCSVWriter.py
File metadata and controls
75 lines (56 loc) · 3.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from .FisnarRobotExtension import FisnarRobotExtension
from .Converter import Converter
from UM.Mesh.MeshWriter import MeshWriter
from UM.Application import Application
from UM.Logger import Logger
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
class FisnarCSVWriter(MeshWriter):
def __init__(self):
super().__init__(add_to_recent_files = False) # don't want the spreadsheets to appear in recent files
if FisnarCSVWriter._instance is not None: # already been created - should never happen
Logger.log("e", "FisnarCSVWriter instantiated more than once")
else:
FisnarCSVWriter._instance = self
self._fre_instance = FisnarRobotExtension.getInstance()
self.converter = Converter()
def write(self, stream, nodes, mode=MeshWriter.OutputMode.TextMode):
# getting updated extension parameters
self.converter.setPrintSurface(self._fre_instance.print_surface)
self.converter.setContinuousExtrusion(self._fre_instance.continuous_extrusion)
# TODO: figure out a way to get the filename of the saved file, and add it as a parameter in the extension plugin
# making sure the mode is text output
if mode != MeshWriter.OutputMode.TextMode:
Logger.log("e", "FisnarCSVWriter does not support non-text mode")
self.setInformation(catalog.i18nc("@error:not supported", "FisnarCSVWriter does not support non-text mode"))
return False # signals error
# making sure gcode_dict exists before calling it
active_build_plate = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
scene = Application.getInstance().getController().getScene()
if not hasattr(scene, "gcode_dict"): # if hasn't been sliced yet
self.setInformation(catalog.i18nc("@warning:status", "Gcode must be prepared before exporting Fisnar CSV"))
return False # error
gcode_dict = getattr(scene, "gcode_dict")
gcode_list = gcode_dict.get(active_build_plate, None) # returns None if not found
if gcode_list is not None: # gcode_list was found
# # debug
# for element in gcode_list:
# Logger.log("d", str(element))
# setting converter gcode and attempting to convert
self.converter.setGcode("".join([str(chunk) for chunk in gcode_list]))
fisnar_commands = self.converter.getFisnarCommands()
if fisnar_commands is False: # error was caught in conversion, get error info from converter object
self.setInformation(catalog.i18nc("@warning:status", self.converter.getInformation()))
return False # error
csv_string = Converter.fisnarCommandsToCSVString(fisnar_commands)
stream.write(csv_string) # writing to file
FisnarRobotExtension.getInstance().most_recent_fisnar_commands = fisnar_commands # updating in extension class
return True # successful conversion
else: # gcode list not found, log error
self.setInformation(catalog.i18nc("@warning:status", "Gcode must be prepared before exporting Fisnar CSV"))
return False # error
_instance = None
@classmethod
def getInstance(cls):
# get the singleton instance of the FisnarCSVWriter class
return cls._instance