Add a viewing mode for the spline graph to hide spline handles
Signed-off-by: Jason Anderson-Young <jase.w.andersonyoung@gmail.com>
Change-Id: I7cb6d3a2f01b2d46a22b5cb0e2b022b1e114d87a
diff --git a/frc971/control_loops/python/path_edit.py b/frc971/control_loops/python/path_edit.py
index 437b242..0a944e1 100755
--- a/frc971/control_loops/python/path_edit.py
+++ b/frc971/control_loops/python/path_edit.py
@@ -47,6 +47,7 @@
# add default spline for testing purposes
# init editing / viewing modes and pointer location
self.mode = Mode.kPlacing
+ self.previous_mode = Mode.kPlacing
self.mousex = 0
self.lastx = 0
self.mousey = 0
@@ -192,6 +193,9 @@
for multispline in self.multisplines:
for i, point in enumerate(multispline.staged_points):
draw_px_x(cr, point[0], point[1], self.pxToM(2))
+ if len(self.multisplines) != 0 and self.multisplines[0].getSplines(
+ ): #still in testing
+ self.draw_splines(cr)
elif self.mode == Mode.kEditing:
if len(self.multisplines) != 0 and self.multisplines[0].getSplines(
):
@@ -479,6 +483,11 @@
self.active_multispline_index = self.multisplines.index(
multispline)
+ elif self.mode == Mode.kViewing:
+
+ if self.control_point_index == None:
+ self.drag_start = (event.x, event.y)
+
self.queue_draw()
def do_motion_notify_event(self, event):
@@ -496,12 +505,13 @@
multispline.update_lib_spline()
self.graph.schedule_recalculate(self.multisplines)
- if self.mode == Mode.kEditing and self.drag_start != None and self.control_point_index == None:
+ if self.drag_start != None and self.control_point_index == None:
+ if self.mode == Mode.kEditing or self.mode == Mode.kViewing:
- self.zoom_transform.translate(event.x - self.lastx,
- event.y - self.lasty)
- self.lastx = event.x
- self.lasty = event.y
+ self.zoom_transform.translate(event.x - self.lastx,
+ event.y - self.lasty)
+ self.lastx = event.x
+ self.lasty = event.y
self.queue_draw()
diff --git a/frc971/control_loops/python/spline_graph.py b/frc971/control_loops/python/spline_graph.py
index dc64dfa..fbe43bf 100755
--- a/frc971/control_loops/python/spline_graph.py
+++ b/frc971/control_loops/python/spline_graph.py
@@ -4,6 +4,7 @@
import matplotlib
import gi
from path_edit import FieldWidget
+from path_edit import Mode # still being tested
from basic_window import RunApp
from constants import FIELDS, FIELD, SCREEN_SIZE
@@ -26,6 +27,21 @@
def clear_clicked(self, button):
self.field.clear()
+ def toggle_view_clicked(self, button):
+ temp_variable = self.field.mode
+
+ if self.field.mode != Mode.kViewing:
+ self.field.mode = Mode.kViewing
+ Gtk.Button.set_label(self.toggle_view, "Switch to Editing Mode")
+
+ else:
+ self.field.mode = self.field.previous_mode
+ if self.field.mode == Mode.kEditing:
+ Gtk.Button.set_label(self.toggle_view,
+ "Switch to Viewing Mode")
+
+ self.field.previous_mode = temp_variable
+
def output_json_clicked(self, button):
self.field.export_json(self.file_name_box.get_text())
@@ -155,7 +171,12 @@
self.clear = Gtk.Button.new_with_label("Clear")
self.clear.set_size_request(50, 40)
self.clear.connect("clicked", self.clear_clicked)
+ #-----------currently being edited-----------#
+ self.toggle_view = Gtk.Button.new_with_label("Switch to Viewing Mode")
+ self.toggle_view.set_size_request(100, 40)
+ self.toggle_view.connect("clicked", self.toggle_view_clicked)
+ #--------------------------------------------#
self.undo = Gtk.Button.new_with_label("Undo (Ctrl + Z)")
self.undo.set_size_request(50, 40)
self.undo.connect("clicked", self.undo_func)
@@ -204,11 +225,12 @@
container.attach(limitControls, 5, 1, 1, 1)
jsonControls = Gtk.FlowBox()
- jsonControls.set_min_children_per_line(7)
+ jsonControls.set_min_children_per_line(8)
jsonControls.add(self.file_name_box)
jsonControls.add(self.output_json)
jsonControls.add(self.input_json)
jsonControls.add(self.clear)
+ jsonControls.add(self.toggle_view) #----------------in progress
jsonControls.add(self.undo)
jsonControls.add(self.new_spline)
jsonControls.add(self.new_multispline)