Beispiel #1
0
        /// <summary>
        /// Aborts this command.
        /// </summary>
        /// <returns>True (always).</returns>
        protected bool AbortCommand()
        {
            // If this command was invoked by an update command, get
            // the update to clean up. Otherwise tell the controller.

            if (m_UpdCmd != null)
            {
                m_UpdCmd.AbortCommand(this);
            }
            else
            {
                this.Controller.AbortCommand(this);
            }

            // Ensure that any reserved IDs have been released
            IdManager idMan = CadastralMapModel.Current.IdManager;

            if (idMan != null)
            {
                idMan.FreeAllReservedIds();
            }

            return(true);
        }
Beispiel #2
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]);
        }
Beispiel #3
0
        /// <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);
        }