TclCommandExteriors.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from ObjectCollection import *
  2. import TclCommand
  3. class TclCommandExteriors(TclCommand.TclCommand):
  4. """
  5. Tcl shell command to get exteriors of polygons
  6. """
  7. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  8. aliases = ['exteriors','ext']
  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 exteriors 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 + "_exteriors"
  41. try:
  42. obj = self.app.collection.get_by_name(name)
  43. except:
  44. self.app.raiseTclError("Could not retrieve object: %s" % name)
  45. if obj is None:
  46. self.app.raiseTclError("Object not found: %s" % name)
  47. if not isinstance(obj, Geometry):
  48. self.app.raiseTclError('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.new_object('geometry', outname, geo_init)