Skip to content

Commit

Permalink
0.21 always start a new openscad instance if the command has changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnweiger committed Jan 21, 2018
1 parent 80b4e85 commit f92af81
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion paths2openscad.inx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ definition of 96 px = 1 inch = 25.4 mm.
(Before inkscape 0.92 the standard was 90 px per inch,
Adobe products often use 75 px per inch)

v0.20
v0.21
Dan Newman (dan newman @ mtbaldy us)
Josef Skladanka (jskladan @ redhat com)
Juergen Weigert (juergen @ fabmail org)
Expand Down
30 changes: 26 additions & 4 deletions paths2openscad.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
# 0.20 do not traverse into objects with style="display:none"
# some precondition checks had 'pass' but should have 'continue'.
#
# 2018-01-21, juergen@fabmail.org
# 0.21 start a new openscad instance if the command has changed.
#
# CAUTION: keep the version numnber in sync with paths2openscad.inx about page

# This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -1257,10 +1260,20 @@ def effect(self):
pidfile = tempfile.gettempdir() + os.sep + "paths2openscad.pid"
running = False
try:
m = re.match(r"(\d+)", open(pidfile).read())
pid = int(m.group(1))
m = re.match(r"(\d+)\s+(.*)", open(pidfile).read())
oldpid = int(m.group(1))
oldcmd = int(m.group(2))
# print >> sys.stderr, "pid {1} seen in {0}".format(pidfile, pid)
running = IsProcessRunning(pid)
if cmd == oldcmd:
# we found a pidfile and the cmd in there is still identical.
# If we change the filename in the inkscape extension gui, the cmd differs, and
# the still running openscad would not pick up our changes.
# If the command is identical, we check if the pid in the pidfile is alive.
# If so, we assume, the still running openscad will pick up the changes.
#
# WARNING: too much magic here. We cannot really test, if the last assumption holds.
# Comment out the next line to always start a new instance of openscad.
running = IsProcessRunning(oldpid)
except:
pass
if not running:
Expand All @@ -1275,9 +1288,16 @@ def effect(self):
except OSError as e:
raise OSError("%s failed: errno=%d %s" % (cmd, e.errno, e.strerror))
try:
open(pidfile, "w").write(str(proc.pid) + "\n")
open(pidfile, "w").write(str(proc.pid) + "\n" + cmd + "\n")
except:
pass
else:
## BUG alert:
# If user changes the file viewed in openscad (save with different name, re-open that name
# without closing openscad, again, the still running openscad does not
# pick up the changes. and we have no way to tell the difference if it did.
pass


if self.options.scad2stl == 'true' or self.options.stlpost == 'true':
stl_fname = self.basename + '.stl'
Expand All @@ -1289,7 +1309,9 @@ def effect(self):

import subprocess
try:
print >> sys.stderr, "fooo"
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print >> sys.stderr, "bar"
except OSError as e:
raise OSError("{0} failed: errno={1} {2}".format(cmd, e.errno, e.strerror))
stdout, stderr = proc.communicate()
Expand Down

0 comments on commit f92af81

Please sign in to comment.