private void FormFlags_Load(object sender, EventArgs e) { lblLast.Text = gStr.gsCurrent + mf.vehicleFileName; DirectoryInfo dinfo = new DirectoryInfo(mf.vehiclesDirectory); FileInfo[] Files = dinfo.GetFiles("*.xml"); if (Files.Length == 0) { Close(); var form = new FormTimedMessage(2000, gStr.gsNoVehiclesSaved, gStr.gsSaveAVehicleFirst); form.Show(); } foreach (FileInfo file in Files) { cboxVeh.Items.Add(Path.GetFileNameWithoutExtension(file.Name)); } }
private void FormFlags_Load(object sender, EventArgs e) { lblLast.Text = gStr.gsCurrent + mf.envFileName; DirectoryInfo dinfo = new DirectoryInfo(mf.envDirectory); FileInfo[] Files = dinfo.GetFiles("*.txt"); if (Files.Length == 0) { DialogResult = DialogResult.Ignore; Close(); var form = new FormTimedMessage(2000, gStr.gsNoEnvironmentSaved, gStr.gsSaveAnEnvironmentFirst); form.Show(); } else { foreach (FileInfo file in Files) { cboxEnv.Items.Add(Path.GetFileNameWithoutExtension(file.Name)); } } }
private void btnAddAndGo_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; 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 = mf.curve.aveLineHeading; //write out the Curve Points foreach (var item in mf.curve.refList) { mf.curve.curveArr[idx].curvePts.Add(item); } mf.curve.isCurveSet = true; mf.FileSaveCurveLines(); Close(); } } else { var form2 = new FormTimedMessage(2000, gStr.gsNoABCurveCreated, gStr.gsCompleteAnABCurveLineFirst); form2.Show(); textBox1.BackColor = SystemColors.Window; } }
public void FileSaveVehicle() { //in the current application directory //string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //string fieldDir = dir + "\\fields\\"; string dirVehicle = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\AgOpenGPS\\Vehicles\\"; string directoryName = Path.GetDirectoryName(dirVehicle); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Title = "Save Vehicle"; saveDialog.Filter = "Text Files (*.txt)|*.txt"; saveDialog.InitialDirectory = directoryName; if (saveDialog.ShowDialog() == DialogResult.OK) { using (StreamWriter writer = new StreamWriter(saveDialog.FileName)) { writer.Write("Overlap," + Properties.Settings.Default.setVehicle_toolOverlap + ","); writer.Write("ToolTrailingHitchLength," + Properties.Settings.Default.setVehicle_toolTrailingHitchLength + ","); writer.Write("AntennaHeight," + Properties.Settings.Default.setVehicle_antennaHeight + ","); writer.Write("LookAhead," + Properties.Settings.Default.setVehicle_lookAhead + ","); writer.Write("AntennaPivot," + Properties.Settings.Default.setVehicle_antennaPivot + ","); writer.Write("HitchLength," + Properties.Settings.Default.setVehicle_hitchLength + ","); writer.Write("ToolOffset," + Properties.Settings.Default.setVehicle_toolOffset + ","); writer.Write("TurnOffDelay," + Properties.Settings.Default.setVehicle_turnOffDelay + ","); writer.Write("Wheelbase," + Properties.Settings.Default.setVehicle_wheelbase + ","); writer.Write("IsPivotBehindAntenna," + Properties.Settings.Default.setVehicle_isPivotBehindAntenna + ","); writer.Write("IsSteerAxleAhead," + Properties.Settings.Default.setVehicle_isSteerAxleAhead + ","); writer.Write("IsToolBehindPivot," + Properties.Settings.Default.setVehicle_isToolBehindPivot + ","); writer.Write("IsToolTrailing," + Properties.Settings.Default.setVehicle_isToolTrailing + ","); writer.Write("Spinner1," + Properties.Settings.Default.setSection_position1 + ","); writer.Write("Spinner2," + Properties.Settings.Default.setSection_position2 + ","); writer.Write("Spinner3," + Properties.Settings.Default.setSection_position3 + ","); writer.Write("Spinner4," + Properties.Settings.Default.setSection_position4 + ","); writer.Write("Spinner5," + Properties.Settings.Default.setSection_position5 + ","); writer.Write("Spinner6," + Properties.Settings.Default.setSection_position6 + ","); writer.Write("Sections," + Properties.Settings.Default.setVehicle_numSections + ","); writer.Write("ToolWidth," + Properties.Settings.Default.setVehicle_toolWidth + ","); writer.Write("Reserved,0,"); writer.Write("Reserved,0,"); writer.Write("Reserved,0,"); writer.Write("Reserved,0,"); writer.Write("Reserved,0,"); writer.Write("Reserved,0,"); writer.Write("Reserved,0,"); writer.Write("Reserved,0,"); writer.Write("Reserved,0,"); writer.Write("Reserved,0"); } //little show to say saved and where var form = new FormTimedMessage(this, 3000, "Saved in Folder: ", dirVehicle); form.Show(); } }
}//end of open file //Function to save a field public void FileSaveField() { //Friday, February 10, 2017 --> 2:58:24 PM //$FieldDir //test_2017Feb10_02.55.46.PM //$Offsets //533210,5927965 //$Heading //False //0,0.2,0.2,0.3,0.3,0,0 //$Sections //3 //4 //76 //-10.791,-10.964 if (!isJobStarted) { using (var form = new FormTimedMessage(this, 3000, "Ooops, Job Not Started", "Start a job")) { form.Show(); } return; } //the saved filename string myFileName = workingDirectory + currentFieldDirectory + "\\Field.fld"; //set saving flag on to ensure rapid save, no gps update isSavingFile = true; //make the file using (BinaryWriter bw = new BinaryWriter(File.Open(myFileName, FileMode.Create, FileAccess.Write))) { //Write out the date bw.Write(DateTime.Now.ToLongDateString() + " --> " + DateTime.Now.ToLongTimeString()); //string bw.Write("$FieldDir"); bw.Write(currentFieldDirectory); //string //write out the easting and northing Offsets bw.Write("$Offsets"); bw.Write(pn.utmEast); //int bw.Write(pn.utmNorth); //int bw.Write(pn.zone); //double //write out the ABLine bw.Write("$Heading"); //true or false if ABLine is set if (ABLine.isABLineSet) { bw.Write(true); //bool } else { bw.Write(false); } bw.Write(ABLine.abHeading); bw.Write(ABLine.refPoint1.x); // double bw.Write(ABLine.refPoint1.z); // double bw.Write(ABLine.refPoint2.x); // double bw.Write(ABLine.refPoint2.z); // double bw.Write(ABLine.tramPassEvery); //int bw.Write(ABLine.passBasedOn); //int //write paths # of sections bw.Write("$Sections"); bw.Write(vehicle.numOfSections + 1); for (int j = 0; j < vehicle.numOfSections + 1; j++) { //total patches for each section int patchCount = section[j].patchList.Count; //Write out the patches number bw.Write(patchCount); if (patchCount > 0) { //for every new chunk of patch in the whole section for (int q = 0; q < patchCount; q++) //each (var triList in section[j].patchList) { int count2 = section[j].patchList[q].Count(); bw.Write(count2); for (int i = 0; i < count2; i++) { bw.Write(section[j].patchList[q][i].x); bw.Write(section[j].patchList[q][i].z); } } } } bw.Write("$TotalSqM"); bw.Write(totalSquareMeters); //double //bw.Close(); } //set saving flag off isSavingFile = false; }
private void btnInField_Click(object sender, EventArgs e) { string infieldList = ""; int numFields = 0; string[] dirs = Directory.GetDirectories(mf.fieldsDirectory); foreach (string dir in dirs) { double lat = 0; double lon = 0; string fieldDirectory = Path.GetFileName(dir); string filename = dir + "\\Field.txt"; string line; //make sure directory has a field.txt in it if (File.Exists(filename)) { using (StreamReader reader = new StreamReader(filename)) { try { //Date time line for (int i = 0; i < 8; i++) { line = reader.ReadLine(); } //start positions if (!reader.EndOfStream) { line = reader.ReadLine(); string[] offs = line.Split(','); lat = (double.Parse(offs[0], CultureInfo.InvariantCulture)); lon = (double.Parse(offs[1], CultureInfo.InvariantCulture)); double dist = GetDistance(lon, lat, mf.pn.longitude, mf.pn.latitude); if (dist < 500) { numFields++; if (string.IsNullOrEmpty(infieldList)) { infieldList += Path.GetFileName(dir); } else { infieldList += "," + Path.GetFileName(dir); } } } } catch (Exception) { var form = new FormTimedMessage(2000, gStr.gsFieldFileIsCorrupt, gStr.gsChooseADifferentField); } } } } if (!string.IsNullOrEmpty(infieldList)) { mf.filePickerFileAndDirectory = ""; if (numFields > 1) { using (var form = new FormDrivePicker(mf, infieldList)) { var result = form.ShowDialog(this); //returns full field.txt file dir name if (result == DialogResult.Yes) { mf.FileOpenField(mf.filePickerFileAndDirectory); Close(); } else { return; } } } else // 1 field found { mf.filePickerFileAndDirectory = mf.fieldsDirectory + infieldList + "\\Field.txt"; mf.FileOpenField(mf.filePickerFileAndDirectory); Close(); } } else //no fields found { var form2 = new FormTimedMessage(2000, gStr.gsNoFieldsFound, gStr.gsFieldNotOpen); form2.Show(this); } }
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 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 FormSwapAB_Load(object sender, EventArgs e) { //different start based on AB line already set or not if (!mf.ABLine.isABLineSet) { Close(); } else { //no AB line } //make sure at least a blank AB Line file exists //make sure at least a global blank AB Line file exists string dirField = mf.fieldsDirectory + mf.currentFieldDirectory + "/"; string directoryName = Path.GetDirectoryName(dirField).ToString(CultureInfo.InvariantCulture); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "/ABLines.txt"; if (!File.Exists(filename)) { using (StreamWriter writer = new StreamWriter(filename)) { writer.WriteLine("ABLine N S,0,0,0"); writer.WriteLine("ABLine E W,90,0,0"); } } //get the file of previous AB Lines if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "/ABLines.txt"; if (!File.Exists(filename)) { mf.TimedMessageBox(2000, "File Error", "Missing AB Line File, Critical Error"); } else { using (StreamReader reader = new StreamReader(filename)) { try { string line; ListViewItem itm; //read all the lines while (!reader.EndOfStream) { line = reader.ReadLine(); string[] words = line.Split(','); //listboxLines.Items.Add(line); itm = new ListViewItem(words); lvLines.Items.Add(itm); } } catch (Exception er) { var form = new FormTimedMessage(2000, "ABLine File is Corrupt", "Please delete it!!!"); form.Show(); mf.WriteErrorLog("FieldOpen, Loading ABLine, Corrupt ABLine File" + er); } } // go to bottom of list - if there is a bottom if (lvLines.Items.Count > 0) { lvLines.Items[lvLines.Items.Count - 1].EnsureVisible(); } } //make sure at least a blank quickAB file exists directoryName = Path.GetDirectoryName(mf.fieldsDirectory).ToString(CultureInfo.InvariantCulture); directoryName += "/" + mf.currentFieldDirectory + "/"; if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "QuickAB.txt"; if (!File.Exists(filename)) { using (StreamWriter writer = new StreamWriter(filename)) { writer.WriteLine("ABLine N S,0,0,0"); writer.WriteLine("ABLine E W,90,0,0"); } } //get the file of previous AB Lines if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "QuickAB.txt"; if (!File.Exists(filename)) { mf.TimedMessageBox(2000, "File Error", "Missing QuickAB File, Critical Error"); } else { using (StreamReader reader = new StreamReader(filename)) { try { string line; //read all the lines { line = reader.ReadLine(); string[] words = line.Split(','); mf.AB1.fieldName = words[0]; mf.AB1.heading = double.Parse(words[1], CultureInfo.InvariantCulture); mf.AB1.X = double.Parse(words[2], CultureInfo.InvariantCulture); mf.AB1.Y = double.Parse(words[3], CultureInfo.InvariantCulture); lblField1.Text = mf.AB1.fieldName; lblHeading1.Text = mf.AB1.heading.ToString("N5"); line = reader.ReadLine(); words = line.Split(','); mf.AB2.fieldName = words[0]; mf.AB2.heading = double.Parse(words[1], CultureInfo.InvariantCulture); mf.AB2.X = double.Parse(words[2], CultureInfo.InvariantCulture); mf.AB2.Y = double.Parse(words[3], CultureInfo.InvariantCulture); lblField2.Text = mf.AB2.fieldName; lblHeading2.Text = mf.AB2.heading.ToString("N5"); } } catch (Exception er) { var form = new FormTimedMessage(2000, "QuickAB File is Corrupt", "Please delete it!!!"); form.Show(); mf.WriteErrorLog("FieldOpen, Loading QuickAB, Corrupt QuickAB File" + er); } } } }
private void btnAddToFile_Click(object sender, EventArgs e) { //get the directory and make sure it exists, create if not string dirField = mf.fieldsDirectory + mf.currentFieldDirectory + "\\"; string directoryName = Path.GetDirectoryName(dirField); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "\\CurveLines.txt"; //use Streamwriter to create and overwrite existing curveLines file using (StreamWriter writer = new StreamWriter(filename, true)) { try { if (mf.curve.refList.Count > 0) { if (textBox1.Text.Length > 0) { curveArr.Add(new CurveLineSaved()); curveArr[curveArr.Count - 1].Name = textBox1.Text; curveArr[curveArr.Count - 1].aveHeading = mf.curve.aveLineHeading; ListViewItem itm = new ListViewItem(curveArr[curveArr.Count - 1].Name); lvLines.Items.Add(itm); //write out the ABLine writer.WriteLine(textBox1.Text); //write out the aveheading writer.WriteLine(mf.curve.aveLineHeading.ToString(CultureInfo.InvariantCulture)); //write out the points of ref line writer.WriteLine(mf.curve.refList.Count.ToString(CultureInfo.InvariantCulture)); for (int j = 0; j < mf.curve.refList.Count; j++) { curveArr[curveArr.Count - 1].curvePts.Add(mf.curve.refList[j]); writer.WriteLine(Math.Round(mf.curve.refList[j].easting, 3).ToString(CultureInfo.InvariantCulture) + "," + Math.Round(mf.curve.refList[j].northing, 3).ToString(CultureInfo.InvariantCulture) + "," + Math.Round(mf.curve.refList[j].heading, 5).ToString(CultureInfo.InvariantCulture)); } } else { //MessageBox.Show("Currently no ABCurve name\n create ABCurve name"); var form2 = new FormTimedMessage(2000, gStr.gsNoNameEntered, gStr.gsEnterUniqueABCurveName); form2.Show(); } textBox1.Clear(); } else { var form2 = new FormTimedMessage(2000, gStr.gsNoABCurveCreated, gStr.gsCompleteAnABCurveLineFirst); form2.Show(); } } catch (Exception er) { mf.WriteErrorLog("Saving Curve Line" + er.ToString()); return; } } }
private void CreateNewField() { //fill something in if (String.IsNullOrEmpty(tboxFieldName.Text.Trim())) { Close(); return; } //append date time to name mf.currentFieldDirectory = tboxFieldName.Text.Trim(); //date if (cboxAddDate.Checked) { mf.currentFieldDirectory += " " + DateTime.Now.ToString("MMM.dd", CultureInfo.InvariantCulture); } if (cboxAddTime.Checked) { mf.currentFieldDirectory += " " + DateTime.Now.ToString("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; //if no template set just make a new file. 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(gStr.gsChooseADifferentName, gStr.gsDirectoryExists, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } else { mf.pn.latStart = latK; mf.pn.lonStart = lonK; if (mf.timerSim.Enabled) { mf.sim.latitude = Properties.Settings.Default.setGPS_SimLatitude = latK; mf.sim.longitude = Properties.Settings.Default.setGPS_SimLongitude = lonK; mf.pn.latitude = latK; mf.pn.longitude = lonK; Properties.Settings.Default.Save(); } mf.pn.SetLocalMetersPerDegree(); //make sure directory exists, or create it if ((!string.IsNullOrEmpty(directoryName)) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } mf.displayFieldName = mf.currentFieldDirectory; //create the field file header info if (!mf.isJobStarted) { using (FormTimedMessage form = new FormTimedMessage(3000, gStr.gsFieldNotOpen, gStr.gsCreateNewField)) { form.Show(this); } return; } string myFileName, dirField; //get the directory and make sure it exists, create if not dirField = mf.fieldsDirectory + mf.currentFieldDirectory + "\\"; directoryName = Path.GetDirectoryName(dirField); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } myFileName = "Field.txt"; using (StreamWriter writer = new StreamWriter(dirField + 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("0,0"); writer.WriteLine("Convergence"); writer.WriteLine("0"); writer.WriteLine("StartFix"); writer.WriteLine(mf.pn.latStart.ToString(CultureInfo.InvariantCulture) + "," + mf.pn.lonStart.ToString(CultureInfo.InvariantCulture)); } 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(gStr.gsError, ex.ToString()); mf.currentFieldDirectory = ""; } }
private void FormABCurve_LoadCurves() { //get the directory and make sure it exists, create if not string dirField = mf.fieldsDirectory + mf.currentFieldDirectory + "\\"; string directoryName = Path.GetDirectoryName(dirField); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "\\CurveLines.txt"; if (!File.Exists(filename)) { using (StreamWriter writer = new StreamWriter(filename)) { writer.WriteLine("$CurveLines"); } } //get the file of previous AB Lines if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } if (!File.Exists(filename)) { mf.TimedMessageBox(2000, "File Error", "Missing CurveLines File, Critical Error"); } else { using (StreamReader reader = new StreamReader(filename)) { try { ListViewItem itm; string line; int num = 0; //read header $CurveLine line = reader.ReadLine(); while (!reader.EndOfStream) { curveArrs.Add(new CurveLines()); //read header $CurveLine curveArrs[num].Name = reader.ReadLine(); // get the average heading line = reader.ReadLine(); curveArrs[num].Heading = double.Parse(line, CultureInfo.InvariantCulture); line = reader.ReadLine(); int numPoints = int.Parse(line); if (numPoints > 1) { itm = new ListViewItem(curveArrs[num].Name); lvLines.Items.Add(itm); curveArrs[num].curveArr?.Clear(); 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)); curveArrs[num].curveArr.Add(vecPt); } num++; } else { if (curveArrs.Count > 0) { curveArrs.RemoveAt(num); } } } } catch (Exception er) { var form = new FormTimedMessage(2000, "Curve Line File is Corrupt", "But Field is Loaded"); form.Show(); mf.WriteErrorLog("Load Curve Line" + er.ToString()); } } // go to bottom of list - if there is a bottom if (lvLines.Items.Count > 0) { lvLines.Items[lvLines.Items.Count - 1].EnsureVisible(); } } }
//---------- Text Versions of Save --------------------- // //Function to save a field public void FileSaveFieldText() { //Saturday, February 11, 2017 --> 7:26:52 AM //$FieldDir //Bob_Feb11 //$Offsets //533172,5927719,12 - offset easting, northing, zone //$Heading //True - ABLine is set, below is heading and ref points, tramline base and offset //4.32475480730906,25.4121330033522,18.2562255775556,10.5295032855356,12.1358088953421,0,0 //$Sections //1 //2 - patches in this section //10 - points in this patch //10.1728031317344,0.723157039771303 -easting, northing //$totalSquareMeters //970.761820481737 //$SectionMeters //256.988029010753,367.092667389756,346.681124081229,0,0 if (!isJobStarted) { using (var form = new FormTimedMessage(this, 3000, "Ooops, Job Not Started", "Start a Job First")) { form.Show(); } return; } string myFileName; string dirField; //get the directory and make sure it exists, create if not dirField = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\AgOpenGPS\\Fields\\" + currentFieldDirectory + "\\"; string directoryName = Path.GetDirectoryName(dirField); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } myFileName = currentFieldDirectory + "_Field.txt"; //set saving flag on to ensure rapid save, no gps update isSavingFile = true; using (StreamWriter writer = new StreamWriter(dirField + myFileName)) { //Write out the date writer.WriteLine(DateTime.Now.ToLongDateString() + " --> " + DateTime.Now.ToLongTimeString()); writer.WriteLine("$FieldDir"); writer.WriteLine(currentFieldDirectory); //write out the easting and northing Offsets writer.WriteLine("$Offsets"); writer.WriteLine(pn.utmEast + "," + pn.utmNorth + "," + pn.zone); //write out the ABLine writer.WriteLine("$Heading"); //true or false if ABLine is set if (ABLine.isABLineSet) { writer.WriteLine(true); } else { writer.WriteLine(false); } writer.WriteLine(ABLine.abHeading + "," + ABLine.refPoint1.x + "," + ABLine.refPoint1.z + "," + ABLine.refPoint2.x + "," + ABLine.refPoint2.z + "," + ABLine.tramPassEvery + "," + ABLine.passBasedOn); //write paths # of sections writer.WriteLine("$Sections"); writer.WriteLine(vehicle.numOfSections + 1); for (int j = 0; j < vehicle.numOfSections + 1; j++) { //every time the patch turns off and on is a new patch int patchCount = section[j].patchList.Count(); //Write out the patch writer.WriteLine(patchCount); if (patchCount > 0) { //for every new chunk of patch in the whole section foreach (var triList in section[j].patchList) { int count2 = triList.Count(); writer.WriteLine(count2); for (int i = 0; i < count2; i++) { writer.WriteLine(triList[i].x + "," + triList[i].z); } } } } writer.WriteLine("$totalSquareMeters"); writer.WriteLine(totalSquareMeters); } //set saving flag off isSavingFile = false; }
private void btnVehicleLoad_Click(object sender, EventArgs e) { if (!mf.isJobStarted) { if (lvVehicles.SelectedItems.Count > 0) { DialogResult result3 = MessageBox.Show( "Load: " + lvVehicles.SelectedItems[0].SubItems[0].Text + ".XML", gStr.gsSaveAndReturn, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result3 == DialogResult.Yes) { SettingsIO.ImportAll(mf.vehiclesDirectory + lvVehicles.SelectedItems[0].SubItems[0].Text + ".XML"); mf.vehicleFileName = lvVehicles.SelectedItems[0].SubItems[0].Text; Properties.Vehicle.Default.setVehicle_vehicleName = mf.vehicleFileName; Properties.Vehicle.Default.Save(); mf.vehicle = new CVehicle(mf); mf.tool = new CTool(mf); //fix the checkboxes on summary //SaveDisplaySettings(); //reset AOG mf.LoadSettings(); chkDisplaySky.Checked = mf.isSkyOn; chkDisplayGrid.Checked = mf.isGridOn; chkDisplaySpeedo.Checked = mf.isSpeedoOn; chkDisplayDayNight.Checked = mf.isAutoDayNight; chkDisplayExtraGuides.Checked = mf.isSideGuideLines; chkDisplayLogNMEA.Checked = mf.isLogNMEA; chkDisplayPolygons.Checked = mf.isDrawPolygons; chkDisplayLightbar.Checked = mf.isLightbarOn; chkDisplayKeyboard.Checked = mf.isKeyboardOn; chkDisplayStartFullScreen.Checked = Properties.Settings.Default.setDisplay_isStartFullScreen; if (mf.isMetric) { rbtnDisplayMetric.Checked = true; } else { rbtnDisplayImperial.Checked = true; } SaveDisplaySettings(); //Form Steer Settings mf.p_252.pgn[mf.p_252.countsPerDegree] = unchecked ((byte)Properties.Settings.Default.setAS_countsPerDegree); mf.p_252.pgn[mf.p_252.ackerman] = unchecked ((byte)Properties.Settings.Default.setAS_ackerman); mf.p_252.pgn[mf.p_252.wasOffsetHi] = unchecked ((byte)(Properties.Settings.Default.setAS_wasOffset >> 8)); mf.p_252.pgn[mf.p_252.wasOffsetLo] = unchecked ((byte)(Properties.Settings.Default.setAS_wasOffset)); mf.p_252.pgn[mf.p_252.highPWM] = unchecked ((byte)Properties.Settings.Default.setAS_highSteerPWM); mf.p_252.pgn[mf.p_252.lowPWM] = unchecked ((byte)Properties.Settings.Default.setAS_lowSteerPWM); mf.p_252.pgn[mf.p_252.gainProportional] = unchecked ((byte)Properties.Settings.Default.setAS_Kp); mf.p_252.pgn[mf.p_252.minPWM] = unchecked ((byte)Properties.Settings.Default.setAS_minSteerPWM); mf.SendPgnToLoop(mf.p_252.pgn); //machine module settings mf.p_238.pgn[mf.p_238.set0] = Properties.Vehicle.Default.setArdMac_setting0; mf.p_238.pgn[mf.p_238.raiseTime] = Properties.Vehicle.Default.setArdMac_hydRaiseTime; mf.p_238.pgn[mf.p_238.lowerTime] = Properties.Vehicle.Default.setArdMac_hydLowerTime; mf.SendPgnToLoop(mf.p_238.pgn); //steer config mf.p_251.pgn[mf.p_251.set0] = Properties.Vehicle.Default.setArdSteer_setting0; mf.p_251.pgn[mf.p_251.set1] = Properties.Vehicle.Default.setArdSteer_setting1; mf.p_251.pgn[mf.p_251.maxPulse] = Properties.Vehicle.Default.setArdSteer_maxPulseCounts; mf.p_251.pgn[mf.p_251.minSpeed] = 5; //0.5 kmh mf.SendPgnToLoop(mf.p_251.pgn); mf.TimedMessageBox(2500, "Steer and Machine Settings Sent", "Was Steer Module Connected?"); } UpdateVehicleListView(); } } else { var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); form.Show(this); } //Close(); }
private void btnInField_Click(object sender, EventArgs e) { string infieldList = ""; int numFields = 0; string[] dirs = Directory.GetDirectories(mf.fieldsDirectory); foreach (string dir in dirs) { double northingOffset = 0; double eastingOffset = 0; string fieldDirectory = Path.GetFileName(dir); string filename = dir + "\\Field.txt"; string line; //make sure directory has a field.txt in it if (File.Exists(filename)) { using (StreamReader reader = new StreamReader(filename)) { try { //Date time line for (int i = 0; i < 4; i++) { line = reader.ReadLine(); } //start positions if (!reader.EndOfStream) { line = reader.ReadLine(); string[] offs = line.Split(','); eastingOffset = (double.Parse(offs[0], CultureInfo.InvariantCulture)); northingOffset = (double.Parse(offs[1], CultureInfo.InvariantCulture)); } } catch (Exception) { var form = new FormTimedMessage(2000, gStr.gsFieldFileIsCorrupt, gStr.gsChooseADifferentField); } } //grab the boundary filename = dir + "\\Boundary.txt"; if (File.Exists(filename)) { List <vec3> pointList = new List <vec3>(); using (StreamReader reader = new StreamReader(filename)) { try { //read header line = reader.ReadLine(); //Boundary if (!reader.EndOfStream) //empty boundary field { //True or False OR points from older boundary files line = reader.ReadLine(); //Check for older boundary files, then above line string is num of points if (line == "True" || line == "False") { line = reader.ReadLine(); //number of points } //Check for latest boundary files, then above line string is num of points if (line == "True" || line == "False") { line = reader.ReadLine(); //number of points } int numPoints = int.Parse(line); vec2[] linePoints = new vec2[numPoints]; if (numPoints > 0) { //load the line for (int i = 0; i < numPoints; i++) { line = reader.ReadLine(); string[] words = line.Split(','); vec2 vecPt = new vec2( double.Parse(words[0], CultureInfo.InvariantCulture) + eastingOffset, double.Parse(words[1], CultureInfo.InvariantCulture) + northingOffset); linePoints[i] = vecPt; } int j = linePoints.Length - 1; bool oddNodes = false; double x = mf.pn.actualEasting; double y = mf.pn.actualNorthing; for (int i = 0; i < linePoints.Length; i++) { if ((linePoints[i].northing < y && linePoints[j].northing >= y || linePoints[j].northing < y && linePoints[i].northing >= y) && (linePoints[i].easting <= x || linePoints[j].easting <= x)) { oddNodes ^= (linePoints[i].easting + (y - linePoints[i].northing) / (linePoints[j].northing - linePoints[i].northing) * (linePoints[j].easting - linePoints[i].easting) < x); } j = i; } if (oddNodes) { numFields++; if (string.IsNullOrEmpty(infieldList)) { infieldList += Path.GetFileName(dir); } else { infieldList += "," + Path.GetFileName(dir); } } } } } catch (Exception) { } } } } } if (!string.IsNullOrEmpty(infieldList)) { mf.filePickerFileAndDirectory = ""; if (numFields > 1) { using (var form = new FormDrivePicker(mf, infieldList)) { var result = form.ShowDialog(); //returns full field.txt file dir name if (result == DialogResult.Yes) { mf.FileOpenField(mf.filePickerFileAndDirectory); Close(); } else { return; } } } else // 1 field found { mf.filePickerFileAndDirectory = mf.fieldsDirectory + infieldList + "\\Field.txt"; mf.FileOpenField(mf.filePickerFileAndDirectory); Close(); } } else //no fields found { var form2 = new FormTimedMessage(2000, gStr.gsNoFieldsFound, gStr.gsFieldNotOpen); form2.Show(); } }
private void btnAddToFile_Click(object sender, EventArgs e) { if (mf.ABLine.isABLineSet) { if (tboxABLineName.Text.Length > 0) { mf.ABLine.lineArr.Add(new CABLines()); mf.ABLine.numABLines = mf.ABLine.lineArr.Count; mf.ABLine.numABLineSelected = mf.ABLine.numABLines; //index to last one. int idx = mf.ABLine.lineArr.Count - 1; 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; //sin x cos z for endpoints, opposite for additional lines mf.ABLine.lineArr[idx].ref1.easting = mf.ABLine.lineArr[idx].origin.easting - (Math.Sin(mf.ABLine.lineArr[idx].heading) * 1600.0); mf.ABLine.lineArr[idx].ref1.northing = mf.ABLine.lineArr[idx].origin.northing - (Math.Cos(mf.ABLine.lineArr[idx].heading) * 1600.0); mf.ABLine.lineArr[idx].ref2.easting = mf.ABLine.lineArr[idx].origin.easting + (Math.Sin(mf.ABLine.lineArr[idx].heading) * 1600.0); mf.ABLine.lineArr[idx].ref2.northing = mf.ABLine.lineArr[idx].origin.northing + (Math.Cos(mf.ABLine.lineArr[idx].heading) * 1600.0); mf.ABLine.lineArr[idx].Name = tboxABLineName.Text.Trim(); //update the list box ListViewItem itm; itm = new ListViewItem(mf.ABLine.lineArr[idx].Name); lvLines.Items.Add(itm); // go to bottom of list - if there is a bottom if (lvLines.Items.Count > 0) { lvLines.Items[lvLines.Items.Count - 1].EnsureVisible(); } mf.FileSaveABLines(); tboxABLineName.BackColor = SystemColors.ControlLight; tboxABLineName.Text = ""; btnAddToFile.Enabled = false; btnAddAndGo.Enabled = false; btnNewABLine.Enabled = true; tboxABLineName.Enabled = false; btnTurnOffAB.Enabled = true; lvLines.Enabled = false; tboxABLineName.Enabled = false; lvLines.Enabled = true; lvLines.Focus(); } else { //MessageBox.Show("Currently no ABCurve name\n create ABCurve name"); var form2 = new FormTimedMessage(2000, gStr.gsNoNameEntered, gStr.gsEnterLineName); form2.Show(); } } else { //MessageBox.Show("Currently no ABCurve name\n create ABCurve name"); var form2 = new FormTimedMessage(2000, gStr.gsNoABLineActive, gStr.gsPleaseCompleteABLine); form2.Show(); } tboxABLineName.Clear(); }
private void btnVehicleLoad_Click(object sender, EventArgs e) { if (!mf.isJobStarted) { if (lvVehicles.SelectedItems.Count > 0) { DialogResult result3 = MessageBox.Show( "Load: " + lvVehicles.SelectedItems[0].SubItems[0].Text + ".XML", gStr.gsSaveAndReturn, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result3 == DialogResult.Yes) { SettingsIO.ImportAll(mf.vehiclesDirectory + lvVehicles.SelectedItems[0].SubItems[0].Text + ".XML"); mf.vehicleFileName = lvVehicles.SelectedItems[0].SubItems[0].Text; Properties.Vehicle.Default.setVehicle_vehicleName = mf.vehicleFileName; Properties.Vehicle.Default.Save(); mf.vehicle = new CVehicle(mf); mf.tool = new CTool(mf); //fix the checkboxes on summary //SaveDisplaySettings(); //reset AOG mf.LoadSettings(); chkDisplaySky.Checked = mf.isSkyOn; chkDisplayFloor.Checked = mf.isTextureOn; chkDisplayGrid.Checked = mf.isGridOn; chkDisplaySpeedo.Checked = mf.isSpeedoOn; chkDisplayDayNight.Checked = mf.isAutoDayNight; chkDisplayExtraGuides.Checked = mf.isSideGuideLines; chkDisplayLogNMEA.Checked = mf.isLogNMEA; chkDisplayPolygons.Checked = mf.isDrawPolygons; chkDisplayLightbar.Checked = mf.isLightbarOn; chkDisplayKeyboard.Checked = mf.isKeyboardOn; chkDisplayStartFullScreen.Checked = Properties.Settings.Default.setDisplay_isStartFullScreen; if (mf.isMetric) { rbtnDisplayMetric.Checked = true; } else { rbtnDisplayImperial.Checked = true; } SaveDisplaySettings(); lblCurrentVehicle.Text = Properties.Vehicle.Default.setVehicle_vehicleName; if (mf.isMetric) { lblInchesCm.Text = gStr.gsCentimeters; lblFeetMeters.Text = gStr.gsMeters; lblSecTotalWidthFeet.Visible = false; lblSecTotalWidthInches.Visible = false; lblSecTotalWidthMeters.Visible = true; } else { lblInchesCm.Text = gStr.gsInches; lblFeetMeters.Text = "Feet"; lblSecTotalWidthFeet.Visible = true; lblSecTotalWidthInches.Visible = true; lblSecTotalWidthMeters.Visible = false; } if (mf.isMetric) { lblSecTotalWidthMeters.Text = (mf.tool.toolWidth * 100).ToString() + " cm"; } else { double toFeet = mf.tool.toolWidth * 3.2808; lblSecTotalWidthFeet.Text = Convert.ToString((int)toFeet) + "'"; double temp = Math.Round((toFeet - Math.Truncate(toFeet)) * 12, 0); lblSecTotalWidthInches.Text = Convert.ToString(temp) + '"'; } //Form Steer Settings mf.p_252.pgn[mf.p_252.countsPerDegree] = unchecked ((byte)Properties.Settings.Default.setAS_countsPerDegree); mf.p_252.pgn[mf.p_252.ackerman] = unchecked ((byte)Properties.Settings.Default.setAS_ackerman); mf.p_252.pgn[mf.p_252.wasOffsetHi] = unchecked ((byte)(Properties.Settings.Default.setAS_wasOffset >> 8)); mf.p_252.pgn[mf.p_252.wasOffsetLo] = unchecked ((byte)(Properties.Settings.Default.setAS_wasOffset)); mf.p_252.pgn[mf.p_252.highPWM] = unchecked ((byte)Properties.Settings.Default.setAS_highSteerPWM); mf.p_252.pgn[mf.p_252.lowPWM] = unchecked ((byte)Properties.Settings.Default.setAS_lowSteerPWM); mf.p_252.pgn[mf.p_252.gainProportional] = unchecked ((byte)Properties.Settings.Default.setAS_Kp); mf.p_252.pgn[mf.p_252.minPWM] = unchecked ((byte)Properties.Settings.Default.setAS_minSteerPWM); mf.SendPgnToLoop(mf.p_252.pgn); //machine module settings mf.p_238.pgn[mf.p_238.set0] = Properties.Vehicle.Default.setArdMac_setting0; mf.p_238.pgn[mf.p_238.raiseTime] = Properties.Vehicle.Default.setArdMac_hydRaiseTime; mf.p_238.pgn[mf.p_238.lowerTime] = Properties.Vehicle.Default.setArdMac_hydLowerTime; mf.SendPgnToLoop(mf.p_238.pgn); //steer config mf.p_251.pgn[mf.p_251.set0] = Properties.Vehicle.Default.setArdSteer_setting0; mf.p_251.pgn[mf.p_251.set1] = Properties.Vehicle.Default.setArdSteer_setting1; mf.p_251.pgn[mf.p_251.maxPulse] = Properties.Vehicle.Default.setArdSteer_maxPulseCounts; mf.p_251.pgn[mf.p_251.minSpeed] = 5; //0.5 kmh if (Properties.Settings.Default.setAS_isAngVelGuidance) { mf.p_251.pgn[mf.p_251.angVel] = 1; } else { mf.p_251.pgn[mf.p_251.angVel] = 0; } mf.SendPgnToLoop(mf.p_251.pgn); //Send Pin configuration SendRelaySettingsToMachineModule(); ///Remind the user mf.TimedMessageBox(2500, "Steer and Machine Settings Sent", "Were Modules Connected?"); } UpdateVehicleListView(); } } else { var form = new FormTimedMessage(2000, gStr.gsFieldIsOpen, gStr.gsCloseFieldFirst); form.Show(this); } //Close(); }
private void FormABLine_Load(object sender, EventArgs e) { //different start based on AB line already set or not if (mf.ABLine.isABLineSet) { //AB line is on screen and set btnAPoint.Enabled = false; btnBPoint.Enabled = true; upDnHeading = Math.Round(glm.toDegrees(mf.ABLine.abHeading), 6); nudTramRepeats.Value = mf.ABLine.tramPassEvery; nudBasedOnPass.Value = mf.ABLine.passBasedOn; tboxHeading.Text = upDnHeading.ToString(CultureInfo.InvariantCulture); } else { //no AB line btnAPoint.Enabled = true; btnBPoint.Enabled = false; //btnABLineOk.Enabled = false; upDnHeading = Math.Round(glm.toDegrees(mf.fixHeading), 6); nudTramRepeats.Value = 0; nudBasedOnPass.Value = 0; mf.ABLine.tramPassEvery = 0; mf.ABLine.passBasedOn = 0; } //make sure at least a blank AB Line file exists string dirABLines = mf.ablinesDirectory; string directoryName = Path.GetDirectoryName(dirABLines).ToString(CultureInfo.InvariantCulture); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "\\ABLines.txt"; if (!File.Exists(filename)) { using (StreamWriter writer = new StreamWriter(filename)) { writer.WriteLine("ABLine N S,0,0,0"); writer.WriteLine("ABLine E W,90,0,0"); } } //get the file of previous AB Lines if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "\\ABLines.txt"; if (!File.Exists(filename)) { mf.TimedMessageBox(2000, "File Error", "Missing AB Line File, Critical Error"); } else { using (StreamReader reader = new StreamReader(filename)) { try { string line; ListViewItem itm; //read all the lines while (!reader.EndOfStream) { line = reader.ReadLine(); string[] words = line.Split(','); //listboxLines.Items.Add(line); itm = new ListViewItem(words); lvLines.Items.Add(itm); //coords.easting = double.Parse(words[0], CultureInfo.InvariantCulture); //coords.northing = double.Parse(words[1], CultureInfo.InvariantCulture); //youFileList.Add(coords); } } catch (Exception er) { var form = new FormTimedMessage(4000, "ABLine File is Corrupt", "Please delete it!!!"); form.Show(); mf.WriteErrorLog("FieldOpen, Loading ABLine, Corrupt ABLine File" + er); } } // go to bottom of list - if there is a bottom if (lvLines.Items.Count > 0) { lvLines.Items[lvLines.Items.Count - 1].EnsureVisible(); } } }
private void LoadLines() { //make sure at least a global blank AB Line file exists string dirField = mf.fieldsDirectory + mf.currentFieldDirectory + "\\"; string directoryName = Path.GetDirectoryName(dirField).ToString(CultureInfo.InvariantCulture); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "\\ABLines.txt"; if (!File.Exists(filename)) { using (StreamWriter writer = new StreamWriter(filename)) { } } if (!File.Exists(filename)) { mf.TimedMessageBox(2000, gStr.gsFileError, gStr.gsMissingABLinesFile); } else { using (StreamReader reader = new StreamReader(filename)) { try { string line; //read all the lines for (int num = 0; !reader.EndOfStream; num++) { lineArr.Add(new ABLinePick()); line = reader.ReadLine(); string[] words = line.Split(','); lineArr[num].Name = words[0]; lineArr[num].heading = glm.toRadians(double.Parse(words[1], CultureInfo.InvariantCulture)); lineArr[num].origin.easting = double.Parse(words[2], CultureInfo.InvariantCulture); lineArr[num].origin.northing = double.Parse(words[3], CultureInfo.InvariantCulture); lineArr[num].ref1.easting = lineArr[num].origin.easting - (Math.Sin(lineArr[num].heading) * 2000.0); lineArr[num].ref1.northing = lineArr[num].origin.northing - (Math.Cos(lineArr[num].heading) * 2000.0); lineArr[num].ref2.easting = lineArr[num].origin.easting + (Math.Sin(lineArr[num].heading) * 2000.0); lineArr[num].ref2.northing = lineArr[num].origin.northing + (Math.Cos(lineArr[num].heading) * 2000.0); } } catch (Exception er) { var form = new FormTimedMessage(2000, gStr.gsABLineFileIsCorrupt, "Please delete it!!!"); form.Show(); mf.WriteErrorLog("FieldOpen, Loading ABLine, Corrupt ABLine File" + er); } } } }
//message box pops up with info then goes away public void TimedMessageBox(int timeout, string s1, string s2) { var form = new FormTimedMessage(timeout, s1, s2); form.Show(); }
private void LoadCurves() { //get the directory and make sure it exists, create if not string dirField = mf.fieldsDirectory + mf.currentFieldDirectory + "\\"; string directoryName = Path.GetDirectoryName(dirField); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "\\CurveLines.txt"; if (!File.Exists(filename)) { using (StreamWriter writer = new StreamWriter(filename)) { writer.WriteLine("$CurveLines"); } } //get the file of previous AB Lines if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } if (!File.Exists(filename)) { mf.TimedMessageBox(2000, gStr.gsFileError, gStr.gsMissingABCurveFile); } else { using (StreamReader reader = new StreamReader(filename)) { try { string line; int num = 0; Random rnd = new Random(); //read header $CurveLine line = reader.ReadLine(); while (!reader.EndOfStream) { curveArr.Add(new CurveLinePick()); //read header $CurveLine curveArr[num].Name = reader.ReadLine(); // get the average heading line = reader.ReadLine(); curveArr[num].aveHeading = double.Parse(line, CultureInfo.InvariantCulture); line = reader.ReadLine(); int numPoints = int.Parse(line); if (numPoints > 1) { curveArr[num].curvePts?.Clear(); 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)); curveArr[num].curvePts.Add(vecPt); } num++; } else { if (curveArr.Count > 0) { curveArr.RemoveAt(num); } } } } catch (Exception er) { var form = new FormTimedMessage(2000, gStr.gsCurveLineFileIsCorrupt, gStr.gsButFieldIsLoaded); form.Show(); mf.WriteErrorLog("Load Curve Line" + er.ToString()); } } } }
private void FormFilePicker_Load(object sender, EventArgs e) { isOrderByName = true; timer1.Enabled = true; ListViewItem itm; string[] dirs = Directory.GetDirectories(mf.fieldsDirectory); fileList?.Clear(); foreach (string dir in dirs) { double latStart = 0; double lonStart = 0; double distance = 0; string fieldDirectory = Path.GetFileName(dir); string filename = dir + "/Field.txt"; string line; //make sure directory has a field.txt in it if (File.Exists(filename)) { using (StreamReader reader = new StreamReader(filename)) { try { //Date time line for (int i = 0; i < 8; i++) { line = reader.ReadLine(); } //start positions if (!reader.EndOfStream) { line = reader.ReadLine(); string[] offs = line.Split(','); latStart = (double.Parse(offs[0], CultureInfo.InvariantCulture)); lonStart = (double.Parse(offs[1], CultureInfo.InvariantCulture)); } } catch (Exception) { var form = new FormTimedMessage(2000, gStr.gsFieldFileIsCorrupt, gStr.gsChooseADifferentField); } } distance = Math.Pow((latStart - mf.pn.latitude), 2) + Math.Pow((lonStart - mf.pn.longitude), 2); distance = Math.Sqrt(distance); distance *= 100; fileList.Add(fieldDirectory); fileList.Add(distance.ToString("00.###")); } } for (int i = 0; i < fileList.Count; i += 2) { string[] fieldNames = { fileList[i], fileList[i + 1] }; itm = new ListViewItem(fieldNames); lvLines.Items.Add(itm); } //string fieldName = Path.GetDirectoryName(dir).ToString(CultureInfo.InvariantCulture); if (lvLines.Items.Count > 0) { this.chName.Text = "Field Name"; this.chName.Width = 805; this.chDistance.Text = "Distance"; this.chDistance.Width = 150; } else { //var form2 = new FormTimedMessage(2000, gStr.gsNoFieldsCreated, gStr.gsCreateNewFieldFirst); //form2.Show(); } }
}//end of open file //Function to save a field public void FileSaveField(string _filename) { if (!isJobStarted) { var form = new FormTimedMessage(this, 3000, "Ooops, Job Not Started", "Push Job Button"); form.Show(); return; } //get the directory and make sure it exists, create if not string dirField = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\AgOpenGPS\\Fields\\"; string directoryName = Path.GetDirectoryName(dirField); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } string myFileName; if (_filename == "Resume") { myFileName = "Resume.txt"; } else { myFileName = String.Format("{0}{1}", DateTime.Now.ToString("yyyy_MMM_dd__hh.mm.ss.tt"), ".txt"); } //set saving flag on to ensure rapid save, no gps update isSavingFile = true; using (StreamWriter writer = new StreamWriter(dirField + myFileName)) { //Write out the date writer.WriteLine(DateTime.Now.ToLongDateString() + " --> " + DateTime.Now.ToLongTimeString()); //write out the easting and northing Offsets writer.WriteLine("$Offsets"); writer.WriteLine(pn.utmEast + "," + pn.utmNorth); //write out the ABLine writer.WriteLine("$Heading"); //true or false if ABLine is set if (ABLine.isABLineSet) { writer.WriteLine(true); } else { writer.WriteLine(false); } writer.WriteLine(ABLine.abHeading + "," + ABLine.refPoint1.x + "," + ABLine.refPoint1.z + "," + ABLine.refPoint2.x + "," + ABLine.refPoint2.z + "," + ABLine.tramPassEvery + "," + ABLine.passBasedOn); //write paths # of sections writer.WriteLine("$Sections"); writer.WriteLine(vehicle.numberOfSections); for (int j = 0; j < vehicle.numberOfSections; j++) { //every time the patch turns off and on is a new patch int patchCount = section[j].patchList.Count(); //Write out the patch writer.WriteLine(patchCount); if (patchCount > 0) { //for every new chunk of patch in the whole section foreach (var triList in section[j].patchList) { int count2 = triList.Count(); writer.WriteLine(count2); for (int i = 0; i < count2; i++) { writer.WriteLine(Math.Round(triList[i].x, 2) + "," + Math.Round(triList[i].z, 2)); } } } } writer.WriteLine("$totalSquareMeters"); writer.WriteLine(totalSquareMeters); writer.WriteLine("$SectionMeters"); writer.WriteLine(section[0].squareMetersSection + "," + section[1].squareMetersSection + "," + section[2].squareMetersSection + "," + section[3].squareMetersSection + "," + section[4].squareMetersSection); } //set saving flag off isSavingFile = false; //little show to say saved and where //MessageBox.Show((dirField + "\n\r\n\r" + myFileName), "File Saved to "); if (_filename != "Resume") { var form2 = new FormTimedMessage(this, 3000, "Folder: " + dirField, "File: " + myFileName); form2.Show(); } }
private void FormFilePicker_Load(object sender, EventArgs e) { order = 0; timer1.Enabled = true; ListViewItem itm; string[] dirs = Directory.GetDirectories(mf.fieldsDirectory); fileList?.Clear(); foreach (string dir in dirs) { double latStart = 0; double lonStart = 0; double distance = 0; string fieldDirectory = Path.GetFileName(dir); string filename = dir + "\\Field.txt"; string line; //make sure directory has a field.txt in it if (File.Exists(filename)) { using (StreamReader reader = new StreamReader(filename)) { try { //Date time line for (int i = 0; i < 8; i++) { line = reader.ReadLine(); } //start positions if (!reader.EndOfStream) { line = reader.ReadLine(); string[] offs = line.Split(','); latStart = (double.Parse(offs[0], CultureInfo.InvariantCulture)); lonStart = (double.Parse(offs[1], CultureInfo.InvariantCulture)); } } catch (Exception) { var form = new FormTimedMessage(2000, gStr.gsFieldFileIsCorrupt, gStr.gsChooseADifferentField); } } distance = Math.Pow((latStart - mf.pn.latitude), 2) + Math.Pow((lonStart - mf.pn.longitude), 2); distance = Math.Sqrt(distance); distance *= 100; fileList.Add(fieldDirectory); fileList.Add(distance.ToString("00.##")); } //grab the boundary area filename = dir + "\\Boundary.txt"; if (File.Exists(filename)) { List <vec3> pointList = new List <vec3>(); double area = 0; using (StreamReader reader = new StreamReader(filename)) { try { //read header line = reader.ReadLine();//Boundary if (!reader.EndOfStream) { //True or False OR points from older boundary files line = reader.ReadLine(); //Check for older boundary files, then above line string is num of points if (line == "True" || line == "False") { line = reader.ReadLine(); //number of points } //Check for latest boundary files, then above line string is num of points if (line == "True" || line == "False") { line = reader.ReadLine(); //number of points } int numPoints = int.Parse(line); if (numPoints > 0) { //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)); pointList.Add(vecPt); } int ptCount = pointList.Count; if (ptCount > 5) { 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 += (pointList[j].easting + pointList[i].easting) * (pointList[j].northing - pointList[i].northing); } if (mf.isMetric) { area = (Math.Abs(area / 2)) * 0.0001; } else { area = (Math.Abs(area / 2)) * 0.00024711; } } } } } catch (Exception) { area = 0; } } fileList.Add(area.ToString("000.#")); } filename = dir + "\\Field.txt"; } for (int i = 0; i < fileList.Count; i += 3) { string[] fieldNames = { fileList[i], fileList[i + 1], fileList[i + 2] }; itm = new ListViewItem(fieldNames); lvLines.Items.Add(itm); } //string fieldName = Path.GetDirectoryName(dir).ToString(CultureInfo.InvariantCulture); if (lvLines.Items.Count > 0) { this.chName.Text = "Field Name"; this.chName.Width = 680; this.chDistance.Text = "Distance"; this.chDistance.Width = 140; this.chArea.Text = "Area"; this.chArea.Width = 140; } else { //var form2 = new FormTimedMessage(2000, gStr.gsNoFieldsCreated, gStr.gsCreateNewFieldFirst); //form2.Show(); } }
private void FormABLine_Load(object sender, EventArgs e) { lvLines.Visible = false; label2.Visible = false; label3.Visible = false; lblEnterName.Visible = false; tboxABLineName.Visible = false; nudBasedOnPass.Visible = false; nudTramRepeats.Visible = false; btnListDelete.Visible = false; btnListUse.Visible = false; btnAddToFile.Visible = false; btnShow.Text = gStr.gsShow; btnShow.Image = Properties.Resources.ArrowLeft; //small window this.Size = new System.Drawing.Size(304, 510); //different start based on AB line already set or not if (mf.ABLine.isABLineSet) { //AB line is on screen and set btnAPoint.Enabled = false; btnBPoint.Enabled = true; upDnHeading = Math.Round(glm.toDegrees(mf.ABLine.abHeading), 6); nudTramRepeats.Value = mf.ABLine.tramPassEvery; nudBasedOnPass.Value = mf.ABLine.passBasedOn; this.tboxHeading.TextChanged -= new System.EventHandler(this.tboxHeading_TextChanged); tboxHeading.Text = upDnHeading.ToString(CultureInfo.InvariantCulture); this.tboxHeading.TextChanged += new System.EventHandler(this.tboxHeading_TextChanged); } else { //no AB line btnAPoint.Enabled = true; btnBPoint.Enabled = false; btnABLineOk.Enabled = false; upDnHeading = Math.Round(glm.toDegrees(mf.fixHeading), 6); nudTramRepeats.Value = 0; nudBasedOnPass.Value = 0; mf.ABLine.tramPassEvery = 0; mf.ABLine.passBasedOn = 0; } //make sure at least a global blank AB Line file exists string dirField = mf.fieldsDirectory + mf.currentFieldDirectory + "\\"; string directoryName = Path.GetDirectoryName(dirField).ToString(CultureInfo.InvariantCulture); if ((directoryName.Length > 0) && (!Directory.Exists(directoryName))) { Directory.CreateDirectory(directoryName); } filename = directoryName + "\\ABLines.txt"; if (!File.Exists(filename)) { using (StreamWriter writer = new StreamWriter(filename)) { } } if (!File.Exists(filename)) { mf.TimedMessageBox(2000, gStr.gsFileError, gStr.gsMissingABLinesFile); } else { using (StreamReader reader = new StreamReader(filename)) { try { string line; ListViewItem itm; //read all the lines while (!reader.EndOfStream) { line = reader.ReadLine(); string[] words = line.Split(','); //listboxLines.Items.Add(line); itm = new ListViewItem(words); lvLines.Items.Add(itm); //coords.easting = double.Parse(words[0], CultureInfo.InvariantCulture); //coords.northing = double.Parse(words[1], CultureInfo.InvariantCulture); //youFileList.Add(coords); } } catch (Exception er) { var form = new FormTimedMessage(2000, "ABLine File is Corrupt", "Please delete it!!!"); form.Show(); mf.WriteErrorLog("FieldOpen, Loading ABLine, Corrupt ABLine File" + er); } } // go to bottom of list - if there is a bottom if (lvLines.Items.Count > 0) { lvLines.Items[lvLines.Items.Count - 1].EnsureVisible(); } } }