Example #1
0
        protected void AddTraverseInfoToGrid(IGSPlan Plan, DataGridView TraverseGrid, List <IVector3D> Traverse,
                                             List <IVector3D> AdjustedTraverse, List <string> FromToList)
        {
            ICadastralUnitConversion pCadUnitConverter = new CadastralUnitConversionClass();
            double            dMetersPerUnit           = pCadUnitConverter.ConvertDouble(1, Plan.DistanceUnits, esriCadastralDistanceUnits.esriCDUMeter);
            IAngularConverter pAngConv = new AngularConverterClass();
            Utilities         Utils    = new Utilities();

            List <string> lstAdjustedCourses = new List <string>();
            List <string> lstResiduals       = new List <string>();

            foreach (IVector3D vect in AdjustedTraverse)
            {
                pAngConv.SetAngle(vect.Azimuth, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);

                int iPrec = 7;
                if (Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds)
                {
                    iPrec = 0;
                }
                string sBearing  = pAngConv.GetString(Plan.DirectionFormat, Plan.AngleUnits, iPrec);
                string sAdjusted = Utils.FormatDirectionDashesToDegMinSecSymbols(sBearing) + ", " + (vect.Magnitude / dMetersPerUnit).ToString("0.000");

                lstAdjustedCourses.Add(sAdjusted);
            }

            int i = 0;

            foreach (IVector3D vect in Traverse)
            {
                pAngConv.SetAngle(vect.Azimuth, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);

                int iPrec = 7;
                if (Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds)
                {
                    iPrec = 0;
                }
                string sBearing     = pAngConv.GetString(Plan.DirectionFormat, Plan.AngleUnits, iPrec);
                string sDescription = Utils.FormatDirectionDashesToDegMinSecSymbols(sBearing) + ", " + (vect.Magnitude / dMetersPerUnit).ToString("0.000");

                string sDistResidual = ((vect.Magnitude - AdjustedTraverse[i].Magnitude) / dMetersPerUnit).ToString("0.000");

                //get the angle difference between the vectors
                IVector3D vec1 = new Vector3DClass();
                vec1.PolarSet(vect.Azimuth, 0, 1);

                IVector3D vec2 = new Vector3DClass();
                vec2.PolarSet(AdjustedTraverse[i].Azimuth, 0, 1);

                double dAngleDifference = Math.Acos(vec1.DotProduct(vec2));
                pAngConv.SetAngle(dAngleDifference, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians);
                string sAngResidual = pAngConv.GetString(esriDirectionType.esriDTPolar, Plan.AngleUnits, iPrec);
                sAngResidual = Utils.FormatDirectionDashesToDegMinSecSymbols(sAngResidual);

                TraverseGrid.Rows.Add(FromToList[i], sDescription, lstAdjustedCourses[i], sAngResidual + ", " + sDistResidual);
                i++;
            }
        }
