/// <summary> /// Reads back an array of ID mappings, associating the user-perceived IDs with the /// corresponding spatial features. /// </summary> /// <param name="field">A tag associated with the array</param> internal void ReadIdMappings(DataField field) { if (!IsNextField(field)) { return; } IdMapping[] mapping = ReadPersistentArray <IdMapping>(field); for (int i = 0; i < mapping.Length; i++) { IdMapping m = mapping[i]; NativeId nid = MapModel.FindNativeId(m.RawId); if (nid == null) { nid = MapModel.AddNativeId(m.RawId); } Feature f = MapModel.Find <Feature>(m.InternalId); // Ignore null ref if we are dealing with the very last mapping of a connection path // (covers CEdit bug that produced spurious point at the end of the path). if (f == null) { //if (m_CurrentEdit is PathOperation && i == (mapping.Length - 1)) // break; throw new ApplicationException("Cannot locate feature for ID mapping: " + m); } f.SetId(nid); } }
/// <summary> /// Reads an array of spatial features (using their unique IDs the read them from the map model). /// </summary> /// <typeparam name="T">The type of spatial feature expected by the caller</typeparam> /// <param name="referenceFrom">The object that is making the reference</param> /// <param name="field">A tag associated with the array</param> /// <returns>The features that were read (should all be not null).</returns> internal T[] ReadFeatureRefArray <T>(IFeatureRefArray referenceFrom, DataField field) where T : Feature { string[] ids = ReadSimpleArray <string>(field); T[] result = new T[ids.Length]; List <ForwardRefArrayItem> fwRefs = null; for (int i = 0; i < result.Length; i++) { InternalIdValue id = new InternalIdValue(ids[i]); result[i] = MapModel.Find <T>(id); if (result[i] == null) { if (fwRefs == null) { fwRefs = new List <ForwardRefArrayItem>(); } fwRefs.Add(new ForwardRefArrayItem(id, i)); } } if (fwRefs != null) { m_ForwardRefs.Add(new ForwardFeatureRefArray(referenceFrom, field, fwRefs.ToArray())); } return(result); }
/// <summary> /// Reads a reference to a spatial feature, using that reference to obtain the /// corresponding feature. /// </summary> /// <typeparam name="T">The type of spatial feature expected by the caller</typeparam> /// <param name="field">A tag associated with the value</param> /// <returns> /// The feature that was read (null if the feature reference is an internal ID of 0). May /// actually have a type that is derived from the supplied type. /// </returns> /// <remarks>This does not create a brand new feature. Rather, it uses a reference /// to try to obtain a feature that should have already been created. /// <para/> /// This version assumes that the referenced feature must have been already deserialized, which /// should always be the case when dealing with edits that were created using Backsight. This /// may NOT be the case when dealing with data files that originated in the old CEdit system. /// The problem is that CEdit handled updates by modifying the objects holding the original /// edits and, since it is valid to make use of features created after the initial edit (so /// long as there is no dependency), it is possible that the features may be initially unknown /// during deserialization. /// <para/> /// So if there is any possibility that the referenced feature may come later in the editing /// sequence, use the version that also accepts an instance of <see cref="IFeatureRef"/>. /// Note that for updates to be possible, the edit needs to implement <see cref="IRevisable"/> /// (if updates are not possible, forward references should not be possible either). /// </remarks> /// <exception cref="ApplicationException">If the internal ID is defined, but the referenced feature /// could not be found.</exception> internal T ReadFeatureRef <T>(DataField field) where T : Feature { InternalIdValue id = m_Reader.ReadInternalId(field.ToString()); if (id.IsEmpty) { return(default(T)); } T result = MapModel.Find <T>(id); if (result == null) { throw new ApplicationException(String.Format("Cannot locate forward reference {0} (type={1})", id, typeof(T).Name)); } return(result); }
/// <summary> /// Reads a reference to a spatial feature, using that reference to obtain the /// corresponding feature. If the feature cannot be found, the reference will be cached as /// a forward reference (on completion of deserialization, you then call <see cref="ApplyForwardRefs"/> /// to process the cache). /// </summary> /// <typeparam name="T">The type of spatial feature expected by the caller</typeparam> /// <param name="referenceFrom">The object that is making the reference</param> /// <param name="field">A tag associated with the value</param> /// <returns> /// The feature that was read (null if not found, or the reference was undefined). May /// actually have a type that is derived from the supplied type. /// </returns> /// <remarks>This does not create a brand new feature. Rather, it uses a reference /// to try to obtain a feature that should have already been created. /// </remarks> internal T ReadFeatureRef <T>(IFeatureRef referenceFrom, DataField field) where T : Feature { InternalIdValue id = m_Reader.ReadInternalId(field.ToString()); if (id.IsEmpty) { return(default(T)); } T result = MapModel.Find <T>(id); if (result == null) { var fwRef = new ForwardFeatureRef(referenceFrom, field, id); m_ForwardRefs.Add(fwRef); } return(result); }