Skip to content

Commit

Permalink
Offset Polygon Menu Item
Browse files Browse the repository at this point in the history
Added a menu item to offset a polygon on the plan page
  • Loading branch information
aunrela authored and meee1 committed Feb 7, 2022
1 parent 640102e commit d31428f
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 8 deletions.
18 changes: 18 additions & 0 deletions GCSViews/FlightPlanner.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions GCSViews/FlightPlanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3557,6 +3557,57 @@ public void fromCurrentWaypointsMenuItem_Click(object sender, EventArgs e)
clearMissionToolStripMenuItem_Click(null, null); // perhaps not best practice to directly call "click" events
}
}
private void offsetPolygonToolStripMenuItem_Click(object sender, EventArgs e)
{
if (drawnpolygon.Points.Count == 0)
{
return;
}
string meter = "0";
double intmeter = 0;
if (InputBox.Show("Offset in Meters", "Please enter the offset in meters. Enter a negative value to make the polygon smaller", ref meter) == DialogResult.OK)
{
if (meter != "0")
{
intmeter = double.Parse(meter);
}
}
List<PointLatLngAlt> list = new List<PointLatLngAlt>();
drawnpolygon.Points.ForEach(x => { list.Add(x); });

List<utmpos> ans = new List<utmpos>();

// utm zone distance calcs will be done in
int utmzone = list[0].GetUTMZone();

// utm position list
List<utmpos> utmpositions = utmpos.ToList(PointLatLngAlt.ToUTM(utmzone, list), utmzone);

// close the loop if its not already
if (utmpositions[0] != utmpositions[utmpositions.Count - 1])
utmpositions.Add(utmpositions[0]); // make a full loop

ClipperLib.ClipperOffset clipperOffset = new ClipperLib.ClipperOffset();

clipperOffset.AddPath(utmpositions.Select(a => { return new ClipperLib.IntPoint(a.x * 1000.0, a.y * 1000.0); }).ToList(), ClipperLib.JoinType.jtMiter, ClipperLib.EndType.etClosedPolygon);

List<utmpos> ans1 = new List<utmpos>();

ClipperLib.PolyTree tree = new ClipperLib.PolyTree();
clipperOffset.Execute(ref tree, (Int64)(intmeter * 1000.0));

if (tree.ChildCount == 0)
return;

foreach (var treeChild in tree.Childs)
{
ans1 = treeChild.Contour.Select(a => new utmpos(a.X / 1000.0, a.Y / 1000.0, utmzone))
.ToList();

ans.AddRange(ans1);
}
redrawPolygonSurvey(ans.Select(plla => { var a = plla.ToLLA(); a.Tag = "S"; return a; }).ToList());
}

void DoGeofencePointsUpload(IProgressReporterDialogue PRD)
{
Expand Down
40 changes: 32 additions & 8 deletions GCSViews/FlightPlanner.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@
<value>Commands</value>
</data>
<data name="&gt;&gt;Commands.Type" xml:space="preserve">
<value>MissionPlanner.Controls.MyDataGridView, MissionPlanner, Version=1.3.7898.21436, Culture=neutral, PublicKeyToken=null</value>
<value>MissionPlanner.Controls.MyDataGridView, MissionPlanner, Version=1.3.8064.23188, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;Commands.Parent" xml:space="preserve">
<value>panelWaypoints</value>
Expand Down Expand Up @@ -1910,6 +1910,12 @@
<data name="fromCurrentWaypointsToolStripMenuItem.Text" xml:space="preserve">
<value>From Current Waypoints</value>
</data>
<data name="offsetPolygonToolStripMenuItem2.Size" type="System.Drawing.Size, System.Drawing">
<value>204, 22</value>
</data>
<data name="offsetPolygonToolStripMenuItem2.Text" xml:space="preserve">
<value>Offset Polygon</value>
</data>
<data name="areaToolStripMenuItem2.Size" type="System.Drawing.Size, System.Drawing">
<value>204, 22</value>
</data>
Expand Down Expand Up @@ -2007,37 +2013,37 @@
<value>Rally Points</value>
</data>
<data name="createWpCircleToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 22</value>
<value>179, 22</value>
</data>
<data name="createWpCircleToolStripMenuItem.Text" xml:space="preserve">
<value>Create Wp Circle</value>
</data>
<data name="createSplineCircleToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 22</value>
<value>179, 22</value>
</data>
<data name="createSplineCircleToolStripMenuItem.Text" xml:space="preserve">
<value>Create Spline Circle</value>
</data>
<data name="areaToolStripMenuItem1.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 22</value>
<value>179, 22</value>
</data>
<data name="areaToolStripMenuItem1.Text" xml:space="preserve">
<value>Area</value>
</data>
<data name="textToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 22</value>
<value>179, 22</value>
</data>
<data name="textToolStripMenuItem.Text" xml:space="preserve">
<value>Text</value>
</data>
<data name="createCircleSurveyToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 22</value>
<value>179, 22</value>
</data>
<data name="createCircleSurveyToolStripMenuItem.Text" xml:space="preserve">
<value>Create Circle Survey</value>
</data>
<data name="surveyGridToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 22</value>
<value>179, 22</value>
</data>
<data name="surveyGridToolStripMenuItem.Text" xml:space="preserve">
<value>Survey (Grid)</value>
Expand Down Expand Up @@ -2336,8 +2342,14 @@
<data name="convertWPToPolygonToolStripMenuItem.Text" xml:space="preserve">
<value>From Current Waypoints</value>
</data>
<data name="offsetPolygonToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>179, 22</value>
</data>
<data name="offsetPolygonToolStripMenuItem.Text" xml:space="preserve">
<value>Offset Polygon</value>
</data>
<data name="contextMenuStripPoly.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 202</value>
<value>180, 224</value>
</data>
<data name="&gt;&gt;contextMenuStripPoly.Name" xml:space="preserve">
<value>contextMenuStripPoly</value>
Expand Down Expand Up @@ -2687,6 +2699,12 @@
<data name="&gt;&gt;fromCurrentWaypointsToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;offsetPolygonToolStripMenuItem2.Name" xml:space="preserve">
<value>offsetPolygonToolStripMenuItem2</value>
</data>
<data name="&gt;&gt;offsetPolygonToolStripMenuItem2.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;areaToolStripMenuItem2.Name" xml:space="preserve">
<value>areaToolStripMenuItem2</value>
</data>
Expand Down Expand Up @@ -3029,6 +3047,12 @@
<data name="&gt;&gt;convertWPToPolygonToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;offsetPolygonToolStripMenuItem.Name" xml:space="preserve">
<value>offsetPolygonToolStripMenuItem</value>
</data>
<data name="&gt;&gt;offsetPolygonToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;drawAPolygonToolStripMenuItem.Name" xml:space="preserve">
<value>drawAPolygonToolStripMenuItem</value>
</data>
Expand Down

0 comments on commit d31428f

Please sign in to comment.