示例#1
0
        // Uses Geometric Network to find connected edges which determine desired rotation of point

        public Nullable <double> GetRotationUsingConnectedEdges(IFeature inFeature)
        {
            Nullable <double> rotationAngle = null;

            if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                try
                {
                    // double diameter = -1;
                    List <double>  angles         = new List <double>();
                    List <double>  diameters      = new List <double>();
                    List <Boolean> flipDirections = new List <Boolean>();

                    IPoint      pnt         = (ESRI.ArcGIS.Geometry.IPoint)inFeature.ShapeCopy;
                    IMxDocument pMxDoc      = (IMxDocument)_app.Document;
                    double      snapdistnet = Globals.ConvertPixelsToMap(2, pMxDoc.FocusMap);


                    // IMxDocument pMxDoc = (IMxDocument)_app.Document;
                    // VBRotate rotFunc = new VBRotate();
                    Rotate rotFunc = new Rotate();

                    if (!(inFeature is INetworkFeature))
                    {
                        rotationAngle = rotFunc.RotatePoint(pMxDoc.FocusMap, inFeature, m_rotationType == esriSymbolRotationType.esriRotateSymbolArithmetic, m_diameterFieldName, m_onlyLayerName);
                    }
                    else
                    {
                        rotationAngle = rotFunc.RotatePointByNetwork(pMxDoc.FocusMap, (INetworkFeature)inFeature, m_rotationType == esriSymbolRotationType.esriRotateSymbolArithmetic, m_diameterFieldName, m_onlyLayerName);
                    }

                    //else
                    //{
                    //    INetworkAnalysisExt pNetAnalysisExt;
                    //    UID pUID = new UIDClass();
                    //    pUID.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
                    //    pNetAnalysisExt = (INetworkAnalysisExt)_app.FindExtensionByCLSID(pUID);

                    //    INetworkFeature netFeat = (INetworkFeature)inFeature;
                    //    ISimpleJunctionFeature simpleJunctionFeature = (ISimpleJunctionFeature)netFeat;
                    //    INetworkClass netClass = (INetworkClass)inFeature.Class;
                    //    IGeometricNetwork geomNetwork = (IGeometricNetwork)netClass.GeometricNetwork;
                    //    INetwork network = (INetwork)geomNetwork.Network;
                    //    INetElements netElements = (INetElements)network;

                    //    IFeatureClass fc = null;
                    //    IFeature feat = null;
                    //    IGeometry geometry = null;
                    //    IPolyline polyline = null;
                    //    ISegmentCollection segmentCollection = null;
                    //    ISegmentCollection segColTest = null;
                    //    ISegment testSegment = null;
                    //    // IEnumSegment enumSegment = null;
                    //    System.Object edgeWeight;
                    //    Boolean edgeOrient;
                    //    //int partIndex = 0;
                    //    //int segmentIndex = 0;
                    //    int edgesCount;
                    //    int edgeEID;
                    //    int classId; int userId; int subId;
                    //    int posField; double angle;
                    //    object Missing = Type.Missing;

                    //    IPoint toPoint, fromPoint;
                    //    //ITopologicalOperator topoOp = null ;
                    //    //IPolygon poly = null;

                    //    IForwardStarGEN forwardStar = (IForwardStarGEN)network.CreateForwardStar(false, null, null, null, null);
                    //    forwardStar.FindAdjacent(0, simpleJunctionFeature.EID, out edgesCount);

                    //    if (edgesCount == 0)
                    //    {
                    //        if (simpleJunctionFeature == null)
                    //            return null;
                    //        if (simpleJunctionFeature.EdgeFeatureCount <= 0)
                    //            return null;
                    //        for (int i = 0; i < simpleJunctionFeature.EdgeFeatureCount; i++)
                    //        {
                    //            IEdgeFeature edgeFeat = null;
                    //            try
                    //            {
                    //                edgeFeat = simpleJunctionFeature.get_EdgeFeature(i);
                    //            }
                    //            catch
                    //            {

                    //                MessageBox.Show("GetRotationUsingConnectedEdge:  Not an edge feature");
                    //            }


                    //            try
                    //            {
                    //                polyline = (IPolyline5)edgeFeat.get_GeometryForEdgeElement(0);
                    //            }
                    //            catch
                    //            {

                    //                MessageBox.Show("GetRotationUsingConnectedEdge:  Not a polyline");
                    //            }


                    //            IHitTest pHt = (IHitTest)polyline;
                    //            //double pHitDist = -1;
                    //            //int pHitPrt = -1;
                    //            //int pHitSeg = -1;
                    //            //bool pHitSide = false;
                    //            IPoint pHitPnt = new PointClass();
                    //            // IPoint pHit = new Point();
                    //            System.Double hitDistance = 0;
                    //            System.Int32 hitPartIndex = 0;
                    //            System.Int32 hitSegmentIndex = 0;
                    //            System.Boolean rightSide = false;



                    //            System.Boolean foundGeometry = pHt.HitTest(pnt, pNetAnalysisExt.SnapTolerance * 2,
                    //                ESRI.ArcGIS.Geometry.esriGeometryHitPartType.esriGeometryPartBoundary,
                    //                pHitPnt, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref
                    //                rightSide);


                    //            //pHt.HitTest(pnt, pNetAnalysisExt.SnapTolerance * 2, esriGeometryHitPartType.esriGeometryPartBoundary, pHitPnt, dht, lPart, lVertex, ref bright);


                    //            if (foundGeometry)
                    //            {
                    //                ESRI.ArcGIS.Geometry.IGeometryCollection geometryCollection_Polyline = (ESRI.ArcGIS.Geometry.IGeometryCollection)polyline;
                    //                ESRI.ArcGIS.Geometry.IGeometry geoFound = geometryCollection_Polyline.get_Geometry(hitPartIndex);
                    //                IPath pPath = geoFound as IPath;



                    //                segmentCollection = (ISegmentCollection)pPath;

                    //                testSegment = segmentCollection.get_Segment(hitSegmentIndex);

                    //                try
                    //                {
                    //                    angle = GetAngleOfSegment(testSegment);
                    //                }
                    //                catch
                    //                {
                    //                    angle = -1;
                    //                    MessageBox.Show("GetRotationUsingConnectedEdge:  Error Getting Angle");
                    //                }

                    //                toPoint = testSegment.ToPoint;
                    //                //  foPoint = testSegment.ToPoint;
                    //                segColTest = new PolylineClass();
                    //                segColTest.AddSegment(testSegment, ref Missing, ref Missing);
                    //                IRelationalOperator2 relOp;

                    //                relOp = toPoint as IRelationalOperator2;
                    //                ITopologicalOperator topoOp;
                    //                IPolygon poly;
                    //                topoOp = pnt as ITopologicalOperator;

                    //                poly = topoOp.Buffer(pNetAnalysisExt.SnapTolerance * 2) as IPolygon;
                    //                //    poly = topoOp.Buffer(snapdistnet) as IPolygon;
                    //                if (relOp.Touches(poly))
                    //                {
                    //                    flipDirections.Add(relOp.Contains(pnt));
                    //                    if (diameter >= 0)
                    //                    {
                    //                        diameters.Add(diameter);
                    //                    }
                    //                }
                    //                angles.Add(angle);

                    //            }

                    //        }
                    //    }
                    //    else
                    //    {
                    //        for (int i = 0; i < edgesCount; i++)
                    //        {

                    //            forwardStar.QueryAdjacentEdge(i, out edgeEID, out edgeOrient, out edgeWeight);

                    //            try
                    //            {
                    //                geometry = geomNetwork.get_GeometryForEdgeEID(edgeEID);
                    //            }
                    //            catch (Exception ex)
                    //            {
                    //                netElements.QueryIDs(edgeEID, esriElementType.esriETEdge, out classId, out userId, out subId);
                    //                fc = GetFeatureClassByClassId(classId, geomNetwork);
                    //                MessageBox.Show("Error getting Edge Geometry\n" +
                    //                                "Edge EID is " + edgeEID + "\n" +
                    //                                fc.AliasName + " with Object ID of " + userId + "\n" +
                    //                                 inFeature.Class.AliasName + " with Object ID:" + inFeature.OID + "\n" + ex.Message +
                    //                                 "\n-------------------------\n" +
                    //                                 "If the error says no Geometric newtork, it probably should say\n" +
                    //                                "The edge feature has the same from and to junction feature - delete network element and rebuild connectivity\n");
                    //                continue;
                    //            }
                    //            // IEdgeFeature edgeFeat = null;
                    //            try
                    //            {
                    //                polyline = (IPolyline5)geometry;
                    //            }
                    //            catch
                    //            {
                    //                polyline = null;
                    //                MessageBox.Show("GetRotationUsingConnectedEdge:  error casting to polyline");
                    //            }



                    //            //Special case for reducer
                    //            if (m_useDiameter & (edgesCount == 2))
                    //            {
                    //                netElements.QueryIDs(edgeEID, esriElementType.esriETEdge, out classId, out userId, out subId);
                    //                fc = GetFeatureClassByClassId(classId, geomNetwork);
                    //                feat = fc.GetFeature(userId);
                    //                posField = GetFieldPosition(m_diameterFieldName, feat);
                    //                if (posField > -1)
                    //                {
                    //                    if (feat.get_Value(posField) != null)
                    //                    {
                    //                        string DiaVal = feat.get_Value(posField).ToString();
                    //                        if (Globals.IsNumeric(DiaVal))
                    //                        {
                    //                            try
                    //                            {
                    //                                diameter = Convert.ToDouble(DiaVal);
                    //                            }
                    //                            catch
                    //                            {
                    //                                MessageBox.Show("Error getting the Diameter from " + feat.Class.AliasName + " OID: " + feat.OID);
                    //                            }


                    //                        }
                    //                        else
                    //                        {
                    //                            diameter = -1;
                    //                        }
                    //                    }
                    //                    else
                    //                    {
                    //                        diameter = -1;
                    //                    }
                    //                }
                    //            }
                    //            IHitTest pHt = (IHitTest)polyline;
                    //            //double pHitDist = -1;
                    //            //int pHitPrt = -1;
                    //            //int pHitSeg = -1;
                    //            //bool pHitSide = false;
                    //            IPoint pHitPnt = new PointClass();
                    //            // IPoint pHit = new Point();
                    //            System.Double hitDistance = 0;
                    //            System.Int32 hitPartIndex = 0;
                    //            System.Int32 hitSegmentIndex = 0;
                    //            System.Boolean rightSide = false;



                    //            System.Boolean foundGeometry = pHt.HitTest(pnt, pNetAnalysisExt.SnapTolerance * 2,
                    //                ESRI.ArcGIS.Geometry.esriGeometryHitPartType.esriGeometryPartBoundary,
                    //                pHitPnt, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref
                    //                rightSide);


                    //            //pHt.HitTest(pnt, pNetAnalysisExt.SnapTolerance * 2, esriGeometryHitPartType.esriGeometryPartBoundary, pHitPnt, dht, lPart, lVertex, ref bright);


                    //            if (foundGeometry)
                    //            {
                    //                ESRI.ArcGIS.Geometry.IGeometryCollection geometryCollection_Polyline = (ESRI.ArcGIS.Geometry.IGeometryCollection)polyline;
                    //                ESRI.ArcGIS.Geometry.IGeometry geoFound = geometryCollection_Polyline.get_Geometry(hitPartIndex);
                    //                IPath pPath = geoFound as IPath;



                    //                segmentCollection = (ISegmentCollection)pPath;
                    //                IRelationalOperator2 relOp;

                    //                testSegment = segmentCollection.get_Segment(hitSegmentIndex);
                    //                toPoint = testSegment.ToPoint;
                    //                fromPoint = testSegment.FromPoint;
                    //                //    relOp = fromPoint as IRelationalOperator2;
                    //                // ITopologicalOperator topoOp;
                    //                //IPolygon poly;
                    //                // topoOp = pnt as ITopologicalOperator;
                    //                relOp = fromPoint as IRelationalOperator2;
                    //                //relOp = pnt as IRelationalOperator;//(topoOp.Buffer(snapdistnet) as IPolygon) as IRelationalOperator2;
                    //                //relOp = (topoOp.Buffer(snapdistnet) as IPolygon) as IRelationalOperator2;
                    //                // bool flipAng;
                    //                if (relOp.IsNear(pnt, snapdistnet))
                    //                {
                    //                    //flipDirections.Add(true);
                    //                    //flipAng = true;
                    //                    //segColTest = new PolylineClass();
                    //                    //segColTest.AddSegment(testSegment, ref Missing, ref Missing);
                    //                    //ICurve pCurv = segColTest as ICurve;
                    //                    //pCurv.ReverseOrientation();
                    //                    //segmentCollection = (ISegmentCollection)pCurv;
                    //                    //testSegment = segmentCollection.get_Segment(0);

                    //                    flipDirections.Add(false);
                    //                }
                    //                else
                    //                {
                    //                    toPoint = testSegment.FromPoint;
                    //                    fromPoint = testSegment.ToPoint;
                    //                    //flipDirections.Add(true);
                    //                    //testSegment.ToPoint = fromPoint;
                    //                    //  testSegment.FromPoint = toPoint;
                    //                    //flipDirections.Add(false);
                    //                    //flipAng = false;
                    //                }

                    //                try
                    //                {
                    //                    angle = GetAngleOfSegment(fromPoint, toPoint);
                    //                    //angle = GetAngleOfSegment2(testSegment);

                    //                }
                    //                catch
                    //                {
                    //                    angle = -1;
                    //                    MessageBox.Show("GetRotationUsingConnectedEdge:  error getting angle");
                    //                }



                    //                if (diameter >= 0)
                    //                {
                    //                    diameters.Add(diameter);
                    //                }
                    //                //if (flipAng == true && angle > 180)
                    //                //{
                    //                //    angle = angle - 180;
                    //                //}
                    //                //else if (flipAng == true && angle < 180)
                    //                //{
                    //                //    angle = angle + 180;
                    //                //}
                    //                angles.Add(angle);

                    //            }

                    //            //given line and point, return angles of all touching segments
                    //            //segmentCollection = (ISegmentCollection)polyline;
                    //            //enumSegment = (IEnumSegment)segmentCollection.EnumSegments;
                    //            //enumSegment.Next(out testSegment, ref partIndex, ref segmentIndex);

                    //            //while (testSegment != null)
                    //            //{
                    //            //    angle = GetAngleOfSegment(testSegment);
                    //            //    toPoint = testSegment.ToPoint;
                    //            //    topoOp = toPoint as ITopologicalOperator;
                    //            //    //poly = topoOp.Buffer(0.01) as IPolygon;
                    //            //    poly = topoOp.Buffer(snapdistnet) as IPolygon;
                    //            //    //ML: 20090617 Added test for segment touching point to be rotated
                    //            //    segColTest = new PolylineClass();
                    //            //    segColTest.AddSegment(testSegment, ref Missing, ref Missing);
                    //            //    relOp = segColTest as IRelationalOperator;

                    //            //    if (relOp.Touches(pnt))
                    //            //    {
                    //            //        relOp = poly as IRelationalOperator;
                    //            //        flipDirections.Add(relOp.Contains(pnt));
                    //            //        diameters.Add(diameter);
                    //            //        angles.Add(angle);
                    //            //    }
                    //            //    enumSegment.Next(out testSegment, ref partIndex, ref segmentIndex);

                    //            //}

                    //            ///end of possible function returning list of angles


                    //        }
                    //    }
                    //    switch (angles.Count)
                    //    {
                    //        case 0:
                    //            break;
                    //        case 1:
                    //            // End cap or plug fitting or simliar.
                    //            rotationAngle = angles[0];
                    //            if (flipDirections.Count == 1)
                    //            {
                    //                if (flipDirections[0]) rotationAngle += 180;
                    //            }
                    //            break;
                    //        case 2:
                    //            if (diameters != null)
                    //            {



                    //                if (diameters.Count >= 2)
                    //                {


                    //                    if (angles[0] > angles[1])
                    //                    {
                    //                        if (((angles[0] - angles[1]) % 180) < 15 || ((angles[0] - angles[1]) % 180) > 165)
                    //                        {

                    //                            if (diameters[0] != null && diameters[1] != null)
                    //                            {
                    //                                if (m_useDiameter & (diameters[0] < diameters[1]))
                    //                                {
                    //                                    rotationAngle = angles[1];
                    //                                    //if (flipDirections[0]) rotationAngle += 180;
                    //                                }
                    //                                else if (m_useDiameter & (diameters[0] >= diameters[1]))
                    //                                {
                    //                                    rotationAngle = angles[0];
                    //                                    //if (flipDirections[1]) rotationAngle += 180;
                    //                                }
                    //                                else rotationAngle = angles[0];
                    //                            }
                    //                            else
                    //                                rotationAngle = angles[0];

                    //                        }
                    //                        else
                    //                        {
                    //                            if ((angles[0] - angles[1]) % 90 > 15 && ((angles[0] - angles[1]) % 90 < 85))
                    //                            {

                    //                                if (diameters[0] != null && diameters[1] != null)
                    //                                {
                    //                                    if (m_useDiameter & (diameters[0] < diameters[1]))
                    //                                    {
                    //                                        rotationAngle = angles[1];
                    //                                        //if (flipDirections[0]) rotationAngle += 180;
                    //                                    }
                    //                                    else if (m_useDiameter & (diameters[0] >= diameters[1]))
                    //                                    {
                    //                                        rotationAngle = angles[0];
                    //                                        //if (flipDirections[1]) rotationAngle += 180;
                    //                                    }
                    //                                    else rotationAngle = angles[0];
                    //                                }
                    //                                else
                    //                                    rotationAngle = angles[0];

                    //                            }
                    //                            else
                    //                            {
                    //                                rotationAngle = (angles[0] + angles[1]) / 2;
                    //                            }
                    //                        }
                    //                    }
                    //                    else
                    //                    {
                    //                        if (((angles[1] - angles[0]) % 180) < 15 || ((angles[1] - angles[0]) % 180) > 165)
                    //                        {

                    //                            if (diameters[0] != null && diameters[1] != null)
                    //                            {
                    //                                if (m_useDiameter & (diameters[0] < diameters[1]))
                    //                                {
                    //                                    rotationAngle = angles[1];
                    //                                    //if (flipDirections[0]) rotationAngle += 180;
                    //                                }
                    //                                else if (m_useDiameter & (diameters[0] >= diameters[1]))
                    //                                {
                    //                                    rotationAngle = angles[0];
                    //                                    //if (flipDirections[1]) rotationAngle += 180;
                    //                                }
                    //                                else rotationAngle = angles[0];
                    //                            }
                    //                            else
                    //                                rotationAngle = angles[0];

                    //                        }
                    //                        else
                    //                        {
                    //                            if ((angles[1] - angles[0]) % 90 > 15 && ((angles[1] - angles[0]) % 90 < 85))
                    //                            {

                    //                                if (diameters[0] != null && diameters[1] != null)
                    //                                {
                    //                                    if (m_useDiameter & (diameters[0] < diameters[1]))
                    //                                    {
                    //                                        rotationAngle = angles[1];
                    //                                        //if (flipDirections[0]) rotationAngle += 180;
                    //                                    }
                    //                                    else if (m_useDiameter & (diameters[0] >= diameters[1]))
                    //                                    {
                    //                                        rotationAngle = angles[0];
                    //                                        //if (flipDirections[1]) rotationAngle += 180;
                    //                                    }
                    //                                    else rotationAngle = angles[0];
                    //                                }
                    //                                else
                    //                                    rotationAngle = angles[0];

                    //                            }
                    //                            else
                    //                            {
                    //                                rotationAngle = (angles[1] + angles[0]) / 2;
                    //                            }
                    //                        }
                    //                    }



                    //                }
                    //                else
                    //                    if (angles[0] > angles[1])
                    //                    {
                    //                        if (((angles[0] - angles[1]) % 180) < 15 || ((angles[0] - angles[1]) % 180) > 165)
                    //                        {
                    //                            rotationAngle = angles[0];
                    //                        }
                    //                        else
                    //                        {
                    //                            if ((angles[0] - angles[1]) % 90 > 15 && ((angles[0] - angles[1]) % 90 < 85))
                    //                            {
                    //                                rotationAngle = angles[0];
                    //                            }
                    //                            else
                    //                            {
                    //                                rotationAngle = (angles[0] + angles[1]) / 2;
                    //                            }
                    //                        }
                    //                    }
                    //                    else
                    //                    {
                    //                        if (((angles[1] - angles[0]) % 180) < 15 || ((angles[1] - angles[0]) % 180) > 165)
                    //                        {
                    //                            rotationAngle = angles[0];
                    //                        }
                    //                        else
                    //                        {
                    //                            if ((angles[1] - angles[0]) % 90 > 15 && ((angles[1] - angles[0]) % 90 < 85))
                    //                            {
                    //                                rotationAngle = angles[0];
                    //                            }
                    //                            else
                    //                            {
                    //                                rotationAngle = (angles[1] + angles[0]) / 2;
                    //                            }
                    //                        }
                    //                    }


                    //            }
                    //            break;

                    //        case 3:
                    //            //Tee or Tap fitting or similiar.  Rotate toward the odd line.
                    //            //int tee = 0;
                    //            //try
                    //            //{
                    //            //    tee = FindTee(angles[0], angles[1], angles[2]);
                    //            //}
                    //            //catch
                    //            //{
                    //            //    MessageBox.Show("Error finding Tee");
                    //            //}
                    //            //rotationAngle = angles[tee];
                    //            //if (flipDirections[tee]) rotationAngle += 180;
                    //            rotationAngle = TeeAngle(angles[0], angles[1], angles[2]);
                    //            break;
                    //        case 4:
                    //            // Cross fitting or similar. Any of the angles should work.
                    //            rotationAngle = (int)angles[0];
                    //            break;
                    //        default:
                    //            break;
                    //    }
                    //}
                    //If needed, convert to geographic degrees(zero north clockwise)
                    if (rotationAngle > 360)
                    {
                        rotationAngle -= 360;
                    }
                    if (rotationAngle < 0)
                    {
                        rotationAngle += 360;
                    }
                    //if (rotationAngle != null & m_rotationType == esriSymbolRotationType.esriRotateSymbolArithmetic)
                    //{
                    //    int a = (int)rotationAngle;


                    //    double newAngle;// = rotationAngle


                    //    newAngle = (double)rotationAngle + 270;
                    //    while (newAngle > 360)
                    //    {
                    //        newAngle = newAngle - 360;
                    //    }
                    //    // newAngle = newAngle - 360;
                    //    //if (a > 0 & a <= 90)
                    //    //    rotationAngle = 90 - a;
                    //    //else if (a > 90 & a <= 360)
                    //    //    rotationAngle = 450 - a;

                    //}

                    //Apply any spin angle
                    if (rotationAngle != null)
                    {
                        rotationAngle += m_spinAngle;
                        if (rotationAngle > 360)
                        {
                            rotationAngle -= 360;
                        }
                        if (rotationAngle < 0)
                        {
                            rotationAngle += 360;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Rotation Feature at " + inFeature.Class.AliasName + " with Object ID:" + inFeature.OID + "\n" + ex.Message);
                    return(-1);
                }
            }



            return(rotationAngle);
        }
        // Uses Geometric Network to find connected edges which determine desired rotation of point
        public Nullable<double> GetRotationUsingConnectedEdges(IFeature inFeature)
        {
            Nullable<double> rotationAngle = null;

            if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
            {

                try
                {
                   // double diameter = -1;
                    List<double> angles = new List<double>();
                    List<double> diameters = new List<double>();
                    List<Boolean> flipDirections = new List<Boolean>();

                    IPoint pnt = (ESRI.ArcGIS.Geometry.IPoint)inFeature.ShapeCopy;
                    IMxDocument pMxDoc = (IMxDocument)_app.Document;
                    double snapdistnet = Globals.ConvertPixelsToMap(2, pMxDoc.FocusMap);

                    // IMxDocument pMxDoc = (IMxDocument)_app.Document;
                    // VBRotate rotFunc = new VBRotate();
                    Rotate rotFunc = new Rotate();

                    if (!(inFeature is INetworkFeature))
                    {
                        rotationAngle = rotFunc.RotatePoint(pMxDoc.FocusMap, inFeature, m_rotationType == esriSymbolRotationType.esriRotateSymbolArithmetic, m_diameterFieldName);

                    }
                    else
                    {
                        rotationAngle = rotFunc.RotatePointByNetwork(pMxDoc.FocusMap, (INetworkFeature)inFeature, m_rotationType == esriSymbolRotationType.esriRotateSymbolArithmetic, m_diameterFieldName);

                    }

                    //else
                    //{
                    //    INetworkAnalysisExt pNetAnalysisExt;
                    //    UID pUID = new UIDClass();
                    //    pUID.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
                    //    pNetAnalysisExt = (INetworkAnalysisExt)_app.FindExtensionByCLSID(pUID);

                    //    INetworkFeature netFeat = (INetworkFeature)inFeature;
                    //    ISimpleJunctionFeature simpleJunctionFeature = (ISimpleJunctionFeature)netFeat;
                    //    INetworkClass netClass = (INetworkClass)inFeature.Class;
                    //    IGeometricNetwork geomNetwork = (IGeometricNetwork)netClass.GeometricNetwork;
                    //    INetwork network = (INetwork)geomNetwork.Network;
                    //    INetElements netElements = (INetElements)network;

                    //    IFeatureClass fc = null;
                    //    IFeature feat = null;
                    //    IGeometry geometry = null;
                    //    IPolyline polyline = null;
                    //    ISegmentCollection segmentCollection = null;
                    //    ISegmentCollection segColTest = null;
                    //    ISegment testSegment = null;
                    //    // IEnumSegment enumSegment = null;
                    //    System.Object edgeWeight;
                    //    Boolean edgeOrient;
                    //    //int partIndex = 0;
                    //    //int segmentIndex = 0;
                    //    int edgesCount;
                    //    int edgeEID;
                    //    int classId; int userId; int subId;
                    //    int posField; double angle;
                    //    object Missing = Type.Missing;

                    //    IPoint toPoint, fromPoint;
                    //    //ITopologicalOperator topoOp = null ;
                    //    //IPolygon poly = null;

                    //    IForwardStarGEN forwardStar = (IForwardStarGEN)network.CreateForwardStar(false, null, null, null, null);
                    //    forwardStar.FindAdjacent(0, simpleJunctionFeature.EID, out edgesCount);

                    //    if (edgesCount == 0)
                    //    {
                    //        if (simpleJunctionFeature == null)
                    //            return null;
                    //        if (simpleJunctionFeature.EdgeFeatureCount <= 0)
                    //            return null;
                    //        for (int i = 0; i < simpleJunctionFeature.EdgeFeatureCount; i++)
                    //        {
                    //            IEdgeFeature edgeFeat = null;
                    //            try
                    //            {
                    //                edgeFeat = simpleJunctionFeature.get_EdgeFeature(i);
                    //            }
                    //            catch
                    //            {

                    //                MessageBox.Show("GetRotationUsingConnectedEdge:  Not an edge feature");
                    //            }

                    //            try
                    //            {
                    //                polyline = (IPolyline5)edgeFeat.get_GeometryForEdgeElement(0);
                    //            }
                    //            catch
                    //            {

                    //                MessageBox.Show("GetRotationUsingConnectedEdge:  Not a polyline");
                    //            }

                    //            IHitTest pHt = (IHitTest)polyline;
                    //            //double pHitDist = -1;
                    //            //int pHitPrt = -1;
                    //            //int pHitSeg = -1;
                    //            //bool pHitSide = false;
                    //            IPoint pHitPnt = new PointClass();
                    //            // IPoint pHit = new Point();
                    //            System.Double hitDistance = 0;
                    //            System.Int32 hitPartIndex = 0;
                    //            System.Int32 hitSegmentIndex = 0;
                    //            System.Boolean rightSide = false;

                    //            System.Boolean foundGeometry = pHt.HitTest(pnt, pNetAnalysisExt.SnapTolerance * 2,
                    //                ESRI.ArcGIS.Geometry.esriGeometryHitPartType.esriGeometryPartBoundary,
                    //                pHitPnt, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref
                    //                rightSide);

                    //            //pHt.HitTest(pnt, pNetAnalysisExt.SnapTolerance * 2, esriGeometryHitPartType.esriGeometryPartBoundary, pHitPnt, dht, lPart, lVertex, ref bright);

                    //            if (foundGeometry)
                    //            {
                    //                ESRI.ArcGIS.Geometry.IGeometryCollection geometryCollection_Polyline = (ESRI.ArcGIS.Geometry.IGeometryCollection)polyline;
                    //                ESRI.ArcGIS.Geometry.IGeometry geoFound = geometryCollection_Polyline.get_Geometry(hitPartIndex);
                    //                IPath pPath = geoFound as IPath;

                    //                segmentCollection = (ISegmentCollection)pPath;

                    //                testSegment = segmentCollection.get_Segment(hitSegmentIndex);

                    //                try
                    //                {
                    //                    angle = GetAngleOfSegment(testSegment);
                    //                }
                    //                catch
                    //                {
                    //                    angle = -1;
                    //                    MessageBox.Show("GetRotationUsingConnectedEdge:  Error Getting Angle");
                    //                }

                    //                toPoint = testSegment.ToPoint;
                    //                //  foPoint = testSegment.ToPoint;
                    //                segColTest = new PolylineClass();
                    //                segColTest.AddSegment(testSegment, ref Missing, ref Missing);
                    //                IRelationalOperator2 relOp;

                    //                relOp = toPoint as IRelationalOperator2;
                    //                ITopologicalOperator topoOp;
                    //                IPolygon poly;
                    //                topoOp = pnt as ITopologicalOperator;

                    //                poly = topoOp.Buffer(pNetAnalysisExt.SnapTolerance * 2) as IPolygon;
                    //                //    poly = topoOp.Buffer(snapdistnet) as IPolygon;
                    //                if (relOp.Touches(poly))
                    //                {
                    //                    flipDirections.Add(relOp.Contains(pnt));
                    //                    if (diameter >= 0)
                    //                    {
                    //                        diameters.Add(diameter);
                    //                    }
                    //                }
                    //                angles.Add(angle);

                    //            }

                    //        }
                    //    }
                    //    else
                    //    {
                    //        for (int i = 0; i < edgesCount; i++)
                    //        {

                    //            forwardStar.QueryAdjacentEdge(i, out edgeEID, out edgeOrient, out edgeWeight);

                    //            try
                    //            {
                    //                geometry = geomNetwork.get_GeometryForEdgeEID(edgeEID);
                    //            }
                    //            catch (Exception ex)
                    //            {
                    //                netElements.QueryIDs(edgeEID, esriElementType.esriETEdge, out classId, out userId, out subId);
                    //                fc = GetFeatureClassByClassId(classId, geomNetwork);
                    //                MessageBox.Show("Error getting Edge Geometry\n" +
                    //                                "Edge EID is " + edgeEID + "\n" +
                    //                                fc.AliasName + " with Object ID of " + userId + "\n" +
                    //                                 inFeature.Class.AliasName + " with Object ID:" + inFeature.OID + "\n" + ex.Message +
                    //                                 "\n-------------------------\n" +
                    //                                 "If the error says no Geometric newtork, it probably should say\n" +
                    //                                "The edge feature has the same from and to junction feature - delete network element and rebuild connectivity\n");
                    //                continue;
                    //            }
                    //            // IEdgeFeature edgeFeat = null;
                    //            try
                    //            {
                    //                polyline = (IPolyline5)geometry;
                    //            }
                    //            catch
                    //            {
                    //                polyline = null;
                    //                MessageBox.Show("GetRotationUsingConnectedEdge:  error casting to polyline");
                    //            }

                    //            //Special case for reducer
                    //            if (m_useDiameter & (edgesCount == 2))
                    //            {
                    //                netElements.QueryIDs(edgeEID, esriElementType.esriETEdge, out classId, out userId, out subId);
                    //                fc = GetFeatureClassByClassId(classId, geomNetwork);
                    //                feat = fc.GetFeature(userId);
                    //                posField = GetFieldPosition(m_diameterFieldName, feat);
                    //                if (posField > -1)
                    //                {
                    //                    if (feat.get_Value(posField) != null)
                    //                    {
                    //                        string DiaVal = feat.get_Value(posField).ToString();
                    //                        if (Globals.IsNumeric(DiaVal))
                    //                        {
                    //                            try
                    //                            {
                    //                                diameter = Convert.ToDouble(DiaVal);
                    //                            }
                    //                            catch
                    //                            {
                    //                                MessageBox.Show("Error getting the Diameter from " + feat.Class.AliasName + " OID: " + feat.OID);
                    //                            }

                    //                        }
                    //                        else
                    //                        {
                    //                            diameter = -1;
                    //                        }
                    //                    }
                    //                    else
                    //                    {
                    //                        diameter = -1;
                    //                    }
                    //                }
                    //            }
                    //            IHitTest pHt = (IHitTest)polyline;
                    //            //double pHitDist = -1;
                    //            //int pHitPrt = -1;
                    //            //int pHitSeg = -1;
                    //            //bool pHitSide = false;
                    //            IPoint pHitPnt = new PointClass();
                    //            // IPoint pHit = new Point();
                    //            System.Double hitDistance = 0;
                    //            System.Int32 hitPartIndex = 0;
                    //            System.Int32 hitSegmentIndex = 0;
                    //            System.Boolean rightSide = false;

                    //            System.Boolean foundGeometry = pHt.HitTest(pnt, pNetAnalysisExt.SnapTolerance * 2,
                    //                ESRI.ArcGIS.Geometry.esriGeometryHitPartType.esriGeometryPartBoundary,
                    //                pHitPnt, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref
                    //                rightSide);

                    //            //pHt.HitTest(pnt, pNetAnalysisExt.SnapTolerance * 2, esriGeometryHitPartType.esriGeometryPartBoundary, pHitPnt, dht, lPart, lVertex, ref bright);

                    //            if (foundGeometry)
                    //            {
                    //                ESRI.ArcGIS.Geometry.IGeometryCollection geometryCollection_Polyline = (ESRI.ArcGIS.Geometry.IGeometryCollection)polyline;
                    //                ESRI.ArcGIS.Geometry.IGeometry geoFound = geometryCollection_Polyline.get_Geometry(hitPartIndex);
                    //                IPath pPath = geoFound as IPath;

                    //                segmentCollection = (ISegmentCollection)pPath;
                    //                IRelationalOperator2 relOp;

                    //                testSegment = segmentCollection.get_Segment(hitSegmentIndex);
                    //                toPoint = testSegment.ToPoint;
                    //                fromPoint = testSegment.FromPoint;
                    //                //    relOp = fromPoint as IRelationalOperator2;
                    //                // ITopologicalOperator topoOp;
                    //                //IPolygon poly;
                    //                // topoOp = pnt as ITopologicalOperator;
                    //                relOp = fromPoint as IRelationalOperator2;
                    //                //relOp = pnt as IRelationalOperator;//(topoOp.Buffer(snapdistnet) as IPolygon) as IRelationalOperator2;
                    //                //relOp = (topoOp.Buffer(snapdistnet) as IPolygon) as IRelationalOperator2;
                    //                // bool flipAng;
                    //                if (relOp.IsNear(pnt, snapdistnet))
                    //                {
                    //                    //flipDirections.Add(true);
                    //                    //flipAng = true;
                    //                    //segColTest = new PolylineClass();
                    //                    //segColTest.AddSegment(testSegment, ref Missing, ref Missing);
                    //                    //ICurve pCurv = segColTest as ICurve;
                    //                    //pCurv.ReverseOrientation();
                    //                    //segmentCollection = (ISegmentCollection)pCurv;
                    //                    //testSegment = segmentCollection.get_Segment(0);

                    //                    flipDirections.Add(false);
                    //                }
                    //                else
                    //                {
                    //                    toPoint = testSegment.FromPoint;
                    //                    fromPoint = testSegment.ToPoint;
                    //                    //flipDirections.Add(true);
                    //                    //testSegment.ToPoint = fromPoint;
                    //                    //  testSegment.FromPoint = toPoint;
                    //                    //flipDirections.Add(false);
                    //                    //flipAng = false;
                    //                }

                    //                try
                    //                {
                    //                    angle = GetAngleOfSegment(fromPoint, toPoint);
                    //                    //angle = GetAngleOfSegment2(testSegment);

                    //                }
                    //                catch
                    //                {
                    //                    angle = -1;
                    //                    MessageBox.Show("GetRotationUsingConnectedEdge:  error getting angle");
                    //                }

                    //                if (diameter >= 0)
                    //                {
                    //                    diameters.Add(diameter);
                    //                }
                    //                //if (flipAng == true && angle > 180)
                    //                //{
                    //                //    angle = angle - 180;
                    //                //}
                    //                //else if (flipAng == true && angle < 180)
                    //                //{
                    //                //    angle = angle + 180;
                    //                //}
                    //                angles.Add(angle);

                    //            }

                    //            //given line and point, return angles of all touching segments
                    //            //segmentCollection = (ISegmentCollection)polyline;
                    //            //enumSegment = (IEnumSegment)segmentCollection.EnumSegments;
                    //            //enumSegment.Next(out testSegment, ref partIndex, ref segmentIndex);

                    //            //while (testSegment != null)
                    //            //{
                    //            //    angle = GetAngleOfSegment(testSegment);
                    //            //    toPoint = testSegment.ToPoint;
                    //            //    topoOp = toPoint as ITopologicalOperator;
                    //            //    //poly = topoOp.Buffer(0.01) as IPolygon;
                    //            //    poly = topoOp.Buffer(snapdistnet) as IPolygon;
                    //            //    //ML: 20090617 Added test for segment touching point to be rotated
                    //            //    segColTest = new PolylineClass();
                    //            //    segColTest.AddSegment(testSegment, ref Missing, ref Missing);
                    //            //    relOp = segColTest as IRelationalOperator;

                    //            //    if (relOp.Touches(pnt))
                    //            //    {
                    //            //        relOp = poly as IRelationalOperator;
                    //            //        flipDirections.Add(relOp.Contains(pnt));
                    //            //        diameters.Add(diameter);
                    //            //        angles.Add(angle);
                    //            //    }
                    //            //    enumSegment.Next(out testSegment, ref partIndex, ref segmentIndex);

                    //            //}

                    //            ///end of possible function returning list of angles

                    //        }
                    //    }
                    //    switch (angles.Count)
                    //    {
                    //        case 0:
                    //            break;
                    //        case 1:
                    //            // End cap or plug fitting or simliar.
                    //            rotationAngle = angles[0];
                    //            if (flipDirections.Count == 1)
                    //            {
                    //                if (flipDirections[0]) rotationAngle += 180;
                    //            }
                    //            break;
                    //        case 2:
                    //            if (diameters != null)
                    //            {

                    //                if (diameters.Count >= 2)
                    //                {

                    //                    if (angles[0] > angles[1])
                    //                    {
                    //                        if (((angles[0] - angles[1]) % 180) < 15 || ((angles[0] - angles[1]) % 180) > 165)
                    //                        {

                    //                            if (diameters[0] != null && diameters[1] != null)
                    //                            {
                    //                                if (m_useDiameter & (diameters[0] < diameters[1]))
                    //                                {
                    //                                    rotationAngle = angles[1];
                    //                                    //if (flipDirections[0]) rotationAngle += 180;
                    //                                }
                    //                                else if (m_useDiameter & (diameters[0] >= diameters[1]))
                    //                                {
                    //                                    rotationAngle = angles[0];
                    //                                    //if (flipDirections[1]) rotationAngle += 180;
                    //                                }
                    //                                else rotationAngle = angles[0];
                    //                            }
                    //                            else
                    //                                rotationAngle = angles[0];

                    //                        }
                    //                        else
                    //                        {
                    //                            if ((angles[0] - angles[1]) % 90 > 15 && ((angles[0] - angles[1]) % 90 < 85))
                    //                            {

                    //                                if (diameters[0] != null && diameters[1] != null)
                    //                                {
                    //                                    if (m_useDiameter & (diameters[0] < diameters[1]))
                    //                                    {
                    //                                        rotationAngle = angles[1];
                    //                                        //if (flipDirections[0]) rotationAngle += 180;
                    //                                    }
                    //                                    else if (m_useDiameter & (diameters[0] >= diameters[1]))
                    //                                    {
                    //                                        rotationAngle = angles[0];
                    //                                        //if (flipDirections[1]) rotationAngle += 180;
                    //                                    }
                    //                                    else rotationAngle = angles[0];
                    //                                }
                    //                                else
                    //                                    rotationAngle = angles[0];

                    //                            }
                    //                            else
                    //                            {
                    //                                rotationAngle = (angles[0] + angles[1]) / 2;
                    //                            }
                    //                        }
                    //                    }
                    //                    else
                    //                    {
                    //                        if (((angles[1] - angles[0]) % 180) < 15 || ((angles[1] - angles[0]) % 180) > 165)
                    //                        {

                    //                            if (diameters[0] != null && diameters[1] != null)
                    //                            {
                    //                                if (m_useDiameter & (diameters[0] < diameters[1]))
                    //                                {
                    //                                    rotationAngle = angles[1];
                    //                                    //if (flipDirections[0]) rotationAngle += 180;
                    //                                }
                    //                                else if (m_useDiameter & (diameters[0] >= diameters[1]))
                    //                                {
                    //                                    rotationAngle = angles[0];
                    //                                    //if (flipDirections[1]) rotationAngle += 180;
                    //                                }
                    //                                else rotationAngle = angles[0];
                    //                            }
                    //                            else
                    //                                rotationAngle = angles[0];

                    //                        }
                    //                        else
                    //                        {
                    //                            if ((angles[1] - angles[0]) % 90 > 15 && ((angles[1] - angles[0]) % 90 < 85))
                    //                            {

                    //                                if (diameters[0] != null && diameters[1] != null)
                    //                                {
                    //                                    if (m_useDiameter & (diameters[0] < diameters[1]))
                    //                                    {
                    //                                        rotationAngle = angles[1];
                    //                                        //if (flipDirections[0]) rotationAngle += 180;
                    //                                    }
                    //                                    else if (m_useDiameter & (diameters[0] >= diameters[1]))
                    //                                    {
                    //                                        rotationAngle = angles[0];
                    //                                        //if (flipDirections[1]) rotationAngle += 180;
                    //                                    }
                    //                                    else rotationAngle = angles[0];
                    //                                }
                    //                                else
                    //                                    rotationAngle = angles[0];

                    //                            }
                    //                            else
                    //                            {
                    //                                rotationAngle = (angles[1] + angles[0]) / 2;
                    //                            }
                    //                        }
                    //                    }

                    //                }
                    //                else
                    //                    if (angles[0] > angles[1])
                    //                    {
                    //                        if (((angles[0] - angles[1]) % 180) < 15 || ((angles[0] - angles[1]) % 180) > 165)
                    //                        {
                    //                            rotationAngle = angles[0];
                    //                        }
                    //                        else
                    //                        {
                    //                            if ((angles[0] - angles[1]) % 90 > 15 && ((angles[0] - angles[1]) % 90 < 85))
                    //                            {
                    //                                rotationAngle = angles[0];
                    //                            }
                    //                            else
                    //                            {
                    //                                rotationAngle = (angles[0] + angles[1]) / 2;
                    //                            }
                    //                        }
                    //                    }
                    //                    else
                    //                    {
                    //                        if (((angles[1] - angles[0]) % 180) < 15 || ((angles[1] - angles[0]) % 180) > 165)
                    //                        {
                    //                            rotationAngle = angles[0];
                    //                        }
                    //                        else
                    //                        {
                    //                            if ((angles[1] - angles[0]) % 90 > 15 && ((angles[1] - angles[0]) % 90 < 85))
                    //                            {
                    //                                rotationAngle = angles[0];
                    //                            }
                    //                            else
                    //                            {
                    //                                rotationAngle = (angles[1] + angles[0]) / 2;
                    //                            }
                    //                        }
                    //                    }

                    //            }
                    //            break;

                    //        case 3:
                    //            //Tee or Tap fitting or similiar.  Rotate toward the odd line.
                    //            //int tee = 0;
                    //            //try
                    //            //{
                    //            //    tee = FindTee(angles[0], angles[1], angles[2]);
                    //            //}
                    //            //catch
                    //            //{
                    //            //    MessageBox.Show("Error finding Tee");
                    //            //}
                    //            //rotationAngle = angles[tee];
                    //            //if (flipDirections[tee]) rotationAngle += 180;
                    //            rotationAngle = TeeAngle(angles[0], angles[1], angles[2]);
                    //            break;
                    //        case 4:
                    //            // Cross fitting or similar. Any of the angles should work.
                    //            rotationAngle = (int)angles[0];
                    //            break;
                    //        default:
                    //            break;
                    //    }
                    //}
                    //If needed, convert to geographic degrees(zero north clockwise)
                    if (rotationAngle > 360) rotationAngle -= 360;
                    if (rotationAngle < 0) rotationAngle += 360;
                    //if (rotationAngle != null & m_rotationType == esriSymbolRotationType.esriRotateSymbolArithmetic)
                    //{
                    //    int a = (int)rotationAngle;

                    //    double newAngle;// = rotationAngle

                    //    newAngle = (double)rotationAngle + 270;
                    //    while (newAngle > 360)
                    //    {
                    //        newAngle = newAngle - 360;
                    //    }
                    //    // newAngle = newAngle - 360;
                    //    //if (a > 0 & a <= 90)
                    //    //    rotationAngle = 90 - a;
                    //    //else if (a > 90 & a <= 360)
                    //    //    rotationAngle = 450 - a;

                    //}

                    //Apply any spin angle
                    if (rotationAngle != null)
                    {
                        rotationAngle += m_spinAngle;
                        if (rotationAngle > 360) rotationAngle -= 360;
                        if (rotationAngle < 0) rotationAngle += 360;
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Rotation Feature at " + inFeature.Class.AliasName + " with Object ID:" + inFeature.OID + "\n" + ex.Message);
                    return -1;
                }

            }

            return rotationAngle;
        }
        // Uses Geometric Network to find connected edges which determine desired rotation of point

        public Nullable <double> GetRotationUsingConnectedEdges(IFeature inFeature)
        {
            Nullable <double> rotationAngle = null;

            if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                try
                {
                    // double diameter = -1;
                    List <double>  angles         = new List <double>();
                    List <double>  diameters      = new List <double>();
                    List <Boolean> flipDirections = new List <Boolean>();

                    IPoint      pnt         = (ESRI.ArcGIS.Geometry.IPoint)inFeature.ShapeCopy;
                    IMxDocument pMxDoc      = (IMxDocument)_app.Document;
                    double      snapdistnet = Globals.ConvertPixelsToMap(2, pMxDoc.FocusMap);


                    // IMxDocument pMxDoc = (IMxDocument)_app.Document;
                    // VBRotate rotFunc = new VBRotate();
                    Rotate rotFunc = new Rotate();

                    if (!(inFeature is INetworkFeature))
                    {
                        rotationAngle = rotFunc.RotatePoint(pMxDoc.FocusMap, pMxDoc.SearchTolerance, inFeature, m_rotationType == esriSymbolRotationType.esriRotateSymbolArithmetic, m_diameterFieldName, m_onlyLayerName);
                    }
                    else
                    {
                        rotationAngle = rotFunc.RotatePointByNetwork(pMxDoc.FocusMap, (INetworkFeature)inFeature, m_rotationType == esriSymbolRotationType.esriRotateSymbolArithmetic, m_diameterFieldName, m_onlyLayerName);
                    }

                    //If needed, convert to geographic degrees(zero north clockwise)
                    if (rotationAngle != null)
                    {
                        if (rotationAngle > 360)
                        {
                            rotationAngle -= 360;
                        }
                        if (rotationAngle < 0)
                        {
                            rotationAngle += 360;
                        }

                        rotationAngle += m_spinAngle;
                        if (rotationAngle > 360)
                        {
                            rotationAngle -= 360;
                        }
                        if (rotationAngle < 0)
                        {
                            rotationAngle += 360;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Rotation Feature at " + inFeature.Class.AliasName + " with Object ID:" + inFeature.OID + "\n" + ex.ToString());
                    return(-1);
                }
            }



            return(rotationAngle);
        }