コード例 #1
0
ファイル: IdManager.cs プロジェクト: 15831944/backsight
        /// <summary>
        /// Generates an index that cross-references each entity type with its corresponding
        /// ID group.
        /// </summary>
        /// <param name="groups">The ID groups to index</param>
        /// <returns>Index of the ID groups for each entity type. The key is the ID of the entity type,
        /// the values are elements in the <paramref name="groups"/> array.</returns>
        Dictionary <int, IdGroup> GetEntityGroups(IdGroup[] groups)
        {
            IEnvironmentContainer ec = EnvironmentContainer.Current;

            if (ec == null)
            {
                return(new Dictionary <int, IdGroup>());
            }

            IEntity[] ents = ec.EntityTypes;
            Dictionary <int, IdGroup> result = new Dictionary <int, IdGroup>(ents.Length);

            foreach (IEntity e in ents)
            {
                IIdGroup idg = e.IdGroup;
                if (idg != null && idg.Id > 0)
                {
                    int     gid      = idg.Id;
                    IdGroup entGroup = Array.Find <IdGroup>(groups, g => g.Id == gid);
                    Debug.Assert(entGroup != null);
                    result.Add(e.Id, entGroup);
                }
            }

            return(result);
        }
コード例 #2
0
ファイル: DisplayId.cs プロジェクト: steve-stanton/backsight
        /// <summary>
        /// Creates a new <c>DisplayId</c>
        /// </summary>
        /// <param name="group">The ID group containing the raw ID</param>
        /// <param name="rawId">The raw ID (undecorated with stuff like check digits)</param>
        internal DisplayId(IdGroup group, uint rawId)
        {
            if (group == null)
                throw new ArgumentNullException();

            m_Group = group;
            m_Id = rawId;
        }
コード例 #3
0
        /// <summary>
        /// Creates a new <c>DisplayId</c>
        /// </summary>
        /// <param name="group">The ID group containing the raw ID</param>
        /// <param name="rawId">The raw ID (undecorated with stuff like check digits)</param>
        internal DisplayId(IdGroup group, uint rawId)
        {
            if (group == null)
            {
                throw new ArgumentNullException();
            }

            m_Group = group;
            m_Id    = rawId;
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
ファイル: IdPacket.cs プロジェクト: steve-stanton/backsight
        /// <summary>
        /// Creates a new <c>IdPacket</c>
        /// </summary>
        /// <param name="group">The group that will contain this packet (not null)</param>
        /// <param name="alloc">The allocation associated with the group (not null)</param>
        /// <exception cref="ArgumentNullException">If either parameter is null</exception>
        /// <exception cref="ArgumentException">If the allocation does not refer to the supplied group</exception>
        internal IdPacket(IdGroup group, IdAllocation alloc)
        {
            if (group==null || alloc==null)
                throw new ArgumentNullException();

            if (group.Id != alloc.GroupId)
                throw new ArgumentException();

            m_Group = group;
            m_Allocation = alloc;
            m_Ids = new NativeId[m_Allocation.Size];
            m_ReservedIds = new List<uint>();
        }
コード例 #6
0
ファイル: IdPacket.cs プロジェクト: 15831944/backsight
        /// <summary>
        /// Creates a new <c>IdPacket</c>
        /// </summary>
        /// <param name="group">The group that will contain this packet (not null)</param>
        /// <param name="alloc">The allocation associated with the group (not null)</param>
        /// <exception cref="ArgumentNullException">If either parameter is null</exception>
        /// <exception cref="ArgumentException">If the allocation does not refer to the supplied group</exception>
        internal IdPacket(IdGroup group, IdAllocation alloc)
        {
            if (group == null || alloc == null)
            {
                throw new ArgumentNullException();
            }

            if (group.Id != alloc.GroupId)
            {
                throw new ArgumentException();
            }

            m_Group       = group;
            m_Allocation  = alloc;
            m_Ids         = new NativeId[m_Allocation.Size];
            m_ReservedIds = new List <uint>();
        }
コード例 #7
0
ファイル: IdManager.cs プロジェクト: 15831944/backsight
        /// <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));
            }
        }
コード例 #8
0
ファイル: IdManager.cs プロジェクト: 15831944/backsight
        /// <summary>
        /// Loads all the ID groups known to the database.
        /// </summary>
        IdGroup[] GetGroups()
        {
            IEnvironmentContainer ec = EnvironmentContainer.Current;

            if (ec == null)
            {
                return(new IdGroup[0]);
            }

            IIdGroup[]     groups = ec.IdGroups;
            List <IdGroup> result = new List <IdGroup>(groups.Length);

            foreach (IIdGroup group in groups)
            {
                if (group.Id != 0)
                {
                    IdGroup idg = new IdGroup(group);
                    result.Add(idg);
                }
            }

            return(result.ToArray());
        }
