275 lines
10 KiB
C#
275 lines
10 KiB
C#
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 Task;
|
|
using System.Threading;
|
|
using GUI.UserControl;
|
|
using System.Drawing.Imaging;
|
|
using CoreUnit.Common;
|
|
using CoreUnit;
|
|
using DB.Recipe;
|
|
|
|
|
|
namespace GUI.Dialog
|
|
{
|
|
public partial class FieldScanDlg : Form
|
|
{
|
|
#region 사용자 정의 변수 및 함수
|
|
|
|
BackgroundWorkerUnit m_backgroundworker = null;
|
|
|
|
List<DB.Recipe.RecipeFieldScan.FieldScanParam> m_fieldScanParams = new List<DB.Recipe.RecipeFieldScan.FieldScanParam>();//필드 스캔 전 영역의 데이터를 가지고 있음
|
|
|
|
List<FieldScanImageUserControl> m_fieldScanImageUserControls = null;//필드 스캔 사용자 컨트롤의 객체 리스트
|
|
|
|
int m_scoutRowCount = 0;
|
|
int m_scoutColumnCount = 0;
|
|
public void Initialize()
|
|
{
|
|
#if _NO_USE_VISION
|
|
#else
|
|
#region 1.바둑판 배열 초기화(행렬)
|
|
m_fieldScanImageUserControls = new List<FieldScanImageUserControl>();
|
|
m_fieldScanImageUserControls.Clear();
|
|
|
|
FieldScanImageUserControl pic = null;
|
|
|
|
RscVision rscVision = (RscVision)Program.tm.GetResource(Task.Properties.Settings.Default.RscVisionID);
|
|
SizeF cameraROI = rscVision.VisionUnits[(int)RscVision.eCameraType.Scanner1].GetCameraROI();
|
|
SizeF scoutField = DB.Dao.SystemRecipe.ScoutField;
|
|
|
|
m_scoutRowCount = (int)Math.Ceiling(scoutField.Height / cameraROI.Height);
|
|
m_scoutColumnCount = (int)Math.Ceiling(scoutField.Width / cameraROI.Width);
|
|
|
|
int locationDeltaX = (int)Math.Round(splitContainer1.Panel2.Width / (double)m_scoutColumnCount);
|
|
int locationDeltaY = (int)Math.Round(splitContainer1.Panel2.Height / (double)m_scoutRowCount);
|
|
|
|
for (int row = 0; row < m_scoutRowCount; row++)
|
|
{
|
|
for (int col = 0; col < m_scoutColumnCount; col++)
|
|
{
|
|
pic = new FieldScanImageUserControl();
|
|
|
|
pic.Location = new Point(locationDeltaX * col, locationDeltaY * row);
|
|
//int newCol = 0;
|
|
//if (row % 2 == 0)
|
|
// newCol = col;
|
|
//else
|
|
// newCol = m_scoutColumnCount - 1 - col;
|
|
//pic.Location = new Point(locationDeltaX * newCol, locationDeltaY * row);
|
|
|
|
pic.Width = locationDeltaX;
|
|
pic.Height = locationDeltaY;
|
|
splitContainer1.Panel2.Controls.Add(pic);
|
|
|
|
m_fieldScanImageUserControls.Add(pic);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 2.스캔 필드 Parameter 객체 생성
|
|
|
|
m_fieldScanParams.Clear();
|
|
int imageWidth = rscVision.VisionUnits[(int)RscVision.eCameraType.Scanner1].GetImageWidth();
|
|
int imageHeight = rscVision.VisionUnits[(int)RscVision.eCameraType.Scanner1].GetImageHeight();
|
|
float scannerInitPosX = -1 * scoutField.Width / 2 + cameraROI.Width / 2;
|
|
float scannerInitPosY = scoutField.Height / 2 - cameraROI.Height / 2;
|
|
|
|
float scanPosX = scannerInitPosX;
|
|
float scanPosY = scannerInitPosY;
|
|
|
|
for (int row = 0; row < m_scoutRowCount; row++)
|
|
{
|
|
scanPosY = scannerInitPosY - cameraROI.Height * row;
|
|
|
|
for (int col = 0; col < m_scoutColumnCount; col++)
|
|
{
|
|
scanPosX = scannerInitPosX + cameraROI.Width * col;
|
|
//if (row % 2 == 0)
|
|
// scanPosX = scannerInitPosX + cameraROI.Width * col;
|
|
//else
|
|
// scanPosX = scannerInitPosX + cameraROI.Width * (m_scoutColumnCount - 1 - col);
|
|
|
|
DB.Recipe.RecipeFieldScan.FieldScanParam param = new DB.Recipe.RecipeFieldScan.FieldScanParam();
|
|
|
|
//1.스캐너 위치값 저장
|
|
param.ScannerPos = new PointF(scanPosX, scanPosY);
|
|
|
|
//2.이미지 Rectangle 값 저장
|
|
Point location = new Point(imageWidth * col, imageHeight * row);
|
|
//int newCol = 0;
|
|
//if (row % 2 == 0)
|
|
// newCol = col;
|
|
//else
|
|
// newCol = m_scoutColumnCount - 1 - col;
|
|
//Point location = new Point(imageWidth * newCol, imageHeight * row);
|
|
|
|
param.ImageRect = new Rectangle(location, new Size(imageWidth, imageHeight));
|
|
m_fieldScanParams.Add(param);
|
|
|
|
// scanPosX += cameraROI.Width;
|
|
}
|
|
|
|
//scanPosX = scannerInitPosX;
|
|
//scanPosY -= cameraROI.Height;
|
|
}
|
|
#endregion
|
|
|
|
//기존에 저장됐던 스캔필드 패러미터 범위와 새로 초기화한 것이 다를 경우
|
|
if (DB.Dao.FieldScanRecipe.FieldScanParams.Count != m_fieldScanParams.Count)
|
|
{
|
|
DB.Dao.FieldScanRecipe.FieldScanParams = m_fieldScanParams;
|
|
}
|
|
|
|
|
|
#region 3.스캔 필드 Parameter 값 초기화
|
|
LoadFieldScanParams();
|
|
#endregion
|
|
|
|
#region 4. 스캔 필드 항목 저장
|
|
SaveFieldScanParams();
|
|
#endregion
|
|
|
|
#endif
|
|
}
|
|
|
|
private void InitializeCheckerBoard()
|
|
{
|
|
|
|
}
|
|
public void SaveFieldScanParams()
|
|
{
|
|
for (int i =0; i<m_fieldScanImageUserControls.Count; i++)
|
|
{
|
|
FieldScanImageUserControl ctrl = m_fieldScanImageUserControls[i];
|
|
//m_fieldScanParams[i].ScoutPictureBox = ctrl.FieldScanImagePictureBox;
|
|
m_fieldScanParams[i].EnableScan = ctrl.EnableScan;
|
|
}
|
|
|
|
DB.Dao.FieldScanRecipe.FieldScanParams = m_fieldScanParams;
|
|
DB.Dao.FieldScanRecipe.Save();
|
|
}
|
|
public void LoadFieldScanParams()
|
|
{
|
|
for (int i = 0; i < DB.Dao.FieldScanRecipe.FieldScanParams.Count; i++)//필드 사이즈가 변경된 경우에는 기존 레시피 파일의 내용이 다를 수 있으므로 현재 스캔 필드 이미지로 설정함.
|
|
{
|
|
DB.Recipe.RecipeFieldScan.FieldScanParam param = DB.Dao.FieldScanRecipe.FieldScanParams[i];
|
|
FieldScanImageUserControl ctrl = m_fieldScanImageUserControls[i];
|
|
ctrl.EnableScan = param.EnableScan;
|
|
m_fieldScanParams[i].EnableScan = param.EnableScan; ;
|
|
m_fieldScanParams[i].OffsetPos = param.OffsetPos;
|
|
}
|
|
}
|
|
public void UpdateStatus()
|
|
{
|
|
switch (TaskManager.ReactiveLayerState)
|
|
{
|
|
case BabFramework.StateManager.ReactiveLayerStateType.HeavyAlarm:
|
|
case BabFramework.StateManager.ReactiveLayerStateType.Run:
|
|
if (splitContainer1.Panel1.Enabled == true) splitContainer1.Panel1.Enabled = false;
|
|
break;
|
|
|
|
case BabFramework.StateManager.ReactiveLayerStateType.Ready:
|
|
if (splitContainer1.Panel1.Enabled == false) splitContainer1.Panel1.Enabled = true;
|
|
break;
|
|
|
|
case BabFramework.StateManager.ReactiveLayerStateType.Idle:
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public FieldScanDlg()
|
|
{
|
|
InitializeComponent();
|
|
Name = "FieldScan";
|
|
|
|
m_backgroundworker = new BackgroundWorkerUnit(this, 300);
|
|
|
|
m_backgroundworker.evtDoWork += new BackgroundWorkerUnit.EventDoWork(UpdateStatus);
|
|
Initialize();
|
|
}
|
|
|
|
private void FieldScanDlg_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
e.Cancel = true;
|
|
this.Hide();
|
|
}
|
|
|
|
private void FieldScanImageDlg_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnFieldScanImage_Click(object sender, EventArgs e)
|
|
{
|
|
if (CoreUnit.Control.Dialog.MessageDlg.messageDlg.RunDlg("필드 스캔 작업을 시작하시겠습니까?", false, CoreUnit.Control.Dialog.MessageDlg.DialogMode.MODAL) == DialogResult.Yes)
|
|
{
|
|
SaveFieldScanParams();
|
|
|
|
List<string> subTaskList = new List<string>();
|
|
subTaskList.Add(Task.Properties.Settings.Default.BhScoutID);
|
|
Program.tm.RunTask(subTaskList, TaskManager.ReactiveLayerOperationType.SemiAuto, true);
|
|
}
|
|
}
|
|
|
|
private void btnSelectAllScannerField_Click(object sender, EventArgs e)
|
|
{
|
|
foreach(FieldScanImageUserControl ctrl in m_fieldScanImageUserControls)
|
|
{
|
|
ctrl.EnableScan = true;
|
|
ctrl.Invalidate();
|
|
}
|
|
|
|
SaveFieldScanParams();
|
|
}
|
|
|
|
private void btnDeselectAllScannerField_Click(object sender, EventArgs e)
|
|
{
|
|
foreach (FieldScanImageUserControl ctrl in m_fieldScanImageUserControls)
|
|
{
|
|
ctrl.EnableScan = false;
|
|
ctrl.Invalidate();
|
|
}
|
|
|
|
SaveFieldScanParams();
|
|
}
|
|
|
|
private void btnSaveFieldScanParam_Click(object sender, EventArgs e)
|
|
{
|
|
if (CoreUnit.Control.Dialog.MessageDlg.messageDlg.RunDlg("필드 스캔 항목값들을 저장 하시겠습니까?", false, CoreUnit.Control.Dialog.MessageDlg.DialogMode.MODAL) == DialogResult.Yes)
|
|
{
|
|
SaveFieldScanParams();
|
|
}
|
|
}
|
|
|
|
private void FieldScanImageDlg_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void FieldScanImageDlg_VisibleChanged(object sender, EventArgs e)
|
|
{
|
|
if (Visible)
|
|
{
|
|
m_backgroundworker.RunDoWork(sender);
|
|
}
|
|
else
|
|
{
|
|
m_backgroundworker.StopDoWork();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|