示例#1
0
        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;
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        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(100);
                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();
            }
        }
示例#4
0
        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();
                }

                //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 = "Drive - " + mf.currentFieldDirectory;
            }

            DialogResult = DialogResult.OK;
            Close();
        }