Beispiel #1
0
        private void loopButton_PreviewMouseMove(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;

                    LoopControl node = new LoopControl(this);
                    node.MouseLeftButtonDown += node_MouseLeftButtonDown;
                    node.MouseLeftButtonUp += node_MouseLeftButtonUp;
                    node.MouseMove += node_MouseMove;
                    node.LostMouseCapture += node_LostMouseCapture;
                    node.SettingsButtonClick += loopNode_SettingsButtonClick;

                    DataObject dragData = new DataObject("NodeFormat", node);
                    DragDrop.DoDragDrop(btn, dragData, DragDropEffects.Move);
                }
            }
        }
Beispiel #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();
            }
        }
Beispiel #3
0
 private void CloseLoopButton_Click(object sender, RoutedEventArgs e)
 {
     if (ViewedLoop.PreviousLoop != null)
     {
         ViewedLoop = ViewedLoop.PreviousLoop;
     }
     else
     {
         ViewedLoop = null;
     }
 }
Beispiel #4
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);
        }
Beispiel #5
0
        void AddAlgNode(string algName, double x = 0, double y = 0, LoopControl loop = null)
        {
            Type algType = HydrologyCore.AlgorithmTypes[algName];

            DataTable paramsTable = new DataTable();
            paramsTable.Columns.Add("Name");
            paramsTable.Columns.Add("Value");

            foreach (ParameterAttribute attr in algType.GetCustomAttributes<ParameterAttribute>())
            {
                DataRow row = paramsTable.NewRow();
                row["Name"] = attr.Name;
                row["Value"] = attr.DefaultValue;
                paramsTable.Rows.Add(row);
            }

            var algSettings = new AlgorithmSettings(FolderDialog, paramsTable, algType)
            {
                Owner = this,
                WindowStartupLocation = WindowStartupLocation.CenterOwner
            };
            if (ViewedLoop != null)
                algSettings.ParentLoop = ViewedLoop;
            bool? dialogResult = algSettings.ShowDialog();
            if (dialogResult.HasValue && dialogResult.Value)
            {
                AddNode(algType, algSettings.Path, algSettings.ParamsTable, x, y, loop, algSettings.VarLoop);
            }
        }
        public void PrepareLoop(LoopControl loop, Experiment experiment, BackgroundWorker worker, DoWorkEventArgs e, double p)
        {
            var chain = loop.LoopBody.CreateExecutionChain();

            double percentInc = 100.0 * p / chain.Count;
            percent += percentInc / 2;
            worker.ReportProgress((int)percent);

            for (loop.ResetValue(); loop.IsLoop(); loop.StepValue())
            {
                for (int i = 0; i < chain.Count; i++)
                {
                    if (chain[i] is InitNodeControl)
                        PrepareInitNode(chain[i] as InitNodeControl, experiment);
                    else if (chain[i] is AlgorithmNodeControl)
                        PrepareAlgorithmNode(chain[i] as AlgorithmNodeControl, experiment);
                    else if (chain[i] is RunProcessNodeControl)
                        PrepareRunProcessNode(chain[i] as RunProcessNodeControl, experiment);
                    else if (chain[i] is LoopControl)
                        PrepareLoop(chain[i] as LoopControl, experiment, worker, e, percentInc);

                    if (worker.CancellationPending == true)
                    {
                        e.Cancel = true;
                        return;
                    }
                    percent += percentInc;
                    worker.ReportProgress((int)percent);
                }

                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    return;
                }
                percent += percentInc;
                worker.ReportProgress((int)percent);
            }
        }