Ejemplo n.º 1
0
        public static void Connect(CommonObject st1, CommonObject st2, bool direction = false)
        {
            if (Equals(st1, st2))
            {
                MessageBox.Show("Нельзя соединить станцию с собой", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                ToTempObj(null);
                return;
            }

            if ((st1.Connection != null) && (st2.Connection != null))
            {
                if (st1.Connection.Any(t1 => st2.Connection.Any(t => t1 == t)))
                {
                    MessageBox.Show("Такое соединение уже существует", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            var parent = LogicalTreeHelper.GetParent(st1) as Panel;

            st1.Connection.Add(new StanConnection(stArrow));
            var index1 = st1.Connection.Count - 1;
            st2.Connection.Add(st1.Connection[index1]);
            //var index2 = st2.Connection.Count - 1;

            st1.Connection[index1].obj1 = st1;
            st1.Connection[index1].obj2 = st2;

            st1.Connection[index1].line.X1 = st1.GetCenter().X;
            st1.Connection[index1].line.Y1 = st1.GetCenter().Y;
            st1.Connection[index1].line.X2 = st2.GetCenter().X;
            st1.Connection[index1].line.Y2 = st2.GetCenter().Y;
            st1.Connection[index1].line.StrokeThickness = 2;

            st1.Connection[index1].line.Stroke = new SolidColorBrush(Colors.Black);

            if (stArrow)
            {
                st1.Connection[index1].arrow1.X1 = st1.Connection[index1].arrow2.X1 = st1.Connection[index1].line.X2;
                st1.Connection[index1].arrow1.Y1 = st1.Connection[index1].arrow2.Y1 = st1.Connection[index1].line.Y2;
                var stP = new Point(st1.Connection[index1].line.X1, st1.Connection[index1].line.Y1);
                var endP = new Point(st1.Connection[index1].line.X2, st1.Connection[index1].line.Y2);
                Point arP1, arP2;
                SetArrowCoords(stP, endP, out arP1, out arP2);
                st1.Connection[index1].arrow1.X2 = arP1.X;
                st1.Connection[index1].arrow1.Y2 = arP1.Y;
                st1.Connection[index1].arrow2.X2 = arP2.X;
                st1.Connection[index1].arrow2.Y2 = arP2.Y;

                st1.Connection[index1].arrow1.StrokeThickness = 2;
                st1.Connection[index1].arrow2.StrokeThickness = 2;

                st1.Connection[index1].arrow1.Stroke = st1.Connection[index1].arrow2.Stroke = new SolidColorBrush(Colors.Black);
            }

            if (parent != null)
            {
                parent.Children.Add(st1.Connection[index1].line);
                if (stArrow)
                {
                    parent.Children.Add(st1.Connection[index1].arrow1);
                    parent.Children.Add(st1.Connection[index1].arrow2);
                }
            }
            stArrow = false;
        }
Ejemplo n.º 2
0
 public double GetDistanse(CommonObject st)
 {
     var x = GetCenter().X - st.GetCenter().X;
     var y = GetCenter().Y - st.GetCenter().Y;
     return Math.Sqrt(x*x + y*y);
 }
Ejemplo n.º 3
0
        public void UpdateLine(CommonObject st)
        {
            Point arP1, arP2;
            if (Equals(obj1, st))
            {
                line.X1 = st.GetCenter().X;
                line.Y1 = st.GetCenter().Y;
                if (_arrow)
                {
                    var stP = new Point(line.X1, line.Y1);
                    var endP = new Point(line.X2, line.Y2);
                    SetArrowCoords(stP, endP, out arP1, out arP2);
                    arrow1.X2 = arP1.X;
                    arrow1.Y2 = arP1.Y;
                    arrow2.X2 = arP2.X;
                    arrow2.Y2 = arP2.Y;
                }
            }
            else
                if (Equals(obj2, st))
                {
                    line.X2 =  st.GetCenter().X;
                    line.Y2 =  st.GetCenter().Y;
                    if (_arrow)
                    {
                        arrow1.X1 = arrow2.X1 = line.X2;
                        arrow1.Y1 = arrow2.Y1 = line.Y2;
                        var stP = new Point(line.X1, line.Y1);
                        var endP = new Point(line.X2, line.Y2);
                        SetArrowCoords(stP, endP, out arP1, out arP2);
                        arrow1.X2 = arP1.X;
                        arrow1.Y2 = arP1.Y;
                        arrow2.X2 = arP2.X;
                        arrow2.Y2 = arP2.Y;
                    }

                }
        }