Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f76b623305 | ||
|
b45f27b91d | ||
|
0e7878555f | ||
|
5ad06ae239 | ||
|
0db70e3020 | ||
|
5f77a4c906 | ||
|
2523d4f151 | ||
|
0a16b54539 | ||
|
467726e7d3 | ||
|
05d5b82867 |
88
HoistingCrane/HoistingCrane/AbstractStrategy.cs
Normal file
88
HoistingCrane/HoistingCrane/AbstractStrategy.cs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
namespace HoistingCrane.MovementStrategy
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
// Перемещаемый объект
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
// Статус перемещения
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
// Ширина поля
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
// Высота поля
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
// Статус перемещения
|
||||||
|
public Status GetStatus() { return _state; }
|
||||||
|
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||||
|
/// <param name="width">Ширина поля</param>
|
||||||
|
/// <param name="height">Высота поля</param>
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||||
|
{
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
_state = Status.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = Status.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
// Шаг перемещения
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Перемещение влевo
|
||||||
|
// <returns>Результат перемещения (true - удалось переместиться, false -неудача)</returns>
|
||||||
|
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||||
|
// Перемещение вправо false - неудача)</returns>
|
||||||
|
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||||
|
// Перемещение вверх
|
||||||
|
// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||||
|
// Перемещение вниз
|
||||||
|
// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||||
|
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||||
|
// Параметры объекта
|
||||||
|
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||||
|
// Шаг объекта
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
// Перемещение к цели
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
// Достигнута ли цель
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
// Попытка перемещения в требуемом направлении
|
||||||
|
// <param name="directionType">Направление</param>
|
||||||
|
// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
private bool MoveTo(DirectionType directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
HoistingCrane/HoistingCrane/AdditionEntityCrane.cs
Normal file
18
HoistingCrane/HoistingCrane/AdditionEntityCrane.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
namespace HoistingCrane.Entities
|
||||||
|
{
|
||||||
|
public class AdditionEntityCrane : EntityCrane
|
||||||
|
{
|
||||||
|
//дополнительный
|
||||||
|
public Color AdditionalColor { get; set; }
|
||||||
|
//противовес
|
||||||
|
public bool CounterWeight { get; private set; }
|
||||||
|
//кран
|
||||||
|
public bool Crane { get; private set; }
|
||||||
|
public AdditionEntityCrane(int speed, double weight, Color bodyColor, Color additionalColor, bool counterWeight, bool crane) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
CounterWeight = counterWeight;
|
||||||
|
Crane = crane;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
HoistingCrane/HoistingCrane/AdditionalDrawingCrane.cs
Normal file
41
HoistingCrane/HoistingCrane/AdditionalDrawingCrane.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using HoistingCrane.Entities;
|
||||||
|
|
||||||
|
namespace HoistingCrane.DrawningObjects
|
||||||
|
{
|
||||||
|
public class AdditionalDrawingCrane : DrawingCrane
|
||||||
|
{
|
||||||
|
// Конструктор
|
||||||
|
public AdditionalDrawingCrane(int speed, double weight, Color bodyColor, Color additionalColor, bool counterWeight, bool crane, int width, int height) : base(speed, weight, bodyColor, width, height)
|
||||||
|
{
|
||||||
|
if (EntityCrane != null)
|
||||||
|
{
|
||||||
|
EntityCrane = new AdditionEntityCrane(speed, weight, bodyColor, additionalColor, counterWeight, crane);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityCrane is not AdditionEntityCrane transportCrane)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(transportCrane.AdditionalColor);
|
||||||
|
//противовес
|
||||||
|
if (transportCrane.CounterWeight)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, _startPositionX + 185, _startPositionY + 20, 15, 45);
|
||||||
|
|
||||||
|
}
|
||||||
|
//кран
|
||||||
|
if (transportCrane.Crane)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, _startPositionX + 20, _startPositionY, 30, 65);
|
||||||
|
g.DrawRectangle(pen, _startPositionX, _startPositionY, 20, 30);
|
||||||
|
g.FillRectangle(additionalBrush, _startPositionX + 20, _startPositionY, 30, 65);
|
||||||
|
g.FillRectangle(additionalBrush, _startPositionX, _startPositionY, 20, 30);
|
||||||
|
}
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
HoistingCrane/HoistingCrane/CraneCompareByColor.cs
Normal file
49
HoistingCrane/HoistingCrane/CraneCompareByColor.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
using HoistingCrane.DrawningObjects;
|
||||||
|
using HoistingCrane.Entities;
|
||||||
|
|
||||||
|
namespace HoistingCrane.Generics
|
||||||
|
{
|
||||||
|
internal class CraneCompareByColor : IComparer<DrawingCrane?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingCrane? x, DrawingCrane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityCrane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityCrane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.EntityCrane.BodyColor.Name != y.EntityCrane.BodyColor.Name)
|
||||||
|
{
|
||||||
|
return x.EntityCrane.BodyColor.Name.CompareTo(y.EntityCrane.BodyColor.Name);
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
if (x is EntityCrane)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (x.GetType().Name == y.GetType().Name && x is AdditionalDrawingCrane)
|
||||||
|
{
|
||||||
|
AdditionEntityCrane _X = (AdditionEntityCrane)x.EntityCrane;
|
||||||
|
AdditionEntityCrane _Y = (AdditionEntityCrane)y.EntityCrane;
|
||||||
|
|
||||||
|
if (_X.AdditionalColor.Name != _Y.AdditionalColor.Name)
|
||||||
|
{
|
||||||
|
return _X.AdditionalColor.Name.CompareTo(_Y.AdditionalColor.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var speedCompare = x.EntityCrane.Speed.CompareTo(y.EntityCrane.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityCrane.Weight.CompareTo(y.EntityCrane.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
HoistingCrane/HoistingCrane/CraneCompareByType.cs
Normal file
30
HoistingCrane/HoistingCrane/CraneCompareByType.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using HoistingCrane.DrawningObjects;
|
||||||
|
|
||||||
|
namespace HoistingCrane.Generics
|
||||||
|
{
|
||||||
|
internal class CraneCompareByType : IComparer<DrawingCrane?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingCrane? x, DrawingCrane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityCrane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityCrane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
}
|
||||||
|
var speedCompare =
|
||||||
|
x.EntityCrane.Speed.CompareTo(y.EntityCrane.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityCrane.Weight.CompareTo(y.EntityCrane.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
HoistingCrane/HoistingCrane/CraneNotFoundException.cs
Normal file
14
HoistingCrane/HoistingCrane/CraneNotFoundException.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace HoistingCrane.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class CraneNotFoundException : ApplicationException
|
||||||
|
{
|
||||||
|
public CraneNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
public CraneNotFoundException() : base() { }
|
||||||
|
public CraneNotFoundException(string message) : base(message) { }
|
||||||
|
public CraneNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected CraneNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
}
|
194
HoistingCrane/HoistingCrane/CraneVisual.Designer.cs
generated
Normal file
194
HoistingCrane/HoistingCrane/CraneVisual.Designer.cs
generated
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
namespace HoistingCrane
|
||||||
|
{
|
||||||
|
partial class CraneVisual
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CraneVisual));
|
||||||
|
this.pictureBoxCrane = new System.Windows.Forms.PictureBox();
|
||||||
|
this.buttonCreate = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
|
this.buttonStep = new System.Windows.Forms.Button();
|
||||||
|
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonCreateAdditional = new System.Windows.Forms.Button();
|
||||||
|
this.buttonChoose = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCrane)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxCrane
|
||||||
|
//
|
||||||
|
this.pictureBoxCrane.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pictureBoxCrane.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.pictureBoxCrane.Name = "pictureBoxCrane";
|
||||||
|
this.pictureBoxCrane.Size = new System.Drawing.Size(878, 444);
|
||||||
|
this.pictureBoxCrane.TabIndex = 0;
|
||||||
|
this.pictureBoxCrane.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonCreate
|
||||||
|
//
|
||||||
|
this.buttonCreate.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||||
|
this.buttonCreate.Location = new System.Drawing.Point(254, 378);
|
||||||
|
this.buttonCreate.Name = "buttonCreate";
|
||||||
|
this.buttonCreate.Size = new System.Drawing.Size(170, 59);
|
||||||
|
this.buttonCreate.TabIndex = 24;
|
||||||
|
this.buttonCreate.Text = "создать кран";
|
||||||
|
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage")));
|
||||||
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonDown.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||||
|
this.buttonDown.Location = new System.Drawing.Point(811, 414);
|
||||||
|
this.buttonDown.Name = "buttonDown";
|
||||||
|
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonDown.TabIndex = 23;
|
||||||
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage")));
|
||||||
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonRight.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||||
|
this.buttonRight.Location = new System.Drawing.Point(847, 414);
|
||||||
|
this.buttonRight.Name = "buttonRight";
|
||||||
|
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonRight.TabIndex = 22;
|
||||||
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage")));
|
||||||
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonLeft.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||||
|
this.buttonLeft.Location = new System.Drawing.Point(775, 414);
|
||||||
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
|
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonLeft.TabIndex = 21;
|
||||||
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
|
||||||
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonUp.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||||
|
this.buttonUp.Location = new System.Drawing.Point(811, 378);
|
||||||
|
this.buttonUp.Name = "buttonUp";
|
||||||
|
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonUp.TabIndex = 20;
|
||||||
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonStep
|
||||||
|
//
|
||||||
|
this.buttonStep.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||||
|
this.buttonStep.Location = new System.Drawing.Point(787, 45);
|
||||||
|
this.buttonStep.Name = "buttonStep";
|
||||||
|
this.buttonStep.Size = new System.Drawing.Size(80, 35);
|
||||||
|
this.buttonStep.TabIndex = 27;
|
||||||
|
this.buttonStep.Text = "шаг";
|
||||||
|
this.buttonStep.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||||
|
"0",
|
||||||
|
"1"});
|
||||||
|
this.comboBoxStrategy.Location = new System.Drawing.Point(695, 6);
|
||||||
|
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
this.comboBoxStrategy.Size = new System.Drawing.Size(182, 33);
|
||||||
|
this.comboBoxStrategy.TabIndex = 26;
|
||||||
|
//
|
||||||
|
// buttonCreateAdditional
|
||||||
|
//
|
||||||
|
this.buttonCreateAdditional.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
this.buttonCreateAdditional.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||||
|
this.buttonCreateAdditional.Location = new System.Drawing.Point(0, 378);
|
||||||
|
this.buttonCreateAdditional.Name = "buttonCreateAdditional";
|
||||||
|
this.buttonCreateAdditional.Size = new System.Drawing.Size(248, 59);
|
||||||
|
this.buttonCreateAdditional.TabIndex = 25;
|
||||||
|
this.buttonCreateAdditional.Text = "создать кран с утяжелителем и краном";
|
||||||
|
this.buttonCreateAdditional.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateAdditional.Click += new System.EventHandler(this.ButtonCreateAdditional_Click);
|
||||||
|
//
|
||||||
|
// buttonChoose
|
||||||
|
//
|
||||||
|
this.buttonChoose.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||||
|
this.buttonChoose.Location = new System.Drawing.Point(430, 378);
|
||||||
|
this.buttonChoose.Name = "buttonChoose";
|
||||||
|
this.buttonChoose.Size = new System.Drawing.Size(170, 59);
|
||||||
|
this.buttonChoose.TabIndex = 28;
|
||||||
|
this.buttonChoose.Text = "Выбрать";
|
||||||
|
this.buttonChoose.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonChoose.Click += new System.EventHandler(this.buttonChoose_Click);
|
||||||
|
//
|
||||||
|
// CraneVisual
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(878, 444);
|
||||||
|
this.Controls.Add(this.buttonChoose);
|
||||||
|
this.Controls.Add(this.buttonStep);
|
||||||
|
this.Controls.Add(this.comboBoxStrategy);
|
||||||
|
this.Controls.Add(this.buttonCreateAdditional);
|
||||||
|
this.Controls.Add(this.buttonCreate);
|
||||||
|
this.Controls.Add(this.buttonDown);
|
||||||
|
this.Controls.Add(this.buttonRight);
|
||||||
|
this.Controls.Add(this.buttonLeft);
|
||||||
|
this.Controls.Add(this.buttonUp);
|
||||||
|
this.Controls.Add(this.pictureBoxCrane);
|
||||||
|
this.Name = "CraneVisual";
|
||||||
|
this.Text = "HoistingCrane";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCrane)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxCrane;
|
||||||
|
private Button buttonCreate;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button buttonStep;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonCreateAdditional;
|
||||||
|
private Button buttonChoose;
|
||||||
|
}
|
||||||
|
}
|
120
HoistingCrane/HoistingCrane/CraneVisual.cs
Normal file
120
HoistingCrane/HoistingCrane/CraneVisual.cs
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
using HoistingCrane.DrawningObjects;
|
||||||
|
using HoistingCrane.MovementStrategy;
|
||||||
|
|
||||||
|
namespace HoistingCrane
|
||||||
|
{
|
||||||
|
public partial class CraneVisual : Form
|
||||||
|
{
|
||||||
|
private DrawingCrane? _drawingCrane;
|
||||||
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public DrawingCrane? SelectedCrane { get; private set; }
|
||||||
|
public CraneVisual()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawingCrane == null) return;
|
||||||
|
Bitmap btm = new(pictureBoxCrane.Width, pictureBoxCrane.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(btm);
|
||||||
|
_drawingCrane.DrawTransport(gr);
|
||||||
|
pictureBoxCrane.Image = btm;
|
||||||
|
}
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawingCrane = new DrawingCrane(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000),
|
||||||
|
color, pictureBoxCrane.Width, pictureBoxCrane.Height);
|
||||||
|
_drawingCrane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void ButtonCreateAdditional_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
Color Additionalcolor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
Additionalcolor = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawingCrane = new AdditionalDrawingCrane(random.Next(100, 300), random.Next(1000, 3000), color, Additionalcolor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxCrane.Width, pictureBoxCrane.Height);
|
||||||
|
_drawingCrane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingCrane == null) return;
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_drawingCrane.MoveCrane(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_drawingCrane.MoveCrane(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_drawingCrane.MoveCrane(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_drawingCrane.MoveCrane(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void buttonChoose_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedCrane = _drawingCrane;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
private void buttonStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingCrane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||||
|
switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(new
|
||||||
|
DrawningObjectsCrane(_drawingCrane), pictureBoxCrane.Width,
|
||||||
|
pictureBoxCrane.Height);
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2396
HoistingCrane/HoistingCrane/CraneVisual.resx
Normal file
2396
HoistingCrane/HoistingCrane/CraneVisual.resx
Normal file
File diff suppressed because it is too large
Load Diff
23
HoistingCrane/HoistingCrane/CranesCollectionInfo.cs
Normal file
23
HoistingCrane/HoistingCrane/CranesCollectionInfo.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
namespace HoistingCrane.Generics
|
||||||
|
{
|
||||||
|
internal class CranesCollectionInfo : IEquatable<CranesCollectionInfo>
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public string Description { get; private set; }
|
||||||
|
public CranesCollectionInfo(string name, string description)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
public bool Equals(CranesCollectionInfo? other)
|
||||||
|
{
|
||||||
|
|
||||||
|
return Name == other.Name;
|
||||||
|
}
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return this.Name.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
99
HoistingCrane/HoistingCrane/CranesGenericCollection.cs
Normal file
99
HoistingCrane/HoistingCrane/CranesGenericCollection.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using HoistingCrane.DrawningObjects;
|
||||||
|
using HoistingCrane.MovementStrategy;
|
||||||
|
|
||||||
|
namespace HoistingCrane.Generics
|
||||||
|
{
|
||||||
|
/// Параметризованный класс для набора объектов DrawningCar
|
||||||
|
internal class CranesGenericCollection<T, U>
|
||||||
|
where T : DrawingCrane
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
private readonly int _placeSizeWidth = 200;
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
private readonly int _placeSizeHeight = 150;
|
||||||
|
/// Набор объектов
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||||
|
public IEnumerable<T?> GetCranes => _collection.GetCranes();
|
||||||
|
/// Конструктор
|
||||||
|
public CranesGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
public static int operator +(CranesGenericCollection<T, U> collect, T? obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect._collection.Insert(obj, new DrawningCraneEqutables());
|
||||||
|
}
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
public static bool operator -(CranesGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection[pos];
|
||||||
|
return collect?._collection.Remove(pos) ?? false;
|
||||||
|
}
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
public Bitmap ShowCars()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{//линия разетки места
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
T? obj;
|
||||||
|
int j = _pictureWidth/_placeSizeWidth-1;
|
||||||
|
int k = _pictureHeight/_placeSizeHeight-1;
|
||||||
|
foreach (var crane in _collection.GetCranes())
|
||||||
|
{
|
||||||
|
if (j < 0)
|
||||||
|
{
|
||||||
|
j += _pictureWidth / _placeSizeWidth;
|
||||||
|
k--;
|
||||||
|
}
|
||||||
|
obj = crane;
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
obj.SetPosition(_placeSizeWidth * j, _placeSizeHeight * k);
|
||||||
|
obj.DrawTransport(g);
|
||||||
|
}
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
143
HoistingCrane/HoistingCrane/CranesGenericStorage.cs
Normal file
143
HoistingCrane/HoistingCrane/CranesGenericStorage.cs
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
using HoistingCrane.DrawningObjects;
|
||||||
|
using HoistingCrane.Generics;
|
||||||
|
using HoistingCrane.MovementStrategy;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace HoistingCrane
|
||||||
|
{
|
||||||
|
internal class CranesGenericStorage
|
||||||
|
{
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
Dictionary<CranesCollectionInfo, CranesGenericCollection<DrawingCrane, DrawningObjectsCrane>> _craneStorages;
|
||||||
|
/// Возвращение списка названий наборов
|
||||||
|
public List<CranesCollectionInfo> Keys => _craneStorages.Keys.ToList();
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
|
/// Разделитель для записей коллекции данных в файл
|
||||||
|
private readonly char _separatorRecords = ';';
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
/// Сохранение информации по автомобилям в хранилище в файл
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<CranesCollectionInfo, CranesGenericCollection<DrawingCrane, DrawningObjectsCrane>> record in _craneStorages)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
foreach (DrawingCrane? elem in record.Value.GetCranes)
|
||||||
|
{
|
||||||
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
|
}
|
||||||
|
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||||
|
}
|
||||||
|
if (data.Length == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Невалиданя операция, нет данных для сохранения");
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamWriter sw = new StreamWriter(filename))
|
||||||
|
{
|
||||||
|
sw.WriteLine("CarStorage");
|
||||||
|
sw.Write(data.ToString());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Файл не найден");
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamReader reader = new StreamReader(filename))
|
||||||
|
{
|
||||||
|
string cheker = reader.ReadLine();
|
||||||
|
if (cheker == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Нет данных для загрузки");
|
||||||
|
}
|
||||||
|
if (!cheker.StartsWith("CarStorage"))
|
||||||
|
{
|
||||||
|
throw new FormatException("Неверный формат данных");
|
||||||
|
}
|
||||||
|
_craneStorages.Clear();
|
||||||
|
string strs;
|
||||||
|
bool firstinit = true;
|
||||||
|
while ((strs = reader.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
if (strs == null && firstinit)
|
||||||
|
{
|
||||||
|
throw new Exception("Нет данных для загрузки");
|
||||||
|
}
|
||||||
|
firstinit = false;
|
||||||
|
string name = strs.Split(_separatorForKeyValue)[0];
|
||||||
|
CranesGenericCollection<DrawingCrane, DrawningObjectsCrane> collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
foreach (string data in strs.Split(_separatorForKeyValue)[1].Split(_separatorRecords))
|
||||||
|
{
|
||||||
|
DrawingCrane? crane =
|
||||||
|
data?.CreateDrawningCrane(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (crane != null)
|
||||||
|
{
|
||||||
|
int? result = collection + crane;
|
||||||
|
if (result == null || result.Value == -1)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка добавления в коллекцию");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_craneStorages.Add(new CranesCollectionInfo(name, string.Empty), collection);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Конструктор
|
||||||
|
public CranesGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_craneStorages = new Dictionary<CranesCollectionInfo, CranesGenericCollection<DrawingCrane, DrawningObjectsCrane>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// Добавление набора
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
if (_craneStorages.ContainsKey(new CranesCollectionInfo(name, string.Empty)))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Словарь уже содержит набор с таким названием", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_craneStorages.Add(new CranesCollectionInfo(name, string.Empty), new CranesGenericCollection<DrawingCrane, DrawningObjectsCrane>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Удаление набора
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
CranesGenericCollection<DrawingCrane, DrawningObjectsCrane> crane;
|
||||||
|
if (_craneStorages.TryGetValue(new CranesCollectionInfo(name, string.Empty), out crane))
|
||||||
|
{
|
||||||
|
_craneStorages.Remove(new CranesCollectionInfo(name, string.Empty));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Доступ к набору
|
||||||
|
public CranesGenericCollection<DrawingCrane, DrawningObjectsCrane>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
CranesCollectionInfo infCrane = new CranesCollectionInfo(ind, string.Empty);
|
||||||
|
if (_craneStorages.ContainsKey(infCrane)) return _craneStorages[infCrane];
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
HoistingCrane/HoistingCrane/Direction.cs
Normal file
11
HoistingCrane/HoistingCrane/Direction.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace HoistingCrane
|
||||||
|
{
|
||||||
|
public enum DirectionType
|
||||||
|
{
|
||||||
|
Up = 1,
|
||||||
|
Down = 2,
|
||||||
|
Left = 3,
|
||||||
|
Right = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
163
HoistingCrane/HoistingCrane/DrawingCrane.cs
Normal file
163
HoistingCrane/HoistingCrane/DrawingCrane.cs
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
using HoistingCrane.Entities;
|
||||||
|
using HoistingCrane.MovementStrategy;
|
||||||
|
|
||||||
|
namespace HoistingCrane.DrawningObjects
|
||||||
|
{
|
||||||
|
public class DrawingCrane
|
||||||
|
{
|
||||||
|
public EntityCrane? EntityCrane { get; protected set; }
|
||||||
|
|
||||||
|
private int _pictureWidth;
|
||||||
|
private int _pictureHeight;
|
||||||
|
|
||||||
|
protected int _startPositionX;
|
||||||
|
protected int _startPositionY;
|
||||||
|
|
||||||
|
protected readonly int _craneWidth = 200;
|
||||||
|
protected readonly int _craneHeight = 150;
|
||||||
|
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawningObjectsCrane(this);
|
||||||
|
public DrawingCrane(int speed, double weight, Color bodyColor, int width, int height)
|
||||||
|
{
|
||||||
|
if ((_craneWidth > width) || (_craneHeight > height)) return;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_pictureWidth = width;
|
||||||
|
EntityCrane = new EntityCrane(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
protected DrawingCrane(int speed, double weight, Color bodyColor, int width, int height, int craneWidth, int craneHeight)
|
||||||
|
{
|
||||||
|
if ((craneWidth > width) || (craneHeight > height)) return;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_craneHeight = craneHeight;
|
||||||
|
_craneWidth = craneWidth;
|
||||||
|
EntityCrane = new EntityCrane(speed, weight, bodyColor);
|
||||||
|
|
||||||
|
}
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
|
||||||
|
while (x + _craneWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
x -= _pictureWidth;
|
||||||
|
}
|
||||||
|
_startPositionX = x;
|
||||||
|
while (y + _craneHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
y -= _pictureHeight;
|
||||||
|
}
|
||||||
|
_startPositionY = y;
|
||||||
|
}
|
||||||
|
public void MoveCrane(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityCrane == null) return;
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (_startPositionX - EntityCrane.Step > 0)
|
||||||
|
{
|
||||||
|
_startPositionX -= (int)EntityCrane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DirectionType.Right:
|
||||||
|
if (_startPositionX + EntityCrane.Step + _craneWidth < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPositionX += (int)EntityCrane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_startPositionY - EntityCrane.Step > 0)
|
||||||
|
{
|
||||||
|
_startPositionY -= (int)EntityCrane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (_startPositionY + EntityCrane.Step + _craneHeight < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPositionY += (int)EntityCrane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public int GetPosX => _startPositionX;
|
||||||
|
public int GetPosY => _startPositionY;
|
||||||
|
|
||||||
|
public int GetWidth => _craneWidth;
|
||||||
|
public int GetHeight => _craneHeight;
|
||||||
|
public bool CanMove(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityCrane == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
DirectionType.Left => _startPositionX - EntityCrane.Step > 0,
|
||||||
|
//вверх
|
||||||
|
DirectionType.Up => _startPositionY - EntityCrane.Step > 0,
|
||||||
|
// вправо
|
||||||
|
DirectionType.Right => _startPositionX + EntityCrane.Step - _craneWidth < _pictureWidth,
|
||||||
|
//вниз
|
||||||
|
DirectionType.Down => _startPositionY + EntityCrane.Step - _craneHeight < _pictureHeight
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction) || EntityCrane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case DirectionType.Left:
|
||||||
|
_startPositionX -= (int)EntityCrane.Step;
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case DirectionType.Up:
|
||||||
|
_startPositionY -= (int)EntityCrane.Step;
|
||||||
|
break;
|
||||||
|
// вправо
|
||||||
|
case DirectionType.Right:
|
||||||
|
_startPositionX += (int)EntityCrane.Step;
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case DirectionType.Down:
|
||||||
|
_startPositionY += (int)EntityCrane.Step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityCrane == null) return;
|
||||||
|
Pen pen = new Pen(Color.Black);
|
||||||
|
Brush bodybrush = new SolidBrush(EntityCrane.BodyColor);
|
||||||
|
// Гусеницы
|
||||||
|
g.DrawLine(pen, _startPositionX + 5, _startPositionY + 110, _startPositionX + 195, _startPositionY + 110);
|
||||||
|
g.DrawLine(pen, _startPositionX, _startPositionY + 115, _startPositionX, _startPositionY + 145);
|
||||||
|
g.DrawLine(pen, _startPositionX + 5, _startPositionY + 150, _startPositionX + 195, _startPositionY + 150);
|
||||||
|
g.DrawLine(pen, _startPositionX + 200, _startPositionY + 115, _startPositionX + 200, _startPositionY + 145);
|
||||||
|
g.DrawArc(pen, _startPositionX, _startPositionY + 110, _craneWidth / 20, _craneHeight / 15, 135, 180);
|
||||||
|
g.DrawArc(pen, _startPositionX, _startPositionY + 140, _craneWidth / 20, _craneHeight / 15, 45, 180);
|
||||||
|
g.DrawArc(pen, _startPositionX + 190, _startPositionY + 110, _craneWidth / 20, _craneHeight / 20, 225, 180);
|
||||||
|
g.DrawArc(pen, _startPositionX + 190, _startPositionY + 143, _craneWidth / 20, _craneHeight / 20, 315, 180);
|
||||||
|
// основное тело
|
||||||
|
g.DrawRectangle(pen, _startPositionX + 10, _startPositionY + 65, 180, 40);
|
||||||
|
g.FillRectangle(bodybrush, _startPositionX + 10, _startPositionY + 65, 180, 40);
|
||||||
|
//катки
|
||||||
|
g.DrawEllipse(pen, _startPositionX + 2, _startPositionY + 112, 36, 36);
|
||||||
|
g.DrawEllipse(pen, _startPositionX + 160, _startPositionY + 112, 36, 36);
|
||||||
|
g.DrawEllipse(pen, _startPositionX + 45, _startPositionY + 128, 20, 20);
|
||||||
|
g.DrawEllipse(pen, _startPositionX + 89, _startPositionY + 128, 20, 20);
|
||||||
|
g.DrawEllipse(pen, _startPositionX + 133, _startPositionY + 128, 20, 20);
|
||||||
|
g.DrawEllipse(pen, _startPositionX + 74, _startPositionY + 112, 10, 10);
|
||||||
|
g.DrawEllipse(pen, _startPositionX + 111, _startPositionY + 112, 10, 10);
|
||||||
|
//кабинка и выхлоп
|
||||||
|
g.DrawRectangle(pen, _startPositionX + 60, _startPositionY + 10, 20, 55);
|
||||||
|
g.DrawRectangle(pen, _startPositionX + 110, _startPositionY, 75, 65);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
58
HoistingCrane/HoistingCrane/DrawningCraneEqutables.cs
Normal file
58
HoistingCrane/HoistingCrane/DrawningCraneEqutables.cs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
using HoistingCrane.DrawningObjects;
|
||||||
|
using HoistingCrane.Entities;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
namespace HoistingCrane.Generics
|
||||||
|
{
|
||||||
|
internal class DrawningCraneEqutables : IEqualityComparer<DrawingCrane?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawingCrane? x, DrawingCrane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityCrane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityCrane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityCrane.Speed != y.EntityCrane.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityCrane.Weight != y.EntityCrane.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityCrane.BodyColor != y.EntityCrane.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x is AdditionalDrawingCrane && y is AdditionalDrawingCrane)
|
||||||
|
{
|
||||||
|
AdditionEntityCrane _x = (AdditionEntityCrane)x.EntityCrane;
|
||||||
|
AdditionEntityCrane _y = (AdditionEntityCrane)y.EntityCrane;
|
||||||
|
if(_x.AdditionalColor != _y.AdditionalColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_x.Speed != _y.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_x.Weight != _y.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public int GetHashCode([DisallowNull] DrawingCrane obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
HoistingCrane/HoistingCrane/DrawningObjectsCrane.cs
Normal file
27
HoistingCrane/HoistingCrane/DrawningObjectsCrane.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using HoistingCrane.DrawningObjects;
|
||||||
|
|
||||||
|
namespace HoistingCrane.MovementStrategy
|
||||||
|
{
|
||||||
|
public class DrawningObjectsCrane : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawingCrane? _drawingCrane = null;
|
||||||
|
public DrawningObjectsCrane(DrawingCrane drawingCrane)
|
||||||
|
{
|
||||||
|
_drawingCrane = drawingCrane;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawingCrane == null || _drawingCrane.EntityCrane == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawingCrane.GetPosX, _drawingCrane.GetPosY, _drawingCrane.GetWidth, _drawingCrane.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawingCrane?.EntityCrane?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(DirectionType direction) => _drawingCrane?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(DirectionType direction) => _drawingCrane?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
20
HoistingCrane/HoistingCrane/EntityCrane.cs
Normal file
20
HoistingCrane/HoistingCrane/EntityCrane.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
namespace HoistingCrane.Entities
|
||||||
|
{
|
||||||
|
public class EntityCrane
|
||||||
|
{
|
||||||
|
//скорость
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
//вес
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
//основной цввет
|
||||||
|
public Color BodyColor { get; set; }
|
||||||
|
//шаг перемещения
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
public EntityCrane(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
HoistingCrane/HoistingCrane/ExtentionDrawningCrane.cs
Normal file
50
HoistingCrane/HoistingCrane/ExtentionDrawningCrane.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using HoistingCrane.Entities;
|
||||||
|
|
||||||
|
namespace HoistingCrane.DrawningObjects
|
||||||
|
{
|
||||||
|
public static class ExtentionDrawningCrane
|
||||||
|
{
|
||||||
|
|
||||||
|
public static DrawingCrane? CreateDrawningCrane(this string info, char separatorForObject, int width, int height)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawingCrane(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new AdditionalDrawingCrane(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]),
|
||||||
|
Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5]),
|
||||||
|
width, height);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningCar">Сохраняемый объект</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <returns>Строка с данными по объекту</returns>
|
||||||
|
public static string GetDataForSave(this DrawingCrane drawningCrane,
|
||||||
|
char separatorForObject)
|
||||||
|
{
|
||||||
|
var car = drawningCrane.EntityCrane;
|
||||||
|
if (car == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
var str = $"{car.Speed}{separatorForObject}{car.Weight}{separatorForObject}{car.BodyColor.Name}";
|
||||||
|
if (car is not AdditionEntityCrane hoistingCrane)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return $"{str}{separatorForObject}{hoistingCrane.AdditionalColor.Name}{separatorForObject}{hoistingCrane.Crane}{separatorForObject}{hoistingCrane.CounterWeight}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
HoistingCrane/HoistingCrane/Form1.Designer.cs
generated
39
HoistingCrane/HoistingCrane/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace HoistingCrane
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form1";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace HoistingCrane
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<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:import namespace="http://www.w3.org/XML/1998/namespace" />
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<value>2.0</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="reader">
|
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
</root>
|
|
278
HoistingCrane/HoistingCrane/FormCraneCollection.Designer.cs
generated
Normal file
278
HoistingCrane/HoistingCrane/FormCraneCollection.Designer.cs
generated
Normal file
@ -0,0 +1,278 @@
|
|||||||
|
namespace HoistingCrane
|
||||||
|
{
|
||||||
|
partial class FormCraneCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.groupBoxInstruments = new System.Windows.Forms.GroupBox();
|
||||||
|
this.groupBoxSet = new System.Windows.Forms.GroupBox();
|
||||||
|
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonAddSet = new System.Windows.Forms.Button();
|
||||||
|
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||||
|
this.buttonRemoveSet = new System.Windows.Forms.Button();
|
||||||
|
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.buttonReload = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDelete = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSortByColor = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSortByType = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||||
|
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||||
|
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.ToolStripMenuItemLoad = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.ToolStripMenuItemSave = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||||
|
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||||
|
this.groupBoxInstruments.SuspendLayout();
|
||||||
|
this.groupBoxSet.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||||
|
this.menuStrip1.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxInstruments
|
||||||
|
//
|
||||||
|
this.groupBoxInstruments.Controls.Add(this.groupBoxSet);
|
||||||
|
this.groupBoxInstruments.Controls.Add(this.maskedTextBoxNumber);
|
||||||
|
this.groupBoxInstruments.Controls.Add(this.buttonReload);
|
||||||
|
this.groupBoxInstruments.Controls.Add(this.buttonDelete);
|
||||||
|
this.groupBoxInstruments.Controls.Add(this.buttonAdd);
|
||||||
|
this.groupBoxInstruments.Controls.Add(this.buttonSortByColor);
|
||||||
|
this.groupBoxInstruments.Controls.Add(this.buttonSortByType);
|
||||||
|
this.groupBoxInstruments.Location = new System.Drawing.Point(806, 0);
|
||||||
|
this.groupBoxInstruments.Name = "groupBoxInstruments";
|
||||||
|
this.groupBoxInstruments.Size = new System.Drawing.Size(192, 511);
|
||||||
|
this.groupBoxInstruments.TabIndex = 0;
|
||||||
|
this.groupBoxInstruments.TabStop = false;
|
||||||
|
this.groupBoxInstruments.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// groupBoxSet
|
||||||
|
//
|
||||||
|
this.groupBoxSet.Controls.Add(this.textBoxStorageName);
|
||||||
|
this.groupBoxSet.Controls.Add(this.buttonAddSet);
|
||||||
|
this.groupBoxSet.Controls.Add(this.listBoxStorages);
|
||||||
|
this.groupBoxSet.Controls.Add(this.buttonRemoveSet);
|
||||||
|
this.groupBoxSet.Location = new System.Drawing.Point(6, 21);
|
||||||
|
this.groupBoxSet.Name = "groupBoxSet";
|
||||||
|
this.groupBoxSet.Size = new System.Drawing.Size(179, 257);
|
||||||
|
this.groupBoxSet.TabIndex = 6;
|
||||||
|
this.groupBoxSet.TabStop = false;
|
||||||
|
this.groupBoxSet.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
this.textBoxStorageName.Location = new System.Drawing.Point(6, 30);
|
||||||
|
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
this.textBoxStorageName.Size = new System.Drawing.Size(150, 31);
|
||||||
|
this.textBoxStorageName.TabIndex = 14;
|
||||||
|
//
|
||||||
|
// buttonAddSet
|
||||||
|
//
|
||||||
|
this.buttonAddSet.Location = new System.Drawing.Point(-6, 65);
|
||||||
|
this.buttonAddSet.Name = "buttonAddSet";
|
||||||
|
this.buttonAddSet.Size = new System.Drawing.Size(191, 35);
|
||||||
|
this.buttonAddSet.TabIndex = 12;
|
||||||
|
this.buttonAddSet.Text = "Добавить набор";
|
||||||
|
this.buttonAddSet.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddSet.Click += new System.EventHandler(this.ButtonAddObject_Click);
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
this.listBoxStorages.FormattingEnabled = true;
|
||||||
|
this.listBoxStorages.ItemHeight = 25;
|
||||||
|
this.listBoxStorages.Location = new System.Drawing.Point(6, 106);
|
||||||
|
this.listBoxStorages.Name = "listBoxStorages";
|
||||||
|
this.listBoxStorages.Size = new System.Drawing.Size(167, 104);
|
||||||
|
this.listBoxStorages.TabIndex = 13;
|
||||||
|
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// buttonRemoveSet
|
||||||
|
//
|
||||||
|
this.buttonRemoveSet.Location = new System.Drawing.Point(-1, 216);
|
||||||
|
this.buttonRemoveSet.Name = "buttonRemoveSet";
|
||||||
|
this.buttonRemoveSet.Size = new System.Drawing.Size(181, 35);
|
||||||
|
this.buttonRemoveSet.TabIndex = 11;
|
||||||
|
this.buttonRemoveSet.Text = "Удалить набор";
|
||||||
|
this.buttonRemoveSet.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRemoveSet.Click += new System.EventHandler(this.ButtonDelObject_Click);
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
this.maskedTextBoxNumber.Location = new System.Drawing.Point(29, 398);
|
||||||
|
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
this.maskedTextBoxNumber.Size = new System.Drawing.Size(150, 31);
|
||||||
|
this.maskedTextBoxNumber.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// buttonReload
|
||||||
|
//
|
||||||
|
this.buttonReload.Location = new System.Drawing.Point(0, 476);
|
||||||
|
this.buttonReload.Name = "buttonReload";
|
||||||
|
this.buttonReload.Size = new System.Drawing.Size(191, 35);
|
||||||
|
this.buttonReload.TabIndex = 8;
|
||||||
|
this.buttonReload.Text = "Обновить экран";
|
||||||
|
this.buttonReload.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonReload.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
this.buttonDelete.Location = new System.Drawing.Point(0, 435);
|
||||||
|
this.buttonDelete.Name = "buttonDelete";
|
||||||
|
this.buttonDelete.Size = new System.Drawing.Size(191, 35);
|
||||||
|
this.buttonDelete.TabIndex = 7;
|
||||||
|
this.buttonDelete.Text = "Удалить кран";
|
||||||
|
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDelete.Click += new System.EventHandler(this.ButtonRemoveCrane_Click);
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(1, 357);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(191, 35);
|
||||||
|
this.buttonAdd.TabIndex = 6;
|
||||||
|
this.buttonAdd.Text = "Добавить кран";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAddCrane_Click);
|
||||||
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
this.buttonSortByColor.Location = new System.Drawing.Point(-1, 319);
|
||||||
|
this.buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
this.buttonSortByColor.Size = new System.Drawing.Size(199, 36);
|
||||||
|
this.buttonSortByColor.TabIndex = 15;
|
||||||
|
this.buttonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
this.buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
this.buttonSortByType.Location = new System.Drawing.Point(0, 278);
|
||||||
|
this.buttonSortByType.Name = "buttonSortByType";
|
||||||
|
this.buttonSortByType.Size = new System.Drawing.Size(198, 35);
|
||||||
|
this.buttonSortByType.TabIndex = 14;
|
||||||
|
this.buttonSortByType.Text = "Сортировка по типу";
|
||||||
|
this.buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
this.pictureBoxCollection.Size = new System.Drawing.Size(998, 478);
|
||||||
|
this.pictureBoxCollection.TabIndex = 5;
|
||||||
|
this.pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// menuStrip1
|
||||||
|
//
|
||||||
|
this.menuStrip1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||||
|
this.menuStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Visible;
|
||||||
|
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
|
||||||
|
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.файлToolStripMenuItem});
|
||||||
|
this.menuStrip1.Location = new System.Drawing.Point(0, 478);
|
||||||
|
this.menuStrip1.Name = "menuStrip1";
|
||||||
|
this.menuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
|
||||||
|
this.menuStrip1.Size = new System.Drawing.Size(998, 33);
|
||||||
|
this.menuStrip1.TabIndex = 12;
|
||||||
|
this.menuStrip1.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// файлToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.ToolStripMenuItemLoad,
|
||||||
|
this.ToolStripMenuItemSave});
|
||||||
|
this.файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||||
|
this.файлToolStripMenuItem.Size = new System.Drawing.Size(68, 29);
|
||||||
|
this.файлToolStripMenuItem.Text = "файл";
|
||||||
|
//
|
||||||
|
// ToolStripMenuItemLoad
|
||||||
|
//
|
||||||
|
this.ToolStripMenuItemLoad.Name = "ToolStripMenuItemLoad";
|
||||||
|
this.ToolStripMenuItemLoad.Size = new System.Drawing.Size(197, 34);
|
||||||
|
this.ToolStripMenuItemLoad.Text = "загрузить";
|
||||||
|
this.ToolStripMenuItemLoad.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// ToolStripMenuItemSave
|
||||||
|
//
|
||||||
|
this.ToolStripMenuItemSave.Name = "ToolStripMenuItemSave";
|
||||||
|
this.ToolStripMenuItemSave.Size = new System.Drawing.Size(197, 34);
|
||||||
|
this.ToolStripMenuItemSave.Text = "сохранить";
|
||||||
|
this.ToolStripMenuItemSave.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
this.openFileDialog.FileName = "openFileDialog1";
|
||||||
|
this.openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// FormCraneCollection
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(998, 511);
|
||||||
|
this.Controls.Add(this.groupBoxInstruments);
|
||||||
|
this.Controls.Add(this.pictureBoxCollection);
|
||||||
|
this.Controls.Add(this.menuStrip1);
|
||||||
|
this.Name = "FormCraneCollection";
|
||||||
|
this.Text = "Набор кранов";
|
||||||
|
this.groupBoxInstruments.ResumeLayout(false);
|
||||||
|
this.groupBoxInstruments.PerformLayout();
|
||||||
|
this.groupBoxSet.ResumeLayout(false);
|
||||||
|
this.groupBoxSet.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||||
|
this.menuStrip1.ResumeLayout(false);
|
||||||
|
this.menuStrip1.PerformLayout();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxInstruments;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private Button buttonReload;
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private GroupBox groupBoxSet;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
private Button buttonAddSet;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button buttonRemoveSet;
|
||||||
|
private MenuStrip menuStrip1;
|
||||||
|
private ToolStripMenuItem файлToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem ToolStripMenuItemLoad;
|
||||||
|
private ToolStripMenuItem ToolStripMenuItemSave;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button buttonSortByColor;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
}
|
||||||
|
}
|
228
HoistingCrane/HoistingCrane/FormCraneCollection.cs
Normal file
228
HoistingCrane/HoistingCrane/FormCraneCollection.cs
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
using HoistingCrane.DrawningObjects;
|
||||||
|
using HoistingCrane.Exceptions;
|
||||||
|
using HoistingCrane.Generics;
|
||||||
|
using HoistingCrane.MovementStrategy;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace HoistingCrane
|
||||||
|
{
|
||||||
|
public partial class FormCraneCollection : Form
|
||||||
|
{
|
||||||
|
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareCranes(new CraneCompareByType());
|
||||||
|
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareCranes(new CraneCompareByColor());
|
||||||
|
}
|
||||||
|
private void CompareCranes(IComparer<DrawingCrane?> comparer)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
obj.Sort(comparer);
|
||||||
|
pictureBoxCollection.Image = obj.ShowCars();
|
||||||
|
}
|
||||||
|
private readonly CranesGenericStorage _storage;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
public FormCraneCollection(ILogger<FormCraneCollection> logger)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_storage = new CranesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorages.SelectedIndex;
|
||||||
|
listBoxStorages.Items.Clear();
|
||||||
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxStorages.Items.Add(_storage.Keys[i].Name);
|
||||||
|
}
|
||||||
|
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 SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storage.SaveData(saveFileDialog.FileName);
|
||||||
|
MessageBox.Show("Сохранение прошло успешно",
|
||||||
|
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogInformation($"Файл сохранен {saveFileDialog.FileName}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Не сохранилось: {ex.Message}",
|
||||||
|
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storage.LoadData(openFileDialog.FileName);
|
||||||
|
MessageBox.Show("Загрузка прошло успешно",
|
||||||
|
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
ReloadObjects();
|
||||||
|
_logger.LogInformation($"Файл загружен {openFileDialog.FileName}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Не загрузилось {ex.Message}", "Результат",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
_logger.LogInformation($"Добавлен набор:{textBoxStorageName.Text}");
|
||||||
|
}
|
||||||
|
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image =
|
||||||
|
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowCars();
|
||||||
|
}
|
||||||
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||||
|
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
||||||
|
?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
_logger.LogInformation($"Удален набор: {name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonAddCrane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var formCraneConfig = new FormCraneConfig();
|
||||||
|
formCraneConfig.AddEvent(crane =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex != -1)
|
||||||
|
{
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty];
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
if (obj + crane != 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = obj.ShowCars();
|
||||||
|
_logger.LogInformation("Объект добавлен");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (StorageOverflowException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
_logger.LogWarning(ex.Message);
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
_logger.LogWarning(ex.Message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
formCraneConfig.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void ButtonRemoveCrane_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("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (obj - pos)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = obj.ShowCars();
|
||||||
|
_logger.LogInformation("Объект удален");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (CraneNotFoundException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
_logger.LogWarning(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowCars();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
72
HoistingCrane/HoistingCrane/FormCraneCollection.resx
Normal file
72
HoistingCrane/HoistingCrane/FormCraneCollection.resx
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<root>
|
||||||
|
<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:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>173, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>367, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>27</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
394
HoistingCrane/HoistingCrane/FormCraneConfig.Designer.cs
generated
Normal file
394
HoistingCrane/HoistingCrane/FormCraneConfig.Designer.cs
generated
Normal file
@ -0,0 +1,394 @@
|
|||||||
|
namespace HoistingCrane
|
||||||
|
{
|
||||||
|
partial class FormCraneConfig
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.labelSpeed = new System.Windows.Forms.Label();
|
||||||
|
this.labelWeight = new System.Windows.Forms.Label();
|
||||||
|
this.groupBoxParametres = new System.Windows.Forms.GroupBox();
|
||||||
|
this.labelModifiedObject = new System.Windows.Forms.Label();
|
||||||
|
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||||
|
this.groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||||
|
this.panelWhite = new System.Windows.Forms.Panel();
|
||||||
|
this.panelYellow = new System.Windows.Forms.Panel();
|
||||||
|
this.panelGreen = new System.Windows.Forms.Panel();
|
||||||
|
this.panelBlack = new System.Windows.Forms.Panel();
|
||||||
|
this.panelGray = new System.Windows.Forms.Panel();
|
||||||
|
this.panelPurple = new System.Windows.Forms.Panel();
|
||||||
|
this.panelBlue = new System.Windows.Forms.Panel();
|
||||||
|
this.panelRed = new System.Windows.Forms.Panel();
|
||||||
|
this.checkBoxCounterweight = new System.Windows.Forms.CheckBox();
|
||||||
|
this.checkBoxCrane = new System.Windows.Forms.CheckBox();
|
||||||
|
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBoxCrane = new System.Windows.Forms.PictureBox();
|
||||||
|
this.labelAdditionalColor = new System.Windows.Forms.Label();
|
||||||
|
this.labelBodyColor = new System.Windows.Forms.Label();
|
||||||
|
this.panelColor = new System.Windows.Forms.Panel();
|
||||||
|
this.groupBoxParametres.SuspendLayout();
|
||||||
|
this.groupBoxColors.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCrane)).BeginInit();
|
||||||
|
this.panelColor.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelSpeed
|
||||||
|
//
|
||||||
|
this.labelSpeed.AutoSize = true;
|
||||||
|
this.labelSpeed.Location = new System.Drawing.Point(6, 27);
|
||||||
|
this.labelSpeed.Name = "labelSpeed";
|
||||||
|
this.labelSpeed.Size = new System.Drawing.Size(89, 25);
|
||||||
|
this.labelSpeed.TabIndex = 0;
|
||||||
|
this.labelSpeed.Text = "Скорость";
|
||||||
|
//
|
||||||
|
// labelWeight
|
||||||
|
//
|
||||||
|
this.labelWeight.AutoSize = true;
|
||||||
|
this.labelWeight.Location = new System.Drawing.Point(12, 70);
|
||||||
|
this.labelWeight.Name = "labelWeight";
|
||||||
|
this.labelWeight.Size = new System.Drawing.Size(39, 25);
|
||||||
|
this.labelWeight.TabIndex = 1;
|
||||||
|
this.labelWeight.Text = "Вес";
|
||||||
|
//
|
||||||
|
// groupBoxParametres
|
||||||
|
//
|
||||||
|
this.groupBoxParametres.Controls.Add(this.labelModifiedObject);
|
||||||
|
this.groupBoxParametres.Controls.Add(this.labelSimpleObject);
|
||||||
|
this.groupBoxParametres.Controls.Add(this.groupBoxColors);
|
||||||
|
this.groupBoxParametres.Controls.Add(this.checkBoxCounterweight);
|
||||||
|
this.groupBoxParametres.Controls.Add(this.checkBoxCrane);
|
||||||
|
this.groupBoxParametres.Controls.Add(this.numericUpDownWeight);
|
||||||
|
this.groupBoxParametres.Controls.Add(this.numericUpDownSpeed);
|
||||||
|
this.groupBoxParametres.Controls.Add(this.labelSpeed);
|
||||||
|
this.groupBoxParametres.Controls.Add(this.labelWeight);
|
||||||
|
this.groupBoxParametres.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.groupBoxParametres.Name = "groupBoxParametres";
|
||||||
|
this.groupBoxParametres.Size = new System.Drawing.Size(540, 304);
|
||||||
|
this.groupBoxParametres.TabIndex = 2;
|
||||||
|
this.groupBoxParametres.TabStop = false;
|
||||||
|
this.groupBoxParametres.Text = "Параметры";
|
||||||
|
//
|
||||||
|
// labelModifiedObject
|
||||||
|
//
|
||||||
|
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelModifiedObject.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
this.labelModifiedObject.Location = new System.Drawing.Point(394, 210);
|
||||||
|
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||||
|
this.labelModifiedObject.Size = new System.Drawing.Size(115, 56);
|
||||||
|
this.labelModifiedObject.TabIndex = 7;
|
||||||
|
this.labelModifiedObject.Text = "Продвинутый";
|
||||||
|
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// labelSimpleObject
|
||||||
|
//
|
||||||
|
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelSimpleObject.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
this.labelSimpleObject.Location = new System.Drawing.Point(247, 210);
|
||||||
|
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||||
|
this.labelSimpleObject.Size = new System.Drawing.Size(115, 56);
|
||||||
|
this.labelSimpleObject.TabIndex = 3;
|
||||||
|
this.labelSimpleObject.Text = "Простой";
|
||||||
|
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// groupBoxColors
|
||||||
|
//
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelWhite);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelYellow);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelBlack);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelGray);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelPurple);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelBlue);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||||
|
this.groupBoxColors.Location = new System.Drawing.Point(247, 25);
|
||||||
|
this.groupBoxColors.Name = "groupBoxColors";
|
||||||
|
this.groupBoxColors.Size = new System.Drawing.Size(271, 159);
|
||||||
|
this.groupBoxColors.TabIndex = 6;
|
||||||
|
this.groupBoxColors.TabStop = false;
|
||||||
|
this.groupBoxColors.Text = "Цвета";
|
||||||
|
//
|
||||||
|
// panelWhite
|
||||||
|
//
|
||||||
|
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||||
|
this.panelWhite.Location = new System.Drawing.Point(214, 96);
|
||||||
|
this.panelWhite.Name = "panelWhite";
|
||||||
|
this.panelWhite.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.panelWhite.TabIndex = 21;
|
||||||
|
this.panelWhite.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelYellow
|
||||||
|
//
|
||||||
|
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||||
|
this.panelYellow.Location = new System.Drawing.Point(214, 34);
|
||||||
|
this.panelYellow.Name = "panelYellow";
|
||||||
|
this.panelYellow.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.panelYellow.TabIndex = 17;
|
||||||
|
this.panelYellow.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelGreen
|
||||||
|
//
|
||||||
|
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
||||||
|
this.panelGreen.Location = new System.Drawing.Point(147, 96);
|
||||||
|
this.panelGreen.Name = "panelGreen";
|
||||||
|
this.panelGreen.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.panelGreen.TabIndex = 20;
|
||||||
|
this.panelGreen.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelBlack
|
||||||
|
//
|
||||||
|
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||||
|
this.panelBlack.Location = new System.Drawing.Point(147, 34);
|
||||||
|
this.panelBlack.Name = "panelBlack";
|
||||||
|
this.panelBlack.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.panelBlack.TabIndex = 16;
|
||||||
|
this.panelBlack.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelGray
|
||||||
|
//
|
||||||
|
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||||
|
this.panelGray.Location = new System.Drawing.Point(75, 96);
|
||||||
|
this.panelGray.Name = "panelGray";
|
||||||
|
this.panelGray.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.panelGray.TabIndex = 19;
|
||||||
|
this.panelGray.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelPurple
|
||||||
|
//
|
||||||
|
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||||
|
this.panelPurple.Location = new System.Drawing.Point(6, 96);
|
||||||
|
this.panelPurple.Name = "panelPurple";
|
||||||
|
this.panelPurple.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.panelPurple.TabIndex = 18;
|
||||||
|
this.panelPurple.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelBlue
|
||||||
|
//
|
||||||
|
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||||
|
this.panelBlue.Location = new System.Drawing.Point(75, 34);
|
||||||
|
this.panelBlue.Name = "panelBlue";
|
||||||
|
this.panelBlue.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.panelBlue.TabIndex = 15;
|
||||||
|
this.panelBlue.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelRed
|
||||||
|
//
|
||||||
|
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||||
|
this.panelRed.Location = new System.Drawing.Point(6, 34);
|
||||||
|
this.panelRed.Name = "panelRed";
|
||||||
|
this.panelRed.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.panelRed.TabIndex = 14;
|
||||||
|
this.panelRed.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// checkBoxCounterweight
|
||||||
|
//
|
||||||
|
this.checkBoxCounterweight.AutoSize = true;
|
||||||
|
this.checkBoxCounterweight.Location = new System.Drawing.Point(12, 155);
|
||||||
|
this.checkBoxCounterweight.Name = "checkBoxCounterweight";
|
||||||
|
this.checkBoxCounterweight.Size = new System.Drawing.Size(138, 29);
|
||||||
|
this.checkBoxCounterweight.TabIndex = 5;
|
||||||
|
this.checkBoxCounterweight.Text = "Противовес";
|
||||||
|
this.checkBoxCounterweight.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxCrane
|
||||||
|
//
|
||||||
|
this.checkBoxCrane.AutoSize = true;
|
||||||
|
this.checkBoxCrane.Location = new System.Drawing.Point(12, 118);
|
||||||
|
this.checkBoxCrane.Name = "checkBoxCrane";
|
||||||
|
this.checkBoxCrane.Size = new System.Drawing.Size(78, 29);
|
||||||
|
this.checkBoxCrane.TabIndex = 4;
|
||||||
|
this.checkBoxCrane.Text = "Кран";
|
||||||
|
this.checkBoxCrane.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericUpDownWeight
|
||||||
|
//
|
||||||
|
this.numericUpDownWeight.Location = new System.Drawing.Point(138, 68);
|
||||||
|
this.numericUpDownWeight.Maximum = new decimal(new int[] {
|
||||||
|
1000,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpDownWeight.Minimum = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||||
|
this.numericUpDownWeight.Size = new System.Drawing.Size(85, 31);
|
||||||
|
this.numericUpDownWeight.TabIndex = 3;
|
||||||
|
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// numericUpDownSpeed
|
||||||
|
//
|
||||||
|
this.numericUpDownSpeed.Location = new System.Drawing.Point(138, 25);
|
||||||
|
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
|
||||||
|
1000,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||||
|
this.numericUpDownSpeed.Size = new System.Drawing.Size(85, 31);
|
||||||
|
this.numericUpDownSpeed.TabIndex = 2;
|
||||||
|
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(147, 241);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(112, 34);
|
||||||
|
this.buttonCancel.TabIndex = 4;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(3, 241);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(112, 34);
|
||||||
|
this.buttonAdd.TabIndex = 3;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonOK_Click);
|
||||||
|
//
|
||||||
|
// pictureBoxCrane
|
||||||
|
//
|
||||||
|
this.pictureBoxCrane.Location = new System.Drawing.Point(3, 72);
|
||||||
|
this.pictureBoxCrane.Name = "pictureBoxCrane";
|
||||||
|
this.pictureBoxCrane.Size = new System.Drawing.Size(256, 163);
|
||||||
|
this.pictureBoxCrane.TabIndex = 2;
|
||||||
|
this.pictureBoxCrane.TabStop = false;
|
||||||
|
//
|
||||||
|
// labelAdditionalColor
|
||||||
|
//
|
||||||
|
this.labelAdditionalColor.AllowDrop = true;
|
||||||
|
this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelAdditionalColor.Location = new System.Drawing.Point(134, 13);
|
||||||
|
this.labelAdditionalColor.Name = "labelAdditionalColor";
|
||||||
|
this.labelAdditionalColor.Size = new System.Drawing.Size(125, 56);
|
||||||
|
this.labelAdditionalColor.TabIndex = 0;
|
||||||
|
this.labelAdditionalColor.Text = "Доп. цвет";
|
||||||
|
this.labelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelAdditionalColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelAddBoxColor_DragDrop);
|
||||||
|
this.labelAdditionalColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||||
|
this.labelAdditionalColor.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// labelBodyColor
|
||||||
|
//
|
||||||
|
this.labelBodyColor.AllowDrop = true;
|
||||||
|
this.labelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelBodyColor.Location = new System.Drawing.Point(3, 13);
|
||||||
|
this.labelBodyColor.Name = "labelBodyColor";
|
||||||
|
this.labelBodyColor.Size = new System.Drawing.Size(125, 56);
|
||||||
|
this.labelBodyColor.TabIndex = 0;
|
||||||
|
this.labelBodyColor.Text = "Цвет";
|
||||||
|
this.labelBodyColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelBodyColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
||||||
|
this.labelBodyColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||||
|
this.labelBodyColor.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// panelColor
|
||||||
|
//
|
||||||
|
this.panelColor.AllowDrop = true;
|
||||||
|
this.panelColor.Controls.Add(this.pictureBoxCrane);
|
||||||
|
this.panelColor.Controls.Add(this.buttonCancel);
|
||||||
|
this.panelColor.Controls.Add(this.labelBodyColor);
|
||||||
|
this.panelColor.Controls.Add(this.buttonAdd);
|
||||||
|
this.panelColor.Controls.Add(this.labelAdditionalColor);
|
||||||
|
this.panelColor.Location = new System.Drawing.Point(546, 12);
|
||||||
|
this.panelColor.Name = "panelColor";
|
||||||
|
this.panelColor.Size = new System.Drawing.Size(262, 278);
|
||||||
|
this.panelColor.TabIndex = 5;
|
||||||
|
this.panelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||||
|
this.panelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||||
|
this.panelColor.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// FormCraneConfig
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(807, 302);
|
||||||
|
this.Controls.Add(this.panelColor);
|
||||||
|
this.Controls.Add(this.groupBoxParametres);
|
||||||
|
this.Name = "FormCraneConfig";
|
||||||
|
this.Text = "FormCraneConfig";
|
||||||
|
this.groupBoxParametres.ResumeLayout(false);
|
||||||
|
this.groupBoxParametres.PerformLayout();
|
||||||
|
this.groupBoxColors.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCrane)).EndInit();
|
||||||
|
this.panelColor.ResumeLayout(false);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label labelSpeed;
|
||||||
|
private Label labelWeight;
|
||||||
|
private GroupBox groupBoxParametres;
|
||||||
|
private Label labelModifiedObject;
|
||||||
|
private Label labelSimpleObject;
|
||||||
|
private GroupBox groupBoxColors;
|
||||||
|
private CheckBox checkBoxCounterweight;
|
||||||
|
private CheckBox checkBoxCrane;
|
||||||
|
private NumericUpDown numericUpDownWeight;
|
||||||
|
private NumericUpDown numericUpDownSpeed;
|
||||||
|
private PictureBox pictureBoxCrane;
|
||||||
|
private Label labelAdditionalColor;
|
||||||
|
private Label labelBodyColor;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private Panel panelColor;
|
||||||
|
private Panel panelWhite;
|
||||||
|
private Panel panelYellow;
|
||||||
|
private Panel panelGreen;
|
||||||
|
private Panel panelBlack;
|
||||||
|
private Panel panelGray;
|
||||||
|
private Panel panelPurple;
|
||||||
|
private Panel panelBlue;
|
||||||
|
private Panel panelRed;
|
||||||
|
}
|
||||||
|
}
|
169
HoistingCrane/HoistingCrane/FormCraneConfig.cs
Normal file
169
HoistingCrane/HoistingCrane/FormCraneConfig.cs
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
|
||||||
|
using HoistingCrane.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 HoistingCrane.Entities;
|
||||||
|
|
||||||
|
namespace HoistingCrane
|
||||||
|
{
|
||||||
|
public partial class FormCraneConfig : Form
|
||||||
|
{
|
||||||
|
private event Action<DrawingCrane> EventAddCar;
|
||||||
|
DrawingCrane? _crane = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Событие
|
||||||
|
/// </summary>
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormCraneConfig()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelGray.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelRed.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||||
|
buttonCancel.Click += (sender, e) =>Close();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Отрисовать машину
|
||||||
|
/// </summary>
|
||||||
|
private void DrawCar()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBoxCrane.Width, pictureBoxCrane.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_crane?.SetPosition(5, 5);
|
||||||
|
_crane?.DrawTransport(gr);
|
||||||
|
pictureBoxCrane.Image = bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddEvent(Action<DrawingCrane> ev)
|
||||||
|
{
|
||||||
|
if (EventAddCar == null)
|
||||||
|
{
|
||||||
|
EventAddCar = new Action< DrawingCrane>(ev);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventAddCar += ev;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Передаем информацию при нажатии на Label
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
||||||
|
DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Действия при приеме перетаскиваемой информации
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||||
|
{
|
||||||
|
case "labelSimpleObject":
|
||||||
|
_crane = new DrawingCrane((int)numericUpDownSpeed.Value,
|
||||||
|
(int)numericUpDownWeight.Value, Color.White, 900, 500);
|
||||||
|
break;
|
||||||
|
case "labelModifiedObject":
|
||||||
|
_crane = new AdditionalDrawingCrane((int)numericUpDownSpeed.Value,
|
||||||
|
(int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||||||
|
checkBoxCounterweight.Checked, checkBoxCrane.Checked, 900,
|
||||||
|
500);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawCar();
|
||||||
|
}
|
||||||
|
/// Добавление машины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonOK_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
EventAddCar?.Invoke(_crane);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_crane != null && _crane.EntityCrane is AdditionEntityCrane entityCrane)
|
||||||
|
{
|
||||||
|
labelAdditionalColor.AllowDrop = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
labelAdditionalColor.AllowDrop = false;
|
||||||
|
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_crane != null)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
_crane.EntityCrane.BodyColor = (Color)e.Data.GetData(typeof(Color));
|
||||||
|
}
|
||||||
|
DrawCar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void labelAddBoxColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_crane != null && _crane.EntityCrane is AdditionEntityCrane entityCrane2)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
entityCrane2.AdditionalColor = (Color)e.Data.GetData(typeof(Color));
|
||||||
|
}
|
||||||
|
DrawCar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
HoistingCrane/HoistingCrane/FormCraneConfig.resx
Normal file
60
HoistingCrane/HoistingCrane/FormCraneConfig.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<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:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -8,4 +8,10 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions" Version="2.2.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
13
HoistingCrane/HoistingCrane/IMoveableObject.cs
Normal file
13
HoistingCrane/HoistingCrane/IMoveableObject.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
namespace HoistingCrane.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
/// Шаг объекта
|
||||||
|
int GetStep { get; }
|
||||||
|
/// Проверка, можно ли переместиться по нужному направлению
|
||||||
|
bool CheckCanMove(DirectionType direction);
|
||||||
|
/// Изменение направления перeмещения объекта
|
||||||
|
void MoveObject(DirectionType direction);
|
||||||
|
}
|
||||||
|
}
|
47
HoistingCrane/HoistingCrane/MoveToBorder.cs
Normal file
47
HoistingCrane/HoistingCrane/MoveToBorder.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
namespace HoistingCrane.MovementStrategy
|
||||||
|
{
|
||||||
|
internal class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal <= FieldWidth && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth && objParams.ObjectMiddleHorizontal <= FieldHeight && objParams.ObjectMiddleHorizontal + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.RightBorder - FieldWidth;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.DownBorder - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
HoistingCrane/HoistingCrane/MoveToCenter.cs
Normal file
47
HoistingCrane/HoistingCrane/MoveToCenter.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
namespace HoistingCrane.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && objParams.ObjectMiddleVertical <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
HoistingCrane/HoistingCrane/ObjectParameters.cs
Normal file
42
HoistingCrane/HoistingCrane/ObjectParameters.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
namespace HoistingCrane.MovementStrategy
|
||||||
|
{
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int _x;
|
||||||
|
private readonly int _y;
|
||||||
|
private readonly int _width;
|
||||||
|
private readonly int _height;
|
||||||
|
/// <summary>
|
||||||
|
/// Левая граница
|
||||||
|
/// </summary>
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int TopBorder => _y;
|
||||||
|
/// <summary>
|
||||||
|
/// Правая граница
|
||||||
|
/// </summary>
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
/// <summary>
|
||||||
|
/// Нижняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,8 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace HoistingCrane
|
namespace HoistingCrane
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -11,7 +16,32 @@ namespace HoistingCrane
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new Form1());
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||||
|
{
|
||||||
|
Application.Run(serviceProvider.GetRequiredService<FormCraneCollection>());
|
||||||
|
}
|
||||||
|
static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<FormCraneCollection>().AddLogging(option =>
|
||||||
|
{
|
||||||
|
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||||
|
string pathNeed = "";
|
||||||
|
for (int i = 0; i < path.Length - 3; i++)
|
||||||
|
{
|
||||||
|
pathNeed += path[i] + "\\";
|
||||||
|
}
|
||||||
|
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile(path: $"{pathNeed}appsettings.json", optional: false, reloadOnChange: true)
|
||||||
|
.Build();
|
||||||
|
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration)
|
||||||
|
.CreateLogger();
|
||||||
|
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddSerilog(logger);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
96
HoistingCrane/HoistingCrane/SetGeneric.cs
Normal file
96
HoistingCrane/HoistingCrane/SetGeneric.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using HoistingCrane.Exceptions;
|
||||||
|
|
||||||
|
namespace HoistingCrane.Generics
|
||||||
|
{
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
|
||||||
|
{
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
private readonly List<T?> _places;
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
public int Count => _places.Count;
|
||||||
|
/// Максимальное количество объектов в списке
|
||||||
|
private readonly int _maxCount;
|
||||||
|
/// Конструктор
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
|
}
|
||||||
|
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
public int Insert(T crane, IEqualityComparer<T?>? equal = null)
|
||||||
|
{
|
||||||
|
if (Count >= _maxCount)
|
||||||
|
throw new StorageOverflowException(Count);
|
||||||
|
Insert(0, crane, equal);
|
||||||
|
if (_places.Contains(null)) _places.Remove(null);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
public int Insert(int position, T crane, IEqualityComparer<T?>? equal = null)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _maxCount || Count >= _maxCount)
|
||||||
|
throw new CraneNotFoundException(position);
|
||||||
|
if (Count >= _maxCount)
|
||||||
|
throw new StorageOverflowException(Count);
|
||||||
|
if (equal != null && _places.Contains(crane, equal))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Добавляемый объект уже существует в коллекции");
|
||||||
|
}
|
||||||
|
_places.Insert(position, crane);
|
||||||
|
if(_places.Contains(null)) _places.Remove(null);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _maxCount || position >= Count || _places[position] == null)
|
||||||
|
throw new CraneNotFoundException(position);
|
||||||
|
|
||||||
|
if ((position < 0) || (position > _maxCount)) return false;
|
||||||
|
_places[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
if ((position < 0) || (position > Count)) return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position < 0 || position > Count)
|
||||||
|
return null;
|
||||||
|
if (_places.Count <= position)
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _maxCount)
|
||||||
|
return;
|
||||||
|
if (_places.Count <= position)
|
||||||
|
return;
|
||||||
|
_places[position] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Проход по списку
|
||||||
|
public IEnumerable<T?> GetCranes(int? maxCranes = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxCranes.HasValue && i == maxCranes.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
10
HoistingCrane/HoistingCrane/Status.cs
Normal file
10
HoistingCrane/HoistingCrane/Status.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace HoistingCrane.MovementStrategy
|
||||||
|
{
|
||||||
|
// Статус выполнения операции перемещения
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
14
HoistingCrane/HoistingCrane/StorageOverflowException.cs
Normal file
14
HoistingCrane/HoistingCrane/StorageOverflowException.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace HoistingCrane.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class StorageOverflowException : ApplicationException
|
||||||
|
{
|
||||||
|
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||||
|
public StorageOverflowException() : base() { }
|
||||||
|
public StorageOverflowException(string message) : base(message) { }
|
||||||
|
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
}
|
20
HoistingCrane/HoistingCrane/appsettings.json
Normal file
20
HoistingCrane/HoistingCrane/appsettings.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Information",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "Logs/log_.log",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||||
|
"Properties": {
|
||||||
|
"Application": "HoistingCrane"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user