public void AddVoltmeter()
    {
        var temp = new Voltmeter(4);

        CreatePairForElement(temp);
        ContextMenuManager.Instance.ContextMenuActive = false;
    }
    public void VoltmeterTest()
    {
        var battery = HelperClass.GetRandomBattery();
        var cable1 = new Cable("test_one", 1, 2);
        var cable2 = new Cable("test_one", 1, 2);
        var voltmeter = new Voltmeter(2);
        battery.Connect(voltmeter);
        voltmeter.Connect(battery);
        voltmeter.SetMeasuredSubcircuit(cable1);
        cable1.Connect(cable2);

        battery.GiveProperties();

        Assert.AreEqual((battery.Properties.Amperage * (cable1.Properties.Resistance + cable2.Properties.Resistance + 2)).ToString(), voltmeter.GetValue().Replace(" Volt", ""));
    }
Example #3
0
    public void VoltmeterTest()
    {
        var battery   = HelperClass.GetRandomBattery();
        var cable1    = new Cable("test_one", 1, 2);
        var cable2    = new Cable("test_one", 1, 2);
        var voltmeter = new Voltmeter(2);

        battery.Connect(voltmeter);
        voltmeter.Connect(battery);
        voltmeter.SetMeasuredSubcircuit(cable1);
        cable1.Connect(cable2);

        battery.GiveProperties();

        Assert.AreEqual((battery.Properties.Amperage * (cable1.Properties.Resistance + cable2.Properties.Resistance + 2)).ToString(), voltmeter.GetValue().Replace(" Volt", ""));
    }
Example #4
0
        public override void AddShapes()
        {
            //设置类型
            Comp = Comp_OhmMeter;

            /*//必须重新设置元件大小(已废弃)
             * size.X = 100;
             * size.Y = 20;*/
            //定义外部接口的位置
            RelativeInterface.Add(new IntPoint(0, 10));   //左端口
            RelativeInterface.Add(new IntPoint(100, 10)); //右端口
            //左边的导线
            MyShape line1 = new MyShape(MyShape.Shape_Line);

            line1.GetLine().Stroke          = System.Windows.Media.Brushes.Red;
            line1.GetLine().X1              = 0;
            line1.GetLine().Y1              = 10;
            line1.GetLine().X2              = 30;
            line1.GetLine().Y2              = 10;
            line1.GetLine().StrokeThickness = 5;
            shapeSet.AddShape(line1);
            //中间的长方形
            MyShape rectangle = new MyShape(MyShape.Shape_Rectangle);

            rectangle.GetRectangle().Fill   = System.Windows.Media.Brushes.Red;
            rectangle.GetRectangle().Width  = 40;
            rectangle.GetRectangle().Height = 20;
            Canvas.SetLeft(rectangle.GetRectangle(), 30);
            Canvas.SetTop(rectangle.GetRectangle(), 0);
            shapeSet.AddShape(rectangle);
            //右边的导线
            MyShape line2 = new MyShape(MyShape.Shape_Line);

            line2.GetLine().Stroke          = System.Windows.Media.Brushes.Red;
            line2.GetLine().X1              = 70;
            line2.GetLine().Y1              = 10;
            line2.GetLine().X2              = 100;
            line2.GetLine().Y2              = 10;
            line2.GetLine().StrokeThickness = 5;
            shapeSet.AddShape(line2);
            //左边的定位圆圈
            MyShape circle1 = new MyShape(MyShape.Shape_Ellipse);

            circle1.GetEllipse().Fill            = System.Windows.Media.Brushes.Red;
            circle1.GetEllipse().StrokeThickness = 3;
            circle1.GetEllipse().Stroke          = System.Windows.Media.Brushes.Yellow;
            circle1.GetEllipse().Width           = 10;
            circle1.GetEllipse().Height          = 10;
            Canvas.SetLeft(circle1.GetEllipse(), -5);
            Canvas.SetTop(circle1.GetEllipse(), 5);
            shapeSet.AddShape(circle1);
            //右边的定位圆圈
            MyShape circle2 = new MyShape(MyShape.Shape_Ellipse);

            circle2.GetEllipse().Fill            = System.Windows.Media.Brushes.Red;
            circle2.GetEllipse().StrokeThickness = 3;
            circle2.GetEllipse().Stroke          = System.Windows.Media.Brushes.Yellow;
            circle2.GetEllipse().Width           = 10;
            circle2.GetEllipse().Height          = 10;
            Canvas.SetLeft(circle2.GetEllipse(), 95);
            Canvas.SetTop(circle2.GetEllipse(), 5);
            shapeSet.AddShape(circle2);

            showingData    = new ShowingData("" + 101230 + "ohm");
            ohmmeterWindow = new Voltmeter(this);
            ohmmeterWindow.Show();
            showingData.SimpleData = "gagagag";
        }
 public void AddVoltmeter()
 {
     var temp = new Voltmeter(4);
     CreatePairForElement(temp);
     ContextMenuManager.Instance.ContextMenuActive = false;
 }
