123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525 |
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.SettingModel;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace PaintDotNet.DedicatedAnalysis.GrainSize
- {
- class GuideSizeArLawClass
- {
- GrainSizeArbitrationLawModel grainSizeArbitrationLawModel;
- ///// <summary>
- ///// 单位
- ///// </summary>
- //public double unitLength;
- /// <summary>
- /// 网格交点
- /// </summary>
- public List<RectangleF> rectangleFs = new List<RectangleF>();
- /// <summary>
- /// 旋转角度
- /// </summary>
- public int rotateAngleV = 0;
- /// <summary>
- /// 图形位置
- /// </summary>
- public PointF loctation;
- /// <summary>
- /// 图形位移
- /// </summary>
- public RectangleF rectangleFLine = new RectangleF();
- /// <summary>
- /// 网格绘制区域
- /// </summary>
- private float minX;
- private float maxX;
- private float minY;
- private float maxY;
- /// <summary>
- /// 水平数量
- /// </summary>
- public int hNumber;
- /// <summary>
- /// 垂直数量
- /// </summary>
- public int vNumber;
- /// <summary>
- /// 网格线宽
- /// </summary>
- public int gridWidth;
- /// <summary>
- /// 网格间距
- /// </summary>
- public float gridSpacing;
- public float gridSpacing1;
- /// <summary>
- /// 网格颜色
- /// </summary>
- public int gridColor;
- /// <summary>
- /// 全图 true:全图 false:非全图
- /// </summary>
- public bool wholePicture;
- /// <summary>
- /// 余白
- /// </summary>
- public int blank;
- /// <summary>
- /// 绘制网格
- /// </summary>
- /// <param name="graphics"></param>
- public void DrawGridViews(Graphics graphics, int CSHeight, int CSWidth)
- {
- Pen linePen = new Pen(Color.FromArgb(this.gridColor), this.gridWidth);
- //float panX = this.loctation.X - this.documentWorkspace.CompositionSurface.Width / 2;
- //float panY = this.loctation.Y - this.documentWorkspace.CompositionSurface.Height / 2;
- float hGridSpacingDraw;
- float vGridSpacingDraw;
- float blankDraw;
- if (this.wholePicture)
- {
- hGridSpacingDraw = (float)(CSHeight - 2 * this.blank) / (this.hNumber - 1);
- vGridSpacingDraw = (float)(CSWidth - 2 * this.blank) / (this.vNumber - 1);
- blankDraw = this.blank;
- }
- else
- {
- blankDraw = 0;
- hGridSpacingDraw = this.gridSpacing;
- vGridSpacingDraw = this.gridSpacing;
- }
- if (this.hNumber > 0)
- {
- if (this.hNumber % 2 == 0)
- {
- float Spacing = hGridSpacingDraw / 2;
- for (int i = 0; i < (float)this.hNumber / 2; i++)
- {
- if (this.wholePicture)
- {
- if (CSHeight > 2 * this.blank && CSWidth > 2 * this.blank)
- {
- if ((float)CSHeight / 2 - Spacing >= blankDraw)
- {
- //PointF pointF1 = rotatedAndPanPoint((float)(Convert.ToDecimal(x) - Convert.ToDecimal((float)this.gridWidth / 2) - 3)
- // , (float)(Convert.ToDecimal(y) - Convert.ToDecimal((float)this.gridWidth / 2) - 3));
- graphics.DrawLine(linePen, rotatedAndPanPoint(blankDraw, (float)CSHeight / 2 - Spacing, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)(CSWidth - blankDraw), (float)CSHeight / 2 - Spacing, CSHeight, CSWidth));
- }
- if ((float)CSHeight / 2 + Spacing <= CSHeight - blankDraw)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint(blankDraw, (float)CSHeight / 2 + Spacing, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)(CSWidth - blankDraw), (float)CSHeight / 2 + Spacing, CSHeight, CSWidth));
- }
- }
- }
- else
- {
- if ((float)CSHeight / 2 - Spacing >= 0)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint(minX, (float)CSHeight / 2 - Spacing, CSHeight, CSWidth)
- , rotatedAndPanPoint(maxX, (float)CSHeight / 2 - Spacing, CSHeight, CSWidth));
- }
- if ((float)CSHeight / 2 + Spacing <= CSHeight)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint(minX, (float)CSHeight / 2 + Spacing, CSHeight, CSWidth)
- , rotatedAndPanPoint(maxX, (float)CSHeight / 2 + Spacing, CSHeight, CSWidth));
- }
- }
- Spacing += hGridSpacingDraw;
- }
- }
- else
- {
- if ((float)CSWidth > 2 * blankDraw)
- {
- if (this.hNumber == 1)
- graphics.DrawLine(linePen, rotatedAndPanPoint(blankDraw, (float)CSHeight / 2, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)(CSWidth - blankDraw), (float)CSHeight / 2, CSHeight, CSWidth));
- else
- {
- float Spacing = hGridSpacingDraw;
- for (int i = 0; i < (this.hNumber - 1) / 2; i++)
- {
- if (this.wholePicture)
- {
- if (CSHeight > 2 * this.blank && CSWidth > 2 * this.blank)
- {
- if (i == 0)
- graphics.DrawLine(linePen, rotatedAndPanPoint(blankDraw, (float)CSHeight / 2, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)(CSWidth - blankDraw), (float)CSHeight / 2, CSHeight, CSWidth));
- if ((float)CSHeight / 2 - Spacing >= blankDraw)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint(blankDraw, (float)CSHeight / 2 - Spacing, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)(CSWidth - blankDraw), (float)CSHeight / 2 - Spacing, CSHeight, CSWidth));
- }
- if ((float)CSHeight / 2 + Spacing <= CSHeight - blankDraw)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint(blankDraw, (float)CSHeight / 2 + Spacing, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)(CSWidth - blankDraw), (float)CSHeight / 2 + Spacing, CSHeight, CSWidth));
- }
- }
- }
- else
- {
- if (i == 0)
- graphics.DrawLine(linePen, rotatedAndPanPoint(minX, (float)CSHeight / 2, CSHeight, CSWidth)
- , rotatedAndPanPoint(maxX, (float)CSHeight / 2, CSHeight, CSWidth));
- if ((float)CSHeight / 2 - Spacing >= 0)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint(minX, (float)CSHeight / 2 - Spacing, CSHeight, CSWidth)
- , rotatedAndPanPoint(maxX, (float)CSHeight / 2 - Spacing, CSHeight, CSWidth));
- }
- if ((float)CSHeight / 2 + Spacing <= CSHeight)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint(minX, (float)CSHeight / 2 + Spacing, CSHeight, CSWidth)
- , rotatedAndPanPoint(maxX, (float)CSHeight / 2 + Spacing, CSHeight, CSWidth));
- }
- }
- Spacing += hGridSpacingDraw;
- }
- }
- }
- }
- }
- if (this.vNumber > 0)
- {
- if (this.vNumber % 2 == 0)
- {
- float Spacing = vGridSpacingDraw / 2;
- for (int i = 0; i < (float)this.vNumber / 2; i++)
- {
- if (this.wholePicture)
- {
- if (CSHeight > 2 * this.blank && CSWidth > 2 * this.blank)
- {
- if ((float)CSWidth / 2 - Spacing >= 0
- && (float)CSWidth / 2 - Spacing >= blankDraw)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2 - Spacing, blankDraw, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2 - Spacing, (float)(CSHeight - blankDraw), CSHeight, CSWidth));
- }
- if ((float)CSWidth / 2 + Spacing <= CSWidth
- && (float)CSWidth / 2 + Spacing <= CSWidth - blankDraw)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2 + Spacing, blankDraw, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2 + Spacing, (float)(CSHeight - blankDraw), CSHeight, CSWidth));
- }
- }
- }
- else
- {
- if ((float)CSWidth / 2 - Spacing >= 0)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2 - Spacing, minY, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2 - Spacing, maxY, CSHeight, CSWidth));
- }
- if ((float)CSWidth / 2 + Spacing <= CSWidth)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2 + Spacing, minY, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2 + Spacing, maxY, CSHeight, CSWidth));
- }
- }
- Spacing += vGridSpacingDraw;
- }
- }
- else
- {
- if (CSHeight > 2 * blankDraw)
- {
- if (this.vNumber == 1)
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2, blankDraw, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2, (float)(CSHeight - blankDraw), CSHeight, CSWidth));
- else
- {
- float Spacing = vGridSpacingDraw;
- for (int i = 0; i < (this.vNumber - 1) / 2; i++)
- {
- if (this.wholePicture)
- {
- if (CSHeight > 2 * this.blank && CSWidth > 2 * this.blank)
- {
- if (i == 0)
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2, blankDraw, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2, (float)(CSHeight - blankDraw), CSHeight, CSWidth));
- if ((float)CSWidth / 2 + Spacing <= CSWidth
- && CSWidth / 2 + Spacing <= CSWidth - blankDraw)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2 + Spacing, blankDraw, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2 + Spacing, (float)(CSHeight - blankDraw), CSHeight, CSWidth));
- }
- if ((float)CSWidth / 2 - Spacing >= 0 && (float)CSWidth / 2 - Spacing >= blankDraw)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2 - Spacing, blankDraw, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2 - Spacing, (float)(CSHeight - blankDraw), CSHeight, CSWidth));
- }
- }
- }
- else
- {
- if (i == 0)
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2, minY, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2, maxY, CSHeight, CSWidth));
- if ((float)CSWidth / 2 + Spacing <= CSWidth)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2 + Spacing, minY, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2 + Spacing, maxY, CSHeight, CSWidth));
- }
- if ((float)CSWidth / 2 - Spacing >= 0)
- {
- graphics.DrawLine(linePen, rotatedAndPanPoint((float)CSWidth / 2 - Spacing, minY, CSHeight, CSWidth)
- , rotatedAndPanPoint((float)CSWidth / 2 - Spacing, maxY, CSHeight, CSWidth));
- }
- }
- Spacing += vGridSpacingDraw;
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 获取辅助线下拉集合
- /// </summary>
- /// <returns></returns>
- public ArrayList GetComboBox1DataSource()
- {
- ArrayList arrayList1 = new ArrayList();
- // 垂直辅助线
- if (grainSizeArbitrationLawModel.GridStyleList != null)
- {
- foreach (var vGuideStyle in grainSizeArbitrationLawModel.GridStyleList)
- {
- arrayList1.Add(vGuideStyle.gridName);
- }
- }
- arrayList1.Insert(0, PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text"));
- return arrayList1;
- }
- public void InitLawModel()
- {
- grainSizeArbitrationLawModel = XmlSerializeHelper.DESerializer<GrainSizeArbitrationLawModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeArbitrationLawModel.xml", FileMode.Open));
- }
- //public void InitUnitLength(Dictionary<MeasurementUnit, double> MeasureInfo)
- //{
- // MeasureInfo.TryGetValue(MeasurementUnit.Micron, out unitLength); double unitLength
- // //double physical_area_length_Micron = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
- //}
- /// <summary>
- /// 更新辅助线及其样式
- /// </summary>
- public void UpdateGuideStyle(object comboBox1SelectedItem, double physical_Micron = 1.0)
- {
- if (grainSizeArbitrationLawModel.GridStyleList != null)
- {
- foreach (var GridStyle in grainSizeArbitrationLawModel.GridStyleList)
- {
- if (GridStyle.gridName.Equals(comboBox1SelectedItem))
- {
- this.hNumber = GridStyle.hNumber + 1;
- this.vNumber = GridStyle.vNumber + 1;
- this.gridWidth = GridStyle.gridWidth;
- this.gridSpacing = (float)(GridStyle.gridSpacing / physical_Micron);
- this.gridSpacing1 = (float)(GridStyle.gridSpacing);
- this.gridColor = GridStyle.gridColor;
- this.wholePicture = GridStyle.wholePicture;
- this.blank = GridStyle.blank;
- }
- }
- }
- }
- /// <summary>
- /// 初始化矩形
- /// </summary>
- public void InitRectangleF(PointF pointF, int CompositionSurfaceHeight, int CompositionSurfaceWidth)
- {
- // 全图
- if (this.wholePicture)
- {
- rectangleFLine = new RectangleF(pointF.X - CompositionSurfaceWidth / 2 + this.blank, pointF.Y - CompositionSurfaceHeight / 2 + this.blank
- , CompositionSurfaceWidth - 2 * this.blank, CompositionSurfaceHeight - 2 * this.blank);
- }
- else
- {
- rectangleFLine = new RectangleF(pointF.X - (this.vNumber - 1) * this.gridSpacing / 2, pointF.Y - (this.hNumber - 1) * this.gridSpacing / 2
- , (this.vNumber - 1) * this.gridSpacing, (this.hNumber - 1) * this.gridSpacing);
- }
- }
- /// <summary>
- /// 刷新网格矩形
- /// </summary>
- public void RefreshGridIntersections(int CompositionSurfaceHeight, int CompositionSurfaceWidth)
- {
- this.rectangleFs.Clear();
- ////float rectangleFLineX = this.rectangleFLine.X + this.lineWidth / 2 + spacing;
- //float panX = this.loctation.X - this.documentWorkspace.CompositionSurface.Width / 2;
- //float panY = this.loctation.Y - this.documentWorkspace.CompositionSurface.Height / 2;
- float hGridSpacingDraw;
- float vGridSpacingDraw;
- if (this.wholePicture)
- {
- hGridSpacingDraw = (float)(CompositionSurfaceHeight - 2 * this.blank) / (this.hNumber - 1);
- vGridSpacingDraw = (float)(CompositionSurfaceWidth - 2 * this.blank) / (this.vNumber - 1);
- }
- else
- {
- hGridSpacingDraw = this.gridSpacing;
- vGridSpacingDraw = this.gridSpacing;
- }
- ArrayList xs = new ArrayList();
- ArrayList ys = new ArrayList();
- if (this.hNumber > 0)
- {
- if (this.hNumber % 2 == 0)
- {
- float Spacing = hGridSpacingDraw / 2;
- for (int i = 0; i < this.hNumber / 2; i++)
- {
- if ((float)CompositionSurfaceHeight / 2 - Spacing >= 0
- && (float)CompositionSurfaceHeight / 2 + Spacing <= CompositionSurfaceHeight)
- {
- ys.Add((float)CompositionSurfaceHeight / 2 - Spacing);
- ys.Add((float)CompositionSurfaceHeight / 2 + Spacing);
- }
- Spacing += hGridSpacingDraw;
- }
- }
- else
- {
- if (this.hNumber == 1)
- ys.Add((float)CompositionSurfaceHeight / 2);
- else
- {
- float Spacing = hGridSpacingDraw;
- for (int i = 0; i < (this.hNumber - 1) / 2; i++)
- {
- if (i == 0)
- ys.Add((float)CompositionSurfaceHeight / 2);
- if ((float)CompositionSurfaceHeight / 2 - Spacing >= 0
- && (float)CompositionSurfaceHeight / 2 + Spacing <= CompositionSurfaceHeight)
- {
- ys.Add((float)CompositionSurfaceHeight / 2 - Spacing);
- ys.Add((float)CompositionSurfaceHeight / 2 + Spacing);
- }
- Spacing += hGridSpacingDraw;
- }
- }
- }
- }
- if (this.vNumber > 0)
- {
- if (this.vNumber % 2 == 0)
- {
- float Spacing = vGridSpacingDraw / 2;
- for (int i = 0; i < this.vNumber / 2; i++)
- {
- if ((float)CompositionSurfaceWidth / 2 - Spacing >= 0
- && (float)CompositionSurfaceWidth / 2 + Spacing <= CompositionSurfaceWidth)
- {
- xs.Add((float)CompositionSurfaceWidth / 2 - Spacing);
- xs.Add((float)CompositionSurfaceWidth / 2 + Spacing);
- }
- Spacing += vGridSpacingDraw;
- }
- }
- else
- {
- if (this.vNumber == 1)
- xs.Add((float)CompositionSurfaceWidth / 2);
- else
- {
- float Spacing = vGridSpacingDraw;
- for (int i = 0; i < (this.vNumber - 1) / 2; i++)
- {
- if (i == 0)
- xs.Add((float)CompositionSurfaceWidth / 2);
- if ((float)CompositionSurfaceWidth / 2 + Spacing <= CompositionSurfaceWidth
- && (float)CompositionSurfaceWidth / 2 - Spacing >= 0)
- {
- xs.Add((float)CompositionSurfaceWidth / 2 - Spacing);
- xs.Add((float)CompositionSurfaceWidth / 2 + Spacing);
- }
- Spacing += vGridSpacingDraw;
- }
- }
- }
- }
- if (xs.Count > 1)
- {
- this.minX = (float)xs[xs.Count - 2];
- this.maxX = (float)xs[xs.Count - 1];
- }
- if (ys.Count > 1)
- {
- this.minY = (float)ys[ys.Count - 2];
- this.maxY = (float)ys[ys.Count - 1];
- }
- foreach (var x in xs)
- {
- foreach (var y in ys)
- {
- PointF pointF1 = rotatedAndPanPoint/*计算旋转后的网点位置,同时需要加中心偏移*/((float)(Convert.ToDecimal(x) - 0/*Convert.ToDecimal((float)this.gridWidth / 2)*/)
- , (float)(Convert.ToDecimal(y) - 0/*Convert.ToDecimal((float)this.gridWidth / 2)*/), CompositionSurfaceHeight, CompositionSurfaceWidth);
- this.rectangleFs.Add(new RectangleF(pointF1.X - 6 - this.gridWidth / 2, pointF1.Y - 6 - this.gridWidth / 2, this.gridWidth + 6, this.gridWidth + 6));
- }
- }
- if (this.wholePicture)
- {
- int count = this.rectangleFs.Count;
- RectangleF rectangleF = new RectangleF(this.blank, this.blank, CompositionSurfaceWidth + 1 - 2 * this.blank
- , CompositionSurfaceHeight + 1 - 2 * this.blank);
- for (int i = count - 1; i >= 0; i--)
- {
- if (!rectangleF.Contains(new PointF(this.rectangleFs[i].X + 3 + (float)this.gridWidth / 2, this.rectangleFs[i].Y + 3 + (float)this.gridWidth / 2)))
- {
- this.rectangleFs.RemoveAt(i);
- }
- }
- }
- }
- private PointF rotatedPoint(float point_X, float point_Y, int CompositionSurfaceHeight, int CompositionSurfaceWidth)
- {
- double rotatedVPai = this.rotateAngleV * Math.PI / 180.0;
- double disX = point_X - CompositionSurfaceWidth / 2;
- double disY = point_Y - CompositionSurfaceHeight / 2;
- double outX = disX * Math.Cos(rotatedVPai) - disY * Math.Sin(rotatedVPai);
- double outY = disX * Math.Sin(rotatedVPai) + disY * Math.Cos(rotatedVPai);
- return new PointF((float)outX, (float)outY);
- }
- private PointF rotatedAndPanPoint(float point_X, float point_Y, int CompositionSurfaceHeight, int CompositionSurfaceWidth)
- {
- PointF point1 = rotatedPoint(point_X, point_Y, CompositionSurfaceHeight, CompositionSurfaceWidth);
- float panX = this.loctation.X;
- float panY = this.loctation.Y;
- return new PointF(point1.X + panX, point1.Y + panY);
- }
- }
- }
|