12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534 |
- using OpenCvSharp;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.Functionodel;
- using PaintDotNet.CustomControl;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.Instrument;
- using System;
- using System.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- using PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass;
- using PaintDotNet.Base.DedicatedAnalysis.GrainSize;
- using Metis.ParameterSet;
- using PaintDotNet.Data.Param;
- using PaintDotNet.Base;
- using System.IO;
- using OpenCvSharp.Extensions;
- using PaintDotNet.Base.SettingModel;
- namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard
- {
- internal class GrainSizeStandardDialog : PdnBaseForm
- {
- /// <summary>
- /// 晶粒度标准的方法类型(0 截点法/截距法, 1 面积法)
- /// </summary>
- private int grainMethodType = -1;
- /// <summary>
- /// 晶粒度标准集成
- /// </summary>
- protected GrainSizeStandardClass GSSClass = new GrainSizeStandardClass();
- #region 内部属性
- /// <summary>
- /// 主控件
- /// </summary>
- protected AppWorkspace appWorkspace;
- /// <summary>
- /// 平均截距
- /// </summary>
- private double value_111 = -1;
- /// <summary>
- /// 二值化集成
- /// </summary>
- protected BinaryClass binaryClass;
- /// <summary>
- /// 公共按钮
- /// </summary>
- private CommonControlButtons commonControlButtons;
- /// <summary>
- /// 图像面板
- /// </summary>
- protected DocumentWorkspaceWindow documentWorkspace;
- /// <summary>
- /// 当前选择的图片
- /// </summary>
- protected Bitmap bitmap;
- /// <summary>
- /// 当前选择的图片
- /// </summary>
- protected Mat matOrg;
- /// <summary>
- /// 相0的图片,处理多视场使用
- /// </summary>
- protected Mat PhaseModel0Mat
- {
- get
- {
- if (binaryClass.PhaseModels0Mat != null)
- return binaryClass.PhaseModels0Mat;
- return this.documentWorkspace.PhaseModels[0].mat;
- }
- }
- /// <summary>
- /// 防止进入页面时错误提示辅助线选项信息
- /// </summary>
- public bool comboboxChange = true;
- /// <summary>
- /// 当前选择图片的Index
- /// </summary>
- protected int selectPicture = -1;
- /// <summary>
- /// 调色板
- /// </summary>
- private ColorsForm colorsFormGrid;
- private Panel panelC;
- /// <summary>
- /// 保存用于生成报告的图片
- /// </summary>
- private List<Bitmap> bitList;
- /// <summary>
- /// 储存点击保存结果后的所有原图与分析图
- /// </summary>
- protected Dictionary<string, List<Bitmap>> bitDic = new Dictionary<string, List<Bitmap>>();
- /// <summary>
- /// 中间数据
- /// </summary>
- protected List<ExportProjectModel> tempDataModel = new List<ExportProjectModel>();
- /// <summary>
- /// 分析结果暂存
- /// </summary>
- protected List<System.Data.DataTable> dataTable_Totals = new List<System.Data.DataTable>();
- /// <summary>
- /// GBT6394面积法 分析结果暂存 -视场面积(Dictionary<string, object>的key为"RectArea")
- /// </summary>
- private Dictionary<string, Dictionary<string, object>> dict_Totals = new Dictionary<string, Dictionary<string, object>>();
- /// <summary>
- /// 详细分析结果暂存
- /// </summary>
- protected List<System.Data.DataTable> dataTables = new List<System.Data.DataTable>();
- /// <summary>
- /// 全部显示
- /// </summary>
- protected bool allShow = false;
- /// <summary>
- /// 详细列表需要求和的index集合
- /// </summary>
- protected List<int> IndexChangedFromIndex = new List<int>();
- /// <summary>
- /// 列表需要求和的index集合,value值为:1 求和 2:平均 3:级别计算 + [输入数据index位置,-1则需要调用自定义方法进行计算]
- /// </summary>
- protected Dictionary<int, int[]> IndexChangedToIndex = new Dictionary<int, int[]>();
- /// <summary>
- /// 详细列表不需要格式化的字符串数据
- /// </summary>
- protected List<int> DetailListStringIndex = new List<int>();
- /// <summary>
- /// 详细列表不需要按double排序的字符串数据
- /// </summary>
- protected List<int> DetailListNotDoubleIndex = new List<int>();
- /// <summary>
- /// 为了解决标题文字相同的标准,只能使用name赋值每列的数据
- /// </summary>
- protected bool HeaderTextUsable = true;
- /// <summary>
- /// 是否脚本运行
- /// </summary>
- private Boolean initScriptValues = false;
- /// <summary>
- /// 数值大于0,则窗口初始化数据完成
- /// </summary>
- private int finishedLoadAction = -1;
- /// <summary>
- /// 当前菜单的唯一id
- /// </summary>
- private int menuId;
- private string menuName;
- /// <summary>
- /// 保存窗口参数
- /// </summary>
- private GrainSizeAnalysisModel analysisModel;
- /// <summary>
- /// 保存所有窗口的参数
- /// </summary>
- private Dictionary<string, GrainSizeAnalysisModel> analysisDict = new Dictionary<string, GrainSizeAnalysisModel>();
- /// <summary>
- /// 应用到全部之前,记住当前选择的窗口
- /// </summary>
- private int currentOldSelectIndex = -1;
- /// <summary>
- /// 晶界重现-保存所有窗口的参数 应用则计算,不应用则清空Mat。应用到全部则提前清空Mat和Model
- /// </summary>
- private Dictionary<string, Base.SettingModel.GrainBoundryDectModel> grainBoundaryDict = new Dictionary<string, Base.SettingModel.GrainBoundryDectModel>();
- /// <summary>
- /// 晶界重现-保存所有窗口的计算结果 应用则计算,不应用则清空
- /// </summary>
- protected Dictionary<string, Mat> grainBoundaryMatDict = new Dictionary<string, Mat>();
- protected Dictionary<string, Mat> everyImgPhaseDict = new Dictionary<string, Mat>();
- /// <summary>
- /// 面积法晶界颜色-保存所有窗口的计算结果 保存结果时一起保存,重新保存则替换
- /// </summary>
- protected Dictionary<string, Mat> grainColorsMatDict = new Dictionary<string, Mat>();
- //private Dictionary<string, Color> grainBoundaryColorDict = new Dictionary<string, Color>();
- //string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel_" + this.menuId + ".xml";
- //bool createNewFile = !System.IO.File.Exists(xmlFilePath);
- // if (createNewFile)
- // return;
- // Base.SettingModel.GrainBoundryDectModel grainBoundryDectModel = Base.CommTool.XmlSerializeHelper.DESerializer<Base.SettingModel.GrainBoundryDectModel>(Base.CommTool.FileOperationHelper.ReadStringFromFile(xmlFilePath, System.IO.FileMode.Open));
- //sigma = grainBoundryDectModel.sigma;
- // textBox6.Text = sigma + "";
- // grainApplygrainboundaries = grainBoundryDectModel.grainApplygrainboundaries;
- // this.applyRadioButton1.Checked = (grainApplygrainboundaries == 1);
- // m_iStandardImage = grainBoundryDectModel.m_iStandardImage;
- protected static string ParamKey_displaygrainboundaries = "displaygrainboundaries";//显示晶界
- protected static string ParamKey_displaygrid = "displaygrid";//显示网格
- protected static string ParamKey_displaysections = "displaysections";//显示截点
- protected static string ParamKey_comboBox1SelectedItem = "comboBox1SelectedItem";//选择的辅助线
- protected static string ParamKey_ShowGrainNumber = "ShowGrainNumber";//显示晶粒编号
- protected static string ParamKey_ShowGrainColor = "ShowGrainColor";//用不同颜色显示晶粒
- protected static string ParamKey_CalculatorDecimalDigits = "CalculatorDecimalDigits";//小数点位数
- protected static string ParamKey_OpenWhileExportReport = "OpenWhileExportReport";//生成报告时打开设置//#22009 22010
- protected static string ParamKey_TargetSelection = "TargetSelection";//目标选择
- #endregion
- #region 组件
- private GroupBox groupBox_operating;
- protected GroupBox groupBox_img;
- protected ListView lstView_img;
- private ImageList imageList_img;
- private IContainer components;
- protected GroupBox groupBox_review;
- protected GroupBox groupBox_report;
- private Label label_resultPrecision;
- private Button button_exportResults;
- private Button button_generateReport;
- protected GroupBox groupBox6groupBox_analysisResult2;
- protected GroupBox groupBox_analysisResult1;
- private Button button_setting;
- private CheckBox checkBox_generateReport_opensetting;
- protected GroupBox groupBox3;
- private Button button9;
- protected ComboBox comboBox1;
- protected DataGridView dataGridView2;
- protected ListView listView2;
- private Button button16;
- private Button button12;
- private Button button11;
- private NumericUpDown numericUpDown1_0;
- private Button button1;
- private BinaryControlSmaller bc;
- protected DataGridView dataGridView_Total;
- protected Button btn_saveresult;
- protected Button button_ApplyToAll;
- protected Button button_SaveAll;
- private Button threeDButton;
- protected Button btn_Grainboundarytoreproduce;
- private Base.SettingModel.GrainBoundryDectModel GrainBoundryDectModel;
- private Mat OrgImg0;
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="appWorkspace"></param>
- /// <param name="grainMethodType">晶粒度标准的方法类型(0 截点法/截距法, 1 面积法)</param>
- public GrainSizeStandardDialog(AppWorkspace appWorkspace, PdnMenuItem menuItem, MethodOfAssessment methodOfAssessment, int grainMethodType = 1)
- {
- this.menuId = menuItem.MenuId;
- this.menuName = menuItem.Text;
- this.appWorkspace = appWorkspace;
- this.Icon = PdnInfo.AppIcon;
- this.colorsFormGrid = new ColorsForm();
- this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
- this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
- if (GSSClass.InitDialogMethod(methodOfAssessment))
- {
- this.grainMethodType = grainMethodType;
- SetAnalyzeModelFromXml(GSSClass.methodOfAssessment.resourcesName);
- }
- else
- {
- this.grainMethodType = grainMethodType;
- if (!GSSClass.InitComboboxValue())
- {
- if (grainMethodType == 1)
- GSSClass.GuideClass.createGuideAreaClassModelsNamed(getModelName());
- else if (grainMethodType == 0)
- GSSClass.GuideClass.createGuideClassModelsNamed(getModelName());
- }
- SetAnalyzeModelFromXml(getTemplateName());
- }
- InitializeComponent();
- this.binaryClass = new BinaryClass(menuId);
- this.binaryClass.ShowDrawClassView = ShowDrawClassView();
- InitializeLanguageText();
- Initialize();
- SubclassInitialize();
- //如果是脚本执行,将参数带入
- if (appWorkspace.ScriptRunning && appWorkspace.ScriptCurrentParam != null && (int)appWorkspace.ScriptCurrentParam.MenuId == menuId)
- {
- this.initScriptValues = true;//ScriptAutomatic
- ////在这里反射出对应功能的参数类
- string className = InvariantData.path_Action + ".Action" + menuId;
- ParamObject param = (ParamObject)System.Reflection.Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
- foreach (Args arg in param.Lists)
- {
- Args param1 = appWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(arg.Key));
- if (param1.value != null)
- arg.Value = param1.value;
- //获取晶界重现参数
- getBinary(arg.Key, arg.Value);
- }
- this.analysisModel = GrainSizeAnalysisModel.cloneListParamScript(param);
- foreach (var item in this.analysisModel.ListParam)
- item.setValue();
- getSonData();
- if (this.GrainBoundryDectModel != null) {
- string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel_" + this.menuId + ".xml";
- string userInfoXml = XmlSerializeHelper.XmlSerialize<GrainBoundryDectModel>(this.GrainBoundryDectModel);
- FileOperationHelper.WriteStringToFile(userInfoXml, xmlFilePath, FileMode.Create);
- this.applyDect();
- }
- }
- else
- {//读取上次关闭窗口时保存的参数
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
- GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
- this.analysisModel = analysisModelXml.cloneListParamModel(this.menuId);
- foreach (var item in this.analysisModel.ListParam)
- item.setValue();
- }
- //初始化头
- this.listView2.View = View.Details;
- ColumnHeader header0 = new ColumnHeader();
- header0.Text = "";
- header0.Width = 180;
- this.listView2.Columns.Add(header0);
- //二值化集成2
- bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件
- binaryClass.createDocumentItemsSmaller(new string[] { PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"), PdnResources.GetString("Menu.Thegrainsareshownindifferentcolors.text") }
- , this.bc, this.appWorkspace, this.documentWorkspace, this.lstView_img);//初始化相的工作结构
- //如果是脚本执行,将参数带入二值化集成2 之后:
- appWorkspace.ScriptCurrentParam = null;//阻止第二次进入仍然被赋值参数
- binaryClass.BinaryImplFinishAction += new EventHandler(this.bClassBinaryImplFinishAction);//二值化后续处理事件
- //InitComboboxValue(null);
- this.button11.Visible = true;
- this.button16.Visible = false;
- this.Shown += new EventHandler(this.ShownChoiseItemAndInitData);
- }
- #region [晶界重现-脚本相关]
- /// <summary>
- /// 脚本获取晶界重现参数
- /// </summary>
- private void getBinary(string key, Object value)
- {
- GrainBoundryDectModel = new Base.SettingModel.GrainBoundryDectModel();
- switch (key)
- {
- case "GrainApplygrainboundaries":
- GrainBoundryDectModel.grainApplygrainboundaries = Convert.ToInt32(value);
- break;
- case "lineColor":
- GrainBoundryDectModel.grainColor = Convert.ToInt32(value);
- break;
- case "GrainIConnect":
- GrainBoundryDectModel.iConnect = Convert.ToInt32(value);
- break;
- case "GrainDisplaysections":
- GrainBoundryDectModel.enhance = Convert.ToBoolean(value) ? 1 : 0;
- break;
- case "GrainSigma":
- GrainBoundryDectModel.sigma = Convert.ToDouble(value);
- break;
- case "GrainCell_size1":
- List<double> twoL = (List<double>)value;
- GrainBoundryDectModel.cell1_size = (int)twoL[0];
- GrainBoundryDectModel.cell2_size = (int)twoL[1];
- break;
- case "GrainDark":
- GrainBoundryDectModel.dark = Convert.ToInt32(value);
- break;
- case "GrainSmooth_type":
- GrainBoundryDectModel.smooth_type = Convert.ToInt32(value);
- break;
- case "GrainM_iStandardImage":
- GrainBoundryDectModel.m_iStandardImage = Convert.ToInt32(value);
- break;
- }
- }
- private void applyDect()
- {
- Bitmap bitmap = this.appWorkspace.DocumentWorkspaces[index].CompositionSurface.CreateAliasedBitmap();
- if (this.documentWorkspace.PhaseModels.Count == 0) {
- return;
- }
- Mat PhaseModel0MatCopy = this.documentWorkspace.PhaseModels[0].mat.Clone();
- double sigma = this.GrainBoundryDectModel.sigma;
- Mat OrgImg = BitmapConverter.ToMat(bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile);
- int grainApplygrainboundaries = this.GrainBoundryDectModel.grainApplygrainboundaries;
- int m_iStandardImage = this.GrainBoundryDectModel.m_iStandardImage;
- int iConnect = this.GrainBoundryDectModel.iConnect;
- /*int */
- int dark = this.GrainBoundryDectModel.dark;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
- /*int */
- int smooth_type = this.GrainBoundryDectModel.smooth_type;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
- //double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数
- /*int */
- int enhance = this.GrainBoundryDectModel.enhance;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
- /*double[] */
- double[] cell_size = new double[2] { this.GrainBoundryDectModel.cell1_size, this.GrainBoundryDectModel.cell2_size }; ;// new double[2] { 0.01, 500 };//晶界大小
- procClass = new ProgressThreadProcClass();
- procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(applyDectAction), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"));
- if (OrgImg0 != null)
- {
- if (this.documentWorkspace.GraphicsList.IsExsitView() && ShowDrawClassView())
- {
- Vec4b vec4 = new Vec4b(0, 0, 0, 0);
- //视场图像
- Mat exsitViewMatOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.documentWorkspace.GetFullSizeWithRegion());
- for (int y = 0; y < exsitViewMatOrg/*temp*/.Rows; y++)
- {
- for (int x = 0; x < exsitViewMatOrg/*temp*/.Cols; x++)
- {
- if (exsitViewMatOrg.At<Vec4b>(y, x).Item3 == 0)
- OrgImg0.Set(y, x, vec4);//不在视场图像范围内
- }
- }
- }
- this.documentWorkspace.PhaseModels[0].mat = OrgImg0.Clone();
- this.documentWorkspace.Refresh();
- if (PhaseModel0MatCopy != null)
- {
- PhaseModel0MatCopy.Dispose();
- PhaseModel0MatCopy = null;
- }
- PhaseModel0MatCopy = this.documentWorkspace.PhaseModels[0].mat.Clone();
- //this.resetOperationsAction();
- OrgImg0 = null;
- }
- if (OrgImg != null)
- {
- OrgImg.Dispose();
- OrgImg = null;
- }
- }
- #endregion
- private void ShownChoiseItemAndInitData(object sender, EventArgs e)
- {
- //二值化集成3
- this.binaryClass.loadParams();
- this.binaryClass.guideClass = GSSClass.GuideClass;
- this.binaryClass.comboBox1 = this.comboBox1;
- if (index > -1)
- {
- //滚动到指定的行位置
- if (index >= 0 && index < this.lstView_img.Items.Count)
- this.lstView_img.EnsureVisible(index); //选中行 //##21319
- if (this.lstView_img.FocusedItem != null && this.lstView_img.FocusedItem.Selected || this.lstView_img.SelectedItems != null && this.lstView_img.SelectedItems.Count > 0)
- {
- if (this.selectPicture == index/*this.lstView_img.FocusedItem.Index*/)
- return;
- this.bitmap = this.appWorkspace.DocumentWorkspaces[index/*this.lstView_img.FocusedItem.Index*/].CompositionSurface.CreateAliasedBitmap();
- matOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
- //二值化集成4
- //if (!is###OtherGrainSizeStandardDialog)
- {
- if (ShowDrawClassView())
- binaryClass.listView1_SelectedIndexChanged(this.bitmap);
- else
- binaryClass.listView1_SelectedIndexChangedHideDrawClassView(this.bitmap, getCurrentWorkTag());
- this.bcOriginCheckedChanged(null, null);
- }
- if (!this.analysisDict.ContainsKey(getCurrentWorkTag()))
- this.analysisDict.Add(getCurrentWorkTag(), this.analysisModel/*.cloneListParamModel(this.menuId)*/);
- else
- this.analysisDict[getCurrentWorkTag()] = this.analysisModel/*.cloneListParamModel(this.menuId)*/;
- //this.analysisModel = this.analysisDict[getCurrentWorkTag()];
- //if (GSSClass.massLabelPointsList != null && GSSClass.massLabelPointsList.Count > 0)
- //{
- // GSSClass.massLabelPointsList.Clear();//1013###19098(切换图片的时候前一张图的信息不遗留显示)}
- // this.documentWorkspace.Refresh();//######
- //}
- ////if (this.checkBox1.Checked)
- ////{
- //// this.documentWorkspace.PhaseModels[1].choise = true;//#########################
- //// this.applyDect();
- ////}
- this.selectPicture = index;// this.lstView_img.FocusedItem.Index;
- GSSClass.GuideClass.guideModel.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
- //UpdateGuideStyle(true);//19845
- InitRectangleF(false);
- AddRectangleToRectangleFCaps();
- refreshWhileImgChanged();
- }
- InitComboboxValue(null);
- try
- {
- object ItemStringObject;
- if (GetParamValue1(ParamKey_comboBox1SelectedItem, out ItemStringObject)) {
- try
- {
- this.comboBox1.SelectedIndex = Convert.ToInt32(ItemStringObject);
- }
- catch (Exception)
- {
- this.comboBox1.SelectedItem = (string)ItemStringObject;
- }
- }
- }
- catch (Exception exc)
- {
- System.Console.WriteLine("this.comboBox1.SelectedItem: " + exc.ToString());
- }
- }
- //// 初始化数据
- //this.bitmap = this.appWorkspace.DocumentWorkspaces[index].CompositionSurface.CreateAliasedBitmap();
- //Document document = Document.FromImage(bitmap);
- //this.documentWorkspace.Document = document;
- //this.documentWorkspace.Visible = true;
- //this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[index].GraphicsList;
- //this.applyButtonImpl(null, null);
- object ShowGrainBoundry;//#21752
- if (GetParamValue1(ParamKey_CalculatorDecimalDigits, out ShowGrainBoundry))//小数点位数
- this.numericUpDown1_0.Value = (int)ShowGrainBoundry;
- if (GetParamValue1(ParamKey_OpenWhileExportReport, out ShowGrainBoundry))//生成报告时打开设置
- this.checkBox_generateReport_opensetting.Checked = (bool)ShowGrainBoundry;
- ////显示直方图
- //this.histogramControl1.CreateHistogram(this.bitmap, true, 339, 130, 0);
- this.finishedLoadAction++;
- if (this.finishedLoadAction > 0 && this.initScriptValues && this.appWorkspace.ScriptAutomatic)
- this.startScriptAutomaticAction();
- }
- /// <summary>
- /// 执行脚本自动化的步骤
- /// </summary>
- private void startScriptAutomaticAction()
- {
- this.button_ApplyToAll.PerformClick();
- this.button_SaveAll.PerformClick();
- for (int j = 0; j < this.listView2.Items.Count; j++)
- this.listView2.Items[j].Selected = true;
- object ItemStringObject;
- if (GetParamValue1("ExportResults", out ItemStringObject)
- && (bool)ItemStringObject)//导出结果
- this.button_exportResults.PerformClick();
- if (GetParamValue1("ExportReports", out ItemStringObject)
- && (bool)ItemStringObject)//生成报告
- this.button_generateReport.PerformClick();
- if (GetParamValue1("ExportProjects", out ItemStringObject)
- && (bool)ItemStringObject)//导出项目
- this.button1.PerformClick();
- //List<Args> dedicatedLists = new List<Args>();
- //IntegerNumber seven = new IntegerNumber(0, 10);
- //seven.key = "CalculatorDecimalDigits";
- //seven.name = "小数点位数";
- //seven.initialValue = 2;
- //seven.value = 2;
- //dedicatedLists.Add(seven);
- //dedicatedLists.Add(new BooleanObject("OpenWhileExportReport", "生成报告时打开设置", true, null));
- //dedicatedLists.Add(new BooleanObject("ExportResults", "导出结果", true, null));
- //dedicatedLists.Add(new BooleanObject("ExportReports", "生成报告", true, null));
- //dedicatedLists.Add(new BooleanObject("ExportProjects", "导出项目", true, null));
- this.appWorkspace.ScriptAutomatic = false;
- this.Close();
- }
- public GrainSizeStandardDialog()
- {
- InitializeComponent();
- }
- #endregion
- #region 初始化组件
- private void InitializeLanguageText()
- {
- //
- // bc
- //
- this.bc = new PaintDotNet.CustomControl.BinaryControlSmaller();
- this.bc.BinaryBackColor = System.Drawing.Color.Red;
- this.bc.BinaryChecked = false;
- this.bc.BinaryStyle = 1;
- this.bc.Location = new System.Drawing.Point(176, 70);
- this.bc.Name = "bc";
- this.bc.OriginChecked = false;
- this.bc.scope1End = 0D;
- this.bc.scope1Start = 0D;
- this.bc.scope2End = 0D;
- this.bc.scope2Start = 0D;
- this.bc.scope3End = 0D;
- this.bc.scope3Start = 0D;
- this.bc.Size = new System.Drawing.Size(360, 247);
- this.bc.TabIndex = 38;
- this.Controls.Add(this.bc);
- this.Controls.SetChildIndex(this.bc, 0);
- this.button9.Text = PdnResources.GetString("Menu.Auxiliarylinesettings.text");
- this.groupBox3.Text = PdnResources.GetString("Menu.Tools.GridLine.Text");
- this.button11.Text = PdnResources.GetString("Menu.Showall.text");
- this.button16.Text = PdnResources.GetString("Menu.Cancelshowall.text");
- this.button12.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
- this.groupBox_analysisResult1.Text = PdnResources.GetString("Menu.Analysisresult.text");
- this.button_generateReport.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text");
- this.button_exportResults.Text = PdnResources.GetString("Menu.Exportresults.text");
- this.label_resultPrecision.Text = PdnResources.GetString("Menu.Decimal.text");
- this.button1.Text = PdnResources.GetString("Menu.Exportproject.text");
- this.threeDButton.Text = "3D效果";
- this.groupBox_img.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
- this.groupBox_review.Text = PdnResources.GetString("Menu.Preview.text");
- this.btn_saveresult.Text = PdnResources.GetString("Menu.Saveresult.text");
- this.btn_Grainboundarytoreproduce.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text");
- this.button_ApplyToAll.Text = "应用到全部";
- this.button_SaveAll.Text = "保存全部";
- this.button_setting.Text = PdnResources.GetString("Menu.Setting.Text");
- this.groupBox_operating.Text = PdnResources.GetString("Menu.operation.text");
- this.checkBox_generateReport_opensetting.Text = PdnResources.GetString("Menu.Opensettingsatingreport.text");
- }
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
- this.groupBox_operating = new System.Windows.Forms.GroupBox();
- this.button_SaveAll = new System.Windows.Forms.Button();
- this.button_ApplyToAll = new System.Windows.Forms.Button();
- this.checkBox_generateReport_opensetting = new System.Windows.Forms.CheckBox();
- this.button_setting = new System.Windows.Forms.Button();
- this.btn_saveresult = new System.Windows.Forms.Button();
- this.btn_Grainboundarytoreproduce = new System.Windows.Forms.Button();
- this.groupBox_img = new System.Windows.Forms.GroupBox();
- this.lstView_img = new System.Windows.Forms.ListView();
- this.imageList_img = new System.Windows.Forms.ImageList(this.components);
- this.groupBox_review = new System.Windows.Forms.GroupBox();
- this.groupBox_report = new System.Windows.Forms.GroupBox();
- this.threeDButton = new System.Windows.Forms.Button();
- this.button1 = new System.Windows.Forms.Button();
- this.numericUpDown1_0 = new System.Windows.Forms.NumericUpDown();
- this.label_resultPrecision = new System.Windows.Forms.Label();
- this.button_exportResults = new System.Windows.Forms.Button();
- this.button_generateReport = new System.Windows.Forms.Button();
- this.groupBox6groupBox_analysisResult2 = new System.Windows.Forms.GroupBox();
- this.dataGridView_Total = new System.Windows.Forms.DataGridView();
- this.dataGridView2 = new System.Windows.Forms.DataGridView();
- this.groupBox_analysisResult1 = new System.Windows.Forms.GroupBox();
- this.button11 = new System.Windows.Forms.Button();
- this.listView2 = new System.Windows.Forms.ListView();
- this.button16 = new System.Windows.Forms.Button();
- this.button12 = new System.Windows.Forms.Button();
- this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.button9 = new System.Windows.Forms.Button();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.groupBox_operating.SuspendLayout();
- this.groupBox_img.SuspendLayout();
- this.groupBox_report.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
- this.groupBox6groupBox_analysisResult2.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView_Total)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit();
- this.groupBox_analysisResult1.SuspendLayout();
- this.groupBox3.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox_operating
- //
- this.groupBox_operating.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox_operating.Controls.Add(this.button_SaveAll);
- this.groupBox_operating.Controls.Add(this.button_ApplyToAll);
- this.groupBox_operating.Controls.Add(this.checkBox_generateReport_opensetting);
- this.groupBox_operating.Controls.Add(this.button_setting);
- this.groupBox_operating.Controls.Add(this.btn_saveresult);
- this.groupBox_operating.Controls.Add(this.btn_Grainboundarytoreproduce);
- this.groupBox_operating.Location = new System.Drawing.Point(13, 12);
- this.groupBox_operating.Name = "groupBox_operating";
- this.groupBox_operating.Size = new System.Drawing.Size(1102, 53);
- this.groupBox_operating.TabIndex = 12;
- this.groupBox_operating.TabStop = false;
- //
- // button_SaveAll
- //
- this.button_SaveAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.button_SaveAll.Location = new System.Drawing.Point(993, 20);
- this.button_SaveAll.Name = "button_SaveAll";
- this.button_SaveAll.Size = new System.Drawing.Size(75, 23);
- this.button_SaveAll.TabIndex = 8;
- this.button_SaveAll.UseVisualStyleBackColor = true;
- this.button_SaveAll.Click += new System.EventHandler(this.button_SaveAll_Click);
- //
- // button_ApplyToAll
- //
- this.button_ApplyToAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.button_ApplyToAll.Location = new System.Drawing.Point(751, 20);
- this.button_ApplyToAll.Name = "button_ApplyToAll";
- this.button_ApplyToAll.Size = new System.Drawing.Size(75, 23);
- this.button_ApplyToAll.TabIndex = 7;
- this.button_ApplyToAll.UseVisualStyleBackColor = true;
- this.button_ApplyToAll.Click += new System.EventHandler(this.button_ApplyToAll_Click);
- //
- // checkBox_generateReport_opensetting
- //
- this.checkBox_generateReport_opensetting.AutoSize = true;
- this.checkBox_generateReport_opensetting.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
- this.checkBox_generateReport_opensetting.Location = new System.Drawing.Point(91, 24);
- this.checkBox_generateReport_opensetting.Name = "checkBox_generateReport_opensetting";
- this.checkBox_generateReport_opensetting.Size = new System.Drawing.Size(15, 14);
- this.checkBox_generateReport_opensetting.TabIndex = 6;
- this.checkBox_generateReport_opensetting.UseVisualStyleBackColor = true;
- //
- // button_setting
- //
- this.button_setting.Location = new System.Drawing.Point(6, 20);
- this.button_setting.Name = "button_setting";
- this.button_setting.Size = new System.Drawing.Size(75, 23);
- this.button_setting.TabIndex = 4;
- this.button_setting.UseVisualStyleBackColor = true;
- this.button_setting.Click += new System.EventHandler(this.button_setting_Click);
- //
- // btn_saveresult
- //
- this.btn_saveresult.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_saveresult.Location = new System.Drawing.Point(912, 20);
- this.btn_saveresult.Name = "btn_saveresult";
- this.btn_saveresult.Size = new System.Drawing.Size(75, 23);
- this.btn_saveresult.TabIndex = 2;
- this.btn_saveresult.UseVisualStyleBackColor = true;
- this.btn_saveresult.Click += new System.EventHandler(this.btn_saveresult_Click);
- //
- // btn_Grainboundarytoreproduce
- //
- this.btn_Grainboundarytoreproduce.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_Grainboundarytoreproduce.Location = new System.Drawing.Point(832, 20);
- this.btn_Grainboundarytoreproduce.Name = "btn_Grainboundarytoreproduce";
- this.btn_Grainboundarytoreproduce.Size = new System.Drawing.Size(75, 23);
- this.btn_Grainboundarytoreproduce.TabIndex = 2;
- this.btn_Grainboundarytoreproduce.UseVisualStyleBackColor = true;
- this.btn_Grainboundarytoreproduce.Click += new System.EventHandler(this.btn_Grainboundarytoreproduce_Click);
- //
- // groupBox_img
- //
- this.groupBox_img.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)));
- this.groupBox_img.Controls.Add(this.lstView_img);
- this.groupBox_img.Location = new System.Drawing.Point(13, 72);
- this.groupBox_img.Margin = new System.Windows.Forms.Padding(4);
- this.groupBox_img.Name = "groupBox_img";
- this.groupBox_img.Padding = new System.Windows.Forms.Padding(4);
- this.groupBox_img.Size = new System.Drawing.Size(158, 502);
- this.groupBox_img.TabIndex = 13;
- this.groupBox_img.TabStop = false;
- //
- // lstView_img
- //
- this.lstView_img.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.lstView_img.HideSelection = false;
- this.lstView_img.LargeImageList = this.imageList_img;
- this.lstView_img.Location = new System.Drawing.Point(8, 26);
- this.lstView_img.Margin = new System.Windows.Forms.Padding(4);
- this.lstView_img.MultiSelect = false;
- this.lstView_img.Name = "lstView_img";
- this.lstView_img.Size = new System.Drawing.Size(140, 468);
- this.lstView_img.TabIndex = 0;
- this.lstView_img.UseCompatibleStateImageBehavior = false;
- this.lstView_img.SelectedIndexChanged += new System.EventHandler(this.lstView_img_SelectedIndexChanged);
- //
- // imageList_img
- //
- this.imageList_img.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
- this.imageList_img.ImageSize = new System.Drawing.Size(64, 64);
- this.imageList_img.TransparentColor = System.Drawing.Color.Transparent;
- //
- // groupBox_review
- //
- this.groupBox_review.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox_review.Location = new System.Drawing.Point(541, 72);
- this.groupBox_review.Name = "groupBox_review";
- this.groupBox_review.Size = new System.Drawing.Size(575, 502);
- this.groupBox_review.TabIndex = 30;
- this.groupBox_review.TabStop = false;
- //
- // groupBox_report
- //
- this.groupBox_report.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox_report.Controls.Add(this.threeDButton);
- this.groupBox_report.Controls.Add(this.button1);
- this.groupBox_report.Controls.Add(this.numericUpDown1_0);
- this.groupBox_report.Controls.Add(this.label_resultPrecision);
- this.groupBox_report.Controls.Add(this.button_exportResults);
- this.groupBox_report.Controls.Add(this.button_generateReport);
- this.groupBox_report.Location = new System.Drawing.Point(974, 580);
- this.groupBox_report.Name = "groupBox_report";
- this.groupBox_report.Size = new System.Drawing.Size(142, 218);
- this.groupBox_report.TabIndex = 33;
- this.groupBox_report.TabStop = false;
- //
- // threeDButton
- //
- this.threeDButton.Location = new System.Drawing.Point(28, 149);
- this.threeDButton.Name = "threeDButton";
- this.threeDButton.Size = new System.Drawing.Size(75, 23);
- this.threeDButton.TabIndex = 24;
- this.threeDButton.UseVisualStyleBackColor = true;
- this.threeDButton.Click += new System.EventHandler(this.threeDButton_Click);
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(29, 112);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 23;
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // numericUpDown1_0
- //
- this.numericUpDown1_0.Location = new System.Drawing.Point(63, 184);
- this.numericUpDown1_0.Maximum = new decimal(new int[] {
- 10,
- 0,
- 0,
- 0});
- this.numericUpDown1_0.Name = "numericUpDown1_0";
- this.numericUpDown1_0.Size = new System.Drawing.Size(56, 21);
- this.numericUpDown1_0.TabIndex = 22;
- this.numericUpDown1_0.Value = new decimal(new int[] {
- 2,
- 0,
- 0,
- 0});
- this.numericUpDown1_0.ValueChanged += new System.EventHandler(this.numericUpDown1_0_ValueChanged);
- //
- // label_resultPrecision
- //
- this.label_resultPrecision.AutoSize = true;
- this.label_resultPrecision.Location = new System.Drawing.Point(26, 188);
- this.label_resultPrecision.Name = "label_resultPrecision";
- this.label_resultPrecision.Size = new System.Drawing.Size(0, 12);
- this.label_resultPrecision.TabIndex = 3;
- //
- // button_exportResults
- //
- this.button_exportResults.Location = new System.Drawing.Point(29, 73);
- this.button_exportResults.Name = "button_exportResults";
- this.button_exportResults.Size = new System.Drawing.Size(75, 23);
- this.button_exportResults.TabIndex = 1;
- this.button_exportResults.UseVisualStyleBackColor = true;
- this.button_exportResults.Click += new System.EventHandler(this.button_exportResults_Click);
- //
- // button_generateReport
- //
- this.button_generateReport.Location = new System.Drawing.Point(29, 34);
- this.button_generateReport.Name = "button_generateReport";
- this.button_generateReport.Size = new System.Drawing.Size(75, 23);
- this.button_generateReport.TabIndex = 0;
- this.button_generateReport.UseVisualStyleBackColor = true;
- this.button_generateReport.Click += new System.EventHandler(this.button_generateReport_Click);
- //
- // groupBox6groupBox_analysisResult2
- //
- this.groupBox6groupBox_analysisResult2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox6groupBox_analysisResult2.Controls.Add(this.dataGridView_Total);
- this.groupBox6groupBox_analysisResult2.Controls.Add(this.dataGridView2);
- this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 580);
- this.groupBox6groupBox_analysisResult2.Name = "groupBox6groupBox_analysisResult2";
- this.groupBox6groupBox_analysisResult2.Size = new System.Drawing.Size(719, 218);
- this.groupBox6groupBox_analysisResult2.TabIndex = 32;
- this.groupBox6groupBox_analysisResult2.TabStop = false;
- //
- // dataGridView_Total
- //
- this.dataGridView_Total.AllowUserToAddRows = false;
- this.dataGridView_Total.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.dataGridView_Total.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
- this.dataGridView_Total.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
- dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
- dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
- dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F);
- dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
- dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
- dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
- dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
- this.dataGridView_Total.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
- this.dataGridView_Total.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.dataGridView_Total.Location = new System.Drawing.Point(13, 144);
- this.dataGridView_Total.Name = "dataGridView_Total";
- this.dataGridView_Total.ReadOnly = true;
- this.dataGridView_Total.RowHeadersVisible = false;
- this.dataGridView_Total.RowTemplate.Height = 23;
- this.dataGridView_Total.Size = new System.Drawing.Size(693, 68);
- this.dataGridView_Total.TabIndex = 17;
- //
- // dataGridView2
- //
- this.dataGridView2.AllowUserToAddRows = false;
- this.dataGridView2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.dataGridView2.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
- this.dataGridView2.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
- dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
- dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control;
- dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F);
- dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText;
- dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
- dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
- dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
- this.dataGridView2.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
- this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.dataGridView2.Location = new System.Drawing.Point(13, 12);
- this.dataGridView2.Name = "dataGridView2";
- this.dataGridView2.ReadOnly = true;
- this.dataGridView2.RowHeadersVisible = false;
- this.dataGridView2.RowTemplate.Height = 23;
- this.dataGridView2.Size = new System.Drawing.Size(693, 128);
- this.dataGridView2.TabIndex = 16;
- //
- // groupBox_analysisResult1
- //
- this.groupBox_analysisResult1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.groupBox_analysisResult1.Controls.Add(this.button11);
- this.groupBox_analysisResult1.Controls.Add(this.listView2);
- this.groupBox_analysisResult1.Controls.Add(this.button16);
- this.groupBox_analysisResult1.Controls.Add(this.button12);
- this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 580);
- this.groupBox_analysisResult1.Name = "groupBox_analysisResult1";
- this.groupBox_analysisResult1.Size = new System.Drawing.Size(224, 218);
- this.groupBox_analysisResult1.TabIndex = 31;
- this.groupBox_analysisResult1.TabStop = false;
- //
- // button11
- //
- this.button11.BackColor = System.Drawing.SystemColors.Control;
- this.button11.Location = new System.Drawing.Point(19, 22);
- this.button11.Name = "button11";
- this.button11.Size = new System.Drawing.Size(63, 26);
- this.button11.TabIndex = 27;
- this.button11.UseVisualStyleBackColor = false;
- this.button11.Click += new System.EventHandler(this.button11_Click);
- //
- // listView2
- //
- this.listView2.FullRowSelect = true;
- this.listView2.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
- this.listView2.HideSelection = false;
- this.listView2.Location = new System.Drawing.Point(19, 58);
- this.listView2.Name = "listView2";
- this.listView2.Size = new System.Drawing.Size(182, 149);
- this.listView2.TabIndex = 26;
- this.listView2.UseCompatibleStateImageBehavior = false;
- this.listView2.SelectedIndexChanged += new System.EventHandler(this.listview2_SelectedIndexChanged);
- //
- // button16
- //
- this.button16.BackColor = System.Drawing.SystemColors.Control;
- this.button16.Location = new System.Drawing.Point(19, 21);
- this.button16.Name = "button16";
- this.button16.Size = new System.Drawing.Size(93, 26);
- this.button16.TabIndex = 25;
- this.button16.UseVisualStyleBackColor = false;
- this.button16.Click += new System.EventHandler(this.button16_Click);
- //
- // button12
- //
- this.button12.BackColor = System.Drawing.SystemColors.Control;
- this.button12.Location = new System.Drawing.Point(149, 21);
- this.button12.Name = "button12";
- this.button12.Size = new System.Drawing.Size(52, 26);
- this.button12.TabIndex = 24;
- this.button12.UseVisualStyleBackColor = false;
- this.button12.Click += new System.EventHandler(this.button12_Click);
- //
- // groupBox3
- //
- this.groupBox3.Controls.Add(this.button9);
- this.groupBox3.Controls.Add(this.comboBox1);
- this.groupBox3.Location = new System.Drawing.Point(179, 320);
- this.groupBox3.Name = "groupBox3";
- this.groupBox3.Size = new System.Drawing.Size(355, 48);
- this.groupBox3.TabIndex = 34;
- this.groupBox3.TabStop = false;
- //
- // button9
- //
- this.button9.BackColor = System.Drawing.SystemColors.Control;
- this.button9.Location = new System.Drawing.Point(241, 15);
- this.button9.Name = "button9";
- this.button9.Size = new System.Drawing.Size(92, 26);
- this.button9.TabIndex = 10;
- this.button9.UseVisualStyleBackColor = false;
- this.button9.Click += new System.EventHandler(this.button9_Click);
- //
- // comboBox1
- //
- this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Location = new System.Drawing.Point(15, 18);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(220, 20);
- this.comboBox1.TabIndex = 0;
- this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- //
- // GrainSizeStandardDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(1127, 810);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox_report);
- this.Controls.Add(this.groupBox6groupBox_analysisResult2);
- this.Controls.Add(this.groupBox_analysisResult1);
- this.Controls.Add(this.groupBox_review);
- this.Controls.Add(this.groupBox_img);
- this.Controls.Add(this.groupBox_operating);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.Name = "GrainSizeStandardDialog";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GrainSizeStandardDialog_FormClosing);
- this.Load += new System.EventHandler(this.GrainSizeStandardDialog_Load);
- this.Controls.SetChildIndex(this.groupBox_operating, 0);
- this.Controls.SetChildIndex(this.groupBox_img, 0);
- this.Controls.SetChildIndex(this.groupBox_review, 0);
- this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
- this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
- this.Controls.SetChildIndex(this.groupBox_report, 0);
- this.Controls.SetChildIndex(this.groupBox3, 0);
- this.groupBox_operating.ResumeLayout(false);
- this.groupBox_operating.PerformLayout();
- this.groupBox_img.ResumeLayout(false);
- this.groupBox_report.ResumeLayout(false);
- this.groupBox_report.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
- this.groupBox6groupBox_analysisResult2.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView_Total)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
- this.groupBox_analysisResult1.ResumeLayout(false);
- this.groupBox3.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- private void DataGridView2_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
- {
- //DetailListNotDoubleIndex.Add(0); //DetailListNotDoubleIndex.Add(1);
- // 如果是学号或成绩列,则按浮点数处理
- if (DetailListNotDoubleIndex.Count > 0 && !DetailListNotDoubleIndex.Contains(e.Column.Index))
- {
- e.SortResult = (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) > 0) ? 1 : (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) < 0) ? -1 : 0;
- }
- //否则,按字符串比较
- else
- {
- e.SortResult = System.String.Compare(Convert.ToString(e.CellValue1), Convert.ToString(e.CellValue2));
- }
- e.Handled = true;//不能省掉,不然没效果
- }
- /// <summary>
- /// 选中的左侧list的下标
- /// </summary>
- protected int index = 0;
- public void Initialize()
- {
- //初始化图片列表
- for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
- {
- this.imageList_img.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail);
- this.lstView_img.Items.Add("", i);
- this.lstView_img.Items[i].ImageIndex = i;
- this.lstView_img.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- this.lstView_img.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- if (this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
- {
- index = i;
- }
- }
- //
- // 初始化选中的数据
- //
- if (index >= 0 && index < this.lstView_img.Items.Count)
- this.lstView_img.Items[index].Selected = true; //选中行 //##21319
- //
- //初始化图像控件
- //
- this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace);
- this.documentWorkspace.Cursor = Cursors.Default;
- this.documentWorkspace.Dock = DockStyle.Fill;
- this.documentWorkspace.HookMouseEvents();
- this.documentWorkspace.AuxiliaryLineEnabled = false;
- this.documentWorkspace.Visible = true;
- this.documentWorkspace.panel.MouseDown += OnMouseDown;
- this.documentWorkspace.panel.Paint += Panel_Paint;
- this.documentWorkspace.panel.MouseMove += onMouseMove;
- this.documentWorkspace.panel.MouseUp += onMouseUp;
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;//禁止视场移动
- this.groupBox_review.Controls.Add(this.documentWorkspace);
- //
- //初始化操作按钮
- //
- this.commonControlButtons = new CommonControlButtons();
- this.commonControlButtons.Dock = DockStyle.Top;
- this.commonControlButtons.Height = 30;
- this.commonControlButtons.HideZoomToWindowAndActualSize();
- this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
- this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
- this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
- this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
- this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
- this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
- groupBox_review.Controls.Add(this.commonControlButtons);
- ////
- //// 初始化选中的数据
- ////
- //this.lstView_img.Items[index].Selected = true; //选中行
- }
- #endregion
- #region 二值化相关方法
- /// <summary>
- /// 添加参数改变的监听
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void GrainSizeStandardDialog_Load(object sender, EventArgs e)
- {
- this.threeDButton.Enabled = false;
- System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
- this.dataGridView2.SortCompare += DataGridView2_SortCompare;
- if (grainMethodType == 0)
- {
- GSSClass.styleClass.styleModel.UpdateCupOffPointStyle();
- AddRectangleToRectangleFCaps();
- }
- ////二值化集成3
- //this.binaryClass.loadParams();
- //this.binaryClass.guideClass = GSSClass.GuideClass;
- //this.binaryClass.comboBox1 = this.comboBox1;
- //object ShowGrainBoundry;//#21752
- //if (GetParamValue1(ParamKey_CalculatorDecimalDigits, out ShowGrainBoundry))//小数点位数
- // this.numericUpDown1_0.Value = (int)ShowGrainBoundry;
- //if (GetParamValue1(ParamKey_OpenWhileExportReport, out ShowGrainBoundry))//生成报告时打开设置
- // this.checkBox_generateReport_opensetting.Checked = (bool)ShowGrainBoundry;
- this.finishedLoadAction++;
- if (this.finishedLoadAction > 0 && this.initScriptValues && this.appWorkspace.ScriptAutomatic)
- this.startScriptAutomaticAction();
- }
- private bool bcBinaryChecked()
- {
- return bc != null && bc.BinaryChecked;
- }
- protected bool bcOriginChecked()
- {
- return bc != null && bc.OriginChecked;
- }
- /// <summary>
- /// 参数改变时,重新处理图像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void bClassBinaryImplFinishAction(object sender, EventArgs e)
- {
- if (grainMethodType == 1 && GetClassNumberOfGrains() == 0)
- this.documentWorkspace.Refresh();
- else//###############################################################
- AddRectangleToRectangleFCaps();
- }
- /// <summary>
- /// 显示原图/原图+二值图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void bcOriginCheckedChanged(object sender, EventArgs e)
- {
- if (!bcOriginChecked())
- {
- if (bcBinaryChecked())
- this.documentWorkspace.PhaseModels[0].choise = true;
- if (getGrainBoundryChecked() && ShowGrainBoundryChecked())
- this.documentWorkspace.PhaseModels[1].choise = true;
- if (grainMethodType == 1 && ShowGrainColorChecked())
- this.documentWorkspace.PhaseModels[2].choise = true;
- }
- else
- {
- this.documentWorkspace.PhaseModels[0].choise = false;
- this.documentWorkspace.PhaseModels[1].choise = false;
- this.documentWorkspace.PhaseModels[2].choise = false;
- }
- this.documentWorkspace.Refresh();
- }
- #endregion
- #region 内部方法
- /// <summary>
- /// 设置按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_setting_Click(object sender, EventArgs e)
- {
- string templateName;
- try
- {
- templateName = getTemplateName();
- }
- catch (Exception)
- {
- templateName = GSSClass.methodOfAssessment.resourcesName;
- }
- AnalyzeSettingDialog metallographicMethodSetDialog = new AnalyzeSettingDialog(this, templateName);
- if (metallographicMethodSetDialog.hasModule)
- {
- metallographicMethodSetDialog.StartPosition = FormStartPosition.CenterScreen;
- metallographicMethodSetDialog.ShowDialog();
- }
- else
- {
- metallographicMethodSetDialog = null;
- }
- }
- /// <summary>
- /// 保存结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_saveresult_Click(object sender, EventArgs e)
- {
- GSSClass.GuideClass.guideModel.oldSelectItem = (string)this.comboBox1.SelectedItem;
- buildListBox_analysisResult(getCurrentWorkTag(), this.selectPicture);
- }
- /// <summary>
- /// 相1的图片,处理多视场使用
- /// </summary>
- protected Mat PhaseModels1Mat;
- protected Color PhaseModels1Color;
- /// <summary>
- /// 晶界重现
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_Grainboundarytoreproduce_Click(object sender, EventArgs e)
- {
- //if (this.documentWorkspace.PhaseModels.Count < 2 || /*this.documentWorkspace.PhaseModels[1].choise == true && */this.documentWorkspace.PhaseModels[1].mat == null)
- //{
- // MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text"));
- // return;
- //}
- if (this.bitmap == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!");
- return;
- }
- //1013###19326 晶粒度的晶界编辑页面,需要把辅助线带过去(客户编辑只处理辅助线位置的晶界)
- GrainBoundaryEditingDialog boundaryEditingDialog = new GrainBoundaryEditingDialog(this.appWorkspace, this.menuId, this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index, this.documentWorkspace.PhaseModels[1].mat == null ? Color.Red : PhaseModels1Color/*this.panel1.BackColor*/
- , this.documentWorkspace.PhaseModels[1].mat == null ? null : this.documentWorkspace.PhaseModels[1].mat.Clone(), ShowDrawClassView());
- boundaryEditingDialog.GuideClass = GSSClass.GuideClass;
- boundaryEditingDialog.SelectedItem = this.comboBox1.SelectedItem;
- if (boundaryEditingDialog.ShowDialog() == DialogResult.OK && boundaryEditingDialog.PhaseMat != null)
- {
- string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel_" + this.menuId + ".xml";
- if (System.IO.File.Exists(xmlFilePath))
- {
- Base.SettingModel.GrainBoundryDectModel grainBoundryDectModel = Base.CommTool.XmlSerializeHelper.DESerializer<Base.SettingModel.GrainBoundryDectModel>(Base.CommTool.FileOperationHelper.ReadStringFromFile(xmlFilePath, System.IO.FileMode.Open));
- //sigma = grainBoundryDectModel.sigma;
- if (!this.grainBoundaryDict.ContainsKey(getCurrentWorkTag()))
- this.grainBoundaryDict.Add(getCurrentWorkTag(), grainBoundryDectModel.cloneModel());
- else
- this.grainBoundaryDict[getCurrentWorkTag()] = grainBoundryDectModel.cloneModel();
- }
- if (this.grainBoundaryDict[getCurrentWorkTag()].grainApplygrainboundaries != 1)
- {//没有选择应用选项
- if (this.grainBoundaryMatDict.ContainsKey(getCurrentWorkTag()))
- {
- this.grainBoundaryMatDict.Remove(getCurrentWorkTag());
- this.documentWorkspace.PhaseModels[1].mat = null;
- if (PhaseModels1Mat != null)
- {
- PhaseModels1Mat.Dispose();
- PhaseModels1Mat = null;
- }
- if (grainMethodType == 1)
- if (GetClassNumberOfGrains() == 0)
- this.documentWorkspace.Refresh();
- else
- AddRectangleToRectangleFCaps();
- this.documentWorkspace.PhaseModels[1].choise = (!bcOriginChecked() && getGrainBoundryChecked() && ShowGrainBoundryChecked());
- //this.documentWorkspace.Refresh();
- if (grainMethodType == 1 && GetClassNumberOfGrains() == 0)
- this.documentWorkspace.Refresh();
- else//###############################################################//#20991
- AddRectangleToRectangleFCaps();
- }
- return;
- }
- PhaseModels1Color = boundaryEditingDialog.PhaseColor;
- if (PhaseModels1Mat != null)
- {
- PhaseModels1Mat.Dispose();
- PhaseModels1Mat = null;
- }
- if (getCurrentWorkspace().GraphicsList.IsExsitView())
- PhaseModels1Mat = boundaryEditingDialog.PhaseMat.Clone();
- this.documentWorkspace.PhaseModels[1].mat = boundaryEditingDialog.PhaseMat.Clone();
- if (!this.grainBoundaryMatDict.ContainsKey(getCurrentWorkTag()))
- this.grainBoundaryMatDict.Add(getCurrentWorkTag(), boundaryEditingDialog.PhaseMat.Clone());
- else
- this.grainBoundaryMatDict[getCurrentWorkTag()] = boundaryEditingDialog.PhaseMat.Clone();
- //if (grainMethodType == 1)
- // if (GetClassNumberOfGrains() == 0)
- // this.documentWorkspace.Refresh();
- // else
- // AddRectangleToRectangleFCaps();
- this.documentWorkspace.PhaseModels[1].choise = (!bcOriginChecked() && getGrainBoundryChecked() && ShowGrainBoundryChecked());
- if (grainMethodType == 1 && GetClassNumberOfGrains() == 0)
- this.documentWorkspace.Refresh();
- else//###############################################################//#20991
- AddRectangleToRectangleFCaps();
- this.documentWorkspace.Refresh();
- }
- }
- private void lstView_img_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.lstView_img.FocusedItem != null && this.lstView_img.FocusedItem.Selected)
- {
- if (this.selectPicture == this.lstView_img.FocusedItem.Index)
- return;
- this.refreshActionWhileImg_SelectedIndexChanged(false);
- }
- }
- /// <summary>
- /// 导出项目
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- if (this.listView2.Items.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Noresults.text"));
- return;
- }
- if (this.checkBox_generateReport_opensetting.Checked)
- this.button_setting.PerformClick();
- if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
- {
- //获取项目工程内的文件夹路径
- ProjectEngineering.NodeItem nodeItem = this.appWorkspace.GetInsertProjectPath(2, getProjectEngineeringName(), this.analyzeSettingModel.savePath);
- if (nodeItem == null) return;
- //获取word书签与excel单元格的关系,以字典方式存储
- List<mic_module_infos> mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
- Dictionary<string, string> tagInfos = new Dictionary<string, string>();
- if (mic_module_infos != null && mic_module_infos.Count > 0)
- {
- foreach (mic_module_infos info in mic_module_infos)
- {
- tagInfos.Add(info.tag_name, info.cell_position);
- }
- }
- //分析结果
- List<List<string>> analysisContent = new List<List<string>>();
- List<string> contentHeaderText2 = new List<string>();
- foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
- {
- contentHeaderText2.Add(c.HeaderText);
- }
- analysisContent.Add(contentHeaderText2);
- foreach (DataGridViewRow item in this.dataGridView_Total.Rows)//##########################
- {
- List<string> content = new List<string>();
- for (int i = 0; i < contentHeaderText2.Count; i++)
- {
- content.Add(item.Cells[i].Value.ToString());
- }
- analysisContent.Add(content);
- }
- List<string> contentHeaderText = new List<string>();
- foreach (DataGridViewColumn c in this.dataGridView2.Columns)
- {
- contentHeaderText.Add(c.HeaderText);
- }
- analysisContent.Add(contentHeaderText);
- foreach (DataGridViewRow item in this.dataGridView2.Rows)//################################
- {
- List<string> content = new List<string>();
- for (int i = 0; i < contentHeaderText.Count; i++)
- {
- content.Add(item.Cells[i].Value.ToString());
- }
- analysisContent.Add(content);
- }
- //图片
- bitList = new List<Bitmap>();
- List<string> pNamesList = new List<string>();
- //中间数据
- List<ExportProjectModel> exportModel = new List<ExportProjectModel>();
- if (this.allShow)
- {
- foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitDic)
- {
- int cal_Index = int.Parse(kv.Key.Replace("img", ""));
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- pNamesList.Add(imgName);
- bitList.Add(kv.Value[0]);
- bitList.Add(kv.Value[1]);
- }
- //中间数据
- foreach (ExportProjectModel model in this.tempDataModel)
- {
- ExportProjectModel tempModel = new ExportProjectModel();
- tempModel.tagName = model.tagName;
- tempModel.picName = model.picName;
- tempModel.dataList = model.dataList;
- exportModel.Add(tempModel);
- }
- }
- else
- {
- if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
- {
- foreach (ListViewItem item in this.listView2.SelectedItems)
- {
- if (bitDic.ContainsKey(item.Name))
- {
- int cal_Index = int.Parse(item.Name.Replace("img", ""));
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- pNamesList.Add(imgName);
- bitList.Add(bitDic[item.Name][0]);
- bitList.Add(bitDic[item.Name][1]);
- }
- else if (bitDic.ContainsKey(item.Tag.ToString()))
- {
- int cal_Index = int.Parse(item.Tag.ToString().Replace("img", ""));
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- pNamesList.Add(imgName);
- bitList.Add(bitDic[item.Tag.ToString()][0]);
- bitList.Add(bitDic[item.Tag.ToString()][1]);
- }
- }
- //中间数据
- foreach (ListViewItem rowItem in this.listView2.SelectedItems)
- {
- foreach (ExportProjectModel model in this.tempDataModel)
- {
- if (model.tagName.Equals(rowItem.Name))
- {
- ExportProjectModel tempModel = new ExportProjectModel();
- tempModel.tagName = model.tagName;
- tempModel.picName = model.picName;
- tempModel.dataList = model.dataList;
- exportModel.Add(tempModel);
- break;
- }
- else if (model.tagName.Equals(rowItem.Tag.ToString()))
- {
- ExportProjectModel tempModel = new ExportProjectModel();
- tempModel.tagName = model.tagName;
- tempModel.picName = model.picName;
- tempModel.dataList = model.dataList;
- exportModel.Add(tempModel);
- break;
- }
- }
- }
- }
- else if (this.listView2.Items.Count > 0)
- {
- ListViewItem rowItem = this.listView2.Items[0];
- if (bitDic.ContainsKey(rowItem.Name))
- {
- int cal_Index = int.Parse(rowItem.Name.Replace("img", ""));
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- pNamesList.Add(imgName);
- bitList.Add(bitDic[rowItem.Name][0]);
- bitList.Add(bitDic[rowItem.Name][1]);
- }
- else if (bitDic.ContainsKey(rowItem.Tag.ToString()))
- {
- int cal_Index = int.Parse(rowItem.Tag.ToString().Replace("img", ""));
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- pNamesList.Add(imgName);
- bitList.Add(bitDic[rowItem.Tag.ToString()][0]);
- bitList.Add(bitDic[rowItem.Tag.ToString()][1]);
- }
- //中间数据
- foreach (ExportProjectModel model in this.tempDataModel)
- {
- if (model.tagName.Equals(rowItem.Name))
- {
- ExportProjectModel tempModel = new ExportProjectModel();
- tempModel.tagName = model.tagName;
- tempModel.picName = model.picName;
- tempModel.dataList = model.dataList;
- exportModel.Add(tempModel);
- break;
- }
- else if (model.tagName.Equals(rowItem.Tag.ToString()))
- {
- ExportProjectModel tempModel = new ExportProjectModel();
- tempModel.tagName = model.tagName;
- tempModel.picName = model.picName;
- tempModel.dataList = model.dataList;
- exportModel.Add(tempModel);
- break;
- }
- }
- }
- }
- string dictPath = Application.StartupPath + "\\temp";
- if (!System.IO.Directory.Exists(dictPath))
- {
- System.IO.Directory.CreateDirectory(dictPath);
- }
- DeleteFolder(dictPath);
- pNames = new Dictionary<string, string>();
- int insertIn = 0;
- for (int k = 0; k < bitList.Count; k += 2)
- {//保存处理后的图片
- List<Bitmap> tempBit = new List<Bitmap>();
- tempBit.Add((Bitmap)bitList[k].Clone());
- tempBit.Add((Bitmap)bitList[k+1].Clone());
- this.SaveAllImage(tempBit, dictPath, insertIn + 1, insertIn + 1, pNamesList[insertIn]);
- insertIn++;
- }
- this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, exportModel, bitList, tagInfos, nodeItem.path, nodeItem.code, dictPath, pNames);
- //保存项目信息到数据库
- this.appWorkspace.InsertIntoDB(this.analyzeSettingModel, nodeItem);
- }
- else
- MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
- }
- Dictionary<string, string> pNames = new Dictionary<string, string>();
- /// <summary>
- /// 保存图片到本地
- /// </summary>
- /// <param name="bitList"></param>
- private void SaveAllImage(List<Bitmap> bitList, string newPath, int originNum, int codeNum, string pName)
- {
- if (bitList != null && bitList.Count > 0)
- {
- for (int i = 0; i < bitList.Count; i++)
- {
- string bitPath = "";
- //分别为原图和处理后的图命名
- if (i % 2 == 0)
- {
- bitPath = newPath + "/" + "origin" + originNum + ".jpg";
- pNames.Add("origin" + originNum, pName);
- }
- else
- {
- bitPath = newPath + "/" + codeNum + ".jpg";
- pNames.Add(codeNum.ToString(), pName);
- }
- bitList[i].Save(bitPath);
- }
- }
- }
- public void DeleteFolder(string path)
- {
- foreach (string d in Directory.GetFileSystemEntries(path))
- {
- if (System.IO.File.Exists(d))
- {
- FileInfo fi = new FileInfo(d);
- if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
- fi.Attributes = FileAttributes.Normal;
- System.IO.File.Delete(d);//直接删除其中的文件
- }
- else
- {
- DirectoryInfo d1 = new DirectoryInfo(d);
- if (d1.GetFiles().Length != 0)
- {
- DeleteFolder(d1.FullName);
- }
- Directory.Delete(d);
- }
- }
- }
- /// <summary>
- /// 导出结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_exportResults_Click(object sender, EventArgs e)
- {
- if (this.listView2.Items.Count > 0)
- {
- List<System.Data.DataTable> list = new List<System.Data.DataTable>();
- System.Data.DataTable table1 = new System.Data.DataTable();
- table1.TableName = PdnResources.GetString("Menu.breakdown.text");
- foreach (DataGridViewColumn c in this.dataGridView2.Columns)
- {
- table1.Columns.Add(HeaderTextUsable ? c.HeaderText : c.Name);
- }
- for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
- {
- System.Data.DataRow dataRow = table1.NewRow();
- if (r == 0)
- {
- for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
- {
- dataRow[HeaderTextUsable ? this.dataGridView2.Columns[c].HeaderText : this.dataGridView2.Columns[c].Name] = this.dataGridView2.Columns[c].HeaderText;
- }
- table1.Rows.Add(dataRow);
- }
- dataRow = table1.NewRow();
- for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
- {
- dataRow[HeaderTextUsable ? this.dataGridView2.Columns[c].HeaderText : this.dataGridView2.Columns[c].Name] = this.dataGridView2.Rows[r].Cells[c].Value;
- }
- table1.Rows.Add(dataRow);
- }
- System.Data.DataTable table2 = new System.Data.DataTable();
- table2.TableName = PdnResources.GetString("Menu.statisaatics.text");
- foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
- {
- table2.Columns.Add(HeaderTextUsable ? c.HeaderText : c.Name);
- }
- for (int r = 0; r < this.dataGridView_Total.Rows.Count; r++)
- {
- System.Data.DataRow dataRow = table2.NewRow();
- if (r == 0)
- {
- for (int c = 0; c < this.dataGridView_Total.Rows[r].Cells.Count; c++)
- {
- dataRow[HeaderTextUsable ? this.dataGridView_Total.Columns[c].HeaderText : this.dataGridView_Total.Columns[c].Name] = this.dataGridView_Total.Columns[c].HeaderText;
- }
- table2.Rows.Add(dataRow);
- }
- dataRow = table2.NewRow();
- for (int c = 0; c < this.dataGridView_Total.Rows[r].Cells.Count; c++)
- {
- dataRow[HeaderTextUsable ? this.dataGridView_Total.Columns[c].HeaderText : this.dataGridView_Total.Columns[c].Name] = this.dataGridView_Total.Rows[r].Cells[c].Value;
- }
- table2.Rows.Add(dataRow);
- }
- if (table2.Rows.Count > 0) list.Add(table2);
- if (table1.Rows.Count > 0) list.Add(table1);
- if (list.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Nonedata.Text") + "!");
- return;
- }
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- saveFileDialog.DefaultExt = "xlsx";
- saveFileDialog.Title = PdnResources.GetString("Menu.ExportdatatoEXECLtable.Text");
- saveFileDialog.FileName = this.Text + PdnResources.GetString("Menu.Analysisresult.text") + DateTime.Now.ToString("yyyyMMddhhmmss");
- saveFileDialog.Filter = "microsoft office execl files (*.xlsx)|*.xlsx";
- saveFileDialog.RestoreDirectory = true;
- if (saveFileDialog.ShowDialog() == DialogResult.OK)
- this.appWorkspace.ExportDataToExcelWithProgress(list, saveFileDialog.FileName, HeaderTextUsable, false, true);
- }
- else
- MessageBox.Show(PdnResources.GetString("Menu.Noanalysisresults.text")+"!");
- }
- /// <summary>
- /// 画布绘制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Panel_Paint(object sender, PaintEventArgs e)
- {
- if (this.documentWorkspace.CompositionSurface != null)
- {
- //
- // 以下是计算绘制图片的位置和大小并绘制图片
- //
- System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
- int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
- int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
- int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
- int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
- //
- // 以下是绘制网格、标注、测量、视场等开始
- //
- e.Graphics.TranslateTransform(x, y);
- e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
- Draw(e.Graphics);
- e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
- e.Graphics.TranslateTransform(-x, -y);
- }
- }
- /// <summary>
- /// 绘制
- /// </summary>
- private void Draw(Graphics graphics)
- {
- // 抗锯齿
- graphics.SmoothingMode = SmoothingMode.AntiAlias;
- drawSubclass(graphics);
- }
- /// <summary>
- /// 计算汇总列表的平均晶粒度级别
- /// </summary>
- /// <returns></returns>
- protected virtual string getGradeTotalCal(DataGridViewRow dgvr, int digits = -1)
- {
- return "00A";
- }
- /// <summary>
- /// 取消全部显示
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button16_Click(object sender, EventArgs e)
- {
- this.button11.Visible = true;
- this.button16.Visible = false;
- this.button11.Focus();
- this.allShow = false;
- this.dataGridView2.Rows.Clear();
- if (this.listView2.SelectedItems.Count <= 0)
- {
- if (this.listView2.Items.Count > 0)
- {
- this.listView2.Items[this.listView2.Items.Count - 1].Selected = true;
- }
- else
- {
- return;
- }
- }
- List<List<double>> valueList = new List<List<double>>();
- double value_1 = 0;
- double small_l = 0;
- this.dataGridView2.Rows.Clear();
- for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
- {
- System.Data.DataTable dataTable1 = new System.Data.DataTable();
- foreach (var dataTable in this.dataTables)
- {
- if (this.listView2.SelectedItems.Count > 0)
- {
- if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
- {
- dataTable1 = dataTable;
- for (int rIndex = 0; rIndex < dataTable1.Rows.Count; rIndex++)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- List<double> valueL = new List<double>();
- for (int c = 0; c < dataTable1.Columns.Count; c++)
- {
- dgvr.Cells[c].Value = dataTable1.Rows[rIndex][c].ToString();
- if (IndexChangedFromIndex.Count > 0)
- {
- if (IndexChangedFromIndex.Contains(c))
- valueL.Add(double.Parse(dataTable1.Rows[rIndex][c].ToString()));
- continue;
- }
- if (c == 3)
- value_1 += double.Parse(dataTable1.Rows[rIndex][c].ToString());
- if (grainMethodType == 1 && c == 4 || grainMethodType == 0 && c == 2)
- small_l += double.Parse(dataTable1.Rows[rIndex][c].ToString());
- }
- if (IndexChangedFromIndex.Count > 0)
- valueList.Add(valueL);
- this.dataGridView2.Rows.Add(dgvr);
- }
- }
- }
- else
- {
- if (this.listView2.Items[0].Tag.Equals(dataTable.TableName))
- {
- dataTable1 = dataTable;
- for (int rIndex = 0; rIndex < dataTable1.Rows.Count; rIndex++)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- List<double> valueL = new List<double>();
- for (int c = 0; c < dataTable1.Columns.Count; c++)
- {
- dgvr.Cells[c].Value = dataTable1.Rows[rIndex][c].ToString();
- if (IndexChangedFromIndex.Count > 0)
- {
- if (IndexChangedFromIndex.Contains(c))
- valueL.Add(double.Parse(dataTable1.Rows[rIndex][c].ToString()));
- continue;
- }
- if (c == 3)
- value_1 += double.Parse(dataTable1.Rows[rIndex][c].ToString());
- if (grainMethodType == 1 && c == 4 || grainMethodType == 0 && c == 2)
- small_l += double.Parse(dataTable1.Rows[rIndex][c].ToString());
- }
- if (IndexChangedFromIndex.Count > 0)
- valueList.Add(valueL);
- this.dataGridView2.Rows.Add(dgvr);
- }
- }
- }
- }
- }
- this.dataGridView_Total.Rows.Clear();
- if (IndexChangedFromIndex.Count > 0 && IndexChangedToIndex.Count > 0 && valueList.Count > 0)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- foreach (int itemkey in IndexChangedToIndex.Keys)
- {
- int[] itemValue = IndexChangedToIndex[itemkey];
- List<double> valueL = new List<double>();//级别时会多算一遍,应该不影响什么
- if (itemValue[1] >= 0)
- foreach (List<double> itemL in valueList)
- {
- valueL.Add(itemL[itemValue[1]]);
- }
- if (itemValue[0] == 1)//求和
- dgvr.Cells[itemkey].Value = valueL.Sum().ToString();
- else if (itemValue[0] == 2)//平均
- dgvr.Cells[itemkey].Value = valueL.Average().ToString();
- else if (itemValue[0] == 3)//级别
- if (itemValue[1] < 0)
- {
- dgvr.Cells[itemkey].Value = getGradeTotalCal(dgvr, Convert.ToInt32(this.numericUpDown1_0.Value));//############
- }
- else
- dgvr.Cells[itemkey].Value = getGradeValue(double.Parse(dgvr.Cells[itemValue[1]].Value.ToString()));
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- this.RefreshDataGridView4();
- return;
- }
- double grainNumber = 0;
- if (getGbtType() == 3)
- value_1 = 0;
- for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
- {
- System.Data.DataTable dataTable1 = new System.Data.DataTable();
- foreach (var dataTable in this.dataTable_Totals)
- {
- if (this.listView2.SelectedItems.Count > 0)
- {
- if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
- dataTable1 = dataTable;
- }
- else
- {
- if (this.listView2.Items[0].Tag.Equals(dataTable.TableName))
- dataTable1 = dataTable;
- }
- }
- grainNumber += double.Parse(dataTable1.Rows[0][grainMethodType == 1 ? 0 : 1].ToString());
- if (this.dict_Totals.ContainsKey(this.listView2.SelectedItems[i].Tag.ToString()))
- {
- Dictionary<string, object> valuePairs = this.dict_Totals[this.listView2.SelectedItems[i].Tag.ToString()];
- if (valuePairs.ContainsKey("RectArea"))
- value_1 += (double)valuePairs["RectArea"];
- }
- }
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- dgvr.Cells[0].Value = (grainMethodType == 1 ? grainNumber : small_l).ToString();
- if (getGbtType() == 3)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- value_1 = value_1 * 0.001 * 0.001;
- dgvr.Cells[1].Value = (3.321928 * Math.Log10(1.0 / value_1) - 2.954).ToString();
- }
- else
- {
- dgvr.Cells[1].Value = (grainMethodType == 1 ? small_l : value_1).ToString();
- if (grainMethodType == 1 && grainNumber > 0)
- small_l = small_l / grainNumber;
- else if (grainMethodType == 0 && value_1 > 0)
- small_l = small_l / value_1;
- dgvr.Cells[2].Value = small_l.ToString();
- if (getGbtType() == 4)
- dgvr.Cells[3].Value = (-6.6439 * Math.Log10(small_l * 0.001) - 3.2877).ToString();
- else
- dgvr.Cells[3].Value = (-6.643856 * Math.Log10(small_l * 0.001) - 3.288).ToString();
- if (grainMethodType == 1)
- {
- if (dgvr.Cells.Count > 4)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- dgvr.Cells[4].Value = value_1.ToString();
- value_1 = value_1 * 0.001 * 0.001;
- }
- if (dgvr.Cells.Count > 5)
- {
- if (getGbtType() == 4)
- dgvr.Cells[5].Value = (3.32 * Math.Log10(1.0 / value_1) - 2.9542).ToString();
- else
- dgvr.Cells[5].Value = (3.321928 * Math.Log10(1.0 / value_1) - 2.954).ToString();
- }
- }
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- }
- //##
- this.RefreshDataGridView4();
- }
- /// <summary>
- /// 切换分析结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void listview2_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (!this.allShow)
- {
- if (this.listView2.SelectedItems.Count <= 0)
- return;
- List<List<double>> valueList = new List<List<double>>();
- double value_1 = 0;
- double small_l = 0;
- this.dataGridView2.Rows.Clear();
- for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
- {
- System.Data.DataTable dataTable1 = new System.Data.DataTable();
- foreach (var dataTable in this.dataTables)
- {
- if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
- {
- dataTable1 = dataTable;
- for (int rIndex = 0; rIndex < dataTable1.Rows.Count; rIndex++)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- List<double> valueL = new List<double>();
- for (int c = 0; c < dataTable1.Columns.Count; c++)
- {
- dgvr.Cells[c].Value = dataTable1.Rows[rIndex][c].ToString();
- if (IndexChangedFromIndex.Count > 0)
- {
- if (IndexChangedFromIndex.Contains(c))
- valueL.Add(double.Parse(dataTable1.Rows[rIndex][c].ToString()));
- continue;
- }
- if (c == 3)
- value_1 += double.Parse(dataTable1.Rows[rIndex][c].ToString());
- if (grainMethodType == 1 && c == 4 || grainMethodType == 0 && c == 2)
- small_l += double.Parse(dataTable1.Rows[rIndex][c].ToString());
- }
- if (IndexChangedFromIndex.Count > 0)
- valueList.Add(valueL);
- this.dataGridView2.Rows.Add(dgvr);
- }
- }
- }
- }
- this.dataGridView_Total.Rows.Clear();
- if (IndexChangedFromIndex.Count > 0 && IndexChangedToIndex.Count > 0 && valueList.Count > 0)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- foreach (int itemkey in IndexChangedToIndex.Keys)
- {
- int[] itemValue = IndexChangedToIndex[itemkey];
- List<double> valueL = new List<double>();//级别时会多算一遍,应该不影响什么
- if (itemValue[1] >= 0)
- foreach (List<double> itemL in valueList)
- {
- valueL.Add(itemL[itemValue[1]]);
- }
- if (itemValue[0] == 1)//求和
- dgvr.Cells[itemkey].Value = valueL.Sum().ToString();
- else if (itemValue[0] == 2)//平均
- dgvr.Cells[itemkey].Value = valueL.Average().ToString();
- else if (itemValue[0] == 3)//级别
- if (itemValue[1] < 0)
- {
- dgvr.Cells[itemkey].Value = getGradeTotalCal(dgvr, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- else
- dgvr.Cells[itemkey].Value = getGradeValue(double.Parse(dgvr.Cells[itemValue[1]].Value.ToString()));
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- this.RefreshDataGridView4();
- return;
- }
- double grainNumber = 0;
- if (getGbtType() == 3)
- value_1 = 0;
- for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
- {
- System.Data.DataTable dataTable1 = new System.Data.DataTable();
- foreach (var dataTable in this.dataTable_Totals)
- {
- if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
- dataTable1 = dataTable;
- }
- if (this.dict_Totals.ContainsKey(this.listView2.SelectedItems[i].Tag.ToString()))
- {
- Dictionary<string, object> valuePairs = this.dict_Totals[this.listView2.SelectedItems[i].Tag.ToString()];
- if (valuePairs.ContainsKey("RectArea"))
- value_1 += (double)valuePairs["RectArea"];
- }
- grainNumber += double.Parse(dataTable1.Rows[0][grainMethodType == 1 ? 0 : 1].ToString());//###21939
- }
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- dgvr.Cells[0].Value = (grainMethodType == 1 ? grainNumber : small_l).ToString();
- if (getGbtType() == 3)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- value_1 = value_1 * 0.001 * 0.001;
- dgvr.Cells[1].Value = (3.321928 * Math.Log10(1.0 / value_1) - 2.954).ToString();
- }
- else
- {
- dgvr.Cells[1].Value = (grainMethodType == 1 ? small_l : value_1).ToString();
- if (grainMethodType == 1 && grainNumber > 0)
- small_l = small_l / grainNumber;
- else if (grainMethodType == 0 && value_1 > 0)
- small_l = small_l / value_1;
- dgvr.Cells[2].Value = small_l.ToString();
- if (getGbtType() == 4)
- dgvr.Cells[3].Value = (-6.6439 * Math.Log10(small_l * 0.001) - 3.2877).ToString();
- else
- dgvr.Cells[3].Value = (-6.643856 * Math.Log10(small_l * 0.001) - 3.288).ToString();
- if (grainMethodType == 1)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- if (dgvr.Cells.Count > 4)
- {
- dgvr.Cells[4].Value = value_1.ToString();
- value_1 = value_1 * 0.001 * 0.001;
- }
- if (dgvr.Cells.Count > 5)
- {
- if (getGbtType() == 4)
- dgvr.Cells[5].Value = (3.32 * Math.Log10(1.0 / value_1) - 2.9542).ToString();
- else
- dgvr.Cells[5].Value = (3.321928 * Math.Log10(1.0 / value_1) - 2.954).ToString();
- }
- }
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- }
- //##
- this.RefreshDataGridView4();
- }
- }
- /// <summary>
- /// 全部显示
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button11_Click(object sender, EventArgs e)
- {
- if (this.listView2.Items.Count > 0)
- {
- this.button11.Visible = false;
- this.button16.Visible = true;
- this.button16.Focus();
- this.allShow = true;
- List<List<double>> valueList = new List<List<double>>();
- double value_1 = 0;
- double small_l = 0;
- this.dataGridView2.Rows.Clear();
- for (int i = 0; i < this.dataTables.Count; i++)
- {
- for (int rIndex = 0; rIndex < this.dataTables[i].Rows.Count; rIndex++)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- List<double> valueL = new List<double>();
- for (int c = 0; c < this.dataTables[i].Columns.Count; c++)
- {
- dgvr.Cells[c].Value = this.dataTables[i].Rows[rIndex][c].ToString();
- if (IndexChangedFromIndex.Count > 0)
- {
- if (IndexChangedFromIndex.Contains(c))
- valueL.Add(double.Parse(this.dataTables[i].Rows[rIndex][c].ToString()));
- continue;
- }
- if (c == 3)
- value_1 += double.Parse(this.dataTables[i].Rows[rIndex][c].ToString());
- if (grainMethodType == 1 && c == 4 || grainMethodType == 0 && c == 2)
- small_l += double.Parse(this.dataTables[i].Rows[rIndex][c].ToString());
- }
- if (IndexChangedFromIndex.Count > 0)
- valueList.Add(valueL);
- this.dataGridView2.Rows.Add(dgvr);
- }
- }
- this.dataGridView_Total.Rows.Clear();
- if (IndexChangedFromIndex.Count > 0 && IndexChangedToIndex.Count > 0 && valueList.Count > 0)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- foreach (int itemkey in IndexChangedToIndex.Keys)
- {
- int[] itemValue = IndexChangedToIndex[itemkey];
- List<double> valueL = new List<double>();//级别时会多算一遍,应该不影响什么
- if (itemValue[1] >= 0)
- foreach (List<double> itemL in valueList)
- {
- valueL.Add(itemL[itemValue[1]]);
- }
- if (itemValue[0] == 1)//求和
- dgvr.Cells[itemkey].Value = valueL.Sum().ToString();
- else if (itemValue[0] == 2)//平均
- dgvr.Cells[itemkey].Value = valueL.Average().ToString();
- else if (itemValue[0] == 3)//级别
- if (itemValue[1] < 0)
- {
- dgvr.Cells[itemkey].Value = getGradeTotalCal(dgvr, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- else
- dgvr.Cells[itemkey].Value = getGradeValue(double.Parse(dgvr.Cells[itemValue[1]].Value.ToString()));
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- this.RefreshDataGridView4();
- return;
- }
- double grainNumber = 0;
- for (int i = 0; i < this.dataTable_Totals.Count; i++)
- {
- grainNumber += double.Parse(this.dataTable_Totals[i].Rows[0][grainMethodType == 1 ? 0 : 1].ToString());
- }
- if (getGbtType() == 3)
- value_1 = 0;
- for (int j = 0; j < this.listView2.Items.Count; j++)
- {
- if (this.dict_Totals.ContainsKey(this.listView2.Items[j].Tag.ToString()))
- {
- Dictionary<string, object> valuePairs = this.dict_Totals[this.listView2.Items[j].Tag.ToString()];
- if (valuePairs.ContainsKey("RectArea"))
- value_1 += (double)valuePairs["RectArea"];
- }
- }
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- dgvr.Cells[0].Value = (grainMethodType == 1 ? grainNumber : small_l).ToString();
- if (getGbtType() == 3)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- value_1 = value_1 * 0.001 * 0.001;
- dgvr.Cells[1].Value = (3.321928 * Math.Log10(1.0 / value_1) - 2.954).ToString();
- }
- else
- {
- dgvr.Cells[1].Value = (grainMethodType == 1 ? small_l : value_1).ToString();
- if (grainMethodType == 1 && grainNumber > 0)
- small_l = small_l / grainNumber;
- else if (grainMethodType == 0 && value_1 > 0)
- small_l = small_l / value_1;
- dgvr.Cells[2].Value = small_l.ToString();
- if (getGbtType() == 4)
- dgvr.Cells[3].Value = (-6.6439 * Math.Log10(small_l * 0.001) - 3.2877).ToString();
- else
- dgvr.Cells[3].Value = (-6.643856 * Math.Log10(small_l * 0.001) - 3.288).ToString();
- if (grainMethodType == 1)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- if (dgvr.Cells.Count >= 5)
- {
- dgvr.Cells[4].Value = value_1.ToString();
- value_1 = value_1 * 0.001 * 0.001;
- }
- if (dgvr.Cells.Count >= 6)
- {
- if (getGbtType() == 4)
- dgvr.Cells[5].Value = (3.32 * Math.Log10(1.0 / value_1) - 2.9542).ToString();
- else
- dgvr.Cells[5].Value = (3.321928 * Math.Log10(1.0 / value_1) - 2.954).ToString();
- }
- }
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- }
- this.RefreshDataGridView4();
- }
- else
- {
- MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
- }
- }
- /// <summary>
- /// 分析结果删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button12_Click(object sender, EventArgs e)
- {
- if (this.listView2.Items.Count > 0)
- {
- if (this.listView2.SelectedItems.Count > 0)
- {
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (dr == DialogResult.OK)
- {
- if (this.listView2.SelectedItems.Count <= 0)
- return;
- for (int i = this.listView2.SelectedItems.Count - 1; i >= 0; i--)
- {
- int selectIndex = this.listView2.SelectedItems[i].Index;
- foreach (var dataTable in this.dataTable_Totals)
- {
- if (dataTable.TableName.Equals(this.listView2.SelectedItems[i].Tag))
- {
- this.dataTable_Totals.Remove(dataTable);
- break;
- }
- }
- if (this.dict_Totals.ContainsKey(this.listView2.SelectedItems[i].Tag.ToString()))
- this.dict_Totals.Remove(this.listView2.SelectedItems[i].Tag.ToString());
- for (int dataTableI = dataTables.Count - 1; dataTableI >= 0; dataTableI--)
- {
- System.Data.DataTable dataTable1 = dataTables[dataTableI];
- if (dataTable1.TableName.Equals(this.listView2.SelectedItems[i].Tag/*tag*/))
- dataTables.RemoveAt(dataTableI);
- }
- if (bitDic.ContainsKey((string)this.listView2.SelectedItems[i].Tag))
- bitDic.Remove((string)this.listView2.SelectedItems[i].Tag);
- foreach (ExportProjectModel model in this.tempDataModel)
- {
- if (model.tagName.Equals((string)this.listView2.SelectedItems[i].Tag))
- {
- this.tempDataModel.Remove(model);
- break;
- }
- }
- this.listView2.Items.RemoveAt(selectIndex);
- }
- if (this.listView2.Items.Count == 0)
- {
- this.dataGridView_Total.Rows.Clear();
- this.dataGridView2.Rows.Clear();
- this.threeDButton.Enabled = false;
- }
- else
- RefreshDataGridView4();
- }
- }
- else
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthedatatobedeleted.text")+"!");
- }
- }
- else
- {
- MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
- }
- }
- /// <summary>
- /// 小数位数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numericUpDown1_0_ValueChanged(object sender, EventArgs e)
- {
- this.RefreshDataGridView4();
- this.RefreshWhileUpDown1_0ValueChanged();
- }
- /// <summary>
- /// 生成报告
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_generateReport_Click(object sender, EventArgs e)
- {
- if (this.listView2.Items.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Noresults.text"));
- return;
- }
- if (this.checkBox_generateReport_opensetting.Checked)
- this.button_setting.PerformClick();
- if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
- {
- //获取word书签与excel单元格的关系,以字典方式存储
- List<mic_module_infos> mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
- Dictionary<string, string> tagInfos = new Dictionary<string, string>();
- if (mic_module_infos != null && mic_module_infos.Count > 0)
- {
- foreach (mic_module_infos info in mic_module_infos)
- {
- tagInfos.Add(info.tag_name, info.cell_position);
- }
- }
- // 中间数据
- List<ExportProjectModel> exportModel = new List<ExportProjectModel>();
- if (this.allShow)
- {
- //中间数据
- foreach (ExportProjectModel model in this.tempDataModel)
- {
- ExportProjectModel tempModel = new ExportProjectModel();
- tempModel.tagName = model.tagName;
- tempModel.picName = model.picName;
- tempModel.dataList = model.dataList;
- exportModel.Add(tempModel);
- }
- }
- else
- {
- if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
- {
- //中间数据
- foreach (ListViewItem rowItem in this.listView2.SelectedItems)
- {
- foreach (ExportProjectModel model in this.tempDataModel)
- {
- if (model.tagName.Equals(rowItem.Name))
- {
- ExportProjectModel tempModel = new ExportProjectModel();
- tempModel.tagName = model.tagName;
- tempModel.picName = model.picName;
- tempModel.dataList = model.dataList;
- exportModel.Add(tempModel);
- break;
- }
- else if (model.tagName.Equals(rowItem.Tag.ToString()))
- {
- ExportProjectModel tempModel = new ExportProjectModel();
- tempModel.tagName = model.tagName;
- tempModel.picName = model.picName;
- tempModel.dataList = model.dataList;
- exportModel.Add(tempModel);
- break;
- }
- }
- }
- }
- else if (this.listView2.Items.Count > 0)
- {
- ListViewItem rowItem = this.listView2.Items[0];
- //中间数据
- foreach (ExportProjectModel model in this.tempDataModel)
- {
- if (model.tagName.Equals(rowItem.Name))
- {
- ExportProjectModel tempModel = new ExportProjectModel();
- tempModel.tagName = model.tagName;
- tempModel.picName = model.picName;
- tempModel.dataList = model.dataList;
- exportModel.Add(tempModel);
- break;
- }
- else if (model.tagName.Equals(rowItem.Tag.ToString()))
- {
- ExportProjectModel tempModel = new ExportProjectModel();
- tempModel.tagName = model.tagName;
- tempModel.picName = model.picName;
- tempModel.dataList = model.dataList;
- exportModel.Add(tempModel);
- break;
- }
- }
- }
- }
- int exportModelIndex = 0;
- //详细数据
- List<List<string>> analysisContent2;
- if (grainMethodType == 1 || tempDataModel == null || tempDataModel.Count == 0)
- analysisContent2 = null;
- else
- {
- analysisContent2 = new List<List<string>>();
- List<string> columnName2 = new List<string>();
- columnName2.Add(PdnResources.GetString("Menu.picture.Text"));
- columnName2.AddRange(exportModel[0].dataList[0]);
- analysisContent2.Add(columnName2);
- foreach (var tempData in exportModel)
- {
- List<List<string>> dataList = tempData.dataList;
- for (int k = 1; k < dataList.Count; k++)
- {
- List<string> strList = new List<string>();
- strList.Add(tempData.picName);
- strList.AddRange(dataList[k]);
- strList[1] = (++exportModelIndex).ToString();
- analysisContent2.Add(strList);
- }
- }
- }
- //分析结果
- List<List<string>> analysisContent = new List<List<string>>();
- List<string> contentHeaderText2 = new List<string>();
- foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
- {
- contentHeaderText2.Add(c.HeaderText);
- }
- analysisContent.Add(contentHeaderText2);
- foreach (DataGridViewRow item in this.dataGridView_Total.Rows)//##########################
- {
- List<string> content = new List<string>();
- for (int i = 0; i < contentHeaderText2.Count; i++)
- {
- content.Add(item.Cells[i].Value.ToString());
- }
- analysisContent.Add(content);
- }
- List<string> contentHeaderText = new List<string>();
- foreach (DataGridViewColumn c in this.dataGridView2.Columns)
- {
- contentHeaderText.Add(c.HeaderText);
- }
- analysisContent.Add(contentHeaderText);
- foreach (DataGridViewRow item in this.dataGridView2.Rows)//##########################
- {
- List<string> content = new List<string>();
- for (int i = 0; i < contentHeaderText.Count; i++)
- {
- content.Add(item.Cells[i].Value.ToString());
- }
- analysisContent.Add(content);
- }
- //图片
- bitList = new List<Bitmap>();
- List<string> pNamesList = new List<string>();
- if (this.allShow)
- {
- foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitDic)
- {
- int cal_Index = int.Parse(kv.Key.Replace("img", ""));
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- pNamesList.Add(imgName);
- bitList.Add(kv.Value[0]);
- bitList.Add(kv.Value[1]);
- }
- }
- else
- {
- if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
- {
- foreach (ListViewItem item in this.listView2.SelectedItems)
- {
- if (bitDic.ContainsKey(item.Name))
- {
- int cal_Index = int.Parse(item.Name.Replace("img", ""));
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- pNamesList.Add(imgName);
- bitList.Add(bitDic[item.Name][0]);
- bitList.Add(bitDic[item.Name][1]);
- }
- else if (bitDic.ContainsKey(item.Tag.ToString()))
- {
- int cal_Index = int.Parse(item.Tag.ToString().Replace("img", ""));
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- pNamesList.Add(imgName);
- bitList.Add(bitDic[item.Tag.ToString()][0]);
- bitList.Add(bitDic[item.Tag.ToString()][1]);
- }
- }
- }
- else if (this.listView2.Items.Count > 0)
- {
- ListViewItem item = this.listView2.Items[0];
- if (bitDic.ContainsKey(item.Name))
- {
- int cal_Index = int.Parse(item.Name.Replace("img", ""));
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- pNamesList.Add(imgName);
- bitList.Add(bitDic[item.Name][0]);
- bitList.Add(bitDic[item.Name][1]);
- }
- else if (bitDic.ContainsKey(item.Tag.ToString()))
- {
- int cal_Index = int.Parse(item.Tag.ToString().Replace("img", ""));
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- pNamesList.Add(imgName);
- bitList.Add(bitDic[item.Tag.ToString()][0]);
- bitList.Add(bitDic[item.Tag.ToString()][1]);
- }
- }
- }
- string dictPath = Application.StartupPath + "\\temp";
- if (!System.IO.Directory.Exists(dictPath))
- {
- System.IO.Directory.CreateDirectory(dictPath);
- }
- DeleteFolder(dictPath);
- pNames = new Dictionary<string, string>();
- int insertIn = 0;
- for (int k = 0; k < bitList.Count; k += 2)
- {//保存处理后的图片
- List<Bitmap> tempBit = new List<Bitmap>();
- tempBit.Add((Bitmap)bitList[k].Clone());
- tempBit.Add((Bitmap)bitList[k + 1].Clone());
- this.SaveAllImage(tempBit, dictPath, insertIn + 1, insertIn + 1, pNamesList[insertIn]);
- insertIn++;
- }
- this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos, dictPath, pNames, analysisContent2);
- }
- else
- MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
- }
- /// <summary>
- /// 切换辅助线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- comboBox1SelectedItem = comboBox1.SelectedItem;
- if (GSSClass.GuideClass.guideModel != null)
- GSSClass.GuideClass.guideModel.oldSelectItem = (string)this.comboBox1.SelectedItem;
- if (this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0)
- {
- if (this.bitmap == null)
- {
- int oldSelectIndex = -1;
- for (int i = 0; i < this.comboBox1.Items.Count; i++)
- {
- if (GSSClass.GuideClass.guideModel.oldSelectItem != null && GSSClass.GuideClass.guideModel.oldSelectItem.Equals(this.comboBox1.Items[i]))
- {
- oldSelectIndex = i;
- }
- }
- if (this.comboBox1.SelectedIndex > 0)
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
- if (oldSelectIndex > -1)
- {
- if (this.comboBox1.SelectedIndex != oldSelectIndex)
- this.comboBox1.SelectedIndex = oldSelectIndex;
- }
- else if (this.comboBox1.Items.Count > 0)
- this.comboBox1.SelectedIndex = 0;
- return;
- }
- UpdateGuideStyle(true && !(this.initScriptValues && this.appWorkspace.ScriptAutomatic));
- if (this.bitmap != null)
- {
- if (this.comboboxChange)
- {
- GSSClass.GuideClass.guideModel.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
- }
- InitRectangleF(true);
- this.comboboxChange = true;
- }
- this.documentWorkspace.Refresh();
- }
- }
- /// <summary>
- /// 辅助线设置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button9_Click(object sender, EventArgs e)
- {
- if (this.bitmap == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
- return;
- }
- GSSClass.GuideClass.guideModel.oldSelectItem = (string)this.comboBox1.SelectedItem;
- GrainGuideSettingsDialog grainGuideStyleSettingsDialog = new GrainGuideSettingsDialog(grainMethodType == 1 ? 1 : 0, GSSClass.methodOfAssessment != null ? GSSClass.methodOfAssessment.guideXmlName : getModelName(), getTypeNames(), this.bitmap, this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index
- ].GetRuler(MeasurementUnit.Micron));
- grainGuideStyleSettingsDialog.StartPosition = FormStartPosition.CenterScreen;
- grainGuideStyleSettingsDialog.ShowDialog(this);
- }
- /// <summary>
- /// 返回小数点位数的数值
- /// </summary>
- /// <returns></returns>
- protected int getNumericUpDown1Value()
- {
- return Convert.ToInt32(this.numericUpDown1_0.Value);
- }
- /// <summary>
- /// 刷新晶粒编号/刷新晶粒颜色?//############
- /// </summary>
- /// <param name="pointFs"></param>
- /// <param name="rectangleF"></param>
- /// <returns>返回晶粒个数</returns>
- protected virtual double GetClassNumberOfGrains()
- {
- return 0.0;
- }
- /// <summary>
- /// 颜色点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void panel1_1_Click(object sender, EventArgs e)
- {
- this.panelC = (Panel)sender;
- this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor);
- this.colorsFormGrid.ShowDialog();
- }
- /// <summary>
- /// PanelC的调色板颜色改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gridColorChanged(object sender, EventArgs e)
- {
- Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
- //更改背景色,触发事件
- if (this.panelC != null)
- {
- this.panelC.BackColor = color;
- this.ColorPanelChanged(this.panelC);
- this.panelC = null;
- }
- //关闭色板
- this.colorsFormGrid.Close();
- }
- #region 公共按钮
- private void zoomInButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomIn();
- }
- private void zoomOutButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomOut();
- }
- private void zoomToWindowButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- }
- private void actualSizeButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
- }
- private void pointerButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;
- }
- private void mobileModeButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
- }
- #endregion
- #region 辅助线拖动
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="drawArea"></param>
- /// <param name="e"></param>
- protected virtual void OnMouseDown(object sender, MouseEventArgs e)
- {
- if (grainMethodType == 1)
- {
- if (this.documentWorkspace.CompositionSurface == null)
- return;
- // 换算后的点
- PointF pointArea = documentWorkspace.GetScalePoint(e.Location);
- //辅助线缩放
- GSSClass.GuideClass.OnMouseDown(pointArea, sender, e);
- //辅助线移动
- if (e.Button == MouseButtons.Left && e.Clicks == 1)
- {
- if (GSSClass.GuideClass.guideModel.RectangleFLine.Contains(pointArea))
- {
- GSSClass.GuideClass.m_canMove = true;
- GSSClass.GuideClass.m_StartPoint = pointArea;
- }
- }
- return;
- }
- // 换算后的点
- PointF point1 = documentWorkspace.GetScalePoint(e.Location);
- if (e.Button == MouseButtons.Left && e.Clicks == 1)
- {
- if (GSSClass.GuideClass.guideModel.RectangleFLine.Contains(point1))
- {
- GSSClass.GuideClass.m_canMove = true;
- GSSClass.GuideClass.m_StartPoint = point1;
- }
- }
- }
- /// <summary>
- /// 移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void onMouseMove(object sender, MouseEventArgs e)
- {
- this.documentWorkspace.Refresh();
- // 换算后的点
- PointF point1 = documentWorkspace.GetScalePoint(e.Location);
- //晶粒度不想让辅助线拖到图像外面
- if (grainMethodType == 0 && this.documentWorkspace.CompositionSurface != null && GSSClass.GuideClass.onMouseMove(point1, this.comboBox1.SelectedItem, e, this.documentWorkspace.CompositionSurface.Width, this.documentWorkspace.CompositionSurface.Height, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron))
- || grainMethodType == 1 && this.documentWorkspace.CompositionSurface != null && GSSClass.GuideClass.onMouseAreaMove(point1, this.comboBox1.SelectedItem, e, this.documentWorkspace.CompositionSurface.Width, this.documentWorkspace.CompositionSurface.Height, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron)))// 矩形缩放
- {//缩放
- GSSClass.GuideClass.guideModel.loctation = new PointF(GSSClass.GuideClass.guideModel.RectangleFLine.X + GSSClass.GuideClass.guideModel.RectangleFLine.Width / 2, GSSClass.GuideClass.guideModel.RectangleFLine.Y + GSSClass.GuideClass.guideModel.RectangleFLine.Height / 2);
- this.AddRectangleToRectangleFCaps();
- this.documentWorkspace.Refresh();
- }
- else if (e.Button == MouseButtons.Left && GSSClass.GuideClass.m_canMove)
- {//移动
- //限制辅助线移动不能拖到图像外面
- PointF m222_StartPoint = new PointF(point1.X, point1.Y);
- double minX = GSSClass.GuideClass.m_StartPoint.X - GSSClass.GuideClass.guideModel.rectangleFLine.X;
- if (point1.X < minX)
- point1.X = (float)minX;
- double maxX = GSSClass.GuideClass.m_StartPoint.X + this.documentWorkspace.CompositionSurface.Width - GSSClass.GuideClass.guideModel.RectangleFLine.Right;
- if (point1.X > maxX)
- point1.X = (float)maxX;
- double minY = GSSClass.GuideClass.m_StartPoint.Y - GSSClass.GuideClass.guideModel.rectangleFLine.Y;
- if (point1.Y < minY)
- point1.Y = (float)minY;
- double maxY = GSSClass.GuideClass.m_StartPoint.Y + this.documentWorkspace.CompositionSurface.Height - GSSClass.GuideClass.guideModel.RectangleFLine.Bottom;
- if (point1.Y > maxY)
- point1.Y = (float)maxY;
- float offsetX = point1.X - GSSClass.GuideClass.m_StartPoint.X;
- float offsetY = point1.Y - GSSClass.GuideClass.m_StartPoint.Y;
- // 矩形偏移
- GSSClass.GuideClass.guideModel.rectangleFLine.Offset(offsetX, offsetY);
- GSSClass.GuideClass.guideModel.loctation = new PointF(GSSClass.GuideClass.guideModel.RectangleFLine.X + GSSClass.GuideClass.guideModel.RectangleFLine.Width / 2, GSSClass.GuideClass.guideModel.RectangleFLine.Y + GSSClass.GuideClass.guideModel.RectangleFLine.Height / 2);
- GSSClass.GuideClass.m_StartPoint = m222_StartPoint;
- if (grainMethodType == 0 && !(!getGrainBoundryChecked() && !getBinaryChecked()))
- //##21247
- this.AddRectangleToRectangleFCaps();
- else if (grainMethodType == 0)
- {
- //##21247
- this.MoveOriginCutOffPoints(offsetX, offsetY);
- }
- this.documentWorkspace.Refresh();
- }
- }
- /// <summary>
- /// 鼠标抬起
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void onMouseUp(object sender, MouseEventArgs e)
- {
- GSSClass.GuideClass.m_canMove = false;
- GSSClass.GuideClass.onMouseUp(sender, e);
- }
- #endregion
- #endregion
- #region 可调用方法
- /// <summary>
- /// 是否显示原图
- /// </summary>
- /// <returns></returns>
- protected Boolean showOrimat()
- {
- return bcOriginChecked();
- }
- /// <summary>
- /// 获取小数点保留位数的显示字符串
- /// </summary>
- /// <param name="doubleValue"></param>
- /// <returns></returns>
- protected string DecnumString(string doubleValue)
- {
- double outValue;
- if (double.TryParse(string.IsNullOrEmpty(doubleValue) ? "0" : doubleValue, out outValue))
- {
- return Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
- }
- else
- return doubleValue;
- }
- /// <summary>
- /// 设置晶粒颜色
- /// </summary>
- protected void ShowGrainColorSettingDialog()
- {
- GrainColorSetting colorSettings = new GrainColorSetting(/*isAreaType ? 1 : 0, getModelName(), getTypeNames(), this.bitmap*/);
- colorSettings.StartPosition = FormStartPosition.CenterScreen;
- //colorSettings.ShowDialog(this)
- if (colorSettings.ShowDialog() == DialogResult.OK)
- {
- //获取设置颜色的集合,按照等级从小到大排序
- List<OpenCvSharp.Vec4b> colorOfGrades = colorSettings.getColorOfGrades();
- GSSClass.setColorOfGrades.Clear();
- GSSClass.setColorOfGrades.AddRange(colorOfGrades);
- setMat2ColorOfLabelMat(-1);
- };
- }
- /// <summary>
- /// 设置截点样式
- /// </summary>
- protected void ShowGrainSurveyPointStyleSettingDialog()
- {
- GrainSurveyPointStyleSettingDialog grainSurveyPointStyleSettingDialog = new GrainSurveyPointStyleSettingDialog();//###
- grainSurveyPointStyleSettingDialog.StartPosition = FormStartPosition.CenterScreen;
- grainSurveyPointStyleSettingDialog.ShowDialog(this);
- }
- /// <summary>
- /// 根据等级设置晶粒颜色
- /// </summary>
- /// <param name="nccomps">连通域数量</param>
- private void setMat2ColorOfLabelMat(int nccomps)
- {
- Mat temp = GSSClass.getMat2ColorOfLabelMat(GSSClass.standardModel, nccomps, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron));
- if (temp != null)
- {
- if (grainMethodType == 1)
- {
- if (this.grainColorsMatDict.ContainsKey(getCurrentWorkTag()))
- this.grainColorsMatDict[getCurrentWorkTag()] = temp.Clone();
- else
- this.grainColorsMatDict.Add(getCurrentWorkTag(), temp.Clone());
- }
- this.documentWorkspace.PhaseModels[2].mat = temp;
- this.documentWorkspace.Refresh();
- }
- }
- /// <summary>
- /// 更新截点样式
- /// </summary>
- public void UpdateCupOffPointStyle()
- {
- GSSClass.styleClass.styleModel.UpdateCupOffPointStyle();
- AddRectangleToRectangleFCaps();
- }
- /// <summary>
- /// 刷新分析结果数据
- /// </summary>
- protected virtual void RefreshDataGridView4()
- {
- if (!this.allShow)
- {
- if (this.listView2.SelectedItems.Count > 0)
- {
- List<List<double>> valueList = new List<List<double>>();
- double value_1 = 0;//面积法(汇总面积)、截点法(截点总数)
- double small_l = 0;//面积法(汇总截距)、截点法(网格总长度)
- this.dataGridView2.Rows.Clear();
- for (int j = 0; j < this.listView2.SelectedItems.Count; j++)
- {
- for (int dataTableIndex = 0; dataTableIndex < this.dataTables.Count; dataTableIndex++)
- {
- if (this.dataTables[dataTableIndex].TableName.Equals(this.listView2.SelectedItems[j].Tag))
- {
- for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- List<double> valueL = new List<double>();
- for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++)
- {
- double outValue;
- if (double.TryParse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
- this.dataTables[dataTableIndex].Rows[r][c].ToString(), out outValue) && !DetailListStringIndex.Contains(c))
- {
- dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
- }
- else
- dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
- if (IndexChangedFromIndex.Count > 0)
- {
- if (IndexChangedFromIndex.Contains(c))
- valueL.Add(double.Parse(this.dataTables[dataTableIndex].Rows[r][c].ToString()));
- continue;
- }
- if (c == 3/*isAreaType && c == 3 || !isAreaType && c == 3*/)
- value_1 += outValue;
- if (grainMethodType == 1 && c == 4 || grainMethodType == 0 && c == 2)
- small_l += outValue;
- }
- if (IndexChangedFromIndex.Count > 0)
- valueList.Add(valueL);
- this.dataGridView2.Rows.Add(dgvr);
- }
- }
- }
- }
- this.dataGridView_Total.Rows.Clear();
- value_111 = -1;
- if (IndexChangedFromIndex.Count > 0 && IndexChangedToIndex.Count > 0 && valueList.Count > 0)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- foreach (int itemkey in IndexChangedToIndex.Keys)
- {
- int[] itemValue = IndexChangedToIndex[itemkey];
- List<double> valueL = new List<double>();//级别时会多算一遍,应该不影响什么
- if (itemValue[1] >= 0)
- foreach (List<double> itemL in valueList)
- {
- valueL.Add(itemL[itemValue[1]]);
- }
- if (itemValue[0] == 1)//求和
- dgvr.Cells[itemkey].Value = "" + Math.Round(valueL.Sum(), Convert.ToInt32(this.numericUpDown1_0.Value));
- else if (itemValue[0] == 2)//平均
- dgvr.Cells[itemkey].Value = "" + Math.Round(valueL.Average(), Convert.ToInt32(this.numericUpDown1_0.Value));
- else if (itemValue[0] == 3)//级别
- if (itemValue[1] < 0)
- {
- dgvr.Cells[itemkey].Value = getGradeTotalCal(dgvr, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- else
- dgvr.Cells[itemkey].Value = getGradeValue(double.Parse(dgvr.Cells[itemValue[1]].Value.ToString()));
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- return;
- }
- double grainNumber = 0;
- if (getGbtType() == 3)
- value_1 = 0;
- for (int j = 0; j < this.listView2.SelectedItems.Count; j++)
- {
- int dataTableIndex = 0;
- for (int i = 0; i < this.dataTable_Totals.Count; i++)
- {
- if (this.dataTable_Totals[i].TableName.Equals(this.listView2.SelectedItems[j].Tag))
- dataTableIndex = i;
- }
- if (this.dataTable_Totals.Count > dataTableIndex && this.dataTable_Totals[dataTableIndex].Rows.Count > 0)
- {
- for (int r = 0; r < this.dataTable_Totals[dataTableIndex].Rows.Count; r++)
- {
- grainNumber += double.Parse(this.dataTable_Totals[dataTableIndex].Rows[r][grainMethodType == 1 ? 0 : 1].ToString());
- }
- }
- if (this.dict_Totals.ContainsKey(this.listView2.SelectedItems[j].Tag.ToString()))
- {
- Dictionary<string, object> valuePairs = this.dict_Totals[this.listView2.SelectedItems[j].Tag.ToString()];
- if (valuePairs.ContainsKey("RectArea"))
- value_1 += (double)valuePairs["RectArea"];
- }
- }
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- dgvr.Cells[0].Value = "" + Math.Round(grainMethodType == 1 ? grainNumber : small_l, Convert.ToInt32(this.numericUpDown1_0.Value));
- if (getGbtType() == 3)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- value_1 = value_1 * 0.001 * 0.001;
- dgvr.Cells[1].Value = "" + Math.Round(3.321928 * Math.Log10(1.0 / value_1) - 2.954, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- else
- {
- dgvr.Cells[1].Value = "" + Math.Round(grainMethodType == 1 ? small_l : value_1, Convert.ToInt32(this.numericUpDown1_0.Value));
- if (grainMethodType == 1 && grainNumber > 0)
- small_l = small_l / grainNumber;
- else if (grainMethodType == 0 && value_1 > 0)
- small_l = small_l / value_1;
- dgvr.Cells[2].Value = "" + Math.Round(small_l, Convert.ToInt32(this.numericUpDown1_0.Value));
- if (getGbtType() == 4)
- dgvr.Cells[3].Value = "" + Math.Round(-6.6439 * Math.Log10(small_l * 0.001) - 3.2877, Convert.ToInt32(this.numericUpDown1_0.Value));
- else
- dgvr.Cells[3].Value = "" + Math.Round(-6.643856 * Math.Log10(small_l * 0.001) - 3.288, Convert.ToInt32(this.numericUpDown1_0.Value));
- value_111 = Math.Max(1, Math.Min(15, 15 - double.Parse(dgvr.Cells[3].Value.ToString()))) * 9;
- if (RegularTetrahedron3D.GetStatus() > 0 && value_111 > 1)
- {
- RegularTetrahedron3D.UpdateRun(Math.Min(value_111, 200));
- //return;
- }
- if (grainMethodType == 1)
- {
- if (dgvr.Cells.Count > 4)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- dgvr.Cells[4].Value = "" + Math.Round(value_1, Convert.ToInt32(this.numericUpDown1_0.Value));
- value_1 = value_1 * 0.001 * 0.001;
- }
- if (dgvr.Cells.Count > 5)
- {
- if (getGbtType() == 4)
- dgvr.Cells[5].Value = "" + Math.Round(3.32 * Math.Log10(1.0 / value_1) - 2.9542, Convert.ToInt32(this.numericUpDown1_0.Value));
- else
- dgvr.Cells[5].Value = "" + Math.Round(3.321928 * Math.Log10(1.0 / value_1) - 2.954, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- }
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- }
- }
- else if (this.listView2.Items.Count > 0)
- {
- var firstTag = this.listView2.Items[0].Tag;
- List<List<double>> valueList = new List<List<double>>();
- double value_1 = 0;
- double small_l = 0;
- this.dataGridView2.Rows.Clear();
- for (int dataTableIndex = 0; dataTableIndex < this.dataTables.Count; dataTableIndex++)
- {
- if (this.dataTables[dataTableIndex].TableName.Equals(firstTag))
- {
- for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- List<double> valueL = new List<double>();
- for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++)
- {
- double outValue;
- if (double.TryParse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
- this.dataTables[dataTableIndex].Rows[r][c].ToString(), out outValue) && !DetailListStringIndex.Contains(c))
- {
- dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
- }
- else
- dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
- if (IndexChangedFromIndex.Count > 0)
- {
- if (IndexChangedFromIndex.Contains(c))
- valueL.Add(double.Parse(this.dataTables[dataTableIndex].Rows[r][c].ToString()));
- continue;
- }
- if (c == 3)
- value_1 += outValue;
- if (grainMethodType == 1 && c == 4 || grainMethodType == 0 && c == 2)
- small_l += outValue;
- }
- if (IndexChangedFromIndex.Count > 0)
- valueList.Add(valueL);
- this.dataGridView2.Rows.Add(dgvr);
- }
- }
- }
- this.dataGridView_Total.Rows.Clear();
- value_111 = -1;
- if (IndexChangedFromIndex.Count > 0 && IndexChangedToIndex.Count > 0 && valueList.Count > 0)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- foreach (int itemkey in IndexChangedToIndex.Keys)
- {
- int[] itemValue = IndexChangedToIndex[itemkey];
- List<double> valueL = new List<double>();//级别时会多算一遍,应该不影响什么
- if (itemValue[1] >= 0)
- foreach (List<double> itemL in valueList)
- {
- valueL.Add(itemL[itemValue[1]]);
- }
- if (itemValue[0] == 1)//求和
- dgvr.Cells[itemkey].Value = "" + Math.Round(valueL.Sum(), Convert.ToInt32(this.numericUpDown1_0.Value));
- else if (itemValue[0] == 2)//平均
- dgvr.Cells[itemkey].Value = "" + Math.Round(valueL.Average(), Convert.ToInt32(this.numericUpDown1_0.Value));
- else if (itemValue[0] == 3)//级别
- {
- if (itemValue[1] < 0)
- {
- dgvr.Cells[itemkey].Value = getGradeTotalCal(dgvr, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- else
- dgvr.Cells[itemkey].Value = getGradeValue(double.Parse(dgvr.Cells[itemValue[1]].Value.ToString()));
- }
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- return;
- ////##
- //this.RefreshDataGridView4();
- }
- double grainNumber = 0;
- //for (int j = 0; j < this.listView2.SelectedItems.Count; j++)
- {
- int dataTableIndex = 0;
- for (int i = 0; i < this.dataTable_Totals.Count; i++)
- {
- if (this.dataTable_Totals[i].TableName.Equals(firstTag/*this.listView2.SelectedItems[j].Tag*/))
- dataTableIndex = i;
- }
- if (this.dataTable_Totals.Count > dataTableIndex && this.dataTable_Totals[dataTableIndex].Rows.Count > 0)
- {
- for (int r = 0; r < this.dataTable_Totals[dataTableIndex].Rows.Count; r++)
- {
- grainNumber += double.Parse(this.dataTable_Totals[dataTableIndex].Rows[r][grainMethodType == 1 ? 0 : 1].ToString());
- }
- }
- }
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- dgvr.Cells[0].Value = "" + Math.Round(grainMethodType == 1 ? grainNumber : small_l, Convert.ToInt32(this.numericUpDown1_0.Value));
- if (getGbtType() == 3)
- {
- if (this.dict_Totals.ContainsKey(firstTag.ToString()))
- {
- Dictionary<string, object> valuePairs = this.dict_Totals[firstTag.ToString()];
- if (valuePairs.ContainsKey("RectArea"))
- value_1 = (double)valuePairs["RectArea"];
- }
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- value_1 = value_1 * 0.001 * 0.001;
- dgvr.Cells[1].Value = "" + Math.Round(3.321928 * Math.Log10(1.0 / value_1) - 2.954, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- else
- {
- dgvr.Cells[1].Value = "" + Math.Round(grainMethodType == 1 ? small_l : value_1, Convert.ToInt32(this.numericUpDown1_0.Value));
- if (grainMethodType == 1 && grainNumber > 0)
- small_l = small_l / grainNumber;
- else if (grainMethodType == 0 && value_1 > 0)
- small_l = small_l / value_1;
- //value_111 = small_l;
- dgvr.Cells[2].Value = "" + Math.Round(small_l, Convert.ToInt32(this.numericUpDown1_0.Value));
- if (getGbtType() == 4)
- dgvr.Cells[3].Value = "" + Math.Round(-6.6439 * Math.Log10(small_l * 0.001) - 3.2877, Convert.ToInt32(this.numericUpDown1_0.Value));
- else
- dgvr.Cells[3].Value = "" + Math.Round(-6.643856 * Math.Log10(small_l * 0.001) - 3.288, Convert.ToInt32(this.numericUpDown1_0.Value));
- value_111 = Math.Max(1, Math.Min(15, 15 - double.Parse(dgvr.Cells[3].Value.ToString()))) * 9;
- if (RegularTetrahedron3D.GetStatus() > 0 && value_111 > 1)
- {
- RegularTetrahedron3D.UpdateRun(Math.Min(value_111, 200));
- //return;
- }
- if (grainMethodType == 1)
- {
- if (dgvr.Cells.Count > 4)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- dgvr.Cells[4].Value = "" + Math.Round(value_1, Convert.ToInt32(this.numericUpDown1_0.Value));
- value_1 = value_1 * 0.001 * 0.001;
- }
- if (dgvr.Cells.Count > 5)
- {
- if (getGbtType() == 4)
- dgvr.Cells[5].Value = "" + Math.Round(3.32 * Math.Log10(1.0 / value_1) - 2.9542, Convert.ToInt32(this.numericUpDown1_0.Value));
- else
- dgvr.Cells[5].Value = "" + Math.Round(3.321928 * Math.Log10(1.0 / value_1) - 2.954, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- }
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- }
- }
- }
- else
- {
- System.Data.DataTable dataTable;
- List<List<double>> valueList = new List<List<double>>();
- double value_1 = 0;
- double small_l = 0;
- this.dataGridView2.Rows.Clear();
- for (int i = this.dataTables.Count - 1; i >= 0; i--)
- {
- dataTable = this.dataTables[i];
- for (int r = 0; r < dataTable.Rows.Count; r++)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- List<double> valueL = new List<double>();
- for (int c = 0; c < dataTable.Columns.Count; c++)
- {
- double outValue;
- if (double.TryParse(string.IsNullOrEmpty(dataTable.Rows[r][c].ToString()) ? "0" :
- dataTable.Rows[r][c].ToString(), out outValue) && !DetailListStringIndex.Contains(c))
- {
- dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
- }
- else
- dgvr.Cells[c].Value = dataTable.Rows[r][c].ToString();
- if (IndexChangedFromIndex.Count > 0)
- {
- if (IndexChangedFromIndex.Contains(c))
- valueL.Add(double.Parse(dataTable.Rows[r][c].ToString()));
- continue;
- }
- if (c == 3)
- value_1 += outValue;
- if (grainMethodType == 1 && c == 4 || grainMethodType == 0 && c == 2)
- small_l += outValue;
- }
- if (IndexChangedFromIndex.Count > 0)
- valueList.Add(valueL);
- this.dataGridView2.Rows.Add(dgvr);
- }
- }
- this.dataGridView_Total.Rows.Clear();
- if (IndexChangedFromIndex.Count > 0 && IndexChangedToIndex.Count > 0 && valueList.Count > 0)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- foreach (int itemkey in IndexChangedToIndex.Keys)
- {
- int[] itemValue = IndexChangedToIndex[itemkey];
- List<double> valueL = new List<double>();//级别时会多算一遍,应该不影响什么
- if (itemValue[1] >= 0)
- foreach (List<double> itemL in valueList)
- {
- valueL.Add(itemL[itemValue[1]]);
- }
- if (itemValue[0] == 1)//求和
- dgvr.Cells[itemkey].Value = "" + Math.Round(valueL.Sum(), Convert.ToInt32(this.numericUpDown1_0.Value));
- else if (itemValue[0] == 2)//平均
- dgvr.Cells[itemkey].Value = "" + Math.Round(valueL.Average(), Convert.ToInt32(this.numericUpDown1_0.Value));
- else if (itemValue[0] == 3)//级别
- if (itemValue[1] < 0)
- {
- dgvr.Cells[itemkey].Value = getGradeTotalCal(dgvr, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- else
- dgvr.Cells[itemkey].Value = getGradeValue(double.Parse(dgvr.Cells[itemValue[1]].Value.ToString()));
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- return;
- ////##
- //this.RefreshDataGridView4();
- }
- double grainNumber = 0;
- if (getGbtType() == 3)
- value_1 = 0;
- for (int j = 0; j < this.listView2.Items.Count; j++)
- {
- int dataTableIndex = 0;
- for (int i = 0; i < this.dataTable_Totals.Count; i++)
- {
- if (this.dataTable_Totals[i].TableName.Equals(this.listView2.Items[j].Tag))
- dataTableIndex = i;
- }
- if (this.dataTable_Totals.Count > dataTableIndex && this.dataTable_Totals[dataTableIndex].Rows.Count > 0)
- {
- for (int r = 0; r < this.dataTable_Totals[dataTableIndex].Rows.Count; r++)
- {
- grainNumber += double.Parse(this.dataTable_Totals[dataTableIndex].Rows[r][grainMethodType == 1 ? 0 : 1].ToString());
- }
- }
- if (this.dict_Totals.ContainsKey(this.listView2.Items[j].Tag.ToString()))
- {
- Dictionary<string, object> valuePairs = this.dict_Totals[this.listView2.Items[j].Tag.ToString()];
- if (valuePairs.ContainsKey("RectArea"))
- value_1 += (double)valuePairs["RectArea"];
- }
- }
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- dgvr.Cells[0].Value = "" + Math.Round(grainMethodType == 1 ? grainNumber : small_l, Convert.ToInt32(this.numericUpDown1_0.Value));
- if (getGbtType() == 3)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- value_1 = value_1 * 0.001 * 0.001;
- dgvr.Cells[1].Value = "" + Math.Round(3.321928 * Math.Log10(1.0 / value_1) - 2.954, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- else
- {
- dgvr.Cells[1].Value = "" + Math.Round(grainMethodType == 1 ? small_l : value_1, Convert.ToInt32(this.numericUpDown1_0.Value));
- if (grainMethodType == 1 && grainNumber > 0)
- small_l = small_l / grainNumber;
- else if (grainMethodType == 0 && value_1 > 0)
- small_l = small_l / value_1;
- dgvr.Cells[2].Value = "" + Math.Round(small_l, Convert.ToInt32(this.numericUpDown1_0.Value));
- if (getGbtType() == 4)
- dgvr.Cells[3].Value = "" + Math.Round(-6.6439 * Math.Log10(small_l * 0.001) - 3.2877, Convert.ToInt32(this.numericUpDown1_0.Value));
- else
- dgvr.Cells[3].Value = "" + Math.Round(-6.643856 * Math.Log10(small_l * 0.001) - 3.288, Convert.ToInt32(this.numericUpDown1_0.Value));
- if (grainMethodType == 1)
- {
- if (grainNumber > 0)
- value_1 = value_1 / grainNumber;
- dgvr.Cells[4].Value = "" + Math.Round(value_1, Convert.ToInt32(this.numericUpDown1_0.Value));
- value_1 = value_1 * 0.001 * 0.001;
- if (getGbtType() == 4)
- dgvr.Cells[5].Value = "" + Math.Round(3.32 * Math.Log10(1.0 / value_1) - 2.9542, Convert.ToInt32(this.numericUpDown1_0.Value));
- else
- dgvr.Cells[5].Value = "" + Math.Round(3.321928 * Math.Log10(1.0 / value_1) - 2.954, Convert.ToInt32(this.numericUpDown1_0.Value));
- }
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- }
- }
- }
- /// <summary>
- /// 是否能取到二值的结果
- /// </summary>
- /// <returns></returns>
- protected Boolean getBinaryChecked()
- {
- return (bcBinaryChecked() && this.documentWorkspace.PhaseModels[0].mat != null);
- }
- /// <summary>
- /// 是否能取到晶界重现的结果
- /// </summary>
- /// <returns></returns>
- protected Boolean getGrainBoundryChecked()
- {
- if (this.documentWorkspace.PhaseModels.Count > 0)
- {
- return (/*this.checkBox1.Checked && */this.documentWorkspace.PhaseModels[1].mat != null);
- }
- return false;
- }
- //public void SetItemOrdinal(int itemOrdinal)
- //{
- // if (this.progressDialog.InvokeRequired)
- // {
- // this.progressDialog.BeginInvoke(new Procedure<int>(SetItemOrdinal), new object[] { itemOrdinal });
- // }
- // else
- // {
- // this.itemOrdinal = itemOrdinal;
- // this.totalWork = 0;
- // this.totalProgress = 0;
- // UpdateUI();
- // }
- //}
- protected object comboBox1SelectedItem = null;
- /// <summary>
- /// 返回当前选择的辅助线名称
- /// </summary>
- /// <returns></returns>
- protected string getCurrentGuideName()
- {
- return comboBox1SelectedItem/*this.comboBox1.SelectedItem*/ != null ? comboBox1SelectedItem/*this.comboBox1.SelectedItem*/.ToString() : "";
- }
- /// <summary>
- /// 返回当前选择的图片内容
- /// </summary>
- /// <returns></returns>
- protected DocumentWorkspace getCurrentWorkspace()
- {
- if (this.lstView_img.FocusedItem == null && this.lstView_img.SelectedItems.Count == 0)
- return null;
- return this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index];
- }
- /// <summary>
- /// 返回当前选择的图片tag
- /// </summary>
- /// <returns></returns>
- protected string getCurrentWorkTag()
- {
- return this.imageList_img.Images.Keys[this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index];
- }
- /// <summary>
- /// 获取面积法显示编号的颜色
- /// </summary>
- /// <returns></returns>
- protected Color getGrainBoundryColor()
- {
- return Color.Red;//#########################1 this.documentWorkspace.PhaseModels[1].color;// this.panel1.BackColor;
- }
- private double cal_gNum = 0;
- private Mat cal_temp = null;
- GrainSizeStandardModel cal1_StandardModel;
- GrainSizeGuideModel cal1_GuideModel;
- Mat cal1_Picture;
- Mat cal_analyzeMat;
- bool cal_BinaryChecked;
- string cal1_Tag;
- int cal1_Index;
- bool cal1_RectFlag = false;
- ProgressThreadProcClass procClass;
- /// <summary>
- /// 刷新晶粒编号
- /// </summary>
- /// <returns>返回晶粒个数</returns>
- protected double GetNumberOfGrains(GrainSizeStandardModel cal_StandardModel = null, GrainSizeGuideModel cal_GuideModel = null,
- string cal_Tag = null, int cal_Index = -1, bool isRectFlag = false)
- {
- bool isCurrentTag = false;
- if (cal_StandardModel == null)
- cal_StandardModel = GSSClass.standardModel;
- if (cal_GuideModel == null)
- cal_GuideModel = GSSClass.GuideClass.guideModel;
- if (cal_Tag == null || cal_Tag.Equals(getCurrentWorkTag()))
- {
- isCurrentTag = true;
- cal_Tag = getCurrentWorkTag();
- }
- if (cal_Index == -1)
- cal_Index = this.selectPicture;
- if (cal_StandardModel.linePointList.Count <= 0)
- return 0.0;//should never go here !
- Mat cal_Picture;
- Mat analyzeMat = new Mat();
- //######################
- Bitmap cal_Bitmap = this.bitmap;
- if (cal_Tag != null && cal_Index >= 0 && cal_Index < this.appWorkspace.DocumentWorkspaces.Length)
- cal_Bitmap = this.appWorkspace.DocumentWorkspaces[cal_Index].CompositionSurface.CreateAliasedBitmap();
- bool BinaryChecked;
- if (cal_Tag != null && !isCurrentTag)
- BinaryChecked = (binaryClass.getModelMat(cal_Tag) != null);
- else
- BinaryChecked = getBinaryChecked();
- if (getGrainBoundryChecked())
- {//######################
- cal_Picture = new Mat(/*cal_*/matOrg.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
- Mat /*cal_*/oldMat = this.documentWorkspace.PhaseModels[1].mat;
- int Rows = oldMat.Rows;
- int Cols = oldMat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (oldMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- {
- cal_Picture.Set<Vec4b>(point, new Vec4b(0, 0, 0, 255));
- }
- }
- }
- Cv2.Erode(cal_Picture, cal_Picture, null, null, 1);
- /*cal_*/oldMat.CopyTo(analyzeMat);
- }
- else if (BinaryChecked)
- {
- Mat cal_Mat = (cal_Tag != null && !isCurrentTag) ? binaryClass.getModelMat(cal_Tag) : this.PhaseModel0Mat;
- cal_Picture = new Mat(cal_Mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
- int Rows = cal_Mat.Rows;
- int Cols = cal_Mat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (cal_Mat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- {
- cal_Picture.Set<Vec4b>(point, new Vec4b(0, 0, 0, 255));
- }
- }
- }
- cal_Mat.CopyTo(analyzeMat);
- }
- else
- {
- Mat cal_Mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(cal_Bitmap);
- cal_Picture = new Mat(cal_Mat/*matOrg*/.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
- cal_Mat.CopyTo(cal_Picture);
- cal_Mat.CopyTo(analyzeMat);
- }
- if (cal_temp != null)
- {
- cal_temp.Dispose();
- cal_temp = null;
- }
- cal_gNum = 0;
- cal1_StandardModel = cal_StandardModel;
- cal1_GuideModel = cal_GuideModel;
- cal1_Picture = cal_Picture;
- cal_analyzeMat = analyzeMat;
- cal1_Tag = cal_Tag;
- cal_BinaryChecked = BinaryChecked;
- cal1_Index = cal_Index;
- cal1_RectFlag = isRectFlag;
- //this.progressDialog = new TransferProgressDialog();
- //this.progressDialog.Text = PdnResources.GetString("DocumentWorkspace.ShowFileDialog.TransferProgress.Title");
- //this.progressDialog.Icon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuFileOpenIcon.png").Reference);
- //this.progressDialog.Title = PdnResources.GetString("DocumentWorkspace.ShowFileDialog.ItemText.Initializing");
- //this.progressDialog.ProgressBar.Style = ProgressBarStyle.Marquee;
- //this.progressDialog.ProgressBar.Maximum = maxPBValue;
- //DoVerbHandler Delegate_do = new DoVerbHandler(ShowProcessWindow);
- //////Thread.Sleep(30000);//隔30秒后判断一下是否完成
- //////IAsyncResult result = Delegate_do.BeginInvoke(null, null);
- //////while (!result.IsCompleted)
- //////{
- ////// Console.WriteLine("子线程未完成2");
- ////// Thread.Sleep(10000);//每隔10秒判断一下是否完成
- //////}
- //////Console.WriteLine("-------子线程已完成-------");
- ////DoVerbHandler invoker = new DoVerbHandler(ShowProcessWindow);
- ////发起一个线程,异步执行打开一个新窗口
- ////this.progressDialog.BeginInvoke(new Procedure<int>(SetItemCount), new object[] { itemCount });
- //Delegate_do.BeginInvoke(null, null);
- //////你需要在窗体遮罩的时候要做的事情
- ////DoVerbMethod();
- //cal_gNum = GSSClass.GetNumberOfGrains(cal1_StandardModel, cal1_GuideModel/*getCurrentGuideName()*/, cal1_Picture, cal_analyzeMat, getGrainBoundryChecked() || cal_BinaryChecked/*getBinaryChecked()*/,
- // this.appWorkspace.DocumentWorkspaces[cal1_Index].GetRuler(MeasurementUnit.Micron), out cal_temp);
- //yourForm.Close();
- procClass = new ProgressThreadProcClass();
- procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(cal_Action/*applyDectAction*/), "正在处理"/*PdnResources.GetString("Menu.Grainboundarytoreproduce.text")*/);
- //ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- //int itemCount = 100;
- //ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
- //System.Threading.ThreadStart copyThreadProc =
- // delegate ()
- // {
- // try
- // {
- // gNum = GSSClass.GetNumberOfGrains(cal_StandardModel, cal_GuideModel/*getCurrentGuideName()*/, cal_Picture, analyzeMat, getGrainBoundryChecked() || BinaryChecked/*getBinaryChecked()*/,
- // this.appWorkspace.DocumentWorkspaces[cal_Index].GetRuler(MeasurementUnit.Micron), out temp);
- // }
- // catch (Exception ex)
- // {
- // }
- // finally
- // {
- // progressEvents.EndOperation(OperationResult.Finished);
- // }
- // };
- //procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, null);
- //根据等级设置晶粒颜色
- if (cal_temp != null)
- {
- if (grainMethodType == 1)
- {
- if (this.grainColorsMatDict.ContainsKey(cal_Tag))
- this.grainColorsMatDict[cal_Tag] = cal_temp.Clone();
- else
- this.grainColorsMatDict.Add(cal_Tag, cal_temp.Clone());
- }
- if (cal_Index == this.selectPicture && cal_Tag == getCurrentWorkTag())
- {
- this.documentWorkspace.PhaseModels[2].mat = cal_temp;
- this.documentWorkspace.Refresh();
- }
- }
- return cal_gNum;
- }
- /// <summary>
- /// 事件处理示例方法
- /// </summary>
- /// <param name="arg"></param>
- private void DoVerbMethod()
- {
- for (int i = 0; i < 100; i++)
- {
- System.Threading.Thread.Sleep(100);
- }
- }
- private void ShowProcessWindow()
- {
- yourForm.StartPosition = FormStartPosition.CenterParent;
- yourForm.lblTitleBackColor = Color.Transparent;
- yourForm.ShowDialog();
- }
- /// <summary>
- /// 全局变量,yourForm为新窗口的名字
- /// </summary>
- TransferProgressDialog yourForm = new TransferProgressDialog();
- /// <summary>
- /// 你需要处理的事情的方法委托
- /// </summary>
- /// <param name="arg"></param>
- public delegate void DoVerbHandler(/*object arg*/);
- /// <summary>
- /// 目标选择 1不包含边缘 2边缘只处理内部 3边缘处理内外部
- /// </summary>
- public int TargetSelection = 2;
- private void cal_Action()
- {
- cal_gNum = GSSClass.GetNumberOfGrains(cal1_RectFlag, TargetSelection, cal1_StandardModel, cal1_GuideModel/*getCurrentGuideName()*/, cal1_Picture, cal_analyzeMat, getGrainBoundryChecked() || cal_BinaryChecked/*getBinaryChecked()*/,
- this.appWorkspace.DocumentWorkspaces[cal1_Index].GetRuler(MeasurementUnit.Micron), out cal_temp);
- if (procClass != null) procClass.DismissProgressAction(this);
- }
- /// <summary>
- /// 面积法组织分项数据列表的内容,并返回汇总截距(μm)和汇总面积(μm²)
- /// </summary>
- private double[] addNewRowsToDatagridView2(GrainSizeStandardModel cal_StandardModel, GrainSizeGuideModel cal_GuideModel, string cal_Tag, int cal_Index)
- {
- double small_l = 0;
- double area_sum = 0;
- //显示编号
- if (cal_StandardModel.massLabelPoints.Count > 0 && cal_StandardModel.currentStats != null)
- {
- this.dataGridView2.Rows.Clear();
- string imgName = this.appWorkspace.DocumentWorkspaces[cal_Index].GetFriendlyName();
- int index = 0;
- int label;
- //Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
- //选择标尺的物理长度(1倍下的 微米/像素)
- //this.physical_length = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
- double physical_area_length_Micron = this.appWorkspace.DocumentWorkspaces[cal_Index].GetRuler(MeasurementUnit.Micron);
- //double physical_area_length_Micron = measurementUnitDictionary[MeasurementUnit.Micron];
- double aec;
- double grainNumber = 1.0;
- decimal NA;
- foreach (int kvLabel in cal_StandardModel.massLabelPoints.Keys)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn c in this.dataGridView2.Columns)
- dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
- dgvr.Cells[0].Value = imgName;
- dgvr.Cells[1].Value = cal_GuideModel.oldSelectItem.ToString();
- dgvr.Cells[2].Value = (++index);//晶粒编号
- label = kvLabel;
- aec = cal_StandardModel.currentStats.At<int>(label/*hcomp*/, 4) * physical_area_length_Micron * physical_area_length_Micron;//晶粒面积
- dgvr.Cells[3].Value = aec/*areaField1*/;
- area_sum += aec;
- aec = aec * 0.001 * 0.001;
- NA = Convert.ToDecimal(grainNumber / aec);
- ////1013###19377##面积法位置,使用晶粒的实际面积去标准中的表进行对应,获取截距后,再进行平均的计算
- double[] lengths = {3.88, 7.75 , 10.96, 15.50, 21.92, 31.0, 43.84, 62.0,
- 87.68, 124, 175.36, 248, 350.73, 496, 701.45, 992, 1402.9, 1984.0, 2805.8, 3968.0, 5611.6,
- 7936.0, 11223.2, 15872.0, 22446.4, 31744.1, 44892.9, 63488.1, 89785.8, 126976.3};
- // 差值
- decimal differenceNew;
- decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max((double)NA - 2.88, (double)NA - 126977.3)));
- int first = 0;
- if ((double)NA > lengths[lengths.Length - 1])
- first = lengths.Length - 1;
- else
- for (int firstI = 0; firstI < lengths.Length; firstI++)
- {
- double item = lengths[firstI];
- differenceNew = Math.Abs(NA - Convert.ToDecimal(item));
- if (differenceNew < differenceOld)
- {
- differenceOld = Math.Abs(NA - Convert.ToDecimal(item));
- first = firstI;
- }
- }
- string[] valueGrade = {"00", "0" , "0.5", "1.0", "1.5", "2.0", "2.5", "3.0",
- "3.5", "4.0", "4.5", "5.0", "5.5", "6.0", "6.5", "7.0", "7.5", "8.0", "8.5", "9.0", "9.5",
- "10.0", "10.5", "11.0", "11.5", "12.0", "12.5", "13.0", "13.5", "14.0"};//显微晶粒度级别数G
- string[] valueG = {"452.5", "320.0" , "269.1", "226.3", "190.3", "160.0", "134.5", "113.1",
- "95.1", "80.0", "67.3", "56.6", "47.6", "40.0", "33.6", "28.3", "23.8", "20.0", "16.8", "14.1", "11.9",
- "10.0", "8.4", "7.1", "5.9", "5.0", "4.2", "3.5", "3.0", "2.5"};//微米##晶粒截距
- dgvr.Cells[4].Value = valueG[first];
- small_l += double.Parse(valueG[first]);
- dgvr.Cells[5].Value = valueGrade[first];
- this.dataGridView2.Rows.Add(dgvr);
- }
- for (int dataTableI = dataTables.Count - 1; dataTableI >= 0; dataTableI--)
- {
- System.Data.DataTable dataTable1 = dataTables[dataTableI];
- if (dataTable1.TableName.Equals(cal_Tag))/*dataTable.TableName*/
- dataTables.RemoveAt(dataTableI);
- }
- System.Data.DataTable dataTable = new System.Data.DataTable();
- dataTable.TableName = cal_Tag;
- foreach (DataGridViewColumn c in this.dataGridView2.Columns)
- {
- dataTable.Columns.Add(c.HeaderText);
- }
- for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
- {
- System.Data.DataRow dataRow = dataTable.NewRow();
- for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
- {
- dataRow[this.dataGridView2.Columns[c].HeaderText] = this.dataGridView2.Rows[r].Cells[c].Value;
- }
- dataTable.Rows.Add(dataRow);
- }
- this.dataTables.Add(dataTable);
- }
- return new double[] { small_l, area_sum };
- }
- #endregion
- #region 需继承方法
- /// <summary>
- /// 0,其他; 3,GBT6394的面积法; 4,ISO643
- /// </summary>
- /// <returns></returns>
- protected virtual int getGbtType()
- {
- return 0;
- }
- /// <summary>
- /// 返回保存的参数值-是否显示晶界,显示网格,显示截点
- /// </summary>
- /// <returns></returns>
- protected bool GetParamValue1(string param_key, out object ShowGrainBoundry)
- {
- bool foundItem = false;
- ShowGrainBoundry = true;
- foreach (var item in this.analysisModel.ListParam)
- {
- if (item.param_key.Equals(param_key) && item.menuId == this.menuId)//显示晶界
- {
- ShowGrainBoundry = item.value;
- foundItem = true;
- break;
- }
- }
- return foundItem;
- }
- /// <summary>
- /// 是否显示晶界
- /// </summary>
- /// <returns></returns>
- protected virtual Boolean ShowGrainBoundryChecked()
- {
- return true;
- }
- /// <summary>
- /// 是否显示网格
- /// </summary>
- /// <returns></returns>
- protected virtual Boolean drawDisplaySections()
- {
- return true;
- }
- /// <summary>
- /// 是否用不同颜色显示晶粒
- /// </summary>
- /// <returns></returns>
- protected virtual Boolean ShowGrainColorChecked()
- {
- return true;
- }
- /// <summary>
- /// 是否显示视场
- /// </summary>
- /// <returns></returns>
- protected virtual Boolean ShowDrawClassView()
- {
- return false;
- }
- /// <summary>
- /// 小数点位数后调用的事件
- /// </summary>
- protected virtual void RefreshWhileUpDown1_0ValueChanged()
- {
- }
- /// <summary>
- /// 图片索引改变后调用的事件
- /// </summary>
- protected virtual void refreshWhileImgChanged()
- {
- }
- /// <summary>
- /// 获取对应级别的方法
- /// </summary>
- /// <param name="smalll_index"></param>
- /// <returns></returns>
- protected virtual string getGradeValue(double smalll_index)
- {
- //对应级别 根据(smalll_index;//平均晶粒直径)
- //area_sum += aec;
- //aec = aec * 0.001 * 0.001;
- //NA = Convert.ToDecimal(grainNumber / aec);
- //////1013###19377##面积法位置,使用晶粒的实际面积去标准中的表进行对应,获取截距后,再进行平均的计算
- decimal NA = Convert.ToDecimal(smalll_index);
- double[] lengths = {508.0, 359.2 , 302.1, 254.0, 213.6, 179.6, 151.0, 127.0,
- 106.8, 89.8, 75.5, 63.5, 53.4, 44.9, 37.8, 31.8, 26.7, 22.5, 18.9, 15.9, 13.3,
- 11.2, 9.4, 7.9, 6.7, 5.6, 4.7, 4.0, 3.3, 2.8};
- // 差值
- decimal differenceNew;
- decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max(smalll_index - 1.8, smalll_index - 509.0)));
- int first = lengths.Length - 1;
- for (int firstI = 0; firstI < lengths.Length; firstI++)
- {
- double item = lengths[firstI];
- differenceNew = Math.Abs(NA - Convert.ToDecimal(item));
- if (differenceNew < differenceOld)
- {
- differenceOld = Math.Abs(NA - Convert.ToDecimal(item));
- first = firstI;
- }
- }
- string[] valueGrade = {"00", "0" , "0.5", "1.0", "1.5", "2.0", "2.5", "3.0",
- "3.5", "4.0", "4.5", "5.0", "5.5", "6.0", "6.5", "7.0", "7.5", "8.0", "8.5", "9.0", "9.5",
- "10.0", "10.5", "11.0", "11.5", "12.0", "12.5", "13.0", "13.5", "14.0"};//显微晶粒度级别数G
- return valueGrade[first];
- }
- /// <summary>
- /// 保存结果
- /// </summary>
- /// <param name="imagesKey">当前选择图片的tag</param>
- /// <param name="analysisPicture">当前选择图片的Index</param>
- protected virtual void buildListBox_analysisResult(string imagesKey, int analysisPicture, bool saveAll = false)
- {
- bool replace = false;
- int add = 0;
- foreach (ListViewItem item in this.listView2.Items)
- {
- if (item.Tag.Equals(imagesKey))
- {
- add++;
- if (saveAll)
- {
- replace = true;
- break;
- }
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (dr == DialogResult.OK)
- {
- replace = true;
- }
- break;
- }
- }
- if (!replace && this.listView2.Items.Count > 0 && add > 0)
- return;
- string imgName = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetFriendlyName();
- if (!replace)
- {
- ListViewItem listViewItem = new ListViewItem();
- listViewItem.SubItems[0].Text = imgName;
- listViewItem.Tag = "" + imagesKey;
- if (this.listView2.Items.Count == 0)
- this.listView2.Items.Add(listViewItem);
- else
- this.listView2.Items.Insert(0, listViewItem);
- this.threeDButton.Enabled = true;
- }
- if (grainMethodType == 1)
- buildListBoxArea_analysisResult(imagesKey, analysisPicture);
- else
- buildListBoxCutOff_analysisResult(imagesKey, analysisPicture);
- }
- /// <summary>
- /// PanelC的调色板颜色改变
- /// </summary>
- protected virtual void ColorPanelChanged(Panel panel)
- {
- }
- /// <summary>
- /// 晶粒度辅助线: 计算当前不显示数据的过程
- /// </summary>
- /// <param name="imagesKey"></param>
- /// <param name="analysisPicture"></param>
- protected void calcOtherImgs(string imagesKey, int analysisPicture)
- {
- if (!this.GSSClass.GuideClass.guideDict.ContainsKey(imagesKey))
- GSSClass.GuideClass.guideDict.Add(imagesKey, GSSClass.GuideClass.guideModel.cloneModel/*cloneListParamModel*/());
- GrainSizeGuideModel guideModel = this.GSSClass.GuideClass.guideDict[imagesKey];
- //if (this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0)
- {
- float recWidth = (float)(Math.Max(1, guideModel.rectangleFLineWidth / this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRuler(MeasurementUnit.Micron)));
- float recHeight = (float)(Math.Max(1, guideModel.rectangleFLineHeight / this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRuler(MeasurementUnit.Micron)));
- double multiple = 1.0;
- if (recWidth > this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.Width)
- {
- multiple = this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.Width / recWidth;
- }
- if (this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.Height < recHeight * multiple)//#21714
- {
- multiple = this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.Height / recHeight;
- }
- guideModel.rectangleFLineWidth = (float)(multiple * guideModel.rectangleFLineWidth);
- guideModel.rectangleFLineHeight = (float)(multiple * guideModel.rectangleFLineHeight);
- if (grainMethodType == 1)//#21714
- GSSClass.GuideClass.UpdateScaleGuideAreaStyle(guideModel.oldSelectItem, guideModel, multiple);
- else
- GSSClass.GuideClass.UpdateScaleGuideStyle(guideModel.oldSelectItem, guideModel, recWidth, recHeight
- , this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRuler(MeasurementUnit.Micron), multiple);
- }
- guideModel.loctation = new PointF(this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.Width / 2, this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.Height / 2);
- //if (this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0)
- {
- float recWidth = (float)(Math.Max(1, guideModel.rectangleFLineWidth / this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRuler(MeasurementUnit.Micron)));
- float recHeight = (float)(Math.Max(1, guideModel.rectangleFLineHeight / this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRuler(MeasurementUnit.Micron)));
- guideModel.RectangleFLine = new RectangleF(guideModel.loctation.X - recWidth / 2
- , guideModel.loctation.Y - recHeight / 2
- , recWidth, recHeight);//########################################
- bool foundItem = false;
- if (grainMethodType == 1)
- {
- if (this.matOrg != null && guideModel.oldSelectItem != null)
- GSSClass.GuideClass.updateGuideAreaRectLine(guideModel.oldSelectItem, guideModel, out foundItem, true/*guideTypeChanged*/, this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRuler(MeasurementUnit.Micron));
- }
- else
- if (this.matOrg != null && guideModel.oldSelectItem != null)
- GSSClass.GuideClass.updateGuideRectLine(guideModel.oldSelectItem, guideModel, out foundItem, true/*guideTypeChanged*/, this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRuler(MeasurementUnit.Micron));
- /////*this.*/
- ////GSSClass.GuideClass.updateRectangleSize(getCurrentWorkspace().GetRuler(MeasurementUnit.Micron)/*physical_Micron*/);
- if (foundItem)
- AddRectangleToRectangleFCaps(imagesKey, analysisPicture);
- //this.documentWorkspace.Refresh();
- }
- }
- /// <summary>
- /// 截点法组织分项数据列表的内容,并返回网格总长度(μm)和截点总数
- /// </summary>
- private double[] addCutOffNewRowsToDatagridView2(string imagesKey, int analysisPicture)
- {
- string imgName = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetFriendlyName();
- //string tag = getCurrentWorkTag();//imagesKey
- double small_l = 0;
- double count_sum = 0;
- this.dataGridView2.Rows.Clear();
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn c in this.dataGridView2.Columns)
- dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
- dgvr.Cells[0].Value = imgName;
- if (analysisPicture != this.selectPicture)//更新二值图片
- binaryClass.updateAnalysisData(imagesKey, analysisPicture);
- GrainSizeGuideModel guideModel = this.GSSClass.GuideClass.guideModel;
- if (this.GSSClass.GuideClass.guideDict.ContainsKey(imagesKey))
- guideModel = this.GSSClass.GuideClass.guideDict[imagesKey];
- //else if (analysisPicture != this.selectPicture)//计算对应图片的数据
- //{
- // this.calcOtherImgs(imagesKey, analysisPicture);
- //}
- GrainPointStyleModel styleModel = this.GSSClass.styleClass.styleModel;
- if (this.GSSClass.styleClass.styleDict.ContainsKey(imagesKey))
- styleModel = this.GSSClass.styleClass.styleDict[imagesKey];
- else//计算对应图片的数据
- {
- }
- if (this.GSSClass.GuideClass.guideModel.oldSelectItem == null)
- this.GSSClass.GuideClass.guideModel.oldSelectItem = this.comboBox1SelectedItem.ToString();
- if (guideModel.oldSelectItem == null)//#######################
- guideModel.oldSelectItem = this.GSSClass.GuideClass.guideModel.oldSelectItem;
- //if (analysisPicture != this.selectPicture)//计算对应图片的数据
- //{
- // this.calcOtherImgs(imagesKey, analysisPicture);
- //}
- dgvr.Cells[1].Value = guideModel.oldSelectItem;// this.comboBox1.SelectedItem;
- double length = GSSClass.GuideClass.guideLength(guideModel/*this.comboBox1.SelectedItem*/);
- small_l += length;
- dgvr.Cells[2].Value = length;
- double countPoints = styleModel.getCountPoints();
- decimal M = 1;
- double PL = (double)M * countPoints / length;
- count_sum += countPoints;
- dgvr.Cells[3].Value = countPoints;
- dgvr.Cells[4].Value = 1.0 / PL;
- if (getGbtType() == 4)
- dgvr.Cells[5].Value = -6.6439 * Math.Log10(1.0 / PL * 0.001) - 3.2877;
- else
- dgvr.Cells[5].Value = -6.643856 * Math.Log10(1.0 / PL * 0.001) - 3.288;
- this.dataGridView2.Rows.Add(dgvr);
- for (int dataTableI = dataTables.Count - 1; dataTableI >= 0; dataTableI--)
- {
- System.Data.DataTable dataTable1 = dataTables[dataTableI];
- if (dataTable1.TableName.Equals(imagesKey))
- dataTables.RemoveAt(dataTableI);
- }
- System.Data.DataTable dataTable = new System.Data.DataTable();
- dataTable.TableName = imagesKey;
- foreach (DataGridViewColumn c in this.dataGridView2.Columns)
- {
- dataTable.Columns.Add(c.HeaderText);
- }
- for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
- {
- System.Data.DataRow dataRow = dataTable.NewRow();
- for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
- {
- dataRow[this.dataGridView2.Columns[c].HeaderText] = this.dataGridView2.Rows[r].Cells[c].Value;
- }
- dataTable.Rows.Add(dataRow);
- }
- this.dataTables.Add(dataTable);
- return new double[] { small_l, count_sum };
- }
- /// <summary>
- /// 截点法-保存结果
- /// </summary>
- private void buildListBoxCutOff_analysisResult(string imagesKey, int analysisPicture)
- {
- //组织详细数据列表的内容,获取截距和截点数后,再进行平均的计算
- double[] res_arr = addCutOffNewRowsToDatagridView2(imagesKey, analysisPicture);
- double small_l = res_arr[0];
- double grainNumber = res_arr[1];
- this.dataGridView_Total.Rows.Clear();
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
- }
- dgvr.Cells[0].Value = small_l;
- dgvr.Cells[1].Value = grainNumber;
- if (grainNumber > 0)
- small_l = small_l / grainNumber;
- dgvr.Cells[2].Value = small_l;
- if (getGbtType() == 4)
- dgvr.Cells[3].Value = -6.6439 * Math.Log10(small_l * 0.001) - 3.2877;
- else
- dgvr.Cells[3].Value = -6.643856 * Math.Log10(small_l * 0.001) - 3.288;
- this.dataGridView_Total.Rows.Add(dgvr);
- System.Data.DataTable dataTable = new System.Data.DataTable();
- dataTable.TableName = imagesKey;
- foreach (System.Data.DataTable dataTable1 in dataTable_Totals)
- {
- if (dataTable1.TableName.Equals(dataTable.TableName))
- {
- dataTable_Totals.Remove(dataTable1);
- break;
- }
- }
- if (this.dict_Totals.ContainsKey(dataTable.TableName))
- this.dict_Totals.Remove(dataTable.TableName);
- foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
- dataTable.Columns.Add(c.HeaderText);
- for (int r = 0; r < this.dataGridView_Total.Rows.Count; r++)
- {
- System.Data.DataRow dataRow = dataTable.NewRow();
- for (int c = 0; c < this.dataGridView_Total.Rows[r].Cells.Count; c++)
- dataRow[this.dataGridView_Total.Columns[c].HeaderText] = this.dataGridView_Total.Rows[r].Cells[c].Value;
-
- dataTable.Rows.Add(dataRow);
- }
- this.dataTable_Totals.Add(dataTable);
- this.RefreshDataGridView4();
- //保存处理后的图片
- double pantographRatio = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
- List<Bitmap> tempBit = new List<Bitmap>();
- Bitmap originalBit = this.bitmap;// this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
- if (analysisPicture != this.selectPicture)//更新处理前的图片
- originalBit = this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.CreateAliasedBitmap();
- originalBit.Tag = pantographRatio;
- tempBit.Add(originalBit);
- Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
- Graphics graphics = Graphics.FromImage(newBit);
- if (binaryClass.getModelMat(imagesKey) != null/*this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null*/)
- {//(imagesKey != null) ? binaryClass.getModelMat(imagesKey) : this.PhaseModel0Mat
- Mat targetMat = binaryClass.getModelMat(imagesKey);// this.PhaseModel0Mat;
- graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- }
- else if (imagesKey.Equals(getCurrentWorkTag()) && this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null)
- {
- Mat targetMat = this.documentWorkspace.PhaseModels[0].mat;// this.PhaseModel0Mat;
- graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- }
- if (this.grainBoundaryMatDict.ContainsKey(imagesKey))
- {
- Mat targetMat = this.grainBoundaryMatDict[imagesKey];// this.documentWorkspace.PhaseModels[1].mat;
- graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- }
- if (this.grainColorsMatDict.ContainsKey(imagesKey) && !bcOriginChecked() && ShowGrainColorChecked())
- {
- Mat targetMat = this.grainColorsMatDict[imagesKey];// this.documentWorkspace.PhaseModels[1].mat;
- graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- }
- //if (this.documentWorkspace.PhaseModels[2].choise && this.documentWorkspace.PhaseModels[2].mat != null
- // && !this.documentWorkspace.PhaseModels[2].mat.IsDisposed)
- //{
- // Mat targetMat = this.documentWorkspace.PhaseModels[2].mat;
- // graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- //}
- graphics.SmoothingMode = SmoothingMode.AntiAlias;
- drawSubclass/*Draw*/(graphics, imagesKey, analysisPicture);
- newBit.Tag = pantographRatio;
- tempBit.Add(newBit);
- if (bitDic.ContainsKey(imagesKey))
- bitDic[imagesKey] = tempBit;
- else
- bitDic.Add(imagesKey, tempBit);
- ////this.
- //this.phy
- ////拼接中间数据
- //List<List<string>> dataList = new List<List<string>>();
- //List<string> columnName = new List<string>();
- //columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
- //columnName.Add(PdnResources.GetString("Menu.Xoordinate.Text"));
- //columnName.Add(PdnResources.GetString("Menu.Yoordinate.Text"));
- //columnName.Add(PdnResources.GetString("Menu.Whethertheinternal.Text"));
- //dataList.Add(columnName);
- GrainPointStyleModel styleModel = this.GSSClass.styleClass.styleModel;
- if (this.GSSClass.styleClass.styleDict.ContainsKey(imagesKey))
- styleModel = this.GSSClass.styleClass.styleDict[imagesKey];
- //拼接中间数据
- List<List<string>> dataList = GSSClass.styleClass.getTableDataList(styleModel, this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRuler(MeasurementUnit.Micron));
- bool isExist = false;//是否已存在进行替换
- int modelIndex = -1;//要替换的下标
- for (int j = 0; j < tempDataModel.Count; j++)
- {
- if (tempDataModel[j].tagName.Equals(imagesKey))
- {
- isExist = true;
- modelIndex = j;
- break;
- }
- }
- if (isExist && modelIndex > -1)
- tempDataModel[modelIndex].dataList = dataList;
- else
- {
- ExportProjectModel newModel = new ExportProjectModel();
- newModel.tagName = imagesKey;
- newModel.picName = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetFriendlyName();//##################################
- newModel.dataList = dataList;
- tempDataModel.Add(newModel);
- }
- }
- /// <summary>
- /// 面积法-保存结果
- /// </summary>
- private void buildListBoxArea_analysisResult(string imagesKey, int analysisPicture)
- {
- if (analysisPicture != this.selectPicture)//更新二值图片
- binaryClass.updateAnalysisData(imagesKey, analysisPicture);
- GrainSizeGuideModel cal_GuideModel = this.GSSClass.GuideClass.guideModel;
- if (this.GSSClass.GuideClass.guideDict.ContainsKey(imagesKey))
- cal_GuideModel = this.GSSClass.GuideClass.guideDict[imagesKey];
- //else if (analysisPicture != this.selectPicture)//根据选择的辅助线 计算对应图片的数据
- //{
- // this.calcOtherImgs(imagesKey, analysisPicture);
- //}
- if (this.GSSClass.GuideClass.guideModel.oldSelectItem == null)
- this.GSSClass.GuideClass.guideModel.oldSelectItem = this.comboBox1SelectedItem.ToString();
- if (cal_GuideModel.oldSelectItem == null)//##
- cal_GuideModel.oldSelectItem = this.GSSClass.GuideClass.guideModel.oldSelectItem;
- GrainSizeStandardModel cal_StandardModel = this.GSSClass.standardModel;
- if (imagesKey != null)
- {
- if (!this.GSSClass.standardDict.ContainsKey(imagesKey))
- this.GSSClass.standardDict.Add(imagesKey, this.GSSClass.standardModel.cloneListParamModel());
- cal_StandardModel = this.GSSClass.standardDict[imagesKey];
- if (analysisPicture == this.selectPicture && imagesKey.Equals(getCurrentWorkTag()))
- this.GSSClass.standardModel = this.GSSClass.standardDict[imagesKey];
- }
- if (analysisPicture != this.selectPicture)//根据选择的辅助线 计算对应图片的数据
- //if (cal_StandardModel.linePointList.Count == 0)
- this.calcOtherImgs(imagesKey, analysisPicture);
- // 是否矩形辅助线
- int isRect;
- double aec0 = GSSClass.GuideClass.guideArea(cal_GuideModel, cal_GuideModel.oldSelectItem/*this.comboBox1.SelectedItem*/, out isRect, getGbtType());
- //aec = aec * 0.001 * 0.001;
- double grainNumber = GetNumberOfGrains(cal_StandardModel, cal_GuideModel, imagesKey, analysisPicture
- , isRect == 1) + isRect;
- //组织详细数据列表的内容,获取截距和面积后,再进行平均的计算<=>GBT6394面积法计算级别
- double[] res_arr = addNewRowsToDatagridView2(cal_StandardModel, cal_GuideModel, imagesKey, analysisPicture);
- //grainNumber = 8;
- double small_l = res_arr[0];
- double area_l = aec0;// res_arr[1];
- this.dataGridView_Total.Rows.Clear();
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
- }
- dgvr.Cells[0].Value = grainNumber;
- if (getGbtType() == 3)
- {
- if (grainNumber > 0)
- area_l = area_l / grainNumber;
- double aec = area_l * 0.001 * 0.001;
- double NA = (double)1/*grainNumber*/ / aec;
- dgvr.Cells[1].Value = 3.321928 * Math.Log10(NA) - 2.954;
- }
- else
- {
- dgvr.Cells[1].Value = small_l;
- if (grainNumber > 0)
- small_l = small_l / grainNumber;
- dgvr.Cells[2].Value = small_l;
- if (getGbtType() == 4)
- dgvr.Cells[3].Value = -6.6439 * Math.Log10(small_l * 0.001) - 3.2877;
- else
- dgvr.Cells[3].Value = -6.643856 * Math.Log10(small_l * 0.001) - 3.288;
- if (grainNumber > 0)
- area_l = area_l / grainNumber;
- dgvr.Cells[4].Value = area_l;
- double aec = area_l * 0.001 * 0.001;
- double NA = (double)1/*grainNumber*/ / aec;
- if (getGbtType() == 4)
- dgvr.Cells[5].Value = 3.32 * Math.Log10(NA) - 2.9542;
- else
- dgvr.Cells[5].Value = 3.321928 * Math.Log10(NA) - 2.954;//!!!!!!!!!!!!!................................
- }
- this.dataGridView_Total.Rows.Add(dgvr);
- System.Data.DataTable dataTable = new System.Data.DataTable();
- dataTable.TableName = imagesKey;
- foreach (System.Data.DataTable dataTable1 in dataTable_Totals)
- {
- if (dataTable1.TableName.Equals(dataTable.TableName))
- {
- dataTable_Totals.Remove(dataTable1);
- break;
- }
- }
- if (this.dict_Totals.ContainsKey(dataTable.TableName))
- this.dict_Totals.Remove(dataTable.TableName);
- foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
- {
- dataTable.Columns.Add(c.HeaderText);
- }
- for (int r = 0; r < this.dataGridView_Total.Rows.Count; r++)
- {
- System.Data.DataRow dataRow = dataTable.NewRow();
- for (int c = 0; c < this.dataGridView_Total.Rows[r].Cells.Count; c++)
- {
- dataRow[this.dataGridView_Total.Columns[c].HeaderText] = this.dataGridView_Total.Rows[r].Cells[c].Value;
- }
- dataTable.Rows.Add(dataRow);
- }
- this.dataTable_Totals.Add(dataTable);
- if (getGbtType() == 3)
- this.dict_Totals.Add(imagesKey, new Dictionary<string, object>() { { "RectArea", aec0 } });
- this.RefreshDataGridView4();
- //保存处理后的图片
- double pantographRatio = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
- List<Bitmap> tempBit = new List<Bitmap>();
- Bitmap originalBit = this.bitmap;
- if (analysisPicture != this.selectPicture)//更新处理前的图片
- originalBit = this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.CreateAliasedBitmap();
- originalBit.Tag = pantographRatio;
- tempBit.Add(originalBit);
- Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
- Graphics graphics = Graphics.FromImage(newBit);
- if (binaryClass.getModelMat(imagesKey) != null)
- {
- Mat targetMat = binaryClass.getModelMat(imagesKey);
- graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- }
- if (this.grainBoundaryMatDict.ContainsKey(imagesKey))
- {
- Mat targetMat = this.grainBoundaryMatDict[imagesKey];
- graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- }
- if (this.grainColorsMatDict.ContainsKey(imagesKey) && !bcOriginChecked() && ShowGrainColorChecked())
- {
- Mat targetMat = this.grainColorsMatDict[imagesKey];
- graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- }
- graphics.SmoothingMode = SmoothingMode.AntiAlias;
- drawSubclass(graphics, imagesKey, analysisPicture);
- newBit.Tag = pantographRatio;
- tempBit.Add(newBit);
- if (bitDic.ContainsKey(imagesKey))
- bitDic[imagesKey] = tempBit;
- else
- bitDic.Add(imagesKey, tempBit);
- //拼接中间数据
- List<List<string>> dataList = new List<List<string>>();
- List<string> columnName = new List<string>();
- columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
- columnName.Add(PdnResources.GetString("Menu.Xoordinate.Text"));
- columnName.Add(PdnResources.GetString("Menu.Yoordinate.Text"));
- columnName.Add(PdnResources.GetString("Menu.Whethertheinternal.Text"));
- //Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
- //选择标尺的物理长度(1倍下的 微米/像素)
- //double physical_area_length_Micron = measurementUnitDictionary[MeasurementUnit.Micron];
- double physical_area_length_Micron = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRuler(MeasurementUnit.Micron);
- if (cal_StandardModel.currentStats != null && physical_area_length_Micron > 0)//##20544
- {
- columnName.Add("晶粒面积"/*PdnResources.GetString("Menu.Whethertheinternal.Text")*/);
- }
- //aec = currentStats.At<int>(label/*hcomp*/, 4) * physical_area_length_Micron * physical_area_length_Micron;//晶粒面积
- dataList.Add(columnName);
- if (cal_StandardModel.massLabelPoints.Count > 0)
- {
- int index = 0;
- int outMaxIndex = cal_StandardModel.massLabelPoints.Count - 0 - cal_StandardModel.within;
- foreach (var label in cal_StandardModel.massLabelPoints.Keys)//####################
- {
- var item = cal_StandardModel.massLabelPoints[label];
- List<string> strList = new List<string>();
- strList.Add(("" + (++index)).ToString());
- strList.Add(item[2].ToString());
- strList.Add(item[3].ToString());
- if (outMaxIndex < index)
- strList.Add(PdnResources.GetString("Menu.Yes.text"));
- else
- strList.Add(PdnResources.GetString("Menu.no.text"));
- strList.Add((cal_StandardModel.currentStats.At<int>(label/*hcomp*/, 4) * physical_area_length_Micron * physical_area_length_Micron).ToString());
- dataList.Add(strList);
- }
- }
- bool isExist = false;//是否已存在进行替换
- int modelIndex = -1;//要替换的下标
- for (int j = 0; j < tempDataModel.Count; j++)
- {
- if (tempDataModel[j].tagName.Equals(imagesKey))
- {
- isExist = true;
- modelIndex = j;
- break;
- }
- }
- if (isExist && modelIndex > -1)
- tempDataModel[modelIndex].dataList = dataList;
- else
- {
- Base.Functionodel.ExportProjectModel newModel = new Base.Functionodel.ExportProjectModel();
- newModel.tagName = imagesKey;
- newModel.picName = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetFriendlyName();
- newModel.dataList = dataList;
- tempDataModel.Add(newModel);
- }
- }
- /// <summary>
- /// 保存子窗体参数
- /// </summary>
- protected virtual void saveSonData()
- {
- }
- /// <summary>
- /// 获取子窗体参数
- /// </summary>
- protected virtual void getSonData()
- {
- }
- /// <summary>
- /// 保存子窗体录制参数
- /// </summary>
- protected virtual object saveRecordingData(string key)
- {
- return null;
- }
- protected virtual void SubclassInitialize()
- {
- throw new NotImplementedException();
- }
- /// <summary>
- /// 辅助线类型
- /// </summary>
- /// <returns></returns>
- protected virtual string[] getTypeNames()
- {
- return new string[] {
- "",
- ""};
- }
- /// <summary>
- /// 辅助线配置文件名称
- /// </summary>
- /// <returns></returns>
- protected virtual string getModelName()
- {
- throw new NotImplementedException();
- }
- /// <summary>
- /// 报告模板命名
- /// </summary>
- /// <returns></returns>
- protected virtual string getTemplateName()
- {
- throw new NotImplementedException();
- }
- /// <summary>
- /// 项目工程内的文件夹路径名称
- /// </summary>
- /// <returns></returns>
- protected virtual string getProjectEngineeringName()
- {
- throw new NotImplementedException();
- }
- /// <summary>
- /// 是否绘制辅助线
- /// </summary>
- /// <param name="graphics"></param>
- /// <returns></returns>
- protected virtual bool showGridChecked()
- {
- return false;
- }
- /// <summary>
- /// 是否绘制截点
- /// </summary>
- /// <param name="graphics"></param>
- /// <returns></returns>
- protected virtual bool drawGuidePoints()
- {
- return false;
- }
- /// <summary>
- /// 是否绘制编号
- /// </summary>
- /// <param name="graphics"></param>
- /// <returns></returns>
- protected virtual bool showGrainNumberChecked()
- {
- return false;
- }
- protected virtual void drawSubclass(Graphics graphics, string imagesKey = null, int analysisPicture = -1)
- {
- GrainSizeGuideModel cal_GuideModel = GSSClass.GuideClass.guideModel;
- if (imagesKey != null && GSSClass.GuideClass.guideDict.ContainsKey(imagesKey))
- cal_GuideModel = GSSClass.GuideClass.guideDict[imagesKey];
- GrainPointStyleModel cal_StyleModel = GSSClass.styleClass.styleModel;
- if (imagesKey != null && GSSClass.styleClass.styleDict.ContainsKey(imagesKey))
- cal_StyleModel = GSSClass.styleClass.styleDict[imagesKey];
- GrainSizeStandardModel cal_StandardModel = GSSClass.standardModel;
- if (imagesKey != null && GSSClass.standardDict.ContainsKey(imagesKey))
- cal_StandardModel = GSSClass.standardDict[imagesKey];
- //显示辅助线
- if (showGridChecked())
- if (grainMethodType == 1)
- GSSClass.GuideClass.DrawAreaGuide(graphics, cal_GuideModel.oldSelectItem != null ? cal_GuideModel.oldSelectItem : this.comboBox1.SelectedItem, cal_GuideModel);
- else
- GSSClass.GuideClass.DrawGuideLines(graphics, cal_GuideModel.oldSelectItem != null ? cal_GuideModel.oldSelectItem : this.comboBox1.SelectedItem, cal_GuideModel);
- //显示截点
- if (drawGuidePoints())
- cal_StyleModel.DrawGuidePoints(graphics);
- //显示编号
- if (showGrainNumberChecked() && cal_StandardModel.massLabelPoints.Count > 0)
- {
- int index = 0;
- Font myFont = new Font("宋体", 12);
- Brush bush = new SolidBrush(getGrainBoundryColor());//填充的颜色
- foreach (var item in cal_StandardModel.massLabelPoints.Values)
- {
- graphics.DrawString("" + (++index), myFont, bush, (float)item[2] - 5, (float)item[3] - 5);
- }
- }
- }
- /// <summary>
- /// 实现手动添加在原图情况下的截点位置跟随辅助线的移动而移动
- /// </summary>
- public void MoveOriginCutOffPoints(float offsetX, float offsetY)
- {
- Mat mat;
- if (!getGrainBoundryChecked() && !getBinaryChecked())
- {
- mat = matOrg;
- }
- else
- {
- if (getGrainBoundryChecked())
- {
- if (this.documentWorkspace.PhaseModels[1].mat != null)
- mat = this.documentWorkspace.PhaseModels[1].mat;
- else
- return;
- }
- else if (this.documentWorkspace.PhaseModels[0].mat != null)
- {
- mat = this.PhaseModel0Mat;
- }
- else
- return;
- }
- if (mat == null)
- return;
- //##21247
- GSSClass.MoveOriginCutOffPoints(offsetX, offsetY, this.getCurrentGuideName(), mat);
- }
- ///// <summary>
- ///// 刷新图形边线点集合//#########################################
- ///// </summary>
- /// <param name="imagesKey">计算当前不显示数据的过程</param>
- /// <param name="analysisPicture">计算当前不显示数据的过程</param>
- private void AddRectangleToRectangleFCaps(string imagesKey = null, int analysisPicture = -1)
- {
- if (grainMethodType == 1 && this.bitmap == null)//####################
- return;
- if (grainMethodType == 1)
- {//###############################################
- Bitmap cal_Bitmap = this.bitmap;
- if (imagesKey != null && analysisPicture != -1)
- cal_Bitmap = this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.CreateAliasedBitmap();
- string cal_GuideName = imagesKey != null ? GSSClass.GuideClass.guideDict[imagesKey].oldSelectItem : this.getCurrentGuideName();
- GSSClass.AddRectangleToRectangleFCaps(imagesKey, grainMethodType, cal_Bitmap, cal_GuideName, 0, null, (analysisPicture != -1 ? this.appWorkspace.DocumentWorkspaces[analysisPicture] : getCurrentWorkspace()).GetRuler(MeasurementUnit.Micron));
- this.documentWorkspace.Refresh();
- return;
- }
- //this.analysisDict.
- bool BinaryChecked;
- if (imagesKey != null)
- BinaryChecked = (binaryClass.getModelMat(imagesKey) != null);
- else
- BinaryChecked = getBinaryChecked();
- Mat mat;
- if (!getGrainBoundryChecked() && !BinaryChecked)//###########################
- {
- mat = matOrg;
- }
- else
- {
- if (getGrainBoundryChecked())
- {
- if (this.documentWorkspace.PhaseModels[1].mat != null)
- mat = this.documentWorkspace.PhaseModels[1].mat;
- else
- return;
- }
- else if (BinaryChecked/*this.documentWorkspace.PhaseModels[0].mat != null*/)
- {
- mat = (imagesKey != null) ? binaryClass.getModelMat(imagesKey) : this.PhaseModel0Mat;
- }
- else
- return;
- }
- if (mat == null)
- return;
- int matLevel = 0;
- if (getGrainBoundryChecked())
- matLevel = 2;
- else if (BinaryChecked/*getBinaryChecked()*/)
- matLevel = 1;
- else if (!getGrainBoundryChecked() && !BinaryChecked/*getBinaryChecked()*/)
- matLevel = 0;
- Bitmap bitmap = this.bitmap;
- if (imagesKey != null)
- bitmap = this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.CreateAliasedBitmap();
- GSSClass.AddRectangleToRectangleFCaps(imagesKey, grainMethodType, bitmap, (imagesKey != null ? GSSClass.GuideClass.guideDict[imagesKey].oldSelectItem : this.getCurrentGuideName()), matLevel, mat, (analysisPicture == -1 ? getCurrentWorkspace() : this.appWorkspace.DocumentWorkspaces[analysisPicture]).GetRuler(MeasurementUnit.Micron));
- if (analysisPicture == -1 || analysisPicture == this.selectPicture)
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 初始化矩形
- /// </summary>
- private void InitRectangleF(bool guideTypeChanged)
- {
- if (this.matOrg != null && this.comboBox1.SelectedItem != null)
- {
- bool foundItem;
- if (grainMethodType == 1)
- GSSClass.GuideClass.guideModel.RectangleFLine = GSSClass.GuideClass.guideAreaRectLine(this.comboBox1.SelectedItem, out foundItem, guideTypeChanged, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron));
- else
- GSSClass.GuideClass.guideModel.RectangleFLine = GSSClass.GuideClass.guideRectLine(this.comboBox1.SelectedItem, out foundItem, guideTypeChanged, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron));
- //if (foundItem)//#21756
- this.AddRectangleToRectangleFCaps();
- }
- }
- /// <summary>
- /// 更新辅助线及其样式
- /// </summary>
- protected virtual void UpdateGuideStyle(bool showMessageAlert)
- {
- if (getCurrentWorkspace() == null)//#21319
- return;
- if (grainMethodType == 1)
- GSSClass.GuideClass.UpdateGuideAreaStyle(this.bitmap, this.comboBox1.SelectedItem, showMessageAlert && this.comboBox1.SelectedIndex > 0, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron));
- else//##19846
- GSSClass.GuideClass.UpdateGuideStyle(matOrg, this.comboBox1.SelectedItem, showMessageAlert && this.comboBox1.SelectedIndex > 0, getCurrentWorkspace().GetRuler(MeasurementUnit.Micron));
- }
- /// <summary>
- /// 添加辅助线后更新下拉列表信息
- /// </summary>
- /// <param name="arrayList"></param>
- public void AddComboboxValue(ArrayList arrayList)
- {
- if (!GSSClass.InitComboboxValue())
- {
- if (grainMethodType == 1)
- GSSClass.GuideClass.createGuideAreaClassModelsNamed(getModelName());
- else
- GSSClass.GuideClass.createGuideClassModelsNamed(getModelName());
- }
- if (arrayList != null && arrayList.Count > 0)
- {
- this.comboBox1.SelectedIndexChanged -= new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- //this.comboBox1.SelectedItem = (string)ItemStringObject;
- //comboBox1SelectedItem = comboBox1.SelectedItem;
- ////this.comboboxChange = false;
- arrayList.Insert(0, PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text"));
- this.comboBox1.DataSource = arrayList;
- //this.comboboxChange = false;
- int oldSelectIndex = -1;
- for (int i = 0; i < this.comboBox1.Items.Count; i++)
- {
- if (GSSClass.GuideClass.guideModel.oldSelectItem.Equals(this.comboBox1.Items[i]))
- {
- oldSelectIndex = i;
- }
- }
- if (oldSelectIndex > -1)
- this.comboBox1.SelectedIndex = oldSelectIndex;
- else if (this.comboBox1.Items.Count > 0)
- this.comboBox1.SelectedIndex = 0;
- this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- }
- //this.comboBox1.DataSource =
- }
- /// <summary>
- /// 辅助线维护
- /// </summary>
- public virtual void InitComboboxValue(ArrayList arrayList)
- {
- UpdateCupOffPointStyle();
- if (!GSSClass.InitComboboxValue())
- {
- if (grainMethodType == 1)
- GSSClass.GuideClass.createGuideAreaClassModelsNamed(getModelName());
- else
- GSSClass.GuideClass.createGuideClassModelsNamed(getModelName());
- }
- this.comboBox1.DataSource = null;
- if (arrayList != null && arrayList.Count > 0)
- {
- this.comboboxChange = false;
- arrayList.Insert(0, PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text"));
- this.comboBox1.DataSource = arrayList;
- this.comboboxChange = false;
- int oldSelectIndex = -1;
- for (int i = 0; i < this.comboBox1.Items.Count; i++)
- {
- if (GSSClass.GuideClass.guideModel.oldSelectItem.Equals(this.comboBox1.Items[i]))
- {
- oldSelectIndex = i;
- }
- }
- if (oldSelectIndex > -1)
- this.comboBox1.SelectedIndex = oldSelectIndex;
- else if (this.comboBox1.Items.Count > 0)
- this.comboBox1.SelectedIndex = 0;
- }
- else
- {
- ArrayList arrayList1;
- if (grainMethodType == 1)
- arrayList1 = GSSClass.GuideClass.getComboboxArrayAreaList1();
- else
- arrayList1 = GSSClass.GuideClass.getComboboxArrayList1();
- if (arrayList1.Count > 0)
- {
- this.comboBox1.DataSource = arrayList1;
- this.comboBox1.SelectedIndex = 0;
- }
- }
- UpdateGuideStyle(false);
- this.documentWorkspace.Refresh();
- }
- #endregion
- /// <summary>
- /// 保存参数的key,value和type
- /// </summary>
- /// <param name="param_key"></param>
- /// <param name="param_value"></param>
- /// <param name="param_type"></param>
- protected void saveParamValue(string param_key, string param_value, int param_type)
- {
- bool foundItem = false;
- foreach (var item in this.analysisModel.ListParam)
- {
- if (item.param_key.Equals(param_key) && item.menuId == this.menuId)
- {
- item.param_value = param_value;
- item.setValue();
- foundItem = true;
- break;
- }
- }
- if (!foundItem)
- {
- GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel();
- analysisItem.menuId = this.menuId;
- analysisItem.param_key = param_key;
- analysisItem.param_type = param_type;
- analysisItem.param_value = param_value;
- analysisItem.setValue();
- this.analysisModel.ListParam.Add(analysisItem);
- }
- }
- /// <summary>
- /// 保存界面中的参数到model
- /// </summary>
- private void saveDialogParamValues()
- {
- saveParamValue(ParamKey_ShowGrainNumber, showGrainNumberChecked() ? "0" : "1", (int)Base.Dtryt.Boolean);//显示晶粒编号
- saveParamValue(ParamKey_ShowGrainColor, ShowGrainColorChecked() ? "0" : "1", (int)Base.Dtryt.Boolean);//用不同颜色显示晶粒
- saveParamValue(ParamKey_displaygrainboundaries, ShowGrainBoundryChecked() ? "0" : "1", (int)Base.Dtryt.Boolean);//显示晶界
- saveParamValue(ParamKey_displaygrid, showGridChecked() ? "0" : "1", (int)Base.Dtryt.Boolean);//显示网格
- saveParamValue(ParamKey_displaysections, drawDisplaySections() ? "0" : "1", (int)Base.Dtryt.Boolean);//显示截点
- saveParamValue(ParamKey_comboBox1SelectedItem, comboBox1SelectedItem != null ? comboBox1SelectedItem.ToString() : "", (int)Base.Dtryt.ItemString);//选择的辅助线
- saveParamValue(ParamKey_CalculatorDecimalDigits, Convert.ToInt32(this.numericUpDown1_0.Value).ToString(), (int)Base.Dtryt.Interger);
- saveParamValue(ParamKey_OpenWhileExportReport, this.checkBox_generateReport_opensetting.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//生成报告时打开设置
- saveParamValue(ParamKey_TargetSelection, this.TargetSelection.ToString(), (int)Base.Dtryt.Interger);
- saveSonData();
- }
- private void GrainSizeStandardDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- #region [开启脚本录制]
- if (appWorkspace.startScriptRecording)
- {
- getScriptRecording();
- }
- #endregion
- this.saveDialogParamValues();
- binaryClass.saveParams();
- //xml保存路径
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
- GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
- foreach (var analysisItem in this.analysisModel.ListParam)
- {
- bool foundItem = false;
- foreach (var item in analysisModelXml.ListParam)
- {
- if (item.param_key.Equals(analysisItem.param_key) && item.menuId == this.menuId)
- {
- item.param_value = analysisItem.param_value;
- foundItem = true;
- break;
- }
- }
- if (!foundItem)
- {
- GrainSizeAnalysisModel newMod = analysisItem.cloneModel();
- newMod.value = null;//避免value为集合导致保存出错
- analysisModelXml.ListParam.Add(newMod);
- }
- //analysisModelXml.ListParam.Add(analysisItem.cloneModel());
- }
- //按路径和名称保存xml文件
- string userInfoXml = XmlSerializeHelper.XmlSerialize<GrainSizeAnalysisModel>(analysisModelXml);
- //保存xml
- FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create);
- }
- /// <summary>
- /// 应用到全部
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_ApplyToAll_Click(object sender, EventArgs e)
- {
- if ((this.menuId != 11012101 && this.menuId != 11012102) && (this.comboBox1.SelectedItem == null || PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text").Equals(this.comboBox1.SelectedItem)))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectauxiliaryline.text") + "!");
- return;
- }
- //清空晶界重现除了当前图片之外的缓存数据
- foreach (var itemKey in this.imageList_img.Images.Keys)
- {
- if (itemKey.Equals(getCurrentWorkTag()))
- continue;
- if (this.grainBoundaryMatDict.ContainsKey(itemKey))
- this.grainBoundaryMatDict.Remove(itemKey);
- if (this.grainBoundaryDict.ContainsKey(itemKey))
- this.grainBoundaryDict.Remove(itemKey);
- }
- binaryClass.applyToAll(this.imageList_img.Images.Keys, getCurrentWorkTag());
- this.saveDialogParamValues();
- this.lstView_img.SelectedIndexChanged -= new System.EventHandler(this.lstView_img_SelectedIndexChanged);
- try
- {
- currentOldSelectIndex = this.selectPicture;
- for (int kselectPicture = 0; kselectPicture <= this.appWorkspace.DocumentWorkspaces.Count(); kselectPicture++)
- {
- if (currentOldSelectIndex == kselectPicture || kselectPicture == this.appWorkspace.DocumentWorkspaces.Count())
- {//跳过当前选择的窗口,并最后回到当前窗口数据
- if (kselectPicture == this.appWorkspace.DocumentWorkspaces.Count())
- {
- kselectPicture = currentOldSelectIndex;
- this.analysisModel = this.analysisDict[this.imageList_img.Images.Keys[kselectPicture]];
- string imagesKeyCurrent = this.imageList_img.Images.Keys[kselectPicture];
- GSSClass.standardModel = GSSClass.standardDict[imagesKeyCurrent];
- GSSClass.GuideClass.guideModel = GSSClass.GuideClass.guideDict[imagesKeyCurrent];
- GSSClass.styleClass.styleModel = GSSClass.styleClass.styleDict[imagesKeyCurrent];
- this.lstView_img.EnsureVisible(kselectPicture);
- this.lstView_img.Items[kselectPicture].Focused = true;
- this.lstView_img.Items[kselectPicture].Selected = true;
- this.refreshActionWhileImg_SelectedIndexChanged(true, kselectPicture/*this.selectPicture*/);
- break;
- }
- continue;
- }
- if (this.analysisDict.ContainsKey(this.imageList_img.Images.Keys[kselectPicture]))
- this.analysisDict[this.imageList_img.Images.Keys[kselectPicture]] = this.analysisModel.cloneListParamModel(this.menuId);
- string imagesKey = this.imageList_img.Images.Keys[kselectPicture];
- if (GSSClass.standardDict.ContainsKey(imagesKey))
- GSSClass.standardDict[imagesKey] = new GrainSizeStandardModel();// GSSClass.standardModel.cloneListParamModel();
- if (GSSClass.GuideClass.guideDict.ContainsKey(imagesKey))
- GSSClass.GuideClass.guideDict[imagesKey] = GSSClass.GuideClass.guideModel.cloneModel/*cloneListParamModel*/();
- if (GSSClass.styleClass.styleDict.ContainsKey(imagesKey))
- GSSClass.styleClass.styleDict[imagesKey] = GSSClass.styleClass.styleModel.cloneListParamModel();
- this.lstView_img.EnsureVisible(kselectPicture);
- this.lstView_img.Items[kselectPicture].Focused = true;
- this.lstView_img.Items[kselectPicture].Selected = true;
- this.refreshActionWhileImg_SelectedIndexChanged(true, kselectPicture/*this.selectPicture*/);
- }
- }
- catch (Exception ex)
- {
- }
- finally
- {
- this.lstView_img.SelectedIndexChanged += new System.EventHandler(this.lstView_img_SelectedIndexChanged);
- }
- }
- /// <summary>
- /// 保存全部
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button_SaveAll_Click(object sender, EventArgs e)
- {
- if (this.imageList_img.Images.Keys.Count <= 1)
- {
- this.btn_saveresult.PerformClick();
- return;
- }
- for (int kselectPicture = 0; kselectPicture < this.appWorkspace.DocumentWorkspaces.Count(); kselectPicture++)
- {
- string imagesKey = /*toDeleteImageKeysList*/this.imageList_img.Images.Keys[kselectPicture];
- //string imagesKey = kselectPicture.ToString();
- if (!this.GSSClass.GuideClass.guideDict.ContainsKey(imagesKey))
- {
- MessageBox.Show("请先应用到全部图片后进行保存全部操作"/* “或者计算每个图片数据后”PdnResources.GetString("Menu.Pleaseselectauxiliaryline.text") + "!"*/);
- return;
- }
- }
- bool replace = false;
- int add = 0;
- //#22510 -> 确定则全部替换,点击取消则只更新没有的结果已存在的不更新
- List<string> toDeleteImageKeysList = new List<string>();
- for (int kselectPicture = 0; kselectPicture < this.imageList_img.Images.Keys.Count; kselectPicture++)
- toDeleteImageKeysList.Add(this.imageList_img.Images.Keys[kselectPicture]);
- for (int itemI = 0; itemI < this.listView2.Items.Count; itemI++)
- {
- ListViewItem item = this.listView2.Items[itemI];
- //if (item.Tag.Equals(imagesKey))
- if (this.imageList_img.Images.Keys.Contains(item.Tag.ToString()))
- {
- add++;
- if (itemI == 0)
- {
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text") + "?" /*+ "\n确定则全部替换,取消则跳过已保存的结果"*/, PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (dr != DialogResult.OK)
- {
- //toDeleteImageKeysList.Clear();
- replace = false;
- }
- else
- {
- replace = true;
- break;
- }
- }
- toDeleteImageKeysList.Remove(item.Tag.ToString());
- }
- }
- if (toDeleteImageKeysList.Count == 0 && !replace && this.listView2.Items.Count > 0 && add > 0)
- return;
- for (int kselectPicture = 0; kselectPicture < toDeleteImageKeysList.Count; kselectPicture++)
- {
- //for (int kselectPicture = 0; kselectPicture < this.appWorkspace.DocumentWorkspaces.Count(); kselectPicture++)
- //{
- string imagesKey = toDeleteImageKeysList/*this.imageList_img.Images.Keys*/[kselectPicture];
- if (!this.GSSClass.GuideClass.guideDict.ContainsKey(imagesKey))
- {
- MessageBox.Show("请先应用到全部图片后进行保存全部操作"/* “或者计算每个图片数据后”PdnResources.GetString("Menu.Pleaseselectauxiliaryline.text") + "!"*/);
- return;
- }
- }
- if (replace)
- {
- this.dataGridView_Total.Rows.Clear();
- }
- //#22510 -> 确定则全部替换,点击取消则只更新没有的结果已存在的不更新
- for (int k = 0; k < toDeleteImageKeysList.Count; k++)
- //for (int k = 0; k < this.appWorkspace.DocumentWorkspaces.Count(); k++)
- buildListBox_analysisResult(toDeleteImageKeysList[k], this.imageList_img.Images.Keys.IndexOf(toDeleteImageKeysList[k]), true);
- if (this.documentWorkspace.PhaseModels[2].mat != null && this.documentWorkspace.PhaseModels[2].mat.IsDisposed && this.grainColorsMatDict.ContainsKey(getCurrentWorkTag()))
- {
- this.documentWorkspace.PhaseModels[2].mat = this.grainColorsMatDict[getCurrentWorkTag()];
- this.documentWorkspace.Refresh();
- }
- }
- /// <summary>
- /// 刷新图片效果和数据时调用该方法
- /// </summary>
- /// <param name="applyingToAll"></param>
- private void refreshActionWhileImg_SelectedIndexChanged(bool applyingToAll, int toSelectIndex = -1)
- {
- GSSClass.styleClass.PointKb = 0;//##21997
- this.saveDialogParamValues();
- this.binaryClass.saveMat(this.imageList_img.Images.Keys[this.selectPicture]);
- //备份第一个显示图片的数据信息到dict中
- if (GSSClass.GuideClass.guideDict.Count == 0 && this.selectPicture >= 0 && this.selectPicture < this.imageList_img.Images.Keys.Count
- && !GSSClass.GuideClass.guideDict.ContainsKey(this.imageList_img.Images.Keys[this.selectPicture]))
- GSSClass.GuideClass.guideDict.Add(this.imageList_img.Images.Keys[this.selectPicture], GSSClass.GuideClass.guideModel);
- if (GSSClass.styleClass.styleDict.Count == 0 && this.selectPicture >= 0 && this.selectPicture < this.imageList_img.Images.Keys.Count
- && !GSSClass.styleClass.styleDict.ContainsKey(this.imageList_img.Images.Keys[this.selectPicture]))
- GSSClass.styleClass.styleDict.Add(this.imageList_img.Images.Keys[this.selectPicture], GSSClass.styleClass.styleModel);
- if (GSSClass.standardDict.Count == 0 && this.selectPicture >= 0 && this.selectPicture < this.imageList_img.Images.Keys.Count
- && !GSSClass.standardDict.ContainsKey(this.imageList_img.Images.Keys[this.selectPicture]))
- GSSClass.standardDict.Add(this.imageList_img.Images.Keys[this.selectPicture], GSSClass.standardModel);
- if (toSelectIndex >= 0/*applyingToAll*/)
- this.bitmap = this.appWorkspace.DocumentWorkspaces[toSelectIndex].CompositionSurface.CreateAliasedBitmap();
- else
- this.bitmap = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
- matOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
- string toSelectImageKey = getCurrentWorkTag();
- if (toSelectIndex >= 0)
- toSelectImageKey = this.imageList_img.Images.Keys[toSelectIndex];
- if (!this.analysisDict.ContainsKey(toSelectImageKey))
- this.analysisDict.Add(toSelectImageKey, this.analysisModel.cloneListParamModel(this.menuId));
- //else
- // this.analysisDict[getCurrentWorkTag()] = this.analysisModel.cloneListParamModel(this.menuId);
- this.analysisModel = this.analysisDict[toSelectImageKey];
- bool existGuideModel = true;
- if (!GSSClass.GuideClass.guideDict.ContainsKey(toSelectImageKey))
- {
- if (/*toSelectIndex >= 0 && */GSSClass.GuideClass.guideModel.oldSelectItem == null && this.comboBox1.SelectedItem != null)
- GSSClass.GuideClass.guideModel.oldSelectItem = (string)this.comboBox1.SelectedItem;
- GSSClass.GuideClass.guideDict.Add(toSelectImageKey, GSSClass.GuideClass.guideModel.cloneModel());
- existGuideModel = false;
- }
- GSSClass.GuideClass.guideModel = GSSClass.GuideClass.guideDict[toSelectImageKey];
- if (toSelectIndex >= 0 && this.comboBox1.SelectedItem != null)
- GSSClass.GuideClass.guideModel.oldSelectItem = (string)this.comboBox1.SelectedItem;
- if (!GSSClass.styleClass.styleDict.ContainsKey(toSelectImageKey))
- GSSClass.styleClass.styleDict.Add(toSelectImageKey, GSSClass.styleClass.styleModel.cloneModel());
- GSSClass.styleClass.styleModel = GSSClass.styleClass.styleDict[toSelectImageKey];
- if (!GSSClass.standardDict.ContainsKey(toSelectImageKey))
- GSSClass.standardDict.Add(toSelectImageKey, GSSClass.standardModel.cloneModel());
- GSSClass.standardModel = GSSClass.standardDict[toSelectImageKey];
- //二值化集成4
- if (ShowDrawClassView())
- binaryClass.listView1_SelectedIndexChanged(this.bitmap);
- else
- binaryClass.listView1_SelectedIndexChangedHideDrawClassView(this.bitmap, toSelectImageKey);//###21974
- //晶界重现
- if (this.selectPicture >= 0 && this.selectPicture < this.imageList_img.Images.Keys.Count
- && this.grainBoundaryDict.ContainsKey(this.imageList_img.Images.Keys[this.selectPicture])
- && !this.grainBoundaryDict.ContainsKey(toSelectImageKey))
- {//如果首次切换到该图片,或者点击了应用到全部,则将参数赋值
- this.grainBoundaryDict.Add(toSelectImageKey, this.grainBoundaryDict[this.imageList_img.Images.Keys[this.selectPicture]].cloneModel());
- }
- if (toSelectIndex >= 0/*applyingToAll*/)
- this.selectPicture = toSelectIndex;
- else
- this.selectPicture = this.lstView_img.FocusedItem.Index;
- //选择了应用晶界重现但是没有计算结果,则进行晶界重现的计算
- if (this.grainBoundaryDict.ContainsKey(toSelectImageKey) && this.grainBoundaryDict[toSelectImageKey].grainApplygrainboundaries == 1
- && !this.grainBoundaryMatDict.ContainsKey(toSelectImageKey))
- {
- procClass = new ProgressThreadProcClass();
- procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(applyDectAction), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"));
- }
- if (this.grainBoundaryMatDict.ContainsKey(toSelectImageKey))
- {
- this.documentWorkspace.PhaseModels[1].mat = this.grainBoundaryMatDict[toSelectImageKey].Clone();
- this.documentWorkspace.PhaseModels[1].choise = (!bcOriginChecked() && getGrainBoundryChecked() && ShowGrainBoundryChecked());
- }
- else
- this.documentWorkspace.PhaseModels[1].mat = null;
- if (grainMethodType == 1)
- {
- if (this.grainColorsMatDict.ContainsKey(toSelectImageKey))
- {
- this.documentWorkspace.PhaseModels[2].mat = this.grainColorsMatDict[toSelectImageKey].Clone();
- this.documentWorkspace.PhaseModels[2].choise = (!bcOriginChecked() && ShowGrainColorChecked());
- }
- else
- this.documentWorkspace.PhaseModels[2].mat = null;
- }
- if (existGuideModel && !applyingToAll)//显示已经存在的数据即可,除非(还差应用到全部的信息没有处理),否则不必刷新
- {
- try
- {
- object ItemStringObject;
- if (GetParamValue1(ParamKey_comboBox1SelectedItem, out ItemStringObject))//切换选择的辅助线类型,以及需要备份和读取数据
- {
- this.comboBox1.SelectedIndexChanged -= new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- this.comboBox1.SelectedItem = (string)ItemStringObject;
- comboBox1SelectedItem = comboBox1.SelectedItem;
- this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- }
- }
- catch (Exception exc)
- {
- System.Console.WriteLine("this.comboBox1.SelectedItem: " + exc.ToString());
- }
- this.documentWorkspace.Refresh();
- refreshWhileImgChanged();
- return;
- }
- DocumentWorkspace toSelectDocumentWorkspace = toSelectIndex >= 0 ? this.appWorkspace.DocumentWorkspaces[toSelectIndex] : getCurrentWorkspace();
- if (this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0)
- {
- float recWidth = (float)(Math.Max(1, GSSClass.GuideClass.guideModel.rectangleFLineWidth / getCurrentWorkspace().GetRuler(MeasurementUnit.Micron)));
- float recHeight = (float)(Math.Max(1, GSSClass.GuideClass.guideModel.rectangleFLineHeight / getCurrentWorkspace().GetRuler(MeasurementUnit.Micron)));
- double multiple = 1.0;
- if (recWidth > this.documentWorkspace.CompositionSurface.Width)
- {
- multiple = this.documentWorkspace.CompositionSurface.Width / recWidth;
- }
- if (this.documentWorkspace.CompositionSurface.Height < recHeight * multiple)//#21714
- {
- multiple = this.documentWorkspace.CompositionSurface.Height / recHeight;
- }
- GSSClass.GuideClass.guideModel.rectangleFLineWidth = (float)(multiple * GSSClass.GuideClass.guideModel.rectangleFLineWidth);
- GSSClass.GuideClass.guideModel.rectangleFLineHeight = (float)(multiple * GSSClass.GuideClass.guideModel.rectangleFLineHeight);
- if (grainMethodType == 1)//#21714
- GSSClass.GuideClass.UpdateScaleGuideAreaStyle((this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0 && this.comboBox1.SelectedItem != null) ? this.comboBox1.SelectedItem : "", GSSClass.GuideClass.guideModel
- , multiple);
- else
- GSSClass.GuideClass.UpdateScaleGuideStyle((this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0 && this.comboBox1.SelectedItem != null) ? this.comboBox1.SelectedItem : "", GSSClass.GuideClass.guideModel, recWidth, recHeight
- , toSelectDocumentWorkspace.GetRuler(MeasurementUnit.Micron), multiple);
- }
- GSSClass.GuideClass.guideModel.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
- if (this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0)
- {
- //UpdateGuideStyle(false);
- float recWidth = (float)(Math.Max(1, GSSClass.GuideClass.guideModel.rectangleFLineWidth / toSelectDocumentWorkspace.GetRuler(MeasurementUnit.Micron)));
- float recHeight = (float)(Math.Max(1, GSSClass.GuideClass.guideModel.rectangleFLineHeight / toSelectDocumentWorkspace.GetRuler(MeasurementUnit.Micron)));
- GSSClass.GuideClass.guideModel.RectangleFLine = new RectangleF(GSSClass.GuideClass.guideModel.loctation.X - recWidth/*GSSClass.GuideClass.RectangleFLine.Width*/ / 2
- , GSSClass.GuideClass.guideModel.loctation.Y - recHeight/*GSSClass.GuideClass.RectangleFLine.Height*/ / 2
- , recWidth/*GSSClass.GuideClass.RectangleFLine.Width*/, recHeight/*GSSClass.GuideClass.RectangleFLine.Height*/);
- bool foundItem = false;
- if (grainMethodType == 1)
- {
- if (this.matOrg != null && this.comboBox1.SelectedItem != null)
- GSSClass.GuideClass.updateGuideAreaRectLine(this.comboBox1.SelectedItem, GSSClass.GuideClass.guideModel, out foundItem, true/*guideTypeChanged*/, toSelectDocumentWorkspace.GetRuler(MeasurementUnit.Micron));
- }
- else
- if (this.matOrg != null && this.comboBox1.SelectedItem != null)
- GSSClass.GuideClass.updateGuideRectLine(this.comboBox1.SelectedItem, GSSClass.GuideClass.guideModel, out foundItem, true/*guideTypeChanged*/, toSelectDocumentWorkspace.GetRuler(MeasurementUnit.Micron));
- /////*this.*/
- ////GSSClass.GuideClass.updateRectangleSize(getCurrentWorkspace().GetRuler(MeasurementUnit.Micron)/*physical_Micron*/);
- if (foundItem)
- AddRectangleToRectangleFCaps();
- //this.documentWorkspace.Refresh();
- }
- else
- InitRectangleF(false);
- refreshWhileImgChanged();//#################################################应用到全部时候计算其他图片不需要刷新界面参数信息?
- //InitComboboxValue(null);
- try
- {
- object ItemStringObject;
- if (GetParamValue1(ParamKey_comboBox1SelectedItem, out ItemStringObject))//切换选择的辅助线类型,以及需要备份和读取数据
- this.comboBox1.SelectedItem = (string)ItemStringObject;
- }
- catch (Exception exc)
- {
- System.Console.WriteLine("this.comboBox1.SelectedItem: " + exc.ToString());
- }
- UpdateGuideStyle(!applyingToAll);
- if (this.bitmap != null)
- {
- GSSClass.GuideClass.guideModel.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
- InitRectangleF(true);
- }
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 3D效果,正十四面体预览
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void threeDButton_Click(object sender, EventArgs e)
- {
- if (RegularTetrahedron3D.GetStatus() > 0 && value_111 > 1)
- {
- RegularTetrahedron3D.UpdateRun(Math.Min(value_111, 200));
- return;
- }
- if (value_111 > 1)
- RegularTetrahedron3D.Run(Math.Min(value_111, 200));
- else
- RegularTetrahedron3D.Run(50/*this.appWorkspace*/);
- }
- private void applyDectAction()
- {
- string toSelectImageKey = this.imageList_img.Images.Keys[this.selectPicture];
- OrgImg0 = GrainBoundaryEditingDialog.runDect(grainBoundaryDict[toSelectImageKey].m_iStandardImage, grainBoundaryDict[toSelectImageKey].iConnect, Color.FromArgb(grainBoundaryDict[toSelectImageKey].grainColor) /*Color.Red*//*this.panel1.BackColor*/, OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap)/*matOrg*//*OrgImg*/, grainBoundaryDict[toSelectImageKey].dark, grainBoundaryDict[toSelectImageKey].smooth_type, grainBoundaryDict[toSelectImageKey].sigma, grainBoundaryDict[toSelectImageKey].enhance
- , new double[] { grainBoundaryDict[toSelectImageKey].cell1_size, grainBoundaryDict[toSelectImageKey].cell2_size});
- this.grainBoundaryMatDict.Add(toSelectImageKey, OrgImg0);
- if (procClass != null) procClass.DismissProgressAction(this);
- }
- #region [脚本录制]
- private void getScriptRecording()
- {
- string className = InvariantData.path_Action + ".Action" + menuId;
- ParamObject param = (ParamObject)System.Reflection.Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
- List<Args> args = param.Lists;
- string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel_" + this.menuId + ".xml";
- if (System.IO.File.Exists(xmlFilePath))
- {
- GrainBoundryDectModel = Base.CommTool.XmlSerializeHelper.DESerializer<Base.SettingModel.GrainBoundryDectModel>(Base.CommTool.FileOperationHelper.ReadStringFromFile(xmlFilePath, System.IO.FileMode.Open));
- }
- foreach (var item in args)
- {
- item.value = setScriptRecording(item.key);
- }
- //找出二值相关参数 进行赋值
- List<Args> isNullList = args.Where(m => m.value == null).ToList();
- foreach (var item in isNullList)
- {
- item.value = binaryClass.setScriptRecording(item.key);
- }
- isNullList = args.Where(m => m.value == null).ToList();
- foreach (var item in isNullList)
- {
- item.value = saveRecordingData(item.key);
- }
- appWorkspace.SetScriptStartRecording(this.menuId, menuName, args);
- }
- private object setScriptRecording(string key)
- {
- object value = null;
- switch (key)
- {
- case "ShowGrainNumber":
- value = showGrainNumberChecked();
- break;
- case "ShowGrainColor":
- value = ShowGrainColorChecked();
- break;
- case "displaygrainboundaries":
- value = ShowGrainBoundryChecked();
- break;
- case "displaygrid":
- value = showGridChecked();
- break;
- case "displaysections":
- value = drawDisplaySections();
- break;
- case "comboBox1SelectedItem":
- value = comboBox1SelectedItem;
- break;
- case "CalculatorDecimalDigits":
- value = Convert.ToInt32(this.numericUpDown1_0.Value);
- break;
- case "OpenWhileExportReport":
- value = this.checkBox_generateReport_opensetting.Checked;
- break;
- case "TargetSelection":
- value = this.TargetSelection;
- break;
- case "ExportResults":
- value = false;
- break;
- case "ExportReports":
- value = false;
- break;
- case "ExportProjects":
- value = false;
- break;
- case "GrainApplygrainboundaries":
- value = GrainBoundryDectModel == null ? 0 : GrainBoundryDectModel.grainApplygrainboundaries;
- break;
- case "lineColor":
- value = GrainBoundryDectModel == null ? Color.Red.ToArgb() : GrainBoundryDectModel.grainColor;
- break;
- case "GrainIConnect":
- value = GrainBoundryDectModel == null ? 0 : GrainBoundryDectModel.iConnect;
- break;
- case "GrainDisplaysections":
- value = GrainBoundryDectModel == null ? false : GrainBoundryDectModel.enhance == 1 ? true : false;
- break;
- case "GrainSigma":
- value = GrainBoundryDectModel == null ? 0 : GrainBoundryDectModel.sigma;
- break;
- case "GrainCell_size1":
- value = GrainBoundryDectModel == null ? new List<double>() { 0, 0 } : new List<double>() { GrainBoundryDectModel.cell1_size, GrainBoundryDectModel.cell2_size };
- break;
- case "GrainDark":
- value = GrainBoundryDectModel == null ? 0 : GrainBoundryDectModel.dark;
- break;
- case "GrainSmooth_type":
- value = GrainBoundryDectModel == null ? 0 : GrainBoundryDectModel.smooth_type;
- break;
- case "GrainM_iStandardImage":
- value = GrainBoundryDectModel == null ? 0 : GrainBoundryDectModel.m_iStandardImage;
- break;
- }
- return value;
- }
- #endregion
- }
- }
|