ソースを参照

- some changes related to the fact that the geometry default tool diameter value can be comma separated string of tool diameters

Marius Stanciu 6 年 前
コミット
0e5e3a5227
5 ファイル変更73 行追加33 行削除
  1. 40 27
      FlatCAMApp.py
  2. 10 1
      FlatCAMCommon.py
  3. 9 1
      FlatCAMObj.py
  4. 2 1
      README.md
  5. 12 3
      camlib.py

+ 40 - 27
FlatCAMApp.py

@@ -5831,51 +5831,64 @@ class App(QtCore.QObject):
                     self.defaults['geometry_toolchangexy'] = "%.*f, %.*f" % (self.decimals, coords_xy[0],
                     self.defaults['geometry_toolchangexy'] = "%.*f, %.*f" % (self.decimals, coords_xy[0],
                                                                              self.decimals, coords_xy[1])
                                                                              self.decimals, coords_xy[1])
                 elif dim == 'geometry_cnctooldia':
                 elif dim == 'geometry_cnctooldia':
-                    tools_diameters = []
-                    try:
-                        tools_string = self.defaults["geometry_cnctooldia"].split(",")
-                        tools_diameters = [eval(a) for a in tools_string if a != '']
-                    except Exception as e:
-                        log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
-                        continue
+                    if type(self.defaults["geometry_cnctooldia"]) == float:
+                        tools_diameters = [self.defaults["geometry_cnctooldia"]]
+                    else:
+                        try:
+                            tools_string = self.defaults["geometry_cnctooldia"].split(",")
+                            tools_diameters = [eval(a) for a in tools_string if a != '']
+                        except Exception as e:
+                            log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
+                            continue
 
 
                     self.defaults['geometry_cnctooldia'] = ''
                     self.defaults['geometry_cnctooldia'] = ''
                     for t in range(len(tools_diameters)):
                     for t in range(len(tools_diameters)):
                         tools_diameters[t] *= sfactor
                         tools_diameters[t] *= sfactor
                         self.defaults['geometry_cnctooldia'] += "%.*f," % (self.decimals, tools_diameters[t])
                         self.defaults['geometry_cnctooldia'] += "%.*f," % (self.decimals, tools_diameters[t])
                 elif dim == 'tools_ncctools':
                 elif dim == 'tools_ncctools':
-                    ncctools = []
-                    try:
-                        tools_string = self.defaults["tools_ncctools"].split(",")
-                        ncctools = [eval(a) for a in tools_string if a != '']
-                    except Exception as e:
-                        log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
-                        continue
+                    ncctools = list()
+                    if type(self.defaults["tools_ncctools"]) == float:
+                        ncctools = [self.defaults["tools_ncctools"]]
+                    else:
+                        try:
+                            tools_string = self.defaults["tools_ncctools"].split(",")
+                            ncctools = [eval(a) for a in tools_string if a != '']
+                        except Exception as e:
+                            log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
+                            continue
 
 
                     self.defaults['tools_ncctools'] = ''
                     self.defaults['tools_ncctools'] = ''
                     for t in range(len(ncctools)):
                     for t in range(len(ncctools)):
                         ncctools[t] *= sfactor
                         ncctools[t] *= sfactor
                         self.defaults['tools_ncctools'] += "%.*f," % (self.decimals, ncctools[t])
                         self.defaults['tools_ncctools'] += "%.*f," % (self.decimals, ncctools[t])
                 elif dim == 'tools_solderpaste_tools':
                 elif dim == 'tools_solderpaste_tools':
