Remove field drawing functions in Spline UI
Trying to centralize usages of mToPx and pxToM in path_edit
Signed-off-by: Ravago Jones <ravagojones@gmail.com>
Change-Id: Id94d81e1a00439c18bbf9e0f1fee857bec87ef38
diff --git a/frc971/control_loops/python/drawing_constants.py b/frc971/control_loops/python/drawing_constants.py
index 8d64e0b..644e449 100644
--- a/frc971/control_loops/python/drawing_constants.py
+++ b/frc971/control_loops/python/drawing_constants.py
@@ -1,6 +1,5 @@
import cairo
from color import Color, palette
-from constants import *
import numpy as np
@@ -59,467 +58,6 @@
cr.show_text(text)
cr.scale(widthb, -heightb)
-
-def draw_at_home_grid(cr):
- field = np.zeros(shape=(5, 11), dtype=bool)
- # field[row from bottom][column from left]
-
- if GALACTIC_SEARCH in FIELD.tags:
- # Galactic search start zone
- field[1][0] = True
- field[3][0] = True
-
- # Galactic search end zone
- field[1][10] = True
- field[3][10] = True
-
- if ARED in FIELD.tags:
- field[4][5] = True
- field[2][2] = True
- field[1][4] = True
- elif ABLUE in FIELD.tags:
- field[0][5] = True
- field[3][6] = True
- field[2][8] = True
- elif BRED in FIELD.tags:
- field[3][2] = True
- field[1][4] = True
- field[3][6] = True
- elif BBLUE in FIELD.tags:
- field[1][5] = True
- field[3][7] = True
- field[1][9] = True
- elif AUTONAV in FIELD.tags:
- # start/end zone
- field[1][0] = True
- field[1][1] = True
- field[3][0] = True
- field[3][1] = True
-
- if BARREL in FIELD.tags:
- # barrels
- field[1][4] = True
- field[3][7] = True
- field[1][9] = True
- if SLALOM in FIELD.tags:
- field[1][3:8] = True # 3 to 7 inclusive
- field[1][9] = True
- if BOUNCE in FIELD.tags:
- # turn on two rows
- field[1][:11] = True
- field[3][:11] = True
-
- # turn off parts of rows
- field[3][2] = False
- field[3][5] = False
- field[3][8] = False
-
- field[1][3] = False
- field[1][5] = False
- field[1][8] = False
-
- # markers to hit
- field[4][2] = True
- field[4][5] = True
- field[4][8] = True
-
- # Move origin to bottom left
- xorigin = -mToPx(FIELD.width) / 2.0
- yorigin = -mToPx(FIELD.length) / 2.0
-
- color = palette["BLACK"]
- # markers are at least 6.35 x 6.35 cm
- marker_length = mToPx(0.0635)
-
- for row, row_array in enumerate(field):
- for column, has_marker in enumerate(row_array):
- one_indexed_row = row + 1
- one_indexed_column = column + 1
-
- # 76.2 cm increments
- pos_y = one_indexed_row * mToPx(0.762)
- pos_x = one_indexed_column * mToPx(0.762)
-
- if has_marker:
- draw_px_x(cr, xorigin + pos_x, yorigin + pos_y, marker_length,
- color)
-
-
-def markers(cr):
- SHOW_MARKERS = False
- if SHOW_MARKERS:
- # Shield Generator Reference
- color = palette["BLUE"]
- yorigin = 0 - SCREEN_SIZE / 2 # Move origin to bottom left
- # Top Left
- draw_circle(cr, mToPx(inToM(206.625)),
- yorigin + mToPx(inToM(212.097), True), 10, color)
- # Top Right
- draw_circle(cr, mToPx(inToM(373.616)),
- yorigin + mToPx(inToM(281.26), True), 10, color)
- # Bottom Right
- draw_circle(cr, mToPx(inToM(422.625)),
- yorigin + mToPx(inToM(124.67), True), 10, color)
- # Bottom Left
- draw_circle(cr, mToPx(inToM(255.634)),
- yorigin + mToPx(inToM(55.5), True), 10, color)
-
- # Trench Run Reference
- color = palette["GREEN"]
- # Bottom Trench Run
- # Bottom Right
- draw_circle(cr, mToPx(inToM(206.625)), yorigin, 10, color)
- # Top Right
- draw_circle(cr, mToPx(inToM(206.625)),
- yorigin + mToPx(inToM(55.5), True), 10, color)
- # Top Left
- draw_circle(cr, mToPx(inToM(422.625)),
- yorigin + mToPx(inToM(55.5), True), 10, color)
- # Bottom Left
- draw_circle(cr, mToPx(inToM(422.625)), yorigin, 10, color)
-
- # Top Trench Run
- # Top Right
- draw_circle(cr, mToPx(inToM(206.625)),
- yorigin + mToPx(inToM(323.25), True), 10, color)
- # Bottom Right
- draw_circle(cr, mToPx(inToM(206.625)),
- yorigin + mToPx(inToM(281.26), True), 10, color)
- # Top Left
- draw_circle(cr, mToPx(inToM(422.625)),
- yorigin + mToPx(inToM(281.26), True), 10, color)
- # Bottom Left
- draw_circle(cr, mToPx(inToM(422.625)),
- yorigin + mToPx(inToM(323.25), True), 10, color)
- cr.stroke()
-
-
-def draw_init_lines(cr):
- set_color(cr, palette["RED"])
- init_line_x = FIELD.width / 2.0 - inToM(120)
- init_start_y = -FIELD.length / 2.0
- init_end_y = FIELD.length / 2.0
- cr.move_to(mToPx(init_line_x), mToPx(init_start_y))
- cr.line_to(mToPx(init_line_x), mToPx(init_end_y))
-
- cr.move_to(mToPx(-init_line_x), mToPx(init_start_y))
- cr.line_to(mToPx(-init_line_x), mToPx(init_end_y))
-
- cr.stroke()
-
-
-def draw_trench_run(cr):
- edge_of_field_y = FIELD.length / 2.0
- edge_of_trench_y = edge_of_field_y - inToM(55.5)
- trench_start_x = inToM(-108.0)
- trench_length_x = inToM(216.0)
- ball_line_y = edge_of_field_y - inToM(27.75)
- ball_one_x = -inToM(72)
- ball_two_x = -inToM(36)
- ball_three_x = 0.0
- # The fourth/fifth balls are referenced off of the init line...
- ball_fourfive_x = FIELD.width / 2.0 - inToM(120.0 + 130.36)
-
- for sign in [1.0, -1.0]:
- set_color(cr, palette["GREEN"])
- cr.rectangle(
- mToPx(sign * trench_start_x), mToPx(sign * edge_of_field_y),
- mToPx(sign * trench_length_x),
- mToPx(sign * (edge_of_trench_y - edge_of_field_y)))
- cr.stroke()
- draw_circle(cr, mToPx(sign * ball_one_x), mToPx(sign * ball_line_y),
- mToPx(0.1), palette["YELLOW"])
- draw_circle(cr, mToPx(sign * ball_two_x), mToPx(sign * ball_line_y),
- mToPx(0.1), palette["YELLOW"])
- draw_circle(cr, mToPx(sign * ball_three_x), mToPx(sign * ball_line_y),
- mToPx(0.1), palette["YELLOW"])
-
- cr.stroke()
-
-
-def draw_shield_generator(cr):
- set_color(cr, palette["BLUE"])
- cr.save()
- cr.rotate(22.5 * np.pi / 180.)
- generator_width = mToPx(inToM(14 * 12 + 0.75))
- generator_height = mToPx(inToM(13 * 12 + 1.5))
- cr.rectangle(-generator_width / 2.0, -generator_height / 2.0,
- generator_width, generator_height)
- cr.restore()
-
- cr.stroke()
-
-
-def draw_control_panel(cr): # Base plates are not included
- set_color(cr, palette["LIGHT_GREY"])
- edge_of_field_y = FIELD.length / 2.0
- edge_of_trench_y = edge_of_field_y - inToM(55.5)
- high_x = inToM(374.59) - FIELD.width / 2.0
- low_x = high_x - inToM(30)
- for sign in [1.0, -1.0]:
- # Bottom Control Panel
- # Top Line
- cr.rectangle(sign * mToPx(high_x), sign * mToPx(edge_of_field_y),
- -sign * mToPx(inToM(30)), -sign * mToPx(inToM(55.5)))
-
- cr.stroke()
-
-
-def draw_HAB(cr):
- # BASE Constants
- X_BASE = 0
- Y_BASE = 0
- R = 0.381 - .1
- BACKWALL_X = X_BASE
- LOADING_Y = mToPx(4.129151) - mToPx(0.696976)
- # HAB Levels 2 and 3 called in variables backhab
- # draw loading stations
- cr.move_to(0, LOADING_Y)
- cr.line_to(mToPx(0.6), LOADING_Y)
- cr.move_to(mToPx(R), LOADING_Y)
- cr.arc(mToPx(R), LOADING_Y, 5, 0, np.pi * 2.0)
- cr.move_to(0, -1.0 * LOADING_Y)
- cr.line_to(mToPx(0.6), -1.0 * LOADING_Y)
- cr.move_to(mToPx(R), -1.0 * LOADING_Y)
- cr.arc(mToPx(R), -1.0 * LOADING_Y, 5, 0, np.pi * 2.0)
-
- # HAB Levels 2 and 3 called in variables backhab
- WIDTH_BACKHAB = mToPx(1.2192)
-
- Y_TOP_BACKHAB_BOX = Y_BASE + mToPx(0.6096)
- BACKHAB_LV2_LENGTH = mToPx(1.016)
-
- BACKHAB_LV3_LENGTH = mToPx(1.2192)
- Y_LV3_BOX = Y_TOP_BACKHAB_BOX - BACKHAB_LV3_LENGTH
-
- Y_BOTTOM_BACKHAB_BOX = Y_LV3_BOX - BACKHAB_LV2_LENGTH
-
- # HAB LEVEL 1
- X_LV1_BOX = BACKWALL_X + WIDTH_BACKHAB
-
- WIDTH_LV1_BOX = mToPx(0.90805)
- LENGTH_LV1_BOX = mToPx(1.6256)
-
- Y_BOTTOM_LV1_BOX = Y_BASE - LENGTH_LV1_BOX
-
- # Ramp off Level 1
- X_RAMP = X_LV1_BOX
-
- Y_TOP_RAMP = Y_BASE + LENGTH_LV1_BOX
- WIDTH_TOP_RAMP = mToPx(1.20015)
- LENGTH_TOP_RAMP = Y_BASE + mToPx(0.28306)
-
- X_MIDDLE_RAMP = X_RAMP + WIDTH_LV1_BOX
- Y_MIDDLE_RAMP = Y_BOTTOM_LV1_BOX
- LENGTH_MIDDLE_RAMP = 2 * LENGTH_LV1_BOX
- WIDTH_MIDDLE_RAMP = WIDTH_TOP_RAMP - WIDTH_LV1_BOX
-
- Y_BOTTOM_RAMP = Y_BASE - LENGTH_LV1_BOX - LENGTH_TOP_RAMP
-
- # Side Bars to Hold in balls
- X_BARS = BACKWALL_X
- WIDTH_BARS = WIDTH_BACKHAB
- LENGTH_BARS = mToPx(0.574675)
-
- Y_TOP_BAR = Y_TOP_BACKHAB_BOX + BACKHAB_LV2_LENGTH
-
- Y_BOTTOM_BAR = Y_BOTTOM_BACKHAB_BOX - LENGTH_BARS
-
- set_color(cr, palette["BLACK"])
- cr.rectangle(BACKWALL_X, Y_TOP_BACKHAB_BOX, WIDTH_BACKHAB,
- BACKHAB_LV2_LENGTH)
- cr.rectangle(BACKWALL_X, Y_LV3_BOX, WIDTH_BACKHAB, BACKHAB_LV3_LENGTH)
- cr.rectangle(BACKWALL_X, Y_BOTTOM_BACKHAB_BOX, WIDTH_BACKHAB,
- BACKHAB_LV2_LENGTH)
- cr.rectangle(X_LV1_BOX, Y_BASE, WIDTH_LV1_BOX, LENGTH_LV1_BOX)
- cr.rectangle(X_LV1_BOX, Y_BOTTOM_LV1_BOX, WIDTH_LV1_BOX, LENGTH_LV1_BOX)
- cr.rectangle(X_RAMP, Y_TOP_RAMP, WIDTH_TOP_RAMP, LENGTH_TOP_RAMP)
- cr.rectangle(X_MIDDLE_RAMP, Y_MIDDLE_RAMP, WIDTH_MIDDLE_RAMP,
- LENGTH_MIDDLE_RAMP)
- cr.rectangle(X_RAMP, Y_BOTTOM_RAMP, WIDTH_TOP_RAMP, LENGTH_TOP_RAMP)
- cr.rectangle(X_BARS, Y_TOP_BAR, WIDTH_BARS, LENGTH_BARS)
- cr.rectangle(X_BARS, Y_BOTTOM_BAR, WIDTH_BARS, LENGTH_BARS)
- cr.stroke()
-
- cr.set_line_join(cairo.LINE_JOIN_ROUND)
-
- cr.stroke()
-
- #draw 0, 0
- set_color(cr, palette["BLACK"])
- cr.move_to(0, 0)
- cr.line_to(0, 0 + mToPx(8.2296 / 2.0))
- cr.move_to(0, 0)
- cr.line_to(0, 0 + mToPx(-8.2296 / 2.0))
- cr.move_to(0, 0)
- cr.line_to(0 + mToPx(8.2296), 0)
-
- cr.stroke()
-
-
-def draw_rockets(cr):
- # BASE Constants
- X_BASE = mToPx(2.41568)
- Y_BASE = 0
- # Robot longitudinal radius
- R = 0.381
- near_side_rocket_center = [
- X_BASE + mToPx((2.89973 + 3.15642) / 2.0), Y_BASE + mToPx(
- (3.86305 + 3.39548) / 2.0)
- ]
- middle_rocket_center = [
- X_BASE + mToPx((3.15642 + 3.6347) / 2.0), Y_BASE + mToPx(
- (3.39548 + 3.392380) / 2.0)
- ]
- far_side_rocket_center = [
- X_BASE + mToPx((3.63473 + 3.89984) / 2.0), Y_BASE + mToPx(
- (3.39238 + 3.86305) / 2.0)
- ]
-
- cr.move_to(near_side_rocket_center[0], near_side_rocket_center[1])
- cr.line_to(near_side_rocket_center[0] - 0.8 * mToPx(0.866),
- near_side_rocket_center[1] - 0.8 * mToPx(0.5))
- cr.move_to(near_side_rocket_center[0] - R * mToPx(0.866),
- near_side_rocket_center[1] - R * mToPx(0.5))
- cr.arc(near_side_rocket_center[0] - R * mToPx(0.866),
- near_side_rocket_center[1] - R * mToPx(0.5), 5, 0, np.pi * 2.0)
-
- cr.move_to(middle_rocket_center[0], middle_rocket_center[1])
- cr.line_to(middle_rocket_center[0], middle_rocket_center[1] - mToPx(0.8))
- cr.move_to(middle_rocket_center[0], middle_rocket_center[1] - mToPx(R))
- cr.arc(middle_rocket_center[0], middle_rocket_center[1] - mToPx(R), 5, 0,
- np.pi * 2.0)
-
- cr.move_to(far_side_rocket_center[0], far_side_rocket_center[1])
- cr.line_to(far_side_rocket_center[0] + 0.8 * mToPx(0.866),
- far_side_rocket_center[1] - 0.8 * mToPx(0.5))
- cr.move_to(far_side_rocket_center[0] + R * mToPx(0.866),
- far_side_rocket_center[1] - R * mToPx(0.5))
- cr.arc(far_side_rocket_center[0] + R * mToPx(0.866),
- far_side_rocket_center[1] - R * mToPx(0.5), 5, 0, np.pi * 2.0)
-
- #print(far_side_rocket_center)
- near_side_rocket_center = [
- X_BASE + mToPx((2.89973 + 3.15642) / 2.0), Y_BASE - mToPx(
- (3.86305 + 3.39548) / 2.0)
- ]
- middle_rocket_center = [
- X_BASE + mToPx((3.15642 + 3.6347) / 2.0), Y_BASE - mToPx(
- (3.39548 + 3.392380) / 2.0)
- ]
- far_side_rocket_center = [
- X_BASE + mToPx((3.63473 + 3.89984) / 2.0), Y_BASE - mToPx(
- (3.39238 + 3.86305) / 2.0)
- ]
-
- cr.move_to(near_side_rocket_center[0], near_side_rocket_center[1])
- cr.line_to(near_side_rocket_center[0] - 0.8 * mToPx(0.866),
- near_side_rocket_center[1] + 0.8 * mToPx(0.5))
-
- cr.move_to(middle_rocket_center[0], middle_rocket_center[1])
- cr.line_to(middle_rocket_center[0], middle_rocket_center[1] + mToPx(0.8))
-
- cr.move_to(far_side_rocket_center[0], far_side_rocket_center[1])
- cr.line_to(far_side_rocket_center[0] + 0.8 * mToPx(0.866),
- far_side_rocket_center[1] + 0.8 * mToPx(0.5))
-
- # Leftmost Line
- cr.move_to(X_BASE + mToPx(2.89973), Y_BASE + mToPx(3.86305))
- cr.line_to(X_BASE + mToPx(3.15642), Y_BASE + mToPx(3.39548))
-
- # Top Line
- cr.move_to(X_BASE + mToPx(3.15642), Y_BASE + mToPx(3.39548))
- cr.line_to(X_BASE + mToPx(3.63473), Y_BASE + mToPx(3.39238))
-
- #Rightmost Line
- cr.move_to(X_BASE + mToPx(3.63473), Y_BASE + mToPx(3.39238))
- cr.line_to(X_BASE + mToPx(3.89984), Y_BASE + mToPx(3.86305))
-
- #Back Line
- cr.move_to(X_BASE + mToPx(2.89973), Y_BASE + mToPx(3.86305))
- cr.line_to(X_BASE + mToPx(3.89984), Y_BASE + mToPx(3.86305))
-
- # Bottom Rocket
- # Leftmost Line
- cr.move_to(X_BASE + mToPx(2.89973), Y_BASE - mToPx(3.86305))
- cr.line_to(X_BASE + mToPx(3.15642), Y_BASE - mToPx(3.39548))
-
- # Top Line
- cr.move_to(X_BASE + mToPx(3.15642), Y_BASE - mToPx(3.39548))
- cr.line_to(X_BASE + mToPx(3.63473), Y_BASE - mToPx(3.39238))
-
- #Rightmost Line
- cr.move_to(X_BASE + mToPx(3.63473), Y_BASE - mToPx(3.39238))
- cr.line_to(X_BASE + mToPx(3.89984), Y_BASE - mToPx(3.86305))
-
- #Back Line
- cr.move_to(X_BASE + mToPx(2.89973), Y_BASE - mToPx(3.86305))
- cr.line_to(X_BASE + mToPx(3.89984), Y_BASE - mToPx(3.86305))
-
- cr.stroke()
-
-
-def draw_cargo_ship(cr):
- # BASE Constants
- X_BASE = 0 + mToPx(5.59435)
- Y_BASE = 0 + 0 #mToPx(4.129151)
- R = 0.381 - 0.1
-
- FRONT_PEG_DELTA_Y = mToPx(0.276352)
- cr.move_to(X_BASE, Y_BASE + FRONT_PEG_DELTA_Y)
- cr.line_to(X_BASE - mToPx(0.8), Y_BASE + FRONT_PEG_DELTA_Y)
-
- cr.move_to(X_BASE, Y_BASE + FRONT_PEG_DELTA_Y)
- cr.arc(X_BASE - mToPx(R), Y_BASE + FRONT_PEG_DELTA_Y, 5, 0, np.pi * 2.0)
-
- cr.move_to(X_BASE, Y_BASE - FRONT_PEG_DELTA_Y)
- cr.line_to(X_BASE - mToPx(0.8), Y_BASE - FRONT_PEG_DELTA_Y)
-
- cr.move_to(X_BASE, Y_BASE - FRONT_PEG_DELTA_Y)
- cr.arc(X_BASE - mToPx(R), Y_BASE - FRONT_PEG_DELTA_Y, 5, 0, np.pi * 2.0)
-
- SIDE_PEG_Y = mToPx(1.41605 / 2.0)
- SIDE_PEG_X = X_BASE + mToPx(1.148842)
- SIDE_PEG_DX = mToPx(0.55245)
-
- cr.move_to(SIDE_PEG_X, SIDE_PEG_Y)
- cr.line_to(SIDE_PEG_X, SIDE_PEG_Y + mToPx(0.8))
- cr.move_to(SIDE_PEG_X, SIDE_PEG_Y + mToPx(R))
- cr.arc(SIDE_PEG_X, SIDE_PEG_Y + mToPx(R), 5, 0, np.pi * 2.0)
-
- cr.move_to(SIDE_PEG_X + SIDE_PEG_DX, SIDE_PEG_Y)
- cr.line_to(SIDE_PEG_X + SIDE_PEG_DX, SIDE_PEG_Y + mToPx(0.8))
- cr.move_to(SIDE_PEG_X + SIDE_PEG_DX, SIDE_PEG_Y + mToPx(R))
- cr.arc(SIDE_PEG_X + SIDE_PEG_DX, SIDE_PEG_Y + mToPx(R), 5, 0, np.pi * 2.0)
-
- cr.move_to(SIDE_PEG_X + 2.0 * SIDE_PEG_DX, SIDE_PEG_Y)
- cr.line_to(SIDE_PEG_X + 2.0 * SIDE_PEG_DX, SIDE_PEG_Y + mToPx(0.8))
- cr.move_to(SIDE_PEG_X + 2.0 * SIDE_PEG_DX, SIDE_PEG_Y + mToPx(R))
- cr.arc(SIDE_PEG_X + 2.0 * SIDE_PEG_DX, SIDE_PEG_Y + mToPx(R), 5, 0,
- np.pi * 2.0)
-
- cr.move_to(SIDE_PEG_X, -1.0 * SIDE_PEG_Y)
- cr.line_to(SIDE_PEG_X, -1.0 * SIDE_PEG_Y - mToPx(0.8))
- cr.move_to(SIDE_PEG_X, -1.0 * SIDE_PEG_Y - mToPx(R))
- cr.arc(SIDE_PEG_X, -1.0 * SIDE_PEG_Y - mToPx(R), 5, 0, np.pi * 2.0)
-
- cr.move_to(SIDE_PEG_X + SIDE_PEG_DX, -1.0 * SIDE_PEG_Y)
- cr.line_to(SIDE_PEG_X + SIDE_PEG_DX, -1.0 * SIDE_PEG_Y - mToPx(0.8))
- cr.move_to(SIDE_PEG_X + SIDE_PEG_DX, -1.0 * SIDE_PEG_Y - mToPx(R))
- cr.arc(SIDE_PEG_X + SIDE_PEG_DX, -1.0 * SIDE_PEG_Y - mToPx(R), 5, 0,
- np.pi * 2.0)
-
- cr.move_to(SIDE_PEG_X + 2.0 * SIDE_PEG_DX, -1.0 * SIDE_PEG_Y)
- cr.line_to(SIDE_PEG_X + 2.0 * SIDE_PEG_DX, -1.0 * SIDE_PEG_Y - mToPx(0.8))
- cr.move_to(SIDE_PEG_X + 2.0 * SIDE_PEG_DX, -1.0 * SIDE_PEG_Y - mToPx(R))
- cr.arc(SIDE_PEG_X + 2.0 * SIDE_PEG_DX, -1.0 * SIDE_PEG_Y - mToPx(R), 5, 0,
- np.pi * 2.0)
-
- cr.rectangle(X_BASE, Y_BASE - mToPx(1.41605 / 2.0), mToPx(2.43205),
- mToPx(1.41605))
- cr.stroke()
-
-
def draw_points(cr, p, size):
for i in range(0, len(p)):
draw_px_cross(cr, p[i][0], p[i][1], size, Color(
diff --git a/frc971/control_loops/python/path_edit.py b/frc971/control_loops/python/path_edit.py
index d402593..3386bc6 100755
--- a/frc971/control_loops/python/path_edit.py
+++ b/frc971/control_loops/python/path_edit.py
@@ -52,8 +52,6 @@
self.held_x = 0
self.spline_edit = -1
- self.curves = []
-
try:
self.field_png = cairo.ImageSurface.create_from_png(
"frc971/control_loops/python/field_images/" + FIELD.field_id +
@@ -185,30 +183,22 @@
if self.mode == Mode.kPlacing or self.mode == Mode.kViewing:
set_color(cr, palette["BLACK"])
- plotPoints = self.points.getPoints()
- if plotPoints:
- for i, point in enumerate(plotPoints):
- draw_px_x(cr, mToPx(point[0]), mToPx(point[1]), 10)
- cr.move_to(mToPx(point[0]), mToPx(point[1]) - 15)
- display_text(cr, str(i), 0.5, 0.5, 2, 2)
+ for i, point in enumerate(self.points.getPoints()):
+ draw_px_x(cr, mToPx(point[0]), mToPx(point[1]), 10)
set_color(cr, palette["WHITE"])
-
elif self.mode == Mode.kEditing:
set_color(cr, palette["BLACK"])
- cr.move_to(-SCREEN_SIZE, 170)
- display_text(cr, "EDITING", 1, 1, 1, 1)
if self.points.getSplines():
self.draw_splines(cr)
for i, points in enumerate(self.points.getSplines()):
- p0 = np.array([mToPx(points[0][0]), mToPx(points[0][1])])
- p1 = np.array([mToPx(points[1][0]), mToPx(points[1][1])])
- p2 = np.array([mToPx(points[2][0]), mToPx(points[2][1])])
- p3 = np.array([mToPx(points[3][0]), mToPx(points[3][1])])
- p4 = np.array([mToPx(points[4][0]), mToPx(points[4][1])])
- p5 = np.array([mToPx(points[5][0]), mToPx(points[5][1])])
+ points = [
+ np.array([mToPx(x), mToPx(y)])
+ for (x, y) in points
+ ]
+ draw_control_points(cr, points)
- draw_control_points(cr, [p0, p1, p2, p3, p4, p5])
+ p0, p1, p2, p3, p4, p5 = points
first_tangent = p0 + 2.0 * (p1 - p0)
second_tangent = p5 + 2.0 * (p4 - p5)
cr.set_source_rgb(0, 0.5, 0)
@@ -239,7 +229,6 @@
print("spent {:.2f} ms drawing the field widget".format(1000 * (time.perf_counter() - start_time)))
def draw_splines(self, cr):
- holder_spline = []
for i, points in enumerate(self.points.getSplines()):
array = np.zeros(shape=(6, 2), dtype=float)
for j, point in enumerate(points):
@@ -253,15 +242,9 @@
cr.line_to(
mToPx(spline.Point(k)[0]), mToPx(spline.Point(k)[1]))
cr.stroke()
- holding = [
- spline.Point(k - 0.01)[0],
- spline.Point(k - 0.01)[1]
- ]
- holder_spline.append(holding)
if i == 0:
self.draw_robot_at_point(cr, 0.00, 0.01, spline)
self.draw_robot_at_point(cr, 1, 0.01, spline)
- self.curves.append(holder_spline)
def mouse_move(self, event):
old_x = self.mousex
@@ -274,8 +257,9 @@
if self.mode == Mode.kEditing:
self.points.updates_for_mouse_move(self.index_of_edit,
- self.spline_edit, self.mousex,
- self.mousey, difs)
+ self.spline_edit,
+ pxToM(self.mousex),
+ pxToM(self.mousey), difs)
def export_json(self, file_name):
self.path_to_export = os.path.join(
@@ -347,7 +331,8 @@
self.mousey = event.y
if self.mode == Mode.kPlacing:
- if self.points.add_point(self.mousex, self.mousey):
+ if self.points.add_point(
+ pxToM(self.mousex), pxToM(self.mousey)):
self.mode = Mode.kEditing
elif self.mode == Mode.kEditing:
# Now after index_of_edit is not -1, the point is selected, so
diff --git a/frc971/control_loops/python/points.py b/frc971/control_loops/python/points.py
index c22582e..d874306 100644
--- a/frc971/control_loops/python/points.py
+++ b/frc971/control_loops/python/points.py
@@ -70,7 +70,7 @@
def updates_for_mouse_move(self, index_of_edit, spline_edit, x, y, difs):
if index_of_edit > -1:
- self.splines[spline_edit][index_of_edit] = [pxToM(x), pxToM(y)]
+ self.splines[spline_edit][index_of_edit] = [x, y]
if index_of_edit == 5:
self.splines[spline_edit][
@@ -150,7 +150,7 @@
def add_point(self, x, y):
if (len(self.points) < 6):
- self.points.append([pxToM(x), pxToM(y)])
+ self.points.append([x, y])
if (len(self.points) == 6):
self.splines.append(np.array(self.points))
self.points = []
diff --git a/frc971/control_loops/python/spline_graph.py b/frc971/control_loops/python/spline_graph.py
index ad3ae96..1378e8f 100755
--- a/frc971/control_loops/python/spline_graph.py
+++ b/frc971/control_loops/python/spline_graph.py
@@ -12,6 +12,7 @@
import basic_window
import os
+
class GridWindow(Gtk.Window):
def method_connect(self, event, cb):
def handler(obj, *args):