Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Flatland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sfwatergit
Flatland
Commits
ddb528a9
Commit
ddb528a9
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
Bug fixed in editor.py click position works now perfectly (xy_to_rc)
parent
18a63599
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
flatland/utils/editor.py
+5
-1
5 additions, 1 deletion
flatland/utils/editor.py
notebooks/Editor2.ipynb
+24
-23
24 additions, 23 deletions
notebooks/Editor2.ipynb
with
29 additions
and
24 deletions
flatland/utils/editor.py
+
5
−
1
View file @
ddb528a9
...
...
@@ -210,7 +210,11 @@ class View(object):
self
.
writableData
[(
y
-
2
):(
y
+
2
),
(
x
-
2
):(
x
+
2
),
:
3
]
=
0
def
xy_to_rc
(
self
,
x
,
y
):
rcCell
=
((
array
([
y
,
x
])
-
self
.
yxBase
)
/
self
.
nPixCell
).
astype
(
int
)
rcCell
=
((
array
([
y
,
x
])
-
self
.
yxBase
))
nX
=
np
.
floor
((
self
.
yxSize
[
0
]
-
self
.
yxBase
[
0
])
/
self
.
model
.
env
.
height
)
nY
=
np
.
floor
((
self
.
yxSize
[
1
]
-
self
.
yxBase
[
1
])
/
self
.
model
.
env
.
width
)
rcCell
[
0
]
=
max
(
0
,
min
(
np
.
floor
(
rcCell
[
0
]
/
nY
),
self
.
model
.
env
.
height
-
1
))
rcCell
[
1
]
=
max
(
0
,
min
(
np
.
floor
(
rcCell
[
1
]
/
nX
),
self
.
model
.
env
.
width
-
1
))
return
rcCell
def
log
(
self
,
*
args
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
notebooks/Editor2.ipynb
+
24
−
23
View file @
ddb528a9
...
...
@@ -9,9 +9,18 @@
},
{
"cell_type": "code",
"execution_count":
1
,
"execution_count":
9
,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
...
...
@@ -19,7 +28,7 @@
},
{
"cell_type": "code",
"execution_count":
2
,
"execution_count":
10
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -32,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count":
3
,
"execution_count":
11
,
"metadata": {},
"outputs": [
{
...
...
@@ -54,31 +63,23 @@
},
{
"cell_type": "code",
"execution_count":
4
,
"execution_count":
12
,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cairo installed: OK\n"
]
}
],
"outputs": [],
"source": [
"from flatland.utils.editor import EditorMVC, EditorModel, View, Controller"
]
},
{
"cell_type": "code",
"execution_count":
5
,
"execution_count":
13
,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<flatland.utils.graphics_pil.PILSVG object at 0x00000
1E6748D1128
> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<flatland.utils.graphics_pil.PILSVG object at 0x00000
20D4CDD2E10
> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n",
" 0000000000000000 Background_#91D1DD.svg\n",
"WE 0000000000000100 Gleis_Deadend.svg\n",
...
...
@@ -141,7 +142,7 @@
},
{
"cell_type": "code",
"execution_count":
6
,
"execution_count":
14
,
"metadata": {
"scrolled": false
},
...
...
@@ -149,7 +150,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
0fd27ca20d9c411586c8ccae843f3950
",
"model_id": "
4c81e4d508834d7f93d104fd2642bc3a
",
"version_major": 2,
"version_minor": 0
},
...
...
@@ -164,7 +165,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<flatland.utils.graphics_pil.PILSVG object at 0x00000
1E674DEF048
> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<flatland.utils.graphics_pil.PILSVG object at 0x00000
20D4CF49D30
> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n",
" 0000000000000000 Background_#91D1DD.svg\n",
"WE 0000000000000100 Gleis_Deadend.svg\n",
...
...
@@ -201,7 +202,7 @@
},
{
"cell_type": "code",
"execution_count":
7
,
"execution_count":
15
,
"metadata": {
"scrolled": false
},
...
...
@@ -209,7 +210,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
e4c58e43c54847c7bc4ad0327ca506d8
",
"model_id": "
83b942888352481995b35116bb2237d9
",
"version_major": 2,
"version_minor": 0
},
...
...
@@ -228,7 +229,7 @@
},
{
"cell_type": "code",
"execution_count":
8
,
"execution_count":
16
,
"metadata": {},
"outputs": [
{
...
...
@@ -237,7 +238,7 @@
"(0, 0)"
]
},
"execution_count":
8
,
"execution_count":
16
,
"metadata": {},
"output_type": "execute_result"
}
...
...
%% Cell type:markdown id: tags:
# Rail Editor v0.2
%% Cell type:code id: tags:
```
python
%
load_ext
autoreload
%
autoreload
2
```
%% Output
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
%% 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
,
EditorModel
,
View
,
Controller
```
%% Output
cairo installed: OK
%% Cell type:code id: tags:
```
python
mvc
=
EditorMVC
(
sGL
=
"
PILSVG
"
)
# sGL="PIL")
```
%% Output
<flatland.utils.graphics_pil.PILSVG object at 0x00000
1E6748D1128
> <class 'flatland.utils.graphics_pil.PILSVG'>
<flatland.utils.graphics_pil.PILSVG object at 0x00000
20D4CDD2E10
> <class 'flatland.utils.graphics_pil.PILSVG'>
<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>
0000000000000000 Background_#91D1DD.svg
WE 0000000000000100 Gleis_Deadend.svg
WW EE NN SS 1000010000100001 Gleis_Diamond_Crossing.svg
WW EE 0000010000000001 Gleis_horizontal.svg
EN SW 0000100000010000 Gleis_Kurve_oben_links.svg
WN SE 0000000001001000 Gleis_Kurve_oben_rechts.svg
ES NW 0001001000000000 Gleis_Kurve_unten_links.svg
NE WS 0100000000000010 Gleis_Kurve_unten_rechts.svg
NN SS 1000000000100000 Gleis_vertikal.svg
NN SS EE WW ES NW SE WN 1001011001101001 Weiche_Double_Slip.svg
EE WW EN SW 0000110000010001 Weiche_horizontal_oben_links.svg
EE WW SE WN 0000010001001001 Weiche_horizontal_oben_rechts.svg
EE WW ES NW 0001011000000001 Weiche_horizontal_unten_links.svg
EE WW NE WS 0100010000000011 Weiche_horizontal_unten_rechts.svg
NN SS EE WW NW ES 1001011000100001 Weiche_Single_Slip.svg
NE NW ES WS 0101001000000010 Weiche_Symetrical.svg
NN SS EN SW 1000100000110000 Weiche_vertikal_oben_links.svg
NN SS SE WN 1000000001101000 Weiche_vertikal_oben_rechts.svg
NN SS NW ES 1001001000100000 Weiche_vertikal_unten_links.svg
NN SS NE WS 1100000000100010 Weiche_vertikal_unten_rechts.svg
EW 0000000100000000 Bahnhof_#d50000_Deadend_links.svg
NS 0010000000000000 Bahnhof_#d50000_Deadend_oben.svg
WE 0000000000000100 Bahnhof_#d50000_Deadend_rechts.svg
SN 0000000010000000 Bahnhof_#d50000_Deadend_unten.svg
EE WW 0000010000000001 Bahnhof_#d50000_Gleis_horizontal.svg
NN SS 1000000000100000 Bahnhof_#d50000_Gleis_vertikal.svg
Clear rails
%% Cell type:markdown id: tags:
## Instructions
-
Drag to draw (improved dead-ends)
-
Shift-Drag to erase rails (erasing dead ends not yet automated - drag right across them)
-
ctrl-click to add agent
-
direction chosen randomly to fit rail
-
ctrl-shift-click to add target for last 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
%% Cell type:code id: tags:
```
python
mvc
.
view
.
display
()
```
%% Output
<flatland.utils.graphics_pil.PILSVG object at 0x00000
1E674DEF048
> <class 'flatland.utils.graphics_pil.PILSVG'>
<flatland.utils.graphics_pil.PILSVG object at 0x00000
20D4CF49D30
> <class 'flatland.utils.graphics_pil.PILSVG'>
<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>
0000000000000000 Background_#91D1DD.svg
WE 0000000000000100 Gleis_Deadend.svg
WW EE NN SS 1000010000100001 Gleis_Diamond_Crossing.svg
WW EE 0000010000000001 Gleis_horizontal.svg
EN SW 0000100000010000 Gleis_Kurve_oben_links.svg
WN SE 0000000001001000 Gleis_Kurve_oben_rechts.svg
ES NW 0001001000000000 Gleis_Kurve_unten_links.svg
NE WS 0100000000000010 Gleis_Kurve_unten_rechts.svg
NN SS 1000000000100000 Gleis_vertikal.svg
NN SS EE WW ES NW SE WN 1001011001101001 Weiche_Double_Slip.svg
EE WW EN SW 0000110000010001 Weiche_horizontal_oben_links.svg
EE WW SE WN 0000010001001001 Weiche_horizontal_oben_rechts.svg
EE WW ES NW 0001011000000001 Weiche_horizontal_unten_links.svg
EE WW NE WS 0100010000000011 Weiche_horizontal_unten_rechts.svg
NN SS EE WW NW ES 1001011000100001 Weiche_Single_Slip.svg
NE NW ES WS 0101001000000010 Weiche_Symetrical.svg
NN SS EN SW 1000100000110000 Weiche_vertikal_oben_links.svg
NN SS SE WN 1000000001101000 Weiche_vertikal_oben_rechts.svg
NN SS NW ES 1001001000100000 Weiche_vertikal_unten_links.svg
NN SS NE WS 1100000000100010 Weiche_vertikal_unten_rechts.svg
EW 0000000100000000 Bahnhof_#d50000_Deadend_links.svg
NS 0010000000000000 Bahnhof_#d50000_Deadend_oben.svg
WE 0000000000000100 Bahnhof_#d50000_Deadend_rechts.svg
SN 0000000010000000 Bahnhof_#d50000_Deadend_unten.svg
EE WW 0000010000000001 Bahnhof_#d50000_Gleis_horizontal.svg
NN SS 1000000000100000 Bahnhof_#d50000_Gleis_vertikal.svg
%% Cell type:code id: tags:
```
python
mvc
.
view
.
wOutput
.
clear_output
()
mvc
.
view
.
wOutput
```
%% Output
%% Cell type:code id: tags:
```
python
len
(
mvc
.
editor
.
env
.
agents
),
len
(
mvc
.
editor
.
env
.
agents_static
)
```
%% Output
(0, 0)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment