/// <summary> /// Creates a new feature ID that doesn't reference anything (and does not add it to the map model). /// </summary> /// <returns>The created feature ID.</returns> internal FeatureId CreateId() { IdPacket p = m_Group.FindPacket(m_Id); p.ReserveId(m_Id); return(p.CreateId(m_Id)); }
/// <summary> /// Restores (un-deletes) this feature. /// </summary> /// <returns>True if feature restored. False if the feature wasn't marked as inactive.</returns> internal virtual bool Restore() { // Return if this feature doesn't currently have the "inactive" state if (!IsInactive) { return(false); } // If this feature referred to an ID, restore it. if (m_Id != null) { // Ensure that the ID is cross-referenced to this feature. m_Id.AddReference(this); // That's pretty well it. When a feature is de-activated, only the back // pointer from the ID is nulled out. The feature retained it's pointer to the ID, // and the ID itself was left in place as part of the IdPacket to which it belongs. // For native IDs, the packet needs to be told to decrement the number of free // IDs. // TODO: This may be irrelevant (need to also review the logic when something is // de-activated). if (m_Id is NativeId) { IdManager idMan = MapModel.IdManager; if (idMan != null) { // Find the ID group that applies to the feature's // entity type (this will be null if the entity type was // not originally listed in the IdEntity table, or the // group is considered to be obsolete). IdGroup g = idMan.GetGroup(this.EntityType); // If we got a group (and the ID if not foreign) try to find // the ID packet that refers to the feature's ID. if (g != null) { NativeId nid = (m_Id as NativeId); IdPacket p = g.FindPacket(nid); p.RestoreId(m_Id); } } } } // Add back into the map index. MapModel.EditingIndex.AddFeature(this); // Remember that the feature is now active IsInactive = false; return(true); }
/// <summary> /// Load an ID combo box with all the available IDs for a specific entity type. /// </summary> /// <param name="box">The combo box (not null)</param> /// <param name="ent">The entity type that the combo is for (if null, the combo will /// be empty)</param> /// <param name="handle">The ID handle that should be defined to correspond with the /// first available ID (may be null). If there are no available IDs for the specified /// entity type, any ID previously reserved will be released.</param> /// <returns>The number of IDs that were loaded into the combo (if any)</returns> internal static int LoadIdCombo(ComboBox box, IEntity ent, IdHandle handle) { if (box == null) { throw new ArgumentNullException(); } // Clear out anything that was in the combo before. box.Items.Clear(); if (ent == null) { return(0); } // Get a list of all the available IDs for the specified entity type... IdManager idMan = CadastralMapModel.Current.IdManager; if (idMan == null) { return(0); } IdGroup group = idMan.GetGroup(ent); if (group == null) { return(0); } // Get the available IDs for the group uint[] avail = group.GetAvailIds(); // If we didn't find any, obtain an extra allocation if (avail.Length == 0) { IdPacket newPacket = group.GetAllocation(true); // with announcement avail = group.GetAvailIds(); if (avail.Length == 0) { throw new ApplicationException("Cannot obtain ID allocation"); } } // Load the combo DisplayId[] ids = new DisplayId[avail.Length]; for (int i = 0; i < ids.Length; i++) { ids[i] = new DisplayId(group, avail[i]); } box.Items.AddRange(ids); // Reserve the first available ID if a handle was supplied (and select it) if (handle != null) { IdPacket p = group.FindPacket(avail[0]); handle.ReserveId(p, ent, avail[0]); box.SelectedItem = ids[0]; } return(avail.Length); }