3838ME_DOWN_COL = 11
3939ME_DIST_COL = 12
4040ME_ANGLE_COL = 13
41+ ME_AGL_COL = 14
4142
4243
4344class ListCtrlComboPopup (wx .ComboPopup ):
@@ -260,6 +261,7 @@ def __init__(self, state, elemodel='SRTM3', *args, **kwds):
260261 self .grid_mission .SetColAttr (ME_DOWN_COL , self .down_attr )
261262 self .grid_mission .SetColAttr (ME_DIST_COL , self .read_only_attr )
262263 self .grid_mission .SetColAttr (ME_ANGLE_COL , self .read_only_attr )
264+ self .grid_mission .SetColAttr (ME_AGL_COL , self .read_only_attr )
263265 self .grid_mission .SetRowLabelSize (50 )
264266
265267 #remember what mission we opened/saved last
@@ -282,7 +284,7 @@ def __set_properties(self):
282284 self .label_home_lon_value .SetMinSize ((100 , 17 ))
283285 self .label_home_lon_value .SetForegroundColour (wx .Colour (0 , 127 , 255 ))
284286 self .label_home_alt_value .SetForegroundColour (wx .Colour (0 , 127 , 255 ))
285- self .grid_mission .CreateGrid (0 , 14 )
287+ self .grid_mission .CreateGrid (0 , 15 )
286288 self .grid_mission .SetRowLabelSize (20 )
287289 self .grid_mission .SetColLabelSize (20 )
288290 self .grid_mission .SetColLabelValue (0 , "Command" )
@@ -301,6 +303,7 @@ def __set_properties(self):
301303 self .grid_mission .SetDefaultColSize (- 1 )
302304 self .grid_mission .SetColLabelValue (12 , "Distance" )
303305 self .grid_mission .SetColLabelValue (13 , "Grad (deg)" )
306+ self .grid_mission .SetColLabelValue (14 , "AGL" )
304307 # end wxGlade
305308
306309 def __do_layout (self ):
@@ -412,6 +415,7 @@ def process_gui_event(self, event):
412415 self .grid_mission .SetColSize (ME_ALT_COL , 75 )
413416 self .grid_mission .SetColSize (ME_DIST_COL , 1 )
414417 self .grid_mission .SetColSize (ME_ANGLE_COL , 1 )
418+ self .grid_mission .SetColSize (ME_AGL_COL , 1 )
415419
416420 self .grid_mission .ForceRefresh ()
417421 elif event .get_type () == me_event .MEGE_ADD_MISS_TABLE_ROWS :
@@ -458,6 +462,7 @@ def process_gui_event(self, event):
458462 self .grid_mission .SetCellValue (row , ME_ALT_COL ,
459463 "%.2f" % event .get_arg ("alt" ))
460464 self .set_grad_dist ()
465+ self .set_agl ()
461466
462467 frame_num = event .get_arg ("frame" )
463468 if frame_num in me_defines .frame_enum :
@@ -532,6 +537,7 @@ def prep_new_rows(self, start_row, num_rows):
532537 def set_modified_state (self , modified ):
533538 if (modified ):
534539 self .set_grad_dist ()
540+ self .set_agl ()
535541 self .label_sync_state .SetLabel ("MODIFIED" )
536542 self .label_sync_state .SetForegroundColour (wx .Colour (255 , 0 , 0 ))
537543 else :
@@ -720,6 +726,7 @@ def on_mission_grid_cell_select(self, event): # wxGlade: MissionEditorFrame.<ev
720726 self .grid_mission .SetColLabelValue (ME_ALT_COL , "Alt" )
721727 self .grid_mission .SetColLabelValue (ME_DIST_COL , "Distance" )
722728 self .grid_mission .SetColLabelValue (ME_ANGLE_COL , "Grad (deg)" )
729+ self .grid_mission .SetColLabelValue (ME_AGL_COL , "AGL" )
723730
724731 if event .GetRow () == self .grid_mission .GetNumberRows ():
725732 # this event fires when last row is deleted; ignore
@@ -941,6 +948,30 @@ def set_grad_dist(self):
941948 grad = format (grad , '.1f' )
942949 self .grid_mission .SetCellValue (row , ME_DIST_COL , str (dist ))
943950 self .grid_mission .SetCellValue (row , ME_ANGLE_COL , str (grad ))
951+
952+ def set_agl (self ):
953+ '''update agl altitude when changing cell values'''
954+ home_def_alt = float (self .label_home_alt_value .GetLabel ())
955+ numrows = self .grid_mission .GetNumberRows ()
956+ for row in range (0 ,numrows ):
957+ command = self .grid_mission .GetCellValue (row , ME_COMMAND_COL )
958+ lat = float (self .grid_mission .GetCellValue (row , ME_LAT_COL ))
959+ lon = float (self .grid_mission .GetCellValue (row , ME_LON_COL ))
960+ agl = 0.0
961+ elevation = self .ElevationModel .GetElevation (lat , lon )
962+ if elevation == None :
963+ continue
964+ if self .has_location (lat , lon , command ) and "NAV" in command :
965+ agl = float (self .grid_mission .GetCellValue (row , ME_ALT_COL ))
966+ frame = self .grid_mission .GetCellValue (row , ME_FRAME_COL )
967+ if frame == "Rel" :
968+ agl = agl + home_def_alt - elevation
969+ elif self .grid_mission .GetCellValue (row , ME_FRAME_COL ) == "Abs" :
970+ agl = agl - elevation
971+ else :
972+ continue
973+ agl = format (float (agl ), '.1f' )
974+ self .grid_mission .SetCellValue (row , ME_AGL_COL , agl )
944975
945976 def on_idle (self , event ):
946977 now = time .time ()
0 commit comments