12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850 |
- 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
- {
- /// <summary>
- /// 0,GBT6394; 1,GBT4335; 2,GBT24177; 3,E112; 4,ISO643;5,YST347(XX)
- /// </summary>
- private int gbtType;
- /// <summary>
- /// 需要根据当前操作图片备份和读取的辅助线数据
- /// </summary>
- public GrainSizeGuideModel guideModel = new GrainSizeGuideModel();
- /// <summary>
- /// 根据图片保存辅助线参数
- /// </summary>
- public Dictionary<string, GrainSizeGuideModel> guideDict = new Dictionary<string, GrainSizeGuideModel>();
- public PointF m_StartPoint = Point.Empty;
- public bool m_canMove;
- /// <summary>
- /// 1上 2下 3左 4右
- /// </summary>
- private int m_MoveDirection = 0;
- private bool m0_canMove;
- /// <summary>
- /// 构造辅助线的工作结构
- /// </summary>
- public void createGuideClassModelsNamed(string modelName)
- {
- GrainSizeGuideStyleModel = XmlSerializeHelper.DESerializer<GrainSizeGuideStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\" + modelName, FileMode.Open));
- }
- /// <summary>
- /// 构造辅助线的工作结构
- /// </summary>
- public void createGuideAreaClassModelsNamed(string modelName)
- {
- GrainSizeGuideAreaMethodModel = XmlSerializeHelper.DESerializer<GrainSizeGuideAreaMethodModel>(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);
- }
- /// <summary>
- /// 面积法-圆的直径
- /// </summary>
- public int GetMat_lineDiameter(double physical_Micron)
- {
- return Math.Max(1, (int)(guideModel.lineDiameter / physical_Micron));
- }
- /// <summary>
- /// 辅助线长度
- /// </summary>
- public double LineLength
- {
- get
- {
- return guideModel.lineLength;
- }
- }
- /// <summary>
- /// 辅助线数量
- /// </summary>
- public int LineDec
- {
- get
- {
- return guideModel.lineDec;
- }
- }
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="point1">换算后的点</param>
- /// <param name="e"></param>
- 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;
- }
- }
- /// <summary>
- /// 面积法的鼠标移动
- /// </summary>
- /// <param name="point1">换算后的点</param>
- /// <param name="e"></param>
- 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;
- }
- /// <summary>
- /// 缩放辅助线及其样式
- /// </summary>
- /// <param name="m_MoveDirection">1上 2下 3左 4右</param>
- /// <param name="SelectedItem"></param>
- /// <param name="startPoint"></param>
- /// <param name="endPoint"></param>
- 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;
- }
- }
- }
- }
- /// <summary>
- /// 移动
- /// </summary>
- /// <param name="point1">换算后的点</param>
- /// <param name="e"></param>
- 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;
- }
- /// <summary>
- /// 鼠标抬起
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void onMouseUp(object sender, MouseEventArgs e)
- {
- m0_canMove = false;
- ((SystemLayer.ScrollPanel)sender).Cursor = Cursors.Default;
- }
- /// <summary>
- /// 更新辅助线及其样式
- /// </summary>
- 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;
- }
- }
- }
- }
- /// <summary>
- /// 缩放辅助线及其样式更新数据
- /// </summary>
- /// <param name="SelectedItem"></param>
- 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);
- }
- /// <summary>
- /// 缩放辅助线及其样式
- /// </summary>
- /// <param name="m_MoveDirection">1上 2下 3左 4右</param>
- /// <param name="SelectedItem"></param>
- /// <param name="endPoint"></param>
- 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);//###
- }
- }
- }
- }
- /// <summary>
- /// 面积法绘制辅助线
- /// </summary>
- /// <param name="graphics"></param>
- /// <param name="SelectedItem"></param>
- 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);
- }
- }
- }
- }
- /// <summary>
- /// 绘制辅助线
- /// </summary>
- 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);
- }
- /// <summary>
- /// 获取辅助线的外框矩形
- /// </summary>
- /// <param name="SelectedItem"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 更新辅助线的外框矩形宽高数值(获取辅助线的外框矩形)
- /// </summary>
- /// <param name="SelectedItem"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 更新辅助线的外框矩形宽高数值(获取辅助线的外框矩形)
- /// </summary>
- /// <param name="SelectedItem"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 获取辅助线的外框矩形
- /// </summary>
- /// <param name="SelectedItem"></param>
- /// <returns></returns>
- 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<PointF> pointFs = new List<PointF>();
- //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;
- }
- /// <summary>
- /// 复合辅助线的点的数量
- /// </summary>
- /// <returns></returns>
- 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<PointF> pointFs = new List<PointF>();
- 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;
- }
- /// <summary>
- /// 图形上所有的点
- /// </summary>
- /// <param name="bitmapW"></param>
- /// <param name="bitmapH"></param>
- /// <param name="SelectedItem"></param>
- /// <param name="physical_Micron"></param>
- /// <param name="guideStyle">1 圆形 2 矩形</param>
- /// <returns></returns>
- public List<PointF> getGuideAreaPointList(int bitmapW, int bitmapH, object SelectedItem, double physical_Micron, out int guideStyle)
- {
- guideStyle = 2;
- List<PointF> linePointList = new List<PointF>();
- // 圆形
- 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;
- }
- /// <summary>
- /// 图形上所有的点,并按照直线或者圆圈类型赋值列表
- /// </summary>
- public List<PointF> getGuidePointListAndClassLine(Mat mat, object SelectedItem, out List<List<PointF>> straightLinePointList, out List<List<PointF>> roundLinePointList)
- {
- List<PointF> linePointList = new List<PointF>();
- straightLinePointList = new List<List<PointF>>();///
- roundLinePointList = new List<List<PointF>>();///
- //lineValueList.Clear();//###
- List<PointF> 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<PointF>();
- 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<PointF>();
- 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<PointF>();
- 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<Point> points = new List<Point>();
- 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<PointF>();
- 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<PointF>();
- 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<PointF>();
- 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<Point> points = new List<Point>();
- if (mat != null)
- {
- classPointList = new List<PointF>();
- 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<PointF>();
- 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<PointF>();
- // 循环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<PointF>();
- // 循环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<PointF>();
- 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<PointF>();
- 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<PointF>();
- 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;
- }
- /// <summary>
- /// 使用圆心及半径得到圆的轮廓
- /// </summary>
- /// <param name="center">圆心</param>
- /// <param name="radius">半径</param>
- /// <returns></returns>
- 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];
- }
- /// <summary>
- /// 更新辅助线及其样式
- /// </summary>
- 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"));
- }
- /// <summary>
- /// 更新辅助线及其样式
- /// </summary>
- 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<int> indexList1 = new List<int>();
- // 圆形
- 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<int> indexList1 = new List<int>();
- // 垂直辅助线
- 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;
- }
- /// <summary>
- /// 获取辅助线缩放比例
- /// </summary>
- /// <param name="gridSize"> 设置的数值 </param>
- /// <param name="maxSize"> 限制最大值 </param>
- /// <returns></returns>
- private double physicalGainMultiple(double gridSize, double maxSize)
- {
- double multiple = 1.0;
- if (gridSize > maxSize)
- {
- multiple = maxSize / gridSize;
- }
- return multiple;
- }
- /// <summary>
- /// 获取辅助线的面积
- /// </summary>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 获取辅助线的物理长度
- /// </summary>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 是否 垂直/水平辅助线
- /// </summary>
- /// <param name="SelectedItem"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
|