Example #2
0
        private void btnAddToEditor_Click(object sender, EventArgs e)
        {
            if (tools.utils.IsNumeric(txtConvergence.Text) == false)
            {
                MessageBox.Show("The convergence angle is not valid.");
                return;
            }

            IEditProperties2 pEditProps = (IEditProperties2)m_pEditor;
            pEditProps.UseGroundToGrid = true;
            //pEditProps.DirectionType = ESRI.ArcGIS.esriSystem.esriDirectionType.esriDTNorthAzimuth;
            //pEditProps.DirectionUnits = ESRI.ArcGIS.esriSystem.esriDirectionUnits.esriDUDecimalDegrees;
            pEditProps.AngularUnitPrecision = 10;

            //The units are in radians so you need to convert them first
            IAngularConverter angularConverter = new AngularConverterClass();
            angularConverter.SetAngle(Convert.ToDouble(txtConvergence.Text), esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDUDecimalDegrees);

            double angRad = angularConverter.GetAngle(esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);

            //angularConverter.SetString("0-0-1", esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDUDegreesMinutesSeconds);
            pEditProps.AngularCorrectionOffset = angularConverter.GetAngle(esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);

            pEditProps.AngularCorrectionOffset = angRad ;

            this.Hide();
        }
        protected void AddTraverseInfoToGrid(IGSPlan Plan, DataGridView TraverseGrid, List<IVector3D> Traverse, 
      List<IVector3D> AdjustedTraverse, List<string> FromToList)
        {
            ICadastralUnitConversion pCadUnitConverter = new CadastralUnitConversionClass();
              double dMetersPerUnit = pCadUnitConverter.ConvertDouble(1, Plan.DistanceUnits, esriCadastralDistanceUnits.esriCDUMeter);
              IAngularConverter pAngConv = new AngularConverterClass();
              Utilities Utils = new Utilities();

              List<string> lstAdjustedCourses = new List<string>();
              List<string> lstResiduals = new List<string>();

              foreach (IVector3D vect in AdjustedTraverse)
              {
            pAngConv.SetAngle(vect.Azimuth, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);

            int iPrec = 7;
            if (Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds)
              iPrec = 0;
            string sBearing = pAngConv.GetString(Plan.DirectionFormat, Plan.AngleUnits, iPrec);
            string sAdjusted = Utils.FormatDirectionDashesToDegMinSecSymbols(sBearing) + ", " + (vect.Magnitude / dMetersPerUnit).ToString("0.000");

            lstAdjustedCourses.Add(sAdjusted);

              }

              int i = 0;

              foreach (IVector3D vect in Traverse)
              {
            pAngConv.SetAngle(vect.Azimuth, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);

            int iPrec = 7;
            if(Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds)
              iPrec=0;
            string sBearing = pAngConv.GetString(Plan.DirectionFormat, Plan.AngleUnits, iPrec);
            string sDescription = Utils.FormatDirectionDashesToDegMinSecSymbols(sBearing) + ", " + (vect.Magnitude/dMetersPerUnit).ToString("0.000");

            string sDistResidual= ((vect.Magnitude-AdjustedTraverse[i].Magnitude)/dMetersPerUnit).ToString("0.000");

            //get the angle difference between the vectors
            IVector3D vec1 = new Vector3DClass();
            vec1.PolarSet(vect.Azimuth, 0, 1);

            IVector3D vec2 = new Vector3DClass();
            vec2.PolarSet(AdjustedTraverse[i].Azimuth, 0, 1);

            double dAngleDifference = Math.Acos(vec1.DotProduct(vec2));
            pAngConv.SetAngle(dAngleDifference, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians);
            string sAngResidual = pAngConv.GetString(esriDirectionType.esriDTPolar, Plan.AngleUnits, iPrec);
            sAngResidual = Utils.FormatDirectionDashesToDegMinSecSymbols(sAngResidual);

            TraverseGrid.Rows.Add(FromToList[i], sDescription, lstAdjustedCourses[i], sAngResidual + ", " + sDistResidual);
            i++;
              }
        }
        private void btnResetDefaults_Click(object sender, EventArgs e)
        {
            optComputeDirnOffset.Checked = true;
            IAngularConverter pAngConv = new AngularConverterClass();

            pAngConv.SetAngle(0, m_EditorProperties.DirectionType, m_EditorProperties.DirectionUnits);
            txtDirectionOffset.Text        = pAngConv.GetString(m_EditorProperties.DirectionType, m_EditorProperties.DirectionUnits, m_EditorProperties.AngularUnitPrecision);
            chkDirectionDifference.Checked = chkSubtendedDistance.Checked = chkReportResults.Checked = true;
            txtDirectionDifference.Text    = "180";
            txtSubtendedDist.Text          = lblDistanceUnits1.Text.ToLower().Contains("meter")? "0.1":"0.3";
        }
        private void btnGetOffsetFromEditor_Click(object sender, EventArgs e)
        {
            if (m_EditorProperties == null)
            {
                return;
            }
            IAngularConverter pAngConv = new AngularConverterClass();
            double            dCorr    = m_EditorProperties.AngularCorrectionOffset;

            pAngConv.SetAngle(dCorr, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);
            string sCorr = pAngConv.GetString(esriDirectionType.esriDTNorthAzimuth, m_EditorProperties.DirectionUnits, m_EditorProperties.AngularUnitPrecision);

            this.txtDirectionOffset.Text = sCorr;
        }
 private void btnResetDefaults_Click(object sender, EventArgs e)
 {
     optComputeDirnOffset.Checked = true;
       IAngularConverter pAngConv = new AngularConverterClass();
       pAngConv.SetAngle(0,m_EditorProperties.DirectionType, m_EditorProperties.DirectionUnits);
       txtDirectionOffset.Text = pAngConv.GetString(m_EditorProperties.DirectionType, m_EditorProperties.DirectionUnits,m_EditorProperties.AngularUnitPrecision);
       chkDirectionDifference.Checked = chkSubtendedDistance.Checked = chkReportResults.Checked = true;
       txtDirectionDifference.Text = "180";
       txtSubtendedDist.Text = lblDistanceUnits1.Text.ToLower().Contains("meter")? "0.1":"0.3";
 }
 private void btnGetOffsetFromEditor_Click(object sender, EventArgs e)
 {
     if (m_EditorProperties == null)
     return;
       IAngularConverter pAngConv = new AngularConverterClass();
       double dCorr = m_EditorProperties.AngularCorrectionOffset;
       pAngConv.SetAngle(dCorr, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);
       string sCorr = pAngConv.GetString(esriDirectionType.esriDTNorthAzimuth, m_EditorProperties.DirectionUnits, m_EditorProperties.AngularUnitPrecision);
       this.txtDirectionOffset.Text = sCorr;
 }
        private void CreateParcelFromSegmentCollection(ISegmentCollection Segments, string PlanName)
        {
            int iCnt = Segments.SegmentCount;

            ISegment[] pSegmentArr = new ISegment[iCnt];
            for (int j = 0; j < iCnt; j++)
            {
                pSegmentArr[j] = Segments.get_Segment(j);
            }

            ICadastralEditor   pCadEd         = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension");
            IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd;

            try
            {
                ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd;
                bool bStartedWithPacketOpen           = pCadPacketMan.PacketOpen;
                if (!bStartedWithPacketOpen)
                {
                    m_editor.StartOperation();
                }

                //1. Start map edit session
                ICadastralMapEdit pCadMapEdit = (ICadastralMapEdit)pCadEd;
                pCadMapEdit.StartMapEdit(esriMapEditType.esriMEEmpty, "NewParcel", false);

                //2.	Get job packet
                ICadastralPacket pCadaPacket = pCadPacketMan.JobPacket;

                //3.	Create Plan (new)
                string sPlanName = PlanName;
                //first check to ensure plan is not already in the database.
                IGSPlan pGSPlan = FindFabricPlanByName(sPlanName, pCadEd);

                if (pGSPlan == null)
                {
                    //if plan is null, it was not found and can be created
                    pGSPlan = new GSPlanClass();
                    // 3.a set values
                    pGSPlan.Accuracy = 4;
                    pGSPlan.Name     = sPlanName;
                }

                //3.b Add the plan to the job packet
                ICadastralPlan pCadaPlan = (ICadastralPlan)pCadaPacket;
                pCadaPlan.AddPlan(pGSPlan);

                //4.	Create Parcel
                ICadastralParcel pCadaParcel  = (ICadastralParcel)pCadaPacket;
                IGSParcel        pNewGSParcel = new GSParcelClass();
                //Make sure that any extended attributes on the parcel have their default values set
                IGSAttributes pGSAttributes = (IGSAttributes)pNewGSParcel;
                if (pGSAttributes != null)
                {
                    ICadastralObjectSetup pCadaObjSetup = (ICadastralObjectSetup)pParcEditorMan;
                    pCadaObjSetup.AddExtendedAttributes(pGSAttributes);
                    pCadaObjSetup.SetDefaultValues(pGSAttributes);
                }

                //4a.	Add the parcel to the packet. (do this before addlines)
                // - This will enable us to Acquire the parcel ID,
                // - Having the parcel attached to the packet allows InsertLine to function.
                pCadaParcel.AddParcel(pNewGSParcel);
                pNewGSParcel.Lot  = "NewParcel";
                pNewGSParcel.Type = 7;
                //4b.	Set Plan (created above)
                IGSPlan thePlan = pCadaPlan.GetPlan(sPlanName);
                pNewGSParcel.Plan = thePlan;
                //4c.	Insert GSLines (from new) into GSParcel
                //4d. To bypass join, you can create GSPoints and assign those point IDs to the GSLines.
                ICadastralPoints     pCadaPoints     = (ICadastralPoints)pCadaPacket;
                IMetricUnitConverter pMetricUnitConv = (IMetricUnitConverter)pCadEd;

                //Set up the initial start point, POB

                IPoint pPt1 = Segments.get_Segment(0).FromPoint;

                IZAware pZAw = (IZAware)pPt1;
                pZAw.ZAware = true;
                pPt1.Z      = 0; //defaulting to 0

                //Convert the point into metric units, and get a new (in-mem) point id
                IGSPoint pGSPointFrom = pMetricUnitConv.SetGSPoint(pPt1);
                pCadaPoints.AddPoint(pGSPointFrom);
                int iID1      = pGSPointFrom.Id;
                int iID1_Orig = iID1;

                int     index   = 0;
                IGSLine pGSLine = null;
                //++++++++++++ Add Courses ++++++++++++++
                int  iID2    = -1;
                bool bIsLoop = (Math.Abs(pPt1.X - Segments.get_Segment(iCnt - 1).ToPoint.X)) < 0.01 &&
                               (Math.Abs(pPt1.Y - Segments.get_Segment(iCnt - 1).ToPoint.Y)) < 0.01;

                IAngularConverter pAngConv = new AngularConverterClass();

                for (int j = 0; j < iCnt; j++)
                {
                    pSegmentArr[j] = Segments.get_Segment(j);

                    double dDir         = 0; //radians north azimuth
                    ILine  pLineOrChord = new LineClass();
                    pLineOrChord.PutCoords(pSegmentArr[j].FromPoint, pSegmentArr[j].ToPoint);

                    if (pAngConv.SetAngle(pLineOrChord.Angle, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians))
                    {
                        dDir = pAngConv.GetAngle(esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);
                    }

                    double dDist         = pLineOrChord.Length;
                    double dRadius       = 0;
                    int    iAccuracy     = -1;
                    int    iUserLineType = -1;
                    int    iCategory     = -1;

                    if (pSegmentArr[j] is ICircularArc)
                    {
                        ICircularArc pCircArc = pSegmentArr[j] as ICircularArc;
                        dRadius = pCircArc.Radius;
                        if (pCircArc.IsCounterClockwise)
                        {
                            dRadius = dRadius * -1;
                        }
                    }
                    bool bComputeToPoint = (bIsLoop && (j < iCnt - 1)) || !bIsLoop;
                    //From, Direction (NAz Radians), Distance (map's projection units), Radius
                    pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1,
                                           iID1, dDir, dDist, dRadius, iAccuracy, iUserLineType, iCategory, bComputeToPoint, out iID2);

                    if (j < iCnt - 1 || !bIsLoop)
                    {
                        iID1 = iID2;
                    }
                    else if ((j == iCnt - 1) && bIsLoop)
                    {
                        pGSLine.ToPoint = iID1_Orig; //closing the traverse back to the POB
                    }
                    iID2 = -1;

                    //Add the line to the new parcel
                    if (pGSLine != null)
                    {
                        pNewGSParcel.InsertLine(++index, pGSLine);
                    }
                }


                //Add radial lines for circular curves
                pNewGSParcel.AddRadialLines();

                // 4.e then set join=true on the parcel.
                pNewGSParcel.Joined = true;

                //let the packet know that a change has been made
                pCadPacketMan.SetPacketModified(true);

                //save the new parcel
                try
                {
                    pCadMapEdit.StopMapEdit(true);
                }
                catch
                {
                    if (!bStartedWithPacketOpen)
                    {
                        m_editor.AbortOperation();
                    }
                    return;
                }
                if (!bStartedWithPacketOpen)
                {
                    m_editor.StopOperation("New Parcel");
                }
                pCadPacketMan.PartialRefresh();
            }
            catch (Exception ex)
            {
                m_editor.AbortOperation();
                MessageBox.Show(ex.Message);
            }
        }
