/// <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> /// Break all connections for a given cable /// </summary> /// <param name="cable">Cable to break connections</param> /// <param name="isExistingOperation">Should we start/stop the edit operation, or are we already in one?</param> /// <returns>Success</returns> public bool BreakAllConnections(FiberCableWrapper cable, bool isExistingOperation) { bool success = false; bool isOperationOpen = false; #region Validation if (null == cable) { throw new ArgumentNullException("cable"); } 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; } try { using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = cable.Feature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass; ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); filter.WhereClause = string.Format("{0}='{1}'", ConfigUtil.ConnectedCableFieldName, cable.IPID); filter.SubFields = string.Format("{0},{1},{2}", ConfigUtil.ConnectedCableFieldName, ConfigUtil.ConnectedFiberFieldName, ConfigUtil.ConnectedEndFieldName); string[] deviceClassNames = ConfigUtil.DeviceFeatureClassNames; for (int i = 0; i < deviceClassNames.Length; i++) { string deviceClassName = deviceClassNames[i]; ESRI.ArcGIS.Geodatabase.IFeatureClass deviceFtClass = _wkspHelper.FindFeatureClass(deviceClassName); // ESRI.ArcGIS.Geodatabase.IFeatureClass deviceFtClass = GdbUtils.GetFeatureClass(cableFtClass, deviceClassName); ESRI.ArcGIS.Geodatabase.ITable portTable = ConfigUtil.GetPortTable(deviceFtClass); ESRI.ArcGIS.Geodatabase.IRowBuffer buffer = portTable.CreateRowBuffer(); // We want to set them to null, so we can just send the empty buffer portTable.UpdateSearchedRows(filter, buffer); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(buffer); } if (isOperationOpen) { _editor.StopOperation("Break Connections"); isOperationOpen = false; } success = true; } } catch { if (isOperationOpen) { _editor.AbortOperation(); } success = false; } return(success); }
///// <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); } }