123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030 |
- // CDrawObj.cpp: implementation of the CDrawObj class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "BaseProDlg.h"
- #include "DynamicProPage.h"
- #include "computer.h"
- #include "bardlg.h"
- #include "curvedlg.h"
- #include "MainFrm.h"
- #include "IDEView.h"
- #include "datainputdlg.h"
- #include "CommondServer.h"
- #include "gradient.h"
- #include "BitmapPage.h"
- #include "datapage.h"
- #include "logicpage.h"
- #include "SingleBarPage.h"
- #include "ArcPage.h"
- #include "WatchPage.h"
- #include "ReportBasePage.h"
- #include "ReportColPage.h"
- #include "YkCmdDlg.h"
- #include "Dlg_OCX.h"
- #include "Dlg_Flash.h"
- #include "SysLib.h"
- #include "Dlg_Pwd.h"
- #include "DlgQueryWarningRec.h"
- #include "DlgSystemLog.h"
- #include "DlgNoticeRec.h"
- #include "DlgEditPwd.h"
- #include "DlgUserManager.h"
- #include "AnalogDlg.h"
- #include "SystemParaSetDlg.h"
- extern CMainFrame *g_pMainFrm;
- #pragma warning (disable : 4805)
- #define DIR_UP 0
- #define DIR_DOWN 1
- #define DIR_LEFT 2
- #define DIR_RIGHT 3
- #define PIE 3.1415926
- // 表盘
- #define HOURSCALE 65
- #define MINUTESCALE 80
- #define HHAND TRUE
- #define MHAND FALSE
- #define SECONDSCALE 80
- #define MAXBLOBWIDTH 25
- #define BUFLEN 30
- #define REPAINT 0
- #define HANDPAINT 1
- #define UPDATE 0
- #define REDRAW 1
- #define OPEN_TLEN 450
- #define ICON_TLEN 45000
- #define CLKSCALE ((INT)8000)
- // END
- // 表盘
- typedef struct
- {
- SHORT sin;
- SHORT cos;
- } TRIG;
- TRIG CirTab[] = { // circle sin, cos, table
- { -7999, -0 },
- { -7956, -836 },
- { -7825, -1663 },
- { -7608, -2472 },
- { -7308, -3253 },
- { -6928, -4000 },
- { -6472, -4702 },
- { -5945, -5353 },
- { -5353, -5945 },
- { -4702, -6472 },
- { -3999, -6928 },
- { -3253, -7308 },
- { -2472, -7608 },
- { -1663, -7825 },
- { -836 , -7956 },
-
- { 0, -7999 },
- { 836, -7956 },
- { 1663, -7825 },
- { 2472, -7608 },
- { 3253, -7308 },
- { 3999, -6928 },
- { 4702, -6472 },
- { 5353, -5945 },
- { 5945, -5353 },
- { 6472, -4702 },
- { 6928, -4000 },
- { 7308, -3253 },
- { 7608, -2472 },
- { 7825, -1663 },
- { 7956, -836 },
- { 8000, 0 },
- { 7956, 836 },
- { 7825, 1663 },
- { 7608, 2472 },
- { 7308, 3253 },
- { 6928, 4000 },
- { 6472, 4702 },
- { 5945, 5353 },
- { 5353, 5945 },
- { 4702, 6472 },
- { 3999, 6928 },
- { 3253, 7308 },
- { 2472, 7608 },
- { 1663, 7825 },
- { 836, 7956 },
- { 0, 7999 },
- { -836, 7956 },
- { -1663, 7825 },
- { -2472, 7608 },
- { -3253, 7308 },
- { -4000, 6928 },
- { -4702, 6472 },
- { -5353, 5945 },
- { -5945, 5353 },
- { -6472, 4702 },
- { -6928, 3999 },
- { -7308, 3253 },
- { -7608, 2472 },
- { -7825, 1663 },
- { -7956, 836 }
- };
- // End
- IMPLEMENT_SERIAL(CAction, CObject, 0)
- CAction::CAction():CObject()
- {
- m_nActionType = YK_COMMOND;
- m_strVariant = _T("");
- m_strActionValue = _T("");
- m_strPicPath = _T("");
- }
- void CAction::Serialize(CArchive& ar)
- {
- CObject::Serialize(ar);
-
- if(ar.IsStoring())
- {
- ar << m_nActionType;
- ar << m_strVariant;
- ar << m_strActionValue;
- ar << m_strPicPath;
- }
- else
- {
- ar >> m_nActionType;
- ar >> m_strVariant;
- ar >> m_strActionValue;
- ar >> m_strPicPath;
- }
- }
- CAction& CAction::operator=(CAction& action)
- {
- m_nActionType = action.m_nActionType;
- m_strVariant = action.m_strVariant;
- m_strActionValue = action.m_strActionValue;
- m_strPicPath = action.m_strPicPath;
- return *this;
- }
- CAction* CAction::Clone(void)
- {
- CAction* pAction = new CAction;
- *pAction = *this;
- pAction->m_nActionType = m_nActionType;
- pAction->m_strVariant = m_strVariant;
- pAction->m_strActionValue = m_strActionValue;
- pAction->m_strPicPath = m_strPicPath;
- return pAction;
- }
- //---------------------------------------------- CDrawObj ---------
- CStringArray CDrawObj::drawsName;
- CPtrArray CDrawObj::drawsRuntimeClass;
- BOOL CDrawObj::bRuning = FALSE; // 是否处于运行状态;
- IMPLEMENT_SERIAL(CDrawObj, CObject, 0)
- CDrawObj::CDrawObj():CObject()
- {
- m_pView = NULL;
- m_nLineWidth = 1;
- m_strLineType = "PS_SOLID";
- m_clrFore = RGB(0, 0, 0);
- m_clrFill = RGB(0, 0, 255);
- m_clrLine = RGB(0, 0, 0); // 线色
- m_clrBack = RGB(255, 0, 0);
- m_clrCurrentFore = RGB(0, 255, 0);
- m_clrCurrentBack = RGB(255, 0, 0);
- m_clrCurrentLine = RGB(0, 255, 255);
- m_bLocked = FALSE;
- m_strCaption = "";
- m_logfont.lfHeight = -12;
- m_logfont.lfWidth = 0;
- m_logfont.lfEscapement = 0;
- m_logfont.lfOrientation = 0;
- m_logfont.lfWeight = FW_NORMAL;
- m_logfont.lfItalic = FALSE;
- m_logfont.lfUnderline = FALSE;
- m_logfont.lfStrikeOut = FALSE;
- if( strcmp(g_strLanguage, "ENG") == 0 )
- {
- m_logfont.lfCharSet = GB2312_CHARSET;
- }
- else if( strcmp(g_strLanguage, "CHS") == 0 )
- {
- m_logfont.lfCharSet = GB2312_CHARSET;
- }
- else if( strcmp(g_strLanguage, "CHT") == 0 )
- {
- m_logfont.lfCharSet = CHINESEBIG5_CHARSET;
- }
- m_logfont.lfOutPrecision = OUT_STROKE_PRECIS;
- m_logfont.lfClipPrecision = CLIP_STROKE_PRECIS;
- m_logfont.lfQuality = DEFAULT_QUALITY;//DRAFT_QUALITY;
- m_logfont.lfPitchAndFamily = FIXED_PITCH|FF_MODERN;
- if( strcmp(g_strLanguage, "ENG") == 0 )
- {
- strcpy(m_logfont.lfFaceName,g_strTimesNewRoman);
- }
- else if( strcmp(g_strLanguage, "CHS") == 0 )
- {
- strcpy(m_logfont.lfFaceName,g_strTimesNewRoman);
- }
- else if( strcmp(g_strLanguage, "CHT") == 0 )
- {
- strcpy(m_logfont.lfFaceName,g_strFontNameCHT);
- }
-
- m_bVertiSize = FALSE;
- m_bHorizSize = FALSE;
- m_bHorizPos = FALSE;
- m_bVertiPos = FALSE;
- m_bShow = TRUE;
- m_bShowtemp = TRUE;
- m_bDynShow = FALSE;
- m_nHorAlign = 0;
- m_nVerAlign = 0;
- m_clrDynBack = RGB(255, 0, 0);
- m_strDynBackCon = "";
- m_clrDynLine = RGB(0, 255, 0);
- m_strDynLineCon = "";
- m_fCurrentValue = 0.0;
- m_bDynFore = FALSE;
- m_bDynBack = FALSE;
- m_bDynLine = FALSE;
- m_bOnButtonDown = false;
- m_bOnButtonUp = false;
- m_bOnMove = false;
- m_nFillMode = 0;
- m_rctCurrent = m_rect;
- m_bHisFreshed = false;
- m_bModifyMore = FALSE;
- m_bFlag1=true;
- m_bFlag2=true;
- m_bFlag3=true;
- }
- void CDrawObj::RegisterClass(CString strName,CRuntimeClass* pRuntimeClass)
- {
- if (pRuntimeClass->IsDerivedFrom(RUNTIME_CLASS(CDrawObj)))
- {
- int nSize = drawsName.GetSize();
- for (int i = 0; i < nSize; i++)
- {
- if ((strName == drawsName[i]) || (pRuntimeClass == drawsRuntimeClass[i]))
- {
- break;
- }
- }
- if (i == nSize)
- {
- drawsName.Add(strName);
- drawsRuntimeClass.Add(pRuntimeClass);
- }
- }
- }
- CDrawObj& CDrawObj::operator=(CDrawObj& drawObj)
- {
- m_rect = drawObj.m_rect;
- m_pView = drawObj.m_pView;
- m_strLineType = drawObj.m_strLineType;
- m_clrLine = drawObj.m_clrLine;
- m_clrFore = drawObj.m_clrFore;
- m_clrBack = drawObj.m_clrBack;
- m_clrLine = drawObj.m_clrLine;
- m_strCaption =drawObj.m_strCaption;
- m_logfont = drawObj.m_logfont;
- m_nLineWidth = drawObj.m_nLineWidth;
- m_bVariant = drawObj.m_bVariant;
- m_bDynShow = drawObj.m_bDynShow;
- m_strDynShow = drawObj.m_strDynShow;
- m_clrDynFore = drawObj.m_clrDynFore;
- m_strDynForeCon = drawObj.m_strDynForeCon;
- m_clrDynBack = drawObj.m_clrDynBack;
- m_strDynBackCon = drawObj.m_strDynBackCon;
- m_clrDynLine = drawObj.m_clrDynLine;
- m_strDynLineCon = drawObj.m_strDynLineCon;
- m_bDynFore = drawObj.m_bDynFore;
- m_bDynBack= drawObj.m_bDynBack;
- m_bDynLine= drawObj.m_bDynLine;
- m_strHoriPos = drawObj.m_strHoriPos;
- m_strHoriSize =drawObj.m_strHoriSize;
- m_strVertiPos =drawObj.m_strVertiPos;
- m_strVertiSize =drawObj.m_strVertiSize;
- m_bVertiSize= drawObj.m_bVertiSize;
- m_bVertiPos =drawObj.m_bVertiPos;
- m_bHorizSize =drawObj.m_bHorizSize;
- m_bHorizPos =drawObj.m_bHorizPos;
- m_downAction = drawObj.m_downAction;
- m_bOnButtonDown = drawObj.m_bOnButtonDown;
- return *this;
- }
- bool CDrawObj::Fresh(CRect &RECT)
- {
- // 取字符串;
- if ( m_bVariant )
- {
- int nValue = (int)pVariantsManager->GetAnalogValue(m_strCaption);
- if( nValue == -1 ) return false;
- m_fCurrentValue = pVariantsManager->GetAnalogValue(m_strCaption);
- int tmp = (int)m_fCurrentValue;
- m_strCurrentCaption.Format("%d", tmp);
- }
- else
- {
- m_strCurrentCaption = m_strCaption;
- }
- m_rctCurrent = m_rect;
- // 计算当前大小
- if (m_bVertiSize)
- {
- CRealComputer com;
- com.SetFormula(m_strVertiSize);
- int tmp = com.GetResult();
- int height = m_rctCurrent.Height();
- CRect rect = m_rctCurrent;
- rect.NormalizeRect();
- if ( m_nVerAlign )
- {
- if (rect.top != m_rctCurrent.top )
- {
- m_rctCurrent.bottom -= tmp-height;
- }
- else
- {
- m_rctCurrent.top -= tmp-height;
- }
- }
- else
- {
- if (rect.top != m_rctCurrent.top )
- {
- m_rctCurrent.top += tmp-height;
- }
- else
- {
- m_rctCurrent.bottom += tmp-height;
- }
- }
- }
- //if (m_bHorizSize) modify by chn 2012.02.06
- //{
- // CRealComputer com;
- // com.SetFormula(m_strHoriSize);
- // int tmp = com.GetResult();
- // int width = m_rctCurrent.Width();
- // CRect rect = m_rctCurrent;
- // rect.NormalizeRect();
- // if ( m_nHorAlign )
- // {
- // if (rect.right != m_rctCurrent.right )
- // {
- // m_rctCurrent.right -= tmp-width;
- // }
- // else
- // {
- // m_rctCurrent.left -= tmp-width;
- // }
- // }
- // else
- // {
- // if (rect.right != m_rctCurrent.right )
- // {
- // m_rctCurrent.left += tmp-width;
- // }
- // else
- // {
- // m_rctCurrent.right += tmp-width;
- // }
- // }
- //}
- // 计算当前位置
- if (m_bVertiPos)
- {
- CRealComputer com;
- com.SetFormula(m_strVertiPos);
- int tmp = com.GetResult();
- int yPos = ((CPoint)m_rctCurrent.TopLeft()).y;
- m_rctCurrent.OffsetRect(0, tmp - yPos);
- }
- if (m_bHorizPos)
- {
- CRealComputer com;
- com.SetFormula(m_strHoriPos);
- int tmp = com.GetResult();
- int xPos = ((CPoint)m_rctCurrent.TopLeft()).x;
- m_rctCurrent.OffsetRect(tmp - xPos, 0);
- }
- m_clrCurrentFore = m_clrFore;
- m_clrCurrentBack = m_clrBack;
- m_clrCurrentLine = m_clrLine;
- // 计算当前的动态颜色;
- if (m_bDynFore==1)
- {
- CRealComputer com;
- com.SetFormula(m_strDynForeCon);
- int tmp = com.GetResult();
- if (tmp)
- {
- if( !m_bHorizSize )
- m_clrCurrentFore = m_clrDynFore;
- else
- {
- if( m_bFlag1 )
- m_clrCurrentFore = m_clrDynFore;
- else
- {
- //m_clrCurrentBack = RGB( 230, 241, 249 );
- //m_clrCurrentLine = RGB( 230, 241, 249 );
- m_clrCurrentFore = RGB( 230, 241, 249 );
- }
-
- m_bFlag1 = !m_bFlag1;
- }
- }
- }
- if (m_bDynBack==1)
- {
- CRealComputer com;
- com.SetFormula(m_strDynBackCon);
- int tmp = com.GetResult();
- //if( -1 != m_strDynBackCon.Find("WTH10_1_Temp_1") )
- //{
- // int a=0;
- //}
- if (tmp)
- {
- if( !m_bHorizSize )
- m_clrCurrentBack = m_clrDynBack;
- else
- {
- if( m_bFlag2 )
- m_clrCurrentBack = m_clrDynBack;
- else
- {
- m_clrCurrentBack = RGB( 230, 241, 249 );
- m_clrCurrentLine = RGB( 230, 241, 249 );
- m_clrCurrentFore = RGB( 230, 241, 249 );
- }
-
- m_bFlag2 = !m_bFlag2;
- }
- }
- }
- if (m_bDynLine==1)
- {
- CRealComputer com;
- com.SetFormula(m_strDynLineCon);
- int tmp = com.GetResult();
- if (tmp)
- {
- if( !m_bHorizSize )
- m_clrCurrentLine = m_clrDynLine;
- else
- {
- if( m_bFlag3 )
- m_clrCurrentLine = m_clrDynLine;
- else
- {
- //m_clrCurrentBack = RGB( 230, 241, 249 );
- m_clrCurrentLine = RGB( 230, 241, 249 );
- //m_clrCurrentFore = RGB( 230, 241, 249 );
- }
-
- m_bFlag3 = !m_bFlag3;
- }
- }
- }
- // 判断是否显示;
- //if( m_strDynShow!="" && m_bDynShow==0 ) LOG4C((LOG_NOTICE, "m_strDynShow=< %s >,m_bDynShow = %d",m_strDynShow,m_bDynShow));
- if ( m_bDynShow==1)
- {
- CRealComputer com;
- com.SetFormula(m_strDynShow);
- m_bShow = (int)com.GetResult();
- ////测试用
- //if( -1 != m_strDynShow.Find("Caross_1_StartORShutStatus") )
- //{
- // if( m_bShow==0 )
- // m_bShow = 1;
- // else
- // m_bShow = 0;
- //}
- //if( -1 != m_strDynShow.Find("Caross_2_StartORShutStatus") )
- //{
- // if( m_bShow==0 )
- // m_bShow = 1;
- // else
- // m_bShow = 0;
- //}
- }
- RECT = m_rect;
- return true;
- }
- CDrawObj* CDrawObj::Clone(void)
- {
- CDrawObj *pObj = new CDrawObj;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_strLineType = m_strLineType;
- pObj->m_clrLine = m_clrLine;
- pObj->m_clrFore = m_clrFore;
- pObj->m_clrBack = m_clrBack;
- pObj->m_clrLine = m_clrLine;
- pObj->m_strCaption = m_strCaption;
- pObj->m_logfont = m_logfont;
- pObj->m_nLineWidth =m_nLineWidth ;
- pObj->m_bVariant =m_bVariant ;
- pObj->m_bDynShow =m_bDynShow ;
- pObj->m_strDynShow =m_strDynShow ;
- pObj->m_clrDynFore =m_clrDynFore ;
- pObj->m_strDynForeCon =m_strDynForeCon ;
- pObj->m_clrDynBack =m_clrDynBack ;
- pObj->m_strDynBackCon =m_strDynBackCon ;
- pObj->m_clrDynLine =m_clrDynLine ;
- pObj->m_strDynLineCon =m_strDynLineCon ;
- pObj->m_bDynFore =m_bDynFore ;
- pObj->m_bDynBack =m_bDynBack ;
- pObj->m_bDynLine =m_bDynLine ;
- pObj->m_strHoriPos =m_strHoriPos ;
- pObj->m_strHoriSize =m_strHoriSize ;
- pObj->m_strVertiPos =m_strVertiPos ;
- pObj->m_strVertiSize =m_strVertiSize ;
- pObj->m_bVertiSize =m_bVertiSize ;
- pObj->m_bVertiPos = m_bVertiPos;
- pObj->m_bHorizSize = m_bHorizSize;
- pObj->m_bHorizPos = m_bHorizPos;
- pObj->m_downAction = m_downAction;
- pObj->m_upAction = m_upAction;
- pObj->m_moveAction = m_moveAction;
- pObj->m_bOnButtonUp = m_bOnButtonUp;
- pObj->m_bOnButtonDown = m_bOnButtonDown;
- pObj->m_bOnMove = m_bOnMove;
- return pObj;
- }
- void CDrawObj::Serialize(CArchive& ar)
- {
- CObject::Serialize(ar);
-
- if(ar.IsStoring())
- {
- ar << m_rect;
- ar << m_clrFore; // 前景色
- ar << m_clrLine; // 线色
- ar << m_clrBack; // 背景色
- ar << m_clrFill; // 填充色
- ar << m_nLineWidth;
- ar << m_strLineType;
- ar << m_strCaption;
- ar << m_bVariant;
-
- ar << m_clrDynFore;
- ar << m_strDynForeCon;
- ar << m_bDynFore;
- ar << m_clrDynBack;
- ar << m_strDynBackCon;
- ar << m_clrDynLine;
- ar << m_strDynLineCon;
- ar << m_bDynBack;
- ar << m_bDynLine;
- ar << m_bDynShow;
- ar << m_strDynShow;
- //if( m_strDynShow!="" ) LOG4C((LOG_NOTICE, "m_strDynShow=< %s >,m_bDynShow = %d",m_strDynShow,m_bDynShow));
- ar << m_strHoriPos;
- ar << m_strHoriSize;
- ar << m_strVertiPos;
- ar << m_strVertiSize;
- ar << m_bVertiSize;
- ar << m_bVertiPos;
- ar << m_bHorizSize;
- ar << m_bHorizPos;
- ar << m_bOnButtonUp;
- ar << m_bOnButtonDown;
- ar << m_bOnMove;
- ar << m_nHorAlign;
- ar << m_nVerAlign;
- ar << m_nFillMode;
- ar.Write(&m_logfont,sizeof(LOGFONT));
- }
- else
- {
- ar >> m_rect;
- ar >> m_clrFore; // 前景色
- ar >> m_clrLine; // 线色
- ar >> m_clrBack; // 背景色
- ar >> m_clrFill; // 填充色
- ar >> m_nLineWidth;
- ar >> m_strLineType;
- ar >> m_strCaption;
- ar >> m_bVariant;
- ar >> m_clrDynFore;
- ar >> m_strDynForeCon;
- ar >> m_bDynFore;
- ar >> m_clrDynBack;
- ar >> m_strDynBackCon;
- ar >> m_clrDynLine;
- ar >> m_strDynLineCon;
- ar >> m_bDynBack;
- ar >> m_bDynLine;
- ar >> m_bDynShow;
- ar >> m_strDynShow;
- //if( m_strDynShow!="" ) LOG4C((LOG_NOTICE, "m_strDynShow=< %s >,m_bDynShow = %d",m_strDynShow,m_bDynShow));
- ar >> m_strHoriPos;
- ar >> m_strHoriSize;
- ar >> m_strVertiPos;
- ar >> m_strVertiSize;
- ar >> m_bVertiSize;
- ar >> m_bVertiPos;
- ar >> m_bHorizSize;
- ar >> m_bHorizPos;
- ar >> m_bOnButtonUp;
- ar >> m_bOnButtonDown;
- ar >> m_bOnMove;
- ar >> m_nHorAlign;
- ar >> m_nVerAlign;
- ar >> m_nFillMode;
- ar.Read(&m_logfont,sizeof(LOGFONT));
- m_rctCurrent = m_rect;
- }
- m_downAction.Serialize(ar);
- m_upAction.Serialize(ar);
- m_moveAction.Serialize(ar);
- m_clrCurrentLine = m_clrLine;
- m_clrCurrentFore = m_clrFore;
- m_clrCurrentBack = m_clrBack;
- }
- BOOL CDrawObj::OnAttrib(void)
- {
- CPropertySheet sheet;
- CBaseProDlg pageBase;
- pageBase.m_clrBack = m_clrBack;
- pageBase.m_clrFore = m_clrFore;
- pageBase.m_clrLine = m_clrLine;
- pageBase.m_clrFill = m_clrFill;
- pageBase.m_logfont = m_logfont;
- pageBase.m_strCaption =m_strCaption;
- pageBase.m_strLineWidth.Format("%d", m_nLineWidth);
- pageBase.m_strLineType = m_strLineType;
- pageBase.m_bDynShow = m_bDynShow;
- pageBase.m_strShowCondition = m_strDynShow;
- pageBase.m_bVariant = m_bVariant;
- pageBase.m_nFillMode = m_nFillMode;
- sheet.AddPage(&pageBase);
- // 编辑多个
- if( m_bModifyMore )
- {
- //CDataPage page;
- //page.m_nFormat = 1;
- //sheet.AddPage(&page);
- pageBase.m_bMoreEdit = true;
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_clrBack = pageBase.m_clrBack;
- m_clrFore = pageBase.m_clrFore;
- m_clrLine = pageBase.m_clrLine;
- m_clrFill = pageBase.m_clrFill;
- m_logfont = pageBase.m_logfont;
- m_nLineWidth = atoi(pageBase.m_strLineWidth);
- m_strLineType = pageBase.m_strLineType;
- m_nFillMode = pageBase.m_nFillMode;
- for (int i=0; i<(int)pageBase.m_vtbitmapList.size(); i++)
- {
- delete pageBase.m_vtbitmapList[i];
- }
- return TRUE;
- }
- for (int i=0; i<(int)pageBase.m_vtbitmapList.size(); i++)
- {
- delete pageBase.m_vtbitmapList[i];
- }
- return FALSE;
- }
- CDynamicProPage pageDynamic;
- pageDynamic.m_clrForeColor = m_clrDynFore;
- pageDynamic.m_strForeColorCondition = m_strDynForeCon;
- pageDynamic.m_bForeColor = m_bDynFore;
- pageDynamic.m_strHoriPos = m_strHoriPos;
- pageDynamic.m_strHoriSize = m_strHoriSize;
- pageDynamic.m_strVertiPos = m_strVertiPos;
- pageDynamic.m_strVertiSize = m_strVertiSize;
- pageDynamic.m_bVertiSize = m_bVertiSize;
- pageDynamic.m_bVertiPos = m_bVertiPos;
- pageDynamic.m_bHorizSize = m_bHorizSize;
- pageDynamic.m_bHorizPos = m_bHorizPos;
- pageDynamic.m_bBackColor = m_bDynBack;
- pageDynamic.m_bLineColor = m_bDynLine;
- pageDynamic.m_clrBackColor = m_clrDynBack;
- pageDynamic.m_clrLineColor = m_clrDynLine;
- pageDynamic.m_strBackColorCondition = m_strDynBackCon;
- pageDynamic.m_strFLineColorCondition = m_strDynLineCon;
- pageDynamic.m_downAction = m_downAction;
- pageDynamic.m_upAction = m_upAction;
- pageDynamic.m_moveAction =m_moveAction;
- pageDynamic.m_bOnButtonUp = m_bOnButtonUp;
- pageDynamic.m_bOnButtonDown = m_bOnButtonDown;
- //pageDynamic.m_bOnMove = m_bOnMove;
- pageDynamic.m_nHorAlign = m_nHorAlign;
- pageDynamic.m_nVerAlign = m_nVerAlign;
- sheet.AddPage(&pageDynamic);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( OnAttrib(sheet) )
- {
- m_clrBack = pageBase.m_clrBack;
- m_clrFore = pageBase.m_clrFore;
- m_clrLine = pageBase.m_clrLine;
- m_clrFill = pageBase.m_clrFill;
- m_logfont = pageBase.m_logfont;
- m_strCaption = pageBase.m_strCaption;
- m_nLineWidth = atoi(pageBase.m_strLineWidth);
- m_strLineType = pageBase.m_strLineType;
- m_bDynShow = pageBase.m_bDynShow;
- m_strDynShow = pageBase.m_strShowCondition;
- m_bVariant = pageBase.m_bVariant;
- m_nFillMode = pageBase.m_nFillMode;
- m_clrDynFore = pageDynamic.m_clrForeColor;
- m_strDynForeCon = pageDynamic.m_strForeColorCondition;
- m_bDynBack = pageDynamic.m_bBackColor;
- m_bDynLine = pageDynamic.m_bLineColor;
- m_clrDynBack = pageDynamic.m_clrBackColor;
- m_clrDynLine = pageDynamic.m_clrLineColor;
- m_strDynBackCon = pageDynamic.m_strBackColorCondition;
- m_strDynLineCon = pageDynamic.m_strFLineColorCondition;
- m_bDynFore = pageDynamic.m_bForeColor;
- m_strHoriPos = pageDynamic.m_strHoriPos;
- m_strHoriSize = pageDynamic.m_strHoriSize;
- m_strVertiPos = pageDynamic.m_strVertiPos;
- m_strVertiSize = pageDynamic.m_strVertiSize;
- m_bVertiSize = pageDynamic.m_bVertiSize;
- m_bVertiPos = pageDynamic.m_bVertiPos;
- m_bHorizSize = pageDynamic.m_bHorizSize;
- m_bHorizPos = pageDynamic.m_bHorizPos;
- m_downAction = pageDynamic.m_downAction;
- m_upAction = pageDynamic.m_upAction;
- m_moveAction = pageDynamic.m_moveAction;
- m_bOnButtonUp = pageDynamic.m_bOnButtonUp;
- m_bOnButtonDown = pageDynamic.m_bOnButtonDown;
- //m_bOnMove = pageDynamic.m_bOnMove;
- m_nHorAlign = pageDynamic.m_nHorAlign;
- m_nVerAlign = pageDynamic.m_nVerAlign;
- for (int i=0; i<(int)pageBase.m_vtbitmapList.size(); i++)
- {
- //m_vtbitmapList.pop_back();
- delete pageBase.m_vtbitmapList[i];
- }
- Invalidate();
- return TRUE;
- }
- for (int i=0; i<(int)pageBase.m_vtbitmapList.size(); i++)
- {
- //m_vtbitmapList.pop_back();
- delete pageBase.m_vtbitmapList[i];
- }
- return FALSE;
- }
- BOOL CDrawObj::OnAttrib(CPropertySheet& sheet)
- {
- CString strName;
- int nSize = drawsRuntimeClass.GetSize();
- for(int i=0;i<nSize;i++)
- {
- CRuntimeClass* pRuntimeClass = (CRuntimeClass*)drawsRuntimeClass[i];
- if(IsKindOf(pRuntimeClass))
- {
- strName = drawsName[i];
- break;
- }
- }
- if(i==nSize) return FALSE;
- sheet.Construct(g_strParamSet);
- if( sheet.DoModal()==IDOK )
- {
- return TRUE;
- }
- return FALSE;
- }
- void CDrawObj::Draw(CDC* pDC)
- {
- if ( !g_bRun )
- {
- m_clrCurrentLine = m_clrLine;
- m_clrCurrentFore = m_clrFore;
- m_clrCurrentBack = m_clrBack;
- }
- }
- void CDrawObj::DrawText(CDC* pDC)
- {
- COLORREF clrFore = m_clrFore;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrFore = m_clrCurrentFore;
- rect = m_rctCurrent;
- }
- pDC->SetTextColor(clrFore);
- pDC->SetTextAlign(TA_CENTER|TA_TOP);
- CFont font;
- font.CreateFontIndirect(&m_logfont);
- CFont* pOldFont = pDC->SelectObject(&font);
- int height = abs(m_logfont.lfHeight);
- rect.NormalizeRect();
- int nX0 = (rect.left+rect.right) / 2;
- int nY0 = (rect.top+rect.bottom) / 2;
- if(rect.Width()>=rect.Height())
- {
- pDC->TextOut(nX0, nY0-height/2, m_strCaption);
- }
- else
- {
- int xt = nX0;
- int yt = nY0;
- int Length = m_strCaption.GetLength();
- const char *p = (const char*)m_strCaption;
- int ystart = yt;
- for(int i=0;i<Length;i++)
- {
- ystart -= height / 2;
- if(*(p+i)<0) i++;
- }
- for(i=0;i<Length;i++)
- {
- if(*(p+i)<0)
- {
- pDC->TextOut(xt,ystart,p+i,2);
- i++;
- }
- else pDC->TextOut(xt,ystart,p+i,1);
- ystart += height;
- }
- }
- pDC->SelectObject(pOldFont);
- DeleteObject( font );
- }
- void CDrawObj::Layout(BYTE Sharp,LAYOUTSTRUCT* pLayout)
- {
- ASSERT(Sharp>0);
- pLayout->rect = m_rect;
- pLayout->rect.NormalizeRect();
- pLayout->nX1 = pLayout->rect.left;
- pLayout->nX2 = pLayout->rect.right;
- pLayout->nY1 = pLayout->rect.top;
- pLayout->nY2 = pLayout->rect.bottom;
- pLayout->nXX = pLayout->nX2 - pLayout->nX1;
- pLayout->nYY = pLayout->nY2 - pLayout->nY1;
- pLayout->nX0 = (pLayout->nX1+pLayout->nX2) / 2;
- pLayout->nY0 = (pLayout->nY1+pLayout->nY2) / 2;
- pLayout->bXInvert = m_rect.left > m_rect.right;
- pLayout->bYInvert = m_rect.top > m_rect.bottom;
- if(pLayout->nXX >= pLayout->nYY)
- {
- pLayout->bHoriz = TRUE;
- pLayout->nMinSize = min(pLayout->nXX/Sharp, pLayout->nYY);
- }
- else
- {
- pLayout->bHoriz = FALSE;
- pLayout->nMinSize = min(pLayout->nXX, pLayout->nYY/Sharp);
- }
- }
- int CDrawObj::GetHandleCount(void)
- {
- return 8;
- }
- CPoint CDrawObj::GetHandle(int nHandle)
- {
- int x, y, xCenter, yCenter;
- xCenter = m_rect.left + m_rect.Width() / 2;
- yCenter = m_rect.top + m_rect.Height() / 2;
- switch (nHandle)
- {
- case 1: x = m_rect.left; y = m_rect.top; break;
- case 2: x = xCenter; y = m_rect.top; break;
- case 3: x = m_rect.right; y = m_rect.top; break;
- case 4: x = m_rect.right; y = yCenter; break;
- case 5: x = m_rect.right; y = m_rect.bottom; break;
- case 6: x = xCenter; y = m_rect.bottom; break;
- case 7: x = m_rect.left; y = m_rect.bottom; break;
- case 8: x = m_rect.left; y = yCenter; break;
- }
- return CPoint(x, y);
- }
- CRect CDrawObj::GetHandleRect(int nHandle)
- {
- CRect rect;
- CPoint point = GetHandle(nHandle);
- rect.SetRect(point.x-3, point.y-3, point.x+3, point.y+3);
- return rect;
- }
- HCURSOR CDrawObj::GetHandleCursor()
- {
- return AfxGetApp()->LoadCursor (IDC_CURSOR2);
- }
- void CDrawObj::MoveTo(CRect rect)
- {
- if(rect==m_rect) return;
- Invalidate();
- m_rect = rect;
- Invalidate();
- }
- void CDrawObj::MoveHandleTo(int nHandle, CPoint point)
- {
- CRect rect = m_rect;
- switch (nHandle)
- {
- case 1: rect.left = point.x; rect.top = point.y; break;
- case 2: rect.top = point.y; break;
- case 3: rect.right = point.x; rect.top = point.y; break;
- case 4: rect.right = point.x; break;
- case 5: rect.right = point.x; rect.bottom = point.y; break;
- case 6: rect.bottom = point.y; break;
- case 7: rect.left = point.x; rect.bottom = point.y; break;
- case 8: rect.left = point.x; break;
- }
- MoveTo(rect);
- }
- void CDrawObj::DrawTracker(CDC* pDC)
- {
- int nHandleCount = GetHandleCount();
- for (int nHandle = 1; nHandle <= nHandleCount; nHandle ++)
- {
- CPoint handle = GetHandle(nHandle);
- pDC->PatBlt(handle.x - 3, handle.y - 3, 7, 7, DSTINVERT);
- }
- }
- int CDrawObj::HitTest(CPoint point)
- {
- int nHandleCount = GetHandleCount();
- for (int nHandle = 1; nHandle <= nHandleCount; nHandle ++)
- {
- CRect rc = GetHandleRect(nHandle);
- if(rc.PtInRect(point)) return nHandle;
- }
- return 0;
- }
- BOOL CDrawObj::Intersects(CRect rect)
- {
- CRect fixed = m_rect;
- fixed.NormalizeRect();
- CRect rectT = rect;
- rectT.NormalizeRect();
- return !(rectT & fixed).IsRectEmpty();
- }
- void CDrawObj::Invalidate(void)
- {
- CRect rect = m_rect;
- rect.NormalizeRect();
- rect.InflateRect(5,5,5,5);
- CClientDC dc(m_pView);
- m_pView->OnPrepareDC(&dc);
- dc.LPtoDP(&rect);
- m_pView->InvalidateRect(rect,FALSE);
- }
- int CDrawObj::GetPenStyle(CString penType)
- {
- if (penType == "PS_SOLID")
- {
- return PS_SOLID;
- }
- else if (penType == "PS_DASH")
- {
- return PS_DASH;
- }
- else if (penType == "PS_DOT")
- {
- return PS_DOT;
- }
- else if (penType == "PS_DASHDOT")
- {
- return PS_DASHDOT;
- }
- else if (penType == "PS_DASHDOTDOT")
- {
- return PS_DASHDOTDOT;
- }
- else if (penType == "PS_NULL")
- {
- return PS_NULL;
- }
- return PS_SOLID;
- }
- // 控制类型:
- // 遥控:控分;控合;取反
- // 遥设:设定;固定;动态输入
- // 增减;固定;动态
- void CDrawObj::ProcessAction(int type)
- {
- CAction action;
- switch (type)
- {
- case MOUSE_CLICK_DOWN:
- action = m_downAction; break;
- case MOUSE_CLICK_UP:
- action = m_upAction; break;
- case MOUSE_MOVE:
- action = m_moveAction; break;
- };
- // exit
- if (action.m_nActionType == EXIT_COMMOND)
- {
- CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->OnSuperEnd();
- return;
- }
- // link
- else if (action.m_nActionType == LINK_COMMOND)
- {
- char picDir[_MAX_PATH] = {0};
- strcpy(picDir, g_strDirectory);
- strcat(picDir, "\\");
- strcat(picDir, _PICTUREDIR);
- strcat(picDir, action.m_strVariant);
- strcat(picDir, ".view");
- //CString str;
- //str = action.m_strPicPath + ".view";
- CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->AddIDEView(action.m_strVariant, picDir);
- return;
- }
- // extern link
- else if( action.m_nActionType == EXTERN_COMMOND )
- {
- ShellExecute(0, "open", action.m_strActionValue, NULL, NULL, SW_SHOWNORMAL);
- }
- // 测试报警
- else if( action.m_nActionType == TEST_ALARM )
- {
- pDevicesManager->TestAlarm( "64320" );
- }
- // 报警记录
- else if( action.m_nActionType == ALARM_RECORD )
- {
- CDlgQueryWarningRec dlg;
- if( dlg.DoModal() == IDOK )
- {
- }
- }
- // 通知记录
- else if( action.m_nActionType == NOTICE_RECORD )
- {
- CDlgNoticeRec dlg;
- dlg.DoModal();
- }
- // 设备日志
- else if( action.m_nActionType == DEVICE_LOG )
- {
- CString strFileName;
- //strFileName.Format("%s\\Query.exe", g_strDirectory);
- //ShellExecute(0, "open", strFileName, NULL, NULL, SW_SHOWNORMAL);
- }
- // 系统日志
- else if( action.m_nActionType == SYSTEM_LOG )
- {
- CDlgSystemLog dlg;
- dlg.DoModal();
- }
- // 变量管理
- else if( action.m_nActionType == VAR_MANAGE )
- {
- CAnalogDlg dlg;
- dlg.DoModal();
- }
- // 用户管理
- else if( action.m_nActionType == USER_MANAGE )
- {
- CDlgUserManager dlg;
- if( dlg.DoModal() == IDOK )
- {
- }
- }
- // 修改密码
- else if( action.m_nActionType == PWD_MANAGE )
- {
- CDlgEditPwd dlg;
- if( dlg.DoModal() == IDOK )
- {
- CString sContent;
- sContent.Format("%s%s",g_strEdit,g_strPwd );
- CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_PWD_EDIT,0,"",(char *)(LPCTSTR)sContent );
- }
- }
- // 首页设置
- else if( action.m_nActionType == FIRST_PAGE )
- {
- CSystemParaSetDlg dlg;
- dlg.m_bStartRun = g_bStartRun;
- dlg.m_bAlarmVoice = g_bAlarmVoice;
- dlg.m_bEventAlarm = g_bEventAlarm;
- dlg.m_bHideTask = g_bHideTask;
- dlg.m_strStartPic = g_strStartPic;
- dlg.m_strStartPath = g_strStartPath;
- if ( dlg.DoModal() == IDOK )
- {
- #if 0 //程序退出之前不改变状态
- g_bStartRun = dlg.m_bStartRun;
- #endif
- //int nPos = dlg.m_strStartPath.Find("\\\\");
- //if( nPos!=-1 )
- //{
- // dlg.m_strStartPath.Delete( nPos );
- //}
- //
- //int nLen = dlg.m_strStartPath.GetLength();
- //nPos = dlg.m_strStartPath.Find("view");
- //CString sTemp;
- //if( nPos<nLen-7 )
- // sTemp = dlg.m_strStartPath.Right( nLen-nPos-7 );
- //if( sTemp!="" )
- // g_strStartPic = sTemp+"\\"+dlg.m_strStartPic;
- //else
- g_strStartPic = dlg.m_strStartPic;
- g_strStartPath = dlg.m_strStartPath;
- g_bEventAlarm = dlg.m_bEventAlarm;
- g_bAlarmVoice = dlg.m_bAlarmVoice;
- g_bHideTask = dlg.m_bHideTask;
- g_pMainFrm->StoreRunPara(dlg.m_bStartRun);
- }
- }
- // 导航树
- else if( action.m_nActionType == NAVIGATION_TREE )
- {
- g_pMainFrm->m_wndDockPageBar1.ShowWindow(SW_SHOW);
- SendMessage( g_pMainFrm->m_wndDockPageBar1,WM_MY_INVALIDATE,0,0 );
- }
- // set yt SET_COMMOND为设置 YT_COMMOND为调节
- if ((action.m_nActionType == SET_COMMOND) || (action.m_nActionType == YT_COMMOND))
- {
- if( g_bHaveControlPwd )
- {
- CDlg_Pwd Dlg_Pwd;
- Dlg_Pwd.m_nShowType = 1;
- if( Dlg_Pwd.DoModal()!=IDOK )
- return;
- }
- if (m_downAction.m_strActionValue == "")
- {
- CDataInputDlg dlg;
- dlg.m_strVarName = action.m_strVariant;
- if ( dlg.DoModal() == IDOK )
- {
- action.m_strActionValue = dlg.m_strData;
- }
- else
- {
- return;
- }
- }
- else
- {
- MessageBox( NULL,"命令已经发送","提示",MB_OK );
- }
- }
- // yk 控制
- if (action.m_nActionType == YK_COMMOND)
- {
- if( g_bHaveControlPwd )
- {
- CDlg_Pwd Dlg_Pwd;
- Dlg_Pwd.m_nShowType = 1;
- if( Dlg_Pwd.DoModal()!=IDOK )
- return;
- }
- CYkCmdDlg dlg;
- if( m_downAction.m_strActionValue == "" )
- dlg.m_strValue = "1-0";
- else
- dlg.m_strValue = m_downAction.m_strActionValue;
-
- if (dlg.DoModal() == IDOK)
- {
- action.m_strActionValue = dlg.m_strValue;
- }
- else
- {
- return;
- }
- }
- CCommondServer server;
- server.PushCommondToDevice(&action);
- }
- void CDrawObj::DrawFrame(CDC *pDC)
- {
- CRect rect = m_rect;
- rect.NormalizeRect();
- CRect rectLeft = CRect(rect.left-4, rect.top-4, rect.left, rect.bottom);
- CRect rectBottom = CRect(rect.left-4, rect.bottom, rect.right, rect.bottom+4);
- CRect rectRight = CRect(rect.right, rect.top, rect.right+4, rect.bottom+4);
- CRect rectTop = CRect(rect.left, rect.top-4, rect.right+4, rect.top);
- pDC->FillSolidRect(rectLeft, RGB(0,0,255));
- pDC->FillSolidRect(rectBottom, RGB(0,0,255));
- pDC->FillSolidRect(rectRight, RGB(0,0,255));
- pDC->FillSolidRect(rectTop, RGB(0,0,255));
- }
- void CDrawObj::DrawVKedu(CDC* pDC, CRect rect, int nKedu, COLORREF clrKedu)
- {
- CPen pen(PS_SOLID,1,clrKedu);
- CPen *pOldPen = pDC->SelectObject(&pen);
- pDC->MoveTo(rect.TopLeft());
- pDC->LineTo(rect.left, rect.bottom);
- //for(int i=0;i<=nKedu;i++)
- //{
- // int nY = rect.top + i*(rect.Height()*1.0/nKedu);
- // if (i == nKedu )
- // nY = rect.bottom;
- // pDC->MoveTo(rect.left, nY);
- // pDC->LineTo(rect.right, nY);
- //}
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- }
- void CDrawObj::DrawHKedu(CDC* pDC, CRect rect, int nKedu, COLORREF clrKedu)
- {
- CPen pen(PS_SOLID,1,clrKedu);
- CPen *pOldPen = pDC->SelectObject(&pen);
- pDC->MoveTo(rect.right, rect.bottom);
- pDC->LineTo(rect.left, rect.bottom);
- for(int i=0;i<=nKedu;i++)
- {
- int nX = rect.left + i*(rect.Width()*1.0/nKedu);
- pDC->MoveTo(nX, rect.top);
- pDC->LineTo(nX, rect.bottom);
- }
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- }
- void CDrawObj::DrawArcKedu(CDC* pDC, CRect rect, int nStartAngle, int nEndAngle, int nKedu, COLORREF clrKedu)
- {
- CPen pen(PS_SOLID,1,clrKedu);
- CPen *pOldPen = pDC->SelectObject(&pen);
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- }
- LOGBRUSH CDrawObj::GetBrush()
- {
- LOGBRUSH brushlog;
- brushlog.lbColor = m_clrCurrentBack;
- if ( m_nFillMode == 0 )
- brushlog.lbStyle = BS_NULL;
- else if ( m_nFillMode == 1 )
- brushlog.lbStyle = BS_SOLID;
- else if ( m_nFillMode < 8 )
- {
- brushlog.lbStyle = BS_HATCHED;
- brushlog.lbHatch = m_nFillMode - 2;
- }
- else
- brushlog.lbStyle = BS_SOLID;
- return brushlog;
- }
- //---------------------------------------------- CDrawComposite ---
- IMPLEMENT_SERIAL(CDrawComposite, CDrawObj, 0)
- CDrawComposite::CDrawComposite():CDrawObj()
- {
- }
- CDrawComposite::CDrawComposite(CDrawObjList &ObjList):CDrawObj()
- {
- m_ObjList.RemoveAll();
- POSITION pos = ObjList.GetHeadPosition();
- bool bFirst = true;
- while(pos != NULL)
- {
- CDrawObj *pObj = ObjList.GetNext(pos);
- CDrawObj *pNewObj = pObj->Clone();
- m_ObjList.AddTail(pNewObj);
- if (bFirst)
- {
- m_rect = pNewObj->m_rect;
- bFirst = false;
- }
- else
- {
- int nLeft = min(m_rect.left, pNewObj->m_rect.left);
- int nTop = min(m_rect.top, pNewObj->m_rect.top);
- int nBottom = max(m_rect.bottom, pNewObj->m_rect.bottom);
- int nRight = max(m_rect.right, pNewObj->m_rect.right);
- m_rect = CRect(nLeft, nTop, nRight, nBottom);
- }
- }
- pos = m_ObjList.GetHeadPosition();
- while(pos != NULL)
- {
- CDrawObj *pObj = m_ObjList.GetNext(pos);
- pObj->m_dbLeftRate = (pObj->m_rect.left - m_rect.left)*1.0/m_rect.Width();
- pObj->m_dbRightRate = (pObj->m_rect.right - m_rect.left)*1.0/m_rect.Width();
- pObj->m_dbTopRate = (pObj->m_rect.top - m_rect.top)*1.0/m_rect.Height();
- pObj->m_dbBottomRate = (pObj->m_rect.bottom - m_rect.top)*1.0/m_rect.Height();
- }
- }
- CDrawComposite::~CDrawComposite()
- {
- POSITION pos = m_ObjList.GetHeadPosition();
- while(pos!=NULL) delete m_ObjList.GetNext(pos);
- m_ObjList.RemoveAll();
- }
- CDrawComposite& CDrawComposite::operator=(CDrawComposite& drawObj)
- {
- CDrawComposite* pComposite = new CDrawComposite();
- return *pComposite;
- }
- CDrawObj* CDrawComposite::Clone(void)
- {
- CDrawComposite* pComposite = new CDrawComposite();
- *((CDrawObj*)pComposite) = *(CDrawObj*)this;
- pComposite->m_ObjList.RemoveAll();
- POSITION pos = m_ObjList.GetHeadPosition();
- bool bFirst = true;
- while(pos != NULL)
- {
- CDrawObj *pObj = m_ObjList.GetNext(pos);
- CDrawObj *pNewObj = pObj->Clone();
- pComposite->m_ObjList.AddTail(pNewObj);
- if (bFirst)
- {
- pComposite->m_rect = pNewObj->m_rect;
- bFirst = false;
- }
- else
- {
- int nLeft = min(pComposite->m_rect.left, pNewObj->m_rect.left);
- int nTop = min(pComposite->m_rect.top, pNewObj->m_rect.top);
- int nBottom = max(pComposite->m_rect.bottom, pNewObj->m_rect.bottom);
- int nRight = max(pComposite->m_rect.right, pNewObj->m_rect.right);
- pComposite->m_rect = CRect(nLeft, nTop, nRight, nBottom);
- }
- }
- pos = pComposite->m_ObjList.GetHeadPosition();
- while(pos != NULL)
- {
- CDrawObj *pObj = pComposite->m_ObjList.GetNext(pos);
- pObj->m_dbLeftRate = (pObj->m_rect.left - pComposite->m_rect.left)*1.0/pComposite->m_rect.Width();
- pObj->m_dbRightRate = (pObj->m_rect.right - pComposite->m_rect.left)*1.0/pComposite->m_rect.Width();
- pObj->m_dbTopRate = (pObj->m_rect.top - pComposite->m_rect.top)*1.0/pComposite->m_rect.Height();
- pObj->m_dbBottomRate = (pObj->m_rect.bottom - pComposite->m_rect.top)*1.0/pComposite->m_rect.Height();
- }
- return pComposite;
- }
- void CDrawComposite::Serialize(CArchive& ar)
- {
- CDrawObj::Serialize(ar);
- m_ObjList.Serialize(ar);
- POSITION pos = m_ObjList.GetHeadPosition();
- while(pos != NULL)
- {
- CDrawObj *pObj = m_ObjList.GetNext(pos);
- pObj->m_dbLeftRate = (pObj->m_rect.left - m_rect.left)*1.0/m_rect.Width();
- pObj->m_dbRightRate = (pObj->m_rect.right - m_rect.left)*1.0/m_rect.Width();
- pObj->m_dbTopRate = (pObj->m_rect.top - m_rect.top)*1.0/m_rect.Height();
- pObj->m_dbBottomRate = (pObj->m_rect.bottom - m_rect.top)*1.0/m_rect.Height();
- }
- }
- void CDrawComposite::Draw(CDC* pDC)
- {
- POSITION pos = m_ObjList.GetHeadPosition();
- while(pos!=NULL)
- {
- CDrawObj* pObj = m_ObjList.GetNext(pos);
- CRect rect = pObj->m_rect;
- rect.NormalizeRect();
- rect.InflateRect(5,5,5,5);
- if (rect.IntersectRect(&rect,&m_rect))
- {
- pObj->Draw(pDC);
- }
- }
- }
- void CDrawComposite::MoveTo(CRect rect)
- {
- if (rect == m_rect)
- {
- return;
- }
- POSITION pos = m_ObjList.GetHeadPosition();
- while (pos != NULL)
- {
- CDrawObj* pObj = m_ObjList.GetNext(pos);
- pObj->m_rect.left = rect.left + pObj->m_dbLeftRate*rect.Width();
- pObj->m_rect.right = rect.left + pObj->m_dbRightRate*rect.Width();
- pObj->m_rect.top = rect.top + pObj->m_dbTopRate * rect.Height();
- pObj->m_rect.bottom = rect.top + pObj->m_dbBottomRate * rect.Height();
- }
- m_rect = rect;
- Invalidate();
- }
- //////////////////////////////////////////////////////////////////////////
- //---------------------------------------------- CDrawTLine --------
- IMPLEMENT_SERIAL(CDrawTLine, CDrawObj, 0)
- CDrawTLine::CDrawTLine():CDrawObj()
- {
- }
- CDrawObj* CDrawTLine::Clone(void)
- {
- CDrawTLine *pObj = new CDrawTLine;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawTLine::Draw(CDC* pDC)
- {
- COLORREF clrLine = m_clrLine;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- rect = m_rctCurrent;
- }
- CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
- rect.NormalizeRect();
- if(rect.Width()>=rect.Height())
- {
- int nY0 = (rect.top+rect.bottom) / 2;
- pDC->MoveTo(rect.left,nY0);
- pDC->LineTo(rect.right,nY0);
- }
- else
- {
- int nX0 = (rect.left+rect.right) / 2;
- pDC->MoveTo(nX0,rect.top);
- pDC->LineTo(nX0,rect.bottom);
- }
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- }
- //////////////////////////////////////////////////////////////////////////
- //---------------------------------------------- CDrawLine --------
- IMPLEMENT_SERIAL(CDrawLine, CDrawObj, 0)
- CDrawLine::CDrawLine():CDrawObj()
- {
- }
- CDrawObj* CDrawLine::Clone(void)
- {
- CDrawLine *pObj = new CDrawLine;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawLine::Draw(CDC* pDC)
- {
- COLORREF clrLine = m_clrLine;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- rect = m_rctCurrent;
- }
- CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
- pDC->MoveTo(rect.left, rect.top);
- pDC->LineTo(rect.right, rect.bottom);
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- }
- //////////////////////////////////////////////////////////////////////////
- //---------------------------------------------- CDrawText --------
- IMPLEMENT_SERIAL(CDrawText, CDrawObj, 0)
- CDrawText::CDrawText():CDrawObj()
- {
- m_strCaption = g_strCharacter;
- m_clrFore = RGB(0, 0, 0);
- }
- CDrawObj* CDrawText::Clone(void)
- {
- CDrawText *pObj = new CDrawText;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- bool CDrawText::Fresh(CRect &RECT)
- {
- CDrawObj::Fresh(RECT);
- //Invalidate( );
- RECT = m_rect;
- return true;
- }
- void CDrawText::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- if ( !m_bShow && bRuning) return;
- if(!pDC->IsPrinting())
- {
- CRect rectRgn = m_rctCurrent;
- if (!bRuning) rectRgn = m_rect;
- rectRgn.NormalizeRect();
- pDC->LPtoDP(&rectRgn);
- CRgn rgn;
- rgn.CreateRectRgnIndirect(&rectRgn);
- pDC->SelectClipRgn(&rgn);
- DrawText(pDC);
- pDC->SelectClipRgn(NULL);
- DeleteObject( rgn );
- }
- else
- DrawText(pDC);
- }
- void CDrawText::DrawText(CDC* pDC)
- {
- COLORREF clrFore = m_clrFore;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrFore = m_clrCurrentFore;
- rect = m_rctCurrent;
- }
- pDC->SetTextColor(clrFore);
- pDC->SetTextAlign(TA_LEFT|TA_TOP);
- CFont font;
- font.CreateFontIndirect(&m_logfont);
- CFont* pOldFont = pDC->SelectObject(&font);
- int height = abs(m_logfont.lfHeight);
- rect.NormalizeRect();
- //int nX0 = (rect.left+rect.right) / 2;
- //int nY0 = (rect.top+rect.bottom) / 2;
- //if(rect.Width()>=rect.Height())
- //{
- // int yt = nY0;
- // int Length = m_strCaption.GetLength();
- // const char *p = (const char*)m_strCaption;
- // int ystart = yt;
- // for(int i=0;i<Length;i++)
- // {
- // ystart -= height / 2;
- // if(*(p+i)<0) i++;
- // }
- // pDC->TextOut(rect.left, ystart, m_strCaption);
- //}
- //else
- //{
- // int xt = nX0;
- // int yt = nY0;
- // int Length = m_strCaption.GetLength();
- // const char *p = (const char*)m_strCaption;
- // int ystart = yt;
- // for(int i=0;i<Length;i++)
- // {
- // ystart -= height / 2;
- // if(*(p+i)<0) i++;
- // }
- // for(i=0;i<Length;i++)
- // {
- // if(*(p+i)<0)
- // {
- // pDC->TextOut(xt,ystart,p+i,2);
- // i++;
- // }
- // else pDC->TextOut(xt,ystart,p+i,1);
- // ystart += height;
- // }
- //}
- //pDC->SelectObject(pOldFont);
- //DeleteObject( font );
- int nX0 = (rect.left+rect.right) / 2;
- int nY0 = (rect.top+rect.bottom) / 2;
- CSize sizeText = pDC->GetTextExtent(m_strCaption);
- int nInterval = sizeText.cy / 2;
- int nYText = nY0 - nInterval + 1;
- int nXText;
- //pDC->SetTextAlign(TA_CENTER|TA_TOP);
- nXText = rect.left;
- //pDC->SetTextColor(txtColor);
- pDC->TextOut(nXText,nYText,m_strCaption);
- pDC->SelectObject(pOldFont);
- DeleteObject( font );
- }
- //////////////////////////////////////////////////////////////////////////
- //---------------------------------------------- CDrawRect --------
- IMPLEMENT_SERIAL(CDrawRect, CDrawObj, 0)
- CDrawRect::CDrawRect():CDrawObj()
- {
- }
- CDrawObj* CDrawRect::Clone(void)
- {
- CDrawRect *pObj = new CDrawRect;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_strLineType = m_strLineType;
- pObj->m_clrLine = m_clrLine;
- return pObj;
- }
- void CDrawRect::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- if ( !m_bShow && bRuning) return;
- COLORREF clrLine = m_clrCurrentLine;
- CRect rect = m_rctCurrent;
- if ( !bRuning )
- {
- clrLine = m_clrLine;
- rect = m_rect;
- }
- CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
-
- // CBrush
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
- if ( m_nFillMode < 8 )
- {
- pDC->Rectangle(rect);
- }
- else // 渐变填充
- {
- CGradient gradient;
- CRect tmp = rect;
- switch ( m_nFillMode )
- {
- case 8:
- gradient.HorizontalGradient(pDC, rect, m_clrFill, m_clrBack);
- break;
- case 9:
- gradient.HorizontalGradient(pDC, rect, m_clrBack, m_clrFill);
- break;
- case 10:
- tmp.NormalizeRect();
- tmp.right = (tmp.left+tmp.right)/2+1;
- gradient.HorizontalGradient(pDC, tmp, m_clrFill, m_clrBack);
- tmp = rect;
- tmp.NormalizeRect();
- tmp.left = (tmp.left+tmp.right)/2-1;
- gradient.HorizontalGradient(pDC, tmp, m_clrBack, m_clrFill);
- break;
- case 11:
- gradient.VerticalGradient(pDC, rect, m_clrFill, m_clrBack);
- break;
- case 12:
- gradient.VerticalGradient(pDC, rect, m_clrBack, m_clrFill);
- break;
- case 13:
- tmp.NormalizeRect();
- tmp.top = (tmp.top+tmp.bottom)/2-1;
- gradient.VerticalGradient(pDC, tmp, m_clrBack, m_clrFill);
- tmp = rect;
- tmp.NormalizeRect();
- tmp.bottom = (tmp.top+tmp.bottom)/2+1;
- gradient.VerticalGradient(pDC, tmp, m_clrFill, m_clrBack);
- break;
- }
- }
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- DeleteObject( pen );
- DeleteObject( m_brush );
- }
- //---------------------------------------------- CDrawRoundRect --------
- IMPLEMENT_SERIAL(CDrawRoundRect, CDrawObj, 0)
- CDrawRoundRect::CDrawRoundRect():CDrawObj()
- {
- }
- CDrawObj* CDrawRoundRect::Clone(void)
- {
- CDrawRoundRect *pObj = new CDrawRoundRect;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_strLineType = m_strLineType;
- pObj->m_clrLine = m_clrLine;
- return pObj;
- }
- void CDrawRoundRect::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- if ( !m_bShow && bRuning) return;
- COLORREF clrLine = m_clrCurrentLine;
- CRect rect = m_rctCurrent;
- if ( !bRuning )
- {
- clrLine = m_clrLine;
- rect = m_rect;
- }
- CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
-
- // CBrush
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
- CPoint pt;
- pt.x = 20;
- pt.y = 20;
- pDC->RoundRect(rect, pt);
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- DeleteObject( pen );
- DeleteObject( m_brush );
- }
- //////////////////////////////////////////////////////////////////////////
- //---------------------------------------------- CDrawOval --------
- IMPLEMENT_SERIAL(CDrawOval, CDrawObj, 0)
- CDrawOval::CDrawOval():CDrawObj()
- {
- }
- CDrawObj* CDrawOval::Clone(void)
- {
- CDrawOval *pObj = new CDrawOval;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawOval::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- if ( !m_bShow && bRuning) return;
- COLORREF clrLine = m_clrLine;
- COLORREF clrBack = m_clrBack;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- clrBack = m_clrCurrentBack;
- rect = m_rctCurrent;
- }
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
-
- // CBrush
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
- pDC->Ellipse(rect);
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- DeleteObject( pen );
- DeleteObject( m_brush );
- }
- //---------------------------------------------- CDrawPie --------
- IMPLEMENT_SERIAL(CDrawPie, CDrawObj, 0)
- CDrawPie::CDrawPie():CDrawObj()
- {
- m_nStartAngle = 0;
- m_nSweepAngle = 90;
- }
- CDrawObj* CDrawPie::Clone(void)
- {
- CDrawPie *pObj = new CDrawPie;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawPie::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- if ( !m_bShow && bRuning) return;
- COLORREF clrLine = m_clrLine;
- COLORREF clrBack = m_clrBack;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- clrBack = m_clrCurrentBack;
- rect = m_rctCurrent;
- }
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
-
- // CBrush
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
- rect.NormalizeRect();
- // 根据角度计算两个点;
- CPoint s = CPoint(rect.right, (rect.top + rect.bottom)/2);
-
- CRgn rgn;
- rgn.CreateEllipticRgnIndirect( rect );
-
- int bLeft = (m_nSweepAngle>90 && m_nSweepAngle<270) ? -1:1;
- CPoint e;
- bool bIn = true;
- for ( int i =0; i<rect.Width()/2; i++)
- {
- e.x = rect.CenterPoint().x + i*bLeft;
- e.y = rect.CenterPoint().y - i*bLeft*tan(m_nSweepAngle*PIE/180);
- if ( !rgn.PtInRegion( e ) )
- {
- break;
- }
- }
- pDC->Pie(&rect, s, e);
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- DeleteObject( pen );
- DeleteObject( m_brush );
- DeleteObject( rgn );
- }
- BOOL CDrawPie::OnAttrib(CPropertySheet& sheet)
- {
- CArcPage page;
- page.m_nStartAngle = m_nStartAngle;
- page.m_nSweepAngle = m_nSweepAngle;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_nStartAngle = page.m_nStartAngle;
- m_nSweepAngle = page.m_nSweepAngle;
- return TRUE;
- }
- return FALSE;
- }
- void CDrawPie::Serialize( CArchive& ar )
- {
- CDrawObj::Serialize( ar );
- if( ar.IsStoring() )
- {
- ar << m_nStartAngle;
- ar << m_nSweepAngle;
- }
- else
- {
- ar >> m_nStartAngle;
- ar >> m_nSweepAngle;
- }
- }
- //---------------------------------------------- CDrawFan --------
- IMPLEMENT_SERIAL(CDrawFan, CDrawObj, 0)
- CDrawFan::CDrawFan():CDrawObj()
- {
- m_nStep = 0;
- m_bComputed = false;
- m_bRun = false;
- m_clrLine = RGB(0,0,0);
- m_clrBack = RGB(255,255,0);
- m_clrFore = RGB(0,255,0);
- }
- CDrawObj* CDrawFan::Clone(void)
- {
- CDrawFan *pObj = new CDrawFan;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_strLogic = m_strLogic;
- return pObj;
- }
- void CDrawFan::Serialize( CArchive& ar )
- {
- CDrawObj::Serialize( ar );
- if( ar.IsStoring() )
- {
- ar << m_strLogic;
- }
- else
- {
- ar >> m_strLogic;
- }
- }
- BOOL CDrawFan::OnAttrib(CPropertySheet& sheet)
- {
- CLogicPage page;
- page.m_strLogic = m_strLogic;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_strLogic = page.m_strLogic;
- return TRUE;
- }
- return FALSE;
- }
- bool CDrawFan::Fresh(CRect &RECT)
- {
- CDrawObj::Fresh(RECT);
- CRealComputer com;
- com.SetFormula(m_strLogic);
- m_bRun = (int)com.GetResult();
- RECT = m_rect;
- return true;
- }
- void CDrawFan::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- COLORREF clrLine = m_clrLine;
- COLORREF clrBack = m_clrBack;
- COLORREF clrFore = m_clrFore;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- clrBack = m_clrCurrentBack;
- clrFore = m_clrCurrentFore;
- rect = m_rctCurrent;
- }
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
- rect.NormalizeRect();
- if ( bRuning && m_bRun )
- {
- m_nStep++;
- m_nStep = m_nStep%8;
- }
- // 计算落点数组
- if ( !bRuning || !m_bComputed )
- {
- CPoint center = rect.CenterPoint();
- float h = rect.Height();
- float w = rect.Width();
- float y = 0;
-
- tagPoint[0] = CPoint(rect.right, (rect.top + rect.bottom)/2);
- tagPoint[2] = CPoint((rect.left +rect.right)/2, rect.top);
- tagPoint[4] = CPoint(rect.left, (rect.top + rect.bottom)/2);
- tagPoint[6] = CPoint((rect.left +rect.right)/2, rect.bottom);
- int x =0;
- for (x = w/4; x<w/2; x++)
- {
- y = 1.0*x*rect.Height()/rect.Width();
- float delta = x*x*(h/2)*(h/2) + y*y*(w/2)*(w/2) - (h/2)*(h/2)*(w/2)*(w/2);
- if ( delta > -1 && delta < 1)
- {
- break;
- }
- }
- int yP = (int)y;
- tagPoint[1] = center + CSize(x, -yP);
- tagPoint[3] = center + CSize(-x, -yP);
- tagPoint[5] = center + CSize(-x, yP);
- tagPoint[7] = center + CSize(x, yP);
- m_bComputed = true;
- }
- CBrush brush(m_clrBack);
- pDC->SelectObject(&brush);
- pDC->Pie(&rect, tagPoint[m_nStep], tagPoint[(m_nStep+2)%8]);
- pDC->Pie(&rect, tagPoint[(m_nStep+4)%8], tagPoint[(m_nStep+6)%8]);
- CBrush brush1(m_clrFore);
- CBrush *pOldBrush = pDC->SelectObject(&brush1);
- pDC->Pie(&rect, tagPoint[(m_nStep+2)%8], tagPoint[(m_nStep+4)%8]);
- pDC->Pie(&rect, tagPoint[(m_nStep+6)%8], tagPoint[(m_nStep)%8]);
- pDC->SelectObject(pOldBrush);
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- DeleteObject( brush );
- DeleteObject( brush1 );
- }
- //---------------------------------------------- CDrawArc --------
- IMPLEMENT_SERIAL(CDrawArc, CDrawObj, 0)
- CDrawArc::CDrawArc():CDrawObj()
- {
- m_nStartAngle = 0;
- m_nSweepAngle = 120;
- }
- CDrawObj* CDrawArc::Clone(void)
- {
- CDrawArc *pObj = new CDrawArc;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_nStartAngle = m_nStartAngle;
- pObj->m_nSweepAngle = m_nSweepAngle;
- return pObj;
- }
- void CDrawArc::Draw(CDC* pDC)
- {
- CRect rect = m_rect;
- COLORREF clrLine = m_clrLine;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- rect = m_rctCurrent;
- }
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
- int x = (rect.left + rect.right)/2;
- int y = (rect.top + rect.bottom)/2;
- int r = (rect.Width() < rect.Height() ? rect.Width() : rect.Height())/2;
- pDC->MoveTo(x + r * cos(m_nStartAngle * PIE / 180), y - r * sin(m_nStartAngle * PIE / 180));
- pDC->AngleArc(x, y, r, m_nStartAngle, m_nSweepAngle);
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- }
- BOOL CDrawArc::OnAttrib(CPropertySheet& sheet)
- {
- CArcPage page;
- page.m_nStartAngle = m_nStartAngle;
- page.m_nSweepAngle = m_nSweepAngle;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_nStartAngle = page.m_nStartAngle;
- m_nSweepAngle = page.m_nSweepAngle;
- return TRUE;
- }
- return FALSE;
- }
- void CDrawArc::Serialize( CArchive& ar )
- {
- CDrawObj::Serialize( ar );
- if( ar.IsStoring() )
- {
- ar << m_nStartAngle;
- ar << m_nSweepAngle;
- }
- else
- {
- ar >> m_nStartAngle;
- ar >> m_nSweepAngle;
- }
- }
- //---------------------------------------------- CDrawPoly --------
- IMPLEMENT_SERIAL(CDrawPoly, CDrawObj, 0)
- CDrawPoly::CDrawPoly():CDrawObj()
- {
- m_points = NULL;
- m_nPoints = 0;
- m_nAllocPoints = 0;
- }
- CDrawPoly::~CDrawPoly()
- {
- //chn mem
- if (m_points != NULL)
- {
- delete[] m_points;
- m_points = NULL;
- }
- }
- void CDrawPoly::AddPoint(const CPoint& point)
- {
- ASSERT_VALID(this);
- if( m_nPoints < 0 ) return;
- if (m_nPoints == m_nAllocPoints)
- {
- CPoint* newPoints = new CPoint[m_nAllocPoints + 10];
- if (m_points != NULL)
- {
- memcpy(newPoints, m_points, sizeof(CPoint) * m_nAllocPoints);
- delete[] m_points;
- }
- m_points = newPoints;
- m_nAllocPoints += 10;
- }
- if (m_nPoints == 0 || m_points[m_nPoints - 1] != point)
- {
- m_points[m_nPoints++] = point;
- if (!RecalcBounds())
- {
- Invalidate();
- }
- }
- }
- BOOL CDrawPoly::RecalcBounds()
- {
- ASSERT_VALID(this);
- if (m_nPoints == 0)
- return FALSE;
- CRect bounds(m_points[0], CSize(0, 0));
- for (int i = 1; i < m_nPoints; ++i)
- {
- if (m_points[i].x < bounds.left)
- bounds.left = m_points[i].x;
- if (m_points[i].x > bounds.right)
- bounds.right = m_points[i].x;
- if (m_points[i].y < bounds.top)
- bounds.top = m_points[i].y;
- if (m_points[i].y > bounds.bottom)
- bounds.bottom = m_points[i].y;
- }
- if (bounds == m_rect)
- return FALSE;
- Invalidate();
- m_rect = bounds;
- Invalidate();
- return TRUE;
- }
- void CDrawPoly::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- COLORREF clrLine = m_clrLine;
- COLORREF clrBack = m_clrBack;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- clrBack = m_clrCurrentBack;
- rect = m_rctCurrent;
- }
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
- // CBrush
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
-
- if ( m_nFillMode < 8 )
- {
- pDC->Polygon(m_points, m_nPoints);
- }
- else // 渐变填充
- {
- CGradient gradient;
- HRGN hRgn = CreatePolygonRgn(m_points, m_nPoints, ALTERNATE);
- CRect tmp = rect;
- switch ( m_nFillMode )
- {
- case 8:
- gradient.HorizontalGradient(pDC, hRgn, m_clrFill, clrBack);
- break;
- case 9:
- case 10:
- gradient.HorizontalGradient(pDC, hRgn, clrBack, m_clrFill);
- break;
- case 11:
- gradient.VerticalGradient(pDC, hRgn, m_clrFill, clrBack);
- break;
- case 12:
- case 13:
- gradient.VerticalGradient(pDC, hRgn, m_clrBack, m_clrFill);
- break;
- }
- DeleteObject(hRgn);
- }
- pDC->SelectObject(pOldBrush);
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- DeleteObject( m_brush );
- }
- void CDrawPoly::Serialize( CArchive& ar )
- {
- int i;
- CDrawObj::Serialize( ar );
- if( ar.IsStoring() )
- {
- ar << (WORD) m_nPoints;
- ar << (WORD) m_nAllocPoints;
- for (i = 0;i< m_nPoints; i++)
- ar << m_points[i];
- }
- else
- {
- WORD wTemp;
- ar >> wTemp; m_nPoints = wTemp;
- ar >> wTemp; m_nAllocPoints = wTemp;
- m_points = new CPoint[m_nAllocPoints];
- for (i = 0;i < m_nPoints; i++)
- ar >> m_points[i];
- }
- }
- CDrawObj* CDrawPoly::Clone()
- {
- CDrawPoly* pClone = new CDrawPoly();
- *((CDrawObj*)pClone) = *(CDrawObj*)this;
- pClone->m_points = new CPoint[m_nAllocPoints];
- memcpy(pClone->m_points, m_points, sizeof(CPoint) * m_nPoints);
- pClone->m_nAllocPoints = m_nAllocPoints;
- pClone->m_nPoints = m_nPoints;
- return pClone;
- }
- void CDrawPoly::MoveTo(CRect rect)
- {
- ASSERT_VALID(this);
- if (rect == m_rect)
- return;
- Invalidate();
- for (int i = 0; i < m_nPoints; i += 1)
- {
- m_points[i].x += rect.left - m_rect.left;
- m_points[i].y += rect.top - m_rect.top;
- }
- m_rect = rect;
- Invalidate();
- }
- int CDrawPoly::GetHandleCount()
- {
- return m_nPoints;
- }
- CPoint CDrawPoly::GetHandle(int nHandle)
- {
- ASSERT_VALID(this);
- ASSERT(nHandle >= 1 && nHandle <= m_nPoints);
- return m_points[nHandle - 1];
- }
- void CDrawPoly::MoveHandleTo(int nHandle, CPoint point)
- {
- ASSERT(nHandle >= 1 && nHandle <= m_nPoints);
- if (m_points[nHandle - 1] == point)
- return;
- m_points[nHandle - 1] = point;
- RecalcBounds();
- Invalidate();
- }
- //---------------------------------------------- CDrawMLine --------
- IMPLEMENT_SERIAL(CDrawMLine, CDrawPoly, 0)
- CDrawMLine::CDrawMLine():CDrawPoly()
- {
- }
- void CDrawMLine::Draw(CDC* pDC)
- {
- ASSERT_VALID(this);
- COLORREF clrLine = m_clrLine;
- COLORREF clrBack = m_clrBack;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- clrBack = m_clrCurrentBack;
- rect = m_rctCurrent;
- }
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
- if ( m_nPoints > 0 )
- pDC->MoveTo(m_points[0]);
- for (int i=1; i<m_nPoints; i++)
- pDC->LineTo(m_points[i]);
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- }
- CDrawObj* CDrawMLine::Clone()
- {
- CDrawMLine* pClone = new CDrawMLine();
- *((CDrawObj*)pClone) = *(CDrawObj*)this;
- pClone->m_points = new CPoint[m_nAllocPoints];
- memcpy(pClone->m_points, m_points, sizeof(CPoint) * m_nPoints);
- pClone->m_nAllocPoints = m_nAllocPoints;
- pClone->m_nPoints = m_nPoints;
- return pClone;
- }
- //---------------------------------------------- CDrawArrow -------
- IMPLEMENT_SERIAL(CDrawArrow, CDrawObj, 0)
- CDrawArrow::CDrawArrow():CDrawObj()
- {
- }
- CDrawObj* CDrawArrow::Clone(void)
- {
- CDrawArrow *pObj = new CDrawArrow;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawArrow::Draw(CDC* pDC)
- {
- CRect rect = m_rect;
- rect.NormalizeRect();
- int nXX = rect.right - rect.left;
- int nYY = rect.bottom - rect.top;
- if(nXX<2||nYY<2) return;
- if(nXX>=nYY)
- {
- if(m_rect.left>=m_rect.right)
- DrawArrow(pDC,rect, DIR_LEFT, m_clrBack);
- else
- DrawArrow(pDC,rect, DIR_RIGHT, m_clrBack);
- }
- else
- {
- if(m_rect.top>=m_rect.bottom)
- DrawArrow(pDC, rect, DIR_DOWN, m_clrBack);
- else
- DrawArrow(pDC, rect, DIR_UP, m_clrBack);
- }
- }
- void CDrawArrow::DrawArrow(CDC* pDC, CRect rect, BYTE Direction,COLORREF clrArrow )
- {
- if(Direction==DIR_UP||Direction==DIR_DOWN)
- {
- int middle = (rect.left + rect.right) / 2;
- for(int i=0; i<rect.Height(); i++)
- {
- int nY = rect.top + i;
- if (Direction==DIR_DOWN)
- {
- int nX1 = rect.left + i*( ( 1.0*rect.Width()/2) / rect.Height() );
- int nX2 = rect.right - i*( ( 1.0*rect.Width()/2) / rect.Height() );
- CRect rect1(nX1, nY, nX2, nY+1);
- pDC->FillSolidRect(rect1,clrArrow);
- }
- else
- {
- int nX1 = middle - i*( ( 1.0*rect.Width()/2) / rect.Height() );
- int nX2 = middle + i*( ( 1.0*rect.Width()/2) / rect.Height() );
- CRect rect1(nX1, nY, nX2, nY+1);
- pDC->FillSolidRect(rect1,clrArrow);
- }
- }
- }
- if(Direction==DIR_LEFT||Direction==DIR_RIGHT)
- {
- int middle = (rect.top + rect.bottom) / 2;
- for(int i=0; i<rect.Width(); i++)
- {
- int nX = rect.left + i;
- if (Direction==DIR_RIGHT)
- {
- int nY1 = rect.top + i*( ( 1.0*rect.Height()/2) / rect.Width() );
- int nY2 = rect.bottom - i*( ( 1.0*rect.Height()/2) / rect.Width() );
- CRect rect1(nX, nY1, nX+1, nY2);
- pDC->FillSolidRect(rect1,clrArrow);
- }
- else
- {
- int nY1 = middle + i*( ( 1.0*rect.Height()/2) / rect.Width() );
- int nY2 = middle - i*( ( 1.0*rect.Height()/2) / rect.Width() );
- CRect rect1(nX, nY1, nX+1, nY2);
- pDC->FillSolidRect(rect1,clrArrow);
- }
- }
- }
- }
- //---------------------------------------------- CDrawBreaker --------
- IMPLEMENT_SERIAL(CDrawBreaker, CDrawObj, 0)
- CDrawBreaker::CDrawBreaker():CDrawObj()
- {
- }
- CDrawObj* CDrawBreaker::Clone(void)
- {
- CDrawBreaker *pObj = new CDrawBreaker;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawBreaker::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- COLORREF clrLine = m_clrLine;
- COLORREF clrBack = m_clrBack;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- clrBack = m_clrCurrentBack;
- rect = m_rctCurrent;
- }
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CBrush brush(clrBack);
- CPen* pOldPen = pDC->SelectObject(&pen);
- CBrush* pOldBrush = pDC->SelectObject(&brush);
- rect.NormalizeRect();
- int nMidX = rect.left + rect.Width()/2;
- pDC->MoveTo(nMidX, rect.top);
- pDC->LineTo(nMidX, rect.top + rect.Height()/4);
- pDC->MoveTo(nMidX, rect.top + rect.Height()*3/4);
- pDC->LineTo(nMidX, rect.bottom );
- rect.DeflateRect(0, rect.Height()/4, 0, rect.Height()/4);
- pDC->Rectangle(rect);
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- DeleteObject( pen );
- DeleteObject( brush );
- }
- //---------------------------------------------- CDrawSwitch --------
- IMPLEMENT_SERIAL(CDrawSwitch, CDrawObj, 0)
- CDrawSwitch::CDrawSwitch():CDrawObj()
- {
- m_clrLine = RGB(0, 255, 0);
- m_bRun = FALSE;
- m_strLogic = "";
- }
- CDrawObj* CDrawSwitch::Clone(void)
- {
- CDrawSwitch *pObj = new CDrawSwitch;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_strLogic = m_strLogic;
- return pObj;
- }
- void CDrawSwitch::Serialize( CArchive& ar )
- {
- CDrawObj::Serialize( ar );
- if( ar.IsStoring() )
- {
- ar << m_strLogic;
- }
- else
- {
- ar >> m_strLogic;
- }
- }
- BOOL CDrawSwitch::OnAttrib(CPropertySheet& sheet)
- {
- CLogicPage page;
- page.m_strLogic = m_strLogic;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_strLogic = page.m_strLogic;
- return TRUE;
- }
- return FALSE;
- }
- bool CDrawSwitch::Fresh(CRect &RECT)
- {
- CDrawObj::Fresh(RECT);
- CRealComputer com;
- com.SetFormula(m_strLogic);
- m_bRun = (int)com.GetResult();
- RECT = m_rect;
- return true;
- }
- void CDrawSwitch::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- CRect rect = m_rect;
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, (bRuning&&m_bRun)?RGB(255,0,0):RGB(0,255,0));
- CPen* pOldPen = pDC->SelectObject(&pen);
- rect.NormalizeRect();
- int nMidX = rect.left + rect.Width()/2;
- pDC->MoveTo(nMidX, rect.top);
- pDC->LineTo(nMidX, rect.top + rect.Height()/4);
- pDC->MoveTo(rect.left + rect.Width()/4, rect.top + rect.Height()/4);
- pDC->LineTo(rect.right - rect.Width()/4, rect.top + rect.Height()/4);
- if ( bRuning && m_bRun )
- {
- pDC->MoveTo(nMidX, rect.top + rect.Height()/4);
- pDC->LineTo(nMidX, rect.top + rect.Height()*3/4);
- }
- else
- {
- pDC->MoveTo(rect.left, rect.top + rect.Height()/4);
- pDC->LineTo(nMidX, rect.top + rect.Height()*3/4);
- }
-
- pDC->MoveTo(nMidX, rect.top + rect.Height()*3/4);
- pDC->LineTo(nMidX, rect.bottom );
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- }
- //---------------------------------------------- CDrawGrid --------
- IMPLEMENT_SERIAL(CDrawGrid, CDrawObj, 0)
- CDrawGrid::CDrawGrid():CDrawObj()
- {
- m_clrLine = RGB(0, 255, 0);
- }
- CDrawObj* CDrawGrid::Clone(void)
- {
- CDrawGrid *pObj = new CDrawGrid;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawGrid::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- COLORREF clrLine = m_clrLine;
- COLORREF clrBack = m_clrBack;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- clrBack = m_clrCurrentBack;
- rect = m_rctCurrent;
- }
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
- rect.NormalizeRect();
- int nXNum = 5;
- int nYNum = 5;
- int nDX = rect.Width()/nXNum;
- int nDY = rect.Height()/nYNum;
- for(int i=0;i<=nXNum;i++)
- {
- int nX = rect.left + nDX*i;
- pDC->MoveTo(nX,rect.top);
- pDC->LineTo(nX,rect.top+nDY*nYNum);
- }
- for(int j=0;j<=nYNum;j++)
- {
- int nY = rect.top + nDY*j;
- pDC->MoveTo(rect.left,nY);
- pDC->LineTo(rect.left+nDX*nXNum,nY);
- }
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- }
- //---------------------------------------------- CDrawTable --------
- IMPLEMENT_SERIAL(CDrawTable, CDrawObj, 0)
- CDrawTable::CDrawTable():CDrawObj()
- {
- m_clrLine = RGB(0, 255, 0);
- m_clrFore = RGB(255, 255, 0);
- m_nFillMode = 0;
- m_bAddAve = false;
- m_bAddMax = false;
- m_bAddMin = false;
- m_bShowRowHead = true;
- m_nType = 0;
- for (int i=0; i<8; i++)
- {
- CColPro* pObj = new CColPro;
- m_colList.AddTail(pObj);
- }
- }
- CDrawObj* CDrawTable::Clone(void)
- {
- CDrawTable *pObj = new CDrawTable;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawTable::Serialize( CArchive& ar )
- {
- CDrawObj::Serialize( ar );
- if( ar.IsStoring() )
- {
- ar << m_bAddAve;
- ar << m_bAddMax;
- ar << m_bAddMin;
- ar << m_nType;
- ar << m_bShowRowHead;
- }
- else
- {
- m_colList.RemoveAll();
- ar >> m_bAddAve;
- ar >> m_bAddMax;
- ar >> m_bAddMin;
- ar >> m_nType;
- ar >> m_bShowRowHead;
- }
- m_colList.Serialize( ar );
- }
- BOOL CDrawTable::OnAttrib(CPropertySheet& sheet)
- {
- CReportBasePage page;
- page.m_bAddAve = m_bAddAve;
- page.m_bAddMin = m_bAddMin;
- page.m_bAddMax = m_bAddMax;
- page.m_nType = m_nType;
- page.m_bShowRowHead = m_bShowRowHead;
- sheet.AddPage(&page);
- CReportColPage cPage;
- POSITION pos = m_colList.GetHeadPosition();
- while(pos!=NULL)
- {
- CColPro* pObj = m_colList.GetNext(pos);
- CColPro *pNewObj = pObj->Clone();
- cPage.m_colList.AddTail(pNewObj);
- }
-
- sheet.AddPage(&cPage);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_bAddAve=page.m_bAddAve;
- m_bAddMin=page.m_bAddMin;
- m_bAddMax=page.m_bAddMax;
- m_nType=page.m_nType;
- m_bShowRowHead=page.m_bShowRowHead;
- m_colList.RemoveAll();
- pos = cPage.m_colList.GetHeadPosition();
- while(pos!=NULL)
- {
- CColPro* pObj = cPage.m_colList.GetNext(pos);
- CColPro *pNewObj = pObj->Clone();
- m_colList.AddTail(pNewObj);
- }
- return TRUE;
- }
- return FALSE;
- }
- CString CDrawTable::GetColFormat(int col)
- {
- int i = 1;
- POSITION pos = m_colList.GetHeadPosition();
- while(pos!=NULL)
- {
- CColPro* pObj = m_colList.GetNext(pos);
- if ( i == col )
- {
- return pObj->m_strFormat;
- }
- i++;
- }
- return "####";
- }
- void CDrawTable::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- COLORREF clrLine = m_clrLine;
- COLORREF clrFore = m_clrFore;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- clrFore = m_clrCurrentFore;
- rect = m_rctCurrent;
- }
- // CBrush
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
- if ( m_nFillMode < 8 )
- {
- pDC->Rectangle(rect);
- }
- else // 渐变填充
- {
- CGradient gradient;
- CRect tmp = rect;
- switch ( m_nFillMode )
- {
- case 8:
- gradient.HorizontalGradient(pDC, rect, m_clrFill, m_clrBack);
- break;
- case 9:
- gradient.HorizontalGradient(pDC, rect, m_clrBack, m_clrFill);
- break;
- case 10:
- tmp.NormalizeRect();
- tmp.right = (tmp.left+tmp.right)/2+1;
- gradient.HorizontalGradient(pDC, tmp, m_clrFill, m_clrBack);
- tmp = rect;
- tmp.NormalizeRect();
- tmp.left = (tmp.left+tmp.right)/2-1;
- gradient.HorizontalGradient(pDC, tmp, m_clrBack, m_clrFill);
- break;
- case 11:
- gradient.VerticalGradient(pDC, rect, m_clrFill, m_clrBack);
- break;
- case 12:
- gradient.VerticalGradient(pDC, rect, m_clrBack, m_clrFill);
- break;
- case 13:
- tmp.NormalizeRect();
- tmp.top = (tmp.top+tmp.bottom)/2-1;
- gradient.VerticalGradient(pDC, tmp, m_clrBack, m_clrFill);
- tmp = rect;
- tmp.NormalizeRect();
- tmp.bottom = (tmp.top+tmp.bottom)/2+1;
- gradient.VerticalGradient(pDC, tmp, m_clrFill, m_clrBack);
- break;
- }
- }
- pDC->SelectObject(pOldBrush);
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
- rect.NormalizeRect();
- pDC->SetTextColor(clrFore);
- CFont font;
- font.CreateFontIndirect(&m_logfont);
- CFont* pOldFont = pDC->SelectObject(&font);
- int nXNum = m_colList.GetCount();
- if ( m_bShowRowHead )
- nXNum++;
- int nYNum;
- if ( m_nType==0 )
- nYNum = 25;
- else
- nYNum = 32;
- if ( m_bAddAve ) nYNum++;
- if ( m_bAddMax ) nYNum++;
- if ( m_bAddMin ) nYNum++;
- float nDX = 1.0*rect.Width()/nXNum;
- float nDY = 1.0*rect.Height()/nYNum;
- for(int i=0;i<=nXNum;i++)
- {
- int nX = rect.left + nDX*i;
- if (i==nXNum) nX = rect.right;
- pDC->MoveTo(nX,rect.top);
- pDC->LineTo(nX,rect.bottom);
- }
- for(int j=0;j<=nYNum;j++)
- {
- int nY = rect.top + nDY*j;
- if (j==nYNum) nY = rect.bottom;
- pDC->MoveTo(rect.left,nY);
- pDC->LineTo(rect.right,nY);
- }
- for( i= m_bShowRowHead?1:0; i<nXNum; i++)
- for(j=1;j<nYNum;j++)
- {
- pDC->SetTextAlign(TA_RIGHT | TA_TOP);
- int y = rect.top + nDY*j + 5;
- int x = rect.left + nDX*(i+1) - 5;
- CString format = GetColFormat(i);
- if (!bRuning)
- pDC->TextOut(x,y, format);
- else
- {
- format.Replace("#","0");
- pDC->TextOut(x,y, format);
- }
- }
- // 画列名
- int col = m_bShowRowHead?1:0;
- POSITION pos = m_colList.GetHeadPosition();
- while(pos!=NULL)
- {
- CColPro* pObj = m_colList.GetNext(pos);
- int y = rect.top + 5;
- int x = rect.left + nDX*(col+1) - 5;
- pDC->TextOut(x,y, pObj->m_strTitle);
- col++;
- }
- pDC->SetTextAlign(TA_LEFT);
- // 画行名
- if (m_bShowRowHead)
- {
- int col = 1;
- if ( m_nType == 0 )
- {
- for ( int i=0; i<24; i++)
- {
- int y = rect.top + nDY*col + 5;
- int x = rect.left + 5;
- CString tmp;
- tmp.Format(g_strHour, i+1);
- pDC->TextOut(x,y, tmp);
- col++;
- }
- }
- else
- {
- for ( int i=0; i<31; i++)
- {
- int y = rect.top + nDY*col + 5;
- int x = rect.left + 5;
- CString tmp;
- tmp.Format(g_strDate, i+1);
- pDC->TextOut(x,y, tmp);
- col++;
- }
- }
- if (m_bAddAve)
- {
- int y = rect.top + nDY*col + 5;
- int x = rect.left + 5;
- pDC->TextOut(x,y, g_strMean);
- col++;
- }
- if (m_bAddMax)
- {
- int y = rect.top + nDY*col + 5;
- int x = rect.left + 5;
- pDC->TextOut(x,y, g_strMaxValues);
- col++;
- }
- if (m_bAddMin)
- {
- int y = rect.top + nDY*col + 5;
- int x = rect.left + 5;
- pDC->TextOut(x,y, g_strMinValues);
- col++;
- }
- }
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- DeleteObject( m_brush );
- DeleteObject( font );
- }
- //---------------------------------------------- CDrawZhePipe --------
- IMPLEMENT_SERIAL(CDrawZhePipe, CDrawObj, 0)
- CDrawZhePipe::CDrawZhePipe():CDrawObj()
- {
- m_clrLine = RGB(0, 255, 0);
- }
- CDrawObj* CDrawZhePipe::Clone(void)
- {
- CDrawZhePipe *pObj = new CDrawZhePipe;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawZhePipe::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- CRect rect = m_rctCurrent;
- COLORREF clrFill = m_clrCurrentBack;
- if ( !bRuning )
- {
- clrFill = m_clrBack;
- rect = m_rect;
- }
- unsigned char red = (unsigned char)(GetRValue(clrFill));
- unsigned char green = (unsigned char)(GetGValue(clrFill));
- unsigned char blue = (unsigned char)(GetBValue(clrFill));
- unsigned char cred, cgreen, cblue;
- int width = abs(rect.Width()/2);
- for ( int i = 0; i<width; i++)
- {
- int crate = abs(rect.Width()/4);
- if ( i<crate )
- {
- cred = (int)(red + i*(255.0-red)*1.0/crate);
- cgreen = (int)(green + i*(255.0-green)*1.0/crate);
- cblue = (int)(blue + i*(255.0-blue)*1.0/crate);
- }
- else
- {
- cred = 510-(int)(red + i*(255.0-red)*1.0/crate);
- cgreen = 510-(int)(green + i*(255.0-green)*1.0/crate);
- cblue = 510-(int)(blue + i*(255.0-blue)*1.0/crate);
- }
- COLORREF color = RGB(cred, cgreen, cblue);
- CRect rct = CRect(rect.left+i, rect.top ,rect.left+i+1, rect.bottom);
- if (rect.left > rect.right )
- rct = CRect(rect.left-i, rect.top ,rect.left-i-1, rect.bottom);
- pDC->FillSolidRect(rct, color);
- }
- int height = abs(rect.Height()/2);
- for ( i = 0; i<height; i++)
- {
- int crate = abs(rect.Height()/4);
- if ( i<crate )
- {
- cred = (int)(red + i*(255.0-red)*1.0/crate);
- cgreen = (int)(green + i*(255.0-green)*1.0/crate);
- cblue = (int)(blue + i*(255.0-blue)*1.0/crate);
- }
- else
- {
- cred = 510-(int)(red + i*(255.0-red)*1.0/crate);
- cgreen = 510-(int)(green + i*(255.0-green)*1.0/crate);
- cblue = 510-(int)(blue + i*(255.0-blue)*1.0/crate);
- }
- COLORREF color = RGB(cred, cgreen, cblue);
- float rate = 1.0*abs(rect.Width())/abs(rect.Height());
- CRect rct = CRect(rect.left+i*rate, rect.top+i ,rect.right, rect.top+i+1);
- if ( rect.left > rect.right )
- {
- rct = CRect(rect.left-i*rate, rect.top+i ,rect.right, rect.top+i+1);
- }
- if ( rect.top > rect.bottom )
- {
- rct = CRect(rect.left+i*rate-1, rect.top-i ,rect.right, rect.top-i+1);
- if ( rect.left > rect.right )
- {
- rct = CRect(rect.left-i*rate, rect.top-i ,rect.right, rect.top-i+1);
- }
- }
- pDC->FillSolidRect(rct, color);
- }
- }
- //---------------------------------------------- CDrawYPipe --------
- IMPLEMENT_SERIAL(CDrawYPipe, CDrawObj, 0)
- CDrawYPipe::CDrawYPipe():CDrawObj()
- {
- m_clrLine = RGB(0, 255, 0);
- }
- CDrawObj* CDrawYPipe::Clone(void)
- {
- CDrawPipe *pObj = new CDrawPipe;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawYPipe::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- CRect rect = m_rctCurrent;
- COLORREF clrFill = m_clrCurrentBack;
- if ( !bRuning )
- {
- clrFill = m_clrBack;
- rect = m_rect;
- }
- unsigned char red = (unsigned char)(GetRValue(clrFill));
- unsigned char green = (unsigned char)(GetGValue(clrFill));
- unsigned char blue = (unsigned char)(GetBValue(clrFill));
- unsigned char cred, cgreen, cblue;
- int width = abs(rect.Width()/2);
- for ( int i = 0; i<width; i++)
- {
- int crate = abs(rect.Width()/4);
- if ( i<crate )
- {
- cred = (int)(red + i*(255.0-red)*1.0/crate);
- cgreen = (int)(green + i*(255.0-green)*1.0/crate);
- cblue = (int)(blue + i*(255.0-blue)*1.0/crate);
- }
- else
- {
- cred = 510-(int)(red + i*(255.0-red)*1.0/crate);
- cgreen = 510-(int)(green + i*(255.0-green)*1.0/crate);
- cblue = 510-(int)(blue + i*(255.0-blue)*1.0/crate);
- }
- COLORREF color = RGB(cred, cgreen, cblue);
- CRect rct = CRect(rect.left+i, rect.top ,rect.left+i+1, rect.bottom);
- if (rect.left > rect.right )
- rct = CRect(rect.left-i, rect.top ,rect.left-i-1, rect.bottom);
- pDC->FillSolidRect(rct, color);
- }
- int middle = (rect.top + rect.bottom)/2;
- int height = abs(rect.Height()/4);
- for ( i = 0; i<height; i++)
- {
- cred = (int)(255 - i*(255.0-red)*1.0/height);
- cgreen = (int)(255 - i*(255.0-green)*1.0/height);
- cblue = (int)(255 - i*(255.0-blue)*1.0/height);
- COLORREF color = RGB(cred, cgreen, cblue);
- float rate = 1.0*abs(rect.Width())/abs(rect.Height());
- CRect rct = CRect(rect.left+abs(rect.Width())/4+i*rate, middle+i ,rect.right, middle+i+1);
- CRect rct1 = CRect(rect.left+abs(rect.Width())/4+i*rate, middle-i ,rect.right, middle-i-1);
- if ( rect.left > rect.right )
- {
- rct = CRect(rect.left-i*rate-abs(rect.Width())/4, middle+i ,rect.right, middle+i+1);
- rct1 = CRect(rect.left-i*rate-abs(rect.Width())/4, middle-i ,rect.right, middle-i-1);
- }
- if ( rect.top > rect.bottom )
- {
- rct = CRect(rect.left+abs(rect.Width())/4+i*rate-1, middle-i ,rect.right, middle-i+1);
- rct1 = CRect(rect.left+abs(rect.Width())/4+i*rate, middle+i ,rect.right, middle+i-1);
- if ( rect.left > rect.right )
- {
- rct = CRect(rect.left-abs(rect.Width())/4-i*rate, middle-i ,rect.right, middle-i+1);
- rct1 = CRect(rect.left-abs(rect.Width())/4-i*rate, middle+i ,rect.right, middle+i-1);
- }
- }
- pDC->FillSolidRect(rct, color);
- pDC->FillSolidRect(rct1, color);
- }
- }
- //---------------------------------------------- CDrawPipe --------
- IMPLEMENT_SERIAL(CDrawPipe, CDrawObj, 0)
- CDrawPipe::CDrawPipe():CDrawObj()
- {
- m_clrLine = RGB(0, 255, 0);
- }
- CDrawObj* CDrawPipe::Clone(void)
- {
- CDrawPipe *pObj = new CDrawPipe;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawPipe::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- if ( !m_bShow && bRuning) return;
- CRect rect = m_rctCurrent;
- COLORREF clrFill = m_clrCurrentBack;
- if ( !bRuning )
- {
- clrFill = m_clrBack;
- rect = m_rect;
- }
- rect.NormalizeRect();
- CRect tmp = rect;
- CGradient gradient;
- if ( rect.Width() < rect.Height() )
- {
- tmp.NormalizeRect();
- tmp.right = (tmp.left+tmp.right)/2+1;
- gradient.HorizontalGradient(pDC, tmp, clrFill, RGB(255, 255, 255));
- tmp = rect;
- tmp.NormalizeRect();
- tmp.left = (tmp.left+tmp.right)/2-1;
- gradient.HorizontalGradient(pDC, tmp, RGB(255, 255, 255), clrFill);
- }
- else
- {
- tmp.NormalizeRect();
- tmp.top = (tmp.top+tmp.bottom)/2-1;
- gradient.VerticalGradient(pDC, tmp, RGB(255, 255, 255), clrFill);
- tmp = rect;
- tmp.NormalizeRect();
- tmp.bottom = (tmp.top+tmp.bottom)/2+1;
- gradient.VerticalGradient(pDC, tmp, clrFill, RGB(255, 255, 255));
- }
- }
- //---------------------------------------------- CDrawBitmap --------
- IMPLEMENT_SERIAL(CDrawBitmap, CDrawObj, 0)
- CDrawBitmap::CDrawBitmap():CDrawObj()
- {
- m_strStaticFile = "home.bmp";
- //m_strStaticFile = "";
- m_strDynFile = "";
- m_bDyn = FALSE;
- m_strDynCondition = "";
- m_bStretch = FALSE;
- m_bUseDnyFile = FALSE;
- m_image = NULL;
- }
- CDrawBitmap::~CDrawBitmap()
- {
- if( m_image )
- {
- delete m_image;
- m_image = NULL;
- }
- }
- CDrawObj* CDrawBitmap::Clone(void)
- {
- CDrawBitmap *pObj = new CDrawBitmap;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_strStaticFile = m_strStaticFile;
- pObj->m_strDynFile = m_strDynFile;
- pObj->m_bDyn = m_bDyn;
- pObj->m_strDynCondition = m_strDynCondition;
- pObj->m_bStretch = m_bStretch;
- pObj->m_bUseDnyFile = m_bUseDnyFile;
- return pObj;
- }
- bool CDrawBitmap::Fresh(CRect &RECT)
- {
- CDrawObj::Fresh(RECT);
- CRealComputer com;
- com.SetFormula(m_strDynCondition);
- m_bUseDnyFile = com.GetResult();
- RECT = m_rect;
- CString sTemp1=m_strStaticFile,sTemp2=m_strDynFile;
- sTemp1 = sTemp1.MakeLower();
- sTemp2 = sTemp2.MakeLower();
- if( -1!=sTemp1.Find( ".bmp" ) || -1!=sTemp2.Find( ".bmp" ) )
- return true;
- else if( -1!=sTemp1.Find( ".png" ) || -1!=sTemp2.Find( ".png" ) )
- return true;
- else if( -1!=sTemp1.Find( ".gif" ) || -1!=sTemp2.Find( ".gif" ) )
- {
- if ( !m_bShow )
- {
- m_bShowtemp = FALSE;
- return true;
- }
- else if( !m_bShowtemp )
- {
- m_bShowtemp = TRUE;
- return true;
- }
- else
- return false;
- }
- else if( -1!=sTemp1.Find( ".jpg" ) || -1!=sTemp2.Find( ".jpg" ) )
- return true;
- return true;
- }
- void CDrawBitmap::Serialize(CArchive& ar)
- {
- CDrawObj::Serialize(ar);
- if(ar.IsStoring())
- {
- ar << m_strStaticFile;
- ar << m_strDynFile;
- ar << m_bDyn;
- ar << m_strDynCondition;
- ar << m_bStretch;
- }
- else
- {
- ar >> m_strStaticFile;
- ar >> m_strDynFile;
- ar >> m_bDyn;
- ar >> m_strDynCondition;
- ar >> m_bStretch;
- }
- }
- void CDrawBitmap::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning)
- {
- CString sTemp1=m_sOldFilePath;
- sTemp1 = sTemp1.MakeLower();
-
- if( -1!=sTemp1.Find( ".gif" ) )
- {
- if( m_image )
- {
- delete m_image;
- m_image = NULL;
- }
- }
- return;
- }
- CRect rect = m_rect;
- rect.NormalizeRect();
- int nX1 = rect.left;
- int nY1 = rect.top;
- int nXX = rect.right - rect.left;
- int nYY = rect.bottom - rect.top;
- char curDir[256];
- strcpy(curDir, g_strDirectory);
- strcat(curDir, "\\");
- strcat(curDir, _BITMAPDIR);
- #if 1
- CString sTemp1=m_strStaticFile,sTemp2=m_strDynFile;
- sTemp1 = sTemp1.MakeLower();
- sTemp2 = sTemp2.MakeLower();
- if( -1!=sTemp1.Find( ".bmp" ) || -1!=sTemp2.Find( ".bmp" ) )
- {
- if ( bRuning && m_bDyn && m_bUseDnyFile)
- DisplayBMP(pDC,nX1,nY1,nXX,nYY,CString(curDir) + m_strDynFile,m_bStretch);
- else
- DisplayBMP(pDC,nX1,nY1,nXX,nYY,CString(curDir) + m_strStaticFile,m_bStretch);
- }
- else if( -1!=sTemp1.Find( ".png" ) || -1!=sTemp2.Find( ".png" ) )
- {
- if ( bRuning && m_bDyn && m_bUseDnyFile)
- DisplayPNG(pDC,nX1,nY1,nXX,nYY,CString(curDir) + m_strDynFile,m_bStretch);
- else
- DisplayPNG(pDC,nX1,nY1,nXX,nYY,CString(curDir) + m_strStaticFile,m_bStretch);
- }
- else if( -1!=sTemp1.Find( ".gif" ) || -1!=sTemp2.Find( ".gif" ) )
- {
- if ( bRuning && m_bDyn && m_bUseDnyFile)
- DisplayGIF(pDC,nX1,nY1,nXX,nYY,CString(curDir) + m_strDynFile,m_bStretch);
- else
- DisplayGIF(pDC,nX1,nY1,nXX,nYY,CString(curDir) + m_strStaticFile,m_bStretch);
- }
- else if( -1!=sTemp1.Find( ".jpg" ) || -1!=sTemp2.Find( ".jpg" ) )
- {
- if ( bRuning && m_bDyn && m_bUseDnyFile)
- DisplayJPG(pDC,nX1,nY1,nXX,nYY,CString(curDir) + m_strDynFile,m_bStretch);
- else
- DisplayJPG(pDC,nX1,nY1,nXX,nYY,CString(curDir) + m_strStaticFile,m_bStretch);
- }
- #else
- if ( bRuning && m_bDyn && m_bUseDnyFile)
- DisplayJPG(pDC,nX1,nY1,nXX,nYY,CString(curDir) + m_strDynFile,m_bStretch);
- else
- DisplayJPG(pDC,nX1,nY1,nXX,nYY,CString(curDir) + m_strStaticFile,m_bStretch);
- #endif
- }
- BOOL CDrawBitmap::DisplayJPG(CDC *pDC, int nX1, int nY1, int nXX, int nYY, CString strJPGFile, BOOL bStretch)
- {
- CString sTemp1=m_sOldFilePath;
- sTemp1 = sTemp1.MakeLower();
-
- if( -1!=sTemp1.Find( ".gif" ) )
- {
- if( m_image )
- {
- delete m_image;
- m_image = NULL;
- }
- }
- GdiplusStartupInput m_gdiplusStartupInput;
- // ULONG_PTR m_pGdiToken;
- wchar_t m_wstrServerName[255] ;
- MultiByteToWideChar(CP_ACP,0,strJPGFile,-1,m_wstrServerName,256);
- Graphics graphics( pDC->m_hDC );
- //wchar_t * p=strJPGFile.AllocSysStrinig();
- Image image( m_wstrServerName, FALSE) ;
- if(bStretch)
- {
- graphics.DrawImage( &image, nX1,nY1,nXX,nYY );
- }
- else
- {
- WORD Width = (WORD)image.GetWidth();
- WORD Height = (WORD)image.GetHeight();
- //Width = min(Width,nXX);
- //Height = min(Height,nYY);
- //graphics.DrawImage( &image, nX1,nY1,Width,Height );
- graphics.DrawImage( &image, nX1,nY1,0,0,nXX,nYY,UnitPixel );
- }
- return TRUE;
- }
- BOOL CDrawBitmap::DisplayBMP(CDC* pDC,int nX1,int nY1,int nXX,int nYY,CString strBMPFile,BOOL bStretch)
- {
- #if 0
- CString sTemp1=m_sOldFilePath;
- sTemp1 = sTemp1.MakeLower();
-
- if( -1!=sTemp1.Find( ".gif" ) )
- {
- if( m_image )
- {
- delete m_image;
- m_image = NULL;
- }
- }
- GdiplusStartupInput m_gdiplusStartupInput;
- // ULONG_PTR m_pGdiToken;
- wchar_t m_wstrServerName[255] ;
- MultiByteToWideChar(CP_ACP,0,strBMPFile,-1,m_wstrServerName,256);
- Graphics graphics( pDC->m_hDC );
- //wchar_t * p=strJPGFile.AllocSysStrinig();
- Image image( m_wstrServerName, FALSE) ;
- if(bStretch)
- {
- graphics.DrawImage( &image, nX1,nY1,nXX,nYY );
- }
- else
- {
- WORD Width = (WORD)image.GetWidth();
- WORD Height = (WORD)image.GetHeight();
- //Width = min(Width,nXX);
- //Height = min(Height,nYY);
- //graphics.DrawImage( &image, nX1,nY1,Width,Height );
- graphics.DrawImage( &image, nX1,nY1,0,0,nXX,nYY,UnitPixel );
- }
- return true;
- #else
- CString sTemp1=m_sOldFilePath;
- sTemp1 = sTemp1.MakeLower();
-
- if( -1!=sTemp1.Find( ".gif" ) )
- {
- if( m_image )
- {
- delete m_image;
- m_image = NULL;
- }
- }
- OFSTRUCT of;
- unsigned fh = OpenFile ((char const*)strBMPFile, &of, OF_READ);
- if(fh==-1) return FALSE;
- DWORD size = (DWORD)(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
- HANDLE hDIBInfo = GlobalAlloc(GMEM_MOVEABLE,size);
- SetStretchBltMode(pDC->m_hDC,HALFTONE);
- BITMAPFILEHEADER bf;
- LPBITMAPINFOHEADER lpbi;
- lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIBInfo);
- _lread(fh,(LPSTR)&bf,sizeof (bf));
- _lread(fh,(LPSTR)lpbi,sizeof(BITMAPINFOHEADER));
- WORD nClrs = (WORD)lpbi->biClrUsed;
- size = ((((lpbi->biWidth*lpbi->biBitCount)+31)&~31)>>3)*lpbi->biHeight;
- if(nClrs==0 && lpbi->biBitCount!=24) nClrs = 1<<lpbi->biBitCount;
- if(lpbi->biClrUsed == 0) lpbi->biClrUsed = (DWORD)nClrs;
- if(lpbi->biSizeImage == 0) lpbi->biSizeImage = size;
- WORD Size = (WORD)lpbi->biSize;
- WORD Width = (WORD)lpbi->biWidth;
- WORD Height = (WORD)lpbi->biHeight;
- WORD ClrUsed = (WORD)lpbi->biClrUsed;
- WORD BitCount = (WORD)lpbi->biBitCount;
- DWORD SizeImage = lpbi->biSizeImage;
- WORD SizeRGB = nClrs*sizeof(RGBQUAD);
- WORD SizeHeader = Size+SizeRGB;
- GlobalUnlock(hDIBInfo);
- hDIBInfo = GlobalReAlloc(hDIBInfo,SizeHeader+SizeImage, 0);
- lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIBInfo);
- _lread(fh,(LPSTR)(lpbi)+Size,SizeRGB);
- if(bf.bfOffBits!=0L) _llseek(fh,bf.bfOffBits,SEEK_SET);
- DWORD ul = SizeImage;
- BYTE *hp = (BYTE *)((LPSTR)lpbi + SizeHeader);
- while(ul>30000L)
- {
- _lread(fh,(LPSTR)hp,30000L);
- ul -= 30000L;
- hp += 30000L;
- }
- _lread(fh,(LPSTR)hp,(WORD)ul);
- _lclose(fh);
- HPALETTE hPalette,hOldPal;
- HANDLE hPalHeader = NULL;
- HDC hDC = pDC->m_hDC;
- LPBITMAPINFOHEADER lpHeader = lpbi;
- WORD wDIBUse = DIB_RGB_COLORS;
- if(ClrUsed)
- {
- WORD size = sizeof(LOGPALETTE) + ClrUsed * sizeof(PALETTEENTRY);
- NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED,size);
- npPal->palVersion = 0x300;
- npPal->palNumEntries = ClrUsed;
- RGBQUAD FAR *lpRGB = (RGBQUAD FAR *)((LPSTR)lpbi + Size);
- for(WORD i=0;i<ClrUsed;i++,lpRGB++)
- {
- npPal->palPalEntry[i].peRed = lpRGB->rgbRed;
- npPal->palPalEntry[i].peGreen = lpRGB->rgbGreen;
- npPal->palPalEntry[i].peBlue = lpRGB->rgbBlue;
- npPal->palPalEntry[i].peFlags = 0;
- }
- hPalette = CreatePalette((LPLOGPALETTE)npPal);
- LocalFree((HANDLE)npPal);
- hOldPal = SelectPalette(hDC,hPalette,FALSE);
- RealizePalette(hDC);
- if(BitCount!=24)
- {
- size = Size+ClrUsed*sizeof(WORD);
- hPalHeader = GlobalAlloc(GMEM_MOVEABLE,size);
- LPBITMAPINFOHEADER lpPalInfo;
- lpPalInfo = (LPBITMAPINFOHEADER)GlobalLock(hPalHeader);
- *lpPalInfo = *lpbi;
- WORD FAR *lpTable = (WORD FAR *)((LPSTR)lpPalInfo + Size);
- for(WORD i=0;i<ClrUsed;i++) *lpTable++ = i;
- GlobalUnlock(hPalHeader);
- lpHeader = (LPBITMAPINFOHEADER) GlobalLock(hPalHeader);
- wDIBUse = DIB_PAL_COLORS;
- }
- }
- HDC hMemDC = CreateCompatibleDC(hDC);
- HBITMAP hDDBitmap = CreateCompatibleBitmap(hDC,Width,Height);
- SetDIBits(hDC,hDDBitmap,0,Height,(LPSTR)lpbi + SizeHeader,
- (LPBITMAPINFO)lpHeader,wDIBUse);
- HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC,hDDBitmap);
- if(bStretch)
- {
- StretchBlt(hDC,nX1,nY1,nXX,nYY,hMemDC,0,0,Width,Height,SRCCOPY);
- }
- else
- {
- Width = min(Width,nXX);
- Height = min(Height,nYY);
- BitBlt(hDC,nX1,nY1,Width,Height,hMemDC,0,0,SRCCOPY);
- }
- SelectObject(hMemDC,hOldBitmap);
- DeleteDC(hMemDC);
- DeleteObject(hDDBitmap);
- if(ClrUsed)
- {
- SelectPalette(hDC,hOldPal,FALSE);
- DeleteObject(hPalette);
- if(BitCount!=24)
- {
- GlobalUnlock(hPalHeader);
- GlobalFree(hPalHeader);
- }
- }
- GlobalUnlock(hDIBInfo);
- GlobalFree(hDIBInfo);
- return TRUE;
- #endif
- }
- BOOL CDrawBitmap::DisplayPNG(CDC* pDC,int nX1,int nY1,int nXX,int nYY,CString strJPGFile,BOOL bStretch)
- {
- CString sTemp1=m_sOldFilePath;
- sTemp1 = sTemp1.MakeLower();
-
- if( -1!=sTemp1.Find( ".gif" ) )
- {
- if( m_image )
- {
- delete m_image;
- m_image = NULL;
- }
- }
- GdiplusStartupInput m_gdiplusStartupInput;
- // ULONG_PTR m_pGdiToken;
- wchar_t m_wstrServerName[255] ;
- MultiByteToWideChar(CP_ACP,0,strJPGFile,-1,m_wstrServerName,256);
- Graphics graphics( pDC->m_hDC );
- //wchar_t * p=strJPGFile.AllocSysStrinig();
- Image image( m_wstrServerName, FALSE) ;
- if(bStretch)
- {
- graphics.DrawImage( &image, nX1,nY1,nXX,nYY );
- }
- else
- {
- WORD Width = (WORD)image.GetWidth();
- WORD Height = (WORD)image.GetHeight();
- //Width = min(Width,nXX);
- //Height = min(Height,nYY);
- //graphics.DrawImage( &image, nX1,nY1,Width,Height );
- graphics.DrawImage( &image, nX1,nY1,0,0,nXX,nYY,UnitPixel );
- }
-
- return true;
- }
- BOOL CDrawBitmap::DisplayGIF(CDC* pDC,int nX1,int nY1,int nXX,int nYY,CString strJPGFile,BOOL bStretch)
- {
- if( m_sOldFilePath!=strJPGFile )
- {
- if( m_image )
- {
- delete m_image;
- m_image = NULL;
- }
- }
- if( m_image==NULL )
- {
- //char curDir[256] = {0};
- ////strcpy(curDir, g_strDirectory);
- //strcat(curDir, ".\\\\");
- //strcat(curDir, _BITMAPDIR);
- //if( m_strStaticFile=="" )//gif 路徑為Bitmap,默認名為StounU.gif
- // m_strStaticFile = "StounU.gif";
- //CString strGifFileName = CString(curDir) + m_strStaticFile;
- m_sOldFilePath = strJPGFile;
- // GDI+
- m_image = new ImageEx(StrToWchar(strJPGFile));
- }
- if( m_image )
- {
- //CRect rect = m_rect;
- //rect.NormalizeRect();
- //int nX1 = rect.left;
- //int nY1 = rect.top;
- //CPoint pt(nX1, nY1);
- CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
- HWND hwnd = m_pView->GetSafeHwnd();//pFrame->m_pActiveView->m_hWnd;
- m_image->InitAnimation(hwnd, CRect(nX1,nY1,nX1+nXX,nY1+nYY),bStretch );
- }
- return true;
- }
- BOOL CDrawBitmap::OnAttrib(CPropertySheet& sheet)
- {
- CBitmapPage page;
-
- page.m_strDynFile = m_strDynFile;
- page.m_strStaticFile = m_strStaticFile;
- page.m_bStretch = m_bStretch;
- page.m_bDyn = m_bDyn;
- page.m_strDynCondition = m_strDynCondition;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_strDynFile = page.m_strDynFile;
- m_strStaticFile = page.m_strStaticFile;
- m_bStretch = page.m_bStretch;
- m_bDyn = page.m_bDyn;
- m_strDynCondition = page.m_strDynCondition;
- return TRUE;
- }
- return FALSE;
- }
- //---------------------------------------------- CDrawGif --------
- IMPLEMENT_SERIAL(CDrawGif, CDrawObj, 0)
- CDrawGif::CDrawGif():CDrawObj()
- {
- //m_strStaticFile = "statusAlarm.gif";
- m_strStaticFile = "";
- m_strDynFile = "";
- m_bDyn = FALSE;
- m_strDynCondition = "";
- m_bStretch = TRUE;
- m_bUseDnyFile = FALSE;
- //char curDir[256] = {0};
- ////strcpy(curDir, g_strDirectory);
- //strcat(curDir, ".\\\\");
- //strcat(curDir, _BITMAPDIR);
- //CString strGifFileName = CString(curDir) + m_strStaticFile;
- // GDI+
- m_image = NULL;
- }
- CDrawGif::~CDrawGif()
- {
- if( m_image )
- {
- delete m_image;
- m_image = NULL;
- }
- }
- CDrawObj* CDrawGif::Clone(void)
- {
- CDrawGif *pObj = new CDrawGif;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_strStaticFile = m_strStaticFile;
- pObj->m_strDynFile = m_strDynFile;
- pObj->m_bDyn = m_bDyn;
- pObj->m_strDynCondition = m_strDynCondition;
- pObj->m_bStretch = m_bStretch;
- pObj->m_bUseDnyFile = m_bUseDnyFile;
- return pObj;
- }
- bool CDrawGif::Fresh(CRect &RECT)
- {
- CDrawObj::Fresh(RECT);
- CRealComputer com;
- com.SetFormula(m_strDynCondition);
- m_bUseDnyFile = com.GetResult();
- //this->Invalidate( );
- //if( m_image )
- //{
- // CRect rect = m_rect;
- // rect.NormalizeRect();
- // int nX1 = rect.left;
- // int nY1 = rect.top;
- // CPoint pt(nX1, nY1);
- // CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
- // HWND hwnd = pFrame->m_pActiveView->m_hWnd;
- // m_image->InitAnimation(hwnd, pt);
- //}
- RECT = m_rect;
- return false;
- }
- void CDrawGif::Serialize(CArchive& ar)
- {
- CDrawObj::Serialize(ar);
- if(ar.IsStoring())
- {
- ar << m_strStaticFile;
- ar << m_strDynFile;
- ar << m_bDyn;
- ar << m_strDynCondition;
- ar << m_bStretch;
- }
- else
- {
- ar >> m_strStaticFile;
- ar >> m_strDynFile;
- ar >> m_bDyn;
- ar >> m_strDynCondition;
- ar >> m_bStretch;
- }
- }
- void CDrawGif::Draw(CDC* pDC)
- {
- if( m_image==NULL )
- {
- char curDir[256] = {0};
- //strcpy(curDir, g_strDirectory);
- strcat(curDir, ".\\\\");
- strcat(curDir, _BITMAPDIR);
- if( m_strStaticFile=="" )//gif 路徑為Bitmap,默認名為StounU.gif
- m_strStaticFile = "StounU.gif";
- CString strGifFileName = CString(curDir) + m_strStaticFile;
- // GDI+
- m_image = new ImageEx(StrToWchar(strGifFileName));
- }
- if( m_image )
- {
- CRect rect = m_rect;
- rect.NormalizeRect();
- int nX1 = rect.left;
- int nY1 = rect.top;
- CPoint pt(nX1, nY1);
- CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
- HWND hwnd = pFrame->m_pActiveView->m_hWnd;
- m_image->InitAnimation(hwnd, pt);
- }
- }
- BOOL CDrawGif::OnAttrib(CPropertySheet& sheet)
- {
- CBitmapPage page;
-
- page.m_strDynFile = m_strDynFile;
- page.m_strStaticFile = m_strStaticFile;
- page.m_bStretch = m_bStretch;
- page.m_bDyn = m_bDyn;
- page.m_strDynCondition = m_strDynCondition;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_strDynFile = page.m_strDynFile;
- m_strStaticFile = page.m_strStaticFile;
- m_bStretch = page.m_bStretch;
- m_bDyn = page.m_bDyn;
- m_strDynCondition = page.m_strDynCondition;
- char curDir[256];
- strcpy(curDir, g_strDirectory);
- strcat(curDir, "\\");
- strcat(curDir, _BITMAPDIR);
- CString strGifFileName = CString(curDir) + m_strStaticFile;
- m_image->FromFile(StrToWchar(strGifFileName));
- CRect rect = m_rect;
- rect.NormalizeRect();
- int nX1 = rect.left;
- int nY1 = rect.top;
- CPoint pt(nX1, nY1);
- CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
- HWND hwnd = pFrame->m_pActiveView->m_hWnd;
- m_image->InitAnimation(hwnd, pt);
- return TRUE;
- }
- return FALSE;
- }
- //---------------------------------------------- CDrawTransfer --------
- IMPLEMENT_SERIAL(CDrawTransfer, CDrawObj, 0)
- CDrawTransfer::CDrawTransfer():CDrawObj()
- {
- m_clrLine = RGB(0, 255, 0);
- }
- CDrawObj* CDrawTransfer::Clone(void)
- {
- CDrawTransfer *pObj = new CDrawTransfer;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawTransfer::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- COLORREF clrLine = m_clrLine;
- COLORREF clrBack = m_clrBack;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrLine = m_clrCurrentLine;
- clrBack = m_clrCurrentBack;
- rect = m_rctCurrent;
- }
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
- CPen* pOldPen = pDC->SelectObject(&pen);
- rect.NormalizeRect();
- int x = (rect.left + rect.right)/2;
- int y = (rect.top + rect.bottom)/2;
- int r = min(rect.Width(), rect.Height()) * 0.25;
-
- DrawCircle(pDC, CPoint(x, y-0.7*r), r);
- CPen pen1( GetPenStyle(m_strLineType), m_nLineWidth, clrBack);
- pDC->SelectObject(&pen1);
- pDC->SelectObject(&pen1);
- DrawCircle(pDC, CPoint(x, y+0.7*r), r);
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- DeleteObject( pen1 );
- }
- void CDrawTransfer::DrawCircle(CDC *pDC, POINT origin, int radius)
- {
- pDC->MoveTo(origin.x + radius, origin.y);
- pDC->AngleArc(origin.x, origin.y, radius, 0, 360);
- }
- //---------------------------------------------- CDrawButton ------
- IMPLEMENT_SERIAL(CDrawButton, CDrawObj, 0)
- CDrawButton::CDrawButton():CDrawObj()
- {
- m_clrFore = RGB(255, 255, 255);
- m_clrBack = RGB(255, 128, 0);
- m_strCaption = "按钮";
- m_clrCurrentBack = m_clrBack;
- }
- CDrawObj* CDrawButton::Clone(void)
- {
- CDrawButton *pObj = new CDrawButton;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawButton::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- if ( !m_bShow && bRuning) return;
- CRect rect = m_rctCurrent;
- COLORREF color = m_clrCurrentBack;
- if (!bRuning)
- {
- rect = m_rect;
- color = m_clrBack;
- }
- pDC->FillSolidRect(rect, color);
-
- int Width = 2;
- int nR0 = GetRValue(color);
- int nG0 = GetGValue(color);
- int nB0 = GetBValue(color);
- int nRMin = nR0/2;
- int nGMin = nG0/2;
- int nBMin = nB0/2;
- int nRMax = min(nR0*2,255);
- int nGMax = min(nG0*2,255);
- int nBMax = min(nB0*2,255);
- for(int i=0;i<Width;i++)
- {
- int n = i;
- int nR1 = (n*nR0+(Width-n)*nRMax) / Width;
- int nG1 = (n*nG0+(Width-n)*nGMax) / Width;
- int nB1 = (n*nB0+(Width-n)*nBMax) / Width;
- COLORREF clrLight = RGB(nR1,nG1,nB1);
- int nR2 = (n*nR0+(Width-n)*nRMin) / Width;
- int nG2 = (n*nG0+(Width-n)*nGMin) / Width;
- int nB2 = (n*nB0+(Width-n)*nBMin) / Width;
- COLORREF clrDark = RGB(nR2,nG2,nB2);
- pDC->Draw3dRect(rect,clrLight,clrDark);
- rect.DeflateRect(1,1,1,1);
- }
- DrawText(pDC);
- }
- //---------------------------------------------- CDrawDatabox -----
- IMPLEMENT_SERIAL(CDrawDatabox, CDrawObj, 0)
- CDrawDatabox::CDrawDatabox():CDrawObj()
- {
- m_clrLine = RGB(0,0,0);
- m_clrBack = RGB(255,0,0);//RGB(255,128,0);
- m_clrFore = RGB(0,0,0);
- m_clrFill = RGB(255,0,0);
- m_nFillMode = 0;
- m_nFormat = 1;
- m_bVariant = true;
- }
- CDrawObj* CDrawDatabox::Clone(void)
- {
- CDrawDatabox *pObj = new CDrawDatabox;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_nFormat = m_nFormat;
- pObj->m_nFillMode = m_nFillMode;
- return pObj;
- }
- bool CDrawDatabox::Fresh(CRect &RECT)
- {
- CDrawObj::Fresh(RECT);
- //InvalidateRect( g_pMainFrm->GetSafeHwnd(),m_rctCurrent,false );
- //Invalidate( );
- RECT = m_rect;
- return true;
- }
- void CDrawDatabox::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- if ( !m_bShow && bRuning) return;
- CRect rectRgn = m_rctCurrent;
- COLORREF clrPen = m_clrCurrentLine;
- COLORREF clrBrush = m_clrCurrentBack;
- COLORREF clrText = m_clrCurrentFore;
- if (!bRuning)
- {
- rectRgn = m_rect;
- clrPen = m_clrLine;
- clrBrush = m_clrBack;
- clrText = m_clrFore;
- }
- CString value = "";
- if (!m_bVariant)
- value = m_strCaption;
- else
- {
- int nValue = 0;
- switch(m_nFormat)
- {
- case 0:
- nValue = (int)m_fCurrentValue;
- value.Format("%d", nValue);
- break;
- case 1:
- value.Format("%.1f",m_fCurrentValue);
- break;
- case 2:
- value.Format("%.2f",m_fCurrentValue);
- break;
- case 3:
- value.Format("%.3f",m_fCurrentValue);
- break;
- }
- }
- CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrPen);
- CPen* pOldPen = pDC->SelectObject(&pen);
- CBrush brush;
- CBrush* pOldBrush;
- if( m_bVariant )
- {
- int nRet = pVariantsManager->VarIsAlarm( m_strCaption );
- if( nRet==1 && bRuning )//报警
- {
- brush.CreateSolidBrush(clrBrush);
- pOldBrush = pDC->SelectObject(&brush);
- }
- else
- {
- LOGBRUSH logBrush = GetBrush();
- brush.CreateBrushIndirect(&logBrush);
- pOldBrush = pDC->SelectObject(&brush);
- }
- }
- else
- {
- LOGBRUSH logBrush = GetBrush();
- brush.CreateBrushIndirect(&logBrush);
- pOldBrush = pDC->SelectObject(&brush);
- }
-
- pDC->Rectangle(rectRgn);
- //pDC->SelectObject(pOldPen);
- //pDC->SelectObject(pOldBrush);
- rectRgn.NormalizeRect();
- pDC->LPtoDP(&rectRgn);
- CRgn rgn;
- rgn.CreateRectRgnIndirect(&rectRgn);
- pDC->SelectClipRgn(&rgn);
- DrawText(pDC, value);
- pDC->SelectClipRgn(NULL);
- DeleteObject( pen );
- DeleteObject( brush );
- DeleteObject( rgn );
- }
- void CDrawDatabox::DrawText(CDC* pDC,CString& strText)
- {
- CRect rect = m_rctCurrent;
- COLORREF txtColor = m_clrCurrentFore;
- if (!bRuning)
- {
- rect = m_rect;
- txtColor = m_clrFore;
- }
- int nX0 = (rect.left+rect.right) / 2;
- int nY0 = (rect.top+rect.bottom) / 2;
- CFont font;
- font.CreateFontIndirect(&m_logfont);
- CFont* pOldFont = pDC->SelectObject(&font);
- CSize sizeText = pDC->GetTextExtent(strText);
- int nInterval = sizeText.cy / 2;
- int nYText = nY0 - nInterval + 1;
- int nXText;
- pDC->SetTextAlign(TA_CENTER|TA_TOP);
- nXText = nX0;
- pDC->SetTextColor(txtColor);
- pDC->TextOut(nXText,nYText,strText);
- pDC->SelectObject(pOldFont);
- DeleteObject( font );
- }
- void CDrawDatabox::Serialize(CArchive& ar)
- {
- CDrawObj::Serialize(ar);
- if(ar.IsStoring())
- {
- ar << m_nFormat;
- }
- else
- {
- ar >> m_nFormat;
- }
- }
- BOOL CDrawDatabox::OnAttrib(CPropertySheet& sheet)
- {
- CDataPage page;
- page.m_nFormat = m_nFormat;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_nFormat = page.m_nFormat;
- return TRUE;
- }
- return FALSE;
- }
- //---------------------------------------------- CDrawWatch -----
- IMPLEMENT_SERIAL(CDrawWatch, CDrawObj, 0)
- CDrawWatch::CDrawWatch():CDrawObj()
- {
- m_clrLine = RGB(255,0,0);
- m_clrBack = RGB(192,192,192);
- m_clrFore = RGB(0,0,0);
- m_nLineWidth = 1;
- m_nLowwer = 0;
- m_nUpper = 1000;
- m_strVar = "";
- }
- CDrawObj* CDrawWatch::Clone(void)
- {
- CDrawWatch *pObj = new CDrawWatch;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawWatch::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- CRect rectRgn = m_rctCurrent;
- COLORREF clrPen = m_clrCurrentLine;
- COLORREF clrBrush = m_clrCurrentBack;
- COLORREF clrText = m_clrCurrentFore;
- if (!bRuning)
- {
- rectRgn = m_rect;
- clrPen = m_clrLine;
- clrBrush = m_clrBack;
- clrText = m_clrFore;
- }
- if (!m_bVariant)
- m_strCurrentCaption = m_strCaption;
-
- rectRgn.NormalizeRect();
- CBrush brush(clrText);
- CBrush *prebrush = pDC->SelectObject(&brush);
- pDC->FillSolidRect(rectRgn, clrBrush);
- int top = rectRgn.top+10;
- int middle = rectRgn.bottom - 40;
- if ( middle < top ) middle = top;
- CRect rectPie = CRect(rectRgn.left + 10, top, rectRgn.right - 10, top + 2*(middle-top));
- CPoint s = CPoint(rectRgn.right - 10, middle);
- CPoint e = CPoint(rectRgn.left + 10, middle);
- INT HorzRes = pDC->GetDeviceCaps(HORZRES);
- INT VertRes = pDC->GetDeviceCaps(VERTRES);
- INT VertSize = pDC->GetDeviceCaps(VERTSIZE);
- INT HorzSize = pDC->GetDeviceCaps(HORZSIZE);
- m_lAspectN = ((LONG)VertRes * 100) / (LONG)VertSize;
- m_lAspectD = ((LONG)HorzRes * 100) / (LONG)HorzSize;
- // 画指针
- CPen pen( GetPenStyle(m_strLineType), m_nLineWidth, m_clrLine );
- CPen* pOldPen = pDC->SelectObject(&pen);
- pDC->MoveTo(rectPie.CenterPoint());
- // 计算指针位置
- rectPie.DeflateRect(5,5,5,5);
- CRgn rgn;
- rgn.CreateEllipticRgnIndirect( rectPie );
- float angle = 180-180*(m_fCurrentValue-m_nLowwer)/(m_nUpper-m_nLowwer);
- int bLeft = 1;
- if ( angle<90 ) bLeft = -1;
- CPoint lastPoint;
- int clockRadius = min(m_rect.Width()/2 - 10 , m_rect.Height() - 50) - 10;
- lastPoint.x = rectPie.CenterPoint().x + clockRadius*cos(angle/180*PI);
- lastPoint.y = rectPie.CenterPoint().y - clockRadius*sin(angle/180*PI);
- pDC->LineTo(lastPoint);
- pDC->SelectObject(pOldPen);
- pDC->DrawEdge(&rectRgn,BDR_RAISEDOUTER,BF_RECT);
- rectRgn.DeflateRect(1,1);
- pDC->DrawEdge(rectRgn, BDR_RAISEDOUTER, BF_RECT);
- rectRgn.left = rectRgn.left+5;
- rectRgn.right = rectRgn.right-5;
- rectRgn.top = rectRgn.top+5;
- rectRgn.bottom = rectRgn.bottom-35;
- pDC->DrawEdge(&rectRgn,BDR_SUNKENOUTER,BF_RECT);
- pDC->SelectObject(prebrush);
- pDC->SelectObject(pOldPen);
- //DrawFace(pDC);
- DeleteObject( pen );
- DeleteObject( brush );
- DeleteObject( rgn );
- }
- void CDrawWatch::DrawFace(CDC* pDC)
- {
- INT i;
- RECT tRect;
- tagPOINT clockCenter;
- char c[5] = {0};
- int clockRadius = min(m_rect.Width()/2 - 10 , m_rect.Height() - 50);
- clockCenter.y = m_rect.bottom - 20;
- clockCenter.x = m_rect.left + m_rect.Width()/2;
- for (i=0; i < 31; i++)
- {
- tRect.top = (INT)(((LONG)(CirTab[i].cos) * clockRadius) / CLKSCALE + clockCenter.y - 20);
- tRect.left = (INT)(((LONG)(CirTab[i].sin) * clockRadius) / CLKSCALE + clockCenter.x);
- if (i % 5)
- {
- tRect.right = tRect.left + 2;
- tRect.bottom = tRect.top + 2;
- pDC->FillSolidRect(&tRect, RGB(255,0,0));
- }
- else
- {
- tRect.right = tRect.left + 2;
- tRect.bottom = tRect.top + 2;
- if((i / 5) == 0)
- _itoa(m_nLowwer, c , 10);
- else
- _itoa((m_nUpper - m_nLowwer) * i / 30, c , 10);
-
- pDC->SetTextColor(m_clrFore);
- pDC->TextOut(tRect.left-1,tRect.top-2,c,(int)strlen(c));
- }
- }
- }
- void CDrawWatch::DrawText(CDC* pDC,CString& strText)
- {
- CRect rect = m_rctCurrent;
- COLORREF txtColor = m_clrCurrentFore;
- if (!bRuning)
- {
- rect = m_rect;
- txtColor = m_clrFore;
- }
- int nX0 = (rect.left+rect.right) / 2;
- int nY0 = (rect.top+rect.bottom) / 2;
- CFont font;
- font.CreateFontIndirect(&m_logfont);
- CFont* pOldFont = pDC->SelectObject(&font);
- CSize sizeText = pDC->GetTextExtent(strText);
- int nInterval = sizeText.cy / 2;
- int nYText = nY0 - nInterval + 1;
- int nXText;
- pDC->SetTextAlign(TA_CENTER|TA_TOP);
- nXText = nX0;
- pDC->SetTextColor(txtColor);
- pDC->TextOut(nXText,nYText,strText);
- pDC->SelectObject(pOldFont);
- DeleteObject( font );
- }
- void CDrawWatch::Serialize(CArchive& ar)
- {
- CDrawObj::Serialize(ar);
- if(ar.IsStoring())
- {
- ar << m_nLowwer;
- ar << m_nUpper;
- ar << m_strVar;
- }
- else
- {
- ar >> m_nLowwer;
- ar >> m_nUpper;
- ar >> m_strVar;
- }
- }
- BOOL CDrawWatch::OnAttrib(CPropertySheet& sheet)
- {
- CWatchPage page;
- page.m_nLowwer = m_nLowwer;
- page.m_nUpper = m_nUpper;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_nLowwer = page.m_nLowwer;
- m_nUpper = page.m_nUpper;
- return TRUE;
- }
- return FALSE;
- }
- //---------------------------------------------- CDrawSingleBar -----
- IMPLEMENT_SERIAL(CDrawSingleBar, CDrawObj, 0)
- CDrawSingleBar::CDrawSingleBar():CDrawObj()
- {
- m_clrLine = RGB(0,0,64);
- m_clrBack = RGB(192,192,192);
- m_clrFore = RGB(255,0,0);
- m_nLineWidth = 2;
- m_nLowwer = 0;
- m_nUpper = 100;
- }
- CDrawObj* CDrawSingleBar::Clone(void)
- {
- CDrawSingleBar *pObj = new CDrawSingleBar;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDrawSingleBar::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- CRect rectRgn = m_rctCurrent;
- COLORREF clrPen = m_clrCurrentLine;
- COLORREF clrBrush = m_clrCurrentBack;
- COLORREF clrText = m_clrCurrentFore;
- if (!bRuning)
- {
- rectRgn = m_rect;
- clrPen = m_clrLine;
- clrBrush = m_clrBack;
- clrText = m_clrFore;
- }
- if (!m_bVariant)
- m_strCurrentCaption = m_strCaption;
-
- rectRgn.NormalizeRect();
- CBrush brush(clrText);
- CBrush *prebrush = pDC->SelectObject(&brush);
- pDC->FillSolidRect(rectRgn, clrBrush);
-
- pDC->DrawEdge(&rectRgn,BDR_RAISEDOUTER,BF_RECT);
- CRect kedu = rectRgn;
- kedu.left += 3;
- kedu.right = kedu.left + 5;
- kedu.top += 4;
- kedu.bottom -= 5;
- DrawVKedu(pDC, kedu, 50, m_clrLine);
-
- rectRgn.left = rectRgn.left+10;
- rectRgn.right = rectRgn.right-4;
- rectRgn.top = rectRgn.top+4;
- rectRgn.bottom = rectRgn.bottom-4;
- pDC->DrawEdge(&rectRgn,BDR_SUNKENOUTER,BF_RECT);
- // 画值
- rectRgn.NormalizeRect();
- rectRgn.left = rectRgn.left+3;
- rectRgn.right = rectRgn.right-3;
- float rate = (m_fCurrentValue-m_nLowwer)/(m_nUpper-m_nLowwer);
- rectRgn.top = rectRgn.top+ rectRgn.Height()*rate;
- rectRgn.bottom = rectRgn.bottom-3;
- pDC->FillSolidRect(rectRgn, clrText);
- pDC->SelectObject(prebrush);
- DeleteObject( brush );
- }
- void CDrawSingleBar::DrawText(CDC* pDC,CString& strText)
- {
- CRect rect = m_rctCurrent;
- COLORREF txtColor = m_clrCurrentFore;
- if (!bRuning)
- {
- rect = m_rect;
- txtColor = m_clrFore;
- }
- int nX0 = (rect.left+rect.right) / 2;
- int nY0 = (rect.top+rect.bottom) / 2;
- CFont font;
- font.CreateFontIndirect(&m_logfont);
- CFont* pOldFont = pDC->SelectObject(&font);
- CSize sizeText = pDC->GetTextExtent(strText);
- int nInterval = sizeText.cy / 2;
- int nYText = nY0 - nInterval + 1;
- int nXText;
- pDC->SetTextAlign(TA_CENTER|TA_TOP);
- nXText = nX0;
- pDC->SetTextColor(txtColor);
- pDC->TextOut(nXText,nYText,strText);
- pDC->SelectObject(pOldFont);
- DeleteObject( font );
- }
- BOOL CDrawSingleBar::OnAttrib(CPropertySheet& sheet)
- {
- CSingleBarPage page;
- page.m_nLower = m_nLowwer;
- page.m_nUpper = m_nUpper;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_nLowwer = page.m_nLower;
- m_nUpper = page.m_nUpper;
- return TRUE;
- }
- return FALSE;
- }
- //---------------------------------------------- CDraw3dCircle ----
- IMPLEMENT_SERIAL(CDraw3dCircle, CDrawObj, 0)
- CDraw3dCircle::CDraw3dCircle()
- {
- m_clrFore = RGB(0, 255, 0);
- m_clrBack = RGB(0, 128, 0);
- m_clrLine = RGB( 255,255,255 );
- //m_clrCurrentLine = RGB( 255,255,255 );
- }
- CDrawObj* CDraw3dCircle::Clone(void)
- {
- CDraw3dCircle *pObj = new CDraw3dCircle;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- return pObj;
- }
- void CDraw3dCircle::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- if ( !m_bShow && bRuning) return;
- COLORREF clrPen = m_clrLine;
- CRect rect = m_rctCurrent;
- COLORREF color = m_clrCurrentBack;
- if (!bRuning)
- {
- rect = m_rect;
- color = m_clrBack;
- }
- rect.NormalizeRect();
- int nX0 = (rect.left+rect.right)/2;
- int nY0 = (rect.top+rect.bottom)/2;
- int nRadius = min(rect.Width()/2,rect.Height()/2);
- rect = CRect(nX0-nRadius, nY0-nRadius, nX0+nRadius, nY0+nRadius);
- CBrush brush;
- brush.CreateSolidBrush(color);
- pDC->SelectObject(&brush);
- CPen framePen;
- framePen.CreatePen(PS_NULL, m_nLineWidth ,m_clrLine);
- pDC->SelectObject(&framePen);
- pDC->Ellipse(rect);
- CPen arcpen;
- arcpen.CreatePen(PS_SOLID,2,m_clrCurrentLine);//RGB(255,255,255));
- pDC->SelectObject(&arcpen);
- pDC->Arc(CRect(nX0-nRadius/2, nY0-nRadius/2, nX0+nRadius/2, nY0+nRadius/2),
- CPoint(nX0, nY0-nRadius/2),CPoint(nX0-nRadius/2, nY0));
- DeleteObject( arcpen );
- DeleteObject( brush );
- }
- //---------------------------------------------- CDrawBar -------
- IMPLEMENT_SERIAL(CDrawBar, CDrawObj, 0)
- CDrawBar::CDrawBar():CDrawObj()
- {
- m_clrBar1 = RGB(255, 0, 0);
- m_clrBar2 = RGB(0, 255, 0);
- m_clrBar3 = RGB(0, 0, 255);
- m_nLowwer = 0;
- m_nUpper = 200;
- m_strVar1 = "";
- m_strVar2 = "";
- m_strVar3 = "";
- m_nValue1 = 0;
- m_nValue2 = 0;
- m_nValue3 = 0;
- m_clrFill = RGB(255,255,255);
- m_nFillMode = 1;
- }
- CDrawObj* CDrawBar::Clone(void)
- {
- CDrawBar *pObj = new CDrawBar;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_clrBar1 = m_clrBar1;
- pObj->m_clrBar2 = m_clrBar2;
- pObj->m_clrBar3 = m_clrBar3;
- pObj->m_nLowwer = m_nLowwer;
- pObj->m_nUpper = m_nUpper;
- pObj->m_strVar1 = m_strVar1;
- pObj->m_strVar2 = m_strVar2;
- pObj->m_strVar3 = m_strVar3;
- return pObj;
- }
- void CDrawBar::DrawBar(CDC* pDC,int data,int x1,int x2,COLORREF clrBar)
- {
- CRect rect = m_rect;
- rect.NormalizeRect();
- float rate = (1.0*(data-m_nLowwer)) / (m_nUpper-m_nLowwer);
- int y1 = rect.bottom - int(rect.Height()*rate);
- y1 = max(rect.top,y1);
- y1 = min(rect.bottom,y1);
- pDC->FillSolidRect(x1,y1,x2-x1,rect.bottom-y1,clrBar);
- }
- void CDrawBar::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- CRect rect = m_rect;
- rect.NormalizeRect();
- int width = rect.Width();
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
- if ( m_nFillMode < 8 )
- {
- pDC->Rectangle(rect);
- }
- int num = GetBarNum();
- int barWidth = width;
- if (num != 0)
- {
- barWidth = width/(num*2 + 1);
- }
- int hadDraw = 0;
- // 画刻度
- CPen pen(PS_SOLID, 1, RGB(255, 255, 255));
- CPen* pOldPen = pDC->SelectObject(&pen);
- pDC->MoveTo(rect.left, rect.top);
- pDC->LineTo(rect.left, rect.bottom);
- pDC->LineTo(rect.right, rect.bottom);
- pDC->LineTo(rect.right, rect.top);
- pDC->LineTo(rect.left, rect.top);
- pDC->SelectObject(pOldPen);
- if (bRuning)
- {
- if (!m_strVar1.IsEmpty())
- {
- int left = rect.left + barWidth;
- int right = rect.left + barWidth*2;
- DrawBar(pDC, m_nValue1, left, right, m_clrBar1);
- hadDraw++;
- }
- if (!m_strVar2.IsEmpty())
- {
- int left = rect.left + barWidth + hadDraw*barWidth*2;
- int right = rect.left + barWidth*2 + hadDraw*barWidth*2;
- DrawBar(pDC, m_nValue2, left, right, m_clrBar2);
- hadDraw++;
- }
- if (!m_strVar3.IsEmpty())
- {
- int left = rect.left + barWidth + hadDraw*barWidth*2;
- int right = rect.left + barWidth*2 + hadDraw*barWidth*2;
- DrawBar(pDC, m_nValue3, left, right, m_clrBar3);
- }
- }
- else
- {
- DrawBar(pDC, 50, rect.left+width/7, rect.left+width/7*2, m_clrBar1);
- DrawBar(pDC, 100, rect.left+width/7*3, rect.left+width/7*4, m_clrBar2);
- DrawBar(pDC, 150, rect.left+width/7*5, rect.left+width/7*6, m_clrBar3);
- }
- // 网格
- CPen penGrid(PS_DOT, 1, RGB(128, 128, 128));
- pOldPen = pDC->SelectObject(&penGrid);
- for (int i=1; i<5; i++)
- {
- pDC->MoveTo(rect.left, rect.top+rect.Height()/5*i);
- pDC->LineTo(rect.right, rect.top+rect.Height()/5*i);
- }
- pDC->SelectObject(pOldPen);
- DeleteObject( pen );
- DeleteObject( penGrid );
- DeleteObject( m_brush );
- }
- void CDrawBar::Serialize(CArchive& ar)
- {
- CDrawObj::Serialize(ar);
- if(ar.IsStoring())
- {
- ar << m_clrBar1;
- ar << m_clrBar2;
- ar << m_clrBar3;
- ar << m_nLowwer;
- ar << m_nUpper;
- ar << m_strVar1;
- ar << m_strVar2;
- ar << m_strVar3;
- }
- else
- {
- ar >> m_clrBar1;
- ar >> m_clrBar2;
- ar >> m_clrBar3;
- ar >> m_nLowwer;
- ar >> m_nUpper;
- ar >> m_strVar1;
- ar >> m_strVar2;
- ar >> m_strVar3;
- }
- }
- BOOL CDrawBar::OnAttrib(CPropertySheet& sheet)
- {
- CBarPage page;
- page.m_nLowwer = m_nLowwer;
- page.m_nUpper = m_nUpper;
- page.m_strVar1 = m_strVar1;
- page.m_strVar2 = m_strVar2;
- page.m_strVar3 = m_strVar3;
- page.m_clrBar1 = m_clrBar1;
- page.m_clrBar2 = m_clrBar2;
- page.m_clrBar3 = m_clrBar3;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_nLowwer = page.m_nLowwer;
- m_nUpper = page.m_nUpper;
- m_strVar1 = page.m_strVar1;
- m_strVar2 = page.m_strVar2;
- m_strVar3 = page.m_strVar3;
- m_clrBar1 = page.m_clrBar1;
- m_clrBar2 = page.m_clrBar2;
- m_clrBar3 = page.m_clrBar3;
- return TRUE;
- }
- return FALSE;
- }
- bool CDrawBar::Fresh(CRect &RECT)
- {
- if ( !m_strVar1.IsEmpty() )
- {
- int nValue = (int) pVariantsManager->GetAnalogValue(m_strVar1);
- if( nValue == -1 ) return true;
- m_nValue1 = (int) pVariantsManager->GetAnalogValue(m_strVar1);
- }
- if ( !m_strVar2.IsEmpty() )
- {
- int nValue = (int) pVariantsManager->GetAnalogValue(m_strVar2);
- if( nValue == -1 ) return true;
- m_nValue2 = (int) pVariantsManager->GetAnalogValue(m_strVar2);
- }
- if ( !m_strVar3.IsEmpty() )
- {
- int nValue = (int) pVariantsManager->GetAnalogValue(m_strVar3);
- if( nValue == -1 ) return true;
- m_nValue3 = (int) pVariantsManager->GetAnalogValue(m_strVar3);
- }
- RECT = m_rect;
- return true;
- }
- int CDrawBar::GetBarNum()
- {
- int num = 0;
- if ( !m_strVar1.IsEmpty() )
- {
- num++;
- }
- if ( !m_strVar2.IsEmpty() )
- {
- num++;
- }
- if ( !m_strVar3.IsEmpty() )
- {
- num++;
- }
- return num;
- }
- //---------------------------------------------- CDrawCurve -------
- IMPLEMENT_SERIAL(CDrawCurve, CDrawObj, 0)
- CDrawCurve::CDrawCurve():CDrawObj()
- {
- m_clrFore = RGB(0, 0, 0);
- //m_clrFill = RGB(0, 0, 255);
- //m_clrLine = RGB(0, 0, 255); // 线色
- m_clrBack = RGB(64,128,128);
- //m_clrCurrentFore = RGB(0, 0, 255);
- //m_clrCurrentBack = RGB(0, 0, 255);
- //m_clrCurrentLine = RGB(0, 0, 255);
- m_clrFill = RGB(255,255,255);
- m_clrCurve1 = RGB(255, 0, 0);
- m_clrCurve2 = RGB(0, 255, 0);
- m_clrCurve3 = RGB(0, 0, 255);
- m_clrLine = RGB(0,0,0);
- m_nLowwer = 0;
- m_nUpper = 200;
- m_strVar1 = "";
- m_strVar2 = "";
- m_strVar3 = "";
- m_nFillMode = 1;
- m_fValue1 = 0.0;
- m_fValue2 = 0.0;
- m_fValue3 = 0.0;
- for (int i=0; i<60; i++)
- {
- m_nValue1[i] = 0;
- m_nValue2[i] = 0;
- m_nValue3[i] = 0;
- }
- }
- CDrawObj* CDrawCurve::Clone(void)
- {
- CDrawCurve *pObj = new CDrawCurve;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_clrCurve1 = m_clrCurve1;
- pObj->m_clrCurve2 = m_clrCurve2;
- pObj->m_clrCurve3 = m_clrCurve3;
- pObj->m_nLowwer = m_nLowwer;
- pObj->m_nUpper = m_nUpper;
- pObj->m_strVar1 = m_strVar1;
- pObj->m_strVar2 = m_strVar2;
- pObj->m_strVar3 = m_strVar3;
- return pObj;
- }
- void CDrawCurve::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- CRect rect = m_rect;
- rect.NormalizeRect();
- CString sText;
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
- if ( m_nFillMode < 8 )
- {
- pDC->Rectangle(rect);
- }
- DeleteObject( m_brush );
-
- // 边框
- pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT);
- CRect inner;
- inner.left = rect.left+40;
- inner.right = rect.right-10;
- inner.top = rect.top+10;
- inner.bottom = rect.bottom-30;
- //pDC->DrawEdge(&inner,EDGE_ETCHED ,BF_RECT);
- // 显示60个点,1s一个点
- if (bRuning)
- {
- if ( !m_strVar1.IsEmpty() )
- {
- DrawCurve(pDC, inner, m_nValue1, m_clrCurve1);
- }
- if ( !m_strVar2.IsEmpty() )
- {
- DrawCurve(pDC, inner, m_nValue2, m_clrCurve2);
- }
- if ( !m_strVar3.IsEmpty() )
- {
- DrawCurve(pDC, inner, m_nValue3, m_clrCurve3);
- }
- }
- else
- {
- for (int i=0; i<60; i++)
- {
- m_nValue1[i] = 100+(i%10)*4-(i%15);
- m_nValue2[i] = 80+(i%15)*3-i;
- m_nValue3[i] = 60+(i%20)*3+i;
- }
- DrawCurve(pDC, inner, m_nValue1, m_clrCurve1);
- DrawCurve(pDC, inner, m_nValue2, m_clrCurve2);
- DrawCurve(pDC, inner, m_nValue3, m_clrCurve3);
- }
-
-
- // 网格
- CPen penGrid(PS_DOT, 1, RGB(192, 192, 192));
- CPen* pOldPen = pDC->SelectObject(&penGrid);
-
- pDC->SetTextColor( m_clrFore );
- pDC->SetTextAlign( TA_RIGHT );
- int Y=0;
- float rate = 0;//(1.0*(m_nLowerLimit-m_nLowwer)) / (m_nUpper-m_nLowwer);
-
- int nSpace = (m_nUpper-m_nLowwer)/10;
- if( nSpace%10!=0 )
- nSpace += ( 10-nSpace%10 );
- if( m_nUpper==2 && m_nLowwer==0 )
- nSpace = 1;
-
- for (int i=m_nLowwer+nSpace; i<m_nUpper; i+=nSpace )
- {
- rate = (1.0*(i-m_nLowwer)) / (m_nUpper-m_nLowwer);
- Y = inner.bottom - int(inner.Height()*rate);
- if (Y > inner.bottom)
- Y = inner.bottom;
- if (Y < inner.top)
- Y = inner.top;
- pDC->MoveTo(inner.left, Y);
- pDC->LineTo(inner.right, Y);
- sText.Format( "%d",i );
- pDC->TextOut( inner.left-5,Y-7,sText );
- }
- DeleteObject( penGrid );
- CPen penFrame(PS_SOLID, 1, RGB(0, 0, 0));
- pDC->SelectObject(&penFrame);
- pDC->MoveTo(inner.left, inner.top);
- pDC->LineTo(inner.right, inner.top);
- pDC->LineTo(inner.right, inner.bottom);
- CRect leftKedu = inner;
- leftKedu.right = leftKedu.left + 5;
- DrawVKedu(pDC, leftKedu, 50, m_clrLine);
- CRect bottomKedu = inner;
- bottomKedu.top = leftKedu.bottom - 5;
- DrawHKedu(pDC, bottomKedu, 60, m_clrLine);
- pDC->SelectObject(pOldPen);
- DeleteObject( penFrame );
- ////////////////////
- if( m_strVarDes1!="" )
- {
- pDC->SetTextAlign( TA_LEFT );
- pDC->SetTextColor( m_clrCurve1 );
- sText.Format( "%s【%0.1f】",m_strVarDes1,m_fValue1 );
- pDC->TextOut( rect.left+20,rect.bottom-23,sText );
- }
- if( m_strVarDes2!="" )
- {
- pDC->SetTextAlign( TA_CENTER );
- pDC->SetTextColor( m_clrCurve2 );
- sText.Format( "%s【%0.1f】",m_strVarDes2,m_fValue2 );
- pDC->TextOut( rect.left+rect.Width()/2,rect.bottom-23,sText );
- }
- if( m_strVarDes3!="" )
- {
- pDC->SetTextAlign( TA_RIGHT );
- pDC->SetTextColor( m_clrCurve3 );
- sText.Format( "%s【%0.1f】",m_strVarDes3,m_fValue3 );
- pDC->TextOut( rect.right-20,rect.bottom-23,sText );
- }
- }
- void CDrawCurve::Serialize(CArchive& ar)
- {
- CDrawObj::Serialize(ar);
- if(ar.IsStoring())
- {
- ar << m_clrCurve1;
- ar << m_clrCurve2;
- ar << m_clrCurve3;
- ar << m_nLowwer;
- ar << m_nUpper;
- ar << m_strVar1;
- ar << m_strVar2;
- ar << m_strVar3;
- }
- else
- {
- ar >> m_clrCurve1;
- ar >> m_clrCurve2;
- ar >> m_clrCurve3;
- ar >> m_nLowwer;
- ar >> m_nUpper;
- ar >> m_strVar1;
- ar >> m_strVar2;
- ar >> m_strVar3;
-
- //得到 上限,下限
- int nLowwer1=0,nUpper1=0,nLowwer2=0,nUpper2=0,nLowwer3=0,nUpper3=0;
- pVariantsManager->GetAnalogValue(m_strVar1,nLowwer1,nUpper1);
- pVariantsManager->GetAnalogValue(m_strVar2,nLowwer2,nUpper2);
- pVariantsManager->GetAnalogValue(m_strVar3,nLowwer3,nUpper3);
- m_nLowwer = nLowwer1;
- if( nLowwer2<nLowwer1 && nLowwer2<nLowwer3 )
- m_nLowwer = nLowwer2;
- if( nLowwer3<nLowwer1 && nLowwer3<nLowwer2 )
- m_nLowwer = nLowwer3;
- m_nUpper = nUpper1;
- if( nUpper2>nUpper1 && nUpper2>nUpper3 )
- m_nUpper = nUpper2;
- if( nUpper3>nUpper1 && nUpper3>nUpper2 )
- m_nUpper = nUpper3;
- if( m_nLowwer == m_nUpper )
- {
- m_nLowwer = 0;
- m_nUpper = 2;
- }
- else
- {
- m_nLowwer = getMin( m_nLowwer );
- m_nUpper = getMax( m_nUpper );
- }
- //得到 描述
- pVariantsManager->GetAnalogValue(m_strVar1,m_strVarDes1);
- pVariantsManager->GetAnalogValue(m_strVar2,m_strVarDes2);
- pVariantsManager->GetAnalogValue(m_strVar3,m_strVarDes3);
- }
- }
- int CDrawCurve::getMin( int iLowwer )
- {
- int nRet=0;
- nRet = iLowwer-20;
- if( nRet<0 )
- nRet = 0;
- int nMod = nRet%10;
- if( nMod!=0 )
- nRet -= nMod;
- return nRet;
- }
- int CDrawCurve::getMax( int iUpper )
- {
- int nRet=0;
- nRet = iUpper+20;
- int nMod = nRet%10;
- if( nMod!=0 )
- nRet += ( 10-nMod );
- return nRet;
- }
- BOOL CDrawCurve::OnAttrib(CPropertySheet& sheet)
- {
- CurvePage page;
- page.m_nLowwer = m_nLowwer;
- page.m_nUpper = m_nUpper;
- page.m_strVar1 = m_strVar1;
- page.m_strVar2 = m_strVar2;
- page.m_strVar3 = m_strVar3;
- page.m_clrCurve1 = m_clrCurve1;
- page.m_clrCurve2 = m_clrCurve2;
- page.m_clrCurve3 = m_clrCurve3;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_nLowwer = page.m_nLowwer;
- m_nUpper = page.m_nUpper;
- m_strVar1 = page.m_strVar1;
- m_strVar2 = page.m_strVar2;
- m_strVar3 = page.m_strVar3;
- m_clrCurve1 = page.m_clrCurve1;
- m_clrCurve2 = page.m_clrCurve2;
- m_clrCurve3 = page.m_clrCurve3;
- return TRUE;
- }
- return FALSE;
- }
- bool CDrawCurve::Fresh(CRect &RECT)
- {
- SYSTEMTIME st;
- GetLocalTime(&st);
- if ( m_nSecond != st.wSecond )
- {
- m_nSecond = st.wSecond;
- }
- else
- return true;
- if( g_nRunEditVarTick==0 )
- g_nRunEditVarTick = GetTickCount();
- if( GetTickCount()-g_nRunEditVarTick>1000*2 )
- {
- g_bRunEditVar = false;
- }
- else if( g_bRunEditVar )
- {
- //得到 上限,下限
- int nLowwer1=0,nUpper1=0,nLowwer2=0,nUpper2=0,nLowwer3=0,nUpper3=0;
- pVariantsManager->GetAnalogValue(m_strVar1,nLowwer1,nUpper1);
- pVariantsManager->GetAnalogValue(m_strVar2,nLowwer2,nUpper2);
- pVariantsManager->GetAnalogValue(m_strVar3,nLowwer3,nUpper3);
- m_nLowwer = nLowwer1;
- if( nLowwer2<nLowwer1 && nLowwer2<nLowwer3 )
- m_nLowwer = nLowwer2;
- if( nLowwer3<nLowwer1 && nLowwer3<nLowwer2 )
- m_nLowwer = nLowwer3;
- m_nUpper = nUpper1;
- if( nUpper2>nUpper1 && nUpper2>nUpper3 )
- m_nUpper = nUpper2;
- if( nUpper3>nUpper1 && nUpper3>nUpper2 )
- m_nUpper = nUpper3;
- if( m_nLowwer == m_nUpper )
- {
- m_nLowwer = 0;
- m_nUpper = 2;
- }
- else
- {
- m_nLowwer = getMin( m_nLowwer );
- m_nUpper = getMax( m_nUpper );
- }
- //得到 描述
- pVariantsManager->GetAnalogValue(m_strVar1,m_strVarDes1);
- pVariantsManager->GetAnalogValue(m_strVar2,m_strVarDes2);
- pVariantsManager->GetAnalogValue(m_strVar3,m_strVarDes3);
- }
- if ( !m_strVar1.IsEmpty() )
- {
- for(int i=0; i<59; i++)
- {
- m_nValue1[i] = m_nValue1[i+1];
- }
- m_fValue1 = pVariantsManager->GetAnalogValue(m_strVar1);
- m_nValue1[59] = (int)m_fValue1;
- }
- if ( !m_strVar2.IsEmpty() )
- {
- for(int i=0; i<59; i++)
- {
- m_nValue2[i] = m_nValue2[i+1];
- }
- m_fValue2 = pVariantsManager->GetAnalogValue(m_strVar2);
- m_nValue2[59] = (int)m_fValue2;
- }
- if ( !m_strVar3.IsEmpty() )
- {
- for(int i=0; i<59; i++)
- {
- m_nValue3[i] = m_nValue3[i+1];
- }
- m_fValue3 = pVariantsManager->GetAnalogValue(m_strVar3);
- m_nValue3[59] = (int)m_fValue3;
- }
- RECT = m_rect;
- return true;
- }
- void CDrawCurve::DrawCurve(CDC* pDC, CRect rect, int* data, COLORREF color)
- {
- rect.NormalizeRect();
- CPen PenBackGrid(PS_SOLID, m_nLineWidth, color);
- CPen* pOldPen = pDC->SelectObject(&PenBackGrid);
- bool f = false;
- for (int i=0; i<60; i++)
- {
- CPoint point;
- point.x = rect.left+i*(1.0*rect.Width()/59);
- float rate = (1.0*(data[i]-m_nLowwer)) / (m_nUpper-m_nLowwer);
- point.y = rect.bottom - int(rect.Height()*rate);
- if (point.y > rect.bottom)
- point.y = rect.bottom;
- if (point.y < rect.top)
- point.y = rect.top;
- if (point.x < rect.left)
- point.x = rect.left;
- if (point.x > rect.right)
- point.x = rect.right;
- if ( !f && point.y!=rect.bottom )
- {
- f = true;
- pDC->MoveTo(point);
- }
- else if ( f )
- {
- pDC->LineTo(point);
- }
- }
- pDC->SelectObject(pOldPen);
- DeleteObject( PenBackGrid );
- }
- //---------------------------------------------- CDrawHisCurve -------
- IMPLEMENT_SERIAL(CDrawHisCurve, CDrawObj, 0)
- CDrawHisCurve::CDrawHisCurve():CDrawObj()
- {
- m_clrFill = RGB(255,255,255);
- m_clrCurve1 = RGB(255, 0, 0);
- m_clrCurve2 = RGB(0, 255, 0);
- m_clrCurve3 = RGB(0, 0, 255);
- m_clrLine = RGB(0,0,0);
- m_nLowwer = 0;
- m_nUpper = 200;
- m_strVar1 = "";
- m_strVar2 = "";
- m_strVar3 = "";
- m_nFillMode = 1;
- for (int i=0; i<60; i++)
- {
- m_nValue1[i] = 0;
- m_nValue2[i] = 0;
- m_nValue3[i] = 0;
- }
- }
- CDrawObj* CDrawHisCurve::Clone(void)
- {
- CDrawHisCurve *pObj = new CDrawHisCurve;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_clrCurve1 = m_clrCurve1;
- pObj->m_clrCurve2 = m_clrCurve2;
- pObj->m_clrCurve3 = m_clrCurve3;
- pObj->m_nLowwer = m_nLowwer;
- pObj->m_nUpper = m_nUpper;
- pObj->m_strVar1 = m_strVar1;
- pObj->m_strVar2 = m_strVar2;
- pObj->m_strVar3 = m_strVar3;
- return pObj;
- }
- void CDrawHisCurve::Draw(CDC* pDC)
- {
- CDrawObj::Draw(pDC);
- CRect rect = m_rect;
- rect.NormalizeRect();
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
- if ( m_nFillMode < 8 )
- {
- pDC->Rectangle(rect);
- }
-
- // 边框
- pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT);
- CRect inner;
- inner.left = rect.left+40;
- inner.right = rect.right-10;
- inner.top = rect.top+10;
- inner.bottom = rect.bottom-30;
- // 显示60个点,1s一个点
- if (bRuning)
- {
- if ( !m_strVar1.IsEmpty() )
- {
- DrawCurve(pDC, inner, m_nValue1, m_clrCurve1);
- }
- if ( !m_strVar2.IsEmpty() )
- {
- DrawCurve(pDC, inner, m_nValue2, m_clrCurve2);
- }
- if ( !m_strVar3.IsEmpty() )
- {
- DrawCurve(pDC, inner, m_nValue3, m_clrCurve3);
- }
- }
- else
- {
- for (int i=0; i<60; i++)
- {
- m_nValue1[i] = 100+(i%10)*4-(i%15);
- m_nValue2[i] = 80+(i%15)*3-i;
- m_nValue3[i] = 60+(i%20)*3+i;
- }
- DrawCurve(pDC, inner, m_nValue1, m_clrCurve1);
- DrawCurve(pDC, inner, m_nValue2, m_clrCurve2);
- DrawCurve(pDC, inner, m_nValue3, m_clrCurve3);
- }
-
-
- // 网格
- CPen penGrid(PS_DOT, 1, RGB(192, 192, 192));
- CPen* pOldPen = pDC->SelectObject(&penGrid);
- for (int i=1; i<5; i++)
- {
- pDC->MoveTo(inner.left, inner.top+inner.Height()*i/5);
- pDC->LineTo(inner.right, inner.top+inner.Height()*i/5);
- }
- for (i=1; i<6; i++)
- {
- pDC->MoveTo(inner.left + inner.Width()*i/6, inner.top);
- pDC->LineTo(inner.left + inner.Width()*i/6, inner.bottom);
- }
- CPen penFrame(PS_SOLID, 1, RGB(0, 0, 0));
- pDC->SelectObject(&penFrame);
- pDC->MoveTo(inner.left, inner.top);
- pDC->LineTo(inner.right, inner.top);
- pDC->LineTo(inner.right, inner.bottom);
- CRect leftKedu = inner;
- leftKedu.right = leftKedu.left + 5;
- DrawVKedu(pDC, leftKedu, 50, m_clrLine);
- CRect bottomKedu = inner;
- bottomKedu.top = leftKedu.bottom - 5;
- DrawHKedu(pDC, bottomKedu, 60, m_clrLine);
- pDC->SelectObject(pOldPen);
- DeleteObject( m_brush );
- DeleteObject( penGrid );
- DeleteObject( penFrame );
- }
- void CDrawHisCurve::Serialize(CArchive& ar)
- {
- CDrawObj::Serialize(ar);
- if(ar.IsStoring())
- {
- ar << m_clrCurve1;
- ar << m_clrCurve2;
- ar << m_clrCurve3;
- ar << m_nLowwer;
- ar << m_nUpper;
- ar << m_strVar1;
- ar << m_strVar2;
- ar << m_strVar3;
- }
- else
- {
- ar >> m_clrCurve1;
- ar >> m_clrCurve2;
- ar >> m_clrCurve3;
- ar >> m_nLowwer;
- ar >> m_nUpper;
- ar >> m_strVar1;
- ar >> m_strVar2;
- ar >> m_strVar3;
- }
- }
- BOOL CDrawHisCurve::OnAttrib(CPropertySheet& sheet)
- {
- CurvePage page;
- page.m_nLowwer = m_nLowwer;
- page.m_nUpper = m_nUpper;
- page.m_strVar1 = m_strVar1;
- page.m_strVar2 = m_strVar2;
- page.m_strVar3 = m_strVar3;
- page.m_clrCurve1 = m_clrCurve1;
- page.m_clrCurve2 = m_clrCurve2;
- page.m_clrCurve3 = m_clrCurve3;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal() == IDOK )
- {
- m_nLowwer = page.m_nLowwer;
- m_nUpper = page.m_nUpper;
- m_strVar1 = page.m_strVar1;
- m_strVar2 = page.m_strVar2;
- m_strVar3 = page.m_strVar3;
- m_clrCurve1 = page.m_clrCurve1;
- m_clrCurve2 = page.m_clrCurve2;
- m_clrCurve3 = page.m_clrCurve3;
- return TRUE;
- }
- return FALSE;
- }
- bool CDrawHisCurve::Fresh(CRect &RECT)
- {
- SYSTEMTIME st;
- GetLocalTime(&st);
- if ( m_nSecond != st.wSecond )
- {
- m_nSecond = st.wSecond;
- }
- else
- return true;
- if ( !m_strVar1.IsEmpty() )
- {
- for(int i=0; i<59; i++)
- {
- m_nValue1[i] = m_nValue1[i+1];
- }
- m_nValue1[59] = (int) pVariantsManager->GetAnalogValue(m_strVar1);
- }
- if ( !m_strVar2.IsEmpty() )
- {
- for(int i=0; i<59; i++)
- {
- m_nValue2[i] = m_nValue2[i+1];
- }
- m_nValue2[59] = (int) pVariantsManager->GetAnalogValue(m_strVar2);
- }
- if ( !m_strVar3.IsEmpty() )
- {
- for(int i=0; i<59; i++)
- {
- m_nValue3[i] = m_nValue3[i+1];
- }
- m_nValue3[59] = (int) pVariantsManager->GetAnalogValue(m_strVar3);
- }
- RECT = m_rect;
- return true;
- }
- void CDrawHisCurve::DrawCurve(CDC* pDC, CRect rect, int* data, COLORREF color)
- {
- rect.NormalizeRect();
- CPen PenBackGrid(PS_SOLID, 1, color);
- CPen* pOldPen = pDC->SelectObject(&PenBackGrid);
- for (int i=0; i<60; i++)
- {
- CPoint point;
- point.x = rect.left+i*(1.0*rect.Width()/59);
- float rate = (1.0*(data[i]-m_nLowwer)) / (m_nUpper-m_nLowwer);
- point.y = rect.bottom - int(rect.Height()*rate);
- if (point.y > rect.bottom)
- point.y = rect.bottom;
- if (point.y < rect.top)
- point.y = rect.top;
- if (point.x < rect.left)
- point.x = rect.left;
- if (point.x > rect.right)
- point.x = rect.right;
- if ( i==0)
- {
- pDC->MoveTo(point);
- }
- else
- {
- pDC->LineTo(point);
- }
- }
- pDC->SelectObject(pOldPen);
- }
- //---------------------------------------------- CDrawOCX --------
- IMPLEMENT_SERIAL(CDrawOCX, CDrawObj, 0)
- CDrawOCX::CDrawOCX():CDrawObj()
- {
- m_clrFore = RGB( 0x80,0x00,0x00 );;
- m_clrBack = RGB( 0xD1,0xE1,0xF8 );//(120, 120, 120);
- m_strCaption = "OCX";
- m_strOcxPath = "";
- m_nOcxIndex = 0;
- }
- CDrawObj* CDrawOCX::Clone(void)
- {
- CDrawOCX *pObj = new CDrawOCX;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_strOcxPath = m_strOcxPath;
- pObj->m_nOcxIndex = m_nOcxIndex;
- return pObj;
- }
- bool CDrawOCX::Fresh(CRect &RECT)
- {
- CDrawObj::Fresh(RECT);
- RECT = m_rect;
-
- if ( !m_bShow )
- {
- m_bShowtemp = FALSE;
- return true;
- }
- else if( !m_bShowtemp )
- {
- m_bShowtemp = TRUE;
- return true;
- }
- else
- return false;
- }
- void CDrawOCX::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning) return;
- if (!g_bRun)
- {
- CRect rect = m_rctCurrent;
- COLORREF color = m_clrCurrentBack;
- if (!bRuning)
- {
- rect = m_rect;
- color = m_clrBack;
- }
- pDC->FillSolidRect(rect, color);
- CPen pen(GetPenStyle(m_strLineType), 5, RGB(255, 128, 0) );
- CPen* pOldPen = pDC->SelectObject(&pen);
- // CBrush
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
- pDC->Rectangle(rect);
- CBrush *pBrushNull=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)) ;
- pOldBrush=pDC->SelectObject(pBrushNull);//选入设备描述表
- CPen pen2(GetPenStyle(m_strLineType), 2, RGB(255, 255, 255) );
- pOldPen = pDC->SelectObject(&pen2);
- //rect.left+=1;
- //rect.right-=1;
- //rect.top+=1;
- //rect.bottom-=1;
- pDC->Rectangle(rect);
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- DrawText(pDC);
- DeleteObject( m_brush );
- DeleteObject( pBrushNull );
- DeleteObject( pen );
- DeleteObject( pen2 );
- }
- else
- {
- }
- }
- void CDrawOCX::DrawText(CDC* pDC)
- {
- CFont *pFont=NULL;
- COLORREF clrFore = m_clrFore;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrFore = m_clrCurrentFore;
- rect = m_rctCurrent;
- }
- pDC->SetTextColor(clrFore);
- pDC->SetTextAlign(TA_LEFT|TA_TOP);
- CFont font;
- font.CreateFontIndirect(&m_logfont);
- CFont* pOldFont = pDC->SelectObject(&font);
- int height = abs(m_logfont.lfHeight);
- rect.NormalizeRect();
- int nX0 = (rect.left+rect.right) / 2;
- int nY0 = (rect.top+rect.bottom) / 2;
- //if(rect.Width()>=rect.Height())
- {
- pFont = new CFont;
- pFont->CreateFont(rect.Height()*2/4, // nHeight
- 0, // nWidth
- 0, // nEscapement
- 0, // nOrientation
- FW_BOLD, // nWeight
- false, // bItalic
- FALSE, // bUnderline
- 0, // cStrikeOut
- ANSI_CHARSET, // nCharSet
- OUT_DEFAULT_PRECIS, // nOutPrecision
- CLIP_DEFAULT_PRECIS, // nClipPrecision
- DEFAULT_QUALITY, // nQuality
- DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
- _T("黑体")); // lpszFac
- pDC->SelectObject( pFont );
- pDC->DrawText(m_strCaption, -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- }
- DeleteObject( font );
- pDC->SelectObject(pOldFont);
- if( pFont )
- delete pFont;
- }
- BOOL CDrawOCX::OnAttrib(CPropertySheet& sheet)
- {
- CDlg_OCX page;
- page.m_sEdit_OCXPath = m_strOcxPath;
- page.m_nComb_OCXIndex = m_nOcxIndex;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_strOcxPath = page.m_sEdit_OCXPath;
- m_nOcxIndex = page.m_nComb_OCXIndex;
- return TRUE;
- }
- return FALSE;
- }
- void CDrawOCX::Serialize(CArchive& ar)
- {
- CDrawObj::Serialize(ar);
- if(ar.IsStoring())
- {
- ar << m_strOcxPath;
- ar << m_nOcxIndex;
- }
- else
- {
- ar >> m_strOcxPath;
- ar >> m_nOcxIndex;
- }
- }
- //---------------------------------------------- CDrawFlash --------
- IMPLEMENT_SERIAL(CDrawFlash, CDrawObj, 0)
- CDrawFlash::CDrawFlash():CDrawObj()
- {
- m_clrFore = RGB( 0x80,0x00,0x00 );;
- m_clrBack = RGB( 0xD1,0xE1,0xF8 );//(120, 120, 120);
- m_strCaption = "swf";
- m_strFlashPath = "";
- m_pCtrlFlash = NULL;
- m_bFlashCreate = false;
- }
- CDrawFlash::~CDrawFlash()
- {
- if( m_pCtrlFlash )
- {
- delete m_pCtrlFlash;
- m_pCtrlFlash = NULL;
- m_bFlashCreate = false;
- }
- }
- CDrawObj* CDrawFlash::Clone(void)
- {
- CDrawFlash *pObj = new CDrawFlash;
- *((CDrawObj*)pObj) = *(CDrawObj*)this;
- pObj->m_strFlashPath = m_strFlashPath;
- return pObj;
- }
- void CDrawFlash::Serialize(CArchive& ar)
- {
- CDrawObj::Serialize(ar);
- if(ar.IsStoring())
- {
- ar << m_strFlashPath;
- }
- else
- {
- ar >> m_strFlashPath;
- }
- }
- bool CDrawFlash::Fresh(CRect &RECT)
- {
- CDrawObj::Fresh(RECT);
- RECT = m_rect;
- #if 1
- if( m_pCtrlFlash )
- {
- CRect rect = m_rect;
- rect.NormalizeRect();
- int nX1 = rect.left;
- int nY1 = rect.top;
- CPoint pt(nX1, nY1);
- CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
- HWND hwnd = pFrame->m_pActiveView->m_hWnd;
- //m_image->InitAnimation(hwnd, pt);
- if( !m_bFlashCreate && m_strFlashPath!="" )
- {
- m_bFlashCreate = true;
- m_pCtrlFlash->Create( "","",WS_CHILD|WS_VISIBLE,rect,CWnd::FromHandle(hwnd),10000 );
- char curDir[256] = {0};
- strcpy(curDir, g_strDirectory);
- strcat(curDir, "\\");
- strcat(curDir, _BITMAPDIR);
- CString strFileName = m_strFlashPath;//CString(curDir) +
- m_pCtrlFlash->SetMovie( strFileName );
- }
- int a = rand()%100;
- CString str;
- str.Format("当前值:%d",a );
- if( m_pCtrlFlash )
- m_pCtrlFlash->SetVariable( "a",str );
- }
- #endif
- if ( !m_bShow )
- {
- m_bShowtemp = FALSE;
- return true;
- }
- else if( !m_bShowtemp )
- {
- m_bShowtemp = TRUE;
- return true;
- }
- else
- return false;
- }
- void CDrawFlash::Draw(CDC* pDC)
- {
- if ( !m_bShow && bRuning)
- {
- if( m_pCtrlFlash )
- {
- delete m_pCtrlFlash;
- m_pCtrlFlash = NULL;
- m_bFlashCreate = false;
- }
- return;
- }
- if (!g_bRun)
- {
- CRect rect = m_rctCurrent;
- COLORREF color = m_clrCurrentBack;
- if (!bRuning)
- {
- rect = m_rect;
- color = m_clrBack;
- }
- pDC->FillSolidRect(rect, color);
- CPen pen(GetPenStyle(m_strLineType), 5, RGB(255, 128, 0) );
- CPen* pOldPen = pDC->SelectObject(&pen);
- // CBrush
- LOGBRUSH brushlog = GetBrush();
- CBrush m_brush;
- m_brush.CreateBrushIndirect(&brushlog);
- CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&m_brush);
- pDC->Rectangle(rect);
- CBrush *pBrushNull=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)) ;
- pOldBrush=pDC->SelectObject(pBrushNull);//选入设备描述表
- CPen pen2(GetPenStyle(m_strLineType), 2, RGB(255, 255, 255) );
- pOldPen = pDC->SelectObject(&pen2);
- //rect.left+=1;
- //rect.right-=1;
- //rect.top+=1;
- //rect.bottom-=1;
- pDC->Rectangle(rect);
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- DrawText(pDC);
- DeleteObject( m_brush );
- DeleteObject( pBrushNull );
- DeleteObject( pen );
- DeleteObject( pen2 );
- }
- if( g_bRun )
- {
- if( m_pCtrlFlash==NULL )
- {
- //char curDir[256] = {0};
- ////strcpy(curDir, g_strDirectory);
- //strcat(curDir, ".\\\\");
- //strcat(curDir, _BITMAPDIR);
- //if( m_strStaticFile=="" )//gif 路徑為Bitmap,默認名為StounU.gif
- // m_strStaticFile = "StounU.gif";
- //CString strGifFileName = CString(curDir) + m_strStaticFile;
- //GDI+
- m_pCtrlFlash = new CShockwaveFlash();
- }
- if( m_pCtrlFlash )
- {
- CRect rect = m_rect;
- rect.NormalizeRect();
- int nX1 = rect.left;
- int nY1 = rect.top;
- CPoint pt(nX1, nY1);
- CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
- HWND hwnd = pFrame->m_pActiveView->m_hWnd;
- //m_image->InitAnimation(hwnd, pt);
- if( !m_bFlashCreate && m_strFlashPath!="" )
- {
- m_bFlashCreate = true;
- m_pCtrlFlash->Create( "","",WS_CHILD|WS_VISIBLE,rect,CWnd::FromHandle(hwnd),10000 );
- char curDir[256] = {0};
- strcpy(curDir, g_strDirectory);
- strcat(curDir, "\\");
- strcat(curDir, _BITMAPDIR);
- CString strFileName = m_strFlashPath;//CString(curDir) +
- m_pCtrlFlash->SetMovie( strFileName );
- }
- int a = rand()%100;
- CString str;
- str.Format("当前值:%d",a );
- if( m_pCtrlFlash )
- m_pCtrlFlash->SetVariable( "a",str );
- }
- }
- }
- BOOL CDrawFlash::OnAttrib(CPropertySheet& sheet)
- {
- CDlg_Flash page;
- page.m_sEdit_FlashPath = m_strFlashPath;
- sheet.AddPage(&page);
- sheet.Construct(g_strParamSet);
- sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
- if( sheet.DoModal()==IDOK )
- {
- m_strFlashPath = page.m_sEdit_FlashPath;
- return TRUE;
- }
- return FALSE;
- }
- void CDrawFlash::DrawText(CDC* pDC)
- {
- CFont *pFont=NULL;
- COLORREF clrFore = m_clrFore;
- CRect rect = m_rect;
- if ( bRuning )
- {
- clrFore = m_clrCurrentFore;
- rect = m_rctCurrent;
- }
- pDC->SetTextColor(clrFore);
- pDC->SetTextAlign(TA_LEFT|TA_TOP);
- CFont font;
- font.CreateFontIndirect(&m_logfont);
- CFont* pOldFont = pDC->SelectObject(&font);
- int height = abs(m_logfont.lfHeight);
- rect.NormalizeRect();
- int nX0 = (rect.left+rect.right) / 2;
- int nY0 = (rect.top+rect.bottom) / 2;
- //if(rect.Width()>=rect.Height())
- {
- pFont = new CFont;
- pFont->CreateFont(rect.Height()*2/4, // nHeight
- 0, // nWidth
- 0, // nEscapement
- 0, // nOrientation
- FW_BOLD, // nWeight
- false, // bItalic
- FALSE, // bUnderline
- 0, // cStrikeOut
- ANSI_CHARSET, // nCharSet
- OUT_DEFAULT_PRECIS, // nOutPrecision
- CLIP_DEFAULT_PRECIS, // nClipPrecision
- DEFAULT_QUALITY, // nQuality
- DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
- _T("黑体")); // lpszFac
- pDC->SelectObject( pFont );
- pDC->DrawText(m_strCaption, -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- }
- pDC->SelectObject(pOldFont);
- DeleteObject( font );
- if( pFont )
- delete pFont;
- }
|