diff --git a/appObjects/FlatCAMGeometry.py b/appObjects/FlatCAMGeometry.py index c7c3ee52..4cca8075 100644 --- a/appObjects/FlatCAMGeometry.py +++ b/appObjects/FlatCAMGeometry.py @@ -2278,6 +2278,8 @@ class GeometryObject(FlatCAMObj, Geometry): dia_cnc_dict.update({ 'tooldia': tooldia_val }) + if "optimization_type" not in tools_dict[tooluid_key]['data']: + tools_dict[tooluid_key]['data']["optimization_type"] = self.app.defaults["geometry_optimization_type"] # find the tool_dia associated with the tooluid_key # search in the self.tools for the sel_tool_dia and when found see what tooluid has diff --git a/appTools/ToolNCC.py b/appTools/ToolNCC.py index 7da7938e..5168ace7 100644 --- a/appTools/ToolNCC.py +++ b/appTools/ToolNCC.py @@ -2869,7 +2869,7 @@ class NonCopperClear(AppTool, Gerber): bounding_box = unary_union(geo_buff_list) elif ncc_sel_obj.kind == 'gerber': geo_n = unary_union(geo_n).convex_hull - bounding_box = unary_union(self.ncc_obj.solid_geometry).convex_hull.intersection(geo_n) + bounding_box = unary_union(ncc_sel_obj.solid_geometry).convex_hull.intersection(geo_n) bounding_box = bounding_box.buffer(distance=ncc_margin, join_style=base.JOIN_STYLE.mitre) else: self.app.inform.emit('[ERROR_NOTCL] %s' % _("The reference object type is not supported.")) @@ -3315,7 +3315,7 @@ class NonCopperClear(AppTool, Gerber): rest_geo = [] current_uid = 1 try: - tool = eval(self.app.defaults["tools_ncc_tools"])[0] + tool = eval(str(self.app.defaults["tools_ncc_tools"]))[0] except TypeError: tool = eval(self.app.defaults["tools_ncc_tools"]) diff --git a/tclCommands/TclCommandCopperClear.py b/tclCommands/TclCommandCopperClear.py index 94529d6f..6e0ad3c8 100644 --- a/tclCommands/TclCommandCopperClear.py +++ b/tclCommands/TclCommandCopperClear.py @@ -259,7 +259,7 @@ class TclCommandCopperClear(TclCommand): margin=margin, has_offset=has_offset, offset=offset, - method=method, + method=method_data, outname=outname, connect=connect, contour=contour, @@ -290,7 +290,7 @@ class TclCommandCopperClear(TclCommand): margin=margin, has_offset=has_offset, offset=offset, - method=method, + method=method_data, outname=outname, connect=connect, contour=contour, diff --git a/tclCommands/TclCommandMillDrills.py b/tclCommands/TclCommandMillDrills.py index 832738e6..ece29c45 100644 --- a/tclCommands/TclCommandMillDrills.py +++ b/tclCommands/TclCommandMillDrills.py @@ -93,8 +93,8 @@ class TclCommandMillDrills(TclCommandSignaled): else: args['use_thread'] = False - if not obj.drills: - self.raise_tcl_error("The Excellon object has no drills: %s" % name) + # if not obj.drills: + # self.raise_tcl_error("The Excellon object has no drills: %s" % name) try: if 'milled_dias' in args and args['milled_dias'] != 'all': diff --git a/tclCommands/TclCommandOpenFolder.py b/tclCommands/TclCommandOpenFolder.py new file mode 100644 index 00000000..0080822d --- /dev/null +++ b/tclCommands/TclCommandOpenFolder.py @@ -0,0 +1,48 @@ +from tclCommands.TclCommand import * +from PyQt5.QtWidgets import QFileDialog + + +class TclCommandOpenFolder(TclCommand): + """ + Tcl shell command to get open a folder browser dialog and return the result + + example: + open_folder + """ + + # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon) + aliases = ['open_folder'] + + # Dictionary of types from Tcl command, needs to be ordered + arg_names = collections.OrderedDict() + + # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value + option_types = collections.OrderedDict([ + ('dir', str) + ]) + + # array of mandatory options for current Tcl command: required = {'name','outname'} + required = [] + + # structured help for current command, args needs to be ordered + help = { + 'main': "Opens a dialog to browse for a folder", + 'args': collections.OrderedDict([ + ('dir', 'Initial directory to open') + ]), + 'examples': ['open_folder'] + } + + def execute(self, args, unnamed_args): + """ + execute current TCL shell command + + :param args: array of known named arguments and options + :param unnamed_args: array of other values which were passed into command + without -somename and we do not have them in known arg_names + :return: None or exception + """ + if "dir" in args: + return QFileDialog.getExistingDirectory(dir=args['dir']) + else: + return QFileDialog.getExistingDirectory() diff --git a/tclCommands/TclCommandSplitGeometry.py b/tclCommands/TclCommandSplitGeometry.py new file mode 100644 index 00000000..acbad273 --- /dev/null +++ b/tclCommands/TclCommandSplitGeometry.py @@ -0,0 +1,63 @@ +from tclCommands.TclCommand import TclCommand +from appObjects.FlatCAMGeometry import GeometryObject + +import collections +from copy import deepcopy + + +class TclCommandSplitGeometry(TclCommand): + """ + Tcl shell command to split a geometry by tools. + + example: + + """ + + # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon) + aliases = ['split_geometries', 'split_geometry'] + + description = '%s %s' % ( + "--", "Split one Geometry object into separate ones for each tool.") + + # Dictionary of types from Tcl command, needs to be ordered + arg_names = collections.OrderedDict([ + ('source_name', str), + ]) + + # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value + option_types = collections.OrderedDict([ + + ]) + + # array of mandatory options for current Tcl command: required = {'name','outname'} + required = ['source_name'] + + # structured help for current command, args needs to be ordered + help = { + 'main': "Creates a new geometry for every tool and fills it with the tools geometry data", + 'args': collections.OrderedDict([ + ('source_name', 'Name of the source Geometry Object. Required'), + ]), + 'examples': ['split_geometry my_geometry'] + } + + def execute(self, args, unnamed_args): + """ + + :param args: + :param unnamed_args: + :return: + """ + + obj: GeometryObject = self.app.collection.get_by_name( + str(args['source_name'])) + if obj is None: + return "Object not found: %s" % args['source_name'] + + for uid in list(obj.tools.keys()): + def initialize(new_obj, app): + new_obj.multigeo = True + new_obj.tools[uid] = deepcopy(obj.tools[uid]) + name = "{0}_tool_{1}".format(args['source_name'], uid) + self.app.app_obj.new_object( + "geometry", name, initialize, plot=False) diff --git a/tclCommands/__init__.py b/tclCommands/__init__.py index 3a49aa49..30971044 100644 --- a/tclCommands/__init__.py +++ b/tclCommands/__init__.py @@ -45,6 +45,7 @@ import tclCommands.TclCommandNewGerber import tclCommands.TclCommandOffset import tclCommands.TclCommandOpenDXF import tclCommands.TclCommandOpenExcellon +import tclCommands.TclCommandOpenFolder import tclCommands.TclCommandOpenGCode import tclCommands.TclCommandOpenGerber import tclCommands.TclCommandOpenProject @@ -63,6 +64,7 @@ import tclCommands.TclCommandSetOrigin import tclCommands.TclCommandSetPath import tclCommands.TclCommandSetSys import tclCommands.TclCommandSkew +import tclCommands.TclCommandSplitGeometry import tclCommands.TclCommandSubtractPoly import tclCommands.TclCommandSubtractRectangle import tclCommands.TclCommandVersion @@ -93,7 +95,8 @@ def register_all_commands(app, commands): :return: None """ - tcl_modules = {k: v for k, v in list(sys.modules.items()) if k.startswith('tclCommands.TclCommand')} + tcl_modules = {k: v for k, v in list( + sys.modules.items()) if k.startswith('tclCommands.TclCommand')} for key, mod in list(tcl_modules.items()): if key != 'tclCommands.TclCommand':