示例#1
0
        private void initButton_MouseMove(object sender, MouseEventArgs e)
        {
            Point mousePos = e.GetPosition(null);
            Vector diff = startPoint - mousePos;

            if (e.LeftButton == MouseButtonState.Pressed && !IsDragDrop)
            {
                if (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance
                    || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
                {
                    IsDragDrop = true;

                    Button btn = (Button)sender;

                    InitNodeControl node = new InitNodeControl() { CornerRadius = new CornerRadius(10) };
                    node.NodeName = "Инициализация";
                    node.Style = (Style)this.FindResource("NodeStyle");
                    node.MouseLeftButtonDown += node_MouseLeftButtonDown;
                    node.MouseLeftButtonUp += node_MouseLeftButtonUp;
                    node.MouseMove += node_MouseMove;
                    node.LostMouseCapture += node_LostMouseCapture;
                    node.SettingsButtonClick += initNode_SettingsButtonClick;

                    DataObject dragData = new DataObject("NodeFormat", node);
                    DragDrop.DoDragDrop(btn, dragData, DragDropEffects.Move);
                }
            }
        }
示例#2
0
        private void LoadExperimentGraph(XElement root, LoopControl loop = null)
        {
            if (loop == null)
                NewExperiment();
            else {
                loop.LoopBody = new ExperimentGraph();
                loop.Canvas.Children.Clear();
            }

            foreach (XElement node in root.Element("nodes").Elements("node"))
            {
                BaseNodeControl nodeControl;
                switch (node.Attribute("type").Value)
                {
                    case "init":
                        nodeControl = new InitNodeControl() { CornerRadius = new CornerRadius(10) };
                        (nodeControl as InitNodeControl).InitPath = node.Element("initpath").Value;
                        (nodeControl as NodeControl).NodeName = "Инициализация";
                        (nodeControl as NodeControl).SettingsButtonClick += initNode_SettingsButtonClick;
                        break;
                    case "runprocess":
                        nodeControl = new RunProcessNodeControl() { CornerRadius = new CornerRadius(10) };
                        (nodeControl as RunProcessNodeControl).ProcessName = node.Element("processname").Value;
                        (nodeControl as NodeControl).NodeName = "Запуск приложения";
                        (nodeControl as NodeControl).SettingsButtonClick += exportNode_SettingsButtonClick;
                        break;
                    case "algorithm":
                        nodeControl = new AlgorithmNodeControl();
                        (nodeControl as AlgorithmNodeControl).InitPath = node.Element("initpath").Value;
                        (nodeControl as AlgorithmNodeControl).AlgorithmType = HydrologyCore.AlgorithmTypes[node.Element("algorithmtype").Value];
                        (nodeControl as AlgorithmNodeControl).VarLoop = new Dictionary<string, LoopControl>();

                        var varNames = new Dictionary<string, LoopControl>();
                        LoopControl p = loop;
                        while (p != null)
                        {
                            varNames.Add(p.VarName, p);
                            p = p.PreviousLoop;
                        }

                        DataTable paramTable = new DataTable();
                        paramTable.Columns.Add("Name");
                        paramTable.Columns.Add("Value");
                        foreach (XElement param in node.Element("params").Elements("param"))
                        {
                            DataRow row = paramTable.NewRow();
                            row["Name"] = param.Attribute("name").Value;
                            row["Value"] = param.Attribute("value").Value;
                            paramTable.Rows.Add(row);

                            if (row["Value"].ToString()[0] == '{')
                            {
                                string varName = row["Value"].ToString();
                                varName = varName.Trim(' ', '{', '}');
                                if (varNames.Keys.Contains(varName))
                                {
                                    (nodeControl as AlgorithmNodeControl).VarLoop.Add(row["Name"].ToString(), varNames[varName]);
                                }
                            }
                        }
                        (nodeControl as AlgorithmNodeControl).ParamsTable = paramTable;
                        var attr = (nodeControl as AlgorithmNodeControl).AlgorithmType.GetCustomAttribute(typeof(NameAttribute)) as NameAttribute;
                        (nodeControl as NodeControl).NodeName = attr.Name;
                        (nodeControl as NodeControl).SettingsButtonClick += node_SettingsClicked;
                        break;
                    case "loopstart":
                        nodeControl = new StartLoopNodeControl() { Width = 30, Height = 30 };
                        break;
                    case "loop":
                        nodeControl = new LoopControl(this) { PreviousLoop = loop };
                        (nodeControl as LoopControl).VarName = node.Element("loopparams").Attribute("varname").Value;
                        (nodeControl as LoopControl).StartValue =
                            double.Parse(node.Element("loopparams").Attribute("start").Value, CultureInfo.InvariantCulture);
                        (nodeControl as LoopControl).EndValue =
                            double.Parse(node.Element("loopparams").Attribute("end").Value, CultureInfo.InvariantCulture);
                        (nodeControl as LoopControl).Step =
                            double.Parse(node.Element("loopparams").Attribute("step").Value, CultureInfo.InvariantCulture);
                        LoadExperimentGraph(node.Element("loopbody"), nodeControl as LoopControl);
                        break;
                    default:
                        nodeControl = new NodeControl();
                        break;
                }
                if (!(nodeControl is StartLoopNodeControl))
                    nodeControl.Style = (Style)this.FindResource("NodeStyle");
                nodeControl.MouseLeftButtonDown += node_MouseLeftButtonDown;
                nodeControl.MouseLeftButtonUp += node_MouseLeftButtonUp;
                nodeControl.MouseMove += node_MouseMove;
                nodeControl.LostMouseCapture += node_LostMouseCapture;

                Canvas.SetLeft(nodeControl, double.Parse(node.Attribute("x").Value, CultureInfo.InvariantCulture));
                Canvas.SetTop(nodeControl, double.Parse(node.Attribute("y").Value, CultureInfo.InvariantCulture));

                if (loop == null)
                {
                    Canvas.Children.Add(nodeControl);
                    experimentGraph.Nodes.Add(nodeControl);
                }
                else
                {
                    loop.Canvas.Children.Add(nodeControl);
                    loop.LoopBody.Nodes.Add(nodeControl);
                }
            }

            if (loop == null)
            {
                Canvas.UpdateLayout();
            }
            else
            {
                loop.Canvas.UpdateLayout();
            }

            foreach (XElement arrow in root.Element("arrows").Elements("arrow"))
            {
                Arrow arr;
                if (loop == null)
                {
                    arr = new Arrow(
                    experimentGraph.Nodes[int.Parse(arrow.Element("from").Attribute("id").Value)],
                    new Point(double.Parse(arrow.Element("from").Attribute("x").Value, CultureInfo.InvariantCulture),
                              double.Parse(arrow.Element("from").Attribute("y").Value, CultureInfo.InvariantCulture)),
                    experimentGraph.Nodes[int.Parse(arrow.Element("to").Attribute("id").Value)],
                    new Point(double.Parse(arrow.Element("to").Attribute("x").Value, CultureInfo.InvariantCulture),
                              double.Parse(arrow.Element("to").Attribute("y").Value, CultureInfo.InvariantCulture))
                    );

                    arr.MouseDown += Arrow_MouseDown;
                    arr.MouseMove += Arrow_MouseMove;
                    arr.MouseUp += Arrow_MouseUp;

                    Canvas.Children.Add(arr);
                    experimentGraph.Arrows.Add(arr);
                    Canvas.UpdateLayout();
                }
                else
                {
                    arr = new Arrow(
                    loop.LoopBody.Nodes[int.Parse(arrow.Element("from").Attribute("id").Value)],
                    new Point(double.Parse(arrow.Element("from").Attribute("x").Value, CultureInfo.InvariantCulture),
                              double.Parse(arrow.Element("from").Attribute("y").Value, CultureInfo.InvariantCulture)),
                    loop.LoopBody.Nodes[int.Parse(arrow.Element("to").Attribute("id").Value)],
                    new Point(double.Parse(arrow.Element("to").Attribute("x").Value, CultureInfo.InvariantCulture),
                              double.Parse(arrow.Element("to").Attribute("y").Value, CultureInfo.InvariantCulture))
                    );

                    arr.MouseDown += Arrow_MouseDown;
                    arr.MouseMove += loop.Arrow_MouseMove;
                    arr.MouseUp += loop.Arrow_MouseUp;

                    loop.Canvas.Children.Add(arr);
                    loop.LoopBody.Arrows.Add(arr);
                    loop.Canvas.UpdateLayout();
                }

                arr.Draw();
            }
        }
示例#3
0
 public void PrepareInitNode(InitNodeControl node, Experiment experiment)
 {
     experiment.StartFrom(node.InitPath);
 }