slic3r / Slic3r

Open Source toolpath generator for 3D printers
https://slic3r.org/
GNU Affero General Public License v3.0
3.33k stars 1.29k forks source link

Feature Request: Temporary Filenames while saving #1844

Closed criede closed 7 years ago

criede commented 10 years ago

Hello,

It happened some times to me that I opened a gcode file in pronterface before slic3r finished generating it. That results in a partial print, according to murphys law after 2/3 of the whole object. Very annoying.

There is an easy fix for that that could be implemented easily in slic3r: When saving gcode, execute the following steps:

I would be very please if you could implement this small change.

Regards, Christian Riede

ledvinap commented 10 years ago

Renaming old file and placing it back on fail is probably too dangerous - it's far too easy to use old file unintentionally. But renaming new file only after g-code generation is successful is good idea ...

jonaskuehling commented 10 years ago

My support for this suggestion - leaving the gcode file somehow hidden or marked "temporary" as long as the file is still being generated would be happily appreciated on my site! Under Linux you could of course just put a leading dot into the filename to mark the file hidden during processing and remove the dot when the file is complete.

Good point.

kefir- commented 10 years ago

While I agree that using tempfiles during writing is a good idea, I don't think renaming the old file away as suggested is a good idea. Instead of solving an old problem again, why not just do the same as Firefox, for example? Firefox's logic seems to do something like this:

filename = "file.gcode"
file = create_file(filename)
if filename already existed:
  number = 1
  loop forever:
    filename = "file ($number).gcode"
    file = create_file(filename)
    if filename already existed:
      number = number + 1
      loop again
    else:
      break loop
temp = filename + ".part"
tempfile = create_file(temp)
write(tempfile, all_the_gcode)
close(tempfile)
close(file)
rename(temp, filename)

You could of course work around the entire issue by putting the timestamp in the output file name. I always do that anyway. But with this approach, even two instances of slic3r running at the same time, processing the same input file within the same second would just create two output files with different names, and you wouldn't overwrite old files by mistake.

alranel commented 10 years ago

@kefir-, the "Save as…" dialog displayed upon clicking on "Export G-code…" already handles the case by displaying a warning like "Are you sure you want to replace the file blah blah?" (system dependent message). So in that case I don't think Slic3r should automatically change the output name like the Firefox example. When using Slic3r from command line, I think it should obey the -o, --output option literally without reverting to other filenames (like any other UNIX command line program does). The "Quick Slice…" command should probably work like command line. So I don't think the Firefox example fits Slic3r entirely.

I agree with @ledvinap and @jonaskuehling: the best option would be to write to a temporary filename and rename it after successful generation. A dot filename would work on OS X and Linux; what about Windows?

kefir- commented 10 years ago

Agreed. :)

ledvinap commented 10 years ago

@alexrj : Browsers use .partial for in-progress files. Is there any advantage to hiding file while it is generated?

alranel commented 7 years ago

Done!