Example #1
0
        void AddNode(Type algType, string initPath, DataTable paramTable, double x = 0, double y = 0, LoopControl loop = null, Dictionary<string, LoopControl> varLoop = null)
        {
            var attr = algType.GetCustomAttribute(typeof(NameAttribute)) as NameAttribute;
            NodeControl node = new AlgorithmNodeControl()
            {
                NodeName = attr.Name,
                AlgorithmType = algType,
                InitPath = initPath,
                ParamsTable = paramTable,
                VarLoop = varLoop
            };
            node.Style = (Style)this.FindResource("NodeStyle");
            node.SettingsButtonClick += node_SettingsClicked;
            node.MouseLeftButtonDown += node_MouseLeftButtonDown;
            node.MouseLeftButtonUp += node_MouseLeftButtonUp;
            node.MouseMove += node_MouseMove;
            node.LostMouseCapture += node_LostMouseCapture;

            Canvas.Children.Add(node);
            experimentGraph.Nodes.Add(node);

            Canvas.SetLeft(node, x);
            Canvas.SetTop(node, y);
        }
Example #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();
            }
        }
Example #3
0
        public void PrepareAlgorithmNode(AlgorithmNodeControl node, Experiment experiment)
        {
            DataTable algParams = node.ParamsTable.Copy();

            foreach (DataRow row in algParams.Rows)
            {
                if (node.VarLoop.Keys.Contains(row["Name"].ToString()))
                    row["Value"] = node.VarLoop[row["Name"].ToString()].RunValue;
            }

            if (string.IsNullOrEmpty(node.InitPath))
            {
                experiment.Then(hydrologyCore.Algorithm(node.AlgorithmType.Name).SetParams(algParams));
            }
            else
            {
                if (Directory.Exists(node.InitPath))
                {
                    experiment.Then(hydrologyCore.Algorithm(node.AlgorithmType.Name).InitFromFolder(node.InitPath).SetParams(algParams));
                }
                else
                {
                    MessageBox.Show(string.Format("Путь {0}, указанный для алгоритма {1} не существует", node.InitPath, node.AlgorithmType.Name),
                        "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
        }