@@ -105,8 +105,6 @@ def clear_scene(self):
105
105
"""
106
106
This function will clear the screen of all objects
107
107
"""
108
- # self.__graphics_grid.clear_scene()
109
-
110
108
# Set all robots variables as invisible
111
109
for robot in self .__robots :
112
110
robot .set_reference_visibility (False )
@@ -338,6 +336,9 @@ def __handle_keyboard_inputs(self):
338
336
def __reload_caption (self , new_list ):
339
337
"""
340
338
Reload the UI with the new list of robot names
339
+
340
+ :param new_list: The new list to apply to the menu
341
+ :type new_list: `list`
341
342
"""
342
343
# Remove all UI elements
343
344
for item in self .__ui_controls :
@@ -353,7 +354,10 @@ def __reload_caption(self, new_list):
353
354
354
355
def __load_mode_ui (self , new_list ):
355
356
"""
357
+ Load the UI menu depending on the current mode
356
358
359
+ :param new_list: The new list to apply to the menu
360
+ :type new_list: `list`
357
361
"""
358
362
if self .__ui_mode == UImode .CANVASCONTROL :
359
363
self .__ui_controls = self .__setup_ui_controls (new_list )
@@ -710,6 +714,7 @@ def __init__(self, height=360, width=640, title='', caption='', grid=True):
710
714
711
715
self .__grid_visibility = grid
712
716
self .__camera_lock = False
717
+ self .__grid_relative = True
713
718
714
719
# Apply HTML title/caption
715
720
if title != '' :
@@ -719,8 +724,14 @@ def __init__(self, height=360, width=640, title='', caption='', grid=True):
719
724
if caption != '' :
720
725
self .scene .caption = caption
721
726
722
- # Rotate the camera
723
- # convert_grid_to_z_up(self.scene)
727
+ self .__ui_controls = []
728
+ self .__reload_caption ()
729
+ # Indices to easily identify entities
730
+ self .__idx_btn_reset = 0 # Camera Reset Button
731
+ self .__idx_chkbox_grid = 1 # Grid Visibility Checkbox
732
+ self .__idx_chkbox_cam = 2 # Camera Lock Checkbox
733
+ self .__idx_chkbox_rel = 3 # Grid Relative Checkbox
734
+ self .__idx_btn_clr = 4 # Clear button
724
735
725
736
# Any time a key or mouse is held down, run the callback function
726
737
rate (30 ) # 30Hz
@@ -743,9 +754,24 @@ def __init__(self, height=360, width=640, title='', caption='', grid=True):
743
754
#######################################
744
755
# Canvas Management
745
756
#######################################
746
- # TODO
747
757
def clear_scene (self ):
748
- pass
758
+ """
759
+ Clear the scene of all objects, keeping the grid visible if set on
760
+ """
761
+ # Save grid visibility
762
+ restore = self .__grid_visibility
763
+
764
+ # Set invis
765
+ if restore :
766
+ self .__graphics_grid .set_visibility (False )
767
+
768
+ # Set all objects invis
769
+ for obj in self .scene .objects :
770
+ obj .visible = False
771
+
772
+ # Restore grid (if needed)
773
+ if restore :
774
+ self .__graphics_grid .set_visibility (True )
749
775
750
776
def grid_visibility (self , is_visible ):
751
777
"""
@@ -759,10 +785,6 @@ def grid_visibility(self, is_visible):
759
785
#######################################
760
786
# UI Management
761
787
#######################################
762
- # TODO
763
- def __setup_ui_controls (self ):
764
- pass
765
-
766
788
def __handle_keyboard_inputs (self ):
767
789
"""
768
790
Pans amount dependent on distance between camera and focus point.
@@ -781,7 +803,7 @@ def __handle_keyboard_inputs(self):
781
803
Q = roll left (rotate)
782
804
E = roll right (rotate)
783
805
784
- ctrl + LMB = rotate (Default Vpython)
806
+ shift + LMB = pan (Default Vpython)
785
807
"""
786
808
# If camera lock, just skip the function
787
809
if self .__camera_lock :
@@ -882,6 +904,109 @@ def __reset_camera(self):
882
904
self .scene .camera .axis = vector (- 0.001 , - 0.001 , - 12 ) # Focus on (5, 5, 0)
883
905
self .scene .up = y_axis_vector
884
906
907
+ def __reload_caption (self ):
908
+ """
909
+ Reload the UI with the new list of robot names
910
+ """
911
+ # Remove all UI elements
912
+ for item in self .__ui_controls :
913
+ item .delete ()
914
+ # Restore the caption
915
+ self .scene .caption = self .__default_caption
916
+ # Create the updated caption.
917
+ self .__setup_ui_controls ()
918
+
919
+ def __setup_ui_controls (self ):
920
+ """
921
+ The initial configuration of the user interface
922
+ """
923
+ self .scene .append_to_caption ('\n ' )
924
+
925
+ # Button to reset camera
926
+ btn_reset = button (bind = self .__reset_camera , text = "Reset Camera" )
927
+ self .scene .append_to_caption ('\t ' )
928
+
929
+ chkbox_cam = checkbox (bind = self .__camera_lock_checkbox , text = "Camera Lock" , checked = self .__camera_lock )
930
+ self .scene .append_to_caption ('\t ' )
931
+
932
+ chkbox_rel = checkbox (bind = self .__grid_relative_checkbox , text = "Grid Relative" , checked = self .__grid_relative )
933
+ self .scene .append_to_caption ('\n \n ' )
934
+
935
+ # Button to clear the screen
936
+ btn_clr = button (bind = self .clear_scene , text = "Clear Scene" )
937
+ self .scene .append_to_caption ('\n \n ' )
938
+
939
+ # Checkbox for grid visibility
940
+ chkbox_grid = checkbox (bind = self .__grid_visibility_checkbox , text = "Grid Visibility" ,
941
+ checked = self .__grid_visibility )
942
+ self .scene .append_to_caption ('\t ' )
943
+
944
+ # Prevent the space bar from toggling the active checkbox/button/etc (default browser behaviour)
945
+ self .scene .append_to_caption ('''
946
+ <script type="text/javascript">
947
+ $(document).keyup(function(event) {
948
+ if(event.which === 32) {
949
+ event.preventDefault();
950
+ }
951
+ });
952
+ </script>''' )
953
+ # https://stackoverflow.com/questions/22280139/prevent-space-button-from-triggering-any-other-button-click-in-jquery
954
+
955
+ # Control manual
956
+ controls_str = '<br><b>Controls</b><br>' \
957
+ '<b>PAN</b><br>' \
958
+ 'SHFT + LMB | <i>free pan</i><br>' \
959
+ 'W , S | <i>up / down</i><br>' \
960
+ 'A , D | <i>left / right</i><br>' \
961
+ '<b>ROTATE</b><br>' \
962
+ 'ARROWS KEYS | <i>rotate direction</i><br>' \
963
+ 'Q , E | <i>roll left / right</i><br>' \
964
+ '<b>ZOOM</b></br>' \
965
+ 'MOUSEWHEEL | <i>zoom in / out</i><br>' \
966
+ '<script type="text/javascript">var arrow_keys_handler = function(e) {switch(e.keyCode){ case 37: case 39: case 38: case 40: case 32: e.preventDefault(); break; default: break;}};window.addEventListener("keydown", arrow_keys_handler, false);</script>'
967
+ # Disable the arrow keys from scrolling in the browser
968
+ # https://stackoverflow.com/questions/8916620/disable-arrow-key-scrolling-in-users-browser
969
+ self .scene .append_to_caption (controls_str )
970
+
971
+ return [btn_reset , chkbox_grid , chkbox_cam , chkbox_rel , btn_clr ]
972
+
973
+ #######################################
974
+ # UI CALLBACKS
975
+ #######################################
976
+ def __camera_lock_checkbox (self , c ):
977
+ """
978
+ When a checkbox is changed for the camera lock, update the camera
979
+
980
+ :param c: The checkbox that has been toggled
981
+ :type c: class:`checkbox`
982
+ """
983
+ # Update parameters
984
+ # True = locked
985
+ self .__camera_lock = c .checked
986
+ # True = enabled
987
+ self .scene .userspin = not c .checked
988
+ self .scene .userzoom = not c .checked
989
+
990
+ def __grid_relative_checkbox (self , c ):
991
+ """
992
+ When a checkbox is changed for the grid lock, update the grid
993
+
994
+ :param c: The checkbox that has been toggled
995
+ :type c: class:`checkbox`
996
+ """
997
+ self .__graphics_grid .set_relative (c .checked )
998
+ self .__grid_relative = c .checked
999
+
1000
+ def __grid_visibility_checkbox (self , c ):
1001
+ """
1002
+ When a checkbox is changed for the grid visibility, update the graphics
1003
+
1004
+ :param c: The checkbox that has been toggled
1005
+ :type c: class:`checkbox`
1006
+ """
1007
+ self .grid_visibility (c .checked )
1008
+ self .__grid_visibility = c .checked
1009
+
885
1010
#######################################
886
1011
# Drawing Functions
887
1012
#######################################
0 commit comments