diff --git a/pad/exportMeta.sh b/pad/exportMeta.sh index 9defd4afd4727a92df005ff0ff8f2e543f6b9796..2ad45f6b059df11cb509e274630de6f6c45e361f 100644 --- a/pad/exportMeta.sh +++ b/pad/exportMeta.sh @@ -1,20 +1,23 @@ -for (( ; ; )); +for (( ; ; )); do mkdir -p svg eps + + rm -f svg/*.svg + rm -f eps/*.eps + echo 'prologues := 3; outputtemplate := "%c.eps";' > eps/metahoguet.eps.mp echo 'outputtemplate := "%c.svg";' > svg/metahoguet.svg.mp curl http://osp.constantvzw.org:9999/p/metahoguet/export/txt | tee -a eps/metahoguet.eps.mp >> svg/metahoguet.svg.mp - + cd svg mpost -interaction=batchmode -s 'outputformat="svg"' metahoguet.svg.mp cd .. cd eps mpost -interaction=batchmode -s 'outputformat="eps"' eps/metahoguet.eps.mp cd .. - sleep 3 + sleep 2 done - diff --git a/pad/index.html b/pad/index.html index 99db80bca88f92fa4f64256c1fea5e095b4d83af..cbbc138621f65150460f6e1cd2e0df4b7ed5a231 100644 --- a/pad/index.html +++ b/pad/index.html @@ -1,13 +1,13 @@ - - - - - - - - - - - + $( "body" ).keypress(function(event) { + var savehash = window.location.hash; + savehash = savehash.substring(1); + $( "body" ).append(''); + console.log(event.keyCode); + savehash += '-'+event.keyCode; + window.location.hash = savehash; + Zoom(); + }); + } - + $("body").on("click", "img", function(){ + var result = window.confirm('voulez-vous imprimer ce glyph ?'); + + if(result){ + var path = $(this).attr('src').split('?')[0].replace(/svg/g, 'eps'); + $.get('/api/ploteps/', { epsfile : path }); + } + }); + + setInterval(function(){ + stamp = (new Date).getTime(); + $("img").each(function () { + var src = $(this).attr('src').split('?')[0]; + $(this).attr('src', src + '?' + stamp); + }); + }, 7000); + + testing(); + + + diff --git a/plotter/api.py b/plotter/api.py index bade4b6f8669d277a19bfc11ed8d641e822c7f95..059d54e3faa88196b44c902b1875096b7209ab22 100644 --- a/plotter/api.py +++ b/plotter/api.py @@ -10,51 +10,81 @@ from plottertools.textbox import Textbox from chiplotle.geometry.core.coordinate import Coordinate from settings import db import os.path +import shutil from flask import Flask, Response, app, request, render_template marginleft = 30 # margin left in mm -marginbottom = (297 / 3) # margin bottom in mm +marginbottom = (271.75 / 3) # margin bottom in mm page = { - 'left': marginleft * -40, - 'right': (210 - marginleft) * 40, - 'bottom': marginbottom * -40, - 'top': (297 - marginbottom) * 40 + 'left': int(marginleft * -40), + 'right': int((190 - marginleft) * 40), + 'bottom': int(marginbottom * -40), + 'top': int((271.75 - marginbottom) * 40) } pen = 1 speed = 10 force = 1 -font=Font(path='fonts/converted/futural.fnt', resolution=1, scale=3) +font=Font(path='fonts/converted/futural.fnt', resolution=1, scale=4.5) app = Flask(__name__) @app.route("/api/ploteps/") def ploteps(): epsfile = request.args.get('epsfile') - hpglfile = './{}.hpgl'.format(os.path.splitext(epsfile)[0]) + charnum = os.path.splitext(os.path.basename(epsfile))[0] + svgfile = './svg/{}.svg'.format(charnum) + hpglfile = './hpgl/{}.hpgl'.format(charnum) + + shutil.copy(svgfile, './svg/snaps/{}-{}.svg'.format(charnum, int(time.time()))) # converting eps to hpgl subprocess.call([ - './eps2hpgl.sh', - './{0}'.format(epsfile) + 'pstoedit', + '-f', + 'plot-hpgl', + epsfile, + hpglfile ]) - handle = open(hpglfile) - shape = ''.join(handle.readlines()).replace('\n', '') + handle = open(hpglfile) + dirtyhpgl = ''.join(handle.readlines()).replace('\n', '') + cleanhpglchunks = [] + + pen = 1 + pencount = 4 + penmap = {} + + for chunk in dirtyhpgl.split(';'): + if chunk[0:2] in ['PA', 'PR', 'PU', 'PD']: + cleanhpglchunks.append(chunk) + elif chunk[0:2] == 'SP': + sourcepen = int(chunk[2]) + if not sourcepen in penmap: + pen += 1 + + if pen > pencount: + pen = 1 + + penmap[sourcepen] = pen + + cleanhpglchunks.append('SP{}'.format(penmap[sourcepen])) + + cleanhpgl = ';'.join(cleanhpglchunks) textbox = Textbox( font=font, - width = 50 * 40, - position = Coordinate(page['right'] - (55 * 40), page['bottom'] + (12 * 40)), + width = 75 * 40, + position = Coordinate(page['right'] - (80 * 40), page['bottom'] + (12 * 40)), align = Textbox.alignLeft, lineHeight=1.40 ) textbox.insertText('{0} \n{1} \n\ntype.code, Maison du Livre, Bruxelles'.format(hpglfile, datetime.now().strftime("%d-%m-%Y %H:%M"))) - hpgl = 'SC{0},{1},{2},{3};SP{4};FS{5};VS{6};PU;{7};PU;'.format(page['left'], page['right'], page['bottom'], page['top'], pen, force, speed, shape) + hpgl = 'IN;RO90;IP0,0,7600,10870;SC{0},{1},{2},{3};FS{5};SP{4};VS{6};PU;{7};PU;'.format(page['left'], page['right'], page['bottom'], page['top'], pen, force, speed, cleanhpgl) # hpgl += box((page['left'] + 200, page['bottom'] + 200), 200 * 40, 287 * 40) hpgl += textbox.hpgl() diff --git a/plotter/hpgl b/plotter/hpgl new file mode 120000 index 0000000000000000000000000000000000000000..4992dc969e086135a29b19522394b21f37077277 --- /dev/null +++ b/plotter/hpgl @@ -0,0 +1 @@ +../pad/hpgl \ No newline at end of file diff --git a/plotter/runner.py b/plotter/runner.py index db794a89c5951232ed3a21760b936c2b6b00afba..20b3d16b9a282d38347464b1804e9bcdea7d7f48 100644 --- a/plotter/runner.py +++ b/plotter/runner.py @@ -25,7 +25,7 @@ while True: if plot: try: - plotter.write(str(plot['hpgl'].decode('utf-8'))) + plotter.write('IN;{};PG;'.format(str(plot['hpgl'].decode('utf-8')))) plotter._serial_port.flush() diff --git a/plotter/svg b/plotter/svg new file mode 120000 index 0000000000000000000000000000000000000000..c8841c07058c4117e26e75ad2fdcab4b4ab2aed4 --- /dev/null +++ b/plotter/svg @@ -0,0 +1 @@ +../pad/svg/ \ No newline at end of file diff --git a/run.md b/run.md index ca45a3fe10d39616064cafad83102c17e6d3d080..0d7fcf3eb04b656ec27952c379269b5850d80ad2 100644 --- a/run.md +++ b/run.md @@ -1,16 +1,17 @@ % To run the API screen -S api -cd /home/pi/Documents/osp.work.metahoguet/plotter +cd /home/pi/Documents/osp.workshop.metahoguet/plotter . /home/pi/venvs/metahoguet/bin/activate -python wsgi.py +gunicorn --bind 0.0.0.0:5555 --workers 3 wsgi:app +sudo service nginx reload % !!! ctr+a d % To run the plotter screen -S plotter -cd /home/pi/Documents/osp.work.metahoguet/plotter +cd /home/pi/Documents/osp.workshop.metahoguet/plotter . /home/pi/venvs/metahoguet/bin/activate python runner.py @@ -20,7 +21,7 @@ python runner.py % To run the mpost downloaded screen -S mpost -cd /home/pi/Documents/osp.work.metahoguet/pad +cd /home/pi/Documents/osp.workshop.metahoguet/pad bash exportMeta.sh % !!! ctr+a d @@ -34,6 +35,6 @@ screen -r plotter python runner.py % !!! ctr+a d -screen -S mpost +screen -r mpost bash exportMeta.sh % !!! ctr+a d