-                    sptools = []
-                    try:
-                        tools_string = self.defaults["tools_solderpaste_tools"].split(",")
-                        sptools = [eval(a) for a in tools_string if a != '']
-                    except Exception as e:
-                        log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
-                        continue
+                    sptools = list()
+                    if type(self.defaults["tools_solderpaste_tools"]) == float:
+                        sptools = [self.defaults["tools_solderpaste_tools"]]
+                    else:
+                        try:
+                            tools_string = self.defaults["tools_solderpaste_tools"].split(",")
+                            sptools = [eval(a) for a in tools_string if a != '']
+                        except Exception as e:
+                            log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
+                            continue
 
 
                     self.defaults['tools_solderpaste_tools'] = ""
                     self.defaults['tools_solderpaste_tools'] = ""
                     for t in range(len(sptools)):
                     for t in range(len(sptools)):
                         sptools[t] *= sfactor
                         sptools[t] *= sfactor
                         self.defaults['tools_solderpaste_tools'] += "%.*f," % (self.decimals, sptools[t])
                         self.defaults['tools_solderpaste_tools'] += "%.*f," % (self.decimals, sptools[t])
                 elif dim == 'tools_solderpaste_xy_toolchange':
                 elif dim == 'tools_solderpaste_xy_toolchange':
-                    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'] = "%.*f, %.*f" % (self.decimals, sp_coords[0],
-                                                                                       self.decimals, sp_coords[1])
+                    try:
+                        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'] = "%.*f, %.*f" % (self.decimals, sp_coords[0],
+                                                                                           self.decimals, sp_coords[1])
+                    except Exception as e:
+                        log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
+                        continue
+
                 elif dim == 'global_gridx' or dim == 'global_gridy':
                 elif dim == 'global_gridx' or dim == 'global_gridy':
                     if new_units == 'IN':
                     if new_units == 'IN':
                         val = 0.1
                         val = 0.1

+ 10 - 1
FlatCAMCommon.py

@@ -1007,7 +1007,16 @@ class ToolsDB(QtWidgets.QWidget):
 
 
         dict_elem = dict()
         dict_elem = dict()
         dict_elem['name'] = 'new_tool'
         dict_elem['name'] = 'new_tool'
-        dict_elem['tooldia'] = self.app.defaults["geometry_cnctooldia"]
+        if type(self.app.defaults["geometry_cnctooldia"]) == float:
+            dict_elem['tooldia'] = self.app.defaults["geometry_cnctooldia"]
+        else:
+            try:
+                tools_string = self.defaults["geometry_cnctooldia"].split(",")
+                tools_diameters = [eval(a) for a in tools_string if a != '']
+                dict_elem['tooldia'] = tools_diameters[0] if tools_diameters else 0.0
+            except Exception as e:
+                self.app.log.debug("ToolDB.build_db_ui.on_tool_add() --> %s" % str(e))
+
         dict_elem['offset'] = 'Path'
         dict_elem['offset'] = 'Path'
         dict_elem['offset_value'] = 0.0
         dict_elem['offset_value'] = 0.0
         dict_elem['type'] = 'Rough'
         dict_elem['type'] = 'Rough'

+ 9 - 1
FlatCAMObj.py

@@ -3588,7 +3588,15 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
         })
         })
 
 
         if "cnctooldia" not in self.options:
         if "cnctooldia" not in self.options:
-            self.options["cnctooldia"] = self.app.defaults["geometry_cnctooldia"]
+            if type(self.app.defaults["geometry_cnctooldia"]) == float:
+                self.options["cnctooldia"] = self.app.defaults["geometry_cnctooldia"]
+            else:
+                try:
+                    tools_string = self.app.defaults["geometry_cnctooldia"].split(",")
+                    tools_diameters = [eval(a) for a in tools_string if a != '']
+                    self.options["cnctooldia"] = tools_diameters[0] if tools_diameters else 0.0
+                except Exception as e:
+                    log.debug("FlatCAMObj.FlatCAMGeometry.init() --> %s" % str(e))
 
 
         self.options["startz"] = self.app.defaults["geometry_startz"]
         self.options["startz"] = self.app.defaults["geometry_startz"]
 
 

+ 2 - 1
README.md

