9 Commits
Lab04 ... Lab06

18 changed files with 1183 additions and 27 deletions

View File

@@ -6,6 +6,10 @@
public int WheelsNum public int WheelsNum
{ {
get
{
return (int)wheelsNumber;
}
set set
{ {
if (value < 2 || value > 4) if (value < 2 || value > 4)

View File

@@ -30,6 +30,7 @@
{ {
_locomotive.DrawTransport(g); _locomotive.DrawTransport(g);
} }
public string GetInfo() => _locomotive?.GetDataForSave();
public static IDrawningObject Create(string data) => new DrawningObjectLocomotive(data.CreateDrawningLocomotive());
} }
} }

View File

@@ -6,6 +6,10 @@
public int WheelsNum public int WheelsNum
{ {
get
{
return (int)wheelsNumber;
}
set set
{ {
if (value < 2 || value > 4) if (value < 2 || value > 4)

View File

@@ -6,6 +6,10 @@
public int WheelsNum public int WheelsNum
{ {
get
{
return (int)wheelsNumber;
}
set set
{ {
if (value < 2 || value > 4) if (value < 2 || value > 4)

View File

@@ -16,7 +16,7 @@
/// <summary> /// <summary>
/// Цвет кузова /// Цвет кузова
/// </summary> /// </summary>
public Color BodyColor { get; private set; } public Color BodyColor { get; set; }
/// <summary> /// <summary>
/// Шаг перемещения /// Шаг перемещения
/// </summary> /// </summary>

View File

@@ -8,7 +8,7 @@
/// <summary> /// <summary>
/// Дополнительный цвет /// Дополнительный цвет
/// </summary> /// </summary>
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; set; }
/// <summary> /// <summary>
/// Признак наличия трубы /// Признак наличия трубы
/// </summary> /// </summary>

View File

@@ -0,0 +1,64 @@
namespace WarmlyLocomotove
{
/// <summary>
/// Расширение для класса DrawningLocomotive
/// </summary>
internal static class ExtentionLocomotive
{
/// <summary>
/// Разделитель для записи информации
/// </summary>
private static readonly char _separatorForObject = ':';
/// <summary>
/// Получаем данные для сохранения в файл
/// </summary>
/// <param name="drawningLocomotive"></param>
/// <returns></returns>
public static string GetDataForSave(this DrawningLocomotive drawningLocomotive)
{
var locomotive = drawningLocomotive.Locomotive;
var str = $"{locomotive.Speed}{_separatorForObject}{locomotive.Weight}{_separatorForObject}{locomotive.BodyColor.Name}{_separatorForObject}{drawningLocomotive.AdditionalElements.WheelsNum}{_separatorForObject}{drawningLocomotive.AdditionalElements.GetType().Name}";
if (locomotive is not EntityWarmlyLocomotive warmlyLocomotive)
{
return str;
}
return $"{str}{_separatorForObject}{warmlyLocomotive.AdditionalColor.Name}{_separatorForObject}{warmlyLocomotive.HasPipe}{_separatorForObject}{warmlyLocomotive.HasFuelTank}";
}
/// <summary>
/// Восстанавливаем объект по полученной из файла информации
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public static DrawningLocomotive CreateDrawningLocomotive(this string info)
{
string[] strs = info.Split(_separatorForObject);
DrawningLocomotive recreatedLocomotive = null;
if (strs.Length == 5)
{
recreatedLocomotive = new DrawningLocomotive(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
if (strs.Length == 8)
{
recreatedLocomotive = new DrawningWarmlyLocomotive
(
Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), 160, 85,
Color.FromName(strs[5]), Convert.ToBoolean(strs[6]), Convert.ToBoolean(strs[7])
);
}
switch (strs[4])
{
case "DrawningWheels":
recreatedLocomotive.AdditionalElements = new DrawningWheels();
break;
case "DrawningRectOrnament":
recreatedLocomotive.AdditionalElements = new DrawningRectOrnament();
break;
case "DrawningEllipseOrnament":
recreatedLocomotive.AdditionalElements = new DrawningEllipseOrnament();
break;
}
recreatedLocomotive.AdditionalElements.WheelsNum = Convert.ToInt32(strs[3]);
return recreatedLocomotive;
}
}
}

View File

@@ -0,0 +1,471 @@
namespace WarmlyLocomotove
{
partial class FormLocomotiveConfig
{
/// <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.labelWheelsNumber = new System.Windows.Forms.Label();
this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOk = new System.Windows.Forms.Button();
this.panelObject = new System.Windows.Forms.Panel();
this.labelAdditionalColor = new System.Windows.Forms.Label();
this.labelColor = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.labelModifiedObject = new System.Windows.Forms.Label();
this.labelRectOrnament = new System.Windows.Forms.Label();
this.labelEllipseOrnament = new System.Windows.Forms.Label();
this.labelNoOrnament = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelAqua = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelPink = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.checkBoxHasFuelTank = new System.Windows.Forms.CheckBox();
this.checkBoxHasPipe = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.labelWeight = new System.Windows.Forms.Label();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelSpeed = new System.Windows.Forms.Label();
this.groupBoxConfig.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit();
this.panelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.SuspendLayout();
//
// groupBoxConfig
//
this.groupBoxConfig.Controls.Add(this.labelWheelsNumber);
this.groupBoxConfig.Controls.Add(this.numericUpDownWheelsNumber);
this.groupBoxConfig.Controls.Add(this.buttonCancel);
this.groupBoxConfig.Controls.Add(this.buttonOk);
this.groupBoxConfig.Controls.Add(this.panelObject);
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
this.groupBoxConfig.Controls.Add(this.labelRectOrnament);
this.groupBoxConfig.Controls.Add(this.labelEllipseOrnament);
this.groupBoxConfig.Controls.Add(this.labelNoOrnament);
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
this.groupBoxConfig.Controls.Add(this.checkBoxHasFuelTank);
this.groupBoxConfig.Controls.Add(this.checkBoxHasPipe);
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
this.groupBoxConfig.Controls.Add(this.labelWeight);
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
this.groupBoxConfig.Controls.Add(this.labelSpeed);
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Size = new System.Drawing.Size(674, 337);
this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Параметры";
//
// labelWheelsNumber
//
this.labelWheelsNumber.AutoSize = true;
this.labelWheelsNumber.Location = new System.Drawing.Point(233, 195);
this.labelWheelsNumber.Name = "labelWheelsNumber";
this.labelWheelsNumber.Size = new System.Drawing.Size(107, 15);
this.labelWheelsNumber.TabIndex = 1;
this.labelWheelsNumber.Text = "Количество колёс";
//
// numericUpDownWheelsNumber
//
this.numericUpDownWheelsNumber.Location = new System.Drawing.Point(200, 193);
this.numericUpDownWheelsNumber.Maximum = new decimal(new int[] {
4,
0,
0,
0});
this.numericUpDownWheelsNumber.Minimum = new decimal(new int[] {
2,
0,
0,
0});
this.numericUpDownWheelsNumber.Name = "numericUpDownWheelsNumber";
this.numericUpDownWheelsNumber.Size = new System.Drawing.Size(27, 23);
this.numericUpDownWheelsNumber.TabIndex = 1;
this.numericUpDownWheelsNumber.Value = new decimal(new int[] {
2,
0,
0,
0});
this.numericUpDownWheelsNumber.ValueChanged += new System.EventHandler(this.NumericUpDownWheelsNumber_ValueChanged);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(544, 193);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(118, 32);
this.buttonCancel.TabIndex = 11;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(404, 192);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(118, 32);
this.buttonOk.TabIndex = 10;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.labelAdditionalColor);
this.panelObject.Controls.Add(this.labelColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(404, 22);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(261, 164);
this.panelObject.TabIndex = 9;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// labelAdditionalColor
//
this.labelAdditionalColor.AllowDrop = true;
this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAdditionalColor.Location = new System.Drawing.Point(138, 8);
this.labelAdditionalColor.Name = "labelAdditionalColor";
this.labelAdditionalColor.Size = new System.Drawing.Size(120, 45);
this.labelAdditionalColor.TabIndex = 11;
this.labelAdditionalColor.Text = "Доп. цвет";
this.labelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelAdditionalColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAdditionalColor_DragDrop);
this.labelAdditionalColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// labelColor
//
this.labelColor.AllowDrop = true;
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelColor.Location = new System.Drawing.Point(3, 8);
this.labelColor.Name = "labelColor";
this.labelColor.Size = new System.Drawing.Size(115, 45);
this.labelColor.TabIndex = 10;
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(3, 56);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(254, 105);
this.pictureBoxObject.TabIndex = 1;
this.pictureBoxObject.TabStop = false;
//
// labelModifiedObject
//
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifiedObject.Location = new System.Drawing.Point(302, 141);
this.labelModifiedObject.Name = "labelModifiedObject";
this.labelModifiedObject.Size = new System.Drawing.Size(96, 45);
this.labelModifiedObject.TabIndex = 8;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelRectOrnament
//
this.labelRectOrnament.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelRectOrnament.Location = new System.Drawing.Point(6, 168);
this.labelRectOrnament.Name = "labelRectOrnament";
this.labelRectOrnament.Size = new System.Drawing.Size(188, 27);
this.labelRectOrnament.TabIndex = 7;
this.labelRectOrnament.Text = "Прямоугольный орнамент";
this.labelRectOrnament.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelRectOrnament.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelOrnament_MouseDown);
//
// labelEllipseOrnament
//
this.labelEllipseOrnament.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelEllipseOrnament.Location = new System.Drawing.Point(6, 195);
this.labelEllipseOrnament.Name = "labelEllipseOrnament";
this.labelEllipseOrnament.Size = new System.Drawing.Size(188, 27);
this.labelEllipseOrnament.TabIndex = 7;
this.labelEllipseOrnament.Text = "Круглый орнамент";
this.labelEllipseOrnament.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelEllipseOrnament.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelOrnament_MouseDown);
//
// labelNoOrnament
//
this.labelNoOrnament.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelNoOrnament.Location = new System.Drawing.Point(6, 141);
this.labelNoOrnament.Name = "labelNoOrnament";
this.labelNoOrnament.Size = new System.Drawing.Size(188, 27);
this.labelNoOrnament.TabIndex = 7;
this.labelNoOrnament.Text = "Без орнамента";
this.labelNoOrnament.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelNoOrnament.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelOrnament_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(200, 141);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(96, 45);
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.panelBlack);
this.groupBoxColors.Controls.Add(this.panelAqua);
this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Controls.Add(this.panelWhite);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelPink);
this.groupBoxColors.Controls.Add(this.panelYellow);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Location = new System.Drawing.Point(200, 22);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(198, 116);
this.groupBoxColors.TabIndex = 6;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelBlack.Location = new System.Drawing.Point(129, 63);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(35, 35);
this.panelBlack.TabIndex = 3;
//
// panelAqua
//
this.panelAqua.BackColor = System.Drawing.Color.Aqua;
this.panelAqua.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelAqua.Location = new System.Drawing.Point(88, 63);
this.panelAqua.Name = "panelAqua";
this.panelAqua.Size = new System.Drawing.Size(35, 35);
this.panelAqua.TabIndex = 3;
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelRed.Location = new System.Drawing.Point(129, 22);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(35, 35);
this.panelRed.TabIndex = 2;
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelWhite.Location = new System.Drawing.Point(47, 63);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(35, 35);
this.panelWhite.TabIndex = 1;
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelGreen.Location = new System.Drawing.Point(47, 22);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(35, 35);
this.panelGreen.TabIndex = 1;
//
// panelPink
//
this.panelPink.BackColor = System.Drawing.Color.Pink;
this.panelPink.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelPink.Location = new System.Drawing.Point(88, 22);
this.panelPink.Name = "panelPink";
this.panelPink.Size = new System.Drawing.Size(35, 35);
this.panelPink.TabIndex = 2;
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelYellow.Location = new System.Drawing.Point(6, 63);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(35, 35);
this.panelYellow.TabIndex = 1;
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelBlue.Location = new System.Drawing.Point(6, 22);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(35, 35);
this.panelBlue.TabIndex = 0;
//
// checkBoxHasFuelTank
//
this.checkBoxHasFuelTank.AutoSize = true;
this.checkBoxHasFuelTank.Location = new System.Drawing.Point(23, 119);
this.checkBoxHasFuelTank.Name = "checkBoxHasFuelTank";
this.checkBoxHasFuelTank.Size = new System.Drawing.Size(171, 19);
this.checkBoxHasFuelTank.TabIndex = 5;
this.checkBoxHasFuelTank.Text = "Наличие топливного бака";
this.checkBoxHasFuelTank.UseVisualStyleBackColor = true;
//
// checkBoxHasPipe
//
this.checkBoxHasPipe.AutoSize = true;
this.checkBoxHasPipe.Location = new System.Drawing.Point(23, 94);
this.checkBoxHasPipe.Name = "checkBoxHasPipe";
this.checkBoxHasPipe.Size = new System.Drawing.Size(112, 19);
this.checkBoxHasPipe.TabIndex = 4;
this.checkBoxHasPipe.Text = "Наличие трубы";
this.checkBoxHasPipe.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(88, 65);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
2000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(56, 23);
this.numericUpDownWeight.TabIndex = 3;
this.numericUpDownWeight.Value = new decimal(new int[] {
1000,
0,
0,
0});
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(23, 67);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(26, 15);
this.labelWeight.TabIndex = 2;
this.labelWeight.Text = "Вес";
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(88, 34);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
200,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(56, 23);
this.numericUpDownSpeed.TabIndex = 1;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(23, 36);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(59, 15);
this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = "Скорость";
//
// FormLocomotiveConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(693, 246);
this.Controls.Add(this.groupBoxConfig);
this.Name = "FormLocomotiveConfig";
this.Text = "Создание объекта";
this.groupBoxConfig.ResumeLayout(false);
this.groupBoxConfig.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit();
this.panelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private CheckBox checkBoxHasFuelTank;
private CheckBox checkBoxHasPipe;
private NumericUpDown numericUpDownWeight;
private Label labelWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelSpeed;
private Label labelModifiedObject;
private Label labelSimpleObject;
private GroupBox groupBoxColors;
private Panel panelBlack;
private Panel panelAqua;
private Panel panelRed;
private Panel panelPink;
private Panel panelWhite;
private Panel panelGreen;
private Panel panelYellow;
private Panel panelBlue;
private Panel panelObject;
private PictureBox pictureBoxObject;
private Label labelAdditionalColor;
private Label labelColor;
private Button buttonCancel;
private Button buttonOk;
private Label labelRectOrnament;
private Label labelEllipseOrnament;
private Label labelNoOrnament;
private Label labelWheelsNumber;
private NumericUpDown numericUpDownWheelsNumber;
}
}

View File

@@ -0,0 +1,213 @@
namespace WarmlyLocomotove
{
/// <summary>
/// Форма создания объекта
/// </summary>
public partial class FormLocomotiveConfig : Form
{
/// <summary>
/// Переменная - выбранный локомотив
/// </summary>
DrawningLocomotive _locomotive = null;
/// <summary>
/// Делегат
/// </summary>
/// <param name="locomotive"></param>
public delegate void Action(DrawningLocomotive locomotive);
/// <summary>
/// Событие
/// </summary>
private event Action EventAddLocomotive;
/// <summary>
/// Конструктор
/// </summary>
public FormLocomotiveConfig()
{
InitializeComponent();
panelAqua.MouseDown += PanelColor_MouseDown;
panelBlack.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelPink.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
//Лямбда-выражение для закрытия окна
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
/// Отрисовка локомотива
/// </summary>
private void DrawLocomotive()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_locomotive?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_locomotive?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev"></param>
public void AddEvent(Action ev)
{
if (EventAddLocomotive == null)
{
EventAddLocomotive = new Action(ev);
}
else
{
EventAddLocomotive += ev;
}
}
/// <summary>
/// Передаём информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text) || e.Data.GetDataPresent(typeof(IDrawningAdditionalElements)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действие при приёме получаемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
_locomotive = new DrawningWarmlyLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, 160, 85, Color.Black, checkBoxHasPipe.Checked, checkBoxHasFuelTank.Checked);
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_locomotive = new DrawningLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
break;
case "labelModifiedObject":
_locomotive = new DrawningWarmlyLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, 160, 85, Color.Black, checkBoxHasPipe.Checked, checkBoxHasFuelTank.Checked);
break;
}
}
else if (_locomotive != null && e.Data.GetDataPresent(typeof(IDrawningAdditionalElements)))
{
var ornament = e.Data.GetData(typeof(IDrawningAdditionalElements));
_locomotive.AdditionalElements = (IDrawningAdditionalElements)ornament;
}
_locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
DrawLocomotive();
}
/// <summary>
/// Отправляем цвет с панели
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel).DoDragDrop((sender as Panel).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect= DragDropEffects.None;
}
}
/// <summary>
/// Принимаем основной цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
_locomotive.Locomotive.BodyColor = (Color)e.Data.GetData(typeof(Color));
DrawLocomotive();
}
/// <summary>
/// Принимаем дополнительный цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
if (_locomotive.Locomotive is EntityWarmlyLocomotive warmlyLocomotive)
{
warmlyLocomotive.AdditionalColor = (Color)e.Data.GetData(typeof(Color));
}
DrawLocomotive();
}
/// <summary>
/// Добавление локомотива
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddLocomotive?.Invoke(_locomotive);
Close();
}
/// <summary>
/// Запоминаем объект от класса доп. прорисовки в переменную типа DataObject
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelOrnament_MouseDown(object sender, MouseEventArgs e)
{
IDrawningAdditionalElements selectedOrnament = new DrawningWheels();
switch ((sender as Label).Name)
{
case "labelNoOrnament":
selectedOrnament = new DrawningWheels();
break;
case "labelRectOrnament":
selectedOrnament = new DrawningRectOrnament();
break;
case "labelEllipseOrnament":
selectedOrnament = new DrawningEllipseOrnament();
break;
}
var dataObj = new DataObject();
dataObj.SetData(typeof(IDrawningAdditionalElements), selectedOrnament);
(sender as Label).DoDragDrop(dataObj, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Автоматически обновляем количество колёс
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void NumericUpDownWheelsNumber_ValueChanged(object sender, EventArgs e)
{
if (_locomotive != null)
{
_locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
DrawLocomotive();
}
}
}
}

