/// <summary> /// Gets the fiber record for a given fiber number on a given cable ft /// </summary> /// <param name="cableFeature"></param> /// <param name="fiberNumber"></param> /// <returns>IRow</returns> private ESRI.ArcGIS.Geodatabase.IRow GetFiberRecord(ESRI.ArcGIS.Geodatabase.IFeature cableFeature, int fiberNumber) { ESRI.ArcGIS.Geodatabase.IRow result = null; ESRI.ArcGIS.Geodatabase.IRelationshipClass fiberRelationship = GdbUtils.GetRelationshipClass(cableFeature.Class, ConfigUtil.FiberCableToFiberRelClassName); if (null != fiberRelationship && null != fiberRelationship.DestinationClass) { ESRI.ArcGIS.Geodatabase.ITable fiberTable = fiberRelationship.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable; if (null != fiberTable) { ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); filter.WhereClause = string.Format("{0}='{1}' AND {2}={3}", fiberRelationship.OriginForeignKey, cableFeature.get_Value(cableFeature.Fields.FindField(fiberRelationship.OriginPrimaryKey)), ConfigUtil.Fiber_NumberFieldName, fiberNumber); ESRI.ArcGIS.Geodatabase.ICursor cursor = null; try { cursor = fiberTable.Search(filter, false); result = cursor.NextRow(); } finally { if (null != cursor) { ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(cursor); } } } } return(result); }
/// <summary> /// Splice closure features can have related: /// splice records /// </summary> /// <param name="spliceFt">Deleted IFeature</param> private void CascadeSpliceClosureDelete(ESRI.ArcGIS.Geodatabase.IFeature spliceFt) { SpliceClosureWrapper splice = new SpliceClosureWrapper(spliceFt); // Delete fiber splices _spliceHelper.BreakAllSplices(splice, true); }
//public static FiberDeviceConnectionHelper Instance(HookHelperExt hookHelper, ESRI.ArcGIS.Editor.IEditor editor) //{ // if(_instance != null) // { // return _instance; // } // else // { // _instance = new FiberDeviceConnectionHelper(hookHelper, editor); // return _instance; // } //} /// <summary> /// Returns cables which have an endpoint coincident with the device point /// </summary> /// <param name="deviceWrapper">Device to check</param> /// <returns>List of ConnectableCableWrapper</returns> public List <ConnectableCableWrapper> GetCoincidentCables(DeviceWrapper deviceWrapper) { List <ConnectableCableWrapper> result = new List <ConnectableCableWrapper>(); if (null == deviceWrapper) { throw new ArgumentNullException("deviceWrapper"); } ESRI.ArcGIS.Geometry.IPoint devicePoint = deviceWrapper.Feature.Shape as ESRI.ArcGIS.Geometry.IPoint; ESRI.ArcGIS.Carto.IFeatureLayer cableLayer = _hookHelper.FindFeatureLayer(ConfigUtil.FiberCableFtClassName); ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = cableLayer.FeatureClass; int displayIdx = cableFtClass.FindField(cableLayer.DisplayField); double buffer = _hookHelper.ConvertPixelsToMapUnits(1); List <ESRI.ArcGIS.Geodatabase.IFeature> coincidentCables = GdbUtils.GetLinearsWithCoincidentEndpoints(devicePoint, cableFtClass, buffer); for (int i = 0; i < coincidentCables.Count; i++) { ESRI.ArcGIS.Geodatabase.IFeature ft = coincidentCables[i]; ESRI.ArcGIS.Geometry.IPolyline line = ft.Shape as ESRI.ArcGIS.Geometry.IPolyline; ESRI.ArcGIS.Geometry.IRelationalOperator lineToPoint = line.ToPoint as ESRI.ArcGIS.Geometry.IRelationalOperator; bool isFromEnd = true; if (lineToPoint.Equals(devicePoint)) { isFromEnd = false; } result.Add(new ConnectableCableWrapper(ft, isFromEnd, displayIdx)); } return(result); }
/// <summary> /// Generates a splice closure at the coincident endpoint. Does not start an edit operation. /// </summary> /// <param name="cableA">Cable A</param> /// <param name="cableB">Cable B</param> /// <returns>SpliceClosureWRapper based on new feature</returns> private SpliceClosureWrapper GenerateSpliceClosure(FiberCableWrapper cableA, SpliceableCableWrapper cableB) { SpliceClosureWrapper wrapper = null; #region Validation if (null == cableA) { throw new ArgumentNullException("cableA"); } if (null == cableB) { throw new ArgumentNullException("cableB"); } if (ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing == _editor.EditState) { throw new InvalidOperationException("You must be editing to perform this operation"); } #endregion // Populate an IPID; we will need it Guid g = Guid.NewGuid(); string spliceIpid = g.ToString("B").ToUpper(); try { ESRI.ArcGIS.Geometry.IPolyline line = cableB.Feature.Shape as ESRI.ArcGIS.Geometry.IPolyline; if (null != line) { ESRI.ArcGIS.Geometry.IPoint splicePoint = null; if (cableB.IsThisFromEnd) { splicePoint = line.FromPoint; } else { splicePoint = line.ToPoint; } ESRI.ArcGIS.Geodatabase.IFeatureClass spliceClosureFtClass = _wkspHelper.FindFeatureClass(ConfigUtil.SpliceClosureFtClassName); // ESRI.ArcGIS.Geodatabase.IFeatureClass spliceClosureFtClass = GdbUtils.GetFeatureClass(cableA.Feature.Class, ConfigUtil.SpliceClosureFtClassName); ESRI.ArcGIS.Geodatabase.IFeature spliceFt = spliceClosureFtClass.CreateFeature(); spliceFt.Shape = splicePoint; spliceFt.set_Value(spliceClosureFtClass.Fields.FindField(ConfigUtil.IpidFieldName), spliceIpid); spliceFt.Store(); wrapper = new SpliceClosureWrapper(spliceFt); } } catch { wrapper = null; } return(wrapper); }
/// <summary> /// Cable features can have related: /// splices, /// connections, /// strands /// buffer tubes, /// maintenance loop /// </summary> /// <param name="cableFeature">Deleted IFeature</param> private void CascadeFiberCableDelete(ESRI.ArcGIS.Geodatabase.IFeature cableFeature) { FiberCableWrapper cable = new FiberCableWrapper(cableFeature); // Delete splices (to other cables) _spliceHelper.BreakAllSplices(cable, true); // Delete connections (to equipment) _connectionHelper.BreakAllConnections(cable, true); }
/// <summary> /// Delete the ports for a given device /// </summary> /// <param name="device">The device feature</param> /// <returns>True if completed</returns> private bool DeletePorts(ESRI.ArcGIS.Geodatabase.IFeature device, int highInputPort, int highOutputPort, ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog, ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel) { bool isCancelled = false; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = (ESRI.ArcGIS.esriSystem.IStepProgressor)progressDialog; ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship((ESRI.ArcGIS.Geodatabase.IFeatureClass)device.Class); if (null != deviceHasPorts) { using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.ITable portTable = (ESRI.ArcGIS.Geodatabase.ITable)deviceHasPorts.DestinationClass; releaser.ManageLifetime(portTable); ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); filter.WhereClause = string.Format("{0}='{1}' AND {2} > {3} AND {4}='{5}'", deviceHasPorts.OriginForeignKey, device.get_Value(device.Fields.FindField(deviceHasPorts.OriginPrimaryKey)), ConfigUtil.PortIdFieldName, highInputPort, ConfigUtil.PortTypeFieldName, 1); stepProgressor.Message = "Deleting higher input ports..."; int deletedPorts = portTable.RowCount(filter); portTable.DeleteSearchedRows(filter); for (int i = 0; i < deletedPorts; i++) { stepProgressor.Step(); } filter.WhereClause = string.Format("{0}='{1}' AND {2} > {3} AND {4}='{5}'", deviceHasPorts.OriginForeignKey, device.get_Value(device.Fields.FindField(deviceHasPorts.OriginPrimaryKey)), ConfigUtil.PortIdFieldName, highOutputPort, ConfigUtil.PortTypeFieldName, 2); stepProgressor.Message = "Deleting higher output ports..."; deletedPorts = portTable.RowCount(filter); portTable.DeleteSearchedRows(filter); for (int i = 0; i < deletedPorts; i++) { stepProgressor.Step(); } } } return(!isCancelled); }
/// <summary> /// Constructs a new FeatureWrapper /// </summary> /// <param name="feature">IFeature</param> public FeatureWrapper(ESRI.ArcGIS.Geodatabase.IFeature feature) { if (null == feature) { throw new ArgumentNullException("feature"); } else if (null == feature.Class) { throw new ArgumentException("feature.Class cannot be null"); } _feature = feature; CacheToString(); }
//鼠标点击事件 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (pMouseOperate == "ZoomIn") { axMapControl1.Extent = axMapControl1.TrackRectangle(); } if (pMouseOperate == "ZoomOut") { IEnvelope penv = axMapControl1.Extent; penv.Expand(2, 2, true); axMapControl1.Extent = penv; } if (pMouseOperate == "Pan") { axMapControl1.Pan(); } if (pMouseOperate == "Identify") { IPoint point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(e.mapX, e.mapY); IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; string shapefieldname = pFeatureClass.ShapeFieldName; ESRI.ArcGIS.Geodatabase.ISpatialFilter pSpatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilter(); pSpatialFilter.Geometry = point; pSpatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.set_OutputSpatialReference(shapefieldname, axMapControl1.SpatialReference); pSpatialFilter.GeometryField = shapefieldname; ESRI.ArcGIS.Geodatabase.IFeatureCursor pFeatureCursor = pFeatureClass.Search(pSpatialFilter, false); ESRI.ArcGIS.Geodatabase.IFeature pFeature = pFeatureCursor.NextFeature(); if (pFeature != null) { axMapControl1.FlashShape(pFeature.Shape); } IFields pField = pFeature.Fields; listFields.Items.Clear(); for (int i = 0; i <= pField.FieldCount - 1; i++) { listFields.Items.Add(pField.get_Field(i).Name + "=" + pFeature.get_Value(i)); } } }
//public static FiberSpliceConnectionHelper Instance(object hook, ESRI.ArcGIS.Editor.IEditor editor) //{ // if (_instance != null) // { // return _instance; // } // else // { // _instance = new FiberSpliceConnectionHelper(hook, editor); // return _instance; // } //} /// <summary> /// Gets a list of cable features that are connected to the splice closure in the geometric network /// </summary> /// <param name="spliceClosure">Splice to check</param> /// <returns>List of IFeature</returns> public List <ESRI.ArcGIS.Geodatabase.IFeature> GetConnectedCables(SpliceClosureWrapper spliceClosure) { // At the time of this comment, splicable means they are connected in the // geometric network and the splice closure "touches" one of the ends of the cable List <ESRI.ArcGIS.Geodatabase.IFeature> result = new List <ESRI.ArcGIS.Geodatabase.IFeature>(); if (null == spliceClosure) { throw new ArgumentNullException("spliceClosure"); } ESRI.ArcGIS.Geometry.IRelationalOperator relOp = spliceClosure.Feature.Shape as ESRI.ArcGIS.Geometry.IRelationalOperator; if (relOp == null) { throw new ArgumentNullException("spliceClosure"); } ESRI.ArcGIS.Geodatabase.ISimpleJunctionFeature junction = spliceClosure.Feature as ESRI.ArcGIS.Geodatabase.ISimpleJunctionFeature; if (null != junction) { for (int i = 0; i < junction.EdgeFeatureCount; i++) { ESRI.ArcGIS.Geodatabase.IFeature connectedEdge = junction.get_EdgeFeature(i) as ESRI.ArcGIS.Geodatabase.IFeature; ESRI.ArcGIS.Geodatabase.IDataset dataset = connectedEdge.Class as ESRI.ArcGIS.Geodatabase.IDataset; string ftClassName = GdbUtils.ParseTableName(dataset); if (0 == string.Compare(ftClassName, ConfigUtil.FiberCableFtClassName, true)) { // Test feature edge is coincident with splice closure. Cables are // complex features so splice might lie half way along some cables // but will not be providing any splice connectivity to them. if (relOp.Touches(connectedEdge.Shape)) // only true if point at either end of a line { result.Add(connectedEdge); } } } } return(result); }
/// <summary> /// Returns a nullable int value for a given field on a feature. If the field uses a coded value domain, the name for /// the value is returned. /// </summary> /// <param name="feature">IFeature</param> /// <param name="fieldName">Name of the field that holds the value</param> /// <returns>int?</returns> public static int?GetDomainedIntName(ESRI.ArcGIS.Geodatabase.IFeature feature, string fieldName) { int?result = null; #region Validation if (null == feature) { throw new ArgumentNullException("feature"); } int fieldIdx = feature.Fields.FindField(fieldName); if (-1 == fieldIdx) { string message = string.Format("Field {0} does not exist.", fieldName); throw new ArgumentException(message); } #endregion object objValue = feature.get_Value(fieldIdx); if (DBNull.Value != objValue) { ESRI.ArcGIS.Geodatabase.IField field = feature.Fields.get_Field(fieldIdx); string valueString = CheckForCodedName(field, objValue); int parseResult = -1; if (!int.TryParse(valueString, out parseResult)) { string message = string.Format("{0} value {1} could not be parsed to int.", fieldName, valueString); throw new Exception(message); } else { result = parseResult; } } return(result); }
void ucResult_SelectedErrorFeatureChanged(ESRI.ArcGIS.Geodatabase.IFeature selErrorFeature, ESRI.ArcGIS.Geodatabase.IFeature selReferFeature) { if (selReferFeature == null) { this.ucAttribute.SetErrorFeature(selErrorFeature, null); } else { this.ucAttribute.SetErrorFeature(selErrorFeature, "源数据"); this.ucAttribute.SetReferFeature(selReferFeature, "目标数据"); if (this.dockLegend.Visibility == DockVisibility.Visible) { this.dockLegend.Visibility = DockVisibility.AutoHide; } if (this.dockAttribute.Visibility != DockVisibility.Visible) { this.dockAttribute.Visibility = DockVisibility.Visible; } } }
protected override void editor_OnCreateFeature(ESRI.ArcGIS.Geodatabase.IObject obj) { ESRI.ArcGIS.Geodatabase.IFeature feature = obj as ESRI.ArcGIS.Geodatabase.IFeature; if (null != feature && null != feature.Class) { ESRI.ArcGIS.Geodatabase.IDataset dataset = (ESRI.ArcGIS.Geodatabase.IDataset)feature.Class; string tableName = GdbUtils.ParseTableName(dataset); if (ConfigUtil.IsDeviceClassName(tableName)) { if (InputPorts != Int32.MinValue && OutputPorts != Int32.MinValue) { try { ConfigureDevice(feature, InputPorts, OutputPorts, true); } catch (Exception ex) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Failed to configure device.", ex.Message); string message = "Failed to configure device:" + System.Environment.NewLine + ex.Message; MessageBox.Show(message, "Configure Device", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { AbortOperation(); _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Port counts are not set.", "Please specify a valid configuration of port settings."); string message = "Port counts are not set." + System.Environment.NewLine + "Please specify a valid configuration of port settings."; MessageBox.Show(message, "Configure Device", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }
/// <summary> /// Flashes the given feature on the hook's active view /// </summary> /// <param name="msPause">Pause between flashes</param> /// <param name="times">Number of times to flash</param> /// <param name="feature">Feature to flash</param> public void FlashFeature(ESRI.ArcGIS.Geodatabase.IFeature feature, int times, int msPause) { if (null == feature) { throw new ArgumentNullException("feature"); } if (null != this.ActiveView) { ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = this.ActiveView.ScreenDisplay; if (null != screenDisplay) { ESRI.ArcGIS.Carto.IIdentifyObj obj = new FeatureIdentifyObjectClass(); ((ESRI.ArcGIS.Carto.IFeatureIdentifyObj)obj).Feature = feature; for (int i = 0; i < times; i++) { obj.Flash(screenDisplay); System.Threading.Thread.Sleep(msPause); } } } }
/// <summary> /// Sets the input and output ports based on the given configuration. If IPID and/or CABLEID are null, it also /// takes care of them /// </summary> /// <param name="feature">The device feature to configure</param> /// <param name="inputPorts">Number of input ports</param> /// <param name="outputPorts">Number of output ports</param> /// <param name="isExistingOperation">Flag to control whether this method is being called from within an existing /// edit operation -- the default behavior is "false" in which case it adds an operation of its own</param> /// <returns>True if the configuration is complete</returns> public bool ConfigureDevice(ESRI.ArcGIS.Geodatabase.IFeature feature, int inputPorts, int outputPorts, bool isExistingOperation) { bool isComplete = false; bool isOurOperationOpen = false; string deviceIpid = string.Empty; #region Validation string missingFieldFormat = "Field {0} is missing."; // The following will be set during Validation ESRI.ArcGIS.Geodatabase.IObjectClass ftClass = null; ESRI.ArcGIS.Geodatabase.IFields fields = null; ftClass = feature.Class; fields = ftClass.Fields; if (null == feature) { throw new ArgumentNullException("feature"); } if (_editor.EditState == ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing) { throw new InvalidOperationException("You must be editing the workspace to perform this operation."); } if (0 > inputPorts) { throw new ArgumentOutOfRangeException("inputPorts"); } if (0 > outputPorts) { throw new ArgumentOutOfRangeException("outputPorts"); } int ipidIdx = fields.FindField(ConfigUtil.IpidFieldName); if (-1 == ipidIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.IpidFieldName)); } int inPortsIdx = fields.FindField(ConfigUtil.InputPortsFieldName); if (-1 == inPortsIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.InputPortsFieldName)); } int outPortsIdx = fields.FindField(ConfigUtil.OutputPortsFieldName); if (-1 == outPortsIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.OutputPortsFieldName)); } #endregion // Are we RE-configuring? // int? oldInputPorts = GdbUtils.GetDomainedIntName(feature, ConfigUtil.InputPortsFieldName); // int? oldOutputPorts = GdbUtils.GetDomainedIntName(feature, ConfigUtil.OutputPortsFieldName); // int inputPortDifference = oldInputPorts.HasValue ? Math.Abs(inputPorts - oldInputPorts.Value) : inputPorts; // int outputPortDifference = oldOutputPorts.HasValue ? Math.Abs(outputPorts - oldOutputPorts.Value) : outputPorts; ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = _hookHelper.CreateProgressDialog(trackCancel, "Configuring device...", 1, inputPorts + outputPorts, 1, "Starting edit operation...", "Device Configuration"); // ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = CreateProgressDialog(trackCancel, "Configuring device...", 1, inputPortDifference + outputPortDifference + 2, 1, "Starting edit operation...", "Device Configuration"); ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = (ESRI.ArcGIS.esriSystem.IStepProgressor)progressDialog; progressDialog.ShowDialog(); stepProgressor.Step(); if (!isExistingOperation) { try { _editor.StartOperation(); isOurOperationOpen = true; } catch (Exception ex) { throw new Exception("Failed to start edit operation.", ex); } } try { feature.set_Value(inPortsIdx, inputPorts); feature.set_Value(outPortsIdx, outputPorts); if (DBNull.Value == feature.get_Value(ipidIdx)) { Guid g = Guid.NewGuid(); deviceIpid = g.ToString("B").ToUpper(); feature.set_Value(ipidIdx, deviceIpid); } else { deviceIpid = feature.get_Value(ipidIdx).ToString(); } // if (!oldOutputPorts.HasValue && !oldInputPorts.HasValue) // { isComplete = GeneratePorts(feature, 1, inputPorts, 1, outputPorts, progressDialog, trackCancel); // } // else // { // bool additionsComplete = false; // bool deletionsComplete = false; // // additionsComplete = GeneratePorts(feature, oldInputPorts.Value + 1, oldInputPorts.Value + inputPortDifference, oldOutputPorts.Value + 1, oldOutputPorts.Value + outputPortDifference, progressDialog, trackCancel); // deletionsComplete = DeletePorts(feature, inputPorts, outputPorts, progressDialog, trackCancel); // // isComplete = additionsComplete && deletionsComplete; // } if (isComplete) { stepProgressor.Message = "Finishing configuration..."; stepProgressor.Step(); if (isOurOperationOpen) { feature.Store(); _editor.StopOperation("Configure Device"); } } else { stepProgressor.Message = "Cancelling configuration..."; stepProgressor.Step(); if (isOurOperationOpen) { _editor.AbortOperation(); } } } catch { if (isOurOperationOpen) { _editor.AbortOperation(); } } if (null != progressDialog) { progressDialog.HideDialog(); } return(isComplete); }
ISymbol IFeatureRenderer.get_SymbolByFeature(ESRI.ArcGIS.Geodatabase.IFeature Feature) { ISymbol pSymbol = m_pLegendGroup.get_Class(0).Symbol; return(pSymbol); }
/// <summary> /// Flashes the feature 3 times with a 250ms pause /// </summary> /// <param name="feature">Feature to flash</param> public void FlashFeature(ESRI.ArcGIS.Geodatabase.IFeature feature) { FlashFeature(feature, 3, 250); }
/// <summary> /// Gets all cables that are considered splicable to another cable at a given splice closure. /// </summary> /// <param name="cable">Cable to splice with</param> /// <param name="spliceClosure">Splice Closure to splice at</param> /// <returns>List of SpliceableCableWrapper</returns> public List <SpliceableCableWrapper> GetSpliceableCables(FiberCableWrapper cable, SpliceClosureWrapper spliceClosure) { // At the time of this comment, splicable means they are connected in the geometric network List <SpliceableCableWrapper> result = new List <SpliceableCableWrapper>(); if (null == cable) { throw new ArgumentNullException("cable"); } if (null == spliceClosure) { throw new ArgumentNullException("spliceClosure"); } int searchOid = cable.Feature.OID; ESRI.ArcGIS.Geodatabase.IEdgeFeature cableFt = cable.Feature as ESRI.ArcGIS.Geodatabase.IEdgeFeature; ESRI.ArcGIS.Carto.IFeatureLayer ftLayer = _hookHelper.FindFeatureLayer(ConfigUtil.FiberCableFtClassName); int displayIdx = ftLayer.FeatureClass.FindField(ftLayer.DisplayField); if (null != cableFt) { // We assume it is simple. Complex junctions are not supported for splicing cables ESRI.ArcGIS.Geodatabase.ISimpleJunctionFeature junction = spliceClosure.Feature as ESRI.ArcGIS.Geodatabase.ISimpleJunctionFeature; if (null != junction) { bool isAFromEnd = false; // would be in the case that junction.EID == cableFt.ToJunctionEID if (junction.EID == cableFt.FromJunctionEID) { isAFromEnd = true; } else if (junction.EID != cableFt.ToJunctionEID) { // It isn't the from or the two? It shouldn't have been passed in as if it was coincident with the cable return(result); // throw new InvalidOperationException("Given splice closure is not the junction for the given cable."); } int edgeCount = junction.EdgeFeatureCount; for (int i = 0; i < edgeCount; i++) { ESRI.ArcGIS.Geodatabase.IEdgeFeature connectedEdge = junction.get_EdgeFeature(i); ESRI.ArcGIS.Geodatabase.IFeature feature = (ESRI.ArcGIS.Geodatabase.IFeature)connectedEdge; ESRI.ArcGIS.Geodatabase.IDataset dataset = feature.Class as ESRI.ArcGIS.Geodatabase.IDataset; string featureClassName = GdbUtils.ParseTableName(dataset); if (0 == string.Compare(featureClassName, ConfigUtil.FiberCableFtClassName) && feature.OID != searchOid) { if (junction.EID == connectedEdge.FromJunctionEID) { result.Add(new SpliceableCableWrapper(feature, true, isAFromEnd, displayIdx)); } else if (junction.EID == connectedEdge.ToJunctionEID) { result.Add(new SpliceableCableWrapper(feature, false, isAFromEnd, displayIdx)); } } } } } return(result); }
public override IGISFeature CreateFeature(ESRI.ArcGIS.Geodatabase.IFeature feature) { return(new Ao.Features.AoMultiPointFeature(feature, GetFeatureClass().ShapeFieldName)); }
/// <summary> /// Returns all features from a given feature class that have a vertex or endpoint coincident with a given point /// </summary> /// <param name="point">IPoint to use as the spatial filter</param> /// <param name="searchFtClass">IFeatureClass to search in</param> /// <param name="linearEndpointsOnly">Flag to use only the endpoints of a line instead of all vertices</param> /// <param name="buffer">Search geometry buffer in map units</param> /// <returns>List of IFeature</returns> public static List <ESRI.ArcGIS.Geodatabase.IFeature> GetFeaturesWithCoincidentVertices(ESRI.ArcGIS.Geometry.IPoint point, ESRI.ArcGIS.Geodatabase.IFeatureClass searchFtClass, bool linearEndpointsOnly, double buffer) { List <ESRI.ArcGIS.Geodatabase.IFeature> result = new List <ESRI.ArcGIS.Geodatabase.IFeature>(); using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.ISpatialFilter filter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass(); releaser.ManageLifetime(filter); ESRI.ArcGIS.Geometry.IEnvelope filterGeometry = point.Envelope; if (0 < buffer) { filterGeometry.Expand(buffer, buffer, false); } filter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects; filter.Geometry = filterGeometry; ESRI.ArcGIS.Geodatabase.IFeatureCursor fts = searchFtClass.Search(filter, false); releaser.ManageLifetime(fts); ESRI.ArcGIS.Geodatabase.IFeature ft = fts.NextFeature(); while (null != ft) { if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint) { result.Add(ft); } else if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline && linearEndpointsOnly) { ESRI.ArcGIS.Geometry.IPolyline polyline = (ESRI.ArcGIS.Geometry.IPolyline)ft.Shape; ESRI.ArcGIS.Geometry.IRelationalOperator fromPoint = polyline.FromPoint as ESRI.ArcGIS.Geometry.IRelationalOperator; ESRI.ArcGIS.Geometry.IRelationalOperator toPoint = polyline.ToPoint as ESRI.ArcGIS.Geometry.IRelationalOperator; if (fromPoint.Equals(point) || toPoint.Equals(point)) { result.Add(ft); } } else { ESRI.ArcGIS.Geometry.IPointCollection pointCollection = ft.Shape as ESRI.ArcGIS.Geometry.IPointCollection; if (null != pointCollection) { for (int i = 0; i < pointCollection.PointCount; i++) { ESRI.ArcGIS.Geometry.IRelationalOperator testPoint = pointCollection.get_Point(i) as ESRI.ArcGIS.Geometry.IRelationalOperator; if (testPoint.Equals(point)) { result.Add(ft); break; } } } } ft = fts.NextFeature(); } } return(result); }
ESRI.ArcGIS.Display.ISymbol IFeatureRenderer.get_SymbolByFeature(ESRI.ArcGIS.Geodatabase.IFeature Feature) { return GetFeatureSymbol(Feature); }
/// <summary> /// Ripple down from the desired start point tracing and highlighting the results. /// </summary> public void TraceTriggered(FeatureWrapper feature, int unit, PortType port = PortType.Input) { try { if (null == feature) { throw new ArgumentNullException("FeatureWrapper"); } FiberCableWrapper fiberCableWrapper = feature as FiberCableWrapper; DeviceWrapper deviceWrapper = feature as DeviceWrapper; int fiberNumber = unit; _startedOnFiber = true; if (null != deviceWrapper) { fiberCableWrapper = GetConnectedFiber(deviceWrapper, unit, port, out fiberNumber); _startedOnFiber = false; } List <Range> traceRange = new List <Range>(new Range[] { new Range(fiberNumber, fiberNumber) }); if (null != fiberCableWrapper) { if (SpliceAndConnectionUtils.AreRangesWithinFiberCount(traceRange, fiberCableWrapper)) { ESRI.ArcGIS.Geodatabase.IFeature ft = fiberCableWrapper.Feature; _traceResults.Clear(); _traceResults = TracePath(ft, fiberNumber, true); _traceResults.Reverse(); // This went down the "from end", so they are backwards _startFiberIdx = _traceResults.Count; // Now add ourselves _traceResults.Add(ft); _traceResults.Add(GetFiberRecord(ft, fiberNumber)); // Now add everything going the other way List <ESRI.ArcGIS.Geodatabase.IRow> resultsAtToEnd = TracePath(ft, fiberNumber, false); _traceResults.AddRange(resultsAtToEnd); if (TraceCompleted != null) { TraceCompleted(this, null); } } else { System.Windows.Forms.MessageBox.Show("Fiber strand number is not within the fiber cable's number of fibers.", "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } } else { System.Windows.Forms.MessageBox.Show("No fiber cable / strand was specified, or none was connected to the specified port.", "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } // --------------------------------------- // This causes a refresh of the selection // and we see the results of the trace on // the map // --------------------------------------- _hookHelper.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null); // ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "ERROR"); System.Diagnostics.Trace.WriteLine(ex.StackTrace, "DETAILS"); } finally { } }
/// <summary> /// Splices all available strands from one cable to the other, at a given splice closure /// </summary> /// <param name="cableA">Cable A</param> /// <param name="cableB">Cable B</param> /// <param name="splice">Splice Closure</param> /// <param name="strands">Strands to splice together</param> /// <param name="isExistingOperation">Flag to control whether we need to wrap this in an edit operation</param> /// <returns>Success</returns> public bool CreateSplices(FiberCableWrapper cableA, SpliceableCableWrapper cableB, SpliceClosureWrapper splice, Dictionary <int, FiberSplice> strands, bool isExistingOperation) { bool success = false; bool isOperationOpen = false; #region Validation if (null == cableA) { throw new ArgumentNullException("cableA"); } if (null == cableB) { throw new ArgumentNullException("cableB"); } if (ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing == _editor.EditState) { throw new InvalidOperationException("You must be editing to perform this operation"); } #endregion if (!isExistingOperation) { _editor.StartOperation(); isOperationOpen = true; } if (null == splice) { splice = GenerateSpliceClosure(cableA, cableB); } else if (0 == splice.IPID.Length) { // Populate an IPID; we will need it ESRI.ArcGIS.Geodatabase.IFeature spliceFt = splice.Feature; Guid g = Guid.NewGuid(); spliceFt.set_Value(spliceFt.Fields.FindField(ConfigUtil.IpidFieldName), g.ToString("B").ToUpper()); spliceFt.Store(); } try { ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = _wkspHelper.FindTable(ConfigUtil.FiberSpliceTableName); // ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = GdbUtils.GetTable(cableA.Feature.Class, ConfigUtil.FiberSpliceTableName); int aCableIdx = fiberSpliceTable.FindField(ConfigUtil.ACableIdFieldName); int bCableIdx = fiberSpliceTable.FindField(ConfigUtil.BCableIdFieldName); int aFiberNumIdx = fiberSpliceTable.FindField(ConfigUtil.AFiberNumberFieldName); int bFiberNumIdx = fiberSpliceTable.FindField(ConfigUtil.BFiberNumberFieldName); int spliceIpidIdx = fiberSpliceTable.FindField(ConfigUtil.SpliceClosureIpidFieldName); int isAFromIdx = fiberSpliceTable.FindField(ConfigUtil.IsAFromEndFieldName); int isBFromIdx = fiberSpliceTable.FindField(ConfigUtil.IsBFromEndFieldName); int lossIdx = fiberSpliceTable.FindField(ConfigUtil.LossFieldName); int typeIdx = fiberSpliceTable.FindField(ConfigUtil.TypeFieldName); ESRI.ArcGIS.Geodatabase.IField typeField = fiberSpliceTable.Fields.get_Field(typeIdx); string aCableId = cableA.IPID; string bCableId = cableB.IPID; string isAFromEnd = cableB.IsOtherFromEnd ? "T" : "F"; string isBFromEnd = cableB.IsThisFromEnd ? "T" : "F"; string spliceIpid = splice.IPID; using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { // TODO cant use insert cursor since edit events wont fire. // We need evetns to fire for dynamic values to get populated. // ESRI.ArcGIS.Geodatabase.ICursor insertCursor = fiberSpliceTable.Insert(true); // releaser.ManageLifetime(insertCursor); foreach (KeyValuePair <int, FiberSplice> pair in strands) { IRow row = fiberSpliceTable.CreateRow(); releaser.ManageLifetime(row); FiberSplice fiberSplice = pair.Value; row.set_Value(aCableIdx, aCableId); row.set_Value(bCableIdx, bCableId); row.set_Value(aFiberNumIdx, pair.Key); row.set_Value(bFiberNumIdx, fiberSplice.BRange.Low); row.set_Value(spliceIpidIdx, spliceIpid); row.set_Value(isAFromIdx, isAFromEnd); row.set_Value(isBFromIdx, isBFromEnd); if (null == fiberSplice.Loss) { row.set_Value(lossIdx, DBNull.Value); } else { row.set_Value(lossIdx, fiberSplice.Loss); } object typeValue = DBNull.Value; if (null != fiberSplice.Type) { try { typeValue = GdbUtils.CheckForCodedValue(typeField, fiberSplice.Type); } catch { // TODO: Log a warning about why we can't set the default split splice type? } } row.set_Value(typeIdx, typeValue); row.Store(); } } if (isOperationOpen) { _editor.StopOperation("Edit Splices"); } success = true; } catch { if (isOperationOpen) { _editor.AbortOperation(); } success = false; } return(success); }
private void CreateFlybyFromPathAnimation(ESRI.ArcGIS.GlobeCore.IGlobe globe, ESRI.ArcGIS.Geodatabase.IFeature lineFeature, ESRI.ArcGIS.Animation.IAGImportPathOptions AGImportPathOptionsCls) { ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay = globe.GlobeDisplay; ESRI.ArcGIS.Analyst3D.IScene scene = globeDisplay.Scene; // Get a handle to the animation extension ESRI.ArcGIS.Analyst3D.IBasicScene2 basicScene2 = (ESRI.ArcGIS.Analyst3D.IBasicScene2)scene; // Explicit Cast ESRI.ArcGIS.Animation.IAnimationExtension animationExtension = basicScene2.AnimationExtension; // Get the geometry of the line feature ESRI.ArcGIS.Geometry.IGeometry geometry = lineFeature.Shape; // Create AGAnimationUtils and AGImportPathOptions objects ESRI.ArcGIS.Animation.IAGAnimationUtils AGAnimationUtilsCls = new ESRI.ArcGIS.Animation.AGAnimationUtilsClass(); AGImportPathOptionsCls.PathGeometry = geometry; AGImportPathOptionsCls.AnimationEnvironment = animationExtension.AnimationEnvironment; ESRI.ArcGIS.Animation.IAGAnimationContainer AGAnimationContainer = animationExtension.AnimationTracks.AnimationObjectContainer; // Call "CreateFlybyFromPath" method AGAnimationUtilsCls.CreateFlybyFromPath(AGAnimationContainer, AGImportPathOptionsCls); }
///// <summary> ///// The active view has refreshed. Redraw our results, if we have any ///// </summary> ///// <param name="Display">Display to draw on</param> ///// <param name="phase"></param> //private void _arcMapWrapper_ActiveViewAfterDraw(ESRI.ArcGIS.Display.IDisplay Display, ESRI.ArcGIS.Carto.esriViewDrawPhase phase) //{ // if (phase == ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection) // { // // Draw after the selection // if (null != _currentResults) // { // ESRI.ArcGIS.Display.ILineSymbol lineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbol(); // ESRI.ArcGIS.Display.IRgbColor color = new ESRI.ArcGIS.Display.RgbColorClass(); // color.Red = 255; // color.Green = 0; // color.Blue = 0; // lineSymbol.Color = color; // lineSymbol.Width = 4; // ESRI.ArcGIS.Display.ISimpleMarkerSymbol markerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass(); // markerSymbol.Color = color; // markerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle; // markerSymbol.Size = 6; // for (int i = 0; i < _currentResults.Count; i++) // { // ESRI.ArcGIS.Geometry.IGeometry geometry = _currentResults[i]; // if (geometry is ESRI.ArcGIS.Geometry.IPolyline) // { // Display.SetSymbol((ESRI.ArcGIS.Display.ISymbol)lineSymbol); // Display.DrawPolyline((ESRI.ArcGIS.Geometry.IPolyline)geometry); // } // else if (geometry is ESRI.ArcGIS.Geometry.IPoint) // { // Display.SetSymbol((ESRI.ArcGIS.Display.ISymbol)markerSymbol); // Display.DrawPoint((ESRI.ArcGIS.Geometry.IPoint)geometry); // } // } // } // } //} private List <ESRI.ArcGIS.Geodatabase.IRow> TracePath(ESRI.ArcGIS.Geodatabase.IFeature cableFeature, int fiberNumber, bool isStartingAtFromEnd) { List <ESRI.ArcGIS.Geodatabase.IRow> result = new List <ESRI.ArcGIS.Geodatabase.IRow>(); string ipid = cableFeature.get_Value(cableFeature.Fields.FindField(ConfigUtil.IpidFieldName)).ToString(); ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = (ESRI.ArcGIS.Geodatabase.IFeatureClass)cableFeature.Class; ESRI.ArcGIS.Geodatabase.IFeatureClass spliceFtClass = _wkspHelper.FindFeatureClass(ConfigUtil.SpliceClosureFtClassName); ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = _wkspHelper.FindTable(ConfigUtil.FiberSpliceTableName); ESRI.ArcGIS.Geodatabase.IFields spliceFields = fiberSpliceTable.Fields; string fiberClassName = ConfigUtil.FiberTableName; ESRI.ArcGIS.Geodatabase.IRelationshipClass fiberRelationship = GdbUtils.GetRelationshipClass(cableFtClass, ConfigUtil.FiberCableToFiberRelClassName); if (null != fiberRelationship && null != fiberRelationship.DestinationClass) { fiberClassName = GdbUtils.ParseTableName(fiberRelationship.DestinationClass as ESRI.ArcGIS.Geodatabase.IDataset); } ESRI.ArcGIS.Geodatabase.ITable fiberTable = _wkspHelper.FindTable(fiberClassName); _aCableIdx = spliceFields.FindField(ConfigUtil.ACableIdFieldName); _bCableIdx = spliceFields.FindField(ConfigUtil.BCableIdFieldName); _aFiberNumIdx = spliceFields.FindField(ConfigUtil.AFiberNumberFieldName); _bFiberNumIdx = spliceFields.FindField(ConfigUtil.BFiberNumberFieldName); _isAFromIdx = spliceFields.FindField(ConfigUtil.IsAFromEndFieldName); _isBFromIdx = spliceFields.FindField(ConfigUtil.IsBFromEndFieldName); _spliceClosureIpidIdx = spliceFields.FindField(ConfigUtil.SpliceClosureIpidFieldName); ESRI.ArcGIS.Geodatabase.IQueryFilter spliceFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); spliceFilter.WhereClause = string.Format("({0}='{1}' AND {2}={3})" + " OR ({4}='{1}' AND {5}={3})", ConfigUtil.ACableIdFieldName, ipid, ConfigUtil.AFiberNumberFieldName, fiberNumber, ConfigUtil.BCableIdFieldName, ConfigUtil.BFiberNumberFieldName); int connections = fiberSpliceTable.RowCount(spliceFilter); if (2 < connections) { // TODO: warning? System.Windows.Forms.MessageBox.Show("Less than 2 connections were detected: " + fiberNumber, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } string spliceClosureIpid = string.Empty; string nextCableId = string.Empty; int nextFiberNumber = -1; bool isNextFromEnd = false; // {{0}} causes the string.format to string cableWhereFormat = string.Format("{0}='{{0}}'", ConfigUtil.IpidFieldName); string spliceWhereFormat = string.Format("{0}='{{0}}'", ConfigUtil.IpidFieldName); string fiberWhereFormat = string.Format("{0}='{{0}}' AND {1}={{1}}", fiberRelationship.OriginForeignKey, ConfigUtil.Fiber_NumberFieldName); using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); // Ripple down the start cable's to end ESRI.ArcGIS.Geodatabase.IRow spliceRow = GetNextSplice(fiberSpliceTable, ipid, fiberNumber, isStartingAtFromEnd, out nextCableId, out nextFiberNumber, out spliceClosureIpid, out isNextFromEnd); while (null != spliceRow) { ESRI.ArcGIS.Geodatabase.IFeature spliceClosure = null; if (spliceClosureIpid.Equals("")) { System.Windows.Forms.MessageBox.Show("Found Splice with no SpliceClosure (ID/#) " + nextCableId + "/" + nextFiberNumber, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } else { filter.WhereClause = string.Format(spliceWhereFormat, spliceClosureIpid); ESRI.ArcGIS.Geodatabase.IFeatureCursor spliceCursor = spliceFtClass.Search(filter, false); releaser.ManageLifetime(spliceCursor); spliceClosure = spliceCursor.NextFeature(); if (spliceClosure == null) { System.Windows.Forms.MessageBox.Show("Invalid SpliceClosure referenced: (IPID)" + spliceClosureIpid, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } } filter.WhereClause = string.Format(cableWhereFormat, nextCableId); ESRI.ArcGIS.Geodatabase.IFeatureCursor cableCursor = cableFtClass.Search(filter, false); releaser.ManageLifetime(cableCursor); ESRI.ArcGIS.Geodatabase.IFeature cable = cableCursor.NextFeature(); if (cable == null) { System.Windows.Forms.MessageBox.Show("Invalid cable ID referenced: (ID)" + nextCableId, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } filter.WhereClause = string.Format(fiberWhereFormat, nextCableId, nextFiberNumber); ESRI.ArcGIS.Geodatabase.ICursor fiberCursor = fiberTable.Search(filter, false); releaser.ManageLifetime(fiberCursor); ESRI.ArcGIS.Geodatabase.IRow fiber = fiberCursor.NextRow(); if (fiber == null) { System.Windows.Forms.MessageBox.Show("Invalid Fiber Cable or # referenced: (ID/#) " + nextCableId + "/" + nextFiberNumber, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } if (isStartingAtFromEnd) { if (spliceRow != null) { result.Add(spliceRow); } if (spliceClosure != null) { result.Add(spliceClosure); } if (fiber != null) { result.Add(fiber); } if (cable != null) { result.Add(cable); } } else { if (spliceClosure != null) { result.Add(spliceClosure); } if (spliceRow != null) { result.Add(spliceRow); } if (cable != null) { result.Add(cable); } if (fiber != null) { result.Add(fiber); } } spliceRow = GetNextSplice(fiberSpliceTable, nextCableId, nextFiberNumber, !isNextFromEnd, out nextCableId, out nextFiberNumber, out spliceClosureIpid, out isNextFromEnd); } // See if there is a port for this one ESRI.ArcGIS.Geodatabase.IRow portRow = null; ESRI.ArcGIS.Geodatabase.IFeature deviceFt = null; if (GetConnectedPort(cableFtClass, nextCableId, nextFiberNumber, isNextFromEnd, out portRow, out deviceFt)) { if (isStartingAtFromEnd) { result.Add(portRow); result.Add(deviceFt); } else { result.Add(deviceFt); result.Add(portRow); } } return(result); } }
private FiberCableWrapper GetConnectedFiber(DeviceWrapper device, int portId, PortType portType, out int fiberNumber) { FiberCableWrapper result = null; fiberNumber = -1; ESRI.ArcGIS.Geodatabase.IFeatureClass deviceFtClass = (ESRI.ArcGIS.Geodatabase.IFeatureClass)device.Feature.Class; ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship(deviceFtClass); if (null == deviceHasPorts) { throw new Exception("Device to port relationship is missing or cannot be opened."); } ESRI.ArcGIS.Geodatabase.ITable portTable = deviceHasPorts.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable; if (null == portTable) { throw new Exception("Port table is missing or cannot be opened."); } using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); filter.WhereClause = string.Format("{0}='{1}' AND {2}={3} AND {4}='{5}'", deviceHasPorts.OriginForeignKey, device.Feature.get_Value(deviceFtClass.FindField(deviceHasPorts.OriginPrimaryKey)), ConfigUtil.PortIdFieldName, portId, ConfigUtil.PortTypeFieldName, PortType.Input == portType ? 1 : 2); ESRI.ArcGIS.Geodatabase.ICursor cursor = portTable.Search(filter, false); releaser.ManageLifetime(cursor); ESRI.ArcGIS.Geodatabase.IRow portRow = cursor.NextRow(); if (null != portRow) { //releaser.ManageLifetime(portRow); object cableIdValue = portRow.get_Value(portTable.FindField(ConfigUtil.ConnectedCableFieldName)); if (DBNull.Value != cableIdValue) { ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = _wkspHelper.FindFeatureClass(ConfigUtil.FiberCableFtClassName); filter.WhereClause = string.Format("{0}='{1}'", ConfigUtil.IpidFieldName, cableIdValue); ESRI.ArcGIS.Geodatabase.IFeatureCursor cableCursor = cableFtClass.Search(filter, false); releaser.ManageLifetime(cableCursor); ESRI.ArcGIS.Geodatabase.IFeature cable = cableCursor.NextFeature(); if (null != cable) { result = new FiberCableWrapper(cable); object fiberNumberValue = portRow.get_Value(portTable.FindField(ConfigUtil.ConnectedFiberFieldName)); if (DBNull.Value != fiberNumberValue) { int.TryParse(fiberNumberValue.ToString(), out fiberNumber); } } } } } return(result); }
/// <summary> /// Constructs a new FiberCableWrapper where the display index is already known /// </summary> /// <param name="fiberCableFeature">IFeature to wrap</param> /// <param name="displayFieldIndex">Index of display field</param> public FiberCableWrapper(ESRI.ArcGIS.Geodatabase.IFeature fiberCableFeature, int displayFieldIndex) : base(fiberCableFeature, displayFieldIndex) { CacheFields(); }
/// <summary> /// Finds the connected device/port /// </summary> /// <param name="siblingFtClass">Any feature class from the workspace</param> /// <param name="cableId">Cable ID to check connx for</param> /// <param name="fiberNumber">Fiber Number to check connx for</param> /// <param name="isFromEnd">Whether to check the cable's from or to end</param> /// <param name="portRow">(out) result port</param> /// <param name="deviceFt">(out) result device</param> /// <returns>True if a connx was found</returns> private bool GetConnectedPort(ESRI.ArcGIS.Geodatabase.IFeatureClass siblingFtClass, string cableId, int fiberNumber, bool isFromEnd, out ESRI.ArcGIS.Geodatabase.IRow portRow, out ESRI.ArcGIS.Geodatabase.IFeature deviceFt) { portRow = null; deviceFt = null; bool result = false; string[] portTableNames = ConfigUtil.PortTableNames; using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); filter.WhereClause = string.Format("{0}='{1}' AND {2}={3} AND {4}='{5}'", ConfigUtil.ConnectedCableFieldName, cableId, ConfigUtil.ConnectedFiberFieldName, fiberNumber, ConfigUtil.ConnectedEndFieldName, isFromEnd ? "T" : "F"); releaser.ManageLifetime(filter); for (int i = 0; i < portTableNames.Length; i++) { string portTableName = portTableNames[i]; ESRI.ArcGIS.Geodatabase.ITable portTable = _wkspHelper.FindTable(portTableName); ESRI.ArcGIS.Geodatabase.ICursor cursor = portTable.Search(filter, false); releaser.ManageLifetime(cursor); portRow = cursor.NextRow(); if (null != portRow) { ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetDeviceRelationship(portTable); if (null == deviceHasPorts) { throw new Exception("Device to port relationship is missing or cannot be opened."); } ESRI.ArcGIS.Geodatabase.IFeatureClass deviceClass = deviceHasPorts.OriginClass as ESRI.ArcGIS.Geodatabase.IFeatureClass; if (null == deviceClass) { throw new Exception("Device feature class is missing or cannot be opened."); } filter.WhereClause = string.Format("{0}='{1}'", deviceHasPorts.OriginPrimaryKey, portRow.get_Value(portTable.FindField(deviceHasPorts.OriginForeignKey))); ESRI.ArcGIS.Geodatabase.IFeatureCursor deviceCursor = deviceClass.Search(filter, false); deviceFt = deviceCursor.NextFeature(); result = true; break; } } } return(result); }
/// <summary> /// Generate the ports for a given device /// </summary> /// <param name="device">The device feature</param> /// <returns>True if completed</returns> private bool GeneratePorts(ESRI.ArcGIS.Geodatabase.IFeature device, int lowInputPort, int inputPortCount, int lowOutputPort, int outputPortCount, ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog, ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel) { bool isCancelled = false; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = (ESRI.ArcGIS.esriSystem.IStepProgressor)progressDialog; ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship((ESRI.ArcGIS.Geodatabase.IFeatureClass)device.Class); Guid g; if (null != deviceHasPorts) { using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.ITable portTable = (ESRI.ArcGIS.Geodatabase.ITable)deviceHasPorts.DestinationClass; releaser.ManageLifetime(portTable); // Fields to populate on port int portIpidIdx = portTable.Fields.FindField(ConfigUtil.IpidFieldName); int portNumberIdx = portTable.Fields.FindField(ConfigUtil.PortIdFieldName); int portTypeIdx = portTable.Fields.FindField(ConfigUtil.PortTypeFieldName); int fkeyIdx = portTable.Fields.FindField(deviceHasPorts.OriginForeignKey); object originPrimaryKey = device.get_Value(device.Fields.FindField(deviceHasPorts.OriginPrimaryKey)); for (int portIdx = lowInputPort; portIdx <= inputPortCount; portIdx++) { stepProgressor.Message = string.Format("Creating input port {0} of {1}", portIdx, inputPortCount); stepProgressor.Step(); g = Guid.NewGuid(); string portIpid = g.ToString("B").ToUpper(); ESRI.ArcGIS.Geodatabase.IRow portRow = portTable.CreateRow(); releaser.ManageLifetime(portRow); portRow.set_Value(portIpidIdx, portIpid); portRow.set_Value(portTypeIdx, PortType.Input); portRow.set_Value(portNumberIdx, portIdx); portRow.set_Value(fkeyIdx, originPrimaryKey); portRow.Store(); if (!trackCancel.Continue()) { isCancelled = true; break; } } if (trackCancel.Continue()) { for (int portIdx = lowOutputPort; portIdx <= outputPortCount; portIdx++) { stepProgressor.Message = string.Format("Creating output port {0} of {1}", portIdx, outputPortCount); stepProgressor.Step(); g = Guid.NewGuid(); string portIpid = g.ToString("B").ToUpper(); ESRI.ArcGIS.Geodatabase.IRow portRow = portTable.CreateRow(); releaser.ManageLifetime(portRow); portRow.set_Value(portIpidIdx, portIpid); portRow.set_Value(portTypeIdx, PortType.Output); portRow.set_Value(portNumberIdx, portIdx); portRow.set_Value(fkeyIdx, originPrimaryKey); portRow.Store(); if (!trackCancel.Continue()) { isCancelled = true; break; } } } } } return(!isCancelled); }
/// <summary> /// Constructs a new FiberCableWrapper /// </summary> /// <param name="fiberCableFeature">IFeature to wrap</param> public FiberCableWrapper(ESRI.ArcGIS.Geodatabase.IFeature fiberCableFeature) : base(fiberCableFeature) { CacheFields(); }