TclCommandSplitGeometry.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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': "Runs a merge operation (join) on the Geometry objects.\n"
  26. "The names of the Geometry objects to be merged will be entered after the outname,\n"
  27. "separated by spaces. See the example below.\n"
  28. "WARNING: if the name of an Geometry objects has spaces, enclose the name with quotes.",
  29. 'args': collections.OrderedDict([
  30. ('source_name', 'Name of the new Geometry Object made by joining of other Geometry objects. Required'),
  31. ]),
  32. 'examples': ['join_geometry merged_new_geo geo_name_1 "geo name_2"']
  33. }
  34. def execute(self, args, unnamed_args):
  35. """
  36. :param args:
  37. :param unnamed_args:
  38. :return:
  39. """
  40. obj: GeometryObject = self.app.collection.get_by_name(
  41. str(args['source_name']))
  42. if obj is None:
  43. return "Object not found: %s" % args['source_name']
  44. for uid in list(obj.tools.keys()):
  45. def initialize(new_obj, app):
  46. new_obj.multigeo = True
  47. new_obj.tools[uid] = deepcopy(obj.tools[uid])
  48. name = "{0}_tool_{1}".format(args['source_name'], uid)
  49. self.app.app_obj.new_object(
  50. "geometry", name, initialize, plot=False)