файлы лабораторной
This commit is contained in:
parent
20f939bb77
commit
1533dab9a5
69
lainer/Lainer1/FormLainerCollection.Designer.cs
generated
69
lainer/Lainer1/FormLainerCollection.Designer.cs
generated
@ -33,6 +33,10 @@
|
|||||||
ButtonRemove = new Button();
|
ButtonRemove = new Button();
|
||||||
ButtonRefresh = new Button();
|
ButtonRefresh = new Button();
|
||||||
maskedTextBoxNumber = new MaskedTextBox();
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
ButtonAddObject = new Button();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
ButtonDelObject = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -40,15 +44,15 @@
|
|||||||
//
|
//
|
||||||
pictureBoxCollection.Location = new Point(16, 14);
|
pictureBoxCollection.Location = new Point(16, 14);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(781, 297);
|
pictureBoxCollection.Size = new Size(815, 434);
|
||||||
pictureBoxCollection.TabIndex = 0;
|
pictureBoxCollection.TabIndex = 0;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
// ButtonAddLainer
|
// ButtonAddLainer
|
||||||
//
|
//
|
||||||
ButtonAddLainer.Location = new Point(813, 40);
|
ButtonAddLainer.Location = new Point(872, 282);
|
||||||
ButtonAddLainer.Name = "ButtonAddLainer";
|
ButtonAddLainer.Name = "ButtonAddLainer";
|
||||||
ButtonAddLainer.Size = new Size(154, 52);
|
ButtonAddLainer.Size = new Size(154, 32);
|
||||||
ButtonAddLainer.TabIndex = 1;
|
ButtonAddLainer.TabIndex = 1;
|
||||||
ButtonAddLainer.Text = "добавить лайнер";
|
ButtonAddLainer.Text = "добавить лайнер";
|
||||||
ButtonAddLainer.UseVisualStyleBackColor = true;
|
ButtonAddLainer.UseVisualStyleBackColor = true;
|
||||||
@ -56,9 +60,9 @@
|
|||||||
//
|
//
|
||||||
// ButtonRemove
|
// ButtonRemove
|
||||||
//
|
//
|
||||||
ButtonRemove.Location = new Point(812, 158);
|
ButtonRemove.Location = new Point(887, 384);
|
||||||
ButtonRemove.Name = "ButtonRemove";
|
ButtonRemove.Name = "ButtonRemove";
|
||||||
ButtonRemove.Size = new Size(139, 65);
|
ButtonRemove.Size = new Size(139, 37);
|
||||||
ButtonRemove.TabIndex = 2;
|
ButtonRemove.TabIndex = 2;
|
||||||
ButtonRemove.Text = "удалить лайнер";
|
ButtonRemove.Text = "удалить лайнер";
|
||||||
ButtonRemove.UseVisualStyleBackColor = true;
|
ButtonRemove.UseVisualStyleBackColor = true;
|
||||||
@ -66,26 +70,67 @@
|
|||||||
//
|
//
|
||||||
// ButtonRefresh
|
// ButtonRefresh
|
||||||
//
|
//
|
||||||
ButtonRefresh.Location = new Point(803, 247);
|
ButtonRefresh.Location = new Point(849, 449);
|
||||||
ButtonRefresh.Name = "ButtonRefresh";
|
ButtonRefresh.Name = "ButtonRefresh";
|
||||||
ButtonRefresh.Size = new Size(164, 54);
|
ButtonRefresh.Size = new Size(164, 29);
|
||||||
ButtonRefresh.TabIndex = 3;
|
ButtonRefresh.TabIndex = 3;
|
||||||
ButtonRefresh.Text = "обновить коллекцию";
|
ButtonRefresh.Text = "обновить коллекцию";
|
||||||
ButtonRefresh.UseVisualStyleBackColor = true;
|
ButtonRefresh.UseVisualStyleBackColor = true;
|
||||||
ButtonRefresh.Click += ButtonRefresh_Click;
|
ButtonRefresh.Click += ButtonRefreshCollection_Click;
|
||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(826, 111);
|
maskedTextBoxNumber.Location = new Point(888, 351);
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(125, 27);
|
maskedTextBoxNumber.Size = new Size(125, 27);
|
||||||
maskedTextBoxNumber.TabIndex = 4;
|
maskedTextBoxNumber.TabIndex = 4;
|
||||||
//
|
//
|
||||||
|
// ButtonAddObject
|
||||||
|
//
|
||||||
|
ButtonAddObject.Location = new Point(856, 55);
|
||||||
|
ButtonAddObject.Name = "ButtonAddObject";
|
||||||
|
ButtonAddObject.Size = new Size(170, 29);
|
||||||
|
ButtonAddObject.TabIndex = 5;
|
||||||
|
ButtonAddObject.Text = "добавить набор";
|
||||||
|
ButtonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddObject.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(892, 22);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(125, 27);
|
||||||
|
textBoxStorageName.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
listBoxStorages.FormattingEnabled = true;
|
||||||
|
listBoxStorages.ItemHeight = 20;
|
||||||
|
listBoxStorages.Location = new Point(876, 90);
|
||||||
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
|
listBoxStorages.Size = new Size(150, 104);
|
||||||
|
listBoxStorages.TabIndex = 7;
|
||||||
|
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// ButtonDelObject
|
||||||
|
//
|
||||||
|
ButtonDelObject.Location = new Point(888, 210);
|
||||||
|
ButtonDelObject.Name = "ButtonDelObject";
|
||||||
|
ButtonDelObject.Size = new Size(138, 29);
|
||||||
|
ButtonDelObject.TabIndex = 8;
|
||||||
|
ButtonDelObject.Text = "удалить набор";
|
||||||
|
ButtonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonDelObject.Click += ButtonDelObject_Click;
|
||||||
|
//
|
||||||
// FormLainerCollection
|
// FormLainerCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1003, 450);
|
ClientSize = new Size(1038, 490);
|
||||||
|
Controls.Add(ButtonDelObject);
|
||||||
|
Controls.Add(listBoxStorages);
|
||||||
|
Controls.Add(textBoxStorageName);
|
||||||
|
Controls.Add(ButtonAddObject);
|
||||||
Controls.Add(maskedTextBoxNumber);
|
Controls.Add(maskedTextBoxNumber);
|
||||||
Controls.Add(ButtonRefresh);
|
Controls.Add(ButtonRefresh);
|
||||||
Controls.Add(ButtonRemove);
|
Controls.Add(ButtonRemove);
|
||||||
@ -105,5 +150,9 @@
|
|||||||
private Button ButtonRemove;
|
private Button ButtonRemove;
|
||||||
private Button ButtonRefresh;
|
private Button ButtonRefresh;
|
||||||
private MaskedTextBox maskedTextBoxNumber;
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private Button ButtonAddObject;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button ButtonDelObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,14 @@
|
|||||||
using ProjectLainer.DrawningObjects;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
using ProjectLainer.DrawningObjects;
|
||||||
using ProjectLainer.Generics;
|
using ProjectLainer.Generics;
|
||||||
using ProjectLainer.MovementStrategy;
|
using ProjectLainer.MovementStrategy;
|
||||||
|
|
||||||
@ -6,21 +16,73 @@ namespace ProjectLainer
|
|||||||
{
|
{
|
||||||
public partial class FormLainerCollection : Form
|
public partial class FormLainerCollection : Form
|
||||||
{
|
{
|
||||||
private readonly LainersGenericCollection<DrawingLainer, DrawningObjectLainer> _lainers;
|
private readonly LainersGenericStorage _storage;
|
||||||
public FormLainerCollection()
|
public FormLainerCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_lainers = new LainersGenericCollection<DrawingLainer, DrawningObjectLainer>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
_storage = new LainersGenericStorage(pictureBoxCollection.Width,
|
||||||
|
pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorages.SelectedIndex;
|
||||||
|
listBoxStorages.Items.Clear();
|
||||||
|
|
||||||
|
foreach (string key in _storage.Keys)
|
||||||
|
{
|
||||||
|
listBoxStorages.Items.Add(key);
|
||||||
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxStorages.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxStorages.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
||||||
|
?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void ButtonAddLainer_Click(object sender, EventArgs e)
|
private void ButtonAddLainer_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
LainerForm form = new();
|
LainerForm form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_lainers + form.SelectedLainer)
|
if (obj + form.SelectedLainer)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _lainers.ShowLainers();
|
pictureBoxCollection.Image = obj.ShowLainers();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -30,30 +92,49 @@ namespace ProjectLainer
|
|||||||
}
|
}
|
||||||
private void ButtonRemove_Click(object sender, EventArgs e)
|
private void ButtonRemove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
|
||||||
{
|
|
||||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
if (_lainers - pos == true)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _lainers.ShowLainers();
|
pictureBoxCollection.Image = obj.ShowLainers();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { MessageBox.Show("Не удалось удалить объект"); }
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
|
||||||
}
|
|
||||||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _lainers.ShowLainers();
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowLainers();
|
||||||
|
}
|
||||||
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowLainers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,17 @@
|
|||||||
using ProjectLainer.MovementStrategy;
|
using ProjectLainer.MovementStrategy;
|
||||||
using ProjectLainer.DrawningObjects;
|
using ProjectLainer.DrawningObjects;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
namespace ProjectLainer.Generics
|
namespace ProjectLainer.Generics
|
||||||
{
|
{
|
||||||
internal class LainersGenericCollection<T, U>
|
internal class LainersGenericCollection<T, U>
|
||||||
where T : DrawingLainer
|
where T : DrawingEntity
|
||||||
where U : IMoveableObject
|
where U : IMoveableObject
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
private readonly int _placeSizeWidth = 210;
|
private readonly int _placeSizeWidth = 210;
|
||||||
|
|
||||||
private readonly int _placeSizeHeight = 90;
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
public readonly SetGeneric<T> _collection;
|
|
||||||
|
|
||||||
public LainersGenericCollection(int picWidth, int picHeight)
|
public LainersGenericCollection(int picWidth, int picHeight)
|
||||||
{
|
{
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
@ -27,40 +20,25 @@ namespace ProjectLainer.Generics
|
|||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_collection = new SetGeneric<T>(width * height);
|
_collection = new SetGeneric<T>(width * height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator +(LainersGenericCollection<T, U> collect, T? obj)
|
public static bool operator +(LainersGenericCollection<T, U> collect, T? obj)
|
||||||
{
|
{
|
||||||
if (obj != null && collect != null)
|
if (obj != null && collect != null)
|
||||||
{
|
return collect._collection.Insert(obj);
|
||||||
var value = collect._collection.Insert(obj);
|
|
||||||
if(value <= collect._collection.Count && value >= 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else { return false; }
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
public static bool? operator -(LainersGenericCollection<T, U> collect, int
|
public static T? operator -(LainersGenericCollection<T, U> collect, int pos)
|
||||||
pos)
|
|
||||||
{
|
{
|
||||||
T? obj = collect?._collection.Get(pos);
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null && collect != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
return collect._collection.Remove(pos);
|
collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
else
|
return obj;
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap ShowLainers()
|
public Bitmap ShowLainers()
|
||||||
{
|
{
|
||||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
@ -69,7 +47,6 @@ namespace ProjectLainer.Generics
|
|||||||
DrawObjects(gr);
|
DrawObjects(gr);
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawBackground(Graphics g)
|
private void DrawBackground(Graphics g)
|
||||||
{
|
{
|
||||||
Pen pen = new(Color.Black, 3);
|
Pen pen = new(Color.Black, 3);
|
||||||
@ -77,7 +54,7 @@ namespace ProjectLainer.Generics
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||||
1; ++j)
|
1; ++j)
|
||||||
{
|
{//линия рамзетки места
|
||||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||||
_placeSizeHeight);
|
_placeSizeHeight);
|
||||||
@ -88,17 +65,19 @@ namespace ProjectLainer.Generics
|
|||||||
}
|
}
|
||||||
private void DrawObjects(Graphics g)
|
private void DrawObjects(Graphics g)
|
||||||
{
|
{
|
||||||
|
int i = 0;
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
foreach (var lainer in _collection.GetLainers())
|
||||||
{
|
{
|
||||||
DrawingLainer? lainer = _collection.Get(i);
|
|
||||||
if (lainer != null)
|
if (lainer != null)
|
||||||
{
|
{
|
||||||
int inRow = _pictureWidth / _placeSizeWidth;
|
int inRow = _pictureWidth / _placeSizeWidth;
|
||||||
|
|
||||||
lainer.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight);
|
lainer.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight);
|
||||||
lainer.DrawTransport(g);
|
lainer.DrawTransport(g);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
47
lainer/Lainer1/LainersGenericStorage.cs
Normal file
47
lainer/Lainer1/LainersGenericStorage.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using ProjectLainer.DrawningObjects;
|
||||||
|
using ProjectLainer.MovementStrategy;
|
||||||
|
namespace ProjectLainer.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс для хранения коллекции
|
||||||
|
/// </summary>
|
||||||
|
internal class LainersGenericStorage
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, LainersGenericCollection<DrawingEntity, DrawningObjectLainer>> _lainerStorages;
|
||||||
|
public List<string> Keys => _lainerStorages.Keys.ToList();
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
public LainersGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_lainerStorages = new Dictionary<string, LainersGenericCollection<DrawingEntity, DrawningObjectLainer>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
if (!_lainerStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_lainerStorages.Add(name, new LainersGenericCollection<DrawingEntity, DrawningObjectLainer>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (_lainerStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_lainerStorages.Remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public LainersGenericCollection<DrawingEntity, DrawningObjectLainer>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_lainerStorages.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _lainerStorages[ind];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,60 +1,74 @@
|
|||||||
namespace ProjectLainer.Generics
|
using System.Numerics;
|
||||||
|
|
||||||
|
namespace ProjectLainer.Generics
|
||||||
{
|
{
|
||||||
internal class SetGeneric<T>
|
internal class SetGeneric<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
private readonly T?[] _places;
|
private readonly List<T?> _places;
|
||||||
public int Count => _places.Length;
|
public int Count => _places.Count;
|
||||||
|
private readonly int _maxCount;
|
||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T?[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
|
public bool Insert(T lainer)
|
||||||
public int Insert(T lainer)
|
|
||||||
{
|
{
|
||||||
if (_places[Count - 1] != null)
|
if (_places.Count == _maxCount)
|
||||||
return Count;
|
{
|
||||||
return Insert(lainer, 0);
|
return false;
|
||||||
}
|
}
|
||||||
public int Insert(T lainer, int position)
|
Insert(lainer, 0);
|
||||||
{
|
return true;
|
||||||
if (position < 0 || position >= Count)
|
|
||||||
{
|
|
||||||
return position;
|
|
||||||
}
|
}
|
||||||
if (_places[position] != null)
|
public bool Insert(T lainer, int position)
|
||||||
{
|
{
|
||||||
int ind = position;
|
if (position < 0 || position > Count || _places.Count >= _maxCount)
|
||||||
while (ind < Count && _places[ind] != null)
|
{
|
||||||
ind++;
|
return false;
|
||||||
if (ind == Count)
|
|
||||||
return Count;
|
|
||||||
for (int i = ind - 1; i >= position; i--)
|
|
||||||
_places[i + 1] = _places[i];
|
|
||||||
}
|
}
|
||||||
_places[position] = lainer;
|
_places.Insert(position, lainer);
|
||||||
return position;
|
return true;
|
||||||
}
|
}
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 )
|
if (position < 0 || position >= Count)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(position >= Count)
|
_places.RemoveAt(position);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_places[position] = null;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public T? Get(int position)
|
public T? this[int position]
|
||||||
{
|
{
|
||||||
if(position < Count && position >= 0)
|
get
|
||||||
{
|
{
|
||||||
|
if(position < 0 || position >= Count)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
return null;
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count || Count >= _maxCount)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_places.Insert(position, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IEnumerable<T?> GetLainers(int? maxLainers = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxLainers.HasValue && i == maxLainers.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user