예제 #1
0
파일: Core.cs 프로젝트: AChE-p/Circulus
        private void Mycanvas_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (IsRuning)
            {
                return;
            }
            if (suspensionWindow.IsNowShown)
            {
                suspensionWindow.ReleaseChooses();
            }
            var      targetElement = e.Source as IInputElement;
            IntPoint point         = ToGrid(new IntPoint(e.GetPosition(Mycanvas)));

            if (targetElement != null)
            {
                targetElement.CaptureMouse();
                if (elecCompSet.FoundPressedElecComp(targetElement))
                {
                    //MessageBox.Show("Right!");
                    //textBox.Text = "Right";
                    ElecComp elecComp = elecCompSet.GetPressedElecComp(targetElement);
                    suspensionWindow.ShowChooses(elecComp, point);
                }
            }
        }
예제 #2
0
        //读取
        public static void Read(ElecCompSet elecCompSet, Canvas Mycanvas)
        {
            OpenFileDialog fd = new OpenFileDialog();

            fd.Filter       = "circ files (*.circ)|*.circ";
            fd.ShowReadOnly = true;
            if (!fd.ShowDialog().Value)
            {
                return;
            }
            String openingFileName = fd.FileName;

            //MessageBox.Show(openingFileName);
            using (FileStream fsRead = new FileStream(openingFileName, FileMode.Open))
            {
                int    fsLen  = (int)fsRead.Length;
                byte[] heByte = new byte[fsLen];
                int    r      = fsRead.Read(heByte, 0, heByte.Length);
                string myStr  = Encoding.UTF8.GetString(heByte);
                Console.WriteLine(myStr);
                string[] Strsp = myStr.Split('\n');
                for (int i = 0; i < Strsp.Length - 1; i++)
                {
                    Console.WriteLine("(" + i + "):" + Strsp[i]);
                    String[] singleSp = Strsp[i].Split(' ');
                    if (singleSp.Length != 5)
                    {
                        MessageBox.Show("Record Wrong!");
                    }
                    for (int j = 0; j < singleSp.Length; j++)
                    {
                        Console.WriteLine("    (" + j + "):" + singleSp[j]);
                    }
                    int Comp = int.Parse(singleSp[0]);

                    int RotateState = int.Parse(singleSp[1]);
                    int X           = int.Parse(singleSp[2]);
                    int Y           = int.Parse(singleSp[3]);

                    ElecComp x = elecCompSet.AddFromRecord(Comp, Mycanvas);
                    x.Move(X, Y);
                    for (int j = 0; j < RotateState; j++)
                    {
                        x.RotateLeft();
                    }
                    x.HandleAttr(singleSp[4]);
                }
            }
        }
예제 #3
0
        public void ShowChooses(ElecComp elecComp_, IntPoint postion)
        {
            IsNowShown = true;
            elecComp   = elecComp_;
            //MessageBox.Show("Choose" + elecComp.Comp);
            switch (elecComp.Comp)
            {
            case ElecComp.Comp_Resistance:
                textBlock1       = new TextBlock();
                textBlock1.Width = 30;
                textBlock1.Text  = "Ω";
                Canvas.SetLeft(textBlock1, postion.X + 75);
                Canvas.SetTop(textBlock1, postion.Y - 30);
                mainWindow.Mycanvas.Children.Add(textBlock1);
                textBox1       = new TextBox();
                textBox1.Width = 70;
                textBox1.Text  = "" + ((Resistance)elecComp).R;
                Canvas.SetLeft(textBox1, postion.X);
                Canvas.SetTop(textBox1, postion.Y - 30);
                textBox1.KeyUp += TextBox1_KeyUp;
                mainWindow.Mycanvas.Children.Add(textBox1);
                break;

            case ElecComp.Comp_Capacity:
                textBlock1       = new TextBlock();
                textBlock1.Width = 30;
                textBlock1.Text  = "F";
                Canvas.SetLeft(textBlock1, postion.X + 75);
                Canvas.SetTop(textBlock1, postion.Y - 30);
                mainWindow.Mycanvas.Children.Add(textBlock1);
                textBox1       = new TextBox();
                textBox1.Width = 70;
                textBox1.Text  = "" + ((Capacity)elecComp).C;
                Canvas.SetLeft(textBox1, postion.X);
                Canvas.SetTop(textBox1, postion.Y - 30);
                textBox1.KeyUp += TextBox1_KeyUp;
                mainWindow.Mycanvas.Children.Add(textBox1);
                break;

            default:
                IsNowShown = false;
                elecComp   = null;
                break;
            }
        }