Example #6
0
    void Update()
    {
        #region cam control
        float rx, ry;
        rx = cam.transform.rotation.eulerAngles.x;
        ry = cam.transform.rotation.eulerAngles.y;
        if (Input.GetMouseButton(1))
        {
            rx -= Input.GetAxis("Mouse Y") * rotateSpeed;
            ry += Input.GetAxis("Mouse X") * rotateSpeed;
        }
        cam.transform.rotation = Quaternion.Euler(rx, ry, 0);
        Vector3 camMove = new Vector3(Input.GetAxis("Horizontal") * moveSpeedXY - ((Input.GetMouseButton(2)) ? Input.GetAxis("Mouse X") : 0) * moveSpeedXMouse, -((Input.GetMouseButton(2)) ? Input.GetAxis("Mouse Y") : 0) * moveSpeedYMouse, Input.GetAxis("Vertical") * moveSpeedXY + Input.GetAxis("Mouse ScrollWheel") * moveSpeedZ);
        cam.transform.Translate(camMove);
        #endregion

        if (Input.GetMouseButtonDown(0))//select
        {
            mouseLastPos = Input.mousePosition;
            Ray        ray = cam.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 500))
            {
                electronicComponent curSelect = hit.collider.gameObject.GetComponent <electronicComponent>();
                if (curSelect != null)
                {
                    if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                    {
                        if (selectedList.Contains(curSelect))
                        {
                            curSelect.unselect();
                            selectedList.Remove(curSelect);
                        }
                        else
                        {
                            curSelect.select();
                            selectedList.Add(curSelect);
                        }
                    }


                    else
                    {
                        foreach (electronicComponent c in selectedList)
                        {
                            c.unselect();
                        }
                        selectedList.Clear();
                        //select a wireNet
                        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                        {
                            if (curSelect.GetType() == typeof(Wire))
                            {
                                foreach (electronicComponent c in ((Wire)curSelect).wireNet.wires)
                                {
                                    c.select();
                                    selectedList.Add(c);
                                }
                                foreach (electronicComponent c in ((Wire)curSelect).wireNet.intersections)
                                {
                                    c.select();
                                    selectedList.Add(c);
                                }
                            }
                            if (curSelect.GetType() == typeof(Intersection))
                            {
                                foreach (electronicComponent c in ((Intersection)curSelect).wireNet.wires)
                                {
                                    c.select();
                                    selectedList.Add(c);
                                }
                                foreach (electronicComponent c in ((Intersection)curSelect).wireNet.intersections)
                                {
                                    c.select();
                                    selectedList.Add(c);
                                }
                            }
                        }
                        else
                        {
                            curSelect.select();
                            selectedList.Add(curSelect);
                        }
                    }
                }
                else
                {
                    foreach (electronicComponent c in selectedList)
                    {
                        c.unselect();
                    }
                    selectedList.Clear();
                }
            }
            else
            {
                foreach (electronicComponent c in selectedList)
                {
                    c.unselect();
                }
                selectedList.Clear();
            }
        }
        if (Input.GetMouseButton(0))//drag
        {
            foreach (electronicComponent c in selectedList)
            {
                c.move(mousePos(selectedList[selectedList.Count - 1].gameObject.transform.position.y, Input.mousePosition) - mousePos(selectedList[selectedList.Count - 1].gameObject.transform.position.y, mouseLastPos), Input.GetKey(KeyCode.LeftAlt)?0:snapGap);
            }
        }
        if (Input.GetMouseButtonUp(0))//drag
        {
            foreach (electronicComponent c in selectedList)
            {
                c.OnMouseRelease();
            }
        }

        #region create/delete components
        if (Input.GetKeyDown(KeyCode.Delete))
        {
            foreach (electronicComponent c in selectedList)
            {
                Data.Remove(c); c.delete();
            }
            selectedList.Clear();
            reArrangeWireNets();
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            InitializeComponent(Instantiate(power));
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            InitializeComponent(Instantiate(resistance));
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            InitializeComponent(Instantiate(capacitance));
        }
        if (Input.GetKeyDown(KeyCode.L))
        {
            InitializeComponent(Instantiate(inductor));
        }
        if (Input.GetKeyDown(KeyCode.I))
        {
            GameObject   newObject = Instantiate(intersection);
            Intersection script    = (Intersection)newObject.GetComponent <electronicComponent>();
            newObject.transform.position = mousePos(0, Input.mousePosition);
            script.create(this);
            foreach (electronicComponent c in selectedList)
            {
                c.unselect();
            }
            selectedList.Clear();
            newObject.GetComponent <electronicComponent>().select();
            selectedList.Add(newObject.GetComponent <electronicComponent>());
            reArrangeWireNets();
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            if (selectedList.Count == 2)
            {
                bool t = true;
                foreach (electronicComponent c in selectedList)
                {
                    if (c.n_emptyConnect() < 1)
                    {
                        t = false;
                    }
                }
                if (t)
                {
                    GameObject newObject = Instantiate(wire);
                    newObject.GetComponent <electronicComponent>().create(this);
                    Wire wireScript = newObject.GetComponent <Wire>();

                    wireScript.addConnection(selectedList[0]);
                    wireScript.addConnection(selectedList[1]);
                    selectedList[0].addConnection(wireScript);
                    selectedList[1].addConnection(wireScript);
                    foreach (electronicComponent c in selectedList)
                    {
                        c.unselect();
                    }
                    selectedList.Clear();
                    newObject.GetComponent <electronicComponent>().select();
                    selectedList.Add(newObject.GetComponent <electronicComponent>());
                    reArrangeWireNets();
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.V))
        {
            if (selectedList.Count == 2)
            {
                bool t = true;
                foreach (electronicComponent c in selectedList)
                {
                    if (c.GetType() != typeof(Wire))
                    {
                        t = false;
                    }
                }
                if (t)
                {
                    GameObject newObject = Instantiate(voltmeter);
                    Voltmeter  script    = newObject.GetComponent <Voltmeter>();
                    script.create_(this, (Wire)selectedList[0], (Wire)selectedList[1]);
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            if (selectedList.Count == 1)
            {
                if (selectedList[0].GetType() != typeof(Wire))
                {
                    GameObject newObject = Instantiate(ammeter);
                    Ammeter    script    = newObject.GetComponent <Ammeter>();
                    script.create_(this, selectedList[0]);
                }
            }
        }
        if (Input.GetKey(KeyCode.Escape))
        {
            foreach (WireNet c in FindObjectsOfType <WireNet>())
            {
                c.Reset();
            }
            foreach (Capacitance c in FindObjectsOfType <Capacitance>())
            {
                c.Reset();
            }
        }

        #endregion

        mouseLastPos = Input.mousePosition;
    }