Сортировка

This commit is contained in:
ArtemEmelyanov 2022-12-09 12:31:38 +04:00
parent 13591af122
commit 7aab615e91
7 changed files with 145 additions and 14 deletions

View File

@ -14,6 +14,7 @@ namespace Airbus
_plane = plane;
}
public float Step => _plane?.Plane?.Step ?? 0;
public DrawningPlane GetPlane => _plane;
public (float Left, float Top, float Right, float Bottom)
GetCurrentPosition()
{

View File

@ -51,6 +51,8 @@
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.buttonSortByType = new System.Windows.Forms.Button();
this.buttonSortByColor = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
@ -59,6 +61,8 @@
//
// groupBox1
//
this.groupBox1.Controls.Add(this.buttonSortByColor);
this.groupBox1.Controls.Add(this.buttonSortByType);
this.groupBox1.Controls.Add(this.groupBoxMaps);
this.groupBox1.Controls.Add(this.buttonLeft);
this.groupBox1.Controls.Add(this.buttonRight);
@ -72,7 +76,7 @@
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(657, 24);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 616);
this.groupBox1.Size = new System.Drawing.Size(200, 674);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
@ -143,7 +147,7 @@
//
this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(56, 572);
this.buttonLeft.Location = new System.Drawing.Point(56, 634);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 9;
@ -154,7 +158,7 @@
//
this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(128, 572);
this.buttonRight.Location = new System.Drawing.Point(128, 634);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 8;
@ -165,7 +169,7 @@
//
this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(92, 572);
this.buttonDown.Location = new System.Drawing.Point(92, 634);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 7;
@ -176,7 +180,7 @@
//
this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(92, 536);
this.buttonUp.Location = new System.Drawing.Point(92, 598);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 6;
@ -185,7 +189,7 @@
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 499);
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 561);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(171, 31);
this.buttonShowOnMap.TabIndex = 5;
@ -195,7 +199,7 @@
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(17, 459);
this.buttonShowStorage.Location = new System.Drawing.Point(17, 521);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(171, 34);
this.buttonShowStorage.TabIndex = 4;
@ -205,7 +209,7 @@
//
// buttonRemovePlane
//
this.buttonRemovePlane.Location = new System.Drawing.Point(17, 400);
this.buttonRemovePlane.Location = new System.Drawing.Point(17, 462);
this.buttonRemovePlane.Name = "buttonRemovePlane";
this.buttonRemovePlane.Size = new System.Drawing.Size(171, 31);
this.buttonRemovePlane.TabIndex = 3;
@ -215,7 +219,7 @@
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 371);
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 433);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(171, 23);
@ -223,7 +227,7 @@
//
// buttonAddPlane
//
this.buttonAddPlane.Location = new System.Drawing.Point(17, 315);
this.buttonAddPlane.Location = new System.Drawing.Point(17, 377);
this.buttonAddPlane.Name = "buttonAddPlane";
this.buttonAddPlane.Size = new System.Drawing.Size(171, 31);
this.buttonAddPlane.TabIndex = 1;
@ -236,7 +240,7 @@
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 24);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(657, 616);
this.pictureBox.Size = new System.Drawing.Size(657, 674);
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
//
@ -262,14 +266,14 @@
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(141, 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.Size = new System.Drawing.Size(141, 22);
this.LoadToolStripMenuItem.Text = "Загрузка";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
@ -281,11 +285,31 @@
//
this.saveFileDialog.Filter = "«txt file | *.txt";
//
// buttonSortByType
//
this.buttonSortByType.Location = new System.Drawing.Point(17, 291);
this.buttonSortByType.Name = "buttonSortByType";
this.buttonSortByType.Size = new System.Drawing.Size(171, 26);
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(17, 323);
this.buttonSortByColor.Name = "buttonSortByColor";
this.buttonSortByColor.Size = new System.Drawing.Size(171, 26);
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(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(857, 640);
this.ClientSize = new System.Drawing.Size(857, 698);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.menuStrip1);
@ -330,5 +354,7 @@
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
}
}

View File

@ -295,5 +295,25 @@ namespace Airbus
}
}
}
private void buttonSortByType_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new PlaneCompareByType());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void buttonSortByColor_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new PlaneCompareByColor());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
}
}

View File

@ -212,5 +212,9 @@ namespace Airbus
_setPlanes.Insert(DrawningObjectPlane.Create(rec) as T);
}
}
public void Sort(IComparer<T> comparer)
{
_setPlanes.SortSet(comparer);
}
}
}

View File

@ -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<IDrawningObject>
{
public int Compare(IDrawningObject? x, IDrawningObject? y)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Airbus
{
internal class PlaneCompareByType : IComparer<IDrawningObject>
{
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 == "DrawningPlane")
{
return -1;
}
return 1;
}
var speedCompare = xPlane.GetPlane.Plane.Speed.CompareTo(yPlane.GetPlane.Plane.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xPlane.GetPlane.Plane.Weight.CompareTo(yPlane.GetPlane.Plane.Weight);
}
}
}

View File

@ -117,5 +117,14 @@ namespace Airbus
}
}
}
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
{
return;
}
_places.Sort(comparer);
}
}
}