From 91c2c075f39a7c28a042d2d6c2f38fc836def290 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 2 Dec 2022 13:23:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/DrawningObjectPlane.cs | 2 + .../Airbus/FormMapWithSetPlanes.Designer.cs | 50 ++++++++++---- Airbus/Airbus/FormMapWithSetPlanes.cs | 12 ++++ Airbus/Airbus/MapWithSetPlanesGeneric.cs | 6 ++ Airbus/Airbus/PlaneCompareByColor.cs | 16 +++++ Airbus/Airbus/PlaneCompareByType.cs | 67 +++++++++++++++++++ Airbus/Airbus/SetPlanesGeneric.cs | 11 +++ 7 files changed, 152 insertions(+), 12 deletions(-) create mode 100644 Airbus/Airbus/PlaneCompareByColor.cs create mode 100644 Airbus/Airbus/PlaneCompareByType.cs diff --git a/Airbus/Airbus/DrawningObjectPlane.cs b/Airbus/Airbus/DrawningObjectPlane.cs index a694d2d..ef8fda5 100644 --- a/Airbus/Airbus/DrawningObjectPlane.cs +++ b/Airbus/Airbus/DrawningObjectPlane.cs @@ -17,6 +17,8 @@ namespace Airbus _airbus = airbus; } + public DrawningAirbus GetPlane => _airbus; + void IDrawningObject.DrawningObject(Graphics g) { _airbus.DrawTransport(g); diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs index fd70732..e19c808 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -51,6 +51,8 @@ this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.buttonSortByType = new System.Windows.Forms.Button(); + this.buttonSortByColor = new System.Windows.Forms.Button(); this.groupBoxTools.SuspendLayout(); this.groupBoxMaps.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); @@ -59,6 +61,8 @@ // // groupBoxTools // + this.groupBoxTools.Controls.Add(this.buttonSortByColor); + this.groupBoxTools.Controls.Add(this.buttonSortByType); this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.buttonRight); this.groupBoxTools.Controls.Add(this.buttonDown); @@ -72,7 +76,7 @@ this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Location = new System.Drawing.Point(843, 28); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(250, 769); + this.groupBoxTools.Size = new System.Drawing.Size(250, 863); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; @@ -145,7 +149,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.Right; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(158, 704); + this.buttonRight.Location = new System.Drawing.Point(158, 798); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(45, 45); this.buttonRight.TabIndex = 9; @@ -157,7 +161,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.Down; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(107, 704); + this.buttonDown.Location = new System.Drawing.Point(107, 798); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(45, 45); this.buttonDown.TabIndex = 8; @@ -169,7 +173,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.Left; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(56, 704); + this.buttonLeft.Location = new System.Drawing.Point(56, 798); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(45, 45); this.buttonLeft.TabIndex = 7; @@ -181,7 +185,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.Up; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(107, 653); + this.buttonUp.Location = new System.Drawing.Point(107, 747); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(45, 45); this.buttonUp.TabIndex = 6; @@ -190,7 +194,7 @@ // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(20, 553); + this.buttonShowOnMap.Location = new System.Drawing.Point(20, 687); this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Size = new System.Drawing.Size(218, 29); this.buttonShowOnMap.TabIndex = 5; @@ -200,7 +204,7 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(20, 500); + this.buttonShowStorage.Location = new System.Drawing.Point(20, 634); this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Size = new System.Drawing.Size(218, 29); this.buttonShowStorage.TabIndex = 4; @@ -210,7 +214,7 @@ // // buttonRemovePlane // - this.buttonRemovePlane.Location = new System.Drawing.Point(20, 446); + this.buttonRemovePlane.Location = new System.Drawing.Point(20, 580); this.buttonRemovePlane.Name = "buttonRemovePlane"; this.buttonRemovePlane.Size = new System.Drawing.Size(218, 29); this.buttonRemovePlane.TabIndex = 3; @@ -220,7 +224,7 @@ // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 413); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 547); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Size = new System.Drawing.Size(218, 27); @@ -228,7 +232,7 @@ // // buttonAddPlane // - this.buttonAddPlane.Location = new System.Drawing.Point(20, 378); + this.buttonAddPlane.Location = new System.Drawing.Point(20, 512); this.buttonAddPlane.Name = "buttonAddPlane"; this.buttonAddPlane.Size = new System.Drawing.Size(218, 29); this.buttonAddPlane.TabIndex = 1; @@ -241,7 +245,7 @@ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 28); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(843, 769); + this.pictureBox.Size = new System.Drawing.Size(843, 863); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -287,11 +291,31 @@ // this.saveFileDialog.Filter = "txt file | *.txt"; // + // buttonSortByType + // + this.buttonSortByType.Location = new System.Drawing.Point(20, 395); + this.buttonSortByType.Name = "buttonSortByType"; + this.buttonSortByType.Size = new System.Drawing.Size(218, 29); + this.buttonSortByType.TabIndex = 11; + this.buttonSortByType.Text = "Сортировка по типу"; + this.buttonSortByType.UseVisualStyleBackColor = true; + this.buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click); + // + // buttonSortByColor + // + this.buttonSortByColor.Location = new System.Drawing.Point(20, 430); + this.buttonSortByColor.Name = "buttonSortByColor"; + this.buttonSortByColor.Size = new System.Drawing.Size(218, 29); + this.buttonSortByColor.TabIndex = 12; + this.buttonSortByColor.Text = "Сортировка по цвету"; + this.buttonSortByColor.UseVisualStyleBackColor = true; + this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click); + // // FormMapWithSetPlanes // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1093, 797); + this.ClientSize = new System.Drawing.Size(1093, 891); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.menuStrip); @@ -335,5 +359,7 @@ private ToolStripMenuItem LoadToolStripMenuItem; private OpenFileDialog openFileDialog; private OpenFileDialog saveFileDialog; + private Button buttonSortByColor; + private Button buttonSortByType; } } \ No newline at end of file diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 18f4ffd..2a3b111 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -292,5 +292,17 @@ namespace Airbus } } } + + //сортировка по типу + private void buttonSortByType_Click(object sender, EventArgs e) + { + + } + + //сортировка по цвету + private void buttonSortByColor_Click(object sender, EventArgs e) + { + //TODO прописать логику + } } } diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index d72eb6d..a67988d 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -108,6 +108,12 @@ namespace Airbus } } + //сортировка + public void Sort(IComparer comparer) + { + _setPlanes.SortSet(comparer); + } + //"взламываем" набор, чтобы все элементы оказались в начале private void Shaking() { diff --git a/Airbus/Airbus/PlaneCompareByColor.cs b/Airbus/Airbus/PlaneCompareByColor.cs new file mode 100644 index 0000000..b70aa65 --- /dev/null +++ b/Airbus/Airbus/PlaneCompareByColor.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal class PlaneCompareByColor : IComparer + { + public int Compare(IDrawningObject? x, IDrawningObject? y) + { + //TODO проверку + } + } +} diff --git a/Airbus/Airbus/PlaneCompareByType.cs b/Airbus/Airbus/PlaneCompareByType.cs new file mode 100644 index 0000000..1c9b86b --- /dev/null +++ b/Airbus/Airbus/PlaneCompareByType.cs @@ -0,0 +1,67 @@ +using Microsoft.Extensions.Logging.Abstractions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal class PlaneCompareByType : IComparer + { + public int Compare(IDrawningObject? x, IDrawningObject? y) + { + if(x == null && y == null) + { + return 0; + } + + if(x == null && y != null) + { + return 1; + } + + if(x != null && y != null) + { + return -1; + } + + var xPlane = x as DrawningObjectPlane; + var yPlane = y as DrawningObjectPlane; + + if(xPlane == null && yPlane == null) + { + return 0; + } + + if(xPlane == null && yPlane != null) + { + return 1; + } + + if(xPlane != null && yPlane == null) + { + return 1; + } + + if(xPlane.GetPlane.GetType().Name != yPlane.GetPlane.GetType().Name) + { + if(xPlane.GetPlane.GetType().Name == "DrawningAirbus") + { + return -1; + } + + return -1; + } + + var speedCompare = xPlane.GetPlane.Airbus.Speed.CompareTo(yPlane.GetPlane.Airbus.Speed); + + if(speedCompare != 0) + { + return speedCompare; + } + + return xPlane.GetPlane.Airbus.Speed.CompareTo(yPlane.GetPlane.Airbus.Speed); + } + } +} diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 8c8edac..364519d 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -114,5 +114,16 @@ namespace Airbus } } } + + //сортировка набора объектов + public void SortSet(IComparer comparer) + { + if(comparer == null) + { + return; + } + + _places.Sort(comparer); + } } }