Skip to content

Commit bc50e72

Browse files
committed
#187 - Prototype can draw a resizable track
1 parent e29a206 commit bc50e72

File tree

6 files changed

+828
-19
lines changed

6 files changed

+828
-19
lines changed

src/prototype_ui/canvas.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class Canvas(QGraphicsView):
1010
def __init__(self, background_colour: Qt.GlobalColor):
1111
super().__init__(None)
1212
self._background_colour = background_colour
13-
self._width = self.geometry().width()
14-
self._height = self.geometry().height()
13+
self._width = self.geometry().width() - 2
14+
self._height = self.geometry().height() - 2
1515
self._recreate_scene()
1616

1717
def paintEvent(self, event):
18-
new_width = self.geometry().width()
19-
new_height = self.geometry().height()
18+
new_width = self.geometry().width() - 2
19+
new_height = self.geometry().height() - 2
2020
if self._width != new_width or self._height != new_height:
2121
self._width = new_width
2222
self._height = new_height

src/prototype_ui/main.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from prototype_ui.menubar import MenuBarManager
88
from prototype_ui.toolbar import ToolBarManager
99
from prototype_ui.track_analysis_canvas import TrackAnalysisCanvas, FilledCircle, TrackArea, Line
10+
from prototype_ui.tracks_v4 import get_all_tracks
1011

1112

1213
class MainWindow(QMainWindow):
@@ -41,12 +42,14 @@ def __init__(self):
4142

4243
self.show()
4344

44-
# Example of drawing stuff in the track canvas until I integrate with Tracks etc.
45-
self.canvas.set_track_area(TrackArea(0, 0, 100, 100))
46-
self.canvas.add_fixed_shape(FilledCircle((90, 90), 20, Qt.GlobalColor.red))
47-
self.canvas.add_fixed_shape(FilledCircle((50, 50), 20, Qt.GlobalColor.white))
48-
self.canvas.add_fixed_shape(FilledCircle((10, 10), 20, Qt.GlobalColor.blue))
49-
self.canvas.add_fixed_shape(Line((0, 100), (100, 0), 10, Qt.GlobalColor.yellow))
45+
# Initialise tracks & draw here temporarily to prove everything works or not
46+
47+
self._tracks = get_all_tracks()
48+
track = self._tracks["reinvent_base"]
49+
track.configure_track_canvas(self.canvas)
50+
# self.canvas.set_track_area(TrackArea(0, 0, 10, 10))
51+
track.draw_track_edges(self.canvas, Qt.GlobalColor.red)
52+
track.draw_waypoints(self.canvas, Qt.GlobalColor.blue, 2, 5)
5053

