2019-10-24 23:10:52 +00:00
|
|
|
from camlib import Geometry
|
2019-01-03 19:25:08 +00:00
|
|
|
from tclCommands.TclCommand import *
|
|
|
|
|
|
|
|
|
|
|
|
class TclCommandAddPolygon(TclCommandSignaled):
|
|
|
|
"""
|
|
|
|
Tcl shell command to create a polygon in the given Geometry object
|
|
|
|
"""
|
|
|
|
|
|
|
|
# array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
|
|
|
|
aliases = ['add_polygon', 'add_poly']
|
|
|
|
|
2020-04-13 16:15:20 +00:00
|
|
|
description = '%s %s' % ("--", "Creates a polygon in the given Geometry object.")
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
# dictionary of types from Tcl command, needs to be ordered
|
|
|
|
arg_names = collections.OrderedDict([
|
|
|
|
('name', str)
|
|
|
|
])
|
|
|
|
|
|
|
|
# dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
|
|
|
|
option_types = collections.OrderedDict()
|
|
|
|
|
|
|
|
# array of mandatory options for current Tcl command: required = {'name','outname'}
|
|
|
|
required = ['name']
|
|
|
|
|
|
|
|
# structured help for current command, args needs to be ordered
|
|
|
|
help = {
|
|
|
|
'main': "Creates a polygon in the given Geometry object.",
|
|
|
|
'args': collections.OrderedDict([
|
|
|
|
('name', 'Name of the Geometry object to which to append the polygon.'),
|
|
|
|
('xi, yi', 'Coordinates of points in the polygon.')
|
|
|
|
]),
|
|
|
|
'examples': [
|
|
|
|
'add_polygon <name> <x0> <y0> <x1> <y1> <x2> <y2> [x3 y3 [...]]'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
def execute(self, args, unnamed_args):
|
|
|
|
"""
|
|
|
|
execute current TCL shell command
|
|
|
|
|
|
|
|
:param args: array of known named arguments and options
|
|
|
|
:param unnamed_args: array of other values which were passed into command
|
|
|
|
without -somename and we do not have them in known arg_names
|
|
|
|
:return: None or exception
|
|
|
|
"""
|
|
|
|
|
|
|
|
name = args['name']
|
|
|
|
|
|
|
|
obj = self.app.collection.get_by_name(name)
|
|
|
|
if obj is None:
|
|
|
|
self.raise_tcl_error("Object not found: %s" % name)
|
|
|
|
|
|
|
|
if not isinstance(obj, Geometry):
|
|
|
|
self.raise_tcl_error('Expected Geometry, got %s %s.' % (name, type(obj)))
|
|
|
|
|
|
|
|
if len(unnamed_args) % 2 != 0:
|
|
|
|
self.raise_tcl_error("Incomplete coordinates.")
|
|
|
|
|
2019-08-25 18:33:46 +00:00
|
|
|
nr_points = int(len(unnamed_args) / 2)
|
|
|
|
points = [[float(unnamed_args[2*i]), float(unnamed_args[2*i+1])] for i in range(nr_points)]
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
obj.add_polygon(points)
|
|
|
|
obj.plot()
|