private void btnAddToFile_Click(object sender, EventArgs e) { if (mf.curve.refList.Count > 0) { if (textBox1.Text.Length > 0) { mf.curve.curveArr.Add(new CCurveLines()); mf.curve.numCurveLines = mf.curve.curveArr.Count; if (mf.curve.numCurveLineSelected > mf.curve.numCurveLines) { mf.curve.numCurveLineSelected = mf.curve.numCurveLines; } //array number is 1 less since it starts at zero int cnt = mf.curve.curveArr.Count - 1; mf.curve.curveArr[cnt].Name = textBox1.Text.Trim(); mf.curve.curveArr[cnt].aveHeading = mf.curve.aveLineHeading; //write out the Curve Points foreach (var item in mf.curve.refList) { mf.curve.curveArr[cnt].curvePts.Add(item); } //update the listbox with new curve name ListViewItem itm = new ListViewItem(mf.curve.curveArr[cnt].Name); lvLines.Items.Add(itm); lvLines.Enabled = true; textBox1.BackColor = SystemColors.ControlLight; textBox1.Text = ""; textBox1.Enabled = false; btnAddAndGo.Enabled = false; btnAddToFile.Enabled = false; btnAPoint.Enabled = false; btnCancel.Enabled = true; btnNewCurve.Enabled = true; lvLines.SelectedItems.Clear(); btnNewCurve.Enabled = true; mf.FileSaveCurveLines(); } } else { var form2 = new FormTimedMessage(2000, gStr.gsNoABCurveCreated, gStr.gsCompleteAnABCurveLineFirst); form2.Show(); textBox1.BackColor = SystemColors.Window; } }
private void bntOk_Click(object sender, EventArgs e) { mf.curve.isEditing = false; if (mf.curve.refList.Count > 0) { //array number is 1 less since it starts at zero int idx = mf.curve.numCurveLineSelected - 1; if (idx >= 0) { mf.curve.curveArr[idx].aveHeading = mf.curve.aveLineHeading; mf.curve.curveArr[idx].curvePts.Clear(); //write out the Curve Points foreach (var item in mf.curve.refList) { mf.curve.curveArr[idx].curvePts.Add(item); } } //save entire list mf.FileSaveCurveLines(); mf.curve.moveDistance = 0; mf.layoutPanelRight.Enabled = true; Close(); } }
private void FormTram_FormClosing(object sender, FormClosingEventArgs e) { if (isSaving) { if (isCurve) { if (mf.curve.refList.Count > 0) { //array number is 1 less since it starts at zero int idx = mf.curve.numCurveLineSelected - 1; //mf.curve.curveArr[idx].Name = textBox1.Text.Trim(); if (idx >= 0) { mf.curve.curveArr[idx].aveHeading = mf.curve.aveLineHeading; mf.curve.curveArr[idx].curvePts.Clear(); //write out the Curve Points foreach (vec3 item in mf.curve.refList) { mf.curve.curveArr[idx].curvePts.Add(item); } } //save entire list mf.FileSaveCurveLines(); mf.curve.moveDistance = 0; } } else { int idx = mf.ABLine.numABLineSelected - 1; if (idx >= 0) { mf.ABLine.lineArr[idx].heading = mf.ABLine.abHeading; //calculate the new points for the reference line and points mf.ABLine.lineArr[idx].origin.easting = mf.ABLine.refPoint1.easting; mf.ABLine.lineArr[idx].origin.northing = mf.ABLine.refPoint1.northing; } mf.FileSaveABLines(); mf.ABLine.moveDistance = 0; } } else { mf.tram.tramArr?.Clear(); mf.tram.tramList?.Clear(); mf.tram.tramBndOuterArr?.Clear(); mf.tram.tramBndInnerArr?.Clear(); mf.tram.displayMode = 0; } mf.panelRight.Enabled = true; mf.panelDrag.Visible = false; mf.FileSaveTram(); mf.FixTramModeButton(); }
private void btnSave_Click(object sender, EventArgs e) { //mf.ABLine.moveDistance = 0; mf.panelRight.Enabled = true; mf.panelDrag.Visible = false; mf.offX = 0; mf.offY = 0; if (mf.curve.refList.Count > 0) { //array number is 1 less since it starts at zero int idx = mf.curve.numCurveLineSelected - 1; //mf.curve.curveArr[idx].Name = textBox1.Text.Trim(); if (idx >= 0) { mf.curve.curveArr[idx].aveHeading = mf.curve.aveLineHeading; mf.curve.curveArr[idx].curvePts.Clear(); //write out the Curve Points foreach (vec3 item in mf.curve.refList) { mf.curve.curveArr[idx].curvePts.Add(item); } } //save entire list mf.FileSaveCurveLines(); mf.curve.moveDistance = 0; } mf.FileSaveTram(); mf.FixTramModeButton(); isClosing = true; Close(); }
private void btnSave_Click(object sender, EventArgs e) { mf.curve.isSmoothWindowOpen = false; mf.curve.SaveSmoothAsRefList(); mf.curve.smooList?.Clear(); if (mf.curve.refList.Count > 0) { //array number is 1 less since it starts at zero int idx = mf.curve.numCurveLineSelected - 1; if (idx >= 0) { mf.curve.curveArr[idx].aveHeading = mf.curve.aveLineHeading; mf.curve.curveArr[idx].curvePts.Clear(); //write out the Curve Points foreach (vec3 item in mf.curve.refList) { mf.curve.curveArr[idx].curvePts.Add(item); } } //save entire list mf.FileSaveCurveLines(); mf.curve.moveDistance = 0; //mf.layoutPanelRight.Enabled = true; //Close(); } //mf.FileSaveCurveLines(); Close(); }
private void btnAdd_Click(object sender, EventArgs e) { if (mf.curve.desList.Count > 0) { if (textBox1.Text.Length == 0) { textBox2.Text = "No Name " + DateTime.Now.ToString("hh:mm:ss", CultureInfo.InvariantCulture); } 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; mf.curve.curveArr[idx].Name = textBox1.Text.Trim(); mf.curve.curveArr[idx].aveHeading = aveLineHeading; //write out the Curve Points foreach (var item in mf.curve.desList) { mf.curve.curveArr[idx].curvePts.Add(item); } mf.FileSaveCurveLines(); mf.curve.desList?.Clear(); } panelPick.Visible = true; panelAPlus.Visible = false; textBox1.Enter -= textBox1_Enter; panelName.Visible = false; textBox1.Enter += textBox1_Enter; this.Size = new System.Drawing.Size(470, 360); UpdateLineList(); lvLines.Focus(); mf.curve.desList?.Clear(); }
private void btnSave_Click(object sender, EventArgs e) { //fill something in if (String.IsNullOrEmpty(tboxFieldName.Text.Trim())) { Close(); return; } //append date time to name mf.currentFieldDirectory = tboxFieldName.Text.Trim() + " "; //task if (!String.IsNullOrEmpty(tboxTask.Text.Trim())) { mf.currentFieldDirectory += tboxTask.Text.Trim() + " "; } //vehicle if (!String.IsNullOrEmpty(tboxVehicle.Text.Trim())) { mf.currentFieldDirectory += tboxVehicle.Text.Trim() + " "; } //date mf.currentFieldDirectory += String.Format("{0}", DateTime.Now.ToString("yyyy.MMM.dd HH_mm", CultureInfo.InvariantCulture)); //get the directory and make sure it exists, create if not string dirNewField = mf.fieldsDirectory + mf.currentFieldDirectory + "\\"; mf.menustripLanguage.Enabled = false; // create from template string directoryName = Path.GetDirectoryName(dirNewField); if ((!string.IsNullOrEmpty(directoryName)) && (Directory.Exists(directoryName))) { MessageBox.Show(gStr.gsChooseADifferentName, gStr.gsDirectoryExists, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } else { //create the new directory if ((!string.IsNullOrEmpty(directoryName)) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } } string line; string offsets, convergence, startFix; using (StreamReader reader = new StreamReader(mf.fieldsDirectory + lblTemplateChosen.Text + "\\Field.txt")) { try { line = reader.ReadLine(); line = reader.ReadLine(); line = reader.ReadLine(); line = reader.ReadLine(); //read the Offsets - all we really need from template field file offsets = reader.ReadLine(); line = reader.ReadLine(); convergence = reader.ReadLine(); line = reader.ReadLine(); startFix = reader.ReadLine(); } catch (Exception ex) { mf.WriteErrorLog("While Opening Field" + ex); var form = new FormTimedMessage(2000, gStr.gsFieldFileIsCorrupt, gStr.gsChooseADifferentField); form.Show(); mf.JobClose(); return; } const string myFileName = "Field.txt"; using (StreamWriter writer = new StreamWriter(dirNewField + myFileName)) { //Write out the date writer.WriteLine(DateTime.Now.ToString("yyyy-MMMM-dd hh:mm:ss tt", CultureInfo.InvariantCulture)); writer.WriteLine("$FieldDir"); writer.WriteLine(mf.currentFieldDirectory.ToString(CultureInfo.InvariantCulture)); //write out the easting and northing Offsets writer.WriteLine("$Offsets"); writer.WriteLine(offsets); writer.WriteLine("$Convergence"); writer.WriteLine(convergence); writer.WriteLine("StartFix"); writer.WriteLine(startFix); } //create txt file copies string templateDirectoryName = (mf.fieldsDirectory + lblTemplateChosen.Text); string fileToCopy = ""; string destinationDirectory = ""; if (chkApplied.Checked) { fileToCopy = templateDirectoryName + "\\Contour.txt"; destinationDirectory = directoryName + "\\Contour.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } fileToCopy = templateDirectoryName + "\\Sections.txt"; destinationDirectory = directoryName + "\\Sections.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } } else { //create blank Contour and Section files mf.FileCreateSections(); mf.FileCreateContour(); //mf.FileCreateElevation(); } fileToCopy = templateDirectoryName + "\\Boundary.txt"; destinationDirectory = directoryName + "\\Boundary.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } if (chkFlags.Checked) { fileToCopy = templateDirectoryName + "\\Flags.txt"; destinationDirectory = directoryName + "\\Flags.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } } else { mf.FileSaveFlags(); } if (chkGuidanceLines.Checked) { fileToCopy = templateDirectoryName + "\\ABLines.txt"; destinationDirectory = directoryName + "\\ABLines.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } fileToCopy = templateDirectoryName + "\\RecPath.txt"; destinationDirectory = directoryName + "\\RecPath.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } fileToCopy = templateDirectoryName + "\\CurveLines.txt"; destinationDirectory = directoryName + "\\CurveLines.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } } else { mf.FileSaveABLines(); mf.FileSaveCurveLines(); mf.FileSaveRecPath(); } if (chkHeadland.Checked) { fileToCopy = templateDirectoryName + "\\Headland.txt"; destinationDirectory = directoryName + "\\Headland.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } } else { mf.FileSaveHeadland(); } //fileToCopy = templateDirectoryName + "\\Elevation.txt"; //destinationDirectory = directoryName + "\\Elevation.txt"; //if (File.Exists(fileToCopy)) // File.Copy(fileToCopy, destinationDirectory); //now open the newly cloned field mf.FileOpenField(dirNewField + myFileName); mf.Text = "AgOpenGPS - " + mf.currentFieldDirectory; } DialogResult = DialogResult.OK; Close(); }
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 FormABDraw_FormClosing(object sender, FormClosingEventArgs e) { if (mf.ABLine.numABLineSelected > 0) { mf.ABLine.refPoint1 = mf.ABLine.lineArr[mf.ABLine.numABLineSelected - 1].origin; mf.ABLine.abHeading = mf.ABLine.lineArr[mf.ABLine.numABLineSelected - 1].heading; mf.ABLine.SetABLineByHeading(); if (mf.ABLine.isBtnABLineOn) { mf.ABLine.isABLineSet = true; mf.ABLine.isABLineLoaded = true; } else { mf.ABLine.isABLineSet = false; } } else { mf.ABLine.DeleteAB(); mf.ABLine.isABLineSet = false; mf.ABLine.isABLineLoaded = false; } mf.FileSaveABLines(); //curve if (mf.curve.numCurveLineSelected > 0) { int idx = mf.curve.numCurveLineSelected - 1; mf.curve.aveLineHeading = mf.curve.curveArr[idx].aveHeading; mf.curve.refList?.Clear(); foreach (vec3 v in mf.curve.curveArr[idx].curvePts) { mf.curve.refList.Add(v); } mf.curve.isCurveSet = true; } else { mf.curve.refList?.Clear(); mf.curve.isCurveSet = false; } mf.FileSaveCurveLines(); if (mf.ABLine.isBtnABLineOn) { if (mf.ABLine.numABLineSelected == 0) { if (mf.isAutoSteerBtnOn) { mf.btnAutoSteer.PerformClick(); } if (mf.yt.isYouTurnBtnOn) { mf.btnAutoYouTurn.PerformClick(); } mf.ABLine.isABLineSet = false; mf.ABLine.isABLineLoaded = false; mf.btnABLine.Image = Properties.Resources.ABLineOff; mf.ABLine.isBtnABLineOn = false; } } if (mf.curve.isBtnCurveOn) { if (mf.curve.numCurveLineSelected == 0) { if (mf.isAutoSteerBtnOn) { mf.btnAutoSteer.PerformClick(); } if (mf.yt.isYouTurnBtnOn) { mf.btnAutoYouTurn.PerformClick(); } mf.curve.isCurveSet = false; mf.curve.refList?.Clear(); mf.curve.isBtnCurveOn = false; mf.btnCurve.Image = Properties.Resources.CurveOff; } } }
private void btnMakeBoundaryCurve_Click(object sender, EventArgs e) { //count the points from the boundary int ptCount = mf.bnd.bndList[0].fenceLine.Count; mf.curve.refList?.Clear(); //outside point vec3 pt3 = new vec3(); double moveDist = (double)nudDistance.Value * mf.inchOrCm2m; double distSq = (moveDist) * (moveDist) * 0.999; //make the boundary tram outer array 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.northing = mf.bnd.bndList[0].fenceLine[i].northing - (Math.Cos(glm.PIBy2 + mf.bnd.bndList[0].fenceLine[i].heading) * (moveDist)); 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.bndList[0].fenceLine[j].northing, mf.bnd.bndList[0].fenceLine[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); } } } btnCancelTouch.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; } } //who knows which way it actually goes mf.curve.CalculateTurnHeadings(); mf.curve.isCurveSet = true; mf.curve.aveLineHeading = 0; //mf.curve.SmoothAB(4); //mf.curve.CalculateTurnHeadings(); mf.curve.isCurveSet = true; //double offset = ((double)nudDistance.Value) / 200.0; 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 = "Boundary Curve"; 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(); }