private void btnEnter_APlus_Click(object sender, EventArgs e) { panelAPlus.Visible = false; panelName.Visible = true; mf.ABLine.desName = "AB " + (Math.Round(glm.toDegrees(mf.ABLine.desHeading), 1)).ToString(CultureInfo.InvariantCulture) + "\u00B0 " + mf.FindDirection(mf.ABLine.desHeading); textBox1.Text = mf.ABLine.desName; }
//private void btnPlus90_Click(object sender, EventArgs e) //{ // mf.ABLine.moveDistance = 0; // upDnHeading += 90; // if (upDnHeading > 359.999999) upDnHeading -= 360; // mf.ABLine.abHeading = glm.toRadians(upDnHeading); // mf.ABLine.SetABLineByHeading(); // tboxHeading.Text = Convert.ToString(upDnHeading, CultureInfo.InvariantCulture); //} private void BtnNewABLine_Click(object sender, EventArgs e) { //is button for adding ABLine set if (btnNewABLine.Text == "+") { btnNewABLine.Text = ""; btnNewABLine.Image = Properties.Resources.AddNew; ShowFullPanel(true); tboxABLineName.BackColor = Color.LightGreen; //create a name tboxABLineName.Enabled = true; tboxHeading.Enabled = false; btnAddToFile.Enabled = true; btnAddAndGo.Enabled = true; btnAPoint.Enabled = false; btnBPoint.Enabled = false; btnUpABHeadingBy1.Enabled = false; btnDnABHeadingBy1.Enabled = false; btnNewABLine.Enabled = false; btnTurnOffAB.Enabled = false; btnNewABLine.Enabled = false; lvLines.Enabled = false; btnAddToFile.Focus(); tboxABLineName.Text = (Math.Round(glm.toDegrees(mf.ABLine.abHeading), 1)).ToString(CultureInfo.InvariantCulture) + "\u00B0" + mf.FindDirection(mf.ABLine.abHeading) + DateTime.Now.ToString("hh:mm:ss", CultureInfo.InvariantCulture); } else // or used to initiate a new line { this.tboxHeading.TextChanged -= new System.EventHandler(this.tboxHeading_TextChanged); tboxHeading.Text = ""; this.tboxHeading.TextChanged += new System.EventHandler(this.tboxHeading_TextChanged); tboxHeading.Enabled = false; mf.ABLine.DeleteAB(); lvLines.SelectedItems.Clear(); btnAPoint.Enabled = true; btnBPoint.Enabled = false; btnUpABHeadingBy1.Enabled = false; btnDnABHeadingBy1.Enabled = false; btnNewABLine.Enabled = false; btnTurnOffAB.Enabled = false; nudTramRepeats.Value = 0; nudBasedOnPass.Value = 0; mf.ABLine.tramPassEvery = 0; mf.ABLine.tramBasedOn = 0; mf.ABLine.isABLineSet = false; mf.ABLine.isABLineLoaded = false; ShowFullPanel(false); } }
public void CalcHeading() { double east, nort; if (isAB) { mf.pn.ConvertWGS84ToLocal((double)nudLatitude.Value, (double)nudLongitude.Value, out nort, out east); mf.ABLine.desPoint1.easting = east; mf.ABLine.desPoint1.northing = nort; mf.pn.ConvertWGS84ToLocal((double)nudLatitudeB.Value, (double)nudLongitudeB.Value, out nort, out east); mf.ABLine.desPoint2.easting = east; mf.ABLine.desPoint2.northing = nort; // heading based on AB points mf.ABLine.desHeading = Math.Atan2(mf.ABLine.desPoint2.easting - mf.ABLine.desPoint1.easting, mf.ABLine.desPoint2.northing - mf.ABLine.desPoint1.northing); if (mf.ABLine.desHeading < 0) { mf.ABLine.desHeading += glm.twoPI; } nudHeading.Value = (decimal)(glm.toDegrees(mf.ABLine.desHeading)); } else { mf.pn.ConvertWGS84ToLocal((double)nudLatitude.Value, (double)nudLongitude.Value, out nort, out east); mf.ABLine.desHeading = glm.toRadians((double)nudHeading.Value); mf.ABLine.desPoint1.easting = east; mf.ABLine.desPoint1.northing = nort; } textBox1.Text = "Manual AB " + (Math.Round(glm.toDegrees(mf.ABLine.desHeading), 1)).ToString(CultureInfo.InvariantCulture) + "\u00B0 " + mf.FindDirection(mf.ABLine.desHeading); if (textBox1.Text != "Create A New Line") { btnEnterManual.Enabled = true; } }
private void btnBPoint_Click(object sender, System.EventArgs e) { mf.curve.aveLineHeading = 0; mf.curve.isOkToAddPoints = false; btnBPoint.Enabled = false; btnAPoint.Enabled = false; btnPausePlay.Enabled = false; btnCancel.Enabled = false; lvLines.Enabled = false; int cnt = mf.curve.refList.Count; if (cnt > 3) { //make sure distance isn't too big between points on Turn for (int i = 0; i < cnt - 1; i++) { int j = i + 1; //if (j == cnt) j = 0; double distance = glm.Distance(mf.curve.refList[i], mf.curve.refList[j]); if (distance > 1.2) { vec3 pointB = new vec3((mf.curve.refList[i].easting + mf.curve.refList[j].easting) / 2.0, (mf.curve.refList[i].northing + mf.curve.refList[j].northing) / 2.0, mf.curve.refList[i].heading); mf.curve.refList.Insert(j, pointB); cnt = mf.curve.refList.Count; i = -1; } } //calculate average heading of line double x = 0, y = 0; mf.curve.isCurveSet = true; foreach (var pt in mf.curve.refList) { x += Math.Cos(pt.heading); y += Math.Sin(pt.heading); } x /= mf.curve.refList.Count; y /= mf.curve.refList.Count; mf.curve.aveLineHeading = Math.Atan2(y, x); if (mf.curve.aveLineHeading < 0) { mf.curve.aveLineHeading += glm.twoPI; } //build the tail extensions mf.curve.AddFirstLastPoints(); SmoothAB(4); mf.curve.CalculateTurnHeadings(); mf.curve.isCurveSet = true; mf.EnableYouTurnButtons(); //mf.FileSaveCurveLine(); lblCurveExists.Text = gStr.gsCurveSet; ShowSavedPanel(true); btnAddAndGo.Enabled = true; btnAddToFile.Enabled = true; btnAPoint.Enabled = false; btnBPoint.Enabled = false; btnPausePlay.Enabled = false; textBox1.BackColor = Color.LightGreen; textBox1.Enabled = true; textBox1.Text = (Math.Round(glm.toDegrees(mf.curve.aveLineHeading), 1)).ToString(CultureInfo.InvariantCulture) + "\u00B0" + mf.FindDirection(mf.curve.aveLineHeading) + DateTime.Now.ToString("hh:mm:ss", CultureInfo.InvariantCulture); } else { mf.curve.isCurveSet = false; mf.curve.refList?.Clear(); lblCurveExists.Text = " > Off <"; ShowSavedPanel(true); btnNewCurve.Enabled = true; btnCancel.Enabled = true; lvLines.Enabled = true; } lvLines.SelectedItems.Clear(); }
private void btnBPoint_Click(object sender, System.EventArgs e) { aveLineHeading = 0; mf.curve.isOkToAddDesPoints = false; panelAPlus.Visible = false; panelName.Visible = true; int cnt = mf.curve.desList.Count; if (cnt > 3) { //make sure distance isn't too big between points on Turn for (int i = 0; i < cnt - 1; i++) { int j = i + 1; //if (j == cnt) j = 0; double distance = glm.Distance(mf.curve.desList[i], mf.curve.desList[j]); if (distance > 1.2) { vec3 pointB = new vec3((mf.curve.desList[i].easting + mf.curve.desList[j].easting) / 2.0, (mf.curve.desList[i].northing + mf.curve.desList[j].northing) / 2.0, mf.curve.desList[i].heading); mf.curve.desList.Insert(j, pointB); cnt = mf.curve.desList.Count; i = -1; } } //calculate average heading of line double x = 0, y = 0; foreach (vec3 pt in mf.curve.desList) { x += Math.Cos(pt.heading); y += Math.Sin(pt.heading); } x /= mf.curve.desList.Count; y /= mf.curve.desList.Count; aveLineHeading = Math.Atan2(y, x); if (aveLineHeading < 0) { aveLineHeading += glm.twoPI; } //build the tail extensions AddFirstLastPoints(); SmoothAB(4); CalculateTurnHeadings(); panelAPlus.Visible = false; panelName.Visible = true; mf.curve.desName = "Cu " + (Math.Round(glm.toDegrees(aveLineHeading), 1)).ToString(CultureInfo.InvariantCulture) + "\u00B0 " + mf.FindDirection(aveLineHeading); textBox1.Text = mf.curve.desName; } else { mf.curve.isOkToAddDesPoints = false; mf.curve.desList?.Clear(); panelPick.Visible = true; panelAPlus.Visible = false; panelName.Visible = false; this.Size = new System.Drawing.Size(470, 360); UpdateLineList(); } }
private void BtnMakeCurve_Click(object sender, EventArgs e) { btnCancelTouch.Enabled = false; mf.curve.refList?.Clear(); vec3 chk = new vec3(arr[start]); for (int i = start; i < end; i++) { mf.curve.refList.Add(arr[i]); } int cnt = mf.curve.refList.Count; if (cnt > 3) { //make sure distance isn't too big between points on Turn for (int i = 0; i < cnt - 1; i++) { int j = i + 1; //if (j == cnt) j = 0; double distance = glm.Distance(mf.curve.refList[i], mf.curve.refList[j]); if (distance > 1.2) { vec3 pointB = new vec3((mf.curve.refList[i].easting + mf.curve.refList[j].easting) / 2.0, (mf.curve.refList[i].northing + mf.curve.refList[j].northing) / 2.0, mf.curve.refList[i].heading); mf.curve.refList.Insert(j, pointB); cnt = mf.curve.refList.Count; i = -1; } } //who knows which way it actually goes mf.curve.CalculateTurnHeadings(); //calculate average heading of line double x = 0, y = 0; mf.curve.isCurveSet = true; foreach (var pt in mf.curve.refList) { x += Math.Cos(pt.heading); y += Math.Sin(pt.heading); } x /= mf.curve.refList.Count; y /= mf.curve.refList.Count; mf.curve.aveLineHeading = Math.Atan2(y, x); if (mf.curve.aveLineHeading < 0) { mf.curve.aveLineHeading += glm.twoPI; } //build the tail extensions mf.curve.AddFirstLastPoints(); mf.curve.SmoothAB(4); mf.curve.CalculateTurnHeadings(); mf.curve.isCurveSet = true; double offset = ((double)nudDistance.Value) / 200.0; //calculate the heading 90 degrees to ref ABLine heading double headingAt90 = mf.curve.aveLineHeading + glm.PIBy2; chk.easting = (Math.Sin(headingAt90) * Math.Abs(offset)) + chk.easting; chk.northing = (Math.Cos(headingAt90) * Math.Abs(offset)) + chk.northing; if (!mf.bnd.bndArr[0].IsPointInsideBoundary(chk)) { headingAt90 = mf.curve.aveLineHeading - glm.PIBy2; } cnt = mf.curve.refList.Count; vec3[] arrMove = new vec3[cnt]; mf.curve.refList.CopyTo(arrMove); mf.curve.refList.Clear(); for (int i = 0; i < cnt; i++) { arrMove[i].easting = (Math.Sin(headingAt90) * offset) + arrMove[i].easting; arrMove[i].northing = (Math.Cos(headingAt90) * offset) + arrMove[i].northing; mf.curve.refList.Add(arrMove[i]); } mf.curve.curveArr.Add(new CCurveLines()); mf.curve.numCurveLines = mf.curve.curveArr.Count; mf.curve.numCurveLineSelected = mf.curve.numCurveLines; //array number is 1 less since it starts at zero int idx = mf.curve.curveArr.Count - 1; //create a name mf.curve.curveArr[idx].Name = (Math.Round(glm.toDegrees(mf.curve.aveLineHeading), 1)).ToString(CultureInfo.InvariantCulture) + "\u00B0" + mf.FindDirection(mf.curve.aveLineHeading) + DateTime.Now.ToString("hh:mm:ss", CultureInfo.InvariantCulture); mf.curve.curveArr[idx].aveHeading = mf.curve.aveLineHeading; //write out the Curve Points foreach (var item in mf.curve.refList) { mf.curve.curveArr[idx].curvePts.Add(item); } mf.FileSaveCurveLines(); //update the arrays btnMakeABLine.Enabled = false; btnMakeCurve.Enabled = false; isMakingCurve = false; isMakingAB = false; start = 99999; end = 99999; FixLabelsCurve(); } else { mf.curve.isCurveSet = false; mf.curve.refList?.Clear(); } }
private void BtnMakeCurve_Click(object sender, EventArgs e) { btnCancelTouch.Enabled = false; double moveDist = (double)nudDistance.Value * mf.inchOrCm2m; double distSq = (moveDist) * (moveDist) * 0.999; mf.curve.refList?.Clear(); vec3 pt3 = new vec3(arr[start]); for (int i = start; i < end; i++) { //calculate the point inside the boundary pt3.easting = arr[i].easting - (Math.Sin(glm.PIBy2 + arr[i].heading) * (moveDist)); pt3.northing = arr[i].northing - (Math.Cos(glm.PIBy2 + arr[i].heading) * (moveDist)); pt3.heading = arr[i].heading; bool Add = true; for (int j = start; j < end; j++) { double check = glm.DistanceSquared(pt3.northing, pt3.easting, arr[j].northing, arr[j].easting); if (check < distSq) { Add = false; break; } } if (Add) { if (mf.curve.refList.Count > 0) { double dist = ((pt3.easting - mf.curve.refList[mf.curve.refList.Count - 1].easting) * (pt3.easting - mf.curve.refList[mf.curve.refList.Count - 1].easting)) + ((pt3.northing - mf.curve.refList[mf.curve.refList.Count - 1].northing) * (pt3.northing - mf.curve.refList[mf.curve.refList.Count - 1].northing)); if (dist > 1) { mf.curve.refList.Add(pt3); } } else { mf.curve.refList.Add(pt3); } } } int cnt = mf.curve.refList.Count; if (cnt > 3) { //make sure distance isn't too big between points on Turn for (int i = 0; i < cnt - 1; i++) { int j = i + 1; //if (j == cnt) j = 0; double distance = glm.Distance(mf.curve.refList[i], mf.curve.refList[j]); if (distance > 1.6) { vec3 pointB = new vec3((mf.curve.refList[i].easting + mf.curve.refList[j].easting) / 2.0, (mf.curve.refList[i].northing + mf.curve.refList[j].northing) / 2.0, mf.curve.refList[i].heading); mf.curve.refList.Insert(j, pointB); cnt = mf.curve.refList.Count; i = -1; } } //who knows which way it actually goes mf.curve.CalculateTurnHeadings(); //calculate average heading of line double x = 0, y = 0; mf.curve.isCurveSet = true; foreach (vec3 pt in mf.curve.refList) { x += Math.Cos(pt.heading); y += Math.Sin(pt.heading); } x /= mf.curve.refList.Count; y /= mf.curve.refList.Count; mf.curve.aveLineHeading = Math.Atan2(y, x); if (mf.curve.aveLineHeading < 0) { mf.curve.aveLineHeading += glm.twoPI; } //build the tail extensions mf.curve.AddFirstLastPoints(); mf.curve.SmoothAB(4); mf.curve.CalculateTurnHeadings(); mf.curve.isCurveSet = true; mf.curve.curveArr.Add(new CCurveLines()); mf.curve.numCurveLines = mf.curve.curveArr.Count; mf.curve.numCurveLineSelected = mf.curve.numCurveLines; //array number is 1 less since it starts at zero int idx = mf.curve.curveArr.Count - 1; //create a name mf.curve.curveArr[idx].Name = (Math.Round(glm.toDegrees(mf.curve.aveLineHeading), 1)).ToString(CultureInfo.InvariantCulture) + "\u00B0" + mf.FindDirection(mf.curve.aveLineHeading) + DateTime.Now.ToString("hh:mm:ss", CultureInfo.InvariantCulture); mf.curve.curveArr[idx].aveHeading = mf.curve.aveLineHeading; //write out the Curve Points foreach (vec3 item in mf.curve.refList) { mf.curve.curveArr[idx].curvePts.Add(item); } mf.FileSaveCurveLines(); //update the arrays btnMakeABLine.Enabled = false; btnMakeCurve.Enabled = false; isMakingCurve = false; isMakingAB = false; start = 99999; end = 99999; FixLabelsCurve(); } else { mf.curve.isCurveSet = false; mf.curve.refList?.Clear(); } btnExit.Focus(); }