From a50b38a5927b8d61fb1719eee2683cde4b48bc80 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Sun, 14 Apr 2024 20:01:01 +0400
Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D1=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
HoistingCrane/HoistingCrane/CarDelegate.cs | 2 +-
.../StorageCollection.cs | 16 +-
.../FormCarCollection.Designer.cs | 4 +-
.../HoistingCrane/FormCarCollection.cs | 20 +--
.../HoistingCrane/FormCarConfig.Designer.cs | 7 +-
HoistingCrane/HoistingCrane/FormCarConfig.cs | 146 ++++++++++++------
6 files changed, 120 insertions(+), 75 deletions(-)
diff --git a/HoistingCrane/HoistingCrane/CarDelegate.cs b/HoistingCrane/HoistingCrane/CarDelegate.cs
index d33d144..7383591 100644
--- a/HoistingCrane/HoistingCrane/CarDelegate.cs
+++ b/HoistingCrane/HoistingCrane/CarDelegate.cs
@@ -7,6 +7,6 @@ using System.Threading.Tasks;
namespace HoistingCrane
{
- public delegate void CarDelegate(DrawningTrackedVehicle car);
+ public delegate void CarDelegate(DrawningTrackedVehicle car);
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
index 7e84f1b..0765bd3 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs
@@ -25,8 +25,6 @@ namespace HoistingCrane.CollectionGenericObjects
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
- // TODO Прописать логику для добавления
if (!string.IsNullOrEmpty(name) && !Keys.Contains(name))
{
if(collectionType == CollectionType.Massive)
@@ -45,12 +43,8 @@ namespace HoistingCrane.CollectionGenericObjects
/// Название коллекции
public void DelCollection(string name)
{
- // TODO Прописать логику для удаления коллекции
-
- if(Keys.Contains(name))
- {
+ if (dict.ContainsKey(name))
dict.Remove(name);
- }
}
///
/// Доступ к коллекции
@@ -61,12 +55,8 @@ namespace HoistingCrane.CollectionGenericObjects
{
get
{
- // TODO Продумать логику получения объекта
- if (dict.TryGetValue(name, out ICollectionGenericObjects? result))
- {
- return result;
- }
- return null;
+ if (name == null || !dict.ContainsKey(name)) { return null; }
+ return dict[name];
}
}
}
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
index 4bb03f2..871848a 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs
@@ -221,9 +221,9 @@
buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
buttonCreateHoistingCrane.Size = new Size(192, 22);
buttonCreateHoistingCrane.TabIndex = 0;
- buttonCreateHoistingCrane.Text = "Добавить подъемный кран";
+ buttonCreateHoistingCrane.Text = "Добавить транспорт";
buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
-
+ buttonCreateHoistingCrane.Click += buttonCreateHoistingCrane_Click;
//
// pictureBox
//
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index 104913c..8382a18 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -72,22 +72,15 @@ namespace HoistingCrane
color = dialog.Color;
}
return color;
- }
-
- private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e)
- {
- FormCarConfig form = new();
- form.Show();
- form.AddEvent(SetCar);
- }
+ }
private void SetCar(DrawningTrackedVehicle car)
{
- if(_company == null || car == null)
+ if (_company == null || car == null)
{
return;
}
- if((_company + car) != -1)
+ if ((_company + car) != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
@@ -225,6 +218,13 @@ namespace HoistingCrane
panelStorage.Enabled = true;
RerfreshListBoxItems();
}
+
+ private void buttonCreateHoistingCrane_Click(object sender, EventArgs e)
+ {
+ FormCarConfig form = new();
+ form.AddEvent(SetCar);
+ form.Show();
+ }
}
}
diff --git a/HoistingCrane/HoistingCrane/FormCarConfig.Designer.cs b/HoistingCrane/HoistingCrane/FormCarConfig.Designer.cs
index 9e6b7cf..2721270 100644
--- a/HoistingCrane/HoistingCrane/FormCarConfig.Designer.cs
+++ b/HoistingCrane/HoistingCrane/FormCarConfig.Designer.cs
@@ -263,7 +263,8 @@
labelAdditionalColor.TabIndex = 10;
labelAdditionalColor.Text = "Доп. цвет";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
- labelAdditionalColor.DragEnter += labelColors_DragEnter;
+ labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop;
+ labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter;
//
// labelBodyColor
//
@@ -274,7 +275,8 @@
labelBodyColor.TabIndex = 9;
labelBodyColor.Text = "Цвет";
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
- labelBodyColor.DragEnter += labelColors_DragEnter;
+ labelBodyColor.DragDrop += labelBodyColor_DragDrop;
+ labelBodyColor.DragEnter += labelBodyColor_DragEnter;
//
// pictureBoxObject
//
@@ -302,7 +304,6 @@
buttonCancel.TabIndex = 2;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
-
//
// FormCarConfig
//
diff --git a/HoistingCrane/HoistingCrane/FormCarConfig.cs b/HoistingCrane/HoistingCrane/FormCarConfig.cs
index 4142774..3135eb7 100644
--- a/HoistingCrane/HoistingCrane/FormCarConfig.cs
+++ b/HoistingCrane/HoistingCrane/FormCarConfig.cs
@@ -10,6 +10,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
namespace HoistingCrane
{
@@ -19,6 +20,7 @@ namespace HoistingCrane
private event CarDelegate? _carDelegate;
public FormCarConfig()
{
+ InitializeComponent();
panelColorRed.MouseDown += panel_MouseDown;
panelColorBlue.MouseDown += panel_MouseDown;
panelColorGreen.MouseDown += panel_MouseDown;
@@ -28,45 +30,53 @@ namespace HoistingCrane
panelColorGray.MouseDown += panel_MouseDown;
panelColorPurple.MouseDown += panel_MouseDown;
buttonCancel.Click += (sender, e) => Close();
-
- InitializeComponent();
}
+ ///
+ /// Привязка метода к событию
+ ///
+ ///
public void AddEvent(CarDelegate carDelegate)
{
_carDelegate += carDelegate;
}
+ ///
+ /// Отрисовка объекта
+ ///
private void DrawObject()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
car?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
- car?.SetPosition(5, 5);
+ car?.SetPosition(25, 25);
car?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
-
+ ///
+ /// Передаем информацию при нажатии на Label
+ ///
+ ///
+ ///
private void labelObject_MouseDown(object sender, MouseEventArgs e)
{
- var label = sender as Label;
- label?.DoDragDrop(label.Name, DragDropEffects.Move);
- label?.DoDragDrop(label.Name, DragDropEffects.Copy);
+ (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
}
-
+ ///
+ /// Проверка получаемой информации (ее типа на соответствие требуемому)
+ ///
+ ///
+ ///
private void panel_DragEnter(object sender, DragEventArgs e)
{
- if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
- {
- e.Effect = DragDropEffects.Copy;
- }
- else
- {
- e.Effect = DragDropEffects.None;
- }
+ e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
}
-
+ ///
+ /// Действия при приеме перетаскиваемой информации
+ ///
+ ///
+ ///
private void panel_DragDrop(object sender, DragEventArgs e)
{
- switch (e.Data?.GetData(DataFormats.Text)?.ToString())
+ switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
car = new DrawningTrackedVehicle((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
@@ -78,35 +88,20 @@ namespace HoistingCrane
}
DrawObject();
}
-
+ ///
+ /// Передаем информацию при нажатии на Panel
+ ///
+ ///
+ ///
private void panel_MouseDown(object? sender, MouseEventArgs e)
{
- var color = sender as Label;
- color?.DoDragDrop(color.BackColor, DragDropEffects.Move);
- color?.DoDragDrop(color.BackColor, DragDropEffects.Copy);
+ (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor ?? Color.White, DragDropEffects.Move | DragDropEffects.Copy);
}
-
- // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
- private void labelColors_DragEnter(object sender, DragEventArgs e)
- {
- var label = (String)sender;
- Color newColor = (Color)e.Data.GetData(typeof(Color).ToString());
- switch (label)
- {
- case "labelBodyColor":
- car?.EntityTrackedVehicle?.SetBodyColor(newColor);
- DrawObject();
- break;
- case "labelAdditionalColor":
- if (car is DrawningHoistingCrane)
- {
- (car.EntityTrackedVehicle as EntityHoistingCrane).SetAdditionalColor(newColor);
- DrawObject();
- }
- break;
- }
- }
-
+ ///
+ /// Передача объекта
+ ///
+ ///
+ ///
private void buttonAdd_Click(object sender, EventArgs e)
{
if (car != null)
@@ -115,8 +110,67 @@ namespace HoistingCrane
Close();
}
}
-
-
+ ///
+ /// Прорисовка основным цветом
+ ///
+ ///
+ ///
+ private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
+ {
+ if (car != null)
+ {
+ car.EntityTrackedVehicle?.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
+ DrawObject();
+ }
+ }
+ ///
+ /// Передача основного цвета
+ ///
+ ///
+ ///
+ private void labelBodyColor_DragEnter(object sender, DragEventArgs e)
+ {
+ if (e.Data.GetDataPresent(typeof(Color)))
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+ ///
+ /// Прорисовка основным цветом
+ ///
+ ///
+ ///
+ private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
+ {
+ if (car?.EntityTrackedVehicle is EntityHoistingCrane entityHoistingCrane)
+ {
+ entityHoistingCrane.SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
+ }
+ DrawObject();
+ }
+ ///
+ /// Передача дополнительного цвета
+ ///
+ ///
+ ///
+ private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
+ {
+ if (car is DrawningHoistingCrane)
+ {
+ if (e.Data.GetDataPresent(typeof(Color)))
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+ }
}
}