TclCommandInteriors.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from tclCommands.TclCommand import TclCommandSignaled
  2. from camlib import Geometry
  3. import collections
  4. class TclCommandInteriors(TclCommandSignaled):
  5. """
  6. Tcl shell command to get interiors of polygons
  7. """
  8. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  9. aliases = ['interiors']
  10. description = '%s %s' % ("--", "Create a new Geometry object with the 'interiors' geo "
  11. "elements of the source 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': "Create a new Geometry object with the 'interiors' geometric elements of "
  25. "the specified source Geometry object.",
  26. 'args': collections.OrderedDict([
  27. ('name', 'Name of the source Geometry object. Required.'),
  28. ('outname', 'Name of the resulting Geometry object.')
  29. ]),
  30. 'examples': ['interiors my_geo_name -outname "outputed_geo"']
  31. }
  32. def execute(self, args, unnamed_args):
  33. """
  34. execute current TCL shell command
  35. :param args: array of known named arguments and options
  36. :param unnamed_args: array of other values which were passed into command
  37. without -somename and we do not have them in known arg_names
  38. :return: None or exception
  39. """
  40. name = args['name']
  41. if 'outname' in args:
  42. outname = args['outname']
  43. else:
  44. outname = name + "_interiors"
  45. obj = self.app.collection.get_by_name(name)
  46. if obj is None:
  47. self.raise_tcl_error("Object not found: %s" % name)
  48. if not isinstance(obj, Geometry):
  49. self.raise_tcl_error('Expected Geometry, got %s %s.' % (name, type(obj)))
  50. def geo_init(geo_obj, app_obj):
  51. geo_obj.solid_geometry = obj_interiors
  52. obj_interiors = obj.get_interiors()
  53. self.app.app_obj.new_object('geometry', outname, geo_init)