traci._polygon
1# -*- coding: utf-8 -*- 2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3# Copyright (C) 2011-2026 German Aerospace Center (DLR) and others. 4# This program and the accompanying materials are made available under the 5# terms of the Eclipse Public License 2.0 which is available at 6# https://www.eclipse.org/legal/epl-2.0/ 7# This Source Code may also be made available under the following Secondary 8# Licenses when the conditions for such availability set forth in the Eclipse 9# Public License 2.0 are satisfied: GNU General Public License, version 2 10# or later which is available at 11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 14# @file _polygon.py 15# @author Michael Behrisch 16# @date 2011-03-16 17 18from __future__ import absolute_import 19from .domain import Domain 20from . import constants as tc 21 22_RETURN_VALUE_FUNC = {tc.VAR_FILL: lambda result: bool(result.read("!i")[0])} 23 24 25class PolygonDomain(Domain): 26 27 def __init__(self): 28 Domain.__init__(self, "polygon", tc.CMD_GET_POLYGON_VARIABLE, tc.CMD_SET_POLYGON_VARIABLE, 29 tc.CMD_SUBSCRIBE_POLYGON_VARIABLE, tc.RESPONSE_SUBSCRIBE_POLYGON_VARIABLE, 30 tc.CMD_SUBSCRIBE_POLYGON_CONTEXT, tc.RESPONSE_SUBSCRIBE_POLYGON_CONTEXT, 31 _RETURN_VALUE_FUNC) 32 33 def getType(self, polygonID): 34 """getType(string) -> string 35 36 Returns the (abstract) type of the polygon. 37 """ 38 return self._getUniversal(tc.VAR_TYPE, polygonID) 39 40 def getShape(self, polygonID): 41 """getShape(string) -> tuple((double, double)) 42 43 Returns the shape (tuple of 2D-positions) of this polygon. 44 """ 45 return self._getUniversal(tc.VAR_SHAPE, polygonID) 46 47 def getColor(self, polygonID): 48 """getColor(string) -> (integer, integer, integer, integer) 49 50 Returns the rgba color of this polygon. 51 """ 52 return self._getUniversal(tc.VAR_COLOR, polygonID) 53 54 def getFilled(self, polygonID): 55 """getFilled(string) -> bool 56 Returns whether the polygon is filled 57 """ 58 return self._getUniversal(tc.VAR_FILL, polygonID) 59 60 def getLineWidth(self, polygonID): 61 """getLineWidth(string) -> double 62 Returns drawing width of unfilled polygon 63 """ 64 return self._getUniversal(tc.VAR_WIDTH, polygonID) 65 66 def setType(self, polygonID, polygonType): 67 """setType(string, string) -> None 68 69 Sets the (abstract) type of the polygon. 70 """ 71 self._setCmd(tc.VAR_TYPE, polygonID, "s", polygonType) 72 73 def setShape(self, polygonID, shape): 74 """setShape(string, list((double, double))) -> None 75 76 Sets the shape (list of 2D-positions) of this polygon. 77 """ 78 self._setCmd(tc.VAR_SHAPE, polygonID, "p", shape) 79 80 def setColor(self, polygonID, color): 81 """setColor(string, (integer, integer, integer, integer)) -> None 82 83 Sets the rgba color of this polygon, i.e. (255,0,0) for the color red. 84 The fourth component (alpha) is optional. 85 """ 86 self._setCmd(tc.VAR_COLOR, polygonID, "c", color) 87 88 def setFilled(self, polygonID, filled): 89 """setFilled(string, bool) -> None 90 Sets the filled status of the polygon 91 """ 92 self._setCmd(tc.VAR_FILL, polygonID, "i", filled) 93 94 def setLineWidth(self, polygonID, lineWidth): 95 """setLineWidth(string, double) -> None 96 Sets the line width for drawing unfilled polygon 97 """ 98 self._setCmd(tc.VAR_WIDTH, polygonID, "d", lineWidth) 99 100 def add(self, polygonID, shape, color, fill=False, polygonType="", layer=0, lineWidth=1): 101 """add(string, list((double, double)), (integer, integer, integer, integer), 102 bool, string, integer, double) -> None 103 Adds a new polygon. 104 """ 105 self._setCmd(tc.ADD, polygonID, "tscBipd", 6, polygonType, color, fill, layer, shape, lineWidth) 106 107 def addDynamics(self, polygonID, trackedObjectID="", timeSpan=(), alphaSpan=(), looped=False, rotate=True): 108 """ addDynamics(string, string, list(float), list(float), bool) -> void 109 polygonID - ID of the polygon, upon which the specified dynamics shall act 110 trackedObjectID - ID of a SUMO traffic object, which shall be tracked by the polygon 111 timeSpan - list of time points for timing the animation keyframes (must start with element zero) 112 If it has length zero, no animation is taken into account. 113 alphaSpan - list of alpha values to be attained at keyframes intermediate values are 114 obtained by linear interpolation. Must have length equal to timeSpan, or zero 115 if no alpha animation is desired. 116 looped - Whether the animation should restart when the last keyframe is reached. In that case 117 the animation jumps to the first keyframe as soon as the last is reached. 118 If looped==false, the controlled polygon is removed as soon as the timeSpan elapses. 119 rotate - Whether, the polygon should be rotated with the tracked object (only applies when such is given) 120 The center of rotation is the object's position. 121 """ 122 self._setCmd(tc.VAR_ADD_DYNAMICS, polygonID, "tsffBB", 5, trackedObjectID, timeSpan, alphaSpan, looped, rotate) 123 124 def remove(self, polygonID, layer=0): 125 """remove(string, integer) -> None 126 Removes a polygon with the given ID 127 """ 128 self._setCmd(tc.REMOVE, polygonID, "i", layer)
26class PolygonDomain(Domain): 27 28 def __init__(self): 29 Domain.__init__(self, "polygon", tc.CMD_GET_POLYGON_VARIABLE, tc.CMD_SET_POLYGON_VARIABLE, 30 tc.CMD_SUBSCRIBE_POLYGON_VARIABLE, tc.RESPONSE_SUBSCRIBE_POLYGON_VARIABLE, 31 tc.CMD_SUBSCRIBE_POLYGON_CONTEXT, tc.RESPONSE_SUBSCRIBE_POLYGON_CONTEXT, 32 _RETURN_VALUE_FUNC) 33 34 def getType(self, polygonID): 35 """getType(string) -> string 36 37 Returns the (abstract) type of the polygon. 38 """ 39 return self._getUniversal(tc.VAR_TYPE, polygonID) 40 41 def getShape(self, polygonID): 42 """getShape(string) -> tuple((double, double)) 43 44 Returns the shape (tuple of 2D-positions) of this polygon. 45 """ 46 return self._getUniversal(tc.VAR_SHAPE, polygonID) 47 48 def getColor(self, polygonID): 49 """getColor(string) -> (integer, integer, integer, integer) 50 51 Returns the rgba color of this polygon. 52 """ 53 return self._getUniversal(tc.VAR_COLOR, polygonID) 54 55 def getFilled(self, polygonID): 56 """getFilled(string) -> bool 57 Returns whether the polygon is filled 58 """ 59 return self._getUniversal(tc.VAR_FILL, polygonID) 60 61 def getLineWidth(self, polygonID): 62 """getLineWidth(string) -> double 63 Returns drawing width of unfilled polygon 64 """ 65 return self._getUniversal(tc.VAR_WIDTH, polygonID) 66 67 def setType(self, polygonID, polygonType): 68 """setType(string, string) -> None 69 70 Sets the (abstract) type of the polygon. 71 """ 72 self._setCmd(tc.VAR_TYPE, polygonID, "s", polygonType) 73 74 def setShape(self, polygonID, shape): 75 """setShape(string, list((double, double))) -> None 76 77 Sets the shape (list of 2D-positions) of this polygon. 78 """ 79 self._setCmd(tc.VAR_SHAPE, polygonID, "p", shape) 80 81 def setColor(self, polygonID, color): 82 """setColor(string, (integer, integer, integer, integer)) -> None 83 84 Sets the rgba color of this polygon, i.e. (255,0,0) for the color red. 85 The fourth component (alpha) is optional. 86 """ 87 self._setCmd(tc.VAR_COLOR, polygonID, "c", color) 88 89 def setFilled(self, polygonID, filled): 90 """setFilled(string, bool) -> None 91 Sets the filled status of the polygon 92 """ 93 self._setCmd(tc.VAR_FILL, polygonID, "i", filled) 94 95 def setLineWidth(self, polygonID, lineWidth): 96 """setLineWidth(string, double) -> None 97 Sets the line width for drawing unfilled polygon 98 """ 99 self._setCmd(tc.VAR_WIDTH, polygonID, "d", lineWidth) 100 101 def add(self, polygonID, shape, color, fill=False, polygonType="", layer=0, lineWidth=1): 102 """add(string, list((double, double)), (integer, integer, integer, integer), 103 bool, string, integer, double) -> None 104 Adds a new polygon. 105 """ 106 self._setCmd(tc.ADD, polygonID, "tscBipd", 6, polygonType, color, fill, layer, shape, lineWidth) 107 108 def addDynamics(self, polygonID, trackedObjectID="", timeSpan=(), alphaSpan=(), looped=False, rotate=True): 109 """ addDynamics(string, string, list(float), list(float), bool) -> void 110 polygonID - ID of the polygon, upon which the specified dynamics shall act 111 trackedObjectID - ID of a SUMO traffic object, which shall be tracked by the polygon 112 timeSpan - list of time points for timing the animation keyframes (must start with element zero) 113 If it has length zero, no animation is taken into account. 114 alphaSpan - list of alpha values to be attained at keyframes intermediate values are 115 obtained by linear interpolation. Must have length equal to timeSpan, or zero 116 if no alpha animation is desired. 117 looped - Whether the animation should restart when the last keyframe is reached. In that case 118 the animation jumps to the first keyframe as soon as the last is reached. 119 If looped==false, the controlled polygon is removed as soon as the timeSpan elapses. 120 rotate - Whether, the polygon should be rotated with the tracked object (only applies when such is given) 121 The center of rotation is the object's position. 122 """ 123 self._setCmd(tc.VAR_ADD_DYNAMICS, polygonID, "tsffBB", 5, trackedObjectID, timeSpan, alphaSpan, looped, rotate) 124 125 def remove(self, polygonID, layer=0): 126 """remove(string, integer) -> None 127 Removes a polygon with the given ID 128 """ 129 self._setCmd(tc.REMOVE, polygonID, "i", layer)
34 def getType(self, polygonID): 35 """getType(string) -> string 36 37 Returns the (abstract) type of the polygon. 38 """ 39 return self._getUniversal(tc.VAR_TYPE, polygonID)
getType(string) -> string
Returns the (abstract) type of the polygon.
41 def getShape(self, polygonID): 42 """getShape(string) -> tuple((double, double)) 43 44 Returns the shape (tuple of 2D-positions) of this polygon. 45 """ 46 return self._getUniversal(tc.VAR_SHAPE, polygonID)
getShape(string) -> tuple((double, double))
Returns the shape (tuple of 2D-positions) of this polygon.
48 def getColor(self, polygonID): 49 """getColor(string) -> (integer, integer, integer, integer) 50 51 Returns the rgba color of this polygon. 52 """ 53 return self._getUniversal(tc.VAR_COLOR, polygonID)
getColor(string) -> (integer, integer, integer, integer)
Returns the rgba color of this polygon.
55 def getFilled(self, polygonID): 56 """getFilled(string) -> bool 57 Returns whether the polygon is filled 58 """ 59 return self._getUniversal(tc.VAR_FILL, polygonID)
getFilled(string) -> bool Returns whether the polygon is filled
61 def getLineWidth(self, polygonID): 62 """getLineWidth(string) -> double 63 Returns drawing width of unfilled polygon 64 """ 65 return self._getUniversal(tc.VAR_WIDTH, polygonID)
getLineWidth(string) -> double Returns drawing width of unfilled polygon
67 def setType(self, polygonID, polygonType): 68 """setType(string, string) -> None 69 70 Sets the (abstract) type of the polygon. 71 """ 72 self._setCmd(tc.VAR_TYPE, polygonID, "s", polygonType)
setType(string, string) -> None
Sets the (abstract) type of the polygon.
74 def setShape(self, polygonID, shape): 75 """setShape(string, list((double, double))) -> None 76 77 Sets the shape (list of 2D-positions) of this polygon. 78 """ 79 self._setCmd(tc.VAR_SHAPE, polygonID, "p", shape)
setShape(string, list((double, double))) -> None
Sets the shape (list of 2D-positions) of this polygon.
81 def setColor(self, polygonID, color): 82 """setColor(string, (integer, integer, integer, integer)) -> None 83 84 Sets the rgba color of this polygon, i.e. (255,0,0) for the color red. 85 The fourth component (alpha) is optional. 86 """ 87 self._setCmd(tc.VAR_COLOR, polygonID, "c", color)
setColor(string, (integer, integer, integer, integer)) -> None
Sets the rgba color of this polygon, i.e. (255,0,0) for the color red. The fourth component (alpha) is optional.
89 def setFilled(self, polygonID, filled): 90 """setFilled(string, bool) -> None 91 Sets the filled status of the polygon 92 """ 93 self._setCmd(tc.VAR_FILL, polygonID, "i", filled)
setFilled(string, bool) -> None Sets the filled status of the polygon
95 def setLineWidth(self, polygonID, lineWidth): 96 """setLineWidth(string, double) -> None 97 Sets the line width for drawing unfilled polygon 98 """ 99 self._setCmd(tc.VAR_WIDTH, polygonID, "d", lineWidth)
setLineWidth(string, double) -> None Sets the line width for drawing unfilled polygon
101 def add(self, polygonID, shape, color, fill=False, polygonType="", layer=0, lineWidth=1): 102 """add(string, list((double, double)), (integer, integer, integer, integer), 103 bool, string, integer, double) -> None 104 Adds a new polygon. 105 """ 106 self._setCmd(tc.ADD, polygonID, "tscBipd", 6, polygonType, color, fill, layer, shape, lineWidth)
add(string, list((double, double)), (integer, integer, integer, integer), bool, string, integer, double) -> None Adds a new polygon.
108 def addDynamics(self, polygonID, trackedObjectID="", timeSpan=(), alphaSpan=(), looped=False, rotate=True): 109 """ addDynamics(string, string, list(float), list(float), bool) -> void 110 polygonID - ID of the polygon, upon which the specified dynamics shall act 111 trackedObjectID - ID of a SUMO traffic object, which shall be tracked by the polygon 112 timeSpan - list of time points for timing the animation keyframes (must start with element zero) 113 If it has length zero, no animation is taken into account. 114 alphaSpan - list of alpha values to be attained at keyframes intermediate values are 115 obtained by linear interpolation. Must have length equal to timeSpan, or zero 116 if no alpha animation is desired. 117 looped - Whether the animation should restart when the last keyframe is reached. In that case 118 the animation jumps to the first keyframe as soon as the last is reached. 119 If looped==false, the controlled polygon is removed as soon as the timeSpan elapses. 120 rotate - Whether, the polygon should be rotated with the tracked object (only applies when such is given) 121 The center of rotation is the object's position. 122 """ 123 self._setCmd(tc.VAR_ADD_DYNAMICS, polygonID, "tsffBB", 5, trackedObjectID, timeSpan, alphaSpan, looped, rotate)
addDynamics(string, string, list(float), list(float), bool) -> void polygonID - ID of the polygon, upon which the specified dynamics shall act trackedObjectID - ID of a SUMO traffic object, which shall be tracked by the polygon timeSpan - list of time points for timing the animation keyframes (must start with element zero) If it has length zero, no animation is taken into account. alphaSpan - list of alpha values to be attained at keyframes intermediate values are obtained by linear interpolation. Must have length equal to timeSpan, or zero if no alpha animation is desired. looped - Whether the animation should restart when the last keyframe is reached. In that case the animation jumps to the first keyframe as soon as the last is reached. If looped==false, the controlled polygon is removed as soon as the timeSpan elapses. rotate - Whether, the polygon should be rotated with the tracked object (only applies when such is given) The center of rotation is the object's position.