From 3a3389359fb3383694cd692f17986c951d3a5d06 Mon Sep 17 00:00:00 2001 From: Krisjans Blukis Date: Tue, 8 May 2012 22:49:08 +0300 Subject: [PATCH 1/3] Fix: Renaming the Device Causes a Segmentation Fault Close and destroy old smatpen object and then re-use already existing doRefreshDeviceState() function to re-connect renamed smartpen. --- src/GUIFrame.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/GUIFrame.cc b/src/GUIFrame.cc index 351562e..c283449 100644 --- a/src/GUIFrame.cc +++ b/src/GUIFrame.cc @@ -706,10 +706,16 @@ void GUIFrame::RenameSmartpen(wxCommandEvent& event) { if (confirmationDialog.ShowModal() == wxID_YES) { printf("Request confirmed. Attempting to rename device...\n"); smartpen->setName((char*)desiredName.c_str()); - printf("returned from setting pen name. resetting device.\n"); + printf("returned from setting pen name. Disconnecting old smartpen instance.\n"); + smartpen->disconnect(); + printf("Destory old smartpen object."); + delete smartpen; + smartpen = NULL; + printf("Close usb decice connection"); libusb_close(dev); - dev = findSmartpen(); - printf("Retrieving smartpen name: %s\n", smartpen->getName()); + dev = NULL; + printf("Refresh decice. Device should be detected under new name.\n"); + doRefreshDeviceState(); } else printf("Rename operation cancelled.\n"); } } From bb3dcc6362d5990e9d0a4b0e8cfe3ecc4793424c Mon Sep 17 00:00:00 2001 From: Krisjans Blukis Date: Wed, 9 May 2012 23:50:50 +0300 Subject: [PATCH 2/3] Set line width in generated png files to 10 pixels. Lines with width of one pixel is hard to see on screen or printouts. --- stf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stf.py b/stf.py index 9d257a6..167c8a0 100644 --- a/stf.py +++ b/stf.py @@ -303,6 +303,7 @@ def handle_point(self, x, y, force, time): print float(bgGreen) print float(bgBlue) +ctx.set_line_width(10) ctx.set_source_rgb(float(bgRed), float(bgGreen), float(bgBlue)) ctx.paint() ctx.set_source_rgb(float(fgRed), float(fgGreen), float(fgBlue)) From 871cbe13473d6aa4e8f4825205d7c999b80adfd8 Mon Sep 17 00:00:00 2001 From: Krisjans Blukis Date: Thu, 10 May 2012 00:05:03 +0300 Subject: [PATCH 3/3] png generation: crop generated images to actual painting(scribing) area (Instead of generating 8000x8000 pixel blocks) --- stf.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/stf.py b/stf.py index 167c8a0..5c65bb8 100644 --- a/stf.py +++ b/stf.py @@ -292,7 +292,40 @@ def handle_point(self, x, y, force, time): assert False -surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 8000, 8000) +class PreParser(STFParser): + def __init__(self, *args): + super(PreParser, self).__init__(*args) + self.minx=8000 + self.miny=8000 + self.maxx=0 + self.maxy=0 + + def handle_point(self, x, y, f, time): + if f: + if x > self.maxx: + self.maxx=x + if x < self.minx: + self.minx=x + if y > self.maxy: + self.maxy=y + if y < self.miny: + self.miny=y + +try: + stf_file +except NameError: + stf_file = sys.argv[1] + +pref = file(stf_file) +prep = PreParser(pref) +prep.parse() + +if prep.maxx > 8000: + prep.maxx = 8000 +if prep.maxy > 8000: + prep.maxy = 8000 + +surface = cairo.ImageSurface(cairo.FORMAT_RGB24, prep.maxx-prep.minx, prep.maxy-prep.miny) ctx = cairo.Context(surface) print float(fgRed) @@ -320,9 +353,9 @@ def handle_stroke_end(self, time): def handle_point(self, x, y, f, time): if f: if self.last_force: - ctx.line_to(x, y) + ctx.line_to(x-prep.minx, y-prep.miny) else: - ctx.move_to(x, y) + ctx.move_to(x-prep.minx, y-prep.miny) self.last_force = 1 try: