12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183 |
- using IWshRuntimeLibrary;
- using Metis.Measuring;
- 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;
- using MSWord = Microsoft.Office.Interop.Word;
- using MSExcel = Microsoft.Office.Interop.Excel;
- 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 drawToolType = 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>
- private void UpdatePixelTracking()
- {
- if (this.pixelTrackingDialog != null)
- {
- this.pixelTrackingDialog.Mat = null;
- }
- }
- [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 bool ContinuousDrawing
- {
- get => DocumentView.ContinuousDrawing;
- set
- {
- DocumentView.ContinuousDrawing = value;
- toolBar.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingMeasure");
- toolsPanel.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingMeasure");
- toolBar.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingLabel");
- toolsPanel.RefreshBtnSelect(DocumentView.ContinuousDrawing, "ContinuousDrawingLabel");
- if (ActiveDocumentWorkspace != null && !DocumentView.ContinuousDrawing
- && ActiveDocumentWorkspace.ActiveTool >= DrawToolType.MeasureLine && ActiveDocumentWorkspace.ActiveTool <= DrawToolType.MeasureThreePointArc)
- {
- ActiveDocumentWorkspace.ToolNumber = -1;
- ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
- }
- toolBar.MainMenu.measureActionMenu.checkMenu(DocumentView.ContinuousDrawing);
- toolBar.MainMenu.labelActionMenu.checkMenu(DocumentView.ContinuousDrawing);
- if (cameraPreviewDialog != null && !cameraPreviewDialog.IsDisposed)
- {
- if (!DocumentView.ContinuousDrawing)
- {
- cameraPreviewDialog.documentWorkspace.ActiveTool = DrawToolType.Pointer;
- }
- if (ActiveDocumentWorkspace != null
- && ActiveDocumentWorkspace.ActiveTool >= DrawToolType.MeasureLine
- && ActiveDocumentWorkspace.ActiveTool <= DrawToolType.MeasureThreePointArc)
- {
- ActiveDocumentWorkspace.ToolNumber = -1;
- }
- }
- }
- }
- public DocumentWorkspace ActiveDocumentWorkspace
- {
- get
- {
- return this.activeDocumentWorkspace;
- }
- set
- {
- if (this.activeDocumentWorkspace != null)
- {
- drawToolType = this.activeDocumentWorkspace.ActiveTool;
- }
- 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);
- if (this.ContinuousDrawing && value != null)
- {
- value.ActiveTool = drawToolType;
- }
- 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.ContinuousDrawing;
- dw.ContinuousDrawingMeasure = this.ContinuousDrawing;
- if (this.drawToolType == DrawToolType.DrawAutoRuler || this.drawToolType == DrawToolType.DrawPrestoredRuler || this.drawToolType == DrawToolType.DrawDateMark || this.drawToolType == DrawToolType.DrawTimeMark || this.drawToolType == DrawToolType.DrawGainNumber)
- {
- dw.ActiveTool = DrawToolType.Pointer;
- }
- else {
- dw.ActiveTool = this.drawToolType;
- }
- 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;
- 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", mode);
- }
- else
- {
- photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, Startup.instance.ruleDB.ruler_name, Startup.instance.ruleDB.gain_multiple.ToString(), mode);
- }
- UpdateContinueNum();
- Widgets.ImageIndexDialog.PreviewRefresh();
- DocumentWorkspace dw = NewDocumentWorkspace();
- dw.fileText = photoName;
- Document document = Document.FromMat(PaintDotNet.Camera.Tools.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;
- case -1:
- dw.fileText = photoName + ".jpg";
- dw.picName = dw.fileText;
- dw.filePath = Startup.instance.configModel.FilePath != null ? Startup.instance.configModel.FilePath + "\\" + dw.fileText : Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\" + dw.fileText;
- return dw.DoSaveNew();
- case -3:
- dw.fileText = photoName + ".jpg";
- dw.UpdateDw2buttonName(dw.fileText);
- dw.picName = dw.fileText;
- dw.filePath = Startup.instance.configModel.FilePath != null ? Startup.instance.configModel.FilePath + "\\" + dw.fileText : Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\" + dw.fileText;
- var res = dw.DoSaveNew();
- if (!res) return res; 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;
- }
- public 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;
- bool isLianXu = this.ContinuousDrawing;
- 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 = PaintDotNet.Camera.Tools.ToMat(map);
- //if (this.histogramDialog != null) this.histogramDialog.Mat = PaintDotNet.Camera.Tools.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);
- }
- }
- bool isLianxu = this.ContinuousDrawing;
- 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 = PaintDotNet.Camera.Tools.ToMat(map);
- // if (this.histogramDialog != null) this.histogramDialog.Mat = PaintDotNet.Camera.Tools.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.ContinuousDrawing;
- this.activeDocumentWorkspace.ContinuousDrawingLabel = this.ContinuousDrawing;
- 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();
- PdnBaseForm.RegisterFormHotKey(Keys.Escape, EscapeMethod);
- }
- /// <summary>
- /// esc事件
- /// </summary>
- /// <param name="t"></param>
- /// <returns></returns>
- private bool EscapeMethod(Keys t)
- {
- if (this.activeDocumentWorkspace != null)
- {
- if (!this.continuousDrawingMeasure && !this.continuousDrawingLabel)
- {
- this.activeDocumentWorkspace.MouseEvent_Del(null, null);
- this.activeDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
- }
- }
- return true;
- }
- 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;
- 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);
- 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;
- if (isInitial)
- {
- this.initialWorkspace = dw;
- }
- if (focused)
- {
- this.ActiveDocumentWorkspace.Focus();
- }
- this.Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
- }
- }
- finally
- {
- }
- return true;
- }
- public bool OpenFilesInNewWorkspace(string[] fileNames)
- {
- if (IsDisposed)
- {
- return false;
- }
- bool result = true;
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- int itemCount = fileNames.Length;
- ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- try
- {
- for (int i = 0; i < fileNames.Length; i++)
- {
- if (!OpenFileInNewWorkspace(fileNames[i]))
- {
- continue;
- }
- System.Threading.Thread.Sleep(100);
- this.Invoke(new Action(() =>
- {
- progressEvents.SetStringProgress((i + 1) + "/" + fileNames.Length);
- }));
- }
- }
- catch (Exception)
- {
- }
- finally
- {
- progressEvents.EndOperation(OperationResult.Finished);
- }
- };
- procClass.StartProgressAction((MainForm)this.Parent, itemCount, copyThreadProc, progressEvents, "打开图片");
- return result;
- }
- public void OpenFileInNewWorkspaceThread(object obj)
- {
- string[] fileNames = (string[])obj;
- foreach (string fileName in fileNames)
- {
- bool result = OpenFileInNewWorkspace(fileName);
- if (!result)
- {
- continue;
- }
- System.Threading.Thread.Sleep(100);
- }
- }
- 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但一张图片都没有,不做处理
- }
- this.Invoke(new Action(() =>
- {
- 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.FromImageMat(Camera.Tools.ToMat((Bitmap)zipImage));
- }
- else
- {
- OpenCvSharp.Mat temp = new OpenCvSharp.Mat(fileName);
- if (temp.Empty()) return false;
- document = Document.FromMat(temp);// DocumentWorkspace.LoadDocument(this, fileName, /*out fileType, */progressCallback);
- }
- this.widgets.StatusBarProgress.EraseProgressStatusBar();
- if (document == null)
- {
- this.Cursor = Cursors.Default;
- }
- else
- {
- this.Invoke(new Action(() =>
- {
- 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";
- string xmlPathAV = fileName+"_meta.xml";
- string xmlPathZEN = fileName + "_zen.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);
- }
- }
- //else if (System.IO.File.Exists(xmlPathAV) && Startup.instance.configModel.AddAxioVision == 1)
- //{
- // dw.RuleAttribute(xmlPathAV);
- // dw.Units = Startup.instance.measurementUnit;
- // //string[] vs = XmlSerializeHelper.GetRuler(xmlPathAV);
- //}
- //else if (System.IO.File.Exists(xmlPathZEN) && Startup.instance.configModel.AddZEN == 1)
- //{
- // //dw.RuleAttribute(xmlPathZEN);
- // //dw.Units = Startup.instance.measurementUnit;
- //}
- //如果不存在,则判断
- //(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);
- 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, DocumentView doc)
- {
- if (this.pixelTrackingDialog != null)
- {
- this.pixelTrackingDialog.SetImageAndData(location, doc);
- }
- }
- /// <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 = this.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
- OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
- OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.Y);
- if (this.scriptRunning)
- {
- DocumentWorkspace dw = this.AddNewDocumentWorkspace();
- Document document = Document.FromImageMat(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.FromImageMat(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 = this.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
- OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
- OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.X);
- if (this.scriptRunning)
- {
- DocumentWorkspace dw = this.AddNewDocumentWorkspace();
- Document document = Document.FromImageMat(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.FromImageMat(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 = this.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
- OpenCvSharp.Mat dst = new OpenCvSharp.Mat();
- OpenCvSharp.Cv2.Flip(src, dst, OpenCvSharp.FlipMode.XY);
- if (this.scriptRunning)
- {
- DocumentWorkspace dw = this.AddNewDocumentWorkspace();
- Document document = Document.FromImageMat(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.FromImageMat(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.FromImageMat(Camera.Tools.ToMat((Bitmap)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
- /// <summary>
- /// 刷新测量工具相关别名
- /// </summary>
- public void RefreshAliasName()
- {
- if (this.widgets.GeometryMeasureDialog != null)
- {
- this.widgets.GeometryMeasureDialog.RefreshAliasName();
- }
- }
- #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);
- }
- #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)
- {
- 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++;
- }
- }
- }
- }
- 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
- #region
- //creating by zm
- /// <summary>
- /// 生成高碳铬轴承钢分析报告
- /// </summary>
- /// <param name="analyzeSettingModel"></param>
- /// <param name="contentList"></param>
- /// <param name="bitmapList"></param>
- /// <param name="tagPositionDic"></param>
- public void CreateAnalysisReportBearingSteal(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 ()
- {
- //当前图片微米标尺(点距计算用毫米)
- 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;
- CreateAnalysisReportBearingSteelExcel(analyzeSettingModel, contentList, bitmapList, tagPositionDic, isNeedZoom, pointPitch, unitLength, GetGainMultiple(), dictPath, pNames, content2List);
- //CreateBearingStealDOC(analyzeSettingModel, contentList,bitmapList, tagPositionDic, pointPitch, unitLength, GetGainMultiple());
- procClass.DismissProgressAction(this.form);
- MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
- };
- 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">除基础信息外的word书签与excel坐标对应信息</param>
- /// <param name="pointPitch">当前图片放大倍数</param>
- /// <param name="unitLength">当前图片标尺</param>
- /// <param name="gainMultiple">系统激活放大倍数(暂时不用保留)</param>
- private static void CreateAnalysisReportBearingSteelExcel(AnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<Bitmap> bitmapList,
- Dictionary<string, string> tagPositionDic, bool isNeedZoom, double pointPitch, double unitLength, decimal gainMultiple, string dictPath = null, Dictionary<string, string> pNames = null, List<List<string>> content2List = null)
- {
- string saveAsPath = "";
- string excelModulePath = Path.GetDirectoryName(analyzeSettingModel.modulePath) + "\\公式.xlsx";//获取excel公式模板的路径
- if (System.IO.File.Exists(excelModulePath))
- {
- saveAsPath = analyzeSettingModel.savePath + "\\" + "高碳铬轴承钢_GBT18254-2002_带状"
- + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";//另存的excel文件名
- //如果savePath是盘符不是文件夹,会多出一个斜杠,office的saveas无法识别,固需处理一下
- if (saveAsPath.IndexOf("\\\\") != -1)
- saveAsPath = saveAsPath.Replace("\\\\", "\\");
- if (contentList != null)
- {
- SaveAsExcelWithModule(excelModulePath, saveAsPath, contentList, dictPath, pNames, content2List);
- }
- CreateBearingStealDOC(analyzeSettingModel, contentList, bitmapList, tagPositionDic, pointPitch, unitLength, gainMultiple);
- }
- }
- private static MSWord.Application m_word;
- private static MSWord.Document m_doc;
- private static Object missing = Type.Missing;
- private static MSExcel.Application m_excel;
- private static MSExcel.Workbook m_workbook;
- private static MSExcel.Worksheet m_worksheet;
- private static MSExcel.Worksheet m2_worksheet;
- /// <summary>
- /// 通过公式模板创建并保存excel
- /// </summary>
- /// <param name="excelModulePath">excel公式模板路径</param>
- /// <param name="saveAsPath">新文件另存路径</param>
- /// <param name="contentList">数据对象模型</param>
- /// <returns></returns>
- private static bool SaveAsExcelWithModule(string excelModulePath, string saveAsPath, List<List<string>> contentList, string dictPath = null, Dictionary<string, string> pNames = null
- , List<List<string>> content2List = null)
- {
- try
- {
- m_excel = new MSExcel.Application();
- m_workbook = m_excel.Workbooks.Add(excelModulePath);
- m_worksheet = m_workbook.Sheets.Item[1];//数据固定插入在第二个sheet页
- if (contentList != null)
- {
- if (m_workbook.Sheets.Count < 3)
- m_workbook.Sheets.Add(System.Reflection.Missing.Value, m_worksheet, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
- m2_worksheet = m_workbook.Sheets.Item[1];
- AddTableToExcelSheet(m2_worksheet, 1, 1, contentList);
- }
- m_worksheet.SaveAs(saveAsPath, missing, missing, missing, missing, missing, missing, missing, missing, missing);
- //m_worksheet.Activate();
- m_workbook.Close(false);
- m_excel.Application.Quit();
- OfficeFileHandleHelper.Kill(m_excel);
- m_worksheet = null;
- m2_worksheet = null;
- m_workbook = null;
- m_excel = null;
- }
- catch (Exception)
- {
- if (m_excel != null)
- {
- if (m_workbook != null)
- m_workbook.Close(false);
- m_excel.Application.Quit();
- OfficeFileHandleHelper.Kill(m_excel);
- }
- m_worksheet = null;
- m2_worksheet = null;
- m_workbook = null;
- m_excel = null;
- return false;
- }
- return true;
- }
- /// <summary>
- /// 向excel的sheet页指定单元格插入表格(自行拼接的list形式)
- /// </summary>
- /// <param name="worksheet">sheet页</param>
- /// <param name="x">插入初始位置横坐标</param>
- /// <param name="y">插入初始位置纵坐标</param>
- /// <param name="contentList">表格对象</param>
- private static void AddTableToExcelSheet(MSExcel.Worksheet worksheet, int x, int y, List<List<string>> contentList)
- {
- if (contentList.Count > 0)
- {
- for (int i = x; i < contentList.Count + 1; i++)
- {
- List<string> rowContent = contentList[i - 1];
- if (rowContent.Count > 0)
- {
- for (int j = y; j < rowContent.Count + 1; j++)
- {
- worksheet.Cells[i, j] = rowContent[j - 1];
- }
- }
- }
- }
- }
- /// <summary>
- /// 通过模板创建高碳铬轴承钢word报告文档
- /// </summary>
- /// <param name="analyzeSettingModel"></param>
- /// <param name="tagValueDic"></param>
- /// <param name="bitmapList"></param>
- private static void CreateBearingStealDOC(AnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<Bitmap> bitmapList, Dictionary<string, string> tagValueDic, double pointPitch, double unitLength, decimal gainMultiple)
- {
- if (!string.IsNullOrEmpty(analyzeSettingModel.modulePath) && Directory.Exists(analyzeSettingModel.savePath))
- {
- string newFilePath = analyzeSettingModel.savePath + "\\" + "高碳铬轴承钢_GBT18254-2002_带状" +
- DateTime.Now.ToString("yyyyMMddHHmmss") + ".docx";
- if (newFilePath.IndexOf("\\\\") != -1)
- newFilePath = newFilePath.Replace("\\\\", "\\");
- try
- {
- System.IO.File.Copy(analyzeSettingModel.modulePath, newFilePath, true);
- }
- catch (Exception)
- {
- //MessageBox.Show("word模板文件已打开,请关闭后重试");
- return;
- }
- Object pathObj = newFilePath;
- try
- {
- m_word = new MSWord.Application();
- m_doc = m_word.Documents.Open(ref pathObj,
- ref missing, ref missing, ref missing, ref missing, ref missing,
- ref missing, ref missing);
- foreach (MSWord.Bookmark bk in m_doc.Bookmarks)
- {
- if (bk.Name == "modulePath")
- bk.Range.Text = analyzeSettingModel.modulePath;
- else if (bk.Name == "savePath")
- bk.Range.Text = analyzeSettingModel.savePath;
- else if (bk.Name == "inspectionPerson")
- bk.Range.Text = analyzeSettingModel.inspectionPerson;
- else if (bk.Name == "itemNumber")
- bk.Range.Text = analyzeSettingModel.itemNumber;
- else if (bk.Name == "inspectionDepartment")
- bk.Range.Text = analyzeSettingModel.inspectionDepartment;
- else if (bk.Name == "contact")
- bk.Range.Text = analyzeSettingModel.contact;
- else if (bk.Name == "ratingDate")
- bk.Range.Text = analyzeSettingModel.ratingDate.ToString("yyyy/MM/dd");
- else if (bk.Name == "inspectionDate")
- bk.Range.Text = analyzeSettingModel.inspectionDate.ToString("yyyy/MM/dd");
- else if (bk.Name == "analyzeClassify")
- bk.Range.Text = analyzeSettingModel.analyzeClassify;
- else if (bk.Name == "other")
- {
- if (analyzeSettingModel.otherList != null && analyzeSettingModel.otherList.Count > 0)
- {
- MSWord.Table table = m_doc.Tables.Add(bk.Range, analyzeSettingModel.otherList.Count + 1, 2, ref missing, ref missing);
- table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
- table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
- table.Cell(1, 1).Range.Text = "名称";
- table.Cell(1, 2).Range.Text = "内容";
- for (int i = 0; i < analyzeSettingModel.otherList.Count; i++)
- {
- table.Cell(2 + i, 1).Range.Text = analyzeSettingModel.otherList[i].name;
- table.Cell(2 + i, 2).Range.Text = analyzeSettingModel.otherList[i].content;
- }
- }
- }
- else if (bk.Name == "picture")
- {
- if (bitmapList != null && bitmapList.Count > 0)
- {
- bitmapList.Reverse();
- for (int i = 0; i < bitmapList.Count; i++)
- {
- //Clipboard.SetDataObject(System.Environment.NewLine);
- //bk.Range.Paste();
- //Image img = bitmapList[i];
- //OpenCvSharp.Mat m = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmapList[i]);
- //OpenCvSharp.Mat resize_image = new OpenCvSharp.Mat();
- //OpenCvSharp.Cv2.Resize(m,resize_image,new OpenCvSharp.Size(),0.5,0.5);
- //Bitmap b = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resize_image);
- //Clipboard.SetDataObject(b);
- //bk.Range.Paste();
- Bitmap bitmap = bitmapList[i];
- int new_w = (int)bitmap.Width / 4;
- int new_h = (int)bitmap.Height / 4;
- Bitmap b = new Bitmap(new_w, new_h);
- Graphics g = Graphics.FromImage(b);
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
- g.DrawImage(bitmap, new System.Drawing.Rectangle(0, 0, new_w, new_h), new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel);
- Clipboard.SetDataObject(b);
- bk.Range.Paste();
- b.Dispose();
- g.Dispose();
- }
- }
- }
- else
- {
- if (tagValueDic != null && tagValueDic.Count > 0)
- {
- foreach (KeyValuePair<string, string> kvp in tagValueDic)
- {
- if (bk.Name == kvp.Key)
- {
- bk.Range.Text = kvp.Value;
- break;
- }
- }
- }
- }
- }
- m_doc.Save();
- m_doc.Close(true);
- m_word.Quit();
- }
- catch (Exception ex)
- {
- string msg = ex.Message;
- if (m_word != null)
- {
- if (m_doc != null)
- m_doc.Close(false);
- m_word.Quit();
- }
- }
- m_doc = null;
- m_word = null;
- }
- }
- /// <summary>
- /// 返回定倍(A4纸)显示后的图片
- /// 定倍计算公式:图片像素(宽和高) * 当前图片标尺 * 当前图片放大倍数
- /// </summary>
- /// <param name="oldBit"></param>
- /// <param name="pointPitch">当前图片放大倍数</param>
- /// <param name="unitLength">当前图片标尺</param>
- /// <param name="gainMultiple">系统激活标尺放大倍数(暂时没用)</param>
- /// <returns></returns>
- private static Bitmap GetFixedMultipleBitmap(Bitmap oldBit, double pointPitch, double unitLength, decimal gainMultiple)
- {
- if (pointPitch == 0)
- return oldBit;
- int oldWidth = oldBit.Width;
- int oldHeight = oldBit.Height;
- int targetWidth = 0;
- int targetHeight = 0;
- if (oldWidth <= 1 || oldHeight <= 1)//像素最小为1,之后不再处理
- return oldBit;
- int newWidth = oldWidth / 2;
- int newHeight = oldHeight / 2;
- //缩放图片
- Bitmap targetBit = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppArgb);
- Graphics g = Graphics.FromImage(targetBit);
- g.DrawImage(oldBit, new System.Drawing.Rectangle(0, 0, newWidth, newHeight), new System.Drawing.Rectangle(0, 0, oldWidth, oldHeight), GraphicsUnit.Pixel);
- return targetBit;
- }
- #endregion
- public void SetContinuousDrawingMeasure(bool value)
- {
- this.continuousDrawingMeasure = value;
- this.continuousDrawingLabel = value;
- SetTopLeftCheckState();
- }
- public void SetContinuousDrawingLable(bool value)
- {
- this.continuousDrawingLabel = 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);
- }
- }
- }
|