diff --git a/Airbus/Airbus/DrawingAirplane.cs b/Airbus/Airbus/DrawingAirplane.cs index 88eed17..8b25c80 100644 --- a/Airbus/Airbus/DrawingAirplane.cs +++ b/Airbus/Airbus/DrawingAirplane.cs @@ -133,4 +133,4 @@ namespace Airbus } } - } +} diff --git a/Airbus/Airbus/DrawningObjectAirplane.cs b/Airbus/Airbus/DrawningObjectAirplane.cs index 65bb174..5e437b2 100644 --- a/Airbus/Airbus/DrawningObjectAirplane.cs +++ b/Airbus/Airbus/DrawningObjectAirplane.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Airbus { - internal class DrawningObjectAirplane : IDrawningObject + public class DrawningObjectAirplane : IDrawningObject { private DrawningAirplane _airplane = null; @@ -31,5 +31,6 @@ namespace Airbus { _airplane?.SetPosition(x, y, width, height); } + public static explicit operator DrawningAirplane(DrawningObjectAirplane drawningObject) => drawningObject._airplane; } } diff --git a/Airbus/Airbus/FormAirplane.cs b/Airbus/Airbus/FormAirplane.cs index 3aa8b2c..37593eb 100644 --- a/Airbus/Airbus/FormAirplane.cs +++ b/Airbus/Airbus/FormAirplane.cs @@ -16,9 +16,15 @@ namespace Airbus private DrawningAirplane airplane; public DrawningAirplane SelectedAirplane { get; private set; } - public FormAirplane() + public FormAirplane(DrawningAirplane? goairplane = null) { + airplane = goairplane; InitializeComponent(); + if (goairplane != null) + { + SetData(); + Draw(); + } } private void Draw() diff --git a/Airbus/Airbus/FormMapWithSetAirplane.Designer.cs b/Airbus/Airbus/FormMapWithSetAirplane.Designer.cs index 3867a3b..eed819b 100644 --- a/Airbus/Airbus/FormMapWithSetAirplane.Designer.cs +++ b/Airbus/Airbus/FormMapWithSetAirplane.Designer.cs @@ -46,6 +46,7 @@ this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonAddAirplane = new System.Windows.Forms.Button(); this.pictureBox = new System.Windows.Forms.PictureBox(); + this.buttonRemoveFromTrashcan = new System.Windows.Forms.Button(); this.groupBoxTools.SuspendLayout(); this.groupBoxMaps.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); @@ -53,6 +54,7 @@ // // groupBoxTools // + this.groupBoxTools.Controls.Add(this.buttonRemoveFromTrashcan); this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.buttonAddAirplaneWithPar); this.groupBoxTools.Controls.Add(this.buttonDown); @@ -195,7 +197,7 @@ // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(62, 370); + this.buttonShowOnMap.Location = new System.Drawing.Point(60, 399); this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Size = new System.Drawing.Size(75, 23); this.buttonShowOnMap.TabIndex = 5; @@ -205,7 +207,7 @@ // // buttonStorage // - this.buttonStorage.Location = new System.Drawing.Point(6, 399); + this.buttonStorage.Location = new System.Drawing.Point(6, 428); this.buttonStorage.Name = "buttonStorage"; this.buttonStorage.Size = new System.Drawing.Size(188, 23); this.buttonStorage.TabIndex = 4; @@ -250,6 +252,16 @@ this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // + // buttonRemoveFromTrashcan + // + this.buttonRemoveFromTrashcan.Location = new System.Drawing.Point(6, 370); + this.buttonRemoveFromTrashcan.Name = "buttonRemoveFromTrashcan"; + this.buttonRemoveFromTrashcan.Size = new System.Drawing.Size(182, 23); + this.buttonRemoveFromTrashcan.TabIndex = 11; + this.buttonRemoveFromTrashcan.Text = "Вернуть с корзины"; + this.buttonRemoveFromTrashcan.UseVisualStyleBackColor = true; + this.buttonRemoveFromTrashcan.Click += new System.EventHandler(this.buttonRemoveFromTrashcan_Click); + // // FormMapWithSetAirplane // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -286,5 +298,6 @@ private Button buttonDelMap; private Button buttonAddMap; private TextBox textBoxNewMapName; + private Button buttonRemoveFromTrashcan; } } \ No newline at end of file diff --git a/Airbus/Airbus/FormMapWithSetAirplane.cs b/Airbus/Airbus/FormMapWithSetAirplane.cs index c477ed9..1f8f551 100644 --- a/Airbus/Airbus/FormMapWithSetAirplane.cs +++ b/Airbus/Airbus/FormMapWithSetAirplane.cs @@ -22,6 +22,7 @@ namespace Airbus /// Объект от коллекции карт /// private readonly MapsCollection _mapsCollection; + private LinkedList trashcan; /// /// Конструктор /// @@ -30,6 +31,7 @@ namespace Airbus InitializeComponent(); _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); comboBoxSelectorMap.Items.Clear(); + trashcan = new(); foreach (var elem in _mapsDict) { comboBoxSelectorMap.Items.Add(elem.Key); @@ -144,8 +146,11 @@ namespace Airbus return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + var delObject = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty, pos]; + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { + trashcan.AddLast(delObject); MessageBox.Show("Объект удален"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } @@ -233,5 +238,28 @@ namespace Airbus } } } + + private void buttonRemoveFromTrashcan_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1 || trashcan.Count == 0) + { + return; + } + FormAirplane form = new((DrawningAirplane)trashcan.First()); + trashcan.RemoveFirst(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObjectAirplane airplane = new(form.SelectedAirplane); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane > -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } } } diff --git a/Airbus/Airbus/MapWithSetAirplaneGeneric.cs b/Airbus/Airbus/MapWithSetAirplaneGeneric.cs index 739d385..f177cb3 100644 --- a/Airbus/Airbus/MapWithSetAirplaneGeneric.cs +++ b/Airbus/Airbus/MapWithSetAirplaneGeneric.cs @@ -29,7 +29,7 @@ namespace Airbus /// /// Набор объектов /// - private readonly SetAirplaneGeneric _setAirplane; + public SetAirplaneGeneric _setAirplane { get; private set; } /// /// Карта /// diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index 159c394..d39cdfc 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -67,5 +67,13 @@ namespace Airbus return null; } } + public DrawningObjectAirplane this[string ind, int indDrawningObject] + { + get + { + _mapStorages.TryGetValue(ind, out var returnAirplane); + return returnAirplane?._setAirplane[indDrawningObject]; + } + } } }