diff --git a/ProjectMonorail/ProjectMonorail/DrawingMonorail.cs b/ProjectMonorail/ProjectMonorail/DrawingMonorail.cs index 91d934b..6ba898c 100644 --- a/ProjectMonorail/ProjectMonorail/DrawingMonorail.cs +++ b/ProjectMonorail/ProjectMonorail/DrawingMonorail.cs @@ -18,11 +18,21 @@ namespace ProjectMonorail.DrawingObjects /// private int _pictureWidth; + public int PictureWidth + { + set { _pictureWidth = value; } + } + /// /// Высота окна /// private int _pictureHeight; + public int PictureHeight + { + set { _pictureHeight = value; } + } + /// /// Левая координата прорисовки монорельса /// diff --git a/ProjectMonorail/ProjectMonorail/EntityExtendedMonorail.cs b/ProjectMonorail/ProjectMonorail/EntityExtendedMonorail.cs index b0540ea..5415e77 100644 --- a/ProjectMonorail/ProjectMonorail/EntityExtendedMonorail.cs +++ b/ProjectMonorail/ProjectMonorail/EntityExtendedMonorail.cs @@ -8,7 +8,7 @@ /// /// Дополнительный цвет (для опциональных элементов) /// - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } /// /// Признак (опция) наличия магнитной рельсы diff --git a/ProjectMonorail/ProjectMonorail/EntityMonorail.cs b/ProjectMonorail/ProjectMonorail/EntityMonorail.cs index fdf2f69..06f6059 100644 --- a/ProjectMonorail/ProjectMonorail/EntityMonorail.cs +++ b/ProjectMonorail/ProjectMonorail/EntityMonorail.cs @@ -18,7 +18,7 @@ /// /// Основной цвет /// - public Color MainColor { get; private set; } + public Color MainColor { get; set; } /// /// Шаг перемещения монорельса diff --git a/ProjectMonorail/ProjectMonorail/FormMonorailCollection.cs b/ProjectMonorail/ProjectMonorail/FormMonorailCollection.cs index 9e19d89..67af839 100644 --- a/ProjectMonorail/ProjectMonorail/FormMonorailCollection.cs +++ b/ProjectMonorail/ProjectMonorail/FormMonorailCollection.cs @@ -1,4 +1,5 @@ -using ProjectMonorail.Generics; +using ProjectMonorail.DrawingObjects; +using ProjectMonorail.Generics; namespace ProjectMonorail { @@ -87,13 +88,10 @@ namespace ProjectMonorail } } - /// - /// Добавление объекта в набор - /// - /// - /// - private void buttonAddMonorail_Click(object sender, EventArgs e) + private void addMonorail(DrawingMonorail monorail) { + monorail.PictureHeight = pictureBoxCollection.Height; + monorail.PictureWidth = pictureBoxCollection.Width; if (listBoxSets.SelectedIndex == -1) { return; @@ -105,19 +103,31 @@ namespace ProjectMonorail return; } - FormMonorail form = new(); - if (form.ShowDialog() == DialogResult.OK) + if (obj + monorail != -1) { - if (obj + form.SelectedMonorail != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowMonorails(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowMonorails(); } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + /// + /// Добавление объекта в набор + /// + /// + /// + private void buttonAddMonorail_Click(object sender, EventArgs e) + { + if (listBoxSets.SelectedIndex == -1) + { + return; + } + var formMonorailConfig = new FormMonorailConfig(); + formMonorailConfig.AddEvent(addMonorail); + formMonorailConfig.Show(); } /// diff --git a/ProjectMonorail/ProjectMonorail/FormMonorailConfig.Designer.cs b/ProjectMonorail/ProjectMonorail/FormMonorailConfig.Designer.cs new file mode 100644 index 0000000..cd33f69 --- /dev/null +++ b/ProjectMonorail/ProjectMonorail/FormMonorailConfig.Designer.cs @@ -0,0 +1,356 @@ +namespace ProjectMonorail +{ + partial class FormMonorailConfig + { + /// + /// 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() + { + groupBoxParameters = new GroupBox(); + panelColor = new Panel(); + panelPurple = new Panel(); + panelRed = new Panel(); + panelYellow = new Panel(); + panelGray = new Panel(); + panelGreen = new Panel(); + panelBlue = new Panel(); + panelWhite = new Panel(); + panelBlack = new Panel(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + checkBoxMagneticRail = new CheckBox(); + checkBoxExtraCabin = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + labelWeight = new Label(); + labelSpeed = new Label(); + pictureBoxObject = new PictureBox(); + panelObject = new Panel(); + labelAdditionalColor = new Label(); + labelMainColor = new Label(); + buttonAdd = new Button(); + buttonCancel = new Button(); + groupBoxParameters.SuspendLayout(); + panelColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panelObject.SuspendLayout(); + SuspendLayout(); + // + // groupBoxParameters + // + groupBoxParameters.Controls.Add(panelColor); + groupBoxParameters.Controls.Add(labelModifiedObject); + groupBoxParameters.Controls.Add(labelSimpleObject); + groupBoxParameters.Controls.Add(checkBoxMagneticRail); + groupBoxParameters.Controls.Add(checkBoxExtraCabin); + groupBoxParameters.Controls.Add(numericUpDownWeight); + groupBoxParameters.Controls.Add(numericUpDownSpeed); + groupBoxParameters.Controls.Add(labelWeight); + groupBoxParameters.Controls.Add(labelSpeed); + groupBoxParameters.Location = new Point(12, 12); + groupBoxParameters.Name = "groupBoxParameters"; + groupBoxParameters.Size = new Size(480, 218); + groupBoxParameters.TabIndex = 0; + groupBoxParameters.TabStop = false; + groupBoxParameters.Text = "Parameters"; + // + // panelColor + // + panelColor.Controls.Add(panelPurple); + panelColor.Controls.Add(panelRed); + panelColor.Controls.Add(panelYellow); + panelColor.Controls.Add(panelGray); + panelColor.Controls.Add(panelGreen); + panelColor.Controls.Add(panelBlue); + panelColor.Controls.Add(panelWhite); + panelColor.Controls.Add(panelBlack); + panelColor.Location = new Point(264, 22); + panelColor.Name = "panelColor"; + panelColor.Size = new Size(210, 112); + panelColor.TabIndex = 9; + panelColor.MouseDown += panelColor_MouseDown; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(168, 62); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(32, 34); + panelPurple.TabIndex = 7; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(10, 16); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(32, 34); + panelRed.TabIndex = 0; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(168, 16); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(32, 34); + panelYellow.TabIndex = 4; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(60, 62); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(32, 34); + panelGray.TabIndex = 5; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(60, 16); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(32, 34); + panelGreen.TabIndex = 2; + // + // panelBlue + // + panelBlue.BackColor = Color.FromArgb(0, 0, 192); + panelBlue.Location = new Point(114, 16); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(32, 34); + panelBlue.TabIndex = 3; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(10, 62); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(32, 34); + panelWhite.TabIndex = 1; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(114, 62); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(32, 34); + panelBlack.TabIndex = 6; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(378, 160); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(94, 33); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Modified"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(264, 160); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(94, 33); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Simple"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // checkBoxMagneticRail + // + checkBoxMagneticRail.AutoSize = true; + checkBoxMagneticRail.Location = new Point(15, 174); + checkBoxMagneticRail.Name = "checkBoxMagneticRail"; + checkBoxMagneticRail.Size = new Size(174, 19); + checkBoxMagneticRail.TabIndex = 5; + checkBoxMagneticRail.Text = "Indication of a magnetic rail"; + checkBoxMagneticRail.UseVisualStyleBackColor = true; + // + // checkBoxExtraCabin + // + checkBoxExtraCabin.AutoSize = true; + checkBoxExtraCabin.Location = new Point(15, 136); + checkBoxExtraCabin.Name = "checkBoxExtraCabin"; + checkBoxExtraCabin.Size = new Size(197, 19); + checkBoxExtraCabin.TabIndex = 4; + checkBoxExtraCabin.Text = "Indication of an additional cabin"; + checkBoxExtraCabin.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(77, 73); + 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(75, 23); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(77, 29); + 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(75, 23); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(15, 76); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(48, 15); + labelWeight.TabIndex = 1; + labelWeight.Text = "Weight:"; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(15, 33); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(42, 15); + labelSpeed.TabIndex = 0; + labelSpeed.Text = "Speed:"; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(12, 44); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(237, 134); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelMainColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(498, 12); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(261, 193); + panelObject.TabIndex = 2; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(139, 8); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(110, 33); + labelAdditionalColor.TabIndex = 10; + labelAdditionalColor.Text = "Additional color"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += labelColor_DragEnter; + // + // labelMainColor + // + labelMainColor.AllowDrop = true; + labelMainColor.BorderStyle = BorderStyle.FixedSingle; + labelMainColor.Location = new Point(12, 8); + labelMainColor.Name = "labelMainColor"; + labelMainColor.Size = new Size(110, 33); + labelMainColor.TabIndex = 9; + labelMainColor.Text = "Color"; + labelMainColor.TextAlign = ContentAlignment.MiddleCenter; + labelMainColor.DragDrop += labelMainColor_DragDrop; + labelMainColor.DragEnter += labelColor_DragEnter; + // + // buttonAdd + // + buttonAdd.Location = new Point(522, 211); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(91, 23); + buttonAdd.TabIndex = 3; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(647, 211); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(91, 23); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Cancellation"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormMonorailConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(772, 242); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(panelObject); + Controls.Add(groupBoxParameters); + Name = "FormMonorailConfig"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Object creation"; + groupBoxParameters.ResumeLayout(false); + groupBoxParameters.PerformLayout(); + panelColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + panelObject.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxParameters; + private Label labelSpeed; + private Label labelWeight; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private CheckBox checkBoxExtraCabin; + private CheckBox checkBoxMagneticRail; + private Panel panelGray; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelWhite; + private Panel panelRed; + private Panel panelPurple; + private Panel panelBlack; + private Label labelModifiedObject; + private Label labelSimpleObject; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelMainColor; + private Button buttonAdd; + private Button buttonCancel; + private Panel panelColor; + } +} \ No newline at end of file diff --git a/ProjectMonorail/ProjectMonorail/FormMonorailConfig.cs b/ProjectMonorail/ProjectMonorail/FormMonorailConfig.cs new file mode 100644 index 0000000..2cfe46f --- /dev/null +++ b/ProjectMonorail/ProjectMonorail/FormMonorailConfig.cs @@ -0,0 +1,159 @@ +using ProjectMonorail.DrawingObjects; +using ProjectMonorail.Entities; + +namespace ProjectMonorail +{ + public partial class FormMonorailConfig : Form + { + /// + /// Переменная-выбранный монорельс + /// + DrawingMonorail? _monorail = null; + + /// + /// Событие + /// + private event Action? EventAddMonorail; + + /// + /// Конструктор + /// + public FormMonorailConfig() + { + 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 += (s, e) => Close(); + } + + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddMonorail == null) + { + EventAddMonorail = ev; + } + else + { + EventAddMonorail += ev; + } + } + + /// + /// Отрисовать монорельс + /// + private void DrawMonorail() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _monorail?.SetPosition(5, 5); + _monorail?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, + DragDropEffects.Move | DragDropEffects.Copy); + } + + private void panelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, + 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 labelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(typeof(Color)) ?? 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": + _monorail = new DrawingMonorail((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _monorail = new DrawingExtendedMonorail((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxMagneticRail.Checked, + checkBoxExtraCabin.Checked, pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + DrawMonorail(); + } + + private void labelMainColor_DragDrop(object sender, DragEventArgs e) + { + if (_monorail == null) + return; + _monorail.EntityMonorail.MainColor = (Color)e.Data?.GetData(typeof(Color)); + DrawMonorail(); + } + + private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_monorail == null || _monorail is not DrawingExtendedMonorail) + return; + ((EntityExtendedMonorail)_monorail.EntityMonorail).AdditionalColor = (Color)e.Data?.GetData(typeof(Color)); + DrawMonorail(); + } + + /// + /// Добавление монорельса + /// + /// + /// + private void buttonAdd_Click(object sender, EventArgs e) + { + EventAddMonorail?.Invoke(_monorail); + Close(); + } + } +} diff --git a/ProjectMonorail/ProjectMonorail/FormMonorailConfig.resx b/ProjectMonorail/ProjectMonorail/FormMonorailConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectMonorail/ProjectMonorail/FormMonorailConfig.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