コード例 #9
0
        void LoadDataFiles(string folderName, uint[] fileNums)
        {
            Trace.Write("Reading data...");
            EditDeserializer ed          = new EditDeserializer(this);
            Session          lastSession = null;
            IdManager        idMan       = m_MapModel.IdManager;

            foreach (uint fileNum in fileNums)
            {
                string editFile = Path.Combine(folderName, ProjectDatabase.GetDataFileName(fileNum));

                using (TextReader tr = File.OpenText(editFile))
                {
                    TextEditReader er = new TextEditReader(tr);

                    // Ignore any empty files altogether
                    while (er.HasNext)
                    {
                        ed.SetReader(er);
                        Change edit = Change.Deserialize(ed);

                        if (edit is NewProjectEvent)
                        {
                            m_ProjectInfo = (NewProjectEvent)edit;

                            // If the project settings don't have default entity types, initialize them with
                            // the layer defaults. This covers a case where the settings file has been lost, and
                            // automatically re-created by ProjectSettings.CreateInstance.

                            var layer = EnvironmentContainer.FindLayerById(m_ProjectInfo.LayerId);
                            m_Settings.SetEntityTypeDefaults(layer);
                        }
                        else if (edit is NewSessionEvent)
                        {
                            lastSession = new Session(this, (NewSessionEvent)edit, editFile);
                            m_MapModel.AddSession(lastSession);
                        }
                        else if (edit is EndSessionEvent)
                        {
                            Debug.Assert(lastSession != null);
                            lastSession.EndTime = edit.When;
                        }
                        else if (edit is IdAllocation)
                        {
                            if (idMan != null)
                            {
                                IdAllocation alloc = (IdAllocation)edit;
                                IdGroup      g     = idMan.FindGroupById(alloc.GroupId);
                                g.AddIdPacket(alloc);

                                // Remember that allocations have been made in the session (bit of a hack
                                // to ensure the session isn't later removed if no edits are actually
                                // performed).
                                lastSession.AddAllocation(alloc);
                            }
                        }
                        else
                        {
                            Debug.Assert(edit is Operation);
                            Debug.Assert(lastSession != null);
                            lastSession.AddOperation((Operation)edit);
                        }
                    }
                }
            }

            if (m_ProjectInfo == null)
            {
                throw new ApplicationException("Could not locate the project creation event");
            }

            // Apply any forward references
            ed.ApplyForwardRefs();

            // Remember the highest internal ID used by the project
            SetLastItem(fileNums[fileNums.Length - 1]);
        }
コード例 #10
0
ファイル: IdHelper.cs プロジェクト: 15831944/backsight
        /// <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);
        }
コード例 #11
0
ファイル: IdManager.cs プロジェクト: steve-stanton/backsight
        /// <summary>
        /// Loads all the ID groups known to the database.
        /// </summary>
        IdGroup[] GetGroups()
        {
            IEnvironmentContainer ec = EnvironmentContainer.Current;
            if (ec == null)
                return new IdGroup[0];

            IIdGroup[] groups = ec.IdGroups;
            List<IdGroup> result = new List<IdGroup>(groups.Length);

            foreach(IIdGroup group in groups)
            {
                if (group.Id != 0)
                {
                    IdGroup idg = new IdGroup(group);
                    result.Add(idg);
                }
            }

            return result.ToArray();
        }
コード例 #12
0
ファイル: IdManager.cs プロジェクト: steve-stanton/backsight
        /// <summary>
        /// Generates an index that cross-references each entity type with its corresponding
        /// ID group.
        /// </summary>
        /// <param name="groups">The ID groups to index</param>
        /// <returns>Index of the ID groups for each entity type. The key is the ID of the entity type,
        /// the values are elements in the <paramref name="groups"/> array.</returns>
        Dictionary<int, IdGroup> GetEntityGroups(IdGroup[] groups)
        {
            IEnvironmentContainer ec = EnvironmentContainer.Current;
            if (ec == null)
                return new Dictionary<int, IdGroup>();

            IEntity[] ents = ec.EntityTypes;
            Dictionary<int, IdGroup> result = new Dictionary<int, IdGroup>(ents.Length);

            foreach (IEntity e in ents)
            {
                IIdGroup idg = e.IdGroup;
                if (idg!=null && idg.Id>0)
                {
                    int gid = idg.Id;
                    IdGroup entGroup = Array.Find<IdGroup>(groups, g => g.Id==gid);
                    Debug.Assert(entGroup!=null);
                    result.Add(e.Id, entGroup);
                }
            }

            return result;
        }
コード例 #13
0
ファイル: NativeId.cs プロジェクト: 15831944/backsight
 /// <summary>
 /// Initializes a new instance of the <see cref="NativeId"/> class.
 /// </summary>
 /// <param name="key">The raw ID value that identifies a feature</param>
 internal NativeId(IdGroup group, uint key)
 {
     m_Group = group;
     m_Key   = key;
 }
コード例 #14
0
ファイル: NativeId.cs プロジェクト: steve-stanton/backsight
 /// <summary>
 /// Initializes a new instance of the <see cref="NativeId"/> class.
 /// </summary>
 /// <param name="key">The raw ID value that identifies a feature</param>
 internal NativeId(IdGroup group, uint key)
 {
     m_Group = group;
     m_Key = key;
 }