ISEbd-21. Pyatkin I.A. Lab work 05. #5

Closed
IvanPyatkin wants to merge 1 commits from lab05 into lab04
11 changed files with 760 additions and 66 deletions

View File

@ -12,7 +12,7 @@ namespace ProjectExcavator.DrawingObjects
public class DrawingExcavator public class DrawingExcavator
{ {
/// <summary> /// <summary>
/// Получение объекта IMoveableObject из объекта DrawingExcavator /// Получение объекта IMoveableObject из объекта DrawningCar
/// </summary> /// </summary>
public IMoveableObject GetMoveableObject => new DrawingObjectExcavator(this); public IMoveableObject GetMoveableObject => new DrawingObjectExcavator(this);
/// <summary> /// <summary>
@ -22,11 +22,11 @@ namespace ProjectExcavator.DrawingObjects
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
/// </summary> /// </summary>
private int _pictureWidth; public int _pictureWidth;
/// <summary> /// <summary>
/// Высота окна /// Высота окна
/// </summary> /// </summary>
private int _pictureHeight; public int _pictureHeight;
/// <summary> /// <summary>
/// /// Левая координата прорисовки экскаватора /// /// Левая координата прорисовки экскаватора
/// </summary> /// </summary>
@ -62,7 +62,10 @@ namespace ProjectExcavator.DrawingObjects
EntityExcavator = new EntityExcavator(speed, weight, bodyColor); EntityExcavator = new EntityExcavator(speed, weight, bodyColor);
} }
} }
public void bodyColor(Color color)
{
EntityExcavator.BodyColor = color;
}
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -199,7 +202,6 @@ namespace ProjectExcavator.DrawingObjects
//цвета //цвета
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush bodyBrush = new SolidBrush(EntityExcavator.BodyColor); Brush bodyBrush = new SolidBrush(EntityExcavator.BodyColor);
Brush brBlack = new SolidBrush(Color.Black);
//отрисовка экскаватора без ковша //отрисовка экскаватора без ковша
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 35, 75, 25); g.DrawRectangle(pen, _startPosX + 50, _startPosY + 35, 75, 25);
@ -229,13 +231,7 @@ namespace ProjectExcavator.DrawingObjects
g.FillPie(bodyBrush, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180); g.FillPie(bodyBrush, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
g.FillPie(bodyBrush, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180); g.FillPie(bodyBrush, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
g.FillRectangle(bodyBrush, _startPosX + 44, _startPosY + 65, 86, 20); g.FillRectangle(bodyBrush, _startPosX + 44, _startPosY + 65, 86, 20);
g.FillEllipse(brBlack, _startPosX + 40, _startPosY + 68, 15, 15);
g.FillEllipse(brBlack, _startPosX + 120, _startPosY + 68, 15, 15);
g.FillEllipse(brBlack, _startPosX + 60, _startPosY + 76, 8, 8);
g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 76, 8, 8);
g.FillEllipse(brBlack, _startPosX + 100, _startPosY + 76, 8, 8);
g.FillEllipse(brBlack, _startPosX + 72, _startPosY + 68, 6, 6);
g.FillEllipse(brBlack, _startPosX + 92, _startPosY + 68, 6, 6);
} }
} }
} }

View File

@ -32,60 +32,65 @@ namespace ProjectExcavator.DrawingObjects
additionalColor, kovsh, katki); additionalColor, kovsh, katki);
} }
} }
public void additionalColor(Color color)
{
(EntityExcavator as EntityExcavatorKovsh).AdditionalColor = color;
}
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
if (EntityExcavator is not EntityExcavatorKovsh excavatorKovsh) if (EntityExcavator is not EntityExcavatorKovsh excavatorKovsh)
{ {
return; return;
} }
//цвета //цвета
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush additionalBrush = new Brush additionalBrush = new
SolidBrush(excavatorKovsh.AdditionalColor); SolidBrush(excavatorKovsh.AdditionalColor);
// ковш // ковш
g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10); if (excavatorKovsh.Kovsh)
g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5); {
g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7); g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10);
g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45); g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5);
g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45); g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7);
g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180); g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45);
g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY); g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45);
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10); g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180);
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12); g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY);
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16); g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10);
g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29); g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12);
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16);
g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29);
g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7); g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7);
g.FillPie(additionalBrush, _startPosX, _startPosY + 44, 28, 30, 90, 180); g.FillPie(additionalBrush, _startPosX, _startPosY + 44, 28, 30, 90, 180);
Point point1 = new Point(_startPosX + 50, _startPosY + 35); Point point1 = new Point(_startPosX + 50, _startPosY + 35);
Point point2 = new Point(_startPosX + 10, _startPosY + 10); Point point2 = new Point(_startPosX + 10, _startPosY + 10);
Point point3 = new Point(_startPosX + 12, _startPosY + 5); Point point3 = new Point(_startPosX + 12, _startPosY + 5);
Point point4 = new Point(_startPosX + 58, _startPosY + 35); Point point4 = new Point(_startPosX + 58, _startPosY + 35);
Point[] truba_1 = { point1, point2, point3, point4, point1 }; Point[] truba_1 = { point1, point2, point3, point4, point1 };
g.FillPolygon(additionalBrush, truba_1); g.FillPolygon(additionalBrush, truba_1);
Point point5 = new Point(_startPosX + 10, _startPosY + 10); Point point5 = new Point(_startPosX + 10, _startPosY + 10);
Point point6 = new Point(_startPosX + 10, _startPosY + 45); Point point6 = new Point(_startPosX + 10, _startPosY + 45);
Point point7 = new Point(_startPosX + 14, _startPosY + 45); Point point7 = new Point(_startPosX + 14, _startPosY + 45);
Point point8 = new Point(_startPosX + 14, _startPosY + 5); Point point8 = new Point(_startPosX + 14, _startPosY + 5);
Point[] truba_2 = { point5, point6, point7, point8, point5 }; Point[] truba_2 = { point5, point6, point7, point8, point5 };
g.FillPolygon(additionalBrush, truba_2); g.FillPolygon(additionalBrush, truba_2);
Point point9 = new Point(_startPosX + 14, _startPosY + 5); Point point9 = new Point(_startPosX + 14, _startPosY + 5);
Point point10 = new Point(_startPosX + 14, _startPosY); Point point10 = new Point(_startPosX + 14, _startPosY);
Point point11 = new Point(_startPosX + 7, _startPosY + 10); Point point11 = new Point(_startPosX + 7, _startPosY + 10);
Point[] triangle = { point9, point10, point11, point9 }; Point[] triangle = { point9, point10, point11, point9 };
g.FillPolygon(additionalBrush, triangle); g.FillPolygon(additionalBrush, triangle);
Point point12 = new Point(_startPosX + 14, _startPosY);
Point point13 = new Point(_startPosX + 50, _startPosY + 12);
Point point14 = new Point(_startPosX + 50, _startPosY + 16);
Point point15 = new Point(_startPosX + 14, _startPosY);
Point[] krepl = { point12, point13, point14, point15, point12 };
g.FillPolygon(additionalBrush, krepl);
Point point12 = new Point(_startPosX + 14, _startPosY);
Point point13 = new Point(_startPosX + 50, _startPosY + 12);
Point point14 = new Point(_startPosX + 50, _startPosY + 16);
Point point15 = new Point(_startPosX + 14, _startPosY);
Point[] krepl = { point12, point13, point14, point15, point12 };
g.FillPolygon(additionalBrush, krepl);
}
base.DrawTransport(g); base.DrawTransport(g);
// катки // катки

View File