View File

@@ -0,0 +1,60 @@
<root>
<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>

View File

@@ -29,6 +29,7 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxTools = new System.Windows.Forms.GroupBox(); this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.buttonShowLastRemovedObject = new System.Windows.Forms.Button();
this.groupBoxMaps = new System.Windows.Forms.GroupBox(); this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.buttonDeleteMap = new System.Windows.Forms.Button(); this.buttonDeleteMap = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox(); this.listBoxMaps = new System.Windows.Forms.ListBox();
@@ -45,10 +46,18 @@
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddCar = new System.Windows.Forms.Button(); this.buttonAddCar = new System.Windows.Forms.Button();
this.pictureBoxLocomotives = new System.Windows.Forms.PictureBox(); this.pictureBoxLocomotives = new System.Windows.Forms.PictureBox();
this.buttonShowLastRemovedObject = new System.Windows.Forms.Button(); this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.FileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveSelectedMapToolstripmenu = new System.Windows.Forms.ToolStripMenuItem();
this.loadMapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.groupBoxTools.SuspendLayout(); this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout(); this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotives)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotives)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBoxTools // groupBoxTools
@@ -72,6 +81,16 @@
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты"; this.groupBoxTools.Text = "Инструменты";
// //
// buttonShowLastRemovedObject
//
this.buttonShowLastRemovedObject.Location = new System.Drawing.Point(31, 517);
this.buttonShowLastRemovedObject.Name = "buttonShowLastRemovedObject";
this.buttonShowLastRemovedObject.Size = new System.Drawing.Size(164, 40);
this.buttonShowLastRemovedObject.TabIndex = 2;
this.buttonShowLastRemovedObject.Text = "Показать последний удалённый элемент";
this.buttonShowLastRemovedObject.UseVisualStyleBackColor = true;
this.buttonShowLastRemovedObject.Click += new System.EventHandler(this.ButtonShowLastRemovedObject_Click);
//
// groupBoxMaps // groupBoxMaps
// //
this.groupBoxMaps.Anchor = System.Windows.Forms.AnchorStyles.Right; this.groupBoxMaps.Anchor = System.Windows.Forms.AnchorStyles.Right;
@@ -242,21 +261,69 @@
this.pictureBoxLocomotives.TabIndex = 1; this.pictureBoxLocomotives.TabIndex = 1;
this.pictureBoxLocomotives.TabStop = false; this.pictureBoxLocomotives.TabStop = false;
// //
// buttonShowLastRemovedObject // menuStrip1
// //
this.buttonShowLastRemovedObject.Location = new System.Drawing.Point(31, 517); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.buttonShowLastRemovedObject.Name = "buttonShowLastRemovedObject"; this.FileToolStripMenuItem});
this.buttonShowLastRemovedObject.Size = new System.Drawing.Size(164, 40); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.buttonShowLastRemovedObject.TabIndex = 2; this.menuStrip1.Name = "menuStrip1";
this.buttonShowLastRemovedObject.Text = "Показать последний удалённый элемент"; this.menuStrip1.Size = new System.Drawing.Size(464, 24);
this.buttonShowLastRemovedObject.UseVisualStyleBackColor = true; this.menuStrip1.TabIndex = 3;
this.buttonShowLastRemovedObject.Click += new System.EventHandler(this.ButtonShowLastRemovedObject_Click); this.menuStrip1.Text = "menuStrip";
//
// FileToolStripMenuItem
//
this.FileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem,
this.saveSelectedMapToolstripmenu,
this.loadMapToolStripMenuItem});
this.FileToolStripMenuItem.Name = "FileToolStripMenuItem";
this.FileToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
this.FileToolStripMenuItem.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);
//
// saveSelectedMapToolstripmenu
//
this.saveSelectedMapToolstripmenu.Name = "saveSelectedMapToolstripmenu";
this.saveSelectedMapToolstripmenu.Size = new System.Drawing.Size(180, 22);
this.saveSelectedMapToolstripmenu.Text = "Сохранить карту";
this.saveSelectedMapToolstripmenu.Click += new System.EventHandler(this.SaveSelectedMapToolStripMenu_Click);
//
// loadMapToolStripMenuItem
//
this.loadMapToolStripMenuItem.Name = "loadMapToolStripMenuItem";
this.loadMapToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.loadMapToolStripMenuItem.Text = "Загрузить карту";
this.loadMapToolStripMenuItem.Click += new System.EventHandler(this.LoadMapToolStripMenu_Click);
//
// saveFileDialog
//
this.saveFileDialog.Filter = "txt file|*.txt";
//
// openFileDialog
//
this.openFileDialog.Filter = "txt file|*.txt";
// //
// FormMapWithSetLocomotives // FormMapWithSetLocomotives
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(687, 760); this.ClientSize = new System.Drawing.Size(687, 760);
this.Controls.Add(this.menuStrip1);
this.Controls.Add(this.pictureBoxLocomotives); this.Controls.Add(this.pictureBoxLocomotives);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetLocomotives"; this.Name = "FormMapWithSetLocomotives";
@@ -266,7 +333,10 @@
this.groupBoxMaps.ResumeLayout(false); this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout(); this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotives)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotives)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
@@ -290,5 +360,13 @@
private Button buttonAddMap; private Button buttonAddMap;
private TextBox textBoxNewMapName; private TextBox textBoxNewMapName;
private Button buttonShowLastRemovedObject; private Button buttonShowLastRemovedObject;
private MenuStrip menuStrip1;
private ToolStripMenuItem FileToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
private ToolStripMenuItem saveSelectedMapToolstripmenu;
private ToolStripMenuItem loadMapToolStripMenuItem;
} }
} }

