tools.py 228 KB

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