@@ -15,13 +15,14 @@ CAD program, and create G-Code for Isolation routing.
 - added a method to darken the outline color for Gerber objects when they have the color set
 - added a method to darken the outline color for Gerber objects when they have the color set
 - when Printing as PDF Gerber objects now the rendered color is the print color
 - when Printing as PDF Gerber objects now the rendered color is the print color
 - speed up the plotting in OpenGL(3D) graphic mode
 - speed up the plotting in OpenGL(3D) graphic mode
-- spped up the color setting for Gerber object when using the OpenGL(3D) graphic mode
+- speed up the color setting for Gerber object when using the OpenGL(3D) graphic mode
 - setting color for Gerber objects work on a selection of Gerber objects
 - setting color for Gerber objects work on a selection of Gerber objects
 - ~~when the selection is changed in the Project Tree the selection shape on canvas is deleted~~
 - ~~when the selection is changed in the Project Tree the selection shape on canvas is deleted~~
 - if an object is selected on Project Tree and it does not have the selection shape drawn, first click on canvas over it will draw the selection shape 
 - if an object is selected on Project Tree and it does not have the selection shape drawn, first click on canvas over it will draw the selection shape 
 - in Tool Transform added a new feature named 'Buffer'. For Geometry and Gerber objects will create (and replace) a geometry at a distance from the original geometry and for Excellon will adjust the Tool diameters
 - in Tool Transform added a new feature named 'Buffer'. For Geometry and Gerber objects will create (and replace) a geometry at a distance from the original geometry and for Excellon will adjust the Tool diameters
 - solved issue #355 - when the tool diameter field in the Edit → Preferences → Geometry → Geometry General → Tools → Tool dia is only one the app failed to read it
 - solved issue #355 - when the tool diameter field in the Edit → Preferences → Geometry → Geometry General → Tools → Tool dia is only one the app failed to read it
 - solved issue #356 - in Tools DB can not be added more than one tool if a translation is active 
 - solved issue #356 - in Tools DB can not be added more than one tool if a translation is active 
+- some changes related to the fact that the geometry default tool diameter value can be comma separated string of tool diameters
 
 
 22.12.2019
 22.12.2019
 
 

+ 12 - 3
camlib.py

@@ -3466,11 +3466,20 @@ class CNCjob(Geometry):
         flat_geometry = self.flatten(temp_solid_geometry, pathonly=True)
         flat_geometry = self.flatten(temp_solid_geometry, pathonly=True)
         log.debug("%d paths" % len(flat_geometry))
         log.debug("%d paths" % len(flat_geometry))
 
 
+        if type(self.app.defaults["geometry_cnctooldia"]) == float:
+            default_dia = self.app.defaults["geometry_cnctooldia"]
+        else:
+            try:
+                tools_string = self.defaults["geometry_cnctooldia"].split(",")
+                tools_diameters = [eval(a) for a in tools_string if a != '']
+                default_dia = tools_diameters[0] if tools_diameters else 0.0
+            except Exception as e:
+                self.app.log.debug("camlib.CNCJob.generate_from_geometry_2() --> %s" % str(e))
+
         try:
         try:
-            self.tooldia = float(tooldia) if tooldia else self.app.defaults["geometry_cnctooldia"]
+            self.tooldia = float(tooldia) if tooldia else default_dia
         except ValueError:
         except ValueError:
-            self.tooldia = [float(el) for el in tooldia.split(',') if el != ''] if tooldia is not None else \
-                self.app.defaults["geometry_cnctooldia"]
+            self.tooldia = [float(el) for el in tooldia.split(',') if el != ''] if tooldia is not None else default_dia
 
 
         self.z_cut = float(z_cut) if z_cut is not None else self.app.defaults["geometry_cutz"]
         self.z_cut = float(z_cut) if z_cut is not None else self.app.defaults["geometry_cutz"]
         self.z_move = float(z_move) if z_move is not None else self.app.defaults["geometry_travelz"]
         self.z_move = float(z_move) if z_move is not None else self.app.defaults["geometry_travelz"]