tools.py 229 KB

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