TclCommandSplitGeometry.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from tclCommands.TclCommand import TclCommand
  2. from appObjects.FlatCAMGeometry import GeometryObject
  3. import collections
  4. from copy import deepcopy
  5. class TclCommandSplitGeometry(TclCommand):
  6. """
  7. Tcl shell command to split a geometry by tools.
  8. example:
  9. """
  10. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  11. aliases = ['split_geometries', 'split_geometry']
  12. description = '%s %s' % (
  13. "--", "Split one Geometry object into separate ones for each tool.")
  14. # Dictionary of types from Tcl command, needs to be ordered
  15. arg_names = collections.OrderedDict([
  16. ('source_name', str),
  17. ])
  18. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  19. option_types = collections.OrderedDict([
  20. ])
  21. # array of mandatory options for current Tcl command: required = {'name','outname'}
  22. required = ['source_name']
  23. # structured help for current command, args needs to be ordered
  24. help = {
  25. 'main': "Creates a new geometry for every tool and fills it with the tools geometry data",
  26. 'args': collections.OrderedDict([
  27. ('source_name', 'Name of the source Geometry Object. Required'),
  28. ]),
  29. 'examples': ['split_geometry my_geometry']
  30. }
  31. def execute(self, args, unnamed_args):
  32. """
  33. :param args:
  34. :param unnamed_args:
  35. :return:
  36. """
  37. obj: GeometryObject = self.app.collection.get_by_name(
  38. str(args['source_name']))
  39. if obj is None:
  40. return "Object not found: %s" % args['source_name']
  41. for uid in list(obj.tools.keys()):
  42. def initialize(new_obj, app):
  43. new_obj.multigeo = True
  44. new_obj.tools[uid] = deepcopy(obj.tools[uid])
  45. name = "{0}_tool_{1}".format(args['source_name'], uid)
  46. self.app.app_obj.new_object(
  47. "geometry", name, initialize, plot=False)