From 729b7cb11cc08d07683faa09b7bd077bfa8e3b9a Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Tue, 9 Jul 2019 13:58:33 +0300 Subject: [PATCH] - some changes in the app.on_togle_units() to make sure we don't try to convert empty parameters which may cause crashes on FlatCAM units change - updated setup_ubuntu.sh file - made sure to import certain libraries in some of the FlatCAM files and not to rely on chained imports --- FlatCAMApp.py | 44 ++++++++++++++++++++++-------- README.md | 6 ++++ flatcamTools/ToolCutOut.py | 1 + setup_ubuntu.sh | 1 - tclCommands/TclCommandCutout.py | 7 +++-- tclCommands/TclCommandGeoCutout.py | 12 +++++--- 6 files changed, 52 insertions(+), 19 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index a3f57ce8..cc21e7ff 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -3679,12 +3679,14 @@ class App(QtCore.QObject): def scale_options(sfactor): for dim in dimensions: if dim == 'excellon_toolchangexy': - coords_xy = [float(eval(a)) for a in self.defaults["excellon_toolchangexy"].split(",")] + coordinates = self.defaults["excellon_toolchangexy"].split(",") + coords_xy = [float(eval(a)) for a in coordinates if a != ''] coords_xy[0] *= sfactor coords_xy[1] *= sfactor self.options['excellon_toolchangexy'] = "%f, %f" % (coords_xy[0], coords_xy[1]) elif dim == 'geometry_toolchangexy': - coords_xy = [float(eval(a)) for a in self.defaults["geometry_toolchangexy"].split(",")] + coordinates = self.defaults["geometry_toolchangexy"].split(",") + coords_xy = [float(eval(a)) for a in coordinates if a != ''] coords_xy[0] *= sfactor coords_xy[1] *= sfactor self.options['geometry_toolchangexy'] = "%f, %f" % (coords_xy[0], coords_xy[1]) @@ -3725,38 +3727,48 @@ class App(QtCore.QObject): sptools[t] *= sfactor self.options['tools_solderpaste_tools'] += "%f," % sptools[t] elif dim == 'tools_solderpaste_xy_toolchange': - sp_coords = [float(eval(a)) for a in self.defaults["tools_solderpaste_xy_toolchange"].split(",")] + coordinates = self.defaults["tools_solderpaste_xy_toolchange"].split(",") + sp_coords = [float(eval(a)) for a in coordinates if a != ''] sp_coords[0] *= sfactor sp_coords[1] *= sfactor self.options['tools_solderpaste_xy_toolchange'] = "%f, %f" % (sp_coords[0], sp_coords[1]) elif dim == 'global_gridx' or dim == 'global_gridy': if new_units == 'IN': + val = 0.1 try: val = float(self.defaults[dim]) * sfactor - self.options[dim] = float('%.6f' % val) except Exception as e: log.debug('App.on_toggle_units().scale_defaults() --> %s' % str(e)) + + self.options[dim] = float('%.6f' % val) else: + val = 0.1 try: val = float(self.defaults[dim]) * sfactor - self.options[dim] = float('%.4f' % val) except Exception as e: log.debug('App.on_toggle_units().scale_defaults() --> %s' % str(e)) + + self.options[dim] = float('%.4f' % val) else: + val = 0.1 try: - self.options[dim] = float(self.options[dim]) * sfactor + val = float(self.options[dim]) * sfactor except Exception as e: log.debug('App.on_toggle_units().scale_options() --> %s' % str(e)) + self.options[dim] = val + def scale_defaults(sfactor): for dim in dimensions: if dim == 'excellon_toolchangexy': - coords_xy = [float(eval(a)) for a in self.defaults["excellon_toolchangexy"].split(",")] + coordinates = self.defaults["excellon_toolchangexy"].split(",") + coords_xy = [float(eval(a)) for a in coordinates if a != ''] coords_xy[0] *= sfactor coords_xy[1] *= sfactor self.defaults['excellon_toolchangexy'] = "%.4f, %.4f" % (coords_xy[0], coords_xy[1]) elif dim == 'geometry_toolchangexy': - coords_xy = [float(eval(a)) for a in self.defaults["geometry_toolchangexy"].split(",")] + coordinates = self.defaults["geometry_toolchangexy"].split(",") + coords_xy = [float(eval(a)) for a in coordinates if a != ''] coords_xy[0] *= sfactor coords_xy[1] *= sfactor self.defaults['geometry_toolchangexy'] = "%.4f, %.4f" % (coords_xy[0], coords_xy[1]) @@ -3797,29 +3809,37 @@ class App(QtCore.QObject): sptools[t] *= sfactor self.defaults['tools_solderpaste_tools'] += "%.4f," % sptools[t] elif dim == 'tools_solderpaste_xy_toolchange': - sp_coords = [float(eval(a)) for a in self.defaults["tools_solderpaste_xy_toolchange"].split(",")] + coordinates = self.defaults["tools_solderpaste_xy_toolchange"].split(",") + sp_coords = [float(eval(a)) for a in coordinates if a != ''] sp_coords[0] *= sfactor sp_coords[1] *= sfactor self.defaults['tools_solderpaste_xy_toolchange'] = "%.4f, %.4f" % (sp_coords[0], sp_coords[1]) elif dim == 'global_gridx' or dim == 'global_gridy': if new_units == 'IN': + val = 0.1 try: val = float(self.defaults[dim]) * sfactor - self.defaults[dim] = float('%.6f' % val) except Exception as e: log.debug('App.on_toggle_units().scale_defaults() --> %s' % str(e)) + + self.defaults[dim] = float('%.6f' % val) else: + val = 0.1 try: val = float(self.defaults[dim]) * sfactor - self.defaults[dim] = float('%.4f' % val) except Exception as e: log.debug('App.on_toggle_units().scale_defaults() --> %s' % str(e)) + + self.defaults[dim] = float('%.4f' % val) else: + val = 0.1 try: - self.defaults[dim] = float(self.defaults[dim]) * sfactor + val = float(self.defaults[dim]) * sfactor except Exception as e: log.debug('App.on_toggle_units().scale_defaults() --> %s' % str(e)) + self.defaults[dim] = val + # The scaling factor depending on choice of units. factor = 1/25.4 if new_units == 'MM': diff --git a/README.md b/README.md index 6df12a80..6e83d73e 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,12 @@ CAD program, and create G-Code for Isolation routing. ================================================= +9.07.2019 + +- some changes in the app.on_togle_units() to make sure we don't try to convert empty parameters which may cause crashes on FlatCAM units change +- updated setup_ubuntu.sh file +- made sure to import certain libraries in some of the FlatCAM files and not to rely on chained imports + 8.07.2019 - fixed bug that allowed empty tool in the tools generated in Geometry object diff --git a/flatcamTools/ToolCutOut.py b/flatcamTools/ToolCutOut.py index 4d3d7695..4db51fa7 100644 --- a/flatcamTools/ToolCutOut.py +++ b/flatcamTools/ToolCutOut.py @@ -2,6 +2,7 @@ from FlatCAMTool import FlatCAMTool from ObjectCollection import * from FlatCAMApp import * from shapely.geometry import box +from shapely.ops import cascaded_union, unary_union import gettext import FlatCAMTranslation as fcTranslate diff --git a/setup_ubuntu.sh b/setup_ubuntu.sh index 6a2249cf..7d3d4b95 100644 --- a/setup_ubuntu.sh +++ b/setup_ubuntu.sh @@ -14,7 +14,6 @@ apt-get install python3-tk apt-get install libspatialindex-dev apt-get install python3-gdal apt-get install python3-lxml -easy_install3 -U distribute pip3 install --upgrade dill pip3 install --upgrade Shapely pip3 install --upgrade vispy diff --git a/tclCommands/TclCommandCutout.py b/tclCommands/TclCommandCutout.py index 49bb5440..e4826acc 100644 --- a/tclCommands/TclCommandCutout.py +++ b/tclCommands/TclCommandCutout.py @@ -1,5 +1,7 @@ from ObjectCollection import * from tclCommands.TclCommand import TclCommand +from shapely.ops import cascaded_union +from shapely.geometry import LineString class TclCommandCutout(TclCommand): @@ -81,11 +83,12 @@ class TclCommandCutout(TclCommand): try: obj = self.app.collection.get_by_name(str(name)) - except: + except Exception as e: + log.debug("TclCommandCutout.execute() --> %s" % str(e)) return "Could not retrieve object: %s" % name def geo_init_me(geo_obj, app_obj): - margin = margin_par + dia_par / 2 + margin = margin_par + dia_par / 2 gap_size = dia_par + gapsize_par minx, miny, maxx, maxy = obj.bounds() diff --git a/tclCommands/TclCommandGeoCutout.py b/tclCommands/TclCommandGeoCutout.py index fb51c048..4a32df88 100644 --- a/tclCommands/TclCommandGeoCutout.py +++ b/tclCommands/TclCommandGeoCutout.py @@ -1,11 +1,15 @@ from ObjectCollection import * from tclCommands.TclCommand import TclCommandSignaled from copy import deepcopy +from shapely.ops import cascaded_union +from shapely.geometry import Polygon, LineString, LinearRing class TclCommandGeoCutout(TclCommandSignaled): """ - Tcl shell command to create a board cutout geometry. Allow cutout for any shape. Cuts holding gaps from geometry. + Tcl shell command to create a board cutout geometry. + Allow cutout for any shape. + Cuts holding gaps from geometry. example: @@ -66,9 +70,9 @@ class TclCommandGeoCutout(TclCommandSignaled): :return: """ - def subtract_rectangle(obj_, x0, y0, x1, y1): - pts = [(x0, y0), (x1, y0), (x1, y1), (x0, y1)] - obj_.subtract_polygon(pts) + # def subtract_rectangle(obj_, x0, y0, x1, y1): + # pts = [(x0, y0), (x1, y0), (x1, y1), (x0, y1)] + # obj_.subtract_polygon(pts) def substract_rectangle_geo(geo, x0, y0, x1, y1): pts = [(x0, y0), (x1, y0), (x1, y1), (x0, y1)]