tools.py 228 KB

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