Commit 334ed178 authored by sumpfralle's avatar sumpfralle

added support for ARC items (DXF format)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@954 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent bf1bcd27
...@@ -9,7 +9,7 @@ Version 0.4.1 - UNRELEASED ...@@ -9,7 +9,7 @@ Version 0.4.1 - UNRELEASED
* added a very simple "pocketing" mode for 2D models * added a very simple "pocketing" mode for 2D models
* added 2D projection of 3D models * added 2D projection of 3D models
* added toolpath cropping * added toolpath cropping
* added support for DXF feature "LWPOLYLINE" * added support for DXF features "LWPOLYLINE" and "ARC"
* added a configuration setting for automatically loading a custom task settings file on startup * added a configuration setting for automatically loading a custom task settings file on startup
* added a simple "undo" feature for reversing model manipulations * added a simple "undo" feature for reversing model manipulations
* added a minimum step width for GCode positions to be written * added a minimum step width for GCode positions to be written
......
...@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Geometry.Point import Point from pycam.Geometry.Point import Point
from pycam.Geometry.Line import Line from pycam.Geometry.Line import Line
import pycam.Geometry.Model import pycam.Geometry.Model
import pycam.Geometry
import pycam.Utils.log import pycam.Utils.log
log = pycam.Utils.log.get_logger() log = pycam.Utils.log.get_logger()
...@@ -41,6 +42,9 @@ class DXFParser(object): ...@@ -41,6 +42,9 @@ class DXFParser(object):
"END_X": 11, "END_X": 11,
"END_Y": 21, "END_Y": 21,
"END_Z": 31, "END_Z": 31,
"RADIUS": 40,
"ANGLE_START": 50,
"ANGLE_END": 51,
"COLOR": 62, "COLOR": 62,
} }
...@@ -127,9 +131,9 @@ class DXFParser(object): ...@@ -127,9 +131,9 @@ class DXFParser(object):
log.warn("DXFImporter: Invalid key in line " \ log.warn("DXFImporter: Invalid key in line " \
+ "%d (int expected): %s" % (self.line_number, line1)) + "%d (int expected): %s" % (self.line_number, line1))
return None, None return None, None
if line1 in (self.KEYS["START_X"], self.KEYS["START_Y"], if line1 in [self.KEYS[key] for key in ("START_X", "START_Y", "START_Z",
self.KEYS["START_Z"], self.KEYS["END_X"], self.KEYS["END_Y"], "END_X", "END_Y", "END_Z", "RADIUS", "ANGLE_START",
self.KEYS["END_Z"]): "ANGLE_END")]:
try: try:
line2 = float(line2) line2 = float(line2)
except ValueError: except ValueError:
...@@ -164,6 +168,8 @@ class DXFParser(object): ...@@ -164,6 +168,8 @@ class DXFParser(object):
self.parse_line() self.parse_line()
elif value == "LWPOLYLINE": elif value == "LWPOLYLINE":
self.parse_polyline() self.parse_polyline()
elif value == "ARC":
self.parse_arc()
else: else:
# not supported # not supported
log.warn("DXFImporter: Ignored unsupported element in " \ log.warn("DXFImporter: Ignored unsupported element in " \
...@@ -275,6 +281,59 @@ class DXFParser(object): ...@@ -275,6 +281,59 @@ class DXFParser(object):
log.warn("DXFImporter: Ignoring zero-length LINE (between " \ log.warn("DXFImporter: Ignoring zero-length LINE (between " \
+ "input line %d and %d): %s" % (start_line, end_line, + "input line %d and %d): %s" % (start_line, end_line,
line)) line))
def parse_arc(self):
start_line = self.line_number
# the z-level defaults to zero (for 2D models)
center = [None, None, 0]
color = None
radius = None
angle_start = None
angle_end = None
key, value = self._read_key_value()
while (not key is None) and (key != self.KEYS["MARKER"]):
if key == self.KEYS["START_X"]:
center[0] = value
elif key == self.KEYS["START_Y"]:
center[1] = value
elif key == self.KEYS["START_Z"]:
center[2] = value
elif key == self.KEYS["RADIUS"]:
radius = value
elif key == self.KEYS["ANGLE_START"]:
angle_start = value
elif key == self.KEYS["ANGLE_END"]:
angle_end = value
elif key == self.KEYS["COLOR"]:
color = value
else:
pass
key, value = self._read_key_value()
end_line = self.line_number
# The last lines were not used - they are just the marker for the next
# item.
if not key is None:
self._push_on_stack(key, value)
if (None in center) or (None in (radius, angle_start, angle_end)):
log.warn("DXFImporter: Incomplete ARC definition between line " \
+ "%d and %d" % (start_line, end_line))
else:
if self._color_as_height and (not color is None):
# use the color code as the z coordinate
center[2] = float(color) / 255
center = Point(center[0], center[1], center[2])
xy_point_coords = pycam.Geometry.get_points_of_arc(center, radius,
angle_start, angle_end)
if len(xy_point_coords) > 1:
for index in range(len(xy_point_coords) - 1):
p1 = xy_point_coords[index]
p1 = Point(p1[0], p1[1], center.z)
p2 = xy_point_coords[index + 1]
p2 = Point(p2[0], p2[1], center.z)
self.lines.append(Line(p1, p2))
else:
log.warn("DXFImporter: Ignoring zero-length LINE (between " \
+ "input line %d and %d): %s" % (start_line, end_line,
line))
def check_header(self): def check_header(self):
# TODO: this function is not used? # TODO: this function is not used?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment