blob: f1982995d855bd30adf3bfb2cc1d0f6d70fc688c [file] [log] [blame]
Tabitha Jarvis1007a132018-12-12 21:47:54 -08001#!/usr/bin/python3
Tabitha Jarvis1007a132018-12-12 21:47:54 -08002from __future__ import print_function
3import os
Andrew Runke0f945fd2019-01-27 21:10:37 -08004import sys
Andrew Runke6842bf92019-01-26 15:38:25 -08005import copy
Tabitha Jarvis1007a132018-12-12 21:47:54 -08006from color import Color, palette
7import random
8import gi
9import numpy as np
10import scipy.spatial.distance
11gi.require_version('Gtk', '3.0')
John Park91e69732019-03-03 13:12:43 -080012gi.require_version('Gdk', '3.0')
Andrew Runke6842bf92019-01-26 15:38:25 -080013from gi.repository import Gdk, Gtk, GLib
Tabitha Jarvis1007a132018-12-12 21:47:54 -080014import cairo
John Park91e69732019-03-03 13:12:43 -080015from libspline import Spline, DistanceSpline, Trajectory
Tabitha Jarvis1007a132018-12-12 21:47:54 -080016import enum
John Park91e69732019-03-03 13:12:43 -080017import json
18from basic_window import *
19from constants import *
20from drawing_constants import *
21from points import Points
22from graph import Graph
Andrew Runke6842bf92019-01-26 15:38:25 -080023
Tabitha Jarvis1007a132018-12-12 21:47:54 -080024
25class Mode(enum.Enum):
26 kViewing = 0
27 kPlacing = 1
28 kEditing = 2
29 kExporting = 3
30 kImporting = 4
Andrew Runke6842bf92019-01-26 15:38:25 -080031
32
John Park91e69732019-03-03 13:12:43 -080033class GTK_Widget(BaseWindow):
Andrew Runke6842bf92019-01-26 15:38:25 -080034 """Create a GTK+ widget on which we will draw using Cairo"""
Ravago Jones26f7ad02021-02-05 15:45:59 -080035
Tabitha Jarvis1007a132018-12-12 21:47:54 -080036 def __init__(self):
37 super(GTK_Widget, self).__init__()
38
John Park91e69732019-03-03 13:12:43 -080039 self.points = Points()
40
Tabitha Jarvis1007a132018-12-12 21:47:54 -080041 # init field drawing
42 # add default spline for testing purposes
43 # init editing / viewing modes and pointer location
44 self.mode = Mode.kPlacing
45 self.x = 0
46 self.y = 0
Andrew Runke0f945fd2019-01-27 21:10:37 -080047 module_path = os.path.dirname(os.path.realpath(sys.argv[0]))
48 self.path_to_export = os.path.join(module_path,
John Park91e69732019-03-03 13:12:43 -080049 'points_for_pathedit.json')
50
Tabitha Jarvis1007a132018-12-12 21:47:54 -080051 # update list of control points
52 self.point_selected = False
53 # self.adding_spline = False
54 self.index_of_selected = -1
55 self.new_point = []
56
57 # For the editing mode
Andrew Runke6842bf92019-01-26 15:38:25 -080058 self.index_of_edit = -1 # Can't be zero beause array starts at 0
Tabitha Jarvis1007a132018-12-12 21:47:54 -080059 self.held_x = 0
Andrew Runke6842bf92019-01-26 15:38:25 -080060 self.spline_edit = -1
Tabitha Jarvis1007a132018-12-12 21:47:54 -080061
Andrew Runke6842bf92019-01-26 15:38:25 -080062 self.curves = []
63
64 self.colors = []
65
66 for c in palette:
67 self.colors.append(palette[c])
68
Tabitha Jarvis1007a132018-12-12 21:47:54 -080069 self.reinit_extents()
70
Andrew Runke6842bf92019-01-26 15:38:25 -080071 self.inStart = None
72 self.inEnd = None
Andrew Runke6842bf92019-01-26 15:38:25 -080073 self.inValue = None
74 self.startSet = False
75
John Park909c0392020-03-05 23:56:30 -080076 self.module_path = os.path.dirname(os.path.realpath(sys.argv[0]))
77
Andrew Runke6842bf92019-01-26 15:38:25 -080078 """set extents on images"""
Ravago Jones26f7ad02021-02-05 15:45:59 -080079
Tabitha Jarvis1007a132018-12-12 21:47:54 -080080 def reinit_extents(self):
John Park91e69732019-03-03 13:12:43 -080081 self.extents_x_min = -1.0 * SCREEN_SIZE
82 self.extents_x_max = SCREEN_SIZE
83 self.extents_y_min = -1.0 * SCREEN_SIZE
84 self.extents_y_max = SCREEN_SIZE
Tabitha Jarvis1007a132018-12-12 21:47:54 -080085
86 # this needs to be rewritten with numpy, i dont think this ought to have
87 # SciPy as a dependecy
88 def get_index_of_nearest_point(self):
89 cur_p = [[self.x, self.y]]
90 distances = scipy.spatial.distance.cdist(cur_p, self.all_controls)
91
92 return np.argmin(distances)
93
94 # return the closest point to the loc of the click event
95 def get_nearest_point(self):
96 return self.all_controls[self.get_index_of_nearest_point()]
97
John Parka30a7782019-02-01 18:47:26 -080098 def draw_field_elements(self, cr):
John Parkcf545162020-02-23 20:07:25 -080099 if FIELD == 2019:
100 draw_HAB(cr)
101 draw_rockets(cr)
102 draw_cargo_ship(cr)
103 elif FIELD == 2020:
104 set_color(cr, palette["BLACK"])
105 markers(cr)
106 draw_shield_generator(cr)
107 draw_trench_run(cr)
108 draw_init_lines(cr)
109 draw_control_panel(cr)
John Parka30a7782019-02-01 18:47:26 -0800110
John Park91e69732019-03-03 13:12:43 -0800111 def draw_robot_at_point(self, cr, i, p, spline):
112 p1 = [mToPx(spline.Point(i)[0]), mToPx(spline.Point(i)[1])]
113 p2 = [mToPx(spline.Point(i + p)[0]), mToPx(spline.Point(i + p)[1])]
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800114
John Park91e69732019-03-03 13:12:43 -0800115 #Calculate Robot
116 distance = np.sqrt((p2[1] - p1[1])**2 + (p2[0] - p1[0])**2)
117 x_difference_o = p2[0] - p1[0]
118 y_difference_o = p2[1] - p1[1]
119 x_difference = x_difference_o * mToPx(LENGTH_OF_ROBOT / 2) / distance
120 y_difference = y_difference_o * mToPx(LENGTH_OF_ROBOT / 2) / distance
121
122 front_middle = []
123 front_middle.append(p1[0] + x_difference)
124 front_middle.append(p1[1] + y_difference)
125
126 back_middle = []
127 back_middle.append(p1[0] - x_difference)
128 back_middle.append(p1[1] - y_difference)
129
130 slope = [-(1 / x_difference_o) / (1 / y_difference_o)]
131 angle = np.arctan(slope)
132
133 x_difference = np.sin(angle[0]) * mToPx(WIDTH_OF_ROBOT / 2)
134 y_difference = np.cos(angle[0]) * mToPx(WIDTH_OF_ROBOT / 2)
135
136 front_1 = []
137 front_1.append(front_middle[0] - x_difference)
138 front_1.append(front_middle[1] - y_difference)
139
140 front_2 = []
141 front_2.append(front_middle[0] + x_difference)
142 front_2.append(front_middle[1] + y_difference)
143
144 back_1 = []
145 back_1.append(back_middle[0] - x_difference)
146 back_1.append(back_middle[1] - y_difference)
147
148 back_2 = []
149 back_2.append(back_middle[0] + x_difference)
150 back_2.append(back_middle[1] + y_difference)
151
152 x_difference = x_difference_o * mToPx(
153 LENGTH_OF_ROBOT / 2 + ROBOT_SIDE_TO_BALL_CENTER) / distance
154 y_difference = y_difference_o * mToPx(
155 LENGTH_OF_ROBOT / 2 + ROBOT_SIDE_TO_BALL_CENTER) / distance
156
157 #Calculate Ball
158 ball_center = []
159 ball_center.append(p1[0] + x_difference)
160 ball_center.append(p1[1] + y_difference)
161
162 x_difference = x_difference_o * mToPx(
163 LENGTH_OF_ROBOT / 2 + ROBOT_SIDE_TO_HATCH_PANEL) / distance
164 y_difference = y_difference_o * mToPx(
165 LENGTH_OF_ROBOT / 2 + ROBOT_SIDE_TO_HATCH_PANEL) / distance
166
167 #Calculate Panel
168 panel_center = []
169 panel_center.append(p1[0] + x_difference)
170 panel_center.append(p1[1] + y_difference)
171
172 x_difference = np.sin(angle[0]) * mToPx(HATCH_PANEL_WIDTH / 2)
173 y_difference = np.cos(angle[0]) * mToPx(HATCH_PANEL_WIDTH / 2)
174
175 panel_1 = []
176 panel_1.append(panel_center[0] + x_difference)
177 panel_1.append(panel_center[1] + y_difference)
178
179 panel_2 = []
180 panel_2.append(panel_center[0] - x_difference)
181 panel_2.append(panel_center[1] - y_difference)
182
183 #Draw Robot
184 cr.move_to(front_1[0], front_1[1])
185 cr.line_to(back_1[0], back_1[1])
186 cr.line_to(back_2[0], back_2[1])
187 cr.line_to(front_2[0], front_2[1])
188 cr.line_to(front_1[0], front_1[1])
189
190 cr.stroke()
191
192 #Draw Ball
193 set_color(cr, palette["ORANGE"], 0.5)
194 cr.move_to(back_middle[0], back_middle[1])
195 cr.line_to(ball_center[0], ball_center[1])
196 cr.arc(ball_center[0], ball_center[1], mToPx(BALL_RADIUS), 0,
197 2 * np.pi)
198 cr.stroke()
199
200 #Draw Panel
201 set_color(cr, palette["YELLOW"], 0.5)
202 cr.move_to(panel_1[0], panel_1[1])
203 cr.line_to(panel_2[0], panel_2[1])
204
205 cr.stroke()
206 cr.set_source_rgba(0, 0, 0, 1)
207
208 def handle_draw(self, cr): # main
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800209 # Fill the background color of the window with grey
John Park91e69732019-03-03 13:12:43 -0800210 set_color(cr, palette["WHITE"])
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800211 cr.paint()
212
213 # Draw a extents rectangle
214 set_color(cr, palette["WHITE"])
215 cr.rectangle(self.extents_x_min, self.extents_y_min,
216 (self.extents_x_max - self.extents_x_min),
217 self.extents_y_max - self.extents_y_min)
218 cr.fill()
219
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800220 cr.move_to(0, 50)
221 cr.show_text('Press "e" to export')
222 cr.show_text('Press "i" to import')
223
James Kuszmaul1c933e02020-03-07 16:17:51 -0800224 cr.save()
225 cr.translate(mToPx(WIDTH_OF_FIELD_IN_METERS) / 2.0, 0.0)
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800226 set_color(cr, palette["BLACK"])
John Parkcf545162020-02-23 20:07:25 -0800227 if FIELD == 2020:
James Kuszmaul1c933e02020-03-07 16:17:51 -0800228 cr.rectangle(-mToPx(WIDTH_OF_FIELD_IN_METERS) / 2.0,
229 -mToPx(LENGTH_OF_FIELD_IN_METERS) / 2.0,
230 mToPx(WIDTH_OF_FIELD_IN_METERS),
231 mToPx(LENGTH_OF_FIELD_IN_METERS))
John Parkcf545162020-02-23 20:07:25 -0800232 else:
James Kuszmaul1c933e02020-03-07 16:17:51 -0800233 cr.rectangle(0, -SCREEN_SIZE / 2, SCREEN_SIZE, SCREEN_SIZE)
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800234 cr.set_line_join(cairo.LINE_JOIN_ROUND)
235 cr.stroke()
John Parka30a7782019-02-01 18:47:26 -0800236 self.draw_field_elements(cr)
Andrew Runke6842bf92019-01-26 15:38:25 -0800237 y = 0
Andrew Runke6842bf92019-01-26 15:38:25 -0800238
John Park91e69732019-03-03 13:12:43 -0800239 # update everything
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800240
John Park91e69732019-03-03 13:12:43 -0800241 if self.mode == Mode.kPlacing or self.mode == Mode.kViewing:
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800242 set_color(cr, palette["BLACK"])
John Park91e69732019-03-03 13:12:43 -0800243 cr.move_to(-SCREEN_SIZE, 170)
244 plotPoints = self.points.getPoints()
245 if plotPoints:
246 for i, point in enumerate(plotPoints):
John Park13d3e282019-01-26 20:16:48 -0800247 draw_px_x(cr, mToPx(point[0]), mToPx(point[1]), 10)
248 cr.move_to(mToPx(point[0]), mToPx(point[1]) - 15)
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800249 display_text(cr, str(i), 0.5, 0.5, 2, 2)
John Park91e69732019-03-03 13:12:43 -0800250 set_color(cr, palette["WHITE"])
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800251
252 elif self.mode == Mode.kEditing:
253 set_color(cr, palette["BLACK"])
John Park91e69732019-03-03 13:12:43 -0800254 cr.move_to(-SCREEN_SIZE, 170)
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800255 display_text(cr, "EDITING", 1, 1, 1, 1)
John Park91e69732019-03-03 13:12:43 -0800256 if self.points.getSplines():
257 self.draw_splines(cr)
258 for i, points in enumerate(self.points.getSplines()):
Andrew Runke6842bf92019-01-26 15:38:25 -0800259
John Park91e69732019-03-03 13:12:43 -0800260 p0 = np.array([mToPx(points[0][0]), mToPx(points[0][1])])
261 p1 = np.array([mToPx(points[1][0]), mToPx(points[1][1])])
262 p2 = np.array([mToPx(points[2][0]), mToPx(points[2][1])])
263 p3 = np.array([mToPx(points[3][0]), mToPx(points[3][1])])
264 p4 = np.array([mToPx(points[4][0]), mToPx(points[4][1])])
265 p5 = np.array([mToPx(points[5][0]), mToPx(points[5][1])])
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800266
John Park91e69732019-03-03 13:12:43 -0800267 draw_control_points(cr, [p0, p1, p2, p3, p4, p5])
268 first_tangent = p0 + 2.0 * (p1 - p0)
269 second_tangent = p5 + 2.0 * (p4 - p5)
270 cr.set_source_rgb(0, 0.5, 0)
271 cr.move_to(p0[0], p0[1])
272 cr.set_line_width(1.0)
273 cr.line_to(first_tangent[0], first_tangent[1])
274 cr.move_to(first_tangent[0], first_tangent[1])
275 cr.line_to(p2[0], p2[1])
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800276
John Park91e69732019-03-03 13:12:43 -0800277 cr.move_to(p5[0], p5[1])
278 cr.line_to(second_tangent[0], second_tangent[1])
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800279
John Park91e69732019-03-03 13:12:43 -0800280 cr.move_to(second_tangent[0], second_tangent[1])
281 cr.line_to(p3[0], p3[1])
282
283 cr.stroke()
284 cr.set_line_width(2.0)
285 self.points.update_lib_spline()
286 set_color(cr, palette["WHITE"])
287
288 cr.paint_with_alpha(0.2)
289
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800290 draw_px_cross(cr, self.x, self.y, 10)
James Kuszmaul1c933e02020-03-07 16:17:51 -0800291 cr.restore()
292 mygraph = Graph(cr, self.points)
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800293
John Park91e69732019-03-03 13:12:43 -0800294 def draw_splines(self, cr):
295 holder_spline = []
296 for i, points in enumerate(self.points.getSplines()):
297 array = np.zeros(shape=(6, 2), dtype=float)
298 for j, point in enumerate(points):
299 array[j, 0] = point[0]
300 array[j, 1] = point[1]
301 spline = Spline(np.ascontiguousarray(np.transpose(array)))
302 for k in np.linspace(0.01, 1, 100):
Ravago Jones26f7ad02021-02-05 15:45:59 -0800303 cr.move_to(
304 mToPx(spline.Point(k - 0.01)[0]),
305 mToPx(spline.Point(k - 0.01)[1]))
306 cr.line_to(
307 mToPx(spline.Point(k)[0]), mToPx(spline.Point(k)[1]))
John Park91e69732019-03-03 13:12:43 -0800308 cr.stroke()
309 holding = [
310 spline.Point(k - 0.01)[0],
311 spline.Point(k - 0.01)[1]
312 ]
313 holder_spline.append(holding)
314 if i == 0:
315 self.draw_robot_at_point(cr, 0.00, 0.01, spline)
316 self.draw_robot_at_point(cr, 1, 0.01, spline)
317 self.curves.append(holder_spline)
318
319 def mouse_move(self, event):
320 old_x = self.x
321 old_y = self.y
James Kuszmaul1c933e02020-03-07 16:17:51 -0800322 self.x = event.x - mToPx(WIDTH_OF_FIELD_IN_METERS / 2.0)
John Park91e69732019-03-03 13:12:43 -0800323 self.y = event.y
James Kuszmaul1c933e02020-03-07 16:17:51 -0800324 dif_x = self.x - old_x
325 dif_y = self.y - old_y
John Park91e69732019-03-03 13:12:43 -0800326 difs = np.array([pxToM(dif_x), pxToM(dif_y)])
327
328 if self.mode == Mode.kEditing:
James Kuszmaulb33b07c2021-02-25 22:39:24 -0800329 self.points.updates_for_mouse_move(
John Park91e69732019-03-03 13:12:43 -0800330 self.index_of_edit, self.spline_edit, self.x, self.y, difs)
331
John Park909c0392020-03-05 23:56:30 -0800332 def export_json(self, file_name):
333 self.path_to_export = os.path.join(self.module_path,
334 "spline_jsons/" + file_name)
335 if file_name[-5:] != ".json":
336 print("Error: Filename doesn't end in .json")
337 else:
338 # Will export to json file
339 self.mode = Mode.kEditing
Ravago Jones3b92afa2021-02-05 14:27:32 -0800340
341 multi_spline = self.points.toMultiSpline()
342 print(multi_spline)
John Park909c0392020-03-05 23:56:30 -0800343 with open(self.path_to_export, mode='w') as points_file:
Ravago Jones3b92afa2021-02-05 14:27:32 -0800344 json.dump(multi_spline, points_file)
John Park909c0392020-03-05 23:56:30 -0800345
346 def import_json(self, file_name):
347 self.path_to_export = os.path.join(self.module_path,
348 "spline_jsons/" + file_name)
349 if file_name[-5:] != ".json":
350 print("Error: Filename doesn't end in .json")
351 else:
352 # import from json file
353 self.mode = Mode.kEditing
James Kuszmaul1c933e02020-03-07 16:17:51 -0800354 print("LOADING LOAD FROM " + file_name) # Load takes a few seconds
John Park909c0392020-03-05 23:56:30 -0800355 with open(self.path_to_export) as points_file:
Ravago Jones3b92afa2021-02-05 14:27:32 -0800356 multi_spline = json.load(points_file)
John Park909c0392020-03-05 23:56:30 -0800357
Ravago Jones3b92afa2021-02-05 14:27:32 -0800358 # if people messed with the spline json,
359 # it might not be the right length
360 # so give them a nice error message
361 try: # try to salvage as many segments of the spline as possible
362 self.points.fromMultiSpline(multi_spline)
363 except IndexError:
364 # check if they're both 6+5*(k-1) long
365 expected_length = 6 + 5 * (multi_spline["spline_count"] - 1)
366 x_len = len(multi_spline["spline_x"])
367 y_len = len(multi_spline["spline_x"])
368 if x_len is not expected_length:
369 print("Error: spline x values were not the expected length; expected {} got {}".format(expected_length, x_len))
370 elif y_len is not expected_length:
371 print("Error: spline y values were not the expected length; expected {} got {}".format(expected_length, y_len))
372
John Park909c0392020-03-05 23:56:30 -0800373 print("SPLINES LOADED")
374
John Park91e69732019-03-03 13:12:43 -0800375 def do_key_press(self, event, file_name):
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800376 keyval = Gdk.keyval_to_lower(event.keyval)
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800377 if keyval == Gdk.KEY_q:
378 print("Found q key and exiting.")
379 quit_main_loop()
John Park909c0392020-03-05 23:56:30 -0800380 if keyval == Gdk.KEY_e:
381 export_json(file_name)
John Park91e69732019-03-03 13:12:43 -0800382
John Park909c0392020-03-05 23:56:30 -0800383 if keyval == Gdk.KEY_i:
384 import_json(file_name)
John Park91e69732019-03-03 13:12:43 -0800385
Andrew Runke6842bf92019-01-26 15:38:25 -0800386 if keyval == Gdk.KEY_p:
387 self.mode = Mode.kPlacing
388 # F0 = A1
389 # B1 = 2F0 - E0
390 # C1= d0 + 4F0 - 4E0
John Park91e69732019-03-03 13:12:43 -0800391 spline_index = len(self.points.getSplines()) - 1
392 self.points.resetPoints()
393 self.points.extrapolate(
394 self.points.getSplines()[len(self.points.getSplines()) - 1][5],
395 self.points.getSplines()[len(self.points.getSplines()) - 1][4],
396 self.points.getSplines()[len(self.points.getSplines()) - 1][3])
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800397
398 def button_press_action(self):
Andrew Runke6842bf92019-01-26 15:38:25 -0800399 if self.mode == Mode.kPlacing:
John Park91e69732019-03-03 13:12:43 -0800400 if self.points.add_point(self.x, self.y):
401 self.mode = Mode.kEditing
Andrew Runke6842bf92019-01-26 15:38:25 -0800402 elif self.mode == Mode.kEditing:
403 # Now after index_of_edit is not -1, the point is selected, so
404 # user can click for new point
405 if self.index_of_edit > -1 and self.held_x != self.x:
John Park91e69732019-03-03 13:12:43 -0800406 self.points.setSplines(self.spline_edit, self.index_of_edit,
407 pxToM(self.x), pxToM(self.y))
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800408
James Kuszmaulb33b07c2021-02-25 22:39:24 -0800409 self.points.splineExtrapolate(self.spline_edit)
Andrew Runke6842bf92019-01-26 15:38:25 -0800410
Andrew Runke6842bf92019-01-26 15:38:25 -0800411 self.index_of_edit = -1
412 self.spline_edit = -1
413 else:
Andrew Runke6842bf92019-01-26 15:38:25 -0800414 # Get clicked point
415 # Find nearest
416 # Move nearest to clicked
John Park13d3e282019-01-26 20:16:48 -0800417 cur_p = [pxToM(self.x), pxToM(self.y)]
Andrew Runke6842bf92019-01-26 15:38:25 -0800418 # Get the distance between each for x and y
419 # Save the index of the point closest
John Park13d3e282019-01-26 20:16:48 -0800420 nearest = 1 # Max distance away a the selected point can be in meters
Andrew Runke6842bf92019-01-26 15:38:25 -0800421 index_of_closest = 0
James Kuszmaul1c933e02020-03-07 16:17:51 -0800422 for index_splines, points in enumerate(
423 self.points.getSplines()):
Andrew Runke6842bf92019-01-26 15:38:25 -0800424 for index_points, val in enumerate(points):
Andrew Runke6842bf92019-01-26 15:38:25 -0800425 distance = np.sqrt((cur_p[0] - val[0])**2 +
426 (cur_p[1] - val[1])**2)
427 if distance < nearest:
428 nearest = distance
429 index_of_closest = index_points
430 print("Nearest: " + str(nearest))
431 print("Index: " + str(index_of_closest))
432 self.index_of_edit = index_of_closest
433 self.spline_edit = index_splines
434 self.held_x = self.x
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800435
436 def do_button_press(self, event):
John Park13d3e282019-01-26 20:16:48 -0800437 # Be consistent with the scaling in the drawing_area
James Kuszmaul1c933e02020-03-07 16:17:51 -0800438 self.x = event.x * 2 - mToPx(WIDTH_OF_FIELD_IN_METERS / 2.0)
Andrew Runkea9c8de52019-01-26 19:54:29 -0800439 self.y = event.y * 2
Tabitha Jarvis1007a132018-12-12 21:47:54 -0800440 self.button_press_action()