Exemple #1
0
        public void MouseMove(object sender, MouseEventArgs e)
        {
            // If the canvas reference is null then we ignore mouse events
            if (null == m_canvas)
            {
                return;
            }

            Point mousePt = e.GetPosition(m_canvas);

            // Clear the border if we'd previously set one
            if (null != m_puWithAlteredBorderColor)
            {
                m_puWithAlteredBorderColor.SetBorderColor(ProcessUnitBorderColor.NoBorder);
                m_puWithAlteredBorderColor = null;
            }

            // See if we're hovering over a process unit (will be null if we're not)
            m_puWithAlteredBorderColor =
                m_canvas.GetChildAt(e.GetPosition(m_canvas), m_sourcePlacementIcon) as ProcessUnitControl;

            // Set the location of icon so that it's right under the mouse pointer
            m_sourcePlacementIcon.SetValue(Canvas.LeftProperty, mousePt.X - m_sourcePlacementIcon.ActualWidth / 2.0);
            m_sourcePlacementIcon.SetValue(Canvas.TopProperty, mousePt.Y - m_sourcePlacementIcon.ActualHeight / 2.0);

            // If we're over a process unit then we need to set its border
            if (null != m_puWithAlteredBorderColor)
            {
                m_puWithAlteredBorderColor.SetBorderColor(
                    m_puWithAlteredBorderColor.ProcessUnit.CanAcceptOutgoingStream(m_stream) ?
                    ProcessUnitBorderColor.AcceptingStreams : ProcessUnitBorderColor.NotAcceptingStreams);
            }
        }
        public void MouseMove(object sender, MouseEventArgs e)
        {
            if (null == m_placementIcon)
            {
                return;
            }

            // Set the location of the icon to follow the mouse
            Point p = e.GetPosition(m_canvas);

            m_placementIcon.SetValue(Canvas.LeftProperty, p.X - m_placementIcon.Width / 2.0);
            m_placementIcon.SetValue(Canvas.TopProperty, p.Y - m_placementIcon.Height / 2.0);

            // If we've highlighted a process unit or stream then clear the highlight
            UnhighlightHover();

            // See if we're hovering over a process unit (will be null if we're not)
            m_highlightedHover = m_canvas.GetChildAtIncludeStreams(p, m_placementIcon);
            ProcessUnitControl pu = m_highlightedHover as ProcessUnitControl;

            ChemProV.PFD.Streams.StreamControl stream =
                m_highlightedHover as ChemProV.PFD.Streams.StreamControl;

            // Set the border if we are hovering over a process unit to indicate that we can attach
            // an anchored comment to it
            if (null != pu)
            {
                pu.SetBorderColor(ProcessUnitBorderColor.AcceptingStreams);
            }
            else if (null != stream)
            {
                stream.SetLineBrush(new SolidColorBrush(Colors.Green));
            }
        }
        /// <summary>
        /// The member variable m_highlightedHover can be a reference to a process unit with a highlighted
        /// border or a stream with a specially colored stem line. This method removes either of these
        /// highlights and sets the member variable back to null.
        /// </summary>
        private void UnhighlightHover()
        {
            if (null == m_highlightedHover)
            {
                return;
            }

            ProcessUnitControl gpu = m_highlightedHover as ProcessUnitControl;

            if (null != gpu)
            {
                gpu.SetBorderColor(ProcessUnitBorderColor.NoBorder);
            }
            else
            {
                PFD.Streams.StreamControl s = m_highlightedHover as PFD.Streams.StreamControl;
                if (null != s)
                {
                    s.Selected = true;
                    s.Selected = false;
                }
            }

            m_highlightedHover = null;
        }
Exemple #4
0
        public void MouseMove(object sender, MouseEventArgs e)
        {
            if (!m_mouseDown)
            {
                return;
            }

            // We can't do anything if the canvas is read-only
            if (m_canvas.IsReadOnly)
            {
                return;
            }

            Point pt = e.GetPosition(m_canvas);

            MathCore.Vector diff = (new MathCore.Vector(pt.X, pt.Y)) - m_mouseDownPt;
            diff = (m_originalLocation + diff);
            pt   = new Point(diff.X, diff.Y);

            // If we changed a border color, change it back and null the reference
            if (null != m_puThatGotBorderChange)
            {
                m_puThatGotBorderChange.SetBorderColor(ProcessUnitBorderColor.Selected);
                m_puThatGotBorderChange = null;
            }

            // Various objects have slightly different moving rules so we need to check the type
            ProcessUnitControl lpu = m_object as ProcessUnitControl;

            if (null != lpu)
            {
                // First off, move the process unit
                lpu.ProcessUnit.Location = new MathCore.Vector(pt.X, pt.Y);

                // See if we're dragging it over anything else
                object hoveringOver = m_canvas.GetChildAt(pt, lpu);

                // See if it's a stream connection endpoint
                DraggableStreamEndpoint endpoint = hoveringOver as DraggableStreamEndpoint;
                if (null != endpoint)
                {
                    m_puThatGotBorderChange = lpu;

                    // Set the process unit's border color
                    m_puThatGotBorderChange.SetBorderColor(endpoint.CanConnectTo(lpu) ?
                                                           ProcessUnitBorderColor.AcceptingStreams : ProcessUnitBorderColor.NotAcceptingStreams);
                }
            }
            else
            {
                // Other items just get their locations set
                m_object.Location = pt;
            }

            // NOTE: Stream-oriented moving stuff is handled elsewhere. See the MovingStreamEndpoint class
        }
        public void MouseMove(object sender, MouseEventArgs e)
        {
            // If the stream is null then we don't process events
            if (null == m_stream)
            {
                return;
            }

            // Get the mouse position relative to the canvas
            Point p = e.GetPosition(m_canvas);

            // Clear the border color if we had set one
            if (null != m_changedBorderColor)
            {
                m_changedBorderColor.SetBorderColor(ProcessUnitBorderColor.NoBorder);
                m_changedBorderColor = null;
            }

            // Find out if we're hovering over a process unit
            ProcessUnitControl lpu = m_canvas.GetChildAt(p, m_dragIcon) as ProcessUnitControl;

            if (null == lpu)
            {
                // All we need to do on a mouse move is make the changes in the m_stream data structure. The
                // application is designed such that UI controls monitor changes in these data structures and
                // update themselves appropriately.
                if (m_dragIcon.IsSource)
                {
                    // If the source is not null, we need to disconnect
                    if (null != m_stream.Source)
                    {
                        m_stream.Source.DetachOutgoingStream(m_stream);
                        m_stream.Source = null;
                    }
                    m_stream.SourceLocation = new Vector(p.X, p.Y);
                }
                else
                {
                    // If the destination is not null, we need to disconnect
                    if (null != m_stream.Destination)
                    {
                        m_stream.Destination.DetachIncomingStream(m_stream);
                        m_stream.Destination = null;
                    }
                    m_stream.DestinationLocation = new Vector(p.X, p.Y);
                }
            }
            else
            {
                // We are hovering over a process unit
                m_changedBorderColor = lpu;
                if (m_dragIcon.IsSource)
                {
                    if (object.ReferenceEquals(m_stream.Source, lpu.ProcessUnit))
                    {
                        // This means that the process unit we're dragging the source icon over is
                        // already set as the source, so we don't have to do anything.
                    }
                    else if (lpu.ProcessUnit.CanAcceptOutgoingStream(m_stream))
                    {
                        // If we had a non-null source then disconnect
                        if (null != m_stream.Source)
                        {
                            m_stream.Source.DetachOutgoingStream(m_stream);
                        }

                        m_stream.Source = lpu.ProcessUnit;
                        lpu.ProcessUnit.AttachOutgoingStream(m_stream);

                        // Set the border color to indicate that we can make this connection
                        lpu.SetBorderColor(ProcessUnitBorderColor.AcceptingStreams);
                    }
                    else
                    {
                        // If we had a non-null source then disconnect
                        if (null != m_stream.Source)
                        {
                            m_stream.Source.DetachOutgoingStream(m_stream);
                            m_stream.Source = null;
                        }

                        // This means that the connection cannot be made
                        lpu.SetBorderColor(ProcessUnitBorderColor.NotAcceptingStreams);
                        m_stream.SourceLocation = new Vector(p.X, p.Y);
                    }
                }
                else
                {
                    if (object.ReferenceEquals(m_stream.Destination, lpu.ProcessUnit))
                    {
                        // This means that the process unit we're dragging the destination icon over
                        // is already set as the destination, so we don't have to do anything.
                    }
                    else if (lpu.ProcessUnit.CanAcceptIncomingStream(m_stream))
                    {
                        // If we had a non-null destination then disconnect
                        if (null != m_stream.Destination)
                        {
                            m_stream.Destination.DetachIncomingStream(m_stream);
                        }

                        m_stream.Destination = lpu.ProcessUnit;
                        lpu.ProcessUnit.AttachIncomingStream(m_stream);

                        // Set the border color to indicate that we can make this connection
                        lpu.SetBorderColor(ProcessUnitBorderColor.AcceptingStreams);
                    }
                    else
                    {
                        // If we had a non-null destination then disconnect
                        if (null != m_stream.Destination)
                        {
                            m_stream.Destination.DetachIncomingStream(m_stream);
                            m_stream.Destination = null;
                        }

                        // This means that the connection cannot be made
                        lpu.SetBorderColor(ProcessUnitBorderColor.NotAcceptingStreams);
                        m_stream.DestinationLocation = new Vector(p.X, p.Y);
                    }
                }
            }
        }