tools.py 229 KB

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