예제 #4
0
        public void ShowChooses(ElecComp elecComp_, IntPoint postion)
        {
            IsNowShown = true;
            elecComp   = elecComp_;
            //MessageBox.Show("Choose" + elecComp.Comp);
            switch (elecComp.Comp)
            {
            case ElecComp.Comp_Resistance:
                textBlock1       = new TextBlock();
                textBlock1.Width = 30;
                textBlock1.Text  = "Ω";
                Canvas.SetLeft(textBlock1, postion.X + 75);
                Canvas.SetTop(textBlock1, postion.Y - 30);
                core.Mycanvas.Children.Add(textBlock1);
                textBox1       = new TextBox();
                textBox1.Width = 70;
                textBox1.Text  = "" + ((Resistance)elecComp).R;
                Canvas.SetLeft(textBox1, postion.X);
                Canvas.SetTop(textBox1, postion.Y - 30);
                textBox1.KeyUp += TextBox1_KeyUp;
                core.Mycanvas.Children.Add(textBox1);
                break;

            case ElecComp.Comp_Capacity:
                textBlock1       = new TextBlock();
                textBlock1.Width = 30;
                textBlock1.Text  = "F";
                Canvas.SetLeft(textBlock1, postion.X + 75);
                Canvas.SetTop(textBlock1, postion.Y - 30);
                core.Mycanvas.Children.Add(textBlock1);
                textBox1       = new TextBox();
                textBox1.Width = 70;
                textBox1.Text  = "" + ((Capacity)elecComp).C;
                Canvas.SetLeft(textBox1, postion.X);
                Canvas.SetTop(textBox1, postion.Y - 30);
                textBox1.KeyUp += TextBox1_KeyUp;
                core.Mycanvas.Children.Add(textBox1);
                break;

            case ElecComp.Comp_Inductance:
                textBlock1       = new TextBlock();
                textBlock1.Width = 30;
                textBlock1.Text  = "H";
                Canvas.SetLeft(textBlock1, postion.X + 75);
                Canvas.SetTop(textBlock1, postion.Y - 30);
                core.Mycanvas.Children.Add(textBlock1);
                textBox1       = new TextBox();
                textBox1.Width = 70;
                textBox1.Text  = "" + ((Inductance)elecComp).L;
                Canvas.SetLeft(textBox1, postion.X);
                Canvas.SetTop(textBox1, postion.Y - 30);
                textBox1.KeyUp += TextBox1_KeyUp;
                core.Mycanvas.Children.Add(textBox1);
                break;

            case ElecComp.Comp_Power:
                textBlock1       = new TextBlock();
                textBlock1.Width = 70;
                textBlock1.Text  = "V (电压)";
                Canvas.SetLeft(textBlock1, postion.X + 75);
                Canvas.SetTop(textBlock1, postion.Y - 30);
                core.Mycanvas.Children.Add(textBlock1);
                textBox1       = new TextBox();
                textBox1.Width = 70;
                textBox1.Text  = "" + ((Power)elecComp).voltage;
                Canvas.SetLeft(textBox1, postion.X);
                Canvas.SetTop(textBox1, postion.Y - 30);
                textBox1.KeyUp += TextBox1_KeyUp;
                core.Mycanvas.Children.Add(textBox1);
                break;

            case ElecComp.Comp_ACPower:
                textBlock1       = new TextBlock();
                textBlock1.Width = 70;
                textBlock1.Text  = "V (幅值)";
                Canvas.SetLeft(textBlock1, postion.X + 75);
                Canvas.SetTop(textBlock1, postion.Y - 30);
                core.Mycanvas.Children.Add(textBlock1);
                textBox1       = new TextBox();
                textBox1.Width = 70;
                textBox1.Text  = "" + ((ACPower)elecComp).pp_value;
                Canvas.SetLeft(textBox1, postion.X);
                Canvas.SetTop(textBox1, postion.Y - 30);
                textBox1.KeyUp += TextBox1_KeyUp;
                core.Mycanvas.Children.Add(textBox1);

                textBlock2       = new TextBlock();
                textBlock2.Width = 70;
                textBlock2.Text  = " Hz(频率)";
                Canvas.SetLeft(textBlock2, postion.X + 75);
                Canvas.SetTop(textBlock2, postion.Y - 60);
                core.Mycanvas.Children.Add(textBlock2);
                textBox2       = new TextBox();
                textBox2.Width = 70;
                textBox2.Text  = "" + ((ACPower)elecComp).frequency;
                Canvas.SetLeft(textBox2, postion.X);
                Canvas.SetTop(textBox2, postion.Y - 60);
                textBox2.KeyUp += TextBox2_KeyUp;
                core.Mycanvas.Children.Add(textBox2);

                break;

            default:
                IsNowShown = false;
                elecComp   = null;
                break;
            }
        }
예제 #5
0
        public List <IntPoint> Interfaces; //这个列表是按顺序来的,对于二极管这种,是有正负极先后顺序的

        public BriefElecComp(int Comp_, List <IntPoint> Interfaces_, ElecComp elecComp_)
        {
            Comp       = Comp_;
            Interfaces = Interfaces_;
            elecComp   = elecComp_;
        }