From 25e8f077f60f514e628967ad50b4b22ba26d0b53 Mon Sep 17 00:00:00 2001 From: LivelyPuer Date: Wed, 10 Apr 2024 19:18:28 +0400 Subject: [PATCH] lab5-ready --- .idea/.idea.BoykoSolution/.idea/encodings.xml | 5 +- .../Entities/EntityElectroTrans.cs | 22 +- ProjectElectroTrans/Entities/EntityTrans.cs | 10 + .../FormTransCollection.Designer.cs | 15 - ProjectElectroTrans/FormTransCollection.cs | 94 ++-- .../FormTransConfig.Designer.cs | 400 ++++++++++++++++++ ProjectElectroTrans/FormTransConfig.cs | 214 ++++++++++ ProjectElectroTrans/FormTransConfig.resx | 120 ++++++ ProjectElectroTrans/TransDelegate.cs | 9 + 9 files changed, 803 insertions(+), 86 deletions(-) create mode 100644 ProjectElectroTrans/FormTransConfig.Designer.cs create mode 100644 ProjectElectroTrans/FormTransConfig.cs create mode 100644 ProjectElectroTrans/FormTransConfig.resx create mode 100644 ProjectElectroTrans/TransDelegate.cs diff --git a/.idea/.idea.BoykoSolution/.idea/encodings.xml b/.idea/.idea.BoykoSolution/.idea/encodings.xml index df87cf9..3c20b14 100644 --- a/.idea/.idea.BoykoSolution/.idea/encodings.xml +++ b/.idea/.idea.BoykoSolution/.idea/encodings.xml @@ -1,4 +1,7 @@ - + + + + \ No newline at end of file diff --git a/ProjectElectroTrans/Entities/EntityElectroTrans.cs b/ProjectElectroTrans/Entities/EntityElectroTrans.cs index 8220a76..093f73b 100644 --- a/ProjectElectroTrans/Entities/EntityElectroTrans.cs +++ b/ProjectElectroTrans/Entities/EntityElectroTrans.cs @@ -13,6 +13,15 @@ internal class EntityElectroTrans : EntityTrans /// public Color AdditionalColor { get; private set; } + /// + /// установка доп. цвета + /// + /// + public void setAdditionalColor(Color color) + { + AdditionalColor = color; + } + /// /// Признак (опция) подняты ли рога /// @@ -22,12 +31,13 @@ internal class EntityElectroTrans : EntityTrans /// Признак (опция) налиция батерей /// public bool Battery { get; private set; } + /// - /// Конструктор сущности - /// - /// Скорость - /// Вес автомобиля - /// Основной цвет + /// Конструктор сущности + /// + /// Скорость + /// Вес автомобиля + /// Основной цвет /// /// Дополнительный цвет /// Признак активности усов /// Признак наличия батарей @@ -38,4 +48,4 @@ internal class EntityElectroTrans : EntityTrans Horns = horns; Battery = battery; } -} +} \ No newline at end of file diff --git a/ProjectElectroTrans/Entities/EntityTrans.cs b/ProjectElectroTrans/Entities/EntityTrans.cs index 86825b7..ebc1c9d 100644 --- a/ProjectElectroTrans/Entities/EntityTrans.cs +++ b/ProjectElectroTrans/Entities/EntityTrans.cs @@ -20,6 +20,16 @@ public class EntityTrans /// /// Шаг перемещения автомобиля /// + + /// + /// Основной цвет + /// + /// + public void setBodyColor(Color color) + { + BodyColor = color; + } + public double Step => Speed * 100 / Weight; /// /// Конструктор сущности diff --git a/ProjectElectroTrans/FormTransCollection.Designer.cs b/ProjectElectroTrans/FormTransCollection.Designer.cs index 9d8464c..a605cbd 100644 --- a/ProjectElectroTrans/FormTransCollection.Designer.cs +++ b/ProjectElectroTrans/FormTransCollection.Designer.cs @@ -46,7 +46,6 @@ namespace ProjectElectroTrans buttonGoToCheck = new Button(); buttonRemoveTrans = new Button(); maskedTextBoxPosition = new MaskedTextBox(); - buttonAddElectroTrans = new Button(); buttonAddTrans = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); @@ -204,18 +203,6 @@ namespace ProjectElectroTrans maskedTextBoxPosition.Size = new Size(167, 23); maskedTextBoxPosition.TabIndex = 3; maskedTextBoxPosition.ValidatingType = typeof(int); - // - // buttonAddElectroTrans - // - buttonAddElectroTrans.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddElectroTrans.Location = new Point(3, 49); - buttonAddElectroTrans.Name = "buttonAddElectroTrans"; - buttonAddElectroTrans.Size = new Size(167, 40); - buttonAddElectroTrans.TabIndex = 2; - buttonAddElectroTrans.Text = "Добавление электропоезд"; - buttonAddElectroTrans.UseVisualStyleBackColor = true; - buttonAddElectroTrans.Click += ButtonAddElectroTrans_Click; - // // buttonAddTrans // buttonAddTrans.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; @@ -251,7 +238,6 @@ namespace ProjectElectroTrans // panelCompanyTools // panelCompanyTools.Controls.Add(buttonAddTrans); - panelCompanyTools.Controls.Add(buttonAddElectroTrans); panelCompanyTools.Controls.Add(maskedTextBoxPosition); panelCompanyTools.Controls.Add(buttonRefresh); panelCompanyTools.Controls.Add(buttonRemoveTrans); @@ -285,7 +271,6 @@ namespace ProjectElectroTrans private GroupBox groupBoxTools; private ComboBox comboBoxSelectorCompany; - private Button buttonAddElectroTrans; private Button buttonAddTrans; private Button buttonRemoveTrans; private MaskedTextBox maskedTextBoxPosition; diff --git a/ProjectElectroTrans/FormTransCollection.cs b/ProjectElectroTrans/FormTransCollection.cs index 6d66a7a..e70734e 100644 --- a/ProjectElectroTrans/FormTransCollection.cs +++ b/ProjectElectroTrans/FormTransCollection.cs @@ -10,9 +10,10 @@ namespace ProjectElectroTrans; public partial class FormTransCollection : Form { /// - /// Хранилише коллекций - /// - private readonly StorageCollection _storageCollection; + /// Хранилише коллекций + /// + private readonly StorageCollection _storageCollection; + /// /// Компания /// @@ -37,54 +38,31 @@ public partial class FormTransCollection : Form switch (comboBoxSelectorCompany.Text) { case "Хранилище": - _company = new TransDepoService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + _company = new TransDepoService(pictureBox.Width, pictureBox.Height, + new MassiveGenericObjects()); break; } } - /// - /// Добавление обычного автомобиля - /// - /// - /// - private void ButtonAddTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingTrans)); + private void ButtonAddTrans_Click(object sender, EventArgs e) + { + FormTransConfig form = new(); - /// - /// Добавление спортивного автомобиля - /// - /// - /// - private void ButtonAddElectroTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingElectroTrans)); + form.Show(); + form.AddEvent(SetTrans); + } /// /// Создание объекта класса-перемещения /// /// Тип создаваемого объекта - private void CreateObject(string type) + private void SetTrans(DrawingTrans? drawingTrans) { - if (_company == null) + if (_company == null || drawingTrans == null) { return; } - - Random random = new(); - DrawingTrans drawingTrans; - switch (type) - { - case nameof(DrawingTrans): - drawingTrans = new DrawingTrans(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); - break; - case nameof(DrawingElectroTrans): - // вызов диалогового окна для выбора цвета - drawingTrans = new DrawingElectroTrans(random.Next(100, 300), random.Next(1000, 3000), - GetColor(random), - GetColor(random), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - + if (_company + drawingTrans != -1) { MessageBox.Show("Объект добавлен"); @@ -96,23 +74,6 @@ public partial class FormTransCollection : Form } } - /// - /// Получение цвета - /// - /// Генератор случайных чисел - /// - private static Color GetColor(Random 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; - } - - return color; - } - /// /// Удаление объекта /// @@ -125,7 +86,8 @@ public partial class FormTransCollection : Form return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != + DialogResult.Yes) { return; } @@ -194,13 +156,14 @@ public partial class FormTransCollection : Form } /// - /// Добавление коллекции - /// - /// - /// - private void ButtonCollectionAdd_Click(object sender, EventArgs e) + /// Добавление коллекции + /// + /// + /// + private void ButtonCollectionAdd_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) + if (string.IsNullOrEmpty(textBoxCollectionName.Text) || + (!radioButtonList.Checked && !radioButtonMassive.Checked)) { MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -232,10 +195,13 @@ public partial class FormTransCollection : Form MessageBox.Show("Коллекция не выбрана"); return; } - if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != + DialogResult.Yes) { return; } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); RerfreshListBoxItems(); } @@ -254,7 +220,6 @@ public partial class FormTransCollection : Form listBoxCollection.Items.Add(colName); } } - } /// @@ -270,7 +235,8 @@ public partial class FormTransCollection : Form return; } - ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; + ICollectionGenericObjects? collection = + _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; if (collection == null) { MessageBox.Show("Коллекция не проинициализирована"); diff --git a/ProjectElectroTrans/FormTransConfig.Designer.cs b/ProjectElectroTrans/FormTransConfig.Designer.cs new file mode 100644 index 0000000..63ebe44 --- /dev/null +++ b/ProjectElectroTrans/FormTransConfig.Designer.cs @@ -0,0 +1,400 @@ +namespace ProjectElectroTrans +{ + partial class FormTransConfig + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBoxConfig = new GroupBox(); + panel2 = new Panel(); + pictureBox1 = new PictureBox(); + panel1 = new Panel(); + groupBoxColors = new GroupBox(); + panelPurple = new Panel(); + panelYellow = new Panel(); + panelBlack = new Panel(); + panelBlue = new Panel(); + panelGray = new Panel(); + panelGreen = new Panel(); + panelWhite = new Panel(); + panelRed = new Panel(); + checkBoxBulldozerDump = new CheckBox(); + checkBoxSupport = new CheckBox(); + checkBoxBucket = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + labelWeight = new Label(); + labelSpeed = new Label(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + panelObject = new Panel(); + labelBodyColor = new Label(); + pictureBoxObject = new PictureBox(); + labelAdditionalColor = new Label(); + buttonAdd = new Button(); + buttonCancel = new Button(); + groupBoxConfig.SuspendLayout(); + panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBoxConfig + // + groupBoxConfig.Controls.Add(panel2); + groupBoxConfig.Controls.Add(panel1); + groupBoxConfig.Controls.Add(groupBoxColors); + groupBoxConfig.Controls.Add(checkBoxBulldozerDump); + groupBoxConfig.Controls.Add(checkBoxSupport); + groupBoxConfig.Controls.Add(checkBoxBucket); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(labelSpeed); + groupBoxConfig.Controls.Add(labelModifiedObject); + groupBoxConfig.Controls.Add(labelSimpleObject); + groupBoxConfig.Dock = DockStyle.Left; + groupBoxConfig.Location = new Point(0, 0); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(571, 251); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // panel2 + // + panel2.Controls.Add(pictureBox1); + panel2.Location = new Point(578, 10); + panel2.Name = "panel2"; + panel2.Size = new Size(250, 125); + panel2.TabIndex = 1; + // + // pictureBox1 + // + pictureBox1.Location = new Point(59, 48); + pictureBox1.Name = "pictureBox1"; + pictureBox1.Size = new Size(125, 62); + pictureBox1.TabIndex = 0; + pictureBox1.TabStop = false; + // + // panel1 + // + panel1.Location = new Point(594, 12); + panel1.Name = "panel1"; + panel1.Size = new Size(226, 144); + panel1.TabIndex = 1; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelPurple); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(panelBlack); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelGray); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(316, 21); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(256, 125); + groupBoxColors.TabIndex = 9; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(189, 81); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(35, 33); + panelPurple.TabIndex = 7; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(189, 36); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(35, 33); + panelYellow.TabIndex = 3; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(130, 81); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(35, 33); + panelBlack.TabIndex = 6; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(130, 36); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(35, 33); + panelBlue.TabIndex = 2; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(74, 81); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(35, 33); + panelGray.TabIndex = 5; + // + // panelGreen + // + panelGreen.BackColor = Color.FromArgb(0, 192, 0); + panelGreen.Location = new Point(74, 36); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(35, 33); + panelGreen.TabIndex = 1; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(23, 81); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(35, 33); + panelWhite.TabIndex = 4; + // + // panelRed + // + panelRed.AllowDrop = true; + panelRed.AutoSize = true; + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(23, 36); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(35, 33); + panelRed.TabIndex = 0; + panelRed.MouseDown += Panel_MouseDown; + // + // checkBoxBulldozerDump + // + checkBoxBulldozerDump.AutoSize = true; + checkBoxBulldozerDump.Location = new Point(13, 162); + checkBoxBulldozerDump.Name = "checkBoxBulldozerDump"; + checkBoxBulldozerDump.Size = new Size(315, 24); + checkBoxBulldozerDump.TabIndex = 8; + checkBoxBulldozerDump.Text = "Признак наличие рогов"; + checkBoxBulldozerDump.UseVisualStyleBackColor = true; + // + // checkBoxSupport + // + checkBoxSupport.AutoSize = true; + checkBoxSupport.Location = new Point(12, 132); + checkBoxSupport.Name = "checkBoxSupport"; + checkBoxSupport.Size = new Size(209, 24); + checkBoxSupport.TabIndex = 7; + checkBoxSupport.Text = "Признак наличие батарей "; + checkBoxSupport.UseVisualStyleBackColor = true; + // + // checkBoxBucket + // + numericUpDownWeight.Location = new Point(91, 54); + numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new Size(150, 27); + numericUpDownWeight.TabIndex = 5; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(91, 21); + numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownSpeed.Name = "numericUpDownSpeed"; + numericUpDownSpeed.Size = new Size(150, 27); + numericUpDownSpeed.TabIndex = 4; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(12, 61); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(33, 20); + labelWeight.TabIndex = 3; + labelWeight.Text = "Вес"; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(12, 23); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(73, 20); + labelSpeed.TabIndex = 2; + labelSpeed.Text = "Скорость"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(161, 201); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(113, 25); + labelModifiedObject.TabIndex = 1; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(33, 201); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(98, 25); + labelSimpleObject.TabIndex = 0; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelBodyColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Location = new Point(575, 7); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(250, 197); + panelObject.TabIndex = 1; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.AutoSize = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(31, 19); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(44, 22); + labelBodyColor.TabIndex = 1; + labelBodyColor.Text = "Цвет"; + labelBodyColor.DragDrop += labelBodyColor_DragDrop; + labelBodyColor.DragEnter += labelBodyColor_DragEnter; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(19, 44); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(216, 150); + pictureBoxObject.TabIndex = 0; + pictureBoxObject.TabStop = false; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.AutoSize = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(158, 19); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(77, 22); + labelAdditionalColor.TabIndex = 2; + labelAdditionalColor.Text = "Доп. цвет"; + labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter; + // + // buttonAdd + // + buttonAdd.Location = new Point(578, 210); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(716, 210); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormExcavatorConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(822, 251); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(panelObject); + Controls.Add(groupBoxConfig); + Name = "FormExcavatorConfig"; + Text = "Создание объекта"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); + groupBoxColors.ResumeLayout(false); + groupBoxColors.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panelObject.ResumeLayout(false); + panelObject.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxConfig; + private Label labelModifiedObject; + private Label labelSimpleObject; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private Label labelSpeed; + private CheckBox checkBoxBulldozerDump; + private CheckBox checkBoxSupport; + private CheckBox checkBoxBucket; + private GroupBox groupBoxColors; + private Panel panelPurple; + private Panel panelYellow; + private Panel panelBlack; + private Panel panelBlue; + private Panel panelGray; + private Panel panelGreen; + private Panel panelWhite; + private Panel panelRed; + private Panel panel1; + private Panel panel2; + private PictureBox pictureBox1; + private Panel panelObject; + private PictureBox pictureBoxObject; + private Button buttonAdd; + private Button buttonCancel; + private Label labelAdditionalColor; + private Label labelBodyColor; + } +} \ No newline at end of file diff --git a/ProjectElectroTrans/FormTransConfig.cs b/ProjectElectroTrans/FormTransConfig.cs new file mode 100644 index 0000000..4a677eb --- /dev/null +++ b/ProjectElectroTrans/FormTransConfig.cs @@ -0,0 +1,214 @@ +using ProjectElectroTrans.Drawnings; +using ProjectElectroTrans.Entities; + + +namespace ProjectElectroTrans +{ + /// + /// форма конфигурации объекта + /// + public partial class FormTransConfig : Form + { + + private DrawingTrans? _trans; + + /// + /// событие для передачи объекта + /// + + private event Action? ElectroTransDelegate; + /// + /// Конструктор + /// + public FormTransConfig() + { + InitializeComponent(); + panelRed.MouseDown += Panel_MouseDown; + panelGreen.MouseDown += Panel_MouseDown; + panelBlue.MouseDown += Panel_MouseDown; + panelYellow.MouseDown += Panel_MouseDown; + panelWhite.MouseDown += Panel_MouseDown; + panelGray.MouseDown += Panel_MouseDown; + panelBlack.MouseDown += Panel_MouseDown; + panelPurple.MouseDown += Panel_MouseDown; + buttonCancel.Click += (sender, e) => Close(); + + } + + + /// + /// Привязка внешнего метода к событию + /// + /// + public void AddEvent(Action excavatorDelegate) + { + ElectroTransDelegate += excavatorDelegate; + } + + /// + /// Отрисовка объекта + /// + private void DrawObject() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _trans?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); + _trans?.SetPosition(15, 15); + _trans?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + + /// + /// Передаем информацию при нажатии на Labe + /// + /// + /// + + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy); + } + + /// + /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// + /// + /// + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + /// + /// действия при приеме перетаскиваемой информации + /// + /// + /// + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text)?.ToString()) + { + case "labelSimpleObject": + _trans = new DrawingTrans((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White); + break; + case "labelModifiedObject": + _trans = new DrawingElectroTrans((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, + Color.White, + Color.Black, checkBoxBucket.Checked, + checkBoxSupport.Checked); + break; + } + labelBodyColor.BackColor = Color.Empty; + labelAdditionalColor.BackColor = Color.Empty; + DrawObject(); + } + + /// + /// Передаем информацию при нажатии на Panel + /// + /// + /// + private void Panel_MouseDown(object? sender, MouseEventArgs e) + { + (sender as Control)?.DoDragDrop((sender as Control)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + + /// + /// Проверка получаемой информации по основному цвету + /// + /// + /// + 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 labelBodyColor_DragDrop(object sender, DragEventArgs e) + { + if (_trans != null) + { + _trans.EntityTrans.setBodyColor((Color)e.Data.GetData(typeof(Color))); + DrawObject(); + } + } + + /// + /// проверка получаемой информации по доп. цвету + /// + /// + /// + private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (_trans is DrawingElectroTrans) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } + + /// + /// действия при перетаскивании доп. цвета + /// + /// + /// + private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_trans.EntityTrans is EntityElectroTrans _excavator) + { + _excavator.setAdditionalColor((Color)e.Data.GetData(typeof(Color))); + } + DrawObject(); + + } + + /// + /// Передача объекта + /// + /// + /// + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (_trans != null) + { + ElectroTransDelegate?.Invoke(_trans); + Close(); + } + } + + } + + + + + + + + +} diff --git a/ProjectElectroTrans/FormTransConfig.resx b/ProjectElectroTrans/FormTransConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectElectroTrans/FormTransConfig.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectElectroTrans/TransDelegate.cs b/ProjectElectroTrans/TransDelegate.cs new file mode 100644 index 0000000..1736abe --- /dev/null +++ b/ProjectElectroTrans/TransDelegate.cs @@ -0,0 +1,9 @@ +using ProjectElectroTrans.Drawnings; + +namespace ProjectElectroTrans; + +/// +/// Делегат передачи объекта класса-прорисовки +/// +/// +public delegate void TransDelegate(DrawingTrans car); \ No newline at end of file