nviz_tools.py 229 KB

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