示例#1
0
    public override void GetProperties()
    {
        GameObject           propertiesContainer = GameObject.Find("PropertiesWindowContainer");
        EditObjectProperties script = propertiesContainer.GetComponent <EditObjectProperties>();

        script.AddString("ComponentNameLabel", _name, SetName);
        script.AddNumeric("InductancePropertyLabel", Inductance.ToString(), Inductance.GetType().ToString(), SetInductance, false);
        script.AddBoolean("TrapezoidalPropertyLabel", IsTrapezoidal.ToString(), SetTrapezoidal);
        script.AddResult("InductancePropertyLabel", "15.6", "Ohm");
    }
        public override object ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
        {
            var stringValue = (string)reader.Value !;

            return(Inductance.Parse(stringValue, serializer.Culture));
        }
示例#3
0
文件: Core.cs 项目: AChE-p/Circulus
        private void NewElecCompFromListIndex(int Index)
        {
            switch (Index)
            {
            case 0:
                Resistance r = new Resistance();
                elecCompSet.AddCompAndShow(r, Mycanvas);
                r.Move(100, 100);
                break;

            case 1:
                Capacity c = new Capacity();
                elecCompSet.AddCompAndShow(c, Mycanvas);
                c.Move(100, 100);
                break;

            case 2:
                Wire w = new Wire();
                elecCompSet.AddCompAndShow(w, Mycanvas);
                w.Move(100, 100);
                break;

            case 3:
                Inductance i = new Inductance();
                elecCompSet.AddCompAndShow(i, Mycanvas);
                i.Move(100, 100);
                break;

            case 4:
                OhmMeter o = new OhmMeter();
                elecCompSet.AddCompAndShow(o, Mycanvas);
                o.Move(100, 100);
                break;

            case 5:
                VoltMeter ee = new VoltMeter();
                elecCompSet.AddCompAndShow(ee, Mycanvas);
                ee.Move(100, 100);
                break;

            case 6:
                ElecGround eg = new ElecGround();
                elecCompSet.AddCompAndShow(eg, Mycanvas);
                eg.Move(100, 100);
                break;

            case 7:
                oscilloscopeData myOscilloscopeData = new
                                                      oscilloscopeData(Brushes.Red, oscilloscopeData.Volt_Index,
                                                                       myOscilloscope.m_SyncContext);
                Probe pb = new Probe(Brushes.Red, myOscilloscopeData);
                if (!myOscilloscope.IsVisible)
                {
                    myOscilloscope.Show();
                }
                myOscilloscope.AddData(myOscilloscopeData);
                myOscilloscope.SyncSettings();
                elecCompSet.AddCompAndShow(pb, Mycanvas);
                pb.Move(100, 100);
                break;

            case 8:
                myOscilloscopeData = new
                                     oscilloscopeData(Brushes.Blue, oscilloscopeData.Volt_Index,
                                                      myOscilloscope.m_SyncContext);
                pb = new Probe(Brushes.Blue, myOscilloscopeData);
                if (!myOscilloscope.IsVisible)
                {
                    myOscilloscope.Show();
                }
                myOscilloscope.AddData(myOscilloscopeData);
                myOscilloscope.SyncSettings();
                elecCompSet.AddCompAndShow(pb, Mycanvas);
                pb.Move(100, 100);
                break;

            case 9:
                Power p = new Power();
                elecCompSet.AddCompAndShow(p, Mycanvas);
                p.Move(100, 100);
                break;

            case 10:
                ACPower ap = new ACPower(0, 0.1, 10);
                elecCompSet.AddCompAndShow(ap, Mycanvas);
                ap.Move(100, 100);
                break;
            }
        }
 public InductanceExtension(Inductance value)
 {
     this.Value = value;
 }
        /// <inheritdoc />
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!this.initialized)
            {
                this.Initialize();
            }

            var message = this.errorText.ToString();

            if (!(targetType == typeof(Inductance) || targetType == typeof(Inductance?)))
            {
                message += $"{this.GetType().Name} does not support converting to {targetType.Name}";
            }

            if (message != string.Empty)
            {
                message = message.TrimEnd('\r', '\n');
                if (Is.DesignMode)
                {
                    throw new InvalidOperationException(message);
                }

                return(message);
            }

            if (value == null)
            {
                return(null);
            }

            if (value is double)
            {
                return(new Inductance((double)value, this.unit.Value));
            }

            var text = value as string;

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            var unitInput = this.UnitInput ?? Wpf.UnitInput.ScalarOnly;

            switch (unitInput)
            {
            case Wpf.UnitInput.ScalarOnly:
            {
                double d;
                if (double.TryParse(text, NumberStyles.Float, culture, out d))
                {
                    return(new Inductance(d, this.unit.Value));
                }

                Inductance result;
                if (Inductance.TryParse(text, NumberStyles.Float, culture, out result))
                {
                    return($"#{text}#");        // returning modified text so that TypeConverter fails and we get an error
                }

                return(text);        // returning raw to trigger error
            }

            case Wpf.UnitInput.SymbolAllowed:
            {
                double d;
                int    pos = 0;
                WhiteSpaceReader.TryRead(text, ref pos);
                if (DoubleReader.TryRead(text, ref pos, NumberStyles.Float, culture, out d))
                {
                    WhiteSpaceReader.TryRead(text, ref pos);
                    if (pos == text.Length)
                    {
                        return(new Inductance(d, this.unit.Value));
                    }
                }

                goto case Wpf.UnitInput.SymbolRequired;
            }

            case Wpf.UnitInput.SymbolRequired:
            {
                Inductance result;
                if (Inductance.TryParse(text, NumberStyles.Float, culture, out result))
                {
                    return(result);
                }

                return(text);
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#6
0
        //读入参数
        private void EndInput()
        {
            //MessageBox.Show(textBox1.Text);
            switch (elecComp.Comp)
            {
            case ElecComp.Comp_Resistance:
                double R;
                if (IsNumeric(textBox1.Text, out R))
                {
                    Resistance resistance = (Resistance)elecComp;
                    resistance.R = R;
                    ReleaseChooses();
                }
                else
                {
                    MessageBox.Show("输入不是数字");
                }
                break;

            case ElecComp.Comp_Capacity:
                double C;
                if (IsNumeric(textBox1.Text, out C))
                {
                    Capacity capacity = (Capacity)elecComp;
                    capacity.C = C;
                    ReleaseChooses();
                }
                else
                {
                    MessageBox.Show("输入不是数字");
                }
                break;

            case ElecComp.Comp_Inductance:
                double L;
                if (IsNumeric(textBox1.Text, out L))
                {
                    Inductance inductance = (Inductance)elecComp;
                    inductance.L = L;
                    ReleaseChooses();
                }
                else
                {
                    MessageBox.Show("输入不是数字");
                }
                break;

            case ElecComp.Comp_Power:
                double V;
                if (IsNumeric(textBox1.Text, out V))
                {
                    Power power = (Power)elecComp;
                    power.voltage = V;
                    ReleaseChooses();
                }
                else
                {
                    MessageBox.Show("输入不是数字");
                }
                break;

            case ElecComp.Comp_ACPower:
                double Vpp;
                double fre;
                if (IsNumeric(textBox1.Text, out Vpp))
                {
                    ACPower acpower = (ACPower)elecComp;
                    acpower.pp_value = Vpp;
                }
                else
                {
                    MessageBox.Show("输入不是数字");
                }
                if (IsNumeric(textBox2.Text, out fre))
                {
                    ACPower acpower = (ACPower)elecComp;
                    acpower.frequency = fre;
                    ReleaseChooses();
                }
                else
                {
                    MessageBox.Show("输入不是数字");
                }
                //@d这里只写了调整频率和幅值,建议加一个选择的组件选择波形
                break;

            default:
                break;
            }
        }
示例#7
0
        private void ElecCompList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (elecCompList.SelectedItems.Count == 1)
            {
                //MessageBox.Show("Select: " + elecCompList.SelectedIndex);
                switch (elecCompList.SelectedIndex)
                {
                case 0:
                    Resistance r = new Resistance();
                    elecCompSet.AddCompAndShow(r, Mycanvas);
                    r.Move(100, 100);
                    break;

                case 1:
                    Capacity c = new Capacity();
                    elecCompSet.AddCompAndShow(c, Mycanvas);
                    c.Move(100, 100);
                    break;

                case 2:
                    Wire w = new Wire();
                    elecCompSet.AddCompAndShow(w, Mycanvas);
                    w.Move(100, 100);
                    break;

                case 3:
                    Inductance i = new Inductance();
                    elecCompSet.AddCompAndShow(i, Mycanvas);
                    i.Move(100, 100);
                    break;

                case 4:
                    OhmMeter o = new OhmMeter();
                    elecCompSet.AddCompAndShow(o, Mycanvas);
                    o.Move(100, 100);
                    break;

                case 5:
                    VoltMeter ee = new VoltMeter();
                    elecCompSet.AddCompAndShow(ee, Mycanvas);
                    ee.Move(100, 100);
                    break;

                case 6:
                    ElecGround eg = new ElecGround();
                    elecCompSet.AddCompAndShow(eg, Mycanvas);
                    eg.Move(100, 100);
                    break;

                case 7:
                    oscilloscopeData myOscilloscopeData = new
                                                          oscilloscopeData(Brushes.Red, oscilloscopeData.Volt_Index,
                                                                           myOscilloscope.m_SyncContext);
                    Probe pb = new Probe(Brushes.Red, myOscilloscopeData);
                    if (!myOscilloscope.IsVisible)
                    {
                        myOscilloscope.Show();
                    }
                    myOscilloscope.AddData(myOscilloscopeData);
                    myOscilloscope.SyncSettings();
                    elecCompSet.AddCompAndShow(pb, Mycanvas);
                    pb.Move(100, 100);
                    break;

                case 8:
                    myOscilloscopeData = new
                                         oscilloscopeData(Brushes.Blue, oscilloscopeData.Volt_Index,
                                                          myOscilloscope.m_SyncContext);
                    pb = new Probe(Brushes.Blue, myOscilloscopeData);
                    if (!myOscilloscope.IsVisible)
                    {
                        myOscilloscope.Show();
                    }
                    myOscilloscope.AddData(myOscilloscopeData);
                    myOscilloscope.SyncSettings();
                    elecCompSet.AddCompAndShow(pb, Mycanvas);
                    pb.Move(100, 100);
                    break;
                }
            }
        }
 protected void SetScalarValue(DependencyProperty property, Inductance? quantity)
 {
     // we set this flag to prevent from setting scalar value changing quantity values.
     this.isUpdatingScalarValue = true;
     var value = quantity != null
         ? this.Unit.GetScalarValue(quantity.Value)
         : (double?)null;
     this.SetCurrentValue(property, value);
     this.isUpdatingScalarValue = false;
 }
 protected virtual void OnMaxValueChanged(Inductance? oldValue, Inductance? newValue)
 {
     this.SetScalarValue(ScalarMaxValueProperty, newValue);
 }