123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136 |
- using IWshRuntimeLibrary;
- using Metis.Measuring;
- using OpenCvSharp.Extensions;
- using PaintDotNet.Actions;
- using PaintDotNet.Annotation;
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Base;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.Functionodel;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.CustomControl;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.DedicatedAnalysis.DuctileIron.Common;
- using PaintDotNet.ImageCollect;
- using PaintDotNet.ImageLabel;
- using PaintDotNet.Instrument;
- using PaintDotNet.Measuring;
- using PaintDotNet.SystemLayer;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.Globalization;
- using System.IO;
- using System.Windows.Forms;
- using static PaintDotNet.Base.Functionodel.ZipXmlModel;
- namespace PaintDotNet
- {
- internal class AppWorkspace : UserControl, ISnapObstacleHost, IAppWorkspaceForSurfaceBox
- {
- #region 控件
- /// <summary>
- /// 顶部菜单和工具栏
- /// </summary>
- public PdnToolBar toolBar;
- /// <summary>
- /// 底部公用工具栏
- /// </summary>
- private PanelBottom panelBottom;
- /// <summary>
- /// 主界面左侧的快捷工具栏
- /// </summary>
- public ToolsControl toolsPanel;
- /// <summary>
- /// 包含DocumentWorkspace集合的panel
- /// </summary>
- public Panel workspacePanel;
- /// <summary>
- /// 底部状态栏
- /// </summary>
- private PdnStatusBar statusBar;
- /// <summary>
- /// 要删除的工作空间位置(避免批量保存有修改的图片时关闭的工作空间位置与for循环顺序不一致)
- /// </summary>
- public int toRemoveDocumentWorkspaceIndex = -1;
- /// <summary>
- /// 图像索引窗口控制状态 -1代表activeDocumentWorkspace无变化 1、2代表进行了添加或者删除操作,需要刷新图像索引窗口内容
- /// </summary>
- public int toInitImageIndexDialogFlag = -1;
- /// <summary>
- /// 当前激活的工作空间
- /// </summary>
- private DocumentWorkspace activeDocumentWorkspace;
- /// <summary>
- /// 如果添加了新的工作空间,并且该工作空间没有被修改,则将其删除。
- /// 这将通过CreateBlankDocumentInNewWorkspace添加的最后一个工作空间确定
- /// (如果为第二个参数传递了true)
- /// </summary>
- private DocumentWorkspace initialWorkspace;
- /// <summary>
- /// 标尺标定窗口
- /// </summary>
- private RuleListForm ruleListForm;
- /// <summary>
- /// 像素跟踪窗口
- /// </summary>
- private PixelTrackingDialog pixelTrackingDialog;
- /// <summary>
- /// 图像索引窗口
- /// </summary>
- private ImageIndexDialog imageIndexDialog;
- /// <summary>
- /// 交互测量
- /// </summary>
- private GeometryMeasureDialog geometryMeasureDialog;
- /// <summary>
- /// 脚本执行跟踪窗口
- /// </summary>
- private ScriptRunningDialog runningDialog;
- /// <summary>
- /// 直方图窗口
- /// </summary>
- private HistogramDialog histogramDialog;
- /// <summary>
- /// 脚本管理窗口
- /// </summary>
- private ScriptManageDialog scriptManageDialog;
- /// <summary>
- /// 划痕处理窗口
- /// </summary>
- private ScratchTreatmentDialog scratchTreatmentDialog;
- /// <summary>
- /// 污迹处理窗口
- /// </summary>
- private SmudgeTreatmentDialog smudgeTreatmentDialog;
- /// <summary>
- /// 标注列表窗口
- /// </summary>
- private LabelListDialog labelListDialog;
- /// <summary>
- /// 工作流程窗口
- /// </summary>
- public WorkFlowDialog workFlowDialog;
- /// <summary>
- /// 测量列表窗口
- /// </summary>
- public MeasureListDialog measureListDialog;
- /// <summary>
- /// 光密度窗口
- /// </summary>
- public OpticalDensityDialog opticalDensityDialog;
- /// <summary>
- /// 项目工程窗口
- /// </summary>
- public ProjectEngineering projectEngineering;
- /// <summary>
- /// 图像预览窗口
- /// </summary>
- public CameraPreviewDialog cameraPreviewDialog;
- #endregion
- /// <summary>
- /// 工作空间集合,打开的图像
- /// </summary>
- private List<DocumentWorkspace> documentWorkspaces = new List<DocumentWorkspace>();
- /// <summary>
- /// 保存了许多可浮动的窗口,为了统一管理,供外部调用
- /// </summary>
- private WorkspaceWidgets widgets;
- /// <summary>
- /// 最近打开的文件
- /// </summary>
- private MostRecentFiles mostRecentFiles = null;
- /// <summary>
- /// 最近打开的文件的最大默认数量
- /// </summary>
- private const int defaultMostRecentFilesMax = 8;
- private SnapObstacleController snapObstacle;
- private bool addedToSnapManager = false;
- private int ignoreUpdateSnapObstacle = 0;
- //private XmlSaveModel xmlSaveModel;
- /// <summary>
- /// 是否循环播放
- /// </summary>
- private bool isLoopPlayback = false;
- /// <summary>
- /// 播放模式 1.后到前;2.前到后
- /// </summary>
- private int playMode = 2;
- /// <summary>
- /// 播放使用的定时器
- /// </summary>
- private Timer timer;
- /// <summary>
- /// 锁定扩缩标记
- /// </summary>
- public bool isLockZoom = false;
- /// <summary>
- /// 锁定扩缩的百分比
- /// </summary>
- public double lockScaleRatio = 0;
- /// <summary>
- /// 当前是否自动运行着脚本
- /// </summary>
- private bool scriptAutomatic = false;
- /// <summary>
- /// 当前是否运行着脚本
- /// </summary>
- private bool scriptRunning = false;
- /// <summary>
- /// 当前是否等待着脚本继续执行
- /// </summary>
- private bool scriptStopping = false;
- private Form form;
- /// <summary>
- /// 测量连续绘制
- /// </summary>
- public bool continuousDrawingMeasure = false;
- /// <summary>
- /// 标记连续绘制
- /// </summary>
- public bool continuousDrawingLabel = false;
- public DrawToolType activeTool = DrawToolType.Pointer;
- /// <summary>
- /// 录制脚本时带入的
- /// </summary>
- public List<mic_script_step> micScriptStepList = new List<mic_script_step>();
- public Dictionary<mic_script_step, List<Args>> micScriptStepParamList = new Dictionary<mic_script_step, List<Args>>();
- /// <summary>
- /// 录制脚本时添加的
- /// </summary>
- public List<mic_script_step> addMicScriptStepList = new List<mic_script_step>();
- public Dictionary<mic_script_step, List<Args>> addMicScriptStepParamList = new Dictionary<mic_script_step, List<Args>>();
- /// <summary>
- /// 是否开启脚本录制
- /// </summary>
- public bool startScriptRecording = false;
- /// <summary>
- /// 脚本录制是否编辑
- /// </summary>
- public bool editScriptRecording = false;
- /// <summary>
- /// 脚本录制是否编辑
- /// </summary>
- public mic_script ScriptRecordingModel;
- public PanelBottom PanelBottom
- {
- get
- {
- return this.panelBottom;
- }
- }
- public bool ScriptAutomatic
- {
- get
- {
- return this.scriptAutomatic;
- }
- set
- {
- this.scriptAutomatic = value;
- }
- }
- public bool ScriptRunning
- {
- get
- {
- return this.scriptRunning;
- }
- set
- {
- this.scriptRunning = value;
- }
- }
- public void SetScriptRunning(Boolean value)
- {
- this.scriptRunning = value;
- }
- public bool GetScriptRunning()
- {
- return this.scriptRunning;
- }
- public bool ScriptStopping
- {
- get
- {
- return this.scriptStopping;
- }
- set
- {
- this.scriptStopping = value;
- //if (value == false)
- // this.ResumeScriptRunning();
- }
- }
- public void SetScriptStopping(Boolean value)
- {
- this.ScriptStopping = value;
- }
- public bool GetScriptStopping()
- {
- return this.scriptStopping;
- }
- public Data.Param.ParamObject ScriptCurrentParam
- {
- set
- {
- if (this.ScriptDialog != null) this.ScriptDialog.ScriptCurrentParam = value;
- }
- get
- {
- if (this.ScriptDialog != null) return this.ScriptDialog.ScriptCurrentParam;
- else return null;
- }
- }
- public void ShutDownScriptRunning()
- {
- if (this.ScriptDialog != null) this.ScriptDialog.ShutDownScriptRunning();
- }
- public void ResumeScriptRunning()
- {
- if (this.ScriptDialog != null/* && !this.ScriptDialog.IsDisposed*/) this.ScriptDialog.ResumeScriptRunning();
- }
- private void DocumentWorkspace_DrawGridChanged(object sender, EventArgs e)
- {
- DrawGrid = this.activeDocumentWorkspace.DrawGrid;
- }
- /*private void ViewConfigStrip_DrawGridChanged(object sender, EventArgs e)
- {
- DrawGrid = ((ViewConfigStrip)sender).DrawGrid;
- }*/
- /// <summary>
- /// 绘制像素网格的flag
- /// </summary>
- private bool DrawGrid
- {
- get
- {
- return false;// this.Widgets.ViewConfigStrip.DrawGrid;
- }
- set
- {
- if (this.Widgets.ViewConfigStrip.DrawGrid != value)
- {
- this.Widgets.ViewConfigStrip.DrawGrid = value;
- }
- if (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.DrawGrid != value)
- {
- this.activeDocumentWorkspace.DrawGrid = value;
- }
- Settings.CurrentUser.SetBoolean(SettingNames.DrawGrid, this.DrawGrid);
- }
- }
- /// <summary>
- /// 单位改变事件
- /// </summary>
- public event EventHandler UnitsChanged;
- protected virtual void OnUnitsChanged()
- {
- if (UnitsChanged != null)
- {
- UnitsChanged(this, EventArgs.Empty);
- }
- }
- public MeasurementUnit Units
- {
- get
- {
- return Startup.instance.measurementUnit;//this.widgets.ViewConfigStrip.Units;
- }
- set
- {
- //this.widgets.ViewConfigStrip.Units = value;
- }
- }
- public SnapObstacle SnapObstacle
- {
- get
- {
- if (this.snapObstacle == null)
- {
- this.snapObstacle = new SnapObstacleController(
- this.Name,
- Rectangle.Empty,
- SnapRegion.Interior,
- true);
- this.snapObstacle.EnableSave = false;
- PdnBaseForm pdbForm = FindForm() as PdnBaseForm;
- pdbForm.Moving += new MovingEventHandler(ParentForm_Moving);
- pdbForm.Move += new EventHandler(ParentForm_Move);
- pdbForm.ResizeEnd += new EventHandler(ParentForm_ResizeEnd);
- pdbForm.Layout += new LayoutEventHandler(ParentForm_Layout);
- pdbForm.SizeChanged += new EventHandler(ParentForm_SizeChanged);
- UpdateSnapObstacle();
- }
- return this.snapObstacle;
- }
- }
- private void ParentForm_Move(object sender, EventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void ParentForm_SizeChanged(object sender, EventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void ParentForm_Layout(object sender, LayoutEventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void ParentForm_ResizeEnd(object sender, EventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void ParentForm_Moving(object sender, MovingEventArgs e)
- {
- UpdateSnapObstacle();
- }
- private void SuspendUpdateSnapObstacle()
- {
- ++this.ignoreUpdateSnapObstacle;
- }
- private void ResumeUpdateSnapObstacle()
- {
- --this.ignoreUpdateSnapObstacle;
- }
- /// <summary>
- /// 更新快照
- /// </summary>
- private void UpdateSnapObstacle()
- {
- if (this.ignoreUpdateSnapObstacle > 0)
- {
- return;
- }
- if (this.snapObstacle == null)
- {
- return;
- }
- if (!this.addedToSnapManager)
- {
- SnapManager sm = SnapManager.FindMySnapManager(this);
- if (sm != null)
- {
- SnapObstacle so = this.SnapObstacle;
- if (!this.addedToSnapManager)
- {
- sm.AddSnapObstacle(this.SnapObstacle);
- this.addedToSnapManager = true;
- FindForm().Shown += new EventHandler(AppWorkspace_Shown);
- }
- }
- }
- if (this.snapObstacle != null)
- {
- Rectangle clientRect;
- if (ActiveDocumentWorkspace != null)
- {
- clientRect = ActiveDocumentWorkspace.VisibleViewRectangle;
- }
- else
- {
- clientRect = this.workspacePanel.ClientRectangle;
- }
- Rectangle screenRect = this.workspacePanel.RectangleToScreen(clientRect);
- this.snapObstacle.SetBounds(screenRect);
- this.snapObstacle.Enabled = this.Visible && this.Enabled;
- try
- {
- //this.ActiveDocumentWorkspace.PanelBottom.documentStrip.Width = screenRect.Width - this.ActiveDocumentWorkspace.PanelBottom.locationX;
- }
- catch (Exception)
- {
- // throw;
- }
- }
- }
- private void AppWorkspace_Shown(object sender, EventArgs e)
- {
- UpdateSnapObstacle();
- }
- protected override void OnLayout(LayoutEventArgs levent)
- {
- UpdateSnapObstacle();
- base.OnLayout(levent);
- }
- protected override void OnLocationChanged(EventArgs e)
- {
- UpdateSnapObstacle();
- base.OnLocationChanged(e);
- }
- protected override void OnSizeChanged(EventArgs e)
- {
- UpdateSnapObstacle();
- base.OnSizeChanged(e);
- }
- protected override void OnEnabledChanged(EventArgs e)
- {
- UpdateSnapObstacle();
- base.OnEnabledChanged(e);
- }
- protected override void OnVisibleChanged(EventArgs e)
- {
- UpdateSnapObstacle();
- base.OnVisibleChanged(e);
- }
- public void ResetFloatingForms()
- {
- ResetFloatingForm(Widgets.RuleListForm);
- ResetFloatingForm(Widgets.PixelTrackingDialog);
- ResetFloatingForm(Widgets.ImageIndexDialog);
- ResetFloatingForm(Widgets.GeometryMeasureDialog);
- ResetFloatingForm(Widgets.RunningDialog);
- ResetFloatingForm(Widgets.HistogramDialog);
- ResetFloatingForm(Widgets.ScratchTreatmentDialog);
- ResetFloatingForm(Widgets.SmudgeTreatmentDialog);
- ResetFloatingForm(Widgets.LabelListDialog);
- ResetFloatingForm(Widgets.WorkFlowDialog);
- ResetFloatingForm(Widgets.MeasureListDialog);
- ResetFloatingForm(Widgets.OpticalDensityDialog);
- ResetFloatingForm(Widgets.ProjectEngineering);
- }
- public void ResetFloatingForm(FloatingToolForm ftf)
- {
- SnapManager sm = SnapManager.FindMySnapManager(this);
- if (ftf == Widgets.RuleListForm)
- {
- sm.ParkObstacle(Widgets.RuleListForm, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.PixelTrackingDialog)
- {
- sm.ParkObstacle(Widgets.PixelTrackingDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.ImageIndexDialog)
- {
- sm.ParkObstacle(Widgets.ImageIndexDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.GeometryMeasureDialog)
- {
- sm.ParkObstacle(Widgets.GeometryMeasureDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.RunningDialog)
- {
- sm.ParkObstacle(Widgets.RunningDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.HistogramDialog)
- {
- sm.ParkObstacle(Widgets.HistogramDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.ScratchTreatmentDialog)
- {
- sm.ParkObstacle(Widgets.ScratchTreatmentDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.SmudgeTreatmentDialog)
- {
- sm.ParkObstacle(Widgets.SmudgeTreatmentDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.LabelListDialog)
- {
- sm.ParkObstacle(Widgets.LabelListDialog, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.WorkFlowDialog)
- {
- sm.ParkObstacle(Widgets.WorkFlowDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.MeasureListDialog)
- {
- sm.ParkObstacle(Widgets.MeasureListDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.OpticalDensityDialog)
- {
- sm.ParkObstacle(Widgets.OpticalDensityDialog, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
- }
- else if (ftf == Widgets.ProjectEngineering)
- {
- sm.ParkObstacle(Widgets.ProjectEngineering, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
- }
- else
- {
- throw new ArgumentException();
- }
- }
- public PdnToolBar ToolBar
- {
- get
- {
- return this.toolBar;
- }
- }
- public MostRecentFiles MostRecentFiles
- {
- get
- {
- if (this.mostRecentFiles == null)
- {
- this.mostRecentFiles = new MostRecentFiles(defaultMostRecentFilesMax);
- }
- return this.mostRecentFiles;
- }
- }
- private void DocumentWorkspace_DocumentChanging(object sender, EventArgs<Document> e)
- {
- UI.SuspendControlPainting(this);
- }
- private void DocumentWorkspace_DocumentChanged(object sender, EventArgs e)
- {
- UpdateDocInfoInStatusBar();
- this.UpdatePixelTracking();
- UI.ResumeControlPainting(this);
- Invalidate(true);
- }
- private void CoordinatesToStrings(int x, int y, out string xString, out string yString, out string unitsString)
- {
- this.activeDocumentWorkspace.Document.CoordinatesToStrings(this.Units, x, y, out xString, out yString, out unitsString);
- }
- /// <summary>
- /// 更新右下角坐标信息
- /// </summary>
- /// <param name="cursorX"></param>
- /// <param name="cursorY"></param>
- private void UpdateCursorInfoInStatusBar(int cursorX, int cursorY)
- {
- SuspendLayout();
- if (this.activeDocumentWorkspace == null ||
- this.activeDocumentWorkspace.Document == null)
- {
- this.statusBar.CursorInfoText = string.Empty;
- }
- else
- {
- string xString;
- string yString;
- string units;
- CoordinatesToStrings(cursorX, cursorY, out xString, out yString, out units);
- string cursorText = string.Format(
- CultureInfo.InvariantCulture,
- PdnResources.GetString("StatusBar.CursorInfo.Format"),
- xString,
- units,
- yString,
- units);
- //this.statusBar.CursorInfoText = cursorText;
- }
- ResumeLayout(false);
- }
- /// <summary>
- /// 更新底部状态栏的文字等
- /// 需要修改为显示标尺相关的信息
- /// </summary>
- public void UpdateDocInfoInStatusBar()
- {
- if (this.activeDocumentWorkspace != null)
- {
- if (this.activeDocumentWorkspace.xmlSaveModel == null)
- {
- this.statusBar.ImageInfoStatusText = PdnResources.GetString("Menu.Unselectedruler.Text");
- this.statusBar.CursorInfoText = PdnResources.GetString("Menu.Defaultis1micron/pixel.Text");
- }
- else
- {
- //选中图片是否有配置文件
- if ((ExistenceXML() && this.activeDocumentWorkspace.xmlSaveModel.pixel_length != 0) || (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.xmlSaveModel != null && this.activeDocumentWorkspace.xmlSaveModel.pixel_length != 0))
- {
- this.statusBar.ImageInfoStatusText = this.activeDocumentWorkspace.xmlSaveModel.ruler_name;
- double unitLength = (double)(this.activeDocumentWorkspace.xmlSaveModel.physical_length / (decimal)this.activeDocumentWorkspace.xmlSaveModel.pixel_length);
- 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");
- }
- else
- {
- this.statusBar.ImageInfoStatusText = Startup.instance.ruleDB.ruler_name;
- 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");
- }
- }
- }
- /*if (this.activeDocumentWorkspace == null ||
- this.activeDocumentWorkspace.Document == null)
- {
- this.statusBar.ImageInfoStatusText = string.Empty;
- }
- else if (this.activeDocumentWorkspace != null &&
- this.activeDocumentWorkspace.Document != null)
- {
- string widthString;
- string heightString;
- string units;
- CoordinatesToStrings(
- this.activeDocumentWorkspace.Document.Width,
- this.activeDocumentWorkspace.Document.Height,
- out widthString,
- out heightString,
- out units);
- string imageText = string.Format(
- CultureInfo.InvariantCulture,
- this.imageInfoStatusBarFormat,
- widthString,
- units,
- heightString,
- units);
- this.statusBar.ImageInfoStatusText = imageText;
- }*/
- }
- /// <summary>
- /// 更新像素跟踪的图像
- /// </summary>
- public void UpdatePixelTracking(OpenCvSharp.Mat mat = null)
- {
- if (this.pixelTrackingDialog != null)
- {
- this.pixelTrackingDialog.Mat = mat;
- }
- }
- [Browsable(false)]
- public WorkspaceWidgets Widgets
- {
- get
- {
- return this.widgets;
- }
- }
- public HistogramDialog Histogram
- {
- get
- {
- if (this.histogramDialog != null)
- {
- return this.histogramDialog;
- }
- else
- {
- return null;
- }
- }
- }
- public ScriptManageDialog ScriptDialog
- {
- get
- {
- if (this.scriptManageDialog != null)
- {
- return this.scriptManageDialog;
- }
- else
- {
- return null;
- }
- }
- set
- {
- this.scriptManageDialog = value;
- }
- }
- public SmudgeTreatmentDialog SmudgeTreatmentDialog
- {
- get
- {
- if (this.smudgeTreatmentDialog != null)
- {
- return this.smudgeTreatmentDialog;
- }
- else
- {
- return null;
- }
- }
- set
- {
- this.smudgeTreatmentDialog = value;
- }
- }
- public ScratchTreatmentDialog ScratchTreatmentDialog
- {
- get
- {
- if (this.scratchTreatmentDialog != null)
- {
- return this.scratchTreatmentDialog;
- }
- else
- {
- return null;
- }
- }
- set
- {
- this.scratchTreatmentDialog = value;
- }
- }
- [Browsable(false)]
- public DocumentWorkspace[] ScriptWorkspaces
- {
- get
- {
- List<DocumentWorkspace> scriptWorkspaces = new List<DocumentWorkspace>();
- for (int index = 0; index < this.documentWorkspaces.Count; index++)
- {
- DocumentWorkspace workspace = this.documentWorkspaces[index];
- if (workspace.OpenInScriptRunning)
- {
- scriptWorkspaces.Add(workspace);
- }
- }
- if (scriptWorkspaces.Count > 0)
- return scriptWorkspaces.ToArray();
- else
- return null;
- }
- }
- public DocumentWorkspace ActiveDocumentWorkspace
- {
- get
- {
- return this.activeDocumentWorkspace;
- }
- set
- {
- if (value != this.activeDocumentWorkspace)
- {
- if (value != null &&
- this.documentWorkspaces.IndexOf(value) == -1)
- {
- throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
- }
- bool focused = false;
- if (this.activeDocumentWorkspace != null)
- {
- focused = this.activeDocumentWorkspace.Focused;
- }
- UI.SuspendControlPainting(this);
- OnActiveDocumentWorkspaceChanging();
- this.activeDocumentWorkspace = value;
- if (this.toInitImageIndexDialogFlag != 2)
- {
- this.toInitImageIndexDialogFlag = 1;
- }
- OnActiveDocumentWorkspaceChanged();
- this.toInitImageIndexDialogFlag = -1;
- UI.ResumeControlPainting(this);
- Refresh();
- if (value != null)
- {
- value.Focus();
- }
- //if (this.histogramDialog != null) this.histogramDialog.ResetMat();
- //backupImage
- if (value != null && value.needBackup)
- {
- FileOperationHelper.BackupImages(value.CompositionSurface.CreateAliasedBitmap(), value.GetFriendlyName(), value.FilePath);
- value.needBackup = false;
- }
- }
- }
- }
- private void ActiveDocumentWorkspace_FirstInputAfterGotFocus(object sender, EventArgs e)
- {
- this.toolBar.DocumentStrip.EnsureItemFullyVisible(this.toolBar.DocumentStrip.SelectedDocumentIndex);
- }
- public DocumentWorkspace[] DocumentWorkspaces
- {
- get
- {
- return this.documentWorkspaces.ToArray();
- }
- }
- public DocumentWorkspace AddNewDocumentWorkspace()
- {
- if (this.initialWorkspace != null)
- {
- if (this.initialWorkspace.Document == null || !this.initialWorkspace.Document.Dirty)
- {
- RemoveDocumentWorkspace(this.initialWorkspace);
- this.initialWorkspace = null;
- }
- }
- DocumentWorkspace dw = new DocumentWorkspace(this);
- dw.AppWorkspace = this;
- dw.ContinuousDrawingLabel = this.continuousDrawingLabel;
- dw.ContinuousDrawingMeasure = this.continuousDrawingMeasure;
- dw.activeTool = this.activeTool;
- this.documentWorkspaces.Add(dw);
- this.toolBar.DocumentStrip.AddDocumentWorkspace(dw);
- return dw;
- }
- public DocumentWorkspace NewDocumentWorkspace()
- {
- if (this.initialWorkspace != null)
- {
- if (this.initialWorkspace.Document == null || !this.initialWorkspace.Document.Dirty)
- {
- RemoveDocumentWorkspace(this.initialWorkspace);
- this.initialWorkspace = null;
- }
- }
- DocumentWorkspace dw = new DocumentWorkspace(this);
- dw.AppWorkspace = this;
- dw.ContinuousDrawingLabel = this.continuousDrawingLabel;
- dw.ContinuousDrawingMeasure = this.continuousDrawingMeasure;
- dw.activeTool = this.activeTool;
- return dw;
- }
- public bool DisplayShoot(Bitmap image, GraphicsList graphicsList, bool hasRuler, int mode = 0)
- {
- if (Widgets.ImageIndexDialog.Visible)
- {
- Startup.instance.configModel.Txt1 = Widgets.ImageIndexDialog.comboBox_T1.Text;
- Startup.instance.configModel.Txt2 = Widgets.ImageIndexDialog.comboBox_T2.Text;
- Startup.instance.configModel.Txt3 = Widgets.ImageIndexDialog.comboBox_T2.Text;
- }
- string photoName;
- if (Startup.instance.ruleDB == null)
- {
- photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, "默认标尺", "0");
- }
- else
- {
- photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, Startup.instance.ruleDB.ruler_name, Startup.instance.ruleDB.gain_multiple.ToString());
- }
- UpdateContinueNum();
- Widgets.ImageIndexDialog.PreviewRefresh();
- DocumentWorkspace dw = NewDocumentWorkspace();
- dw.fileText = photoName;
- Document document = Document.FromMat(BitmapConverter.ToMat(image));
- document.Dirty = true;
- dw.Document = document;
- //dw.rules = new Dictionary<MeasurementUnit, double>(Startup.instance.rules);
- dw.xmlSaveModel = Startup.instance.ruleDB;
- dw.InitRulerInfo(); //激活
- //如果绘制了标注、测量,则需要深度copy过去
- if (graphicsList?.Count > 0)
- {
- for (int i = 0; i < graphicsList.Count; i++)
- {
- DrawObject mobject = graphicsList[i].Clone(dw);
- mobject.Selected = false;
- dw.GraphicsList.Add(mobject);
- }
- }
- //绘制标尺
- if (hasRuler)
- {
- bool needResetDB = false;
- decimal oldGainNumber = dw.GetGainMultiple();
- Dictionary<MeasurementUnit, double> measurementUnitDictionary = this.getMeasureInfo();
- MeasurementUnit unit = this.Units;
- double oldRatio = measurementUnitDictionary[unit];//每像素多少长度
- //mic_rulers mic_Ruler = (mic_rulers)this.comboBox1.SelectedValue;
- mic_rulers mic_Ruler = dw.xmlSaveModel;
- if (Startup.instance.ruleDB == null)
- {
- Startup.instance.ruleDB = new mic_rulers();
- needResetDB = true;
- }
- Startup.instance.ruleDB.gain_multiple = mic_Ruler.gain_multiple;
- double micronRatio;
- Startup.instance.rules.TryGetValue(unit, out micronRatio);
- Startup.instance.rules[unit] = micronRatio;
- dw.ActiveTool = Annotation.Enum.DrawToolType.DrawAutoRuler;
- dw.Units = unit;
- if (needResetDB)
- Startup.instance.ruleDB = null;
- else
- Startup.instance.ruleDB.gain_multiple = oldGainNumber;
- Startup.instance.rules[unit] = oldRatio;
- }
- dw.Refresh();
- switch (mode)
- {
- case 0:
- case 2:
- Add(dw);
- break;
- case 1:
- return dw.DoSaveAsNew(mode);
- case 3:
- var result = dw.DoSaveAsNew(mode);
- if (!result) return result; Add(dw);
- break;
- }
- ActiveDocumentWorkspace = dw;
- if (isLockZoom && lockScaleRatio > 0)
- {
- ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(lockScaleRatio);
- SetZoonTrackValue(ActiveDocumentWorkspace.ScaleFactor);
- }
- else
- {
- ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- }
- return true;
- }
- private void Add(DocumentWorkspace dw)
- {
- this.documentWorkspaces.Add(dw);
- this.toolBar.DocumentStrip.AddDocumentWorkspace(dw);
- }
- public void RemoveDocumentWorkspace(DocumentWorkspace documentWorkspace)
- {
- int dwIndex = this.documentWorkspaces.IndexOf(documentWorkspace);
- if (dwIndex == -1)
- {
- throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
- }
- bool removingCurrentDW;
- if (this.ActiveDocumentWorkspace == documentWorkspace)
- {
- removingCurrentDW = true;
- }
- else
- {
- removingCurrentDW = false;
- }
- this.toInitImageIndexDialogFlag = 2;
- // Choose new active DW if removing the current DW
- if (removingCurrentDW)
- {
- if (this.documentWorkspaces.Count == 1)
- {
- this.ActiveDocumentWorkspace = null;
- }
- else if (dwIndex == 0)
- {
- this.ActiveDocumentWorkspace = this.documentWorkspaces[1];
- }
- else
- {
- this.ActiveDocumentWorkspace = this.documentWorkspaces[dwIndex - 1];
- }
- }
- this.toInitImageIndexDialogFlag = 1;
- this.documentWorkspaces.Remove(documentWorkspace);
- this.toolBar.DocumentStrip.RemoveDocumentWorkspace(documentWorkspace);
- //刷新图像索引窗口
- if ((this.activeDocumentWorkspace == null || this.activeDocumentWorkspace != null && this.toInitImageIndexDialogFlag == 1)
- && ImageIndexDialog.imageIndexDialog != null)
- ImageIndexDialog.imageIndexDialog.InitData();
- this.toInitImageIndexDialogFlag = -1;
- if (this.initialWorkspace == documentWorkspace)
- {
- this.initialWorkspace = null;
- }
- // Clean up the DocumentWorkspace
- Document document = documentWorkspace.Document;
- documentWorkspace.Document = null;
- document.Dispose();
- documentWorkspace.Dispose();
- documentWorkspace = null;
- }
- public event EventHandler ActiveDocumentWorkspaceChanging;
- protected virtual void OnActiveDocumentWorkspaceChanging()
- {
- //如果定时器在运行则先关闭
- if (timer.Enabled)
- timer.Enabled = false;
- SuspendUpdateSnapObstacle();
- if (ActiveDocumentWorkspaceChanging != null)
- {
- ActiveDocumentWorkspaceChanging(this, EventArgs.Empty);
- }
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.FirstInputAfterGotFocus +=
- ActiveDocumentWorkspace_FirstInputAfterGotFocus;
- this.activeDocumentWorkspace.RulersEnabledChanged -= this.DocumentWorkspace_RulersEnabledChanged;
- this.activeDocumentWorkspace.DocumentMouseEnter -= this.DocumentMouseEnterHandler;
- this.activeDocumentWorkspace.DocumentMouseLeave -= this.DocumentMouseLeaveHandler;
- this.activeDocumentWorkspace.DocumentMouseMove -= this.DocumentMouseMoveHandler;
- this.activeDocumentWorkspace.DocumentMouseDown -= this.DocumentMouseDownHandler;
- this.activeDocumentWorkspace.Scroll -= this.DocumentWorkspace_Scroll;
- this.activeDocumentWorkspace.Layout -= this.DocumentWorkspace_Layout;
- this.activeDocumentWorkspace.DrawGridChanged -= this.DocumentWorkspace_DrawGridChanged;
- this.activeDocumentWorkspace.DocumentClick -= this.DocumentClick;
- this.activeDocumentWorkspace.DocumentMouseUp -= this.DocumentMouseUpHandler;
- this.activeDocumentWorkspace.DocumentKeyPress -= this.DocumentKeyPress;
- this.activeDocumentWorkspace.DocumentKeyUp -= this.DocumenKeyUp;
- this.activeDocumentWorkspace.DocumentKeyDown -= this.DocumentKeyDown;
- this.activeDocumentWorkspace.StatusChanged -= OnDocumentWorkspaceStatusChanged;
- this.activeDocumentWorkspace.DocumentChanging -= DocumentWorkspace_DocumentChanging;
- this.activeDocumentWorkspace.DocumentChanged -= DocumentWorkspace_DocumentChanged;
- //this.activeDocumentWorkspace.ScaleFactorChanged -= ZoomChangedHandler;
- //this.activeDocumentWorkspace.ZoomBasisChanged -= DocumentWorkspace_ZoomBasisChanged;
- this.activeDocumentWorkspace.Visible = false;
- this.activeDocumentWorkspace.ToolChanging -= this.ToolChangingHandler;
- this.activeDocumentWorkspace.ToolChanged -= this.ToolChangedHandler;
- }
- ResumeUpdateSnapObstacle();
- UpdateSnapObstacle();
- }
- public event EventHandler ActiveDocumentWorkspaceChanged;
- protected virtual void OnActiveDocumentWorkspaceChanged()
- {
- SuspendUpdateSnapObstacle();
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.SuspendLayout();
- this.activeDocumentWorkspace.BackColor = System.Drawing.SystemColors.ControlDark;
- this.activeDocumentWorkspace.Dock = System.Windows.Forms.DockStyle.Fill;
- this.activeDocumentWorkspace.DrawGrid = this.DrawGrid;
- this.activeDocumentWorkspace.PanelAutoScroll = true;
- this.activeDocumentWorkspace.RulersEnabled = Settings.CurrentUser.GetBoolean(SettingNames.Rulers, true);
- this.activeDocumentWorkspace.AuxiliaryLineEnabled = Settings.CurrentUser.GetBoolean(SettingNames.DrawAuxiliaryLine, true);
- this.activeDocumentWorkspace.TabIndex = 0;
- this.activeDocumentWorkspace.TabStop = false;
- this.activeDocumentWorkspace.RulersEnabledChanged += this.DocumentWorkspace_RulersEnabledChanged;
- this.activeDocumentWorkspace.DocumentMouseEnter += this.DocumentMouseEnterHandler;
- this.activeDocumentWorkspace.DocumentMouseLeave += this.DocumentMouseLeaveHandler;
- this.activeDocumentWorkspace.DocumentMouseMove += this.DocumentMouseMoveHandler;
- this.activeDocumentWorkspace.DocumentMouseDown += this.DocumentMouseDownHandler;
- this.activeDocumentWorkspace.Scroll += this.DocumentWorkspace_Scroll;
- this.activeDocumentWorkspace.DrawGridChanged += this.DocumentWorkspace_DrawGridChanged;
- this.activeDocumentWorkspace.DocumentClick += this.DocumentClick;
- this.activeDocumentWorkspace.DocumentMouseUp += this.DocumentMouseUpHandler;
- this.activeDocumentWorkspace.DocumentKeyPress += this.DocumentKeyPress;
- this.activeDocumentWorkspace.DocumentKeyUp += this.DocumenKeyUp;
- this.activeDocumentWorkspace.DocumentKeyDown += this.DocumentKeyDown;
- //TODO 全局判断
- this.activeDocumentWorkspace.ActiveTool = this.activeTool;
- if (this.workspacePanel.Controls.Contains(this.activeDocumentWorkspace))
- {
- this.activeDocumentWorkspace.Visible = true;
- }
- else
- {
- this.activeDocumentWorkspace.Dock = DockStyle.Fill;
- this.workspacePanel.Controls.Add(this.activeDocumentWorkspace);
- }
- this.activeDocumentWorkspace.Layout += this.DocumentWorkspace_Layout;
- //this.toolBar.ViewConfigStrip.ScaleFactor = this.activeDocumentWorkspace.ScaleFactor;
- //this.toolBar.ViewConfigStrip.ZoomBasis = this.activeDocumentWorkspace.ZoomBasis;
- this.activeDocumentWorkspace.AppWorkspace = this;
- this.activeDocumentWorkspace.StatusChanged += OnDocumentWorkspaceStatusChanged;
- this.activeDocumentWorkspace.DocumentChanging += DocumentWorkspace_DocumentChanging;
- this.activeDocumentWorkspace.DocumentChanged += DocumentWorkspace_DocumentChanged;
- //this.activeDocumentWorkspace.ScaleFactorChanged += ZoomChangedHandler;
- //this.activeDocumentWorkspace.ZoomBasisChanged += DocumentWorkspace_ZoomBasisChanged;
- //this.activeDocumentWorkspace.Units = this.widgets.ViewConfigStrip.Units;
- this.activeDocumentWorkspace.ToolChanging += this.ToolChangingHandler;
- this.activeDocumentWorkspace.ToolChanged += this.ToolChangedHandler;
- this.toolBar.DocumentStrip.SelectDocumentWorkspace(this.activeDocumentWorkspace);
- //切换相
- this.PanelBottom.documentStrip.ClearPhase();
- this.PanelBottom.documentStrip.AddPhase(this.activeDocumentWorkspace.phaseModels);
- //处理像素跟踪
- if (this.pixelTrackingDialog != null) this.pixelTrackingDialog.Mat = null;
- //Bitmap map = this.activeDocumentWorkspace.SurfaceBox.Surface.CreateAliasedBitmap();
- ////oldMat = OpenCvSharp.Extensions.BitmapConverter.ToMat(map);
- //if (this.histogramDialog != null) this.histogramDialog.Mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(map);// null;
- //处理底部缩放百分比的trackbar和textbox
- this.SetZoonTrackValue(this.activeDocumentWorkspace.ScaleFactor);
- this.activeDocumentWorkspace.ResumeLayout();
- this.activeDocumentWorkspace.PerformLayout();
- this.activeDocumentWorkspace.FirstInputAfterGotFocus += ActiveDocumentWorkspace_FirstInputAfterGotFocus;
- //更新信息
- this.UpdateDocInfoInStatusBar();
- //判断当前对象是否是zip的,如果是则需要处理右下角按钮及读取图片
- if (this.activeDocumentWorkspace.zipXmlModel == null)
- {
- this.PanelBottom.documentStrip.ShowPictures = false;
- }
- else
- {
- this.PanelBottom.documentStrip.ShowPictures = true;
- this.PanelBottom.documentStrip.trackBar.Maximum = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
- PicName oldPicName = this.activeDocumentWorkspace.zipXmlModel.picNameList.Find(a => a.name == this.activeDocumentWorkspace.picName);
- this.panelBottom.documentStrip.trackBar.Value = this.activeDocumentWorkspace.zipXmlModel.picNameList.IndexOf(oldPicName) + 1;
- this.PanelBottom.documentStrip.textBox.Text = this.PanelBottom.documentStrip.trackBar.Value + @"/" + this.PanelBottom.documentStrip.trackBar.Maximum;
- ChangeImageInActiveDocument(this.panelBottom.documentStrip.trackBar.Value);
- }
- }
- if (ActiveDocumentWorkspaceChanged != null)
- {
- ActiveDocumentWorkspaceChanged(this, EventArgs.Empty);
- }
- UpdateStatusBarContextStatus();
- ResumeUpdateSnapObstacle();
- UpdateSnapObstacle();
- if (this.activeDocumentWorkspace != null)
- {
- if (!this.activeDocumentWorkspace.ContinuousDrawingMeasure
- && this.activeDocumentWorkspace.activeTool >= DrawToolType.MeasureLine && this.activeDocumentWorkspace.activeTool <= DrawToolType.MeasureThreePointArc)
- this.activeDocumentWorkspace.activeTool = DrawToolType.Pointer;
- if (!this.activeDocumentWorkspace.ContinuousDrawingLabel
- && this.activeDocumentWorkspace.activeTool >= DrawToolType.DrawRectangle && this.activeDocumentWorkspace.activeTool <= DrawToolType.DrawPrestoredRuler)
- this.activeDocumentWorkspace.activeTool = DrawToolType.Pointer;
- this.SetTopLeftCheckState();
- this.UpdateBottomButtonSelectionStatus();
- if (this.activeDocumentWorkspace.best)
- this.activeDocumentWorkspace.buttonType = 0;
- else if (this.activeDocumentWorkspace.maxMin)
- this.activeDocumentWorkspace.buttonType = 1;
- else if (this.activeDocumentWorkspace.gamma45)
- this.activeDocumentWorkspace.buttonType = 2;
- else if (this.activeDocumentWorkspace.origin)
- this.activeDocumentWorkspace.buttonType = 3;
- this.RefreshHistogram();
- RefreshOpticalDensity();
- }
- if (this.histogramDialog != null) this.histogramDialog.ResetMat();
- //if (this.activeDocumentWorkspace != null)
- //{
- // Bitmap map = this.activeDocumentWorkspace.SurfaceBox.Surface.CreateAliasedBitmap();
- // //oldMat = OpenCvSharp.Extensions.BitmapConverter.ToMat(map);
- // if (this.histogramDialog != null) this.histogramDialog.Mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(map);// null;
- //}
- //else
- //{
- // if (this.histogramDialog != null) this.histogramDialog.Mat = null;
- //}
- //刷新图像索引窗口
- if ((this.activeDocumentWorkspace == null || this.activeDocumentWorkspace != null && this.toInitImageIndexDialogFlag == 1)
- && ImageIndexDialog.imageIndexDialog != null)
- ImageIndexDialog.imageIndexDialog.InitData();
- }
- public void SetTopLeftCheckState()
- {
- if (this.toolBar != null && this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.ContinuousDrawingMeasure = this.continuousDrawingMeasure;
- this.activeDocumentWorkspace.ContinuousDrawingLabel = this.continuousDrawingLabel;
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingMeasure, "ContinuousDrawingMeasure");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingMeasure, "ContinuousDrawingMeasure");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingLabel, "ContinuousDrawingLabel");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingLabel, "ContinuousDrawingLabel");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.RulersEnabled, "ViewRuler");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.RulersEnabled, "ViewRuler");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousBinaryAction, "ContinuousOperation");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousBinaryAction, "ContinuousOperation");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ActualSize, "ActualSize");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ActualSize, "ActualSize");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.LockZoom, "LockZoom");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.LockZoom, "LockZoom");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.FixedMultiple, "FixedMultiple");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.FixedMultiple, "FixedMultiple");
- this.toolBar.RefreshBtnSelect(this.Widgets.LabelListDialog.Visible, "LabelListAction");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.LabelListDialog.Visible, "LabelListAction");
- this.toolBar.RefreshBtnSelect(this.Widgets.MeasureListDialog.Visible, "MeasureList");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.MeasureListDialog.Visible, "MeasureList");
- this.toolBar.RefreshBtnSelect(this.Widgets.RuleListForm.Visible, "SubRulerCalibration");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.RuleListForm.Visible, "SubRulerCalibration");
- this.toolBar.RefreshBtnSelect(this.Widgets.OpticalDensityDialog.Visible, "OpticalDensity");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.OpticalDensityDialog.Visible, "OpticalDensity");
- this.toolBar.RefreshBtnSelect(this.Widgets.HistogramDialog.Visible, "Histogram");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.HistogramDialog.Visible, "Histogram");
- this.toolBar.RefreshBtnSelect(this.Widgets.PixelTrackingDialog.Visible, "PixelTracking");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.PixelTrackingDialog.Visible, "PixelTracking");
- this.toolBar.RefreshBtnSelect(this.Widgets.ImageIndexDialog.Visible, "ImageIndex");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.ImageIndexDialog.Visible, "ImageIndex");
- this.toolBar.RefreshBtnSelect(this.Widgets.GeometryMeasureDialog.Visible, "Geometry");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.GeometryMeasureDialog.Visible, "Geometry");
- this.toolBar.RefreshBtnSelect(this.Widgets.WorkFlowDialog.Visible, "WorkFlow");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.WorkFlowDialog.Visible, "WorkFlow");
- this.toolBar.RefreshBtnSelect(this.Widgets.ScratchTreatmentDialog.Visible, "ScratchTreatment");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.ScratchTreatmentDialog.Visible, "ScratchTreatment");
- this.toolBar.RefreshBtnSelect(this.Widgets.SmudgeTreatmentDialog.Visible, "SmudgeTreatment");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.SmudgeTreatmentDialog.Visible, "SmudgeTreatment");
- this.toolBar.RefreshBtnSelect(this.Widgets.ProjectEngineering.Visible, "OpenProject");
- this.toolsPanel.RefreshBtnSelect(this.Widgets.ProjectEngineering.Visible, "OpenProject");
- if (!this.activeDocumentWorkspace.DeleteFieldOfView)
- this.activeDocumentWorkspace.MergeFieldOfView = true;
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
- }
- }
- public AppWorkspace(Form form)
- {
- this.form = form;
- SuspendLayout();
- // initialize!
- InitializeComponent();
- InitializeFloatingForms();
- //初始化相机列表
- this.toolBar.MainMenu.imageCollectionMenu.InitCameraList();
- //this.toolBar.ToolChooserStrip.ToolClicked += new ToolClickedEventHandler(this.MainToolBar_ToolClicked);
- this.toolBar.AppWorkspace = this;
- // init the Widgets container
- this.widgets = new WorkspaceWidgets(this);
- //this.widgets.ViewConfigStrip = this.toolBar.ViewConfigStrip;
- //this.widgets.CommonActionsStrip = this.toolBar.CommonActionsStrip;
- this.Widgets.RuleListForm = this.ruleListForm;
- this.Widgets.PixelTrackingDialog = this.pixelTrackingDialog;
- this.Widgets.ImageIndexDialog = this.imageIndexDialog;
- this.Widgets.GeometryMeasureDialog = this.geometryMeasureDialog;
- this.Widgets.RunningDialog = this.runningDialog;
- this.Widgets.HistogramDialog = this.histogramDialog;
- this.Widgets.ScratchTreatmentDialog = this.scratchTreatmentDialog;
- this.Widgets.SmudgeTreatmentDialog = this.smudgeTreatmentDialog;
- this.Widgets.LabelListDialog = this.labelListDialog;
- this.Widgets.WorkFlowDialog = this.workFlowDialog;
- this.Widgets.MeasureListDialog = this.measureListDialog;
- this.Widgets.OpticalDensityDialog = this.opticalDensityDialog;
- this.Widgets.ProjectEngineering = this.projectEngineering;
- this.widgets.StatusBarProgress = this.statusBar;
- this.widgets.DocumentStrip = this.toolBar.DocumentStrip;
- this.toolBar.DocumentStrip.RelinquishFocus += RelinquishFocusHandler;
- //this.toolBar.CommonActionsStrip.RelinquishFocus += OnToolStripRelinquishFocus;
- //this.toolBar.CommonActionsStrip.MouseWheel += OnToolStripMouseWheel;
- /*this.toolBar.ViewConfigStrip.DrawGridChanged += ViewConfigStrip_DrawGridChanged;
- this.toolBar.ViewConfigStrip.ZoomBasisChanged += ViewConfigStrip_ZoomBasisChanged;
- this.toolBar.ViewConfigStrip.ZoomScaleChanged += ViewConfigStrip_ZoomScaleChanged;
- this.toolBar.ViewConfigStrip.ZoomIn += ViewConfigStrip_ZoomIn;
- this.toolBar.ViewConfigStrip.ZoomOut += ViewConfigStrip_ZoomOut;
- this.toolBar.ViewConfigStrip.UnitsChanged += ViewConfigStrip_UnitsChanged;
- this.toolBar.ViewConfigStrip.RelinquishFocus += OnToolStripRelinquishFocus;
- this.toolBar.ViewConfigStrip.MouseWheel += OnToolStripMouseWheel;*/
- this.toolBar.DocumentStrip.RelinquishFocus += OnToolStripRelinquishFocus;
- this.toolBar.DocumentStrip.DocumentClicked += DocumentStrip_DocumentTabClicked;
- this.toolBar.DocumentStrip.DocumentListChanged += DocumentStrip_DocumentListChanged;
- ResumeLayout();
- PerformLayout();
- this.InitializeBottomEvent();
- this.InitializePanelBottomRight();
- }
- private void DocumentStrip_DocumentListChanged(object sender, EventArgs e)
- {
- bool enableThem = (this.widgets.DocumentStrip.DocumentCount != 0);
- this.widgets.RuleListForm.Enabled = enableThem;
- this.widgets.PixelTrackingDialog.Enabled = enableThem;
- this.widgets.ImageIndexDialog.Enabled = enableThem;
- this.widgets.GeometryMeasureDialog.Enabled = enableThem;
- this.widgets.RunningDialog.Enabled = enableThem;
- this.widgets.HistogramDialog.Enabled = enableThem;
- this.widgets.ScratchTreatmentDialog.Enabled = enableThem;
- this.widgets.SmudgeTreatmentDialog.Enabled = enableThem;
- this.widgets.LabelListDialog.Enabled = enableThem;
- this.widgets.WorkFlowDialog.Enabled = enableThem;
- this.widgets.MeasureListDialog.Enabled = enableThem;
- this.widgets.OpticalDensityDialog.Enabled = enableThem;
- this.widgets.ProjectEngineering.Enabled = enableThem;
- UpdateDocInfoInStatusBar();
- UpdateCursorInfoInStatusBar(0, 0);
- }
- public void SaveSettings()
- {
- Settings.CurrentUser.SetBoolean(SettingNames.DrawGrid, this.DrawGrid);
- this.MostRecentFiles.SaveMruList();
- }
- protected override void OnLoad(EventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- this.ActiveDocumentWorkspace.Select();
- }
- UpdateSnapObstacle();
- base.OnLoad(e);
- }
- private void RelinquishFocusHandler(object sender, EventArgs e)
- {
- this.Focus();
- }
- /*private void ZoomChangedHandler(object sender, EventArgs e)
- {
- ScaleFactor sf = this.activeDocumentWorkspace.ScaleFactor;
- this.toolBar.ViewConfigStrip.SuspendEvents();
- this.toolBar.ViewConfigStrip.ZoomBasis = this.activeDocumentWorkspace.ZoomBasis;
- this.toolBar.ViewConfigStrip.ScaleFactor = sf;
- this.toolBar.ViewConfigStrip.ResumeEvents();
- }*/
- private void InitializeComponent()
- {
- this.panelBottom = new PanelBottom();
- this.toolBar = new PdnToolBar(this);
- this.statusBar = new PdnStatusBar();
- this.toolsPanel = new ToolsControl(this);
- this.workspacePanel = new Panel();
- this.workspacePanel.SuspendLayout();
- this.statusBar.SuspendLayout();
- this.SuspendLayout();
- //
- // panelBottom
- //
- this.panelBottom.Height = 30;
- this.panelBottom.Dock = DockStyle.Bottom;
- //
- // toolBar
- //
- this.toolBar.Name = "toolBar";
- this.toolBar.Dock = DockStyle.Top;
- //
- // statusBar
- //
- this.statusBar.Name = "statusBar";
- //
- // toolsPanel
- //
- this.toolsPanel.Width = 50;
- this.toolsPanel.Dock = DockStyle.Left;
- //
- // workspacePanel
- //
- this.workspacePanel.Name = "workspacePanel";
- this.workspacePanel.Dock = DockStyle.Fill;
- //
- // AppWorkspace
- //
- this.Controls.Add(this.workspacePanel);
- this.Controls.Add(this.panelBottom);
- this.Controls.Add(this.toolsPanel);
- this.Controls.Add(this.statusBar);
- this.Controls.Add(this.toolBar);
- this.Name = "AppWorkspace";
- this.Size = new System.Drawing.Size(872, 640);
- this.workspacePanel.ResumeLayout(false);
- this.statusBar.ResumeLayout(false);
- this.statusBar.PerformLayout();
- this.ResumeLayout(false);
- }
- private void DocumentStrip_DocumentTabClicked(
- object sender,
- EventArgs<Pair<DocumentWorkspace, DocumentClickAction>> e)
- {
- switch (e.Data.Second)
- {
- case DocumentClickAction.Select:
- this.ActiveDocumentWorkspace = e.Data.First;
- break;
- case DocumentClickAction.Close:
- CloseWorkspaceAction cwa = new CloseWorkspaceAction(e.Data.First);
- PerformAction(cwa);
- break;
- default:
- throw new NotImplementedException("Code for DocumentClickAction." + e.Data.Second.ToString() + " not implemented");
- }
- Update();
- }
- private void OnToolStripMouseWheel(object sender, MouseEventArgs e)
- {
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.PerformMouseWheel((Control)sender, e);
- }
- }
- private void OnToolStripRelinquishFocus(object sender, EventArgs e)
- {
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.Focus();
- }
- }
- private void DocumentMouseEnterHandler(object sender, EventArgs e)
- {
- }
- private void DocumentMouseLeaveHandler(object sender, EventArgs e)
- {
- }
- private void DocumentMouseUpHandler(object sender, MouseEventArgs e)
- {
- }
- private void DocumentMouseDownHandler(object sender, MouseEventArgs e)
- {
- }
- private void DocumentMouseMoveHandler(object sender, MouseEventArgs e)
- {
- UpdateCursorInfoInStatusBar(e.X, e.Y);
- }
- private void DocumentClick(object sender, EventArgs e)
- {
- }
- private void DocumentKeyPress(object sender, KeyPressEventArgs e)
- {
- }
- private void DocumentKeyDown(object sender, KeyEventArgs e)
- {
- }
- private void DocumenKeyUp(object sender, KeyEventArgs e)
- {
- }
- private void InitializeFloatingForms()
- {
- // RuleListForm
- ruleListForm = new RuleListForm(this);
- ruleListForm.RelinquishFocus += RelinquishFocusHandler;
- ruleListForm.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- // PixelTrackingDialog
- pixelTrackingDialog = new PixelTrackingDialog(this);
- pixelTrackingDialog.RelinquishFocus += RelinquishFocusHandler;
- pixelTrackingDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- // imageIndexDialog
- imageIndexDialog = new ImageIndexDialog(this);
- imageIndexDialog.RelinquishFocus += RelinquishFocusHandler;
- imageIndexDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- // geometryMeasureDialog
- geometryMeasureDialog = new GeometryMeasureDialog(this);
- geometryMeasureDialog.RelinquishFocus += RelinquishFocusHandler;
- geometryMeasureDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- // RunningDialog
- runningDialog = new ScriptRunningDialog(this, null);
- runningDialog.RelinquishFocus += RelinquishFocusHandler;
- runningDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- // HistogramDialog
- histogramDialog = new HistogramDialog(this);
- histogramDialog.RelinquishFocus += RelinquishFocusHandler;
- histogramDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- //ScratchTreatmentDialog
- scratchTreatmentDialog = new ScratchTreatmentDialog(this);
- scratchTreatmentDialog.RelinquishFocus += RelinquishFocusHandler;
- scratchTreatmentDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- //SmudgeTreatmentDialog
- smudgeTreatmentDialog = new SmudgeTreatmentDialog(this);
- smudgeTreatmentDialog.RelinquishFocus += RelinquishFocusHandler;
- smudgeTreatmentDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- //LabelListDialog
- labelListDialog = new LabelListDialog(this);
- labelListDialog.RelinquishFocus += RelinquishFocusHandler;
- labelListDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- // WorkFlowDialog
- workFlowDialog = new WorkFlowDialog(this);
- workFlowDialog.RelinquishFocus += RelinquishFocusHandler;
- workFlowDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- measureListDialog = new MeasureListDialog(this);
- measureListDialog.RelinquishFocus += RelinquishFocusHandler;
- measureListDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- opticalDensityDialog = new OpticalDensityDialog(this);
- opticalDensityDialog.RelinquishFocus += RelinquishFocusHandler;
- opticalDensityDialog.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- projectEngineering = new ProjectEngineering(this);
- projectEngineering.RelinquishFocus += RelinquishFocusHandler;
- projectEngineering.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
- }
- public event CmdKeysEventHandler ProcessCmdKeyEvent;
- private bool OnToolFormProcessCmdKeyEvent(object sender, ref Message msg, Keys keyData)
- {
- if (ProcessCmdKeyEvent != null)
- {
- return ProcessCmdKeyEvent(sender, ref msg, keyData);
- }
- else
- {
- return false;
- }
- }
- public void PerformActionAsync(AppWorkspaceAction performMe)
- {
- this.BeginInvoke(new Procedure<AppWorkspaceAction>(PerformAction), new object[] { performMe });
- }
- public void PerformAction(AppWorkspaceAction performMe)
- {
- Update();
- using (new WaitCursorChanger(this))
- {
- performMe.PerformAction(this);
- }
- Update();
- }
- private void ToolChangingHandler(object sender, EventArgs e)
- {
- UI.SuspendControlPainting(this.toolBar);
- }
- private void ToolChangedHandler(object sender, EventArgs e)
- {
- UpdateStatusBarContextStatus();
- UI.ResumeControlPainting(this.toolBar);
- this.toolBar.Refresh();
- }
- protected override void OnResize(EventArgs e)
- {
- UpdateSnapObstacle();
- base.OnResize(e);
- }
- private void DocumentWorkspace_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
- {
- OnScroll(e);
- }
- private void DocumentWorkspace_Layout(object sender, LayoutEventArgs e)
- {
- UpdateSnapObstacle();
- }
- /*private void DocumentWorkspace_ZoomBasisChanged(object sender, EventArgs e)
- {
- if (this.toolBar.ViewConfigStrip.ZoomBasis != this.ActiveDocumentWorkspace.ZoomBasis)
- {
- this.toolBar.ViewConfigStrip.ZoomBasis = this.ActiveDocumentWorkspace.ZoomBasis;
- }
- }*/
- private void DocumentWorkspace_RulersEnabledChanged(object sender, EventArgs e)
- {
- PerformLayout();
- }
- public void ViewConfigStrip_UnitsChanged(object sender, EventArgs e)
- {
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.Units = this.Units;
- }
- UpdateDocInfoInStatusBar();
- this.statusBar.CursorInfoText = string.Empty;
- OnUnitsChanged();
- }
- public event EventHandler StatusChanged;
- private void OnStatusChanged()
- {
- if (StatusChanged != null)
- {
- StatusChanged(this, EventArgs.Empty);
- }
- }
- private void OnDocumentWorkspaceStatusChanged(object sender, EventArgs e)
- {
- OnStatusChanged();
- UpdateStatusBarContextStatus();
- }
- private void UpdateStatusBarContextStatus()
- {
- if (ActiveDocumentWorkspace != null)
- {
- this.statusBar.ContextStatusText = this.activeDocumentWorkspace.StatusText;
- this.statusBar.ContextStatusImage = this.activeDocumentWorkspace.StatusIcon;
- }
- else
- {
- this.statusBar.ContextStatusText = string.Empty;
- this.statusBar.ContextStatusImage = null;
- }
- }
- public bool CreateBlankDocumentInNewWorkspace(Size size, MeasurementUnit dpuUnit, double dpu, bool isInitial)
- {
- DocumentWorkspace dw1 = this.activeDocumentWorkspace;
- if (dw1 != null)
- {
- dw1.SuspendRefresh();
- }
- try
- {
- Document untitled = new Document(size.Width, size.Height);
- untitled.DpuUnit = dpuUnit;
- untitled.DpuX = dpu;
- untitled.DpuY = dpu;
- /*BitmapLayer bitmapLayer;
- try
- {
- using (new WaitCursorChanger(this))
- {
- bitmapLayer = Layer.CreateBackgroundLayer(size.Width, size.Height);
- }
- }
- catch (OutOfMemoryException)
- {
- Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory"));
- return false;
- }*/
- using (new WaitCursorChanger(this))
- {
- bool focused = false;
- if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.Focused)
- {
- focused = true;
- }
- untitled.surface = new Surface(new Size(size.Width, size.Height));
- untitled.surface.Clear(ColorBgra.FromBgra(255, 255, 255, 255));
- untitled.surface.PixelFormat = PixelFormat.Format32bppArgb;
- //untitled.Layers.Add(bitmapLayer);
- DocumentWorkspace dw = this.AddNewDocumentWorkspace();
- dw.needBackup = false;
- this.Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
- dw.SuspendRefresh();
- try
- {
- dw.Document = untitled;
- }
- catch (OutOfMemoryException)
- {
- Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory"));
- RemoveDocumentWorkspace(dw);
- untitled.Dispose();
- return false;
- }
- this.ActiveDocumentWorkspace = dw;
- dw.SetDocumentSaveOptions(null, null, null);
- dw.Document.Dirty = false;
- dw.ResumeRefresh();
- if (isInitial)
- {
- this.initialWorkspace = dw;
- }
- if (focused)
- {
- this.ActiveDocumentWorkspace.Focus();
- }
- this.Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
- }
- }
- finally
- {
- if (dw1 != null)
- {
- dw1.ResumeRefresh();
- }
- }
- return true;
- }
- public bool OpenFilesInNewWorkspace(string[] fileNames)
- {
- if (IsDisposed)
- {
- return false;
- }
- bool result = true;
- foreach (string fileName in fileNames)
- {
- result &= OpenFileInNewWorkspace(fileName);
- if (!result)
- {
- break;
- }
- }
- return result;
- }
- public bool OpenFileInNewWorkspace(string fileName)
- {
- return OpenFileInNewWorkspace(fileName, true);
- }
- /// <summary>
- /// 需要修改
- /// (1)判断是否有同名的xml文件,有则读取并处理
- /// (2)判断是否识别其它标尺,有则读取
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="addToMruList"></param>
- /// <returns></returns>
- public bool OpenFileInNewWorkspace(string fileName, bool addToMruList)
- {
- if (fileName == null)
- {
- throw new ArgumentNullException("fileName");
- }
- if (fileName.Length == 0)
- {
- throw new ArgumentOutOfRangeException("fileName.Length == 0");
- }
- //判断是压缩包文件
- ZipHandleHelper zipHandleHelper = null;
- ZipXmlModel zipXmlModel = null;
- bool isZipFile = false;
- string picName = "";
- Image zipImage = null;
- if (Path.GetExtension(fileName) == ".tga")
- {
- zipHandleHelper = new ZipHandleHelper(fileName);
- zipXmlModel = zipHandleHelper.GetXmlFromZip();
- if (zipXmlModel.picNameList != null && zipXmlModel.picNameList.Count > 0)
- {
- picName = zipXmlModel.picNameList[0].name;//获取xml中第一张图的名称
- zipImage = zipHandleHelper.GetPicFromZip(picName);
- isZipFile = true;
- }
- else
- return false;//没有xml文件或有xml但一张图片都没有,不做处理
- }
- PdnBaseForm.UpdateAllForms();
- FileType fileType = null;
- Document document;
- this.widgets.StatusBarProgress.ResetProgressStatusBar();
- ProgressEventHandler progressCallback =
- delegate (object sender, ProgressEventArgs e)
- {
- this.widgets.StatusBarProgress.SetProgressStatusBar(e.Percent);
- };
- if (isZipFile)
- {
- if (zipImage == null)
- return false;
- document = Document.FromImage(zipImage);
- }
- else
- document = DocumentWorkspace.LoadDocument(this, fileName, out fileType, progressCallback);
- this.widgets.StatusBarProgress.EraseProgressStatusBar();
- if (document == null)
- {
- this.Cursor = Cursors.Default;
- }
- else
- {
- using (new WaitCursorChanger(this))
- {
- DocumentWorkspace dw = AddNewDocumentWorkspace();
- //如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId);
- if (this.ScriptRunning/* && this.ScriptCurrentParam != null && this.ScriptCurrentParam.MenuId == action.MenuId*/)
- {
- dw.OpenInScriptRunning = true;
- }
- Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
- try
- {
- dw.Document = document;
- //dw.rules = new Dictionary<MeasurementUnit, double>(Startup.instance.rules);
- //dw.xmlSaveModel = Startup.instance.ruleDB;
- //dw.InitRulerInfo();
- if (isZipFile)
- {
- dw.fileText = picName;
- dw.zipHandleHelper = zipHandleHelper;
- dw.zipXmlModel = zipXmlModel;
- dw.picName = picName;
- }
- }
- catch (OutOfMemoryException)
- {
- Utility.ErrorBox(this, PdnResources.GetString("LoadImage.Error.OutOfMemoryException"));
- RemoveDocumentWorkspace(dw);
- document.Dispose();
- return false;
- }
- //判断是否存在xml,进行读取
- PicConfigModel configModel = null;
- try
- {
- if (isZipFile)
- {
- configModel = zipHandleHelper.GetImageXmlFromZip();
- if (configModel != null)
- {
- RestoreLabelAndMeasure(configModel, dw);
- }
- }
- string path = Path.GetDirectoryName(fileName);
- string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
- //如果xml存在
- if (System.IO.File.Exists(xmlPath))
- {
- configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
- dw.RuleAttribute(configModel);
- dw.Units = Startup.instance.measurementUnit;
- if (configModel != null)
- {
- RestoreLabelAndMeasure(configModel, dw);
- }
- }
- //如果不存在,则判断
- //(1)是否自动添加ZEN标尺
- //(2)是否自动添加AxioVision标尺
- else
- {
- dw.xmlSaveModel = Startup.instance.ruleDB;
- dw.InitRulerInfo();
- }
- //else
- //{
- // string path = Path.GetDirectoryName(fileName);
- // string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
- // //如果xml存在
- // if (System.IO.File.Exists(xmlPath))
- // {
- // configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
- // dw.RuleAttribute(configModel);
- // if (configModel != null)
- // {
- // RestoreLabelAndMeasure(configModel, dw);
- // }
- // }
- // //如果不存在,则判断
- // //(1)是否自动添加ZEN标尺
- // //(2)是否自动添加AxioVision标尺
- // else
- // {
- // dw.xmlSaveModel = Startup.instance.ruleDB;
- // dw.InitRulerInfo();
- // }
- //}
- }
- catch (Exception)
- {
- }
- if (!isZipFile)
- dw.SetDocumentSaveOptions(fileName, fileType, null);
- this.ActiveDocumentWorkspace = dw;
- this.ActiveDocumentWorkspace.Units = Startup.instance.measurementUnit;
- document.Dirty = false;
- Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
- }
- //lockScaleRatio = 1;
- //isLockZoom = true;
- if (document != null)
- {
- if (isLockZoom && lockScaleRatio > 0)
- {
- ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(lockScaleRatio);
- }
- else
- {
- ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- }
- if (isZipFile)
- {
- this.PanelBottom.documentStrip.ShowPictures = true;
- }
- else
- this.PanelBottom.documentStrip.ShowPictures = false;
- }
- // add to MRU list
- if (addToMruList && !isZipFile)
- {
- ActiveDocumentWorkspace.AddToMruList();
- }
- //this.toolBar.DocumentStrip.SyncThumbnails();
- WarnAboutSavedWithVersion(document.SavedWithVersion);
- }
- if (ActiveDocumentWorkspace != null)
- {
- ActiveDocumentWorkspace.Focus();
- }
- return document != null;
- }
- /// <summary>
- /// 还原标注和测量
- /// </summary>
- /// <param name="configModel"></param>
- /// <param name="dw"></param>
- public void RestoreLabelAndMeasure(PicConfigModel configModel, DocumentWorkspace dw)
- {
- //还原标注
- if (configModel.labels != null && configModel.labels.Count > 0)
- {
- configModel.labels.Reverse();
- foreach (LabelMeasureDataModel label in configModel.labels)
- {
- string className = InvariantData.path_Label + "." + label.drawToolType;
- object[] parameters = new object[4];
- parameters[0] = dw;
- parameters[1] = label.points;
- parameters[2] = label.style;
- parameters[3] = label.content;
- object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
- dw.GraphicsList.Add((DrawObject)obj);
- }
- }
- //还原测量
- if (configModel.measures != null && configModel.measures.Count > 0)
- {
- configModel.measures.Reverse();
- foreach (LabelMeasureDataModel measure in configModel.measures)
- {
- string className = InvariantData.path_Measure + "." + measure.drawToolType;
- object[] parameters = new object[4];
- parameters[0] = dw;
- parameters[1] = measure.points;
- parameters[2] = measure.style;
- parameters[3] = measure.content;
- object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
- dw.GraphicsList.Add((DrawObject)obj);
- }
- }
- //还原其他
- //if (configModel.others != null && configModel.others.Count > 0)
- //{
- // configModel.others.Reverse();
- // foreach (LabelMeasureDataModel other in configModel.others)
- // {
- // string className = InvariantData.path_Other + "." + other.drawToolType;
- // object[] parameters = new object[4];
- // parameters[0] = dw;
- // parameters[1] = other.points;
- // parameters[2] = other.style;
- // parameters[3] = other.content;
- // object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
- // dw.GraphicsList.Add((DrawObject)obj);
- // }
- //}
- }
- /// <summary>
- /// 版本警告,暂时用不到
- /// </summary>
- /// <param name="savedWith"></param>
- private void WarnAboutSavedWithVersion(Version savedWith)
- {
- if (savedWith < new Version(2, 6, 0))
- {
- Version ourVersion = PdnInfo.GetVersion();
- Version ourVersion2 = new Version(ourVersion.Major, ourVersion.Minor);
- Version ourVersion3 = new Version(ourVersion.Major, ourVersion.Minor, ourVersion.Build);
- int fields;
- if (savedWith < ourVersion2)
- {
- fields = 2;
- }
- else
- {
- fields = 3;
- }
- string format = PdnResources.GetString("SavedWithOlderVersion.Format");
- string text = string.Format(format, savedWith.ToString(fields), ourVersion.ToString(fields));
- //Utility.InfoBox(this, text);
- }
- }
- /// <summary>
- /// Computes what the size of a new document should be. If the screen is in a normal,
- /// wider-than-tall (landscape) mode then it returns 800x600. If the screen is in a
- /// taller-than-wide (portrait) mode then it retusn 600x800. If the screen is square
- /// then it returns 800x600.
- /// </summary>
- public Size GetNewDocumentSize()
- {
- PdnBaseForm findForm = this.FindForm() as PdnBaseForm;
- if (findForm != null && findForm.ScreenAspect < 1.0)
- {
- return new Size(600, 800);
- }
- else
- {
- return new Size(800, 600);
- }
- }
- /// <summary>
- /// 保存快捷方式
- /// </summary>
- /// <returns></returns>
- public bool DoSaveLnk()
- {
- //保存窗口
- SaveFileDialog saveLnkDialog = new SaveFileDialog();
- saveLnkDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- saveLnkDialog.AddExtension = true;
- saveLnkDialog.Filter = "Lnk(*.lnk)|*.lnk";
- saveLnkDialog.FilterIndex = 1;
- saveLnkDialog.CheckFileExists = false;// true;
- saveLnkDialog.DefaultExt = "lnk";
- saveLnkDialog.FileName = PdnResources.GetString("Menu.Ashortcu.Text");
- saveLnkDialog.Title = PdnResources.GetString("Menu.Tools.CreateShortcut.Text");
- //saveLnkDialog.DereferenceLinks = true;
- if (saveLnkDialog.ShowDialog() == DialogResult.OK)
- {
- try
- {
- //存快捷方式
- WshShell shell = new WshShell();
- string savePath = saveLnkDialog.FileName;
- string saveName = Path.GetFileNameWithoutExtension(savePath);
- IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(savePath);
- shortcut.TargetPath = Application.ExecutablePath;
- shortcut.WorkingDirectory = Application.StartupPath;
- shortcut.WindowStyle = 1;
- shortcut.Arguments = "/personalConfig /" + saveName;//参数
- bool b = FileOperationHelper.CopyDirectory(Application.StartupPath + "\\Config\\Default\\", Application.StartupPath + "\\Config\\" + saveName + "\\", true);
- if (!b)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Failedtosaveconfigurationfile.text"));
- return false;
- }
- shortcut.Save();
- return true;
- }
- catch (Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Shortcutsavefailed.text"));
- return false;
- }
- }
- else
- return false;
- }
- #region 对外接口
- /// <summary>
- /// 获取网格样式配置
- /// </summary>
- /// <returns></returns>
- public GridModel GetGridModel()
- {
- return Startup.instance.gridModel;
- }
- /// <summary>
- /// 获取标注样式配置
- /// </summary>
- /// <returns></returns>
- public LabelStyleModel GetLabelStyleModel()
- {
- return Startup.instance.labelStyleModel;
- }
- /// <summary>
- /// 获取测量样式配置
- /// </summary>
- /// <returns></returns>
- public MeasureStyleModel GetMeasureStyleModel()
- {
- return Startup.instance.measureStyleModel;
- }
- /// <summary>
- /// 获取设置-常规设置-辅助线样式信息
- /// </summary>
- /// <returns></returns>
- public GuideStyleModel GetGuideStyleModel()
- {
- return Startup.instance.guideStyleModel;
- }
- /// <summary>
- /// 获取水印样式配置
- /// </summary>
- /// <returns></returns>
- public WatermarkModel GetWatermarkModel()
- {
- return Startup.instance.watermarkModel;
- }
- /// <summary>
- /// 获取工字线配置
- /// </summary>
- /// <returns></returns>
- public WorkTypeStyleModel GetWorkTypeStyleModel()
- {
- return Startup.instance.workTypeStyleModel;
- }
- /// <summary>
- /// 获取标尺样式配置
- /// </summary>
- /// <returns></returns>
- public RulerModel GetRulerStyleModel()
- {
- return Startup.instance.rulerModel;
- }
- /// <summary>
- /// 像素跟踪
- /// 需要增加标记,在进行比如图像旋转等直接在当前
- /// 面板进行图像大小变化操作的,需要停止像素跟踪,
- /// 处理完成之后在恢复,否则可能会导致读取内存异常
- /// </summary>
- /// <param name="location"></param>
- public void SetImageAndData(Point location)
- {
- if (this.pixelTrackingDialog != null)
- {
- this.pixelTrackingDialog.SetImageAndData(location);
- }
- }
- /// <summary>
- /// 刷新标注列表
- /// </summary>
- public void RefreshLabelListDialog()
- {
- if (this.labelListDialog != null)
- this.labelListDialog.RefreshDateGridView(null, null);
- }
- /// <summary>
- /// 刷新交互测量列表
- /// </summary>
- public void RefreshMeasureListView()
- {
- Form form = Application.OpenForms["GeometryMeasureDialog"];
- if (form != null)
- {
- ((GeometryMeasureDialog)form).RefreshListView(null, null);
- }
- this.Refresh();
- }
- /// <summary>
- /// 刷新测量列表
- /// </summary>
- public void RefreshListView()
- {
- if (this.measureListDialog != null)
- this.measureListDialog.RefreshListView(null, null);
- this.Refresh();
- }
- /// <summary>
- /// 刷新直方图
- /// </summary>
- public void RefreshHistogram()
- {
- if (this.histogramDialog != null)
- this.histogramDialog.ButtonFocus(null, null);
- this.Refresh();
- }
- /// <summary>
- /// 取得绘制属性
- /// </summary>
- public void SetDrawNodes()
- {
- if (this.measureListDialog != null)
- this.measureListDialog.SetDrawNodes(null, null);
- }
- /// <summary>
- /// 刷新光密度画面
- /// </summary>
- public void RefreshOpticalDensity()
- {
- if (this.opticalDensityDialog != null)
- this.opticalDensityDialog.RefreshOpticalDensity(null, null);
- }
- /*public PointF GetDocumentScrollPositionF()
- {
- return this.activeDocumentWorkspace.DocumentScrollPositionF;
- }
- public void SetDocumentScrollPositionF(PointF newScrollPos)
- {
- this.activeDocumentWorkspace.DocumentScrollPositionF = newScrollPos;
- }*/
- public RectangleF GetVisibleDocumentRectangleF()
- {
- return this.activeDocumentWorkspace.VisibleDocumentRectangleF;
- }
- public SizeF GetDocumentSize()
- {
- //return this.activeDocumentWorkspace.Document.Size;
- if (this.cameraPreviewDialog != null && !this.cameraPreviewDialog.IsDisposed)
- {
- if (this.cameraPreviewDialog.documentWorkspace != null)
- {
- return this.cameraPreviewDialog.documentWorkspace.Document.Size;
- }
- }
- else
- {
- return this.activeDocumentWorkspace.Document.Size;
- }
- return this.activeDocumentWorkspace.Document.Size;
- }
- public double GetRatio()
- {
- return this.activeDocumentWorkspace.ScaleFactor.Ratio;
- }
- public PointF DocumentToClient(PointF pointF)
- {
- return this.activeDocumentWorkspace.DocumentToClient(pointF);
- }
- /// <summary>
- /// 获取系统当前选中单位及每单位像素值
- /// </summary>
- /// <returns>3位字符串数组,
- /// 0:系统选中单位枚举字符串
- /// 1:系统选中单位名称字符串
- /// 2:系统选中单位符号字符串
- /// 3:系统选中单位每单位像素长度
- /// 4:系统选中单位每单位物理长度
- /// </returns>
- public string[] GetPxPerUnit()
- {
- if (this.activeDocumentWorkspace != null)
- return this.activeDocumentWorkspace.getRulerList();
- else
- {
- string[] result = new string[5];
- result[0] = Startup.instance.measurementUnit.ToString();
- result[1] = InvariantData.unitsDictionary[(int)Startup.instance.measurementUnit];
- result[2] = InvariantData.unitSymbolsDictionary[(int)Startup.instance.measurementUnit];
- result[3] = (Startup.instance.rules[Startup.instance.measurementUnit]).ToString();
- result[4] = (Startup.instance.rules[MeasurementUnit.Micron]).ToString();
- return result;
- }
- }
- /// <summary>
- /// 获取当前激活的图像工作空间的视场行为
- /// 合并/剪切
- /// </summary>
- /// <returns></returns>
- public CombineMode GetCombineMode()
- {
- return this.ActiveDocumentWorkspace.CombineMode;
- }
- /// <summary>
- /// 获取测量单位对应的换算字典
- /// </summary>
- /// <returns></returns>
- public Dictionary<MeasurementUnit, double> getMeasureInfo()
- {
- if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.rules != null)
- return this.ActiveDocumentWorkspace.rules;
- else
- return Startup.instance.rules;
- }
- /// <summary>
- /// 获取系统当前放大倍数
- /// </summary>
- /// <returns></returns>
- public decimal GetGainMultiple()
- {
- if (Startup.instance.ruleDB == null)
- {
- return decimal.Zero;
- }
- else
- {
- return Startup.instance.ruleDB.gain_multiple;
- }
- }
- PanelBottom IAppWorkspaceForSurfaceBox.GetPanelBottom()
- {
- return PanelBottom;
- }
- /// <summary>
- /// 更新命名的延续数字
- /// </summary>
- public void UpdateContinueNum()
- {
- if (Startup.instance.configModel != null)
- {
- ConfigModel configModel = Startup.instance.configModel;
- configModel.ContinueNum++;
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
- FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create);
- }
- }
- #endregion
- #region 底部公共按钮
- /// <summary>
- /// 初始化底部按钮的各种事件
- /// </summary>
- private void InitializeBottomEvent()
- {
- //最佳
- this.PanelBottom.bestButton.MouseDown += new MouseEventHandler(BestButton_Click);
- //最大最小
- this.PanelBottom.maxMinButton.MouseDown += new MouseEventHandler(MaxMinButton_Click);
- //原始状态
- this.PanelBottom.originButton.MouseDown += new MouseEventHandler(OriginButton_Click);
- //伽马0.45
- this.PanelBottom.gamma45Button.MouseDown += new MouseEventHandler(Gamma45Button_Click);
- //网格
- this.PanelBottom.gridButton.MouseDown += new MouseEventHandler(GridButton_Click);
- //辅助线
- this.PanelBottom.auxiliaryLineButton.MouseDown += new MouseEventHandler(AuxiliaryLineButton_Click);
- //水平镜像
- this.PanelBottom.horizontalMirroringButton.Click += new EventHandler(HorizontalMirroringButton_Click);
- //垂直镜像
- this.PanelBottom.verticalMirrorButton.Click += new EventHandler(VerticalMirrorButton_Click);
- //中心镜像
- this.PanelBottom.centerMirrorButton.Click += new EventHandler(CenterMirrorButton_Click);
- //移动模式
- this.PanelBottom.mobileModeButton.MouseDown += new MouseEventHandler(MobileModeButton_Click);
- //指针模式
- this.PanelBottom.cursorModeButton.MouseDown += new MouseEventHandler(CursorModeButton_Click);
- //实际大小
- this.PanelBottom.actualSizeButton.MouseDown += new MouseEventHandler(ActualSizeButton_Click);
- //合适大小
- this.PanelBottom.zoomToWindowButton.MouseDown += new MouseEventHandler(ZoomToWindowButton_Click);
- //定倍显示
- //this.PanelBottom.fixedTimesButton.Click += null;
- //锁定扩缩
- this.PanelBottom.lockdownButton.MouseDown += new MouseEventHandler(LockdownButton_Click);
- //缩小按钮
- this.PanelBottom.zoomOutButton.Click += new EventHandler(ZoomOutButton_Click);
- //放大按钮
- this.PanelBottom.zoomInButton.Click += new EventHandler(zoomInButton_Click);
- //放大缩小拖动条事件
- this.PanelBottom.trackBar.ValueChanged += new EventHandler(PanelBottom_trackBar_ValueChanged);
- //缩放缩小倍数的改变事件
- this.PanelBottom.textBox.TextChanged += new EventHandler(PanelBottom_textBox_ValueChanged);
- //相的选中事件
- this.panelBottom.ItemICheckChanged += new EventHandler<EventArgs<int>>(this.PhaseItemICheckChanged);
- }
- public void SetZoonTrackValue(ScaleFactor newValue)
- {
- this.panelBottom.trackBar.Maximum = 6200;// (int)(ScaleFactor.MaxValue.Ratio * 100);
- if (newValue != null)
- {
- this.PanelBottom.trackBar.ValueChanged -= this.PanelBottom_trackBar_ValueChanged;
- double v = newValue.Ratio * 100;
- if (v <= 100)
- {
- this.PanelBottom.trackBar.Value = (int)(31 * v);
- }
- else
- {
- double x = 3100 + newValue.Ratio * 100;
- if (x > 6200) x = 6200;
- this.PanelBottom.trackBar.Value = (int)x;
- }
- this.PanelBottom.trackBar.ValueChanged += new EventHandler(this.PanelBottom_trackBar_ValueChanged);
- }
- //设置底部缩放比例的百分比textbox的值
- this.PanelBottom.textBox.TextChanged -= new EventHandler(PanelBottom_textBox_ValueChanged);
- this.PanelBottom.textBox.Text = newValue.ToString();
- this.PanelBottom.textBox.TextChanged += new EventHandler(PanelBottom_textBox_ValueChanged);
- }
- /// <summary>
- /// 最佳
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BestButton_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
- {
- if (!this.activeDocumentWorkspace.best)
- {
- this.activeDocumentWorkspace.best = true;
- this.activeDocumentWorkspace.maxMin = false;
- this.activeDocumentWorkspace.origin = false;
- this.activeDocumentWorkspace.gamma45 = false;
- this.PanelBottom.maxMinButton.selected = false;
- this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.originButton.selected = false;
- this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gamma45Button.selected = false;
- this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.best)
- {
- this.PanelBottom.bestButton.selected = true;
- this.PanelBottom.bestButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.bestButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.bestButton.selected = false;
- this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- this.Histogram.BestButtonMethod();
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.buttonType = 0;
- this.RefreshHistogram();
- }
- }
- }
- /// <summary>
- /// 从直方图更新选中状态
- /// </summary>
- /// <param name="selected"></param>
- public void MaxMinBest(bool best, bool maxMin, bool origin, bool gamma45)
- {
- this.activeDocumentWorkspace.best = best;
- this.activeDocumentWorkspace.maxMin = maxMin;
- this.activeDocumentWorkspace.origin = origin;
- this.activeDocumentWorkspace.gamma45 = gamma45;
- if (this.activeDocumentWorkspace.best)
- {
- this.PanelBottom.bestButton.selected = true;
- this.PanelBottom.bestButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.bestButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.bestButton.selected = false;
- this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.maxMin)
- {
- this.PanelBottom.maxMinButton.selected = true;
- this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.maxMinButton.selected = false;
- this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.origin)
- {
- this.PanelBottom.originButton.selected = true;
- this.PanelBottom.originButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.originButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.originButton.selected = false;
- this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.gamma45)
- {
- this.PanelBottom.gamma45Button.selected = true;
- this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 1;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.gamma45Button.selected = false;
- this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- }
- /// <summary>
- /// 最大最小
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MaxMinButton_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
- {
- if (!this.activeDocumentWorkspace.maxMin)
- {
- this.activeDocumentWorkspace.maxMin = true;
- this.activeDocumentWorkspace.best = false;
- this.activeDocumentWorkspace.origin = false;
- this.activeDocumentWorkspace.gamma45 = false;
- this.PanelBottom.bestButton.selected = false;
- this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.originButton.selected = false;
- this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gamma45Button.selected = false;
- this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.maxMin)
- {
- this.PanelBottom.maxMinButton.selected = true;
- this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.maxMinButton.selected = false;
- this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.buttonType = 1;
- this.RefreshHistogram();
- }
- this.Histogram.MaxMinButtonMethod();
- }
- }
- /// <summary>
- /// 原始状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OriginButton_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
- {
- if (!this.activeDocumentWorkspace.origin)
- {
- this.activeDocumentWorkspace.origin = true;
- this.activeDocumentWorkspace.maxMin = false;
- this.activeDocumentWorkspace.best = false;
- this.activeDocumentWorkspace.gamma45 = false;
- this.PanelBottom.bestButton.selected = false;
- this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.maxMinButton.selected = false;
- this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gamma45Button.selected = false;
- this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.origin)
- {
- this.PanelBottom.originButton.selected = true;
- this.PanelBottom.originButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.originButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.originButton.selected = false;
- this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.buttonType = 3;
- this.RefreshHistogram();
- }
- this.Histogram.OriginButtonMethod();
- }
- }
- /// <summary>
- /// 伽马0.45
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Gamma45Button_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null && this.Histogram != null)
- {
- if (!this.activeDocumentWorkspace.gamma45)
- {
- this.activeDocumentWorkspace.gamma45 = true;
- this.activeDocumentWorkspace.origin = false;
- this.activeDocumentWorkspace.maxMin = false;
- this.activeDocumentWorkspace.best = false;
- this.PanelBottom.bestButton.selected = false;
- this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.maxMinButton.selected = false;
- this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.originButton.selected = false;
- this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.gamma45)
- {
- this.PanelBottom.gamma45Button.selected = true;
- this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 1;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.gamma45Button.selected = false;
- this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.buttonType = 2;
- this.RefreshHistogram();
- }
- this.Histogram.Gamma45ButtonMethod();
- }
- }
- /// <summary>
- /// 更新底部按钮选中状态
- /// </summary>
- public void UpdateBottomButtonSelectionStatus()
- {
- if (this.ActiveDocumentWorkspace == null)
- return;
- if (this.ActiveDocumentWorkspace.GridLineEnabled)
- {
- this.PanelBottom.gridButton.selected = true;
- this.PanelBottom.gridButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gridButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.gridButton.selected = false;
- this.PanelBottom.gridButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gridButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.ActiveDocumentWorkspace.AuxiliaryLineEnabled)
- {
- this.PanelBottom.auxiliaryLineButton.selected = true;
- this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.auxiliaryLineButton.selected = false;
- this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.ActualSize)
- {
- this.PanelBottom.actualSizeButton.selected = true;
- this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.actualSizeButton.selected = false;
- this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.SuitableSize)
- {
- this.PanelBottom.zoomToWindowButton.selected = true;
- this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.zoomToWindowButton.selected = false;
- this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.ActiveDocumentWorkspace.LockZoom)
- {
- this.PanelBottom.lockdownButton.selected = true;
- this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.lockdownButton.selected = false;
- this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.best)
- {
- this.PanelBottom.bestButton.selected = true;
- this.PanelBottom.bestButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.bestButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.bestButton.selected = false;
- this.PanelBottom.bestButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.bestButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.bestButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.bestButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.maxMin)
- {
- this.PanelBottom.maxMinButton.selected = true;
- this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.maxMinButton.selected = false;
- this.PanelBottom.maxMinButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.maxMinButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.maxMinButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.origin)
- {
- this.PanelBottom.originButton.selected = true;
- this.PanelBottom.originButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.originButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.originButton.selected = false;
- this.PanelBottom.originButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.originButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.originButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.originButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.gamma45)
- {
- this.PanelBottom.gamma45Button.selected = true;
- this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 1;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.gamma45Button.selected = false;
- this.PanelBottom.gamma45Button.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gamma45Button.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderSize = 0;
- this.PanelBottom.gamma45Button.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.ActiveDocumentWorkspace.GridLineEnabled)
- {
- this.PanelBottom.gridButton.selected = true;
- this.PanelBottom.gridButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gridButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.gridButton.selected = false;
- this.PanelBottom.gridButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gridButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.mobileMode)
- {
- this.PanelBottom.mobileModeButton.selected = true;
- this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.mobileModeButton.selected = false;
- this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.cursorMode)
- {
- this.PanelBottom.cursorModeButton.selected = true;
- this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.cursorModeButton.selected = false;
- this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- }
- /// <summary>
- /// 网格
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void GridButton_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- this.ActiveDocumentWorkspace.GridLineEnabled = !this.ActiveDocumentWorkspace.GridLineEnabled;
- if (this.ActiveDocumentWorkspace.GridLineEnabled)
- {
- this.PanelBottom.gridButton.selected = true;
- this.PanelBottom.gridButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gridButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.gridButton.selected = false;
- this.PanelBottom.gridButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.gridButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.gridButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.gridButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
- this.ActiveDocumentWorkspace.Refresh();
- }
- }
- /// <summary>
- /// 底部快捷栏 辅助线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void AuxiliaryLineButton_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- this.ActiveDocumentWorkspace.AuxiliaryLineEnabled = !Settings.CurrentUser.GetBoolean(SettingNames.DrawAuxiliaryLine, false);
- if (this.ActiveDocumentWorkspace.AuxiliaryLineEnabled)
- {
- this.PanelBottom.auxiliaryLineButton.selected = true;
- this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.auxiliaryLineButton.selected = false;
- this.PanelBottom.auxiliaryLineButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.auxiliaryLineButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.auxiliaryLineButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
- this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
- Settings.CurrentUser.SetBoolean(SettingNames.DrawAuxiliaryLine, this.ActiveDocumentWorkspace.AuxiliaryLineEnabled);
- this.ActiveDocumentWorkspace.Refresh();
- }
- }
- /// <summary>
- /// 水平镜像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void HorizontalMirroringButton_Click(object sender, EventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- OpenCvSharp.Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());
- OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
- OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.Y);
- if (this.scriptRunning)
- {
- DocumentWorkspace dw = this.AddNewDocumentWorkspace();
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- dw.Document = document;
- dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
- this.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- }
- else
- {
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- this.ActiveDocumentWorkspace.Document = document;
- this.ActiveDocumentWorkspace.Refresh();
- }
- }
- }
- /// <summary>
- /// 垂直镜像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void VerticalMirrorButton_Click(object sender, EventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- OpenCvSharp.Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());
- OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
- OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.X);
- if (this.scriptRunning)
- {
- DocumentWorkspace dw = this.AddNewDocumentWorkspace();
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- dw.Document = document;
- dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
- this.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- }
- else
- {
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- this.ActiveDocumentWorkspace.Document = document;
- this.ActiveDocumentWorkspace.Refresh();
- }
- }
- }
- /// <summary>
- /// 中心镜像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void CenterMirrorButton_Click(object sender, EventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- OpenCvSharp.Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());
- OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
- OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.XY);
- if (this.scriptRunning)
- {
- DocumentWorkspace dw = this.AddNewDocumentWorkspace();
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- dw.Document = document;
- dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
- this.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- }
- else
- {
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- this.ActiveDocumentWorkspace.Document = document;
- this.ActiveDocumentWorkspace.Refresh();
- }
- }
- }
- /// <summary>
- /// 移动模式
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MobileModeButton_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- if (!this.activeDocumentWorkspace.mobileMode)
- {
- this.activeDocumentWorkspace.mobileMode = true;
- this.activeDocumentWorkspace.cursorMode = false;
- this.PanelBottom.cursorModeButton.selected = false;
- this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.mobileMode)
- {
- this.PanelBottom.mobileModeButton.selected = true;
- this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.mobileModeButton.selected = false;
- this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- this.ActiveDocumentWorkspace.ActiveTool = DrawToolType.MoveMode;
- }
- }
- /// <summary>
- /// 指针模式
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void CursorModeButton_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- if (!this.activeDocumentWorkspace.cursorMode)
- {
- this.activeDocumentWorkspace.cursorMode = true;
- this.activeDocumentWorkspace.mobileMode = false;
- this.PanelBottom.mobileModeButton.selected = false;
- this.PanelBottom.mobileModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.mobileModeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.mobileModeButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.mobileModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.cursorMode)
- {
- this.PanelBottom.cursorModeButton.selected = true;
- this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.cursorModeButton.selected = false;
- this.PanelBottom.cursorModeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.cursorModeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.cursorModeButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.cursorModeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- this.ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
- }
- }
- /// <summary>
- /// 底部快捷栏 实际大小
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ActualSizeButton_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- if (!this.activeDocumentWorkspace.ActualSize)
- {
- this.activeDocumentWorkspace.ActualSize = !this.activeDocumentWorkspace.ActualSize;
- this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.activeDocumentWorkspace.SuitableSize = false;
- this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- }
- else
- {
- this.activeDocumentWorkspace.ActualSize = !this.activeDocumentWorkspace.ActualSize;
- this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- }
- if (this.activeDocumentWorkspace.ActualSize)
- {
- this.PanelBottom.actualSizeButton.selected = true;
- this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.actualSizeButton.selected = false;
- this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.SuitableSize)
- {
- this.PanelBottom.zoomToWindowButton.selected = true;
- this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.zoomToWindowButton.selected = false;
- this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- this.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- this.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
- }
- }
- /// <summary>
- /// 底部快捷栏 合适大小
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ZoomToWindowButton_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- if (!this.activeDocumentWorkspace.SuitableSize)
- {
- this.activeDocumentWorkspace.SuitableSize = !this.activeDocumentWorkspace.SuitableSize;
- this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.activeDocumentWorkspace.ActualSize = false;
- this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- }
- else
- {
- this.activeDocumentWorkspace.SuitableSize = !this.activeDocumentWorkspace.SuitableSize;
- this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- }
- if (this.activeDocumentWorkspace.SuitableSize)
- {
- this.PanelBottom.zoomToWindowButton.selected = true;
- this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.zoomToWindowButton.selected = false;
- this.PanelBottom.zoomToWindowButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.zoomToWindowButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.zoomToWindowButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- if (this.activeDocumentWorkspace.ActualSize)
- {
- this.PanelBottom.actualSizeButton.selected = true;
- this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.actualSizeButton.selected = false;
- this.PanelBottom.actualSizeButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.actualSizeButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.actualSizeButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- this.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- }
- }
- /// <summary>
- /// 底部快捷键 锁定扩缩
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void LockdownButton_Click(object sender, MouseEventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- this.ActiveDocumentWorkspace.LockZoom = !this.ActiveDocumentWorkspace.LockZoom;
- this.toolBar.RefreshBtnSelect(this.ActiveDocumentWorkspace.LockZoom, "LockZoom");
- this.toolsPanel.RefreshBtnSelect(this.ActiveDocumentWorkspace.LockZoom, "LockZoom");
- if (this.ActiveDocumentWorkspace.LockZoom)
- {
- this.PanelBottom.lockdownButton.selected = true;
- this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(181, 215, 243);
- this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 1;
- this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 120, 215);
- }
- else
- {
- this.PanelBottom.lockdownButton.selected = false;
- this.PanelBottom.lockdownButton.BackColor = Color.FromArgb(0, 0, 0, 0);
- this.PanelBottom.lockdownButton.FlatStyle = FlatStyle.Flat;
- this.PanelBottom.lockdownButton.FlatAppearance.BorderSize = 0;
- this.PanelBottom.lockdownButton.FlatAppearance.BorderColor = Color.FromArgb(0, 0, 0, 0);
- }
- this.isLockZoom = !this.isLockZoom;
- this.lockScaleRatio = this.activeDocumentWorkspace.ScaleFactor.Ratio;
- }
- }
- /// <summary>
- /// 底部快捷栏 缩小事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ZoomOutButton_Click(object sender, EventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- this.ActiveDocumentWorkspace.ZoomOut();
- this.activeDocumentWorkspace.ActualSize = false;
- this.activeDocumentWorkspace.SuitableSize = false;
- this.activeDocumentWorkspace.SuitableHeight = false;
- this.activeDocumentWorkspace.SuitableWidth = false;
- this.SetTopLeftCheckState();
- this.UpdateBottomButtonSelectionStatus();
- }
- }
- /// <summary>
- /// 底部快捷栏 放大事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void zoomInButton_Click(object sender, EventArgs e)
- {
- if (this.ActiveDocumentWorkspace != null)
- {
- this.ActiveDocumentWorkspace.ZoomIn();
- this.activeDocumentWorkspace.ActualSize = false;
- this.activeDocumentWorkspace.SuitableSize = false;
- this.activeDocumentWorkspace.SuitableHeight = false;
- this.activeDocumentWorkspace.SuitableWidth = false;
- this.SetTopLeftCheckState();
- this.UpdateBottomButtonSelectionStatus();
- }
- }
- /// <summary>
- /// 底部方法缩小拖动条事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PanelBottom_trackBar_ValueChanged(object sender, EventArgs e)
- {
- if (this.activeDocumentWorkspace != null)
- {
- this.activeDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- if (this.PanelBottom.trackBar.Tag == null)
- {
- int v = this.PanelBottom.trackBar.Value;
- if (this.PanelBottom.trackBar.Value <= 3100)
- {
- this.PanelBottom.trackBar.SmallChange = 31;
- v = this.PanelBottom.trackBar.Value / 31;
- }
- else
- {
- this.PanelBottom.trackBar.SmallChange = 100;
- v = 100 + this.PanelBottom.trackBar.Value - 3100;
- }
- this.activeDocumentWorkspace.ScaleFactor = new ScaleFactor(v, 100);
- this.PanelBottom.trackBar.Tag = this.PanelBottom.trackBar.Value;
- }
- else
- {
- int oldValue = (int)this.PanelBottom.trackBar.Tag;
- if (oldValue != this.PanelBottom.trackBar.Value)
- {
- int v = this.PanelBottom.trackBar.Value;
- if (this.PanelBottom.trackBar.Value <= 3100)
- {
- this.PanelBottom.trackBar.SmallChange = 31;
- v = this.PanelBottom.trackBar.Value / 31;
- }
- else
- {
- this.PanelBottom.trackBar.SmallChange = 100;
- v = 100 + this.PanelBottom.trackBar.Value - 3100;
- }
- this.activeDocumentWorkspace.ScaleFactor = new ScaleFactor(v, 100);
- this.PanelBottom.trackBar.Tag = this.PanelBottom.trackBar.Value;
- }
- }
- }
- }
- private void PanelBottom_textBox_ValueChanged(object sender, EventArgs e)
- {
- int v;
- if (!string.IsNullOrEmpty(this.PanelBottom.textBox.Text) &&
- !this.PanelBottom.textBox.Text.Equals("%") &&
- int.TryParse(this.PanelBottom.textBox.Text.Replace("%", ""), out v))
- {
- if (v > this.PanelBottom.trackBar.Maximum) v = this.PanelBottom.trackBar.Maximum;
- if (v < this.PanelBottom.trackBar.Minimum) v = this.PanelBottom.trackBar.Minimum;
- if (v <= 100)
- {
- this.PanelBottom.trackBar.Value = 31 * v;
- }
- else
- {
- int x = 3000 + v;
- if (x > 6100) x = 6200;
- this.PanelBottom.trackBar.Value = x;
- }
- }
- }
- /// <summary>
- /// 用于相的选中和取消
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PhaseItemICheckChanged(object sender, EventArgs<int> e)
- {
- if (e.Data > 0)
- {
- if (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.phaseModels.Count >= e.Data)
- {
- this.activeDocumentWorkspace.phaseModels[e.Data - 1].choise = !this.activeDocumentWorkspace.phaseModels[e.Data - 1].choise;
- this.activeDocumentWorkspace.panel.Refresh();
- }
- }
- }
- /// <summary>
- /// 初始化右下角播放系列按钮的各种事件
- /// </summary>
- private void InitializePanelBottomRight()
- {
- this.playMode = 2;//默认是前到后的播放模式
- this.PanelBottom.documentStrip.play2Button.BackColor = Color.Gray;//前到后的按钮选中
- //初始化定时器
- timer = new Timer();
- timer.Interval = 1000;
- timer.Tick += new EventHandler(timer_Tick);
- timer.Enabled = false;
- //滚动条事件
- this.panelBottom.documentStrip.trackBar.TrackBarScroll += new EventHandler(PanelBottom_TrackBarScroll);
- //从后往前播放模式
- this.PanelBottom.documentStrip.play1Button.Click += new EventHandler(PanelBottom_Play1ButtonClick);
- //从前往后播放模式
- this.PanelBottom.documentStrip.play2Button.Click += new EventHandler(PanelBottom_Play2ButtonClick);
- //循环播放模式
- this.PanelBottom.documentStrip.play3Button.Click += new EventHandler(PanelBottom_Play3ButtonClick);
- //播放(暂停)
- this.PanelBottom.documentStrip.playOrPauseButton.Click += new EventHandler(PanelBottom_PlayOrPauseButtonClick);
- //删除当前显示页
- this.PanelBottom.documentStrip.deleteButton.Click += new EventHandler(PanelBottom_DeleteButtonClick);
- //修改播放时间间隔
- this.panelBottom.documentStrip.editTimeButton.Click += new EventHandler(PanelBottom_EditTimeButtonClick);
- }
- /// <summary>
- /// 右下滚动条事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PanelBottom_TrackBarScroll(object sender, EventArgs e)
- {
- if (this.activeDocumentWorkspace.zipXmlModel.picNameList != null && this.activeDocumentWorkspace.zipXmlModel.picNameList.Count > 0
- && this.activeDocumentWorkspace.zipHandleHelper != null)
- {
- ChangeImageInActiveDocument(this.PanelBottom.documentStrip.trackBar.Value);
- }
- }
- /// <summary>
- /// 从后往前播放按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PanelBottom_Play1ButtonClick(object sender, EventArgs e)
- {
- if (this.PanelBottom.documentStrip.play1Button.BackColor == Color.Gray)
- return;
- else
- {
- this.PanelBottom.documentStrip.play1Button.BackColor = Color.Gray;
- this.panelBottom.documentStrip.play2Button.BackColor = Color.FromArgb(255, 240, 240, 240);
- this.playMode = 1;
- }
- }
- /// <summary>
- /// 从前往后播放按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PanelBottom_Play2ButtonClick(object sender, EventArgs e)
- {
- if (this.PanelBottom.documentStrip.play2Button.BackColor == Color.Gray)
- return;
- else
- {
- this.PanelBottom.documentStrip.play2Button.BackColor = Color.Gray;
- this.panelBottom.documentStrip.play1Button.BackColor = Color.FromArgb(255, 240, 240, 240);
- this.playMode = 2;
- }
- }
- /// <summary>
- /// 循环播放按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PanelBottom_Play3ButtonClick(object sender, EventArgs e)
- {
- if (this.PanelBottom.documentStrip.play3Button.BackColor == Color.Gray)
- {
- this.panelBottom.documentStrip.play3Button.BackColor = Color.FromArgb(255, 240, 240, 240);
- this.isLoopPlayback = false;
- }
- else
- {
- this.PanelBottom.documentStrip.play3Button.BackColor = Color.Gray;
- this.isLoopPlayback = true;
- }
- }
- /// <summary>
- /// 播放(暂停)按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PanelBottom_PlayOrPauseButtonClick(object sender, EventArgs e)
- {
- timer.Enabled = !timer.Enabled;
- }
- /// <summary>
- /// 删除当前页按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PanelBottom_DeleteButtonClick(object sender, EventArgs e)
- {
- if (this.activeDocumentWorkspace.zipHandleHelper != null)
- {
- //如点击删除时正在播放是否需要关闭定时器?
- if (timer.Enabled)
- timer.Enabled = false;
- //压缩包里只有一张图片的情况,可能需替换成别的逻辑
- if (this.activeDocumentWorkspace.zipXmlModel.picNameList.Count == 1)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Thereisonlyoneimwedtobedeleted.text"));
- return;
- }
- this.activeDocumentWorkspace.zipHandleHelper.DeletePicFromZip(this.activeDocumentWorkspace.zipXmlModel.picNameList[this.PanelBottom.documentStrip.trackBar.Value - 1].name);
- this.activeDocumentWorkspace.zipXmlModel.picNameList.RemoveAt(this.PanelBottom.documentStrip.trackBar.Value - 1);
- this.activeDocumentWorkspace.zipHandleHelper.ModifyXmlNodes(this.activeDocumentWorkspace.zipXmlModel);
- //如果删除的是最后一张图,索引向前移一位
- if (this.PanelBottom.documentStrip.trackBar.Value > this.activeDocumentWorkspace.zipXmlModel.picNameList.Count)
- this.PanelBottom.documentStrip.trackBar.Value -= 1;
- ChangeImageInActiveDocument(this.PanelBottom.documentStrip.trackBar.Value);
- this.PanelBottom.documentStrip.trackBar.Maximum = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
- this.PanelBottom.documentStrip.textBox.Text = this.PanelBottom.documentStrip.trackBar.Value + @"/" + this.PanelBottom.documentStrip.trackBar.Maximum;
- }
- }
- /// <summary>
- /// 修改播放间隔按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PanelBottom_EditTimeButtonClick(object sender, EventArgs e)
- {
- using (PlayIntervalSettingDialog playIntervalSettingDialog = new PlayIntervalSettingDialog())
- {
- playIntervalSettingDialog.StartPosition = FormStartPosition.CenterScreen;
- playIntervalSettingDialog.textBox1.Text = timer.Interval.ToString();
- playIntervalSettingDialog.button1.Click += new EventHandler(IntervalDialog_ButtonClick);
- playIntervalSettingDialog.ShowDialog();
- }
- }
- /// <summary>
- /// 播放间隔设置页的确定按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void IntervalDialog_ButtonClick(object sender, EventArgs e)
- {
- Button button = (Button)sender;
- PlayIntervalSettingDialog playIntervalSettingDialog = (PlayIntervalSettingDialog)button.Parent;
- timer.Interval = Convert.ToInt32(playIntervalSettingDialog.textBox1.Text);
- playIntervalSettingDialog.Close();
- }
- /// <summary>
- /// 播放使用定时器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timer_Tick(object sender, EventArgs e)
- {
- //前到后
- if (this.playMode == 2)
- {
- if (this.PanelBottom.documentStrip.trackBar.Value < this.activeDocumentWorkspace.zipXmlModel.picNameList.Count)//当前不是最后一张图
- this.PanelBottom.documentStrip.trackBar.Value += 1;
- else
- {
- //是否循环
- if (isLoopPlayback)
- {
- this.PanelBottom.documentStrip.trackBar.Value = 1;
- }
- else
- {
- //不循环则到终点关闭定时器
- timer.Enabled = false;
- return;
- }
- }
- }
- //后到前
- if (this.playMode == 1)
- {
- if (this.PanelBottom.documentStrip.trackBar.Value > 1)//当前不是第一张图
- this.PanelBottom.documentStrip.trackBar.Value -= 1;
- else
- {
- //是否循环
- if (isLoopPlayback)
- {
- this.PanelBottom.documentStrip.trackBar.Value = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
- }
- else
- {
- //不循环则到终点关闭定时器
- timer.Enabled = false;
- return;
- }
- }
- }
- ChangeImageInActiveDocument(this.PanelBottom.documentStrip.trackBar.Value);
- this.PanelBottom.documentStrip.trackBar.Maximum = this.activeDocumentWorkspace.zipXmlModel.picNameList.Count;
- this.PanelBottom.documentStrip.textBox.Text = this.PanelBottom.documentStrip.trackBar.Value + @"/" + this.PanelBottom.documentStrip.trackBar.Maximum;
- }
- /// <summary>
- /// 替换当前画布的图片
- /// </summary>
- /// <param name="trackBarValue"></param>
- private void ChangeImageInActiveDocument(int trackBarValue)
- {
- this.activeDocumentWorkspace.picName = this.activeDocumentWorkspace.zipXmlModel.picNameList[trackBarValue - 1].name;
- Image zipImage = this.activeDocumentWorkspace.zipHandleHelper.GetPicFromZip(this.activeDocumentWorkspace.picName);
- Document document = Document.FromImage(zipImage);
- this.activeDocumentWorkspace.fileText = this.activeDocumentWorkspace.picName;//tab页改图片名不好用
- this.activeDocumentWorkspace.Document = document;
- }
- private bool ExistenceXML()
- {
- if (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.existenceXML)
- {
- return true;
- }
- //获取图片路径
- bool existenceXML = false;
- if (this.activeDocumentWorkspace != null)
- {
- string fileName;
- FileType fileType;
- SaveConfigToken saveConfigToken;
- this.activeDocumentWorkspace.GetDocumentSaveOptions(out fileName, out fileType, out saveConfigToken);
- if (fileName != null)
- {
- string path = Path.GetDirectoryName(fileName);
- string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
- existenceXML = System.IO.File.Exists(xmlPath);
- if (existenceXML)
- {
- PicConfigModel configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
- this.activeDocumentWorkspace.RuleAttribute(configModel);
- }
- //this.activeDocumentWorkspace.existenceXML = existenceXML;
- }
- }
- return existenceXML;
- }
- #endregion
- #region 标尺相关
- /// <summary>
- /// 刷新标尺列表
- /// </summary>
- public void RefueshRuleList()
- {
- if (this.widgets.RuleListForm != null)
- {
- this.widgets.RuleListForm.InitListViewData();
- }
- }
- /// <summary>
- /// 激活理论比例尺
- /// </summary>
- public void ActivateTemporaryRuler()
- {
- if (this.widgets.RuleListForm != null)
- {
- this.widgets.RuleListForm.ActivateTemporaryRuler();
- }
- }
- /// <summary>
- /// 设置当前选中标尺
- /// </summary>
- /// <param name="index"></param>
- public void SetActiveRulerIndex(int index)
- {
- if (this.widgets.RuleListForm != null)
- {
- this.widgets.RuleListForm.SetActiveRulerIndex(index);
- }
- }
- /// <summary>
- /// 刷新当前选中的标尺-编辑后使用
- /// </summary>
- public void RefreshActiveRuler()
- {
- if (this.widgets.RuleListForm != null)
- {
- this.widgets.RuleListForm.RefreshActiveRuler();
- }
- }
- #endregion
- #region 项目工程
- /// <summary>
- /// 通用、专用分析添加到项目工程,获取路径,路径就是编号
- /// </summary>
- /// <param name="type">1通用分析 2专用分析</param>
- /// <param name="analysis">分析的名称</param>
- /// <returns></returns>
- public ProjectEngineering.NodeItem GetInsertProjectPath(int type, string analysis, string originPath)
- {
- return this.Widgets.ProjectEngineering.GetProjectPath(type, analysis, originPath);
- }
- /// <summary>
- /// 插入数据库
- /// </summary>
- /// <param name="analyzeSettingModel">分析设置信息</param>
- /// <param name="folder">项目编号</param>
- public void InsertIntoDB(AnalyzeSettingModel analyzeSettingModel, ProjectEngineering.NodeItem code)
- {
- this.Widgets.ProjectEngineering.InsertIntoDB(analyzeSettingModel, code);
- }
- public void RefreshCameraPriview()
- {
- if (cameraPreviewDialog != null && !cameraPreviewDialog.IsDisposed)
- cameraPreviewDialog.RefreshDrawNodes();
- }
- #endregion
- #region 生成报告相关
- /// <summary>
- /// 导出结果(一个sheet页/多个sheet页),可选择性的显示进度条
- /// </summary>
- 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)
- {
- AppCommon appCommon = new AppCommon();
- if (!appCommon.isExcelInstalled())
- {
- MessageBox.Show(PdnResources.GetString("office.Message"));
- return;
- }
- Microsoft.Office.Interop.Excel.Worksheet workSheet = null;
- Microsoft.Office.Interop.Excel.Workbook workBook = null;
- Microsoft.Office.Interop.Excel.Workbooks workbooks = null;
- Microsoft.Office.Interop.Excel.Application xlApp = null;
- if (showProgress /*&& currentForm != null*/ && datas != null && datas.Count > 0)
- {
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- int itemCount = 100;
- ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- try
- {
- progressEvents.SetItemCount(itemCount);
- double currentWriteRow = 0.0;
- double rowsCount = 0.0;
- foreach (System.Data.DataTable dtb in datas)
- rowsCount += dtb.Rows.Count;
- progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
- //if(heaterTextShow)
- //{
- // for (int i = 0; i < itemCount; ++i)
- // {
- // System.Threading.Thread.Sleep(50);
- // progressEvents.SetItemOrdinal(i);
- // }
- //}
- xlApp = new Microsoft.Office.Interop.Excel.Application();
- workbooks = xlApp.Workbooks;
- workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
- if (multiSheet)
- {
- if (datas != null && datas.Count > 0)
- {
- int ka = 1;
- foreach (System.Data.DataTable dtb in datas)
- {
- if (ka > 1)
- {
- Microsoft.Office.Interop.Excel.Sheets sheets = workBook.Worksheets;
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
- }
- else
- {
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
- }
- if (dtb.TableName != null)
- {
- workSheet.Name = dtb.TableName;
- }
- ka++;
- if (heaterTextShow)
- {
- for (int i = 0; i < dtb.Columns.Count; i++)
- {
- workSheet.Cells[1, i + 1] = dtb.Columns[i].ColumnName;
- }
- }
- //解决标题重复显示的问题
- bool columNameRepeat = true;
- if (dtb.Rows.Count > 0)
- for (int k = 0; k < dtb.Columns.Count; k++)
- if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
- {
- columNameRepeat = false;
- break;
- }
- for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
- {
- currentWriteRow += 1;
- progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
- for (int k = 0; k < dtb.Columns.Count; k++)
- {
- workSheet.Cells[j + (heaterTextShow ? 2 : 1) /*- (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
- }
- }
- //workSheet.SaveAs(path, missing, missing, missing, missing, missing, missing, missing, missing, missing);
- }
- }
- }
- else
- {
- workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
- if (datas != null && datas.Count > 0)
- {
- int kk = 0;
- int jj = 0;
- foreach (System.Data.DataTable dtb in datas)
- {
- //if (kk == 0)
- {
- if (heaterTextShow)
- {
- if (kk > 0)
- jj++;//避免标题被后面数据覆盖
- for (int i = 0; i < dtb.Columns.Count; i++)
- {
- workSheet.Cells[jj + 1, i + 1] = dtb.Columns[i].ColumnName;
- }
- }
- kk++;
- }
- //解决标题重复显示的问题
- bool columNameRepeat = true;
- if (dtb.Rows.Count > 0)
- for (int k = 0; k < dtb.Columns.Count; k++)
- if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
- {
- columNameRepeat = false;
- break;
- }
- for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
- {
- currentWriteRow += 1;
- progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
- for (int k = 0; k < dtb.Columns.Count; k++)
- {
- workSheet.Cells[jj + (heaterTextShow ? 2 : 1)/* - (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
- }
- jj++;
- }
- }
- }
- if (bitmapList != null && bitmapList.Count > 0)
- {
- try
- {
- foreach (var item in bitmapList)
- {
- int left = Convert.ToInt32(item.Split(',')[1]);
- int top = Convert.ToInt32(item.Split(',')[2]);
- int width = Convert.ToInt32(item.Split(',')[3]);
- int height = Convert.ToInt32(item.Split(',')[4]);
- workSheet.Shapes.AddPicture(item.Split(',')[0], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, left, top, width, height);
- }
- //workSheet.Shapes.AddPicture("", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, PicLeft, PicTop, 90, 70);
- }
- catch
- {
- }
- }
- }
- object nothing = Type.Missing;
- // workSheet.Cells.ColumnWidth = 15;
- //workSheet.Range["A1:C1"].ColumnWidth = 12;
- //workSheet.Range["A1:A4"].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
- //workSheet.Range["B2:Z2"].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
- //workSheet.Range["A6:C6"].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
- // workSheet.Range["B1:L1"].ColumnWidth = 12;
- //workSheet.Range["A1:L1"].Font.Name = "黑体";
- //workSheet.Range["A1:L1"].Font.Size = 12;
- workBook.SaveAs(path, nothing, nothing, nothing, nothing, nothing,
- Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);
- }
- catch (Exception e)
- {
- System.Console.WriteLine(e.ToString());
- }
- finally
- {
- if (xlApp != null)
- {
- if (xlApp != null && workBook != null)
- workBook.Close(false);
- xlApp.Quit();
- OfficeFileHandleHelper.Kill(xlApp);
- }
- progressEvents.EndOperation(OperationResult.Finished);
- }
- };
- procClass.StartProgressAction(/*currentForm*/this.form, itemCount, copyThreadProc, progressEvents, dialogText);
- return;
- }
- try
- {
- xlApp = new Microsoft.Office.Interop.Excel.Application();
- workbooks = xlApp.Workbooks;
- workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
- if (multiSheet)
- {
- if (datas != null && datas.Count > 0)
- {
- int ka = 1;
- foreach (System.Data.DataTable dtb in datas)
- {
- if (ka > 1)
- {
- Microsoft.Office.Interop.Excel.Sheets sheets = workBook.Worksheets;
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
- }
- else
- {
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
- }
- if (dtb.TableName != null)
- workSheet.Name = dtb.TableName;
- ka++;
- if (heaterTextShow)
- {
- for (int i = 0; i < dtb.Columns.Count; i++)
- {
- workSheet.Cells[1, i + 1] = dtb.Columns[i].ColumnName;
- }
- }
- //解决标题重复显示的问题
- bool columNameRepeat = true;
- if (dtb.Rows.Count > 0)
- for (int k = 0; k < dtb.Columns.Count; k++)
- if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
- {
- columNameRepeat = false;
- break;
- }
- for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
- {
- for (int k = 0; k < dtb.Columns.Count; k++)
- {
- workSheet.Cells[j + (heaterTextShow ? 2 : 1)/* - (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
- }
- }
- //workSheet.SaveAs(path, missing, missing, missing, missing, missing, missing, missing, missing, missing);
- }
- }
- }
- else
- {
- workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
- if (datas != null && datas.Count > 0)
- {
- int kk = 0;
- int jj = 0;
- foreach (System.Data.DataTable dtb in datas)
- {
- //if (kk == 0)
- {
- if (heaterTextShow)
- {
- if (kk > 0)
- jj++;//避免标题被后面数据覆盖
- for (int i = 0; i < dtb.Columns.Count; i++)
- {
- workSheet.Cells[jj + 1, i + 1] = dtb.Columns[i].ColumnName;
- }
- }
- kk++;
- }
- //解决标题重复显示的问题
- bool columNameRepeat = true;
- if (dtb.Rows.Count > 0)
- for (int k = 0; k < dtb.Columns.Count; k++)
- if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
- {
- columNameRepeat = false;
- break;
- }
- for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
- {
- for (int k = 0; k < dtb.Columns.Count; k++)
- {
- workSheet.Cells[jj + (heaterTextShow ? 2 : 1) /*- (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
- }
- jj++;
- }
- }
- }
- }
- object nothing = Type.Missing;
- workBook.SaveAs(path, nothing, nothing, nothing, nothing, nothing,
- Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);
- }
- catch (Exception e)
- {
- System.Console.WriteLine(e.ToString());
- }
- finally
- {
- if (xlApp != null)
- {
- if (xlApp != null && workBook != null)
- workBook.Close(false);
- xlApp.Quit();
- OfficeFileHandleHelper.Kill(xlApp);
- }
- }
- }
- public void ExportDataToExcelWithProgressForCrystal(List<List<System.Data.DataTable>> datasMore, List<List<string>> bitmapListMore, string path, string dialogText=null)
- {
- AppCommon appCommon = new AppCommon();
- if (!appCommon.isExcelInstalled())
- {
- MessageBox.Show(PdnResources.GetString("office.Message"));
- return;
- }
- Microsoft.Office.Interop.Excel.Worksheet workSheet = null;
- Microsoft.Office.Interop.Excel.Workbook workBook = null;
- Microsoft.Office.Interop.Excel.Workbooks workbooks = null;
- Microsoft.Office.Interop.Excel.Application xlApp = null;
- if (datasMore != null && datasMore.Count > 0)
- {
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- int itemCount = 100;
- ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- try
- {
- progressEvents.SetItemCount(itemCount);
- double currentWriteRow = 0.0;
- double rowsCount = 0.0;
- foreach (List<System.Data.DataTable> datas in datasMore)
- {
- foreach (System.Data.DataTable dtb in datas)
- {
- rowsCount += dtb.Rows.Count;
- }
- }
-
-
- progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
-
- xlApp = new Microsoft.Office.Interop.Excel.Application();
- workbooks = xlApp.Workbooks;
- workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
- workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
-
- for (int one = 0; one < datasMore.Count; one++)
- {
- List<System.Data.DataTable> datas = datasMore[one];
- int current = 15 * one; ;
- if (datas != null && datas.Count > 0)
- {
- int kk = 0;
- int jj = 0;
- foreach (System.Data.DataTable dtb in datas)
- {
- if (kk > 0)
- jj++;//避免标题被后面数据覆盖
- for (int i = 0; i < dtb.Columns.Count; i++)
- {
- workSheet.Cells[jj + 1, i + 1+ current] = dtb.Columns[i].ColumnName;
- }
- kk++;
- //解决标题重复显示的问题
- bool columNameRepeat = true;
- if (dtb.Rows.Count > 0)
- for (int k = 0; k < dtb.Columns.Count; k++)
- if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
- {
- columNameRepeat = false;
- break;
- }
- for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
- {
- currentWriteRow += 1;
- progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
- for (int k = 0; k < dtb.Columns.Count; k++)
- {
- workSheet.Cells[jj + 2, k + 1+ current] = dtb.Rows[j][k].ToString();
- }
- jj++;
- }
- }
- if (one == 0)
- {
- continue;
- }
- List<string> bitmapList = bitmapListMore[one - 1];
- if (bitmapList != null && bitmapList.Count > 0)
- {
- try
- {
- foreach (var item in bitmapList)
- {
- int left = Convert.ToInt32(item.Split(',')[1])+48*15*one;
- int top = Convert.ToInt32(item.Split(',')[2]);
- int width = Convert.ToInt32(item.Split(',')[3]);
- int height = Convert.ToInt32(item.Split(',')[4]);
- workSheet.Shapes.AddPicture(item.Split(',')[0], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, left, top, width, height);
- }
- }
- catch
- {
- }
- }
- }
- }
-
- object nothing = Type.Missing;
- //workSheet.Range["A1:B1"].ColumnWidth = 12;
- //workSheet.Range["A1:A4"].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
- //workSheet.Range["B2:Z2"].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
- //workSheet.Range["A6:C6"].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
-
- workBook.SaveAs(path, nothing, nothing, nothing, nothing, nothing,
- Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);
- }
- catch (Exception e)
- {
- System.Console.WriteLine(e.ToString());
- }
- finally
- {
- if (xlApp != null)
- {
- if (xlApp != null && workBook != null)
- workBook.Close(false);
- xlApp.Quit();
- OfficeFileHandleHelper.Kill(xlApp);
- }
- progressEvents.EndOperation(OperationResult.Finished);
- }
- };
- procClass.StartProgressAction(/*currentForm*/this.form, itemCount, copyThreadProc, progressEvents, dialogText);
- return;
- }
-
- }
- 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)
- {
- AppCommon appCommon = new AppCommon();
- if (!appCommon.isExcelInstalled())
- {
- MessageBox.Show(PdnResources.GetString("office.Message"));
- return;
- }
- Microsoft.Office.Interop.Excel.Worksheet workSheet = null;
- Microsoft.Office.Interop.Excel.Workbook workBook = null;
- Microsoft.Office.Interop.Excel.Workbooks workbooks = null;
- Microsoft.Office.Interop.Excel.Application xlApp = null;
- if (showProgress /*&& currentForm != null*/ && datas != null && datas.Count > 0)
- {
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- int itemCount = 100;
- ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- try
- {
- progressEvents.SetItemCount(itemCount);
- double currentWriteRow = 0.0;
- double rowsCount = 0.0;
- foreach (System.Data.DataTable dtb in datas)
- rowsCount += dtb.Rows.Count;
- progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
- //if(heaterTextShow)
- //{
- // for (int i = 0; i < itemCount; ++i)
- // {
- // System.Threading.Thread.Sleep(50);
- // progressEvents.SetItemOrdinal(i);
- // }
- //}
- xlApp = new Microsoft.Office.Interop.Excel.Application();
- workbooks = xlApp.Workbooks;
- workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
- if (multiSheet)
- {
- if (datas != null && datas.Count > 0)
- {
- int ka = 1;
- foreach (System.Data.DataTable dtb in datas)
- {
- if (ka > 1)
- {
- Microsoft.Office.Interop.Excel.Sheets sheets = workBook.Worksheets;
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
- }
- else
- {
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
- }
- if (dtb.TableName != null)
- {
- workSheet.Name = dtb.TableName;
- }
- ka++;
- if (heaterTextShow)
- {
- for (int i = 0; i < dtb.Columns.Count; i++)
- {
- workSheet.Cells[1, i + 1] = dtb.Columns[i].ColumnName;
- }
- }
- //解决标题重复显示的问题
- bool columNameRepeat = true;
- if (dtb.Rows.Count > 0)
- for (int k = 0; k < dtb.Columns.Count; k++)
- if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
- {
- columNameRepeat = false;
- break;
- }
- for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
- {
- currentWriteRow += 1;
- progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
- for (int k = 0; k < dtb.Columns.Count; k++)
- {
- workSheet.Cells[j + (heaterTextShow ? 2 : 1) /*- (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
- }
- }
- if (bitmapList != null && bitmapList.Count > 0)
- {
- try
- {
- //worksheet.Shapes.AddPicture(PicturePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, PicLeft, PicTop, PictuteWidth, PictureHeight);
- //workSheet.Shapes.AddPicture("", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, PicLeft, PicTop, 90, 70);
- }
- catch
- {
- }
- }
- //workSheet.SaveAs(path, missing, missing, missing, missing, missing, missing, missing, missing, missing);
- }
- }
- }
- else
- {
- workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
- if (datas != null && datas.Count > 0)
- {
- int kk = 0;
- int jj = 0;
- foreach (System.Data.DataTable dtb in datas)
- {
- //if (kk == 0)
- {
- if (heaterTextShow)
- {
- if (kk > 0)
- jj++;//避免标题被后面数据覆盖
- for (int i = 0; i < dtb.Columns.Count; i++)
- {
- workSheet.Cells[jj + 1, i + 1] = dtb.Columns[i].ColumnName;
- }
- }
- kk++;
- }
- //解决标题重复显示的问题
- bool columNameRepeat = true;
- if (dtb.Rows.Count > 0)
- for (int k = 0; k < dtb.Columns.Count; k++)
- if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
- {
- columNameRepeat = false;
- break;
- }
- for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
- {
- currentWriteRow += 1;
- progressEvents.SetItemOrdinal((int)(currentWriteRow * 100 / rowsCount));
- for (int k = 0; k < dtb.Columns.Count; k++)
- {
- workSheet.Cells[jj + (heaterTextShow ? 2 : 1)/* - (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
- }
- jj++;
- }
- }
- }
- }
- object nothing = Type.Missing;
- workBook.SaveAs(path, nothing, nothing, nothing, nothing, nothing,
- Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);
- }
- catch (Exception e)
- {
- System.Console.WriteLine(e.ToString());
- }
- finally
- {
- if (xlApp != null)
- {
- if (xlApp != null && workBook != null)
- workBook.Close(false);
- xlApp.Quit();
- OfficeFileHandleHelper.Kill(xlApp);
- }
- progressEvents.EndOperation(OperationResult.Finished);
- }
- };
- procClass.StartProgressAction(/*currentForm*/this.form, itemCount, copyThreadProc, progressEvents, dialogText);
- return;
- }
- try
- {
- xlApp = new Microsoft.Office.Interop.Excel.Application();
- workbooks = xlApp.Workbooks;
- workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
- if (multiSheet)
- {
- if (datas != null && datas.Count > 0)
- {
- int ka = 1;
- foreach (System.Data.DataTable dtb in datas)
- {
- if (ka > 1)
- {
- Microsoft.Office.Interop.Excel.Sheets sheets = workBook.Worksheets;
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
- }
- else
- {
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
- }
- if (dtb.TableName != null)
- workSheet.Name = dtb.TableName;
- ka++;
- if (heaterTextShow)
- {
- for (int i = 0; i < dtb.Columns.Count; i++)
- {
- workSheet.Cells[1, i + 1] = dtb.Columns[i].ColumnName;
- }
- }
- //解决标题重复显示的问题
- bool columNameRepeat = true;
- if (dtb.Rows.Count > 0)
- for (int k = 0; k < dtb.Columns.Count; k++)
- if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
- {
- columNameRepeat = false;
- break;
- }
- for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
- {
- for (int k = 0; k < dtb.Columns.Count; k++)
- {
- workSheet.Cells[j + (heaterTextShow ? 2 : 1)/* - (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
- }
- }
- //workSheet.SaveAs(path, missing, missing, missing, missing, missing, missing, missing, missing, missing);
- }
- }
- }
- else
- {
- workBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
- workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
- if (datas != null && datas.Count > 0)
- {
- int kk = 0;
- int jj = 0;
- foreach (System.Data.DataTable dtb in datas)
- {
- //if (kk == 0)
- {
- if (heaterTextShow)
- {
- if (kk > 0)
- jj++;//避免标题被后面数据覆盖
- for (int i = 0; i < dtb.Columns.Count; i++)
- {
- workSheet.Cells[jj + 1, i + 1] = dtb.Columns[i].ColumnName;
- }
- }
- kk++;
- }
- //解决标题重复显示的问题
- bool columNameRepeat = true;
- if (dtb.Rows.Count > 0)
- for (int k = 0; k < dtb.Columns.Count; k++)
- if (!dtb.Rows[0][k].ToString().Equals(dtb.Columns[k].ColumnName))
- {
- columNameRepeat = false;
- break;
- }
- for (int j = columNameRepeat ? 1 : 0; j < dtb.Rows.Count; j++)
- {
- for (int k = 0; k < dtb.Columns.Count; k++)
- {
- workSheet.Cells[jj + (heaterTextShow ? 2 : 1) /*- (columNameRepeat ? 1 : 0)*/, k + 1] = dtb.Rows[j][k].ToString();
- }
- jj++;
- }
- }
- }
- }
- object nothing = Type.Missing;
- workBook.SaveAs(path, nothing, nothing, nothing, nothing, nothing,
- Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);
- }
- catch (Exception e)
- {
- System.Console.WriteLine(e.ToString());
- }
- finally
- {
- if (xlApp != null)
- {
- if (xlApp != null && workBook != null)
- workBook.Close(false);
- xlApp.Quit();
- OfficeFileHandleHelper.Kill(xlApp);
- }
- }
- }
- /// <summary>
- /// 生成分析报告(夹杂物)
- /// </summary>
- /// <param name="analyzeSettingModel">基础信息对象</param>
- /// <param name="contentList">数据对象模型</param>
- /// <param name="bitmapList">图片集合</param>
- /// <param name="tagPositionDic">除基础信息外的word书签与excel坐标对应信息</param>
- public void CreateAnalysisReportInclusion(AnalyzeSettingModel analyzeSettingModel, List<List<List<string>>> sheets, List<Bitmap> bitmapList,
- Dictionary<string, string> tagPositionDic)
- {
- AppCommon appCommon = new AppCommon();
- if (!appCommon.isExcelInstalled())
- {
- MessageBox.Show(PdnResources.GetString("office.Message"));
- return;
- }
- if (analyzeSettingModel == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
- return;
- }
- if (string.IsNullOrEmpty(analyzeSettingModel.savePath))
- {
- MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
- return;
- }
- if (sheets.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
- return;
- }
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
- double pointPitch = 0;
- if (dotPitch > 0)
- {
- mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
- if (screenList != null)
- {
- try
- {
- pointPitch = double.Parse(screenList.point_pitch);//获取点距
- }
- catch (System.Exception)
- {
- }
- }
- }
- //获取系统的毫米标尺
- double unitLength = 0;
- this.getMeasureInfo().TryGetValue(MeasurementUnit.Millimeter, out unitLength);
- if (unitLength == 0)
- unitLength = 1;
- try
- {
- OfficeFileHandleHelper.CreateAnalysisReportInclusion(analyzeSettingModel, sheets, bitmapList, tagPositionDic, pointPitch, unitLength, GetGainMultiple());
- procClass.DismissProgressAction(this.form);
- MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
- }
- catch (Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
- }
- finally
- {
- procClass.DismissProgressAction(this.form);
- }
- };
- procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
- }
- /// <summary>
- /// 生成分析报告
- /// </summary>
- /// <param name="analyzeSettingModel"></param>
- /// <param name="contentList"></param>
- /// <param name="bitmapList"></param>
- /// <param name="tagPositionDic"></param>
- public void CreateAnalysisReport(AnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<Bitmap> bitmapList,
- Dictionary<string, string> tagPositionDic, string dictPath = null, Dictionary<string, string> pNames = null, List<List<string>> content2List = null)
- {
- AppCommon appCommon = new AppCommon();
- if (!appCommon.isExcelInstalled())
- {
- MessageBox.Show(PdnResources.GetString("office.Message"));
- return;
- }
- if (analyzeSettingModel == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
- return;
- }
- if (string.IsNullOrEmpty(analyzeSettingModel.savePath))
- {
- MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
- return;
- }
- if (contentList != null && contentList.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
- return;
- }
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- //bool isNeedZoom = false;//是否需要缩放
- //int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
- //double pointPitch = 0;
- //if (dotPitch > 0)
- //{
- // mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
- // if (screenList != null)
- // {
- // try
- // {
- // pointPitch = double.Parse(screenList.point_pitch);//获取点距
- // if (pointPitch > 0)
- // isNeedZoom = true;
- // }
- // catch (System.Exception)
- // {
- // }
- // }
- //}
- //当前图片微米标尺(点距计算用毫米)
- double unitLength = 0;
- //当前图片放大倍数
- double pointPitch = 0;
- this.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
- //获取当前图片放大倍数
- if (this.activeDocumentWorkspace != null)
- pointPitch = (double)this.activeDocumentWorkspace.xmlSaveModel.gain_multiple;
- else
- pointPitch = 1;
- bool isNeedZoom = true;
- if (unitLength == 0)
- unitLength = 1;
- try
- {
- OfficeFileHandleHelper.CreateAnalysisReport(analyzeSettingModel, contentList, bitmapList, tagPositionDic, isNeedZoom, pointPitch, unitLength, GetGainMultiple(), dictPath, pNames, content2List);
- procClass.DismissProgressAction(this.form);
- MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
- }
- catch (Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
- }
- finally
- {
- procClass.DismissProgressAction(this.form);
- }
- };
- procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
- }
- /// <summary>
- /// 生成分析报告并保存图片与中间数据
- /// </summary>
- /// <param name="analyzeSettingModel"></param>
- /// <param name="contentList"></param>
- /// <param name="dataList"></param>
- /// <param name="bitmapList"></param>
- /// <param name="tagPositionDic"></param>
- /// <param name="newPath"></param>
- /// <param name="newCode"></param>
- public void CreateAnalysisReport(AnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<ExportProjectModel> dataList,
- List<Bitmap> bitmapList, Dictionary<string, string> tagPositionDic, string newPath, string newCode
- , string dictPath = null, Dictionary<string, string> pNames = null, List<List<string>> content2List = null)
- {
- AppCommon appCommon = new AppCommon();
- if (!appCommon.isExcelInstalled())
- {
- MessageBox.Show(PdnResources.GetString("office.Message"));
- return;
- }
- if (analyzeSettingModel == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
- return;
- }
- if (string.IsNullOrEmpty(newPath))
- {
- MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
- return;
- }
- if (contentList.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.noresult.Text"));
- return;
- }
- if (string.IsNullOrEmpty(newCode))
- {
- MessageBox.Show(PdnResources.GetString("Menu.nonumcannotsave.Text"));
- return;
- }
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- //bool isNeedZoom = false;//是否需要缩放
- //int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
- //double pointPitch = 0;
- //if (dotPitch > 0)
- //{
- // mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
- // if (screenList != null)
- // {
- // try
- // {
- // pointPitch = double.Parse(screenList.point_pitch);//获取点距
- // if (pointPitch > 0)
- // isNeedZoom = true;
- // }
- // catch (System.Exception)
- // {
- // }
- // }
- //}
- ////获取系统的毫米标尺
- //double unitLength = 0;
- //this.getMeasureInfo().TryGetValue(MeasurementUnit.Millimeter, out unitLength);
- //if (unitLength == 0)
- // unitLength = 1;
- //当前图片微米标尺(点距计算用毫米)
- double unitLength = 0;
- //当前图片放大倍数
- double pointPitch = 0;
- this.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
- //获取当前图片放大倍数
- if (this.activeDocumentWorkspace != null)
- pointPitch = (double)this.activeDocumentWorkspace.xmlSaveModel.gain_multiple;
- else
- pointPitch = 1;
- bool isNeedZoom = true;
- try
- {
- OfficeFileHandleHelper.CreateAnalysisReport(analyzeSettingModel, contentList, dataList, bitmapList, tagPositionDic, newPath, newCode, isNeedZoom, pointPitch, unitLength, GetGainMultiple(), dictPath, pNames, content2List);
- procClass.DismissProgressAction(this.form);
- MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
- }
- catch (Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
- }
- finally
- {
- procClass.DismissProgressAction(this.form);
- }
- };
- procClass.StartProgressAutoAction(this.form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Exportproject.text"));
- }
- public void CopyAndPasteByControlAndDoubleClick()
- {
- this.ToolBar.CopyAndPasteByControlAndDoubleClick();
- }
- #endregion
- public DrawToolType GetDrawToolType()
- {
- return activeTool;
- }
- public void SetDrawToolType(DrawToolType t)
- {
- activeTool = t;
- }
- public void SetContinuousDrawingMeasure(bool value)
- {
- this.continuousDrawingMeasure = value;
- SetTopLeftCheckState();
- }
- public void SetContinuousDrawingLable(bool value)
- {
- this.continuousDrawingLabel = value;
- SetTopLeftCheckState();
- }
- /// <summary>
- /// 录制脚本添加参数
- /// </summary>
- public void SetScriptStartRecording(int menuId, string menuName, List<Args> list)
- {
- mic_script_step script_Step = new mic_script_step();
- script_Step.automatic = 2;
- script_Step.menu_id = menuId;
- script_Step.script_id = 0;
- script_Step.step_name = menuName;
- script_Step.step_sort = this.addMicScriptStepList.Count;
- this.addMicScriptStepList.Add(script_Step);
- this.addMicScriptStepParamList.Add(script_Step, list);
- }
- }
- }
|