/// <summary>
        /// Flash the feature geometry on the map
        /// <param name="pFeature">The feature being flashed</param>
        /// <param name="pMxDoc">A hook to the application display</param>
        /// <param name="direction">The digitized direction of the barrier with respect to the underlying source feature</param>
        /// </summary>
        private void FlashFeature(IFeature pFeature, esriNetworkEdgeDirection direction)
        {
            IMxDocument pMxDoc = m_app.Document as IMxDocument;

            // Start drawing on screen.
            pMxDoc.ActiveView.ScreenDisplay.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache);

            // Switch functions based on Geometry type.
            switch (pFeature.Shape.GeometryType)
            {
            case esriGeometryType.esriGeometryPolyline:
                FlashLine(pMxDoc.ActiveView.ScreenDisplay, pFeature.Shape, direction);
                break;

            case esriGeometryType.esriGeometryPolygon:
                // no network elements can be polygons
                break;

            case esriGeometryType.esriGeometryPoint:
                FlashPoint(pMxDoc.ActiveView.ScreenDisplay, pFeature.Shape);
                break;

            default:
                throw new Exception("Unexpected Geometry Type");
            }

            // Finish drawing on screen.
            pMxDoc.ActiveView.ScreenDisplay.FinishDrawing();
        }
        /// <summary>
        /// Flash a line feature on the map
        /// <param name="pDisplay">The map screen</param>
        /// <param name="pGeometry">The geometry of the feature to be flashed</param>
        /// <param name="direction">The digitized direction of the barrier with respect to the underlying source feature</param>
        /// </summary>
        private void FlashLine(IScreenDisplay pDisplay, IGeometry pGeometry, esriNetworkEdgeDirection direction)
        {
            // The flash will be on a line symbol with an arrow on it
            ICartographicLineSymbol ipArrowLineSymbol = new CartographicLineSymbolClass();

            // the line color will be red
            IRgbColor ipRgbRedColor = new RgbColorClass();

            ipRgbRedColor.Red = 192;

            // the arrow will be black
            IRgbColor ipRgbBlackColor = new RgbColorClass();

            ipRgbBlackColor.RGB = 0;

            // set up the arrow that will be displayed along the line
            IArrowMarkerSymbol ipArrowMarker = new ArrowMarkerSymbolClass();

            ipArrowMarker.Style  = esriArrowMarkerStyle.esriAMSPlain;
            ipArrowMarker.Length = 18;
            ipArrowMarker.Width  = 12;
            ipArrowMarker.Color  = ipRgbBlackColor;

            // set up the line itself
            ipArrowLineSymbol.Width = 4;
            ipArrowLineSymbol.Color = ipRgbRedColor;

            // Set up the Raster Op-Code to help the flash mechanism
            ((ISymbol)ipArrowMarker).ROP2     = esriRasterOpCode.esriROPNotXOrPen;
            ((ISymbol)ipArrowLineSymbol).ROP2 = esriRasterOpCode.esriROPNotXOrPen;

            // decorate the line with the arrow symbol
            ISimpleLineDecorationElement ipSimpleLineDecorationElement = new SimpleLineDecorationElementClass();

            ipSimpleLineDecorationElement.Rotate          = true;
            ipSimpleLineDecorationElement.PositionAsRatio = true;
            ipSimpleLineDecorationElement.MarkerSymbol    = ipArrowMarker;
            ipSimpleLineDecorationElement.AddPosition(0.5);
            ILineDecoration ipLineDecoration = new LineDecorationClass();

            ipLineDecoration.AddElement(ipSimpleLineDecorationElement);
            ((ILineProperties)ipArrowLineSymbol).LineDecoration = ipLineDecoration;

            // the arrow is initially set to correspond to the digitized direction of the line
            //  if the barrier direction is against digitized, then we need to flip the arrow direction
            if (direction == esriNetworkEdgeDirection.esriNEDAgainstDigitized)
            {
                ipSimpleLineDecorationElement.FlipAll = true;
            }

            // Flash the line
            //  Two calls are made to Draw.  Since the ROP2 setting is NotXOrPen, the first call
            //  draws the symbol with our new symbology and the second call redraws what was originally
            //  in the place of the symbol
            pDisplay.SetSymbol(ipArrowLineSymbol as ISymbol);
            pDisplay.DrawPolyline(pGeometry);
            System.Threading.Thread.Sleep(300);
            pDisplay.DrawPolyline(pGeometry);
        }
        /// <summary>
        /// Occurs when a dataGrid row header is clicked.
        ///   It is used here to flash the geometry of the newly selected row
        /// <param name="sender">The control raising this event</param>
        /// <param name="e">Arguments associated with the event</param>
        /// </summary>
        private void dataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            // make sure none of the cells are in edit mode.  When in edit mode, the values obtained
            //  programmatically will not yet match the value the user has changed the cell to
            DataGridView dgv = (DataGridView)sender;

            dgv.EndEdit();

            // Only flash when there is one selected row
            if (dgv.SelectedRows.Count > 1)
            {
                return;
            }
            DataGridViewRow selectedRow = dgv.SelectedRows[0];

            // If it is the extra dataGrid row or has errors, then don't try to flash it
            ValidateRow(selectedRow);
            if (selectedRow.IsNewRow || selectedRow.ErrorText != "")
            {
                return;
            }

            // also, if any of the row's cell have no value, then don't want to flash it
            foreach (DataGridViewCell cell in selectedRow.Cells)
            {
                if (cell.Value == null)
                {
                    return;
                }
            }

            // use the EID to obtain the barrier's corresponding network element and source feature
            INetworkElement element = GetElementByEID(selectedRow.Cells[0].Value.ToString(), dgv.Name);

            if (element == null)
            {
                return;
            }
            IFeature sourceFeature = GetSourceFeature(element);

            // For an edge, get the part geometry of the barrier covered portion of the source feature
            //  that should be displayed
            INetworkEdge             netEdge          = element as INetworkEdge;
            esriNetworkEdgeDirection displayDirection = esriNetworkEdgeDirection.esriNEDNone;

            if (netEdge != null)
            {
                sourceFeature.Shape = GetBarrierSubcurve(netEdge, sourceFeature, selectedRow);
                displayDirection    = GetDirectionValue(selectedRow);
            }

            // Draw
            FlashFeature(sourceFeature, displayDirection);
        }
 public NetworkAssignment(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     this._isDefault             = info.GetBoolean("isDefault");
     this._id                    = info.GetInt32("id");
     this._networkAttributeName  = info.GetString("networkAttributeName");
     this._networkElementType    = (esriNetworkElementType)Enum.Parse(typeof(esriNetworkElementType), info.GetString("networkElementType"), true);
     this._networkSourceName     = info.GetString("networkSourceName");
     this._networkEvaluatorCLSID = info.GetString("networkEvaluatorCLSID");
     this._networkEdgeDirection  = (esriNetworkEdgeDirection)Enum.Parse(typeof(esriNetworkEdgeDirection), info.GetString("networkEdgeDirection"), true);
     this._networkEvaluatorData  = (List <Property>)info.GetValue("networkEvaluatorData", typeof(List <Property>));
 }
        /// <summary>
        /// Load both the Edge and Junction dataGrids with the information in the barrier feature
        /// <param name="barrier">The barrier being loaded into dataGrids</param>
        /// </summary>
        void LoadDatagrids()
        {
            // Populate the cell with the direction drop down
            ((DataGridViewComboBoxColumn)dataGridViewEdges.Columns[1]).Items.AddRange(EDGE_ALONG, EDGE_AGAINST);;

            // get the location ranges out of the barrier feature
            var naLocRangesObject = m_barrier as INALocationRangesObject;
            var naLocRanges       = naLocRangesObject.NALocationRanges;

            if (naLocRanges == null)
            {
                throw new Exception("Selected barrier has a null NALocationRanges value");
            }

            // add all of the junctions included in the barrier to the Junctions dataGrid
            long junctionCount = naLocRanges.JunctionCount;
            int  junctionEID   = -1;

            for (int i = 0; i < junctionCount; i++)
            {
                naLocRanges.QueryJunction(i, ref junctionEID);
                int rowIndex = dataGridViewJunctions.Rows.Add();
                dataGridViewJunctions.Rows[rowIndex].SetValues(junctionEID);
            }

            // add all of the edges included in the barrier to the Edges dataGrid
            long   edgeRangeCount = naLocRanges.EdgeRangeCount;
            int    edgeEID = -1;
            double fromPosition, toPosition;

            fromPosition = toPosition = -1;
            esriNetworkEdgeDirection edgeDirection = esriNetworkEdgeDirection.esriNEDNone;

            for (int i = 0; i < edgeRangeCount; i++)
            {
                naLocRanges.QueryEdgeRange(i, ref edgeEID, ref edgeDirection, ref fromPosition, ref toPosition);

                string directionValue = "";
                if (edgeDirection == esriNetworkEdgeDirection.esriNEDAlongDigitized)
                {
                    directionValue = EDGE_ALONG;
                }
                else if (edgeDirection == esriNetworkEdgeDirection.esriNEDAgainstDigitized)
                {
                    directionValue = EDGE_AGAINST;
                }

                dataGridViewEdges.Rows.Add(edgeEID, directionValue, fromPosition, toPosition);
            }
        }
        /// <summary>
        /// Determine the esriNetworkEdgeDirection from the value in the dataGridView cell
        /// <param name="selectedRow">The row containing the barrier's location range information</param>
        /// </summary>
        private esriNetworkEdgeDirection GetDirectionValue(DataGridViewRow selectedRow)
        {
            esriNetworkEdgeDirection direction = esriNetworkEdgeDirection.esriNEDNone;
            string textValue = selectedRow.Cells[1].Value.ToString();

            if (textValue == EDGE_ALONG)
            {
                direction = esriNetworkEdgeDirection.esriNEDAlongDigitized;
            }
            else if (textValue == EDGE_AGAINST)
            {
                direction = esriNetworkEdgeDirection.esriNEDAgainstDigitized;
            }

            return(direction);
        }
 public NetworkAssignment(NetworkAssignment prototype) : base(prototype)
 {
     this._isDefault             = prototype.IsDefault;
     this._id                    = prototype.ID;
     this._networkAttributeName  = prototype.NetworkAttributeName;
     this._networkElementType    = prototype.NetworkElementType;
     this._networkSourceName     = prototype.NetworkSourceName;
     this._networkEvaluatorCLSID = prototype.NetworkEvaluatorCLSID;
     this._networkEdgeDirection  = prototype.NetworkEdgeDirection;
     this._networkEvaluatorData  = new List <Property>();
     foreach (Property property in prototype.NetworkEvaluatorDataCollection)
     {
         Property propertyClone = (Property)property.Clone();
         this._networkEvaluatorData.Add(propertyClone);
     }
 }
        //
        // CONSTRUCTOR
        //
        public NetworkAssignment(IXPathNavigable path) : base(path)
        {
            // Get Navigator
            XPathNavigator navigator = path.CreateNavigator();

            // <IsDefault>
            XPathNavigator navigatorIsDefault = navigator.SelectSingleNode("IsDefault");

            if (navigatorIsDefault != null)
            {
                this._isDefault = navigatorIsDefault.ValueAsBoolean;
            }

            // <ID>
            XPathNavigator navigatorID = navigator.SelectSingleNode("ID");

            if (navigatorID != null)
            {
                this._id = navigatorID.ValueAsInt;
            }

            // <NetworkAttributeName>
            XPathNavigator navigatorNetworkAttributeName = navigator.SelectSingleNode("NetworkAttributeName");

            if (navigatorNetworkAttributeName != null)
            {
                this._networkAttributeName = navigatorNetworkAttributeName.Value;
            }

            // <NetworkElementType>
            XPathNavigator navigatorNetworkElementType = navigator.SelectSingleNode("NetworkElementType");

            if (navigatorNetworkElementType != null)
            {
                this._networkElementType = (esriNetworkElementType)Enum.Parse(typeof(esriNetworkElementType), navigatorNetworkElementType.Value, true);
            }

            // <NetworkSourceName>
            XPathNavigator navigatorNetworkSourceName = navigator.SelectSingleNode("NetworkSourceName");

            if (navigatorNetworkSourceName != null)
            {
                this._networkSourceName = navigatorNetworkSourceName.Value;
            }

            // <NetworkEvaluatorCLSID>
            XPathNavigator navigatorNetworkEvaluatorCLSID = navigator.SelectSingleNode("NetworkEvaluatorCLSID");

            if (navigatorNetworkEvaluatorCLSID != null)
            {
                this._networkEvaluatorCLSID = navigatorNetworkEvaluatorCLSID.Value;
            }

            // <NetworkEdgeDirection>
            XPathNavigator navigatorNetworkEdgeDirection = navigator.SelectSingleNode("NetworkEdgeDirection");

            if (navigatorNetworkEdgeDirection != null)
            {
                this._networkEdgeDirection = (esriNetworkEdgeDirection)Enum.Parse(typeof(esriNetworkEdgeDirection), navigatorNetworkEdgeDirection.Value, true);
            }

            // <NetworkEvaluatorData><PropertyArray><PropertySetProperty>
            this._networkEvaluatorData = new List <Property>();
            XPathNodeIterator interatorProperty = navigator.Select("NetworkEvaluatorData/PropertyArray/PropertySetProperty");

            while (interatorProperty.MoveNext())
            {
                // Get <PropertySetProperty>
                XPathNavigator navigatorProperty = interatorProperty.Current;

                // Add PropertySetProperty
                Property property = new Property(navigatorProperty);
                this._networkEvaluatorData.Add(property);
            }
        }
        /// <summary>
        /// Take a network edge, a source feature, and a row from the edges dataGrid, and determine
        ///  the geometry to be flashed on the map
        /// <param name="netEdge">The edge upon which the barrier resides</param>
        /// <param name="sourceFeature">The source feature corresponding to the network edge</param>
        /// <param name="selectedRow">The row containing the barrier's location range information</param>
        /// </summary>
        private ICurve GetBarrierSubcurve(INetworkEdge netEdge, IFeature sourceFeature, DataGridViewRow selectedRow)
        {
            // value for displaying the entire source feature
            double fromPosition = 0;
            double toPosition   = 1;

            // Find the values for displaying only the element portion of the source feature
            double fromElementPosition, toElementPosition;

            netEdge.QueryPositions(out fromElementPosition, out toElementPosition);

            // due to the element possibly being in the against digitized direction,
            //   fromPosition could be greater than toPosition.  If that is the case, swap the values
            if (fromElementPosition > toElementPosition)
            {
                double tmp = fromElementPosition;
                fromElementPosition = toElementPosition;
                toElementPosition   = tmp;
            }

            esriNetworkEdgeDirection direction = GetDirectionValue(selectedRow);

            if (direction == esriNetworkEdgeDirection.esriNEDNone)
            {
                return(null);
            }

            // Flash the edge
            if (rbFlashElementPortion.Checked)
            {
                fromPosition = fromElementPosition;
                toPosition   = toElementPosition;
            }
            // Flash the barrier portion of the edge
            else if (rbFlashBarrierPortion.Checked)
            {
                double fromBarrierPosition = -1;
                double toBarrierPosition   = -1;

                // gather the from and to position values for the barrier
                fromBarrierPosition = Double.Parse(selectedRow.Cells[2].Value.ToString());
                toBarrierPosition   = Double.Parse(selectedRow.Cells[3].Value.ToString());

                // for barriers in the against direction, we need to adjust that the element position is
                if (direction == esriNetworkEdgeDirection.esriNEDAgainstDigitized)
                {
                    fromBarrierPosition = 1 - fromBarrierPosition;
                    toBarrierPosition   = 1 - toBarrierPosition;
                }

                // use the positioning along the element of the barrier
                //  to get the position along the original source feature
                fromPosition = fromElementPosition + (fromBarrierPosition * (toElementPosition - fromElementPosition));
                toPosition   = fromElementPosition + (toBarrierPosition * (toElementPosition - fromElementPosition));
            }

            if (fromPosition > toPosition)
            {
                double tmp = fromPosition;
                fromPosition = toPosition;
                toPosition   = tmp;
            }

            // get the subspan on the polyline that represents the from and to positions we specified
            ICurve displayCurve;
            ICurve sourceCurve = sourceFeature.Shape as ICurve;

            sourceCurve.GetSubcurve(fromPosition, toPosition, true, out displayCurve);
            return(displayCurve);
        }
		/// <summary>
		/// Flash a line feature on the map
		/// <param name="pDisplay">The map screen</param>
		/// <param name="pGeometry">The geometry of the feature to be flashed</param>
		/// <param name="direction">The digitized direction of the barrier with respect to the underlying source feature</param>
		/// </summary>
		private void FlashLine(IScreenDisplay pDisplay, IGeometry pGeometry, esriNetworkEdgeDirection direction)
		{
			// The flash will be on a line symbol with an arrow on it
			ICartographicLineSymbol ipArrowLineSymbol = new CartographicLineSymbolClass();

			// the line color will be red
			IRgbColor ipRgbRedColor = new RgbColorClass();
			ipRgbRedColor.Red = 192;

			// the arrow will be black
			IRgbColor ipRgbBlackColor = new RgbColorClass();
			ipRgbBlackColor.RGB = 0;

			// set up the arrow that will be displayed along the line
			IArrowMarkerSymbol ipArrowMarker = new ArrowMarkerSymbolClass();
			ipArrowMarker.Style = esriArrowMarkerStyle.esriAMSPlain;
			ipArrowMarker.Length = 18;
			ipArrowMarker.Width = 12;
			ipArrowMarker.Color = ipRgbBlackColor;

			// set up the line itself
			ipArrowLineSymbol.Width = 4;
			ipArrowLineSymbol.Color = ipRgbRedColor;

			// Set up the Raster Op-Code to help the flash mechanism
			((ISymbol)ipArrowMarker).ROP2 = esriRasterOpCode.esriROPNotXOrPen;
			((ISymbol)ipArrowLineSymbol).ROP2 = esriRasterOpCode.esriROPNotXOrPen;

			// decorate the line with the arrow symbol
			ISimpleLineDecorationElement ipSimpleLineDecorationElement = new SimpleLineDecorationElementClass();
			ipSimpleLineDecorationElement.Rotate = true;
			ipSimpleLineDecorationElement.PositionAsRatio = true;
			ipSimpleLineDecorationElement.MarkerSymbol = ipArrowMarker;
			ipSimpleLineDecorationElement.AddPosition(0.5);
			ILineDecoration ipLineDecoration = new LineDecorationClass();
			ipLineDecoration.AddElement(ipSimpleLineDecorationElement);
			((ILineProperties)ipArrowLineSymbol).LineDecoration = ipLineDecoration;

			// the arrow is initially set to correspond to the digitized direction of the line
			//  if the barrier direction is against digitized, then we need to flip the arrow direction
			if (direction == esriNetworkEdgeDirection.esriNEDAgainstDigitized)
				ipSimpleLineDecorationElement.FlipAll = true;

			// Flash the line
			//  Two calls are made to Draw.  Since the ROP2 setting is NotXOrPen, the first call
			//  draws the symbol with our new symbology and the second call redraws what was originally 
			//  in the place of the symbol
			pDisplay.SetSymbol(ipArrowLineSymbol as ISymbol);
			pDisplay.DrawPolyline(pGeometry);
			System.Threading.Thread.Sleep(300);
			pDisplay.DrawPolyline(pGeometry);
		}
        /// <summary>
        /// Occurs when the user clicks the Save button.
        ///   The barrier information is collected out of the junction and edge barrier
        ///   dataGrids, then stored back into the original barrier feature as a replacement
        ///   to the existing barrier information.  The original geometry of the barrier remains
        ///   unaltered.
        /// <param name="sender">The control raising this event</param>
        /// <param name="e">Arguments associated with the event</param>
        /// </summary>
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateDataGrid(dataGridViewEdges))
            {
                return;
            }
            if (!ValidateDataGrid(dataGridViewJunctions))
            {
                return;
            }

            // The existing NALocationRanges for the barrier will be replaced with a new one
            INALocationRanges naLocRanges = new NALocationRangesClass();

            // First gather the edge ranges
            foreach (DataGridViewRow row in dataGridViewEdges.Rows)
            {
                // ignore the extra row in the dataGrid
                if (row.IsNewRow)
                {
                    continue;
                }

                // gather the EID value for the new range
                int eid = Int32.Parse(row.Cells[0].Value.ToString());

                // gather the edge direction value for the new range
                string directionValue = row.Cells[1].Value.ToString();
                esriNetworkEdgeDirection direction = esriNetworkEdgeDirection.esriNEDNone;
                if (directionValue == EDGE_ALONG)
                {
                    direction = esriNetworkEdgeDirection.esriNEDAlongDigitized;
                }
                else if (directionValue == EDGE_AGAINST)
                {
                    direction = esriNetworkEdgeDirection.esriNEDAgainstDigitized;
                }

                // gather the from and to position values for the new range
                double fromPos = Double.Parse(row.Cells[2].Value.ToString());
                double toPos   = Double.Parse(row.Cells[3].Value.ToString());

                // load the values for this range into the NALocationRanges object
                naLocRanges.AddEdgeRange(eid, direction, fromPos, toPos);
            }

            // Now gather the junctions to be included in the barrier
            foreach (DataGridViewRow row in dataGridViewJunctions.Rows)
            {
                // ignore the extra row in the dataGrid
                if (row.IsNewRow)
                {
                    continue;
                }

                // gather the EID value for the junction to include
                int eid = Int32.Parse(row.Cells[0].Value.ToString());

                // load this junction into the NALocationRanges object
                naLocRanges.AddJunction(eid);
            }

            // Cast the barrier feature to INALocationRanges Object, then populate
            //   its NALocationRanges value with the new barrier that was created above.
            //   Then, save the new barrier with a call to Store()
            INALocationRangesObject naLocationRangesObject = m_barrier as INALocationRangesObject;

            naLocationRangesObject.NALocationRanges = naLocRanges;
            m_barrier.Store();

            this.Close();
        }
