From 49922fb64deeba676575b473ee4a556b92a50695 Mon Sep 17 00:00:00 2001
From: "Egli Adrian (IT-SCI-API-PFI)" <adrian.egli@sbb.ch>
Date: Thu, 3 Oct 2019 07:43:37 +0200
Subject: [PATCH] clear debug text : agent, if off then agents path gets seen

---
 flatland/utils/graphics_layer.py | 3 ++-
 flatland/utils/graphics_pil.py   | 7 +++++--
 flatland/utils/rendertools.py    | 8 +++++---
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/flatland/utils/graphics_layer.py b/flatland/utils/graphics_layer.py
index 5f0ce53a..30ad93a2 100644
--- a/flatland/utils/graphics_layer.py
+++ b/flatland/utils/graphics_layer.py
@@ -73,7 +73,8 @@ class GraphicsLayer(object):
         """
         pass
 
-    def set_agent_at(self, iAgent, row, col, iDirIn, iDirOut, isSelected=False,rail_grid=None,show_debug=False):
+    def set_agent_at(self, iAgent, row, col, iDirIn, iDirOut, isSelected=False,rail_grid=None,show_debug=False,
+                     clear_debug_text=True):
         pass
 
     def set_cell_occupied(self, iAgent, row, col):
diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py
index f6799643..2037f2d7 100644
--- a/flatland/utils/graphics_pil.py
+++ b/flatland/utils/graphics_pil.py
@@ -639,7 +639,7 @@ class PILSVG(PILGL):
                     self.pil_zug[(in_direction_2, out_direction_2, color_idx)] = pils[color_idx]
 
     def set_agent_at(self, agent_idx, row, col, in_direction, out_direction, is_selected,
-                     rail_grid=None, show_debug=False):
+                     rail_grid=None, show_debug=False,clear_debug_text=True):
         delta_dir = (out_direction - in_direction) % 4
         color_idx = agent_idx % self.n_agent_colors
         # when flipping direction at a dead end, use the "out_direction" direction.
@@ -656,7 +656,10 @@ class PILSVG(PILGL):
             self.clear_layer(PILGL.SELECTED_AGENT_LAYER, 0)
             self.draw_image_row_col(bg_svg, (row, col), layer=PILGL.SELECTED_AGENT_LAYER)
         if show_debug:
-            self.text_rowcol((row + 0.2, col + 0.2,), str(agent_idx))
+            if not clear_debug_text:
+                self.text_rowcol((row + 0.2, col + 0.2,), str(agent_idx), layer=PILGL.SELECTED_AGENT_LAYER)
+            else:
+                self.text_rowcol((row + 0.2, col + 0.2,), str(agent_idx))
 
     def set_cell_occupied(self, agent_idx, row, col):
         occupied_im = self.cell_occupied[agent_idx % len(self.cell_occupied)]
diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py
index be6ffb79..a26aa5ef 100644
--- a/flatland/utils/rendertools.py
+++ b/flatland/utils/rendertools.py
@@ -41,7 +41,7 @@ class RenderTool(object):
 
     def __init__(self, env, gl="PILSVG", jupyter=False,
                  agent_render_variant=AgentRenderVariant.ONE_STEP_BEHIND,
-                 show_debug=False, screen_width=800, screen_height=600):
+                 show_debug=False, clear_debug_text=True,screen_width=800, screen_height=600):
 
         self.env = env
         self.frame_nr = 0
@@ -60,6 +60,7 @@ class RenderTool(object):
 
         self.new_rail = True
         self.show_debug = show_debug
+        self.clear_debug_text = clear_debug_text
         self.update_background()
 
     def reset(self):
@@ -556,7 +557,8 @@ class RenderTool(object):
                 if self.agent_render_variant == AgentRenderVariant.ONE_STEP_BEHIND_AND_BOX:
                     self.gl.set_cell_occupied(agent_idx, *(agent.position))
                 self.gl.set_agent_at(agent_idx, *position, old_direction, direction,
-                                     selected_agent == agent_idx, rail_grid=env.rail.grid, show_debug=self.show_debug)
+                                     selected_agent == agent_idx, rail_grid=env.rail.grid,
+                                     show_debug=self.show_debug,clear_debug_text=self.clear_debug_text)
             else:
                 position = agent.position
                 direction = agent.direction
@@ -569,7 +571,7 @@ class RenderTool(object):
                         # set_agent_at uses the agent index for the color
                         self.gl.set_agent_at(agent_idx, *position, agent.direction, direction,
                                              selected_agent == agent_idx, rail_grid=env.rail.grid,
-                                             show_debug=self.show_debug)
+                                             show_debug=self.show_debug,clear_debug_text=self.clear_debug_text)
 
                 # set_agent_at uses the agent index for the color
                 if self.agent_render_variant == AgentRenderVariant.AGENT_SHOWS_OPTIONS_AND_BOX:
-- 
GitLab