TclCommandExteriors.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from tclCommands.TclCommand import TclCommandSignaled
  2. from camlib import Geometry
  3. import collections
  4. class TclCommandExteriors(TclCommandSignaled):
  5. """
  6. Tcl shell command to get exteriors of polygons
  7. """
  8. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  9. aliases = ['exteriors', 'ext']
  10. description = '%s %s' % ("--", "Get exteriors of polygons from a Geometry object and "
  11. "from them create a new Geometry object.")
  12. # dictionary of types from Tcl command, needs to be ordered
  13. arg_names = collections.OrderedDict([
  14. ('name', 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. ('outname', str)
  19. ])
  20. # array of mandatory options for current Tcl command: required = {'name','outname'}
  21. required = ['name']
  22. # structured help for current command, args needs to be ordered
  23. help = {
  24. 'main': "Get exteriors of polygons from a Geometry object and from them create a new Geometry object.",
  25. 'args': collections.OrderedDict([
  26. ('name', 'Name of the source Geometry object. Required.'),
  27. ('outname', 'Name of the resulting Geometry object.')
  28. ]),
  29. 'examples': ['ext geo_source_name -outname "final_geo"']
  30. }
  31. def execute(self, args, unnamed_args):
  32. """
  33. execute current TCL shell command
  34. :param args: array of known named arguments and options
  35. :param unnamed_args: array of other values which were passed into command
  36. without -somename and we do not have them in known arg_names
  37. :return: None or exception
  38. """
  39. name = args['name']
  40. if 'outname' in args:
  41. outname = args['outname']
  42. else:
  43. outname = name + "_exteriors"
  44. obj = self.app.collection.get_by_name(name)
  45. if obj is None:
  46. self.raise_tcl_error("Object not found: %s" % name)
  47. if not isinstance(obj, Geometry):
  48. self.raise_tcl_error('Expected Geometry, got %s %s.' % (name, type(obj)))
  49. def geo_init(geo_obj, app_obj):
  50. geo_obj.solid_geometry = obj_exteriors
  51. obj_exteriors = obj.get_exteriors()
  52. self.app.app_obj.new_object('geometry', outname, geo_init, plot=False)