Example #12
0
        /// <summary>Adds new Network Attribute Evaluators</summary>
        private void AddEvaluators(NetworkAttributeInfo nai, IEvaluatedNetworkAttribute netAttr)
        {
            foreach (EvaluatorInfo eval in nai.Evaluators)
            {
                INetworkEvaluator evaluator = null;

                if (eval.EvaluatorType == eEvaluatorType.Constant)
                {
                    evaluator = new NetworkConstantEvaluatorClass();
                    if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTBoolean)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = eval.Expression.Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase);
                    }
                    else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTDouble)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToDouble(eval.Expression);
                    }
                    else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTFloat)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToSingle(eval.Expression);
                    }
                    else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTInteger)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToInt32(eval.Expression);
                    }
                }
                else if (eval.EvaluatorType == eEvaluatorType.Script)
                {
                    evaluator = new NetworkScriptEvaluatorClass();

#if ARCGIS_10_0     // Handle Python script language added in ArcGIS 10.1
                    if (eval.ScriptLanguage != "VBScript")
                    {
                        throw new ApplicationException(RESMGR.GetString("GPTools_OSMGPCreateNetworkDataset_invalidScriptLanguage"));
                    }

                    INetworkScriptEvaluator scriptEvaluator = (INetworkScriptEvaluator)evaluator;
                    scriptEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#else
                    INetworkScriptEvaluator2 scriptEvaluator = (INetworkScriptEvaluator2)evaluator;
                    scriptEvaluator.SetLanguage(eval.ScriptLanguage);
                    scriptEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#endif
                }
                else if (eval.EvaluatorType == eEvaluatorType.Field)
                {
                    evaluator = new NetworkFieldEvaluatorClass();

#if ARCGIS_10_0     // Handle Python script language added in ArcGIS 10.1
                    if (eval.ScriptLanguage != "VBScript")
                    {
                        throw new ApplicationException(RESMGR.GetString("GPTools_OSMGPCreateNetworkDataset_invalidScriptLanguage"));
                    }

                    INetworkFieldEvaluator fieldEvaluator = (INetworkFieldEvaluator)evaluator;
                    fieldEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#else
                    INetworkFieldEvaluator2 fieldEvaluator = (INetworkFieldEvaluator2)evaluator;
                    fieldEvaluator.SetLanguage(eval.ScriptLanguage);
                    fieldEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#endif
                }

                INetworkSource source = EnumerateNetworkSources()
                                        .FirstOrDefault(ns => ns.Name.Equals(GetFullClassName(eval.Source), StringComparison.CurrentCultureIgnoreCase));
                if (source != null)
                {
                    esriNetworkEdgeDirection direction = eval.Direction;
                    if (!(source is IEdgeFeatureSource))
                    {
                        direction = esriNetworkEdgeDirection.esriNEDNone;
                    }

                    netAttr.set_Evaluator(source, direction, evaluator);
                }
            }
        }
        public static void SetEvaluator(IEvaluatedNetworkAttribute netAttribute, INetworkSource netSource, Type t, esriNetworkEdgeDirection dirType)
        {
            object            obj  = Activator.CreateInstance(t);
            INetworkEvaluator eval = obj as INetworkEvaluator;

            netAttribute.set_Evaluator(netSource, dirType, eval);
        }
		/// <summary>
		/// Flash the feature geometry on the map
		/// <param name="pFeature">The feature being flashed</param>
		/// <param name="pMxDoc">A hook to the application display</param>
		/// <param name="direction">The digitized direction of the barrier with respect to the underlying source feature</param>
		/// </summary>
		private void FlashFeature(IFeature pFeature, esriNetworkEdgeDirection direction)
		{
			IMxDocument pMxDoc = m_app.Document as IMxDocument;

			// Start drawing on screen. 
			pMxDoc.ActiveView.ScreenDisplay.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache);

			// Switch functions based on Geometry type. 
			switch (pFeature.Shape.GeometryType)
			{
				case esriGeometryType.esriGeometryPolyline:
					FlashLine(pMxDoc.ActiveView.ScreenDisplay, pFeature.Shape, direction);
					break;
				case esriGeometryType.esriGeometryPolygon:
					// no network elements can be polygons
					break;
				case esriGeometryType.esriGeometryPoint:
					FlashPoint(pMxDoc.ActiveView.ScreenDisplay, pFeature.Shape);
					break;
				default:
					throw new Exception("Unexpected Geometry Type");
			}

			// Finish drawing on screen. 
			pMxDoc.ActiveView.ScreenDisplay.FinishDrawing();
		}
 public NetworkAssignment(SerializationInfo info, StreamingContext context) : base(info, context) {
     this._isDefault = info.GetBoolean("isDefault");
     this._id = info.GetInt32("id");
     this._networkAttributeName = info.GetString("networkAttributeName");
     this._networkElementType = (esriNetworkElementType)Enum.Parse(typeof(esriNetworkElementType), info.GetString("networkElementType"), true);
     this._networkSourceName = info.GetString("networkSourceName");
     this._networkEvaluatorCLSID = info.GetString("networkEvaluatorCLSID");
     this._networkEdgeDirection = (esriNetworkEdgeDirection)Enum.Parse(typeof(esriNetworkEdgeDirection), info.GetString("networkEdgeDirection"), true);
     this._networkEvaluatorData = (List<Property>)info.GetValue("networkEvaluatorData", typeof(List<Property>));
 }
 public NetworkAssignment(NetworkAssignment prototype) : base(prototype) {
     this._isDefault = prototype.IsDefault;
     this._id = prototype.ID;
     this._networkAttributeName = prototype.NetworkAttributeName;
     this._networkElementType = prototype.NetworkElementType;
     this._networkSourceName = prototype.NetworkSourceName;
     this._networkEvaluatorCLSID = prototype.NetworkEvaluatorCLSID;
     this._networkEdgeDirection = prototype.NetworkEdgeDirection;
     this._networkEvaluatorData = new List<Property>();
     foreach (Property property in prototype.NetworkEvaluatorDataCollection) {
         Property propertyClone = (Property)property.Clone();
         this._networkEvaluatorData.Add(propertyClone);
     }
 }
        //
        // CONSTRUCTOR
        //
        public NetworkAssignment(IXPathNavigable path) : base(path) {
            // Get Navigator
            XPathNavigator navigator = path.CreateNavigator();

            // <IsDefault>
            XPathNavigator navigatorIsDefault = navigator.SelectSingleNode("IsDefault");
            if (navigatorIsDefault != null) {
                this._isDefault = navigatorIsDefault.ValueAsBoolean;
            }

            // <ID>
            XPathNavigator navigatorID = navigator.SelectSingleNode("ID");
            if (navigatorID != null) {
                this._id = navigatorID.ValueAsInt;
            }

            // <NetworkAttributeName>
            XPathNavigator navigatorNetworkAttributeName = navigator.SelectSingleNode("NetworkAttributeName");
            if (navigatorNetworkAttributeName != null) {
                this._networkAttributeName = navigatorNetworkAttributeName.Value;
            }

            // <NetworkElementType>
            XPathNavigator navigatorNetworkElementType = navigator.SelectSingleNode("NetworkElementType");
            if (navigatorNetworkElementType != null) {
                this._networkElementType = (esriNetworkElementType)Enum.Parse(typeof(esriNetworkElementType), navigatorNetworkElementType.Value, true);
            }

            // <NetworkSourceName>
            XPathNavigator navigatorNetworkSourceName = navigator.SelectSingleNode("NetworkSourceName");
            if (navigatorNetworkSourceName != null) {
                this._networkSourceName = navigatorNetworkSourceName.Value;
            }

            // <NetworkEvaluatorCLSID>
            XPathNavigator navigatorNetworkEvaluatorCLSID = navigator.SelectSingleNode("NetworkEvaluatorCLSID");
            if (navigatorNetworkEvaluatorCLSID != null) {
                this._networkEvaluatorCLSID = navigatorNetworkEvaluatorCLSID.Value;
            }

            // <NetworkEdgeDirection>
            XPathNavigator navigatorNetworkEdgeDirection = navigator.SelectSingleNode("NetworkEdgeDirection");
            if (navigatorNetworkEdgeDirection != null) {
                this._networkEdgeDirection = (esriNetworkEdgeDirection)Enum.Parse(typeof(esriNetworkEdgeDirection), navigatorNetworkEdgeDirection.Value, true);
            }

            // <NetworkEvaluatorData><PropertyArray><PropertySetProperty>
            this._networkEvaluatorData = new List<Property>();
            XPathNodeIterator interatorProperty = navigator.Select("NetworkEvaluatorData/PropertyArray/PropertySetProperty");
            while (interatorProperty.MoveNext()) {
                // Get <PropertySetProperty>
                XPathNavigator navigatorProperty = interatorProperty.Current;

                // Add PropertySetProperty
                Property property = new Property(navigatorProperty);
                this._networkEvaluatorData.Add(property);
            }
        }