Example #9
0
        protected override void OnClick()
        {
            ICadastralEditor   pCadEd         = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension");
            IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd;

            ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd;

            //bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen;

            if (pParcEditorMan == null)
            {
                return;
            }

            IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");

            if (pEd.EditState == esriEditState.esriStateNotEditing)
            {
                MessageBox.Show("Please start editing and try again.");
                return;
            }

            IParcelConstruction       pConstr                   = pParcEditorMan.ParcelConstruction;
            IParcelConstruction4      pConstr4                  = pConstr as IParcelConstruction4;
            ICadastralPoints          pCadastralPts             = pConstr4 as ICadastralPoints;
            ICadastralEditorSettings2 pCadastralEditorSettings2 = pCadEd as ICadastralEditorSettings2;

            ICadastralFixedPoints pFixedPoints = pCadastralPts as ICadastralFixedPoints;
            IPointCalculation     pPointCalc   = new PointCalculationClass();

            if (pConstr == null)
            {
                return;
            }

            IGSLine pParcelLine = null;
            IMetricUnitConverter pMetricUnitConv = (IMetricUnitConverter)pCadEd;
            IGSPoint             pStartPoint     = null;
            List <int>           lstPointIds     = new List <int>();

            List <IVector3D> Traverse = new List <IVector3D>();

            //get rotation here
            IParcelConstructionData    pConstrData = pConstr4.ConstructionData;
            IConstructionParentParcels pConstructionParentParcels = pConstrData as IConstructionParentParcels;

            ICadastralUndoRedo pCadUndoRedo = pConstr as ICadastralUndoRedo;

            try
            {
                int iParcelID = -1;
                if (pConstructionParentParcels.ParentParcelCount > 0)
                {
                    pConstructionParentParcels.GetParentParcel(0, ref iParcelID);
                }

                ICadastralParcel pCadaParcel = pCadPacketMan.JobPacket as ICadastralParcel;

                IGSParcel pGSParcel = null;

                if (pCadaParcel != null)
                {
                    pGSParcel = pCadaParcel.GetParcel(iParcelID);
                }
                //if in measurement view then rotation is 0
                double TheRotation = 0;

                if (pGSParcel == null)
                {
                    pGSParcel = pConstr.Parcel;
                }

                if (!pCadastralEditorSettings2.MeasurementView)
                {
                    TheRotation = pGSParcel.Rotation;//radians
                }
                if (TheRotation == 123456789)
                {
                    TheRotation = 0;
                }

                pPointCalc.Rotation = TheRotation;
                IGSPoint pClosingPoint = null;

                #region simple method as fall-back
                bool bUseSimpleStackSelection = false;
                if (bUseSimpleStackSelection)
                {
                    //bool bLineSelectionSequence = false;
                    //IGSLine pLastSelectedGSLineInGrid = null;
                    //for (int i = 0; i < pConstr.LineCount; i++)
                    //{
                    //  if (pConstr.GetLineSelection(i))
                    //  {
                    //    if (pConstr.GetLine(i, ref pParcelLine))
                    //    {
                    //      if (!bLineSelectionSequence) //first line
                    //      {
                    //        pStartPoint = pCadastralPts.GetPoint(pParcelLine.FromPoint);
                    //        pToPoint = pCadastralPts.GetPoint(pParcelLine.ToPoint);
                    //      }

                    //      pPointCalc.AddLine(pParcelLine);

                    //      pLastSelectedGSLineInGrid = pParcelLine;
                    //      pToPoint = pCadastralPts.GetPoint(pParcelLine.ToPoint);
                    //      lstPointIds.Add(pToPoint.Id);

                    //    }
                    //    bLineSelectionSequence = true;

                    //    double dBear = pParcelLine.Bearing; //Azimuth of IVector3D is north azimuth radians zero degrees north
                    //    double dDist = pParcelLine.Distance;
                    //    IVector3D vec = new Vector3DClass();
                    //    vec.PolarSet(dBear, 0, dDist); ////Azimuth of IVector3D is north azimuth radians zero degrees north
                    //    Traverse.Add(vec);
                    //  }
                    //  else
                    //  {
                    //    if (bLineSelectionSequence && pConstr.GetLine(i, ref pParcelLine) && HasLineSelectionAfter(pConstr, i))
                    //    //if there was a prior selection and this line is a complete line, and there is no later selection
                    //    {
                    //      MessageBox.Show("Please select a continuous set of lines for closure.");
                    //      return;
                    //    }
                    //  }
                    //}
                    //pClosingPoint = pCadastralPts.GetPoint(pLastSelectedGSLineInGrid.ToPoint);
                }
                else
                #endregion

                {//build a forward star for the selected lines
                    IEnumCELines pCELines     = new EnumCELinesClass();
                    IEnumGSLines pEnumGSLines = (IEnumGSLines)pCELines;
                    ILongArray   pLongArray   = new LongArrayClass();
                    int          iFirstToNode = -1;
                    for (int i = 0; i < pConstr.LineCount; i++)
                    {
                        if (pConstr.GetLineSelection(i))
                        {
                            if (pConstr.GetLine(i, ref pParcelLine))
                            {
                                if (iFirstToNode < 0)
                                {
                                    iFirstToNode = pParcelLine.ToPoint;
                                }
                                pLongArray.Add(i);
                                pCELines.Add(pParcelLine);
                            }
                        }
                    }

                    if (pCELines.Count == 0)
                    {
                        MessageBox.Show("No lines selected. Please select a continuous set of lines for closure." + Environment.NewLine +
                                        "Line selection should not have branches.", "Traverse");
                        return;
                    }

                    IParcelLineFunctions3 ParcelLineFx = new ParcelFunctionsClass();
                    IGSForwardStar        pFwdStar     = ParcelLineFx.CreateForwardStar(pEnumGSLines);
                    //forward star object is now created for all the selected lines,
                    //need to first re-sequence the lines, and test for branching and discontinuity

                    int           iBranches = 0; int iTracedLines = 0;
                    int           iLoops = 0; int iTerminals = 0;
                    List <int>    LineIDList = new List <int>();
                    List <int>    FromList   = new List <int>();
                    List <int>    ToList     = new List <int>();
                    List <string> FromToLine = new List <string>();

                    bool bTraceSucceeded = TraceLines(ref pFwdStar, iFirstToNode, ref iBranches, ref iTracedLines,
                                                      ref iLoops, ref iTerminals, ref FromToLine, ref FromList, ref ToList, 0);

                    if (iBranches > 0)
                    {
                        MessageBox.Show("Please select a continuous set of lines for closure." + Environment.NewLine +
                                        "Line selection should not have branches.", "Traverse");
                        return;
                    }

                    if (iTracedLines < pLongArray.Count)
                    {
                        MessageBox.Show("Please select a continuous set of lines for closure." + Environment.NewLine +
                                        "Selected Lines should be connected in a single sequence without branches.", "Traverse");
                        return;
                    }

                    //if it's a single loop check to see if the sequence needs to be reversed
                    //CW or CCW based on bearings
                    if (iLoops == 1)
                    {
                        bool bIsReversed = false;
                        foreach (int i in FromList)
                        {
                            if (i < 0)
                            {
                                bIsReversed = true;
                            }
                            else
                            {
                                bIsReversed = false;
                                break;
                            }
                        }
                        if (bIsReversed)
                        {//all courses are running reversed, so reverse the whole sequence
                            FromToLine.Clear();
                            FromList.Reverse();
                            ToList.Reverse();
                            int    iNewFrom   = -ToList[ToList.Count - 1];
                            int    iNewTo     = -FromList[ToList.Count - 1];
                            string sNewFromTo = iNewFrom.ToString() + "," + iNewTo.ToString();
                            FromToLine.Add(sNewFromTo);
                            for (int i = 1; i < ToList.Count; i++)
                            {
                                iNewFrom   = -ToList[i - 1];
                                iNewTo     = -FromList[i - 1];
                                sNewFromTo = iNewFrom.ToString() + "," + iNewTo.ToString();
                                FromToLine.Add(sNewFromTo);
                            }
                        }
                    }

                    LineIDList.Clear();
                    FromList.Clear();
                    ToList.Clear();
                    pLongArray.RemoveAll();

                    pCadUndoRedo.StartUndoRedoSession("Adjust Traverse");

                    if (iLoops == 0)
                    {
                        //re-sequence using TraceLines function based on either end point, because the order of
                        //selected construction lines in grid don't control start or end point
                        FromToLine.Clear();
                        int iTerminus = -1;
                        iTracedLines = 0;
                        iBranches    = 0;
                        iLoops       = 0; iTerminals = 0;
                        FindTerminusForSequence(ref pFwdStar, iFirstToNode, ref iTerminus, 0);
                        if (iTerminus == -1)
                        {
                            pCadUndoRedo.WriteUndoRedoSession(false);
                            return;
                        }
                        TraceLines(ref pFwdStar, iTerminus, ref iBranches, ref iTracedLines, ref iLoops, ref iTerminals,
                                   ref FromToLine, ref FromList, ref ToList, 0);
                    }

                    List <IVector3D> SequencedTraverse = new List <IVector3D>();
                    IGSLine          pGSLineInPath     = null;
                    foreach (string s in FromToLine)
                    {
                        string[] sFromTo = s.Split(',');
                        int      iFrom   = Convert.ToInt32(sFromTo[0]);
                        int      iTo     = Convert.ToInt32(sFromTo[1]);

                        bool bReversed = pFwdStar.GetLine(iFrom, iTo, ref pGSLineInPath);
                        if (bReversed)
                        {
                            IGSLine pGSLine180 = new GSLineClass();
                            pGSLine180.FromPoint = pGSLineInPath.ToPoint;
                            pGSLine180.ToPoint   = pGSLineInPath.FromPoint;
                            pGSLine180.Bearing   = pGSLineInPath.Bearing + Math.PI;
                            pGSLine180.Distance  = pGSLineInPath.Distance;

                            IVector3D vec180 = new Vector3DClass();
                            vec180.PolarSet(pGSLine180.Bearing, 0, pGSLine180.Distance); //Azimuth of IVector3D is north azimuth radians zero degrees north
                            Traverse.Add(vec180);
                            lstPointIds.Add(pGSLine180.ToPoint);
                            pPointCalc.AddLine(pGSLine180);
                        }
                        else
                        {
                            double    dBear = pGSLineInPath.Bearing;
                            double    dDist = pGSLineInPath.Distance;
                            IVector3D vec   = new Vector3DClass();
                            vec.PolarSet(dBear, 0, dDist); //Azimuth of IVector3D is north azimuth radians zero degrees north
                            Traverse.Add(vec);
                            lstPointIds.Add(pGSLineInPath.ToPoint);
                            pPointCalc.AddLine(pGSLineInPath);
                        }

                        if (pStartPoint == null)
                        {
                            if (bReversed)
                            {
                                pStartPoint = pCadastralPts.GetPoint(pGSLineInPath.ToPoint);
                            }
                            else
                            {
                                pStartPoint = pCadastralPts.GetPoint(pGSLineInPath.FromPoint);
                            }
                        }

                        if (bReversed)
                        {
                            pClosingPoint = pCadastralPts.GetPoint(pGSLineInPath.FromPoint);
                        }
                        else
                        {
                            pClosingPoint = pCadastralPts.GetPoint(pGSLineInPath.ToPoint);
                        }
                    }
                }

                if (pStartPoint == null)
                {
                    pCadUndoRedo.WriteUndoRedoSession(false);
                    return;
                }
                IPoint pStart = new PointClass();
                pStart.X = pStartPoint.X;
                pStart.Y = pStartPoint.Y;

                string sAdjustMethod = "Compass";
                esriParcelAdjustmentType eAdjMethod = esriParcelAdjustmentType.esriParcelAdjustmentCompass;

                if (pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentNone ||
                    pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentCompass)
                {
                    eAdjMethod = esriParcelAdjustmentType.esriParcelAdjustmentCompass;
                }
                else if (pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentCrandall)
                {
                    sAdjustMethod = "Crandall";
                    eAdjMethod    = pCadastralEditorSettings2.ParcelAdjustment;
                }
                else if (pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentTransit)
                {
                    sAdjustMethod = "Transit";
                    eAdjMethod    = pCadastralEditorSettings2.ParcelAdjustment;
                }

                pPointCalc.CalculatePoints(eAdjMethod, pStartPoint.Id, pStartPoint, pClosingPoint.Id, pClosingPoint, true);
                ITraverseClosure pClose = pPointCalc.Closure;
                List <string>    lstCoursesFromTo = new List <string>();
                List <IVector3D> AdjustedTraverse = new List <IVector3D>();
                double           dAdjustedPointX = 0; double dAdjustedPointY = 0;
                double           dPreviousPointX = 0; double dPreviousPointY = 0;

                for (int i = 0; i < pClose.CourseCount; i++)
                {
                    IGSPoint pPt = pCadastralPts.GetPoint(lstPointIds[i]);
                    dAdjustedPointY = pPointCalc.GetCalculatedPoint(lstPointIds[i], ref dAdjustedPointX);
                    string    sFromTo       = "";
                    IVector3D pAdjustedLine = new Vector3DClass();
                    if (i == 0)
                    {
                        sFromTo = pStartPoint.Id.ToString() + "-" + lstPointIds[i].ToString();
                        pAdjustedLine.SetComponents(dAdjustedPointX - pStartPoint.X, dAdjustedPointY - pStartPoint.Y, 0);
                    }
                    else
                    {
                        sFromTo = lstPointIds[i - 1].ToString() + "-" + lstPointIds[i].ToString();
                        pAdjustedLine.SetComponents(dAdjustedPointX - dPreviousPointX, dAdjustedPointY - dPreviousPointY, 0);
                    }
                    lstCoursesFromTo.Add(sFromTo);

                    IVector3D Z_Axis = new Vector3DClass();
                    Z_Axis.SetComponents(0, 0, 100);

                    pAdjustedLine.Rotate(TheRotation, Z_Axis);
                    AdjustedTraverse.Add(pAdjustedLine);

                    dPreviousPointX = dAdjustedPointX;
                    dPreviousPointY = dAdjustedPointY;

                    pPt.X = dAdjustedPointX;
                    pPt.Y = dAdjustedPointY;

                    if (!pCadastralEditorSettings2.MeasurementView)
                    {
                        pFixedPoints.SetFixedPoint(lstPointIds[i], true);
                    }
                }

                double  dMisclosureDistance = pClose.MisclosureDistance; double dMisclosureBearing = pClose.MisclosureDirection;
                IVector MiscloseVector = new Vector3DClass();

                IEditProperties2 pEdProps = pEd as IEditProperties2;

                IAngularConverter pAngConv = new AngularConverterClass();
                pAngConv.SetAngle(dMisclosureBearing, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);
                //int iPrec = 7;
                //if (pConstr.Parcel.Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds)
                //  iPrec = 0;

                string sMiscloseBearing = pAngConv.GetString(pEdProps.DirectionType, pEdProps.DirectionUnits, pEdProps.AngularUnitPrecision);

                Utilities UTIL   = new Utilities();
                string    sRatio = "High Accuracy";

                if (pClose.RelativeErrorRatio < 10000)
                {
                    sRatio = "1:" + pClose.RelativeErrorRatio.ToString("0");
                }

                if (dMisclosureDistance >= 0.001)
                {
                    sMiscloseBearing = UTIL.FormatDirectionDashesToDegMinSecSymbols(sMiscloseBearing);
                }
                else
                {
                    sMiscloseBearing = "----";
                }

                ICadastralUnitConversion pCadUnitConverter = new CadastralUnitConversionClass();
                double dMetersPerUnit = pCadUnitConverter.ConvertDouble(1, pConstr.Parcel.Plan.DistanceUnits, esriCadastralDistanceUnits.esriCDUMeter);

                string sReport = "Closure:" + Environment.NewLine +
                                 "        error:  " + sRatio + Environment.NewLine +
                                 "        distance:  " + (dMisclosureDistance / dMetersPerUnit).ToString("0.000") + Environment.NewLine +
                                 "        bearing:  " + sMiscloseBearing + Environment.NewLine +
                                 "        xdist:  " + (pClose.MisclosureX / dMetersPerUnit).ToString("0.000") + Environment.NewLine +
                                 "        ydist:  " + (pClose.MisclosureY / dMetersPerUnit).ToString("0.000") + Environment.NewLine +
                                 "        courses: " + (pClose.CourseCount) + Environment.NewLine +
                                 Environment.NewLine + "Adjustment:" + Environment.NewLine +
                                 "        method: " + sAdjustMethod;

                dlgTraverseResults dlgTraverseResults = new dlgTraverseResults();
                AddTraverseInfoToGrid(pConstr.Parcel.Plan, dlgTraverseResults.dataGridView1, Traverse, AdjustedTraverse, lstCoursesFromTo);
                dlgTraverseResults.txtMiscloseReport.Text = sReport;
                DialogResult dRes = dlgTraverseResults.ShowDialog();
                if (dRes == DialogResult.Cancel)
                {
                    //since we cancelled, set the points back
                    foreach (int i in lstPointIds)
                    {
                        pFixedPoints.SetFixedPoint(i, false);
                    }
                    pCadUndoRedo.WriteUndoRedoSession(false);
                }
                else
                {
                    pCadUndoRedo.WriteUndoRedoSession(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + "Line number:" + ex.LineNumber().ToString()
                                + " in " + ex.TargetSite.Name, "Traverse");
                pCadUndoRedo.WriteUndoRedoSession(false);
            }
        }
Example #10
0
        private string RadiansToAngularDefaultUnits(double inRadians)
        {
            try
            {
                IAngularConverter pAngularConverter = new AngularConverterClass();
                pAngularConverter.SetAngle(inRadians,esriDirectionType.esriDTPolar,esriDirectionUnits.esriDURadians);

                return pAngularConverter.GetString(m_pEditProp2.DirectionType,m_pEditProp2.DirectionUnits,m_pEditProp2.AngularUnitPrecision);
            }
            catch
            {
                return string.Empty;
            }
        }
        protected override void OnClick()
        {
            IEditor  pEd  = (IEditor)ArcMap.Editor;
            IEditor2 pEd2 = (IEditor2)ArcMap.Editor;

            IEditProperties  pEdProps1 = pEd as IEditProperties;
            IEditProperties2 pEdProps2 = pEd as IEditProperties2;

            IEditSketch2       pSketch2 = ArcMap.Editor as IEditSketch2;
            ISegmentCollection pSegColl = pSketch2.Geometry as ISegmentCollection;

            double dLineDirection = 0;

            ISketchTool sketchTool = ArcMap.Application.CurrentTool.Command as ISketchTool;

            if (sketchTool.Constraint == esriSketchConstraint.esriConstraintAngle)
            {
                dLineDirection = sketchTool.AngleConstraint;
            }
            else
            {
                ILine pRubberBandLine = new LineClass();
                pRubberBandLine.PutCoords(pSketch2.LastPoint, pEd2.Location);
                dLineDirection = pRubberBandLine.Angle;
            }

            IAngularConverter pAngConv = new AngularConverterClass();

            pAngConv.SetAngle(dLineDirection, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians);

            int iSegCnt = pSegColl.SegmentCount;
            dlgSpiralParameters SpiralEntryDialog = new dlgSpiralParameters();

            string sBearing = pAngConv.GetString(pEdProps2.DirectionType, pEdProps2.DirectionUnits, pEdProps2.AngularUnitPrecision);

            SpiralEntryDialog.txtDirection.Text = sBearing;
            //Display the dialog
            DialogResult pDialogResult = SpiralEntryDialog.ShowDialog();

            esriCurveDensifyMethod DensifyMethod = esriCurveDensifyMethod.esriCurveDensifyByAngle; //default
            double dDensifyParameter             = 2 * Math.PI / 180;                              //2 degrees //default

            if (SpiralEntryDialog.optCustomDensification.Checked)
            {
                DensifyMethod = (esriCurveDensifyMethod)SpiralEntryDialog.cboDensificationType.SelectedIndex;
                if (DensifyMethod == esriCurveDensifyMethod.esriCurveDensifyByAngle)
                {
                    dDensifyParameter = Convert.ToDouble(SpiralEntryDialog.numAngleDensification.Value) * Math.PI / 180;
                }
                else
                {
                    if (!Double.TryParse(SpiralEntryDialog.txtDensifyValue.Text, out dDensifyParameter))
                    {
                        dDensifyParameter = 2;
                    }
                }
            }

            if (pDialogResult != DialogResult.OK)
            {
                return;
            }

            if (SpiralEntryDialog.txtStartRadius.Text.ToLower().Trim() == "infinity" && SpiralEntryDialog.txtEndRadius.Text.ToLower().Trim() == "infinity")
            {
                return;
            }


            double dSpiralRadius1 = Double.MaxValue; //default to infinity
            double dFromCurvature = 0;

            if (SpiralEntryDialog.txtStartRadius.Text.ToLower() != "infinity")
            {
                if (Double.TryParse(SpiralEntryDialog.txtStartRadius.Text, out dSpiralRadius1))
                {
                    dFromCurvature = 1 / dSpiralRadius1;
                }
                else
                {
                    return;
                }
            }

            double dSpiralRadius2 = Double.MaxValue; //default to infinity
            double dToCurvature   = 0;

            if (SpiralEntryDialog.txtEndRadius.Text.ToLower() != "infinity")
            {
                if (Double.TryParse(SpiralEntryDialog.txtEndRadius.Text, out dSpiralRadius2))
                {
                    dToCurvature = 1 / dSpiralRadius2;
                }
                else
                {
                    return;
                }
            }

            bool bIsCCW = (dSpiralRadius1 > dSpiralRadius2) ? SpiralEntryDialog.optRight.Checked : SpiralEntryDialog.optLeft.Checked;

            bool bSpecialCaseCircularArc = (dSpiralRadius1 == dSpiralRadius2);

            if (!pAngConv.SetString(SpiralEntryDialog.txtDirection.Text, pEdProps2.DirectionType, pEdProps2.DirectionUnits))
            {
                return;
            }

            double dNorthAzimuthRadians = pAngConv.GetAngle(esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);

            IVector3D pVec = new Vector3DClass();

            pVec.PolarSet(dNorthAzimuthRadians, 0, 500);

            IPoint pTangentPoint = new PointClass();

            pTangentPoint.PutCoords(pSketch2.LastPoint.X + pVec.XComponent, pSketch2.LastPoint.Y + pVec.YComponent);

            //double dStreamingTol = pEdProps1.StreamTolerance;
            //if (dStreamingTol == 0)
            //  dStreamingTol = 0.001 * 5000; //metric

            //double dSpiralOffsetGeometryPrecision = 0.001 * 250; //metric 0.25 m

            IPolyline6 theSpiralPolyLine = null;
            double     dExitTangent      = 0;

            if (SpiralEntryDialog.cboPathLengthParameter.SelectedIndex == 0)
            {
                double dSpiralArcLength;
                if (!Double.TryParse(SpiralEntryDialog.txtPathLengthParameter.Text, out dSpiralArcLength))
                {
                    return;
                }

                if (bSpecialCaseCircularArc)
                {
                    ILine pInTangentLine = new LineClass();
                    pInTangentLine.PutCoords(pSketch2.LastPoint, pTangentPoint);

                    ISegment pTangentSegment = (ISegment)pInTangentLine;
                    IConstructCircularArc2 pCircArcConstr = new ESRI.ArcGIS.Geometry.CircularArcClass() as IConstructCircularArc2;
                    pCircArcConstr.ConstructTangentRadiusArc(pTangentSegment, false, bIsCCW, dSpiralRadius1, dSpiralArcLength);
                    ICircularArc pArcSegment = pCircArcConstr as ICircularArc;

                    //Get chord Line from tangent curve constructor
                    ILine pChordLine = new LineClass();
                    pChordLine.PutCoords(pArcSegment.FromPoint, pArcSegment.ToPoint);
                    double dPolarRadians = pChordLine.Angle; //to get the chord azimuth

                    pCircArcConstr.ConstructBearingRadiusArc(pSketch2.LastPoint, dPolarRadians, bIsCCW, dSpiralRadius1, dSpiralArcLength);

                    dExitTangent = pArcSegment.ToAngle + Math.PI / 2;

                    ISegmentCollection segCollection = new PolylineClass() as ISegmentCollection;
                    object             obj           = Type.Missing;
                    segCollection.AddSegment((ISegment)pArcSegment, ref obj, ref obj);
                    theSpiralPolyLine = segCollection as IPolyline6;
                }
                else
                {
                    theSpiralPolyLine = ConstructSpiralbyLength(pSketch2.LastPoint, pTangentPoint, dFromCurvature, dToCurvature, bIsCCW, dSpiralArcLength,
                                                                DensifyMethod, dDensifyParameter, out dExitTangent);
                }
            }

            if (SpiralEntryDialog.cboPathLengthParameter.SelectedIndex == 1)
            {
                if (!pAngConv.SetString(SpiralEntryDialog.txtPathLengthParameter.Text, esriDirectionType.esriDTPolar, pEdProps2.DirectionUnits))
                {
                    return;
                }
                double dSpiralDeltaAngle = pAngConv.GetAngle(esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians);

                if (bSpecialCaseCircularArc)
                {
                    ILine pInTangentLine = new LineClass();
                    pInTangentLine.PutCoords(pSketch2.LastPoint, pTangentPoint);

                    ISegment pTangentSegment = (ISegment)pInTangentLine;
                    IConstructCircularArc2 pCircArcConstr = new ESRI.ArcGIS.Geometry.CircularArcClass() as IConstructCircularArc2;
                    pCircArcConstr.ConstructTangentRadiusAngle(pTangentSegment, false, bIsCCW, dSpiralRadius1, dSpiralDeltaAngle);
                    ICircularArc pArcSegment = pCircArcConstr as ICircularArc;

                    //Get chord Line from tangent curve constructor
                    ILine pChordLine = new LineClass();
                    pChordLine.PutCoords(pArcSegment.FromPoint, pArcSegment.ToPoint);
                    double dPolarRadians = pChordLine.Angle; //to get the chord azimuth

                    pCircArcConstr.ConstructBearingRadiusAngle(pSketch2.LastPoint, dPolarRadians, bIsCCW, dSpiralRadius1, dSpiralDeltaAngle);

                    dExitTangent = pArcSegment.ToAngle + Math.PI / 2;

                    ISegmentCollection segCollection = new PolylineClass() as ISegmentCollection;
                    object             obj           = Type.Missing;
                    segCollection.AddSegment((ISegment)pArcSegment, ref obj, ref obj);
                    theSpiralPolyLine = segCollection as IPolyline6;
                }
                else
                {
                    theSpiralPolyLine = ConstructSpiralbyDeltaAngle(pSketch2.LastPoint, pTangentPoint, dFromCurvature, dToCurvature, bIsCCW, dSpiralDeltaAngle,
                                                                    DensifyMethod, dDensifyParameter, out dExitTangent);
                }
            }

            if (theSpiralPolyLine == null)
            {
                MessageBox.Show("A spiral could not be created with the entered parameters.");
                return;
            }

            ISegmentCollection pSpiralSegCollection = theSpiralPolyLine as ISegmentCollection;
            //Start a sketch operation and insert the new envelope into the sketch
            ISketchOperation2 sketchOp = new SketchOperationClass();

            sketchOp.Start(ArcMap.Editor);
            sketchOp.MenuString = "Add Spiral";
            pSegColl.AddSegmentCollection(pSpiralSegCollection);
            IGeometry geom = pSegColl as IGeometry;

            pSketch2.Geometry = geom;

            //set the angle constraint to the exit tangent of the spiral
            sketchTool.Constraint      = esriSketchConstraint.esriConstraintAngle;
            sketchTool.AngleConstraint = dExitTangent;

            sketchOp.Finish(ArcMap.Document.ActiveView.Extent, esriSketchOperationType.esriSketchOperationGeneral, null);
        }
Example #12
0
 /// <summary>
 /// Gets the geographic angle from two points.
 /// </summary>
 /// <param name="p1">A point.</param>
 /// <param name="p2">A point.</param>
 /// <returns>Returns the angle.</returns>
 public static double GetGeographicAngleOfTwoPoints(IPoint p1, IPoint p2)
 {
     double angle = 0.0;
     if (IsGeometryValid(p1) && IsGeometryValid(p2))
     {
         angle = AngleOfTwoPoints(p1.Y, p2.Y, p1.X, p2.X);
         if (angle < 0)
             angle = 360 - (((angle * 360) * -1) / (2 * System.Math.PI));
         else
             angle = (angle * 360) / (2 * System.Math.PI);
     }
     IAngularConverter converter = new AngularConverterClass();
     converter.SetAngle(angle, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDUDecimalDegrees);
     return converter.GetAngle(esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDUDecimalDegrees);
 }
        protected override void OnClick()
        {
            ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension");
              IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd;

              ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd;
              //bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen;

              if (pParcEditorMan == null)
            return;

              IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");
              if (pEd.EditState == esriEditState.esriStateNotEditing)
              {
            MessageBox.Show("Please start editing and try again.");
            return;
              }

              IParcelConstruction pConstr = pParcEditorMan.ParcelConstruction;
              IParcelConstruction4 pConstr4 = pConstr as IParcelConstruction4;
              ICadastralPoints pCadastralPts = pConstr4 as ICadastralPoints;
              ICadastralEditorSettings2 pCadastralEditorSettings2 = pCadEd as ICadastralEditorSettings2;

              ICadastralFixedPoints pFixedPoints = pCadastralPts as ICadastralFixedPoints;
              IPointCalculation pPointCalc = new PointCalculationClass();

              if (pConstr == null)
            return;

              IGSLine pParcelLine = null;
              IMetricUnitConverter pMetricUnitConv = (IMetricUnitConverter)pCadEd;
              IGSPoint pStartPoint = null;
              List<int> lstPointIds = new List<int>();

              List<IVector3D> Traverse = new List<IVector3D>();

              //get rotation here
              IParcelConstructionData pConstrData = pConstr4.ConstructionData;
              IConstructionParentParcels pConstructionParentParcels = pConstrData as IConstructionParentParcels;

              ICadastralUndoRedo pCadUndoRedo = pConstr as ICadastralUndoRedo;
              try
              {
            int iParcelID = -1;
            if (pConstructionParentParcels.ParentParcelCount>0)
              pConstructionParentParcels.GetParentParcel(0, ref iParcelID);

            ICadastralParcel pCadaParcel = pCadPacketMan.JobPacket as ICadastralParcel;

            IGSParcel pGSParcel = null;

            if (pCadaParcel != null)
              pGSParcel = pCadaParcel.GetParcel(iParcelID);
            //if in measurement view then rotation is 0
            double TheRotation = 0;

            if (pGSParcel == null)
              pGSParcel = pConstr.Parcel;

            if (!pCadastralEditorSettings2.MeasurementView)
              TheRotation = pGSParcel.Rotation;//radians

            if (TheRotation == 123456789)
              TheRotation = 0;

            pPointCalc.Rotation = TheRotation;
            IGSPoint pClosingPoint = null;

            #region simple method as fall-back
            bool bUseSimpleStackSelection = false;
            if (bUseSimpleStackSelection)
            {
              //bool bLineSelectionSequence = false;
              //IGSLine pLastSelectedGSLineInGrid = null;
              //for (int i = 0; i < pConstr.LineCount; i++)
              //{
              //  if (pConstr.GetLineSelection(i))
              //  {
              //    if (pConstr.GetLine(i, ref pParcelLine))
              //    {
              //      if (!bLineSelectionSequence) //first line
              //      {
              //        pStartPoint = pCadastralPts.GetPoint(pParcelLine.FromPoint);
              //        pToPoint = pCadastralPts.GetPoint(pParcelLine.ToPoint);
              //      }

              //      pPointCalc.AddLine(pParcelLine);

              //      pLastSelectedGSLineInGrid = pParcelLine;
              //      pToPoint = pCadastralPts.GetPoint(pParcelLine.ToPoint);
              //      lstPointIds.Add(pToPoint.Id);

              //    }
              //    bLineSelectionSequence = true;

              //    double dBear = pParcelLine.Bearing; //Azimuth of IVector3D is north azimuth radians zero degrees north
              //    double dDist = pParcelLine.Distance;
              //    IVector3D vec = new Vector3DClass();
              //    vec.PolarSet(dBear, 0, dDist); ////Azimuth of IVector3D is north azimuth radians zero degrees north
              //    Traverse.Add(vec);
              //  }
              //  else
              //  {
              //    if (bLineSelectionSequence && pConstr.GetLine(i, ref pParcelLine) && HasLineSelectionAfter(pConstr, i))
              //    //if there was a prior selection and this line is a complete line, and there is no later selection
              //    {
              //      MessageBox.Show("Please select a continuous set of lines for closure.");
              //      return;
              //    }
              //  }
              //}
              //pClosingPoint = pCadastralPts.GetPoint(pLastSelectedGSLineInGrid.ToPoint);
            }
            else
            #endregion

            {//build a forward star for the selected lines
              IEnumCELines pCELines = new EnumCELinesClass();
              IEnumGSLines pEnumGSLines = (IEnumGSLines)pCELines;
              ILongArray pLongArray = new LongArrayClass();
              int iFirstToNode = -1;
              for (int i = 0; i < pConstr.LineCount; i++)
              {
            if (pConstr.GetLineSelection(i))
            {
              if (pConstr.GetLine(i, ref pParcelLine))
              {
                if (iFirstToNode < 0)
                  iFirstToNode = pParcelLine.ToPoint;
                pLongArray.Add(i);
                pCELines.Add(pParcelLine);
              }
            }
              }

              if (pCELines.Count==0)
              {
            MessageBox.Show("No lines selected. Please select a continuous set of lines for closure." + Environment.NewLine +
              "Line selection should not have branches.", "Traverse");
            return;
              }

              IParcelLineFunctions3 ParcelLineFx = new ParcelFunctionsClass();
              IGSForwardStar pFwdStar = ParcelLineFx.CreateForwardStar(pEnumGSLines);
              //forward star object is now created for all the selected lines,
              //need to first re-sequence the lines, and test for branching and discontinuity

              int iBranches = 0; int iTracedLines = 0;
              int iLoops = 0; int iTerminals = 0;
              List<int> LineIDList = new List<int>();
              List<int> FromList = new List<int>();
              List<int> ToList = new List<int>();
              List<string> FromToLine = new List<string>();

              bool bTraceSucceeded = TraceLines(ref pFwdStar, iFirstToNode, ref iBranches, ref iTracedLines,
            ref iLoops, ref iTerminals, ref FromToLine, ref FromList, ref ToList, 0);

              if (iBranches > 0)
              {
            MessageBox.Show("Please select a continuous set of lines for closure." + Environment.NewLine +
              "Line selection should not have branches.", "Traverse");
            return;
              }

              if (iTracedLines < pLongArray.Count)
              {
            MessageBox.Show("Please select a continuous set of lines for closure." + Environment.NewLine +
              "Selected Lines should be connected in a single sequence without branches.", "Traverse");
            return;
              }

              //if it's a single loop check to see if the sequence needs to be reversed
              //CW or CCW based on bearings
              if (iLoops == 1)
              {
            bool bIsReversed = false;
            foreach (int i in FromList)
            {
              if (i < 0)
                bIsReversed = true;
              else
              {
                bIsReversed = false;
                break;
              }
            }
            if (bIsReversed)
            {//all courses are running reversed, so reverse the whole sequence
              FromToLine.Clear();
              FromList.Reverse();
              ToList.Reverse();
              int iNewFrom = -ToList[ToList.Count-1];
              int iNewTo = -FromList[ToList.Count-1];
              string sNewFromTo = iNewFrom.ToString() + "," + iNewTo.ToString();
              FromToLine.Add(sNewFromTo);
              for (int i =1; i < ToList.Count ;i++)
              {
                iNewFrom = -ToList[i-1];
                iNewTo = -FromList[i-1];
                sNewFromTo = iNewFrom.ToString() + "," + iNewTo.ToString();
                FromToLine.Add(sNewFromTo);
              }
            }
              }

              LineIDList.Clear();
              FromList.Clear();
              ToList.Clear();
              pLongArray.RemoveAll();

              pCadUndoRedo.StartUndoRedoSession("Adjust Traverse");

              if (iLoops == 0)
              {
            //re-sequence using TraceLines function based on either end point, because the order of
            //selected construction lines in grid don't control start or end point
            FromToLine.Clear();
            int iTerminus = -1;
            iTracedLines = 0;
            iBranches = 0;
            iLoops = 0; iTerminals = 0;
            FindTerminusForSequence(ref pFwdStar, iFirstToNode, ref iTerminus, 0);
            if (iTerminus == -1)
            {
              pCadUndoRedo.WriteUndoRedoSession(false);
              return;
            }
            TraceLines(ref pFwdStar, iTerminus, ref iBranches, ref iTracedLines, ref iLoops, ref iTerminals,
              ref FromToLine, ref FromList, ref ToList, 0);
              }

              List<IVector3D> SequencedTraverse = new List<IVector3D>();
              IGSLine pGSLineInPath = null;
              foreach (string s in FromToLine)
              {
            string[] sFromTo = s.Split(',');
            int iFrom = Convert.ToInt32(sFromTo[0]);
            int iTo = Convert.ToInt32(sFromTo[1]);

            bool bReversed = pFwdStar.GetLine(iFrom, iTo, ref pGSLineInPath);
            if (bReversed)
            {
              IGSLine pGSLine180 = new GSLineClass();
              pGSLine180.FromPoint = pGSLineInPath.ToPoint;
              pGSLine180.ToPoint = pGSLineInPath.FromPoint;
              pGSLine180.Bearing = pGSLineInPath.Bearing + Math.PI;
              pGSLine180.Distance = pGSLineInPath.Distance;

              IVector3D vec180 = new Vector3DClass();
              vec180.PolarSet(pGSLine180.Bearing, 0, pGSLine180.Distance); //Azimuth of IVector3D is north azimuth radians zero degrees north
              Traverse.Add(vec180);
              lstPointIds.Add(pGSLine180.ToPoint);
              pPointCalc.AddLine(pGSLine180);
            }
            else
            {
              double dBear = pGSLineInPath.Bearing;
              double dDist = pGSLineInPath.Distance;
              IVector3D vec = new Vector3DClass();
              vec.PolarSet(dBear, 0, dDist); //Azimuth of IVector3D is north azimuth radians zero degrees north
              Traverse.Add(vec);
              lstPointIds.Add(pGSLineInPath.ToPoint);
              pPointCalc.AddLine(pGSLineInPath);
            }

            if (pStartPoint == null)
            {
              if (bReversed)
                pStartPoint = pCadastralPts.GetPoint(pGSLineInPath.ToPoint);
              else
                pStartPoint = pCadastralPts.GetPoint(pGSLineInPath.FromPoint);
            }

            if (bReversed)
              pClosingPoint = pCadastralPts.GetPoint(pGSLineInPath.FromPoint);
            else
              pClosingPoint = pCadastralPts.GetPoint(pGSLineInPath.ToPoint);
              }
            }

            if (pStartPoint == null)
            {
              pCadUndoRedo.WriteUndoRedoSession(false);
              return;
            }
            IPoint pStart = new PointClass();
            pStart.X = pStartPoint.X;
            pStart.Y = pStartPoint.Y;

            string sAdjustMethod = "Compass";
            esriParcelAdjustmentType eAdjMethod = esriParcelAdjustmentType.esriParcelAdjustmentCompass;

            if (pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentNone ||
              pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentCompass)
              eAdjMethod = esriParcelAdjustmentType.esriParcelAdjustmentCompass;
            else if (pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentCrandall)
            {
              sAdjustMethod = "Crandall";
              eAdjMethod = pCadastralEditorSettings2.ParcelAdjustment;
            }
            else if (pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentTransit)
            {
              sAdjustMethod = "Transit";
              eAdjMethod = pCadastralEditorSettings2.ParcelAdjustment;
            }

            pPointCalc.CalculatePoints(eAdjMethod, pStartPoint.Id, pStartPoint, pClosingPoint.Id, pClosingPoint, true);
            ITraverseClosure pClose = pPointCalc.Closure;
            List<string> lstCoursesFromTo = new List<string>();
            List<IVector3D> AdjustedTraverse = new List<IVector3D>();
            double dAdjustedPointX = 0; double dAdjustedPointY = 0;
            double dPreviousPointX = 0; double dPreviousPointY = 0;

            for (int i = 0; i < pClose.CourseCount; i++)
            {
              IGSPoint pPt = pCadastralPts.GetPoint(lstPointIds[i]);
              dAdjustedPointY = pPointCalc.GetCalculatedPoint(lstPointIds[i], ref dAdjustedPointX);
              string sFromTo = "";
              IVector3D pAdjustedLine = new Vector3DClass();
              if (i == 0)
              {
            sFromTo = pStartPoint.Id.ToString() + "-" + lstPointIds[i].ToString();
            pAdjustedLine.SetComponents(dAdjustedPointX - pStartPoint.X, dAdjustedPointY - pStartPoint.Y, 0);
              }
              else
              {
            sFromTo = lstPointIds[i - 1].ToString() + "-" + lstPointIds[i].ToString();
            pAdjustedLine.SetComponents(dAdjustedPointX - dPreviousPointX, dAdjustedPointY - dPreviousPointY, 0);
              }
              lstCoursesFromTo.Add(sFromTo);

              IVector3D Z_Axis = new Vector3DClass();
              Z_Axis.SetComponents(0, 0, 100);

              pAdjustedLine.Rotate(TheRotation, Z_Axis);
              AdjustedTraverse.Add(pAdjustedLine);

              dPreviousPointX = dAdjustedPointX;
              dPreviousPointY = dAdjustedPointY;

              pPt.X = dAdjustedPointX;
              pPt.Y = dAdjustedPointY;

              if (!pCadastralEditorSettings2.MeasurementView)
            pFixedPoints.SetFixedPoint(lstPointIds[i], true);
            }

            double dMisclosureDistance = pClose.MisclosureDistance; double dMisclosureBearing = pClose.MisclosureDirection;
            IVector MiscloseVector = new Vector3DClass();

            IEditProperties2 pEdProps = pEd as IEditProperties2;

            IAngularConverter pAngConv = new AngularConverterClass();
            pAngConv.SetAngle(dMisclosureBearing, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);
            //int iPrec = 7;
            //if (pConstr.Parcel.Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds)
            //  iPrec = 0;

            string sMiscloseBearing = pAngConv.GetString(pEdProps.DirectionType, pEdProps.DirectionUnits, pEdProps.AngularUnitPrecision);

            Utilities UTIL = new Utilities();
            string sRatio = "High Accuracy";

            if (pClose.RelativeErrorRatio < 10000)
              sRatio = "1:" + pClose.RelativeErrorRatio.ToString("0");

            if (dMisclosureDistance >= 0.001)
              sMiscloseBearing = UTIL.FormatDirectionDashesToDegMinSecSymbols(sMiscloseBearing);
            else
              sMiscloseBearing = "----";

            ICadastralUnitConversion pCadUnitConverter = new CadastralUnitConversionClass();
            double dMetersPerUnit = pCadUnitConverter.ConvertDouble(1, pConstr.Parcel.Plan.DistanceUnits, esriCadastralDistanceUnits.esriCDUMeter);

            string sReport = "Closure:" + Environment.NewLine +
              "        error:  " + sRatio + Environment.NewLine +
              "        distance:  " + (dMisclosureDistance / dMetersPerUnit).ToString("0.000") + Environment.NewLine +
              "        bearing:  " + sMiscloseBearing + Environment.NewLine +
              "        xdist:  " + (pClose.MisclosureX / dMetersPerUnit).ToString("0.000") + Environment.NewLine +
              "        ydist:  " + (pClose.MisclosureY / dMetersPerUnit).ToString("0.000") + Environment.NewLine +
              "        courses: " + (pClose.CourseCount) + Environment.NewLine +
              Environment.NewLine + "Adjustment:" + Environment.NewLine +
              "        method: " + sAdjustMethod;

            dlgTraverseResults dlgTraverseResults = new dlgTraverseResults();
            AddTraverseInfoToGrid(pConstr.Parcel.Plan, dlgTraverseResults.dataGridView1, Traverse, AdjustedTraverse, lstCoursesFromTo);
            dlgTraverseResults.txtMiscloseReport.Text = sReport;
            DialogResult dRes = dlgTraverseResults.ShowDialog();
            if (dRes == DialogResult.Cancel)
            {
              //since we cancelled, set the points back
              foreach (int i in lstPointIds)
            pFixedPoints.SetFixedPoint(i, false);
              pCadUndoRedo.WriteUndoRedoSession(false);
            }
            else
              pCadUndoRedo.WriteUndoRedoSession(true);
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.Message + Environment.NewLine + "Line number:" + ex.LineNumber().ToString()
              + " in " + ex.TargetSite.Name, "Traverse");
            pCadUndoRedo.WriteUndoRedoSession(false);
              }
        }
        void distanceAngle_Disposed(object sender, EventArgs e)
        {
            if (_isDistAngleFormDisposed) return;

            double x = 0, y = 0;
            IPoint anchor = new PointClass();
            if (_segmentCollection.SegmentCount > 0)
            {
                try
                {
                    ISegment seg = _segmentCollection.get_Segment(_segmentCollection.SegmentCount - 1);
                    x = seg.ToPoint.X;
                    y = seg.ToPoint.Y;
                }
                catch
                {
                }
            }
            else
            {
                x = _initialAnchorPoint.X;
                y = _initialAnchorPoint.Y;
            }

            if (x > 0 && y > 0 && _distance > 10)
            {
                anchor.X = x;
                anchor.Y = y;
                IAngularConverter converter = new AngularConverterClass();
                esriDirectionType dt = ((IEditProperties2)ExtensionInfo.Editor).DirectionType;// GISApplication.EditorDirectionType();
                esriDirectionUnits ut = ((IEditProperties2)ExtensionInfo.Editor).DirectionUnits;// GISApplication.EditorDirectionUnit();
                converter.SetAngle(_angle, esriDirectionType.esriDTPolar, ut);
                _angle = converter.GetAngle(dt, ut);
                IConstructPoint newPoint = new PointClass();
                double radians = DisplayMap.DegreesToRadians(_angle);
                newPoint.ConstructAngleDistance(anchor, radians, _distance);
                ProcessSegment((IPoint)newPoint);
            }

            _isDistAngleFormDisposed = true;
        }
        void conAngle_TextChanged(object sender, EventArgs e)
        {
            double angle = ((NumericTextBox)sender).DoubleValue;
            IAngularConverter converter = new AngularConverterClass();
            esriDirectionType dt = ((IEditProperties2)ExtensionInfo.Editor).DirectionType;
            esriDirectionUnits ut = ((IEditProperties2)ExtensionInfo.Editor).DirectionUnits;
            converter.SetAngle(angle, esriDirectionType.esriDTPolar, ut);
            angle = converter.GetAngle(dt, ut);
            _constrainedAngle = DisplayMap.DegreesToRadians(angle);
            // newPoint.ConstructAngleDistance(anchor, radians, _distance);

            //  IAngularConverter converter = new AngularConverterClass();
            // converter.SetAngle(angle, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians);
            //  angle = converter.GetAngle(esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);
            // _constrainedAngle = Mathmatics.RadiansToDegrees(angle);
        }