View File

@@ -113,23 +113,20 @@
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonAddLocomotive_Click(object sender, EventArgs e) private void ButtonAddLocomotive_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1) FormLocomotiveConfig formLocomotiveConfig = new();
formLocomotiveConfig.AddEvent(new(AddLocomotive));
formLocomotiveConfig.Show();
}
private void AddLocomotive(DrawningLocomotive locomotive)
{
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectLocomotive(locomotive)) > -1)
{ {
return; MessageBox.Show("Объект добавлен");
pictureBoxLocomotives.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
FormLocomotive form = new(); else
if (form.ShowDialog() == DialogResult.OK)
{ {
DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive); MessageBox.Show("Не удалось добавить объект");
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive) > -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxLocomotives.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
} }
} }
/// <summary> /// <summary>
@@ -238,5 +235,91 @@
formWithLastRemovedObject.Draw(); formWithLastRemovedObject.Draw();
_mapsCollection.RemoveLastObject(); _mapsCollection.RemoveLastObject();
} }
/// <summary>
/// Обработка нажатия "Сохранение"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Обработка нажатия "Загрузка"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadMaps();
}
else
{
MessageBox.Show("Не удалось загрузить файл", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Обработка нажатия "Сохранить выбранную карту"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveSelectedMapToolStripMenu_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.SaveMap(saveFileDialog.FileName, listBoxMaps.SelectedItem?.ToString() ?? string.Empty))
{
MessageBox.Show("Сохранение карты прошло успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Карта не сохранилась", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Обработка нажатия "Загрузить карту"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LoadMapToolStripMenu_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.LoadMap(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadMaps();
}
else
{
MessageBox.Show("Не удалось загрузить файл", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
} }
} }

View File

@@ -57,4 +57,13 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>265, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
</metadata>
</root> </root>

View File

@@ -8,7 +8,7 @@
/// <summary> /// <summary>
/// Свойство получения количества колёс /// Свойство получения количества колёс
/// </summary> /// </summary>
public int WheelsNum { set; } public int WheelsNum { get; set; }
/// <summary> /// <summary>
/// Отрисовка колёс /// Отрисовка колёс
/// </summary> /// </summary>

View File

@@ -32,5 +32,10 @@
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
(float Top, float Bottom, float Left, float Right) GetCurrentPosition(); (float Top, float Bottom, float Left, float Right) GetCurrentPosition();
/// <summary>
/// Получение информации по объекту
/// </summary>
/// <returns></returns>
string GetInfo();
} }
} }

