Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
931ccb2599 | ||
|
|
beb635889b | ||
|
|
01d98db116 | ||
|
|
122a5dbfe1 | ||
|
|
cc983c3272 | ||
|
|
dcaf120503 |
@@ -11,9 +11,5 @@ namespace WinFormsApp1
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4,
|
||||
DRDiagonal = 5,
|
||||
DLDiagonal = 6,
|
||||
ULDiagonal = 7,
|
||||
URDiagonal = 8
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tractors;
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
@@ -23,6 +24,10 @@ namespace WinFormsApp1
|
||||
return _tractor?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public string GetInfo() => _tractor?.GetDataForSave();
|
||||
|
||||
public static IDrawningObject Create(string data) => new DrawningObjectTractor(data.CreateDrawingTraktor());
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_tractor?.MoveTransport(direction);
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace WinFormsApp1
|
||||
/// <summary>
|
||||
/// Цвет кузова
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
public Color BodyColor { get; set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
@@ -34,5 +34,12 @@ namespace WinFormsApp1
|
||||
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
public static EntityTractor Creator(string data)
|
||||
{
|
||||
string[] strs = data.Split(':');
|
||||
return new EntityTractor(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
45
WinFormsApp1/ExtentionTraktor.cs
Normal file
45
WinFormsApp1/ExtentionTraktor.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WinFormsApp1;
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
internal static class ExtentionTraktor
|
||||
{
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
public static TractorDraw CreateDrawingTraktor(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new TractorDraw(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new MultiTraktorDraw(
|
||||
Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]), Color.FromName(strs[3]),
|
||||
Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]));
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static string GetDataForSave(this TractorDraw drawingTraktor)
|
||||
{
|
||||
var traktor = drawingTraktor.Tractor;
|
||||
var str = $"{traktor.Speed}{_separatorForObject}{traktor.Weight}{_separatorForObject}{traktor.BodyColor.Name}";
|
||||
if (traktor is not MultiTraktor multiTraktor)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{_separatorForObject}{multiTraktor.DopColor.Name}{_separatorForObject}{multiTraktor.dopAhead}{_separatorForObject}{multiTraktor.dopBehind}";
|
||||
}
|
||||
}
|
||||
}
|
||||
80
WinFormsApp1/FormMapWithSetTraktor.Designer.cs
generated
80
WinFormsApp1/FormMapWithSetTraktor.Designer.cs
generated
@@ -47,9 +47,16 @@ namespace WinFormsApp1
|
||||
this.buttonRemoveTraktor = new System.Windows.Forms.Button();
|
||||
this.buttonAddTraktor = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBoxMaps.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
@@ -65,11 +72,11 @@ namespace WinFormsApp1
|
||||
this.groupBox1.Controls.Add(this.buttonRemoveTraktor);
|
||||
this.groupBox1.Controls.Add(this.buttonAddTraktor);
|
||||
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox1.Location = new System.Drawing.Point(596, 0);
|
||||
this.groupBox1.Location = new System.Drawing.Point(596, 24);
|
||||
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.groupBox1.Size = new System.Drawing.Size(219, 476);
|
||||
this.groupBox1.Size = new System.Drawing.Size(219, 515);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
@@ -143,7 +150,7 @@ namespace WinFormsApp1
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::Tractors.Properties.Resources.RkYIe2_6DuQ;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(126, 435);
|
||||
this.buttonRight.Location = new System.Drawing.Point(126, 442);
|
||||
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(35, 30);
|
||||
@@ -156,7 +163,7 @@ namespace WinFormsApp1
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Tractors.Properties.Resources.MbV2DYU_nPM;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(91, 435);
|
||||
this.buttonDown.Location = new System.Drawing.Point(91, 442);
|
||||
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(35, 30);
|
||||
@@ -169,7 +176,7 @@ namespace WinFormsApp1
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::Tractors.Properties.Resources.Hhxt4dLqV5g;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(56, 435);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(56, 442);
|
||||
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(35, 30);
|
||||
@@ -182,7 +189,7 @@ namespace WinFormsApp1
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Tractors.Properties.Resources._2EdzyM4iEKw;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(91, 405);
|
||||
this.buttonUp.Location = new System.Drawing.Point(91, 412);
|
||||
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(35, 30);
|
||||
@@ -245,20 +252,66 @@ namespace WinFormsApp1
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 24);
|
||||
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(596, 476);
|
||||
this.pictureBox.Size = new System.Drawing.Size(596, 515);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.файлToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(815, 24);
|
||||
this.menuStrip.TabIndex = 2;
|
||||
this.menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
// файлToolStripMenuItem
|
||||
//
|
||||
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.SaveToolStripMenuItem,
|
||||
this.LoadToolStripMenuItem});
|
||||
this.файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
this.файлToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
|
||||
this.файлToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.SaveToolStripMenuItem.Text = "Сохранение";
|
||||
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.LoadToolStripMenuItem.Text = "Загрузка";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.FileName = "openFileDialog1";
|
||||
this.openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
//
|
||||
// FormMapWithSetTraktor
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(815, 476);
|
||||
this.ClientSize = new System.Drawing.Size(815, 538);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "FormMapWithSetTraktor";
|
||||
this.Text = "Автобус";
|
||||
@@ -267,7 +320,10 @@ namespace WinFormsApp1
|
||||
this.groupBoxMaps.ResumeLayout(false);
|
||||
this.groupBoxMaps.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
@@ -290,5 +346,11 @@ namespace WinFormsApp1
|
||||
private Button buttonAddMap;
|
||||
private TextBox textBoxNewMapName;
|
||||
private ListBox listBoxMaps;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem файлToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@@ -23,16 +24,22 @@ namespace WinFormsApp1
|
||||
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
|
||||
public FormMapWithSetTraktor()
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public FormMapWithSetTraktor(ILogger<FormMapWithSetTraktor> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
foreach (var item in _mapsDict)
|
||||
{
|
||||
comboBoxSelectorMap.Items.Add(item.Key);
|
||||
}
|
||||
}
|
||||
|
||||
public FormMapWithSetTraktor()
|
||||
{
|
||||
}
|
||||
|
||||
private void ReloadMaps()
|
||||
@@ -81,31 +88,42 @@ namespace WinFormsApp1
|
||||
|
||||
private void ButtonAddTraktor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
var formBusConfig = new FormTraktorConfig();
|
||||
formBusConfig.AddEvent(AddTraktor);
|
||||
formBusConfig.Show();
|
||||
}
|
||||
|
||||
private void AddTraktor(TractorDraw traktor)
|
||||
{
|
||||
try
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormTractor form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.SelectedTractor == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Сначала создайте объект");
|
||||
return;
|
||||
}
|
||||
|
||||
DrawningObjectTractor bus = new(form.SelectedTractor);
|
||||
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + bus != -1)
|
||||
DrawningObjectTractor boat = new(traktor);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat >= 0)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
_logger.LogInformation("Объект добавлен");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogInformation("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
_logger.LogWarning($"Ошибка, переполнение хранилища: {0}", ex.Message);
|
||||
MessageBox.Show($"Ошибка, хранилище переполнено: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
_logger.LogWarning("Ошибка добавления");
|
||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemoveTraktor_Click(object sender, EventArgs e)
|
||||
@@ -127,15 +145,30 @@ namespace WinFormsApp1
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
var deletedTraktor = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
|
||||
if (deletedTraktor != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
_logger.LogInformation("Из текущей карты удален объект {@traktor}", deletedTraktor);
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Не удалось добавить объект по позиции {0} равен null", pos);
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
catch (TraktorNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
_logger.LogWarning("Ошибка удаления: {0}", ex.Message);
|
||||
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Неизвестная ошибка удаления: {0}", ex.Message);
|
||||
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,20 +222,24 @@ namespace WinFormsApp1
|
||||
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogInformation("При добавлении карты {0}", comboBoxSelectorMap.SelectedIndex == -1 ? "Не была выбрана карта" : "Не была названа карта");
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||
{
|
||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogInformation("При добавлении карты {0}", comboBoxSelectorMap.SelectedIndex == -1 ? "Не была выбрана карта" : "Не была названа карта");
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||
ReloadMaps();
|
||||
_logger.LogInformation("Добавлена карта {0}", textBoxNewMapName.Text);
|
||||
}
|
||||
|
||||
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
_logger.LogInformation("Осуществлён переход на карту под названием {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
}
|
||||
|
||||
private void buttonDeleteMap_Click(object sender, EventArgs e)
|
||||
@@ -216,6 +253,44 @@ namespace WinFormsApp1
|
||||
{
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
ReloadMaps();
|
||||
_logger.LogInformation("Удалена карта {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
_logger.LogInformation("Загрузка данных из файла '{0}' прошла успешно", openFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogInformation("Не удалось загрузить файл '{0}'. Текст ошибки: {1}", openFileDialog.FileName, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка данных прошла успешно", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadMaps();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,10 +82,6 @@ namespace WinFormsApp1
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
@@ -103,7 +99,7 @@ namespace WinFormsApp1
|
||||
dopColor = dialogDop.Color;
|
||||
}
|
||||
|
||||
_Tractor = new MultiTraktorDraw(random.Next(100, 300), random.Next(1000, 2000), color, dopColor);
|
||||
_Tractor = new MultiTraktorDraw(random.Next(100, 300), random.Next(1000, 2000), color, dopColor, true, true);
|
||||
|
||||
SetData();
|
||||
Draw();
|
||||
|
||||
358
WinFormsApp1/FormTraktorConfig.Designer.cs
generated
Normal file
358
WinFormsApp1/FormTraktorConfig.Designer.cs
generated
Normal file
@@ -0,0 +1,358 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
partial class FormTraktorConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBoxConfig = new System.Windows.Forms.GroupBox();
|
||||
this.labelHardObject = new System.Windows.Forms.Label();
|
||||
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||
this.groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||
this.panelPurple = new System.Windows.Forms.Panel();
|
||||
this.panelBlack = new System.Windows.Forms.Panel();
|
||||
this.panelYellow = new System.Windows.Forms.Panel();
|
||||
this.panelGray = new System.Windows.Forms.Panel();
|
||||
this.panelBlue = new System.Windows.Forms.Panel();
|
||||
this.panelWhite = new System.Windows.Forms.Panel();
|
||||
this.panelGreen = new System.Windows.Forms.Panel();
|
||||
this.panelRed = new System.Windows.Forms.Panel();
|
||||
this.checkBoxBehind = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxAhead = new System.Windows.Forms.CheckBox();
|
||||
this.labelWeight = new System.Windows.Forms.Label();
|
||||
this.labelSpeed = new System.Windows.Forms.Label();
|
||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.labelDopColor = new System.Windows.Forms.Label();
|
||||
this.labelColor = new System.Windows.Forms.Label();
|
||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.groupBoxConfig.SuspendLayout();
|
||||
this.groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||
this.panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxConfig
|
||||
//
|
||||
this.groupBoxConfig.Controls.Add(this.labelHardObject);
|
||||
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
|
||||
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
|
||||
this.groupBoxConfig.Controls.Add(this.checkBoxBehind);
|
||||
this.groupBoxConfig.Controls.Add(this.checkBoxAhead);
|
||||
this.groupBoxConfig.Controls.Add(this.labelWeight);
|
||||
this.groupBoxConfig.Controls.Add(this.labelSpeed);
|
||||
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
|
||||
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
|
||||
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBoxConfig.Name = "groupBoxConfig";
|
||||
this.groupBoxConfig.Size = new System.Drawing.Size(423, 197);
|
||||
this.groupBoxConfig.TabIndex = 0;
|
||||
this.groupBoxConfig.TabStop = false;
|
||||
this.groupBoxConfig.Text = "Параметры";
|
||||
//
|
||||
// labelHardObject
|
||||
//
|
||||
this.labelHardObject.AllowDrop = true;
|
||||
this.labelHardObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelHardObject.Location = new System.Drawing.Point(314, 127);
|
||||
this.labelHardObject.Name = "labelHardObject";
|
||||
this.labelHardObject.Size = new System.Drawing.Size(94, 40);
|
||||
this.labelHardObject.TabIndex = 8;
|
||||
this.labelHardObject.Text = "Продвинутый";
|
||||
this.labelHardObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelHardObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
this.labelSimpleObject.AllowDrop = true;
|
||||
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelSimpleObject.Location = new System.Drawing.Point(238, 127);
|
||||
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||
this.labelSimpleObject.Size = new System.Drawing.Size(70, 40);
|
||||
this.labelSimpleObject.TabIndex = 7;
|
||||
this.labelSimpleObject.Text = "Простой";
|
||||
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
|
||||
//
|
||||
// groupBoxColors
|
||||
//
|
||||
this.groupBoxColors.Controls.Add(this.panelPurple);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlack);
|
||||
this.groupBoxColors.Controls.Add(this.panelYellow);
|
||||
this.groupBoxColors.Controls.Add(this.panelGray);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlue);
|
||||
this.groupBoxColors.Controls.Add(this.panelWhite);
|
||||
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||
this.groupBoxColors.Location = new System.Drawing.Point(238, 22);
|
||||
this.groupBoxColors.Name = "groupBoxColors";
|
||||
this.groupBoxColors.Size = new System.Drawing.Size(170, 102);
|
||||
this.groupBoxColors.TabIndex = 6;
|
||||
this.groupBoxColors.TabStop = false;
|
||||
this.groupBoxColors.Text = "Цвета";
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||
this.panelPurple.Location = new System.Drawing.Point(123, 58);
|
||||
this.panelPurple.Name = "panelPurple";
|
||||
this.panelPurple.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelPurple.TabIndex = 2;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||
this.panelBlack.Location = new System.Drawing.Point(87, 58);
|
||||
this.panelBlack.Name = "panelBlack";
|
||||
this.panelBlack.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelBlack.TabIndex = 1;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||
this.panelYellow.Location = new System.Drawing.Point(123, 22);
|
||||
this.panelYellow.Name = "panelYellow";
|
||||
this.panelYellow.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelYellow.TabIndex = 1;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||
this.panelGray.Location = new System.Drawing.Point(51, 58);
|
||||
this.panelGray.Name = "panelGray";
|
||||
this.panelGray.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelGray.TabIndex = 1;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
this.panelBlue.BackColor = System.Drawing.SystemColors.HotTrack;
|
||||
this.panelBlue.Location = new System.Drawing.Point(87, 22);
|
||||
this.panelBlue.Name = "panelBlue";
|
||||
this.panelBlue.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelBlue.TabIndex = 1;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||
this.panelWhite.Location = new System.Drawing.Point(15, 58);
|
||||
this.panelWhite.Name = "panelWhite";
|
||||
this.panelWhite.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelWhite.TabIndex = 1;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.SeaGreen;
|
||||
this.panelGreen.Location = new System.Drawing.Point(51, 22);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelGreen.TabIndex = 1;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||
this.panelRed.Location = new System.Drawing.Point(15, 22);
|
||||
this.panelRed.Name = "panelRed";
|
||||
this.panelRed.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelRed.TabIndex = 0;
|
||||
//
|
||||
// checkBoxBehind
|
||||
//
|
||||
this.checkBoxBehind.AutoSize = true;
|
||||
this.checkBoxBehind.Location = new System.Drawing.Point(17, 116);
|
||||
this.checkBoxBehind.Name = "checkBoxBehind";
|
||||
this.checkBoxBehind.Size = new System.Drawing.Size(219, 19);
|
||||
this.checkBoxBehind.TabIndex = 5;
|
||||
this.checkBoxBehind.Text = "Признак наличия рыхлителя сзади";
|
||||
this.checkBoxBehind.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxAhead
|
||||
//
|
||||
this.checkBoxAhead.AutoSize = true;
|
||||
this.checkBoxAhead.Location = new System.Drawing.Point(17, 91);
|
||||
this.checkBoxAhead.Name = "checkBoxAhead";
|
||||
this.checkBoxAhead.Size = new System.Drawing.Size(216, 19);
|
||||
this.checkBoxAhead.TabIndex = 4;
|
||||
this.checkBoxAhead.Text = "Прищнак наличия ковша спереди";
|
||||
this.checkBoxAhead.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
this.labelWeight.AutoSize = true;
|
||||
this.labelWeight.Location = new System.Drawing.Point(17, 70);
|
||||
this.labelWeight.Name = "labelWeight";
|
||||
this.labelWeight.Size = new System.Drawing.Size(26, 15);
|
||||
this.labelWeight.TabIndex = 3;
|
||||
this.labelWeight.Text = "Вес";
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
this.labelSpeed.AutoSize = true;
|
||||
this.labelSpeed.Location = new System.Drawing.Point(17, 41);
|
||||
this.labelSpeed.Name = "labelSpeed";
|
||||
this.labelSpeed.Size = new System.Drawing.Size(59, 15);
|
||||
this.labelSpeed.TabIndex = 2;
|
||||
this.labelSpeed.Text = "Скорость";
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
this.numericUpDownWeight.Location = new System.Drawing.Point(82, 62);
|
||||
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
this.numericUpDownWeight.Size = new System.Drawing.Size(120, 23);
|
||||
this.numericUpDownWeight.TabIndex = 1;
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(82, 33);
|
||||
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
this.numericUpDownSpeed.Size = new System.Drawing.Size(120, 23);
|
||||
this.numericUpDownSpeed.TabIndex = 0;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.AllowDrop = true;
|
||||
this.panel1.Controls.Add(this.labelDopColor);
|
||||
this.panel1.Controls.Add(this.labelColor);
|
||||
this.panel1.Controls.Add(this.pictureBoxObject);
|
||||
this.panel1.Location = new System.Drawing.Point(454, 31);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(246, 197);
|
||||
this.panel1.TabIndex = 1;
|
||||
this.panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.Panel1_DragDrop);
|
||||
this.panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.Panel1_DragEnter);
|
||||
//
|
||||
// labelDopColor
|
||||
//
|
||||
this.labelDopColor.AllowDrop = true;
|
||||
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelDopColor.Location = new System.Drawing.Point(88, 8);
|
||||
this.labelDopColor.Name = "labelDopColor";
|
||||
this.labelDopColor.Size = new System.Drawing.Size(78, 29);
|
||||
this.labelDopColor.TabIndex = 10;
|
||||
this.labelDopColor.Text = "Доп. цвет";
|
||||
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
|
||||
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter);
|
||||
//
|
||||
// labelColor
|
||||
//
|
||||
this.labelColor.AllowDrop = true;
|
||||
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelColor.Location = new System.Drawing.Point(12, 8);
|
||||
this.labelColor.Name = "labelColor";
|
||||
this.labelColor.Size = new System.Drawing.Size(70, 29);
|
||||
this.labelColor.TabIndex = 9;
|
||||
this.labelColor.Text = "Цвет";
|
||||
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
|
||||
this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
this.pictureBoxObject.Location = new System.Drawing.Point(12, 43);
|
||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||
this.pictureBoxObject.Size = new System.Drawing.Size(231, 151);
|
||||
this.pictureBoxObject.TabIndex = 0;
|
||||
this.pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(480, 234);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonAdd.TabIndex = 2;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(561, 234);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonCancel.TabIndex = 3;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormTraktorConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(770, 317);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.groupBoxConfig);
|
||||
this.Name = "FormTraktorConfig";
|
||||
this.Text = "FormTraktorConfig";
|
||||
this.groupBoxConfig.ResumeLayout(false);
|
||||
this.groupBoxConfig.PerformLayout();
|
||||
this.groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||
this.panel1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxConfig;
|
||||
private CheckBox checkBoxBehind;
|
||||
private CheckBox checkBoxAhead;
|
||||
private Label labelWeight;
|
||||
private Label labelSpeed;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelHardObject;
|
||||
private Label labelSimpleObject;
|
||||
private GroupBox groupBoxColors;
|
||||
private Panel panelPurple;
|
||||
private Panel panelBlack;
|
||||
private Panel panelYellow;
|
||||
private Panel panelGray;
|
||||
private Panel panelBlue;
|
||||
private Panel panelWhite;
|
||||
private Panel panelGreen;
|
||||
private Panel panelRed;
|
||||
private Panel panel1;
|
||||
private Label labelDopColor;
|
||||
private Label labelColor;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Button buttonAdd;
|
||||
private Button buttonCancel;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
148
WinFormsApp1/FormTraktorConfig.cs
Normal file
148
WinFormsApp1/FormTraktorConfig.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
public partial class FormTraktorConfig : Form
|
||||
{
|
||||
TractorDraw _traktor = null;
|
||||
private event TraktorDelegate EventAddTraktor;
|
||||
|
||||
public FormTraktorConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||
panelGray.MouseDown += PanelColor_MouseDown;
|
||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||
panelRed.MouseDown += PanelColor_MouseDown;
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
buttonCancel.Click += (object sender, EventArgs a) => Close();
|
||||
}
|
||||
|
||||
private void labelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void DrawTraktor()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_traktor?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
_traktor?.DrawEntity(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
|
||||
public void AddEvent(TraktorDelegate ev)
|
||||
{
|
||||
if (EventAddTraktor == null)
|
||||
{
|
||||
EventAddTraktor = new TraktorDelegate(ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddTraktor += ev;
|
||||
}
|
||||
}
|
||||
|
||||
private void Panel1_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void Panel1_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_traktor = new TractorDraw((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, labelColor.BackColor);
|
||||
break;
|
||||
case "labelHardObject":
|
||||
_traktor = new MultiTraktorDraw((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, labelColor.BackColor, labelDopColor.BackColor,
|
||||
checkBoxAhead.Checked, checkBoxBehind.Checked);
|
||||
break;
|
||||
}
|
||||
DrawTraktor();
|
||||
}
|
||||
|
||||
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void LabelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
var color = e.Data.GetData(typeof(Color));
|
||||
if (color != null)
|
||||
{
|
||||
(sender as Label).BackColor = (Color)color;
|
||||
}
|
||||
if (_traktor != null)
|
||||
{
|
||||
_traktor.Tractor.BodyColor = (Color)color;
|
||||
DrawTraktor();
|
||||
}
|
||||
}
|
||||
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_traktor != null && _traktor.Tractor is MultiTraktor entityBulldozer)
|
||||
{
|
||||
entityBulldozer.DopColor = (Color)e.Data.GetData(typeof(Color));
|
||||
|
||||
DrawTraktor();
|
||||
}
|
||||
}
|
||||
|
||||
private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddTraktor?.Invoke(_traktor);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
120
WinFormsApp1/FormTraktorConfig.resx
Normal file
120
WinFormsApp1/FormTraktorConfig.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -25,5 +25,7 @@ namespace WinFormsApp1
|
||||
void DrawningObject(Graphics g);
|
||||
/// Получение текущей позиции объекта
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
|
||||
string GetInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ namespace WinFormsApp1
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public static int operator +(MapWithSetTraktorGeneric<T, U> map, T bus)
|
||||
public static int operator +(MapWithSetTraktorGeneric<T, U> map, T traktor)
|
||||
{
|
||||
return map._setTraktors.Insert(bus);
|
||||
return map._setTraktors.Insert(traktor);
|
||||
}
|
||||
|
||||
public static T operator -(MapWithSetTraktorGeneric<T, U> map, int position)
|
||||
@@ -75,10 +75,10 @@ namespace WinFormsApp1
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var bus = _setTraktors[j];
|
||||
if (bus != null)
|
||||
var traktor = _setTraktors[j];
|
||||
if (traktor != null)
|
||||
{
|
||||
_setTraktors.Insert(bus, i);
|
||||
_setTraktors.Insert(traktor, i);
|
||||
_setTraktors.Remove(j);
|
||||
break;
|
||||
}
|
||||
@@ -109,31 +109,48 @@ namespace WinFormsApp1
|
||||
|
||||
private void DrawTraktors(Graphics g)
|
||||
{
|
||||
|
||||
|
||||
|
||||
int currentWidth = _pictureWidth / _placeSizeWidth - 1;
|
||||
int currentHeight = _pictureHeight / _placeSizeHeight - 1;
|
||||
|
||||
int widthEl = _pictureWidth / _placeSizeWidth;
|
||||
int heightEl = _pictureHeight / _placeSizeHeight;
|
||||
int curWidth = 1;
|
||||
int curHeight = 0;
|
||||
foreach (var traktor in _setTraktors.GetTraktor())
|
||||
{
|
||||
traktor?.SetObject(
|
||||
currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
traktor?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 130,
|
||||
curHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight);
|
||||
traktor?.DrawningObject(g);
|
||||
|
||||
if (currentWidth > 0)
|
||||
{
|
||||
currentWidth -= 1;
|
||||
}
|
||||
if (curWidth < widthEl)
|
||||
curWidth++;
|
||||
else
|
||||
{
|
||||
if (currentHeight > 0)
|
||||
{
|
||||
currentHeight -= 1;
|
||||
currentWidth = _pictureWidth / _placeSizeWidth - 1;
|
||||
}
|
||||
else return;
|
||||
curWidth = 1;
|
||||
curHeight++;
|
||||
}
|
||||
if (curHeight > heightEl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetData(char separatorType, char separatorData)
|
||||
{
|
||||
string data = $"{_map.GetType().Name}{separatorType}";
|
||||
foreach (var traktor in _setTraktors.GetTraktor())
|
||||
{
|
||||
data += $"{traktor.GetInfo()}{separatorData}";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public void LoadData(string[] records)
|
||||
{
|
||||
foreach (var rec in records)
|
||||
{
|
||||
_setTraktors.Insert(DrawningObjectTractor.Create(rec) as T);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -8,7 +9,7 @@ namespace WinFormsApp1
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
readonly Dictionary<string, MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>> _mapStorages;
|
||||
readonly Dictionary<string, MapWithSetTraktorGeneric<IDrawningObject, AbstractMap>> _mapStorages;
|
||||
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
|
||||
@@ -16,9 +17,13 @@ namespace WinFormsApp1
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
private readonly char separatorDict = '|';
|
||||
|
||||
private readonly char separatorData = ';';
|
||||
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>>();
|
||||
_mapStorages = new Dictionary<string, MapWithSetTraktorGeneric<IDrawningObject, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@@ -28,7 +33,7 @@ namespace WinFormsApp1
|
||||
if (_mapStorages.ContainsKey(name)) return; //уникальное имя
|
||||
else
|
||||
{
|
||||
_mapStorages.Add(name, new MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages.Add(name, new MapWithSetTraktorGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,14 +45,70 @@ namespace WinFormsApp1
|
||||
}
|
||||
}
|
||||
|
||||
public MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> this[string ind]
|
||||
public MapWithSetTraktorGeneric<IDrawningObject, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
_mapStorages.TryGetValue(ind, out var MapWithSetDoubleDeckerBusGeneric);
|
||||
return MapWithSetDoubleDeckerBusGeneric;
|
||||
_mapStorages.TryGetValue(ind, out var result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
private static void WriteToFile(string text, FileStream stream)
|
||||
{
|
||||
byte[] info = new UTF8Encoding(true).GetBytes(text);
|
||||
stream.Write(info, 0, info.Length);
|
||||
}
|
||||
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
using (StreamWriter fs = new(filename))
|
||||
{
|
||||
fs.Write($"MapsCollection{Environment.NewLine}");
|
||||
foreach (var storage in _mapStorages)
|
||||
{
|
||||
fs.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
string str = "";
|
||||
if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new FileFormatException("Формат данных в файле неправильный");
|
||||
}
|
||||
//очищаем записи
|
||||
_mapStorages.Clear();
|
||||
while ((str = sr.ReadLine()) != null)
|
||||
{
|
||||
var elem = str.Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Поле":
|
||||
map = new FieldMap();
|
||||
break;
|
||||
}
|
||||
_mapStorages.Add(elem[0], new MapWithSetTraktorGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,14 @@ namespace WinFormsApp1
|
||||
{
|
||||
internal class MultiTraktor : EntityTractor
|
||||
{
|
||||
public Color DopColor { get; private set; }
|
||||
/// Инициализация свойств
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес трактора</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
public MultiTraktor(int speed, float weight, Color bodyColor, Color dopColor) : base(speed, weight, bodyColor)
|
||||
public Color DopColor { get; set; }
|
||||
public bool dopAhead { get; private set; }
|
||||
public bool dopBehind { get; private set; }
|
||||
public MultiTraktor(int speed, float weight, Color bodyColor, Color dopColor, bool dopahead, bool dopbehind) : base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
dopAhead = dopahead;
|
||||
dopBehind = dopbehind;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,16 +7,14 @@ namespace WinFormsApp1
|
||||
{
|
||||
class MultiTraktorDraw : TractorDraw
|
||||
{
|
||||
/// Инициализация свойств
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес трактора</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="trktrWidth">Ширина отрисовки автомобиля</param>
|
||||
/// <param name="trktrHeight">Высота отрисовки автомобиля</param>
|
||||
public MultiTraktorDraw(int speed, float weight, Color bodyColor, Color dopColor) : base(speed, weight, bodyColor, 188, 100)
|
||||
public void SetDopColor(Color color)
|
||||
{
|
||||
Tractor = new MultiTraktor(speed, weight, bodyColor, dopColor);
|
||||
((MultiTraktor)Tractor).DopColor = color;
|
||||
}
|
||||
|
||||
public MultiTraktorDraw(int speed, float weight, Color bodyColor, Color dopColor, bool dopahead, bool dopbehind) : base(speed, weight, bodyColor, 188, 100)
|
||||
{
|
||||
Tractor = new MultiTraktor(speed, weight, bodyColor, dopColor, dopahead, dopbehind);
|
||||
}
|
||||
|
||||
public override void DrawEntity(Graphics g)
|
||||
@@ -25,6 +23,10 @@ namespace WinFormsApp1
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!DrawCheck())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen_Black_1pxl = new Pen(Color.Black, 1);
|
||||
Pen pen_Black_2pxl = new Pen(Color.Black, 2);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
@@ -38,48 +40,54 @@ namespace WinFormsApp1
|
||||
g.DrawRectangle(pen_Black_1pxl, startPosX, startPosY + 8, 4, 35);
|
||||
g.DrawRectangle(pen_Black_1pxl, startPosX + 33, startPosY + 34, 10, 15);
|
||||
|
||||
point1 = new PointF(startPosX, startPosY + 8);
|
||||
point2 = new PointF(startPosX + 33, startPosY + 41);
|
||||
point3 = new PointF(startPosX + 33, startPosY + 34);
|
||||
point4 = new PointF(startPosX + 7, startPosY + 8);
|
||||
PointF[] curvePoints =
|
||||
if (multiTraktor.dopBehind)
|
||||
{
|
||||
point1 = new PointF(startPosX, startPosY + 8);
|
||||
point2 = new PointF(startPosX + 33, startPosY + 41);
|
||||
point3 = new PointF(startPosX + 33, startPosY + 34);
|
||||
point4 = new PointF(startPosX + 7, startPosY + 8);
|
||||
PointF[] curvePoints =
|
||||
{
|
||||
point1,
|
||||
point2,
|
||||
point3,
|
||||
point4
|
||||
};
|
||||
g.FillPolygon(dopBrush, curvePoints);
|
||||
g.DrawPolygon(pen_Black_1pxl, curvePoints);
|
||||
g.FillPolygon(dopBrush, curvePoints);
|
||||
g.DrawPolygon(pen_Black_1pxl, curvePoints);
|
||||
|
||||
point1 = new PointF(startPosX + 6, startPosY + 8 + 15);
|
||||
point2 = new PointF(startPosX + 6, startPosY + 8 + 35);
|
||||
point3 = new PointF(startPosX + 26, startPosY + 8 + 35);
|
||||
PointF[] curvePoints2 =
|
||||
{
|
||||
point1 = new PointF(startPosX + 6, startPosY + 8 + 15);
|
||||
point2 = new PointF(startPosX + 6, startPosY + 8 + 35);
|
||||
point3 = new PointF(startPosX + 26, startPosY + 8 + 35);
|
||||
PointF[] curvePoints2 =
|
||||
{
|
||||
point1,
|
||||
point2,
|
||||
point3
|
||||
};
|
||||
g.FillPolygon(dopBrush, curvePoints2);
|
||||
g.DrawPolygon(pen_Black_1pxl, curvePoints2);
|
||||
g.FillPolygon(dopBrush, curvePoints2);
|
||||
g.DrawPolygon(pen_Black_1pxl, curvePoints2);
|
||||
}
|
||||
|
||||
startPosX += 43;
|
||||
base.DrawEntity(g);
|
||||
startPosX -= 43;
|
||||
|
||||
point1 = new PointF(startPosX + 43 + 102, startPosY + 30);
|
||||
point2 = new PointF(startPosX + 43 + 102, startPosY + 65);
|
||||
point3 = new PointF(startPosX + 43 + 137, startPosY + 65);
|
||||
|
||||
PointF[] curvePoints3 =
|
||||
if (multiTraktor.dopAhead)
|
||||
{
|
||||
point1 = new PointF(startPosX + 43 + 102, startPosY + 30);
|
||||
point2 = new PointF(startPosX + 43 + 102, startPosY + 65);
|
||||
point3 = new PointF(startPosX + 43 + 137, startPosY + 65);
|
||||
|
||||
PointF[] curvePoints3 =
|
||||
{
|
||||
point1,
|
||||
point2,
|
||||
point3
|
||||
};
|
||||
g.FillPolygon(dopBrush, curvePoints3);
|
||||
g.DrawPolygon(pen_Black_1pxl, curvePoints3);
|
||||
g.FillPolygon(dopBrush, curvePoints3);
|
||||
g.DrawPolygon(pen_Black_1pxl, curvePoints3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
@@ -14,10 +19,30 @@ namespace WinFormsApp1
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormMapWithSetTraktor());
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetTraktor>());
|
||||
}
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormMapWithSetTraktor>()
|
||||
.AddLogging(option =>
|
||||
{
|
||||
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: "appsettings.json").Build();
|
||||
|
||||
var logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.CreateLogger();
|
||||
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(logger);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,15 +27,20 @@ namespace WinFormsApp1
|
||||
|
||||
public int Insert(T tractor, int position)
|
||||
{
|
||||
if (position < 0 && position > _maxCount)
|
||||
if (position > _maxCount && position < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
if (_places.Contains(tractor))
|
||||
{
|
||||
_places.Insert(position, tractor);
|
||||
return position;
|
||||
throw new ArgumentException($"Объект {tractor} уже есть в наборе");
|
||||
}
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
_places.Insert(position, tractor);
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
|
||||
23
WinFormsApp1/StoreageOverflowException.cs
Normal file
23
WinFormsApp1/StoreageOverflowException.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
[Serializable]
|
||||
class StorageOverflowException : ApplicationException
|
||||
{
|
||||
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||
|
||||
public StorageOverflowException() : base() { }
|
||||
|
||||
public StorageOverflowException(string message) : base(message) { }
|
||||
|
||||
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
||||
@@ -90,38 +90,19 @@ namespace WinFormsApp1
|
||||
startPosY -= Tractor.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.DRDiagonal:
|
||||
if (startPosX + entWidth + Tractor.Step < pictureWidth && startPosY + entHeight + Tractor.Step < pictureHeight)
|
||||
{
|
||||
startPosX += Tractor.Step;
|
||||
startPosY += Tractor.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.DLDiagonal:
|
||||
if (startPosY + entHeight + Tractor.Step < pictureHeight && startPosX - 10 - Tractor.Step > 0)
|
||||
{
|
||||
startPosY += Tractor.Step;
|
||||
startPosX -= Tractor.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.URDiagonal:
|
||||
if (startPosY - Tractor.Step > 0 && startPosX + entWidth + Tractor.Step < pictureWidth)
|
||||
{
|
||||
startPosY -= Tractor.Step;
|
||||
startPosX += Tractor.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.ULDiagonal:
|
||||
if (startPosY - Tractor.Step > 0 && startPosX - 10 - Tractor.Step > 0)
|
||||
{
|
||||
startPosY -= Tractor.Step;
|
||||
startPosX -= Tractor.Step;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public bool DrawCheck()
|
||||
{
|
||||
if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//Отрисовка сущности
|
||||
public virtual void DrawEntity(Graphics g)
|
||||
{
|
||||
|
||||
@@ -3,9 +3,36 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.0" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.LoggerConfiguration.ConditionExtensions" Version="1.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
10
WinFormsApp1/TraktorDelgete.cs
Normal file
10
WinFormsApp1/TraktorDelgete.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
public delegate void TraktorDelegate(TractorDraw traktor);
|
||||
}
|
||||
22
WinFormsApp1/TraktorNotFoundExeption.cs
Normal file
22
WinFormsApp1/TraktorNotFoundExeption.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
internal class TraktorNotFoundException : ApplicationException
|
||||
{
|
||||
public TraktorNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
|
||||
public TraktorNotFoundException() : base() { }
|
||||
|
||||
public TraktorNotFoundException(string message) : base(message) { }
|
||||
|
||||
public TraktorNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected TraktorNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
||||
19
WinFormsApp1/appsettings.json
Normal file
19
WinFormsApp1/appsettings.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"outputTemplate": "{Timestamp:HH:mm:ss. zzz} [{Level}] {Message} {Exception} {NewLine}",
|
||||
"path": "D:/log.txt",
|
||||
"fileSizeLimitBytes": 2147483648
|
||||
}
|
||||
}
|
||||
],
|
||||
"Properties": {
|
||||
"Application": "Serilog-Demo"
|
||||
}
|
||||
}
|
||||
}
|
||||
13
WinFormsApp1/nlog.config
Normal file
13
WinFormsApp1/nlog.config
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload ="true" internalLogLevel ="Info">
|
||||
<targets>
|
||||
<target xsi:type="File" name ="tofile" fileName ="tankerlog-${shortdate}.log"/>
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name ="*" minlevel ="Debug" writeTo ="toFile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user