private void ApplyPlate(PlateMetadata plate) { plate.Country = (_cmbCountries.SelectedItem as CountryItem)?.ModelId; plate.Stencil = (_cmbStencils.SelectedItem as StencilItem)?.StencilId; plate.Quality = Core.Quality(_rdiHigh.Checked, _rdiNormal.Checked); _image.PlateCoordinates?.CopyTo(plate.Coordinates, 0); }
public void ChangeNumber_CarNumberAndPlate_EditedNumber() { var number = "C123AB35"; var plate = new PlateMetadata { Number = "C124AC35", }; Core.ChangeNumber(number, plate); Assert.That(plate.Number, Is.EqualTo(number)); }
/// <summary>Обновляет номер на UI из указанных метаданных.</summary> /// <param name="plate"></param> private void UpdateUIPlate(PlateMetadata plate) { Assert.IsNotNull(plate); SuspendUpdate(); _txtPlate.Text = plate.Number; var countryId = plate.Country; if (string.IsNullOrWhiteSpace(countryId)) // Если страна не указана { countryId = _stencilsProvider.GetModel(plate.Stencil)?.Id; } UpdateCountry(countryId); UpdateStencil(plate.Stencil); UpdatePlateQuality(plate); UpdateImage(plate); ResumeUpdate(); }
/// <summary>Изменяет качество номера в зависимости от выбранного.</summary> private void UpdatePlateQuality(PlateMetadata plate) { if (plate == null) { return; } switch (plate.Quality) { case PlateQuality.High: _rdiHigh.Checked = true; break; case PlateQuality.Normal: _rdiNormal.Checked = true; break; case PlateQuality.Low: _rdiLow.Checked = true; break; } }
/// <summary>Добавление нового номера.</summary> private void AddNewPlate() { if (string.IsNullOrWhiteSpace(_txtPlate.Text)) { return; } try { var newPlate = Core.SanitizePlate(_txtPlate.Text); if (_lbxPlates.FindString(newPlate) != -1) { MessageBox.Show("This number is already there!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SearchTemplateEnteredNumber(newPlate); var plate = new PlateMetadata { Country = (_cmbCountries.SelectedItem as CountryItem)?.ModelId, Stencil = (_cmbStencils.SelectedItem as StencilItem)?.StencilId, Number = newPlate, }; _lbxPlates.Items.Add(plate); _lbxPlates.SelectedItem = plate; _image.IsPlateVisible = true; } catch (Exception exc) when(!exc.IsCritical()) { Log.Error("Add plate fail.", exc); } }
private void UpdateImage(PlateMetadata plate) { _image.UpdatePlate(plate); UpdatePlateImage(plate); _image.IsPlateVisible = true; }
private void UpdatePlateImage([CanBeNull] PlateMetadata plate = null, [CanBeNull] Decision decision = null) { try { var coordinates = _image.PlateCoordinates; if (coordinates != null && coordinates.Any()) { if (decision != null) { var rect = coordinates.ToBoundedRectangle(); _imgPlate.FooterText = $"{decision.Plate.Number} [{decision.Plate.Stencil}], {rect}"; rect.Inflate(15, 6); rect.Intersect(new Rectangle(Point.Empty, _image.ImageSize)); _image.Matrix.CopyTo(_imgPlate.Matrix, rect); if (_imgPlate.Matrix is Matrix m) { Enhancement.ContrastStretch(m); } _imgPlate.Invalidate(); var offsetX = -rect.X; var offsetY = -rect.Y; _imagePlateWidget.PlateCoords = coordinates.Select(c => { c.Offset(offsetX, offsetY); return(c); }).ToArray(); var symbols = new List <WidgetSymbol>(); foreach (var symbol in decision.Symbols) { var ws = new WidgetSymbol() { Char = symbol.Char.ToString(), Bounds = symbol.Bounds.Offset(offsetX, offsetY).ToRect(), }; symbols.Add(ws); } _imagePlateWidget.Symbols = symbols.ToArray(); _imagePlateWidget.IsVisible = true; } else { var rect = coordinates.ToBoundedRectangle(); if (plate != null) { _imgPlate.FooterText = $"{plate.Number} [{plate.Stencil}], {rect}"; } rect.Inflate(15, 6); rect.Intersect(new Rectangle(Point.Empty, _image.ImageSize)); _image.Matrix.CopyTo(_imgPlate.Matrix, rect); if (_imgPlate.Matrix is Matrix m) { Enhancement.ContrastStretch(m); } _imgPlate.Invalidate(); var offsetX = -rect.X; var offsetY = -rect.Y; _imagePlateWidget.PlateCoords = coordinates.Select(c => { c.Offset(offsetX, offsetY); return(c); }).ToArray(); _imagePlateWidget.Symbols = default; _imagePlateWidget.IsVisible = true; } } else { _imgPlate.FooterText = string.Empty; } } catch (Exception exc) when(!exc.IsCritical()) { Log.Error(exc.Message, exc); } }