Пример #1
0
        internal override void MouseMove(IPosition p)
        {
            PointFeature      oldCurrentPoint = m_CurrentPoint;
            CadastralMapModel map             = CadastralMapModel.Current;
            EditingController ec   = EditingController.Current;
            ILength           size = new Length(ec.Project.Settings.PointHeight * 0.5);

            m_CurrentPoint = (map.QueryClosest(p, size, SpatialType.Point) as PointFeature);

            if (m_Start == null)
            {
                // If the mouse is over a different point, ensure the old point is erased
                if (oldCurrentPoint != null && !Object.ReferenceEquals(oldCurrentPoint, m_CurrentPoint))
                {
                    ErasePainting();
                }

                return;
            }

            if (m_CurrentPoint == null)
            {
                m_End = PointGeometry.Create(p);
            }
            else
            {
                m_End = m_CurrentPoint;
            }

            if (m_End.IsCoincident(m_Start))
            {
                m_End = null;
                return;
            }

            ErasePainting();
        }
Пример #2
0
        private ISpatialObject SelectObject(ISpatialDisplay display, IPosition p, SpatialType spatialType)
        {
            ProjectSettings   ps         = m_Project.Settings;
            CadastralMapModel cmm        = this.CadastralMapModel;
            ISpatialSelection currentSel = this.SpatialSelection;
            ISpatialObject    oldItem    = currentSel.Item;
            ISpatialObject    newItem;

            // Try to find a point feature if points are drawn.
            if ((spatialType & SpatialType.Point) != 0 && display.MapScale <= ps.ShowPointScale)
            {
                ILength size = new Length(ps.PointHeight * 0.5);
                newItem = cmm.QueryClosest(p, size, SpatialType.Point);
                if (newItem != null)
                {
                    return(newItem);
                }
            }

            // If we are adding a line, don't bother trying to select
            // lines or polygons or text.

            /*
             * if (m_Op==ID_LINE_NEW || m_Op==ID_LINE_CURVE)
             *  return 0;
             */

            ILength tol = new Length(0.001 * display.MapScale);

            // Try to find a line, using a tolerance of 1mm at the draw scale.
            if ((spatialType & SpatialType.Line) != 0)
            {
                // If we previously selected something, see if the search point
                // lies within tolerance. If so, just return with what we've already got
                // ...just make the query (the issue here has to do with special highlighting
                // for topological sections -- if you point at another section of a line, the
                // highlighting doesn't move).

                // if (oldItem!=null && oldItem.SpatialType==SpatialType.Line)
                // {
                //     ILength dist = oldItem.Distance(p);
                //     if (dist.Meters < tol.Meters)
                //         return;
                // }

                newItem = cmm.QueryClosest(p, tol, SpatialType.Line);
                if (newItem != null)
                {
                    return(newItem);
                }
            }

            // Try for a text string if text is drawn.
            // The old software handles text by checking that the point is inside
            // the outline, not sure whether the new index provides acceptable alternative.
            if ((spatialType & SpatialType.Text) != 0 && display.MapScale <= ps.ShowLabelScale)
            {
                newItem = cmm.QueryClosest(p, tol, SpatialType.Text);
                if (newItem != null)
                {
                    return(newItem);
                }
            }

            // Just return if a command dialog is up,
            // since selecting a polygon is distracting at that stage
            // (really, this applies to things like intersect commands).
            // There MIGHT be cases at some later date where we really
            // do want to select pols...
            // For updates, allow polygon selection

            if (IsCommandRunning && !(m_Command is UpdateUI))
            {
                return(null);
            }

            if ((spatialType & SpatialType.Polygon) != 0)
            {
                // If we currently have a selected polygon, see if we're still inside it.

                /*
                 * if (oldItem is Polygon)
                 * {
                 *  Polygon oldPol = (oldItem is Polygon);
                 *  if (oldPol.IsEnclosing(p))
                 *
                 * }
                 */

                IPointGeometry pg    = PointGeometry.Create(p);
                ISpatialIndex  index = cmm.Index;
                Polygon        pol   = new FindPointContainerQuery(index, pg).Result;
                if (pol != null)
                {
                    return(pol);
                }
            }

            return(null);
        }
