PIbd-21. Danilov V.V. Lab work 05 #5

Closed
VoOneChek wants to merge 3 commits from LabWork05 into LabWork04
4 changed files with 617 additions and 0 deletions
Showing only changes of commit 4d68354f6f - Show all commits

View File

@ -0,0 +1,347 @@
namespace Project_DumpTruck
{
partial class FormTruckConfig
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
groupBox1 = new GroupBox();
label4 = new Label();
label3 = new Label();
groupBox2 = new GroupBox();
panelPurple = new Panel();
panelBlack = new Panel();
panelGray = new Panel();
panelWhite = new Panel();
panelYellow = new Panel();
panelBlue = new Panel();
panelGreen = new Panel();
panelRed = new Panel();
checkBoxTent = new CheckBox();
checkBoxBodyKit = new CheckBox();
numericUpDownWeight = new NumericUpDown();
numericUpDownSpeed = new NumericUpDown();
label2 = new Label();
label1 = new Label();
pictureBoxObject = new PictureBox();
panel9 = new Panel();
label6 = new Label();
label5 = new Label();
buttonOk = new Button();
button2 = new Button();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
panel9.SuspendLayout();
SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(label4);
groupBox1.Controls.Add(label3);
groupBox1.Controls.Add(groupBox2);
groupBox1.Controls.Add(checkBoxTent);
groupBox1.Controls.Add(checkBoxBodyKit);
groupBox1.Controls.Add(numericUpDownWeight);
groupBox1.Controls.Add(numericUpDownSpeed);
groupBox1.Controls.Add(label2);
groupBox1.Controls.Add(label1);
groupBox1.Location = new Point(12, 12);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(444, 196);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Параметры";
//
// label4
//
label4.BorderStyle = BorderStyle.FixedSingle;
label4.Location = new Point(344, 156);
label4.Name = "label4";
label4.Size = new Size(94, 23);
label4.TabIndex = 8;
label4.Text = "Продвинутый";
label4.TextAlign = ContentAlignment.MiddleCenter;
//
// label3
//
label3.BorderStyle = BorderStyle.FixedSingle;
label3.Location = new Point(238, 156);
label3.Name = "label3";
label3.Size = new Size(100, 23);
label3.TabIndex = 7;
label3.Text = "Простой";
label3.TextAlign = ContentAlignment.MiddleCenter;
label3.MouseDown += LabelObject_MouseDown;
//
// groupBox2
//
groupBox2.Controls.Add(panelPurple);
groupBox2.Controls.Add(panelBlack);
groupBox2.Controls.Add(panelGray);
groupBox2.Controls.Add(panelWhite);
groupBox2.Controls.Add(panelYellow);
groupBox2.Controls.Add(panelBlue);
groupBox2.Controls.Add(panelGreen);
groupBox2.Controls.Add(panelRed);
groupBox2.Location = new Point(238, 22);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(200, 127);
groupBox2.TabIndex = 6;
groupBox2.TabStop = false;
groupBox2.Text = "Цвета";
//
// panelPurple
//
panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(137, 70);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(33, 32);
panelPurple.TabIndex = 1;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(98, 70);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(33, 32);
panelBlack.TabIndex = 1;
//
// panelGray
//
panelGray.BackColor = Color.Silver;
panelGray.Location = new Point(59, 70);
panelGray.Name = "panelGray";
panelGray.Size = new Size(33, 32);
panelGray.TabIndex = 1;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(20, 70);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(33, 32);
panelWhite.TabIndex = 1;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(137, 32);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(33, 32);
panelYellow.TabIndex = 1;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(98, 32);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(33, 32);
panelBlue.TabIndex = 1;
//
// panelGreen
//
panelGreen.BackColor = Color.Lime;
panelGreen.Location = new Point(59, 32);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(33, 32);
panelGreen.TabIndex = 1;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(20, 32);
panelRed.Name = "panelRed";
panelRed.Size = new Size(33, 32);
panelRed.TabIndex = 0;
//
// checkBoxTent
//
checkBoxTent.AutoSize = true;
checkBoxTent.Location = new Point(15, 156);
checkBoxTent.Name = "checkBoxTent";
checkBoxTent.Size = new Size(155, 19);
checkBoxTent.TabIndex = 5;
checkBoxTent.Text = "Признак наличия тента";
checkBoxTent.UseVisualStyleBackColor = true;
//
// checkBoxBodyKit
//
checkBoxBodyKit.AutoSize = true;
checkBoxBodyKit.Location = new Point(15, 117);
checkBoxBodyKit.Name = "checkBoxBodyKit";
checkBoxBodyKit.Size = new Size(162, 19);
checkBoxBodyKit.TabIndex = 4;
checkBoxBodyKit.Text = "Признак наличия кузова";
checkBoxBodyKit.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(83, 77);
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(120, 23);
numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(83, 31);
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(120, 23);
numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(15, 79);
label2.Name = "label2";
label2.Size = new Size(29, 15);
label2.TabIndex = 1;
label2.Text = "Вес:";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(15, 33);
label1.Name = "label1";
label1.Size = new Size(62, 15);
label1.TabIndex = 0;
label1.Text = "Скорость:";
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(13, 54);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(188, 95);
pictureBoxObject.TabIndex = 1;
pictureBoxObject.TabStop = false;
//
// panel9
//
panel9.AllowDrop = true;
panel9.Controls.Add(label6);
panel9.Controls.Add(label5);
panel9.Controls.Add(pictureBoxObject);
panel9.Location = new Point(462, 12);
panel9.Name = "panel9";
panel9.Size = new Size(221, 160);
panel9.TabIndex = 2;
//
// label6
//
label6.BorderStyle = BorderStyle.FixedSingle;
label6.Location = new Point(107, 9);
label6.Name = "label6";
label6.Size = new Size(94, 38);
label6.TabIndex = 9;
label6.Text = "Доп. цвет";
label6.TextAlign = ContentAlignment.MiddleCenter;
//
// label5
//
label5.BorderStyle = BorderStyle.FixedSingle;
label5.Location = new Point(13, 9);
label5.Name = "label5";
label5.Size = new Size(88, 38);
label5.TabIndex = 8;
label5.Text = "Цвет";
label5.TextAlign = ContentAlignment.MiddleCenter;
//
// buttonOk
//
buttonOk.Location = new Point(475, 185);
buttonOk.Name = "buttonOk";
buttonOk.Size = new Size(75, 23);
buttonOk.TabIndex = 3;
buttonOk.Text = "Добавить";
buttonOk.UseVisualStyleBackColor = true;
buttonOk.Click += buttonOk_Click;
//
// button2
//
button2.Location = new Point(588, 185);
button2.Name = "button2";
button2.Size = new Size(75, 23);
button2.TabIndex = 4;
button2.Text = "Отмена";
button2.UseVisualStyleBackColor = true;
//
// FormTruckConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(700, 225);
Controls.Add(button2);
Controls.Add(buttonOk);
Controls.Add(panel9);
Controls.Add(groupBox1);
Name = "FormTruckConfig";
Text = "Создание объекта";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
panel9.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private GroupBox groupBox2;
private Panel panelPurple;
private Panel panelBlack;
private Panel panelGray;
private Panel panelWhite;
private Panel panelYellow;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelRed;
private CheckBox checkBoxTent;
private CheckBox checkBoxBodyKit;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label label2;
private Label label1;
private Label label4;
private Label label3;
private PictureBox pictureBoxObject;
private Panel panel9;
private Label label6;
private Label label5;
private Button buttonOk;
private Button button2;
}
}

