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
53299edc
Commit
53299edc
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
code cleaned
parent
0d32b1ee
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
examples/demo.py
+1
-1
1 addition, 1 deletion
examples/demo.py
flatland/utils/render_qt.py
+17
-16
17 additions, 16 deletions
flatland/utils/render_qt.py
with
18 additions
and
17 deletions
examples/demo.py
+
1
−
1
View file @
53299edc
...
@@ -192,7 +192,7 @@ class Demo:
...
@@ -192,7 +192,7 @@ class Demo:
break
break
if
Fals
e
:
if
Tru
e
:
demo_000
=
Demo
(
Scenario_Generator
.
generate_random_scenario
())
demo_000
=
Demo
(
Scenario_Generator
.
generate_random_scenario
())
demo_000
.
run_demo
()
demo_000
.
run_demo
()
demo_000
=
None
demo_000
=
None
...
...
This diff is collapsed.
Click to expand it.
flatland/utils/render_qt.py
+
17
−
16
View file @
53299edc
...
@@ -11,6 +11,19 @@ from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout
...
@@ -11,6 +11,19 @@ from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout
from
PyQt5
import
QtSvg
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
):
class
QTGL
(
GraphicsLayer
):
def
__init__
(
self
,
width
,
height
):
def
__init__
(
self
,
width
,
height
):
self
.
cell_pixels
=
60
self
.
cell_pixels
=
60
...
@@ -129,13 +142,7 @@ class QTSVG(GraphicsLayer):
...
@@ -129,13 +142,7 @@ class QTSVG(GraphicsLayer):
if
False
:
if
False
:
for
binTrans
in
self
.
track
.
dSvg
.
keys
():
for
binTrans
in
self
.
track
.
dSvg
.
keys
():
sSVG
=
self
.
track
.
dSvg
[
binTrans
].
to_string
()
sSVG
=
self
.
track
.
dSvg
[
binTrans
].
to_string
()
self
.
layout
.
addWidget
(
create_QtSvgWidget_from_svg_string
(
sSVG
),
iRow
,
iCol
)
bySVG
=
bytearray
(
sSVG
,
encoding
=
'
utf-8
'
)
svgWidget
=
QtSvg
.
QSvgWidget
()
svgWidget
.
renderer
().
load
(
bySVG
)
print
(
iRow
,
iCol
)
self
.
layout
.
addWidget
(
svgWidget
,
iRow
,
iCol
)
iArt
+=
1
iArt
+=
1
iRow
=
int
(
iArt
/
nCols
)
iRow
=
int
(
iArt
/
nCols
)
...
@@ -170,10 +177,7 @@ class QTSVG(GraphicsLayer):
...
@@ -170,10 +177,7 @@ class QTSVG(GraphicsLayer):
def
setRailAt
(
self
,
row
,
col
,
binTrans
):
def
setRailAt
(
self
,
row
,
col
,
binTrans
):
if
binTrans
in
self
.
track
.
dSvg
:
if
binTrans
in
self
.
track
.
dSvg
:
sSVG
=
self
.
track
.
dSvg
[
binTrans
].
to_string
()
sSVG
=
self
.
track
.
dSvg
[
binTrans
].
to_string
()
sSVG
=
sSVG
.
replace
(
"
ASCII
"
,
"
UTF-8
"
)
svgWidget
=
create_QtSvgWidget_from_svg_string
(
sSVG
)
bySVG
=
bytearray
(
sSVG
,
encoding
=
'
utf-8
'
)
svgWidget
=
QtSvg
.
QSvgWidget
()
svgWidget
.
renderer
().
load
(
bySVG
)
self
.
layout
.
addWidget
(
svgWidget
,
row
,
col
)
self
.
layout
.
addWidget
(
svgWidget
,
row
,
col
)
self
.
lwTrack
.
append
(
svgWidget
)
self
.
lwTrack
.
append
(
svgWidget
)
else
:
else
:
...
@@ -200,8 +204,7 @@ class QTSVG(GraphicsLayer):
...
@@ -200,8 +204,7 @@ class QTSVG(GraphicsLayer):
agentPrev
.
direction
=
iDirOut
agentPrev
.
direction
=
iDirOut
agentPrev
.
old_direction
=
iDirIn
agentPrev
.
old_direction
=
iDirIn
sSVG
=
self
.
zug
.
getSvg
(
iAgent
,
iDirIn
,
iDirOut
,
color
=
color
).
to_string
()
sSVG
=
self
.
zug
.
getSvg
(
iAgent
,
iDirIn
,
iDirOut
,
color
=
color
).
to_string
()
bySVG
=
bytearray
(
sSVG
,
encoding
=
'
utf-8
'
)
wAgent
.
renderer
().
load
(
transform_string_svg
(
sSVG
))
wAgent
.
renderer
().
load
(
bySVG
)
return
return
# Ensure we have adequate slots in the list lwAgents
# Ensure we have adequate slots in the list lwAgents
...
@@ -211,9 +214,7 @@ class QTSVG(GraphicsLayer):
...
@@ -211,9 +214,7 @@ class QTSVG(GraphicsLayer):
# Create a new widget for the agent
# Create a new widget for the agent
sSVG
=
self
.
zug
.
getSvg
(
iAgent
,
iDirIn
,
iDirOut
,
color
=
color
).
to_string
()
sSVG
=
self
.
zug
.
getSvg
(
iAgent
,
iDirIn
,
iDirOut
,
color
=
color
).
to_string
()
bySVG
=
bytearray
(
sSVG
,
encoding
=
'
utf-8
'
)
svgWidget
=
create_QtSvgWidget_from_svg_string
(
sSVG
)
svgWidget
=
QtSvg
.
QSvgWidget
()
svgWidget
.
renderer
().
load
(
bySVG
)
self
.
lwAgents
[
iAgent
]
=
svgWidget
self
.
lwAgents
[
iAgent
]
=
svgWidget
self
.
agents_prev
[
iAgent
]
=
EnvAgent
((
row
,
col
),
iDirOut
,
(
0
,
0
),
old_direction
=
iDirIn
)
self
.
agents_prev
[
iAgent
]
=
EnvAgent
((
row
,
col
),
iDirOut
,
(
0
,
0
),
old_direction
=
iDirIn
)
self
.
layout
.
addWidget
(
svgWidget
,
row
,
col
)
self
.
layout
.
addWidget
(
svgWidget
,
row
,
col
)
...
...
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