2026-06-05 13:44:39 +09:00

562 lines
21 KiB
C#

using CoreUnit.Common;
using CoreUnit.Scanner.UserControl.ScannerCanvas;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace CoreUnit.Scanner.UserControl.Canvas.Dialog
{
public partial class SnowmanEditorDlg : FormBase
{
public SnowmanEditorDlg(int selectedIndex)
{
InitializeComponent();
m_selectedIndex = selectedIndex;
if (m_selectedIndex < 1) {
m_scannerParam = ScannerCanvasUserCtrl.ScannerParams[0].Clone();
} else {
m_scannerParam = ScannerCanvasUserCtrl.ScannerParams[m_selectedIndex - 1].Clone();
}
Initialize();
}
ScannerParam m_scannerParam;
int m_selectedIndex = 0;
private void Initialize()
{
ScannerParamToDialog();
InitializeProfileTab();
InitializeRotationTab();
}
private void ScannerParamToDialog()
{
tbHeadWidth.Text = (m_scannerParam.HorizontalRadiusOfHead * 2).ToString("F2");
tbHeadHeight.Text = (m_scannerParam.VerticalRadiusOfHead * 2).ToString("F2");
tbBodyWidth.Text = (m_scannerParam.HorizontalRadiusOfBody * 2).ToString("F2");
tbBodyHeight.Text = (m_scannerParam.VerticalRadiusOfBody * 2).ToString("F2");
tbHeadVelocity.Text = m_scannerParam.HeadVelocity.ToString("F2");
tbBodyVelocity.Text = m_scannerParam.BodyVelocity.ToString("F2");
tbHeadVelocity2.Text = m_scannerParam.HeadVelocity.ToString("F2");
tbBodyVelocityPercent.Text = (m_scannerParam.BodyVelocity / m_scannerParam.HeadVelocity * 100).ToString("F1");
lbFrequency.Text = (1 / m_scannerParam.SnowManCycleTime).ToString("F2");
lbAngle.Text = m_scannerParam.TiltingAngle.ToString();
lbPitch.Text = (m_scannerParam.SnowManCycleTime * m_scannerParam.MarkSpeed).ToString("F2");
}
private void DialogToScannerParam()
{
try {
m_scannerParam.HorizontalRadiusOfHead = Convert.ToDouble(tbHeadWidth.Text) * 0.5;
m_scannerParam.VerticalRadiusOfHead = Convert.ToDouble(tbHeadHeight.Text) * 0.5;
m_scannerParam.HorizontalRadiusOfBody = Convert.ToDouble(tbBodyWidth.Text) * 0.5;
m_scannerParam.VerticalRadiusOfBody = Convert.ToDouble(tbBodyHeight.Text) * 0.5;
m_scannerParam.HeadVelocity = Convert.ToDouble(tbHeadVelocity.Text);
m_scannerParam.BodyVelocity = Convert.ToDouble(tbBodyVelocity.Text);
ScannerCanvasUserCtrl.ScannerParams[m_selectedIndex - 1] = m_scannerParam.Clone();
} catch {
MessageBox.Show("Check the Paramter Value");
}
}
private void InitializeRotationTab()
{
tbRotationAngle.Text = m_scannerParam.TiltingAngle.ToString();
UpLoadPictureBoxList();
Bitmap canvas = new Bitmap(pbRotationAngle.Width, pbRotationAngle.Height);
using (Graphics g = Graphics.FromImage(canvas)) {
//흰 색으로 배경 채우기
g.FillRectangle(Brushes.White, 0, 0, canvas.Width, canvas.Height);
DrawArrow(g, canvas.Width, canvas.Height);
}
//pbRotationAnlge 그리기
DrawSnowManAngle(pbRotationAngle, canvas, m_scannerParam.TiltingAngle);
canvas = new Bitmap(pbAngle0.Width, pbAngle0.Height);
using (Graphics g = Graphics.FromImage(canvas)) {
//흰 색으로 배경 채우기
g.FillRectangle(Brushes.White, 0, 0, canvas.Width, canvas.Height);
DrawArrow(g, canvas.Width, canvas.Height);
}
//이외 모든 pictureBox 그리기
foreach (PictureBox pb in pbList) {
DrawSnowManAngle(pb, canvas);
}
}
//Dictionary<string, PictureBox> pbList = new Dictionary<string, PictureBox>();
List<PictureBox> pbList = new List<PictureBox>();
private void InitializeProfileTab()
{
#region pbShapeOfSnowMan 업데이트
Bitmap canvas = new Bitmap(pbShapeOfSnowMan.Width, pbShapeOfSnowMan.Height);
using (Graphics g = Graphics.FromImage(canvas)) {
//흰 색으로 배경 채우기
g.FillRectangle(Brushes.White, 0, 0, canvas.Width, canvas.Height);
DrawArrow(g, canvas.Width, canvas.Height);
}
double angle = Convert.ToDouble(lbAngle.Text);
double headWidth = Convert.ToDouble(tbHeadWidth.Text);
double headHeight = Convert.ToDouble(tbHeadHeight.Text);
double bodyWidth = Convert.ToDouble(tbBodyWidth.Text);
double bodyHeight = Convert.ToDouble(tbBodyHeight.Text);
DrawSnowManAngle(pbShapeOfSnowMan, canvas, angle, headWidth, headHeight, bodyWidth, bodyHeight);
#endregion
#region pbShowPitch 업데이트
canvas = new Bitmap(pbShowPitch.Width, pbShowPitch.Height);
using (Graphics g = Graphics.FromImage(canvas)) {
//흰 색으로 배경 채우기
g.FillRectangle(Brushes.White, 0, 0, canvas.Width, canvas.Height);
DrawArrow(g, canvas.Width, canvas.Height);
}
angle = Convert.ToDouble(lbAngle.Text);
headWidth = Convert.ToDouble(tbHeadWidth.Text);
headHeight = Convert.ToDouble(tbHeadHeight.Text);
bodyWidth = Convert.ToDouble(tbBodyWidth.Text);
bodyHeight = Convert.ToDouble(tbBodyHeight.Text);
double pitch = Convert.ToDouble(lbPitch.Text);
DrawSnowManPitch(pbShowPitch, canvas, angle, headWidth, headHeight, bodyWidth, bodyHeight, pitch);
#endregion
}
private void DrawArrow(Graphics g, int width, int height)
{
int arrowBodyHeight = (int)(height * 0.2);
int arrowBodyWidth = (int)(width * 0.6);
Rectangle rect = new Rectangle(10, (int)(height / 2 - arrowBodyHeight / 2), arrowBodyWidth, arrowBodyHeight);
g.FillRectangle(Brushes.LimeGreen, rect);
int arrowHeadHeight = arrowBodyHeight * 2;
int arrowHeadWidth = (int)(arrowBodyWidth * 0.5);
Point[] p = new Point[]
{
new Point(arrowBodyWidth, (int)(height/2 - arrowHeadHeight/2)),
new Point(arrowBodyWidth, (int)(height/2 + arrowHeadHeight/2)),
new Point(arrowBodyWidth + arrowHeadWidth , height/2)
};
g.FillPolygon(Brushes.LimeGreen, p);
}
private void DrawSnowManAngle(PictureBox pictureBox, Bitmap canvas)
{
int imageWidth = canvas.Width;
int imageHeight = canvas.Height;
int size = (int)(imageWidth * 0.4);
Bitmap snowMan = new Bitmap(imageWidth, imageHeight);
using (Graphics g = Graphics.FromImage(snowMan)) {
using (Pen p = new Pen(Color.Blue, 3)) {
g.TranslateTransform(imageWidth / 2, imageHeight / 2);
int angle = Convert.ToInt16(pictureBox.Name.ToString().Substring(7));
g.RotateTransform(-angle);
g.DrawEllipse(p, -size / 2, -size, size, size);
g.DrawEllipse(p, -size / 2, 0, size, size);
}
}
Bitmap finalImage = (Bitmap)canvas.Clone();
using (Graphics g = Graphics.FromImage(finalImage)) {
g.DrawImage(snowMan, 0, 0);
}
pictureBox.Image = finalImage;
}
private void DrawSnowManAngle(PictureBox pictureBox, Bitmap canvas, double angle)
{
int imageWidth = canvas.Width;
int imageHeight = canvas.Height;
int size = (int)(imageWidth * 0.4);
Bitmap snowMan = new Bitmap(imageWidth, imageHeight);
using (Graphics g = Graphics.FromImage(snowMan)) {
using (Pen p = new Pen(Color.Blue, 3)) {
g.TranslateTransform(imageWidth / 2, imageHeight / 2);
g.RotateTransform(-(int)angle);
g.DrawEllipse(p, -size / 2, -size, size, size);
g.DrawEllipse(p, -size / 2, 0, size, size);
}
}
Bitmap finalImage = (Bitmap)canvas.Clone();
using (Graphics g = Graphics.FromImage(finalImage)) {
g.DrawImage(snowMan, 0, 0);
}
pictureBox.Image = finalImage;
}
private void DrawSnowManAngle(PictureBox pictureBox, Bitmap canvas, double angle, double headWidth, double headHeight, double bodyWidth, double bodyHeight)
{
int imageWidth = canvas.Width;
int imageHeight = canvas.Height;
//이미지 크기에 맞춰서 타원 크기 정하기
List<double> sizeList = new List<double>();
sizeList.Add(headWidth);
sizeList.Add(headHeight);
sizeList.Add(bodyWidth);
sizeList.Add(bodyHeight);
double maxSize = 0;
for (int i = 0; i < sizeList.Count; i++) {
if (sizeList[i] > maxSize) {
maxSize = sizeList[i];
}
}
double ratio = imageHeight * 0.4 / maxSize;
int headWidthImage = (int)(headWidth * ratio);
int headHeightImage = (int)(headHeight * ratio);
int bodyWidthImage = (int)(bodyWidth * ratio);
int bodyHeightImage = (int)(bodyHeight * ratio);
Bitmap snowMan = new Bitmap(imageWidth, imageHeight);
using (Graphics g = Graphics.FromImage(snowMan)) {
using (Pen p = new Pen(Color.Blue, 3)) {
g.TranslateTransform(imageWidth / 2, imageHeight / 2);
g.RotateTransform(-(int)angle);
g.DrawEllipse(p, -headWidthImage / 2, -headHeightImage, headWidthImage, headHeightImage);
g.DrawEllipse(p, -bodyWidthImage / 2, 0, bodyWidthImage, bodyHeightImage);
}
}
Bitmap finalImage = (Bitmap)canvas.Clone();
using (Graphics g = Graphics.FromImage(finalImage)) {
g.DrawImage(snowMan, 0, 0);
}
pictureBox.Image = finalImage;
}
private void DrawSnowManPitch(PictureBox pictureBox, Bitmap canvas, double angle, double headWidth, double headHeight, double bodyWidth, double bodyHeight, double pitch)
{
int imageWidth = canvas.Width;
int imageHeight = canvas.Height;
//이미지 크기에 맞춰서 타원 크기 정하기
List<double> sizeList = new List<double>();
sizeList.Add(headWidth);
sizeList.Add(headHeight);
sizeList.Add(bodyWidth);
sizeList.Add(bodyHeight);
sizeList.Add(pitch);
double maxSize = 0;
for (int i = 0; i < sizeList.Count; i++) {
if (sizeList[i] > maxSize) {
maxSize = sizeList[i];
}
}
double ratio = imageHeight * 0.4 / maxSize;
int headWidthImage = (int)(headWidth * ratio);
int headHeightImage = (int)(headHeight * ratio);
int bodyWidthImage = (int)(bodyWidth * ratio);
int bodyHeightImage = (int)(bodyHeight * ratio);
int pitchImage = (int)(pitch * ratio);
Bitmap snowMan = new Bitmap(imageWidth, imageHeight);
using (Graphics g = Graphics.FromImage(snowMan)) {
//첫번째
using (Pen p = new Pen(Color.Pink, 3)) {
g.TranslateTransform(imageWidth / 2 - pitchImage, imageHeight / 2);
g.RotateTransform(-(int)angle);
g.DrawEllipse(p, -headWidthImage / 2, -headHeightImage, headWidthImage, headHeightImage);
g.DrawEllipse(p, -bodyWidthImage / 2, 0, bodyWidthImage, bodyHeightImage);
}
}
using (Graphics g = Graphics.FromImage(snowMan)) {
//두번째 (가운데)
using (Pen p = new Pen(Color.Blue, 3)) {
g.TranslateTransform(imageWidth / 2, imageHeight / 2);
g.RotateTransform(-(int)angle);
g.DrawEllipse(p, -headWidthImage / 2, -headHeightImage, headWidthImage, headHeightImage);
g.DrawEllipse(p, -bodyWidthImage / 2, 0, bodyWidthImage, bodyHeightImage);
}
}
using (Graphics g = Graphics.FromImage(snowMan)) {
//세번째
using (Pen p = new Pen(Color.Red, 3)) {
g.TranslateTransform(imageWidth / 2 + pitchImage, imageHeight / 2);
g.RotateTransform(-(int)angle);
g.DrawEllipse(p, -headWidthImage / 2, -headHeightImage, headWidthImage, headHeightImage);
g.DrawEllipse(p, -bodyWidthImage / 2, 0, bodyWidthImage, bodyHeightImage);
}
}
Bitmap finalImage = (Bitmap)canvas.Clone();
using (Graphics g = Graphics.FromImage(finalImage)) {
g.DrawImage(snowMan, 0, 0);
}
pictureBox.Image = finalImage;
}
private void UpLoadPictureBoxList()
{
pbList.Clear();
pbList.Add(pbAngle0);
pbList.Add(pbAngle15);
pbList.Add(pbAngle30);
pbList.Add(pbAngle45);
pbList.Add(pbAngle60);
pbList.Add(pbAngle75);
pbList.Add(pbAngle90);
pbList.Add(pbAngle105);
pbList.Add(pbAngle120);
pbList.Add(pbAngle135);
pbList.Add(pbAngle150);
pbList.Add(pbAngle165);
pbList.Add(pbAngle180);
pbList.Add(pbAngle195);
pbList.Add(pbAngle210);
pbList.Add(pbAngle225);
pbList.Add(pbAngle240);
pbList.Add(pbAngle255);
pbList.Add(pbAngle270);
pbList.Add(pbAngle285);
pbList.Add(pbAngle300);
pbList.Add(pbAngle315);
pbList.Add(pbAngle330);
pbList.Add(pbAngle345);
}
private void ApplyRotationAngle(int iAngle)
{
Bitmap canvas = new Bitmap(pbRotationAngle.Width, pbRotationAngle.Height);
#region Rotation Tab
using (Graphics g = Graphics.FromImage(canvas)) {
//흰 색으로 배경 채우기
g.FillRectangle(Brushes.White, 0, 0, canvas.Width, canvas.Height);
DrawArrow(g, canvas.Width, canvas.Height);
}
//pbRotationAnlge 그리기
DrawSnowManAngle(pbRotationAngle, canvas, m_scannerParam.TiltingAngle);
trackBarAngle.Value = (int)m_scannerParam.TiltingAngle;
#endregion
#region Profile Tab
canvas = new Bitmap(pbShapeOfSnowMan.Width, pbShapeOfSnowMan.Height);
using (Graphics g = Graphics.FromImage(canvas)) {
//흰 색으로 배경 채우기
g.FillRectangle(Brushes.White, 0, 0, canvas.Width, canvas.Height);
DrawArrow(g, canvas.Width, canvas.Height);
}
double angle = iAngle;
double headWidth = Convert.ToDouble(tbHeadWidth.Text);
double headHeight = Convert.ToDouble(tbHeadHeight.Text);
double bodyWidth = Convert.ToDouble(tbBodyWidth.Text);
double bodyHeight = Convert.ToDouble(tbBodyHeight.Text);
DrawSnowManAngle(pbShapeOfSnowMan, canvas, angle, headWidth, headHeight, bodyWidth, bodyHeight);
#endregion
}
private void btnApplyRotationAngle_Click(object sender, EventArgs e)
{
try {
m_scannerParam.TiltingAngle = Convert.ToInt16(tbRotationAngle.Text);
lbAngle.Text = tbRotationAngle.Text;
ApplyRotationAngle(m_scannerParam.TiltingAngle);
} catch {
MessageBox.Show("Check the Paramter Value");
}
}
private void btnOk_Click(object sender, EventArgs e)
{
DialogToScannerParam();
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void btnApplySize_Click(object sender, EventArgs e)
{
try {
Bitmap canvas = new Bitmap(pbShapeOfSnowMan.Width, pbShapeOfSnowMan.Height);
using (Graphics g = Graphics.FromImage(canvas)) {
//흰 색으로 배경 채우기
g.FillRectangle(Brushes.White, 0, 0, canvas.Width, canvas.Height);
DrawArrow(g, canvas.Width, canvas.Height);
}
m_scannerParam.TiltingAngle = Convert.ToInt32(lbAngle.Text);
m_scannerParam.HorizontalRadiusOfHead = Convert.ToDouble(tbHeadWidth.Text) * 0.5;
m_scannerParam.VerticalRadiusOfHead = Convert.ToDouble(tbHeadHeight.Text) * 0.5;
m_scannerParam.HorizontalRadiusOfBody = Convert.ToDouble(tbBodyWidth.Text) * 0.5;
m_scannerParam.VerticalRadiusOfBody = Convert.ToDouble(tbBodyHeight.Text) * 0.5;
lbFrequency.Text = (1 / m_scannerParam.SnowManCycleTime).ToString("F2");
lbAngle.Text = m_scannerParam.TiltingAngle.ToString();
lbPitch.Text = (m_scannerParam.SnowManCycleTime * m_scannerParam.MarkSpeed).ToString("F2");
DrawSnowManAngle(pbShapeOfSnowMan, canvas, m_scannerParam.TiltingAngle,
m_scannerParam.HorizontalRadiusOfHead * 2, m_scannerParam.VerticalRadiusOfHead * 2, m_scannerParam.HorizontalRadiusOfBody * 2, m_scannerParam.VerticalRadiusOfBody * 2);
canvas = new Bitmap(pbShowPitch.Width, pbShowPitch.Height);
using (Graphics g = Graphics.FromImage(canvas)) {
//흰 색으로 배경 채우기
g.FillRectangle(Brushes.White, 0, 0, canvas.Width, canvas.Height);
DrawArrow(g, canvas.Width, canvas.Height);
}
DrawSnowManPitch(pbShowPitch, canvas, m_scannerParam.TiltingAngle,
m_scannerParam.HorizontalRadiusOfHead * 2, m_scannerParam.VerticalRadiusOfHead * 2, m_scannerParam.HorizontalRadiusOfBody * 2, m_scannerParam.VerticalRadiusOfBody * 2, Convert.ToDouble(lbPitch.Text));
} catch {
MessageBox.Show("Check the Paramter Value");
}
}
private void btnApplyVelocityAbsolute_Click(object sender, EventArgs e)
{
try {
m_scannerParam.HeadVelocity = Convert.ToDouble(tbHeadVelocity.Text);
m_scannerParam.BodyVelocity = Convert.ToDouble(tbBodyVelocity.Text);
tbHeadVelocity2.Text = tbHeadVelocity.Text;
lbFrequency.Text = (1 / m_scannerParam.SnowManCycleTime).ToString("F2");
lbAngle.Text = m_scannerParam.TiltingAngle.ToString();
lbPitch.Text = (m_scannerParam.SnowManCycleTime * m_scannerParam.MarkSpeed).ToString("F2");
Bitmap canvas = new Bitmap(pbShowPitch.Width, pbShowPitch.Height);
using (Graphics g = Graphics.FromImage(canvas)) {
//흰 색으로 배경 채우기
g.FillRectangle(Brushes.White, 0, 0, canvas.Width, canvas.Height);
DrawArrow(g, canvas.Width, canvas.Height);
}
DrawSnowManPitch(pbShowPitch, canvas, m_scannerParam.TiltingAngle,
m_scannerParam.HorizontalRadiusOfHead * 2, m_scannerParam.VerticalRadiusOfHead * 2, m_scannerParam.HorizontalRadiusOfBody * 2, m_scannerParam.VerticalRadiusOfBody * 2, Convert.ToDouble(lbPitch.Text));
} catch {
MessageBox.Show("Check the Paramter Value");
}
}
private void btnApplyVelocityByRatio_Click(object sender, EventArgs e)
{
try {
double percent = Convert.ToDouble(tbBodyVelocityPercent.Text);
m_scannerParam.BodyVelocity = m_scannerParam.HeadVelocity * percent * 0.01;
tbBodyVelocity.Text = m_scannerParam.BodyVelocity.ToString("F2");
} catch {
MessageBox.Show("Check the Paramter Value");
}
}
private void trackBarAngle_Scroll(object sender, EventArgs e)
{
tbRotationAngle.Text = trackBarAngle.Value.ToString();
}
private void rbAngle_CheckedChanged(object sender, EventArgs e)
{
try {
RadioButton rbAngle = (RadioButton)sender;
if (rbAngle.Checked) {
int angle = Convert.ToInt16(rbAngle.Text);
m_scannerParam.TiltingAngle = angle;
lbAngle.Text = angle.ToString();
tbRotationAngle.Text = angle.ToString();
ApplyRotationAngle(angle);
}
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
}
}