Skip to content
Snippets Groups Projects
Commit 2f23359a authored by adrian_egli's avatar adrian_egli
Browse files

Merge branch '#11-bugfix-editor-2' into 'master'

#11 bugfix editor 2

See merge request flatland/flatland!68
parents d4b6be81 55d7d307
No related branches found
No related tags found
No related merge requests found
......@@ -96,6 +96,7 @@ class Demo:
for iAgent in range(self.env.get_num_agents()):
# allways walk straight forward
action = 2
action = np.random.choice([0, 1, 2, 3], 1, p=[0.0, 0.5, 0.5, 0.0])[0]
# update the actions
action_dict.update({iAgent: action})
......
......@@ -9,7 +9,6 @@ from ipywidgets import IntSlider, VBox, HBox, Checkbox, Output, Text, RadioButto
from numpy import array
import flatland.utils.rendertools as rt
from examples.play_model import Player
from flatland.envs.agent_utils import EnvAgent, EnvAgentStatic
from flatland.envs.env_utils import mirror
from flatland.envs.generators import complex_rail_generator, empty_rail_generator
......@@ -113,9 +112,6 @@ class View(object):
VBox([self.wShowObs]),
]
# Progress bar intended for stepping in the background (not yet working)
self.wProg_steps = ipywidgets.IntProgress(value=0, min=0, max=20, step=1, description="Step")
# abbreviated description of buttons and the methods they call
ldButtons = [
dict(name="Refresh", method=self.controller.refresh, tip="Redraw only"),
......@@ -128,7 +124,6 @@ class View(object):
tip="Regenerate the rails using the method selected below"),
dict(name="Load", method=self.controller.load),
dict(name="Save", method=self.controller.save),
dict(name="Step", method=self.controller.step)
]
self.lwButtons = []
......@@ -360,7 +355,6 @@ class Controller(object):
self.model.init_agents_static]
self.model.env.agents = None
self.model.init_agents_static = None
self.player = None
self.model.env.restart_agents()
self.model.env.reset(False, False)
self.refresh(event)
......@@ -413,7 +407,6 @@ class EditorModel(object):
self.env_filename = "temp.pkl"
self.set_env(env)
self.iSelectedAgent = None
self.player = None
self.init_agents_static = None
self.thread = None
......@@ -616,7 +609,6 @@ class EditorModel(object):
self.env.rail.grid[:, :] = 0
self.env.agents = []
self.env.agents_static = []
self.player = None
self.redraw()
......@@ -631,7 +623,6 @@ class EditorModel(object):
def restartAgents(self):
self.env.agents = EnvAgent.list_from_static(self.env.agents_static)
self.player = None
self.redraw()
def setFilename(self, filename):
......@@ -650,6 +641,7 @@ class EditorModel(object):
self.env.restart_agents()
self.env.reset(False, False)
self.init_agents_static = None
self.view.oRT.update_background()
self.fix_env()
self.set_env(self.env)
self.redraw()
......@@ -688,7 +680,6 @@ class EditorModel(object):
self.env.reset(regen_rail=True)
self.fix_env()
self.set_env(self.env)
self.player = None
self.view.new_env()
self.redraw()
......@@ -721,7 +712,7 @@ class EditorModel(object):
# Create a new agent and select it.
agent_static = EnvAgentStatic(rcCell, 0, rcCell, moving=False)
self.iSelectedAgent = self.env.add_agent_static(agent_static)
self.player = None # will need to start a new player
self.view.oRT.update_background()
else:
# Move the selected agent to this cell
agent_static = self.env.agents_static[self.iSelectedAgent]
......@@ -745,26 +736,9 @@ class EditorModel(object):
if self.iSelectedAgent is not None:
self.env.agents_static[self.iSelectedAgent].target = rcCell
self.init_agents_static = None
self.view.oRT.update_background()
self.redraw()
def step(self):
if self.init_agents_static is None:
self.init_agents_static = [agent.to_list() for agent in self.env.agents_static]
if self.player is None:
self.player = Player(self.env)
self.env.reset(regen_rail=False, replace_agents=False)
self.player.step()
self.redraw()
def bg_updater(self, wProg_steps):
try:
for i in range(20):
self.step()
time.sleep(0.2)
wProg_steps.value = i + 1 # indicate progress on bar
finally:
self.thread = None
def fix_env(self):
self.env.width = self.env.rail.width
self.env.height = self.env.rail.height
......
%% Cell type:markdown id: tags:
# Railway Scene Editor
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
```
%% Cell type:code id: tags:
``` python
import numpy as np
from numpy import array
import ipywidgets
import IPython
from IPython.core.display import display, HTML
```
%% Cell type:code id: tags:
``` python
display(HTML("<style>.container { width:95% !important; }</style>"))
```
%% Output
%% Cell type:code id: tags:
``` python
from flatland.utils.editor import EditorMVC
```
%% Cell type:code id: tags:
``` python
mvc = EditorMVC(sGL="PILSVG" )
```
%% Cell type:markdown id: tags:
## Instructions
- Drag to draw (improved dead-ends)
- ctrl-click to add agent or select agent
- if agent is selected:
- ctrl-click to move agent position
- use rotate agent to rotate 90°
- ctrl-shift-click to set target for selected agent
- target can be moved by repeating
- to Resize the env (cannot preserve work):
- select "Regen" tab, set regen size slider, click regenerate.
- alt-click remove all rails from cell
Demo Scene: complex_scene.pkl
%% Cell type:code id: tags:
``` python
mvc.view.display()
```
%% Output
......
ffmpeg -y -framerate 12 -i frame_%04d.bmp -hide_banner -c:v libx264 -pix_fmt yuv420p test.mp4
ffmpeg -i test.mp4 test.gif
pause
\ No newline at end of file
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