@ -8,7 +8,7 @@ using ProjectExcavator.DrawingObjects;
namespace ProjectExcavator.MovementStrategy namespace ProjectExcavator.MovementStrategy
{ {
/// <summary> /// <summary>
/// Реализация интерфейса IDrawningObject для работы с объектом DrawingExcavator (паттерн Adapter) /// Реализация интерфейса IDrawningObject для работы с объектом DrawningExcavator (паттерн Adapter)
/// </summary> /// </summary>
public class DrawingObjectExcavator : IMoveableObject public class DrawingObjectExcavator : IMoveableObject
{ {

View File

@ -19,7 +19,7 @@ namespace ProjectExcavator.Entities
/// <summary> /// <summary>
/// Основной цвет /// Основной цвет
/// </summary> /// </summary>
public Color BodyColor { get; private set; } public Color BodyColor { get; set; }
Review

В классах-сущностях требовалось прописать методы для смены основного и дополнительного цветов

В классах-сущностях требовалось прописать методы для смены основного и дополнительного цветов
/// <summary> /// <summary>
/// Шаг перемещения экскаватора /// Шаг перемещения экскаватора
/// </summary> /// </summary>

View File

@ -14,7 +14,7 @@ namespace ProjectExcavator.Entities
/// <summary> /// <summary>
/// Дополнительный цвет (для опциональных элементов) /// Дополнительный цвет (для опциональных элементов)
/// </summary> /// </summary>
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; set; }
Review

В классах-сущностях требовалось прописать методы для смены основного и дополнительного цветов

В классах-сущностях требовалось прописать методы для смены основного и дополнительного цветов
/// <summary> /// <summary>
/// Ковш /// Ковш
/// </summary> /// </summary>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectExcavator.DrawingObjects;
namespace ProjectExcavator.Excavators
{
/// <summary>
/// Делегат для передачи объекта-экскаватора
/// </summary>
/// <param name="car"></param>
public delegate void ExcavatorDelegate(DrawingExcavator excavator);
Review

Не используется

Не используется
}

View File

@ -56,7 +56,8 @@ namespace ProjectExcavator.Generics
/// <param name="collect"></param> /// <param name="collect"></param>
/// <param name="obj"></param> /// <param name="obj"></param>
/// <returns></returns> /// <returns></returns>
public static bool operator +(ExcavatorGenericCollection<T, U> collect, T? obj) public static bool operator +(ExcavatorGenericCollection<T, U> collect, T?
obj)
{ {
if (obj == null) if (obj == null)
{ {
@ -71,7 +72,8 @@ namespace ProjectExcavator.Generics
/// <param name="collect"></param> /// <param name="collect"></param>
/// <param name="pos"></param> /// <param name="pos"></param>
/// <returns></returns> /// <returns></returns>
public static T? operator -(ExcavatorGenericCollection<T, U> collect, int pos) public static T? operator -(ExcavatorGenericCollection<T, U> collect, int
pos)
{ {
T? obj = collect._collection[pos]; T? obj = collect._collection[pos];
if (obj != null) if (obj != null)
@ -133,12 +135,17 @@ namespace ProjectExcavator.Generics
int height = _pictureHeight / _placeSizeHeight; int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _collection.Count; i++) for (int i = 0; i < _collection.Count; i++)
{ {
// TODO получение объекта
T? excavator = _collection[i]; T? excavator = _collection[i];
if (excavator == null) if (excavator == null)
continue; continue;
excavator._pictureHeight = _pictureHeight;
excavator._pictureWidth = _pictureWidth;
int r = i / width; int r = i / width;
int s = width - 1 - (i % width); int s = width - 1 - (i % width);
// TODO установка позиции
excavator.SetPosition(s * _placeSizeWidth, r * _placeSizeHeight); excavator.SetPosition(s * _placeSizeWidth, r * _placeSizeHeight);
// TODO прорисовка объекта
excavator.DrawTransport(g); excavator.DrawTransport(g);
} }
} }

View File

@ -1,7 +1,7 @@
using ProjectExcavator.DrawingObjects; using ProjectExcavator.DrawingObjects;
using ProjectExcavator.Generics; using ProjectExcavator.Generics;
using ProjectExcavator.MovementStrategy; using ProjectExcavator.MovementStrategy;
using ProjectExcavator.Excavators;
namespace ProjectExcavator namespace ProjectExcavator
{ {
/// <summary> /// <summary>
@ -41,6 +41,13 @@ namespace ProjectExcavator
index < listBoxStorages.Items.Count) index < listBoxStorages.Items.Count)
{ {
listBoxStorages.SelectedIndex = index; listBoxStorages.SelectedIndex = index;
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowExcavator();
} }
} }
/// <summary> /// <summary>
@ -87,12 +94,6 @@ namespace ProjectExcavator
_storage.DelSet(listBoxStorages.SelectedItem.ToString() _storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty); ?? string.Empty);
ReloadObjects(); ReloadObjects();
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowExcavator();
} }
} }
/// <summary> /// <summary>
@ -112,10 +113,11 @@ namespace ProjectExcavator
{ {
return; return;
} }
FormExcavator form = new(); FormExcavatorConfig form = new FormExcavatorConfig();
if (form.ShowDialog() == DialogResult.OK) Action<DrawingExcavator>? ExcavatorDelegate = (excavator) =>
{ {
if (obj + form.SelectedExcavator) bool SelectedExcavator = obj + excavator;
if (SelectedExcavator)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowExcavator(); pictureBoxCollection.Image = obj.ShowExcavator();
@ -124,7 +126,9 @@ namespace ProjectExcavator
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
} };
form.AddEvent(ExcavatorDelegate);
form.Show();
} }
/// <summary> /// <summary>
/// Удаление объекта из набора /// Удаление объекта из набора

View File

