AppWorkspace.cs 220 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183
  1. using IWshRuntimeLibrary;
  2. using Metis.Measuring;
  3. using PaintDotNet.Actions;
  4. using PaintDotNet.Annotation;
  5. using PaintDotNet.Annotation.Enum;
  6. using PaintDotNet.Base;
  7. using PaintDotNet.Base.CommTool;
  8. using PaintDotNet.Base.Functionodel;
  9. using PaintDotNet.Base.SettingModel;
  10. using PaintDotNet.CustomControl;
  11. using PaintDotNet.DbOpreate.DbBll;
  12. using PaintDotNet.DbOpreate.DbModel;
  13. using PaintDotNet.DedicatedAnalysis.DuctileIron.Common;
  14. using PaintDotNet.ImageCollect;
  15. using PaintDotNet.ImageLabel;
  16. using PaintDotNet.Instrument;
  17. using PaintDotNet.Measuring;
  18. using PaintDotNet.SystemLayer;
  19. using System;
  20. using System.Collections.Generic;
  21. using System.ComponentModel;
  22. using System.Drawing;
  23. using System.Drawing.Drawing2D;
  24. using System.Drawing.Imaging;
  25. using System.Globalization;
  26. using System.IO;
  27. using System.Windows.Forms;
  28. using static PaintDotNet.Base.Functionodel.ZipXmlModel;
  29. using MSWord = Microsoft.Office.Interop.Word;
  30. using MSExcel = Microsoft.Office.Interop.Excel;
  31. namespace PaintDotNet
  32. {
  33. internal class AppWorkspace : UserControl, ISnapObstacleHost, IAppWorkspaceForSurfaceBox
  34. {
  35. #region 控件
  36. /// <summary>
  37. /// 顶部菜单和工具栏
  38. /// </summary>
  39. public PdnToolBar toolBar;
  40. /// <summary>
  41. /// 底部公用工具栏
  42. /// </summary>
  43. private PanelBottom panelBottom;
  44. /// <summary>
  45. /// 主界面左侧的快捷工具栏
  46. /// </summary>
  47. public ToolsControl toolsPanel;
  48. /// <summary>
  49. /// 包含DocumentWorkspace集合的panel
  50. /// </summary>
  51. public Panel workspacePanel;
  52. /// <summary>
  53. /// 底部状态栏
  54. /// </summary>
  55. private PdnStatusBar statusBar;
  56. /// <summary>
  57. /// 要删除的工作空间位置(避免批量保存有修改的图片时关闭的工作空间位置与for循环顺序不一致)
  58. /// </summary>
  59. public int toRemoveDocumentWorkspaceIndex = -1;
  60. /// <summary>
  61. /// 图像索引窗口控制状态 -1代表activeDocumentWorkspace无变化 1、2代表进行了添加或者删除操作,需要刷新图像索引窗口内容
  62. /// </summary>
  63. public int toInitImageIndexDialogFlag = -1;
  64. /// <summary>
  65. /// 当前激活的工作空间
  66. /// </summary>
  67. private DocumentWorkspace activeDocumentWorkspace;
  68. /// <summary>
  69. /// 如果添加了新的工作空间,并且该工作空间没有被修改,则将其删除。
  70. /// 这将通过CreateBlankDocumentInNewWorkspace添加的最后一个工作空间确定
  71. /// (如果为第二个参数传递了true)
  72. /// </summary>
  73. private DocumentWorkspace initialWorkspace;
  74. /// <summary>
  75. /// 标尺标定窗口
  76. /// </summary>
  77. private RuleListForm ruleListForm;
  78. /// <summary>
  79. /// 像素跟踪窗口
  80. /// </summary>
  81. private PixelTrackingDialog pixelTrackingDialog;
  82. /// <summary>
  83. /// 图像索引窗口
  84. /// </summary>
  85. private ImageIndexDialog imageIndexDialog;
  86. /// <summary>
  87. /// 交互测量
  88. /// </summary>
  89. private GeometryMeasureDialog geometryMeasureDialog;
  90. /// <summary>
  91. /// 脚本执行跟踪窗口
  92. /// </summary>
  93. private ScriptRunningDialog runningDialog;
  94. /// <summary>
  95. /// 直方图窗口
  96. /// </summary>
  97. private HistogramDialog histogramDialog;
  98. /// <summary>
  99. /// 脚本管理窗口
  100. /// </summary>
  101. private ScriptManageDialog scriptManageDialog;
  102. /// <summary>
  103. /// 划痕处理窗口
  104. /// </summary>
  105. private ScratchTreatmentDialog scratchTreatmentDialog;
  106. /// <summary>
  107. /// 污迹处理窗口
  108. /// </summary>
  109. private SmudgeTreatmentDialog smudgeTreatmentDialog;
  110. /// <summary>
  111. /// 标注列表窗口
  112. /// </summary>
  113. private LabelListDialog labelListDialog;
  114. /// <summary>
  115. /// 工作流程窗口
  116. /// </summary>
  117. public WorkFlowDialog workFlowDialog;
  118. /// <summary>
  119. /// 测量列表窗口
  120. /// </summary>
  121. public MeasureListDialog measureListDialog;
  122. /// <summary>
  123. /// 光密度窗口
  124. /// </summary>
  125. public OpticalDensityDialog opticalDensityDialog;
  126. /// <summary>
  127. /// 项目工程窗口
  128. /// </summary>
  129. public ProjectEngineering projectEngineering;
  130. /// <summary>
  131. /// 图像预览窗口
  132. /// </summary>
  133. public CameraPreviewDialog cameraPreviewDialog;
  134. #endregion
  135. /// <summary>
  136. /// 工作空间集合,打开的图像
  137. /// </summary>
  138. private List<DocumentWorkspace> documentWorkspaces = new List<DocumentWorkspace>();
  139. /// <summary>
  140. /// 保存了许多可浮动的窗口,为了统一管理,供外部调用
  141. /// </summary>
  142. private WorkspaceWidgets widgets;
  143. /// <summary>
  144. /// 最近打开的文件
  145. /// </summary>
  146. private MostRecentFiles mostRecentFiles = null;
  147. /// <summary>
  148. /// 最近打开的文件的最大默认数量
  149. /// </summary>
  150. private const int defaultMostRecentFilesMax = 8;
  151. private SnapObstacleController snapObstacle;
  152. private bool addedToSnapManager = false;
  153. private int ignoreUpdateSnapObstacle = 0;
  154. //private XmlSaveModel xmlSaveModel;
  155. /// <summary>
  156. /// 是否循环播放
  157. /// </summary>
  158. private bool isLoopPlayback = false;
  159. /// <summary>
  160. /// 播放模式 1.后到前;2.前到后
  161. /// </summary>
  162. private int playMode = 2;
  163. /// <summary>
  164. /// 播放使用的定时器
  165. /// </summary>
  166. private Timer timer;
  167. /// <summary>
  168. /// 锁定扩缩标记
  169. /// </summary>
  170. public bool isLockZoom = false;
  171. /// <summary>
  172. /// 锁定扩缩的百分比
  173. /// </summary>
  174. public double lockScaleRatio = 0;
  175. /// <summary>
  176. /// 当前是否自动运行着脚本
  177. /// </summary>
  178. private bool scriptAutomatic = false;
  179. /// <summary>
  180. /// 当前是否运行着脚本
  181. /// </summary>
  182. private bool scriptRunning = false;
  183. /// <summary>
  184. /// 当前是否等待着脚本继续执行
  185. /// </summary>
  186. private bool scriptStopping = false;
  187. private Form form;
  188. /// <summary>
  189. /// 测量连续绘制
  190. /// </summary>
  191. public bool continuousDrawingMeasure = false;
  192. /// <summary>
  193. /// 标记连续绘制
  194. /// </summary>
  195. public bool continuousDrawingLabel = false;
  196. public DrawToolType drawToolType = DrawToolType.Pointer;
  197. /// <summary>
  198. /// 录制脚本时带入的
  199. /// </summary>
  200. public List<mic_script_step> micScriptStepList = new List<mic_script_step>();
  201. public Dictionary<mic_script_step, List<Args>> micScriptStepParamList = new Dictionary<mic_script_step, List<Args>>();
  202. /// <summary>
  203. /// 录制脚本时添加的
  204. /// </summary>
  205. public List<mic_script_step> addMicScriptStepList = new List<mic_script_step>();
  206. public Dictionary<mic_script_step, List<Args>> addMicScriptStepParamList = new Dictionary<mic_script_step, List<Args>>();
  207. /// <summary>
  208. /// 是否开启脚本录制
  209. /// </summary>
  210. public bool startScriptRecording = false;
  211. /// <summary>
  212. /// 脚本录制是否编辑
  213. /// </summary>
  214. public bool editScriptRecording = false;
  215. /// <summary>
  216. /// 脚本录制是否编辑
  217. /// </summary>
  218. public mic_script ScriptRecordingModel;
  219. public PanelBottom PanelBottom
  220. {
  221. get
  222. {
  223. return this.panelBottom;
  224. }
  225. }
  226. public bool ScriptAutomatic
  227. {
  228. get
  229. {
  230. return this.scriptAutomatic;
  231. }
  232. set
  233. {
  234. this.scriptAutomatic = value;
  235. }
  236. }
  237. public bool ScriptRunning
  238. {
  239. get
  240. {
  241. return this.scriptRunning;
  242. }
  243. set
  244. {
  245. this.scriptRunning = value;
  246. }
  247. }
  248. public void SetScriptRunning(Boolean value)
  249. {
  250. this.scriptRunning = value;
  251. }
  252. public bool GetScriptRunning()
  253. {
  254. return this.scriptRunning;
  255. }
  256. public bool ScriptStopping
  257. {
  258. get
  259. {
  260. return this.scriptStopping;
  261. }
  262. set
  263. {
  264. this.scriptStopping = value;
  265. //if (value == false)
  266. // this.ResumeScriptRunning();
  267. }
  268. }
  269. public void SetScriptStopping(Boolean value)
  270. {
  271. this.ScriptStopping = value;
  272. }
  273. public bool GetScriptStopping()
  274. {
  275. return this.scriptStopping;
  276. }
  277. public Data.Param.ParamObject ScriptCurrentParam
  278. {
  279. set
  280. {
  281. if (this.ScriptDialog != null) this.ScriptDialog.ScriptCurrentParam = value;
  282. }
  283. get
  284. {
  285. if (this.ScriptDialog != null) return this.ScriptDialog.ScriptCurrentParam;
  286. else return null;
  287. }
  288. }
  289. public void ShutDownScriptRunning()
  290. {
  291. if (this.ScriptDialog != null) this.ScriptDialog.ShutDownScriptRunning();
  292. }
  293. public void ResumeScriptRunning()
  294. {
  295. if (this.ScriptDialog != null/* && !this.ScriptDialog.IsDisposed*/) this.ScriptDialog.ResumeScriptRunning();
  296. }
  297. private void DocumentWorkspace_DrawGridChanged(object sender, EventArgs e)
  298. {
  299. DrawGrid = this.activeDocumentWorkspace.DrawGrid;
  300. }
  301. /*private void ViewConfigStrip_DrawGridChanged(object sender, EventArgs e)
  302. {
  303. DrawGrid = ((ViewConfigStrip)sender).DrawGrid;
  304. }*/
  305. /// <summary>
  306. /// 绘制像素网格的flag
  307. /// </summary>
  308. private bool DrawGrid
  309. {
  310. get
  311. {
  312. return false;// this.Widgets.ViewConfigStrip.DrawGrid;
  313. }
  314. set
  315. {
  316. if (this.Widgets.ViewConfigStrip.DrawGrid != value)
  317. {
  318. this.Widgets.ViewConfigStrip.DrawGrid = value;
  319. }
  320. if (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.DrawGrid != value)
  321. {
  322. this.activeDocumentWorkspace.DrawGrid = value;
  323. }
  324. Settings.CurrentUser.SetBoolean(SettingNames.DrawGrid, this.DrawGrid);
  325. }
  326. }
  327. /// <summary>
  328. /// 单位改变事件
  329. /// </summary>
  330. public event EventHandler UnitsChanged;
  331. protected virtual void OnUnitsChanged()
  332. {
  333. if (UnitsChanged != null)
  334. {
  335. UnitsChanged(this, EventArgs.Empty);
  336. }
  337. }
  338. public MeasurementUnit Units
  339. {
  340. get
  341. {
  342. return Startup.instance.measurementUnit;//this.widgets.ViewConfigStrip.Units;
  343. }
  344. set
  345. {
  346. //this.widgets.ViewConfigStrip.Units = value;
  347. }
  348. }
  349. public SnapObstacle SnapObstacle
  350. {
  351. get
  352. {
  353. if (this.snapObstacle == null)
  354. {
  355. this.snapObstacle = new SnapObstacleController(
  356. this.Name,
  357. Rectangle.Empty,
  358. SnapRegion.Interior,
  359. true);
  360. this.snapObstacle.EnableSave = false;
  361. PdnBaseForm pdbForm = FindForm() as PdnBaseForm;
  362. pdbForm.Moving += new MovingEventHandler(ParentForm_Moving);
  363. pdbForm.Move += new EventHandler(ParentForm_Move);
  364. pdbForm.ResizeEnd += new EventHandler(ParentForm_ResizeEnd);
  365. pdbForm.Layout += new LayoutEventHandler(ParentForm_Layout);
  366. pdbForm.SizeChanged += new EventHandler(ParentForm_SizeChanged);
  367. UpdateSnapObstacle();
  368. }
  369. return this.snapObstacle;
  370. }
  371. }
  372. private void ParentForm_Move(object sender, EventArgs e)
  373. {
  374. UpdateSnapObstacle();
  375. }
  376. private void ParentForm_SizeChanged(object sender, EventArgs e)
  377. {
  378. UpdateSnapObstacle();
  379. }
  380. private void ParentForm_Layout(object sender, LayoutEventArgs e)
  381. {
  382. UpdateSnapObstacle();
  383. }
  384. private void ParentForm_ResizeEnd(object sender, EventArgs e)
  385. {
  386. UpdateSnapObstacle();
  387. }
  388. private void ParentForm_Moving(object sender, MovingEventArgs e)
  389. {
  390. UpdateSnapObstacle();
  391. }
  392. private void SuspendUpdateSnapObstacle()
  393. {
  394. ++this.ignoreUpdateSnapObstacle;
  395. }
  396. private void ResumeUpdateSnapObstacle()
  397. {
  398. --this.ignoreUpdateSnapObstacle;
  399. }
  400. /// <summary>
  401. /// 更新快照
  402. /// </summary>
  403. private void UpdateSnapObstacle()
  404. {
  405. if (this.ignoreUpdateSnapObstacle > 0)
  406. {
  407. return;
  408. }
  409. if (this.snapObstacle == null)
  410. {
  411. return;
  412. }
  413. if (!this.addedToSnapManager)
  414. {
  415. SnapManager sm = SnapManager.FindMySnapManager(this);
  416. if (sm != null)
  417. {
  418. SnapObstacle so = this.SnapObstacle;
  419. if (!this.addedToSnapManager)
  420. {
  421. sm.AddSnapObstacle(this.SnapObstacle);
  422. this.addedToSnapManager = true;
  423. FindForm().Shown += new EventHandler(AppWorkspace_Shown);
  424. }
  425. }
  426. }
  427. if (this.snapObstacle != null)
  428. {
  429. Rectangle clientRect;
  430. if (ActiveDocumentWorkspace != null)
  431. {
  432. clientRect = ActiveDocumentWorkspace.VisibleViewRectangle;
  433. }
  434. else
  435. {
  436. clientRect = this.workspacePanel.ClientRectangle;
  437. }
  438. Rectangle screenRect = this.workspacePanel.RectangleToScreen(clientRect);
  439. this.snapObstacle.SetBounds(screenRect);
  440. this.snapObstacle.Enabled = this.Visible && this.Enabled;
  441. try
  442. {
  443. //this.ActiveDocumentWorkspace.PanelBottom.documentStrip.Width = screenRect.Width - this.ActiveDocumentWorkspace.PanelBottom.locationX;
  444. }
  445. catch (Exception)
  446. {
  447. // throw;
  448. }
  449. }
  450. }
  451. private void AppWorkspace_Shown(object sender, EventArgs e)
  452. {
  453. UpdateSnapObstacle();
  454. }
  455. protected override void OnLayout(LayoutEventArgs levent)
  456. {
  457. UpdateSnapObstacle();
  458. base.OnLayout(levent);
  459. }
  460. protected override void OnLocationChanged(EventArgs e)
  461. {
  462. UpdateSnapObstacle();
  463. base.OnLocationChanged(e);
  464. }
  465. protected override void OnSizeChanged(EventArgs e)
  466. {
  467. UpdateSnapObstacle();
  468. base.OnSizeChanged(e);
  469. }
  470. protected override void OnEnabledChanged(EventArgs e)
  471. {
  472. UpdateSnapObstacle();
  473. base.OnEnabledChanged(e);
  474. }
  475. protected override void OnVisibleChanged(EventArgs e)
  476. {
  477. UpdateSnapObstacle();
  478. base.OnVisibleChanged(e);
  479. }
  480. public void ResetFloatingForms()
  481. {
  482. ResetFloatingForm(Widgets.RuleListForm);
  483. ResetFloatingForm(Widgets.PixelTrackingDialog);
  484. ResetFloatingForm(Widgets.ImageIndexDialog);
  485. ResetFloatingForm(Widgets.GeometryMeasureDialog);
  486. ResetFloatingForm(Widgets.RunningDialog);
  487. ResetFloatingForm(Widgets.HistogramDialog);
  488. ResetFloatingForm(Widgets.ScratchTreatmentDialog);
  489. ResetFloatingForm(Widgets.SmudgeTreatmentDialog);
  490. ResetFloatingForm(Widgets.LabelListDialog);
  491. ResetFloatingForm(Widgets.WorkFlowDialog);
  492. ResetFloatingForm(Widgets.MeasureListDialog);
  493. ResetFloatingForm(Widgets.OpticalDensityDialog);
  494. ResetFloatingForm(Widgets.ProjectEngineering);
  495. }
  496. public void ResetFloatingForm(FloatingToolForm ftf)
  497. {
  498. SnapManager sm = SnapManager.FindMySnapManager(this);
  499. if (ftf == Widgets.RuleListForm)
  500. {
  501. sm.ParkObstacle(Widgets.RuleListForm, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  502. }
  503. else if (ftf == Widgets.PixelTrackingDialog)
  504. {
  505. sm.ParkObstacle(Widgets.PixelTrackingDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  506. }
  507. else if (ftf == Widgets.ImageIndexDialog)
  508. {
  509. sm.ParkObstacle(Widgets.ImageIndexDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  510. }
  511. else if (ftf == Widgets.GeometryMeasureDialog)
  512. {
  513. sm.ParkObstacle(Widgets.GeometryMeasureDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  514. }
  515. else if (ftf == Widgets.RunningDialog)
  516. {
  517. sm.ParkObstacle(Widgets.RunningDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
  518. }
  519. else if (ftf == Widgets.HistogramDialog)
  520. {
  521. sm.ParkObstacle(Widgets.HistogramDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
  522. }
  523. else if (ftf == Widgets.ScratchTreatmentDialog)
  524. {
  525. sm.ParkObstacle(Widgets.ScratchTreatmentDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
  526. }
  527. else if (ftf == Widgets.SmudgeTreatmentDialog)
  528. {
  529. sm.ParkObstacle(Widgets.SmudgeTreatmentDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
  530. }
  531. else if (ftf == Widgets.LabelListDialog)
  532. {
  533. sm.ParkObstacle(Widgets.LabelListDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
  534. }
  535. else if (ftf == Widgets.WorkFlowDialog)
  536. {
  537. sm.ParkObstacle(Widgets.WorkFlowDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  538. }
  539. else if (ftf == Widgets.MeasureListDialog)
  540. {
  541. sm.ParkObstacle(Widgets.MeasureListDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  542. }
  543. else if (ftf == Widgets.OpticalDensityDialog)
  544. {
  545. sm.ParkObstacle(Widgets.OpticalDensityDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  546. }
  547. else if (ftf == Widgets.ProjectEngineering)
  548. {
  549. sm.ParkObstacle(Widgets.ProjectEngineering, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  550. }
  551. else
  552. {
  553. throw new ArgumentException();
  554. }
  555. }
  556. public PdnToolBar ToolBar
  557. {
  558. get
  559. {
  560. return this.toolBar;
  561. }
  562. }
  563. public MostRecentFiles MostRecentFiles
  564. {
  565. get
  566. {
  567. if (this.mostRecentFiles == null)
  568. {
  569. this.mostRecentFiles = new MostRecentFiles(defaultMostRecentFilesMax);
  570. }
  571. return this.mostRecentFiles;
  572. }
  573. }
  574. private void DocumentWorkspace_DocumentChanging(object sender, EventArgs<Document> e)
  575. {
  576. UI.SuspendControlPainting(this);
  577. }
  578. private void DocumentWorkspace_DocumentChanged(object sender, EventArgs e)
  579. {
  580. UpdateDocInfoInStatusBar();
  581. this.UpdatePixelTracking();
  582. UI.ResumeControlPainting(this);
  583. Invalidate(true);
  584. }
  585. private void CoordinatesToStrings(int x, int y, out string xString, out string yString, out string unitsString)
  586. {
  587. this.activeDocumentWorkspace.Document.CoordinatesToStrings(this.Units, x, y, out xString, out yString, out unitsString);
  588. }
  589. /// <summary>
  590. /// 更新右下角坐标信息
  591. /// </summary>
  592. /// <param name="cursorX"></param>
  593. /// <param name="cursorY"></param>
  594. private void UpdateCursorInfoInStatusBar(int cursorX, int cursorY)
  595. {
  596. SuspendLayout();
  597. if (this.activeDocumentWorkspace == null ||
  598. this.activeDocumentWorkspace.Document == null)
  599. {
  600. this.statusBar.CursorInfoText = string.Empty;
  601. }
  602. else
  603. {
  604. string xString;
  605. string yString;
  606. string units;
  607. CoordinatesToStrings(cursorX, cursorY, out xString, out yString, out units);
  608. string cursorText = string.Format(
  609. CultureInfo.InvariantCulture,
  610. PdnResources.GetString("StatusBar.CursorInfo.Format"),
  611. xString,
  612. units,
  613. yString,
  614. units);
  615. //this.statusBar.CursorInfoText = cursorText;
  616. }
  617. ResumeLayout(false);
  618. }
  619. /// <summary>
  620. /// 更新底部状态栏的文字等
  621. /// 需要修改为显示标尺相关的信息
  622. /// </summary>
  623. public void UpdateDocInfoInStatusBar()
  624. {
  625. if (this.activeDocumentWorkspace != null)
  626. {
  627. if (this.activeDocumentWorkspace.xmlSaveModel == null)
  628. {
  629. this.statusBar.ImageInfoStatusText = PdnResources.GetString("Menu.Unselectedruler.Text");
  630. this.statusBar.CursorInfoText = PdnResources.GetString("Menu.Defaultis1micron/pixel.Text");
  631. }
  632. else
  633. {
  634. //选中图片是否有配置文件
  635. if ((ExistenceXML() && this.activeDocumentWorkspace.xmlSaveModel.pixel_length != 0) || (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.xmlSaveModel != null && this.activeDocumentWorkspace.xmlSaveModel.pixel_length != 0))
  636. {
  637. this.statusBar.ImageInfoStatusText = this.activeDocumentWorkspace.xmlSaveModel.ruler_name;
  638. double unitLength = (double)(this.activeDocumentWorkspace.xmlSaveModel.physical_length / (decimal)this.activeDocumentWorkspace.xmlSaveModel.pixel_length);
  639. this.statusBar.CursorInfoText = Math.Round(unitLength, 4) + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), this.activeDocumentWorkspace.xmlSaveModel.ruler_units)))].ToString() + "/" + PdnResources.GetString("Menu.Pixel.text");
  640. }
  641. else
  642. {
  643. this.statusBar.ImageInfoStatusText = Startup.instance.ruleDB.ruler_name;
  644. this.statusBar.CursorInfoText = Math.Round(Startup.instance.rules[(MeasurementUnit)Startup.instance.ruleDB.ruler_units], 4) + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), Startup.instance.ruleDB.ruler_units)))].ToString() + "/" + PdnResources.GetString("Menu.Pixel.text");
  645. }
  646. }
  647. }
  648. /*if (this.activeDocumentWorkspace == null ||
  649. this.activeDocumentWorkspace.Document == null)
  650. {
  651. this.statusBar.ImageInfoStatusText = string.Empty;
  652. }
  653. else if (this.activeDocumentWorkspace != null &&
  654. this.activeDocumentWorkspace.Document != null)
  655. {
  656. string widthString;
  657. string heightString;
  658. string units;
  659. CoordinatesToStrings(
  660. this.activeDocumentWorkspace.Document.Width,
  661. this.activeDocumentWorkspace.Document.Height,
  662. out widthString,
  663. out heightString,
  664. out units);
  665. string imageText = string.Format(
  666. CultureInfo.InvariantCulture,
  667. this.imageInfoStatusBarFormat,
  668. widthString,
  669. units,
  670. heightString,
  671. units);
  672. this.statusBar.ImageInfoStatusText = imageText;
  673. }*/
  674. }
  675. /// <summary>
  676. /// 更新像素跟踪的图像
  677. /// </summary>
  678. private void UpdatePixelTracking()
  679. {
  680. if (this.pixelTrackingDialog != null)
  681. {
  682. this.pixelTrackingDialog.Mat = null;
  683. }
  684. }
  685. [Browsable(false)]
  686. public WorkspaceWidgets Widgets
  687. {
  688. get
  689. {
  690. return this.widgets;
  691. }
  692. }
  693. public HistogramDialog Histogram
  694. {
  695. get
  696. {
  697. if (this.histogramDialog != null)
  698. {
  699. return this.histogramDialog;
  700. }
  701. else
  702. {
  703. return null;
  704. }
  705. }
  706. }
  707. public ScriptManageDialog ScriptDialog
  708. {
  709. get
  710. {
  711. if (this.scriptManageDialog != null)
  712. {
  713. return this.scriptManageDialog;
  714. }
  715. else
  716. {
  717. return null;
  718. }
  719. }
  720. set
  721. {
  722. this.scriptManageDialog = value;
  723. }
  724. }
  725. public SmudgeTreatmentDialog SmudgeTreatmentDialog
  726. {
  727. get
  728. {
  729. if (this.smudgeTreatmentDialog != null)
  730. {
  731. return this.smudgeTreatmentDialog;
  732. }
  733. else
  734. {
  735. return null;
  736. }
  737. }
  738. set
  739. {
  740. this.smudgeTreatmentDialog = value;
  741. }
  742. }
  743. public ScratchTreatmentDialog ScratchTreatmentDialog
  744. {
  745. get
  746. {
  747. if (this.scratchTreatmentDialog != null)
  748. {
  749. return this.scratchTreatmentDialog;
  750. }
  751. else
  752. {
  753. return null;
  754. }
  755. }
  756. set
  757. {
  758. this.scratchTreatmentDialog = value;
  759. }
  760. }
  761. [Browsable(false)]
  762. public DocumentWorkspace[] ScriptWorkspaces
  763. {
  764. get
  765. {
  766. List<DocumentWorkspace> scriptWorkspaces = new List<DocumentWorkspace>();
  767. for (int index = 0; index < this.documentWorkspaces.Count; index++)
  768. {
  769. DocumentWorkspace workspace = this.documentWorkspaces[index];
  770. if (workspace.OpenInScriptRunning)
  771. {
  772. scriptWorkspaces.Add(workspace);
  773. }
  774. }
  775. if (scriptWorkspaces.Count > 0)
  776. return scriptWorkspaces.ToArray();
  777. else
  778. return null;
  779. }
  780. }
  781. public bool ContinuousDrawing
  782. {
  783. get => DocumentView.ContinuousDrawing;
  784. set
  785. {
  786. DocumentView.ContinuousDrawing = value;
  787. toolBar.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingMeasure");
  788. toolsPanel.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingMeasure");
  789. toolBar.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingLabel");
  790. toolsPanel.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingLabel");
  791. if (ActiveDocumentWorkspace != null && !DocumentView.ContinuousDrawing
  792. && ActiveDocumentWorkspace.ActiveTool >= DrawToolType.MeasureLine && ActiveDocumentWorkspace.ActiveTool <= DrawToolType.MeasureThreePointArc)
  793. {
  794. ActiveDocumentWorkspace.ToolNumber = -1;
  795. ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
  796. }
  797. toolBar.MainMenu.measureActionMenu.checkMenu(DocumentView.ContinuousDrawing);
  798. toolBar.MainMenu.labelActionMenu.checkMenu(DocumentView.ContinuousDrawing);
  799. if (cameraPreviewDialog != null && !cameraPreviewDialog.IsDisposed)
  800. {
  801. if (!DocumentView.ContinuousDrawing)
  802. {
  803. cameraPreviewDialog.documentWorkspace.ActiveTool = DrawToolType.Pointer;
  804. }
  805. if (ActiveDocumentWorkspace != null
  806. && ActiveDocumentWorkspace.ActiveTool >= DrawToolType.MeasureLine
  807. && ActiveDocumentWorkspace.ActiveTool <= DrawToolType.MeasureThreePointArc)
  808. {
  809. ActiveDocumentWorkspace.ToolNumber = -1;
  810. }
  811. }
  812. }
  813. }
  814. public DocumentWorkspace ActiveDocumentWorkspace
  815. {
  816. get
  817. {
  818. return this.activeDocumentWorkspace;
  819. }
  820. set
  821. {
  822. if (this.activeDocumentWorkspace != null)
  823. {
  824. drawToolType = this.activeDocumentWorkspace.ActiveTool;
  825. }
  826. if (value != this.activeDocumentWorkspace)
  827. {
  828. if (value != null &&
  829. this.documentWorkspaces.IndexOf(value) == -1)
  830. {
  831. throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
  832. }
  833. bool focused = false;
  834. if (this.activeDocumentWorkspace != null)
  835. {
  836. focused = this.activeDocumentWorkspace.Focused;
  837. }
  838. UI.SuspendControlPainting(this);
  839. OnActiveDocumentWorkspaceChanging();
  840. this.activeDocumentWorkspace = value;
  841. if (this.toInitImageIndexDialogFlag != 2)
  842. {
  843. this.toInitImageIndexDialogFlag = 1;
  844. }
  845. OnActiveDocumentWorkspaceChanged();
  846. this.toInitImageIndexDialogFlag = -1;
  847. UI.ResumeControlPainting(this);
  848. if (this.ContinuousDrawing && value != null)
  849. {
  850. value.ActiveTool = drawToolType;
  851. }
  852. Refresh();
  853. if (value != null)
  854. {
  855. value.Focus();
  856. }
  857. //if (this.histogramDialog != null) this.histogramDialog.ResetMat();
  858. //backupImage
  859. if (value != null && value.needBackup)
  860. {
  861. FileOperationHelper.BackupImages(value.CompositionSurface.CreateAliasedBitmap(), value.GetFriendlyName(), value.FilePath);
  862. value.needBackup = false;
  863. }
  864. }
  865. }
  866. }
  867. private void ActiveDocumentWorkspace_FirstInputAfterGotFocus(object sender, EventArgs e)
  868. {
  869. this.toolBar.DocumentStrip.EnsureItemFullyVisible(this.toolBar.DocumentStrip.SelectedDocumentIndex);
  870. }
  871. public DocumentWorkspace[] DocumentWorkspaces
  872. {
  873. get
  874. {
  875. return this.documentWorkspaces.ToArray();
  876. }
  877. }
  878. public DocumentWorkspace AddNewDocumentWorkspace()
  879. {
  880. if (this.initialWorkspace != null)
  881. {
  882. if (this.initialWorkspace.Document == null || !this.initialWorkspace.Document.Dirty)
  883. {
  884. RemoveDocumentWorkspace(this.initialWorkspace);
  885. this.initialWorkspace = null;
  886. }
  887. }
  888. DocumentWorkspace dw = new DocumentWorkspace(this);
  889. dw.AppWorkspace = this;
  890. dw.ContinuousDrawingLabel = this.ContinuousDrawing;
  891. dw.ContinuousDrawingMeasure = this.ContinuousDrawing;
  892. if (this.drawToolType == DrawToolType.DrawAutoRuler || this.drawToolType == DrawToolType.DrawPrestoredRuler || this.drawToolType == DrawToolType.DrawDateMark || this.drawToolType == DrawToolType.DrawTimeMark || this.drawToolType == DrawToolType.DrawGainNumber)
  893. {
  894. dw.ActiveTool = DrawToolType.Pointer;
  895. }
  896. else {
  897. dw.ActiveTool = this.drawToolType;
  898. }
  899. this.documentWorkspaces.Add(dw);
  900. this.toolBar.DocumentStrip.AddDocumentWorkspace(dw);
  901. return dw;
  902. }
  903. public DocumentWorkspace NewDocumentWorkspace()
  904. {
  905. if (this.initialWorkspace != null)
  906. {
  907. if (this.initialWorkspace.Document == null || !this.initialWorkspace.Document.Dirty)
  908. {
  909. RemoveDocumentWorkspace(this.initialWorkspace);
  910. this.initialWorkspace = null;
  911. }
  912. }
  913. DocumentWorkspace dw = new DocumentWorkspace(this);
  914. dw.AppWorkspace = this;
  915. dw.ContinuousDrawingLabel = this.continuousDrawingLabel;
  916. dw.ContinuousDrawingMeasure = this.continuousDrawingMeasure;
  917. return dw;
  918. }
  919. public bool DisplayShoot(Bitmap image, GraphicsList graphicsList, bool hasRuler, int mode = 0)
  920. {
  921. if (Widgets.ImageIndexDialog.Visible)
  922. {
  923. Startup.instance.configModel.Txt1 = Widgets.ImageIndexDialog.comboBox_T1.Text;
  924. Startup.instance.configModel.Txt2 = Widgets.ImageIndexDialog.comboBox_T2.Text;
  925. Startup.instance.configModel.Txt3 = Widgets.ImageIndexDialog.comboBox_T2.Text;
  926. }
  927. string photoName;
  928. if (Startup.instance.ruleDB == null)
  929. {
  930. photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, "默认标尺", "0", mode);
  931. }
  932. else
  933. {
  934. photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, Startup.instance.ruleDB.ruler_name, Startup.instance.ruleDB.gain_multiple.ToString(), mode);
  935. }
  936. UpdateContinueNum();
  937. Widgets.ImageIndexDialog.PreviewRefresh();
  938. DocumentWorkspace dw = NewDocumentWorkspace();
  939. dw.fileText = photoName;
  940. Document document = Document.FromMat(PaintDotNet.Camera.Tools.ToMat(image));
  941. document.Dirty = true;
  942. dw.Document = document;
  943. //dw.rules = new Dictionary<MeasurementUnit, double>(Startup.instance.rules);
  944. dw.xmlSaveModel = Startup.instance.ruleDB;
  945. dw.InitRulerInfo(); //激活
  946. //如果绘制了标注、测量,则需要深度copy过去
  947. if (graphicsList?.Count > 0)
  948. {
  949. for (int i = 0; i < graphicsList.Count; i++)
  950. {
  951. DrawObject mobject = graphicsList[i].Clone(dw);
  952. mobject.Selected = false;
  953. dw.GraphicsList.Add(mobject);
  954. }
  955. }
  956. //绘制标尺
  957. if (hasRuler)
  958. {
  959. bool needResetDB = false;
  960. decimal oldGainNumber = dw.GetGainMultiple();
  961. Dictionary<MeasurementUnit, double> measurementUnitDictionary = this.getMeasureInfo();
  962. MeasurementUnit unit = this.Units;
  963. double oldRatio = measurementUnitDictionary[unit];//每像素多少长度
  964. //mic_rulers mic_Ruler = (mic_rulers)this.comboBox1.SelectedValue;
  965. mic_rulers mic_Ruler = dw.xmlSaveModel;
  966. if (Startup.instance.ruleDB == null)
  967. {
  968. Startup.instance.ruleDB = new mic_rulers();
  969. needResetDB = true;
  970. }
  971. Startup.instance.ruleDB.gain_multiple = mic_Ruler.gain_multiple;
  972. double micronRatio;
  973. Startup.instance.rules.TryGetValue(unit, out micronRatio);
  974. Startup.instance.rules[unit] = micronRatio;
  975. dw.ActiveTool = Annotation.Enum.DrawToolType.DrawAutoRuler;
  976. dw.Units = unit;
  977. if (needResetDB)
  978. Startup.instance.ruleDB = null;
  979. else
  980. Startup.instance.ruleDB.gain_multiple = oldGainNumber;
  981. Startup.instance.rules[unit] = oldRatio;
  982. }
  983. dw.Refresh();
  984. switch (mode)
  985. {
  986. case 0:
  987. case 2:
  988. Add(dw);
  989. break;
  990. case 1:
  991. return dw.DoSaveAsNew(mode);
  992. case 3:
  993. var result = dw.DoSaveAsNew(mode);
  994. if (!result) return result; Add(dw);
  995. break;
  996. case -1:
  997. dw.fileText = photoName + ".jpg";
  998. dw.picName = dw.fileText;
  999. dw.filePath = Startup.instance.configModel.FilePath != null ? Startup.instance.configModel.FilePath + "\\" + dw.fileText : Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\" + dw.fileText;
  1000. return dw.DoSaveNew();
  1001. case -3:
  1002. dw.fileText = photoName + ".jpg";
  1003. dw.UpdateDw2buttonName(dw.fileText);
  1004. dw.picName = dw.fileText;
  1005. dw.filePath = Startup.instance.configModel.FilePath != null ? Startup.instance.configModel.FilePath + "\\" + dw.fileText : Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\" + dw.fileText;
  1006. var res = dw.DoSaveNew();
  1007. if (!res) return res; Add(dw);
  1008. break;
  1009. }
  1010. ActiveDocumentWorkspace = dw;
  1011. if (isLockZoom && lockScaleRatio > 0)
  1012. {
  1013. ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  1014. ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(lockScaleRatio);
  1015. SetZoonTrackValue(ActiveDocumentWorkspace.ScaleFactor);
  1016. }
  1017. else
  1018. {
  1019. ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  1020. }
  1021. return true;
  1022. }
  1023. public void Add(DocumentWorkspace dw)
  1024. {
  1025. this.documentWorkspaces.Add(dw);
  1026. this.toolBar.DocumentStrip.AddDocumentWorkspace(dw);
  1027. }
  1028. public void RemoveDocumentWorkspace(DocumentWorkspace documentWorkspace)
  1029. {
  1030. int dwIndex = this.documentWorkspaces.IndexOf(documentWorkspace);
  1031. if (dwIndex == -1)
  1032. {
  1033. throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
  1034. }
  1035. bool removingCurrentDW;
  1036. if (this.ActiveDocumentWorkspace == documentWorkspace)
  1037. {
  1038. removingCurrentDW = true;
  1039. }
  1040. else
  1041. {
  1042. removingCurrentDW = false;
  1043. }
  1044. this.toInitImageIndexDialogFlag = 2;
  1045. // Choose new active DW if removing the current DW
  1046. if (removingCurrentDW)
  1047. {
  1048. if (this.documentWorkspaces.Count == 1)
  1049. {
  1050. this.ActiveDocumentWorkspace = null;
  1051. }
  1052. else if (dwIndex == 0)
  1053. {
  1054. this.ActiveDocumentWorkspace = this.documentWorkspaces[1];
  1055. }
  1056. else
  1057. {
  1058. this.ActiveDocumentWorkspace = this.documentWorkspaces[dwIndex - 1];
  1059. }
  1060. }
  1061. this.toInitImageIndexDialogFlag = 1;
  1062. this.documentWorkspaces.Remove(documentWorkspace);
  1063. this.toolBar.DocumentStrip.RemoveDocumentWorkspace(documentWorkspace);
  1064. //刷新图像索引窗口
  1065. if ((this.activeDocumentWorkspace == null || this.activeDocumentWorkspace != null && this.toInitImageIndexDialogFlag == 1)
  1066. && ImageIndexDialog.imageIndexDialog != null)
  1067. ImageIndexDialog.imageIndexDialog.InitData();
  1068. this.toInitImageIndexDialogFlag = -1;
  1069. if (this.initialWorkspace == documentWorkspace)
  1070. {
  1071. this.initialWorkspace = null;
  1072. }
  1073. // Clean up the DocumentWorkspace
  1074. Document document = documentWorkspace.Document;
  1075. documentWorkspace.Document = null;
  1076. document.Dispose();
  1077. documentWorkspace.Dispose();
  1078. documentWorkspace = null;
  1079. }
  1080. public event EventHandler ActiveDocumentWorkspaceChanging;
  1081. protected virtual void OnActiveDocumentWorkspaceChanging()
  1082. {
  1083. //如果定时器在运行则先关闭
  1084. if (timer.Enabled)
  1085. timer.Enabled = false;
  1086. SuspendUpdateSnapObstacle();
  1087. if (ActiveDocumentWorkspaceChanging != null)
  1088. {
  1089. ActiveDocumentWorkspaceChanging(this, EventArgs.Empty);
  1090. }
  1091. if (this.activeDocumentWorkspace != null)
  1092. {
  1093. this.activeDocumentWorkspace.FirstInputAfterGotFocus +=
  1094. ActiveDocumentWorkspace_FirstInputAfterGotFocus;
  1095. this.activeDocumentWorkspace.RulersEnabledChanged -= this.DocumentWorkspace_RulersEnabledChanged;
  1096. this.activeDocumentWorkspace.DocumentMouseEnter -= this.DocumentMouseEnterHandler;
  1097. this.activeDocumentWorkspace.DocumentMouseLeave -= this.DocumentMouseLeaveHandler;
  1098. this.activeDocumentWorkspace.DocumentMouseMove -= this.DocumentMouseMoveHandler;
  1099. this.activeDocumentWorkspace.DocumentMouseDown -= this.DocumentMouseDownHandler;
  1100. this.activeDocumentWorkspace.Scroll -= this.DocumentWorkspace_Scroll;
  1101. this.activeDocumentWorkspace.Layout -= this.DocumentWorkspace_Layout;
  1102. this.activeDocumentWorkspace.DrawGridChanged -= this.DocumentWorkspace_DrawGridChanged;
  1103. this.activeDocumentWorkspace.DocumentClick -= this.DocumentClick;
  1104. this.activeDocumentWorkspace.DocumentMouseUp -= this.DocumentMouseUpHandler;
  1105. this.activeDocumentWorkspace.DocumentKeyPress -= this.DocumentKeyPress;
  1106. this.activeDocumentWorkspace.DocumentKeyUp -= this.DocumenKeyUp;
  1107. this.activeDocumentWorkspace.DocumentKeyDown -= this.DocumentKeyDown;
  1108. this.activeDocumentWorkspace.StatusChanged -= OnDocumentWorkspaceStatusChanged;
  1109. this.activeDocumentWorkspace.DocumentChanging -= DocumentWorkspace_DocumentChanging;
  1110. this.activeDocumentWorkspace.DocumentChanged -= DocumentWorkspace_DocumentChanged;
  1111. //this.activeDocumentWorkspace.ScaleFactorChanged -= ZoomChangedHandler;
  1112. //this.activeDocumentWorkspace.ZoomBasisChanged -= DocumentWorkspace_ZoomBasisChanged;
  1113. this.activeDocumentWorkspace.Visible = false;
  1114. this.activeDocumentWorkspace.ToolChanging -= this.ToolChangingHandler;
  1115. this.activeDocumentWorkspace.ToolChanged -= this.ToolChangedHandler;
  1116. }
  1117. ResumeUpdateSnapObstacle();
  1118. UpdateSnapObstacle();
  1119. }
  1120. public event EventHandler ActiveDocumentWorkspaceChanged;
  1121. protected virtual void OnActiveDocumentWorkspaceChanged()
  1122. {
  1123. SuspendUpdateSnapObstacle();
  1124. if (this.activeDocumentWorkspace != null)
  1125. {
  1126. this.activeDocumentWorkspace.SuspendLayout();
  1127. this.activeDocumentWorkspace.BackColor = System.Drawing.SystemColors.ControlDark;
  1128. this.activeDocumentWorkspace.Dock = System.Windows.Forms.DockStyle.Fill;
  1129. this.activeDocumentWorkspace.DrawGrid = this.DrawGrid;
  1130. this.activeDocumentWorkspace.PanelAutoScroll = true;
  1131. this.activeDocumentWorkspace.RulersEnabled = Settings.CurrentUser.GetBoolean(SettingNames.Rulers, true);
  1132. this.activeDocumentWorkspace.AuxiliaryLineEnabled = Settings.CurrentUser.GetBoolean(SettingNames.DrawAuxiliaryLine, true);
  1133. this.activeDocumentWorkspace.TabIndex = 0;
  1134. this.activeDocumentWorkspace.TabStop = false;
  1135. this.activeDocumentWorkspace.RulersEnabledChanged += this.DocumentWorkspace_RulersEnabledChanged;
  1136. this.activeDocumentWorkspace.DocumentMouseEnter += this.DocumentMouseEnterHandler;
  1137. this.activeDocumentWorkspace.DocumentMouseLeave += this.DocumentMouseLeaveHandler;
  1138. this.activeDocumentWorkspace.DocumentMouseMove += this.DocumentMouseMoveHandler;
  1139. this.activeDocumentWorkspace.DocumentMouseDown += this.DocumentMouseDownHandler;
  1140. this.activeDocumentWorkspace.Scroll += this.DocumentWorkspace_Scroll;
  1141. this.activeDocumentWorkspace.DrawGridChanged += this.DocumentWorkspace_DrawGridChanged;
  1142. this.activeDocumentWorkspace.DocumentClick += this.DocumentClick;
  1143. this.activeDocumentWorkspace.DocumentMouseUp += this.DocumentMouseUpHandler;
  1144. this.activeDocumentWorkspace.DocumentKeyPress += this.DocumentKeyPress;
  1145. this.activeDocumentWorkspace.DocumentKeyUp += this.DocumenKeyUp;
  1146. this.activeDocumentWorkspace.DocumentKeyDown += this.DocumentKeyDown;
  1147. bool isLianXu = this.ContinuousDrawing;
  1148. if (this.workspacePanel.Controls.Contains(this.activeDocumentWorkspace))
  1149. {
  1150. this.activeDocumentWorkspace.Visible = true;
  1151. }
  1152. else
  1153. {
  1154. this.activeDocumentWorkspace.Dock = DockStyle.Fill;
  1155. this.workspacePanel.Controls.Add(this.activeDocumentWorkspace);
  1156. }
  1157. this.activeDocumentWorkspace.Layout += this.DocumentWorkspace_Layout;
  1158. //this.toolBar.ViewConfigStrip.ScaleFactor = this.activeDocumentWorkspace.ScaleFactor;
  1159. //this.toolBar.ViewConfigStrip.ZoomBasis = this.activeDocumentWorkspace.ZoomBasis;
  1160. this.activeDocumentWorkspace.AppWorkspace = this;
  1161. this.activeDocumentWorkspace.StatusChanged += OnDocumentWorkspaceStatusChanged;
  1162. this.activeDocumentWorkspace.DocumentChanging += DocumentWorkspace_DocumentChanging;
  1163. this.activeDocumentWorkspace.DocumentChanged += DocumentWorkspace_DocumentChanged;
  1164. //this.activeDocumentWorkspace.ScaleFactorChanged += ZoomChangedHandler;
  1165. //this.activeDocumentWorkspace.ZoomBasisChanged += DocumentWorkspace_ZoomBasisChanged;
  1166. //this.activeDocumentWorkspace.Units = this.widgets.ViewConfigStrip.Units;
  1167. this.activeDocumentWorkspace.ToolChanging += this.ToolChangingHandler;
  1168. this.activeDocumentWorkspace.ToolChanged += this.ToolChangedHandler;
  1169. this.toolBar.DocumentStrip.SelectDocumentWorkspace(this.activeDocumentWorkspace);
  1170. //切换相
  1171. this.PanelBottom.documentStrip.ClearPhase();
  1172. this.PanelBottom.documentStrip.AddPhase(this.activeDocumentWorkspace.phaseModels);
  1173. //处理像素跟踪
  1174. if (this.pixelTrackingDialog != null) this.pixelTrackingDialog.Mat = null;
  1175. //Bitmap map = this.activeDocumentWorkspace.SurfaceBox.Surface.CreateAliasedBitmap();
  1176. ////oldMat = PaintDotNet.Camera.Tools.ToMat(map);
  1177. //if (this.histogramDialog != null) this.histogramDialog.Mat = PaintDotNet.Camera.Tools.ToMat(map);// null;
  1178. //处理底部缩放百分比的trackbar和textbox
  1179. this.SetZoonTrackValue(this.activeDocumentWorkspace.ScaleFactor);
  1180. this.activeDocumentWorkspace.ResumeLayout();
  1181. this.activeDocumentWorkspace.PerformLayout();
  1182. this.activeDocumentWorkspace.FirstInputAfterGotFocus += ActiveDocumentWorkspace_FirstInputAfterGotFocus;
  1183. //更新信息
  1184. this.UpdateDocInfoInStatusBar();
  1185. //判断当前对象是否是zip的,如果是则需要处理右下角按钮及读取图片
  1186. if (this.activeDocumentWorkspace.zipXmlModel == null)
  1187. {
  1188. this.PanelBottom.documentStrip.ShowPictures = false;
  1189. }
  1190. else
  1191. {
  1192. this.PanelBottom.documentStrip.ShowPictures = true;
  1193. this.PanelBottom.documentStrip.trackBar.Maximum = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
  1194. PicName oldPicName = this.activeDocumentWorkspace.zipXmlModel.picNameList.Find(a => a.name == this.activeDocumentWorkspace.picName);
  1195. this.panelBottom.documentStrip.trackBar.Value = this.activeDocumentWorkspace.zipXmlModel.picNameList.IndexOf(oldPicName) + 1;
  1196. this.PanelBottom.documentStrip.textBox.Text = this.PanelBottom.documentStrip.trackBar.Value + @"/" + this.PanelBottom.documentStrip.trackBar.Maximum;
  1197. ChangeImageInActiveDocument(this.panelBottom.documentStrip.trackBar.Value);
  1198. }
  1199. }
  1200. bool isLianxu = this.ContinuousDrawing;
  1201. if (ActiveDocumentWorkspaceChanged != null)
  1202. {
  1203. ActiveDocumentWorkspaceChanged(this, EventArgs.Empty);
  1204. }
  1205. UpdateStatusBarContextStatus();
  1206. ResumeUpdateSnapObstacle();
  1207. UpdateSnapObstacle();
  1208. if (this.activeDocumentWorkspace != null)
  1209. {
  1210. if (!this.activeDocumentWorkspace.ContinuousDrawingMeasure
  1211. && this.activeDocumentWorkspace.ActiveTool >= DrawToolType.MeasureLine && this.activeDocumentWorkspace.ActiveTool <= DrawToolType.MeasureThreePointArc)
  1212. this.activeDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
  1213. if (!this.activeDocumentWorkspace.ContinuousDrawingLabel
  1214. && this.activeDocumentWorkspace.ActiveTool >= DrawToolType.DrawRectangle && this.activeDocumentWorkspace.ActiveTool <= DrawToolType.DrawPrestoredRuler)
  1215. this.activeDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
  1216. this.SetTopLeftCheckState();
  1217. this.UpdateBottomButtonSelectionStatus();
  1218. if (this.activeDocumentWorkspace.best)
  1219. this.activeDocumentWorkspace.buttonType = 0;
  1220. else if (this.activeDocumentWorkspace.maxMin)
  1221. this.activeDocumentWorkspace.buttonType = 1;
  1222. else if (this.activeDocumentWorkspace.gamma45)
  1223. this.activeDocumentWorkspace.buttonType = 2;
  1224. else if (this.activeDocumentWorkspace.origin)
  1225. this.activeDocumentWorkspace.buttonType = 3;
  1226. this.RefreshHistogram();
  1227. RefreshOpticalDensity();
  1228. }
  1229. //直方图
  1230. if (this.histogramDialog != null) this.histogramDialog.ResetMat();
  1231. //if (this.activeDocumentWorkspace != null)
  1232. //{
  1233. // Bitmap map = this.activeDocumentWorkspace.SurfaceBox.Surface.CreateAliasedBitmap();
  1234. // //oldMat = PaintDotNet.Camera.Tools.ToMat(map);
  1235. // if (this.histogramDialog != null) this.histogramDialog.Mat = PaintDotNet.Camera.Tools.ToMat(map);// null;
  1236. //}
  1237. //else
  1238. //{
  1239. // if (this.histogramDialog != null) this.histogramDialog.Mat = null;
  1240. //}
  1241. //刷新图像索引窗口
  1242. if ((this.activeDocumentWorkspace == null || this.activeDocumentWorkspace != null && this.toInitImageIndexDialogFlag == 1)
  1243. && ImageIndexDialog.imageIndexDialog != null)
  1244. ImageIndexDialog.imageIndexDialog.InitData();
  1245. }
  1246. public void SetTopLeftCheckState()
  1247. {
  1248. if (this.toolBar != null && this.activeDocumentWorkspace != null)
  1249. {
  1250. this.activeDocumentWorkspace.ContinuousDrawingMeasure = this.ContinuousDrawing;
  1251. this.activeDocumentWorkspace.ContinuousDrawingLabel = this.ContinuousDrawing;
  1252. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingMeasure, "ContinuousDrawingMeasure");
  1253. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingMeasure, "ContinuousDrawingMeasure");
  1254. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingLabel, "ContinuousDrawingLabel");
  1255. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingLabel, "ContinuousDrawingLabel");
  1256. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
  1257. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
  1258. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
  1259. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
  1260. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.RulersEnabled, "ViewRuler");
  1261. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.RulersEnabled, "ViewRuler");
  1262. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousBinaryAction, "ContinuousOperation");
  1263. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousBinaryAction, "ContinuousOperation");
  1264. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ActualSize, "ActualSize");
  1265. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ActualSize, "ActualSize");
  1266. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableSize, "ZoomToWindow");
  1267. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableSize, "ZoomToWindow");
  1268. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  1269. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  1270. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  1271. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  1272. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.LockZoom, "LockZoom");
  1273. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.LockZoom, "LockZoom");
  1274. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.FixedMultiple, "FixedMultiple");
  1275. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.FixedMultiple, "FixedMultiple");
  1276. this.toolBar.RefreshBtnSelect(this.Widgets.LabelListDialog.Visible, "LabelListAction");
  1277. this.toolsPanel.RefreshBtnSelect(this.Widgets.LabelListDialog.Visible, "LabelListAction");
  1278. this.toolBar.RefreshBtnSelect(this.Widgets.MeasureListDialog.Visible, "MeasureList");
  1279. this.toolsPanel.RefreshBtnSelect(this.Widgets.MeasureListDialog.Visible, "MeasureList");
  1280. this.toolBar.RefreshBtnSelect(this.Widgets.RuleListForm.Visible, "SubRulerCalibration");
  1281. this.toolsPanel.RefreshBtnSelect(this.Widgets.RuleListForm.Visible, "SubRulerCalibration");
  1282. this.toolBar.RefreshBtnSelect(this.Widgets.OpticalDensityDialog.Visible, "OpticalDensity");
  1283. this.toolsPanel.RefreshBtnSelect(this.Widgets.OpticalDensityDialog.Visible, "OpticalDensity");
  1284. this.toolBar.RefreshBtnSelect(this.Widgets.HistogramDialog.Visible, "Histogram");
  1285. this.toolsPanel.RefreshBtnSelect(this.Widgets.HistogramDialog.Visible, "Histogram");
  1286. this.toolBar.RefreshBtnSelect(this.Widgets.PixelTrackingDialog.Visible, "PixelTracking");
  1287. this.toolsPanel.RefreshBtnSelect(this.Widgets.PixelTrackingDialog.Visible, "PixelTracking");
  1288. this.toolBar.RefreshBtnSelect(this.Widgets.ImageIndexDialog.Visible, "ImageIndex");
  1289. this.toolsPanel.RefreshBtnSelect(this.Widgets.ImageIndexDialog.Visible, "ImageIndex");
  1290. this.toolBar.RefreshBtnSelect(this.Widgets.GeometryMeasureDialog.Visible, "Geometry");
  1291. this.toolsPanel.RefreshBtnSelect(this.Widgets.GeometryMeasureDialog.Visible, "Geometry");
  1292. this.toolBar.RefreshBtnSelect(this.Widgets.WorkFlowDialog.Visible, "WorkFlow");
  1293. this.toolsPanel.RefreshBtnSelect(this.Widgets.WorkFlowDialog.Visible, "WorkFlow");
  1294. this.toolBar.RefreshBtnSelect(this.Widgets.ScratchTreatmentDialog.Visible, "ScratchTreatment");
  1295. this.toolsPanel.RefreshBtnSelect(this.Widgets.ScratchTreatmentDialog.Visible, "ScratchTreatment");
  1296. this.toolBar.RefreshBtnSelect(this.Widgets.SmudgeTreatmentDialog.Visible, "SmudgeTreatment");
  1297. this.toolsPanel.RefreshBtnSelect(this.Widgets.SmudgeTreatmentDialog.Visible, "SmudgeTreatment");
  1298. this.toolBar.RefreshBtnSelect(this.Widgets.ProjectEngineering.Visible, "OpenProject");
  1299. this.toolsPanel.RefreshBtnSelect(this.Widgets.ProjectEngineering.Visible, "OpenProject");
  1300. if (!this.activeDocumentWorkspace.DeleteFieldOfView)
  1301. this.activeDocumentWorkspace.MergeFieldOfView = true;
  1302. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
  1303. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
  1304. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
  1305. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
  1306. }
  1307. }
  1308. public AppWorkspace(Form form)
  1309. {
  1310. this.form = form;
  1311. SuspendLayout();
  1312. // initialize!
  1313. InitializeComponent();
  1314. InitializeFloatingForms();
  1315. //初始化相机列表
  1316. this.toolBar.MainMenu.imageCollectionMenu.InitCameraList();
  1317. //this.toolBar.ToolChooserStrip.ToolClicked += new ToolClickedEventHandler(this.MainToolBar_ToolClicked);
  1318. this.toolBar.AppWorkspace = this;
  1319. // init the Widgets container
  1320. this.widgets = new WorkspaceWidgets(this);
  1321. //this.widgets.ViewConfigStrip = this.toolBar.ViewConfigStrip;
  1322. //this.widgets.CommonActionsStrip = this.toolBar.CommonActionsStrip;
  1323. this.Widgets.RuleListForm = this.ruleListForm;
  1324. this.Widgets.PixelTrackingDialog = this.pixelTrackingDialog;
  1325. this.Widgets.ImageIndexDialog = this.imageIndexDialog;
  1326. this.Widgets.GeometryMeasureDialog = this.geometryMeasureDialog;
  1327. this.Widgets.RunningDialog = this.runningDialog;
  1328. this.Widgets.HistogramDialog = this.histogramDialog;
  1329. this.Widgets.ScratchTreatmentDialog = this.scratchTreatmentDialog;
  1330. this.Widgets.SmudgeTreatmentDialog = this.smudgeTreatmentDialog;
  1331. this.Widgets.LabelListDialog = this.labelListDialog;
  1332. this.Widgets.WorkFlowDialog = this.workFlowDialog;
  1333. this.Widgets.MeasureListDialog = this.measureListDialog;
  1334. this.Widgets.OpticalDensityDialog = this.opticalDensityDialog;
  1335. this.Widgets.ProjectEngineering = this.projectEngineering;
  1336. this.widgets.StatusBarProgress = this.statusBar;
  1337. this.widgets.DocumentStrip = this.toolBar.DocumentStrip;
  1338. this.toolBar.DocumentStrip.RelinquishFocus += RelinquishFocusHandler;
  1339. //this.toolBar.CommonActionsStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  1340. //this.toolBar.CommonActionsStrip.MouseWheel += OnToolStripMouseWheel;
  1341. /*this.toolBar.ViewConfigStrip.DrawGridChanged += ViewConfigStrip_DrawGridChanged;
  1342. this.toolBar.ViewConfigStrip.ZoomBasisChanged += ViewConfigStrip_ZoomBasisChanged;
  1343. this.toolBar.ViewConfigStrip.ZoomScaleChanged += ViewConfigStrip_ZoomScaleChanged;
  1344. this.toolBar.ViewConfigStrip.ZoomIn += ViewConfigStrip_ZoomIn;
  1345. this.toolBar.ViewConfigStrip.ZoomOut += ViewConfigStrip_ZoomOut;
  1346. this.toolBar.ViewConfigStrip.UnitsChanged += ViewConfigStrip_UnitsChanged;
  1347. this.toolBar.ViewConfigStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  1348. this.toolBar.ViewConfigStrip.MouseWheel += OnToolStripMouseWheel;*/
  1349. this.toolBar.DocumentStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  1350. this.toolBar.DocumentStrip.DocumentClicked += DocumentStrip_DocumentTabClicked;
  1351. this.toolBar.DocumentStrip.DocumentListChanged += DocumentStrip_DocumentListChanged;
  1352. ResumeLayout();
  1353. PerformLayout();
  1354. this.InitializeBottomEvent();
  1355. this.InitializePanelBottomRight();
  1356. PdnBaseForm.RegisterFormHotKey(Keys.Escape, EscapeMethod);
  1357. }
  1358. /// <summary>
  1359. /// esc事件
  1360. /// </summary>
  1361. /// <param name="t"></param>
  1362. /// <returns></returns>
  1363. private bool EscapeMethod(Keys t)
  1364. {
  1365. if (this.activeDocumentWorkspace != null)
  1366. {
  1367. if (!this.continuousDrawingMeasure && !this.continuousDrawingLabel)
  1368. {
  1369. this.activeDocumentWorkspace.MouseEvent_Del(null, null);
  1370. this.activeDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
  1371. }
  1372. }
  1373. return true;
  1374. }
  1375. private void DocumentStrip_DocumentListChanged(object sender, EventArgs e)
  1376. {
  1377. bool enableThem = (this.widgets.DocumentStrip.DocumentCount != 0);
  1378. this.widgets.RuleListForm.Enabled = enableThem;
  1379. this.widgets.PixelTrackingDialog.Enabled = enableThem;
  1380. this.widgets.ImageIndexDialog.Enabled = enableThem;
  1381. this.widgets.GeometryMeasureDialog.Enabled = enableThem;
  1382. this.widgets.RunningDialog.Enabled = enableThem;
  1383. this.widgets.HistogramDialog.Enabled = enableThem;
  1384. this.widgets.ScratchTreatmentDialog.Enabled = enableThem;
  1385. this.widgets.SmudgeTreatmentDialog.Enabled = enableThem;
  1386. this.widgets.LabelListDialog.Enabled = enableThem;
  1387. this.widgets.WorkFlowDialog.Enabled = enableThem;
  1388. this.widgets.MeasureListDialog.Enabled = enableThem;
  1389. this.widgets.OpticalDensityDialog.Enabled = enableThem;
  1390. this.widgets.ProjectEngineering.Enabled = enableThem;
  1391. UpdateDocInfoInStatusBar();
  1392. UpdateCursorInfoInStatusBar(0, 0);
  1393. }
  1394. public void SaveSettings()
  1395. {
  1396. Settings.CurrentUser.SetBoolean(SettingNames.DrawGrid, this.DrawGrid);
  1397. this.MostRecentFiles.SaveMruList();
  1398. }
  1399. protected override void OnLoad(EventArgs e)
  1400. {
  1401. if (this.ActiveDocumentWorkspace != null)
  1402. {
  1403. this.ActiveDocumentWorkspace.Select();
  1404. }
  1405. UpdateSnapObstacle();
  1406. base.OnLoad(e);
  1407. }
  1408. private void RelinquishFocusHandler(object sender, EventArgs e)
  1409. {
  1410. this.Focus();
  1411. }
  1412. /*private void ZoomChangedHandler(object sender, EventArgs e)
  1413. {
  1414. ScaleFactor sf = this.activeDocumentWorkspace.ScaleFactor;
  1415. this.toolBar.ViewConfigStrip.SuspendEvents();
  1416. this.toolBar.ViewConfigStrip.ZoomBasis = this.activeDocumentWorkspace.ZoomBasis;
  1417. this.toolBar.ViewConfigStrip.ScaleFactor = sf;
  1418. this.toolBar.ViewConfigStrip.ResumeEvents();
  1419. }*/
  1420. private void InitializeComponent()
  1421. {
  1422. this.panelBottom = new PanelBottom();
  1423. this.toolBar = new PdnToolBar(this);
  1424. this.statusBar = new PdnStatusBar();
  1425. this.toolsPanel = new ToolsControl(this);
  1426. this.workspacePanel = new Panel();
  1427. this.workspacePanel.SuspendLayout();
  1428. this.statusBar.SuspendLayout();
  1429. this.SuspendLayout();
  1430. //
  1431. // panelBottom
  1432. //
  1433. this.panelBottom.Height = 30;
  1434. this.panelBottom.Dock = DockStyle.Bottom;
  1435. //
  1436. // toolBar
  1437. //
  1438. this.toolBar.Name = "toolBar";
  1439. this.toolBar.Dock = DockStyle.Top;
  1440. //
  1441. // statusBar
  1442. //
  1443. this.statusBar.Name = "statusBar";
  1444. //
  1445. // toolsPanel
  1446. //
  1447. this.toolsPanel.Width = 50;
  1448. this.toolsPanel.Dock = DockStyle.Left;
  1449. //
  1450. // workspacePanel
  1451. //
  1452. this.workspacePanel.Name = "workspacePanel";
  1453. this.workspacePanel.Dock = DockStyle.Fill;
  1454. //
  1455. // AppWorkspace
  1456. //
  1457. this.Controls.Add(this.workspacePanel);
  1458. this.Controls.Add(this.panelBottom);
  1459. this.Controls.Add(this.toolsPanel);
  1460. this.Controls.Add(this.statusBar);
  1461. this.Controls.Add(this.toolBar);
  1462. this.Name = "AppWorkspace";
  1463. this.Size = new System.Drawing.Size(872, 640);
  1464. this.workspacePanel.ResumeLayout(false);
  1465. this.statusBar.ResumeLayout(false);
  1466. this.statusBar.PerformLayout();
  1467. this.ResumeLayout(false);
  1468. }
  1469. private void DocumentStrip_DocumentTabClicked(
  1470. object sender,
  1471. EventArgs<Pair<DocumentWorkspace, DocumentClickAction>> e)
  1472. {
  1473. switch (e.Data.Second)
  1474. {
  1475. case DocumentClickAction.Select:
  1476. this.ActiveDocumentWorkspace = e.Data.First;
  1477. break;
  1478. case DocumentClickAction.Close:
  1479. CloseWorkspaceAction cwa = new CloseWorkspaceAction(e.Data.First);
  1480. PerformAction(cwa);
  1481. break;
  1482. default:
  1483. throw new NotImplementedException("Code for DocumentClickAction." + e.Data.Second.ToString() + " not implemented");
  1484. }
  1485. Update();
  1486. }
  1487. private void OnToolStripMouseWheel(object sender, MouseEventArgs e)
  1488. {
  1489. if (this.activeDocumentWorkspace != null)
  1490. {
  1491. this.activeDocumentWorkspace.PerformMouseWheel((Control)sender, e);
  1492. }
  1493. }
  1494. private void OnToolStripRelinquishFocus(object sender, EventArgs e)
  1495. {
  1496. if (this.activeDocumentWorkspace != null)
  1497. {
  1498. this.activeDocumentWorkspace.Focus();
  1499. }
  1500. }
  1501. private void DocumentMouseEnterHandler(object sender, EventArgs e)
  1502. {
  1503. }
  1504. private void DocumentMouseLeaveHandler(object sender, EventArgs e)
  1505. {
  1506. }
  1507. private void DocumentMouseUpHandler(object sender, MouseEventArgs e)
  1508. {
  1509. }
  1510. private void DocumentMouseDownHandler(object sender, MouseEventArgs e)
  1511. {
  1512. }
  1513. private void DocumentMouseMoveHandler(object sender, MouseEventArgs e)
  1514. {
  1515. UpdateCursorInfoInStatusBar(e.X, e.Y);
  1516. }
  1517. private void DocumentClick(object sender, EventArgs e)
  1518. {
  1519. }
  1520. private void DocumentKeyPress(object sender, KeyPressEventArgs e)
  1521. {
  1522. }
  1523. private void DocumentKeyDown(object sender, KeyEventArgs e)
  1524. {
  1525. }
  1526. private void DocumenKeyUp(object sender, KeyEventArgs e)
  1527. {
  1528. }
  1529. private void InitializeFloatingForms()
  1530. {
  1531. // RuleListForm
  1532. ruleListForm = new RuleListForm(this);
  1533. ruleListForm.RelinquishFocus += RelinquishFocusHandler;
  1534. ruleListForm.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1535. // PixelTrackingDialog
  1536. pixelTrackingDialog = new PixelTrackingDialog(this);
  1537. pixelTrackingDialog.RelinquishFocus += RelinquishFocusHandler;
  1538. pixelTrackingDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1539. // imageIndexDialog
  1540. imageIndexDialog = new ImageIndexDialog(this);
  1541. imageIndexDialog.RelinquishFocus += RelinquishFocusHandler;
  1542. imageIndexDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1543. // geometryMeasureDialog
  1544. geometryMeasureDialog = new GeometryMeasureDialog(this);
  1545. geometryMeasureDialog.RelinquishFocus += RelinquishFocusHandler;
  1546. geometryMeasureDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1547. // RunningDialog
  1548. runningDialog = new ScriptRunningDialog(this, null);
  1549. runningDialog.RelinquishFocus += RelinquishFocusHandler;
  1550. runningDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1551. // HistogramDialog
  1552. histogramDialog = new HistogramDialog(this);
  1553. histogramDialog.RelinquishFocus += RelinquishFocusHandler;
  1554. histogramDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1555. //ScratchTreatmentDialog
  1556. scratchTreatmentDialog = new ScratchTreatmentDialog(this);
  1557. scratchTreatmentDialog.RelinquishFocus += RelinquishFocusHandler;
  1558. scratchTreatmentDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1559. //SmudgeTreatmentDialog
  1560. smudgeTreatmentDialog = new SmudgeTreatmentDialog(this);
  1561. smudgeTreatmentDialog.RelinquishFocus += RelinquishFocusHandler;
  1562. smudgeTreatmentDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1563. //LabelListDialog
  1564. labelListDialog = new LabelListDialog(this);
  1565. labelListDialog.RelinquishFocus += RelinquishFocusHandler;
  1566. labelListDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1567. // WorkFlowDialog
  1568. workFlowDialog = new WorkFlowDialog(this);
  1569. workFlowDialog.RelinquishFocus += RelinquishFocusHandler;
  1570. workFlowDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1571. measureListDialog = new MeasureListDialog(this);
  1572. measureListDialog.RelinquishFocus += RelinquishFocusHandler;
  1573. measureListDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1574. opticalDensityDialog = new OpticalDensityDialog(this);
  1575. opticalDensityDialog.RelinquishFocus += RelinquishFocusHandler;
  1576. opticalDensityDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1577. projectEngineering = new ProjectEngineering(this);
  1578. projectEngineering.RelinquishFocus += RelinquishFocusHandler;
  1579. projectEngineering.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  1580. }
  1581. public event CmdKeysEventHandler ProcessCmdKeyEvent;
  1582. private bool OnToolFormProcessCmdKeyEvent(object sender, ref Message msg, Keys keyData)
  1583. {
  1584. if (ProcessCmdKeyEvent != null)
  1585. {
  1586. return ProcessCmdKeyEvent(sender, ref msg, keyData);
  1587. }
  1588. else
  1589. {
  1590. return false;
  1591. }
  1592. }
  1593. public void PerformActionAsync(AppWorkspaceAction performMe)
  1594. {
  1595. this.BeginInvoke(new Procedure<AppWorkspaceAction>(PerformAction), new object[] { performMe });
  1596. }
  1597. public void PerformAction(AppWorkspaceAction performMe)
  1598. {
  1599. Update();
  1600. using (new WaitCursorChanger(this))
  1601. {
  1602. performMe.PerformAction(this);
  1603. }
  1604. Update();
  1605. }
  1606. private void ToolChangingHandler(object sender, EventArgs e)
  1607. {
  1608. UI.SuspendControlPainting(this.toolBar);
  1609. }
  1610. private void ToolChangedHandler(object sender, EventArgs e)
  1611. {
  1612. UpdateStatusBarContextStatus();
  1613. UI.ResumeControlPainting(this.toolBar);
  1614. this.toolBar.Refresh();
  1615. }
  1616. protected override void OnResize(EventArgs e)
  1617. {
  1618. UpdateSnapObstacle();
  1619. base.OnResize(e);
  1620. }
  1621. private void DocumentWorkspace_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
  1622. {
  1623. OnScroll(e);
  1624. }
  1625. private void DocumentWorkspace_Layout(object sender, LayoutEventArgs e)
  1626. {
  1627. UpdateSnapObstacle();
  1628. }
  1629. /*private void DocumentWorkspace_ZoomBasisChanged(object sender, EventArgs e)
  1630. {
  1631. if (this.toolBar.ViewConfigStrip.ZoomBasis != this.ActiveDocumentWorkspace.ZoomBasis)
  1632. {
  1633. this.toolBar.ViewConfigStrip.ZoomBasis = this.ActiveDocumentWorkspace.ZoomBasis;
  1634. }
  1635. }*/
  1636. private void DocumentWorkspace_RulersEnabledChanged(object sender, EventArgs e)
  1637. {
  1638. PerformLayout();
  1639. }
  1640. public void ViewConfigStrip_UnitsChanged(object sender, EventArgs e)
  1641. {
  1642. if (this.activeDocumentWorkspace != null)
  1643. {
  1644. this.activeDocumentWorkspace.Units = this.Units;
  1645. }
  1646. UpdateDocInfoInStatusBar();
  1647. this.statusBar.CursorInfoText = string.Empty;
  1648. OnUnitsChanged();
  1649. }
  1650. public event EventHandler StatusChanged;
  1651. private void OnStatusChanged()
  1652. {
  1653. if (StatusChanged != null)
  1654. {
  1655. StatusChanged(this, EventArgs.Empty);
  1656. }
  1657. }
  1658. private void OnDocumentWorkspaceStatusChanged(object sender, EventArgs e)
  1659. {
  1660. OnStatusChanged();
  1661. UpdateStatusBarContextStatus();
  1662. }
  1663. private void UpdateStatusBarContextStatus()
  1664. {
  1665. if (ActiveDocumentWorkspace != null)
  1666. {
  1667. this.statusBar.ContextStatusText = this.activeDocumentWorkspace.StatusText;
  1668. this.statusBar.ContextStatusImage = this.activeDocumentWorkspace.StatusIcon;
  1669. }
  1670. else
  1671. {
  1672. this.statusBar.ContextStatusText = string.Empty;
  1673. this.statusBar.ContextStatusImage = null;
  1674. }
  1675. }
  1676. public bool CreateBlankDocumentInNewWorkspace(Size size, MeasurementUnit dpuUnit, double dpu, bool isInitial)
  1677. {
  1678. DocumentWorkspace dw1 = this.activeDocumentWorkspace;
  1679. try
  1680. {
  1681. Document untitled = new Document(size.Width, size.Height);
  1682. untitled.DpuUnit = dpuUnit;
  1683. untitled.DpuX = dpu;
  1684. untitled.DpuY = dpu;
  1685. /*BitmapLayer bitmapLayer;
  1686. try
  1687. {
  1688. using (new WaitCursorChanger(this))
  1689. {
  1690. bitmapLayer = Layer.CreateBackgroundLayer(size.Width, size.Height);
  1691. }
  1692. }
  1693. catch (OutOfMemoryException)
  1694. {
  1695. Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory"));
  1696. return false;
  1697. }*/
  1698. using (new WaitCursorChanger(this))
  1699. {
  1700. bool focused = false;
  1701. if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.Focused)
  1702. {
  1703. focused = true;
  1704. }
  1705. untitled.surface = new Surface(new Size(size.Width, size.Height));
  1706. untitled.surface.Clear(ColorBgra.FromBgra(255, 255, 255, 255));
  1707. untitled.surface.PixelFormat = PixelFormat.Format32bppArgb;
  1708. //untitled.Layers.Add(bitmapLayer);
  1709. DocumentWorkspace dw = this.AddNewDocumentWorkspace();
  1710. dw.needBackup = false;
  1711. this.Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
  1712. try
  1713. {
  1714. dw.Document = untitled;
  1715. }
  1716. catch (OutOfMemoryException)
  1717. {
  1718. Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory"));
  1719. RemoveDocumentWorkspace(dw);
  1720. untitled.Dispose();
  1721. return false;
  1722. }
  1723. this.ActiveDocumentWorkspace = dw;
  1724. dw.SetDocumentSaveOptions(null/*, null, null*/);
  1725. dw.Document.Dirty = false;
  1726. if (isInitial)
  1727. {
  1728. this.initialWorkspace = dw;
  1729. }
  1730. if (focused)
  1731. {
  1732. this.ActiveDocumentWorkspace.Focus();
  1733. }
  1734. this.Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
  1735. }
  1736. }
  1737. finally
  1738. {
  1739. }
  1740. return true;
  1741. }
  1742. public bool OpenFilesInNewWorkspace(string[] fileNames)
  1743. {
  1744. if (IsDisposed)
  1745. {
  1746. return false;
  1747. }
  1748. bool result = true;
  1749. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  1750. int itemCount = fileNames.Length;
  1751. ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
  1752. System.Threading.ThreadStart copyThreadProc =
  1753. delegate ()
  1754. {
  1755. try
  1756. {
  1757. for (int i = 0; i < fileNames.Length; i++)
  1758. {
  1759. if (!OpenFileInNewWorkspace(fileNames[i]))
  1760. {
  1761. continue;
  1762. }
  1763. System.Threading.Thread.Sleep(100);
  1764. this.Invoke(new Action(() =>
  1765. {
  1766. progressEvents.SetStringProgress((i + 1) + "/" + fileNames.Length);
  1767. }));
  1768. }
  1769. }
  1770. catch (Exception)
  1771. {
  1772. }
  1773. finally
  1774. {
  1775. progressEvents.EndOperation(OperationResult.Finished);
  1776. }
  1777. };
  1778. procClass.StartProgressAction((MainForm)this.Parent, itemCount, copyThreadProc, progressEvents, "打开图片");
  1779. return result;
  1780. }
  1781. public void OpenFileInNewWorkspaceThread(object obj)
  1782. {
  1783. string[] fileNames = (string[])obj;
  1784. foreach (string fileName in fileNames)
  1785. {
  1786. bool result = OpenFileInNewWorkspace(fileName);
  1787. if (!result)
  1788. {
  1789. continue;
  1790. }
  1791. System.Threading.Thread.Sleep(100);
  1792. }
  1793. }
  1794. public bool OpenFileInNewWorkspace(string fileName)
  1795. {
  1796. return OpenFileInNewWorkspace(fileName, true);
  1797. }
  1798. /// <summary>
  1799. /// 需要修改
  1800. /// (1)判断是否有同名的xml文件,有则读取并处理
  1801. /// (2)判断是否识别其它标尺,有则读取
  1802. /// </summary>
  1803. /// <param name="fileName"></param>
  1804. /// <param name="addToMruList"></param>
  1805. /// <returns></returns>
  1806. public bool OpenFileInNewWorkspace(string fileName, bool addToMruList)
  1807. {
  1808. if (fileName == null)
  1809. {
  1810. throw new ArgumentNullException("fileName");
  1811. }
  1812. if (fileName.Length == 0)
  1813. {
  1814. throw new ArgumentOutOfRangeException("fileName.Length == 0");
  1815. }
  1816. //判断是压缩包文件
  1817. ZipHandleHelper zipHandleHelper = null;
  1818. ZipXmlModel zipXmlModel = null;
  1819. bool isZipFile = false;
  1820. string picName = "";
  1821. Image zipImage = null;
  1822. if (Path.GetExtension(fileName) == ".tga")
  1823. {
  1824. zipHandleHelper = new ZipHandleHelper(fileName);
  1825. zipXmlModel = zipHandleHelper.GetXmlFromZip();
  1826. if (zipXmlModel.picNameList != null && zipXmlModel.picNameList.Count > 0)
  1827. {
  1828. picName = zipXmlModel.picNameList[0].name;//获取xml中第一张图的名称
  1829. zipImage = zipHandleHelper.GetPicFromZip(picName);
  1830. isZipFile = true;
  1831. }
  1832. else
  1833. return false;//没有xml文件或有xml但一张图片都没有,不做处理
  1834. }
  1835. this.Invoke(new Action(() =>
  1836. {
  1837. PdnBaseForm.UpdateAllForms();
  1838. }));
  1839. //FileType fileType = null;
  1840. Document document;
  1841. //this.widgets.StatusBarProgress.ResetProgressStatusBar();
  1842. ProgressEventHandler progressCallback =
  1843. delegate (object sender, ProgressEventArgs e)
  1844. {
  1845. this.widgets.StatusBarProgress.SetProgressStatusBar(e.Percent);
  1846. };
  1847. if (isZipFile)
  1848. {
  1849. if (zipImage == null)
  1850. return false;
  1851. document = Document.FromImageMat(Camera.Tools.ToMat((Bitmap)zipImage));
  1852. }
  1853. else
  1854. {
  1855. OpenCvSharp.Mat temp = new OpenCvSharp.Mat(fileName);
  1856. if (temp.Empty()) return false;
  1857. document = Document.FromMat(temp);// DocumentWorkspace.LoadDocument(this, fileName, /*out fileType, */progressCallback);
  1858. }
  1859. this.widgets.StatusBarProgress.EraseProgressStatusBar();
  1860. if (document == null)
  1861. {
  1862. this.Cursor = Cursors.Default;
  1863. }
  1864. else
  1865. {
  1866. this.Invoke(new Action(() =>
  1867. {
  1868. using (new WaitCursorChanger(this))
  1869. {
  1870. DocumentWorkspace dw = AddNewDocumentWorkspace();
  1871. //如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId);
  1872. if (this.ScriptRunning/* && this.ScriptCurrentParam != null && this.ScriptCurrentParam.MenuId == action.MenuId*/)
  1873. {
  1874. dw.OpenInScriptRunning = true;
  1875. }
  1876. Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
  1877. try
  1878. {
  1879. dw.Document = document;
  1880. //dw.rules = new Dictionary<MeasurementUnit, double>(Startup.instance.rules);
  1881. //dw.xmlSaveModel = Startup.instance.ruleDB;
  1882. //dw.InitRulerInfo();
  1883. if (isZipFile)
  1884. {
  1885. dw.fileText = picName;
  1886. dw.zipHandleHelper = zipHandleHelper;
  1887. dw.zipXmlModel = zipXmlModel;
  1888. dw.picName = picName;
  1889. }
  1890. }
  1891. catch (OutOfMemoryException)
  1892. {
  1893. Utility.ErrorBox(this, PdnResources.GetString("LoadImage.Error.OutOfMemoryException"));
  1894. RemoveDocumentWorkspace(dw);
  1895. document.Dispose();
  1896. //return false;
  1897. }
  1898. //判断是否存在xml,进行读取
  1899. PicConfigModel configModel = null;
  1900. try
  1901. {
  1902. if (isZipFile)
  1903. {
  1904. configModel = zipHandleHelper.GetImageXmlFromZip();
  1905. if (configModel != null)
  1906. {
  1907. RestoreLabelAndMeasure(configModel, dw);
  1908. }
  1909. }
  1910. string path = Path.GetDirectoryName(fileName);
  1911. string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
  1912. string xmlPathAV = fileName+"_meta.xml";
  1913. string xmlPathZEN = fileName + "_zen.xml";
  1914. //如果xml存在
  1915. if (System.IO.File.Exists(xmlPath))
  1916. {
  1917. configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
  1918. dw.RuleAttribute(configModel);
  1919. dw.Units = Startup.instance.measurementUnit;
  1920. if (configModel != null)
  1921. {
  1922. RestoreLabelAndMeasure(configModel, dw);
  1923. }
  1924. }
  1925. //else if (System.IO.File.Exists(xmlPathAV) && Startup.instance.configModel.AddAxioVision == 1)
  1926. //{
  1927. // dw.RuleAttribute(xmlPathAV);
  1928. // dw.Units = Startup.instance.measurementUnit;
  1929. // //string[] vs = XmlSerializeHelper.GetRuler(xmlPathAV);
  1930. //}
  1931. //else if (System.IO.File.Exists(xmlPathZEN) && Startup.instance.configModel.AddZEN == 1)
  1932. //{
  1933. // //dw.RuleAttribute(xmlPathZEN);
  1934. // //dw.Units = Startup.instance.measurementUnit;
  1935. //}
  1936. //如果不存在,则判断
  1937. //(1)是否自动添加ZEN标尺
  1938. //(2)是否自动添加AxioVision标尺
  1939. else
  1940. {
  1941. dw.xmlSaveModel = Startup.instance.ruleDB;
  1942. dw.InitRulerInfo();
  1943. }
  1944. //else
  1945. //{
  1946. // string path = Path.GetDirectoryName(fileName);
  1947. // string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
  1948. // //如果xml存在
  1949. // if (System.IO.File.Exists(xmlPath))
  1950. // {
  1951. // configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
  1952. // dw.RuleAttribute(configModel);
  1953. // if (configModel != null)
  1954. // {
  1955. // RestoreLabelAndMeasure(configModel, dw);
  1956. // }
  1957. // }
  1958. // //如果不存在,则判断
  1959. // //(1)是否自动添加ZEN标尺
  1960. // //(2)是否自动添加AxioVision标尺
  1961. // else
  1962. // {
  1963. // dw.xmlSaveModel = Startup.instance.ruleDB;
  1964. // dw.InitRulerInfo();
  1965. // }
  1966. //}
  1967. }
  1968. catch (Exception)
  1969. {
  1970. }
  1971. if (!isZipFile)
  1972. dw.SetDocumentSaveOptions(fileName/*, fileType, null*/);
  1973. this.ActiveDocumentWorkspace = dw;
  1974. this.ActiveDocumentWorkspace.Units = Startup.instance.measurementUnit;
  1975. document.Dirty = false;
  1976. Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
  1977. if (document != null)
  1978. {
  1979. if (isLockZoom && lockScaleRatio > 0)
  1980. {
  1981. ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  1982. ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(lockScaleRatio);
  1983. }
  1984. else
  1985. {
  1986. ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  1987. }
  1988. if (isZipFile)
  1989. {
  1990. this.PanelBottom.documentStrip.ShowPictures = true;
  1991. }
  1992. else
  1993. this.PanelBottom.documentStrip.ShowPictures = false;
  1994. }
  1995. // add to MRU list
  1996. if (addToMruList && !isZipFile)
  1997. {
  1998. ActiveDocumentWorkspace.AddToMruList();
  1999. }
  2000. //this.toolBar.DocumentStrip.SyncThumbnails();
  2001. WarnAboutSavedWithVersion(document.SavedWithVersion);
  2002. if (ActiveDocumentWorkspace != null)
  2003. {
  2004. ActiveDocumentWorkspace.Focus();
  2005. }
  2006. }
  2007. }));
  2008. }
  2009. return document != null;
  2010. }
  2011. /// <summary>
  2012. /// 还原标注和测量
  2013. /// </summary>
  2014. /// <param name="configModel"></param>
  2015. /// <param name="dw"></param>
  2016. public void RestoreLabelAndMeasure(PicConfigModel configModel, DocumentWorkspace dw)
  2017. {
  2018. //还原标注
  2019. if (configModel.labels != null && configModel.labels.Count > 0)
  2020. {
  2021. configModel.labels.Reverse();
  2022. foreach (LabelMeasureDataModel label in configModel.labels)
  2023. {
  2024. string className = InvariantData.path_Label + "." + label.drawToolType;
  2025. object[] parameters = new object[4];
  2026. parameters[0] = dw;
  2027. parameters[1] = label.points;
  2028. parameters[2] = label.style;
  2029. parameters[3] = label.content;
  2030. object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
  2031. dw.GraphicsList.Add((DrawObject)obj);
  2032. }
  2033. }
  2034. //还原测量
  2035. if (configModel.measures != null && configModel.measures.Count > 0)
  2036. {
  2037. configModel.measures.Reverse();
  2038. foreach (LabelMeasureDataModel measure in configModel.measures)
  2039. {
  2040. string className = InvariantData.path_Measure + "." + measure.drawToolType;
  2041. object[] parameters = new object[4];
  2042. parameters[0] = dw;
  2043. parameters[1] = measure.points;
  2044. parameters[2] = measure.style;
  2045. parameters[3] = measure.content;
  2046. object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
  2047. dw.GraphicsList.Add((DrawObject)obj);
  2048. }
  2049. }
  2050. //还原其他
  2051. //if (configModel.others != null && configModel.others.Count > 0)
  2052. //{
  2053. // configModel.others.Reverse();
  2054. // foreach (LabelMeasureDataModel other in configModel.others)
  2055. // {
  2056. // string className = InvariantData.path_Other + "." + other.drawToolType;
  2057. // object[] parameters = new object[4];
  2058. // parameters[0] = dw;
  2059. // parameters[1] = other.points;
  2060. // parameters[2] = other.style;
  2061. // parameters[3] = other.content;
  2062. // object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
  2063. // dw.GraphicsList.Add((DrawObject)obj);
  2064. // }
  2065. //}
  2066. }
  2067. /// <summary>
  2068. /// 版本警告,暂时用不到
  2069. /// </summary>
  2070. /// <param name="savedWith"></param>
  2071. private void WarnAboutSavedWithVersion(Version savedWith)
  2072. {
  2073. if (savedWith < new Version(2, 6, 0))
  2074. {
  2075. Version ourVersion = PdnInfo.GetVersion();
  2076. Version ourVersion2 = new Version(ourVersion.Major, ourVersion.Minor);
  2077. Version ourVersion3 = new Version(ourVersion.Major, ourVersion.Minor, ourVersion.Build);
  2078. int fields;
  2079. if (savedWith < ourVersion2)
  2080. {
  2081. fields = 2;
  2082. }
  2083. else
  2084. {
  2085. fields = 3;
  2086. }
  2087. string format = PdnResources.GetString("SavedWithOlderVersion.Format");
  2088. string text = string.Format(format, savedWith.ToString(fields), ourVersion.ToString(fields));
  2089. //Utility.InfoBox(this, text);
  2090. }
  2091. }
  2092. /// <summary>
  2093. /// Computes what the size of a new document should be. If the screen is in a normal,
  2094. /// wider-than-tall (landscape) mode then it returns 800x600. If the screen is in a
  2095. /// taller-than-wide (portrait) mode then it retusn 600x800. If the screen is square
  2096. /// then it returns 800x600.
  2097. /// </summary>
  2098. public Size GetNewDocumentSize()
  2099. {
  2100. PdnBaseForm findForm = this.FindForm() as PdnBaseForm;
  2101. if (findForm != null && findForm.ScreenAspect < 1.0)
  2102. {
  2103. return new Size(600, 800);
  2104. }
  2105. else
  2106. {
  2107. return new Size(800, 600);
  2108. }
  2109. }
  2110. /// <summary>
  2111. /// 保存快捷方式
  2112. /// </summary>
  2113. /// <returns></returns>
  2114. public bool DoSaveLnk()
  2115. {
  2116. //保存窗口
  2117. SaveFileDialog saveLnkDialog = new SaveFileDialog();
  2118. saveLnkDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  2119. saveLnkDialog.AddExtension = true;
  2120. saveLnkDialog.Filter = "Lnk(*.lnk)|*.lnk";
  2121. saveLnkDialog.FilterIndex = 1;
  2122. saveLnkDialog.CheckFileExists = false;// true;
  2123. saveLnkDialog.DefaultExt = "lnk";
  2124. saveLnkDialog.FileName = PdnResources.GetString("Menu.Ashortcu.Text");
  2125. saveLnkDialog.Title = PdnResources.GetString("Menu.Tools.CreateShortcut.Text");
  2126. //saveLnkDialog.DereferenceLinks = true;
  2127. if (saveLnkDialog.ShowDialog() == DialogResult.OK)
  2128. {
  2129. try
  2130. {
  2131. //存快捷方式
  2132. WshShell shell = new WshShell();
  2133. string savePath = saveLnkDialog.FileName;
  2134. string saveName = Path.GetFileNameWithoutExtension(savePath);
  2135. IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(savePath);
  2136. shortcut.TargetPath = Application.ExecutablePath;
  2137. shortcut.WorkingDirectory = Application.StartupPath;
  2138. shortcut.WindowStyle = 1;
  2139. shortcut.Arguments = "/personalConfig /" + saveName;//参数
  2140. bool b = FileOperationHelper.CopyDirectory(Application.StartupPath + "\\Config\\Default\\", Application.StartupPath + "\\Config\\" + saveName + "\\", true);
  2141. if (!b)
  2142. {
  2143. MessageBox.Show(PdnResources.GetString("Menu.Failedtosaveconfigurationfile.text"));
  2144. return false;
  2145. }
  2146. shortcut.Save();
  2147. return true;
  2148. }
  2149. catch (Exception)
  2150. {
  2151. MessageBox.Show(PdnResources.GetString("Menu.Shortcutsavefailed.text"));
  2152. return false;
  2153. }
  2154. }
  2155. else
  2156. return false;
  2157. }
  2158. #region 对外接口
  2159. /// <summary>
  2160. /// 获取网格样式配置
  2161. /// </summary>
  2162. /// <returns></returns>
  2163. public GridModel GetGridModel()
  2164. {
  2165. return Startup.instance.gridModel;
  2166. }
  2167. /// <summary>
  2168. /// 获取标注样式配置
  2169. /// </summary>
  2170. /// <returns></returns>
  2171. public LabelStyleModel GetLabelStyleModel()
  2172. {
  2173. return Startup.instance.labelStyleModel;
  2174. }
  2175. /// <summary>
  2176. /// 获取测量样式配置
  2177. /// </summary>
  2178. /// <returns></returns>
  2179. public MeasureStyleModel GetMeasureStyleModel()
  2180. {
  2181. return Startup.instance.measureStyleModel;
  2182. }
  2183. /// <summary>
  2184. /// 获取设置-常规设置-辅助线样式信息
  2185. /// </summary>
  2186. /// <returns></returns>
  2187. public GuideStyleModel GetGuideStyleModel()
  2188. {
  2189. return Startup.instance.guideStyleModel;
  2190. }
  2191. /// <summary>
  2192. /// 获取水印样式配置
  2193. /// </summary>
  2194. /// <returns></returns>
  2195. public WatermarkModel GetWatermarkModel()
  2196. {
  2197. return Startup.instance.watermarkModel;
  2198. }
  2199. /// <summary>
  2200. /// 获取工字线配置
  2201. /// </summary>
  2202. /// <returns></returns>
  2203. public WorkTypeStyleModel GetWorkTypeStyleModel()
  2204. {
  2205. return Startup.instance.workTypeStyleModel;
  2206. }
  2207. /// <summary>
  2208. /// 获取标尺样式配置
  2209. /// </summary>
  2210. /// <returns></returns>
  2211. public RulerModel GetRulerStyleModel()
  2212. {
  2213. return Startup.instance.rulerModel;
  2214. }
  2215. /// <summary>
  2216. /// 像素跟踪
  2217. /// 需要增加标记,在进行比如图像旋转等直接在当前
  2218. /// 面板进行图像大小变化操作的,需要停止像素跟踪,
  2219. /// 处理完成之后在恢复,否则可能会导致读取内存异常
  2220. /// </summary>
  2221. /// <param name="location"></param>
  2222. public void SetImageAndData(Point location, DocumentView doc)
  2223. {
  2224. if (this.pixelTrackingDialog != null)
  2225. {
  2226. this.pixelTrackingDialog.SetImageAndData(location, doc);
  2227. }
  2228. }
  2229. /// <summary>
  2230. /// 刷新标注列表
  2231. /// </summary>
  2232. public void RefreshLabelListDialog()
  2233. {
  2234. if (this.labelListDialog != null)
  2235. this.labelListDialog.RefreshDateGridView(null, null);
  2236. }
  2237. /// <summary>
  2238. /// 刷新交互测量列表
  2239. /// </summary>
  2240. public void RefreshMeasureListView()
  2241. {
  2242. Form form = Application.OpenForms["GeometryMeasureDialog"];
  2243. if (form != null)
  2244. {
  2245. ((GeometryMeasureDialog)form).RefreshListView(null, null);
  2246. }
  2247. this.Refresh();
  2248. }
  2249. /// <summary>
  2250. /// 刷新测量列表
  2251. /// </summary>
  2252. public void RefreshListView()
  2253. {
  2254. if (this.measureListDialog != null)
  2255. this.measureListDialog.RefreshListView(null, null);
  2256. this.Refresh();
  2257. }
  2258. /// <summary>
  2259. /// 刷新直方图
  2260. /// </summary>
  2261. public void RefreshHistogram()
  2262. {
  2263. if (this.histogramDialog != null)
  2264. this.histogramDialog.ButtonFocus(null, null);
  2265. this.Refresh();
  2266. }
  2267. /// <summary>
  2268. /// 取得绘制属性
  2269. /// </summary>
  2270. public void SetDrawNodes()
  2271. {
  2272. if (this.measureListDialog != null)
  2273. this.measureListDialog.SetDrawNodes(null, null);
  2274. }
  2275. /// <summary>
  2276. /// 刷新光密度画面
  2277. /// </summary>
  2278. public void RefreshOpticalDensity()
  2279. {
  2280. if (this.opticalDensityDialog != null)
  2281. this.opticalDensityDialog.RefreshOpticalDensity(null, null);
  2282. }
  2283. /*public PointF GetDocumentScrollPositionF()
  2284. {
  2285. return this.activeDocumentWorkspace.DocumentScrollPositionF;
  2286. }
  2287. public void SetDocumentScrollPositionF(PointF newScrollPos)
  2288. {
  2289. this.activeDocumentWorkspace.DocumentScrollPositionF = newScrollPos;
  2290. }*/
  2291. public RectangleF GetVisibleDocumentRectangleF()
  2292. {
  2293. return this.activeDocumentWorkspace.VisibleDocumentRectangleF;
  2294. }
  2295. public SizeF GetDocumentSize()
  2296. {
  2297. //return this.activeDocumentWorkspace.Document.Size;
  2298. if (this.cameraPreviewDialog != null && !this.cameraPreviewDialog.IsDisposed)
  2299. {
  2300. if (this.cameraPreviewDialog.documentWorkspace != null)
  2301. {
  2302. return this.cameraPreviewDialog.documentWorkspace.Document.Size;
  2303. }
  2304. }
  2305. else
  2306. {
  2307. return this.activeDocumentWorkspace.Document.Size;
  2308. }
  2309. return this.activeDocumentWorkspace.Document.Size;
  2310. }
  2311. public double GetRatio()
  2312. {
  2313. return this.activeDocumentWorkspace.ScaleFactor.Ratio;
  2314. }
  2315. public PointF DocumentToClient(PointF pointF)
  2316. {
  2317. return this.activeDocumentWorkspace.DocumentToClient(pointF);
  2318. }
  2319. /// <summary>
  2320. /// 获取系统当前选中单位及每单位像素值
  2321. /// </summary>
  2322. /// <returns>3位字符串数组,
  2323. /// 0:系统选中单位枚举字符串
  2324. /// 1:系统选中单位名称字符串
  2325. /// 2:系统选中单位符号字符串
  2326. /// 3:系统选中单位每单位像素长度
  2327. /// 4:系统选中单位每单位物理长度
  2328. /// </returns>
  2329. public string[] GetPxPerUnit()
  2330. {
  2331. if (this.activeDocumentWorkspace != null)
  2332. return this.activeDocumentWorkspace.getRulerList();
  2333. else
  2334. {
  2335. string[] result = new string[5];
  2336. result[0] = Startup.instance.measurementUnit.ToString();
  2337. result[1] = InvariantData.unitsDictionary[(int)Startup.instance.measurementUnit];
  2338. result[2] = InvariantData.unitSymbolsDictionary[(int)Startup.instance.measurementUnit];
  2339. result[3] = (Startup.instance.rules[Startup.instance.measurementUnit]).ToString();
  2340. result[4] = (Startup.instance.rules[MeasurementUnit.Micron]).ToString();
  2341. return result;
  2342. }
  2343. }
  2344. /// <summary>
  2345. /// 获取当前激活的图像工作空间的视场行为
  2346. /// 合并/剪切
  2347. /// </summary>
  2348. /// <returns></returns>
  2349. public CombineMode GetCombineMode()
  2350. {
  2351. return this.ActiveDocumentWorkspace.CombineMode;
  2352. }
  2353. /// <summary>
  2354. /// 获取测量单位对应的换算字典
  2355. /// </summary>
  2356. /// <returns></returns>
  2357. public Dictionary<MeasurementUnit, double> getMeasureInfo()
  2358. {
  2359. if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.rules != null)
  2360. return this.ActiveDocumentWorkspace.rules;
  2361. else
  2362. return Startup.instance.rules;
  2363. }
  2364. /// <summary>
  2365. /// 获取系统当前放大倍数
  2366. /// </summary>
  2367. /// <returns></returns>
  2368. public decimal GetGainMultiple()
  2369. {
  2370. if (Startup.instance.ruleDB == null)
  2371. {
  2372. return decimal.Zero;
  2373. }
  2374. else
  2375. {
  2376. return Startup.instance.ruleDB.gain_multiple;
  2377. }
  2378. }
  2379. PanelBottom IAppWorkspaceForSurfaceBox.GetPanelBottom()
  2380. {
  2381. return PanelBottom;
  2382. }
  2383. /// <summary>
  2384. /// 更新命名的延续数字
  2385. /// </summary>
  2386. public void UpdateContinueNum()
  2387. {
  2388. if (Startup.instance.configModel != null)
  2389. {
  2390. ConfigModel configModel = Startup.instance.configModel;
  2391. configModel.ContinueNum++;
  2392. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  2393. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  2394. FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create);
  2395. }
  2396. }
  2397. #endregion
  2398. #region 底部公共按钮
  2399. /// <summary>
  2400. /// 初始化底部按钮的各种事件
  2401. /// </summary>
  2402. private void InitializeBottomEvent()
  2403. {
  2404. //最佳
  2405. this.PanelBottom.bestButton.MouseDown += new MouseEventHandler(BestButton_Click);
  2406. //最大最小
  2407. this.PanelBottom.maxMinButton.MouseDown += new MouseEventHandler(MaxMinButton_Click);
  2408. //原始状态
  2409. this.PanelBottom.originButton.MouseDown += new MouseEventHandler(OriginButton_Click);
  2410. //伽马0.45
  2411. this.PanelBottom.gamma45Button.MouseDown += new MouseEventHandler(Gamma45Button_Click);
  2412. //网格
  2413. this.PanelBottom.gridButton.MouseDown += new MouseEventHandler(GridButton_Click);
  2414. //辅助线
  2415. this.PanelBottom.auxiliaryLineButton.MouseDown += new MouseEventHandler(AuxiliaryLineButton_Click);
  2416. //水平镜像
  2417. this.PanelBottom.horizontalMirroringButton.Click += new EventHandler(HorizontalMirroringButton_Click);
  2418. //垂直镜像
  2419. this.PanelBottom.verticalMirrorButton.Click += new EventHandler(VerticalMirrorButton_Click);
  2420. //中心镜像
  2421. this.PanelBottom.centerMirrorButton.Click += new EventHandler(CenterMirrorButton_Click);
  2422. //移动模式
  2423. this.PanelBottom.mobileModeButton.MouseDown += new MouseEventHandler(MobileModeButton_Click);
  2424. //指针模式
  2425. this.PanelBottom.cursorModeButton.MouseDown += new MouseEventHandler(CursorModeButton_Click);
  2426. //实际大小
  2427. this.PanelBottom.actualSizeButton.MouseDown += new MouseEventHandler(ActualSizeButton_Click);
  2428. //合适大小
  2429. this.PanelBottom.zoomToWindowButton.MouseDown += new MouseEventHandler(ZoomToWindowButton_Click);
  2430. //定倍显示
  2431. //this.PanelBottom.fixedTimesButton.Click += null;
  2432. //锁定扩缩
  2433. this.PanelBottom.lockdownButton.MouseDown += new MouseEventHandler(LockdownButton_Click);
  2434. //缩小按钮
  2435. this.PanelBottom.zoomOutButton.Click += new EventHandler(ZoomOutButton_Click);
  2436. //放大按钮
  2437. this.PanelBottom.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  2438. //放大缩小拖动条事件
  2439. this.PanelBottom.trackBar.ValueChanged += new EventHandler(PanelBottom_trackBar_ValueChanged);
  2440. //缩放缩小倍数的改变事件
  2441. this.PanelBottom.textBox.TextChanged += new EventHandler(PanelBottom_textBox_ValueChanged);
  2442. //相的选中事件
  2443. this.panelBottom.ItemICheckChanged += new EventHandler<EventArgs<int>>(this.PhaseItemICheckChanged);
  2444. }
  2445. public void SetZoonTrackValue(ScaleFactor newValue)
  2446. {
  2447. this.panelBottom.trackBar.Maximum = 6200;// (int)(ScaleFactor.MaxValue.Ratio * 100);
  2448. if (newValue != null)
  2449. {
  2450. this.PanelBottom.trackBar.ValueChanged -= this.PanelBottom_trackBar_ValueChanged;
  2451. double v = newValue.Ratio * 100;
  2452. if (v <= 100)
  2453. {
  2454. this.PanelBottom.trackBar.Value = (int)(31 * v);
  2455. }
  2456. else
  2457. {
  2458. double x = 3100 + newValue.Ratio * 100;
  2459. if (x > 6200) x = 6200;
  2460. this.PanelBottom.trackBar.Value = (int)x;
  2461. }
  2462. this.PanelBottom.trackBar.ValueChanged += new EventHandler(this.PanelBottom_trackBar_ValueChanged);
  2463. }
  2464. //设置底部缩放比例的百分比textbox的值
  2465. this.PanelBottom.textBox.TextChanged -= new EventHandler(PanelBottom_textBox_ValueChanged);
  2466. this.PanelBottom.textBox.Text = newValue.ToString();
  2467. this.PanelBottom.textBox.TextChanged += new EventHandler(PanelBottom_textBox_ValueChanged);
  2468. }
  2469. /// <summary>
  2470. /// 最佳
  2471. /// </summary>
  2472. /// <param name="sender"></param>
  2473. /// <param name="e"></param>
  2474. private void BestButton_Click(object sender, MouseEventArgs e)
  2475. {
  2476. if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
  2477. {
  2478. if (!this.activeDocumentWorkspace.best)
  2479. {
  2480. this.activeDocumentWorkspace.best = true;
  2481. this.activeDocumentWorkspace.maxMin = false;
  2482. this.activeDocumentWorkspace.origin = false;
  2483. this.activeDocumentWorkspace.gamma45 = false;
  2484. this.PanelBottom.maxMinButton.selected = false;
  2485. this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2486. this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
  2487. this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
  2488. this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2489. this.PanelBottom.originButton.selected = false;
  2490. this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2491. this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
  2492. this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
  2493. this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2494. this.PanelBottom.gamma45Button.selected = false;
  2495. this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
  2496. this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
  2497. this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
  2498. this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2499. }
  2500. if (this.activeDocumentWorkspace.best)
  2501. {
  2502. this.PanelBottom.bestButton.selected = true;
  2503. this.PanelBottom.bestButton.BackColor = Color.FromArgb(181, 215, 243);
  2504. this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
  2505. this.PanelBottom.bestButton.FlatAppearance.BorderSize = 1;
  2506. this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2507. }
  2508. else
  2509. {
  2510. this.PanelBottom.bestButton.selected = false;
  2511. this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2512. this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
  2513. this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
  2514. this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2515. }
  2516. this.Histogram.BestButtonMethod();
  2517. if (this.activeDocumentWorkspace != null)
  2518. {
  2519. this.activeDocumentWorkspace.buttonType = 0;
  2520. this.RefreshHistogram();
  2521. }
  2522. }
  2523. }
  2524. /// <summary>
  2525. /// 从直方图更新选中状态
  2526. /// </summary>
  2527. /// <param name="selected"></param>
  2528. public void MaxMinBest(bool best, bool maxMin, bool origin, bool gamma45)
  2529. {
  2530. this.activeDocumentWorkspace.best = best;
  2531. this.activeDocumentWorkspace.maxMin = maxMin;
  2532. this.activeDocumentWorkspace.origin = origin;
  2533. this.activeDocumentWorkspace.gamma45 = gamma45;
  2534. if (this.activeDocumentWorkspace.best)
  2535. {
  2536. this.PanelBottom.bestButton.selected = true;
  2537. this.PanelBottom.bestButton.BackColor = Color.FromArgb(181, 215, 243);
  2538. this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
  2539. this.PanelBottom.bestButton.FlatAppearance.BorderSize = 1;
  2540. this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2541. }
  2542. else
  2543. {
  2544. this.PanelBottom.bestButton.selected = false;
  2545. this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2546. this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
  2547. this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
  2548. this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2549. }
  2550. if (this.activeDocumentWorkspace.maxMin)
  2551. {
  2552. this.PanelBottom.maxMinButton.selected = true;
  2553. this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(181, 215, 243);
  2554. this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
  2555. this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 1;
  2556. this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2557. }
  2558. else
  2559. {
  2560. this.PanelBottom.maxMinButton.selected = false;
  2561. this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2562. this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
  2563. this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
  2564. this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2565. }
  2566. if (this.activeDocumentWorkspace.origin)
  2567. {
  2568. this.PanelBottom.originButton.selected = true;
  2569. this.PanelBottom.originButton.BackColor = Color.FromArgb(181, 215, 243);
  2570. this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
  2571. this.PanelBottom.originButton.FlatAppearance.BorderSize = 1;
  2572. this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2573. }
  2574. else
  2575. {
  2576. this.PanelBottom.originButton.selected = false;
  2577. this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2578. this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
  2579. this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
  2580. this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2581. }
  2582. if (this.activeDocumentWorkspace.gamma45)
  2583. {
  2584. this.PanelBottom.gamma45Button.selected = true;
  2585. this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(181, 215, 243);
  2586. this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
  2587. this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 1;
  2588. this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2589. }
  2590. else
  2591. {
  2592. this.PanelBottom.gamma45Button.selected = false;
  2593. this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
  2594. this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
  2595. this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
  2596. this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2597. }
  2598. }
  2599. /// <summary>
  2600. /// 最大最小
  2601. /// </summary>
  2602. /// <param name="sender"></param>
  2603. /// <param name="e"></param>
  2604. private void MaxMinButton_Click(object sender, MouseEventArgs e)
  2605. {
  2606. if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
  2607. {
  2608. if (!this.activeDocumentWorkspace.maxMin)
  2609. {
  2610. this.activeDocumentWorkspace.maxMin = true;
  2611. this.activeDocumentWorkspace.best = false;
  2612. this.activeDocumentWorkspace.origin = false;
  2613. this.activeDocumentWorkspace.gamma45 = false;
  2614. this.PanelBottom.bestButton.selected = false;
  2615. this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2616. this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
  2617. this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
  2618. this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2619. this.PanelBottom.originButton.selected = false;
  2620. this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2621. this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
  2622. this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
  2623. this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2624. this.PanelBottom.gamma45Button.selected = false;
  2625. this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
  2626. this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
  2627. this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
  2628. this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2629. }
  2630. if (this.activeDocumentWorkspace.maxMin)
  2631. {
  2632. this.PanelBottom.maxMinButton.selected = true;
  2633. this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(181, 215, 243);
  2634. this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
  2635. this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 1;
  2636. this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2637. }
  2638. else
  2639. {
  2640. this.PanelBottom.maxMinButton.selected = false;
  2641. this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2642. this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
  2643. this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
  2644. this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2645. }
  2646. if (this.activeDocumentWorkspace != null)
  2647. {
  2648. this.activeDocumentWorkspace.buttonType = 1;
  2649. this.RefreshHistogram();
  2650. }
  2651. this.Histogram.MaxMinButtonMethod();
  2652. }
  2653. }
  2654. /// <summary>
  2655. /// 原始状态
  2656. /// </summary>
  2657. /// <param name="sender"></param>
  2658. /// <param name="e"></param>
  2659. private void OriginButton_Click(object sender, MouseEventArgs e)
  2660. {
  2661. if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
  2662. {
  2663. if (!this.activeDocumentWorkspace.origin)
  2664. {
  2665. this.activeDocumentWorkspace.origin = true;
  2666. this.activeDocumentWorkspace.maxMin = false;
  2667. this.activeDocumentWorkspace.best = false;
  2668. this.activeDocumentWorkspace.gamma45 = false;
  2669. this.PanelBottom.bestButton.selected = false;
  2670. this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2671. this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
  2672. this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
  2673. this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2674. this.PanelBottom.maxMinButton.selected = false;
  2675. this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2676. this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
  2677. this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
  2678. this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2679. this.PanelBottom.gamma45Button.selected = false;
  2680. this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
  2681. this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
  2682. this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
  2683. this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2684. }
  2685. if (this.activeDocumentWorkspace.origin)
  2686. {
  2687. this.PanelBottom.originButton.selected = true;
  2688. this.PanelBottom.originButton.BackColor = Color.FromArgb(181, 215, 243);
  2689. this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
  2690. this.PanelBottom.originButton.FlatAppearance.BorderSize = 1;
  2691. this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2692. }
  2693. else
  2694. {
  2695. this.PanelBottom.originButton.selected = false;
  2696. this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2697. this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
  2698. this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
  2699. this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2700. }
  2701. if (this.activeDocumentWorkspace != null)
  2702. {
  2703. this.activeDocumentWorkspace.buttonType = 3;
  2704. this.RefreshHistogram();
  2705. }
  2706. this.Histogram.OriginButtonMethod();
  2707. }
  2708. }
  2709. /// <summary>
  2710. /// 伽马0.45
  2711. /// </summary>
  2712. /// <param name="sender"></param>
  2713. /// <param name="e"></param>
  2714. private void Gamma45Button_Click(object sender, MouseEventArgs e)
  2715. {
  2716. if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
  2717. {
  2718. if (!this.activeDocumentWorkspace.gamma45)
  2719. {
  2720. this.activeDocumentWorkspace.gamma45 = true;
  2721. this.activeDocumentWorkspace.origin = false;
  2722. this.activeDocumentWorkspace.maxMin = false;
  2723. this.activeDocumentWorkspace.best = false;
  2724. this.PanelBottom.bestButton.selected = false;
  2725. this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2726. this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
  2727. this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
  2728. this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2729. this.PanelBottom.maxMinButton.selected = false;
  2730. this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2731. this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
  2732. this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
  2733. this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2734. this.PanelBottom.originButton.selected = false;
  2735. this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2736. this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
  2737. this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
  2738. this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2739. }
  2740. if (this.activeDocumentWorkspace.gamma45)
  2741. {
  2742. this.PanelBottom.gamma45Button.selected = true;
  2743. this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(181, 215, 243);
  2744. this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
  2745. this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 1;
  2746. this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2747. }
  2748. else
  2749. {
  2750. this.PanelBottom.gamma45Button.selected = false;
  2751. this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
  2752. this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
  2753. this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
  2754. this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2755. }
  2756. if (this.activeDocumentWorkspace != null)
  2757. {
  2758. this.activeDocumentWorkspace.buttonType = 2;
  2759. this.RefreshHistogram();
  2760. }
  2761. this.Histogram.Gamma45ButtonMethod();
  2762. }
  2763. }
  2764. /// <summary>
  2765. /// 更新底部按钮选中状态
  2766. /// </summary>
  2767. public void UpdateBottomButtonSelectionStatus()
  2768. {
  2769. if (this.ActiveDocumentWorkspace == null)
  2770. return;
  2771. if (this.ActiveDocumentWorkspace.GridLineEnabled)
  2772. {
  2773. this.PanelBottom.gridButton.selected = true;
  2774. this.PanelBottom.gridButton.BackColor = Color.FromArgb(181, 215, 243);
  2775. this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
  2776. this.PanelBottom.gridButton.FlatAppearance.BorderSize = 1;
  2777. this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2778. }
  2779. else
  2780. {
  2781. this.PanelBottom.gridButton.selected = false;
  2782. this.PanelBottom.gridButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2783. this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
  2784. this.PanelBottom.gridButton.FlatAppearance.BorderSize = 0;
  2785. this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2786. }
  2787. if (this.ActiveDocumentWorkspace.AuxiliaryLineEnabled)
  2788. {
  2789. this.PanelBottom.auxiliaryLineButton.selected = true;
  2790. this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(181, 215, 243);
  2791. this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
  2792. this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 1;
  2793. this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2794. }
  2795. else
  2796. {
  2797. this.PanelBottom.auxiliaryLineButton.selected = false;
  2798. this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2799. this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
  2800. this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 0;
  2801. this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2802. }
  2803. if (this.activeDocumentWorkspace.ActualSize)
  2804. {
  2805. this.PanelBottom.actualSizeButton.selected = true;
  2806. this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(181, 215, 243);
  2807. this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
  2808. this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 1;
  2809. this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2810. }
  2811. else
  2812. {
  2813. this.PanelBottom.actualSizeButton.selected = false;
  2814. this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2815. this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
  2816. this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 0;
  2817. this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2818. }
  2819. if (this.activeDocumentWorkspace.SuitableSize)
  2820. {
  2821. this.PanelBottom.zoomToWindowButton.selected = true;
  2822. this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(181, 215, 243);
  2823. this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
  2824. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 1;
  2825. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2826. }
  2827. else
  2828. {
  2829. this.PanelBottom.zoomToWindowButton.selected = false;
  2830. this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2831. this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
  2832. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 0;
  2833. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2834. }
  2835. if (this.ActiveDocumentWorkspace.LockZoom)
  2836. {
  2837. this.PanelBottom.lockdownButton.selected = true;
  2838. this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(181, 215, 243);
  2839. this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
  2840. this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 1;
  2841. this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2842. }
  2843. else
  2844. {
  2845. this.PanelBottom.lockdownButton.selected = false;
  2846. this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2847. this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
  2848. this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 0;
  2849. this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2850. }
  2851. if (this.activeDocumentWorkspace.best)
  2852. {
  2853. this.PanelBottom.bestButton.selected = true;
  2854. this.PanelBottom.bestButton.BackColor = Color.FromArgb(181, 215, 243);
  2855. this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
  2856. this.PanelBottom.bestButton.FlatAppearance.BorderSize = 1;
  2857. this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2858. }
  2859. else
  2860. {
  2861. this.PanelBottom.bestButton.selected = false;
  2862. this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2863. this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
  2864. this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
  2865. this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2866. }
  2867. if (this.activeDocumentWorkspace.maxMin)
  2868. {
  2869. this.PanelBottom.maxMinButton.selected = true;
  2870. this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(181, 215, 243);
  2871. this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
  2872. this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 1;
  2873. this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2874. }
  2875. else
  2876. {
  2877. this.PanelBottom.maxMinButton.selected = false;
  2878. this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2879. this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
  2880. this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
  2881. this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2882. }
  2883. if (this.activeDocumentWorkspace.origin)
  2884. {
  2885. this.PanelBottom.originButton.selected = true;
  2886. this.PanelBottom.originButton.BackColor = Color.FromArgb(181, 215, 243);
  2887. this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
  2888. this.PanelBottom.originButton.FlatAppearance.BorderSize = 1;
  2889. this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2890. }
  2891. else
  2892. {
  2893. this.PanelBottom.originButton.selected = false;
  2894. this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2895. this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
  2896. this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
  2897. this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2898. }
  2899. if (this.activeDocumentWorkspace.gamma45)
  2900. {
  2901. this.PanelBottom.gamma45Button.selected = true;
  2902. this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(181, 215, 243);
  2903. this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
  2904. this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 1;
  2905. this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2906. }
  2907. else
  2908. {
  2909. this.PanelBottom.gamma45Button.selected = false;
  2910. this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
  2911. this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
  2912. this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
  2913. this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2914. }
  2915. if (this.ActiveDocumentWorkspace.GridLineEnabled)
  2916. {
  2917. this.PanelBottom.gridButton.selected = true;
  2918. this.PanelBottom.gridButton.BackColor = Color.FromArgb(181, 215, 243);
  2919. this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
  2920. this.PanelBottom.gridButton.FlatAppearance.BorderSize = 1;
  2921. this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2922. }
  2923. else
  2924. {
  2925. this.PanelBottom.gridButton.selected = false;
  2926. this.PanelBottom.gridButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2927. this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
  2928. this.PanelBottom.gridButton.FlatAppearance.BorderSize = 0;
  2929. this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2930. }
  2931. if (this.activeDocumentWorkspace.mobileMode)
  2932. {
  2933. this.PanelBottom.mobileModeButton.selected = true;
  2934. this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(181, 215, 243);
  2935. this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
  2936. this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 1;
  2937. this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2938. }
  2939. else
  2940. {
  2941. this.PanelBottom.mobileModeButton.selected = false;
  2942. this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2943. this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
  2944. this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 0;
  2945. this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2946. }
  2947. if (this.activeDocumentWorkspace.cursorMode)
  2948. {
  2949. this.PanelBottom.cursorModeButton.selected = true;
  2950. this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(181, 215, 243);
  2951. this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
  2952. this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 1;
  2953. this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2954. }
  2955. else
  2956. {
  2957. this.PanelBottom.cursorModeButton.selected = false;
  2958. this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2959. this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
  2960. this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 0;
  2961. this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2962. }
  2963. }
  2964. /// <summary>
  2965. /// 网格
  2966. /// </summary>
  2967. /// <param name="sender"></param>
  2968. /// <param name="e"></param>
  2969. private void GridButton_Click(object sender, MouseEventArgs e)
  2970. {
  2971. if (this.ActiveDocumentWorkspace != null)
  2972. {
  2973. this.ActiveDocumentWorkspace.GridLineEnabled = !this.ActiveDocumentWorkspace.GridLineEnabled;
  2974. if (this.ActiveDocumentWorkspace.GridLineEnabled)
  2975. {
  2976. this.PanelBottom.gridButton.selected = true;
  2977. this.PanelBottom.gridButton.BackColor = Color.FromArgb(181, 215, 243);
  2978. this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
  2979. this.PanelBottom.gridButton.FlatAppearance.BorderSize = 1;
  2980. this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  2981. }
  2982. else
  2983. {
  2984. this.PanelBottom.gridButton.selected = false;
  2985. this.PanelBottom.gridButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  2986. this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
  2987. this.PanelBottom.gridButton.FlatAppearance.BorderSize = 0;
  2988. this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  2989. }
  2990. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
  2991. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
  2992. this.ActiveDocumentWorkspace.Refresh();
  2993. }
  2994. }
  2995. /// <summary>
  2996. /// 底部快捷栏 辅助线
  2997. /// </summary>
  2998. /// <param name="sender"></param>
  2999. /// <param name="e"></param>
  3000. private void AuxiliaryLineButton_Click(object sender, MouseEventArgs e)
  3001. {
  3002. if (this.ActiveDocumentWorkspace != null)
  3003. {
  3004. this.ActiveDocumentWorkspace.AuxiliaryLineEnabled = !Settings.CurrentUser.GetBoolean(SettingNames.DrawAuxiliaryLine, false);
  3005. if (this.ActiveDocumentWorkspace.AuxiliaryLineEnabled)
  3006. {
  3007. this.PanelBottom.auxiliaryLineButton.selected = true;
  3008. this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(181, 215, 243);
  3009. this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
  3010. this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 1;
  3011. this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  3012. }
  3013. else
  3014. {
  3015. this.PanelBottom.auxiliaryLineButton.selected = false;
  3016. this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  3017. this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
  3018. this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 0;
  3019. this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  3020. }
  3021. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
  3022. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
  3023. Settings.CurrentUser.SetBoolean(SettingNames.DrawAuxiliaryLine, this.ActiveDocumentWorkspace.AuxiliaryLineEnabled);
  3024. this.ActiveDocumentWorkspace.Refresh();
  3025. }
  3026. }
  3027. /// <summary>
  3028. /// 水平镜像
  3029. /// </summary>
  3030. /// <param name="sender"></param>
  3031. /// <param name="e"></param>
  3032. public void HorizontalMirroringButton_Click(object sender, EventArgs e)
  3033. {
  3034. if (this.ActiveDocumentWorkspace != null)
  3035. {
  3036. OpenCvSharp.Mat src = this.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
  3037. OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
  3038. OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.Y);
  3039. if (this.scriptRunning)
  3040. {
  3041. DocumentWorkspace dw = this.AddNewDocumentWorkspace();
  3042. Document document = Document.FromImageMat(dst);
  3043. dw.Document = document;
  3044. dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
  3045. this.ActiveDocumentWorkspace = dw;
  3046. Startup.instance.step_length += 1;
  3047. }
  3048. else
  3049. {
  3050. Document document = Document.FromImageMat(dst);
  3051. this.ActiveDocumentWorkspace.Document = document;
  3052. this.ActiveDocumentWorkspace.Refresh();
  3053. }
  3054. }
  3055. }
  3056. /// <summary>
  3057. /// 垂直镜像
  3058. /// </summary>
  3059. /// <param name="sender"></param>
  3060. /// <param name="e"></param>
  3061. public void VerticalMirrorButton_Click(object sender, EventArgs e)
  3062. {
  3063. if (this.ActiveDocumentWorkspace != null)
  3064. {
  3065. OpenCvSharp.Mat src = this.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
  3066. OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
  3067. OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.X);
  3068. if (this.scriptRunning)
  3069. {
  3070. DocumentWorkspace dw = this.AddNewDocumentWorkspace();
  3071. Document document = Document.FromImageMat(dst);
  3072. dw.Document = document;
  3073. dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
  3074. this.ActiveDocumentWorkspace = dw;
  3075. Startup.instance.step_length += 1;
  3076. }
  3077. else
  3078. {
  3079. Document document = Document.FromImageMat(dst);
  3080. this.ActiveDocumentWorkspace.Document = document;
  3081. this.ActiveDocumentWorkspace.Refresh();
  3082. }
  3083. }
  3084. }
  3085. /// <summary>
  3086. /// 中心镜像
  3087. /// </summary>
  3088. /// <param name="sender"></param>
  3089. /// <param name="e"></param>
  3090. public void CenterMirrorButton_Click(object sender, EventArgs e)
  3091. {
  3092. if (this.ActiveDocumentWorkspace != null)
  3093. {
  3094. OpenCvSharp.Mat src = this.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
  3095. OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
  3096. OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.XY);
  3097. if (this.scriptRunning)
  3098. {
  3099. DocumentWorkspace dw = this.AddNewDocumentWorkspace();
  3100. Document document = Document.FromImageMat(dst);
  3101. dw.Document = document;
  3102. dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
  3103. this.ActiveDocumentWorkspace = dw;
  3104. Startup.instance.step_length += 1;
  3105. }
  3106. else
  3107. {
  3108. Document document = Document.FromImageMat(dst);
  3109. this.ActiveDocumentWorkspace.Document = document;
  3110. this.ActiveDocumentWorkspace.Refresh();
  3111. }
  3112. }
  3113. }
  3114. /// <summary>
  3115. /// 移动模式
  3116. /// </summary>
  3117. /// <param name="sender"></param>
  3118. /// <param name="e"></param>
  3119. private void MobileModeButton_Click(object sender, MouseEventArgs e)
  3120. {
  3121. if (this.ActiveDocumentWorkspace != null)
  3122. {
  3123. if (!this.activeDocumentWorkspace.mobileMode)
  3124. {
  3125. this.activeDocumentWorkspace.mobileMode = true;
  3126. this.activeDocumentWorkspace.cursorMode = false;
  3127. this.PanelBottom.cursorModeButton.selected = false;
  3128. this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  3129. this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
  3130. this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 0;
  3131. this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  3132. }
  3133. if (this.activeDocumentWorkspace.mobileMode)
  3134. {
  3135. this.PanelBottom.mobileModeButton.selected = true;
  3136. this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(181, 215, 243);
  3137. this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
  3138. this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 1;
  3139. this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  3140. }
  3141. else
  3142. {
  3143. this.PanelBottom.mobileModeButton.selected = false;
  3144. this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  3145. this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
  3146. this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 0;
  3147. this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  3148. }
  3149. this.ActiveDocumentWorkspace.ActiveTool = DrawToolType.MoveMode;
  3150. }
  3151. }
  3152. /// <summary>
  3153. /// 指针模式
  3154. /// </summary>
  3155. /// <param name="sender"></param>
  3156. /// <param name="e"></param>
  3157. private void CursorModeButton_Click(object sender, MouseEventArgs e)
  3158. {
  3159. if (this.ActiveDocumentWorkspace != null)
  3160. {
  3161. if (!this.activeDocumentWorkspace.cursorMode)
  3162. {
  3163. this.activeDocumentWorkspace.cursorMode = true;
  3164. this.activeDocumentWorkspace.mobileMode = false;
  3165. this.PanelBottom.mobileModeButton.selected = false;
  3166. this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  3167. this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
  3168. this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 0;
  3169. this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  3170. }
  3171. if (this.activeDocumentWorkspace.cursorMode)
  3172. {
  3173. this.PanelBottom.cursorModeButton.selected = true;
  3174. this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(181, 215, 243);
  3175. this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
  3176. this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 1;
  3177. this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  3178. }
  3179. else
  3180. {
  3181. this.PanelBottom.cursorModeButton.selected = false;
  3182. this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  3183. this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
  3184. this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 0;
  3185. this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  3186. }
  3187. this.ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
  3188. }
  3189. }
  3190. /// <summary>
  3191. /// 底部快捷栏 实际大小
  3192. /// </summary>
  3193. /// <param name="sender"></param>
  3194. /// <param name="e"></param>
  3195. private void ActualSizeButton_Click(object sender, MouseEventArgs e)
  3196. {
  3197. if (this.ActiveDocumentWorkspace != null)
  3198. {
  3199. if (!this.activeDocumentWorkspace.ActualSize)
  3200. {
  3201. this.activeDocumentWorkspace.ActualSize = !this.activeDocumentWorkspace.ActualSize;
  3202. this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  3203. this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  3204. this.activeDocumentWorkspace.SuitableSize = false;
  3205. this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  3206. this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  3207. }
  3208. else
  3209. {
  3210. this.activeDocumentWorkspace.ActualSize = !this.activeDocumentWorkspace.ActualSize;
  3211. this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  3212. this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  3213. }
  3214. if (this.activeDocumentWorkspace.ActualSize)
  3215. {
  3216. this.PanelBottom.actualSizeButton.selected = true;
  3217. this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(181, 215, 243);
  3218. this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
  3219. this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 1;
  3220. this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  3221. }
  3222. else
  3223. {
  3224. this.PanelBottom.actualSizeButton.selected = false;
  3225. this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  3226. this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
  3227. this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 0;
  3228. this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  3229. }
  3230. if (this.activeDocumentWorkspace.SuitableSize)
  3231. {
  3232. this.PanelBottom.zoomToWindowButton.selected = true;
  3233. this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(181, 215, 243);
  3234. this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
  3235. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 1;
  3236. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  3237. }
  3238. else
  3239. {
  3240. this.PanelBottom.zoomToWindowButton.selected = false;
  3241. this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  3242. this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
  3243. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 0;
  3244. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  3245. }
  3246. this.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  3247. this.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  3248. }
  3249. }
  3250. /// <summary>
  3251. /// 底部快捷栏 合适大小
  3252. /// </summary>
  3253. /// <param name="sender"></param>
  3254. /// <param name="e"></param>
  3255. private void ZoomToWindowButton_Click(object sender, MouseEventArgs e)
  3256. {
  3257. if (this.ActiveDocumentWorkspace != null)
  3258. {
  3259. if (!this.activeDocumentWorkspace.SuitableSize)
  3260. {
  3261. this.activeDocumentWorkspace.SuitableSize = !this.activeDocumentWorkspace.SuitableSize;
  3262. this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  3263. this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  3264. this.activeDocumentWorkspace.ActualSize = false;
  3265. this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  3266. this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  3267. }
  3268. else
  3269. {
  3270. this.activeDocumentWorkspace.SuitableSize = !this.activeDocumentWorkspace.SuitableSize;
  3271. this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  3272. this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  3273. }
  3274. if (this.activeDocumentWorkspace.SuitableSize)
  3275. {
  3276. this.PanelBottom.zoomToWindowButton.selected = true;
  3277. this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(181, 215, 243);
  3278. this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
  3279. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 1;
  3280. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  3281. }
  3282. else
  3283. {
  3284. this.PanelBottom.zoomToWindowButton.selected = false;
  3285. this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  3286. this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
  3287. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 0;
  3288. this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  3289. }
  3290. if (this.activeDocumentWorkspace.ActualSize)
  3291. {
  3292. this.PanelBottom.actualSizeButton.selected = true;
  3293. this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(181, 215, 243);
  3294. this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
  3295. this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 1;
  3296. this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  3297. }
  3298. else
  3299. {
  3300. this.PanelBottom.actualSizeButton.selected = false;
  3301. this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  3302. this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
  3303. this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 0;
  3304. this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  3305. }
  3306. this.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  3307. }
  3308. }
  3309. /// <summary>
  3310. /// 底部快捷键 锁定扩缩
  3311. /// </summary>
  3312. /// <param name="sender"></param>
  3313. /// <param name="e"></param>
  3314. private void LockdownButton_Click(object sender, MouseEventArgs e)
  3315. {
  3316. if (this.ActiveDocumentWorkspace != null)
  3317. {
  3318. this.ActiveDocumentWorkspace.LockZoom = !this.ActiveDocumentWorkspace.LockZoom;
  3319. this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.LockZoom, "LockZoom");
  3320. this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.LockZoom, "LockZoom");
  3321. if (this.ActiveDocumentWorkspace.LockZoom)
  3322. {
  3323. this.PanelBottom.lockdownButton.selected = true;
  3324. this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(181, 215, 243);
  3325. this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
  3326. this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 1;
  3327. this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
  3328. }
  3329. else
  3330. {
  3331. this.PanelBottom.lockdownButton.selected = false;
  3332. this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(0, 0, 0, 0);
  3333. this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
  3334. this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 0;
  3335. this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
  3336. }
  3337. this.isLockZoom = !this.isLockZoom;
  3338. this.lockScaleRatio = this.activeDocumentWorkspace.ScaleFactor.Ratio;
  3339. }
  3340. }
  3341. /// <summary>
  3342. /// 底部快捷栏 缩小事件
  3343. /// </summary>
  3344. /// <param name="sender"></param>
  3345. /// <param name="e"></param>
  3346. private void ZoomOutButton_Click(object sender, EventArgs e)
  3347. {
  3348. if (this.ActiveDocumentWorkspace != null)
  3349. {
  3350. this.ActiveDocumentWorkspace.ZoomOut();
  3351. this.activeDocumentWorkspace.ActualSize = false;
  3352. this.activeDocumentWorkspace.SuitableSize = false;
  3353. this.activeDocumentWorkspace.SuitableHeight = false;
  3354. this.activeDocumentWorkspace.SuitableWidth = false;
  3355. this.SetTopLeftCheckState();
  3356. this.UpdateBottomButtonSelectionStatus();
  3357. }
  3358. }
  3359. /// <summary>
  3360. /// 底部快捷栏 放大事件
  3361. /// </summary>
  3362. /// <param name="sender"></param>
  3363. /// <param name="e"></param>
  3364. private void zoomInButton_Click(object sender, EventArgs e)
  3365. {
  3366. if (this.ActiveDocumentWorkspace != null)
  3367. {
  3368. this.ActiveDocumentWorkspace.ZoomIn();
  3369. this.activeDocumentWorkspace.ActualSize = false;
  3370. this.activeDocumentWorkspace.SuitableSize = false;
  3371. this.activeDocumentWorkspace.SuitableHeight = false;
  3372. this.activeDocumentWorkspace.SuitableWidth = false;
  3373. this.SetTopLeftCheckState();
  3374. this.UpdateBottomButtonSelectionStatus();
  3375. }
  3376. }
  3377. /// <summary>
  3378. /// 底部方法缩小拖动条事件
  3379. /// </summary>
  3380. /// <param name="sender"></param>
  3381. /// <param name="e"></param>
  3382. private void PanelBottom_trackBar_ValueChanged(object sender, EventArgs e)
  3383. {
  3384. if (this.activeDocumentWorkspace != null)
  3385. {
  3386. this.activeDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  3387. if (this.PanelBottom.trackBar.Tag == null)
  3388. {
  3389. int v = this.PanelBottom.trackBar.Value;
  3390. if (this.PanelBottom.trackBar.Value <= 3100)
  3391. {
  3392. this.PanelBottom.trackBar.SmallChange = 31;
  3393. v = this.PanelBottom.trackBar.Value / 31;
  3394. }
  3395. else
  3396. {
  3397. this.PanelBottom.trackBar.SmallChange = 100;
  3398. v = 100 + this.PanelBottom.trackBar.Value - 3100;
  3399. }
  3400. this.activeDocumentWorkspace.ScaleFactor = new ScaleFactor(v, 100);
  3401. this.PanelBottom.trackBar.Tag = this.PanelBottom.trackBar.Value;
  3402. }
  3403. else
  3404. {
  3405. int oldValue = (int)this.PanelBottom.trackBar.Tag;
  3406. if (oldValue != this.PanelBottom.trackBar.Value)
  3407. {
  3408. int v = this.PanelBottom.trackBar.Value;
  3409. if (this.PanelBottom.trackBar.Value <= 3100)
  3410. {
  3411. this.PanelBottom.trackBar.SmallChange = 31;
  3412. v = this.PanelBottom.trackBar.Value / 31;
  3413. }
  3414. else
  3415. {
  3416. this.PanelBottom.trackBar.SmallChange = 100;
  3417. v = 100 + this.PanelBottom.trackBar.Value - 3100;
  3418. }
  3419. this.activeDocumentWorkspace.ScaleFactor = new ScaleFactor(v, 100);
  3420. this.PanelBottom.trackBar.Tag = this.PanelBottom.trackBar.Value;
  3421. }
  3422. }
  3423. }
  3424. }
  3425. private void PanelBottom_textBox_ValueChanged(object sender, EventArgs e)
  3426. {
  3427. int v;
  3428. if (!string.IsNullOrEmpty(this.PanelBottom.textBox.Text) &&
  3429. !this.PanelBottom.textBox.Text.Equals("%") &&
  3430. int.TryParse(this.PanelBottom.textBox.Text.Replace("%", ""), out v))
  3431. {
  3432. if (v > this.PanelBottom.trackBar.Maximum) v = this.PanelBottom.trackBar.Maximum;
  3433. if (v < this.PanelBottom.trackBar.Minimum) v = this.PanelBottom.trackBar.Minimum;
  3434. if (v <= 100)
  3435. {
  3436. this.PanelBottom.trackBar.Value = 31 * v;
  3437. }
  3438. else
  3439. {
  3440. int x = 3000 + v;
  3441. if (x > 6100) x = 6200;
  3442. this.PanelBottom.trackBar.Value = x;
  3443. }
  3444. }
  3445. }
  3446. /// <summary>
  3447. /// 用于相的选中和取消
  3448. /// </summary>
  3449. /// <param name="sender"></param>
  3450. /// <param name="e"></param>
  3451. private void PhaseItemICheckChanged(object sender, EventArgs<int> e)
  3452. {
  3453. if (e.Data > 0)
  3454. {
  3455. if (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.phaseModels.Count >= e.Data)
  3456. {
  3457. this.activeDocumentWorkspace.phaseModels[e.Data - 1].choise = !this.activeDocumentWorkspace.phaseModels[e.Data - 1].choise;
  3458. this.activeDocumentWorkspace.panel.Refresh();
  3459. }
  3460. }
  3461. }
  3462. /// <summary>
  3463. /// 初始化右下角播放系列按钮的各种事件
  3464. /// </summary>
  3465. private void InitializePanelBottomRight()
  3466. {
  3467. this.playMode = 2;//默认是前到后的播放模式
  3468. this.PanelBottom.documentStrip.play2Button.BackColor = Color.Gray;//前到后的按钮选中
  3469. //初始化定时器
  3470. timer = new Timer();
  3471. timer.Interval = 1000;
  3472. timer.Tick += new EventHandler(timer_Tick);
  3473. timer.Enabled = false;
  3474. //滚动条事件
  3475. this.panelBottom.documentStrip.trackBar.TrackBarScroll += new EventHandler(PanelBottom_TrackBarScroll);
  3476. //从后往前播放模式
  3477. this.PanelBottom.documentStrip.play1Button.Click += new EventHandler(PanelBottom_Play1ButtonClick);
  3478. //从前往后播放模式
  3479. this.PanelBottom.documentStrip.play2Button.Click += new EventHandler(PanelBottom_Play2ButtonClick);
  3480. //循环播放模式
  3481. this.PanelBottom.documentStrip.play3Button.Click += new EventHandler(PanelBottom_Play3ButtonClick);
  3482. //播放(暂停)
  3483. this.PanelBottom.documentStrip.playOrPauseButton.Click += new EventHandler(PanelBottom_PlayOrPauseButtonClick);
  3484. //删除当前显示页
  3485. this.PanelBottom.documentStrip.deleteButton.Click += new EventHandler(PanelBottom_DeleteButtonClick);
  3486. //修改播放时间间隔
  3487. this.panelBottom.documentStrip.editTimeButton.Click += new EventHandler(PanelBottom_EditTimeButtonClick);
  3488. }
  3489. /// <summary>
  3490. /// 右下滚动条事件
  3491. /// </summary>
  3492. /// <param name="sender"></param>
  3493. /// <param name="e"></param>
  3494. private void PanelBottom_TrackBarScroll(object sender, EventArgs e)
  3495. {
  3496. if (this.activeDocumentWorkspace.zipXmlModel.picNameList != null && this.activeDocumentWorkspace.zipXmlModel.picNameList.Count > 0
  3497. && this.activeDocumentWorkspace.zipHandleHelper != null)
  3498. {
  3499. ChangeImageInActiveDocument(this.PanelBottom.documentStrip.trackBar.Value);
  3500. }
  3501. }
  3502. /// <summary>
  3503. /// 从后往前播放按钮
  3504. /// </summary>
  3505. /// <param name="sender"></param>
  3506. /// <param name="e"></param>
  3507. private void PanelBottom_Play1ButtonClick(object sender, EventArgs e)
  3508. {
  3509. if (this.PanelBottom.documentStrip.play1Button.BackColor == Color.Gray)
  3510. return;
  3511. else
  3512. {
  3513. this.PanelBottom.documentStrip.play1Button.BackColor = Color.Gray;
  3514. this.panelBottom.documentStrip.play2Button.BackColor = Color.FromArgb(255, 240, 240, 240);
  3515. this.playMode = 1;
  3516. }
  3517. }
  3518. /// <summary>
  3519. /// 从前往后播放按钮
  3520. /// </summary>
  3521. /// <param name="sender"></param>
  3522. /// <param name="e"></param>
  3523. private void PanelBottom_Play2ButtonClick(object sender, EventArgs e)
  3524. {
  3525. if (this.PanelBottom.documentStrip.play2Button.BackColor == Color.Gray)
  3526. return;
  3527. else
  3528. {
  3529. this.PanelBottom.documentStrip.play2Button.BackColor = Color.Gray;
  3530. this.panelBottom.documentStrip.play1Button.BackColor = Color.FromArgb(255, 240, 240, 240);
  3531. this.playMode = 2;
  3532. }
  3533. }
  3534. /// <summary>
  3535. /// 循环播放按钮
  3536. /// </summary>
  3537. /// <param name="sender"></param>
  3538. /// <param name="e"></param>
  3539. private void PanelBottom_Play3ButtonClick(object sender, EventArgs e)
  3540. {
  3541. if (this.PanelBottom.documentStrip.play3Button.BackColor == Color.Gray)
  3542. {
  3543. this.panelBottom.documentStrip.play3Button.BackColor = Color.FromArgb(255, 240, 240, 240);
  3544. this.isLoopPlayback = false;
  3545. }
  3546. else
  3547. {
  3548. this.PanelBottom.documentStrip.play3Button.BackColor = Color.Gray;
  3549. this.isLoopPlayback = true;
  3550. }
  3551. }
  3552. /// <summary>
  3553. /// 播放(暂停)按钮
  3554. /// </summary>
  3555. /// <param name="sender"></param>
  3556. /// <param name="e"></param>
  3557. private void PanelBottom_PlayOrPauseButtonClick(object sender, EventArgs e)
  3558. {
  3559. timer.Enabled = !timer.Enabled;
  3560. }
  3561. /// <summary>
  3562. /// 删除当前页按钮
  3563. /// </summary>
  3564. /// <param name="sender"></param>
  3565. /// <param name="e"></param>
  3566. private void PanelBottom_DeleteButtonClick(object sender, EventArgs e)
  3567. {
  3568. if (this.activeDocumentWorkspace.zipHandleHelper != null)
  3569. {
  3570. //如点击删除时正在播放是否需要关闭定时器?
  3571. if (timer.Enabled)
  3572. timer.Enabled = false;
  3573. //压缩包里只有一张图片的情况,可能需替换成别的逻辑
  3574. if (this.activeDocumentWorkspace.zipXmlModel.picNameList.Count == 1)
  3575. {
  3576. MessageBox.Show(PdnResources.GetString("Menu.Thereisonlyoneimwedtobedeleted.text"));
  3577. return;
  3578. }
  3579. this.activeDocumentWorkspace.zipHandleHelper.DeletePicFromZip(this.activeDocumentWorkspace.zipXmlModel.picNameList[this.PanelBottom.documentStrip.trackBar.Value - 1].name);
  3580. this.activeDocumentWorkspace.zipXmlModel.picNameList.RemoveAt(this.PanelBottom.documentStrip.trackBar.Value - 1);
  3581. this.activeDocumentWorkspace.zipHandleHelper.ModifyXmlNodes(this.activeDocumentWorkspace.zipXmlModel);
  3582. //如果删除的是最后一张图,索引向前移一位
  3583. if (this.PanelBottom.documentStrip.trackBar.Value > this.activeDocumentWorkspace.zipXmlModel.picNameList.Count)
  3584. this.PanelBottom.documentStrip.trackBar.Value -= 1;
  3585. ChangeImageInActiveDocument(this.PanelBottom.documentStrip.trackBar.Value);
  3586. this.PanelBottom.documentStrip.trackBar.Maximum = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
  3587. this.PanelBottom.documentStrip.textBox.Text = this.PanelBottom.documentStrip.trackBar.Value + @"/" + this.PanelBottom.documentStrip.trackBar.Maximum;
  3588. }
  3589. }
  3590. /// <summary>
  3591. /// 修改播放间隔按钮
  3592. /// </summary>
  3593. /// <param name="sender"></param>
  3594. /// <param name="e"></param>
  3595. private void PanelBottom_EditTimeButtonClick(object sender, EventArgs e)
  3596. {
  3597. using (PlayIntervalSettingDialog playIntervalSettingDialog = new PlayIntervalSettingDialog())
  3598. {
  3599. playIntervalSettingDialog.StartPosition = FormStartPosition.CenterScreen;
  3600. playIntervalSettingDialog.textBox1.Text = timer.Interval.ToString();
  3601. playIntervalSettingDialog.button1.Click += new EventHandler(IntervalDialog_ButtonClick);
  3602. playIntervalSettingDialog.ShowDialog();
  3603. }
  3604. }
  3605. /// <summary>
  3606. /// 播放间隔设置页的确定按钮
  3607. /// </summary>
  3608. /// <param name="sender"></param>
  3609. /// <param name="e"></param>
  3610. private void IntervalDialog_ButtonClick(object sender, EventArgs e)
  3611. {
  3612. Button button = (Button)sender;
  3613. PlayIntervalSettingDialog playIntervalSettingDialog = (PlayIntervalSettingDialog)button.Parent;
  3614. timer.Interval = Convert.ToInt32(playIntervalSettingDialog.textBox1.Text);
  3615. playIntervalSettingDialog.Close();
  3616. }
  3617. /// <summary>
  3618. /// 播放使用定时器
  3619. /// </summary>
  3620. /// <param name="sender"></param>
  3621. /// <param name="e"></param>
  3622. private void timer_Tick(object sender, EventArgs e)
  3623. {
  3624. //前到后
  3625. if (this.playMode == 2)
  3626. {
  3627. if (this.PanelBottom.documentStrip.trackBar.Value < this.activeDocumentWorkspace.zipXmlModel.picNameList.Count)//当前不是最后一张图
  3628. this.PanelBottom.documentStrip.trackBar.Value += 1;
  3629. else
  3630. {
  3631. //是否循环
  3632. if (isLoopPlayback)
  3633. {
  3634. this.PanelBottom.documentStrip.trackBar.Value = 1;
  3635. }
  3636. else
  3637. {
  3638. //不循环则到终点关闭定时器
  3639. timer.Enabled = false;
  3640. return;
  3641. }
  3642. }
  3643. }
  3644. //后到前
  3645. if (this.playMode == 1)
  3646. {
  3647. if (this.PanelBottom.documentStrip.trackBar.Value > 1)//当前不是第一张图
  3648. this.PanelBottom.documentStrip.trackBar.Value -= 1;
  3649. else
  3650. {
  3651. //是否循环
  3652. if (isLoopPlayback)
  3653. {
  3654. this.PanelBottom.documentStrip.trackBar.Value = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
  3655. }
  3656. else
  3657. {
  3658. //不循环则到终点关闭定时器
  3659. timer.Enabled = false;
  3660. return;
  3661. }
  3662. }
  3663. }
  3664. ChangeImageInActiveDocument(this.PanelBottom.documentStrip.trackBar.Value);
  3665. this.PanelBottom.documentStrip.trackBar.Maximum = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
  3666. this.PanelBottom.documentStrip.textBox.Text = this.PanelBottom.documentStrip.trackBar.Value + @"/" + this.PanelBottom.documentStrip.trackBar.Maximum;
  3667. }
  3668. /// <summary>
  3669. /// 替换当前画布的图片
  3670. /// </summary>
  3671. /// <param name="trackBarValue"></param>
  3672. private void ChangeImageInActiveDocument(int trackBarValue)
  3673. {
  3674. this.activeDocumentWorkspace.picName = this.activeDocumentWorkspace.zipXmlModel.picNameList[trackBarValue - 1].name;
  3675. Image zipImage = this.activeDocumentWorkspace.zipHandleHelper.GetPicFromZip(this.activeDocumentWorkspace.picName);
  3676. Document document = Document.FromImageMat(Camera.Tools.ToMat((Bitmap)zipImage));
  3677. this.activeDocumentWorkspace.fileText = this.activeDocumentWorkspace.picName;//tab页改图片名不好用
  3678. this.activeDocumentWorkspace.Document = document;
  3679. }
  3680. private bool ExistenceXML()
  3681. {
  3682. if (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.existenceXML)
  3683. {
  3684. return true;
  3685. }
  3686. //获取图片路径
  3687. bool existenceXML = false;
  3688. if (this.activeDocumentWorkspace != null)
  3689. {
  3690. string fileName;
  3691. //FileType fileType;
  3692. //SaveConfigToken saveConfigToken;
  3693. this.activeDocumentWorkspace.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/);
  3694. if (fileName != null)
  3695. {
  3696. string path = Path.GetDirectoryName(fileName);
  3697. string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
  3698. existenceXML = System.IO.File.Exists(xmlPath);
  3699. if (existenceXML)
  3700. {
  3701. PicConfigModel configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
  3702. this.activeDocumentWorkspace.RuleAttribute(configModel);
  3703. }
  3704. //this.activeDocumentWorkspace.existenceXML = existenceXML;
  3705. }
  3706. }
  3707. return existenceXML;
  3708. }
  3709. #endregion
  3710. #region 标尺相关
  3711. /// <summary>
  3712. /// 刷新标尺列表
  3713. /// </summary>
  3714. public void RefueshRuleList()
  3715. {
  3716. if (this.widgets.RuleListForm != null)
  3717. {
  3718. this.widgets.RuleListForm.InitListViewData();
  3719. }
  3720. }
  3721. /// <summary>
  3722. /// 激活理论比例尺
  3723. /// </summary>
  3724. public void ActivateTemporaryRuler()
  3725. {
  3726. if (this.widgets.RuleListForm != null)
  3727. {
  3728. this.widgets.RuleListForm.ActivateTemporaryRuler();
  3729. }
  3730. }
  3731. /// <summary>
  3732. /// 设置当前选中标尺
  3733. /// </summary>
  3734. /// <param name="index"></param>
  3735. public void SetActiveRulerIndex(int index)
  3736. {
  3737. if (this.widgets.RuleListForm != null)
  3738. {
  3739. this.widgets.RuleListForm.SetActiveRulerIndex(index);
  3740. }
  3741. }
  3742. /// <summary>
  3743. /// 刷新当前选中的标尺-编辑后使用
  3744. /// </summary>
  3745. public void RefreshActiveRuler()
  3746. {
  3747. if (this.widgets.RuleListForm != null)
  3748. {
  3749. this.widgets.RuleListForm.RefreshActiveRuler();
  3750. }
  3751. }
  3752. #endregion
  3753. /// <summary>
  3754. /// 刷新测量工具相关别名
  3755. /// </summary>
  3756. public void RefreshAliasName()
  3757. {
  3758. if (this.widgets.GeometryMeasureDialog != null)
  3759. {
  3760. this.widgets.GeometryMeasureDialog.RefreshAliasName();
  3761. }
  3762. }
  3763. #region 项目工程
  3764. /// <summary>
  3765. /// 通用、专用分析添加到项目工程,获取路径,路径就是编号
  3766. /// </summary>
  3767. /// <param name="type">1通用分析 2专用分析</param>
  3768. /// <param name="analysis">分析的名称</param>
  3769. /// <returns></returns>
  3770. public ProjectEngineering.NodeItem GetInsertProjectPath(int type, string analysis, string originPath)
  3771. {
  3772. return this.Widgets.ProjectEngineering.GetProjectPath(type, analysis, originPath);
  3773. }
  3774. /// <summary>
  3775. /// 插入数据库
  3776. /// </summary>
  3777. /// <param name="analyzeSettingModel">分析设置信息</param>
  3778. /// <param name="folder">项目编号</param>
  3779. public void InsertIntoDB(AnalyzeSettingModel analyzeSettingModel, ProjectEngineering.NodeItem code)
  3780. {
  3781. this.Widgets.ProjectEngineering.InsertIntoDB(analyzeSettingModel, code);
  3782. }
  3783. #endregion
  3784. #region 生成报告相关
  3785. /// <summary>
  3786. /// 导出结果(一个sheet页/多个sheet页),可选择性的显示进度条
  3787. /// </summary>
  3788. public void ExportDataToExcelWithProgress(List<System.Data.DataTable> datas, string path, bool heaterTextShow = true, bool multiSheet = false, bool showProgress = false, Form currentForm = null, string dialogText = null)
  3789. {
  3790. AppCommon appCommon = new AppCommon();
  3791. if (!appCommon.isExcelInstalled())
  3792. {
  3793. MessageBox.Show(PdnResources.GetString("office.Message"));
  3794. return;
  3795. }
  3796. Microsoft.Office.Interop.Excel.Worksheet workSheet = null;
  3797. Microsoft.Office.Interop.Excel.Workbook workBook = null;
  3798. Microsoft.Office.Interop.Excel.Workbooks workbooks = null;
  3799. Microsoft.Office.Interop.Excel.Application xlApp = null;
  3800. if (showProgress /*&& currentForm != null*/ && datas != null && datas.Count > 0)
  3801. {
  3802. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  3803. int itemCount = 100;
  3804. ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
  3805. System.Threading.ThreadStart copyThreadProc =
  3806. delegate ()
  3807. {
  3808. try
  3809. {
  3810. progressEvents.SetItemCount(itemCount);
  3811. double currentWriteRow = 0.0;
  3812. double rowsCount = 0.0;
  3813. foreach (System.Data.DataTable dtb in datas)
  3814. rowsCount += dtb.Rows.Count;
  3815. progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
  3816. //if(heaterTextShow)
  3817. //{
  3818. // for (int i = 0; i < itemCount; ++i)
  3819. // {
  3820. // System.Threading.Thread.Sleep(50);
  3821. // progressEvents.SetItemOrdinal(i);
  3822. // }
  3823. //}
  3824. xlApp = new Microsoft.Office.Interop.Excel.Application();
  3825. workbooks = xlApp.Workbooks;
  3826. workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
  3827. if (multiSheet)
  3828. {
  3829. if (datas != null && datas.Count > 0)
  3830. {
  3831. int ka = 1;
  3832. foreach (System.Data.DataTable dtb in datas)
  3833. {
  3834. if (ka > 1)
  3835. {
  3836. Microsoft.Office.Interop.Excel.Sheets sheets = workBook.Worksheets;
  3837. workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
  3838. }
  3839. else
  3840. {
  3841. workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
  3842. }
  3843. if (dtb.TableName != null)
  3844. {
  3845. workSheet.Name = dtb.TableName;
  3846. }
  3847. ka++;
  3848. if (heaterTextShow)
  3849. {
  3850. for (int i = 0; i < dtb.Columns.Count; i++)
  3851. {
  3852. workSheet.Cells[1, i + 1] = dtb.Columns[i].ColumnName;
  3853. }
  3854. }
  3855. //解决标题重复显示的问题
  3856. bool columNameRepeat = true;
  3857. if (dtb.Rows.Count > 0)
  3858. for (int k = 0; k < dtb.Columns.Count; k++)
  3859. if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
  3860. {
  3861. columNameRepeat = false;
  3862. break;
  3863. }
  3864. for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
  3865. {
  3866. currentWriteRow += 1;
  3867. progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
  3868. for (int k = 0; k < dtb.Columns.Count; k++)
  3869. {
  3870. workSheet.Cells[j + (heaterTextShow ? 2 : 1) /*- (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
  3871. }
  3872. }
  3873. //workSheet.SaveAs(path, missing, missing, missing, missing, missing, missing, missing, missing, missing);
  3874. }
  3875. }
  3876. }
  3877. else
  3878. {
  3879. workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
  3880. workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
  3881. if (datas != null && datas.Count > 0)
  3882. {
  3883. int kk = 0;
  3884. int jj = 0;
  3885. foreach (System.Data.DataTable dtb in datas)
  3886. {
  3887. //if (kk == 0)
  3888. {
  3889. if (heaterTextShow)
  3890. {
  3891. if (kk > 0)
  3892. jj++;//避免标题被后面数据覆盖
  3893. for (int i = 0; i < dtb.Columns.Count; i++)
  3894. {
  3895. workSheet.Cells[jj + 1, i + 1] = dtb.Columns[i].ColumnName;
  3896. }
  3897. }
  3898. kk++;
  3899. }
  3900. //解决标题重复显示的问题
  3901. bool columNameRepeat = true;
  3902. if (dtb.Rows.Count > 0)
  3903. for (int k = 0; k < dtb.Columns.Count; k++)
  3904. if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
  3905. {
  3906. columNameRepeat = false;
  3907. break;
  3908. }
  3909. for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
  3910. {
  3911. currentWriteRow += 1;
  3912. progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
  3913. for (int k = 0; k < dtb.Columns.Count; k++)
  3914. {
  3915. workSheet.Cells[jj + (heaterTextShow ? 2 : 1)/* - (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
  3916. }
  3917. jj++;
  3918. }
  3919. }
  3920. }
  3921. }
  3922. object nothing = Type.Missing;
  3923. workBook.SaveAs(path, nothing, nothing, nothing, nothing, nothing,
  3924. Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);
  3925. }
  3926. catch (Exception e)
  3927. {
  3928. System.Console.WriteLine(e.ToString());
  3929. }
  3930. finally
  3931. {
  3932. if (xlApp != null)
  3933. {
  3934. if (xlApp != null && workBook != null)
  3935. workBook.Close(false);
  3936. xlApp.Quit();
  3937. OfficeFileHandleHelper.Kill(xlApp);
  3938. }
  3939. progressEvents.EndOperation(OperationResult.Finished);
  3940. }
  3941. };
  3942. procClass.StartProgressAction(/*currentForm*/this.form, itemCount, copyThreadProc, progressEvents, dialogText);
  3943. return;
  3944. }
  3945. try
  3946. {
  3947. xlApp = new Microsoft.Office.Interop.Excel.Application();
  3948. workbooks = xlApp.Workbooks;
  3949. workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
  3950. if (multiSheet)
  3951. {
  3952. if (datas != null && datas.Count > 0)
  3953. {
  3954. int ka = 1;
  3955. foreach (System.Data.DataTable dtb in datas)
  3956. {
  3957. if (ka > 1)
  3958. {
  3959. Microsoft.Office.Interop.Excel.Sheets sheets = workBook.Worksheets;
  3960. workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
  3961. }
  3962. else
  3963. {
  3964. workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
  3965. }
  3966. if (dtb.TableName != null)
  3967. workSheet.Name = dtb.TableName;
  3968. ka++;
  3969. if (heaterTextShow)
  3970. {
  3971. for (int i = 0; i < dtb.Columns.Count; i++)
  3972. {
  3973. workSheet.Cells[1, i + 1] = dtb.Columns[i].ColumnName;
  3974. }
  3975. }
  3976. //解决标题重复显示的问题
  3977. bool columNameRepeat = true;
  3978. if (dtb.Rows.Count > 0)
  3979. for (int k = 0; k < dtb.Columns.Count; k++)
  3980. if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
  3981. {
  3982. columNameRepeat = false;
  3983. break;
  3984. }
  3985. for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
  3986. {
  3987. for (int k = 0; k < dtb.Columns.Count; k++)
  3988. {
  3989. workSheet.Cells[j + (heaterTextShow ? 2 : 1)/* - (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
  3990. }
  3991. }
  3992. //workSheet.SaveAs(path, missing, missing, missing, missing, missing, missing, missing, missing, missing);
  3993. }
  3994. }
  3995. }
  3996. else
  3997. {
  3998. workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
  3999. workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
  4000. if (datas != null && datas.Count > 0)
  4001. {
  4002. int kk = 0;
  4003. int jj = 0;
  4004. foreach (System.Data.DataTable dtb in datas)
  4005. {
  4006. //if (kk == 0)
  4007. {
  4008. if (heaterTextShow)
  4009. {
  4010. if (kk > 0)
  4011. jj++;//避免标题被后面数据覆盖
  4012. for (int i = 0; i < dtb.Columns.Count; i++)
  4013. {
  4014. workSheet.Cells[jj + 1, i + 1] = dtb.Columns[i].ColumnName;
  4015. }
  4016. }
  4017. kk++;
  4018. }
  4019. //解决标题重复显示的问题
  4020. bool columNameRepeat = true;
  4021. if (dtb.Rows.Count > 0)
  4022. for (int k = 0; k < dtb.Columns.Count; k++)
  4023. if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
  4024. {
  4025. columNameRepeat = false;
  4026. break;
  4027. }
  4028. for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
  4029. {
  4030. for (int k = 0; k < dtb.Columns.Count; k++)
  4031. {
  4032. workSheet.Cells[jj + (heaterTextShow ? 2 : 1) /*- (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
  4033. }
  4034. jj++;
  4035. }
  4036. }
  4037. }
  4038. }
  4039. object nothing = Type.Missing;
  4040. workBook.SaveAs(path, nothing, nothing, nothing, nothing, nothing,
  4041. Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);
  4042. }
  4043. catch (Exception e)
  4044. {
  4045. System.Console.WriteLine(e.ToString());
  4046. }
  4047. finally
  4048. {
  4049. if (xlApp != null)
  4050. {
  4051. if (xlApp != null && workBook != null)
  4052. workBook.Close(false);
  4053. xlApp.Quit();
  4054. OfficeFileHandleHelper.Kill(xlApp);
  4055. }
  4056. }
  4057. }
  4058. /// <summary>
  4059. /// 生成分析报告(夹杂物)
  4060. /// </summary>
  4061. /// <param name="analyzeSettingModel">基础信息对象</param>
  4062. /// <param name="contentList">数据对象模型</param>
  4063. /// <param name="bitmapList">图片集合</param>
  4064. /// <param name="tagPositionDic">除基础信息外的word书签与excel坐标对应信息</param>
  4065. public void CreateAnalysisReportInclusion(AnalyzeSettingModel analyzeSettingModel, List<List<List<string>>> sheets, List<Bitmap> bitmapList,
  4066. Dictionary<string, string> tagPositionDic)
  4067. {
  4068. AppCommon appCommon = new AppCommon();
  4069. if (!appCommon.isExcelInstalled())
  4070. {
  4071. MessageBox.Show(PdnResources.GetString("office.Message"));
  4072. return;
  4073. }
  4074. if (analyzeSettingModel == null)
  4075. {
  4076. MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
  4077. return;
  4078. }
  4079. if (string.IsNullOrEmpty(analyzeSettingModel.savePath))
  4080. {
  4081. MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
  4082. return;
  4083. }
  4084. if (sheets.Count == 0)
  4085. {
  4086. MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
  4087. return;
  4088. }
  4089. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  4090. System.Threading.ThreadStart copyThreadProc =
  4091. delegate ()
  4092. {
  4093. int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
  4094. double pointPitch = 0;
  4095. if (dotPitch > 0)
  4096. {
  4097. mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
  4098. if (screenList != null)
  4099. {
  4100. try
  4101. {
  4102. pointPitch = double.Parse(screenList.point_pitch);//获取点距
  4103. }
  4104. catch (System.Exception)
  4105. {
  4106. }
  4107. }
  4108. }
  4109. //获取系统的毫米标尺
  4110. double unitLength = 0;
  4111. this.getMeasureInfo().TryGetValue(MeasurementUnit.Millimeter, out unitLength);
  4112. if (unitLength == 0)
  4113. unitLength = 1;
  4114. try
  4115. {
  4116. OfficeFileHandleHelper.CreateAnalysisReportInclusion(analyzeSettingModel, sheets, bitmapList, tagPositionDic, pointPitch, unitLength, GetGainMultiple());
  4117. procClass.DismissProgressAction(this.form);
  4118. MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
  4119. }
  4120. catch (Exception)
  4121. {
  4122. MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
  4123. }
  4124. finally
  4125. {
  4126. procClass.DismissProgressAction(this.form);
  4127. }
  4128. };
  4129. procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
  4130. }
  4131. /// <summary>
  4132. /// 生成分析报告
  4133. /// </summary>
  4134. /// <param name="analyzeSettingModel"></param>
  4135. /// <param name="contentList"></param>
  4136. /// <param name="bitmapList"></param>
  4137. /// <param name="tagPositionDic"></param>
  4138. public void CreateAnalysisReport(AnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<Bitmap> bitmapList,
  4139. Dictionary<string, string> tagPositionDic, string dictPath = null, Dictionary<string, string> pNames = null, List<List<string>> content2List = null)
  4140. {
  4141. AppCommon appCommon = new AppCommon();
  4142. if (!appCommon.isExcelInstalled())
  4143. {
  4144. MessageBox.Show(PdnResources.GetString("office.Message"));
  4145. return;
  4146. }
  4147. if (analyzeSettingModel == null)
  4148. {
  4149. MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
  4150. return;
  4151. }
  4152. if (string.IsNullOrEmpty(analyzeSettingModel.savePath))
  4153. {
  4154. MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
  4155. return;
  4156. }
  4157. //if (contentList != null && contentList.Count == 0)
  4158. //{
  4159. // MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
  4160. // return;
  4161. //}
  4162. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  4163. System.Threading.ThreadStart copyThreadProc =
  4164. delegate ()
  4165. {
  4166. //bool isNeedZoom = false;//是否需要缩放
  4167. //int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
  4168. //double pointPitch = 0;
  4169. //if (dotPitch > 0)
  4170. //{
  4171. // mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
  4172. // if (screenList != null)
  4173. // {
  4174. // try
  4175. // {
  4176. // pointPitch = double.Parse(screenList.point_pitch);//获取点距
  4177. // if (pointPitch > 0)
  4178. // isNeedZoom = true;
  4179. // }
  4180. // catch (System.Exception)
  4181. // {
  4182. // }
  4183. // }
  4184. //}
  4185. //当前图片微米标尺(点距计算用毫米)
  4186. double unitLength = 0;
  4187. //当前图片放大倍数
  4188. double pointPitch = 0;
  4189. this.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
  4190. //获取当前图片放大倍数
  4191. if (this.activeDocumentWorkspace != null)
  4192. pointPitch = (double)this.activeDocumentWorkspace.xmlSaveModel.gain_multiple;
  4193. else
  4194. pointPitch = 1;
  4195. bool isNeedZoom = true;
  4196. if (unitLength == 0)
  4197. unitLength = 1;
  4198. try
  4199. {
  4200. OfficeFileHandleHelper.CreateAnalysisReport(analyzeSettingModel, contentList, bitmapList, tagPositionDic, isNeedZoom, pointPitch, unitLength, GetGainMultiple(), dictPath, pNames, content2List);
  4201. procClass.DismissProgressAction(this.form);
  4202. MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
  4203. }
  4204. catch (Exception)
  4205. {
  4206. MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
  4207. }
  4208. finally
  4209. {
  4210. procClass.DismissProgressAction(this.form);
  4211. }
  4212. };
  4213. procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
  4214. }
  4215. /// <summary>
  4216. /// 生成分析报告并保存图片与中间数据
  4217. /// </summary>
  4218. /// <param name="analyzeSettingModel"></param>
  4219. /// <param name="contentList"></param>
  4220. /// <param name="dataList"></param>
  4221. /// <param name="bitmapList"></param>
  4222. /// <param name="tagPositionDic"></param>
  4223. /// <param name="newPath"></param>
  4224. /// <param name="newCode"></param>
  4225. public void CreateAnalysisReport(AnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<ExportProjectModel> dataList,
  4226. List<Bitmap> bitmapList, Dictionary<string, string> tagPositionDic, string newPath, string newCode
  4227. , string dictPath = null, Dictionary<string, string> pNames = null, List<List<string>> content2List = null)
  4228. {
  4229. AppCommon appCommon = new AppCommon();
  4230. if (!appCommon.isExcelInstalled())
  4231. {
  4232. MessageBox.Show(PdnResources.GetString("office.Message"));
  4233. return;
  4234. }
  4235. if (analyzeSettingModel == null)
  4236. {
  4237. MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
  4238. return;
  4239. }
  4240. if (string.IsNullOrEmpty(newPath))
  4241. {
  4242. MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
  4243. return;
  4244. }
  4245. if (contentList.Count == 0)
  4246. {
  4247. MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
  4248. return;
  4249. }
  4250. if (string.IsNullOrEmpty(newCode))
  4251. {
  4252. MessageBox.Show(PdnResources.GetString("Menu.nonumcannotsave.Text"));
  4253. return;
  4254. }
  4255. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  4256. System.Threading.ThreadStart copyThreadProc =
  4257. delegate ()
  4258. {
  4259. //bool isNeedZoom = false;//是否需要缩放
  4260. //int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
  4261. //double pointPitch = 0;
  4262. //if (dotPitch > 0)
  4263. //{
  4264. // mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
  4265. // if (screenList != null)
  4266. // {
  4267. // try
  4268. // {
  4269. // pointPitch = double.Parse(screenList.point_pitch);//获取点距
  4270. // if (pointPitch > 0)
  4271. // isNeedZoom = true;
  4272. // }
  4273. // catch (System.Exception)
  4274. // {
  4275. // }
  4276. // }
  4277. //}
  4278. ////获取系统的毫米标尺
  4279. //double unitLength = 0;
  4280. //this.getMeasureInfo().TryGetValue(MeasurementUnit.Millimeter, out unitLength);
  4281. //if (unitLength == 0)
  4282. // unitLength = 1;
  4283. //当前图片微米标尺(点距计算用毫米)
  4284. double unitLength = 0;
  4285. //当前图片放大倍数
  4286. double pointPitch = 0;
  4287. this.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
  4288. //获取当前图片放大倍数
  4289. if (this.activeDocumentWorkspace != null)
  4290. pointPitch = (double)this.activeDocumentWorkspace.xmlSaveModel.gain_multiple;
  4291. else
  4292. pointPitch = 1;
  4293. bool isNeedZoom = true;
  4294. try
  4295. {
  4296. OfficeFileHandleHelper.CreateAnalysisReport(analyzeSettingModel, contentList, dataList, bitmapList, tagPositionDic, newPath, newCode, isNeedZoom, pointPitch, unitLength, GetGainMultiple(), dictPath, pNames, content2List);
  4297. procClass.DismissProgressAction(this.form);
  4298. MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
  4299. }
  4300. catch (Exception)
  4301. {
  4302. MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
  4303. }
  4304. finally
  4305. {
  4306. procClass.DismissProgressAction(this.form);
  4307. }
  4308. };
  4309. procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Exportproject.text"));
  4310. }
  4311. public void CopyAndPasteByControlAndDoubleClick()
  4312. {
  4313. this.ToolBar.CopyAndPasteByControlAndDoubleClick();
  4314. }
  4315. #endregion
  4316. #region
  4317. //creating by zm
  4318. /// <summary>
  4319. /// 生成高碳铬轴承钢分析报告
  4320. /// </summary>
  4321. /// <param name="analyzeSettingModel"></param>
  4322. /// <param name="contentList"></param>
  4323. /// <param name="bitmapList"></param>
  4324. /// <param name="tagPositionDic"></param>
  4325. public void CreateAnalysisReportBearingSteal(AnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<Bitmap> bitmapList,
  4326. Dictionary<string, string> tagPositionDic, string dictPath = null, Dictionary<string, string> pNames = null, List<List<string>> content2List = null)
  4327. {
  4328. AppCommon appCommon = new AppCommon();
  4329. if (!appCommon.isExcelInstalled())
  4330. {
  4331. MessageBox.Show(PdnResources.GetString("office.Message"));
  4332. return;
  4333. }
  4334. if (analyzeSettingModel == null)
  4335. {
  4336. MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
  4337. return;
  4338. }
  4339. if (string.IsNullOrEmpty(analyzeSettingModel.savePath))
  4340. {
  4341. MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
  4342. return;
  4343. }
  4344. if (contentList != null && contentList.Count == 0)
  4345. {
  4346. MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
  4347. return;
  4348. }
  4349. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  4350. System.Threading.ThreadStart copyThreadProc =
  4351. delegate ()
  4352. {
  4353. //当前图片微米标尺(点距计算用毫米)
  4354. double unitLength = 0;
  4355. //当前图片放大倍数
  4356. double pointPitch = 0;
  4357. this.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
  4358. //获取当前图片放大倍数
  4359. if (this.activeDocumentWorkspace != null)
  4360. pointPitch = (double)this.activeDocumentWorkspace.xmlSaveModel.gain_multiple;
  4361. else
  4362. pointPitch = 1;
  4363. bool isNeedZoom = true;
  4364. if (unitLength == 0)
  4365. unitLength = 1;
  4366. CreateAnalysisReportBearingSteelExcel(analyzeSettingModel, contentList, bitmapList, tagPositionDic, isNeedZoom, pointPitch, unitLength, GetGainMultiple(), dictPath, pNames, content2List);
  4367. //CreateBearingStealDOC(analyzeSettingModel, contentList,bitmapList, tagPositionDic, pointPitch, unitLength, GetGainMultiple());
  4368. procClass.DismissProgressAction(this.form);
  4369. MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
  4370. };
  4371. procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
  4372. }
  4373. /// <summary>
  4374. /// 生成分析报告
  4375. /// </summary>
  4376. /// <param name="analyzeSettingModel">基础信息对象</param>
  4377. /// <param name="contentList">数据对象模型</param>
  4378. /// <param name="bitmapList">图片集合</param>
  4379. /// <param name="tagPositionDic">除基础信息外的word书签与excel坐标对应信息</param>
  4380. /// <param name="pointPitch">当前图片放大倍数</param>
  4381. /// <param name="unitLength">当前图片标尺</param>
  4382. /// <param name="gainMultiple">系统激活放大倍数(暂时不用保留)</param>
  4383. private static void CreateAnalysisReportBearingSteelExcel(AnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<Bitmap> bitmapList,
  4384. Dictionary<string, string> tagPositionDic, bool isNeedZoom, double pointPitch, double unitLength, decimal gainMultiple, string dictPath = null, Dictionary<string, string> pNames = null, List<List<string>> content2List = null)
  4385. {
  4386. string saveAsPath = "";
  4387. string excelModulePath = Path.GetDirectoryName(analyzeSettingModel.modulePath) + "\\公式.xlsx";//获取excel公式模板的路径
  4388. if (System.IO.File.Exists(excelModulePath))
  4389. {
  4390. saveAsPath = analyzeSettingModel.savePath + "\\" + "高碳铬轴承钢_GBT18254-2002_带状"
  4391. + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";//另存的excel文件名
  4392. //如果savePath是盘符不是文件夹,会多出一个斜杠,office的saveas无法识别,固需处理一下
  4393. if (saveAsPath.IndexOf("\\\\") != -1)
  4394. saveAsPath = saveAsPath.Replace("\\\\", "\\");
  4395. if (contentList != null)
  4396. {
  4397. SaveAsExcelWithModule(excelModulePath, saveAsPath, contentList, dictPath, pNames, content2List);
  4398. }
  4399. CreateBearingStealDOC(analyzeSettingModel, contentList, bitmapList, tagPositionDic, pointPitch, unitLength, gainMultiple);
  4400. }
  4401. }
  4402. private static MSWord.Application m_word;
  4403. private static MSWord.Document m_doc;
  4404. private static Object missing = Type.Missing;
  4405. private static MSExcel.Application m_excel;
  4406. private static MSExcel.Workbook m_workbook;
  4407. private static MSExcel.Worksheet m_worksheet;
  4408. private static MSExcel.Worksheet m2_worksheet;
  4409. /// <summary>
  4410. /// 通过公式模板创建并保存excel
  4411. /// </summary>
  4412. /// <param name="excelModulePath">excel公式模板路径</param>
  4413. /// <param name="saveAsPath">新文件另存路径</param>
  4414. /// <param name="contentList">数据对象模型</param>
  4415. /// <returns></returns>
  4416. private static bool SaveAsExcelWithModule(string excelModulePath, string saveAsPath, List<List<string>> contentList, string dictPath = null, Dictionary<string, string> pNames = null
  4417. , List<List<string>> content2List = null)
  4418. {
  4419. try
  4420. {
  4421. m_excel = new MSExcel.Application();
  4422. m_workbook = m_excel.Workbooks.Add(excelModulePath);
  4423. m_worksheet = m_workbook.Sheets.Item[1];//数据固定插入在第二个sheet页
  4424. if (contentList != null)
  4425. {
  4426. if (m_workbook.Sheets.Count < 3)
  4427. m_workbook.Sheets.Add(System.Reflection.Missing.Value, m_worksheet, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
  4428. m2_worksheet = m_workbook.Sheets.Item[1];
  4429. AddTableToExcelSheet(m2_worksheet, 1, 1, contentList);
  4430. }
  4431. m_worksheet.SaveAs(saveAsPath, missing, missing, missing, missing, missing, missing, missing, missing, missing);
  4432. //m_worksheet.Activate();
  4433. m_workbook.Close(false);
  4434. m_excel.Application.Quit();
  4435. OfficeFileHandleHelper.Kill(m_excel);
  4436. m_worksheet = null;
  4437. m2_worksheet = null;
  4438. m_workbook = null;
  4439. m_excel = null;
  4440. }
  4441. catch (Exception)
  4442. {
  4443. if (m_excel != null)
  4444. {
  4445. if (m_workbook != null)
  4446. m_workbook.Close(false);
  4447. m_excel.Application.Quit();
  4448. OfficeFileHandleHelper.Kill(m_excel);
  4449. }
  4450. m_worksheet = null;
  4451. m2_worksheet = null;
  4452. m_workbook = null;
  4453. m_excel = null;
  4454. return false;
  4455. }
  4456. return true;
  4457. }
  4458. /// <summary>
  4459. /// 向excel的sheet页指定单元格插入表格(自行拼接的list形式)
  4460. /// </summary>
  4461. /// <param name="worksheet">sheet页</param>
  4462. /// <param name="x">插入初始位置横坐标</param>
  4463. /// <param name="y">插入初始位置纵坐标</param>
  4464. /// <param name="contentList">表格对象</param>
  4465. private static void AddTableToExcelSheet(MSExcel.Worksheet worksheet, int x, int y, List<List<string>> contentList)
  4466. {
  4467. if (contentList.Count > 0)
  4468. {
  4469. for (int i = x; i < contentList.Count + 1; i++)
  4470. {
  4471. List<string> rowContent = contentList[i - 1];
  4472. if (rowContent.Count > 0)
  4473. {
  4474. for (int j = y; j < rowContent.Count + 1; j++)
  4475. {
  4476. worksheet.Cells[i, j] = rowContent[j - 1];
  4477. }
  4478. }
  4479. }
  4480. }
  4481. }
  4482. /// <summary>
  4483. /// 通过模板创建高碳铬轴承钢word报告文档
  4484. /// </summary>
  4485. /// <param name="analyzeSettingModel"></param>
  4486. /// <param name="tagValueDic"></param>
  4487. /// <param name="bitmapList"></param>
  4488. private static void CreateBearingStealDOC(AnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<Bitmap> bitmapList, Dictionary<string, string> tagValueDic, double pointPitch, double unitLength, decimal gainMultiple)
  4489. {
  4490. if (!string.IsNullOrEmpty(analyzeSettingModel.modulePath) && Directory.Exists(analyzeSettingModel.savePath))
  4491. {
  4492. string newFilePath = analyzeSettingModel.savePath + "\\" + "高碳铬轴承钢_GBT18254-2002_带状" +
  4493. DateTime.Now.ToString("yyyyMMddHHmmss") + ".docx";
  4494. if (newFilePath.IndexOf("\\\\") != -1)
  4495. newFilePath = newFilePath.Replace("\\\\", "\\");
  4496. try
  4497. {
  4498. System.IO.File.Copy(analyzeSettingModel.modulePath, newFilePath, true);
  4499. }
  4500. catch (Exception)
  4501. {
  4502. //MessageBox.Show("word模板文件已打开,请关闭后重试");
  4503. return;
  4504. }
  4505. Object pathObj = newFilePath;
  4506. try
  4507. {
  4508. m_word = new MSWord.Application();
  4509. m_doc = m_word.Documents.Open(ref pathObj,
  4510. ref missing, ref missing, ref missing, ref missing, ref missing,
  4511. ref missing, ref missing);
  4512. foreach (MSWord.Bookmark bk in m_doc.Bookmarks)
  4513. {
  4514. if (bk.Name == "modulePath")
  4515. bk.Range.Text = analyzeSettingModel.modulePath;
  4516. else if (bk.Name == "savePath")
  4517. bk.Range.Text = analyzeSettingModel.savePath;
  4518. else if (bk.Name == "inspectionPerson")
  4519. bk.Range.Text = analyzeSettingModel.inspectionPerson;
  4520. else if (bk.Name == "itemNumber")
  4521. bk.Range.Text = analyzeSettingModel.itemNumber;
  4522. else if (bk.Name == "inspectionDepartment")
  4523. bk.Range.Text = analyzeSettingModel.inspectionDepartment;
  4524. else if (bk.Name == "contact")
  4525. bk.Range.Text = analyzeSettingModel.contact;
  4526. else if (bk.Name == "ratingDate")
  4527. bk.Range.Text = analyzeSettingModel.ratingDate.ToString("yyyy/MM/dd");
  4528. else if (bk.Name == "inspectionDate")
  4529. bk.Range.Text = analyzeSettingModel.inspectionDate.ToString("yyyy/MM/dd");
  4530. else if (bk.Name == "analyzeClassify")
  4531. bk.Range.Text = analyzeSettingModel.analyzeClassify;
  4532. else if (bk.Name == "other")
  4533. {
  4534. if (analyzeSettingModel.otherList != null && analyzeSettingModel.otherList.Count > 0)
  4535. {
  4536. MSWord.Table table = m_doc.Tables.Add(bk.Range, analyzeSettingModel.otherList.Count + 1, 2, ref missing, ref missing);
  4537. table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
  4538. table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
  4539. table.Cell(1, 1).Range.Text = "名称";
  4540. table.Cell(1, 2).Range.Text = "内容";
  4541. for (int i = 0; i < analyzeSettingModel.otherList.Count; i++)
  4542. {
  4543. table.Cell(2 + i, 1).Range.Text = analyzeSettingModel.otherList[i].name;
  4544. table.Cell(2 + i, 2).Range.Text = analyzeSettingModel.otherList[i].content;
  4545. }
  4546. }
  4547. }
  4548. else if (bk.Name == "picture")
  4549. {
  4550. if (bitmapList != null && bitmapList.Count > 0)
  4551. {
  4552. bitmapList.Reverse();
  4553. for (int i = 0; i < bitmapList.Count; i++)
  4554. {
  4555. //Clipboard.SetDataObject(System.Environment.NewLine);
  4556. //bk.Range.Paste();
  4557. //Image img = bitmapList[i];
  4558. //OpenCvSharp.Mat m = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmapList[i]);
  4559. //OpenCvSharp.Mat resize_image = new OpenCvSharp.Mat();
  4560. //OpenCvSharp.Cv2.Resize(m,resize_image,new OpenCvSharp.Size(),0.5,0.5);
  4561. //Bitmap b = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resize_image);
  4562. //Clipboard.SetDataObject(b);
  4563. //bk.Range.Paste();
  4564. Bitmap bitmap = bitmapList[i];
  4565. int new_w = (int)bitmap.Width / 4;
  4566. int new_h = (int)bitmap.Height / 4;
  4567. Bitmap b = new Bitmap(new_w, new_h);
  4568. Graphics g = Graphics.FromImage(b);
  4569. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  4570. g.DrawImage(bitmap, new System.Drawing.Rectangle(0, 0, new_w, new_h), new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel);
  4571. Clipboard.SetDataObject(b);
  4572. bk.Range.Paste();
  4573. b.Dispose();
  4574. g.Dispose();
  4575. }
  4576. }
  4577. }
  4578. else
  4579. {
  4580. if (tagValueDic != null && tagValueDic.Count > 0)
  4581. {
  4582. foreach (KeyValuePair<string, string> kvp in tagValueDic)
  4583. {
  4584. if (bk.Name == kvp.Key)
  4585. {
  4586. bk.Range.Text = kvp.Value;
  4587. break;
  4588. }
  4589. }
  4590. }
  4591. }
  4592. }
  4593. m_doc.Save();
  4594. m_doc.Close(true);
  4595. m_word.Quit();
  4596. }
  4597. catch (Exception ex)
  4598. {
  4599. string msg = ex.Message;
  4600. if (m_word != null)
  4601. {
  4602. if (m_doc != null)
  4603. m_doc.Close(false);
  4604. m_word.Quit();
  4605. }
  4606. }
  4607. m_doc = null;
  4608. m_word = null;
  4609. }
  4610. }
  4611. /// <summary>
  4612. /// 返回定倍(A4纸)显示后的图片
  4613. /// 定倍计算公式:图片像素(宽和高) * 当前图片标尺 * 当前图片放大倍数
  4614. /// </summary>
  4615. /// <param name="oldBit"></param>
  4616. /// <param name="pointPitch">当前图片放大倍数</param>
  4617. /// <param name="unitLength">当前图片标尺</param>
  4618. /// <param name="gainMultiple">系统激活标尺放大倍数(暂时没用)</param>
  4619. /// <returns></returns>
  4620. private static Bitmap GetFixedMultipleBitmap(Bitmap oldBit, double pointPitch, double unitLength, decimal gainMultiple)
  4621. {
  4622. if (pointPitch == 0)
  4623. return oldBit;
  4624. int oldWidth = oldBit.Width;
  4625. int oldHeight = oldBit.Height;
  4626. int targetWidth = 0;
  4627. int targetHeight = 0;
  4628. if (oldWidth <= 1 || oldHeight <= 1)//像素最小为1,之后不再处理
  4629. return oldBit;
  4630. int newWidth = oldWidth / 2;
  4631. int newHeight = oldHeight / 2;
  4632. //缩放图片
  4633. Bitmap targetBit = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppArgb);
  4634. Graphics g = Graphics.FromImage(targetBit);
  4635. g.DrawImage(oldBit, new System.Drawing.Rectangle(0, 0, newWidth, newHeight), new System.Drawing.Rectangle(0, 0, oldWidth, oldHeight), GraphicsUnit.Pixel);
  4636. return targetBit;
  4637. }
  4638. #endregion
  4639. public void SetContinuousDrawingMeasure(bool value)
  4640. {
  4641. this.continuousDrawingMeasure = value;
  4642. this.continuousDrawingLabel = value;
  4643. SetTopLeftCheckState();
  4644. }
  4645. public void SetContinuousDrawingLable(bool value)
  4646. {
  4647. this.continuousDrawingLabel = value;
  4648. this.continuousDrawingLabel = value;
  4649. SetTopLeftCheckState();
  4650. }
  4651. /// <summary>
  4652. /// 录制脚本添加参数
  4653. /// </summary>
  4654. public void SetScriptStartRecording(int menuId, string menuName, List<Args> list)
  4655. {
  4656. mic_script_step script_Step = new mic_script_step();
  4657. script_Step.automatic = 2;
  4658. script_Step.menu_id = menuId;
  4659. script_Step.script_id = 0;
  4660. script_Step.step_name = menuName;
  4661. script_Step.step_sort = this.addMicScriptStepList.Count;
  4662. this.addMicScriptStepList.Add(script_Step);
  4663. this.addMicScriptStepParamList.Add(script_Step, list);
  4664. }
  4665. }
  4666. }