TclCommandJoinGeometry.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from tclCommands.TclCommand import TclCommand
  2. from appObjects.FlatCAMGeometry import GeometryObject
  3. import collections
  4. class TclCommandJoinGeometry(TclCommand):
  5. """
  6. Tcl shell command to merge Excellon objects.
  7. example:
  8. """
  9. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  10. aliases = ['join_geometries', 'join_geometry']
  11. description = '%s %s' % ("--", "Merge two or more Geometry objects and create a new Geometry object.")
  12. # Dictionary of types from Tcl command, needs to be ordered
  13. arg_names = collections.OrderedDict([
  14. ('outname', str),
  15. ])
  16. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  17. option_types = collections.OrderedDict([
  18. ])
  19. # array of mandatory options for current Tcl command: required = {'name','outname'}
  20. required = ['outname']
  21. # structured help for current command, args needs to be ordered
  22. help = {
  23. 'main': "Runs a merge operation (join) on the Geometry objects.\n"
  24. "The names of the Geometry objects to be merged will be entered after the outname,\n"
  25. "separated by spaces. See the example below.\n"
  26. "WARNING: if the name of an Geometry objects has spaces, enclose the name with quotes.",
  27. 'args': collections.OrderedDict([
  28. ('outname', 'Name of the new Geometry Object made by joining of other Geometry objects. Required'),
  29. ]),
  30. 'examples': ['join_geometry merged_new_geo geo_name_1 "geo name_2"']
  31. }
  32. def execute(self, args, unnamed_args):
  33. """
  34. :param args:
  35. :param unnamed_args:
  36. :return:
  37. """
  38. outname = args['outname']
  39. obj_names = unnamed_args
  40. objs = []
  41. for obj_n in obj_names:
  42. obj = self.app.collection.get_by_name(str(obj_n))
  43. if obj is None:
  44. return "Object not found: %s" % obj_n
  45. else:
  46. objs.append(obj)
  47. def initialize(obj_, app):
  48. GeometryObject.merge(objs, obj_)
  49. if objs and len(objs) >= 2:
  50. self.app.app_obj.new_object("geometry", outname, initialize, plot=False)
  51. else:
  52. return "No Geometry objects to be joined or less than two Geometry objects specified for merging."