using OpenCvSharp;
using PaintDotNet.Base.CommTool;
using PaintDotNet.Base.SettingModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Windows.Forms;
using Point = System.Drawing.Point;
namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass
{
class GrainSizeGuideClass
{
///
/// 0,GBT6394; 1,GBT4335; 2,GBT24177; 3,E112; 4,ISO643;5,YST347(XX)
///
private int gbtType;
///
/// 需要根据当前操作图片备份和读取的辅助线数据
///
public GrainSizeGuideModel guideModel = new GrainSizeGuideModel();
///
/// 根据图片保存辅助线参数
///
public Dictionary guideDict = new Dictionary();
public PointF m_StartPoint = Point.Empty;
public bool m_canMove;
///
/// 1上 2下 3左 4右
///
private int m_MoveDirection = 0;
private bool m0_canMove;
///
/// 构造辅助线的工作结构
///
public void createGuideClassModelsNamed(string modelName)
{
GrainSizeGuideStyleModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\" + modelName, FileMode.Open));
}
///
/// 构造辅助线的工作结构
///
public void createGuideAreaClassModelsNamed(string modelName)
{
GrainSizeGuideAreaMethodModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\" + modelName, FileMode.Open));
}
public GrainSizeGuideAreaMethodModel GrainSizeGuideAreaMethodModel { get; private set; }
public GrainSizeGuideStyleModel GrainSizeGuideStyleModel { get; private set; }
public void updateRectangleSize(double physical_Micron = 1.0)
{
this.guideModel.rectangleFLineWidth = (float)(this.guideModel.rectangleFLine.Width * physical_Micron);
this.guideModel.rectangleFLineHeight = (float)(this.guideModel.rectangleFLine.Height * physical_Micron);
}
///
/// 面积法-圆的直径
///
public int GetMat_lineDiameter(double physical_Micron)
{
return Math.Max(1, (int)(guideModel.lineDiameter / physical_Micron));
}
///
/// 辅助线长度
///
public double LineLength
{
get
{
return guideModel.lineLength;
}
}
///
/// 辅助线数量
///
public int LineDec
{
get
{
return guideModel.lineDec;
}
}
///
/// 鼠标按下
///
/// 换算后的点
///
public void OnMouseDown(PointF point1, object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && e.Clicks == 1)
{
RectangleF rectangleLeft = new RectangleF(this.guideModel.rectangleFLine.X - 5, this.guideModel.rectangleFLine.Y, 10, this.guideModel.rectangleFLine.Height);
RectangleF rectangleRight = new RectangleF(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width - 5, this.guideModel.rectangleFLine.Y, 10, this.guideModel.rectangleFLine.Height);
RectangleF rectangleTop = new RectangleF(this.guideModel.rectangleFLine.X, this.guideModel.rectangleFLine.Y - 5, this.guideModel.rectangleFLine.Width, 10);
RectangleF rectangleBottom = new RectangleF(this.guideModel.rectangleFLine.X, this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height - 5, this.guideModel.rectangleFLine.Width, 10);
if (rectangleLeft.Contains(point1))
{
((SystemLayer.ScrollPanel)sender).Cursor = Cursors.SizeWE;
m0_canMove = true;
m_MoveDirection = 3;
}
else if (rectangleRight.Contains(point1))
{
((SystemLayer.ScrollPanel)sender).Cursor = Cursors.SizeWE;
m0_canMove = true;
m_MoveDirection = 4;
}
else if (rectangleTop.Contains(point1))
{
((SystemLayer.ScrollPanel)sender).Cursor = Cursors.SizeNS;
m0_canMove = true;
m_MoveDirection = 1;
}
else if (rectangleBottom.Contains(point1))
{
((SystemLayer.ScrollPanel)sender).Cursor = Cursors.SizeNS;
m0_canMove = true;
m_MoveDirection = 2;
}
else
((SystemLayer.ScrollPanel)sender).Cursor = Cursors.Default;
}
}
///
/// 面积法的鼠标移动
///
/// 换算后的点
///
public bool onMouseAreaMove(PointF point1, object SelectedItem, MouseEventArgs e, int surfaceWidth, int surfaceHeight, double physical_Micron = 1.0)
{
if (e.Button == MouseButtons.Left && m0_canMove)
{
// 缩放
this.ScaleGuideAreaStyle(m_MoveDirection, SelectedItem, point1, surfaceWidth, surfaceHeight, physical_Micron);
return true;
}
return false;
}
///
/// 缩放辅助线及其样式
///
/// 1上 2下 3左 4右
///
///
///
private void ScaleGuideAreaStyle(int m_MoveDirection, object SelectedItem/*, PointF startPoint*/, PointF endPoint, int surfaceWidth, int surfaceHeight, double physical_Micron = 1.0)
{
double multiple = 1;
switch (m_MoveDirection)
{
case 1:
multiple = (this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height - endPoint.Y) / guideModel.originHeight;// (this.rectangleFLine.Y + this.rectangleFLine.Height - startPoint.Y);
break;
case 2:
multiple = (endPoint.Y - this.guideModel.rectangleFLine.Y) / guideModel.originHeight;// (startPoint.Y - this.rectangleFLine.Y);
break;
case 3:
multiple = (this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width - endPoint.X) / guideModel.originWidth;// (this.rectangleFLine.X + this.rectangleFLine.Width - startPoint.X);
break;
case 4:
multiple = (endPoint.X - this.guideModel.rectangleFLine.X) / guideModel.originWidth;// (startPoint.X - this.rectangleFLine.X);
break;
default:
break;
}
//向上移动或向左侧移动
if (m_MoveDirection == 1 || m_MoveDirection == 3)
{
if (this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width - (int)(guideModel.originWidth * multiple) < 0)
{
multiple = (this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width) / guideModel.originWidth;
}
if (this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height - (int)(guideModel.originHeight * multiple) < 0)
{
multiple = (this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height) / guideModel.originHeight;
}
}
else
{
if (this.guideModel.rectangleFLine.X + (int)(guideModel.originWidth * multiple) > surfaceWidth)
{
multiple = (surfaceWidth - this.guideModel.rectangleFLine.X) / guideModel.originWidth;
}
if (this.guideModel.rectangleFLine.Y + (int)(guideModel.originHeight * multiple) > surfaceHeight)
{
multiple = (surfaceHeight - this.guideModel.rectangleFLine.Y) / guideModel.originHeight;
}
}
//避免操作异常
if (guideModel.originWidth * multiple < 10 || guideModel.originHeight * multiple < 10)
return;
switch (m_MoveDirection)
{
case 1:
this.guideModel.rectangleFLine = new RectangleF(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width - (int)(guideModel.originWidth * multiple), this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height - (int)(guideModel.originHeight * multiple), (int)(guideModel.originWidth * multiple), (int)(guideModel.originHeight * multiple));
break;
case 2:
this.guideModel.rectangleFLine = new RectangleF(this.guideModel.rectangleFLine.X, this.guideModel.rectangleFLine.Y, (int)(guideModel.originWidth * multiple), (int)(guideModel.originHeight * multiple));
break;
case 3:
this.guideModel.rectangleFLine = new RectangleF(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width - (int)(guideModel.originWidth * multiple), this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height - (int)(guideModel.originHeight * multiple), (int)(guideModel.originWidth * multiple), (int)(guideModel.originHeight * multiple));
break;
case 4:
this.guideModel.rectangleFLine = new RectangleF(this.guideModel.rectangleFLine.X, this.guideModel.rectangleFLine.Y, (int)(guideModel.originWidth * multiple), (int)(guideModel.originHeight * multiple));
break;
default:
break;
}
this.updateRectangleSize(physical_Micron);
// 圆形
if (GrainSizeGuideAreaMethodModel.circularGuideStyles != null)
{
foreach (var circularGuideStyle in GrainSizeGuideAreaMethodModel.circularGuideStyles)
{
if (SelectedItem.Equals(circularGuideStyle.tag))
{
this.guideModel.lineDiameter = multiple * this.guideModel.originLineDiameter;
}
}
}
// 矩形
if (GrainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
{
foreach (var rectangleGuideStyle in GrainSizeGuideAreaMethodModel.rectangleGuideStyles)
{
if (SelectedItem.Equals(rectangleGuideStyle.tag))
{
this.guideModel.lineRectangleWidth = multiple * this.guideModel.originLineRectangleWidth;
this.guideModel.lineRectangleHeight = multiple * this.guideModel.originLineRectangleHeight;
}
}
}
}
///
/// 移动
///
/// 换算后的点
///
public bool onMouseMove(PointF point1, object SelectedItem, MouseEventArgs e, int surfaceWidth, int surfaceHeight, double physical_Micron = 1.0)
{
if (e.Button == MouseButtons.Left && m0_canMove)
{
// 缩放
this.ScaleGuideStyle(m_MoveDirection, SelectedItem, point1, surfaceWidth, surfaceHeight, physical_Micron);
return true;
}
return false;
}
///
/// 鼠标抬起
///
///
///
public void onMouseUp(object sender, MouseEventArgs e)
{
m0_canMove = false;
((SystemLayer.ScrollPanel)sender).Cursor = Cursors.Default;
}
///
/// 更新辅助线及其样式
///
public void UpdateScaleGuideAreaStyle(object SelectedItem, GrainSizeGuideModel guideModel, double multiple = 1.0)
{
if (GrainSizeGuideAreaMethodModel == null)
return;
// 圆形
if (GrainSizeGuideAreaMethodModel.circularGuideStyles != null)
{
foreach (var circularGuideStyle in GrainSizeGuideAreaMethodModel.circularGuideStyles)
{
if (SelectedItem.Equals(circularGuideStyle.tag))
{
guideModel.lineDiameter = multiple * guideModel.lineDiameter;
}
}
}
// 矩形
if (GrainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
{
foreach (var rectangleGuideStyle in GrainSizeGuideAreaMethodModel.rectangleGuideStyles)
{
if (SelectedItem.Equals(rectangleGuideStyle.tag))
{
guideModel.lineRectangleWidth = multiple * guideModel.lineRectangleWidth;
guideModel.lineRectangleHeight = multiple * guideModel.lineRectangleHeight;
}
}
}
}
///
/// 缩放辅助线及其样式更新数据
///
///
public void UpdateScaleGuideStyle(object SelectedItem, GrainSizeGuideModel guideModel, float recWidth, float recHeight, double physical_Micron = 1.0, double multiple = 1.0)
{
if (GrainSizeGuideStyleModel == null)
{
return;
}
// 垂直辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.vGuideStyles != null)
foreach (var vGuideStyle in GrainSizeGuideStyleModel.vGuideStyles)
if (SelectedItem.Equals(vGuideStyle.tag))
guideModel.updateWithGuideModel1(multiple, physical_Micron, recWidth);
// 水平辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.hGuideStyles != null)
foreach (var hGuideStyle in GrainSizeGuideStyleModel.hGuideStyles)
if (SelectedItem.Equals(hGuideStyle.tag))
guideModel.updateWithGuideModel2(multiple, physical_Micron, recHeight);
// 单圆辅助线
if (this.gbtType != 1 && GrainSizeGuideStyleModel.cGuideStyles != null)
foreach (var cGuideStyle in GrainSizeGuideStyleModel.cGuideStyles)
if (SelectedItem.Equals(cGuideStyle.tag))
guideModel.updateWithGuideModel3(multiple, physical_Micron);
// 三圆辅助线
if (GrainSizeGuideStyleModel.tCGuideStyles != null)
foreach (var tCGuideStyle in GrainSizeGuideStyleModel.tCGuideStyles)
if (SelectedItem.Equals(tCGuideStyle.tag))
guideModel.updateWithGuideModel4(multiple, physical_Micron);
// 复合辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.rGuideStyles != null)
foreach (var rGuideStyle in GrainSizeGuideStyleModel.rGuideStyles)
if (SelectedItem.Equals(rGuideStyle.tag))
guideModel.updateWithGuideModel5(multiple, physical_Micron);
}
///
/// 缩放辅助线及其样式
///
/// 1上 2下 3左 4右
///
///
private void ScaleGuideStyle(int m_MoveDirection, object SelectedItem, PointF endPoint, int surfaceWidth, int surfaceHeight, double physical_Micron = 1.0)
{
double multiple = 1;
switch (m_MoveDirection)
{
case 1:
multiple = (this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height - endPoint.Y) / guideModel.originHeight;// (this.rectangleFLine.Y + this.rectangleFLine.Height - startPoint.Y);
break;
case 2:
multiple = (endPoint.Y - this.guideModel.rectangleFLine.Y) / guideModel.originHeight;
break;
case 3:
multiple = (this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width - endPoint.X) / guideModel.originWidth;// (this.rectangleFLine.X + this.rectangleFLine.Width - startPoint.X);
break;
case 4:
multiple = (endPoint.X - this.guideModel.rectangleFLine.X) / guideModel.originWidth;
break;
default:
break;
}
//避免操作异常
if (guideModel.originWidth * multiple < 10 || guideModel.originHeight * multiple < 10)
return;
//向上移动或向左侧移动
if (m_MoveDirection == 1 || m_MoveDirection == 3)
{
if (this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width - (int)(guideModel.originWidth * multiple) < 0)
{
multiple = (this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width) / guideModel.originWidth;
}
if (this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height - (int)(guideModel.originHeight * multiple) < 0)
{
multiple = (this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height) / guideModel.originHeight;
}
}
else
{
if (this.guideModel.rectangleFLine.X + (int)(guideModel.originWidth * multiple) > surfaceWidth)
{
multiple = (surfaceWidth - this.guideModel.rectangleFLine.X) / guideModel.originWidth;
}
if (this.guideModel.rectangleFLine.Y + (int)(guideModel.originHeight * multiple) > surfaceHeight)
{
multiple = (surfaceHeight - this.guideModel.rectangleFLine.Y) / guideModel.originHeight;
}
}
switch (m_MoveDirection)
{
case 1://向上移动
{
this.guideModel.rectangleFLine = new RectangleF(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width - (int)(guideModel.originWidth * multiple), this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height - (int)(guideModel.originHeight * multiple), (int)(guideModel.originWidth * multiple), (int)(guideModel.originHeight * multiple));
}
break;
case 2:
{
this.guideModel.rectangleFLine = new RectangleF(this.guideModel.rectangleFLine.X, this.guideModel.rectangleFLine.Y, (int)(guideModel.originWidth * multiple), (int)(guideModel.originHeight * multiple));
}
break;
case 3://向左侧移动
{
this.guideModel.rectangleFLine = new RectangleF(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width - (int)(guideModel.originWidth * multiple), this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height - (int)(guideModel.originHeight * multiple), (int)(guideModel.originWidth * multiple), (int)(guideModel.originHeight * multiple));
}
break;
case 4:
{
this.guideModel.rectangleFLine = new RectangleF(this.guideModel.rectangleFLine.X, this.guideModel.rectangleFLine.Y, (int)(guideModel.originWidth * multiple), (int)(guideModel.originHeight * multiple));
}
break;
default:
break;
}
this.updateRectangleSize(physical_Micron);
// 垂直辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.vGuideStyles != null)
{
foreach (var vGuideStyle in GrainSizeGuideStyleModel.vGuideStyles)
{
if (SelectedItem.Equals(vGuideStyle.tag))
{
this.guideModel.updateWithGuideModel1(multiple, physical_Micron, -1);//###
}
}
}
// 水平辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.hGuideStyles != null)
{
foreach (var hGuideStyle in GrainSizeGuideStyleModel.hGuideStyles)
{
if (SelectedItem.Equals(hGuideStyle.tag))
{
this.guideModel.updateWithGuideModel2(multiple, physical_Micron, -1);//###
}
}
}
// 单圆辅助线
if (this.gbtType != 1 && GrainSizeGuideStyleModel.cGuideStyles != null)
{
foreach (var cGuideStyle in GrainSizeGuideStyleModel.cGuideStyles)
{
if (SelectedItem.Equals(cGuideStyle.tag))
{
this.guideModel.updateWithGuideModel3(multiple, physical_Micron, true);//###
}
}
}
// 三圆辅助线
if (GrainSizeGuideStyleModel.tCGuideStyles != null)
{
foreach (var tCGuideStyle in GrainSizeGuideStyleModel.tCGuideStyles)
{
if (SelectedItem.Equals(tCGuideStyle.tag))
{
this.guideModel.updateWithGuideModel4(multiple, physical_Micron, true);//###
}
}
}
// 复合辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.rGuideStyles != null)
{
foreach (var rGuideStyle in GrainSizeGuideStyleModel.rGuideStyles)
{
if (SelectedItem.Equals(rGuideStyle.tag))
{
this.guideModel.updateWithGuideModel5(multiple, physical_Micron, true);//###
}
}
}
}
///
/// 面积法绘制辅助线
///
///
///
public void DrawAreaGuide(Graphics graphics, object SelectedItem, GrainSizeGuideModel cal_CuideModel)
{
if (SelectedItem == null)
return;
// 以下为绘制样式
Pen linePen = new Pen(Color.FromArgb(cal_CuideModel.lineColor), cal_CuideModel.lineWidth);
// 圆形
if (GrainSizeGuideAreaMethodModel.circularGuideStyles != null)
{
foreach (var circularGuideStyle in GrainSizeGuideAreaMethodModel.circularGuideStyles)
{
if (SelectedItem.Equals(circularGuideStyle.tag))
{
graphics.DrawEllipse(linePen, cal_CuideModel.rectangleFLine.X, cal_CuideModel.rectangleFLine.Y, cal_CuideModel.rectangleFLine.Width, cal_CuideModel.rectangleFLine.Height);
}
}
}
// 矩形
if (GrainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
{
foreach (var rectangleGuideStyle in GrainSizeGuideAreaMethodModel.rectangleGuideStyles)
{
if (SelectedItem.Equals(rectangleGuideStyle.tag))
{
graphics.DrawRectangle(linePen, cal_CuideModel.rectangleFLine.X, cal_CuideModel.rectangleFLine.Y, cal_CuideModel.rectangleFLine.Width, cal_CuideModel.rectangleFLine.Height);
}
}
}
}
///
/// 绘制辅助线
///
public void DrawGuideLines(Graphics graphics, object SelectedItem, GrainSizeGuideModel cal_CuideModel)
{
if (SelectedItem == null)
return;
// 垂直辅助线
if (GrainSizeGuideStyleModel.vGuideStyles != null)
foreach (var vGuideStyle in GrainSizeGuideStyleModel.vGuideStyles)
if (SelectedItem.Equals(vGuideStyle.tag))
cal_CuideModel.DrawGuideLines1(graphics);
// 水平辅助线
if (GrainSizeGuideStyleModel.hGuideStyles != null)
foreach (var hGuideStyle in GrainSizeGuideStyleModel.hGuideStyles)
if (SelectedItem.Equals(hGuideStyle.tag))
cal_CuideModel.DrawGuideLines2(graphics);
// 单圆辅助线
if (GrainSizeGuideStyleModel.cGuideStyles != null)
foreach (var cGuideStyle in GrainSizeGuideStyleModel.cGuideStyles)
if (SelectedItem.Equals(cGuideStyle.tag))
cal_CuideModel.DrawGuideLines3(graphics);
// 三圆辅助线
if (GrainSizeGuideStyleModel.tCGuideStyles != null)
foreach (var tCGuideStyle in GrainSizeGuideStyleModel.tCGuideStyles)
if (SelectedItem.Equals(tCGuideStyle.tag))
cal_CuideModel.DrawGuideLines4(graphics);
// 复合辅助线
if (GrainSizeGuideStyleModel.rGuideStyles != null)
foreach (var rGuideStyle in GrainSizeGuideStyleModel.rGuideStyles)
if (SelectedItem.Equals(rGuideStyle.tag))
cal_CuideModel.DrawGuideLines5(graphics);
}
///
/// 获取辅助线的外框矩形
///
///
///
public RectangleF guideAreaRectLine(object SelectedItem, out bool foundItem, bool guideTypeChanged = true, double physical_Micron = 1.0)
{
PointF pointF = this.guideModel.loctation;
foundItem = false;
RectangleF rectFLine = new RectangleF();
double pppppp = physical_Micron * 1.0;
// 圆形
if (GrainSizeGuideAreaMethodModel.circularGuideStyles != null)
{
foreach (var circularGuideStyle in GrainSizeGuideAreaMethodModel.circularGuideStyles)
{
if (SelectedItem.Equals(circularGuideStyle.tag))
{
rectFLine = new RectangleF(pointF.X - (float)(this.guideModel.lineDiameter / (2.0 * pppppp))
, pointF.Y - (float)(this.guideModel.lineDiameter / (2.0 * pppppp)), (float)(this.guideModel.lineDiameter / pppppp), (float)(this.guideModel.lineDiameter / pppppp));
foundItem = true;
if (guideTypeChanged)
{
this.guideModel.originWidth = (float)(Math.Max(1, guideModel.originLineDiameter / pppppp));
this.guideModel.originHeight = (float)(Math.Max(1, guideModel.originLineDiameter / pppppp));
}
}
}
}
// 矩形
if (GrainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
{
foreach (var rectangleGuideStyle in GrainSizeGuideAreaMethodModel.rectangleGuideStyles)
{
if (SelectedItem.Equals(rectangleGuideStyle.tag))
{
rectFLine = new RectangleF(pointF.X - (float)(this.guideModel.lineRectangleWidth / (2.0 * pppppp))
, pointF.Y - (float)(this.guideModel.lineRectangleHeight / (2.0 * pppppp)), (float)(this.guideModel.lineRectangleWidth / pppppp), (float)(this.guideModel.lineRectangleHeight / pppppp));
foundItem = true;
if (guideTypeChanged)
{
this.guideModel.originWidth = (float)(Math.Max(1, guideModel.originLineRectangleWidth / pppppp));
this.guideModel.originHeight = (float)(Math.Max(1, guideModel.originLineRectangleHeight / pppppp));
}
}
}
}
//if (guideTypeChanged)
//{
// this.originWidth = Math.Max(1, rectFLine.Width);
// this.originHeight = Math.Max(1, rectFLine.Height);
//}
this.guideModel.rectangleFLine = rectFLine;
this.updateRectangleSize(physical_Micron);
return rectFLine;
}
///
/// 更新辅助线的外框矩形宽高数值(获取辅助线的外框矩形)
///
///
///
public RectangleF updateGuideAreaRectLine(object SelectedItem, GrainSizeGuideModel guideModel, out bool foundItem, bool guideTypeChanged = true, double physical_Micron = 1.0)
{
foundItem = false;
RectangleF rectFLine = new RectangleF();
double pppppp = physical_Micron * 1.0;
// 圆形
if (GrainSizeGuideAreaMethodModel.circularGuideStyles != null)
{
foreach (var circularGuideStyle in GrainSizeGuideAreaMethodModel.circularGuideStyles)
{
if (SelectedItem.Equals(circularGuideStyle.tag))
{
//rectFLine = new RectangleF(pointF.X - (float)(this.lineDiameter / (2.0 * pppppp))
// , pointF.Y - (float)(this.lineDiameter / (2.0 * pppppp)), (float)(this.lineDiameter / pppppp), (float)(this.lineDiameter / pppppp));
foundItem = true;
if (guideTypeChanged)
{
guideModel.originWidth = (float)(Math.Max(1, guideModel.originLineDiameter / pppppp));
guideModel.originHeight = (float)(Math.Max(1, guideModel.originLineDiameter / pppppp));
}
}
}
}
// 矩形
if (GrainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
{
foreach (var rectangleGuideStyle in GrainSizeGuideAreaMethodModel.rectangleGuideStyles)
{
if (SelectedItem.Equals(rectangleGuideStyle.tag))
{
//rectFLine = new RectangleF(pointF.X - (float)(this.lineRectangleWidth / (2.0 * pppppp))
// , pointF.Y - (float)(this.lineRectangleHeight / (2.0 * pppppp)), (float)(this.lineRectangleWidth / pppppp), (float)(this.lineRectangleHeight / pppppp));
foundItem = true;
if (guideTypeChanged)
{
guideModel.originWidth = (float)(Math.Max(1, guideModel.originLineRectangleWidth / pppppp));
guideModel.originHeight = (float)(Math.Max(1, guideModel.originLineRectangleHeight / pppppp));
}
}
}
}
return rectFLine;
}
///
/// 更新辅助线的外框矩形宽高数值(获取辅助线的外框矩形)
///
///
///
public RectangleF updateGuideRectLine(object SelectedItem, GrainSizeGuideModel guideModel, out bool foundItem, bool guideTypeChanged = true, double physical_Micron = 1.0)
{
foundItem = false;
RectangleF rectFLine = new RectangleF();
// 垂直辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.vGuideStyles != null)
{
foreach (var vGuideStyle in GrainSizeGuideStyleModel.vGuideStyles)
{
if (SelectedItem.Equals(vGuideStyle.tag))
{
//rectFLine = new RectangleF(pointF.X - (float)(this.mat_lineSpacing * (this.lineDec - 1)) / 2 - (float)this.lineWidth / 2
// , pointF.Y - (float)this.mat_lineLength / 2, this.mat_lineSpacing * (this.lineDec - 1)/* + this.lineWidth*/, this.mat_lineLength);
foundItem = true;
if (guideTypeChanged)
{
guideModel.originWidth = (float)(Math.Max(1, guideModel.originMat_lineSpacing * (guideModel.lineDec - 1)));
guideModel.originHeight = (float)(Math.Max(1, guideModel.originLineLength / physical_Micron));
}
}
}
}
// 水平辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.hGuideStyles != null)
{
foreach (var hGuideStyle in GrainSizeGuideStyleModel.hGuideStyles)
{
if (SelectedItem.Equals(hGuideStyle.tag))
{
//rectFLine = new RectangleF(pointF.X - this.mat_lineLength / 2
// , pointF.Y - (float)(this.mat_lineSpacing * (this.lineDec - 1)) / 2 - (float)this.lineWidth / 2
// , this.mat_lineLength, this.mat_lineSpacing * (this.lineDec - 1)/* + this.lineWidth*/);
foundItem = true;
if (guideTypeChanged)
{
guideModel.originWidth = (float)(Math.Max(1, guideModel.originLineLength / physical_Micron));
guideModel.originHeight = (float)(Math.Max(1, guideModel.originMat_lineSpacing * (guideModel.lineDec - 1)));
}
}
}
}
// 单圆辅助线
if (this.gbtType != 1 && GrainSizeGuideStyleModel.cGuideStyles != null)
{
foreach (var cGuideStyle in GrainSizeGuideStyleModel.cGuideStyles)
{
if (SelectedItem.Equals(cGuideStyle.tag))
{
//rectFLine = new RectangleF(pointF.X - this.mat_diameter / 2
// , pointF.Y - this.mat_diameter / 2, this.mat_diameter, this.mat_diameter);
foundItem = true;
if (guideTypeChanged)
{
guideModel.originWidth = (float)(Math.Max(1, guideModel.originDiameter / physical_Micron));
guideModel.originHeight = (float)(Math.Max(1, guideModel.originDiameter / physical_Micron));
}
}
}
}
// 三圆辅助线
if (GrainSizeGuideStyleModel.tCGuideStyles != null)
{
foreach (var tCGuideStyle in GrainSizeGuideStyleModel.tCGuideStyles)
{
if (SelectedItem.Equals(tCGuideStyle.tag))
{
//rectFLine = new RectangleF(pointF.X - this.mat_diameter / 2 - 2 * this.mat_margin
// , pointF.Y - this.mat_diameter / 2 - 2 * this.mat_margin, this.mat_diameter + 4 * this.mat_margin, this.mat_diameter + 4 * this.mat_margin);
foundItem = true;
if (guideTypeChanged)
{
guideModel.originWidth = (float)(Math.Max(1, (guideModel.originDiameter + 4 * guideModel.originMargin) / physical_Micron));
guideModel.originHeight = (float)(Math.Max(1, (guideModel.originDiameter + 4 * guideModel.originMargin) / physical_Micron));
}
}
}
}
// 复合辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.rGuideStyles != null)
{
foreach (var rGuideStyle in GrainSizeGuideStyleModel.rGuideStyles)
{
if (SelectedItem.Equals(rGuideStyle.tag))
{
// rectFLine = new RectangleF(pointF.X - this.mat_diameter / 2 - this.mat_margin * 2 - this.mat_VLineToCDistance
//, pointF.Y - this.mat_diameter / 2 - this.mat_margin * 2, this.mat_diameter + 4 * this.mat_margin + this.mat_VLineToCDistance, this.mat_diameter + 4 * this.mat_margin + this.mat_HLineToCDistance);
foundItem = true;
if (guideTypeChanged)
{//this.mat_diameter + 4 * this.mat_margin + this.mat_VLineToCDistance
guideModel.originWidth = (float)(Math.Max(1, (guideModel.originDiameter + 4 * guideModel.originMargin + guideModel.originVLineToCDistance) / physical_Micron));
//this.mat_diameter + 4 * this.mat_margin + this.mat_HLineToCDistance
guideModel.originHeight = (float)(Math.Max(1, (guideModel.originDiameter + 4 * guideModel.originMargin + guideModel.originHLineToCDistance) / physical_Micron));
}
}
}
}
return rectFLine;
}
///
/// 获取辅助线的外框矩形
///
///
///
public RectangleF guideRectLine(object SelectedItem, out bool foundItem, bool guideTypeChanged = true, double physical_Micron = 1.0)
{
PointF pointF = this.guideModel.loctation;
foundItem = false;
RectangleF rectFLine = new RectangleF();
// 垂直辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.vGuideStyles != null)
{
foreach (var vGuideStyle in GrainSizeGuideStyleModel.vGuideStyles)
{
if (SelectedItem.Equals(vGuideStyle.tag))
{
rectFLine = new RectangleF(pointF.X - (float)(this.guideModel.mat_lineSpacing * (this.guideModel.lineDec - 1)) / 2 - (float)this.guideModel.lineWidth / 2
, pointF.Y - (float)this.guideModel.mat_lineLength / 2, this.guideModel.mat_lineSpacing * (this.guideModel.lineDec - 1)/* + this.lineWidth*/, this.guideModel.mat_lineLength);
foundItem = true;
if (guideTypeChanged)
{
this.guideModel.originWidth = (float)(Math.Max(1, guideModel.originMat_lineSpacing * (this.guideModel.lineDec - 1)));
this.guideModel.originHeight = (float)(Math.Max(1, guideModel.originLineLength / physical_Micron));
}
}
}
}
// 水平辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.hGuideStyles != null)
{
foreach (var hGuideStyle in GrainSizeGuideStyleModel.hGuideStyles)
{
if (SelectedItem.Equals(hGuideStyle.tag))
{
rectFLine = new RectangleF(pointF.X - this.guideModel.mat_lineLength / 2
, pointF.Y - (float)(this.guideModel.mat_lineSpacing * (this.guideModel.lineDec - 1)) / 2 - (float)this.guideModel.lineWidth / 2
, this.guideModel.mat_lineLength, this.guideModel.mat_lineSpacing * (this.guideModel.lineDec - 1)/* + this.lineWidth*/);
foundItem = true;
if (guideTypeChanged)
{
this.guideModel.originWidth = (float)(Math.Max(1, guideModel.originLineLength / physical_Micron));
this.guideModel.originHeight = (float)(Math.Max(1, guideModel.originMat_lineSpacing * (this.guideModel.lineDec - 1)));
}
}
}
}
// 单圆辅助线
if (this.gbtType != 1 && GrainSizeGuideStyleModel.cGuideStyles != null)
{
foreach (var cGuideStyle in GrainSizeGuideStyleModel.cGuideStyles)
{
if (SelectedItem.Equals(cGuideStyle.tag))
{
rectFLine = new RectangleF(pointF.X - this.guideModel.mat_diameter / 2
, pointF.Y - this.guideModel.mat_diameter / 2, this.guideModel.mat_diameter, this.guideModel.mat_diameter);
foundItem = true;
if (guideTypeChanged)
{
this.guideModel.originWidth = (float)(Math.Max(1, guideModel.originDiameter / physical_Micron));
this.guideModel.originHeight = (float)(Math.Max(1, guideModel.originDiameter / physical_Micron));
}
}
}
}
// 三圆辅助线
if (GrainSizeGuideStyleModel.tCGuideStyles != null)
{
foreach (var tCGuideStyle in GrainSizeGuideStyleModel.tCGuideStyles)
{
if (SelectedItem.Equals(tCGuideStyle.tag))
{
rectFLine = new RectangleF(pointF.X - this.guideModel.mat_diameter / 2 - 2 * this.guideModel.mat_margin
, pointF.Y - this.guideModel.mat_diameter / 2 - 2 * this.guideModel.mat_margin, this.guideModel.mat_diameter + 4 * this.guideModel.mat_margin, this.guideModel.mat_diameter + 4 * this.guideModel.mat_margin);
foundItem = true;
if (guideTypeChanged)
{
this.guideModel.originWidth = (float)(Math.Max(1, (guideModel.originDiameter + 4 * guideModel.originMargin) / physical_Micron));
this.guideModel.originHeight = (float)(Math.Max(1, (guideModel.originDiameter + 4 * guideModel.originMargin) / physical_Micron));
}
}
}
}
// 复合辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.rGuideStyles != null)
{
foreach (var rGuideStyle in GrainSizeGuideStyleModel.rGuideStyles)
{
if (SelectedItem.Equals(rGuideStyle.tag))
{
rectFLine = new RectangleF(pointF.X - this.guideModel.mat_diameter / 2 - this.guideModel.mat_margin * 2 - this.guideModel.mat_VLineToCDistance
, pointF.Y - this.guideModel.mat_diameter / 2 - this.guideModel.mat_margin * 2, this.guideModel.mat_diameter + 4 * this.guideModel.mat_margin + this.guideModel.mat_VLineToCDistance, this.guideModel.mat_diameter + 4 * this.guideModel.mat_margin + this.guideModel.mat_HLineToCDistance);
//List pointFs = new List();
//PointF rPoint = new PointF(rectFLine.X + rectFLine.Width / 2 + this.mat_VLineToCDistance / 2 - this.mat_hLineLength / 2, rectFLine.Bottom);
//pointFs.Add(rPoint);
//rPoint = new PointF(rectFLine.X + rectFLine.Width / 2 + this.mat_VLineToCDistance / 2 + this.mat_hLineLength / 2, rectFLine.Bottom);
//pointFs.Add(rPoint);
//rPoint = new PointF(rectFLine.X, rectFLine.Y + rectFLine.Height / 2 - this.mat_HLineToCDistance / 2 - this.mat_vLineLength / 2);
//pointFs.Add(rPoint);
//rPoint = new PointF(rectFLine.X, rectFLine.Y + rectFLine.Height / 2 - this.mat_HLineToCDistance / 2 + this.mat_vLineLength / 2);
//pointFs.Add(rPoint);
//// 圆心
//Point center = new Point((int)(rectFLine.X + rectFLine.Width / 2 + this.mat_VLineToCDistance / 2), (int)(rectFLine.Y + rectFLine.Height / 2 - this.mat_HLineToCDistance / 2));
//double len = Math.Sqrt(((this.mat_ToprightLineLength / 2) * (this.mat_ToprightLineLength / 2)) / 2);
//// 左下到右上斜线
//Point a = new Point((int)center.X - (int)len, (int)center.Y + (int)len);
//Point b = new Point((int)center.X + (int)len, (int)center.Y - (int)len);
//pointFs.Add(a);
//pointFs.Add(b);
//len = Math.Sqrt(((this.mat_TopleftLineLength / 2) * (this.mat_TopleftLineLength / 2)) / 2);
//// 左上到右下斜线
//a = new Point((int)center.X - (int)len, (int)center.Y - (int)len);
//b = new Point((int)center.X + (int)len, (int)center.Y + (int)len);
//pointFs.Add(a);
//pointFs.Add(b);
//pointFs.Add(rectFLine.Location);
//pointFs.Add(new PointF(rectFLine.Right, rectFLine.Bottom));
//PointF pointF2 = new PointF(0, 0);
//float maxLiftX = 0;
//float maxLiftY = 0;
//float minRightX = 0;
//float minRightY = 0;
//foreach (var pointF1 in pointFs)
//{
// if (pointF1.X > maxLiftX)
// maxLiftX = pointF1.X;
// if (pointF1.Y > maxLiftY)
// maxLiftY = pointF1.Y;
// if (pointF1.X < minRightX)
// minRightX = pointF1.X;
// if (pointF1.Y < minRightY)
// minRightY = pointF1.Y;
//}
//rectFLine/*rectangleF*/ = new RectangleF(minRightX, minRightY, Math.Abs(minRightX - maxLiftX), Math.Abs(minRightY - maxLiftY));
////rectFLine = new RectangleF(pointF.X - this.mat_diameter / 2 - this.mat_margin * 2 - this.mat_VLineToCDistance
//// , pointF.Y - this.mat_diameter / 2 - this.mat_margin * 2, this.mat_diameter + 4 * this.mat_margin + this.mat_VLineToCDistance, this.mat_diameter + 4 * this.mat_margin + this.mat_HLineToCDistance);
foundItem = true;
// rectFLine = new RectangleF(pointF.X - this.mat_diameter / 2 - this.mat_margin * 2 - this.mat_VLineToCDistance
//, pointF.Y - this.mat_diameter / 2 - this.mat_margin * 2, this.mat_diameter + 4 * this.mat_margin + this.mat_VLineToCDistance, this.mat_diameter + 4 * this.mat_margin + this.mat_HLineToCDistance);
if (guideTypeChanged)
{//this.mat_diameter + 4 * this.mat_margin + this.mat_VLineToCDistance
this.guideModel.originWidth = (float)(Math.Max(1, (guideModel.originDiameter + 4 * guideModel.originMargin + this.guideModel.originVLineToCDistance) / physical_Micron));
//this.mat_diameter + 4 * this.mat_margin + this.mat_HLineToCDistance
this.guideModel.originHeight = (float)(Math.Max(1, (guideModel.originDiameter + 4 * guideModel.originMargin + this.guideModel.originHLineToCDistance) / physical_Micron));
}
}
}
}
//if (guideTypeChanged)
//{
// this.originWidth = Math.Max(1, rectFLine.Width);
// this.originHeight = Math.Max(1, rectFLine.Height);
//}
this.guideModel.rectangleFLine = rectFLine;
this.updateRectangleSize(physical_Micron);
return rectFLine;
}
///
/// 复合辅助线的点的数量
///
///
public int getAddOfRStyle(PointF point1, object SelectedItem, out RectangleF rectangleF)
{
rectangleF = new RectangleF();
int add = 0;
// 复合辅助线
if (GrainSizeGuideStyleModel.rGuideStyles != null)
{
foreach (var rGuideStyle in GrainSizeGuideStyleModel.rGuideStyles)
{
if (SelectedItem.Equals(rGuideStyle.tag))
{
add++;
List pointFs = new List();
PointF pointF = new PointF(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width / 2 + this.guideModel.mat_VLineToCDistance / 2 - this.guideModel.mat_hLineLength / 2, this.guideModel.rectangleFLine.Bottom);
pointFs.Add(pointF);
pointF = new PointF(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width / 2 + this.guideModel.mat_VLineToCDistance / 2 + this.guideModel.mat_hLineLength / 2, this.guideModel.rectangleFLine.Bottom);
pointFs.Add(pointF);
pointF = new PointF(this.guideModel.rectangleFLine.X, this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height / 2 - this.guideModel.mat_HLineToCDistance / 2 - this.guideModel.mat_vLineLength / 2);
pointFs.Add(pointF);
pointF = new PointF(this.guideModel.rectangleFLine.X, this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height / 2 - this.guideModel.mat_HLineToCDistance / 2 + this.guideModel.mat_vLineLength / 2);
pointFs.Add(pointF);
// 圆心
Point center = new Point((int)(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width / 2 + this.guideModel.mat_VLineToCDistance / 2), (int)(this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height / 2 - this.guideModel.mat_HLineToCDistance / 2));
double len = Math.Sqrt(((this.guideModel.mat_ToprightLineLength / 2) * (this.guideModel.mat_ToprightLineLength / 2)) / 2);
// 左下到右上斜线
Point a = new Point((int)center.X - (int)len, (int)center.Y + (int)len);
Point b = new Point((int)center.X + (int)len, (int)center.Y - (int)len);
pointFs.Add(a);
pointFs.Add(b);
len = Math.Sqrt(((this.guideModel.mat_TopleftLineLength / 2) * (this.guideModel.mat_TopleftLineLength / 2)) / 2);
// 左上到右下斜线
a = new Point((int)center.X - (int)len, (int)center.Y - (int)len);
b = new Point((int)center.X + (int)len, (int)center.Y + (int)len);
pointFs.Add(a);
pointFs.Add(b);
pointFs.Add(this.guideModel.rectangleFLine.Location);
pointFs.Add(new PointF(this.guideModel.rectangleFLine.Right, this.guideModel.rectangleFLine.Bottom));
PointF pointF2 = new PointF(0, 0);
PointF pointF3 = new PointF();
int big = 0;
float maxLiftX = 0;
float maxLiftY = 0;
float minRightX = 0;
float minRightY = 0;
foreach (var pointF1 in pointFs)
{
if (pointF1.X > maxLiftX)
maxLiftX = pointF1.X;
if (pointF1.Y > maxLiftY)
maxLiftY = pointF1.Y;
if (big == 0)
{
minRightX = pointF1.X;
minRightY = pointF1.Y;
}
else
{
if (point1.X < minRightX)
minRightX = point1.X;//######### Y;
if (point1.Y < minRightY)
minRightY = point1.Y;
}
big++;
}
rectangleF = new RectangleF(minRightX, minRightY, Math.Abs(minRightX - maxLiftX), Math.Abs(minRightY - maxLiftY));
}
}
}
return add;
}
///
/// 图形上所有的点
///
///
///
///
///
/// 1 圆形 2 矩形
///
public List getGuideAreaPointList(int bitmapW, int bitmapH, object SelectedItem, double physical_Micron, out int guideStyle)
{
guideStyle = 2;
List linePointList = new List();
// 圆形
if (GrainSizeGuideAreaMethodModel.circularGuideStyles != null)
{
double pppppp = physical_Micron * 1.0;
foreach (var circularGuideStyle in GrainSizeGuideAreaMethodModel.circularGuideStyles)
{
if (SelectedItem.Equals(circularGuideStyle.tag))
{
guideStyle = 1;
// 圆心
Point center = new Point((int)(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width / 2), (int)(this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height / 2));
for (int i = 0; i <= 360; i++)
{
Point[] points = roundOutline(center, (int)(guideModel.lineDiameter / (2.0 * pppppp)));
foreach (var point in points)
{
linePointList.Add(new Point(point.X, point.Y));
}
}
}
}
}
// 矩形
if (GrainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
{
foreach (var rectangleGuideStyle in GrainSizeGuideAreaMethodModel.rectangleGuideStyles)
{
if (SelectedItem.Equals(rectangleGuideStyle.tag))
{
guideStyle = 2;
for (int l = (int)this.guideModel.rectangleFLine.Y; l <= this.guideModel.rectangleFLine.Bottom; l++)
{
if (this.guideModel.rectangleFLine.X >= 0 && this.guideModel.rectangleFLine.X < bitmapW && l >= 0 && l < bitmapH)
linePointList.Add(new PointF(this.guideModel.rectangleFLine.X, l));
}
for (int t = (int)this.guideModel.rectangleFLine.X; t <= this.guideModel.rectangleFLine.Right; t++)
{
if (t >= 0 && t < bitmapW && this.guideModel.rectangleFLine.Y >= 0 && this.guideModel.rectangleFLine.Y < bitmapH)
linePointList.Add(new PointF(t, this.guideModel.rectangleFLine.Y));
}
for (int r = (int)this.guideModel.rectangleFLine.Y; r <= this.guideModel.rectangleFLine.Bottom; r++)
{
if (this.guideModel.rectangleFLine.Right >= 0 && this.guideModel.rectangleFLine.Right < bitmapW && r >= 0 && r < bitmapH)
linePointList.Add(new PointF(this.guideModel.rectangleFLine.Right, r));
}
for (int t = (int)this.guideModel.rectangleFLine.X; t <= this.guideModel.rectangleFLine.Right; t++)
{
if (t >= 0 && t < bitmapW && this.guideModel.rectangleFLine.Bottom >= 0 && this.guideModel.rectangleFLine.Bottom < bitmapH)
linePointList.Add(new PointF(t, this.guideModel.rectangleFLine.Bottom));
}
}
}
}
return linePointList;
}
///
/// 图形上所有的点,并按照直线或者圆圈类型赋值列表
///
public List getGuidePointListAndClassLine(Mat mat, object SelectedItem, out List> straightLinePointList, out List> roundLinePointList)
{
List linePointList = new List();
straightLinePointList = new List>();///
roundLinePointList = new List>();///
//lineValueList.Clear();//###
List classPointList;
int lengthI = 0;
// 垂直辅助线
if (GrainSizeGuideStyleModel.vGuideStyles != null)
{
foreach (var vGuideStyle in GrainSizeGuideStyleModel.vGuideStyles)
{
if (SelectedItem.Equals(vGuideStyle.tag))
{
if (mat != null)
{
int spacing = 0;
for (int d = 0; d < this.guideModel.lineDec; d++)
{
classPointList = new List();
float rectangleFLineX = this.guideModel.rectangleFLine.X /*+ this.lineWidth / 2*/ + spacing;//1019###19638
spacing += (int)this.guideModel.mat_lineSpacing;
for (int i = (int)this.guideModel.rectangleFLine.Y; i <= this.guideModel.rectangleFLine.Bottom; i++)
{
linePointList.Add(new PointF(rectangleFLineX, i));
classPointList.Add(new PointF(rectangleFLineX, i));
}
straightLinePointList.Add(classPointList);
}
}
}
}
}
// 水平辅助线
if (GrainSizeGuideStyleModel.hGuideStyles != null)
{
foreach (var hGuideStyle in GrainSizeGuideStyleModel.hGuideStyles)
{
if (SelectedItem.Equals(hGuideStyle.tag))
{
if (mat != null)
{
int spacing = 0;
for (int d = 0; d < this.guideModel.lineDec; d++)
{
classPointList = new List();
float rectangleFLineY = this.guideModel.rectangleFLine.Y /*+ this.lineWidth / 2*/ + spacing;
spacing += (int)this.guideModel.mat_lineSpacing;
for (int i = (int)this.guideModel.rectangleFLine.X; i <= this.guideModel.rectangleFLine.Right; i++)
{
linePointList.Add(new PointF(i, rectangleFLineY));
classPointList.Add(new PointF(i, rectangleFLineY));
}
straightLinePointList.Add(classPointList);
}
}
}
}
}
// 单圆辅助线
if (GrainSizeGuideStyleModel.cGuideStyles != null)
{
foreach (var cGuideStyle in GrainSizeGuideStyleModel.cGuideStyles)
{
if (SelectedItem.Equals(cGuideStyle.tag))
{
// 圆心
Point center = new Point((int)(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width / 2), (int)(this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height / 2));
// 圆上的点集合
Point[] points = roundOutline(center, (int)this.guideModel.mat_diameter / 2);//0914###18749
if (mat != null)
{
classPointList = new List();
classPointList.Add(new PointF(center.X, center.Y));
foreach (var point in points)
{
linePointList.Add(new PointF(point.X, point.Y));
classPointList.Add(new PointF(point.X, point.Y));
}
roundLinePointList.Add(classPointList);
}
}
}
}
// 三圆辅助线
if (GrainSizeGuideStyleModel.tCGuideStyles != null)
{
foreach (var tCGuideStyle in GrainSizeGuideStyleModel.tCGuideStyles)
{
if (SelectedItem.Equals(tCGuideStyle.tag))
{
// 圆心
Point center = new Point((int)(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width / 2), (int)(this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height / 2));
// 圆上的点集合
List points = new List();
Point[] points1 = roundOutline(center, (int)this.guideModel.mat_diameter / 2);
Point[] points2 = roundOutline(center, (int)this.guideModel.mat_diameter / 2 + (int)this.guideModel.mat_margin);
Point[] points3 = roundOutline(center, (int)this.guideModel.mat_diameter / 2 + 2 * (int)this.guideModel.mat_margin);
classPointList = new List();
classPointList.Add(new PointF(center.X, center.Y));
foreach (var item in points1)
{
points.Add(new Point(item.X, item.Y));
classPointList.Add(new PointF(item.X, item.Y));
}
roundLinePointList.Add(classPointList);
classPointList = new List();
classPointList.Add(new PointF(center.X, center.Y));
foreach (var item in points2)
{
points.Add(new Point(item.X, item.Y));
classPointList.Add(new PointF(item.X, item.Y));
}
roundLinePointList.Add(classPointList);
classPointList = new List();
classPointList.Add(new PointF(center.X, center.Y));
foreach (var item in points3)
{
points.Add(new Point(item.X, item.Y));
classPointList.Add(new PointF(item.X, item.Y));
}
roundLinePointList.Add(classPointList);
if (mat != null)
{
foreach (var point in points)
{
linePointList.Add(new PointF(point.X, point.Y));
}
}
}
}
}
// 复合辅助线
if (GrainSizeGuideStyleModel.rGuideStyles != null)
{
foreach (var rGuideStyle in GrainSizeGuideStyleModel.rGuideStyles)
{
if (SelectedItem.Equals(rGuideStyle.tag))
{
// 圆上的点集合
List points = new List();
if (mat != null)
{
classPointList = new List();
for (int i = (int)(this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height / 2 - this.guideModel.mat_HLineToCDistance / 2 - this.guideModel.mat_vLineLength / 2); i <= this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height / 2 - this.guideModel.mat_HLineToCDistance / 2 + this.guideModel.mat_vLineLength / 2; i++)
{
points.Add(new Point((int)this.guideModel.rectangleFLine.X, i));
classPointList.Add(new PointF(this.guideModel.rectangleFLine.X, i));
}
straightLinePointList.Add(classPointList);
}
if (mat != null)
{
classPointList = new List();
for (int i = (int)(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width / 2 + this.guideModel.mat_VLineToCDistance / 2 - this.guideModel.mat_hLineLength / 2); i <= this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width / 2 + this.guideModel.mat_VLineToCDistance / 2 + this.guideModel.mat_hLineLength / 2; i++)
{
points.Add(new Point(i, (int)this.guideModel.rectangleFLine.Bottom));
classPointList.Add(new PointF(i, this.guideModel.rectangleFLine.Bottom));
}
straightLinePointList.Add(classPointList);
}
// 圆心
Point center = new Point((int)(this.guideModel.rectangleFLine.X + this.guideModel.rectangleFLine.Width / 2 + this.guideModel.mat_VLineToCDistance / 2), (int)(this.guideModel.rectangleFLine.Y + this.guideModel.rectangleFLine.Height / 2 - this.guideModel.mat_HLineToCDistance / 2));
double len = Math.Sqrt(((this.guideModel.mat_ToprightLineLength / 2) * (this.guideModel.mat_ToprightLineLength / 2)) / 2);
// 左下到右上斜线
Point a = new Point((int)center.X - (int)len, (int)center.Y + (int)len);
Point b = new Point((int)center.X + (int)len, (int)center.Y - (int)len);
if (mat != null)
{
classPointList = new List();
// 循环x坐标
for (int i = a.X + 1; i < b.X; i++)
{
// 计算斜率1653
double k = ((double)(a.Y - b.Y)) / (a.X - b.X);
// 根据斜率,计算y坐标
double y = k * (i - a.X) + a.Y;
// 简单判断一下y是不是整数
double d = y - (int)y;
if (0.001 > d && d > -0.001)
{
points.Add(new Point(i, (int)y));
classPointList.Add(new PointF(i, (float)y));
}
}
straightLinePointList.Add(classPointList);
}
len = Math.Sqrt(((this.guideModel.mat_TopleftLineLength / 2) * (this.guideModel.mat_TopleftLineLength / 2)) / 2);
// 左上到右下斜线
a = new Point((int)center.X - (int)len, (int)center.Y - (int)len);
b = new Point((int)center.X + (int)len, (int)center.Y + (int)len);
if (mat != null)
{
classPointList = new List();
// 循环x坐标
for (int i = a.X + 1; i < b.X; i++)
{
// 计算斜率1653
double k = ((double)(a.Y - b.Y)) / (a.X - b.X);
// 根据斜率,计算y坐标
double y = k * (i - a.X) + a.Y;
// 简单判断一下y是不是整数
double d = y - (int)y;
if (0.001 > d && d > -0.001)
{
points.Add(new Point(i, (int)y));
classPointList.Add(new PointF(i, (float)y));
}
}
straightLinePointList.Add(classPointList);
}
if (mat != null)
{
// 圆上的点集合
Point[] points1 = roundOutline(center, (int)this.guideModel.mat_diameter / 2);
Point[] points2 = roundOutline(center, (int)this.guideModel.mat_diameter / 2 + (int)this.guideModel.mat_margin);
Point[] points3 = roundOutline(center, (int)this.guideModel.mat_diameter / 2 + 2 * (int)this.guideModel.mat_margin);
classPointList = new List();
classPointList.Add(new PointF(center.X, center.Y));
foreach (var item in points1)
{
points.Add(new Point(item.X, item.Y));
classPointList.Add(new PointF(item.X, item.Y));
}
roundLinePointList.Add(classPointList);
classPointList = new List();
classPointList.Add(new PointF(center.X, center.Y));
foreach (var item in points2)
{
points.Add(new Point(item.X, item.Y));
classPointList.Add(new PointF(item.X, item.Y));
}
roundLinePointList.Add(classPointList);
classPointList = new List();
classPointList.Add(new PointF(center.X, center.Y));
foreach (var item in points3)
{
points.Add(new Point(item.X, item.Y));
classPointList.Add(new PointF(item.X, item.Y));
}
roundLinePointList.Add(classPointList);
foreach (var point in points)
{
linePointList.Add(new PointF(point.X, point.Y));
}
}
}
}
}
return linePointList;
}
///
/// 使用圆心及半径得到圆的轮廓
///
/// 圆心
/// 半径
///
public Point[] roundOutline(Point center, int radius)
{
if (radius < 1)
radius = 1;
Mat mat = new Mat((int)(radius * 2.1), (int)(radius * 2.1), MatType.CV_8UC1, new Scalar(0, 0, 0));
OpenCvSharp.Point point = new OpenCvSharp.Point(mat.Cols / 2, mat.Rows / 2);
Cv2.Circle(mat, point, radius, new Scalar(255, 255, 255), -1);
OpenCvSharp.Point[][] contours;
HierarchyIndex[] hierarchy;
Cv2.FindContours(mat, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
if (contours.Length > 0)
{
OpenCvSharp.Point[] roundOutline = contours[0];
Point[] roundOutPoints = new Point[roundOutline.Length];
for (int i = 0; i < roundOutline.Length; i++)
{
roundOutPoints[i].X = roundOutline[i].X - point.X + center.X;
roundOutPoints[i].Y = roundOutline[i].Y - point.Y + center.Y;
}
return roundOutPoints;
}
return new Point[0];
}
///
/// 更新辅助线及其样式
///
public void UpdateGuideAreaStyle(Mat imageMat, object SelectedItem, bool showMessageAlert, double physical_Micron)//#####################
{
if (imageMat == null)//1014###18517
return;
Boolean autosized = false;/* if (matOrg == null)//1014###18517 return; */
double maxSize = Math.Min(imageMat.Width, imageMat.Height);
if (GrainSizeGuideAreaMethodModel == null)
return;
double pppppp = physical_Micron * 1.0;
// 圆形
if (GrainSizeGuideAreaMethodModel.circularGuideStyles != null)
{
foreach (var circularGuideStyle in GrainSizeGuideAreaMethodModel.circularGuideStyles)
{
if (SelectedItem.Equals(circularGuideStyle.tag))
{
double multiple = this.physicalGainMultiple(circularGuideStyle.lineDiameter / pppppp, maxSize);
if (multiple < 1)
autosized = true;
this.guideModel.originLineDiameter = 1/*multiple*/ * circularGuideStyle.lineDiameter;
this.guideModel.lineDiameter = multiple * circularGuideStyle.lineDiameter;
this.guideModel.lineColor = circularGuideStyle.lineColor;
this.guideModel.lineWidth = circularGuideStyle.lineWidth;
}
}
}
// 矩形
if (GrainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
{
foreach (var rectangleGuideStyle in GrainSizeGuideAreaMethodModel.rectangleGuideStyles)
{
if (SelectedItem.Equals(rectangleGuideStyle.tag))
{
double multiple1 = this.physicalGainMultiple(rectangleGuideStyle.lineRectangleWidth / pppppp, imageMat.Width);
double multiple2 = this.physicalGainMultiple(rectangleGuideStyle.lineRectangleHeight / pppppp, imageMat.Height);
double multiple = Math.Min(multiple1, multiple2);
if (multiple < 1)
autosized = true;
this.guideModel.originLineRectangleWidth = 1/*multiple*/ * rectangleGuideStyle.lineRectangleWidth;
this.guideModel.lineRectangleWidth = multiple * rectangleGuideStyle.lineRectangleWidth;
this.guideModel.originLineRectangleHeight = 1/*multiple*/ * rectangleGuideStyle.lineRectangleHeight;
this.guideModel.lineRectangleHeight = multiple * rectangleGuideStyle.lineRectangleHeight;
this.guideModel.lineColor = rectangleGuideStyle.lineColor;
this.guideModel.lineWidth = rectangleGuideStyle.lineWidth;
}
}
}
if (autosized && showMessageAlert)//showMessageBox
MessageBox.Show(PdnResources.GetString("Menu.Thesizeoftheauxiliaryhepicturesize.text"));
}
///
/// 更新辅助线及其样式
///
public void UpdateGuideStyle(Mat matOrg, object SelectedItem, bool showMessageAlert = true, double physical_Micron = 1.0)
{
if (matOrg == null)
return;
Boolean autosized = false;
double maxSize = Math.Min(matOrg.Width, matOrg.Height);
// 垂直辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.vGuideStyles != null)
{
foreach (var vGuideStyle in GrainSizeGuideStyleModel.vGuideStyles)
{
if (SelectedItem.Equals(vGuideStyle.tag))
{
double maxSizeCurrent = vGuideStyle.lineLength;//#21683
double multiple1 = this.physicalGainMultiple(maxSizeCurrent / physical_Micron, matOrg.Height);
maxSizeCurrent = vGuideStyle.lineSpacing * (vGuideStyle.lineDec - 1);
double multiple2 = this.physicalGainMultiple(maxSizeCurrent / physical_Micron, matOrg.Width);
double multiple = Math.Min(multiple1, multiple2);// this.physicalGainMultiple(maxSizeCurrent / physical_Micron, maxSize);
if (multiple < 1)
autosized = true;
this.guideModel.initWithGrainRGuideStyle1(multiple, physical_Micron, vGuideStyle);
}
}
}
// 水平辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.hGuideStyles != null)
{
foreach (var hGuideStyle in GrainSizeGuideStyleModel.hGuideStyles)
{
if (SelectedItem.Equals(hGuideStyle.tag))
{
double maxSizeCurrent = hGuideStyle.lineLength;//#21683
double multiple1 = this.physicalGainMultiple(maxSizeCurrent / physical_Micron, matOrg.Width);
maxSizeCurrent = hGuideStyle.lineSpacing * (hGuideStyle.lineDec - 1);
double multiple2 = this.physicalGainMultiple(maxSizeCurrent / physical_Micron, matOrg.Height);
double multiple = Math.Min(multiple1, multiple2);// this.physicalGainMultiple(maxSizeCurrent / physical_Micron, maxSize);
if (multiple < 1)
autosized = true;
this.guideModel.initWithGrainRGuideStyle2(multiple, physical_Micron, hGuideStyle);
}
}
}
// 单圆辅助线
if (this.gbtType != 1 && GrainSizeGuideStyleModel.cGuideStyles != null)
{
foreach (var cGuideStyle in GrainSizeGuideStyleModel.cGuideStyles)
{
if (SelectedItem.Equals(cGuideStyle.tag))
{
double multiple = this.physicalGainMultiple(cGuideStyle.diameter / physical_Micron, maxSize);
if (multiple < 1)
autosized = true;
this.guideModel.initWithGrainRGuideStyle3(multiple, physical_Micron, cGuideStyle);
}
}
}
// 三圆辅助线
if (GrainSizeGuideStyleModel.tCGuideStyles != null)
{
foreach (var tCGuideStyle in GrainSizeGuideStyleModel.tCGuideStyles)
{
if (SelectedItem.Equals(tCGuideStyle.tag))
{
double multiple = this.physicalGainMultiple((tCGuideStyle.diameter + tCGuideStyle.margin * 4) / physical_Micron, maxSize);
if (multiple < 1)
autosized = true;
this.guideModel.initWithGrainRGuideStyle4(multiple, physical_Micron, tCGuideStyle);
}
}
}
// 复合辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.rGuideStyles != null)
{
foreach (GrainSizeGuideStyleModel.RGuideStyle rGuideStyle in GrainSizeGuideStyleModel.rGuideStyles)
{
if (SelectedItem.Equals(rGuideStyle.tag))
{
double maxSizeCurrent = 0;
if (rGuideStyle.vLineLength / physical_Micron > maxSizeCurrent)
{
maxSizeCurrent = rGuideStyle.vLineLength / physical_Micron;
}
if (rGuideStyle.hLineLength / physical_Micron > maxSizeCurrent)
{
maxSizeCurrent = rGuideStyle.hLineLength / physical_Micron;
}
if ((rGuideStyle.diameter + rGuideStyle.margin * 4 + rGuideStyle.VLineToCDistance) / physical_Micron > maxSizeCurrent)
{
maxSizeCurrent = (rGuideStyle.diameter + rGuideStyle.margin * 4 + rGuideStyle.VLineToCDistance) / physical_Micron;
}
if ((rGuideStyle.diameter + rGuideStyle.margin * 4 + rGuideStyle.HLineToCDistance) / physical_Micron > maxSizeCurrent)
{
maxSizeCurrent = (rGuideStyle.diameter + rGuideStyle.margin * 4 + rGuideStyle.HLineToCDistance) / physical_Micron;
}
if ((rGuideStyle.TopleftLineLength / Math.Sqrt(2.0)) / physical_Micron > maxSizeCurrent)
{
maxSizeCurrent = (rGuideStyle.TopleftLineLength / Math.Sqrt(2.0)) / physical_Micron;
}
if ((rGuideStyle.ToprightLineLength / Math.Sqrt(2.0)) / physical_Micron > maxSizeCurrent)
{
maxSizeCurrent = (rGuideStyle.ToprightLineLength / Math.Sqrt(2.0)) / physical_Micron;
}
double multiple = this.physicalGainMultiple(maxSizeCurrent, maxSize);
if (multiple < 1)
autosized = true;
this.guideModel.initWithGrainRGuideStyle5(multiple, physical_Micron, rGuideStyle);
}
}
}
if (autosized && showMessageAlert)//##19846
MessageBox.Show(PdnResources.GetString("Menu.Thesizeoftheauxiliaryhepicturesize.text"));
}
public ArrayList getComboboxArrayAreaList1()
{
ArrayList arrayList1 = new ArrayList();
List indexList1 = new List();
// 圆形
if (GrainSizeGuideAreaMethodModel.circularGuideStyles != null)
{
foreach (var circularGuideStyle in GrainSizeGuideAreaMethodModel.circularGuideStyles)
{
arrayList1.Add(circularGuideStyle.tag/*" "*/);
indexList1.Add(circularGuideStyle.index);
}
}
// 矩形
if (GrainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
{
foreach (var rectangleGuideStyle in GrainSizeGuideAreaMethodModel.rectangleGuideStyles)
{
arrayList1.Add(rectangleGuideStyle.tag/*" "*/);
indexList1.Add(rectangleGuideStyle.index);
}
}
if (arrayList1.Count > 0)//0916###18839
{
//排序算法//0914###18839
bool sortSuccess = false;
while (!sortSuccess)
{
sortSuccess = true;
int firstIndex = 0;
int secondIndex = 0;
for (int i = 0; i < indexList1.Count; i++)
{
for (int j = i + 1; j < indexList1.Count; j++)
{
if (indexList1[i] > indexList1[j])
{
sortSuccess = false;
firstIndex = i;
secondIndex = j;
}
}
if (!sortSuccess)
break;
}
string firstValue = arrayList1[firstIndex] + "";
arrayList1[firstIndex] = arrayList1[secondIndex] + "";
arrayList1[secondIndex] = firstValue;
int firstIndexV = indexList1[firstIndex] + 0;
indexList1[firstIndex] = indexList1[secondIndex] + 0;
indexList1[secondIndex] = firstIndexV;
}
arrayList1.Insert(0, PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text"));
}
return arrayList1;
}
public ArrayList getComboboxArrayList1()
{
ArrayList arrayList1 = new ArrayList();
List indexList1 = new List();
// 垂直辅助线
if (GrainSizeGuideStyleModel.vGuideStyles != null)
{
foreach (var vGuideStyle in GrainSizeGuideStyleModel.vGuideStyles)
{
arrayList1.Add(vGuideStyle.tag/*""*/);
indexList1.Add(vGuideStyle.index);
}
}
// 水平辅助线
if (GrainSizeGuideStyleModel.hGuideStyles != null)
{
foreach (var hGuideStyle in GrainSizeGuideStyleModel.hGuideStyles)
{
arrayList1.Add(hGuideStyle.tag/*""*/);
indexList1.Add(hGuideStyle.index);
}
}
// 单圆辅助线
if (this.gbtType != 1 && GrainSizeGuideStyleModel.cGuideStyles != null)
{
foreach (var cGuideStyle in GrainSizeGuideStyleModel.cGuideStyles)
{
arrayList1.Add(cGuideStyle.tag);
indexList1.Add(cGuideStyle.index);
}
}
// 三圆辅助线
if (GrainSizeGuideStyleModel.tCGuideStyles != null)
{
foreach (var tCGuideStyle in GrainSizeGuideStyleModel.tCGuideStyles)
{
arrayList1.Add(tCGuideStyle.tag);
indexList1.Add(tCGuideStyle.index);
}
}
// 复合辅助线
if (this.gbtType != 13 && this.gbtType != 1 && GrainSizeGuideStyleModel.rGuideStyles != null)
{
foreach (var rGuideStyle in GrainSizeGuideStyleModel.rGuideStyles)
{
arrayList1.Add(rGuideStyle.tag);//.Add();
indexList1.Add(rGuideStyle.index);
}
}
if (arrayList1.Count > 0)
{
//###//排序算法//0914###18839
bool sortSuccess = false;
while (!sortSuccess)
{
sortSuccess = true;
int firstIndex = 0;
int secondIndex = 0;
for (int i = 0; i < indexList1.Count; i++)
{
for (int j = i + 1; j < indexList1.Count; j++)
{
if (indexList1[i] > indexList1[j])
{
sortSuccess = false;
firstIndex = i;
secondIndex = j;
}
}
if (!sortSuccess)
break;
}
string firstValue = arrayList1[firstIndex] + "";
arrayList1[firstIndex] = arrayList1[secondIndex] + "";
arrayList1[secondIndex] = firstValue;
int firstIndexV = indexList1[firstIndex] + 0;
indexList1[firstIndex] = indexList1[secondIndex] + 0;
indexList1[secondIndex] = firstIndexV;
}
arrayList1.Insert(0, PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text"));
}
return arrayList1;
}
///
/// 获取辅助线缩放比例
///
/// 设置的数值
/// 限制最大值
///
private double physicalGainMultiple(double gridSize, double maxSize)
{
double multiple = 1.0;
if (gridSize > maxSize)
{
multiple = maxSize / gridSize;
}
return multiple;
}
///
/// 获取辅助线的面积
///
///
public double guideArea(GrainSizeGuideModel cal_GuideModel, object SelectedItem, out int isRect, int gbtType)
{
// 矩形
isRect = 0;
double aec = 0;
// 圆形
if (GrainSizeGuideAreaMethodModel.circularGuideStyles != null)
{
foreach (var circularGuideStyle in GrainSizeGuideAreaMethodModel.circularGuideStyles)
{
if (SelectedItem.Equals(circularGuideStyle.tag))
{
aec = cal_GuideModel.lineDiameter / 2.0 * cal_GuideModel.lineDiameter / 2.0 * Math.PI;
}
}
}
if (GrainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
{
foreach (var rectangleGuideStyle in GrainSizeGuideAreaMethodModel.rectangleGuideStyles)
{
if (SelectedItem.Equals(rectangleGuideStyle.tag))
{
aec = cal_GuideModel.lineRectangleWidth * cal_GuideModel.lineRectangleHeight;
if (gbtType == 4)
isRect = 1;// -1;//英文版是+1,中文版可能是翻译问题被改成-1了。。
else if (gbtType == 3)
isRect = 1;
}
}
}
return aec;
}
///
/// 获取辅助线的物理长度
///
///
public double guideLength(GrainSizeGuideModel guideMod)
{
double length = 0;
// 垂直辅助线
if (GrainSizeGuideStyleModel.vGuideStyles != null)
foreach (var vGuideStyle in GrainSizeGuideStyleModel.vGuideStyles)
if (guideMod.oldSelectItem.Equals(vGuideStyle.tag))
length = guideMod.lineLength * guideMod.lineDec;
// 水平辅助线
if (GrainSizeGuideStyleModel.hGuideStyles != null)
foreach (var hGuideStyle in GrainSizeGuideStyleModel.hGuideStyles)
if (guideMod.oldSelectItem.Equals(hGuideStyle.tag))
length = guideMod.lineLength * guideMod.lineDec;
// 单圆辅助线
if (GrainSizeGuideStyleModel.cGuideStyles != null)
foreach (var cGuideStyle in GrainSizeGuideStyleModel.cGuideStyles)
if (guideMod.oldSelectItem.Equals(cGuideStyle.tag))
{
length = guideMod.diameter * Math.PI;
if (length == 0)
guideMod.diameter = 0;
}
// 三圆辅助线
if (GrainSizeGuideStyleModel.tCGuideStyles != null)
foreach (var tCGuideStyle in GrainSizeGuideStyleModel.tCGuideStyles)
if (guideMod.oldSelectItem.Equals(tCGuideStyle.tag))
length = guideMod.diameter * Math.PI + (guideMod.diameter + 2 * guideMod.margin) * Math.PI + (guideMod.diameter + 4 * guideMod.margin) * Math.PI;
// 复合辅助线
if (GrainSizeGuideStyleModel.rGuideStyles != null)
foreach (var rGuideStyle in GrainSizeGuideStyleModel.rGuideStyles)
if (guideMod.oldSelectItem.Equals(rGuideStyle.tag))
length = guideMod.hLineLength + guideMod.vLineLength + guideMod.TopleftLineLength + guideMod.ToprightLineLength
+ guideMod.diameter * Math.PI + (guideMod.diameter + 2 * guideMod.margin) * Math.PI + (guideMod.diameter + 4 * guideMod.margin) * Math.PI;
return length;
}
///
/// 是否 垂直/水平辅助线
///
///
///
public bool IsVGuideStylesOrHGuideStyles(object SelectedItem)
{
bool vGuideStylesOrHGuideStyles = false;
// 垂直辅助线
if (GrainSizeGuideStyleModel.vGuideStyles != null)
{
foreach (var vGuideStyle in GrainSizeGuideStyleModel.vGuideStyles)
{
if (SelectedItem.Equals(vGuideStyle.tag))
{
vGuideStylesOrHGuideStyles = true;
break;
}
}
}
// 水平辅助线
if (GrainSizeGuideStyleModel.hGuideStyles != null)
{
foreach (var hGuideStyle in GrainSizeGuideStyleModel.hGuideStyles)
{
if (SelectedItem.Equals(hGuideStyle.tag))
{
vGuideStylesOrHGuideStyles = true;
break;
}
}
}
return vGuideStylesOrHGuideStyles;
}
}
}