|
@@ -58,32 +58,39 @@ namespace HOZProject
|
|
|
#region 加载切孔文件,生成切孔列表
|
|
|
private void pbCutHoleFile_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- if (FormHOZMainObject.m_MeasureFile == null)
|
|
|
- {
|
|
|
- MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
- }
|
|
|
- else
|
|
|
+ try
|
|
|
{
|
|
|
- if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
|
|
|
+ if (FormHOZMainObject.m_MeasureFile == null)
|
|
|
{
|
|
|
- MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
|
|
|
- //文件路径
|
|
|
- string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
|
|
|
- FormHOZMainObject.CreateCutHoleList(ListCutHole);
|
|
|
- //显示导入的切孔数量
|
|
|
- lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
|
|
|
- tbCutHoleFilePath.Text = CutHoleFilePath;
|
|
|
- //保存测量文件
|
|
|
- if (FormHOZMainObject.IsSave)
|
|
|
+ if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
|
|
|
{
|
|
|
- FormHOZMainObject.m_MeasureFile.Save();
|
|
|
+ MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
|
|
|
+ //文件路径
|
|
|
+ string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
|
|
|
+ FormHOZMainObject.CreateCutHoleList(ListCutHole);
|
|
|
+ //显示导入的切孔数量
|
|
|
+ lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
|
|
|
+ tbCutHoleFilePath.Text = CutHoleFilePath;
|
|
|
+ //保存测量文件
|
|
|
+ if (FormHOZMainObject.IsSave)
|
|
|
+ {
|
|
|
+ FormHOZMainObject.m_MeasureFile.Save();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogManager.LogError(ex.Message);
|
|
|
+ }
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
@@ -95,55 +102,96 @@ namespace HOZProject
|
|
|
/// <param name="e"></param>
|
|
|
private void pbCutHoleAuto_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- if (FormHOZMainObject.m_MeasureFile == null)
|
|
|
- {
|
|
|
- MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
- }
|
|
|
- else
|
|
|
+ try
|
|
|
{
|
|
|
- if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
|
|
|
+ if (FormHOZMainObject.m_MeasureFile == null)
|
|
|
{
|
|
|
- MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
|
|
|
- //根据切孔文件的一个切孔,自动计算其他切孔位置
|
|
|
-
|
|
|
- //文件路径
|
|
|
- string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
|
|
|
- FormHOZMainObject.CreateCutHoleList(ListCutHole);
|
|
|
- //显示导入的切孔数量
|
|
|
- lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
|
|
|
- tbCutHoleFilePath.Text = CutHoleFilePath;
|
|
|
- //保存测量文件
|
|
|
- if (FormHOZMainObject.IsSave)
|
|
|
+ if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
|
|
|
{
|
|
|
- FormHOZMainObject.m_MeasureFile.Save();
|
|
|
+ MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
|
|
|
+ if (ListCutHole != null)
|
|
|
+ {
|
|
|
+ if (ListCutHole.Count > 0)
|
|
|
+ {
|
|
|
+ //根据切孔文件的一个切孔,自动计算其他切孔位置
|
|
|
+ float centerX = 65;
|
|
|
+ float centerY = 65;
|
|
|
+ float firstX = ListCutHole[0].Position.X;
|
|
|
+ float firstY = ListCutHole[0].Position.Y;
|
|
|
+ //距离
|
|
|
+ float distance = 30;
|
|
|
+ //矩阵 4*4
|
|
|
+ int rag = 4;
|
|
|
+ List<PointF> cutHolePoint = new List<PointF>();
|
|
|
+ //根据一个切孔点计算其他切孔信息
|
|
|
+ cutHolePoint = AnalysisPosition(centerX, centerY, firstX, firstY, distance, rag);
|
|
|
+ if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromAnalysisPosition(cutHolePoint))
|
|
|
+ {
|
|
|
+ MessageBox.Show("生成切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //文件路径
|
|
|
+ string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
|
|
|
+ //重新获取切孔列表信息
|
|
|
+ ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
|
|
|
+ //创建切孔列表信息
|
|
|
+ FormHOZMainObject.CreateCutHoleList(ListCutHole);
|
|
|
+ //显示导入的切孔数量
|
|
|
+ lblCutHoleCount.Text = string.Format("成功生成{0}个切孔", ListCutHole.Count);
|
|
|
+ tbCutHoleFilePath.Text = CutHoleFilePath;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //保存测量文件
|
|
|
+ if (FormHOZMainObject.IsSave)
|
|
|
+ {
|
|
|
+ FormHOZMainObject.m_MeasureFile.Save();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogManager.LogError(ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 将分析点坐标,添加到切孔列表中
|
|
|
+ /// </summary>
|
|
|
+ public void AddCutHole()
|
|
|
+ {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 根据一个切孔点计算其他切孔信息
|
|
|
+ /// 分析点坐标
|
|
|
/// </summary>
|
|
|
- /// <param name="centerX"></param>
|
|
|
- /// <param name="centerY"></param>
|
|
|
- /// <param name="firstX"></param>
|
|
|
- /// <param name="firstY"></param>
|
|
|
- /// <param name="distance"></param>
|
|
|
- /// <param name="rag"></param>
|
|
|
- /// <param name="ptsx"></param>
|
|
|
- /// <param name="ptsy"></param>
|
|
|
- public void AnalysisPosition(Double centerX, Double centerY, Double firstX, Double firstY, Double distance, int rag, ref List<Double> ptsx, ref List<Double> ptsy)
|
|
|
+ /// <param name="centerX">中心点X轴坐标</param>
|
|
|
+ /// <param name="centerY">中心点Y轴坐标</param>
|
|
|
+ /// <param name="firstX">第一个点X轴坐标</param>
|
|
|
+ /// <param name="firstY">第一个点Y轴坐标</param>
|
|
|
+ /// <param name="distance">点与点的距离</param>
|
|
|
+ /// <param name="rag">行、列数</param>
|
|
|
+ /// <param name="ptsx">计算生成所有X轴坐标</param>
|
|
|
+ /// <param name="ptsy">计算生成所有Y轴坐标</param>
|
|
|
+ public List<PointF> AnalysisPosition(float centerX, float centerY, float firstX, float firstY, float distance, int rag)
|
|
|
{
|
|
|
//求样品1的水平角度
|
|
|
double angle = 0;
|
|
|
|
|
|
//清空所有点信息
|
|
|
- ptsx.Clear();
|
|
|
- ptsy.Clear();
|
|
|
+ List<float> ptsx = new List<float>();
|
|
|
+ List<float> ptsy = new List<float>();
|
|
|
//将第一个点加入到点信息中
|
|
|
ptsx.Add(firstX);
|
|
|
ptsy.Add(firstY);
|
|
@@ -156,27 +204,37 @@ namespace HOZProject
|
|
|
angle = 45 - angle;
|
|
|
angle = angle * Math.PI / 180;
|
|
|
|
|
|
- double tx = 0;
|
|
|
- double ty = 0;
|
|
|
+ float tx = 0;
|
|
|
+ float ty = 0;
|
|
|
for (int j = 0; j < rag; j++)
|
|
|
{
|
|
|
//计算每行第一个点的坐标
|
|
|
if (j > 0)
|
|
|
{
|
|
|
- tx = distance * j * Math.Sin(angle);
|
|
|
- ty = distance * j * Math.Cos(angle);
|
|
|
+ tx = (float)(distance * j * Math.Sin(angle));
|
|
|
+ ty = (float)(distance * j * Math.Cos(angle));
|
|
|
ptsx.Add(tx + ptsx[0]);
|
|
|
ptsy.Add(ptsy[0] - ty);
|
|
|
}
|
|
|
//计算每行其他点的坐标
|
|
|
for (int i = 1; i < rag; i++)
|
|
|
{
|
|
|
- tx = distance * i * Math.Cos(angle);
|
|
|
- ty = distance * i * Math.Sin(angle);
|
|
|
+ tx = (float)(distance * i * Math.Cos(angle));
|
|
|
+ ty = (float)(distance * i * Math.Sin(angle));
|
|
|
ptsx.Add(tx + ptsx[j * rag]);
|
|
|
ptsy.Add(ty + ptsy[j * rag]);
|
|
|
}
|
|
|
}
|
|
|
+ List<PointF> pts = new List<PointF>();
|
|
|
+ for (int i = 0; i < ptsx.Count; i++)
|
|
|
+ {
|
|
|
+ //增加的点
|
|
|
+ PointF pf = new PointF();
|
|
|
+ pf.X = ptsx[i];
|
|
|
+ pf.Y = ptsy[i];
|
|
|
+ pts.Add(pf);
|
|
|
+ }
|
|
|
+ return pts;
|
|
|
}
|
|
|
#endregion
|
|
|
|