Beispiel #1
0
        void ExportKey(TextFeature text)
        {
            Layer layer = m_Layers.GetLayer(text, m_ContinuousLineType, true);

            if (layer == null)
            {
                return;
            }

            // Get the label's key string. It HAS to be defined.
            string keystr = text.FormattedKey;

            if (String.IsNullOrEmpty(keystr))
            {
                return;
            }

            // Get the label's reference position.
            IPointGeometry refpos = text.GetPolPosition();

            // Define the position for AutoCad (bottom right corner).


            TextGeometry geom   = text.TextGeometry;
            Text         acText = new Text(geom.Text, GetVector(geom.Position), geom.Height);

            acText.Rotation = (float)geom.Rotation.Degrees;
            acText.Layer    = layer;

            m_Dxf.AddEntity(acText);
        }
        /// <summary>
        /// Delegate that's called whenever the index finds text with a window that overlaps the query window
        /// </summary>
        /// <param name="item">The item to process (expected to be some sort of <c>TextFeature</c>)</param>
        /// <returns>True (always), indicating that the query should continue.</returns>
        private bool OnTextFound(ISpatialObject item)
        {
            // Ignore test that's already been built
            TextFeature text = (TextFeature)item;

            if (text.IsBuilt)
            {
                return(true);
            }

            if (text.IsTopological)
            {
                // Get the label's reference position.
                IPointGeometry posn = text.GetPolPosition();

                // Try to find enclosing polygon
                if (m_Polygon.IsEnclosing(posn))
                {
                    m_Result = text;
                    return(false);
                }
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Performs checks for a text label.
        /// </summary>
        /// <param name="label">The label to check.</param>
        /// <returns>The problem(s) that were found.</returns>
        internal static CheckType CheckLabel(TextFeature label)
        {
            CheckType types = CheckType.Null;
            Polygon   p     = label.Container;

            if (p == null)
            {
                types |= CheckType.NoPolygonForLabel;
            }
            else
            {
                // Does the polygon point back? If not, we've got a multi-label.
                if (p.LabelCount > 1 && p.Label != label)
                {
                    types |= CheckType.MultiLabel;
                }
            }

            // Does the label have at least one row of attribute data?
            FeatureId fid = label.FeatureId;

            if (fid == null || fid.RowCount == 0)
            {
                types |= CheckType.NoAttributes;
            }

            return(types);
        }
Beispiel #4
0
        bool WriteText(ISpatialObject item)
        {
            TextFeature text = (item as TextFeature);

            if (this.IsTopological)
            {
                ExportKey(text);
            }
            else
            {
            }

            // Skip if the AutoCad layer cannot be determined
            Layer layer = m_Layers.GetLayer(text, m_ContinuousLineType, this.IsTopological);

            if (layer != null)
            {
                TextGeometry geom   = text.TextGeometry;
                Text         acText = new Text(geom.Text, GetVector(geom.Position), geom.Height);
                acText.Rotation = (float)geom.Rotation.Degrees;
                acText.Layer    = layer;

                m_Dxf.AddEntity(acText);
            }
            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Adds a reference from this ID to a row.
        /// </summary>
        /// <param name="row">The row to point to.</param>
        internal void AddReference(Row row)
        {
            m_Rows = (m_Rows == null ? row : m_Rows.Add(row));

            // Check whether any associated features are instances of TextFeature that
            // have RowTextContent geometry (a placeholder class that is meant to exist
            // only during deserialization from the database). If so, see whether the
            // geometry can now be replaced with the "proper" RowTextGeometry.

            if (m_Features != null)
            {
                foreach (Feature f in m_Features)
                {
                    TextFeature tf = (f as TextFeature);
                    if (tf != null)
                    {
                        RowTextContent content = (tf.TextGeometry as RowTextContent);
                        if (content != null && content.TableId == row.Table.Id)
                        {
                            tf.TextGeometry = new RowTextGeometry(row, content);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Delegate called to process each text feature found within the build window.
        /// Called by <see cref="BuildLabels"/>.
        /// </summary>
        /// <param name="o">An item found in the spatial index.</param>
        /// <returns>True (always), indicating that the spatial query should keep going.</returns>
        bool ProcessLabel(ISpatialObject o)
        {
            Debug.Assert(o is TextFeature);
            TextFeature f = (TextFeature)o;

            f.SetPolygon();
            return(true);
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new <c>TextCheck</c> that relates to the specified text.
        /// </summary>
        /// <param name="label">The text the check relates to (not null).</param>
        /// <param name="types">The type(s) of check this item corresponds to</param>
        /// <exception cref="ArgumentNullException">If <paramref name="label"/> is null</exception>
        internal TextCheck(TextFeature label, CheckType types)
            : base(types)
        {
            if (label==null)
                throw new ArgumentNullException();

            m_Label = label;
        }
        /// <summary>
        /// Creates a new <c>FindPolygonLabelQuery</c> (and executes it). The result of the query
        /// can then be obtained through the <c>Result</c> property.
        /// </summary>
        /// <param name="index">The spatial index to search</param>
        /// <param name="polygon">The polygon that needs to be associated with a label</param>
        internal FindPolygonLabelQuery(ISpatialIndex index, Polygon polygon)
        {
            m_Polygon = polygon;
            m_Result = null;

            if (!polygon.HasAnyIslands)
                index.QueryWindow(m_Polygon.Extent, SpatialType.Text, OnTextFound);
        }
Beispiel #9
0
        /// <summary>
        /// Changes the text for this object
        /// </summary>
        /// <param name="s">The new value for this geometry</param>
        internal void SetText(TextFeature label, string s)
        {
            CadastralMapModel map   = label.MapModel;
            EditingIndex      index = map.EditingIndex;

            index.RemoveFeature(label);
            m_Text = s;
            index.AddFeature(label);
        }
        /// <summary>
        /// Creates a new <c>FindPolygonLabelQuery</c> (and executes it). The result of the query
        /// can then be obtained through the <c>Result</c> property.
        /// </summary>
        /// <param name="index">The spatial index to search</param>
        /// <param name="polygon">The polygon that needs to be associated with a label</param>
        internal FindPolygonLabelQuery(ISpatialIndex index, Polygon polygon)
        {
            m_Polygon = polygon;
            m_Result  = null;

            if (!polygon.HasAnyIslands)
            {
                index.QueryWindow(m_Polygon.Extent, SpatialType.Text, OnTextFound);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Creates a new <c>TextCheck</c> that relates to the specified text.
        /// </summary>
        /// <param name="label">The text the check relates to (not null).</param>
        /// <param name="types">The type(s) of check this item corresponds to</param>
        /// <exception cref="ArgumentNullException">If <paramref name="label"/> is null</exception>
        internal TextCheck(TextFeature label, CheckType types)
            : base(types)
        {
            if (label == null)
            {
                throw new ArgumentNullException();
            }

            m_Label = label;
        }
Beispiel #12
0
        /// <summary>
        /// The ID associated with this polygon. This is actually the ID of
        /// the polygon's label (if any).
        /// </summary>
        /// <returns>The polygon label's ID (if any).</returns>
        internal FeatureId GetId()
        {
            // Return if this polygon does not have any labels.
            TextFeature label = this.Label;

            if (label == null)
            {
                return(null);
            }

            // Return the ID of the label.
            return(label.FeatureId);
        }
Beispiel #13
0
        /// <summary>
        /// Breaks the association between this polygon and an enclosed label
        /// </summary>
        /// <param name="label">The label that was formerly enclosed by this polygon (the label's
        /// <see cref="TextFeature.Container"/> property will be nulled)</param>
        internal void ReleaseLabel(TextFeature label)
        {
            Debug.Assert(label != null);
            label.Container = null;

            if (m_Labels != null)
            {
                m_Labels.Remove(label);
                if (m_Labels.Count == 0)
                {
                    m_Labels = null;
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// Locates any text features associated with this ID that have
        /// <see cref="RowTextGeometry"/>.
        /// </summary>
        /// <returns>Any text features associated with this ID that
        /// have a geometry that's dependent on database attributes. May be
        /// an empty array (but never null)</returns>
        internal TextFeature[] GetRowText()
        {
            List <TextFeature> result = new List <TextFeature>();

            if (m_Features != null)
            {
                foreach (Feature f in m_Features)
                {
                    TextFeature tf = (f as TextFeature);
                    if (tf != null && (tf.TextGeometry is RowTextGeometry))
                    {
                        result.Add(tf);
                    }
                }
            }

            return(result.ToArray());
        }
Beispiel #15
0
        /// <summary>
        /// Delegate that's called whenever the index finds text with a window that overlaps the query window
        /// </summary>
        /// <param name="item">The item to process (expected to be some sort of <c>TextFeature</c>)</param>
        /// <returns>True (always), indicating that the query should continue.</returns>
        private bool OnTextFound(ISpatialObject item)
        {
            TextFeature text = (TextFeature)item;

            // Get the outline for the text
            IPosition[] outline = text.TextGeometry.Outline;

            // If any corner of the text outline is inside the closed shape (or any edge of
            // the outline intersects), remember the text in the results
            ClosedShape cs = new ClosedShape(outline);

            if (cs.IsOverlap(m_ClosedShape))
            {
                m_Result.Add(text);
            }

            return(true);
        }
Beispiel #16
0
        /// <summary>
        /// Associates this polygon with the specified label
        /// </summary>
        /// <param name="label">The label to associate with this polygon (usually appearing
        /// somewhere inside the polygon).</param>
        internal void ClaimLabel(TextFeature label)
        {
            Debug.Assert(label != null);

            // Refer the label to this polygon (even if this polygon doesn't end up pointing back)
            label.Container = this;

            /*
             * if (m_Label!=null && !Object.ReferenceEquals(m_Label, label))
             * {
             *  string msg = String.Format("Label {0} falls inside same polygon as label {1}",
             *                                  label.ToString(), m_Label.ToString());
             *  Trace.TraceWarning(msg);
             * }
             */

            // Associate this polygon with the supplied label
            if (m_Labels == null)
            {
                m_Labels = new List <TextFeature>(1);
            }

            m_Labels.Add(label);
        }
Beispiel #17
0
        /// <summary>
        /// Delegate that's called whenever the index finds an item of text.
        /// </summary>
        /// <param name="item">The item to process</param>
        /// <returns>True (always), indicating that the query should continue.</returns>
        private bool CheckText(ISpatialObject item)
        {
            Debug.Assert(item is TextFeature);
            TextFeature label = (TextFeature)item;

            // Return if the label is non-topological
            if (!label.IsTopological)
            {
                return(true);
            }

            // Check the label & restrict to requested types.
            CheckType types = TextCheck.CheckLabel(label);

            types &= m_Options;

            if (types != CheckType.Null)
            {
                TextCheck check = new TextCheck(label, types);
                m_Result.Add(check);
            }

            return(OnCheck());
        }
Beispiel #18
0
        /// <summary>
        /// Breaks the association between this polygon and an enclosed label
        /// </summary>
        /// <param name="label">The label that was formerly enclosed by this polygon (the label's
        /// <see cref="TextFeature.Container"/> property will be nulled)</param>
        internal void ReleaseLabel(TextFeature label)
        {
            Debug.Assert(label!=null);
            label.Container = null;

            if (m_Labels!=null)
            {
                m_Labels.Remove(label);
                if (m_Labels.Count==0)
                    m_Labels = null;
            }
        }
Beispiel #19
0
        private Feature ImportName(Ntx.Name name, Operation creator)
        {
            /*
             * // Get pointer to the applicable map theme
             * CeTheme theme(Name.GetTheme());
             * CeTheme* pTheme = theme.AddTheme();
             *
             * // Get pointer to the entity type.
             * GRAPHICSTYPE geom = ANNOTATION;
             * if ( Name.IsLabel() ) geom = POLYGON;
             * CeEntity* pEntity = AddEntity(Name.GetpFeatureCode(),pTheme,geom);
             */
            IEntity entity = GetEntityType(name, SpatialType.Text);

            // Get the text string
            string text = name.Text;

            // Get the position of the centre of the 1st character
            Ntx.Position pos     = name.Position(0);
            IPosition    vcentre = new Position(pos.Easting, pos.Northing);

            // Get text metrics
            float height   = name.Height;
            float spacing  = name.Spacing;
            float rotation = name.Rotation;

            // Calculate the top left corner of the first character using
            // the text metrics we just got ...

            // Get the width of the first character. For names that contain
            // only one character, the spacing we have will be zero, so in
            // that case, deduce the width of the character via the covering
            // rectangle.

            float charwidth = spacing;

            if (charwidth < Constants.TINY)
            {
                // Get the covering rectangle.
                Ntx.Position nw = name.NorthWest;
                Ntx.Position se = name.SouthEast;

                // And get the dimensions.
                double dx = se.Easting - nw.Easting;
                double dy = nw.Northing - se.Northing;

                // If the cover is screwed up, assume the width is 80% of the text height.
                if (dy < Constants.TINY)
                {
                    charwidth = (float)(height * 0.8);
                }
                else
                {
                    charwidth = (float)(height * (dx / dy));
                }
            }

            // Define the bearing from bottom to top of the text.
            double vbear = (double)rotation;

            // Get position directly above the centre of the 1st char.
            IPosition above = Geom.Polar(vcentre, vbear, 0.5 * (double)height);

            // Define the bearing from the point we just got to the
            // start of the text string.
            double hbear = vbear - Constants.PIDIV2;

            // Back up half a character to get the initial corner.
            PointGeometry topleft = new PointGeometry(Geom.Polar(above, hbear, 0.5 * (double)charwidth));

            IFont       font   = null;
            double      width  = (double)text.Length * charwidth;
            TextFeature result = null;

            if (name.IsLabel)
            {
                // Create key text
                string          keystr = name.Text;
                KeyTextGeometry kt     = new KeyTextGeometry(topleft, font, height, width, rotation);
                InternalIdValue id     = CadastralMapModel.Current.WorkingSession.AllocateNextId();
                result   = new TextFeature(creator, id, entity, kt);
                kt.Label = result;
                result.SetTopology(true);

                // Define the label's foreign ID and form a two-way association
                ForeignId fid = GetFeatureId(keystr);
                Debug.Assert(fid != null);
                fid.Add(result);

                // Remember the reference position of the label.
                Ntx.Position   xp = name.RefPosition;
                IPointGeometry pp = new PointGeometry(xp.Easting, xp.Northing);
                result.SetPolPosition(pp);
            }
            else
            {
                // Create a miscellaneous text label.
                MiscTextGeometry mt = new MiscTextGeometry(text, topleft, font, height, width, rotation);
                InternalIdValue  id = CadastralMapModel.Current.WorkingSession.AllocateNextId();
                result = new TextFeature(creator, id, entity, mt);
                result.SetTopology(false);
            }

            return(result);
        }
Beispiel #20
0
        void ExportKey(TextFeature text)
        {
            Layer layer = m_Layers.GetLayer(text, m_ContinuousLineType, true);
            if (layer == null)
                return;

            // Get the label's key string. It HAS to be defined.
            string keystr = text.FormattedKey;
            if (String.IsNullOrEmpty(keystr))
                return;

            // Get the label's reference position.
            IPointGeometry refpos = text.GetPolPosition();

            // Define the position for AutoCad (bottom right corner).

            TextGeometry geom = text.TextGeometry;
            Text acText = new Text(geom.Text, GetVector(geom.Position), geom.Height);
            acText.Rotation = (float)geom.Rotation.Degrees;
            acText.Layer = layer;

            m_Dxf.AddEntity(acText);
        }
 /// <summary>
 /// Creates a new <c>KeyTextGeometry</c> that isn't associated with a text feature. There is a chicken and egg
 /// problem here - an instance of KeyTextGeometry is expected to refer to a TextFeature, but the feature cannot
 /// be created until the geometry has been created. So after creating the KeyTextGeometry, you are expected to
 /// create the corresponding feature, then assign the feature to this geometry using the <see cref="Label"/>
 /// property.
 /// </summary>
 /// <param name="pos">Position of the text's reference point (always the top left corner of the string).</param>
 /// <param name="font">The text style (defines the type-face and the height of the text).</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>
 internal KeyTextGeometry(PointGeometry pos, IFont font, double height, double width, float rotation)
     : base(pos, font, height, width, rotation)
 {
     m_Feature = null;
 }
Beispiel #22
0
        /// <summary>
        /// Performs checks for a text label.
        /// </summary>
        /// <param name="label">The label to check.</param>
        /// <returns>The problem(s) that were found.</returns>
        internal static CheckType CheckLabel(TextFeature label)
        {
            CheckType types = CheckType.Null;
            Polygon p = label.Container;

            if (p==null)
                types |= CheckType.NoPolygonForLabel;
            else
            {
                // Does the polygon point back? If not, we've got a multi-label.
                if (p.LabelCount>1 && p.Label!=label)
                    types |= CheckType.MultiLabel;
            }

            // Does the label have at least one row of attribute data?
            FeatureId fid = label.FeatureId;
            if (fid==null || fid.RowCount==0)
                types |= CheckType.NoAttributes;

            return types;
        }
Beispiel #23
0
        private Feature ImportName(Ntx.Name name, Operation creator)
        {
            /*
            // Get pointer to the applicable map theme
            CeTheme theme(Name.GetTheme());
            CeTheme* pTheme = theme.AddTheme();

            // Get pointer to the entity type.
            GRAPHICSTYPE geom = ANNOTATION;
            if ( Name.IsLabel() ) geom = POLYGON;
            CeEntity* pEntity = AddEntity(Name.GetpFeatureCode(),pTheme,geom);
             */
            IEntity entity = GetEntityType(name, SpatialType.Text);

            // Get the text string
            string text = name.Text;

            // Get the position of the centre of the 1st character
            Ntx.Position pos = name.Position(0);
            IPosition vcentre = new Position(pos.Easting, pos.Northing);

            // Get text metrics
            float height = name.Height;
            float spacing = name.Spacing;
            float rotation = name.Rotation;

            // Calculate the top left corner of the first character using
            // the text metrics we just got ...

            // Get the width of the first character. For names that contain
            // only one character, the spacing we have will be zero, so in
            // that case, deduce the width of the character via the covering
            // rectangle.

            float charwidth = spacing;
            if (charwidth < Constants.TINY)
            {
                // Get the covering rectangle.
                Ntx.Position nw = name.NorthWest;
                Ntx.Position se = name.SouthEast;

                // And get the dimensions.
                double dx = se.Easting - nw.Easting;
                double dy = nw.Northing - se.Northing;

                // If the cover is screwed up, assume the width is 80% of the text height.
                if (dy < Constants.TINY)
                    charwidth = (float)(height * 0.8);
                else
                    charwidth = (float)(height * (dx/dy));
            }

            // Define the bearing from bottom to top of the text.
            double vbear = (double)rotation;

            // Get position directly above the centre of the 1st char.
            IPosition above = Geom.Polar(vcentre, vbear, 0.5 * (double)height);

            // Define the bearing from the point we just got to the
            // start of the text string.
            double hbear = vbear - Constants.PIDIV2;

            // Back up half a character to get the initial corner.
            PointGeometry topleft = new PointGeometry(Geom.Polar(above, hbear, 0.5 * (double)charwidth));

            IFont font = null;
            double width = (double)text.Length * charwidth;
            TextFeature result = null;

            if (name.IsLabel)
            {
                // Create key text
                string keystr = name.Text;
                KeyTextGeometry kt = new KeyTextGeometry(topleft, font, height, width, rotation);
                InternalIdValue id = CadastralMapModel.Current.WorkingSession.AllocateNextId();
                result = new TextFeature(creator, id, entity, kt);
                kt.Label = result;
                result.SetTopology(true);

                // Define the label's foreign ID and form a two-way association
                ForeignId fid = GetFeatureId(keystr);
                Debug.Assert(fid != null);
                fid.Add(result);

                // Remember the reference position of the label.
                Ntx.Position xp = name.RefPosition;
                IPointGeometry pp = new PointGeometry(xp.Easting, xp.Northing);
                result.SetPolPosition(pp);
            }
            else
            {
                // Create a miscellaneous text label.
                MiscTextGeometry mt = new MiscTextGeometry(text, topleft, font, height, width, rotation);
                InternalIdValue id = CadastralMapModel.Current.WorkingSession.AllocateNextId();
                result = new TextFeature(creator, id, entity, mt);
                result.SetTopology(false);
            }

            return result;
        }
        /// <summary>
        /// Delegate that's called whenever the index finds text with a window that overlaps the query window
        /// </summary>
        /// <param name="item">The item to process (expected to be some sort of <c>TextFeature</c>)</param>
        /// <returns>True (always), indicating that the query should continue.</returns>
        private bool OnTextFound(ISpatialObject item)
        {
            // Ignore test that's already been built
            TextFeature text = (TextFeature)item;
            if (text.IsBuilt)
                return true;

            if (text.IsTopological)
            {
                // Get the label's reference position.
                IPointGeometry posn = text.GetPolPosition();

                // Try to find enclosing polygon
                if (m_Polygon.IsEnclosing(posn))
                {
                    m_Result = text;
                    return false;
                }
            }

            return true;
        }
Beispiel #25
0
        /// <summary>
        /// Associates this polygon with the specified label
        /// </summary>
        /// <param name="label">The label to associate with this polygon (usually appearing
        /// somewhere inside the polygon).</param>
        internal void ClaimLabel(TextFeature label)
        {
            Debug.Assert(label!=null);

            // Refer the label to this polygon (even if this polygon doesn't end up pointing back)
            label.Container = this;

            /*
            if (m_Label!=null && !Object.ReferenceEquals(m_Label, label))
            {
                string msg = String.Format("Label {0} falls inside same polygon as label {1}",
                                                label.ToString(), m_Label.ToString());
                Trace.TraceWarning(msg);
            }
            */

            // Associate this polygon with the supplied label
            if (m_Labels==null)
                m_Labels = new List<TextFeature>(1);

            m_Labels.Add(label);
        }
Beispiel #26
0
 /// <summary>
 /// Creates a new <c>KeyTextGeometry</c> that isn't associated with a text feature. There is a chicken and egg
 /// problem here - an instance of KeyTextGeometry is expected to refer to a TextFeature, but the feature cannot
 /// be created until the geometry has been created. So after creating the KeyTextGeometry, you are expected to
 /// create the corresponding feature, then assign the feature to this geometry using the <see cref="Label"/>
 /// property.
 /// </summary>
 /// <param name="pos">Position of the text's reference point (always the top left corner of the string).</param>
 /// <param name="font">The text style (defines the type-face and the height of the text).</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>
 internal KeyTextGeometry(PointGeometry pos, IFont font, double height, double width, float rotation)
     : base(pos, font, height, width, rotation)
 {
     m_Feature = null;
 }