TclCommandInteriors.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from ObjectCollection import *
  2. import TclCommand
  3. class TclCommandInteriors(TclCommand.TclCommand):
  4. """
  5. Tcl shell command to get interiors of polygons
  6. """
  7. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  8. aliases = ['interiors']
  9. # dictionary of types from Tcl command, needs to be ordered
  10. arg_names = collections.OrderedDict([
  11. ('name', str)
  12. ])
  13. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  14. option_types = collections.OrderedDict([
  15. ('outname', str)
  16. ])
  17. # array of mandatory options for current Tcl command: required = {'name','outname'}
  18. required = ['name']
  19. # structured help for current command, args needs to be ordered
  20. help = {
  21. 'main': "Get interiors of polygons.",
  22. 'args': collections.OrderedDict([
  23. ('name', 'Name of the source Geometry object.'),
  24. ('outname', 'Name of the resulting Geometry object.')
  25. ]),
  26. 'examples': []
  27. }
  28. def execute(self, args, unnamed_args):
  29. """
  30. execute current TCL shell command
  31. :param args: array of known named arguments and options
  32. :param unnamed_args: array of other values which were passed into command
  33. without -somename and we do not have them in known arg_names
  34. :return: None or exception
  35. """
  36. name = args['name']
  37. if 'outname' in args:
  38. outname = args['outname']
  39. else:
  40. outname = name + "_interiors"
  41. obj = self.app.collection.get_by_name(name)
  42. if obj is None:
  43. self.raise_tcl_error("Object not found: %s" % name)
  44. if not isinstance(obj, Geometry):
  45. self.raise_tcl_error('Expected Geometry, got %s %s.' % (name, type(obj)))
  46. def geo_init(geo_obj):
  47. geo_obj.solid_geometry = obj_exteriors
  48. obj_exteriors = obj.get_interiors()
  49. self.app.new_object('geometry', outname, geo_init)