tools.py 223 KB

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