Exemple #1
0
        /// <summary>
        /// Override does the same as <c>SpatialController.SetSelection</c>, and additionally
        /// tells the application's main window (the main window goes on to display a property
        /// grid for the current selection).
        /// </summary>
        public override bool SetSelection(ISpatialSelection newSel)
        {
            if (!base.SetSelection(newSel))
            {
                return(false);
            }

            if (m_Main != null)
            {
                Debug.Assert(newSel != null);
                ISpatialObject so = newSel.Item;
                if (so is GeometryWrapper)
                {
                    GeometryWrapper g = (GeometryWrapper)so;
                    object          o = (g == null ? null : g.UserData);
                    m_Main.SetSelection(o);
                }
                else
                {
                    m_Main.SetSelection(null);
                }
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Handles a mouse double click event by attempting to select a spatial object
        /// at the supplied position. If the resultant selection refers to just one object,
        /// it will be processed with <see cref="RunUpdate"/>.
        /// </summary>
        /// <param name="sender">The display where the mouse event originated</param>
        /// <param name="p">The position where the mouse click occurred</param>
        public override void MouseDoubleClick(ISpatialDisplay sender, IPosition p)
        {
            // Attempt to select something
            OnSelect(sender, p, false);

            // Update the selected item
            ISpatialSelection ss = SpatialSelection;

            RunUpdate(null, ss.Item);
        }
        /// <summary>
        /// Creates a <c>SpatialController</c> with a map model that's suitable
        /// for use at design time.
        /// </summary>
        public SpatialController()
        {
            s_Controller = this;

            m_Data      = new DesignTimeMapModel();
            m_Selection = new SpatialSelection();
            m_Displays  = new List <ISpatialDisplay>();

            // Initialize map model in case any of the prelim stuff needs it (the
            // running application needs to replace it with something more appropriate).
            SetMapModel(m_Data, null);
        }
        /// <summary>
        /// Creates a <c>SpatialController</c> with a map model that's suitable
        /// for use at design time.
        /// </summary>
        public SpatialController()
        {
            s_Controller = this;

            m_Data = new DesignTimeMapModel();
            m_Selection = new SpatialSelection();
            m_Displays = new List<ISpatialDisplay>();

            // Initialize map model in case any of the prelim stuff needs it (the
            // running application needs to replace it with something more appropriate).
            SetMapModel(m_Data, null);
        }
Exemple #5
0
        /// <summary>
        /// Checks whether this selection refers to the same spatial objects as
        /// another selection, and has the same reference position.
        /// </summary>
        /// <param name="that">The selection to compare with</param>
        /// <returns>True if the two selections refer to the same spatial objects (not
        /// necessarily in the same order)</returns>
        public bool Equals(ISpatialSelection that)
        {
            // The same spatial objects have to be involved
            if (!SpatialSelection.Equals(this, that))
                return false;

            // If both selections refer to the same divider (or null), they're the same
            Selection other = (that as Selection);
            if (other == null)
                return false;

            IDivider d1 = (this.m_Section == null ? null : this.m_Section.Divider);
            IDivider d2 = (other.m_Section == null ? null : other.m_Section.Divider);
            return Object.ReferenceEquals(d1, d2);
        }
Exemple #6
0
        /// <summary>
        /// Override does the same as <c>SpatialController.SetSelection</c>, and additionally
        /// tells the application's main window (the main window goes on to display a property
        /// grid for the current selection).
        /// </summary>
        public override bool SetSelection(ISpatialSelection newSel)
        {
            if (!base.SetSelection(newSel))
            {
                return(false);
            }

            if (m_Main != null)
            {
                Debug.Assert(newSel != null);
                ISpatialObject so = newSel.Item;
                m_Main.SetSelection(so);
            }

            return(true);
        }
Exemple #7
0
        /// <summary>
        /// Handles a change to the current selection
        /// </summary>
        /// <param name="newSelection">The new selection (may be null)</param>
        public void OnSelectionChanged(ISpatialSelection newSelection)
        {
            using (Graphics g = mapPanel.CreateGraphics())
            {
                m_SavedDisplay.Render(g);

                if (newSelection != null)
                {
                    m_SavedDisplay.Render(m_Display.Graphics);

                    // Highlight the new selection
                    IDrawStyle style = SpatialController.Current.HighlightStyle;
                    newSelection.Render(this, style);

                    m_Display.Render(g);
                }
            }
        }
        /// <summary>
        /// Remembers a new selection
        /// </summary>
        /// <param name="newSel">The new selection (specify null to clear any current selection)</param>
        /// <returns>True if selection changed. False if the selection matches the#
        /// current selection</returns>
        public virtual bool SetSelection(ISpatialSelection newSel)
        {
            ISpatialSelection ss = (newSel == null ? new SpatialSelection() : newSel);

            if (m_Selection.Equals(ss))
            {
                return(false);
            }

            m_Selection = newSel; //new SpatialSelection(ss.Items);

            foreach (ISpatialDisplay d in m_Displays)
            {
                d.OnSelectionChanged(m_Selection);
            }

            return(true);
        }
Exemple #9
0
        /// <summary>
        /// Runs a trim dangles command by creating the editing operation (using the current feature
        /// selection) & executing it. The controller is then told to clear the selection before
        /// completing the command.
        /// </summary>
        /// <returns>True if the command ran to completion. False if any exception arose (in that
        /// case, the controller would be told to abort the command).</returns>
        internal override bool Run()
        {
            // Grab the current selection & filter out stuff that can't be trimmed
            EditingController c  = Controller;
            ISpatialSelection ss = c.SpatialSelection;

            LineFeature[] lines = TrimLineOperation.PreCheck(ss.Items);
            if (lines.Length == 0)
            {
                StringBuilder sb = new StringBuilder(200);
                sb.Append("Nothing can be trimmed. Possible reasons:");
                sb.Append(System.Environment.NewLine);
                sb.Append(System.Environment.NewLine);
                sb.Append("1. Lines have to be dangling.");
                sb.Append(System.Environment.NewLine);
                sb.Append("2. Only lines that are polygon boundaries can be trimmed.");
                sb.Append(System.Environment.NewLine);
                sb.Append("3. There has to be something left after trimming a line.");

                MessageBox.Show(sb.ToString());
                c.AbortCommand(this);
                return(false);
            }

            TrimLineOperation op = null;

            try
            {
                op = new TrimLineOperation();
                op.Execute(lines);

                c.ClearSelection();
                c.FinishCommand(this);
                return(true);
            }

            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace, e.Message);
                c.AbortCommand(this);
                return(false);
            }
        }
