Ejemplo n.º 1
0
        public CarSpecsEditor(CarObject car) {
            _automaticallyRecalculate = ValuesStorage.GetBool(AutomaticallyRecalculateKey);

            InitializeComponent();
            DataContext = this;

            Buttons = new[] {
                OkButton,
                CreateExtraDialogButton(AppStrings.CarSpecs_FixFormats, FixValues),
                CreateExtraDialogButton(AppStrings.CarSpecs_UpdateCurves, UpdateCurves),
                CancelButton
            };

            _fixableInputs = new[] {
                PowerInput, TorqueInput, WeightInput, AccelerationInput, TopSpeedInput, PwRatioInput
            };

            foreach (var input in _fixableInputs) {
                input.PreviewMouseDown += FixableInput_MouseDown;
            }

            Car = car;
            TorqueGraph = car.SpecsTorqueCurve;
            PowerGraph = car.SpecsPowerCurve;

            Closing += CarSpecsEditor_Closing;
        }
Ejemplo n.º 2
0
        protected override void LoadData(JObject json) {
            base.LoadData(json);

            Brand = json.GetStringValueOnly("brand");
            if (string.IsNullOrEmpty(Brand)) {
                AddError(AcErrorType.Data_CarBrandIsMissing);
            }

            if (Country == null && Brand != null) {
                Country = AcStringValues.CountryFromBrand(Brand);
            }

            CarClass = json.GetStringValueOnly("class");
            ParentId = json.GetStringValueOnly("parent");

            var specsObj = json["specs"] as JObject;
            SpecsBhp = specsObj?.GetStringValueOnly("bhp");
            SpecsTorque = specsObj?.GetStringValueOnly("torque");
            SpecsWeight = specsObj?.GetStringValueOnly("weight");
            SpecsTopSpeed = specsObj?.GetStringValueOnly("topspeed");
            SpecsAcceleration = specsObj?.GetStringValueOnly("acceleration");
            SpecsPwRatio = specsObj?.GetStringValueOnly("pwratio");

            SpecsTorqueCurve = new GraphData(json["torqueCurve"] as JArray);
            SpecsPowerCurve = new GraphData(json["powerCurve"] as JArray);
        }
Ejemplo n.º 3
0
        private void RecalculateCurves(object sender, RoutedEventArgs e) {
            var dlg = new CarTransmissionLossSelector(Car);
            dlg.ShowDialog();
            if (!dlg.IsResultOk) return;

            var lossMultipler = 100.0 / (100.0 - dlg.Value);

            Lut torque;
            try {
                torque = TorquePhysicUtils.LoadCarTorque(Car.AcdData);
            } catch (FileNotFoundException) {
                return;
            }

            torque.TransformSelf(x => x.Y * lossMultipler);
            var power = TorquePhysicUtils.TorqueToPower(torque);

            TorqueGraph = new GraphData(torque);
            PowerGraph = new GraphData(power);

            if (ShowMessage(AppStrings.CarSpecs_CopyNewPowerAndTorque, AppStrings.Common_OneMoreThing, MessageBoxButton.YesNo) == MessageBoxResult.Yes) {
                // MaxY values were updated while creating new GraphData instances above
                TorqueInput.Text = Format(AppStrings.CarSpecs_Torque_FormatTooltip, torque.MaxY.ToString(@"F0", CultureInfo.InvariantCulture));
                PowerInput.Text = Format(AppStrings.CarSpecs_Power_FormatTooltip, power.MaxY.ToString(@"F0", CultureInfo.InvariantCulture));
            }
        }
Ejemplo n.º 4
0
        private void RecalculateAndScaleCurves(object sender, RoutedEventArgs e) {
            double maxPower, maxTorque;
            if (!FlexibleParser.TryParseDouble(PowerInput.Text, out maxPower) ||
                    !FlexibleParser.TryParseDouble(TorqueInput.Text, out maxTorque)) {
                ShowMessage(AppStrings.CarSpecs_SpecifyPowerAndTorqueFirst, ToolsStrings.Common_CannotDo_Title, MessageBoxButton.OK);
                return;
            }

            Lut torque;
            try {
                torque = TorquePhysicUtils.LoadCarTorque(Car.AcdData);
            } catch (FileNotFoundException ex) {
                Logging.Warning(ex);
                return;
            }

            TorqueGraph = new GraphData(torque).ScaleTo(maxTorque);
            PowerGraph = new GraphData(torque.Transform(x => x.X * x.Y)).ScaleTo(maxPower);
        }
Ejemplo n.º 5
0
        private void ScaleCurves(object sender, RoutedEventArgs e) {
            double power, torque;
            if (!FlexibleParser.TryParseDouble(PowerInput.Text, out power) ||
                    !FlexibleParser.TryParseDouble(TorqueInput.Text, out torque)) {
                ShowMessage(AppStrings.CarSpecs_SpecifyPowerAndTorqueFirst, ToolsStrings.Common_CannotDo_Title, MessageBoxButton.OK);
                return;
            }

            TorqueGraph = TorqueGraph.ScaleTo(torque);
            PowerGraph = PowerGraph.ScaleTo(power);
        }
Ejemplo n.º 6
0
        public static void Replace(this PlotModel collection, string trackerKey, GraphData data) {
            var series = collection.Series.OfType<LineSeries>().FirstOrDefault(x => x.TrackerKey == trackerKey);
            if (series == null) return;

            series.Points.Clear();
            if (data != null) {
                series.Points.AddRange(data.Points.Select(x => new DataPoint(x.X, x.Y)));
            }
        }