From a25303e43de484449312bba7dc1f8353c7d38982 Mon Sep 17 00:00:00 2001 From: p00qwerty Gamer Date: Sun, 24 Oct 2021 18:51:38 +0200 Subject: [PATCH 01/18] Partial class CBoundary with [CHead & CTurn] Partial class CBoundaryLines with [CHeadLines & CTurnLines] calcList isnt needed anymore --- SourceCode/GPS/Classes/CBoundary.cs | 52 ++-- SourceCode/GPS/Classes/CBoundaryLines.cs | 184 ++++---------- SourceCode/GPS/Classes/CContour.cs | 31 +-- SourceCode/GPS/Classes/CFieldData.cs | 3 +- SourceCode/GPS/Classes/CHead.cs | 75 ++---- SourceCode/GPS/Classes/CHeadLines.cs | 117 ++------- SourceCode/GPS/Classes/CTurn.cs | 190 ++++---------- SourceCode/GPS/Classes/CTurnLines.cs | 106 ++------ SourceCode/GPS/Classes/CYouTurn.cs | 61 +++-- SourceCode/GPS/Forms/Controls.Designer.cs | 24 +- SourceCode/GPS/Forms/FormBoundary.cs | 231 ++++++++---------- SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 27 +- SourceCode/GPS/Forms/FormFieldKML.cs | 25 +- SourceCode/GPS/Forms/FormFlags.cs | 3 - SourceCode/GPS/Forms/FormGPS.cs | 32 +-- SourceCode/GPS/Forms/FormHeadland.cs | 128 ++-------- SourceCode/GPS/Forms/GUI.Designer.cs | 2 +- SourceCode/GPS/Forms/Guidance/FormABDraw.cs | 101 +------- SourceCode/GPS/Forms/OpenGL.Designer.cs | 46 ++-- SourceCode/GPS/Forms/Pickers/FormTouchPick.cs | 107 +------- SourceCode/GPS/Forms/Position.designer.cs | 40 +-- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 137 +++-------- .../Forms/Settings/ConfigModule.Designer.cs | 2 +- 23 files changed, 457 insertions(+), 1267 deletions(-) diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index 279adc692..0a4e18dcf 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -4,7 +4,7 @@ namespace AgOpenGPS { - public class CBoundary + public partial class CBoundary { //copy of the mainform address private readonly FormGPS mf; @@ -14,7 +14,7 @@ public class CBoundary /// /// public List bndArr = new List(); - public List bndBeingMadePts = new List(); + public List bndBeingMadePts = new List(128); private readonly double scanWidth, boxLength; @@ -29,7 +29,11 @@ public CBoundary(FormGPS _f) boundarySelected = 0; scanWidth = 1.0; boxLength = 2000; - //boundaries array + + turnSelected = 0; + + isOn = false; + isToolUp = true; } // the list of possible bounds points @@ -45,6 +49,29 @@ public CBoundary(FormGPS _f) //point at the farthest boundary segment from pivotAxle public vec3 closestBoundaryPt = new vec3(-10000, -10000, 9); + public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) + { + //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders + if (bndArr[0].IsPointInsideBoundaryArea(testPoint)) + { + for (int i = 1; i < bndArr.Count; i++) + { + //make sure not inside a non drivethru boundary + if (bndArr[i].isDriveThru) continue; + if (bndArr[i].IsPointInsideBoundaryArea(testPoint)) + { + return false; + } + } + } + else + { + return false; + } + //we are safely inside outer, outside inner boundaries + return true; + } + public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) { //heading is based on ABLine, average Curve, and going same direction as AB or not @@ -91,7 +118,7 @@ public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) //determine if point is inside bounding box bndClosestList.Clear(); vec4 inBox; - for (int i = 0; i < mf.bnd.bndArr.Count; i++) + for (int i = 0; i < bndArr.Count; i++) { //skip the drive thru if (bndArr[i].isDriveThru) continue; @@ -140,7 +167,7 @@ public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) closestBoundaryPt.easting = bndClosestList[i].easting; closestBoundaryPt.northing = bndClosestList[i].northing; closestBoundaryPt.heading = bndClosestList[i].heading; - mf.bnd.closestBoundaryNum = bndClosestList[i].index; + closestBoundaryNum = bndClosestList[i].index; } } if (closestBoundaryPt.heading < 0) closestBoundaryPt.heading += glm.twoPI; @@ -174,20 +201,20 @@ public void DrawBoundaryLines() GL.Enable(EnableCap.LineStipple); GL.LineStipple(1, 0x0700); GL.Begin(PrimitiveType.LineStrip); - if (mf.bnd.isDrawRightSide) + if (isDrawRightSide) { GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * -mf.bnd.createBndOffset), - pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * -mf.bnd.createBndOffset), 0); + GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * -createBndOffset), + pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * -createBndOffset), 0); GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); } else { GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * mf.bnd.createBndOffset), - pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * mf.bnd.createBndOffset), 0); + GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * createBndOffset), + pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * createBndOffset), 0); GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); } GL.End(); @@ -202,11 +229,6 @@ public void DrawBoundaryLines() } } - public void ResetBoundaries() - { - bndArr.Clear(); - } - //draws the derived closest point public void DrawClosestPoint() { diff --git a/SourceCode/GPS/Classes/CBoundaryLines.cs b/SourceCode/GPS/Classes/CBoundaryLines.cs index 52a75f8fc..38229fc9c 100644 --- a/SourceCode/GPS/Classes/CBoundaryLines.cs +++ b/SourceCode/GPS/Classes/CBoundaryLines.cs @@ -4,54 +4,26 @@ namespace AgOpenGPS { - //public class vec3 - //{ - // public double easting { get; set; } - // public double northing { get; set; } - // public double heading { get; set; } - - // //constructor - // public vec3(double _easting, double _northing, double _heading) - // { - // easting = _easting; - // northing = _northing; - // heading = _heading; - // } - //} - - public class CBoundaryLines + public partial class CBoundaryLines { //list of coordinates of boundary line - public List bndLine = new List(); - - //the list of constants and multiples of the boundary - public List calcList = new List(); - - - // the [point reduced version of boundary - //the list of constants and multiples of the boundary - public List calcListEar = new List(); - - public List bndLineEar = new List(); - + public List bndLine = new List(128); + public List bndLineEar = new List(128); + public List hdLine = new List(128); + public List turnLine = new List(128); //area variable public double area; //boundary variables - public bool isSet, isDriveAround, isDriveThru; + public bool isDriveAround, isDriveThru; //constructor public CBoundaryLines() { area = 0; - isSet = false; isDriveAround = false; isDriveThru = false; - bndLine.Capacity = 128; - calcList.Capacity = 128; - calcListEar.Capacity = 128; - bndLineEar.Capacity = 128; } public void CalculateBoundaryHeadings() @@ -189,132 +161,58 @@ public void ReverseWinding() } } - public void PreCalcBoundaryLines() - { - int j = bndLine.Count - 1; - //clear the list, constant is easting, multiple is northing - calcList.Clear(); - vec2 constantMultiple = new vec2(0, 0); - - for (int i = 0; i < bndLine.Count; j = i++) - { - //check for divide by zero - if (Math.Abs(bndLine[i].northing - bndLine[j].northing) < 0.00000000001) - { - constantMultiple.easting = bndLine[i].easting; - constantMultiple.northing = 0; - calcList.Add(constantMultiple); - } - else - { - //determine constant and multiple and add to list - constantMultiple.easting = bndLine[i].easting - ((bndLine[i].northing * bndLine[j].easting) - / (bndLine[j].northing - bndLine[i].northing)) + ((bndLine[i].northing * bndLine[i].easting) - / (bndLine[j].northing - bndLine[i].northing)); - constantMultiple.northing = (bndLine[j].easting - bndLine[i].easting) / (bndLine[j].northing - bndLine[i].northing); - calcList.Add(constantMultiple); - } - } - } - - public void PreCalcBoundaryEarLines() - { - int j = bndLineEar.Count - 1; - //clear the list, constant is easting, multiple is northing - calcListEar.Clear(); - vec2 constantMultiple = new vec2(0, 0); - - for (int i = 0; i < bndLineEar.Count; j = i++) - { - //check for divide by zero - if (Math.Abs(bndLineEar[i].northing - bndLineEar[j].northing) < 0.00000000001) - { - constantMultiple.easting = bndLineEar[i].easting; - constantMultiple.northing = 0; - calcListEar.Add(constantMultiple); - } - else - { - //determine constant and multiple and add to list - constantMultiple.easting = bndLineEar[i].easting - ((bndLineEar[i].northing * bndLineEar[j].easting) - / (bndLineEar[j].northing - bndLineEar[i].northing)) + ((bndLineEar[i].northing * bndLineEar[i].easting) - / (bndLineEar[j].northing - bndLineEar[i].northing)); - constantMultiple.northing = (bndLineEar[j].easting - bndLineEar[i].easting) / (bndLineEar[j].northing - bndLineEar[i].northing); - calcListEar.Add(constantMultiple); - } - } - } - - public bool IsPointInsideBoundary(vec3 testPointv3) + public bool IsPointInsideBoundaryArea(vec3 testPoint) { - if (calcList.Count < 3) return false; + bool result = false; int j = bndLine.Count - 1; - bool oddNodes = false; - - //test against the constant and multiples list the test point - for (int i = 0; i < bndLine.Count; j = i++) - { - if ((bndLine[i].northing < testPointv3.northing && bndLine[j].northing >= testPointv3.northing) - || (bndLine[j].northing < testPointv3.northing && bndLine[i].northing >= testPointv3.northing)) - { - oddNodes ^= ((testPointv3.northing * calcList[i].northing) + calcList[i].easting < testPointv3.easting); - } - } - return oddNodes; //true means inside. - } - - public bool IsPointInsideBoundary(vec2 testPointv2) - { - if (calcList.Count < 3) return false; - int j = bndLine.Count - 1; - bool oddNodes = false; - - //test against the constant and multiples list the test point - for (int i = 0; i < bndLine.Count; j = i++) + for (int i = 0; i < bndLine.Count; i++) { - if ((bndLine[i].northing < testPointv2.northing && bndLine[j].northing >= testPointv2.northing) - || (bndLine[j].northing < testPointv2.northing && bndLine[i].northing >= testPointv2.northing)) + if ((bndLine[i].easting < testPoint.easting && bndLine[j].easting >= testPoint.easting) || (bndLine[j].easting < testPoint.easting && bndLine[i].easting >= testPoint.easting)) { - oddNodes ^= ((testPointv2.northing * calcList[i].northing) + calcList[i].easting < testPointv2.easting); + if (bndLine[i].northing + (testPoint.easting - bndLine[i].easting) / (bndLine[j].easting - bndLine[i].easting) * (bndLine[j].northing - bndLine[i].northing) < testPoint.northing) + { + result = !result; + } } + j = i; } - return oddNodes; //true means inside. + return result; } - public bool IsPointInsideBoundaryEar(vec3 testPointv3) + public bool IsPointInsideBoundaryEar(vec3 testPoint) { - if (calcListEar.Count < 3) return false; + bool result = false; int j = bndLineEar.Count - 1; - bool oddNodes = false; - - //test against the constant and multiples list the test point - for (int i = 0; i < bndLineEar.Count; j = i++) + for (int i = 0; i < bndLineEar.Count; i++) { - if ((bndLineEar[i].northing < testPointv3.northing && bndLineEar[j].northing >= testPointv3.northing) - || (bndLineEar[j].northing < testPointv3.northing && bndLineEar[i].northing >= testPointv3.northing)) + if ((bndLineEar[i].easting < testPoint.easting && bndLineEar[j].easting >= testPoint.easting) || (bndLineEar[j].easting < testPoint.easting && bndLineEar[i].easting >= testPoint.easting)) { - oddNodes ^= ((testPointv3.northing * calcListEar[i].northing) + calcListEar[i].easting < testPointv3.easting); + if (bndLineEar[i].northing + (testPoint.easting - bndLineEar[i].easting) / (bndLineEar[j].easting - bndLineEar[i].easting) * (bndLineEar[j].northing - bndLineEar[i].northing) < testPoint.northing) + { + result = !result; + } } + j = i; } - return oddNodes; //true means inside. + return result; } - - public bool IsPointInsideBoundaryEar(vec2 testPointv2) + + public bool IsPointInsideBoundaryEar(vec2 testPoint) { - if (calcListEar.Count < 3) return false; + bool result = false; int j = bndLineEar.Count - 1; - bool oddNodes = false; - - //test against the constant and multiples list the test point - for (int i = 0; i < bndLineEar.Count; j = i++) + for (int i = 0; i < bndLineEar.Count; i++) { - if ((bndLineEar[i].northing < testPointv2.northing && bndLineEar[j].northing >= testPointv2.northing) - || (bndLineEar[j].northing < testPointv2.northing && bndLineEar[i].northing >= testPointv2.northing)) + if ((bndLineEar[i].easting < testPoint.easting && bndLineEar[j].easting >= testPoint.easting) || (bndLineEar[j].easting < testPoint.easting && bndLineEar[i].easting >= testPoint.easting)) { - oddNodes ^= ((testPointv2.northing * calcListEar[i].northing) + calcListEar[i].easting < testPointv2.easting); + if (bndLineEar[i].northing + (testPoint.easting - bndLineEar[i].easting) / (bndLineEar[j].easting - bndLineEar[i].easting) * (bndLineEar[j].northing - bndLineEar[i].northing) < testPoint.northing) + { + result = !result; + } } + j = i; } - return oddNodes; //true means inside. + return result; } public void DrawBoundaryLine(int lw, bool outOfBounds) @@ -353,7 +251,7 @@ public void DrawBoundaryLine(int lw, bool outOfBounds) } //obvious - public bool CalculateBoundaryArea() + public bool CalculateBoundaryArea(int idx) { int ptCount = bndLine.Count; if (ptCount < 1) return false; @@ -370,6 +268,12 @@ public bool CalculateBoundaryArea() area = Math.Abs(area / 2); + //make sure is clockwise for outer counter clockwise for inner + if ((idx == 0 && isClockwise) || (idx > 0 && !isClockwise)) + { + ReverseWinding(); + } + return isClockwise; } } diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index 9856dc251..f14c244c6 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -948,36 +948,14 @@ public void BuildBoundaryContours(int pass, int spacingInt) ((mf.tool.toolWidth - mf.tool.toolOverlap) * 0.5); } - - //outside boundary - - //count the points from the boundary - int ptCount = mf.bnd.bndArr[0].bndLine.Count; - - ptList = new List(); - ptList.Capacity = 128; - stripList.Add(ptList); - - for (int i = ptCount - 1; i >= 0; i--) - { - //calculate the point inside the boundary - point.easting = mf.bnd.bndArr[0].bndLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * totalHeadWidth); - point.northing = mf.bnd.bndArr[0].bndLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * totalHeadWidth); - point.heading = mf.bnd.bndArr[0].bndLine[i].heading - Math.PI; - if (point.heading < -glm.twoPI) point.heading += glm.twoPI; - ptList.Add(point); - } - //totalHeadWidth = (mf.tool.toolWidth - mf.tool.toolOverlap) * 0.5 + 0.2 + (mf.tool.toolWidth - mf.tool.toolOverlap); - for (int j = 1; j < mf.bnd.bndArr.Count; j++) + for (int j = 0; j < mf.bnd.bndArr.Count; j++) { - if (!mf.bnd.bndArr[j].isSet) continue; - //count the points from the boundary - ptCount = mf.bnd.bndArr[j].bndLine.Count; + int ptCount = mf.bnd.bndArr[j].bndLine.Count; - ptList = new List(); + ptList = new List(128); stripList.Add(ptList); for (int i = ptCount - 1; i >= 0; i--) @@ -991,9 +969,6 @@ public void BuildBoundaryContours(int pass, int spacingInt) //only add if inside actual field boundary ptList.Add(point); } - - //add the point list to the save list for appending to contour file - //mf.contourSaveList.Add(ptList); } mf.TimedMessageBox(1500, "Boundary Contour", "Contour Path Created"); diff --git a/SourceCode/GPS/Classes/CFieldData.cs b/SourceCode/GPS/Classes/CFieldData.cs index a2137fa62..aed0102cb 100644 --- a/SourceCode/GPS/Classes/CFieldData.cs +++ b/SourceCode/GPS/Classes/CFieldData.cs @@ -132,7 +132,6 @@ public CFieldData(FormGPS _f) public void UpdateFieldBoundaryGUIAreas() { - if (mf.bnd.bndArr.Count > 0) { areaOuterBoundary = mf.bnd.bndArr[0].area; @@ -140,7 +139,7 @@ public void UpdateFieldBoundaryGUIAreas() for (int i = 1; i < mf.bnd.bndArr.Count; i++) { - if (mf.bnd.bndArr[i].isSet) areaBoundaryOuterLessInner -= mf.bnd.bndArr[i].area; + areaBoundaryOuterLessInner -= mf.bnd.bndArr[i].area; } } else diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index 41cca6cff..4e7febefb 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -1,14 +1,9 @@ using System; -using System.Collections.Generic; namespace AgOpenGPS { - public class CHead + public partial class CBoundary { - //copy of the mainform address - private readonly FormGPS mf; - - public double singleSpaceHeadlandDistance; public bool isOn; public double leftToolDistance; public double rightToolDistance; @@ -23,21 +18,6 @@ public class CHead public bool isLookRightIn = false; public bool isLookLeftIn = false; - /// - /// array of turns - /// - public List headArr = new List(); - - //constructor - public CHead(FormGPS _f) - { - mf = _f; - singleSpaceHeadlandDistance = 18; - isOn = false; - headArr.Add(new CHeadLines()); - isToolUp = true; - } - public void SetHydPosition() { if (mf.vehicle.isHydLiftOn && mf.pn.speed > 0.2 && mf.autoBtnState == FormGPS.btnStates.Auto) @@ -57,23 +37,19 @@ public void SetHydPosition() public void WhereAreToolCorners() { - if (headArr[0].hdLine.Count == 0) - { - return; - } - else + if (bndArr.Count > 0 && bndArr[0].hdLine.Count > 0) { bool isLeftInWk, isRightInWk = true; - if (mf.hd.isOn) + if (isOn) { for (int j = 0; j < mf.tool.numOfSections; j++) { if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftInWk = mf.hd.headArr[0].IsPointInHeadArea(mf.section[j].leftPoint); - isRightInWk = mf.hd.headArr[0].IsPointInHeadArea(mf.section[j].rightPoint); + isLeftInWk = bndArr[0].IsPointInHeadArea(mf.section[j].leftPoint); + isRightInWk = bndArr[0].IsPointInHeadArea(mf.section[j].rightPoint); //save left side mf.tool.isLeftSideInHeadland = !isLeftInWk; @@ -86,7 +62,7 @@ public void WhereAreToolCorners() { //grab the right of previous section, its the left of this section isLeftInWk = isRightInWk; - isRightInWk = mf.hd.headArr[0].IsPointInHeadArea(mf.section[j].rightPoint); + isRightInWk = bndArr[0].IsPointInHeadArea(mf.section[j].rightPoint); mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } @@ -108,11 +84,7 @@ public void WhereAreToolCorners() public void WhereAreToolLookOnPoints() { - if (headArr[0].hdLine.Count == 0) - { - return; - } - else + if (bndArr.Count > 0 && bndArr[0].hdLine.Count > 0) { vec3 toolFix = mf.toolPos; double sinAB = Math.Sin(toolFix.heading); @@ -154,19 +126,11 @@ public void WhereAreToolLookOnPoints() } } - - public void DrawHeadLinesBack() - { - { - if (headArr[0].hdLine.Count > 0 && isOn) headArr[0].DrawHeadLineBackBuffer(); - } - } - public void DrawHeadLines() { - //for (int i = 0; i < mf.bnd.bndArr.Count; i++) + for (int i = 0; i < bndArr.Count; i++) { - if (headArr[0].hdLine.Count > 0 && isOn) headArr[0].DrawHeadLine(mf.ABLine.lineWidth); + if (bndArr[i].hdLine.Count > 0) bndArr[i].DrawHeadLine(); } //GL.LineWidth(4.0f); @@ -191,19 +155,16 @@ public void DrawHeadLines() public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add - if (headArr.Count > 0 && headArr[0].IsPointInHeadArea(pt)) + if (bndArr.Count > 0 && bndArr[0].IsPointInHeadArea(pt)) { - //for (int b = 1; b < mf.bnd.bndArr.Count; b++) - //{ - // if (mf.bnd.bndArr[b].isSet) - // { - // if (headArr[b].IsPointInHeadArea(pt)) - // { - // //point is in an inner turn area but inside outer - // return false; - // } - // } - //} + for (int b = 1; b < bndArr.Count; b++) + { + if (bndArr[b].IsPointInHeadArea(pt)) + { + //point is in an inner turn area but inside outer + return false; + } + } return true; } else diff --git a/SourceCode/GPS/Classes/CHeadLines.cs b/SourceCode/GPS/Classes/CHeadLines.cs index ad449ac00..c933932a9 100644 --- a/SourceCode/GPS/Classes/CHeadLines.cs +++ b/SourceCode/GPS/Classes/CHeadLines.cs @@ -1,83 +1,51 @@ using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; namespace AgOpenGPS { - public class CHeadLines + public partial class CBoundaryLines { - //list of coordinates of boundary line - public List hdLine = new List(); - - //the list of constants and multiples of the boundary - public List calcList = new List(); - - public void ResetHead() - { - calcList?.Clear(); - hdLine?.Clear(); - hdLine.Capacity = 128; - calcList.Capacity = 128; - } - - public bool IsPointInHeadArea(vec3 testPointv2) + public bool IsPointInHeadArea(vec2 testPoint) { - if (calcList.Count < 3) return false; + bool result = false; int j = hdLine.Count - 1; - bool oddNodes = false; - - //test against the constant and multiples list the test point - for (int i = 0; i < hdLine.Count; j = i++) + for (int i = 0; i < hdLine.Count; i++) { - if ((hdLine[i].northing < testPointv2.northing && hdLine[j].northing >= testPointv2.northing) - || (hdLine[j].northing < testPointv2.northing && hdLine[i].northing >= testPointv2.northing)) + if ((hdLine[i].easting < testPoint.easting && hdLine[j].easting >= testPoint.easting) || (hdLine[j].easting < testPoint.easting && hdLine[i].easting >= testPoint.easting)) { - oddNodes ^= ((testPointv2.northing * calcList[i].northing) + calcList[i].easting < testPointv2.easting); + if (hdLine[i].northing + (testPoint.easting - hdLine[i].easting) / (hdLine[j].easting - hdLine[i].easting) * (hdLine[j].northing - hdLine[i].northing) < testPoint.northing) + { + result = !result; + } } + j = i; } - return oddNodes; //true means inside. + return result; } - public bool IsPointInHeadArea(vec2 testPointv2) + public bool IsPointInHeadArea(vec3 testPoint) { - if (calcList.Count < 3) return false; + bool result = false; int j = hdLine.Count - 1; - bool oddNodes = false; - - //test against the constant and multiples list the test point - for (int i = 0; i < hdLine.Count; j = i++) + for (int i = 0; i < hdLine.Count; i++) { - if ((hdLine[i].northing < testPointv2.northing && hdLine[j].northing >= testPointv2.northing) - || (hdLine[j].northing < testPointv2.northing && hdLine[i].northing >= testPointv2.northing)) + if ((hdLine[i].easting < testPoint.easting && hdLine[j].easting >= testPoint.easting) || (hdLine[j].easting < testPoint.easting && hdLine[i].easting >= testPoint.easting)) { - oddNodes ^= ((testPointv2.northing * calcList[i].northing) + calcList[i].easting < testPointv2.easting); + if (hdLine[i].northing + (testPoint.easting - hdLine[i].easting) / (hdLine[j].easting - hdLine[i].easting) * (hdLine[j].northing - hdLine[i].northing) < testPoint.northing) + { + result = !result; + } } + j = i; } - return oddNodes; //true means inside. + return result; } - public void DrawHeadLine(int linewidth) + public void DrawHeadLine() { - ////draw the turn line oject - //if (hdLine.Count < 1) return; - //int ptCount = hdLine.Count; - //GL.LineWidth(linewidth); - //GL.Color3(0.732f, 0.7932f, 0.30f); - //GL.Begin(PrimitiveType.LineStrip); - //for (int h = 0; h < ptCount; h++) GL.Vertex3(hdLine[h].easting, hdLine[h].northing, 0); - //GL.Vertex3(hdLine[0].easting, hdLine[0].northing, 0); - //GL.End(); - - if (hdLine.Count < 2) return; - int ptCount = hdLine.Count; - if (ptCount > 1) + if (hdLine.Count > 1) { - GL.LineWidth(linewidth); - GL.Color3(0.960f, 0.96232f, 0.30f); - //GL.PointSize(2); - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < ptCount; i++) + for (int i = 0; i < hdLine.Count; i++) { GL.Vertex3(hdLine[i].easting, hdLine[i].northing, 0); } @@ -87,48 +55,15 @@ public void DrawHeadLine(int linewidth) public void DrawHeadLineBackBuffer() { - if (hdLine.Count < 2) return; - int ptCount = hdLine.Count; - if (ptCount > 1) + if (hdLine.Count > 1) { - GL.LineWidth(3); - GL.Color3((byte)0, (byte)250, (byte)0); - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < ptCount; i++) + for (int i = 0; i < hdLine.Count; i++) { GL.Vertex3(hdLine[i].easting, hdLine[i].northing, 0); } GL.End(); } } - - public void PreCalcHeadLines() - { - int j = hdLine.Count - 1; - //clear the list, constant is easting, multiple is northing - calcList.Clear(); - vec2 constantMultiple = new vec2(0, 0); - - for (int i = 0; i < hdLine.Count; j = i++) - { - //check for divide by zero - if (Math.Abs(hdLine[i].northing - hdLine[j].northing) < double.Epsilon) - { - constantMultiple.easting = hdLine[i].easting; - constantMultiple.northing = 0; - calcList.Add(constantMultiple); - } - else - { - //determine constant and multiple and add to list - constantMultiple.easting = hdLine[i].easting - ((hdLine[i].northing * hdLine[j].easting) - / (hdLine[j].northing - hdLine[i].northing)) + ((hdLine[i].northing * hdLine[i].easting) - / (hdLine[j].northing - hdLine[i].northing)); - constantMultiple.northing = (hdLine[j].easting - hdLine[i].easting) / (hdLine[j].northing - hdLine[i].northing); - calcList.Add(constantMultiple); - } - } - } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index 7f2f90f41..d6fdec0d7 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -4,41 +4,16 @@ namespace AgOpenGPS { - public class CTurn + public partial class CBoundary { - //copy of the mainform address - private readonly FormGPS mf; - - private readonly double boxLength; - - /// - /// array of turns - /// - public List turnArr = new List(); - - //constructor - public CTurn(FormGPS _f) - { - mf = _f; - turnSelected = 0; - //scanWidth = 1.5; - boxLength = 2000; - } - // the list of possible bounds points public List turnClosestList = new List(); public int turnSelected, closestTurnNum; - //generated box for finding closest point - public vec2 boxA = new vec2(9000, 9000), boxB = new vec2(9000, 9002); - - public vec2 boxC = new vec2(9001, 9001), boxD = new vec2(9002, 9003); - //point at the farthest turn segment from pivotAxle public vec3 closestTurnPt = new vec3(-10000, -10000, 9); - public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB) { //initial scan is straight ahead of pivot point of vehicle to find the right turnLine/boundary @@ -56,14 +31,13 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (turnArr[0].IsPointInTurnWorkArea(pt)) + if (bndArr[0].IsPointInTurnWorkArea(pt)) { - for (int t = 1; t < mf.bnd.bndArr.Count; t++) + for (int t = 1; t < bndArr.Count; t++) { - if (!mf.bnd.bndArr[t].isSet) continue; - if (mf.bnd.bndArr[t].isDriveThru) continue; - if (mf.bnd.bndArr[t].isDriveAround) continue; - if (mf.turn.turnArr[t].IsPointInTurnWorkArea(pt)) + if (bndArr[t].isDriveThru) continue; + if (bndArr[t].isDriveAround) continue; + if (bndArr[t].IsPointInTurnWorkArea(pt)) { isFound = true; closestTurnNum = t; @@ -112,28 +86,27 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB //determine if point is inside bounding box of the 1 turn chosen above turnClosestList.Clear(); - mf.turn.closestTurnNum = closestTurnNum; vec4 inBox; - int ptCount = turnArr[closestTurnNum].turnLine.Count; + int ptCount = bndArr[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (turnArr[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (turnArr[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (turnArr[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (turnArr[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (turnArr[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (turnArr[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (turnArr[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (turnArr[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = turnArr[closestTurnNum].turnLine[p].easting; - inBox.northing = turnArr[closestTurnNum].turnLine[p].northing; - inBox.heading = turnArr[closestTurnNum].turnLine[p].heading; + inBox.easting = bndArr[closestTurnNum].turnLine[p].easting; + inBox.northing = bndArr[closestTurnNum].turnLine[p].northing; + inBox.heading = bndArr[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -169,27 +142,26 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB //determine if point is inside bounding box of the 1 turn chosen above turnClosestList.Clear(); - mf.turn.closestTurnNum = closestTurnNum; + ptCount = bndArr[closestTurnNum].turnLine.Count; - ptCount = turnArr[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (turnArr[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (turnArr[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (turnArr[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (turnArr[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (turnArr[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (turnArr[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (turnArr[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (turnArr[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = turnArr[closestTurnNum].turnLine[p].easting; - inBox.northing = turnArr[closestTurnNum].turnLine[p].northing; - inBox.heading = turnArr[closestTurnNum].turnLine[p].heading; + inBox.easting = bndArr[closestTurnNum].turnLine[p].easting; + inBox.northing = bndArr[closestTurnNum].turnLine[p].northing; + inBox.heading = bndArr[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -226,41 +198,12 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB } } - //public bool PointInsideWorkArea(vec2 pt) - //{ - // //if inside outer boundary, then potentially add - // if (turnArr[0].IsPointInTurnWorkArea(pt)) - // { - // for (int b = 1; b < mf.bnd.bndArr.Count; b++) - // { - // if (mf.bnd.bndArr[b].isSet) - // { - // if (turnArr[b].IsPointInTurnWorkArea(pt)) - // { - // //point is in an inner turn area but inside outer - // return false; - // } - // } - // } - // return true; - // } - // else - // { - // return false; - // } - //} - - public void ResetTurnLines() - { - turnArr.Clear(); - } - public void BuildTurnLines() { //update the GUI values for boundaries mf.fd.UpdateFieldBoundaryGUIAreas(); - if (mf.bnd.bndArr.Count == 0) + if (bndArr.Count == 0) { //mf.TimedMessageBox(1500, " No Boundaries", "No Turn Lines Made"); return; @@ -272,55 +215,31 @@ public void BuildTurnLines() //determine how wide a headland space double totalHeadWidth = mf.yt.uturnDistanceFromBoundary; - //outside boundary - count the points from the boundary - turnArr[0].turnLine.Clear(); - int ptCount = mf.bnd.bndArr[0].bndLine.Count; - for (int i = ptCount - 1; i >= 0; i--) - { - //calculate the point inside the boundary - point.easting = mf.bnd.bndArr[0].bndLine[i].easting + (-Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * totalHeadWidth); - point.northing = mf.bnd.bndArr[0].bndLine[i].northing + (-Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * totalHeadWidth); - point.heading = mf.bnd.bndArr[0].bndLine[i].heading; - if (point.heading < -glm.twoPI) point.heading += glm.twoPI; - - //only add if inside actual field boundary - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) - { - vec3 tPnt = new vec3(point.easting, point.northing, point.heading); - turnArr[0].turnLine.Add(tPnt); - } - } - turnArr[0].FixTurnLine(totalHeadWidth, mf.bnd.bndArr[0].bndLine, mf.tool.toolWidth * 0.33); - turnArr[0].PreCalcTurnLines(); - //inside boundaries - for (int j = 1; j < mf.bnd.bndArr.Count; j++) + for (int j = 0; j < bndArr.Count; j++) { - turnArr[j].turnLine.Clear(); - if (!mf.bnd.bndArr[j].isSet || mf.bnd.bndArr[j].isDriveThru || mf.bnd.bndArr[j].isDriveAround) continue; + bndArr[j].turnLine.Clear(); + if (bndArr[j].isDriveThru || bndArr[j].isDriveAround) continue; - ptCount = mf.bnd.bndArr[j].bndLine.Count; + int ptCount = bndArr[j].bndLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point outside the boundary - point.easting = mf.bnd.bndArr[j].bndLine[i].easting + (-Math.Sin(glm.PIBy2 + mf.bnd.bndArr[j].bndLine[i].heading) * totalHeadWidth); - point.northing = mf.bnd.bndArr[j].bndLine[i].northing + (-Math.Cos(glm.PIBy2 + mf.bnd.bndArr[j].bndLine[i].heading) * totalHeadWidth); - point.heading = mf.bnd.bndArr[j].bndLine[i].heading; + point.easting = bndArr[j].bndLine[i].easting + (-Math.Sin(glm.PIBy2 + bndArr[j].bndLine[i].heading) * totalHeadWidth); + point.northing = bndArr[j].bndLine[i].northing + (-Math.Cos(glm.PIBy2 + bndArr[j].bndLine[i].heading) * totalHeadWidth); + point.heading = bndArr[j].bndLine[i].heading; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (!mf.bnd.bndArr[j].IsPointInsideBoundaryEar(point)) + if (j == 0 == bndArr[j].IsPointInsideBoundaryEar(point)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); - turnArr[j].turnLine.Add(tPnt); + bndArr[j].turnLine.Add(tPnt); } } - turnArr[j].FixTurnLine(totalHeadWidth, mf.bnd.bndArr[j].bndLine, mf.tool.toolWidth * 0.33); - turnArr[j].PreCalcTurnLines(); + bndArr[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); } - - //mf.TimedMessageBox(800, "Turn Lines", "Turn limits Created"); } public void DrawTurnLines() @@ -329,39 +248,20 @@ public void DrawTurnLines() GL.Color3(0.3555f, 0.6232f, 0.20f); //GL.PointSize(2); - for (int i = 0; i < mf.bnd.bndArr.Count; i++) + for (int i = 0; i < bndArr.Count; i++) { - if (!mf.bnd.bndArr[i].isSet && mf.bnd.bndArr[i].isDriveAround) continue; + if (bndArr[i].isDriveAround) continue; //turnArr[i].DrawTurnLine(); { ////draw the turn line oject - int ptCount = mf.turn.turnArr[i].turnLine.Count; + int ptCount = bndArr[i].turnLine.Count; if (ptCount < 1) continue; GL.Begin(PrimitiveType.LineLoop); - for (int h = 0; h < ptCount; h++) GL.Vertex3(mf.turn.turnArr[i].turnLine[h].easting, mf.turn.turnArr[i].turnLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(bndArr[i].turnLine[h].easting, bndArr[i].turnLine[h].northing, 0); GL.End(); } } } - - //draws the derived closest point - public void DrawClosestPoint() - { - //GL.PointSize(6.0f); - //GL.Color3(0.219f, 0.932f, 0.070f); - //GL.Begin(PrimitiveType.Points); - //GL.Vertex3(closestTurnPt.easting, closestTurnPt.northing, 0); - //GL.End(); - - //GL.LineWidth(1); - //GL.Color3(0.92f, 0.62f, 0.42f); - //GL.Begin(PrimitiveType.LineStrip); - //GL.Vertex3(boxD.easting, boxD.northing, 0); - //GL.Vertex3(boxA.easting, boxA.northing, 0); - //GL.Vertex3(boxB.easting, boxB.northing, 0); - //GL.Vertex3(boxC.easting, boxC.northing, 0); - //GL.End(); - } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CTurnLines.cs b/SourceCode/GPS/Classes/CTurnLines.cs index 97684fc97..8b37faa76 100644 --- a/SourceCode/GPS/Classes/CTurnLines.cs +++ b/SourceCode/GPS/Classes/CTurnLines.cs @@ -1,32 +1,10 @@ using OpenTK.Graphics.OpenGL; using System; -using System.Collections.Generic; namespace AgOpenGPS { - //public class CTurnPt - //{ - // public double easting { get; set; } - // public double northing { get; set; } - // public double heading { get; set; } - - // //constructor - // public CTurnPt(double _easting, double _northing, double _heading) - // { - // easting = _easting; - // northing = _northing; - // heading = _heading; - // } - //} - - public class CTurnLines + public partial class CBoundaryLines { - //list of coordinates of boundary line - public List turnLine = new List(); - - //the list of constants and multiples of the boundary - public List calcList = new List(); - public void CalculateTurnHeadings() { //to calc heading based on next and previous points to give an average heading. @@ -58,13 +36,7 @@ public void CalculateTurnHeadings() turnLine.Add(pt3); } - public void ResetTurn() - { - calcList?.Clear(); - turnLine?.Clear(); - } - - public void FixTurnLine(double totalHeadWidth, List curBnd, double spacing) + public void FixTurnLine(double totalHeadWidth, double spacing) { //count the points from the boundary int lineCount = turnLine.Count; @@ -74,15 +46,14 @@ public void FixTurnLine(double totalHeadWidth, List curBnd, double spacing //int headCount = mf.bndArr[inTurnNum].bndLine.Count; double distance; - int bndCount = curBnd.Count; //remove the points too close to boundary - for (int i = 0; i < bndCount; i++) + for (int i = 0; i < bndLine.Count; i++) { for (int j = 0; j < lineCount; j++) { //make sure distance between headland and boundary is not less then width - distance = glm.DistanceSquared(curBnd[i], turnLine[j]); + distance = glm.DistanceSquared(bndLine[i], turnLine[j]); if (distance < (totalHeadWidth * 0.99)) { turnLine.RemoveAt(j); @@ -94,7 +65,7 @@ public void FixTurnLine(double totalHeadWidth, List curBnd, double spacing //make sure distance isn't too big between points on Turn - bndCount = turnLine.Count; + int bndCount = turnLine.Count; for (int i = 0; i < bndCount; i++) { int j = i + 1; @@ -154,70 +125,23 @@ public void FixTurnLine(double totalHeadWidth, List curBnd, double spacing //} } - public void PreCalcTurnLines() + public bool IsPointInTurnWorkArea(vec3 testPoint) { + bool result = false; int j = turnLine.Count - 1; - //clear the list, constant is easting, multiple is northing - calcList.Clear(); - vec2 constantMultiple = new vec2(0, 0); - - for (int i = 0; i < turnLine.Count; j = i++) + for (int i = 0; i < turnLine.Count; i++) { - //check for divide by zero - if (Math.Abs(turnLine[i].northing - turnLine[j].northing) < 0.00000000001) + if ((turnLine[i].easting < testPoint.easting && turnLine[j].easting >= testPoint.easting) || (turnLine[j].easting < testPoint.easting && turnLine[i].easting >= testPoint.easting)) { - constantMultiple.easting = turnLine[i].easting; - constantMultiple.northing = 0; - calcList.Add(constantMultiple); - } - else - { - //determine constant and multiple and add to list - constantMultiple.easting = turnLine[i].easting - ((turnLine[i].northing * turnLine[j].easting) - / (turnLine[j].northing - turnLine[i].northing)) + ((turnLine[i].northing * turnLine[i].easting) - / (turnLine[j].northing - turnLine[i].northing)); - constantMultiple.northing = (turnLine[j].easting - turnLine[i].easting) / (turnLine[j].northing - turnLine[i].northing); - calcList.Add(constantMultiple); - } - } - } - - public bool IsPointInTurnWorkArea(vec3 testPointv3) - { - if (calcList.Count < 3) return false; - int j = turnLine.Count - 1; - bool oddNodes = false; - - //test against the constant and multiples list the test point - for (int i = 0; i < turnLine.Count; j = i++) - { - if ((turnLine[i].northing < testPointv3.northing && turnLine[j].northing >= testPointv3.northing) - || (turnLine[j].northing < testPointv3.northing && turnLine[i].northing >= testPointv3.northing)) - { - oddNodes ^= ((testPointv3.northing * calcList[i].northing) + calcList[i].easting < testPointv3.easting); - } - } - return oddNodes; //true means inside. - } - - public bool IsPointInTurnWorkArea(vec2 testPointv2) - { - if (calcList.Count < 3) return false; - int j = turnLine.Count - 1; - bool oddNodes = false; - - //test against the constant and multiples list the test point - for (int i = 0; i < turnLine.Count; j = i++) - { - if ((turnLine[i].northing < testPointv2.northing && turnLine[j].northing >= testPointv2.northing) - || (turnLine[j].northing < testPointv2.northing && turnLine[i].northing >= testPointv2.northing)) - { - oddNodes ^= ((testPointv2.northing * calcList[i].northing) + calcList[i].easting < testPointv2.easting); + if (turnLine[i].northing + (testPoint.easting - turnLine[i].easting) / (turnLine[j].easting - turnLine[i].easting) * (turnLine[j].northing - turnLine[i].northing) < testPoint.northing) + { + result = !result; + } } + j = i; } - return oddNodes; //true means inside. + return result; } - public void DrawTurnLine() { ////draw the turn line oject diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index 576be2ac8..b6a82524e 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -115,7 +115,7 @@ public bool FindCurveTurnPoints() //for each point in succession keep going till a turnLine is found. for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) { - if (!mf.turn.turnArr[0].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(mf.curve.curList[j])) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -128,10 +128,9 @@ public bool FindCurveTurnPoints() for (int i = 1; i < mf.bnd.bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (!mf.bnd.bndArr[i].isSet) continue; if (mf.bnd.bndArr[i].isDriveThru) continue; if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.turn.turnArr[i].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(mf.curve.curList[j])) { crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -143,8 +142,8 @@ public bool FindCurveTurnPoints() } } - //escape for multiple for's - CrossingFound:; + //escape for multiple for's + CrossingFound:; } else //counting down, going opposite way mf.curve was created. @@ -153,7 +152,7 @@ public bool FindCurveTurnPoints() for (int j = mf.curve.currentLocationIndex; j > 0; j--) { - if (!mf.turn.turnArr[0].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(mf.curve.curList[j])) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; @@ -166,10 +165,9 @@ public bool FindCurveTurnPoints() for (int i = 1; i < mf.bnd.bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (!mf.bnd.bndArr[i].isSet) continue; if (mf.bnd.bndArr[i].isDriveThru) continue; if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.turn.turnArr[i].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(mf.curve.curList[j])) { crossingCurvePoint.easting = mf.curve.curList[j].easting; crossingCurvePoint.northing = mf.curve.curList[j].northing; @@ -181,8 +179,8 @@ public bool FindCurveTurnPoints() } } - //escape for multiple for's, point and turnLine index are found - CrossingFound:; + //escape for multiple for's, point and turnLine index are found + CrossingFound:; } int turnNum = crossingTurnLinePoint.index; @@ -193,17 +191,17 @@ public bool FindCurveTurnPoints() return false; } - int curTurnLineCount = mf.turn.turnArr[turnNum].turnLine.Count; + int curTurnLineCount = mf.bnd.bndArr[turnNum].turnLine.Count; //possible points close to AB Curve point List turnLineCloseList = new List(); for (int j = 0; j < curTurnLineCount; j++) { - if ((mf.turn.turnArr[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 - && (mf.turn.turnArr[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 - && (mf.turn.turnArr[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 - && (mf.turn.turnArr[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) + if ((mf.bnd.bndArr[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 + && (mf.bnd.bndArr[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 + && (mf.bnd.bndArr[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 + && (mf.bnd.bndArr[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) { turnLineCloseList.Add(j); } @@ -213,8 +211,8 @@ public bool FindCurveTurnPoints() curTurnLineCount = turnLineCloseList.Count; for (int i = 0; i < curTurnLineCount; i++) { - dist1 = glm.Distance(mf.turn.turnArr[turnNum].turnLine[turnLineCloseList[i]].easting, - mf.turn.turnArr[turnNum].turnLine[turnLineCloseList[i]].northing, + dist1 = glm.Distance(mf.bnd.bndArr[turnNum].turnLine[turnLineCloseList[i]].easting, + mf.bnd.bndArr[turnNum].turnLine[turnLineCloseList[i]].northing, crossingCurvePoint.easting, crossingCurvePoint.northing); if (dist1 < dist2) { @@ -224,9 +222,9 @@ public bool FindCurveTurnPoints() } //fill up the coords - crossingTurnLinePoint.easting = mf.turn.turnArr[turnNum].turnLine[crossingTurnLinePoint.index].easting; - crossingTurnLinePoint.northing = mf.turn.turnArr[turnNum].turnLine[crossingTurnLinePoint.index].northing; - crossingTurnLinePoint.heading = mf.turn.turnArr[turnNum].turnLine[crossingTurnLinePoint.index].heading; + crossingTurnLinePoint.easting = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].easting; + crossingTurnLinePoint.northing = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].northing; + crossingTurnLinePoint.heading = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].heading; return crossingCurvePoint.easting != -20000 && crossingCurvePoint.easting != -20000; } @@ -389,12 +387,12 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) vec3 onPurePoint = new vec3(mf.ABLine.rEastAB, mf.ABLine.rNorthAB, 0); //how far are we from any turn boundary - mf.turn.FindClosestTurnPoint(isYouTurnRight, onPurePoint, headAB); + mf.bnd.FindClosestTurnPoint(isYouTurnRight, onPurePoint, headAB); //or did we lose the turnLine - we are on the highway cuz we left the outer/inner turn boundary - if ((int)mf.turn.closestTurnPt.easting != -20000) + if ((int)mf.bnd.closestTurnPt.easting != -20000) { - mf.distancePivotToTurnLine = glm.Distance(mf.pivotAxlePos, mf.turn.closestTurnPt); + mf.distancePivotToTurnLine = glm.Distance(mf.pivotAxlePos, mf.bnd.closestTurnPt); } else { @@ -403,7 +401,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) } //delta between AB heading and boundary closest point heading - boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(mf.turn.closestTurnPt.heading - headAB) - Math.PI); + boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(mf.bnd.closestTurnPt.heading - headAB) - Math.PI); boundaryAngleOffPerpendicular -= glm.PIBy2; boundaryAngleOffPerpendicular *= -1; if (boundaryAngleOffPerpendicular > 1.25) boundaryAngleOffPerpendicular = 1.25; @@ -586,16 +584,15 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.turn.turnArr[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; + if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; if (isOutOfBounds) break; for (int i = 1; i < mf.bnd.bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (!mf.bnd.bndArr[i].isSet) continue; if (mf.bnd.bndArr[i].isDriveThru) continue; if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.turn.turnArr[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; @@ -647,17 +644,16 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.turn.turnArr[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; + if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; if (isOutOfBounds) break; for (int i = 1; i < mf.bnd.bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (!mf.bnd.bndArr[i].isSet) continue; if (mf.bnd.bndArr[i].isDriveThru) continue; if (mf.bnd.bndArr[i].isDriveAround) continue; - if (!mf.turn.turnArr[i].IsPointInTurnWorkArea(ytList[j])) + if (!mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; @@ -856,7 +852,7 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!mf.turn.turnArr[0].IsPointInTurnWorkArea(ytList[j])) + if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; @@ -865,10 +861,9 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) for (int i = 1; i < mf.bnd.bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (!mf.bnd.bndArr[i].isSet) continue; if (mf.bnd.bndArr[i].isDriveThru) continue; if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.turn.turnArr[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index f15245da1..a609102c7 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -1546,12 +1546,13 @@ private void cboxpRowWidth_SelectedIndexChanged(object sender, EventArgs e) Properties.Vehicle.Default.set_youSkipWidth = yt.rowSkipsWidth; Properties.Vehicle.Default.Save(); } + private void btnHeadlandOnOff_Click(object sender, EventArgs e) { - if (hd.headArr[0].hdLine.Count > 0) + if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) { - hd.isOn = !hd.isOn; - if (hd.isOn) + bnd.isOn = !bnd.isOn; + if (bnd.isOn) { btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHydLift.Visible = true; @@ -1562,8 +1563,9 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; } } + else bnd.isOn = false; - if (!hd.isOn) + if (!bnd.isOn) { p_239.pgn[p_239.hydLift] = 0; vehicle.isHydLiftOn = false; @@ -1572,9 +1574,10 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) } } + private void btnHydLift_Click(object sender, EventArgs e) { - if (hd.isOn) + if (bnd.isOn) { vehicle.isHydLiftOn = !vehicle.isHydLiftOn; if (vehicle.isHydLiftOn) @@ -1968,15 +1971,12 @@ public void GetHeadland() { using (var form = new FormHeadland (this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) - { - } + form.ShowDialog(); } - if (hd.headArr[0].hdLine.Count > 0) + if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) { - hd.isOn = true; + bnd.isOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -1984,7 +1984,7 @@ public void GetHeadland() } else { - hd.isOn = false; + bnd.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index 0d384f3fc..6121798e0 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -61,108 +61,105 @@ private void UpdateChart() for (int i = 0; i < mf.bnd.bndArr.Count && i < 6; i++) { - if (mf.bnd.bndArr[i].isSet) + //outer inner + Button a = new Button { - //outer inner - Button a = new Button - { - Margin = new Padding(6), - Size = new Size(150, 35), - Name = i.ToString(), - TextAlign = ContentAlignment.MiddleCenter, - //ForeColor = System.Drawing.SystemColors.ButtonFace - }; - a.Click += B_Click; - a.BackColor = System.Drawing.SystemColors.ButtonFace; + Margin = new Padding(6), + Size = new Size(150, 35), + Name = i.ToString(), + TextAlign = ContentAlignment.MiddleCenter, + //ForeColor = System.Drawing.SystemColors.ButtonFace + }; + a.Click += B_Click; + a.BackColor = System.Drawing.SystemColors.ButtonFace; + //a.Font = backupfont; + //a.FlatStyle = FlatStyle.Flat; + //a.FlatAppearance.BorderColor = Color.Cyan; + //a.BackColor = Color.Transparent; + //a.FlatAppearance.MouseOverBackColor = BackColor; + //a.FlatAppearance.MouseDownBackColor = BackColor; + + + //area + Button b = new Button + { + Margin = new Padding(6), + Size = new System.Drawing.Size(150, 35), + Name = i.ToString(), + TextAlign = System.Drawing.ContentAlignment.MiddleCenter, + //ForeColor = System.Drawing.SystemColors.ButtonFace + }; + b.Click += B_Click; + b.BackColor = System.Drawing.SystemColors.ButtonFace; + //b.FlatStyle = FlatStyle.Flat; + //b.Font = backupfont; + //b.FlatAppearance.BorderColor = BackColor; + //b.FlatAppearance.MouseOverBackColor = BackColor; + //b.FlatAppearance.MouseDownBackColor = BackColor; + + //drive thru + Button d = new Button + { + Margin = new Padding(6), + Size = new System.Drawing.Size(80, 35), + Name = i.ToString(), + TextAlign = ContentAlignment.MiddleCenter, + //ForeColor = System.Drawing.SystemColors.ButtonFace + //Font = backupfont + }; + d.Click += DriveThru_Click; + d.BackColor = System.Drawing.SystemColors.ButtonFace; + d.Visible = true; + + tableLayoutPanel1.Controls.Add(a, 0, i); + tableLayoutPanel1.Controls.Add(b, 1, i); + tableLayoutPanel1.Controls.Add(d, 2, i); + + if (i == 0) + { + //cc.Text = "Outer"; + mf.bnd.bndArr[i].isDriveThru = false; + mf.bnd.bndArr[i].isDriveAround = false; + a.Text = string.Format(gStr.gsOuter); //a.Font = backupfont; - //a.FlatStyle = FlatStyle.Flat; - //a.FlatAppearance.BorderColor = Color.Cyan; - //a.BackColor = Color.Transparent; - //a.FlatAppearance.MouseOverBackColor = BackColor; - //a.FlatAppearance.MouseDownBackColor = BackColor; - - - //area - Button b = new Button - { - Margin = new Padding(6), - Size = new System.Drawing.Size(150, 35), - Name = i.ToString(), - TextAlign = System.Drawing.ContentAlignment.MiddleCenter, - //ForeColor = System.Drawing.SystemColors.ButtonFace - }; - b.Click += B_Click; - b.BackColor = System.Drawing.SystemColors.ButtonFace; - //b.FlatStyle = FlatStyle.Flat; - //b.Font = backupfont; - //b.FlatAppearance.BorderColor = BackColor; - //b.FlatAppearance.MouseOverBackColor = BackColor; - //b.FlatAppearance.MouseDownBackColor = BackColor; - - //drive thru - Button d = new Button - { - Margin = new Padding(6), - Size = new System.Drawing.Size(80, 35), - Name = i.ToString(), - TextAlign = ContentAlignment.MiddleCenter, - //ForeColor = System.Drawing.SystemColors.ButtonFace - //Font = backupfont - }; - d.Click += DriveThru_Click; - d.BackColor = System.Drawing.SystemColors.ButtonFace; - d.Visible = true; - - tableLayoutPanel1.Controls.Add(a, 0, i); - tableLayoutPanel1.Controls.Add(b, 1, i); - tableLayoutPanel1.Controls.Add(d, 2, i); - - if (i == 0) - { - //cc.Text = "Outer"; - mf.bnd.bndArr[i].isDriveThru = false; - mf.bnd.bndArr[i].isDriveAround = false; - a.Text = string.Format(gStr.gsOuter); - //a.Font = backupfont; - d.Text = mf.bnd.bndArr[i].isDriveThru ? "--" : "--"; - d.Enabled = false; - d.Anchor = System.Windows.Forms.AnchorStyles.None; - a.Anchor = System.Windows.Forms.AnchorStyles.None; - b.Anchor = System.Windows.Forms.AnchorStyles.None; - //d.BackColor = Color.Transparent; - } - else - { - //cc.Text = "Inner"; - inner += 1; - a.Text = string.Format(gStr.gsInner + " {0}", inner); - //a.Font = backupfont; - d.Text = mf.bnd.bndArr[i].isDriveThru ? "Yes" : "No"; - d.Anchor = System.Windows.Forms.AnchorStyles.None; - a.Anchor = System.Windows.Forms.AnchorStyles.None; - b.Anchor = System.Windows.Forms.AnchorStyles.None; - //d.BackColor = Color.Transparent; - } + d.Text = mf.bnd.bndArr[i].isDriveThru ? "--" : "--"; + d.Enabled = false; + d.Anchor = System.Windows.Forms.AnchorStyles.None; + a.Anchor = System.Windows.Forms.AnchorStyles.None; + b.Anchor = System.Windows.Forms.AnchorStyles.None; + //d.BackColor = Color.Transparent; + } + else + { + //cc.Text = "Inner"; + inner += 1; + a.Text = string.Format(gStr.gsInner + " {0}", inner); + //a.Font = backupfont; + d.Text = mf.bnd.bndArr[i].isDriveThru ? "Yes" : "No"; + d.Anchor = System.Windows.Forms.AnchorStyles.None; + a.Anchor = System.Windows.Forms.AnchorStyles.None; + b.Anchor = System.Windows.Forms.AnchorStyles.None; + //d.BackColor = Color.Transparent; + } - if (mf.isMetric) - { - b.Text = Math.Round(mf.bnd.bndArr[i].area * 0.0001, 2).ToString() + " Ha"; - } - else - { - b.Text = Math.Round(mf.bnd.bndArr[i].area * 0.000247105, 2) + " Ac"; - } + if (mf.isMetric) + { + b.Text = Math.Round(mf.bnd.bndArr[i].area * 0.0001, 2).ToString() + " Ha"; + } + else + { + b.Text = Math.Round(mf.bnd.bndArr[i].area * 0.000247105, 2) + " Ac"; + } - if (Selectedreset == false && i == mf.bnd.boundarySelected) - { - a.ForeColor = Color.OrangeRed; - b.ForeColor = Color.OrangeRed; - } - else - { - a.ForeColor = System.Drawing.SystemColors.ControlText; - b.ForeColor = System.Drawing.SystemColors.ControlText; - } + if (Selectedreset == false && i == mf.bnd.boundarySelected) + { + a.ForeColor = Color.OrangeRed; + b.ForeColor = Color.OrangeRed; + } + else + { + a.ForeColor = System.Drawing.SystemColors.ControlText; + b.ForeColor = System.Drawing.SystemColors.ControlText; } } } @@ -173,7 +170,7 @@ private void DriveThru_Click(object sender, EventArgs e) { mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveThru = !mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveThru; UpdateChart(); - mf.turn.BuildTurnLines(); + mf.bnd.BuildTurnLines(); } } @@ -200,7 +197,7 @@ private void B_Click(object sender, EventArgs e) Selectedreset = false; - if (mf.bnd.bndArr.Count > mf.bnd.boundarySelected && mf.bnd.bndArr[mf.bnd.boundarySelected].isSet) + if (mf.bnd.bndArr.Count > mf.bnd.boundarySelected) { btnDelete.Enabled = true; } @@ -235,7 +232,6 @@ private void btnDelete_Click(object sender, EventArgs e) if (mf.bnd.bndArr.Count > mf.bnd.boundarySelected) { mf.bnd.bndArr.RemoveAt(mf.bnd.boundarySelected); - mf.turn.turnArr.RemoveAt(mf.bnd.boundarySelected); } mf.FileSaveBoundary(); @@ -243,7 +239,7 @@ private void btnDelete_Click(object sender, EventArgs e) mf.bnd.boundarySelected = -1; Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); - mf.turn.BuildTurnLines(); + mf.bnd.BuildTurnLines(); UpdateChart(); } else @@ -255,13 +251,12 @@ private void btnDelete_Click(object sender, EventArgs e) private void ResetAllBoundary() { mf.bnd.bndArr.Clear(); - mf.turn.turnArr.Clear(); mf.FileSaveBoundary(); tableLayoutPanel1.Controls.Clear(); tableLayoutPanel1.RowStyles.Clear(); UpdateChart(); - mf.turn.BuildTurnLines(); + mf.bnd.BuildTurnLines(); btnDelete.Enabled = false; } @@ -272,7 +267,6 @@ private void btnOpenGoogleEarth_Click(object sender, EventArgs e) mf.FileMakeKMLFromCurrentPosition(mf.pn.latitude, mf.pn.longitude); System.Diagnostics.Process.Start(mf.fieldsDirectory + mf.currentFieldDirectory + "\\CurrentPosition.KML"); Close(); - } private void btnDeleteAll_Click(object sender, EventArgs e) @@ -400,8 +394,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) //at least 3 points if (numberSets.Length > 2) { - mf.bnd.bndArr.Add(new CBoundaryLines()); - mf.turn.turnArr.Add(new CTurnLines()); + CBoundaryLines New = new CBoundaryLines(); foreach (string item in numberSets) { @@ -412,32 +405,18 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) mf.pn.ConvertWGS84ToLocal(latK, lonK, out norting, out easting); //add the point to boundary - vec3 bndPt = new vec3(easting, norting, 0); - mf.bnd.bndArr[i].bndLine.Add(bndPt); + New.bndLine.Add(new vec3(easting, norting, 0)); } - //build the boundary, make sure is clockwise for outer counter clockwise for inner - bool isCW = mf.bnd.bndArr[i].CalculateBoundaryArea(); - if (mf.bnd.boundarySelected == 0 && isCW) - { - mf.bnd.bndArr[i].ReverseWinding(); - } + New.CalculateBoundaryArea(mf.bnd.boundarySelected); + New.FixBoundaryLine(i); - //inner boundaries - if (mf.bnd.boundarySelected > 0 && !isCW) - { - mf.bnd.bndArr[i].ReverseWinding(); - } + mf.bnd.bndArr.Add(New); - mf.bnd.bndArr[i].FixBoundaryLine(i); - mf.bnd.bndArr[i].PreCalcBoundaryEarLines(); - mf.bnd.bndArr[i].PreCalcBoundaryLines(); - mf.bnd.bndArr[i].isSet = true; mf.fd.UpdateFieldBoundaryGUIAreas(); mf.btnMakeLinesFromBoundary.Visible = true; - coordinates = ""; i++; } @@ -452,7 +431,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) } } mf.FileSaveBoundary(); - mf.turn.BuildTurnLines(); + mf.bnd.BuildTurnLines(); mf.btnMakeLinesFromBoundary.Visible = true; mf.fd.UpdateFieldBoundaryGUIAreas(); UpdateChart(); diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 3d231746c..3be336c6b 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -29,31 +29,17 @@ private void btnStop_Click(object sender, EventArgs e) { if (mf.bnd.bndBeingMadePts.Count > 2) { - mf.bnd.bndArr.Add(new CBoundaryLines()); - mf.turn.turnArr.Add(new CTurnLines()); + CBoundaryLines New = new CBoundaryLines(); for (int i = 0; i < mf.bnd.bndBeingMadePts.Count; i++) { - mf.bnd.bndArr[mf.bnd.boundarySelected].bndLine.Add(mf.bnd.bndBeingMadePts[i]); + New.bndLine.Add(mf.bnd.bndBeingMadePts[i]); } - //build the boundary, make sure is clockwise for outer counter clockwise for inner - bool isCW = mf.bnd.bndArr[mf.bnd.boundarySelected].CalculateBoundaryArea(); - if (mf.bnd.boundarySelected == 0 && isCW) - { - mf.bnd.bndArr[mf.bnd.boundarySelected].ReverseWinding(); - } - - //inner boundaries - if (mf.bnd.boundarySelected > 0 && !isCW) - { - mf.bnd.bndArr[mf.bnd.boundarySelected].ReverseWinding(); - } + New.CalculateBoundaryArea(mf.bnd.boundarySelected); + New.FixBoundaryLine(mf.bnd.boundarySelected); - mf.bnd.bndArr[mf.bnd.boundarySelected].FixBoundaryLine(mf.bnd.boundarySelected); - mf.bnd.bndArr[mf.bnd.boundarySelected].PreCalcBoundaryEarLines(); - mf.bnd.bndArr[mf.bnd.boundarySelected].PreCalcBoundaryLines(); - mf.bnd.bndArr[mf.bnd.boundarySelected].isSet = true; + mf.bnd.bndArr.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); } @@ -64,7 +50,7 @@ private void btnStop_Click(object sender, EventArgs e) //turn lines made from boundaries mf.CalculateMinMax(); mf.FileSaveBoundary(); - mf.turn.BuildTurnLines(); + mf.bnd.BuildTurnLines(); //mf.hd.BuildSingleSpaceHeadLines(); mf.btnMakeLinesFromBoundary.Visible = true; @@ -179,7 +165,6 @@ private void btnLeftRight_Click(object sender, EventArgs e) { mf.bnd.isDrawRightSide = !mf.bnd.isDrawRightSide; btnLeftRight.Image = mf.bnd.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; - } } } \ No newline at end of file diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 09b7ab90e..53cce9638 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -166,8 +166,7 @@ private void LoadKMLBoundary(string filename) //at least 3 points if (numberSets.Length > 2) { - mf.bnd.bndArr.Add(new CBoundaryLines()); - mf.turn.turnArr.Add(new CTurnLines()); + CBoundaryLines New = new CBoundaryLines(); foreach (string item in numberSets) { @@ -180,27 +179,15 @@ private void LoadKMLBoundary(string filename) mf.pn.ConvertWGS84ToLocal(latK, lonK, out northing, out easting); //add the point to boundary - vec3 bndPt = new vec3(easting, northing, 0); - mf.bnd.bndArr[i].bndLine.Add(bndPt); + New.bndLine.Add(new vec3(easting, northing, 0)); } //build the boundary, make sure is clockwise for outer counter clockwise for inner - bool isCW = mf.bnd.bndArr[i].CalculateBoundaryArea(); - if (mf.bnd.boundarySelected == 0 && isCW) - { - mf.bnd.bndArr[i].ReverseWinding(); - } + New.CalculateBoundaryArea(mf.bnd.boundarySelected); + New.FixBoundaryLine(i); - //inner boundaries - if (mf.bnd.boundarySelected > 0 && !isCW) - { - mf.bnd.bndArr[i].ReverseWinding(); - } + mf.bnd.bndArr.Add(New); - mf.bnd.bndArr[i].FixBoundaryLine(i); - mf.bnd.bndArr[i].PreCalcBoundaryEarLines(); - mf.bnd.bndArr[i].PreCalcBoundaryLines(); - mf.bnd.bndArr[i].isSet = true; mf.fd.UpdateFieldBoundaryGUIAreas(); mf.btnMakeLinesFromBoundary.Visible = true; @@ -219,7 +206,7 @@ private void LoadKMLBoundary(string filename) } } mf.FileSaveBoundary(); - mf.turn.BuildTurnLines(); + mf.bnd.BuildTurnLines(); mf.fd.UpdateFieldBoundaryGUIAreas(); mf.CalculateMinMax(); diff --git a/SourceCode/GPS/Forms/FormFlags.cs b/SourceCode/GPS/Forms/FormFlags.cs index da3d006a4..2c4d6594f 100644 --- a/SourceCode/GPS/Forms/FormFlags.cs +++ b/SourceCode/GPS/Forms/FormFlags.cs @@ -54,10 +54,7 @@ private void btnExit_Click(object sender, EventArgs e) timer1.Enabled = false; mf.flagNumberPicked = 0; mf.FileSaveFlags(); - mf.flagDubinsList?.Clear(); - Close(); - } private void btnDeleteFlag_Click(object sender, EventArgs e) diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index 6791e6b3c..142809b11 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -30,9 +30,6 @@ public partial class FormGPS : Form #region // Class Props and instances - //list of vec3 points of Dubins shortest path between 2 points - To be converted to RecPt - public List flagDubinsList = new List(); - //maximum sections available public const int MAXSECTIONS = 17; @@ -192,16 +189,6 @@ public partial class FormGPS : Form /// public CBoundary bnd; - /// - /// The boundary object - /// - public CTurn turn; - - /// - /// The headland created - /// - public CHead hd; - /// /// The internal simulator /// @@ -381,12 +368,6 @@ public FormGPS() //boundary object bnd = new CBoundary(this); - //Turn object - turn = new CTurn(this); - - //headland object - hd = new CHead(this); - //nmea simulator built in. sim = new CSim(this); @@ -998,7 +979,7 @@ public void JobClose() pn.fixOffset.northing = 0; //turn off headland - hd.isOn = false; + bnd.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; @@ -1012,9 +993,7 @@ public void JobClose() oglZoom.SendToBack(); //clean all the lines - bnd.bndArr?.Clear(); - turn.turnArr?.Clear(); - hd.headArr[0].hdLine?.Clear(); + bnd.bndArr.Clear(); panelRight.Enabled = false; FieldMenuButtonEnableDisable(false); @@ -1095,7 +1074,6 @@ public void JobClose() ABLine.DeleteAB(); ABLine.lineArr?.Clear(); ABLine.numABLineSelected = 0; - tram.tramArr?.Clear(); tram.tramList?.Clear(); //curve line @@ -1143,12 +1121,6 @@ public void JobClose() //reset acre and distance counters fd.workedAreaTotal = 0; - //reset boundaries - bnd.ResetBoundaries(); - - //reset turn lines - turn.ResetTurnLines(); - //reset GUI areas fd.UpdateFieldBoundaryGUIAreas(); diff --git a/SourceCode/GPS/Forms/FormHeadland.cs b/SourceCode/GPS/Forms/FormHeadland.cs index 0bdac5c07..d4bc8e0dc 100644 --- a/SourceCode/GPS/Forms/FormHeadland.cs +++ b/SourceCode/GPS/Forms/FormHeadland.cs @@ -12,7 +12,6 @@ public partial class FormHeadland : Form //access to the main GPS form and all its variables private readonly FormGPS mf = null; - private double maxFieldX, maxFieldY, minFieldX, minFieldY, fieldCenterX, fieldCenterY, maxFieldDistance; private Point fixPt; private bool isA, isSet; @@ -39,6 +38,8 @@ public FormHeadland(Form callingForm) btnReset.Text = gStr.gsResetAll; nudDistance.Controls[0].Enabled = false; + + mf.CalculateMinMax(); } private void FormHeadland_Load(object sender, EventArgs e) @@ -53,10 +54,10 @@ private void FormHeadland_Load(object sender, EventArgs e) nudDistance.Value = 0; nudSetDistance.Value = 0; - if (mf.hd.headArr[0].hdLine.Count > 0) + if (mf.bnd.bndArr[0].hdLine.Count > 0) { - hdArr = new vec3[mf.hd.headArr[0].hdLine.Count]; - mf.hd.headArr[0].hdLine.CopyTo(hdArr); + hdArr = new vec3[mf.bnd.bndArr[0].hdLine.Count]; + mf.bnd.bndArr[0].hdLine.CopyTo(hdArr); RebuildHeadLineTemplate(); } else @@ -316,13 +317,11 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit); GL.LoadIdentity(); // Reset The View - CalculateMinMax(); - //back the camera up - GL.Translate(0, 0, -maxFieldDistance); + GL.Translate(0, 0, -mf.maxFieldDistance); //translate to that spot in the world - GL.Translate(-fieldCenterX, -fieldCenterY, 0); + GL.Translate(-mf.fieldCenterX, -mf.fieldCenterY, 0); GL.Color3(1, 1, 1); @@ -381,13 +380,13 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) vec3 plotPt = new vec3 { //convert screen coordinates to field coordinates - easting = fixPt.X * maxFieldDistance / 632.0, - northing = fixPt.Y * maxFieldDistance / 632.0, + easting = fixPt.X * mf.maxFieldDistance / 632.0, + northing = fixPt.Y * mf.maxFieldDistance / 632.0, heading = 0 }; - plotPt.easting += fieldCenterX; - plotPt.northing += fieldCenterY; + plotPt.easting += mf.fieldCenterX; + plotPt.northing += mf.fieldCenterY; pint.easting = plotPt.easting; pint.northing = plotPt.northing; @@ -566,7 +565,7 @@ private void timer1_Tick(object sender, EventArgs e) private void btnExit_Click(object sender, EventArgs e) { - mf.hd.headArr[0].hdLine?.Clear(); + mf.bnd.bndArr[0].hdLine?.Clear(); //middle points for (int i = 1; i < hdArr.Length; i++) @@ -581,7 +580,7 @@ private void btnExit_Click(object sender, EventArgs e) { if (i == 0) { - mf.hd.headArr[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); + mf.bnd.bndArr[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); continue; } delta += (hdArr[i - 1].heading - hdArr[i].heading); @@ -590,24 +589,10 @@ private void btnExit_Click(object sender, EventArgs e) { vec3 pt = new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading); - mf.hd.headArr[0].hdLine.Add(pt); + mf.bnd.bndArr[0].hdLine.Add(pt); delta = 0; } } - - - - //for (int i = 0; i < hdArr.Length; i++) - //{ - // vec3 pt = new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading); - // mf.hd.headArr[0].hdLine.Add(pt); - - // if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(pt)) mf.hd.headArr[0].isDrawList.Add(true); - // else mf.hd.headArr[0].isDrawList.Add(false); - //} - - mf.hd.headArr[0].PreCalcHeadLines(); - mf.FileSaveHeadland(); Close(); @@ -615,9 +600,7 @@ private void btnExit_Click(object sender, EventArgs e) private void btnTurnOffHeadland_Click(object sender, EventArgs e) { - mf.hd.headArr[0].hdLine?.Clear(); - - mf.hd.headArr[0].calcList?.Clear(); + mf.bnd.bndArr[0].hdLine?.Clear(); mf.FileSaveHeadland(); @@ -686,86 +669,5 @@ private void oglSelf_Resize(object sender, EventArgs e) } //determine mins maxs of patches and whole field. - private void CalculateMinMax() - { - minFieldX = 9999999; minFieldY = 9999999; - maxFieldX = -9999999; maxFieldY = -9999999; - - //draw patches j= # of sections - for (int j = 0; j < mf.tool.numSuperSection; j++) - { - //every time the section turns off and on is a new patch - int patchCount = mf.section[j].patchList.Count; - - if (patchCount > 0) - { - //for every new chunk of patch - foreach (List triList in mf.section[j].patchList) - { - int count2 = triList.Count; - for (int i = 0; i < count2; i += 3) - { - double x = triList[i].easting; - double y = triList[i].northing; - - //also tally the max/min of field x and z - if (minFieldX > x) minFieldX = x; - if (maxFieldX < x) maxFieldX = x; - if (minFieldY > y) minFieldY = y; - if (maxFieldY < y) maxFieldY = y; - } - } - } - - //min max of the boundary - if (mf.bnd.bndArr.Count > 0) - { - int bndCnt = mf.bnd.bndArr[0].bndLine.Count; - for (int i = 0; i < bndCnt; i++) - { - double x = mf.bnd.bndArr[0].bndLine[i].easting; - double y = mf.bnd.bndArr[0].bndLine[i].northing; - - //also tally the max/min of field x and z - if (minFieldX > x) minFieldX = x; - if (maxFieldX < x) maxFieldX = x; - if (minFieldY > y) minFieldY = y; - if (maxFieldY < y) maxFieldY = y; - } - } - - if (maxFieldX == -9999999 || minFieldX == 9999999 || maxFieldY == -9999999 || minFieldY == 9999999) - { - maxFieldX = 0; minFieldX = 0; maxFieldY = 0; minFieldY = 0; - } - else - { - //the largest distancew across field - double dist = Math.Abs(minFieldX - maxFieldX); - double dist2 = Math.Abs(minFieldY - maxFieldY); - - if (dist > dist2) maxFieldDistance = dist; - else maxFieldDistance = dist2; - - if (maxFieldDistance < 100) maxFieldDistance = 100; - if (maxFieldDistance > 19900) maxFieldDistance = 19900; - //lblMax.Text = ((int)maxFieldDistance).ToString(); - - fieldCenterX = (maxFieldX + minFieldX) / 2.0; - fieldCenterY = (maxFieldY + minFieldY) / 2.0; - } - - //if (isMetric) - //{ - // lblFieldWidthEastWest.Text = Math.Abs((maxFieldX - minFieldX)).ToString("N0") + " m"; - // lblFieldWidthNorthSouth.Text = Math.Abs((maxFieldY - minFieldY)).ToString("N0") + " m"; - //} - //else - //{ - // lblFieldWidthEastWest.Text = Math.Abs((maxFieldX - minFieldX) * glm.m2ft).ToString("N0") + " ft"; - // lblFieldWidthNorthSouth.Text = Math.Abs((maxFieldY - minFieldY) * glm.m2ft).ToString("N0") + " ft"; - //} - } - } } } diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 57884799a..10bc6cb2f 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -498,7 +498,7 @@ public void LoadSettings() if (Properties.Settings.Default.setAS_isAutoSteerAutoOn) btnAutoSteer.Text = "R"; else btnAutoSteer.Text = "M"; - if (hd.isOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; + if (bnd.isOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; else btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnChangeMappingColor.BackColor = sectionColorDay; diff --git a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs index 6108828e8..fc1e2270b 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs @@ -12,7 +12,6 @@ public partial class FormABDraw : Form //access to the main GPS form and all its variables private readonly FormGPS mf = null; - private double maxFieldX, maxFieldY, minFieldX, minFieldY, fieldCenterX, fieldCenterY, maxFieldDistance; private Point fixPt; private bool isA = true, isMakingAB = false, isMakingCurve = false; @@ -41,6 +40,8 @@ public FormABDraw(Form callingForm) nudDistance.Maximum = (int)(nudDistance.Maximum / 2.54M); nudDistance.Minimum = (int)(nudDistance.Minimum / 2.54M); } + + mf.CalculateMinMax(); } private void FormABDraw_Load(object sender, EventArgs e) @@ -256,13 +257,13 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) vec3 plotPt = new vec3 { //convert screen coordinates to field coordinates - easting = fixPt.X * maxFieldDistance / 632.0, - northing = fixPt.Y * maxFieldDistance / 632.0, + easting = fixPt.X * mf.maxFieldDistance / 632.0, + northing = fixPt.Y * mf.maxFieldDistance / 632.0, heading = 0 }; - plotPt.easting += fieldCenterX; - plotPt.northing += fieldCenterY; + plotPt.easting += mf.fieldCenterX; + plotPt.northing += mf.fieldCenterY; pint.easting = plotPt.easting; pint.northing = plotPt.northing; @@ -659,13 +660,11 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit); GL.LoadIdentity(); // Reset The View - CalculateMinMax(); - //back the camera up - GL.Translate(0, 0, -maxFieldDistance); + GL.Translate(0, 0, -mf.maxFieldDistance); //translate to that spot in the world - GL.Translate(-fieldCenterX, -fieldCenterY, 0); + GL.Translate(-mf.fieldCenterX, -mf.fieldCenterY, 0); GL.Color3(1, 1, 1); @@ -959,90 +958,6 @@ private void DrawSections() } } } //end of section patches - - } - - //determine mins maxs of patches and whole field. - private void CalculateMinMax() - { - minFieldX = 9999999; minFieldY = 9999999; - maxFieldX = -9999999; maxFieldY = -9999999; - - //draw patches j= # of sections - for (int j = 0; j < mf.tool.numSuperSection; j++) - { - //every time the section turns off and on is a new patch - int patchCount = mf.section[j].patchList.Count; - - if (patchCount > 0) - { - //for every new chunk of patch - foreach (System.Collections.Generic.List triList in mf.section[j].patchList) - { - int count2 = triList.Count; - for (int i = 0; i < count2; i += 3) - { - double x = triList[i].easting; - double y = triList[i].northing; - - //also tally the max/min of field x and z - if (minFieldX > x) minFieldX = x; - if (maxFieldX < x) maxFieldX = x; - if (minFieldY > y) minFieldY = y; - if (maxFieldY < y) maxFieldY = y; - } - } - } - - //min max of the boundary - if (mf.bnd.bndArr.Count > 0) - { - int bndCnt = mf.bnd.bndArr[0].bndLine.Count; - for (int i = 0; i < bndCnt; i++) - { - double x = mf.bnd.bndArr[0].bndLine[i].easting; - double y = mf.bnd.bndArr[0].bndLine[i].northing; - - //also tally the max/min of field x and z - if (minFieldX > x) minFieldX = x; - if (maxFieldX < x) maxFieldX = x; - if (minFieldY > y) minFieldY = y; - if (maxFieldY < y) maxFieldY = y; - } - } - - if (maxFieldX == -9999999 || minFieldX == 9999999 || maxFieldY == -9999999 || minFieldY == 9999999) - { - maxFieldX = 0; minFieldX = 0; maxFieldY = 0; minFieldY = 0; - } - else - { - //the largest distancew across field - double dist = Math.Abs(minFieldX - maxFieldX); - double dist2 = Math.Abs(minFieldY - maxFieldY); - - if (dist > dist2) maxFieldDistance = dist; - else maxFieldDistance = dist2; - - if (maxFieldDistance < 100) maxFieldDistance = 100; - if (maxFieldDistance > 19900) maxFieldDistance = 19900; - //lblMax.Text = ((int)maxFieldDistance).ToString(); - - fieldCenterX = (maxFieldX + minFieldX) / 2.0; - fieldCenterY = (maxFieldY + minFieldY) / 2.0; - } - - //if (isMetric) - //{ - // lblFieldWidthEastWest.Text = Math.Abs((maxFieldX - minFieldX)).ToString("N0") + " m"; - // lblFieldWidthNorthSouth.Text = Math.Abs((maxFieldY - minFieldY)).ToString("N0") + " m"; - //} - //else - //{ - // lblFieldWidthEastWest.Text = Math.Abs((maxFieldX - minFieldX) * glm.m2ft).ToString("N0") + " ft"; - // lblFieldWidthNorthSouth.Text = Math.Abs((maxFieldY - minFieldY) * glm.m2ft).ToString("N0") + " ft"; - //} - } } } } \ No newline at end of file diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index edb8f16ef..e9d953000 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -1,5 +1,4 @@ - -using System; +using System; using OpenTK; using OpenTK.Graphics.OpenGL; using System.Windows.Forms; @@ -344,10 +343,18 @@ private void oglMain_Paint(object sender, PaintEventArgs e) //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) { - turn.DrawTurnLines(); + bnd.DrawTurnLines(); } - if (hd.isOn) hd.DrawHeadLines(); + if (bnd.isOn) + { + GL.LineWidth(ABLine.lineWidth); + GL.Color3(0.960f, 0.96232f, 0.30f); + for (int i = 0; i < bnd.bndArr.Count; i++) + { + if (bnd.bndArr[i].hdLine.Count > 0) bnd.bndArr[i].DrawHeadLine(); + } + } if (flagPts.Count > 0) DrawFlags(); @@ -624,7 +631,16 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //draw 250 green for the headland - if (hd.isOn) hd.DrawHeadLinesBack(); + if (bnd.isOn) + { + GL.LineWidth(3); + GL.Color3((byte)0, (byte)250, (byte)0); + + for (int i = 0; i < bnd.bndArr.Count; i++) + { + if (bnd.bndArr[i].hdLine.Count > 0) bnd.bndArr[i].DrawHeadLineBackBuffer(); + } + } //finish it up - we need to read the ram of video card @@ -661,7 +677,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tool.numOfSections == 1 || pn.speed < vehicle.slowSpeedCutoff) tool.isSuperSectionAllowedOn = false; - if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && hd.isOn) + if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && bnd.isOn) tool.isSuperSectionAllowedOn = false; //clamp the height after looking way ahead, this is for switching off super section only @@ -671,7 +687,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //10 % min is required for overlap, otherwise it never would be on. int pixLimit = (int)((double)(section[0].rpSectionWidth * rpOnHeight) / (double)(5.0)); - if ((rpOnHeight < rpToolHeight && hd.isOn)) rpHeight = rpToolHeight + 2; + if ((rpOnHeight < rpToolHeight && bnd.isOn)) rpHeight = rpToolHeight + 2; else rpHeight = rpOnHeight + 2; if (rpHeight > 290) rpHeight = 290; @@ -733,7 +749,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //determine if in or out of headland, do hydraulics if on - if (hd.isOn) + if (bnd.isOn) { //calculate the slope double m = (vehicle.hydLiftLookAheadDistanceRight - vehicle.hydLiftLookAheadDistanceLeft) / tool.rpWidth; @@ -754,12 +770,12 @@ private void oglBack_Paint(object sender, PaintEventArgs e) GetOutTool: //is the tool completely in the headland or not - hd.isToolInHeadland = hd.isToolOuterPointsInHeadland && !isHeadlandClose; + bnd.isToolInHeadland = bnd.isToolOuterPointsInHeadland && !isHeadlandClose; - if (isHeadlandClose || hd.isToolInHeadland) tool.isSuperSectionAllowedOn = false; + if (isHeadlandClose || bnd.isToolInHeadland) tool.isSuperSectionAllowedOn = false; //set hydraulics based on tool in headland or not - hd.SetHydPosition(); + bnd.SetHydPosition(); } } else //supersection check by applied only @@ -919,7 +935,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) section[j].mappingOnTimer = 0; } - else if (section[j].isInHeadlandArea & hd.isOn) + else if (section[j].isInHeadlandArea & bnd.isOn) { // if headland is on and out, turn off section[j].isMappingRequiredOn = false; @@ -934,7 +950,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) /////////////////////////////////////////// Section control ssssssssssssssssssssss /// - if (hd.isOn) hd.WhereAreToolLookOnPoints(); + if (bnd.isOn) bnd.WhereAreToolLookOnPoints(); for (int j = 0; j < tool.numOfSections; j++) { @@ -997,7 +1013,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //is headland coming up - if (hd.isOn) + if (bnd.isOn) { bool isHeadlandInLookOn = false; @@ -2399,7 +2415,7 @@ public void CalculateMinMax() foreach (var triList in section[j].patchList) { int count2 = triList.Count; - for (int i = 0; i < count2; i += 3) + for (int i = 1; i < count2; i += 3) { double x = triList[i].easting; double y = triList[i].northing; diff --git a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs index c885f16c7..cd7e1b6fb 100644 --- a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs +++ b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs @@ -13,15 +13,10 @@ public partial class FormTouchPick : Form //access to the main GPS form and all its variables private readonly FormGPS mf = null; - private double maxFieldX, maxFieldY, minFieldX, minFieldY, fieldCenterX, fieldCenterY, maxFieldDistance; private Point fixPt; public double low = 0, high = 1; - //list of coordinates of boundary line - //public List bndLine = new List(); - //public List> bndArr = new List>(); - public vec3 pint = new vec3(0.0, 1.0, 0.0); public FormTouchPick(Form callingForm) @@ -32,6 +27,8 @@ public FormTouchPick(Form callingForm) InitializeComponent(); //lblPick.Text = gStr.gsSelectALine; //nudDistance.Controls[0].Enabled = false; + + mf.CalculateMinMax(); } private void TouchPick_Load(object sender, EventArgs e) @@ -61,9 +58,6 @@ private void TouchPick_Load(object sender, EventArgs e) { line = reader.ReadLine(); string[] offs = line.Split(','); - - mf.bnd.bndArr.Add(new CBoundaryLines()); - mf.turn.turnArr.Add(new CTurnLines()); } } catch (Exception) @@ -98,13 +92,13 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) vec3 plotPt = new vec3 { //convert screen coordinates to field coordinates - easting = fixPt.X * maxFieldDistance / 632.0, - northing = fixPt.Y * maxFieldDistance / 632.0, + easting = fixPt.X * mf.maxFieldDistance / 632.0, + northing = fixPt.Y * mf.maxFieldDistance / 632.0, heading = 0 }; - plotPt.easting += fieldCenterX; - plotPt.northing += fieldCenterY; + plotPt.easting += mf.fieldCenterX; + plotPt.northing += mf.fieldCenterY; pint.easting = plotPt.easting; pint.northing = plotPt.northing; @@ -119,13 +113,11 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit); GL.LoadIdentity(); // Reset The View - CalculateMinMax(); - //back the camera up - GL.Translate(0, 0, -maxFieldDistance); + GL.Translate(0, 0, -mf.maxFieldDistance); //translate to that spot in the world - GL.Translate(-fieldCenterX, -fieldCenterY, 0); + GL.Translate(-mf.fieldCenterX, -mf.fieldCenterY, 0); GL.Color3(1, 1, 1); @@ -167,88 +159,5 @@ private void oglSelf_Load(object sender, EventArgs e) GL.CullFace(CullFaceMode.Back); GL.ClearColor(0.23122f, 0.2318f, 0.2315f, 1.0f); } - - //determine mins maxs of patches and whole field. - private void CalculateMinMax() - { - minFieldX = 9999999; minFieldY = 9999999; - maxFieldX = -9999999; maxFieldY = -9999999; - - //draw patches j= # of sections - for (int j = 0; j < mf.tool.numSuperSection; j++) - { - //every time the section turns off and on is a new patch - int patchCount = mf.section[j].patchList.Count; - - if (patchCount > 0) - { - //for every new chunk of patch - foreach (List triList in mf.section[j].patchList) - { - int count2 = triList.Count; - for (int i = 0; i < count2; i += 3) - { - double x = triList[i].easting; - double y = triList[i].northing; - - //also tally the max/min of field x and z - if (minFieldX > x) minFieldX = x; - if (maxFieldX < x) maxFieldX = x; - if (minFieldY > y) minFieldY = y; - if (maxFieldY < y) maxFieldY = y; - } - } - } - - //min max of the boundary - if (mf.bnd.bndArr.Count > 0) - { - int bndCnt = mf.bnd.bndArr[0].bndLine.Count; - for (int i = 0; i < bndCnt; i++) - { - double x = mf.bnd.bndArr[0].bndLine[i].easting; - double y = mf.bnd.bndArr[0].bndLine[i].northing; - - //also tally the max/min of field x and z - if (minFieldX > x) minFieldX = x; - if (maxFieldX < x) maxFieldX = x; - if (minFieldY > y) minFieldY = y; - if (maxFieldY < y) maxFieldY = y; - } - } - - if (maxFieldX == -9999999 || minFieldX == 9999999 || maxFieldY == -9999999 || minFieldY == 9999999) - { - maxFieldX = 0; minFieldX = 0; maxFieldY = 0; minFieldY = 0; - } - else - { - //the largest distancew across field - double dist = Math.Abs(minFieldX - maxFieldX); - double dist2 = Math.Abs(minFieldY - maxFieldY); - - if (dist > dist2) maxFieldDistance = dist; - else maxFieldDistance = dist2; - - if (maxFieldDistance < 100) maxFieldDistance = 100; - if (maxFieldDistance > 19900) maxFieldDistance = 19900; - //lblMax.Text = ((int)maxFieldDistance).ToString(); - - fieldCenterX = (maxFieldX + minFieldX) / 2.0; - fieldCenterY = (maxFieldY + minFieldY) / 2.0; - } - - //if (isMetric) - //{ - // lblFieldWidthEastWest.Text = Math.Abs((maxFieldX - minFieldX)).ToString("N0") + " m"; - // lblFieldWidthNorthSouth.Text = Math.Abs((maxFieldY - minFieldY)).ToString("N0") + " m"; - //} - //else - //{ - // lblFieldWidthEastWest.Text = Math.Abs((maxFieldX - minFieldX) * glm.m2ft).ToString("N0") + " ft"; - // lblFieldWidthNorthSouth.Text = Math.Abs((maxFieldY - minFieldY) * glm.m2ft).ToString("N0") + " ft"; - //} - } - } } } \ No newline at end of file diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index 98b966709..b0f06a281 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -710,7 +710,7 @@ public void UpdateFixPosition() if (bnd.bndArr.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (IsInsideGeoFenceAKABoundary() && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (bnd.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; @@ -1238,7 +1238,7 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (tool.lookAheadDistanceOffPixelsRight > 160) tool.lookAheadDistanceOffPixelsRight = 160; //determine where the tool is wrt to headland - if (hd.isOn) hd.WhereAreToolCorners(); + if (bnd.isOn) bnd.WhereAreToolCorners(); //set up the super for youturn section[tool.numOfSections].isInBoundary = true; @@ -1259,11 +1259,8 @@ public void CalculateSectionLookAhead(double northing, double easting, double co for (int i = 1; i < bnd.bndArr.Count; i++) { //inner boundaries should normally NOT have point inside - if (bnd.bndArr[i].isSet) - { - isLeftIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].leftPoint); - isRightIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].rightPoint); - } + isLeftIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].leftPoint); + isRightIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].rightPoint); } //merge the two sides into in or out @@ -1279,7 +1276,7 @@ public void CalculateSectionLookAhead(double northing, double easting, double co for (int i = 1; i < bnd.bndArr.Count; i++) { //inner boundaries should normally NOT have point inside - if (bnd.bndArr[i].isSet) isRightIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].rightPoint); + isRightIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].rightPoint); } if (isLeftIn && isRightIn) section[j].isInBoundary = true; @@ -1668,33 +1665,6 @@ private void InitializeFirstFewGPSPositions() return; } } - - public bool IsInsideGeoFenceAKABoundary() - { - //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (bnd.bndArr[0].IsPointInsideBoundary(pivotAxlePos)) - { - for (int i = 1; i < bnd.bndArr.Count; i++) - { - //make sure not inside a non drivethru boundary - if (!bnd.bndArr[i].isSet) continue; - if (bnd.bndArr[i].isDriveThru) continue; - if (bnd.bndArr[i].IsPointInsideBoundary(pivotAxlePos)) - { - distancePivotToTurnLine = -3333; - return false; - } - } - } - else - { - distancePivotToTurnLine = -3333; - return false; - } - //we are safely inside outer, outside inner boundaries - return true; - } - }//end class }//end namespace diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index bb4bdf7e3..5e0892f09 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -683,8 +683,7 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - bnd.bndArr.Add(new CBoundaryLines()); - turn.turnArr.Add(new CTurnLines()); + CBoundaryLines New = new CBoundaryLines(); //True or False OR points from older boundary files line = reader.ReadLine(); @@ -692,14 +691,14 @@ public void FileOpenField(string _openType) //Check for older boundary files, then above line string is num of points if (line == "True" || line == "False") { - bnd.bndArr[k].isDriveThru = bool.Parse(line); + New.isDriveThru = bool.Parse(line); line = reader.ReadLine(); //number of points } //Check for latest boundary files, then above line string is num of points if (line == "True" || line == "False") { - bnd.bndArr[k].isDriveAround = bool.Parse(line); + New.isDriveAround = bool.Parse(line); line = reader.ReadLine(); //number of points } @@ -717,49 +716,35 @@ public void FileOpenField(string _openType) double.Parse(words[1], CultureInfo.InvariantCulture), double.Parse(words[2], CultureInfo.InvariantCulture)); - //if (turnheading) - //{ - // vecPt.heading = vecPt.heading + Math.PI; - //} - bnd.bndArr[k].bndLine.Add(vecPt); + New.bndLine.Add(vecPt); } - bnd.bndArr[k].CalculateBoundaryArea(); - bnd.bndArr[k].PreCalcBoundaryLines(); - if (bnd.bndArr[k].area > 0) bnd.bndArr[k].isSet = true; - else bnd.bndArr[k].isSet = false; + New.CalculateBoundaryArea(k); double delta = 0; - bnd.bndArr[k].bndLineEar?.Clear(); + New.bndLineEar?.Clear(); - for (int i = 0; i < bnd.bndArr[k].bndLine.Count; i++) + for (int i = 0; i < New.bndLine.Count; i++) { if (i == 0) { - bnd.bndArr[k].bndLineEar.Add(new vec2(bnd.bndArr[k].bndLine[i].easting, bnd.bndArr[k].bndLine[i].northing)); + New.bndLineEar.Add(new vec2(New.bndLine[i].easting, New.bndLine[i].northing)); continue; } - delta += (bnd.bndArr[k].bndLine[i - 1].heading - bnd.bndArr[k].bndLine[i].heading); + delta += (New.bndLine[i - 1].heading - New.bndLine[i].heading); if (Math.Abs(delta) > 0.04) { - bnd.bndArr[k].bndLineEar.Add(new vec2(bnd.bndArr[k].bndLine[i].easting, bnd.bndArr[k].bndLine[i].northing)); + New.bndLineEar.Add(new vec2(New.bndLine[i].easting, New.bndLine[i].northing)); delta = 0; } } - bnd.bndArr[k].PreCalcBoundaryEarLines(); + bnd.bndArr.Add(New); } - else - { - bnd.bndArr.RemoveAt(bnd.bndArr.Count - 1); - turn.turnArr.RemoveAt(bnd.bndArr.Count - 1); - k = k - 1; - } - if (reader.EndOfStream) break; } CalculateMinMax(); - turn.BuildTurnLines(); + bnd.BuildTurnLines(); if (bnd.bndArr.Count > 0) btnMakeLinesFromBoundary.Visible = true; } @@ -788,30 +773,28 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - hd.headArr[0].hdLine.Clear(); - - //read the number of points - line = reader.ReadLine(); - int numPoints = int.Parse(line); - - if (numPoints > 0 && bnd.bndArr.Count >= hd.headArr.Count) + if (bnd.bndArr.Count > k) { + bnd.bndArr[k].hdLine.Clear(); - hd.headArr[k].hdLine.Clear(); - hd.headArr[k].calcList.Clear(); + //read the number of points + line = reader.ReadLine(); + int numPoints = int.Parse(line); - //load the line - for (int i = 0; i < numPoints; i++) + if (numPoints > 0) { - line = reader.ReadLine(); - string[] words = line.Split(','); - vec3 vecPt = new vec3( - double.Parse(words[0], CultureInfo.InvariantCulture), - double.Parse(words[1], CultureInfo.InvariantCulture), - double.Parse(words[2], CultureInfo.InvariantCulture)); - hd.headArr[k].hdLine.Add(vecPt); + //load the line + for (int i = 0; i < numPoints; i++) + { + line = reader.ReadLine(); + string[] words = line.Split(','); + vec3 vecPt = new vec3( + double.Parse(words[0], CultureInfo.InvariantCulture), + double.Parse(words[1], CultureInfo.InvariantCulture), + double.Parse(words[2], CultureInfo.InvariantCulture)); + bnd.bndArr[k].hdLine.Add(vecPt); + } } - hd.headArr[k].PreCalcHeadLines(); } } } @@ -825,15 +808,9 @@ public void FileOpenField(string _openType) } } - //if (hd.headArr[0].hdLine.Count > 0) hd.isOn = true; - //hd.isOn = false; - - //if (hd.isOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; - //btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; - - if (hd.headArr[0].hdLine.Count > 0) + if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) { - hd.isOn = true; + bnd.isOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -842,7 +819,7 @@ public void FileOpenField(string _openType) } else { - hd.isOn = false; + bnd.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; @@ -934,40 +911,6 @@ public void FileOpenField(string _openType) } } - // bnd.bndArr[k].CalculateBoundaryArea(); - // bnd.bndArr[k].PreCalcBoundaryLines(); - // if (bnd.bndArr[k].area > 0) bnd.bndArr[k].isSet = true; - // else bnd.bndArr[k].isSet = false; - - // double delta = 0; - // bnd.bndArr[k].bndLineEar?.Clear(); - - // for (int i = 0; i < bnd.bndArr[k].bndLine.Count; i++) - // { - // if (i == 0) - // { - // bnd.bndArr[k].bndLineEar.Add(new vec2(bnd.bndArr[k].bndLine[i].easting, bnd.bndArr[k].bndLine[i].northing)); - // continue; - // } - // delta += (bnd.bndArr[k].bndLine[i - 1].heading - bnd.bndArr[k].bndLine[i].heading); - // if (Math.Abs(delta) > 0.04) - // { - // bnd.bndArr[k].bndLineEar.Add(new vec2(bnd.bndArr[k].bndLine[i].easting, bnd.bndArr[k].bndLine[i].northing)); - // delta = 0; - // } - // } - - // bnd.bndArr[k].PreCalcBoundaryEarLines(); - // } - // else - // { - // bnd.bndArr.RemoveAt(bnd.bndArr.Count - 1); - // turn.turnArr.RemoveAt(bnd.bndArr.Count - 1); - // k = k - 1; - // } - // if (reader.EndOfStream) break; - //} - FixTramModeButton(); } @@ -1352,17 +1295,17 @@ public void FileSaveHeadland() { writer.WriteLine("$Headland"); - if (hd.headArr[0].hdLine.Count > 0) + if (bnd.bndArr[0].hdLine.Count > 0) { - for (int i = 0; i < hd.headArr.Count; i++) + for (int i = 0; i < bnd.bndArr.Count; i++) { - writer.WriteLine(hd.headArr[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); - if (hd.headArr[0].hdLine.Count > 0) + writer.WriteLine(bnd.bndArr[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); + if (bnd.bndArr[0].hdLine.Count > 0) { - for (int j = 0; j < hd.headArr[i].hdLine.Count; j++) - writer.WriteLine(Math.Round(hd.headArr[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(hd.headArr[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(hd.headArr[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < bnd.bndArr[i].hdLine.Count; j++) + writer.WriteLine(Math.Round(bnd.bndArr[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndArr[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndArr[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); } } } diff --git a/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs b/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs index 2adc2d0e2..5286675aa 100644 --- a/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs +++ b/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs @@ -401,7 +401,7 @@ private void tabUTurn_Leave(object sender, EventArgs e) Properties.Settings.Default.Save(); Properties.Vehicle.Default.Save(); - mf.turn.BuildTurnLines(); + mf.bnd.BuildTurnLines(); mf.yt.ResetCreatedYouTurn(); } From 599ae1f1a4e811049cae90476800c1a9ec179146 Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Mon, 25 Oct 2021 00:14:59 -0600 Subject: [PATCH 02/18] Change Boundary to Plot, Lines to Plots Plot is the main object, and the files Boundary, Turns, Headland are partials to plot Plots is the array, BoundaryLines, TurnLines, and HeadlandLines are partial to each array. --- SourceCode/GPS/AgOpenGPS.csproj | 26 +++-- SourceCode/GPS/Classes/CABCurve.cs | 10 +- SourceCode/GPS/Classes/CABLine.cs | 8 +- SourceCode/GPS/Classes/CBoundary.cs | 94 +++++-------------- SourceCode/GPS/Classes/CBoundaryLines.cs | 31 ++---- SourceCode/GPS/Classes/CContour.cs | 12 +-- SourceCode/GPS/Classes/CFieldData.cs | 8 +- SourceCode/GPS/Classes/CHead.cs | 23 ++--- SourceCode/GPS/Classes/CHeadLines.cs | 2 +- SourceCode/GPS/Classes/CPlot.cs | 35 +++++++ SourceCode/GPS/Classes/CPlots.cs | 30 ++++++ SourceCode/GPS/Classes/CTram.cs | 26 ++--- SourceCode/GPS/Classes/CTurn.cs | 90 +++++++++--------- SourceCode/GPS/Classes/CTurnLines.cs | 2 +- SourceCode/GPS/Classes/CVehicle.cs | 12 +-- SourceCode/GPS/Classes/CYouTurn.cs | 78 +++++++-------- SourceCode/GPS/Forms/Controls.Designer.cs | 24 ++--- SourceCode/GPS/Forms/FormBoundary.cs | 62 ++++++------ SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 62 ++++++------ SourceCode/GPS/Forms/FormFieldKML.cs | 16 ++-- SourceCode/GPS/Forms/FormGPS.cs | 8 +- SourceCode/GPS/Forms/FormHeadland.cs | 24 ++--- SourceCode/GPS/Forms/GUI.Designer.cs | 6 +- SourceCode/GPS/Forms/Guidance/FormABDraw.cs | 30 +++--- SourceCode/GPS/Forms/OpenGL.Designer.cs | 62 ++++++------ SourceCode/GPS/Forms/Pickers/FormTouchPick.cs | 2 +- SourceCode/GPS/Forms/Position.designer.cs | 42 ++++----- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 62 ++++++------ .../Forms/Settings/ConfigModule.Designer.cs | 2 +- 29 files changed, 451 insertions(+), 438 deletions(-) create mode 100644 SourceCode/GPS/Classes/CPlot.cs create mode 100644 SourceCode/GPS/Classes/CPlots.cs diff --git a/SourceCode/GPS/AgOpenGPS.csproj b/SourceCode/GPS/AgOpenGPS.csproj index 6038b0af3..e2584fa00 100644 --- a/SourceCode/GPS/AgOpenGPS.csproj +++ b/SourceCode/GPS/AgOpenGPS.csproj @@ -113,24 +113,34 @@ + + CPlot.cs + + + CPlots.cs + + - + - - + + CPlots.cs + + + CPlot.cs + - @@ -140,8 +150,12 @@ - - + + CPlot.cs + + + CPlots.cs + Form diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index 94aa5c004..3fb7ebcf5 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -683,7 +683,7 @@ public void BuildTram() mf.tram.tramList?.Clear(); mf.tram.tramArr?.Clear(); - bool isBndExist = mf.bnd.bndArr.Count != 0; + bool isBndExist = mf.plot.plots.Count != 0; double pass = 0.5; @@ -735,7 +735,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } @@ -744,7 +744,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } @@ -816,7 +816,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } @@ -825,7 +825,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index 32896ffd2..7c3f8dff0 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -452,7 +452,7 @@ public void BuildTram() mf.tram.tramArr?.Clear(); List tramRef = new List(); - bool isBndExist = mf.bnd.bndArr.Count != 0; + bool isBndExist = mf.plot.plots.Count != 0; double pass = 0.5; double hsin = Math.Sin(abHeading); @@ -495,7 +495,7 @@ public void BuildTram() if (isBndExist) { - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(P1)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(P1)) { mf.tram.tramArr.Add(P1); } @@ -523,7 +523,7 @@ public void BuildTram() if (isBndExist) { - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(P1)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(P1)) { mf.tram.tramArr.Add(P1); } @@ -538,7 +538,7 @@ public void BuildTram() tramRef?.Clear(); //outside tram - if (mf.bnd.bndArr.Count == 0 || mf.tram.passes != 0) + if (mf.plot.plots.Count == 0 || mf.tram.passes != 0) { //return; } diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index 0a4e18dcf..c19551b06 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -4,38 +4,13 @@ namespace AgOpenGPS { - public partial class CBoundary + public partial class CPlot { - //copy of the mainform address - private readonly FormGPS mf; - - /// - /// array of boundaries - /// - /// - public List bndArr = new List(); public List bndBeingMadePts = new List(128); - private readonly double scanWidth, boxLength; - public double createBndOffset; public bool isBndBeingMade; - public bool isDrawRightSide = true, isOkToAddPoints = false; - //constructor - public CBoundary(FormGPS _f) - { - mf = _f; - boundarySelected = 0; - scanWidth = 1.0; - boxLength = 2000; - - turnSelected = 0; - - isOn = false; - isToolUp = true; - } - // the list of possible bounds points public List bndClosestList = new List(); @@ -52,13 +27,13 @@ public CBoundary(FormGPS _f) public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) { //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (bndArr[0].IsPointInsideBoundaryArea(testPoint)) + if (plots[0].IsPointInsideBoundaryArea(testPoint)) { - for (int i = 1; i < bndArr.Count; i++) + for (int i = 1; i < plots.Count; i++) { //make sure not inside a non drivethru boundary - if (bndArr[i].isDriveThru) continue; - if (bndArr[i].IsPointInsideBoundaryArea(testPoint)) + if (plots[i].isDriveThru) continue; + if (plots[i].IsPointInsideBoundaryArea(testPoint)) { return false; } @@ -74,31 +49,6 @@ public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) { - //heading is based on ABLine, average Curve, and going same direction as AB or not - //Draw a bounding box to determine if points are in it - - //if (mf.yt.isYouTurnTriggered || mf.yt.isEnteringDriveThru || mf.yt.isExitingDriveThru) - //{ - // boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * -scanWidth); //subtract if positive - // boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * -scanWidth); - - // boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); - // boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); - - // boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); - // boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); - - // boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); - // boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); - - // boxA.easting -= (Math.Sin(headAB) * boxLength); - // boxA.northing -= (Math.Cos(headAB) * boxLength); - - // boxB.easting -= (Math.Sin(headAB) * boxLength); - // boxB.northing -= (Math.Cos(headAB) * boxLength); - //} - //else - { boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); @@ -118,30 +68,30 @@ public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) //determine if point is inside bounding box bndClosestList.Clear(); vec4 inBox; - for (int i = 0; i < bndArr.Count; i++) + for (int i = 0; i < plots.Count; i++) { //skip the drive thru - if (bndArr[i].isDriveThru) continue; + if (plots[i].isDriveThru) continue; - ptCount = bndArr[i].bndLine.Count; + ptCount = plots[i].bndLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (bndArr[i].bndLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (bndArr[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (plots[i].bndLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (plots[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (bndArr[i].bndLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (bndArr[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (plots[i].bndLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (plots[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (bndArr[i].bndLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (bndArr[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (plots[i].bndLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (plots[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (bndArr[i].bndLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (bndArr[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (plots[i].bndLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (plots[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = bndArr[i].bndLine[p].easting; - inBox.northing = bndArr[i].bndLine[p].northing; - inBox.heading = bndArr[i].bndLine[p].heading; + inBox.easting = plots[i].bndLine[p].easting; + inBox.northing = plots[i].bndLine[p].northing; + inBox.heading = plots[i].bndLine[p].heading; inBox.index = i; //which boundary/headland is it from @@ -179,9 +129,9 @@ public void DrawBoundaryLines() //draw the boundaries GL.Color3(0.75f, 0.5f, 0.250f); - for (int i = 0; i < bndArr.Count; i++) + for (int i = 0; i < plots.Count; i++) { - bndArr[i].DrawBoundaryLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); + plots[i].DrawBoundaryLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); } if (bndBeingMadePts.Count > 0) @@ -248,4 +198,4 @@ public void DrawClosestPoint() GL.End(); } } -} \ No newline at end of file +} diff --git a/SourceCode/GPS/Classes/CBoundaryLines.cs b/SourceCode/GPS/Classes/CBoundaryLines.cs index 38229fc9c..42f16d30b 100644 --- a/SourceCode/GPS/Classes/CBoundaryLines.cs +++ b/SourceCode/GPS/Classes/CBoundaryLines.cs @@ -1,31 +1,14 @@ -using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; +using System.Linq; +using OpenTK.Graphics.OpenGL; using System; using System.Collections.Generic; namespace AgOpenGPS { - public partial class CBoundaryLines + public partial class CPlots { - //list of coordinates of boundary line - public List bndLine = new List(128); - public List bndLineEar = new List(128); - public List hdLine = new List(128); - public List turnLine = new List(128); - - //area variable - public double area; - - //boundary variables - public bool isDriveAround, isDriveThru; - - //constructor - public CBoundaryLines() - { - area = 0; - isDriveAround = false; - isDriveThru = false; - } - public void CalculateBoundaryHeadings() { //to calc heading based on next and previous points to give an average heading. @@ -196,7 +179,7 @@ public bool IsPointInsideBoundaryEar(vec3 testPoint) } return result; } - + public bool IsPointInsideBoundaryEar(vec2 testPoint) { bool result = false; @@ -277,4 +260,4 @@ public bool CalculateBoundaryArea(int idx) return isClockwise; } } -} \ No newline at end of file +} diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index f14c244c6..be15b4f9e 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -924,7 +924,7 @@ public void StopContourLine(vec3 pivot) //build contours for boundaries public void BuildBoundaryContours(int pass, int spacingInt) { - if (mf.bnd.bndArr.Count == 0) + if (mf.plot.plots.Count == 0) { mf.TimedMessageBox(1500, "Boundary Contour Error", "No Boundaries Made"); return; @@ -950,10 +950,10 @@ public void BuildBoundaryContours(int pass, int spacingInt) //totalHeadWidth = (mf.tool.toolWidth - mf.tool.toolOverlap) * 0.5 + 0.2 + (mf.tool.toolWidth - mf.tool.toolOverlap); - for (int j = 0; j < mf.bnd.bndArr.Count; j++) + for (int j = 0; j < mf.plot.plots.Count; j++) { //count the points from the boundary - int ptCount = mf.bnd.bndArr[j].bndLine.Count; + int ptCount = mf.plot.plots[j].bndLine.Count; ptList = new List(128); stripList.Add(ptList); @@ -961,9 +961,9 @@ public void BuildBoundaryContours(int pass, int spacingInt) for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.bnd.bndArr[j].bndLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.bnd.bndArr[j].bndLine[i].heading) * totalHeadWidth); - point.northing = mf.bnd.bndArr[j].bndLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.bnd.bndArr[j].bndLine[i].heading) * totalHeadWidth); - point.heading = mf.bnd.bndArr[j].bndLine[i].heading - Math.PI; + point.easting = mf.plot.plots[j].bndLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.plot.plots[j].bndLine[i].heading) * totalHeadWidth); + point.northing = mf.plot.plots[j].bndLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.plot.plots[j].bndLine[i].heading) * totalHeadWidth); + point.heading = mf.plot.plots[j].bndLine[i].heading - Math.PI; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if inside actual field boundary diff --git a/SourceCode/GPS/Classes/CFieldData.cs b/SourceCode/GPS/Classes/CFieldData.cs index aed0102cb..d76e520ce 100644 --- a/SourceCode/GPS/Classes/CFieldData.cs +++ b/SourceCode/GPS/Classes/CFieldData.cs @@ -132,14 +132,14 @@ public CFieldData(FormGPS _f) public void UpdateFieldBoundaryGUIAreas() { - if (mf.bnd.bndArr.Count > 0) + if (mf.plot.plots.Count > 0) { - areaOuterBoundary = mf.bnd.bndArr[0].area; + areaOuterBoundary = mf.plot.plots[0].area; areaBoundaryOuterLessInner = areaOuterBoundary; - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { - areaBoundaryOuterLessInner -= mf.bnd.bndArr[i].area; + areaBoundaryOuterLessInner -= mf.plot.plots[i].area; } } else diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index 4e7febefb..ca3060637 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -2,7 +2,7 @@ namespace AgOpenGPS { - public partial class CBoundary + public partial class CPlot { public bool isOn; public double leftToolDistance; @@ -37,7 +37,7 @@ public void SetHydPosition() public void WhereAreToolCorners() { - if (bndArr.Count > 0 && bndArr[0].hdLine.Count > 0) + if (plots.Count > 0 && plots[0].hdLine.Count > 0) { bool isLeftInWk, isRightInWk = true; @@ -48,8 +48,8 @@ public void WhereAreToolCorners() if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftInWk = bndArr[0].IsPointInHeadArea(mf.section[j].leftPoint); - isRightInWk = bndArr[0].IsPointInHeadArea(mf.section[j].rightPoint); + isLeftInWk = plots[0].IsPointInHeadArea(mf.section[j].leftPoint); + isRightInWk = plots[0].IsPointInHeadArea(mf.section[j].rightPoint); //save left side mf.tool.isLeftSideInHeadland = !isLeftInWk; @@ -62,7 +62,7 @@ public void WhereAreToolCorners() { //grab the right of previous section, its the left of this section isLeftInWk = isRightInWk; - isRightInWk = bndArr[0].IsPointInHeadArea(mf.section[j].rightPoint); + isRightInWk = plots[0].IsPointInHeadArea(mf.section[j].rightPoint); mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } @@ -84,7 +84,7 @@ public void WhereAreToolCorners() public void WhereAreToolLookOnPoints() { - if (bndArr.Count > 0 && bndArr[0].hdLine.Count > 0) + if (plots.Count > 0 && plots[0].hdLine.Count > 0) { vec3 toolFix = mf.toolPos; double sinAB = Math.Sin(toolFix.heading); @@ -128,10 +128,11 @@ public void WhereAreToolLookOnPoints() public void DrawHeadLines() { - for (int i = 0; i < bndArr.Count; i++) + for (int i = 0; i < plots.Count; i++) { - if (bndArr[i].hdLine.Count > 0) bndArr[i].DrawHeadLine(); + if (plots[i].hdLine.Count > 0) plots[i].DrawHeadLine(); } + //GL.LineWidth(4.0f); //GL.Color3(0.9219f, 0.2f, 0.970f); @@ -155,11 +156,11 @@ public void DrawHeadLines() public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add - if (bndArr.Count > 0 && bndArr[0].IsPointInHeadArea(pt)) + if (plots.Count > 0 && plots[0].IsPointInHeadArea(pt)) { - for (int b = 1; b < bndArr.Count; b++) + for (int b = 1; b < plots.Count; b++) { - if (bndArr[b].IsPointInHeadArea(pt)) + if (plots[b].IsPointInHeadArea(pt)) { //point is in an inner turn area but inside outer return false; diff --git a/SourceCode/GPS/Classes/CHeadLines.cs b/SourceCode/GPS/Classes/CHeadLines.cs index c933932a9..1fc4ea59f 100644 --- a/SourceCode/GPS/Classes/CHeadLines.cs +++ b/SourceCode/GPS/Classes/CHeadLines.cs @@ -2,7 +2,7 @@ namespace AgOpenGPS { - public partial class CBoundaryLines + public partial class CPlots { public bool IsPointInHeadArea(vec2 testPoint) { diff --git a/SourceCode/GPS/Classes/CPlot.cs b/SourceCode/GPS/Classes/CPlot.cs new file mode 100644 index 000000000..af734e7a7 --- /dev/null +++ b/SourceCode/GPS/Classes/CPlot.cs @@ -0,0 +1,35 @@ +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; + +namespace AgOpenGPS +{ + public partial class CPlot + { + //copy of the mainform address + private readonly FormGPS mf; + + /// + /// array of boundaries + /// + /// + public List plots = new List(); + + private readonly double scanWidth, boxLength; + + public bool isDrawRightSide = true, isOkToAddPoints = false; + //constructor + public CPlot(FormGPS _f) + { + mf = _f; + boundarySelected = 0; + scanWidth = 1.0; + boxLength = 2000; + + turnSelected = 0; + + isOn = false; + isToolUp = true; + } + } +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CPlots.cs b/SourceCode/GPS/Classes/CPlots.cs new file mode 100644 index 000000000..879e18796 --- /dev/null +++ b/SourceCode/GPS/Classes/CPlots.cs @@ -0,0 +1,30 @@ +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; + +namespace AgOpenGPS +{ + public partial class CPlots + { + //list of coordinates of boundary line + public List bndLine = new List(128); + public List bndLineEar = new List(128); + public List hdLine = new List(128); + public List turnLine = new List(128); + + //area variable + public double area; + + //boundary variables + public bool isDriveAround, isDriveThru; + + //constructor + public CPlots() + { + area = 0; + isDriveAround = false; + isDriveThru = false; + } + + } +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CTram.cs b/SourceCode/GPS/Classes/CTram.cs index e1dfbe4de..7b6455fa3 100644 --- a/SourceCode/GPS/Classes/CTram.cs +++ b/SourceCode/GPS/Classes/CTram.cs @@ -84,7 +84,7 @@ public void DrawTram() public void BuildTramBnd() { - bool isBndExist = mf.bnd.bndArr.Count != 0; + bool isBndExist = mf.plot.plots.Count != 0; if (isBndExist) { @@ -101,7 +101,7 @@ public void BuildTramBnd() private void CreateBndInnerTramTrack() { //count the points from the boundary - int ptCount = mf.bnd.bndArr[0].bndLine.Count; + int ptCount = mf.plot.plots[0].bndLine.Count; tramBndInnerArr?.Clear(); //outside point @@ -113,18 +113,18 @@ private void CreateBndInnerTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.bnd.bndArr[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.easting = mf.plot.plots[0].bndLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); - pt3.northing = mf.bnd.bndArr[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.northing = mf.plot.plots[0].bndLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.bnd.bndArr[0].bndLine[j].northing, mf.bnd.bndArr[0].bndLine[j].easting); + mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); if (check < distSq) { Add = false; @@ -149,7 +149,7 @@ private void CreateBndInnerTramTrack() public void CreateBndOuterTramTrack() { //count the points from the boundary - int ptCount = mf.bnd.bndArr[0].bndLine.Count; + int ptCount = mf.plot.plots[0].bndLine.Count; tramBndOuterArr?.Clear(); //outside point @@ -161,18 +161,18 @@ public void CreateBndOuterTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.bnd.bndArr[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.easting = mf.plot.plots[0].bndLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); - pt3.northing = mf.bnd.bndArr[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.northing = mf.plot.plots[0].bndLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.bnd.bndArr[0].bndLine[j].northing, mf.bnd.bndArr[0].bndLine[j].easting); + mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); if (check < distSq) { Add = false; diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index d6fdec0d7..30bdda5ea 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -4,7 +4,7 @@ namespace AgOpenGPS { - public partial class CBoundary + public partial class CPlot { // the list of possible bounds points public List turnClosestList = new List(); @@ -31,13 +31,13 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (bndArr[0].IsPointInTurnWorkArea(pt)) + if (plots[0].IsPointInTurnWorkArea(pt)) { - for (int t = 1; t < bndArr.Count; t++) + for (int t = 1; t < plots.Count; t++) { - if (bndArr[t].isDriveThru) continue; - if (bndArr[t].isDriveAround) continue; - if (bndArr[t].IsPointInTurnWorkArea(pt)) + if (plots[t].isDriveThru) continue; + if (plots[t].isDriveAround) continue; + if (plots[t].IsPointInTurnWorkArea(pt)) { isFound = true; closestTurnNum = t; @@ -88,25 +88,25 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB vec4 inBox; - int ptCount = bndArr[closestTurnNum].turnLine.Count; + int ptCount = plots[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (plots[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (plots[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (plots[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (plots[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (plots[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (plots[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (plots[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (plots[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = bndArr[closestTurnNum].turnLine[p].easting; - inBox.northing = bndArr[closestTurnNum].turnLine[p].northing; - inBox.heading = bndArr[closestTurnNum].turnLine[p].heading; + inBox.easting = plots[closestTurnNum].turnLine[p].easting; + inBox.northing = plots[closestTurnNum].turnLine[p].northing; + inBox.heading = plots[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -142,26 +142,26 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB //determine if point is inside bounding box of the 1 turn chosen above turnClosestList.Clear(); - ptCount = bndArr[closestTurnNum].turnLine.Count; + ptCount = plots[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (plots[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (plots[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (plots[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (plots[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (plots[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (plots[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (plots[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (plots[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = bndArr[closestTurnNum].turnLine[p].easting; - inBox.northing = bndArr[closestTurnNum].turnLine[p].northing; - inBox.heading = bndArr[closestTurnNum].turnLine[p].heading; + inBox.easting = plots[closestTurnNum].turnLine[p].easting; + inBox.northing = plots[closestTurnNum].turnLine[p].northing; + inBox.heading = plots[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -203,7 +203,7 @@ public void BuildTurnLines() //update the GUI values for boundaries mf.fd.UpdateFieldBoundaryGUIAreas(); - if (bndArr.Count == 0) + if (plots.Count == 0) { //mf.TimedMessageBox(1500, " No Boundaries", "No Turn Lines Made"); return; @@ -216,29 +216,29 @@ public void BuildTurnLines() double totalHeadWidth = mf.yt.uturnDistanceFromBoundary; //inside boundaries - for (int j = 0; j < bndArr.Count; j++) + for (int j = 0; j < plots.Count; j++) { - bndArr[j].turnLine.Clear(); - if (bndArr[j].isDriveThru || bndArr[j].isDriveAround) continue; + plots[j].turnLine.Clear(); + if (plots[j].isDriveThru || plots[j].isDriveAround) continue; - int ptCount = bndArr[j].bndLine.Count; + int ptCount = plots[j].bndLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point outside the boundary - point.easting = bndArr[j].bndLine[i].easting + (-Math.Sin(glm.PIBy2 + bndArr[j].bndLine[i].heading) * totalHeadWidth); - point.northing = bndArr[j].bndLine[i].northing + (-Math.Cos(glm.PIBy2 + bndArr[j].bndLine[i].heading) * totalHeadWidth); - point.heading = bndArr[j].bndLine[i].heading; + point.easting = plots[j].bndLine[i].easting + (-Math.Sin(glm.PIBy2 + plots[j].bndLine[i].heading) * totalHeadWidth); + point.northing = plots[j].bndLine[i].northing + (-Math.Cos(glm.PIBy2 + plots[j].bndLine[i].heading) * totalHeadWidth); + point.heading = plots[j].bndLine[i].heading; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == bndArr[j].IsPointInsideBoundaryEar(point)) + if (j == 0 == plots[j].IsPointInsideBoundaryEar(point)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); - bndArr[j].turnLine.Add(tPnt); + plots[j].turnLine.Add(tPnt); } } - bndArr[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); + plots[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); } } @@ -248,17 +248,17 @@ public void DrawTurnLines() GL.Color3(0.3555f, 0.6232f, 0.20f); //GL.PointSize(2); - for (int i = 0; i < bndArr.Count; i++) + for (int i = 0; i < plots.Count; i++) { - if (bndArr[i].isDriveAround) continue; + if (plots[i].isDriveAround) continue; //turnArr[i].DrawTurnLine(); { ////draw the turn line oject - int ptCount = bndArr[i].turnLine.Count; + int ptCount = plots[i].turnLine.Count; if (ptCount < 1) continue; GL.Begin(PrimitiveType.LineLoop); - for (int h = 0; h < ptCount; h++) GL.Vertex3(bndArr[i].turnLine[h].easting, bndArr[i].turnLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(plots[i].turnLine[h].easting, plots[i].turnLine[h].northing, 0); GL.End(); } } diff --git a/SourceCode/GPS/Classes/CTurnLines.cs b/SourceCode/GPS/Classes/CTurnLines.cs index 8b37faa76..db8e8cf07 100644 --- a/SourceCode/GPS/Classes/CTurnLines.cs +++ b/SourceCode/GPS/Classes/CTurnLines.cs @@ -3,7 +3,7 @@ namespace AgOpenGPS { - public partial class CBoundaryLines + public partial class CPlots { public void CalculateTurnHeadings() { diff --git a/SourceCode/GPS/Classes/CVehicle.cs b/SourceCode/GPS/Classes/CVehicle.cs index 977b12296..e2076105b 100644 --- a/SourceCode/GPS/Classes/CVehicle.cs +++ b/SourceCode/GPS/Classes/CVehicle.cs @@ -408,9 +408,9 @@ public void DrawVehicle() GL.End(); } - if (mf.bnd.isBndBeingMade) + if (mf.plot.isBndBeingMade) { - if (mf.bnd.isDrawRightSide) + if (mf.plot.isDrawRightSide) { GL.LineWidth(2); GL.Color3(0.0, 1.270, 0.0); @@ -418,8 +418,8 @@ public void DrawVehicle() { GL.Vertex3(0.0, 0, 0); GL.Color3(1.270, 1.220, 0.20); - GL.Vertex3(mf.bnd.createBndOffset, 0, 0); - GL.Vertex3(mf.bnd.createBndOffset * 0.75, 0.25, 0); + GL.Vertex3(mf.plot.createBndOffset, 0, 0); + GL.Vertex3(mf.plot.createBndOffset * 0.75, 0.25, 0); } GL.End(); } @@ -433,8 +433,8 @@ public void DrawVehicle() { GL.Vertex3(0.0, 0, 0); GL.Color3(1.270, 1.220, 0.20); - GL.Vertex3(-mf.bnd.createBndOffset, 0, 0); - GL.Vertex3(-mf.bnd.createBndOffset * 0.75, 0.25, 0); + GL.Vertex3(-mf.plot.createBndOffset, 0, 0); + GL.Vertex3(-mf.plot.createBndOffset * 0.75, 0.25, 0); } GL.End(); } diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index b6a82524e..4e7b9b385 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -115,7 +115,7 @@ public bool FindCurveTurnPoints() //for each point in succession keep going till a turnLine is found. for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) { - if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (!mf.plot.plots[0].IsPointInTurnWorkArea(mf.curve.curList[j])) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -125,12 +125,12 @@ public bool FindCurveTurnPoints() goto CrossingFound; } - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndArr[i].isDriveThru) continue; - if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (mf.plot.plots[i].isDriveThru) continue; + if (mf.plot.plots[i].isDriveAround) continue; + if (mf.plot.plots[i].IsPointInTurnWorkArea(mf.curve.curList[j])) { crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -152,7 +152,7 @@ public bool FindCurveTurnPoints() for (int j = mf.curve.currentLocationIndex; j > 0; j--) { - if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (!mf.plot.plots[0].IsPointInTurnWorkArea(mf.curve.curList[j])) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; @@ -162,12 +162,12 @@ public bool FindCurveTurnPoints() goto CrossingFound; } - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndArr[i].isDriveThru) continue; - if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (mf.plot.plots[i].isDriveThru) continue; + if (mf.plot.plots[i].isDriveAround) continue; + if (mf.plot.plots[i].IsPointInTurnWorkArea(mf.curve.curList[j])) { crossingCurvePoint.easting = mf.curve.curList[j].easting; crossingCurvePoint.northing = mf.curve.curList[j].northing; @@ -191,17 +191,17 @@ public bool FindCurveTurnPoints() return false; } - int curTurnLineCount = mf.bnd.bndArr[turnNum].turnLine.Count; + int curTurnLineCount = mf.plot.plots[turnNum].turnLine.Count; //possible points close to AB Curve point List turnLineCloseList = new List(); for (int j = 0; j < curTurnLineCount; j++) { - if ((mf.bnd.bndArr[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 - && (mf.bnd.bndArr[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 - && (mf.bnd.bndArr[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 - && (mf.bnd.bndArr[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) + if ((mf.plot.plots[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 + && (mf.plot.plots[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 + && (mf.plot.plots[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 + && (mf.plot.plots[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) { turnLineCloseList.Add(j); } @@ -211,8 +211,8 @@ public bool FindCurveTurnPoints() curTurnLineCount = turnLineCloseList.Count; for (int i = 0; i < curTurnLineCount; i++) { - dist1 = glm.Distance(mf.bnd.bndArr[turnNum].turnLine[turnLineCloseList[i]].easting, - mf.bnd.bndArr[turnNum].turnLine[turnLineCloseList[i]].northing, + dist1 = glm.Distance(mf.plot.plots[turnNum].turnLine[turnLineCloseList[i]].easting, + mf.plot.plots[turnNum].turnLine[turnLineCloseList[i]].northing, crossingCurvePoint.easting, crossingCurvePoint.northing); if (dist1 < dist2) { @@ -222,9 +222,9 @@ public bool FindCurveTurnPoints() } //fill up the coords - crossingTurnLinePoint.easting = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].easting; - crossingTurnLinePoint.northing = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].northing; - crossingTurnLinePoint.heading = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].heading; + crossingTurnLinePoint.easting = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].easting; + crossingTurnLinePoint.northing = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].northing; + crossingTurnLinePoint.heading = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].heading; return crossingCurvePoint.easting != -20000 && crossingCurvePoint.easting != -20000; } @@ -387,12 +387,12 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) vec3 onPurePoint = new vec3(mf.ABLine.rEastAB, mf.ABLine.rNorthAB, 0); //how far are we from any turn boundary - mf.bnd.FindClosestTurnPoint(isYouTurnRight, onPurePoint, headAB); + mf.plot.FindClosestTurnPoint(isYouTurnRight, onPurePoint, headAB); //or did we lose the turnLine - we are on the highway cuz we left the outer/inner turn boundary - if ((int)mf.bnd.closestTurnPt.easting != -20000) + if ((int)mf.plot.closestTurnPt.easting != -20000) { - mf.distancePivotToTurnLine = glm.Distance(mf.pivotAxlePos, mf.bnd.closestTurnPt); + mf.distancePivotToTurnLine = glm.Distance(mf.pivotAxlePos, mf.plot.closestTurnPt); } else { @@ -401,7 +401,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) } //delta between AB heading and boundary closest point heading - boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(mf.bnd.closestTurnPt.heading - headAB) - Math.PI); + boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(mf.plot.closestTurnPt.heading - headAB) - Math.PI); boundaryAngleOffPerpendicular -= glm.PIBy2; boundaryAngleOffPerpendicular *= -1; if (boundaryAngleOffPerpendicular > 1.25) boundaryAngleOffPerpendicular = 1.25; @@ -584,15 +584,15 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; + if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; if (isOutOfBounds) break; - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndArr[i].isDriveThru) continue; - if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.plot.plots[i].isDriveThru) continue; + if (mf.plot.plots[i].isDriveAround) continue; + if (mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; @@ -644,16 +644,16 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; + if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; if (isOutOfBounds) break; - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndArr[i].isDriveThru) continue; - if (mf.bnd.bndArr[i].isDriveAround) continue; - if (!mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.plot.plots[i].isDriveThru) continue; + if (mf.plot.plots[i].isDriveAround) continue; + if (!mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; @@ -852,18 +852,18 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) + if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; } - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndArr[i].isDriveThru) continue; - if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.plot.plots[i].isDriveThru) continue; + if (mf.plot.plots[i].isDriveAround) continue; + if (mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index a609102c7..0055a0d97 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -355,7 +355,7 @@ private void btnAutoYouTurn_Click(object sender, EventArgs e) { yt.isTurnCreationTooClose = false; - if (bnd.bndArr.Count == 0) + if (plot.plots.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1494,7 +1494,7 @@ private void BtnMakeLinesFromBoundary_Click(object sender, EventArgs e) return; } - if (bnd.bndArr.Count == 0) + if (plot.plots.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1549,10 +1549,10 @@ private void cboxpRowWidth_SelectedIndexChanged(object sender, EventArgs e) private void btnHeadlandOnOff_Click(object sender, EventArgs e) { - if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) + if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - bnd.isOn = !bnd.isOn; - if (bnd.isOn) + plot.isOn = !plot.isOn; + if (plot.isOn) { btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHydLift.Visible = true; @@ -1563,9 +1563,9 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; } } - else bnd.isOn = false; + else plot.isOn = false; - if (!bnd.isOn) + if (!plot.isOn) { p_239.pgn[p_239.hydLift] = 0; vehicle.isHydLiftOn = false; @@ -1577,7 +1577,7 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) private void btnHydLift_Click(object sender, EventArgs e) { - if (bnd.isOn) + if (plot.isOn) { vehicle.isHydLiftOn = !vehicle.isHydLiftOn; if (vehicle.isHydLiftOn) @@ -1959,7 +1959,7 @@ private void tramLinesMenuField_Click(object sender, EventArgs e) } private void headlandToolStripMenuItem_Click(object sender, EventArgs e) { - if (bnd.bndArr.Count == 0) + if (plot.plots.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1974,9 +1974,9 @@ public void GetHeadland() form.ShowDialog(); } - if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) + if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - bnd.isOn = true; + plot.isOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -1984,7 +1984,7 @@ public void GetHeadland() } else { - bnd.isOn = false; + plot.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index 6121798e0..8721b187b 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -59,7 +59,7 @@ private void UpdateChart() Font backupfont = new Font(Font.FontFamily, 18F, FontStyle.Bold); - for (int i = 0; i < mf.bnd.bndArr.Count && i < 6; i++) + for (int i = 0; i < mf.plot.plots.Count && i < 6; i++) { //outer inner Button a = new Button @@ -118,11 +118,11 @@ private void UpdateChart() if (i == 0) { //cc.Text = "Outer"; - mf.bnd.bndArr[i].isDriveThru = false; - mf.bnd.bndArr[i].isDriveAround = false; + mf.plot.plots[i].isDriveThru = false; + mf.plot.plots[i].isDriveAround = false; a.Text = string.Format(gStr.gsOuter); //a.Font = backupfont; - d.Text = mf.bnd.bndArr[i].isDriveThru ? "--" : "--"; + d.Text = mf.plot.plots[i].isDriveThru ? "--" : "--"; d.Enabled = false; d.Anchor = System.Windows.Forms.AnchorStyles.None; a.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -135,7 +135,7 @@ private void UpdateChart() inner += 1; a.Text = string.Format(gStr.gsInner + " {0}", inner); //a.Font = backupfont; - d.Text = mf.bnd.bndArr[i].isDriveThru ? "Yes" : "No"; + d.Text = mf.plot.plots[i].isDriveThru ? "Yes" : "No"; d.Anchor = System.Windows.Forms.AnchorStyles.None; a.Anchor = System.Windows.Forms.AnchorStyles.None; b.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -144,14 +144,14 @@ private void UpdateChart() if (mf.isMetric) { - b.Text = Math.Round(mf.bnd.bndArr[i].area * 0.0001, 2).ToString() + " Ha"; + b.Text = Math.Round(mf.plot.plots[i].area * 0.0001, 2).ToString() + " Ha"; } else { - b.Text = Math.Round(mf.bnd.bndArr[i].area * 0.000247105, 2) + " Ac"; + b.Text = Math.Round(mf.plot.plots[i].area * 0.000247105, 2) + " Ac"; } - if (Selectedreset == false && i == mf.bnd.boundarySelected) + if (Selectedreset == false && i == mf.plot.boundarySelected) { a.ForeColor = Color.OrangeRed; b.ForeColor = Color.OrangeRed; @@ -168,9 +168,9 @@ private void DriveThru_Click(object sender, EventArgs e) { if (sender is Button b) { - mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveThru = !mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveThru; + mf.plot.plots[Convert.ToInt32(b.Name)].isDriveThru = !mf.plot.plots[Convert.ToInt32(b.Name)].isDriveThru; UpdateChart(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); } } @@ -178,7 +178,7 @@ private void DriveAround_Click(object sender, EventArgs e) { if (sender is Button b) { - mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveAround = !mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveAround; + mf.plot.plots[Convert.ToInt32(b.Name)].isDriveAround = !mf.plot.plots[Convert.ToInt32(b.Name)].isDriveAround; UpdateChart(); } } @@ -188,16 +188,16 @@ private void B_Click(object sender, EventArgs e) if (sender is Button b) { - mf.bnd.boundarySelected = Convert.ToInt32(b.Name); + mf.plot.boundarySelected = Convert.ToInt32(b.Name); - if (mf.bnd.boundarySelected == 0 && mf.bnd.bndArr.Count > 1) + if (mf.plot.boundarySelected == 0 && mf.plot.plots.Count > 1) { return; } Selectedreset = false; - if (mf.bnd.bndArr.Count > mf.bnd.boundarySelected) + if (mf.plot.plots.Count > mf.plot.boundarySelected) { btnDelete.Enabled = true; } @@ -213,7 +213,7 @@ private void B_Click(object sender, EventArgs e) private void btnSerialCancel_Click(object sender, EventArgs e) { - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; } private void btnDelete_Click(object sender, EventArgs e) @@ -229,17 +229,17 @@ private void btnDelete_Click(object sender, EventArgs e) btnDelete.Enabled = false; - if (mf.bnd.bndArr.Count > mf.bnd.boundarySelected) + if (mf.plot.plots.Count > mf.plot.boundarySelected) { - mf.bnd.bndArr.RemoveAt(mf.bnd.boundarySelected); + mf.plot.plots.RemoveAt(mf.plot.boundarySelected); } mf.FileSaveBoundary(); - mf.bnd.boundarySelected = -1; + mf.plot.boundarySelected = -1; Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); UpdateChart(); } else @@ -250,13 +250,13 @@ private void btnDelete_Click(object sender, EventArgs e) private void ResetAllBoundary() { - mf.bnd.bndArr.Clear(); + mf.plot.plots.Clear(); mf.FileSaveBoundary(); tableLayoutPanel1.Controls.Clear(); tableLayoutPanel1.RowStyles.Clear(); UpdateChart(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); btnDelete.Enabled = false; } @@ -282,10 +282,10 @@ private void btnDeleteAll_Click(object sender, EventArgs e) ResetAllBoundary(); - mf.bnd.boundarySelected = -1; + mf.plot.boundarySelected = -1; Selectedreset = true; - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; mf.fd.UpdateFieldBoundaryGUIAreas(); } else @@ -297,7 +297,7 @@ private void btnDeleteAll_Click(object sender, EventArgs e) private void btnReturn_Click(object sender, EventArgs e) { - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; panelMain.Visible = true; panelChoose.Visible = false; @@ -310,7 +310,7 @@ private void btnReturn_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e) { - mf.bnd.boundarySelected = mf.bnd.bndArr.Count; + mf.plot.boundarySelected = mf.plot.plots.Count; Selectedreset = false; @@ -353,7 +353,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) { if (button.Name == "btnLoadMultiBoundaryFromGE") ResetAllBoundary(); - else i = mf.bnd.boundarySelected; + else i = mf.plot.boundarySelected; try { @@ -394,7 +394,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) //at least 3 points if (numberSets.Length > 2) { - CBoundaryLines New = new CBoundaryLines(); + CPlots New = new CPlots(); foreach (string item in numberSets) { @@ -408,10 +408,10 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) New.bndLine.Add(new vec3(easting, norting, 0)); } - New.CalculateBoundaryArea(mf.bnd.boundarySelected); + New.CalculateBoundaryArea(mf.plot.boundarySelected); New.FixBoundaryLine(i); - mf.bnd.bndArr.Add(New); + mf.plot.plots.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); @@ -431,7 +431,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) } } mf.FileSaveBoundary(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); mf.btnMakeLinesFromBoundary.Visible = true; mf.fd.UpdateFieldBoundaryGUIAreas(); UpdateChart(); @@ -442,7 +442,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) } } } - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; panelMain.Visible = true; panelChoose.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 3be336c6b..2d8a3f2a0 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -27,34 +27,34 @@ public FormBoundaryPlayer(Form callingForm) private void btnStop_Click(object sender, EventArgs e) { - if (mf.bnd.bndBeingMadePts.Count > 2) + if (mf.plot.bndBeingMadePts.Count > 2) { - CBoundaryLines New = new CBoundaryLines(); + CPlots New = new CPlots(); - for (int i = 0; i < mf.bnd.bndBeingMadePts.Count; i++) + for (int i = 0; i < mf.plot.bndBeingMadePts.Count; i++) { - New.bndLine.Add(mf.bnd.bndBeingMadePts[i]); + New.bndLine.Add(mf.plot.bndBeingMadePts[i]); } - New.CalculateBoundaryArea(mf.bnd.boundarySelected); - New.FixBoundaryLine(mf.bnd.boundarySelected); + New.CalculateBoundaryArea(mf.plot.boundarySelected); + New.FixBoundaryLine(mf.plot.boundarySelected); - mf.bnd.bndArr.Add(New); + mf.plot.plots.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); } //stop it all for adding - mf.bnd.isOkToAddPoints = false; - mf.bnd.isBndBeingMade = false; + mf.plot.isOkToAddPoints = false; + mf.plot.isBndBeingMade = false; //turn lines made from boundaries mf.CalculateMinMax(); mf.FileSaveBoundary(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); //mf.hd.BuildSingleSpaceHeadLines(); mf.btnMakeLinesFromBoundary.Visible = true; - mf.bnd.bndBeingMadePts.Clear(); + mf.plot.bndBeingMadePts.Clear(); //close window Close(); } @@ -62,9 +62,9 @@ private void btnStop_Click(object sender, EventArgs e) //actually the record button private void btnPausePlay_Click(object sender, EventArgs e) { - if (mf.bnd.isOkToAddPoints) + if (mf.plot.isOkToAddPoints) { - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; btnPausePlay.Image = Properties.Resources.BoundaryRecord; //btnPausePlay.Text = gStr.gsRecord; btnAddPoint.Enabled = true; @@ -72,7 +72,7 @@ private void btnPausePlay_Click(object sender, EventArgs e) } else { - mf.bnd.isOkToAddPoints = true; + mf.plot.isOkToAddPoints = true; btnPausePlay.Image = Properties.Resources.boundaryPause; //btnPausePlay.Text = gStr.gsPause; btnAddPoint.Enabled = false; @@ -86,15 +86,15 @@ private void FormBoundaryPlayer_Load(object sender, EventArgs e) //mf.bnd.isOkToAddPoints = false; nudOffset.Value = (decimal)(mf.tool.toolWidth * 0.5); btnPausePlay.Image = Properties.Resources.BoundaryRecord; - btnLeftRight.Image = mf.bnd.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; - mf.bnd.createBndOffset = (double)nudOffset.Value; - mf.bnd.isBndBeingMade = true; + btnLeftRight.Image = mf.plot.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; + mf.plot.createBndOffset = (double)nudOffset.Value; + mf.plot.isBndBeingMade = true; mf.Focus(); } private void timer1_Tick(object sender, EventArgs e) { - int ptCount = mf.bnd.bndBeingMadePts.Count; + int ptCount = mf.plot.bndBeingMadePts.Count; double area = 0; if (ptCount > 0) @@ -103,7 +103,7 @@ private void timer1_Tick(object sender, EventArgs e) for (int i = 0; i < ptCount; j = i++) { - area += (mf.bnd.bndBeingMadePts[j].easting + mf.bnd.bndBeingMadePts[i].easting) * (mf.bnd.bndBeingMadePts[j].northing - mf.bnd.bndBeingMadePts[i].northing); + area += (mf.plot.bndBeingMadePts[j].easting + mf.plot.bndBeingMadePts[i].easting) * (mf.plot.bndBeingMadePts[j].northing - mf.plot.bndBeingMadePts[i].northing); } area = Math.Abs(area / 2); } @@ -115,27 +115,27 @@ private void timer1_Tick(object sender, EventArgs e) { lblArea.Text = Math.Round(area * 0.000247105, 2) + " Acre"; } - lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); + lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); } private void btnAddPoint_Click(object sender, EventArgs e) { - mf.bnd.isOkToAddPoints = true; + mf.plot.isOkToAddPoints = true; mf.AddBoundaryPoint(); - mf.bnd.isOkToAddPoints = false; - lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); + mf.plot.isOkToAddPoints = false; + lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); mf.Focus(); } private void btnDeleteLast_Click(object sender, EventArgs e) { - int ptCount = mf.bnd.bndBeingMadePts.Count; + int ptCount = mf.plot.bndBeingMadePts.Count; if (ptCount > 0) - mf.bnd.bndBeingMadePts.RemoveAt(ptCount - 1); - lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); + mf.plot.bndBeingMadePts.RemoveAt(ptCount - 1); + lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); mf.Focus(); } @@ -148,8 +148,8 @@ private void btnRestart_Click(object sender, EventArgs e) MessageBoxDefaultButton.Button2); if (result3 == DialogResult.Yes) { - mf.bnd.bndBeingMadePts?.Clear(); - lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); + mf.plot.bndBeingMadePts?.Clear(); + lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); } mf.Focus(); } @@ -158,13 +158,13 @@ private void nudOffset_Click(object sender, EventArgs e) { mf.KeypadToNUD((NumericUpDown)sender, this); btnPausePlay.Focus(); - mf.bnd.createBndOffset = (double)nudOffset.Value; + mf.plot.createBndOffset = (double)nudOffset.Value; } private void btnLeftRight_Click(object sender, EventArgs e) { - mf.bnd.isDrawRightSide = !mf.bnd.isDrawRightSide; - btnLeftRight.Image = mf.bnd.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; + mf.plot.isDrawRightSide = !mf.plot.isDrawRightSide; + btnLeftRight.Image = mf.plot.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; } } } \ No newline at end of file diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 53cce9638..034d3e748 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -125,7 +125,7 @@ private void LoadKMLBoundary(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.bnd.boundarySelected; + i = mf.plot.boundarySelected; try { @@ -166,7 +166,7 @@ private void LoadKMLBoundary(string filename) //at least 3 points if (numberSets.Length > 2) { - CBoundaryLines New = new CBoundaryLines(); + CPlots New = new CPlots(); foreach (string item in numberSets) { @@ -183,10 +183,10 @@ private void LoadKMLBoundary(string filename) } //build the boundary, make sure is clockwise for outer counter clockwise for inner - New.CalculateBoundaryArea(mf.bnd.boundarySelected); + New.CalculateBoundaryArea(mf.plot.boundarySelected); New.FixBoundaryLine(i); - mf.bnd.bndArr.Add(New); + mf.plot.plots.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); @@ -206,7 +206,7 @@ private void LoadKMLBoundary(string filename) } } mf.FileSaveBoundary(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); mf.fd.UpdateFieldBoundaryGUIAreas(); mf.CalculateMinMax(); @@ -221,7 +221,7 @@ private void LoadKMLBoundary(string filename) } } - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; } private void FindLatLon(string filename) @@ -233,7 +233,7 @@ private void FindLatLon(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.bnd.boundarySelected; + i = mf.plot.boundarySelected; try { @@ -312,7 +312,7 @@ private void FindLatLon(string filename) } } - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; } diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index 142809b11..d4d2c5a57 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -187,7 +187,7 @@ public partial class FormGPS : Form /// /// The boundary object /// - public CBoundary bnd; + public CPlot plot; /// /// The internal simulator @@ -366,7 +366,7 @@ public FormGPS() mc = new CModuleComm(); //boundary object - bnd = new CBoundary(this); + plot = new CPlot(this); //nmea simulator built in. sim = new CSim(this); @@ -979,7 +979,7 @@ public void JobClose() pn.fixOffset.northing = 0; //turn off headland - bnd.isOn = false; + plot.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; @@ -993,7 +993,7 @@ public void JobClose() oglZoom.SendToBack(); //clean all the lines - bnd.bndArr.Clear(); + plot.plots.Clear(); panelRight.Enabled = false; FieldMenuButtonEnableDisable(false); diff --git a/SourceCode/GPS/Forms/FormHeadland.cs b/SourceCode/GPS/Forms/FormHeadland.cs index d4bc8e0dc..9091c6a0a 100644 --- a/SourceCode/GPS/Forms/FormHeadland.cs +++ b/SourceCode/GPS/Forms/FormHeadland.cs @@ -54,10 +54,10 @@ private void FormHeadland_Load(object sender, EventArgs e) nudDistance.Value = 0; nudSetDistance.Value = 0; - if (mf.bnd.bndArr[0].hdLine.Count > 0) + if (mf.plot.plots[0].hdLine.Count > 0) { - hdArr = new vec3[mf.bnd.bndArr[0].hdLine.Count]; - mf.bnd.bndArr[0].hdLine.CopyTo(hdArr); + hdArr = new vec3[mf.plot.plots[0].hdLine.Count]; + mf.plot.plots[0].hdLine.CopyTo(hdArr); RebuildHeadLineTemplate(); } else @@ -80,13 +80,13 @@ public void BuildHeadLineTemplateFromBoundary() //outside boundary - count the points from the boundary headLineTemplate.Clear(); - int ptCount = mf.bnd.bndArr[0].bndLine.Count; + int ptCount = mf.plot.plots[0].bndLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.bnd.bndArr[0].bndLine[i].easting; - point.northing = mf.bnd.bndArr[0].bndLine[i].northing; - point.heading = mf.bnd.bndArr[0].bndLine[i].heading; + point.easting = mf.plot.plots[0].bndLine[i].easting; + point.northing = mf.plot.plots[0].bndLine[i].northing; + point.heading = mf.plot.plots[0].bndLine[i].heading; headLineTemplate.Add(point); } @@ -334,7 +334,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) //else lblEnd.Text = end.ToString(); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.plot.DrawBoundaryLines(); int ptCount = hdArr.Length; if (ptCount > 1) @@ -565,7 +565,7 @@ private void timer1_Tick(object sender, EventArgs e) private void btnExit_Click(object sender, EventArgs e) { - mf.bnd.bndArr[0].hdLine?.Clear(); + mf.plot.plots[0].hdLine?.Clear(); //middle points for (int i = 1; i < hdArr.Length; i++) @@ -580,7 +580,7 @@ private void btnExit_Click(object sender, EventArgs e) { if (i == 0) { - mf.bnd.bndArr[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); + mf.plot.plots[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); continue; } delta += (hdArr[i - 1].heading - hdArr[i].heading); @@ -589,7 +589,7 @@ private void btnExit_Click(object sender, EventArgs e) { vec3 pt = new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading); - mf.bnd.bndArr[0].hdLine.Add(pt); + mf.plot.plots[0].hdLine.Add(pt); delta = 0; } } @@ -600,7 +600,7 @@ private void btnExit_Click(object sender, EventArgs e) private void btnTurnOffHeadland_Click(object sender, EventArgs e) { - mf.bnd.bndArr[0].hdLine?.Clear(); + mf.plot.plots[0].hdLine?.Clear(); mf.FileSaveHeadland(); diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 10bc6cb2f..66dab5db2 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -125,7 +125,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) // fd.WorkedAreaRemainPercentage +"\r\n" + // fd.TimeTillFinished + "\r\n" + // fd.WorkRateHectares; - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) lblFieldStatus.Text = fd.AreaBoundaryLessInnersHectares + " " + fd.WorkedAreaRemainHectares + " " + fd.TimeTillFinished + " " + fd.WorkedAreaRemainPercentage+" " @@ -136,7 +136,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) } else //imperial { - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) lblFieldStatus.Text = fd.AreaBoundaryLessInnersAcres + " " + fd.WorkedAreaRemainAcres + " " + fd.TimeTillFinished + " " + fd.WorkedAreaRemainPercentage + " " + fd.WorkedAcres; @@ -498,7 +498,7 @@ public void LoadSettings() if (Properties.Settings.Default.setAS_isAutoSteerAutoOn) btnAutoSteer.Text = "R"; else btnAutoSteer.Text = "M"; - if (bnd.isOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; + if (plot.isOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; else btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnChangeMappingColor.BackColor = sectionColorDay; diff --git a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs index fc1e2270b..b19add630 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs @@ -46,21 +46,21 @@ public FormABDraw(Form callingForm) private void FormABDraw_Load(object sender, EventArgs e) { - int cnt = mf.bnd.bndArr[0].bndLine.Count; + int cnt = mf.plot.plots[0].bndLine.Count; arr = new vec3[cnt * 2]; for (int i = 0; i < cnt; i++) { - arr[i].easting = mf.bnd.bndArr[0].bndLine[i].easting; - arr[i].northing = mf.bnd.bndArr[0].bndLine[i].northing; - arr[i].heading = mf.bnd.bndArr[0].bndLine[i].heading; + arr[i].easting = mf.plot.plots[0].bndLine[i].easting; + arr[i].northing = mf.plot.plots[0].bndLine[i].northing; + arr[i].heading = mf.plot.plots[0].bndLine[i].heading; } for (int i = cnt; i < cnt * 2; i++) { - arr[i].easting = mf.bnd.bndArr[0].bndLine[i - cnt].easting; - arr[i].northing = mf.bnd.bndArr[0].bndLine[i - cnt].northing; - arr[i].heading = mf.bnd.bndArr[0].bndLine[i - cnt].heading; + arr[i].easting = mf.plot.plots[0].bndLine[i - cnt].easting; + arr[i].northing = mf.plot.plots[0].bndLine[i - cnt].northing; + arr[i].heading = mf.plot.plots[0].bndLine[i - cnt].heading; } nudDistance.Value = (decimal)Math.Round(((mf.tool.toolWidth * mf.m2InchOrCm) * 0.5), 0); // @@ -356,7 +356,7 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) { //count the points from the boundary - int ptCount = mf.bnd.bndArr[0].bndLine.Count; + int ptCount = mf.plot.plots[0].bndLine.Count; mf.curve.refList?.Clear(); //outside point @@ -369,20 +369,20 @@ private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.bnd.bndArr[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (moveDist)); + pt3.easting = mf.plot.plots[0].bndLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (moveDist)); - pt3.northing = mf.bnd.bndArr[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (moveDist)); + pt3.northing = mf.plot.plots[0].bndLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (moveDist)); - pt3.heading = mf.bnd.bndArr[0].bndLine[i].heading; + pt3.heading = mf.plot.plots[0].bndLine[i].heading; bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.bnd.bndArr[0].bndLine[j].northing, mf.bnd.bndArr[0].bndLine[j].easting); + mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); if (check < distSq) { Add = false; @@ -669,7 +669,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.plot.DrawBoundaryLines(); //the vehicle GL.PointSize(16.0f); diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index e9d953000..c763d943b 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -338,21 +338,21 @@ private void oglMain_Paint(object sender, PaintEventArgs e) recPath.DrawDubins(); //draw Boundaries - bnd.DrawBoundaryLines(); + plot.DrawBoundaryLines(); //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) { - bnd.DrawTurnLines(); + plot.DrawTurnLines(); } - if (bnd.isOn) + if (plot.isOn) { GL.LineWidth(ABLine.lineWidth); GL.Color3(0.960f, 0.96232f, 0.30f); - for (int i = 0; i < bnd.bndArr.Count; i++) + for (int i = 0; i < plot.plots.Count; i++) { - if (bnd.bndArr[i].hdLine.Count > 0) bnd.bndArr[i].DrawHeadLine(); + if (plot.plots[i].hdLine.Count > 0) plot.plots[i].DrawHeadLine(); } } @@ -416,7 +416,7 @@ private void oglMain_Paint(object sender, PaintEventArgs e) if ((ahrs.imuRoll != 88888)) DrawRollBar(); - if (bnd.bndArr.Count > 0 && yt.isYouTurnBtnOn) DrawUTurnBtn(); + if (plot.plots.Count > 0 && yt.isYouTurnBtnOn) DrawUTurnBtn(); if (isAutoSteerBtnOn && !ct.isContourBtnOn) DrawManUTurnBtn(); @@ -616,29 +616,29 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //draw 240 green for boundary - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) { ////draw the bnd line - int ptCount = bnd.bndArr[0].bndLine.Count; + int ptCount = plot.plots[0].bndLine.Count; if (ptCount > 3) { GL.LineWidth(3); GL.Color3((byte)0, (byte)240, (byte)0); GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < ptCount; h++) GL.Vertex3(bnd.bndArr[0].bndLine[h].easting, bnd.bndArr[0].bndLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(plot.plots[0].bndLine[h].easting, plot.plots[0].bndLine[h].northing, 0); GL.End(); } } //draw 250 green for the headland - if (bnd.isOn) + if (plot.isOn) { GL.LineWidth(3); GL.Color3((byte)0, (byte)250, (byte)0); - for (int i = 0; i < bnd.bndArr.Count; i++) + for (int i = 0; i < plot.plots.Count; i++) { - if (bnd.bndArr[i].hdLine.Count > 0) bnd.bndArr[i].DrawHeadLineBackBuffer(); + if (plot.plots[i].hdLine.Count > 0) plot.plots[i].DrawHeadLineBackBuffer(); } } @@ -677,7 +677,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tool.numOfSections == 1 || pn.speed < vehicle.slowSpeedCutoff) tool.isSuperSectionAllowedOn = false; - if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && bnd.isOn) + if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && plot.isOn) tool.isSuperSectionAllowedOn = false; //clamp the height after looking way ahead, this is for switching off super section only @@ -687,7 +687,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //10 % min is required for overlap, otherwise it never would be on. int pixLimit = (int)((double)(section[0].rpSectionWidth * rpOnHeight) / (double)(5.0)); - if ((rpOnHeight < rpToolHeight && bnd.isOn)) rpHeight = rpToolHeight + 2; + if ((rpOnHeight < rpToolHeight && plot.isOn)) rpHeight = rpToolHeight + 2; else rpHeight = rpOnHeight + 2; if (rpHeight > 290) rpHeight = 290; @@ -712,7 +712,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (!tool.isMultiColoredSections) { - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) { //are there enough pixels in buffer array to warrant turning off supersection for (int a = 0; a < (tool.rpWidth * rpOnHeight); a++) @@ -749,7 +749,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //determine if in or out of headland, do hydraulics if on - if (bnd.isOn) + if (plot.isOn) { //calculate the slope double m = (vehicle.hydLiftLookAheadDistanceRight - vehicle.hydLiftLookAheadDistanceLeft) / tool.rpWidth; @@ -770,12 +770,12 @@ private void oglBack_Paint(object sender, PaintEventArgs e) GetOutTool: //is the tool completely in the headland or not - bnd.isToolInHeadland = bnd.isToolOuterPointsInHeadland && !isHeadlandClose; + plot.isToolInHeadland = plot.isToolOuterPointsInHeadland && !isHeadlandClose; - if (isHeadlandClose || bnd.isToolInHeadland) tool.isSuperSectionAllowedOn = false; + if (isHeadlandClose || plot.isToolInHeadland) tool.isSuperSectionAllowedOn = false; //set hydraulics based on tool in headland or not - bnd.SetHydPosition(); + plot.SetHydPosition(); } } else //supersection check by applied only @@ -923,7 +923,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tagged == 0) section[j].isMappingRequiredOn = false; } - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) { //if out of boundary, turn it off if (!section[j].isInBoundary) @@ -935,7 +935,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) section[j].mappingOnTimer = 0; } - else if (section[j].isInHeadlandArea & bnd.isOn) + else if (section[j].isInHeadlandArea & plot.isOn) { // if headland is on and out, turn off section[j].isMappingRequiredOn = false; @@ -950,7 +950,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) /////////////////////////////////////////// Section control ssssssssssssssssssssss /// - if (bnd.isOn) bnd.WhereAreToolLookOnPoints(); + if (plot.isOn) plot.WhereAreToolLookOnPoints(); for (int j = 0; j < tool.numOfSections; j++) { @@ -958,7 +958,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //ensure it starts off section[j].isSectionRequiredOn = false; - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) { //if out of boundary, turn it off if (!section[j].isInBoundary) @@ -1013,7 +1013,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //is headland coming up - if (bnd.isOn) + if (plot.isOn) { bool isHeadlandInLookOn = false; @@ -1502,7 +1502,7 @@ private void oglZoom_Paint(object sender, PaintEventArgs e) } //draw all the boundaries - bnd.DrawBoundaryLines(); + plot.DrawBoundaryLines(); GL.PointSize(8.0f); GL.Begin(PrimitiveType.Points); @@ -2385,13 +2385,13 @@ public void CalculateMinMax() //min max of the boundary //min max of the boundary - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) { - int bndCnt = bnd.bndArr[0].bndLine.Count; + int bndCnt = plot.plots[0].bndLine.Count; for (int i = 0; i < bndCnt; i++) { - double x = bnd.bndArr[0].bndLine[i].easting; - double y = bnd.bndArr[0].bndLine[i].northing; + double x = plot.plots[0].bndLine[i].easting; + double y = plot.plots[0].bndLine[i].northing; //also tally the max/min of field x and z if (minFieldX > x) minFieldX = x; @@ -2481,7 +2481,7 @@ private void DrawFieldText() { if (isMetric) { - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) { sb.Clear(); sb.Append(((fd.workedAreaTotal - fd.actualAreaCovered) * glm.m2ha).ToString("N3")); @@ -2512,7 +2512,7 @@ private void DrawFieldText() } else { - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) { sb.Clear(); sb.Append(((fd.workedAreaTotal - fd.actualAreaCovered) * glm.m2ac).ToString("N3")); diff --git a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs index cd7e1b6fb..19a0032aa 100644 --- a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs +++ b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs @@ -122,7 +122,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.plot.DrawBoundaryLines(); GL.Flush(); oglSelf.SwapBuffers(); diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index b0f06a281..a0c7c217d 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -707,10 +707,10 @@ public void UpdateFixPosition() mc.isOutOfBounds = true; //if an outer boundary is set, then apply critical stop logic - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (bnd.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (plot.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; @@ -822,7 +822,7 @@ private void TheRest() } //test if travelled far enough for new boundary point - if (bnd.isOkToAddPoints) + if (plot.isOkToAddPoints) { double boundaryDistance = glm.Distance(pn.fix, prevBoundaryPos); if (boundaryDistance > 1) AddBoundaryPoint(); @@ -982,16 +982,16 @@ public void AddBoundaryPoint() //build the boundary line - if (bnd.isOkToAddPoints) + if (plot.isOkToAddPoints) { - if (bnd.isDrawRightSide) + if (plot.isDrawRightSide) { //Right side vec3 point = new vec3( - pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * -bnd.createBndOffset), - pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * -bnd.createBndOffset), + pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * -plot.createBndOffset), + pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * -plot.createBndOffset), pivotAxlePos.heading); - bnd.bndBeingMadePts.Add(point); + plot.bndBeingMadePts.Add(point); } //draw on left side @@ -999,10 +999,10 @@ public void AddBoundaryPoint() { //Right side vec3 point = new vec3( - pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * bnd.createBndOffset), - pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * bnd.createBndOffset), + pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * plot.createBndOffset), + pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * plot.createBndOffset), pivotAxlePos.heading); - bnd.bndBeingMadePts.Add(point); + plot.bndBeingMadePts.Add(point); } } } @@ -1238,7 +1238,7 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (tool.lookAheadDistanceOffPixelsRight > 160) tool.lookAheadDistanceOffPixelsRight = 160; //determine where the tool is wrt to headland - if (bnd.isOn) bnd.WhereAreToolCorners(); + if (plot.isOn) plot.WhereAreToolCorners(); //set up the super for youturn section[tool.numOfSections].isInBoundary = true; @@ -1248,19 +1248,19 @@ public void CalculateSectionLookAhead(double northing, double easting, double co for (int j = 0; j < tool.numOfSections; j++) { - if (bnd.bndArr.Count > 0) + if (plot.plots.Count > 0) { if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftIn = bnd.bndArr[0].IsPointInsideBoundaryEar(section[j].leftPoint); - isRightIn = bnd.bndArr[0].IsPointInsideBoundaryEar(section[j].rightPoint); + isLeftIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].leftPoint); + isRightIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].rightPoint); - for (int i = 1; i < bnd.bndArr.Count; i++) + for (int i = 1; i < plot.plots.Count; i++) { //inner boundaries should normally NOT have point inside - isLeftIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].leftPoint); - isRightIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].rightPoint); + isLeftIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].leftPoint); + isRightIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].rightPoint); } //merge the two sides into in or out @@ -1272,11 +1272,11 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { //grab the right of previous section, its the left of this section isLeftIn = isRightIn; - isRightIn = bnd.bndArr[0].IsPointInsideBoundaryEar(section[j].rightPoint); - for (int i = 1; i < bnd.bndArr.Count; i++) + isRightIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].rightPoint); + for (int i = 1; i < plot.plots.Count; i++) { //inner boundaries should normally NOT have point inside - isRightIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].rightPoint); + isRightIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].rightPoint); } if (isLeftIn && isRightIn) section[j].isInBoundary = true; diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index 5e0892f09..df00849ed 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -683,7 +683,7 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - CBoundaryLines New = new CBoundaryLines(); + CPlots New = new CPlots(); //True or False OR points from older boundary files line = reader.ReadLine(); @@ -739,13 +739,13 @@ public void FileOpenField(string _openType) } } - bnd.bndArr.Add(New); + plot.plots.Add(New); } } CalculateMinMax(); - bnd.BuildTurnLines(); - if (bnd.bndArr.Count > 0) btnMakeLinesFromBoundary.Visible = true; + plot.BuildTurnLines(); + if (plot.plots.Count > 0) btnMakeLinesFromBoundary.Visible = true; } catch (Exception e) @@ -773,9 +773,9 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - if (bnd.bndArr.Count > k) + if (plot.plots.Count > k) { - bnd.bndArr[k].hdLine.Clear(); + plot.plots[k].hdLine.Clear(); //read the number of points line = reader.ReadLine(); @@ -792,7 +792,7 @@ public void FileOpenField(string _openType) double.Parse(words[0], CultureInfo.InvariantCulture), double.Parse(words[1], CultureInfo.InvariantCulture), double.Parse(words[2], CultureInfo.InvariantCulture)); - bnd.bndArr[k].hdLine.Add(vecPt); + plot.plots[k].hdLine.Add(vecPt); } } } @@ -808,9 +808,9 @@ public void FileOpenField(string _openType) } } - if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) + if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - bnd.isOn = true; + plot.isOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -819,7 +819,7 @@ public void FileOpenField(string _openType) } else { - bnd.isOn = false; + plot.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; @@ -1209,19 +1209,19 @@ public void FileSaveBoundary() using (StreamWriter writer = new StreamWriter(dirField + "Boundary.Txt")) { writer.WriteLine("$Boundary"); - for (int i = 0; i < bnd.bndArr.Count; i++) + for (int i = 0; i < plot.plots.Count; i++) { - writer.WriteLine(bnd.bndArr[i].isDriveThru); - writer.WriteLine(bnd.bndArr[i].isDriveAround); + writer.WriteLine(plot.plots[i].isDriveThru); + writer.WriteLine(plot.plots[i].isDriveAround); //writer.WriteLine(bnd.bndArr[i].isOwnField); - writer.WriteLine(bnd.bndArr[i].bndLine.Count.ToString(CultureInfo.InvariantCulture)); - if (bnd.bndArr[i].bndLine.Count > 0) + writer.WriteLine(plot.plots[i].bndLine.Count.ToString(CultureInfo.InvariantCulture)); + if (plot.plots[i].bndLine.Count > 0) { - for (int j = 0; j < bnd.bndArr[i].bndLine.Count; j++) - writer.WriteLine(Math.Round(bnd.bndArr[i].bndLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndArr[i].bndLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndArr[i].bndLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < plot.plots[i].bndLine.Count; j++) + writer.WriteLine(Math.Round(plot.plots[i].bndLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].bndLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].bndLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); } } } @@ -1295,17 +1295,17 @@ public void FileSaveHeadland() { writer.WriteLine("$Headland"); - if (bnd.bndArr[0].hdLine.Count > 0) + if (plot.plots[0].hdLine.Count > 0) { - for (int i = 0; i < bnd.bndArr.Count; i++) + for (int i = 0; i < plot.plots.Count; i++) { - writer.WriteLine(bnd.bndArr[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); - if (bnd.bndArr[0].hdLine.Count > 0) + writer.WriteLine(plot.plots[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); + if (plot.plots[0].hdLine.Count > 0) { - for (int j = 0; j < bnd.bndArr[i].hdLine.Count; j++) - writer.WriteLine(Math.Round(bnd.bndArr[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndArr[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndArr[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < plot.plots[i].hdLine.Count; j++) + writer.WriteLine(Math.Round(plot.plots[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); } } } @@ -1678,7 +1678,7 @@ public void FileSaveFieldKML() kml.WriteStartElement("Folder"); kml.WriteElementString("name", "Boundaries"); - for (int i = 0; i < bnd.bndArr.Count; i++) + for (int i = 0; i < plot.plots.Count; i++) { kml.WriteStartElement("Placemark"); if (i == 0) kml.WriteElementString("name", currentFieldDirectory); @@ -1705,7 +1705,7 @@ public void FileSaveFieldKML() //coords kml.WriteStartElement("coordinates"); string bndPts = ""; - if (bnd.bndArr[i].bndLine.Count > 3) + if (plot.plots[i].bndLine.Count > 3) bndPts = GetBoundaryPointsLatLon(i); kml.WriteRaw(bndPts); kml.WriteEndElement(); // @@ -1949,12 +1949,12 @@ public string GetBoundaryPointsLatLon(int bndNum) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < bnd.bndArr[bndNum].bndLine.Count; i++) + for (int i = 0; i < plot.plots[bndNum].bndLine.Count; i++) { double lat = 0; double lon = 0; - pn.ConvertLocalToWGS84(bnd.bndArr[bndNum].bndLine[i].northing, bnd.bndArr[bndNum].bndLine[i].easting, out lat, out lon); + pn.ConvertLocalToWGS84(plot.plots[bndNum].bndLine[i].northing, plot.plots[bndNum].bndLine[i].easting, out lat, out lon); sb.Append(lon.ToString("N7", CultureInfo.InvariantCulture) + ',' + lat.ToString("N7", CultureInfo.InvariantCulture) + ",0 "); } diff --git a/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs b/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs index 5286675aa..a898ef27d 100644 --- a/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs +++ b/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs @@ -401,7 +401,7 @@ private void tabUTurn_Leave(object sender, EventArgs e) Properties.Settings.Default.Save(); Properties.Vehicle.Default.Save(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); mf.yt.ResetCreatedYouTurn(); } From e07ed0b282ee4f4336caf19f6fcde980ca5cfa84 Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Mon, 25 Oct 2021 15:28:15 -0600 Subject: [PATCH 03/18] Renaming to boundary groups --- SourceCode/AgIO/Source/AgIO.csproj | 1 + SourceCode/GPS/AgOpenGPS.csproj | 22 +- SourceCode/GPS/Classes/CABCurve.cs | 52 +--- SourceCode/GPS/Classes/CABLine.cs | 4 +- SourceCode/GPS/Classes/CBoundary.cs | 202 +------------- SourceCode/GPS/Classes/CBoundaryLines.cs | 263 ------------------ SourceCode/GPS/Classes/CBoundaryList.cs | 106 +++++++ SourceCode/GPS/Classes/CContour.cs | 10 +- SourceCode/GPS/Classes/CFence.cs | 181 ++++++++++++ SourceCode/GPS/Classes/CFenceLine.cs | 213 ++++++++++++++ SourceCode/GPS/Classes/CHead.cs | 16 +- SourceCode/GPS/Classes/CHeadLines.cs | 37 +-- SourceCode/GPS/Classes/CPlot.cs | 35 --- SourceCode/GPS/Classes/CPlots.cs | 30 -- SourceCode/GPS/Classes/CTram.cs | 24 +- SourceCode/GPS/Classes/CTurn.cs | 23 +- SourceCode/GPS/Classes/CTurnLines.cs | 23 +- SourceCode/GPS/Classes/CYouTurn.cs | 20 +- SourceCode/GPS/Forms/Controls.Designer.cs | 14 +- SourceCode/GPS/Forms/FormBoundary.cs | 28 +- SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 8 +- SourceCode/GPS/Forms/FormFieldKML.cs | 12 +- SourceCode/GPS/Forms/FormGPS.cs | 6 +- SourceCode/GPS/Forms/FormHeadland.cs | 8 +- SourceCode/GPS/Forms/GUI.Designer.cs | 2 +- SourceCode/GPS/Forms/Guidance/FormABDraw.cs | 28 +- .../GPS/Forms/Guidance/FormMakeBndCon.cs | 2 +- SourceCode/GPS/Forms/OpenGL.Designer.cs | 26 +- SourceCode/GPS/Forms/Position.designer.cs | 14 +- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 38 +-- 30 files changed, 678 insertions(+), 770 deletions(-) delete mode 100644 SourceCode/GPS/Classes/CBoundaryLines.cs create mode 100644 SourceCode/GPS/Classes/CBoundaryList.cs create mode 100644 SourceCode/GPS/Classes/CFence.cs create mode 100644 SourceCode/GPS/Classes/CFenceLine.cs delete mode 100644 SourceCode/GPS/Classes/CPlot.cs delete mode 100644 SourceCode/GPS/Classes/CPlots.cs diff --git a/SourceCode/AgIO/Source/AgIO.csproj b/SourceCode/AgIO/Source/AgIO.csproj index acf311cc4..01e53c1d7 100644 --- a/SourceCode/AgIO/Source/AgIO.csproj +++ b/SourceCode/AgIO/Source/AgIO.csproj @@ -166,6 +166,7 @@ FormGPSData.cs + Designer FormKeyboard.cs diff --git a/SourceCode/GPS/AgOpenGPS.csproj b/SourceCode/GPS/AgOpenGPS.csproj index e2584fa00..2b1114007 100644 --- a/SourceCode/GPS/AgOpenGPS.csproj +++ b/SourceCode/GPS/AgOpenGPS.csproj @@ -113,29 +113,29 @@ - - CPlot.cs + + CBoundary.cs - - CPlots.cs - - + + CBoundaryList.cs + + - + - CPlots.cs + CBoundaryList.cs - CPlot.cs + CBoundary.cs @@ -151,10 +151,10 @@ - CPlot.cs + CBoundary.cs - CPlots.cs + CBoundaryList.cs diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index 3fb7ebcf5..de9f27ad3 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -735,7 +735,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) + if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar )) { mf.tram.tramArr.Add(point); } @@ -744,7 +744,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) + if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -816,7 +816,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) + if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -825,7 +825,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) + if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -1033,48 +1033,4 @@ public class CCurveLines } -//for (int i = 1; i <= mf.tram.passes; i++) -//{ -// tramArr = new List(); -// tramList.Add(tramArr); - -// List tramTemp = new List(); - -// for (int j = 0; j < tramRef.Count; j++) -// { -// P1.easting = (hsin * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].easting; -// P1.northing = (hcos * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].northing; - -// if (isBndExist) -// { -// if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(P1)) -// { -// tramTemp.Add(P1); -// P1.easting = (hsin * mf.vehicle.trackWidth) + P1.easting; -// P1.northing = (hcos * mf.vehicle.trackWidth) + P1.northing; -// tramTemp.Add(P1); -// } -// } -// else -// { -// tramTemp.Add(P1); - -// P1.easting = (hsin * mf.vehicle.trackWidth) + P1.easting; -// P1.northing = (hcos * mf.vehicle.trackWidth) + P1.northing; -// tramTemp.Add(P1); -// } - -// if (tramTemp.Count > 6) -// { -// vec2[] array = new vec2[tramTemp.Count]; -// tramTemp.CopyTo(array); - -// tramArr.Add(array[0]); -// tramArr.Add(array[1]); -// tramArr.Add(array[tramTemp.Count - 2]); -// tramArr.Add(array[tramTemp.Count - 1]); -// } - -// } -//} diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index 7c3f8dff0..b08b15e2e 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -495,7 +495,7 @@ public void BuildTram() if (isBndExist) { - if (mf.plot.plots[0].IsPointInsideBoundaryEar(P1)) + if (mf.plot.plots[0].IsPointInPolygon(P1, ref mf.plot.plots[0].fenceLineEar)) { mf.tram.tramArr.Add(P1); } @@ -523,7 +523,7 @@ public void BuildTram() if (isBndExist) { - if (mf.plot.plots[0].IsPointInsideBoundaryEar(P1)) + if (mf.plot.plots[0].IsPointInPolygon(P1, ref mf.plot.plots[0].fenceLineEar)) { mf.tram.tramArr.Add(P1); } diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index c19551b06..807bfdceb 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -4,198 +4,22 @@ namespace AgOpenGPS { - public partial class CPlot + public partial class CBoundary { - public List bndBeingMadePts = new List(128); + //copy of the mainform address + private readonly FormGPS mf; - public double createBndOffset; - public bool isBndBeingMade; + public List plots = new List(); - // the list of possible bounds points - public List bndClosestList = new List(); - - public int boundarySelected, closestBoundaryNum; - - //generated box for finding closest point - public vec2 boxA = new vec2(9000, 9000), boxB = new vec2(9000, 9002); - - public vec2 boxC = new vec2(9001, 9001), boxD = new vec2(9002, 9003); - - //point at the farthest boundary segment from pivotAxle - public vec3 closestBoundaryPt = new vec3(-10000, -10000, 9); - - public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) - { - //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (plots[0].IsPointInsideBoundaryArea(testPoint)) - { - for (int i = 1; i < plots.Count; i++) - { - //make sure not inside a non drivethru boundary - if (plots[i].isDriveThru) continue; - if (plots[i].IsPointInsideBoundaryArea(testPoint)) - { - return false; - } - } - } - else - { - return false; - } - //we are safely inside outer, outside inner boundaries - return true; - } - - public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) - { - { - boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); - boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); - - boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); - boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); - - boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); - boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); - - boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); - boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); - } - - int ptCount; - - //determine if point is inside bounding box - bndClosestList.Clear(); - vec4 inBox; - for (int i = 0; i < plots.Count; i++) - { - //skip the drive thru - if (plots[i].isDriveThru) continue; - - ptCount = plots[i].bndLine.Count; - for (int p = 0; p < ptCount; p++) - { - if ((((boxB.easting - boxA.easting) * (plots[i].bndLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (plots[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } - - if ((((boxD.easting - boxC.easting) * (plots[i].bndLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (plots[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } - - if ((((boxC.easting - boxB.easting) * (plots[i].bndLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (plots[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } - - if ((((boxA.easting - boxD.easting) * (plots[i].bndLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (plots[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } - - //it's in the box, so add to list - inBox.easting = plots[i].bndLine[p].easting; - inBox.northing = plots[i].bndLine[p].northing; - inBox.heading = plots[i].bndLine[p].heading; - inBox.index = i; - - //which boundary/headland is it from - bndClosestList.Add(inBox); - } - } - - //which of the points is closest - closestBoundaryPt.easting = -20000; closestBoundaryPt.northing = -20000; - ptCount = bndClosestList.Count; - if (ptCount != 0) - { - //determine closest point - double minDistance = 9999999; - for (int i = 0; i < ptCount; i++) - { - double dist = ((fromPt.easting - bndClosestList[i].easting) * (fromPt.easting - bndClosestList[i].easting)) - + ((fromPt.northing - bndClosestList[i].northing) * (fromPt.northing - bndClosestList[i].northing)); - if (minDistance >= dist) - { - minDistance = dist; - - closestBoundaryPt.easting = bndClosestList[i].easting; - closestBoundaryPt.northing = bndClosestList[i].northing; - closestBoundaryPt.heading = bndClosestList[i].heading; - closestBoundaryNum = bndClosestList[i].index; - } - } - if (closestBoundaryPt.heading < 0) closestBoundaryPt.heading += glm.twoPI; - } - } - - public void DrawBoundaryLines() + //constructor + public CBoundary(FormGPS _f) { - //draw the boundaries - GL.Color3(0.75f, 0.5f, 0.250f); - - for (int i = 0; i < plots.Count; i++) - { - plots[i].DrawBoundaryLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); - } - - if (bndBeingMadePts.Count > 0) - { - //the boundary so far - vec3 pivot = mf.pivotAxlePos; - GL.LineWidth(mf.ABLine.lineWidth); - GL.Color3(0.825f, 0.22f, 0.90f); - GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); - GL.Color3(0.295f, 0.972f, 0.290f); - GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - GL.End(); - - //line from last point to pivot marker - GL.Color3(0.825f, 0.842f, 0.0f); - GL.Enable(EnableCap.LineStipple); - GL.LineStipple(1, 0x0700); - GL.Begin(PrimitiveType.LineStrip); - if (isDrawRightSide) - { - GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - - GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * -createBndOffset), - pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * -createBndOffset), 0); - GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); - } - else - { - GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - - GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * createBndOffset), - pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * createBndOffset), 0); - GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); - } - GL.End(); - GL.Disable(EnableCap.LineStipple); - - //boundary points - GL.Color3(0.0f, 0.95f, 0.95f); - GL.PointSize(6.0f); - GL.Begin(PrimitiveType.Points); - for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); - GL.End(); - } - } - - //draws the derived closest point - public void DrawClosestPoint() - { - GL.PointSize(4.0f); - GL.Color3(0.919f, 0.932f, 0.070f); - GL.Begin(PrimitiveType.Points); - GL.Vertex3(closestBoundaryPt.easting, closestBoundaryPt.northing, 0); - GL.End(); - - GL.LineWidth(1); - GL.Color3(0.92f, 0.62f, 0.42f); - GL.Begin(PrimitiveType.LineStrip); - GL.Vertex3(boxD.easting, boxD.northing, 0); - GL.Vertex3(boxA.easting, boxA.northing, 0); - GL.Vertex3(boxB.easting, boxB.northing, 0); - GL.Vertex3(boxC.easting, boxC.northing, 0); - GL.End(); + mf = _f; + fenceSelected = 0; + boxLength = 2000; + turnSelected = 0; + isHeadlandOn = false; + isToolUp = true; } } -} +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CBoundaryLines.cs b/SourceCode/GPS/Classes/CBoundaryLines.cs deleted file mode 100644 index 42f16d30b..000000000 --- a/SourceCode/GPS/Classes/CBoundaryLines.cs +++ /dev/null @@ -1,263 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; - -namespace AgOpenGPS -{ - public partial class CPlots - { - public void CalculateBoundaryHeadings() - { - //to calc heading based on next and previous points to give an average heading. - int cnt = bndLine.Count; - vec3[] arr = new vec3[cnt]; - cnt--; - bndLine.CopyTo(arr); - bndLine.Clear(); - - //first point needs last, first, second points - vec3 pt3 = arr[0]; - pt3.heading = Math.Atan2(arr[1].easting - arr[cnt].easting, arr[1].northing - arr[cnt].northing); - if (pt3.heading < 0) pt3.heading += glm.twoPI; - bndLine.Add(pt3); - - //middle points - for (int i = 1; i < cnt; i++) - { - pt3 = arr[i]; - pt3.heading = Math.Atan2(arr[i + 1].easting - arr[i - 1].easting, arr[i + 1].northing - arr[i - 1].northing); - if (pt3.heading < 0) pt3.heading += glm.twoPI; - bndLine.Add(pt3); - } - - //last and first point - pt3 = arr[cnt]; - pt3.heading = Math.Atan2(arr[0].easting - arr[cnt - 1].easting, arr[0].northing - arr[cnt - 1].northing); - if (pt3.heading < 0) pt3.heading += glm.twoPI; - bndLine.Add(pt3); - } - - public void FixBoundaryLine(int bndNum) - { - double spacing; - //boundary point spacing based on eq width - //close if less then 30 ha, 60ha, more then 60 - if (area < 200000) spacing = 1.1; - else if (area < 400000) spacing = 2.2; - else spacing = 3.3; - - if (bndNum > 0) spacing *= 0.5; - - int bndCount = bndLine.Count; - double distance; - - //make sure distance isn't too big between points on boundary - for (int i = 0; i < bndCount; i++) - { - int j = i + 1; - - if (j == bndCount) j = 0; - distance = glm.Distance(bndLine[i], bndLine[j]); - if (distance > spacing * 1.5) - { - vec3 pointB = new vec3((bndLine[i].easting + bndLine[j].easting) / 2.0, - (bndLine[i].northing + bndLine[j].northing) / 2.0, bndLine[i].heading); - - bndLine.Insert(j, pointB); - bndCount = bndLine.Count; - i--; - } - } - - //make sure distance isn't too big between points on boundary - bndCount = bndLine.Count; - - for (int i = 0; i < bndCount; i++) - { - int j = i + 1; - - if (j == bndCount) j = 0; - distance = glm.Distance(bndLine[i], bndLine[j]); - if (distance > spacing * 1.6) - { - vec3 pointB = new vec3((bndLine[i].easting + bndLine[j].easting) / 2.0, - (bndLine[i].northing + bndLine[j].northing) / 2.0, bndLine[i].heading); - - bndLine.Insert(j, pointB); - bndCount = bndLine.Count; - i--; - } - } - - //make sure distance isn't too small between points on headland - spacing *= 1.2; - bndCount = bndLine.Count; - for (int i = 0; i < bndCount - 1; i++) - { - distance = glm.Distance(bndLine[i], bndLine[i + 1]); - if (distance < spacing) - { - bndLine.RemoveAt(i + 1); - bndCount = bndLine.Count; - i--; - } - } - - //make sure headings are correct for calculated points - CalculateBoundaryHeadings(); - - double delta = 0; - bndLineEar?.Clear(); - - for (int i = 0; i < bndLine.Count; i++) - { - if (i == 0) - { - bndLineEar.Add(new vec2(bndLine[i].easting, bndLine[i].northing)); - continue; - } - delta += (bndLine[i - 1].heading - bndLine[i].heading); - if (Math.Abs(delta) > 0.01) - { - bndLineEar.Add(new vec2(bndLine[i].easting, bndLine[i].northing)); - delta = 0; - } - } - } - - public void ReverseWinding() - { - //reverse the boundary - int cnt = bndLine.Count; - vec3[] arr = new vec3[cnt]; - cnt--; - bndLine.CopyTo(arr); - bndLine.Clear(); - for (int i = cnt; i >= 0; i--) - { - arr[i].heading -= Math.PI; - if (arr[i].heading < 0) arr[i].heading += glm.twoPI; - bndLine.Add(arr[i]); - } - } - - public bool IsPointInsideBoundaryArea(vec3 testPoint) - { - bool result = false; - int j = bndLine.Count - 1; - for (int i = 0; i < bndLine.Count; i++) - { - if ((bndLine[i].easting < testPoint.easting && bndLine[j].easting >= testPoint.easting) || (bndLine[j].easting < testPoint.easting && bndLine[i].easting >= testPoint.easting)) - { - if (bndLine[i].northing + (testPoint.easting - bndLine[i].easting) / (bndLine[j].easting - bndLine[i].easting) * (bndLine[j].northing - bndLine[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - - public bool IsPointInsideBoundaryEar(vec3 testPoint) - { - bool result = false; - int j = bndLineEar.Count - 1; - for (int i = 0; i < bndLineEar.Count; i++) - { - if ((bndLineEar[i].easting < testPoint.easting && bndLineEar[j].easting >= testPoint.easting) || (bndLineEar[j].easting < testPoint.easting && bndLineEar[i].easting >= testPoint.easting)) - { - if (bndLineEar[i].northing + (testPoint.easting - bndLineEar[i].easting) / (bndLineEar[j].easting - bndLineEar[i].easting) * (bndLineEar[j].northing - bndLineEar[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - - public bool IsPointInsideBoundaryEar(vec2 testPoint) - { - bool result = false; - int j = bndLineEar.Count - 1; - for (int i = 0; i < bndLineEar.Count; i++) - { - if ((bndLineEar[i].easting < testPoint.easting && bndLineEar[j].easting >= testPoint.easting) || (bndLineEar[j].easting < testPoint.easting && bndLineEar[i].easting >= testPoint.easting)) - { - if (bndLineEar[i].northing + (testPoint.easting - bndLineEar[i].easting) / (bndLineEar[j].easting - bndLineEar[i].easting) * (bndLineEar[j].northing - bndLineEar[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - - public void DrawBoundaryLine(int lw, bool outOfBounds) - { - ////draw the perimeter line so far - if (bndLine.Count < 1) return; - //GL.PointSize(8); - //int ptCount = bndLine.Count; - //GL.Color3(0.925f, 0.752f, 0.860f); - ////else - //GL.Begin(PrimitiveType.Points); - //for (int h = 0; h < ptCount; h++) GL.Vertex3(bndLine[h].easting, bndLine[h].northing, 0); - ////GL.Color3(0.95f, 0.972f, 0.90f); - ////GL.Vertex3(bndLine[0].easting, bndLine[0].northing, 0); - //GL.End(); - - //ptCount = bdList.Count; - //if (ptCount < 1) return; - if (!outOfBounds) - { - GL.Color3(0.95f, 0.75f, 0.50f); - GL.LineWidth(lw); - } - else - { - GL.LineWidth(lw * 3); - GL.Color3(0.95f, 0.25f, 0.250f); - } - - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < bndLineEar.Count; i++) - { - GL.Vertex3(bndLineEar[i].easting, bndLineEar[i].northing, 0); - } - GL.End(); - } - - //obvious - public bool CalculateBoundaryArea(int idx) - { - int ptCount = bndLine.Count; - if (ptCount < 1) return false; - bool isClockwise = true; - - area = 0; // Accumulates area in the loop - int j = ptCount - 1; // The last vertex is the 'previous' one to the first - - for (int i = 0; i < ptCount; j = i++) - { - area += (bndLine[j].easting + bndLine[i].easting) * (bndLine[j].northing - bndLine[i].northing); - } - if (area < 0) isClockwise = false; - - area = Math.Abs(area / 2); - - //make sure is clockwise for outer counter clockwise for inner - if ((idx == 0 && isClockwise) || (idx > 0 && !isClockwise)) - { - ReverseWinding(); - } - - return isClockwise; - } - } -} diff --git a/SourceCode/GPS/Classes/CBoundaryList.cs b/SourceCode/GPS/Classes/CBoundaryList.cs new file mode 100644 index 000000000..8d8eee844 --- /dev/null +++ b/SourceCode/GPS/Classes/CBoundaryList.cs @@ -0,0 +1,106 @@ +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; + +namespace AgOpenGPS +{ + public partial class CBoundaryList + { + //list of coordinates of boundary line + public List fenceLine = new List(128); + public List fenceLineEar = new List(128); + public List hdLine = new List(128); + public List turnLine = new List(128); + + + //constructor + public CBoundaryList() + { + area = 0; + isDriveAround = false; + isDriveThru = false; + } + + public bool IsPointInPolygon(vec3 testPoint, ref List polygon) + { + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) + { + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + + public bool IsPointInPolygon(vec2 testPoint, ref List polygon) + { + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) + { + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + public bool IsPointInPolygon(vec2 testPoint, ref List polygon) + { + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) + { + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + public bool IsPointInPolygon(vec3 testPoint, ref List polygon) + { + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) + { + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + } +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index be15b4f9e..b61895a5f 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -922,7 +922,7 @@ public void StopContourLine(vec3 pivot) } //build contours for boundaries - public void BuildBoundaryContours(int pass, int spacingInt) + public void BuildFenceContours(int pass, int spacingInt) { if (mf.plot.plots.Count == 0) { @@ -953,7 +953,7 @@ public void BuildBoundaryContours(int pass, int spacingInt) for (int j = 0; j < mf.plot.plots.Count; j++) { //count the points from the boundary - int ptCount = mf.plot.plots[j].bndLine.Count; + int ptCount = mf.plot.plots[j].fenceLine.Count; ptList = new List(128); stripList.Add(ptList); @@ -961,9 +961,9 @@ public void BuildBoundaryContours(int pass, int spacingInt) for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.plot.plots[j].bndLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.plot.plots[j].bndLine[i].heading) * totalHeadWidth); - point.northing = mf.plot.plots[j].bndLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.plot.plots[j].bndLine[i].heading) * totalHeadWidth); - point.heading = mf.plot.plots[j].bndLine[i].heading - Math.PI; + point.easting = mf.plot.plots[j].fenceLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.plot.plots[j].fenceLine[i].heading) * totalHeadWidth); + point.northing = mf.plot.plots[j].fenceLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.plot.plots[j].fenceLine[i].heading) * totalHeadWidth); + point.heading = mf.plot.plots[j].fenceLine[i].heading - Math.PI; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if inside actual field boundary diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs new file mode 100644 index 000000000..fc41e2cf3 --- /dev/null +++ b/SourceCode/GPS/Classes/CFence.cs @@ -0,0 +1,181 @@ +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; + +namespace AgOpenGPS +{ + public partial class CBoundary + { + public List bndBeingMadePts = new List(128); + + public double createBndOffset; + public bool isBndBeingMade; + + // the list of possible bounds points + public List bndClosestList = new List(); + + public bool isDrawRightSide = true, isOkToAddPoints = false; + + public int fenceSelected, closestFenceNum; + + //point at the farthest boundary segment from pivotAxle + public vec3 closestFencePt = new vec3(-10000, -10000, 9); + + public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) + { + //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders + if (plots[0].IsPointInPolygon(testPoint, ref plots[0].fenceLine)) + { + for (int i = 1; i < plots.Count; i++) + { + //make sure not inside a non drivethru boundary + if (plots[i].isDriveThru) continue; + if (plots[i].IsPointInPolygon(testPoint, ref plots[i].fenceLine)) + { + return false; + } + } + } + else + { + return false; + } + //we are safely inside outer, outside inner boundaries + return true; + } + + public void DrawBoundaryLines() + { + //draw the boundaries + GL.Color3(0.75f, 0.5f, 0.250f); + + for (int i = 0; i < plots.Count; i++) + { + plots[i].DrawFenceLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); + } + + if (bndBeingMadePts.Count > 0) + { + //the boundary so far + vec3 pivot = mf.pivotAxlePos; + GL.LineWidth(mf.ABLine.lineWidth); + GL.Color3(0.825f, 0.22f, 0.90f); + GL.Begin(PrimitiveType.LineStrip); + for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); + GL.Color3(0.295f, 0.972f, 0.290f); + GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); + GL.End(); + + //line from last point to pivot marker + GL.Color3(0.825f, 0.842f, 0.0f); + GL.Enable(EnableCap.LineStipple); + GL.LineStipple(1, 0x0700); + GL.Begin(PrimitiveType.LineStrip); + if (isDrawRightSide) + { + GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); + + GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * -createBndOffset), + pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * -createBndOffset), 0); + GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); + } + else + { + GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); + + GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * createBndOffset), + pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * createBndOffset), 0); + GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); + } + GL.End(); + GL.Disable(EnableCap.LineStipple); + + //boundary points + GL.Color3(0.0f, 0.95f, 0.95f); + GL.PointSize(6.0f); + GL.Begin(PrimitiveType.Points); + for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); + GL.End(); + } + } + + } +} + + +//public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) + //{ + // { + // boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); + // boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); + + // boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); + // boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); + + // boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); + // boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); + + // boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); + // boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); + // } + + // int ptCount; + + // //determine if point is inside bounding box + // bndClosestList.Clear(); + // vec4 inBox; + // for (int i = 0; i < plots.Count; i++) + // { + // //skip the drive thru + // if (plots[i].isDriveThru) continue; + + // ptCount = plots[i].bndLine.Count; + // for (int p = 0; p < ptCount; p++) + // { + // if ((((boxB.easting - boxA.easting) * (plots[i].bndLine[p].northing - boxA.northing)) + // - ((boxB.northing - boxA.northing) * (plots[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } + + // if ((((boxD.easting - boxC.easting) * (plots[i].bndLine[p].northing - boxC.northing)) + // - ((boxD.northing - boxC.northing) * (plots[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } + + // if ((((boxC.easting - boxB.easting) * (plots[i].bndLine[p].northing - boxB.northing)) + // - ((boxC.northing - boxB.northing) * (plots[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } + + // if ((((boxA.easting - boxD.easting) * (plots[i].bndLine[p].northing - boxD.northing)) + // - ((boxA.northing - boxD.northing) * (plots[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } + + // //it's in the box, so add to list + // inBox.easting = plots[i].bndLine[p].easting; + // inBox.northing = plots[i].bndLine[p].northing; + // inBox.heading = plots[i].bndLine[p].heading; + // inBox.index = i; + + // //which boundary/headland is it from + // bndClosestList.Add(inBox); + // } + // } + + // //which of the points is closest + // closestBoundaryPt.easting = -20000; closestBoundaryPt.northing = -20000; + // ptCount = bndClosestList.Count; + // if (ptCount != 0) + // { + // //determine closest point + // double minDistance = 9999999; + // for (int i = 0; i < ptCount; i++) + // { + // double dist = ((fromPt.easting - bndClosestList[i].easting) * (fromPt.easting - bndClosestList[i].easting)) + // + ((fromPt.northing - bndClosestList[i].northing) * (fromPt.northing - bndClosestList[i].northing)); + // if (minDistance >= dist) + // { + // minDistance = dist; + + // closestBoundaryPt.easting = bndClosestList[i].easting; + // closestBoundaryPt.northing = bndClosestList[i].northing; + // closestBoundaryPt.heading = bndClosestList[i].heading; + // closestBoundaryNum = bndClosestList[i].index; + // } + // } + // if (closestBoundaryPt.heading < 0) closestBoundaryPt.heading += glm.twoPI; + // } + //} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CFenceLine.cs b/SourceCode/GPS/Classes/CFenceLine.cs new file mode 100644 index 000000000..9a84e554b --- /dev/null +++ b/SourceCode/GPS/Classes/CFenceLine.cs @@ -0,0 +1,213 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using OpenTK.Graphics.OpenGL; + +namespace AgOpenGPS +{ + public partial class CBoundaryList + { + //area variable + public double area; + + //boundary variables + public bool isDriveAround, isDriveThru; + + public void CalculateFenceLineHeadings() + { + //to calc heading based on next and previous points to give an average heading. + int cnt = fenceLine.Count; + vec3[] arr = new vec3[cnt]; + cnt--; + fenceLine.CopyTo(arr); + fenceLine.Clear(); + + //first point needs last, first, second points + vec3 pt3 = arr[0]; + pt3.heading = Math.Atan2(arr[1].easting - arr[cnt].easting, arr[1].northing - arr[cnt].northing); + if (pt3.heading < 0) pt3.heading += glm.twoPI; + fenceLine.Add(pt3); + + //middle points + for (int i = 1; i < cnt; i++) + { + pt3 = arr[i]; + pt3.heading = Math.Atan2(arr[i + 1].easting - arr[i - 1].easting, arr[i + 1].northing - arr[i - 1].northing); + if (pt3.heading < 0) pt3.heading += glm.twoPI; + fenceLine.Add(pt3); + } + + //last and first point + pt3 = arr[cnt]; + pt3.heading = Math.Atan2(arr[0].easting - arr[cnt - 1].easting, arr[0].northing - arr[cnt - 1].northing); + if (pt3.heading < 0) pt3.heading += glm.twoPI; + fenceLine.Add(pt3); + } + + public void FixFenceLine(int bndNum) + { + double spacing; + //boundary point spacing based on eq width + //close if less then 30 ha, 60ha, more then 60 + if (area < 200000) spacing = 1.1; + else if (area < 400000) spacing = 2.2; + else spacing = 3.3; + + if (bndNum > 0) spacing *= 0.5; + + int bndCount = fenceLine.Count; + double distance; + + //make sure distance isn't too big between points on boundary + for (int i = 0; i < bndCount; i++) + { + int j = i + 1; + + if (j == bndCount) j = 0; + distance = glm.Distance(fenceLine[i], fenceLine[j]); + if (distance > spacing * 1.5) + { + vec3 pointB = new vec3((fenceLine[i].easting + fenceLine[j].easting) / 2.0, + (fenceLine[i].northing + fenceLine[j].northing) / 2.0, fenceLine[i].heading); + + fenceLine.Insert(j, pointB); + bndCount = fenceLine.Count; + i--; + } + } + + //make sure distance isn't too big between points on boundary + bndCount = fenceLine.Count; + + for (int i = 0; i < bndCount; i++) + { + int j = i + 1; + + if (j == bndCount) j = 0; + distance = glm.Distance(fenceLine[i], fenceLine[j]); + if (distance > spacing * 1.6) + { + vec3 pointB = new vec3((fenceLine[i].easting + fenceLine[j].easting) / 2.0, + (fenceLine[i].northing + fenceLine[j].northing) / 2.0, fenceLine[i].heading); + + fenceLine.Insert(j, pointB); + bndCount = fenceLine.Count; + i--; + } + } + + //make sure distance isn't too small between points on headland + spacing *= 1.2; + bndCount = fenceLine.Count; + for (int i = 0; i < bndCount - 1; i++) + { + distance = glm.Distance(fenceLine[i], fenceLine[i + 1]); + if (distance < spacing) + { + fenceLine.RemoveAt(i + 1); + bndCount = fenceLine.Count; + i--; + } + } + + //make sure headings are correct for calculated points + CalculateFenceLineHeadings(); + + double delta = 0; + fenceLineEar?.Clear(); + + for (int i = 0; i < fenceLine.Count; i++) + { + if (i == 0) + { + fenceLineEar.Add(new vec2(fenceLine[i].easting, fenceLine[i].northing)); + continue; + } + delta += (fenceLine[i - 1].heading - fenceLine[i].heading); + if (Math.Abs(delta) > 0.01) + { + fenceLineEar.Add(new vec2(fenceLine[i].easting, fenceLine[i].northing)); + delta = 0; + } + } + } + + public void ReverseWinding() + { + //reverse the boundary + int cnt = fenceLine.Count; + vec3[] arr = new vec3[cnt]; + cnt--; + fenceLine.CopyTo(arr); + fenceLine.Clear(); + for (int i = cnt; i >= 0; i--) + { + arr[i].heading -= Math.PI; + if (arr[i].heading < 0) arr[i].heading += glm.twoPI; + fenceLine.Add(arr[i]); + } + } + + public void DrawFenceLine(int lw, bool outOfBounds) + { + ////draw the perimeter line so far + if (fenceLine.Count < 1) return; + //GL.PointSize(8); + //int ptCount = bndLine.Count; + //GL.Color3(0.925f, 0.752f, 0.860f); + ////else + //GL.Begin(PrimitiveType.Points); + //for (int h = 0; h < ptCount; h++) GL.Vertex3(bndLine[h].easting, bndLine[h].northing, 0); + ////GL.Color3(0.95f, 0.972f, 0.90f); + ////GL.Vertex3(bndLine[0].easting, bndLine[0].northing, 0); + //GL.End(); + + //ptCount = bdList.Count; + //if (ptCount < 1) return; + if (!outOfBounds) + { + GL.Color3(0.95f, 0.75f, 0.50f); + GL.LineWidth(lw); + } + else + { + GL.LineWidth(lw * 3); + GL.Color3(0.95f, 0.25f, 0.250f); + } + + GL.Begin(PrimitiveType.LineLoop); + for (int i = 0; i < fenceLineEar.Count; i++) + { + GL.Vertex3(fenceLineEar[i].easting, fenceLineEar[i].northing, 0); + } + GL.End(); + } + + //obvious + public bool CalculateFenceArea(int idx) + { + int ptCount = fenceLine.Count; + if (ptCount < 1) return false; + bool isClockwise = true; + + area = 0; // Accumulates area in the loop + int j = ptCount - 1; // The last vertex is the 'previous' one to the first + + for (int i = 0; i < ptCount; j = i++) + { + area += (fenceLine[j].easting + fenceLine[i].easting) * (fenceLine[j].northing - fenceLine[i].northing); + } + if (area < 0) isClockwise = false; + + area = Math.Abs(area / 2); + + //make sure is clockwise for outer counter clockwise for inner + if ((idx == 0 && isClockwise) || (idx > 0 && !isClockwise)) + { + ReverseWinding(); + } + + return isClockwise; + } + } +} diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index ca3060637..e7379034e 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -2,9 +2,9 @@ namespace AgOpenGPS { - public partial class CPlot + public partial class CBoundary { - public bool isOn; + public bool isHeadlandOn; public double leftToolDistance; public double rightToolDistance; @@ -41,15 +41,15 @@ public void WhereAreToolCorners() { bool isLeftInWk, isRightInWk = true; - if (isOn) + if (isHeadlandOn) { for (int j = 0; j < mf.tool.numOfSections; j++) { if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftInWk = plots[0].IsPointInHeadArea(mf.section[j].leftPoint); - isRightInWk = plots[0].IsPointInHeadArea(mf.section[j].rightPoint); + isLeftInWk = plots[0].IsPointInPolygon(mf.section[j].leftPoint, ref plots[0].hdLine); + isRightInWk = plots[0].IsPointInPolygon(mf.section[j].rightPoint, ref plots[0].hdLine); //save left side mf.tool.isLeftSideInHeadland = !isLeftInWk; @@ -62,7 +62,7 @@ public void WhereAreToolCorners() { //grab the right of previous section, its the left of this section isLeftInWk = isRightInWk; - isRightInWk = plots[0].IsPointInHeadArea(mf.section[j].rightPoint); + isRightInWk = plots[0].IsPointInPolygon(mf.section[j].rightPoint, ref plots[0].hdLine); mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } @@ -156,11 +156,11 @@ public void DrawHeadLines() public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add - if (plots.Count > 0 && plots[0].IsPointInHeadArea(pt)) + if (plots.Count > 0 && plots[0].IsPointInPolygon(pt, ref plots[0].hdLine)) { for (int b = 1; b < plots.Count; b++) { - if (plots[b].IsPointInHeadArea(pt)) + if (plots[b].IsPointInPolygon(pt, ref plots[b].hdLine)) { //point is in an inner turn area but inside outer return false; diff --git a/SourceCode/GPS/Classes/CHeadLines.cs b/SourceCode/GPS/Classes/CHeadLines.cs index 1fc4ea59f..634e61b08 100644 --- a/SourceCode/GPS/Classes/CHeadLines.cs +++ b/SourceCode/GPS/Classes/CHeadLines.cs @@ -2,43 +2,8 @@ namespace AgOpenGPS { - public partial class CPlots + public partial class CBoundaryList { - public bool IsPointInHeadArea(vec2 testPoint) - { - bool result = false; - int j = hdLine.Count - 1; - for (int i = 0; i < hdLine.Count; i++) - { - if ((hdLine[i].easting < testPoint.easting && hdLine[j].easting >= testPoint.easting) || (hdLine[j].easting < testPoint.easting && hdLine[i].easting >= testPoint.easting)) - { - if (hdLine[i].northing + (testPoint.easting - hdLine[i].easting) / (hdLine[j].easting - hdLine[i].easting) * (hdLine[j].northing - hdLine[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - - public bool IsPointInHeadArea(vec3 testPoint) - { - bool result = false; - int j = hdLine.Count - 1; - for (int i = 0; i < hdLine.Count; i++) - { - if ((hdLine[i].easting < testPoint.easting && hdLine[j].easting >= testPoint.easting) || (hdLine[j].easting < testPoint.easting && hdLine[i].easting >= testPoint.easting)) - { - if (hdLine[i].northing + (testPoint.easting - hdLine[i].easting) / (hdLine[j].easting - hdLine[i].easting) * (hdLine[j].northing - hdLine[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } public void DrawHeadLine() { diff --git a/SourceCode/GPS/Classes/CPlot.cs b/SourceCode/GPS/Classes/CPlot.cs deleted file mode 100644 index af734e7a7..000000000 --- a/SourceCode/GPS/Classes/CPlot.cs +++ /dev/null @@ -1,35 +0,0 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; - -namespace AgOpenGPS -{ - public partial class CPlot - { - //copy of the mainform address - private readonly FormGPS mf; - - /// - /// array of boundaries - /// - /// - public List plots = new List(); - - private readonly double scanWidth, boxLength; - - public bool isDrawRightSide = true, isOkToAddPoints = false; - //constructor - public CPlot(FormGPS _f) - { - mf = _f; - boundarySelected = 0; - scanWidth = 1.0; - boxLength = 2000; - - turnSelected = 0; - - isOn = false; - isToolUp = true; - } - } -} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CPlots.cs b/SourceCode/GPS/Classes/CPlots.cs deleted file mode 100644 index 879e18796..000000000 --- a/SourceCode/GPS/Classes/CPlots.cs +++ /dev/null @@ -1,30 +0,0 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; - -namespace AgOpenGPS -{ - public partial class CPlots - { - //list of coordinates of boundary line - public List bndLine = new List(128); - public List bndLineEar = new List(128); - public List hdLine = new List(128); - public List turnLine = new List(128); - - //area variable - public double area; - - //boundary variables - public bool isDriveAround, isDriveThru; - - //constructor - public CPlots() - { - area = 0; - isDriveAround = false; - isDriveThru = false; - } - - } -} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CTram.cs b/SourceCode/GPS/Classes/CTram.cs index 7b6455fa3..f00222a02 100644 --- a/SourceCode/GPS/Classes/CTram.cs +++ b/SourceCode/GPS/Classes/CTram.cs @@ -101,7 +101,7 @@ public void BuildTramBnd() private void CreateBndInnerTramTrack() { //count the points from the boundary - int ptCount = mf.plot.plots[0].bndLine.Count; + int ptCount = mf.plot.plots[0].fenceLine.Count; tramBndInnerArr?.Clear(); //outside point @@ -113,18 +113,18 @@ private void CreateBndInnerTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.easting = mf.plot.plots[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); - pt3.northing = mf.plot.plots[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.northing = mf.plot.plots[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); + mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); if (check < distSq) { Add = false; @@ -149,7 +149,7 @@ private void CreateBndInnerTramTrack() public void CreateBndOuterTramTrack() { //count the points from the boundary - int ptCount = mf.plot.plots[0].bndLine.Count; + int ptCount = mf.plot.plots[0].fenceLine.Count; tramBndOuterArr?.Clear(); //outside point @@ -161,18 +161,18 @@ public void CreateBndOuterTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.easting = mf.plot.plots[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); - pt3.northing = mf.plot.plots[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.northing = mf.plot.plots[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); + mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); if (check < distSq) { Add = false; diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index 30bdda5ea..7a8b37987 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -4,13 +4,20 @@ namespace AgOpenGPS { - public partial class CPlot + public partial class CBoundary { // the list of possible bounds points public List turnClosestList = new List(); public int turnSelected, closestTurnNum; + //generated box for finding closest point + public vec2 boxA = new vec2(9000, 9000), boxB = new vec2(9000, 9002); + + public vec2 boxC = new vec2(9001, 9001), boxD = new vec2(9002, 9003); + + private readonly double boxLength; + //point at the farthest turn segment from pivotAxle public vec3 closestTurnPt = new vec3(-10000, -10000, 9); @@ -31,13 +38,13 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (plots[0].IsPointInTurnWorkArea(pt)) + if (plots[0].IsPointInPolygon(pt, ref plots[0].turnLine)) { for (int t = 1; t < plots.Count; t++) { if (plots[t].isDriveThru) continue; if (plots[t].isDriveAround) continue; - if (plots[t].IsPointInTurnWorkArea(pt)) + if (plots[t].IsPointInPolygon(pt, ref plots[0].turnLine)) { isFound = true; closestTurnNum = t; @@ -221,18 +228,18 @@ public void BuildTurnLines() plots[j].turnLine.Clear(); if (plots[j].isDriveThru || plots[j].isDriveAround) continue; - int ptCount = plots[j].bndLine.Count; + int ptCount = plots[j].fenceLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point outside the boundary - point.easting = plots[j].bndLine[i].easting + (-Math.Sin(glm.PIBy2 + plots[j].bndLine[i].heading) * totalHeadWidth); - point.northing = plots[j].bndLine[i].northing + (-Math.Cos(glm.PIBy2 + plots[j].bndLine[i].heading) * totalHeadWidth); - point.heading = plots[j].bndLine[i].heading; + point.easting = plots[j].fenceLine[i].easting + (-Math.Sin(glm.PIBy2 + plots[j].fenceLine[i].heading) * totalHeadWidth); + point.northing = plots[j].fenceLine[i].northing + (-Math.Cos(glm.PIBy2 + plots[j].fenceLine[i].heading) * totalHeadWidth); + point.heading = plots[j].fenceLine[i].heading; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == plots[j].IsPointInsideBoundaryEar(point)) + if (j == 0 == plots[j].IsPointInPolygon(point, ref plots[j].fenceLineEar)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); plots[j].turnLine.Add(tPnt); diff --git a/SourceCode/GPS/Classes/CTurnLines.cs b/SourceCode/GPS/Classes/CTurnLines.cs index db8e8cf07..83bd604fd 100644 --- a/SourceCode/GPS/Classes/CTurnLines.cs +++ b/SourceCode/GPS/Classes/CTurnLines.cs @@ -3,7 +3,7 @@ namespace AgOpenGPS { - public partial class CPlots + public partial class CBoundaryList { public void CalculateTurnHeadings() { @@ -48,12 +48,12 @@ public void FixTurnLine(double totalHeadWidth, double spacing) double distance; //remove the points too close to boundary - for (int i = 0; i < bndLine.Count; i++) + for (int i = 0; i < fenceLine.Count; i++) { for (int j = 0; j < lineCount; j++) { //make sure distance between headland and boundary is not less then width - distance = glm.DistanceSquared(bndLine[i], turnLine[j]); + distance = glm.DistanceSquared(fenceLine[i], turnLine[j]); if (distance < (totalHeadWidth * 0.99)) { turnLine.RemoveAt(j); @@ -125,23 +125,6 @@ public void FixTurnLine(double totalHeadWidth, double spacing) //} } - public bool IsPointInTurnWorkArea(vec3 testPoint) - { - bool result = false; - int j = turnLine.Count - 1; - for (int i = 0; i < turnLine.Count; i++) - { - if ((turnLine[i].easting < testPoint.easting && turnLine[j].easting >= testPoint.easting) || (turnLine[j].easting < testPoint.easting && turnLine[i].easting >= testPoint.easting)) - { - if (turnLine[i].northing + (testPoint.easting - turnLine[i].easting) / (turnLine[j].easting - turnLine[i].easting) * (turnLine[j].northing - turnLine[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } public void DrawTurnLine() { ////draw the turn line oject diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index 4e7b9b385..26bf06e86 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -115,7 +115,7 @@ public bool FindCurveTurnPoints() //for each point in succession keep going till a turnLine is found. for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) { - if (!mf.plot.plots[0].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (!mf.plot.plots[0].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[0].turnLine)) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -130,7 +130,7 @@ public bool FindCurveTurnPoints() //make sure not inside a non drivethru boundary if (mf.plot.plots[i].isDriveThru) continue; if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (mf.plot.plots[i].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[i].turnLine)) { crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -152,7 +152,7 @@ public bool FindCurveTurnPoints() for (int j = mf.curve.currentLocationIndex; j > 0; j--) { - if (!mf.plot.plots[0].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (!mf.plot.plots[0].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[0].turnLine)) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; @@ -167,7 +167,7 @@ public bool FindCurveTurnPoints() //make sure not inside a non drivethru boundary if (mf.plot.plots[i].isDriveThru) continue; if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (mf.plot.plots[i].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[i].turnLine)) { crossingCurvePoint.easting = mf.curve.curList[j].easting; crossingCurvePoint.northing = mf.curve.curList[j].northing; @@ -584,7 +584,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; + if (!mf.plot.plots[0].IsPointInPolygon(ytList[j],ref mf.plot.plots[0].turnLine)) isOutOfBounds = true; if (isOutOfBounds) break; for (int i = 1; i < mf.plot.plots.Count; i++) @@ -592,7 +592,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) //make sure not inside a non drivethru boundary if (mf.plot.plots[i].isDriveThru) continue; if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[i].turnLine)) { isOutOfBounds = true; break; @@ -644,7 +644,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; + if (!mf.plot.plots[0].IsPointInPolygon(ytList[j], ref mf.plot.plots[0].turnLine)) isOutOfBounds = true; if (isOutOfBounds) break; @@ -653,7 +653,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) //make sure not inside a non drivethru boundary if (mf.plot.plots[i].isDriveThru) continue; if (mf.plot.plots[i].isDriveAround) continue; - if (!mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) + if (!mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[i].turnLine)) { isOutOfBounds = true; break; @@ -852,7 +852,7 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) + if (!mf.plot.plots[0].IsPointInPolygon(ytList[j], ref mf.plot.plots[0].turnLine)) { isOutOfBounds = true; break; @@ -863,7 +863,7 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) //make sure not inside a non drivethru boundary if (mf.plot.plots[i].isDriveThru) continue; if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[1].turnLine)) { isOutOfBounds = true; break; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index 0055a0d97..76a7f2beb 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -1551,8 +1551,8 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) { if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - plot.isOn = !plot.isOn; - if (plot.isOn) + plot.isHeadlandOn = !plot.isHeadlandOn; + if (plot.isHeadlandOn) { btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHydLift.Visible = true; @@ -1563,9 +1563,9 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; } } - else plot.isOn = false; + else plot.isHeadlandOn = false; - if (!plot.isOn) + if (!plot.isHeadlandOn) { p_239.pgn[p_239.hydLift] = 0; vehicle.isHydLiftOn = false; @@ -1577,7 +1577,7 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) private void btnHydLift_Click(object sender, EventArgs e) { - if (plot.isOn) + if (plot.isHeadlandOn) { vehicle.isHydLiftOn = !vehicle.isHydLiftOn; if (vehicle.isHydLiftOn) @@ -1976,7 +1976,7 @@ public void GetHeadland() if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - plot.isOn = true; + plot.isHeadlandOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -1984,7 +1984,7 @@ public void GetHeadland() } else { - plot.isOn = false; + plot.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index 8721b187b..7df2c5359 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -151,7 +151,7 @@ private void UpdateChart() b.Text = Math.Round(mf.plot.plots[i].area * 0.000247105, 2) + " Ac"; } - if (Selectedreset == false && i == mf.plot.boundarySelected) + if (Selectedreset == false && i == mf.plot.fenceSelected) { a.ForeColor = Color.OrangeRed; b.ForeColor = Color.OrangeRed; @@ -188,16 +188,16 @@ private void B_Click(object sender, EventArgs e) if (sender is Button b) { - mf.plot.boundarySelected = Convert.ToInt32(b.Name); + mf.plot.fenceSelected = Convert.ToInt32(b.Name); - if (mf.plot.boundarySelected == 0 && mf.plot.plots.Count > 1) + if (mf.plot.fenceSelected == 0 && mf.plot.plots.Count > 1) { return; } Selectedreset = false; - if (mf.plot.plots.Count > mf.plot.boundarySelected) + if (mf.plot.plots.Count > mf.plot.fenceSelected) { btnDelete.Enabled = true; } @@ -229,14 +229,14 @@ private void btnDelete_Click(object sender, EventArgs e) btnDelete.Enabled = false; - if (mf.plot.plots.Count > mf.plot.boundarySelected) + if (mf.plot.plots.Count > mf.plot.fenceSelected) { - mf.plot.plots.RemoveAt(mf.plot.boundarySelected); + mf.plot.plots.RemoveAt(mf.plot.fenceSelected); } mf.FileSaveBoundary(); - mf.plot.boundarySelected = -1; + mf.plot.fenceSelected = -1; Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); mf.plot.BuildTurnLines(); @@ -282,7 +282,7 @@ private void btnDeleteAll_Click(object sender, EventArgs e) ResetAllBoundary(); - mf.plot.boundarySelected = -1; + mf.plot.fenceSelected = -1; Selectedreset = true; mf.plot.isOkToAddPoints = false; @@ -310,7 +310,7 @@ private void btnReturn_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e) { - mf.plot.boundarySelected = mf.plot.plots.Count; + mf.plot.fenceSelected = mf.plot.plots.Count; Selectedreset = false; @@ -353,7 +353,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) { if (button.Name == "btnLoadMultiBoundaryFromGE") ResetAllBoundary(); - else i = mf.plot.boundarySelected; + else i = mf.plot.fenceSelected; try { @@ -394,7 +394,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) //at least 3 points if (numberSets.Length > 2) { - CPlots New = new CPlots(); + CBoundaryList New = new CBoundaryList(); foreach (string item in numberSets) { @@ -405,11 +405,11 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) mf.pn.ConvertWGS84ToLocal(latK, lonK, out norting, out easting); //add the point to boundary - New.bndLine.Add(new vec3(easting, norting, 0)); + New.fenceLine.Add(new vec3(easting, norting, 0)); } - New.CalculateBoundaryArea(mf.plot.boundarySelected); - New.FixBoundaryLine(i); + New.CalculateFenceArea(mf.plot.fenceSelected); + New.FixFenceLine(i); mf.plot.plots.Add(New); diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 2d8a3f2a0..59b15796d 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -29,15 +29,15 @@ private void btnStop_Click(object sender, EventArgs e) { if (mf.plot.bndBeingMadePts.Count > 2) { - CPlots New = new CPlots(); + CBoundaryList New = new CBoundaryList(); for (int i = 0; i < mf.plot.bndBeingMadePts.Count; i++) { - New.bndLine.Add(mf.plot.bndBeingMadePts[i]); + New.fenceLine.Add(mf.plot.bndBeingMadePts[i]); } - New.CalculateBoundaryArea(mf.plot.boundarySelected); - New.FixBoundaryLine(mf.plot.boundarySelected); + New.CalculateFenceArea(mf.plot.fenceSelected); + New.FixFenceLine(mf.plot.fenceSelected); mf.plot.plots.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 034d3e748..22bc7ebf7 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -125,7 +125,7 @@ private void LoadKMLBoundary(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.plot.boundarySelected; + i = mf.plot.fenceSelected; try { @@ -166,7 +166,7 @@ private void LoadKMLBoundary(string filename) //at least 3 points if (numberSets.Length > 2) { - CPlots New = new CPlots(); + CBoundaryList New = new CBoundaryList(); foreach (string item in numberSets) { @@ -179,12 +179,12 @@ private void LoadKMLBoundary(string filename) mf.pn.ConvertWGS84ToLocal(latK, lonK, out northing, out easting); //add the point to boundary - New.bndLine.Add(new vec3(easting, northing, 0)); + New.fenceLine.Add(new vec3(easting, northing, 0)); } //build the boundary, make sure is clockwise for outer counter clockwise for inner - New.CalculateBoundaryArea(mf.plot.boundarySelected); - New.FixBoundaryLine(i); + New.CalculateFenceArea(mf.plot.fenceSelected); + New.FixFenceLine(i); mf.plot.plots.Add(New); @@ -233,7 +233,7 @@ private void FindLatLon(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.plot.boundarySelected; + i = mf.plot.fenceSelected; try { diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index d4d2c5a57..2e2d2e18c 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -187,7 +187,7 @@ public partial class FormGPS : Form /// /// The boundary object /// - public CPlot plot; + public CBoundary plot; /// /// The internal simulator @@ -366,7 +366,7 @@ public FormGPS() mc = new CModuleComm(); //boundary object - plot = new CPlot(this); + plot = new CBoundary(this); //nmea simulator built in. sim = new CSim(this); @@ -979,7 +979,7 @@ public void JobClose() pn.fixOffset.northing = 0; //turn off headland - plot.isOn = false; + plot.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; diff --git a/SourceCode/GPS/Forms/FormHeadland.cs b/SourceCode/GPS/Forms/FormHeadland.cs index 9091c6a0a..3ce8739dc 100644 --- a/SourceCode/GPS/Forms/FormHeadland.cs +++ b/SourceCode/GPS/Forms/FormHeadland.cs @@ -80,13 +80,13 @@ public void BuildHeadLineTemplateFromBoundary() //outside boundary - count the points from the boundary headLineTemplate.Clear(); - int ptCount = mf.plot.plots[0].bndLine.Count; + int ptCount = mf.plot.plots[0].fenceLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.plot.plots[0].bndLine[i].easting; - point.northing = mf.plot.plots[0].bndLine[i].northing; - point.heading = mf.plot.plots[0].bndLine[i].heading; + point.easting = mf.plot.plots[0].fenceLine[i].easting; + point.northing = mf.plot.plots[0].fenceLine[i].northing; + point.heading = mf.plot.plots[0].fenceLine[i].heading; headLineTemplate.Add(point); } diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 66dab5db2..2ffa9913f 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -498,7 +498,7 @@ public void LoadSettings() if (Properties.Settings.Default.setAS_isAutoSteerAutoOn) btnAutoSteer.Text = "R"; else btnAutoSteer.Text = "M"; - if (plot.isOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; + if (plot.isHeadlandOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; else btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnChangeMappingColor.BackColor = sectionColorDay; diff --git a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs index b19add630..073fd189d 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs @@ -46,21 +46,21 @@ public FormABDraw(Form callingForm) private void FormABDraw_Load(object sender, EventArgs e) { - int cnt = mf.plot.plots[0].bndLine.Count; + int cnt = mf.plot.plots[0].fenceLine.Count; arr = new vec3[cnt * 2]; for (int i = 0; i < cnt; i++) { - arr[i].easting = mf.plot.plots[0].bndLine[i].easting; - arr[i].northing = mf.plot.plots[0].bndLine[i].northing; - arr[i].heading = mf.plot.plots[0].bndLine[i].heading; + arr[i].easting = mf.plot.plots[0].fenceLine[i].easting; + arr[i].northing = mf.plot.plots[0].fenceLine[i].northing; + arr[i].heading = mf.plot.plots[0].fenceLine[i].heading; } for (int i = cnt; i < cnt * 2; i++) { - arr[i].easting = mf.plot.plots[0].bndLine[i - cnt].easting; - arr[i].northing = mf.plot.plots[0].bndLine[i - cnt].northing; - arr[i].heading = mf.plot.plots[0].bndLine[i - cnt].heading; + arr[i].easting = mf.plot.plots[0].fenceLine[i - cnt].easting; + arr[i].northing = mf.plot.plots[0].fenceLine[i - cnt].northing; + arr[i].heading = mf.plot.plots[0].fenceLine[i - cnt].heading; } nudDistance.Value = (decimal)Math.Round(((mf.tool.toolWidth * mf.m2InchOrCm) * 0.5), 0); // @@ -356,7 +356,7 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) { //count the points from the boundary - int ptCount = mf.plot.plots[0].bndLine.Count; + int ptCount = mf.plot.plots[0].fenceLine.Count; mf.curve.refList?.Clear(); //outside point @@ -369,20 +369,20 @@ private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (moveDist)); + pt3.easting = mf.plot.plots[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (moveDist)); - pt3.northing = mf.plot.plots[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (moveDist)); + pt3.northing = mf.plot.plots[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (moveDist)); - pt3.heading = mf.plot.plots[0].bndLine[i].heading; + pt3.heading = mf.plot.plots[0].fenceLine[i].heading; bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); + mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); if (check < distSq) { Add = false; diff --git a/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs b/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs index 9d182e165..2d05e3c58 100644 --- a/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs +++ b/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs @@ -24,7 +24,7 @@ public FormMakeBndCon(Form _mf) private void BtnOk_Click(object sender, System.EventArgs e) { //convert to meters - mf.ct.BuildBoundaryContours((int)nudPass.Value, (int)(nudSpacing.Value * 0.01m)); + mf.ct.BuildFenceContours((int)nudPass.Value, (int)(nudSpacing.Value * 0.01m)); Close(); } diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index c763d943b..53c2a662a 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -346,7 +346,7 @@ private void oglMain_Paint(object sender, PaintEventArgs e) plot.DrawTurnLines(); } - if (plot.isOn) + if (plot.isHeadlandOn) { GL.LineWidth(ABLine.lineWidth); GL.Color3(0.960f, 0.96232f, 0.30f); @@ -619,19 +619,19 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (plot.plots.Count > 0) { ////draw the bnd line - int ptCount = plot.plots[0].bndLine.Count; + int ptCount = plot.plots[0].fenceLine.Count; if (ptCount > 3) { GL.LineWidth(3); GL.Color3((byte)0, (byte)240, (byte)0); GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < ptCount; h++) GL.Vertex3(plot.plots[0].bndLine[h].easting, plot.plots[0].bndLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(plot.plots[0].fenceLine[h].easting, plot.plots[0].fenceLine[h].northing, 0); GL.End(); } } //draw 250 green for the headland - if (plot.isOn) + if (plot.isHeadlandOn) { GL.LineWidth(3); GL.Color3((byte)0, (byte)250, (byte)0); @@ -677,7 +677,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tool.numOfSections == 1 || pn.speed < vehicle.slowSpeedCutoff) tool.isSuperSectionAllowedOn = false; - if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && plot.isOn) + if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && plot.isHeadlandOn) tool.isSuperSectionAllowedOn = false; //clamp the height after looking way ahead, this is for switching off super section only @@ -687,7 +687,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //10 % min is required for overlap, otherwise it never would be on. int pixLimit = (int)((double)(section[0].rpSectionWidth * rpOnHeight) / (double)(5.0)); - if ((rpOnHeight < rpToolHeight && plot.isOn)) rpHeight = rpToolHeight + 2; + if ((rpOnHeight < rpToolHeight && plot.isHeadlandOn)) rpHeight = rpToolHeight + 2; else rpHeight = rpOnHeight + 2; if (rpHeight > 290) rpHeight = 290; @@ -749,7 +749,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //determine if in or out of headland, do hydraulics if on - if (plot.isOn) + if (plot.isHeadlandOn) { //calculate the slope double m = (vehicle.hydLiftLookAheadDistanceRight - vehicle.hydLiftLookAheadDistanceLeft) / tool.rpWidth; @@ -935,7 +935,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) section[j].mappingOnTimer = 0; } - else if (section[j].isInHeadlandArea & plot.isOn) + else if (section[j].isInHeadlandArea & plot.isHeadlandOn) { // if headland is on and out, turn off section[j].isMappingRequiredOn = false; @@ -950,7 +950,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) /////////////////////////////////////////// Section control ssssssssssssssssssssss /// - if (plot.isOn) plot.WhereAreToolLookOnPoints(); + if (plot.isHeadlandOn) plot.WhereAreToolLookOnPoints(); for (int j = 0; j < tool.numOfSections; j++) { @@ -1013,7 +1013,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //is headland coming up - if (plot.isOn) + if (plot.isHeadlandOn) { bool isHeadlandInLookOn = false; @@ -2387,11 +2387,11 @@ public void CalculateMinMax() //min max of the boundary if (plot.plots.Count > 0) { - int bndCnt = plot.plots[0].bndLine.Count; + int bndCnt = plot.plots[0].fenceLine.Count; for (int i = 0; i < bndCnt; i++) { - double x = plot.plots[0].bndLine[i].easting; - double y = plot.plots[0].bndLine[i].northing; + double x = plot.plots[0].fenceLine[i].easting; + double y = plot.plots[0].fenceLine[i].northing; //also tally the max/min of field x and z if (minFieldX > x) minFieldX = x; diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index a0c7c217d..4a766dae7 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -1238,7 +1238,7 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (tool.lookAheadDistanceOffPixelsRight > 160) tool.lookAheadDistanceOffPixelsRight = 160; //determine where the tool is wrt to headland - if (plot.isOn) plot.WhereAreToolCorners(); + if (plot.isHeadlandOn) plot.WhereAreToolCorners(); //set up the super for youturn section[tool.numOfSections].isInBoundary = true; @@ -1253,14 +1253,14 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].leftPoint); - isRightIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].rightPoint); + isLeftIn = plot.plots[0].IsPointInPolygon(section[j].leftPoint, ref plot.plots[0].fenceLineEar); + isRightIn = plot.plots[0].IsPointInPolygon(section[j].rightPoint, ref plot.plots[0].fenceLineEar); for (int i = 1; i < plot.plots.Count; i++) { //inner boundaries should normally NOT have point inside - isLeftIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].leftPoint); - isRightIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].rightPoint); + isLeftIn &= !plot.plots[i].IsPointInPolygon(section[j].leftPoint, ref plot.plots[i].fenceLineEar); + isRightIn &= !plot.plots[i].IsPointInPolygon(section[j].rightPoint, ref plot.plots[i].fenceLineEar); } //merge the two sides into in or out @@ -1272,11 +1272,11 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { //grab the right of previous section, its the left of this section isLeftIn = isRightIn; - isRightIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].rightPoint); + isRightIn = plot.plots[0].IsPointInPolygon(section[j].rightPoint, ref plot.plots[0].fenceLineEar); for (int i = 1; i < plot.plots.Count; i++) { //inner boundaries should normally NOT have point inside - isRightIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].rightPoint); + isRightIn &= !plot.plots[i].IsPointInPolygon(section[j].rightPoint, ref plot.plots[i].fenceLineEar); } if (isLeftIn && isRightIn) section[j].isInBoundary = true; diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index df00849ed..726feae46 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -683,7 +683,7 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - CPlots New = new CPlots(); + CBoundaryList New = new CBoundaryList(); //True or False OR points from older boundary files line = reader.ReadLine(); @@ -716,25 +716,25 @@ public void FileOpenField(string _openType) double.Parse(words[1], CultureInfo.InvariantCulture), double.Parse(words[2], CultureInfo.InvariantCulture)); - New.bndLine.Add(vecPt); + New.fenceLine.Add(vecPt); } - New.CalculateBoundaryArea(k); + New.CalculateFenceArea(k); double delta = 0; - New.bndLineEar?.Clear(); + New.fenceLineEar?.Clear(); - for (int i = 0; i < New.bndLine.Count; i++) + for (int i = 0; i < New.fenceLine.Count; i++) { if (i == 0) { - New.bndLineEar.Add(new vec2(New.bndLine[i].easting, New.bndLine[i].northing)); + New.fenceLineEar.Add(new vec2(New.fenceLine[i].easting, New.fenceLine[i].northing)); continue; } - delta += (New.bndLine[i - 1].heading - New.bndLine[i].heading); + delta += (New.fenceLine[i - 1].heading - New.fenceLine[i].heading); if (Math.Abs(delta) > 0.04) { - New.bndLineEar.Add(new vec2(New.bndLine[i].easting, New.bndLine[i].northing)); + New.fenceLineEar.Add(new vec2(New.fenceLine[i].easting, New.fenceLine[i].northing)); delta = 0; } } @@ -810,7 +810,7 @@ public void FileOpenField(string _openType) if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - plot.isOn = true; + plot.isHeadlandOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -819,7 +819,7 @@ public void FileOpenField(string _openType) } else { - plot.isOn = false; + plot.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; @@ -1215,13 +1215,13 @@ public void FileSaveBoundary() writer.WriteLine(plot.plots[i].isDriveAround); //writer.WriteLine(bnd.bndArr[i].isOwnField); - writer.WriteLine(plot.plots[i].bndLine.Count.ToString(CultureInfo.InvariantCulture)); - if (plot.plots[i].bndLine.Count > 0) + writer.WriteLine(plot.plots[i].fenceLine.Count.ToString(CultureInfo.InvariantCulture)); + if (plot.plots[i].fenceLine.Count > 0) { - for (int j = 0; j < plot.plots[i].bndLine.Count; j++) - writer.WriteLine(Math.Round(plot.plots[i].bndLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].bndLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].bndLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < plot.plots[i].fenceLine.Count; j++) + writer.WriteLine(Math.Round(plot.plots[i].fenceLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].fenceLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].fenceLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); } } } @@ -1705,7 +1705,7 @@ public void FileSaveFieldKML() //coords kml.WriteStartElement("coordinates"); string bndPts = ""; - if (plot.plots[i].bndLine.Count > 3) + if (plot.plots[i].fenceLine.Count > 3) bndPts = GetBoundaryPointsLatLon(i); kml.WriteRaw(bndPts); kml.WriteEndElement(); // @@ -1949,12 +1949,12 @@ public string GetBoundaryPointsLatLon(int bndNum) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < plot.plots[bndNum].bndLine.Count; i++) + for (int i = 0; i < plot.plots[bndNum].fenceLine.Count; i++) { double lat = 0; double lon = 0; - pn.ConvertLocalToWGS84(plot.plots[bndNum].bndLine[i].northing, plot.plots[bndNum].bndLine[i].easting, out lat, out lon); + pn.ConvertLocalToWGS84(plot.plots[bndNum].fenceLine[i].northing, plot.plots[bndNum].fenceLine[i].easting, out lat, out lon); sb.Append(lon.ToString("N7", CultureInfo.InvariantCulture) + ',' + lat.ToString("N7", CultureInfo.InvariantCulture) + ",0 "); } From 2fde294f8770e6e69836d5523e170cf7ed0d0fca Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Mon, 25 Oct 2021 15:53:26 -0600 Subject: [PATCH 04/18] plot -> bnd and bndList --- SourceCode/GPS/Classes/CABCurve.cs | 10 +-- SourceCode/GPS/Classes/CABLine.cs | 8 +- SourceCode/GPS/Classes/CBoundary.cs | 2 +- SourceCode/GPS/Classes/CContour.cs | 12 +-- SourceCode/GPS/Classes/CFence.cs | 12 +-- SourceCode/GPS/Classes/CFieldData.cs | 8 +- SourceCode/GPS/Classes/CHead.cs | 20 ++--- SourceCode/GPS/Classes/CTram.cs | 26 +++--- SourceCode/GPS/Classes/CTurn.cs | 88 +++++++++---------- SourceCode/GPS/Classes/CVehicle.cs | 12 +-- SourceCode/GPS/Classes/CYouTurn.cs | 78 ++++++++-------- SourceCode/GPS/Forms/Controls.Designer.cs | 24 ++--- SourceCode/GPS/Forms/FormBoundary.cs | 60 ++++++------- SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 60 ++++++------- SourceCode/GPS/Forms/FormFieldKML.cs | 14 +-- SourceCode/GPS/Forms/FormGPS.cs | 8 +- SourceCode/GPS/Forms/FormHeadland.cs | 24 ++--- SourceCode/GPS/Forms/GUI.Designer.cs | 6 +- SourceCode/GPS/Forms/Guidance/FormABDraw.cs | 30 +++---- SourceCode/GPS/Forms/OpenGL.Designer.cs | 62 ++++++------- SourceCode/GPS/Forms/Pickers/FormTouchPick.cs | 2 +- SourceCode/GPS/Forms/Position.designer.cs | 42 ++++----- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 60 ++++++------- .../Forms/Settings/ConfigModule.Designer.cs | 2 +- 24 files changed, 335 insertions(+), 335 deletions(-) diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index de9f27ad3..7cb578218 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -683,7 +683,7 @@ public void BuildTram() mf.tram.tramList?.Clear(); mf.tram.tramArr?.Clear(); - bool isBndExist = mf.plot.plots.Count != 0; + bool isBndExist = mf.bnd.bndList.Count != 0; double pass = 0.5; @@ -735,7 +735,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar )) + if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar )) { mf.tram.tramArr.Add(point); } @@ -744,7 +744,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) + if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -816,7 +816,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) + if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -825,7 +825,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) + if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index b08b15e2e..1b86caec5 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -452,7 +452,7 @@ public void BuildTram() mf.tram.tramArr?.Clear(); List tramRef = new List(); - bool isBndExist = mf.plot.plots.Count != 0; + bool isBndExist = mf.bnd.bndList.Count != 0; double pass = 0.5; double hsin = Math.Sin(abHeading); @@ -495,7 +495,7 @@ public void BuildTram() if (isBndExist) { - if (mf.plot.plots[0].IsPointInPolygon(P1, ref mf.plot.plots[0].fenceLineEar)) + if (mf.bnd.bndList[0].IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(P1); } @@ -523,7 +523,7 @@ public void BuildTram() if (isBndExist) { - if (mf.plot.plots[0].IsPointInPolygon(P1, ref mf.plot.plots[0].fenceLineEar)) + if (mf.bnd.bndList[0].IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(P1); } @@ -538,7 +538,7 @@ public void BuildTram() tramRef?.Clear(); //outside tram - if (mf.plot.plots.Count == 0 || mf.tram.passes != 0) + if (mf.bnd.bndList.Count == 0 || mf.tram.passes != 0) { //return; } diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index 807bfdceb..7a67962d7 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -9,7 +9,7 @@ public partial class CBoundary //copy of the mainform address private readonly FormGPS mf; - public List plots = new List(); + public List bndList = new List(); //constructor public CBoundary(FormGPS _f) diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index b61895a5f..4ae78d278 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -924,7 +924,7 @@ public void StopContourLine(vec3 pivot) //build contours for boundaries public void BuildFenceContours(int pass, int spacingInt) { - if (mf.plot.plots.Count == 0) + if (mf.bnd.bndList.Count == 0) { mf.TimedMessageBox(1500, "Boundary Contour Error", "No Boundaries Made"); return; @@ -950,10 +950,10 @@ public void BuildFenceContours(int pass, int spacingInt) //totalHeadWidth = (mf.tool.toolWidth - mf.tool.toolOverlap) * 0.5 + 0.2 + (mf.tool.toolWidth - mf.tool.toolOverlap); - for (int j = 0; j < mf.plot.plots.Count; j++) + for (int j = 0; j < mf.bnd.bndList.Count; j++) { //count the points from the boundary - int ptCount = mf.plot.plots[j].fenceLine.Count; + int ptCount = mf.bnd.bndList[j].fenceLine.Count; ptList = new List(128); stripList.Add(ptList); @@ -961,9 +961,9 @@ public void BuildFenceContours(int pass, int spacingInt) for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.plot.plots[j].fenceLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.plot.plots[j].fenceLine[i].heading) * totalHeadWidth); - point.northing = mf.plot.plots[j].fenceLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.plot.plots[j].fenceLine[i].heading) * totalHeadWidth); - point.heading = mf.plot.plots[j].fenceLine[i].heading - Math.PI; + point.easting = mf.bnd.bndList[j].fenceLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.bnd.bndList[j].fenceLine[i].heading) * totalHeadWidth); + point.northing = mf.bnd.bndList[j].fenceLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.bnd.bndList[j].fenceLine[i].heading) * totalHeadWidth); + point.heading = mf.bnd.bndList[j].fenceLine[i].heading - Math.PI; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if inside actual field boundary diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs index fc41e2cf3..cdbbcaf78 100644 --- a/SourceCode/GPS/Classes/CFence.cs +++ b/SourceCode/GPS/Classes/CFence.cs @@ -24,13 +24,13 @@ public partial class CBoundary public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) { //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (plots[0].IsPointInPolygon(testPoint, ref plots[0].fenceLine)) + if (bndList[0].IsPointInPolygon(testPoint, ref bndList[0].fenceLine)) { - for (int i = 1; i < plots.Count; i++) + for (int i = 1; i < bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (plots[i].isDriveThru) continue; - if (plots[i].IsPointInPolygon(testPoint, ref plots[i].fenceLine)) + if (bndList[i].isDriveThru) continue; + if (bndList[i].IsPointInPolygon(testPoint, ref bndList[i].fenceLine)) { return false; } @@ -49,9 +49,9 @@ public void DrawBoundaryLines() //draw the boundaries GL.Color3(0.75f, 0.5f, 0.250f); - for (int i = 0; i < plots.Count; i++) + for (int i = 0; i < bndList.Count; i++) { - plots[i].DrawFenceLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); + bndList[i].DrawFenceLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); } if (bndBeingMadePts.Count > 0) diff --git a/SourceCode/GPS/Classes/CFieldData.cs b/SourceCode/GPS/Classes/CFieldData.cs index d76e520ce..72adb8a0a 100644 --- a/SourceCode/GPS/Classes/CFieldData.cs +++ b/SourceCode/GPS/Classes/CFieldData.cs @@ -132,14 +132,14 @@ public CFieldData(FormGPS _f) public void UpdateFieldBoundaryGUIAreas() { - if (mf.plot.plots.Count > 0) + if (mf.bnd.bndList.Count > 0) { - areaOuterBoundary = mf.plot.plots[0].area; + areaOuterBoundary = mf.bnd.bndList[0].area; areaBoundaryOuterLessInner = areaOuterBoundary; - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { - areaBoundaryOuterLessInner -= mf.plot.plots[i].area; + areaBoundaryOuterLessInner -= mf.bnd.bndList[i].area; } } else diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index e7379034e..71c10f30a 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -37,7 +37,7 @@ public void SetHydPosition() public void WhereAreToolCorners() { - if (plots.Count > 0 && plots[0].hdLine.Count > 0) + if (bndList.Count > 0 && bndList[0].hdLine.Count > 0) { bool isLeftInWk, isRightInWk = true; @@ -48,8 +48,8 @@ public void WhereAreToolCorners() if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftInWk = plots[0].IsPointInPolygon(mf.section[j].leftPoint, ref plots[0].hdLine); - isRightInWk = plots[0].IsPointInPolygon(mf.section[j].rightPoint, ref plots[0].hdLine); + isLeftInWk = bndList[0].IsPointInPolygon(mf.section[j].leftPoint, ref bndList[0].hdLine); + isRightInWk = bndList[0].IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); //save left side mf.tool.isLeftSideInHeadland = !isLeftInWk; @@ -62,7 +62,7 @@ public void WhereAreToolCorners() { //grab the right of previous section, its the left of this section isLeftInWk = isRightInWk; - isRightInWk = plots[0].IsPointInPolygon(mf.section[j].rightPoint, ref plots[0].hdLine); + isRightInWk = bndList[0].IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } @@ -84,7 +84,7 @@ public void WhereAreToolCorners() public void WhereAreToolLookOnPoints() { - if (plots.Count > 0 && plots[0].hdLine.Count > 0) + if (bndList.Count > 0 && bndList[0].hdLine.Count > 0) { vec3 toolFix = mf.toolPos; double sinAB = Math.Sin(toolFix.heading); @@ -128,9 +128,9 @@ public void WhereAreToolLookOnPoints() public void DrawHeadLines() { - for (int i = 0; i < plots.Count; i++) + for (int i = 0; i < bndList.Count; i++) { - if (plots[i].hdLine.Count > 0) plots[i].DrawHeadLine(); + if (bndList[i].hdLine.Count > 0) bndList[i].DrawHeadLine(); } @@ -156,11 +156,11 @@ public void DrawHeadLines() public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add - if (plots.Count > 0 && plots[0].IsPointInPolygon(pt, ref plots[0].hdLine)) + if (bndList.Count > 0 && bndList[0].IsPointInPolygon(pt, ref bndList[0].hdLine)) { - for (int b = 1; b < plots.Count; b++) + for (int b = 1; b < bndList.Count; b++) { - if (plots[b].IsPointInPolygon(pt, ref plots[b].hdLine)) + if (bndList[b].IsPointInPolygon(pt, ref bndList[b].hdLine)) { //point is in an inner turn area but inside outer return false; diff --git a/SourceCode/GPS/Classes/CTram.cs b/SourceCode/GPS/Classes/CTram.cs index f00222a02..3a8efe3fb 100644 --- a/SourceCode/GPS/Classes/CTram.cs +++ b/SourceCode/GPS/Classes/CTram.cs @@ -84,7 +84,7 @@ public void DrawTram() public void BuildTramBnd() { - bool isBndExist = mf.plot.plots.Count != 0; + bool isBndExist = mf.bnd.bndList.Count != 0; if (isBndExist) { @@ -101,7 +101,7 @@ public void BuildTramBnd() private void CreateBndInnerTramTrack() { //count the points from the boundary - int ptCount = mf.plot.plots[0].fenceLine.Count; + int ptCount = mf.bnd.bndList[0].fenceLine.Count; tramBndInnerArr?.Clear(); //outside point @@ -113,18 +113,18 @@ private void CreateBndInnerTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].fenceLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.easting = mf.bnd.bndList[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); - pt3.northing = mf.plot.plots[0].fenceLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.northing = mf.bnd.bndList[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); + mf.bnd.bndList[0].fenceLine[j].northing, mf.bnd.bndList[0].fenceLine[j].easting); if (check < distSq) { Add = false; @@ -149,7 +149,7 @@ private void CreateBndInnerTramTrack() public void CreateBndOuterTramTrack() { //count the points from the boundary - int ptCount = mf.plot.plots[0].fenceLine.Count; + int ptCount = mf.bnd.bndList[0].fenceLine.Count; tramBndOuterArr?.Clear(); //outside point @@ -161,18 +161,18 @@ public void CreateBndOuterTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].fenceLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.easting = mf.bnd.bndList[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); - pt3.northing = mf.plot.plots[0].fenceLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.northing = mf.bnd.bndList[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); + mf.bnd.bndList[0].fenceLine[j].northing, mf.bnd.bndList[0].fenceLine[j].easting); if (check < distSq) { Add = false; diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index 7a8b37987..118180603 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -38,13 +38,13 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (plots[0].IsPointInPolygon(pt, ref plots[0].turnLine)) + if (bndList[0].IsPointInPolygon(pt, ref bndList[0].turnLine)) { - for (int t = 1; t < plots.Count; t++) + for (int t = 1; t < bndList.Count; t++) { - if (plots[t].isDriveThru) continue; - if (plots[t].isDriveAround) continue; - if (plots[t].IsPointInPolygon(pt, ref plots[0].turnLine)) + if (bndList[t].isDriveThru) continue; + if (bndList[t].isDriveAround) continue; + if (bndList[t].IsPointInPolygon(pt, ref bndList[0].turnLine)) { isFound = true; closestTurnNum = t; @@ -95,25 +95,25 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB vec4 inBox; - int ptCount = plots[closestTurnNum].turnLine.Count; + int ptCount = bndList[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (plots[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (plots[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (plots[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (plots[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (plots[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (plots[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (plots[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (plots[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = plots[closestTurnNum].turnLine[p].easting; - inBox.northing = plots[closestTurnNum].turnLine[p].northing; - inBox.heading = plots[closestTurnNum].turnLine[p].heading; + inBox.easting = bndList[closestTurnNum].turnLine[p].easting; + inBox.northing = bndList[closestTurnNum].turnLine[p].northing; + inBox.heading = bndList[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -149,26 +149,26 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB //determine if point is inside bounding box of the 1 turn chosen above turnClosestList.Clear(); - ptCount = plots[closestTurnNum].turnLine.Count; + ptCount = bndList[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (plots[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (plots[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (plots[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (plots[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (plots[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (plots[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (plots[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (plots[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = plots[closestTurnNum].turnLine[p].easting; - inBox.northing = plots[closestTurnNum].turnLine[p].northing; - inBox.heading = plots[closestTurnNum].turnLine[p].heading; + inBox.easting = bndList[closestTurnNum].turnLine[p].easting; + inBox.northing = bndList[closestTurnNum].turnLine[p].northing; + inBox.heading = bndList[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -210,7 +210,7 @@ public void BuildTurnLines() //update the GUI values for boundaries mf.fd.UpdateFieldBoundaryGUIAreas(); - if (plots.Count == 0) + if (bndList.Count == 0) { //mf.TimedMessageBox(1500, " No Boundaries", "No Turn Lines Made"); return; @@ -223,29 +223,29 @@ public void BuildTurnLines() double totalHeadWidth = mf.yt.uturnDistanceFromBoundary; //inside boundaries - for (int j = 0; j < plots.Count; j++) + for (int j = 0; j < bndList.Count; j++) { - plots[j].turnLine.Clear(); - if (plots[j].isDriveThru || plots[j].isDriveAround) continue; + bndList[j].turnLine.Clear(); + if (bndList[j].isDriveThru || bndList[j].isDriveAround) continue; - int ptCount = plots[j].fenceLine.Count; + int ptCount = bndList[j].fenceLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point outside the boundary - point.easting = plots[j].fenceLine[i].easting + (-Math.Sin(glm.PIBy2 + plots[j].fenceLine[i].heading) * totalHeadWidth); - point.northing = plots[j].fenceLine[i].northing + (-Math.Cos(glm.PIBy2 + plots[j].fenceLine[i].heading) * totalHeadWidth); - point.heading = plots[j].fenceLine[i].heading; + point.easting = bndList[j].fenceLine[i].easting + (-Math.Sin(glm.PIBy2 + bndList[j].fenceLine[i].heading) * totalHeadWidth); + point.northing = bndList[j].fenceLine[i].northing + (-Math.Cos(glm.PIBy2 + bndList[j].fenceLine[i].heading) * totalHeadWidth); + point.heading = bndList[j].fenceLine[i].heading; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == plots[j].IsPointInPolygon(point, ref plots[j].fenceLineEar)) + if (j == 0 == bndList[j].IsPointInPolygon(point, ref bndList[j].fenceLineEar)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); - plots[j].turnLine.Add(tPnt); + bndList[j].turnLine.Add(tPnt); } } - plots[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); + bndList[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); } } @@ -255,17 +255,17 @@ public void DrawTurnLines() GL.Color3(0.3555f, 0.6232f, 0.20f); //GL.PointSize(2); - for (int i = 0; i < plots.Count; i++) + for (int i = 0; i < bndList.Count; i++) { - if (plots[i].isDriveAround) continue; + if (bndList[i].isDriveAround) continue; //turnArr[i].DrawTurnLine(); { ////draw the turn line oject - int ptCount = plots[i].turnLine.Count; + int ptCount = bndList[i].turnLine.Count; if (ptCount < 1) continue; GL.Begin(PrimitiveType.LineLoop); - for (int h = 0; h < ptCount; h++) GL.Vertex3(plots[i].turnLine[h].easting, plots[i].turnLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(bndList[i].turnLine[h].easting, bndList[i].turnLine[h].northing, 0); GL.End(); } } diff --git a/SourceCode/GPS/Classes/CVehicle.cs b/SourceCode/GPS/Classes/CVehicle.cs index e2076105b..977b12296 100644 --- a/SourceCode/GPS/Classes/CVehicle.cs +++ b/SourceCode/GPS/Classes/CVehicle.cs @@ -408,9 +408,9 @@ public void DrawVehicle() GL.End(); } - if (mf.plot.isBndBeingMade) + if (mf.bnd.isBndBeingMade) { - if (mf.plot.isDrawRightSide) + if (mf.bnd.isDrawRightSide) { GL.LineWidth(2); GL.Color3(0.0, 1.270, 0.0); @@ -418,8 +418,8 @@ public void DrawVehicle() { GL.Vertex3(0.0, 0, 0); GL.Color3(1.270, 1.220, 0.20); - GL.Vertex3(mf.plot.createBndOffset, 0, 0); - GL.Vertex3(mf.plot.createBndOffset * 0.75, 0.25, 0); + GL.Vertex3(mf.bnd.createBndOffset, 0, 0); + GL.Vertex3(mf.bnd.createBndOffset * 0.75, 0.25, 0); } GL.End(); } @@ -433,8 +433,8 @@ public void DrawVehicle() { GL.Vertex3(0.0, 0, 0); GL.Color3(1.270, 1.220, 0.20); - GL.Vertex3(-mf.plot.createBndOffset, 0, 0); - GL.Vertex3(-mf.plot.createBndOffset * 0.75, 0.25, 0); + GL.Vertex3(-mf.bnd.createBndOffset, 0, 0); + GL.Vertex3(-mf.bnd.createBndOffset * 0.75, 0.25, 0); } GL.End(); } diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index 26bf06e86..00fb32256 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -115,7 +115,7 @@ public bool FindCurveTurnPoints() //for each point in succession keep going till a turnLine is found. for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) { - if (!mf.plot.plots[0].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[0].turnLine)) + if (!mf.bnd.bndList[0].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -125,12 +125,12 @@ public bool FindCurveTurnPoints() goto CrossingFound; } - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.plot.plots[i].isDriveThru) continue; - if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[i].turnLine)) + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (mf.bnd.bndList[i].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) { crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -152,7 +152,7 @@ public bool FindCurveTurnPoints() for (int j = mf.curve.currentLocationIndex; j > 0; j--) { - if (!mf.plot.plots[0].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[0].turnLine)) + if (!mf.bnd.bndList[0].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; @@ -162,12 +162,12 @@ public bool FindCurveTurnPoints() goto CrossingFound; } - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.plot.plots[i].isDriveThru) continue; - if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[i].turnLine)) + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (mf.bnd.bndList[i].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) { crossingCurvePoint.easting = mf.curve.curList[j].easting; crossingCurvePoint.northing = mf.curve.curList[j].northing; @@ -191,17 +191,17 @@ public bool FindCurveTurnPoints() return false; } - int curTurnLineCount = mf.plot.plots[turnNum].turnLine.Count; + int curTurnLineCount = mf.bnd.bndList[turnNum].turnLine.Count; //possible points close to AB Curve point List turnLineCloseList = new List(); for (int j = 0; j < curTurnLineCount; j++) { - if ((mf.plot.plots[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 - && (mf.plot.plots[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 - && (mf.plot.plots[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 - && (mf.plot.plots[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) + if ((mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 + && (mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 + && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 + && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) { turnLineCloseList.Add(j); } @@ -211,8 +211,8 @@ public bool FindCurveTurnPoints() curTurnLineCount = turnLineCloseList.Count; for (int i = 0; i < curTurnLineCount; i++) { - dist1 = glm.Distance(mf.plot.plots[turnNum].turnLine[turnLineCloseList[i]].easting, - mf.plot.plots[turnNum].turnLine[turnLineCloseList[i]].northing, + dist1 = glm.Distance(mf.bnd.bndList[turnNum].turnLine[turnLineCloseList[i]].easting, + mf.bnd.bndList[turnNum].turnLine[turnLineCloseList[i]].northing, crossingCurvePoint.easting, crossingCurvePoint.northing); if (dist1 < dist2) { @@ -222,9 +222,9 @@ public bool FindCurveTurnPoints() } //fill up the coords - crossingTurnLinePoint.easting = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].easting; - crossingTurnLinePoint.northing = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].northing; - crossingTurnLinePoint.heading = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].heading; + crossingTurnLinePoint.easting = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].easting; + crossingTurnLinePoint.northing = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].northing; + crossingTurnLinePoint.heading = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].heading; return crossingCurvePoint.easting != -20000 && crossingCurvePoint.easting != -20000; } @@ -387,12 +387,12 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) vec3 onPurePoint = new vec3(mf.ABLine.rEastAB, mf.ABLine.rNorthAB, 0); //how far are we from any turn boundary - mf.plot.FindClosestTurnPoint(isYouTurnRight, onPurePoint, headAB); + mf.bnd.FindClosestTurnPoint(isYouTurnRight, onPurePoint, headAB); //or did we lose the turnLine - we are on the highway cuz we left the outer/inner turn boundary - if ((int)mf.plot.closestTurnPt.easting != -20000) + if ((int)mf.bnd.closestTurnPt.easting != -20000) { - mf.distancePivotToTurnLine = glm.Distance(mf.pivotAxlePos, mf.plot.closestTurnPt); + mf.distancePivotToTurnLine = glm.Distance(mf.pivotAxlePos, mf.bnd.closestTurnPt); } else { @@ -401,7 +401,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) } //delta between AB heading and boundary closest point heading - boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(mf.plot.closestTurnPt.heading - headAB) - Math.PI); + boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(mf.bnd.closestTurnPt.heading - headAB) - Math.PI); boundaryAngleOffPerpendicular -= glm.PIBy2; boundaryAngleOffPerpendicular *= -1; if (boundaryAngleOffPerpendicular > 1.25) boundaryAngleOffPerpendicular = 1.25; @@ -584,15 +584,15 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.plot.plots[0].IsPointInPolygon(ytList[j],ref mf.plot.plots[0].turnLine)) isOutOfBounds = true; + if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j],ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; if (isOutOfBounds) break; - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.plot.plots[i].isDriveThru) continue; - if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[i].turnLine)) + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) { isOutOfBounds = true; break; @@ -644,16 +644,16 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.plot.plots[0].IsPointInPolygon(ytList[j], ref mf.plot.plots[0].turnLine)) isOutOfBounds = true; + if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; if (isOutOfBounds) break; - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.plot.plots[i].isDriveThru) continue; - if (mf.plot.plots[i].isDriveAround) continue; - if (!mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[i].turnLine)) + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (!mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) { isOutOfBounds = true; break; @@ -852,18 +852,18 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!mf.plot.plots[0].IsPointInPolygon(ytList[j], ref mf.plot.plots[0].turnLine)) + if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) { isOutOfBounds = true; break; } - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.plot.plots[i].isDriveThru) continue; - if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[1].turnLine)) + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[1].turnLine)) { isOutOfBounds = true; break; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index 76a7f2beb..0c1cc25dc 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -355,7 +355,7 @@ private void btnAutoYouTurn_Click(object sender, EventArgs e) { yt.isTurnCreationTooClose = false; - if (plot.plots.Count == 0) + if (bnd.bndList.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1494,7 +1494,7 @@ private void BtnMakeLinesFromBoundary_Click(object sender, EventArgs e) return; } - if (plot.plots.Count == 0) + if (bnd.bndList.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1549,10 +1549,10 @@ private void cboxpRowWidth_SelectedIndexChanged(object sender, EventArgs e) private void btnHeadlandOnOff_Click(object sender, EventArgs e) { - if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) + if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) { - plot.isHeadlandOn = !plot.isHeadlandOn; - if (plot.isHeadlandOn) + bnd.isHeadlandOn = !bnd.isHeadlandOn; + if (bnd.isHeadlandOn) { btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHydLift.Visible = true; @@ -1563,9 +1563,9 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; } } - else plot.isHeadlandOn = false; + else bnd.isHeadlandOn = false; - if (!plot.isHeadlandOn) + if (!bnd.isHeadlandOn) { p_239.pgn[p_239.hydLift] = 0; vehicle.isHydLiftOn = false; @@ -1577,7 +1577,7 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) private void btnHydLift_Click(object sender, EventArgs e) { - if (plot.isHeadlandOn) + if (bnd.isHeadlandOn) { vehicle.isHydLiftOn = !vehicle.isHydLiftOn; if (vehicle.isHydLiftOn) @@ -1959,7 +1959,7 @@ private void tramLinesMenuField_Click(object sender, EventArgs e) } private void headlandToolStripMenuItem_Click(object sender, EventArgs e) { - if (plot.plots.Count == 0) + if (bnd.bndList.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1974,9 +1974,9 @@ public void GetHeadland() form.ShowDialog(); } - if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) + if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) { - plot.isHeadlandOn = true; + bnd.isHeadlandOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -1984,7 +1984,7 @@ public void GetHeadland() } else { - plot.isHeadlandOn = false; + bnd.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index 7df2c5359..4718ceb52 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -59,7 +59,7 @@ private void UpdateChart() Font backupfont = new Font(Font.FontFamily, 18F, FontStyle.Bold); - for (int i = 0; i < mf.plot.plots.Count && i < 6; i++) + for (int i = 0; i < mf.bnd.bndList.Count && i < 6; i++) { //outer inner Button a = new Button @@ -118,11 +118,11 @@ private void UpdateChart() if (i == 0) { //cc.Text = "Outer"; - mf.plot.plots[i].isDriveThru = false; - mf.plot.plots[i].isDriveAround = false; + mf.bnd.bndList[i].isDriveThru = false; + mf.bnd.bndList[i].isDriveAround = false; a.Text = string.Format(gStr.gsOuter); //a.Font = backupfont; - d.Text = mf.plot.plots[i].isDriveThru ? "--" : "--"; + d.Text = mf.bnd.bndList[i].isDriveThru ? "--" : "--"; d.Enabled = false; d.Anchor = System.Windows.Forms.AnchorStyles.None; a.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -135,7 +135,7 @@ private void UpdateChart() inner += 1; a.Text = string.Format(gStr.gsInner + " {0}", inner); //a.Font = backupfont; - d.Text = mf.plot.plots[i].isDriveThru ? "Yes" : "No"; + d.Text = mf.bnd.bndList[i].isDriveThru ? "Yes" : "No"; d.Anchor = System.Windows.Forms.AnchorStyles.None; a.Anchor = System.Windows.Forms.AnchorStyles.None; b.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -144,14 +144,14 @@ private void UpdateChart() if (mf.isMetric) { - b.Text = Math.Round(mf.plot.plots[i].area * 0.0001, 2).ToString() + " Ha"; + b.Text = Math.Round(mf.bnd.bndList[i].area * 0.0001, 2).ToString() + " Ha"; } else { - b.Text = Math.Round(mf.plot.plots[i].area * 0.000247105, 2) + " Ac"; + b.Text = Math.Round(mf.bnd.bndList[i].area * 0.000247105, 2) + " Ac"; } - if (Selectedreset == false && i == mf.plot.fenceSelected) + if (Selectedreset == false && i == mf.bnd.fenceSelected) { a.ForeColor = Color.OrangeRed; b.ForeColor = Color.OrangeRed; @@ -168,9 +168,9 @@ private void DriveThru_Click(object sender, EventArgs e) { if (sender is Button b) { - mf.plot.plots[Convert.ToInt32(b.Name)].isDriveThru = !mf.plot.plots[Convert.ToInt32(b.Name)].isDriveThru; + mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveThru = !mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveThru; UpdateChart(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); } } @@ -178,7 +178,7 @@ private void DriveAround_Click(object sender, EventArgs e) { if (sender is Button b) { - mf.plot.plots[Convert.ToInt32(b.Name)].isDriveAround = !mf.plot.plots[Convert.ToInt32(b.Name)].isDriveAround; + mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround = !mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround; UpdateChart(); } } @@ -188,16 +188,16 @@ private void B_Click(object sender, EventArgs e) if (sender is Button b) { - mf.plot.fenceSelected = Convert.ToInt32(b.Name); + mf.bnd.fenceSelected = Convert.ToInt32(b.Name); - if (mf.plot.fenceSelected == 0 && mf.plot.plots.Count > 1) + if (mf.bnd.fenceSelected == 0 && mf.bnd.bndList.Count > 1) { return; } Selectedreset = false; - if (mf.plot.plots.Count > mf.plot.fenceSelected) + if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) { btnDelete.Enabled = true; } @@ -213,7 +213,7 @@ private void B_Click(object sender, EventArgs e) private void btnSerialCancel_Click(object sender, EventArgs e) { - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; } private void btnDelete_Click(object sender, EventArgs e) @@ -229,17 +229,17 @@ private void btnDelete_Click(object sender, EventArgs e) btnDelete.Enabled = false; - if (mf.plot.plots.Count > mf.plot.fenceSelected) + if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) { - mf.plot.plots.RemoveAt(mf.plot.fenceSelected); + mf.bnd.bndList.RemoveAt(mf.bnd.fenceSelected); } mf.FileSaveBoundary(); - mf.plot.fenceSelected = -1; + mf.bnd.fenceSelected = -1; Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); UpdateChart(); } else @@ -250,13 +250,13 @@ private void btnDelete_Click(object sender, EventArgs e) private void ResetAllBoundary() { - mf.plot.plots.Clear(); + mf.bnd.bndList.Clear(); mf.FileSaveBoundary(); tableLayoutPanel1.Controls.Clear(); tableLayoutPanel1.RowStyles.Clear(); UpdateChart(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); btnDelete.Enabled = false; } @@ -282,10 +282,10 @@ private void btnDeleteAll_Click(object sender, EventArgs e) ResetAllBoundary(); - mf.plot.fenceSelected = -1; + mf.bnd.fenceSelected = -1; Selectedreset = true; - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; mf.fd.UpdateFieldBoundaryGUIAreas(); } else @@ -297,7 +297,7 @@ private void btnDeleteAll_Click(object sender, EventArgs e) private void btnReturn_Click(object sender, EventArgs e) { - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; panelMain.Visible = true; panelChoose.Visible = false; @@ -310,7 +310,7 @@ private void btnReturn_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e) { - mf.plot.fenceSelected = mf.plot.plots.Count; + mf.bnd.fenceSelected = mf.bnd.bndList.Count; Selectedreset = false; @@ -353,7 +353,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) { if (button.Name == "btnLoadMultiBoundaryFromGE") ResetAllBoundary(); - else i = mf.plot.fenceSelected; + else i = mf.bnd.fenceSelected; try { @@ -408,10 +408,10 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) New.fenceLine.Add(new vec3(easting, norting, 0)); } - New.CalculateFenceArea(mf.plot.fenceSelected); + New.CalculateFenceArea(mf.bnd.fenceSelected); New.FixFenceLine(i); - mf.plot.plots.Add(New); + mf.bnd.bndList.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); @@ -431,7 +431,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) } } mf.FileSaveBoundary(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); mf.btnMakeLinesFromBoundary.Visible = true; mf.fd.UpdateFieldBoundaryGUIAreas(); UpdateChart(); @@ -442,7 +442,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) } } } - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; panelMain.Visible = true; panelChoose.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 59b15796d..007aa0e2d 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -27,34 +27,34 @@ public FormBoundaryPlayer(Form callingForm) private void btnStop_Click(object sender, EventArgs e) { - if (mf.plot.bndBeingMadePts.Count > 2) + if (mf.bnd.bndBeingMadePts.Count > 2) { CBoundaryList New = new CBoundaryList(); - for (int i = 0; i < mf.plot.bndBeingMadePts.Count; i++) + for (int i = 0; i < mf.bnd.bndBeingMadePts.Count; i++) { - New.fenceLine.Add(mf.plot.bndBeingMadePts[i]); + New.fenceLine.Add(mf.bnd.bndBeingMadePts[i]); } - New.CalculateFenceArea(mf.plot.fenceSelected); - New.FixFenceLine(mf.plot.fenceSelected); + New.CalculateFenceArea(mf.bnd.fenceSelected); + New.FixFenceLine(mf.bnd.fenceSelected); - mf.plot.plots.Add(New); + mf.bnd.bndList.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); } //stop it all for adding - mf.plot.isOkToAddPoints = false; - mf.plot.isBndBeingMade = false; + mf.bnd.isOkToAddPoints = false; + mf.bnd.isBndBeingMade = false; //turn lines made from boundaries mf.CalculateMinMax(); mf.FileSaveBoundary(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); //mf.hd.BuildSingleSpaceHeadLines(); mf.btnMakeLinesFromBoundary.Visible = true; - mf.plot.bndBeingMadePts.Clear(); + mf.bnd.bndBeingMadePts.Clear(); //close window Close(); } @@ -62,9 +62,9 @@ private void btnStop_Click(object sender, EventArgs e) //actually the record button private void btnPausePlay_Click(object sender, EventArgs e) { - if (mf.plot.isOkToAddPoints) + if (mf.bnd.isOkToAddPoints) { - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; btnPausePlay.Image = Properties.Resources.BoundaryRecord; //btnPausePlay.Text = gStr.gsRecord; btnAddPoint.Enabled = true; @@ -72,7 +72,7 @@ private void btnPausePlay_Click(object sender, EventArgs e) } else { - mf.plot.isOkToAddPoints = true; + mf.bnd.isOkToAddPoints = true; btnPausePlay.Image = Properties.Resources.boundaryPause; //btnPausePlay.Text = gStr.gsPause; btnAddPoint.Enabled = false; @@ -86,15 +86,15 @@ private void FormBoundaryPlayer_Load(object sender, EventArgs e) //mf.bnd.isOkToAddPoints = false; nudOffset.Value = (decimal)(mf.tool.toolWidth * 0.5); btnPausePlay.Image = Properties.Resources.BoundaryRecord; - btnLeftRight.Image = mf.plot.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; - mf.plot.createBndOffset = (double)nudOffset.Value; - mf.plot.isBndBeingMade = true; + btnLeftRight.Image = mf.bnd.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; + mf.bnd.createBndOffset = (double)nudOffset.Value; + mf.bnd.isBndBeingMade = true; mf.Focus(); } private void timer1_Tick(object sender, EventArgs e) { - int ptCount = mf.plot.bndBeingMadePts.Count; + int ptCount = mf.bnd.bndBeingMadePts.Count; double area = 0; if (ptCount > 0) @@ -103,7 +103,7 @@ private void timer1_Tick(object sender, EventArgs e) for (int i = 0; i < ptCount; j = i++) { - area += (mf.plot.bndBeingMadePts[j].easting + mf.plot.bndBeingMadePts[i].easting) * (mf.plot.bndBeingMadePts[j].northing - mf.plot.bndBeingMadePts[i].northing); + area += (mf.bnd.bndBeingMadePts[j].easting + mf.bnd.bndBeingMadePts[i].easting) * (mf.bnd.bndBeingMadePts[j].northing - mf.bnd.bndBeingMadePts[i].northing); } area = Math.Abs(area / 2); } @@ -115,27 +115,27 @@ private void timer1_Tick(object sender, EventArgs e) { lblArea.Text = Math.Round(area * 0.000247105, 2) + " Acre"; } - lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); + lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); } private void btnAddPoint_Click(object sender, EventArgs e) { - mf.plot.isOkToAddPoints = true; + mf.bnd.isOkToAddPoints = true; mf.AddBoundaryPoint(); - mf.plot.isOkToAddPoints = false; - lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); + mf.bnd.isOkToAddPoints = false; + lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); mf.Focus(); } private void btnDeleteLast_Click(object sender, EventArgs e) { - int ptCount = mf.plot.bndBeingMadePts.Count; + int ptCount = mf.bnd.bndBeingMadePts.Count; if (ptCount > 0) - mf.plot.bndBeingMadePts.RemoveAt(ptCount - 1); - lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); + mf.bnd.bndBeingMadePts.RemoveAt(ptCount - 1); + lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); mf.Focus(); } @@ -148,8 +148,8 @@ private void btnRestart_Click(object sender, EventArgs e) MessageBoxDefaultButton.Button2); if (result3 == DialogResult.Yes) { - mf.plot.bndBeingMadePts?.Clear(); - lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); + mf.bnd.bndBeingMadePts?.Clear(); + lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); } mf.Focus(); } @@ -158,13 +158,13 @@ private void nudOffset_Click(object sender, EventArgs e) { mf.KeypadToNUD((NumericUpDown)sender, this); btnPausePlay.Focus(); - mf.plot.createBndOffset = (double)nudOffset.Value; + mf.bnd.createBndOffset = (double)nudOffset.Value; } private void btnLeftRight_Click(object sender, EventArgs e) { - mf.plot.isDrawRightSide = !mf.plot.isDrawRightSide; - btnLeftRight.Image = mf.plot.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; + mf.bnd.isDrawRightSide = !mf.bnd.isDrawRightSide; + btnLeftRight.Image = mf.bnd.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; } } } \ No newline at end of file diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 22bc7ebf7..5b5a90d9c 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -125,7 +125,7 @@ private void LoadKMLBoundary(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.plot.fenceSelected; + i = mf.bnd.fenceSelected; try { @@ -183,10 +183,10 @@ private void LoadKMLBoundary(string filename) } //build the boundary, make sure is clockwise for outer counter clockwise for inner - New.CalculateFenceArea(mf.plot.fenceSelected); + New.CalculateFenceArea(mf.bnd.fenceSelected); New.FixFenceLine(i); - mf.plot.plots.Add(New); + mf.bnd.bndList.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); @@ -206,7 +206,7 @@ private void LoadKMLBoundary(string filename) } } mf.FileSaveBoundary(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); mf.fd.UpdateFieldBoundaryGUIAreas(); mf.CalculateMinMax(); @@ -221,7 +221,7 @@ private void LoadKMLBoundary(string filename) } } - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; } private void FindLatLon(string filename) @@ -233,7 +233,7 @@ private void FindLatLon(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.plot.fenceSelected; + i = mf.bnd.fenceSelected; try { @@ -312,7 +312,7 @@ private void FindLatLon(string filename) } } - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; } diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index 2e2d2e18c..b4487c1c0 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -187,7 +187,7 @@ public partial class FormGPS : Form /// /// The boundary object /// - public CBoundary plot; + public CBoundary bnd; /// /// The internal simulator @@ -366,7 +366,7 @@ public FormGPS() mc = new CModuleComm(); //boundary object - plot = new CBoundary(this); + bnd = new CBoundary(this); //nmea simulator built in. sim = new CSim(this); @@ -979,7 +979,7 @@ public void JobClose() pn.fixOffset.northing = 0; //turn off headland - plot.isHeadlandOn = false; + bnd.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; @@ -993,7 +993,7 @@ public void JobClose() oglZoom.SendToBack(); //clean all the lines - plot.plots.Clear(); + bnd.bndList.Clear(); panelRight.Enabled = false; FieldMenuButtonEnableDisable(false); diff --git a/SourceCode/GPS/Forms/FormHeadland.cs b/SourceCode/GPS/Forms/FormHeadland.cs index 3ce8739dc..f03b0368a 100644 --- a/SourceCode/GPS/Forms/FormHeadland.cs +++ b/SourceCode/GPS/Forms/FormHeadland.cs @@ -54,10 +54,10 @@ private void FormHeadland_Load(object sender, EventArgs e) nudDistance.Value = 0; nudSetDistance.Value = 0; - if (mf.plot.plots[0].hdLine.Count > 0) + if (mf.bnd.bndList[0].hdLine.Count > 0) { - hdArr = new vec3[mf.plot.plots[0].hdLine.Count]; - mf.plot.plots[0].hdLine.CopyTo(hdArr); + hdArr = new vec3[mf.bnd.bndList[0].hdLine.Count]; + mf.bnd.bndList[0].hdLine.CopyTo(hdArr); RebuildHeadLineTemplate(); } else @@ -80,13 +80,13 @@ public void BuildHeadLineTemplateFromBoundary() //outside boundary - count the points from the boundary headLineTemplate.Clear(); - int ptCount = mf.plot.plots[0].fenceLine.Count; + int ptCount = mf.bnd.bndList[0].fenceLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.plot.plots[0].fenceLine[i].easting; - point.northing = mf.plot.plots[0].fenceLine[i].northing; - point.heading = mf.plot.plots[0].fenceLine[i].heading; + point.easting = mf.bnd.bndList[0].fenceLine[i].easting; + point.northing = mf.bnd.bndList[0].fenceLine[i].northing; + point.heading = mf.bnd.bndList[0].fenceLine[i].heading; headLineTemplate.Add(point); } @@ -334,7 +334,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) //else lblEnd.Text = end.ToString(); //draw all the boundaries - mf.plot.DrawBoundaryLines(); + mf.bnd.DrawBoundaryLines(); int ptCount = hdArr.Length; if (ptCount > 1) @@ -565,7 +565,7 @@ private void timer1_Tick(object sender, EventArgs e) private void btnExit_Click(object sender, EventArgs e) { - mf.plot.plots[0].hdLine?.Clear(); + mf.bnd.bndList[0].hdLine?.Clear(); //middle points for (int i = 1; i < hdArr.Length; i++) @@ -580,7 +580,7 @@ private void btnExit_Click(object sender, EventArgs e) { if (i == 0) { - mf.plot.plots[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); + mf.bnd.bndList[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); continue; } delta += (hdArr[i - 1].heading - hdArr[i].heading); @@ -589,7 +589,7 @@ private void btnExit_Click(object sender, EventArgs e) { vec3 pt = new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading); - mf.plot.plots[0].hdLine.Add(pt); + mf.bnd.bndList[0].hdLine.Add(pt); delta = 0; } } @@ -600,7 +600,7 @@ private void btnExit_Click(object sender, EventArgs e) private void btnTurnOffHeadland_Click(object sender, EventArgs e) { - mf.plot.plots[0].hdLine?.Clear(); + mf.bnd.bndList[0].hdLine?.Clear(); mf.FileSaveHeadland(); diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 2ffa9913f..05b2ecc47 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -125,7 +125,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) // fd.WorkedAreaRemainPercentage +"\r\n" + // fd.TimeTillFinished + "\r\n" + // fd.WorkRateHectares; - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) lblFieldStatus.Text = fd.AreaBoundaryLessInnersHectares + " " + fd.WorkedAreaRemainHectares + " " + fd.TimeTillFinished + " " + fd.WorkedAreaRemainPercentage+" " @@ -136,7 +136,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) } else //imperial { - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) lblFieldStatus.Text = fd.AreaBoundaryLessInnersAcres + " " + fd.WorkedAreaRemainAcres + " " + fd.TimeTillFinished + " " + fd.WorkedAreaRemainPercentage + " " + fd.WorkedAcres; @@ -498,7 +498,7 @@ public void LoadSettings() if (Properties.Settings.Default.setAS_isAutoSteerAutoOn) btnAutoSteer.Text = "R"; else btnAutoSteer.Text = "M"; - if (plot.isHeadlandOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; + if (bnd.isHeadlandOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; else btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnChangeMappingColor.BackColor = sectionColorDay; diff --git a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs index 073fd189d..df3ac41c8 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs @@ -46,21 +46,21 @@ public FormABDraw(Form callingForm) private void FormABDraw_Load(object sender, EventArgs e) { - int cnt = mf.plot.plots[0].fenceLine.Count; + int cnt = mf.bnd.bndList[0].fenceLine.Count; arr = new vec3[cnt * 2]; for (int i = 0; i < cnt; i++) { - arr[i].easting = mf.plot.plots[0].fenceLine[i].easting; - arr[i].northing = mf.plot.plots[0].fenceLine[i].northing; - arr[i].heading = mf.plot.plots[0].fenceLine[i].heading; + arr[i].easting = mf.bnd.bndList[0].fenceLine[i].easting; + arr[i].northing = mf.bnd.bndList[0].fenceLine[i].northing; + arr[i].heading = mf.bnd.bndList[0].fenceLine[i].heading; } for (int i = cnt; i < cnt * 2; i++) { - arr[i].easting = mf.plot.plots[0].fenceLine[i - cnt].easting; - arr[i].northing = mf.plot.plots[0].fenceLine[i - cnt].northing; - arr[i].heading = mf.plot.plots[0].fenceLine[i - cnt].heading; + arr[i].easting = mf.bnd.bndList[0].fenceLine[i - cnt].easting; + arr[i].northing = mf.bnd.bndList[0].fenceLine[i - cnt].northing; + arr[i].heading = mf.bnd.bndList[0].fenceLine[i - cnt].heading; } nudDistance.Value = (decimal)Math.Round(((mf.tool.toolWidth * mf.m2InchOrCm) * 0.5), 0); // @@ -356,7 +356,7 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) { //count the points from the boundary - int ptCount = mf.plot.plots[0].fenceLine.Count; + int ptCount = mf.bnd.bndList[0].fenceLine.Count; mf.curve.refList?.Clear(); //outside point @@ -369,20 +369,20 @@ private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].fenceLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (moveDist)); + pt3.easting = mf.bnd.bndList[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (moveDist)); - pt3.northing = mf.plot.plots[0].fenceLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (moveDist)); + pt3.northing = mf.bnd.bndList[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (moveDist)); - pt3.heading = mf.plot.plots[0].fenceLine[i].heading; + pt3.heading = mf.bnd.bndList[0].fenceLine[i].heading; bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); + mf.bnd.bndList[0].fenceLine[j].northing, mf.bnd.bndList[0].fenceLine[j].easting); if (check < distSq) { Add = false; @@ -669,7 +669,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.plot.DrawBoundaryLines(); + mf.bnd.DrawBoundaryLines(); //the vehicle GL.PointSize(16.0f); diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index 53c2a662a..45aab364f 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -338,21 +338,21 @@ private void oglMain_Paint(object sender, PaintEventArgs e) recPath.DrawDubins(); //draw Boundaries - plot.DrawBoundaryLines(); + bnd.DrawBoundaryLines(); //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) { - plot.DrawTurnLines(); + bnd.DrawTurnLines(); } - if (plot.isHeadlandOn) + if (bnd.isHeadlandOn) { GL.LineWidth(ABLine.lineWidth); GL.Color3(0.960f, 0.96232f, 0.30f); - for (int i = 0; i < plot.plots.Count; i++) + for (int i = 0; i < bnd.bndList.Count; i++) { - if (plot.plots[i].hdLine.Count > 0) plot.plots[i].DrawHeadLine(); + if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLine(); } } @@ -416,7 +416,7 @@ private void oglMain_Paint(object sender, PaintEventArgs e) if ((ahrs.imuRoll != 88888)) DrawRollBar(); - if (plot.plots.Count > 0 && yt.isYouTurnBtnOn) DrawUTurnBtn(); + if (bnd.bndList.Count > 0 && yt.isYouTurnBtnOn) DrawUTurnBtn(); if (isAutoSteerBtnOn && !ct.isContourBtnOn) DrawManUTurnBtn(); @@ -616,29 +616,29 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //draw 240 green for boundary - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) { ////draw the bnd line - int ptCount = plot.plots[0].fenceLine.Count; + int ptCount = bnd.bndList[0].fenceLine.Count; if (ptCount > 3) { GL.LineWidth(3); GL.Color3((byte)0, (byte)240, (byte)0); GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < ptCount; h++) GL.Vertex3(plot.plots[0].fenceLine[h].easting, plot.plots[0].fenceLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(bnd.bndList[0].fenceLine[h].easting, bnd.bndList[0].fenceLine[h].northing, 0); GL.End(); } } //draw 250 green for the headland - if (plot.isHeadlandOn) + if (bnd.isHeadlandOn) { GL.LineWidth(3); GL.Color3((byte)0, (byte)250, (byte)0); - for (int i = 0; i < plot.plots.Count; i++) + for (int i = 0; i < bnd.bndList.Count; i++) { - if (plot.plots[i].hdLine.Count > 0) plot.plots[i].DrawHeadLineBackBuffer(); + if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLineBackBuffer(); } } @@ -677,7 +677,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tool.numOfSections == 1 || pn.speed < vehicle.slowSpeedCutoff) tool.isSuperSectionAllowedOn = false; - if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && plot.isHeadlandOn) + if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && bnd.isHeadlandOn) tool.isSuperSectionAllowedOn = false; //clamp the height after looking way ahead, this is for switching off super section only @@ -687,7 +687,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //10 % min is required for overlap, otherwise it never would be on. int pixLimit = (int)((double)(section[0].rpSectionWidth * rpOnHeight) / (double)(5.0)); - if ((rpOnHeight < rpToolHeight && plot.isHeadlandOn)) rpHeight = rpToolHeight + 2; + if ((rpOnHeight < rpToolHeight && bnd.isHeadlandOn)) rpHeight = rpToolHeight + 2; else rpHeight = rpOnHeight + 2; if (rpHeight > 290) rpHeight = 290; @@ -712,7 +712,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (!tool.isMultiColoredSections) { - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) { //are there enough pixels in buffer array to warrant turning off supersection for (int a = 0; a < (tool.rpWidth * rpOnHeight); a++) @@ -749,7 +749,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //determine if in or out of headland, do hydraulics if on - if (plot.isHeadlandOn) + if (bnd.isHeadlandOn) { //calculate the slope double m = (vehicle.hydLiftLookAheadDistanceRight - vehicle.hydLiftLookAheadDistanceLeft) / tool.rpWidth; @@ -770,12 +770,12 @@ private void oglBack_Paint(object sender, PaintEventArgs e) GetOutTool: //is the tool completely in the headland or not - plot.isToolInHeadland = plot.isToolOuterPointsInHeadland && !isHeadlandClose; + bnd.isToolInHeadland = bnd.isToolOuterPointsInHeadland && !isHeadlandClose; - if (isHeadlandClose || plot.isToolInHeadland) tool.isSuperSectionAllowedOn = false; + if (isHeadlandClose || bnd.isToolInHeadland) tool.isSuperSectionAllowedOn = false; //set hydraulics based on tool in headland or not - plot.SetHydPosition(); + bnd.SetHydPosition(); } } else //supersection check by applied only @@ -923,7 +923,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tagged == 0) section[j].isMappingRequiredOn = false; } - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) { //if out of boundary, turn it off if (!section[j].isInBoundary) @@ -935,7 +935,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) section[j].mappingOnTimer = 0; } - else if (section[j].isInHeadlandArea & plot.isHeadlandOn) + else if (section[j].isInHeadlandArea & bnd.isHeadlandOn) { // if headland is on and out, turn off section[j].isMappingRequiredOn = false; @@ -950,7 +950,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) /////////////////////////////////////////// Section control ssssssssssssssssssssss /// - if (plot.isHeadlandOn) plot.WhereAreToolLookOnPoints(); + if (bnd.isHeadlandOn) bnd.WhereAreToolLookOnPoints(); for (int j = 0; j < tool.numOfSections; j++) { @@ -958,7 +958,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //ensure it starts off section[j].isSectionRequiredOn = false; - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) { //if out of boundary, turn it off if (!section[j].isInBoundary) @@ -1013,7 +1013,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //is headland coming up - if (plot.isHeadlandOn) + if (bnd.isHeadlandOn) { bool isHeadlandInLookOn = false; @@ -1502,7 +1502,7 @@ private void oglZoom_Paint(object sender, PaintEventArgs e) } //draw all the boundaries - plot.DrawBoundaryLines(); + bnd.DrawBoundaryLines(); GL.PointSize(8.0f); GL.Begin(PrimitiveType.Points); @@ -2385,13 +2385,13 @@ public void CalculateMinMax() //min max of the boundary //min max of the boundary - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) { - int bndCnt = plot.plots[0].fenceLine.Count; + int bndCnt = bnd.bndList[0].fenceLine.Count; for (int i = 0; i < bndCnt; i++) { - double x = plot.plots[0].fenceLine[i].easting; - double y = plot.plots[0].fenceLine[i].northing; + double x = bnd.bndList[0].fenceLine[i].easting; + double y = bnd.bndList[0].fenceLine[i].northing; //also tally the max/min of field x and z if (minFieldX > x) minFieldX = x; @@ -2481,7 +2481,7 @@ private void DrawFieldText() { if (isMetric) { - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) { sb.Clear(); sb.Append(((fd.workedAreaTotal - fd.actualAreaCovered) * glm.m2ha).ToString("N3")); @@ -2512,7 +2512,7 @@ private void DrawFieldText() } else { - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) { sb.Clear(); sb.Append(((fd.workedAreaTotal - fd.actualAreaCovered) * glm.m2ac).ToString("N3")); diff --git a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs index 19a0032aa..cd7e1b6fb 100644 --- a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs +++ b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs @@ -122,7 +122,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.plot.DrawBoundaryLines(); + mf.bnd.DrawBoundaryLines(); GL.Flush(); oglSelf.SwapBuffers(); diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index 4a766dae7..def686870 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -707,10 +707,10 @@ public void UpdateFixPosition() mc.isOutOfBounds = true; //if an outer boundary is set, then apply critical stop logic - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (plot.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (bnd.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; @@ -822,7 +822,7 @@ private void TheRest() } //test if travelled far enough for new boundary point - if (plot.isOkToAddPoints) + if (bnd.isOkToAddPoints) { double boundaryDistance = glm.Distance(pn.fix, prevBoundaryPos); if (boundaryDistance > 1) AddBoundaryPoint(); @@ -982,16 +982,16 @@ public void AddBoundaryPoint() //build the boundary line - if (plot.isOkToAddPoints) + if (bnd.isOkToAddPoints) { - if (plot.isDrawRightSide) + if (bnd.isDrawRightSide) { //Right side vec3 point = new vec3( - pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * -plot.createBndOffset), - pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * -plot.createBndOffset), + pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * -bnd.createBndOffset), + pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * -bnd.createBndOffset), pivotAxlePos.heading); - plot.bndBeingMadePts.Add(point); + bnd.bndBeingMadePts.Add(point); } //draw on left side @@ -999,10 +999,10 @@ public void AddBoundaryPoint() { //Right side vec3 point = new vec3( - pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * plot.createBndOffset), - pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * plot.createBndOffset), + pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * bnd.createBndOffset), + pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * bnd.createBndOffset), pivotAxlePos.heading); - plot.bndBeingMadePts.Add(point); + bnd.bndBeingMadePts.Add(point); } } } @@ -1238,7 +1238,7 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (tool.lookAheadDistanceOffPixelsRight > 160) tool.lookAheadDistanceOffPixelsRight = 160; //determine where the tool is wrt to headland - if (plot.isHeadlandOn) plot.WhereAreToolCorners(); + if (bnd.isHeadlandOn) bnd.WhereAreToolCorners(); //set up the super for youturn section[tool.numOfSections].isInBoundary = true; @@ -1248,19 +1248,19 @@ public void CalculateSectionLookAhead(double northing, double easting, double co for (int j = 0; j < tool.numOfSections; j++) { - if (plot.plots.Count > 0) + if (bnd.bndList.Count > 0) { if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftIn = plot.plots[0].IsPointInPolygon(section[j].leftPoint, ref plot.plots[0].fenceLineEar); - isRightIn = plot.plots[0].IsPointInPolygon(section[j].rightPoint, ref plot.plots[0].fenceLineEar); + isLeftIn = bnd.bndList[0].IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[0].fenceLineEar); + isRightIn = bnd.bndList[0].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); - for (int i = 1; i < plot.plots.Count; i++) + for (int i = 1; i < bnd.bndList.Count; i++) { //inner boundaries should normally NOT have point inside - isLeftIn &= !plot.plots[i].IsPointInPolygon(section[j].leftPoint, ref plot.plots[i].fenceLineEar); - isRightIn &= !plot.plots[i].IsPointInPolygon(section[j].rightPoint, ref plot.plots[i].fenceLineEar); + isLeftIn &= !bnd.bndList[i].IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[i].fenceLineEar); + isRightIn &= !bnd.bndList[i].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); } //merge the two sides into in or out @@ -1272,11 +1272,11 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { //grab the right of previous section, its the left of this section isLeftIn = isRightIn; - isRightIn = plot.plots[0].IsPointInPolygon(section[j].rightPoint, ref plot.plots[0].fenceLineEar); - for (int i = 1; i < plot.plots.Count; i++) + isRightIn = bnd.bndList[0].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); + for (int i = 1; i < bnd.bndList.Count; i++) { //inner boundaries should normally NOT have point inside - isRightIn &= !plot.plots[i].IsPointInPolygon(section[j].rightPoint, ref plot.plots[i].fenceLineEar); + isRightIn &= !bnd.bndList[i].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); } if (isLeftIn && isRightIn) section[j].isInBoundary = true; diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index 726feae46..f04c1bc4d 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -739,13 +739,13 @@ public void FileOpenField(string _openType) } } - plot.plots.Add(New); + bnd.bndList.Add(New); } } CalculateMinMax(); - plot.BuildTurnLines(); - if (plot.plots.Count > 0) btnMakeLinesFromBoundary.Visible = true; + bnd.BuildTurnLines(); + if (bnd.bndList.Count > 0) btnMakeLinesFromBoundary.Visible = true; } catch (Exception e) @@ -773,9 +773,9 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - if (plot.plots.Count > k) + if (bnd.bndList.Count > k) { - plot.plots[k].hdLine.Clear(); + bnd.bndList[k].hdLine.Clear(); //read the number of points line = reader.ReadLine(); @@ -792,7 +792,7 @@ public void FileOpenField(string _openType) double.Parse(words[0], CultureInfo.InvariantCulture), double.Parse(words[1], CultureInfo.InvariantCulture), double.Parse(words[2], CultureInfo.InvariantCulture)); - plot.plots[k].hdLine.Add(vecPt); + bnd.bndList[k].hdLine.Add(vecPt); } } } @@ -808,9 +808,9 @@ public void FileOpenField(string _openType) } } - if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) + if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) { - plot.isHeadlandOn = true; + bnd.isHeadlandOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -819,7 +819,7 @@ public void FileOpenField(string _openType) } else { - plot.isHeadlandOn = false; + bnd.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; @@ -1209,19 +1209,19 @@ public void FileSaveBoundary() using (StreamWriter writer = new StreamWriter(dirField + "Boundary.Txt")) { writer.WriteLine("$Boundary"); - for (int i = 0; i < plot.plots.Count; i++) + for (int i = 0; i < bnd.bndList.Count; i++) { - writer.WriteLine(plot.plots[i].isDriveThru); - writer.WriteLine(plot.plots[i].isDriveAround); + writer.WriteLine(bnd.bndList[i].isDriveThru); + writer.WriteLine(bnd.bndList[i].isDriveAround); //writer.WriteLine(bnd.bndArr[i].isOwnField); - writer.WriteLine(plot.plots[i].fenceLine.Count.ToString(CultureInfo.InvariantCulture)); - if (plot.plots[i].fenceLine.Count > 0) + writer.WriteLine(bnd.bndList[i].fenceLine.Count.ToString(CultureInfo.InvariantCulture)); + if (bnd.bndList[i].fenceLine.Count > 0) { - for (int j = 0; j < plot.plots[i].fenceLine.Count; j++) - writer.WriteLine(Math.Round(plot.plots[i].fenceLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].fenceLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].fenceLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < bnd.bndList[i].fenceLine.Count; j++) + writer.WriteLine(Math.Round(bnd.bndList[i].fenceLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndList[i].fenceLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndList[i].fenceLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); } } } @@ -1295,17 +1295,17 @@ public void FileSaveHeadland() { writer.WriteLine("$Headland"); - if (plot.plots[0].hdLine.Count > 0) + if (bnd.bndList[0].hdLine.Count > 0) { - for (int i = 0; i < plot.plots.Count; i++) + for (int i = 0; i < bnd.bndList.Count; i++) { - writer.WriteLine(plot.plots[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); - if (plot.plots[0].hdLine.Count > 0) + writer.WriteLine(bnd.bndList[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); + if (bnd.bndList[0].hdLine.Count > 0) { - for (int j = 0; j < plot.plots[i].hdLine.Count; j++) - writer.WriteLine(Math.Round(plot.plots[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < bnd.bndList[i].hdLine.Count; j++) + writer.WriteLine(Math.Round(bnd.bndList[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndList[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndList[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); } } } @@ -1678,7 +1678,7 @@ public void FileSaveFieldKML() kml.WriteStartElement("Folder"); kml.WriteElementString("name", "Boundaries"); - for (int i = 0; i < plot.plots.Count; i++) + for (int i = 0; i < bnd.bndList.Count; i++) { kml.WriteStartElement("Placemark"); if (i == 0) kml.WriteElementString("name", currentFieldDirectory); @@ -1705,7 +1705,7 @@ public void FileSaveFieldKML() //coords kml.WriteStartElement("coordinates"); string bndPts = ""; - if (plot.plots[i].fenceLine.Count > 3) + if (bnd.bndList[i].fenceLine.Count > 3) bndPts = GetBoundaryPointsLatLon(i); kml.WriteRaw(bndPts); kml.WriteEndElement(); // @@ -1949,12 +1949,12 @@ public string GetBoundaryPointsLatLon(int bndNum) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < plot.plots[bndNum].fenceLine.Count; i++) + for (int i = 0; i < bnd.bndList[bndNum].fenceLine.Count; i++) { double lat = 0; double lon = 0; - pn.ConvertLocalToWGS84(plot.plots[bndNum].fenceLine[i].northing, plot.plots[bndNum].fenceLine[i].easting, out lat, out lon); + pn.ConvertLocalToWGS84(bnd.bndList[bndNum].fenceLine[i].northing, bnd.bndList[bndNum].fenceLine[i].easting, out lat, out lon); sb.Append(lon.ToString("N7", CultureInfo.InvariantCulture) + ',' + lat.ToString("N7", CultureInfo.InvariantCulture) + ",0 "); } diff --git a/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs b/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs index a898ef27d..5286675aa 100644 --- a/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs +++ b/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs @@ -401,7 +401,7 @@ private void tabUTurn_Leave(object sender, EventArgs e) Properties.Settings.Default.Save(); Properties.Vehicle.Default.Save(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); mf.yt.ResetCreatedYouTurn(); } From 5004a046aa899a59f38a5f6a3b50619a115a05b0 Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Tue, 26 Oct 2021 08:46:48 -0600 Subject: [PATCH 05/18] delete unused functions, geofence references --- SourceCode/GPS/Classes/CFence.cs | 4 +-- SourceCode/GPS/Classes/CHead.cs | 27 ------------------- SourceCode/GPS/Forms/FormHeadland.cs | 2 +- SourceCode/GPS/Forms/Guidance/FormABDraw.cs | 2 +- SourceCode/GPS/Forms/OpenGL.Designer.cs | 4 +-- SourceCode/GPS/Forms/Pickers/FormTouchPick.cs | 2 +- SourceCode/GPS/Forms/Position.designer.cs | 2 +- 7 files changed, 8 insertions(+), 35 deletions(-) diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs index cdbbcaf78..1185efd2c 100644 --- a/SourceCode/GPS/Classes/CFence.cs +++ b/SourceCode/GPS/Classes/CFence.cs @@ -21,7 +21,7 @@ public partial class CBoundary //point at the farthest boundary segment from pivotAxle public vec3 closestFencePt = new vec3(-10000, -10000, 9); - public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) + public bool IsInsideAllFences(vec3 testPoint) { //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders if (bndList[0].IsPointInPolygon(testPoint, ref bndList[0].fenceLine)) @@ -44,7 +44,7 @@ public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) return true; } - public void DrawBoundaryLines() + public void DrawFenceLines() { //draw the boundaries GL.Color3(0.75f, 0.5f, 0.250f); diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index 71c10f30a..70a878318 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -126,33 +126,6 @@ public void WhereAreToolLookOnPoints() } } - public void DrawHeadLines() - { - for (int i = 0; i < bndList.Count; i++) - { - if (bndList[i].hdLine.Count > 0) bndList[i].DrawHeadLine(); - } - - - //GL.LineWidth(4.0f); - //GL.Color3(0.9219f, 0.2f, 0.970f); - //GL.Begin(PrimitiveType.Lines); - //{ - // GL.Vertex3(headArr[0].hdLine[A].easting, headArr[0].hdLine[A].northing, 0); - // GL.Vertex3(headArr[0].hdLine[B].easting, headArr[0].hdLine[B].northing, 0); - // GL.Vertex3(headArr[0].hdLine[C].easting, headArr[0].hdLine[C].northing, 0); - // GL.Vertex3(headArr[0].hdLine[D].easting, headArr[0].hdLine[D].northing, 0); - //} - //GL.End(); - - //GL.PointSize(6.0f); - //GL.Color3(0.219f, 0.932f, 0.970f); - //GL.Begin(PrimitiveType.Points); - //GL.Vertex3(downL.easting, downL.northing, 0); - //GL.Vertex3(downR.easting, downR.northing, 0); - //GL.End(); - } - public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add diff --git a/SourceCode/GPS/Forms/FormHeadland.cs b/SourceCode/GPS/Forms/FormHeadland.cs index f03b0368a..3bfcda0e0 100644 --- a/SourceCode/GPS/Forms/FormHeadland.cs +++ b/SourceCode/GPS/Forms/FormHeadland.cs @@ -334,7 +334,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) //else lblEnd.Text = end.ToString(); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.bnd.DrawFenceLines(); int ptCount = hdArr.Length; if (ptCount > 1) diff --git a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs index df3ac41c8..82c1a1c85 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs @@ -669,7 +669,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.bnd.DrawFenceLines(); //the vehicle GL.PointSize(16.0f); diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index 45aab364f..945fa1975 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -338,7 +338,7 @@ private void oglMain_Paint(object sender, PaintEventArgs e) recPath.DrawDubins(); //draw Boundaries - bnd.DrawBoundaryLines(); + bnd.DrawFenceLines(); //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) @@ -1502,7 +1502,7 @@ private void oglZoom_Paint(object sender, PaintEventArgs e) } //draw all the boundaries - bnd.DrawBoundaryLines(); + bnd.DrawFenceLines(); GL.PointSize(8.0f); GL.Begin(PrimitiveType.Points); diff --git a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs index cd7e1b6fb..5d1e7a98c 100644 --- a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs +++ b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs @@ -122,7 +122,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.bnd.DrawFenceLines(); GL.Flush(); oglSelf.SwapBuffers(); diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index def686870..b046d7aed 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -710,7 +710,7 @@ public void UpdateFixPosition() if (bnd.bndList.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (bnd.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (bnd.IsInsideAllFences(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; From 3258b6d5d82836884ccc149c09f89b0c2da97c25 Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Tue, 26 Oct 2021 12:55:51 -0600 Subject: [PATCH 06/18] Revert "delete unused functions, geofence references" This reverts commit 5004a046aa899a59f38a5f6a3b50619a115a05b0. --- SourceCode/GPS/Classes/CFence.cs | 4 +-- SourceCode/GPS/Classes/CHead.cs | 27 +++++++++++++++++++ SourceCode/GPS/Forms/FormHeadland.cs | 2 +- SourceCode/GPS/Forms/Guidance/FormABDraw.cs | 2 +- SourceCode/GPS/Forms/OpenGL.Designer.cs | 4 +-- SourceCode/GPS/Forms/Pickers/FormTouchPick.cs | 2 +- SourceCode/GPS/Forms/Position.designer.cs | 2 +- 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs index 1185efd2c..cdbbcaf78 100644 --- a/SourceCode/GPS/Classes/CFence.cs +++ b/SourceCode/GPS/Classes/CFence.cs @@ -21,7 +21,7 @@ public partial class CBoundary //point at the farthest boundary segment from pivotAxle public vec3 closestFencePt = new vec3(-10000, -10000, 9); - public bool IsInsideAllFences(vec3 testPoint) + public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) { //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders if (bndList[0].IsPointInPolygon(testPoint, ref bndList[0].fenceLine)) @@ -44,7 +44,7 @@ public bool IsInsideAllFences(vec3 testPoint) return true; } - public void DrawFenceLines() + public void DrawBoundaryLines() { //draw the boundaries GL.Color3(0.75f, 0.5f, 0.250f); diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index 70a878318..71c10f30a 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -126,6 +126,33 @@ public void WhereAreToolLookOnPoints() } } + public void DrawHeadLines() + { + for (int i = 0; i < bndList.Count; i++) + { + if (bndList[i].hdLine.Count > 0) bndList[i].DrawHeadLine(); + } + + + //GL.LineWidth(4.0f); + //GL.Color3(0.9219f, 0.2f, 0.970f); + //GL.Begin(PrimitiveType.Lines); + //{ + // GL.Vertex3(headArr[0].hdLine[A].easting, headArr[0].hdLine[A].northing, 0); + // GL.Vertex3(headArr[0].hdLine[B].easting, headArr[0].hdLine[B].northing, 0); + // GL.Vertex3(headArr[0].hdLine[C].easting, headArr[0].hdLine[C].northing, 0); + // GL.Vertex3(headArr[0].hdLine[D].easting, headArr[0].hdLine[D].northing, 0); + //} + //GL.End(); + + //GL.PointSize(6.0f); + //GL.Color3(0.219f, 0.932f, 0.970f); + //GL.Begin(PrimitiveType.Points); + //GL.Vertex3(downL.easting, downL.northing, 0); + //GL.Vertex3(downR.easting, downR.northing, 0); + //GL.End(); + } + public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add diff --git a/SourceCode/GPS/Forms/FormHeadland.cs b/SourceCode/GPS/Forms/FormHeadland.cs index 3bfcda0e0..f03b0368a 100644 --- a/SourceCode/GPS/Forms/FormHeadland.cs +++ b/SourceCode/GPS/Forms/FormHeadland.cs @@ -334,7 +334,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) //else lblEnd.Text = end.ToString(); //draw all the boundaries - mf.bnd.DrawFenceLines(); + mf.bnd.DrawBoundaryLines(); int ptCount = hdArr.Length; if (ptCount > 1) diff --git a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs index 82c1a1c85..df3ac41c8 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs @@ -669,7 +669,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.bnd.DrawFenceLines(); + mf.bnd.DrawBoundaryLines(); //the vehicle GL.PointSize(16.0f); diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index 945fa1975..45aab364f 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -338,7 +338,7 @@ private void oglMain_Paint(object sender, PaintEventArgs e) recPath.DrawDubins(); //draw Boundaries - bnd.DrawFenceLines(); + bnd.DrawBoundaryLines(); //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) @@ -1502,7 +1502,7 @@ private void oglZoom_Paint(object sender, PaintEventArgs e) } //draw all the boundaries - bnd.DrawFenceLines(); + bnd.DrawBoundaryLines(); GL.PointSize(8.0f); GL.Begin(PrimitiveType.Points); diff --git a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs index 5d1e7a98c..cd7e1b6fb 100644 --- a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs +++ b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs @@ -122,7 +122,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.bnd.DrawFenceLines(); + mf.bnd.DrawBoundaryLines(); GL.Flush(); oglSelf.SwapBuffers(); diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index b046d7aed..def686870 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -710,7 +710,7 @@ public void UpdateFixPosition() if (bnd.bndList.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (bnd.IsInsideAllFences(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (bnd.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; From 2cc68795979229265baabb31ec4f7086084879dd Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Tue, 26 Oct 2021 12:55:58 -0600 Subject: [PATCH 07/18] Revert "plot -> bnd and bndList" This reverts commit 2fde294f8770e6e69836d5523e170cf7ed0d0fca. --- SourceCode/GPS/Classes/CABCurve.cs | 10 +-- SourceCode/GPS/Classes/CABLine.cs | 8 +- SourceCode/GPS/Classes/CBoundary.cs | 2 +- SourceCode/GPS/Classes/CContour.cs | 12 +-- SourceCode/GPS/Classes/CFence.cs | 12 +-- SourceCode/GPS/Classes/CFieldData.cs | 8 +- SourceCode/GPS/Classes/CHead.cs | 20 ++--- SourceCode/GPS/Classes/CTram.cs | 26 +++--- SourceCode/GPS/Classes/CTurn.cs | 88 +++++++++---------- SourceCode/GPS/Classes/CVehicle.cs | 12 +-- SourceCode/GPS/Classes/CYouTurn.cs | 78 ++++++++-------- SourceCode/GPS/Forms/Controls.Designer.cs | 24 ++--- SourceCode/GPS/Forms/FormBoundary.cs | 60 ++++++------- SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 60 ++++++------- SourceCode/GPS/Forms/FormFieldKML.cs | 14 +-- SourceCode/GPS/Forms/FormGPS.cs | 8 +- SourceCode/GPS/Forms/FormHeadland.cs | 24 ++--- SourceCode/GPS/Forms/GUI.Designer.cs | 6 +- SourceCode/GPS/Forms/Guidance/FormABDraw.cs | 30 +++---- SourceCode/GPS/Forms/OpenGL.Designer.cs | 62 ++++++------- SourceCode/GPS/Forms/Pickers/FormTouchPick.cs | 2 +- SourceCode/GPS/Forms/Position.designer.cs | 42 ++++----- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 60 ++++++------- .../Forms/Settings/ConfigModule.Designer.cs | 2 +- 24 files changed, 335 insertions(+), 335 deletions(-) diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index 7cb578218..de9f27ad3 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -683,7 +683,7 @@ public void BuildTram() mf.tram.tramList?.Clear(); mf.tram.tramArr?.Clear(); - bool isBndExist = mf.bnd.bndList.Count != 0; + bool isBndExist = mf.plot.plots.Count != 0; double pass = 0.5; @@ -735,7 +735,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar )) + if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar )) { mf.tram.tramArr.Add(point); } @@ -744,7 +744,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) + if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -816,7 +816,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) + if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -825,7 +825,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) + if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index 1b86caec5..b08b15e2e 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -452,7 +452,7 @@ public void BuildTram() mf.tram.tramArr?.Clear(); List tramRef = new List(); - bool isBndExist = mf.bnd.bndList.Count != 0; + bool isBndExist = mf.plot.plots.Count != 0; double pass = 0.5; double hsin = Math.Sin(abHeading); @@ -495,7 +495,7 @@ public void BuildTram() if (isBndExist) { - if (mf.bnd.bndList[0].IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) + if (mf.plot.plots[0].IsPointInPolygon(P1, ref mf.plot.plots[0].fenceLineEar)) { mf.tram.tramArr.Add(P1); } @@ -523,7 +523,7 @@ public void BuildTram() if (isBndExist) { - if (mf.bnd.bndList[0].IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) + if (mf.plot.plots[0].IsPointInPolygon(P1, ref mf.plot.plots[0].fenceLineEar)) { mf.tram.tramArr.Add(P1); } @@ -538,7 +538,7 @@ public void BuildTram() tramRef?.Clear(); //outside tram - if (mf.bnd.bndList.Count == 0 || mf.tram.passes != 0) + if (mf.plot.plots.Count == 0 || mf.tram.passes != 0) { //return; } diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index 7a67962d7..807bfdceb 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -9,7 +9,7 @@ public partial class CBoundary //copy of the mainform address private readonly FormGPS mf; - public List bndList = new List(); + public List plots = new List(); //constructor public CBoundary(FormGPS _f) diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index 4ae78d278..b61895a5f 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -924,7 +924,7 @@ public void StopContourLine(vec3 pivot) //build contours for boundaries public void BuildFenceContours(int pass, int spacingInt) { - if (mf.bnd.bndList.Count == 0) + if (mf.plot.plots.Count == 0) { mf.TimedMessageBox(1500, "Boundary Contour Error", "No Boundaries Made"); return; @@ -950,10 +950,10 @@ public void BuildFenceContours(int pass, int spacingInt) //totalHeadWidth = (mf.tool.toolWidth - mf.tool.toolOverlap) * 0.5 + 0.2 + (mf.tool.toolWidth - mf.tool.toolOverlap); - for (int j = 0; j < mf.bnd.bndList.Count; j++) + for (int j = 0; j < mf.plot.plots.Count; j++) { //count the points from the boundary - int ptCount = mf.bnd.bndList[j].fenceLine.Count; + int ptCount = mf.plot.plots[j].fenceLine.Count; ptList = new List(128); stripList.Add(ptList); @@ -961,9 +961,9 @@ public void BuildFenceContours(int pass, int spacingInt) for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.bnd.bndList[j].fenceLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.bnd.bndList[j].fenceLine[i].heading) * totalHeadWidth); - point.northing = mf.bnd.bndList[j].fenceLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.bnd.bndList[j].fenceLine[i].heading) * totalHeadWidth); - point.heading = mf.bnd.bndList[j].fenceLine[i].heading - Math.PI; + point.easting = mf.plot.plots[j].fenceLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.plot.plots[j].fenceLine[i].heading) * totalHeadWidth); + point.northing = mf.plot.plots[j].fenceLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.plot.plots[j].fenceLine[i].heading) * totalHeadWidth); + point.heading = mf.plot.plots[j].fenceLine[i].heading - Math.PI; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if inside actual field boundary diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs index cdbbcaf78..fc41e2cf3 100644 --- a/SourceCode/GPS/Classes/CFence.cs +++ b/SourceCode/GPS/Classes/CFence.cs @@ -24,13 +24,13 @@ public partial class CBoundary public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) { //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (bndList[0].IsPointInPolygon(testPoint, ref bndList[0].fenceLine)) + if (plots[0].IsPointInPolygon(testPoint, ref plots[0].fenceLine)) { - for (int i = 1; i < bndList.Count; i++) + for (int i = 1; i < plots.Count; i++) { //make sure not inside a non drivethru boundary - if (bndList[i].isDriveThru) continue; - if (bndList[i].IsPointInPolygon(testPoint, ref bndList[i].fenceLine)) + if (plots[i].isDriveThru) continue; + if (plots[i].IsPointInPolygon(testPoint, ref plots[i].fenceLine)) { return false; } @@ -49,9 +49,9 @@ public void DrawBoundaryLines() //draw the boundaries GL.Color3(0.75f, 0.5f, 0.250f); - for (int i = 0; i < bndList.Count; i++) + for (int i = 0; i < plots.Count; i++) { - bndList[i].DrawFenceLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); + plots[i].DrawFenceLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); } if (bndBeingMadePts.Count > 0) diff --git a/SourceCode/GPS/Classes/CFieldData.cs b/SourceCode/GPS/Classes/CFieldData.cs index 72adb8a0a..d76e520ce 100644 --- a/SourceCode/GPS/Classes/CFieldData.cs +++ b/SourceCode/GPS/Classes/CFieldData.cs @@ -132,14 +132,14 @@ public CFieldData(FormGPS _f) public void UpdateFieldBoundaryGUIAreas() { - if (mf.bnd.bndList.Count > 0) + if (mf.plot.plots.Count > 0) { - areaOuterBoundary = mf.bnd.bndList[0].area; + areaOuterBoundary = mf.plot.plots[0].area; areaBoundaryOuterLessInner = areaOuterBoundary; - for (int i = 1; i < mf.bnd.bndList.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { - areaBoundaryOuterLessInner -= mf.bnd.bndList[i].area; + areaBoundaryOuterLessInner -= mf.plot.plots[i].area; } } else diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index 71c10f30a..e7379034e 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -37,7 +37,7 @@ public void SetHydPosition() public void WhereAreToolCorners() { - if (bndList.Count > 0 && bndList[0].hdLine.Count > 0) + if (plots.Count > 0 && plots[0].hdLine.Count > 0) { bool isLeftInWk, isRightInWk = true; @@ -48,8 +48,8 @@ public void WhereAreToolCorners() if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftInWk = bndList[0].IsPointInPolygon(mf.section[j].leftPoint, ref bndList[0].hdLine); - isRightInWk = bndList[0].IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); + isLeftInWk = plots[0].IsPointInPolygon(mf.section[j].leftPoint, ref plots[0].hdLine); + isRightInWk = plots[0].IsPointInPolygon(mf.section[j].rightPoint, ref plots[0].hdLine); //save left side mf.tool.isLeftSideInHeadland = !isLeftInWk; @@ -62,7 +62,7 @@ public void WhereAreToolCorners() { //grab the right of previous section, its the left of this section isLeftInWk = isRightInWk; - isRightInWk = bndList[0].IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); + isRightInWk = plots[0].IsPointInPolygon(mf.section[j].rightPoint, ref plots[0].hdLine); mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } @@ -84,7 +84,7 @@ public void WhereAreToolCorners() public void WhereAreToolLookOnPoints() { - if (bndList.Count > 0 && bndList[0].hdLine.Count > 0) + if (plots.Count > 0 && plots[0].hdLine.Count > 0) { vec3 toolFix = mf.toolPos; double sinAB = Math.Sin(toolFix.heading); @@ -128,9 +128,9 @@ public void WhereAreToolLookOnPoints() public void DrawHeadLines() { - for (int i = 0; i < bndList.Count; i++) + for (int i = 0; i < plots.Count; i++) { - if (bndList[i].hdLine.Count > 0) bndList[i].DrawHeadLine(); + if (plots[i].hdLine.Count > 0) plots[i].DrawHeadLine(); } @@ -156,11 +156,11 @@ public void DrawHeadLines() public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add - if (bndList.Count > 0 && bndList[0].IsPointInPolygon(pt, ref bndList[0].hdLine)) + if (plots.Count > 0 && plots[0].IsPointInPolygon(pt, ref plots[0].hdLine)) { - for (int b = 1; b < bndList.Count; b++) + for (int b = 1; b < plots.Count; b++) { - if (bndList[b].IsPointInPolygon(pt, ref bndList[b].hdLine)) + if (plots[b].IsPointInPolygon(pt, ref plots[b].hdLine)) { //point is in an inner turn area but inside outer return false; diff --git a/SourceCode/GPS/Classes/CTram.cs b/SourceCode/GPS/Classes/CTram.cs index 3a8efe3fb..f00222a02 100644 --- a/SourceCode/GPS/Classes/CTram.cs +++ b/SourceCode/GPS/Classes/CTram.cs @@ -84,7 +84,7 @@ public void DrawTram() public void BuildTramBnd() { - bool isBndExist = mf.bnd.bndList.Count != 0; + bool isBndExist = mf.plot.plots.Count != 0; if (isBndExist) { @@ -101,7 +101,7 @@ public void BuildTramBnd() private void CreateBndInnerTramTrack() { //count the points from the boundary - int ptCount = mf.bnd.bndList[0].fenceLine.Count; + int ptCount = mf.plot.plots[0].fenceLine.Count; tramBndInnerArr?.Clear(); //outside point @@ -113,18 +113,18 @@ private void CreateBndInnerTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.bnd.bndList[0].fenceLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.easting = mf.plot.plots[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); - pt3.northing = mf.bnd.bndList[0].fenceLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.northing = mf.plot.plots[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.bnd.bndList[0].fenceLine[j].northing, mf.bnd.bndList[0].fenceLine[j].easting); + mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); if (check < distSq) { Add = false; @@ -149,7 +149,7 @@ private void CreateBndInnerTramTrack() public void CreateBndOuterTramTrack() { //count the points from the boundary - int ptCount = mf.bnd.bndList[0].fenceLine.Count; + int ptCount = mf.plot.plots[0].fenceLine.Count; tramBndOuterArr?.Clear(); //outside point @@ -161,18 +161,18 @@ public void CreateBndOuterTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.bnd.bndList[0].fenceLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.easting = mf.plot.plots[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); - pt3.northing = mf.bnd.bndList[0].fenceLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.northing = mf.plot.plots[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.bnd.bndList[0].fenceLine[j].northing, mf.bnd.bndList[0].fenceLine[j].easting); + mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); if (check < distSq) { Add = false; diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index 118180603..7a8b37987 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -38,13 +38,13 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (bndList[0].IsPointInPolygon(pt, ref bndList[0].turnLine)) + if (plots[0].IsPointInPolygon(pt, ref plots[0].turnLine)) { - for (int t = 1; t < bndList.Count; t++) + for (int t = 1; t < plots.Count; t++) { - if (bndList[t].isDriveThru) continue; - if (bndList[t].isDriveAround) continue; - if (bndList[t].IsPointInPolygon(pt, ref bndList[0].turnLine)) + if (plots[t].isDriveThru) continue; + if (plots[t].isDriveAround) continue; + if (plots[t].IsPointInPolygon(pt, ref plots[0].turnLine)) { isFound = true; closestTurnNum = t; @@ -95,25 +95,25 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB vec4 inBox; - int ptCount = bndList[closestTurnNum].turnLine.Count; + int ptCount = plots[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (plots[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (plots[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (plots[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (plots[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (plots[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (plots[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (plots[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (plots[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = bndList[closestTurnNum].turnLine[p].easting; - inBox.northing = bndList[closestTurnNum].turnLine[p].northing; - inBox.heading = bndList[closestTurnNum].turnLine[p].heading; + inBox.easting = plots[closestTurnNum].turnLine[p].easting; + inBox.northing = plots[closestTurnNum].turnLine[p].northing; + inBox.heading = plots[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -149,26 +149,26 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB //determine if point is inside bounding box of the 1 turn chosen above turnClosestList.Clear(); - ptCount = bndList[closestTurnNum].turnLine.Count; + ptCount = plots[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (plots[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (plots[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (plots[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (plots[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (plots[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (plots[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (plots[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (plots[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = bndList[closestTurnNum].turnLine[p].easting; - inBox.northing = bndList[closestTurnNum].turnLine[p].northing; - inBox.heading = bndList[closestTurnNum].turnLine[p].heading; + inBox.easting = plots[closestTurnNum].turnLine[p].easting; + inBox.northing = plots[closestTurnNum].turnLine[p].northing; + inBox.heading = plots[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -210,7 +210,7 @@ public void BuildTurnLines() //update the GUI values for boundaries mf.fd.UpdateFieldBoundaryGUIAreas(); - if (bndList.Count == 0) + if (plots.Count == 0) { //mf.TimedMessageBox(1500, " No Boundaries", "No Turn Lines Made"); return; @@ -223,29 +223,29 @@ public void BuildTurnLines() double totalHeadWidth = mf.yt.uturnDistanceFromBoundary; //inside boundaries - for (int j = 0; j < bndList.Count; j++) + for (int j = 0; j < plots.Count; j++) { - bndList[j].turnLine.Clear(); - if (bndList[j].isDriveThru || bndList[j].isDriveAround) continue; + plots[j].turnLine.Clear(); + if (plots[j].isDriveThru || plots[j].isDriveAround) continue; - int ptCount = bndList[j].fenceLine.Count; + int ptCount = plots[j].fenceLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point outside the boundary - point.easting = bndList[j].fenceLine[i].easting + (-Math.Sin(glm.PIBy2 + bndList[j].fenceLine[i].heading) * totalHeadWidth); - point.northing = bndList[j].fenceLine[i].northing + (-Math.Cos(glm.PIBy2 + bndList[j].fenceLine[i].heading) * totalHeadWidth); - point.heading = bndList[j].fenceLine[i].heading; + point.easting = plots[j].fenceLine[i].easting + (-Math.Sin(glm.PIBy2 + plots[j].fenceLine[i].heading) * totalHeadWidth); + point.northing = plots[j].fenceLine[i].northing + (-Math.Cos(glm.PIBy2 + plots[j].fenceLine[i].heading) * totalHeadWidth); + point.heading = plots[j].fenceLine[i].heading; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == bndList[j].IsPointInPolygon(point, ref bndList[j].fenceLineEar)) + if (j == 0 == plots[j].IsPointInPolygon(point, ref plots[j].fenceLineEar)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); - bndList[j].turnLine.Add(tPnt); + plots[j].turnLine.Add(tPnt); } } - bndList[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); + plots[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); } } @@ -255,17 +255,17 @@ public void DrawTurnLines() GL.Color3(0.3555f, 0.6232f, 0.20f); //GL.PointSize(2); - for (int i = 0; i < bndList.Count; i++) + for (int i = 0; i < plots.Count; i++) { - if (bndList[i].isDriveAround) continue; + if (plots[i].isDriveAround) continue; //turnArr[i].DrawTurnLine(); { ////draw the turn line oject - int ptCount = bndList[i].turnLine.Count; + int ptCount = plots[i].turnLine.Count; if (ptCount < 1) continue; GL.Begin(PrimitiveType.LineLoop); - for (int h = 0; h < ptCount; h++) GL.Vertex3(bndList[i].turnLine[h].easting, bndList[i].turnLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(plots[i].turnLine[h].easting, plots[i].turnLine[h].northing, 0); GL.End(); } } diff --git a/SourceCode/GPS/Classes/CVehicle.cs b/SourceCode/GPS/Classes/CVehicle.cs index 977b12296..e2076105b 100644 --- a/SourceCode/GPS/Classes/CVehicle.cs +++ b/SourceCode/GPS/Classes/CVehicle.cs @@ -408,9 +408,9 @@ public void DrawVehicle() GL.End(); } - if (mf.bnd.isBndBeingMade) + if (mf.plot.isBndBeingMade) { - if (mf.bnd.isDrawRightSide) + if (mf.plot.isDrawRightSide) { GL.LineWidth(2); GL.Color3(0.0, 1.270, 0.0); @@ -418,8 +418,8 @@ public void DrawVehicle() { GL.Vertex3(0.0, 0, 0); GL.Color3(1.270, 1.220, 0.20); - GL.Vertex3(mf.bnd.createBndOffset, 0, 0); - GL.Vertex3(mf.bnd.createBndOffset * 0.75, 0.25, 0); + GL.Vertex3(mf.plot.createBndOffset, 0, 0); + GL.Vertex3(mf.plot.createBndOffset * 0.75, 0.25, 0); } GL.End(); } @@ -433,8 +433,8 @@ public void DrawVehicle() { GL.Vertex3(0.0, 0, 0); GL.Color3(1.270, 1.220, 0.20); - GL.Vertex3(-mf.bnd.createBndOffset, 0, 0); - GL.Vertex3(-mf.bnd.createBndOffset * 0.75, 0.25, 0); + GL.Vertex3(-mf.plot.createBndOffset, 0, 0); + GL.Vertex3(-mf.plot.createBndOffset * 0.75, 0.25, 0); } GL.End(); } diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index 00fb32256..26bf06e86 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -115,7 +115,7 @@ public bool FindCurveTurnPoints() //for each point in succession keep going till a turnLine is found. for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) { - if (!mf.bnd.bndList[0].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) + if (!mf.plot.plots[0].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[0].turnLine)) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -125,12 +125,12 @@ public bool FindCurveTurnPoints() goto CrossingFound; } - for (int i = 1; i < mf.bnd.bndList.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (mf.bnd.bndList[i].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) + if (mf.plot.plots[i].isDriveThru) continue; + if (mf.plot.plots[i].isDriveAround) continue; + if (mf.plot.plots[i].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[i].turnLine)) { crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -152,7 +152,7 @@ public bool FindCurveTurnPoints() for (int j = mf.curve.currentLocationIndex; j > 0; j--) { - if (!mf.bnd.bndList[0].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) + if (!mf.plot.plots[0].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[0].turnLine)) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; @@ -162,12 +162,12 @@ public bool FindCurveTurnPoints() goto CrossingFound; } - for (int i = 1; i < mf.bnd.bndList.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (mf.bnd.bndList[i].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) + if (mf.plot.plots[i].isDriveThru) continue; + if (mf.plot.plots[i].isDriveAround) continue; + if (mf.plot.plots[i].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[i].turnLine)) { crossingCurvePoint.easting = mf.curve.curList[j].easting; crossingCurvePoint.northing = mf.curve.curList[j].northing; @@ -191,17 +191,17 @@ public bool FindCurveTurnPoints() return false; } - int curTurnLineCount = mf.bnd.bndList[turnNum].turnLine.Count; + int curTurnLineCount = mf.plot.plots[turnNum].turnLine.Count; //possible points close to AB Curve point List turnLineCloseList = new List(); for (int j = 0; j < curTurnLineCount; j++) { - if ((mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 - && (mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 - && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 - && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) + if ((mf.plot.plots[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 + && (mf.plot.plots[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 + && (mf.plot.plots[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 + && (mf.plot.plots[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) { turnLineCloseList.Add(j); } @@ -211,8 +211,8 @@ public bool FindCurveTurnPoints() curTurnLineCount = turnLineCloseList.Count; for (int i = 0; i < curTurnLineCount; i++) { - dist1 = glm.Distance(mf.bnd.bndList[turnNum].turnLine[turnLineCloseList[i]].easting, - mf.bnd.bndList[turnNum].turnLine[turnLineCloseList[i]].northing, + dist1 = glm.Distance(mf.plot.plots[turnNum].turnLine[turnLineCloseList[i]].easting, + mf.plot.plots[turnNum].turnLine[turnLineCloseList[i]].northing, crossingCurvePoint.easting, crossingCurvePoint.northing); if (dist1 < dist2) { @@ -222,9 +222,9 @@ public bool FindCurveTurnPoints() } //fill up the coords - crossingTurnLinePoint.easting = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].easting; - crossingTurnLinePoint.northing = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].northing; - crossingTurnLinePoint.heading = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].heading; + crossingTurnLinePoint.easting = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].easting; + crossingTurnLinePoint.northing = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].northing; + crossingTurnLinePoint.heading = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].heading; return crossingCurvePoint.easting != -20000 && crossingCurvePoint.easting != -20000; } @@ -387,12 +387,12 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) vec3 onPurePoint = new vec3(mf.ABLine.rEastAB, mf.ABLine.rNorthAB, 0); //how far are we from any turn boundary - mf.bnd.FindClosestTurnPoint(isYouTurnRight, onPurePoint, headAB); + mf.plot.FindClosestTurnPoint(isYouTurnRight, onPurePoint, headAB); //or did we lose the turnLine - we are on the highway cuz we left the outer/inner turn boundary - if ((int)mf.bnd.closestTurnPt.easting != -20000) + if ((int)mf.plot.closestTurnPt.easting != -20000) { - mf.distancePivotToTurnLine = glm.Distance(mf.pivotAxlePos, mf.bnd.closestTurnPt); + mf.distancePivotToTurnLine = glm.Distance(mf.pivotAxlePos, mf.plot.closestTurnPt); } else { @@ -401,7 +401,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) } //delta between AB heading and boundary closest point heading - boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(mf.bnd.closestTurnPt.heading - headAB) - Math.PI); + boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(mf.plot.closestTurnPt.heading - headAB) - Math.PI); boundaryAngleOffPerpendicular -= glm.PIBy2; boundaryAngleOffPerpendicular *= -1; if (boundaryAngleOffPerpendicular > 1.25) boundaryAngleOffPerpendicular = 1.25; @@ -584,15 +584,15 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j],ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; + if (!mf.plot.plots[0].IsPointInPolygon(ytList[j],ref mf.plot.plots[0].turnLine)) isOutOfBounds = true; if (isOutOfBounds) break; - for (int i = 1; i < mf.bnd.bndList.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) + if (mf.plot.plots[i].isDriveThru) continue; + if (mf.plot.plots[i].isDriveAround) continue; + if (mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[i].turnLine)) { isOutOfBounds = true; break; @@ -644,16 +644,16 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; + if (!mf.plot.plots[0].IsPointInPolygon(ytList[j], ref mf.plot.plots[0].turnLine)) isOutOfBounds = true; if (isOutOfBounds) break; - for (int i = 1; i < mf.bnd.bndList.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (!mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) + if (mf.plot.plots[i].isDriveThru) continue; + if (mf.plot.plots[i].isDriveAround) continue; + if (!mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[i].turnLine)) { isOutOfBounds = true; break; @@ -852,18 +852,18 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) + if (!mf.plot.plots[0].IsPointInPolygon(ytList[j], ref mf.plot.plots[0].turnLine)) { isOutOfBounds = true; break; } - for (int i = 1; i < mf.bnd.bndList.Count; i++) + for (int i = 1; i < mf.plot.plots.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[1].turnLine)) + if (mf.plot.plots[i].isDriveThru) continue; + if (mf.plot.plots[i].isDriveAround) continue; + if (mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[1].turnLine)) { isOutOfBounds = true; break; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index 0c1cc25dc..76a7f2beb 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -355,7 +355,7 @@ private void btnAutoYouTurn_Click(object sender, EventArgs e) { yt.isTurnCreationTooClose = false; - if (bnd.bndList.Count == 0) + if (plot.plots.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1494,7 +1494,7 @@ private void BtnMakeLinesFromBoundary_Click(object sender, EventArgs e) return; } - if (bnd.bndList.Count == 0) + if (plot.plots.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1549,10 +1549,10 @@ private void cboxpRowWidth_SelectedIndexChanged(object sender, EventArgs e) private void btnHeadlandOnOff_Click(object sender, EventArgs e) { - if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) + if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - bnd.isHeadlandOn = !bnd.isHeadlandOn; - if (bnd.isHeadlandOn) + plot.isHeadlandOn = !plot.isHeadlandOn; + if (plot.isHeadlandOn) { btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHydLift.Visible = true; @@ -1563,9 +1563,9 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; } } - else bnd.isHeadlandOn = false; + else plot.isHeadlandOn = false; - if (!bnd.isHeadlandOn) + if (!plot.isHeadlandOn) { p_239.pgn[p_239.hydLift] = 0; vehicle.isHydLiftOn = false; @@ -1577,7 +1577,7 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) private void btnHydLift_Click(object sender, EventArgs e) { - if (bnd.isHeadlandOn) + if (plot.isHeadlandOn) { vehicle.isHydLiftOn = !vehicle.isHydLiftOn; if (vehicle.isHydLiftOn) @@ -1959,7 +1959,7 @@ private void tramLinesMenuField_Click(object sender, EventArgs e) } private void headlandToolStripMenuItem_Click(object sender, EventArgs e) { - if (bnd.bndList.Count == 0) + if (plot.plots.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1974,9 +1974,9 @@ public void GetHeadland() form.ShowDialog(); } - if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) + if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - bnd.isHeadlandOn = true; + plot.isHeadlandOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -1984,7 +1984,7 @@ public void GetHeadland() } else { - bnd.isHeadlandOn = false; + plot.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index 4718ceb52..7df2c5359 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -59,7 +59,7 @@ private void UpdateChart() Font backupfont = new Font(Font.FontFamily, 18F, FontStyle.Bold); - for (int i = 0; i < mf.bnd.bndList.Count && i < 6; i++) + for (int i = 0; i < mf.plot.plots.Count && i < 6; i++) { //outer inner Button a = new Button @@ -118,11 +118,11 @@ private void UpdateChart() if (i == 0) { //cc.Text = "Outer"; - mf.bnd.bndList[i].isDriveThru = false; - mf.bnd.bndList[i].isDriveAround = false; + mf.plot.plots[i].isDriveThru = false; + mf.plot.plots[i].isDriveAround = false; a.Text = string.Format(gStr.gsOuter); //a.Font = backupfont; - d.Text = mf.bnd.bndList[i].isDriveThru ? "--" : "--"; + d.Text = mf.plot.plots[i].isDriveThru ? "--" : "--"; d.Enabled = false; d.Anchor = System.Windows.Forms.AnchorStyles.None; a.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -135,7 +135,7 @@ private void UpdateChart() inner += 1; a.Text = string.Format(gStr.gsInner + " {0}", inner); //a.Font = backupfont; - d.Text = mf.bnd.bndList[i].isDriveThru ? "Yes" : "No"; + d.Text = mf.plot.plots[i].isDriveThru ? "Yes" : "No"; d.Anchor = System.Windows.Forms.AnchorStyles.None; a.Anchor = System.Windows.Forms.AnchorStyles.None; b.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -144,14 +144,14 @@ private void UpdateChart() if (mf.isMetric) { - b.Text = Math.Round(mf.bnd.bndList[i].area * 0.0001, 2).ToString() + " Ha"; + b.Text = Math.Round(mf.plot.plots[i].area * 0.0001, 2).ToString() + " Ha"; } else { - b.Text = Math.Round(mf.bnd.bndList[i].area * 0.000247105, 2) + " Ac"; + b.Text = Math.Round(mf.plot.plots[i].area * 0.000247105, 2) + " Ac"; } - if (Selectedreset == false && i == mf.bnd.fenceSelected) + if (Selectedreset == false && i == mf.plot.fenceSelected) { a.ForeColor = Color.OrangeRed; b.ForeColor = Color.OrangeRed; @@ -168,9 +168,9 @@ private void DriveThru_Click(object sender, EventArgs e) { if (sender is Button b) { - mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveThru = !mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveThru; + mf.plot.plots[Convert.ToInt32(b.Name)].isDriveThru = !mf.plot.plots[Convert.ToInt32(b.Name)].isDriveThru; UpdateChart(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); } } @@ -178,7 +178,7 @@ private void DriveAround_Click(object sender, EventArgs e) { if (sender is Button b) { - mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround = !mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround; + mf.plot.plots[Convert.ToInt32(b.Name)].isDriveAround = !mf.plot.plots[Convert.ToInt32(b.Name)].isDriveAround; UpdateChart(); } } @@ -188,16 +188,16 @@ private void B_Click(object sender, EventArgs e) if (sender is Button b) { - mf.bnd.fenceSelected = Convert.ToInt32(b.Name); + mf.plot.fenceSelected = Convert.ToInt32(b.Name); - if (mf.bnd.fenceSelected == 0 && mf.bnd.bndList.Count > 1) + if (mf.plot.fenceSelected == 0 && mf.plot.plots.Count > 1) { return; } Selectedreset = false; - if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) + if (mf.plot.plots.Count > mf.plot.fenceSelected) { btnDelete.Enabled = true; } @@ -213,7 +213,7 @@ private void B_Click(object sender, EventArgs e) private void btnSerialCancel_Click(object sender, EventArgs e) { - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; } private void btnDelete_Click(object sender, EventArgs e) @@ -229,17 +229,17 @@ private void btnDelete_Click(object sender, EventArgs e) btnDelete.Enabled = false; - if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) + if (mf.plot.plots.Count > mf.plot.fenceSelected) { - mf.bnd.bndList.RemoveAt(mf.bnd.fenceSelected); + mf.plot.plots.RemoveAt(mf.plot.fenceSelected); } mf.FileSaveBoundary(); - mf.bnd.fenceSelected = -1; + mf.plot.fenceSelected = -1; Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); UpdateChart(); } else @@ -250,13 +250,13 @@ private void btnDelete_Click(object sender, EventArgs e) private void ResetAllBoundary() { - mf.bnd.bndList.Clear(); + mf.plot.plots.Clear(); mf.FileSaveBoundary(); tableLayoutPanel1.Controls.Clear(); tableLayoutPanel1.RowStyles.Clear(); UpdateChart(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); btnDelete.Enabled = false; } @@ -282,10 +282,10 @@ private void btnDeleteAll_Click(object sender, EventArgs e) ResetAllBoundary(); - mf.bnd.fenceSelected = -1; + mf.plot.fenceSelected = -1; Selectedreset = true; - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; mf.fd.UpdateFieldBoundaryGUIAreas(); } else @@ -297,7 +297,7 @@ private void btnDeleteAll_Click(object sender, EventArgs e) private void btnReturn_Click(object sender, EventArgs e) { - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; panelMain.Visible = true; panelChoose.Visible = false; @@ -310,7 +310,7 @@ private void btnReturn_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e) { - mf.bnd.fenceSelected = mf.bnd.bndList.Count; + mf.plot.fenceSelected = mf.plot.plots.Count; Selectedreset = false; @@ -353,7 +353,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) { if (button.Name == "btnLoadMultiBoundaryFromGE") ResetAllBoundary(); - else i = mf.bnd.fenceSelected; + else i = mf.plot.fenceSelected; try { @@ -408,10 +408,10 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) New.fenceLine.Add(new vec3(easting, norting, 0)); } - New.CalculateFenceArea(mf.bnd.fenceSelected); + New.CalculateFenceArea(mf.plot.fenceSelected); New.FixFenceLine(i); - mf.bnd.bndList.Add(New); + mf.plot.plots.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); @@ -431,7 +431,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) } } mf.FileSaveBoundary(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); mf.btnMakeLinesFromBoundary.Visible = true; mf.fd.UpdateFieldBoundaryGUIAreas(); UpdateChart(); @@ -442,7 +442,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) } } } - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; panelMain.Visible = true; panelChoose.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 007aa0e2d..59b15796d 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -27,34 +27,34 @@ public FormBoundaryPlayer(Form callingForm) private void btnStop_Click(object sender, EventArgs e) { - if (mf.bnd.bndBeingMadePts.Count > 2) + if (mf.plot.bndBeingMadePts.Count > 2) { CBoundaryList New = new CBoundaryList(); - for (int i = 0; i < mf.bnd.bndBeingMadePts.Count; i++) + for (int i = 0; i < mf.plot.bndBeingMadePts.Count; i++) { - New.fenceLine.Add(mf.bnd.bndBeingMadePts[i]); + New.fenceLine.Add(mf.plot.bndBeingMadePts[i]); } - New.CalculateFenceArea(mf.bnd.fenceSelected); - New.FixFenceLine(mf.bnd.fenceSelected); + New.CalculateFenceArea(mf.plot.fenceSelected); + New.FixFenceLine(mf.plot.fenceSelected); - mf.bnd.bndList.Add(New); + mf.plot.plots.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); } //stop it all for adding - mf.bnd.isOkToAddPoints = false; - mf.bnd.isBndBeingMade = false; + mf.plot.isOkToAddPoints = false; + mf.plot.isBndBeingMade = false; //turn lines made from boundaries mf.CalculateMinMax(); mf.FileSaveBoundary(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); //mf.hd.BuildSingleSpaceHeadLines(); mf.btnMakeLinesFromBoundary.Visible = true; - mf.bnd.bndBeingMadePts.Clear(); + mf.plot.bndBeingMadePts.Clear(); //close window Close(); } @@ -62,9 +62,9 @@ private void btnStop_Click(object sender, EventArgs e) //actually the record button private void btnPausePlay_Click(object sender, EventArgs e) { - if (mf.bnd.isOkToAddPoints) + if (mf.plot.isOkToAddPoints) { - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; btnPausePlay.Image = Properties.Resources.BoundaryRecord; //btnPausePlay.Text = gStr.gsRecord; btnAddPoint.Enabled = true; @@ -72,7 +72,7 @@ private void btnPausePlay_Click(object sender, EventArgs e) } else { - mf.bnd.isOkToAddPoints = true; + mf.plot.isOkToAddPoints = true; btnPausePlay.Image = Properties.Resources.boundaryPause; //btnPausePlay.Text = gStr.gsPause; btnAddPoint.Enabled = false; @@ -86,15 +86,15 @@ private void FormBoundaryPlayer_Load(object sender, EventArgs e) //mf.bnd.isOkToAddPoints = false; nudOffset.Value = (decimal)(mf.tool.toolWidth * 0.5); btnPausePlay.Image = Properties.Resources.BoundaryRecord; - btnLeftRight.Image = mf.bnd.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; - mf.bnd.createBndOffset = (double)nudOffset.Value; - mf.bnd.isBndBeingMade = true; + btnLeftRight.Image = mf.plot.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; + mf.plot.createBndOffset = (double)nudOffset.Value; + mf.plot.isBndBeingMade = true; mf.Focus(); } private void timer1_Tick(object sender, EventArgs e) { - int ptCount = mf.bnd.bndBeingMadePts.Count; + int ptCount = mf.plot.bndBeingMadePts.Count; double area = 0; if (ptCount > 0) @@ -103,7 +103,7 @@ private void timer1_Tick(object sender, EventArgs e) for (int i = 0; i < ptCount; j = i++) { - area += (mf.bnd.bndBeingMadePts[j].easting + mf.bnd.bndBeingMadePts[i].easting) * (mf.bnd.bndBeingMadePts[j].northing - mf.bnd.bndBeingMadePts[i].northing); + area += (mf.plot.bndBeingMadePts[j].easting + mf.plot.bndBeingMadePts[i].easting) * (mf.plot.bndBeingMadePts[j].northing - mf.plot.bndBeingMadePts[i].northing); } area = Math.Abs(area / 2); } @@ -115,27 +115,27 @@ private void timer1_Tick(object sender, EventArgs e) { lblArea.Text = Math.Round(area * 0.000247105, 2) + " Acre"; } - lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); + lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); } private void btnAddPoint_Click(object sender, EventArgs e) { - mf.bnd.isOkToAddPoints = true; + mf.plot.isOkToAddPoints = true; mf.AddBoundaryPoint(); - mf.bnd.isOkToAddPoints = false; - lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); + mf.plot.isOkToAddPoints = false; + lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); mf.Focus(); } private void btnDeleteLast_Click(object sender, EventArgs e) { - int ptCount = mf.bnd.bndBeingMadePts.Count; + int ptCount = mf.plot.bndBeingMadePts.Count; if (ptCount > 0) - mf.bnd.bndBeingMadePts.RemoveAt(ptCount - 1); - lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); + mf.plot.bndBeingMadePts.RemoveAt(ptCount - 1); + lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); mf.Focus(); } @@ -148,8 +148,8 @@ private void btnRestart_Click(object sender, EventArgs e) MessageBoxDefaultButton.Button2); if (result3 == DialogResult.Yes) { - mf.bnd.bndBeingMadePts?.Clear(); - lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); + mf.plot.bndBeingMadePts?.Clear(); + lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); } mf.Focus(); } @@ -158,13 +158,13 @@ private void nudOffset_Click(object sender, EventArgs e) { mf.KeypadToNUD((NumericUpDown)sender, this); btnPausePlay.Focus(); - mf.bnd.createBndOffset = (double)nudOffset.Value; + mf.plot.createBndOffset = (double)nudOffset.Value; } private void btnLeftRight_Click(object sender, EventArgs e) { - mf.bnd.isDrawRightSide = !mf.bnd.isDrawRightSide; - btnLeftRight.Image = mf.bnd.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; + mf.plot.isDrawRightSide = !mf.plot.isDrawRightSide; + btnLeftRight.Image = mf.plot.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; } } } \ No newline at end of file diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 5b5a90d9c..22bc7ebf7 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -125,7 +125,7 @@ private void LoadKMLBoundary(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.bnd.fenceSelected; + i = mf.plot.fenceSelected; try { @@ -183,10 +183,10 @@ private void LoadKMLBoundary(string filename) } //build the boundary, make sure is clockwise for outer counter clockwise for inner - New.CalculateFenceArea(mf.bnd.fenceSelected); + New.CalculateFenceArea(mf.plot.fenceSelected); New.FixFenceLine(i); - mf.bnd.bndList.Add(New); + mf.plot.plots.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); @@ -206,7 +206,7 @@ private void LoadKMLBoundary(string filename) } } mf.FileSaveBoundary(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); mf.fd.UpdateFieldBoundaryGUIAreas(); mf.CalculateMinMax(); @@ -221,7 +221,7 @@ private void LoadKMLBoundary(string filename) } } - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; } private void FindLatLon(string filename) @@ -233,7 +233,7 @@ private void FindLatLon(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.bnd.fenceSelected; + i = mf.plot.fenceSelected; try { @@ -312,7 +312,7 @@ private void FindLatLon(string filename) } } - mf.bnd.isOkToAddPoints = false; + mf.plot.isOkToAddPoints = false; } diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index b4487c1c0..2e2d2e18c 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -187,7 +187,7 @@ public partial class FormGPS : Form /// /// The boundary object /// - public CBoundary bnd; + public CBoundary plot; /// /// The internal simulator @@ -366,7 +366,7 @@ public FormGPS() mc = new CModuleComm(); //boundary object - bnd = new CBoundary(this); + plot = new CBoundary(this); //nmea simulator built in. sim = new CSim(this); @@ -979,7 +979,7 @@ public void JobClose() pn.fixOffset.northing = 0; //turn off headland - bnd.isHeadlandOn = false; + plot.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; @@ -993,7 +993,7 @@ public void JobClose() oglZoom.SendToBack(); //clean all the lines - bnd.bndList.Clear(); + plot.plots.Clear(); panelRight.Enabled = false; FieldMenuButtonEnableDisable(false); diff --git a/SourceCode/GPS/Forms/FormHeadland.cs b/SourceCode/GPS/Forms/FormHeadland.cs index f03b0368a..3ce8739dc 100644 --- a/SourceCode/GPS/Forms/FormHeadland.cs +++ b/SourceCode/GPS/Forms/FormHeadland.cs @@ -54,10 +54,10 @@ private void FormHeadland_Load(object sender, EventArgs e) nudDistance.Value = 0; nudSetDistance.Value = 0; - if (mf.bnd.bndList[0].hdLine.Count > 0) + if (mf.plot.plots[0].hdLine.Count > 0) { - hdArr = new vec3[mf.bnd.bndList[0].hdLine.Count]; - mf.bnd.bndList[0].hdLine.CopyTo(hdArr); + hdArr = new vec3[mf.plot.plots[0].hdLine.Count]; + mf.plot.plots[0].hdLine.CopyTo(hdArr); RebuildHeadLineTemplate(); } else @@ -80,13 +80,13 @@ public void BuildHeadLineTemplateFromBoundary() //outside boundary - count the points from the boundary headLineTemplate.Clear(); - int ptCount = mf.bnd.bndList[0].fenceLine.Count; + int ptCount = mf.plot.plots[0].fenceLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.bnd.bndList[0].fenceLine[i].easting; - point.northing = mf.bnd.bndList[0].fenceLine[i].northing; - point.heading = mf.bnd.bndList[0].fenceLine[i].heading; + point.easting = mf.plot.plots[0].fenceLine[i].easting; + point.northing = mf.plot.plots[0].fenceLine[i].northing; + point.heading = mf.plot.plots[0].fenceLine[i].heading; headLineTemplate.Add(point); } @@ -334,7 +334,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) //else lblEnd.Text = end.ToString(); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.plot.DrawBoundaryLines(); int ptCount = hdArr.Length; if (ptCount > 1) @@ -565,7 +565,7 @@ private void timer1_Tick(object sender, EventArgs e) private void btnExit_Click(object sender, EventArgs e) { - mf.bnd.bndList[0].hdLine?.Clear(); + mf.plot.plots[0].hdLine?.Clear(); //middle points for (int i = 1; i < hdArr.Length; i++) @@ -580,7 +580,7 @@ private void btnExit_Click(object sender, EventArgs e) { if (i == 0) { - mf.bnd.bndList[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); + mf.plot.plots[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); continue; } delta += (hdArr[i - 1].heading - hdArr[i].heading); @@ -589,7 +589,7 @@ private void btnExit_Click(object sender, EventArgs e) { vec3 pt = new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading); - mf.bnd.bndList[0].hdLine.Add(pt); + mf.plot.plots[0].hdLine.Add(pt); delta = 0; } } @@ -600,7 +600,7 @@ private void btnExit_Click(object sender, EventArgs e) private void btnTurnOffHeadland_Click(object sender, EventArgs e) { - mf.bnd.bndList[0].hdLine?.Clear(); + mf.plot.plots[0].hdLine?.Clear(); mf.FileSaveHeadland(); diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 05b2ecc47..2ffa9913f 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -125,7 +125,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) // fd.WorkedAreaRemainPercentage +"\r\n" + // fd.TimeTillFinished + "\r\n" + // fd.WorkRateHectares; - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) lblFieldStatus.Text = fd.AreaBoundaryLessInnersHectares + " " + fd.WorkedAreaRemainHectares + " " + fd.TimeTillFinished + " " + fd.WorkedAreaRemainPercentage+" " @@ -136,7 +136,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) } else //imperial { - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) lblFieldStatus.Text = fd.AreaBoundaryLessInnersAcres + " " + fd.WorkedAreaRemainAcres + " " + fd.TimeTillFinished + " " + fd.WorkedAreaRemainPercentage + " " + fd.WorkedAcres; @@ -498,7 +498,7 @@ public void LoadSettings() if (Properties.Settings.Default.setAS_isAutoSteerAutoOn) btnAutoSteer.Text = "R"; else btnAutoSteer.Text = "M"; - if (bnd.isHeadlandOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; + if (plot.isHeadlandOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; else btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnChangeMappingColor.BackColor = sectionColorDay; diff --git a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs index df3ac41c8..073fd189d 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs @@ -46,21 +46,21 @@ public FormABDraw(Form callingForm) private void FormABDraw_Load(object sender, EventArgs e) { - int cnt = mf.bnd.bndList[0].fenceLine.Count; + int cnt = mf.plot.plots[0].fenceLine.Count; arr = new vec3[cnt * 2]; for (int i = 0; i < cnt; i++) { - arr[i].easting = mf.bnd.bndList[0].fenceLine[i].easting; - arr[i].northing = mf.bnd.bndList[0].fenceLine[i].northing; - arr[i].heading = mf.bnd.bndList[0].fenceLine[i].heading; + arr[i].easting = mf.plot.plots[0].fenceLine[i].easting; + arr[i].northing = mf.plot.plots[0].fenceLine[i].northing; + arr[i].heading = mf.plot.plots[0].fenceLine[i].heading; } for (int i = cnt; i < cnt * 2; i++) { - arr[i].easting = mf.bnd.bndList[0].fenceLine[i - cnt].easting; - arr[i].northing = mf.bnd.bndList[0].fenceLine[i - cnt].northing; - arr[i].heading = mf.bnd.bndList[0].fenceLine[i - cnt].heading; + arr[i].easting = mf.plot.plots[0].fenceLine[i - cnt].easting; + arr[i].northing = mf.plot.plots[0].fenceLine[i - cnt].northing; + arr[i].heading = mf.plot.plots[0].fenceLine[i - cnt].heading; } nudDistance.Value = (decimal)Math.Round(((mf.tool.toolWidth * mf.m2InchOrCm) * 0.5), 0); // @@ -356,7 +356,7 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) { //count the points from the boundary - int ptCount = mf.bnd.bndList[0].fenceLine.Count; + int ptCount = mf.plot.plots[0].fenceLine.Count; mf.curve.refList?.Clear(); //outside point @@ -369,20 +369,20 @@ private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.bnd.bndList[0].fenceLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (moveDist)); + pt3.easting = mf.plot.plots[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (moveDist)); - pt3.northing = mf.bnd.bndList[0].fenceLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (moveDist)); + pt3.northing = mf.plot.plots[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (moveDist)); - pt3.heading = mf.bnd.bndList[0].fenceLine[i].heading; + pt3.heading = mf.plot.plots[0].fenceLine[i].heading; bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.bnd.bndList[0].fenceLine[j].northing, mf.bnd.bndList[0].fenceLine[j].easting); + mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); if (check < distSq) { Add = false; @@ -669,7 +669,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.plot.DrawBoundaryLines(); //the vehicle GL.PointSize(16.0f); diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index 45aab364f..53c2a662a 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -338,21 +338,21 @@ private void oglMain_Paint(object sender, PaintEventArgs e) recPath.DrawDubins(); //draw Boundaries - bnd.DrawBoundaryLines(); + plot.DrawBoundaryLines(); //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) { - bnd.DrawTurnLines(); + plot.DrawTurnLines(); } - if (bnd.isHeadlandOn) + if (plot.isHeadlandOn) { GL.LineWidth(ABLine.lineWidth); GL.Color3(0.960f, 0.96232f, 0.30f); - for (int i = 0; i < bnd.bndList.Count; i++) + for (int i = 0; i < plot.plots.Count; i++) { - if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLine(); + if (plot.plots[i].hdLine.Count > 0) plot.plots[i].DrawHeadLine(); } } @@ -416,7 +416,7 @@ private void oglMain_Paint(object sender, PaintEventArgs e) if ((ahrs.imuRoll != 88888)) DrawRollBar(); - if (bnd.bndList.Count > 0 && yt.isYouTurnBtnOn) DrawUTurnBtn(); + if (plot.plots.Count > 0 && yt.isYouTurnBtnOn) DrawUTurnBtn(); if (isAutoSteerBtnOn && !ct.isContourBtnOn) DrawManUTurnBtn(); @@ -616,29 +616,29 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //draw 240 green for boundary - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) { ////draw the bnd line - int ptCount = bnd.bndList[0].fenceLine.Count; + int ptCount = plot.plots[0].fenceLine.Count; if (ptCount > 3) { GL.LineWidth(3); GL.Color3((byte)0, (byte)240, (byte)0); GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < ptCount; h++) GL.Vertex3(bnd.bndList[0].fenceLine[h].easting, bnd.bndList[0].fenceLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(plot.plots[0].fenceLine[h].easting, plot.plots[0].fenceLine[h].northing, 0); GL.End(); } } //draw 250 green for the headland - if (bnd.isHeadlandOn) + if (plot.isHeadlandOn) { GL.LineWidth(3); GL.Color3((byte)0, (byte)250, (byte)0); - for (int i = 0; i < bnd.bndList.Count; i++) + for (int i = 0; i < plot.plots.Count; i++) { - if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLineBackBuffer(); + if (plot.plots[i].hdLine.Count > 0) plot.plots[i].DrawHeadLineBackBuffer(); } } @@ -677,7 +677,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tool.numOfSections == 1 || pn.speed < vehicle.slowSpeedCutoff) tool.isSuperSectionAllowedOn = false; - if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && bnd.isHeadlandOn) + if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && plot.isHeadlandOn) tool.isSuperSectionAllowedOn = false; //clamp the height after looking way ahead, this is for switching off super section only @@ -687,7 +687,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //10 % min is required for overlap, otherwise it never would be on. int pixLimit = (int)((double)(section[0].rpSectionWidth * rpOnHeight) / (double)(5.0)); - if ((rpOnHeight < rpToolHeight && bnd.isHeadlandOn)) rpHeight = rpToolHeight + 2; + if ((rpOnHeight < rpToolHeight && plot.isHeadlandOn)) rpHeight = rpToolHeight + 2; else rpHeight = rpOnHeight + 2; if (rpHeight > 290) rpHeight = 290; @@ -712,7 +712,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (!tool.isMultiColoredSections) { - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) { //are there enough pixels in buffer array to warrant turning off supersection for (int a = 0; a < (tool.rpWidth * rpOnHeight); a++) @@ -749,7 +749,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //determine if in or out of headland, do hydraulics if on - if (bnd.isHeadlandOn) + if (plot.isHeadlandOn) { //calculate the slope double m = (vehicle.hydLiftLookAheadDistanceRight - vehicle.hydLiftLookAheadDistanceLeft) / tool.rpWidth; @@ -770,12 +770,12 @@ private void oglBack_Paint(object sender, PaintEventArgs e) GetOutTool: //is the tool completely in the headland or not - bnd.isToolInHeadland = bnd.isToolOuterPointsInHeadland && !isHeadlandClose; + plot.isToolInHeadland = plot.isToolOuterPointsInHeadland && !isHeadlandClose; - if (isHeadlandClose || bnd.isToolInHeadland) tool.isSuperSectionAllowedOn = false; + if (isHeadlandClose || plot.isToolInHeadland) tool.isSuperSectionAllowedOn = false; //set hydraulics based on tool in headland or not - bnd.SetHydPosition(); + plot.SetHydPosition(); } } else //supersection check by applied only @@ -923,7 +923,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tagged == 0) section[j].isMappingRequiredOn = false; } - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) { //if out of boundary, turn it off if (!section[j].isInBoundary) @@ -935,7 +935,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) section[j].mappingOnTimer = 0; } - else if (section[j].isInHeadlandArea & bnd.isHeadlandOn) + else if (section[j].isInHeadlandArea & plot.isHeadlandOn) { // if headland is on and out, turn off section[j].isMappingRequiredOn = false; @@ -950,7 +950,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) /////////////////////////////////////////// Section control ssssssssssssssssssssss /// - if (bnd.isHeadlandOn) bnd.WhereAreToolLookOnPoints(); + if (plot.isHeadlandOn) plot.WhereAreToolLookOnPoints(); for (int j = 0; j < tool.numOfSections; j++) { @@ -958,7 +958,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //ensure it starts off section[j].isSectionRequiredOn = false; - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) { //if out of boundary, turn it off if (!section[j].isInBoundary) @@ -1013,7 +1013,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //is headland coming up - if (bnd.isHeadlandOn) + if (plot.isHeadlandOn) { bool isHeadlandInLookOn = false; @@ -1502,7 +1502,7 @@ private void oglZoom_Paint(object sender, PaintEventArgs e) } //draw all the boundaries - bnd.DrawBoundaryLines(); + plot.DrawBoundaryLines(); GL.PointSize(8.0f); GL.Begin(PrimitiveType.Points); @@ -2385,13 +2385,13 @@ public void CalculateMinMax() //min max of the boundary //min max of the boundary - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) { - int bndCnt = bnd.bndList[0].fenceLine.Count; + int bndCnt = plot.plots[0].fenceLine.Count; for (int i = 0; i < bndCnt; i++) { - double x = bnd.bndList[0].fenceLine[i].easting; - double y = bnd.bndList[0].fenceLine[i].northing; + double x = plot.plots[0].fenceLine[i].easting; + double y = plot.plots[0].fenceLine[i].northing; //also tally the max/min of field x and z if (minFieldX > x) minFieldX = x; @@ -2481,7 +2481,7 @@ private void DrawFieldText() { if (isMetric) { - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) { sb.Clear(); sb.Append(((fd.workedAreaTotal - fd.actualAreaCovered) * glm.m2ha).ToString("N3")); @@ -2512,7 +2512,7 @@ private void DrawFieldText() } else { - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) { sb.Clear(); sb.Append(((fd.workedAreaTotal - fd.actualAreaCovered) * glm.m2ac).ToString("N3")); diff --git a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs index cd7e1b6fb..19a0032aa 100644 --- a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs +++ b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs @@ -122,7 +122,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.plot.DrawBoundaryLines(); GL.Flush(); oglSelf.SwapBuffers(); diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index def686870..4a766dae7 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -707,10 +707,10 @@ public void UpdateFixPosition() mc.isOutOfBounds = true; //if an outer boundary is set, then apply critical stop logic - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (bnd.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (plot.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; @@ -822,7 +822,7 @@ private void TheRest() } //test if travelled far enough for new boundary point - if (bnd.isOkToAddPoints) + if (plot.isOkToAddPoints) { double boundaryDistance = glm.Distance(pn.fix, prevBoundaryPos); if (boundaryDistance > 1) AddBoundaryPoint(); @@ -982,16 +982,16 @@ public void AddBoundaryPoint() //build the boundary line - if (bnd.isOkToAddPoints) + if (plot.isOkToAddPoints) { - if (bnd.isDrawRightSide) + if (plot.isDrawRightSide) { //Right side vec3 point = new vec3( - pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * -bnd.createBndOffset), - pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * -bnd.createBndOffset), + pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * -plot.createBndOffset), + pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * -plot.createBndOffset), pivotAxlePos.heading); - bnd.bndBeingMadePts.Add(point); + plot.bndBeingMadePts.Add(point); } //draw on left side @@ -999,10 +999,10 @@ public void AddBoundaryPoint() { //Right side vec3 point = new vec3( - pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * bnd.createBndOffset), - pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * bnd.createBndOffset), + pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * plot.createBndOffset), + pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * plot.createBndOffset), pivotAxlePos.heading); - bnd.bndBeingMadePts.Add(point); + plot.bndBeingMadePts.Add(point); } } } @@ -1238,7 +1238,7 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (tool.lookAheadDistanceOffPixelsRight > 160) tool.lookAheadDistanceOffPixelsRight = 160; //determine where the tool is wrt to headland - if (bnd.isHeadlandOn) bnd.WhereAreToolCorners(); + if (plot.isHeadlandOn) plot.WhereAreToolCorners(); //set up the super for youturn section[tool.numOfSections].isInBoundary = true; @@ -1248,19 +1248,19 @@ public void CalculateSectionLookAhead(double northing, double easting, double co for (int j = 0; j < tool.numOfSections; j++) { - if (bnd.bndList.Count > 0) + if (plot.plots.Count > 0) { if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftIn = bnd.bndList[0].IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[0].fenceLineEar); - isRightIn = bnd.bndList[0].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); + isLeftIn = plot.plots[0].IsPointInPolygon(section[j].leftPoint, ref plot.plots[0].fenceLineEar); + isRightIn = plot.plots[0].IsPointInPolygon(section[j].rightPoint, ref plot.plots[0].fenceLineEar); - for (int i = 1; i < bnd.bndList.Count; i++) + for (int i = 1; i < plot.plots.Count; i++) { //inner boundaries should normally NOT have point inside - isLeftIn &= !bnd.bndList[i].IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[i].fenceLineEar); - isRightIn &= !bnd.bndList[i].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); + isLeftIn &= !plot.plots[i].IsPointInPolygon(section[j].leftPoint, ref plot.plots[i].fenceLineEar); + isRightIn &= !plot.plots[i].IsPointInPolygon(section[j].rightPoint, ref plot.plots[i].fenceLineEar); } //merge the two sides into in or out @@ -1272,11 +1272,11 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { //grab the right of previous section, its the left of this section isLeftIn = isRightIn; - isRightIn = bnd.bndList[0].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); - for (int i = 1; i < bnd.bndList.Count; i++) + isRightIn = plot.plots[0].IsPointInPolygon(section[j].rightPoint, ref plot.plots[0].fenceLineEar); + for (int i = 1; i < plot.plots.Count; i++) { //inner boundaries should normally NOT have point inside - isRightIn &= !bnd.bndList[i].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); + isRightIn &= !plot.plots[i].IsPointInPolygon(section[j].rightPoint, ref plot.plots[i].fenceLineEar); } if (isLeftIn && isRightIn) section[j].isInBoundary = true; diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index f04c1bc4d..726feae46 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -739,13 +739,13 @@ public void FileOpenField(string _openType) } } - bnd.bndList.Add(New); + plot.plots.Add(New); } } CalculateMinMax(); - bnd.BuildTurnLines(); - if (bnd.bndList.Count > 0) btnMakeLinesFromBoundary.Visible = true; + plot.BuildTurnLines(); + if (plot.plots.Count > 0) btnMakeLinesFromBoundary.Visible = true; } catch (Exception e) @@ -773,9 +773,9 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - if (bnd.bndList.Count > k) + if (plot.plots.Count > k) { - bnd.bndList[k].hdLine.Clear(); + plot.plots[k].hdLine.Clear(); //read the number of points line = reader.ReadLine(); @@ -792,7 +792,7 @@ public void FileOpenField(string _openType) double.Parse(words[0], CultureInfo.InvariantCulture), double.Parse(words[1], CultureInfo.InvariantCulture), double.Parse(words[2], CultureInfo.InvariantCulture)); - bnd.bndList[k].hdLine.Add(vecPt); + plot.plots[k].hdLine.Add(vecPt); } } } @@ -808,9 +808,9 @@ public void FileOpenField(string _openType) } } - if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) + if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - bnd.isHeadlandOn = true; + plot.isHeadlandOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -819,7 +819,7 @@ public void FileOpenField(string _openType) } else { - bnd.isHeadlandOn = false; + plot.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; @@ -1209,19 +1209,19 @@ public void FileSaveBoundary() using (StreamWriter writer = new StreamWriter(dirField + "Boundary.Txt")) { writer.WriteLine("$Boundary"); - for (int i = 0; i < bnd.bndList.Count; i++) + for (int i = 0; i < plot.plots.Count; i++) { - writer.WriteLine(bnd.bndList[i].isDriveThru); - writer.WriteLine(bnd.bndList[i].isDriveAround); + writer.WriteLine(plot.plots[i].isDriveThru); + writer.WriteLine(plot.plots[i].isDriveAround); //writer.WriteLine(bnd.bndArr[i].isOwnField); - writer.WriteLine(bnd.bndList[i].fenceLine.Count.ToString(CultureInfo.InvariantCulture)); - if (bnd.bndList[i].fenceLine.Count > 0) + writer.WriteLine(plot.plots[i].fenceLine.Count.ToString(CultureInfo.InvariantCulture)); + if (plot.plots[i].fenceLine.Count > 0) { - for (int j = 0; j < bnd.bndList[i].fenceLine.Count; j++) - writer.WriteLine(Math.Round(bnd.bndList[i].fenceLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndList[i].fenceLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndList[i].fenceLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < plot.plots[i].fenceLine.Count; j++) + writer.WriteLine(Math.Round(plot.plots[i].fenceLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].fenceLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].fenceLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); } } } @@ -1295,17 +1295,17 @@ public void FileSaveHeadland() { writer.WriteLine("$Headland"); - if (bnd.bndList[0].hdLine.Count > 0) + if (plot.plots[0].hdLine.Count > 0) { - for (int i = 0; i < bnd.bndList.Count; i++) + for (int i = 0; i < plot.plots.Count; i++) { - writer.WriteLine(bnd.bndList[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); - if (bnd.bndList[0].hdLine.Count > 0) + writer.WriteLine(plot.plots[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); + if (plot.plots[0].hdLine.Count > 0) { - for (int j = 0; j < bnd.bndList[i].hdLine.Count; j++) - writer.WriteLine(Math.Round(bnd.bndList[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndList[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndList[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < plot.plots[i].hdLine.Count; j++) + writer.WriteLine(Math.Round(plot.plots[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); } } } @@ -1678,7 +1678,7 @@ public void FileSaveFieldKML() kml.WriteStartElement("Folder"); kml.WriteElementString("name", "Boundaries"); - for (int i = 0; i < bnd.bndList.Count; i++) + for (int i = 0; i < plot.plots.Count; i++) { kml.WriteStartElement("Placemark"); if (i == 0) kml.WriteElementString("name", currentFieldDirectory); @@ -1705,7 +1705,7 @@ public void FileSaveFieldKML() //coords kml.WriteStartElement("coordinates"); string bndPts = ""; - if (bnd.bndList[i].fenceLine.Count > 3) + if (plot.plots[i].fenceLine.Count > 3) bndPts = GetBoundaryPointsLatLon(i); kml.WriteRaw(bndPts); kml.WriteEndElement(); // @@ -1949,12 +1949,12 @@ public string GetBoundaryPointsLatLon(int bndNum) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < bnd.bndList[bndNum].fenceLine.Count; i++) + for (int i = 0; i < plot.plots[bndNum].fenceLine.Count; i++) { double lat = 0; double lon = 0; - pn.ConvertLocalToWGS84(bnd.bndList[bndNum].fenceLine[i].northing, bnd.bndList[bndNum].fenceLine[i].easting, out lat, out lon); + pn.ConvertLocalToWGS84(plot.plots[bndNum].fenceLine[i].northing, plot.plots[bndNum].fenceLine[i].easting, out lat, out lon); sb.Append(lon.ToString("N7", CultureInfo.InvariantCulture) + ',' + lat.ToString("N7", CultureInfo.InvariantCulture) + ",0 "); } diff --git a/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs b/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs index 5286675aa..a898ef27d 100644 --- a/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs +++ b/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs @@ -401,7 +401,7 @@ private void tabUTurn_Leave(object sender, EventArgs e) Properties.Settings.Default.Save(); Properties.Vehicle.Default.Save(); - mf.bnd.BuildTurnLines(); + mf.plot.BuildTurnLines(); mf.yt.ResetCreatedYouTurn(); } From 0071680a0d11a7b8518ac72ed29b0b9670e72c13 Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Tue, 26 Oct 2021 12:56:03 -0600 Subject: [PATCH 08/18] Revert "Renaming to boundary groups" This reverts commit e07ed0b282ee4f4336caf19f6fcde980ca5cfa84. --- SourceCode/AgIO/Source/AgIO.csproj | 1 - SourceCode/GPS/AgOpenGPS.csproj | 22 +- SourceCode/GPS/Classes/CABCurve.cs | 52 +++- SourceCode/GPS/Classes/CABLine.cs | 4 +- SourceCode/GPS/Classes/CBoundary.cs | 202 +++++++++++++- SourceCode/GPS/Classes/CBoundaryLines.cs | 263 ++++++++++++++++++ SourceCode/GPS/Classes/CBoundaryList.cs | 106 ------- SourceCode/GPS/Classes/CContour.cs | 10 +- SourceCode/GPS/Classes/CFence.cs | 181 ------------ SourceCode/GPS/Classes/CFenceLine.cs | 213 -------------- SourceCode/GPS/Classes/CHead.cs | 16 +- SourceCode/GPS/Classes/CHeadLines.cs | 37 ++- SourceCode/GPS/Classes/CPlot.cs | 35 +++ SourceCode/GPS/Classes/CPlots.cs | 30 ++ SourceCode/GPS/Classes/CTram.cs | 24 +- SourceCode/GPS/Classes/CTurn.cs | 23 +- SourceCode/GPS/Classes/CTurnLines.cs | 23 +- SourceCode/GPS/Classes/CYouTurn.cs | 20 +- SourceCode/GPS/Forms/Controls.Designer.cs | 14 +- SourceCode/GPS/Forms/FormBoundary.cs | 28 +- SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 8 +- SourceCode/GPS/Forms/FormFieldKML.cs | 12 +- SourceCode/GPS/Forms/FormGPS.cs | 6 +- SourceCode/GPS/Forms/FormHeadland.cs | 8 +- SourceCode/GPS/Forms/GUI.Designer.cs | 2 +- SourceCode/GPS/Forms/Guidance/FormABDraw.cs | 28 +- .../GPS/Forms/Guidance/FormMakeBndCon.cs | 2 +- SourceCode/GPS/Forms/OpenGL.Designer.cs | 26 +- SourceCode/GPS/Forms/Position.designer.cs | 14 +- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 38 +-- 30 files changed, 770 insertions(+), 678 deletions(-) create mode 100644 SourceCode/GPS/Classes/CBoundaryLines.cs delete mode 100644 SourceCode/GPS/Classes/CBoundaryList.cs delete mode 100644 SourceCode/GPS/Classes/CFence.cs delete mode 100644 SourceCode/GPS/Classes/CFenceLine.cs create mode 100644 SourceCode/GPS/Classes/CPlot.cs create mode 100644 SourceCode/GPS/Classes/CPlots.cs diff --git a/SourceCode/AgIO/Source/AgIO.csproj b/SourceCode/AgIO/Source/AgIO.csproj index 01e53c1d7..acf311cc4 100644 --- a/SourceCode/AgIO/Source/AgIO.csproj +++ b/SourceCode/AgIO/Source/AgIO.csproj @@ -166,7 +166,6 @@ FormGPSData.cs - Designer FormKeyboard.cs diff --git a/SourceCode/GPS/AgOpenGPS.csproj b/SourceCode/GPS/AgOpenGPS.csproj index 2b1114007..e2584fa00 100644 --- a/SourceCode/GPS/AgOpenGPS.csproj +++ b/SourceCode/GPS/AgOpenGPS.csproj @@ -113,29 +113,29 @@ - - CBoundary.cs + + CPlot.cs - - CBoundaryList.cs - - + + CPlots.cs + + - + - CBoundaryList.cs + CPlots.cs - CBoundary.cs + CPlot.cs @@ -151,10 +151,10 @@ - CBoundary.cs + CPlot.cs - CBoundaryList.cs + CPlots.cs diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index de9f27ad3..3fb7ebcf5 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -735,7 +735,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar )) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } @@ -744,7 +744,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } @@ -816,7 +816,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } @@ -825,7 +825,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.plot.plots[0].IsPointInPolygon(point, ref mf.plot.plots[0].fenceLineEar)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } @@ -1033,4 +1033,48 @@ public class CCurveLines } +//for (int i = 1; i <= mf.tram.passes; i++) +//{ +// tramArr = new List(); +// tramList.Add(tramArr); + +// List tramTemp = new List(); + +// for (int j = 0; j < tramRef.Count; j++) +// { +// P1.easting = (hsin * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].easting; +// P1.northing = (hcos * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].northing; + +// if (isBndExist) +// { +// if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(P1)) +// { +// tramTemp.Add(P1); +// P1.easting = (hsin * mf.vehicle.trackWidth) + P1.easting; +// P1.northing = (hcos * mf.vehicle.trackWidth) + P1.northing; +// tramTemp.Add(P1); +// } +// } +// else +// { +// tramTemp.Add(P1); + +// P1.easting = (hsin * mf.vehicle.trackWidth) + P1.easting; +// P1.northing = (hcos * mf.vehicle.trackWidth) + P1.northing; +// tramTemp.Add(P1); +// } + +// if (tramTemp.Count > 6) +// { +// vec2[] array = new vec2[tramTemp.Count]; +// tramTemp.CopyTo(array); + +// tramArr.Add(array[0]); +// tramArr.Add(array[1]); +// tramArr.Add(array[tramTemp.Count - 2]); +// tramArr.Add(array[tramTemp.Count - 1]); +// } + +// } +//} diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index b08b15e2e..7c3f8dff0 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -495,7 +495,7 @@ public void BuildTram() if (isBndExist) { - if (mf.plot.plots[0].IsPointInPolygon(P1, ref mf.plot.plots[0].fenceLineEar)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(P1)) { mf.tram.tramArr.Add(P1); } @@ -523,7 +523,7 @@ public void BuildTram() if (isBndExist) { - if (mf.plot.plots[0].IsPointInPolygon(P1, ref mf.plot.plots[0].fenceLineEar)) + if (mf.plot.plots[0].IsPointInsideBoundaryEar(P1)) { mf.tram.tramArr.Add(P1); } diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index 807bfdceb..c19551b06 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -4,22 +4,198 @@ namespace AgOpenGPS { - public partial class CBoundary + public partial class CPlot { - //copy of the mainform address - private readonly FormGPS mf; + public List bndBeingMadePts = new List(128); - public List plots = new List(); + public double createBndOffset; + public bool isBndBeingMade; - //constructor - public CBoundary(FormGPS _f) + // the list of possible bounds points + public List bndClosestList = new List(); + + public int boundarySelected, closestBoundaryNum; + + //generated box for finding closest point + public vec2 boxA = new vec2(9000, 9000), boxB = new vec2(9000, 9002); + + public vec2 boxC = new vec2(9001, 9001), boxD = new vec2(9002, 9003); + + //point at the farthest boundary segment from pivotAxle + public vec3 closestBoundaryPt = new vec3(-10000, -10000, 9); + + public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) + { + //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders + if (plots[0].IsPointInsideBoundaryArea(testPoint)) + { + for (int i = 1; i < plots.Count; i++) + { + //make sure not inside a non drivethru boundary + if (plots[i].isDriveThru) continue; + if (plots[i].IsPointInsideBoundaryArea(testPoint)) + { + return false; + } + } + } + else + { + return false; + } + //we are safely inside outer, outside inner boundaries + return true; + } + + public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) + { + { + boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); + boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); + + boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); + boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); + + boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); + boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); + + boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); + boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); + } + + int ptCount; + + //determine if point is inside bounding box + bndClosestList.Clear(); + vec4 inBox; + for (int i = 0; i < plots.Count; i++) + { + //skip the drive thru + if (plots[i].isDriveThru) continue; + + ptCount = plots[i].bndLine.Count; + for (int p = 0; p < ptCount; p++) + { + if ((((boxB.easting - boxA.easting) * (plots[i].bndLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (plots[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } + + if ((((boxD.easting - boxC.easting) * (plots[i].bndLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (plots[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } + + if ((((boxC.easting - boxB.easting) * (plots[i].bndLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (plots[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } + + if ((((boxA.easting - boxD.easting) * (plots[i].bndLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (plots[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } + + //it's in the box, so add to list + inBox.easting = plots[i].bndLine[p].easting; + inBox.northing = plots[i].bndLine[p].northing; + inBox.heading = plots[i].bndLine[p].heading; + inBox.index = i; + + //which boundary/headland is it from + bndClosestList.Add(inBox); + } + } + + //which of the points is closest + closestBoundaryPt.easting = -20000; closestBoundaryPt.northing = -20000; + ptCount = bndClosestList.Count; + if (ptCount != 0) + { + //determine closest point + double minDistance = 9999999; + for (int i = 0; i < ptCount; i++) + { + double dist = ((fromPt.easting - bndClosestList[i].easting) * (fromPt.easting - bndClosestList[i].easting)) + + ((fromPt.northing - bndClosestList[i].northing) * (fromPt.northing - bndClosestList[i].northing)); + if (minDistance >= dist) + { + minDistance = dist; + + closestBoundaryPt.easting = bndClosestList[i].easting; + closestBoundaryPt.northing = bndClosestList[i].northing; + closestBoundaryPt.heading = bndClosestList[i].heading; + closestBoundaryNum = bndClosestList[i].index; + } + } + if (closestBoundaryPt.heading < 0) closestBoundaryPt.heading += glm.twoPI; + } + } + + public void DrawBoundaryLines() { - mf = _f; - fenceSelected = 0; - boxLength = 2000; - turnSelected = 0; - isHeadlandOn = false; - isToolUp = true; + //draw the boundaries + GL.Color3(0.75f, 0.5f, 0.250f); + + for (int i = 0; i < plots.Count; i++) + { + plots[i].DrawBoundaryLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); + } + + if (bndBeingMadePts.Count > 0) + { + //the boundary so far + vec3 pivot = mf.pivotAxlePos; + GL.LineWidth(mf.ABLine.lineWidth); + GL.Color3(0.825f, 0.22f, 0.90f); + GL.Begin(PrimitiveType.LineStrip); + for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); + GL.Color3(0.295f, 0.972f, 0.290f); + GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); + GL.End(); + + //line from last point to pivot marker + GL.Color3(0.825f, 0.842f, 0.0f); + GL.Enable(EnableCap.LineStipple); + GL.LineStipple(1, 0x0700); + GL.Begin(PrimitiveType.LineStrip); + if (isDrawRightSide) + { + GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); + + GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * -createBndOffset), + pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * -createBndOffset), 0); + GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); + } + else + { + GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); + + GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * createBndOffset), + pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * createBndOffset), 0); + GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); + } + GL.End(); + GL.Disable(EnableCap.LineStipple); + + //boundary points + GL.Color3(0.0f, 0.95f, 0.95f); + GL.PointSize(6.0f); + GL.Begin(PrimitiveType.Points); + for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); + GL.End(); + } + } + + //draws the derived closest point + public void DrawClosestPoint() + { + GL.PointSize(4.0f); + GL.Color3(0.919f, 0.932f, 0.070f); + GL.Begin(PrimitiveType.Points); + GL.Vertex3(closestBoundaryPt.easting, closestBoundaryPt.northing, 0); + GL.End(); + + GL.LineWidth(1); + GL.Color3(0.92f, 0.62f, 0.42f); + GL.Begin(PrimitiveType.LineStrip); + GL.Vertex3(boxD.easting, boxD.northing, 0); + GL.Vertex3(boxA.easting, boxA.northing, 0); + GL.Vertex3(boxB.easting, boxB.northing, 0); + GL.Vertex3(boxC.easting, boxC.northing, 0); + GL.End(); } } -} \ No newline at end of file +} diff --git a/SourceCode/GPS/Classes/CBoundaryLines.cs b/SourceCode/GPS/Classes/CBoundaryLines.cs new file mode 100644 index 000000000..42f16d30b --- /dev/null +++ b/SourceCode/GPS/Classes/CBoundaryLines.cs @@ -0,0 +1,263 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; + +namespace AgOpenGPS +{ + public partial class CPlots + { + public void CalculateBoundaryHeadings() + { + //to calc heading based on next and previous points to give an average heading. + int cnt = bndLine.Count; + vec3[] arr = new vec3[cnt]; + cnt--; + bndLine.CopyTo(arr); + bndLine.Clear(); + + //first point needs last, first, second points + vec3 pt3 = arr[0]; + pt3.heading = Math.Atan2(arr[1].easting - arr[cnt].easting, arr[1].northing - arr[cnt].northing); + if (pt3.heading < 0) pt3.heading += glm.twoPI; + bndLine.Add(pt3); + + //middle points + for (int i = 1; i < cnt; i++) + { + pt3 = arr[i]; + pt3.heading = Math.Atan2(arr[i + 1].easting - arr[i - 1].easting, arr[i + 1].northing - arr[i - 1].northing); + if (pt3.heading < 0) pt3.heading += glm.twoPI; + bndLine.Add(pt3); + } + + //last and first point + pt3 = arr[cnt]; + pt3.heading = Math.Atan2(arr[0].easting - arr[cnt - 1].easting, arr[0].northing - arr[cnt - 1].northing); + if (pt3.heading < 0) pt3.heading += glm.twoPI; + bndLine.Add(pt3); + } + + public void FixBoundaryLine(int bndNum) + { + double spacing; + //boundary point spacing based on eq width + //close if less then 30 ha, 60ha, more then 60 + if (area < 200000) spacing = 1.1; + else if (area < 400000) spacing = 2.2; + else spacing = 3.3; + + if (bndNum > 0) spacing *= 0.5; + + int bndCount = bndLine.Count; + double distance; + + //make sure distance isn't too big between points on boundary + for (int i = 0; i < bndCount; i++) + { + int j = i + 1; + + if (j == bndCount) j = 0; + distance = glm.Distance(bndLine[i], bndLine[j]); + if (distance > spacing * 1.5) + { + vec3 pointB = new vec3((bndLine[i].easting + bndLine[j].easting) / 2.0, + (bndLine[i].northing + bndLine[j].northing) / 2.0, bndLine[i].heading); + + bndLine.Insert(j, pointB); + bndCount = bndLine.Count; + i--; + } + } + + //make sure distance isn't too big between points on boundary + bndCount = bndLine.Count; + + for (int i = 0; i < bndCount; i++) + { + int j = i + 1; + + if (j == bndCount) j = 0; + distance = glm.Distance(bndLine[i], bndLine[j]); + if (distance > spacing * 1.6) + { + vec3 pointB = new vec3((bndLine[i].easting + bndLine[j].easting) / 2.0, + (bndLine[i].northing + bndLine[j].northing) / 2.0, bndLine[i].heading); + + bndLine.Insert(j, pointB); + bndCount = bndLine.Count; + i--; + } + } + + //make sure distance isn't too small between points on headland + spacing *= 1.2; + bndCount = bndLine.Count; + for (int i = 0; i < bndCount - 1; i++) + { + distance = glm.Distance(bndLine[i], bndLine[i + 1]); + if (distance < spacing) + { + bndLine.RemoveAt(i + 1); + bndCount = bndLine.Count; + i--; + } + } + + //make sure headings are correct for calculated points + CalculateBoundaryHeadings(); + + double delta = 0; + bndLineEar?.Clear(); + + for (int i = 0; i < bndLine.Count; i++) + { + if (i == 0) + { + bndLineEar.Add(new vec2(bndLine[i].easting, bndLine[i].northing)); + continue; + } + delta += (bndLine[i - 1].heading - bndLine[i].heading); + if (Math.Abs(delta) > 0.01) + { + bndLineEar.Add(new vec2(bndLine[i].easting, bndLine[i].northing)); + delta = 0; + } + } + } + + public void ReverseWinding() + { + //reverse the boundary + int cnt = bndLine.Count; + vec3[] arr = new vec3[cnt]; + cnt--; + bndLine.CopyTo(arr); + bndLine.Clear(); + for (int i = cnt; i >= 0; i--) + { + arr[i].heading -= Math.PI; + if (arr[i].heading < 0) arr[i].heading += glm.twoPI; + bndLine.Add(arr[i]); + } + } + + public bool IsPointInsideBoundaryArea(vec3 testPoint) + { + bool result = false; + int j = bndLine.Count - 1; + for (int i = 0; i < bndLine.Count; i++) + { + if ((bndLine[i].easting < testPoint.easting && bndLine[j].easting >= testPoint.easting) || (bndLine[j].easting < testPoint.easting && bndLine[i].easting >= testPoint.easting)) + { + if (bndLine[i].northing + (testPoint.easting - bndLine[i].easting) / (bndLine[j].easting - bndLine[i].easting) * (bndLine[j].northing - bndLine[i].northing) < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + + public bool IsPointInsideBoundaryEar(vec3 testPoint) + { + bool result = false; + int j = bndLineEar.Count - 1; + for (int i = 0; i < bndLineEar.Count; i++) + { + if ((bndLineEar[i].easting < testPoint.easting && bndLineEar[j].easting >= testPoint.easting) || (bndLineEar[j].easting < testPoint.easting && bndLineEar[i].easting >= testPoint.easting)) + { + if (bndLineEar[i].northing + (testPoint.easting - bndLineEar[i].easting) / (bndLineEar[j].easting - bndLineEar[i].easting) * (bndLineEar[j].northing - bndLineEar[i].northing) < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + + public bool IsPointInsideBoundaryEar(vec2 testPoint) + { + bool result = false; + int j = bndLineEar.Count - 1; + for (int i = 0; i < bndLineEar.Count; i++) + { + if ((bndLineEar[i].easting < testPoint.easting && bndLineEar[j].easting >= testPoint.easting) || (bndLineEar[j].easting < testPoint.easting && bndLineEar[i].easting >= testPoint.easting)) + { + if (bndLineEar[i].northing + (testPoint.easting - bndLineEar[i].easting) / (bndLineEar[j].easting - bndLineEar[i].easting) * (bndLineEar[j].northing - bndLineEar[i].northing) < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + + public void DrawBoundaryLine(int lw, bool outOfBounds) + { + ////draw the perimeter line so far + if (bndLine.Count < 1) return; + //GL.PointSize(8); + //int ptCount = bndLine.Count; + //GL.Color3(0.925f, 0.752f, 0.860f); + ////else + //GL.Begin(PrimitiveType.Points); + //for (int h = 0; h < ptCount; h++) GL.Vertex3(bndLine[h].easting, bndLine[h].northing, 0); + ////GL.Color3(0.95f, 0.972f, 0.90f); + ////GL.Vertex3(bndLine[0].easting, bndLine[0].northing, 0); + //GL.End(); + + //ptCount = bdList.Count; + //if (ptCount < 1) return; + if (!outOfBounds) + { + GL.Color3(0.95f, 0.75f, 0.50f); + GL.LineWidth(lw); + } + else + { + GL.LineWidth(lw * 3); + GL.Color3(0.95f, 0.25f, 0.250f); + } + + GL.Begin(PrimitiveType.LineLoop); + for (int i = 0; i < bndLineEar.Count; i++) + { + GL.Vertex3(bndLineEar[i].easting, bndLineEar[i].northing, 0); + } + GL.End(); + } + + //obvious + public bool CalculateBoundaryArea(int idx) + { + int ptCount = bndLine.Count; + if (ptCount < 1) return false; + bool isClockwise = true; + + area = 0; // Accumulates area in the loop + int j = ptCount - 1; // The last vertex is the 'previous' one to the first + + for (int i = 0; i < ptCount; j = i++) + { + area += (bndLine[j].easting + bndLine[i].easting) * (bndLine[j].northing - bndLine[i].northing); + } + if (area < 0) isClockwise = false; + + area = Math.Abs(area / 2); + + //make sure is clockwise for outer counter clockwise for inner + if ((idx == 0 && isClockwise) || (idx > 0 && !isClockwise)) + { + ReverseWinding(); + } + + return isClockwise; + } + } +} diff --git a/SourceCode/GPS/Classes/CBoundaryList.cs b/SourceCode/GPS/Classes/CBoundaryList.cs deleted file mode 100644 index 8d8eee844..000000000 --- a/SourceCode/GPS/Classes/CBoundaryList.cs +++ /dev/null @@ -1,106 +0,0 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; - -namespace AgOpenGPS -{ - public partial class CBoundaryList - { - //list of coordinates of boundary line - public List fenceLine = new List(128); - public List fenceLineEar = new List(128); - public List hdLine = new List(128); - public List turnLine = new List(128); - - - //constructor - public CBoundaryList() - { - area = 0; - isDriveAround = false; - isDriveThru = false; - } - - public bool IsPointInPolygon(vec3 testPoint, ref List polygon) - { - bool result = false; - int j = polygon.Count - 1; - for (int i = 0; i < polygon.Count; i++) - { - if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) - || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) - { - if (polygon[i].northing + (testPoint.easting - polygon[i].easting) - / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) - < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - - public bool IsPointInPolygon(vec2 testPoint, ref List polygon) - { - bool result = false; - int j = polygon.Count - 1; - for (int i = 0; i < polygon.Count; i++) - { - if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) - || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) - { - if (polygon[i].northing + (testPoint.easting - polygon[i].easting) - / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) - < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - public bool IsPointInPolygon(vec2 testPoint, ref List polygon) - { - bool result = false; - int j = polygon.Count - 1; - for (int i = 0; i < polygon.Count; i++) - { - if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) - || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) - { - if (polygon[i].northing + (testPoint.easting - polygon[i].easting) - / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) - < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - public bool IsPointInPolygon(vec3 testPoint, ref List polygon) - { - bool result = false; - int j = polygon.Count - 1; - for (int i = 0; i < polygon.Count; i++) - { - if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) - || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) - { - if (polygon[i].northing + (testPoint.easting - polygon[i].easting) - / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) - < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - } -} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index b61895a5f..be15b4f9e 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -922,7 +922,7 @@ public void StopContourLine(vec3 pivot) } //build contours for boundaries - public void BuildFenceContours(int pass, int spacingInt) + public void BuildBoundaryContours(int pass, int spacingInt) { if (mf.plot.plots.Count == 0) { @@ -953,7 +953,7 @@ public void BuildFenceContours(int pass, int spacingInt) for (int j = 0; j < mf.plot.plots.Count; j++) { //count the points from the boundary - int ptCount = mf.plot.plots[j].fenceLine.Count; + int ptCount = mf.plot.plots[j].bndLine.Count; ptList = new List(128); stripList.Add(ptList); @@ -961,9 +961,9 @@ public void BuildFenceContours(int pass, int spacingInt) for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.plot.plots[j].fenceLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.plot.plots[j].fenceLine[i].heading) * totalHeadWidth); - point.northing = mf.plot.plots[j].fenceLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.plot.plots[j].fenceLine[i].heading) * totalHeadWidth); - point.heading = mf.plot.plots[j].fenceLine[i].heading - Math.PI; + point.easting = mf.plot.plots[j].bndLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.plot.plots[j].bndLine[i].heading) * totalHeadWidth); + point.northing = mf.plot.plots[j].bndLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.plot.plots[j].bndLine[i].heading) * totalHeadWidth); + point.heading = mf.plot.plots[j].bndLine[i].heading - Math.PI; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if inside actual field boundary diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs deleted file mode 100644 index fc41e2cf3..000000000 --- a/SourceCode/GPS/Classes/CFence.cs +++ /dev/null @@ -1,181 +0,0 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; - -namespace AgOpenGPS -{ - public partial class CBoundary - { - public List bndBeingMadePts = new List(128); - - public double createBndOffset; - public bool isBndBeingMade; - - // the list of possible bounds points - public List bndClosestList = new List(); - - public bool isDrawRightSide = true, isOkToAddPoints = false; - - public int fenceSelected, closestFenceNum; - - //point at the farthest boundary segment from pivotAxle - public vec3 closestFencePt = new vec3(-10000, -10000, 9); - - public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) - { - //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (plots[0].IsPointInPolygon(testPoint, ref plots[0].fenceLine)) - { - for (int i = 1; i < plots.Count; i++) - { - //make sure not inside a non drivethru boundary - if (plots[i].isDriveThru) continue; - if (plots[i].IsPointInPolygon(testPoint, ref plots[i].fenceLine)) - { - return false; - } - } - } - else - { - return false; - } - //we are safely inside outer, outside inner boundaries - return true; - } - - public void DrawBoundaryLines() - { - //draw the boundaries - GL.Color3(0.75f, 0.5f, 0.250f); - - for (int i = 0; i < plots.Count; i++) - { - plots[i].DrawFenceLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); - } - - if (bndBeingMadePts.Count > 0) - { - //the boundary so far - vec3 pivot = mf.pivotAxlePos; - GL.LineWidth(mf.ABLine.lineWidth); - GL.Color3(0.825f, 0.22f, 0.90f); - GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); - GL.Color3(0.295f, 0.972f, 0.290f); - GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - GL.End(); - - //line from last point to pivot marker - GL.Color3(0.825f, 0.842f, 0.0f); - GL.Enable(EnableCap.LineStipple); - GL.LineStipple(1, 0x0700); - GL.Begin(PrimitiveType.LineStrip); - if (isDrawRightSide) - { - GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - - GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * -createBndOffset), - pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * -createBndOffset), 0); - GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); - } - else - { - GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - - GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * createBndOffset), - pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * createBndOffset), 0); - GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); - } - GL.End(); - GL.Disable(EnableCap.LineStipple); - - //boundary points - GL.Color3(0.0f, 0.95f, 0.95f); - GL.PointSize(6.0f); - GL.Begin(PrimitiveType.Points); - for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); - GL.End(); - } - } - - } -} - - -//public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) - //{ - // { - // boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); - // boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); - - // boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); - // boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); - - // boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); - // boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); - - // boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); - // boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); - // } - - // int ptCount; - - // //determine if point is inside bounding box - // bndClosestList.Clear(); - // vec4 inBox; - // for (int i = 0; i < plots.Count; i++) - // { - // //skip the drive thru - // if (plots[i].isDriveThru) continue; - - // ptCount = plots[i].bndLine.Count; - // for (int p = 0; p < ptCount; p++) - // { - // if ((((boxB.easting - boxA.easting) * (plots[i].bndLine[p].northing - boxA.northing)) - // - ((boxB.northing - boxA.northing) * (plots[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } - - // if ((((boxD.easting - boxC.easting) * (plots[i].bndLine[p].northing - boxC.northing)) - // - ((boxD.northing - boxC.northing) * (plots[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } - - // if ((((boxC.easting - boxB.easting) * (plots[i].bndLine[p].northing - boxB.northing)) - // - ((boxC.northing - boxB.northing) * (plots[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } - - // if ((((boxA.easting - boxD.easting) * (plots[i].bndLine[p].northing - boxD.northing)) - // - ((boxA.northing - boxD.northing) * (plots[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } - - // //it's in the box, so add to list - // inBox.easting = plots[i].bndLine[p].easting; - // inBox.northing = plots[i].bndLine[p].northing; - // inBox.heading = plots[i].bndLine[p].heading; - // inBox.index = i; - - // //which boundary/headland is it from - // bndClosestList.Add(inBox); - // } - // } - - // //which of the points is closest - // closestBoundaryPt.easting = -20000; closestBoundaryPt.northing = -20000; - // ptCount = bndClosestList.Count; - // if (ptCount != 0) - // { - // //determine closest point - // double minDistance = 9999999; - // for (int i = 0; i < ptCount; i++) - // { - // double dist = ((fromPt.easting - bndClosestList[i].easting) * (fromPt.easting - bndClosestList[i].easting)) - // + ((fromPt.northing - bndClosestList[i].northing) * (fromPt.northing - bndClosestList[i].northing)); - // if (minDistance >= dist) - // { - // minDistance = dist; - - // closestBoundaryPt.easting = bndClosestList[i].easting; - // closestBoundaryPt.northing = bndClosestList[i].northing; - // closestBoundaryPt.heading = bndClosestList[i].heading; - // closestBoundaryNum = bndClosestList[i].index; - // } - // } - // if (closestBoundaryPt.heading < 0) closestBoundaryPt.heading += glm.twoPI; - // } - //} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CFenceLine.cs b/SourceCode/GPS/Classes/CFenceLine.cs deleted file mode 100644 index 9a84e554b..000000000 --- a/SourceCode/GPS/Classes/CFenceLine.cs +++ /dev/null @@ -1,213 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using OpenTK.Graphics.OpenGL; - -namespace AgOpenGPS -{ - public partial class CBoundaryList - { - //area variable - public double area; - - //boundary variables - public bool isDriveAround, isDriveThru; - - public void CalculateFenceLineHeadings() - { - //to calc heading based on next and previous points to give an average heading. - int cnt = fenceLine.Count; - vec3[] arr = new vec3[cnt]; - cnt--; - fenceLine.CopyTo(arr); - fenceLine.Clear(); - - //first point needs last, first, second points - vec3 pt3 = arr[0]; - pt3.heading = Math.Atan2(arr[1].easting - arr[cnt].easting, arr[1].northing - arr[cnt].northing); - if (pt3.heading < 0) pt3.heading += glm.twoPI; - fenceLine.Add(pt3); - - //middle points - for (int i = 1; i < cnt; i++) - { - pt3 = arr[i]; - pt3.heading = Math.Atan2(arr[i + 1].easting - arr[i - 1].easting, arr[i + 1].northing - arr[i - 1].northing); - if (pt3.heading < 0) pt3.heading += glm.twoPI; - fenceLine.Add(pt3); - } - - //last and first point - pt3 = arr[cnt]; - pt3.heading = Math.Atan2(arr[0].easting - arr[cnt - 1].easting, arr[0].northing - arr[cnt - 1].northing); - if (pt3.heading < 0) pt3.heading += glm.twoPI; - fenceLine.Add(pt3); - } - - public void FixFenceLine(int bndNum) - { - double spacing; - //boundary point spacing based on eq width - //close if less then 30 ha, 60ha, more then 60 - if (area < 200000) spacing = 1.1; - else if (area < 400000) spacing = 2.2; - else spacing = 3.3; - - if (bndNum > 0) spacing *= 0.5; - - int bndCount = fenceLine.Count; - double distance; - - //make sure distance isn't too big between points on boundary - for (int i = 0; i < bndCount; i++) - { - int j = i + 1; - - if (j == bndCount) j = 0; - distance = glm.Distance(fenceLine[i], fenceLine[j]); - if (distance > spacing * 1.5) - { - vec3 pointB = new vec3((fenceLine[i].easting + fenceLine[j].easting) / 2.0, - (fenceLine[i].northing + fenceLine[j].northing) / 2.0, fenceLine[i].heading); - - fenceLine.Insert(j, pointB); - bndCount = fenceLine.Count; - i--; - } - } - - //make sure distance isn't too big between points on boundary - bndCount = fenceLine.Count; - - for (int i = 0; i < bndCount; i++) - { - int j = i + 1; - - if (j == bndCount) j = 0; - distance = glm.Distance(fenceLine[i], fenceLine[j]); - if (distance > spacing * 1.6) - { - vec3 pointB = new vec3((fenceLine[i].easting + fenceLine[j].easting) / 2.0, - (fenceLine[i].northing + fenceLine[j].northing) / 2.0, fenceLine[i].heading); - - fenceLine.Insert(j, pointB); - bndCount = fenceLine.Count; - i--; - } - } - - //make sure distance isn't too small between points on headland - spacing *= 1.2; - bndCount = fenceLine.Count; - for (int i = 0; i < bndCount - 1; i++) - { - distance = glm.Distance(fenceLine[i], fenceLine[i + 1]); - if (distance < spacing) - { - fenceLine.RemoveAt(i + 1); - bndCount = fenceLine.Count; - i--; - } - } - - //make sure headings are correct for calculated points - CalculateFenceLineHeadings(); - - double delta = 0; - fenceLineEar?.Clear(); - - for (int i = 0; i < fenceLine.Count; i++) - { - if (i == 0) - { - fenceLineEar.Add(new vec2(fenceLine[i].easting, fenceLine[i].northing)); - continue; - } - delta += (fenceLine[i - 1].heading - fenceLine[i].heading); - if (Math.Abs(delta) > 0.01) - { - fenceLineEar.Add(new vec2(fenceLine[i].easting, fenceLine[i].northing)); - delta = 0; - } - } - } - - public void ReverseWinding() - { - //reverse the boundary - int cnt = fenceLine.Count; - vec3[] arr = new vec3[cnt]; - cnt--; - fenceLine.CopyTo(arr); - fenceLine.Clear(); - for (int i = cnt; i >= 0; i--) - { - arr[i].heading -= Math.PI; - if (arr[i].heading < 0) arr[i].heading += glm.twoPI; - fenceLine.Add(arr[i]); - } - } - - public void DrawFenceLine(int lw, bool outOfBounds) - { - ////draw the perimeter line so far - if (fenceLine.Count < 1) return; - //GL.PointSize(8); - //int ptCount = bndLine.Count; - //GL.Color3(0.925f, 0.752f, 0.860f); - ////else - //GL.Begin(PrimitiveType.Points); - //for (int h = 0; h < ptCount; h++) GL.Vertex3(bndLine[h].easting, bndLine[h].northing, 0); - ////GL.Color3(0.95f, 0.972f, 0.90f); - ////GL.Vertex3(bndLine[0].easting, bndLine[0].northing, 0); - //GL.End(); - - //ptCount = bdList.Count; - //if (ptCount < 1) return; - if (!outOfBounds) - { - GL.Color3(0.95f, 0.75f, 0.50f); - GL.LineWidth(lw); - } - else - { - GL.LineWidth(lw * 3); - GL.Color3(0.95f, 0.25f, 0.250f); - } - - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < fenceLineEar.Count; i++) - { - GL.Vertex3(fenceLineEar[i].easting, fenceLineEar[i].northing, 0); - } - GL.End(); - } - - //obvious - public bool CalculateFenceArea(int idx) - { - int ptCount = fenceLine.Count; - if (ptCount < 1) return false; - bool isClockwise = true; - - area = 0; // Accumulates area in the loop - int j = ptCount - 1; // The last vertex is the 'previous' one to the first - - for (int i = 0; i < ptCount; j = i++) - { - area += (fenceLine[j].easting + fenceLine[i].easting) * (fenceLine[j].northing - fenceLine[i].northing); - } - if (area < 0) isClockwise = false; - - area = Math.Abs(area / 2); - - //make sure is clockwise for outer counter clockwise for inner - if ((idx == 0 && isClockwise) || (idx > 0 && !isClockwise)) - { - ReverseWinding(); - } - - return isClockwise; - } - } -} diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index e7379034e..ca3060637 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -2,9 +2,9 @@ namespace AgOpenGPS { - public partial class CBoundary + public partial class CPlot { - public bool isHeadlandOn; + public bool isOn; public double leftToolDistance; public double rightToolDistance; @@ -41,15 +41,15 @@ public void WhereAreToolCorners() { bool isLeftInWk, isRightInWk = true; - if (isHeadlandOn) + if (isOn) { for (int j = 0; j < mf.tool.numOfSections; j++) { if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftInWk = plots[0].IsPointInPolygon(mf.section[j].leftPoint, ref plots[0].hdLine); - isRightInWk = plots[0].IsPointInPolygon(mf.section[j].rightPoint, ref plots[0].hdLine); + isLeftInWk = plots[0].IsPointInHeadArea(mf.section[j].leftPoint); + isRightInWk = plots[0].IsPointInHeadArea(mf.section[j].rightPoint); //save left side mf.tool.isLeftSideInHeadland = !isLeftInWk; @@ -62,7 +62,7 @@ public void WhereAreToolCorners() { //grab the right of previous section, its the left of this section isLeftInWk = isRightInWk; - isRightInWk = plots[0].IsPointInPolygon(mf.section[j].rightPoint, ref plots[0].hdLine); + isRightInWk = plots[0].IsPointInHeadArea(mf.section[j].rightPoint); mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } @@ -156,11 +156,11 @@ public void DrawHeadLines() public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add - if (plots.Count > 0 && plots[0].IsPointInPolygon(pt, ref plots[0].hdLine)) + if (plots.Count > 0 && plots[0].IsPointInHeadArea(pt)) { for (int b = 1; b < plots.Count; b++) { - if (plots[b].IsPointInPolygon(pt, ref plots[b].hdLine)) + if (plots[b].IsPointInHeadArea(pt)) { //point is in an inner turn area but inside outer return false; diff --git a/SourceCode/GPS/Classes/CHeadLines.cs b/SourceCode/GPS/Classes/CHeadLines.cs index 634e61b08..1fc4ea59f 100644 --- a/SourceCode/GPS/Classes/CHeadLines.cs +++ b/SourceCode/GPS/Classes/CHeadLines.cs @@ -2,8 +2,43 @@ namespace AgOpenGPS { - public partial class CBoundaryList + public partial class CPlots { + public bool IsPointInHeadArea(vec2 testPoint) + { + bool result = false; + int j = hdLine.Count - 1; + for (int i = 0; i < hdLine.Count; i++) + { + if ((hdLine[i].easting < testPoint.easting && hdLine[j].easting >= testPoint.easting) || (hdLine[j].easting < testPoint.easting && hdLine[i].easting >= testPoint.easting)) + { + if (hdLine[i].northing + (testPoint.easting - hdLine[i].easting) / (hdLine[j].easting - hdLine[i].easting) * (hdLine[j].northing - hdLine[i].northing) < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + + public bool IsPointInHeadArea(vec3 testPoint) + { + bool result = false; + int j = hdLine.Count - 1; + for (int i = 0; i < hdLine.Count; i++) + { + if ((hdLine[i].easting < testPoint.easting && hdLine[j].easting >= testPoint.easting) || (hdLine[j].easting < testPoint.easting && hdLine[i].easting >= testPoint.easting)) + { + if (hdLine[i].northing + (testPoint.easting - hdLine[i].easting) / (hdLine[j].easting - hdLine[i].easting) * (hdLine[j].northing - hdLine[i].northing) < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } public void DrawHeadLine() { diff --git a/SourceCode/GPS/Classes/CPlot.cs b/SourceCode/GPS/Classes/CPlot.cs new file mode 100644 index 000000000..af734e7a7 --- /dev/null +++ b/SourceCode/GPS/Classes/CPlot.cs @@ -0,0 +1,35 @@ +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; + +namespace AgOpenGPS +{ + public partial class CPlot + { + //copy of the mainform address + private readonly FormGPS mf; + + /// + /// array of boundaries + /// + /// + public List plots = new List(); + + private readonly double scanWidth, boxLength; + + public bool isDrawRightSide = true, isOkToAddPoints = false; + //constructor + public CPlot(FormGPS _f) + { + mf = _f; + boundarySelected = 0; + scanWidth = 1.0; + boxLength = 2000; + + turnSelected = 0; + + isOn = false; + isToolUp = true; + } + } +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CPlots.cs b/SourceCode/GPS/Classes/CPlots.cs new file mode 100644 index 000000000..879e18796 --- /dev/null +++ b/SourceCode/GPS/Classes/CPlots.cs @@ -0,0 +1,30 @@ +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; + +namespace AgOpenGPS +{ + public partial class CPlots + { + //list of coordinates of boundary line + public List bndLine = new List(128); + public List bndLineEar = new List(128); + public List hdLine = new List(128); + public List turnLine = new List(128); + + //area variable + public double area; + + //boundary variables + public bool isDriveAround, isDriveThru; + + //constructor + public CPlots() + { + area = 0; + isDriveAround = false; + isDriveThru = false; + } + + } +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CTram.cs b/SourceCode/GPS/Classes/CTram.cs index f00222a02..7b6455fa3 100644 --- a/SourceCode/GPS/Classes/CTram.cs +++ b/SourceCode/GPS/Classes/CTram.cs @@ -101,7 +101,7 @@ public void BuildTramBnd() private void CreateBndInnerTramTrack() { //count the points from the boundary - int ptCount = mf.plot.plots[0].fenceLine.Count; + int ptCount = mf.plot.plots[0].bndLine.Count; tramBndInnerArr?.Clear(); //outside point @@ -113,18 +113,18 @@ private void CreateBndInnerTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].fenceLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.easting = mf.plot.plots[0].bndLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); - pt3.northing = mf.plot.plots[0].fenceLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.northing = mf.plot.plots[0].bndLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); + mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); if (check < distSq) { Add = false; @@ -149,7 +149,7 @@ private void CreateBndInnerTramTrack() public void CreateBndOuterTramTrack() { //count the points from the boundary - int ptCount = mf.plot.plots[0].fenceLine.Count; + int ptCount = mf.plot.plots[0].bndLine.Count; tramBndOuterArr?.Clear(); //outside point @@ -161,18 +161,18 @@ public void CreateBndOuterTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].fenceLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.easting = mf.plot.plots[0].bndLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); - pt3.northing = mf.plot.plots[0].fenceLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.northing = mf.plot.plots[0].bndLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); + mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); if (check < distSq) { Add = false; diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index 7a8b37987..30bdda5ea 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -4,20 +4,13 @@ namespace AgOpenGPS { - public partial class CBoundary + public partial class CPlot { // the list of possible bounds points public List turnClosestList = new List(); public int turnSelected, closestTurnNum; - //generated box for finding closest point - public vec2 boxA = new vec2(9000, 9000), boxB = new vec2(9000, 9002); - - public vec2 boxC = new vec2(9001, 9001), boxD = new vec2(9002, 9003); - - private readonly double boxLength; - //point at the farthest turn segment from pivotAxle public vec3 closestTurnPt = new vec3(-10000, -10000, 9); @@ -38,13 +31,13 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (plots[0].IsPointInPolygon(pt, ref plots[0].turnLine)) + if (plots[0].IsPointInTurnWorkArea(pt)) { for (int t = 1; t < plots.Count; t++) { if (plots[t].isDriveThru) continue; if (plots[t].isDriveAround) continue; - if (plots[t].IsPointInPolygon(pt, ref plots[0].turnLine)) + if (plots[t].IsPointInTurnWorkArea(pt)) { isFound = true; closestTurnNum = t; @@ -228,18 +221,18 @@ public void BuildTurnLines() plots[j].turnLine.Clear(); if (plots[j].isDriveThru || plots[j].isDriveAround) continue; - int ptCount = plots[j].fenceLine.Count; + int ptCount = plots[j].bndLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point outside the boundary - point.easting = plots[j].fenceLine[i].easting + (-Math.Sin(glm.PIBy2 + plots[j].fenceLine[i].heading) * totalHeadWidth); - point.northing = plots[j].fenceLine[i].northing + (-Math.Cos(glm.PIBy2 + plots[j].fenceLine[i].heading) * totalHeadWidth); - point.heading = plots[j].fenceLine[i].heading; + point.easting = plots[j].bndLine[i].easting + (-Math.Sin(glm.PIBy2 + plots[j].bndLine[i].heading) * totalHeadWidth); + point.northing = plots[j].bndLine[i].northing + (-Math.Cos(glm.PIBy2 + plots[j].bndLine[i].heading) * totalHeadWidth); + point.heading = plots[j].bndLine[i].heading; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == plots[j].IsPointInPolygon(point, ref plots[j].fenceLineEar)) + if (j == 0 == plots[j].IsPointInsideBoundaryEar(point)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); plots[j].turnLine.Add(tPnt); diff --git a/SourceCode/GPS/Classes/CTurnLines.cs b/SourceCode/GPS/Classes/CTurnLines.cs index 83bd604fd..db8e8cf07 100644 --- a/SourceCode/GPS/Classes/CTurnLines.cs +++ b/SourceCode/GPS/Classes/CTurnLines.cs @@ -3,7 +3,7 @@ namespace AgOpenGPS { - public partial class CBoundaryList + public partial class CPlots { public void CalculateTurnHeadings() { @@ -48,12 +48,12 @@ public void FixTurnLine(double totalHeadWidth, double spacing) double distance; //remove the points too close to boundary - for (int i = 0; i < fenceLine.Count; i++) + for (int i = 0; i < bndLine.Count; i++) { for (int j = 0; j < lineCount; j++) { //make sure distance between headland and boundary is not less then width - distance = glm.DistanceSquared(fenceLine[i], turnLine[j]); + distance = glm.DistanceSquared(bndLine[i], turnLine[j]); if (distance < (totalHeadWidth * 0.99)) { turnLine.RemoveAt(j); @@ -125,6 +125,23 @@ public void FixTurnLine(double totalHeadWidth, double spacing) //} } + public bool IsPointInTurnWorkArea(vec3 testPoint) + { + bool result = false; + int j = turnLine.Count - 1; + for (int i = 0; i < turnLine.Count; i++) + { + if ((turnLine[i].easting < testPoint.easting && turnLine[j].easting >= testPoint.easting) || (turnLine[j].easting < testPoint.easting && turnLine[i].easting >= testPoint.easting)) + { + if (turnLine[i].northing + (testPoint.easting - turnLine[i].easting) / (turnLine[j].easting - turnLine[i].easting) * (turnLine[j].northing - turnLine[i].northing) < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } public void DrawTurnLine() { ////draw the turn line oject diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index 26bf06e86..4e7b9b385 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -115,7 +115,7 @@ public bool FindCurveTurnPoints() //for each point in succession keep going till a turnLine is found. for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) { - if (!mf.plot.plots[0].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[0].turnLine)) + if (!mf.plot.plots[0].IsPointInTurnWorkArea(mf.curve.curList[j])) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -130,7 +130,7 @@ public bool FindCurveTurnPoints() //make sure not inside a non drivethru boundary if (mf.plot.plots[i].isDriveThru) continue; if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[i].turnLine)) + if (mf.plot.plots[i].IsPointInTurnWorkArea(mf.curve.curList[j])) { crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -152,7 +152,7 @@ public bool FindCurveTurnPoints() for (int j = mf.curve.currentLocationIndex; j > 0; j--) { - if (!mf.plot.plots[0].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[0].turnLine)) + if (!mf.plot.plots[0].IsPointInTurnWorkArea(mf.curve.curList[j])) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; @@ -167,7 +167,7 @@ public bool FindCurveTurnPoints() //make sure not inside a non drivethru boundary if (mf.plot.plots[i].isDriveThru) continue; if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInPolygon(mf.curve.curList[j], ref mf.plot.plots[i].turnLine)) + if (mf.plot.plots[i].IsPointInTurnWorkArea(mf.curve.curList[j])) { crossingCurvePoint.easting = mf.curve.curList[j].easting; crossingCurvePoint.northing = mf.curve.curList[j].northing; @@ -584,7 +584,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.plot.plots[0].IsPointInPolygon(ytList[j],ref mf.plot.plots[0].turnLine)) isOutOfBounds = true; + if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; if (isOutOfBounds) break; for (int i = 1; i < mf.plot.plots.Count; i++) @@ -592,7 +592,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) //make sure not inside a non drivethru boundary if (mf.plot.plots[i].isDriveThru) continue; if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[i].turnLine)) + if (mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; @@ -644,7 +644,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.plot.plots[0].IsPointInPolygon(ytList[j], ref mf.plot.plots[0].turnLine)) isOutOfBounds = true; + if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; if (isOutOfBounds) break; @@ -653,7 +653,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) //make sure not inside a non drivethru boundary if (mf.plot.plots[i].isDriveThru) continue; if (mf.plot.plots[i].isDriveAround) continue; - if (!mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[i].turnLine)) + if (!mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; @@ -852,7 +852,7 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!mf.plot.plots[0].IsPointInPolygon(ytList[j], ref mf.plot.plots[0].turnLine)) + if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; @@ -863,7 +863,7 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) //make sure not inside a non drivethru boundary if (mf.plot.plots[i].isDriveThru) continue; if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInPolygon(ytList[j], ref mf.plot.plots[1].turnLine)) + if (mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index 76a7f2beb..0055a0d97 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -1551,8 +1551,8 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) { if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - plot.isHeadlandOn = !plot.isHeadlandOn; - if (plot.isHeadlandOn) + plot.isOn = !plot.isOn; + if (plot.isOn) { btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHydLift.Visible = true; @@ -1563,9 +1563,9 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; } } - else plot.isHeadlandOn = false; + else plot.isOn = false; - if (!plot.isHeadlandOn) + if (!plot.isOn) { p_239.pgn[p_239.hydLift] = 0; vehicle.isHydLiftOn = false; @@ -1577,7 +1577,7 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) private void btnHydLift_Click(object sender, EventArgs e) { - if (plot.isHeadlandOn) + if (plot.isOn) { vehicle.isHydLiftOn = !vehicle.isHydLiftOn; if (vehicle.isHydLiftOn) @@ -1976,7 +1976,7 @@ public void GetHeadland() if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - plot.isHeadlandOn = true; + plot.isOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -1984,7 +1984,7 @@ public void GetHeadland() } else { - plot.isHeadlandOn = false; + plot.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index 7df2c5359..8721b187b 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -151,7 +151,7 @@ private void UpdateChart() b.Text = Math.Round(mf.plot.plots[i].area * 0.000247105, 2) + " Ac"; } - if (Selectedreset == false && i == mf.plot.fenceSelected) + if (Selectedreset == false && i == mf.plot.boundarySelected) { a.ForeColor = Color.OrangeRed; b.ForeColor = Color.OrangeRed; @@ -188,16 +188,16 @@ private void B_Click(object sender, EventArgs e) if (sender is Button b) { - mf.plot.fenceSelected = Convert.ToInt32(b.Name); + mf.plot.boundarySelected = Convert.ToInt32(b.Name); - if (mf.plot.fenceSelected == 0 && mf.plot.plots.Count > 1) + if (mf.plot.boundarySelected == 0 && mf.plot.plots.Count > 1) { return; } Selectedreset = false; - if (mf.plot.plots.Count > mf.plot.fenceSelected) + if (mf.plot.plots.Count > mf.plot.boundarySelected) { btnDelete.Enabled = true; } @@ -229,14 +229,14 @@ private void btnDelete_Click(object sender, EventArgs e) btnDelete.Enabled = false; - if (mf.plot.plots.Count > mf.plot.fenceSelected) + if (mf.plot.plots.Count > mf.plot.boundarySelected) { - mf.plot.plots.RemoveAt(mf.plot.fenceSelected); + mf.plot.plots.RemoveAt(mf.plot.boundarySelected); } mf.FileSaveBoundary(); - mf.plot.fenceSelected = -1; + mf.plot.boundarySelected = -1; Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); mf.plot.BuildTurnLines(); @@ -282,7 +282,7 @@ private void btnDeleteAll_Click(object sender, EventArgs e) ResetAllBoundary(); - mf.plot.fenceSelected = -1; + mf.plot.boundarySelected = -1; Selectedreset = true; mf.plot.isOkToAddPoints = false; @@ -310,7 +310,7 @@ private void btnReturn_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e) { - mf.plot.fenceSelected = mf.plot.plots.Count; + mf.plot.boundarySelected = mf.plot.plots.Count; Selectedreset = false; @@ -353,7 +353,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) { if (button.Name == "btnLoadMultiBoundaryFromGE") ResetAllBoundary(); - else i = mf.plot.fenceSelected; + else i = mf.plot.boundarySelected; try { @@ -394,7 +394,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) //at least 3 points if (numberSets.Length > 2) { - CBoundaryList New = new CBoundaryList(); + CPlots New = new CPlots(); foreach (string item in numberSets) { @@ -405,11 +405,11 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) mf.pn.ConvertWGS84ToLocal(latK, lonK, out norting, out easting); //add the point to boundary - New.fenceLine.Add(new vec3(easting, norting, 0)); + New.bndLine.Add(new vec3(easting, norting, 0)); } - New.CalculateFenceArea(mf.plot.fenceSelected); - New.FixFenceLine(i); + New.CalculateBoundaryArea(mf.plot.boundarySelected); + New.FixBoundaryLine(i); mf.plot.plots.Add(New); diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 59b15796d..2d8a3f2a0 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -29,15 +29,15 @@ private void btnStop_Click(object sender, EventArgs e) { if (mf.plot.bndBeingMadePts.Count > 2) { - CBoundaryList New = new CBoundaryList(); + CPlots New = new CPlots(); for (int i = 0; i < mf.plot.bndBeingMadePts.Count; i++) { - New.fenceLine.Add(mf.plot.bndBeingMadePts[i]); + New.bndLine.Add(mf.plot.bndBeingMadePts[i]); } - New.CalculateFenceArea(mf.plot.fenceSelected); - New.FixFenceLine(mf.plot.fenceSelected); + New.CalculateBoundaryArea(mf.plot.boundarySelected); + New.FixBoundaryLine(mf.plot.boundarySelected); mf.plot.plots.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 22bc7ebf7..034d3e748 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -125,7 +125,7 @@ private void LoadKMLBoundary(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.plot.fenceSelected; + i = mf.plot.boundarySelected; try { @@ -166,7 +166,7 @@ private void LoadKMLBoundary(string filename) //at least 3 points if (numberSets.Length > 2) { - CBoundaryList New = new CBoundaryList(); + CPlots New = new CPlots(); foreach (string item in numberSets) { @@ -179,12 +179,12 @@ private void LoadKMLBoundary(string filename) mf.pn.ConvertWGS84ToLocal(latK, lonK, out northing, out easting); //add the point to boundary - New.fenceLine.Add(new vec3(easting, northing, 0)); + New.bndLine.Add(new vec3(easting, northing, 0)); } //build the boundary, make sure is clockwise for outer counter clockwise for inner - New.CalculateFenceArea(mf.plot.fenceSelected); - New.FixFenceLine(i); + New.CalculateBoundaryArea(mf.plot.boundarySelected); + New.FixBoundaryLine(i); mf.plot.plots.Add(New); @@ -233,7 +233,7 @@ private void FindLatLon(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.plot.fenceSelected; + i = mf.plot.boundarySelected; try { diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index 2e2d2e18c..d4d2c5a57 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -187,7 +187,7 @@ public partial class FormGPS : Form /// /// The boundary object /// - public CBoundary plot; + public CPlot plot; /// /// The internal simulator @@ -366,7 +366,7 @@ public FormGPS() mc = new CModuleComm(); //boundary object - plot = new CBoundary(this); + plot = new CPlot(this); //nmea simulator built in. sim = new CSim(this); @@ -979,7 +979,7 @@ public void JobClose() pn.fixOffset.northing = 0; //turn off headland - plot.isHeadlandOn = false; + plot.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; diff --git a/SourceCode/GPS/Forms/FormHeadland.cs b/SourceCode/GPS/Forms/FormHeadland.cs index 3ce8739dc..9091c6a0a 100644 --- a/SourceCode/GPS/Forms/FormHeadland.cs +++ b/SourceCode/GPS/Forms/FormHeadland.cs @@ -80,13 +80,13 @@ public void BuildHeadLineTemplateFromBoundary() //outside boundary - count the points from the boundary headLineTemplate.Clear(); - int ptCount = mf.plot.plots[0].fenceLine.Count; + int ptCount = mf.plot.plots[0].bndLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.plot.plots[0].fenceLine[i].easting; - point.northing = mf.plot.plots[0].fenceLine[i].northing; - point.heading = mf.plot.plots[0].fenceLine[i].heading; + point.easting = mf.plot.plots[0].bndLine[i].easting; + point.northing = mf.plot.plots[0].bndLine[i].northing; + point.heading = mf.plot.plots[0].bndLine[i].heading; headLineTemplate.Add(point); } diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 2ffa9913f..66dab5db2 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -498,7 +498,7 @@ public void LoadSettings() if (Properties.Settings.Default.setAS_isAutoSteerAutoOn) btnAutoSteer.Text = "R"; else btnAutoSteer.Text = "M"; - if (plot.isHeadlandOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; + if (plot.isOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; else btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnChangeMappingColor.BackColor = sectionColorDay; diff --git a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs index 073fd189d..b19add630 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs @@ -46,21 +46,21 @@ public FormABDraw(Form callingForm) private void FormABDraw_Load(object sender, EventArgs e) { - int cnt = mf.plot.plots[0].fenceLine.Count; + int cnt = mf.plot.plots[0].bndLine.Count; arr = new vec3[cnt * 2]; for (int i = 0; i < cnt; i++) { - arr[i].easting = mf.plot.plots[0].fenceLine[i].easting; - arr[i].northing = mf.plot.plots[0].fenceLine[i].northing; - arr[i].heading = mf.plot.plots[0].fenceLine[i].heading; + arr[i].easting = mf.plot.plots[0].bndLine[i].easting; + arr[i].northing = mf.plot.plots[0].bndLine[i].northing; + arr[i].heading = mf.plot.plots[0].bndLine[i].heading; } for (int i = cnt; i < cnt * 2; i++) { - arr[i].easting = mf.plot.plots[0].fenceLine[i - cnt].easting; - arr[i].northing = mf.plot.plots[0].fenceLine[i - cnt].northing; - arr[i].heading = mf.plot.plots[0].fenceLine[i - cnt].heading; + arr[i].easting = mf.plot.plots[0].bndLine[i - cnt].easting; + arr[i].northing = mf.plot.plots[0].bndLine[i - cnt].northing; + arr[i].heading = mf.plot.plots[0].bndLine[i - cnt].heading; } nudDistance.Value = (decimal)Math.Round(((mf.tool.toolWidth * mf.m2InchOrCm) * 0.5), 0); // @@ -356,7 +356,7 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) { //count the points from the boundary - int ptCount = mf.plot.plots[0].fenceLine.Count; + int ptCount = mf.plot.plots[0].bndLine.Count; mf.curve.refList?.Clear(); //outside point @@ -369,20 +369,20 @@ private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].fenceLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (moveDist)); + pt3.easting = mf.plot.plots[0].bndLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (moveDist)); - pt3.northing = mf.plot.plots[0].fenceLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].fenceLine[i].heading) * (moveDist)); + pt3.northing = mf.plot.plots[0].bndLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (moveDist)); - pt3.heading = mf.plot.plots[0].fenceLine[i].heading; + pt3.heading = mf.plot.plots[0].bndLine[i].heading; bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].fenceLine[j].northing, mf.plot.plots[0].fenceLine[j].easting); + mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); if (check < distSq) { Add = false; diff --git a/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs b/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs index 2d05e3c58..9d182e165 100644 --- a/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs +++ b/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs @@ -24,7 +24,7 @@ public FormMakeBndCon(Form _mf) private void BtnOk_Click(object sender, System.EventArgs e) { //convert to meters - mf.ct.BuildFenceContours((int)nudPass.Value, (int)(nudSpacing.Value * 0.01m)); + mf.ct.BuildBoundaryContours((int)nudPass.Value, (int)(nudSpacing.Value * 0.01m)); Close(); } diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index 53c2a662a..c763d943b 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -346,7 +346,7 @@ private void oglMain_Paint(object sender, PaintEventArgs e) plot.DrawTurnLines(); } - if (plot.isHeadlandOn) + if (plot.isOn) { GL.LineWidth(ABLine.lineWidth); GL.Color3(0.960f, 0.96232f, 0.30f); @@ -619,19 +619,19 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (plot.plots.Count > 0) { ////draw the bnd line - int ptCount = plot.plots[0].fenceLine.Count; + int ptCount = plot.plots[0].bndLine.Count; if (ptCount > 3) { GL.LineWidth(3); GL.Color3((byte)0, (byte)240, (byte)0); GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < ptCount; h++) GL.Vertex3(plot.plots[0].fenceLine[h].easting, plot.plots[0].fenceLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(plot.plots[0].bndLine[h].easting, plot.plots[0].bndLine[h].northing, 0); GL.End(); } } //draw 250 green for the headland - if (plot.isHeadlandOn) + if (plot.isOn) { GL.LineWidth(3); GL.Color3((byte)0, (byte)250, (byte)0); @@ -677,7 +677,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tool.numOfSections == 1 || pn.speed < vehicle.slowSpeedCutoff) tool.isSuperSectionAllowedOn = false; - if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && plot.isHeadlandOn) + if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && plot.isOn) tool.isSuperSectionAllowedOn = false; //clamp the height after looking way ahead, this is for switching off super section only @@ -687,7 +687,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //10 % min is required for overlap, otherwise it never would be on. int pixLimit = (int)((double)(section[0].rpSectionWidth * rpOnHeight) / (double)(5.0)); - if ((rpOnHeight < rpToolHeight && plot.isHeadlandOn)) rpHeight = rpToolHeight + 2; + if ((rpOnHeight < rpToolHeight && plot.isOn)) rpHeight = rpToolHeight + 2; else rpHeight = rpOnHeight + 2; if (rpHeight > 290) rpHeight = 290; @@ -749,7 +749,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //determine if in or out of headland, do hydraulics if on - if (plot.isHeadlandOn) + if (plot.isOn) { //calculate the slope double m = (vehicle.hydLiftLookAheadDistanceRight - vehicle.hydLiftLookAheadDistanceLeft) / tool.rpWidth; @@ -935,7 +935,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) section[j].mappingOnTimer = 0; } - else if (section[j].isInHeadlandArea & plot.isHeadlandOn) + else if (section[j].isInHeadlandArea & plot.isOn) { // if headland is on and out, turn off section[j].isMappingRequiredOn = false; @@ -950,7 +950,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) /////////////////////////////////////////// Section control ssssssssssssssssssssss /// - if (plot.isHeadlandOn) plot.WhereAreToolLookOnPoints(); + if (plot.isOn) plot.WhereAreToolLookOnPoints(); for (int j = 0; j < tool.numOfSections; j++) { @@ -1013,7 +1013,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //is headland coming up - if (plot.isHeadlandOn) + if (plot.isOn) { bool isHeadlandInLookOn = false; @@ -2387,11 +2387,11 @@ public void CalculateMinMax() //min max of the boundary if (plot.plots.Count > 0) { - int bndCnt = plot.plots[0].fenceLine.Count; + int bndCnt = plot.plots[0].bndLine.Count; for (int i = 0; i < bndCnt; i++) { - double x = plot.plots[0].fenceLine[i].easting; - double y = plot.plots[0].fenceLine[i].northing; + double x = plot.plots[0].bndLine[i].easting; + double y = plot.plots[0].bndLine[i].northing; //also tally the max/min of field x and z if (minFieldX > x) minFieldX = x; diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index 4a766dae7..a0c7c217d 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -1238,7 +1238,7 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (tool.lookAheadDistanceOffPixelsRight > 160) tool.lookAheadDistanceOffPixelsRight = 160; //determine where the tool is wrt to headland - if (plot.isHeadlandOn) plot.WhereAreToolCorners(); + if (plot.isOn) plot.WhereAreToolCorners(); //set up the super for youturn section[tool.numOfSections].isInBoundary = true; @@ -1253,14 +1253,14 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftIn = plot.plots[0].IsPointInPolygon(section[j].leftPoint, ref plot.plots[0].fenceLineEar); - isRightIn = plot.plots[0].IsPointInPolygon(section[j].rightPoint, ref plot.plots[0].fenceLineEar); + isLeftIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].leftPoint); + isRightIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].rightPoint); for (int i = 1; i < plot.plots.Count; i++) { //inner boundaries should normally NOT have point inside - isLeftIn &= !plot.plots[i].IsPointInPolygon(section[j].leftPoint, ref plot.plots[i].fenceLineEar); - isRightIn &= !plot.plots[i].IsPointInPolygon(section[j].rightPoint, ref plot.plots[i].fenceLineEar); + isLeftIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].leftPoint); + isRightIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].rightPoint); } //merge the two sides into in or out @@ -1272,11 +1272,11 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { //grab the right of previous section, its the left of this section isLeftIn = isRightIn; - isRightIn = plot.plots[0].IsPointInPolygon(section[j].rightPoint, ref plot.plots[0].fenceLineEar); + isRightIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].rightPoint); for (int i = 1; i < plot.plots.Count; i++) { //inner boundaries should normally NOT have point inside - isRightIn &= !plot.plots[i].IsPointInPolygon(section[j].rightPoint, ref plot.plots[i].fenceLineEar); + isRightIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].rightPoint); } if (isLeftIn && isRightIn) section[j].isInBoundary = true; diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index 726feae46..df00849ed 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -683,7 +683,7 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - CBoundaryList New = new CBoundaryList(); + CPlots New = new CPlots(); //True or False OR points from older boundary files line = reader.ReadLine(); @@ -716,25 +716,25 @@ public void FileOpenField(string _openType) double.Parse(words[1], CultureInfo.InvariantCulture), double.Parse(words[2], CultureInfo.InvariantCulture)); - New.fenceLine.Add(vecPt); + New.bndLine.Add(vecPt); } - New.CalculateFenceArea(k); + New.CalculateBoundaryArea(k); double delta = 0; - New.fenceLineEar?.Clear(); + New.bndLineEar?.Clear(); - for (int i = 0; i < New.fenceLine.Count; i++) + for (int i = 0; i < New.bndLine.Count; i++) { if (i == 0) { - New.fenceLineEar.Add(new vec2(New.fenceLine[i].easting, New.fenceLine[i].northing)); + New.bndLineEar.Add(new vec2(New.bndLine[i].easting, New.bndLine[i].northing)); continue; } - delta += (New.fenceLine[i - 1].heading - New.fenceLine[i].heading); + delta += (New.bndLine[i - 1].heading - New.bndLine[i].heading); if (Math.Abs(delta) > 0.04) { - New.fenceLineEar.Add(new vec2(New.fenceLine[i].easting, New.fenceLine[i].northing)); + New.bndLineEar.Add(new vec2(New.bndLine[i].easting, New.bndLine[i].northing)); delta = 0; } } @@ -810,7 +810,7 @@ public void FileOpenField(string _openType) if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) { - plot.isHeadlandOn = true; + plot.isOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -819,7 +819,7 @@ public void FileOpenField(string _openType) } else { - plot.isHeadlandOn = false; + plot.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; @@ -1215,13 +1215,13 @@ public void FileSaveBoundary() writer.WriteLine(plot.plots[i].isDriveAround); //writer.WriteLine(bnd.bndArr[i].isOwnField); - writer.WriteLine(plot.plots[i].fenceLine.Count.ToString(CultureInfo.InvariantCulture)); - if (plot.plots[i].fenceLine.Count > 0) + writer.WriteLine(plot.plots[i].bndLine.Count.ToString(CultureInfo.InvariantCulture)); + if (plot.plots[i].bndLine.Count > 0) { - for (int j = 0; j < plot.plots[i].fenceLine.Count; j++) - writer.WriteLine(Math.Round(plot.plots[i].fenceLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].fenceLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].fenceLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < plot.plots[i].bndLine.Count; j++) + writer.WriteLine(Math.Round(plot.plots[i].bndLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].bndLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(plot.plots[i].bndLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); } } } @@ -1705,7 +1705,7 @@ public void FileSaveFieldKML() //coords kml.WriteStartElement("coordinates"); string bndPts = ""; - if (plot.plots[i].fenceLine.Count > 3) + if (plot.plots[i].bndLine.Count > 3) bndPts = GetBoundaryPointsLatLon(i); kml.WriteRaw(bndPts); kml.WriteEndElement(); // @@ -1949,12 +1949,12 @@ public string GetBoundaryPointsLatLon(int bndNum) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < plot.plots[bndNum].fenceLine.Count; i++) + for (int i = 0; i < plot.plots[bndNum].bndLine.Count; i++) { double lat = 0; double lon = 0; - pn.ConvertLocalToWGS84(plot.plots[bndNum].fenceLine[i].northing, plot.plots[bndNum].fenceLine[i].easting, out lat, out lon); + pn.ConvertLocalToWGS84(plot.plots[bndNum].bndLine[i].northing, plot.plots[bndNum].bndLine[i].easting, out lat, out lon); sb.Append(lon.ToString("N7", CultureInfo.InvariantCulture) + ',' + lat.ToString("N7", CultureInfo.InvariantCulture) + ",0 "); } From 85ed0e441a09d5658b57dc7012eb896b842a0c4d Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Tue, 26 Oct 2021 12:56:08 -0600 Subject: [PATCH 09/18] Revert "Change Boundary to Plot, Lines to Plots" This reverts commit 599ae1f1a4e811049cae90476800c1a9ec179146. --- SourceCode/GPS/AgOpenGPS.csproj | 26 ++--- SourceCode/GPS/Classes/CABCurve.cs | 10 +- SourceCode/GPS/Classes/CABLine.cs | 8 +- SourceCode/GPS/Classes/CBoundary.cs | 94 ++++++++++++++----- SourceCode/GPS/Classes/CBoundaryLines.cs | 31 ++++-- SourceCode/GPS/Classes/CContour.cs | 12 +-- SourceCode/GPS/Classes/CFieldData.cs | 8 +- SourceCode/GPS/Classes/CHead.cs | 23 +++-- SourceCode/GPS/Classes/CHeadLines.cs | 2 +- SourceCode/GPS/Classes/CPlot.cs | 35 ------- SourceCode/GPS/Classes/CPlots.cs | 30 ------ SourceCode/GPS/Classes/CTram.cs | 26 ++--- SourceCode/GPS/Classes/CTurn.cs | 90 +++++++++--------- SourceCode/GPS/Classes/CTurnLines.cs | 2 +- SourceCode/GPS/Classes/CVehicle.cs | 12 +-- SourceCode/GPS/Classes/CYouTurn.cs | 78 +++++++-------- SourceCode/GPS/Forms/Controls.Designer.cs | 24 ++--- SourceCode/GPS/Forms/FormBoundary.cs | 62 ++++++------ SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 62 ++++++------ SourceCode/GPS/Forms/FormFieldKML.cs | 16 ++-- SourceCode/GPS/Forms/FormGPS.cs | 8 +- SourceCode/GPS/Forms/FormHeadland.cs | 24 ++--- SourceCode/GPS/Forms/GUI.Designer.cs | 6 +- SourceCode/GPS/Forms/Guidance/FormABDraw.cs | 30 +++--- SourceCode/GPS/Forms/OpenGL.Designer.cs | 62 ++++++------ SourceCode/GPS/Forms/Pickers/FormTouchPick.cs | 2 +- SourceCode/GPS/Forms/Position.designer.cs | 42 ++++----- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 62 ++++++------ .../Forms/Settings/ConfigModule.Designer.cs | 2 +- 29 files changed, 438 insertions(+), 451 deletions(-) delete mode 100644 SourceCode/GPS/Classes/CPlot.cs delete mode 100644 SourceCode/GPS/Classes/CPlots.cs diff --git a/SourceCode/GPS/AgOpenGPS.csproj b/SourceCode/GPS/AgOpenGPS.csproj index e2584fa00..6038b0af3 100644 --- a/SourceCode/GPS/AgOpenGPS.csproj +++ b/SourceCode/GPS/AgOpenGPS.csproj @@ -113,34 +113,24 @@ - - CPlot.cs - - - CPlots.cs - - - + - - CPlots.cs - - - CPlot.cs - + + + @@ -150,12 +140,8 @@ - - CPlot.cs - - - CPlots.cs - + + Form diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index 3fb7ebcf5..94aa5c004 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -683,7 +683,7 @@ public void BuildTram() mf.tram.tramList?.Clear(); mf.tram.tramArr?.Clear(); - bool isBndExist = mf.plot.plots.Count != 0; + bool isBndExist = mf.bnd.bndArr.Count != 0; double pass = 0.5; @@ -735,7 +735,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) + if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } @@ -744,7 +744,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) + if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } @@ -816,7 +816,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) + if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } @@ -825,7 +825,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.plot.plots[0].IsPointInsideBoundaryEar(point)) + if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) { mf.tram.tramArr.Add(point); } diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index 7c3f8dff0..32896ffd2 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -452,7 +452,7 @@ public void BuildTram() mf.tram.tramArr?.Clear(); List tramRef = new List(); - bool isBndExist = mf.plot.plots.Count != 0; + bool isBndExist = mf.bnd.bndArr.Count != 0; double pass = 0.5; double hsin = Math.Sin(abHeading); @@ -495,7 +495,7 @@ public void BuildTram() if (isBndExist) { - if (mf.plot.plots[0].IsPointInsideBoundaryEar(P1)) + if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(P1)) { mf.tram.tramArr.Add(P1); } @@ -523,7 +523,7 @@ public void BuildTram() if (isBndExist) { - if (mf.plot.plots[0].IsPointInsideBoundaryEar(P1)) + if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(P1)) { mf.tram.tramArr.Add(P1); } @@ -538,7 +538,7 @@ public void BuildTram() tramRef?.Clear(); //outside tram - if (mf.plot.plots.Count == 0 || mf.tram.passes != 0) + if (mf.bnd.bndArr.Count == 0 || mf.tram.passes != 0) { //return; } diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index c19551b06..0a4e18dcf 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -4,13 +4,38 @@ namespace AgOpenGPS { - public partial class CPlot + public partial class CBoundary { + //copy of the mainform address + private readonly FormGPS mf; + + /// + /// array of boundaries + /// + /// + public List bndArr = new List(); public List bndBeingMadePts = new List(128); + private readonly double scanWidth, boxLength; + public double createBndOffset; public bool isBndBeingMade; + public bool isDrawRightSide = true, isOkToAddPoints = false; + //constructor + public CBoundary(FormGPS _f) + { + mf = _f; + boundarySelected = 0; + scanWidth = 1.0; + boxLength = 2000; + + turnSelected = 0; + + isOn = false; + isToolUp = true; + } + // the list of possible bounds points public List bndClosestList = new List(); @@ -27,13 +52,13 @@ public partial class CPlot public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) { //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (plots[0].IsPointInsideBoundaryArea(testPoint)) + if (bndArr[0].IsPointInsideBoundaryArea(testPoint)) { - for (int i = 1; i < plots.Count; i++) + for (int i = 1; i < bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (plots[i].isDriveThru) continue; - if (plots[i].IsPointInsideBoundaryArea(testPoint)) + if (bndArr[i].isDriveThru) continue; + if (bndArr[i].IsPointInsideBoundaryArea(testPoint)) { return false; } @@ -49,6 +74,31 @@ public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) { + //heading is based on ABLine, average Curve, and going same direction as AB or not + //Draw a bounding box to determine if points are in it + + //if (mf.yt.isYouTurnTriggered || mf.yt.isEnteringDriveThru || mf.yt.isExitingDriveThru) + //{ + // boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * -scanWidth); //subtract if positive + // boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * -scanWidth); + + // boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); + // boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); + + // boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); + // boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); + + // boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); + // boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); + + // boxA.easting -= (Math.Sin(headAB) * boxLength); + // boxA.northing -= (Math.Cos(headAB) * boxLength); + + // boxB.easting -= (Math.Sin(headAB) * boxLength); + // boxB.northing -= (Math.Cos(headAB) * boxLength); + //} + //else + { boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); @@ -68,30 +118,30 @@ public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) //determine if point is inside bounding box bndClosestList.Clear(); vec4 inBox; - for (int i = 0; i < plots.Count; i++) + for (int i = 0; i < bndArr.Count; i++) { //skip the drive thru - if (plots[i].isDriveThru) continue; + if (bndArr[i].isDriveThru) continue; - ptCount = plots[i].bndLine.Count; + ptCount = bndArr[i].bndLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (plots[i].bndLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (plots[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (bndArr[i].bndLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (bndArr[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (plots[i].bndLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (plots[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (bndArr[i].bndLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (bndArr[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (plots[i].bndLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (plots[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (bndArr[i].bndLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (bndArr[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (plots[i].bndLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (plots[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (bndArr[i].bndLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (bndArr[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = plots[i].bndLine[p].easting; - inBox.northing = plots[i].bndLine[p].northing; - inBox.heading = plots[i].bndLine[p].heading; + inBox.easting = bndArr[i].bndLine[p].easting; + inBox.northing = bndArr[i].bndLine[p].northing; + inBox.heading = bndArr[i].bndLine[p].heading; inBox.index = i; //which boundary/headland is it from @@ -129,9 +179,9 @@ public void DrawBoundaryLines() //draw the boundaries GL.Color3(0.75f, 0.5f, 0.250f); - for (int i = 0; i < plots.Count; i++) + for (int i = 0; i < bndArr.Count; i++) { - plots[i].DrawBoundaryLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); + bndArr[i].DrawBoundaryLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); } if (bndBeingMadePts.Count > 0) @@ -198,4 +248,4 @@ public void DrawClosestPoint() GL.End(); } } -} +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CBoundaryLines.cs b/SourceCode/GPS/Classes/CBoundaryLines.cs index 42f16d30b..38229fc9c 100644 --- a/SourceCode/GPS/Classes/CBoundaryLines.cs +++ b/SourceCode/GPS/Classes/CBoundaryLines.cs @@ -1,14 +1,31 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using OpenTK.Graphics.OpenGL; +using OpenTK.Graphics.OpenGL; using System; using System.Collections.Generic; namespace AgOpenGPS { - public partial class CPlots + public partial class CBoundaryLines { + //list of coordinates of boundary line + public List bndLine = new List(128); + public List bndLineEar = new List(128); + public List hdLine = new List(128); + public List turnLine = new List(128); + + //area variable + public double area; + + //boundary variables + public bool isDriveAround, isDriveThru; + + //constructor + public CBoundaryLines() + { + area = 0; + isDriveAround = false; + isDriveThru = false; + } + public void CalculateBoundaryHeadings() { //to calc heading based on next and previous points to give an average heading. @@ -179,7 +196,7 @@ public bool IsPointInsideBoundaryEar(vec3 testPoint) } return result; } - + public bool IsPointInsideBoundaryEar(vec2 testPoint) { bool result = false; @@ -260,4 +277,4 @@ public bool CalculateBoundaryArea(int idx) return isClockwise; } } -} +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index be15b4f9e..f14c244c6 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -924,7 +924,7 @@ public void StopContourLine(vec3 pivot) //build contours for boundaries public void BuildBoundaryContours(int pass, int spacingInt) { - if (mf.plot.plots.Count == 0) + if (mf.bnd.bndArr.Count == 0) { mf.TimedMessageBox(1500, "Boundary Contour Error", "No Boundaries Made"); return; @@ -950,10 +950,10 @@ public void BuildBoundaryContours(int pass, int spacingInt) //totalHeadWidth = (mf.tool.toolWidth - mf.tool.toolOverlap) * 0.5 + 0.2 + (mf.tool.toolWidth - mf.tool.toolOverlap); - for (int j = 0; j < mf.plot.plots.Count; j++) + for (int j = 0; j < mf.bnd.bndArr.Count; j++) { //count the points from the boundary - int ptCount = mf.plot.plots[j].bndLine.Count; + int ptCount = mf.bnd.bndArr[j].bndLine.Count; ptList = new List(128); stripList.Add(ptList); @@ -961,9 +961,9 @@ public void BuildBoundaryContours(int pass, int spacingInt) for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.plot.plots[j].bndLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.plot.plots[j].bndLine[i].heading) * totalHeadWidth); - point.northing = mf.plot.plots[j].bndLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.plot.plots[j].bndLine[i].heading) * totalHeadWidth); - point.heading = mf.plot.plots[j].bndLine[i].heading - Math.PI; + point.easting = mf.bnd.bndArr[j].bndLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.bnd.bndArr[j].bndLine[i].heading) * totalHeadWidth); + point.northing = mf.bnd.bndArr[j].bndLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.bnd.bndArr[j].bndLine[i].heading) * totalHeadWidth); + point.heading = mf.bnd.bndArr[j].bndLine[i].heading - Math.PI; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if inside actual field boundary diff --git a/SourceCode/GPS/Classes/CFieldData.cs b/SourceCode/GPS/Classes/CFieldData.cs index d76e520ce..aed0102cb 100644 --- a/SourceCode/GPS/Classes/CFieldData.cs +++ b/SourceCode/GPS/Classes/CFieldData.cs @@ -132,14 +132,14 @@ public CFieldData(FormGPS _f) public void UpdateFieldBoundaryGUIAreas() { - if (mf.plot.plots.Count > 0) + if (mf.bnd.bndArr.Count > 0) { - areaOuterBoundary = mf.plot.plots[0].area; + areaOuterBoundary = mf.bnd.bndArr[0].area; areaBoundaryOuterLessInner = areaOuterBoundary; - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndArr.Count; i++) { - areaBoundaryOuterLessInner -= mf.plot.plots[i].area; + areaBoundaryOuterLessInner -= mf.bnd.bndArr[i].area; } } else diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index ca3060637..4e7febefb 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -2,7 +2,7 @@ namespace AgOpenGPS { - public partial class CPlot + public partial class CBoundary { public bool isOn; public double leftToolDistance; @@ -37,7 +37,7 @@ public void SetHydPosition() public void WhereAreToolCorners() { - if (plots.Count > 0 && plots[0].hdLine.Count > 0) + if (bndArr.Count > 0 && bndArr[0].hdLine.Count > 0) { bool isLeftInWk, isRightInWk = true; @@ -48,8 +48,8 @@ public void WhereAreToolCorners() if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftInWk = plots[0].IsPointInHeadArea(mf.section[j].leftPoint); - isRightInWk = plots[0].IsPointInHeadArea(mf.section[j].rightPoint); + isLeftInWk = bndArr[0].IsPointInHeadArea(mf.section[j].leftPoint); + isRightInWk = bndArr[0].IsPointInHeadArea(mf.section[j].rightPoint); //save left side mf.tool.isLeftSideInHeadland = !isLeftInWk; @@ -62,7 +62,7 @@ public void WhereAreToolCorners() { //grab the right of previous section, its the left of this section isLeftInWk = isRightInWk; - isRightInWk = plots[0].IsPointInHeadArea(mf.section[j].rightPoint); + isRightInWk = bndArr[0].IsPointInHeadArea(mf.section[j].rightPoint); mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } @@ -84,7 +84,7 @@ public void WhereAreToolCorners() public void WhereAreToolLookOnPoints() { - if (plots.Count > 0 && plots[0].hdLine.Count > 0) + if (bndArr.Count > 0 && bndArr[0].hdLine.Count > 0) { vec3 toolFix = mf.toolPos; double sinAB = Math.Sin(toolFix.heading); @@ -128,11 +128,10 @@ public void WhereAreToolLookOnPoints() public void DrawHeadLines() { - for (int i = 0; i < plots.Count; i++) + for (int i = 0; i < bndArr.Count; i++) { - if (plots[i].hdLine.Count > 0) plots[i].DrawHeadLine(); + if (bndArr[i].hdLine.Count > 0) bndArr[i].DrawHeadLine(); } - //GL.LineWidth(4.0f); //GL.Color3(0.9219f, 0.2f, 0.970f); @@ -156,11 +155,11 @@ public void DrawHeadLines() public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add - if (plots.Count > 0 && plots[0].IsPointInHeadArea(pt)) + if (bndArr.Count > 0 && bndArr[0].IsPointInHeadArea(pt)) { - for (int b = 1; b < plots.Count; b++) + for (int b = 1; b < bndArr.Count; b++) { - if (plots[b].IsPointInHeadArea(pt)) + if (bndArr[b].IsPointInHeadArea(pt)) { //point is in an inner turn area but inside outer return false; diff --git a/SourceCode/GPS/Classes/CHeadLines.cs b/SourceCode/GPS/Classes/CHeadLines.cs index 1fc4ea59f..c933932a9 100644 --- a/SourceCode/GPS/Classes/CHeadLines.cs +++ b/SourceCode/GPS/Classes/CHeadLines.cs @@ -2,7 +2,7 @@ namespace AgOpenGPS { - public partial class CPlots + public partial class CBoundaryLines { public bool IsPointInHeadArea(vec2 testPoint) { diff --git a/SourceCode/GPS/Classes/CPlot.cs b/SourceCode/GPS/Classes/CPlot.cs deleted file mode 100644 index af734e7a7..000000000 --- a/SourceCode/GPS/Classes/CPlot.cs +++ /dev/null @@ -1,35 +0,0 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; - -namespace AgOpenGPS -{ - public partial class CPlot - { - //copy of the mainform address - private readonly FormGPS mf; - - /// - /// array of boundaries - /// - /// - public List plots = new List(); - - private readonly double scanWidth, boxLength; - - public bool isDrawRightSide = true, isOkToAddPoints = false; - //constructor - public CPlot(FormGPS _f) - { - mf = _f; - boundarySelected = 0; - scanWidth = 1.0; - boxLength = 2000; - - turnSelected = 0; - - isOn = false; - isToolUp = true; - } - } -} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CPlots.cs b/SourceCode/GPS/Classes/CPlots.cs deleted file mode 100644 index 879e18796..000000000 --- a/SourceCode/GPS/Classes/CPlots.cs +++ /dev/null @@ -1,30 +0,0 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; - -namespace AgOpenGPS -{ - public partial class CPlots - { - //list of coordinates of boundary line - public List bndLine = new List(128); - public List bndLineEar = new List(128); - public List hdLine = new List(128); - public List turnLine = new List(128); - - //area variable - public double area; - - //boundary variables - public bool isDriveAround, isDriveThru; - - //constructor - public CPlots() - { - area = 0; - isDriveAround = false; - isDriveThru = false; - } - - } -} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CTram.cs b/SourceCode/GPS/Classes/CTram.cs index 7b6455fa3..e1dfbe4de 100644 --- a/SourceCode/GPS/Classes/CTram.cs +++ b/SourceCode/GPS/Classes/CTram.cs @@ -84,7 +84,7 @@ public void DrawTram() public void BuildTramBnd() { - bool isBndExist = mf.plot.plots.Count != 0; + bool isBndExist = mf.bnd.bndArr.Count != 0; if (isBndExist) { @@ -101,7 +101,7 @@ public void BuildTramBnd() private void CreateBndInnerTramTrack() { //count the points from the boundary - int ptCount = mf.plot.plots[0].bndLine.Count; + int ptCount = mf.bnd.bndArr[0].bndLine.Count; tramBndInnerArr?.Clear(); //outside point @@ -113,18 +113,18 @@ private void CreateBndInnerTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.easting = mf.bnd.bndArr[0].bndLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); - pt3.northing = mf.plot.plots[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.northing = mf.bnd.bndArr[0].bndLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); + mf.bnd.bndArr[0].bndLine[j].northing, mf.bnd.bndArr[0].bndLine[j].easting); if (check < distSq) { Add = false; @@ -149,7 +149,7 @@ private void CreateBndInnerTramTrack() public void CreateBndOuterTramTrack() { //count the points from the boundary - int ptCount = mf.plot.plots[0].bndLine.Count; + int ptCount = mf.bnd.bndArr[0].bndLine.Count; tramBndOuterArr?.Clear(); //outside point @@ -161,18 +161,18 @@ public void CreateBndOuterTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.easting = mf.bnd.bndArr[0].bndLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); - pt3.northing = mf.plot.plots[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.northing = mf.bnd.bndArr[0].bndLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); + mf.bnd.bndArr[0].bndLine[j].northing, mf.bnd.bndArr[0].bndLine[j].easting); if (check < distSq) { Add = false; diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index 30bdda5ea..d6fdec0d7 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -4,7 +4,7 @@ namespace AgOpenGPS { - public partial class CPlot + public partial class CBoundary { // the list of possible bounds points public List turnClosestList = new List(); @@ -31,13 +31,13 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (plots[0].IsPointInTurnWorkArea(pt)) + if (bndArr[0].IsPointInTurnWorkArea(pt)) { - for (int t = 1; t < plots.Count; t++) + for (int t = 1; t < bndArr.Count; t++) { - if (plots[t].isDriveThru) continue; - if (plots[t].isDriveAround) continue; - if (plots[t].IsPointInTurnWorkArea(pt)) + if (bndArr[t].isDriveThru) continue; + if (bndArr[t].isDriveAround) continue; + if (bndArr[t].IsPointInTurnWorkArea(pt)) { isFound = true; closestTurnNum = t; @@ -88,25 +88,25 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB vec4 inBox; - int ptCount = plots[closestTurnNum].turnLine.Count; + int ptCount = bndArr[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (plots[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (plots[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (plots[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (plots[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (plots[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (plots[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (plots[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (plots[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = plots[closestTurnNum].turnLine[p].easting; - inBox.northing = plots[closestTurnNum].turnLine[p].northing; - inBox.heading = plots[closestTurnNum].turnLine[p].heading; + inBox.easting = bndArr[closestTurnNum].turnLine[p].easting; + inBox.northing = bndArr[closestTurnNum].turnLine[p].northing; + inBox.heading = bndArr[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -142,26 +142,26 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB //determine if point is inside bounding box of the 1 turn chosen above turnClosestList.Clear(); - ptCount = plots[closestTurnNum].turnLine.Count; + ptCount = bndArr[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (plots[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (plots[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (plots[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (plots[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (plots[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (plots[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (plots[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (plots[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = plots[closestTurnNum].turnLine[p].easting; - inBox.northing = plots[closestTurnNum].turnLine[p].northing; - inBox.heading = plots[closestTurnNum].turnLine[p].heading; + inBox.easting = bndArr[closestTurnNum].turnLine[p].easting; + inBox.northing = bndArr[closestTurnNum].turnLine[p].northing; + inBox.heading = bndArr[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -203,7 +203,7 @@ public void BuildTurnLines() //update the GUI values for boundaries mf.fd.UpdateFieldBoundaryGUIAreas(); - if (plots.Count == 0) + if (bndArr.Count == 0) { //mf.TimedMessageBox(1500, " No Boundaries", "No Turn Lines Made"); return; @@ -216,29 +216,29 @@ public void BuildTurnLines() double totalHeadWidth = mf.yt.uturnDistanceFromBoundary; //inside boundaries - for (int j = 0; j < plots.Count; j++) + for (int j = 0; j < bndArr.Count; j++) { - plots[j].turnLine.Clear(); - if (plots[j].isDriveThru || plots[j].isDriveAround) continue; + bndArr[j].turnLine.Clear(); + if (bndArr[j].isDriveThru || bndArr[j].isDriveAround) continue; - int ptCount = plots[j].bndLine.Count; + int ptCount = bndArr[j].bndLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point outside the boundary - point.easting = plots[j].bndLine[i].easting + (-Math.Sin(glm.PIBy2 + plots[j].bndLine[i].heading) * totalHeadWidth); - point.northing = plots[j].bndLine[i].northing + (-Math.Cos(glm.PIBy2 + plots[j].bndLine[i].heading) * totalHeadWidth); - point.heading = plots[j].bndLine[i].heading; + point.easting = bndArr[j].bndLine[i].easting + (-Math.Sin(glm.PIBy2 + bndArr[j].bndLine[i].heading) * totalHeadWidth); + point.northing = bndArr[j].bndLine[i].northing + (-Math.Cos(glm.PIBy2 + bndArr[j].bndLine[i].heading) * totalHeadWidth); + point.heading = bndArr[j].bndLine[i].heading; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == plots[j].IsPointInsideBoundaryEar(point)) + if (j == 0 == bndArr[j].IsPointInsideBoundaryEar(point)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); - plots[j].turnLine.Add(tPnt); + bndArr[j].turnLine.Add(tPnt); } } - plots[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); + bndArr[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); } } @@ -248,17 +248,17 @@ public void DrawTurnLines() GL.Color3(0.3555f, 0.6232f, 0.20f); //GL.PointSize(2); - for (int i = 0; i < plots.Count; i++) + for (int i = 0; i < bndArr.Count; i++) { - if (plots[i].isDriveAround) continue; + if (bndArr[i].isDriveAround) continue; //turnArr[i].DrawTurnLine(); { ////draw the turn line oject - int ptCount = plots[i].turnLine.Count; + int ptCount = bndArr[i].turnLine.Count; if (ptCount < 1) continue; GL.Begin(PrimitiveType.LineLoop); - for (int h = 0; h < ptCount; h++) GL.Vertex3(plots[i].turnLine[h].easting, plots[i].turnLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(bndArr[i].turnLine[h].easting, bndArr[i].turnLine[h].northing, 0); GL.End(); } } diff --git a/SourceCode/GPS/Classes/CTurnLines.cs b/SourceCode/GPS/Classes/CTurnLines.cs index db8e8cf07..8b37faa76 100644 --- a/SourceCode/GPS/Classes/CTurnLines.cs +++ b/SourceCode/GPS/Classes/CTurnLines.cs @@ -3,7 +3,7 @@ namespace AgOpenGPS { - public partial class CPlots + public partial class CBoundaryLines { public void CalculateTurnHeadings() { diff --git a/SourceCode/GPS/Classes/CVehicle.cs b/SourceCode/GPS/Classes/CVehicle.cs index e2076105b..977b12296 100644 --- a/SourceCode/GPS/Classes/CVehicle.cs +++ b/SourceCode/GPS/Classes/CVehicle.cs @@ -408,9 +408,9 @@ public void DrawVehicle() GL.End(); } - if (mf.plot.isBndBeingMade) + if (mf.bnd.isBndBeingMade) { - if (mf.plot.isDrawRightSide) + if (mf.bnd.isDrawRightSide) { GL.LineWidth(2); GL.Color3(0.0, 1.270, 0.0); @@ -418,8 +418,8 @@ public void DrawVehicle() { GL.Vertex3(0.0, 0, 0); GL.Color3(1.270, 1.220, 0.20); - GL.Vertex3(mf.plot.createBndOffset, 0, 0); - GL.Vertex3(mf.plot.createBndOffset * 0.75, 0.25, 0); + GL.Vertex3(mf.bnd.createBndOffset, 0, 0); + GL.Vertex3(mf.bnd.createBndOffset * 0.75, 0.25, 0); } GL.End(); } @@ -433,8 +433,8 @@ public void DrawVehicle() { GL.Vertex3(0.0, 0, 0); GL.Color3(1.270, 1.220, 0.20); - GL.Vertex3(-mf.plot.createBndOffset, 0, 0); - GL.Vertex3(-mf.plot.createBndOffset * 0.75, 0.25, 0); + GL.Vertex3(-mf.bnd.createBndOffset, 0, 0); + GL.Vertex3(-mf.bnd.createBndOffset * 0.75, 0.25, 0); } GL.End(); } diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index 4e7b9b385..b6a82524e 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -115,7 +115,7 @@ public bool FindCurveTurnPoints() //for each point in succession keep going till a turnLine is found. for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) { - if (!mf.plot.plots[0].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(mf.curve.curList[j])) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -125,12 +125,12 @@ public bool FindCurveTurnPoints() goto CrossingFound; } - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.plot.plots[i].isDriveThru) continue; - if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (mf.bnd.bndArr[i].isDriveThru) continue; + if (mf.bnd.bndArr[i].isDriveAround) continue; + if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(mf.curve.curList[j])) { crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -152,7 +152,7 @@ public bool FindCurveTurnPoints() for (int j = mf.curve.currentLocationIndex; j > 0; j--) { - if (!mf.plot.plots[0].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(mf.curve.curList[j])) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; @@ -162,12 +162,12 @@ public bool FindCurveTurnPoints() goto CrossingFound; } - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.plot.plots[i].isDriveThru) continue; - if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (mf.bnd.bndArr[i].isDriveThru) continue; + if (mf.bnd.bndArr[i].isDriveAround) continue; + if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(mf.curve.curList[j])) { crossingCurvePoint.easting = mf.curve.curList[j].easting; crossingCurvePoint.northing = mf.curve.curList[j].northing; @@ -191,17 +191,17 @@ public bool FindCurveTurnPoints() return false; } - int curTurnLineCount = mf.plot.plots[turnNum].turnLine.Count; + int curTurnLineCount = mf.bnd.bndArr[turnNum].turnLine.Count; //possible points close to AB Curve point List turnLineCloseList = new List(); for (int j = 0; j < curTurnLineCount; j++) { - if ((mf.plot.plots[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 - && (mf.plot.plots[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 - && (mf.plot.plots[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 - && (mf.plot.plots[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) + if ((mf.bnd.bndArr[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 + && (mf.bnd.bndArr[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 + && (mf.bnd.bndArr[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 + && (mf.bnd.bndArr[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) { turnLineCloseList.Add(j); } @@ -211,8 +211,8 @@ public bool FindCurveTurnPoints() curTurnLineCount = turnLineCloseList.Count; for (int i = 0; i < curTurnLineCount; i++) { - dist1 = glm.Distance(mf.plot.plots[turnNum].turnLine[turnLineCloseList[i]].easting, - mf.plot.plots[turnNum].turnLine[turnLineCloseList[i]].northing, + dist1 = glm.Distance(mf.bnd.bndArr[turnNum].turnLine[turnLineCloseList[i]].easting, + mf.bnd.bndArr[turnNum].turnLine[turnLineCloseList[i]].northing, crossingCurvePoint.easting, crossingCurvePoint.northing); if (dist1 < dist2) { @@ -222,9 +222,9 @@ public bool FindCurveTurnPoints() } //fill up the coords - crossingTurnLinePoint.easting = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].easting; - crossingTurnLinePoint.northing = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].northing; - crossingTurnLinePoint.heading = mf.plot.plots[turnNum].turnLine[crossingTurnLinePoint.index].heading; + crossingTurnLinePoint.easting = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].easting; + crossingTurnLinePoint.northing = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].northing; + crossingTurnLinePoint.heading = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].heading; return crossingCurvePoint.easting != -20000 && crossingCurvePoint.easting != -20000; } @@ -387,12 +387,12 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) vec3 onPurePoint = new vec3(mf.ABLine.rEastAB, mf.ABLine.rNorthAB, 0); //how far are we from any turn boundary - mf.plot.FindClosestTurnPoint(isYouTurnRight, onPurePoint, headAB); + mf.bnd.FindClosestTurnPoint(isYouTurnRight, onPurePoint, headAB); //or did we lose the turnLine - we are on the highway cuz we left the outer/inner turn boundary - if ((int)mf.plot.closestTurnPt.easting != -20000) + if ((int)mf.bnd.closestTurnPt.easting != -20000) { - mf.distancePivotToTurnLine = glm.Distance(mf.pivotAxlePos, mf.plot.closestTurnPt); + mf.distancePivotToTurnLine = glm.Distance(mf.pivotAxlePos, mf.bnd.closestTurnPt); } else { @@ -401,7 +401,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) } //delta between AB heading and boundary closest point heading - boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(mf.plot.closestTurnPt.heading - headAB) - Math.PI); + boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(mf.bnd.closestTurnPt.heading - headAB) - Math.PI); boundaryAngleOffPerpendicular -= glm.PIBy2; boundaryAngleOffPerpendicular *= -1; if (boundaryAngleOffPerpendicular > 1.25) boundaryAngleOffPerpendicular = 1.25; @@ -584,15 +584,15 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; + if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; if (isOutOfBounds) break; - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.plot.plots[i].isDriveThru) continue; - if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.bnd.bndArr[i].isDriveThru) continue; + if (mf.bnd.bndArr[i].isDriveAround) continue; + if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; @@ -644,16 +644,16 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; + if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; if (isOutOfBounds) break; - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.plot.plots[i].isDriveThru) continue; - if (mf.plot.plots[i].isDriveAround) continue; - if (!mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.bnd.bndArr[i].isDriveThru) continue; + if (mf.bnd.bndArr[i].isDriveAround) continue; + if (!mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; @@ -852,18 +852,18 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!mf.plot.plots[0].IsPointInTurnWorkArea(ytList[j])) + if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; } - for (int i = 1; i < mf.plot.plots.Count; i++) + for (int i = 1; i < mf.bnd.bndArr.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.plot.plots[i].isDriveThru) continue; - if (mf.plot.plots[i].isDriveAround) continue; - if (mf.plot.plots[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.bnd.bndArr[i].isDriveThru) continue; + if (mf.bnd.bndArr[i].isDriveAround) continue; + if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) { isOutOfBounds = true; break; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index 0055a0d97..a609102c7 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -355,7 +355,7 @@ private void btnAutoYouTurn_Click(object sender, EventArgs e) { yt.isTurnCreationTooClose = false; - if (plot.plots.Count == 0) + if (bnd.bndArr.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1494,7 +1494,7 @@ private void BtnMakeLinesFromBoundary_Click(object sender, EventArgs e) return; } - if (plot.plots.Count == 0) + if (bnd.bndArr.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1549,10 +1549,10 @@ private void cboxpRowWidth_SelectedIndexChanged(object sender, EventArgs e) private void btnHeadlandOnOff_Click(object sender, EventArgs e) { - if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) + if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) { - plot.isOn = !plot.isOn; - if (plot.isOn) + bnd.isOn = !bnd.isOn; + if (bnd.isOn) { btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHydLift.Visible = true; @@ -1563,9 +1563,9 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; } } - else plot.isOn = false; + else bnd.isOn = false; - if (!plot.isOn) + if (!bnd.isOn) { p_239.pgn[p_239.hydLift] = 0; vehicle.isHydLiftOn = false; @@ -1577,7 +1577,7 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) private void btnHydLift_Click(object sender, EventArgs e) { - if (plot.isOn) + if (bnd.isOn) { vehicle.isHydLiftOn = !vehicle.isHydLiftOn; if (vehicle.isHydLiftOn) @@ -1959,7 +1959,7 @@ private void tramLinesMenuField_Click(object sender, EventArgs e) } private void headlandToolStripMenuItem_Click(object sender, EventArgs e) { - if (plot.plots.Count == 0) + if (bnd.bndArr.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1974,9 +1974,9 @@ public void GetHeadland() form.ShowDialog(); } - if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) + if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) { - plot.isOn = true; + bnd.isOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -1984,7 +1984,7 @@ public void GetHeadland() } else { - plot.isOn = false; + bnd.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index 8721b187b..6121798e0 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -59,7 +59,7 @@ private void UpdateChart() Font backupfont = new Font(Font.FontFamily, 18F, FontStyle.Bold); - for (int i = 0; i < mf.plot.plots.Count && i < 6; i++) + for (int i = 0; i < mf.bnd.bndArr.Count && i < 6; i++) { //outer inner Button a = new Button @@ -118,11 +118,11 @@ private void UpdateChart() if (i == 0) { //cc.Text = "Outer"; - mf.plot.plots[i].isDriveThru = false; - mf.plot.plots[i].isDriveAround = false; + mf.bnd.bndArr[i].isDriveThru = false; + mf.bnd.bndArr[i].isDriveAround = false; a.Text = string.Format(gStr.gsOuter); //a.Font = backupfont; - d.Text = mf.plot.plots[i].isDriveThru ? "--" : "--"; + d.Text = mf.bnd.bndArr[i].isDriveThru ? "--" : "--"; d.Enabled = false; d.Anchor = System.Windows.Forms.AnchorStyles.None; a.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -135,7 +135,7 @@ private void UpdateChart() inner += 1; a.Text = string.Format(gStr.gsInner + " {0}", inner); //a.Font = backupfont; - d.Text = mf.plot.plots[i].isDriveThru ? "Yes" : "No"; + d.Text = mf.bnd.bndArr[i].isDriveThru ? "Yes" : "No"; d.Anchor = System.Windows.Forms.AnchorStyles.None; a.Anchor = System.Windows.Forms.AnchorStyles.None; b.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -144,14 +144,14 @@ private void UpdateChart() if (mf.isMetric) { - b.Text = Math.Round(mf.plot.plots[i].area * 0.0001, 2).ToString() + " Ha"; + b.Text = Math.Round(mf.bnd.bndArr[i].area * 0.0001, 2).ToString() + " Ha"; } else { - b.Text = Math.Round(mf.plot.plots[i].area * 0.000247105, 2) + " Ac"; + b.Text = Math.Round(mf.bnd.bndArr[i].area * 0.000247105, 2) + " Ac"; } - if (Selectedreset == false && i == mf.plot.boundarySelected) + if (Selectedreset == false && i == mf.bnd.boundarySelected) { a.ForeColor = Color.OrangeRed; b.ForeColor = Color.OrangeRed; @@ -168,9 +168,9 @@ private void DriveThru_Click(object sender, EventArgs e) { if (sender is Button b) { - mf.plot.plots[Convert.ToInt32(b.Name)].isDriveThru = !mf.plot.plots[Convert.ToInt32(b.Name)].isDriveThru; + mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveThru = !mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveThru; UpdateChart(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); } } @@ -178,7 +178,7 @@ private void DriveAround_Click(object sender, EventArgs e) { if (sender is Button b) { - mf.plot.plots[Convert.ToInt32(b.Name)].isDriveAround = !mf.plot.plots[Convert.ToInt32(b.Name)].isDriveAround; + mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveAround = !mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveAround; UpdateChart(); } } @@ -188,16 +188,16 @@ private void B_Click(object sender, EventArgs e) if (sender is Button b) { - mf.plot.boundarySelected = Convert.ToInt32(b.Name); + mf.bnd.boundarySelected = Convert.ToInt32(b.Name); - if (mf.plot.boundarySelected == 0 && mf.plot.plots.Count > 1) + if (mf.bnd.boundarySelected == 0 && mf.bnd.bndArr.Count > 1) { return; } Selectedreset = false; - if (mf.plot.plots.Count > mf.plot.boundarySelected) + if (mf.bnd.bndArr.Count > mf.bnd.boundarySelected) { btnDelete.Enabled = true; } @@ -213,7 +213,7 @@ private void B_Click(object sender, EventArgs e) private void btnSerialCancel_Click(object sender, EventArgs e) { - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; } private void btnDelete_Click(object sender, EventArgs e) @@ -229,17 +229,17 @@ private void btnDelete_Click(object sender, EventArgs e) btnDelete.Enabled = false; - if (mf.plot.plots.Count > mf.plot.boundarySelected) + if (mf.bnd.bndArr.Count > mf.bnd.boundarySelected) { - mf.plot.plots.RemoveAt(mf.plot.boundarySelected); + mf.bnd.bndArr.RemoveAt(mf.bnd.boundarySelected); } mf.FileSaveBoundary(); - mf.plot.boundarySelected = -1; + mf.bnd.boundarySelected = -1; Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); UpdateChart(); } else @@ -250,13 +250,13 @@ private void btnDelete_Click(object sender, EventArgs e) private void ResetAllBoundary() { - mf.plot.plots.Clear(); + mf.bnd.bndArr.Clear(); mf.FileSaveBoundary(); tableLayoutPanel1.Controls.Clear(); tableLayoutPanel1.RowStyles.Clear(); UpdateChart(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); btnDelete.Enabled = false; } @@ -282,10 +282,10 @@ private void btnDeleteAll_Click(object sender, EventArgs e) ResetAllBoundary(); - mf.plot.boundarySelected = -1; + mf.bnd.boundarySelected = -1; Selectedreset = true; - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; mf.fd.UpdateFieldBoundaryGUIAreas(); } else @@ -297,7 +297,7 @@ private void btnDeleteAll_Click(object sender, EventArgs e) private void btnReturn_Click(object sender, EventArgs e) { - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; panelMain.Visible = true; panelChoose.Visible = false; @@ -310,7 +310,7 @@ private void btnReturn_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e) { - mf.plot.boundarySelected = mf.plot.plots.Count; + mf.bnd.boundarySelected = mf.bnd.bndArr.Count; Selectedreset = false; @@ -353,7 +353,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) { if (button.Name == "btnLoadMultiBoundaryFromGE") ResetAllBoundary(); - else i = mf.plot.boundarySelected; + else i = mf.bnd.boundarySelected; try { @@ -394,7 +394,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) //at least 3 points if (numberSets.Length > 2) { - CPlots New = new CPlots(); + CBoundaryLines New = new CBoundaryLines(); foreach (string item in numberSets) { @@ -408,10 +408,10 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) New.bndLine.Add(new vec3(easting, norting, 0)); } - New.CalculateBoundaryArea(mf.plot.boundarySelected); + New.CalculateBoundaryArea(mf.bnd.boundarySelected); New.FixBoundaryLine(i); - mf.plot.plots.Add(New); + mf.bnd.bndArr.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); @@ -431,7 +431,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) } } mf.FileSaveBoundary(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); mf.btnMakeLinesFromBoundary.Visible = true; mf.fd.UpdateFieldBoundaryGUIAreas(); UpdateChart(); @@ -442,7 +442,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) } } } - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; panelMain.Visible = true; panelChoose.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 2d8a3f2a0..3be336c6b 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -27,34 +27,34 @@ public FormBoundaryPlayer(Form callingForm) private void btnStop_Click(object sender, EventArgs e) { - if (mf.plot.bndBeingMadePts.Count > 2) + if (mf.bnd.bndBeingMadePts.Count > 2) { - CPlots New = new CPlots(); + CBoundaryLines New = new CBoundaryLines(); - for (int i = 0; i < mf.plot.bndBeingMadePts.Count; i++) + for (int i = 0; i < mf.bnd.bndBeingMadePts.Count; i++) { - New.bndLine.Add(mf.plot.bndBeingMadePts[i]); + New.bndLine.Add(mf.bnd.bndBeingMadePts[i]); } - New.CalculateBoundaryArea(mf.plot.boundarySelected); - New.FixBoundaryLine(mf.plot.boundarySelected); + New.CalculateBoundaryArea(mf.bnd.boundarySelected); + New.FixBoundaryLine(mf.bnd.boundarySelected); - mf.plot.plots.Add(New); + mf.bnd.bndArr.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); } //stop it all for adding - mf.plot.isOkToAddPoints = false; - mf.plot.isBndBeingMade = false; + mf.bnd.isOkToAddPoints = false; + mf.bnd.isBndBeingMade = false; //turn lines made from boundaries mf.CalculateMinMax(); mf.FileSaveBoundary(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); //mf.hd.BuildSingleSpaceHeadLines(); mf.btnMakeLinesFromBoundary.Visible = true; - mf.plot.bndBeingMadePts.Clear(); + mf.bnd.bndBeingMadePts.Clear(); //close window Close(); } @@ -62,9 +62,9 @@ private void btnStop_Click(object sender, EventArgs e) //actually the record button private void btnPausePlay_Click(object sender, EventArgs e) { - if (mf.plot.isOkToAddPoints) + if (mf.bnd.isOkToAddPoints) { - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; btnPausePlay.Image = Properties.Resources.BoundaryRecord; //btnPausePlay.Text = gStr.gsRecord; btnAddPoint.Enabled = true; @@ -72,7 +72,7 @@ private void btnPausePlay_Click(object sender, EventArgs e) } else { - mf.plot.isOkToAddPoints = true; + mf.bnd.isOkToAddPoints = true; btnPausePlay.Image = Properties.Resources.boundaryPause; //btnPausePlay.Text = gStr.gsPause; btnAddPoint.Enabled = false; @@ -86,15 +86,15 @@ private void FormBoundaryPlayer_Load(object sender, EventArgs e) //mf.bnd.isOkToAddPoints = false; nudOffset.Value = (decimal)(mf.tool.toolWidth * 0.5); btnPausePlay.Image = Properties.Resources.BoundaryRecord; - btnLeftRight.Image = mf.plot.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; - mf.plot.createBndOffset = (double)nudOffset.Value; - mf.plot.isBndBeingMade = true; + btnLeftRight.Image = mf.bnd.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; + mf.bnd.createBndOffset = (double)nudOffset.Value; + mf.bnd.isBndBeingMade = true; mf.Focus(); } private void timer1_Tick(object sender, EventArgs e) { - int ptCount = mf.plot.bndBeingMadePts.Count; + int ptCount = mf.bnd.bndBeingMadePts.Count; double area = 0; if (ptCount > 0) @@ -103,7 +103,7 @@ private void timer1_Tick(object sender, EventArgs e) for (int i = 0; i < ptCount; j = i++) { - area += (mf.plot.bndBeingMadePts[j].easting + mf.plot.bndBeingMadePts[i].easting) * (mf.plot.bndBeingMadePts[j].northing - mf.plot.bndBeingMadePts[i].northing); + area += (mf.bnd.bndBeingMadePts[j].easting + mf.bnd.bndBeingMadePts[i].easting) * (mf.bnd.bndBeingMadePts[j].northing - mf.bnd.bndBeingMadePts[i].northing); } area = Math.Abs(area / 2); } @@ -115,27 +115,27 @@ private void timer1_Tick(object sender, EventArgs e) { lblArea.Text = Math.Round(area * 0.000247105, 2) + " Acre"; } - lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); + lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); } private void btnAddPoint_Click(object sender, EventArgs e) { - mf.plot.isOkToAddPoints = true; + mf.bnd.isOkToAddPoints = true; mf.AddBoundaryPoint(); - mf.plot.isOkToAddPoints = false; - lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); + mf.bnd.isOkToAddPoints = false; + lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); mf.Focus(); } private void btnDeleteLast_Click(object sender, EventArgs e) { - int ptCount = mf.plot.bndBeingMadePts.Count; + int ptCount = mf.bnd.bndBeingMadePts.Count; if (ptCount > 0) - mf.plot.bndBeingMadePts.RemoveAt(ptCount - 1); - lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); + mf.bnd.bndBeingMadePts.RemoveAt(ptCount - 1); + lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); mf.Focus(); } @@ -148,8 +148,8 @@ private void btnRestart_Click(object sender, EventArgs e) MessageBoxDefaultButton.Button2); if (result3 == DialogResult.Yes) { - mf.plot.bndBeingMadePts?.Clear(); - lblPoints.Text = mf.plot.bndBeingMadePts.Count.ToString(); + mf.bnd.bndBeingMadePts?.Clear(); + lblPoints.Text = mf.bnd.bndBeingMadePts.Count.ToString(); } mf.Focus(); } @@ -158,13 +158,13 @@ private void nudOffset_Click(object sender, EventArgs e) { mf.KeypadToNUD((NumericUpDown)sender, this); btnPausePlay.Focus(); - mf.plot.createBndOffset = (double)nudOffset.Value; + mf.bnd.createBndOffset = (double)nudOffset.Value; } private void btnLeftRight_Click(object sender, EventArgs e) { - mf.plot.isDrawRightSide = !mf.plot.isDrawRightSide; - btnLeftRight.Image = mf.plot.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; + mf.bnd.isDrawRightSide = !mf.bnd.isDrawRightSide; + btnLeftRight.Image = mf.bnd.isDrawRightSide ? Properties.Resources.BoundaryRight : Properties.Resources.BoundaryLeft; } } } \ No newline at end of file diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 034d3e748..53cce9638 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -125,7 +125,7 @@ private void LoadKMLBoundary(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.plot.boundarySelected; + i = mf.bnd.boundarySelected; try { @@ -166,7 +166,7 @@ private void LoadKMLBoundary(string filename) //at least 3 points if (numberSets.Length > 2) { - CPlots New = new CPlots(); + CBoundaryLines New = new CBoundaryLines(); foreach (string item in numberSets) { @@ -183,10 +183,10 @@ private void LoadKMLBoundary(string filename) } //build the boundary, make sure is clockwise for outer counter clockwise for inner - New.CalculateBoundaryArea(mf.plot.boundarySelected); + New.CalculateBoundaryArea(mf.bnd.boundarySelected); New.FixBoundaryLine(i); - mf.plot.plots.Add(New); + mf.bnd.bndArr.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); @@ -206,7 +206,7 @@ private void LoadKMLBoundary(string filename) } } mf.FileSaveBoundary(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); mf.fd.UpdateFieldBoundaryGUIAreas(); mf.CalculateMinMax(); @@ -221,7 +221,7 @@ private void LoadKMLBoundary(string filename) } } - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; } private void FindLatLon(string filename) @@ -233,7 +233,7 @@ private void FindLatLon(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.plot.boundarySelected; + i = mf.bnd.boundarySelected; try { @@ -312,7 +312,7 @@ private void FindLatLon(string filename) } } - mf.plot.isOkToAddPoints = false; + mf.bnd.isOkToAddPoints = false; } diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index d4d2c5a57..142809b11 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -187,7 +187,7 @@ public partial class FormGPS : Form /// /// The boundary object /// - public CPlot plot; + public CBoundary bnd; /// /// The internal simulator @@ -366,7 +366,7 @@ public FormGPS() mc = new CModuleComm(); //boundary object - plot = new CPlot(this); + bnd = new CBoundary(this); //nmea simulator built in. sim = new CSim(this); @@ -979,7 +979,7 @@ public void JobClose() pn.fixOffset.northing = 0; //turn off headland - plot.isOn = false; + bnd.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; @@ -993,7 +993,7 @@ public void JobClose() oglZoom.SendToBack(); //clean all the lines - plot.plots.Clear(); + bnd.bndArr.Clear(); panelRight.Enabled = false; FieldMenuButtonEnableDisable(false); diff --git a/SourceCode/GPS/Forms/FormHeadland.cs b/SourceCode/GPS/Forms/FormHeadland.cs index 9091c6a0a..d4bc8e0dc 100644 --- a/SourceCode/GPS/Forms/FormHeadland.cs +++ b/SourceCode/GPS/Forms/FormHeadland.cs @@ -54,10 +54,10 @@ private void FormHeadland_Load(object sender, EventArgs e) nudDistance.Value = 0; nudSetDistance.Value = 0; - if (mf.plot.plots[0].hdLine.Count > 0) + if (mf.bnd.bndArr[0].hdLine.Count > 0) { - hdArr = new vec3[mf.plot.plots[0].hdLine.Count]; - mf.plot.plots[0].hdLine.CopyTo(hdArr); + hdArr = new vec3[mf.bnd.bndArr[0].hdLine.Count]; + mf.bnd.bndArr[0].hdLine.CopyTo(hdArr); RebuildHeadLineTemplate(); } else @@ -80,13 +80,13 @@ public void BuildHeadLineTemplateFromBoundary() //outside boundary - count the points from the boundary headLineTemplate.Clear(); - int ptCount = mf.plot.plots[0].bndLine.Count; + int ptCount = mf.bnd.bndArr[0].bndLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.plot.plots[0].bndLine[i].easting; - point.northing = mf.plot.plots[0].bndLine[i].northing; - point.heading = mf.plot.plots[0].bndLine[i].heading; + point.easting = mf.bnd.bndArr[0].bndLine[i].easting; + point.northing = mf.bnd.bndArr[0].bndLine[i].northing; + point.heading = mf.bnd.bndArr[0].bndLine[i].heading; headLineTemplate.Add(point); } @@ -334,7 +334,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) //else lblEnd.Text = end.ToString(); //draw all the boundaries - mf.plot.DrawBoundaryLines(); + mf.bnd.DrawBoundaryLines(); int ptCount = hdArr.Length; if (ptCount > 1) @@ -565,7 +565,7 @@ private void timer1_Tick(object sender, EventArgs e) private void btnExit_Click(object sender, EventArgs e) { - mf.plot.plots[0].hdLine?.Clear(); + mf.bnd.bndArr[0].hdLine?.Clear(); //middle points for (int i = 1; i < hdArr.Length; i++) @@ -580,7 +580,7 @@ private void btnExit_Click(object sender, EventArgs e) { if (i == 0) { - mf.plot.plots[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); + mf.bnd.bndArr[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); continue; } delta += (hdArr[i - 1].heading - hdArr[i].heading); @@ -589,7 +589,7 @@ private void btnExit_Click(object sender, EventArgs e) { vec3 pt = new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading); - mf.plot.plots[0].hdLine.Add(pt); + mf.bnd.bndArr[0].hdLine.Add(pt); delta = 0; } } @@ -600,7 +600,7 @@ private void btnExit_Click(object sender, EventArgs e) private void btnTurnOffHeadland_Click(object sender, EventArgs e) { - mf.plot.plots[0].hdLine?.Clear(); + mf.bnd.bndArr[0].hdLine?.Clear(); mf.FileSaveHeadland(); diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 66dab5db2..10bc6cb2f 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -125,7 +125,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) // fd.WorkedAreaRemainPercentage +"\r\n" + // fd.TimeTillFinished + "\r\n" + // fd.WorkRateHectares; - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) lblFieldStatus.Text = fd.AreaBoundaryLessInnersHectares + " " + fd.WorkedAreaRemainHectares + " " + fd.TimeTillFinished + " " + fd.WorkedAreaRemainPercentage+" " @@ -136,7 +136,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) } else //imperial { - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) lblFieldStatus.Text = fd.AreaBoundaryLessInnersAcres + " " + fd.WorkedAreaRemainAcres + " " + fd.TimeTillFinished + " " + fd.WorkedAreaRemainPercentage + " " + fd.WorkedAcres; @@ -498,7 +498,7 @@ public void LoadSettings() if (Properties.Settings.Default.setAS_isAutoSteerAutoOn) btnAutoSteer.Text = "R"; else btnAutoSteer.Text = "M"; - if (plot.isOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; + if (bnd.isOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; else btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnChangeMappingColor.BackColor = sectionColorDay; diff --git a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs index b19add630..fc1e2270b 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs @@ -46,21 +46,21 @@ public FormABDraw(Form callingForm) private void FormABDraw_Load(object sender, EventArgs e) { - int cnt = mf.plot.plots[0].bndLine.Count; + int cnt = mf.bnd.bndArr[0].bndLine.Count; arr = new vec3[cnt * 2]; for (int i = 0; i < cnt; i++) { - arr[i].easting = mf.plot.plots[0].bndLine[i].easting; - arr[i].northing = mf.plot.plots[0].bndLine[i].northing; - arr[i].heading = mf.plot.plots[0].bndLine[i].heading; + arr[i].easting = mf.bnd.bndArr[0].bndLine[i].easting; + arr[i].northing = mf.bnd.bndArr[0].bndLine[i].northing; + arr[i].heading = mf.bnd.bndArr[0].bndLine[i].heading; } for (int i = cnt; i < cnt * 2; i++) { - arr[i].easting = mf.plot.plots[0].bndLine[i - cnt].easting; - arr[i].northing = mf.plot.plots[0].bndLine[i - cnt].northing; - arr[i].heading = mf.plot.plots[0].bndLine[i - cnt].heading; + arr[i].easting = mf.bnd.bndArr[0].bndLine[i - cnt].easting; + arr[i].northing = mf.bnd.bndArr[0].bndLine[i - cnt].northing; + arr[i].heading = mf.bnd.bndArr[0].bndLine[i - cnt].heading; } nudDistance.Value = (decimal)Math.Round(((mf.tool.toolWidth * mf.m2InchOrCm) * 0.5), 0); // @@ -356,7 +356,7 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) { //count the points from the boundary - int ptCount = mf.plot.plots[0].bndLine.Count; + int ptCount = mf.bnd.bndArr[0].bndLine.Count; mf.curve.refList?.Clear(); //outside point @@ -369,20 +369,20 @@ private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.plot.plots[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (moveDist)); + pt3.easting = mf.bnd.bndArr[0].bndLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (moveDist)); - pt3.northing = mf.plot.plots[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.plot.plots[0].bndLine[i].heading) * (moveDist)); + pt3.northing = mf.bnd.bndArr[0].bndLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (moveDist)); - pt3.heading = mf.plot.plots[0].bndLine[i].heading; + pt3.heading = mf.bnd.bndArr[0].bndLine[i].heading; bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.plot.plots[0].bndLine[j].northing, mf.plot.plots[0].bndLine[j].easting); + mf.bnd.bndArr[0].bndLine[j].northing, mf.bnd.bndArr[0].bndLine[j].easting); if (check < distSq) { Add = false; @@ -669,7 +669,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.plot.DrawBoundaryLines(); + mf.bnd.DrawBoundaryLines(); //the vehicle GL.PointSize(16.0f); diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index c763d943b..e9d953000 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -338,21 +338,21 @@ private void oglMain_Paint(object sender, PaintEventArgs e) recPath.DrawDubins(); //draw Boundaries - plot.DrawBoundaryLines(); + bnd.DrawBoundaryLines(); //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) { - plot.DrawTurnLines(); + bnd.DrawTurnLines(); } - if (plot.isOn) + if (bnd.isOn) { GL.LineWidth(ABLine.lineWidth); GL.Color3(0.960f, 0.96232f, 0.30f); - for (int i = 0; i < plot.plots.Count; i++) + for (int i = 0; i < bnd.bndArr.Count; i++) { - if (plot.plots[i].hdLine.Count > 0) plot.plots[i].DrawHeadLine(); + if (bnd.bndArr[i].hdLine.Count > 0) bnd.bndArr[i].DrawHeadLine(); } } @@ -416,7 +416,7 @@ private void oglMain_Paint(object sender, PaintEventArgs e) if ((ahrs.imuRoll != 88888)) DrawRollBar(); - if (plot.plots.Count > 0 && yt.isYouTurnBtnOn) DrawUTurnBtn(); + if (bnd.bndArr.Count > 0 && yt.isYouTurnBtnOn) DrawUTurnBtn(); if (isAutoSteerBtnOn && !ct.isContourBtnOn) DrawManUTurnBtn(); @@ -616,29 +616,29 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //draw 240 green for boundary - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) { ////draw the bnd line - int ptCount = plot.plots[0].bndLine.Count; + int ptCount = bnd.bndArr[0].bndLine.Count; if (ptCount > 3) { GL.LineWidth(3); GL.Color3((byte)0, (byte)240, (byte)0); GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < ptCount; h++) GL.Vertex3(plot.plots[0].bndLine[h].easting, plot.plots[0].bndLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(bnd.bndArr[0].bndLine[h].easting, bnd.bndArr[0].bndLine[h].northing, 0); GL.End(); } } //draw 250 green for the headland - if (plot.isOn) + if (bnd.isOn) { GL.LineWidth(3); GL.Color3((byte)0, (byte)250, (byte)0); - for (int i = 0; i < plot.plots.Count; i++) + for (int i = 0; i < bnd.bndArr.Count; i++) { - if (plot.plots[i].hdLine.Count > 0) plot.plots[i].DrawHeadLineBackBuffer(); + if (bnd.bndArr[i].hdLine.Count > 0) bnd.bndArr[i].DrawHeadLineBackBuffer(); } } @@ -677,7 +677,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tool.numOfSections == 1 || pn.speed < vehicle.slowSpeedCutoff) tool.isSuperSectionAllowedOn = false; - if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && plot.isOn) + if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && bnd.isOn) tool.isSuperSectionAllowedOn = false; //clamp the height after looking way ahead, this is for switching off super section only @@ -687,7 +687,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //10 % min is required for overlap, otherwise it never would be on. int pixLimit = (int)((double)(section[0].rpSectionWidth * rpOnHeight) / (double)(5.0)); - if ((rpOnHeight < rpToolHeight && plot.isOn)) rpHeight = rpToolHeight + 2; + if ((rpOnHeight < rpToolHeight && bnd.isOn)) rpHeight = rpToolHeight + 2; else rpHeight = rpOnHeight + 2; if (rpHeight > 290) rpHeight = 290; @@ -712,7 +712,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (!tool.isMultiColoredSections) { - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) { //are there enough pixels in buffer array to warrant turning off supersection for (int a = 0; a < (tool.rpWidth * rpOnHeight); a++) @@ -749,7 +749,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //determine if in or out of headland, do hydraulics if on - if (plot.isOn) + if (bnd.isOn) { //calculate the slope double m = (vehicle.hydLiftLookAheadDistanceRight - vehicle.hydLiftLookAheadDistanceLeft) / tool.rpWidth; @@ -770,12 +770,12 @@ private void oglBack_Paint(object sender, PaintEventArgs e) GetOutTool: //is the tool completely in the headland or not - plot.isToolInHeadland = plot.isToolOuterPointsInHeadland && !isHeadlandClose; + bnd.isToolInHeadland = bnd.isToolOuterPointsInHeadland && !isHeadlandClose; - if (isHeadlandClose || plot.isToolInHeadland) tool.isSuperSectionAllowedOn = false; + if (isHeadlandClose || bnd.isToolInHeadland) tool.isSuperSectionAllowedOn = false; //set hydraulics based on tool in headland or not - plot.SetHydPosition(); + bnd.SetHydPosition(); } } else //supersection check by applied only @@ -923,7 +923,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tagged == 0) section[j].isMappingRequiredOn = false; } - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) { //if out of boundary, turn it off if (!section[j].isInBoundary) @@ -935,7 +935,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) section[j].mappingOnTimer = 0; } - else if (section[j].isInHeadlandArea & plot.isOn) + else if (section[j].isInHeadlandArea & bnd.isOn) { // if headland is on and out, turn off section[j].isMappingRequiredOn = false; @@ -950,7 +950,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) /////////////////////////////////////////// Section control ssssssssssssssssssssss /// - if (plot.isOn) plot.WhereAreToolLookOnPoints(); + if (bnd.isOn) bnd.WhereAreToolLookOnPoints(); for (int j = 0; j < tool.numOfSections; j++) { @@ -958,7 +958,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //ensure it starts off section[j].isSectionRequiredOn = false; - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) { //if out of boundary, turn it off if (!section[j].isInBoundary) @@ -1013,7 +1013,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //is headland coming up - if (plot.isOn) + if (bnd.isOn) { bool isHeadlandInLookOn = false; @@ -1502,7 +1502,7 @@ private void oglZoom_Paint(object sender, PaintEventArgs e) } //draw all the boundaries - plot.DrawBoundaryLines(); + bnd.DrawBoundaryLines(); GL.PointSize(8.0f); GL.Begin(PrimitiveType.Points); @@ -2385,13 +2385,13 @@ public void CalculateMinMax() //min max of the boundary //min max of the boundary - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) { - int bndCnt = plot.plots[0].bndLine.Count; + int bndCnt = bnd.bndArr[0].bndLine.Count; for (int i = 0; i < bndCnt; i++) { - double x = plot.plots[0].bndLine[i].easting; - double y = plot.plots[0].bndLine[i].northing; + double x = bnd.bndArr[0].bndLine[i].easting; + double y = bnd.bndArr[0].bndLine[i].northing; //also tally the max/min of field x and z if (minFieldX > x) minFieldX = x; @@ -2481,7 +2481,7 @@ private void DrawFieldText() { if (isMetric) { - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) { sb.Clear(); sb.Append(((fd.workedAreaTotal - fd.actualAreaCovered) * glm.m2ha).ToString("N3")); @@ -2512,7 +2512,7 @@ private void DrawFieldText() } else { - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) { sb.Clear(); sb.Append(((fd.workedAreaTotal - fd.actualAreaCovered) * glm.m2ac).ToString("N3")); diff --git a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs index 19a0032aa..cd7e1b6fb 100644 --- a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs +++ b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs @@ -122,7 +122,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.plot.DrawBoundaryLines(); + mf.bnd.DrawBoundaryLines(); GL.Flush(); oglSelf.SwapBuffers(); diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index a0c7c217d..b0f06a281 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -707,10 +707,10 @@ public void UpdateFixPosition() mc.isOutOfBounds = true; //if an outer boundary is set, then apply critical stop logic - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (plot.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (bnd.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; @@ -822,7 +822,7 @@ private void TheRest() } //test if travelled far enough for new boundary point - if (plot.isOkToAddPoints) + if (bnd.isOkToAddPoints) { double boundaryDistance = glm.Distance(pn.fix, prevBoundaryPos); if (boundaryDistance > 1) AddBoundaryPoint(); @@ -982,16 +982,16 @@ public void AddBoundaryPoint() //build the boundary line - if (plot.isOkToAddPoints) + if (bnd.isOkToAddPoints) { - if (plot.isDrawRightSide) + if (bnd.isDrawRightSide) { //Right side vec3 point = new vec3( - pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * -plot.createBndOffset), - pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * -plot.createBndOffset), + pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * -bnd.createBndOffset), + pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * -bnd.createBndOffset), pivotAxlePos.heading); - plot.bndBeingMadePts.Add(point); + bnd.bndBeingMadePts.Add(point); } //draw on left side @@ -999,10 +999,10 @@ public void AddBoundaryPoint() { //Right side vec3 point = new vec3( - pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * plot.createBndOffset), - pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * plot.createBndOffset), + pivotAxlePos.easting + (Math.Sin(pivotAxlePos.heading - glm.PIBy2) * bnd.createBndOffset), + pivotAxlePos.northing + (Math.Cos(pivotAxlePos.heading - glm.PIBy2) * bnd.createBndOffset), pivotAxlePos.heading); - plot.bndBeingMadePts.Add(point); + bnd.bndBeingMadePts.Add(point); } } } @@ -1238,7 +1238,7 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (tool.lookAheadDistanceOffPixelsRight > 160) tool.lookAheadDistanceOffPixelsRight = 160; //determine where the tool is wrt to headland - if (plot.isOn) plot.WhereAreToolCorners(); + if (bnd.isOn) bnd.WhereAreToolCorners(); //set up the super for youturn section[tool.numOfSections].isInBoundary = true; @@ -1248,19 +1248,19 @@ public void CalculateSectionLookAhead(double northing, double easting, double co for (int j = 0; j < tool.numOfSections; j++) { - if (plot.plots.Count > 0) + if (bnd.bndArr.Count > 0) { if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].leftPoint); - isRightIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].rightPoint); + isLeftIn = bnd.bndArr[0].IsPointInsideBoundaryEar(section[j].leftPoint); + isRightIn = bnd.bndArr[0].IsPointInsideBoundaryEar(section[j].rightPoint); - for (int i = 1; i < plot.plots.Count; i++) + for (int i = 1; i < bnd.bndArr.Count; i++) { //inner boundaries should normally NOT have point inside - isLeftIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].leftPoint); - isRightIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].rightPoint); + isLeftIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].leftPoint); + isRightIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].rightPoint); } //merge the two sides into in or out @@ -1272,11 +1272,11 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { //grab the right of previous section, its the left of this section isLeftIn = isRightIn; - isRightIn = plot.plots[0].IsPointInsideBoundaryEar(section[j].rightPoint); - for (int i = 1; i < plot.plots.Count; i++) + isRightIn = bnd.bndArr[0].IsPointInsideBoundaryEar(section[j].rightPoint); + for (int i = 1; i < bnd.bndArr.Count; i++) { //inner boundaries should normally NOT have point inside - isRightIn &= !plot.plots[i].IsPointInsideBoundaryEar(section[j].rightPoint); + isRightIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].rightPoint); } if (isLeftIn && isRightIn) section[j].isInBoundary = true; diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index df00849ed..5e0892f09 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -683,7 +683,7 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - CPlots New = new CPlots(); + CBoundaryLines New = new CBoundaryLines(); //True or False OR points from older boundary files line = reader.ReadLine(); @@ -739,13 +739,13 @@ public void FileOpenField(string _openType) } } - plot.plots.Add(New); + bnd.bndArr.Add(New); } } CalculateMinMax(); - plot.BuildTurnLines(); - if (plot.plots.Count > 0) btnMakeLinesFromBoundary.Visible = true; + bnd.BuildTurnLines(); + if (bnd.bndArr.Count > 0) btnMakeLinesFromBoundary.Visible = true; } catch (Exception e) @@ -773,9 +773,9 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - if (plot.plots.Count > k) + if (bnd.bndArr.Count > k) { - plot.plots[k].hdLine.Clear(); + bnd.bndArr[k].hdLine.Clear(); //read the number of points line = reader.ReadLine(); @@ -792,7 +792,7 @@ public void FileOpenField(string _openType) double.Parse(words[0], CultureInfo.InvariantCulture), double.Parse(words[1], CultureInfo.InvariantCulture), double.Parse(words[2], CultureInfo.InvariantCulture)); - plot.plots[k].hdLine.Add(vecPt); + bnd.bndArr[k].hdLine.Add(vecPt); } } } @@ -808,9 +808,9 @@ public void FileOpenField(string _openType) } } - if (plot.plots.Count > 0 && plot.plots[0].hdLine.Count > 0) + if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) { - plot.isOn = true; + bnd.isOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -819,7 +819,7 @@ public void FileOpenField(string _openType) } else { - plot.isOn = false; + bnd.isOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; @@ -1209,19 +1209,19 @@ public void FileSaveBoundary() using (StreamWriter writer = new StreamWriter(dirField + "Boundary.Txt")) { writer.WriteLine("$Boundary"); - for (int i = 0; i < plot.plots.Count; i++) + for (int i = 0; i < bnd.bndArr.Count; i++) { - writer.WriteLine(plot.plots[i].isDriveThru); - writer.WriteLine(plot.plots[i].isDriveAround); + writer.WriteLine(bnd.bndArr[i].isDriveThru); + writer.WriteLine(bnd.bndArr[i].isDriveAround); //writer.WriteLine(bnd.bndArr[i].isOwnField); - writer.WriteLine(plot.plots[i].bndLine.Count.ToString(CultureInfo.InvariantCulture)); - if (plot.plots[i].bndLine.Count > 0) + writer.WriteLine(bnd.bndArr[i].bndLine.Count.ToString(CultureInfo.InvariantCulture)); + if (bnd.bndArr[i].bndLine.Count > 0) { - for (int j = 0; j < plot.plots[i].bndLine.Count; j++) - writer.WriteLine(Math.Round(plot.plots[i].bndLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].bndLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].bndLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < bnd.bndArr[i].bndLine.Count; j++) + writer.WriteLine(Math.Round(bnd.bndArr[i].bndLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndArr[i].bndLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndArr[i].bndLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); } } } @@ -1295,17 +1295,17 @@ public void FileSaveHeadland() { writer.WriteLine("$Headland"); - if (plot.plots[0].hdLine.Count > 0) + if (bnd.bndArr[0].hdLine.Count > 0) { - for (int i = 0; i < plot.plots.Count; i++) + for (int i = 0; i < bnd.bndArr.Count; i++) { - writer.WriteLine(plot.plots[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); - if (plot.plots[0].hdLine.Count > 0) + writer.WriteLine(bnd.bndArr[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); + if (bnd.bndArr[0].hdLine.Count > 0) { - for (int j = 0; j < plot.plots[i].hdLine.Count; j++) - writer.WriteLine(Math.Round(plot.plots[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(plot.plots[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < bnd.bndArr[i].hdLine.Count; j++) + writer.WriteLine(Math.Round(bnd.bndArr[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndArr[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndArr[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); } } } @@ -1678,7 +1678,7 @@ public void FileSaveFieldKML() kml.WriteStartElement("Folder"); kml.WriteElementString("name", "Boundaries"); - for (int i = 0; i < plot.plots.Count; i++) + for (int i = 0; i < bnd.bndArr.Count; i++) { kml.WriteStartElement("Placemark"); if (i == 0) kml.WriteElementString("name", currentFieldDirectory); @@ -1705,7 +1705,7 @@ public void FileSaveFieldKML() //coords kml.WriteStartElement("coordinates"); string bndPts = ""; - if (plot.plots[i].bndLine.Count > 3) + if (bnd.bndArr[i].bndLine.Count > 3) bndPts = GetBoundaryPointsLatLon(i); kml.WriteRaw(bndPts); kml.WriteEndElement(); // @@ -1949,12 +1949,12 @@ public string GetBoundaryPointsLatLon(int bndNum) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < plot.plots[bndNum].bndLine.Count; i++) + for (int i = 0; i < bnd.bndArr[bndNum].bndLine.Count; i++) { double lat = 0; double lon = 0; - pn.ConvertLocalToWGS84(plot.plots[bndNum].bndLine[i].northing, plot.plots[bndNum].bndLine[i].easting, out lat, out lon); + pn.ConvertLocalToWGS84(bnd.bndArr[bndNum].bndLine[i].northing, bnd.bndArr[bndNum].bndLine[i].easting, out lat, out lon); sb.Append(lon.ToString("N7", CultureInfo.InvariantCulture) + ',' + lat.ToString("N7", CultureInfo.InvariantCulture) + ",0 "); } diff --git a/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs b/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs index a898ef27d..5286675aa 100644 --- a/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs +++ b/SourceCode/GPS/Forms/Settings/ConfigModule.Designer.cs @@ -401,7 +401,7 @@ private void tabUTurn_Leave(object sender, EventArgs e) Properties.Settings.Default.Save(); Properties.Vehicle.Default.Save(); - mf.plot.BuildTurnLines(); + mf.bnd.BuildTurnLines(); mf.yt.ResetCreatedYouTurn(); } From 375ed7abca596a04a9b202383fcbbe41f106787f Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Tue, 26 Oct 2021 21:50:23 -0600 Subject: [PATCH 10/18] Fixed [t] bug, all changes back --- SourceCode/AgIO/Source/AgIO.csproj | 1 + SourceCode/GPS/AgOpenGPS.csproj | 26 +- SourceCode/GPS/Classes/CABCurve.cs | 54 +--- SourceCode/GPS/Classes/CABLine.cs | 8 +- SourceCode/GPS/Classes/CBoundary.cs | 232 +-------------- SourceCode/GPS/Classes/CBoundaryLines.cs | 280 ------------------ SourceCode/GPS/Classes/CBoundaryList.cs | 106 +++++++ SourceCode/GPS/Classes/CContour.cs | 14 +- SourceCode/GPS/Classes/CFence.cs | 181 +++++++++++ SourceCode/GPS/Classes/CFenceLine.cs | 213 +++++++++++++ SourceCode/GPS/Classes/CFieldData.cs | 8 +- SourceCode/GPS/Classes/CHead.cs | 46 +-- SourceCode/GPS/Classes/CHeadLines.cs | 37 +-- SourceCode/GPS/Classes/CTram.cs | 26 +- SourceCode/GPS/Classes/CTurn.cs | 95 +++--- SourceCode/GPS/Classes/CTurnLines.cs | 23 +- SourceCode/GPS/Classes/CYouTurn.cs | 70 ++--- SourceCode/GPS/Forms/Controls.Designer.cs | 24 +- SourceCode/GPS/Forms/FormBoundary.cs | 50 ++-- SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 10 +- SourceCode/GPS/Forms/FormFieldKML.cs | 14 +- SourceCode/GPS/Forms/FormGPS.cs | 4 +- SourceCode/GPS/Forms/FormHeadland.cs | 24 +- SourceCode/GPS/Forms/GUI.Designer.cs | 6 +- SourceCode/GPS/Forms/Guidance/FormABDraw.cs | 30 +- .../GPS/Forms/Guidance/FormMakeBndCon.cs | 2 +- SourceCode/GPS/Forms/OpenGL.Designer.cs | 54 ++-- SourceCode/GPS/Forms/Pickers/FormTouchPick.cs | 2 +- SourceCode/GPS/Forms/Position.designer.cs | 24 +- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 74 ++--- 30 files changed, 816 insertions(+), 922 deletions(-) delete mode 100644 SourceCode/GPS/Classes/CBoundaryLines.cs create mode 100644 SourceCode/GPS/Classes/CBoundaryList.cs create mode 100644 SourceCode/GPS/Classes/CFence.cs create mode 100644 SourceCode/GPS/Classes/CFenceLine.cs diff --git a/SourceCode/AgIO/Source/AgIO.csproj b/SourceCode/AgIO/Source/AgIO.csproj index acf311cc4..01e53c1d7 100644 --- a/SourceCode/AgIO/Source/AgIO.csproj +++ b/SourceCode/AgIO/Source/AgIO.csproj @@ -166,6 +166,7 @@ FormGPSData.cs + Designer FormKeyboard.cs diff --git a/SourceCode/GPS/AgOpenGPS.csproj b/SourceCode/GPS/AgOpenGPS.csproj index 6038b0af3..2b1114007 100644 --- a/SourceCode/GPS/AgOpenGPS.csproj +++ b/SourceCode/GPS/AgOpenGPS.csproj @@ -113,24 +113,34 @@ + + CBoundary.cs + + + CBoundaryList.cs + + - + - - + + CBoundaryList.cs + + + CBoundary.cs + - @@ -140,8 +150,12 @@ - - + + CBoundary.cs + + + CBoundaryList.cs + Form diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index 94aa5c004..7cb578218 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -683,7 +683,7 @@ public void BuildTram() mf.tram.tramList?.Clear(); mf.tram.tramArr?.Clear(); - bool isBndExist = mf.bnd.bndArr.Count != 0; + bool isBndExist = mf.bnd.bndList.Count != 0; double pass = 0.5; @@ -735,7 +735,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) + if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar )) { mf.tram.tramArr.Add(point); } @@ -744,7 +744,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) + if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -816,7 +816,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) + if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -825,7 +825,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(point)) + if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -1033,48 +1033,4 @@ public class CCurveLines } -//for (int i = 1; i <= mf.tram.passes; i++) -//{ -// tramArr = new List(); -// tramList.Add(tramArr); - -// List tramTemp = new List(); - -// for (int j = 0; j < tramRef.Count; j++) -// { -// P1.easting = (hsin * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].easting; -// P1.northing = (hcos * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].northing; - -// if (isBndExist) -// { -// if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(P1)) -// { -// tramTemp.Add(P1); -// P1.easting = (hsin * mf.vehicle.trackWidth) + P1.easting; -// P1.northing = (hcos * mf.vehicle.trackWidth) + P1.northing; -// tramTemp.Add(P1); -// } -// } -// else -// { -// tramTemp.Add(P1); - -// P1.easting = (hsin * mf.vehicle.trackWidth) + P1.easting; -// P1.northing = (hcos * mf.vehicle.trackWidth) + P1.northing; -// tramTemp.Add(P1); -// } - -// if (tramTemp.Count > 6) -// { -// vec2[] array = new vec2[tramTemp.Count]; -// tramTemp.CopyTo(array); - -// tramArr.Add(array[0]); -// tramArr.Add(array[1]); -// tramArr.Add(array[tramTemp.Count - 2]); -// tramArr.Add(array[tramTemp.Count - 1]); -// } - -// } -//} diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index 32896ffd2..1b86caec5 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -452,7 +452,7 @@ public void BuildTram() mf.tram.tramArr?.Clear(); List tramRef = new List(); - bool isBndExist = mf.bnd.bndArr.Count != 0; + bool isBndExist = mf.bnd.bndList.Count != 0; double pass = 0.5; double hsin = Math.Sin(abHeading); @@ -495,7 +495,7 @@ public void BuildTram() if (isBndExist) { - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(P1)) + if (mf.bnd.bndList[0].IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(P1); } @@ -523,7 +523,7 @@ public void BuildTram() if (isBndExist) { - if (mf.bnd.bndArr[0].IsPointInsideBoundaryEar(P1)) + if (mf.bnd.bndList[0].IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(P1); } @@ -538,7 +538,7 @@ public void BuildTram() tramRef?.Clear(); //outside tram - if (mf.bnd.bndArr.Count == 0 || mf.tram.passes != 0) + if (mf.bnd.bndList.Count == 0 || mf.tram.passes != 0) { //return; } diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index 0a4e18dcf..7a67962d7 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -9,243 +9,17 @@ public partial class CBoundary //copy of the mainform address private readonly FormGPS mf; - /// - /// array of boundaries - /// - /// - public List bndArr = new List(); - public List bndBeingMadePts = new List(128); + public List bndList = new List(); - private readonly double scanWidth, boxLength; - - public double createBndOffset; - public bool isBndBeingMade; - - public bool isDrawRightSide = true, isOkToAddPoints = false; //constructor public CBoundary(FormGPS _f) { mf = _f; - boundarySelected = 0; - scanWidth = 1.0; + fenceSelected = 0; boxLength = 2000; - turnSelected = 0; - - isOn = false; + isHeadlandOn = false; isToolUp = true; } - - // the list of possible bounds points - public List bndClosestList = new List(); - - public int boundarySelected, closestBoundaryNum; - - //generated box for finding closest point - public vec2 boxA = new vec2(9000, 9000), boxB = new vec2(9000, 9002); - - public vec2 boxC = new vec2(9001, 9001), boxD = new vec2(9002, 9003); - - //point at the farthest boundary segment from pivotAxle - public vec3 closestBoundaryPt = new vec3(-10000, -10000, 9); - - public bool IsInsideGeoFenceAKABoundary(vec3 testPoint) - { - //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (bndArr[0].IsPointInsideBoundaryArea(testPoint)) - { - for (int i = 1; i < bndArr.Count; i++) - { - //make sure not inside a non drivethru boundary - if (bndArr[i].isDriveThru) continue; - if (bndArr[i].IsPointInsideBoundaryArea(testPoint)) - { - return false; - } - } - } - else - { - return false; - } - //we are safely inside outer, outside inner boundaries - return true; - } - - public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) - { - //heading is based on ABLine, average Curve, and going same direction as AB or not - //Draw a bounding box to determine if points are in it - - //if (mf.yt.isYouTurnTriggered || mf.yt.isEnteringDriveThru || mf.yt.isExitingDriveThru) - //{ - // boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * -scanWidth); //subtract if positive - // boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * -scanWidth); - - // boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); - // boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); - - // boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); - // boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); - - // boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); - // boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); - - // boxA.easting -= (Math.Sin(headAB) * boxLength); - // boxA.northing -= (Math.Cos(headAB) * boxLength); - - // boxB.easting -= (Math.Sin(headAB) * boxLength); - // boxB.northing -= (Math.Cos(headAB) * boxLength); - //} - //else - - { - boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); - boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); - - boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); - boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); - - boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); - boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); - - boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); - boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); - } - - int ptCount; - - //determine if point is inside bounding box - bndClosestList.Clear(); - vec4 inBox; - for (int i = 0; i < bndArr.Count; i++) - { - //skip the drive thru - if (bndArr[i].isDriveThru) continue; - - ptCount = bndArr[i].bndLine.Count; - for (int p = 0; p < ptCount; p++) - { - if ((((boxB.easting - boxA.easting) * (bndArr[i].bndLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (bndArr[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } - - if ((((boxD.easting - boxC.easting) * (bndArr[i].bndLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (bndArr[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } - - if ((((boxC.easting - boxB.easting) * (bndArr[i].bndLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (bndArr[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } - - if ((((boxA.easting - boxD.easting) * (bndArr[i].bndLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (bndArr[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } - - //it's in the box, so add to list - inBox.easting = bndArr[i].bndLine[p].easting; - inBox.northing = bndArr[i].bndLine[p].northing; - inBox.heading = bndArr[i].bndLine[p].heading; - inBox.index = i; - - //which boundary/headland is it from - bndClosestList.Add(inBox); - } - } - - //which of the points is closest - closestBoundaryPt.easting = -20000; closestBoundaryPt.northing = -20000; - ptCount = bndClosestList.Count; - if (ptCount != 0) - { - //determine closest point - double minDistance = 9999999; - for (int i = 0; i < ptCount; i++) - { - double dist = ((fromPt.easting - bndClosestList[i].easting) * (fromPt.easting - bndClosestList[i].easting)) - + ((fromPt.northing - bndClosestList[i].northing) * (fromPt.northing - bndClosestList[i].northing)); - if (minDistance >= dist) - { - minDistance = dist; - - closestBoundaryPt.easting = bndClosestList[i].easting; - closestBoundaryPt.northing = bndClosestList[i].northing; - closestBoundaryPt.heading = bndClosestList[i].heading; - closestBoundaryNum = bndClosestList[i].index; - } - } - if (closestBoundaryPt.heading < 0) closestBoundaryPt.heading += glm.twoPI; - } - } - - public void DrawBoundaryLines() - { - //draw the boundaries - GL.Color3(0.75f, 0.5f, 0.250f); - - for (int i = 0; i < bndArr.Count; i++) - { - bndArr[i].DrawBoundaryLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); - } - - if (bndBeingMadePts.Count > 0) - { - //the boundary so far - vec3 pivot = mf.pivotAxlePos; - GL.LineWidth(mf.ABLine.lineWidth); - GL.Color3(0.825f, 0.22f, 0.90f); - GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); - GL.Color3(0.295f, 0.972f, 0.290f); - GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - GL.End(); - - //line from last point to pivot marker - GL.Color3(0.825f, 0.842f, 0.0f); - GL.Enable(EnableCap.LineStipple); - GL.LineStipple(1, 0x0700); - GL.Begin(PrimitiveType.LineStrip); - if (isDrawRightSide) - { - GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - - GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * -createBndOffset), - pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * -createBndOffset), 0); - GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); - } - else - { - GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); - - GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * createBndOffset), - pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * createBndOffset), 0); - GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); - } - GL.End(); - GL.Disable(EnableCap.LineStipple); - - //boundary points - GL.Color3(0.0f, 0.95f, 0.95f); - GL.PointSize(6.0f); - GL.Begin(PrimitiveType.Points); - for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); - GL.End(); - } - } - - //draws the derived closest point - public void DrawClosestPoint() - { - GL.PointSize(4.0f); - GL.Color3(0.919f, 0.932f, 0.070f); - GL.Begin(PrimitiveType.Points); - GL.Vertex3(closestBoundaryPt.easting, closestBoundaryPt.northing, 0); - GL.End(); - - GL.LineWidth(1); - GL.Color3(0.92f, 0.62f, 0.42f); - GL.Begin(PrimitiveType.LineStrip); - GL.Vertex3(boxD.easting, boxD.northing, 0); - GL.Vertex3(boxA.easting, boxA.northing, 0); - GL.Vertex3(boxB.easting, boxB.northing, 0); - GL.Vertex3(boxC.easting, boxC.northing, 0); - GL.End(); - } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CBoundaryLines.cs b/SourceCode/GPS/Classes/CBoundaryLines.cs deleted file mode 100644 index 38229fc9c..000000000 --- a/SourceCode/GPS/Classes/CBoundaryLines.cs +++ /dev/null @@ -1,280 +0,0 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; - -namespace AgOpenGPS -{ - public partial class CBoundaryLines - { - //list of coordinates of boundary line - public List bndLine = new List(128); - public List bndLineEar = new List(128); - public List hdLine = new List(128); - public List turnLine = new List(128); - - //area variable - public double area; - - //boundary variables - public bool isDriveAround, isDriveThru; - - //constructor - public CBoundaryLines() - { - area = 0; - isDriveAround = false; - isDriveThru = false; - } - - public void CalculateBoundaryHeadings() - { - //to calc heading based on next and previous points to give an average heading. - int cnt = bndLine.Count; - vec3[] arr = new vec3[cnt]; - cnt--; - bndLine.CopyTo(arr); - bndLine.Clear(); - - //first point needs last, first, second points - vec3 pt3 = arr[0]; - pt3.heading = Math.Atan2(arr[1].easting - arr[cnt].easting, arr[1].northing - arr[cnt].northing); - if (pt3.heading < 0) pt3.heading += glm.twoPI; - bndLine.Add(pt3); - - //middle points - for (int i = 1; i < cnt; i++) - { - pt3 = arr[i]; - pt3.heading = Math.Atan2(arr[i + 1].easting - arr[i - 1].easting, arr[i + 1].northing - arr[i - 1].northing); - if (pt3.heading < 0) pt3.heading += glm.twoPI; - bndLine.Add(pt3); - } - - //last and first point - pt3 = arr[cnt]; - pt3.heading = Math.Atan2(arr[0].easting - arr[cnt - 1].easting, arr[0].northing - arr[cnt - 1].northing); - if (pt3.heading < 0) pt3.heading += glm.twoPI; - bndLine.Add(pt3); - } - - public void FixBoundaryLine(int bndNum) - { - double spacing; - //boundary point spacing based on eq width - //close if less then 30 ha, 60ha, more then 60 - if (area < 200000) spacing = 1.1; - else if (area < 400000) spacing = 2.2; - else spacing = 3.3; - - if (bndNum > 0) spacing *= 0.5; - - int bndCount = bndLine.Count; - double distance; - - //make sure distance isn't too big between points on boundary - for (int i = 0; i < bndCount; i++) - { - int j = i + 1; - - if (j == bndCount) j = 0; - distance = glm.Distance(bndLine[i], bndLine[j]); - if (distance > spacing * 1.5) - { - vec3 pointB = new vec3((bndLine[i].easting + bndLine[j].easting) / 2.0, - (bndLine[i].northing + bndLine[j].northing) / 2.0, bndLine[i].heading); - - bndLine.Insert(j, pointB); - bndCount = bndLine.Count; - i--; - } - } - - //make sure distance isn't too big between points on boundary - bndCount = bndLine.Count; - - for (int i = 0; i < bndCount; i++) - { - int j = i + 1; - - if (j == bndCount) j = 0; - distance = glm.Distance(bndLine[i], bndLine[j]); - if (distance > spacing * 1.6) - { - vec3 pointB = new vec3((bndLine[i].easting + bndLine[j].easting) / 2.0, - (bndLine[i].northing + bndLine[j].northing) / 2.0, bndLine[i].heading); - - bndLine.Insert(j, pointB); - bndCount = bndLine.Count; - i--; - } - } - - //make sure distance isn't too small between points on headland - spacing *= 1.2; - bndCount = bndLine.Count; - for (int i = 0; i < bndCount - 1; i++) - { - distance = glm.Distance(bndLine[i], bndLine[i + 1]); - if (distance < spacing) - { - bndLine.RemoveAt(i + 1); - bndCount = bndLine.Count; - i--; - } - } - - //make sure headings are correct for calculated points - CalculateBoundaryHeadings(); - - double delta = 0; - bndLineEar?.Clear(); - - for (int i = 0; i < bndLine.Count; i++) - { - if (i == 0) - { - bndLineEar.Add(new vec2(bndLine[i].easting, bndLine[i].northing)); - continue; - } - delta += (bndLine[i - 1].heading - bndLine[i].heading); - if (Math.Abs(delta) > 0.01) - { - bndLineEar.Add(new vec2(bndLine[i].easting, bndLine[i].northing)); - delta = 0; - } - } - } - - public void ReverseWinding() - { - //reverse the boundary - int cnt = bndLine.Count; - vec3[] arr = new vec3[cnt]; - cnt--; - bndLine.CopyTo(arr); - bndLine.Clear(); - for (int i = cnt; i >= 0; i--) - { - arr[i].heading -= Math.PI; - if (arr[i].heading < 0) arr[i].heading += glm.twoPI; - bndLine.Add(arr[i]); - } - } - - public bool IsPointInsideBoundaryArea(vec3 testPoint) - { - bool result = false; - int j = bndLine.Count - 1; - for (int i = 0; i < bndLine.Count; i++) - { - if ((bndLine[i].easting < testPoint.easting && bndLine[j].easting >= testPoint.easting) || (bndLine[j].easting < testPoint.easting && bndLine[i].easting >= testPoint.easting)) - { - if (bndLine[i].northing + (testPoint.easting - bndLine[i].easting) / (bndLine[j].easting - bndLine[i].easting) * (bndLine[j].northing - bndLine[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - - public bool IsPointInsideBoundaryEar(vec3 testPoint) - { - bool result = false; - int j = bndLineEar.Count - 1; - for (int i = 0; i < bndLineEar.Count; i++) - { - if ((bndLineEar[i].easting < testPoint.easting && bndLineEar[j].easting >= testPoint.easting) || (bndLineEar[j].easting < testPoint.easting && bndLineEar[i].easting >= testPoint.easting)) - { - if (bndLineEar[i].northing + (testPoint.easting - bndLineEar[i].easting) / (bndLineEar[j].easting - bndLineEar[i].easting) * (bndLineEar[j].northing - bndLineEar[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - - public bool IsPointInsideBoundaryEar(vec2 testPoint) - { - bool result = false; - int j = bndLineEar.Count - 1; - for (int i = 0; i < bndLineEar.Count; i++) - { - if ((bndLineEar[i].easting < testPoint.easting && bndLineEar[j].easting >= testPoint.easting) || (bndLineEar[j].easting < testPoint.easting && bndLineEar[i].easting >= testPoint.easting)) - { - if (bndLineEar[i].northing + (testPoint.easting - bndLineEar[i].easting) / (bndLineEar[j].easting - bndLineEar[i].easting) * (bndLineEar[j].northing - bndLineEar[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - - public void DrawBoundaryLine(int lw, bool outOfBounds) - { - ////draw the perimeter line so far - if (bndLine.Count < 1) return; - //GL.PointSize(8); - //int ptCount = bndLine.Count; - //GL.Color3(0.925f, 0.752f, 0.860f); - ////else - //GL.Begin(PrimitiveType.Points); - //for (int h = 0; h < ptCount; h++) GL.Vertex3(bndLine[h].easting, bndLine[h].northing, 0); - ////GL.Color3(0.95f, 0.972f, 0.90f); - ////GL.Vertex3(bndLine[0].easting, bndLine[0].northing, 0); - //GL.End(); - - //ptCount = bdList.Count; - //if (ptCount < 1) return; - if (!outOfBounds) - { - GL.Color3(0.95f, 0.75f, 0.50f); - GL.LineWidth(lw); - } - else - { - GL.LineWidth(lw * 3); - GL.Color3(0.95f, 0.25f, 0.250f); - } - - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < bndLineEar.Count; i++) - { - GL.Vertex3(bndLineEar[i].easting, bndLineEar[i].northing, 0); - } - GL.End(); - } - - //obvious - public bool CalculateBoundaryArea(int idx) - { - int ptCount = bndLine.Count; - if (ptCount < 1) return false; - bool isClockwise = true; - - area = 0; // Accumulates area in the loop - int j = ptCount - 1; // The last vertex is the 'previous' one to the first - - for (int i = 0; i < ptCount; j = i++) - { - area += (bndLine[j].easting + bndLine[i].easting) * (bndLine[j].northing - bndLine[i].northing); - } - if (area < 0) isClockwise = false; - - area = Math.Abs(area / 2); - - //make sure is clockwise for outer counter clockwise for inner - if ((idx == 0 && isClockwise) || (idx > 0 && !isClockwise)) - { - ReverseWinding(); - } - - return isClockwise; - } - } -} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CBoundaryList.cs b/SourceCode/GPS/Classes/CBoundaryList.cs new file mode 100644 index 000000000..8d8eee844 --- /dev/null +++ b/SourceCode/GPS/Classes/CBoundaryList.cs @@ -0,0 +1,106 @@ +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; + +namespace AgOpenGPS +{ + public partial class CBoundaryList + { + //list of coordinates of boundary line + public List fenceLine = new List(128); + public List fenceLineEar = new List(128); + public List hdLine = new List(128); + public List turnLine = new List(128); + + + //constructor + public CBoundaryList() + { + area = 0; + isDriveAround = false; + isDriveThru = false; + } + + public bool IsPointInPolygon(vec3 testPoint, ref List polygon) + { + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) + { + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + + public bool IsPointInPolygon(vec2 testPoint, ref List polygon) + { + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) + { + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + public bool IsPointInPolygon(vec2 testPoint, ref List polygon) + { + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) + { + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + public bool IsPointInPolygon(vec3 testPoint, ref List polygon) + { + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) + { + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; + } + return result; + } + } +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index f14c244c6..4ae78d278 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -922,9 +922,9 @@ public void StopContourLine(vec3 pivot) } //build contours for boundaries - public void BuildBoundaryContours(int pass, int spacingInt) + public void BuildFenceContours(int pass, int spacingInt) { - if (mf.bnd.bndArr.Count == 0) + if (mf.bnd.bndList.Count == 0) { mf.TimedMessageBox(1500, "Boundary Contour Error", "No Boundaries Made"); return; @@ -950,10 +950,10 @@ public void BuildBoundaryContours(int pass, int spacingInt) //totalHeadWidth = (mf.tool.toolWidth - mf.tool.toolOverlap) * 0.5 + 0.2 + (mf.tool.toolWidth - mf.tool.toolOverlap); - for (int j = 0; j < mf.bnd.bndArr.Count; j++) + for (int j = 0; j < mf.bnd.bndList.Count; j++) { //count the points from the boundary - int ptCount = mf.bnd.bndArr[j].bndLine.Count; + int ptCount = mf.bnd.bndList[j].fenceLine.Count; ptList = new List(128); stripList.Add(ptList); @@ -961,9 +961,9 @@ public void BuildBoundaryContours(int pass, int spacingInt) for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.bnd.bndArr[j].bndLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.bnd.bndArr[j].bndLine[i].heading) * totalHeadWidth); - point.northing = mf.bnd.bndArr[j].bndLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.bnd.bndArr[j].bndLine[i].heading) * totalHeadWidth); - point.heading = mf.bnd.bndArr[j].bndLine[i].heading - Math.PI; + point.easting = mf.bnd.bndList[j].fenceLine[i].easting - (signPass * Math.Sin(glm.PIBy2 + mf.bnd.bndList[j].fenceLine[i].heading) * totalHeadWidth); + point.northing = mf.bnd.bndList[j].fenceLine[i].northing - (signPass * Math.Cos(glm.PIBy2 + mf.bnd.bndList[j].fenceLine[i].heading) * totalHeadWidth); + point.heading = mf.bnd.bndList[j].fenceLine[i].heading - Math.PI; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if inside actual field boundary diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs new file mode 100644 index 000000000..1185efd2c --- /dev/null +++ b/SourceCode/GPS/Classes/CFence.cs @@ -0,0 +1,181 @@ +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; + +namespace AgOpenGPS +{ + public partial class CBoundary + { + public List bndBeingMadePts = new List(128); + + public double createBndOffset; + public bool isBndBeingMade; + + // the list of possible bounds points + public List bndClosestList = new List(); + + public bool isDrawRightSide = true, isOkToAddPoints = false; + + public int fenceSelected, closestFenceNum; + + //point at the farthest boundary segment from pivotAxle + public vec3 closestFencePt = new vec3(-10000, -10000, 9); + + public bool IsInsideAllFences(vec3 testPoint) + { + //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders + if (bndList[0].IsPointInPolygon(testPoint, ref bndList[0].fenceLine)) + { + for (int i = 1; i < bndList.Count; i++) + { + //make sure not inside a non drivethru boundary + if (bndList[i].isDriveThru) continue; + if (bndList[i].IsPointInPolygon(testPoint, ref bndList[i].fenceLine)) + { + return false; + } + } + } + else + { + return false; + } + //we are safely inside outer, outside inner boundaries + return true; + } + + public void DrawFenceLines() + { + //draw the boundaries + GL.Color3(0.75f, 0.5f, 0.250f); + + for (int i = 0; i < bndList.Count; i++) + { + bndList[i].DrawFenceLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); + } + + if (bndBeingMadePts.Count > 0) + { + //the boundary so far + vec3 pivot = mf.pivotAxlePos; + GL.LineWidth(mf.ABLine.lineWidth); + GL.Color3(0.825f, 0.22f, 0.90f); + GL.Begin(PrimitiveType.LineStrip); + for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); + GL.Color3(0.295f, 0.972f, 0.290f); + GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); + GL.End(); + + //line from last point to pivot marker + GL.Color3(0.825f, 0.842f, 0.0f); + GL.Enable(EnableCap.LineStipple); + GL.LineStipple(1, 0x0700); + GL.Begin(PrimitiveType.LineStrip); + if (isDrawRightSide) + { + GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); + + GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * -createBndOffset), + pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * -createBndOffset), 0); + GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); + } + else + { + GL.Vertex3(bndBeingMadePts[0].easting, bndBeingMadePts[0].northing, 0); + + GL.Vertex3(pivot.easting + (Math.Sin(pivot.heading - glm.PIBy2) * createBndOffset), + pivot.northing + (Math.Cos(pivot.heading - glm.PIBy2) * createBndOffset), 0); + GL.Vertex3(bndBeingMadePts[bndBeingMadePts.Count - 1].easting, bndBeingMadePts[bndBeingMadePts.Count - 1].northing, 0); + } + GL.End(); + GL.Disable(EnableCap.LineStipple); + + //boundary points + GL.Color3(0.0f, 0.95f, 0.95f); + GL.PointSize(6.0f); + GL.Begin(PrimitiveType.Points); + for (int h = 0; h < bndBeingMadePts.Count; h++) GL.Vertex3(bndBeingMadePts[h].easting, bndBeingMadePts[h].northing, 0); + GL.End(); + } + } + + } +} + + +//public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) + //{ + // { + // boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); + // boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); + + // boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); + // boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); + + // boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); + // boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); + + // boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); + // boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); + // } + + // int ptCount; + + // //determine if point is inside bounding box + // bndClosestList.Clear(); + // vec4 inBox; + // for (int i = 0; i < plots.Count; i++) + // { + // //skip the drive thru + // if (plots[i].isDriveThru) continue; + + // ptCount = plots[i].bndLine.Count; + // for (int p = 0; p < ptCount; p++) + // { + // if ((((boxB.easting - boxA.easting) * (plots[i].bndLine[p].northing - boxA.northing)) + // - ((boxB.northing - boxA.northing) * (plots[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } + + // if ((((boxD.easting - boxC.easting) * (plots[i].bndLine[p].northing - boxC.northing)) + // - ((boxD.northing - boxC.northing) * (plots[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } + + // if ((((boxC.easting - boxB.easting) * (plots[i].bndLine[p].northing - boxB.northing)) + // - ((boxC.northing - boxB.northing) * (plots[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } + + // if ((((boxA.easting - boxD.easting) * (plots[i].bndLine[p].northing - boxD.northing)) + // - ((boxA.northing - boxD.northing) * (plots[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } + + // //it's in the box, so add to list + // inBox.easting = plots[i].bndLine[p].easting; + // inBox.northing = plots[i].bndLine[p].northing; + // inBox.heading = plots[i].bndLine[p].heading; + // inBox.index = i; + + // //which boundary/headland is it from + // bndClosestList.Add(inBox); + // } + // } + + // //which of the points is closest + // closestBoundaryPt.easting = -20000; closestBoundaryPt.northing = -20000; + // ptCount = bndClosestList.Count; + // if (ptCount != 0) + // { + // //determine closest point + // double minDistance = 9999999; + // for (int i = 0; i < ptCount; i++) + // { + // double dist = ((fromPt.easting - bndClosestList[i].easting) * (fromPt.easting - bndClosestList[i].easting)) + // + ((fromPt.northing - bndClosestList[i].northing) * (fromPt.northing - bndClosestList[i].northing)); + // if (minDistance >= dist) + // { + // minDistance = dist; + + // closestBoundaryPt.easting = bndClosestList[i].easting; + // closestBoundaryPt.northing = bndClosestList[i].northing; + // closestBoundaryPt.heading = bndClosestList[i].heading; + // closestBoundaryNum = bndClosestList[i].index; + // } + // } + // if (closestBoundaryPt.heading < 0) closestBoundaryPt.heading += glm.twoPI; + // } + //} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CFenceLine.cs b/SourceCode/GPS/Classes/CFenceLine.cs new file mode 100644 index 000000000..9a84e554b --- /dev/null +++ b/SourceCode/GPS/Classes/CFenceLine.cs @@ -0,0 +1,213 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using OpenTK.Graphics.OpenGL; + +namespace AgOpenGPS +{ + public partial class CBoundaryList + { + //area variable + public double area; + + //boundary variables + public bool isDriveAround, isDriveThru; + + public void CalculateFenceLineHeadings() + { + //to calc heading based on next and previous points to give an average heading. + int cnt = fenceLine.Count; + vec3[] arr = new vec3[cnt]; + cnt--; + fenceLine.CopyTo(arr); + fenceLine.Clear(); + + //first point needs last, first, second points + vec3 pt3 = arr[0]; + pt3.heading = Math.Atan2(arr[1].easting - arr[cnt].easting, arr[1].northing - arr[cnt].northing); + if (pt3.heading < 0) pt3.heading += glm.twoPI; + fenceLine.Add(pt3); + + //middle points + for (int i = 1; i < cnt; i++) + { + pt3 = arr[i]; + pt3.heading = Math.Atan2(arr[i + 1].easting - arr[i - 1].easting, arr[i + 1].northing - arr[i - 1].northing); + if (pt3.heading < 0) pt3.heading += glm.twoPI; + fenceLine.Add(pt3); + } + + //last and first point + pt3 = arr[cnt]; + pt3.heading = Math.Atan2(arr[0].easting - arr[cnt - 1].easting, arr[0].northing - arr[cnt - 1].northing); + if (pt3.heading < 0) pt3.heading += glm.twoPI; + fenceLine.Add(pt3); + } + + public void FixFenceLine(int bndNum) + { + double spacing; + //boundary point spacing based on eq width + //close if less then 30 ha, 60ha, more then 60 + if (area < 200000) spacing = 1.1; + else if (area < 400000) spacing = 2.2; + else spacing = 3.3; + + if (bndNum > 0) spacing *= 0.5; + + int bndCount = fenceLine.Count; + double distance; + + //make sure distance isn't too big between points on boundary + for (int i = 0; i < bndCount; i++) + { + int j = i + 1; + + if (j == bndCount) j = 0; + distance = glm.Distance(fenceLine[i], fenceLine[j]); + if (distance > spacing * 1.5) + { + vec3 pointB = new vec3((fenceLine[i].easting + fenceLine[j].easting) / 2.0, + (fenceLine[i].northing + fenceLine[j].northing) / 2.0, fenceLine[i].heading); + + fenceLine.Insert(j, pointB); + bndCount = fenceLine.Count; + i--; + } + } + + //make sure distance isn't too big between points on boundary + bndCount = fenceLine.Count; + + for (int i = 0; i < bndCount; i++) + { + int j = i + 1; + + if (j == bndCount) j = 0; + distance = glm.Distance(fenceLine[i], fenceLine[j]); + if (distance > spacing * 1.6) + { + vec3 pointB = new vec3((fenceLine[i].easting + fenceLine[j].easting) / 2.0, + (fenceLine[i].northing + fenceLine[j].northing) / 2.0, fenceLine[i].heading); + + fenceLine.Insert(j, pointB); + bndCount = fenceLine.Count; + i--; + } + } + + //make sure distance isn't too small between points on headland + spacing *= 1.2; + bndCount = fenceLine.Count; + for (int i = 0; i < bndCount - 1; i++) + { + distance = glm.Distance(fenceLine[i], fenceLine[i + 1]); + if (distance < spacing) + { + fenceLine.RemoveAt(i + 1); + bndCount = fenceLine.Count; + i--; + } + } + + //make sure headings are correct for calculated points + CalculateFenceLineHeadings(); + + double delta = 0; + fenceLineEar?.Clear(); + + for (int i = 0; i < fenceLine.Count; i++) + { + if (i == 0) + { + fenceLineEar.Add(new vec2(fenceLine[i].easting, fenceLine[i].northing)); + continue; + } + delta += (fenceLine[i - 1].heading - fenceLine[i].heading); + if (Math.Abs(delta) > 0.01) + { + fenceLineEar.Add(new vec2(fenceLine[i].easting, fenceLine[i].northing)); + delta = 0; + } + } + } + + public void ReverseWinding() + { + //reverse the boundary + int cnt = fenceLine.Count; + vec3[] arr = new vec3[cnt]; + cnt--; + fenceLine.CopyTo(arr); + fenceLine.Clear(); + for (int i = cnt; i >= 0; i--) + { + arr[i].heading -= Math.PI; + if (arr[i].heading < 0) arr[i].heading += glm.twoPI; + fenceLine.Add(arr[i]); + } + } + + public void DrawFenceLine(int lw, bool outOfBounds) + { + ////draw the perimeter line so far + if (fenceLine.Count < 1) return; + //GL.PointSize(8); + //int ptCount = bndLine.Count; + //GL.Color3(0.925f, 0.752f, 0.860f); + ////else + //GL.Begin(PrimitiveType.Points); + //for (int h = 0; h < ptCount; h++) GL.Vertex3(bndLine[h].easting, bndLine[h].northing, 0); + ////GL.Color3(0.95f, 0.972f, 0.90f); + ////GL.Vertex3(bndLine[0].easting, bndLine[0].northing, 0); + //GL.End(); + + //ptCount = bdList.Count; + //if (ptCount < 1) return; + if (!outOfBounds) + { + GL.Color3(0.95f, 0.75f, 0.50f); + GL.LineWidth(lw); + } + else + { + GL.LineWidth(lw * 3); + GL.Color3(0.95f, 0.25f, 0.250f); + } + + GL.Begin(PrimitiveType.LineLoop); + for (int i = 0; i < fenceLineEar.Count; i++) + { + GL.Vertex3(fenceLineEar[i].easting, fenceLineEar[i].northing, 0); + } + GL.End(); + } + + //obvious + public bool CalculateFenceArea(int idx) + { + int ptCount = fenceLine.Count; + if (ptCount < 1) return false; + bool isClockwise = true; + + area = 0; // Accumulates area in the loop + int j = ptCount - 1; // The last vertex is the 'previous' one to the first + + for (int i = 0; i < ptCount; j = i++) + { + area += (fenceLine[j].easting + fenceLine[i].easting) * (fenceLine[j].northing - fenceLine[i].northing); + } + if (area < 0) isClockwise = false; + + area = Math.Abs(area / 2); + + //make sure is clockwise for outer counter clockwise for inner + if ((idx == 0 && isClockwise) || (idx > 0 && !isClockwise)) + { + ReverseWinding(); + } + + return isClockwise; + } + } +} diff --git a/SourceCode/GPS/Classes/CFieldData.cs b/SourceCode/GPS/Classes/CFieldData.cs index aed0102cb..72adb8a0a 100644 --- a/SourceCode/GPS/Classes/CFieldData.cs +++ b/SourceCode/GPS/Classes/CFieldData.cs @@ -132,14 +132,14 @@ public CFieldData(FormGPS _f) public void UpdateFieldBoundaryGUIAreas() { - if (mf.bnd.bndArr.Count > 0) + if (mf.bnd.bndList.Count > 0) { - areaOuterBoundary = mf.bnd.bndArr[0].area; + areaOuterBoundary = mf.bnd.bndList[0].area; areaBoundaryOuterLessInner = areaOuterBoundary; - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { - areaBoundaryOuterLessInner -= mf.bnd.bndArr[i].area; + areaBoundaryOuterLessInner -= mf.bnd.bndList[i].area; } } else diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index 4e7febefb..70a878318 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -4,7 +4,7 @@ namespace AgOpenGPS { public partial class CBoundary { - public bool isOn; + public bool isHeadlandOn; public double leftToolDistance; public double rightToolDistance; @@ -37,19 +37,19 @@ public void SetHydPosition() public void WhereAreToolCorners() { - if (bndArr.Count > 0 && bndArr[0].hdLine.Count > 0) + if (bndList.Count > 0 && bndList[0].hdLine.Count > 0) { bool isLeftInWk, isRightInWk = true; - if (isOn) + if (isHeadlandOn) { for (int j = 0; j < mf.tool.numOfSections; j++) { if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftInWk = bndArr[0].IsPointInHeadArea(mf.section[j].leftPoint); - isRightInWk = bndArr[0].IsPointInHeadArea(mf.section[j].rightPoint); + isLeftInWk = bndList[0].IsPointInPolygon(mf.section[j].leftPoint, ref bndList[0].hdLine); + isRightInWk = bndList[0].IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); //save left side mf.tool.isLeftSideInHeadland = !isLeftInWk; @@ -62,7 +62,7 @@ public void WhereAreToolCorners() { //grab the right of previous section, its the left of this section isLeftInWk = isRightInWk; - isRightInWk = bndArr[0].IsPointInHeadArea(mf.section[j].rightPoint); + isRightInWk = bndList[0].IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } @@ -84,7 +84,7 @@ public void WhereAreToolCorners() public void WhereAreToolLookOnPoints() { - if (bndArr.Count > 0 && bndArr[0].hdLine.Count > 0) + if (bndList.Count > 0 && bndList[0].hdLine.Count > 0) { vec3 toolFix = mf.toolPos; double sinAB = Math.Sin(toolFix.heading); @@ -126,40 +126,14 @@ public void WhereAreToolLookOnPoints() } } - public void DrawHeadLines() - { - for (int i = 0; i < bndArr.Count; i++) - { - if (bndArr[i].hdLine.Count > 0) bndArr[i].DrawHeadLine(); - } - - //GL.LineWidth(4.0f); - //GL.Color3(0.9219f, 0.2f, 0.970f); - //GL.Begin(PrimitiveType.Lines); - //{ - // GL.Vertex3(headArr[0].hdLine[A].easting, headArr[0].hdLine[A].northing, 0); - // GL.Vertex3(headArr[0].hdLine[B].easting, headArr[0].hdLine[B].northing, 0); - // GL.Vertex3(headArr[0].hdLine[C].easting, headArr[0].hdLine[C].northing, 0); - // GL.Vertex3(headArr[0].hdLine[D].easting, headArr[0].hdLine[D].northing, 0); - //} - //GL.End(); - - //GL.PointSize(6.0f); - //GL.Color3(0.219f, 0.932f, 0.970f); - //GL.Begin(PrimitiveType.Points); - //GL.Vertex3(downL.easting, downL.northing, 0); - //GL.Vertex3(downR.easting, downR.northing, 0); - //GL.End(); - } - public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add - if (bndArr.Count > 0 && bndArr[0].IsPointInHeadArea(pt)) + if (bndList.Count > 0 && bndList[0].IsPointInPolygon(pt, ref bndList[0].hdLine)) { - for (int b = 1; b < bndArr.Count; b++) + for (int b = 1; b < bndList.Count; b++) { - if (bndArr[b].IsPointInHeadArea(pt)) + if (bndList[b].IsPointInPolygon(pt, ref bndList[b].hdLine)) { //point is in an inner turn area but inside outer return false; diff --git a/SourceCode/GPS/Classes/CHeadLines.cs b/SourceCode/GPS/Classes/CHeadLines.cs index c933932a9..634e61b08 100644 --- a/SourceCode/GPS/Classes/CHeadLines.cs +++ b/SourceCode/GPS/Classes/CHeadLines.cs @@ -2,43 +2,8 @@ namespace AgOpenGPS { - public partial class CBoundaryLines + public partial class CBoundaryList { - public bool IsPointInHeadArea(vec2 testPoint) - { - bool result = false; - int j = hdLine.Count - 1; - for (int i = 0; i < hdLine.Count; i++) - { - if ((hdLine[i].easting < testPoint.easting && hdLine[j].easting >= testPoint.easting) || (hdLine[j].easting < testPoint.easting && hdLine[i].easting >= testPoint.easting)) - { - if (hdLine[i].northing + (testPoint.easting - hdLine[i].easting) / (hdLine[j].easting - hdLine[i].easting) * (hdLine[j].northing - hdLine[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - - public bool IsPointInHeadArea(vec3 testPoint) - { - bool result = false; - int j = hdLine.Count - 1; - for (int i = 0; i < hdLine.Count; i++) - { - if ((hdLine[i].easting < testPoint.easting && hdLine[j].easting >= testPoint.easting) || (hdLine[j].easting < testPoint.easting && hdLine[i].easting >= testPoint.easting)) - { - if (hdLine[i].northing + (testPoint.easting - hdLine[i].easting) / (hdLine[j].easting - hdLine[i].easting) * (hdLine[j].northing - hdLine[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } public void DrawHeadLine() { diff --git a/SourceCode/GPS/Classes/CTram.cs b/SourceCode/GPS/Classes/CTram.cs index e1dfbe4de..3a8efe3fb 100644 --- a/SourceCode/GPS/Classes/CTram.cs +++ b/SourceCode/GPS/Classes/CTram.cs @@ -84,7 +84,7 @@ public void DrawTram() public void BuildTramBnd() { - bool isBndExist = mf.bnd.bndArr.Count != 0; + bool isBndExist = mf.bnd.bndList.Count != 0; if (isBndExist) { @@ -101,7 +101,7 @@ public void BuildTramBnd() private void CreateBndInnerTramTrack() { //count the points from the boundary - int ptCount = mf.bnd.bndArr[0].bndLine.Count; + int ptCount = mf.bnd.bndList[0].fenceLine.Count; tramBndInnerArr?.Clear(); //outside point @@ -113,18 +113,18 @@ private void CreateBndInnerTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.bnd.bndArr[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.easting = mf.bnd.bndList[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); - pt3.northing = mf.bnd.bndArr[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); + pt3.northing = mf.bnd.bndList[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 + halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.bnd.bndArr[0].bndLine[j].northing, mf.bnd.bndArr[0].bndLine[j].easting); + mf.bnd.bndList[0].fenceLine[j].northing, mf.bnd.bndList[0].fenceLine[j].easting); if (check < distSq) { Add = false; @@ -149,7 +149,7 @@ private void CreateBndInnerTramTrack() public void CreateBndOuterTramTrack() { //count the points from the boundary - int ptCount = mf.bnd.bndArr[0].bndLine.Count; + int ptCount = mf.bnd.bndList[0].fenceLine.Count; tramBndOuterArr?.Clear(); //outside point @@ -161,18 +161,18 @@ public void CreateBndOuterTramTrack() for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.bnd.bndArr[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.easting = mf.bnd.bndList[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); - pt3.northing = mf.bnd.bndArr[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); + pt3.northing = mf.bnd.bndList[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (tramWidth * 0.5 - halfWheelTrack)); bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.bnd.bndArr[0].bndLine[j].northing, mf.bnd.bndArr[0].bndLine[j].easting); + mf.bnd.bndList[0].fenceLine[j].northing, mf.bnd.bndList[0].fenceLine[j].easting); if (check < distSq) { Add = false; diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index d6fdec0d7..9ed0738f7 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -11,6 +11,13 @@ public partial class CBoundary public int turnSelected, closestTurnNum; + //generated box for finding closest point + public vec2 boxA = new vec2(9000, 9000), boxB = new vec2(9000, 9002); + + public vec2 boxC = new vec2(9001, 9001), boxD = new vec2(9002, 9003); + + private readonly double boxLength; + //point at the farthest turn segment from pivotAxle public vec3 closestTurnPt = new vec3(-10000, -10000, 9); @@ -31,13 +38,13 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (bndArr[0].IsPointInTurnWorkArea(pt)) + if (bndList[0].IsPointInPolygon(pt, ref bndList[0].turnLine)) { - for (int t = 1; t < bndArr.Count; t++) + for (int t = 1; t < bndList.Count; t++) { - if (bndArr[t].isDriveThru) continue; - if (bndArr[t].isDriveAround) continue; - if (bndArr[t].IsPointInTurnWorkArea(pt)) + if (bndList[t].isDriveThru) continue; + if (bndList[t].isDriveAround) continue; + if (bndList[t].IsPointInPolygon(pt, ref bndList[t].turnLine)) { isFound = true; closestTurnNum = t; @@ -88,25 +95,25 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB vec4 inBox; - int ptCount = bndArr[closestTurnNum].turnLine.Count; + int ptCount = bndList[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = bndArr[closestTurnNum].turnLine[p].easting; - inBox.northing = bndArr[closestTurnNum].turnLine[p].northing; - inBox.heading = bndArr[closestTurnNum].turnLine[p].heading; + inBox.easting = bndList[closestTurnNum].turnLine[p].easting; + inBox.northing = bndList[closestTurnNum].turnLine[p].northing; + inBox.heading = bndList[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -142,26 +149,26 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB //determine if point is inside bounding box of the 1 turn chosen above turnClosestList.Clear(); - ptCount = bndArr[closestTurnNum].turnLine.Count; + ptCount = bndList[closestTurnNum].turnLine.Count; for (int p = 0; p < ptCount; p++) { - if ((((boxB.easting - boxA.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxA.northing)) - - ((boxB.northing - boxA.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } + if ((((boxB.easting - boxA.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxA.northing)) + - ((boxB.northing - boxA.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxA.easting))) < 0) { continue; } - if ((((boxD.easting - boxC.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxC.northing)) - - ((boxD.northing - boxC.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } + if ((((boxD.easting - boxC.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxC.northing)) + - ((boxD.northing - boxC.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxC.easting))) < 0) { continue; } - if ((((boxC.easting - boxB.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxB.northing)) - - ((boxC.northing - boxB.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } + if ((((boxC.easting - boxB.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxB.northing)) + - ((boxC.northing - boxB.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxB.easting))) < 0) { continue; } - if ((((boxA.easting - boxD.easting) * (bndArr[closestTurnNum].turnLine[p].northing - boxD.northing)) - - ((boxA.northing - boxD.northing) * (bndArr[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } + if ((((boxA.easting - boxD.easting) * (bndList[closestTurnNum].turnLine[p].northing - boxD.northing)) + - ((boxA.northing - boxD.northing) * (bndList[closestTurnNum].turnLine[p].easting - boxD.easting))) < 0) { continue; } //it's in the box, so add to list - inBox.easting = bndArr[closestTurnNum].turnLine[p].easting; - inBox.northing = bndArr[closestTurnNum].turnLine[p].northing; - inBox.heading = bndArr[closestTurnNum].turnLine[p].heading; + inBox.easting = bndList[closestTurnNum].turnLine[p].easting; + inBox.northing = bndList[closestTurnNum].turnLine[p].northing; + inBox.heading = bndList[closestTurnNum].turnLine[p].heading; inBox.index = closestTurnNum; //which turn/headland is it from @@ -203,7 +210,7 @@ public void BuildTurnLines() //update the GUI values for boundaries mf.fd.UpdateFieldBoundaryGUIAreas(); - if (bndArr.Count == 0) + if (bndList.Count == 0) { //mf.TimedMessageBox(1500, " No Boundaries", "No Turn Lines Made"); return; @@ -216,29 +223,29 @@ public void BuildTurnLines() double totalHeadWidth = mf.yt.uturnDistanceFromBoundary; //inside boundaries - for (int j = 0; j < bndArr.Count; j++) + for (int j = 0; j < bndList.Count; j++) { - bndArr[j].turnLine.Clear(); - if (bndArr[j].isDriveThru || bndArr[j].isDriveAround) continue; + bndList[j].turnLine.Clear(); + if (bndList[j].isDriveThru || bndList[j].isDriveAround) continue; - int ptCount = bndArr[j].bndLine.Count; + int ptCount = bndList[j].fenceLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point outside the boundary - point.easting = bndArr[j].bndLine[i].easting + (-Math.Sin(glm.PIBy2 + bndArr[j].bndLine[i].heading) * totalHeadWidth); - point.northing = bndArr[j].bndLine[i].northing + (-Math.Cos(glm.PIBy2 + bndArr[j].bndLine[i].heading) * totalHeadWidth); - point.heading = bndArr[j].bndLine[i].heading; + point.easting = bndList[j].fenceLine[i].easting + (-Math.Sin(glm.PIBy2 + bndList[j].fenceLine[i].heading) * totalHeadWidth); + point.northing = bndList[j].fenceLine[i].northing + (-Math.Cos(glm.PIBy2 + bndList[j].fenceLine[i].heading) * totalHeadWidth); + point.heading = bndList[j].fenceLine[i].heading; if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == bndArr[j].IsPointInsideBoundaryEar(point)) + if (j == 0 == bndList[j].IsPointInPolygon(point, ref bndList[j].fenceLineEar)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); - bndArr[j].turnLine.Add(tPnt); + bndList[j].turnLine.Add(tPnt); } } - bndArr[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); + bndList[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); } } @@ -248,17 +255,17 @@ public void DrawTurnLines() GL.Color3(0.3555f, 0.6232f, 0.20f); //GL.PointSize(2); - for (int i = 0; i < bndArr.Count; i++) + for (int i = 0; i < bndList.Count; i++) { - if (bndArr[i].isDriveAround) continue; + if (bndList[i].isDriveAround) continue; //turnArr[i].DrawTurnLine(); { ////draw the turn line oject - int ptCount = bndArr[i].turnLine.Count; + int ptCount = bndList[i].turnLine.Count; if (ptCount < 1) continue; GL.Begin(PrimitiveType.LineLoop); - for (int h = 0; h < ptCount; h++) GL.Vertex3(bndArr[i].turnLine[h].easting, bndArr[i].turnLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(bndList[i].turnLine[h].easting, bndList[i].turnLine[h].northing, 0); GL.End(); } } diff --git a/SourceCode/GPS/Classes/CTurnLines.cs b/SourceCode/GPS/Classes/CTurnLines.cs index 8b37faa76..83bd604fd 100644 --- a/SourceCode/GPS/Classes/CTurnLines.cs +++ b/SourceCode/GPS/Classes/CTurnLines.cs @@ -3,7 +3,7 @@ namespace AgOpenGPS { - public partial class CBoundaryLines + public partial class CBoundaryList { public void CalculateTurnHeadings() { @@ -48,12 +48,12 @@ public void FixTurnLine(double totalHeadWidth, double spacing) double distance; //remove the points too close to boundary - for (int i = 0; i < bndLine.Count; i++) + for (int i = 0; i < fenceLine.Count; i++) { for (int j = 0; j < lineCount; j++) { //make sure distance between headland and boundary is not less then width - distance = glm.DistanceSquared(bndLine[i], turnLine[j]); + distance = glm.DistanceSquared(fenceLine[i], turnLine[j]); if (distance < (totalHeadWidth * 0.99)) { turnLine.RemoveAt(j); @@ -125,23 +125,6 @@ public void FixTurnLine(double totalHeadWidth, double spacing) //} } - public bool IsPointInTurnWorkArea(vec3 testPoint) - { - bool result = false; - int j = turnLine.Count - 1; - for (int i = 0; i < turnLine.Count; i++) - { - if ((turnLine[i].easting < testPoint.easting && turnLine[j].easting >= testPoint.easting) || (turnLine[j].easting < testPoint.easting && turnLine[i].easting >= testPoint.easting)) - { - if (turnLine[i].northing + (testPoint.easting - turnLine[i].easting) / (turnLine[j].easting - turnLine[i].easting) * (turnLine[j].northing - turnLine[i].northing) < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } public void DrawTurnLine() { ////draw the turn line oject diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index b6a82524e..00fb32256 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -115,7 +115,7 @@ public bool FindCurveTurnPoints() //for each point in succession keep going till a turnLine is found. for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) { - if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (!mf.bnd.bndList[0].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -125,12 +125,12 @@ public bool FindCurveTurnPoints() goto CrossingFound; } - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndArr[i].isDriveThru) continue; - if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (mf.bnd.bndList[i].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) { crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -152,7 +152,7 @@ public bool FindCurveTurnPoints() for (int j = mf.curve.currentLocationIndex; j > 0; j--) { - if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (!mf.bnd.bndList[0].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; @@ -162,12 +162,12 @@ public bool FindCurveTurnPoints() goto CrossingFound; } - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndArr[i].isDriveThru) continue; - if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(mf.curve.curList[j])) + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (mf.bnd.bndList[i].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) { crossingCurvePoint.easting = mf.curve.curList[j].easting; crossingCurvePoint.northing = mf.curve.curList[j].northing; @@ -191,17 +191,17 @@ public bool FindCurveTurnPoints() return false; } - int curTurnLineCount = mf.bnd.bndArr[turnNum].turnLine.Count; + int curTurnLineCount = mf.bnd.bndList[turnNum].turnLine.Count; //possible points close to AB Curve point List turnLineCloseList = new List(); for (int j = 0; j < curTurnLineCount; j++) { - if ((mf.bnd.bndArr[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 - && (mf.bnd.bndArr[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 - && (mf.bnd.bndArr[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 - && (mf.bnd.bndArr[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) + if ((mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 + && (mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 + && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 + && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) { turnLineCloseList.Add(j); } @@ -211,8 +211,8 @@ public bool FindCurveTurnPoints() curTurnLineCount = turnLineCloseList.Count; for (int i = 0; i < curTurnLineCount; i++) { - dist1 = glm.Distance(mf.bnd.bndArr[turnNum].turnLine[turnLineCloseList[i]].easting, - mf.bnd.bndArr[turnNum].turnLine[turnLineCloseList[i]].northing, + dist1 = glm.Distance(mf.bnd.bndList[turnNum].turnLine[turnLineCloseList[i]].easting, + mf.bnd.bndList[turnNum].turnLine[turnLineCloseList[i]].northing, crossingCurvePoint.easting, crossingCurvePoint.northing); if (dist1 < dist2) { @@ -222,9 +222,9 @@ public bool FindCurveTurnPoints() } //fill up the coords - crossingTurnLinePoint.easting = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].easting; - crossingTurnLinePoint.northing = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].northing; - crossingTurnLinePoint.heading = mf.bnd.bndArr[turnNum].turnLine[crossingTurnLinePoint.index].heading; + crossingTurnLinePoint.easting = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].easting; + crossingTurnLinePoint.northing = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].northing; + crossingTurnLinePoint.heading = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].heading; return crossingCurvePoint.easting != -20000 && crossingCurvePoint.easting != -20000; } @@ -584,15 +584,15 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; + if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j],ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; if (isOutOfBounds) break; - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndArr[i].isDriveThru) continue; - if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) { isOutOfBounds = true; break; @@ -644,16 +644,16 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) isOutOfBounds = true; + if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; if (isOutOfBounds) break; - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndArr[i].isDriveThru) continue; - if (mf.bnd.bndArr[i].isDriveAround) continue; - if (!mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (!mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) { isOutOfBounds = true; break; @@ -852,18 +852,18 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!mf.bnd.bndArr[0].IsPointInTurnWorkArea(ytList[j])) + if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) { isOutOfBounds = true; break; } - for (int i = 1; i < mf.bnd.bndArr.Count; i++) + for (int i = 1; i < mf.bnd.bndList.Count; i++) { //make sure not inside a non drivethru boundary - if (mf.bnd.bndArr[i].isDriveThru) continue; - if (mf.bnd.bndArr[i].isDriveAround) continue; - if (mf.bnd.bndArr[i].IsPointInTurnWorkArea(ytList[j])) + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[1].turnLine)) { isOutOfBounds = true; break; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index a609102c7..0c1cc25dc 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -355,7 +355,7 @@ private void btnAutoYouTurn_Click(object sender, EventArgs e) { yt.isTurnCreationTooClose = false; - if (bnd.bndArr.Count == 0) + if (bnd.bndList.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1494,7 +1494,7 @@ private void BtnMakeLinesFromBoundary_Click(object sender, EventArgs e) return; } - if (bnd.bndArr.Count == 0) + if (bnd.bndList.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1549,10 +1549,10 @@ private void cboxpRowWidth_SelectedIndexChanged(object sender, EventArgs e) private void btnHeadlandOnOff_Click(object sender, EventArgs e) { - if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) + if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) { - bnd.isOn = !bnd.isOn; - if (bnd.isOn) + bnd.isHeadlandOn = !bnd.isHeadlandOn; + if (bnd.isHeadlandOn) { btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHydLift.Visible = true; @@ -1563,9 +1563,9 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; } } - else bnd.isOn = false; + else bnd.isHeadlandOn = false; - if (!bnd.isOn) + if (!bnd.isHeadlandOn) { p_239.pgn[p_239.hydLift] = 0; vehicle.isHydLiftOn = false; @@ -1577,7 +1577,7 @@ private void btnHeadlandOnOff_Click(object sender, EventArgs e) private void btnHydLift_Click(object sender, EventArgs e) { - if (bnd.isOn) + if (bnd.isHeadlandOn) { vehicle.isHydLiftOn = !vehicle.isHydLiftOn; if (vehicle.isHydLiftOn) @@ -1959,7 +1959,7 @@ private void tramLinesMenuField_Click(object sender, EventArgs e) } private void headlandToolStripMenuItem_Click(object sender, EventArgs e) { - if (bnd.bndArr.Count == 0) + if (bnd.bndList.Count == 0) { TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst); return; @@ -1974,9 +1974,9 @@ public void GetHeadland() form.ShowDialog(); } - if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) + if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) { - bnd.isOn = true; + bnd.isHeadlandOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -1984,7 +1984,7 @@ public void GetHeadland() } else { - bnd.isOn = false; + bnd.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index 6121798e0..4718ceb52 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -59,7 +59,7 @@ private void UpdateChart() Font backupfont = new Font(Font.FontFamily, 18F, FontStyle.Bold); - for (int i = 0; i < mf.bnd.bndArr.Count && i < 6; i++) + for (int i = 0; i < mf.bnd.bndList.Count && i < 6; i++) { //outer inner Button a = new Button @@ -118,11 +118,11 @@ private void UpdateChart() if (i == 0) { //cc.Text = "Outer"; - mf.bnd.bndArr[i].isDriveThru = false; - mf.bnd.bndArr[i].isDriveAround = false; + mf.bnd.bndList[i].isDriveThru = false; + mf.bnd.bndList[i].isDriveAround = false; a.Text = string.Format(gStr.gsOuter); //a.Font = backupfont; - d.Text = mf.bnd.bndArr[i].isDriveThru ? "--" : "--"; + d.Text = mf.bnd.bndList[i].isDriveThru ? "--" : "--"; d.Enabled = false; d.Anchor = System.Windows.Forms.AnchorStyles.None; a.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -135,7 +135,7 @@ private void UpdateChart() inner += 1; a.Text = string.Format(gStr.gsInner + " {0}", inner); //a.Font = backupfont; - d.Text = mf.bnd.bndArr[i].isDriveThru ? "Yes" : "No"; + d.Text = mf.bnd.bndList[i].isDriveThru ? "Yes" : "No"; d.Anchor = System.Windows.Forms.AnchorStyles.None; a.Anchor = System.Windows.Forms.AnchorStyles.None; b.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -144,14 +144,14 @@ private void UpdateChart() if (mf.isMetric) { - b.Text = Math.Round(mf.bnd.bndArr[i].area * 0.0001, 2).ToString() + " Ha"; + b.Text = Math.Round(mf.bnd.bndList[i].area * 0.0001, 2).ToString() + " Ha"; } else { - b.Text = Math.Round(mf.bnd.bndArr[i].area * 0.000247105, 2) + " Ac"; + b.Text = Math.Round(mf.bnd.bndList[i].area * 0.000247105, 2) + " Ac"; } - if (Selectedreset == false && i == mf.bnd.boundarySelected) + if (Selectedreset == false && i == mf.bnd.fenceSelected) { a.ForeColor = Color.OrangeRed; b.ForeColor = Color.OrangeRed; @@ -168,7 +168,7 @@ private void DriveThru_Click(object sender, EventArgs e) { if (sender is Button b) { - mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveThru = !mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveThru; + mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveThru = !mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveThru; UpdateChart(); mf.bnd.BuildTurnLines(); } @@ -178,7 +178,7 @@ private void DriveAround_Click(object sender, EventArgs e) { if (sender is Button b) { - mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveAround = !mf.bnd.bndArr[Convert.ToInt32(b.Name)].isDriveAround; + mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround = !mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround; UpdateChart(); } } @@ -188,16 +188,16 @@ private void B_Click(object sender, EventArgs e) if (sender is Button b) { - mf.bnd.boundarySelected = Convert.ToInt32(b.Name); + mf.bnd.fenceSelected = Convert.ToInt32(b.Name); - if (mf.bnd.boundarySelected == 0 && mf.bnd.bndArr.Count > 1) + if (mf.bnd.fenceSelected == 0 && mf.bnd.bndList.Count > 1) { return; } Selectedreset = false; - if (mf.bnd.bndArr.Count > mf.bnd.boundarySelected) + if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) { btnDelete.Enabled = true; } @@ -229,14 +229,14 @@ private void btnDelete_Click(object sender, EventArgs e) btnDelete.Enabled = false; - if (mf.bnd.bndArr.Count > mf.bnd.boundarySelected) + if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) { - mf.bnd.bndArr.RemoveAt(mf.bnd.boundarySelected); + mf.bnd.bndList.RemoveAt(mf.bnd.fenceSelected); } mf.FileSaveBoundary(); - mf.bnd.boundarySelected = -1; + mf.bnd.fenceSelected = -1; Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); mf.bnd.BuildTurnLines(); @@ -250,7 +250,7 @@ private void btnDelete_Click(object sender, EventArgs e) private void ResetAllBoundary() { - mf.bnd.bndArr.Clear(); + mf.bnd.bndList.Clear(); mf.FileSaveBoundary(); tableLayoutPanel1.Controls.Clear(); tableLayoutPanel1.RowStyles.Clear(); @@ -282,7 +282,7 @@ private void btnDeleteAll_Click(object sender, EventArgs e) ResetAllBoundary(); - mf.bnd.boundarySelected = -1; + mf.bnd.fenceSelected = -1; Selectedreset = true; mf.bnd.isOkToAddPoints = false; @@ -310,7 +310,7 @@ private void btnReturn_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e) { - mf.bnd.boundarySelected = mf.bnd.bndArr.Count; + mf.bnd.fenceSelected = mf.bnd.bndList.Count; Selectedreset = false; @@ -353,7 +353,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) { if (button.Name == "btnLoadMultiBoundaryFromGE") ResetAllBoundary(); - else i = mf.bnd.boundarySelected; + else i = mf.bnd.fenceSelected; try { @@ -394,7 +394,7 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) //at least 3 points if (numberSets.Length > 2) { - CBoundaryLines New = new CBoundaryLines(); + CBoundaryList New = new CBoundaryList(); foreach (string item in numberSets) { @@ -405,13 +405,13 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) mf.pn.ConvertWGS84ToLocal(latK, lonK, out norting, out easting); //add the point to boundary - New.bndLine.Add(new vec3(easting, norting, 0)); + New.fenceLine.Add(new vec3(easting, norting, 0)); } - New.CalculateBoundaryArea(mf.bnd.boundarySelected); - New.FixBoundaryLine(i); + New.CalculateFenceArea(mf.bnd.fenceSelected); + New.FixFenceLine(i); - mf.bnd.bndArr.Add(New); + mf.bnd.bndList.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 3be336c6b..007aa0e2d 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -29,17 +29,17 @@ private void btnStop_Click(object sender, EventArgs e) { if (mf.bnd.bndBeingMadePts.Count > 2) { - CBoundaryLines New = new CBoundaryLines(); + CBoundaryList New = new CBoundaryList(); for (int i = 0; i < mf.bnd.bndBeingMadePts.Count; i++) { - New.bndLine.Add(mf.bnd.bndBeingMadePts[i]); + New.fenceLine.Add(mf.bnd.bndBeingMadePts[i]); } - New.CalculateBoundaryArea(mf.bnd.boundarySelected); - New.FixBoundaryLine(mf.bnd.boundarySelected); + New.CalculateFenceArea(mf.bnd.fenceSelected); + New.FixFenceLine(mf.bnd.fenceSelected); - mf.bnd.bndArr.Add(New); + mf.bnd.bndList.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); } diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 53cce9638..5b5a90d9c 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -125,7 +125,7 @@ private void LoadKMLBoundary(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.bnd.boundarySelected; + i = mf.bnd.fenceSelected; try { @@ -166,7 +166,7 @@ private void LoadKMLBoundary(string filename) //at least 3 points if (numberSets.Length > 2) { - CBoundaryLines New = new CBoundaryLines(); + CBoundaryList New = new CBoundaryList(); foreach (string item in numberSets) { @@ -179,14 +179,14 @@ private void LoadKMLBoundary(string filename) mf.pn.ConvertWGS84ToLocal(latK, lonK, out northing, out easting); //add the point to boundary - New.bndLine.Add(new vec3(easting, northing, 0)); + New.fenceLine.Add(new vec3(easting, northing, 0)); } //build the boundary, make sure is clockwise for outer counter clockwise for inner - New.CalculateBoundaryArea(mf.bnd.boundarySelected); - New.FixBoundaryLine(i); + New.CalculateFenceArea(mf.bnd.fenceSelected); + New.FixFenceLine(i); - mf.bnd.bndArr.Add(New); + mf.bnd.bndList.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); @@ -233,7 +233,7 @@ private void FindLatLon(string filename) using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.bnd.boundarySelected; + i = mf.bnd.fenceSelected; try { diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index 142809b11..b4487c1c0 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -979,7 +979,7 @@ public void JobClose() pn.fixOffset.northing = 0; //turn off headland - bnd.isOn = false; + bnd.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; @@ -993,7 +993,7 @@ public void JobClose() oglZoom.SendToBack(); //clean all the lines - bnd.bndArr.Clear(); + bnd.bndList.Clear(); panelRight.Enabled = false; FieldMenuButtonEnableDisable(false); diff --git a/SourceCode/GPS/Forms/FormHeadland.cs b/SourceCode/GPS/Forms/FormHeadland.cs index d4bc8e0dc..3bfcda0e0 100644 --- a/SourceCode/GPS/Forms/FormHeadland.cs +++ b/SourceCode/GPS/Forms/FormHeadland.cs @@ -54,10 +54,10 @@ private void FormHeadland_Load(object sender, EventArgs e) nudDistance.Value = 0; nudSetDistance.Value = 0; - if (mf.bnd.bndArr[0].hdLine.Count > 0) + if (mf.bnd.bndList[0].hdLine.Count > 0) { - hdArr = new vec3[mf.bnd.bndArr[0].hdLine.Count]; - mf.bnd.bndArr[0].hdLine.CopyTo(hdArr); + hdArr = new vec3[mf.bnd.bndList[0].hdLine.Count]; + mf.bnd.bndList[0].hdLine.CopyTo(hdArr); RebuildHeadLineTemplate(); } else @@ -80,13 +80,13 @@ public void BuildHeadLineTemplateFromBoundary() //outside boundary - count the points from the boundary headLineTemplate.Clear(); - int ptCount = mf.bnd.bndArr[0].bndLine.Count; + int ptCount = mf.bnd.bndList[0].fenceLine.Count; for (int i = ptCount - 1; i >= 0; i--) { //calculate the point inside the boundary - point.easting = mf.bnd.bndArr[0].bndLine[i].easting; - point.northing = mf.bnd.bndArr[0].bndLine[i].northing; - point.heading = mf.bnd.bndArr[0].bndLine[i].heading; + point.easting = mf.bnd.bndList[0].fenceLine[i].easting; + point.northing = mf.bnd.bndList[0].fenceLine[i].northing; + point.heading = mf.bnd.bndList[0].fenceLine[i].heading; headLineTemplate.Add(point); } @@ -334,7 +334,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) //else lblEnd.Text = end.ToString(); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.bnd.DrawFenceLines(); int ptCount = hdArr.Length; if (ptCount > 1) @@ -565,7 +565,7 @@ private void timer1_Tick(object sender, EventArgs e) private void btnExit_Click(object sender, EventArgs e) { - mf.bnd.bndArr[0].hdLine?.Clear(); + mf.bnd.bndList[0].hdLine?.Clear(); //middle points for (int i = 1; i < hdArr.Length; i++) @@ -580,7 +580,7 @@ private void btnExit_Click(object sender, EventArgs e) { if (i == 0) { - mf.bnd.bndArr[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); + mf.bnd.bndList[0].hdLine.Add(new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading)); continue; } delta += (hdArr[i - 1].heading - hdArr[i].heading); @@ -589,7 +589,7 @@ private void btnExit_Click(object sender, EventArgs e) { vec3 pt = new vec3(hdArr[i].easting, hdArr[i].northing, hdArr[i].heading); - mf.bnd.bndArr[0].hdLine.Add(pt); + mf.bnd.bndList[0].hdLine.Add(pt); delta = 0; } } @@ -600,7 +600,7 @@ private void btnExit_Click(object sender, EventArgs e) private void btnTurnOffHeadland_Click(object sender, EventArgs e) { - mf.bnd.bndArr[0].hdLine?.Clear(); + mf.bnd.bndList[0].hdLine?.Clear(); mf.FileSaveHeadland(); diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 10bc6cb2f..05b2ecc47 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -125,7 +125,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) // fd.WorkedAreaRemainPercentage +"\r\n" + // fd.TimeTillFinished + "\r\n" + // fd.WorkRateHectares; - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) lblFieldStatus.Text = fd.AreaBoundaryLessInnersHectares + " " + fd.WorkedAreaRemainHectares + " " + fd.TimeTillFinished + " " + fd.WorkedAreaRemainPercentage+" " @@ -136,7 +136,7 @@ private void tmrWatchdog_tick(object sender, EventArgs e) } else //imperial { - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) lblFieldStatus.Text = fd.AreaBoundaryLessInnersAcres + " " + fd.WorkedAreaRemainAcres + " " + fd.TimeTillFinished + " " + fd.WorkedAreaRemainPercentage + " " + fd.WorkedAcres; @@ -498,7 +498,7 @@ public void LoadSettings() if (Properties.Settings.Default.setAS_isAutoSteerAutoOn) btnAutoSteer.Text = "R"; else btnAutoSteer.Text = "M"; - if (bnd.isOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; + if (bnd.isHeadlandOn) btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; else btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnChangeMappingColor.BackColor = sectionColorDay; diff --git a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs index fc1e2270b..82c1a1c85 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABDraw.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABDraw.cs @@ -46,21 +46,21 @@ public FormABDraw(Form callingForm) private void FormABDraw_Load(object sender, EventArgs e) { - int cnt = mf.bnd.bndArr[0].bndLine.Count; + int cnt = mf.bnd.bndList[0].fenceLine.Count; arr = new vec3[cnt * 2]; for (int i = 0; i < cnt; i++) { - arr[i].easting = mf.bnd.bndArr[0].bndLine[i].easting; - arr[i].northing = mf.bnd.bndArr[0].bndLine[i].northing; - arr[i].heading = mf.bnd.bndArr[0].bndLine[i].heading; + arr[i].easting = mf.bnd.bndList[0].fenceLine[i].easting; + arr[i].northing = mf.bnd.bndList[0].fenceLine[i].northing; + arr[i].heading = mf.bnd.bndList[0].fenceLine[i].heading; } for (int i = cnt; i < cnt * 2; i++) { - arr[i].easting = mf.bnd.bndArr[0].bndLine[i - cnt].easting; - arr[i].northing = mf.bnd.bndArr[0].bndLine[i - cnt].northing; - arr[i].heading = mf.bnd.bndArr[0].bndLine[i - cnt].heading; + arr[i].easting = mf.bnd.bndList[0].fenceLine[i - cnt].easting; + arr[i].northing = mf.bnd.bndList[0].fenceLine[i - cnt].northing; + arr[i].heading = mf.bnd.bndList[0].fenceLine[i - cnt].heading; } nudDistance.Value = (decimal)Math.Round(((mf.tool.toolWidth * mf.m2InchOrCm) * 0.5), 0); // @@ -356,7 +356,7 @@ private void oglSelf_MouseDown(object sender, MouseEventArgs e) private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) { //count the points from the boundary - int ptCount = mf.bnd.bndArr[0].bndLine.Count; + int ptCount = mf.bnd.bndList[0].fenceLine.Count; mf.curve.refList?.Clear(); //outside point @@ -369,20 +369,20 @@ private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) for (int i = 0; i < ptCount; i++) { //calculate the point inside the boundary - pt3.easting = mf.bnd.bndArr[0].bndLine[i].easting - - (Math.Sin(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (moveDist)); + pt3.easting = mf.bnd.bndList[0].fenceLine[i].easting - + (Math.Sin(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (moveDist)); - pt3.northing = mf.bnd.bndArr[0].bndLine[i].northing - - (Math.Cos(glm.PIBy2 + mf.bnd.bndArr[0].bndLine[i].heading) * (moveDist)); + pt3.northing = mf.bnd.bndList[0].fenceLine[i].northing - + (Math.Cos(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (moveDist)); - pt3.heading = mf.bnd.bndArr[0].bndLine[i].heading; + pt3.heading = mf.bnd.bndList[0].fenceLine[i].heading; bool Add = true; for (int j = 0; j < ptCount; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, - mf.bnd.bndArr[0].bndLine[j].northing, mf.bnd.bndArr[0].bndLine[j].easting); + mf.bnd.bndList[0].fenceLine[j].northing, mf.bnd.bndList[0].fenceLine[j].easting); if (check < distSq) { Add = false; @@ -669,7 +669,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.bnd.DrawFenceLines(); //the vehicle GL.PointSize(16.0f); diff --git a/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs b/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs index 9d182e165..2d05e3c58 100644 --- a/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs +++ b/SourceCode/GPS/Forms/Guidance/FormMakeBndCon.cs @@ -24,7 +24,7 @@ public FormMakeBndCon(Form _mf) private void BtnOk_Click(object sender, System.EventArgs e) { //convert to meters - mf.ct.BuildBoundaryContours((int)nudPass.Value, (int)(nudSpacing.Value * 0.01m)); + mf.ct.BuildFenceContours((int)nudPass.Value, (int)(nudSpacing.Value * 0.01m)); Close(); } diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index e9d953000..945fa1975 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -338,7 +338,7 @@ private void oglMain_Paint(object sender, PaintEventArgs e) recPath.DrawDubins(); //draw Boundaries - bnd.DrawBoundaryLines(); + bnd.DrawFenceLines(); //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) @@ -346,13 +346,13 @@ private void oglMain_Paint(object sender, PaintEventArgs e) bnd.DrawTurnLines(); } - if (bnd.isOn) + if (bnd.isHeadlandOn) { GL.LineWidth(ABLine.lineWidth); GL.Color3(0.960f, 0.96232f, 0.30f); - for (int i = 0; i < bnd.bndArr.Count; i++) + for (int i = 0; i < bnd.bndList.Count; i++) { - if (bnd.bndArr[i].hdLine.Count > 0) bnd.bndArr[i].DrawHeadLine(); + if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLine(); } } @@ -416,7 +416,7 @@ private void oglMain_Paint(object sender, PaintEventArgs e) if ((ahrs.imuRoll != 88888)) DrawRollBar(); - if (bnd.bndArr.Count > 0 && yt.isYouTurnBtnOn) DrawUTurnBtn(); + if (bnd.bndList.Count > 0 && yt.isYouTurnBtnOn) DrawUTurnBtn(); if (isAutoSteerBtnOn && !ct.isContourBtnOn) DrawManUTurnBtn(); @@ -616,29 +616,29 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //draw 240 green for boundary - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) { ////draw the bnd line - int ptCount = bnd.bndArr[0].bndLine.Count; + int ptCount = bnd.bndList[0].fenceLine.Count; if (ptCount > 3) { GL.LineWidth(3); GL.Color3((byte)0, (byte)240, (byte)0); GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < ptCount; h++) GL.Vertex3(bnd.bndArr[0].bndLine[h].easting, bnd.bndArr[0].bndLine[h].northing, 0); + for (int h = 0; h < ptCount; h++) GL.Vertex3(bnd.bndList[0].fenceLine[h].easting, bnd.bndList[0].fenceLine[h].northing, 0); GL.End(); } } //draw 250 green for the headland - if (bnd.isOn) + if (bnd.isHeadlandOn) { GL.LineWidth(3); GL.Color3((byte)0, (byte)250, (byte)0); - for (int i = 0; i < bnd.bndArr.Count; i++) + for (int i = 0; i < bnd.bndList.Count; i++) { - if (bnd.bndArr[i].hdLine.Count > 0) bnd.bndArr[i].DrawHeadLineBackBuffer(); + if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLineBackBuffer(); } } @@ -677,7 +677,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tool.numOfSections == 1 || pn.speed < vehicle.slowSpeedCutoff) tool.isSuperSectionAllowedOn = false; - if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && bnd.isOn) + if ((tool.isRightSideInHeadland || tool.isLeftSideInHeadland) && bnd.isHeadlandOn) tool.isSuperSectionAllowedOn = false; //clamp the height after looking way ahead, this is for switching off super section only @@ -687,7 +687,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //10 % min is required for overlap, otherwise it never would be on. int pixLimit = (int)((double)(section[0].rpSectionWidth * rpOnHeight) / (double)(5.0)); - if ((rpOnHeight < rpToolHeight && bnd.isOn)) rpHeight = rpToolHeight + 2; + if ((rpOnHeight < rpToolHeight && bnd.isHeadlandOn)) rpHeight = rpToolHeight + 2; else rpHeight = rpOnHeight + 2; if (rpHeight > 290) rpHeight = 290; @@ -712,7 +712,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (!tool.isMultiColoredSections) { - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) { //are there enough pixels in buffer array to warrant turning off supersection for (int a = 0; a < (tool.rpWidth * rpOnHeight); a++) @@ -749,7 +749,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //determine if in or out of headland, do hydraulics if on - if (bnd.isOn) + if (bnd.isHeadlandOn) { //calculate the slope double m = (vehicle.hydLiftLookAheadDistanceRight - vehicle.hydLiftLookAheadDistanceLeft) / tool.rpWidth; @@ -923,7 +923,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) if (tagged == 0) section[j].isMappingRequiredOn = false; } - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) { //if out of boundary, turn it off if (!section[j].isInBoundary) @@ -935,7 +935,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) section[j].mappingOnTimer = 0; } - else if (section[j].isInHeadlandArea & bnd.isOn) + else if (section[j].isInHeadlandArea & bnd.isHeadlandOn) { // if headland is on and out, turn off section[j].isMappingRequiredOn = false; @@ -950,7 +950,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) /////////////////////////////////////////// Section control ssssssssssssssssssssss /// - if (bnd.isOn) bnd.WhereAreToolLookOnPoints(); + if (bnd.isHeadlandOn) bnd.WhereAreToolLookOnPoints(); for (int j = 0; j < tool.numOfSections; j++) { @@ -958,7 +958,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) //ensure it starts off section[j].isSectionRequiredOn = false; - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) { //if out of boundary, turn it off if (!section[j].isInBoundary) @@ -1013,7 +1013,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) } //is headland coming up - if (bnd.isOn) + if (bnd.isHeadlandOn) { bool isHeadlandInLookOn = false; @@ -1502,7 +1502,7 @@ private void oglZoom_Paint(object sender, PaintEventArgs e) } //draw all the boundaries - bnd.DrawBoundaryLines(); + bnd.DrawFenceLines(); GL.PointSize(8.0f); GL.Begin(PrimitiveType.Points); @@ -2385,13 +2385,13 @@ public void CalculateMinMax() //min max of the boundary //min max of the boundary - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) { - int bndCnt = bnd.bndArr[0].bndLine.Count; + int bndCnt = bnd.bndList[0].fenceLine.Count; for (int i = 0; i < bndCnt; i++) { - double x = bnd.bndArr[0].bndLine[i].easting; - double y = bnd.bndArr[0].bndLine[i].northing; + double x = bnd.bndList[0].fenceLine[i].easting; + double y = bnd.bndList[0].fenceLine[i].northing; //also tally the max/min of field x and z if (minFieldX > x) minFieldX = x; @@ -2481,7 +2481,7 @@ private void DrawFieldText() { if (isMetric) { - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) { sb.Clear(); sb.Append(((fd.workedAreaTotal - fd.actualAreaCovered) * glm.m2ha).ToString("N3")); @@ -2512,7 +2512,7 @@ private void DrawFieldText() } else { - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) { sb.Clear(); sb.Append(((fd.workedAreaTotal - fd.actualAreaCovered) * glm.m2ac).ToString("N3")); diff --git a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs index cd7e1b6fb..5d1e7a98c 100644 --- a/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs +++ b/SourceCode/GPS/Forms/Pickers/FormTouchPick.cs @@ -122,7 +122,7 @@ private void oglSelf_Paint(object sender, PaintEventArgs e) GL.Color3(1, 1, 1); //draw all the boundaries - mf.bnd.DrawBoundaryLines(); + mf.bnd.DrawFenceLines(); GL.Flush(); oglSelf.SwapBuffers(); diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index b0f06a281..b046d7aed 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -707,10 +707,10 @@ public void UpdateFixPosition() mc.isOutOfBounds = true; //if an outer boundary is set, then apply critical stop logic - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (bnd.IsInsideGeoFenceAKABoundary(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (bnd.IsInsideAllFences(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; @@ -1238,7 +1238,7 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (tool.lookAheadDistanceOffPixelsRight > 160) tool.lookAheadDistanceOffPixelsRight = 160; //determine where the tool is wrt to headland - if (bnd.isOn) bnd.WhereAreToolCorners(); + if (bnd.isHeadlandOn) bnd.WhereAreToolCorners(); //set up the super for youturn section[tool.numOfSections].isInBoundary = true; @@ -1248,19 +1248,19 @@ public void CalculateSectionLookAhead(double northing, double easting, double co for (int j = 0; j < tool.numOfSections; j++) { - if (bnd.bndArr.Count > 0) + if (bnd.bndList.Count > 0) { if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftIn = bnd.bndArr[0].IsPointInsideBoundaryEar(section[j].leftPoint); - isRightIn = bnd.bndArr[0].IsPointInsideBoundaryEar(section[j].rightPoint); + isLeftIn = bnd.bndList[0].IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[0].fenceLineEar); + isRightIn = bnd.bndList[0].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); - for (int i = 1; i < bnd.bndArr.Count; i++) + for (int i = 1; i < bnd.bndList.Count; i++) { //inner boundaries should normally NOT have point inside - isLeftIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].leftPoint); - isRightIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].rightPoint); + isLeftIn &= !bnd.bndList[i].IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[i].fenceLineEar); + isRightIn &= !bnd.bndList[i].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); } //merge the two sides into in or out @@ -1272,11 +1272,11 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { //grab the right of previous section, its the left of this section isLeftIn = isRightIn; - isRightIn = bnd.bndArr[0].IsPointInsideBoundaryEar(section[j].rightPoint); - for (int i = 1; i < bnd.bndArr.Count; i++) + isRightIn = bnd.bndList[0].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); + for (int i = 1; i < bnd.bndList.Count; i++) { //inner boundaries should normally NOT have point inside - isRightIn &= !bnd.bndArr[i].IsPointInsideBoundaryEar(section[j].rightPoint); + isRightIn &= !bnd.bndList[i].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); } if (isLeftIn && isRightIn) section[j].isInBoundary = true; diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index 5e0892f09..f04c1bc4d 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -683,7 +683,7 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - CBoundaryLines New = new CBoundaryLines(); + CBoundaryList New = new CBoundaryList(); //True or False OR points from older boundary files line = reader.ReadLine(); @@ -716,36 +716,36 @@ public void FileOpenField(string _openType) double.Parse(words[1], CultureInfo.InvariantCulture), double.Parse(words[2], CultureInfo.InvariantCulture)); - New.bndLine.Add(vecPt); + New.fenceLine.Add(vecPt); } - New.CalculateBoundaryArea(k); + New.CalculateFenceArea(k); double delta = 0; - New.bndLineEar?.Clear(); + New.fenceLineEar?.Clear(); - for (int i = 0; i < New.bndLine.Count; i++) + for (int i = 0; i < New.fenceLine.Count; i++) { if (i == 0) { - New.bndLineEar.Add(new vec2(New.bndLine[i].easting, New.bndLine[i].northing)); + New.fenceLineEar.Add(new vec2(New.fenceLine[i].easting, New.fenceLine[i].northing)); continue; } - delta += (New.bndLine[i - 1].heading - New.bndLine[i].heading); + delta += (New.fenceLine[i - 1].heading - New.fenceLine[i].heading); if (Math.Abs(delta) > 0.04) { - New.bndLineEar.Add(new vec2(New.bndLine[i].easting, New.bndLine[i].northing)); + New.fenceLineEar.Add(new vec2(New.fenceLine[i].easting, New.fenceLine[i].northing)); delta = 0; } } - bnd.bndArr.Add(New); + bnd.bndList.Add(New); } } CalculateMinMax(); bnd.BuildTurnLines(); - if (bnd.bndArr.Count > 0) btnMakeLinesFromBoundary.Visible = true; + if (bnd.bndList.Count > 0) btnMakeLinesFromBoundary.Visible = true; } catch (Exception e) @@ -773,9 +773,9 @@ public void FileOpenField(string _openType) { if (reader.EndOfStream) break; - if (bnd.bndArr.Count > k) + if (bnd.bndList.Count > k) { - bnd.bndArr[k].hdLine.Clear(); + bnd.bndList[k].hdLine.Clear(); //read the number of points line = reader.ReadLine(); @@ -792,7 +792,7 @@ public void FileOpenField(string _openType) double.Parse(words[0], CultureInfo.InvariantCulture), double.Parse(words[1], CultureInfo.InvariantCulture), double.Parse(words[2], CultureInfo.InvariantCulture)); - bnd.bndArr[k].hdLine.Add(vecPt); + bnd.bndList[k].hdLine.Add(vecPt); } } } @@ -808,9 +808,9 @@ public void FileOpenField(string _openType) } } - if (bnd.bndArr.Count > 0 && bnd.bndArr[0].hdLine.Count > 0) + if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) { - bnd.isOn = true; + bnd.isHeadlandOn = true; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn; btnHeadlandOnOff.Visible = true; btnHydLift.Visible = true; @@ -819,7 +819,7 @@ public void FileOpenField(string _openType) } else { - bnd.isOn = false; + bnd.isHeadlandOn = false; btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff; btnHeadlandOnOff.Visible = false; btnHydLift.Visible = false; @@ -1209,19 +1209,19 @@ public void FileSaveBoundary() using (StreamWriter writer = new StreamWriter(dirField + "Boundary.Txt")) { writer.WriteLine("$Boundary"); - for (int i = 0; i < bnd.bndArr.Count; i++) + for (int i = 0; i < bnd.bndList.Count; i++) { - writer.WriteLine(bnd.bndArr[i].isDriveThru); - writer.WriteLine(bnd.bndArr[i].isDriveAround); + writer.WriteLine(bnd.bndList[i].isDriveThru); + writer.WriteLine(bnd.bndList[i].isDriveAround); //writer.WriteLine(bnd.bndArr[i].isOwnField); - writer.WriteLine(bnd.bndArr[i].bndLine.Count.ToString(CultureInfo.InvariantCulture)); - if (bnd.bndArr[i].bndLine.Count > 0) + writer.WriteLine(bnd.bndList[i].fenceLine.Count.ToString(CultureInfo.InvariantCulture)); + if (bnd.bndList[i].fenceLine.Count > 0) { - for (int j = 0; j < bnd.bndArr[i].bndLine.Count; j++) - writer.WriteLine(Math.Round(bnd.bndArr[i].bndLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndArr[i].bndLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndArr[i].bndLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < bnd.bndList[i].fenceLine.Count; j++) + writer.WriteLine(Math.Round(bnd.bndList[i].fenceLine[j].easting,3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndList[i].fenceLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndList[i].fenceLine[j].heading,5).ToString(CultureInfo.InvariantCulture)); } } } @@ -1295,17 +1295,17 @@ public void FileSaveHeadland() { writer.WriteLine("$Headland"); - if (bnd.bndArr[0].hdLine.Count > 0) + if (bnd.bndList[0].hdLine.Count > 0) { - for (int i = 0; i < bnd.bndArr.Count; i++) + for (int i = 0; i < bnd.bndList.Count; i++) { - writer.WriteLine(bnd.bndArr[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); - if (bnd.bndArr[0].hdLine.Count > 0) + writer.WriteLine(bnd.bndList[i].hdLine.Count.ToString(CultureInfo.InvariantCulture)); + if (bnd.bndList[0].hdLine.Count > 0) { - for (int j = 0; j < bnd.bndArr[i].hdLine.Count; j++) - writer.WriteLine(Math.Round(bnd.bndArr[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndArr[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + - Math.Round(bnd.bndArr[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); + for (int j = 0; j < bnd.bndList[i].hdLine.Count; j++) + writer.WriteLine(Math.Round(bnd.bndList[i].hdLine[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndList[i].hdLine[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + + Math.Round(bnd.bndList[i].hdLine[j].heading, 3).ToString(CultureInfo.InvariantCulture)); } } } @@ -1678,7 +1678,7 @@ public void FileSaveFieldKML() kml.WriteStartElement("Folder"); kml.WriteElementString("name", "Boundaries"); - for (int i = 0; i < bnd.bndArr.Count; i++) + for (int i = 0; i < bnd.bndList.Count; i++) { kml.WriteStartElement("Placemark"); if (i == 0) kml.WriteElementString("name", currentFieldDirectory); @@ -1705,7 +1705,7 @@ public void FileSaveFieldKML() //coords kml.WriteStartElement("coordinates"); string bndPts = ""; - if (bnd.bndArr[i].bndLine.Count > 3) + if (bnd.bndList[i].fenceLine.Count > 3) bndPts = GetBoundaryPointsLatLon(i); kml.WriteRaw(bndPts); kml.WriteEndElement(); // @@ -1949,12 +1949,12 @@ public string GetBoundaryPointsLatLon(int bndNum) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < bnd.bndArr[bndNum].bndLine.Count; i++) + for (int i = 0; i < bnd.bndList[bndNum].fenceLine.Count; i++) { double lat = 0; double lon = 0; - pn.ConvertLocalToWGS84(bnd.bndArr[bndNum].bndLine[i].northing, bnd.bndArr[bndNum].bndLine[i].easting, out lat, out lon); + pn.ConvertLocalToWGS84(bnd.bndList[bndNum].fenceLine[i].northing, bnd.bndList[bndNum].fenceLine[i].easting, out lat, out lon); sb.Append(lon.ToString("N7", CultureInfo.InvariantCulture) + ',' + lat.ToString("N7", CultureInfo.InvariantCulture) + ",0 "); } From 7d6c36f763e21d0166b4c92bed737bd865713d9b Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Tue, 26 Oct 2021 23:54:47 -0600 Subject: [PATCH 11/18] Static glm.isPointInPolygon --- SourceCode/GPS/Classes/CABCurve.cs | 8 +- SourceCode/GPS/Classes/CABLine.cs | 4 +- SourceCode/GPS/Classes/CBoundaryList.cs | 82 --------------- SourceCode/GPS/Classes/CFence.cs | 4 +- SourceCode/GPS/Classes/CGLM.cs | 123 +++++++++++++--------- SourceCode/GPS/Classes/CHead.cs | 10 +- SourceCode/GPS/Classes/CTurn.cs | 6 +- SourceCode/GPS/Classes/CYouTurn.cs | 20 ++-- SourceCode/GPS/Forms/Position.designer.cs | 12 +-- 9 files changed, 103 insertions(+), 166 deletions(-) diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index 7cb578218..17ea9d2d4 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -735,7 +735,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar )) + if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar )) { mf.tram.tramArr.Add(point); } @@ -744,7 +744,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) + if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -816,7 +816,7 @@ public void BuildTram() if (dist > 2) { //if inside the boundary, add - if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) + if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } @@ -825,7 +825,7 @@ public void BuildTram() else { //need a first point to do distance - if (mf.bnd.bndList[0].IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) + if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(point); } diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index 1b86caec5..df7fbbd1a 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -495,7 +495,7 @@ public void BuildTram() if (isBndExist) { - if (mf.bnd.bndList[0].IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) + if (glm.IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(P1); } @@ -523,7 +523,7 @@ public void BuildTram() if (isBndExist) { - if (mf.bnd.bndList[0].IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) + if (glm.IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) { mf.tram.tramArr.Add(P1); } diff --git a/SourceCode/GPS/Classes/CBoundaryList.cs b/SourceCode/GPS/Classes/CBoundaryList.cs index 8d8eee844..0b52a3b28 100644 --- a/SourceCode/GPS/Classes/CBoundaryList.cs +++ b/SourceCode/GPS/Classes/CBoundaryList.cs @@ -20,87 +20,5 @@ public CBoundaryList() isDriveAround = false; isDriveThru = false; } - - public bool IsPointInPolygon(vec3 testPoint, ref List polygon) - { - bool result = false; - int j = polygon.Count - 1; - for (int i = 0; i < polygon.Count; i++) - { - if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) - || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) - { - if (polygon[i].northing + (testPoint.easting - polygon[i].easting) - / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) - < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - - public bool IsPointInPolygon(vec2 testPoint, ref List polygon) - { - bool result = false; - int j = polygon.Count - 1; - for (int i = 0; i < polygon.Count; i++) - { - if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) - || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) - { - if (polygon[i].northing + (testPoint.easting - polygon[i].easting) - / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) - < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - public bool IsPointInPolygon(vec2 testPoint, ref List polygon) - { - bool result = false; - int j = polygon.Count - 1; - for (int i = 0; i < polygon.Count; i++) - { - if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) - || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) - { - if (polygon[i].northing + (testPoint.easting - polygon[i].easting) - / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) - < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } - public bool IsPointInPolygon(vec3 testPoint, ref List polygon) - { - bool result = false; - int j = polygon.Count - 1; - for (int i = 0; i < polygon.Count; i++) - { - if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) - || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) - { - if (polygon[i].northing + (testPoint.easting - polygon[i].easting) - / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) - < testPoint.northing) - { - result = !result; - } - } - j = i; - } - return result; - } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs index 1185efd2c..3a18c4588 100644 --- a/SourceCode/GPS/Classes/CFence.cs +++ b/SourceCode/GPS/Classes/CFence.cs @@ -24,13 +24,13 @@ public partial class CBoundary public bool IsInsideAllFences(vec3 testPoint) { //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (bndList[0].IsPointInPolygon(testPoint, ref bndList[0].fenceLine)) + if (glm.IsPointInPolygon(testPoint, ref bndList[0].fenceLine)) { for (int i = 1; i < bndList.Count; i++) { //make sure not inside a non drivethru boundary if (bndList[i].isDriveThru) continue; - if (bndList[i].IsPointInPolygon(testPoint, ref bndList[i].fenceLine)) + if (glm.IsPointInPolygon(testPoint, ref bndList[i].fenceLine)) { return false; } diff --git a/SourceCode/GPS/Classes/CGLM.cs b/SourceCode/GPS/Classes/CGLM.cs index 3480ef789..ea5a52bbc 100644 --- a/SourceCode/GPS/Classes/CGLM.cs +++ b/SourceCode/GPS/Classes/CGLM.cs @@ -1,74 +1,93 @@ using System; +using System.Collections.Generic; using System.Windows.Forms; namespace AgOpenGPS { - public static class NudChk + public static class glm { - public static bool CheckValue(this NumericUpDown numericUpDown, ref decimal value) + public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) { - if (value < numericUpDown.Minimum) + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) { - value = numericUpDown.Minimum; - MessageBox.Show("Serious Settings Problem with - " + numericUpDown.Name - + " \n\rMinimum has been exceeded\n\rDouble check ALL your Settings and \n\rFix it and Resave Vehicle File", - "Critical Settings Warning", - MessageBoxButtons.OK, - MessageBoxIcon.Error); - return true; + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; } - else if (value > numericUpDown.Maximum) + return result; + } + + public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) + { + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) { - value = numericUpDown.Maximum; - MessageBox.Show("Serious Settings Problem with - " + numericUpDown.Name - + " \n\rMaximum has been exceeded\n\rDouble check ALL your Settings and \n\rFix it and Resave Vehicle File", - "Critical Settings Warning", - MessageBoxButtons.OK, - MessageBoxIcon.Error); - return true; + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; } - - //value is ok - return false; + return result; } - - public static bool CheckValueCm(this NumericUpDown numericUpDown, ref double value) + public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) { - //convert to cm - value *= 100; - bool isChanged = false; - - if (value < (double)numericUpDown.Minimum) + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) { - value = (double)numericUpDown.Minimum / 2.4; - MessageBox.Show("Serious Settings Problem with - " + numericUpDown.Name - + " \n\rMinimum has been exceeded\n\rDouble check ALL your Settings and \n\rFix it and Resave Vehicle File", - "Critical Settings Warning", - MessageBoxButtons.OK, - MessageBoxIcon.Error); - isChanged = true; + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; } - else if (value > (double)numericUpDown.Maximum) + return result; + } + public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) + { + bool result = false; + int j = polygon.Count - 1; + for (int i = 0; i < polygon.Count; i++) { - value = (double)numericUpDown.Maximum / 2.6; - MessageBox.Show("Serious Settings Problem with - " + numericUpDown.Name - + " \n\rMaximum has been exceeded\n\rDouble check ALL your Settings and \n\rFix it and Resave Vehicle File", - "Critical Settings Warning", - MessageBoxButtons.OK, - MessageBoxIcon.Error); - isChanged = true; + if ((polygon[i].easting < testPoint.easting && polygon[j].easting >= testPoint.easting) + || (polygon[j].easting < testPoint.easting && polygon[i].easting >= testPoint.easting)) + { + if (polygon[i].northing + (testPoint.easting - polygon[i].easting) + / (polygon[j].easting - polygon[i].easting) * (polygon[j].northing - polygon[i].northing) + < testPoint.northing) + { + result = !result; + } + } + j = i; } - - //revert back to meters - value *= 0.01; - - //value is ok - return isChanged; + return result; } - } - public static class glm - { // Catmull Rom interpoint spline calculation public static vec3 Catmull(double t, vec3 p0, vec3 p1, vec3 p2, vec3 p3) { diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index 70a878318..08dcdae02 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -48,8 +48,8 @@ public void WhereAreToolCorners() if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftInWk = bndList[0].IsPointInPolygon(mf.section[j].leftPoint, ref bndList[0].hdLine); - isRightInWk = bndList[0].IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); + isLeftInWk = glm.IsPointInPolygon(mf.section[j].leftPoint, ref bndList[0].hdLine); + isRightInWk = glm.IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); //save left side mf.tool.isLeftSideInHeadland = !isLeftInWk; @@ -62,7 +62,7 @@ public void WhereAreToolCorners() { //grab the right of previous section, its the left of this section isLeftInWk = isRightInWk; - isRightInWk = bndList[0].IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); + isRightInWk = glm.IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } @@ -129,11 +129,11 @@ public void WhereAreToolLookOnPoints() public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add - if (bndList.Count > 0 && bndList[0].IsPointInPolygon(pt, ref bndList[0].hdLine)) + if (bndList.Count > 0 && glm.IsPointInPolygon(pt, ref bndList[0].hdLine)) { for (int b = 1; b < bndList.Count; b++) { - if (bndList[b].IsPointInPolygon(pt, ref bndList[b].hdLine)) + if (glm.IsPointInPolygon(pt, ref bndList[b].hdLine)) { //point is in an inner turn area but inside outer return false; diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index 9ed0738f7..2dc00743c 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -38,13 +38,13 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (bndList[0].IsPointInPolygon(pt, ref bndList[0].turnLine)) + if (glm.IsPointInPolygon(pt, ref bndList[0].turnLine)) { for (int t = 1; t < bndList.Count; t++) { if (bndList[t].isDriveThru) continue; if (bndList[t].isDriveAround) continue; - if (bndList[t].IsPointInPolygon(pt, ref bndList[t].turnLine)) + if (glm.IsPointInPolygon(pt, ref bndList[t].turnLine)) { isFound = true; closestTurnNum = t; @@ -239,7 +239,7 @@ public void BuildTurnLines() if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == bndList[j].IsPointInPolygon(point, ref bndList[j].fenceLineEar)) + if (j == 0 == glm.IsPointInPolygon(point, ref bndList[j].fenceLineEar)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); bndList[j].turnLine.Add(tPnt); diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index 00fb32256..df0268fdb 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -115,7 +115,7 @@ public bool FindCurveTurnPoints() //for each point in succession keep going till a turnLine is found. for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) { - if (!mf.bnd.bndList[0].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) + if (!glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -130,7 +130,7 @@ public bool FindCurveTurnPoints() //make sure not inside a non drivethru boundary if (mf.bnd.bndList[i].isDriveThru) continue; if (mf.bnd.bndList[i].isDriveAround) continue; - if (mf.bnd.bndList[i].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) + if (glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) { crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; @@ -152,7 +152,7 @@ public bool FindCurveTurnPoints() for (int j = mf.curve.currentLocationIndex; j > 0; j--) { - if (!mf.bnd.bndList[0].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) + if (!glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) { //it passed outer turnLine crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; @@ -167,7 +167,7 @@ public bool FindCurveTurnPoints() //make sure not inside a non drivethru boundary if (mf.bnd.bndList[i].isDriveThru) continue; if (mf.bnd.bndList[i].isDriveAround) continue; - if (mf.bnd.bndList[i].IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) + if (glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) { crossingCurvePoint.easting = mf.curve.curList[j].easting; crossingCurvePoint.northing = mf.curve.curList[j].northing; @@ -584,7 +584,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j],ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; + if (!glm.IsPointInPolygon(ytList[j],ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; if (isOutOfBounds) break; for (int i = 1; i < mf.bnd.bndList.Count; i++) @@ -592,7 +592,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) //make sure not inside a non drivethru boundary if (mf.bnd.bndList[i].isDriveThru) continue; if (mf.bnd.bndList[i].isDriveAround) continue; - if (mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) + if (glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) { isOutOfBounds = true; break; @@ -644,7 +644,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; + if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; if (isOutOfBounds) break; @@ -653,7 +653,7 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) //make sure not inside a non drivethru boundary if (mf.bnd.bndList[i].isDriveThru) continue; if (mf.bnd.bndList[i].isDriveAround) continue; - if (!mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) + if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) { isOutOfBounds = true; break; @@ -852,7 +852,7 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!mf.bnd.bndList[0].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) + if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) { isOutOfBounds = true; break; @@ -863,7 +863,7 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) //make sure not inside a non drivethru boundary if (mf.bnd.bndList[i].isDriveThru) continue; if (mf.bnd.bndList[i].isDriveAround) continue; - if (mf.bnd.bndList[i].IsPointInPolygon(ytList[j], ref mf.bnd.bndList[1].turnLine)) + if (glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[1].turnLine)) { isOutOfBounds = true; break; diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index b046d7aed..fef8e4128 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -1253,14 +1253,14 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (j == 0) { //only one first left point, the rest are all rights moved over to left - isLeftIn = bnd.bndList[0].IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[0].fenceLineEar); - isRightIn = bnd.bndList[0].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); + isLeftIn = glm.IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[0].fenceLineEar); + isRightIn = glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); for (int i = 1; i < bnd.bndList.Count; i++) { //inner boundaries should normally NOT have point inside - isLeftIn &= !bnd.bndList[i].IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[i].fenceLineEar); - isRightIn &= !bnd.bndList[i].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); + isLeftIn &= !glm.IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[i].fenceLineEar); + isRightIn &= !glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); } //merge the two sides into in or out @@ -1272,11 +1272,11 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { //grab the right of previous section, its the left of this section isLeftIn = isRightIn; - isRightIn = bnd.bndList[0].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); + isRightIn = glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); for (int i = 1; i < bnd.bndList.Count; i++) { //inner boundaries should normally NOT have point inside - isRightIn &= !bnd.bndList[i].IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); + isRightIn &= !glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); } if (isLeftIn && isRightIn) section[j].isInBoundary = true; From 51e3e51af03610b3546778ce3fe3dd9d8fd9b706 Mon Sep 17 00:00:00 2001 From: p00qwerty Gamer Date: Wed, 27 Oct 2021 14:39:08 +0200 Subject: [PATCH 12/18] Code Cleanup --- SourceCode/GPS/AgOpenGPS.csproj | 3 - SourceCode/GPS/Classes/CABCurve.cs | 91 ++------ SourceCode/GPS/Classes/CABLine.cs | 18 +- SourceCode/GPS/Classes/CBoundary.cs | 6 +- SourceCode/GPS/Classes/CBoundaryList.cs | 6 +- SourceCode/GPS/Classes/CContour.cs | 18 +- SourceCode/GPS/Classes/CFence.cs | 130 ++++-------- SourceCode/GPS/Classes/CFenceLine.cs | 44 +--- SourceCode/GPS/Classes/CGLM.cs | 27 ++- SourceCode/GPS/Classes/CHead.cs | 113 +++------- SourceCode/GPS/Classes/CHeadLines.cs | 34 --- SourceCode/GPS/Classes/CSection.cs | 25 +-- SourceCode/GPS/Classes/CTurn.cs | 73 +++---- SourceCode/GPS/Classes/CTurnLines.cs | 41 +--- SourceCode/GPS/Classes/CYouTurn.cs | 209 ++++--------------- SourceCode/GPS/Forms/Controls.Designer.cs | 220 ++++---------------- SourceCode/GPS/Forms/FormBoundary.cs | 71 ++----- SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 19 +- SourceCode/GPS/Forms/FormFieldKML.cs | 18 +- SourceCode/GPS/Forms/FormGPS.Designer.cs | 1 + SourceCode/GPS/Forms/FormGPS.cs | 27 +-- SourceCode/GPS/Forms/FormJob.cs | 2 +- SourceCode/GPS/Forms/GUI.Designer.cs | 3 - SourceCode/GPS/Forms/Guidance/FormABLine.cs | 4 +- SourceCode/GPS/Forms/Guidance/FormEditAB.cs | 3 +- SourceCode/GPS/Forms/OpenGL.Designer.cs | 16 +- SourceCode/GPS/Forms/Position.designer.cs | 55 ++--- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 6 +- SourceCode/GPS/Forms/Settings/FormSteer.cs | 2 +- 29 files changed, 302 insertions(+), 983 deletions(-) delete mode 100644 SourceCode/GPS/Classes/CHeadLines.cs diff --git a/SourceCode/GPS/AgOpenGPS.csproj b/SourceCode/GPS/AgOpenGPS.csproj index 2b1114007..d8d2bf0b8 100644 --- a/SourceCode/GPS/AgOpenGPS.csproj +++ b/SourceCode/GPS/AgOpenGPS.csproj @@ -131,9 +131,6 @@ - - CBoundaryList.cs - CBoundary.cs diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index 17ea9d2d4..39a2fbffb 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -725,51 +725,18 @@ public void BuildTram() } if (Add) { - if (isBndExist) + //a new point only every 2 meters + double dist = mf.tram.tramArr.Count > 0 ? ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) + + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)) : 3.0; + if (dist > 2) { - if (mf.tram.tramArr.Count > 0) - { - //a new point only every 2 meters - double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) - + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); - if (dist > 2) - { - //if inside the boundary, add - if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar )) - { - mf.tram.tramArr.Add(point); - } - } - } - else - { - //need a first point to do distance - if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) - { - mf.tram.tramArr.Add(point); - } - } - } - else - { - //no boundary to cull points - if (mf.tram.tramArr.Count > 0) - { - double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) - + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); - if (dist > 2) - { - mf.tram.tramArr.Add(point); - } - } - else + //if inside the boundary, add + if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(point)) { mf.tram.tramArr.Add(point); } - } } - } } @@ -806,48 +773,16 @@ public void BuildTram() } if (Add) { - if (isBndExist) + //a new point only every 2 meters + double dist = mf.tram.tramArr.Count > 0 ? ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) + + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)) : 3.0; + if (dist > 2) { - if (mf.tram.tramArr.Count > 0) - { - //a new point only every 2 meters - double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) - + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); - if (dist > 2) - { - //if inside the boundary, add - if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) - { - mf.tram.tramArr.Add(point); - } - } - } - else - { - //need a first point to do distance - if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) - { - mf.tram.tramArr.Add(point); - } - } - } - else - { - //no boundary to cull points - if (mf.tram.tramArr.Count > 0) - { - double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) - + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); - if (dist > 2) - { - mf.tram.tramArr.Add(point); - } - } - else + //if inside the boundary, add + if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(point)) { mf.tram.tramArr.Add(point); } - } } } @@ -1020,8 +955,6 @@ public void ResetCurveLine() refList?.Clear(); isCurveSet = false; } - - ////draw the guidance line } public class CCurveLines diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index df7fbbd1a..832af3870 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -493,14 +493,7 @@ public void BuildTram() P1.easting = (hsin * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].easting; P1.northing = (hcos * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].northing; - if (isBndExist) - { - if (glm.IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) - { - mf.tram.tramArr.Add(P1); - } - } - else + if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(P1)) { mf.tram.tramArr.Add(P1); } @@ -521,14 +514,7 @@ public void BuildTram() P1.easting = (hsin * ((mf.tram.tramWidth * (pass + i)) + mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].easting; P1.northing = (hcos * ((mf.tram.tramWidth * (pass + i)) + mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].northing; - if (isBndExist) - { - if (glm.IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) - { - mf.tram.tramArr.Add(P1); - } - } - else + if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(P1)) { mf.tram.tramArr.Add(P1); } diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index 7a67962d7..f4cf9bb19 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -1,6 +1,4 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace AgOpenGPS { @@ -15,11 +13,9 @@ public partial class CBoundary public CBoundary(FormGPS _f) { mf = _f; - fenceSelected = 0; boxLength = 2000; turnSelected = 0; isHeadlandOn = false; - isToolUp = true; } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CBoundaryList.cs b/SourceCode/GPS/Classes/CBoundaryList.cs index 0b52a3b28..3114a70a5 100644 --- a/SourceCode/GPS/Classes/CBoundaryList.cs +++ b/SourceCode/GPS/Classes/CBoundaryList.cs @@ -1,6 +1,4 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace AgOpenGPS { @@ -12,12 +10,10 @@ public partial class CBoundaryList public List hdLine = new List(128); public List turnLine = new List(128); - //constructor public CBoundaryList() { area = 0; - isDriveAround = false; isDriveThru = false; } } diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index 4ae78d278..086a4cba3 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -313,10 +313,10 @@ public void BuildContourGuidanceLine(vec3 pivot, vec3 steer) stripNum = 0; for (int s = 0; s < stripCount; s++) { - double dist = 0; int p; ptCount = stripList[s].Count; if (ptCount == 0) continue; + double dist; for (p = 0; p < ptCount; p += 6) { dist = ((pivot.easting - stripList[s][p].easting) * (pivot.easting - stripList[s][p].easting)) @@ -515,13 +515,10 @@ public void BuildContourGuidanceLine(vec3 pivot, vec3 steer) stop = pt + 6; if (stop > ptCount) stop = ptCount; } - double distAway = 0; - double distSqAway = 0; - //if (howManyPathsAway != 0 && (mf.tool.halfToolWidth < (0.5*mf.tool.toolOffset))) { - distAway = (mf.tool.toolWidth - mf.tool.toolOverlap) * howManyPathsAway + (isSameWay ? -mf.tool.toolOffset : mf.tool.toolOffset); - distSqAway = (distAway * distAway) * 0.97; + double distAway = (mf.tool.toolWidth - mf.tool.toolOverlap) * howManyPathsAway + (isSameWay ? -mf.tool.toolOffset : mf.tool.toolOffset); + double distSqAway = (distAway * distAway) * 0.97; for (int i = start; i < stop; i++) @@ -845,8 +842,7 @@ public void StartContourLine(vec3 pivot) if (stripList.Count == 0) { //make new ptList - ptList = new List(); - ptList.Capacity = 16; + ptList = new List(16); //ptList.Add(new vec3(pivot.easting + Math.Cos(pivot.heading) // * mf.tool.toolOffset, pivot.northing - Math.Sin(pivot.heading) * mf.tool.toolOffset, pivot.heading)); stripList.Add(ptList); @@ -882,7 +878,6 @@ public void StopContourLine(vec3 pivot) double head = ptList[0].heading; int length = (int)mf.tool.toolWidth+3; vec3 pnt; - int ptc = ctList.Count - 1; for (int a = 0; a < length; a ++) { pnt.easting = ptList[0].easting - (Math.Sin(head)); @@ -891,7 +886,7 @@ public void StopContourLine(vec3 pivot) ptList.Insert(0, pnt); } - ptc = ptList.Count - 1; + int ptc = ptList.Count - 1; head = ptList[ptc].heading; for (double i = 1; i < length; i += 1) @@ -905,8 +900,7 @@ public void StopContourLine(vec3 pivot) //add the point list to the save list for appending to contour file mf.contourSaveList.Add(ptList); - ptList = new List(); - ptList.Capacity = 32; + ptList = new List(32); stripList.Add(ptList); } diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs index 3a18c4588..f32d948c0 100644 --- a/SourceCode/GPS/Classes/CFence.cs +++ b/SourceCode/GPS/Classes/CFence.cs @@ -11,47 +11,69 @@ public partial class CBoundary public double createBndOffset; public bool isBndBeingMade; - // the list of possible bounds points - public List bndClosestList = new List(); - public bool isDrawRightSide = true, isOkToAddPoints = false; - public int fenceSelected, closestFenceNum; + public int closestFenceNum; //point at the farthest boundary segment from pivotAxle public vec3 closestFencePt = new vec3(-10000, -10000, 9); - public bool IsInsideAllFences(vec3 testPoint) + public bool IsPointInsideFenceArea(vec3 testPoint) { //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (glm.IsPointInPolygon(testPoint, ref bndList[0].fenceLine)) + if (bndList[0].fenceLineEar.IsPointInPolygon(testPoint)) { for (int i = 1; i < bndList.Count; i++) { //make sure not inside a non drivethru boundary if (bndList[i].isDriveThru) continue; - if (glm.IsPointInPolygon(testPoint, ref bndList[i].fenceLine)) + if (bndList[i].fenceLineEar.IsPointInPolygon(testPoint)) { return false; } } + //we are safely inside outer, outside inner boundaries + return true; } - else + return false; + } + + public bool IsPointInsideFenceArea(vec2 testPoint) + { + //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders + if (bndList[0].fenceLineEar.IsPointInPolygon(testPoint)) { - return false; + for (int i = 1; i < bndList.Count; i++) + { + //make sure not inside a non drivethru boundary + if (bndList[i].isDriveThru) continue; + if (bndList[i].fenceLineEar.IsPointInPolygon(testPoint)) + { + return false; + } + } + //we are safely inside outer, outside inner boundaries + return true; } - //we are safely inside outer, outside inner boundaries - return true; + return false; } public void DrawFenceLines() { - //draw the boundaries - GL.Color3(0.75f, 0.5f, 0.250f); + if (!mf.mc.isOutOfBounds) + { + GL.Color3(0.95f, 0.75f, 0.50f); + GL.LineWidth(mf.ABLine.lineWidth); + } + else + { + GL.LineWidth(mf.ABLine.lineWidth * 3); + GL.Color3(0.95f, 0.25f, 0.250f); + } for (int i = 0; i < bndList.Count; i++) { - bndList[i].DrawFenceLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); + bndList[i].fenceLine.DrawPolygon(); } if (bndBeingMadePts.Count > 0) @@ -100,82 +122,4 @@ public void DrawFenceLines() } } -} - - -//public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) - //{ - // { - // boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); - // boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); - - // boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); - // boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); - - // boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); - // boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); - - // boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); - // boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); - // } - - // int ptCount; - - // //determine if point is inside bounding box - // bndClosestList.Clear(); - // vec4 inBox; - // for (int i = 0; i < plots.Count; i++) - // { - // //skip the drive thru - // if (plots[i].isDriveThru) continue; - - // ptCount = plots[i].bndLine.Count; - // for (int p = 0; p < ptCount; p++) - // { - // if ((((boxB.easting - boxA.easting) * (plots[i].bndLine[p].northing - boxA.northing)) - // - ((boxB.northing - boxA.northing) * (plots[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } - - // if ((((boxD.easting - boxC.easting) * (plots[i].bndLine[p].northing - boxC.northing)) - // - ((boxD.northing - boxC.northing) * (plots[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } - - // if ((((boxC.easting - boxB.easting) * (plots[i].bndLine[p].northing - boxB.northing)) - // - ((boxC.northing - boxB.northing) * (plots[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } - - // if ((((boxA.easting - boxD.easting) * (plots[i].bndLine[p].northing - boxD.northing)) - // - ((boxA.northing - boxD.northing) * (plots[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } - - // //it's in the box, so add to list - // inBox.easting = plots[i].bndLine[p].easting; - // inBox.northing = plots[i].bndLine[p].northing; - // inBox.heading = plots[i].bndLine[p].heading; - // inBox.index = i; - - // //which boundary/headland is it from - // bndClosestList.Add(inBox); - // } - // } - - // //which of the points is closest - // closestBoundaryPt.easting = -20000; closestBoundaryPt.northing = -20000; - // ptCount = bndClosestList.Count; - // if (ptCount != 0) - // { - // //determine closest point - // double minDistance = 9999999; - // for (int i = 0; i < ptCount; i++) - // { - // double dist = ((fromPt.easting - bndClosestList[i].easting) * (fromPt.easting - bndClosestList[i].easting)) - // + ((fromPt.northing - bndClosestList[i].northing) * (fromPt.northing - bndClosestList[i].northing)); - // if (minDistance >= dist) - // { - // minDistance = dist; - - // closestBoundaryPt.easting = bndClosestList[i].easting; - // closestBoundaryPt.northing = bndClosestList[i].northing; - // closestBoundaryPt.heading = bndClosestList[i].heading; - // closestBoundaryNum = bndClosestList[i].index; - // } - // } - // if (closestBoundaryPt.heading < 0) closestBoundaryPt.heading += glm.twoPI; - // } - //} \ No newline at end of file +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CFenceLine.cs b/SourceCode/GPS/Classes/CFenceLine.cs index 9a84e554b..b4aceed01 100644 --- a/SourceCode/GPS/Classes/CFenceLine.cs +++ b/SourceCode/GPS/Classes/CFenceLine.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using OpenTK.Graphics.OpenGL; namespace AgOpenGPS { @@ -11,7 +8,7 @@ public partial class CBoundaryList public double area; //boundary variables - public bool isDriveAround, isDriveThru; + public bool isDriveThru; public void CalculateFenceLineHeadings() { @@ -148,47 +145,11 @@ public void ReverseWinding() } } - public void DrawFenceLine(int lw, bool outOfBounds) - { - ////draw the perimeter line so far - if (fenceLine.Count < 1) return; - //GL.PointSize(8); - //int ptCount = bndLine.Count; - //GL.Color3(0.925f, 0.752f, 0.860f); - ////else - //GL.Begin(PrimitiveType.Points); - //for (int h = 0; h < ptCount; h++) GL.Vertex3(bndLine[h].easting, bndLine[h].northing, 0); - ////GL.Color3(0.95f, 0.972f, 0.90f); - ////GL.Vertex3(bndLine[0].easting, bndLine[0].northing, 0); - //GL.End(); - - //ptCount = bdList.Count; - //if (ptCount < 1) return; - if (!outOfBounds) - { - GL.Color3(0.95f, 0.75f, 0.50f); - GL.LineWidth(lw); - } - else - { - GL.LineWidth(lw * 3); - GL.Color3(0.95f, 0.25f, 0.250f); - } - - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < fenceLineEar.Count; i++) - { - GL.Vertex3(fenceLineEar[i].easting, fenceLineEar[i].northing, 0); - } - GL.End(); - } - //obvious public bool CalculateFenceArea(int idx) { int ptCount = fenceLine.Count; if (ptCount < 1) return false; - bool isClockwise = true; area = 0; // Accumulates area in the loop int j = ptCount - 1; // The last vertex is the 'previous' one to the first @@ -197,7 +158,8 @@ public bool CalculateFenceArea(int idx) { area += (fenceLine[j].easting + fenceLine[i].easting) * (fenceLine[j].northing - fenceLine[i].northing); } - if (area < 0) isClockwise = false; + + bool isClockwise = area >= 0; area = Math.Abs(area / 2); diff --git a/SourceCode/GPS/Classes/CGLM.cs b/SourceCode/GPS/Classes/CGLM.cs index ea5a52bbc..ab792ea4d 100644 --- a/SourceCode/GPS/Classes/CGLM.cs +++ b/SourceCode/GPS/Classes/CGLM.cs @@ -1,12 +1,12 @@ -using System; +using OpenTK.Graphics.OpenGL; +using System; using System.Collections.Generic; -using System.Windows.Forms; namespace AgOpenGPS { public static class glm { - public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) + public static bool IsPointInPolygon(this List polygon, vec3 testPoint) { bool result = false; int j = polygon.Count - 1; @@ -27,7 +27,7 @@ public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) return result; } - public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) + public static bool IsPointInPolygon(this List polygon, vec2 testPoint) { bool result = false; int j = polygon.Count - 1; @@ -47,7 +47,8 @@ public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) } return result; } - public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) + + public static bool IsPointInPolygon(this List polygon, vec2 testPoint) { bool result = false; int j = polygon.Count - 1; @@ -67,7 +68,8 @@ public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) } return result; } - public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) + + public static bool IsPointInPolygon(this List polygon, vec3 testPoint) { bool result = false; int j = polygon.Count - 1; @@ -88,6 +90,19 @@ public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) return result; } + public static void DrawPolygon(this List polygon) + { + if (polygon.Count > 1) + { + GL.Begin(PrimitiveType.LineLoop); + for (int i = 0; i < polygon.Count; i++) + { + GL.Vertex3(polygon[i].easting, polygon[i].northing, 0); + } + GL.End(); + } + } + // Catmull Rom interpoint spline calculation public static vec3 Catmull(double t, vec3 p0, vec3 p1, vec3 p2, vec3 p3) { diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index 08dcdae02..ae0a347ce 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -5,18 +5,7 @@ namespace AgOpenGPS public partial class CBoundary { public bool isHeadlandOn; - public double leftToolDistance; - public double rightToolDistance; - - //generated box for finding closest point - public vec2 downL = new vec2(9000, 9000), downR = new vec2(9000, 9002); - - public bool isToolInHeadland, isToolUp, isToolOuterPointsInHeadland; - - public bool isToolLeftIn = false; - public bool isToolRightIn = false; - public bool isLookRightIn = false; - public bool isLookLeftIn = false; + public bool isToolInHeadland, isToolOuterPointsInHeadland; public void SetHydPosition() { @@ -25,12 +14,10 @@ public void SetHydPosition() if (isToolInHeadland) { mf.p_239.pgn[mf.p_239.hydLift] = 2; - isToolUp = true; } else { mf.p_239.pgn[mf.p_239.hydLift] = 1; - isToolUp = false; } } } @@ -41,44 +28,24 @@ public void WhereAreToolCorners() { bool isLeftInWk, isRightInWk = true; - if (isHeadlandOn) + for (int j = 0; j < mf.tool.numOfSections; j++) { - for (int j = 0; j < mf.tool.numOfSections; j++) - { - if (j == 0) - { - //only one first left point, the rest are all rights moved over to left - isLeftInWk = glm.IsPointInPolygon(mf.section[j].leftPoint, ref bndList[0].hdLine); - isRightInWk = glm.IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); - - //save left side - mf.tool.isLeftSideInHeadland = !isLeftInWk; - - //merge the two sides into in or out - mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; - - } - else - { - //grab the right of previous section, its the left of this section - isLeftInWk = isRightInWk; - isRightInWk = glm.IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); - - mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; - } - } + isLeftInWk = j == 0 ? IsPointInsideHeadArea(mf.section[j].leftPoint) : isRightInWk; + isRightInWk = IsPointInsideHeadArea(mf.section[j].rightPoint); - //save right side - mf.tool.isRightSideInHeadland = !isRightInWk; + //save left side + if (j == 0) + mf.tool.isLeftSideInHeadland = !isLeftInWk; - //is the tool in or out based on endpoints - isToolOuterPointsInHeadland = mf.tool.isLeftSideInHeadland && mf.tool.isRightSideInHeadland; - } - else - { - //set all to true; - isToolOuterPointsInHeadland = true; + //merge the two sides into in or out + mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } + + //save right side + mf.tool.isRightSideInHeadland = !isRightInWk; + + //is the tool in or out based on endpoints + isToolOuterPointsInHeadland = mf.tool.isLeftSideInHeadland && mf.tool.isRightSideInHeadland; } } @@ -86,54 +53,43 @@ public void WhereAreToolLookOnPoints() { if (bndList.Count > 0 && bndList[0].hdLine.Count > 0) { + bool isLookRightIn = false; + vec3 toolFix = mf.toolPos; double sinAB = Math.Sin(toolFix.heading); double cosAB = Math.Cos(toolFix.heading); - double pos = mf.section[0].rpSectionWidth; + //generated box for finding closest point + double pos = 0; double mOn = (mf.tool.lookAheadDistanceOnPixelsRight - mf.tool.lookAheadDistanceOnPixelsLeft) / mf.tool.rpWidth; - double endHeight = (mf.tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * 0.1; for (int j = 0; j < mf.tool.numOfSections; j++) { - if (j == 0) - { - downL.easting = mf.section[j].leftPoint.easting + (sinAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1); - downL.northing = mf.section[j].leftPoint.northing + (cosAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1); - - downR.easting = mf.section[j].rightPoint.easting + (sinAB * endHeight); - downR.northing = mf.section[j].rightPoint.northing + (cosAB * endHeight); - isLookLeftIn = IsPointInsideHeadLine(downL); - isLookRightIn = IsPointInsideHeadLine(downR); + bool isLookLeftIn = j == 0 ? IsPointInsideHeadArea(new vec2( + mf.section[j].leftPoint.easting + (sinAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1), + mf.section[j].leftPoint.northing + (cosAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1))) : isLookRightIn; - mf.section[j].isLookOnInHeadland = !isLookLeftIn && !isLookRightIn; - isLookLeftIn = isLookRightIn; - } - else - { - pos += mf.section[j].rpSectionWidth; - endHeight = (mf.tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * 0.1; + pos += mf.section[j].rpSectionWidth; + double endHeight = (mf.tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * 0.1; - downR.easting = mf.section[j].rightPoint.easting + (sinAB * endHeight); - downR.northing = mf.section[j].rightPoint.northing + (cosAB * endHeight); + isLookRightIn = IsPointInsideHeadArea(new vec2( + mf.section[j].rightPoint.easting + (sinAB * endHeight), + mf.section[j].rightPoint.northing + (cosAB * endHeight))); - isLookRightIn = IsPointInsideHeadLine(downR); - mf.section[j].isLookOnInHeadland = !isLookLeftIn && !isLookRightIn; - isLookLeftIn = isLookRightIn; - } + mf.section[j].isLookOnInHeadland = !isLookLeftIn && !isLookRightIn; } } } - public bool IsPointInsideHeadLine(vec2 pt) + public bool IsPointInsideHeadArea(vec2 pt) { //if inside outer boundary, then potentially add - if (bndList.Count > 0 && glm.IsPointInPolygon(pt, ref bndList[0].hdLine)) + if (bndList[0].hdLine.IsPointInPolygon(pt)) { - for (int b = 1; b < bndList.Count; b++) + for (int i = 1; i < bndList.Count; i++) { - if (glm.IsPointInPolygon(pt, ref bndList[b].hdLine)) + if (bndList[i].hdLine.IsPointInPolygon(pt)) { //point is in an inner turn area but inside outer return false; @@ -141,10 +97,7 @@ public bool IsPointInsideHeadLine(vec2 pt) } return true; } - else - { - return false; - } + return false; } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CHeadLines.cs b/SourceCode/GPS/Classes/CHeadLines.cs deleted file mode 100644 index 634e61b08..000000000 --- a/SourceCode/GPS/Classes/CHeadLines.cs +++ /dev/null @@ -1,34 +0,0 @@ -using OpenTK.Graphics.OpenGL; - -namespace AgOpenGPS -{ - public partial class CBoundaryList - { - - public void DrawHeadLine() - { - if (hdLine.Count > 1) - { - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < hdLine.Count; i++) - { - GL.Vertex3(hdLine[i].easting, hdLine[i].northing, 0); - } - GL.End(); - } - } - - public void DrawHeadLineBackBuffer() - { - if (hdLine.Count > 1) - { - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < hdLine.Count; i++) - { - GL.Vertex3(hdLine[i].easting, hdLine[i].northing, 0); - } - GL.End(); - } - } - } -} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CSection.cs b/SourceCode/GPS/Classes/CSection.cs index ad81f2090..4f08ef877 100644 --- a/SourceCode/GPS/Classes/CSection.cs +++ b/SourceCode/GPS/Classes/CSection.cs @@ -67,12 +67,12 @@ public class CSection public int rpSectionPosition = 0; //points in world space that start and end of section are in - public vec3 leftPoint; - public vec3 rightPoint; + public vec2 leftPoint; + public vec2 rightPoint; //used to determine left and right speed of section - public vec3 lastLeftPoint; - public vec3 lastRightPoint; + public vec2 lastLeftPoint; + public vec2 lastRightPoint; //whether or not this section is in boundary, headland public bool isInBoundary = true, isHydLiftInWorkArea = true; @@ -103,8 +103,7 @@ public void TurnMappingOn(int j) isMappingOn = true; //starting a new patch chunk so create a new triangle list - triangleList = new List(); - triangleList.Capacity = 16; + triangleList = new List(32); patchList.Add(triangleList); @@ -205,23 +204,15 @@ public void AddMappingPoint(int j) //save the cutoff patch to be saved later mf.patchSaveList.Add(triangleList); - triangleList = new List(); - triangleList.Capacity = 32; + triangleList = new List(32); patchList.Add(triangleList); //Add Patch colour if (!mf.tool.isMultiColoredSections) - { - vec3 colur = new vec3(mf.sectionColorDay.R, mf.sectionColorDay.G, mf.sectionColorDay.B); - triangleList.Add(colur); - } - + triangleList.Add(new vec3(mf.sectionColorDay.R, mf.sectionColorDay.G, mf.sectionColorDay.B)); else - { - vec3 collor = new vec3(mf.tool.secColors[j].R, mf.tool.secColors[j].G, mf.tool.secColors[j].B); - triangleList.Add(collor); - } + triangleList.Add(new vec3(mf.tool.secColors[j].R, mf.tool.secColors[j].G, mf.tool.secColors[j].B)); //add the points to List, yes its more points, but breaks up patches for culling triangleList.Add(point); diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index 2dc00743c..3e48d16f3 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -1,5 +1,4 @@ -using OpenTK.Graphics.OpenGL; -using System; +using System; using System.Collections.Generic; namespace AgOpenGPS @@ -21,13 +20,29 @@ public partial class CBoundary //point at the farthest turn segment from pivotAxle public vec3 closestTurnPt = new vec3(-10000, -10000, 9); + public int IsPointInsideTurnArea(vec3 pt) + { + if (bndList.Count > 0 && bndList[0].turnLine.IsPointInPolygon(pt)) + { + for (int i = 1; i < bndList.Count; i++) + { + if (bndList[i].isDriveThru) continue; + if (bndList[i].turnLine.IsPointInPolygon(pt)) + { + return i; + } + } + return 0; + } + return -1; + } + public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB) { //initial scan is straight ahead of pivot point of vehicle to find the right turnLine/boundary vec3 pt = new vec3(); vec3 rayPt = new vec3(); - bool isFound = false; int closestTurnNum = 99; double cosHead = Math.Cos(headAB); @@ -38,31 +53,16 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (glm.IsPointInPolygon(pt, ref bndList[0].turnLine)) - { - for (int t = 1; t < bndList.Count; t++) - { - if (bndList[t].isDriveThru) continue; - if (bndList[t].isDriveAround) continue; - if (glm.IsPointInPolygon(pt, ref bndList[t].turnLine)) - { - isFound = true; - closestTurnNum = t; - rayPt.easting = pt.easting; - rayPt.northing = pt.northing; - break; - } - } - if (isFound) break; - } - else + int idx = IsPointInsideTurnArea(pt); + if (idx != 0) { - closestTurnNum = 0; + closestTurnNum = idx; rayPt.easting = pt.easting; rayPt.northing = pt.northing; break; } } + if (closestTurnNum < 0) closestTurnNum = 0; //second scan is straight ahead of outside of tool based on turn direction double scanWidthL, scanWidthR; @@ -207,9 +207,6 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB public void BuildTurnLines() { - //update the GUI values for boundaries - mf.fd.UpdateFieldBoundaryGUIAreas(); - if (bndList.Count == 0) { //mf.TimedMessageBox(1500, " No Boundaries", "No Turn Lines Made"); @@ -226,7 +223,7 @@ public void BuildTurnLines() for (int j = 0; j < bndList.Count; j++) { bndList[j].turnLine.Clear(); - if (bndList[j].isDriveThru || bndList[j].isDriveAround) continue; + if (bndList[j].isDriveThru) continue; int ptCount = bndList[j].fenceLine.Count; @@ -239,7 +236,7 @@ public void BuildTurnLines() if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == glm.IsPointInPolygon(point, ref bndList[j].fenceLineEar)) + if (j == 0 == bndList[j].fenceLineEar.IsPointInPolygon(point)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); bndList[j].turnLine.Add(tPnt); @@ -248,27 +245,5 @@ public void BuildTurnLines() bndList[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); } } - - public void DrawTurnLines() - { - GL.LineWidth(mf.ABLine.lineWidth); - GL.Color3(0.3555f, 0.6232f, 0.20f); - //GL.PointSize(2); - - for (int i = 0; i < bndList.Count; i++) - { - if (bndList[i].isDriveAround) continue; - //turnArr[i].DrawTurnLine(); - { - ////draw the turn line oject - int ptCount = bndList[i].turnLine.Count; - if (ptCount < 1) continue; - - GL.Begin(PrimitiveType.LineLoop); - for (int h = 0; h < ptCount; h++) GL.Vertex3(bndList[i].turnLine[h].easting, bndList[i].turnLine[h].northing, 0); - GL.End(); - } - } - } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CTurnLines.cs b/SourceCode/GPS/Classes/CTurnLines.cs index 83bd604fd..91dd97b7a 100644 --- a/SourceCode/GPS/Classes/CTurnLines.cs +++ b/SourceCode/GPS/Classes/CTurnLines.cs @@ -1,5 +1,4 @@ -using OpenTK.Graphics.OpenGL; -using System; +using System; namespace AgOpenGPS { @@ -99,44 +98,6 @@ public void FixTurnLine(double totalHeadWidth, double spacing) { CalculateTurnHeadings(); } - - //int cnt = turnLine.Count; - //vec3[] arr = new vec3[cnt]; - //turnLine.CopyTo(arr); - //turnLine.Clear(); - - //double delta = 0; - //for (int i = 0; i < arr.Length; i++) - //{ - // if (i == 0) - // { - // turnLine.Add(new vec3(arr[i].easting, arr[i].northing, arr[i].heading)); - // continue; - // } - // delta += (arr[i - 1].heading - arr[i].heading); - - // if (Math.Abs(delta) > 0.1) - // { - // vec3 pt = new vec3(arr[i].easting, arr[i].northing, arr[i].heading); - - // turnLine.Add(pt); - // delta = 0; - // } - //} - } - - public void DrawTurnLine() - { - ////draw the turn line oject - int ptCount = turnLine.Count; - if (ptCount < 1) return; - GL.LineWidth(1); - GL.Color3(0.8555f, 0.9232f, 0.60f); - GL.PointSize(2); - GL.Begin(PrimitiveType.LineLoop); - for (int h = 0; h < ptCount; h++) GL.Vertex3(turnLine[h].easting, turnLine[h].northing, 0); - GL.Vertex3(turnLine[0].easting, turnLine[0].northing, 0); - GL.End(); } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index df0268fdb..c629aba89 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -13,24 +13,12 @@ public class CYouTurn public bool isYouTurnTriggered; /// /// turning right or left?/// - public bool isYouTurnRight, isLastToggle; - - /// /// What was the last successful you turn direction? /// - public bool isLastYouTurnRight; - - //public bool isEnteringDriveThru = false, isExitingDriveThru = false; - - //if not in workArea but in bounds, then we are on headland - public bool isInWorkArea, isInBoundz; - - //controlled by user in GUI to en/dis able - public bool isRecordingCustomYouTurn; + public bool isYouTurnRight; /// /// Is the youturn button enabled? /// public bool isYouTurnBtnOn; public double boundaryAngleOffPerpendicular; - public double distanceTurnBeforeLine = 0, tangencyAngle; public int rowSkipsWidth = 1, uTurnSmoothing = 10; @@ -38,7 +26,7 @@ public class CYouTurn public int rowSkipsWidth2 = 3, turnSkips = 2; /// /// distance from headland as offset where to start turn shape /// - public int youTurnStartOffset, C; + public int youTurnStartOffset; //guidance values public double distanceFromCurrentLine, uturnDistanceFromBoundary, dxAB, dyAB; @@ -64,20 +52,14 @@ public class CYouTurn //list of points for scaled and rotated YouTurn line, used for pattern, dubins, abcurve, abline public List ytList = new List(); - ////list of points read from file, this is the actual pattern from a bunch of sources possible - //public List youFileList = new List(); - - //to try and pull a UTurn back in bounds - public double turnDistanceAdjuster; - //is UTurn pattern in or out of bounds public bool isOutOfBounds = false; //sequence of operations of finding the next turn 0 to 3 - public int youTurnPhase, curListCount; + public int youTurnPhase; public vec4 crossingCurvePoint = new vec4(); - public vec4 crossingTurnLinePoint = new vec4(); + public double crossingheading = 0; //constructor public CYouTurn(FormGPS _f) @@ -98,94 +80,29 @@ public CYouTurn(FormGPS _f) //Finds the point where an AB Curve crosses the turn line public bool FindCurveTurnPoints() { - crossingCurvePoint.easting = -20000; - crossingTurnLinePoint.easting = -20000; + crossingCurvePoint.easting = -20000; //find closet AB Curve point that will cross and go out of bounds - curListCount = mf.curve.curList.Count; - - //otherwise we count down - bool isCountingUp = mf.curve.isHeadingSameWay; + int Count = mf.curve.isHeadingSameWay ? 1 : -1; + int turnNum = 99; - //check if outside a border - if (isCountingUp) + for (int j = mf.curve.currentLocationIndex; j > 0 && j < mf.curve.curList.Count; j += Count) { - crossingTurnLinePoint.index = 99; - - //for each point in succession keep going till a turnLine is found. - for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) + int idx = mf.bnd.IsPointInsideTurnArea(mf.curve.curList[j]); + if (idx != 0) { - if (!glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) - { //it passed outer turnLine - crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; - crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; - crossingCurvePoint.heading = mf.curve.curList[j - 1].heading; - crossingCurvePoint.index = j - 1; - crossingTurnLinePoint.index = 0; - goto CrossingFound; - } - - for (int i = 1; i < mf.bnd.bndList.Count; i++) - { - //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) - { - crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; - crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; - crossingCurvePoint.heading = mf.curve.curList[j - 1].heading; - crossingCurvePoint.index = j - 1; - crossingTurnLinePoint.index = i; - goto CrossingFound; - } - } - } - - //escape for multiple for's - CrossingFound:; - - } - else //counting down, going opposite way mf.curve was created. - { - crossingTurnLinePoint.index = 99; - - for (int j = mf.curve.currentLocationIndex; j > 0; j--) - { - if (!glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) - { //it passed outer turnLine - crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; - crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; - crossingCurvePoint.heading = mf.curve.curList[j + 1].heading; - crossingCurvePoint.index = j + 1; - crossingTurnLinePoint.index = 0; - goto CrossingFound; - } - - for (int i = 1; i < mf.bnd.bndList.Count; i++) - { - //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) - { - crossingCurvePoint.easting = mf.curve.curList[j].easting; - crossingCurvePoint.northing = mf.curve.curList[j].northing; - crossingCurvePoint.heading = mf.curve.curList[j].heading; - crossingCurvePoint.index = j; - crossingTurnLinePoint.index = i; - goto CrossingFound; - } - } + crossingCurvePoint.easting = mf.curve.curList[j - Count].easting; + crossingCurvePoint.northing = mf.curve.curList[j - Count].northing; + crossingCurvePoint.heading = mf.curve.curList[j - Count].heading; + crossingCurvePoint.index = j - Count; + turnNum = idx; + break; } - - //escape for multiple for's, point and turnLine index are found - CrossingFound:; } - int turnNum = crossingTurnLinePoint.index; - - if (turnNum == 99) + if (turnNum < 0) + turnNum = 0; + else if (turnNum == 99) { isTurnCreationNotCrossingError = true; return false; @@ -198,10 +115,10 @@ public bool FindCurveTurnPoints() for (int j = 0; j < curTurnLineCount; j++) { - if ((mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 - && (mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 - && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 - && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) + if ((mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 15 + && (mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -15 + && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 15 + && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -15) { turnLineCloseList.Add(j); } @@ -209,6 +126,7 @@ public bool FindCurveTurnPoints() double dist1, dist2 = 99; curTurnLineCount = turnLineCloseList.Count; + int index = -1; for (int i = 0; i < curTurnLineCount; i++) { dist1 = glm.Distance(mf.bnd.bndList[turnNum].turnLine[turnLineCloseList[i]].easting, @@ -216,17 +134,16 @@ public bool FindCurveTurnPoints() crossingCurvePoint.easting, crossingCurvePoint.northing); if (dist1 < dist2) { - crossingTurnLinePoint.index = turnLineCloseList[i]; + index = turnLineCloseList[i]; dist2 = dist1; } } - //fill up the coords - crossingTurnLinePoint.easting = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].easting; - crossingTurnLinePoint.northing = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].northing; - crossingTurnLinePoint.heading = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].heading; + crossingheading = -20000; + if (index >= 0) + crossingheading = mf.bnd.bndList[turnNum].turnLine[index].heading; - return crossingCurvePoint.easting != -20000 && crossingCurvePoint.easting != -20000; + return crossingheading != -20000 && crossingCurvePoint.easting != -20000; } public void AddSequenceLines(double head) @@ -408,13 +325,13 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) if (boundaryAngleOffPerpendicular < -1.25) boundaryAngleOffPerpendicular = -1.25; //for calculating innner circles of turn - tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; + double tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; //baseline away from boundary to start calculations double toolTurnWidth = mf.tool.toolWidth * rowSkipsWidth; //distance from TurnLine for trigger added in youturn form, include the 3 m bump forward - distanceTurnBeforeLine = 0; + double distanceTurnBeforeLine = 0; if (mf.vehicle.minTurningRadius * 2 < toolTurnWidth) { @@ -584,21 +501,11 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!glm.IsPointInPolygon(ytList[j],ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; - if (isOutOfBounds) break; - - for (int i = 1; i < mf.bnd.bndList.Count; i++) + if (mf.bnd.IsPointInsideTurnArea(ytList[j]) != 0) { - //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) - { - isOutOfBounds = true; - break; - } + isOutOfBounds = true; + break; } - if (isOutOfBounds) break; } if (!isOutOfBounds) @@ -644,23 +551,11 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; - if (isOutOfBounds) - break; - - for (int i = 1; i < mf.bnd.bndList.Count; i++) + if (mf.bnd.IsPointInsideTurnArea(ytList[j]) != 0) { - //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) - { - isOutOfBounds = true; - break; - } - } - if (isOutOfBounds) + isOutOfBounds = true; break; + } } if (isOutOfBounds) @@ -698,15 +593,16 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) if (!isHeadingSameWay) head += Math.PI; //delta between AB heading and boundary closest point heading - boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(crossingTurnLinePoint.heading - head) - Math.PI); + boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(crossingheading - head) - Math.PI); boundaryAngleOffPerpendicular -= glm.PIBy2; boundaryAngleOffPerpendicular *= -1; if (boundaryAngleOffPerpendicular > 1.25) boundaryAngleOffPerpendicular = 1.25; if (boundaryAngleOffPerpendicular < -1.25) boundaryAngleOffPerpendicular = -1.25; //for calculating innner circles of turn - tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; + double tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; + double distanceTurnBeforeLine; //distance from crossPoint to turn line if (mf.vehicle.minTurningRadius * 2 < (mf.tool.toolWidth * rowSkipsWidth)) { @@ -852,24 +748,11 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) + if (mf.bnd.IsPointInsideTurnArea(ytList[j]) != 0) { isOutOfBounds = true; break; } - - for (int i = 1; i < mf.bnd.bndList.Count; i++) - { - //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[1].turnLine)) - { - isOutOfBounds = true; - break; - } - } - if (isOutOfBounds) break; } //first check if not out of bounds, add a bit more to clear turn line, set to phase 2 @@ -902,8 +785,8 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) else { crossingCurvePoint.index++; - if (crossingCurvePoint.index >= curListCount) - crossingCurvePoint.index = curListCount - 1; + if (crossingCurvePoint.index >= mf.curve.curList.Count) + crossingCurvePoint.index = mf.curve.curList.Count - 1; } crossingCurvePoint.easting = mf.curve.curList[crossingCurvePoint.index].easting; crossingCurvePoint.northing = mf.curve.curList[crossingCurvePoint.index].northing; @@ -1027,7 +910,6 @@ public void ResetYouTurn() isYouTurnTriggered = false; ytList?.Clear(); ResetCreatedYouTurn(); - turnDistanceAdjuster = 0; mf.isBoundAlarming = false; isTurnCreationTooClose = false; isTurnCreationNotCrossingError = false; @@ -1035,7 +917,6 @@ public void ResetYouTurn() public void ResetCreatedYouTurn() { - turnDistanceAdjuster = 0; youTurnPhase = 0; ytList?.Clear(); } @@ -1223,7 +1104,7 @@ public bool DistanceFromYouTurnLine() } //just need to make sure the points continue ascending or heading switches all over the place - if (A > B) { C = A; A = B; B = C; } + if (A > B) { int C = A; A = B; B = C; } //minDistA = 100; //int closestPt = 0; @@ -1324,7 +1205,7 @@ public bool DistanceFromYouTurnLine() } //just need to make sure the points continue ascending or heading switches all over the place - if (A > B) { C = A; A = B; B = C; } + if (A > B) { int C = A; A = B; B = C; } minDistA = 100; int closestPt = 0; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index 0c1cc25dc..251d328ae 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -780,30 +780,29 @@ private void setWorkingDirectoryToolStripMenuItem_Click(object sender, EventArgs if (Settings.Default.setF_workingDirectory == "Default") fbd.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); else fbd.SelectedPath = Settings.Default.setF_workingDirectory; - if (fbd.ShowDialog() == DialogResult.OK) + if (fbd.ShowDialog(this) == DialogResult.OK) { if (fbd.SelectedPath != Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) { Settings.Default.setF_workingDirectory = fbd.SelectedPath; - Settings.Default.Save(); } else { Settings.Default.setF_workingDirectory = "Default"; - Settings.Default.Save(); } + Settings.Default.Save(); //restart program MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); Close(); } } + private void enterSimCoordsToolStripMenuItem_Click(object sender, EventArgs e) { - var result = DialogResult.Cancel; using (var form = new FormSimCoords(this)) { - result = form.ShowDialog(); + form.ShowDialog(this); } } @@ -811,10 +810,10 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new Form_About()) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) { } + form.ShowDialog(this); } } + private void resetALLToolStripMenuItem_Click(object sender, EventArgs e) { if (isJobStarted) @@ -1020,14 +1019,12 @@ private void simulatorOnToolStripMenuItem_Click(object sender, EventArgs e) Settings.Default.setMenu_isSimulatorOn = simulatorOnToolStripMenuItem.Checked; Settings.Default.Save(); } + private void colorsToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new FormColor(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) - { - } + form.ShowDialog(this); } } @@ -1035,165 +1032,69 @@ private void colorsSectionToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new FormSectionColor(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) - { - } + form.ShowDialog(this); } } //Languages private void menuLanguageEnglish_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("en"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - + SetLanguage("en", true); } private void menuLanguageDanish_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("da"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - + SetLanguage("da", true); } private void menuLanguageDeutsch_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("de"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - + SetLanguage("de", true); } private void menuLanguageRussian_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("ru"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("ru", true); } private void menuLanguageDutch_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("nl"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("nl", true); } private void menuLanguageSpanish_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("es"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("es", true); } private void menuLanguageFrench_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("fr"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("fr", true); } private void menuLanguageItalian_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("it"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("it", true); } private void menuLanguageUkranian_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("uk"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("uk", true); } private void menuLanguageSlovak_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("sk"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - + SetLanguage("sk", true); } private void menuLanguagesPolski_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("pl"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("pl", true); } private void menuLanguageTest_Click(object sender, EventArgs e) { - if (isJobStarted) + SetLanguage("af", true); + } + + private void SetLanguage(string lang, bool Restart) + { + if (Restart && isJobStarted) { var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); form.Show(this); return; } - SetLanguage("af"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - } - private void SetLanguage(string lang) - { //reset them all to false menuLanguageEnglish.Checked = false; menuLanguageDeutsch.Checked = false; @@ -1274,6 +1175,12 @@ private void SetLanguage(string lang) //storing the values key.SetValue("Language", lang); key.Close(); + + if (Restart) + { + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); + } } #endregion @@ -1347,16 +1254,10 @@ public void CloseTopMosts() private void btnOpenConfig_Click(object sender, EventArgs e) { - //check if window already exists - - //Form form = new FormConfig(this); - //form.Show(this); - using (var form = new FormConfig(this)) { form.ShowDialog(this); } - } private void btnTramDisplayMode_Click(object sender, EventArgs e) @@ -1388,8 +1289,7 @@ private void btnChangeMappingColor_Click(object sender, EventArgs e) { using (var form = new FormColorPicker(this, sectionColorDay)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) + if (form.ShowDialog(this) == DialogResult.OK) { sectionColorDay = form.useThisColor; } @@ -1508,10 +1408,7 @@ public void GetAB() using (var form = new FormABDraw(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) - { - } + form.ShowDialog(this); ABLine.moveDistance = 0; curve.moveDistance = 0; } @@ -1610,8 +1507,7 @@ private void SmoothABtoolStripMenu_Click(object sender, EventArgs e) { using (var form = new FormSmoothAB(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) { } + form.ShowDialog(this); } } else @@ -1733,8 +1629,7 @@ private void offsetFixToolStrip_Click(object sender, EventArgs e) { using (var form = new FormShiftPos(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) { } + form.ShowDialog(this); } } @@ -1827,12 +1722,12 @@ private void toolStripBtnFieldOpen_Click(object sender, EventArgs e) { using (var form = new FormJob(this)) { - var result = form.ShowDialog(); + var result = form.ShowDialog(this); if (result == DialogResult.Yes) { //ask for a directory name using (var form2 = new FormFieldDir(this)) - { form2.ShowDialog(); } + { form2.ShowDialog(this); } } //load from KML @@ -1840,7 +1735,7 @@ private void toolStripBtnFieldOpen_Click(object sender, EventArgs e) { //ask for a directory name using (var form2 = new FormFieldKML(this)) - { form2.ShowDialog(); } + { form2.ShowDialog(this); } } } @@ -1913,7 +1808,7 @@ private void CloseCurrentJob() //ask for a directory name using (var form2 = new FormSaveAs(this)) { - form2.ShowDialog(); + form2.ShowDialog(this); } break; @@ -1926,8 +1821,7 @@ private void toolStripBtnMakeBndContour_Click(object sender, EventArgs e) //build all the contour guidance lines from boundaries, all of them. using (var form = new FormMakeBndCon(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) { } + form.ShowDialog(this); } } private void tramLinesMenuField_Click(object sender, EventArgs e) @@ -1971,7 +1865,7 @@ public void GetHeadland() { using (var form = new FormHeadland (this)) { - form.ShowDialog(); + form.ShowDialog(this); } if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) @@ -2000,8 +1894,7 @@ private void boundariesToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new FormBoundary(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) + if (form.ShowDialog(this) == DialogResult.OK) { Form form2 = new FormBoundaryPlayer(this); form2.Show(this); @@ -2205,33 +2098,6 @@ public void FixTramModeButton() default: break; } - - } - - private void googleEarthFlagsToolStrip_Click(object sender, EventArgs e) - { - if (isJobStarted) - { - //save new copy of flags - FileSaveFieldKML(); - - //Process.Start(@"C:\Program Files (x86)\Google\Google Earth\client\googleearth", workingDirectory + currentFieldDirectory + "\\Flags.KML"); - Process.Start(fieldsDirectory + currentFieldDirectory + "\\Field.KML"); - } - else - { - var form = new FormTimedMessage(1500, gStr.gsFieldNotOpen, gStr.gsStartNewField); - form.Show(this); - } } - private void ZoomExtentsStripBtn_Click(object sender, EventArgs e) - { - if (camera.camSetDistance < -400) camera.camSetDistance = -75; - else camera.camSetDistance = -3 * maxFieldDistance; - if (camera.camSetDistance == 0) camera.camSetDistance = -2000; - SetZoom(); - } - - private Button btnEditAB; }//end class }//end namespace \ No newline at end of file diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index 4718ceb52..a10590f96 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -10,9 +10,8 @@ public partial class FormBoundary : Form { private readonly FormGPS mf = null; - private bool Selectedreset = true; - private double easting, norting, latK, lonK; + private int fenceSelected = -1; public FormBoundary(Form callingForm) { @@ -119,7 +118,6 @@ private void UpdateChart() { //cc.Text = "Outer"; mf.bnd.bndList[i].isDriveThru = false; - mf.bnd.bndList[i].isDriveAround = false; a.Text = string.Format(gStr.gsOuter); //a.Font = backupfont; d.Text = mf.bnd.bndList[i].isDriveThru ? "--" : "--"; @@ -151,7 +149,7 @@ private void UpdateChart() b.Text = Math.Round(mf.bnd.bndList[i].area * 0.000247105, 2) + " Ac"; } - if (Selectedreset == false && i == mf.bnd.fenceSelected) + if (i == fenceSelected) { a.ForeColor = Color.OrangeRed; b.ForeColor = Color.OrangeRed; @@ -174,39 +172,21 @@ private void DriveThru_Click(object sender, EventArgs e) } } - private void DriveAround_Click(object sender, EventArgs e) - { - if (sender is Button b) - { - mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround = !mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround; - UpdateChart(); - } - } - private void B_Click(object sender, EventArgs e) { if (sender is Button b) { - - mf.bnd.fenceSelected = Convert.ToInt32(b.Name); - - if (mf.bnd.fenceSelected == 0 && mf.bnd.bndList.Count > 1) - { - return; - } - - Selectedreset = false; - - if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) - { + int oldfenceSelected = fenceSelected; + fenceSelected = Convert.ToInt32(b.Name); + + if (fenceSelected == oldfenceSelected) + fenceSelected = -1; + else if (fenceSelected == 0) + btnDelete.Enabled = mf.bnd.bndList.Count == 1; + else if (fenceSelected > 0) btnDelete.Enabled = true; - } - else - { - btnDelete.Enabled = false; - btnDeleteAll.Enabled = false; - } + btnDeleteAll.Enabled = fenceSelected == -1; } UpdateChart(); } @@ -229,15 +209,13 @@ private void btnDelete_Click(object sender, EventArgs e) btnDelete.Enabled = false; - if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) + if (mf.bnd.bndList.Count > fenceSelected) { - mf.bnd.bndList.RemoveAt(mf.bnd.fenceSelected); + mf.bnd.bndList.RemoveAt(fenceSelected); } + fenceSelected = -1; mf.FileSaveBoundary(); - - mf.bnd.fenceSelected = -1; - Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); mf.bnd.BuildTurnLines(); UpdateChart(); @@ -250,6 +228,7 @@ private void btnDelete_Click(object sender, EventArgs e) private void ResetAllBoundary() { + fenceSelected = -1; mf.bnd.bndList.Clear(); mf.FileSaveBoundary(); tableLayoutPanel1.Controls.Clear(); @@ -282,9 +261,6 @@ private void btnDeleteAll_Click(object sender, EventArgs e) ResetAllBoundary(); - mf.bnd.fenceSelected = -1; - Selectedreset = true; - mf.bnd.isOkToAddPoints = false; mf.fd.UpdateFieldBoundaryGUIAreas(); } @@ -310,10 +286,6 @@ private void btnReturn_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e) { - mf.bnd.fenceSelected = mf.bnd.bndList.Count; - - Selectedreset = false; - panelMain.Visible = false; panelKML.Visible = false; panelChoose.Visible = true; @@ -326,8 +298,6 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) { if (sender is Button button) { - Selectedreset = true; - string fileAndDirectory; { //create the dialog instance @@ -341,19 +311,17 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) }; //was a file selected - if (ofd.ShowDialog() == DialogResult.Cancel) return; + if (ofd.ShowDialog(this) == DialogResult.Cancel) return; else fileAndDirectory = ofd.FileName; } string coordinates = null; int startIndex; - int i = 0; using (StreamReader reader = new StreamReader(fileAndDirectory)) { if (button.Name == "btnLoadMultiBoundaryFromGE") ResetAllBoundary(); - else i = mf.bnd.fenceSelected; try { @@ -408,17 +376,14 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) New.fenceLine.Add(new vec3(easting, norting, 0)); } - New.CalculateFenceArea(mf.bnd.fenceSelected); - New.FixFenceLine(i); + New.CalculateFenceArea(mf.bnd.bndList.Count); + New.FixFenceLine(mf.bnd.bndList.Count); mf.bnd.bndList.Add(New); - mf.fd.UpdateFieldBoundaryGUIAreas(); - mf.btnMakeLinesFromBoundary.Visible = true; coordinates = ""; - i++; } else { diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 007aa0e2d..807c4bf42 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -36,24 +36,23 @@ private void btnStop_Click(object sender, EventArgs e) New.fenceLine.Add(mf.bnd.bndBeingMadePts[i]); } - New.CalculateFenceArea(mf.bnd.fenceSelected); - New.FixFenceLine(mf.bnd.fenceSelected); + New.CalculateFenceArea(mf.bnd.bndList.Count); + New.FixFenceLine(mf.bnd.bndList.Count); mf.bnd.bndList.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); + + //turn lines made from boundaries + mf.CalculateMinMax(); + mf.FileSaveBoundary(); + mf.bnd.BuildTurnLines(); + //mf.hd.BuildSingleSpaceHeadLines(); + mf.btnMakeLinesFromBoundary.Visible = true; } //stop it all for adding mf.bnd.isOkToAddPoints = false; mf.bnd.isBndBeingMade = false; - - //turn lines made from boundaries - mf.CalculateMinMax(); - mf.FileSaveBoundary(); - mf.bnd.BuildTurnLines(); - //mf.hd.BuildSingleSpaceHeadLines(); - mf.btnMakeLinesFromBoundary.Visible = true; - mf.bnd.bndBeingMadePts.Clear(); //close window Close(); diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 5b5a90d9c..7d772f4e4 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -121,12 +121,9 @@ private void LoadKMLBoundary(string filename) { string coordinates = null; int startIndex; - int i; using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.bnd.fenceSelected; - try { while (!reader.EndOfStream) @@ -183,26 +180,20 @@ private void LoadKMLBoundary(string filename) } //build the boundary, make sure is clockwise for outer counter clockwise for inner - New.CalculateFenceArea(mf.bnd.fenceSelected); - New.FixFenceLine(i); + New.CalculateFenceArea(mf.bnd.bndList.Count); + New.FixFenceLine(mf.bnd.bndList.Count); mf.bnd.bndList.Add(New); - mf.fd.UpdateFieldBoundaryGUIAreas(); - mf.btnMakeLinesFromBoundary.Visible = true; coordinates = ""; - i++; } else { mf.TimedMessageBox(2000, gStr.gsErrorreadingKML, gStr.gsChooseBuildDifferentone); } - //if (button.Name == "btnLoadBoundaryFromGE") - //{ break; - //} } } mf.FileSaveBoundary(); @@ -228,13 +219,9 @@ private void FindLatLon(string filename) { string coordinates = null; int startIndex; - int i; using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - - i = mf.bnd.fenceSelected; - try { while (!reader.EndOfStream) @@ -291,7 +278,6 @@ private void FindLatLon(string filename) latK = lat / counter; coordinates = ""; - i++; } else { diff --git a/SourceCode/GPS/Forms/FormGPS.Designer.cs b/SourceCode/GPS/Forms/FormGPS.Designer.cs index aa1df4b77..320e3b904 100644 --- a/SourceCode/GPS/Forms/FormGPS.Designer.cs +++ b/SourceCode/GPS/Forms/FormGPS.Designer.cs @@ -2392,6 +2392,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem toolStripBtnMakeBndContour; private System.Windows.Forms.ToolStripMenuItem sectionColorToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem enterABToolStripMenuItem; + private System.Windows.Forms.Button btnEditAB; } } diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index bff8a1a65..9a978b33f 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -4,7 +4,6 @@ using OpenTK; using OpenTK.Graphics.OpenGL; using System; -using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; @@ -430,7 +429,7 @@ private void FormGPS_Load(object sender, EventArgs e) pictureboxStart.Dock = System.Windows.Forms.DockStyle.Fill; //set the language to last used - SetLanguage(Settings.Default.setF_culture); + SetLanguage(Settings.Default.setF_culture, false); currentVersionStr = Application.ProductVersion.ToString(CultureInfo.InvariantCulture); @@ -748,25 +747,11 @@ public void SwapDirection() { if (!yt.isYouTurnTriggered) { - //is it turning right already? - if (yt.isYouTurnRight) - { - yt.isYouTurnRight = false; - yt.isLastYouTurnRight = !yt.isLastYouTurnRight; - yt.ResetCreatedYouTurn(); - } - else - { - //make it turn the other way - yt.isYouTurnRight = true; - yt.isLastYouTurnRight = !yt.isLastYouTurnRight; - yt.ResetCreatedYouTurn(); - } - } - else - { - if (yt.isYouTurnBtnOn) btnAutoYouTurn.PerformClick(); + yt.isYouTurnRight = !yt.isYouTurnRight; + yt.ResetCreatedYouTurn(); } + else if (yt.isYouTurnBtnOn) + btnAutoYouTurn.PerformClick(); } private void BuildMachineByte() @@ -823,7 +808,7 @@ public int SaveOrNot(bool closing) using (FormSaveOrNot form = new FormSaveOrNot(closing)) { - DialogResult result = form.ShowDialog(); + DialogResult result = form.ShowDialog(this); if (result == DialogResult.OK) return 0; //Save and Exit if (result == DialogResult.Ignore) return 1; //Ignore diff --git a/SourceCode/GPS/Forms/FormJob.cs b/SourceCode/GPS/Forms/FormJob.cs index e463beec3..2b91a6340 100644 --- a/SourceCode/GPS/Forms/FormJob.cs +++ b/SourceCode/GPS/Forms/FormJob.cs @@ -74,7 +74,7 @@ private void btnJobTouch_Click(object sender, EventArgs e) using (FormTouchPick form = new FormTouchPick(mf)) { //returns full field.txt file dir name - if (form.ShowDialog() == DialogResult.Yes) + if (form.ShowDialog(this) == DialogResult.Yes) { mf.FileOpenField(mf.filePickerFileAndDirectory); Close(); diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 05b2ecc47..53bb45e30 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -532,9 +532,6 @@ public void LoadSettings() ahrs = new CAHRS(); - //update the field data areas - fd.UpdateFieldBoundaryGUIAreas(); - //Set width of section and positions for each section SectionSetPosition(); diff --git a/SourceCode/GPS/Forms/Guidance/FormABLine.cs b/SourceCode/GPS/Forms/Guidance/FormABLine.cs index 0b40754d9..fa7aa78a7 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABLine.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABLine.cs @@ -442,11 +442,9 @@ private void btnAddTimeEdit_Click(object sender, EventArgs e) private void btnManual_Click(object sender, EventArgs e) { - var result = DialogResult.Cancel; using (var form = new FormEnterAB(mf)) { - result = form.ShowDialog(); - if (result == DialogResult.OK) + if (form.ShowDialog(this) == DialogResult.OK) { panelAPlus.Visible = false; panelName.Visible = true; diff --git a/SourceCode/GPS/Forms/Guidance/FormEditAB.cs b/SourceCode/GPS/Forms/Guidance/FormEditAB.cs index 7cba5cc08..999092edd 100644 --- a/SourceCode/GPS/Forms/Guidance/FormEditAB.cs +++ b/SourceCode/GPS/Forms/Guidance/FormEditAB.cs @@ -46,8 +46,7 @@ private void tboxHeading_Enter(object sender, EventArgs e) using (FormNumeric form = new FormNumeric(0, 360, Math.Round(glm.toDegrees(mf.ABLine.abHeading), 5))) { - DialogResult result = form.ShowDialog(); - if (result == DialogResult.OK) + if (form.ShowDialog(this) == DialogResult.OK) { tboxHeading.Text = ((double)form.ReturnValue).ToString(); mf.ABLine.abHeading = glm.toRadians((double)form.ReturnValue); diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index 945fa1975..b3bedef83 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -340,19 +340,23 @@ private void oglMain_Paint(object sender, PaintEventArgs e) //draw Boundaries bnd.DrawFenceLines(); + GL.LineWidth(ABLine.lineWidth); //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) { - bnd.DrawTurnLines(); + GL.Color3(0.3555f, 0.6232f, 0.20f); + for (int i = 0; i < bnd.bndList.Count; i++) + { + bnd.bndList[i].turnLine.DrawPolygon(); + } } if (bnd.isHeadlandOn) { - GL.LineWidth(ABLine.lineWidth); GL.Color3(0.960f, 0.96232f, 0.30f); for (int i = 0; i < bnd.bndList.Count; i++) { - if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLine(); + bnd.bndList[i].hdLine.DrawPolygon(); } } @@ -624,9 +628,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) { GL.LineWidth(3); GL.Color3((byte)0, (byte)240, (byte)0); - GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < ptCount; h++) GL.Vertex3(bnd.bndList[0].fenceLine[h].easting, bnd.bndList[0].fenceLine[h].northing, 0); - GL.End(); + bnd.bndList[0].fenceLine.DrawPolygon(); } } @@ -638,7 +640,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) for (int i = 0; i < bnd.bndList.Count; i++) { - if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLineBackBuffer(); + bnd.bndList[i].hdLine.DrawPolygon(); } } diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index fef8e4128..47f67a493 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -710,7 +710,7 @@ public void UpdateFixPosition() if (bnd.bndList.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (bnd.IsInsideAllFences(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (bnd.IsPointInsideFenceArea(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; @@ -1124,8 +1124,8 @@ private void AddSectionOrContourPathPoints() public void CalculateSectionLookAhead(double northing, double easting, double cosHeading, double sinHeading) { //calculate left side of section 1 - vec3 left = new vec3(); - vec3 right = left; + vec2 left = new vec2(); + vec2 right = left; double leftSpeed = 0, rightSpeed = 0; //speed max for section kmh*0.277 to m/s * 10 cm per pixel * 1.7 max speed @@ -1137,8 +1137,8 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (j == 0) { //only one first left point, the rest are all rights moved over to left - section[j].leftPoint = new vec3(cosHeading * (section[j].positionLeft) + easting, - sinHeading * (section[j].positionLeft) + northing,0); + section[j].leftPoint = new vec2(cosHeading * (section[j].positionLeft) + easting, + sinHeading * (section[j].positionLeft) + northing); left = section[j].leftPoint - section[j].lastLeftPoint; @@ -1163,8 +1163,8 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (leftSpeed > rightSpeed) leftSpeed = rightSpeed; } - section[j].rightPoint = new vec3(cosHeading * (section[j].positionRight) + easting, - sinHeading * (section[j].positionRight) + northing,0); + section[j].rightPoint = new vec2(cosHeading * (section[j].positionRight) + easting, + sinHeading * (section[j].positionRight) + northing); //now we have left and right for this section right = section[j].rightPoint - section[j].lastRightPoint; @@ -1250,44 +1250,17 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { if (bnd.bndList.Count > 0) { - if (j == 0) - { - //only one first left point, the rest are all rights moved over to left - isLeftIn = glm.IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[0].fenceLineEar); - isRightIn = glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); - - for (int i = 1; i < bnd.bndList.Count; i++) - { - //inner boundaries should normally NOT have point inside - isLeftIn &= !glm.IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[i].fenceLineEar); - isRightIn &= !glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); - } + //only one first left point, the rest are all rights moved over to left + isLeftIn = j == 0 ? bnd.IsPointInsideFenceArea(section[j].leftPoint) : isRightIn; + isRightIn = bnd.IsPointInsideFenceArea(section[j].rightPoint); - //merge the two sides into in or out - if (isLeftIn && isRightIn) section[j].isInBoundary = true; - else section[j].isInBoundary = false; - } + //merge the two sides into in or out + if (isLeftIn && isRightIn) section[j].isInBoundary = true; + else section[j].isInBoundary = false; - else - { - //grab the right of previous section, its the left of this section - isLeftIn = isRightIn; - isRightIn = glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); - for (int i = 1; i < bnd.bndList.Count; i++) - { - //inner boundaries should normally NOT have point inside - isRightIn &= !glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); - } - - if (isLeftIn && isRightIn) section[j].isInBoundary = true; - else section[j].isInBoundary = false; - } section[tool.numOfSections].isInBoundary &= section[j].isInBoundary; - } - - //no boundary created so always inside - else + else//no boundary created so always inside { section[j].isInBoundary = true; section[tool.numOfSections].isInBoundary = false; diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index f04c1bc4d..51ebb41e9 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -318,7 +318,7 @@ public void FileOpenField(string _openType) ofd.Filter = "Field files (Field.txt)|Field.txt"; //was a file selected - if (ofd.ShowDialog() == DialogResult.Cancel) fileAndDirectory = "Cancel"; + if (ofd.ShowDialog(this) == DialogResult.Cancel) fileAndDirectory = "Cancel"; else fileAndDirectory = ofd.FileName; break; } @@ -698,7 +698,6 @@ public void FileOpenField(string _openType) //Check for latest boundary files, then above line string is num of points if (line == "True" || line == "False") { - New.isDriveAround = bool.Parse(line); line = reader.ReadLine(); //number of points } @@ -1212,8 +1211,7 @@ public void FileSaveBoundary() for (int i = 0; i < bnd.bndList.Count; i++) { writer.WriteLine(bnd.bndList[i].isDriveThru); - writer.WriteLine(bnd.bndList[i].isDriveAround); - //writer.WriteLine(bnd.bndArr[i].isOwnField); + //writer.WriteLine(bnd.bndList[i].isDriveAround); writer.WriteLine(bnd.bndList[i].fenceLine.Count.ToString(CultureInfo.InvariantCulture)); if (bnd.bndList[i].fenceLine.Count > 0) diff --git a/SourceCode/GPS/Forms/Settings/FormSteer.cs b/SourceCode/GPS/Forms/Settings/FormSteer.cs index 8e383088b..b65496e92 100644 --- a/SourceCode/GPS/Forms/Settings/FormSteer.cs +++ b/SourceCode/GPS/Forms/Settings/FormSteer.cs @@ -381,7 +381,7 @@ private void hsbarIntegralPurePursuit_ValueChanged(object sender, EventArgs e) private void hsbarSideHillComp_ValueChanged(object sender, EventArgs e) { - double deg = (double)hsbarSideHillComp.Value; + double deg = hsbarSideHillComp.Value; deg *= 0.01; lblSideHillComp.Text = (deg.ToString("N2") + "\u00B0"); Properties.Settings.Default.setAS_sideHillComp = deg; From 983ef9860f8f62cd792ea914699b9706012e7809 Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Wed, 27 Oct 2021 07:23:21 -0600 Subject: [PATCH 13/18] Revert "Code Cleanup" This reverts commit 51e3e51af03610b3546778ce3fe3dd9d8fd9b706. --- SourceCode/GPS/AgOpenGPS.csproj | 3 + SourceCode/GPS/Classes/CABCurve.cs | 91 ++++++-- SourceCode/GPS/Classes/CABLine.cs | 18 +- SourceCode/GPS/Classes/CBoundary.cs | 6 +- SourceCode/GPS/Classes/CBoundaryList.cs | 6 +- SourceCode/GPS/Classes/CContour.cs | 18 +- SourceCode/GPS/Classes/CFence.cs | 130 ++++++++---- SourceCode/GPS/Classes/CFenceLine.cs | 44 +++- SourceCode/GPS/Classes/CGLM.cs | 27 +-- SourceCode/GPS/Classes/CHead.cs | 113 +++++++--- SourceCode/GPS/Classes/CHeadLines.cs | 34 +++ SourceCode/GPS/Classes/CSection.cs | 25 ++- SourceCode/GPS/Classes/CTurn.cs | 73 ++++--- SourceCode/GPS/Classes/CTurnLines.cs | 41 +++- SourceCode/GPS/Classes/CYouTurn.cs | 209 +++++++++++++++---- SourceCode/GPS/Forms/Controls.Designer.cs | 220 ++++++++++++++++---- SourceCode/GPS/Forms/FormBoundary.cs | 71 +++++-- SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 19 +- SourceCode/GPS/Forms/FormFieldKML.cs | 18 +- SourceCode/GPS/Forms/FormGPS.Designer.cs | 1 - SourceCode/GPS/Forms/FormGPS.cs | 27 ++- SourceCode/GPS/Forms/FormJob.cs | 2 +- SourceCode/GPS/Forms/GUI.Designer.cs | 3 + SourceCode/GPS/Forms/Guidance/FormABLine.cs | 4 +- SourceCode/GPS/Forms/Guidance/FormEditAB.cs | 3 +- SourceCode/GPS/Forms/OpenGL.Designer.cs | 16 +- SourceCode/GPS/Forms/Position.designer.cs | 55 +++-- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 6 +- SourceCode/GPS/Forms/Settings/FormSteer.cs | 2 +- 29 files changed, 983 insertions(+), 302 deletions(-) create mode 100644 SourceCode/GPS/Classes/CHeadLines.cs diff --git a/SourceCode/GPS/AgOpenGPS.csproj b/SourceCode/GPS/AgOpenGPS.csproj index d8d2bf0b8..2b1114007 100644 --- a/SourceCode/GPS/AgOpenGPS.csproj +++ b/SourceCode/GPS/AgOpenGPS.csproj @@ -131,6 +131,9 @@ + + CBoundaryList.cs + CBoundary.cs diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index 39a2fbffb..17ea9d2d4 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -725,18 +725,51 @@ public void BuildTram() } if (Add) { - //a new point only every 2 meters - double dist = mf.tram.tramArr.Count > 0 ? ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) - + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)) : 3.0; - if (dist > 2) + if (isBndExist) { - //if inside the boundary, add - if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(point)) + if (mf.tram.tramArr.Count > 0) + { + //a new point only every 2 meters + double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) + + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); + if (dist > 2) + { + //if inside the boundary, add + if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar )) + { + mf.tram.tramArr.Add(point); + } + } + } + else + { + //need a first point to do distance + if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) + { + mf.tram.tramArr.Add(point); + } + } + } + else + { + //no boundary to cull points + if (mf.tram.tramArr.Count > 0) + { + double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) + + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); + if (dist > 2) + { + mf.tram.tramArr.Add(point); + } + } + else { mf.tram.tramArr.Add(point); } + } } + } } @@ -773,16 +806,48 @@ public void BuildTram() } if (Add) { - //a new point only every 2 meters - double dist = mf.tram.tramArr.Count > 0 ? ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) - + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)) : 3.0; - if (dist > 2) + if (isBndExist) { - //if inside the boundary, add - if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(point)) + if (mf.tram.tramArr.Count > 0) + { + //a new point only every 2 meters + double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) + + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); + if (dist > 2) + { + //if inside the boundary, add + if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) + { + mf.tram.tramArr.Add(point); + } + } + } + else + { + //need a first point to do distance + if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) + { + mf.tram.tramArr.Add(point); + } + } + } + else + { + //no boundary to cull points + if (mf.tram.tramArr.Count > 0) + { + double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) + + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); + if (dist > 2) + { + mf.tram.tramArr.Add(point); + } + } + else { mf.tram.tramArr.Add(point); } + } } } @@ -955,6 +1020,8 @@ public void ResetCurveLine() refList?.Clear(); isCurveSet = false; } + + ////draw the guidance line } public class CCurveLines diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index 832af3870..df7fbbd1a 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -493,7 +493,14 @@ public void BuildTram() P1.easting = (hsin * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].easting; P1.northing = (hcos * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].northing; - if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(P1)) + if (isBndExist) + { + if (glm.IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) + { + mf.tram.tramArr.Add(P1); + } + } + else { mf.tram.tramArr.Add(P1); } @@ -514,7 +521,14 @@ public void BuildTram() P1.easting = (hsin * ((mf.tram.tramWidth * (pass + i)) + mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].easting; P1.northing = (hcos * ((mf.tram.tramWidth * (pass + i)) + mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].northing; - if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(P1)) + if (isBndExist) + { + if (glm.IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) + { + mf.tram.tramArr.Add(P1); + } + } + else { mf.tram.tramArr.Add(P1); } diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index f4cf9bb19..7a67962d7 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; namespace AgOpenGPS { @@ -13,9 +15,11 @@ public partial class CBoundary public CBoundary(FormGPS _f) { mf = _f; + fenceSelected = 0; boxLength = 2000; turnSelected = 0; isHeadlandOn = false; + isToolUp = true; } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CBoundaryList.cs b/SourceCode/GPS/Classes/CBoundaryList.cs index 3114a70a5..0b52a3b28 100644 --- a/SourceCode/GPS/Classes/CBoundaryList.cs +++ b/SourceCode/GPS/Classes/CBoundaryList.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using OpenTK.Graphics.OpenGL; +using System; +using System.Collections.Generic; namespace AgOpenGPS { @@ -10,10 +12,12 @@ public partial class CBoundaryList public List hdLine = new List(128); public List turnLine = new List(128); + //constructor public CBoundaryList() { area = 0; + isDriveAround = false; isDriveThru = false; } } diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index 086a4cba3..4ae78d278 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -313,10 +313,10 @@ public void BuildContourGuidanceLine(vec3 pivot, vec3 steer) stripNum = 0; for (int s = 0; s < stripCount; s++) { + double dist = 0; int p; ptCount = stripList[s].Count; if (ptCount == 0) continue; - double dist; for (p = 0; p < ptCount; p += 6) { dist = ((pivot.easting - stripList[s][p].easting) * (pivot.easting - stripList[s][p].easting)) @@ -515,10 +515,13 @@ public void BuildContourGuidanceLine(vec3 pivot, vec3 steer) stop = pt + 6; if (stop > ptCount) stop = ptCount; } + double distAway = 0; + double distSqAway = 0; + //if (howManyPathsAway != 0 && (mf.tool.halfToolWidth < (0.5*mf.tool.toolOffset))) { - double distAway = (mf.tool.toolWidth - mf.tool.toolOverlap) * howManyPathsAway + (isSameWay ? -mf.tool.toolOffset : mf.tool.toolOffset); - double distSqAway = (distAway * distAway) * 0.97; + distAway = (mf.tool.toolWidth - mf.tool.toolOverlap) * howManyPathsAway + (isSameWay ? -mf.tool.toolOffset : mf.tool.toolOffset); + distSqAway = (distAway * distAway) * 0.97; for (int i = start; i < stop; i++) @@ -842,7 +845,8 @@ public void StartContourLine(vec3 pivot) if (stripList.Count == 0) { //make new ptList - ptList = new List(16); + ptList = new List(); + ptList.Capacity = 16; //ptList.Add(new vec3(pivot.easting + Math.Cos(pivot.heading) // * mf.tool.toolOffset, pivot.northing - Math.Sin(pivot.heading) * mf.tool.toolOffset, pivot.heading)); stripList.Add(ptList); @@ -878,6 +882,7 @@ public void StopContourLine(vec3 pivot) double head = ptList[0].heading; int length = (int)mf.tool.toolWidth+3; vec3 pnt; + int ptc = ctList.Count - 1; for (int a = 0; a < length; a ++) { pnt.easting = ptList[0].easting - (Math.Sin(head)); @@ -886,7 +891,7 @@ public void StopContourLine(vec3 pivot) ptList.Insert(0, pnt); } - int ptc = ptList.Count - 1; + ptc = ptList.Count - 1; head = ptList[ptc].heading; for (double i = 1; i < length; i += 1) @@ -900,7 +905,8 @@ public void StopContourLine(vec3 pivot) //add the point list to the save list for appending to contour file mf.contourSaveList.Add(ptList); - ptList = new List(32); + ptList = new List(); + ptList.Capacity = 32; stripList.Add(ptList); } diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs index f32d948c0..3a18c4588 100644 --- a/SourceCode/GPS/Classes/CFence.cs +++ b/SourceCode/GPS/Classes/CFence.cs @@ -11,69 +11,47 @@ public partial class CBoundary public double createBndOffset; public bool isBndBeingMade; + // the list of possible bounds points + public List bndClosestList = new List(); + public bool isDrawRightSide = true, isOkToAddPoints = false; - public int closestFenceNum; + public int fenceSelected, closestFenceNum; //point at the farthest boundary segment from pivotAxle public vec3 closestFencePt = new vec3(-10000, -10000, 9); - public bool IsPointInsideFenceArea(vec3 testPoint) + public bool IsInsideAllFences(vec3 testPoint) { //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (bndList[0].fenceLineEar.IsPointInPolygon(testPoint)) + if (glm.IsPointInPolygon(testPoint, ref bndList[0].fenceLine)) { for (int i = 1; i < bndList.Count; i++) { //make sure not inside a non drivethru boundary if (bndList[i].isDriveThru) continue; - if (bndList[i].fenceLineEar.IsPointInPolygon(testPoint)) + if (glm.IsPointInPolygon(testPoint, ref bndList[i].fenceLine)) { return false; } } - //we are safely inside outer, outside inner boundaries - return true; } - return false; - } - - public bool IsPointInsideFenceArea(vec2 testPoint) - { - //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (bndList[0].fenceLineEar.IsPointInPolygon(testPoint)) + else { - for (int i = 1; i < bndList.Count; i++) - { - //make sure not inside a non drivethru boundary - if (bndList[i].isDriveThru) continue; - if (bndList[i].fenceLineEar.IsPointInPolygon(testPoint)) - { - return false; - } - } - //we are safely inside outer, outside inner boundaries - return true; + return false; } - return false; + //we are safely inside outer, outside inner boundaries + return true; } public void DrawFenceLines() { - if (!mf.mc.isOutOfBounds) - { - GL.Color3(0.95f, 0.75f, 0.50f); - GL.LineWidth(mf.ABLine.lineWidth); - } - else - { - GL.LineWidth(mf.ABLine.lineWidth * 3); - GL.Color3(0.95f, 0.25f, 0.250f); - } + //draw the boundaries + GL.Color3(0.75f, 0.5f, 0.250f); for (int i = 0; i < bndList.Count; i++) { - bndList[i].fenceLine.DrawPolygon(); + bndList[i].DrawFenceLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); } if (bndBeingMadePts.Count > 0) @@ -122,4 +100,82 @@ public void DrawFenceLines() } } -} \ No newline at end of file +} + + +//public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) + //{ + // { + // boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); + // boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); + + // boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); + // boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); + + // boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); + // boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); + + // boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); + // boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); + // } + + // int ptCount; + + // //determine if point is inside bounding box + // bndClosestList.Clear(); + // vec4 inBox; + // for (int i = 0; i < plots.Count; i++) + // { + // //skip the drive thru + // if (plots[i].isDriveThru) continue; + + // ptCount = plots[i].bndLine.Count; + // for (int p = 0; p < ptCount; p++) + // { + // if ((((boxB.easting - boxA.easting) * (plots[i].bndLine[p].northing - boxA.northing)) + // - ((boxB.northing - boxA.northing) * (plots[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } + + // if ((((boxD.easting - boxC.easting) * (plots[i].bndLine[p].northing - boxC.northing)) + // - ((boxD.northing - boxC.northing) * (plots[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } + + // if ((((boxC.easting - boxB.easting) * (plots[i].bndLine[p].northing - boxB.northing)) + // - ((boxC.northing - boxB.northing) * (plots[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } + + // if ((((boxA.easting - boxD.easting) * (plots[i].bndLine[p].northing - boxD.northing)) + // - ((boxA.northing - boxD.northing) * (plots[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } + + // //it's in the box, so add to list + // inBox.easting = plots[i].bndLine[p].easting; + // inBox.northing = plots[i].bndLine[p].northing; + // inBox.heading = plots[i].bndLine[p].heading; + // inBox.index = i; + + // //which boundary/headland is it from + // bndClosestList.Add(inBox); + // } + // } + + // //which of the points is closest + // closestBoundaryPt.easting = -20000; closestBoundaryPt.northing = -20000; + // ptCount = bndClosestList.Count; + // if (ptCount != 0) + // { + // //determine closest point + // double minDistance = 9999999; + // for (int i = 0; i < ptCount; i++) + // { + // double dist = ((fromPt.easting - bndClosestList[i].easting) * (fromPt.easting - bndClosestList[i].easting)) + // + ((fromPt.northing - bndClosestList[i].northing) * (fromPt.northing - bndClosestList[i].northing)); + // if (minDistance >= dist) + // { + // minDistance = dist; + + // closestBoundaryPt.easting = bndClosestList[i].easting; + // closestBoundaryPt.northing = bndClosestList[i].northing; + // closestBoundaryPt.heading = bndClosestList[i].heading; + // closestBoundaryNum = bndClosestList[i].index; + // } + // } + // if (closestBoundaryPt.heading < 0) closestBoundaryPt.heading += glm.twoPI; + // } + //} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CFenceLine.cs b/SourceCode/GPS/Classes/CFenceLine.cs index b4aceed01..9a84e554b 100644 --- a/SourceCode/GPS/Classes/CFenceLine.cs +++ b/SourceCode/GPS/Classes/CFenceLine.cs @@ -1,4 +1,7 @@ using System; +using System.Collections.Generic; +using System.Linq; +using OpenTK.Graphics.OpenGL; namespace AgOpenGPS { @@ -8,7 +11,7 @@ public partial class CBoundaryList public double area; //boundary variables - public bool isDriveThru; + public bool isDriveAround, isDriveThru; public void CalculateFenceLineHeadings() { @@ -145,11 +148,47 @@ public void ReverseWinding() } } + public void DrawFenceLine(int lw, bool outOfBounds) + { + ////draw the perimeter line so far + if (fenceLine.Count < 1) return; + //GL.PointSize(8); + //int ptCount = bndLine.Count; + //GL.Color3(0.925f, 0.752f, 0.860f); + ////else + //GL.Begin(PrimitiveType.Points); + //for (int h = 0; h < ptCount; h++) GL.Vertex3(bndLine[h].easting, bndLine[h].northing, 0); + ////GL.Color3(0.95f, 0.972f, 0.90f); + ////GL.Vertex3(bndLine[0].easting, bndLine[0].northing, 0); + //GL.End(); + + //ptCount = bdList.Count; + //if (ptCount < 1) return; + if (!outOfBounds) + { + GL.Color3(0.95f, 0.75f, 0.50f); + GL.LineWidth(lw); + } + else + { + GL.LineWidth(lw * 3); + GL.Color3(0.95f, 0.25f, 0.250f); + } + + GL.Begin(PrimitiveType.LineLoop); + for (int i = 0; i < fenceLineEar.Count; i++) + { + GL.Vertex3(fenceLineEar[i].easting, fenceLineEar[i].northing, 0); + } + GL.End(); + } + //obvious public bool CalculateFenceArea(int idx) { int ptCount = fenceLine.Count; if (ptCount < 1) return false; + bool isClockwise = true; area = 0; // Accumulates area in the loop int j = ptCount - 1; // The last vertex is the 'previous' one to the first @@ -158,8 +197,7 @@ public bool CalculateFenceArea(int idx) { area += (fenceLine[j].easting + fenceLine[i].easting) * (fenceLine[j].northing - fenceLine[i].northing); } - - bool isClockwise = area >= 0; + if (area < 0) isClockwise = false; area = Math.Abs(area / 2); diff --git a/SourceCode/GPS/Classes/CGLM.cs b/SourceCode/GPS/Classes/CGLM.cs index ab792ea4d..ea5a52bbc 100644 --- a/SourceCode/GPS/Classes/CGLM.cs +++ b/SourceCode/GPS/Classes/CGLM.cs @@ -1,12 +1,12 @@ -using OpenTK.Graphics.OpenGL; -using System; +using System; using System.Collections.Generic; +using System.Windows.Forms; namespace AgOpenGPS { public static class glm { - public static bool IsPointInPolygon(this List polygon, vec3 testPoint) + public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) { bool result = false; int j = polygon.Count - 1; @@ -27,7 +27,7 @@ public static bool IsPointInPolygon(this List polygon, vec3 testPoint) return result; } - public static bool IsPointInPolygon(this List polygon, vec2 testPoint) + public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) { bool result = false; int j = polygon.Count - 1; @@ -47,8 +47,7 @@ public static bool IsPointInPolygon(this List polygon, vec2 testPoint) } return result; } - - public static bool IsPointInPolygon(this List polygon, vec2 testPoint) + public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) { bool result = false; int j = polygon.Count - 1; @@ -68,8 +67,7 @@ public static bool IsPointInPolygon(this List polygon, vec2 testPoint) } return result; } - - public static bool IsPointInPolygon(this List polygon, vec3 testPoint) + public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) { bool result = false; int j = polygon.Count - 1; @@ -90,19 +88,6 @@ public static bool IsPointInPolygon(this List polygon, vec3 testPoint) return result; } - public static void DrawPolygon(this List polygon) - { - if (polygon.Count > 1) - { - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < polygon.Count; i++) - { - GL.Vertex3(polygon[i].easting, polygon[i].northing, 0); - } - GL.End(); - } - } - // Catmull Rom interpoint spline calculation public static vec3 Catmull(double t, vec3 p0, vec3 p1, vec3 p2, vec3 p3) { diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index ae0a347ce..08dcdae02 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -5,7 +5,18 @@ namespace AgOpenGPS public partial class CBoundary { public bool isHeadlandOn; - public bool isToolInHeadland, isToolOuterPointsInHeadland; + public double leftToolDistance; + public double rightToolDistance; + + //generated box for finding closest point + public vec2 downL = new vec2(9000, 9000), downR = new vec2(9000, 9002); + + public bool isToolInHeadland, isToolUp, isToolOuterPointsInHeadland; + + public bool isToolLeftIn = false; + public bool isToolRightIn = false; + public bool isLookRightIn = false; + public bool isLookLeftIn = false; public void SetHydPosition() { @@ -14,10 +25,12 @@ public void SetHydPosition() if (isToolInHeadland) { mf.p_239.pgn[mf.p_239.hydLift] = 2; + isToolUp = true; } else { mf.p_239.pgn[mf.p_239.hydLift] = 1; + isToolUp = false; } } } @@ -28,24 +41,44 @@ public void WhereAreToolCorners() { bool isLeftInWk, isRightInWk = true; - for (int j = 0; j < mf.tool.numOfSections; j++) + if (isHeadlandOn) { - isLeftInWk = j == 0 ? IsPointInsideHeadArea(mf.section[j].leftPoint) : isRightInWk; - isRightInWk = IsPointInsideHeadArea(mf.section[j].rightPoint); + for (int j = 0; j < mf.tool.numOfSections; j++) + { + if (j == 0) + { + //only one first left point, the rest are all rights moved over to left + isLeftInWk = glm.IsPointInPolygon(mf.section[j].leftPoint, ref bndList[0].hdLine); + isRightInWk = glm.IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); + + //save left side + mf.tool.isLeftSideInHeadland = !isLeftInWk; + + //merge the two sides into in or out + mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; + + } + else + { + //grab the right of previous section, its the left of this section + isLeftInWk = isRightInWk; + isRightInWk = glm.IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); + + mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; + } + } - //save left side - if (j == 0) - mf.tool.isLeftSideInHeadland = !isLeftInWk; + //save right side + mf.tool.isRightSideInHeadland = !isRightInWk; - //merge the two sides into in or out - mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; + //is the tool in or out based on endpoints + isToolOuterPointsInHeadland = mf.tool.isLeftSideInHeadland && mf.tool.isRightSideInHeadland; + } + else + { + //set all to true; + isToolOuterPointsInHeadland = true; } - - //save right side - mf.tool.isRightSideInHeadland = !isRightInWk; - - //is the tool in or out based on endpoints - isToolOuterPointsInHeadland = mf.tool.isLeftSideInHeadland && mf.tool.isRightSideInHeadland; } } @@ -53,43 +86,54 @@ public void WhereAreToolLookOnPoints() { if (bndList.Count > 0 && bndList[0].hdLine.Count > 0) { - bool isLookRightIn = false; - vec3 toolFix = mf.toolPos; double sinAB = Math.Sin(toolFix.heading); double cosAB = Math.Cos(toolFix.heading); - //generated box for finding closest point - double pos = 0; + double pos = mf.section[0].rpSectionWidth; double mOn = (mf.tool.lookAheadDistanceOnPixelsRight - mf.tool.lookAheadDistanceOnPixelsLeft) / mf.tool.rpWidth; + double endHeight = (mf.tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * 0.1; for (int j = 0; j < mf.tool.numOfSections; j++) { + if (j == 0) + { + downL.easting = mf.section[j].leftPoint.easting + (sinAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1); + downL.northing = mf.section[j].leftPoint.northing + (cosAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1); + + downR.easting = mf.section[j].rightPoint.easting + (sinAB * endHeight); + downR.northing = mf.section[j].rightPoint.northing + (cosAB * endHeight); - bool isLookLeftIn = j == 0 ? IsPointInsideHeadArea(new vec2( - mf.section[j].leftPoint.easting + (sinAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1), - mf.section[j].leftPoint.northing + (cosAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1))) : isLookRightIn; + isLookLeftIn = IsPointInsideHeadLine(downL); + isLookRightIn = IsPointInsideHeadLine(downR); - pos += mf.section[j].rpSectionWidth; - double endHeight = (mf.tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * 0.1; + mf.section[j].isLookOnInHeadland = !isLookLeftIn && !isLookRightIn; + isLookLeftIn = isLookRightIn; + } + else + { + pos += mf.section[j].rpSectionWidth; + endHeight = (mf.tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * 0.1; - isLookRightIn = IsPointInsideHeadArea(new vec2( - mf.section[j].rightPoint.easting + (sinAB * endHeight), - mf.section[j].rightPoint.northing + (cosAB * endHeight))); + downR.easting = mf.section[j].rightPoint.easting + (sinAB * endHeight); + downR.northing = mf.section[j].rightPoint.northing + (cosAB * endHeight); - mf.section[j].isLookOnInHeadland = !isLookLeftIn && !isLookRightIn; + isLookRightIn = IsPointInsideHeadLine(downR); + mf.section[j].isLookOnInHeadland = !isLookLeftIn && !isLookRightIn; + isLookLeftIn = isLookRightIn; + } } } } - public bool IsPointInsideHeadArea(vec2 pt) + public bool IsPointInsideHeadLine(vec2 pt) { //if inside outer boundary, then potentially add - if (bndList[0].hdLine.IsPointInPolygon(pt)) + if (bndList.Count > 0 && glm.IsPointInPolygon(pt, ref bndList[0].hdLine)) { - for (int i = 1; i < bndList.Count; i++) + for (int b = 1; b < bndList.Count; b++) { - if (bndList[i].hdLine.IsPointInPolygon(pt)) + if (glm.IsPointInPolygon(pt, ref bndList[b].hdLine)) { //point is in an inner turn area but inside outer return false; @@ -97,7 +141,10 @@ public bool IsPointInsideHeadArea(vec2 pt) } return true; } - return false; + else + { + return false; + } } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CHeadLines.cs b/SourceCode/GPS/Classes/CHeadLines.cs new file mode 100644 index 000000000..634e61b08 --- /dev/null +++ b/SourceCode/GPS/Classes/CHeadLines.cs @@ -0,0 +1,34 @@ +using OpenTK.Graphics.OpenGL; + +namespace AgOpenGPS +{ + public partial class CBoundaryList + { + + public void DrawHeadLine() + { + if (hdLine.Count > 1) + { + GL.Begin(PrimitiveType.LineLoop); + for (int i = 0; i < hdLine.Count; i++) + { + GL.Vertex3(hdLine[i].easting, hdLine[i].northing, 0); + } + GL.End(); + } + } + + public void DrawHeadLineBackBuffer() + { + if (hdLine.Count > 1) + { + GL.Begin(PrimitiveType.LineLoop); + for (int i = 0; i < hdLine.Count; i++) + { + GL.Vertex3(hdLine[i].easting, hdLine[i].northing, 0); + } + GL.End(); + } + } + } +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CSection.cs b/SourceCode/GPS/Classes/CSection.cs index 4f08ef877..ad81f2090 100644 --- a/SourceCode/GPS/Classes/CSection.cs +++ b/SourceCode/GPS/Classes/CSection.cs @@ -67,12 +67,12 @@ public class CSection public int rpSectionPosition = 0; //points in world space that start and end of section are in - public vec2 leftPoint; - public vec2 rightPoint; + public vec3 leftPoint; + public vec3 rightPoint; //used to determine left and right speed of section - public vec2 lastLeftPoint; - public vec2 lastRightPoint; + public vec3 lastLeftPoint; + public vec3 lastRightPoint; //whether or not this section is in boundary, headland public bool isInBoundary = true, isHydLiftInWorkArea = true; @@ -103,7 +103,8 @@ public void TurnMappingOn(int j) isMappingOn = true; //starting a new patch chunk so create a new triangle list - triangleList = new List(32); + triangleList = new List(); + triangleList.Capacity = 16; patchList.Add(triangleList); @@ -204,15 +205,23 @@ public void AddMappingPoint(int j) //save the cutoff patch to be saved later mf.patchSaveList.Add(triangleList); - triangleList = new List(32); + triangleList = new List(); + triangleList.Capacity = 32; patchList.Add(triangleList); //Add Patch colour if (!mf.tool.isMultiColoredSections) - triangleList.Add(new vec3(mf.sectionColorDay.R, mf.sectionColorDay.G, mf.sectionColorDay.B)); + { + vec3 colur = new vec3(mf.sectionColorDay.R, mf.sectionColorDay.G, mf.sectionColorDay.B); + triangleList.Add(colur); + } + else - triangleList.Add(new vec3(mf.tool.secColors[j].R, mf.tool.secColors[j].G, mf.tool.secColors[j].B)); + { + vec3 collor = new vec3(mf.tool.secColors[j].R, mf.tool.secColors[j].G, mf.tool.secColors[j].B); + triangleList.Add(collor); + } //add the points to List, yes its more points, but breaks up patches for culling triangleList.Add(point); diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index 3e48d16f3..2dc00743c 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -1,4 +1,5 @@ -using System; +using OpenTK.Graphics.OpenGL; +using System; using System.Collections.Generic; namespace AgOpenGPS @@ -20,29 +21,13 @@ public partial class CBoundary //point at the farthest turn segment from pivotAxle public vec3 closestTurnPt = new vec3(-10000, -10000, 9); - public int IsPointInsideTurnArea(vec3 pt) - { - if (bndList.Count > 0 && bndList[0].turnLine.IsPointInPolygon(pt)) - { - for (int i = 1; i < bndList.Count; i++) - { - if (bndList[i].isDriveThru) continue; - if (bndList[i].turnLine.IsPointInPolygon(pt)) - { - return i; - } - } - return 0; - } - return -1; - } - public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB) { //initial scan is straight ahead of pivot point of vehicle to find the right turnLine/boundary vec3 pt = new vec3(); vec3 rayPt = new vec3(); + bool isFound = false; int closestTurnNum = 99; double cosHead = Math.Cos(headAB); @@ -53,16 +38,31 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - int idx = IsPointInsideTurnArea(pt); - if (idx != 0) + if (glm.IsPointInPolygon(pt, ref bndList[0].turnLine)) + { + for (int t = 1; t < bndList.Count; t++) + { + if (bndList[t].isDriveThru) continue; + if (bndList[t].isDriveAround) continue; + if (glm.IsPointInPolygon(pt, ref bndList[t].turnLine)) + { + isFound = true; + closestTurnNum = t; + rayPt.easting = pt.easting; + rayPt.northing = pt.northing; + break; + } + } + if (isFound) break; + } + else { - closestTurnNum = idx; + closestTurnNum = 0; rayPt.easting = pt.easting; rayPt.northing = pt.northing; break; } } - if (closestTurnNum < 0) closestTurnNum = 0; //second scan is straight ahead of outside of tool based on turn direction double scanWidthL, scanWidthR; @@ -207,6 +207,9 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB public void BuildTurnLines() { + //update the GUI values for boundaries + mf.fd.UpdateFieldBoundaryGUIAreas(); + if (bndList.Count == 0) { //mf.TimedMessageBox(1500, " No Boundaries", "No Turn Lines Made"); @@ -223,7 +226,7 @@ public void BuildTurnLines() for (int j = 0; j < bndList.Count; j++) { bndList[j].turnLine.Clear(); - if (bndList[j].isDriveThru) continue; + if (bndList[j].isDriveThru || bndList[j].isDriveAround) continue; int ptCount = bndList[j].fenceLine.Count; @@ -236,7 +239,7 @@ public void BuildTurnLines() if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == bndList[j].fenceLineEar.IsPointInPolygon(point)) + if (j == 0 == glm.IsPointInPolygon(point, ref bndList[j].fenceLineEar)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); bndList[j].turnLine.Add(tPnt); @@ -245,5 +248,27 @@ public void BuildTurnLines() bndList[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); } } + + public void DrawTurnLines() + { + GL.LineWidth(mf.ABLine.lineWidth); + GL.Color3(0.3555f, 0.6232f, 0.20f); + //GL.PointSize(2); + + for (int i = 0; i < bndList.Count; i++) + { + if (bndList[i].isDriveAround) continue; + //turnArr[i].DrawTurnLine(); + { + ////draw the turn line oject + int ptCount = bndList[i].turnLine.Count; + if (ptCount < 1) continue; + + GL.Begin(PrimitiveType.LineLoop); + for (int h = 0; h < ptCount; h++) GL.Vertex3(bndList[i].turnLine[h].easting, bndList[i].turnLine[h].northing, 0); + GL.End(); + } + } + } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CTurnLines.cs b/SourceCode/GPS/Classes/CTurnLines.cs index 91dd97b7a..83bd604fd 100644 --- a/SourceCode/GPS/Classes/CTurnLines.cs +++ b/SourceCode/GPS/Classes/CTurnLines.cs @@ -1,4 +1,5 @@ -using System; +using OpenTK.Graphics.OpenGL; +using System; namespace AgOpenGPS { @@ -98,6 +99,44 @@ public void FixTurnLine(double totalHeadWidth, double spacing) { CalculateTurnHeadings(); } + + //int cnt = turnLine.Count; + //vec3[] arr = new vec3[cnt]; + //turnLine.CopyTo(arr); + //turnLine.Clear(); + + //double delta = 0; + //for (int i = 0; i < arr.Length; i++) + //{ + // if (i == 0) + // { + // turnLine.Add(new vec3(arr[i].easting, arr[i].northing, arr[i].heading)); + // continue; + // } + // delta += (arr[i - 1].heading - arr[i].heading); + + // if (Math.Abs(delta) > 0.1) + // { + // vec3 pt = new vec3(arr[i].easting, arr[i].northing, arr[i].heading); + + // turnLine.Add(pt); + // delta = 0; + // } + //} + } + + public void DrawTurnLine() + { + ////draw the turn line oject + int ptCount = turnLine.Count; + if (ptCount < 1) return; + GL.LineWidth(1); + GL.Color3(0.8555f, 0.9232f, 0.60f); + GL.PointSize(2); + GL.Begin(PrimitiveType.LineLoop); + for (int h = 0; h < ptCount; h++) GL.Vertex3(turnLine[h].easting, turnLine[h].northing, 0); + GL.Vertex3(turnLine[0].easting, turnLine[0].northing, 0); + GL.End(); } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index c629aba89..df0268fdb 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -13,12 +13,24 @@ public class CYouTurn public bool isYouTurnTriggered; /// /// turning right or left?/// - public bool isYouTurnRight; + public bool isYouTurnRight, isLastToggle; + + /// /// What was the last successful you turn direction? /// + public bool isLastYouTurnRight; + + //public bool isEnteringDriveThru = false, isExitingDriveThru = false; + + //if not in workArea but in bounds, then we are on headland + public bool isInWorkArea, isInBoundz; + + //controlled by user in GUI to en/dis able + public bool isRecordingCustomYouTurn; /// /// Is the youturn button enabled? /// public bool isYouTurnBtnOn; public double boundaryAngleOffPerpendicular; + public double distanceTurnBeforeLine = 0, tangencyAngle; public int rowSkipsWidth = 1, uTurnSmoothing = 10; @@ -26,7 +38,7 @@ public class CYouTurn public int rowSkipsWidth2 = 3, turnSkips = 2; /// /// distance from headland as offset where to start turn shape /// - public int youTurnStartOffset; + public int youTurnStartOffset, C; //guidance values public double distanceFromCurrentLine, uturnDistanceFromBoundary, dxAB, dyAB; @@ -52,14 +64,20 @@ public class CYouTurn //list of points for scaled and rotated YouTurn line, used for pattern, dubins, abcurve, abline public List ytList = new List(); + ////list of points read from file, this is the actual pattern from a bunch of sources possible + //public List youFileList = new List(); + + //to try and pull a UTurn back in bounds + public double turnDistanceAdjuster; + //is UTurn pattern in or out of bounds public bool isOutOfBounds = false; //sequence of operations of finding the next turn 0 to 3 - public int youTurnPhase; + public int youTurnPhase, curListCount; public vec4 crossingCurvePoint = new vec4(); - public double crossingheading = 0; + public vec4 crossingTurnLinePoint = new vec4(); //constructor public CYouTurn(FormGPS _f) @@ -80,29 +98,94 @@ public CYouTurn(FormGPS _f) //Finds the point where an AB Curve crosses the turn line public bool FindCurveTurnPoints() { - crossingCurvePoint.easting = -20000; + crossingTurnLinePoint.easting = -20000; + //find closet AB Curve point that will cross and go out of bounds - int Count = mf.curve.isHeadingSameWay ? 1 : -1; - int turnNum = 99; + curListCount = mf.curve.curList.Count; + + //otherwise we count down + bool isCountingUp = mf.curve.isHeadingSameWay; - for (int j = mf.curve.currentLocationIndex; j > 0 && j < mf.curve.curList.Count; j += Count) + //check if outside a border + if (isCountingUp) { - int idx = mf.bnd.IsPointInsideTurnArea(mf.curve.curList[j]); - if (idx != 0) + crossingTurnLinePoint.index = 99; + + //for each point in succession keep going till a turnLine is found. + for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) { - crossingCurvePoint.easting = mf.curve.curList[j - Count].easting; - crossingCurvePoint.northing = mf.curve.curList[j - Count].northing; - crossingCurvePoint.heading = mf.curve.curList[j - Count].heading; - crossingCurvePoint.index = j - Count; - turnNum = idx; - break; + if (!glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) + { //it passed outer turnLine + crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; + crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; + crossingCurvePoint.heading = mf.curve.curList[j - 1].heading; + crossingCurvePoint.index = j - 1; + crossingTurnLinePoint.index = 0; + goto CrossingFound; + } + + for (int i = 1; i < mf.bnd.bndList.Count; i++) + { + //make sure not inside a non drivethru boundary + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) + { + crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; + crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; + crossingCurvePoint.heading = mf.curve.curList[j - 1].heading; + crossingCurvePoint.index = j - 1; + crossingTurnLinePoint.index = i; + goto CrossingFound; + } + } } + + //escape for multiple for's + CrossingFound:; + } + else //counting down, going opposite way mf.curve was created. + { + crossingTurnLinePoint.index = 99; - if (turnNum < 0) - turnNum = 0; - else if (turnNum == 99) + for (int j = mf.curve.currentLocationIndex; j > 0; j--) + { + if (!glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) + { //it passed outer turnLine + crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; + crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; + crossingCurvePoint.heading = mf.curve.curList[j + 1].heading; + crossingCurvePoint.index = j + 1; + crossingTurnLinePoint.index = 0; + goto CrossingFound; + } + + for (int i = 1; i < mf.bnd.bndList.Count; i++) + { + //make sure not inside a non drivethru boundary + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) + { + crossingCurvePoint.easting = mf.curve.curList[j].easting; + crossingCurvePoint.northing = mf.curve.curList[j].northing; + crossingCurvePoint.heading = mf.curve.curList[j].heading; + crossingCurvePoint.index = j; + crossingTurnLinePoint.index = i; + goto CrossingFound; + } + } + } + + //escape for multiple for's, point and turnLine index are found + CrossingFound:; + } + + int turnNum = crossingTurnLinePoint.index; + + if (turnNum == 99) { isTurnCreationNotCrossingError = true; return false; @@ -115,10 +198,10 @@ public bool FindCurveTurnPoints() for (int j = 0; j < curTurnLineCount; j++) { - if ((mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 15 - && (mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -15 - && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 15 - && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -15) + if ((mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 + && (mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 + && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 + && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) { turnLineCloseList.Add(j); } @@ -126,7 +209,6 @@ public bool FindCurveTurnPoints() double dist1, dist2 = 99; curTurnLineCount = turnLineCloseList.Count; - int index = -1; for (int i = 0; i < curTurnLineCount; i++) { dist1 = glm.Distance(mf.bnd.bndList[turnNum].turnLine[turnLineCloseList[i]].easting, @@ -134,16 +216,17 @@ public bool FindCurveTurnPoints() crossingCurvePoint.easting, crossingCurvePoint.northing); if (dist1 < dist2) { - index = turnLineCloseList[i]; + crossingTurnLinePoint.index = turnLineCloseList[i]; dist2 = dist1; } } - crossingheading = -20000; - if (index >= 0) - crossingheading = mf.bnd.bndList[turnNum].turnLine[index].heading; + //fill up the coords + crossingTurnLinePoint.easting = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].easting; + crossingTurnLinePoint.northing = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].northing; + crossingTurnLinePoint.heading = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].heading; - return crossingheading != -20000 && crossingCurvePoint.easting != -20000; + return crossingCurvePoint.easting != -20000 && crossingCurvePoint.easting != -20000; } public void AddSequenceLines(double head) @@ -325,13 +408,13 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) if (boundaryAngleOffPerpendicular < -1.25) boundaryAngleOffPerpendicular = -1.25; //for calculating innner circles of turn - double tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; + tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; //baseline away from boundary to start calculations double toolTurnWidth = mf.tool.toolWidth * rowSkipsWidth; //distance from TurnLine for trigger added in youturn form, include the 3 m bump forward - double distanceTurnBeforeLine = 0; + distanceTurnBeforeLine = 0; if (mf.vehicle.minTurningRadius * 2 < toolTurnWidth) { @@ -501,11 +584,21 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (mf.bnd.IsPointInsideTurnArea(ytList[j]) != 0) + if (!glm.IsPointInPolygon(ytList[j],ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; + if (isOutOfBounds) break; + + for (int i = 1; i < mf.bnd.bndList.Count; i++) { - isOutOfBounds = true; - break; + //make sure not inside a non drivethru boundary + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) + { + isOutOfBounds = true; + break; + } } + if (isOutOfBounds) break; } if (!isOutOfBounds) @@ -551,11 +644,23 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (mf.bnd.IsPointInsideTurnArea(ytList[j]) != 0) - { - isOutOfBounds = true; + if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; + if (isOutOfBounds) break; + + for (int i = 1; i < mf.bnd.bndList.Count; i++) + { + //make sure not inside a non drivethru boundary + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) + { + isOutOfBounds = true; + break; + } } + if (isOutOfBounds) + break; } if (isOutOfBounds) @@ -593,16 +698,15 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) if (!isHeadingSameWay) head += Math.PI; //delta between AB heading and boundary closest point heading - boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(crossingheading - head) - Math.PI); + boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(crossingTurnLinePoint.heading - head) - Math.PI); boundaryAngleOffPerpendicular -= glm.PIBy2; boundaryAngleOffPerpendicular *= -1; if (boundaryAngleOffPerpendicular > 1.25) boundaryAngleOffPerpendicular = 1.25; if (boundaryAngleOffPerpendicular < -1.25) boundaryAngleOffPerpendicular = -1.25; //for calculating innner circles of turn - double tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; + tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; - double distanceTurnBeforeLine; //distance from crossPoint to turn line if (mf.vehicle.minTurningRadius * 2 < (mf.tool.toolWidth * rowSkipsWidth)) { @@ -748,11 +852,24 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (mf.bnd.IsPointInsideTurnArea(ytList[j]) != 0) + if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) { isOutOfBounds = true; break; } + + for (int i = 1; i < mf.bnd.bndList.Count; i++) + { + //make sure not inside a non drivethru boundary + if (mf.bnd.bndList[i].isDriveThru) continue; + if (mf.bnd.bndList[i].isDriveAround) continue; + if (glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[1].turnLine)) + { + isOutOfBounds = true; + break; + } + } + if (isOutOfBounds) break; } //first check if not out of bounds, add a bit more to clear turn line, set to phase 2 @@ -785,8 +902,8 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) else { crossingCurvePoint.index++; - if (crossingCurvePoint.index >= mf.curve.curList.Count) - crossingCurvePoint.index = mf.curve.curList.Count - 1; + if (crossingCurvePoint.index >= curListCount) + crossingCurvePoint.index = curListCount - 1; } crossingCurvePoint.easting = mf.curve.curList[crossingCurvePoint.index].easting; crossingCurvePoint.northing = mf.curve.curList[crossingCurvePoint.index].northing; @@ -910,6 +1027,7 @@ public void ResetYouTurn() isYouTurnTriggered = false; ytList?.Clear(); ResetCreatedYouTurn(); + turnDistanceAdjuster = 0; mf.isBoundAlarming = false; isTurnCreationTooClose = false; isTurnCreationNotCrossingError = false; @@ -917,6 +1035,7 @@ public void ResetYouTurn() public void ResetCreatedYouTurn() { + turnDistanceAdjuster = 0; youTurnPhase = 0; ytList?.Clear(); } @@ -1104,7 +1223,7 @@ public bool DistanceFromYouTurnLine() } //just need to make sure the points continue ascending or heading switches all over the place - if (A > B) { int C = A; A = B; B = C; } + if (A > B) { C = A; A = B; B = C; } //minDistA = 100; //int closestPt = 0; @@ -1205,7 +1324,7 @@ public bool DistanceFromYouTurnLine() } //just need to make sure the points continue ascending or heading switches all over the place - if (A > B) { int C = A; A = B; B = C; } + if (A > B) { C = A; A = B; B = C; } minDistA = 100; int closestPt = 0; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index 251d328ae..0c1cc25dc 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -780,29 +780,30 @@ private void setWorkingDirectoryToolStripMenuItem_Click(object sender, EventArgs if (Settings.Default.setF_workingDirectory == "Default") fbd.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); else fbd.SelectedPath = Settings.Default.setF_workingDirectory; - if (fbd.ShowDialog(this) == DialogResult.OK) + if (fbd.ShowDialog() == DialogResult.OK) { if (fbd.SelectedPath != Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) { Settings.Default.setF_workingDirectory = fbd.SelectedPath; + Settings.Default.Save(); } else { Settings.Default.setF_workingDirectory = "Default"; + Settings.Default.Save(); } - Settings.Default.Save(); //restart program MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); Close(); } } - private void enterSimCoordsToolStripMenuItem_Click(object sender, EventArgs e) { + var result = DialogResult.Cancel; using (var form = new FormSimCoords(this)) { - form.ShowDialog(this); + result = form.ShowDialog(); } } @@ -810,10 +811,10 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new Form_About()) { - form.ShowDialog(this); + var result = form.ShowDialog(); + if (result == DialogResult.OK) { } } } - private void resetALLToolStripMenuItem_Click(object sender, EventArgs e) { if (isJobStarted) @@ -1019,12 +1020,14 @@ private void simulatorOnToolStripMenuItem_Click(object sender, EventArgs e) Settings.Default.setMenu_isSimulatorOn = simulatorOnToolStripMenuItem.Checked; Settings.Default.Save(); } - private void colorsToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new FormColor(this)) { - form.ShowDialog(this); + var result = form.ShowDialog(); + if (result == DialogResult.OK) + { + } } } @@ -1032,69 +1035,165 @@ private void colorsSectionToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new FormSectionColor(this)) { - form.ShowDialog(this); + var result = form.ShowDialog(); + if (result == DialogResult.OK) + { + } } } //Languages private void menuLanguageEnglish_Click(object sender, EventArgs e) { - SetLanguage("en", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("en"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); + } private void menuLanguageDanish_Click(object sender, EventArgs e) { - SetLanguage("da", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("da"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); + } private void menuLanguageDeutsch_Click(object sender, EventArgs e) { - SetLanguage("de", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("de"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); + } private void menuLanguageRussian_Click(object sender, EventArgs e) { - SetLanguage("ru", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("ru"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); } private void menuLanguageDutch_Click(object sender, EventArgs e) { - SetLanguage("nl", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("nl"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); } private void menuLanguageSpanish_Click(object sender, EventArgs e) { - SetLanguage("es", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("es"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); } private void menuLanguageFrench_Click(object sender, EventArgs e) { - SetLanguage("fr", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("fr"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); } private void menuLanguageItalian_Click(object sender, EventArgs e) { - SetLanguage("it", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("it"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); } private void menuLanguageUkranian_Click(object sender, EventArgs e) { - SetLanguage("uk", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("uk"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); } private void menuLanguageSlovak_Click(object sender, EventArgs e) { - SetLanguage("sk", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("sk"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); + } private void menuLanguagesPolski_Click(object sender, EventArgs e) { - SetLanguage("pl", true); + if (isJobStarted) + { + var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); + form.Show(this); + return; + } + SetLanguage("pl"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); } private void menuLanguageTest_Click(object sender, EventArgs e) { - SetLanguage("af", true); - } - - private void SetLanguage(string lang, bool Restart) - { - if (Restart && isJobStarted) + if (isJobStarted) { var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); form.Show(this); return; } + SetLanguage("af"); + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); + } + private void SetLanguage(string lang) + { //reset them all to false menuLanguageEnglish.Checked = false; menuLanguageDeutsch.Checked = false; @@ -1175,12 +1274,6 @@ private void SetLanguage(string lang, bool Restart) //storing the values key.SetValue("Language", lang); key.Close(); - - if (Restart) - { - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - } } #endregion @@ -1254,10 +1347,16 @@ public void CloseTopMosts() private void btnOpenConfig_Click(object sender, EventArgs e) { + //check if window already exists + + //Form form = new FormConfig(this); + //form.Show(this); + using (var form = new FormConfig(this)) { form.ShowDialog(this); } + } private void btnTramDisplayMode_Click(object sender, EventArgs e) @@ -1289,7 +1388,8 @@ private void btnChangeMappingColor_Click(object sender, EventArgs e) { using (var form = new FormColorPicker(this, sectionColorDay)) { - if (form.ShowDialog(this) == DialogResult.OK) + var result = form.ShowDialog(); + if (result == DialogResult.OK) { sectionColorDay = form.useThisColor; } @@ -1408,7 +1508,10 @@ public void GetAB() using (var form = new FormABDraw(this)) { - form.ShowDialog(this); + var result = form.ShowDialog(); + if (result == DialogResult.OK) + { + } ABLine.moveDistance = 0; curve.moveDistance = 0; } @@ -1507,7 +1610,8 @@ private void SmoothABtoolStripMenu_Click(object sender, EventArgs e) { using (var form = new FormSmoothAB(this)) { - form.ShowDialog(this); + var result = form.ShowDialog(); + if (result == DialogResult.OK) { } } } else @@ -1629,7 +1733,8 @@ private void offsetFixToolStrip_Click(object sender, EventArgs e) { using (var form = new FormShiftPos(this)) { - form.ShowDialog(this); + var result = form.ShowDialog(); + if (result == DialogResult.OK) { } } } @@ -1722,12 +1827,12 @@ private void toolStripBtnFieldOpen_Click(object sender, EventArgs e) { using (var form = new FormJob(this)) { - var result = form.ShowDialog(this); + var result = form.ShowDialog(); if (result == DialogResult.Yes) { //ask for a directory name using (var form2 = new FormFieldDir(this)) - { form2.ShowDialog(this); } + { form2.ShowDialog(); } } //load from KML @@ -1735,7 +1840,7 @@ private void toolStripBtnFieldOpen_Click(object sender, EventArgs e) { //ask for a directory name using (var form2 = new FormFieldKML(this)) - { form2.ShowDialog(this); } + { form2.ShowDialog(); } } } @@ -1808,7 +1913,7 @@ private void CloseCurrentJob() //ask for a directory name using (var form2 = new FormSaveAs(this)) { - form2.ShowDialog(this); + form2.ShowDialog(); } break; @@ -1821,7 +1926,8 @@ private void toolStripBtnMakeBndContour_Click(object sender, EventArgs e) //build all the contour guidance lines from boundaries, all of them. using (var form = new FormMakeBndCon(this)) { - form.ShowDialog(this); + var result = form.ShowDialog(); + if (result == DialogResult.OK) { } } } private void tramLinesMenuField_Click(object sender, EventArgs e) @@ -1865,7 +1971,7 @@ public void GetHeadland() { using (var form = new FormHeadland (this)) { - form.ShowDialog(this); + form.ShowDialog(); } if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) @@ -1894,7 +2000,8 @@ private void boundariesToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new FormBoundary(this)) { - if (form.ShowDialog(this) == DialogResult.OK) + var result = form.ShowDialog(); + if (result == DialogResult.OK) { Form form2 = new FormBoundaryPlayer(this); form2.Show(this); @@ -2098,6 +2205,33 @@ public void FixTramModeButton() default: break; } + + } + + private void googleEarthFlagsToolStrip_Click(object sender, EventArgs e) + { + if (isJobStarted) + { + //save new copy of flags + FileSaveFieldKML(); + + //Process.Start(@"C:\Program Files (x86)\Google\Google Earth\client\googleearth", workingDirectory + currentFieldDirectory + "\\Flags.KML"); + Process.Start(fieldsDirectory + currentFieldDirectory + "\\Field.KML"); + } + else + { + var form = new FormTimedMessage(1500, gStr.gsFieldNotOpen, gStr.gsStartNewField); + form.Show(this); + } } + private void ZoomExtentsStripBtn_Click(object sender, EventArgs e) + { + if (camera.camSetDistance < -400) camera.camSetDistance = -75; + else camera.camSetDistance = -3 * maxFieldDistance; + if (camera.camSetDistance == 0) camera.camSetDistance = -2000; + SetZoom(); + } + + private Button btnEditAB; }//end class }//end namespace \ No newline at end of file diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index a10590f96..4718ceb52 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -10,8 +10,9 @@ public partial class FormBoundary : Form { private readonly FormGPS mf = null; + private bool Selectedreset = true; + private double easting, norting, latK, lonK; - private int fenceSelected = -1; public FormBoundary(Form callingForm) { @@ -118,6 +119,7 @@ private void UpdateChart() { //cc.Text = "Outer"; mf.bnd.bndList[i].isDriveThru = false; + mf.bnd.bndList[i].isDriveAround = false; a.Text = string.Format(gStr.gsOuter); //a.Font = backupfont; d.Text = mf.bnd.bndList[i].isDriveThru ? "--" : "--"; @@ -149,7 +151,7 @@ private void UpdateChart() b.Text = Math.Round(mf.bnd.bndList[i].area * 0.000247105, 2) + " Ac"; } - if (i == fenceSelected) + if (Selectedreset == false && i == mf.bnd.fenceSelected) { a.ForeColor = Color.OrangeRed; b.ForeColor = Color.OrangeRed; @@ -172,21 +174,39 @@ private void DriveThru_Click(object sender, EventArgs e) } } + private void DriveAround_Click(object sender, EventArgs e) + { + if (sender is Button b) + { + mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround = !mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround; + UpdateChart(); + } + } + private void B_Click(object sender, EventArgs e) { if (sender is Button b) { - int oldfenceSelected = fenceSelected; - fenceSelected = Convert.ToInt32(b.Name); - - if (fenceSelected == oldfenceSelected) - fenceSelected = -1; - else if (fenceSelected == 0) - btnDelete.Enabled = mf.bnd.bndList.Count == 1; - else if (fenceSelected > 0) + + mf.bnd.fenceSelected = Convert.ToInt32(b.Name); + + if (mf.bnd.fenceSelected == 0 && mf.bnd.bndList.Count > 1) + { + return; + } + + Selectedreset = false; + + if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) + { btnDelete.Enabled = true; + } + else + { + btnDelete.Enabled = false; + btnDeleteAll.Enabled = false; + } - btnDeleteAll.Enabled = fenceSelected == -1; } UpdateChart(); } @@ -209,13 +229,15 @@ private void btnDelete_Click(object sender, EventArgs e) btnDelete.Enabled = false; - if (mf.bnd.bndList.Count > fenceSelected) + if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) { - mf.bnd.bndList.RemoveAt(fenceSelected); + mf.bnd.bndList.RemoveAt(mf.bnd.fenceSelected); } - fenceSelected = -1; mf.FileSaveBoundary(); + + mf.bnd.fenceSelected = -1; + Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); mf.bnd.BuildTurnLines(); UpdateChart(); @@ -228,7 +250,6 @@ private void btnDelete_Click(object sender, EventArgs e) private void ResetAllBoundary() { - fenceSelected = -1; mf.bnd.bndList.Clear(); mf.FileSaveBoundary(); tableLayoutPanel1.Controls.Clear(); @@ -261,6 +282,9 @@ private void btnDeleteAll_Click(object sender, EventArgs e) ResetAllBoundary(); + mf.bnd.fenceSelected = -1; + Selectedreset = true; + mf.bnd.isOkToAddPoints = false; mf.fd.UpdateFieldBoundaryGUIAreas(); } @@ -286,6 +310,10 @@ private void btnReturn_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e) { + mf.bnd.fenceSelected = mf.bnd.bndList.Count; + + Selectedreset = false; + panelMain.Visible = false; panelKML.Visible = false; panelChoose.Visible = true; @@ -298,6 +326,8 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) { if (sender is Button button) { + Selectedreset = true; + string fileAndDirectory; { //create the dialog instance @@ -311,17 +341,19 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) }; //was a file selected - if (ofd.ShowDialog(this) == DialogResult.Cancel) return; + if (ofd.ShowDialog() == DialogResult.Cancel) return; else fileAndDirectory = ofd.FileName; } string coordinates = null; int startIndex; + int i = 0; using (StreamReader reader = new StreamReader(fileAndDirectory)) { if (button.Name == "btnLoadMultiBoundaryFromGE") ResetAllBoundary(); + else i = mf.bnd.fenceSelected; try { @@ -376,14 +408,17 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) New.fenceLine.Add(new vec3(easting, norting, 0)); } - New.CalculateFenceArea(mf.bnd.bndList.Count); - New.FixFenceLine(mf.bnd.bndList.Count); + New.CalculateFenceArea(mf.bnd.fenceSelected); + New.FixFenceLine(i); mf.bnd.bndList.Add(New); + mf.fd.UpdateFieldBoundaryGUIAreas(); + mf.btnMakeLinesFromBoundary.Visible = true; coordinates = ""; + i++; } else { diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 807c4bf42..007aa0e2d 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -36,23 +36,24 @@ private void btnStop_Click(object sender, EventArgs e) New.fenceLine.Add(mf.bnd.bndBeingMadePts[i]); } - New.CalculateFenceArea(mf.bnd.bndList.Count); - New.FixFenceLine(mf.bnd.bndList.Count); + New.CalculateFenceArea(mf.bnd.fenceSelected); + New.FixFenceLine(mf.bnd.fenceSelected); mf.bnd.bndList.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); - - //turn lines made from boundaries - mf.CalculateMinMax(); - mf.FileSaveBoundary(); - mf.bnd.BuildTurnLines(); - //mf.hd.BuildSingleSpaceHeadLines(); - mf.btnMakeLinesFromBoundary.Visible = true; } //stop it all for adding mf.bnd.isOkToAddPoints = false; mf.bnd.isBndBeingMade = false; + + //turn lines made from boundaries + mf.CalculateMinMax(); + mf.FileSaveBoundary(); + mf.bnd.BuildTurnLines(); + //mf.hd.BuildSingleSpaceHeadLines(); + mf.btnMakeLinesFromBoundary.Visible = true; + mf.bnd.bndBeingMadePts.Clear(); //close window Close(); diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 7d772f4e4..5b5a90d9c 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -121,9 +121,12 @@ private void LoadKMLBoundary(string filename) { string coordinates = null; int startIndex; + int i; using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { + i = mf.bnd.fenceSelected; + try { while (!reader.EndOfStream) @@ -180,20 +183,26 @@ private void LoadKMLBoundary(string filename) } //build the boundary, make sure is clockwise for outer counter clockwise for inner - New.CalculateFenceArea(mf.bnd.bndList.Count); - New.FixFenceLine(mf.bnd.bndList.Count); + New.CalculateFenceArea(mf.bnd.fenceSelected); + New.FixFenceLine(i); mf.bnd.bndList.Add(New); + mf.fd.UpdateFieldBoundaryGUIAreas(); + mf.btnMakeLinesFromBoundary.Visible = true; coordinates = ""; + i++; } else { mf.TimedMessageBox(2000, gStr.gsErrorreadingKML, gStr.gsChooseBuildDifferentone); } + //if (button.Name == "btnLoadBoundaryFromGE") + //{ break; + //} } } mf.FileSaveBoundary(); @@ -219,9 +228,13 @@ private void FindLatLon(string filename) { string coordinates = null; int startIndex; + int i; using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { + + i = mf.bnd.fenceSelected; + try { while (!reader.EndOfStream) @@ -278,6 +291,7 @@ private void FindLatLon(string filename) latK = lat / counter; coordinates = ""; + i++; } else { diff --git a/SourceCode/GPS/Forms/FormGPS.Designer.cs b/SourceCode/GPS/Forms/FormGPS.Designer.cs index 320e3b904..aa1df4b77 100644 --- a/SourceCode/GPS/Forms/FormGPS.Designer.cs +++ b/SourceCode/GPS/Forms/FormGPS.Designer.cs @@ -2392,7 +2392,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem toolStripBtnMakeBndContour; private System.Windows.Forms.ToolStripMenuItem sectionColorToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem enterABToolStripMenuItem; - private System.Windows.Forms.Button btnEditAB; } } diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index 9a978b33f..bff8a1a65 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -4,6 +4,7 @@ using OpenTK; using OpenTK.Graphics.OpenGL; using System; +using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; @@ -429,7 +430,7 @@ private void FormGPS_Load(object sender, EventArgs e) pictureboxStart.Dock = System.Windows.Forms.DockStyle.Fill; //set the language to last used - SetLanguage(Settings.Default.setF_culture, false); + SetLanguage(Settings.Default.setF_culture); currentVersionStr = Application.ProductVersion.ToString(CultureInfo.InvariantCulture); @@ -747,11 +748,25 @@ public void SwapDirection() { if (!yt.isYouTurnTriggered) { - yt.isYouTurnRight = !yt.isYouTurnRight; - yt.ResetCreatedYouTurn(); + //is it turning right already? + if (yt.isYouTurnRight) + { + yt.isYouTurnRight = false; + yt.isLastYouTurnRight = !yt.isLastYouTurnRight; + yt.ResetCreatedYouTurn(); + } + else + { + //make it turn the other way + yt.isYouTurnRight = true; + yt.isLastYouTurnRight = !yt.isLastYouTurnRight; + yt.ResetCreatedYouTurn(); + } + } + else + { + if (yt.isYouTurnBtnOn) btnAutoYouTurn.PerformClick(); } - else if (yt.isYouTurnBtnOn) - btnAutoYouTurn.PerformClick(); } private void BuildMachineByte() @@ -808,7 +823,7 @@ public int SaveOrNot(bool closing) using (FormSaveOrNot form = new FormSaveOrNot(closing)) { - DialogResult result = form.ShowDialog(this); + DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) return 0; //Save and Exit if (result == DialogResult.Ignore) return 1; //Ignore diff --git a/SourceCode/GPS/Forms/FormJob.cs b/SourceCode/GPS/Forms/FormJob.cs index 2b91a6340..e463beec3 100644 --- a/SourceCode/GPS/Forms/FormJob.cs +++ b/SourceCode/GPS/Forms/FormJob.cs @@ -74,7 +74,7 @@ private void btnJobTouch_Click(object sender, EventArgs e) using (FormTouchPick form = new FormTouchPick(mf)) { //returns full field.txt file dir name - if (form.ShowDialog(this) == DialogResult.Yes) + if (form.ShowDialog() == DialogResult.Yes) { mf.FileOpenField(mf.filePickerFileAndDirectory); Close(); diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 53bb45e30..05b2ecc47 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -532,6 +532,9 @@ public void LoadSettings() ahrs = new CAHRS(); + //update the field data areas + fd.UpdateFieldBoundaryGUIAreas(); + //Set width of section and positions for each section SectionSetPosition(); diff --git a/SourceCode/GPS/Forms/Guidance/FormABLine.cs b/SourceCode/GPS/Forms/Guidance/FormABLine.cs index fa7aa78a7..0b40754d9 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABLine.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABLine.cs @@ -442,9 +442,11 @@ private void btnAddTimeEdit_Click(object sender, EventArgs e) private void btnManual_Click(object sender, EventArgs e) { + var result = DialogResult.Cancel; using (var form = new FormEnterAB(mf)) { - if (form.ShowDialog(this) == DialogResult.OK) + result = form.ShowDialog(); + if (result == DialogResult.OK) { panelAPlus.Visible = false; panelName.Visible = true; diff --git a/SourceCode/GPS/Forms/Guidance/FormEditAB.cs b/SourceCode/GPS/Forms/Guidance/FormEditAB.cs index 999092edd..7cba5cc08 100644 --- a/SourceCode/GPS/Forms/Guidance/FormEditAB.cs +++ b/SourceCode/GPS/Forms/Guidance/FormEditAB.cs @@ -46,7 +46,8 @@ private void tboxHeading_Enter(object sender, EventArgs e) using (FormNumeric form = new FormNumeric(0, 360, Math.Round(glm.toDegrees(mf.ABLine.abHeading), 5))) { - if (form.ShowDialog(this) == DialogResult.OK) + DialogResult result = form.ShowDialog(); + if (result == DialogResult.OK) { tboxHeading.Text = ((double)form.ReturnValue).ToString(); mf.ABLine.abHeading = glm.toRadians((double)form.ReturnValue); diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index b3bedef83..945fa1975 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -340,23 +340,19 @@ private void oglMain_Paint(object sender, PaintEventArgs e) //draw Boundaries bnd.DrawFenceLines(); - GL.LineWidth(ABLine.lineWidth); //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) { - GL.Color3(0.3555f, 0.6232f, 0.20f); - for (int i = 0; i < bnd.bndList.Count; i++) - { - bnd.bndList[i].turnLine.DrawPolygon(); - } + bnd.DrawTurnLines(); } if (bnd.isHeadlandOn) { + GL.LineWidth(ABLine.lineWidth); GL.Color3(0.960f, 0.96232f, 0.30f); for (int i = 0; i < bnd.bndList.Count; i++) { - bnd.bndList[i].hdLine.DrawPolygon(); + if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLine(); } } @@ -628,7 +624,9 @@ private void oglBack_Paint(object sender, PaintEventArgs e) { GL.LineWidth(3); GL.Color3((byte)0, (byte)240, (byte)0); - bnd.bndList[0].fenceLine.DrawPolygon(); + GL.Begin(PrimitiveType.LineStrip); + for (int h = 0; h < ptCount; h++) GL.Vertex3(bnd.bndList[0].fenceLine[h].easting, bnd.bndList[0].fenceLine[h].northing, 0); + GL.End(); } } @@ -640,7 +638,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) for (int i = 0; i < bnd.bndList.Count; i++) { - bnd.bndList[i].hdLine.DrawPolygon(); + if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLineBackBuffer(); } } diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index 47f67a493..fef8e4128 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -710,7 +710,7 @@ public void UpdateFixPosition() if (bnd.bndList.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (bnd.IsPointInsideFenceArea(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (bnd.IsInsideAllFences(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; @@ -1124,8 +1124,8 @@ private void AddSectionOrContourPathPoints() public void CalculateSectionLookAhead(double northing, double easting, double cosHeading, double sinHeading) { //calculate left side of section 1 - vec2 left = new vec2(); - vec2 right = left; + vec3 left = new vec3(); + vec3 right = left; double leftSpeed = 0, rightSpeed = 0; //speed max for section kmh*0.277 to m/s * 10 cm per pixel * 1.7 max speed @@ -1137,8 +1137,8 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (j == 0) { //only one first left point, the rest are all rights moved over to left - section[j].leftPoint = new vec2(cosHeading * (section[j].positionLeft) + easting, - sinHeading * (section[j].positionLeft) + northing); + section[j].leftPoint = new vec3(cosHeading * (section[j].positionLeft) + easting, + sinHeading * (section[j].positionLeft) + northing,0); left = section[j].leftPoint - section[j].lastLeftPoint; @@ -1163,8 +1163,8 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (leftSpeed > rightSpeed) leftSpeed = rightSpeed; } - section[j].rightPoint = new vec2(cosHeading * (section[j].positionRight) + easting, - sinHeading * (section[j].positionRight) + northing); + section[j].rightPoint = new vec3(cosHeading * (section[j].positionRight) + easting, + sinHeading * (section[j].positionRight) + northing,0); //now we have left and right for this section right = section[j].rightPoint - section[j].lastRightPoint; @@ -1250,17 +1250,44 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { if (bnd.bndList.Count > 0) { - //only one first left point, the rest are all rights moved over to left - isLeftIn = j == 0 ? bnd.IsPointInsideFenceArea(section[j].leftPoint) : isRightIn; - isRightIn = bnd.IsPointInsideFenceArea(section[j].rightPoint); + if (j == 0) + { + //only one first left point, the rest are all rights moved over to left + isLeftIn = glm.IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[0].fenceLineEar); + isRightIn = glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); + + for (int i = 1; i < bnd.bndList.Count; i++) + { + //inner boundaries should normally NOT have point inside + isLeftIn &= !glm.IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[i].fenceLineEar); + isRightIn &= !glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); + } - //merge the two sides into in or out - if (isLeftIn && isRightIn) section[j].isInBoundary = true; - else section[j].isInBoundary = false; + //merge the two sides into in or out + if (isLeftIn && isRightIn) section[j].isInBoundary = true; + else section[j].isInBoundary = false; + } + else + { + //grab the right of previous section, its the left of this section + isLeftIn = isRightIn; + isRightIn = glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); + for (int i = 1; i < bnd.bndList.Count; i++) + { + //inner boundaries should normally NOT have point inside + isRightIn &= !glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); + } + + if (isLeftIn && isRightIn) section[j].isInBoundary = true; + else section[j].isInBoundary = false; + } section[tool.numOfSections].isInBoundary &= section[j].isInBoundary; + } - else//no boundary created so always inside + + //no boundary created so always inside + else { section[j].isInBoundary = true; section[tool.numOfSections].isInBoundary = false; diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index 51ebb41e9..f04c1bc4d 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -318,7 +318,7 @@ public void FileOpenField(string _openType) ofd.Filter = "Field files (Field.txt)|Field.txt"; //was a file selected - if (ofd.ShowDialog(this) == DialogResult.Cancel) fileAndDirectory = "Cancel"; + if (ofd.ShowDialog() == DialogResult.Cancel) fileAndDirectory = "Cancel"; else fileAndDirectory = ofd.FileName; break; } @@ -698,6 +698,7 @@ public void FileOpenField(string _openType) //Check for latest boundary files, then above line string is num of points if (line == "True" || line == "False") { + New.isDriveAround = bool.Parse(line); line = reader.ReadLine(); //number of points } @@ -1211,7 +1212,8 @@ public void FileSaveBoundary() for (int i = 0; i < bnd.bndList.Count; i++) { writer.WriteLine(bnd.bndList[i].isDriveThru); - //writer.WriteLine(bnd.bndList[i].isDriveAround); + writer.WriteLine(bnd.bndList[i].isDriveAround); + //writer.WriteLine(bnd.bndArr[i].isOwnField); writer.WriteLine(bnd.bndList[i].fenceLine.Count.ToString(CultureInfo.InvariantCulture)); if (bnd.bndList[i].fenceLine.Count > 0) diff --git a/SourceCode/GPS/Forms/Settings/FormSteer.cs b/SourceCode/GPS/Forms/Settings/FormSteer.cs index b65496e92..8e383088b 100644 --- a/SourceCode/GPS/Forms/Settings/FormSteer.cs +++ b/SourceCode/GPS/Forms/Settings/FormSteer.cs @@ -381,7 +381,7 @@ private void hsbarIntegralPurePursuit_ValueChanged(object sender, EventArgs e) private void hsbarSideHillComp_ValueChanged(object sender, EventArgs e) { - double deg = hsbarSideHillComp.Value; + double deg = (double)hsbarSideHillComp.Value; deg *= 0.01; lblSideHillComp.Text = (deg.ToString("N2") + "\u00B0"); Properties.Settings.Default.setAS_sideHillComp = deg; From 4c51c40362bc23e44c41574392ee1e9685c1ae9c Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Wed, 27 Oct 2021 07:39:57 -0600 Subject: [PATCH 14/18] Remove "Enter AB" off File menu --- SourceCode/GPS/Forms/FormGPS.Designer.cs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/SourceCode/GPS/Forms/FormGPS.Designer.cs b/SourceCode/GPS/Forms/FormGPS.Designer.cs index aa1df4b77..20e76aaa7 100644 --- a/SourceCode/GPS/Forms/FormGPS.Designer.cs +++ b/SourceCode/GPS/Forms/FormGPS.Designer.cs @@ -64,7 +64,6 @@ private void InitializeComponent() this.resetEverythingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.enterABToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tmrWatchdog = new System.Windows.Forms.Timer(this.components); this.contextMenuStripFlag = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripMenuItemFlagRed = new System.Windows.Forms.ToolStripMenuItem(); @@ -235,7 +234,6 @@ private void InitializeComponent() this.toolStripSeparator10, this.colorsToolStripMenuItem1, this.sectionColorToolStripMenuItem, - this.enterABToolStripMenuItem, this.toolStripSeparator8, this.topFieldViewToolStripMenuItem, this.toolStripSeparator3, @@ -463,12 +461,6 @@ private void InitializeComponent() this.helpMenuItem.Text = "Help"; this.helpMenuItem.Click += new System.EventHandler(this.helpMenuItem_Click); // - // enterABToolStripMenuItem - // - this.enterABToolStripMenuItem.Name = "enterABToolStripMenuItem"; - this.enterABToolStripMenuItem.Size = new System.Drawing.Size(319, 40); - this.enterABToolStripMenuItem.Text = "Enter AB"; - // // tmrWatchdog // this.tmrWatchdog.Interval = 250; @@ -669,7 +661,7 @@ private void InitializeComponent() this.btnResetSim.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnResetSim.Font = new System.Drawing.Font("Tahoma", 9.75F); this.btnResetSim.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.btnResetSim.Location = new System.Drawing.Point(508, 4); + this.btnResetSim.Location = new System.Drawing.Point(506, 4); this.btnResetSim.Name = "btnResetSim"; this.btnResetSim.Size = new System.Drawing.Size(50, 31); this.btnResetSim.TabIndex = 164; @@ -684,7 +676,7 @@ private void InitializeComponent() this.btnResetSteerAngle.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnResetSteerAngle.Font = new System.Drawing.Font("Tahoma", 9.75F); this.btnResetSteerAngle.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.btnResetSteerAngle.Location = new System.Drawing.Point(456, 4); + this.btnResetSteerAngle.Location = new System.Drawing.Point(454, 4); this.btnResetSteerAngle.Name = "btnResetSteerAngle"; this.btnResetSteerAngle.Size = new System.Drawing.Size(44, 31); this.btnResetSteerAngle.TabIndex = 162; @@ -709,10 +701,10 @@ private void InitializeComponent() this.hsbarSteerAngle.Dock = System.Windows.Forms.DockStyle.Fill; this.hsbarSteerAngle.ImeMode = System.Windows.Forms.ImeMode.NoControl; this.hsbarSteerAngle.LargeChange = 20; - this.hsbarSteerAngle.Location = new System.Drawing.Point(260, 1); + this.hsbarSteerAngle.Location = new System.Drawing.Point(259, 1); this.hsbarSteerAngle.Maximum = 800; this.hsbarSteerAngle.Name = "hsbarSteerAngle"; - this.hsbarSteerAngle.Size = new System.Drawing.Size(192, 37); + this.hsbarSteerAngle.Size = new System.Drawing.Size(191, 37); this.hsbarSteerAngle.TabIndex = 179; this.hsbarSteerAngle.Value = 400; this.hsbarSteerAngle.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsbarSteerAngle_Scroll); @@ -725,7 +717,7 @@ private void InitializeComponent() this.hsbarStepDistance.Location = new System.Drawing.Point(1, 1); this.hsbarStepDistance.Minimum = -25; this.hsbarStepDistance.Name = "hsbarStepDistance"; - this.hsbarStepDistance.Size = new System.Drawing.Size(192, 37); + this.hsbarStepDistance.Size = new System.Drawing.Size(191, 37); this.hsbarStepDistance.TabIndex = 178; this.hsbarStepDistance.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsbarStepDistance_Scroll); // @@ -1417,7 +1409,7 @@ private void InitializeComponent() this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 65F)); this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 51F)); - this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 92F)); + this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 94F)); this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.panelSim.Controls.Add(this.btnResetSteerAngle, 3, 0); this.panelSim.Controls.Add(this.hsbarSteerAngle, 2, 0); @@ -1441,7 +1433,7 @@ private void InitializeComponent() this.btnSimSetSpeedToZero.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnSimSetSpeedToZero.Font = new System.Drawing.Font("Tahoma", 9.75F); this.btnSimSetSpeedToZero.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.btnSimSetSpeedToZero.Location = new System.Drawing.Point(197, 4); + this.btnSimSetSpeedToZero.Location = new System.Drawing.Point(196, 4); this.btnSimSetSpeedToZero.Name = "btnSimSetSpeedToZero"; this.btnSimSetSpeedToZero.Size = new System.Drawing.Size(59, 31); this.btnSimSetSpeedToZero.TabIndex = 453; @@ -2391,7 +2383,6 @@ private void InitializeComponent() private System.Windows.Forms.Label label1; private System.Windows.Forms.ToolStripMenuItem toolStripBtnMakeBndContour; private System.Windows.Forms.ToolStripMenuItem sectionColorToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem enterABToolStripMenuItem; } } From 59ffee9ef1adfb1ea39e4a5f41c8d9b1a18b024a Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Wed, 27 Oct 2021 08:01:51 -0600 Subject: [PATCH 15/18] Revert "Remove "Enter AB" off File menu" This reverts commit 4c51c40362bc23e44c41574392ee1e9685c1ae9c. --- SourceCode/GPS/Forms/FormGPS.Designer.cs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/SourceCode/GPS/Forms/FormGPS.Designer.cs b/SourceCode/GPS/Forms/FormGPS.Designer.cs index 20e76aaa7..aa1df4b77 100644 --- a/SourceCode/GPS/Forms/FormGPS.Designer.cs +++ b/SourceCode/GPS/Forms/FormGPS.Designer.cs @@ -64,6 +64,7 @@ private void InitializeComponent() this.resetEverythingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.enterABToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tmrWatchdog = new System.Windows.Forms.Timer(this.components); this.contextMenuStripFlag = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripMenuItemFlagRed = new System.Windows.Forms.ToolStripMenuItem(); @@ -234,6 +235,7 @@ private void InitializeComponent() this.toolStripSeparator10, this.colorsToolStripMenuItem1, this.sectionColorToolStripMenuItem, + this.enterABToolStripMenuItem, this.toolStripSeparator8, this.topFieldViewToolStripMenuItem, this.toolStripSeparator3, @@ -461,6 +463,12 @@ private void InitializeComponent() this.helpMenuItem.Text = "Help"; this.helpMenuItem.Click += new System.EventHandler(this.helpMenuItem_Click); // + // enterABToolStripMenuItem + // + this.enterABToolStripMenuItem.Name = "enterABToolStripMenuItem"; + this.enterABToolStripMenuItem.Size = new System.Drawing.Size(319, 40); + this.enterABToolStripMenuItem.Text = "Enter AB"; + // // tmrWatchdog // this.tmrWatchdog.Interval = 250; @@ -661,7 +669,7 @@ private void InitializeComponent() this.btnResetSim.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnResetSim.Font = new System.Drawing.Font("Tahoma", 9.75F); this.btnResetSim.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.btnResetSim.Location = new System.Drawing.Point(506, 4); + this.btnResetSim.Location = new System.Drawing.Point(508, 4); this.btnResetSim.Name = "btnResetSim"; this.btnResetSim.Size = new System.Drawing.Size(50, 31); this.btnResetSim.TabIndex = 164; @@ -676,7 +684,7 @@ private void InitializeComponent() this.btnResetSteerAngle.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnResetSteerAngle.Font = new System.Drawing.Font("Tahoma", 9.75F); this.btnResetSteerAngle.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.btnResetSteerAngle.Location = new System.Drawing.Point(454, 4); + this.btnResetSteerAngle.Location = new System.Drawing.Point(456, 4); this.btnResetSteerAngle.Name = "btnResetSteerAngle"; this.btnResetSteerAngle.Size = new System.Drawing.Size(44, 31); this.btnResetSteerAngle.TabIndex = 162; @@ -701,10 +709,10 @@ private void InitializeComponent() this.hsbarSteerAngle.Dock = System.Windows.Forms.DockStyle.Fill; this.hsbarSteerAngle.ImeMode = System.Windows.Forms.ImeMode.NoControl; this.hsbarSteerAngle.LargeChange = 20; - this.hsbarSteerAngle.Location = new System.Drawing.Point(259, 1); + this.hsbarSteerAngle.Location = new System.Drawing.Point(260, 1); this.hsbarSteerAngle.Maximum = 800; this.hsbarSteerAngle.Name = "hsbarSteerAngle"; - this.hsbarSteerAngle.Size = new System.Drawing.Size(191, 37); + this.hsbarSteerAngle.Size = new System.Drawing.Size(192, 37); this.hsbarSteerAngle.TabIndex = 179; this.hsbarSteerAngle.Value = 400; this.hsbarSteerAngle.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsbarSteerAngle_Scroll); @@ -717,7 +725,7 @@ private void InitializeComponent() this.hsbarStepDistance.Location = new System.Drawing.Point(1, 1); this.hsbarStepDistance.Minimum = -25; this.hsbarStepDistance.Name = "hsbarStepDistance"; - this.hsbarStepDistance.Size = new System.Drawing.Size(191, 37); + this.hsbarStepDistance.Size = new System.Drawing.Size(192, 37); this.hsbarStepDistance.TabIndex = 178; this.hsbarStepDistance.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsbarStepDistance_Scroll); // @@ -1409,7 +1417,7 @@ private void InitializeComponent() this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 65F)); this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 51F)); - this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 94F)); + this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 92F)); this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.panelSim.Controls.Add(this.btnResetSteerAngle, 3, 0); this.panelSim.Controls.Add(this.hsbarSteerAngle, 2, 0); @@ -1433,7 +1441,7 @@ private void InitializeComponent() this.btnSimSetSpeedToZero.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnSimSetSpeedToZero.Font = new System.Drawing.Font("Tahoma", 9.75F); this.btnSimSetSpeedToZero.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.btnSimSetSpeedToZero.Location = new System.Drawing.Point(196, 4); + this.btnSimSetSpeedToZero.Location = new System.Drawing.Point(197, 4); this.btnSimSetSpeedToZero.Name = "btnSimSetSpeedToZero"; this.btnSimSetSpeedToZero.Size = new System.Drawing.Size(59, 31); this.btnSimSetSpeedToZero.TabIndex = 453; @@ -2383,6 +2391,7 @@ private void InitializeComponent() private System.Windows.Forms.Label label1; private System.Windows.Forms.ToolStripMenuItem toolStripBtnMakeBndContour; private System.Windows.Forms.ToolStripMenuItem sectionColorToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem enterABToolStripMenuItem; } } From b9ed8726a685594bf2dcd00053228f0e6634db75 Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Wed, 27 Oct 2021 08:02:01 -0600 Subject: [PATCH 16/18] Revert "Revert "Code Cleanup"" This reverts commit 983ef9860f8f62cd792ea914699b9706012e7809. --- SourceCode/GPS/AgOpenGPS.csproj | 3 - SourceCode/GPS/Classes/CABCurve.cs | 91 ++------ SourceCode/GPS/Classes/CABLine.cs | 18 +- SourceCode/GPS/Classes/CBoundary.cs | 6 +- SourceCode/GPS/Classes/CBoundaryList.cs | 6 +- SourceCode/GPS/Classes/CContour.cs | 18 +- SourceCode/GPS/Classes/CFence.cs | 130 ++++-------- SourceCode/GPS/Classes/CFenceLine.cs | 44 +--- SourceCode/GPS/Classes/CGLM.cs | 27 ++- SourceCode/GPS/Classes/CHead.cs | 113 +++------- SourceCode/GPS/Classes/CHeadLines.cs | 34 --- SourceCode/GPS/Classes/CSection.cs | 25 +-- SourceCode/GPS/Classes/CTurn.cs | 73 +++---- SourceCode/GPS/Classes/CTurnLines.cs | 41 +--- SourceCode/GPS/Classes/CYouTurn.cs | 209 ++++--------------- SourceCode/GPS/Forms/Controls.Designer.cs | 220 ++++---------------- SourceCode/GPS/Forms/FormBoundary.cs | 71 ++----- SourceCode/GPS/Forms/FormBoundaryPlayer.cs | 19 +- SourceCode/GPS/Forms/FormFieldKML.cs | 18 +- SourceCode/GPS/Forms/FormGPS.Designer.cs | 1 + SourceCode/GPS/Forms/FormGPS.cs | 27 +-- SourceCode/GPS/Forms/FormJob.cs | 2 +- SourceCode/GPS/Forms/GUI.Designer.cs | 3 - SourceCode/GPS/Forms/Guidance/FormABLine.cs | 4 +- SourceCode/GPS/Forms/Guidance/FormEditAB.cs | 3 +- SourceCode/GPS/Forms/OpenGL.Designer.cs | 16 +- SourceCode/GPS/Forms/Position.designer.cs | 55 ++--- SourceCode/GPS/Forms/SaveOpen.Designer.cs | 6 +- SourceCode/GPS/Forms/Settings/FormSteer.cs | 2 +- 29 files changed, 302 insertions(+), 983 deletions(-) delete mode 100644 SourceCode/GPS/Classes/CHeadLines.cs diff --git a/SourceCode/GPS/AgOpenGPS.csproj b/SourceCode/GPS/AgOpenGPS.csproj index 2b1114007..d8d2bf0b8 100644 --- a/SourceCode/GPS/AgOpenGPS.csproj +++ b/SourceCode/GPS/AgOpenGPS.csproj @@ -131,9 +131,6 @@ - - CBoundaryList.cs - CBoundary.cs diff --git a/SourceCode/GPS/Classes/CABCurve.cs b/SourceCode/GPS/Classes/CABCurve.cs index 17ea9d2d4..39a2fbffb 100644 --- a/SourceCode/GPS/Classes/CABCurve.cs +++ b/SourceCode/GPS/Classes/CABCurve.cs @@ -725,51 +725,18 @@ public void BuildTram() } if (Add) { - if (isBndExist) + //a new point only every 2 meters + double dist = mf.tram.tramArr.Count > 0 ? ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) + + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)) : 3.0; + if (dist > 2) { - if (mf.tram.tramArr.Count > 0) - { - //a new point only every 2 meters - double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) - + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); - if (dist > 2) - { - //if inside the boundary, add - if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar )) - { - mf.tram.tramArr.Add(point); - } - } - } - else - { - //need a first point to do distance - if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) - { - mf.tram.tramArr.Add(point); - } - } - } - else - { - //no boundary to cull points - if (mf.tram.tramArr.Count > 0) - { - double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) - + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); - if (dist > 2) - { - mf.tram.tramArr.Add(point); - } - } - else + //if inside the boundary, add + if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(point)) { mf.tram.tramArr.Add(point); } - } } - } } @@ -806,48 +773,16 @@ public void BuildTram() } if (Add) { - if (isBndExist) + //a new point only every 2 meters + double dist = mf.tram.tramArr.Count > 0 ? ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) + + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)) : 3.0; + if (dist > 2) { - if (mf.tram.tramArr.Count > 0) - { - //a new point only every 2 meters - double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) - + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); - if (dist > 2) - { - //if inside the boundary, add - if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) - { - mf.tram.tramArr.Add(point); - } - } - } - else - { - //need a first point to do distance - if (glm.IsPointInPolygon(point, ref mf.bnd.bndList[0].fenceLineEar)) - { - mf.tram.tramArr.Add(point); - } - } - } - else - { - //no boundary to cull points - if (mf.tram.tramArr.Count > 0) - { - double dist = ((point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting) * (point.easting - mf.tram.tramArr[mf.tram.tramArr.Count - 1].easting)) - + ((point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing) * (point.northing - mf.tram.tramArr[mf.tram.tramArr.Count - 1].northing)); - if (dist > 2) - { - mf.tram.tramArr.Add(point); - } - } - else + //if inside the boundary, add + if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(point)) { mf.tram.tramArr.Add(point); } - } } } @@ -1020,8 +955,6 @@ public void ResetCurveLine() refList?.Clear(); isCurveSet = false; } - - ////draw the guidance line } public class CCurveLines diff --git a/SourceCode/GPS/Classes/CABLine.cs b/SourceCode/GPS/Classes/CABLine.cs index df7fbbd1a..832af3870 100644 --- a/SourceCode/GPS/Classes/CABLine.cs +++ b/SourceCode/GPS/Classes/CABLine.cs @@ -493,14 +493,7 @@ public void BuildTram() P1.easting = (hsin * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].easting; P1.northing = (hcos * ((mf.tram.tramWidth * (pass + i)) - mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].northing; - if (isBndExist) - { - if (glm.IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) - { - mf.tram.tramArr.Add(P1); - } - } - else + if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(P1)) { mf.tram.tramArr.Add(P1); } @@ -521,14 +514,7 @@ public void BuildTram() P1.easting = (hsin * ((mf.tram.tramWidth * (pass + i)) + mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].easting; P1.northing = (hcos * ((mf.tram.tramWidth * (pass + i)) + mf.tram.halfWheelTrack + mf.tool.halfToolWidth)) + tramRef[j].northing; - if (isBndExist) - { - if (glm.IsPointInPolygon(P1, ref mf.bnd.bndList[0].fenceLineEar)) - { - mf.tram.tramArr.Add(P1); - } - } - else + if (!isBndExist || mf.bnd.bndList[0].fenceLineEar.IsPointInPolygon(P1)) { mf.tram.tramArr.Add(P1); } diff --git a/SourceCode/GPS/Classes/CBoundary.cs b/SourceCode/GPS/Classes/CBoundary.cs index 7a67962d7..f4cf9bb19 100644 --- a/SourceCode/GPS/Classes/CBoundary.cs +++ b/SourceCode/GPS/Classes/CBoundary.cs @@ -1,6 +1,4 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace AgOpenGPS { @@ -15,11 +13,9 @@ public partial class CBoundary public CBoundary(FormGPS _f) { mf = _f; - fenceSelected = 0; boxLength = 2000; turnSelected = 0; isHeadlandOn = false; - isToolUp = true; } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CBoundaryList.cs b/SourceCode/GPS/Classes/CBoundaryList.cs index 0b52a3b28..3114a70a5 100644 --- a/SourceCode/GPS/Classes/CBoundaryList.cs +++ b/SourceCode/GPS/Classes/CBoundaryList.cs @@ -1,6 +1,4 @@ -using OpenTK.Graphics.OpenGL; -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace AgOpenGPS { @@ -12,12 +10,10 @@ public partial class CBoundaryList public List hdLine = new List(128); public List turnLine = new List(128); - //constructor public CBoundaryList() { area = 0; - isDriveAround = false; isDriveThru = false; } } diff --git a/SourceCode/GPS/Classes/CContour.cs b/SourceCode/GPS/Classes/CContour.cs index 4ae78d278..086a4cba3 100644 --- a/SourceCode/GPS/Classes/CContour.cs +++ b/SourceCode/GPS/Classes/CContour.cs @@ -313,10 +313,10 @@ public void BuildContourGuidanceLine(vec3 pivot, vec3 steer) stripNum = 0; for (int s = 0; s < stripCount; s++) { - double dist = 0; int p; ptCount = stripList[s].Count; if (ptCount == 0) continue; + double dist; for (p = 0; p < ptCount; p += 6) { dist = ((pivot.easting - stripList[s][p].easting) * (pivot.easting - stripList[s][p].easting)) @@ -515,13 +515,10 @@ public void BuildContourGuidanceLine(vec3 pivot, vec3 steer) stop = pt + 6; if (stop > ptCount) stop = ptCount; } - double distAway = 0; - double distSqAway = 0; - //if (howManyPathsAway != 0 && (mf.tool.halfToolWidth < (0.5*mf.tool.toolOffset))) { - distAway = (mf.tool.toolWidth - mf.tool.toolOverlap) * howManyPathsAway + (isSameWay ? -mf.tool.toolOffset : mf.tool.toolOffset); - distSqAway = (distAway * distAway) * 0.97; + double distAway = (mf.tool.toolWidth - mf.tool.toolOverlap) * howManyPathsAway + (isSameWay ? -mf.tool.toolOffset : mf.tool.toolOffset); + double distSqAway = (distAway * distAway) * 0.97; for (int i = start; i < stop; i++) @@ -845,8 +842,7 @@ public void StartContourLine(vec3 pivot) if (stripList.Count == 0) { //make new ptList - ptList = new List(); - ptList.Capacity = 16; + ptList = new List(16); //ptList.Add(new vec3(pivot.easting + Math.Cos(pivot.heading) // * mf.tool.toolOffset, pivot.northing - Math.Sin(pivot.heading) * mf.tool.toolOffset, pivot.heading)); stripList.Add(ptList); @@ -882,7 +878,6 @@ public void StopContourLine(vec3 pivot) double head = ptList[0].heading; int length = (int)mf.tool.toolWidth+3; vec3 pnt; - int ptc = ctList.Count - 1; for (int a = 0; a < length; a ++) { pnt.easting = ptList[0].easting - (Math.Sin(head)); @@ -891,7 +886,7 @@ public void StopContourLine(vec3 pivot) ptList.Insert(0, pnt); } - ptc = ptList.Count - 1; + int ptc = ptList.Count - 1; head = ptList[ptc].heading; for (double i = 1; i < length; i += 1) @@ -905,8 +900,7 @@ public void StopContourLine(vec3 pivot) //add the point list to the save list for appending to contour file mf.contourSaveList.Add(ptList); - ptList = new List(); - ptList.Capacity = 32; + ptList = new List(32); stripList.Add(ptList); } diff --git a/SourceCode/GPS/Classes/CFence.cs b/SourceCode/GPS/Classes/CFence.cs index 3a18c4588..f32d948c0 100644 --- a/SourceCode/GPS/Classes/CFence.cs +++ b/SourceCode/GPS/Classes/CFence.cs @@ -11,47 +11,69 @@ public partial class CBoundary public double createBndOffset; public bool isBndBeingMade; - // the list of possible bounds points - public List bndClosestList = new List(); - public bool isDrawRightSide = true, isOkToAddPoints = false; - public int fenceSelected, closestFenceNum; + public int closestFenceNum; //point at the farthest boundary segment from pivotAxle public vec3 closestFencePt = new vec3(-10000, -10000, 9); - public bool IsInsideAllFences(vec3 testPoint) + public bool IsPointInsideFenceArea(vec3 testPoint) { //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders - if (glm.IsPointInPolygon(testPoint, ref bndList[0].fenceLine)) + if (bndList[0].fenceLineEar.IsPointInPolygon(testPoint)) { for (int i = 1; i < bndList.Count; i++) { //make sure not inside a non drivethru boundary if (bndList[i].isDriveThru) continue; - if (glm.IsPointInPolygon(testPoint, ref bndList[i].fenceLine)) + if (bndList[i].fenceLineEar.IsPointInPolygon(testPoint)) { return false; } } + //we are safely inside outer, outside inner boundaries + return true; } - else + return false; + } + + public bool IsPointInsideFenceArea(vec2 testPoint) + { + //first where are we, must be inside outer and outside of inner geofence non drive thru turn borders + if (bndList[0].fenceLineEar.IsPointInPolygon(testPoint)) { - return false; + for (int i = 1; i < bndList.Count; i++) + { + //make sure not inside a non drivethru boundary + if (bndList[i].isDriveThru) continue; + if (bndList[i].fenceLineEar.IsPointInPolygon(testPoint)) + { + return false; + } + } + //we are safely inside outer, outside inner boundaries + return true; } - //we are safely inside outer, outside inner boundaries - return true; + return false; } public void DrawFenceLines() { - //draw the boundaries - GL.Color3(0.75f, 0.5f, 0.250f); + if (!mf.mc.isOutOfBounds) + { + GL.Color3(0.95f, 0.75f, 0.50f); + GL.LineWidth(mf.ABLine.lineWidth); + } + else + { + GL.LineWidth(mf.ABLine.lineWidth * 3); + GL.Color3(0.95f, 0.25f, 0.250f); + } for (int i = 0; i < bndList.Count; i++) { - bndList[i].DrawFenceLine(mf.ABLine.lineWidth, mf.mc.isOutOfBounds); + bndList[i].fenceLine.DrawPolygon(); } if (bndBeingMadePts.Count > 0) @@ -100,82 +122,4 @@ public void DrawFenceLines() } } -} - - -//public void FindClosestBoundaryPoint(vec3 fromPt, double headAB) - //{ - // { - // boxA.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * (scanWidth - 2)); - // boxA.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * (scanWidth - 2)); - - // boxB.easting = fromPt.easting + (Math.Sin(headAB + glm.PIBy2) * scanWidth); - // boxB.northing = fromPt.northing + (Math.Cos(headAB + glm.PIBy2) * scanWidth); - - // boxC.easting = boxB.easting + (Math.Sin(headAB) * boxLength); - // boxC.northing = boxB.northing + (Math.Cos(headAB) * boxLength); - - // boxD.easting = boxA.easting + (Math.Sin(headAB) * boxLength); - // boxD.northing = boxA.northing + (Math.Cos(headAB) * boxLength); - // } - - // int ptCount; - - // //determine if point is inside bounding box - // bndClosestList.Clear(); - // vec4 inBox; - // for (int i = 0; i < plots.Count; i++) - // { - // //skip the drive thru - // if (plots[i].isDriveThru) continue; - - // ptCount = plots[i].bndLine.Count; - // for (int p = 0; p < ptCount; p++) - // { - // if ((((boxB.easting - boxA.easting) * (plots[i].bndLine[p].northing - boxA.northing)) - // - ((boxB.northing - boxA.northing) * (plots[i].bndLine[p].easting - boxA.easting))) < 0) { continue; } - - // if ((((boxD.easting - boxC.easting) * (plots[i].bndLine[p].northing - boxC.northing)) - // - ((boxD.northing - boxC.northing) * (plots[i].bndLine[p].easting - boxC.easting))) < 0) { continue; } - - // if ((((boxC.easting - boxB.easting) * (plots[i].bndLine[p].northing - boxB.northing)) - // - ((boxC.northing - boxB.northing) * (plots[i].bndLine[p].easting - boxB.easting))) < 0) { continue; } - - // if ((((boxA.easting - boxD.easting) * (plots[i].bndLine[p].northing - boxD.northing)) - // - ((boxA.northing - boxD.northing) * (plots[i].bndLine[p].easting - boxD.easting))) < 0) { continue; } - - // //it's in the box, so add to list - // inBox.easting = plots[i].bndLine[p].easting; - // inBox.northing = plots[i].bndLine[p].northing; - // inBox.heading = plots[i].bndLine[p].heading; - // inBox.index = i; - - // //which boundary/headland is it from - // bndClosestList.Add(inBox); - // } - // } - - // //which of the points is closest - // closestBoundaryPt.easting = -20000; closestBoundaryPt.northing = -20000; - // ptCount = bndClosestList.Count; - // if (ptCount != 0) - // { - // //determine closest point - // double minDistance = 9999999; - // for (int i = 0; i < ptCount; i++) - // { - // double dist = ((fromPt.easting - bndClosestList[i].easting) * (fromPt.easting - bndClosestList[i].easting)) - // + ((fromPt.northing - bndClosestList[i].northing) * (fromPt.northing - bndClosestList[i].northing)); - // if (minDistance >= dist) - // { - // minDistance = dist; - - // closestBoundaryPt.easting = bndClosestList[i].easting; - // closestBoundaryPt.northing = bndClosestList[i].northing; - // closestBoundaryPt.heading = bndClosestList[i].heading; - // closestBoundaryNum = bndClosestList[i].index; - // } - // } - // if (closestBoundaryPt.heading < 0) closestBoundaryPt.heading += glm.twoPI; - // } - //} \ No newline at end of file +} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CFenceLine.cs b/SourceCode/GPS/Classes/CFenceLine.cs index 9a84e554b..b4aceed01 100644 --- a/SourceCode/GPS/Classes/CFenceLine.cs +++ b/SourceCode/GPS/Classes/CFenceLine.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using OpenTK.Graphics.OpenGL; namespace AgOpenGPS { @@ -11,7 +8,7 @@ public partial class CBoundaryList public double area; //boundary variables - public bool isDriveAround, isDriveThru; + public bool isDriveThru; public void CalculateFenceLineHeadings() { @@ -148,47 +145,11 @@ public void ReverseWinding() } } - public void DrawFenceLine(int lw, bool outOfBounds) - { - ////draw the perimeter line so far - if (fenceLine.Count < 1) return; - //GL.PointSize(8); - //int ptCount = bndLine.Count; - //GL.Color3(0.925f, 0.752f, 0.860f); - ////else - //GL.Begin(PrimitiveType.Points); - //for (int h = 0; h < ptCount; h++) GL.Vertex3(bndLine[h].easting, bndLine[h].northing, 0); - ////GL.Color3(0.95f, 0.972f, 0.90f); - ////GL.Vertex3(bndLine[0].easting, bndLine[0].northing, 0); - //GL.End(); - - //ptCount = bdList.Count; - //if (ptCount < 1) return; - if (!outOfBounds) - { - GL.Color3(0.95f, 0.75f, 0.50f); - GL.LineWidth(lw); - } - else - { - GL.LineWidth(lw * 3); - GL.Color3(0.95f, 0.25f, 0.250f); - } - - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < fenceLineEar.Count; i++) - { - GL.Vertex3(fenceLineEar[i].easting, fenceLineEar[i].northing, 0); - } - GL.End(); - } - //obvious public bool CalculateFenceArea(int idx) { int ptCount = fenceLine.Count; if (ptCount < 1) return false; - bool isClockwise = true; area = 0; // Accumulates area in the loop int j = ptCount - 1; // The last vertex is the 'previous' one to the first @@ -197,7 +158,8 @@ public bool CalculateFenceArea(int idx) { area += (fenceLine[j].easting + fenceLine[i].easting) * (fenceLine[j].northing - fenceLine[i].northing); } - if (area < 0) isClockwise = false; + + bool isClockwise = area >= 0; area = Math.Abs(area / 2); diff --git a/SourceCode/GPS/Classes/CGLM.cs b/SourceCode/GPS/Classes/CGLM.cs index ea5a52bbc..ab792ea4d 100644 --- a/SourceCode/GPS/Classes/CGLM.cs +++ b/SourceCode/GPS/Classes/CGLM.cs @@ -1,12 +1,12 @@ -using System; +using OpenTK.Graphics.OpenGL; +using System; using System.Collections.Generic; -using System.Windows.Forms; namespace AgOpenGPS { public static class glm { - public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) + public static bool IsPointInPolygon(this List polygon, vec3 testPoint) { bool result = false; int j = polygon.Count - 1; @@ -27,7 +27,7 @@ public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) return result; } - public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) + public static bool IsPointInPolygon(this List polygon, vec2 testPoint) { bool result = false; int j = polygon.Count - 1; @@ -47,7 +47,8 @@ public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) } return result; } - public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) + + public static bool IsPointInPolygon(this List polygon, vec2 testPoint) { bool result = false; int j = polygon.Count - 1; @@ -67,7 +68,8 @@ public static bool IsPointInPolygon(vec2 testPoint, ref List polygon) } return result; } - public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) + + public static bool IsPointInPolygon(this List polygon, vec3 testPoint) { bool result = false; int j = polygon.Count - 1; @@ -88,6 +90,19 @@ public static bool IsPointInPolygon(vec3 testPoint, ref List polygon) return result; } + public static void DrawPolygon(this List polygon) + { + if (polygon.Count > 1) + { + GL.Begin(PrimitiveType.LineLoop); + for (int i = 0; i < polygon.Count; i++) + { + GL.Vertex3(polygon[i].easting, polygon[i].northing, 0); + } + GL.End(); + } + } + // Catmull Rom interpoint spline calculation public static vec3 Catmull(double t, vec3 p0, vec3 p1, vec3 p2, vec3 p3) { diff --git a/SourceCode/GPS/Classes/CHead.cs b/SourceCode/GPS/Classes/CHead.cs index 08dcdae02..ae0a347ce 100644 --- a/SourceCode/GPS/Classes/CHead.cs +++ b/SourceCode/GPS/Classes/CHead.cs @@ -5,18 +5,7 @@ namespace AgOpenGPS public partial class CBoundary { public bool isHeadlandOn; - public double leftToolDistance; - public double rightToolDistance; - - //generated box for finding closest point - public vec2 downL = new vec2(9000, 9000), downR = new vec2(9000, 9002); - - public bool isToolInHeadland, isToolUp, isToolOuterPointsInHeadland; - - public bool isToolLeftIn = false; - public bool isToolRightIn = false; - public bool isLookRightIn = false; - public bool isLookLeftIn = false; + public bool isToolInHeadland, isToolOuterPointsInHeadland; public void SetHydPosition() { @@ -25,12 +14,10 @@ public void SetHydPosition() if (isToolInHeadland) { mf.p_239.pgn[mf.p_239.hydLift] = 2; - isToolUp = true; } else { mf.p_239.pgn[mf.p_239.hydLift] = 1; - isToolUp = false; } } } @@ -41,44 +28,24 @@ public void WhereAreToolCorners() { bool isLeftInWk, isRightInWk = true; - if (isHeadlandOn) + for (int j = 0; j < mf.tool.numOfSections; j++) { - for (int j = 0; j < mf.tool.numOfSections; j++) - { - if (j == 0) - { - //only one first left point, the rest are all rights moved over to left - isLeftInWk = glm.IsPointInPolygon(mf.section[j].leftPoint, ref bndList[0].hdLine); - isRightInWk = glm.IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); - - //save left side - mf.tool.isLeftSideInHeadland = !isLeftInWk; - - //merge the two sides into in or out - mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; - - } - else - { - //grab the right of previous section, its the left of this section - isLeftInWk = isRightInWk; - isRightInWk = glm.IsPointInPolygon(mf.section[j].rightPoint, ref bndList[0].hdLine); - - mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; - } - } + isLeftInWk = j == 0 ? IsPointInsideHeadArea(mf.section[j].leftPoint) : isRightInWk; + isRightInWk = IsPointInsideHeadArea(mf.section[j].rightPoint); - //save right side - mf.tool.isRightSideInHeadland = !isRightInWk; + //save left side + if (j == 0) + mf.tool.isLeftSideInHeadland = !isLeftInWk; - //is the tool in or out based on endpoints - isToolOuterPointsInHeadland = mf.tool.isLeftSideInHeadland && mf.tool.isRightSideInHeadland; - } - else - { - //set all to true; - isToolOuterPointsInHeadland = true; + //merge the two sides into in or out + mf.section[j].isInHeadlandArea = !isLeftInWk && !isRightInWk; } + + //save right side + mf.tool.isRightSideInHeadland = !isRightInWk; + + //is the tool in or out based on endpoints + isToolOuterPointsInHeadland = mf.tool.isLeftSideInHeadland && mf.tool.isRightSideInHeadland; } } @@ -86,54 +53,43 @@ public void WhereAreToolLookOnPoints() { if (bndList.Count > 0 && bndList[0].hdLine.Count > 0) { + bool isLookRightIn = false; + vec3 toolFix = mf.toolPos; double sinAB = Math.Sin(toolFix.heading); double cosAB = Math.Cos(toolFix.heading); - double pos = mf.section[0].rpSectionWidth; + //generated box for finding closest point + double pos = 0; double mOn = (mf.tool.lookAheadDistanceOnPixelsRight - mf.tool.lookAheadDistanceOnPixelsLeft) / mf.tool.rpWidth; - double endHeight = (mf.tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * 0.1; for (int j = 0; j < mf.tool.numOfSections; j++) { - if (j == 0) - { - downL.easting = mf.section[j].leftPoint.easting + (sinAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1); - downL.northing = mf.section[j].leftPoint.northing + (cosAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1); - - downR.easting = mf.section[j].rightPoint.easting + (sinAB * endHeight); - downR.northing = mf.section[j].rightPoint.northing + (cosAB * endHeight); - isLookLeftIn = IsPointInsideHeadLine(downL); - isLookRightIn = IsPointInsideHeadLine(downR); + bool isLookLeftIn = j == 0 ? IsPointInsideHeadArea(new vec2( + mf.section[j].leftPoint.easting + (sinAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1), + mf.section[j].leftPoint.northing + (cosAB * mf.tool.lookAheadDistanceOnPixelsLeft * 0.1))) : isLookRightIn; - mf.section[j].isLookOnInHeadland = !isLookLeftIn && !isLookRightIn; - isLookLeftIn = isLookRightIn; - } - else - { - pos += mf.section[j].rpSectionWidth; - endHeight = (mf.tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * 0.1; + pos += mf.section[j].rpSectionWidth; + double endHeight = (mf.tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * 0.1; - downR.easting = mf.section[j].rightPoint.easting + (sinAB * endHeight); - downR.northing = mf.section[j].rightPoint.northing + (cosAB * endHeight); + isLookRightIn = IsPointInsideHeadArea(new vec2( + mf.section[j].rightPoint.easting + (sinAB * endHeight), + mf.section[j].rightPoint.northing + (cosAB * endHeight))); - isLookRightIn = IsPointInsideHeadLine(downR); - mf.section[j].isLookOnInHeadland = !isLookLeftIn && !isLookRightIn; - isLookLeftIn = isLookRightIn; - } + mf.section[j].isLookOnInHeadland = !isLookLeftIn && !isLookRightIn; } } } - public bool IsPointInsideHeadLine(vec2 pt) + public bool IsPointInsideHeadArea(vec2 pt) { //if inside outer boundary, then potentially add - if (bndList.Count > 0 && glm.IsPointInPolygon(pt, ref bndList[0].hdLine)) + if (bndList[0].hdLine.IsPointInPolygon(pt)) { - for (int b = 1; b < bndList.Count; b++) + for (int i = 1; i < bndList.Count; i++) { - if (glm.IsPointInPolygon(pt, ref bndList[b].hdLine)) + if (bndList[i].hdLine.IsPointInPolygon(pt)) { //point is in an inner turn area but inside outer return false; @@ -141,10 +97,7 @@ public bool IsPointInsideHeadLine(vec2 pt) } return true; } - else - { - return false; - } + return false; } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CHeadLines.cs b/SourceCode/GPS/Classes/CHeadLines.cs deleted file mode 100644 index 634e61b08..000000000 --- a/SourceCode/GPS/Classes/CHeadLines.cs +++ /dev/null @@ -1,34 +0,0 @@ -using OpenTK.Graphics.OpenGL; - -namespace AgOpenGPS -{ - public partial class CBoundaryList - { - - public void DrawHeadLine() - { - if (hdLine.Count > 1) - { - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < hdLine.Count; i++) - { - GL.Vertex3(hdLine[i].easting, hdLine[i].northing, 0); - } - GL.End(); - } - } - - public void DrawHeadLineBackBuffer() - { - if (hdLine.Count > 1) - { - GL.Begin(PrimitiveType.LineLoop); - for (int i = 0; i < hdLine.Count; i++) - { - GL.Vertex3(hdLine[i].easting, hdLine[i].northing, 0); - } - GL.End(); - } - } - } -} \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CSection.cs b/SourceCode/GPS/Classes/CSection.cs index ad81f2090..4f08ef877 100644 --- a/SourceCode/GPS/Classes/CSection.cs +++ b/SourceCode/GPS/Classes/CSection.cs @@ -67,12 +67,12 @@ public class CSection public int rpSectionPosition = 0; //points in world space that start and end of section are in - public vec3 leftPoint; - public vec3 rightPoint; + public vec2 leftPoint; + public vec2 rightPoint; //used to determine left and right speed of section - public vec3 lastLeftPoint; - public vec3 lastRightPoint; + public vec2 lastLeftPoint; + public vec2 lastRightPoint; //whether or not this section is in boundary, headland public bool isInBoundary = true, isHydLiftInWorkArea = true; @@ -103,8 +103,7 @@ public void TurnMappingOn(int j) isMappingOn = true; //starting a new patch chunk so create a new triangle list - triangleList = new List(); - triangleList.Capacity = 16; + triangleList = new List(32); patchList.Add(triangleList); @@ -205,23 +204,15 @@ public void AddMappingPoint(int j) //save the cutoff patch to be saved later mf.patchSaveList.Add(triangleList); - triangleList = new List(); - triangleList.Capacity = 32; + triangleList = new List(32); patchList.Add(triangleList); //Add Patch colour if (!mf.tool.isMultiColoredSections) - { - vec3 colur = new vec3(mf.sectionColorDay.R, mf.sectionColorDay.G, mf.sectionColorDay.B); - triangleList.Add(colur); - } - + triangleList.Add(new vec3(mf.sectionColorDay.R, mf.sectionColorDay.G, mf.sectionColorDay.B)); else - { - vec3 collor = new vec3(mf.tool.secColors[j].R, mf.tool.secColors[j].G, mf.tool.secColors[j].B); - triangleList.Add(collor); - } + triangleList.Add(new vec3(mf.tool.secColors[j].R, mf.tool.secColors[j].G, mf.tool.secColors[j].B)); //add the points to List, yes its more points, but breaks up patches for culling triangleList.Add(point); diff --git a/SourceCode/GPS/Classes/CTurn.cs b/SourceCode/GPS/Classes/CTurn.cs index 2dc00743c..3e48d16f3 100644 --- a/SourceCode/GPS/Classes/CTurn.cs +++ b/SourceCode/GPS/Classes/CTurn.cs @@ -1,5 +1,4 @@ -using OpenTK.Graphics.OpenGL; -using System; +using System; using System.Collections.Generic; namespace AgOpenGPS @@ -21,13 +20,29 @@ public partial class CBoundary //point at the farthest turn segment from pivotAxle public vec3 closestTurnPt = new vec3(-10000, -10000, 9); + public int IsPointInsideTurnArea(vec3 pt) + { + if (bndList.Count > 0 && bndList[0].turnLine.IsPointInPolygon(pt)) + { + for (int i = 1; i < bndList.Count; i++) + { + if (bndList[i].isDriveThru) continue; + if (bndList[i].turnLine.IsPointInPolygon(pt)) + { + return i; + } + } + return 0; + } + return -1; + } + public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB) { //initial scan is straight ahead of pivot point of vehicle to find the right turnLine/boundary vec3 pt = new vec3(); vec3 rayPt = new vec3(); - bool isFound = false; int closestTurnNum = 99; double cosHead = Math.Cos(headAB); @@ -38,31 +53,16 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB pt.easting = fromPt.easting + (sinHead * b); pt.northing = fromPt.northing + (cosHead * b); - if (glm.IsPointInPolygon(pt, ref bndList[0].turnLine)) - { - for (int t = 1; t < bndList.Count; t++) - { - if (bndList[t].isDriveThru) continue; - if (bndList[t].isDriveAround) continue; - if (glm.IsPointInPolygon(pt, ref bndList[t].turnLine)) - { - isFound = true; - closestTurnNum = t; - rayPt.easting = pt.easting; - rayPt.northing = pt.northing; - break; - } - } - if (isFound) break; - } - else + int idx = IsPointInsideTurnArea(pt); + if (idx != 0) { - closestTurnNum = 0; + closestTurnNum = idx; rayPt.easting = pt.easting; rayPt.northing = pt.northing; break; } } + if (closestTurnNum < 0) closestTurnNum = 0; //second scan is straight ahead of outside of tool based on turn direction double scanWidthL, scanWidthR; @@ -207,9 +207,6 @@ public void FindClosestTurnPoint(bool isYouTurnRight, vec3 fromPt, double headAB public void BuildTurnLines() { - //update the GUI values for boundaries - mf.fd.UpdateFieldBoundaryGUIAreas(); - if (bndList.Count == 0) { //mf.TimedMessageBox(1500, " No Boundaries", "No Turn Lines Made"); @@ -226,7 +223,7 @@ public void BuildTurnLines() for (int j = 0; j < bndList.Count; j++) { bndList[j].turnLine.Clear(); - if (bndList[j].isDriveThru || bndList[j].isDriveAround) continue; + if (bndList[j].isDriveThru) continue; int ptCount = bndList[j].fenceLine.Count; @@ -239,7 +236,7 @@ public void BuildTurnLines() if (point.heading < -glm.twoPI) point.heading += glm.twoPI; //only add if outside actual field boundary - if (j == 0 == glm.IsPointInPolygon(point, ref bndList[j].fenceLineEar)) + if (j == 0 == bndList[j].fenceLineEar.IsPointInPolygon(point)) { vec3 tPnt = new vec3(point.easting, point.northing, point.heading); bndList[j].turnLine.Add(tPnt); @@ -248,27 +245,5 @@ public void BuildTurnLines() bndList[j].FixTurnLine(totalHeadWidth, mf.tool.toolWidth * 0.33); } } - - public void DrawTurnLines() - { - GL.LineWidth(mf.ABLine.lineWidth); - GL.Color3(0.3555f, 0.6232f, 0.20f); - //GL.PointSize(2); - - for (int i = 0; i < bndList.Count; i++) - { - if (bndList[i].isDriveAround) continue; - //turnArr[i].DrawTurnLine(); - { - ////draw the turn line oject - int ptCount = bndList[i].turnLine.Count; - if (ptCount < 1) continue; - - GL.Begin(PrimitiveType.LineLoop); - for (int h = 0; h < ptCount; h++) GL.Vertex3(bndList[i].turnLine[h].easting, bndList[i].turnLine[h].northing, 0); - GL.End(); - } - } - } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CTurnLines.cs b/SourceCode/GPS/Classes/CTurnLines.cs index 83bd604fd..91dd97b7a 100644 --- a/SourceCode/GPS/Classes/CTurnLines.cs +++ b/SourceCode/GPS/Classes/CTurnLines.cs @@ -1,5 +1,4 @@ -using OpenTK.Graphics.OpenGL; -using System; +using System; namespace AgOpenGPS { @@ -99,44 +98,6 @@ public void FixTurnLine(double totalHeadWidth, double spacing) { CalculateTurnHeadings(); } - - //int cnt = turnLine.Count; - //vec3[] arr = new vec3[cnt]; - //turnLine.CopyTo(arr); - //turnLine.Clear(); - - //double delta = 0; - //for (int i = 0; i < arr.Length; i++) - //{ - // if (i == 0) - // { - // turnLine.Add(new vec3(arr[i].easting, arr[i].northing, arr[i].heading)); - // continue; - // } - // delta += (arr[i - 1].heading - arr[i].heading); - - // if (Math.Abs(delta) > 0.1) - // { - // vec3 pt = new vec3(arr[i].easting, arr[i].northing, arr[i].heading); - - // turnLine.Add(pt); - // delta = 0; - // } - //} - } - - public void DrawTurnLine() - { - ////draw the turn line oject - int ptCount = turnLine.Count; - if (ptCount < 1) return; - GL.LineWidth(1); - GL.Color3(0.8555f, 0.9232f, 0.60f); - GL.PointSize(2); - GL.Begin(PrimitiveType.LineLoop); - for (int h = 0; h < ptCount; h++) GL.Vertex3(turnLine[h].easting, turnLine[h].northing, 0); - GL.Vertex3(turnLine[0].easting, turnLine[0].northing, 0); - GL.End(); } } } \ No newline at end of file diff --git a/SourceCode/GPS/Classes/CYouTurn.cs b/SourceCode/GPS/Classes/CYouTurn.cs index df0268fdb..c629aba89 100644 --- a/SourceCode/GPS/Classes/CYouTurn.cs +++ b/SourceCode/GPS/Classes/CYouTurn.cs @@ -13,24 +13,12 @@ public class CYouTurn public bool isYouTurnTriggered; /// /// turning right or left?/// - public bool isYouTurnRight, isLastToggle; - - /// /// What was the last successful you turn direction? /// - public bool isLastYouTurnRight; - - //public bool isEnteringDriveThru = false, isExitingDriveThru = false; - - //if not in workArea but in bounds, then we are on headland - public bool isInWorkArea, isInBoundz; - - //controlled by user in GUI to en/dis able - public bool isRecordingCustomYouTurn; + public bool isYouTurnRight; /// /// Is the youturn button enabled? /// public bool isYouTurnBtnOn; public double boundaryAngleOffPerpendicular; - public double distanceTurnBeforeLine = 0, tangencyAngle; public int rowSkipsWidth = 1, uTurnSmoothing = 10; @@ -38,7 +26,7 @@ public class CYouTurn public int rowSkipsWidth2 = 3, turnSkips = 2; /// /// distance from headland as offset where to start turn shape /// - public int youTurnStartOffset, C; + public int youTurnStartOffset; //guidance values public double distanceFromCurrentLine, uturnDistanceFromBoundary, dxAB, dyAB; @@ -64,20 +52,14 @@ public class CYouTurn //list of points for scaled and rotated YouTurn line, used for pattern, dubins, abcurve, abline public List ytList = new List(); - ////list of points read from file, this is the actual pattern from a bunch of sources possible - //public List youFileList = new List(); - - //to try and pull a UTurn back in bounds - public double turnDistanceAdjuster; - //is UTurn pattern in or out of bounds public bool isOutOfBounds = false; //sequence of operations of finding the next turn 0 to 3 - public int youTurnPhase, curListCount; + public int youTurnPhase; public vec4 crossingCurvePoint = new vec4(); - public vec4 crossingTurnLinePoint = new vec4(); + public double crossingheading = 0; //constructor public CYouTurn(FormGPS _f) @@ -98,94 +80,29 @@ public CYouTurn(FormGPS _f) //Finds the point where an AB Curve crosses the turn line public bool FindCurveTurnPoints() { - crossingCurvePoint.easting = -20000; - crossingTurnLinePoint.easting = -20000; + crossingCurvePoint.easting = -20000; //find closet AB Curve point that will cross and go out of bounds - curListCount = mf.curve.curList.Count; - - //otherwise we count down - bool isCountingUp = mf.curve.isHeadingSameWay; + int Count = mf.curve.isHeadingSameWay ? 1 : -1; + int turnNum = 99; - //check if outside a border - if (isCountingUp) + for (int j = mf.curve.currentLocationIndex; j > 0 && j < mf.curve.curList.Count; j += Count) { - crossingTurnLinePoint.index = 99; - - //for each point in succession keep going till a turnLine is found. - for (int j = mf.curve.currentLocationIndex; j < curListCount; j++) + int idx = mf.bnd.IsPointInsideTurnArea(mf.curve.curList[j]); + if (idx != 0) { - if (!glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) - { //it passed outer turnLine - crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; - crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; - crossingCurvePoint.heading = mf.curve.curList[j - 1].heading; - crossingCurvePoint.index = j - 1; - crossingTurnLinePoint.index = 0; - goto CrossingFound; - } - - for (int i = 1; i < mf.bnd.bndList.Count; i++) - { - //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) - { - crossingCurvePoint.easting = mf.curve.curList[j - 1].easting; - crossingCurvePoint.northing = mf.curve.curList[j - 1].northing; - crossingCurvePoint.heading = mf.curve.curList[j - 1].heading; - crossingCurvePoint.index = j - 1; - crossingTurnLinePoint.index = i; - goto CrossingFound; - } - } - } - - //escape for multiple for's - CrossingFound:; - - } - else //counting down, going opposite way mf.curve was created. - { - crossingTurnLinePoint.index = 99; - - for (int j = mf.curve.currentLocationIndex; j > 0; j--) - { - if (!glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[0].turnLine)) - { //it passed outer turnLine - crossingCurvePoint.easting = mf.curve.curList[j + 1].easting; - crossingCurvePoint.northing = mf.curve.curList[j + 1].northing; - crossingCurvePoint.heading = mf.curve.curList[j + 1].heading; - crossingCurvePoint.index = j + 1; - crossingTurnLinePoint.index = 0; - goto CrossingFound; - } - - for (int i = 1; i < mf.bnd.bndList.Count; i++) - { - //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (glm.IsPointInPolygon(mf.curve.curList[j], ref mf.bnd.bndList[i].turnLine)) - { - crossingCurvePoint.easting = mf.curve.curList[j].easting; - crossingCurvePoint.northing = mf.curve.curList[j].northing; - crossingCurvePoint.heading = mf.curve.curList[j].heading; - crossingCurvePoint.index = j; - crossingTurnLinePoint.index = i; - goto CrossingFound; - } - } + crossingCurvePoint.easting = mf.curve.curList[j - Count].easting; + crossingCurvePoint.northing = mf.curve.curList[j - Count].northing; + crossingCurvePoint.heading = mf.curve.curList[j - Count].heading; + crossingCurvePoint.index = j - Count; + turnNum = idx; + break; } - - //escape for multiple for's, point and turnLine index are found - CrossingFound:; } - int turnNum = crossingTurnLinePoint.index; - - if (turnNum == 99) + if (turnNum < 0) + turnNum = 0; + else if (turnNum == 99) { isTurnCreationNotCrossingError = true; return false; @@ -198,10 +115,10 @@ public bool FindCurveTurnPoints() for (int j = 0; j < curTurnLineCount; j++) { - if ((mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 2 - && (mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -2 - && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 2 - && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -2) + if ((mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) < 15 + && (mf.bnd.bndList[turnNum].turnLine[j].easting - crossingCurvePoint.easting) > -15 + && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) < 15 + && (mf.bnd.bndList[turnNum].turnLine[j].northing - crossingCurvePoint.northing) > -15) { turnLineCloseList.Add(j); } @@ -209,6 +126,7 @@ public bool FindCurveTurnPoints() double dist1, dist2 = 99; curTurnLineCount = turnLineCloseList.Count; + int index = -1; for (int i = 0; i < curTurnLineCount; i++) { dist1 = glm.Distance(mf.bnd.bndList[turnNum].turnLine[turnLineCloseList[i]].easting, @@ -216,17 +134,16 @@ public bool FindCurveTurnPoints() crossingCurvePoint.easting, crossingCurvePoint.northing); if (dist1 < dist2) { - crossingTurnLinePoint.index = turnLineCloseList[i]; + index = turnLineCloseList[i]; dist2 = dist1; } } - //fill up the coords - crossingTurnLinePoint.easting = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].easting; - crossingTurnLinePoint.northing = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].northing; - crossingTurnLinePoint.heading = mf.bnd.bndList[turnNum].turnLine[crossingTurnLinePoint.index].heading; + crossingheading = -20000; + if (index >= 0) + crossingheading = mf.bnd.bndList[turnNum].turnLine[index].heading; - return crossingCurvePoint.easting != -20000 && crossingCurvePoint.easting != -20000; + return crossingheading != -20000 && crossingCurvePoint.easting != -20000; } public void AddSequenceLines(double head) @@ -408,13 +325,13 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) if (boundaryAngleOffPerpendicular < -1.25) boundaryAngleOffPerpendicular = -1.25; //for calculating innner circles of turn - tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; + double tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; //baseline away from boundary to start calculations double toolTurnWidth = mf.tool.toolWidth * rowSkipsWidth; //distance from TurnLine for trigger added in youturn form, include the 3 m bump forward - distanceTurnBeforeLine = 0; + double distanceTurnBeforeLine = 0; if (mf.vehicle.minTurningRadius * 2 < toolTurnWidth) { @@ -584,21 +501,11 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!glm.IsPointInPolygon(ytList[j],ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; - if (isOutOfBounds) break; - - for (int i = 1; i < mf.bnd.bndList.Count; i++) + if (mf.bnd.IsPointInsideTurnArea(ytList[j]) != 0) { - //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) - { - isOutOfBounds = true; - break; - } + isOutOfBounds = true; + break; } - if (isOutOfBounds) break; } if (!isOutOfBounds) @@ -644,23 +551,11 @@ public bool BuildABLineDubinsYouTurn(bool isTurnRight) for (int j = 0; j < cnt; j += 2) { - if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) isOutOfBounds = true; - if (isOutOfBounds) - break; - - for (int i = 1; i < mf.bnd.bndList.Count; i++) + if (mf.bnd.IsPointInsideTurnArea(ytList[j]) != 0) { - //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[i].turnLine)) - { - isOutOfBounds = true; - break; - } - } - if (isOutOfBounds) + isOutOfBounds = true; break; + } } if (isOutOfBounds) @@ -698,15 +593,16 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) if (!isHeadingSameWay) head += Math.PI; //delta between AB heading and boundary closest point heading - boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(crossingTurnLinePoint.heading - head) - Math.PI); + boundaryAngleOffPerpendicular = Math.PI - Math.Abs(Math.Abs(crossingheading - head) - Math.PI); boundaryAngleOffPerpendicular -= glm.PIBy2; boundaryAngleOffPerpendicular *= -1; if (boundaryAngleOffPerpendicular > 1.25) boundaryAngleOffPerpendicular = 1.25; if (boundaryAngleOffPerpendicular < -1.25) boundaryAngleOffPerpendicular = -1.25; //for calculating innner circles of turn - tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; + double tangencyAngle = (glm.PIBy2 - Math.Abs(boundaryAngleOffPerpendicular)) * 0.5; + double distanceTurnBeforeLine; //distance from crossPoint to turn line if (mf.vehicle.minTurningRadius * 2 < (mf.tool.toolWidth * rowSkipsWidth)) { @@ -852,24 +748,11 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) isOutOfBounds = false; for (int j = 0; j < count; j += 2) { - if (!glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[0].turnLine)) + if (mf.bnd.IsPointInsideTurnArea(ytList[j]) != 0) { isOutOfBounds = true; break; } - - for (int i = 1; i < mf.bnd.bndList.Count; i++) - { - //make sure not inside a non drivethru boundary - if (mf.bnd.bndList[i].isDriveThru) continue; - if (mf.bnd.bndList[i].isDriveAround) continue; - if (glm.IsPointInPolygon(ytList[j], ref mf.bnd.bndList[1].turnLine)) - { - isOutOfBounds = true; - break; - } - } - if (isOutOfBounds) break; } //first check if not out of bounds, add a bit more to clear turn line, set to phase 2 @@ -902,8 +785,8 @@ public bool BuildCurveDubinsYouTurn(bool isTurnRight, vec3 pivotPos) else { crossingCurvePoint.index++; - if (crossingCurvePoint.index >= curListCount) - crossingCurvePoint.index = curListCount - 1; + if (crossingCurvePoint.index >= mf.curve.curList.Count) + crossingCurvePoint.index = mf.curve.curList.Count - 1; } crossingCurvePoint.easting = mf.curve.curList[crossingCurvePoint.index].easting; crossingCurvePoint.northing = mf.curve.curList[crossingCurvePoint.index].northing; @@ -1027,7 +910,6 @@ public void ResetYouTurn() isYouTurnTriggered = false; ytList?.Clear(); ResetCreatedYouTurn(); - turnDistanceAdjuster = 0; mf.isBoundAlarming = false; isTurnCreationTooClose = false; isTurnCreationNotCrossingError = false; @@ -1035,7 +917,6 @@ public void ResetYouTurn() public void ResetCreatedYouTurn() { - turnDistanceAdjuster = 0; youTurnPhase = 0; ytList?.Clear(); } @@ -1223,7 +1104,7 @@ public bool DistanceFromYouTurnLine() } //just need to make sure the points continue ascending or heading switches all over the place - if (A > B) { C = A; A = B; B = C; } + if (A > B) { int C = A; A = B; B = C; } //minDistA = 100; //int closestPt = 0; @@ -1324,7 +1205,7 @@ public bool DistanceFromYouTurnLine() } //just need to make sure the points continue ascending or heading switches all over the place - if (A > B) { C = A; A = B; B = C; } + if (A > B) { int C = A; A = B; B = C; } minDistA = 100; int closestPt = 0; diff --git a/SourceCode/GPS/Forms/Controls.Designer.cs b/SourceCode/GPS/Forms/Controls.Designer.cs index 0c1cc25dc..251d328ae 100644 --- a/SourceCode/GPS/Forms/Controls.Designer.cs +++ b/SourceCode/GPS/Forms/Controls.Designer.cs @@ -780,30 +780,29 @@ private void setWorkingDirectoryToolStripMenuItem_Click(object sender, EventArgs if (Settings.Default.setF_workingDirectory == "Default") fbd.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); else fbd.SelectedPath = Settings.Default.setF_workingDirectory; - if (fbd.ShowDialog() == DialogResult.OK) + if (fbd.ShowDialog(this) == DialogResult.OK) { if (fbd.SelectedPath != Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) { Settings.Default.setF_workingDirectory = fbd.SelectedPath; - Settings.Default.Save(); } else { Settings.Default.setF_workingDirectory = "Default"; - Settings.Default.Save(); } + Settings.Default.Save(); //restart program MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); Close(); } } + private void enterSimCoordsToolStripMenuItem_Click(object sender, EventArgs e) { - var result = DialogResult.Cancel; using (var form = new FormSimCoords(this)) { - result = form.ShowDialog(); + form.ShowDialog(this); } } @@ -811,10 +810,10 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new Form_About()) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) { } + form.ShowDialog(this); } } + private void resetALLToolStripMenuItem_Click(object sender, EventArgs e) { if (isJobStarted) @@ -1020,14 +1019,12 @@ private void simulatorOnToolStripMenuItem_Click(object sender, EventArgs e) Settings.Default.setMenu_isSimulatorOn = simulatorOnToolStripMenuItem.Checked; Settings.Default.Save(); } + private void colorsToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new FormColor(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) - { - } + form.ShowDialog(this); } } @@ -1035,165 +1032,69 @@ private void colorsSectionToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new FormSectionColor(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) - { - } + form.ShowDialog(this); } } //Languages private void menuLanguageEnglish_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("en"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - + SetLanguage("en", true); } private void menuLanguageDanish_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("da"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - + SetLanguage("da", true); } private void menuLanguageDeutsch_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("de"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - + SetLanguage("de", true); } private void menuLanguageRussian_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("ru"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("ru", true); } private void menuLanguageDutch_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("nl"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("nl", true); } private void menuLanguageSpanish_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("es"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("es", true); } private void menuLanguageFrench_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("fr"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("fr", true); } private void menuLanguageItalian_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("it"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("it", true); } private void menuLanguageUkranian_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("uk"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("uk", true); } private void menuLanguageSlovak_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("sk"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - + SetLanguage("sk", true); } private void menuLanguagesPolski_Click(object sender, EventArgs e) { - if (isJobStarted) - { - var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); - form.Show(this); - return; - } - SetLanguage("pl"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); + SetLanguage("pl", true); } private void menuLanguageTest_Click(object sender, EventArgs e) { - if (isJobStarted) + SetLanguage("af", true); + } + + private void SetLanguage(string lang, bool Restart) + { + if (Restart && isJobStarted) { var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); form.Show(this); return; } - SetLanguage("af"); - MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); - System.Environment.Exit(1); - } - private void SetLanguage(string lang) - { //reset them all to false menuLanguageEnglish.Checked = false; menuLanguageDeutsch.Checked = false; @@ -1274,6 +1175,12 @@ private void SetLanguage(string lang) //storing the values key.SetValue("Language", lang); key.Close(); + + if (Restart) + { + MessageBox.Show(gStr.gsProgramWillExitPleaseRestart); + System.Environment.Exit(1); + } } #endregion @@ -1347,16 +1254,10 @@ public void CloseTopMosts() private void btnOpenConfig_Click(object sender, EventArgs e) { - //check if window already exists - - //Form form = new FormConfig(this); - //form.Show(this); - using (var form = new FormConfig(this)) { form.ShowDialog(this); } - } private void btnTramDisplayMode_Click(object sender, EventArgs e) @@ -1388,8 +1289,7 @@ private void btnChangeMappingColor_Click(object sender, EventArgs e) { using (var form = new FormColorPicker(this, sectionColorDay)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) + if (form.ShowDialog(this) == DialogResult.OK) { sectionColorDay = form.useThisColor; } @@ -1508,10 +1408,7 @@ public void GetAB() using (var form = new FormABDraw(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) - { - } + form.ShowDialog(this); ABLine.moveDistance = 0; curve.moveDistance = 0; } @@ -1610,8 +1507,7 @@ private void SmoothABtoolStripMenu_Click(object sender, EventArgs e) { using (var form = new FormSmoothAB(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) { } + form.ShowDialog(this); } } else @@ -1733,8 +1629,7 @@ private void offsetFixToolStrip_Click(object sender, EventArgs e) { using (var form = new FormShiftPos(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) { } + form.ShowDialog(this); } } @@ -1827,12 +1722,12 @@ private void toolStripBtnFieldOpen_Click(object sender, EventArgs e) { using (var form = new FormJob(this)) { - var result = form.ShowDialog(); + var result = form.ShowDialog(this); if (result == DialogResult.Yes) { //ask for a directory name using (var form2 = new FormFieldDir(this)) - { form2.ShowDialog(); } + { form2.ShowDialog(this); } } //load from KML @@ -1840,7 +1735,7 @@ private void toolStripBtnFieldOpen_Click(object sender, EventArgs e) { //ask for a directory name using (var form2 = new FormFieldKML(this)) - { form2.ShowDialog(); } + { form2.ShowDialog(this); } } } @@ -1913,7 +1808,7 @@ private void CloseCurrentJob() //ask for a directory name using (var form2 = new FormSaveAs(this)) { - form2.ShowDialog(); + form2.ShowDialog(this); } break; @@ -1926,8 +1821,7 @@ private void toolStripBtnMakeBndContour_Click(object sender, EventArgs e) //build all the contour guidance lines from boundaries, all of them. using (var form = new FormMakeBndCon(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) { } + form.ShowDialog(this); } } private void tramLinesMenuField_Click(object sender, EventArgs e) @@ -1971,7 +1865,7 @@ public void GetHeadland() { using (var form = new FormHeadland (this)) { - form.ShowDialog(); + form.ShowDialog(this); } if (bnd.bndList.Count > 0 && bnd.bndList[0].hdLine.Count > 0) @@ -2000,8 +1894,7 @@ private void boundariesToolStripMenuItem_Click(object sender, EventArgs e) { using (var form = new FormBoundary(this)) { - var result = form.ShowDialog(); - if (result == DialogResult.OK) + if (form.ShowDialog(this) == DialogResult.OK) { Form form2 = new FormBoundaryPlayer(this); form2.Show(this); @@ -2205,33 +2098,6 @@ public void FixTramModeButton() default: break; } - - } - - private void googleEarthFlagsToolStrip_Click(object sender, EventArgs e) - { - if (isJobStarted) - { - //save new copy of flags - FileSaveFieldKML(); - - //Process.Start(@"C:\Program Files (x86)\Google\Google Earth\client\googleearth", workingDirectory + currentFieldDirectory + "\\Flags.KML"); - Process.Start(fieldsDirectory + currentFieldDirectory + "\\Field.KML"); - } - else - { - var form = new FormTimedMessage(1500, gStr.gsFieldNotOpen, gStr.gsStartNewField); - form.Show(this); - } } - private void ZoomExtentsStripBtn_Click(object sender, EventArgs e) - { - if (camera.camSetDistance < -400) camera.camSetDistance = -75; - else camera.camSetDistance = -3 * maxFieldDistance; - if (camera.camSetDistance == 0) camera.camSetDistance = -2000; - SetZoom(); - } - - private Button btnEditAB; }//end class }//end namespace \ No newline at end of file diff --git a/SourceCode/GPS/Forms/FormBoundary.cs b/SourceCode/GPS/Forms/FormBoundary.cs index 4718ceb52..a10590f96 100644 --- a/SourceCode/GPS/Forms/FormBoundary.cs +++ b/SourceCode/GPS/Forms/FormBoundary.cs @@ -10,9 +10,8 @@ public partial class FormBoundary : Form { private readonly FormGPS mf = null; - private bool Selectedreset = true; - private double easting, norting, latK, lonK; + private int fenceSelected = -1; public FormBoundary(Form callingForm) { @@ -119,7 +118,6 @@ private void UpdateChart() { //cc.Text = "Outer"; mf.bnd.bndList[i].isDriveThru = false; - mf.bnd.bndList[i].isDriveAround = false; a.Text = string.Format(gStr.gsOuter); //a.Font = backupfont; d.Text = mf.bnd.bndList[i].isDriveThru ? "--" : "--"; @@ -151,7 +149,7 @@ private void UpdateChart() b.Text = Math.Round(mf.bnd.bndList[i].area * 0.000247105, 2) + " Ac"; } - if (Selectedreset == false && i == mf.bnd.fenceSelected) + if (i == fenceSelected) { a.ForeColor = Color.OrangeRed; b.ForeColor = Color.OrangeRed; @@ -174,39 +172,21 @@ private void DriveThru_Click(object sender, EventArgs e) } } - private void DriveAround_Click(object sender, EventArgs e) - { - if (sender is Button b) - { - mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround = !mf.bnd.bndList[Convert.ToInt32(b.Name)].isDriveAround; - UpdateChart(); - } - } - private void B_Click(object sender, EventArgs e) { if (sender is Button b) { - - mf.bnd.fenceSelected = Convert.ToInt32(b.Name); - - if (mf.bnd.fenceSelected == 0 && mf.bnd.bndList.Count > 1) - { - return; - } - - Selectedreset = false; - - if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) - { + int oldfenceSelected = fenceSelected; + fenceSelected = Convert.ToInt32(b.Name); + + if (fenceSelected == oldfenceSelected) + fenceSelected = -1; + else if (fenceSelected == 0) + btnDelete.Enabled = mf.bnd.bndList.Count == 1; + else if (fenceSelected > 0) btnDelete.Enabled = true; - } - else - { - btnDelete.Enabled = false; - btnDeleteAll.Enabled = false; - } + btnDeleteAll.Enabled = fenceSelected == -1; } UpdateChart(); } @@ -229,15 +209,13 @@ private void btnDelete_Click(object sender, EventArgs e) btnDelete.Enabled = false; - if (mf.bnd.bndList.Count > mf.bnd.fenceSelected) + if (mf.bnd.bndList.Count > fenceSelected) { - mf.bnd.bndList.RemoveAt(mf.bnd.fenceSelected); + mf.bnd.bndList.RemoveAt(fenceSelected); } + fenceSelected = -1; mf.FileSaveBoundary(); - - mf.bnd.fenceSelected = -1; - Selectedreset = true; mf.fd.UpdateFieldBoundaryGUIAreas(); mf.bnd.BuildTurnLines(); UpdateChart(); @@ -250,6 +228,7 @@ private void btnDelete_Click(object sender, EventArgs e) private void ResetAllBoundary() { + fenceSelected = -1; mf.bnd.bndList.Clear(); mf.FileSaveBoundary(); tableLayoutPanel1.Controls.Clear(); @@ -282,9 +261,6 @@ private void btnDeleteAll_Click(object sender, EventArgs e) ResetAllBoundary(); - mf.bnd.fenceSelected = -1; - Selectedreset = true; - mf.bnd.isOkToAddPoints = false; mf.fd.UpdateFieldBoundaryGUIAreas(); } @@ -310,10 +286,6 @@ private void btnReturn_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e) { - mf.bnd.fenceSelected = mf.bnd.bndList.Count; - - Selectedreset = false; - panelMain.Visible = false; panelKML.Visible = false; panelChoose.Visible = true; @@ -326,8 +298,6 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) { if (sender is Button button) { - Selectedreset = true; - string fileAndDirectory; { //create the dialog instance @@ -341,19 +311,17 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) }; //was a file selected - if (ofd.ShowDialog() == DialogResult.Cancel) return; + if (ofd.ShowDialog(this) == DialogResult.Cancel) return; else fileAndDirectory = ofd.FileName; } string coordinates = null; int startIndex; - int i = 0; using (StreamReader reader = new StreamReader(fileAndDirectory)) { if (button.Name == "btnLoadMultiBoundaryFromGE") ResetAllBoundary(); - else i = mf.bnd.fenceSelected; try { @@ -408,17 +376,14 @@ private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e) New.fenceLine.Add(new vec3(easting, norting, 0)); } - New.CalculateFenceArea(mf.bnd.fenceSelected); - New.FixFenceLine(i); + New.CalculateFenceArea(mf.bnd.bndList.Count); + New.FixFenceLine(mf.bnd.bndList.Count); mf.bnd.bndList.Add(New); - mf.fd.UpdateFieldBoundaryGUIAreas(); - mf.btnMakeLinesFromBoundary.Visible = true; coordinates = ""; - i++; } else { diff --git a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs index 007aa0e2d..807c4bf42 100644 --- a/SourceCode/GPS/Forms/FormBoundaryPlayer.cs +++ b/SourceCode/GPS/Forms/FormBoundaryPlayer.cs @@ -36,24 +36,23 @@ private void btnStop_Click(object sender, EventArgs e) New.fenceLine.Add(mf.bnd.bndBeingMadePts[i]); } - New.CalculateFenceArea(mf.bnd.fenceSelected); - New.FixFenceLine(mf.bnd.fenceSelected); + New.CalculateFenceArea(mf.bnd.bndList.Count); + New.FixFenceLine(mf.bnd.bndList.Count); mf.bnd.bndList.Add(New); mf.fd.UpdateFieldBoundaryGUIAreas(); + + //turn lines made from boundaries + mf.CalculateMinMax(); + mf.FileSaveBoundary(); + mf.bnd.BuildTurnLines(); + //mf.hd.BuildSingleSpaceHeadLines(); + mf.btnMakeLinesFromBoundary.Visible = true; } //stop it all for adding mf.bnd.isOkToAddPoints = false; mf.bnd.isBndBeingMade = false; - - //turn lines made from boundaries - mf.CalculateMinMax(); - mf.FileSaveBoundary(); - mf.bnd.BuildTurnLines(); - //mf.hd.BuildSingleSpaceHeadLines(); - mf.btnMakeLinesFromBoundary.Visible = true; - mf.bnd.bndBeingMadePts.Clear(); //close window Close(); diff --git a/SourceCode/GPS/Forms/FormFieldKML.cs b/SourceCode/GPS/Forms/FormFieldKML.cs index 5b5a90d9c..7d772f4e4 100644 --- a/SourceCode/GPS/Forms/FormFieldKML.cs +++ b/SourceCode/GPS/Forms/FormFieldKML.cs @@ -121,12 +121,9 @@ private void LoadKMLBoundary(string filename) { string coordinates = null; int startIndex; - int i; using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - i = mf.bnd.fenceSelected; - try { while (!reader.EndOfStream) @@ -183,26 +180,20 @@ private void LoadKMLBoundary(string filename) } //build the boundary, make sure is clockwise for outer counter clockwise for inner - New.CalculateFenceArea(mf.bnd.fenceSelected); - New.FixFenceLine(i); + New.CalculateFenceArea(mf.bnd.bndList.Count); + New.FixFenceLine(mf.bnd.bndList.Count); mf.bnd.bndList.Add(New); - mf.fd.UpdateFieldBoundaryGUIAreas(); - mf.btnMakeLinesFromBoundary.Visible = true; coordinates = ""; - i++; } else { mf.TimedMessageBox(2000, gStr.gsErrorreadingKML, gStr.gsChooseBuildDifferentone); } - //if (button.Name == "btnLoadBoundaryFromGE") - //{ break; - //} } } mf.FileSaveBoundary(); @@ -228,13 +219,9 @@ private void FindLatLon(string filename) { string coordinates = null; int startIndex; - int i; using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - - i = mf.bnd.fenceSelected; - try { while (!reader.EndOfStream) @@ -291,7 +278,6 @@ private void FindLatLon(string filename) latK = lat / counter; coordinates = ""; - i++; } else { diff --git a/SourceCode/GPS/Forms/FormGPS.Designer.cs b/SourceCode/GPS/Forms/FormGPS.Designer.cs index aa1df4b77..320e3b904 100644 --- a/SourceCode/GPS/Forms/FormGPS.Designer.cs +++ b/SourceCode/GPS/Forms/FormGPS.Designer.cs @@ -2392,6 +2392,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem toolStripBtnMakeBndContour; private System.Windows.Forms.ToolStripMenuItem sectionColorToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem enterABToolStripMenuItem; + private System.Windows.Forms.Button btnEditAB; } } diff --git a/SourceCode/GPS/Forms/FormGPS.cs b/SourceCode/GPS/Forms/FormGPS.cs index bff8a1a65..9a978b33f 100644 --- a/SourceCode/GPS/Forms/FormGPS.cs +++ b/SourceCode/GPS/Forms/FormGPS.cs @@ -4,7 +4,6 @@ using OpenTK; using OpenTK.Graphics.OpenGL; using System; -using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; @@ -430,7 +429,7 @@ private void FormGPS_Load(object sender, EventArgs e) pictureboxStart.Dock = System.Windows.Forms.DockStyle.Fill; //set the language to last used - SetLanguage(Settings.Default.setF_culture); + SetLanguage(Settings.Default.setF_culture, false); currentVersionStr = Application.ProductVersion.ToString(CultureInfo.InvariantCulture); @@ -748,25 +747,11 @@ public void SwapDirection() { if (!yt.isYouTurnTriggered) { - //is it turning right already? - if (yt.isYouTurnRight) - { - yt.isYouTurnRight = false; - yt.isLastYouTurnRight = !yt.isLastYouTurnRight; - yt.ResetCreatedYouTurn(); - } - else - { - //make it turn the other way - yt.isYouTurnRight = true; - yt.isLastYouTurnRight = !yt.isLastYouTurnRight; - yt.ResetCreatedYouTurn(); - } - } - else - { - if (yt.isYouTurnBtnOn) btnAutoYouTurn.PerformClick(); + yt.isYouTurnRight = !yt.isYouTurnRight; + yt.ResetCreatedYouTurn(); } + else if (yt.isYouTurnBtnOn) + btnAutoYouTurn.PerformClick(); } private void BuildMachineByte() @@ -823,7 +808,7 @@ public int SaveOrNot(bool closing) using (FormSaveOrNot form = new FormSaveOrNot(closing)) { - DialogResult result = form.ShowDialog(); + DialogResult result = form.ShowDialog(this); if (result == DialogResult.OK) return 0; //Save and Exit if (result == DialogResult.Ignore) return 1; //Ignore diff --git a/SourceCode/GPS/Forms/FormJob.cs b/SourceCode/GPS/Forms/FormJob.cs index e463beec3..2b91a6340 100644 --- a/SourceCode/GPS/Forms/FormJob.cs +++ b/SourceCode/GPS/Forms/FormJob.cs @@ -74,7 +74,7 @@ private void btnJobTouch_Click(object sender, EventArgs e) using (FormTouchPick form = new FormTouchPick(mf)) { //returns full field.txt file dir name - if (form.ShowDialog() == DialogResult.Yes) + if (form.ShowDialog(this) == DialogResult.Yes) { mf.FileOpenField(mf.filePickerFileAndDirectory); Close(); diff --git a/SourceCode/GPS/Forms/GUI.Designer.cs b/SourceCode/GPS/Forms/GUI.Designer.cs index 05b2ecc47..53bb45e30 100644 --- a/SourceCode/GPS/Forms/GUI.Designer.cs +++ b/SourceCode/GPS/Forms/GUI.Designer.cs @@ -532,9 +532,6 @@ public void LoadSettings() ahrs = new CAHRS(); - //update the field data areas - fd.UpdateFieldBoundaryGUIAreas(); - //Set width of section and positions for each section SectionSetPosition(); diff --git a/SourceCode/GPS/Forms/Guidance/FormABLine.cs b/SourceCode/GPS/Forms/Guidance/FormABLine.cs index 0b40754d9..fa7aa78a7 100644 --- a/SourceCode/GPS/Forms/Guidance/FormABLine.cs +++ b/SourceCode/GPS/Forms/Guidance/FormABLine.cs @@ -442,11 +442,9 @@ private void btnAddTimeEdit_Click(object sender, EventArgs e) private void btnManual_Click(object sender, EventArgs e) { - var result = DialogResult.Cancel; using (var form = new FormEnterAB(mf)) { - result = form.ShowDialog(); - if (result == DialogResult.OK) + if (form.ShowDialog(this) == DialogResult.OK) { panelAPlus.Visible = false; panelName.Visible = true; diff --git a/SourceCode/GPS/Forms/Guidance/FormEditAB.cs b/SourceCode/GPS/Forms/Guidance/FormEditAB.cs index 7cba5cc08..999092edd 100644 --- a/SourceCode/GPS/Forms/Guidance/FormEditAB.cs +++ b/SourceCode/GPS/Forms/Guidance/FormEditAB.cs @@ -46,8 +46,7 @@ private void tboxHeading_Enter(object sender, EventArgs e) using (FormNumeric form = new FormNumeric(0, 360, Math.Round(glm.toDegrees(mf.ABLine.abHeading), 5))) { - DialogResult result = form.ShowDialog(); - if (result == DialogResult.OK) + if (form.ShowDialog(this) == DialogResult.OK) { tboxHeading.Text = ((double)form.ReturnValue).ToString(); mf.ABLine.abHeading = glm.toRadians((double)form.ReturnValue); diff --git a/SourceCode/GPS/Forms/OpenGL.Designer.cs b/SourceCode/GPS/Forms/OpenGL.Designer.cs index 945fa1975..b3bedef83 100644 --- a/SourceCode/GPS/Forms/OpenGL.Designer.cs +++ b/SourceCode/GPS/Forms/OpenGL.Designer.cs @@ -340,19 +340,23 @@ private void oglMain_Paint(object sender, PaintEventArgs e) //draw Boundaries bnd.DrawFenceLines(); + GL.LineWidth(ABLine.lineWidth); //draw the turnLines if (yt.isYouTurnBtnOn && !ct.isContourBtnOn) { - bnd.DrawTurnLines(); + GL.Color3(0.3555f, 0.6232f, 0.20f); + for (int i = 0; i < bnd.bndList.Count; i++) + { + bnd.bndList[i].turnLine.DrawPolygon(); + } } if (bnd.isHeadlandOn) { - GL.LineWidth(ABLine.lineWidth); GL.Color3(0.960f, 0.96232f, 0.30f); for (int i = 0; i < bnd.bndList.Count; i++) { - if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLine(); + bnd.bndList[i].hdLine.DrawPolygon(); } } @@ -624,9 +628,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) { GL.LineWidth(3); GL.Color3((byte)0, (byte)240, (byte)0); - GL.Begin(PrimitiveType.LineStrip); - for (int h = 0; h < ptCount; h++) GL.Vertex3(bnd.bndList[0].fenceLine[h].easting, bnd.bndList[0].fenceLine[h].northing, 0); - GL.End(); + bnd.bndList[0].fenceLine.DrawPolygon(); } } @@ -638,7 +640,7 @@ private void oglBack_Paint(object sender, PaintEventArgs e) for (int i = 0; i < bnd.bndList.Count; i++) { - if (bnd.bndList[i].hdLine.Count > 0) bnd.bndList[i].DrawHeadLineBackBuffer(); + bnd.bndList[i].hdLine.DrawPolygon(); } } diff --git a/SourceCode/GPS/Forms/Position.designer.cs b/SourceCode/GPS/Forms/Position.designer.cs index fef8e4128..47f67a493 100644 --- a/SourceCode/GPS/Forms/Position.designer.cs +++ b/SourceCode/GPS/Forms/Position.designer.cs @@ -710,7 +710,7 @@ public void UpdateFixPosition() if (bnd.bndList.Count > 0) { //Are we inside outer and outside inner all turn boundaries, no turn creation problems - if (bnd.IsInsideAllFences(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) + if (bnd.IsPointInsideFenceArea(pivotAxlePos) && !yt.isTurnCreationTooClose && !yt.isTurnCreationNotCrossingError) { //reset critical stop for bounds violation mc.isOutOfBounds = false; @@ -1124,8 +1124,8 @@ private void AddSectionOrContourPathPoints() public void CalculateSectionLookAhead(double northing, double easting, double cosHeading, double sinHeading) { //calculate left side of section 1 - vec3 left = new vec3(); - vec3 right = left; + vec2 left = new vec2(); + vec2 right = left; double leftSpeed = 0, rightSpeed = 0; //speed max for section kmh*0.277 to m/s * 10 cm per pixel * 1.7 max speed @@ -1137,8 +1137,8 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (j == 0) { //only one first left point, the rest are all rights moved over to left - section[j].leftPoint = new vec3(cosHeading * (section[j].positionLeft) + easting, - sinHeading * (section[j].positionLeft) + northing,0); + section[j].leftPoint = new vec2(cosHeading * (section[j].positionLeft) + easting, + sinHeading * (section[j].positionLeft) + northing); left = section[j].leftPoint - section[j].lastLeftPoint; @@ -1163,8 +1163,8 @@ public void CalculateSectionLookAhead(double northing, double easting, double co if (leftSpeed > rightSpeed) leftSpeed = rightSpeed; } - section[j].rightPoint = new vec3(cosHeading * (section[j].positionRight) + easting, - sinHeading * (section[j].positionRight) + northing,0); + section[j].rightPoint = new vec2(cosHeading * (section[j].positionRight) + easting, + sinHeading * (section[j].positionRight) + northing); //now we have left and right for this section right = section[j].rightPoint - section[j].lastRightPoint; @@ -1250,44 +1250,17 @@ public void CalculateSectionLookAhead(double northing, double easting, double co { if (bnd.bndList.Count > 0) { - if (j == 0) - { - //only one first left point, the rest are all rights moved over to left - isLeftIn = glm.IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[0].fenceLineEar); - isRightIn = glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); - - for (int i = 1; i < bnd.bndList.Count; i++) - { - //inner boundaries should normally NOT have point inside - isLeftIn &= !glm.IsPointInPolygon(section[j].leftPoint, ref bnd.bndList[i].fenceLineEar); - isRightIn &= !glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); - } + //only one first left point, the rest are all rights moved over to left + isLeftIn = j == 0 ? bnd.IsPointInsideFenceArea(section[j].leftPoint) : isRightIn; + isRightIn = bnd.IsPointInsideFenceArea(section[j].rightPoint); - //merge the two sides into in or out - if (isLeftIn && isRightIn) section[j].isInBoundary = true; - else section[j].isInBoundary = false; - } + //merge the two sides into in or out + if (isLeftIn && isRightIn) section[j].isInBoundary = true; + else section[j].isInBoundary = false; - else - { - //grab the right of previous section, its the left of this section - isLeftIn = isRightIn; - isRightIn = glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[0].fenceLineEar); - for (int i = 1; i < bnd.bndList.Count; i++) - { - //inner boundaries should normally NOT have point inside - isRightIn &= !glm.IsPointInPolygon(section[j].rightPoint, ref bnd.bndList[i].fenceLineEar); - } - - if (isLeftIn && isRightIn) section[j].isInBoundary = true; - else section[j].isInBoundary = false; - } section[tool.numOfSections].isInBoundary &= section[j].isInBoundary; - } - - //no boundary created so always inside - else + else//no boundary created so always inside { section[j].isInBoundary = true; section[tool.numOfSections].isInBoundary = false; diff --git a/SourceCode/GPS/Forms/SaveOpen.Designer.cs b/SourceCode/GPS/Forms/SaveOpen.Designer.cs index f04c1bc4d..51ebb41e9 100644 --- a/SourceCode/GPS/Forms/SaveOpen.Designer.cs +++ b/SourceCode/GPS/Forms/SaveOpen.Designer.cs @@ -318,7 +318,7 @@ public void FileOpenField(string _openType) ofd.Filter = "Field files (Field.txt)|Field.txt"; //was a file selected - if (ofd.ShowDialog() == DialogResult.Cancel) fileAndDirectory = "Cancel"; + if (ofd.ShowDialog(this) == DialogResult.Cancel) fileAndDirectory = "Cancel"; else fileAndDirectory = ofd.FileName; break; } @@ -698,7 +698,6 @@ public void FileOpenField(string _openType) //Check for latest boundary files, then above line string is num of points if (line == "True" || line == "False") { - New.isDriveAround = bool.Parse(line); line = reader.ReadLine(); //number of points } @@ -1212,8 +1211,7 @@ public void FileSaveBoundary() for (int i = 0; i < bnd.bndList.Count; i++) { writer.WriteLine(bnd.bndList[i].isDriveThru); - writer.WriteLine(bnd.bndList[i].isDriveAround); - //writer.WriteLine(bnd.bndArr[i].isOwnField); + //writer.WriteLine(bnd.bndList[i].isDriveAround); writer.WriteLine(bnd.bndList[i].fenceLine.Count.ToString(CultureInfo.InvariantCulture)); if (bnd.bndList[i].fenceLine.Count > 0) diff --git a/SourceCode/GPS/Forms/Settings/FormSteer.cs b/SourceCode/GPS/Forms/Settings/FormSteer.cs index 8e383088b..b65496e92 100644 --- a/SourceCode/GPS/Forms/Settings/FormSteer.cs +++ b/SourceCode/GPS/Forms/Settings/FormSteer.cs @@ -381,7 +381,7 @@ private void hsbarIntegralPurePursuit_ValueChanged(object sender, EventArgs e) private void hsbarSideHillComp_ValueChanged(object sender, EventArgs e) { - double deg = (double)hsbarSideHillComp.Value; + double deg = hsbarSideHillComp.Value; deg *= 0.01; lblSideHillComp.Text = (deg.ToString("N2") + "\u00B0"); Properties.Settings.Default.setAS_sideHillComp = deg; From 2dd8f9b468345a327daaed574504d965ee103414 Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Wed, 27 Oct 2021 08:03:49 -0600 Subject: [PATCH 17/18] Remove Enter AB from file menu --- SourceCode/GPS/Forms/FormGPS.Designer.cs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/SourceCode/GPS/Forms/FormGPS.Designer.cs b/SourceCode/GPS/Forms/FormGPS.Designer.cs index 320e3b904..7d073e0b3 100644 --- a/SourceCode/GPS/Forms/FormGPS.Designer.cs +++ b/SourceCode/GPS/Forms/FormGPS.Designer.cs @@ -64,7 +64,6 @@ private void InitializeComponent() this.resetEverythingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.enterABToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tmrWatchdog = new System.Windows.Forms.Timer(this.components); this.contextMenuStripFlag = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripMenuItemFlagRed = new System.Windows.Forms.ToolStripMenuItem(); @@ -235,7 +234,6 @@ private void InitializeComponent() this.toolStripSeparator10, this.colorsToolStripMenuItem1, this.sectionColorToolStripMenuItem, - this.enterABToolStripMenuItem, this.toolStripSeparator8, this.topFieldViewToolStripMenuItem, this.toolStripSeparator3, @@ -463,12 +461,6 @@ private void InitializeComponent() this.helpMenuItem.Text = "Help"; this.helpMenuItem.Click += new System.EventHandler(this.helpMenuItem_Click); // - // enterABToolStripMenuItem - // - this.enterABToolStripMenuItem.Name = "enterABToolStripMenuItem"; - this.enterABToolStripMenuItem.Size = new System.Drawing.Size(319, 40); - this.enterABToolStripMenuItem.Text = "Enter AB"; - // // tmrWatchdog // this.tmrWatchdog.Interval = 250; @@ -669,7 +661,7 @@ private void InitializeComponent() this.btnResetSim.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnResetSim.Font = new System.Drawing.Font("Tahoma", 9.75F); this.btnResetSim.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.btnResetSim.Location = new System.Drawing.Point(508, 4); + this.btnResetSim.Location = new System.Drawing.Point(506, 4); this.btnResetSim.Name = "btnResetSim"; this.btnResetSim.Size = new System.Drawing.Size(50, 31); this.btnResetSim.TabIndex = 164; @@ -684,7 +676,7 @@ private void InitializeComponent() this.btnResetSteerAngle.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnResetSteerAngle.Font = new System.Drawing.Font("Tahoma", 9.75F); this.btnResetSteerAngle.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.btnResetSteerAngle.Location = new System.Drawing.Point(456, 4); + this.btnResetSteerAngle.Location = new System.Drawing.Point(454, 4); this.btnResetSteerAngle.Name = "btnResetSteerAngle"; this.btnResetSteerAngle.Size = new System.Drawing.Size(44, 31); this.btnResetSteerAngle.TabIndex = 162; @@ -709,10 +701,10 @@ private void InitializeComponent() this.hsbarSteerAngle.Dock = System.Windows.Forms.DockStyle.Fill; this.hsbarSteerAngle.ImeMode = System.Windows.Forms.ImeMode.NoControl; this.hsbarSteerAngle.LargeChange = 20; - this.hsbarSteerAngle.Location = new System.Drawing.Point(260, 1); + this.hsbarSteerAngle.Location = new System.Drawing.Point(259, 1); this.hsbarSteerAngle.Maximum = 800; this.hsbarSteerAngle.Name = "hsbarSteerAngle"; - this.hsbarSteerAngle.Size = new System.Drawing.Size(192, 37); + this.hsbarSteerAngle.Size = new System.Drawing.Size(191, 37); this.hsbarSteerAngle.TabIndex = 179; this.hsbarSteerAngle.Value = 400; this.hsbarSteerAngle.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsbarSteerAngle_Scroll); @@ -725,7 +717,7 @@ private void InitializeComponent() this.hsbarStepDistance.Location = new System.Drawing.Point(1, 1); this.hsbarStepDistance.Minimum = -25; this.hsbarStepDistance.Name = "hsbarStepDistance"; - this.hsbarStepDistance.Size = new System.Drawing.Size(192, 37); + this.hsbarStepDistance.Size = new System.Drawing.Size(191, 37); this.hsbarStepDistance.TabIndex = 178; this.hsbarStepDistance.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsbarStepDistance_Scroll); // @@ -1417,7 +1409,7 @@ private void InitializeComponent() this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 65F)); this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 51F)); - this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 92F)); + this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 94F)); this.panelSim.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.panelSim.Controls.Add(this.btnResetSteerAngle, 3, 0); this.panelSim.Controls.Add(this.hsbarSteerAngle, 2, 0); @@ -1441,7 +1433,7 @@ private void InitializeComponent() this.btnSimSetSpeedToZero.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnSimSetSpeedToZero.Font = new System.Drawing.Font("Tahoma", 9.75F); this.btnSimSetSpeedToZero.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.btnSimSetSpeedToZero.Location = new System.Drawing.Point(197, 4); + this.btnSimSetSpeedToZero.Location = new System.Drawing.Point(196, 4); this.btnSimSetSpeedToZero.Name = "btnSimSetSpeedToZero"; this.btnSimSetSpeedToZero.Size = new System.Drawing.Size(59, 31); this.btnSimSetSpeedToZero.TabIndex = 453; @@ -2391,7 +2383,6 @@ private void InitializeComponent() private System.Windows.Forms.Label label1; private System.Windows.Forms.ToolStripMenuItem toolStripBtnMakeBndContour; private System.Windows.Forms.ToolStripMenuItem sectionColorToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem enterABToolStripMenuItem; private System.Windows.Forms.Button btnEditAB; } } From 076d1f82103b35b6cce659295fb0ba7ee97dd56d Mon Sep 17 00:00:00 2001 From: Brian Tischler Date: Wed, 27 Oct 2021 15:40:36 -0600 Subject: [PATCH 18/18] Fix About Form address --- SourceCode/GPS/Forms/Form_About.Designer.cs | 4 ++-- SourceCode/GPS/Forms/Form_About.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SourceCode/GPS/Forms/Form_About.Designer.cs b/SourceCode/GPS/Forms/Form_About.Designer.cs index b64279128..33b8efa0e 100644 --- a/SourceCode/GPS/Forms/Form_About.Designer.cs +++ b/SourceCode/GPS/Forms/Form_About.Designer.cs @@ -116,10 +116,10 @@ private void InitializeComponent() this.linkLabelCombineForum.Font = new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabelCombineForum.Location = new System.Drawing.Point(12, 609); this.linkLabelCombineForum.Name = "linkLabelCombineForum"; - this.linkLabelCombineForum.Size = new System.Drawing.Size(258, 19); + this.linkLabelCombineForum.Size = new System.Drawing.Size(251, 19); this.linkLabelCombineForum.TabIndex = 12; this.linkLabelCombineForum.TabStop = true; - this.linkLabelCombineForum.Text = "https://agopengps.discourse.forum"; + this.linkLabelCombineForum.Text = "https://discourse.agopengps.com/"; this.linkLabelCombineForum.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabelCombineForum_LinkClicked); // // button1 diff --git a/SourceCode/GPS/Forms/Form_About.cs b/SourceCode/GPS/Forms/Form_About.cs index 352e0e2f8..5b41b090b 100644 --- a/SourceCode/GPS/Forms/Form_About.cs +++ b/SourceCode/GPS/Forms/Form_About.cs @@ -32,7 +32,7 @@ private void Form_About_Load(object sender, EventArgs e) // Add a link to the LinkLabel. LinkLabel.Link linkCf = new LinkLabel.Link { - LinkData = "https://agopengps.discourse.forum" + LinkData = "https://discourse.agopengps.com/" }; linkLabelCombineForum.Links.Add(linkCf); }