From 4479e1cfe7036ba337d4e4954dd7feea1bee1921 Mon Sep 17 00:00:00 2001 From: 5_fG Date: Thu, 9 May 2024 19:31:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=96=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionGenericObjects/GarageService.cs | 26 +- .../Drawnings/DrawningTrackedVehicle.cs | 4 +- .../Entities/EntityExcavator.cs | 7 +- ...ckedVehicle.cs => EntityTrackedVehicle.cs} | 9 +- .../FormExcavatorCollection.Designer.cs | 166 ++++---- .../FormExcavatorCollection.cs | 58 +-- .../FormExcavatorConfig.Designer.cs | 373 ++++++++++++++++++ .../ProjectExcavator/FormExcavatorConfig.cs | 174 ++++++++ .../ProjectExcavator/FormExcavatorConfig.resx | 120 ++++++ 9 files changed, 784 insertions(+), 153 deletions(-) rename ProjectExcavator/ProjectExcavator/Entities/{TrackedVehicle.cs => EntityTrackedVehicle.cs} (82%) create mode 100644 ProjectExcavator/ProjectExcavator/FormExcavatorConfig.Designer.cs create mode 100644 ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs create mode 100644 ProjectExcavator/ProjectExcavator/FormExcavatorConfig.resx diff --git a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/GarageService.cs b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/GarageService.cs index 370da23..45738a5 100644 --- a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/GarageService.cs +++ b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/GarageService.cs @@ -8,11 +8,11 @@ namespace ProjectExcavator.CollectionGenericObjects; internal class GarageService : AbstractCompany { /// - /// Конструктор - /// - /// - /// - /// + /// Конструктор + /// + /// + /// + /// public GarageService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) { } @@ -39,21 +39,23 @@ internal class GarageService : AbstractCompany protected override void SetObjectsPosition() { - - int col = _collection?.Count ?? 0; - int LevelWidth = 0; int LevelHeight = 0; - for (int i = 0; i < col; i++) + + for (int i = 0; i < _collection?.Count; i++) { - if (LevelHeight + 1 > _pictureHeight/ (_placeSizeHeight + 60)) + if (_collection.Get(i) != null) + { + _collection?.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition((_pictureWidth - 190) - _placeSizeWidth * LevelWidth, 20 + (_placeSizeHeight + 60) * LevelHeight); + } + + if (LevelHeight + 1 > _pictureHeight / (_placeSizeHeight + 60)) { return; } - _collection?.Get(i)?.SetPosition((_pictureWidth - 190) - _placeSizeWidth * LevelWidth, 20 + (_placeSizeHeight + 60) * LevelHeight ); - if (LevelWidth + 1 < _pictureWidth / _placeSizeWidth) { LevelWidth++; diff --git a/ProjectExcavator/ProjectExcavator/Drawnings/DrawningTrackedVehicle.cs b/ProjectExcavator/ProjectExcavator/Drawnings/DrawningTrackedVehicle.cs index 1cf7de9..3811e37 100644 --- a/ProjectExcavator/ProjectExcavator/Drawnings/DrawningTrackedVehicle.cs +++ b/ProjectExcavator/ProjectExcavator/Drawnings/DrawningTrackedVehicle.cs @@ -10,7 +10,7 @@ public class DrawningTrackedVehicle /// /// Класс-сущность /// - public TrackedVehicle? EntityTrackedVehicle { get; protected set; } + public EntityTrackedVehicle? EntityTrackedVehicle { get; protected set; } /// /// Ширина окна @@ -81,7 +81,7 @@ public class DrawningTrackedVehicle /// Основной цвет public DrawningTrackedVehicle(int speed, double weight, Color bodyColor) : this() { - EntityTrackedVehicle = new TrackedVehicle(speed, weight, bodyColor); + EntityTrackedVehicle = new EntityTrackedVehicle(speed, weight, bodyColor); } /// diff --git a/ProjectExcavator/ProjectExcavator/Entities/EntityExcavator.cs b/ProjectExcavator/ProjectExcavator/Entities/EntityExcavator.cs index c47796c..0325a92 100644 --- a/ProjectExcavator/ProjectExcavator/Entities/EntityExcavator.cs +++ b/ProjectExcavator/ProjectExcavator/Entities/EntityExcavator.cs @@ -3,13 +3,18 @@ /// /// Класс-сущность "Экскаватор" /// -public class EntityExcavator : TrackedVehicle +public class EntityExcavator : EntityTrackedVehicle { /// /// Дополнительный цвет (для опциональных элементов) /// public Color AdditionalColor { get; private set; } + public void SetAdditionalColor(Color additionalColor) + { + AdditionalColor = additionalColor; + } + /// /// Признак (опция) наличия ковша /// diff --git a/ProjectExcavator/ProjectExcavator/Entities/TrackedVehicle.cs b/ProjectExcavator/ProjectExcavator/Entities/EntityTrackedVehicle.cs similarity index 82% rename from ProjectExcavator/ProjectExcavator/Entities/TrackedVehicle.cs rename to ProjectExcavator/ProjectExcavator/Entities/EntityTrackedVehicle.cs index c577bde..3e173d2 100644 --- a/ProjectExcavator/ProjectExcavator/Entities/TrackedVehicle.cs +++ b/ProjectExcavator/ProjectExcavator/Entities/EntityTrackedVehicle.cs @@ -3,7 +3,7 @@ /// /// Класс-сущность "Гусеничная Машина" /// -public class TrackedVehicle +public class EntityTrackedVehicle { /// /// Скорость @@ -20,6 +20,11 @@ public class TrackedVehicle /// public Color BodyColor { get; private set; } + public void SetBodyColor(Color bodyColor) + { + BodyColor = bodyColor; + } + /// /// Шаг перемещения Экскаватора/Гусеничной машины /// @@ -32,7 +37,7 @@ public class TrackedVehicle /// Вес /// Основной цвет - public TrackedVehicle(int speed, double weight, Color bodyColor) + public EntityTrackedVehicle(int speed, double weight, Color bodyColor) { Speed = speed; Weight = weight; diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs index 4825a31..4f676fa 100644 --- a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs +++ b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + panelCompanyTools = new Panel(); + buttonAddTrackedVehicle = new Button(); + buttonRefresh = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonGoToCheck = new Button(); + ButtonRemoveExcavator = new Button(); buttonCreateCompany = new Button(); panelStorage = new Panel(); buttonCollectionDel = new Button(); @@ -38,19 +44,12 @@ radioButtonMassive = new RadioButton(); textBoxCollectionName = new TextBox(); labelCollectionName = new Label(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - ButtonRemoveExcavator = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - buttonAddExcavator = new Button(); - buttonAddTrackedVehicle = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); - panelCompanyTools = new Panel(); groupBoxTools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - panelCompanyTools.SuspendLayout(); SuspendLayout(); // // groupBoxTools @@ -67,6 +66,73 @@ groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddTrackedVehicle); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(ButtonRemoveExcavator); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(2, 350); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(220, 289); + panelCompanyTools.TabIndex = 2; + // + // buttonAddTrackedVehicle + // + buttonAddTrackedVehicle.Anchor = AnchorStyles.Top; + buttonAddTrackedVehicle.Location = new Point(3, 3); + buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle"; + buttonAddTrackedVehicle.Size = new Size(215, 50); + buttonAddTrackedVehicle.TabIndex = 1; + buttonAddTrackedVehicle.Text = "Добавление гусеничной машины"; + buttonAddTrackedVehicle.UseVisualStyleBackColor = true; + buttonAddTrackedVehicle.Click += ButtonAddTrackedVehicle_Click; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top; + buttonRefresh.Location = new Point(3, 240); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(215, 40); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Anchor = AnchorStyles.Top; + maskedTextBoxPosition.Location = new Point(3, 115); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(215, 27); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top; + buttonGoToCheck.Location = new Point(3, 194); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(215, 40); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // ButtonRemoveExcavator + // + ButtonRemoveExcavator.Anchor = AnchorStyles.Top; + ButtonRemoveExcavator.Location = new Point(3, 148); + ButtonRemoveExcavator.Name = "ButtonRemoveExcavator"; + ButtonRemoveExcavator.Size = new Size(215, 40); + ButtonRemoveExcavator.TabIndex = 4; + ButtonRemoveExcavator.Text = "Удаление транспорта"; + ButtonRemoveExcavator.UseVisualStyleBackColor = true; + ButtonRemoveExcavator.Click += ButtonRemoveExcavator_Click; + // // buttonCreateCompany // buttonCreateCompany.Location = new Point(13, 317); @@ -170,71 +236,6 @@ labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции:"; // - // buttonRefresh - // - buttonRefresh.Anchor = AnchorStyles.Top; - buttonRefresh.Location = new Point(3, 240); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(215, 40); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; - // - // buttonGoToCheck - // - buttonGoToCheck.Anchor = AnchorStyles.Top; - buttonGoToCheck.Location = new Point(3, 194); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(215, 40); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; - // - // ButtonRemoveExcavator - // - ButtonRemoveExcavator.Anchor = AnchorStyles.Top; - ButtonRemoveExcavator.Location = new Point(3, 148); - ButtonRemoveExcavator.Name = "ButtonRemoveExcavator"; - ButtonRemoveExcavator.Size = new Size(215, 40); - ButtonRemoveExcavator.TabIndex = 4; - ButtonRemoveExcavator.Text = "Удаление транспорта"; - ButtonRemoveExcavator.UseVisualStyleBackColor = true; - ButtonRemoveExcavator.Click += ButtonRemoveExcavator_Click; - // - // maskedTextBoxPosition - // - maskedTextBoxPosition.Anchor = AnchorStyles.Top; - maskedTextBoxPosition.Location = new Point(3, 115); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(215, 27); - maskedTextBoxPosition.TabIndex = 3; - maskedTextBoxPosition.ValidatingType = typeof(int); - // - // buttonAddExcavator - // - buttonAddExcavator.Anchor = AnchorStyles.Top; - buttonAddExcavator.Location = new Point(2, 59); - buttonAddExcavator.Name = "buttonAddExcavator"; - buttonAddExcavator.Size = new Size(215, 50); - buttonAddExcavator.TabIndex = 2; - buttonAddExcavator.Text = "Добавление экскаватора"; - buttonAddExcavator.UseVisualStyleBackColor = true; - buttonAddExcavator.Click += ButtonAddExcavator_Click; - // - // buttonAddTrackedVehicle - // - buttonAddTrackedVehicle.Anchor = AnchorStyles.Top; - buttonAddTrackedVehicle.Location = new Point(3, 3); - buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle"; - buttonAddTrackedVehicle.Size = new Size(215, 50); - buttonAddTrackedVehicle.TabIndex = 1; - buttonAddTrackedVehicle.Text = "Добавление гусеничной машины"; - buttonAddTrackedVehicle.UseVisualStyleBackColor = true; - buttonAddTrackedVehicle.Click += ButtonAddTrackedVehicle_Click; - // // comboBoxSelectorCompany // comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; @@ -256,20 +257,6 @@ pictureBox.TabIndex = 1; pictureBox.TabStop = false; // - // panelCompanyTools - // - panelCompanyTools.Controls.Add(buttonAddTrackedVehicle); - panelCompanyTools.Controls.Add(buttonAddExcavator); - panelCompanyTools.Controls.Add(buttonRefresh); - panelCompanyTools.Controls.Add(maskedTextBoxPosition); - panelCompanyTools.Controls.Add(buttonGoToCheck); - panelCompanyTools.Controls.Add(ButtonRemoveExcavator); - panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(2, 350); - panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(220, 289); - panelCompanyTools.TabIndex = 2; - // // FormExcavatorCollection // AutoScaleDimensions = new SizeF(8F, 20F); @@ -280,11 +267,11 @@ Name = "FormExcavatorCollection"; Text = "Коллекция экскаваторов"; groupBoxTools.ResumeLayout(false); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); - panelCompanyTools.ResumeLayout(false); - panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -292,7 +279,6 @@ private GroupBox groupBoxTools; private ComboBox comboBoxSelectorCompany; - private Button buttonAddExcavator; private Button buttonAddTrackedVehicle; private PictureBox pictureBox; private Button ButtonRemoveExcavator; diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs index 6293088..37ef523 100644 --- a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs +++ b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs @@ -42,46 +42,29 @@ public partial class FormExcavatorCollection : Form } /// - /// Добавление гусеничной машины + /// Добавление гусеничной машины/ экскаватора /// /// /// - private void ButtonAddTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle)); - + private void ButtonAddTrackedVehicle_Click(object sender, EventArgs e) { + FormExcavatorConfig form = new(); + // TODO передать метод(c) + form.Show(); + form.AddEvent(SetTrackedVehicle); + } /// - /// Добавление экскаватора + /// Добавление экскаватора/гусинечной машины в коллекцию /// - /// - /// - private void ButtonAddExcavator_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningExcavator)); - - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) + /// + private void SetTrackedVehicle(DrawningTrackedVehicle? trackedVehicle) { - if (_company == null) + if (_company == null || trackedVehicle == null) { return; } - Random random = new(); - DrawningTrackedVehicle drawningTrackedVehicle; - switch (type) - { - case nameof(DrawningTrackedVehicle): - drawningTrackedVehicle = new DrawningTrackedVehicle(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); - break; - case nameof(DrawningExcavator): - drawningTrackedVehicle = new DrawningExcavator(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), true, true); - break; - default: - return; - } - - if (_company + drawningTrackedVehicle != -1) + if (_company + trackedVehicle != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -92,23 +75,6 @@ public partial class FormExcavatorCollection : 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; - } - /// /// Удаление объекта /// diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.Designer.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.Designer.cs new file mode 100644 index 0000000..0daa554 --- /dev/null +++ b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.Designer.cs @@ -0,0 +1,373 @@ +namespace ProjectExcavator +{ + partial class FormExcavatorConfig + { + /// + /// 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(); + labelWeight = new Label(); + groupBoxColors = new GroupBox(); + panelPurple = new Panel(); + panelYellow = new Panel(); + panelBlack = new Panel(); + panelGray = new Panel(); + panelBlue = new Panel(); + panelWhite = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); + checkBoxSupports = new CheckBox(); + checkBoxBucket = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + labelSpeed = new Label(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + buttonAdd = new Button(); + buttonCancel = new Button(); + panelObject = new Panel(); + pictureBoxObject = new PictureBox(); + labelBodyColor = new Label(); + labelAdditionalColor = new Label(); + groupBoxConfig.SuspendLayout(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBoxConfig + // + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(groupBoxColors); + groupBoxConfig.Controls.Add(checkBoxSupports); + groupBoxConfig.Controls.Add(checkBoxBucket); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + 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(548, 285); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(12, 90); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(36, 20); + labelWeight.TabIndex = 12; + labelWeight.Text = "Вес:"; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelPurple); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(panelBlack); + groupBoxColors.Controls.Add(panelGray); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(260, 27); + groupBoxColors.Margin = new Padding(3, 4, 3, 4); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Padding = new Padding(3, 4, 3, 4); + groupBoxColors.Size = new Size(259, 149); + groupBoxColors.TabIndex = 10; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.MediumPurple; + panelPurple.Location = new Point(201, 88); + panelPurple.Margin = new Padding(3, 4, 3, 4); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(39, 45); + panelPurple.TabIndex = 3; + // + // panelYellow + // + panelYellow.BackColor = Color.Gold; + panelYellow.Location = new Point(201, 29); + panelYellow.Margin = new Padding(3, 4, 3, 4); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(39, 45); + panelYellow.TabIndex = 1; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(137, 88); + panelBlack.Margin = new Padding(3, 4, 3, 4); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(39, 45); + panelBlack.TabIndex = 4; + // + // panelGray + // + panelGray.BackColor = Color.DarkGray; + panelGray.Location = new Point(77, 88); + panelGray.Margin = new Padding(3, 4, 3, 4); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(39, 45); + panelGray.TabIndex = 5; + // + // panelBlue + // + panelBlue.BackColor = Color.LightSteelBlue; + panelBlue.Location = new Point(137, 29); + panelBlue.Margin = new Padding(3, 4, 3, 4); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(39, 45); + panelBlue.TabIndex = 1; + // + // panelWhite + // + panelWhite.BackColor = Color.Transparent; + panelWhite.Location = new Point(17, 88); + panelWhite.Margin = new Padding(3, 4, 3, 4); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(39, 45); + panelWhite.TabIndex = 2; + // + // panelGreen + // + panelGreen.BackColor = Color.Olive; + panelGreen.Location = new Point(77, 29); + panelGreen.Margin = new Padding(3, 4, 3, 4); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(39, 45); + panelGreen.TabIndex = 1; + // + // panelRed + // + panelRed.BackColor = Color.DarkRed; + panelRed.Location = new Point(17, 29); + panelRed.Margin = new Padding(3, 4, 3, 4); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(39, 45); + panelRed.TabIndex = 0; + // + // checkBoxSupports + // + checkBoxSupports.AutoSize = true; + checkBoxSupports.Location = new Point(12, 248); + checkBoxSupports.Margin = new Padding(3, 4, 3, 4); + checkBoxSupports.Name = "checkBoxSupports"; + checkBoxSupports.Size = new Size(305, 24); + checkBoxSupports.TabIndex = 8; + checkBoxSupports.Text = "Признак наличия опоры для фиксации"; + checkBoxSupports.UseVisualStyleBackColor = true; + // + // checkBoxBucket + // + checkBoxBucket.AutoSize = true; + checkBoxBucket.Location = new Point(12, 208); + checkBoxBucket.Margin = new Padding(3, 4, 3, 4); + checkBoxBucket.Name = "checkBoxBucket"; + checkBoxBucket.Size = new Size(202, 24); + checkBoxBucket.TabIndex = 7; + checkBoxBucket.Text = "Признак наличия ковша"; + checkBoxBucket.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(109, 88); + 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(105, 27); + numericUpDownWeight.TabIndex = 6; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(109, 45); + 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(105, 27); + numericUpDownSpeed.TabIndex = 5; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(12, 47); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(76, 20); + labelSpeed.TabIndex = 3; + labelSpeed.Text = "Скорость:"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(404, 187); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(115, 45); + labelModifiedObject.TabIndex = 2; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(261, 187); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(115, 45); + labelSimpleObject.TabIndex = 1; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // buttonAdd + // + buttonAdd.Location = new Point(575, 241); + buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(86, 31); + buttonAdd.TabIndex = 3; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(740, 240); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 31); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelBodyColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(575, 13); + panelObject.Margin = new Padding(3, 4, 3, 4); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(251, 219); + panelObject.TabIndex = 5; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(13, 75); + pictureBoxObject.Margin = new Padding(3, 4, 3, 4); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(226, 132); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(16, 17); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(100, 40); + labelBodyColor.TabIndex = 2; + labelBodyColor.Text = "Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += labelBodyColor_DragDrop; + labelBodyColor.DragEnter += labelBodyColor_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(139, 17); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(100, 40); + labelAdditionalColor.TabIndex = 4; + labelAdditionalColor.Text = "Доп. цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter; + // + // FormExcavatorConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(838, 285); + Controls.Add(panelObject); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(groupBoxConfig); + Name = "FormExcavatorConfig"; + Text = "Создание объекта"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxConfig; + private Label labelSpeed; + private Label labelModifiedObject; + private Label labelSimpleObject; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private CheckBox checkBoxBucket; + private CheckBox checkBoxSupports; + private GroupBox groupBoxColors; + private Panel panelPurple; + private Panel panelYellow; + private Panel panelBlack; + private Panel panelGray; + private Panel panelBlue; + private Panel panelWhite; + private Panel panelGreen; + private Panel panelRed; + private Button buttonAdd; + private Button buttonCancel; + private Panel panelObject; + private PictureBox pictureBoxObject; + private Label labelWeight; + private Label labelAdditionalColor; + private Label labelBodyColor; + } +} \ No newline at end of file diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs new file mode 100644 index 0000000..e0eabf4 --- /dev/null +++ b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs @@ -0,0 +1,174 @@ +using ProjectExcavator.Drawnings; +using ProjectExcavator.Entities; + +namespace ProjectExcavator; + +/// +/// Форма конфигурации объекта +/// +public partial class FormExcavatorConfig : Form +{ + /// + /// Объект - прорисовка гусеничной машины/экскаватора + /// + private DrawningTrackedVehicle? _trackedVehicle; + + /// + /// Событие для передачи объекта + /// + private event Action? _trackedVehicleDelegate; + + /// + /// Конструктор + /// + public FormExcavatorConfig() + { + + 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; + + // TODO buttonCancel.Click привязать анонимный метод через lambda с закрытием формы(c) + buttonCancel.Click += (sender, e) => Close(); + + } + + /// + /// Привязка внешнего метода к событию + /// + /// + public void AddEvent(Action excavatorDelegate) + { + _trackedVehicleDelegate += excavatorDelegate; + } + + + /// + /// Прорисовка объекта + /// + private void DrawObject() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _trackedVehicle?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); + _trackedVehicle?.SetPosition(30, 20); + _trackedVehicle?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + 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) + { + e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None; + } + + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text)?.ToString()) + { + case "labelSimpleObject": + _trackedVehicle = new DrawningTrackedVehicle((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White); + break; + case "labelModifiedObject": + _trackedVehicle = new DrawningExcavator((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, + Color.Black, checkBoxBucket.Checked, checkBoxSupports.Checked); + break; + } + DrawObject(); + } + + // + /// Передаем информацию при нажатии на Panel + /// + /// + /// + private void Panel_MouseDown(object? sender, MouseEventArgs e) + { + //Отправка цвета в Drag&Drop + (sender as Panel)?.DoDragDrop((sender as Panel)?.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 (_trackedVehicle != null) + { + _trackedVehicle.EntityTrackedVehicle.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + DrawObject(); + } + } + + private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (_trackedVehicle is DrawningExcavator) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } + + private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_trackedVehicle?.EntityTrackedVehicle is EntityExcavator _catamaran) + { + _catamaran.SetAdditionalColor((Color)e.Data.GetData(typeof(Color))); + } + DrawObject(); + + } + + + /// + /// Передача объекта + /// + /// + /// + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (_trackedVehicle != null) + { + _trackedVehicleDelegate?.Invoke(_trackedVehicle); + Close(); + } + } +} + diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.resx b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.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 -- 2.25.1