/// <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; }
/// <summary> /// Reserves the next available ID for a given entity type. /// </summary> /// <param name="idh">The ID handle to fill in.</param> /// <param name="ent">The entity type to search for.</param> /// <param name="id">The specific ID to reserve (specify 0 to get the next available ID).</param> /// <returns>True if the ID handle was filled in successfully.</returns> internal bool ReserveId(IdHandle idh, IEntity ent, uint id) { // Ensure the ID handle is free. idh.FreeReservedId(); // Get the ID group to make the reservation IdGroup g = GetGroup(ent); if (g == null) { return(false); } else { return(g.ReserveId(idh, id)); } }
/// <summary> /// Assigns the next available ID to this feature. The feature cannot /// already have an ID. /// </summary> internal void SetNextId() { if (CadastralMapModel.Current.WorkingSession != null) { // Disallow if this feature already has an ID. if (m_Id != null) { throw new InvalidOperationException("Feature already has an ID"); } // If we can reserve a new ID, create it. IdHandle idh = new IdHandle(); if (idh.ReserveId(m_What, 0)) { idh.CreateId(this); } } }
/// <summary> /// Reserves an ID belonging to this ID group. /// </summary> /// <param name="idh">The ID handle to define.</param> /// <param name="id">The specific ID to reserve. Specify 0 for the next /// available ID (in that case, an additional allocation will be made if /// necessary).</param> /// <returns>True if the ID was reserved ok. False if it is already reserved (or /// an allocation could not be obtained).</returns> internal bool ReserveId(IdHandle idh, uint id) { if (id > 0) { // Find the packet that contains the specified ID. IdPacket packet = FindPacket(id); if (packet == null) { MessageBox.Show("IdGroup.ReserveId - Wrong ID group."); return(false); } // Get the ID handle to reserve the ID. return(idh.ReserveId(packet, idh.Entity, id)); } else { // Find the packet that contains the next available ID. IdPacket packet = FindNextAvail(); // If we didn't find anything, ask the ID manager to make // a new allocation (most of the work actually gets passed // back to IdGroup.GetAllocation). if (packet == null) { GetAllocation(true); packet = FindNextAvail(); if (packet == null) { return(false); } } // Get the next ID from the packet. uint nextid = packet.ReserveId(); if (nextid == 0) { MessageBox.Show("IdGroup.ReserveId - Range did not have any free IDs."); return(false); } return(idh.Define(packet, idh.Entity, nextid)); } }
/// <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); }
/// <summary> /// Handles a selection change made to an ID combo. This reserves the ID /// by associating it with the supplied ID handle (and discards any previous /// reserve). /// </summary> /// <param name="comboBox">The combo box where the selection has changed.</param> /// <param name="handle">The handle for the selected ID</param> internal static void OnChangeSelectedId(ComboBox comboBox, IdHandle handle) { DisplayId id = (DisplayId)comboBox.SelectedItem; handle.ReserveId(handle.Entity, id.RawId); }
/// <summary> /// Reserves the next available ID for a given entity type. /// </summary> /// <param name="idh">The ID handle to fill in.</param> /// <param name="ent">The entity type to search for.</param> /// <param name="id">The specific ID to reserve (specify 0 to get the next available ID).</param> /// <returns>True if the ID handle was filled in successfully.</returns> internal bool ReserveId(IdHandle idh, IEntity ent, uint id) { // Ensure the ID handle is free. idh.FreeReservedId(); // Get the ID group to make the reservation IdGroup g = GetGroup(ent); if (g==null) return false; else return g.ReserveId(idh, id); }
/// <summary> /// Reserves an ID belonging to this ID group. /// </summary> /// <param name="idh">The ID handle to define.</param> /// <param name="id">The specific ID to reserve. Specify 0 for the next /// available ID (in that case, an additional allocation will be made if /// necessary).</param> /// <returns>True if the ID was reserved ok. False if it is already reserved (or /// an allocation could not be obtained).</returns> internal bool ReserveId(IdHandle idh, uint id) { if (id>0) { // Find the packet that contains the specified ID. IdPacket packet = FindPacket(id); if (packet == null) { MessageBox.Show("IdGroup.ReserveId - Wrong ID group."); return false; } // Get the ID handle to reserve the ID. return idh.ReserveId(packet, idh.Entity, id); } else { // Find the packet that contains the next available ID. IdPacket packet = FindNextAvail(); // If we didn't find anything, ask the ID manager to make // a new allocation (most of the work actually gets passed // back to IdGroup.GetAllocation). if (packet == null) { GetAllocation(true); packet = FindNextAvail(); if (packet == null) return false; } // Get the next ID from the packet. uint nextid = packet.ReserveId(); if (nextid==0) { MessageBox.Show("IdGroup.ReserveId - Range did not have any free IDs."); return false; } return idh.Define(packet, idh.Entity, nextid); } }