Example #18
0
        private string GenerateDataString(ref IRow row)
        {
            string textOut = "";

            // On a zero-based index, iterate through the fields in the collection.
            for (int fieldIndex = 0; fieldIndex < row.Fields.FieldCount; fieldIndex++)
            {
                if (fieldIndex > 0)
                {
                    textOut += DELIMITER;
                }
                IField field = row.Fields.get_Field(fieldIndex);

                // for shape fields in a point layer, export the associated X and Y coordinates
                if (field.Type == esriFieldType.esriFieldTypeGeometry)
                {
                    if (field.GeometryDef.GeometryType == esriGeometryType.esriGeometryPoint)
                    {
                        // x y location information must be retrieved from the Feature
                        IPoint point = row.get_Value(fieldIndex) as ESRI.ArcGIS.Geometry.Point;
                        textOut += point.X.ToString();
                        textOut += DELIMITER;
                        textOut += point.Y.ToString();
                    }
                    else if (field.GeometryDef.GeometryType == esriGeometryType.esriGeometryPolyline ||
                             field.GeometryDef.GeometryType == esriGeometryType.esriGeometryPolygon)
                    {
                        StringBuilder stringBuffer    = new StringBuilder();
                        var           pointCollection = row.get_Value(fieldIndex) as IPointCollection;
                        for (int pointIndex = 0; pointIndex < pointCollection.PointCount; pointIndex++)
                        {
                            IPoint point = pointCollection.get_Point(pointIndex);

                            if (pointIndex > 0)
                            {
                                stringBuffer.Append(",");
                            }
                            stringBuffer.Append("{");
                            stringBuffer.Append(point.X);
                            stringBuffer.Append(",");
                            stringBuffer.Append(point.Y);
                            stringBuffer.Append(",");
                            stringBuffer.Append(point.Z);
                            stringBuffer.Append(",");
                            stringBuffer.Append(point.M);
                            stringBuffer.Append("}");
                        }
                        textOut += stringBuffer.ToString();
                    }
                    else
                    {
                        textOut += "Shape";
                    }
                }
                // Handle the Locations field for polyline and polygon barrier classes
                else if (field.Name == "Locations" && field.Type == esriFieldType.esriFieldTypeBlob)
                {
                    StringBuilder stringBuffer = new StringBuilder();


                    // get the location ranges out of the barrier feature
                    var naLocRangesObject = row as INALocationRangesObject;
                    if (naLocRangesObject == null) // Not a location ranges object
                    {
                        textOut += row.get_Value(fieldIndex).ToString();
                    }

                    var naLocRanges = naLocRangesObject.NALocationRanges;
                    if (naLocRanges == null) // does not have any location ranges
                    {
                        textOut += row.get_Value(fieldIndex).ToString();
                    }

                    // add all of the junctions included in the barrier to the Junctions dataGrid
                    stringBuffer.Append("{Junctions:{");
                    long junctionCount = naLocRanges.JunctionCount;
                    int  junctionEID   = -1;
                    for (int i = 0; i < junctionCount; i++)
                    {
                        naLocRanges.QueryJunction(i, ref junctionEID);

                        if (i > 0)
                        {
                            stringBuffer.Append(",");
                        }
                        stringBuffer.Append("{");
                        stringBuffer.Append(junctionEID);
                        stringBuffer.Append("}");
                    }
                    stringBuffer.Append("}");

                    // add all of the edges included in the barrier to the Edges dataGrid
                    stringBuffer.Append(",EdgeRanges:{");
                    long   edgeRangeCount = naLocRanges.EdgeRangeCount;
                    int    edgeEID = -1;
                    double fromPosition, toPosition;
                    fromPosition = toPosition = -1;
                    esriNetworkEdgeDirection edgeDirection = esriNetworkEdgeDirection.esriNEDNone;
                    for (int i = 0; i < edgeRangeCount; i++)
                    {
                        naLocRanges.QueryEdgeRange(i, ref edgeEID, ref edgeDirection, ref fromPosition, ref toPosition);

                        string directionValue = "";
                        if (edgeDirection == esriNetworkEdgeDirection.esriNEDAlongDigitized)
                        {
                            directionValue = "Along Digitized";
                        }
                        else if (edgeDirection == esriNetworkEdgeDirection.esriNEDAgainstDigitized)
                        {
                            directionValue = "Against Digitized";
                        }

                        if (i > 0)
                        {
                            stringBuffer.Append(",");
                        }
                        stringBuffer.Append("{");
                        stringBuffer.Append(edgeEID);
                        stringBuffer.Append(",");
                        stringBuffer.Append(directionValue);
                        stringBuffer.Append(",");
                        stringBuffer.Append(fromPosition);
                        stringBuffer.Append(",");
                        stringBuffer.Append(toPosition);
                        stringBuffer.Append("}");
                    }
                    stringBuffer.Append("}");

                    textOut += stringBuffer.ToString();
                }
                else
                {
                    textOut += row.get_Value(fieldIndex).ToString();
                }
            }
            return(textOut);
        }
		public static void SetEvaluator(IEvaluatedNetworkAttribute netAttribute, INetworkSource netSource, Type t, esriNetworkEdgeDirection dirType)
		{
			object obj = Activator.CreateInstance(t);
			INetworkEvaluator eval = obj as INetworkEvaluator;
			netAttribute.set_Evaluator(netSource, dirType, eval);
		}