View File

@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Project_DumpTruck.DrawningObjects;
namespace Project_DumpTruck
{
public partial class FormTruckConfig : Form
{
/// <summary>
/// Переменная-выбранная машина
/// </summary>
DrawningTruck? _truck = null;
/// <summary>
/// Событие
/// </summary>
private event TruckDelegate? EventAddTruck;
/// <summary>
/// Конструктор
/// </summary>
public FormTruckConfig()
{
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;
// TODO buttonCancel.Click with lambda
}
/// <summary>
/// Отрисовать машину
/// </summary>
private void DrawCar()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_truck?.SetPosition(5, 5);
_truck?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(TruckDelegate ev)
{
if (EventAddTruck == null)
{
EventAddTruck = ev;
}
else
{
EventAddTruck += ev;
}
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_truck = new DrawningTruck((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelModifiedObject":
_truck = new DrawningDumpTruck((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxBodyKit.Checked,
checkBoxTent.Checked, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
}
DrawCar();
}
// TODO Реализовать логику смены цветов: основного и дополнительного(для продвинутого объекта)
/// <summary>
/// Добавление машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonOk_Click(object sender, EventArgs e)
{
EventAddTruck?.Invoke(_truck);
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Project_DumpTruck.DrawningObjects;
namespace Project_DumpTruck
{
/// <summary>
/// Делегат для передачи объекта-автомобиля
/// </summary>
/// <param name="car"></param>
public delegate void TruckDelegate(DrawningTruck Truck);
}