tools.py 229 KB

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