tools.py 227 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880
  1. """
  2. @package nviz.tools
  3. @brief Nviz (3D view) tools window
  4. Classes:
  5. - tools::NvizToolWindow
  6. - tools::PositionWindow
  7. - tools::ViewPositionWindow
  8. - tools::LightPositionWindow
  9. (C) 2008-2011 by the GRASS Development Team
  10. This program is free software under the GNU General Public License
  11. (>=v2). Read the file COPYING that comes with GRASS for details.
  12. @author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  13. @author Enhancements by Michael Barton <michael.barton asu.edu>
  14. @author Anna Kratochvilova <kratochanna gmail.com> (Google SoC 2011)
  15. """
  16. import os
  17. import sys
  18. import copy
  19. import six
  20. import wx
  21. import wx.lib.colourselect as csel
  22. import wx.lib.scrolledpanel as SP
  23. import wx.lib.filebrowsebutton as filebrowse
  24. try:
  25. import wx.lib.agw.flatnotebook as FN
  26. except ImportError:
  27. import wx.lib.flatnotebook as FN
  28. try:
  29. from agw import foldpanelbar as fpb
  30. except ImportError: # if it's not there locally, try the wxPython lib.
  31. try:
  32. import wx.lib.agw.foldpanelbar as fpb
  33. except ImportError:
  34. import wx.lib.foldpanelbar as fpb # versions <=2.5.5.1
  35. try:
  36. import wx.lib.agw.floatspin as fs
  37. except ImportError:
  38. fs = None
  39. import grass.script as grass
  40. from core import globalvar
  41. from gui_core.gselect import VectorDBInfo
  42. from core.gcmd import GMessage, RunCommand
  43. from modules.colorrules import ThematicVectorTable
  44. from core.settings import UserSettings
  45. from gui_core.widgets import ScrolledPanel, NumTextCtrl, FloatSlider, SymbolButton
  46. from gui_core.gselect import Select
  47. from gui_core.wrap import Window, SpinCtrl, PseudoDC, ToggleButton, Button, \
  48. TextCtrl, ToggleButton, StaticText, StaticBox, CheckListBox, ColourSelect
  49. from core.debug import Debug
  50. try:
  51. from nviz.mapwindow import wxUpdateProperties, wxUpdateView,\
  52. wxUpdateLight, wxUpdateCPlane
  53. import wxnviz
  54. except ImportError:
  55. pass
  56. class NvizToolWindow(FN.FlatNotebook):
  57. """Nviz (3D view) tools panel
  58. """
  59. def __init__(self, parent, tree, display, id=wx.ID_ANY,
  60. style=globalvar.FNPageStyle | FN.FNB_NO_X_BUTTON,
  61. **kwargs):
  62. Debug.msg(5, "NvizToolWindow.__init__()")
  63. self.parent = parent
  64. self.tree = tree
  65. self.mapDisplay = display
  66. self.mapWindow = display.GetWindow()
  67. self._display = self.mapWindow.GetDisplay()
  68. if globalvar.hasAgw:
  69. kwargs['agwStyle'] = style
  70. else:
  71. kwargs['style'] = style
  72. FN.FlatNotebook.__init__(self, parent, id, **kwargs)
  73. self.SetTabAreaColour(globalvar.FNPageColor)
  74. self.win = {} # window ids
  75. self.page = {} # page ids
  76. # view page
  77. self.AddPage(page=self._createViewPage(),
  78. text=" %s " % _("View"))
  79. # data page
  80. self.AddPage(page=self._createDataPage(),
  81. text=" %s " % _("Data"))
  82. # appearance page
  83. self.AddPage(page=self._createAppearancePage(),
  84. text=" %s " % _("Appearance"))
  85. # analysis page
  86. self.AddPage(page=self._createAnalysisPage(),
  87. text=" %s " % _("Analysis"))
  88. # view page
  89. self.AddPage(page=self._createAnimationPage(),
  90. text=" %s " % _("Animation"))
  91. self.UpdateSettings()
  92. self.mapWindow.SetToolWin(self)
  93. self.pageChanging = False
  94. self.vetoGSelectEvt = False # when setting map, event is invoked
  95. self.mapWindow.render['quick'] = False
  96. self.mapWindow.Refresh(False)
  97. # bindings
  98. self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
  99. self.Bind(wx.EVT_SIZE, self.OnSize)
  100. self.mapWindow.GetAnimation().animationFinished.connect(self.OnAnimationFinished)
  101. self.mapWindow.GetAnimation().animationUpdateIndex.connect(
  102. self.OnAnimationUpdateIndex)
  103. Debug.msg(3, "NvizToolWindow.__init__()")
  104. self.Update()
  105. wx.CallAfter(self.SetPage, 'view')
  106. wx.CallAfter(
  107. self.UpdateScrolling,
  108. (self.foldpanelData,
  109. self.foldpanelAppear,
  110. self.foldpanelAnalysis))
  111. wx.CallAfter(self.SetInitialMaps)
  112. def SetInitialMaps(self):
  113. """Set initial raster and vector map"""
  114. for ltype in ('raster', 'vector', 'raster_3d'):
  115. selectedLayer = self.tree.GetSelectedLayer(
  116. multi=False, checkedOnly=True)
  117. if selectedLayer is None:
  118. continue
  119. selectedLayer = self.tree.GetLayerInfo(
  120. selectedLayer, key='maplayer')
  121. layers = self.mapWindow.Map.GetListOfLayers(
  122. ltype=ltype, active=True)
  123. if selectedLayer in layers:
  124. selection = selectedLayer.GetName()
  125. else:
  126. try:
  127. selection = layers[0].GetName()
  128. except:
  129. continue
  130. if ltype == 'raster':
  131. self.FindWindowById(
  132. self.win['surface']['map']).SetValue(selection)
  133. self.FindWindowById(
  134. self.win['fringe']['map']).SetValue(selection)
  135. elif ltype == 'vector':
  136. self.FindWindowById(
  137. self.win['vector']['map']).SetValue(selection)
  138. elif ltype == 'raster_3d':
  139. self.FindWindowById(
  140. self.win['volume']['map']).SetValue(selection)
  141. def UpdateState(self, **kwargs):
  142. if 'view' in kwargs:
  143. self.mapWindow.view = kwargs['view']
  144. self.FindWindowById(
  145. self.win['view']['position']).data = kwargs['view']
  146. self.FindWindowById(self.win['view']['position']).PostDraw()
  147. if 'iview' in kwargs:
  148. self.mapWindow.iview = kwargs['iview']
  149. if 'light' in kwargs:
  150. self.mapWindow.light = kwargs['light']
  151. self.FindWindowById(
  152. self.win['light']['position']).data = kwargs['light']
  153. self.FindWindowById(self.win['light']['position']).PostDraw()
  154. if 'fly' in kwargs:
  155. self.mapWindow.fly['exag'] = kwargs['fly']['exag']
  156. def LoadSettings(self):
  157. """Load Nviz settings and apply to current session"""
  158. view = copy.deepcopy(
  159. UserSettings.Get(
  160. group='nviz',
  161. key='view')) # copy
  162. light = copy.deepcopy(
  163. UserSettings.Get(
  164. group='nviz',
  165. key='light')) # copy
  166. fly = copy.deepcopy(UserSettings.Get(group='nviz', key='fly')) # copy
  167. self.UpdateState(view=view, light=light, fly=fly)
  168. self.PostViewEvent(zExag=True)
  169. self.PostLightEvent()
  170. self.UpdatePage('view')
  171. self.UpdatePage('light')
  172. self.mapWindow.ReloadLayersData()
  173. self.UpdatePage('surface')
  174. self.UpdatePage('vector')
  175. self.UpdateSettings()
  176. def OnPageChanged(self, event):
  177. new = event.GetSelection()
  178. # self.ChangeSelection(new)
  179. def PostViewEvent(self, zExag=False):
  180. """Change view settings"""
  181. event = wxUpdateView(zExag=zExag)
  182. wx.PostEvent(self.mapWindow, event)
  183. def PostLightEvent(self, refresh=False):
  184. """Change light settings"""
  185. event = wxUpdateLight(refresh=refresh)
  186. wx.PostEvent(self.mapWindow, event)
  187. def OnSize(self, event):
  188. """After window is resized, update scrolling"""
  189. # workaround to resize captionbars of foldpanelbar
  190. wx.CallAfter(
  191. self.UpdateScrolling,
  192. (self.foldpanelData,
  193. self.foldpanelAppear,
  194. self.foldpanelAnalysis))
  195. event.Skip()
  196. def OnPressCaption(self, event):
  197. """When foldpanel item collapsed/expanded, update scrollbars"""
  198. foldpanel = event.GetBar().GetGrandParent().GetParent()
  199. wx.CallAfter(self.UpdateScrolling, (foldpanel,))
  200. event.Skip()
  201. def UpdateScrolling(self, foldpanels):
  202. """Update scrollbars in foldpanel"""
  203. for foldpanel in foldpanels:
  204. length = foldpanel.GetPanelsLength(collapsed=0, expanded=0)
  205. # virtual width is set to fixed value to suppress GTK warning
  206. foldpanel.GetParent().SetVirtualSize((100, length[2]))
  207. foldpanel.GetParent().Layout()
  208. def _createViewPage(self):
  209. """Create view settings page"""
  210. panel = SP.ScrolledPanel(parent=self, id=wx.ID_ANY)
  211. panel.SetupScrolling(scroll_x=False)
  212. self.page['view'] = {'id': 0,
  213. 'notebook': self.GetId()}
  214. pageSizer = wx.BoxSizer(wx.VERTICAL)
  215. box = StaticBox(parent=panel, id=wx.ID_ANY,
  216. label=" %s " % (_("Control View")))
  217. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  218. gridSizer = wx.GridBagSizer(vgap=5, hgap=10)
  219. self.win['view'] = {}
  220. # position
  221. posSizer = wx.GridBagSizer(vgap=3, hgap=3)
  222. self._createCompass(panel=panel, sizer=posSizer, type='view')
  223. view = ViewPositionWindow(panel, size=(175, 175),
  224. mapwindow=self.mapWindow)
  225. self.win['view']['position'] = view.GetId()
  226. posSizer.Add(
  227. view, pos=(1, 1),
  228. flag=wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  229. gridSizer.Add(posSizer, pos=(0, 0))
  230. # perspective
  231. # set initial defaults here (or perhaps in a default values file), not in user settings
  232. # todo: consider setting an absolute max at 360 instead of undefined.
  233. # (leave the default max value at pi)
  234. tooltip = _(
  235. "Adjusts the distance and angular perspective of the image viewpoint")
  236. self._createControl(
  237. panel,
  238. data=self.win['view'],
  239. name='persp',
  240. tooltip=tooltip,
  241. range=(
  242. 1,
  243. 120),
  244. bind=(
  245. self.OnViewChange,
  246. self.OnViewChanged,
  247. self.OnViewChangedText))
  248. gridSizer.Add(
  249. StaticText(
  250. panel, id=wx.ID_ANY, label=_("Perspective:")), pos=(
  251. 1, 0), flag=wx.ALIGN_CENTER)
  252. gridSizer.Add(
  253. self.FindWindowById(
  254. self.win['view']['persp']['slider']), pos=(
  255. 2, 0), flag=wx.ALIGN_CENTER)
  256. gridSizer.Add(
  257. self.FindWindowById(
  258. self.win['view']['persp']['text']), pos=(
  259. 3, 0), flag=wx.ALIGN_CENTER)
  260. # twist
  261. tooltip = _("Tilts the plane of the surface from the horizontal")
  262. self._createControl(panel,
  263. data=self.win['view'],
  264. name='twist',
  265. tooltip=tooltip,
  266. range=(-180,
  267. 180),
  268. bind=(self.OnViewChange,
  269. self.OnViewChanged,
  270. self.OnViewChangedText))
  271. gridSizer.Add(
  272. StaticText(
  273. panel, id=wx.ID_ANY, label=_("Tilt:")), pos=(
  274. 1, 1), flag=wx.ALIGN_CENTER)
  275. gridSizer.Add(
  276. self.FindWindowById(
  277. self.win['view']['twist']['slider']), pos=(
  278. 2, 1))
  279. gridSizer.Add(
  280. self.FindWindowById(
  281. self.win['view']['twist']['text']), pos=(
  282. 3, 1), flag=wx.ALIGN_CENTER)
  283. # height + z-exag
  284. tooltip = _(
  285. "Adjusts the viewing height above the surface"
  286. " (angle of view automatically adjusts to maintain the same center of view)")
  287. self._createControl(
  288. panel,
  289. data=self.win['view'],
  290. name='height',
  291. sliderHor=False,
  292. tooltip=tooltip,
  293. range=(
  294. 0,
  295. 1),
  296. bind=(
  297. self.OnViewChange,
  298. self.OnViewChanged,
  299. self.OnViewChangedText))
  300. tooltip = _(
  301. "Adjusts the relative height of features above the plane of the surface")
  302. self._createControl(
  303. panel,
  304. data=self.win['view'],
  305. name='z-exag',
  306. sliderHor=False,
  307. tooltip=tooltip,
  308. range=(
  309. 0,
  310. 10),
  311. floatSlider=True,
  312. bind=(
  313. self.OnViewChange,
  314. self.OnViewChanged,
  315. self.OnViewChangedText))
  316. self.FindWindowById(self.win['view']['z-exag']['slider']).SetValue(1)
  317. self.FindWindowById(self.win['view']['z-exag']['text']).SetValue(1)
  318. heightSizer = wx.GridBagSizer(vgap=3, hgap=3)
  319. heightSizer.Add(
  320. StaticText(
  321. panel, id=wx.ID_ANY, label=_("Height:")), pos=(
  322. 0, 0), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, span=(
  323. 1, 2))
  324. heightSizer.Add(
  325. self.FindWindowById(
  326. self.win['view']['height']['slider']),
  327. flag=wx.ALIGN_RIGHT,
  328. pos=(
  329. 1,
  330. 0))
  331. heightSizer.Add(
  332. self.FindWindowById(
  333. self.win['view']['height']['text']),
  334. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  335. pos=(
  336. 1,
  337. 1))
  338. heightSizer.Add(
  339. StaticText(
  340. panel,
  341. id=wx.ID_ANY,
  342. label=_("Z-exag:")),
  343. pos=(
  344. 0,
  345. 2),
  346. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  347. span=(
  348. 1,
  349. 2))
  350. heightSizer.Add(
  351. self.FindWindowById(
  352. self.win['view']['z-exag']['slider']),
  353. flag=wx.ALIGN_RIGHT,
  354. pos=(
  355. 1,
  356. 2))
  357. heightSizer.Add(self.FindWindowById(
  358. self.win['view']['z-exag']['text']),
  359. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  360. wx.BOTTOM | wx.RIGHT, pos=(1, 3))
  361. gridSizer.Add(heightSizer, pos=(0, 1), flag=wx.ALIGN_CENTER)
  362. # view setup + reset
  363. viewSizer = wx.BoxSizer(wx.HORIZONTAL)
  364. viewSizer.Add(StaticText(panel, id=wx.ID_ANY,
  365. label=_("Look:")),
  366. flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  367. border=5)
  368. here = ToggleButton(panel, id=wx.ID_ANY, label=_("here"))
  369. here.Bind(wx.EVT_TOGGLEBUTTON, self.OnLookAt)
  370. here.SetName('here')
  371. here.SetToolTip(_("Allows you to select a point on the surface "
  372. "that becomes the new center of view. "
  373. "Click on the button and then on the surface."))
  374. viewSizer.Add(here, flag=wx.TOP | wx.BOTTOM |
  375. wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=5)
  376. center = Button(panel, id=wx.ID_ANY, label=_("center"))
  377. center.Bind(wx.EVT_BUTTON, self.OnLookAt)
  378. center.SetName('center')
  379. center.SetToolTip(
  380. _("Resets the view to the original default center of view"))
  381. viewSizer.Add(center, flag=wx.TOP | wx.BOTTOM |
  382. wx.ALIGN_CENTER_VERTICAL, border=5)
  383. top = Button(panel, id=wx.ID_ANY, label=_("top"))
  384. top.Bind(wx.EVT_BUTTON, self.OnLookAt)
  385. top.SetName('top')
  386. top.SetToolTip(
  387. _("Sets the viewer directly over the scene's center position. This top view orients approximately north south."))
  388. viewSizer.Add(top, flag=wx.TOP | wx.BOTTOM |
  389. wx.ALIGN_CENTER_VERTICAL, border=5)
  390. reset = Button(panel, id=wx.ID_ANY, label=_("reset"))
  391. reset.SetToolTip(_("Reset to default view"))
  392. reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  393. viewSizer.Add(reset, proportion=0,
  394. flag=wx.TOP | wx.BOTTOM | wx.RIGHT | wx.ALIGN_RIGHT,
  395. border=5)
  396. gridSizer.Add(viewSizer, pos=(4, 0), span=(1, 3),
  397. flag=wx.EXPAND)
  398. # body
  399. boxSizer.Add(gridSizer, proportion=1,
  400. flag=wx.ALL | wx.EXPAND, border=2)
  401. pageSizer.Add(boxSizer, proportion=0,
  402. flag=wx.EXPAND | wx.ALL,
  403. border=3)
  404. box = StaticBox(parent=panel, id=wx.ID_ANY,
  405. label=" %s " % (_("Image Appearance")))
  406. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  407. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  408. # background color
  409. self.win['view']['background'] = {}
  410. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  411. label=_("Background color:")),
  412. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  413. color = csel.ColourSelect(
  414. panel,
  415. id=wx.ID_ANY,
  416. colour=UserSettings.Get(
  417. group='nviz',
  418. key='view',
  419. subkey=[
  420. 'background',
  421. 'color']),
  422. size=globalvar.DIALOG_COLOR_SIZE)
  423. self.win['view']['background']['color'] = color.GetId()
  424. color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
  425. gridSizer.Add(color, pos=(0, 1))
  426. gridSizer.AddGrowableCol(0)
  427. boxSizer.Add(gridSizer, proportion=1,
  428. flag=wx.ALL | wx.EXPAND, border=3)
  429. pageSizer.Add(boxSizer, proportion=0,
  430. flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
  431. border=3)
  432. panel.SetSizer(pageSizer)
  433. return panel
  434. def _createAnimationPage(self):
  435. """Create view settings page"""
  436. panel = SP.ScrolledPanel(parent=self, id=wx.ID_ANY)
  437. panel.SetupScrolling(scroll_x=False)
  438. self.page['animation'] = {'id': 0,
  439. 'notebook': self.GetId()}
  440. pageSizer = wx.BoxSizer(wx.VERTICAL)
  441. box = StaticBox(parent=panel, id=wx.ID_ANY,
  442. label=" %s " % (_("Animation")))
  443. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  444. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  445. self.win['anim'] = {}
  446. # animation help text
  447. help = StaticText(
  448. parent=panel, id=wx.ID_ANY, label=_(
  449. "Press 'Record' button and start changing the view. "
  450. "It is recommended to use fly-through mode "
  451. "(Map Display toolbar) to achieve smooth motion."))
  452. self.win['anim']['help'] = help.GetId()
  453. hSizer.Add(help, proportion=0)
  454. boxSizer.Add(hSizer, proportion=1,
  455. flag=wx.ALL | wx.EXPAND, border=5)
  456. # animation controls
  457. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  458. record = SymbolButton(parent=panel, id=wx.ID_ANY,
  459. usage="record", label=_("Record"))
  460. play = SymbolButton(parent=panel, id=wx.ID_ANY,
  461. usage="play", label=_("Play"))
  462. pause = SymbolButton(parent=panel, id=wx.ID_ANY,
  463. usage="pause", label=_("Pause"))
  464. stop = SymbolButton(parent=panel, id=wx.ID_ANY,
  465. usage="stop", label=_("Stop"))
  466. self.win['anim']['record'] = record.GetId()
  467. self.win['anim']['play'] = play.GetId()
  468. self.win['anim']['pause'] = pause.GetId()
  469. self.win['anim']['stop'] = stop.GetId()
  470. self._createControl(
  471. panel, data=self.win['anim'], name='frameIndex', range=(
  472. 0, 1), floatSlider=False, bind=(
  473. self.OnFrameIndex, None, self.OnFrameIndexText))
  474. frameSlider = self.FindWindowById(
  475. self.win['anim']['frameIndex']['slider'])
  476. frameText = self.FindWindowById(self.win['anim']['frameIndex']['text'])
  477. infoLabel = StaticText(
  478. parent=panel,
  479. id=wx.ID_ANY,
  480. label=_("Total number of frames :"))
  481. info = StaticText(parent=panel, id=wx.ID_ANY)
  482. self.win['anim']['info'] = info.GetId()
  483. fpsLabel = StaticText(
  484. parent=panel,
  485. id=wx.ID_ANY,
  486. label=_("Frame rate (FPS):"))
  487. fps = SpinCtrl(
  488. parent=panel, id=wx.ID_ANY, size=(65, -1),
  489. initial=UserSettings.Get(
  490. group='nviz', key='animation', subkey='fps'),
  491. min=1, max=50)
  492. self.win['anim']['fps'] = fps.GetId()
  493. fps.SetToolTip(
  494. _("Frames are recorded with given frequency (FPS). "))
  495. record.Bind(wx.EVT_BUTTON, self.OnRecord)
  496. play.Bind(wx.EVT_BUTTON, self.OnPlay)
  497. stop.Bind(wx.EVT_BUTTON, self.OnStop)
  498. pause.Bind(wx.EVT_BUTTON, self.OnPause)
  499. fps.Bind(wx.EVT_SPINCTRL, self.OnFPS)
  500. hSizer.Add(record, proportion=0)
  501. hSizer.Add(play, proportion=0)
  502. hSizer.Add(pause, proportion=0)
  503. hSizer.Add(stop, proportion=0)
  504. boxSizer.Add(hSizer, proportion=0,
  505. flag=wx.ALL | wx.EXPAND, border=3)
  506. sliderBox = wx.BoxSizer(wx.HORIZONTAL)
  507. sliderBox.Add(
  508. frameSlider,
  509. proportion=1,
  510. border=5,
  511. flag=wx.EXPAND | wx.RIGHT)
  512. sliderBox.Add(
  513. frameText,
  514. proportion=0,
  515. border=5,
  516. flag=wx.EXPAND | wx.RIGHT | wx.LEFT)
  517. boxSizer.Add(sliderBox, proportion=0, flag=wx.EXPAND)
  518. # total number of frames
  519. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  520. hSizer.Add(infoLabel, proportion=0, flag=wx.RIGHT, border=5)
  521. hSizer.Add(info, proportion=0, flag=wx.LEFT, border=5)
  522. boxSizer.Add(hSizer, proportion=0,
  523. flag=wx.ALL | wx.EXPAND, border=5)
  524. # frames per second
  525. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  526. hSizer.Add(
  527. fpsLabel,
  528. proportion=0,
  529. flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL,
  530. border=5)
  531. hSizer.Add(fps, proportion=0, flag=wx.LEFT |
  532. wx.ALIGN_CENTER_VERTICAL, border=5)
  533. boxSizer.Add(hSizer, proportion=0,
  534. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  535. pageSizer.Add(boxSizer, proportion=0,
  536. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  537. border=3)
  538. # save animation
  539. self.win['anim']['save'] = {}
  540. self.win['anim']['save']['image'] = {}
  541. box = StaticBox(parent=panel, id=wx.ID_ANY,
  542. label=" %s " % (_("Save image sequence")))
  543. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  544. vSizer = wx.BoxSizer(wx.VERTICAL)
  545. gridSizer = wx.GridBagSizer(vgap=5, hgap=10)
  546. pwd = os.getcwd()
  547. dir = filebrowse.DirBrowseButton(
  548. parent=panel,
  549. id=wx.ID_ANY,
  550. labelText=_("Choose a directory:"),
  551. dialogTitle=_("Choose a directory for images"),
  552. buttonText=_('Browse'),
  553. startDirectory=pwd)
  554. dir.SetValue(pwd)
  555. prefixLabel = StaticText(
  556. parent=panel,
  557. id=wx.ID_ANY,
  558. label=_("File prefix:"))
  559. prefixCtrl = TextCtrl(
  560. parent=panel, id=wx.ID_ANY, size=(100, -1),
  561. value=UserSettings.Get(
  562. group='nviz', key='animation', subkey='prefix'))
  563. prefixCtrl.SetToolTip(
  564. _("Generated files names will look like this: prefix_1.ppm, prefix_2.ppm, ..."))
  565. fileTypeLabel = StaticText(
  566. parent=panel, id=wx.ID_ANY, label=_("File format:"))
  567. fileTypeCtrl = wx.Choice(
  568. parent=panel, id=wx.ID_ANY, choices=[
  569. "TIF", "PPM"])
  570. save = Button(parent=panel, id=wx.ID_ANY,
  571. label="Save")
  572. self.win['anim']['save']['image']['dir'] = dir.GetId()
  573. self.win['anim']['save']['image']['prefix'] = prefixCtrl.GetId()
  574. self.win['anim']['save']['image']['format'] = fileTypeCtrl.GetId()
  575. self.win['anim']['save']['image']['confirm'] = save.GetId()
  576. boxSizer.Add(dir, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  577. gridSizer.Add(
  578. prefixLabel, pos=(0, 0),
  579. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  580. gridSizer.Add(prefixCtrl, pos=(0, 1), flag=wx.EXPAND)
  581. gridSizer.Add(
  582. fileTypeLabel, pos=(1, 0),
  583. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  584. gridSizer.Add(fileTypeCtrl, pos=(1, 1), flag=wx.EXPAND)
  585. boxSizer.Add(gridSizer, proportion=1,
  586. flag=wx.ALL | wx.EXPAND, border=5)
  587. boxSizer.Add(
  588. save,
  589. proportion=0,
  590. flag=wx.ALL | wx.ALIGN_RIGHT,
  591. border=5)
  592. save.Bind(wx.EVT_BUTTON, self.OnSaveAnimation)
  593. pageSizer.Add(boxSizer, proportion=0,
  594. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  595. border=3)
  596. panel.SetSizer(pageSizer)
  597. return panel
  598. def _createDataPage(self):
  599. """Create data (surface, vector, volume) settings page"""
  600. self.mainPanelData = ScrolledPanel(parent=self)
  601. self.mainPanelData.SetupScrolling(scroll_x=False)
  602. try: # wxpython <= 2.8.10
  603. self.foldpanelData = fpb.FoldPanelBar(
  604. parent=self.mainPanelData, id=wx.ID_ANY,
  605. style=fpb.FPB_DEFAULT_STYLE, extraStyle=fpb.FPB_SINGLE_FOLD)
  606. except:
  607. try: # wxpython >= 2.8.11
  608. self.foldpanelData = fpb.FoldPanelBar(
  609. parent=self.mainPanelData, id=wx.ID_ANY,
  610. agwStyle=fpb.FPB_SINGLE_FOLD)
  611. except: # to be sure
  612. self.foldpanelData = fpb.FoldPanelBar(
  613. parent=self.mainPanelData, id=wx.ID_ANY,
  614. style=fpb.FPB_SINGLE_FOLD)
  615. self.foldpanelData.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  616. # # surface page
  617. surfacePanel = self.foldpanelData.AddFoldPanel(
  618. _("Surface"), collapsed=False)
  619. self.foldpanelData.AddFoldPanelWindow(
  620. surfacePanel, window=self._createSurfacePage(
  621. parent=surfacePanel), flags=fpb.FPB_ALIGN_WIDTH)
  622. self.EnablePage("surface", enabled=False)
  623. # constant page
  624. constantPanel = self.foldpanelData.AddFoldPanel(
  625. _("Constant surface"), collapsed=True)
  626. self.foldpanelData.AddFoldPanelWindow(
  627. constantPanel, window=self._createConstantPage(
  628. parent=constantPanel), flags=fpb.FPB_ALIGN_WIDTH)
  629. self.EnablePage("constant", enabled=False)
  630. # vector page
  631. vectorPanel = self.foldpanelData.AddFoldPanel(
  632. _("Vector"), collapsed=True)
  633. self.foldpanelData.AddFoldPanelWindow(
  634. vectorPanel, window=self._createVectorPage(
  635. parent=vectorPanel), flags=fpb.FPB_ALIGN_WIDTH)
  636. self.EnablePage("vector", enabled=False)
  637. # volume page
  638. volumePanel = self.foldpanelData.AddFoldPanel(
  639. _("3D raster"), collapsed=True)
  640. self.foldpanelData.AddFoldPanelWindow(
  641. volumePanel, window=self._createVolumePage(
  642. parent=volumePanel), flags=fpb.FPB_ALIGN_WIDTH)
  643. self.EnablePage("volume", enabled=False)
  644. # self.foldpanelData.ApplyCaptionStyleAll(style)
  645. sizer = wx.BoxSizer(wx.VERTICAL)
  646. sizer.Add(self.foldpanelData, proportion=1, flag=wx.EXPAND)
  647. self.mainPanelData.SetSizer(sizer)
  648. self.mainPanelData.Layout()
  649. self.mainPanelData.Fit()
  650. return self.mainPanelData
  651. def _createAppearancePage(self):
  652. """Create data (surface, vector, volume) settings page"""
  653. self.mainPanelAppear = ScrolledPanel(parent=self)
  654. self.mainPanelAppear.SetupScrolling(scroll_x=False)
  655. try: # wxpython <= 2.8.10
  656. self.foldpanelAppear = fpb.FoldPanelBar(
  657. parent=self.mainPanelAppear, id=wx.ID_ANY,
  658. style=fpb.FPB_DEFAULT_STYLE, extraStyle=fpb.FPB_SINGLE_FOLD)
  659. except:
  660. try: # wxpython >= 2.8.11
  661. self.foldpanelAppear = fpb.FoldPanelBar(
  662. parent=self.mainPanelAppear, id=wx.ID_ANY,
  663. agwStyle=fpb.FPB_SINGLE_FOLD)
  664. except: # to be sure
  665. self.foldpanelAppear = fpb.FoldPanelBar(
  666. parent=self.mainPanelAppear, id=wx.ID_ANY,
  667. style=fpb.FPB_SINGLE_FOLD)
  668. self.foldpanelAppear.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  669. # light page
  670. lightPanel = self.foldpanelAppear.AddFoldPanel(
  671. _("Lighting"), collapsed=False)
  672. self.foldpanelAppear.AddFoldPanelWindow(
  673. lightPanel, window=self._createLightPage(
  674. parent=lightPanel), flags=fpb.FPB_ALIGN_WIDTH)
  675. # fringe page
  676. fringePanel = self.foldpanelAppear.AddFoldPanel(
  677. _("Fringe"), collapsed=True)
  678. self.foldpanelAppear.AddFoldPanelWindow(
  679. fringePanel, window=self._createFringePage(
  680. parent=fringePanel), flags=fpb.FPB_ALIGN_WIDTH)
  681. self.EnablePage('fringe', False)
  682. # decoration page
  683. decorationPanel = self.foldpanelAppear.AddFoldPanel(
  684. _("Decorations"), collapsed=True)
  685. self.foldpanelAppear.AddFoldPanelWindow(
  686. decorationPanel, window=self._createDecorationPage(
  687. parent=decorationPanel), flags=fpb.FPB_ALIGN_WIDTH)
  688. sizer = wx.BoxSizer(wx.VERTICAL)
  689. sizer.Add(self.foldpanelAppear, proportion=1, flag=wx.EXPAND)
  690. self.mainPanelAppear.SetSizer(sizer)
  691. self.mainPanelAppear.Layout()
  692. self.mainPanelAppear.Fit()
  693. return self.mainPanelAppear
  694. def _createAnalysisPage(self):
  695. """Create data analysis (cutting planes, ...) page"""
  696. self.mainPanelAnalysis = ScrolledPanel(parent=self)
  697. self.mainPanelAnalysis.SetupScrolling(scroll_x=False)
  698. self.foldpanelAnalysis = fpb.FoldPanelBar(
  699. parent=self.mainPanelAnalysis, id=wx.ID_ANY,
  700. style=fpb.FPB_SINGLE_FOLD)
  701. self.foldpanelAnalysis.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  702. # cutting planes page
  703. cplanePanel = self.foldpanelAnalysis.AddFoldPanel(
  704. _("Cutting planes"), collapsed=False)
  705. self.foldpanelAnalysis.AddFoldPanelWindow(
  706. cplanePanel, window=self._createCPlanePage(
  707. parent=cplanePanel), flags=fpb.FPB_ALIGN_WIDTH)
  708. sizer = wx.BoxSizer(wx.VERTICAL)
  709. sizer.Add(self.foldpanelAnalysis, proportion=1, flag=wx.EXPAND)
  710. self.mainPanelAnalysis.SetSizer(sizer)
  711. self.mainPanelAnalysis.Layout()
  712. self.mainPanelAnalysis.Fit()
  713. return self.mainPanelAnalysis
  714. def _createSurfacePage(self, parent):
  715. """Create view settings page"""
  716. panel = wx.Panel(parent=parent, id=wx.ID_ANY)
  717. self.page['surface'] = {'id': 0,
  718. 'notebook': self.foldpanelData.GetId()}
  719. pageSizer = wx.BoxSizer(wx.VERTICAL)
  720. self.win['surface'] = {}
  721. # selection
  722. box = StaticBox(parent=panel, id=wx.ID_ANY,
  723. label=" %s " % (_("Raster map")))
  724. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  725. rmaps = Select(parent=panel, type='raster',
  726. onPopup=self.GselectOnPopup)
  727. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster)
  728. self.win['surface']['map'] = rmaps.GetId()
  729. desc = StaticText(parent=panel, id=wx.ID_ANY)
  730. self.win['surface']['desc'] = desc.GetId()
  731. boxSizer.Add(rmaps, proportion=0,
  732. flag=wx.ALL,
  733. border=3)
  734. boxSizer.Add(desc, proportion=0,
  735. flag=wx.ALL,
  736. border=3)
  737. pageSizer.Add(boxSizer, proportion=0,
  738. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  739. border=3)
  740. #
  741. # draw
  742. #
  743. self.win['surface']['draw'] = {}
  744. box = StaticBox(parent=panel, id=wx.ID_ANY,
  745. label=" %s " % (_("Draw")))
  746. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  747. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  748. # mode
  749. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  750. label=_("Mode:")),
  751. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  752. mode = wx.Choice(parent=panel, id=wx.ID_ANY, size=(-1, -1),
  753. choices=[_("coarse"),
  754. _("fine"),
  755. _("both")])
  756. mode.SetName("selection")
  757. mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  758. self.win['surface']['draw']['mode'] = mode.GetId()
  759. gridSizer.Add(mode, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  760. pos=(0, 1), span=(1, 2))
  761. # shading
  762. gridSizer.Add(
  763. StaticText(
  764. parent=panel, id=wx.ID_ANY, label=_("Shading:")), pos=(
  765. 0, 3), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  766. shade = wx.Choice(parent=panel, id=wx.ID_ANY, size=(-1, -1),
  767. choices=[_("flat"),
  768. _("gouraud")])
  769. shade.SetName("selection")
  770. self.win['surface']['draw']['shading'] = shade.GetId()
  771. shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  772. gridSizer.Add(shade, flag=wx.ALIGN_CENTER_VERTICAL,
  773. pos=(0, 4))
  774. # set to all
  775. all = Button(panel, id=wx.ID_ANY, label=_("Set to all"))
  776. all.SetToolTip(_("Use draw settings for all loaded surfaces"))
  777. all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
  778. gridSizer.Add(
  779. all,
  780. flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  781. pos=(
  782. 3,
  783. 4))
  784. self.win['surface']['all'] = all.GetId()
  785. # resolution coarse
  786. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  787. label=_("Coarse mode:")),
  788. pos=(2, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  789. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  790. label=_("resolution:")),
  791. pos=(2, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  792. resC = SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  793. initial=6,
  794. min=1,
  795. max=100)
  796. resC.SetName("value")
  797. self.win['surface']['draw']['res-coarse'] = resC.GetId()
  798. resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  799. gridSizer.Add(
  800. resC, pos=(2, 2),
  801. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  802. # Coarse style
  803. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  804. label=_("style:")),
  805. pos=(3, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  806. style = wx.Choice(parent=panel, id=wx.ID_ANY, size=(100, -1),
  807. choices=[_("wire"),
  808. _("surface")])
  809. style.SetName("selection")
  810. self.win['surface']['draw']['style'] = style.GetId()
  811. style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  812. gridSizer.Add(style, flag=wx.ALIGN_CENTER_VERTICAL,
  813. pos=(3, 2))
  814. # color
  815. color = ColourSelect(panel, id=wx.ID_ANY,
  816. size=globalvar.DIALOG_COLOR_SIZE)
  817. color.SetName("colour")
  818. color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
  819. color.SetToolTip(_("Change wire color"))
  820. self.win['surface']['draw']['wire-color'] = color.GetId()
  821. gridSizer.Add(
  822. color,
  823. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  824. pos=(
  825. 3,
  826. 3))
  827. # resolution fine
  828. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  829. label=_("Fine mode:")),
  830. pos=(1, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  831. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  832. label=_("resolution:")),
  833. pos=(1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  834. resF = SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  835. initial=3,
  836. min=1,
  837. max=100)
  838. resF.SetName("value")
  839. self.win['surface']['draw']['res-fine'] = resF.GetId()
  840. resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  841. gridSizer.Add(
  842. resF, pos=(1, 2),
  843. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  844. gridSizer.AddGrowableCol(3)
  845. boxSizer.Add(gridSizer, proportion=1,
  846. flag=wx.ALL | wx.EXPAND, border=3)
  847. pageSizer.Add(boxSizer, proportion=0,
  848. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  849. border=3)
  850. #
  851. # surface attributes
  852. #
  853. box = StaticBox(parent=panel, id=wx.ID_ANY,
  854. label=" %s " % (_("Surface attributes")))
  855. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  856. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  857. # type
  858. self.win['surface']['attr'] = {}
  859. row = 0
  860. for code, attrb in (('color', _("Color")),
  861. ('mask', _("Mask")),
  862. ('transp', _("Transparency")),
  863. ('shine', _("Shininess"))):
  864. self.win['surface'][code] = {}
  865. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  866. label=attrb + ':'),
  867. pos=(row, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  868. use = wx.Choice(parent=panel, id=wx.ID_ANY, size=(100, -1),
  869. choices=[_("map")])
  870. if code not in ('color', 'shine'):
  871. use.Insert(item=_("unset"), pos=0)
  872. self.win['surface'][code]['required'] = False
  873. else:
  874. self.win['surface'][code]['required'] = True
  875. if code != 'mask':
  876. use.Append(item=_('constant'))
  877. self.win['surface'][code]['use'] = use.GetId()
  878. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  879. gridSizer.Add(use, flag=wx.ALIGN_CENTER_VERTICAL,
  880. pos=(row, 1))
  881. map = Select(parent=panel, id=wx.ID_ANY,
  882. # size = globalvar.DIALOG_GSELECT_SIZE,
  883. size=(-1, -1),
  884. type="raster")
  885. if globalvar.CheckWxVersion([3]):
  886. self.win['surface'][code]['map'] = map.GetId()
  887. else:
  888. self.win['surface'][code]['map'] = map.GetTextCtrl().GetId()
  889. map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  890. gridSizer.Add(map, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  891. pos=(row, 2))
  892. if code == 'color':
  893. color = UserSettings.Get(
  894. group='nviz', key='surface', subkey=[
  895. 'color', 'value'])
  896. value = csel.ColourSelect(panel, id=wx.ID_ANY,
  897. colour=color,
  898. size=globalvar.DIALOG_COLOR_SIZE)
  899. value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
  900. elif code == 'mask':
  901. value = None
  902. else:
  903. value = SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  904. initial=0)
  905. value.SetRange(minVal=0, maxVal=100)
  906. value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  907. if value:
  908. self.win['surface'][code]['const'] = value.GetId()
  909. value.Enable(False)
  910. gridSizer.Add(value, flag=wx.ALIGN_CENTER_VERTICAL,
  911. pos=(row, 3))
  912. else:
  913. self.win['surface'][code]['const'] = None
  914. # -> enable map / disable constant
  915. self.SetMapObjUseMap(nvizType='surface', attrb=code)
  916. row += 1
  917. gridSizer.AddGrowableCol(2)
  918. boxSizer.Add(gridSizer, proportion=0,
  919. flag=wx.ALL | wx.EXPAND, border=3)
  920. pageSizer.Add(boxSizer, proportion=0,
  921. flag=wx.EXPAND | wx.ALL,
  922. border=3)
  923. #
  924. # position
  925. #
  926. self.win['surface']['position'] = {}
  927. box = StaticBox(parent=panel, id=wx.ID_ANY,
  928. label=" %s " % (_("Position")))
  929. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  930. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  931. # position
  932. tooltip = _("Changes the x, y, and z position of the current surface")
  933. self._createControl(panel,
  934. data=self.win['surface'],
  935. name='position',
  936. tooltip=tooltip,
  937. range=(-10000,
  938. 10000),
  939. floatSlider=True,
  940. bind=(self.OnSurfacePosition,
  941. self.OnSurfacePositionChanged,
  942. self.OnSurfacePositionText))
  943. axis = wx.Choice(parent=panel, id=wx.ID_ANY, size=(75, -1),
  944. choices=["X",
  945. "Y",
  946. "Z"])
  947. reset = Button(panel, id=wx.ID_ANY, label=_("Reset"))
  948. reset.SetToolTip(_("Reset to default position"))
  949. reset.Bind(wx.EVT_BUTTON, self.OnResetSurfacePosition)
  950. self.win['surface']['position']['reset'] = reset.GetId()
  951. self.win['surface']['position']['axis'] = axis.GetId()
  952. axis.SetSelection(2)
  953. axis.Bind(wx.EVT_CHOICE, self.OnSurfaceAxis)
  954. pslide = self.FindWindowById(self.win['surface']['position']['slider'])
  955. ptext = self.FindWindowById(self.win['surface']['position']['text'])
  956. ptext.SetValue('0')
  957. gridSizer.Add(axis, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
  958. gridSizer.Add(pslide, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 1))
  959. gridSizer.Add(ptext, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 2))
  960. gridSizer.Add(
  961. reset,
  962. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  963. pos=(
  964. 0,
  965. 3))
  966. gridSizer.AddGrowableCol(3)
  967. boxSizer.Add(gridSizer, proportion=1,
  968. flag=wx.ALL | wx.EXPAND, border=3)
  969. pageSizer.Add(boxSizer, proportion=1,
  970. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  971. border=3)
  972. #
  973. # mask
  974. #
  975. # box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  976. # label = " %s " % (_("Mask")))
  977. ## boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  978. ## gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  979. ##
  980. # gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  981. # label = _("Mask zeros:")),
  982. # pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  983. ##
  984. # elev = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  985. # label = _("by elevation"))
  986. # elev.Enable(False) # TODO: not implemented yet
  987. ## gridSizer.Add(item = elev, pos = (0, 1))
  988. ##
  989. # color = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  990. # label = _("by color"))
  991. # color.Enable(False) # TODO: not implemented yet
  992. ## gridSizer.Add(item = color, pos = (0, 2))
  993. ##
  994. # boxSizer.Add(item = gridSizer, proportion = 1,
  995. # flag = wx.ALL | wx.EXPAND, border = 3)
  996. # pageSizer.Add(item = boxSizer, proportion = 0,
  997. ## flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  998. # border = 3)
  999. panel.SetSizer(pageSizer)
  1000. panel.Layout()
  1001. panel.Fit()
  1002. return panel
  1003. def _createCPlanePage(self, parent):
  1004. """Create cutting planes page"""
  1005. panel = wx.Panel(parent=parent, id=wx.ID_ANY)
  1006. self.page['cplane'] = {'id': 4,
  1007. 'notebook': self.foldpanelData.GetId()}
  1008. self.win['cplane'] = {}
  1009. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1010. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1011. label=" %s " % (_("Cutting planes")))
  1012. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1013. horSizer = wx.BoxSizer(wx.HORIZONTAL)
  1014. # planes
  1015. horSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1016. label=_("Active cutting plane:")),
  1017. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  1018. choice = wx.Choice(parent=panel, id=wx.ID_ANY, choices=[])
  1019. self.win['cplane']['planes'] = choice.GetId()
  1020. choice.Bind(wx.EVT_CHOICE, self.OnCPlaneSelection)
  1021. horSizer.Add(choice, flag=wx.ALL, border=5)
  1022. # shading
  1023. horSizer.Add(wx.Size(-1, -1), proportion=1)
  1024. horSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1025. label=_("Shading:")),
  1026. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  1027. choices = [_("clear"),
  1028. _("top color"),
  1029. _("bottom color"),
  1030. _("blend"),
  1031. _("shaded")]
  1032. choice = wx.Choice(parent=panel, id=wx.ID_ANY, choices=choices)
  1033. self.win['cplane']['shading'] = choice.GetId()
  1034. choice.Bind(wx.EVT_CHOICE, self.OnCPlaneShading)
  1035. horSizer.Add(choice, flag=wx.ALL, border=5)
  1036. boxSizer.Add(horSizer, flag=wx.EXPAND)
  1037. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1038. # cutting plane horizontal x position
  1039. self.win['cplane']['position'] = {}
  1040. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1041. label=_("Horizontal X:")),
  1042. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1043. tooltip = _("Sets the X coordinate of the current cutting plane")
  1044. self._createControl(panel,
  1045. data=self.win['cplane']['position'],
  1046. name='x',
  1047. size=250,
  1048. range=(-1000,
  1049. 1000),
  1050. sliderHor=True,
  1051. floatSlider=True,
  1052. tooltip=tooltip,
  1053. bind=(self.OnCPlaneChanging,
  1054. self.OnCPlaneChangeDone,
  1055. self.OnCPlaneChangeText))
  1056. self.FindWindowById(self.win['cplane']['position'][
  1057. 'x']['slider']).SetValue(0)
  1058. self.FindWindowById(self.win['cplane']['position'][
  1059. 'x']['text']).SetValue(0)
  1060. gridSizer.Add(
  1061. self.FindWindowById(
  1062. self.win['cplane']['position']['x']['slider']), pos=(
  1063. 0, 1), flag=wx.EXPAND | wx.ALIGN_RIGHT)
  1064. gridSizer.Add(
  1065. self.FindWindowById(
  1066. self.win['cplane']['position']['x']['text']), pos=(
  1067. 0, 2), flag=wx.ALIGN_CENTER)
  1068. # cutting plane horizontal y position
  1069. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1070. label=_("Horizontal Y:")),
  1071. pos=(1, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1072. tooltip = _("Sets the Y coordinate of the current cutting plane")
  1073. self._createControl(panel,
  1074. data=self.win['cplane']['position'],
  1075. name='y',
  1076. size=250,
  1077. range=(-1000,
  1078. 1000),
  1079. sliderHor=True,
  1080. floatSlider=True,
  1081. tooltip=tooltip,
  1082. bind=(self.OnCPlaneChanging,
  1083. self.OnCPlaneChangeDone,
  1084. self.OnCPlaneChangeText))
  1085. self.FindWindowById(self.win['cplane']['position'][
  1086. 'y']['slider']).SetValue(0)
  1087. self.FindWindowById(self.win['cplane']['position'][
  1088. 'y']['text']).SetValue(0)
  1089. gridSizer.Add(
  1090. self.FindWindowById(
  1091. self.win['cplane']['position']['y']['slider']), pos=(
  1092. 1, 1), flag=wx.EXPAND | wx.ALIGN_RIGHT)
  1093. gridSizer.Add(
  1094. self.FindWindowById(
  1095. self.win['cplane']['position']['y']['text']), pos=(
  1096. 1, 2), flag=wx.ALIGN_CENTER)
  1097. # cutting plane rotation
  1098. self.win['cplane']['rotation'] = {}
  1099. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1100. label=_("Rotation:")),
  1101. pos=(2, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1102. tooltip = _("Rotates the current cutting plane about vertical axis")
  1103. self._createControl(
  1104. panel, data=self.win['cplane']['rotation'], name='rot', size=250, range=(
  1105. 0, 360), sliderHor=True, tooltip=tooltip, bind=(
  1106. self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  1107. self.FindWindowById(self.win['cplane']['rotation'][
  1108. 'rot']['slider']).SetValue(180)
  1109. self.FindWindowById(self.win['cplane']['rotation'][
  1110. 'rot']['text']).SetValue(180)
  1111. gridSizer.Add(
  1112. self.FindWindowById(
  1113. self.win['cplane']['rotation']['rot']['slider']), pos=(
  1114. 2, 1), flag=wx.EXPAND | wx.ALIGN_RIGHT)
  1115. gridSizer.Add(
  1116. self.FindWindowById(
  1117. self.win['cplane']['rotation']['rot']['text']), pos=(
  1118. 2, 2), flag=wx.ALIGN_CENTER)
  1119. # cutting plane tilt
  1120. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1121. label=_("Tilt:")),
  1122. pos=(3, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1123. tooltip = _("Rotates the current cutting plane about horizontal axis")
  1124. self._createControl(
  1125. panel, data=self.win['cplane']['rotation'], name='tilt', size=250, range=(
  1126. 0, 360), sliderHor=True, tooltip=tooltip, bind=(
  1127. self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  1128. self.FindWindowById(self.win['cplane']['rotation'][
  1129. 'tilt']['slider']).SetValue(0)
  1130. self.FindWindowById(self.win['cplane']['rotation'][
  1131. 'tilt']['text']).SetValue(0)
  1132. gridSizer.Add(
  1133. self.FindWindowById(
  1134. self.win['cplane']['rotation']['tilt']['slider']), pos=(
  1135. 3, 1), flag=wx.EXPAND | wx.ALIGN_RIGHT)
  1136. gridSizer.Add(
  1137. self.FindWindowById(
  1138. self.win['cplane']['rotation']['tilt']['text']), pos=(
  1139. 3, 2), flag=wx.ALIGN_CENTER)
  1140. # cutting pland height
  1141. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1142. label=_("Height:")),
  1143. pos=(4, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1144. tooltip = _(
  1145. "Sets the Z coordinate of the current cutting plane (only meaningful when tilt is not 0)")
  1146. self._createControl(panel,
  1147. data=self.win['cplane']['position'],
  1148. name='z',
  1149. size=250,
  1150. range=(-1000,
  1151. 1000),
  1152. sliderHor=True,
  1153. tooltip=tooltip,
  1154. bind=(self.OnCPlaneChanging,
  1155. self.OnCPlaneChangeDone,
  1156. self.OnCPlaneChangeText))
  1157. self.FindWindowById(self.win['cplane']['position'][
  1158. 'z']['slider']).SetValue(0)
  1159. self.FindWindowById(self.win['cplane']['position'][
  1160. 'z']['text']).SetValue(0)
  1161. gridSizer.Add(
  1162. self.FindWindowById(
  1163. self.win['cplane']['position']['z']['slider']), pos=(
  1164. 4, 1), flag=wx.EXPAND | wx.ALIGN_RIGHT)
  1165. gridSizer.Add(
  1166. self.FindWindowById(
  1167. self.win['cplane']['position']['z']['text']), pos=(
  1168. 4, 2), flag=wx.ALIGN_CENTER)
  1169. boxSizer.Add(
  1170. gridSizer,
  1171. proportion=0,
  1172. flag=wx.EXPAND | wx.ALL,
  1173. border=5)
  1174. horSizer = wx.BoxSizer(wx.HORIZONTAL)
  1175. horSizer.Add(wx.Size(-1, -1), proportion=1, flag=wx.ALL, border=5)
  1176. # reset
  1177. reset = Button(parent=panel, id=wx.ID_ANY, label=_("Reset"))
  1178. self.win['cplane']['reset'] = reset.GetId()
  1179. reset.Bind(wx.EVT_BUTTON, self.OnCPlaneReset)
  1180. horSizer.Add(reset, flag=wx.ALL, border=5)
  1181. boxSizer.Add(horSizer, proportion=0, flag=wx.EXPAND)
  1182. pageSizer.Add(boxSizer, proportion=0, flag=wx.EXPAND)
  1183. panel.SetSizer(pageSizer)
  1184. panel.Fit()
  1185. return panel
  1186. def _createConstantPage(self, parent):
  1187. """Create constant page"""
  1188. panel = wx.Panel(parent=parent, id=wx.ID_ANY)
  1189. self.page['constant'] = {'id': 1,
  1190. 'notebook': self.foldpanelData.GetId()}
  1191. self.win['constant'] = {}
  1192. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1193. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1194. label=" %s " % (_("Constant surface")))
  1195. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1196. horsizer = wx.BoxSizer(wx.HORIZONTAL)
  1197. surface = wx.ComboBox(parent=panel, id=wx.ID_ANY,
  1198. style=wx.CB_SIMPLE | wx.CB_READONLY,
  1199. choices=[])
  1200. self.win['constant']['surface'] = surface.GetId()
  1201. surface.Bind(wx.EVT_COMBOBOX, self.OnConstantSelection)
  1202. horsizer.Add(
  1203. surface,
  1204. proportion=1,
  1205. flag=wx.EXPAND | wx.RIGHT,
  1206. border=20)
  1207. addNew = Button(panel, id=wx.ID_ANY, label=_("New"))
  1208. addNew.Bind(wx.EVT_BUTTON, self.OnNewConstant)
  1209. self.win['constant']['new'] = addNew.GetId()
  1210. delete = Button(panel, id=wx.ID_ANY, label=_("Delete"))
  1211. delete.Bind(wx.EVT_BUTTON, self.OnDeleteConstant)
  1212. self.win['constant']['delete'] = delete.GetId()
  1213. horsizer.Add(
  1214. addNew,
  1215. proportion=0,
  1216. flag=wx.RIGHT | wx.LEFT,
  1217. border=3)
  1218. horsizer.Add(
  1219. delete,
  1220. proportion=0,
  1221. flag=wx.RIGHT | wx.LEFT,
  1222. border=3)
  1223. boxSizer.Add(horsizer, proportion=0, flag=wx.ALL | wx.EXPAND,
  1224. border=5)
  1225. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1226. # fine resolution
  1227. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1228. label=_("Fine resolution:")),
  1229. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1230. resF = SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  1231. initial=3,
  1232. min=1,
  1233. max=100)
  1234. resF.SetName("value")
  1235. self.win['constant']['resolution'] = resF.GetId()
  1236. resF.Bind(wx.EVT_SPINCTRL, self.OnSetConstantProp)
  1237. gridSizer.Add(
  1238. resF, pos=(0, 1),
  1239. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  1240. # value
  1241. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1242. label=_("Value:")), pos=(1, 0),
  1243. flag=wx.ALIGN_CENTER_VERTICAL)
  1244. value = SpinCtrl(panel, id=wx.ID_ANY,
  1245. min=-1e9, max=1e9,
  1246. size=(65, -1))
  1247. self.win['constant']['value'] = value.GetId()
  1248. value.Bind(wx.EVT_SPINCTRL, self.OnSetConstantProp)
  1249. gridSizer.Add(value, pos=(1, 1))
  1250. # transparency
  1251. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1252. label=_("Transparency:")), pos=(2, 0),
  1253. flag=wx.ALIGN_CENTER_VERTICAL)
  1254. transp = SpinCtrl(panel, id=wx.ID_ANY,
  1255. min=0, max=100,
  1256. size=(65, -1))
  1257. self.win['constant']['transp'] = transp.GetId()
  1258. transp.Bind(wx.EVT_SPINCTRL, self.OnSetConstantProp)
  1259. gridSizer.Add(transp, pos=(2, 1))
  1260. # color
  1261. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1262. label=_("Color:")), pos=(3, 0),
  1263. flag=wx.ALIGN_CENTER_VERTICAL)
  1264. color = csel.ColourSelect(panel, id=wx.ID_ANY,
  1265. colour=(0, 0, 0),
  1266. size=globalvar.DIALOG_COLOR_SIZE)
  1267. self.win['constant']['color'] = color.GetId()
  1268. color.Bind(csel.EVT_COLOURSELECT, self.OnSetConstantProp)
  1269. gridSizer.Add(color, pos=(3, 1))
  1270. boxSizer.Add(gridSizer, proportion=0, flag=wx.ALL,
  1271. border=5)
  1272. pageSizer.Add(boxSizer, proportion=0,
  1273. flag=wx.EXPAND | wx.ALL,
  1274. border=3)
  1275. panel.SetSizer(pageSizer)
  1276. panel.Fit()
  1277. return panel
  1278. def _createVectorPage(self, parent):
  1279. """Create view settings page"""
  1280. panel = wx.Panel(parent=parent, id=wx.ID_ANY)
  1281. self.page['vector'] = {'id': 2,
  1282. 'notebook': self.foldpanelData.GetId()}
  1283. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1284. self.win['vector'] = {}
  1285. # selection
  1286. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1287. label=" %s " % (_("Vector map")))
  1288. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1289. vmaps = Select(parent=panel, type='vector',
  1290. onPopup=self.GselectOnPopup)
  1291. vmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetVector)
  1292. self.win['vector']['map'] = vmaps.GetId()
  1293. desc = StaticText(parent=panel, id=wx.ID_ANY)
  1294. self.win['vector']['desc'] = desc.GetId()
  1295. boxSizer.Add(vmaps, proportion=0,
  1296. flag=wx.ALL,
  1297. border=3)
  1298. boxSizer.Add(desc, proportion=0,
  1299. flag=wx.ALL,
  1300. border=3)
  1301. pageSizer.Add(boxSizer, proportion=0,
  1302. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1303. border=3)
  1304. #
  1305. # vector lines
  1306. #
  1307. self.win['vector']['lines'] = {}
  1308. showLines = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1309. label=_("Show vector lines"))
  1310. showLines.SetValue(True)
  1311. self.win['vector']['lines']['show'] = showLines.GetId()
  1312. showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  1313. pageSizer.Add(showLines, proportion=0, flag=wx.LEFT |
  1314. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  1315. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1316. label=" %s " % (_("Vector lines")))
  1317. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1318. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  1319. # width
  1320. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1321. label=_("Line:")),
  1322. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1323. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1324. label=_("width:")),
  1325. pos=(0, 1), flag=wx.ALIGN_CENTER_VERTICAL |
  1326. wx.ALIGN_RIGHT)
  1327. width = SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  1328. initial=1,
  1329. min=1,
  1330. max=100)
  1331. width.SetValue(1)
  1332. self.win['vector']['lines']['width'] = width.GetId()
  1333. width.Bind(wx.EVT_SPINCTRL, self.OnVectorLines)
  1334. gridSizer.Add(width, pos=(0, 2),
  1335. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1336. # color
  1337. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1338. label=_("color:")),
  1339. pos=(0, 3), flag=wx.ALIGN_CENTER_VERTICAL |
  1340. wx.ALIGN_RIGHT)
  1341. color = csel.ColourSelect(panel, id=wx.ID_ANY,
  1342. colour=(0, 0, 0),
  1343. size=globalvar.DIALOG_COLOR_SIZE)
  1344. self.win['vector']['lines']['color'] = color.GetId()
  1345. color.Bind(csel.EVT_COLOURSELECT, self.OnVectorLines)
  1346. gridSizer.Add(color, pos=(0, 4), flag=wx.ALIGN_CENTER_VERTICAL |
  1347. wx.ALIGN_LEFT)
  1348. # thematic mapping
  1349. self.win['vector']['lines']['thematic'] = {}
  1350. checkThematicColor = wx.CheckBox(
  1351. parent=panel, id=wx.ID_ANY,
  1352. label=_("use color for thematic mapping"))
  1353. checkThematicWidth = wx.CheckBox(
  1354. parent=panel, id=wx.ID_ANY,
  1355. label=_("use width for thematic mapping"))
  1356. self.win['vector']['lines']['thematic'][
  1357. 'checkcolor'] = checkThematicColor.GetId()
  1358. self.win['vector']['lines']['thematic'][
  1359. 'checkwidth'] = checkThematicWidth.GetId()
  1360. checkThematicColor.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
  1361. checkThematicWidth.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
  1362. checkThematicColor.SetValue(False)
  1363. checkThematicWidth.SetValue(False)
  1364. vSizer = wx.BoxSizer(wx.VERTICAL)
  1365. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  1366. hSizer.Add(checkThematicColor, flag=wx.ALIGN_CENTER_VERTICAL,
  1367. border=5)
  1368. setThematic = Button(parent=panel, id=wx.ID_ANY,
  1369. label=_("Set options..."))
  1370. self.win['vector']['lines']['thematic'][
  1371. 'buttoncolor'] = setThematic.GetId()
  1372. setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
  1373. hSizer.Add(wx.Size(-1, -1), proportion=1)
  1374. hSizer.Add(setThematic, flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
  1375. border=5, proportion=0)
  1376. vSizer.Add(hSizer, flag=wx.EXPAND)
  1377. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  1378. hSizer.Add(checkThematicWidth, flag=wx.ALIGN_CENTER_VERTICAL,
  1379. border=5)
  1380. setThematic = Button(parent=panel, id=wx.ID_ANY,
  1381. label=_("Set options..."))
  1382. self.win['vector']['lines']['thematic'][
  1383. 'buttonwidth'] = setThematic.GetId()
  1384. setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
  1385. hSizer.Add(wx.Size(-1, -1), proportion=1)
  1386. hSizer.Add(setThematic, flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
  1387. border=5, proportion=0)
  1388. vSizer.Add(hSizer, flag=wx.EXPAND)
  1389. gridSizer.Add(vSizer, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  1390. pos=(1, 1), span=(1, 5))
  1391. # display
  1392. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1393. label=_("Display")),
  1394. pos=(2, 0), flag=wx.ALIGN_CENTER_VERTICAL |
  1395. wx.ALIGN_LEFT)
  1396. display = wx.Choice(parent=panel, id=wx.ID_ANY, size=(-1, -1),
  1397. choices=[_("on surface(s):"),
  1398. _("as 3D")])
  1399. self.win['vector']['lines']['3d'] = display.GetId()
  1400. display.Bind(wx.EVT_CHOICE, self.OnVectorLinesMode)
  1401. gridSizer.Add(display, flag=wx.ALIGN_CENTER_VERTICAL |
  1402. wx.ALIGN_LEFT | wx.EXPAND, pos=(2, 1), span=(1, 4))
  1403. # height
  1404. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1405. label=_("Height above surface:")),
  1406. pos=(3, 5), flag=wx.ALIGN_BOTTOM | wx.EXPAND)
  1407. surface = CheckListBox(parent=panel, id=wx.ID_ANY, size=(-1, 60),
  1408. choices=[], style=wx.LB_NEEDED_SB)
  1409. surface.Bind(wx.EVT_CHECKLISTBOX, self.OnVectorSurface)
  1410. self.win['vector']['lines']['surface'] = surface.GetId()
  1411. gridSizer.Add(surface,
  1412. pos=(3, 0), span=(3, 5),
  1413. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  1414. self._createControl(
  1415. panel,
  1416. data=self.win['vector']['lines'],
  1417. name='height',
  1418. size=-1,
  1419. range=(
  1420. 0,
  1421. 500),
  1422. sliderHor=True,
  1423. bind=(
  1424. self.OnVectorHeight,
  1425. self.OnVectorHeightFull,
  1426. self.OnVectorHeightText))
  1427. self.FindWindowById(self.win['vector']['lines'][
  1428. 'height']['slider']).SetValue(0)
  1429. self.FindWindowById(self.win['vector']['lines'][
  1430. 'height']['text']).SetValue(0)
  1431. gridSizer.Add(
  1432. self.FindWindowById(
  1433. self.win['vector']['lines']['height']['slider']), pos=(
  1434. 4, 5), flag=wx.EXPAND | wx.ALIGN_RIGHT)
  1435. gridSizer.Add(
  1436. self.FindWindowById(
  1437. self.win['vector']['lines']['height']['text']), pos=(
  1438. 5, 5), flag=wx.ALIGN_CENTER)
  1439. gridSizer.AddGrowableCol(5)
  1440. boxSizer.Add(gridSizer, proportion=1,
  1441. flag=wx.ALL | wx.EXPAND, border=3)
  1442. pageSizer.Add(boxSizer, proportion=0,
  1443. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1444. border=3)
  1445. #
  1446. # vector points
  1447. #
  1448. self.win['vector']['points'] = {}
  1449. showPoints = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1450. label=_("Show vector points"))
  1451. showPoints.SetValue(True)
  1452. self.win['vector']['points']['show'] = showPoints.GetId()
  1453. showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  1454. pageSizer.Add(showPoints, proportion=0, flag=wx.LEFT |
  1455. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  1456. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1457. label=" %s " % (_("Vector points")))
  1458. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1459. vertSizer = wx.BoxSizer(wx.VERTICAL)
  1460. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  1461. # icon size
  1462. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1463. label=_("Icon:")),
  1464. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1465. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1466. label=_("size:")),
  1467. pos=(0, 1), flag=wx.ALIGN_CENTER_VERTICAL |
  1468. wx.ALIGN_RIGHT)
  1469. if fs:
  1470. isize = fs.FloatSpin(parent=panel, id=wx.ID_ANY,
  1471. min_val=0, max_val=1e6,
  1472. increment=1, value=1, style=fs.FS_RIGHT)
  1473. isize.SetFormat("%f")
  1474. isize.SetDigits(1)
  1475. isize.Bind(fs.EVT_FLOATSPIN, self.OnVectorPoints)
  1476. else:
  1477. isize = SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  1478. initial=1,
  1479. min=1,
  1480. max=1e6)
  1481. isize.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  1482. isize.SetName('value')
  1483. isize.SetValue(100)
  1484. self.win['vector']['points']['size'] = isize.GetId()
  1485. gridSizer.Add(isize, pos=(0, 2),
  1486. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1487. # icon color
  1488. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1489. label=_("color:")),
  1490. pos=(0, 3), flag=wx.ALIGN_CENTER_VERTICAL |
  1491. wx.ALIGN_RIGHT)
  1492. icolor = csel.ColourSelect(panel, id=wx.ID_ANY,
  1493. size=globalvar.DIALOG_COLOR_SIZE)
  1494. icolor.SetName("color")
  1495. icolor.SetColour((0, 0, 255))
  1496. self.win['vector']['points']['color'] = icolor.GetId()
  1497. icolor.Bind(csel.EVT_COLOURSELECT, self.OnVectorPoints)
  1498. gridSizer.Add(icolor, flag=wx.ALIGN_CENTER_VERTICAL |
  1499. wx.ALIGN_LEFT,
  1500. pos=(0, 4))
  1501. # icon width - seems to do nothing
  1502. # gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1503. # label = _("width")),
  1504. # pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  1505. # wx.ALIGN_RIGHT)
  1506. ##
  1507. # iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  1508. ## initial = 1,
  1509. ## min = 1,
  1510. # max = 1e6)
  1511. # iwidth.SetName('value')
  1512. # iwidth.SetValue(100)
  1513. ## self.win['vector']['points']['width'] = iwidth.GetId()
  1514. ## iwidth.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  1515. ## iwidth.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  1516. # gridSizer.Add(item = iwidth, pos = (1, 2),
  1517. # flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1518. # icon symbol
  1519. gridSizer.Add(
  1520. StaticText(
  1521. parent=panel, id=wx.ID_ANY, label=_("symbol:")), pos=(
  1522. 0, 5), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  1523. isym = wx.Choice(
  1524. parent=panel, id=wx.ID_ANY, size=(100, -1),
  1525. choices=UserSettings.Get(
  1526. group='nviz', key='vector', subkey=['points', 'marker'],
  1527. settings_type='internal'))
  1528. isym.SetName("selection")
  1529. self.win['vector']['points']['marker'] = isym.GetId()
  1530. isym.Bind(wx.EVT_CHOICE, self.OnVectorPoints)
  1531. gridSizer.Add(isym, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  1532. pos=(0, 6))
  1533. # thematic mapping
  1534. self.win['vector']['points']['thematic'] = {}
  1535. checkThematicColor = wx.CheckBox(
  1536. parent=panel, id=wx.ID_ANY,
  1537. label=_("use color for thematic mapping"))
  1538. checkThematicSize = wx.CheckBox(
  1539. parent=panel, id=wx.ID_ANY,
  1540. label=_("use size for thematic mapping"))
  1541. self.win['vector']['points']['thematic'][
  1542. 'checkcolor'] = checkThematicColor.GetId()
  1543. self.win['vector']['points']['thematic'][
  1544. 'checksize'] = checkThematicSize.GetId()
  1545. checkThematicColor.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
  1546. checkThematicSize.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
  1547. checkThematicColor.SetValue(False)
  1548. checkThematicSize.SetValue(False)
  1549. gridSizer.Add(
  1550. checkThematicColor,
  1551. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  1552. pos=(
  1553. 1,
  1554. 1),
  1555. span=(
  1556. 1,
  1557. 5))
  1558. setThematic = Button(parent=panel, id=wx.ID_ANY,
  1559. label=_("Set options..."))
  1560. self.win['vector']['points']['thematic'][
  1561. 'buttoncolor'] = setThematic.GetId()
  1562. setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
  1563. gridSizer.Add(setThematic, flag=wx.ALIGN_CENTER_VERTICAL,
  1564. pos=(1, 6))
  1565. gridSizer.Add(
  1566. checkThematicSize,
  1567. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  1568. pos=(
  1569. 2,
  1570. 1),
  1571. span=(
  1572. 1,
  1573. 5))
  1574. setThematic = Button(parent=panel, id=wx.ID_ANY,
  1575. label=_("Set options..."))
  1576. self.win['vector']['points']['thematic'][
  1577. 'buttonsize'] = setThematic.GetId()
  1578. setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
  1579. gridSizer.Add(setThematic, flag=wx.ALIGN_CENTER_VERTICAL,
  1580. pos=(2, 6))
  1581. gridSizer.AddGrowableCol(0)
  1582. gridSizer.AddGrowableCol(2)
  1583. gridSizer.AddGrowableCol(4)
  1584. gridSizer.AddGrowableCol(6)
  1585. vertSizer.Add(gridSizer, proportion=0, flag=wx.EXPAND, border=0)
  1586. # high
  1587. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  1588. gridSizer.Add(
  1589. StaticText(
  1590. parent=panel, label=_("Display")), pos=(
  1591. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1592. display = wx.Choice(parent=panel)
  1593. self.win['vector']['points']['3d'] = display.GetId()
  1594. display.Bind(wx.EVT_CHOICE, self.OnVectorPointsMode)
  1595. gridSizer.Add(display,
  1596. pos=(0, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  1597. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1598. label=_("Height above surface:")),
  1599. pos=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  1600. surface = CheckListBox(parent=panel, id=wx.ID_ANY, size=(-1, 60),
  1601. choices=[], style=wx.LB_NEEDED_SB)
  1602. surface.Bind(wx.EVT_CHECKLISTBOX, self.OnVectorSurface)
  1603. self.win['vector']['points']['surface'] = surface.GetId()
  1604. gridSizer.Add(surface,
  1605. pos=(1, 0), span=(3, 2),
  1606. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  1607. self._createControl(
  1608. panel,
  1609. data=self.win['vector']['points'],
  1610. name='height',
  1611. size=-1,
  1612. range=(
  1613. 0,
  1614. 500),
  1615. bind=(
  1616. self.OnVectorHeight,
  1617. self.OnVectorHeightFull,
  1618. self.OnVectorHeightText))
  1619. self.FindWindowById(self.win['vector']['points'][
  1620. 'height']['slider']).SetValue(0)
  1621. self.FindWindowById(self.win['vector']['points'][
  1622. 'height']['text']).SetValue(0)
  1623. gridSizer.Add(
  1624. self.FindWindowById(
  1625. self.win['vector']['points']['height']['slider']), pos=(
  1626. 2, 2), flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
  1627. gridSizer.Add(
  1628. self.FindWindowById(
  1629. self.win['vector']['points']['height']['text']), pos=(
  1630. 3, 2), flag=wx.ALIGN_CENTER)
  1631. gridSizer.AddGrowableCol(2)
  1632. vertSizer.Add(gridSizer, proportion=0, flag=wx.EXPAND, border=0)
  1633. boxSizer.Add(vertSizer, proportion=1,
  1634. flag=wx.ALL | wx.EXPAND, border=3)
  1635. pageSizer.Add(boxSizer, proportion=0,
  1636. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1637. border=3)
  1638. panel.SetSizer(pageSizer)
  1639. panel.Fit()
  1640. return panel
  1641. def GselectOnPopup(self, ltype, exclude=False):
  1642. """Update gselect.Select() items"""
  1643. maps = list()
  1644. for layer in self.mapWindow.Map.GetListOfLayers(
  1645. ltype=ltype, active=True):
  1646. maps.append(layer.GetName())
  1647. return maps, exclude
  1648. def _createVolumePage(self, parent):
  1649. """Create view settings page"""
  1650. panel = wx.Panel(parent=parent, id=wx.ID_ANY)
  1651. self.page['volume'] = {'id': 3,
  1652. 'notebook': self.foldpanelData.GetId()}
  1653. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1654. self.win['volume'] = {}
  1655. # selection
  1656. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1657. label=" %s " % (_("3D raster map")))
  1658. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1659. rmaps = Select(parent=panel, type='raster_3d',
  1660. onPopup=self.GselectOnPopup)
  1661. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster3D)
  1662. self.win['volume']['map'] = rmaps.GetId()
  1663. desc = StaticText(parent=panel, id=wx.ID_ANY)
  1664. self.win['volume']['desc'] = desc.GetId()
  1665. boxSizer.Add(rmaps, proportion=0,
  1666. flag=wx.ALL,
  1667. border=3)
  1668. boxSizer.Add(desc, proportion=0,
  1669. flag=wx.ALL,
  1670. border=3)
  1671. pageSizer.Add(boxSizer, proportion=0,
  1672. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1673. border=3)
  1674. #
  1675. # draw
  1676. #
  1677. self.win['volume']['draw'] = {}
  1678. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1679. label=" %s " % (_("Draw")))
  1680. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1681. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  1682. # gridSizer.AddGrowableCol(4)
  1683. # mode
  1684. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1685. label=_("Mode:")),
  1686. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1687. mode = wx.Choice(parent=panel, id=wx.ID_ANY, size=(-1, -1),
  1688. choices=[_("isosurfaces"),
  1689. _("slices")])
  1690. mode.SetSelection(0)
  1691. mode.SetName("selection")
  1692. mode.Bind(wx.EVT_CHOICE, self.OnVolumeMode)
  1693. self.win['volume']['draw']['mode'] = mode.GetId()
  1694. gridSizer.Add(mode, flag=wx.ALIGN_CENTER_VERTICAL,
  1695. pos=(0, 1))
  1696. # shading
  1697. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1698. label=_("Shading:")),
  1699. pos=(0, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  1700. shade = wx.Choice(parent=panel, id=wx.ID_ANY, size=(100, -1),
  1701. choices=[_("flat"),
  1702. _("gouraud")])
  1703. shade.SetName("selection")
  1704. self.win['volume']['draw']['shading'] = shade.GetId()
  1705. shade.Bind(wx.EVT_CHOICE, self.OnVolumeDrawMode)
  1706. gridSizer.Add(shade, flag=wx.ALIGN_CENTER_VERTICAL,
  1707. pos=(0, 3))
  1708. # resolution (mode)
  1709. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  1710. label=_("Resolution:")),
  1711. pos=(0, 4), flag=wx.ALIGN_CENTER_VERTICAL)
  1712. resol = SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  1713. initial=1,
  1714. min=1,
  1715. max=100)
  1716. resol.SetName("value")
  1717. self.win['volume']['draw']['resolution'] = resol.GetId()
  1718. resol.Bind(wx.EVT_SPINCTRL, self.OnVolumeResolution)
  1719. resol.Bind(wx.EVT_TEXT, self.OnVolumeResolution)
  1720. gridSizer.Add(resol, pos=(0, 5))
  1721. # draw wire box
  1722. box = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1723. label=_("Draw wire box"))
  1724. box.SetName("value")
  1725. self.win['volume']['draw']['box'] = box.GetId()
  1726. box.Bind(wx.EVT_CHECKBOX, self.OnVolumeDrawBox)
  1727. gridSizer.Add(box, pos=(1, 0), span=(1, 6))
  1728. boxSizer.Add(gridSizer, proportion=0,
  1729. flag=wx.ALL | wx.EXPAND, border=3)
  1730. pageSizer.Add(boxSizer, proportion=0,
  1731. flag=wx.EXPAND | wx.ALL,
  1732. border=3)
  1733. #
  1734. # manage isosurfaces
  1735. #
  1736. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1737. label=" %s " % (_("List of isosurfaces")))
  1738. box.SetName('listStaticBox')
  1739. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1740. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  1741. # list
  1742. isolevel = CheckListBox(parent=panel, id=wx.ID_ANY,
  1743. size=(300, 150))
  1744. self.Bind(wx.EVT_CHECKLISTBOX, self.OnVolumeCheck, isolevel)
  1745. self.Bind(wx.EVT_LISTBOX, self.OnVolumeSelect, isolevel)
  1746. self.win['volume']['isosurfs'] = isolevel.GetId()
  1747. self.win['volume']['slices'] = isolevel.GetId()
  1748. gridSizer.Add(isolevel, pos=(0, 0), span=(4, 1))
  1749. # buttons (add, delete, move up, move down)
  1750. btnAdd = Button(parent=panel, id=wx.ID_ADD)
  1751. self.win['volume']['btnAdd'] = btnAdd.GetId()
  1752. btnAdd.Bind(wx.EVT_BUTTON, self.OnVolumeAdd)
  1753. gridSizer.Add(btnAdd,
  1754. pos=(0, 1))
  1755. btnDelete = Button(parent=panel, id=wx.ID_DELETE)
  1756. self.win['volume']['btnDelete'] = btnDelete.GetId()
  1757. btnDelete.Bind(wx.EVT_BUTTON, self.OnVolumeDelete)
  1758. btnDelete.Enable(False)
  1759. gridSizer.Add(btnDelete,
  1760. pos=(1, 1))
  1761. btnMoveUp = Button(parent=panel, id=wx.ID_UP)
  1762. self.win['volume']['btnMoveUp'] = btnMoveUp.GetId()
  1763. btnMoveUp.Bind(wx.EVT_BUTTON, self.OnVolumeMoveUp)
  1764. btnMoveUp.Enable(False)
  1765. gridSizer.Add(btnMoveUp,
  1766. pos=(2, 1))
  1767. btnMoveDown = Button(parent=panel, id=wx.ID_DOWN)
  1768. self.win['volume']['btnMoveDown'] = btnMoveDown.GetId()
  1769. btnMoveDown.Bind(wx.EVT_BUTTON, self.OnVolumeMoveDown)
  1770. btnMoveDown.Enable(False)
  1771. gridSizer.Add(btnMoveDown,
  1772. pos=(3, 1))
  1773. boxSizer.Add(gridSizer, proportion=1,
  1774. flag=wx.ALL | wx.EXPAND, border=3)
  1775. pageSizer.Add(boxSizer, proportion=0,
  1776. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1777. border=3)
  1778. # isosurface/slice
  1779. sizer = wx.BoxSizer()
  1780. self.isoPanel = self._createIsosurfacePanel(panel)
  1781. self.slicePanel = self._createSlicePanel(panel)
  1782. sizer.Add(
  1783. self.isoPanel,
  1784. proportion=1,
  1785. flag=wx.EXPAND | wx.ALL,
  1786. border=0)
  1787. sizer.Add(
  1788. self.slicePanel,
  1789. proportion=1,
  1790. flag=wx.EXPAND | wx.ALL,
  1791. border=0)
  1792. sizer.Hide(self.slicePanel)
  1793. pageSizer.Add(sizer, proportion=0,
  1794. flag=wx.EXPAND | wx.ALL,
  1795. border=3)
  1796. #
  1797. # position
  1798. #
  1799. self.win['volume']['position'] = {}
  1800. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1801. label=" %s " % (_("Position")))
  1802. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1803. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  1804. # position
  1805. self._createControl(panel,
  1806. data=self.win['volume'],
  1807. name='position',
  1808. range=(-10000,
  1809. 10000),
  1810. floatSlider=True,
  1811. bind=(self.OnVolumePosition,
  1812. self.OnVolumePositionChanged,
  1813. self.OnVolumePositionText))
  1814. axis = wx.Choice(parent=panel, id=wx.ID_ANY, size=(75, -1),
  1815. choices=["X",
  1816. "Y",
  1817. "Z"])
  1818. reset = Button(panel, id=wx.ID_ANY, label=_("Reset"))
  1819. reset.SetToolTip(_("Reset to default position"))
  1820. reset.Bind(wx.EVT_BUTTON, self.OnResetVolumePosition)
  1821. self.win['volume']['position']['reset'] = reset.GetId()
  1822. self.win['volume']['position']['axis'] = axis.GetId()
  1823. axis.SetSelection(2) # Z
  1824. axis.Bind(wx.EVT_CHOICE, self.OnVolumeAxis)
  1825. pslide = self.FindWindowById(self.win['volume']['position']['slider'])
  1826. ptext = self.FindWindowById(self.win['volume']['position']['text'])
  1827. ptext.SetValue('0')
  1828. gridSizer.Add(axis, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
  1829. gridSizer.Add(pslide, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 1))
  1830. gridSizer.Add(ptext, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 2))
  1831. gridSizer.Add(
  1832. reset,
  1833. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  1834. pos=(
  1835. 0,
  1836. 3))
  1837. gridSizer.AddGrowableCol(3)
  1838. boxSizer.Add(gridSizer, proportion=1,
  1839. flag=wx.ALL | wx.EXPAND, border=3)
  1840. pageSizer.Add(boxSizer, proportion=0,
  1841. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1842. border=3)
  1843. panel.SetSizer(pageSizer)
  1844. panel.Fit()
  1845. return panel
  1846. def _createLightPage(self, parent):
  1847. """Create light page"""
  1848. panel = wx.Panel(parent=parent, id=wx.ID_ANY)
  1849. self.page['light'] = {'id': 0,
  1850. 'notebook': self.foldpanelAppear.GetId()}
  1851. self.win['light'] = {}
  1852. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1853. show = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1854. label=_("Show light model"))
  1855. show.Bind(wx.EVT_CHECKBOX, self.OnShowLightModel)
  1856. show.SetValue(True)
  1857. self._display.showLight = True
  1858. pageSizer.Add(show, proportion=0,
  1859. flag=wx.ALL, border=3)
  1860. # surface = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1861. # label = _("Follow source viewpoint"))
  1862. # pageSizer.Add(item = surface, proportion = 0,
  1863. # flag = wx.ALL, border = 3)
  1864. # position
  1865. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1866. label=" %s " % (_("Light source position")))
  1867. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1868. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  1869. posSizer = wx.GridBagSizer(vgap=3, hgap=3)
  1870. self._createCompass(panel=panel, sizer=posSizer, type='light')
  1871. pos = LightPositionWindow(panel, id=wx.ID_ANY, size=(175, 175),
  1872. mapwindow=self.mapWindow)
  1873. self.win['light']['position'] = pos.GetId()
  1874. posSizer.Add(
  1875. pos, pos=(1, 1),
  1876. flag=wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  1877. gridSizer.Add(posSizer, pos=(0, 0))
  1878. # height
  1879. tooltip = _("Adjusts the light height")
  1880. self._createControl(
  1881. panel, data=self.win['light'], name='z', sliderHor=False, range=(
  1882. 0, 100), tooltip=tooltip, bind=(
  1883. self.OnLightChange, self.OnLightChanged, self.OnLightChange))
  1884. heightSizer = wx.GridBagSizer(vgap=3, hgap=3)
  1885. heightSizer.Add(
  1886. StaticText(
  1887. panel, id=wx.ID_ANY, label=_("Height:")), pos=(
  1888. 0, 0), flag=wx.ALIGN_LEFT, span=(
  1889. 1, 2))
  1890. heightSizer.Add(
  1891. self.FindWindowById(
  1892. self.win['light']['z']['slider']), flag=wx.ALIGN_RIGHT, pos=(
  1893. 1, 0))
  1894. heightSizer.Add(self.FindWindowById(
  1895. self.win['light']['z']['text']),
  1896. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  1897. wx.BOTTOM | wx.RIGHT, pos=(1, 1))
  1898. gridSizer.Add(heightSizer, pos=(0, 2), flag=wx.ALIGN_RIGHT)
  1899. boxSizer.Add(gridSizer, proportion=1,
  1900. flag=wx.ALL | wx.EXPAND, border=2)
  1901. pageSizer.Add(boxSizer, proportion=0,
  1902. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1903. border=3)
  1904. # position
  1905. box = StaticBox(parent=panel, id=wx.ID_ANY,
  1906. label=" %s " % (_("Light color and intensity")))
  1907. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1908. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  1909. gridSizer.Add(
  1910. StaticText(
  1911. panel, id=wx.ID_ANY, label=_("Color:")), pos=(
  1912. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1913. color = csel.ColourSelect(
  1914. panel, id=wx.ID_ANY, colour=UserSettings.Get(
  1915. group='nviz', key='light', subkey='color'),
  1916. size=globalvar.DIALOG_COLOR_SIZE)
  1917. self.win['light']['color'] = color.GetId()
  1918. color.Bind(csel.EVT_COLOURSELECT, self.OnLightColor)
  1919. gridSizer.Add(color, pos=(0, 2))
  1920. gridSizer.Add(
  1921. StaticText(
  1922. panel, id=wx.ID_ANY, label=_("Brightness:")), pos=(
  1923. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1924. tooltip = _("Adjusts the brightness of the light")
  1925. self._createControl(
  1926. panel, data=self.win['light'], name='bright', size=300, range=(
  1927. 0, 100), tooltip=tooltip, bind=(
  1928. self.OnLightValue, self.OnLightChanged, self.OnLightValue))
  1929. gridSizer.Add(
  1930. self.FindWindowById(
  1931. self.win['light']['bright']['slider']), pos=(
  1932. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  1933. gridSizer.Add(
  1934. self.FindWindowById(
  1935. self.win['light']['bright']['text']), pos=(
  1936. 1, 2), flag=wx.ALIGN_CENTER)
  1937. gridSizer.Add(
  1938. StaticText(
  1939. panel, id=wx.ID_ANY, label=_("Ambient:")), pos=(
  1940. 2, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1941. tooltip = _("Adjusts the ambient light")
  1942. self._createControl(
  1943. panel, data=self.win['light'], name='ambient', size=300, range=(
  1944. 0, 100), tooltip=tooltip, bind=(
  1945. self.OnLightValue, self.OnLightChanged, self.OnLightValue))
  1946. gridSizer.Add(
  1947. self.FindWindowById(
  1948. self.win['light']['ambient']['slider']), pos=(
  1949. 2, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  1950. gridSizer.Add(
  1951. self.FindWindowById(
  1952. self.win['light']['ambient']['text']), pos=(
  1953. 2, 2), flag=wx.ALIGN_CENTER)
  1954. boxSizer.Add(gridSizer, proportion=1,
  1955. flag=wx.ALL | wx.EXPAND, border=2)
  1956. pageSizer.Add(boxSizer, proportion=0,
  1957. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1958. border=3)
  1959. # reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  1960. # reset.SetToolTipString(_("Reset to default view"))
  1961. # # self.win['reset'] = reset.GetId()
  1962. # reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  1963. # viewSizer.Add(item = reset, proportion = 1,
  1964. # flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT,
  1965. # border = 5)
  1966. # gridSizer.AddGrowableCol(3)
  1967. # gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
  1968. # flag = wx.EXPAND)
  1969. panel.SetSizer(pageSizer)
  1970. panel.Layout()
  1971. panel.Fit()
  1972. return panel
  1973. def _createFringePage(self, parent):
  1974. """Create fringe page"""
  1975. panel = wx.Panel(parent=parent, id=wx.ID_ANY)
  1976. self.page['fringe'] = {'id': 1,
  1977. 'notebook': self.foldpanelAppear.GetId()}
  1978. self.win['fringe'] = {}
  1979. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1980. # selection
  1981. rbox = StaticBox(parent=panel, id=wx.ID_ANY,
  1982. label=" %s " % (_("Surface")))
  1983. rboxSizer = wx.StaticBoxSizer(rbox, wx.VERTICAL)
  1984. rmaps = Select(parent=panel, type='raster',
  1985. onPopup=self.GselectOnPopup)
  1986. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetSurface)
  1987. self.win['fringe']['map'] = rmaps.GetId()
  1988. rboxSizer.Add(rmaps, proportion=0,
  1989. flag=wx.ALL,
  1990. border=3)
  1991. pageSizer.Add(rboxSizer, proportion=0,
  1992. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1993. border=3)
  1994. ebox = StaticBox(parent=panel, id=wx.ID_ANY,
  1995. label=" %s " % (_("Edges with fringe")))
  1996. eboxSizer = wx.StaticBoxSizer(ebox, wx.HORIZONTAL)
  1997. for edge in [(_("N && W"), "nw"),
  1998. (_("N && E"), "ne"),
  1999. (_("S && W"), "sw"),
  2000. (_("S && E"), "se")]:
  2001. chkbox = wx.CheckBox(parent=panel,
  2002. label=edge[0],
  2003. name=edge[1])
  2004. self.win['fringe'][edge[1]] = chkbox.GetId()
  2005. eboxSizer.Add(
  2006. chkbox,
  2007. proportion=0,
  2008. flag=wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT,
  2009. border=5)
  2010. chkbox.Bind(wx.EVT_CHECKBOX, self.OnFringe)
  2011. pageSizer.Add(eboxSizer, proportion=0,
  2012. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  2013. border=3)
  2014. sbox = StaticBox(parent=panel, id=wx.ID_ANY,
  2015. label=" %s " % (_("Settings")))
  2016. sboxSizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
  2017. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  2018. # elevation
  2019. gridSizer.Add(
  2020. StaticText(
  2021. parent=panel, id=wx.ID_ANY,
  2022. label=_("Elevation of fringe from bottom:")),
  2023. pos=(0, 0),
  2024. flag=wx.ALIGN_CENTER_VERTICAL)
  2025. spin = SpinCtrl(parent=panel, id=wx.ID_ANY,
  2026. size=(65, -1), min=-1e6, max=1e6)
  2027. spin.SetValue(
  2028. UserSettings.Get(
  2029. group='nviz',
  2030. key='fringe',
  2031. subkey='elev'))
  2032. spin.Bind(wx.EVT_SPINCTRL, self.OnFringe)
  2033. self.win['fringe']['elev'] = spin.GetId()
  2034. gridSizer.Add(spin, pos=(0, 1))
  2035. # color
  2036. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  2037. label=_("Color:")),
  2038. pos=(1, 0),
  2039. flag=wx.ALIGN_CENTER_VERTICAL)
  2040. color = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
  2041. size=globalvar.DIALOG_COLOR_SIZE)
  2042. color.SetColour(UserSettings.Get(group='nviz', key='fringe',
  2043. subkey='color'))
  2044. color.Bind(csel.EVT_COLOURSELECT, self.OnFringe)
  2045. self.win['fringe']['color'] = color.GetId()
  2046. gridSizer.Add(color, pos=(1, 1))
  2047. sboxSizer.Add(gridSizer, proportion=1,
  2048. flag=wx.ALL | wx.EXPAND, border=3)
  2049. pageSizer.Add(sboxSizer, proportion=0,
  2050. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  2051. border=3)
  2052. panel.SetSizer(pageSizer)
  2053. panel.Layout()
  2054. panel.Fit()
  2055. return panel
  2056. def _createDecorationPage(self, parent):
  2057. """Create decoration (north arrow, scalebar, legend) page"""
  2058. panel = wx.Panel(parent=parent, id=wx.ID_ANY)
  2059. self.page['decoration'] = {'id': 2,
  2060. 'notebook': self.foldpanelAppear.GetId()}
  2061. self.win['decoration'] = {}
  2062. pageSizer = wx.BoxSizer(wx.VERTICAL)
  2063. # north arrow
  2064. self.win['decoration']['arrow'] = {}
  2065. nabox = StaticBox(parent=panel, id=wx.ID_ANY,
  2066. label=" %s " % (_("North Arrow")))
  2067. naboxSizer = wx.StaticBoxSizer(nabox, wx.VERTICAL)
  2068. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  2069. # size
  2070. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  2071. label=_("Arrow length (in map units):")),
  2072. pos=(0, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  2073. sizeCtrl = NumTextCtrl(
  2074. parent=panel, id=wx.ID_ANY, size=(
  2075. 65, -1), style=wx.TE_PROCESS_ENTER)
  2076. gridSizer.Add(sizeCtrl, pos=(0, 2))
  2077. self.win['decoration']['arrow']['size'] = sizeCtrl.GetId()
  2078. sizeCtrl.Bind(wx.EVT_TEXT_ENTER, self.OnDecorationProp)
  2079. sizeCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnDecorationProp)
  2080. # color
  2081. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  2082. label=_("Arrow color:")),
  2083. pos=(1, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  2084. color = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
  2085. size=globalvar.DIALOG_COLOR_SIZE)
  2086. gridSizer.Add(color, pos=(1, 2))
  2087. self.win['decoration']['arrow']['color'] = color.GetId()
  2088. color.Bind(csel.EVT_COLOURSELECT, self.OnDecorationProp)
  2089. # control
  2090. toggle = ToggleButton(
  2091. parent=panel,
  2092. id=wx.ID_ANY,
  2093. label=_("Place arrow"))
  2094. gridSizer.Add(toggle, pos=(2, 0))
  2095. toggle.Bind(wx.EVT_TOGGLEBUTTON, self.OnDecorationPlacement)
  2096. self.win['decoration']['arrow']['place'] = toggle.GetId()
  2097. toggle.SetName('placeArrow')
  2098. delete = Button(parent=panel, id=wx.ID_ANY, label=_("Delete"))
  2099. self.win['decoration']['arrow']['delete'] = delete.GetId()
  2100. gridSizer.Add(delete, pos=(2, 1))
  2101. delete.Bind(wx.EVT_BUTTON, self.OnArrowDelete)
  2102. shown = self.mapWindow.decoration['arrow']['show']
  2103. delete.Enable(shown)
  2104. naboxSizer.Add(gridSizer, proportion=0, flag=wx.EXPAND, border=3)
  2105. pageSizer.Add(naboxSizer, proportion=0,
  2106. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  2107. border=3)
  2108. # scale bars
  2109. self.win['decoration']['scalebar'] = {}
  2110. nabox = StaticBox(parent=panel, id=wx.ID_ANY,
  2111. label=" %s " % (_("Scale bar")))
  2112. naboxSizer = wx.StaticBoxSizer(nabox, wx.VERTICAL)
  2113. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  2114. # size
  2115. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  2116. label=_("Scale bar length (in map units):")),
  2117. pos=(0, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  2118. sizeCtrl = NumTextCtrl(
  2119. parent=panel, id=wx.ID_ANY, size=(
  2120. 65, -1), style=wx.TE_PROCESS_ENTER)
  2121. gridSizer.Add(sizeCtrl, pos=(0, 2))
  2122. self.win['decoration']['scalebar']['size'] = sizeCtrl.GetId()
  2123. sizeCtrl.Bind(wx.EVT_TEXT_ENTER, self.OnDecorationProp)
  2124. sizeCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnDecorationProp)
  2125. # color
  2126. gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  2127. label=_("Scale bar color:")),
  2128. pos=(1, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  2129. color = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
  2130. size=globalvar.DIALOG_COLOR_SIZE)
  2131. gridSizer.Add(color, pos=(1, 2))
  2132. self.win['decoration']['scalebar']['color'] = color.GetId()
  2133. color.Bind(csel.EVT_COLOURSELECT, self.OnDecorationProp)
  2134. # control
  2135. toggle = ToggleButton(
  2136. parent=panel,
  2137. id=wx.ID_ANY,
  2138. label=_("Place new scale bar"))
  2139. gridSizer.Add(toggle, pos=(2, 0))
  2140. toggle.Bind(wx.EVT_TOGGLEBUTTON, self.OnDecorationPlacement)
  2141. self.win['decoration']['scalebar']['place'] = toggle.GetId()
  2142. toggle.SetName('placeScalebar')
  2143. scalebarChoice = wx.Choice(parent=panel, id=wx.ID_ANY, choices=[])
  2144. self.win['decoration']['scalebar']['choice'] = scalebarChoice.GetId()
  2145. gridSizer.Add(scalebarChoice, pos=(3, 0), flag=wx.EXPAND)
  2146. delete = Button(parent=panel, id=wx.ID_ANY, label=_("Delete"))
  2147. self.win['decoration']['scalebar']['delete'] = delete.GetId()
  2148. gridSizer.Add(delete, pos=(3, 1))
  2149. delete.Bind(wx.EVT_BUTTON, self.OnScalebarDelete)
  2150. naboxSizer.Add(gridSizer, proportion=0, flag=wx.EXPAND, border=3)
  2151. pageSizer.Add(naboxSizer, proportion=0,
  2152. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  2153. border=3)
  2154. self.DisableScalebarControls()
  2155. panel.SetSizer(pageSizer)
  2156. panel.Layout()
  2157. panel.Fit()
  2158. return panel
  2159. def GetLayerData(self, nvizType, nameOnly=False):
  2160. """Get nviz data"""
  2161. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  2162. if nameOnly:
  2163. return name
  2164. if nvizType == 'surface' or nvizType == 'fringe':
  2165. return self._getLayerPropertiesByName(name, mapType='raster')
  2166. elif nvizType == 'vector':
  2167. return self._getLayerPropertiesByName(name, mapType='vector')
  2168. elif nvizType == 'volume':
  2169. return self._getLayerPropertiesByName(name, mapType='raster_3d')
  2170. return None
  2171. def _getMapLayerByName(self, name, mapType):
  2172. """Get layer (render.Layer) by name and type.
  2173. :param name: layer name
  2174. :param mapType: map type (raster, vector, raster_3d)
  2175. """
  2176. layers = self.mapWindow.Map.GetListOfLayers(ltype=mapType, name=name)
  2177. if layers:
  2178. return layers[0]
  2179. return None
  2180. def _getLayerPropertiesByName(self, name, mapType):
  2181. """Get nviz properties stored in layertree items by name and type.
  2182. :param name: layer name
  2183. :param mapType: map type (raster, vector, raster_3d)
  2184. """
  2185. items = self.tree.FindItemByData(key='name', value=name)
  2186. if not items:
  2187. return None
  2188. for item in items:
  2189. if self.tree.GetLayerInfo(item, key='type') == mapType:
  2190. return self.tree.GetLayerInfo(item, key='nviz')
  2191. return None
  2192. def OnRecord(self, event):
  2193. """Animation: start recording"""
  2194. anim = self.mapWindow.GetAnimation()
  2195. if not anim.IsPaused():
  2196. if anim.Exists() and not anim.IsSaved():
  2197. msg = _(
  2198. "Do you want to record new animation without saving the previous one?")
  2199. dlg = wx.MessageDialog(parent=self,
  2200. message=msg,
  2201. caption=_("Animation already axists"),
  2202. style=wx.YES_NO | wx.CENTRE)
  2203. if dlg.ShowModal() == wx.ID_NO:
  2204. dlg.Destroy()
  2205. return
  2206. anim.Clear()
  2207. self.UpdateFrameIndex(0)
  2208. self.UpdateFrameCount()
  2209. anim.SetPause(False)
  2210. anim.SetMode(mode='record')
  2211. anim.Start()
  2212. self.FindWindowById(self.win['anim']['play']).Disable()
  2213. self.FindWindowById(self.win['anim']['record']).Disable()
  2214. self.FindWindowById(self.win['anim']['pause']).Enable()
  2215. self.FindWindowById(self.win['anim']['stop']).Enable()
  2216. self.FindWindowById(self.win['anim']['frameIndex']['slider']).Disable()
  2217. self.FindWindowById(self.win['anim']['frameIndex']['text']).Disable()
  2218. def OnPlay(self, event):
  2219. """Animation: replay"""
  2220. anim = self.mapWindow.GetAnimation()
  2221. anim.SetPause(False)
  2222. anim.SetMode(mode='play')
  2223. anim.Start()
  2224. self.FindWindowById(self.win['anim']['play']).Disable()
  2225. self.FindWindowById(self.win['anim']['record']).Disable()
  2226. self.FindWindowById(self.win['anim']['pause']).Enable()
  2227. self.FindWindowById(self.win['anim']['stop']).Enable()
  2228. self.FindWindowById(self.win['anim']['frameIndex']['slider']).Enable()
  2229. self.FindWindowById(self.win['anim']['frameIndex']['text']).Enable()
  2230. def OnStop(self, event):
  2231. """Animation: stop recording/replaying"""
  2232. anim = self.mapWindow.GetAnimation()
  2233. anim.SetPause(False)
  2234. if anim.GetMode() == 'save':
  2235. anim.StopSaving()
  2236. if anim.IsRunning():
  2237. anim.Stop()
  2238. self.UpdateFrameIndex(0)
  2239. self.FindWindowById(self.win['anim']['play']).Enable()
  2240. self.FindWindowById(self.win['anim']['record']).Enable()
  2241. self.FindWindowById(self.win['anim']['pause']).Disable()
  2242. self.FindWindowById(self.win['anim']['stop']).Disable()
  2243. self.FindWindowById(self.win['anim']['frameIndex']['slider']).Disable()
  2244. self.FindWindowById(self.win['anim']['frameIndex']['text']).Disable()
  2245. def OnPause(self, event):
  2246. """Pause animation"""
  2247. anim = self.mapWindow.GetAnimation()
  2248. anim.SetPause(True)
  2249. mode = anim.GetMode()
  2250. if anim.IsRunning():
  2251. anim.Pause()
  2252. if mode == "record":
  2253. self.FindWindowById(self.win['anim']['play']).Disable()
  2254. self.FindWindowById(self.win['anim']['record']).Enable()
  2255. self.FindWindowById(
  2256. self.win['anim']['frameIndex']['slider']).Disable()
  2257. self.FindWindowById(
  2258. self.win['anim']['frameIndex']['text']).Disable()
  2259. elif mode == 'play':
  2260. self.FindWindowById(self.win['anim']['record']).Disable()
  2261. self.FindWindowById(self.win['anim']['play']).Enable()
  2262. self.FindWindowById(
  2263. self.win['anim']['frameIndex']['slider']).Enable()
  2264. self.FindWindowById(
  2265. self.win['anim']['frameIndex']['text']).Enable()
  2266. self.FindWindowById(self.win['anim']['pause']).Disable()
  2267. self.FindWindowById(self.win['anim']['stop']).Enable()
  2268. def OnFrameIndex(self, event):
  2269. """Frame index changed (by slider)"""
  2270. index = event.GetInt()
  2271. self.UpdateFrameIndex(index=index, sliderWidget=False)
  2272. def OnFrameIndexText(self, event):
  2273. """Frame index changed by (textCtrl)"""
  2274. index = event.GetValue()
  2275. self.UpdateFrameIndex(index=index, textWidget=False)
  2276. def OnFPS(self, event):
  2277. """Frames per second changed"""
  2278. anim = self.mapWindow.GetAnimation()
  2279. anim.SetFPS(event.GetInt())
  2280. def UpdateFrameIndex(self, index, sliderWidget=True,
  2281. textWidget=True, goToFrame=True):
  2282. """Update frame index"""
  2283. anim = self.mapWindow.GetAnimation()
  2284. # check index
  2285. frameCount = anim.GetFrameCount()
  2286. if index >= frameCount:
  2287. index = frameCount - 1
  2288. if index < 0:
  2289. index = 0
  2290. if sliderWidget:
  2291. slider = self.FindWindowById(
  2292. self.win['anim']['frameIndex']['slider'])
  2293. slider.SetValue(index)
  2294. if textWidget:
  2295. text = self.FindWindowById(self.win['anim']['frameIndex']['text'])
  2296. text.SetValue(int(index))
  2297. # if called from tool window, update frame
  2298. if goToFrame:
  2299. anim.GoToFrame(int(index))
  2300. def UpdateFrameCount(self):
  2301. """Update frame count label"""
  2302. anim = self.mapWindow.GetAnimation()
  2303. count = anim.GetFrameCount()
  2304. self.FindWindowById(self.win['anim']['info']).SetLabel(str(count))
  2305. def OnAnimationFinished(self, mode):
  2306. """Animation finished"""
  2307. anim = self.mapWindow.GetAnimation()
  2308. self.UpdateFrameIndex(index=0)
  2309. slider = self.FindWindowById(self.win['anim']['frameIndex']['slider'])
  2310. text = self.FindWindowById(self.win['anim']['frameIndex']['text'])
  2311. if mode == 'record':
  2312. count = anim.GetFrameCount()
  2313. slider.SetMax(count)
  2314. self.UpdateFrameCount()
  2315. self.FindWindowById(self.win['anim']['pause']).Disable()
  2316. self.FindWindowById(self.win['anim']['stop']).Disable()
  2317. self.FindWindowById(self.win['anim']['record']).Enable()
  2318. self.FindWindowById(self.win['anim']['play']).Enable()
  2319. self.FindWindowById(self.win['anim']['frameIndex']['slider']).Disable()
  2320. self.FindWindowById(self.win['anim']['frameIndex']['text']).Disable()
  2321. self.FindWindowById(self.win['anim']['save'][
  2322. 'image']['confirm']).Enable()
  2323. self.mapWindow.render['quick'] = False
  2324. self.mapWindow.Refresh(False)
  2325. def OnAnimationUpdateIndex(self, index, mode):
  2326. """Animation: frame index changed"""
  2327. if mode == 'record':
  2328. self.UpdateFrameCount()
  2329. elif mode == 'play':
  2330. self.UpdateFrameIndex(index=index, goToFrame=False)
  2331. def OnSaveAnimation(self, event):
  2332. """Save animation as a sequence of images"""
  2333. anim = self.mapWindow.GetAnimation()
  2334. prefix = self.FindWindowById(
  2335. self.win['anim']['save']['image']['prefix']).GetValue()
  2336. format = self.FindWindowById(
  2337. self.win['anim']['save']['image']['format']).GetSelection()
  2338. dir = self.FindWindowById(
  2339. self.win['anim']['save']['image']['dir']).GetValue()
  2340. if not prefix:
  2341. GMessage(parent=self,
  2342. message=_("No file prefix given."))
  2343. return
  2344. elif not os.path.exists(dir):
  2345. GMessage(parent=self,
  2346. message=_("Directory %s does not exist.") % dir)
  2347. return
  2348. self.FindWindowById(self.win['anim']['pause']).Disable()
  2349. self.FindWindowById(self.win['anim']['stop']).Enable()
  2350. self.FindWindowById(self.win['anim']['record']).Disable()
  2351. self.FindWindowById(self.win['anim']['play']).Disable()
  2352. self.FindWindowById(self.win['anim']['frameIndex']['slider']).Disable()
  2353. self.FindWindowById(self.win['anim']['frameIndex']['text']).Disable()
  2354. self.FindWindowById(self.win['anim']['save'][
  2355. 'image']['confirm']).Disable()
  2356. anim.SaveAnimationFile(path=dir, prefix=prefix, format=format)
  2357. def OnNewConstant(self, event):
  2358. """Create new surface with constant value"""
  2359. # TODO settings
  2360. name = self.mapWindow.NewConstant()
  2361. win = self.FindWindowById(self.win['constant']['surface'])
  2362. name = _("constant#") + str(name)
  2363. win.Append(name)
  2364. win.SetStringSelection(name)
  2365. self.OnConstantSelection(None)
  2366. self.EnablePage(name='constant', enabled=True)
  2367. self.mapWindow.Refresh(eraseBackground=False)
  2368. # need to update list of surfaces in vector page
  2369. for vtype in ('points', 'lines'):
  2370. checklist = self.FindWindowById(
  2371. self.win['vector'][vtype]['surface'])
  2372. checklist.Append(name)
  2373. win = self.FindWindowById(self.win['vector']['map'])
  2374. win.SetValue(win.GetValue())
  2375. def OnDeleteConstant(self, event):
  2376. """Delete selected constant surface"""
  2377. layerIdx = self.FindWindowById(
  2378. self.win['constant']['surface']).GetSelection()
  2379. if layerIdx == wx.NOT_FOUND:
  2380. return
  2381. name = self.FindWindowById(
  2382. self.win['constant']['surface']).GetStringSelection()
  2383. self.mapWindow.DeleteConstant(layerIdx)
  2384. win = self.FindWindowById(self.win['constant']['surface'])
  2385. win.Delete(layerIdx)
  2386. if win.IsEmpty():
  2387. win.SetValue("")
  2388. self.EnablePage(name='constant', enabled=False)
  2389. else:
  2390. win.SetSelection(0)
  2391. self.OnConstantSelection(None)
  2392. # need to update list of surfaces in vector page
  2393. for vtype in ('points', 'lines'):
  2394. checklist = self.FindWindowById(
  2395. self.win['vector'][vtype]['surface'])
  2396. checklist.Delete(checklist.FindString(name))
  2397. if self.mapDisplay.IsAutoRendered():
  2398. self.mapWindow.Refresh(False)
  2399. def OnConstantSelection(self, event):
  2400. """Constant selected"""
  2401. layerIdx = self.FindWindowById(
  2402. self.win['constant']['surface']).GetSelection()
  2403. if layerIdx == wx.NOT_FOUND:
  2404. return
  2405. name = _("constant#") + str(layerIdx + 1)
  2406. data = self.mapWindow.constants[layerIdx]
  2407. for attr, value in six.iteritems(data['constant']):
  2408. if attr == 'color':
  2409. value = self._getColorFromString(value)
  2410. if attr in ('color', 'value', 'resolution', 'transp'):
  2411. if attr == 'transp':
  2412. self.FindWindowById(
  2413. self.win['constant'][attr]).SetValue(
  2414. self._getPercent(value))
  2415. self.FindWindowById(self.win['constant'][attr]).SetValue(value)
  2416. def OnSetConstantProp(self, event):
  2417. """Change properties (color, value, resolution)
  2418. of currently selected constant surface"""
  2419. layerIdx = self.FindWindowById(
  2420. self.win['constant']['surface']).GetSelection()
  2421. if layerIdx == wx.NOT_FOUND:
  2422. return
  2423. data = self.mapWindow.constants[layerIdx]
  2424. for attr in ('resolution', 'value', 'transp'):
  2425. data['constant'][attr] = self.FindWindowById(
  2426. self.win['constant'][attr]).GetValue()
  2427. data['constant']['color'] = self._getColorString(
  2428. self.FindWindowById(self.win['constant']['color']).GetValue())
  2429. data['constant']['transp'] = self._getPercent(
  2430. data['constant']['transp'], toPercent=False)
  2431. # update properties
  2432. event = wxUpdateProperties(data=data)
  2433. wx.PostEvent(self.mapWindow, event)
  2434. if self.mapDisplay.IsAutoRendered():
  2435. self.mapWindow.Refresh(False)
  2436. def OnFringe(self, event):
  2437. """Show/hide fringe"""
  2438. data = self.GetLayerData('fringe')['surface']
  2439. sid = data['object']['id']
  2440. elev = self.FindWindowById(self.win['fringe']['elev']).GetValue()
  2441. color = self.FindWindowById(self.win['fringe']['color']).GetValue()
  2442. self._display.SetFringe(
  2443. sid, color, elev, self.FindWindowById(
  2444. self.win['fringe']['nw']).IsChecked(), self.FindWindowById(
  2445. self.win['fringe']['ne']).IsChecked(), self.FindWindowById(
  2446. self.win['fringe']['sw']).IsChecked(), self.FindWindowById(
  2447. self.win['fringe']['se']).IsChecked())
  2448. self.mapWindow.Refresh(False)
  2449. def OnScroll(self, event, win, data):
  2450. """Generic scrolling handler"""
  2451. winName = self.__GetWindowName(win, event.GetId())
  2452. if not winName:
  2453. return
  2454. data[winName] = self.FindWindowById(event.GetId()).GetValue()
  2455. for w in six.itervalues(win[winName]):
  2456. self.FindWindowById(w).SetValue(data[winName])
  2457. event.Skip()
  2458. def AdjustSliderRange(self, slider, value):
  2459. minim, maxim = slider.GetRange()
  2460. if not (minim <= value <= maxim):
  2461. slider.SetRange(min(minim, value), max(maxim, value))
  2462. def _createIsosurfacePanel(self, parent):
  2463. panel = wx.Panel(parent=parent, id=wx.ID_ANY)
  2464. vSizer = wx.BoxSizer(wx.HORIZONTAL)
  2465. box = StaticBox(parent=panel, id=wx.ID_ANY,
  2466. label=" %s " % (_("Isosurface attributes")))
  2467. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2468. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  2469. self.win['volume']['attr'] = {}
  2470. inout = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  2471. label=_("toggle normal direction"))
  2472. gridSizer.Add(
  2473. inout, pos=(
  2474. 0, 0), span=(
  2475. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  2476. inout.Bind(wx.EVT_CHECKBOX, self.OnInOutMode)
  2477. self.win['volume']['inout'] = inout.GetId()
  2478. row = 1
  2479. for code, attrb in (('topo', _("Isosurface value")),
  2480. ('color', _("Color")),
  2481. ('mask', _("Mask")),
  2482. ('transp', _("Transparency")),
  2483. ('shine', _("Shininess"))):
  2484. self.win['volume'][code] = {}
  2485. # label
  2486. colspan = 1
  2487. if code == 'topo':
  2488. colspan = 2
  2489. gridSizer.Add(
  2490. StaticText(
  2491. parent=panel,
  2492. id=wx.ID_ANY,
  2493. label=attrb + ':'),
  2494. pos=(
  2495. row,
  2496. 0),
  2497. span=(
  2498. 1,
  2499. colspan),
  2500. flag=wx.ALIGN_CENTER_VERTICAL)
  2501. if code != 'topo':
  2502. use = wx.Choice(parent=panel, id=wx.ID_ANY, size=(100, -1),
  2503. choices=[_("map")])
  2504. else:
  2505. use = None
  2506. # check for required properties
  2507. if code not in ('topo', 'color', 'shine'):
  2508. use.Insert(item=_("unset"), pos=0)
  2509. self.win['volume'][code]['required'] = False
  2510. else:
  2511. self.win['volume'][code]['required'] = True
  2512. if use and code != 'mask':
  2513. use.Append(item=_('constant'))
  2514. if use:
  2515. self.win['volume'][code]['use'] = use.GetId()
  2516. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  2517. gridSizer.Add(use, flag=wx.ALIGN_CENTER_VERTICAL,
  2518. pos=(row, 1))
  2519. if code != 'topo':
  2520. map = Select(parent=panel, id=wx.ID_ANY,
  2521. # size = globalvar.DIALOG_GSELECT_SIZE,
  2522. size=(200, -1),
  2523. type="grid3")
  2524. if globalvar.CheckWxVersion([3]):
  2525. self.win['volume'][code]['map'] = map.GetId()
  2526. else:
  2527. self.win['volume'][code]['map'] = map.GetTextCtrl().GetId()
  2528. map.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  2529. gridSizer.Add(map, flag=wx.ALIGN_CENTER_VERTICAL,
  2530. pos=(row, 2))
  2531. else:
  2532. map = None
  2533. if code == 'color':
  2534. color = UserSettings.Get(
  2535. group='nviz', key='volume', subkey=[
  2536. 'color', 'value'])
  2537. value = csel.ColourSelect(panel, id=wx.ID_ANY,
  2538. colour=color,
  2539. size=globalvar.DIALOG_COLOR_SIZE)
  2540. value.Bind(csel.EVT_COLOURSELECT, self.OnVolumeIsosurfMap)
  2541. value.SetName('color')
  2542. elif code == 'mask':
  2543. value = None
  2544. elif code == 'topo':
  2545. value = NumTextCtrl(parent=panel, id=wx.ID_ANY, size=(200, -1),
  2546. style=wx.TE_PROCESS_ENTER)
  2547. value.Bind(wx.EVT_TEXT_ENTER, self.OnVolumeIsosurfMap)
  2548. value.Bind(wx.EVT_KILL_FOCUS, self.OnVolumeIsosurfMap)
  2549. ## value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  2550. else:
  2551. size = (65, -1)
  2552. value = SpinCtrl(parent=panel, id=wx.ID_ANY, size=size,
  2553. initial=0)
  2554. if code == 'topo':
  2555. value.SetRange(minVal=-1e9, maxVal=1e9)
  2556. elif code in ('shine', 'transp'):
  2557. value.SetRange(minVal=0, maxVal=100)
  2558. value.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfMap)
  2559. value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  2560. if value:
  2561. self.win['volume'][code]['const'] = value.GetId()
  2562. if code == 'topo':
  2563. gridSizer.Add(value, flag=wx.ALIGN_CENTER_VERTICAL,
  2564. pos=(row, 2))
  2565. else:
  2566. value.Enable(False)
  2567. gridSizer.Add(value, flag=wx.ALIGN_CENTER_VERTICAL,
  2568. pos=(row, 3))
  2569. else:
  2570. self.win['volume'][code]['const'] = None
  2571. if code != 'topo':
  2572. # -> enable map / disable constant
  2573. self.SetMapObjUseMap(nvizType='volume', attrb=code)
  2574. row += 1
  2575. boxSizer.Add(gridSizer, proportion=1,
  2576. flag=wx.ALL | wx.EXPAND, border=3)
  2577. vSizer.Add(boxSizer, proportion=1,
  2578. flag=wx.EXPAND, border=0)
  2579. panel.SetSizer(vSizer)
  2580. return panel
  2581. def _createSlicePanel(self, parent):
  2582. panel = wx.Panel(parent=parent, id=wx.ID_ANY)
  2583. vSizer = wx.BoxSizer(wx.HORIZONTAL)
  2584. box = StaticBox(parent=panel, id=wx.ID_ANY,
  2585. label=" %s " % (_("Slice attributes")))
  2586. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2587. hSizer = wx.BoxSizer()
  2588. self.win['volume']['slice'] = {}
  2589. hSizer.Add(
  2590. StaticText(
  2591. parent=panel,
  2592. id=wx.ID_ANY,
  2593. label=_("Slice parallel to axis:")),
  2594. proportion=0,
  2595. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  2596. border=3)
  2597. axes = wx.Choice(
  2598. parent=panel, id=wx.ID_ANY, size=(65, -1),
  2599. choices=("X", "Y", "Z"))
  2600. hSizer.Add(axes, proportion=0, flag=wx.ALIGN_LEFT | wx.LEFT, border=3)
  2601. self.win['volume']['slice']['axes'] = axes.GetId()
  2602. axes.Bind(wx.EVT_CHOICE, self.OnVolumeSliceAxes)
  2603. boxSizer.Add(hSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  2604. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  2605. # text labels
  2606. for i in range(2):
  2607. label = StaticText(parent=panel, id=wx.ID_ANY)
  2608. label.SetName('label_edge_' + str(i))
  2609. gridSizer.Add(label, pos=(0, i + 1),
  2610. flag=wx.ALIGN_CENTER)
  2611. for i in range(2, 4):
  2612. label = StaticText(parent=panel, id=wx.ID_ANY)
  2613. label.SetName('label_edge_' + str(i))
  2614. gridSizer.Add(label, pos=(3, i - 1),
  2615. flag=wx.ALIGN_CENTER)
  2616. for i in range(2):
  2617. label = StaticText(parent=panel, id=wx.ID_ANY)
  2618. label.SetName('label_coord_' + str(i))
  2619. gridSizer.Add(label, pos=(i + 1, 0),
  2620. flag=wx.ALIGN_CENTER_VERTICAL)
  2621. label = StaticText(parent=panel, id=wx.ID_ANY)
  2622. label.SetName('label_coord_2')
  2623. gridSizer.Add(label, pos=(4, 0),
  2624. flag=wx.ALIGN_CENTER_VERTICAL)
  2625. # sliders
  2626. for i, coord in enumerate(('x1', 'x2')):
  2627. slider = wx.Slider(
  2628. parent=panel,
  2629. id=wx.ID_ANY,
  2630. minValue=0,
  2631. maxValue=100,
  2632. value=0)
  2633. self.win['volume']['slice']['slider_' + coord] = slider.GetId()
  2634. slider.Bind(wx.EVT_SPIN, self.OnSlicePositionChange)
  2635. slider.Bind(
  2636. wx.EVT_SCROLL_THUMBRELEASE,
  2637. self.OnSlicePositionChanged)
  2638. gridSizer.Add(slider, pos=(1, i + 1),
  2639. flag=wx.ALIGN_CENTER | wx.EXPAND)
  2640. for i, coord in enumerate(('y1', 'y2')):
  2641. slider = wx.Slider(
  2642. parent=panel,
  2643. id=wx.ID_ANY,
  2644. minValue=0,
  2645. maxValue=100,
  2646. value=0)
  2647. self.win['volume']['slice']['slider_' + coord] = slider.GetId()
  2648. slider.Bind(wx.EVT_SPIN, self.OnSlicePositionChange)
  2649. slider.Bind(
  2650. wx.EVT_SCROLL_THUMBRELEASE,
  2651. self.OnSlicePositionChanged)
  2652. gridSizer.Add(slider, pos=(2, i + 1),
  2653. flag=wx.ALIGN_CENTER | wx.EXPAND)
  2654. for i, coord in enumerate(('z1', 'z2')):
  2655. slider = wx.Slider(
  2656. parent=panel,
  2657. id=wx.ID_ANY,
  2658. minValue=0,
  2659. maxValue=100,
  2660. value=0)
  2661. self.win['volume']['slice']['slider_' + coord] = slider.GetId()
  2662. slider.Bind(wx.EVT_SPIN, self.OnSlicePositionChange)
  2663. slider.Bind(
  2664. wx.EVT_SCROLL_THUMBRELEASE,
  2665. self.OnSlicePositionChanged)
  2666. gridSizer.Add(slider, pos=(4, i + 1),
  2667. flag=wx.ALIGN_CENTER | wx.EXPAND)
  2668. gridSizer.AddGrowableCol(0, 1)
  2669. gridSizer.AddGrowableCol(1, 2)
  2670. gridSizer.AddGrowableCol(2, 2)
  2671. boxSizer.Add(gridSizer, proportion=1,
  2672. flag=wx.ALL | wx.EXPAND, border=3)
  2673. # transparency, reset
  2674. hSizer = wx.BoxSizer()
  2675. hSizer.Add(StaticText(parent=panel, id=wx.ID_ANY,
  2676. label=_("Transparency:")), proportion=0,
  2677. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, border=7)
  2678. spin = SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  2679. min=0, max=100, initial=0)
  2680. spin.Bind(wx.EVT_SPINCTRL, self.OnSliceTransparency)
  2681. self.win['volume']['slice']['transp'] = spin.GetId()
  2682. hSizer.Add(spin, proportion=0,
  2683. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.TOP, border=7)
  2684. hSizer.Add(wx.Size(-1, -1), proportion=1,
  2685. flag=wx.EXPAND)
  2686. reset = Button(parent=panel, id=wx.ID_ANY, label=_("Reset"))
  2687. reset.Bind(wx.EVT_BUTTON, self.OnSliceReset)
  2688. self.win['volume']['slice']['reset'] = reset.GetId()
  2689. hSizer.Add(reset, proportion=0,
  2690. flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP, border=7)
  2691. boxSizer.Add(hSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  2692. panel.SetSizer(boxSizer)
  2693. return panel
  2694. def _createControl(self, parent, data, name, range, tooltip=None, bind=(
  2695. None, None, None), sliderHor=True, size=200, floatSlider=False):
  2696. """Add control (Slider + TextCtrl)"""
  2697. data[name] = dict()
  2698. if sliderHor:
  2699. style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  2700. wx.SL_BOTTOM
  2701. sizeW = (size, -1)
  2702. else:
  2703. style = wx.SL_VERTICAL | wx.SL_AUTOTICKS | \
  2704. wx.SL_INVERSE
  2705. sizeW = (-1, size)
  2706. kwargs = dict(parent=parent, id=wx.ID_ANY,
  2707. minValue=range[0],
  2708. maxValue=range[1],
  2709. style=style,
  2710. size=sizeW)
  2711. if floatSlider:
  2712. slider = FloatSlider(**kwargs)
  2713. else:
  2714. slider = wx.Slider(**kwargs)
  2715. slider.SetName('slider')
  2716. if bind[0]:
  2717. # EVT_SCROLL emits event after slider is released, EVT_SPIN not
  2718. slider.Bind(wx.EVT_SPIN, bind[0])
  2719. if bind[1]:
  2720. slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, bind[1])
  2721. data[name]['slider'] = slider.GetId()
  2722. text = NumTextCtrl(parent=parent, id=wx.ID_ANY, size=(65, -1),
  2723. style=wx.TE_PROCESS_ENTER)
  2724. text.SetName('text')
  2725. if tooltip:
  2726. text.SetToolTip(tooltip)
  2727. if bind[2]:
  2728. text.Bind(wx.EVT_TEXT_ENTER, bind[2])
  2729. text.Bind(wx.EVT_KILL_FOCUS, bind[2])
  2730. data[name]['text'] = text.GetId()
  2731. def _createCompass(self, panel, sizer, type):
  2732. """Create 'compass' widget for light and view page"""
  2733. w = Button(panel, id=wx.ID_ANY, label=_("W"))
  2734. n = Button(panel, id=wx.ID_ANY, label=_("N"))
  2735. s = Button(panel, id=wx.ID_ANY, label=_("S"))
  2736. e = Button(panel, id=wx.ID_ANY, label=_("E"))
  2737. nw = Button(panel, id=wx.ID_ANY, label=_("NW"))
  2738. ne = Button(panel, id=wx.ID_ANY, label=_("NE"))
  2739. se = Button(panel, id=wx.ID_ANY, label=_("SE"))
  2740. sw = Button(panel, id=wx.ID_ANY, label=_("SW"))
  2741. padding = 15
  2742. if sys.platform == 'darwin':
  2743. padding = 20
  2744. minWidth = sw.GetTextExtent(sw.GetLabel())[0] + padding
  2745. for win, name in zip((w, n, s, e, nw, ne, se, sw),
  2746. ('w', 'n', 's', 'e', 'nw', 'ne', 'se', 'sw')):
  2747. win.SetMinSize((minWidth, -1))
  2748. win.Bind(wx.EVT_BUTTON, self.OnLookFrom)
  2749. win.SetName(type + '_' + name)
  2750. sizer.Add(nw, pos=(0, 0), flag=wx.ALIGN_CENTER)
  2751. sizer.Add(n, pos=(0, 1), flag=wx.ALIGN_CENTER)
  2752. sizer.Add(ne, pos=(0, 2), flag=wx.ALIGN_CENTER)
  2753. sizer.Add(e, pos=(1, 2), flag=wx.ALIGN_CENTER)
  2754. sizer.Add(se, pos=(2, 2), flag=wx.ALIGN_CENTER)
  2755. sizer.Add(s, pos=(2, 1), flag=wx.ALIGN_CENTER)
  2756. sizer.Add(sw, pos=(2, 0), flag=wx.ALIGN_CENTER)
  2757. sizer.Add(w, pos=(1, 0), flag=wx.ALIGN_CENTER)
  2758. def __GetWindowName(self, data, id):
  2759. for name in six.iterkeys(data):
  2760. if isinstance(data[name], type({})):
  2761. for win in six.itervalues(data[name]):
  2762. if win == id:
  2763. return name
  2764. else:
  2765. if data[name] == id:
  2766. return name
  2767. return None
  2768. def UpdateSettings(self):
  2769. """Update view from settings values
  2770. stored in self.mapWindow.view dictionary"""
  2771. for control in ('height',
  2772. 'persp',
  2773. 'twist',
  2774. 'z-exag'):
  2775. for win in six.itervalues(self.win['view'][control]):
  2776. try:
  2777. if control == 'height':
  2778. value = int(self.mapWindow.iview[control]['value'])
  2779. else:
  2780. value = self.mapWindow.view[control]['value']
  2781. except KeyError:
  2782. value = -1
  2783. self.FindWindowById(win).SetValue(value)
  2784. viewWin = self.FindWindowById(self.win['view']['position'])
  2785. x, y = viewWin.UpdatePos(self.mapWindow.view['position']['x'],
  2786. self.mapWindow.view['position']['y'])
  2787. viewWin.Draw(pos=(x, y), scale=True)
  2788. viewWin.Refresh(False)
  2789. color = self._getColorString(
  2790. self.mapWindow.view['background']['color'])
  2791. self._display.SetBgColor(str(color))
  2792. self.Update()
  2793. self.mapWindow.Refresh(eraseBackground=False)
  2794. self.mapWindow.render['quick'] = False
  2795. self.mapWindow.Refresh(True)
  2796. def OnShowLightModel(self, event):
  2797. """Show light model"""
  2798. self._display.showLight = event.IsChecked()
  2799. self._display.DrawLightingModel()
  2800. def OnLightChange(self, event):
  2801. """Position of the light changing"""
  2802. winName = self.__GetWindowName(self.win['light'], event.GetId())
  2803. if not winName:
  2804. return
  2805. value = self.FindWindowById(event.GetId()).GetValue()
  2806. self.mapWindow.light['position']['z'] = value
  2807. for win in six.itervalues(self.win['light'][winName]):
  2808. self.FindWindowById(win).SetValue(value)
  2809. self.PostLightEvent()
  2810. event.Skip()
  2811. def OnLightChanged(self, event):
  2812. """Light changed"""
  2813. self.PostLightEvent(refresh=True)
  2814. def OnLightColor(self, event):
  2815. """Color of the light changed"""
  2816. self.mapWindow.light['color'] = tuple(event.GetValue())
  2817. self.PostLightEvent(refresh=True)
  2818. event.Skip()
  2819. def OnLightValue(self, event):
  2820. """Light brightness/ambient changing"""
  2821. data = self.mapWindow.light
  2822. self.OnScroll(event, self.win['light'], data)
  2823. self.PostLightEvent()
  2824. event.Skip()
  2825. def OnBgColor(self, event):
  2826. """Background color changed"""
  2827. color = event.GetValue()
  2828. self.mapWindow.view['background']['color'] = tuple(color)
  2829. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2830. self._display.SetBgColor(str(color))
  2831. if self.mapDisplay.IsAutoRendered():
  2832. self.mapWindow.Refresh(False)
  2833. def OnSetSurface(self, event):
  2834. """Surface selected, currently used for fringes"""
  2835. name = event.GetString()
  2836. try:
  2837. data = self._getLayerPropertiesByName(
  2838. name, mapType='raster')['surface']
  2839. except:
  2840. self.EnablePage('fringe', False)
  2841. return
  2842. layer = self._getMapLayerByName(name, mapType='raster')
  2843. self.EnablePage('fringe', True)
  2844. def OnSetRaster(self, event):
  2845. """Raster map selected, update surface page"""
  2846. name = event.GetString()
  2847. try:
  2848. data = self._getLayerPropertiesByName(
  2849. name, mapType='raster')['surface']
  2850. except TypeError as e:
  2851. self.EnablePage('surface', False)
  2852. return
  2853. layer = self._getMapLayerByName(name, mapType='raster')
  2854. self.EnablePage('surface', True)
  2855. self.UpdateSurfacePage(layer, data, updateName=False)
  2856. def OnSetVector(self, event):
  2857. """Vector map selected, update properties page"""
  2858. name = event.GetString()
  2859. try:
  2860. data = self._getLayerPropertiesByName(
  2861. name, mapType='vector')['vector']
  2862. except:
  2863. self.EnablePage('vector', False)
  2864. return
  2865. layer = self._getMapLayerByName(name, mapType='vector')
  2866. self.EnablePage('vector', True)
  2867. self.UpdateVectorPage(layer, data, updateName=False)
  2868. def OnSetRaster3D(self, event):
  2869. """3D Raster map selected, update surface page"""
  2870. name = event.GetString()
  2871. try:
  2872. data = self._getLayerPropertiesByName(
  2873. name, mapType='raster_3d')['volume']
  2874. except:
  2875. self.EnablePage('volume', False)
  2876. return
  2877. layer = self._getMapLayerByName(name, mapType='raster_3d')
  2878. self.EnablePage('volume', True)
  2879. self.UpdateVolumePage(layer, data, updateName=False)
  2880. def OnViewChange(self, event):
  2881. """Change view, render in quick mode"""
  2882. # find control
  2883. winName = self.__GetWindowName(self.win['view'], event.GetId())
  2884. if not winName:
  2885. return
  2886. value = self.FindWindowById(event.GetId()).GetValue()
  2887. slider = self.FindWindowById(self.win['view'][winName]['slider'])
  2888. if winName == 'persp' and not (0 <= value <= 180):
  2889. return
  2890. self.AdjustSliderRange(slider=slider, value=value)
  2891. if winName == 'height':
  2892. view = self.mapWindow.iview # internal
  2893. else:
  2894. view = self.mapWindow.view
  2895. if winName == 'z-exag' and value >= 0:
  2896. self.PostViewEvent(zExag=True)
  2897. else:
  2898. self.PostViewEvent(zExag=False)
  2899. if winName in ('persp', 'twist'):
  2900. convert = int
  2901. else:
  2902. convert = float
  2903. view[winName]['value'] = convert(value)
  2904. for win in six.itervalues(self.win['view'][winName]):
  2905. self.FindWindowById(win).SetValue(value)
  2906. self.mapWindow.iview['dir']['use'] = False
  2907. self.mapWindow.render['quick'] = True
  2908. if self.mapDisplay.IsAutoRendered():
  2909. self.mapWindow.Refresh(False)
  2910. event.Skip()
  2911. def OnViewChanged(self, event):
  2912. """View changed, render in full resolution"""
  2913. self.mapWindow.render['quick'] = False
  2914. self.mapWindow.Refresh(False)
  2915. self.UpdateSettings()
  2916. try: # when calling event = None
  2917. event.Skip()
  2918. except AttributeError:
  2919. pass
  2920. def OnViewChangedText(self, event):
  2921. """View changed, render in full resolution"""
  2922. self.mapWindow.render['quick'] = False
  2923. self.OnViewChange(event)
  2924. self.OnViewChanged(None)
  2925. self.Update()
  2926. event.Skip()
  2927. def OnLookAt(self, event):
  2928. """Look here/center"""
  2929. name = self.FindWindowById(event.GetId()).GetName()
  2930. if name == 'center':
  2931. self._display.LookAtCenter()
  2932. focus = self.mapWindow.iview['focus']
  2933. focus['x'], focus['y'], focus['z'] = self._display.GetFocus()
  2934. self.mapWindow.saveHistory = True
  2935. self.mapWindow.Refresh(False)
  2936. elif name == 'top':
  2937. self.mapWindow.view['position']['x'] = 0.5
  2938. self.mapWindow.view['position']['y'] = 0.5
  2939. self.PostViewEvent(zExag=True)
  2940. self.UpdateSettings()
  2941. self.mapWindow.Refresh(False)
  2942. else: # here
  2943. if self.FindWindowById(event.GetId()).GetValue():
  2944. self.mapDisplay.Raise()
  2945. self.mapWindow.mouse['use'] = 'lookHere'
  2946. self.mapWindow.SetNamedCursor('cross')
  2947. else:
  2948. self.mapWindow.mouse['use'] = 'default'
  2949. self.mapWindow.SetNamedCursor('default')
  2950. def OnResetView(self, event):
  2951. """Reset to default view (view page)"""
  2952. self.mapWindow.ResetView()
  2953. self.UpdateSettings()
  2954. self.mapWindow.Refresh(False)
  2955. def OnResetSurfacePosition(self, event):
  2956. """Reset position of surface"""
  2957. for win in six.itervalues(self.win['surface']['position']):
  2958. if win == self.win['surface']['position']['axis']:
  2959. self.FindWindowById(win).SetSelection(2) # Z
  2960. elif win == self.win['surface']['position']['reset']:
  2961. continue
  2962. else:
  2963. self.FindWindowById(win).SetValue(0)
  2964. data = self.GetLayerData('surface')
  2965. data['surface']['position']['x'] = 0
  2966. data['surface']['position']['y'] = 0
  2967. data['surface']['position']['z'] = 0
  2968. data['surface']['position']['update'] = None
  2969. # update properties
  2970. event = wxUpdateProperties(data=data)
  2971. wx.PostEvent(self.mapWindow, event)
  2972. if self.mapDisplay.IsAutoRendered():
  2973. self.mapWindow.Refresh(False)
  2974. def OnLookFrom(self, event):
  2975. """Position of view/light changed by buttons"""
  2976. name = self.FindWindowById(event.GetId()).GetName()
  2977. buttonName = name.split('_')[1]
  2978. if name.split('_')[0] == 'view':
  2979. type = 'view'
  2980. data = self.mapWindow.view
  2981. else:
  2982. type = 'light'
  2983. data = self.mapWindow.light
  2984. if buttonName == 'n': # north
  2985. data['position']['x'] = 0.5
  2986. data['position']['y'] = 0.0
  2987. elif buttonName == 's': # south
  2988. data['position']['x'] = 0.5
  2989. data['position']['y'] = 1.0
  2990. elif buttonName == 'e': # east
  2991. data['position']['x'] = 1.0
  2992. data['position']['y'] = 0.5
  2993. elif buttonName == 'w': # west
  2994. data['position']['x'] = 0.0
  2995. data['position']['y'] = 0.5
  2996. elif buttonName == 'nw': # north-west
  2997. data['position']['x'] = 0.0
  2998. data['position']['y'] = 0.0
  2999. elif buttonName == 'ne': # north-east
  3000. data['position']['x'] = 1.0
  3001. data['position']['y'] = 0.0
  3002. elif buttonName == 'se': # south-east
  3003. data['position']['x'] = 1.0
  3004. data['position']['y'] = 1.0
  3005. elif buttonName == 'sw': # south-west
  3006. data['position']['x'] = 0.0
  3007. data['position']['y'] = 1.0
  3008. if type == 'view':
  3009. self.PostViewEvent(zExag=True)
  3010. self.UpdateSettings()
  3011. else:
  3012. self.PostLightEvent()
  3013. lightWin = self.FindWindowById(self.win['light']['position'])
  3014. x, y = lightWin.UpdatePos(self.mapWindow.light['position']['x'],
  3015. self.mapWindow.light['position']['y'])
  3016. lightWin.Draw(pos=(x, y), scale=True)
  3017. lightWin.Refresh(False)
  3018. self.mapWindow.render['quick'] = False
  3019. self.mapWindow.Refresh(False)
  3020. def OnMapObjUse(self, event):
  3021. """Set surface attribute -- use -- map/constant"""
  3022. if not self.mapWindow.init:
  3023. return
  3024. wx.Yield()
  3025. # find attribute row
  3026. attrb = self.__GetWindowName(self.win['surface'], event.GetId())
  3027. if not attrb:
  3028. attrb = self.__GetWindowName(self.win['volume'], event.GetId())
  3029. nvizType = 'volume'
  3030. else:
  3031. nvizType = 'surface'
  3032. selection = event.GetSelection()
  3033. if self.win[nvizType][attrb]['required']: # no 'unset'
  3034. selection += 1
  3035. if selection == 0: # unset
  3036. useMap = None
  3037. value = ''
  3038. elif selection == 1: # map
  3039. useMap = True
  3040. value = self.FindWindowById(
  3041. self.win[nvizType][attrb]['map']).GetValue()
  3042. elif selection == 2: # constant
  3043. useMap = False
  3044. if attrb == 'color':
  3045. value = self.FindWindowById(
  3046. self.win[nvizType][attrb]['const']).GetColour()
  3047. value = self._getColorString(value)
  3048. else:
  3049. value = self._getPercent(
  3050. self.FindWindowById(
  3051. self.win[nvizType][attrb]['const']).GetValue(),
  3052. toPercent=False)
  3053. self.SetMapObjUseMap(nvizType=nvizType,
  3054. attrb=attrb, map=useMap)
  3055. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  3056. if nvizType == 'surface':
  3057. data = self._getLayerPropertiesByName(name, mapType='raster')
  3058. data[nvizType]['attribute'][attrb] = {'map': useMap,
  3059. 'value': str(value),
  3060. 'update': None}
  3061. else: # volume / isosurface
  3062. data = self._getLayerPropertiesByName(name, mapType='raster_3d')
  3063. list = self.FindWindowById(self.win['volume']['isosurfs'])
  3064. id = list.GetSelection()
  3065. if id != -1:
  3066. data[nvizType]['isosurface'][id][attrb] = {'map': useMap,
  3067. 'value': str(value),
  3068. 'update': None}
  3069. # update properties
  3070. event = wxUpdateProperties(data=data)
  3071. wx.PostEvent(self.mapWindow, event)
  3072. if self.mapDisplay.IsAutoRendered():
  3073. self.mapWindow.Refresh(False)
  3074. def EnablePage(self, name, enabled=True):
  3075. """Enable/disable all widgets on page"""
  3076. for key, item in six.iteritems(self.win[name]):
  3077. if key in ('map', 'surface', 'new', 'planes'):
  3078. continue
  3079. if isinstance(item, dict):
  3080. for skey, sitem in six.iteritems(self.win[name][key]):
  3081. if isinstance(sitem, dict):
  3082. for ssitem in six.itervalues(self.win[name][key][skey]):
  3083. if not isinstance(ssitem, bool) and \
  3084. isinstance(ssitem, int):
  3085. self.FindWindowById(ssitem).Enable(enabled)
  3086. else:
  3087. # type(bool) != types.IntType but
  3088. # isinstance(bool) == types.IntType
  3089. if not isinstance(sitem, bool) and \
  3090. isinstance(sitem, int):
  3091. self.FindWindowById(sitem).Enable(enabled)
  3092. else:
  3093. if not isinstance(item, bool) and \
  3094. isinstance(item, int):
  3095. self.FindWindowById(item).Enable(enabled)
  3096. def SetMapObjUseMap(self, nvizType, attrb, map=None):
  3097. """Update dialog widgets when attribute type changed"""
  3098. if attrb in ('topo', 'color', 'shine'):
  3099. incSel = -1 # decrement selection (no 'unset')
  3100. else:
  3101. incSel = 0
  3102. if nvizType == 'volume' and attrb == 'topo':
  3103. return
  3104. if map is True: # map
  3105. if attrb != 'topo': # changing map topography not allowed
  3106. # not sure why, but here must be disabled both ids, should be
  3107. # fixed!
  3108. self.FindWindowById(
  3109. self.win[nvizType][attrb]['map']).Enable(True)
  3110. if self.win[nvizType][attrb]['const']:
  3111. self.FindWindowById(
  3112. self.win[nvizType][attrb]['const']).Enable(False)
  3113. self.FindWindowById(
  3114. self.win[nvizType][attrb]['use']).SetSelection(
  3115. 1 + incSel)
  3116. elif map is False: # const
  3117. self.FindWindowById(self.win[nvizType][attrb]['map']).Enable(False)
  3118. if self.win[nvizType][attrb]['const']:
  3119. self.FindWindowById(
  3120. self.win[nvizType][attrb]['const']).Enable(True)
  3121. self.FindWindowById(
  3122. self.win[nvizType][attrb]['use']).SetSelection(
  3123. 2 + incSel)
  3124. else: # unset
  3125. self.FindWindowById(
  3126. self.win[nvizType][attrb]['use']).SetSelection(0)
  3127. self.FindWindowById(self.win[nvizType][attrb]['map']).Enable(False)
  3128. if self.win[nvizType][attrb]['const']:
  3129. self.FindWindowById(
  3130. self.win[nvizType][attrb]['const']).Enable(False)
  3131. def OnSurfaceMap(self, event):
  3132. """Set surface attribute"""
  3133. if self.vetoGSelectEvt:
  3134. self.vetoGSelectEvt = False
  3135. return
  3136. self.SetMapObjAttrb(nvizType='surface', winId=event.GetId())
  3137. def SetMapObjAttrb(self, nvizType, winId):
  3138. """Set map object (surface/isosurface) attribute (map/constant)"""
  3139. if not self.mapWindow.init:
  3140. return
  3141. attrb = self.__GetWindowName(self.win[nvizType], winId)
  3142. if not attrb:
  3143. return
  3144. if not (nvizType == 'volume' and attrb == 'topo'):
  3145. selection = self.FindWindowById(
  3146. self.win[nvizType][attrb]['use']).GetSelection()
  3147. if self.win[nvizType][attrb]['required']:
  3148. selection += 1
  3149. if selection == 0: # unset
  3150. useMap = None
  3151. value = ''
  3152. elif selection == 1: # map
  3153. value = self.FindWindowById(
  3154. self.win[nvizType][attrb]['map']).GetValue()
  3155. useMap = True
  3156. else: # constant
  3157. if attrb == 'color':
  3158. value = self.FindWindowById(
  3159. self.win[nvizType][attrb]['const']).GetColour()
  3160. # tuple to string
  3161. value = self._getColorString(value)
  3162. else:
  3163. value = self._getPercent(
  3164. self.FindWindowById(
  3165. self.win[nvizType][attrb]['const']).GetValue(),
  3166. toPercent=False)
  3167. useMap = False
  3168. else:
  3169. useMap = None
  3170. value = self.FindWindowById(
  3171. self.win[nvizType][attrb]['const']).GetValue()
  3172. if not self.pageChanging:
  3173. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  3174. if nvizType == 'surface':
  3175. data = self._getLayerPropertiesByName(name, mapType='raster')
  3176. data[nvizType]['attribute'][attrb] = {'map': useMap,
  3177. 'value': str(value),
  3178. 'update': None}
  3179. else:
  3180. data = self._getLayerPropertiesByName(
  3181. name, mapType='raster_3d')
  3182. list = self.FindWindowById(self.win['volume']['isosurfs'])
  3183. id = list.GetSelection()
  3184. if id > -1:
  3185. data[nvizType]['isosurface'][id][attrb] = {
  3186. 'map': useMap, 'value': str(value), 'update': None}
  3187. if attrb == 'topo':
  3188. list = self.FindWindowById(
  3189. self.win['volume']['isosurfs'])
  3190. sel = list.GetSelection()
  3191. list.SetString(sel, "%s %s" % (_("Level"), str(value)))
  3192. list.Check(sel)
  3193. # update properties
  3194. event = wxUpdateProperties(data=data)
  3195. wx.PostEvent(self.mapWindow, event)
  3196. if self.mapDisplay.IsAutoRendered():
  3197. self.mapWindow.Refresh(False)
  3198. def OnSurfaceResolution(self, event):
  3199. """Draw resolution changed"""
  3200. self.SetSurfaceResolution()
  3201. if self.mapDisplay.IsAutoRendered():
  3202. self.mapWindow.Refresh(False)
  3203. def SetSurfaceResolution(self):
  3204. """Set draw resolution"""
  3205. coarse = self.FindWindowById(
  3206. self.win['surface']['draw']['res-coarse']).GetValue()
  3207. fine = self.FindWindowById(
  3208. self.win['surface']['draw']['res-fine']).GetValue()
  3209. data = self.GetLayerData('surface')
  3210. data['surface']['draw']['resolution'] = {'coarse': coarse,
  3211. 'fine': fine,
  3212. 'update': None}
  3213. # update properties
  3214. event = wxUpdateProperties(data=data)
  3215. wx.PostEvent(self.mapWindow, event)
  3216. def SetSurfaceMode(self):
  3217. """Set draw mode"""
  3218. mode = self.FindWindowById(
  3219. self.win['surface']['draw']['mode']).GetSelection()
  3220. style = self.FindWindowById(
  3221. self.win['surface']['draw']['style']).GetSelection()
  3222. if style == 0: # wire
  3223. self.FindWindowById(self.win['surface']['draw'][
  3224. 'wire-color']).Enable(True)
  3225. elif style == 1: # surface
  3226. self.FindWindowById(self.win['surface']['draw'][
  3227. 'wire-color']).Enable(False)
  3228. shade = self.FindWindowById(
  3229. self.win['surface']['draw']['shading']).GetSelection()
  3230. value, desc = self.mapWindow.nvizDefault.GetDrawMode(
  3231. mode, style, shade)
  3232. return value, desc
  3233. def OnSurfaceMode(self, event):
  3234. """Set draw mode"""
  3235. value, desc = self.SetSurfaceMode()
  3236. data = self.GetLayerData('surface')
  3237. data['surface']['draw']['mode'] = {'value': value,
  3238. 'desc': desc,
  3239. 'update': None}
  3240. # update properties
  3241. event = wxUpdateProperties(data=data)
  3242. wx.PostEvent(self.mapWindow, event)
  3243. if self.mapDisplay.IsAutoRendered():
  3244. self.mapWindow.Refresh(False)
  3245. def OnSurfaceModeAll(self, event):
  3246. """Set draw mode (including wire color) for all loaded surfaces"""
  3247. value, desc = self.SetSurfaceMode()
  3248. coarse = self.FindWindowById(
  3249. self.win['surface']['draw']['res-coarse']).GetValue()
  3250. fine = self.FindWindowById(
  3251. self.win['surface']['draw']['res-fine']).GetValue()
  3252. color = self.FindWindowById(
  3253. self.win['surface']['draw']['wire-color']).GetColour()
  3254. cvalue = self._getColorString(color)
  3255. for name in self.mapWindow.GetLayerNames(type='raster'):
  3256. data = self._getLayerPropertiesByName(name, mapType='raster')
  3257. if not data:
  3258. continue # shouldy no happen
  3259. data['surface']['draw']['all'] = True
  3260. data['surface']['draw']['mode'] = {'value': value,
  3261. 'desc': desc,
  3262. 'update': None}
  3263. data['surface']['draw']['resolution'] = {'coarse': coarse,
  3264. 'fine': fine,
  3265. 'update': None}
  3266. data['surface']['draw']['wire-color'] = {'value': cvalue,
  3267. 'update': None}
  3268. # update properties
  3269. event = wxUpdateProperties(data=data)
  3270. wx.PostEvent(self.mapWindow, event)
  3271. if self.mapDisplay.IsAutoRendered():
  3272. self.mapWindow.Refresh(False)
  3273. def _getColorString(self, color):
  3274. """Convert color tuple to R:G:B format
  3275. :param color: tuple
  3276. :return: string R:G:B
  3277. """
  3278. return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  3279. def _getColorFromString(self, color, delim=':'):
  3280. """Convert color string (R:G:B) to wx.Colour
  3281. :param color: string
  3282. :param delim: delimiter
  3283. :return: wx.Colour instance
  3284. """
  3285. return wx.Colour(*map(int, color.split(delim)))
  3286. def _get3dRange(self, name):
  3287. """Gelper func for getting range of 3d map"""
  3288. ret = RunCommand('r3.info', read=True, flags='r', map=name)
  3289. if ret:
  3290. range = []
  3291. for value in ret.strip('\n').split('\n'):
  3292. range.append(float(value.split('=')[1]))
  3293. return range
  3294. return -1e6, 1e6
  3295. def _getPercent(self, value, toPercent=True):
  3296. """Convert values 0 - 255 to percents and vice versa"""
  3297. value = int(value)
  3298. if toPercent:
  3299. value = int(value / 255. * 100)
  3300. else:
  3301. value = int(value / 100. * 255)
  3302. return value
  3303. def OnSurfaceWireColor(self, event):
  3304. """Set wire color"""
  3305. data = self.GetLayerData('surface')
  3306. value = self._getColorString(event.GetValue())
  3307. data['surface']['draw']['wire-color'] = {'value': value,
  3308. 'update': None}
  3309. # update properties
  3310. event = wxUpdateProperties(data=data)
  3311. wx.PostEvent(self.mapWindow, event)
  3312. if self.mapDisplay.IsAutoRendered():
  3313. self.mapWindow.Refresh(False)
  3314. def OnSurfaceAxis(self, event):
  3315. """Surface position, axis changed"""
  3316. data = self.GetLayerData('surface')
  3317. id = data['surface']['object']['id']
  3318. axis = self.FindWindowById(
  3319. self.win['surface']['position']['axis']).GetSelection()
  3320. slider = self.FindWindowById(self.win['surface']['position']['slider'])
  3321. text = self.FindWindowById(self.win['surface']['position']['text'])
  3322. xydim = self._display.GetLongDim()
  3323. zdim = self._display.GetZRange()
  3324. zdim = zdim[1] - zdim[0]
  3325. x, y, z = self._display.GetSurfacePosition(id)
  3326. if axis == 0: # x
  3327. slider.SetRange(-3 * xydim, 3 * xydim)
  3328. slider.SetValue(x)
  3329. text.SetValue(x)
  3330. elif axis == 1: # y
  3331. slider.SetRange(-3 * xydim, 3 * xydim)
  3332. slider.SetValue(y)
  3333. text.SetValue(y)
  3334. else: # z
  3335. slider.SetRange(-3 * zdim, 3 * zdim)
  3336. slider.SetValue(z)
  3337. text.SetValue(z)
  3338. def OnSurfacePosition(self, event):
  3339. """Surface position"""
  3340. winName = self.__GetWindowName(self.win['surface'], event.GetId())
  3341. if not winName:
  3342. return
  3343. axis = self.FindWindowById(
  3344. self.win['surface']['position']['axis']).GetSelection()
  3345. value = self.FindWindowById(event.GetId()).GetValue()
  3346. slider = self.FindWindowById(self.win['surface'][winName]['slider'])
  3347. self.AdjustSliderRange(slider=slider, value=value)
  3348. for win in six.itervalues(self.win['surface']['position']):
  3349. if win in (self.win['surface']['position']['axis'],
  3350. self.win['surface']['position']['reset']):
  3351. continue
  3352. else:
  3353. self.FindWindowById(win).SetValue(value)
  3354. data = self.GetLayerData('surface')
  3355. id = data['surface']['object']['id']
  3356. x, y, z = self._display.GetSurfacePosition(id)
  3357. if axis == 0: # x
  3358. x = value
  3359. elif axis == 1: # y
  3360. y = value
  3361. else: # z
  3362. z = value
  3363. data['surface']['position']['x'] = x
  3364. data['surface']['position']['y'] = y
  3365. data['surface']['position']['z'] = z
  3366. data['surface']['position']['update'] = None
  3367. # update properties
  3368. event = wxUpdateProperties(data=data)
  3369. wx.PostEvent(self.mapWindow, event)
  3370. self.mapWindow.render['quick'] = True
  3371. if self.mapDisplay.IsAutoRendered():
  3372. self.mapWindow.Refresh(False)
  3373. # self.UpdatePage('surface')
  3374. def OnSurfacePositionChanged(self, event):
  3375. """Surface position changed"""
  3376. self.mapWindow.render['quick'] = False
  3377. self.mapWindow.Refresh(False)
  3378. def OnSurfacePositionText(self, event):
  3379. """Surface position changed by textctrl"""
  3380. self.OnSurfacePosition(event)
  3381. self.OnSurfacePositionChanged(None)
  3382. def UpdateVectorShow(self, vecType, enabled):
  3383. """Enable/disable lines/points widgets
  3384. :param vecType: vector type (lines, points)
  3385. """
  3386. if vecType != 'lines' and vecType != 'points':
  3387. return False
  3388. for win in self.win['vector'][vecType].keys():
  3389. if win == 'show':
  3390. continue
  3391. if isinstance(self.win['vector'][vecType][win], type({})):
  3392. for swin in self.win['vector'][vecType][win].keys():
  3393. if enabled:
  3394. self.FindWindowById(
  3395. self.win['vector'][vecType][win][swin]).Enable(True)
  3396. else:
  3397. self.FindWindowById(
  3398. self.win['vector'][vecType][win][swin]).Enable(False)
  3399. else:
  3400. if enabled:
  3401. self.FindWindowById(
  3402. self.win['vector'][vecType][win]).Enable(True)
  3403. else:
  3404. self.FindWindowById(
  3405. self.win['vector'][vecType][win]).Enable(False)
  3406. return True
  3407. def OnVectorShow(self, event):
  3408. """Show vector lines/points"""
  3409. winId = event.GetId()
  3410. if winId == self.win['vector']['lines']['show']:
  3411. vecType = 'lines'
  3412. points = False
  3413. else: # points
  3414. vecType = 'points'
  3415. points = True
  3416. checked = event.IsChecked()
  3417. name = self.FindWindowById(self.win['vector']['map']).GetValue()
  3418. items = self.tree.FindItemByData(key='name', value=name)
  3419. for item in items:
  3420. if self.tree.GetLayerInfo(item, key='type') == 'vector':
  3421. break
  3422. data = self.GetLayerData('vector')['vector']
  3423. if checked:
  3424. self.mapWindow.LoadVector(item, points=points, append=False)
  3425. else:
  3426. self.mapWindow.UnloadVector(item, points=points, remove=False)
  3427. self.UpdateVectorShow(vecType, checked)
  3428. if checked:
  3429. try:
  3430. id = data[vecType]['object']['id']
  3431. except KeyError:
  3432. id = -1
  3433. if id > 0:
  3434. self.mapWindow.SetMapObjProperties(item, id, vecType)
  3435. # update properties
  3436. event = wxUpdateProperties(data=data)
  3437. wx.PostEvent(self.mapWindow, event)
  3438. if self.mapDisplay.IsAutoRendered():
  3439. self.mapWindow.Refresh(False)
  3440. event.Skip()
  3441. def OnVectorLinesMode(self, event):
  3442. """Display vector lines on surface/3d"""
  3443. rasters = self.mapWindow.GetLayerNames('raster')
  3444. if event.GetSelection() == 0: # surface
  3445. if len(rasters) < 1:
  3446. self.FindWindowById(
  3447. self.win['vector']['lines']['surface']).Enable(False)
  3448. self.FindWindowById(
  3449. self.win['vector']['lines']['3d']).SetSelection(1)
  3450. return
  3451. self.FindWindowById(
  3452. self.win['vector']['lines']['surface']).Enable(True)
  3453. # set first found surface
  3454. data = self.GetLayerData('vector')
  3455. data['vector']['lines']['mode']['surface'] = rasters[0]
  3456. self.FindWindowById(
  3457. self.win['vector']['lines']['surface']).SetStringSelection(
  3458. rasters[0])
  3459. else: # 3D
  3460. self.FindWindowById(self.win['vector']['lines'][
  3461. 'surface']).Enable(False)
  3462. self.OnVectorLines(event)
  3463. event.Skip()
  3464. def OnVectorLines(self, event):
  3465. """Set vector lines mode, apply changes if auto-rendering is enabled"""
  3466. data = self.GetLayerData('vector')
  3467. width = self.FindWindowById(
  3468. self.win['vector']['lines']['width']).GetValue()
  3469. mode = {}
  3470. if self.FindWindowById(self.win['vector']['lines'][
  3471. '3d']).GetSelection() == 0:
  3472. mode['type'] = 'surface'
  3473. mode['surface'] = {}
  3474. checklist = self.FindWindowById(
  3475. self.win['vector']['lines']['surface'])
  3476. value = list()
  3477. checked = list()
  3478. for surface in range(checklist.GetCount()):
  3479. value.append(checklist.GetString(surface))
  3480. checked.append(checklist.IsChecked(surface))
  3481. mode['surface']['value'] = value
  3482. mode['surface']['show'] = checked
  3483. else:
  3484. mode['type'] = '3d'
  3485. for attrb in ('width', 'mode'):
  3486. data['vector']['lines'][attrb]['update'] = None
  3487. data['vector']['lines']['width']['value'] = width
  3488. data['vector']['lines']['mode'] = mode
  3489. color = self.FindWindowById(
  3490. self.win['vector']['lines']['color']).GetColour()
  3491. if isinstance(color, csel.ColourSelect):
  3492. pass # color picker not yet instantiated
  3493. else:
  3494. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  3495. data['vector']['lines']['color']['update'] = None
  3496. data['vector']['lines']['color']['value'] = color
  3497. # update properties
  3498. event = wxUpdateProperties(data=data)
  3499. wx.PostEvent(self.mapWindow, event)
  3500. if self.mapDisplay.IsAutoRendered():
  3501. self.mapWindow.Refresh(False)
  3502. def OnVectorPointsMode(self, event):
  3503. rasters = self.mapWindow.GetLayerNames('raster')
  3504. if event.GetSelection() == 0: # surface
  3505. if len(rasters) < 1:
  3506. self.FindWindowById(
  3507. self.win['vector']['points']['surface']).Enable(False)
  3508. self.FindWindowById(
  3509. self.win['vector']['points']['3d']).SetSelection(1)
  3510. return
  3511. self.FindWindowById(
  3512. self.win['vector']['points']['surface']).Enable(True)
  3513. # set first found surface
  3514. data = self.GetLayerData('vector')
  3515. data['vector']['points']['mode']['surface']['value'] = rasters
  3516. data['vector']['points']['mode']['3d'] = False
  3517. self.FindWindowById(
  3518. self.win['vector']['points']['surface']).SetStringSelection(
  3519. rasters[0])
  3520. else: # use z coordinate if 3d
  3521. data = self.GetLayerData('vector')
  3522. data['vector']['points']['mode']['3d'] = True
  3523. self.FindWindowById(self.win['vector']['points'][
  3524. 'surface']).Enable(False)
  3525. data['vector']['points']['mode']['update'] = None
  3526. self.OnVectorPoints(event)
  3527. event.Skip()
  3528. def OnVectorHeight(self, event):
  3529. id = event.GetId()
  3530. if id in self.win['vector']['lines']['height'].values():
  3531. vtype = 'lines'
  3532. else:
  3533. vtype = 'points'
  3534. value = self.FindWindowById(id).GetValue()
  3535. slider = self.FindWindowById(
  3536. self.win['vector'][vtype]['height']['slider'])
  3537. self.AdjustSliderRange(slider=slider, value=value)
  3538. for win in six.itervalues(self.win['vector'][vtype]['height']):
  3539. self.FindWindowById(win).SetValue(value)
  3540. data = self.GetLayerData('vector')
  3541. data['vector'][vtype]['height'] = {'value': value,
  3542. 'update': None}
  3543. # update properties
  3544. event = wxUpdateProperties(data=data)
  3545. wx.PostEvent(self.mapWindow, event)
  3546. self.mapWindow.render['quick'] = True
  3547. self.mapWindow.render['v' + vtype] = True
  3548. self.mapWindow.Refresh(False)
  3549. event.Skip()
  3550. def OnVectorHeightFull(self, event):
  3551. """Vector height changed, render in full resolution"""
  3552. self.OnVectorHeight(event)
  3553. # self.OnVectorSurface(event)
  3554. id = event.GetId()
  3555. if id in self.win['vector']['lines']['height'].values():
  3556. vtype = 'lines'
  3557. else:
  3558. vtype = 'points'
  3559. self.mapWindow.render['quick'] = False
  3560. self.mapWindow.render['v' + vtype] = False
  3561. self.mapWindow.Refresh(False)
  3562. def OnVectorHeightText(self, event):
  3563. """Vector height changed, render in full resolution"""
  3564. # self.OnVectorHeight(event)
  3565. self.OnVectorHeightFull(event)
  3566. def OnVectorSurface(self, event):
  3567. """Reference surface for vector map (lines/points)"""
  3568. id = event.GetId()
  3569. if id == self.win['vector']['lines']['surface']:
  3570. vtype = 'lines'
  3571. else:
  3572. vtype = 'points'
  3573. checkList = self.FindWindowById(self.win['vector'][vtype]['surface'])
  3574. checked = []
  3575. surfaces = []
  3576. for items in range(checkList.GetCount()):
  3577. checked.append(checkList.IsChecked(items))
  3578. surfaces.append(checkList.GetString(items))
  3579. data = self.GetLayerData('vector')
  3580. data['vector'][vtype]['mode']['surface'] = {'value': surfaces,
  3581. 'show': checked}
  3582. data['vector'][vtype]['mode']['update'] = None
  3583. # update properties
  3584. event = wxUpdateProperties(data=data)
  3585. wx.PostEvent(self.mapWindow, event)
  3586. if self.mapDisplay.IsAutoRendered():
  3587. self.mapWindow.Refresh(False)
  3588. def OnVectorPoints(self, event):
  3589. """Set vector points mode, apply changes if auto-rendering is enabled"""
  3590. data = self.GetLayerData('vector')
  3591. size = self.FindWindowById(
  3592. self.win['vector']['points']['size']).GetValue()
  3593. marker = self.FindWindowById(
  3594. self.win['vector']['points']['marker']).GetSelection()
  3595. # width = self.FindWindowById(self.win['vector']['points']['width']).GetValue()
  3596. for attrb in ('size', 'marker'):
  3597. data['vector']['points'][attrb]['update'] = None
  3598. data['vector']['points']['size']['value'] = size
  3599. # data['vector']['points']['width']['value'] = width
  3600. data['vector']['points']['marker']['value'] = marker
  3601. color = self.FindWindowById(
  3602. self.win['vector']['points']['color']).GetColour()
  3603. if isinstance(color, csel.ColourSelect):
  3604. pass # color picker not yet instantiated
  3605. else:
  3606. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  3607. data['vector']['points']['color']['update'] = None
  3608. data['vector']['points']['color']['value'] = color
  3609. # update properties
  3610. event = wxUpdateProperties(data=data)
  3611. wx.PostEvent(self.mapWindow, event)
  3612. if self.mapDisplay.IsAutoRendered():
  3613. self.mapWindow.Refresh(False)
  3614. def OnCheckThematic(self, event):
  3615. """Switch on/off thematic mapping"""
  3616. # can be called with no event to enable/disable button
  3617. if not event:
  3618. ids = (self.win['vector']['points']['thematic']['checkcolor'],
  3619. self.win['vector']['lines']['thematic']['checkcolor'],
  3620. self.win['vector']['points']['thematic']['checksize'],
  3621. self.win['vector']['lines']['thematic']['checkwidth'])
  3622. else:
  3623. ids = (event.GetId(),)
  3624. for id in ids:
  3625. if id in self.win['vector']['points']['thematic'].values():
  3626. vtype = 'points'
  3627. if id == self.win['vector'][vtype]['thematic']['checkcolor']:
  3628. attrType = 'color'
  3629. else:
  3630. attrType = 'size'
  3631. else:
  3632. vtype = 'lines'
  3633. if id == self.win['vector'][vtype]['thematic']['checkcolor']:
  3634. attrType = 'color'
  3635. else:
  3636. attrType = 'width'
  3637. check = self.win['vector'][vtype]['thematic']['check' + attrType]
  3638. button = self.win['vector'][vtype]['thematic']['button' + attrType]
  3639. if self.FindWindowById(check).GetValue():
  3640. checked = True
  3641. else:
  3642. checked = False
  3643. self.FindWindowById(button).Enable(checked)
  3644. data = self.GetLayerData('vector')
  3645. # decide if use GRASSRGB column
  3646. if attrType == 'color':
  3647. name = self.FindWindowById(
  3648. self.win['vector']['map']).GetValue()
  3649. if not data['vector'][vtype]['thematic']['rgbcolumn']:
  3650. try:
  3651. id = data['vector'][vtype]['object']['id']
  3652. # if GRASSRGB exists and color table doesn't, use GRGB
  3653. if self.HasGRASSRGB(name) and \
  3654. not self._display.CheckColorTable(id=id, type=vtype):
  3655. data['vector'][vtype]['thematic'][
  3656. 'rgbcolumn'] = 'GRASSRGB'
  3657. except KeyError:
  3658. pass
  3659. data['vector'][vtype]['thematic']['use' + attrType] = checked
  3660. data['vector'][vtype]['thematic']['update'] = None
  3661. # update properties
  3662. event = wxUpdateProperties(data=data)
  3663. wx.PostEvent(self.mapWindow, event)
  3664. if self.mapDisplay.IsAutoRendered():
  3665. self.mapWindow.Refresh(False)
  3666. def HasGRASSRGB(self, name):
  3667. """Check if GRASSRGB column exist."""
  3668. column = False
  3669. dbInfo = VectorDBInfo(name)
  3670. if len(dbInfo.layers):
  3671. table = dbInfo.layers[1]['table']
  3672. if 'GRASSRGB' in dbInfo.GetTableDesc(table):
  3673. column = True
  3674. return column
  3675. def OnSetThematic(self, event):
  3676. """Set options for thematic points"""
  3677. if event.GetId() in self.win['vector']['points']['thematic'].values():
  3678. vtype = 'points'
  3679. else:
  3680. vtype = 'lines'
  3681. if event.GetId() == self.win['vector'][vtype][
  3682. 'thematic']['buttoncolor']:
  3683. attrType = 'color'
  3684. elif vtype == 'points':
  3685. attrType = 'size'
  3686. else:
  3687. attrType = 'width'
  3688. ctable = ThematicVectorTable(self, vtype, attributeType=attrType)
  3689. ctable.CentreOnScreen()
  3690. ctable.Show()
  3691. def UpdateIsosurfButtons(self, list):
  3692. """Enable/disable buttons 'add', 'delete',
  3693. 'move up', 'move down'"""
  3694. nitems = list.GetCount()
  3695. add = self.FindWindowById(self.win['volume']['btnAdd'])
  3696. delete = self.FindWindowById(self.win['volume']['btnDelete'])
  3697. moveDown = self.FindWindowById(self.win['volume']['btnMoveDown'])
  3698. moveUp = self.FindWindowById(self.win['volume']['btnMoveUp'])
  3699. if nitems >= wxnviz.MAX_ISOSURFS:
  3700. # disable add button on max
  3701. add.Enable(False)
  3702. else:
  3703. add.Enable(True)
  3704. if nitems < 1:
  3705. # disable 'delete' if only one item in the lis
  3706. delete.Enable(False)
  3707. else:
  3708. delete.Enable(True)
  3709. if list.GetSelection() >= nitems - 1:
  3710. # disable 'move-down' if last
  3711. moveDown.Enable(False)
  3712. else:
  3713. moveDown.Enable(True)
  3714. if list.GetSelection() < 1:
  3715. # disable 'move-up' if first
  3716. moveUp.Enable(False)
  3717. else:
  3718. moveUp.Enable(True)
  3719. def OnVolumeMode(self, event):
  3720. """Change mode isosurfaces/slices"""
  3721. mode = self.FindWindowById(
  3722. self.win['volume']['draw']['mode']).GetSelection()
  3723. data = self.GetLayerData('volume')['volume']
  3724. sizer = self.isoPanel.GetContainingSizer()
  3725. sizer = self.slicePanel.GetContainingSizer()
  3726. listBox = self.FindWindowByName('listStaticBox')
  3727. if mode == 0:
  3728. sizer.Show(self.isoPanel)
  3729. sizer.Hide(self.slicePanel)
  3730. listBox.SetLabel(" %s " % _("List of isosurfaces"))
  3731. data['draw']['mode']['value'] = 0
  3732. data['draw']['mode']['desc'] = 'isosurface'
  3733. else:
  3734. sizer.Hide(self.isoPanel)
  3735. sizer.Show(self.slicePanel)
  3736. listBox.SetLabel(" %s " % _("List of slices"))
  3737. data['draw']['mode']['value'] = 1
  3738. data['draw']['mode']['desc'] = 'slice'
  3739. if event:
  3740. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3741. layer = self._getMapLayerByName(name, mapType='raster_3d')
  3742. self.UpdateVolumePage(layer, data, updateName=False)
  3743. sizer.Layout()
  3744. listBox.GetParent().Fit()
  3745. def OnVolumeDrawMode(self, event):
  3746. """Set isosurface/slice draw mode"""
  3747. self.SetVolumeDrawMode(event.GetSelection())
  3748. def OnVolumeDrawBox(self, event):
  3749. """Set wire box drawing"""
  3750. data = self.GetLayerData('volume')['volume']
  3751. vid = data['object']['id']
  3752. checked = self.FindWindowById(
  3753. self.win['volume']['draw']['box']).GetValue()
  3754. self._display.SetVolumeDrawBox(vid, checked)
  3755. data['draw']['box']['enabled'] = checked
  3756. if self.mapDisplay.IsAutoRendered():
  3757. self.mapWindow.Refresh(False)
  3758. def SetVolumeDrawMode(self, selection):
  3759. """Set isosurface draw mode"""
  3760. data = self.GetLayerData('volume')['volume']
  3761. id = data['object']['id']
  3762. mode = 0
  3763. if selection == 0:
  3764. mode |= wxnviz.DM_FLAT
  3765. else:
  3766. mode |= wxnviz.DM_GOURAUD
  3767. if self.FindWindowById(self.win['volume']['draw'][
  3768. 'mode']).GetSelection() == 0:
  3769. self._display.SetIsosurfaceMode(id, mode)
  3770. data['draw']['shading']['isosurface']['desc'] = 'gouraud'
  3771. data['draw']['shading']['isosurface']['value'] = mode
  3772. else:
  3773. self._display.SetSliceMode(id, mode)
  3774. data['draw']['shading']['slice']['desc'] = 'flat'
  3775. data['draw']['shading']['slice']['value'] = mode
  3776. if self.mapDisplay.IsAutoRendered():
  3777. self.mapWindow.Refresh(False)
  3778. def OnVolumeResolution(self, event):
  3779. """Set isosurface/slice draw resolution"""
  3780. self.SetVolumeResolution(event.GetInt())
  3781. def SetVolumeResolution(self, res):
  3782. """Set isosurface draw resolution"""
  3783. data = self.GetLayerData('volume')['volume']
  3784. id = data['object']['id']
  3785. if self.FindWindowById(self.win['volume']['draw'][
  3786. 'mode']).GetSelection() == 0:
  3787. self._display.SetIsosurfaceRes(id, res)
  3788. data['draw']['resolution']['isosurface']['value'] = res
  3789. else:
  3790. self._display.SetSliceRes(id, res)
  3791. data['draw']['resolution']['slice']['value'] = res
  3792. if self.mapDisplay.IsAutoRendered():
  3793. self.mapWindow.Refresh(False)
  3794. def OnInOutMode(self, event):
  3795. """Change isosurfaces mode inout"""
  3796. data = self.GetLayerData('volume')['volume']
  3797. id = data['object']['id']
  3798. isosurfId = self.FindWindowById(
  3799. self.win['volume']['isosurfs']).GetSelection()
  3800. ret = self._display.SetIsosurfaceInOut(id, isosurfId, event.GetInt())
  3801. if ret == 1:
  3802. data['isosurface'][isosurfId]['inout']['value'] = event.GetInt()
  3803. if self.mapDisplay.IsAutoRendered():
  3804. self.mapWindow.Refresh(False)
  3805. def OnVolumeIsosurfMap(self, event):
  3806. """Set surface attribute"""
  3807. if self.vetoGSelectEvt:
  3808. self.vetoGSelectEvt = False
  3809. return
  3810. self.SetMapObjAttrb(nvizType='volume', winId=event.GetId())
  3811. def OnVolumeCheck(self, event):
  3812. """Isosurface/slice checked (->load) or unchecked (->unload)"""
  3813. if self.FindWindowById(self.win['volume']['draw'][
  3814. 'mode']).GetSelection() == 0:
  3815. mode = 'isosurf'
  3816. else:
  3817. mode = 'slice'
  3818. index = event.GetSelection()
  3819. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3820. data = self.GetLayerData('volume')['volume']
  3821. vid = data['object']['id']
  3822. id = event.GetSelection()
  3823. if mode == 'isosurf':
  3824. if list.IsChecked(index):
  3825. if 'transp' in data['isosurface'][id] and\
  3826. data['isosurface'][id]['transp']['map'] is not None:
  3827. if data['isosurface'][id]['transp']['map']:
  3828. map = True
  3829. value = data['isosurface'][id]['transp']['value']
  3830. elif data['isosurface'][id]['transp']['map'] is not None:
  3831. map = False
  3832. value = data['isosurface'][id]['transp']['value']
  3833. self._display.SetIsosurfaceTransp(vid, id, map, value)
  3834. else:
  3835. self._display.SetIsosurfaceTransp(vid, id, False, "0")
  3836. else:
  3837. # disable -> make transparent
  3838. self._display.SetIsosurfaceTransp(vid, id, False, "255")
  3839. else:
  3840. if list.IsChecked(index):
  3841. value = data['slice'][id]['transp']['value']
  3842. self._display.SetSliceTransp(vid, id, value)
  3843. else:
  3844. # disable -> make transparent
  3845. self._display.SetSliceTransp(vid, id, 255)
  3846. if self.mapDisplay.IsAutoRendered():
  3847. self.mapWindow.Refresh(False)
  3848. def OnVolumeSelect(self, event):
  3849. """Isosurface/Slice item selected"""
  3850. if self.FindWindowById(self.win['volume']['draw'][
  3851. 'mode']).GetSelection() == 0:
  3852. mode = 'isosurf'
  3853. else:
  3854. mode = 'slice'
  3855. winUp = self.FindWindowById(self.win['volume']['btnMoveUp'])
  3856. winDown = self.FindWindowById(self.win['volume']['btnMoveDown'])
  3857. selection = event.GetSelection()
  3858. if selection == -1:
  3859. return
  3860. elif selection == 0:
  3861. winUp.Enable(False)
  3862. if not winDown.IsEnabled():
  3863. winDown.Enable()
  3864. elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
  3865. winDown.Enable(False)
  3866. if not winUp.IsEnabled():
  3867. winUp.Enable()
  3868. else:
  3869. if not winDown.IsEnabled():
  3870. winDown.Enable()
  3871. if not winUp.IsEnabled():
  3872. winUp.Enable()
  3873. # update dialog
  3874. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3875. layer = self._getMapLayerByName(name, mapType='raster_3d')
  3876. if mode == 'isosurf':
  3877. data = self.GetLayerData('volume')['volume'][
  3878. 'isosurface'][selection]
  3879. self.UpdateVolumeIsosurfPage(data)
  3880. else:
  3881. data = self.GetLayerData('volume')['volume']['slice'][selection]
  3882. self.UpdateVolumeSlicePage(data)
  3883. def OnVolumeAdd(self, event):
  3884. """Add new isosurface/slice to the list"""
  3885. if self.FindWindowById(self.win['volume']['draw'][
  3886. 'mode']).GetSelection() == 0:
  3887. mode = 'isosurf'
  3888. else:
  3889. mode = 'slice'
  3890. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3891. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3892. layer = self._getMapLayerByName(name, mapType='raster_3d')
  3893. data = self.GetLayerData('volume')['volume']
  3894. id = data['object']['id']
  3895. sel = list.GetSelection()
  3896. if mode == 'isosurf':
  3897. isosurfData = self.mapWindow.nvizDefault.SetIsosurfaceDefaultProp()
  3898. if isosurfData['color']['map']:
  3899. isosurfData['color']['value'] = layer.name
  3900. level = isosurfData['topo']['value'] = round(
  3901. self._get3dRange(name=layer.name)[0], 2)
  3902. if sel < 0 or sel >= list.GetCount() - 1:
  3903. item = list.Append(item=_("Level {level}").format(level=level))
  3904. else:
  3905. list.Insert(item=_("Level {level}").format(level=level),
  3906. pos=sel + 1) # append
  3907. item = sel + 1
  3908. else:
  3909. sliceData = self.mapWindow.nvizDefault.SetSliceDefaultProp()
  3910. axis = ("X", "Y", "Z")[sliceData['position']['axis']]
  3911. if sel < 0 or sel >= list.GetCount() - 1:
  3912. item = list.Append(
  3913. item=_("Slice parallel to {axis}").format(
  3914. axis=axis))
  3915. else:
  3916. list.Insert(
  3917. item=_("Slice parallel to {axis}").format(
  3918. axis=axis), pos=sel + 1) # append
  3919. item = sel + 1
  3920. list.Check(item)
  3921. list.SetSelection(item)
  3922. if mode == 'isosurf':
  3923. data['isosurface'].insert(item, isosurfData)
  3924. # add isosurface
  3925. self._display.AddIsosurface(id, float(level))
  3926. else:
  3927. data['slice'].insert(item, sliceData)
  3928. # add isosurface
  3929. nslice = self._display.AddSlice(id)
  3930. self._display.SetSlicePosition(
  3931. id, nslice - 1, sliceData['position']['x1'],
  3932. sliceData['position']['x2'],
  3933. sliceData['position']['y1'],
  3934. sliceData['position']['y2'],
  3935. sliceData['position']['z1'],
  3936. sliceData['position']['z2'],
  3937. sliceData['position']['axis'])
  3938. # update properties
  3939. event = wxUpdateProperties(data=data)
  3940. wx.PostEvent(self.mapWindow, event)
  3941. # update buttons
  3942. self.UpdateIsosurfButtons(list)
  3943. if mode == 'isosurf':
  3944. self.UpdateVolumeIsosurfPage(isosurfData)
  3945. else:
  3946. self.UpdateVolumeSlicePage(sliceData)
  3947. if self.mapDisplay.IsAutoRendered():
  3948. self.mapWindow.Refresh(False)
  3949. event.Skip()
  3950. def OnVolumeDelete(self, event):
  3951. """Remove isosurface/slice from list"""
  3952. if self.FindWindowById(self.win['volume']['draw'][
  3953. 'mode']).GetSelection() == 0:
  3954. mode = 'isosurf'
  3955. else:
  3956. mode = 'slice'
  3957. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3958. # remove item from list
  3959. id = list.GetSelection()
  3960. list.Delete(id)
  3961. # select last item
  3962. if list.GetCount() > 0:
  3963. list.SetSelection(list.GetCount() - 1)
  3964. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3965. layer = self._getMapLayerByName(name, mapType='raster_3d')
  3966. data = self.GetLayerData('volume')['volume']
  3967. vid = data['object']['id']
  3968. # delete isosurface
  3969. if mode == 'isosurf':
  3970. del data['isosurface'][id]
  3971. self._display.DeleteIsosurface(vid, id)
  3972. else:
  3973. del data['slice'][id]
  3974. self._display.DeleteSlice(vid, id)
  3975. # update buttons
  3976. if list.GetCount() > 0:
  3977. if mode == 'isosurf':
  3978. self.UpdateVolumeIsosurfPage(
  3979. data['isosurface'][list.GetSelection()])
  3980. else:
  3981. self.UpdateVolumeSlicePage(data['slice'][list.GetSelection()])
  3982. else:
  3983. if mode == 'isosurf':
  3984. self.UpdateVolumeIsosurfPage(data['attribute'])
  3985. else:
  3986. self.UpdateVolumeSlicePage(None)
  3987. self.UpdateIsosurfButtons(list)
  3988. if self.mapDisplay.IsAutoRendered():
  3989. self.mapWindow.Refresh(False)
  3990. event.Skip()
  3991. def OnVolumeMoveUp(self, event):
  3992. """Move isosurface/slice up in the list"""
  3993. if self.FindWindowById(self.win['volume']['draw'][
  3994. 'mode']).GetSelection() == 0:
  3995. mode = 'isosurf'
  3996. else:
  3997. mode = 'slice'
  3998. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3999. sel = list.GetSelection()
  4000. if sel < 1:
  4001. return # this should not happen
  4002. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  4003. layer = self._getMapLayerByName(name, mapType='raster_3d')
  4004. data = self.GetLayerData('volume')['volume']
  4005. id = data['object']['id']
  4006. # move item up
  4007. text = list.GetStringSelection()
  4008. list.Insert(item=text, pos=sel - 1)
  4009. list.Check(sel - 1)
  4010. list.SetSelection(sel - 1)
  4011. list.Delete(sel + 1)
  4012. if mode == 'isosurf':
  4013. data['isosurface'].insert(sel - 1, data['isosurface'][sel])
  4014. del data['isosurface'][sel + 1]
  4015. self._display.MoveIsosurface(id, sel, True)
  4016. else:
  4017. data['slice'].insert(sel - 1, data['slice'][sel])
  4018. del data['slice'][sel + 1]
  4019. self._display.MoveSlice(id, sel, True)
  4020. # update buttons
  4021. self.UpdateIsosurfButtons(list)
  4022. if self.mapDisplay.IsAutoRendered():
  4023. self.mapWindow.Refresh(False)
  4024. event.Skip()
  4025. def OnVolumeMoveDown(self, event):
  4026. """Move isosurface/slice down in the list"""
  4027. if self.FindWindowById(self.win['volume']['draw'][
  4028. 'mode']).GetSelection() == 0:
  4029. mode = 'isosurf'
  4030. else:
  4031. mode = 'slice'
  4032. list = self.FindWindowById(self.win['volume'][mode + 's'])
  4033. sel = list.GetSelection()
  4034. if sel >= list.GetCount() - 1:
  4035. return # this should not happen
  4036. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  4037. layer = self._getMapLayerByName(name, mapType='raster_3d')
  4038. data = self.GetLayerData('volume')['volume']
  4039. id = data['object']['id']
  4040. # move item up
  4041. text = list.GetStringSelection()
  4042. list.Insert(item=text, pos=sel + 2)
  4043. list.Check(sel + 2)
  4044. list.SetSelection(sel + 2)
  4045. list.Delete(sel)
  4046. if mode == 'isosurf':
  4047. data['isosurface'].insert(sel + 2, data['isosurface'][sel])
  4048. del data['isosurface'][sel]
  4049. self._display.MoveIsosurface(id, sel, False)
  4050. else:
  4051. data['slice'].insert(sel + 2, data['slice'][sel])
  4052. del data['slice'][sel]
  4053. self._display.MoveSlice(id, sel, False)
  4054. # update buttons
  4055. self.UpdateIsosurfButtons(list)
  4056. if self.mapDisplay.IsAutoRendered():
  4057. self.mapWindow.Refresh(False)
  4058. event.Skip()
  4059. def OnVolumePositionChanged(self, event):
  4060. """Volume position changed"""
  4061. self.mapWindow.render['quick'] = False
  4062. self.mapWindow.Refresh(False)
  4063. def OnVolumePosition(self, event):
  4064. """Volume position"""
  4065. winName = self.__GetWindowName(self.win['volume'], event.GetId())
  4066. if not winName:
  4067. return
  4068. axis = self.FindWindowById(
  4069. self.win['volume']['position']['axis']).GetSelection()
  4070. value = self.FindWindowById(event.GetId()).GetValue()
  4071. slider = self.FindWindowById(self.win['volume'][winName]['slider'])
  4072. self.AdjustSliderRange(slider=slider, value=value)
  4073. for win in six.itervalues(self.win['volume']['position']):
  4074. if win in (self.win['volume']['position']['axis'],
  4075. self.win['volume']['position']['reset']):
  4076. continue
  4077. else:
  4078. self.FindWindowById(win).SetValue(value)
  4079. data = self.GetLayerData('volume')
  4080. id = data['volume']['object']['id']
  4081. x, y, z = self._display.GetVolumePosition(id)
  4082. if axis == 0: # x
  4083. x = value
  4084. elif axis == 1: # y
  4085. y = value
  4086. else: # z
  4087. z = value
  4088. data['volume']['position']['x'] = x
  4089. data['volume']['position']['y'] = y
  4090. data['volume']['position']['z'] = z
  4091. data['volume']['position']['update'] = None
  4092. # update properties
  4093. event = wxUpdateProperties(data=data)
  4094. wx.PostEvent(self.mapWindow, event)
  4095. self.mapWindow.render['quick'] = True
  4096. if self.mapDisplay.IsAutoRendered():
  4097. self.mapWindow.Refresh(False)
  4098. def OnVolumeAxis(self, event):
  4099. """Volume position, axis changed"""
  4100. data = self.GetLayerData('volume')
  4101. id = data['volume']['object']['id']
  4102. axis = self.FindWindowById(
  4103. self.win['volume']['position']['axis']).GetSelection()
  4104. slider = self.FindWindowById(self.win['volume']['position']['slider'])
  4105. text = self.FindWindowById(self.win['volume']['position']['text'])
  4106. xydim = self._display.GetLongDim()
  4107. zdim = self._display.GetZRange()
  4108. zdim = zdim[1] - zdim[0]
  4109. x, y, z = self._display.GetVolumePosition(id)
  4110. if axis == 0: # x
  4111. slider.SetRange(-3 * xydim, 3 * xydim)
  4112. slider.SetValue(x)
  4113. text.SetValue(x)
  4114. elif axis == 1: # y
  4115. slider.SetRange(-3 * xydim, 3 * xydim)
  4116. slider.SetValue(y)
  4117. text.SetValue(y)
  4118. else: # z
  4119. slider.SetRange(-3 * zdim, 3 * zdim)
  4120. slider.SetValue(z)
  4121. text.SetValue(z)
  4122. def OnVolumePositionText(self, event):
  4123. """Volume position changed by textctrl"""
  4124. self.OnVolumePosition(event)
  4125. self.OnVolumePositionChanged(None)
  4126. def OnResetVolumePosition(self, event):
  4127. """Reset position of volume"""
  4128. for win in six.itervalues(self.win['volume']['position']):
  4129. if win == self.win['volume']['position']['axis']:
  4130. self.FindWindowById(win).SetSelection(2) # Z
  4131. elif win == self.win['volume']['position']['reset']:
  4132. continue
  4133. else:
  4134. self.FindWindowById(win).SetValue(0)
  4135. data = self.GetLayerData('volume')
  4136. data['volume']['position']['x'] = 0
  4137. data['volume']['position']['y'] = 0
  4138. data['volume']['position']['z'] = 0
  4139. data['volume']['position']['update'] = None
  4140. # update properties
  4141. event = wxUpdateProperties(data=data)
  4142. wx.PostEvent(self.mapWindow, event)
  4143. if self.mapDisplay.IsAutoRendered():
  4144. self.mapWindow.Refresh(False)
  4145. def OnVolumeSliceAxes(self, event):
  4146. """Slice axis changed"""
  4147. self.UpdateSliceLabels()
  4148. data = self.GetLayerData('volume')
  4149. list = self.FindWindowById(self.win['volume']['slices'])
  4150. sel = list.GetSelection()
  4151. if sel < 0:
  4152. return
  4153. axis = self.FindWindowById(
  4154. self.win['volume']['slice']['axes']).GetSelection()
  4155. data['volume']['slice'][sel]['position']['axis'] = axis
  4156. data['volume']['slice'][sel]['position']['update'] = None
  4157. axis = ("X", "Y", "Z")[axis]
  4158. list.SetString(sel, "%s %s" % (_("Slice parallel to"), axis))
  4159. list.Check(sel)
  4160. # update properties
  4161. event = wxUpdateProperties(data=data)
  4162. wx.PostEvent(self.mapWindow, event)
  4163. if self.mapDisplay.IsAutoRendered():
  4164. self.mapWindow.Refresh(False)
  4165. def OnSliceTransparency(self, event):
  4166. """Slice transparency changed"""
  4167. data = self.GetLayerData('volume')
  4168. list = self.FindWindowById(self.win['volume']['slices'])
  4169. sel = list.GetSelection()
  4170. if sel < 0:
  4171. return
  4172. val = self.FindWindowById(
  4173. self.win['volume']['slice']['transp']).GetValue()
  4174. data['volume']['slice'][sel]['transp'][
  4175. 'value'] = self._getPercent(val, toPercent=False)
  4176. data['volume']['slice'][sel]['transp']['update'] = None
  4177. # update properties
  4178. event = wxUpdateProperties(data=data)
  4179. wx.PostEvent(self.mapWindow, event)
  4180. if self.mapDisplay.IsAutoRendered():
  4181. self.mapWindow.Refresh(False)
  4182. def OnSliceReset(self, event):
  4183. """Slice position reset"""
  4184. data = self.GetLayerData('volume')
  4185. list = self.FindWindowById(self.win['volume']['slices'])
  4186. sel = list.GetSelection()
  4187. if sel < 0:
  4188. return
  4189. for coord, val in zip(
  4190. ('x1', 'x2', 'y1', 'y2', 'z1', 'z2'),
  4191. (0, 1, 0, 1, 0, 1, 0)):
  4192. data['volume']['slice'][sel]['position'][coord] = val
  4193. data['volume']['slice'][sel]['position']['update'] = None
  4194. self.UpdateVolumeSlicePage(data['volume']['slice'][sel])
  4195. # update properties
  4196. event = wxUpdateProperties(data=data)
  4197. wx.PostEvent(self.mapWindow, event)
  4198. if self.mapDisplay.IsAutoRendered():
  4199. self.mapWindow.Refresh(False)
  4200. def OnSlicePositionChange(self, event):
  4201. """Slice position is changing"""
  4202. data = self.GetLayerData('volume')
  4203. list = self.FindWindowById(self.win['volume']['slices'])
  4204. sel = list.GetSelection()
  4205. if sel < 0:
  4206. return
  4207. win = self.win['volume']['slice']
  4208. winId = event.GetId()
  4209. value = event.GetInt() / 100.
  4210. for coord in ('x1', 'x2', 'y1', 'y2', 'z1', 'z2'):
  4211. if win['slider_' + coord] == winId:
  4212. data['volume']['slice'][sel]['position'][coord] = value
  4213. data['volume']['slice'][sel]['position']['update'] = None
  4214. break
  4215. self.mapWindow.render['quick'] = True
  4216. # update properties
  4217. event = wxUpdateProperties(data=data)
  4218. wx.PostEvent(self.mapWindow, event)
  4219. if self.mapDisplay.IsAutoRendered():
  4220. self.mapWindow.Refresh(False)
  4221. def OnSlicePositionChanged(self, event):
  4222. """Slice position is changed"""
  4223. self.mapWindow.render['quick'] = False
  4224. if self.mapDisplay.IsAutoRendered():
  4225. self.mapWindow.Refresh(False)
  4226. def OnCPlaneSelection(self, event):
  4227. """Cutting plane selected"""
  4228. plane = self.FindWindowById(
  4229. self.win['cplane']['planes']).GetStringSelection()
  4230. try:
  4231. planeIndex = int(plane.split()[-1]) - 1
  4232. self.EnablePage("cplane", enabled=True)
  4233. except:
  4234. planeIndex = -1
  4235. self.EnablePage("cplane", enabled=False)
  4236. self.mapWindow.SelectCPlane(planeIndex)
  4237. if planeIndex >= 0:
  4238. self.mapWindow.UpdateCPlane(
  4239. planeIndex, changes=[
  4240. 'rotation', 'position', 'shading'])
  4241. if self.mapDisplay.IsAutoRendered():
  4242. self.mapWindow.Refresh(False)
  4243. self.UpdateCPlanePage(planeIndex)
  4244. def OnCPlaneChanging(self, event):
  4245. """Cutting plane is changing"""
  4246. plane = self.FindWindowById(
  4247. self.win['cplane']['planes']).GetStringSelection()
  4248. try:
  4249. planeIndex = int(plane.split()[-1]) - 1
  4250. except: # TODO disabled page
  4251. planeIndex = -1
  4252. if event.GetId() in (list(self.win['cplane']['rotation']['rot'].values()) +
  4253. list(self.win['cplane']['rotation']['tilt'].values())):
  4254. action = 'rotation'
  4255. else:
  4256. action = 'position'
  4257. data = self.mapWindow.cplanes[planeIndex][action]
  4258. self.OnScroll(event, self.win['cplane'][action], data)
  4259. self.mapWindow.render['quick'] = True
  4260. event = wxUpdateCPlane(update=(action,), current=planeIndex)
  4261. wx.PostEvent(self.mapWindow, event)
  4262. if self.mapDisplay.IsAutoRendered():
  4263. self.mapWindow.Refresh(False)
  4264. def OnCPlaneChangeDone(self, event):
  4265. """Cutting plane change done"""
  4266. self.mapWindow.render['quick'] = False
  4267. if self.mapDisplay.IsAutoRendered():
  4268. self.mapWindow.Refresh(False)
  4269. def OnCPlaneChangeText(self, event):
  4270. """Cutting plane changed by textctrl"""
  4271. for axis in ('x', 'y', 'z'):
  4272. if event.GetId() == self.win['cplane']['position'][axis]['text']:
  4273. value = self.FindWindowById(event.GetId()).GetValue()
  4274. slider = self.FindWindowById(
  4275. self.win['cplane']['position'][axis]['slider'])
  4276. self.AdjustSliderRange(slider=slider, value=value)
  4277. self.OnCPlaneChanging(event=event)
  4278. self.OnCPlaneChangeDone(None)
  4279. def OnCPlaneShading(self, event):
  4280. """Cutting plane shading changed"""
  4281. shading = self.FindWindowById(
  4282. self.win['cplane']['shading']).GetSelection()
  4283. plane = self.FindWindowById(
  4284. self.win['cplane']['planes']).GetStringSelection()
  4285. try:
  4286. planeIndex = int(plane.split()[-1]) - 1
  4287. except: # TODO disabled page
  4288. planeIndex = -1
  4289. self.mapWindow.cplanes[planeIndex]['shading'] = shading
  4290. event = wxUpdateCPlane(update=('shading',), current=planeIndex)
  4291. wx.PostEvent(self.mapWindow, event)
  4292. self.OnCPlaneChangeDone(None)
  4293. def OnCPlaneReset(self, event):
  4294. """Reset current cutting plane"""
  4295. plane = self.FindWindowById(
  4296. self.win['cplane']['planes']).GetStringSelection()
  4297. try:
  4298. planeIndex = int(plane.split()[-1]) - 1
  4299. except: # TODO disabled page
  4300. planeIndex = -1
  4301. self.mapWindow.cplanes[planeIndex] = copy.deepcopy(
  4302. UserSettings.Get(group='nviz', key='cplane'))
  4303. self.mapWindow.cplanes[planeIndex]['on'] = True
  4304. event = wxUpdateCPlane(
  4305. update=(
  4306. 'position',
  4307. 'rotation',
  4308. 'shading'),
  4309. current=planeIndex)
  4310. wx.PostEvent(self.mapWindow, event)
  4311. self.OnCPlaneChangeDone(None)
  4312. self.UpdateCPlanePage(planeIndex)
  4313. def OnDecorationPlacement(self, event):
  4314. """Place an arrow/scalebar by clicking on display"""
  4315. if event.GetId() == self.win['decoration']['arrow']['place']:
  4316. type = 'arrow'
  4317. elif event.GetId() == self.win['decoration']['scalebar']['place']:
  4318. type = 'scalebar'
  4319. else:
  4320. return
  4321. if event.GetInt():
  4322. self.mapDisplay.Raise()
  4323. self.mapWindow.mouse['use'] = type
  4324. self.mapWindow.SetNamedCursor('cross')
  4325. else:
  4326. self.mapWindow.mouse['use'] = 'default'
  4327. self.mapWindow.SetNamedCursor('default')
  4328. def OnArrowDelete(self, event):
  4329. """Delete arrow"""
  4330. self._display.DeleteArrow()
  4331. self.mapWindow.decoration['arrow']['show'] = False
  4332. self.FindWindowById(self.win['decoration'][
  4333. 'arrow']['delete']).Disable()
  4334. self.mapWindow.Refresh(False)
  4335. def OnScalebarDelete(self, event):
  4336. """Delete scalebar"""
  4337. choice = self.FindWindowById(
  4338. self.win['decoration']['scalebar']['choice'])
  4339. choiceIndex = choice.GetSelection()
  4340. index = choice.GetClientData(choiceIndex)
  4341. if index == wx.NOT_FOUND:
  4342. return
  4343. self._display.DeleteScalebar(id=index)
  4344. self.FindWindowById(self.win['decoration']['scalebar'][
  4345. 'choice']).Delete(choiceIndex)
  4346. if not choice.IsEmpty():
  4347. choice.SetSelection(choice.GetCount() - 1)
  4348. self.DisableScalebarControls()
  4349. self.mapWindow.Refresh(False)
  4350. def AddScalebar(self, scalebarNum):
  4351. choice = self.FindWindowById(
  4352. self.win['decoration']['scalebar']['choice'])
  4353. choice.Append(_("Scalebar %d") % (scalebarNum + 1), scalebarNum)
  4354. choice.SetSelection(choice.GetCount() - 1)
  4355. self.DisableScalebarControls()
  4356. def AddArrow(self):
  4357. self.FindWindowById(self.win['decoration']['arrow']['delete']).Enable()
  4358. def DisableScalebarControls(self):
  4359. choice = self.FindWindowById(
  4360. self.win['decoration']['scalebar']['choice'])
  4361. self.FindWindowById(
  4362. self.win['decoration']['scalebar']['delete']).Enable(
  4363. not choice.IsEmpty())
  4364. self.FindWindowById(
  4365. self.win['decoration']['scalebar']['choice']).Enable(
  4366. not choice.IsEmpty())
  4367. def OnDecorationProp(self, event):
  4368. """Set arrow/scalebar properties"""
  4369. if event.GetId() in self.win['decoration']['arrow'].values():
  4370. type = 'arrow'
  4371. elif event.GetId() in self.win['decoration']['scalebar'].values():
  4372. type = 'scalebar'
  4373. else:
  4374. return
  4375. color = self.FindWindowById(
  4376. self.win['decoration'][type]['color']).GetValue()
  4377. size = self.FindWindowById(
  4378. self.win['decoration'][type]['size']).GetValue()
  4379. if type == 'arrow':
  4380. self.mapWindow.decoration[type][
  4381. 'color'] = self._getColorString(color)
  4382. self.mapWindow.decoration[type]['size'] = size
  4383. elif type == 'scalebar'and self.mapWindow.decoration['scalebar']:
  4384. for scalebar in self.mapWindow.decoration[type]:
  4385. scalebar['color'] = self._getColorString(color)
  4386. scalebar['size'] = size
  4387. if type == 'arrow' and self.mapWindow.decoration['arrow']['show']:
  4388. self._display.SetArrow(
  4389. self.mapWindow.decoration['arrow']['position']['x'],
  4390. self.mapWindow.decoration['arrow']['position']['y'],
  4391. self.mapWindow.decoration['arrow']['size'],
  4392. self.mapWindow.decoration['arrow']['color'])
  4393. self._display.DrawArrow()
  4394. elif type == 'scalebar' and self.mapWindow.decoration['scalebar']:
  4395. ids = []
  4396. choice = self.FindWindowById(
  4397. self.win['decoration']['scalebar']['choice'])
  4398. for index in range(choice.GetCount()):
  4399. ids.append(choice.GetClientData(index))
  4400. for scalebar in self.mapWindow.decoration[type]:
  4401. if scalebar['id'] in ids:
  4402. self._display.SetScalebar(scalebar['id'],
  4403. scalebar['position']['x'],
  4404. scalebar['position']['y'],
  4405. scalebar['size'],
  4406. scalebar['color'])
  4407. self._display.DrawScalebar()
  4408. self.mapWindow.Refresh(False)
  4409. def UpdatePage(self, pageId):
  4410. """Update dialog (selected page)"""
  4411. self.pageChanging = True
  4412. Debug.msg(1, "NvizToolWindow.UpdatePage(): %s", pageId)
  4413. if pageId == 'view':
  4414. self.SetPage('view')
  4415. hmin = self.mapWindow.iview['height']['min']
  4416. hmax = self.mapWindow.iview['height']['max']
  4417. hval = self.mapWindow.iview['height']['value']
  4418. zmin = self.mapWindow.view['z-exag']['min']
  4419. zmax = self.mapWindow.view['z-exag']['max']
  4420. zval = self.mapWindow.view['z-exag']['value']
  4421. for control in ('slider', 'text'):
  4422. try:
  4423. self.FindWindowById(
  4424. self.win['view']['height'][control]).SetRange(
  4425. hmin, hmax)
  4426. except OverflowError:
  4427. hmin = self.mapWindow.iview['height']['min'] = 0
  4428. hmax = self.mapWindow.iview['height']['max'] = 10000
  4429. hval = self.mapWindow.iview['height']['value'] = 5000
  4430. self.FindWindowById(
  4431. self.win['view']['height'][control]).SetRange(
  4432. hmin, hmax)
  4433. self.FindWindowById(
  4434. self.win['view']['z-exag'][control]).SetRange(zmin, zmax)
  4435. self.FindWindowById(
  4436. self.win['view']['height'][control]).SetValue(hval)
  4437. self.FindWindowById(
  4438. self.win['view']['z-exag'][control]).SetValue(zval)
  4439. self.FindWindowById(
  4440. self.win['view']['background']['color']).SetColour(
  4441. self.mapWindow.view['background']['color'])
  4442. tval = self.mapWindow.view['twist']['value']
  4443. pval = self.mapWindow.view['persp']['value']
  4444. for control in ('slider', 'text'):
  4445. self.FindWindowById(
  4446. self.win['view']['twist'][control]).SetValue(tval)
  4447. self.FindWindowById(
  4448. self.win['view']['persp'][control]).SetValue(pval)
  4449. elif pageId in ('surface', 'vector', 'volume'):
  4450. name = self.FindWindowById(self.win[pageId]['map']).GetValue()
  4451. data = self.GetLayerData(pageId)
  4452. if data:
  4453. if pageId == 'surface':
  4454. layer = self._getMapLayerByName(name, mapType='raster')
  4455. if layer:
  4456. self.UpdateSurfacePage(layer, data['surface'])
  4457. elif pageId == 'vector':
  4458. layer = self._getMapLayerByName(name, mapType='vector')
  4459. if layer:
  4460. self.UpdateVectorPage(layer, data['vector'])
  4461. elif pageId == 'volume':
  4462. layer = self._getMapLayerByName(name, mapType='raster_3d')
  4463. if layer:
  4464. self.UpdateVolumePage(layer, data['volume'])
  4465. elif pageId == 'light':
  4466. zval = self.mapWindow.light['position']['z']
  4467. bval = self.mapWindow.light['bright']
  4468. aval = self.mapWindow.light['ambient']
  4469. for control in ('slider', 'text'):
  4470. self.FindWindowById(
  4471. self.win['light']['z'][control]).SetValue(zval)
  4472. self.FindWindowById(
  4473. self.win['light']['bright'][control]).SetValue(bval)
  4474. self.FindWindowById(
  4475. self.win['light']['ambient'][control]).SetValue(aval)
  4476. self.FindWindowById(
  4477. self.win['light']['color']).SetColour(
  4478. self.mapWindow.light['color'])
  4479. self.FindWindowById(self.win['light']['position']).PostDraw()
  4480. elif pageId == 'fringe':
  4481. win = self.FindWindowById(self.win['fringe']['map'])
  4482. win.SetValue(
  4483. self.FindWindowById(
  4484. self.win['surface']['map']).GetValue())
  4485. elif pageId == 'decoration':
  4486. win = self.FindWindowById(self.win['decoration']['arrow']['size'])
  4487. win.SetValue(self.mapWindow.decoration['arrow']['size'])
  4488. win = self.FindWindowById(
  4489. self.win['decoration']['scalebar']['size'])
  4490. win.SetValue(self.mapWindow._getDecorationSize())
  4491. elif pageId == 'constant':
  4492. if self.mapWindow.constants:
  4493. surface = self.FindWindowById(self.win['constant']['surface'])
  4494. for item in self.mapWindow.constants:
  4495. surface.Append(_("constant#") +
  4496. str(item['constant']['object']['name']))
  4497. surface.SetSelection(0)
  4498. self.OnConstantSelection(None)
  4499. self.EnablePage('constant', True)
  4500. elif pageId == 'cplane':
  4501. count = self._display.GetCPlanesCount()
  4502. choices = [_("None"), ]
  4503. for plane in range(count):
  4504. choices.append("%s %i" % (_("Plane"), plane + 1))
  4505. self.FindWindowById(self.win['cplane']['planes']).SetItems(choices)
  4506. current = 0
  4507. for i, cplane in enumerate(self.mapWindow.cplanes):
  4508. if cplane['on']:
  4509. current = i + 1
  4510. self.FindWindowById(
  4511. self.win['cplane']['planes']).SetSelection(current)
  4512. xyRange, zRange = self._display.GetXYRange(), self._display.GetZRange()
  4513. if xyRange > 0: # GTK warning
  4514. self.FindWindowById(self.win['cplane']['position']['x'][
  4515. 'slider']).SetRange(-xyRange / 2., xyRange / 2.)
  4516. self.FindWindowById(self.win['cplane']['position']['y'][
  4517. 'slider']).SetRange(-xyRange / 2., xyRange / 2.)
  4518. if zRange[1] - zRange[0] > 1:
  4519. self.FindWindowById(
  4520. self.win['cplane']['position']['z']['slider']).SetRange(
  4521. zRange[0], zRange[1])
  4522. self.FindWindowById(
  4523. self.win['cplane']['position']['z']['slider']).SetValue(
  4524. zRange[0])
  4525. self.FindWindowById(
  4526. self.win['cplane']['position']['z']['text']).SetValue(
  4527. zRange[0])
  4528. self.OnCPlaneSelection(None)
  4529. elif pageId == 'animation':
  4530. self.UpdateAnimationPage()
  4531. self.Update()
  4532. self.pageChanging = False
  4533. def UpdateAnimationPage(self):
  4534. """Update animation page"""
  4535. # wrap help text according to tool window
  4536. help = self.FindWindowById(self.win['anim']['help'])
  4537. width = help.GetGrandParent().GetSize()[0]
  4538. help.Wrap(width - 15)
  4539. anim = self.mapWindow.GetAnimation()
  4540. if anim.Exists():
  4541. self.FindWindowById(self.win['anim']['play']).Enable()
  4542. else:
  4543. self.UpdateFrameIndex(index=0)
  4544. self.UpdateFrameCount()
  4545. self.FindWindowById(self.win['anim']['play']).Disable()
  4546. self.FindWindowById(self.win['anim']['record']).Enable()
  4547. self.FindWindowById(self.win['anim']['pause']).Disable()
  4548. self.FindWindowById(self.win['anim']['stop']).Disable()
  4549. self.FindWindowById(self.win['anim']['frameIndex']['slider']).Disable()
  4550. self.FindWindowById(self.win['anim']['frameIndex']['text']).Disable()
  4551. def UpdateCPlanePage(self, index):
  4552. """Update widgets according to selected clip plane"""
  4553. if index == -1:
  4554. return
  4555. data = self.mapWindow.cplanes[index]
  4556. for widget in ('text', 'slider'):
  4557. for axes in ('x', 'y', 'z'):
  4558. self.FindWindowById(
  4559. self.win['cplane']['position'][axes][widget]).SetValue(
  4560. data['position'][axes])
  4561. for each in ('tilt', 'rot'):
  4562. self.FindWindowById(
  4563. self.win['cplane']['rotation'][each][widget]).SetValue(
  4564. data['rotation'][each])
  4565. self.FindWindowById(
  4566. self.win['cplane']['shading']).SetSelection(
  4567. data['shading'])
  4568. def UpdateSurfacePage(self, layer, data, updateName=True):
  4569. """Update surface page"""
  4570. desc = grass.raster_info(layer.name)['title']
  4571. if updateName:
  4572. self.FindWindowById(
  4573. self.win['surface']['map']).SetValue(
  4574. layer.name)
  4575. self.FindWindowById(self.win['surface']['desc']).SetLabel(desc)
  4576. # attributes
  4577. if layer and layer.type == 'raster':
  4578. self.vetoGSelectEvt = True
  4579. self.FindWindowById(
  4580. self.win['surface']['color']['map']).SetValue(
  4581. layer.name)
  4582. else:
  4583. self.FindWindowById(
  4584. self.win['surface']['color']['map']).SetValue('')
  4585. self.SetMapObjUseMap(nvizType='surface',
  4586. attrb='color', map=True) # -> map
  4587. if 'color' in data['attribute']:
  4588. value = data['attribute']['color']['value']
  4589. if data['attribute']['color']['map']:
  4590. self.FindWindowById(
  4591. self.win['surface']['color']['map']).SetValue(value)
  4592. else: # constant
  4593. color = list(map(int, value.split(':')))
  4594. self.FindWindowById(
  4595. self.win['surface']['color']['const']).SetColour(color)
  4596. self.SetMapObjUseMap(
  4597. nvizType='surface', attrb='color',
  4598. map=data['attribute']['color']['map'])
  4599. self.SetMapObjUseMap(
  4600. nvizType='surface', attrb='shine',
  4601. map=data['attribute']['shine']['map'])
  4602. value = data['attribute']['shine']['value']
  4603. if data['attribute']['shine']['map']:
  4604. self.FindWindowById(
  4605. self.win['surface']['shine']['map']).SetValue(value)
  4606. else:
  4607. self.FindWindowById(
  4608. self.win['surface']['shine']['const']).SetValue(
  4609. self._getPercent(value))
  4610. if 'transp' in data['attribute']:
  4611. value = data['attribute']['transp']['value']
  4612. if data['attribute']['transp']['map']:
  4613. self.FindWindowById(
  4614. self.win['surface']['color']['map']).SetValue(value)
  4615. else:
  4616. self.FindWindowById(
  4617. self.win['surface']['transp']['const']).SetValue(
  4618. self._getPercent(value))
  4619. self.SetMapObjUseMap(
  4620. nvizType='surface',
  4621. attrb='transp',
  4622. map=data['attribute']['transp']['map'])
  4623. else:
  4624. self.SetMapObjUseMap(nvizType='surface', attrb='transp', map=None)
  4625. #
  4626. # draw
  4627. #
  4628. for control, drawData in six.iteritems(data['draw']):
  4629. if control == 'all': # skip 'all' property
  4630. continue
  4631. if control == 'resolution':
  4632. self.FindWindowById(self.win['surface']['draw'][
  4633. 'res-coarse']).SetValue(drawData['coarse'])
  4634. self.FindWindowById(self.win['surface']['draw'][
  4635. 'res-fine']).SetValue(drawData['fine'])
  4636. continue
  4637. if control == 'mode':
  4638. if drawData['desc']['mode'] == 'coarse':
  4639. self.FindWindowById(
  4640. self.win['surface']['draw']['mode']).SetSelection(0)
  4641. elif drawData['desc']['mode'] == 'fine':
  4642. self.FindWindowById(
  4643. self.win['surface']['draw']['mode']).SetSelection(1)
  4644. else: # both
  4645. self.FindWindowById(
  4646. self.win['surface']['draw']['mode']).SetSelection(2)
  4647. if drawData['desc']['style'] == 'wire':
  4648. self.FindWindowById(
  4649. self.win['surface']['draw']['style']).SetSelection(0)
  4650. else: # surface
  4651. self.FindWindowById(
  4652. self.win['surface']['draw']['style']).SetSelection(1)
  4653. if drawData['desc']['shading'] == 'flat':
  4654. self.FindWindowById(
  4655. self.win['surface']['draw']['shading']).SetSelection(0)
  4656. else: # gouraud
  4657. self.FindWindowById(
  4658. self.win['surface']['draw']['shading']).SetSelection(1)
  4659. continue
  4660. value = drawData['value']
  4661. win = self.FindWindowById(self.win['surface']['draw'][control])
  4662. name = win.GetName()
  4663. if name == "selection":
  4664. win.SetSelection(value)
  4665. elif name == "colour":
  4666. color = list(map(int, value.split(':')))
  4667. win.SetColour(color)
  4668. else:
  4669. win.SetValue(value)
  4670. #
  4671. # position
  4672. #
  4673. self.OnSurfaceAxis(None)
  4674. # enable/disable res widget + set draw mode
  4675. self.OnSurfaceMode(event=None)
  4676. def UpdateVectorPage(self, layer, data, updateName=True):
  4677. """Update vector page"""
  4678. vInfo = grass.vector_info_topo(layer.GetName())
  4679. if not vInfo:
  4680. return
  4681. if vInfo['map3d']:
  4682. desc = _("Vector map is 3D")
  4683. enable = False
  4684. else:
  4685. desc = _("Vector map is 2D")
  4686. enable = True
  4687. desc += " - " + _("%(features)d features (%(points)d points)") % \
  4688. {'features': vInfo['primitives'], 'points': vInfo['points']}
  4689. if updateName:
  4690. self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
  4691. self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
  4692. self.FindWindowById(self.win['vector']['lines']['3d']).Enable(enable)
  4693. for v in ('lines', 'points'):
  4694. self.FindWindowById(
  4695. self.win['vector'][v]['surface']).Enable(enable)
  4696. self.FindWindowById(self.win['vector'][v]['height'][
  4697. 'slider']).Enable(enable)
  4698. self.FindWindowById(
  4699. self.win['vector'][v]['height']['text']).Enable(enable)
  4700. if data[v]['thematic']['usecolor']:
  4701. check = self.FindWindowById(
  4702. self.win['vector'][v]['thematic']['checkcolor'])
  4703. check.SetValue(data[v]['thematic']['usecolor'])
  4704. if 'usesize' in data[v]['thematic'] and data[
  4705. v]['thematic']['usesize']:
  4706. check = self.FindWindowById(
  4707. self.win['vector'][v]['thematic']['checksize'])
  4708. check.SetValue(data[v]['thematic']['usesize'])
  4709. elif 'usewidth' in data[v]['thematic'] and data[v]['thematic']['usewidth']:
  4710. check = self.FindWindowById(
  4711. self.win['vector'][v]['thematic']['checkwidth'])
  4712. check.SetValue(data[v]['thematic']['usewidth'])
  4713. self.OnCheckThematic(None)
  4714. #
  4715. # lines
  4716. #
  4717. showLines = self.FindWindowById(self.win['vector']['lines']['show'])
  4718. if 'object' in data['lines']:
  4719. showLines.SetValue(True)
  4720. else:
  4721. showLines.SetValue(False)
  4722. if (vInfo['lines'] + vInfo['boundaries']) > 0:
  4723. showLines.Enable(True)
  4724. else:
  4725. showLines.Enable(False)
  4726. self.UpdateVectorShow('lines', showLines.IsChecked())
  4727. width = self.FindWindowById(self.win['vector']['lines']['width'])
  4728. width.SetValue(data['lines']['width']['value'])
  4729. color = self.FindWindowById(self.win['vector']['lines']['color'])
  4730. color.SetValue(list(map(int, data['lines']['color']['value'].split(':'))))
  4731. for vtype in ('lines', 'points'):
  4732. if vtype == 'lines':
  4733. display = self.FindWindowById(
  4734. self.win['vector']['lines']['3d'])
  4735. if vInfo['map3d']:
  4736. items = [_("on surface(s):"), _("as 3D")]
  4737. else:
  4738. items = [_("on surface")]
  4739. display.SetItems(items)
  4740. if data[vtype]['mode']['type'] == '3d':
  4741. display.SetSelection(1)
  4742. else:
  4743. display.SetSelection(0)
  4744. if data[vtype]['mode']['type'] == 'surface':
  4745. rasters = self.mapWindow.GetLayerNames('raster')
  4746. constants = self.mapWindow.GetLayerNames('constant')
  4747. surfaces = rasters + constants
  4748. surfaceWin = self.FindWindowById(
  4749. self.win['vector'][vtype]['surface'])
  4750. surfaceWin.SetItems(surfaces)
  4751. for idx, surface in enumerate(surfaces):
  4752. try: # TODO fix this mess
  4753. selected = data[vtype]['mode']['surface']['show'][idx]
  4754. except (TypeError, IndexError, KeyError):
  4755. selected = False
  4756. surfaceWin.Check(idx, selected)
  4757. for type in ('slider', 'text'):
  4758. win = self.FindWindowById(
  4759. self.win['vector']['lines']['height'][type])
  4760. win.SetValue(data['lines']['height']['value'])
  4761. #
  4762. # points
  4763. #
  4764. showPoints = self.FindWindowById(self.win['vector']['points']['show'])
  4765. if 'object' in data['points']:
  4766. showPoints.SetValue(True)
  4767. else:
  4768. showPoints.SetValue(False)
  4769. if (vInfo['points'] + vInfo['centroids']) > 0:
  4770. showPoints.Enable(True)
  4771. else:
  4772. showPoints.Enable(False)
  4773. self.UpdateVectorShow('points', showPoints.IsChecked())
  4774. # size, width, marker, color
  4775. for prop in ('size', 'marker', 'color'):
  4776. win = self.FindWindowById(self.win['vector']['points'][prop])
  4777. name = win.GetName()
  4778. if name == 'selection':
  4779. win.SetSelection(data['points'][prop]['value'])
  4780. elif name == 'color':
  4781. color = list(map(int, data['points'][prop]['value'].split(':')))
  4782. win.SetValue(color)
  4783. else:
  4784. win.SetValue(data['points'][prop]['value'])
  4785. win = self.FindWindowById(self.win['vector']['points']['3d'])
  4786. if vInfo['map3d']:
  4787. items = [_("on surface(s):"), _("as 3D")]
  4788. else:
  4789. items = [_("on surface")]
  4790. win.SetItems(items)
  4791. if data['points']['mode'].get('3d', False):
  4792. win.SetSelection(1)
  4793. else:
  4794. win.SetSelection(0)
  4795. # self.OnCheckThematic(None)
  4796. # height
  4797. for type in ('slider', 'text'):
  4798. win = self.FindWindowById(
  4799. self.win['vector']['points']['height'][type])
  4800. win.SetValue(data['points']['height']['value'])
  4801. def UpdateVolumePage(self, layer, data, updateName=True):
  4802. """Update volume page"""
  4803. if updateName:
  4804. self.FindWindowById(self.win['volume']['map']).SetValue(layer.name)
  4805. # draw
  4806. for control, idata in six.iteritems(data['draw']):
  4807. if control == 'all': # skip 'all' property
  4808. continue
  4809. win = self.FindWindowById(self.win['volume']['draw'][control])
  4810. if control == 'mode':
  4811. value = data['draw']['mode']['value']
  4812. if control == 'shading':
  4813. if data['draw']['shading'][data['draw']
  4814. ['mode']['desc']]['desc'] == 'flat':
  4815. value = 0
  4816. else:
  4817. value = 1
  4818. if control == 'resolution':
  4819. value = idata[data['draw']['mode']['desc']]['value']
  4820. if control == 'box':
  4821. value = idata['enabled']
  4822. if win.GetName() == "selection":
  4823. win.SetSelection(value)
  4824. else:
  4825. win.SetValue(value)
  4826. self.OnVolumeMode(None)
  4827. id = data['object']['id']
  4828. if data['draw']['mode']['desc'] == 'isosurface':
  4829. self._display.SetIsosurfaceMode(
  4830. id, data['draw']['shading']['isosurface']['value'])
  4831. self._display.SetIsosurfaceRes(
  4832. id, data['draw']['resolution']['isosurface']['value'])
  4833. else:
  4834. self._display.SetSliceMode(
  4835. id, data['draw']['shading']['slice']['value'])
  4836. self._display.SetSliceRes(
  4837. id, data['draw']['resolution']['slice']['value'])
  4838. box = self.FindWindowById(self.win['volume']['isosurfs'])
  4839. if data['draw']['mode']['desc'] == 'isosurface':
  4840. isosurfaces = []
  4841. for iso in data['isosurface']:
  4842. level = iso['topo']['value']
  4843. isosurfaces.append("%s %s" % (_("Level"), level))
  4844. box.Set(isosurfaces)
  4845. for i in range(len(isosurfaces)):
  4846. box.Check(i)
  4847. if data['isosurface']:
  4848. box.SetSelection(0)
  4849. self.UpdateVolumeIsosurfPage(data['isosurface'][0])
  4850. else:
  4851. self.UpdateVolumeIsosurfPage(data['attribute'])
  4852. else:
  4853. slices = []
  4854. for slice in data['slice']:
  4855. axis = ("X", "Y", "Z")[slice['position']['axis']]
  4856. slices.append("%s %s" % (_("Slice parallel to"), axis))
  4857. box.Set(slices)
  4858. for i in range(len(slices)):
  4859. box.Check(i)
  4860. if data['slice']:
  4861. box.SetSelection(0)
  4862. self.UpdateVolumeSlicePage(data['slice'][0])
  4863. else:
  4864. self.UpdateVolumeSlicePage(None)
  4865. #
  4866. # position
  4867. #
  4868. if 'z' in data['position']:
  4869. zval = data['position']['z']
  4870. self.FindWindowById(
  4871. self.win['volume']['position']['axis']).SetSelection(2)
  4872. for control in ('slider', 'text'):
  4873. self.FindWindowById(
  4874. self.win['volume']['position'][control]).SetValue(zval)
  4875. # set topo range
  4876. mapRange = self._get3dRange(name=layer.name)
  4877. desc = self.FindWindowById(self.win['volume']['desc'])
  4878. desc.SetLabel(
  4879. "%s %.2f - %.2f" %
  4880. (_("range:"), mapRange[0], mapRange[1]))
  4881. def UpdateVolumeIsosurfPage(self, data):
  4882. """Update dialog -- isosurface attributes"""
  4883. #
  4884. # isosurface attributes
  4885. #
  4886. for attrb in ('topo', 'color', 'mask',
  4887. 'transp', 'shine'):
  4888. # skip empty attributes
  4889. if attrb not in data:
  4890. self.SetMapObjUseMap(nvizType='volume', attrb=attrb, map=None)
  4891. continue
  4892. value = data[attrb]['value']
  4893. if attrb == 'color':
  4894. if data[attrb]['map']:
  4895. self.FindWindowById(
  4896. self.win['volume'][attrb]['map']).SetValue(value)
  4897. else: # constant
  4898. color = list(map(int, value.split(':')))
  4899. self.FindWindowById(
  4900. self.win['volume'][attrb]['const']).SetColour(color)
  4901. else:
  4902. if data[attrb]['map']:
  4903. self.vetoGSelectEvt = True
  4904. win = self.FindWindowById(self.win['volume'][attrb]['map'])
  4905. win.SetValue(value)
  4906. else:
  4907. if value:
  4908. win = self.FindWindowById(
  4909. self.win['volume'][attrb]['const'])
  4910. if attrb == 'topo':
  4911. win.SetValue(float(value))
  4912. else:
  4913. win.SetValue(self._getPercent(value))
  4914. self.SetMapObjUseMap(nvizType='volume',
  4915. attrb=attrb, map=data[attrb]['map'])
  4916. # set inout
  4917. if 'inout' in data:
  4918. self.FindWindowById(
  4919. self.win['volume']['inout']).SetValue(
  4920. data['inout']['value'])
  4921. def UpdateVolumeSlicePage(self, data):
  4922. """Update dialog -- slice attributes"""
  4923. if data:
  4924. for coord in ('x1', 'x2', 'y1', 'y2', 'z1', 'z2'):
  4925. win = self.FindWindowById(
  4926. self.win['volume']['slice'][
  4927. 'slider_' + coord])
  4928. win.Enable()
  4929. win.SetValue(data['position'][coord] * 100)
  4930. win = self.FindWindowById(self.win['volume']['slice']['axes'])
  4931. win.SetSelection(data['position']['axis'])
  4932. win.Enable()
  4933. win = self.FindWindowById(self.win['volume']['slice']['transp'])
  4934. win.SetValue(self._getPercent(data['transp']['value']))
  4935. win.Enable()
  4936. self.FindWindowById(self.win['volume']['slice']['reset']).Enable()
  4937. else:
  4938. for coord in ('x1', 'x2', 'y1', 'y2', 'z1', 'z2'):
  4939. self.FindWindowById(
  4940. self.win['volume']['slice'][
  4941. 'slider_' + coord]).Disable()
  4942. self.FindWindowById(self.win['volume']['slice']['axes']).Disable()
  4943. self.FindWindowById(
  4944. self.win['volume']['slice']['transp']).Disable()
  4945. self.FindWindowById(self.win['volume']['slice']['reset']).Disable()
  4946. self.UpdateSliceLabels()
  4947. def UpdateSliceLabels(self):
  4948. """Update text labels of slice controls according to axis"""
  4949. sel = self.FindWindowById(
  4950. self.win['volume']['slice']['axes']).GetSelection()
  4951. if sel == 0:
  4952. self.FindWindowByName('label_edge_0').SetLabel(_("North edge:"))
  4953. self.FindWindowByName('label_edge_1').SetLabel(_("South edge:"))
  4954. self.FindWindowByName('label_edge_2').SetLabel(_("West edge:"))
  4955. self.FindWindowByName('label_edge_3').SetLabel(_("East edge:"))
  4956. self.FindWindowByName('label_coord_0').SetLabel(_("Northing (Y):"))
  4957. self.FindWindowByName('label_coord_1').SetLabel(_("Height (Z):"))
  4958. self.FindWindowByName('label_coord_2').SetLabel(_("Easting (X):"))
  4959. elif sel == 1:
  4960. self.FindWindowByName('label_edge_0').SetLabel(_("West edge:"))
  4961. self.FindWindowByName('label_edge_1').SetLabel(_("East edge:"))
  4962. self.FindWindowByName('label_edge_2').SetLabel(_("North edge:"))
  4963. self.FindWindowByName('label_edge_3').SetLabel(_("South edge:"))
  4964. self.FindWindowByName('label_coord_0').SetLabel(_("Easting (X):"))
  4965. self.FindWindowByName('label_coord_1').SetLabel(_("Height (Z):"))
  4966. self.FindWindowByName('label_coord_2').SetLabel(_("Northing (Y):"))
  4967. else:
  4968. self.FindWindowByName('label_edge_0').SetLabel(_("West edge:"))
  4969. self.FindWindowByName('label_edge_1').SetLabel(_("East edge:"))
  4970. self.FindWindowByName('label_edge_2').SetLabel(_("Bottom edge:"))
  4971. self.FindWindowByName('label_edge_3').SetLabel(_("Top edge:"))
  4972. self.FindWindowByName('label_coord_0').SetLabel(_("Easting (X):"))
  4973. self.FindWindowByName('label_coord_1').SetLabel(_("Northing (Y):"))
  4974. self.FindWindowByName('label_coord_2').SetLabel(_("Height (Z):"))
  4975. def SetPage(self, name):
  4976. """Get named page"""
  4977. if name == 'view':
  4978. self.SetSelection(0)
  4979. elif name in ('surface', 'vector', 'volume'):
  4980. self.SetSelection(1)
  4981. else:
  4982. self.SetSelection(2)
  4983. win = self.FindWindowById(self.page[name]['notebook'])
  4984. try:
  4985. win.Expand(win.GetFoldPanel(self.page[name]['id']))
  4986. self.UpdateScrolling(
  4987. (win.GetFoldPanel(self.page[name]['id']).GetGrandParent(),))
  4988. except AttributeError:
  4989. win.SetSelection(self.page[name]['id'])
  4990. class PositionWindow(Window):
  4991. """Abstract position control window, see subclasses
  4992. ViewPostionWindow and LightPositionWindow"""
  4993. def __init__(self, parent, mapwindow, id=wx.ID_ANY,
  4994. **kwargs):
  4995. self.mapWindow = mapwindow
  4996. self.quick = True
  4997. Window.__init__(self, parent, id, **kwargs)
  4998. self.SetBackgroundColour("WHITE")
  4999. self.pdc = PseudoDC()
  5000. self.pdc.SetBrush(wx.Brush(colour='dark green', style=wx.SOLID))
  5001. self.pdc.SetPen(wx.Pen(colour='dark green', width=2, style=wx.SOLID))
  5002. self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
  5003. self.Bind(wx.EVT_PAINT, self.OnPaint)
  5004. # self.Bind(wx.EVT_MOTION, self.OnMouse)
  5005. self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
  5006. def Draw(self, pos, scale=False):
  5007. w, h = self.GetClientSize()
  5008. x, y = pos
  5009. if scale:
  5010. x = x * w
  5011. y = y * h
  5012. self.pdc.Clear()
  5013. self.pdc.BeginDrawing()
  5014. self.pdc.DrawLine(w / 2, h / 2, x, y)
  5015. self.pdc.DrawCircle(x, y, 5)
  5016. self.pdc.EndDrawing()
  5017. def OnPaint(self, event):
  5018. dc = wx.BufferedPaintDC(self)
  5019. dc.SetBackground(wx.Brush("White"))
  5020. dc.Clear()
  5021. # probably does nothing, removed from wxPython 2.9
  5022. # self.PrepareDC(dc)
  5023. self.pdc.DrawToDC(dc)
  5024. def UpdatePos(self, xcoord, ycoord):
  5025. """Update position coordinates (origin: UL)"""
  5026. if xcoord < 0.0:
  5027. xcoord = 0.0
  5028. elif xcoord > 1.0:
  5029. xcoord = 1.0
  5030. if ycoord < 0.0:
  5031. ycoord = 0.0
  5032. elif ycoord > 1.0:
  5033. ycoord = 1.0
  5034. x, y = self.TransformCoordinates(xcoord, ycoord)
  5035. self.data['position']['x'] = x
  5036. self.data['position']['y'] = y
  5037. return xcoord, ycoord
  5038. def OnMouse(self, event):
  5039. if event.LeftIsDown():
  5040. x, y = event.GetPosition()
  5041. self.Draw(pos=(x, y))
  5042. w, h = self.GetClientSize()
  5043. x = float(x) / w
  5044. y = float(y) / h
  5045. self.UpdatePos(x, y)
  5046. self.Refresh(False)
  5047. event.Skip()
  5048. def PostDraw(self):
  5049. x, y = self.UpdatePos(self.data['position']['x'],
  5050. self.data['position']['y'])
  5051. self.Draw(pos=(x, y), scale=True)
  5052. class ViewPositionWindow(PositionWindow):
  5053. """View position control widget"""
  5054. def __init__(self, parent, mapwindow, id=wx.ID_ANY,
  5055. **kwargs):
  5056. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  5057. self.SetToolTip(
  5058. _("Adjusts the distance and direction of the image viewpoint"))
  5059. self.data = self.mapWindow.view
  5060. self.PostDraw()
  5061. def UpdatePos(self, xcoord, ycoord):
  5062. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  5063. event = wxUpdateView(zExag=True)
  5064. wx.PostEvent(self.mapWindow, event)
  5065. return x, y
  5066. def TransformCoordinates(self, x, y, toLight=True):
  5067. return x, y
  5068. def OnMouse(self, event):
  5069. # use focus instead of viewdir
  5070. self.mapWindow.iview['dir']['use'] = False
  5071. PositionWindow.OnMouse(self, event)
  5072. if event.LeftIsDown():
  5073. self.mapWindow.render['quick'] = self.quick
  5074. self.mapWindow.Refresh(eraseBackground=False)
  5075. elif event.LeftUp():
  5076. self.mapWindow.render['quick'] = False
  5077. self.mapWindow.Refresh(eraseBackground=False)
  5078. event.Skip()
  5079. class LightPositionWindow(PositionWindow):
  5080. """Light position control widget"""
  5081. def __init__(self, parent, mapwindow, id=wx.ID_ANY,
  5082. **kwargs):
  5083. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  5084. self.SetToolTip(_("Adjusts the light direction. "
  5085. "Click and drag the puck to change the light direction."))
  5086. self.data = self.mapWindow.light
  5087. self.quick = False
  5088. self.PostDraw()
  5089. def UpdatePos(self, xcoord, ycoord):
  5090. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  5091. event = wxUpdateLight(refresh=False)
  5092. wx.PostEvent(self.mapWindow, event)
  5093. return x, y
  5094. def TransformCoordinates(self, x, y, toLight=True):
  5095. if toLight:
  5096. x = 2 * x - 1
  5097. y = -2 * y + 1
  5098. else:
  5099. x = (x + 1) / 2
  5100. y = (1 - y) / 2
  5101. return x, y
  5102. def PostDraw(self):
  5103. event = wxUpdateLight(refresh=True)
  5104. wx.PostEvent(self.mapWindow, event)
  5105. x, y = self.data['position']['x'], self.data['position']['y']
  5106. x, y = self.TransformCoordinates(x, y, toLight=False)
  5107. self.Draw(pos=(x, y), scale=True)
  5108. def OnMouse(self, event):
  5109. PositionWindow.OnMouse(self, event)
  5110. if event.LeftUp():
  5111. self.mapWindow.render['quick'] = False
  5112. self.mapWindow.Refresh(eraseBackground=False)