Esempio n. 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Console.WriteLine("Pressing");
            // var view = (Canvas)this.FindName("view");
            var n = new CustomNode();

            n.move(100, 100);
            n.NodeName = "Jumping";
            view_model.Rectangles.Add(n);
            view_model.m_fsm.add_state(n.m_state);
        }
Esempio n. 2
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. 3
0
        public void read_from_file(string path)
        {
            m_rectangles.Clear();
            m_connections.Clear();
            m_fsm.from_file(path);
            var count = m_fsm.get_state_count();


            var state_map = new Dictionary<string, CustomNode>();
            for (int i = 0; i < count; i++)
            {
                StateWrapper w = m_fsm.get_state_at_index(i);
                var n = new CustomNode(w);
                n.NodeName = w.get_name();
                m_rectangles.Add(n);
                state_map[n.NodeName] = n;
            }

            for (int i = 0; i < count; i++)
            {
                var node = Rectangles[i];
                var state = node.m_state;
                var conn_count = state.get_connection_count();
                Console.WriteLine(conn_count);
                for (int c = 0; c < conn_count; ++c)
                {

                    var conn = state.get_connection_at_index(c);
                    string endName = conn.get_destination_name();
                    CustomNode endNode = state_map[endName];
                    StateWrapper endState = endNode.m_state;
                    var connShape = new Connection();
                    connShape.conn = conn;
                    var outp = node.OutPlug;
                    var inp = endNode.InPlug;
                    outp.IsSelected = true;
                    inp.IsSelected = true;
                    //TODO FIX RADIUSSS
                    outp.AddConnection(connShape);
                    inp.AddConnection(connShape);
                    connShape.StartPlug = inp;
                    connShape.EndPlug = outp;
                    var r = 10;
                    connShape.EndPoint= new Point(outp.X+r, outp.Y+r);
                    connShape.StartPoint= new Point(inp.X+r, inp.Y+r);
                    Connections.Add(connShape);

                    int cond_count = conn.get_condition_count();
                    for (int cnd = 0; cnd < cond_count; cnd++)
                    {
                        var t = conn.get_condition_type_at_index(cnd);
                        int templ_type = conn.get_condition_template_type_at_index(cnd);
                        if (t == "TypedCondition")
                        {
                            TypedConditionBinding binding;
                            if (templ_type == 0)
                            {
                                var cond = conn.get_Typed_at_index<int>(cnd);
                                binding = new TypedConditionBinding(cond);
                            }
                            else if (templ_type == 1)
                            {
                                var cond = conn.get_Typed_at_index<float>(cnd);
                                binding = new TypedConditionBinding(cond);
                            }
                            else
                            {
                                var cond = conn.get_Typed_at_index<bool>(cnd);
                                binding = new TypedConditionBinding(cond);
                            }
                            connShape.Conditions.Add(binding);
                        }
                        else
                        {
                            DoubleConditionBinding binding;
                            if (templ_type == 0)
                            {
                                var cond = conn.get_Double_at_index<int>(cnd);
                                binding = new DoubleConditionBinding(cond);
                            }
                            else if (templ_type == 1)
                            {
                                var cond = conn.get_Typed_at_index<float>(cnd);
                                binding = new DoubleConditionBinding(cond);
                            }
                            else
                            {
                                var cond = conn.get_Typed_at_index<bool>(cnd);
                                binding = new DoubleConditionBinding(cond);
                            }
                            connShape.Conditions.Add(binding);
                        }
                    }
                }
            }
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        public void read_from_file(string path)
        {
            m_rectangles.Clear();
            m_connections.Clear();
            m_fsm.from_file(path);
            var count = m_fsm.get_state_count();


            var state_map = new Dictionary <string, CustomNode>();

            for (int i = 0; i < count; i++)
            {
                StateWrapper w = m_fsm.get_state_at_index(i);
                var          n = new CustomNode(w);
                n.NodeName = w.get_name();
                m_rectangles.Add(n);
                state_map[n.NodeName] = n;
            }

            for (int i = 0; i < count; i++)
            {
                var node       = Rectangles[i];
                var state      = node.m_state;
                var conn_count = state.get_connection_count();
                Console.WriteLine(conn_count);
                for (int c = 0; c < conn_count; ++c)
                {
                    var          conn      = state.get_connection_at_index(c);
                    string       endName   = conn.get_destination_name();
                    CustomNode   endNode   = state_map[endName];
                    StateWrapper endState  = endNode.m_state;
                    var          connShape = new Connection();
                    connShape.conn = conn;
                    var outp = node.OutPlug;
                    var inp  = endNode.InPlug;
                    outp.IsSelected = true;
                    inp.IsSelected  = true;
                    //TODO FIX RADIUSSS
                    outp.AddConnection(connShape);
                    inp.AddConnection(connShape);
                    connShape.StartPlug = inp;
                    connShape.EndPlug   = outp;
                    var r = 10;
                    connShape.EndPoint   = new Point(outp.X + r, outp.Y + r);
                    connShape.StartPoint = new Point(inp.X + r, inp.Y + r);
                    Connections.Add(connShape);

                    int cond_count = conn.get_condition_count();
                    for (int cnd = 0; cnd < cond_count; cnd++)
                    {
                        var t          = conn.get_condition_type_at_index(cnd);
                        int templ_type = conn.get_condition_template_type_at_index(cnd);
                        if (t == "TypedCondition")
                        {
                            TypedConditionBinding binding;
                            if (templ_type == 0)
                            {
                                var cond = conn.get_Typed_at_index <int>(cnd);
                                binding = new TypedConditionBinding(cond);
                            }
                            else if (templ_type == 1)
                            {
                                var cond = conn.get_Typed_at_index <float>(cnd);
                                binding = new TypedConditionBinding(cond);
                            }
                            else
                            {
                                var cond = conn.get_Typed_at_index <bool>(cnd);
                                binding = new TypedConditionBinding(cond);
                            }
                            connShape.Conditions.Add(binding);
                        }
                        else
                        {
                            DoubleConditionBinding binding;
                            if (templ_type == 0)
                            {
                                var cond = conn.get_Double_at_index <int>(cnd);
                                binding = new DoubleConditionBinding(cond);
                            }
                            else if (templ_type == 1)
                            {
                                var cond = conn.get_Typed_at_index <float>(cnd);
                                binding = new DoubleConditionBinding(cond);
                            }
                            else
                            {
                                var cond = conn.get_Typed_at_index <bool>(cnd);
                                binding = new DoubleConditionBinding(cond);
                            }
                            connShape.Conditions.Add(binding);
                        }
                    }
                }
            }
        }