Esempio n. 1
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);
        }
Esempio n. 2
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;
        }