Skip to content
Snippets Groups Projects
Commit 14b63f9d authored by Erik Nygren's avatar Erik Nygren
Browse files

Merge branch 'master' of gitlab.aicrowd.com:flatland/flatland

parents eaac3484 fa4d3966
No related branches found
No related tags found
No related merge requests found
......@@ -192,7 +192,7 @@ class Demo:
break
if False:
if True:
demo_000 = Demo(Scenario_Generator.generate_random_scenario())
demo_000.run_demo()
demo_000 = None
......
......@@ -11,6 +11,19 @@ from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout
from PyQt5 import QtSvg
def transform_string_svg(sSVG):
sSVG = sSVG.replace("ASCII", "UTF-8")
bySVG = bytearray(sSVG, encoding='utf-8')
return bySVG
def create_QtSvgWidget_from_svg_string(sSVG):
svgWidget = QtSvg.QSvgWidget()
ret = svgWidget.renderer().load(transform_string_svg(sSVG))
if ret == False:
print("create_QtSvgWidget_from_svg_string : failed to parse:", sSVG)
return svgWidget
class QTGL(GraphicsLayer):
def __init__(self, width, height):
self.cell_pixels = 60
......@@ -129,13 +142,7 @@ class QTSVG(GraphicsLayer):
if False:
for binTrans in self.track.dSvg.keys():
sSVG = self.track.dSvg[binTrans].to_string()
bySVG = bytearray(sSVG, encoding='utf-8')
svgWidget = QtSvg.QSvgWidget()
svgWidget.renderer().load(bySVG)
print(iRow, iCol)
self.layout.addWidget(svgWidget, iRow, iCol)
self.layout.addWidget(create_QtSvgWidget_from_svg_string(sSVG), iRow, iCol)
iArt += 1
iRow = int(iArt / nCols)
......@@ -170,10 +177,7 @@ class QTSVG(GraphicsLayer):
def setRailAt(self, row, col, binTrans):
if binTrans in self.track.dSvg:
sSVG = self.track.dSvg[binTrans].to_string()
sSVG = sSVG.replace("ASCII", "UTF-8")
bySVG = bytearray(sSVG, encoding='utf-8')
svgWidget = QtSvg.QSvgWidget()
svgWidget.renderer().load(bySVG)
svgWidget = create_QtSvgWidget_from_svg_string(sSVG)
self.layout.addWidget(svgWidget, row, col)
self.lwTrack.append(svgWidget)
else:
......@@ -200,8 +204,7 @@ class QTSVG(GraphicsLayer):
agentPrev.direction = iDirOut
agentPrev.old_direction = iDirIn
sSVG = self.zug.getSvg(iAgent, iDirIn, iDirOut, color=color).to_string()
bySVG = bytearray(sSVG, encoding='utf-8')
wAgent.renderer().load(bySVG)
wAgent.renderer().load(transform_string_svg(sSVG))
return
# Ensure we have adequate slots in the list lwAgents
......@@ -211,13 +214,10 @@ class QTSVG(GraphicsLayer):
# Create a new widget for the agent
sSVG = self.zug.getSvg(iAgent, iDirIn, iDirOut, color=color).to_string()
bySVG = bytearray(sSVG, encoding='utf-8')
svgWidget = QtSvg.QSvgWidget()
svgWidget.renderer().load(bySVG)
svgWidget = create_QtSvgWidget_from_svg_string(sSVG)
self.lwAgents[iAgent] = svgWidget
self.agents_prev[iAgent] = EnvAgent((row, col), iDirOut, (0, 0), old_direction=iDirIn)
self.layout.addWidget(svgWidget, row, col)
# print("Created ", iAgent, row, col)
def show(self, block=False):
self.wMain.update()
......
......@@ -764,12 +764,18 @@ class RenderTool(object):
iAction = action_dict[iAgent]
new_direction, action_isValid = self.env.check_action(agent, iAction)
if action_isValid:
self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction, color=oColor)
# ** TODO ***
# why should we only update if the action is valid ?
if False:
if action_isValid:
self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction, color=oColor)
else:
pass
# print("invalid action - agent ", iAgent, " bend ", agent.direction, new_direction)
# self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction)
else:
pass
# print("invalid action - agent ", iAgent, " bend ", agent.direction, new_direction)
# self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction)
self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction, color=oColor)
self.gl.show()
for i in range(3):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment