| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724 | using System;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;using OTS.WinFormsUI.Docking;using System.IO;using System.Drawing.Drawing2D;using System.Collections;using OTSDataType;using OTSModelSharp;using static OTSDataType.otsdataconst;using OTSCLRINTERFACE;namespace OTSMeasureApp{    public partial class OTSSamplespaceWindow : DockContent    {        #region 全局变量定义        //样品台对象        //StageDrawingData m_StageDrawingData;        public StageDrawingData m_OTSSampleStageData = null;        //样品测量集合对象        public List<SampleMeasurePara> m_SMeasrueAreaList = null;        //样品台存在的List集合 the rectangle on the edge of  stage ,usually one.        public static List<ARectangleGDIObject> m_RectangleGDIObjects;        //标样存在的List集合 usually it is a samll circle.        public static List<ARectangleGDIObject> m_SpecimenGDIObjects;        //样品孔的List集合        string m_SampleHoleSelectName = string.Empty;        public static string m_SampleSelectName = string.Empty;        string m_MeasureSelectName = string.Empty;        public static List<ARectangleGDIObject> m_SampleHoleGDIObjects;// the hole gdi of the stage         //样品的List集合        string m_SelectName = string.Empty;        public static ARectangleGDIObject selectSampleGDIObjects;        public static List<ARectangleGDIObject> m_SampleGDIObjects;        //工作样品的List集合        string m_WorkSelectName = string.Empty;        public static List<ARectangleGDIObject> m_WorkStageGDIObjects;        //测量区域        public static List<ARectangleGDIObject> m_MeasureGDIObjects;        //文字内容        public static List<ARectangleGDIObject> m_ContentGDIObjects;//the text that will display in the hole.        //测量区域        public static List<ARectangleGDIObject> m_MeasurePathGDIObjects;        //帧图        public static List<ARectangleGDIObject> m_SingleGDIObjects;        //所有帧图        public static List<ARectangleGDIObject> m_ALLSingleGDIObjects;        //BSE图像        public static List<ARectangleGDIObject> m_ImageGDIObjects;        //BSE图像帧图 为了获取位置与尺寸        public static List<ARectangleGDIObject> m_ImageSingleGDIObjects;        //手绘测量区域        public static List<ARectangleGDIObject> m_DrawMeasureGDIObjects;        //SEM中心位置        public static List<ARectangleGDIObject> m_SEMCenterGDIObjects;        //多边形测量区域完成标识        public static List<ARectangleGDIObject> m_DrawPolygonFinishGDIObjects;        //记录添加帧图的尺寸  鼠标滚动时使用的原值        //public static List<RectangleF> f;        //鼠标点击样品台(Mouse Down 里设置),说明样品台被选中,允许拖动被选中的样品台        bool m_RectangIsDragging = false;        float m_PenWidth = 5;        //分辨率 计算方式 0:宽度 1:高度        public static int IsWidth = 0;        static int m_WDomain = 0;        int m_DefaultW = 0;        int m_DefaultH = 0;        int m_DefaultWidth = 0;        int m_DefaultHeight = 0;        int m_DefaultStageWidth = 0;        int m_DefaultStageHeight = 0;        int m_DefaultSampleWidth = 0;        int m_DefaultSampleHeight = 0;        //当前位置与原位置的样品台相差位置        PointF m_DifferentPoint = new PointF();        //主窗体对象        OTSIncAMeasureAppForm m_MeasureAppForm;        //鼠标右键选择的类型 0:样品台 1:样品 2:测量区域        public int m_IsSelectType = 0;        //当前是否选择测量区域        public static bool m_IsMeasure = false;        SEMDATAFieldManage m_SEMDATAFieldManage;        List<Rectangle> m_RectFieldRects = null;        //记录绘制样品台时的中心位置        Point m_RegionStartCenterPoint = new Point(0, 0);        //记录绘制后样品台的电镜坐标范围         Point StageLTPointToSEMLocation = new Point(0, 0);        Point StageRBPointToSEMLocation = new Point(0, 0);        //当前是否移动样品        bool m_IsMoveSample = false;        //XML文件名称        static string m_XMLFileName = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;        //电镜与样品参数中的放大倍数与工作距离         public static double m_SEMIWDistance = 0;        public static double m_SEMDMagni = 0;        public static double m_PropIWDistance = 0;        public static double m_PropDMagni = 0;        #region 鼠标滚动所需参数        public static float m_ScaleNum = 1;        public static float m_GlobalZoomNum = 1;//记录每次比例缩放后的总体比例系数。        //改变窗体 记录的比例系数        public static float m_WorkAreaZoom = 1;        //加载的样品台类型 默认为原型样品台        public static int m_Shape = 0;        private Size m_intSize = new Size(0, 0);        int m_MinMeasureWidthValue = 20;                Point m_MouseDownLocation = new Point(0, 0);        #endregion        #region 手动绘制测量区域        Point m_MouseDownPoint;        Point m_MouseUpPoint;        Point m_MouseMovePoint;        //绘制多边形,点集合        List<PointF> m_PolygonPoint;        //点数量        int m_PointCount = 2;        //与多边形绘制的开始点相差的像素值        int m_OffsetPX = 10;        //手动绘制多边形测量区域完成标识        bool m_IsDrawPolygonFinish = false;        //手动绘制测量区域的形状类型        int m_DrawMeasureType = 1;        //是否手绘标识准备        public bool m_IsDrawMeasureReady = false;        //是否手绘标识        public bool m_IsDrawMeasure = false;        #endregion        //所选测量区域的矩形对象        Rectangle m_SelMeasureRect;        //是否选中样品台标识        bool m_IsSelectSampleStage = false;        private Point m_P, m_P1;        protected Point m_MeasureToSamplePoint;        //是否按下Ctrl键        bool m_IsCtrl = false;        bool m_IsAlt = false;        //配合Ctrol键是否选中多边形的点标识        bool m_IsSelPolygonPoint = false;        //配合Ctrol键是否选中多边形的点        PointF m_SelPolygonPoint = new Point();        //测量区域矩形对象        static Rectangle m_MeasureRectangle = new Rectangle();        //默认值        const int m_DValue = 1;        int m_CompletedFieldsCount = 0;        NLog.Logger log ;		//选择工作样品测量的状态        bool selWSampleMeasureStatus = false;        #endregion        #region 标尺变量        //缩放的增大缩小的增量        private float f_zoom_increment = 0.1f;        //缩放的基数,临时变量        private float f_widthandheight_js = 0;        //与原先缩放的记录数        private float f_zoom_record = 1;        //最小缩放倍数        private float f_zoom_mix = 0.5f;        //标尺的大小记录        private float f_ruler_size = 100;        //标尺原先大小的记录,参与计算        private float f_old_ruler_size = 100;        public RectangleF BackRectF        {            set { backrectf = value; }            get { return backrectf; }        }        //背景矩形        public RectangleF backrectf = new RectangleF();        //记录原值,背景矩形        public RectangleF old_backrectf = new RectangleF();        //国际化        OTSSysMgrTools.Language lan;        Hashtable table;        #endregion        #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;            //this.InitDataEvent();            SetDoubleBufferByIsDraw();// 双缓冲                   m_OTSSampleStageData = new StageDrawingData();            //国际化            lan = new OTSSysMgrTools.Language(this);            table = lan.GetNameTable(this.Name);        }        /// <summary>        /// 画圆形测试区域 事件        /// </summary>        public void Rev_DDrawCircleMeasure_MeasureAppToSampleWindow_Event()        {            //手绘测量区域类型为圆形            m_DrawMeasureType = (int)CreateRectangleType.Circle;            m_IsDrawMeasureReady = true;            m_RectangIsDragging = false;            this.Cursor = Cursors.Hand;        }        /// <summary>        /// 画矩形测试区域 事件        /// </summary>        public void Rev_DDrawRectangleMeasure_MeasureAppToSampleWindow_Event()        {            //手绘测量区域类型为矩形            m_DrawMeasureType = (int)CreateRectangleType.SampleBackGround_Rectangle;            m_IsDrawMeasureReady = true;            m_RectangIsDragging = false;            this.Cursor = Cursors.Hand;        }        /// <summary>        /// 画多边形测试区域 事件        /// </summary>        public void Rev_DDrawPolygonMeasure_MeasureAppToSampleWindow_Event()        {            //多边形测量区域完成标识            m_DrawPolygonFinishGDIObjects = new List<ARectangleGDIObject>();            //手绘测量区域类型为矩形            m_DrawMeasureType = (int)CreateRectangleType.Polygon;            m_IsDrawMeasureReady = true;            m_IsDrawMeasure = true;            m_RectangIsDragging = false;            m_PolygonPoint = new List<PointF>();            this.Cursor = Cursors.Hand;        }        /// <summary>        /// 三点画圆形测试区域 事件        /// </summary>        public void Rev_DDrawCircleMeasureByThreePoints_MeasureAppToSampleWindow_Event()        {            //多边形测量区域完成标识            m_DrawPolygonFinishGDIObjects = new List<ARectangleGDIObject>();            //手绘测量区域类型为圆形            m_DrawMeasureType = (int)CreateRectangleType.CircleByThreePoints;            m_IsDrawMeasureReady = true;            m_IsDrawMeasure = true;            m_RectangIsDragging = false;            m_PolygonPoint = new List<PointF>();            this.Cursor = Cursors.Hand;        }        /// <summary>        /// 当修改了GRID 的样品台测量精度、放大倍数和图片像素大小 时,SAMPLEWINDOW重新绘制样品台        /// </summary>        public void Rev_DDDrawSampleStage_EventHandler_Event()        {            m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;            //显示帧图            if (m_SingleGDIObjects.Count > 0)            {                showSingleInfo();            }        }        public void Rev_MeasureApp_OpenExistSampleFile_Event(CStage SStage, CSEMStageData SEMStageData, List<SampleMeasurePara> SMeasrueAreaList, string sWorkSampleName)        {            GetSampleStageData(SStage, SEMStageData);          var  SStageData = m_OTSSampleStageData;            m_GlobalZoomNum = 1;            //清除所有绘制的图形信息            ClearDrawInfo();            //绘制样品台信息            if (SStageData != null)            {                m_OTSSampleStageData = SStageData;                DrawSampleStage(SStageData);            }            //绘制样品与测量区域            //1.绘制样品            if (SMeasrueAreaList != null)            {                m_SMeasrueAreaList = SMeasrueAreaList;                DrawSampleAndMeasureInfo(SMeasrueAreaList);            }            //2.测量区域            //设置工作样品            if (sWorkSampleName != "")            {                Rev_MeasureApp_SwitchWorkSample_Event(sWorkSampleName);                //打开文件后 设置工作样品名称                m_SampleSelectName = sWorkSampleName;            }            //重新绘制            Invalidate();        }        ///MeasureApp和 SampleSpaceWindow 切换工作样品名称事件委托        ///string sNewWSampleName:    切换新工作样品名称        public void Rev_MeasureApp_SwitchWorkSample_Event(string sNewWSampleName, bool bDrawField = false)        {            try            {                //获取存在帧图的样品名称                string singleSampleName = string.Empty;                if (m_SingleGDIObjects != null)                {                    if (m_SingleGDIObjects.Count > 0)                    {                        singleSampleName = m_SingleGDIObjects[0].SampleName;                    }                }                //判断当前帧图所在样品的样品名称与新样品名称是否相同                if (!singleSampleName.Equals(""))                {                    if (singleSampleName != sNewWSampleName)                    {                        //先清空帧图信息                        ClearImageAndSingleGDIObjects();                        this.Invalidate();                    }                }                //判断当前帧图所在样品的样品名称与新样品名称是否相同                if (m_SingleGDIObjects != null)                {                    if (m_SingleGDIObjects.Count > 0)                    {                        if (m_SingleGDIObjects[0].SampleName != sNewWSampleName)                        {                            //先清空帧图信息                            ClearImageAndSingleGDIObjects();                            this.Invalidate();                        }                    }                }                //设置工作样品样式                CStageManage.SetWorkSampleAndWorkMeasure(sNewWSampleName);                foreach (var itemMeasure in m_MeasureGDIObjects)                {                    if (itemMeasure.IsSingle && itemMeasure.IsWorkSample && sNewWSampleName == itemMeasure.SampleName)                    {                        //当前工作样品的测量区域 获取帧图信息                        if (m_SingleGDIObjects.Count == 0)                        {                            string message = table["message1"].ToString();                            //log.Trace("Rev_MeasureApp_SwitchWorkSample_Event:--" + message + "--begin--");                            showSingleInfo();                            //log.Trace("Rev_MeasureApp_SwitchWorkSample_Event:--" + message + "--end--");                            break;                        }                    }                }                ////绘制已完成的帧图状态                COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.m_ResultData;                //当前工作样品的测量区域 获取帧图信息                COTSSample cSample = cProjMgr.GetWorkingSample();                int CompletedFieldsCount = cSample.GetMsrStatus().GetCompletedFields();                if (CompletedFieldsCount > 0)                {                    //设置测量区域获取帧图                    foreach (var itemMeasure in m_MeasureGDIObjects)                    {                        if (cSample.GetName() == itemMeasure.SampleName)                        {                            itemMeasure.IsSingle = true;                            break;                        }                    }                    if (m_SingleGDIObjects.Count == 0)                    {                        showSingleInfo();                    }                    //获取已完成测量的帧图中心点                    List<Point> CompleteFieldList = cProjMgr.GetWorkingSample().GetMsrStatus().GetCompletedFieldsCenter();                    //修改帧图完成状态                    OTSMeasureDisplayResult.ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, m_MeasureAppForm);                }                else                {                    //根据测量文件中已获取sem信息                    if (cSample.GetSEMDataMsr().GetTotalFields() > 0)                    {                        foreach (var itemMeasure in m_MeasureGDIObjects)                        {                            if (cSample.GetName() == itemMeasure.SampleName)                            {                                itemMeasure.IsSingle = true;                                showSingleInfo();                                break;                            }                        }                    }                }                //设置为手绘测量区域                m_IsDrawMeasureReady = false;                m_IsDrawMeasure = false;                this.Invalidate();                return;            }            catch (Exception ex)            {                string message = table["message2"].ToString();                //记录错误日志                log.Trace("Rev_MeasureApp_SwitchWorkSample_Event():" + message + ":" + ex.ToString() + "");            }        }        //MeasureApp和 SampleSpaceWindow 修改工作样品名称事件委托        //string sSampleHoleName:    修改工作样品名称          public void Rev_MeasureApp_ChangeWorkSampleName_Event(string sNewWSampleName)        {            try            {                string oldSampleName = string.Empty;                foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)                {                    if (itemSample.IsWorkSample)                    {                        oldSampleName = itemSample.SampleName;                    }                }                //更换样品名称                CStageManage.ChangeSampleName(sNewWSampleName);                this.Invalidate();                return;            }            catch (Exception ex)            {                string message = table["message2"].ToString();                //记录错误日志                log.Trace("Rev_MeasureApp_ChangeWorkSampleName_Event():" + message + ":" + ex.ToString() + "");            }        }        //MeasureApp和 SampleSpaceWindow 删除样品事件委托,  MeasureApp 给 SampleSpaceWindow 发送删除样品委托事件        //string sSampleHoleName:    删除工作样品名         public void Rev_MeasureApp_DeleteWorkSample_Event(string sDeleteWSampleName, string sNewWSampleName)        {            try            {                foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)                {                    if (itemSample.SampleName == sDeleteWSampleName)                    {                        if (itemSample.IsWorkSample)                        {                            //删除样品测量集合中的对象                            if (CStageManage.DeleteSample(sDeleteWSampleName))                            {                                if (m_SampleGDIObjects.Count == 0)                                {                                    //将测量状态初始化                                    m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();                                }                                //根据样品名称 删除对应帧图信息                                OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, sDeleteWSampleName);                                if (!string.IsNullOrEmpty(sNewWSampleName))                                {                                    //设置工作样品                                    m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(sNewWSampleName);                                }                                else                                {                                    //先清空帧图信息                                    ClearImageAndSingleGDIObjects();                                }                                this.Invalidate();                                return;                            }                        }                    }                }            }            catch (Exception ex)            {                string message = table["message2"].ToString();                //记录错误日志                log.Error("Rev_MeasureApp_DeleteWorkSample_Event():" + message + ":" + ex.ToString() + "");            }        }        #region 更改工作样品中 测量区域形状        public void changeShape(int iShape)        {            try            {                string sampleName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();                //m_Shap 更换样品形状                if (CStageManage.ChangeSampleShape(iShape))                {                    //设置新添加测量区域更改位置与缩放                    foreach (var item in m_MeasureGDIObjects)                    {                        if (item.SampleName == sampleName)                        {                            item.IsWorkSample = true;                            if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))                            {                                //保存原位置                                Rectangle rectPara = item.Region;                                #region 测量区域与样品中心相差的距离                                foreach (var itemSample in m_SampleGDIObjects)                                {                                    if (itemSample.SampleName == item.SampleName)                                    {                                        item.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);                                        break;                                    }                                }                                if (item.IsSingle)                                {                                    showSingleInfo();                                }                                #endregion                            }                        }                    }                }                this.Invalidate();                return;            }            catch (Exception ex)            {                string message = table["message2"].ToString();                //记录错误日志                log.Error("changeShape():" + message + ":" + ex.ToString() + "");            }        }        #endregion        #region 还原测量区域形状        public void ResetShape()        {            try            {                //设置新添加测量区域更改位置与缩放                foreach (var item in m_MeasureGDIObjects)                {                    if (item.IsWorkSample)                    {                        if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))                        {                            //保存原位置                            Rectangle rectPara = item.Region;                            #region 测量区域与样品中心相差的距离                            foreach (var itemSample in m_SampleGDIObjects)                            {                                if (itemSample.SampleName == item.SampleName)                                {                                    item.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);                                    break;                                }                            }                            if (item.IsSingle)                            {                                showSingleInfo();                            }                            #endregion                        }                    }                }                this.Invalidate();                return;            }            catch (Exception ex)            {                string message = table["message2"].ToString();                //记录错误日志                log.Error("changeShape():" + message + ":" + ex.ToString() + "");            }        }        #endregion        ///MeasureApp 给SampleWindow窗口发送添加样品的样品孔名,测量区域信息        //string sSampleName : 新添加样品名        //string sSampleHoleName:    新添加样品所在的样品孔名称        //int iShape:   测量区域形状        //Point pStartPoint: 测量区域起点        //Point pEndPoint  :  测量区域终点        public void AddOneSampleArea(SampleMeasurePara SMeasurePara)        {            try            {                CMStrip.Hide();                //获取样品信息                Point xHole = new Point(SMeasurePara.MeasureRect.Left, SMeasurePara.MeasureRect.Top);                Point yHole = new Point(SMeasurePara.MeasureRect.Right, SMeasurePara.MeasureRect.Bottom);                //将微米转换为像素                int widthHole = (int)(Math.Abs(((Point)yHole).X - ((Point)xHole).X));                int heightHole = (int)(Math.Abs(((Point)yHole).Y - ((Point)xHole).Y));                //定义测量区域                RectangleF SampleRectangleF = OTSSamplespaceGraphicsPanelFun.GetPixRectF(m_WDomain, yHole, xHole, "", "", IsWidth, m_DefaultW, m_DefaultH);                ARectangleGDIObject m_SampleGDIObject = OTSSamplespaceGraphicsPanelFun.GetPixRect(m_WDomain, yHole, xHole, SMeasurePara.iShape, "", "", IsWidth, m_DefaultW, m_DefaultH);                m_SampleGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);                m_SampleGDIObject.RegionF = SampleRectangleF;                m_SampleGDIObject.DrawRegionF = SampleRectangleF;                //测量区域名称 样品名称                m_SampleGDIObject.SampleName = SMeasurePara.sSampleName;                //测量区域类型                 m_SampleGDIObject.CreateType = SMeasurePara.iShape;                //添加样品                if (CStageManage.AddSample(SMeasurePara.sHoleName, SMeasurePara.sSampleName, m_SampleGDIObject, this, m_GlobalZoomNum))                {                    //设置新添加样品测量的位置                    if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(m_MeasureGDIObjects[m_MeasureGDIObjects.Count - 1], m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))                    {                        CStageManage.SetWorkSampleAndWorkMeasure(SMeasurePara.sSampleName);                        //清除帧图信息                        ClearImageAndSingleGDIObjects();                        Invalidate();                    }                }            }            catch (Exception ex)            {                string message = table["message2"].ToString();                //记录错误日志                log.Error("OTSSamplespaceWindow_Rev_MeasureApp_AddSample_Event():--" + message + ":" + ex.ToString() + "");            }        }        //响应委托事件的样品台数据        public void InitStageDisplay(CStage SStage, CSEMStageData SEMStageData)        {            GetSampleStageData(SStage, SEMStageData);            m_GlobalZoomNum = 1;                    //清除所有绘制的图形信息            ClearDrawInfo();            //绘制样品台信息            DrawSampleStage(m_OTSSampleStageData);            //标尺初始化            RulerInit();            //重新绘制            Invalidate();            //1.将测量结果窗体中已存在的内容清空            //2.将测量图像清空                           //图像隐藏               HideMessureStatuWindowBSEImage(m_MeasureAppForm);                //将测量结果信息状态初始化                InitMeasureStateInfo();                       if (m_SampleGDIObjects != null)            {                if (m_SampleGDIObjects.Count == 0)                {                    //将测量状态初始化                    m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();                }            }        }        public void HideMessureStatuWindowBSEImage(OTSIncAMeasureAppForm m_MeasureApps)        {            m_MeasureApps.m_MessureStatuWindow.pbBSEImage.Hide();        }        #region 将测量状态进度窗口信息初始化        public void InitMeasureStateInfo()        {           m_MeasureAppForm.m_MeasureRetWindow.SetInit();        }        #endregion        //获取绘制样品台的数据        private bool GetSampleStageData(CStage SStage ,CSEMStageData SEMStageData)        {            //StageDrawingData m_OTSSampleStageData = new StageDrawingData();            //获取样品台信息            //CStage SStage = m_ResultData.GetStage();            if (null == SStage)            {                return false;            }            //获得样品台数据            m_OTSSampleStageData.sStageName = SStage.GetName();            m_OTSSampleStageData.bStageShape = (int)SStage.GetBoundary().GetShape();            m_OTSSampleStageData.StageDomain = (Rectangle)SStage.GetBoundary().GetRectDomain();            m_OTSSampleStageData.bSampleShape = (int)SStage.GetSTD().GetShape();            m_OTSSampleStageData.SampleRect = (Rectangle)SStage.GetSTD().GetRectDomain();            int iSHoleCount = SStage.GetHoleList().Count;    //样品孔个数                       if (m_OTSSampleStageData.sSHoleInfoList.Count > 0)            {                m_OTSSampleStageData.sSHoleInfoList.Clear();            }            var holeLst = SStage.GetHoleList();            for (int i = 0; i < iSHoleCount; i++)            {                CHole d = holeLst[i];                OTSSampleHoleInfo SHoleInfo = new OTSSampleHoleInfo();                //获取样品口的名称,形状,坐标                SHoleInfo.sSHoleName = d.GetName();                SHoleInfo.iSHoleShape = (int)d.GetShape();                Rectangle r = (Rectangle)d.GetRectDomain();                SHoleInfo.HoleRect = r;                m_OTSSampleStageData.sSHoleInfoList.Add(SHoleInfo);            }            //获取SEMData 绘制样品            m_OTSSampleStageData.iScanFieldSize100 = SEMStageData.GetScanFieldSize100();  //放大倍数为100倍时的屏幕尺寸            m_OTSSampleStageData.iXAxisDir = (int)SEMStageData.GetXAxisDir();            m_OTSSampleStageData.iYAxisDir = (int)SEMStageData.GetYAxisDir();            m_OTSSampleStageData.iXAxisStartVal = SEMStageData.GetXAxis().GetStart();            m_OTSSampleStageData.iXAxisEndVal = SEMStageData.GetXAxis().GetEnd();            m_OTSSampleStageData.iYAxisStartVal = SEMStageData.GetYAxis().GetStart();            m_OTSSampleStageData.iYAxisEndVal = SEMStageData.GetYAxis().GetEnd();            return true;        }                  //记录样品台的最大宽度        static int RegionMaxWidth = 0;        #region 绘制样品台信息        /// <summary>        /// 绘制样品台信息        /// </summary>        /// <returns></returns>        public void DrawSampleStage(StageDrawingData SData)        {            try            {                if (SData.StageDomain.X == 0 && SData.StageDomain.Y == 0)                {                    return;                }                string stageName = SData.sStageName;                int widthDomain = 0;                int heightDomain = 0;                //获取样品台                int StageShape = SData.bStageShape;                Point xDomain = new Point(SData.StageDomain.Left, SData.StageDomain.Top);                Point yDomain = new Point(SData.StageDomain.Right, SData.StageDomain.Bottom);                //OTS宽度高度差值                widthDomain = Math.Abs(yDomain.X - xDomain.X);                heightDomain = Math.Abs(yDomain.Y - xDomain.Y);                //样品台转换在电镜位置的宽度与高度                StageLTPointToSEMLocation = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(xDomain);                StageRBPointToSEMLocation = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(yDomain);                //设置样品台宽度                m_WDomain = widthDomain;                IsWidth = this.Height > this.Width ? 0 : 1;                //记录添加帧图的尺寸  鼠标滚动时使用的原值                m_DefaultW = this.Width;                m_DefaultH = this.Height;                m_Shape = SData.bStageShape;                CreateRectangle CreateBourary = null;                //0:圆角矩形 1:圆形 2:文字 3:矩形                if (SData.bStageShape == (int)CreateRectangleType.SampleBackGround_Rectangle)                {                    CreateBourary = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xDomain, yDomain, (int)CreateRectangleType.SampleBackGround_Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);                }                else                {                    CreateBourary = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xDomain, yDomain, (int)CreateRectangleType.SampleBackGround_Circle, "", "", IsWidth, m_DefaultW, m_DefaultH);                }                //获取默认尺寸                m_DefaultWidth = CreateBourary.Region.Width;                m_DefaultHeight = CreateBourary.Region.Height;                //添加样品台 对象                //设置路径                GraphicsPath MeasurePath = new GraphicsPath();                if (StageShape == (int)CreateRectangleType.Circle)                {                    MeasurePath.AddEllipse(CreateBourary.Region);                }                else                {                    MeasurePath.AddRectangle(CreateBourary.Region);                }                CreateBourary.GPath = MeasurePath;                CreateBourary.Shape = StageShape;                m_RectangleGDIObjects.Add(CreateBourary);                //绘制后的样品台中心位置                Point m_Region = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0].Region);                //获取绘制后的样品台中心位置                if (m_RegionStartCenterPoint.X != m_Region.X || m_RegionStartCenterPoint.Y != m_Region.Y)                {                    m_RegionStartCenterPoint = m_Region;                }                //获取最大宽度                if (RegionMaxWidth <= 0)                {                    RegionMaxWidth = (IsWidth == 0 ? this.Width : this.Height);                }                //获取样品孔                System.Collections.Generic.List<OTSSampleHoleInfo> ChloeClrList = SData.sSHoleInfoList;                if (ChloeClrList.Count > 0)                {                    for (int i = 0; i < ChloeClrList.Count; i++)                    {                        //获取微米信息                        var xHole = new Point(ChloeClrList[i].HoleRect.Left, ChloeClrList[i].HoleRect.Top);                        var yHole = new Point(ChloeClrList[i].HoleRect.Right, ChloeClrList[i].HoleRect.Bottom);                        //将微米转换为像素                        int widthHole = Math.Abs(yHole.X - xHole.X);                        int heightHole = Math.Abs(yHole.Y - xHole.Y);                        //获取矩形                        CreateRectangle CreateHole = null;                        //0:圆角矩形 1:圆形 2:文字 3:矩形                        if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.SampleBackGround_Rectangle)                        {                            CreateHole = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Rectangle, "", ChloeClrList[i].sSHoleName, IsWidth, m_DefaultW, m_DefaultH);                        }                        else                        {                            CreateHole = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Circle, "", ChloeClrList[i].sSHoleName, IsWidth, m_DefaultW, m_DefaultH);                        }                        //获取样品孔默认尺寸                        m_DefaultStageWidth = CreateHole.Region.Width;                        m_DefaultStageHeight = CreateHole.Region.Height;                        //绘制样品孔路径                        GraphicsPath HolePath = new GraphicsPath();                        if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.Circle)                        {                            HolePath.AddEllipse(CreateHole.Region);                        }                        else                        {                            HolePath.AddRectangle(CreateHole.Region);                        }                        CreateHole.GPath = HolePath;                        m_SampleHoleGDIObjects.Add(CreateHole);                        //添加文字                        CreateRectangle CreateContent = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);                        //类型 文字:2                        CreateContent.CreateType = (int)CreateRectangleType.Font;                        CreateContent.Region = CreateHole.Region;                        CreateContent.strContent = ChloeClrList[i].sSHoleName;                        CreateContent.Name = ChloeClrList[i].sSHoleName;                        m_ContentGDIObjects.Add(CreateContent);                    }                }                //获取标样                int StageShapes = SData.bStageShape;                Point xSTD = new Point(SData.SampleRect.Left, SData.SampleRect.Top);                Point ySTD = new Point(SData.SampleRect.Right, SData.SampleRect.Bottom);                //获取矩形                CreateRectangle CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);                if (StageShapes == (int)CreateRectangleType.Circle)                {                    CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.SpecimenCircle, "", "", IsWidth, m_DefaultW, m_DefaultH);                }                else                {                    CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.SpecimenRectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);                }                m_DefaultSampleWidth = CreateSTD.Region.Width;                m_DefaultSampleHeight = CreateSTD.Region.Height;                //绘制标样路径                GraphicsPath STDPath = new GraphicsPath();                if (StageShapes == (int)CreateRectangleType.Circle)                {                    STDPath.AddEllipse(CreateSTD.Region);                }                else                {                    STDPath.AddRectangle(CreateSTD.Region);                }                CreateSTD.GPath = STDPath;                m_SpecimenGDIObjects.Add(CreateSTD);                return;            }            catch (Exception ex)            {                string message = table["message2"].ToString();                log.Error("OTSSamplespaceWindow_DrawSampleInfo():--" + message + ":" + ex.ToString() + "");            }        }        #endregion        private string m_fileName = string.Empty;        public string FileName        {            get { return m_fileName; }            set            {                if (value != string.Empty)                {                    Stream s = new FileStream(value, FileMode.Open);                    FileInfo efInfo = new FileInfo(value);                    string fext = efInfo.Extension.ToUpper();                    s.Close();                }                m_fileName = value;                this.ToolTipText = value;            }        }        #endregion        #region 窗体事件        private void OTSSamplespaceWindow_Load(object sender, EventArgs e)        {            try            {                //样品台                m_RectangleGDIObjects = new List<ARectangleGDIObject>();                //标样                m_SpecimenGDIObjects = new List<ARectangleGDIObject>();                //样品孔                m_SampleHoleGDIObjects = new List<ARectangleGDIObject>();                //样品孔文字内容                m_ContentGDIObjects = new List<ARectangleGDIObject>();                //样品                m_SampleGDIObjects = new List<ARectangleGDIObject>();                //工作样品                m_WorkStageGDIObjects = new List<ARectangleGDIObject>();                //测量区域                m_MeasureGDIObjects = new List<ARectangleGDIObject>();                //测量区域图形路径                m_MeasurePathGDIObjects = new List<ARectangleGDIObject>();                //手绘测量区域                m_DrawMeasureGDIObjects = new List<ARectangleGDIObject>();                //帧图                m_SingleGDIObjects = new List<ARectangleGDIObject>();                //所有帧图                m_ALLSingleGDIObjects = new List<ARectangleGDIObject>();                //样品孔BSE图像                m_ImageGDIObjects = new List<ARectangleGDIObject>();                //BSE图像帧图为了获取位置与尺寸                m_ImageSingleGDIObjects = new List<ARectangleGDIObject>();                //SEM中心位置                m_SEMCenterGDIObjects = new List<ARectangleGDIObject>();                this.ResizeRedraw = true;                log = NLog.LogManager.GetCurrentClassLogger();            }            catch (Exception ex)            {                string message = table["message2"].ToString();                log.Error("OTSSamplespaceWindow_OTSSamplespaceWindow_Load:--" + message + ":" + ex.ToString() + "");            }        }        protected override void OnMouseDown(MouseEventArgs e)        {            lblFocus.Focus();            //记录鼠标按下的位置            m_P.X = e.X;            m_P.Y = e.Y;            m_P1.X = e.X;            m_P1.Y = e.Y;            int WH = 2;            //鼠标点击时的位置            Point _Point = new Point();            m_RectangIsDragging = false;            if (m_RectangleGDIObjects == null)                return;            //判断当前是否手绘            if (m_IsDrawMeasureReady)            {                //获取当前的鼠标点击位置                this.m_MouseDownPoint = new Point(e.X, e.Y);                //获取当前工作样品                COTSSample cSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();                string sampleHoleName = cSample.GetSampleHoleName();                string sampleName = cSample.GetName();                int sizeWH = 5;                Size size = new Size(sizeWH, sizeWH);                Rectangle rectangle = new Rectangle(m_MouseDownPoint, size);                //绘制多边形 测量区域                if (m_DrawMeasureType == (int)CreateRectangleType.Polygon)                {                    //显示绘制多边形完成标识                    if (m_PolygonPoint.Count > m_PointCount)                    {                        Point startPoint = new Point((int)(m_PolygonPoint[0].X), (int)(m_PolygonPoint[0].Y));                        if (m_IsDrawPolygonFinish)                        {                            DialogResult dResult = MessageBox.Show(table["message10"].ToString(), table["message11"].ToString(), MessageBoxButtons.YesNo);                            if (dResult == DialogResult.Yes)                            {                                m_PolygonPoint.Add(startPoint);                                CreateRectangle createFinishPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.Polygon, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);                                GraphicsPath PolygonMeasurePath = new GraphicsPath();                                PolygonMeasurePath.AddPolygon(m_PolygonPoint.ToArray());                                createFinishPoint.GPath = PolygonMeasurePath;                                for (int i = 0; i < createFinishPoint.PolygonPointRegionF.Count; i++)                                {                                    float X = createFinishPoint.PolygonPointRegionF[i].X / m_GlobalZoomNum;                                    float Y = createFinishPoint.PolygonPointRegionF[i].Y / m_GlobalZoomNum;                                    PointF DrawPoint = new PointF(X, Y);                                    createFinishPoint.DrawPolygonPointRegionF[i] = DrawPoint;                                }                                if (m_DrawMeasureGDIObjects.Count > 0)                                {                                    m_DrawMeasureGDIObjects[0] = createFinishPoint;                                }                                bool IsSingle = false;                                //清除当前的样品测量区域                                for (int measureIndex = m_MeasureGDIObjects.Count - 1; measureIndex >= 0; measureIndex--)                                {                                    if (m_MeasureGDIObjects[measureIndex].SampleName == sampleName)                                    {                                        IsSingle = m_MeasureGDIObjects[measureIndex].IsSingle;                                        m_MeasureGDIObjects.RemoveAt(measureIndex);                                        break;                                    }                                }                                //删除存在的帧图                                for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)                                {                                    if (m_SingleGDIObjects[singleIndex].SampleName == sampleName)                                    {                                        m_SingleGDIObjects.RemoveAt(singleIndex);                                    }                                }                                //将绘制好的多边形测量区域赋值给 多边形测量区域对象                                if (m_DrawMeasureGDIObjects.Count > 0)                                {                                    m_DrawMeasureGDIObjects[0].IsSelect = true;                                    m_DrawMeasureGDIObjects[0].IsWorkSample = true;                                    //创建多边形外接矩形                                    m_DrawMeasureGDIObjects[0].Region = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(OTSSamplespaceGraphicsPanelFun.PointConvertPointF(m_DrawMeasureGDIObjects[0].PolygonPointRegion));                                    m_DrawMeasureGDIObjects[0].RegionF = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_DrawMeasureGDIObjects[0].DrawPolygonPointRegionF);                                    m_DrawMeasureGDIObjects[0].DrawRegionF = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_DrawMeasureGDIObjects[0].DrawPolygonPointRegionF);                                    m_DrawMeasureGDIObjects[0].IsSingle = IsSingle;                                    m_DrawMeasureGDIObjects[0].IsWorkSample = true;                                    m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);                                    m_DrawMeasureGDIObjects.Clear();                                    m_DrawPolygonFinishGDIObjects.Clear();                                }                                if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(m_MeasureGDIObjects[m_MeasureGDIObjects.Count - 1], m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))                                {                                    m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;                                    CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;                                    //设置工作样品                                    m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);                                    Invalidate();                                }                                //设置手绘标识                                m_IsDrawMeasureReady = false;                                m_IsDrawMeasure = false;                                m_IsDrawPolygonFinish = false;                                this.Cursor = Cursors.Default;                                return;                            }                            else                            {                                return;                            }                        }                    }                    //添加多边形点信息                    m_MouseDownPoint = new Point((int)(m_MouseDownPoint.X), (int)(m_MouseDownPoint.Y));                    m_PolygonPoint.Add(m_MouseDownPoint);                    CreateRectangle createPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.Polygon, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);                    if (m_DrawMeasureGDIObjects.Count > 0)                    {                        m_DrawMeasureGDIObjects[0] = createPoint;                    }                    else                    {                        m_DrawMeasureGDIObjects.Add(createPoint);                    }                    //添加当前绘制的第一点位置,生成多边形测量区域完成标识                    if (m_DrawPolygonFinishGDIObjects.Count == 0)                    {                        int rectSize = m_MinMeasureWidthValue;                        Point PolygonFinishPoint = new Point((int)(m_MouseDownPoint.X - m_MinMeasureWidthValue / 2), (int)(m_MouseDownPoint.Y - m_MinMeasureWidthValue / 2));                        Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));                        CreateRectangle createPolygonFinish = new CreateRectangle(pRect, (int)CreateRectangleType.DrawPolygonFinish, sampleHoleName, sampleName, Color.Green);                        m_DrawPolygonFinishGDIObjects.Add(createPolygonFinish);                    }                    return;                }                else if(m_DrawMeasureType == (int)CreateRectangleType.CircleByThreePoints)                {                    //显示绘制多边形完成标识                    if (m_PolygonPoint.Count == 3)                    {                        Point startPoint = new Point((int)(m_PolygonPoint[0].X), (int)(m_PolygonPoint[0].Y));                                                        //清除当前的样品测量区域                                for (int measureIndex = m_MeasureGDIObjects.Count - 1; measureIndex >= 0; measureIndex--)                                {                                    if (m_MeasureGDIObjects[measureIndex].SampleName == sampleName)                                    {                                        m_MeasureGDIObjects.RemoveAt(measureIndex);                                        break;                                    }                                }                                //删除存在的帧图                                for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)                                {                                    if (m_SingleGDIObjects[singleIndex].SampleName == sampleName)                                    {                                        m_SingleGDIObjects.RemoveAt(singleIndex);                                    }                                }                                //设置手绘标识                                m_IsDrawMeasureReady = false;                                m_IsDrawMeasure = false;                                m_IsDrawPolygonFinish = false;                                this.Cursor = Cursors.Default;                                return;                                                   }                                        //添加多边形点信息                    m_MouseDownPoint = new Point((int)(m_MouseDownPoint.X), (int)(m_MouseDownPoint.Y));                    m_PolygonPoint.Add(m_MouseDownPoint);                    CreateRectangle createPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.CircleByThreePoints, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);                    if (m_DrawMeasureGDIObjects.Count > 0)                    {                        m_DrawMeasureGDIObjects[0] = createPoint;                    }                    else                    {                        m_DrawMeasureGDIObjects.Add(createPoint);                        System.Threading.Thread.Sleep(1);                        //MessageBox.Show("a");                    }                    return;                }                else                {                    //在样品台内部缩放                    if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(new Rectangle(this.m_MouseDownPoint, new Size(2, 2)), m_RectangleGDIObjects[0].Region, m_DrawMeasureType))                    {                        m_IsDrawMeasure = true;                    }                    else                    {                        m_IsDrawMeasure = false;                        return;                    }                    Color MeasureColor = Color.Red;                    CreateRectangle createRectangle = new CreateRectangle(rectangle, m_DifferentPoint, (int)CreateRectangleType.MeasureArea, m_DrawMeasureType, sampleName, sampleName, MeasureColor);                    //在鼠标点击时添加一个默认大小与位置的图形                    createRectangle.RegionF = createRectangle.Region;                    createRectangle.DrawRegionF = createRectangle.Region;                    m_DrawMeasureGDIObjects.Add(createRectangle);                    return;                }            }            else            {                if (e.Button == MouseButtons.Right)                {                    if (m_MeasureAppForm.MeasureThreadRunFlag)                    {                        m_IsSelectType = (int)ContextMenuType.ThreadRunMenu;                        //设置编辑右键菜单项                        CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);                        _Point = this.PointToClient(Cursor.Position);                        this.CMStrip.Show(this, _Point);                        return;                    }                    //获取鼠标右键点击位置                    m_MouseDownLocation = e.Location;                    //显示XY轴                    OTSSamplespaceGraphicsPanelFun.ShowSemCoordvAL(e.Location, m_MeasureAppForm, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth);                    string workSampleName = string.Empty;                    foreach (ARectangleGDIObject item in m_SingleGDIObjects)                    {                        if (item.RegionF.Contains(e.Location))                        {                            //样品孔菜单                            m_IsSelectType = (int)ContextMenuType.SingleMenu;                            _Point = this.PointToClient(Cursor.Position);                            bool IsTrue = false;                            //设置编辑右键菜单项                            foreach (ARectangleGDIObject imageItem in m_ImageGDIObjects)                            {                                if (imageItem.SampleName == item.SampleName)                                {                                    IsTrue = true;                                    break;                                }                            }                            //设置编辑右键菜单项                            CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, IsTrue);                            //将删除样品与测量 设置为不可编辑状态                            this.CMStrip.Show(this, _Point);                            return;                        }                    }                    foreach (ARectangleGDIObject item in m_SampleGDIObjects)                    {                        if (item.IsWorkSample)                        {                            workSampleName = item.SampleName;                            break;                        }                    }                    for (int i = m_MeasureGDIObjects.Count - 1; i >= 0; i--)                    {                        foreach (var SampleItem in m_SampleGDIObjects)                        {                            if (m_MeasureGDIObjects[i].SampleName == SampleItem.SampleName)                            {                                bool isSelMeasure = false;                                if (m_MeasureGDIObjects[i].Shape == (int)CreateRectangleType.Polygon)                                {                                    //判断当前位置是否在不规则形状里面                                    if (OTSSamplespaceGraphicsPanelFun.PositionPnpoly(OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(m_MeasureGDIObjects[i].PolygonPointRegionF), e.Location) && !m_MeasureGDIObjects[i].SelColor.Name.Equals("Transparent"))                                    {                                        isSelMeasure = true;                                    }                                }                                else                                {                                    if (m_MeasureGDIObjects[i].Region.Contains(e.Location) && !m_MeasureGDIObjects[i].SelColor.Name.Equals("Transparent"))                                    {                                        isSelMeasure = true;                                        Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));                                        int CheckShape = (int)CreateRectangleType.Circle;                                        if (m_MeasureGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)                                        {                                            CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;                                        }                                        if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rect, m_MeasureGDIObjects[i].Region, CheckShape))                                        {                                            break;                                        }                                    }                                }                                if (isSelMeasure)                                {                                    //如果选择的样品不是当前工作样品 则删除原有帧图信息                                    if (m_MeasureGDIObjects[i].SampleName != workSampleName)                                    {                                        ClearImageAndSingleGDIObjects();                                    }                                    //删除BSE照片                                    bool IsTrue = false;                                    //设置编辑右键菜单项                                    foreach (ARectangleGDIObject imageItem in m_ImageGDIObjects)                                    {                                        if (imageItem.SampleName == m_MeasureGDIObjects[i].SampleName)                                        {                                            IsTrue = true;                                            break;                                        }                                    }                                    //测量区域菜单                                    m_IsSelectType = (int)ContextMenuType.MeasureMenu;                                    //设置编辑右键菜单项                                    CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, IsTrue);                                    _Point = this.PointToClient(Cursor.Position);                                    this.CMStrip.Show(this, _Point);                                    m_MeasureSelectName = m_MeasureGDIObjects[i].SampleName;                                    m_SampleHoleSelectName = m_MeasureGDIObjects[i].Name;                                    if (m_SampleSelectName != m_MeasureGDIObjects[i].SampleName)                                    {                                        m_SampleSelectName = m_MeasureGDIObjects[i].SampleName;                                        m_MeasureGDIObjects[i].IsSelect = true;                                        m_MeasureGDIObjects[i].IsWorkSample = true;                                        //设置工作样品                                        m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);                                        Invalidate();                                    }                                    return;                                }                            }                        }                    }                    foreach (ARectangleGDIObject item in m_ImageGDIObjects)                    {                        if (item.Region.Contains(e.Location))                        {                            //样品孔菜单                            m_IsSelectType = (int)ContextMenuType.SampleHoleBSEImage;                            _Point = this.PointToClient(Cursor.Position);                            //设置编辑右键菜单项                            CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);                            this.CMStrip.Show(this, _Point);                            return;                        }                    }                    //只点击样品上(测量区域被移动到其他地方)                    for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)                    {                        if (m_SampleGDIObjects[i].Region.Contains(e.Location))                        {                            //如果选择的样品不是当前工作样品 则删除原有帧图信息                            if (m_SampleGDIObjects[i].SampleName != workSampleName)                            {                                ClearImageAndSingleGDIObjects();                            }                            Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));                            //判断样品形状                            int CheckShape = (int)CreateRectangleType.Circle;                            if (m_MeasureGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)                            {                                CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;                            }                            if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rect, m_SampleGDIObjects[i].Region, CheckShape))                            {                                break;                            }                            //样品菜单                            m_IsSelectType = (int)ContextMenuType.SampleMenu;                            //将删除样品与测量 设置为不可编辑状态                            _Point = this.PointToClient(Cursor.Position);                            bool flag = false;                            foreach (var MeasureItem in m_MeasureGDIObjects)                            {                                if (m_SampleGDIObjects[i].SampleName == MeasureItem.SampleName)                                {                                    if (MeasureItem.Region.Contains(e.Location))                                    {                                        //测量区域菜单                                        m_IsSelectType = (int)ContextMenuType.MeasureMenu;                                        //flag = !MeasureItem.IsSingle;                                        break;                                    }                                }                            }                            //设置编辑右键菜单项                            CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, flag);                            this.CMStrip.Show(this, _Point);                            if (m_SampleSelectName != m_SampleGDIObjects[i].SampleName)                            {                                m_SampleSelectName = m_SampleGDIObjects[i].SampleName;                                m_SampleHoleSelectName = m_SampleGDIObjects[i].Name;                                m_SampleGDIObjects[i].IsSelect = true;                                m_SampleGDIObjects[i].IsWorkSample = true;                                //设置工作样品 向主窗体发送请求                                m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);                                Invalidate();                            }                            return;                        }                    }                    //点击样品孔                    foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)                    {                        if (item.Region.Contains(e.Location))                        {                            Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));                            int CheckShape = (int)CreateRectangleType.Circle;                            if (item.Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)                            {                                CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;                            }                                                    //样品孔菜单                            m_IsSelectType = (int)ContextMenuType.SampleHoleMenu;                            _Point = this.PointToClient(Cursor.Position);                            //设置编辑右键菜单项                            CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);                            //将删除样品与测量 设置为不可编辑状态                            this.CMStrip.Show(this, _Point);                                                        m_SampleHoleSelectName = item.Name;                            item.IsSelect = true;                            return;                        }                    }                    foreach (ARectangleGDIObject item in m_RectangleGDIObjects)                    {                        if (item.Region.Contains(e.Location))                        {                            //样品台菜单                            m_IsSelectType = (int)ContextMenuType.SampleStateMenu;                            //设置编辑右键菜单项                            CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);                            _Point = this.PointToClient(Cursor.Position);                            this.CMStrip.Show(this, _Point);                            break;                        }                    }                    return;                }                //左键点击样品台上                else                {                    //如果正在进行测量线程,则退出鼠标点击操作                    if (m_MeasureAppForm.MeasureThreadRunFlag)                    {                        return;                    }                    foreach (ARectangleGDIObject item in m_RectangleGDIObjects)                    {                        if (item.Region.Contains(e.Location))                        {                            m_RectangIsDragging = true;                            m_IsSelectSampleStage = true;                        }                        item.IsDragging = true;                        item.DraggingPoint = e.Location;                    }                    //测量区域                    foreach (ARectangleGDIObject item in m_MeasureGDIObjects)                    {                        if (Control.ModifierKeys == Keys.Control)                        {                            //获取选择工作样品的测量状态                            selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();                            if (selWSampleMeasureStatus)                            {                                return;                            }                            //如果选择的测量区域 颜色不是透明 可以选择                            if (!item.SelColor.Name.Equals("Transparent"))                            {                                if (item.CreateType == (int)CreateRectangleType.Polygon)                                {                                    if (item.GPath != null)                                    {                                        //在多边形点附近切换光标                                        foreach (PointF itemPoint in item.PolygonPointRegionF)                                        {                                            if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)                                            {                                                if (Control.ModifierKeys == Keys.Control)                                                {                                                    if (m_DrawPolygonFinishGDIObjects != null)                                                    {                                                        if (m_DrawPolygonFinishGDIObjects.Count > 0)                                                        {                                                            m_DrawPolygonFinishGDIObjects.Clear();                                                        }                                                    }                                                    m_IsSelPolygonPoint = true;                                                    m_IsCtrl = true;                                                    m_IsSelectSampleStage = false;                                                    //选择前测量区域的尺寸                                                    m_SelMeasureRect = item.Region;                                                    m_MeasureRectangle = item.Region;                                                    item.SelColor = Color.Red;                                                    item.IsDragging = true;                                                    item.DraggingPoint = e.Location;                                                    item.IsSelect = true;                                                    item.IsWorkSample = true;                                                    //记录选择的多边形点信息                                                    m_SelPolygonPoint = itemPoint;                                                    int rectSize = m_MinMeasureWidthValue;                                                    Point PolygonFinishPoint = new Point((int)(itemPoint.X - m_MinMeasureWidthValue / 2), (int)(itemPoint.Y - m_MinMeasureWidthValue / 2));                                                    Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));                                                    CreateRectangle createPolygonFinish = new CreateRectangle(pRect, (int)CreateRectangleType.DrawPolygonFinish, "", "", Color.Green);                                                    if (m_DrawPolygonFinishGDIObjects != null)                                                    {                                                        m_DrawPolygonFinishGDIObjects.Add(createPolygonFinish);                                                    }                                                    break;                                                }                                            }                                        }                                        //如果鼠标已选择多边形的点,跳出循环                                        if (item.IsSelect == true)                                        {                                            break;                                        }                                        if (item.GPath.IsVisible(e.Location))                                        {                                            m_IsCtrl = true;                                            m_IsSelectSampleStage = false;                                            //选择前测量区域的尺寸                                            m_SelMeasureRect = item.Region;                                            m_MeasureRectangle = item.Region;                                            item.SelColor = Color.Red;                                            item.IsDragging = true;                                            item.DraggingPoint = e.Location;                                            item.IsWorkSample = true;                                            item.IsSelect = false;                                            break;                                        }                                    }                                }                                else                                {                                    if (item.GPath != null)                                    {                                        if (item.GPath.IsOutlineVisible((float)e.X, (float)e.Y, new Pen(Color.Gray, m_PenWidth)))                                        {                                            m_IsCtrl = true;                                            m_IsSelectSampleStage = false;                                            //选择前测量区域的尺寸                                            m_SelMeasureRect = item.Region;                                            m_MeasureRectangle = item.Region;                                            item.SelColor = Color.Red;                                            item.IsDragging = true;                                            item.DraggingPoint = e.Location;                                            item.IsSelect = true;                                            item.IsWorkSample = true;                                            break;                                        }                                    }                                    if (item.Region.Contains(e.Location))                                    {                                        m_IsCtrl = true;                                        m_IsSelectSampleStage = false;                                        //选择前测量区域的尺寸                                        m_SelMeasureRect = item.Region;                                        m_MeasureRectangle = item.Region;                                        item.SelColor = Color.Red;                                        item.IsDragging = true;                                        item.DraggingPoint = e.Location;                                        item.IsWorkSample = true;                                        item.IsSelect = false;                                        break;                                    }                                }                            }                        }                    }                    //当鼠标点击样品上(测量区域被拖动到其他地方)                    for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)                    {                        if ((Control.ModifierKeys == Keys.Alt))                        {                            if (m_SampleGDIObjects[i].Region.Contains(e.Location))                            {                                m_IsMoveSample = true;                                m_IsSelectSampleStage = false;                                m_IsAlt = true;                            }                        }                        if (!(Control.ModifierKeys == Keys.Control))                        {                            if (m_SampleGDIObjects[i].Region.Contains(e.Location))                            {                                foreach (var measureItem in m_MeasureGDIObjects)                                {                                    if (measureItem.SampleName == m_SampleGDIObjects[i].SampleName)                                    {                                        m_MeasureRectangle = measureItem.Region;                                        measureItem.SelColor = Color.Red;                                    }                                    else                                    {                                        measureItem.SelColor = Color.Transparent;                                    }                                }                                for (int x = 0; x < m_SampleGDIObjects.Count; x++)                                {                                    //获取颜色                                    string SampleColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);                                    m_SampleGDIObjects[x].SelColor = ColorTranslator.FromHtml(SampleColorStr);                                    m_SampleGDIObjects[x].IsWorkSample = false;                                    m_SampleGDIObjects[x].IsSelect = false;                                }                                //设置为工作样品                                m_SampleGDIObjects[i].IsWorkSample = true;                                m_SampleGDIObjects[i].IsSelect = true;                                //获取颜色                                string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);                                m_SampleGDIObjects[i].SelColor = ColorTranslator.FromHtml(ColorStr);                                selectSampleGDIObjects = m_SampleGDIObjects[i];                                if (m_SampleSelectName != m_SampleGDIObjects[i].SampleName)                                {                                    //获取工作样品名称                                    m_SampleSelectName = m_SampleGDIObjects[i].SampleName;                                    //设置工作样品 向主窗体发送请求                                    m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);                                }                                break;                            }                        }                    }                    //样品                    MouseDownFucntion(m_SampleGDIObjects, e);                    //样品孔                    MouseDownFucntion(m_SampleHoleGDIObjects, e);                    //标样                    MouseDownFucntion(m_SpecimenGDIObjects, e);                    //测量                    MouseDownFucntion(m_MeasureGDIObjects, e);                    //文字                    MouseDownFucntion(m_ContentGDIObjects, e);                    //帧图                    MouseDownFucntion(m_SingleGDIObjects, e);                    //所有获取的帧图                    MouseDownFucntion(m_ALLSingleGDIObjects, e);                    //样品台中BSE图片                    MouseDownFucntion(m_ImageGDIObjects, e);                    //SEM中心位置                    MouseDownFucntion(m_SEMCenterGDIObjects, e);                    for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)                    {                        if (m_SampleGDIObjects[i].Region.Contains(e.Location) && m_SampleGDIObjects[i].IsWorkSample)                        {                            //获取当前样品与测量区域的位置                            foreach (ARectangleGDIObject item in m_MeasureGDIObjects)                            {                                if (m_SampleGDIObjects[i].SampleName == item.SampleName && m_SampleGDIObjects[i].IsWorkSample)                                {                                    m_MeasureToSamplePoint.X = m_SampleGDIObjects[i].Region.X - item.Region.X;                                    m_MeasureToSamplePoint.Y = m_SampleGDIObjects[i].Region.Y - item.Region.Y;                                    break;                                }                            }                        }                    }                }            }            //重绘控件            Invalidate();        }        protected override void OnMouseMove(MouseEventArgs e)        {            //'记录光标拖动的当前点            m_P1.X = e.X;            m_P1.Y = e.Y;            bool InMeasure = false;            //如果正在进行测量线程,则退出鼠标点击操作            if (m_MeasureAppForm.MeasureThreadRunFlag)            {                return;            }            //获取选择工作样品的测量状态            if (selWSampleMeasureStatus)            {                return;            }            //手动绘制 记录鼠标移动位置            if (m_IsDrawMeasure)            {                this.m_MouseMovePoint = new Point(e.X, e.Y);                //绘制多边形                if (m_DrawMeasureType == (int)CreateRectangleType.Polygon)                {                    PointF startPoint = new PointF();                    PointF endPoint = new PointF();                    //显示直线开始点与鼠标当前位置的直线                    if (m_PolygonPoint.Count > 0)                    {                        startPoint = m_PolygonPoint[0];                        endPoint = m_PolygonPoint[m_PolygonPoint.Count - 1];                    }                    //显示绘制多边形完成标识                    if (m_PolygonPoint.Count > m_PointCount)                    {                        if (Math.Abs(m_MouseMovePoint.X - startPoint.X) <= m_OffsetPX && Math.Abs(m_MouseMovePoint.Y - startPoint.Y) <= m_OffsetPX)                        {                            //显示绘制多边形完成标识                            m_IsDrawPolygonFinish = true;                        }                        else                        {                            m_IsDrawPolygonFinish = false;                        }                    }                }                //圆形三点法                else if (m_DrawMeasureType == (int)CreateRectangleType.CircleByThreePoints)                {                    PointF startPoint = new PointF();                    PointF endPoint = new PointF();                    //显示直线开始点与鼠标当前位置的直线                    if (m_PolygonPoint.Count > 0)                    {                        startPoint = m_PolygonPoint[0];                        endPoint = m_PolygonPoint[m_PolygonPoint.Count - 1];                    }                }                else                {                    if (m_DrawMeasureGDIObjects == null || m_RectangleGDIObjects == null)                    {                        return;                    }                    Rectangle rectangle = new Rectangle();                    foreach (var item in m_DrawMeasureGDIObjects)                    {                        rectangle = item.Region;                        //移动鼠标绘制测量区域                        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;                        }                        //移动鼠标绘制测量区域                        //以中心绘制测量区域方法                        //rectangle = new Rectangle(m_MouseDownPoint.X - tmp, m_MouseDownPoint.Y - tmp, 2 * tmp, 2 * tmp);                        OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition enumMouse = OTSSamplespaceGraphicsPanelFun.MousePointPosition(m_MouseDownPoint, m_MouseMovePoint);                        Point LTPoint = new Point();                        Size RBSize = new Size();                        switch (enumMouse)                        {                            case OTSSamplespaceGraphicsPanelFun.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 OTSSamplespaceGraphicsPanelFun.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 OTSSamplespaceGraphicsPanelFun.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 OTSSamplespaceGraphicsPanelFun.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 (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectangle, m_RectangleGDIObjects[0].Region, m_DrawMeasureType))                        {                            //移动鼠标绘制测量区域                            //以中心绘制测量区域方法                            //item.Region = new Rectangle(m_MouseDownPoint.X - tmp, m_MouseDownPoint.Y - tmp, 2 * tmp, 2 * tmp);                            item.Region = new Rectangle(LTPoint, RBSize);                            item.RegionF = new RectangleF(new PointF((item.Region.X) / m_GlobalZoomNum, (item.Region.Y) / m_GlobalZoomNum), new SizeF(item.Region.Width / m_GlobalZoomNum, item.Region.Height / m_GlobalZoomNum));                            item.DrawRegionF = item.RegionF;                            //生成图形路径                            GraphicsPath MeasurePath = new GraphicsPath();                            if (item.Shape == (int)CreateRectangleType.Rectangle)                            {                                MeasurePath.AddRectangle(item.Region);                            }                            else                            {                                MeasurePath.AddEllipse(item.Region);                            }                            item.GPath = MeasurePath;                            break;                        }                    }                }            }            if (m_RectangIsDragging)            {                if (m_RectangleGDIObjects == null) { return; }                if (!m_IsSelectSampleStage)                {                    foreach (ARectangleGDIObject item in m_SampleGDIObjects)                    {                        if (!m_IsMeasure)                        {                            if (item.Region.Contains(e.Location))                            {                                if (item.IsDragging)                                {                                    if (item.IsWorkSample)                                    {                                        if (item.IsSelect)                                        {                                            //判断移动的样品 是否在样品台尺寸范围内                                            foreach (ARectangleGDIObject measureItem in m_MeasureGDIObjects)                                            {                                                if (measureItem.SampleName == item.SampleName)                                                {                                                    if (measureItem.CreateType == (int)CreateRectangleType.Polygon)                                                    {                                                        if (this.Cursor != Cursors.Default)                                                        {                                                            return;                                                        }                                                        //判断移动的样品 是否在样品台尺寸范围内                                                        Rectangle rectTemp = item.Region;                                                        rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;                                                        rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;                                                        int CheckShape = (int)CreateRectangleType.Circle;                                                        if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)                                                        {                                                            CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;                                                        }                                                        //判断样品是否超越样品台                                                        if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))                                                        {                                                            return;                                                        }                                                        else                                                        {                                                            //生成多边形最小面积外接矩形                                                            Rectangle rectMeasureTemp = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(measureItem.PolygonPointRegionF);                                                            //判断多边形是否超越样品台                                                            rectMeasureTemp.X = rectMeasureTemp.Left + e.X - measureItem.DraggingPoint.X;                                                            rectMeasureTemp.Y = rectMeasureTemp.Top + e.Y - measureItem.DraggingPoint.Y;                                                            if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))                                                            {                                                                Rectangle rectSampleTemp = item.Region;                                                                rectSampleTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;                                                                rectSampleTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;                                                                if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectSampleTemp, m_RectangleGDIObjects[0].Region, CheckShape))                                                                {                                                                    MouseMovePolygonMeasureFucntion(measureItem, e);                                                                    OTSSamplespaceGraphicsPanelFun.GetMouseMoveLocation(item, e);                                                                    //计算两个点之间的距离 移动样品台后与绘制样品台时的位置                                                                    m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);                                                                    isChange = true;                                                                }                                                            }                                                        }                                                    }                                                    else                                                    {                                                        Rectangle rectMeasureTemp = measureItem.Region;                                                        rectMeasureTemp.X = measureItem.Region.Left + e.X - measureItem.DraggingPoint.X;                                                        rectMeasureTemp.Y = measureItem.Region.Top + e.Y - measureItem.DraggingPoint.Y;                                                        //判断移动的样品 是否在样品台尺寸范围内                                                        Rectangle rectTemp = item.Region;                                                        rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;                                                        rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;                                                        int CheckShape = (int)CreateRectangleType.Circle;                                                        if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)                                                        {                                                            CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;                                                        }                                                        //判断样品是否超越样品台                                                        if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))                                                        {                                                            return;                                                        }                                                        //判断测量区域是否超越样品台                                                        if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))                                                        {                                                            Rectangle rectSampleTemp = item.Region;                                                            rectSampleTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;                                                            rectSampleTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;                                                            if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectSampleTemp, m_RectangleGDIObjects[0].Region, CheckShape))                                                            {                                                                MouseMoveMeasureFucntion(measureItem, e);                                                                OTSSamplespaceGraphicsPanelFun.GetMouseMoveLocation(item, e);                                                                //计算两个点之间的距离 移动样品台后与绘制样品台时的位置                                                                m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);                                                                isChange = true;                                                            }                                                        }                                                        else                                                        {                                                            return;                                                        }                                                    }                                                }                                            }                                        }                                        foreach (ARectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)                                        {                                            //获取样品孔中心点                                             Point sampleHoleCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(sampleHoleItem);                                            if (item.Region.Contains(sampleHoleCenterPoint))                                            {                                                if (item.Name != sampleHoleItem.Name)                                                {                                                    //获取颜色                                                    string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);                                                    item.SelColor = ColorTranslator.FromHtml(ColorStr);                                                    break;                                                }                                            }                                            else                                            {                                                //获取颜色                                                string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);                                                item.SelColor = ColorTranslator.FromHtml(ColorStr);                                            }                                        }                                    }                                    Invalidate();                                }                            }                        }                    }                    foreach (ARectangleGDIObject item in m_MeasureGDIObjects)                    {                        //检测鼠标光标点是否在路径上                        if (item.IsDragging)                        {                            if (item.IsWorkSample)                            {                                if (item.IsSelect)                                {                                    if (item.DraggingPoint != Point.Empty)                                    {                                        //获取中心点                                        Point xy1 = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(item.Region);                                        //获取鼠标坐标                                        Point xy2 = e.Location;                                        Rectangle rectTemp = new Rectangle();                                        int CheckShape = (int)CreateRectangleType.Circle;                                        if (item.CreateType == (int)CreateRectangleType.Polygon)                                        {                                            if (m_IsSelPolygonPoint)                                            {                                                //获取选中点进行移动,代码                                                #region MyRegion                                                if (Control.ModifierKeys == Keys.Control)                                                {                                                    //int pointCount = m_DrawPolygonFinishGDIObjects.Count;                                                    //在多边形点附近切换光标                                                    for (int i = 0; i < item.PolygonPointRegionF.Count; i++)                                                    {                                                        if (item.PolygonPointRegionF[i].X == m_SelPolygonPoint.X && item.PolygonPointRegionF[i].Y == m_SelPolygonPoint.Y)                                                        {                                                            //移动点的位置                                                            Rectangle selPolygonPointRect = new Rectangle(0, 0, 2, 2);                                                            selPolygonPointRect.X = (int)m_SelPolygonPoint.X + e.X - item.DraggingPoint.X;                                                            selPolygonPointRect.Y = (int)m_SelPolygonPoint.Y + e.Y - item.DraggingPoint.Y;                                                            //判断样品是否超越样品台                                                            if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(selPolygonPointRect, m_RectangleGDIObjects[0].Region, CheckShape))                                                            {                                                                if (i == 0 || i == item.PolygonPointRegionF.Count - 1)                                                                {                                                                    //移动点                                                                    m_SelPolygonPoint = new Point(e.X, e.Y);                                                                    item.PolygonPointRegion[item.PolygonPointRegionF.Count - 1] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);                                                                    item.PolygonPointRegionF[item.PolygonPointRegionF.Count - 1] = m_SelPolygonPoint;                                                                    item.DrawPolygonPointRegionF[item.PolygonPointRegionF.Count - 1] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);                                                                    item.PolygonPointRegionF[0] = m_SelPolygonPoint;                                                                    item.PolygonPointRegion[0] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);                                                                    item.PolygonPointRegionF[0] = m_SelPolygonPoint;                                                                    item.DrawPolygonPointRegionF[0] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);                                                                }                                                                else                                                                {                                                                    m_SelPolygonPoint = new Point(e.X, e.Y);                                                                    item.PolygonPointRegion[i] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);                                                                    item.PolygonPointRegionF[i] = m_SelPolygonPoint;                                                                    item.DrawPolygonPointRegionF[i] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);                                                                }                                                                m_DrawPolygonFinishGDIObjects[0].Region = new Rectangle(new Point((int)m_SelPolygonPoint.X - m_OffsetPX, (int)m_SelPolygonPoint.Y - m_OffsetPX), new Size(m_MinMeasureWidthValue, m_MinMeasureWidthValue));                                                                m_DrawPolygonFinishGDIObjects[0].RegionF = new Rectangle(new Point((int)m_SelPolygonPoint.X - m_OffsetPX, (int)m_SelPolygonPoint.Y - m_OffsetPX), new Size(m_MinMeasureWidthValue, m_MinMeasureWidthValue));                                                                m_DrawPolygonFinishGDIObjects[0].DrawRegionF = new Rectangle(new Point((int)m_SelPolygonPoint.X - m_OffsetPX, (int)m_SelPolygonPoint.Y - m_OffsetPX), new Size(m_MinMeasureWidthValue, m_MinMeasureWidthValue));                                                                //生成多边形最小面积外接矩形                                                                Rectangle rectPolygonMeasure = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);                                                                item.Region = rectPolygonMeasure;                                                                item.RegionF = rectPolygonMeasure;                                                                item.DrawRegionF = rectPolygonMeasure;                                                                item.DraggingPoint = e.Location;                                                                break;                                                            }                                                        }                                                    }                                                }                                                #endregion                                            }                                        }                                        else                                        {                                            //计算偏离半径                                            int a = (xy1.X - xy2.X) * (xy1.X - xy2.X);                                            int b = (xy1.Y - xy2.Y) * (xy1.Y - xy2.Y);                                            int c = a + b;                                            int r = Convert.ToInt32(System.Math.Sqrt(c));                                            int width = r * 2;                                            rectTemp = new Rectangle(xy1.X - r, xy1.Y - r, width, width);                                            //在样品台内部缩放                                            if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))                                            {                                                #region 需抽出作为公共方法                                                int xMove = rectTemp.X - item.Region.X;                                                int yMove = rectTemp.Y - item.Region.Y;                                                int Width = rectTemp.Width - item.Region.Width;                                                int Height = rectTemp.Height - item.Region.Height;                                                //如果大于最小测量高度 设置图形大小                                                if (rectTemp.Width / m_GlobalZoomNum > m_MinMeasureWidthValue)                                                {                                                    item.Region = rectTemp;                                                    float WidthNew = (float)((item.RegionF.Width + Width / m_GlobalZoomNum));                                                    float HeightNew = (float)((item.RegionF.Height + Height / m_GlobalZoomNum));                                                    //设置原测量区域图形大小                                                    float xMoveNew = (float)((item.RegionF.X + xMove / m_GlobalZoomNum));                                                    float yMoveNew = (float)((item.RegionF.Y + yMove / m_GlobalZoomNum));                                                    item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));                                                    item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));                                                    item.DraggingPoint = e.Location;                                                    isChange = true;                                                }                                                #endregion                                            }                                            else                                            {                                                return;                                            }                                            Invalidate();                                            return;                                        }                                    }                                }                                else                                {                                    //鼠标配合Ctrol键 移动单个测量区域                                    if (item.Shape == (int)CreateRectangleType.Polygon)                                    {                                        //判断是否已存在多边形的点,不能移动多边形                                        if (!m_IsSelPolygonPoint)                                        {                                            if (this.Cursor == Cursors.SizeAll)                                            {                                                if (item.GPath.IsVisible(e.Location))                                                {                                                    isChange = true;                                                    MouseMovePolygonMeasureFucntion(item, e);                                                }                                            }                                        }                                    }                                    else                                    {                                        if (item.Region.Contains(e.Location))                                        {                                            isChange = true;                                            MouseMoveMeasureFucntion(item, e);                                        }                                    }                                }                            }                        }                    }                }                //移动样品台                if (m_IsSelectSampleStage)                {                    if (m_IsCtrl)                    {                        return;                    }                    if (m_IsAlt)                    {                        return;                    }                    //样品台                    MouseMoveFucntion(m_RectangleGDIObjects, e);                    //样品孔                    MouseMoveFucntion(m_SampleHoleGDIObjects, e);                    //样品                    MouseMoveFucntion(m_SampleGDIObjects, e);                    //标样                    MouseMoveFucntion(m_SpecimenGDIObjects, e);                    //测量                    MouseMoveFucntion(m_MeasureGDIObjects, e);                    //文字                    MouseMoveFucntion(m_ContentGDIObjects, e);                    //帧图                    if (m_SingleGDIObjects.Count > 0)                    {                        MouseMoveSingleFucntion(m_SingleGDIObjects, e);                        string sampleName = m_SingleGDIObjects[0].SampleName;                    }                    //样品孔BSE图片                    MouseMoveSingleFucntion(m_ImageGDIObjects, e);                    //计算两个点之间的距离 移动样品台后与绘制样品台时的位置                    m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);                }            }            //显示XY轴            OTSSamplespaceGraphicsPanelFun.ShowSemCoordvAL(e.Location, m_MeasureAppForm, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth);            Invalidate();            foreach (var item in m_MeasureGDIObjects)            {                if (item.CreateType == (int)CreateRectangleType.Polygon)                {                    if (m_IsSelPolygonPoint)                    {                        InMeasure = true;                    }                }                if (item.Region.Contains(e.Location))                {                    InMeasure = true;                }            }            if (!InMeasure)            {                //this.Cursor = Cursors.Default;            }        }        bool isChange = false;        protected override void OnMouseUp(MouseEventArgs e)        {            //判断当前是否手绘            if (m_IsDrawMeasure)            {                //获取当前的鼠标点击位置                this.m_MouseUpPoint = new Point(e.X, e.Y);                //绘制多边形                if (m_DrawMeasureType != (int)CreateRectangleType.Polygon)                {                    foreach (var item in m_DrawMeasureGDIObjects)                    {                        for (int i = 0; i < m_MeasureGDIObjects.Count; i++)                        {                            if (item.SampleName == m_MeasureGDIObjects[i].SampleName)                            {                                //获取样品孔名称与其他属性                                item.Name = m_MeasureGDIObjects[i].Name;                                item.IsSingle = m_MeasureGDIObjects[i].IsSingle;                                item.IsWorkSample = m_MeasureGDIObjects[i].IsWorkSample;                                //删除存在的帧图                                for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)                                {                                    if (m_SingleGDIObjects[singleIndex].SampleName == item.SampleName)                                    {                                        m_SingleGDIObjects.RemoveAt(singleIndex);                                    }                                }                                m_MeasureGDIObjects[i] = item;                                if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))                                {                                    m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;                                    CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;                                    showSingleInfo();                                    break;                                }                            }                        }                    }                    //清空绘制测量区域                    if (m_DrawMeasureGDIObjects.Count > 0)                    {                        m_DrawMeasureGDIObjects.Clear();                    }                    this.Cursor = Cursors.Default;                    //设置手绘标识                    m_IsDrawMeasureReady = false;                    m_IsDrawMeasure = false;                }            }            //如果正在进行测量线程,则退出鼠标点击操作            if (m_MeasureAppForm.MeasureThreadRunFlag)            {                return;            }            //是否移动至新样品孔            int IsContains = 0;            string HoleName = string.Empty;            //如果没有选择样品台            if (!m_IsSelectSampleStage)            {                //根据选择工作样品的测量状态,控制操作                if (selWSampleMeasureStatus)                {                    return;                }                if (isChange)                {                    if (m_RectangleGDIObjects == null)                    {                        return;                    }                    foreach (var measureItem in m_MeasureGDIObjects)                    {                        if (measureItem.IsWorkSample)                        {                            if (measureItem.Region.Contains(e.Location))                            {                                if (isChange == false)                                {                                    isChange = true;                                }                            }                            //保存原位置                            Rectangle rectPara = measureItem.Region;                            #region 测量区域与样品中心相差的距离                            foreach (var itemSample in m_SampleGDIObjects)                            {                                if (itemSample.SampleName == measureItem.SampleName)                                {                                    measureItem.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);                                    break;                                }                            }                            #endregion                            //获取修改后的测量区域的位置与尺寸                            if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))                            {                                //设置图形位置与大小                                measureItem.Region = rectPara;                                //重新绘制测量区域路径                                OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(measureItem, rectPara);                                //恢复光标                                this.Cursor = System.Windows.Forms.Cursors.Default;                                foreach (ARectangleGDIObject item in m_RectangleGDIObjects)                                {                                    if (item.Region.Contains(e.Location))                                    {                                        m_IsSelectSampleStage = true;                                    }                                    else                                    {                                        m_IsSelectSampleStage = false;                                    }                                }                            }                            break;                        }                    }                    if (isChange)                    {                        //设置颜色                        if (m_SingleGDIObjects.Count > 0)                        {                            for (int i = 0; i < m_SingleGDIObjects.Count; i++)                            {                                string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);                                m_SingleGDIObjects[i].SelColor = ColorTranslator.FromHtml(ColorStr);                            }                        }                        //切换至测量模式                        m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;                        CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;                        showSingleInfo();                    }                    foreach (ARectangleGDIObject item in m_SampleGDIObjects)                    {                        //判断鼠标是否在样品中                        if (item.Region.Contains(e.Location))                        {                            if (item.IsWorkSample)                            {                                //获取原样品孔名称                                HoleName = item.Name;                                foreach (ARectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)                                {                                    //获取样品孔中心点                                           Point sampleHoleCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(sampleHoleItem);                                    //移动的样品在样品孔中心时                                    if (item.Region.Contains(sampleHoleCenterPoint))                                    {                                        if (item.Name != sampleHoleItem.Name)                                        {                                            sampleHoleItem.SampleCount += 1;                                            //样品孔信息                                            item.Name = sampleHoleItem.Name;                                            //样品Rectangle                                            item.Region = sampleHoleItem.Region;                                            item.RegionF = sampleHoleItem.RegionF;                                            item.DrawRegionF = sampleHoleItem.DrawRegionF;                                            IsContains++;                                            foreach (var sampleHoleCountItem in m_SampleHoleGDIObjects)                                            {                                                if (HoleName != string.Empty)                                                {                                                    if (sampleHoleCountItem.Name == HoleName)                                                    {                                                        //减少样品数量                                                        sampleHoleCountItem.SampleCount -= 1;                                                    }                                                }                                            }                                        }                                    }                                }                                //获取工作样品中的测量区域                                foreach (ARectangleGDIObject measureItem in m_MeasureGDIObjects)                                {                                    if (item.SampleName == measureItem.SampleName)                                    {                                        //设置样品与样品孔名称                                        measureItem.Name = item.Name;                                        measureItem.SampleName = item.SampleName;                                        Rectangle rectPara = item.Region;                                        RectangleF rectParaF = item.RegionF;                                        if (m_IsMoveSample)                                        {                                            #region 样品移动至其他样品台后 修改测量区域位置                                            rectPara.X = item.Region.X - m_MeasureToSamplePoint.X;                                            rectPara.Y = item.Region.Y - m_MeasureToSamplePoint.Y;                                            rectPara.Width = measureItem.Region.Width;                                            rectPara.Height = measureItem.Region.Height;                                            rectParaF.X = rectPara.X / m_GlobalZoomNum;                                            rectParaF.Y = rectPara.Y / m_GlobalZoomNum;                                            rectParaF.Width = measureItem.RegionF.Width;                                            rectParaF.Height = measureItem.RegionF.Height;                                            //判断移动到其他样品孔后、当前测量区域是否超越样品台边缘                                            int CheckShape = measureItem.Shape;                                            if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectPara, m_RectangleGDIObjects[0].Region, CheckShape))                                            {                                                measureItem.Region = rectPara;                                                measureItem.RegionF = rectParaF;                                                measureItem.DrawRegionF = rectParaF;                                            }                                            #endregion                                        }                                        //测量区域与样品中心相差的距离                                        measureItem.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, measureItem.Region);                                        //获取修改后的测量区域的位置与尺寸                                        if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))                                        {                                            //设置测量区域信息                                            measureItem.SampleName = item.SampleName;                                            measureItem.Name = item.Name;                                            //将所有帧图移动测量区域位置中                                            //获取样品孔 与 样品名称                                            foreach (var SampleItem in m_SampleGDIObjects)                                            {                                                if (item.IsWorkSample)                                                {                                                    //设置工作样品的测量区域 存在帧图                                                    foreach (var MeasureItem in m_MeasureGDIObjects)                                                    {                                                        if (MeasureItem.SampleName == item.SampleName)                                                        {                                                            //设置工作样品的测量区域 存在帧图标识                                                            if (m_SingleGDIObjects.Count > 0)                                                            {                                                                OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_SingleGDIObjects, MeasureItem);                                                            }                                                        }                                                    }                                                }                                            }                                            //更新Grid 工作样品属性值                                            m_MeasureAppForm.UpdateTreeSampleAndGridSampleVal();                                            Invalidate();                                            break;                                        }                                    }                                }                            }                        }                        if (item.IsWorkSample)                        {                            //设置颜色                            string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);                            item.SelColor = ColorTranslator.FromHtml(ColorStr);                        }                    }                    isChange = false;                }                //移动多边形的点后,显示已获取的帧图                if (m_IsSelPolygonPoint)                {                    foreach (var measureItem in m_MeasureGDIObjects)                    {                        if (measureItem.IsWorkSample)                        {                            if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))                            {                                if (measureItem.IsSingle)                                {                                    showSingleInfo();                                }                            }                        }                    }                }                Invalidate();            }            //样品台            MouseUpFucntion(m_RectangleGDIObjects, e);            //样品             MouseUpFucntion(m_SampleGDIObjects, e);            //样品孔            MouseUpFucntion(m_SampleHoleGDIObjects, e);            //标样            MouseUpFucntion(m_SpecimenGDIObjects, e);            //测量            MouseUpFucntion(m_MeasureGDIObjects, e);            //测量路径            MouseUpFucntion(m_MeasurePathGDIObjects, e);            //文字            MouseUpFucntion(m_ContentGDIObjects, e);            //帧图            MouseUpFucntion(m_SingleGDIObjects, e);            //已获取的帧图            MouseUpFucntion(m_ALLSingleGDIObjects, e);            //样品孔中BSE图片            MouseUpFucntion(m_ImageGDIObjects, e);            //SEM中心位置            MouseUpFucntion(m_SEMCenterGDIObjects, e);            //撤回原样品孔中            if (IsContains == 0)            {                foreach (var item in m_SampleGDIObjects)                {                    //if (item.Region.Contains(e.Location))                    //{                    //鼠标按下事件中获取选择的样品原有位置                    //如果没有找到其他样品孔的中心点,则将移动的样品设置为原位置                    foreach (ARectangleGDIObject sampleHoleItems in m_SampleHoleGDIObjects)                    {                        if (sampleHoleItems.SampleCount > 0)                        {                            if (item.IsWorkSample)                            {                                //设置颜色                                string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);                                item.SelColor = ColorTranslator.FromHtml(ColorStr);                                if (selectSampleGDIObjects != null)                                {                                    if (sampleHoleItems.Name == selectSampleGDIObjects.Name && item.SampleName == selectSampleGDIObjects.SampleName)                                    {                                        item.Region = sampleHoleItems.Region;                                        Invalidate();                                        break;                                    }                                }                            }                        }                    }                    //}                    //获取帧图与测量区域的相差的位置                    int m_singleDiffX = 0;                    int m_singleDiffY = 0;                    //如果当前样品没有移动至其他样品孔 测量区域恢复原位置                    if (m_IsMoveSample)                    {                        if (item.IsWorkSample)                        {                            foreach (var measureItem in m_MeasureGDIObjects)                            {                                if (measureItem.SampleName == item.SampleName)                                {                                    //获取测量区域与样品之间相差的距离                                    if (m_SingleGDIObjects.Count > 0)                                    {                                        m_singleDiffX = measureItem.Region.X - item.Region.X + m_MeasureToSamplePoint.X;                                        m_singleDiffY = measureItem.Region.Y - item.Region.Y + m_MeasureToSamplePoint.Y;                                    }                                    RectangleF rectParaF = item.RegionF;                                    Rectangle rectPara = item.Region;                                    rectPara.X = item.Region.X - m_MeasureToSamplePoint.X;                                    rectPara.Y = item.Region.Y - m_MeasureToSamplePoint.Y;                                    rectPara.Width = measureItem.Region.Width;                                    rectPara.Height = measureItem.Region.Height;                                    measureItem.Region = rectPara;                                    rectParaF.X = rectPara.X / m_GlobalZoomNum;                                    rectParaF.Y = rectPara.Y / m_GlobalZoomNum;                                    rectParaF.Width = measureItem.RegionF.Width;                                    rectParaF.Height = measureItem.RegionF.Height;                                    measureItem.RegionF = rectParaF;                                    measureItem.DrawRegionF = rectParaF;                                    break;                                }                            }                            //将帧图恢复至原位置                            foreach (var singleItem in m_SingleGDIObjects)                            {                                if (singleItem.SampleName == item.SampleName)                                {                                    RectangleF rectParaDrawF = singleItem.DrawRegionF;                                    RectangleF rectParaF = singleItem.RegionF;                                    Rectangle rectPara = singleItem.Region;                                    rectPara.X = singleItem.Region.X - m_singleDiffX;                                    rectPara.Y = singleItem.Region.Y - m_singleDiffY;                                    rectPara.Width = singleItem.Region.Width;                                    rectPara.Height = singleItem.Region.Height;                                    singleItem.Region = rectPara;                                    //更改帧图RegionF                                    rectParaF.X = singleItem.RegionF.X - m_singleDiffX;                                    rectParaF.Y = singleItem.RegionF.Y - m_singleDiffY;                                    singleItem.RegionF = rectParaF;                                    //更改帧图绘制原位置DrawRegionF                                    rectParaDrawF.X = (rectParaDrawF.X - m_singleDiffX / m_GlobalZoomNum);                                    rectParaDrawF.Y = (rectParaDrawF.Y - m_singleDiffY / m_GlobalZoomNum);                                    rectParaDrawF.Width = rectParaDrawF.Width;                                    rectParaDrawF.Height = rectParaDrawF.Height;                                    singleItem.DrawRegionF = rectParaDrawF;                                }                            }                            //删除已添加的帧图信息、重新添加帧图信息                            if (m_ALLSingleGDIObjects.Count > 0)                            {                                OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, item.SampleName);                                OTSSamplespaceGraphicsPanelFun.AddALLSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, item.SampleName);                            }                        }                    }                }            }            m_IsMoveSample = false;            m_MeasureToSamplePoint = new Point();            //计算两个点之间的距离 移动样品台后与绘制样品台时的位置            if (m_RectangleGDIObjects.Count > 0)            {                m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);            }            m_IsCtrl = false;            m_IsAlt = false;            m_IsSelPolygonPoint = false;            selWSampleMeasureStatus = false;        }        protected override void OnPaint(PaintEventArgs e)//处理重绘情况        {            OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_RectangleGDIObjects);             OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SampleHoleGDIObjects);            OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SampleGDIObjects);            OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SpecimenGDIObjects);            //切换显示样品孔中的文字            if (IsShowSampleHoleFont)            {                OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_ContentGDIObjects);            }            //切换显示样品孔中的BSE图片            if (IsShowSampleHoleImage)            {                if (m_ImageGDIObjects != null)                {                    if (m_ImageGDIObjects.Count > 0)                    {                        OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_ImageGDIObjects);                    }                }            }            OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_MeasurePathGDIObjects);            try            {                if (m_SingleGDIObjects != null)                {                    if (m_SingleGDIObjects.Count > 0)                    {                        OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SingleGDIObjects);                    }                }            }            catch (Exception)            {            }            //手动绘制测量区域            if (m_DrawMeasureGDIObjects != null)            {                if (m_DrawMeasureGDIObjects.Count > 0)                {                    for (int i = 0; i < m_DrawMeasureGDIObjects.Count; i++)                    {                        if (m_DrawMeasureGDIObjects[i] != null)                        {                            m_DrawMeasureGDIObjects[i].EndPoint = this.m_MouseMovePoint;                            m_DrawMeasureGDIObjects[i].OnPaint(e);                        }                    }                }            }            OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_MeasureGDIObjects);            OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SEMCenterGDIObjects);            if (m_IsDrawPolygonFinish || m_IsSelPolygonPoint)            {                OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_DrawPolygonFinishGDIObjects);            }        }        protected override void OnMouseWheel(MouseEventArgs e)        {            //如果正在进行测量线程,则退出鼠标点击操作            if (m_MeasureAppForm.MeasureThreadRunFlag)            {                return;            }            base.OnMouseWheel(e);            //设置记录每次比例缩放后的总体比例系数            if (e.Delta > 0)            {                m_GlobalZoomNum += 0.1f;            }            else            {                m_GlobalZoomNum -= 0.1f;                if (m_GlobalZoomNum < 1)                {                    m_GlobalZoomNum = 1;                }            }            if (e.Delta > 0)            {                //if (f_zoom_record <= f_zoom_max)                //{                #region //图形缩放计算部份-------放大------------//是放大                f_widthandheight_js = f_zoom_increment;                f_zoom_record = f_zoom_record + f_zoom_increment;                f_zoom_record = float.Parse(f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则                #endregion                #region 计算标尺尺寸部份-----放大------                //计算标尺实际占用像素的宽度                f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * f_zoom_increment);                control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);                //显示该像素宽度代表的实际宽度                control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));                //放大过长时,这里将宽度与代表的实际宽度进行折半显示                if (control_Ruler2.RulerWidth > 200)                {                    control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size) / 2;                }                #endregion                //}            }            else            {                if (f_zoom_record >= f_zoom_mix)                {                    #region //图形缩放计算部份------缩小--------------------                    f_widthandheight_js = -f_zoom_increment;                    f_zoom_record = f_zoom_record - f_zoom_increment;                    f_zoom_record = float.Parse(f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则                    #endregion                    #region 计算标尺尺寸部份-----缩小------f_onepixel_size,是不是该乘以rulerwidth是实际的长度                    f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * -f_zoom_increment);                    control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);                    control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));                    if (control_Ruler2.RulerWidth > 200)                    {                        control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size) / 2;                    }                    #endregion                }            }            if (m_GlobalZoomNum >= 1)            {                if (m_RectangleGDIObjects.Count > 0)                {                    //恢复图像初始位置                    OTSSamplespaceGraphicsPanelFun.RecoverInitialPosition(m_SingleGDIObjects, m_GlobalZoomNum);                    OTSSamplespaceGraphicsPanelFun.RecoverInitialPosition(m_ALLSingleGDIObjects, m_GlobalZoomNum);                    OTSSamplespaceGraphicsPanelFun.RecoverInitialPosition(m_ImageGDIObjects, m_GlobalZoomNum);                    //样品                    OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_SampleGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);                    //样品孔                    OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_SampleHoleGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);                    //标样                    OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_SpecimenGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);                    //测量区域                    OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_MeasureGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);                    //文字                    OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_ContentGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);                    //样品台                    OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_RectangleGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);                    if (m_GlobalZoomNum == 1)                    {                        // 将绘制的样品台信息 按屏幕中心移动                        //获取当前样品台中心点                        Point samplePoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0].Region);                        //获取当前工作区域中心点                        Point workAreaPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(this.ClientRectangle);                        //计算样品台中心点与工作区域中心点相差的距离                        PointF distancePoint = new PointF(samplePoint.X - workAreaPoint.X, samplePoint.Y - workAreaPoint.Y);                        if (distancePoint.X != 0 || distancePoint.Y != 0)                        {                            MoveToSrceenCenterFunction(distancePoint);                        }                        //标尺恢复初始                        f_ruler_size = f_old_ruler_size;                        control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);                        control_Ruler2.ShowString = "1000um";                        control_Ruler2.SetValueInspector(110, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));                    }                    //重新绘制                    Invalidate();                }            }        }        #endregion        #region 鼠标方法操作        public void MouseDownFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)        {            foreach (ARectangleGDIObject item in objList)            {                item.IsDragging = true;                item.DraggingPoint = e.Location;            }        }        public void MouseMoveFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)        {            foreach (ARectangleGDIObject item in objList)            {                if (item.IsDragging)                {                    item.Region = new Rectangle(                    item.Region.Left + Convert.ToInt32((e.X - item.DraggingPoint.X)),                    item.Region.Top + Convert.ToInt32((e.Y - item.DraggingPoint.Y)),                    item.Region.Width,                    item.Region.Height);                    item.RegionF = new RectangleF(                    item.RegionF.Left + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,                    item.RegionF.Top + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum,                    item.RegionF.Width,                    item.RegionF.Height);                    item.DrawRegionF = new RectangleF(                    item.DrawRegionF.Left + (float)(e.X - item.DraggingPoint.X),                    item.DrawRegionF.Top + (float)(e.Y - item.DraggingPoint.Y),                    item.DrawRegionF.Width,                    item.DrawRegionF.Height);                    item.LineStartPoint = new PointF(                    item.Region.Left + (e.X - item.DraggingPoint.X),                    item.Region.Top + (e.Y - item.DraggingPoint.Y));                    item.BSEImageLocation = new PointF(                    item.BSEImageLocation.X + e.X - item.DraggingPoint.X,                    item.BSEImageLocation.Y + e.Y - item.DraggingPoint.Y);                    //移动SEM中心点位置                    item.SEMCenterPoint = new PointF(                    item.SEMCenterPoint.X + (e.X - item.DraggingPoint.X),                    item.SEMCenterPoint.Y + (e.Y - item.DraggingPoint.Y));                    //多边形样品台移动                    if (item.Shape == (int)CreateRectangleType.Polygon)                    {                        if (item.DrawPolygonPointRegionF != null)                        {                            if (item.DrawPolygonPointRegionF.Count > 0)                            {                                int polygonPointCount = item.DrawPolygonPointRegionF.Count;                                if (polygonPointCount > 0)                                {                                    for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)                                    {                                        item.PolygonPointRegion[pointIndex] = new Point(                                        item.PolygonPointRegion[pointIndex].X + Convert.ToInt32((e.X - item.DraggingPoint.X)),                                        item.PolygonPointRegion[pointIndex].Y + Convert.ToInt32((e.Y - item.DraggingPoint.Y)));                                        item.PolygonPointRegionF[pointIndex] = new PointF(                                        item.PolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X),                                        item.PolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y));                                        //2020-12-1日注释                                        item.DrawPolygonPointRegionF[pointIndex] = new PointF(                                        item.DrawPolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,                                        item.DrawPolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum);                                    }                                }                            }                        }                    }                    item.DraggingPoint = e.Location;                    //重新绘制测量区域路径                    OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);                }            }        }        public void MouseMoveMeasureFucntion(ARectangleGDIObject item, MouseEventArgs e)        {            //判断移动的样品 是否在样品台尺寸范围内            Rectangle rectTemp = item.Region;            rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;            rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;            int CheckShape = (int)CreateRectangleType.Circle;            if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)            {                CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;            }            if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))            {                #region 需抽出作为公共方法                int xMove = rectTemp.X - item.Region.X;                int yMove = rectTemp.Y - item.Region.Y;                int Width = rectTemp.Width - item.Region.Width;                int Height = rectTemp.Height - item.Region.Height;                //设置图形大小                item.Region = rectTemp;                int WidthNew = (int)((item.RegionF.Width + Width / m_GlobalZoomNum));                int HeightNew = (int)((item.RegionF.Height + Height / m_GlobalZoomNum));                //设置原测量区域图形大小                float xMoveNew = (float)((item.RegionF.X + (xMove / m_GlobalZoomNum)));                float yMoveNew = (float)((item.RegionF.Y + (yMove / m_GlobalZoomNum)));                item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));                item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));                item.DraggingPoint = e.Location;                #endregion                //重新绘制测量区域路径                OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);                //帧图                MouseMoveSingleFucntion(m_SingleGDIObjects, e);                Invalidate();                return;            }        }        public void MouseMovePolygonMeasureFucntion(ARectangleGDIObject item, MouseEventArgs e)        {            //多边形样品台移动            if (item.Shape == (int)CreateRectangleType.Polygon)            {                //判断样品台形状                int CheckShape = (int)CreateRectangleType.Circle;                if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)                {                    CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;                }                //生成多边形最小面积外接矩形                Rectangle rectMeasureTemp = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);                //判断多边形是否超越样品台                rectMeasureTemp.X = rectMeasureTemp.Left + e.X - item.DraggingPoint.X;                rectMeasureTemp.Y = rectMeasureTemp.Top + e.Y - item.DraggingPoint.Y;                if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))                {                    int polygonPointCount = item.DrawPolygonPointRegionF.Count;                    if (polygonPointCount > 0)                    {                        for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)                        {                            item.PolygonPointRegion[pointIndex] = new Point(                            item.PolygonPointRegion[pointIndex].X + Convert.ToInt32((e.X - item.DraggingPoint.X)),                            item.PolygonPointRegion[pointIndex].Y + Convert.ToInt32((e.Y - item.DraggingPoint.Y)));                            item.PolygonPointRegionF[pointIndex] = new PointF(                            item.PolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X),                            item.PolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y));                            item.DrawPolygonPointRegionF[pointIndex] = new PointF(                            item.DrawPolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,                            item.DrawPolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum);                        }                        Rectangle rectTemp = item.Region;                        rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;                        rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;                        #region 需抽出作为公共方法                        int xMove = rectTemp.X - item.Region.X;                        int yMove = rectTemp.Y - item.Region.Y;                        int Width = rectTemp.Width - item.Region.Width;                        int Height = rectTemp.Height - item.Region.Height;                        //设置图形大小                        item.Region = rectTemp;                        int WidthNew = (int)((item.RegionF.Width + Width / m_GlobalZoomNum));                        int HeightNew = (int)((item.RegionF.Height + Height / m_GlobalZoomNum));                        //设置原测量区域图形大小                        float xMoveNew = (float)((item.RegionF.X + (xMove / m_GlobalZoomNum)));                        float yMoveNew = (float)((item.RegionF.Y + (yMove / m_GlobalZoomNum)));                        //item.Region = new Rectangle(new Point((int)xMoveNew, (int)yMoveNew), new Size(WidthNew, HeightNew));                        item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));                        item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));                        item.DraggingPoint = e.Location;                        #endregion                        ////生成多边形最小面积外接矩形                        //Rectangle rectPolygonMeasure = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);                        //item.Region = rectPolygonMeasure;                        //item.RegionF = rectPolygonMeasure;                        //item.DrawRegionF = rectPolygonMeasure;                    }                    item.DraggingPoint = e.Location;                    //重新绘制测量区域路径                    OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);                    //帧图                    MouseMoveSingleFucntion(m_SingleGDIObjects, e);                }            }                       Invalidate();            return;        }        public bool MoveMeasureInStage(ARectangleGDIObject item, Point m_StageCenterPoint, Point semLocation, double m_GlobalZoomNum)        {            //判断测量区域移动到SEM的当前位置 是否在样品台尺寸范围内            Rectangle rectTemp = item.Region;            rectTemp.X = m_StageCenterPoint.X + semLocation.X;// - rectTemp.Width / 2;             rectTemp.Y = m_StageCenterPoint.Y - semLocation.Y;// - rectTemp.Height/ 2;            rectTemp.Width = 2;            rectTemp.Height = 2;            int CheckShape = (int)CreateRectangleType.Circle;            if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)            {                CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;            }            if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))            {                return false;            }            return true;        }        public void MouseMoveSingleFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)        {            foreach (ARectangleGDIObject item in objList)            {                if (item.IsDragging)                {                    item.Region = new Rectangle(                    item.Region.Left + e.X - item.DraggingPoint.X,                    item.Region.Top + e.Y - item.DraggingPoint.Y,                    item.Region.Width,                    item.Region.Height);                    item.RegionF = new RectangleF(                    item.RegionF.Left + (e.X - item.DraggingPoint.X),                    item.RegionF.Top + (e.Y - item.DraggingPoint.Y),                    item.RegionF.Width,                    item.RegionF.Height);                    item.DrawRegionF = new RectangleF(                    item.DrawRegionF.Left + (e.X - item.DraggingPoint.X) / m_GlobalZoomNum,                    item.DrawRegionF.Top + (e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum,                    item.DrawRegionF.Width,                    item.DrawRegionF.Height);                    item.LineStartPoint = new PointF(                    item.Region.Left + (e.X - item.DraggingPoint.X),                    item.Region.Top + (e.Y - item.DraggingPoint.Y));                    item.DraggingPoint = e.Location;                    //重新绘制测量区域路径                    OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);                }            }        }        public void MouseUpFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)        {            foreach (ARectangleGDIObject item in objList)            {                if (item.IsDragging)                {                    item.IsSelect = false;                    item.IsDragging = false;                    item.DraggingPoint = Point.Empty;                    //item.IsWorkSample = false;                }            }        }        public void SizeChangeFucntion(List<ARectangleGDIObject> objList, float Zoom)        {            foreach (ARectangleGDIObject item in objList)            {                float x = item.RegionF.X * Zoom;                float y = item.RegionF.Y * Zoom;                float widthRect = item.RegionF.Width * Zoom;                float heightRect = item.RegionF.Height * Zoom;                //改变窗体时,修改图形位置与大小                item.Region = new Rectangle((int)x, (int)y, (int)widthRect, (int)heightRect);                item.RegionF = new RectangleF(x, y, widthRect, heightRect);                item.DrawRegionF = new RectangleF(x, y, widthRect, heightRect);            }        }        public void SizeFChangeFucntion(List<ARectangleGDIObject> objList, float Zoom)        {            foreach (ARectangleGDIObject item in objList)            {                float x = item.DrawRegionF.X * Zoom;                float y = item.DrawRegionF.Y * Zoom;                float widthRect = item.DrawRegionF.Width * Zoom;                float heightRect = item.DrawRegionF.Height * Zoom;                //改变窗体时,修改图形位置与大小                item.Region = new Rectangle((int)x, (int)y, (int)widthRect, (int)heightRect);                item.RegionF = new RectangleF(x, y, widthRect, heightRect);                item.DrawRegionF = new RectangleF(x, y, widthRect, heightRect);            }        }        /// <summary>        /// 将绘制的样品台信息 按屏幕中心移动        /// </summary>        public void MoveToSrceenCenterFunction(PointF distancePoint)        {            if (distancePoint.X != 0 || distancePoint.Y != 0)            {                //循环样品台上的图形,将其按工作区域中心点移动                MoveLocationToSrceenCenterFunction(m_RectangleGDIObjects, distancePoint);                MoveLocationToSrceenCenterFunction(m_SampleHoleGDIObjects, distancePoint);                MoveLocationToSrceenCenterFunction(m_SampleGDIObjects, distancePoint);                MoveLocationToSrceenCenterFunction(m_SpecimenGDIObjects, distancePoint);                MoveLocationToSrceenCenterFunction(m_ContentGDIObjects, distancePoint);                MoveLocationToSrceenCenterFunction(m_MeasureGDIObjects, distancePoint);                MoveLocationToSrceenCenterFunction(m_MeasurePathGDIObjects, distancePoint);                MoveLocationToSrceenCenterFunction(m_SingleGDIObjects, distancePoint);                MoveLocationToSrceenCenterFunction(m_ImageGDIObjects, distancePoint);            }        }        public void MoveLocationToSrceenCenterFunction(List<ARectangleGDIObject> objList, PointF distancePoint)        {            foreach (var item in objList)            {                if (item.Shape == (int)CreateRectangleType.Polygon)                {                    for (int i = 0; i < item.PolygonPointRegion.Count; i++)                    {                        item.PolygonPointRegion[i] = new Point((int)(item.PolygonPointRegion[i].X - distancePoint.X), (int)(item.PolygonPointRegion[i].Y - distancePoint.Y));                        item.PolygonPointRegionF[i] = new PointF(item.PolygonPointRegionF[i].X - distancePoint.X, (item.PolygonPointRegionF[i].Y - distancePoint.Y));                        item.DrawPolygonPointRegionF[i] = new PointF(item.DrawPolygonPointRegionF[i].X - distancePoint.X, (item.DrawPolygonPointRegionF[i].Y - distancePoint.Y));                    }                }                item.Region = new Rectangle((int)((item.Region.X - distancePoint.X)), (int)(item.Region.Y - distancePoint.Y), item.Region.Width, item.Region.Height);                item.RegionF = new RectangleF((item.RegionF.X - distancePoint.X), (item.RegionF.Y - distancePoint.Y), item.RegionF.Width, item.RegionF.Height);                item.DrawRegionF = new RectangleF((item.DrawRegionF.X - distancePoint.X), (item.DrawRegionF.Y - distancePoint.Y), item.DrawRegionF.Width, item.DrawRegionF.Height);                item.BSEImageWitdh = item.Region.Width;                item.BSEImageHeight = item.Region.Height;                item.BSEImageLocation = item.Region.Location;                //重新绘制测量区域路径                OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);            }        }        #endregion        #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);                    break;                case "DeleteStage":                    //删除样品                    OTSSamplespaceGraphicsPanelFun.DeleteSampleInfo(m_MeasureAppForm, m_SampleSelectName);                    break;                case "DriveSEMToCenterLocation":                    //驱动SEM到中心位置                    SetSEMToCenterPoint();                    break;                case "DriveSEMToCurrentLocation":                    //驱动SEM到当前位置                    SetSEMCurrentLocation();                    break;                case "SetSEMCenterLocation":                    //将测量区域移到SEM当前位置                    SetMeasureToSEMLocation();                    break;                case "ReadSEMData":                    m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;                    //设定SEM数据                    CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;                    GetSingleInfo();                    // 根据已完成测量的帧图信息 绘制帧图已完成状态                     GetSingleInfoForSampleNameAndOTSSamplespaceWindow();                    break;                case "SetSemData":                    double SemMag = 0;                    double dDistance = 0;                    log.Trace("OTSSamplespaceWindow_CMStrip_ItemClicked:--begin--");                    if (m_MeasureAppForm.m_ProjParam.GetMagAndDistance(ref SemMag, ref dDistance))                    {                        //设置SEM数据                        bool IsTrue = SetSEMDATAMParameter(SemMag, dDistance);                        if (!IsTrue)                        {                            log.Error("OTSSamplespaceWindow_CMStrip_ItemClicked:--SetSemData:--Mag:" + SemMag + "--Distance:" + dDistance + "--");                        }                    }                    break;                case "ShootBSEPicture":                    //设置消息类型 拍摄样品孔                    m_MeasureAppForm.m_MessageStates = MessageState.ShotBSEPicture;                    //清除原图片信息                    DeleteHoleBSEImageDataNoMessageBox();                    //记录当前放大倍数 在停止拍摄图片后设置回原放大倍数                    m_MeasureAppForm.m_ProjParam.GetWorkingSampleSEMData(ref m_PropIWDistance, ref m_PropDMagni);                    GetSEMDATAMParameter(ref m_SEMDMagni, ref m_SEMIWDistance);                    GetBSEPictures();                    break;                case "DeleteBSEPicture":                    DeleteHoleBSEImageData();                    break;            }        }        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)        {            //键盘抬起时,将选择区域的标识 设置为未选择状态            m_IsMeasure = false;            this.Cursor = System.Windows.Forms.Cursors.Default;            //删除正在绘制的多边形的点            if (e.KeyValue == (int)Keys.Back)            {                if (m_IsDrawMeasure)                {                    if (m_PolygonPoint.Count > 0)                    {                        for (int i = m_PolygonPoint.Count - 1; i >= 0;)                        {                            m_PolygonPoint.RemoveAt(i);                            break;                        }                    }                }                if (m_PolygonPoint.Count == 0)                {                    //设置手绘标识                    m_IsDrawMeasureReady = false;                    m_IsDrawMeasure = false;                    m_IsDrawPolygonFinish = false;                }                this.Invalidate();            }        }        public void KeyDowns()        {            //鼠标相对于屏幕的坐标            Point p1 = MousePosition;            //鼠标相对于窗体的坐标            Point p2 = this.PointToClient(p1);            Pen GrayPen = new Pen(Color.Gray, m_PenWidth);            //设置鼠标在样品测量区域上的样式            foreach (ARectangleGDIObject item in m_MeasureGDIObjects)            {                if (!item.SelColor.Name.Equals("Transparent"))                {                    //判断鼠标是否在测量区域的绘制线上,更改光标样式                    if (item.GPath != null)                    {                        if (item.CreateType == (int)CreateRectangleType.Polygon)                        {                            //在多边形点附近切换光标                            foreach (PointF itemPoint in item.PolygonPointRegionF)                            {                                if (Math.Abs(itemPoint.X - p2.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - p2.Y) <= m_OffsetPX)                                {                                    if (Control.ModifierKeys == Keys.Control)                                    {                                        this.Cursor = System.Windows.Forms.Cursors.Hand;                                        return;                                    }                                }                            }                        }                        else                        {                            if (item.GPath.IsOutlineVisible(p2, GrayPen))                            {                                if (Control.ModifierKeys == Keys.Control)                                {                                    this.Cursor = System.Windows.Forms.Cursors.NoMove2D;                                    return;                                }                            }                        }                    }                    //判断鼠标是否在测量区域内,更改光标样式                    if (item.GPath != null)                    {                        if (!m_IsSelPolygonPoint)                        {                            if (item.GPath.IsVisible(p2))                            {                                if (Control.ModifierKeys == Keys.Control)                                {                                    if (!m_IsMeasure)                                    {                                        this.Cursor = System.Windows.Forms.Cursors.SizeAll;                                        return;                                    }                                }                            }                        }                    }                    if (item.Region.Contains(p2))                    {                        if (!m_IsSelPolygonPoint)                        {                            if (Control.ModifierKeys == Keys.Control)                            {                                if (!m_IsMeasure)                                {                                    this.Cursor = System.Windows.Forms.Cursors.SizeAll;                                    return;                                }                            }                        }                    }                }            }            //设置鼠标在样品上的样式            foreach (ARectangleGDIObject item in m_SampleGDIObjects)            {                if (!item.SelColor.Name.Equals("Transparent"))                {                    if (item.Region.Contains(p2))                    {                        if ((Control.ModifierKeys == Keys.Alt))                        {                            if (!m_IsMeasure)                            {                                this.Cursor = System.Windows.Forms.Cursors.SizeAll;                                return;                            }                        }                    }                }            }        }        public void KeyUps()        {            //鼠标相对于屏幕的坐标            Point p1 = MousePosition;            //鼠标相对于窗体的坐标            Point p2 = this.PointToClient(p1);            Pen GrayPen = new Pen(Color.Gray, m_PenWidth);            foreach (ARectangleGDIObject item in m_RectangleGDIObjects)            {                if (item.Region.Contains(p2))                {                    m_RectangIsDragging = true;                    m_IsSelectSampleStage = true;                }            }            //键盘抬起时,将选择区域的标识 设置为未选择状态            m_IsMeasure = false;            this.Cursor = System.Windows.Forms.Cursors.Default;        }        #endregion        #region 处理方法总汇        #region 清除所需图形        public void ClearDrawInfoForChangeWindownSize()        {            try            {                if (m_RectangleGDIObjects != null)                {                    m_RectangleGDIObjects.Clear();                }                if (m_SampleHoleGDIObjects != null)                {                    m_SampleHoleGDIObjects.Clear();                }                if (m_SpecimenGDIObjects != null)                {                    m_SpecimenGDIObjects.Clear();                }                if (m_ContentGDIObjects != null)                {                    m_ContentGDIObjects.Clear();                }            }            catch (Exception ex)            {                string message = table["message2"].ToString();                log.Error("OTSSamplespaceWindow_ClearDrawInfo():--" + message + ":" + ex.ToString() + "");            }        }        public void ClearDrawInfo()        {            try            {                if (m_RectangleGDIObjects != null)                {                    m_RectangleGDIObjects.Clear();                }                if (m_MeasureGDIObjects != null)                {                    m_MeasureGDIObjects.Clear();                }                if (m_MeasurePathGDIObjects != null)                {                    m_MeasurePathGDIObjects.Clear();                }                if (m_SampleGDIObjects != null)                {                    m_SampleGDIObjects.Clear();                }                if (m_SampleHoleGDIObjects != null)                {                    m_SampleHoleGDIObjects.Clear();                }                if (m_SpecimenGDIObjects != null)                {                    m_SpecimenGDIObjects.Clear();                }                if (m_ContentGDIObjects != null)                {                    m_ContentGDIObjects.Clear();                }                if (m_SingleGDIObjects != null)                {                    m_SingleGDIObjects.Clear();                }                if (m_ImageGDIObjects != null)                {                    m_ImageGDIObjects.Clear();                }                if (m_ImageSingleGDIObjects != null)                {                    m_ImageSingleGDIObjects.Clear();                }                if (m_DrawMeasureGDIObjects != null)                {                    m_DrawMeasureGDIObjects.Clear();                }                if (m_SEMCenterGDIObjects != null)                {                    m_SEMCenterGDIObjects.Clear();                }                if (m_ALLSingleGDIObjects != null)                {                    m_ALLSingleGDIObjects.Clear();                }            }            catch (Exception ex)            {                string message = table["message2"].ToString();                log.Error("OTSSamplespaceWindow_ClearDrawInfo():--" + message + ":" + ex.ToString() + "");            }        }        #endregion        #endregion        #region 绘制样品以及测量区域        /// <summary>        /// 绘制样品以及测量区域        /// </summary>        /// <param name="SMeasrueAreaList">测量区域的集合</param>        public void DrawSampleAndMeasureInfo(List<SampleMeasurePara> SMeasrueAreaList)        {            //获取样品孔            if (SMeasrueAreaList.Count > 0)            {                for (int i = 0; i < SMeasrueAreaList.Count; i++)                {                    foreach (var item in m_SampleHoleGDIObjects)                    {                        if (item.Name == SMeasrueAreaList[i].sHoleName)                        {                            if (CStageManage.AddOnlySample(SMeasrueAreaList[i].sHoleName, SMeasrueAreaList[i].sSampleName, this))                            {                                //获取样品信息                                Point xHole = new Point(SMeasrueAreaList[i].MeasureRect.Left, SMeasrueAreaList[i].MeasureRect.Top);                                Point yHole = new Point(SMeasrueAreaList[i].MeasureRect.Right, SMeasrueAreaList[i].MeasureRect.Bottom);                                //获取测量区域中的四个点位置                                int left = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(xHole.X), IsWidth, m_DefaultW, m_DefaultH));                                int top = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(xHole.Y), IsWidth, m_DefaultW, m_DefaultH));                                int right = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(yHole.X), IsWidth, m_DefaultW, m_DefaultH));                                int bottom = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(yHole.Y), IsWidth, m_DefaultW, m_DefaultH));                                //生成测量区域的绘制点                                Point StartPoint = new Point(Math.Abs(left), Math.Abs(top));                                Size endPoint = new Size(Math.Abs(right), Math.Abs(bottom));                                //定义测量区域                                Rectangle rectMeasure = new Rectangle(StartPoint, endPoint);                                //获取样品信息                                Rectangle rectSample = new Rectangle();                                Point sampleCenterDifferPoint = new Point();                                foreach (var itemSample in m_SampleGDIObjects)                                {                                    if (item.Name == itemSample.Name)                                    {                                        rectSample = item.Region;                                        //获取测量区域中心与样品中心相差的距离                                        sampleCenterDifferPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectMeasure, rectSample);                                        break;                                    }                                }                                if (SMeasrueAreaList[i].iShape == (int)CreateRectangleType.Polygon)                                {                                    //多边形测量区域完成标识                                    m_DrawPolygonFinishGDIObjects = new List<ARectangleGDIObject>();                                    //获取样品台 中心点                                    PointF RectanglePointCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPointF(m_RectangleGDIObjects[0].RegionF);                                    //获取样品台中心点                                    int w = (IsWidth == 0 ? m_DefaultW : m_DefaultH);                                    float CenterX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.X, m_WDomain, w);                                    float CenterY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.Y, m_WDomain, w);                                    //绘制多边形测量区域                                    List<PointF> drawPointList = new List<PointF>();                                    for (int pointIndex = 0; pointIndex < SMeasrueAreaList[i].DrawPolygonPointRegionF.Count; pointIndex++)                                    {                                        float offX = CenterX + SMeasrueAreaList[i].PolygonPointRegionF[pointIndex].X;                                        float offY = CenterY - SMeasrueAreaList[i].PolygonPointRegionF[pointIndex].Y;                                        //获取测量区域中的四个点位置                                        float X = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(offX), IsWidth, m_DefaultW, m_DefaultH));                                        float Y = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(offY), IsWidth, m_DefaultW, m_DefaultH));                                        PointF DrawPoint = new PointF(X / m_GlobalZoomNum, Y / m_GlobalZoomNum);                                        drawPointList.Add(DrawPoint);                                    }                                    CreateRectangle createFinishPoint = new CreateRectangle(drawPointList, (int)CreateRectangleType.Polygon, m_DrawMeasureType, SMeasrueAreaList[i].sHoleName, SMeasrueAreaList[i].sSampleName, Color.Red);                                    GraphicsPath PolygonMeasurePath = new GraphicsPath();                                    PolygonMeasurePath.AddPolygon(drawPointList.ToArray());                                    createFinishPoint.GPath = PolygonMeasurePath;                                    m_DrawMeasureGDIObjects.Add(createFinishPoint);                                    //设置测量区域位置与尺寸                                    //获取外接矩形                                    Rectangle polygonRectPara = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(drawPointList);                                    m_DrawMeasureGDIObjects[0].Region = polygonRectPara;                                    m_DrawMeasureGDIObjects[0].RegionF = polygonRectPara;                                    m_DrawMeasureGDIObjects[0].DrawRegionF = polygonRectPara;                                    //将绘制好的多边形测量区域赋值给 多边形测量区域对象                                    m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);                                    m_DrawMeasureGDIObjects.Clear();                                    if (m_DrawPolygonFinishGDIObjects != null)                                    {                                        m_DrawPolygonFinishGDIObjects.Clear();                                    }                                    //设置手绘标识                                    m_IsDrawMeasureReady = false;                                    m_IsDrawMeasure = false;                                    m_IsDrawPolygonFinish = false;                                    break;                                }                                else                                {                                    //正常绘制测量区域                                    CreateRectangle cRect = OTSSamplespaceGraphicsPanelFun.GetPixRect(m_WDomain, xHole, yHole, SMeasrueAreaList[i].iShape, "", "", IsWidth, m_DefaultW, m_DefaultH);                                    //测量区域名称 样品名称                                    cRect.SampleName = SMeasrueAreaList[i].sSampleName;                                    cRect.Name = SMeasrueAreaList[i].sHoleName;                                    //测量区域类型                                     cRect.CreateType = SMeasrueAreaList[i].iShape;                                    if (CStageManage.AddMeasure(cRect.CreateType, cRect))                                    {                                        break;                                    }                                }                            }                        }                    }                }            }        }        #endregion        #region 获取工作样品的测量区域信息        public SampleMeasurePara GetSampleMeasureRect(ARectangleGDIObject MeasureItem)        {            int w = (IsWidth == 0 ? Width : Height);            int iShape = 0;            Rectangle Srect = new Rectangle();            SampleMeasurePara sampleMeasureParas = new SampleMeasurePara();            //获取当前工作的测量区域信息            bool returnResult = m_MeasureAppForm.m_ProjParam.GetWSampleMrsArea(ref iShape, ref Srect);            sampleMeasureParas.iShape = iShape;            sampleMeasureParas.MeasureRect = Srect;            sampleMeasureParas.sHoleName = MeasureItem.Name;            sampleMeasureParas.sSampleName = MeasureItem.SampleName;            if (MeasureItem.CreateType == (int)CreateRectangleType.Polygon)            {                //获取测量区域中的四个点位置                float Left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Left, m_WDomain, w);                float Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Top, m_WDomain, w);                float Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Right, m_WDomain, w);                float Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Bottom, m_WDomain, w);                float Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Width, m_WDomain, w);                float Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Height, m_WDomain, w);                //生成测量区域的绘制点                Point StartPoint = new Point((int)Left, (int)Top);                Size endPoint = new Size((int)Right, (int)Bottom);                //定义测量区域                Rectangle rectMeasure = new Rectangle(StartPoint, endPoint);                sampleMeasureParas.PolygonPointRegion = MeasureItem.PolygonPointRegion;                sampleMeasureParas.PolygonPointRegionF = MeasureItem.PolygonPointRegionF;                sampleMeasureParas.DrawPolygonPointRegionF = MeasureItem.DrawPolygonPointRegionF;            }            return sampleMeasureParas;        }        /// <summary>        /// 获取所有测量区域的位置        /// </summary>        /// <param name="MeasureItem"></param>        /// <returns></returns>        public List<SampleMeasurePara> GetALLSampleMeasureRect()        {            Rectangle Srect = new Rectangle();            List<SampleMeasurePara> sampleMeasureParasList = new List<SampleMeasurePara>();            List<COTSSample> cSample = m_MeasureAppForm.m_ProjParam.m_ResultData.GetSampleList();            foreach (var item in cSample)            {                CDomain pMsrArea = new CDomain();                pMsrArea = item.GetMsrArea();                ValueType ValType = new Rectangle();                ValType = pMsrArea.GetRectDomain();                Srect = (Rectangle)ValType;                SampleMeasurePara sampleMeasureParas = new SampleMeasurePara();                sampleMeasureParas.iShape = (int)pMsrArea.GetShape();                sampleMeasureParas.MeasureRect = Srect;                sampleMeasureParas.sHoleName = item.GetSampleHoleName();                sampleMeasureParas.sSampleName = item.GetName();                List<Point> Points = item.GetMsrArea().GetPolygonPoint();                List<PointF> PointFs = OTSSamplespaceGraphicsPanelFun.PointConvertPointF(Points);                sampleMeasureParas.PolygonPointRegion = Points;                sampleMeasureParas.PolygonPointRegionF = PointFs;                sampleMeasureParas.DrawPolygonPointRegionF = PointFs;                sampleMeasureParasList.Add(sampleMeasureParas);            }            return sampleMeasureParasList;        }        #endregion        #region 获取帧图信息        public void GetSingleInfo()        {            #region 设置电镜参数            //判断是否为模拟模式            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);                    //设置工作样品的测量区域 存在帧图                    foreach (var MeasureItem in m_MeasureGDIObjects)                    {                        if (MeasureItem.IsWorkSample)                        {                            //设置工作样品的测量区域 存在帧图标识                            MeasureItem.IsSingle = true;                            break;                        }                    }                    //将右键SEM数据菜单设置为可编辑状态                    CMStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;                                    }                //m_SEMDATAFieldManage.CloseSEM();            }                       #endregion            #endregion            if (m_SingleGDIObjects != null)            {                showSingleInfo();            }        }        #region 获取Filed帧图        public List<Rectangle> GetFieldRects()        {            List<Point> listCenterPoint = new List<Point>();            Size rectSize = new Size();            //获取所有帧图的中心点信息 与矩形尺寸信息            bool flag = GetField(ref listCenterPoint, ref rectSize);            //将所有中心点 转换为矩形            List<Rectangle> returnRectList = new List<Rectangle>();            foreach (Point item in listCenterPoint)            {                returnRectList.Add(new Rectangle(item, rectSize));            }            return returnRectList;        }        public bool GetField(ref List<Point> pFields, ref Size iSzie)        {            var m_ResultData = m_MeasureAppForm.m_ProjParam.m_ResultData;                        COTSSample WSample = m_ResultData.GetWorkingSample();            if (null == WSample)            {                return false;            }            CDomain pMsrArea = WSample.GetMsrArea();            //m_MeasureAppForm.m_ProjParam.m_ResultData.GetImageProcParam            COTSImgScanPrm pImgScanParam = WSample.GetMsrParams().GetImageScanParam();            CSEMDataMsr pSEMDataMsr = WSample.GetSEMDataMsr();                  CFieldPositionMgr pFieldMgr = new CFieldPositionMgr();            List<Point> listPoint = new List<Point>();            listPoint.Clear();            //设置测量区域                      if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)            {                //获取最小放大倍数与FieldSize100倍数                pSEMDataMsr.SetScanFieldSize100(m_OTSSampleStageData.iScanFieldSize100);                double dMagnification = m_MeasureAppForm.m_ProjParam.m_DefaultParam.GetStageDataParam().GetMinMag();                pSEMDataMsr.SetMagnification(dMagnification);                //设置样品孔当前位置信息                Rectangle sampleHoleRect = CMeasureThreadWrapper.c_DomainMessure.GetRectDomain();                //判断                if ((int)this.CMStrip.Items[9].Tag == 1)                {                    int shape = 0;                    foreach (var item in m_SampleHoleGDIObjects)                    {                        if (item.Name == WSample.GetName())                        {                            shape = item.Shape;                        }                    }                    pMsrArea.SetShape((DOMAIN_SHAPE)shape);                }                pMsrArea.SetRectDomain(sampleHoleRect);                     }            else if (m_MeasureAppForm.m_MessageStates == MessageState.MeasureBSEPicture)            {                //获取最小放大倍数与FieldSize100倍数                pSEMDataMsr.SetScanFieldSize100(m_OTSSampleStageData.iScanFieldSize100);                double dMagnification = WSample.GetSEMDataMsr().GetMagnification();                pSEMDataMsr.SetMagnification(dMagnification);                //设置样品孔当前位置信息                Rectangle sampleHoleRect = CMeasureThreadWrapper.c_DomainMessure.GetRectDomain();                pMsrArea.SetRectDomain(sampleHoleRect);                   }            else            {                try                {                    //设置当前工作区域                    if (CMeasureThreadWrapper.c_DomainMessure != null)                    {                        Rectangle measureRect = CMeasureThreadWrapper.c_DomainMessure.GetRectDomain();                        pMsrArea.SetRectDomain(measureRect);                    }                }                catch (Exception ex)                {                    log.Error("获取幁图数问题:" + ex.ToString());                }                pSEMDataMsr.SetScanFieldSize100(m_OTSSampleStageData.iScanFieldSize100);                double dMagnification = WSample.GetSEMDataMsr().GetMagnification();                pSEMDataMsr.SetMagnification(dMagnification);                         }            ////初始化            if (!pFieldMgr.Init(pMsrArea, pImgScanParam, pSEMDataMsr, listPoint))            {                return false;            }            //获取幁图的中心点            pFields = pFieldMgr.GetFieldCentrePoints();            //获取幁图数            int iFieldCount = pFieldMgr.GetTotalFields();            var oValue = new Rectangle();            if (!pFieldMgr.GetFieldRectByIndex(0, ref oValue))            {                return false;            }            iSzie = oValue.Size;            //将幁图数赋值给工作样品后           WSample.GetSEMDataMsr().SetTotalFields(iFieldCount);            return true;        }        #endregion        public void showSingleInfo()        {            try            {                if (m_SingleGDIObjects == null)                {                    return;                }                //清除帧图信息                ClearImageAndSingleGDIObjects();                #region 获取帧图与绘制帧图                    #region 获取当前工作的测量区域信息                //是否获取过帧图标识                bool IsSingle = false;                if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)                {                    //设置测量区域形状与位置                    IsSingle = SetWorkSampleMeasureArea();                    if (!IsSingle)                    {                        return;                    }                }                #endregion                //获取Field集合                m_RectFieldRects = GetFieldRects();                if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)                {                    m_MeasureAppForm.UpdatePropertyVal();                }                //如果当前工作样品是多边形则设置回原测量区域参数                if (IsSingle)                {                    foreach (var MeasureItem in m_MeasureGDIObjects)                    {                        if (MeasureItem.IsSingle && MeasureItem.IsWorkSample)                        {                            if (MeasureItem.CreateType == (int)CreateRectangleType.Polygon)                            {                                SetWorkSampleMeasureArea((int)CreateRectangleType.Polygon);                            }                        }                    }                }                //样品孔名称与样品名称                string sampleName = string.Empty;                string sampleHoleName = string.Empty;                //获取样品孔 与 样品名称                foreach (var item in m_SampleGDIObjects)                {                    if (item.IsWorkSample)                    {                        sampleName = item.SampleName;                        sampleHoleName = item.Name;                    }                }                //以矩形绘制帧图                for (int i = m_RectFieldRects.Count - 1; i >= 0; i--)                {                    Point pt = new Point(m_RectFieldRects[i].X, m_RectFieldRects[i].Y);                    pt.X = m_RectFieldRects[i].X - m_RectFieldRects[i].Width / 2;                    pt.Y = m_RectFieldRects[i].Y + m_RectFieldRects[i].Height / 2;                    //获取Rectang 两点信息                    Point XSTD = new Point(m_RectFieldRects[i].Left, m_RectFieldRects[i].Top);                    Point YSTD = new Point(m_RectFieldRects[i].Right, m_RectFieldRects[i].Bottom);                    //绘制帧图                    RectangleF rectSingle = OTSSamplespaceGraphicsPanelFun.GetPixRectF(m_WDomain, XSTD, YSTD, sampleName, sampleHoleName, IsWidth, Width, Height);                    //设置每一个帧图的宽与高 以中心点大小为标准                    rectSingle = new RectangleF(new PointF(rectSingle.X, rectSingle.Y), new SizeF(rectSingle.Width, rectSingle.Height));                    //添加所有转换后的RectangleF                    //根据缩放倍数                    float xZoom = (rectSingle.X * m_GlobalZoomNum);                    float yZoom = (rectSingle.Y * m_GlobalZoomNum);                    float widthZoom = (rectSingle.Width * m_GlobalZoomNum);                    float heightZoom = (rectSingle.Height * m_GlobalZoomNum);                    RectangleF rectZoomSingle = new RectangleF(xZoom, yZoom, widthZoom, heightZoom);                    //设置颜色                    string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);                    CreateRectangle createRect = new CreateRectangle(rectZoomSingle, m_RectFieldRects[i].X, m_RectFieldRects[i].Y, (int)CreateRectangleType.SingleRectangle, sampleHoleName, sampleName, ColorTranslator.FromHtml(ColorStr));                    //如果选择为测量区域BSE照片 则添加样品名称                    if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)                    {                        if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.StartMeasure)                        {                            createRect.SampleName = sampleName;                        }                    }                    createRect.Name = sampleHoleName;                    //保留原帧图位置与大小                    createRect.RegionF = rectZoomSingle;                    createRect.DrawRegionF = rectSingle;                    //拍摄样品孔照片                    if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)                    {                        //添加样品孔图片列表                        m_ImageSingleGDIObjects.Add(createRect);                    }                    else if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)                    {                        //添加帧图列表                        m_SingleGDIObjects.Add(createRect);                    }                }                if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)                {                    //添加帧图信息                    OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, sampleName);                    OTSSamplespaceGraphicsPanelFun.AddALLSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, sampleName);                }                //将所有帧图移植测量区域位置中                //获取样品孔 与 样品名称                foreach (var item in m_SampleGDIObjects)                {                    if (item.IsWorkSample)                    {                        sampleName = item.SampleName;                        sampleHoleName = item.Name;                        if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)                        {                            //设置工作样品的测量区域 存在帧图                            foreach (var MeasureItem in m_MeasureGDIObjects)                            {                                if (MeasureItem.SampleName == item.SampleName)                                {                                    //设置工作样品的测量区域 存在帧图标识                                    if (m_SingleGDIObjects.Count > 0)                                    {                                        //if (!(MeasureItem.CreateType == (int)CreateRectangleType.Polygon))                                        //{                                        OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_SingleGDIObjects, MeasureItem);                                        //}                                    }                                    break;                                }                            }                        }                        if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)                        {                            if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)                            {                                if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)(int)MessageState.ShotBSEPicture)                                {                                    //设置工作样品的测量区域 存在帧图                                    foreach (var SampleHoleItem in m_SampleHoleGDIObjects)                                    {                                        if (SampleHoleItem.Name == item.Name)                                        {                                            //设置工作样品的测量区域 存在帧图标识                                            if (m_ImageSingleGDIObjects.Count > 0)                                            {                                                OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_ImageSingleGDIObjects, SampleHoleItem);                                            }                                            break;                                        }                                    }                                }                                else                                {                                    //设置工作样品的测量区域 存在帧图                                    foreach (var MeasureItem in m_MeasureGDIObjects)                                    {                                        if (MeasureItem.SampleName == item.SampleName)                                        {                                            //设置工作样品的测量区域 存在帧图标识                                            if (m_ImageSingleGDIObjects.Count > 0)                                            {                                                OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_ImageSingleGDIObjects, MeasureItem);                                            }                                            break;                                        }                                    }                                }                            }                        }                    }                }                Invalidate();                #endregion            }            catch (Exception ex)            {                string message = table["message2"].ToString();                log.Error("OTSSamplespaceWindow_CMStrip_ItemClicked:--" + message + ":" + ex.ToString());            }        }        #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())            {                //获取电镜参数                List<double> semParameters = m_SEMDATAFieldManage.GetSEMMagAndWDParameter();                bool mFlag = false;                bool wFlag = false;                         mFlag = m_SEMDATAFieldManage.SetSEMMagnificationParameter(magnification);                wFlag = m_SEMDATAFieldManage.SetSEMWorkingDistanceParameter(semWorkingDistance);                                         if (mFlag || wFlag)                {                    return true;                }                //m_SEMDATAFieldManage.CloseSEM();            }            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];                //m_SEMDATAFieldManage.CloseSEM();                return true;            }            return false;            #endregion        }        #endregion        #region 驱动到SEM当前位置        protected void SetMeasureToSEMLocation()        {            try            {                //获取SEM位置                List<double> SemLocation = new List<double>();                if (GetSemLocation(ref SemLocation))                {                    //SemLocation[0] = 60000;                    //SemLocation[1] = 60000;                    Point OTSLocation = m_MeasureAppForm.m_ProjParam.ConverSEMToOTSPoint(new Point((int)SemLocation[(int)XYIndex.X], (int)SemLocation[(int)XYIndex.Y]));                    //转换为工作区域位置坐标                    int w = (int)OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(OTSLocation.X), IsWidth, m_DefaultW, m_DefaultH);                    int h = (int)OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(OTSLocation.Y), IsWidth, m_DefaultW, m_DefaultH);                    //样品台中心点                    Point m_StageCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0]);                    Point moveToSEMLocation = new Point(w, h);                    //根据鼠标右键点击的位置 重新绘制帧图                    if (m_MeasureGDIObjects != null)                    {                        if (m_MeasureGDIObjects.Count > 0)                        {                            foreach (var MeasureItem in m_MeasureGDIObjects)                            {                                if (MeasureItem.IsWorkSample)                                {                                    bool selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();                                    if (selWSampleMeasureStatus)                                    {                                        return;                                    }                                    if (MoveMeasureInStage(MeasureItem, m_StageCenterPoint, moveToSEMLocation, m_GlobalZoomNum))                                    {                                        if (OTSSamplespaceGraphicsPanelFun.NewLocationDrawSingleInfo(m_MeasureAppForm, this, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth, moveToSEMLocation, m_SingleGDIObjects, MeasureItem, m_GlobalZoomNum))                                        {                                            //根据鼠标右键点击的位置 重新绘制区域                                            OTSSamplespaceGraphicsPanelFun.NewLocationDrawMeasureInfo(this, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth, moveToSEMLocation, m_MeasureGDIObjects, m_GlobalZoomNum);                                            //根据鼠标右键点击的位置 重新绘制区域路径                                            OTSSamplespaceGraphicsPanelFun.NewLocationDrawMeasureInfo(this, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth, moveToSEMLocation, m_MeasurePathGDIObjects, m_GlobalZoomNum);                                            //设置当前测量区域的位置                                            bool result = OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(MeasureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain);                                            //删除已存在的帧图信息  在重新添加当前操作的帧图信息                                            OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, MeasureItem.SampleName);                                            OTSSamplespaceGraphicsPanelFun.AddALLSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, MeasureItem.SampleName);                                            break;                                        }                                    }                                    else                                    {                                        MessageBox.Show(table["message12"].ToString(), table["message11"].ToString());                                        return;                                    }                                }                            }                        }                    }                }                Invalidate();            }            catch (Exception ex)            {                string message = table["message2"].ToString();                log.Error("OTSSamplespaceWindow_SetSEMCenterLocation_" + message + ":" + 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_MouseDownLocation, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth, Width, Height);                //m_SEMDATAFieldManage.CloseSEM();                }                           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;                if (m_SEMDATAFieldManage.InitAndConnection())                {                    bret = (m_SEMDATAFieldManage.DriveSEMToLocation(m_MouseDownLocation, m_RectangleGDIObjects, m_SingleGDIObjects, m_OTSSampleStageData, IsWidth, Width, Height));                    //m_SEMDATAFieldManage.CloseSEM();                }                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);                //m_SEMDATAFieldManage.CloseSEM();                }            return bret;                   }        #endregion        #region 根据已完成测量的帧图信息 绘制帧图已完成状态         /// <summary>        ///  根据已完成测量的帧图信息 绘制帧图已完成状态         /// </summary>        public void GetSingleInfoForSampleNameAndOTSSamplespaceWindow()        {            #region 根据已完成测量的帧图信息 绘制帧图已完成状态             //获取完成帧图信息的方法返回布尔值            bool GetBeforeCompleteFieldResult = false;            //当前测量名称            string msrSampleName = string.Empty;            //已完成的帧图坐标中心信息列表            List<Point> CompleteFieldList = new List<Point>();            GetBeforeCompleteFieldResult = m_MeasureAppForm.m_ProjParam.GetBeforeCompleteField(ref msrSampleName, ref CompleteFieldList);            //如果获取的返回值为false            if (!GetBeforeCompleteFieldResult)            {                return;            }            else            {                //如果当前工作样品名称与返回的工作样品名称一致                if (m_SampleSelectName.Equals(msrSampleName))                {                    //如果已完成的帧图数量为0                    if (CompleteFieldList.Count == 0)                    {                        //重新加载帧图信息                    }                    else                    {                        //绘制已完成的帧图信息                        OTSMeasureDisplayResult.ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, m_MeasureAppForm);                    }                }            }            #endregion        }        #endregion        #region 连接电镜连接        public bool ConnectToSEM()        {            if (m_SEMDATAFieldManage == null)            {                m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);            }            //连接电镜连接            bool result = m_SEMDATAFieldManage.InitAndConnection();            return result;        }        public bool ConnectionSEM(ref SEMDATAFieldManage m_SEMDATAFieldManage)        {            if (m_SEMDATAFieldManage == null)            {                m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);            }            //string message = table["message6"].ToString();            //连接电镜连接            log.Trace("--" + "connect to SEM" + "--");            bool result = m_SEMDATAFieldManage.InitAndConnection();            if (result)            {                log.Trace("--" + "connect succeed" + ":True--");            }            return result;        }        #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;            if (control_Ruler2.Visible)            {                //显示                control_Ruler2.Visible = false;            }            else            {                //显示                control_Ruler2.Visible = true;                control_Ruler2.ShowString = "1000um";                f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * f_zoom_increment);                control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);                control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));            }        }        public void RulerInit()        {            control_Ruler2.ShowString = "100um";            control_Ruler2.Width = 130;        }        #endregion        #region 隐藏与显示样品台中的文字        static bool IsShowSampleHoleFont = true;        public void ChangeSampleHoleFont()        {            IsShowSampleHoleFont = IsShowSampleHoleFont ? false : true;            Invalidate();        }        #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)        {            //获取样品孔名称            string sampleHoleName = string.Empty;            ARectangleGDIObject itemWorkSample = null;            foreach (ARectangleGDIObject item in m_SampleGDIObjects)            {                if (item.IsWorkSample)                {                    sampleHoleName = item.Name;                    itemWorkSample = item;                    break;                }            }            //获取样品孔BSE图像            Image bseImage = null;            int m_iWidth = width;            int m_iHeigh = height;            RectangleF ImgRegionF = new RectangleF();            float ImgRegionWidth = 0;            float ImgRegionHeight = 0;            if (m_ImageSingleGDIObjects.Count > 0)            {                for (int i = 0; i < m_ImageSingleGDIObjects.Count; i++)                {                    if (m_ImageSingleGDIObjects[i].OTSX == fieldPos.X && m_ImageSingleGDIObjects[i].OTSY == fieldPos.Y)                    {                        ImgRegionF = m_ImageSingleGDIObjects[i].RegionF;                        ImgRegionWidth = Convert.ToInt32(m_ImageSingleGDIObjects[i].RegionF.Width);                        ImgRegionHeight = Convert.ToInt32(m_ImageSingleGDIObjects[i].RegionF.Height);                        //获取图片                        bseImage = OTSSysMgrTools.Imagepro.ToGrayBitmap(ImageData, m_iWidth, m_iHeigh);                        //获取工作样品位置                        Point drawImageLocation = itemWorkSample.Region.Location;                        //绘制图像                        CreateRectangle createImageRect = new CreateRectangle(ImgRegionF, fieldPos.X, fieldPos.Y, itemWorkSample.SampleName, itemWorkSample.Name, bseImage, ImgRegionWidth, ImgRegionHeight, drawImageLocation, (int)CreateRectangleType.DrawSampleHoleBSEImage);                        //添加至List集合中                        createImageRect.DrawRegionF = m_ImageSingleGDIObjects[i].DrawRegionF;                        createImageRect.RegionF = m_ImageSingleGDIObjects[i].RegionF;                        createImageRect.Region = m_ImageSingleGDIObjects[i].Region;                        createImageRect.Name = m_ImageSingleGDIObjects[i].Name;                        m_ImageGDIObjects.Add(createImageRect);                        break;                    }                }            }            //显示样品孔照片            IsShowSampleHoleImage = true;            Invalidate();        }        #endregion        #region 删除样品孔中BSE图像信息        public void DeleteHoleBSEImageData()        {            try            {                //鼠标右键点击的位置坐标                Point mouseCurrent = m_MouseDownLocation;                //样品名称                string SampleName = "";                //获取当前工作样品并删除对应BSE图                foreach (ARectangleGDIObject ImageItem in m_ImageGDIObjects)                {                    if (ImageItem.Region.Contains(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)                    {                        CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.StartMeasure;                        DeleteHoleBSEImageDataNoMessageBox();                        return;                    }                    else                    {                        return;                    }                }                //删除样品孔BSE图                //样品孔名称                string HoleName = "";                foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)                {                    if (item.Region.Contains(mouseCurrent))                    {                        HoleName = item.Name;                        break;                    }                }                if (HoleName != null && !HoleName.Equals(""))                {                    string message = table["message8"].ToString();                    if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)                    {                        CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.ShotBSEPicture;                        DeleteHoleBSEImageDataNoMessageBox();                        return;                    }                    else                    {                        return;                    }                }            }            catch (Exception ex)            {                string message = table["message9"].ToString();                log.Trace(message + ex.ToString());            }        }        public void DeleteHoleBSEImageDataNoMessageBox()        {            try            {                if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)                {                    if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.ShotBSEPicture)                    {                        string HoleName = string.Empty;                        //鼠标右键点击的位置坐标                        Point mouseCurrent = m_MouseDownLocation;                        //获取当前工作样品并删除对应BSE图                        foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)                        {                            if (item.Region.Contains(mouseCurrent))                            {                                HoleName = item.Name;                                break;                            }                        }                        if (!HoleName.Equals(""))                        {                            for (int i = m_ImageGDIObjects.Count - 1; i >= 0; i--)                            {                                if (m_ImageGDIObjects[i].Name == HoleName && m_ImageGDIObjects[i].SampleName == null)                                {                                    m_ImageGDIObjects.RemoveAt(i);                                }                            }                            for (int i = m_ImageSingleGDIObjects.Count - 1; i >= 0; i--)                            {                                if (m_ImageSingleGDIObjects[i].Name == HoleName && m_ImageGDIObjects[i].SampleName == null)                                {                                    m_ImageSingleGDIObjects.RemoveAt(i);                                }                            }                            Invalidate();                        }                    }                    else                    {                        string SampleName = string.Empty;                        //鼠标右键点击的位置坐标                        Point mouseCurrent = m_MouseDownLocation;                        //获取当前工作样品并删除对应BSE图                        foreach (ARectangleGDIObject item in m_ImageGDIObjects)                        {                            if (item.Region.Contains(mouseCurrent))                            {                                SampleName = item.SampleName;                                break;                            }                        }                        if (!SampleName.Equals(""))                        {                            for (int i = m_ImageGDIObjects.Count - 1; i >= 0; i--)                            {                                if (m_ImageGDIObjects[i].SampleName == SampleName)                                {                                    m_ImageGDIObjects.RemoveAt(i);                                }                            }                            for (int i = m_ImageSingleGDIObjects.Count - 1; i >= 0; i--)                            {                                if (m_ImageSingleGDIObjects[i].SampleName == SampleName)                                {                                    m_ImageSingleGDIObjects.RemoveAt(i);                                }                            }                            Invalidate();                        }                    }                }            }            catch (Exception)            {            }        }        #endregion        #region 获取样品孔图片        public void GetBSEPictures()        {            //获取当前工作的测量区域信息            CDomain cDomain = new CDomain();            DOMAIN_SHAPE iShape = 0;            Rectangle Srect = new Rectangle();            //拍摄样品孔BSE照片            if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)            {                if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.ShotBSEPicture)                {                    //获取当前样品孔的索引 与 样品中对应的测量区域                    OTSSampleHoleInfo sampleHoleInfo = null;                    int sampleHoleIndex = OTSSamplespaceGraphicsPanelFun.GetSampleHoleIndex(m_OTSSampleStageData, m_SampleHoleSelectName, ref sampleHoleInfo);                    if (sampleHoleInfo != null)                    {                        foreach (var sampleHoleItem in m_SampleHoleGDIObjects)                        {                            if (sampleHoleItem.Name == sampleHoleInfo.sSHoleName)                            {                                SampleHolePara sampleHolePara = OTSSamplespaceGraphicsPanelFun.GetSampleHoleRect(sampleHoleItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain);                                iShape = (DOMAIN_SHAPE)sampleHolePara.iShape;                                Srect = sampleHolePara.SampleHoleRect;                                //设置测量区域形状                                cDomain.SetShape(iShape);                                cDomain.SetRectDomain(Srect);                                //开始获取样品孔中的照片                                m_MeasureAppForm.StartSampleHoleBSEImage((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage, sampleHoleIndex, cDomain);                                break;                            }                        }                    }                }                else                {                    int measureIndex = 0;                    //获取测量区域信息                    foreach (var MeasureItem in m_MeasureGDIObjects)                    {                        if (MeasureItem.SampleName == m_SampleSelectName)                        {                            measureIndex++;                            SampleMeasurePara sampleMeasure = OTSSamplespaceGraphicsPanelFun.GetSampleMeasureRect(MeasureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain);                            iShape = (DOMAIN_SHAPE)sampleMeasure.iShape;                            Srect = sampleMeasure.MeasureRect;                            //设置测量区域形状                            if (iShape == (DOMAIN_SHAPE)(int)CreateRectangleType.Polygon)                            {                                if (iShape > 0)                                {                                    cDomain.SetShape(iShape);                                }                                else                                {                                    cDomain.SetShape((DOMAIN_SHAPE.ROUND));                                }                            }                            else                            {                                cDomain.SetShape(iShape);                            }                            cDomain.SetRectDomain(Srect);                            List<Point> PolygonPoint = OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(sampleMeasure.DrawPolygonPointRegionF);                                                        cDomain.SetPolygonPoint(PolygonPoint);                            //开始获取样品孔中的照片                            m_MeasureAppForm.StartSampleHoleBSEImage((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage, 2, cDomain);                            break;                        }                    }                }            }        }        #endregion        #region 复位工作样品区域        public void ResetWorkSampleMeasure()        {            COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();            OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();            if (!m_MeasureAppForm.m_ProjParam.GetWorkSamplePerameter(WSample, ref MeasureInfo))            {                return;            }            Rectangle measureSize = m_MeasureAppForm.m_ProjParam.CalculateMsrArea(MeasureInfo.SMeasurePara.sHoleName);            //获取位置与尺寸            MeasureInfo.SMeasurePara.MeasureRect.Location = measureSize.Location;            MeasureInfo.SMeasurePara.MeasureRect.Size = measureSize.Size;            //获取样品信息            Point xHole = new Point(MeasureInfo.SMeasurePara.MeasureRect.Left, MeasureInfo.SMeasurePara.MeasureRect.Top);            Point yHole = new Point(MeasureInfo.SMeasurePara.MeasureRect.Right, MeasureInfo.SMeasurePara.MeasureRect.Bottom);            //将微米转换为像素            int widthHole = (int)(Math.Abs(((Point)yHole).X - ((Point)xHole).X));            int heightHole = (int)(Math.Abs(((Point)yHole).Y - ((Point)xHole).Y));            //定义测量区域            RectangleF SampleRectangleF = OTSSamplespaceGraphicsPanelFun.GetPixRectF(m_WDomain, yHole, xHole, "", "", IsWidth, m_DefaultW, m_DefaultH);            ARectangleGDIObject m_MeasureGDIObject = OTSSamplespaceGraphicsPanelFun.GetPixRect(m_WDomain, yHole, xHole, MeasureInfo.SMeasurePara.iShape, "", "", IsWidth, m_DefaultW, m_DefaultH);            m_MeasureGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);            m_MeasureGDIObject.RegionF = SampleRectangleF;            m_MeasureGDIObject.DrawRegionF = SampleRectangleF;            foreach (var itemSample in m_SampleGDIObjects)            {                if (itemSample.IsWorkSample)                {                    for (int i = 0; i < m_MeasureGDIObjects.Count; i++)                    {                        if (m_MeasureGDIObjects[i].IsWorkSample)                        {                            ARectangleGDIObject m_ResetMeasureGDIobjects = CStageManage.ResetMeasure((int)CreateRectangleType.Circle, itemSample, m_MeasureGDIObject, m_GlobalZoomNum);                            m_MeasureGDIObjects[i].Region = m_ResetMeasureGDIobjects.Region;                            m_MeasureGDIObjects[i].RegionF = m_ResetMeasureGDIobjects.RegionF;                            m_MeasureGDIObjects[i].DrawRegionF = m_ResetMeasureGDIobjects.DrawRegionF;                            m_MeasureGDIObjects[i].Shape = m_ResetMeasureGDIobjects.Shape;                            Invalidate();                            break;                        }                    }                    break;                }            }        }        #endregion        #region 清空帧图对象与图像位置对象        public void ClearImageAndSingleGDIObjects()        {            //先清空帧图信息            if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)            {                m_SingleGDIObjects = OTSSamplespaceGraphicsPanelFun.ListClear(m_SingleGDIObjects);            }            if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)            {                m_ImageSingleGDIObjects = OTSSamplespaceGraphicsPanelFun.ListClear(m_ImageSingleGDIObjects);            }        }        #endregion        #region 样品对象列表中无样品信息 则清除帧图对象列表信息        /// <summary>        /// 样品对象列表中无样品信息 则清除帧图对象列表信息        /// </summary>        /// <returns></returns>        public bool SampleIsEmptyClearSingleInfo()        {            bool result = false;            if (m_SampleGDIObjects != null)            {                if (m_SampleGDIObjects.Count == 0)                {                    result = true;                    ClearImageAndSingleGDIObjects();                }            }            return result;        }        #endregion        #region 切换样品 填充帧图信息        public static void ChangeSampleFillSingleInfo(string sampleName)        {            OTSSamplespaceGraphicsPanelFun.ChangeSampleFillSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, sampleName);        }             #endregion        #region 设置工作样品测量区域        public bool SetWorkSampleMeasureArea(int shape = 0)        {            bool IsSingle = false;            //获取当前工作的测量区域信息            CDomain cDomain = new CDomain();            DOMAIN_SHAPE iShape = 0;            Rectangle Srect = new Rectangle();            List<Point> PolygonPoint = new List<Point>();            //获取测量区域形状与位置            //获取当前测量区域            foreach (var MeasureItem in m_MeasureGDIObjects)            {                if (MeasureItem.IsSingle && MeasureItem.IsWorkSample)                {                    if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(MeasureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))                    {                        IsSingle = true;                        SampleMeasurePara sampleMeasure = GetSampleMeasureRect(MeasureItem);                        if (sampleMeasure.PolygonPointRegion == null)                        {                            sampleMeasure.PolygonPointRegion = new List<Point>();                        }                        PolygonPoint = OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(sampleMeasure.PolygonPointRegionF);                        iShape = (DOMAIN_SHAPE)sampleMeasure.iShape;                        //设置测量区域形状                        if (iShape == (DOMAIN_SHAPE)(int)CreateRectangleType.Polygon)                        {                            if (shape > 0)                            {                                cDomain.SetShape((DOMAIN_SHAPE)shape);                            }                            else                            {                                cDomain.SetShape((DOMAIN_SHAPE.ROUND));                            }                        }                        else                        {                            cDomain.SetShape((DOMAIN_SHAPE)iShape);                        }                        Srect = sampleMeasure.MeasureRect;                        cDomain.SetRectDomain(Srect);                        cDomain.SetPolygonPoint(PolygonPoint);                        //线程执行类型 1:测量类型 2:获取样品孔图片类型                        CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;                        //设置获取样品孔中照片所需的参数                        CMeasureThreadWrapper.c_DomainMessure = cDomain;                    }                    break;                }            }            return IsSingle;        }        #endregion    }}
 |