TclCommandInteriors.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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: args = {'name': str}, this is for value without optionname
  10. arg_names = {'name': str}
  11. # dictionary of types from Tcl command: types = {'outname': str} , this is for options like -optionname value
  12. option_types = {'outname': str}
  13. # array of mandatory options for current Tcl command: required = {'name','outname'}
  14. required = ['name']
  15. # structured help for current command
  16. help = {
  17. 'main': "Get interiors of polygons.",
  18. 'args': {
  19. 'name': 'Name of the source Geometry object.',
  20. 'outname': 'Name of the resulting Geometry object.'
  21. },
  22. 'examples':[]
  23. }
  24. def execute(self, args, unnamed_args):
  25. """
  26. execute current TCL shell command
  27. :param args: array of known named arguments and options
  28. :param unnamed_args: array of other values which were passed into command
  29. without -somename and we do not have them in known arg_names
  30. :return: None or exception
  31. """
  32. name = args['name']
  33. if 'outname' in args:
  34. outname = args['outname']
  35. else:
  36. outname = name + "_interiors"
  37. try:
  38. obj = self.app.collection.get_by_name(name)
  39. except:
  40. self.app.raiseTclError("Could not retrieve object: %s" % name)
  41. if obj is None:
  42. self.app.raiseTclError("Object not found: %s" % name)
  43. if not isinstance(obj, Geometry):
  44. self.app.raiseTclError('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)