void Events_OnStartEditing() { // ----------------------------------- // Check to see if we are editing the // telecom workspace, and that // workspace is valid, if not ignore. // ----------------------------------- ESRI.ArcGIS.Geodatabase.IFeatureWorkspace workspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)ArcMap.Editor.EditWorkspace; IFeatureWorkspace fwksp = TelecomWorkspaceHelper.Instance().CurrentWorkspace; bool wkspIsValid = TelecomWorkspaceHelper.Instance().CurrentWorkspaceIsValid; if (workspace == null || !wkspIsValid || !workspace.Equals(fwksp)) { return; } // ----------------------------------- // Workspace is valid for editing. // Get the splice form and set to // edit mode // ----------------------------------- FiberDeviceConnectionWindow.AddinImpl winImpl = AddIn.FromID <FiberDeviceConnectionWindow.AddinImpl>(ThisAddIn.IDs.Esri_Telecom_Tools_Windows_FiberDeviceConnectionWindow); FiberDeviceConnectionWindow deviceWindow = winImpl.UI; deviceWindow.IsEditing = true; }
/// <summary> /// Gets a list of all strand numbers from a cable that are spliced on the given end /// </summary> /// <param name="cable">Cable to check</param> /// <param name="isFromEnd">True to check from end, False to check to end</param> /// <returns>List of int</returns> private static List <int> GetSplicedStrands(FiberCableWrapper cable, bool isFromEnd) { if (null == cable) { throw new ArgumentNullException("cable"); } List <int> result = new List <int>(); using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = TelecomWorkspaceHelper.Instance().FindTable(ConfigUtil.FiberSpliceTableName); // ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = GdbUtils.GetTable(cable.Feature.Class, ConfigUtil.FiberSpliceTableName); ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); filter.WhereClause = string.Format("{0}='{1}' AND {2}='{3}'", ConfigUtil.ACableIdFieldName, cable.IPID, ConfigUtil.IsAFromEndFieldName, (isFromEnd ? "T" : "F")); ESRI.ArcGIS.Geodatabase.ICursor spliceCursor = fiberSpliceTable.Search(filter, true); ESRI.ArcGIS.Geodatabase.IRow spliceRow = spliceCursor.NextRow(); int fiberIdIdx = fiberSpliceTable.FindField(ConfigUtil.AFiberNumberFieldName); while (null != spliceRow) { result.Add((int)spliceRow.get_Value(fiberIdIdx)); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceRow); spliceRow = spliceCursor.NextRow(); } ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceCursor); filter.WhereClause = string.Format("{0}='{1}' AND {2}='{3}'", ConfigUtil.BCableIdFieldName, cable.IPID, ConfigUtil.IsBFromEndFieldName, (isFromEnd ? "T" : "F")); spliceCursor = fiberSpliceTable.Search(filter, true); spliceRow = spliceCursor.NextRow(); fiberIdIdx = fiberSpliceTable.FindField(ConfigUtil.BFiberNumberFieldName); while (null != spliceRow) { result.Add((int)spliceRow.get_Value(fiberIdIdx)); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceRow); spliceRow = spliceCursor.NextRow(); } ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceCursor); } return(result); }
public FiberEditorExtension() { try { // -------------------------------------- // Initialize log window with log helper // -------------------------------------- _logHelper = LogHelper.Instance(); TelecomToolsLogWindow.AddinImpl winImpl = AddIn.FromID <TelecomToolsLogWindow.AddinImpl>( ThisAddIn.IDs.Esri_Telecom_Tools_Windows_TelecomToolsLogWindow); TelecomToolsLogWindow logWindow = winImpl.UI; logWindow.InitLog(_logHelper); // -------------------- // Build a hook helper // -------------------- _hookHelper = HookHelperExt.Instance(this.Hook); // ------------------------------------------- // Initialize telecom workspace helper. // // Listen to ActiveViewChanged event. // // If this happens the focus map more than // likely changed. Since the tools go after // layers in the TOC we probably need to close // the current telecom workspace since // editing etc could not longer be done. // Should add code to ask for saving changes. // ------------------------------------------- _wkspHelper = TelecomWorkspaceHelper.Instance(); _wkspHelper.ActiveViewChanged += new EventHandler(_wkspHelper_ActiveViewChanged); // ------------------------------------------- // Build helpers that actually do all object // creation work for special feature types // ------------------------------------------- _fiberCableHelper = new FiberCableConfigHelper(_hookHelper, ArcMap.Editor as IEditor3); _fiberDeviceHelper = new FiberDeviceConfigHelper(_hookHelper, ArcMap.Editor as IEditor3); // -------------------------------------------- // Splice and Connection helpers // -------------------------------------------- _spliceHelper = new FiberSpliceHelper(_hookHelper, ArcMap.Editor as IEditor3); _connectionHelper = new FiberDeviceConnectionHelper(_hookHelper, ArcMap.Editor as IEditor3); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Telecom Extension Constructed."); } catch (Exception ex) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "General error.", ex.ToString()); } }
/// <summary> /// On starting an edit session the user may have the /// choice of selecting one or more workspaces in the /// editor selection dialog. /// /// This handler will validate that the user selected /// the telecom workspace for editing, if not we do /// nothing we dont care about those edits. If they did /// choose the telecom workspace then we signal the /// helpers that they need to start work. /// /// We also need to deal with dynamic values population. /// </summary> private void m_editEvents_OnStartEditing() { _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "On start editing"); try { // ----------------------------------- // Check to see if we are editing the // telecom workspace, and that // workspace is valid, if not ignore. // ----------------------------------- ESRI.ArcGIS.Geodatabase.IFeatureWorkspace workspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)ArcMap.Editor.EditWorkspace; IFeatureWorkspace fwksp = TelecomWorkspaceHelper.Instance().CurrentWorkspace; bool wkspIsValid = TelecomWorkspaceHelper.Instance().CurrentWorkspaceIsValid; if (workspace == null || !wkspIsValid) { return; } // Valid telecom workspace being edited... _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Started editing telecom workspace..."); // ------------------------------------ // Start the helpers to deal with // telecom workspace editing. // ------------------------------------ _fiberCableHelper.onStartEditing(); _fiberDeviceHelper.onStartEditing(); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Initialized telecom helpers."); //--------------------------------------- // Open dynamic defaults table // Doing this now for performance reasons // Feature creation and population will // work much faster. Even better if we // brought contents into memory. //--------------------------------------- if (workspace == null) { return; } ITable tab = TelecomWorkspaceHelper.Instance().FindTable(TelecomWorkspaceHelper.Instance().dynamicValuesTableName()); if (tab == null) { ArcMap.Application.StatusBar.set_Message(0, "No Dynamic Defaults"); return; } else { m_dynDefaults = tab; } //--------------------------------------- // Listen for feature template changes // so we can show appopriate dialogs // when needed. //--------------------------------------- Events5.OnCurrentTemplateChanged += new IEditEvents5_OnCurrentTemplateChangedEventHandler(Events5_OnCurrentTemplateChanged); Events5.OnTemplateModified += new IEditEvents5_OnTemplateModifiedEventHandler(Events5_OnTemplateModified); // Everything below hear needs to move to helpers and dynamic values helper // ------------------------------------------------ // We need to deal with deletions differently since // there may be connectivity invovled. // // All creations are managed by helpers (embedded // in dialogs). // // All deletions are managed by Editor extension. // ------------------------------------------------- Events.OnDeleteFeature += new IEditEvents_OnDeleteFeatureEventHandler(Events_OnDeleteFeature); // ----------------------------------- // Now for Dynamic Values changes // ----------------------------------- Events.OnChangeFeature += new IEditEvents_OnChangeFeatureEventHandler(m_editEvents_OnChangeFeature); Events.OnCreateFeature += new IEditEvents_OnCreateFeatureEventHandler(m_editEvents_OnCreateFeature); if (lastValueProperties == null) { constructFieldArray(); } // ---------------------------------------------------------------------- // Assuming that none of the non feature class tables will be in the // document by default, add in object class level events for adds and // deletes. NOTE: these events will only fire if cursor type adds and // updates are NOT used. These cursors are designed to do fast updates // by eliminating event firing. // ---------------------------------------------------------------------- //HookHelperExt helper = new HookHelperExt(m_editor.Parent, m_editor); // _nonFeatureObjClassEvents = new System.Collections.Generic.List<IObjectClassEvents_Event>(); // for (int i = 0; i < m_nonFeatureTables.Length; i++) // { // if (workspace != null) // { //// ITable tab = TelecomWorkspaceHelper.Instance().FindTable(TelecomWorkspaceHelper.Instance().dynamicValuesTableName()); // ESRI.ArcGIS.Geodatabase.IObjectClassEvents_Event nonFeatureOCE = TelecomWorkspaceHelper.Instance().FindTable(m_nonFeatureTables[i]) as ESRI.ArcGIS.Geodatabase.IObjectClassEvents_Event; //// ESRI.ArcGIS.Geodatabase.IObjectClassEvents_Event nonFeatureOCE = workspace.OpenTable(m_nonFeatureTables[i]) as ESRI.ArcGIS.Geodatabase.IObjectClassEvents_Event; // if (null != nonFeatureOCE) // { // _nonFeatureObjClassEvents.Add(nonFeatureOCE); // nonFeatureOCE.OnChange += new IObjectClassEvents_OnChangeEventHandler( // m_editEvents_OnChangeFeature); // nonFeatureOCE.OnCreate += new IObjectClassEvents_OnCreateEventHandler( // m_editEvents_OnCreateFeature); // } // } // } } catch (Exception ex) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Editor error occurred.", ex.ToString()); MessageBox.Show("Error: \n" + ex.ToString()); } }
/// <summary> /// Gets a list of all strand numbers from a cable that are connected on the given end /// </summary> /// <param name="cable">Cable to check</param> /// <param name="isFromEnd">True to check from end, False to check to end</param> /// <returns>List of int</returns> private static List <int> GetConnectedStrands(FiberCableWrapper cable, bool isFromEnd) { #region Validation if (null == cable) { throw new ArgumentNullException("cable"); } #endregion List <int> result = new List <int>(); using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = cable.Feature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass; string[] deviceClassNames = ConfigUtil.DeviceFeatureClassNames; for (int i = 0; i < deviceClassNames.Length; i++) { string deviceClassName = deviceClassNames[i]; ESRI.ArcGIS.Geodatabase.IFeatureClass deviceFtClass = TelecomWorkspaceHelper.Instance().FindFeatureClass(deviceClassName); // ESRI.ArcGIS.Geodatabase.IFeatureClass deviceFtClass = GdbUtils.GetFeatureClass(cableFtClass, deviceClassName); if (null != deviceFtClass) { ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship(deviceFtClass); if (null != deviceHasPorts) { ESRI.ArcGIS.Geodatabase.ITable portTable = deviceHasPorts.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable; if (null != 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} IS NOT NULL", ConfigUtil.ConnectedCableFieldName, cable.IPID, ConfigUtil.ConnectedEndFieldName, (isFromEnd ? "T" : "F"), ConfigUtil.ConnectedFiberFieldName); ESRI.ArcGIS.Geodatabase.ICursor portCursor = portTable.Search(filter, true); ESRI.ArcGIS.Geodatabase.IRow portRow = portCursor.NextRow(); int fiberIdIdx = portTable.FindField(ConfigUtil.ConnectedFiberFieldName); while (null != portRow) { result.Add((int)portRow.get_Value(fiberIdIdx)); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(portRow); portRow = portCursor.NextRow(); } ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(portCursor); } } } } } return(result); }
/// <summary> /// Get the existing splice ranges between two cables at an existing closure /// </summary> /// <param name="cableA">One cable</param> /// <param name="cableB">Other cable</param> /// <param name="splice">Splice Closure</param> /// <returns>List of FiberSplice</returns> /// <remarks>Currently only checks A/B as passed, does not check the reverse B/A combination</remarks> public static List <FiberSplice> GetSplicedRanges(FiberCableWrapper cableA, FiberCableWrapper cableB, SpliceClosureWrapper splice) { List <FiberSplice> result = new List <FiberSplice>(); string spliceWhere = string.Format("{0}='{1}' AND {2}='{3}' AND {4}='{5}'", ConfigUtil.ACableIdFieldName, cableA.IPID, ConfigUtil.BCableIdFieldName, cableB.IPID, ConfigUtil.SpliceClosureIpidFieldName, splice.IPID); using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = TelecomWorkspaceHelper.Instance().FindTable(ConfigUtil.FiberSpliceTableName); // ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = GdbUtils.GetTable(cableA.Feature.Class, ConfigUtil.FiberSpliceTableName); ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); filter.WhereClause = spliceWhere; ((ESRI.ArcGIS.Geodatabase.IQueryFilterDefinition)filter).PostfixClause = string.Format("ORDER BY {0}", ConfigUtil.AFiberNumberFieldName); int aUnitIdx = fiberSpliceTable.FindField(ConfigUtil.AFiberNumberFieldName); int bUnitIdx = fiberSpliceTable.FindField(ConfigUtil.BFiberNumberFieldName); int lossIdx = fiberSpliceTable.FindField(ConfigUtil.LossFieldName); int typeIdx = fiberSpliceTable.FindField(ConfigUtil.TypeFieldName); ESRI.ArcGIS.Geodatabase.IField typeField = fiberSpliceTable.Fields.get_Field(typeIdx); ESRI.ArcGIS.Geodatabase.ICodedValueDomain typeDomain = typeField.Domain as ESRI.ArcGIS.Geodatabase.ICodedValueDomain; ESRI.ArcGIS.Geodatabase.ICursor splices = fiberSpliceTable.Search(filter, true); releaser.ManageLifetime(splices); ESRI.ArcGIS.Geodatabase.IRow spliceRow = splices.NextRow(); int lastAUnit = -1; int lastBUnit = -1; double?lastLoss = null; object lastType = Type.Missing; int aLow = -1; int bLow = -1; while (null != spliceRow) { // These are not-null columns int aUnit = (int)spliceRow.get_Value(aUnitIdx); int bUnit = (int)spliceRow.get_Value(bUnitIdx); object lossObj = spliceRow.get_Value(lossIdx); double?loss = null; if (DBNull.Value != lossObj) { loss = (double)lossObj; } object type = spliceRow.get_Value(typeIdx); if (aUnit != (lastAUnit + 1) || bUnit != (lastBUnit + 1) || loss != lastLoss || !type.Equals(lastType)) { if (-1 != lastAUnit) { string typeString = string.Empty; if (null != typeString) { if (null != typeDomain) { typeString = GdbUtils.GetDomainNameForValue(typeDomain, lastType); } else { typeString = lastType.ToString(); // DBNull.Value will return string.Empty } } result.Add(new FiberSplice(new Range(aLow, lastAUnit), new Range(bLow, lastBUnit), lastLoss, typeString)); } aLow = aUnit; bLow = bUnit; } lastAUnit = aUnit; lastBUnit = bUnit; lastLoss = loss; lastType = type; ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceRow); spliceRow = splices.NextRow(); } if (-1 < aLow) { string typeString = string.Empty; if (null != typeString) { if (null != typeDomain) { typeString = GdbUtils.GetDomainNameForValue(typeDomain, lastType); } else { typeString = lastType.ToString(); // DBNull.Value will return string.Empty } } result.Add(new FiberSplice(new Range(aLow, lastAUnit), new Range(bLow, lastBUnit), lastLoss, typeString)); } } return(result); }