Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MultiSegmentGeometry"/> class
        /// using the data read from persistent storage.
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        internal MultiSegmentGeometry(EditDeserializer editDeserializer)
            : base(editDeserializer)
        {
            // LineString assumes 2D, with X preceding Y. Each coordinate pair is separated
            // with a comma, with a space between each X and Y (e.g. "123 345,124 349,129 341")

            string s = editDeserializer.ReadString(DataField.LineString);

            string[] xys = s.Split(',');
            m_Data = new IPointGeometry[xys.Length];

            for (int i = 0; i < xys.Length; i++)
            {
                string xy = xys[i].Trim();

                int blankPos = xy.IndexOf(' ');
                if (blankPos <= 0)
                {
                    throw new FormatException();
                }

                double x = Double.Parse(xy.Substring(0, blankPos));
                double y = Double.Parse(xy.Substring(blankPos + 1));
                m_Data[i] = new PointGeometry(x, y);
            }

            m_Extent = LineStringGeometry.GetExtent(this);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IdAllocation"/> class.
 /// </summary>
 /// <param name="ed">The mechanism for reading back content.</param>
 internal IdAllocation(EditDeserializer ed)
     : base(ed)
 {
     this.GroupId   = ed.ReadInt32(DataField.GroupId);
     this.LowestId  = ed.ReadInt32(DataField.LowestId);
     this.HighestId = ed.ReadInt32(DataField.HighestId);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArcGeometry"/> class
        /// using the data read from persistent storage.
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        internal ArcGeometry(EditDeserializer editDeserializer)
            : base(editDeserializer)
        {
            m_IsClockwise = editDeserializer.ReadBool(DataField.Clockwise);

            if (editDeserializer.IsNextField(DataField.Center))
            {
                PointFeature center = editDeserializer.ReadFeatureRef <PointFeature>(this, DataField.Center);

                // The arc is the first arc attached to the circle. However, we cannot
                // calculate the radius just yet because the bc/ec points are not persisted
                // as part of the ArcGeometry definition (they are defined as part of the
                // LineFeature object that utilizes the ArcGeometry).

                // Even if we did have the bc/ec points at this stage, their positions will
                // only be available if the data came from an import (they will still be
                // undefined if the geometry is calculated, since calculation only occurs
                // after deserialization has been completed).

                if (center != null)
                {
                    ApplyFeatureRef(DataField.Center, center);
                }
            }
            else
            {
                ArcFeature firstArc = editDeserializer.ReadFeatureRef <ArcFeature>(this, DataField.FirstArc);
                if (firstArc != null)
                {
                    ApplyFeatureRef(DataField.FirstArc, firstArc);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads the content of an editing event.
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        /// <returns>The created editing event object</returns>
        static internal Change Deserialize(EditDeserializer editDeserializer)
        {
            Change result = editDeserializer.ReadPersistent <Change>(DataField.Edit);

            // Note that calculated geometry is NOT defined at this stage. That happens
            // when the model is asked to index the data.

            // Associate referenced features with the edit
            result.AddReferences();

            // If we're dealing with an update, exchange update items. Do this NOW (rather than at it's natural
            // spot in the editing sequence) so as to avoid repeated calculation loops during loading. When an
            // update is applied during regular editing work, we have to rework the calculation sequence and
            // rollforward all the subsequent edits. So we'd have to do that for every update. By applying changes
            // now, we'll end up doing a single calculation loop.

            UpdateOperation upo = (result as UpdateOperation);

            if (upo != null)
            {
                upo.ApplyChanges();
            }

            return(result);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Operation"/> class
 /// using the data read from persistent storage.
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 protected Operation(EditDeserializer editDeserializer)
     : base(editDeserializer)
 {
     editDeserializer.CurrentEdit = this;
     m_Session = editDeserializer.MapModel.LastSession;
     Debug.Assert(m_Session != null);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PointFeature"/> class
        /// using the data read from persistent storage.
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        internal PointFeature(EditDeserializer editDeserializer)
            : base(editDeserializer)
        {
            long x, y;

            ReadData(editDeserializer, out x, out y);
            m_Geom = new Node(this, new PointGeometry(x, y));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LineGeometry"/> class
        /// using the data read from persistent storage.
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        protected LineGeometry(EditDeserializer editDeserializer)
        {
            // When deserializing line geometry (in the context of line features), passing
            // the terminal down via the EditDeserializer is a bit too contrived. Instead,
            // we'll set the terminals back in LineFeature.ReadData.

            m_Start = m_End = null;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MiscTextGeometry"/> class
        /// using the data read from persistent storage.
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        internal RowTextGeometry(EditDeserializer editDeserializer)
            : base(editDeserializer)
        {
            // This constructor exists only to satisfy the requirement that classes implementing
            // IPersistent (as specified by the TextGeometry class) must also provide a constructor
            // that accepts a deserializer object. The RowTextContent class must be used instead.

            throw new ApplicationException("Unexpected attempt to deserialize RowTextGeometry");
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SectionGeometry"/> class
        /// using the data read from persistent storage.
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        internal SectionGeometry(EditDeserializer editDeserializer)
            : base(editDeserializer)
        {
            m_Base = editDeserializer.ReadFeatureRef <LineFeature>(DataField.Base);

            if (m_Base == null)
            {
                throw new ArgumentNullException();
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NewProjectEvent"/> class.
 /// </summary>
 /// <param name="ed">The mechanism for reading back content.</param>
 internal NewProjectEvent(EditDeserializer ed)
     : base(ed)
 {
     this.ProjectId     = new Guid(ed.ReadString(DataField.ProjectId));
     this.ProjectName   = ed.ReadString(DataField.ProjectName);
     this.LayerId       = ed.ReadInt32(DataField.LayerId);
     this.DefaultSystem = ed.ReadString(DataField.CoordinateSystem);
     this.UserName      = ed.ReadString(DataField.UserName);
     this.MachineName   = ed.ReadString(DataField.MachineName);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Loads a miscellaneous value back from a storage medium (so long as it comes next in the supplied
        /// deserialization stream).
        /// </summary>
        /// <typeparam name="T">The type of value expected by the caller.</typeparam>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        /// <param name="field">The tag that identifies the value.</param>
        /// <returns>True if an item was loaded, false if the next item in the deserialization
        /// stream does not have the specified name.</returns>
        internal bool ReadItem <T>(EditDeserializer editDeserializer, DataField field) where T : IConvertible
        {
            if (editDeserializer.IsNextField(field))
            {
                T result = editDeserializer.ReadValue <T>(field);
                Add(new UpdateItem(field, result));
                return(true);
            }

            return(false);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Change"/> class
        /// using the data read from persistent storage.
        /// </summary>
        /// <param name="ed">The mechanism for reading back content.</param>
        protected Change(EditDeserializer ed)
        {
            m_Sequence = ed.ReadUInt32(DataField.Id);
            m_When     = ed.ReadDateTime(DataField.When);

            // Handle old files
            //if (ed.IsNextField(DataField.When))
            //    m_When = ed.ReadDateTime(DataField.When);
            //else
            //    m_When = DateTime.Now; // could perhaps grab the session start time
        }
Exemplo n.º 13
0
        /// <summary>
        /// Loads an observation back from a storage medium (so long as it comes next in the supplied
        /// deserialization stream).
        /// </summary>
        /// <typeparam name="T">The type of object expected by the caller.</typeparam>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        /// <param name="field">The tag that identifies the item.</param>
        /// <returns>True if an observation was loaded, false if the next item in the deserialization
        /// stream does not have the specified name.</returns>
        internal bool ReadObservation <T>(EditDeserializer editDeserializer, DataField field) where T : Observation
        {
            if (editDeserializer.IsNextField(field))
            {
                T result = editDeserializer.ReadPersistent <T>(field);
                Add(new UpdateItem(field, result));
                return(true);
            }

            return(false);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Loads a feature reference back from a storage medium (so long as it comes next in the supplied
        /// deserialization stream).
        /// </summary>
        /// <typeparam name="T">The type of feature expected by the caller.</typeparam>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        /// <param name="field">The tag that identifies the item.</param>
        /// <returns>True if a feature reference was loaded, false if the next item in the deserialization
        /// stream does not have the specified name.</returns>
        internal bool ReadFeature <T>(EditDeserializer editDeserializer, DataField field) where T : Feature
        {
            if (editDeserializer.IsNextField(field))
            {
                T result = editDeserializer.ReadFeatureRef <T>(field);
                Add(new UpdateItem(field, result));
                return(true);
            }

            return(false);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextFeature"/> class
        /// using the data read from persistent storage.
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        internal TextFeature(EditDeserializer editDeserializer)
            : base(editDeserializer)
        {
            bool isTopological;

            ReadData(editDeserializer, out isTopological, out m_PolygonPosition, out m_Geom);
            SetTopology(isTopological);

            if (m_Geom is KeyTextGeometry)
            {
                (m_Geom as KeyTextGeometry).Label = this;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LegFace"/> class
        /// using the data read from persistent storage.
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        internal LegFace(EditDeserializer editDeserializer)
        {
            // Only connection paths should generate LegFace instances
            PathOperation op = (editDeserializer.CurrentEdit as PathOperation);

            if (op == null)
            {
                throw new ApplicationException("Unexpected creating edit for a leg face");
            }

            this.Sequence = editDeserializer.ReadInternalId(DataField.Id);

            if (editDeserializer.IsNextField(DataField.PrimaryFaceId))
            {
                InternalIdValue primaryFaceId = editDeserializer.ReadInternalId(DataField.PrimaryFaceId);
                LegFace         face          = op.FindFace(primaryFaceId);

                if (face == null)
                {
                    throw new ApplicationException("Cannot locate primary face " + primaryFaceId);
                }

                Leg = face.Leg;
                Leg.AlternateFace = this;
            }
            else
            {
                // This should never happen. Primary faces are not serialized using the LegFace
                // class (we only use LegFace as part of a PathOperation to simplify import of
                // extra legs from old CEdit files).

                throw new ApplicationException();
            }

            // Convert the data entry string into observed spans
            string       entryString      = editDeserializer.ReadString(DataField.EntryString);
            DistanceUnit defaultEntryUnit = EditingController.Current.EntryUnit;

            Distance[] dists = LineSubdivisionFace.GetDistances(entryString, defaultEntryUnit, false);
            m_Spans = new SpanInfo[dists.Length];

            for (int i = 0; i < m_Spans.Length; i++)
            {
                m_Spans[i] = new SpanInfo()
                {
                    ObservedDistance = dists[i]
                };
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Reads data that was previously written using <see cref="WriteData"/>
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        /// <param name="isTopological">Are we dealing with a polygon label</param>
        /// <param name="polPos">The label reference point (usually applies onlt to polygon labels). Null if it's
        /// identical to the position recorded via the geometry object.</param>
        /// <param name="geom">The geometry for the text.</param>
        static void ReadData(EditDeserializer editDeserializer, out bool isTopological, out PointGeometry polPos, out TextGeometry geom)
        {
            isTopological = editDeserializer.ReadBool(DataField.Topological);

            if (editDeserializer.IsNextField(DataField.PolygonX))
            {
                polPos = editDeserializer.ReadPointGeometry(DataField.PolygonX, DataField.PolygonY);
            }
            else
            {
                polPos = null;
            }

            geom = editDeserializer.ReadPersistent <TextGeometry>(DataField.Type);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Feature"/> class
        /// using the data read from persistent storage.
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        protected Feature(EditDeserializer editDeserializer)
        {
            m_Creator = editDeserializer.CurrentEdit;
            Debug.Assert(m_Creator != null);
            ReadData(editDeserializer, out m_InternalId, out m_What, out m_Id);
            m_References = null;
            m_Flag       = 0;

            // If a user-defined ID is present, ensure it knows about this feature, and vice versa
            if (m_Id != null)
            {
                m_Id.AddReference(this);
            }

            // Remember this feature as part of the model
            m_Creator.MapModel.AddFeature(this);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Reads data that was previously written using <see cref="WriteData"/>
        /// </summary>
        /// <param name="editDeserializer">The mechanism for reading back content.</param>
        /// <param name="font">The text style</param>
        /// <param name="position">Position of the text's reference point</param>
        /// <param name="height">The height of the text, in meters on the ground.</param>
        /// <param name="width">The total width of the text, in meters on the ground.</param>
        /// <param name="rotation">Clockwise rotation from horizontal</param>
        static void ReadData(EditDeserializer editDeserializer, out IFont font, out PointGeometry position,
                             out float height, out float width, out IAngle rotation)
        {
            if (editDeserializer.IsNextField(DataField.Font))
            {
                int fontId = editDeserializer.ReadInt32(DataField.Font);
                font = EnvironmentContainer.FindFontById(fontId);
            }
            else
            {
                font = null;
            }

            position = editDeserializer.ReadPointGeometry(DataField.X, DataField.Y);
            width    = (float)editDeserializer.ReadDouble(DataField.Width);
            height   = (float)editDeserializer.ReadDouble(DataField.Height);
            rotation = editDeserializer.ReadRadians(DataField.Rotation);
        }
Exemplo n.º 20
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]);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MiscTextGeometry"/> class
 /// using the data read from persistent storage.
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 internal MiscTextGeometry(EditDeserializer editDeserializer)
     : base(editDeserializer)
 {
     m_Text = editDeserializer.ReadString(DataField.Text);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RowTextContent"/> class
 /// using the data read from persistent storage.
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 internal RowTextContent(EditDeserializer editDeserializer)
     : base(editDeserializer)
 {
     m_TableId    = editDeserializer.ReadInt32(DataField.Table);
     m_TemplateId = editDeserializer.ReadInt32(DataField.Template);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Reads data that was previously written using <see cref="WriteData"/>
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 /// <param name="line">The line the point should appear on </param>
 /// <param name="positionRatio">The position ratio of the attached point.</param>
 /// <param name="point">The point that was created.</param>
 static void ReadData(EditDeserializer editDeserializer, out long x, out long y)
 {
     x = editDeserializer.ReadInt64(DataField.X);
     y = editDeserializer.ReadInt64(DataField.Y);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnsectionedLineGeometry"/> class
 /// using the data read from persistent storage.
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 protected UnsectionedLineGeometry(EditDeserializer editDeserializer)
     : base(editDeserializer)
 {
 }
Exemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FeatureStub"/> class
 /// using the data read from persistent storage.
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 internal FeatureStub(EditDeserializer editDeserializer)
 {
     m_Creator = editDeserializer.CurrentEdit;
     Debug.Assert(m_Creator != null);
     ReadData(editDeserializer, out m_InternalId, out m_What, out m_Id);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Reads data that was previously written using <see cref="WriteData"/>
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 /// <param name="id">The internal of the feature within the project that created it.</param>
 /// <param name="entity">The type of real-world object that the feature corresponds to.</param>
 /// <param name="fid">The ID of the feature (may be null).</param>
 static void ReadData(EditDeserializer editDeserializer, out InternalIdValue id, out IEntity entity, out FeatureId fid)
 {
     id     = editDeserializer.ReadInternalId(DataField.Id);
     entity = editDeserializer.ReadEntity(DataField.Entity);
     fid    = editDeserializer.ReadFeatureId();
 }
Exemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TextGeometry"/> class
 /// using the data read from persistent storage.
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 protected TextGeometry(EditDeserializer editDeserializer)
 {
     ReadData(editDeserializer, out m_Font, out m_Position, out m_Height, out m_Width, out m_Rotation);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyTextGeometry"/> class
 /// using the data read from persistent storage.
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 internal KeyTextGeometry(EditDeserializer editDeserializer)
     : base(editDeserializer)
 {
     // Nothing to do - the TextFeature constructor must define the Label property after
     // this geometry object has been created.
 }
Exemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ArcFeature"/> class
 /// using the data read from persistent storage.
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 internal ArcFeature(EditDeserializer editDeserializer)
     : base(editDeserializer)
 {
 }
Exemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IdMapping"/> class
 /// using the data read from persistent storage.
 /// </summary>
 /// <param name="editDeserializer">The mechanism for reading back content.</param>
 internal IdMapping(EditDeserializer editDeserializer)
 {
     m_InternalId = editDeserializer.ReadInternalId(DataField.Id);
     m_RawId      = editDeserializer.ReadUInt32(DataField.Key);
 }