AppWorkspace.cs 214 KB

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