Commit 3721bac4 authored by sumpfralle's avatar sumpfralle

added a "unit" parameter to the importers -> the svg/dxf importers can...

added a "unit" parameter to the importers -> the svg/dxf importers can re-scale the model now, if the user configured "mm" instead of "inch" (pstoedit seems to output scaled to inch)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@608 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent ccfb17c8
......@@ -400,9 +400,12 @@ if __name__ == "__main__":
model = get_default_model()
# the "get_default_model" function returns a string or a model
if isinstance(model, basestring):
model = load_model_file(model, program_locations)
model = load_model_file(model,
program_locations=program_locations,
unit=opts.unit_size)
else:
model = load_model_file(inputfile, program_locations)
model = load_model_file(inputfile,
program_locations=program_locations, unit=opts.unit_size)
if model is None:
# something went wrong - we quit
sys.exit(EXIT_CODES["load_model_failed"])
......
......@@ -1763,8 +1763,9 @@ class ProjectGui:
self.disable_progress_cancel_button()
self.model.scale(factor, callback=self.update_progress_bar)
self._set_model_center(old_center)
self.update_support_grid_model()
self.update_view()
self.append_to_queue(self.update_scale_controls)
self.append_to_queue(self.update_support_grid_model)
self.append_to_queue(self.update_view)
@gui_activity_guard
def update_scale_controls(self, widget=None):
......@@ -1864,7 +1865,8 @@ class ProjectGui:
file_type, importer = pycam.Importers.detect_file_type(filename)
if file_type and callable(importer):
self.load_model(importer(filename,
program_locations=program_locations))
program_locations=program_locations,
unit=self.settings.get("unit")))
self.set_model_filename(filename)
else:
log.error("Failed to detect filetype!")
......
......@@ -209,7 +209,7 @@ class DXFParser:
return None
def import_model(filename, program_locations=None):
def import_model(filename, program_locations=None, unit=None):
try:
infile = open(filename,"rb")
except IOError, err_msg:
......@@ -225,6 +225,10 @@ def import_model(filename, program_locations=None):
model = pycam.Geometry.Model.ContourModel()
for l in lines:
model.append(l)
if unit == "mm":
# pstoedit uses inch internally - we need to scale
log.info("DXFImporter: scaling model from inch to mm")
model.scale(25.4)
log.info("DXFImporter: Imported DXF model: %d lines" % len(lines))
return model
else:
......
......@@ -74,7 +74,7 @@ def UniqueEdge(p1, p2):
return e
def ImportModel(filename, use_kdtree=True, program_locations=None):
def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None):
global vertices, edges, kdtree
vertices = 0
edges = 0
......
......@@ -70,7 +70,7 @@ def convert_eps2dxf(eps_filename, dxf_filename, location=None):
process.stderr.read()))
return False
def import_model(filename, program_locations=None):
def import_model(filename, program_locations=None, unit=None):
if not os.path.isfile(filename):
log.error("SVGImporter: file (%s) does not exist" % filename)
return None
......@@ -116,7 +116,7 @@ def import_model(filename, program_locations=None):
result = None
else:
log.info("Successfully converted EPS file to DXF file")
result = pycam.Importers.DXFImporter.import_model(dxf_file_name)
result = pycam.Importers.DXFImporter.import_model(dxf_file_name, unit=unit)
# always remove the dxf file
remove_temp_file(dxf_file_name)
return result
......
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