Add something whithout form's modofocations, 4 LabWork
This commit is contained in:
parent
5ade022f0c
commit
1d4d9c2d3a
@ -8,7 +8,6 @@ namespace ProjectElectricLocomotive.Entities
|
|||||||
{
|
{
|
||||||
public class EntityLocomotive
|
public class EntityLocomotive
|
||||||
{
|
{
|
||||||
//a new branch
|
|
||||||
public int Speed { get; private set;}
|
public int Speed { get; private set;}
|
||||||
public double Weight { get; private set;}
|
public double Weight { get; private set;}
|
||||||
public Color BodyColor { get; private set;}
|
public Color BodyColor { get; private set;}
|
||||||
|
@ -46,14 +46,14 @@
|
|||||||
this.Instruments.Controls.Add(this.ButtonRefreshCollection);
|
this.Instruments.Controls.Add(this.ButtonRefreshCollection);
|
||||||
this.Instruments.Controls.Add(this.ButtonRemoveLocomotive);
|
this.Instruments.Controls.Add(this.ButtonRemoveLocomotive);
|
||||||
this.Instruments.Controls.Add(this.ButtonAddLocomotive);
|
this.Instruments.Controls.Add(this.ButtonAddLocomotive);
|
||||||
this.Instruments.Location = new System.Drawing.Point(435, -40);
|
this.Instruments.Location = new System.Drawing.Point(815, 0);
|
||||||
this.Instruments.Name = "Instruments";
|
this.Instruments.Name = "Instruments";
|
||||||
this.Instruments.Size = new System.Drawing.Size(191, 451);
|
this.Instruments.Size = new System.Drawing.Size(233, 596);
|
||||||
this.Instruments.TabIndex = 0;
|
this.Instruments.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(42, 123);
|
this.maskedTextBoxNumber.Location = new System.Drawing.Point(55, 124);
|
||||||
this.maskedTextBoxNumber.Mask = "0";
|
this.maskedTextBoxNumber.Mask = "0";
|
||||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
|
this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
|
||||||
@ -63,7 +63,7 @@
|
|||||||
//
|
//
|
||||||
this.ButtonRefreshCollection.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
this.ButtonRefreshCollection.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
||||||
this.ButtonRefreshCollection.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
this.ButtonRefreshCollection.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(29, 249);
|
this.ButtonRefreshCollection.Location = new System.Drawing.Point(42, 326);
|
||||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(150, 36);
|
this.ButtonRefreshCollection.Size = new System.Drawing.Size(150, 36);
|
||||||
this.ButtonRefreshCollection.TabIndex = 2;
|
this.ButtonRefreshCollection.TabIndex = 2;
|
||||||
@ -75,7 +75,7 @@
|
|||||||
//
|
//
|
||||||
this.ButtonRemoveLocomotive.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
this.ButtonRemoveLocomotive.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
||||||
this.ButtonRemoveLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
this.ButtonRemoveLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
this.ButtonRemoveLocomotive.Location = new System.Drawing.Point(29, 179);
|
this.ButtonRemoveLocomotive.Location = new System.Drawing.Point(42, 254);
|
||||||
this.ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
|
this.ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
|
||||||
this.ButtonRemoveLocomotive.Size = new System.Drawing.Size(150, 36);
|
this.ButtonRemoveLocomotive.Size = new System.Drawing.Size(150, 36);
|
||||||
this.ButtonRemoveLocomotive.TabIndex = 1;
|
this.ButtonRemoveLocomotive.TabIndex = 1;
|
||||||
@ -87,7 +87,7 @@
|
|||||||
//
|
//
|
||||||
this.ButtonAddLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
this.ButtonAddLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.ButtonAddLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
this.ButtonAddLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
this.ButtonAddLocomotive.Location = new System.Drawing.Point(29, 52);
|
this.ButtonAddLocomotive.Location = new System.Drawing.Point(42, 41);
|
||||||
this.ButtonAddLocomotive.Name = "ButtonAddLocomotive";
|
this.ButtonAddLocomotive.Name = "ButtonAddLocomotive";
|
||||||
this.ButtonAddLocomotive.Size = new System.Drawing.Size(150, 36);
|
this.ButtonAddLocomotive.Size = new System.Drawing.Size(150, 36);
|
||||||
this.ButtonAddLocomotive.TabIndex = 0;
|
this.ButtonAddLocomotive.TabIndex = 0;
|
||||||
@ -98,9 +98,9 @@
|
|||||||
// pictureBoxCollections
|
// pictureBoxCollections
|
||||||
//
|
//
|
||||||
this.pictureBoxCollections.Anchor = System.Windows.Forms.AnchorStyles.Left;
|
this.pictureBoxCollections.Anchor = System.Windows.Forms.AnchorStyles.Left;
|
||||||
this.pictureBoxCollections.Location = new System.Drawing.Point(-3, -2);
|
this.pictureBoxCollections.Location = new System.Drawing.Point(-3, 0);
|
||||||
this.pictureBoxCollections.Name = "pictureBoxCollections";
|
this.pictureBoxCollections.Name = "pictureBoxCollections";
|
||||||
this.pictureBoxCollections.Size = new System.Drawing.Size(458, 373);
|
this.pictureBoxCollections.Size = new System.Drawing.Size(821, 596);
|
||||||
this.pictureBoxCollections.TabIndex = 1;
|
this.pictureBoxCollections.TabIndex = 1;
|
||||||
this.pictureBoxCollections.TabStop = false;
|
this.pictureBoxCollections.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -108,7 +108,7 @@
|
|||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(626, 370);
|
this.ClientSize = new System.Drawing.Size(1048, 593);
|
||||||
this.Controls.Add(this.pictureBoxCollections);
|
this.Controls.Add(this.pictureBoxCollections);
|
||||||
this.Controls.Add(this.Instruments);
|
this.Controls.Add(this.Instruments);
|
||||||
this.Name = "FormLocomotiveCollections";
|
this.Name = "FormLocomotiveCollections";
|
||||||
|
@ -1,64 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<root>
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
@ -44,13 +44,19 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
/// Перегрузка оператора вычитания
|
/// Перегрузка оператора вычитания
|
||||||
public static T operator -(LocomotiveGenericCollection<T, U> collect, int pos)
|
public static T operator -(LocomotiveGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
return collect._collection.Remove(pos);
|
T? obj = collect._collection[pos];
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
//return collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// получение объекта imoveableObj
|
// получение объекта imoveableObj
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Вывод всего набора объектов
|
/// Вывод всего набора объектов
|
||||||
@ -82,7 +88,7 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
int WidthObjCount = _pictureWidth / _placeSizeWidth;
|
int WidthObjCount = _pictureWidth / _placeSizeWidth;
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
{
|
{
|
||||||
T? type = _collection.Get(i);
|
T? type = _collection[i];
|
||||||
if (type != null)
|
if (type != null)
|
||||||
{
|
{
|
||||||
type.SetPosition(
|
type.SetPosition(
|
||||||
|
@ -0,0 +1,83 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
using ProjectElectricLocomotive.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.Generics
|
||||||
|
{
|
||||||
|
internal class LocomotiveGenericStorage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> _locomotivesStorage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий наборов
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Keys => _locomotivesStorage.Keys.ToList();
|
||||||
|
|
||||||
|
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pictureWidth"></param>
|
||||||
|
/// <param name="pictureHeight"></param>
|
||||||
|
public LocomotiveGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_locomotivesStorage = new Dictionary<string, LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
if (!_locomotivesStorage.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_locomotivesStorage.Add(name, new LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (!_locomotivesStorage.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_locomotivesStorage.Remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>?
|
||||||
|
this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения набора
|
||||||
|
if (_locomotivesStorage.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _locomotivesStorage[ind];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,11 +8,17 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
{
|
{
|
||||||
internal class SetGeneric<T> where T : class
|
internal class SetGeneric<T> where T : class
|
||||||
{
|
{
|
||||||
private readonly T[] _places;
|
|
||||||
public int Count => _places.Length;
|
private readonly List<T?> _places;
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
@ -49,15 +55,10 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
// TODO проверка позиции
|
|
||||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
|
||||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент //
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
|
||||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
|
||||||
if (position >= Count || position < 0)
|
if (position >= Count || position < 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -65,12 +66,47 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
_places[position] = null;
|
_places[position] = null;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count) return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count) return;
|
||||||
|
if(value == null) return;
|
||||||
|
_places[position] = value;
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO проверка свободных мест в списке
|
||||||
|
// TODO вставка в список по позиции
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по списку
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T?> GetCars(int? maxLocos = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxLocos.HasValue && i == maxLocos.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Получение объекта из набора по позиции
|
//Получение объекта из набора по позиции
|
||||||
public T Get(int position)
|
/* public T Get(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
if (position < 0 || position >= Count) return null;
|
if (position < 0 || position >= Count) return null;
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user