From 88f846b20be369c953f62ff7dc3f07c9f531d8b6 Mon Sep 17 00:00:00 2001
From: "Egli Adrian (IT-SCI-API-PFI)" <adrian.egli@sbb.ch>
Date: Sat, 25 May 2019 10:24:57 +0200
Subject: [PATCH] editor alt + click removes all trans (rails) from cell

---
 flatland/core/env.py     |  2 +-
 flatland/utils/editor.py | 16 ++++++++++++++--
 notebooks/Editor2.ipynb  |  7 ++++---
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/flatland/core/env.py b/flatland/core/env.py
index 5334b22..3c25bee 100644
--- a/flatland/core/env.py
+++ b/flatland/core/env.py
@@ -34,7 +34,7 @@ class Environment:
             "train_0": False,    # train_0 is still running
             "train_1": True,     # train_1 is done
             "__all__": False,    # the env is not done
-        }
+        }h
         >>> print(infos)
         {
             "train_0": {},  # info for train_0
diff --git a/flatland/utils/editor.py b/flatland/utils/editor.py
index 13ec977..680695f 100644
--- a/flatland/utils/editor.py
+++ b/flatland/utils/editor.py
@@ -234,16 +234,19 @@ class Controller(object):
     def on_click(self, wid, event):
         x = event['canvasX']
         y = event['canvasY']
-        self.debug("debug:", event)
+        self.debug("debug:", x,y)
 
         rcCell = self.view.xy_to_rc(x, y)
 
         bShift = event["shiftKey"]
         bCtrl = event["ctrlKey"]
-        if bCtrl and not bShift:
+        bAlt = event["altKey"]
+        if bCtrl and not bShift and not bAlt:
             self.model.click_agent(rcCell)
         elif bShift and bCtrl:
             self.model.add_target(rcCell)
+        elif bAlt and not bShift and not bCtrl:
+            self.model.clearCell(rcCell)
 
         self.debug("click in cell", rcCell)
         self.model.debug_cell(rcCell)
@@ -263,6 +266,7 @@ class Controller(object):
     def on_mouse_move(self, wid, event):
         """Mouse motion event handler for drawing.
         """
+
         x = event['canvasX']
         y = event['canvasY']
         qEvents = self.qEvents
@@ -309,6 +313,8 @@ class Controller(object):
                     #     # This is the first cell in a mouse stroke
                     #     lrcStroke.append(rcCell)
                 self.view.redisplayImage()
+
+
         else:
             self.model.mod_path(not event["shiftKey"])
 
@@ -609,6 +615,12 @@ class EditorModel(object):
 
         self.redraw()
 
+
+    def clearCell(self,rcCell):
+        self.debug_cell(rcCell)
+        self.env.rail.grid[rcCell[0],rcCell[1]] = 0
+        self.redraw()
+
     def reset(self, replace_agents=False, nAgents=0):
         # if replace_agents:
         #    self.env.agents_handles = range(nAgents)
diff --git a/notebooks/Editor2.ipynb b/notebooks/Editor2.ipynb
index 22bc707..0a192f2 100644
--- a/notebooks/Editor2.ipynb
+++ b/notebooks/Editor2.ipynb
@@ -92,7 +92,8 @@
     "- ctrl-shift-click to add target for last agent\n",
     "  - target can be moved by repeating\n",
     "- to Resize the env (cannot preserve work):\n",
-    "  - select \"Regen\" tab, set regen size slider, click regenerate."
+    "  - select \"Regen\" tab, set regen size slider, click regenerate.\n",
+    "- alt-click remove all rails from cell \n"
    ]
   },
   {
@@ -105,7 +106,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "0f61a1b60a024112ace6ee136b49f20a",
+       "model_id": "deb9bf5c1c344a5c91f6349802a6ab58",
        "version_major": 2,
        "version_minor": 0
       },
@@ -131,7 +132,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "d3c56d6d214949e181e45330b00082f8",
+       "model_id": "01057ff96f9543c8b48cbfdbd385a3d0",
        "version_major": 2,
        "version_minor": 0
       },
-- 
GitLab