Преглед на файлове

- 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

Marius Stanciu преди 6 години
родител
ревизия
729b7cb11c
променени са 6 файла, в които са добавени 52 реда и са изтрити 19 реда
  1. 32 12
      FlatCAMApp.py
  2. 6 0
      README.md
  3. 1 0
      flatcamTools/ToolCutOut.py
  4. 0 1
      setup_ubuntu.sh
  5. 5 2
      tclCommands/TclCommandCutout.py
  6. 8 4
      tclCommands/TclCommandGeoCutout.py

+ 32 - 12
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':

+ 6 - 0
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

+ 1 - 0
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

+ 0 - 1
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

+ 5 - 2
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()

+ 8 - 4
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)]