View File

@@ -178,5 +178,39 @@
CurrentLocomotiveNumber++; CurrentLocomotiveNumber++;
} }
} }
/// <summary>
/// Получение данных в виде строки
/// </summary>
/// <param name="separatorType"></param>
/// <param name="separatorData"></param>
/// <returns></returns>
public string GetData(char separatorType, char separatorData)
{
//Получаем название карты
string data = $"{_map.GetType().Name}{separatorType}";
foreach (var locomotive in _setLocomotives.GetLocomotives())
{
data += $"{locomotive.GetInfo()}{separatorData}";
}
return data;
}
/// <summary>
/// Загрузка списка из массива строк
/// </summary>
/// <param name="records"></param>
public void LoadData(string[] records)
{
foreach (var record in records)
{
_setLocomotives.Insert(DrawningObjectLocomotive.Create(record) as T, 0);
}
}
/// <summary>
/// Очистка содержимого карты
/// </summary>
public void ClearObjectCollection()
{
_setLocomotives.ClearLocomotives();
}
} }
} }

View File

@@ -22,6 +22,14 @@
/// </summary> /// </summary>
private readonly int _pictureHeight; private readonly int _pictureHeight;
/// <summary> /// <summary>
/// Разделитель для записи информации по элементу словаря в файл
/// </summary>
private readonly char separatorDict = '|';
/// <summary>
/// Разделитель для записи коллекции данных в файл
/// </summary>
private readonly char separatorData = ';';
/// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
/// <param name="pictureWidth"></param> /// <param name="pictureWidth"></param>
@@ -45,6 +53,62 @@
_mapStorages.Add(name, new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(_pictureWidth, _pictureHeight, map)); _mapStorages.Add(name, new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(_pictureWidth, _pictureHeight, map));
} }
} }
public bool SaveMap(string filename, string maptosave)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
using (StreamWriter sw = new(filename))
{
sw.Write("Map\n");
sw.Write(maptosave + "\n");
sw.Write($"{_mapStorages[maptosave].GetData(separatorDict, separatorData)}");
sw.Close();
}
return true;
}
public bool LoadMap(string filename)
{
if (!File.Exists(filename))
{
return false;
}
using (StreamReader sr = new(filename))
{
string firstStr = sr.ReadLine();
if (firstStr == null || !firstStr.Contains("Map"))
{
return false;
}
string mapName = sr.ReadLine();
string mapInfo = sr.ReadLine();
AbstractMap newMap = null;
var info = mapInfo.Split(separatorDict);
switch (info[0])
{
case "SimpleMap":
newMap = new SimpleMap();
break;
case "CrossMap":
newMap = new CrossMap();
break;
case "RoadsMap":
newMap = new RoadsMap();
break;
}
if (_mapStorages.ContainsKey(mapName))
{
_mapStorages[mapName].ClearObjectCollection();
}
else
{
_mapStorages.Add(mapName, new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(_pictureWidth, _pictureHeight, newMap));
}
_mapStorages[mapName].LoadData(info[1].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
return true;
}
/// <summary> /// <summary>
/// Удаление карты /// Удаление карты
/// </summary> /// </summary>
@@ -115,6 +179,61 @@
{ {
_removedObjects.RemoveLast(); _removedObjects.RemoveLast();
} }
public bool SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
using (StreamWriter sw = new(filename))
{
sw.Write("MapsCollection\n");
foreach (var storage in _mapStorages)
{
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}\n");
}
sw.Close();
}
return true;
}
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
using (StreamReader sr = new(filename))
{
string firstStr = sr.ReadLine();
if (firstStr == null || !firstStr.Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
return false;
}
string? currentString;
while ((currentString = sr.ReadLine()) != null)
{
var elem = currentString.Split(separatorDict);
AbstractMap map = null;
switch (elem[1])
{
case "SimpleMap":
map = new SimpleMap();
break;
case "CrossMap":
map = new CrossMap();
break;
case "RoadsMap":
map = new RoadsMap();
break;
}
_mapStorages.Add(elem[0], new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(_pictureWidth, _pictureHeight, map));
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
sr.Close();
return true;
}
}
} }
} }

View File

@@ -97,5 +97,12 @@
} }
} }
} }
/// <summary>
/// Очистка списка объектов
/// </summary>
public void ClearLocomotives()
{
_places.Clear();
}
} }
} }