Пример #3
0
        private void okButton_Click(object sender, EventArgs e)
        {
            // Get the northing & easting.
            double y;

            if (!Double.TryParse(northingTextBox.Text, out y))
            {
                MessageBox.Show("Bad northing");
                northingTextBox.Focus();
                return;
            }

            double x;

            if (!Double.TryParse(eastingTextBox.Text, out x))
            {
                MessageBox.Show("Bad easting");
                eastingTextBox.Focus();
                return;
            }

            if (Math.Abs(x) < Double.Epsilon || Math.Abs(y) < Double.Epsilon)
            {
                MessageBox.Show("Position has not been specified.");
                return;
            }

            // See if there is an elevation (get 0.0 if not).
            double z = 0.0;

            if (elevationTextBox.Text.Length > 0)
            {
                if (!Double.TryParse(elevationTextBox.Text, out z))
                {
                    MessageBox.Show("Bad elevation");
                    elevationTextBox.Focus();
                    return;
                }
            }

            m_Position  = new Position(x, y);
            m_Elevation = z;

            // Check whether the position is on screen. If not, issue a warning
            // message, and let the user cancel if desired.
            ISpatialDisplay display = EditingController.Current.ActiveDisplay;
            IWindow         extent  = display.Extent;

            if (extent == null || !extent.IsOverlap(m_Position))
            {
                if (MessageBox.Show("Specified position does not overlap current draw window. Continue?",
                                    "Off screen", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }

            // Are we doing an update?
            PointFeature pupt = this.UpdatePoint;

            // Confirm that there is no selectable point already at the specified position. Allow
            // a tolerance of 1cm on the ground. Only check in 2D.
            // The seatch should be restricted to those points that are currently visible.

            CadastralMapModel map   = CadastralMapModel.Current;
            ILength           tol   = new Length(0.01);
            PointFeature      close = (PointFeature)map.QueryClosest(m_Position, tol, SpatialType.Point);

            if (close != null)
            {
                // Get the ground distance between the existing point & the new one.
                double dist = Geom.Distance(m_Position, close);

                // Confirm if the points are coincident. Unless we're doing an update,
                // and it's the one we're doing.

                if (pupt == null || !Object.ReferenceEquals(close, pupt))
                {
                    if (dist < Constants.TINY)
                    {
                        string msg = String.Format("Specified position coincides with existing point {0}. Continue?",
                                                   close.FormattedKey);
                        if (MessageBox.Show(msg, "Coincident point", MessageBoxButtons.YesNo) == DialogResult.No)
                        {
                            return;
                        }
                    }
                    else
                    {
                        string msg = String.Format("Specified position is only {0:0.000} metres away from point {1}. Continue?",
                                                   dist, close.FormattedKey);

                        if (MessageBox.Show(msg, "Very near another point", MessageBoxButtons.YesNo) == DialogResult.No)
                        {
                            return;
                        }
                    }
                }
            }

            // If we're updating a 3D position, update ONLY the elevation
            // now. We must leave the planimetric change to NewPointUI,
            // since it is in charge of controlling rollforward.

            if (pupt != null)
            {
                // For the time being, we do not provide the ability to change
                // a 2D location into a 3D one. Would need to modify the location,
                // thereby changing its address (or possibly create a duplicate
                // location in XY, although that could cause problems elsewhere).


                if (m_Elevation > Constants.TINY && !(pupt is IEditPosition3D))
                {
                    MessageBox.Show("Cannot convert a 2D point into 3D");
                    return;
                }

                // The point MUST be associated with a creating operation (either
                // a eNewPoint or a GetControl operation).
                Operation creator = (Operation)pupt.Creator;
                if (creator == null)
                {
                    MessageBox.Show("Point cannot be updated because it has no associated edit.");
                    return;
                }

                if (!(creator.EditId == EditingActionId.NewPoint ||
                      creator.EditId == EditingActionId.GetControl))
                {
                    MessageBox.Show("Unexpected editing operation");
                    return;
                }

                // Define new elevation if we have a 3D location.
                if (m_Elevation > Constants.TINY)
                {
                    IEditPosition3D p3D = (pupt as IEditPosition3D);
                    if (p3D == null)
                    {
                        MessageBox.Show("Unable to assign elevation");
                    }
                    else
                    {
                        p3D.Z = m_Elevation;
                    }
                }
            }

            m_Cmd.DialFinish(this);
        }