TclCommandInteriors.py 2.0 KB

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