5154
def _new_file(self):
5255
print("New File")
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#
2+
# DeepRacer Guru
3+
#
4+
# Version 3.0 onwards
5+
#
6+
# Copyright (c) 2021 dmh23
7+
#
8+
9+
import src.personalize.configuration.personal_track_annotations as config
10+
from prototype_ui.track_v4 import Track
11+
12+
13+
class Reinvent2018Track(Track):
14+
def __init__(self):
15+
super().__init__()
16+
17+
self._ui_name = "re:Invent 2018"
18+
self._ui_description = "The official 2019 DeepRacer League Summit Circuit track."
19+
self._ui_length_in_m = 17.6 # metres
20+
self._ui_width_in_cm = 76 # centimetres
21+
self._world_name = "reinvent_base"
22+
self._track_sector_dividers = [20, 45, 76]
23+
self._annotations = config.reinvent_2018_annotations
24+
self._track_width = 0.76
25+
26+
self._track_waypoints = [(3.059733510017395, 0.6826554089784622), (3.2095088958740234, 0.6831344813108444),
27+
(3.359275460243225, 0.6833638250827789), (3.5090349912643433, 0.6834017932415009),
28+
(3.6587949991226196, 0.6834610402584076), (3.808555006980896, 0.6835170090198517),
29+
(3.9583150148391724, 0.6835691034793854), (4.1080756187438965, 0.6836211383342743),
30+
(4.2578349113464355, 0.6836741119623184), (4.407594919204712, 0.683727964758873),
31+
(4.557354927062988, 0.6837812215089798), (4.7071144580841064, 0.6838362663984299),
32+
(4.856873989105225, 0.6838938742876053), (5.006633043289185, 0.6839521080255508),
33+
(5.156393527984619, 0.6840048730373383), (5.306154489517212, 0.6840500980615616),
34+
(5.455911874771118, 0.6841173022985458), (5.605645418167114, 0.6843366473913193),
35+
(5.75542140007019, 0.6842880994081497), (5.905304670333862, 0.6835954934358597),
36+
(6.055286169052124, 0.6823406517505646), (6.204955101013184, 0.6861690580844879),
37+
(6.354061603546143, 0.6985173225402832), (6.502514362335205, 0.7188082784414291),
38+
(6.643739938735962, 0.7683110386133194), (6.77488899230957, 0.8412670791149139),
39+
(6.89846134185791, 0.9262270629405975), (7.0100367069244385, 1.0257667303085327),
40+
(7.0997467041015625, 1.1460862159729004), (7.172473669052124, 1.2770325541496277),
41+
(7.230445146560669, 1.4172040224075317), (7.272417068481445, 1.565867006778717),
42+
(7.283682584762573, 1.7152734994888306), (7.265743970870972, 1.8636599779129024),
43+
(7.233960151672363, 2.010729968547821), (7.1842029094696045, 2.154710531234741),
44+
(7.114001989364624, 2.2871004343032837), (7.0233659744262695, 2.406221032142639),
45+
(6.917426347732544, 2.512663960456848), (6.79807996749878, 2.604923009872436),
46+
(6.6672019958496085, 2.6775895357131962), (6.526654481887817, 2.729645013809204),
47+
(6.380491495132446, 2.7596704959869385), (6.229795932769775, 2.7700384855270386),
48+
(6.079286813735961, 2.7733629941940308), (5.929529666900635, 2.7721140384674072),
49+
(5.7797839641571045, 2.7707979679107666), (5.630027532577515, 2.769605040550232),
50+
(5.48030161857605, 2.7690484523773193), (5.330573081970215, 2.768457531929016),
51+
(5.180745601654053, 2.765363574028015), (5.031071662902832, 2.766121029853821),
52+
(4.8823630809783936, 2.7846319675445557), (4.735179901123047, 2.821260929107666),
53+
(4.596354961395264, 2.878996968269348), (4.471064329147339, 2.959028959274292),
54+
(4.358901500701904, 3.0601580142974854), (4.255730390548706, 3.1701360940933228),
55+
(4.16035795211792, 3.2856805324554443), (4.066727519035339, 3.4024704694747925),
56+
(3.9719725847244263, 3.518454909324646), (3.8773505687713623, 3.6345274448394775),
57+
(3.7827706336975098, 3.7506459951400757), (3.6881529092788696, 3.86673903465271),
58+
(3.5935609340667725, 3.9826358556747437), (3.4988315105438232, 4.09949803352356),
59+
(3.4035515785217285, 4.217398405075073), (3.294981002807617, 4.319329500198364),
60+
(3.1679095029830933, 4.398614168167114), (3.0387414693832397, 4.461370468139648),
61+
(2.854969024658203, 4.497744560241699), (2.797850012779234, 4.495018482208252),
62+
(2.633301019668579, 4.497664451599121), (2.4294214248657227, 4.4980690479278564),
63+
(2.2890069484710693, 4.492910385131836), (2.1444239616394043, 4.488077163696289),
64+
(1.99241304397583, 4.483960390090942), (1.842801034450531, 4.479875564575195),
65+
(1.6925734877586365, 4.4749414920806885), (1.539882481098175, 4.468656063079834),
66+
(1.3862689733505262, 4.457833528518677), (1.2433670163154602, 4.418424367904663),
67+
(1.1135604083538055, 4.345951080322266), (0.9965091645717638, 4.250534892082216),
68+
(0.8920779228210449, 4.136229991912842), (0.8050850629806519, 4.006568551063538),
69+
(0.7456648498773575, 3.8689799308776855), (0.7141403257846834, 3.723703503608705),
70+
(0.7072480469942093, 3.572937488555908), (0.714956521987915, 3.4234429597854614),
71+
(0.7365620285272598, 3.275694489479065), (0.7720642238855366, 3.129692554473875),
72+
(0.8129126578569412, 2.9843615293502808), (0.8494300991296768, 2.838486909866333),
73+
(0.8816098272800446, 2.692067503929138), (0.9119606614112854, 2.5454180240631104),
74+
(0.942350447177887, 2.3987735509872437), (0.9727316200733185, 2.2521289587020874),
75+
(1.0031171143054962, 2.1054846048355103), (1.0335085093975067, 1.958836555480957),
76+
(1.063848465681076, 1.8122150301933289), (1.0942798256874084, 1.6655445098876953),
77+
(1.125132828950882, 1.518646478652954), (1.1569859981536865, 1.3717305064201355),
78+
(1.1986910104751587, 1.2280805110931396), (1.2531161606311798, 1.0885401666164398),
79+
(1.3394269943237305, 0.9674179255962372), (1.440102458000183, 0.8561052978038788),
80+
(1.5720524787902832, 0.7863914519548416), (1.7143170237541199, 0.7385813295841217),
81+
(1.862565040588379, 0.7073544710874557), (2.011545956134796, 0.6859170347452164),
82+
(2.1608630418777466, 0.6737564653158188), (2.3105164766311646, 0.6708721071481705),
83+
(2.4604655504226685, 0.6761422604322433), (2.610395073890686, 0.6808701455593109),
84+
(2.760238528251648, 0.6832202970981598), (2.909994959831238, 0.6831925511360168),
85+
(3.059733510017395, 0.6826554089784622)]

src/prototype_ui/track_analysis_canvas.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,16 @@ def _paint(self, painter: QPainter):
9292
f.paint(painter, scale)
9393

9494
def _get_scene_items(self) -> list[QAbstractGraphicsShapeItem]:
95-
rect = QGraphicsRectItem(0, 0, self._width / 20, self._height / 20)
96-
rect.setPos(self._width / 10, self._height / 10)
97-
brush = QBrush(Qt.GlobalColor.red)
98-
rect.setBrush(brush)
99-
pen = QPen(Qt.GlobalColor.cyan)
100-
pen.setWidth(10)
101-
rect.setPen(pen)
102-
103-
return [rect]
95+
# rect = QGraphicsRectItem(0, 0, self._width / 20, self._height / 20)
96+
# rect.setPos(self._width / 10, self._height / 10)
97+
# brush = QBrush(Qt.GlobalColor.red)
98+
# rect.setBrush(brush)
99+
# pen = QPen(Qt.GlobalColor.cyan)
100+
# pen.setWidth(10)
101+
# rect.setPen(pen)
102+
#
103+
# return [rect]
104+
return []
104105

105106
def add_fixed_shape(self, item: FixedShape):
106107
self._fixed_shapes.append(item)

0 commit comments

Comments
 (0)