Exemple #10
0
        /// <summary>
        /// Checks whether two selections refer to the same objects
        /// </summary>
        /// <param name="a">The 1st selection</param>
        /// <param name="b">The 2nd selection</param>
        /// <returns>True if both selections are not null, contain the same number
        /// of elements, and refer to the same spatial objects (the same instances)</returns>
        public static bool Equals(ISpatialSelection a, ISpatialSelection b)
        {
            if (a == null || b == null)
            {
                return(false);
            }

            if (Object.ReferenceEquals(a, b))
            {
                return(true);
            }

            if (a.Count != b.Count)
            {
                return(false);
            }

            foreach (ISpatialObject sob in b.Items)
            {
                bool found = false;

                foreach (ISpatialObject soa in a.Items)
                {
                    if (Object.ReferenceEquals(soa, sob))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Checks whether two selections refer to the same objects
        /// </summary>
        /// <param name="a">The 1st selection</param>
        /// <param name="b">The 2nd selection</param>
        /// <returns>True if both selections are not null, contain the same number
        /// of elements, and refer to the same spatial objects (the same instances)</returns>
        public static bool Equals(ISpatialSelection a, ISpatialSelection b)
        {
            if (a==null || b==null)
                return false;

            if (Object.ReferenceEquals(a, b))
                return true;

            if (a.Count != b.Count)
                return false;

            foreach (ISpatialObject sob in b.Items)
            {
                bool found = false;

                foreach (ISpatialObject soa in a.Items)
                {
                    if (Object.ReferenceEquals(soa, sob))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                    return false;
            }

            return true;
        }
        /// <summary>
        /// Remembers a new selection
        /// </summary>
        /// <param name="newSel">The new selection (specify null to clear any current selection)</param>
        /// <returns>True if selection changed. False if the selection matches the#
        /// current selection</returns>
        public virtual bool SetSelection(ISpatialSelection newSel)
        {
            ISpatialSelection ss = (newSel==null ? new SpatialSelection() : newSel);
            if (m_Selection.Equals(ss))
                return false;

            m_Selection = newSel; //new SpatialSelection(ss.Items);

            foreach (ISpatialDisplay d in m_Displays)
                d.OnSelectionChanged(m_Selection);

            return true;
        }
 public virtual void Close()
 {
     m_Data = null;
     m_Selection = new SpatialSelection();
 }
 public virtual void Close()
 {
     m_Data      = null;
     m_Selection = new SpatialSelection();
 }
Exemple #15
0
 /// <summary>
 /// Checks whether this selection refers to the same spatial objects as
 /// another selection.
 /// </summary>
 /// <param name="that">The selection to compare with</param>
 /// <returns>True if the two selections refer to the same spatial objects (not
 /// necessarily in the same order)</returns>
 public bool Equals(ISpatialSelection that)
 {
     return(Equals(this, that));
 }
Exemple #16
0
 /// <summary>
 /// Creates a context menu that contains all display tools
 /// </summary>
 /// <param name="s">The current spatial selection (not used)</param>
 /// <returns>A context menu corresponding to all display tools</returns>
 internal ContextMenuStrip CreateContextMenu(ISpatialSelection s)
 {
     return(contextMenu);
 }
Exemple #17
0
        public override bool SetSelection(ISpatialSelection newSel)
        {
            ISpatialSelection ss = (newSel == null ? new Selection() : newSel);
            bool isChanged       = base.SetSelection(ss);

            if (!isChanged)
            {
                return(false);
            }

            ISpatialObject item = ss.Item;

            if (m_Main != null)
            {
                m_Main.SetSelection(item);
            }

            // If a single item has been selected
            if (item != null)
            {
                if (item is DividerObject)
                {
                    item = (item as DividerObject).Divider.Line;
                }

                if (item is PointFeature)
                {
                    if (ArePointsDrawn)
                    {
                        PointFeature selPoint = (item as PointFeature);

                        if (m_Inverse != null)
                        {
                            m_Inverse.OnSelectPoint(selPoint);
                        }

                        if (m_Command != null)
                        {
                            m_Command.OnSelectPoint(selPoint);
                        }
                    }
                }
                else if (item is LineFeature)
                {
                    if (m_Command != null)
                    {
                        LineFeature selLine = (item as LineFeature);
                        m_Command.OnSelectLine(selLine);
                    }
                }

                // 20100709 -- Not sure about this. If the user wants to point at the
                // same point twice in succession, the fact that the point is still
                // selected means the 2nd pointing won't get passed down (we tested
                // for a change above).

                if (m_Command != null)
                {
                    // 20101005 -- Allow highlighting of polygons, since their selection
                    // should not interfere with command dialogs (and in things like the
                    // update UI, it can be useful to confirm that topology is ok).

                    if (!(item is Polygon))
                    {
                        ClearSelection();
                    }
                }
            }

            m_HasSelectionChanged = true;
            return(true);
        }
Exemple #18
0
        /// <summary>
        /// Handles a change to the current selection
        /// </summary>
        /// <param name="newSelection">The new selection (may be null)</param>
        public void OnSelectionChanged(ISpatialSelection newSelection)
        {
            using (Graphics g = mapPanel.CreateGraphics())
            {
                m_SavedDisplay.Render(g);

                if (newSelection!=null)
                {
                    m_SavedDisplay.Render(m_Display.Graphics);

                    // Highlight the new selection
                    IDrawStyle style = SpatialController.Current.HighlightStyle;
                    newSelection.Render(this, style);

                    m_Display.Render(g);
                }
            }
        }
Exemple #19
0
        internal ContextMenuStrip CreateContextMenu(ISpatialSelection s)
        {
            if (s==null)
                throw new ArgumentNullException();
            /*
            void CeView::OnRButtonUp(UINT nFlags, CPoint point)
            {
            // Ensure any limit selection has been included.
            m_Sel.UseLimit();

            // If we were panning, cancel it now (cursor gets screwed up
            // if you don't).
            if ( m_DoPan ) OnViewPan();

            // If we have an active command, and that command can process
            // the right click, just leave it at that (the command thinks
            // it's actually OnRButtonDown, because I originally thought
            // this function was reacting the the initial event!).

            // Commands always expect logical coordinates.

            if ( m_pCommand ) {
            CClientDC dc(this);
            OnPrepareDC(&dc);
            CPoint lpt(point);
            dc.DPtoLP(&lpt);
            if ( m_pCommand->RButtonDown(lpt) ) return;
            }

            //	Create appropriate cursor menu
            CMenu menu;
            menu.LoadMenu(IDR_CURSOR_MENU);
            ClientToScreen(&point);

            if ( m_Op == ID_LINE_NEW ) {

            menu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,
                            point.x,point.y,this);
            return;
            }
            else if ( m_Op == ID_LINE_CURVE ) {

            if ( m_IsShortArc )
            menu.CheckMenuRadioItem(ID_SHORT_ARC,ID_LONG_ARC,
                                        ID_SHORT_ARC, MF_BYCOMMAND);
            else
            menu.CheckMenuRadioItem(ID_SHORT_ARC,ID_LONG_ARC,
                                        ID_LONG_ARC, MF_BYCOMMAND);

            menu.GetSubMenu(2)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,
                            point.x,point.y,this);

            return;
            }
             */

            // Handle single-item selections...

            if (s.Item!=null)
            {
                SpatialType t = s.Item.SpatialType;

                if (t == SpatialType.Point)
                    return pointContextMenu;

                if (t == SpatialType.Line)
                {
                    LineFeature line = (s.Item as LineFeature);
                    if (line == null && s.Item is DividerObject)
                        line = (s.Item as DividerObject).Divider.Line;

                    if (line != null)
                        ctxLinePolygonBoundary.Checked = line.HasTopology;

                    return lineContextMenu;
                }

                if (t == SpatialType.Text)
                    return textContextMenu;
            }

            if (s.Count>1)
                return multiSelectContextMenu;

            // Show the default menu, enabling the "Subdivide Polygon" item if a single polygon
            // is currently selected
            ctxLineSubdividePolygon.Enabled = (s.Item!=null && s.Item.SpatialType==SpatialType.Polygon);
            return noSelectionContextMenu;
        }
 /// <summary>
 /// Checks whether this selection refers to the same spatial objects as
 /// another selection.
 /// </summary>
 /// <param name="that">The selection to compare with</param>
 /// <returns>True if the two selections refer to the same spatial objects (not
 /// necessarily in the same order)</returns>
 public bool Equals(ISpatialSelection that)
 {
     return Equals(this, that);
 }
        public override bool SetSelection(ISpatialSelection newSel)
        {
            ISpatialSelection ss = (newSel==null ? new Selection() : newSel);
            bool isChanged = base.SetSelection(ss);
            if (!isChanged)
                return false;

            ISpatialObject item = ss.Item;
            if (m_Main!=null)
                m_Main.SetSelection(item);

            // If a single item has been selected
            if (item!=null)
            {
                if (item is DividerObject)
                    item = (item as DividerObject).Divider.Line;

                if (item is PointFeature)
                {
                    if (ArePointsDrawn)
                    {
                        PointFeature selPoint = (item as PointFeature);

                        if (m_Inverse!=null)
                            m_Inverse.OnSelectPoint(selPoint);

                        if (m_Command!=null)
                            m_Command.OnSelectPoint(selPoint);
                    }
                }
                else if (item is LineFeature)
                {
                    if (m_Command!=null)
                    {
                        LineFeature selLine = (item as LineFeature);
                        m_Command.OnSelectLine(selLine);
                    }
                }

                // 20100709 -- Not sure about this. If the user wants to point at the
                // same point twice in succession, the fact that the point is still
                // selected means the 2nd pointing won't get passed down (we tested
                // for a change above).

                if (m_Command != null)
                {
                    // 20101005 -- Allow highlighting of polygons, since their selection
                    // should not interfere with command dialogs (and in things like the
                    // update UI, it can be useful to confirm that topology is ok).

                    if (!(item is Polygon))
                        ClearSelection();
                }
            }

            m_HasSelectionChanged = true;
            return true;
        }
Exemple #22
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);
        }
Exemple #23
0
 /// <summary>
 /// Creates a context menu that contains all display tools
 /// </summary>
 /// <param name="s">The current spatial selection (not used)</param>
 /// <returns>A context menu corresponding to all display tools</returns>
 internal ContextMenuStrip CreateContextMenu(ISpatialSelection s)
 {
     return contextMenu;
 }
        /// <summary>
        /// Override does the same as <c>SpatialController.SetSelection</c>, and additionally
        /// tells the application's main window (the main window goes on to display a property
        /// grid for the current selection).
        /// </summary>
        public override bool SetSelection(ISpatialSelection newSel)
        {
            if (!base.SetSelection(newSel))
                return false;

            if (m_Main!=null)
            {
                Debug.Assert(newSel!=null);
                ISpatialObject so = newSel.Item;
                if (so is GeometryWrapper)
                {
                    GeometryWrapper g = (GeometryWrapper)so;
                    object o = (g==null ? null : g.UserData);
                    m_Main.SetSelection(o);
                }
                else
                    m_Main.SetSelection(null);
            }

            return true;
        }
Exemple #25
0
        /// <summary>
        /// Draws from the map model and refreshes the display
        /// </summary>
        /// <param name="addToHistory">Should the map panel extent be added to the view history?</param>
        internal void Draw(bool addToHistory)
        {
            Rectangle rect = new Rectangle(0, 0, mapPanel.Width, mapPanel.Height);
            Brush     b    = new SolidBrush(mapPanel.BackColor);

            //m_Display.Graphics.FillRectangle(Brushes.AntiqueWhite, rect);
            m_Display.Graphics.FillRectangle(b, rect);

            ISpatialController controller = SpatialController.Current;
            ISpatialModel      mapModel   = controller.MapModel;

            if (mapModel == null)
            {
                return;
            }

            SetScrollBars();
            //Rectangle rect = new Rectangle(0, 0, mapPanel.Width, mapPanel.Height);
            //m_Display.Graphics.FillRectangle(Brushes.White, rect);

            // TEST: Try drawing an image (in Selkirk)
            try
            {
                IWindow w     = this.Extent;
                IWindow testw = new Window(651000.0, 5555000.0, 652000.0, 5556000.0);
                if (w.IsOverlap(testw))
                {
                    float     fx  = EastingToDisplay(651000.0);
                    float     fy  = NorthingToDisplay(5556000.0);
                    float     fsz = LengthToDisplay(1000.0);
                    Rectangle r   = new Rectangle((int)fx, (int)fy, (int)fsz, (int)fsz);
                    Image     i   = Bitmap.FromFile(@"C:\Users\sstanton\Data\6515555.tif");
                    m_Display.Graphics.DrawImage(i, r);
                }
            }

            catch { }
            // end test

            mapModel.Render(this, controller.DrawStyle);

            // Paint the map panel
            using (Graphics g = mapPanel.CreateGraphics())
            {
                m_Display.Render(g);

                // Save the display without any highlighting
                m_Display.Render(m_SavedDisplay.Graphics);
                //CopyMapPanelToSavedDisplay();

                // Any selection needs to be drawn too, but after the above
                ISpatialSelection ss = controller.SpatialSelection;
                if (ss.Count > 0)
                {
                    IDrawStyle style = controller.HighlightStyle;
                    foreach (ISpatialObject item in ss.Items)
                    {
                        item.Render(this, style);
                    }

                    m_Display.Render(g);
                }
            }

            if (addToHistory)
            {
                AddExtent();
            }
        }