123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using OTS.WinFormsUI.Docking;
- using System.Collections;
- using OTSDataType;
- using OTSModelSharp;
- using MyControls;
- using OTSModelSharp.ServiceInterface;
- using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel;
- using static OTSDataType.otsdataconst;
- namespace OTSMeasureApp
- {
- public enum EnumMousePointPosition
- {
- MouseSizeNone = 0, //'无
- MouseSizeRight = 1, //'拉伸右边框
- MouseSizeLeft = 2, //'拉伸左边框
- MouseSizeBottom = 3, //'拉伸下边框
- MouseSizeTop = 4, //'拉伸上边框
- MouseSizeTopLeft = 5, //'拉伸左上角
- MouseSizeTopRight = 6, //'拉伸右上角
- MouseSizeBottomLeft = 7, //'拉伸左下角
- MouseSizeBottomRight = 8, //'拉伸右下角
- MouseDrag = 9 // '鼠标拖动
- }
- public partial class OTSSamplespaceWindow : DockContent
- {
- #region 全局变量定义
- public CVisualStage m_visualStage;
- //样品孔的List集合
- string m_SampleHoleSelectName = string.Empty;
- public string m_SampleSelectName = string.Empty;
-
- public List<CVisualSampleArea> m_visualSamples;
- //BSE图像
- public static List<CRectangleGDIObject> m_ImageGDIObjects;
- //BSE图像帧图 为了获取位置与尺寸
- public static List<CRectangleGDIObject> m_ImageOfFieldGDIObjects;
- //手绘测量区域
- public static CRectangleGDIObject m_DrawMeasureGDIObject=new CRectangleGDIObject();
-
- //多边形测量区域完成标识
- public static CRectangleGDIObject m_DrawPolygonFinishGDIObject;
- //主窗体对象
- OTSIncAMeasureAppForm m_MeasureAppForm;
-
- SEMDATAFieldManage m_SEMDATAFieldManage;
-
- private _5_OTSMeasureStatuImageFun.SlopFocus slopFocus=null;
-
- const float m_PenWidth = 5;
- const int m_MinMeasureWidthValue = 20;
- //点数量
- const int m_PolygonMinPointCount = 2;
- //与多边形绘制的开始点相差的像素值
- const int m_OffsetPX = 10;
- //默认值
- const int m_DValue = 1;
-
- #region 手动绘制测量区域
- Point m_MouseDownPoint;
-
- Point m_MouseMovePoint;
- //手动绘制多边形测量区域完成标识
- bool m_IsDrawPolygonFinish = false;
- //手动绘制测量区域的形状类型
- CreateRectangleType m_DrawMeasureType = (CreateRectangleType)1;
- //是否手绘标识
- bool m_IsDrawMeasure = false;
- #endregion
- #endregion
- NLog.Logger log;
- #region 标尺变量
- //最小缩放倍数
- const float f_zoom_mix = 0.5f;
- //标尺的大小记录
- private float f_ruler_size = 100;
- //标尺原先大小的记录,参与计算
- private float f_old_ruler_size = 100;
- #endregion
- //国际化
- OTSCommon.Language lan;
- Hashtable table;
- #region 设置双缓冲
- /// <summary>
- /// 设置双缓冲
- /// </summary>
- public void SetDoubleBufferByIsDraw()
- {
- SetStyle(ControlStyles.UserPaint, true);
- SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲
- }
- #endregion
- #region 构造函数 获取父窗体对象
- public OTSSamplespaceWindow(OTSIncAMeasureAppForm MeasureAppForm)
- {
- InitializeComponent();
- m_MeasureAppForm = MeasureAppForm;
-
- SetDoubleBufferByIsDraw();// 双缓冲
-
-
- //国际化
- lan = new OTSCommon.Language(this);
- table = lan.GetNameTable(this.Name);
- }
- /// <summary>
- /// 画圆形测试区域 事件
- /// </summary>
- public void DrawCircleMeasure()
- {
- //手绘测量区域类型为圆形
- m_DrawMeasureType = CreateRectangleType.Circle;
- m_IsDrawMeasure = true;
- this.Cursor = Cursors.Hand;
- }
- /// <summary>
- /// 画矩形测试区域 事件
- /// </summary>
- public void DrawRectangleMeasure()
- {
- //手绘测量区域类型为矩形
- m_DrawMeasureType = CreateRectangleType.SampleBackGround_Rectangle;
-
- m_IsDrawMeasure = true;
- this.Cursor = Cursors.Hand;
- }
- /// <summary>
- /// 画多边形测试区域 事件
- /// </summary>
- public void DrawPolygonMeasure()
- {
- m_DrawMeasureType = CreateRectangleType.Polygon;
- m_IsDrawMeasure = true;
-
- this.Cursor = Cursors.Hand;
- }
- /// <summary>
- /// 三点画圆形测试区域 事件 先多边形后圆形
- /// </summary>
- public void DrawCircleMeasureByThreePoints()
- {
- //手绘测量区域类型为圆形
- m_DrawMeasureType = CreateRectangleType.CircleByThreePoints;
- m_IsDrawMeasure = true;
-
- this.Cursor = Cursors.Hand;
- }
- public void DrawRingShapeArea()
- {
- //手绘测量区域类型为圆形
- m_DrawMeasureType = CreateRectangleType.RingShape;
- RingGdiDataInput frmInput = new RingGdiDataInput();
- if (frmInput.ShowDialog() == DialogResult.OK)
- {
- float diameter =(float) m_visualStage.MicronConvertToPixel(frmInput.Diameter);
- float ringwidth = (float)m_visualStage.MicronConvertToPixel( frmInput.RingWidth);
- var sam = GetWorkingVisualSample();
- SizeF size = new SizeF(diameter, diameter);
- var position =sam.GetMeasureGDIObject().GetZoomedRegionF().Location;
- RectangleF rectangle = new RectangleF(position, size);
- Color MeasureColor = Color.Red;
- CRingGDIObject newGDI;
-
- newGDI = new CRingGDIObject(rectangle, CreateRectangleType.RingShape, sam.GetSampleGDIObject().NameOrHoleName, sam.GetSampleName(), MeasureColor);
- newGDI.SetRingWidth(ringwidth);
- newGDI.SetZoomNumber(m_visualStage.GetZoomNum());
- newGDI.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
- newGDI.IsWorkSample = true;
- sam.SetMeasureGDIObject(newGDI);
- m_DrawPolygonFinishGDIObject = null;
- m_DrawMeasureGDIObject = null;
- var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
- }
-
-
- }
- #region 菜单操作
- private void CMStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- Point mousePoint = this.PointToClient(Control.MousePosition);
- CMStrip.Hide();
- switch (e.ClickedItem.Name)
- {
- case "AddStage":
- m_MeasureAppForm.m_SPropertyWindows.TSSaveAs.Enabled = true;
- m_MeasureAppForm.m_SPropertyWindows.TSLoad.Enabled = true;
- m_MeasureAppForm.m_SPropertyWindows.TSEdit.Enabled = false;
- m_MeasureAppForm.m_SPropertyWindows.TSEdit.Visible = false;
- //添加样品
- m_MeasureAppForm.AddNewSampleMeasure(m_SampleHoleSelectName);
- ReadSEMDataFromSEM();
- break;
- case "DeleteStage":
- //删除样品
- DeleteSampleInfo(m_SampleSelectName);
- break;
- case "DriveSEMToCenterLocation":
- //驱动SEM到中心位置
- SetSEMToCenterPoint();
- break;
- case "DriveSEMToCurrentLocation":
- //驱动SEM到当前位置
- SetSEMCurrentLocation();
- break;
- case "SetSEMCenterLocation":
- //将测量区域移到SEM当前位置
- SetMeasureToSEMLocation();
- break;
- case "ReadSEMData":
- m_MeasureAppForm.m_RunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- //设定SEM数据
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- ReadSEMDataFromSEM();
- PrepareMeasureField(GetWorkingVisualSample());
-
- break;
- case "SetSemData":
- double SemMag = 0;
- double dDistance = 0;
- if (m_MeasureAppForm.m_ProjParam.GetMagAndDistance(ref SemMag, ref dDistance))
- {
- //设置SEM数据
- if (!SetSEMDATAMParameter(SemMag, dDistance))
- {
- log.Error("Failed SetSemData:--Mag:" + SemMag + "--Distance:" + dDistance + "--");
- }
- }
- break;
- case "ShootBSEPicture":
- //设置消息类型 拍摄样品孔
- m_MeasureAppForm.m_RunType = MSR_THREAD_RunSTATUS.RUNSampleHoleImage;
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNSampleHoleImage;
- //清除原图片信息
- DeleteHoleBSEImageDataNoMessageBox();
-
- PrepareMeasureField(GetWorkingVisualSample());
-
- GetBSEPictures();
- break;
- case "DeleteBSEPicture":
- DeleteHoleBSEImageData();
- break;
- case "SlopFocusMenuItem":
- if (slopFocus == null)
- {
- slopFocus = new _5_OTSMeasureStatuImageFun.SlopFocus(this);
- }
- slopFocus.Show();
- break;
- }
- }
- #endregion
- public CVisualSampleArea GetWorkingVisualSample()
- {
- foreach (var s in m_visualSamples)
- {
- if (s.IsWorkSample())
- {
- return s;
- }
-
- }
- return null;
- }
- public CVisualSampleArea GetVisualSampleByName(string name)
- {
- foreach (var s in m_visualSamples)
- {
- if (s.GetSampleName() == name)
- {
- return s;
- }
- }
- return null;
- }
-
- public void OpenExistSampleFile(CStage SStage, CSEMStageData SEMStageData, List<SampleMeasurePara> SMeasrueParaList)
- {
-
- m_visualStage.InitSampleStageData(SStage, SEMStageData, this.Width, this.Height);
- m_visualStage.DrawSampleStage();
- m_visualSamples.Clear();
- foreach (var SMeasrueArea in SMeasrueParaList)
- {
- var m_Sample = m_MeasureAppForm.m_ProjParam.GetResultData().GetSampleByName(SMeasrueArea.sSampleName);
- var FldDatas = m_Sample.GetFieldsData();
- if (FldDatas.Count == 0)
- {
- //this part code is to be compatible with previouse version result file which there's no AllField position info.
- DrawSampleAndMeasureInfo(SMeasrueArea);
-
- }
- else
- {
- var item = m_visualStage.GetHoleGDIByHoleName(SMeasrueArea.sampleHoleName);
- if (item != null)
- {
- CVisualSampleArea sam;
- if (AddVisualSample(SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, out sam))
- {
- if (SMeasrueArea.iShape == (ShapeType)CreateRectangleType.Polygon)
- {
- var ps = new List<PointF>();
- foreach (var p in SMeasrueArea.DrawPolygonPointList)
- {
- var ctrlcoordPoint = m_visualStage.OTSCoordToCtrlCoord(p);
- ps.Add(ctrlcoordPoint);
- }
- CRectangleGDIObject polygonGdi = new CRectangleGDIObject(ps, CreateRectangleType.Polygon, (ShapeType)SMeasrueArea.iShape, SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, Color.Red);
- sam.SetMeasureGDIObject(polygonGdi);
-
- }
- else
- {
- PointF xHole = new PointF(SMeasrueArea.MeasureRect.Left, SMeasrueArea.MeasureRect.Top);
- PointF yHole = new PointF(SMeasrueArea.MeasureRect.Right, SMeasrueArea.MeasureRect.Bottom);
- CRectangleGDIObject gdi = m_visualStage.GetCtrlCoordRect(xHole, yHole, (CreateRectangleType)SMeasrueArea.iShape, "", "");
- gdi.SampleName = SMeasrueArea.sSampleName;
- gdi.NameOrHoleName = SMeasrueArea.sampleHoleName;
- gdi.Shape = SMeasrueArea.iShape;
- CRectangleGDIObject measureGdi;
- if (m_visualStage.GetMeasureGdiObjectFromSampleGdi(gdi, out measureGdi))
- {
- sam.SetMeasureGDIObject(measureGdi);
-
- }
- }
-
- List<CRectangleGDIObject> visualfieldRects = new List<CRectangleGDIObject>();
- foreach (var fld in FldDatas)
- {
-
- float micronWidth = (float)fld.Width * (float)fld.GetPixelSize();
- float micronHeight = (float)fld.Height * (float)fld.GetPixelSize();
-
- var fldRect = new RectangleF(new PointF(fld.GetOTSPosition().X - micronWidth / 2, fld.GetOTSPosition().Y - micronHeight / 2), new SizeF(micronWidth, micronHeight));
- PointF lt = new PointF(fldRect.Left, fldRect.Top);
- PointF rb = new PointF(fldRect.Right, fldRect.Bottom);
- RectangleF visualRect = m_visualStage.GetCtrlCoordRectF(lt, rb);
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);
- string sampleName = sam.GetSampleName();
- string sampleHoleName = sam.GetSampleGDIObject().NameOrHoleName;
- CRectangleGDIObject createRect = new CRectangleGDIObject(visualRect,(int)fld.GetOTSPosition().X,(int)fld.GetOTSPosition().Y, CreateRectangleType.FieldRectangle, sampleHoleName, sampleName, ColorTranslator.FromHtml(ColorStr));
- visualfieldRects.Add(createRect);
-
- }
- sam.GetMeasureGDIObject().SubItems().Clear();
- //添加帧图列表
- int sequenceNum = 0;
- foreach (var r in visualfieldRects)
- {
- if (sam.GetMeasureGDIObject().ifRectangleIntersect(r))//filter the unmeasure fields
- {
- r.SequenceNum = sequenceNum++;
- sam.AddFieldGDIObject(r);
- }
- }
- COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();
- List<PointF> CompleteFieldList = cProjMgr.GetSampleByName(SMeasrueArea.sSampleName).GetMsrStatus().GetCompletedFieldsCenter();
- if (CompleteFieldList.Count > 0)
- {
- ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, sam);
- }
- }
- }
- }
- }
-
- SwitchWorkSample(SMeasrueParaList[0].sSampleName);
- m_SampleSelectName = SMeasrueParaList[0].sSampleName;
-
- //重新绘制
- Invalidate();
- }
-
- public void SwitchWorkSample(string sNewWSampleName, bool bDrawField = false)
- {
- try
- {
- for (int i = 0; i < m_visualSamples.Count; i++)
- {
- //获取颜色
- if (m_visualSamples[i].GetSampleName() == sNewWSampleName)
- {
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- m_visualSamples[i].GetSampleGDIObject().SelColor = ColorTranslator.FromHtml(ColorStr);
- m_visualSamples[i].SetIsWorkSample(true);
- }
- else
- {
- string SampleColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- m_visualSamples[i].GetSampleGDIObject().SelColor = ColorTranslator.FromHtml(SampleColorStr);
- m_visualSamples[i].SetIsWorkSample(false);
- }
-
- }
-
- m_IsDrawMeasure = false;
- this.Invalidate();
- return;
- }
- catch (Exception ex)
- {
-
- log.Trace(ex.ToString() );
- }
- }
- public void ChangeCompleteFieldMeasureState(List<PointF> CompleteFieldList, Color changeColor,CVisualSampleArea vsSam)
- {
- foreach(var p in CompleteFieldList)
- {
- ChangeDoneMeasureState(vsSam,p, changeColor);
-
- }
-
- }
- public void ChangeDoneMeasureState(CVisualSampleArea vsSam, PointF CurrentFIELDOTSPoint, Color changeColor)
- {
-
- foreach (var gdi in vsSam.GetMeasureFieldGDIObjects())
- {
- var fieldPoint = m_visualStage.OTSCoordToCtrlCoord(new PointF((float)CurrentFIELDOTSPoint.X , (float)CurrentFIELDOTSPoint.Y));
- if (gdi.IfContains(fieldPoint))
- {
- //修改完成状态
- gdi.SelColor = changeColor;
- break;
- }
- }
-
- }
-
- public void ChangeWorkSampleName(string sNewWSampleName)
- {
-
-
- //更换样品名称
- var sam = GetWorkingVisualSample();
- sam.SetSampleName(sNewWSampleName);
- this.Invalidate();
- return;
-
- }
- public void SetMeasureState(Color setColor)
- {
- foreach (var items in m_visualSamples)
- {
- items.GetMeasureGDIObject().SelColor = setColor;
- }
- }
- #endregion
- #region 修改样品选择状态
- public void SetSampleState(Color setColor)
- {
- foreach (var items in m_visualSamples)
- {
- if (items.GetSampleGDIObject().IsDragging)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- items.GetSampleGDIObject().SelColor = ColorTranslator.FromHtml(ColorStr);
- }
- else
- {
- items.GetSampleGDIObject().SelColor = setColor;
- }
- }
- }
-
- public bool DeleteSample(string SampleName)
- {
- var sam = GetVisualSampleByName(SampleName);
- m_visualStage.DecreaseSampleCount(SampleName);
- m_visualSamples.Remove(sam);
-
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- SetSampleState(ColorTranslator.FromHtml(ColorStr));
- SetMeasureState(ColorTranslator.FromHtml(ColorStr));
-
- return false;
- }
-
-
- public void DeleteWorkSample(string sDeleteWSampleName)
- {
- try
- {
- DeleteSample(sDeleteWSampleName);
-
- }
- catch (Exception ex)
- {
-
- log.Error( ex.ToString() );
- }
- }
- #region 更改工作样品中 测量区域形状
-
- public void changeShape(ShapeType iShape)
- {
- try
- {
- string sampleName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
- //m_Shap 更换样品形状
-
- var sam = GetWorkingVisualSample();
- var itemMeasure = sam.GetMeasureGDIObject();
- itemMeasure.Shape = iShape;
-
-
- var sampleMeasurePara = m_visualStage. GetSampleMeasurePara(sam.GetMeasureGDIObject());
-
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(sampleMeasurePara);
-
-
- PrepareMeasureField(sam);
-
-
- this.Invalidate();
- return;
- }
- catch (Exception ex)
- {
-
- log.Error(ex.ToString() );
- }
- }
- #endregion
-
-
- public void AddSampleArea(SampleMeasurePara SMeasurePara)
- {
-
- try
- {
- CMStrip.Hide();
-
- CVisualSampleArea sam;
- //添加样品
- foreach (var itemSample in m_visualSamples)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- itemSample.GetSampleGDIObject().SelColor = ColorTranslator.FromHtml(ColorStr);
- itemSample.SetIsWorkSample(false);
- }
- if (m_visualStage. GetVisualSampleArea(SMeasurePara, out sam))
- {
- sam.SetIsWorkSample(true);
- m_visualSamples.Add(sam);
- m_SampleSelectName = SMeasurePara.sSampleName;
- var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());
- //var para = SMeasurePara;
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- Invalidate();
-
- }
- }
- catch (Exception ex)
- {
-
- log.Error( ex.ToString() );
- }
- }
- public bool AddVisualSample(string SampleHoleName, string SampleName,out CVisualSampleArea outsample)
- {
- CRectangleGDIObject itemAdd;
- //设置样品选择状态为非工作样品
- foreach (var Sample in m_visualSamples)
- {
- var itemSample = Sample.GetSampleGDIObject();
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
- itemSample.IsWorkSample = false;
- }
- itemAdd = m_visualStage.GetHoleGDIByHoleName(SampleHoleName);
- if (itemAdd != null)
- {
- //获取样品台类型
- var shape = itemAdd.Shape;
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- Color selColor = ColorTranslator.FromHtml(ColorStr);
- CRectangleGDIObject sample =new CRectangleGDIObject (itemAdd.GetOrigionalDrawRegionF(), CreateRectangleType.SelectSample, shape, itemAdd.NameOrHoleName, selColor);
- //累加样品数量
- itemAdd.SampleCount += 1;
- itemAdd.IsWorkSample = true;
- sample.SampleName = SampleName;
- sample.NameOrHoleName = itemAdd.NameOrHoleName;
-
- var newSam = new CVisualSampleArea();
- newSam.SetSampleGDIObject(sample);
- newSam.SetSampleName(sample.SampleName);
- m_visualSamples.Add(newSam);
- outsample = newSam;
- return true;
- }
- outsample = null;
- return false;
- }
- #region 设置工作样品
- /// <summary>
- /// 设置工作样品与测量区域
- /// </summary>
- /// <param name="sampleName">样品名称</param>
- public void SetSampleOrder(string sampleName)
- {
-
-
- //修改测量区域集合 索引 (添加样品或者切换样品时,将当前工作样品显示在样品孔的最上)
- m_visualSamples = SelectMeasureIndexIsTop(m_visualSamples, sampleName);
-
- }
- #endregion
- private List<CVisualSampleArea> SelectMeasureIndexIsTop(List<CVisualSampleArea> objList, string SampleName)
- {
- List<CVisualSampleArea> objListTemp = objList;
- CVisualSampleArea itemTemp ;
- foreach (CVisualSampleArea item in objList)
- {
- if (item.GetSampleName() == SampleName)
- {
- //临时记录所选测量区域
- itemTemp = item;
- //删除原信息
- objListTemp.Remove(item);
- //添加新信息
- objListTemp.Insert(objListTemp.Count, itemTemp);
- break;
- }
- }
- return objListTemp;
- }
-
- //响应委托事件的样品台数据
- public void InitStageDisplay(CStage SStage, CSEMStageData SEMStageData)
- {
- m_visualStage. InitSampleStageData(SStage, SEMStageData,this.Width,this.Height);
-
-
- //清除所有绘制的图形信息
- ClearDrawInfo();
- //绘制样品台信息
- m_visualStage. DrawSampleStage();
-
- //标尺初始化
- RulerInit(m_visualStage.GetOTSSampleStageData());
-
- ShowRulerLocation();
- //图像隐藏
- HideMessureStatuWindowBSEImage(m_MeasureAppForm);
- //将测量结果信息状态初始化
- InitMeasureStateInfo();
-
-
- if (m_visualSamples.Count == 0)
- {
- //将测量状态初始化
- m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();
- }
-
- Invalidate();
- }
-
- public void HideMessureStatuWindowBSEImage(OTSIncAMeasureAppForm m_MeasureApps)
- {
- m_MeasureApps.m_MessureStatuWindow.pbBSEImage.Hide();
- }
- #region 将测量状态进度窗口信息初始化
- public void InitMeasureStateInfo()
- {
- m_MeasureAppForm.m_MeasureRetWindow.SetInit();
- }
- #endregion
-
- private void GetTriangleExcenterRadius(PointF px1, PointF px2, PointF px3, out float R, out PointF center)
- {
- float x1, y1, x2, y2, x3, y3;
- float a, b;
- x1 = px1.X;
- y1 = px1.Y;
- x2 = px2.X;
- y2 = px2.Y;
- x3 = px3.X;
- y3 = px3.Y;
- a = ((y2 - y1) * (y3 * y3 - y1 * y1 + x3 * x3 - x1 * x1) - (y3 - y1) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1)) / (2 * ((x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1)));
- b = ((x2 - x1) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1) - (x3 - x1) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1)) / (2 * ((y3 - y1) * (x2 - x1) - (y2 - y1) * (x3 - x1)));
- center = new PointF(a, b);
- R = (float)Math.Sqrt((x1 - a) * (x1 - a) + (y1 - b) * (y1 - b));
- }
-
- #region 窗体事件
- private void OTSSamplespaceWindow_Load(object sender, EventArgs e)
- {
-
- m_visualStage = new CVisualStage();
- m_visualSamples = new List<CVisualSampleArea>();
-
-
- //样品孔BSE图像
- m_ImageGDIObjects = new List<CRectangleGDIObject>();
- //BSE图像帧图为了获取位置与尺寸
- m_ImageOfFieldGDIObjects = new List<CRectangleGDIObject>();
-
- this.ResizeRedraw = true;
- control_Ruler2 = new Control_Ruler();
- Point rulerLocation = new Point(10, this.Height - (int)(control_Ruler2.Height * 2));
- control_Ruler2.Location = rulerLocation;
- this.Controls.Add(control_Ruler2);
- log = NLog.LogManager.GetCurrentClassLogger();
-
- }
- public static void SetShowCMStrip(ContextMenuType IsSelectType, ContextMenuStrip cmStrip, bool IsTrue)
- {
- switch (IsSelectType)
- {
- case ContextMenuType.SampleHoleMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SEMStripSeparator].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
- break;
- case ContextMenuType.SampleMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SEMStripSeparator].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
- break;
- case ContextMenuType.MeasureMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
-
-
- break;
- case ContextMenuType.FieldMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
-
-
- break;
- case ContextMenuType.ThreadRunMenu:
- for (int i = 0; i < cmStrip.Items.Count; i++)
- {
- cmStrip.Items[i].Enabled = false;
- }
- break;
- case ContextMenuType.SampleStateMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
- break;
- case ContextMenuType.SampleHoleBSEImage:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = IsTrue;
- break;
- }
- }
- private List<CRectangleGDIObject> GetAllVisualSampleGDIObject()
- {
- List<CRectangleGDIObject> allobj = new List<CRectangleGDIObject>();
- foreach (var s in m_visualSamples)
- {
- allobj.Add(s.GetSampleGDIObject());
- allobj.Add(s.GetMeasureGDIObject());
- foreach (var f in s.GetMeasureFieldGDIObjects())
- {
- allobj.Add(f);
- }
- }
- return allobj;
- }
- private List<CRectangleGDIObject> GetOnlyVisualSampleGDIObject()
- {
- List<CRectangleGDIObject> allobj = new List<CRectangleGDIObject>();
- foreach (var s in m_visualSamples)
- {
- allobj.Add(s.GetSampleGDIObject());
-
- }
- return allobj;
- }
- private List<CRectangleGDIObject> GetAllVisualFieldGdiObject()
- {
- List<CRectangleGDIObject> allobj = new List<CRectangleGDIObject>();
- foreach (var s in m_visualSamples)
- {
- allobj.Add(s.GetMeasureGDIObject());
- var flds = s.GetMeasureFieldGDIObjects();
- for(int i=flds.Count;i>0;i--)//revert the sequence so that the last field will paint first.then the green or yellow rectangle can display fully.
- {
- var f = flds[i-1];
- allobj.Add(f);
- }
- }
- return allobj;
- }
- private EnumMousePointPosition MousePointPosition(Point point, Point e)
- {
- //MouseDrag 中心
- if ((e.X == point.X) && (e.Y == point.Y))
- {
- return EnumMousePointPosition.MouseDrag;
- }
- //MouseSizeTopLeft 上左
- if ((e.X < point.X) && (e.Y < point.Y))
- {
- return EnumMousePointPosition.MouseSizeTopLeft;
- }
- //MouseSizeTopRight 下右
- if ((e.X > point.X) && (e.Y < point.Y))
- {
- return EnumMousePointPosition.MouseSizeTopRight;
- }
- //MouseSizeLeft 左侧
- if ((e.X < point.X) && (e.Y == point.Y))
- {
- return EnumMousePointPosition.MouseSizeLeft;
- }
- //MouseSizeRight 右侧
- if ((e.X > point.X) && (e.Y == point.Y))
- {
- return EnumMousePointPosition.MouseSizeRight;
- }
- //MouseSizeTop 上侧
- if ((e.X == point.X) && (e.Y < point.Y))
- {
- return EnumMousePointPosition.MouseSizeTop;
- }
- //MouseSizeBottom 下侧
- if ((e.X == point.X) && (e.Y > point.Y))
- {
- return EnumMousePointPosition.MouseSizeBottom;
- }
- //MouseSizeBottomRight 下左
- if ((e.X < point.X) && (e.Y > point.Y))
- {
- return EnumMousePointPosition.MouseSizeBottomLeft;
- }
- //MouseSizeBottomRight 下右
- if ((e.X > point.X) && (e.Y > point.Y))
- {
- return EnumMousePointPosition.MouseSizeBottomRight;
- }
- return EnumMousePointPosition.MouseSizeNone;
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- lblFocus.Focus();
-
- Point _Point ;
-
- //判断当前是否手绘
- if (m_IsDrawMeasure)
- {
- this.m_MouseDownPoint = new Point(e.X, e.Y);
- COTSSample workSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
- string sampleHoleName = workSample.GetSampleHoleName();
- string sampleName = workSample.GetName();
-
- //绘制多边形 测量区域
- if (m_DrawMeasureType == CreateRectangleType.Polygon)
- {
- if (m_DrawMeasureGDIObject == null)
- {
- m_DrawMeasureGDIObject = new CRectangleGDIObject(new List<PointF>(), CreateRectangleType.Polygon, (ShapeType)m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
- }
- var polygonPoints = m_DrawMeasureGDIObject.GetPolygonPointFList();
- if (m_IsDrawPolygonFinish)
- {
- DialogResult dResult = MessageBox.Show(table["message10"].ToString(), table["message11"].ToString(), MessageBoxButtons.YesNo);
- if (dResult == DialogResult.Yes)
- {
- Point startPoint = new Point((int)(polygonPoints[0].X), (int)(polygonPoints[0].Y));//the last point is the first point too.we get the first point as the last point.
- polygonPoints.Add(startPoint);
- CRectangleGDIObject polygonGdi =new CRectangleGDIObject (polygonPoints, CreateRectangleType.Polygon, (ShapeType)m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
- polygonGdi.SetZoomNumber(m_visualStage.GetZoomNum());
- polygonGdi.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
- polygonGdi.SetPolygonPointFList(polygonPoints);
-
- polygonGdi.IsWorkSample = true;
-
- var sam = GetVisualSampleByName(sampleName);
-
- sam.SetMeasureGDIObject(polygonGdi);
-
- m_DrawPolygonFinishGDIObject = null;
- m_DrawMeasureGDIObject = null;
- var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
- //-------------------- draw measrue field and save these data to sample
- m_MeasureAppForm.m_RunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- PrepareMeasureField(sam);
- //--------------------
- Invalidate();
-
-
-
- m_IsDrawMeasure = false;
- m_IsDrawPolygonFinish = false;
- this.Cursor = Cursors.Default;
- return;
- }
- else
- {
- return;
- }
- }
- polygonPoints.Add(m_MouseDownPoint);
- m_DrawMeasureGDIObject.SetPolygonPointFList(polygonPoints);
-
- return;
- }
- else if(m_DrawMeasureType == CreateRectangleType.CircleByThreePoints)
- {
- if (m_DrawMeasureGDIObject == null)
- {
- m_DrawMeasureGDIObject = new CRectangleGDIObject(new List<PointF>(), CreateRectangleType.Polygon, (ShapeType)m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
- }
- var m_PolygonPoint = m_DrawMeasureGDIObject.GetPolygonPointFList();
-
- m_PolygonPoint.Add(m_MouseDownPoint);
-
-
- if (m_PolygonPoint.Count == 3)//three point can make a circle .
- {
-
- m_DrawMeasureType = (int)CreateRectangleType.Circle;
- float r = 0;
- PointF Centerpoint ;
- GetTriangleExcenterRadius(m_PolygonPoint[0], m_PolygonPoint[1], m_PolygonPoint[2], out r, out Centerpoint);
-
- RectangleF rectangleThree = new RectangleF(new PointF(Centerpoint.X - r, Centerpoint.Y - r), new SizeF(r * 2, r * 2));
-
-
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectangleThree))
- {
- m_IsDrawMeasure = true;
- }
- else
- {
- m_IsDrawMeasure = false;
- return;
- }
- Color MeasureColor = Color.Red;
- CRectangleGDIObject CRectangleGDI =new CRectangleGDIObject (rectangleThree, CreateRectangleType.CircleByThreePoints, (ShapeType)m_DrawMeasureType, sampleName, sampleName, MeasureColor);
-
- m_DrawMeasureGDIObject=CRectangleGDI;
- m_DrawMeasureGDIObject.SetZoomNumber(m_visualStage.GetZoomNum());
- m_DrawMeasureGDIObject.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
- var sam1 = GetVisualSampleByName(sampleName);
- sam1.SetMeasureGDIObject(m_DrawMeasureGDIObject);
- sam1.GetMeasureGDIObject().SetZoomedRegionF(rectangleThree);
- m_DrawMeasureGDIObject = null;
- var para = m_visualStage.GetSampleMeasurePara(sam1.GetMeasureGDIObject());
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
- m_MeasureAppForm.m_RunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
-
- m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
- Invalidate();
-
- //设置手绘标识
- m_IsDrawMeasure = false;
- this.Cursor = Cursors.Default;
- return;
- }
- return;
- }
- else
- {
-
- var measureArea = new Rectangle(this.m_MouseDownPoint, new Size(2, 2));
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(measureArea))
- {
- m_IsDrawMeasure = true;
- }
- else
- {
- m_IsDrawMeasure = false;
- return;
- }
- int sizeWH = 5;
- Size size = new Size(sizeWH, sizeWH);
- Rectangle rectangle = new Rectangle(m_MouseDownPoint, size);
- Color MeasureColor = Color.Red;
- CRectangleGDIObject newGDI;
-
- newGDI = new CRectangleGDIObject(rectangle, CreateRectangleType.MeasureArea, (ShapeType)m_DrawMeasureType, sampleName, sampleName, MeasureColor);
-
- newGDI.SetZoomNumber(m_visualStage.GetZoomNum());
- newGDI.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
- m_DrawMeasureGDIObject = newGDI;
-
-
- return;
- }
- }
- else if(!m_IsDrawMeasure)
- {
- if (e.Button == MouseButtons.Right)
- {
- if (m_MeasureAppForm.MeasureThreadRunFlag)
- {
-
- SetShowCMStrip(ContextMenuType.ThreadRunMenu, CMStrip, false);
- _Point = this.PointToClient(Cursor.Position);
- this.CMStrip.Show(this, _Point);
- return;
- }
- //获取鼠标右键点击位置
- m_MouseDownPoint = e.Location;
-
-
- var sam2 = GetWorkingVisualSample();
- if (sam2 != null)
- {
- foreach (CRectangleGDIObject item in sam2.GetMeasureFieldGDIObjects())
- {
- if (item.IfZoomContains(e.Location))
- {
- //样品孔菜单
- _Point = this.PointToClient(Cursor.Position);
- bool IsTrue = false;
- //设置编辑右键菜单项
- foreach (CRectangleGDIObject imageItem in m_ImageGDIObjects)
- {
- if (imageItem.SampleName == item.SampleName)
- {
- IsTrue = true;
- break;
- }
- }
- //设置编辑右键菜单项
- SetShowCMStrip(ContextMenuType.FieldMenu, CMStrip, IsTrue);
- this.CMStrip.Show(this, _Point);
- return;
- }
- }
- }
-
-
- foreach(var item in m_visualSamples)
- {
- bool isSelMeasure = false;
- if (item.GetMeasureGDIObject().CreateType == CreateRectangleType.Polygon)
- {
-
- if(item.GetMeasureGDIObject().GetGPath().IsVisible(e.Location))
- {
- isSelMeasure = true;
- }
- }
- else
- {
- if (item.GetMeasureGDIObject().IfZoomContains(e.Location) /*&& !item.MeasureGDIObject.SelColor.Name.Equals("Transparent")*/)
- {
- isSelMeasure = true;
- int WH = 2;
- Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
-
- if (!m_visualStage.CheckMeasureAreaIsBeyondStageArea(rect))
- {
- break;
- }
- }
- }
- if (isSelMeasure)
- {
-
- //删除BSE照片
- bool IsTrue = false;
- //设置编辑右键菜单项
- foreach (CRectangleGDIObject imageItem in m_ImageGDIObjects)
- {
- if (imageItem.SampleName == item.GetSampleName())
- {
- IsTrue = true;
- break;
- }
- }
-
- //设置编辑右键菜单项
- SetShowCMStrip(ContextMenuType.MeasureMenu, CMStrip, IsTrue);
- _Point = this.PointToClient(Cursor.Position);
- this.CMStrip.Show(this, _Point);
-
- m_SampleHoleSelectName = item.GetMeasureGDIObject().NameOrHoleName;
- if (m_SampleSelectName != item.GetMeasureGDIObject().SampleName)
- {
- m_SampleSelectName = item.GetSampleName();
- //item.IsSelect = true;
- item.SetIsWorkSample(true);
- //设置工作样品
- m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
- Invalidate();
- }
- return;
- }
- }
-
- foreach (CRectangleGDIObject item in m_ImageGDIObjects)
- {
- if (item.IfZoomContains(e.Location))
- {
- //样品孔菜单
-
- _Point = this.PointToClient(Cursor.Position);
- //设置编辑右键菜单项
- SetShowCMStrip(ContextMenuType.SampleHoleBSEImage, CMStrip, false);
- this.CMStrip.Show(this, _Point);
- return;
- }
- }
- //只点击样品上(测量区域被移动到其他地方)
- for (int i = m_visualSamples.Count - 1; i >= 0; i--)
- {
- if (m_visualSamples[i].GetSampleGDIObject().IfZoomContains(e.Location))
- {
-
-
- //样品菜单
- var _IsSelectType =ContextMenuType.SampleMenu;
- //将删除样品与测量 设置为不可编辑状态
- _Point = this.PointToClient(Cursor.Position);
- bool flag = false;
-
- if (m_visualSamples[i].GetMeasureGDIObject().IfZoomContains(e.Location))
- {
- //测量区域菜单
- _IsSelectType = ContextMenuType.MeasureMenu;
-
- break;
- }
-
- //设置编辑右键菜单项
- SetShowCMStrip(_IsSelectType, CMStrip, flag);
- this.CMStrip.Show(this, _Point);
- if (m_SampleSelectName != m_visualSamples[i].GetSampleName())
- {
- m_SampleSelectName = m_visualSamples[i].GetSampleName();
- m_SampleHoleSelectName = m_visualSamples[i].GetMeasureGDIObject().NameOrHoleName;
-
- m_visualSamples[i].SetIsWorkSample(true);
-
- m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
- Invalidate();
- }
- return;
- }
- }
- //点击样品孔
-
- CRectangleGDIObject gdiitem;
- if (m_visualStage.IfMouseInSampleHole(e.Location,out gdiitem))
- {
-
-
-
- _Point = this.PointToClient(Cursor.Position);
- //设置编辑右键菜单项
- SetShowCMStrip(ContextMenuType.SampleHoleMenu, CMStrip, false);
- //将删除样品与测量 设置为不可编辑状态
- this.CMStrip.Show(this, _Point);
-
- m_SampleHoleSelectName = gdiitem.NameOrHoleName;
-
- return;
- }
-
-
- if (m_visualStage.IfMouseInStage(e.Location))
- {
-
- //设置编辑右键菜单项
- SetShowCMStrip(ContextMenuType.SampleStateMenu, CMStrip, false);
- _Point = this.PointToClient(Cursor.Position);
- this.CMStrip.Show(this, _Point);
- return;
- }
-
- return;
- }
- else if(e.Button == MouseButtons.Left)
- {
- //如果正在进行测量线程,则退出鼠标点击操作
- if (m_MeasureAppForm.MeasureThreadRunFlag)
- {
- return;
- }
-
- CRectangleGDIObject stageobj;
- if (m_visualStage.IfMouseInStage(e.Location, out stageobj))
- {
-
- MouseDownFunction(m_visualStage.GetAllGDIObject(), e);
- //样品
- MouseDownFunction(GetAllVisualSampleGDIObject(), e);
- //样品台中BSE图片
- MouseDownFunction(m_ImageGDIObjects, e);
- }
- //测量区域
- if (Control.ModifierKeys == Keys.Control)// ctrl key is pressed,means changing position or altering the visual sample area.
- {
- var sam = GetWorkingVisualSample();
- if (sam != null)
- {
- var item = sam.GetMeasureGDIObject();
-
- var selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
- if (selWSampleMeasureStatus)
- {
- return;
- }
-
- if (item.CreateType == CreateRectangleType.Polygon)
- {
-
- bool isSelPolygonPoint = false;
- foreach (PointF itemPoint in item.GetPolygonPointFList())
- {
- if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)
- {
-
- isSelPolygonPoint = true;
-
- item.SelColor = Color.Red;
-
- item.DraggingPoint = new PointF(itemPoint.X,itemPoint .Y);//e.Location;
- item.IsAltering = true;//this state means operator want to alter the size of the polygon shape.
-
- item.IsDragging = false;
- break;
-
- }
- }
- if (!isSelPolygonPoint)//not selecting the polygon point,just dragging on the inside area of the polygon shape.
- {
- if (item.GetGPath().IsVisible(e.Location))
- {
- item.SelColor = Color.Red;
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
-
- item.IsAltering = false;
- }
- }
-
-
- }
- else
- {
-
- if (item.GetGPath().IsOutlineVisible((float)e.X, (float)e.Y, new Pen(Color.Gray, m_PenWidth)))
- {
-
- item.SelColor = Color.Red;
- item.IsDragging = false;
- item.DraggingPoint = e.Location;
- item.IsAltering = true;
-
- }
- else//not outlinevisible then is altering sample area position.
- {
- if (item.IfZoomContains(e.Location))
- {
-
- item.SelColor = Color.Red;
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
- item.IsAltering = false;
- }
- }
-
- }
-
- }
- }
- //click on the sample area without ctrl key,just switch to that sample.
- if (!(Control.ModifierKeys == Keys.Control))
- {
- for (int i = m_visualSamples.Count - 1; i >= 0; i--)
- {
- var sam1 = m_visualSamples[i];
-
- if (sam1.GetSampleGDIObject().IfZoomContains(e.Location)|| sam1.GetMeasureGDIObject().IfZoomContains(e.Location))
- {
- NLog.LogManager.GetCurrentClassLogger().Info(sam1.GetMeasureGDIObject().GetOrigionalDrawRegionF().ToString());
- var measureItem = sam1.GetMeasureGDIObject();
- measureItem.SelColor = Color.Red;
- //设置为工作样品
- sam1.SetIsWorkSample(true);
-
- //获取颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- sam1.GetSampleGDIObject().SelColor = ColorTranslator.FromHtml(ColorStr);
- m_SampleSelectName = sam1.GetSampleName();
- m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
- break;
- }
- }
-
- }
-
-
-
- }
- }
- //重绘控件
- Invalidate();
- }
-
- protected override void OnMouseMove(MouseEventArgs e)
- {
-
- if (m_MeasureAppForm.MeasureThreadRunFlag)
- {
- return;
- }
-
- if (m_IsDrawMeasure)
- {
- this.m_MouseMovePoint = new Point(e.X, e.Y);
- if (m_DrawMeasureGDIObject == null) return;//the object must be initialized by mousedown event.
- //绘制多边形
- if (m_DrawMeasureType == CreateRectangleType.Polygon)
- {
-
- m_DrawMeasureGDIObject.PolygonDrawingEndPoint = this.m_MouseMovePoint;
- var m_PolygonPoint = m_DrawMeasureGDIObject.GetPolygonPointFList();
- //显示直线开始点与鼠标当前位置的直线
- PointF startPoint = new PointF();
- if (m_PolygonPoint.Count > 0)
- {
- startPoint = m_PolygonPoint[0];
-
- }
- //显示绘制多边形完成标识
- if (m_PolygonPoint.Count > m_PolygonMinPointCount)
- {
- if (Math.Abs(m_MouseMovePoint.X - startPoint.X) <= m_OffsetPX && Math.Abs(m_MouseMovePoint.Y - startPoint.Y) <= m_OffsetPX)
- {
- //显示绘制多边形完成标识
- m_IsDrawPolygonFinish = true;
- int rectSize = m_MinMeasureWidthValue;
- if (m_DrawPolygonFinishGDIObject == null)
- {
- Point PolygonFinishPoint = new Point((int)(startPoint.X - m_MinMeasureWidthValue / 2), (int)(startPoint.Y - m_MinMeasureWidthValue / 2));
- Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));
- CRectangleGDIObject createPolygonFinish = new CRectangleGDIObject(pRect, CreateRectangleType.DrawPolygonFinish, "", "", Color.Green);
- m_DrawPolygonFinishGDIObject = createPolygonFinish;
- }
- }
- else
- {
- m_DrawPolygonFinishGDIObject = null;
- m_IsDrawPolygonFinish = false;
- }
- }
-
- }
- //圆形三点法
- else if (m_DrawMeasureType == CreateRectangleType.CircleByThreePoints)
- {
- m_DrawMeasureGDIObject.PolygonDrawingEndPoint = this.m_MouseMovePoint;
-
- }
- else
- {
- if (m_DrawMeasureGDIObject == null )
- {
- return;
- }
-
-
-
- RectangleF rectangle = m_DrawMeasureGDIObject.GetZoomedRegion;
- int tmp = (int)Math.Sqrt((m_MouseDownPoint.X - m_MouseMovePoint.X) * (m_MouseDownPoint.X - m_MouseMovePoint.X) + (m_MouseDownPoint.Y - m_MouseMovePoint.Y) * (m_MouseDownPoint.Y - m_MouseMovePoint.Y));
- if (tmp == 0)
- {
- tmp = m_DValue;
- }
-
- EnumMousePointPosition enumMouse = MousePointPosition(m_MouseDownPoint, m_MouseMovePoint);
- Point LTPoint = new Point();
- Size RBSize = new Size();
- switch (enumMouse)
- {
- case EnumMousePointPosition.MouseSizeTopLeft:
- if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
- {
- LTPoint.X = m_MouseDownPoint.X - tmp;
- LTPoint.Y = m_MouseDownPoint.Y - tmp;
- RBSize.Width = tmp;
- RBSize.Height = tmp;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- else
- {
- LTPoint.X = m_MouseMovePoint.X;
- LTPoint.Y = m_MouseMovePoint.Y;
- RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
- RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- break;
- case EnumMousePointPosition.MouseSizeTopRight:
- if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
- {
- LTPoint.X = m_MouseDownPoint.X;
- LTPoint.Y = m_MouseDownPoint.Y - tmp;
- RBSize.Width = tmp;
- RBSize.Height = tmp;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- else
- {
- LTPoint.X = m_MouseDownPoint.X;
- LTPoint.Y = m_MouseDownPoint.Y - (m_MouseDownPoint.Y - m_MouseMovePoint.Y);
- RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
- RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- break;
- case EnumMousePointPosition.MouseSizeBottomLeft:
- if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
- {
- LTPoint.X = m_MouseDownPoint.X - tmp;
- LTPoint.Y = m_MouseDownPoint.Y;
- RBSize.Width = tmp;
- RBSize.Height = tmp;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- else
- {
- LTPoint.X = m_MouseDownPoint.X - (m_MouseDownPoint.X - m_MouseMovePoint.X);
- LTPoint.Y = m_MouseDownPoint.Y;
- RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
- RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- break;
- case EnumMousePointPosition.MouseSizeBottomRight:
- if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
- {
- LTPoint.X = m_MouseDownPoint.X;
- LTPoint.Y = m_MouseDownPoint.Y;
- RBSize.Width = tmp;
- RBSize.Height = tmp;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- else
- {
- LTPoint.X = m_MouseDownPoint.X;
- LTPoint.Y = m_MouseDownPoint.Y;
- RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
- RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- break;
- }
- //在样品台内部缩放
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectangle))
- {
-
- var rec= new Rectangle(LTPoint, RBSize);
- m_DrawMeasureGDIObject.SetZoomedRegionF(new RectangleF(new PointF((rec.X), (rec.Y) ), new SizeF(rec.Width, rec.Height)));
-
- }
-
- }
- }
-
- if (Control.ModifierKeys == Keys.Control)//is dragging on the edge or on the vertex so we can alter the size of the item.
- {
- var sam = GetWorkingVisualSample();
-
- var curMeasureGdi = sam.GetMeasureGDIObject();
-
- if (curMeasureGdi.IsAltering)//click on the edge or on the polygon point( vertex point of rectangle).
- {
- if (curMeasureGdi.CreateType == CreateRectangleType.Polygon)
- {
-
-
- for (int i = 0; i < curMeasureGdi.GetPolygonPointFList().Count; i++)
- {
- if (curMeasureGdi.GetPolygonPointFList()[i].X == curMeasureGdi.DraggingPoint.X && curMeasureGdi.GetPolygonPointFList()[i].Y == curMeasureGdi.DraggingPoint.Y)
- {
- //移动点的位置
- RectangleF selPolygonPointRect = new RectangleF(0, 0, 2, 2);
- selPolygonPointRect.X = curMeasureGdi.DraggingPoint.X + e.X - curMeasureGdi.DraggingPoint.X;
- selPolygonPointRect.Y = curMeasureGdi.DraggingPoint.Y + e.Y - curMeasureGdi.DraggingPoint.Y;
- //判断样品是否超越样品台
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(selPolygonPointRect))
- {
- List<PointF> polygonPs = curMeasureGdi.GetPolygonPointFList();
- if (i == 0 || i == curMeasureGdi.GetPolygonPointFList().Count - 1)
- {
- curMeasureGdi.DraggingPoint = new Point(e.X, e.Y);
- polygonPs [0] = curMeasureGdi.DraggingPoint;
- polygonPs[curMeasureGdi.GetPolygonPointFList().Count - 1] = curMeasureGdi.DraggingPoint;//the last point and the first point of one polygon object are the same.
-
- }
- else
- {
- curMeasureGdi.DraggingPoint = new Point(e.X, e.Y);
-
- polygonPs[i] = curMeasureGdi.DraggingPoint;
-
- }
- curMeasureGdi.SetPolygonPointFList(polygonPs);
- curMeasureGdi.DraggingPoint = e.Location;
- break;
- }
- }
- }
-
-
-
- }
- else
- {
- if (curMeasureGdi.Shape == ShapeType.RECTANGLE)
- {
- List<PointF> vertexPoint = curMeasureGdi.GetVertexPoints();
- var oldRegion = curMeasureGdi.GetZoomedRegionF();
- for (int i=0;i< vertexPoint.Count;i++)
- {
- var itemPoint = vertexPoint[i];
- PointF lefttop,leftBottom,rightTop,rightBottom;
- float width;
- float height;
- if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)
- {
- switch (i)
- {
- case 0://left top point
- lefttop = new PointF(e.X, e.Y);
- width = vertexPoint[2].X - e.X;
- height = vertexPoint[1].Y - e.Y;
- curMeasureGdi.SetZoomedRegionF(new RectangleF(lefttop, new SizeF(width, height)));
- break;
- case 1://left bottom
- leftBottom = new PointF(e.X, e.Y);
- width = vertexPoint[3].X - e.X;
- height = -(vertexPoint[0].Y - e.Y);
- curMeasureGdi.SetZoomedRegionF(new RectangleF(new PointF(leftBottom.X,leftBottom.Y-height), new SizeF(width, height)));
- break;
-
- case 2://right top
- rightTop = new PointF(e.X, e.Y);
- width = -(vertexPoint[0].X - e.X);
- height = (vertexPoint[3].Y - e.Y);
- curMeasureGdi.SetZoomedRegionF(new RectangleF(new PointF(rightTop.X-width, rightTop.Y ), new SizeF(width, height)));
- break;
- case 3://right bottom
- rightBottom = new PointF(e.X, e.Y);
- width = (e.X-vertexPoint[0].X );
- height = ( e.Y-vertexPoint[0].Y);
- curMeasureGdi.SetZoomedRegionF(new RectangleF(new PointF(rightBottom.X-width, rightBottom.Y - height), new SizeF(width, height)));
- break;
- }
-
- Invalidate();
- }
- }
- }
- else
- {
- PointF gdicenter = m_visualStage.GetCenterPoint(curMeasureGdi.GetZoomedRegion);
- //获取鼠标坐标
- PointF mousePoint = e.Location;
- RectangleF rectTemp;
- //计算偏离半径
- float a = (gdicenter.X - mousePoint.X) * (gdicenter.X - mousePoint.X);
- float b = (gdicenter.Y - mousePoint.Y) * (gdicenter.Y - mousePoint.Y);
- float c = a + b;
- double r = System.Math.Sqrt(c);
- float width = (float)r * 2;
- rectTemp = new RectangleF(gdicenter.X - (float)r, gdicenter.Y - (float)r, width, width);
-
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectTemp))
- {
- //如果大于最小测量高度 设置图形大小
- if (rectTemp.Width / curMeasureGdi.GetZoomNumber() > m_MinMeasureWidthValue)
- {
- curMeasureGdi.SetZoomedRegionF(rectTemp);
- curMeasureGdi.DraggingPoint = e.Location;
- }
- }
- else
- {
- return;
- }
- Invalidate();
- return;
- }
-
- }
-
- }
- else if(curMeasureGdi.IsDragging)
- {
- if (curMeasureGdi.GetGPath().IsVisible(e.Location))
- {
- curMeasureGdi.PositionAltering(e.Location,true);
- }
-
- }
-
- }
- else
- {
-
-
- //样品台
- MouseMoveFucntion(m_visualStage.GetAllGDIObject(), e);
-
- //样品
- MouseMoveFucntion(GetAllVisualSampleGDIObject(), e);
- //样品孔BSE图片
- MouseMoveFucntion(m_ImageGDIObjects, e);
-
- }
-
- //显示XY轴
- m_visualStage.ShowSemCoordvAL(e.Location, m_MeasureAppForm);
- Invalidate();
- }
-
- protected override void OnMouseUp(MouseEventArgs e)
- {
- //如果正在进行测量线程,则退出鼠标点击操作
- if (m_MeasureAppForm.MeasureThreadRunFlag)
- {
- return;
- }
- //判断当前是否手绘
- if (m_IsDrawMeasure)
- {
- //绘制多边形
- if (m_DrawMeasureType != CreateRectangleType.Polygon && m_DrawMeasureType != CreateRectangleType.CircleByThreePoints)
- {
- var item = m_DrawMeasureGDIObject;
- //获取样品孔名称与其他属性
- var sam = GetVisualSampleByName(item.SampleName);
- item.NameOrHoleName = sam.GetMeasureGDIObject().NameOrHoleName;
-
- item.IsWorkSample = sam.GetMeasureGDIObject().IsWorkSample;
-
- sam.GetMeasureFieldGDIObjects().Clear();
- sam.SetMeasureGDIObject(item);
- var para = m_visualStage.GetSampleMeasurePara(item);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- m_MeasureAppForm.m_RunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- PrepareMeasureField(sam);
- m_DrawMeasureGDIObject = null;
-
- this.Cursor = Cursors.Default;
- //设置手绘标识
-
- m_IsDrawMeasure = false;
- }
- }
-
- if (Control.ModifierKeys == Keys.Control)//while pressing ctrl key then it must be altering something(position or size)
- {
-
- var selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
- if (selWSampleMeasureStatus)
- {
- return;
- }
- var sam = GetWorkingVisualSample();
- if (sam == null)
- {
- return;
- }
- var measureItem = sam.GetMeasureGDIObject();
-
- var para = m_visualStage.GetSampleMeasurePara(measureItem);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);//set the altering result to the public parameter object
-
- this.Cursor = System.Windows.Forms.Cursors.Default;
-
- m_MeasureAppForm.m_RunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- PrepareMeasureField(sam);
- measureItem.IsAltering = false;
- measureItem.IsDragging = false;
- Invalidate();
- }
- //only moving the whole stage
- MouseUpFucntion(m_visualStage.GetAllGDIObject(), e);
- //样品
- MouseUpFucntion(GetAllVisualSampleGDIObject(), e);
-
-
-
- //样品孔中BSE图片
- MouseUpFucntion(m_ImageGDIObjects, e);
-
-
- }
- protected override void OnPaint(PaintEventArgs e)//处理重绘情况
- {
-
- OnPaint(e, m_visualStage.GetAllGDIObject());
-
- OnPaint(e, GetOnlyVisualSampleGDIObject());
- if (IsShowSampleHoleImage)
- {
- if (m_ImageGDIObjects.Count > 0)
- {
- OnPaint(e, m_ImageGDIObjects);
- }
- }
- OnPaint(e, GetAllVisualFieldGdiObject());
- if (m_DrawMeasureGDIObject != null)
- {
-
- m_DrawMeasureGDIObject.OnPaint(e);
- }
-
-
- if(m_DrawPolygonFinishGDIObject!=null) m_DrawPolygonFinishGDIObject.OnPaint(e);
-
- }
- public void OnPaint(PaintEventArgs e, List<CRectangleGDIObject> m_ObjectGDIObjects)//处理重绘情况
- {
- foreach (CRectangleGDIObject item in m_ObjectGDIObjects)
- {
- if (item != null)
- {
- item.OnPaint(e);
- }
- }
- }
- protected override void OnMouseWheel(MouseEventArgs e)
- {
- var m_GlobalZoomNum = m_visualStage.GetZoomNum();
- //如果正在进行测量线程,则退出鼠标点击操作
- if (m_MeasureAppForm.MeasureThreadRunFlag)
- {
- return;
- }
- if (e.Delta > 0)
- {
- #region 计算标尺尺寸部份-----放大------
- //计算标尺实际占用像素的宽度
- f_ruler_size = f_old_ruler_size * m_GlobalZoomNum;
- control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
- control_Ruler2.Value = 1;
- //放大过长时,这里将宽度与代表的实际宽度进行折半显示
- while (control_Ruler2.Width > 300)
- {
- control_Ruler2.RulerWidth = Convert.ToInt32(control_Ruler2.RulerWidth) / 2;
- control_Ruler2.Value = control_Ruler2.Value * 2;
- }
- control_Ruler2.SetValue(control_Ruler2.RulerWidth, control_Ruler2.Value.ToString());
- #endregion
- }
- else
- {
- if (m_GlobalZoomNum >= f_zoom_mix)
- {
- #region 计算标尺尺寸部份-----缩小
- f_ruler_size = f_old_ruler_size * m_GlobalZoomNum;
- control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
- control_Ruler2.Value = 1;
- while (control_Ruler2.Width > 300)
- {
- control_Ruler2.RulerWidth = Convert.ToInt32(control_Ruler2.RulerWidth) / 2;
- control_Ruler2.Value = control_Ruler2.Value * 2;
- }
- control_Ruler2.SetValue(control_Ruler2.RulerWidth, control_Ruler2.Value.ToString());
- #endregion
- }
- }
- //设置记录每次比例缩放后的总体比例系数
- if (e.Delta > 0)
- {
- m_GlobalZoomNum += 0.1f;
-
- }
- else
- {
- m_GlobalZoomNum -= 0.1f;
- if (m_GlobalZoomNum < 1)
- {
- m_GlobalZoomNum = 1;
- }
-
- if (m_GlobalZoomNum == 1)
- {
-
- //标尺恢复初始
- f_ruler_size = f_old_ruler_size;
- control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
- control_Ruler2.ShowString = "1mm";
- control_Ruler2.SetValue(control_Ruler2.RulerWidth);
- }
- }
- MouseWheelFunction(m_ImageGDIObjects, e.Location, m_GlobalZoomNum);
- MouseWheelFunction(GetAllVisualSampleGDIObject(), e.Location, m_GlobalZoomNum);
- //样品孔
- MouseWheelFunction(m_visualStage.GetAllGDIObject(), e.Location, m_GlobalZoomNum);
- base.OnMouseWheel(e);
- //重新绘制
- Invalidate();
- }
- private void MouseWheelFunction(List<CRectangleGDIObject> objList, Point mousePoint, float ZoomNum)
- {
-
- for (int i = 0; i < objList.Count; i++)
- {
-
- objList[i].Zoom(mousePoint, ZoomNum);
- }
- }
- #endregion
- #region 鼠标方法操作
- public void MouseDownFunction(List<CRectangleGDIObject> objList, MouseEventArgs e)
- {
- foreach (CRectangleGDIObject item in objList)
- {
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
- }
- }
- public void MouseMoveFucntion(List<CRectangleGDIObject> objList, MouseEventArgs e)
- {
- foreach (CRectangleGDIObject item in objList)
- {
- if (item.IsDragging)
- {
-
- item.Move(e.Location);
-
- }
- }
- }
-
-
- public void MouseUpFucntion(List<CRectangleGDIObject> objList, MouseEventArgs e)
- {
- foreach (CRectangleGDIObject item in objList)
- {
- if (item.IsDragging)
- {
-
- item.IsDragging = false;
- item.DraggingPoint = Point.Empty;
-
- }
- }
- }
-
-
- #endregion
-
- private void DeleteSampleInfo( string sampleSelectName)
- {
-
- if (ShowDeleteDialog(sampleSelectName))
- {
- //设置当前状态
- m_MeasureAppForm.m_RunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- m_MeasureAppForm.DeleteSample(sampleSelectName);
-
- }
- return ;
-
- }
- private bool ShowDeleteDialog(string sampleName)
- {
- //国际化
- OTSCommon.Language lan = new OTSCommon.Language();
- Hashtable table = lan.GetNameTable("OTSIncAMeasureAppForm");
- string str1 = table["message5"].ToString();
- string str2 = table["message6"].ToString();
- string sDeleteSampleName = str1;
- sDeleteSampleName += sampleName;
- sDeleteSampleName += " 信息 ?";
- if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Delete sample information prompt", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool setSlopFocusParam(_5_OTSMeasureStatuImageFun.SlopFocus slopFocus)
- {
- if (slopFocus == null)
- {
- return false;
- }
- else
- {
- m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().SlopParam = slopFocus.GetCSlopFocusParam();
- return true;
- }
- }
- protected override bool ProcessDialogKey(Keys keyData)
- {
- if (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Left || keyData == Keys.Right)
- {
- return false;
- }
- else
- {
- return base.ProcessDialogKey(keyData);
- }
- }
- private void OTSSamplespaceWindow_KeyDown(object sender, KeyEventArgs e)
- {
- KeyDowns();
- }
- private void OTSSamplespaceWindow_KeyUp(object sender, KeyEventArgs e)
- {
- //键盘抬起时,将选择区域的标识 设置为未选择状态
- this.Cursor = System.Windows.Forms.Cursors.Default;
-
- this.Invalidate();
-
- }
- public void KeyDowns()
- {
- //鼠标相对于屏幕的坐标
- Point p1 = MousePosition;
- //鼠标相对于窗体的坐标
- Point mousePoint = this.PointToClient(p1);
- Pen GrayPen = new Pen(Color.Gray, m_PenWidth);
- //设置鼠标在样品测量区域上的样式
- foreach (var sam in m_visualSamples)
- {
- var item = sam.GetMeasureGDIObject();
-
-
- if (item.GetGPath() != null)
- {
- if (item.CreateType == CreateRectangleType.Polygon)
- {
- //在多边形点附近切换光标
- foreach (PointF itemPoint in item.GetPolygonPointFList())
- {
- if (Math.Abs(itemPoint.X - mousePoint.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - mousePoint.Y) <= m_OffsetPX)
- {
- if (Control.ModifierKeys == Keys.Control)
- {
- this.Cursor = System.Windows.Forms.Cursors.Hand;
- return;
- }
- }
- }
-
- if (item.GetGPath().IsVisible(mousePoint))
- {
- if (Control.ModifierKeys == Keys.Control)
- {
- this.Cursor = System.Windows.Forms.Cursors.SizeAll;
- return;
- }
- }
-
- }
- else
- {
- if (item.GetGPath().IsOutlineVisible(mousePoint, GrayPen))
- {
- if (item.Shape == ShapeType.RECTANGLE)
- {
- List<PointF> vertexPoint = item.GetVertexPoints();
-
- foreach (PointF itemPoint in vertexPoint)
- {
- if (Math.Abs(itemPoint.X - mousePoint.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - mousePoint.Y) <= m_OffsetPX)
- {
- if (Control.ModifierKeys == Keys.Control)
- {
- this.Cursor = System.Windows.Forms.Cursors.Hand;
- return;
- }
- }
- }
- }
- else
- {
- if (Control.ModifierKeys == Keys.Control)
- {
- this.Cursor = System.Windows.Forms.Cursors.NoMove2D;
- return;
- }
- }
- }
- if (item.IfZoomContains(mousePoint))
- {
-
- if (Control.ModifierKeys == Keys.Control)
- {
- this.Cursor = System.Windows.Forms.Cursors.SizeAll;
- return;
- }
-
- }
- }
-
-
-
-
- }
- }
- //设置鼠标在样品上的样式
- foreach (var sam in m_visualSamples)
- {
- var item = sam.GetSampleGDIObject();
- if (!item.SelColor.Name.Equals("Transparent"))
- {
- if (item.IfZoomContains(mousePoint))
- {
- if ((Control.ModifierKeys == Keys.Alt))
- {
-
- this.Cursor = System.Windows.Forms.Cursors.SizeAll;
- return;
-
- }
- }
- }
- }
- }
- public void KeyUps()
- {
- this.Cursor = System.Windows.Forms.Cursors.Default;
- }
-
- #region 处理方法总汇
- #region 清除所需图形
-
- public void ClearDrawInfo()
- {
- try
- {
-
- m_visualStage.cleargdiobj();
-
- m_visualSamples.Clear();
- if (m_ImageGDIObjects != null)
- {
- m_ImageGDIObjects.Clear();
- }
- if (m_ImageOfFieldGDIObjects != null)
- {
- m_ImageOfFieldGDIObjects.Clear();
- }
- if (m_DrawMeasureGDIObject != null)
- {
- m_DrawMeasureGDIObject = null;
- }
- }
- catch (Exception ex)
- {
-
- log.Error( ex.ToString() );
- }
- }
- #endregion
- #endregion
-
-
-
-
- #region 绘制样品以及测量区域
- /// <summary>
- /// 绘制样品以及测量区域
- /// </summary>
- /// <param name="SMeasrueAreaList">测量区域的集合</param>
- public void DrawSampleAndMeasureInfo(SampleMeasurePara SMeasrueArea)
- {
-
- var item = m_visualStage.GetHoleGDIByHoleName(SMeasrueArea.sampleHoleName);
- if (item!=null)
- {
- CVisualSampleArea sam;
- if (AddVisualSample(SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName,out sam))
- {
-
-
- if (SMeasrueArea.iShape ==(ShapeType) CreateRectangleType.Polygon)
- {
-
-
- var ps = new List<PointF>();
- foreach (var p in SMeasrueArea.DrawPolygonPointList)
- {
- var ctrlcoordPoint = m_visualStage.OTSCoordToCtrlCoord(p);
- ps.Add(ctrlcoordPoint);
-
- }
-
- CRectangleGDIObject polygongdi =new CRectangleGDIObject (ps, CreateRectangleType.Polygon, (ShapeType)SMeasrueArea.iShape, SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, Color.Red);
-
- sam.SetMeasureGDIObject(polygongdi);
- PrepareMeasureField(sam);
-
- }
- else
- {
- PointF xHole = new PointF(SMeasrueArea.MeasureRect.Left, SMeasrueArea.MeasureRect.Top);
- PointF yHole = new PointF(SMeasrueArea.MeasureRect.Right, SMeasrueArea.MeasureRect.Bottom);
- CRectangleGDIObject gdi = m_visualStage.GetCtrlCoordRect(xHole,yHole, (CreateRectangleType)SMeasrueArea.iShape, "", "");
- gdi.SampleName = SMeasrueArea.sSampleName;
- gdi.NameOrHoleName = SMeasrueArea.sampleHoleName;
- gdi.Shape =SMeasrueArea.iShape;
- CRectangleGDIObject measureGdi;
- if (m_visualStage. GetMeasureGdiObjectFromSampleGdi( gdi,out measureGdi))
- {
-
- sam.SetMeasureGDIObject(measureGdi);
- PrepareMeasureField(sam);
- }
- }
- COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();
-
- List<PointF> CompleteFieldList = cProjMgr.GetSampleByName(SMeasrueArea.sSampleName).GetMsrStatus().GetCompletedFieldsCenter();
- if (CompleteFieldList .Count> 0)
- {
-
-
- ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, sam );
- }
- }
- }
-
- }
- #endregion
- #region 获取帧图信息
- public void ReadSEMDataFromSEM()
- {
-
-
- List<double> semParameters ;
-
-
- #region 获取电镜参数
- ////获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- //获取电镜参数 放大倍数与工作距离 [Magnification]:放大倍数 [WorkingDistance]工作距离
- semParameters = m_SEMDATAFieldManage.GetSEMMagAndWDParameter();
- double mag = semParameters[0];
- double wd = semParameters[1];
- if (mag != 0 && wd != 0)
- {
- //设置样品文件中的电镜参数
- m_MeasureAppForm.m_ProjParam.SetWorkingSampleSEMData(wd, mag);
-
- //将右键SEM数据菜单设置为可编辑状态
- CMStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
-
- }
-
- }
-
- #endregion
-
-
- }
- #region 获取Filed帧图
- public List<CRectangleGDIObject> GetOTSFieldVisualRects(CVisualSampleArea sam)
- {
- List<Point> listCenterPoint ;
- Size rectSize ;
-
- var m_ResultData = m_MeasureAppForm.m_ProjParam.GetResultData();
- var sample = m_ResultData.GetSampleByName(sam.GetSampleName());
- List<CRectangleGDIObject> visualfieldRects = new List<CRectangleGDIObject>();
- if (GetFieldData(sample,out listCenterPoint, out rectSize))
- {
-
- for (int i=0;i< listCenterPoint.Count;i++)
- {
- //convert the center point to leftTop point of rectangle.
- Point otsPoint = listCenterPoint[i];
- int left = otsPoint.X - rectSize.Width / 2;
- int top = otsPoint.Y - rectSize.Height / 2;//the ots coordinate is leftbottom is (0,0),but the control coordinate is leftTop is (0,0),so here use minus.
- var rect=new Rectangle(new Point(left,top), rectSize);
- Point lt = new Point(rect.Left, rect.Top);
- Point rb = new Point(rect.Right, rect.Bottom);
- RectangleF visualRect = m_visualStage.GetCtrlCoordRectF(lt, rb);
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);
- string sampleName = sam.GetSampleName();
- string sampleHoleName = sam.GetSampleGDIObject().NameOrHoleName;
- CRectangleGDIObject createRect = new CRectangleGDIObject(visualRect, otsPoint.X, otsPoint.Y, CreateRectangleType.FieldRectangle, sampleHoleName, sampleName, ColorTranslator.FromHtml(ColorStr));
- visualfieldRects.Add(createRect);
- }
- }
- return visualfieldRects;
- }
- public bool GetFieldData(COTSSample sample, out List<Point> pFields, out Size iSzie)
- {
- pFields = new List<Point>();
- iSzie = new Size();
-
- COTSSample WSample = sample;
- if (null == WSample)
- {
- return false;
- }
-
- CDomain pMsrArea = WSample.GetMsrArea();
-
- COTSImgScanPrm pImgScanParam = WSample.GetMsrParams().GetImageScanParam();
-
- CFieldPositionMgr pFieldMgr = new CFieldPositionMgr();
- List<PointF> listPoint = new List<PointF>();
- listPoint.Clear();
- //设置测量区域
- CSEMDataMsr pSEMDataMsr; ;
- if (m_MeasureAppForm.m_RunType == MSR_THREAD_RunSTATUS.RUNSampleHoleImage)
- {
- pSEMDataMsr = new CSEMDataMsr();
- pSEMDataMsr.SetScanFieldSize100(m_visualStage.GetOTSSampleStageData().iScanFieldSize100);
- double dMagnification = m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetStageDataParam().GetMinMag();//using the min mag to photo the hole image.
- pSEMDataMsr.SetMagnification(dMagnification);
- }
- else
- {
- pSEMDataMsr = WSample.GetSEMDataMsr();
- }
-
- //calculate all the field position point in OTS coordination.
- if (!pFieldMgr.Init(pMsrArea, pImgScanParam, pSEMDataMsr, listPoint))
- {
- return false;
- }
- pFields = pFieldMgr.GetFieldCentrePoints();
-
- var oValue = new Rectangle();
- if (!pFieldMgr.GetFieldRectByIndex(0, ref oValue))
- {
- return false;
- }
- iSzie = oValue.Size;
-
- return true;
- }
- #endregion
- public void PrepareMeasureField(CVisualSampleArea sam)
- {
-
- try
- {
-
- List<CRectangleGDIObject> visualfieldRects = null;
- visualfieldRects = GetOTSFieldVisualRects(sam);//get all the possible field rects through C++ code.
- if (m_MeasureAppForm.m_RunType == MSR_THREAD_RunSTATUS.RUNSampleHoleImage)
- {
- foreach (var r in visualfieldRects)
- {
- r.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
- r.SetZoomNumber(m_visualStage.GetZoomNum());
- m_ImageOfFieldGDIObjects.Add(r);
- }
-
- }
- else if (m_MeasureAppForm.m_RunType == MSR_THREAD_RunSTATUS.RUNMEASURE)
- {
-
- sam.GetMeasureGDIObject().SubItems().Clear();
- //添加帧图列表
- int sequenceNum=0;
- for (int i=0;i<visualfieldRects.Count;i++)
- {
- var r = visualfieldRects[i];
- if (sam.GetMeasureGDIObject().ifRectangleIntersect(r))//filter the unmeasure fields
- {
- r.SequenceNum = sequenceNum++;
- sam.AddFieldGDIObject(r);
- }
-
- }
- SaveFieldPositionInfoToSample(sam);
- m_MeasureAppForm.UpdatePropertyVal();
- }
-
- }
- catch (Exception ex)
- {
- log.Error( ex.ToString());
- }
- }
- public void SaveFieldPositionInfoToSample(CVisualSampleArea sam)
- {
- var m_ResultData = m_MeasureAppForm.m_ProjParam.GetResultData();
- var sample = m_ResultData.GetSampleByName(sam.GetSampleName());
- var fields = sam.GetMeasureFieldGDIObjects();
- sample.ClearFields();
- for (int i=0;i<fields.Count;i++ )
- {
- var f = fields[i];
- var otsPoint = new Point(f.OTSX, f.OTSY);
- sample.AddFieldData(otsPoint);
- }
-
- }
- #endregion
- #region 设置SEM数据
- public bool SetSEMDATAMParameter(double magnification, double semWorkingDistance)
- {
- #region 获取电镜参数
-
- //获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- //获取电镜参数
- bool mFlag ;
- bool wFlag;
-
- mFlag = m_SEMDATAFieldManage.SetGMagnification(magnification);
- wFlag = m_SEMDATAFieldManage.SetSemWorkingDistance(semWorkingDistance);
- if (mFlag || wFlag)
- {
- return true;
- }
-
- }
- return false;
- #endregion
- }
- public bool GetSEMDATAMParameter(ref double magnification, ref double WorkingDistance)
- {
- #region 获取电镜参数
- //获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- //获取电镜参数
- List<double> semParameters = m_SEMDATAFieldManage.GetSEMMagAndWDParameter();
- //放大倍数
- magnification = semParameters[0];
- WorkingDistance = semParameters[1];
-
- return true;
- }
- return false;
- #endregion
- }
- #endregion
- #region 驱动到SEM当前位置
- protected void SetMeasureToSEMLocation()
- {
- bool selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
- if (selWSampleMeasureStatus)
- {
- return;
- }
- try
- {
- List<double> SemLocation = new List<double>();
- if (GetSemLocation(ref SemLocation))
- {
-
- PointF OTSLocation = m_MeasureAppForm.m_ProjParam.ConverSEMToOTSCoord(new PointF((int)Math.Round(SemLocation[(int)XYIndex.X], 0), (int)Math.Round(SemLocation[(int)XYIndex.Y], 0)));
-
-
- var sam = GetWorkingVisualSample();
- var MeasureItem = sam.GetMeasureGDIObject();
-
- var measurePos = m_visualStage.OTSCoordToCtrlCoord(OTSLocation);
- MeasureItem.DraggingPoint = MeasureItem.GetCenterPoint();
- MeasureItem.PositionAltering(measurePos,false);
- var para = m_visualStage.GetSampleMeasurePara(MeasureItem);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
- }
- Invalidate();
- }
- catch (Exception ex)
- {
-
- log.Error( ex.ToString());
- }
- }
- #endregion
- #region 驱动SEM到当前位置
- public bool SetSEMCurrentLocation()
- {
-
- bool bret=false;
- //获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- bret = m_SEMDATAFieldManage.SetSEMCurrentLocation(m_MouseDownPoint, m_visualStage);
-
- }
-
- return bret;
-
-
- }
- #endregion
- #region 设置SEM到中心
- public bool SetSEMToCenterPoint()
- {
- try
- {
- //获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- bool bret = false;
- var sam = GetWorkingVisualSample();
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- bret = (m_SEMDATAFieldManage.DriveSEMToLocation(m_MouseDownPoint, m_visualStage, sam.GetMeasureFieldGDIObjects()));
- }
- return bret;
- }
- catch (Exception ex)
- {
-
- log.Error("OTSSamplespaceWindow_" + "SetSEMToCenterPoint" + ":" + ex.ToString() + "");
- return false;
- }
- }
- #endregion
- #region 获取SEM当前位置
- public bool GetSemLocation(ref List<double> SemLocation)
- {
-
- //获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- bool bret=false;
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- bret = m_SEMDATAFieldManage.GetSemLocation(ref SemLocation);
-
- }
- return bret;
-
- }
- #endregion
- #region 显示标尺
- /// <summary>
- /// 是否显示标尺控件
- /// </summary>
- /// <param name="b_show"></param>
- public void ShowRulerLocation()
- {
-
- //设置标尺位置
- Point rulerLocation = new Point(10, this.Height - (int)(control_Ruler2.Height * 2));
- this.control_Ruler2.Location = rulerLocation;
-
- control_Ruler2.Visible = true;
- var m_GlobalZoomNum = m_visualStage.GetZoomNum();
- f_ruler_size = Convert.ToInt32(f_old_ruler_size * m_GlobalZoomNum);
- control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
- control_Ruler2.Value = 1;
-
- //放大过长时,这里将宽度与代表的实际宽度进行折半显示
- while (control_Ruler2.Width > 300)
- {
- control_Ruler2.RulerWidth = Convert.ToInt32(control_Ruler2.RulerWidth) / 2;
- control_Ruler2.Value = control_Ruler2.Value * 2;
- }
- control_Ruler2.SetValue(control_Ruler2.RulerWidth, control_Ruler2.Value.ToString());
-
- }
- public void RulerInit(StageDrawingData SData)
- {
- control_Ruler2.ShowString = "1mm";
- PointF xDomain = new PointF(SData.StageDomain.Left, SData.StageDomain.Top);
- PointF yDomain = new PointF(SData.StageDomain.Right, SData.StageDomain.Bottom);
- //OTS宽度高度差值
- float widthDomain = Math.Abs(yDomain.X - xDomain.X);
- int length = this.Height > this.Width ? this.Width : this.Height;
- control_Ruler2.RulerWidth = (int)(length / widthDomain * 1000);
- f_ruler_size = f_old_ruler_size = control_Ruler2.RulerWidth;
- control_Ruler2.Value = 1000;
- }
- #endregion
- #region 隐藏与显示样品孔照片
- static bool IsShowSampleHoleImage = true;
- public void ChangeSampleHoleImage()
- {
- IsShowSampleHoleImage = IsShowSampleHoleImage ? false : true;
- Invalidate();
- }
- #endregion
- #region 添加样品孔中BSE图像信息
- public void AddHoleBSEImageData(byte[] ImageData, int width, int height, Point fieldPos)
- {
-
- CRectangleGDIObject itemWorkSample;
- var sam = GetWorkingVisualSample();
- itemWorkSample = GetWorkingVisualSample().GetSampleGDIObject();
- //获取样品孔BSE图像
- Image bseImage ;
- int m_iWidth = width;
- int m_iHeigh = height;
- RectangleF ImgRegionF;
- float ImgRegionWidth;
- float ImgRegionHeight ;
- if (m_ImageOfFieldGDIObjects.Count > 0)
- {
- for (int i = 0; i < m_ImageOfFieldGDIObjects.Count; i++)
- {
-
- var ctrlPos = m_visualStage.OTSCoordToCtrlCoord(fieldPos);
- if (m_ImageOfFieldGDIObjects[i].IfContains(ctrlPos))
- {
- ImgRegionF = m_ImageOfFieldGDIObjects[i].GetOrigionalDrawRegionF();
- ImgRegionWidth = Convert.ToInt32(ImgRegionF.Width);
- ImgRegionHeight = Convert.ToInt32(ImgRegionF.Height);
- //获取图片
- bseImage = CImageHandler.ToGrayBitmap(ImageData, m_iWidth, m_iHeigh);
-
- //绘制图像
- CRectangleGDIObject createImageRect =new CRectangleGDIObject (ImgRegionF, fieldPos.X, fieldPos.Y, itemWorkSample.SampleName, itemWorkSample.NameOrHoleName, bseImage, ImgRegionWidth, ImgRegionHeight, CreateRectangleType.DrawSampleHoleBSEImage);
- //添加至List集合中
- createImageRect.SetInitRegionF(m_ImageOfFieldGDIObjects[i].GetOrigionalDrawRegionF());
- createImageRect.NameOrHoleName = m_ImageOfFieldGDIObjects[i].NameOrHoleName;
- createImageRect.SetZoomNumber(m_visualStage.GetZoomNum());
- createImageRect.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
- m_ImageGDIObjects.Add(createImageRect);
-
- break;
- }
- }
- }
- //显示样品孔照片
- IsShowSampleHoleImage = true;
- Invalidate();
- }
- #endregion
- #region 删除样品孔中BSE图像信息
- public void DeleteHoleBSEImageData()
- {
- try
- {
- //鼠标右键点击的位置坐标
- Point mouseCurrent = m_MouseDownPoint;
- //样品名称
- string SampleName = "";
- //获取当前工作样品并删除对应BSE图
- foreach (CRectangleGDIObject ImageItem in m_ImageGDIObjects)
- {
- if (ImageItem.IfZoomContains(mouseCurrent))
- {
- SampleName = ImageItem.SampleName;
- break;
- }
- }
- if (SampleName != null && !SampleName.Equals(""))
- {
- string message = table["message7"].ToString();
- if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
- {
-
- DeleteHoleBSEImageDataNoMessageBox();
- return;
- }
- else
- {
- return;
- }
- }
- //删除样品孔BSE图
- //样品孔名称
- string HoleName = "";
- var item = m_visualStage.GetHoleGDIByMousePoint(mouseCurrent);
-
- if (item!=null)
- {
- HoleName = item.NameOrHoleName;
-
- }
-
- if (HoleName != null && !HoleName.Equals(""))
- {
- string message = table["message8"].ToString();
- if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
- {
-
- DeleteHoleBSEImageDataNoMessageBox();
- return;
- }
- else
- {
- return;
- }
- }
- }
- catch (Exception ex)
- {
-
- log.Trace(ex.ToString());
- }
- }
- public void DeleteHoleBSEImageDataNoMessageBox()
- {
-
- //鼠标右键点击的位置坐标
- Point mouseCurrent = m_MouseDownPoint;
-
- var item = m_visualStage.GetHoleGDIByMousePoint(mouseCurrent);
- if (item!=null)
- {
- m_ImageOfFieldGDIObjects.Clear();
- m_ImageGDIObjects.Clear();
- Invalidate();
- }
-
- }
- #endregion
- #region 获取样品孔图片
- private int GetSampleHoleIndex(StageDrawingData oTSSampleStageData, string sampleHoleName, ref OTSSampleHoleInfo sampleHoleInfo)
- {
- try
- {
- int sampleHoleIndex = -1;
- if (oTSSampleStageData.sSHoleInfoList.Count > 0)
- {
- for (int i = 0; i < oTSSampleStageData.sSHoleInfoList.Count; i++)
- {
- if (oTSSampleStageData.sSHoleInfoList[i].sSHoleName == sampleHoleName)
- {
- sampleHoleInfo = oTSSampleStageData.sSHoleInfoList[i];
- sampleHoleIndex = i;
- break;
- }
- }
- }
- return sampleHoleIndex;
- }
- catch (Exception)
- {
- return -1;
- }
- }
- public void GetBSEPictures()
- {
-
- OTSSampleHoleInfo sampleHoleInfo = null;
- var index= GetSampleHoleIndex(m_visualStage.GetOTSSampleStageData(), m_SampleHoleSelectName, ref sampleHoleInfo);
- if (sampleHoleInfo != null)
- {
-
- m_MeasureAppForm.StartSampleHoleBSEImage(MSR_THREAD_RunSTATUS.RUNSampleHoleImage, index);
- }
-
- }
- #endregion
- #region 复位工作样品区域
- public CRectangleGDIObject ResetMeasure( CRectangleGDIObject SampleGDIObjects, CRectangleGDIObject MeasureGDIObjects)
- {
-
-
- m_visualStage .GetMeasureGdiObjectFromSampleGdi(SampleGDIObjects,out MeasureGDIObjects);
-
- return MeasureGDIObjects;
-
- }
- public void ResetWorkSampleMeasure()
- {
- COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
- OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();
- if (!m_MeasureAppForm.m_ProjParam.GetWorkSamplePerameter(WSample, ref MeasureInfo))
- {
- return;
- }
- RectangleF measureSize = m_MeasureAppForm.m_ProjParam.CalculateMsrArea(MeasureInfo.SMeasurePara.sampleHoleName);
- //获取位置与尺寸
- MeasureInfo.SMeasurePara.MeasureRect.Location = measureSize.Location;
- MeasureInfo.SMeasurePara.MeasureRect.Size = measureSize.Size;
- //获取样品信息
- PointF xHole = new PointF(MeasureInfo.SMeasurePara.MeasureRect.Left, MeasureInfo.SMeasurePara.MeasureRect.Top);
- PointF yHole = new PointF(MeasureInfo.SMeasurePara.MeasureRect.Right, MeasureInfo.SMeasurePara.MeasureRect.Bottom);
-
- //定义测量区域
- RectangleF SampleRectangleF = m_visualStage.GetCtrlCoordRectF(xHole,yHole);
- CRectangleGDIObject m_MeasureGDIObject = m_visualStage.GetCtrlCoordRect(xHole,yHole,(CreateRectangleType)MeasureInfo.SMeasurePara.iShape, "", "");
- m_MeasureGDIObject.SetInitRegionF(SampleRectangleF);
-
- var sam = GetWorkingVisualSample();
- var mea = sam.GetMeasureGDIObject();
- CRectangleGDIObject m_ResetMeasureGDIobjects = ResetMeasure( sam.GetSampleGDIObject(), m_MeasureGDIObject);
- mea.SetInitRegionF(m_ResetMeasureGDIobjects.GetOrigionalDrawRegionF());
- mea.Shape = m_ResetMeasureGDIobjects.Shape;
- Invalidate();
-
- }
- #endregion
- }
- }
- #endregion
|