Commit 30fa4082 authored by sumpfralle's avatar sumpfralle

fixed code-style issues


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@478 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 5e5750ed
......@@ -90,8 +90,10 @@ class DXFParser:
current_group = ordered_groups[-1]
closest_distance = None
for cmp_group in remaining_groups:
cmp_distance = get_distance_between_groups(current_group, cmp_group)
if (closest_distance is None) or (cmp_distance < closest_distance):
cmp_distance = get_distance_between_groups(current_group,
cmp_group)
if (closest_distance is None) \
or (cmp_distance < closest_distance):
closest_distance = cmp_distance
closest_group = cmp_group
ordered_groups.append(closest_group)
......@@ -140,13 +142,13 @@ class DXFParser:
line2 = None
else:
line2 = line2.upper()
pass
self.line_number += 2
return line1, line2
def parse_content(self):
key, value = self._read_key_value()
while (not key is None) and not ((key == self.KEYS["MARKER"]) and (value == "EOF")):
while (not key is None) \
and not ((key == self.KEYS["MARKER"]) and (value == "EOF")):
if key == self.KEYS["MARKER"]:
if value in ("SECTION", "TABLE", "LAYER", "ENDTAB", "ENDSEC"):
# we don't handle these meta-information
......@@ -181,32 +183,35 @@ class DXFParser:
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
# 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 p1) or (None in p2):
log.warn("DXFImporter: Incomplete LINE definition between line " \
+ "%d and %d" % (start_line, end_line))
else:
self.lines.append(Line(Point(p1[0], p1[1], p1[2]), Point(p2[0], p2[1], p2[2])))
self.lines.append(Line(Point(p1[0], p1[1], p1[2]),
Point(p2[0], p2[1], p2[2])))
def check_header(self):
# TODO: this function is not used?
# we expect "0" in the first line and "SECTION" in the second one
key, value = self._read_key_value()
if (key != KEYS["MARKER"]) or (value and (value != "SECTION")):
if (key != self.KEYS["MARKER"]) or (value and (value != "SECTION")):
log.error("DXFImporter: DXF file header not recognized")
return None
def import_model(filename):
try:
f = open(filename,"rb")
infile = open(filename,"rb")
except IOError, err_msg:
log.error("DXFImporter: Failed to read file (%s): %s" % (filename, err_msg))
log.error("DXFImporter: Failed to read file (%s): %s" \
% (filename, err_msg))
return None
result = DXFParser(f)
result = DXFParser(infile)
lines = result.get_model()["lines"]
......
This diff is collapsed.
......@@ -23,52 +23,55 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Geometry import Triangle, Line, Point
from pycam.Geometry.Model import Model
def TestModel():
def get_test_model():
points = []
points.append(Point(-2,1,4))
points.append(Point(2,1,4))
points.append(Point(0,-2,4))
points.append(Point(-5,2,2))
points.append(Point(-1,3,2))
points.append(Point(5,2,2))
points.append(Point(4,-1,2))
points.append(Point(2,-4,2))
points.append(Point(-2,-4,2))
points.append(Point(-3,-2,2))
points.append(Point(-2, 1, 4))
points.append(Point(2, 1, 4))
points.append(Point(0, -2, 4))
points.append(Point(-5, 2, 2))
points.append(Point(-1, 3, 2))
points.append(Point(5, 2, 2))
points.append(Point(4, -1, 2))
points.append(Point(2, -4, 2))
points.append(Point(-2, -4, 2))
points.append(Point(-3, -2, 2))
lines = []
lines.append(Line(points[0],points[1]))
lines.append(Line(points[1],points[2]))
lines.append(Line(points[2],points[0]))
lines.append(Line(points[0],points[3]))
lines.append(Line(points[3],points[4]))
lines.append(Line(points[4],points[0]))
lines.append(Line(points[4],points[1]))
lines.append(Line(points[4],points[5]))
lines.append(Line(points[5],points[1]))
lines.append(Line(points[5],points[6]))
lines.append(Line(points[6],points[1]))
lines.append(Line(points[6],points[2]))
lines.append(Line(points[6],points[7]))
lines.append(Line(points[7],points[2]))
lines.append(Line(points[7],points[8]))
lines.append(Line(points[8],points[2]))
lines.append(Line(points[8],points[9]))
lines.append(Line(points[9],points[2]))
lines.append(Line(points[9],points[0]))
lines.append(Line(points[9],points[3]))
lines.append(Line(points[0], points[1]))
lines.append(Line(points[1], points[2]))
lines.append(Line(points[2], points[0]))
lines.append(Line(points[0], points[3]))
lines.append(Line(points[3], points[4]))
lines.append(Line(points[4], points[0]))
lines.append(Line(points[4], points[1]))
lines.append(Line(points[4], points[5]))
lines.append(Line(points[5], points[1]))
lines.append(Line(points[5], points[6]))
lines.append(Line(points[6], points[1]))
lines.append(Line(points[6], points[2]))
lines.append(Line(points[6], points[7]))
lines.append(Line(points[7], points[2]))
lines.append(Line(points[7], points[8]))
lines.append(Line(points[8], points[2]))
lines.append(Line(points[8], points[9]))
lines.append(Line(points[9], points[2]))
lines.append(Line(points[9], points[0]))
lines.append(Line(points[9], points[3]))
model = Model()
model.append(Triangle(points[0],points[1],points[2],lines[0],lines[1],lines[2]))
model.append(Triangle(points[0],points[3],points[4],lines[3],lines[4],lines[5]))
model.append(Triangle(points[0],points[4],points[1],lines[5],lines[6],lines[0]))
model.append(Triangle(points[1],points[4],points[5],lines[6],lines[7],lines[8]))
model.append(Triangle(points[1],points[5],points[6],lines[8],lines[9],lines[10]))
model.append(Triangle(points[1],points[6],points[2],lines[10],lines[11],lines[1]))
model.append(Triangle(points[2],points[6],points[7],lines[11],lines[12],lines[13]))
model.append(Triangle(points[2],points[7],points[8],lines[13],lines[14],lines[15]))
model.append(Triangle(points[2],points[8],points[9],lines[15],lines[16],lines[17]))
model.append(Triangle(points[2],points[9],points[0],lines[17],lines[18],lines[2]))
model.append(Triangle(points[0],points[9],points[3],lines[18],lines[19],lines[3]))
for p1, p2, p3, l1, l2, l3 in (
(0, 1, 2, 0, 1, 2),
(0, 3, 4, 3, 4, 5),
(0, 4, 1, 5, 6, 0),
(1, 4, 5, 6, 7, 8),
(1, 5, 6, 8, 9, 10),
(1, 6, 2, 10, 11, 1),
(2, 6, 7, 11, 12, 13),
(2, 7, 8, 13, 14, 15),
(2, 8, 9, 15, 16, 17),
(2, 9, 0, 17, 18, 2),
(0, 9, 3, 18, 19, 3)):
model.append(Triangle(points[p1], points[p2], points[p3],
lines[l1], lines[l2], lines[l3]))
return model
......@@ -24,8 +24,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
__all__ = ["STLImporter", "DXFImporter", "TestModel"]
import pycam.Utils.log
import DXFImporter
import STLImporter
import pycam.Importers.DXFImporter
import pycam.Importers.STLImporter
import os
......@@ -40,9 +40,9 @@ def detect_file_type(filename):
# check all listed importers
# TODO: this should be done by evaluating the header of the file
if filename.endswith(".stl"):
return ("stl", STLImporter.ImportModel)
return ("stl", pycam.Importers.STLImporter.ImportModel)
elif filename.endswith(".dxf"):
return ("dxf", DXFImporter.import_model)
return ("dxf", pycam.Importers.DXFImporter.import_model)
else:
log.error("Importers: Failed to detect the model type of '%s'." \
% filename + " Is the file extension (.stl/.dxf) correct?")
......
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