コード例 #1
0
ファイル: Wireclass.xaml.cs プロジェクト: DouahIlies/CircLab
        public void relier()
        {
            Ellipse select;

            destination = UserClass.TryFindParent <Terminal>(selection2);
            source      = UserClass.TryFindParent <Terminal>(selection1);

            if (source.IsOutpt == false)
            {
                if (destination.IsOutpt == true)
                {
                    select     = selection2;
                    selection2 = selection1;
                    selection1 = select;
                    Terminal temp = destination;
                    destination = source;
                    source      = temp;
                }
                else
                {
                    //selected = false;
                    return;
                }
            }
            else
            {
                if (destination.IsOutpt == true)
                {
                    //selected = false;
                    return;
                }
            }

            if (destination.wires.Count >= 1)
            {
                //selected = false;
                return;
            }

            btn111 = selection1;
            btn222 = selection2;
            destination.wires.Add(this);
            destination.etat = this._state;
            source.wires.Add(this);


            btn2Point = selection2.TransformToAncestor(myCanvas).Transform(new Point(0, 0));
            btn1Point = selection1.TransformToAncestor(myCanvas).Transform(new Point(0, 0));


            l1.Stroke          = new SolidColorBrush(Colors.Black);
            l1.StrokeThickness = 2.0;
            l1.X1 = btn1Point.X;
            l1.X2 = (btn1Point.X + btn2Point.X + 2 * selection1.ActualWidth) / 2;
            l1.Y1 = btn1Point.Y + selection1.ActualHeight / 2;
            l1.Y2 = btn1Point.Y + selection1.ActualHeight / 2;
            if (!myCanvas.Children.Contains(l1))
            {
                myCanvas.Children.Add(l1);
            }


            l2.Stroke          = new SolidColorBrush(Colors.Black);
            l2.StrokeThickness = 2.0;
            l2.X1 = l1.X2;
            l2.X2 = l1.X2;
            l2.Y1 = l1.Y1;
            l2.Y2 = btn2Point.Y - selection2.ActualHeight / 2;
            if (!myCanvas.Children.Contains(l2))
            {
                myCanvas.Children.Add(l2);
            }


            l3.Stroke          = new SolidColorBrush(Colors.Black);
            l3.StrokeThickness = 2.0;
            l3.X1 = l2.X2;
            l3.X2 = (btn2Point.X);
            l3.Y1 = l2.Y2;
            l3.Y2 = l2.Y2;
            if (!myCanvas.Children.Contains(l3))
            {
                myCanvas.Children.Add(l3);
            }


            UserClass.TryFindParent <StandardComponent>(source).Run();
            //selected = false;
            UserClass.TryFindParent <StandardComponent>(destination).Run();
            destinations.Add(UserClass.TryFindParent <StandardComponent>(destination));

            if (source.wires.Count <= 1)
            {
                source.logestWire = this;
            }
            else
            {
                if (Math.Abs((source.logestWire).l1.X1 - (source.logestWire).l1.X2) < Math.Abs(this.l1.X1 - this.l1.X2))
                {
                    source.logestWire = this;
                }
            }
            dessinernoued();
        }