Commit 8d452189 authored by sumpfralle's avatar sumpfralle

show a little bit of activity when loading big model files


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@857 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 643306c3
......@@ -215,7 +215,7 @@ def load_fonts(callback=None):
progress_counter = None
for font_file in all_font_files:
charset = pycam.Importers.CXFImporter.import_font(font_file,
callback=progress_counter)
callback=progress_counter.update)
if (not progress_counter is None) and progress_counter.increment():
break
if not charset is None:
......@@ -1892,6 +1892,9 @@ class ProjectGui:
if self.view3d and not self.view3d.enabled:
# initialization failed - don't do anything
return
if not self.model:
# no model loaded - don't enable the window
return
current_state = not ((self.view3d is None) or (not self.view3d.is_visible))
if value is None:
new_state = not current_state
......@@ -2503,6 +2506,7 @@ class ProjectGui:
window.destroy()
@gui_activity_guard
@progress_activity_guard
def load_model_file(self, widget=None, filename=None):
if callable(filename):
filename = filename()
......@@ -2520,9 +2524,13 @@ class ProjectGui:
program_locations[key[len(prefix):]] = self.settings.get(key)
file_type, importer = pycam.Importers.detect_file_type(filename)
if file_type and callable(importer):
self.update_progress_bar(text="Loading model file ...")
# "cancel" is not allowed
self.disable_progress_cancel_button()
self.load_model(importer(filename,
program_locations=program_locations,
unit=self.settings.get("unit")))
unit=self.settings.get("unit"),
callback=self.update_progress_bar))
self.set_model_filename(filename)
else:
log.error("Failed to detect filetype!")
......@@ -2978,6 +2986,8 @@ class ProjectGui:
self._progress_start_time = time.time()
self.update_progress_bar("", 0)
self.progress_cancel_button.set_sensitive(True)
# enable "pulse" mode for a start (in case of unknown ETA)
self.progress_bar.pulse()
self.progress_widget.show()
else:
self.progress_widget.hide()
......@@ -2994,6 +3004,9 @@ class ProjectGui:
if not percent is None:
percent = min(max(percent, 0.0), 100.0)
self.progress_bar.set_fraction(percent/100.0)
if (percent is None) and (self.progress_bar.get_fraction() == 0):
# use "pulse" mode until we reach 1% of the work to be done
self.progress_bar.pulse()
# "estimated time of arrival" text
time_estimation_suffix = " remaining ..."
if self.progress_bar.get_fraction() > 0:
......
......@@ -105,7 +105,7 @@ class CXFParser(object):
# Update the GUI from time to time.
# This is useful for the big unicode font.
if self.callback and (len(self.letters) % 100 == 0):
self.callback.update()
self.callback()
if (len(line) >= 3) and (line[2] == "]"):
# single character
character = line[1]
......
......@@ -44,11 +44,12 @@ class DXFParser:
"COLOR": 62,
}
def __init__(self, inputstream):
def __init__(self, inputstream, callback=None):
self.inputstream = inputstream
self.line_number = 0
self.lines = []
self._input_stack = []
self.callback = callback
self.parse_content()
self.optimize_line_order()
......@@ -61,6 +62,8 @@ class DXFParser:
groups.append(current_group)
remaining_lines = self.lines[:]
while remaining_lines:
if self.callback and self.callback():
return
if not current_group:
current_group.append(remaining_lines.pop(0))
else:
......@@ -150,6 +153,8 @@ class DXFParser:
key, value = self._read_key_value()
while (not key is None) \
and not ((key == self.KEYS["MARKER"]) and (value == "EOF")):
if self.callback and self.callback():
return
if key == self.KEYS["MARKER"]:
if value in ("SECTION", "TABLE", "LAYER", "ENDTAB", "ENDSEC"):
# we don't handle these meta-information
......@@ -209,7 +214,7 @@ class DXFParser:
return None
def import_model(filename, program_locations=None, unit=None):
def import_model(filename, program_locations=None, unit=None, callback=None):
try:
infile = open(filename,"rb")
except IOError, err_msg:
......@@ -217,10 +222,14 @@ def import_model(filename, program_locations=None, unit=None):
% (filename, err_msg))
return None
result = DXFParser(infile)
result = DXFParser(infile, callback=callback)
lines = result.get_model()["lines"]
if callback and callback():
log.warn("DXFImporter: load model operation was cancelled")
return None
if lines:
model = pycam.Geometry.Model.ContourModel()
for l in lines:
......
......@@ -29,7 +29,7 @@ import os
log = pycam.Utils.log.get_logger()
def import_model(filename, program_locations=None, unit=None):
def import_model(filename, program_locations=None, unit=None, callback=None):
if not os.path.isfile(filename):
log.error("PSImporter: file (%s) does not exist" % filename)
return None
......@@ -53,9 +53,13 @@ def import_model(filename, program_locations=None, unit=None):
success = convert_eps2dxf(filename, dxf_file_name, location=pstoedit_path)
if not success:
result = None
elif callback and callback():
log.warn("PSImporter: load model operation canceled")
result = None
else:
log.info("Successfully converted PS file to DXF file")
result = pycam.Importers.DXFImporter.import_model(dxf_file_name, unit=unit)
result = pycam.Importers.DXFImporter.import_model(dxf_file_name,
unit=unit, callback=callback)
# always remove the dxf file
remove_temp_file(dxf_file_name)
return result
......
......@@ -53,7 +53,8 @@ def UniqueVertex(x, y, z):
vertices += 1
return Point(x, y, z)
def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None):
def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None,
callback=None):
global vertices, edges, kdtree
vertices = 0
edges = 0
......@@ -106,6 +107,9 @@ def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None):
if binary:
for i in range(1, numfacets + 1):
if callback and callback():
log.warn("STLImporter: load model operation cancelled")
return None
a1 = unpack("<f", f.read(4))[0]
a2 = unpack("<f", f.read(4))[0]
a3 = unpack("<f", f.read(4))[0]
......@@ -180,6 +184,9 @@ def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None):
current_line = 0
for line in f:
if callback and callback():
log.warn("STLImporter: load model operation cancelled")
return None
current_line += 1
m = solid.match(line)
if m:
......
......@@ -76,7 +76,7 @@ def convert_eps2dxf(eps_filename, dxf_filename, location=None):
process.stderr.read()))
return False
def import_model(filename, program_locations=None, unit=None):
def import_model(filename, program_locations=None, unit=None, callback=None):
if not os.path.isfile(filename):
log.error("SVGImporter: file (%s) does not exist" % filename)
return None
......@@ -110,6 +110,10 @@ def import_model(filename, program_locations=None, unit=None):
if not success:
remove_temp_file(eps_file_name)
return None
if callback and callback():
remove_temp_file(eps_file_name)
log.warn("SVGImporter: load model operation was cancelled")
return None
log.info("Successfully converted SVG file to EPS file")
# convert eps to dxf via pstoedit
......@@ -120,9 +124,13 @@ def import_model(filename, program_locations=None, unit=None):
remove_temp_file(eps_file_name)
if not success:
result = None
elif callback and callback():
log.warn("SVGImporter: load model operation was cancelled")
result = None
else:
log.info("Successfully converted EPS file to DXF file")
result = pycam.Importers.DXFImporter.import_model(dxf_file_name, unit=unit)
result = pycam.Importers.DXFImporter.import_model(dxf_file_name,
unit=unit, callback=callback)
# 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