private void btnABLineOk_Click(object sender, EventArgs e) { //save the ABLine mf.FileSaveABLine(); DialogResult = DialogResult.OK; Close(); }
private void btnABLineOk_Click(object sender, EventArgs e) { //save the ABLine mf.FileSaveABLine(); //update the default mf.AB0.fieldName = mf.currentFieldDirectory; mf.AB0.heading = glm.toDegrees(mf.ABLine.abHeading); mf.AB0.X = mf.ABLine.refPoint1.easting; mf.AB0.Y = mf.ABLine.refPoint1.northing; DialogResult = DialogResult.OK; Close(); }
private void BtnMakeABLine_Click(object sender, EventArgs e) { mf.ABLine.refPoint1.easting = arr[A].easting; mf.ABLine.refPoint1.northing = arr[A].northing; mf.ABLine.refPoint2.easting = arr[C].easting; mf.ABLine.refPoint2.northing = arr[C].northing; //calculate the AB Heading mf.ABLine.abHeading = Math.Atan2(mf.ABLine.refPoint2.easting - mf.ABLine.refPoint1.easting, mf.ABLine.refPoint2.northing - mf.ABLine.refPoint1.northing); if (mf.ABLine.abHeading < 0) { mf.ABLine.abHeading += glm.twoPI; } //sin x cos z for endpoints, opposite for additional lines mf.ABLine.refABLineP1.easting = mf.ABLine.refPoint1.easting - (Math.Sin(mf.ABLine.abHeading) * 4000.0); mf.ABLine.refABLineP1.northing = mf.ABLine.refPoint1.northing - (Math.Cos(mf.ABLine.abHeading) * 4000.0); mf.ABLine.refABLineP2.easting = mf.ABLine.refPoint1.easting + (Math.Sin(mf.ABLine.abHeading) * 4000.0); mf.ABLine.refABLineP2.northing = mf.ABLine.refPoint1.northing + (Math.Cos(mf.ABLine.abHeading) * 4000.0); mf.ABLine.isABLineSet = false; mf.ABLine.isABLineLoaded = true; btnMakeABLine.Enabled = false; btnMakeCurve.Enabled = false; tboxABLineSaveName.Enabled = true; tboxCurveSaveName.Enabled = false; mf.FileSaveABLine(); }
private void btnABLineOk_Click(object sender, EventArgs e) { //save the ABLine mf.FileSaveABLine(); //update the default mf.AB0.fieldName = mf.currentFieldDirectory; mf.AB0.heading = glm.toDegrees(mf.ABLine.abHeading); mf.AB0.X = mf.ABLine.refPoint1.easting; mf.AB0.Y = mf.ABLine.refPoint1.northing; if (mf.ABLine.tramPassEvery == 0) { mf.mc.relayRateData[mf.mc.rdTramLine] = 0; } DialogResult = DialogResult.OK; Close(); }
private void BtnNewABLine_Click(object sender, EventArgs e) { this.tboxHeading.TextChanged -= new System.EventHandler(this.tboxHeading_TextChanged); tboxHeading.Text = ""; this.tboxHeading.TextChanged += new System.EventHandler(this.tboxHeading_TextChanged); mf.ABLine.DeleteAB(); btnAPoint.Enabled = true; btnBPoint.Enabled = false; btnABLineOk.Enabled = false; nudTramRepeats.Value = 0; nudBasedOnPass.Value = 0; mf.ABLine.tramPassEvery = 0; mf.ABLine.passBasedOn = 0; //save the no ABLine; mf.FileSaveABLine(); }
private void button1_Click(object sender, EventArgs e) { //fill something in if (String.IsNullOrEmpty(tboxFieldName.Text)) { tboxFieldName.Text = "XX"; } //append date time to name mf.currentFieldDirectory = tboxFieldName.Text.Trim() + String.Format("{0}", DateTime.Now.ToString(" MMMdd", CultureInfo.InvariantCulture)); try { //get the directory and make sure it exists, create if not string dirField = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\AgOpenGPS\\Fields\\" + mf.currentFieldDirectory + "\\"; //make sure directory exists, or create it for first save string directoryName = Path.GetDirectoryName(dirField); if ((!string.IsNullOrEmpty(directoryName)) && (Directory.Exists(directoryName))) { MessageBox.Show("Choose a different name", "Directory Exists", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } else { //reset the offsets mf.pn.utmEast = (int)mf.pn.actualEasting; mf.pn.utmNorth = (int)mf.pn.actualNorthing; mf.worldGrid.CreateWorldGrid(0, 0); //make sure directory exists, or create it if ((!string.IsNullOrEmpty(directoryName)) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } //create the field file header info mf.FileCreateField(); mf.FileCreateContour(); mf.FileSaveFlags(); mf.FileSaveABLine(); } } catch (Exception ex) { mf.WriteErrorLog("Creating new field " + ex); MessageBox.Show("Error", ex.ToString()); mf.currentFieldDirectory = ""; } DialogResult = DialogResult.OK; Close(); }
private void btnExit_Click(object sender, EventArgs e) { if (numABSelected > 0) { mf.ABLine.refPoint1 = lineArr[numABSelected - 1].origin; //mf.ABLine.refPoint2 = lineArr[numABSelected - 1].ref2; mf.ABLine.abHeading = lineArr[numABSelected - 1].heading; mf.ABLine.SetABLineByHeading(); mf.FileSaveABLine(); mf.ABLine.isABLineSet = false; mf.ABLine.isABLineLoaded = true; } else { mf.ABLine.isABLineSet = false; mf.ABLine.isABLineLoaded = false; } //curve if (numCurveSelected > 0) { int aa = numCurveSelected - 1; mf.curve.aveLineHeading = curveArr[aa].aveHeading; mf.curve.refList?.Clear(); for (int i = 0; i < curveArr[aa].curvePts.Count; i++) { mf.curve.refList.Add(curveArr[aa].curvePts[i]); } mf.curve.isCurveSet = true; mf.FileSaveCurveLine(); } else { mf.curve.isCurveSet = false; mf.curve.refList?.Clear(); } Close(); }
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 + "\\"; //if no template set just make a new file. if (!isTemplateSet) { try { //start a new job mf.JobNew(); //create it for first save string directoryName = Path.GetDirectoryName(dirNewField); if ((!string.IsNullOrEmpty(directoryName)) && (Directory.Exists(directoryName))) { MessageBox.Show("Choose a different name", "Directory Exists", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } else { //reset the offsets mf.pn.utmEast = (int)mf.pn.actualEasting; mf.pn.utmNorth = (int)mf.pn.actualNorthing; mf.worldGrid.CreateWorldGrid(0, 0); //calculate the central meridian of current zone mf.pn.centralMeridian = -177 + ((mf.pn.zone - 1) * 6); //Azimuth Error - utm declination mf.pn.convergenceAngle = Math.Atan(Math.Sin(glm.toRadians(mf.pn.latitude)) * Math.Tan(glm.toRadians(mf.pn.longitude - mf.pn.centralMeridian))); mf.lblConvergenceAngle.Text = Math.Round(glm.toDegrees(mf.pn.convergenceAngle), 3).ToString(); //make sure directory exists, or create it if ((!string.IsNullOrEmpty(directoryName)) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } //create the field file header info mf.FileCreateField(); mf.FileCreateSections(); mf.FileCreateRecPath(); mf.FileCreateContour(); mf.FileCreateElevation(); mf.FileSaveFlags(); mf.FileSaveABLine(); mf.FileSaveCurveLine(); //mf.FileSaveHeadland(); } } catch (Exception ex) { mf.WriteErrorLog("Creating new field " + ex); MessageBox.Show("Error", ex.ToString()); mf.currentFieldDirectory = ""; } } else { // create from template string directoryName = Path.GetDirectoryName(dirNewField); if ((!string.IsNullOrEmpty(directoryName)) && (Directory.Exists(directoryName))) { MessageBox.Show("Choose a different name", "Directory Exists", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } else { //create the new directory if ((!string.IsNullOrEmpty(directoryName)) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } } string line; string offsets; using (StreamReader reader = new StreamReader(templateFileAndDirectory)) { 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(); } catch (Exception ex) { mf.WriteErrorLog("While Opening Field" + ex); var form = new FormTimedMessage(4000, "Field File is Corrupt", "Choose a different field"); 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); } //create blank Contour and Section files mf.FileCreateSections(); mf.FileCreateContour(); mf.FileCreateElevation(); //copy over the files from template string templateDirectoryName = Path.GetDirectoryName(templateFileAndDirectory); string fileToCopy = templateDirectoryName + "\\Boundary.txt"; string destinationDirectory = directoryName + "\\Boundary.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } fileToCopy = templateDirectoryName + "\\Headland.txt"; destinationDirectory = directoryName + "\\Headland.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } fileToCopy = templateDirectoryName + "\\Flags.txt"; destinationDirectory = directoryName + "\\Flags.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } fileToCopy = templateDirectoryName + "\\ABLine.txt"; destinationDirectory = directoryName + "\\ABLine.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 + "\\CurveLine.txt"; destinationDirectory = directoryName + "\\CurveLine.txt"; if (File.Exists(fileToCopy)) { File.Copy(fileToCopy, destinationDirectory); } //now open the newly cloned field mf.FileOpenField(dirNewField + myFileName); } } DialogResult = DialogResult.OK; Close(); }
private void oglSelf_MouseDown(object sender, MouseEventArgs e) { Point pt = oglSelf.PointToClient(Cursor.Position); //Convert to Origin in the center of window, 800 pixels fixPt.X = pt.X - 400; fixPt.Y = (800 - pt.Y - 400); vec3 plotPt = new vec3 { //convert screen coordinates to field coordinates easting = ((double)fixPt.X) * (double)maxFieldDistance / 723.0 * gain, northing = ((double)fixPt.Y) * (double)maxFieldDistance / 723.0 * gain, heading = 0 }; plotPt.easting += fieldCenterX; plotPt.northing += fieldCenterY; lblX.Text = plotPt.easting.ToString(); lblY.Text = plotPt.northing.ToString(); mf.self.pint.easting = plotPt.easting; mf.self.pint.northing = plotPt.northing; if (isA) { mf.self.linePtList?.Clear(); mf.self.lineList?.Clear(); mf.ABLine.ResetABLine(); lastABLineP1.easting = 9999; lastABLineP1.northing = 9999; lastABLineP2.easting = 9999; lastABLineP2.northing = 9999; mf.ABLine.refPoint1.easting = plotPt.easting; mf.ABLine.refPoint1.northing = plotPt.northing; isA = false; isB = true; } else if (isB) { mf.ABLine.refPoint2.easting = plotPt.easting; mf.ABLine.refPoint2.northing = plotPt.northing; isA = false; isB = false; isC = true; //calculate the AB Heading mf.ABLine.abHeading = Math.Atan2(mf.ABLine.refPoint2.easting - mf.ABLine.refPoint1.easting, mf.ABLine.refPoint2.northing - mf.ABLine.refPoint1.northing); if (mf.ABLine.abHeading < 0) { mf.ABLine.abHeading += glm.twoPI; } //sin x cos y for endpoints, opposite for additional lines mf.ABLine.refABLineP1.easting = mf.ABLine.refPoint1.easting - (Math.Sin(mf.ABLine.abHeading) * 1500.0); mf.ABLine.refABLineP1.northing = mf.ABLine.refPoint1.northing - (Math.Cos(mf.ABLine.abHeading) * 1500.0); mf.ABLine.refABLineP2.easting = mf.ABLine.refPoint1.easting + (Math.Sin(mf.ABLine.abHeading) * 1500.0); mf.ABLine.refABLineP2.northing = mf.ABLine.refPoint1.northing + (Math.Cos(mf.ABLine.abHeading) * 1500.0); mf.ABLine.isABLineSet = true; mf.FileSaveABLine(); } //borrowed snap code for last line of field else if (isC) { //move the ABLine over based on the overlap amount set in vehicle double widthMinusOverlap = mf.vehicle.toolWidth - mf.vehicle.toolOverlap; //x2-x1 double dx = mf.ABLine.refABLineP2.easting - mf.ABLine.refABLineP1.easting; //z2-z1 double dy = mf.ABLine.refABLineP2.northing - mf.ABLine.refABLineP1.northing; //how far are we away from the reference line at 90 degrees double distanceFromRefLine = ((dy * plotPt.easting) - (dx * plotPt.northing) + (mf.ABLine.refABLineP2.easting * mf.ABLine.refABLineP1.northing) - (mf.ABLine.refABLineP2.northing * mf.ABLine.refABLineP1.easting)) / Math.Sqrt((dy * dy) + (dx * dx)); //sign of distance determines which side of line we are on int refLineSide; if (distanceFromRefLine > 0) { refLineSide = 1; } else { refLineSide = -1; } //absolute the distance distanceFromRefLine = Math.Abs(distanceFromRefLine); //Which ABLine is the vehicle on, negative is left and positive is right side double howManyPathsAway = Math.Round(distanceFromRefLine / widthMinusOverlap, 0, MidpointRounding.AwayFromZero); //generate that pass number as signed integer mf.self.lastPassNumber = Convert.ToInt32(refLineSide * howManyPathsAway); //calculate the new point that is number of implement widths over double toolOffset = mf.vehicle.toolOffset; vec2 point1 = new vec2((Math.Cos(-mf.ABLine.abHeading) * ((widthMinusOverlap * howManyPathsAway * refLineSide) - toolOffset)) + mf.ABLine.refPoint1.easting, (Math.Sin(-mf.ABLine.abHeading) * ((widthMinusOverlap * howManyPathsAway * refLineSide) - toolOffset)) + mf.ABLine.refPoint1.northing); //create the new line extent points for current ABLine based on original heading of AB line lastABLineP1.easting = point1.easting - (Math.Sin(mf.ABLine.abHeading) * 1500.0); lastABLineP1.northing = point1.northing - (Math.Cos(mf.ABLine.abHeading) * 1500.0); lastABLineP2.easting = point1.easting + (Math.Sin(mf.ABLine.abHeading) * 1500.0); lastABLineP2.northing = point1.northing + (Math.Cos(mf.ABLine.abHeading) * 1500.0); isC = false; isA = true; lblPasses.Text = mf.self.lastPassNumber.ToString(); //build the lines, determine bounds mf.self.BuildLines(); int cnt = mf.self.cellDecList.Count; tbox1.Text = ""; for (int i = 0; i < cnt; i++) { tbox1.Text += i + "\t" + mf.self.cellDecList[i].lines + "\t" + mf.self.cellDecList[i].cells + "\r\n"; } } }