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