Compare commits
2 Commits
cd4cf22b7e
...
05d0e55103
Author | SHA1 | Date | |
---|---|---|---|
|
05d0e55103 | ||
|
4246af5f48 |
@ -8,7 +8,7 @@ namespace ProjectMachine
|
||||
{
|
||||
internal class DrawningObject : IDrawningObject
|
||||
{
|
||||
private DrawningMachine _machine = null;
|
||||
public DrawningMachine _machine = null;
|
||||
|
||||
public DrawningObject(DrawningMachine machine)
|
||||
{
|
||||
@ -17,6 +17,8 @@ namespace ProjectMachine
|
||||
|
||||
public float Step => _machine?.Machine?.Step ?? 0;
|
||||
|
||||
public DrawningMachine GetTank => _machine;
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _machine?.GetCurrentPosition() ?? default;
|
||||
|
@ -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.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.buttonLeft);
|
||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||
@ -70,9 +74,9 @@
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddTank);
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(799, 28);
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(812, 28);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(233, 758);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(233, 843);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Инструменты";
|
||||
@ -150,7 +154,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::ProjectMachine.Properties.Resources.лево;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(69, 703);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(69, 788);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(34, 30);
|
||||
this.buttonLeft.TabIndex = 13;
|
||||
@ -163,7 +167,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::ProjectMachine.Properties.Resources.вверх;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(105, 667);
|
||||
this.buttonUp.Location = new System.Drawing.Point(105, 752);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(34, 30);
|
||||
this.buttonUp.TabIndex = 12;
|
||||
@ -176,7 +180,7 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::ProjectMachine.Properties.Resources.право;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(141, 703);
|
||||
this.buttonRight.Location = new System.Drawing.Point(141, 788);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(34, 30);
|
||||
this.buttonRight.TabIndex = 11;
|
||||
@ -189,7 +193,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::ProjectMachine.Properties.Resources.вниз;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(105, 703);
|
||||
this.buttonDown.Location = new System.Drawing.Point(105, 788);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(34, 30);
|
||||
this.buttonDown.TabIndex = 10;
|
||||
@ -199,7 +203,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(21, 611);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(20, 689);
|
||||
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
|
||||
@ -210,7 +214,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(21, 556);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(20, 634);
|
||||
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
|
||||
@ -221,7 +225,7 @@
|
||||
//
|
||||
// buttonRemoveTank
|
||||
//
|
||||
this.buttonRemoveTank.Location = new System.Drawing.Point(21, 501);
|
||||
this.buttonRemoveTank.Location = new System.Drawing.Point(20, 579);
|
||||
this.buttonRemoveTank.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonRemoveTank.Name = "buttonRemoveTank";
|
||||
this.buttonRemoveTank.Size = new System.Drawing.Size(200, 47);
|
||||
@ -232,7 +236,7 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(21, 466);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(22, 544);
|
||||
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
@ -242,7 +246,7 @@
|
||||
//
|
||||
// buttonAddTank
|
||||
//
|
||||
this.buttonAddTank.Location = new System.Drawing.Point(21, 411);
|
||||
this.buttonAddTank.Location = new System.Drawing.Point(20, 489);
|
||||
this.buttonAddTank.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonAddTank.Name = "buttonAddTank";
|
||||
this.buttonAddTank.Size = new System.Drawing.Size(200, 47);
|
||||
@ -256,7 +260,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(799, 758);
|
||||
this.pictureBox.Size = new System.Drawing.Size(812, 843);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
@ -267,7 +271,7 @@
|
||||
this.файлToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(1032, 28);
|
||||
this.menuStrip.Size = new System.Drawing.Size(1045, 28);
|
||||
this.menuStrip.TabIndex = 2;
|
||||
this.menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
@ -302,11 +306,33 @@
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
this.buttonSortByType.Location = new System.Drawing.Point(20, 366);
|
||||
this.buttonSortByType.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonSortByType.Name = "buttonSortByType";
|
||||
this.buttonSortByType.Size = new System.Drawing.Size(200, 47);
|
||||
this.buttonSortByType.TabIndex = 15;
|
||||
this.buttonSortByType.Text = "Сортировать по типу";
|
||||
this.buttonSortByType.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click);
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
this.buttonSortByColor.Location = new System.Drawing.Point(22, 421);
|
||||
this.buttonSortByColor.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonSortByColor.Name = "buttonSortByColor";
|
||||
this.buttonSortByColor.Size = new System.Drawing.Size(200, 47);
|
||||
this.buttonSortByColor.TabIndex = 16;
|
||||
this.buttonSortByColor.Text = "Сортировать по цвету";
|
||||
this.buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click);
|
||||
//
|
||||
// FormMapWithSetTank
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1032, 786);
|
||||
this.ClientSize = new System.Drawing.Size(1045, 871);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
@ -350,5 +376,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -146,6 +146,11 @@ namespace ProjectMachine
|
||||
_logger.Warning("Ошибка переполнения хранилища: {0}", ex.Message);
|
||||
MessageBox.Show($"Ошибка переполнения хранилища: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warning("Такой объект уже есть:");
|
||||
MessageBox.Show($"Такой объект уже есть:", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
@ -294,6 +299,34 @@ namespace ProjectMachine
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка по типу
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new TankCompareByType());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка по цвету
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new TankCompareByColor());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,6 +139,14 @@ namespace ProjectMachine
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setTank.SortSet(comparer);
|
||||
}
|
||||
/// <summary>
|
||||
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||
/// </summary>
|
||||
private void Shaking()
|
||||
|
@ -51,7 +51,7 @@ namespace ProjectMachine
|
||||
public int Insert(T tank, int position)
|
||||
{
|
||||
if (_places.Contains(tank))
|
||||
throw new ArgumentException($"Объект {tank} уже есть");
|
||||
throw new ArgumentException($"Такой объект уже есть");
|
||||
if (Count >= _maxCount)
|
||||
throw new StorageOverflowException(Count);
|
||||
if (position < 0 || position >= _maxCount)
|
||||
@ -112,6 +112,18 @@ namespace ProjectMachine
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка набора объектов
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
45
ProjectMachine/ProjectMachine/TankCompareByColor.cs
Normal file
45
ProjectMachine/ProjectMachine/TankCompareByColor.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectMachine
|
||||
{
|
||||
internal class TankCompareByColor : 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 xTank = x as DrawningObject;
|
||||
var yTank = y as DrawningObject;
|
||||
if (xTank == null && yTank == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xTank == null && yTank != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xTank != null && yTank == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xColorName = xTank._machine.Machine.BodyColor.Name;
|
||||
var yColorName = yTank._machine.Machine.BodyColor.Name;
|
||||
return xColorName.CompareTo(yColorName);
|
||||
}
|
||||
}
|
||||
}
|
56
ProjectMachine/ProjectMachine/TankCompareByType.cs
Normal file
56
ProjectMachine/ProjectMachine/TankCompareByType.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectMachine
|
||||
{
|
||||
internal class TankCompareByType : 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 xTank = x as DrawningObject;
|
||||
var yTank = y as DrawningObject;
|
||||
if (xTank == null && yTank == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xTank == null && yTank != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xTank != null && yTank == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (xTank.GetTank.GetType().Name != yTank.GetTank.GetType().Name)
|
||||
{
|
||||
if (xTank.GetTank.GetType().Name == "DrawningMachine")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
var speedCompare = xTank.GetTank.Machine.Speed.CompareTo(yTank.GetTank.Machine.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xTank.GetTank.Machine.Weight.CompareTo(yTank.GetTank.Machine.Weight);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user