@ -0,0 +1,385 @@
namespace ProjectExcavator
{
partial class FormExcavatorConfig
{
/// <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.groupBoxParam = new System.Windows.Forms.GroupBox();
this.labelModifiedObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColor = new System.Windows.Forms.GroupBox();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.checkBox_Katki = new System.Windows.Forms.CheckBox();
this.checkBox_Kovsh = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelweight = new System.Windows.Forms.Label();
this.labelspeed = new System.Windows.Forms.Label();
this.panelObject = new System.Windows.Forms.Panel();
this.labelAdditionalColor = new System.Windows.Forms.Label();
this.labelMainColor = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxParam.SuspendLayout();
this.groupBoxColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.panelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.SuspendLayout();
//
// groupBoxParam
//
this.groupBoxParam.Controls.Add(this.labelModifiedObject);
this.groupBoxParam.Controls.Add(this.labelSimpleObject);
this.groupBoxParam.Controls.Add(this.groupBoxColor);
this.groupBoxParam.Controls.Add(this.checkBox_Katki);
this.groupBoxParam.Controls.Add(this.checkBox_Kovsh);
this.groupBoxParam.Controls.Add(this.numericUpDownWeight);
this.groupBoxParam.Controls.Add(this.numericUpDownSpeed);
this.groupBoxParam.Controls.Add(this.labelweight);
this.groupBoxParam.Controls.Add(this.labelspeed);
this.groupBoxParam.Location = new System.Drawing.Point(12, 12);
this.groupBoxParam.Name = "groupBoxParam";
this.groupBoxParam.Size = new System.Drawing.Size(562, 437);
this.groupBoxParam.TabIndex = 0;
this.groupBoxParam.TabStop = false;
this.groupBoxParam.Text = "Параметры";
//
// labelModifiedObject
//
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifiedObject.Location = new System.Drawing.Point(373, 258);
this.labelModifiedObject.Name = "labelModifiedObject";
this.labelModifiedObject.Size = new System.Drawing.Size(100, 23);
this.labelModifiedObject.TabIndex = 8;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(217, 258);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(100, 23);
this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBoxColor
//
this.groupBoxColor.Controls.Add(this.panelPurple);
this.groupBoxColor.Controls.Add(this.panelBlack);
this.groupBoxColor.Controls.Add(this.panelGray);
this.groupBoxColor.Controls.Add(this.panelWhite);
this.groupBoxColor.Controls.Add(this.panelYellow);
this.groupBoxColor.Controls.Add(this.panelGreen);
this.groupBoxColor.Controls.Add(this.panelBlue);
this.groupBoxColor.Controls.Add(this.panelRed);
this.groupBoxColor.Location = new System.Drawing.Point(201, 54);
this.groupBoxColor.Name = "groupBoxColor";
this.groupBoxColor.Size = new System.Drawing.Size(292, 170);
this.groupBoxColor.TabIndex = 6;
this.groupBoxColor.TabStop = false;
this.groupBoxColor.Text = "Цвета";
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(222, 102);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(50, 50);
this.panelPurple.TabIndex = 7;
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(156, 102);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(49, 50);
this.panelBlack.TabIndex = 6;
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGray
//
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(87, 102);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(51, 50);
this.panelGray.TabIndex = 5;
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(16, 102);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(53, 50);
this.panelWhite.TabIndex = 4;
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(222, 36);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(50, 50);
this.panelYellow.TabIndex = 3;
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(87, 36);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(51, 50);
this.panelGreen.TabIndex = 2;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(155, 36);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(50, 50);
this.panelBlue.TabIndex = 1;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(16, 37);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(51, 49);
this.panelRed.TabIndex = 0;
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// checkBox_Katki
//
this.checkBox_Katki.AutoSize = true;
this.checkBox_Katki.Location = new System.Drawing.Point(0, 205);
this.checkBox_Katki.Name = "checkBox_Katki";
this.checkBox_Katki.Size = new System.Drawing.Size(114, 19);
this.checkBox_Katki.TabIndex = 5;
this.checkBox_Katki.Text = "Наличие катков";
this.checkBox_Katki.UseVisualStyleBackColor = true;
//
// checkBox_Kovsh
//
this.checkBox_Kovsh.AutoSize = true;
this.checkBox_Kovsh.Location = new System.Drawing.Point(0, 156);
this.checkBox_Kovsh.Name = "checkBox_Kovsh";
this.checkBox_Kovsh.Size = new System.Drawing.Size(114, 19);
this.checkBox_Kovsh.TabIndex = 4;
this.checkBox_Kovsh.Text = "Наличие ковша";
this.checkBox_Kovsh.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(74, 91);
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(120, 23);
this.numericUpDownWeight.TabIndex = 3;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(74, 55);
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(120, 23);
this.numericUpDownSpeed.TabIndex = 2;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelweight
//
this.labelweight.AutoSize = true;
this.labelweight.Location = new System.Drawing.Point(6, 95);
this.labelweight.Name = "labelweight";
this.labelweight.Size = new System.Drawing.Size(29, 15);
this.labelweight.TabIndex = 1;
this.labelweight.Text = "Вес:";
//
// labelspeed
//
this.labelspeed.AutoSize = true;
this.labelspeed.Location = new System.Drawing.Point(6, 57);
this.labelspeed.Name = "labelspeed";
this.labelspeed.Size = new System.Drawing.Size(62, 15);
this.labelspeed.TabIndex = 0;
this.labelspeed.Text = "Скорость:";
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.labelAdditionalColor);
this.panelObject.Controls.Add(this.labelMainColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(593, 22);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(279, 343);
this.panelObject.TabIndex = 1;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// labelAdditionalColor
//
this.labelAdditionalColor.AllowDrop = true;
this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAdditionalColor.Location = new System.Drawing.Point(166, 38);
this.labelAdditionalColor.Name = "labelAdditionalColor";
this.labelAdditionalColor.Size = new System.Drawing.Size(100, 23);
this.labelAdditionalColor.TabIndex = 2;
this.labelAdditionalColor.Text = "Доп. цвет";
this.labelAdditionalColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
this.labelAdditionalColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// labelMainColor
//
this.labelMainColor.AllowDrop = true;
this.labelMainColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelMainColor.Location = new System.Drawing.Point(13, 38);
this.labelMainColor.Name = "labelMainColor";
this.labelMainColor.Size = new System.Drawing.Size(100, 23);
this.labelMainColor.TabIndex = 1;
this.labelMainColor.Text = "Цвет";
this.labelMainColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
this.labelMainColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(13, 68);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(253, 260);
this.pictureBoxObject.TabIndex = 0;
this.pictureBoxObject.TabStop = false;
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(606, 382);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(75, 23);
this.buttonOk.TabIndex = 2;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(784, 382);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 3;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// FormExcavatorConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(884, 461);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxParam);
this.Name = "FormExcavatorConfig";
this.Text = "FormExcavatorConfig";
this.groupBoxParam.ResumeLayout(false);
this.groupBoxParam.PerformLayout();
this.groupBoxColor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.panelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxParam;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelweight;
private Label labelspeed;
private Label labelModifiedObject;
private Label labelSimpleObject;
private GroupBox groupBoxColor;
private Panel panelPurple;
private Panel panelBlack;
private Panel panelGray;
private Panel panelWhite;
private Panel panelYellow;
private Panel panelGreen;
private Panel panelBlue;
private Panel panelRed;
private CheckBox checkBox_Katki;
private CheckBox checkBox_Kovsh;
private Panel panelObject;
private Label labelAdditionalColor;
private Label labelMainColor;
private PictureBox pictureBoxObject;
private Button buttonOk;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,162 @@
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 ProjectExcavator.DrawingObjects;
using ProjectExcavator.Excavators;
namespace ProjectExcavator
{
public partial class FormExcavatorConfig : Form
{
/// <summary>
/// Переменная-выбранного экскаватора
/// </summary>
DrawingExcavator? _excavator = null;
/// <summary>
/// Встроенный делегат
/// </summary>
private event Action<DrawingExcavator>? EventAddExcavator;
/// <summary>
/// Конструктор
/// </summary>
public FormExcavatorConfig()
{
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 DrawExcavator()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_excavator?.SetPosition(5, 5);
_excavator?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <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":
_excavator = new DrawingExcavator((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelModifiedObject":
_excavator = new DrawingExcavatorKovsh((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBox_Kovsh.Checked, checkBox_Katki.Checked, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
}
DrawExcavator();
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(Action<DrawingExcavator> ev)
{
if (EventAddExcavator == null)
{
EventAddExcavator = ev;
}
else
{
EventAddExcavator += ev;
}
}
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 (e.Data?.GetDataPresent(typeof(Color)) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
if (_excavator == null)
return;
((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color));
switch (((Label)sender).Name)
{
case "labelMainColor":
_excavator.bodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelAdditionalColor":
if (!(_excavator is DrawingExcavatorKovsh))
return;
(_excavator as DrawingExcavatorKovsh).additionalColor((Color)e.Data.GetData(typeof(Color)));
break;
}
DrawExcavator();
}
/// <summary>
/// Добавление экскаватора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddExcavator?.Invoke(_excavator);
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?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>