tools.py 231 KB

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