Skip to content

Commit

Permalink
fix #14637
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Apr 1, 2024
1 parent fcb5097 commit 6a03254
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tools/sumolib/net/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def getParams(self):
return self._params


class EdgeType:
def __init__(self, id, allow, disallow):
self.id = id
self.allow = allow
self.disallow = disallow

class Net:

"""The whole sumo network."""
Expand All @@ -179,10 +185,14 @@ def __init__(self):
# store dijsktra heap for reuse if the same origin is used repeatedly
self._shortestPathCache = None
self._version = None
self._edgeTypes = defaultdict(lambda : EdgeType("DEFAULT_EDGETYPE", "", ""))

def getVersion(self):
return self._version

def getEdgeType(self, typeID):
return self._edgeTypes[typeID]

def setLocation(self, netOffset, convBoundary, origBoundary, projParameter):
self._location["netOffset"] = netOffset
self._location["convBoundary"] = convBoundary
Expand Down Expand Up @@ -246,6 +256,10 @@ def addEdge(self, id, fromID, toID, prio, function, name, edgeType=''):
return self._id2edge[id]

def addLane(self, edge, speed, length, width, allow=None, disallow=None):
if self.getVersion() >= (1,20) and allow is None and disallow is None:
edgeType = self.getEdgeType(edge.getType())
allow = edgeType.allow
disallow = edgeType.disallow
return lane.Lane(edge, speed, length, width, allow, disallow)

def addRoundabout(self, nodes, edges=None):
Expand Down Expand Up @@ -699,10 +713,13 @@ def __init__(self, **others):

def startElement(self, name, attrs):
if name == 'net':
self._net._version = tuple(attrs["version"].split('.'))
parts = attrs["version"].split('.', 1)
self._net._version = (int(parts[0]), float(parts[1]))
elif name == 'location':
self._net.setLocation(attrs["netOffset"], attrs["convBoundary"], attrs[
"origBoundary"], attrs["projParameter"])
elif name == 'type':
self._net._edgeTypes[attrs['id']] = EdgeType(attrs['id'], attrs.get('allow'), attrs.get('disallow'))
elif name == 'edge':
function = attrs.get('function', '')
if (function == ''
Expand Down

0 comments on commit 6a03254

Please sign in to comment.