diff --git a/Airbus/Airbus/DrawningObjectPlane.cs b/Airbus/Airbus/DrawningObjectPlane.cs index cf25713..93a9274 100644 --- a/Airbus/Airbus/DrawningObjectPlane.cs +++ b/Airbus/Airbus/DrawningObjectPlane.cs @@ -36,5 +36,13 @@ namespace Airbus { _airbus?.SetPosition(x, y, width, height); } + public void DrawningObject() + { + //TODO + } + + public string GetInfo() => _airbus?.GetDataForSave(); + + public static IDrawningObject Create(string data) => new DrawningObjectPlane(data.CreateDrawningPlane()); } } diff --git a/Airbus/Airbus/EntityAirbus.cs b/Airbus/Airbus/EntityAirbus.cs index c9fb4d2..16ed3a7 100644 --- a/Airbus/Airbus/EntityAirbus.cs +++ b/Airbus/Airbus/EntityAirbus.cs @@ -10,7 +10,7 @@ namespace Airbus { public int Speed { get; private set; } //скорость public float Weight { get; private set; } //вес - public Color CorpusColor { get; private set; } //цвет корпуса + public Color CorpusColor { get; set; } //цвет корпуса public float Step => Speed * 100 / Weight; //шаг перемещения самолёта public EntityAirbus(int speed, float weight, Color corpusColor) { diff --git a/Airbus/Airbus/EntitySuperAirbus.cs b/Airbus/Airbus/EntitySuperAirbus.cs index fd95042..718a171 100644 --- a/Airbus/Airbus/EntitySuperAirbus.cs +++ b/Airbus/Airbus/EntitySuperAirbus.cs @@ -10,13 +10,13 @@ namespace Airbus internal class EntitySuperAirbus: EntityAirbus { //Дополнительный цвет - public Color AddColor { get; private set; } + public Color AddColor { get; set; } //Признак наличия дополнительно пассажирского отсека public bool AddСompartment { get; private set; } //Признак наличия доплнительных двигателей - public bool AddEngine { get; private set; } + public bool AddEngine { get; set; } //Инициализация свойств public EntitySuperAirbus(int speed, float weight, Color corpusColor, Color addColor, bool addCompartment, bool addEngine) : diff --git a/Airbus/Airbus/ExtentionPlane.cs b/Airbus/Airbus/ExtentionPlane.cs new file mode 100644 index 0000000..3873e23 --- /dev/null +++ b/Airbus/Airbus/ExtentionPlane.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + //расширение для класса DrawingPlane (класс для сохранения в файл колекций объектов) + internal static class ExtentionPlane + { + //разделитель для записи информации по объекту в файл + private static readonly char _separatorForObject = ':'; + + //создание объекта из строки + public static DrawningAirbus CreateDrawningPlane(this string info) + { + string[] strs = info.Split(_separatorForObject); + + //если простой самолёт + if (strs.Length == 3) + { + return new DrawningAirbus(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2])); + } + + //если аэробус + if (strs.Length == 6) + { + return new DrawningSuperAirbus(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 DrawningAirbus drawingPlane) + { + var plane = drawingPlane.Airbus; + var str = $"{plane.Speed}{_separatorForObject}{plane.Weight}{_separatorForObject}{plane.CorpusColor.Name}"; + + //если объект не расширеный + if (plane is not EntitySuperAirbus airbus) + { + return str; + } + + return $"{str}{_separatorForObject}{airbus.AddColor.Name}{_separatorForObject}" + + $"{airbus.AddEngine}{_separatorForObject}{airbus.AddСompartment}"; + + } + } +} diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs index d88d944..cc0ccb2 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -45,9 +45,16 @@ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.textBoxNewMapName = new System.Windows.Forms.TextBox(); this.pictureBox = new System.Windows.Forms.PictureBox(); + this.menuStrip1 = 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.groupBoxTools.SuspendLayout(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // // groupBoxTools @@ -63,9 +70,9 @@ this.groupBoxTools.Controls.Add(this.buttonUp); this.groupBoxTools.Controls.Add(this.groupBox1); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(627, 0); + this.groupBoxTools.Location = new System.Drawing.Point(627, 24); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(200, 534); + this.groupBoxTools.Size = new System.Drawing.Size(200, 547); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; @@ -229,19 +236,63 @@ // 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.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(627, 534); + this.pictureBox.Size = new System.Drawing.Size(627, 547); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(827, 24); + this.menuStrip1.TabIndex = 2; + this.menuStrip1.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"; + // // FormMapWithSetPlanes // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(827, 534); + this.ClientSize = new System.Drawing.Size(827, 571); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; this.Name = "FormMapWithSetPlanes"; this.Text = "FormMapWithSetPlanes"; this.groupBoxTools.ResumeLayout(false); @@ -249,7 +300,10 @@ this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -272,5 +326,11 @@ private Button buttonAddMap; private Button buttonDeleteMap; private TextBox textBoxNewMapName; + private MenuStrip menuStrip1; + private ToolStripMenuItem ToolStripMenuItem; + private ToolStripMenuItem SaveToolStripMenuItem; + private ToolStripMenuItem LoadToolStripMenuItem; + private OpenFileDialog openFileDialog; + private SaveFileDialog saveFileDialog; } } \ No newline at end of file diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index e372d50..9dd90b0 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -24,6 +24,7 @@ namespace Airbus //объект от коллекции карт private readonly MapsCollection _mapsCollection; + //конструктор public FormMapWithSetPlanes() { InitializeComponent(); @@ -98,6 +99,8 @@ namespace Airbus ReloadMaps(); } } + + //отрисовка добавленного объекта в хранилище private void AddPlane(DrawningAirbus plane) { if (listBoxMaps.SelectedIndex == -1) @@ -203,6 +206,41 @@ namespace Airbus pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].MoveObject(dir); } + //обработка нажатия сохранения + 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); + } + } + } + //обработка нажатия загрузки + private void LoadToolStripMenuItem_Click(object sender, EventArgs e) + { + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + if (_mapsCollection.LoadData(openFileDialog.FileName)) + { + ReloadMaps(); + MessageBox.Show("Загрузка данных прошла успешно", "Результат", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Ошибка загрузки данных", "Результат", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } } \ No newline at end of file diff --git a/Airbus/Airbus/FormMapWithSetPlanes.resx b/Airbus/Airbus/FormMapWithSetPlanes.resx index f298a7b..ddcfdb1 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.resx +++ b/Airbus/Airbus/FormMapWithSetPlanes.resx @@ -57,4 +57,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 132, 17 + + + 272, 17 + \ No newline at end of file diff --git a/Airbus/Airbus/FormPlaneConfig.Designer.cs b/Airbus/Airbus/FormPlaneConfig.Designer.cs index 6095bc3..b8bad92 100644 --- a/Airbus/Airbus/FormPlaneConfig.Designer.cs +++ b/Airbus/Airbus/FormPlaneConfig.Designer.cs @@ -29,35 +29,35 @@ private void InitializeComponent() { this.groupBoxConfig = new System.Windows.Forms.GroupBox(); - this.labelSpeed = new System.Windows.Forms.Label(); - this.labelWeight = new System.Windows.Forms.Label(); - this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); - this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); - this.checkBoxAddEngine = new System.Windows.Forms.CheckBox(); - this.checkBoxAddСompartment = new System.Windows.Forms.CheckBox(); - this.groupBoxColors = new System.Windows.Forms.GroupBox(); - this.panelWhite = new System.Windows.Forms.Panel(); - this.panelGray = new System.Windows.Forms.Panel(); - this.panelBlack = new System.Windows.Forms.Panel(); - this.panelPurple = new System.Windows.Forms.Panel(); - this.panelYellow = new System.Windows.Forms.Panel(); - this.panelBlue = new System.Windows.Forms.Panel(); - this.panelGreen = new System.Windows.Forms.Panel(); - this.panelRed = new System.Windows.Forms.Panel(); - this.labelSimpleObject = new System.Windows.Forms.Label(); this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColors = new System.Windows.Forms.GroupBox(); + this.panelRed = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.checkBoxAddСompartment = new System.Windows.Forms.CheckBox(); + this.checkBoxAddEngine = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + this.labelSpeed = new System.Windows.Forms.Label(); this.pictureBoxObject = new System.Windows.Forms.PictureBox(); - this.anelObject = new System.Windows.Forms.Panel(); - this.labelBaseColor = new System.Windows.Forms.Label(); + this.panelObject = new System.Windows.Forms.Panel(); this.labelAddColor = new System.Windows.Forms.Label(); + this.labelBaseColor = new System.Windows.Forms.Label(); this.buttonAddObject = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.groupBoxConfig.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); this.groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); - this.anelObject.SuspendLayout(); + this.panelObject.SuspendLayout(); this.SuspendLayout(); // // groupBoxConfig @@ -78,57 +78,27 @@ this.groupBoxConfig.TabStop = false; this.groupBoxConfig.Text = "Параметры"; // - // labelSpeed + // labelModifiedObject // - this.labelSpeed.AutoSize = true; - this.labelSpeed.Location = new System.Drawing.Point(17, 31); - this.labelSpeed.Name = "labelSpeed"; - this.labelSpeed.Size = new System.Drawing.Size(62, 15); - this.labelSpeed.TabIndex = 0; - this.labelSpeed.Text = "Скорость:"; + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(500, 142); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(103, 23); + 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); // - // labelWeight + // labelSimpleObject // - this.labelWeight.AutoSize = true; - this.labelWeight.Location = new System.Drawing.Point(17, 66); - this.labelWeight.Name = "labelWeight"; - this.labelWeight.Size = new System.Drawing.Size(29, 15); - this.labelWeight.TabIndex = 1; - this.labelWeight.Text = "Вес:"; - // - // numericUpDownSpeed - // - this.numericUpDownSpeed.Location = new System.Drawing.Point(89, 29); - this.numericUpDownSpeed.Name = "numericUpDownSpeed"; - this.numericUpDownSpeed.Size = new System.Drawing.Size(69, 23); - this.numericUpDownSpeed.TabIndex = 2; - // - // numericUpDownWeight - // - this.numericUpDownWeight.Location = new System.Drawing.Point(89, 58); - this.numericUpDownWeight.Name = "numericUpDownWeight"; - this.numericUpDownWeight.Size = new System.Drawing.Size(69, 23); - this.numericUpDownWeight.TabIndex = 3; - // - // checkBoxAddEngine - // - this.checkBoxAddEngine.AutoSize = true; - this.checkBoxAddEngine.Location = new System.Drawing.Point(17, 106); - this.checkBoxAddEngine.Name = "checkBoxAddEngine"; - this.checkBoxAddEngine.Size = new System.Drawing.Size(281, 19); - this.checkBoxAddEngine.TabIndex = 4; - this.checkBoxAddEngine.Text = "Признак наличия дополнительного двигателя"; - this.checkBoxAddEngine.UseVisualStyleBackColor = true; - // - // checkBoxAddСompartment - // - this.checkBoxAddСompartment.AutoSize = true; - this.checkBoxAddСompartment.Location = new System.Drawing.Point(17, 142); - this.checkBoxAddСompartment.Name = "checkBoxAddСompartment"; - this.checkBoxAddСompartment.Size = new System.Drawing.Size(351, 19); - this.checkBoxAddСompartment.TabIndex = 5; - this.checkBoxAddСompartment.Text = "Признак наличия дополнительного пассажирского отсека"; - this.checkBoxAddСompartment.UseVisualStyleBackColor = true; + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(386, 142); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(100, 23); + 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 // @@ -147,54 +117,14 @@ this.groupBoxColors.TabStop = false; this.groupBoxColors.Text = "Цвета"; // - // panelWhite + // panelRed // - this.panelWhite.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.panelWhite.Location = new System.Drawing.Point(6, 22); - this.panelWhite.Name = "panelWhite"; - this.panelWhite.Size = new System.Drawing.Size(39, 32); - this.panelWhite.TabIndex = 0; - // - // panelGray - // - this.panelGray.BackColor = System.Drawing.SystemColors.ControlDark; - this.panelGray.Location = new System.Drawing.Point(51, 22); - this.panelGray.Name = "panelGray"; - this.panelGray.Size = new System.Drawing.Size(39, 32); - this.panelGray.TabIndex = 1; - // - // panelBlack - // - this.panelBlack.BackColor = System.Drawing.SystemColors.ActiveCaptionText; - this.panelBlack.Location = new System.Drawing.Point(96, 22); - this.panelBlack.Name = "panelBlack"; - this.panelBlack.Size = new System.Drawing.Size(39, 32); - this.panelBlack.TabIndex = 2; - // - // panelPurple - // - this.panelPurple.BackColor = System.Drawing.Color.Purple; - this.panelPurple.Location = new System.Drawing.Point(141, 22); - this.panelPurple.Name = "panelPurple"; - this.panelPurple.Size = new System.Drawing.Size(39, 32); - this.panelPurple.TabIndex = 3; - // - // panelYellow - // - this.panelYellow.BackColor = System.Drawing.Color.Yellow; - this.panelYellow.Location = new System.Drawing.Point(6, 60); - this.panelYellow.Name = "panelYellow"; - this.panelYellow.Size = new System.Drawing.Size(39, 32); - this.panelYellow.TabIndex = 4; - // - // panelBlue - // - this.panelBlue.BackColor = System.Drawing.Color.Blue; - this.panelBlue.Location = new System.Drawing.Point(51, 60); - this.panelBlue.Name = "panelBlue"; - this.panelBlue.Size = new System.Drawing.Size(39, 32); - this.panelBlue.TabIndex = 1; - this.panelBlue.Paint += new System.Windows.Forms.PaintEventHandler(this.panel6_Paint); + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(141, 60); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(39, 32); + this.panelRed.TabIndex = 6; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelGreen // @@ -203,68 +133,135 @@ this.panelGreen.Name = "panelGreen"; this.panelGreen.Size = new System.Drawing.Size(39, 32); this.panelGreen.TabIndex = 5; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // - // panelRed + // panelBlue // - this.panelRed.BackColor = System.Drawing.Color.Red; - this.panelRed.Location = new System.Drawing.Point(141, 60); - this.panelRed.Name = "panelRed"; - this.panelRed.Size = new System.Drawing.Size(39, 32); - this.panelRed.TabIndex = 6; + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(51, 60); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(39, 32); + this.panelBlue.TabIndex = 1; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // - // labelSimpleObject + // panelYellow // - this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelSimpleObject.Location = new System.Drawing.Point(386, 142); - this.labelSimpleObject.Name = "labelSimpleObject"; - this.labelSimpleObject.Size = new System.Drawing.Size(100, 23); - 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); + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(6, 60); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(39, 32); + this.panelYellow.TabIndex = 4; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // - // labelModifiedObject + // panelPurple // - this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelModifiedObject.Location = new System.Drawing.Point(500, 142); - this.labelModifiedObject.Name = "labelModifiedObject"; - this.labelModifiedObject.Size = new System.Drawing.Size(103, 23); - 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); + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(141, 22); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(39, 32); + this.panelPurple.TabIndex = 3; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.SystemColors.ActiveCaptionText; + this.panelBlack.Location = new System.Drawing.Point(96, 22); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(39, 32); + this.panelBlack.TabIndex = 2; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.SystemColors.ControlDark; + this.panelGray.Location = new System.Drawing.Point(51, 22); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(39, 32); + this.panelGray.TabIndex = 1; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.SystemColors.ControlLightLight; + this.panelWhite.Location = new System.Drawing.Point(6, 22); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(39, 32); + this.panelWhite.TabIndex = 0; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // checkBoxAddСompartment + // + this.checkBoxAddСompartment.AutoSize = true; + this.checkBoxAddСompartment.Location = new System.Drawing.Point(17, 142); + this.checkBoxAddСompartment.Name = "checkBoxAddСompartment"; + this.checkBoxAddСompartment.Size = new System.Drawing.Size(351, 19); + this.checkBoxAddСompartment.TabIndex = 5; + this.checkBoxAddСompartment.Text = "Признак наличия дополнительного пассажирского отсека"; + this.checkBoxAddСompartment.UseVisualStyleBackColor = true; + // + // checkBoxAddEngine + // + this.checkBoxAddEngine.AutoSize = true; + this.checkBoxAddEngine.Location = new System.Drawing.Point(17, 106); + this.checkBoxAddEngine.Name = "checkBoxAddEngine"; + this.checkBoxAddEngine.Size = new System.Drawing.Size(281, 19); + this.checkBoxAddEngine.TabIndex = 4; + this.checkBoxAddEngine.Text = "Признак наличия дополнительного двигателя"; + this.checkBoxAddEngine.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(89, 58); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(69, 23); + this.numericUpDownWeight.TabIndex = 3; + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(89, 29); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(69, 23); + this.numericUpDownSpeed.TabIndex = 2; + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(17, 66); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(29, 15); + this.labelWeight.TabIndex = 1; + this.labelWeight.Text = "Вес:"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(17, 31); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(62, 15); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость:"; // // pictureBoxObject // - this.pictureBoxObject.Location = new System.Drawing.Point(17, 41); + this.pictureBoxObject.Location = new System.Drawing.Point(17, 38); + this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBoxObject.Name = "pictureBoxObject"; - this.pictureBoxObject.Size = new System.Drawing.Size(206, 71); + this.pictureBoxObject.Size = new System.Drawing.Size(206, 83); this.pictureBoxObject.TabIndex = 1; this.pictureBoxObject.TabStop = false; // - // anelObject + // panelObject // - this.anelObject.AllowDrop = true; - this.anelObject.Controls.Add(this.labelAddColor); - this.anelObject.Controls.Add(this.labelBaseColor); - this.anelObject.Controls.Add(this.pictureBoxObject); - this.anelObject.Location = new System.Drawing.Point(673, 2); - this.anelObject.Name = "anelObject"; - this.anelObject.Size = new System.Drawing.Size(237, 124); - this.anelObject.TabIndex = 2; - this.anelObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); - // - // labelBaseColor - // - this.labelBaseColor.AllowDrop = true; - this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelBaseColor.Location = new System.Drawing.Point(17, 10); - this.labelBaseColor.Name = "labelBaseColor"; - this.labelBaseColor.Size = new System.Drawing.Size(100, 23); - this.labelBaseColor.TabIndex = 8; - this.labelBaseColor.Text = "Цвет"; - this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.labelBaseColor.MouseEnter += new System.EventHandler(this.PanelObject_DragEnter); + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Controls.Add(this.labelAddColor); + this.panelObject.Controls.Add(this.labelBaseColor); + this.panelObject.Location = new System.Drawing.Point(673, 2); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(237, 124); + this.panelObject.TabIndex = 2; + this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); // // labelAddColor // @@ -276,6 +273,21 @@ this.labelAddColor.TabIndex = 9; this.labelAddColor.Text = "Доп. цвет"; this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop); + this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // labelBaseColor + // + this.labelBaseColor.AllowDrop = true; + this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelBaseColor.Location = new System.Drawing.Point(17, 10); + this.labelBaseColor.Name = "labelBaseColor"; + this.labelBaseColor.Size = new System.Drawing.Size(100, 23); + this.labelBaseColor.TabIndex = 8; + this.labelBaseColor.Text = "Цвет"; + this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop); + this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); // // buttonAddObject // @@ -285,6 +297,7 @@ this.buttonAddObject.TabIndex = 3; this.buttonAddObject.Text = "Добавить"; this.buttonAddObject.UseVisualStyleBackColor = true; + this.buttonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click); // // buttonCancel // @@ -302,17 +315,17 @@ this.ClientSize = new System.Drawing.Size(933, 184); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonAddObject); - this.Controls.Add(this.anelObject); this.Controls.Add(this.groupBoxConfig); + this.Controls.Add(this.panelObject); this.Name = "FormPlaneConfig"; this.Text = "Создание объекта"; this.groupBoxConfig.ResumeLayout(false); this.groupBoxConfig.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); this.groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); - this.anelObject.ResumeLayout(false); + this.panelObject.ResumeLayout(false); this.ResumeLayout(false); } @@ -338,7 +351,7 @@ private Label labelWeight; private Label labelSpeed; private PictureBox pictureBoxObject; - private Panel anelObject; + private Panel panelObject; private Label labelAddColor; private Label labelBaseColor; private Button buttonAddObject; diff --git a/Airbus/Airbus/FormPlaneConfig.cs b/Airbus/Airbus/FormPlaneConfig.cs index b863e89..67ca635 100644 --- a/Airbus/Airbus/FormPlaneConfig.cs +++ b/Airbus/Airbus/FormPlaneConfig.cs @@ -11,11 +11,11 @@ using System.Windows.Forms; namespace Airbus { public partial class FormPlaneConfig : Form - {//переменная-выбранная машина + {//переменная-выбранный самолёт DrawningAirbus _plane = null; //событие - private event PlaneDelegate EventAddPlane; + private event Action EventAddPlane; //конструктор public FormPlaneConfig() @@ -29,6 +29,8 @@ namespace Airbus panelWhite.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; + + buttonCancel.Click += (object sender, EventArgs e) => Close(); } //отрисовка самолёт @@ -41,11 +43,11 @@ namespace Airbus pictureBoxObject.Image = bmp; } //добавление события - public void AddEvent(PlaneDelegate ev) + public void AddEvent(Action ev) { - if (EventAddPlane == null) + if(EventAddPlane == null) { - EventAddPlane = new PlaneDelegate(ev); + EventAddPlane = new Action(ev); } else { @@ -56,7 +58,6 @@ namespace Airbus { (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); } - //проверка получаемой информации (ее типа на соответствие требуемому) private void PanelObject_DragEnter(object sender, DragEventArgs e) { @@ -90,13 +91,13 @@ namespace Airbus //отправляем цвет с панели private void PanelColor_MouseDown(object sender, MouseEventArgs e) { - (sender as Control).DoDragDrop((sender as Control).Name, DragDropEffects.Move | DragDropEffects.Copy); + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); } //проверка получаемой информации (её типа на соответсвие требуемому) - private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) + private void LabelColor_DragEnter(object sender, DragEventArgs e) { - if (e.Data.GetDataPresent(DataFormats.Text)) + if (e.Data.GetDataPresent(typeof(Color))) { e.Effect = DragDropEffects.Copy; } @@ -109,77 +110,23 @@ namespace Airbus //принимаем основной цвет private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) { - switch (e.Data.GetData(DataFormats.Text).ToString()) + //проверка на пустоту объекта + if (_plane != null) { - case "panelRed": - labelBaseColor.BackColor = Color.Red; - break; - case "panelBlack": - labelBaseColor.BackColor = Color.Black; - break; - case "panelGreen": - labelBaseColor.BackColor = Color.Green; - break; - case "panelYellow": - labelBaseColor.BackColor = Color.Yellow; - break; - case "panelBlue": - labelBaseColor.BackColor = Color.Blue; - break; - case "panelPurple": - labelBaseColor.BackColor = Color.Purple; - break; - case "panelGray": - labelBaseColor.BackColor = Color.DarkGray; - break; - case "panelWhite": - labelBaseColor.BackColor = Color.White; - break; - } - } - - //проверка получаемой информации (её типа на соответсвие требуемому) - private void LabelAddColor_DragEnter(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.Text)) - { - e.Effect = DragDropEffects.Copy; - } - else - { - e.Effect = DragDropEffects.None; + _plane.Airbus.CorpusColor = (Color)e.Data.GetData(typeof(Color)); + DrawPlane(); } } //принимаем дополнительный цвет - private void labelAddColor_DragDrop(object sender, DragEventArgs e) + private void LabelAddColor_DragDrop(object sender, DragEventArgs e) { - switch (e.Data.GetData(DataFormats.Text).ToString()) + //проверка на пустоту объекта и правильную сущноть + if (_plane != null && _plane.Airbus is EntitySuperAirbus entityAirbus) { - case "panelRed": - labelAddColor.BackColor = Color.Red; - break; - case "panelBlack": - labelAddColor.BackColor = Color.Black; - break; - case "panelGreen": - labelAddColor.BackColor = Color.Green; - break; - case "panelYellow": - labelAddColor.BackColor = Color.Yellow; - break; - case "panelBlue": - labelAddColor.BackColor = Color.Blue; - break; - case "panelPurple": - labelAddColor.BackColor = Color.Purple; - break; - case "panelGray": - labelAddColor.BackColor = Color.DarkGray; - break; - case "panelWhite": - labelAddColor.BackColor = Color.White; - break; + entityAirbus.AddColor = (Color)e.Data.GetData(typeof(Color)); + + DrawPlane(); } } @@ -189,12 +136,5 @@ namespace Airbus EventAddPlane?.Invoke(_plane); Close(); } - - //закрытие формы конфигурации - private void ButtonCancel_Click(object sender, EventArgs e) - { - Close(); - } - } } diff --git a/Airbus/Airbus/IDrawningObject.cs b/Airbus/Airbus/IDrawningObject.cs index 2f42ff0..26a38db 100644 --- a/Airbus/Airbus/IDrawningObject.cs +++ b/Airbus/Airbus/IDrawningObject.cs @@ -22,5 +22,8 @@ namespace Airbus //получение текущей позиции объекта (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + + //получение информации по объекту + string GetInfo(); } } diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 50f1dbd..277e013 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -82,6 +82,27 @@ namespace Airbus return new(_pictureWidth, _pictureHeight); } + //получение данных в виде строки + public string GetData(char separatorType, char separatorData) + { + string data = $"{_map.GetType().Name}{separatorType}"; + + foreach (var plane in _setPlanes.GetAirbus()) + { + data += $"{plane.GetInfo()}{separatorData}"; + } + + return data; + } + + //Загрузка списка из массива строк + public void LoadData(string[] records) + { + foreach (var rec in records) + { + _setPlanes.Insert(DrawningObjectPlane.Create(rec) as T); + } + } //"взламываем" набор, чтобы все элементы оказались в начале private void Shaking() diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index b432cea..240ca3f 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -10,11 +10,17 @@ namespace Airbus internal class MapsCollection { //словарь (хранилище) с картами - readonly Dictionary> _mapStorage; + readonly Dictionary> _mapStorage; //возвращение списка названий карт public List Keys => _mapStorage.Keys.ToList(); + //разделитель для записи информации по элементу словаря в файл + private readonly char separatorDict = '|'; + + //разделитель для записи коллекции данных в файл + private readonly char separatorData = ';'; + //ширина окна отрисовки private readonly int _pictureWidth; @@ -24,7 +30,7 @@ namespace Airbus //конструктор public MapsCollection(int pictureWidth, int pictureHeight) { - _mapStorage = new Dictionary>(); + _mapStorage = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } @@ -32,23 +38,105 @@ namespace Airbus //добавление карты public void AddMap(string name, AbstractMap map) { - var NewElem = new MapWithSetPlanesGeneric( - _pictureWidth, _pictureHeight, map); - _mapStorage.Add(name, NewElem); + if (!_mapStorage.ContainsKey(name)) + { + _mapStorage.Add(name, new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map)); + } } //удаление карты public void DelMap(string name) { - _mapStorage.Remove(name); + if (_mapStorage.ContainsKey(name)) + { + _mapStorage.Remove(name); + } } - //Доступ к аэродрому - public MapWithSetPlanesGeneric this[string ind] + // сохранение информации по автомобилям в хранилище в файл + public bool SaveData(string filename) + { + if (File.Exists(filename)) + { + File.Delete(filename); + } + + using (StreamWriter sw = new(filename)) + { + sw.Write($"MapsCollection{Environment.NewLine}"); + foreach (var storage in _mapStorage) + { + + sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" + + $"{Environment.NewLine}"); + } + } + + return true; + } + + // загрузка информации по автомобилям на парковках из файла + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + + using (StreamReader sr = new(filename)) + { + string str = ""; + + //если не содержит такую запись или пустой файл + if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection")) + { + return false; + } + + _mapStorage.Clear(); + + while ((str = sr.ReadLine()) != null) + { + var element = str.Split(separatorDict); + AbstractMap map = null; + + switch (element[1]) + { + case "SimpleMap": + map = new SimpleMap(); + break; + case "DesertMap": + map = new DesertMap(); + break; + case "SpaceMap": + map = new SpaceMap(); + break; + } + + _mapStorage.Add(element[0], new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map)); + _mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); + } + } + + return true; + } + + //доступ к аэродрому + public MapWithSetPlanesGeneric this[string ind] { get { - return _mapStorage[ind]; + if (ind != string.Empty) + { + MapWithSetPlanesGeneric value; + + if (_mapStorage.TryGetValue(ind, out value)) + { + return value; + } + } + + return null; } } } diff --git a/Airbus/Airbus/PlaneDelegate.cs b/Airbus/Airbus/PlaneDelegate.cs deleted file mode 100644 index 1ceb27d..0000000 --- a/Airbus/Airbus/PlaneDelegate.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Airbus -{ - //делегат для передачи объекта-самолёта - public delegate void PlaneDelegate(DrawningAirbus plane); -}