AppWorkspace.cs 222 KB

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