mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 23:46:22 -06:00
T466: Added basic file loading and parsing
This commit is contained in:
parent
65f3495a29
commit
8aa3b1b38c
2 changed files with 110 additions and 36 deletions
|
@ -24,6 +24,36 @@ class GCODEReader(MeshReader):
|
|||
super(GCODEReader, self).__init__()
|
||||
self._supported_extensions = [".gcode", ".g"]
|
||||
|
||||
def getInt(self, line, code):
|
||||
n = line.find(code) + 1
|
||||
if n < 1:
|
||||
return None
|
||||
m = line.find(' ', n)
|
||||
m2 = line.find(';', n)
|
||||
if m < 0:
|
||||
m = m2
|
||||
try:
|
||||
if m < 0:
|
||||
return int(line[n:])
|
||||
return int(line[n:m])
|
||||
except:
|
||||
return None
|
||||
|
||||
def getFloat(self, line, code):
|
||||
n = line.find(code) + 1
|
||||
if n < 1:
|
||||
return None
|
||||
m = line.find(' ', n)
|
||||
m2 = line.find(';', n)
|
||||
if m < 0:
|
||||
m = m2
|
||||
try:
|
||||
if m < 0:
|
||||
return float(line[n:])
|
||||
return float(line[n:m])
|
||||
except:
|
||||
return None
|
||||
|
||||
def read(self, file_name):
|
||||
scene_node = None
|
||||
|
||||
|
@ -43,48 +73,90 @@ class GCODEReader(MeshReader):
|
|||
#
|
||||
# scene_node.setMeshData(mesh_builder.build())
|
||||
|
||||
def getBoundingBox():
|
||||
return AxisAlignedBox(minimum=Vector(0, 0, 0), maximum=Vector(10, 10, 10))
|
||||
|
||||
scene_node.getBoundingBox = getBoundingBox
|
||||
# scene_node.getBoundingBox = getBoundingBox
|
||||
scene_node.gcode = True
|
||||
backend = Application.getInstance().getBackend()
|
||||
backend._pauseSlicing = True
|
||||
backend.backendStateChange.emit(0)
|
||||
|
||||
mesh_builder = MeshBuilder()
|
||||
mesh_builder.setFileName(file_name)
|
||||
|
||||
mesh_builder.addCube(10,10,10)
|
||||
|
||||
scene_node.setMeshData(mesh_builder.build())
|
||||
file = open(file_name, "r")
|
||||
|
||||
layer_data = LayerDataBuilder.LayerDataBuilder()
|
||||
layer_count = 1
|
||||
for id in range(layer_count):
|
||||
layer_data.addLayer(id)
|
||||
this_layer = layer_data.getLayer(id)
|
||||
layer_data.setLayerHeight(id, 1)
|
||||
layer_data.setLayerThickness(id, 1)
|
||||
|
||||
extruder = 1
|
||||
line_types = numpy.empty((1, 1), numpy.int32)
|
||||
line_types[0, 0] = 6
|
||||
line_widths = numpy.empty((1, 1), numpy.int32)
|
||||
line_widths[0, 0] = 1
|
||||
points = numpy.empty((2, 3), numpy.float32)
|
||||
points[0, 0] = 0
|
||||
points[0, 1] = 0
|
||||
points[0, 2] = 0
|
||||
points[1, 0] = 10
|
||||
points[1, 1] = 10
|
||||
points[1, 2] = 10
|
||||
layer_id = 0
|
||||
|
||||
this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, points, line_widths)
|
||||
layer_data.addLayer(layer_id)
|
||||
this_layer = layer_data.getLayer(layer_id)
|
||||
layer_data.setLayerHeight(layer_id, 0)
|
||||
layer_data.setLayerThickness(layer_id, 0.1)
|
||||
|
||||
current_extruder = 1
|
||||
current_path = []
|
||||
current_x = 0
|
||||
current_y = 0
|
||||
current_z = 0
|
||||
|
||||
def CreatePolygon():
|
||||
count = len(current_path)
|
||||
line_types = numpy.empty((count-1, 1), numpy.int32)
|
||||
line_types[:, 0] = 1
|
||||
line_widths = numpy.empty((count-1, 1), numpy.int32)
|
||||
line_widths[:, 0] = 1
|
||||
points = numpy.empty((count, 3), numpy.float32)
|
||||
i = 0
|
||||
for point in current_path:
|
||||
points[i, 0] = point[0]
|
||||
points[i, 1] = point[1]
|
||||
points[i, 2] = point[2]
|
||||
i += 1
|
||||
|
||||
this_poly = LayerPolygon.LayerPolygon(layer_data, current_extruder, line_types, points, line_widths)
|
||||
this_poly.buildCache()
|
||||
|
||||
this_layer.polygons.append(this_poly)
|
||||
|
||||
current_path.clear()
|
||||
|
||||
# current_path.append([0, 0, 0])
|
||||
# current_path.append([10, 10, 10])
|
||||
# while file.readable():
|
||||
for line in file:
|
||||
if len(line) == 0:
|
||||
continue
|
||||
if line[0] == ";":
|
||||
continue
|
||||
G = self.getInt(line, "G")
|
||||
if G:
|
||||
if G == 0 or G == 1:
|
||||
x = self.getFloat(line, "X")
|
||||
y = self.getFloat(line, "Y")
|
||||
z = self.getFloat(line, "Z")
|
||||
e = self.getFloat(line, "E")
|
||||
if x:
|
||||
current_x = x
|
||||
if y:
|
||||
current_y = y
|
||||
if z:
|
||||
current_z = z
|
||||
if e and e > 0:
|
||||
current_path.append([current_x, current_z, -current_y])
|
||||
else:
|
||||
if len(current_path) > 1:
|
||||
CreatePolygon()
|
||||
elif G == 92:
|
||||
x = self.getFloat(line, "X")
|
||||
y = self.getFloat(line, "Y")
|
||||
z = self.getFloat(line, "Z")
|
||||
if x:
|
||||
current_x += x
|
||||
if y:
|
||||
current_y += y
|
||||
if z:
|
||||
current_z += z
|
||||
|
||||
if len(current_path) > 1:
|
||||
CreatePolygon()
|
||||
|
||||
layer_mesh = layer_data.build()
|
||||
decorator = LayerDataDecorator.LayerDataDecorator()
|
||||
decorator.setLayerData(layer_mesh)
|
||||
|
@ -93,6 +165,14 @@ class GCODEReader(MeshReader):
|
|||
scene_node_parent = Application.getInstance().getBuildVolume()
|
||||
scene_node.setParent(scene_node_parent)
|
||||
|
||||
mesh_builder = MeshBuilder()
|
||||
mesh_builder.setFileName(file_name)
|
||||
|
||||
mesh_builder.addCube(10, 10, 10, Vector(0, -5, 0))
|
||||
|
||||
scene_node.setMeshData(mesh_builder.build())
|
||||
scene_node.setPosition(Vector(0,0,0))
|
||||
|
||||
view = Application.getInstance().getController().getActiveView()
|
||||
if view.getPluginId() == "LayerView":
|
||||
view.resetLayerData()
|
||||
|
|
|
@ -118,14 +118,8 @@ class LayerView(View):
|
|||
if type(node) is ConvexHullNode and not Selection.isSelected(node.getWatchedNode()):
|
||||
continue
|
||||
|
||||
flag = False
|
||||
try:
|
||||
flag = node.gcode
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
if not node.render(renderer):
|
||||
if node.getMeshData() and node.isVisible() and not flag:
|
||||
if node.getMeshData() and node.isVisible():
|
||||
renderer.queueNode(node, transparent = True, shader = self._ghost_shader)
|
||||
|
||||
def setLayer(self, value):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue