Esempio n. 1
0
        private void MainWindow_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            m_dragging = false;
            if (e.OriginalSource is Ellipse)
            {
                Plug p = find_visual_parent <Plug>(e.OriginalSource as DependencyObject);

                //first let check we have something selected
                if (m_selected != null)
                {
                    //is it a connection?
                    if (m_selected is Connection)
                    {
                        //if so cast it to connection
                        var conn = m_selected as Connection;
                        //if we  ha have the connection selected we make sure to
                        //set the right color
                        if (conn.IsSelected == true)
                        {
                            p.IsConnectionSelected = true;
                        }
                        else
                        {
                            p.IsSelected = true;
                        }

                        //create the connection
                        CustomNode node = find_visual_parent <CustomNode>(e.OriginalSource as DependencyObject);
                        var        x    = Canvas.GetLeft(node);
                        var        y    = Canvas.GetTop(node);

                        Ellipse ell    = e.OriginalSource as Ellipse;
                        var     radius = ell.Width / 2;

                        conn.EndPoint = new Point(x + p.X + radius, y + p.Y + radius);
                        conn.EndPlug  = p;
                        var srcNode  = find_visual_parent <CustomNode>(conn.StartPlug);
                        var destNode = find_visual_parent <CustomNode>(p);

                        conn.FinalizeConnection(view_model.m_fsm, srcNode.m_state,
                                                destNode.m_state);
                        //ConditionBinding cb = new ConditionBinding(conn.cond);
                        p.AddConnection(conn);
                        //conn.Conditions.Add(cb);
                        //conn.conn.add_conditions(cb.m_wrapCond);
                        conn = null;
                        clear_selection();
                        return;
                    }
                }
            }
            else
            {
                var view = (ItemsControl)this.FindName("view");

                var isNull          = m_selected != null;
                var isConnection    = m_selected is Connection;
                var sourceisnotconn = !(e.OriginalSource is Connection);
                //check if anything is selected
                if (m_selected != null
                    //that what is selected is a connection
                    && m_selected is Connection
                    //also that the original source is not a connecton otherwise
                    //if we lift the mouse when a connection is selected we delete it
                    && !(e.OriginalSource is Connection))
                {
                    var conn = m_selected as Connection;
                    if (conn.StartPlug != null)
                    {
                        conn.StartPlug.IsSelected = false;
                    }
                    if (conn.EndPlug != null)
                    {
                        conn.EndPlug.IsSelected = false;
                    }
                    // view.Children.Remove(conn);

                    view_model.Connections.Remove(conn);
                    conn       = null;
                    m_selected = null;
                    clear_selection();
                }
            }
        }
Esempio n. 2
0
        private void MainWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            m_dragging = true;
            var view = (ItemsControl)this.FindName("view");

            m_mouse_pos = e.GetPosition(view);
            var t = e.GetPosition(this);

            Console.WriteLine("mouse ");
            Console.WriteLine(m_mouse_pos.X);
            Console.WriteLine("win");
            Console.WriteLine(t.X);
            // Canvas foundCanvas = UIHelper.FindChild<Canvas>(Application.Current.MainWindow, "MarkerCanvas");

            if (e.OriginalSource is Rectangle)
            {
                CustomNode node = find_visual_parent <CustomNode>(e.OriginalSource as DependencyObject);
                clear_selection();
                node.IsSelected = true;
                m_selected      = node;
                return;
            }
            else if (e.OriginalSource is Ellipse)
            {
                Plug p = find_visual_parent <Plug>(e.OriginalSource as DependencyObject);
                clear_selection();

                //create the connection
                var        conn = new Connection();
                CustomNode node = find_visual_parent <CustomNode>(e.OriginalSource as DependencyObject);
                var        x    = Canvas.GetLeft(node);
                var        y    = Canvas.GetTop(node);

                //adding cross referencing
                p.AddConnection(conn);
                p.IsSelected   = true;
                conn.StartPlug = p;

                //FIX RADIUSSS
                Ellipse ell    = e.OriginalSource as Ellipse;
                var     radius = ell.Width / 2;
                var     finalX = x + p.X + radius;
                var     finalY = y + p.Y + radius;
                conn.StartPoint = new Point(x + p.X + radius, y + p.Y + radius);
                conn.EndPoint   = new Point(x + p.X + radius, y + p.Y + radius);
                view_model.Connections.Add(conn);
                m_selected = conn;
                return;
            }
            else if (e.OriginalSource is Connection)
            {
                clear_selection();
                Connection conn = e.OriginalSource as Connection;

                conn.IsSelected = true;
                m_selected      = conn;

                ConnectionViewer.DataContext = conn;
                return;
            }

            clear_selection();
        }