tools.py 226 KB

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