From 7a71936fa4e7caa68fea02c88493b2df6a5e175c Mon Sep 17 00:00:00 2001 From: Andras Schaffer Date: Wed, 28 Jul 2021 23:06:48 +0200 Subject: [PATCH] Fix FlightPlanner CTRL-Z undo --- GCSViews/FlightPlanner.cs | 105 ++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 28 deletions(-) diff --git a/GCSViews/FlightPlanner.cs b/GCSViews/FlightPlanner.cs index 92d7c0687c..86e5470c84 100644 --- a/GCSViews/FlightPlanner.cs +++ b/GCSViews/FlightPlanner.cs @@ -140,7 +140,7 @@ public void Init() - // config map + // config map MainMap.CacheLocation = Settings.GetDataDirectory() + "gmapcache" + Path.DirectorySeparatorChar; @@ -176,7 +176,7 @@ public void Init() //MainMap.MaxZoom = 18; - // get zoom + // get zoom MainMap.MinZoom = 0; MainMap.MaxZoom = 24; @@ -573,7 +573,7 @@ public void AddWPToMap(double lat, double lng, int alt) Commands.Rows[selectedrow].Cells[Command.Index].Value = MAVLink.MAV_CMD.WAYPOINT.ToString(); ChangeColumnHeader(MAVLink.MAV_CMD.WAYPOINT.ToString()); } - + updateUndoBuffer(false); setfromMap(lat, lng, alt); } @@ -726,6 +726,7 @@ public void callMeDrag(string pointno, double lat, double lng, int alt) if (pointno == "H") { // auto update home alt + updateUndoBuffer(true); TXT_homealt.Text = (srtm.getAltitude(lat, lng).alt * CurrentState.multiplieralt).ToString(); TXT_homelat.Text = lat.ToString(); @@ -743,14 +744,14 @@ public void callMeDrag(string pointno, double lat, double lng, int alt) { selectedrow = int.Parse(pointno) - 1; Commands.CurrentCell = Commands[1, selectedrow]; - // depending on the dragged item, selectedrow can be reset + // depending on the dragged item, selectedrow can be reset selectedrow = int.Parse(pointno) - 1; } catch { return; } - + updateUndoBuffer(true); setfromMap(lat, lng, alt); } @@ -781,7 +782,7 @@ public T DeepClone(T obj) { double denom = ((end1.Lng - start1.Lng) * (end2.Lat - start2.Lat)) - ((end1.Lat - start1.Lat) * (end2.Lng - start2.Lng)); - // AB & CD are parallel + // AB & CD are parallel if (denom == 0) return PointLatLng.Empty; double numer = ((start1.Lat - start2.Lat) * (end2.Lng - start2.Lng)) - @@ -792,7 +793,7 @@ public T DeepClone(T obj) double s = numer2 / denom; if ((r < 0 || r > 1) || (s < 0 || s > 1)) return PointLatLng.Empty; - // Find intersection point + // Find intersection point PointLatLng result = new PointLatLng(); result.Lng = start1.Lng + (r * (end1.Lng - start1.Lng)); result.Lat = start1.Lat + (r * (end1.Lat - start1.Lat)); @@ -1021,28 +1022,42 @@ public void redrawPolygonSurvey(List list) MainMap.Invalidate(); } - /// - /// Actualy Sets the values into the datagrid and verifys height if turned on - /// - /// - /// - /// - public void setfromMap(double lat, double lng, int alt, double p1 = -1) - { - if (selectedrow > Commands.RowCount) - { - CustomMessageBox.Show("Invalid coord, How did you do this?"); - return; - } + public void updateUndoBuffer(bool noBlankRow) + { try { if (!quickadd) { // get current command list var currentlist = GetCommandList(); + + Locationwp home = new Locationwp(); + try + { + home.id = (ushort)MAVLink.MAV_CMD.WAYPOINT; + + if (MainV2.comPort.MAV.cs.HomeLocation.Lat != 0 && MainV2.comPort.MAV.cs.HomeLocation.Lng != 0) + { + home.lat = MainV2.comPort.MAV.cs.HomeLocation.Lat; + home.lng = MainV2.comPort.MAV.cs.HomeLocation.Lng; + home.alt = (float)MainV2.comPort.MAV.cs.HomeLocation.Alt; + } + else + { + home.lat = MainV2.comPort.MAV.cs.PlannedHomeLocation.Lat; + home.lng = MainV2.comPort.MAV.cs.PlannedHomeLocation.Lng; + home.alt = (float)MainV2.comPort.MAV.cs.PlannedHomeLocation.Alt; + } + } + catch { } + // remove the current blank row that has not been populated yet - currentlist.RemoveAt(selectedrow); + if (!noBlankRow) + { + currentlist.RemoveAt(selectedrow); + } + currentlist.Insert(0, home); // add history history.Add(currentlist); } @@ -1058,6 +1073,23 @@ public void setfromMap(double lat, double lng, int alt, double p1 = -1) history.RemoveRange(0, history.Count - 40); } + } + + /// + /// Actualy Sets the values into the datagrid and verifys height if turned on + /// + /// + /// + /// + public void setfromMap(double lat, double lng, int alt, double p1 = -1) + { + if (selectedrow > Commands.RowCount) + { + CustomMessageBox.Show("Invalid coord, How did you do this?"); + return; + } + + DataGridViewTextBoxCell cell; if (alt == -2 && Commands.Columns[Alt.Index].HeaderText.Equals("Alt")) { @@ -1682,6 +1714,8 @@ public void areaToolStripMenuItem_Click(object sender, EventArgs e) /// public void BUT_Add_Click(object sender, EventArgs e) { + + updateUndoBuffer(true); // no new row added yet. So no need to delete if (Commands.CurrentRow == null) { selectedrow = 0; @@ -2144,6 +2178,7 @@ public void Commands_CellContentClick(object sender, DataGridViewCellEventArgs e return; if (e.ColumnIndex == Delete.Index && (e.RowIndex + 0) < Commands.RowCount) // delete { + updateUndoBuffer(true); quickadd = true; // mono fix Commands.CurrentCell = null; @@ -2154,6 +2189,7 @@ public void Commands_CellContentClick(object sender, DataGridViewCellEventArgs e if (e.ColumnIndex == Up.Index && e.RowIndex != 0) // up { + updateUndoBuffer(true); DataGridViewRow myrow = Commands.CurrentRow; Commands.Rows.Remove(myrow); Commands.Rows.Insert(e.RowIndex - 1, myrow); @@ -2162,6 +2198,7 @@ public void Commands_CellContentClick(object sender, DataGridViewCellEventArgs e if (e.ColumnIndex == Down.Index && e.RowIndex < Commands.RowCount - 1) // down { + updateUndoBuffer(true); DataGridViewRow myrow = Commands.CurrentRow; Commands.Rows.Remove(myrow); Commands.Rows.Insert(e.RowIndex + 1, myrow); @@ -2782,6 +2819,7 @@ public void createSplineCircleToolStripMenuItem_Click(object sender, EventArgs e double a = startangle; double step = 360.0f / Points; + updateUndoBuffer(false); quickadd = true; AddCommand(MAVLink.MAV_CMD.DO_SET_ROI, 0, 0, 0, 0, MouseDownStart.Lng, MouseDownStart.Lat, 0); @@ -2812,6 +2850,7 @@ public void createSplineCircleToolStripMenuItem_Click(object sender, EventArgs e PointLatLng pll = new PointLatLng(lat2 * MathHelper.rad2deg, lon2 * MathHelper.rad2deg); + setfromMap(pll.Lat, pll.Lng, stepalt); if (!startup) @@ -2886,7 +2925,7 @@ public void createWpCircleToolStripMenuItem_Click(object sender, EventArgs e) a += 360; step *= -1; } - + updateUndoBuffer(false); quickadd = true; for (; a <= (startangle + 360) && a >= 0; a += step) @@ -3129,7 +3168,7 @@ public void enterUTMCoordToolStripMenuItem_Click(object sender, EventArgs e) selectedrow = Commands.Rows.Add(); ChangeColumnHeader(MAVLink.MAV_CMD.WAYPOINT.ToString()); - + updateUndoBuffer(false); setfromMap(ans.Lat, ans.Lng, (int) ans.Alt); } @@ -3785,6 +3824,7 @@ public void insertSplineWPToolStripMenuItem_Click(object sender, EventArgs e) ChangeColumnHeader(MAVLink.MAV_CMD.SPLINE_WAYPOINT.ToString()); + updateUndoBuffer(false); setfromMap(MouseDownStart.Lat, MouseDownStart.Lng, (int) float.Parse(TXT_DefaultAlt.Text)); } } @@ -3808,6 +3848,7 @@ public void insertWpToolStripMenuItem_Click(object sender, EventArgs e) ChangeColumnHeader(MAVLink.MAV_CMD.WAYPOINT.ToString()); + updateUndoBuffer(false); setfromMap(MouseDownStart.Lat, MouseDownStart.Lng, (int) float.Parse(TXT_DefaultAlt.Text)); } } @@ -4024,6 +4065,7 @@ public void landToolStripMenuItem_Click(object sender, EventArgs e) ChangeColumnHeader(MAVLink.MAV_CMD.LAND.ToString()); + updateUndoBuffer(false); setfromMap(MouseDownEnd.Lat, MouseDownEnd.Lng, 1); writeKML(); @@ -4468,6 +4510,7 @@ public void loitercirclesToolStripMenuItem_Click(object sender, EventArgs e) ChangeColumnHeader(MAVLink.MAV_CMD.LOITER_TURNS.ToString()); + updateUndoBuffer(false); setfromMap(MouseDownEnd.Lat, MouseDownEnd.Lng, (int) float.Parse(TXT_DefaultAlt.Text)); writeKML(); @@ -4500,6 +4543,7 @@ public void loitertimeToolStripMenuItem_Click(object sender, EventArgs e) ChangeColumnHeader(MAVLink.MAV_CMD.LOITER_TIME.ToString()); + updateUndoBuffer(false); setfromMap(MouseDownEnd.Lat, MouseDownEnd.Lng, (int) float.Parse(TXT_DefaultAlt.Text)); writeKML(); @@ -5458,7 +5502,7 @@ private void savewaypoints() sw.Write((a + 1)); // seq sw.Write("\t" + 0); // current - sw.Write("\t" + ((int) Commands.Rows[a].Cells[Frame.Index].Value).ToString()); //frame + sw.Write("\t" + ((int) Commands.Rows[a].Cells[Frame.Index].Value).ToString()); //frame sw.Write("\t" + mode); sw.Write("\t" + double.Parse(Commands.Rows[a].Cells[Param1.Index].Value.ToString()) @@ -5960,6 +6004,7 @@ public void setROIToolStripMenuItem_Click(object sender, EventArgs e) ChangeColumnHeader(MAVLink.MAV_CMD.DO_SET_ROI.ToString()); + updateUndoBuffer(false); setfromMap(MouseDownEnd.Lat, MouseDownEnd.Lng, (int) float.Parse(TXT_DefaultAlt.Text)); writeKML(); @@ -6514,7 +6559,7 @@ private void updateRowNumbers() if (!IsHandleCreated || IsDisposed || Disposing) return; - // number rows + // number rows BeginInvoke((MethodInvoker) delegate { // thread for updateing row numbers @@ -6552,9 +6597,9 @@ private void updateRowNumbers() /// private string BuildGetCapabilitityRequest(string serverUrl) { - // What happens if the URL already has '?'. + // What happens if the URL already has '?'. // For example: http://foo.com?Token=yyyy - // In this example, the get capability request should be + // In this example, the get capability request should be // http://foo.com?Token=yyyy&version=1.1.0&Request=GetCapabilities&service=WMS but not // http://foo.com?Token=yyyy?version=1.1.0&Request=GetCapabilities&service=WMS @@ -6842,6 +6887,7 @@ private void MainMap_MouseUp(object sender, MouseEventArgs e) if (CurrentMidLine is GMapMarkerPlus) { + updateUndoBuffer(true); int pnt2 = 0; var midline = CurrentMidLine.Tag as midline; // var pnt1 = int.Parse(midline.now.Tag); @@ -6942,6 +6988,9 @@ private void MainMap_MouseUp(object sender, MouseEventArgs e) { if (groupmarkers.Count > 0) { + + updateUndoBuffer(true); + Dictionary dest = new Dictionary(); var markers = MainMap.Overlays.First(a => a.Id == "WPOverlay"); @@ -7451,7 +7500,7 @@ private void ProcessWmsCapabilitesRequest(XmlDocument xCapabilitesResponse) if (nameNode != null) { var name = nameNode.InnerText; - // Set the default title as the layer name. + // Set the default title as the layer name. var title = name; // Get Title element. var titleNode = layerElement.SelectSingleNode("Title", nsmgr);