tools.py 229 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172
  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 nviz.animation import EVT_ANIM_FIN, EVT_ANIM_UPDATE_IDX
  46. from gui_core.widgets import ScrolledPanel, NumTextCtrl, FloatSlider, SymbolButton
  47. from gui_core.gselect import Select
  48. from core.debug import Debug
  49. try:
  50. from nviz.mapwindow import wxUpdateProperties, wxUpdateView,\
  51. wxUpdateLight, wxUpdateCPlane
  52. import wxnviz
  53. except ImportError:
  54. pass
  55. class NvizToolWindow(FN.FlatNotebook):
  56. """!Nviz (3D view) tools panel
  57. """
  58. def __init__(self, parent, display, id = wx.ID_ANY,
  59. style = globalvar.FNPageStyle|FN.FNB_NO_X_BUTTON,
  60. **kwargs):
  61. Debug.msg(5, "NvizToolWindow.__init__()")
  62. self.parent = parent # GMFrame
  63. self.mapDisplay = display
  64. self.mapWindow = display.GetWindow()
  65. self._display = self.mapWindow.GetDisplay()
  66. if globalvar.hasAgw:
  67. kwargs['agwStyle'] = style
  68. else:
  69. kwargs['style'] = style
  70. FN.FlatNotebook.__init__(self, parent, id, **kwargs)
  71. self.SetTabAreaColour(globalvar.FNPageColor)
  72. self.win = {} # window ids
  73. self.page = {} # page ids
  74. # view page
  75. self.AddPage(page = self._createViewPage(),
  76. text = " %s " % _("View"))
  77. # data page
  78. self.AddPage(page = self._createDataPage(),
  79. text = " %s " % _("Data"))
  80. # appearance page
  81. self.AddPage(page = self._createAppearancePage(),
  82. text = " %s " % _("Appearance"))
  83. # analysis page
  84. self.AddPage(page = self._createAnalysisPage(),
  85. text = " %s " % _("Analysis"))
  86. # view page
  87. self.AddPage(page = self._createAnimationPage(),
  88. text = " %s " % _("Animation"))
  89. self.UpdateSettings()
  90. self.mapWindow.SetToolWin(self)
  91. self.pageChanging = False
  92. self.vetoGSelectEvt = False #when setting map, event is invoked
  93. self.mapWindow.render['quick'] = False
  94. self.mapWindow.Refresh(False)
  95. # bindings
  96. self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
  97. self.Bind(wx.EVT_SIZE, self.OnSize)
  98. self.Bind(EVT_ANIM_FIN, self.OnAnimationFinished)
  99. self.Bind(EVT_ANIM_UPDATE_IDX, self.OnAnimationUpdateIndex)
  100. Debug.msg(3, "NvizToolWindow.__init__()")
  101. self.Update()
  102. wx.CallAfter(self.SetPage, 'view')
  103. wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear,
  104. self.foldpanelAnalysis))
  105. wx.CallAfter(self.SetInitialMaps)
  106. def SetInitialMaps(self):
  107. """!Set initial raster and vector map"""
  108. for ltype in ('raster', 'vector', '3d-raster'):
  109. selectedLayer = self.parent.GetLayerTree().GetSelectedLayer(multi = False, checkedOnly = True)
  110. selectedLayer = self.parent.GetLayerTree().GetLayerInfo(selectedLayer, key = 'maplayer')
  111. layers = self.mapWindow.Map.GetListOfLayers(ltype = ltype, active = True)
  112. if selectedLayer in layers:
  113. selection = selectedLayer.GetName()
  114. else:
  115. try:
  116. selection = layers[0].GetName()
  117. except:
  118. continue
  119. if ltype == 'raster':
  120. self.FindWindowById(self.win['surface']['map']).SetValue(selection)
  121. self.FindWindowById(self.win['fringe']['map']).SetValue(selection)
  122. elif ltype == 'vector':
  123. self.FindWindowById(self.win['vector']['map']).SetValue(selection)
  124. elif ltype == '3d-raster':
  125. self.FindWindowById(self.win['volume']['map']).SetValue(selection)
  126. def UpdateState(self, **kwargs):
  127. if 'view' in kwargs:
  128. self.mapWindow.view = kwargs['view']
  129. self.FindWindowById(self.win['view']['position']).data = kwargs['view']
  130. self.FindWindowById(self.win['view']['position']).PostDraw()
  131. if 'iview' in kwargs:
  132. self.mapWindow.iview = kwargs['iview']
  133. if 'light' in kwargs:
  134. self.mapWindow.light = kwargs['light']
  135. self.FindWindowById(self.win['light']['position']).data = kwargs['light']
  136. self.FindWindowById(self.win['light']['position']).PostDraw()
  137. if 'fly' in kwargs:
  138. self.mapWindow.fly['exag'] = kwargs['fly']['exag']
  139. def LoadSettings(self):
  140. """!Load Nviz settings and apply to current session"""
  141. view = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'view')) # copy
  142. light = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'light')) # copy
  143. fly = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'fly')) # copy
  144. self.UpdateState(view = view, light = light, fly = fly)
  145. self.PostViewEvent(zExag = True)
  146. self.PostLightEvent()
  147. self.UpdatePage('view')
  148. self.UpdatePage('light')
  149. self.mapWindow.ReloadLayersData()
  150. self.UpdatePage('surface')
  151. self.UpdatePage('vector')
  152. self.UpdateSettings()
  153. def OnPageChanged(self, event):
  154. new = event.GetSelection()
  155. # self.ChangeSelection(new)
  156. def PostViewEvent(self, zExag = False):
  157. """!Change view settings"""
  158. event = wxUpdateView(zExag = zExag)
  159. wx.PostEvent(self.mapWindow, event)
  160. def PostLightEvent(self, refresh = False):
  161. """!Change light settings"""
  162. event = wxUpdateLight(refresh = refresh)
  163. wx.PostEvent(self.mapWindow, event)
  164. def OnSize(self, event):
  165. """!After window is resized, update scrolling"""
  166. # workaround to resize captionbars of foldpanelbar
  167. wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear,
  168. self.foldpanelAnalysis))
  169. event.Skip()
  170. def OnPressCaption(self, event):
  171. """!When foldpanel item collapsed/expanded, update scrollbars"""
  172. foldpanel = event.GetBar().GetGrandParent().GetParent()
  173. wx.CallAfter(self.UpdateScrolling, (foldpanel,))
  174. event.Skip()
  175. def UpdateScrolling(self, foldpanels):
  176. """!Update scrollbars in foldpanel"""
  177. for foldpanel in foldpanels:
  178. length = foldpanel.GetPanelsLength(collapsed = 0, expanded = 0)
  179. # virtual width is set to fixed value to suppress GTK warning
  180. foldpanel.GetParent().SetVirtualSize((100, length[2]))
  181. foldpanel.GetParent().Layout()
  182. def _createViewPage(self):
  183. """!Create view settings page"""
  184. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  185. panel.SetupScrolling(scroll_x = False)
  186. self.page['view'] = { 'id' : 0,
  187. 'notebook' : self.GetId()}
  188. pageSizer = wx.BoxSizer(wx.VERTICAL)
  189. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  190. label = " %s " % (_("Control View")))
  191. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  192. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 10)
  193. self.win['view'] = {}
  194. # position
  195. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  196. self._createCompass(panel = panel, sizer = posSizer, type = 'view')
  197. view = ViewPositionWindow(panel, size = (175, 175),
  198. mapwindow = self.mapWindow)
  199. self.win['view']['position'] = view.GetId()
  200. posSizer.Add(item = view,
  201. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  202. gridSizer.Add(item = posSizer, pos = (0, 0))
  203. # perspective
  204. # set initial defaults here (or perhaps in a default values file), not in user settings
  205. #todo: consider setting an absolute max at 360 instead of undefined. (leave the default max value at pi)
  206. tooltip = _("Adjusts the distance and angular perspective of the image viewpoint")
  207. self._createControl(panel, data = self.win['view'], name = 'persp',
  208. tooltip = tooltip, range = (1, 120),
  209. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  210. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Perspective:")),
  211. pos = (1, 0), flag = wx.ALIGN_CENTER)
  212. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['slider']), pos = (2, 0),
  213. flag = wx.ALIGN_CENTER)
  214. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['text']), pos = (3, 0),
  215. flag = wx.ALIGN_CENTER)
  216. # twist
  217. tooltip = _("Tilts the plane of the surface from the horizontal")
  218. self._createControl(panel, data = self.win['view'], name = 'twist',
  219. tooltip = tooltip, range = (-180,180),
  220. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  221. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Tilt:")),
  222. pos = (1, 1), flag = wx.ALIGN_CENTER)
  223. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['slider']), pos = (2, 1))
  224. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['text']), pos = (3, 1),
  225. flag = wx.ALIGN_CENTER)
  226. # height + z-exag
  227. tooltip = _("Adjusts the viewing height above the surface"
  228. " (angle of view automatically adjusts to maintain the same center of view)")
  229. self._createControl(panel, data = self.win['view'], name = 'height', sliderHor = False,
  230. tooltip = tooltip, range = (0, 1),
  231. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  232. tooltip = _("Adjusts the relative height of features above the plane of the surface")
  233. self._createControl(panel, data = self.win['view'], name = 'z-exag', sliderHor = False,
  234. tooltip = tooltip, range = (0, 10), floatSlider = True,
  235. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  236. self.FindWindowById(self.win['view']['z-exag']['slider']).SetValue(1)
  237. self.FindWindowById(self.win['view']['z-exag']['text']).SetValue(1)
  238. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  239. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  240. pos = (0, 0), flag = wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, span = (1, 2))
  241. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['slider']),
  242. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  243. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['text']),
  244. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT, pos = (1, 1))
  245. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Z-exag:")),
  246. pos = (0, 2), flag = wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, span = (1, 2))
  247. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['slider']),
  248. flag = wx.ALIGN_RIGHT, pos = (1, 2))
  249. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['text']),
  250. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  251. wx.BOTTOM | wx.RIGHT, pos = (1, 3))
  252. gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_CENTER)
  253. # view setup + reset
  254. viewSizer = wx.BoxSizer(wx.HORIZONTAL)
  255. viewSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY,
  256. label = _("Look:")),
  257. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  258. border = 5)
  259. here = wx.ToggleButton(panel, id = wx.ID_ANY, label = _("here"))
  260. here.Bind(wx.EVT_TOGGLEBUTTON, self.OnLookAt)
  261. here.SetName('here')
  262. here.SetToolTipString(_("Allows you to select a point on the surface "
  263. "that becomes the new center of view. "
  264. "Click on the button and then on the surface."))
  265. viewSizer.Add(item = here, flag = wx.TOP|wx.BOTTOM|wx.LEFT|wx.ALIGN_CENTER_VERTICAL,
  266. border = 5)
  267. center = wx.Button(panel, id = wx.ID_ANY, label = _("center"))
  268. center.Bind(wx.EVT_BUTTON, self.OnLookAt)
  269. center.SetName('center')
  270. center.SetToolTipString(_("Resets the view to the original default center of view"))
  271. viewSizer.Add(item = center, flag = wx.TOP|wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL,
  272. border = 5)
  273. top = wx.Button(panel, id = wx.ID_ANY, label = _("top"))
  274. top.Bind(wx.EVT_BUTTON, self.OnLookAt)
  275. top.SetName('top')
  276. top.SetToolTipString(_("Sets the viewer directly over the scene's center position. This top view orients approximately north south."))
  277. viewSizer.Add(item = top, flag = wx.TOP|wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL,
  278. border = 5)
  279. reset = wx.Button(panel, id = wx.ID_ANY, label = _("reset"))
  280. reset.SetToolTipString(_("Reset to default view"))
  281. reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  282. viewSizer.Add(item = reset, proportion = 0,
  283. flag = wx.TOP|wx.BOTTOM|wx.RIGHT| wx.ALIGN_RIGHT,
  284. border = 5)
  285. gridSizer.AddGrowableCol(2)
  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. gridSizer.AddGrowableCol(0)
  299. # background color
  300. self.win['view']['background'] = {}
  301. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  302. label = _("Background color:")),
  303. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  304. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  305. colour = UserSettings.Get(group = 'nviz', key = 'view',
  306. subkey = ['background', 'color']),
  307. size = globalvar.DIALOG_COLOR_SIZE)
  308. self.win['view']['background']['color'] = color.GetId()
  309. color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
  310. gridSizer.Add(item = color, pos = (0, 1))
  311. 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. gridSizer.AddGrowableCol(3)
  570. # mode
  571. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  572. label = _("Mode:")),
  573. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  574. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  575. choices = [_("coarse"),
  576. _("fine"),
  577. _("both")])
  578. mode.SetName("selection")
  579. mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  580. self.win['surface']['draw']['mode'] = mode.GetId()
  581. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
  582. pos = (0, 1),span = (1, 2))
  583. # shading
  584. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  585. label = _("Shading:")),
  586. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  587. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  588. choices = [_("flat"),
  589. _("gouraud")])
  590. shade.SetName("selection")
  591. self.win['surface']['draw']['shading'] = shade.GetId()
  592. shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  593. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  594. pos = (0, 4))
  595. # set to all
  596. all = wx.Button(panel, id = wx.ID_ANY, label = _("Set to all"))
  597. all.SetToolTipString(_("Use draw settings for all loaded surfaces"))
  598. all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
  599. gridSizer.Add(item = all, flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  600. pos = (3, 4))
  601. self.win['surface']['all'] = all.GetId()
  602. # resolution coarse
  603. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  604. label = _("Coarse mode:")),
  605. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  606. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  607. label = _("resolution:")),
  608. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  609. resC = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  610. initial = 6,
  611. min = 1,
  612. max = 100)
  613. resC.SetName("value")
  614. self.win['surface']['draw']['res-coarse'] = resC.GetId()
  615. resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  616. gridSizer.Add(item = resC, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  617. # Coarse style
  618. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  619. label = _("style:")),
  620. pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  621. style = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  622. choices = [_("wire"),
  623. _("surface")])
  624. style.SetName("selection")
  625. self.win['surface']['draw']['style'] = style.GetId()
  626. style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  627. gridSizer.Add(item = style, flag = wx.ALIGN_CENTER_VERTICAL,
  628. pos = (3, 2))
  629. # color
  630. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  631. size = globalvar.DIALOG_COLOR_SIZE)
  632. color.SetName("colour")
  633. color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
  634. color.SetToolTipString(_("Change wire color"))
  635. self.win['surface']['draw']['wire-color'] = color.GetId()
  636. gridSizer.Add(item = color, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  637. pos = (3, 3))
  638. # resolution fine
  639. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  640. label = _("Fine mode:")),
  641. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  642. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  643. label = _("resolution:")),
  644. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  645. resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  646. initial = 3,
  647. min = 1,
  648. max = 100)
  649. resF.SetName("value")
  650. self.win['surface']['draw']['res-fine'] = resF.GetId()
  651. resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  652. gridSizer.Add(item = resF, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  653. 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. gridSizer.AddGrowableCol(2)
  666. # type
  667. self.win['surface']['attr'] = {}
  668. row = 0
  669. for code, attrb in (('color', _("Color")),
  670. ('mask', _("Mask")),
  671. ('transp', _("Transparency")),
  672. ('shine', _("Shininess"))):
  673. self.win['surface'][code] = {}
  674. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  675. label = attrb + ':'),
  676. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  677. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  678. choices = [_("map")])
  679. if code not in ('color', 'shine'):
  680. use.Insert(item = _("unset"), pos = 0)
  681. self.win['surface'][code]['required'] = False
  682. else:
  683. self.win['surface'][code]['required'] = True
  684. if code != 'mask':
  685. use.Append(item = _('constant'))
  686. self.win['surface'][code]['use'] = use.GetId()
  687. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  688. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  689. pos = (row, 1))
  690. map = Select(parent = panel, id = wx.ID_ANY,
  691. # size = globalvar.DIALOG_GSELECT_SIZE,
  692. size = (-1, -1),
  693. type = "raster")
  694. self.win['surface'][code]['map'] = map.GetId() - 1 # FIXME
  695. map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  696. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
  697. pos = (row, 2))
  698. if code == 'color':
  699. color = UserSettings.Get(group = 'nviz', key = 'surface', subkey = ['color', 'value'])
  700. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  701. colour = color,
  702. size = globalvar.DIALOG_COLOR_SIZE)
  703. value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
  704. elif code == 'mask':
  705. value = None
  706. else:
  707. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  708. initial = 0)
  709. value.SetRange(minVal = 0, maxVal = 100)
  710. value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  711. if value:
  712. self.win['surface'][code]['const'] = value.GetId()
  713. value.Enable(False)
  714. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  715. pos = (row, 3))
  716. else:
  717. self.win['surface'][code]['const'] = None
  718. self.SetMapObjUseMap(nvizType = 'surface',
  719. attrb = code) # -> enable map / disable constant
  720. row += 1
  721. 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. gridSizer.AddGrowableCol(3)
  735. # position
  736. tooltip = _("Changes the x, y, and z position of the current surface")
  737. self._createControl(panel, data = self.win['surface'], name = 'position',
  738. tooltip = tooltip, range = (-10000, 10000), floatSlider = True,
  739. bind = (self.OnSurfacePosition, self.OnSurfacePositionChanged, self.OnSurfacePositionText))
  740. axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
  741. choices = ["X",
  742. "Y",
  743. "Z"])
  744. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  745. reset.SetToolTipString(_("Reset to default position"))
  746. reset.Bind(wx.EVT_BUTTON, self.OnResetSurfacePosition)
  747. self.win['surface']['position']['reset'] = reset.GetId()
  748. self.win['surface']['position']['axis'] = axis.GetId()
  749. axis.SetSelection(2)
  750. axis.Bind(wx.EVT_CHOICE, self.OnSurfaceAxis)
  751. pslide = self.FindWindowById(self.win['surface']['position']['slider'])
  752. ptext = self.FindWindowById(self.win['surface']['position']['text'])
  753. ptext.SetValue('0')
  754. gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  755. gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
  756. gridSizer.Add(item = ptext, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
  757. gridSizer.Add(item = reset, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, pos = (0, 3))
  758. 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. gridSizer.AddGrowableCol(5)
  1039. # width
  1040. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1041. label = _("Line:")),
  1042. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1043. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1044. label = _("width:")),
  1045. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  1046. wx.ALIGN_RIGHT)
  1047. width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  1048. initial = 1,
  1049. min = 1,
  1050. max = 100)
  1051. width.SetValue(1)
  1052. self.win['vector']['lines']['width'] = width.GetId()
  1053. width.Bind(wx.EVT_SPINCTRL, self.OnVectorLines)
  1054. gridSizer.Add(item = width, pos = (0, 2),
  1055. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1056. # color
  1057. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1058. label = _("color:")),
  1059. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  1060. wx.ALIGN_RIGHT)
  1061. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  1062. colour = (0,0,0),
  1063. size = globalvar.DIALOG_COLOR_SIZE)
  1064. self.win['vector']['lines']['color'] = color.GetId()
  1065. color.Bind(csel.EVT_COLOURSELECT, self.OnVectorLines)
  1066. gridSizer.Add(item = color, pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL |
  1067. wx.ALIGN_LEFT)
  1068. # thematic mapping
  1069. self.win['vector']['lines']['thematic'] = {}
  1070. checkThematicColor = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1071. label = _("use color for thematic mapping"))
  1072. checkThematicWidth = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1073. label = _("use width for thematic mapping"))
  1074. self.win['vector']['lines']['thematic']['checkcolor'] = checkThematicColor.GetId()
  1075. self.win['vector']['lines']['thematic']['checkwidth'] = checkThematicWidth.GetId()
  1076. checkThematicColor.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
  1077. checkThematicWidth.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
  1078. checkThematicColor.SetValue(False)
  1079. checkThematicWidth.SetValue(False)
  1080. vSizer = wx.BoxSizer(wx.VERTICAL)
  1081. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  1082. hSizer.Add(item = checkThematicColor, flag = wx.ALIGN_CENTER_VERTICAL,
  1083. border = 5)
  1084. setThematic = wx.Button(parent = panel, id = wx.ID_ANY,
  1085. label = _("Set options..."))
  1086. self.win['vector']['lines']['thematic']['buttoncolor'] = setThematic.GetId()
  1087. setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
  1088. hSizer.Add(item = wx.Size(-1, -1), proportion = 1)
  1089. hSizer.Add(item = setThematic, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT,
  1090. border = 5, proportion = 0)
  1091. vSizer.Add(hSizer, flag = wx.EXPAND)
  1092. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  1093. hSizer.Add(item = checkThematicWidth, flag = wx.ALIGN_CENTER_VERTICAL,
  1094. border = 5)
  1095. setThematic = wx.Button(parent = panel, id = wx.ID_ANY,
  1096. label = _("Set options..."))
  1097. self.win['vector']['lines']['thematic']['buttonwidth'] = setThematic.GetId()
  1098. setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
  1099. hSizer.Add(item = wx.Size(-1, -1), proportion = 1)
  1100. hSizer.Add(item = setThematic, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT,
  1101. border = 5, proportion = 0)
  1102. vSizer.Add(hSizer, flag = wx.EXPAND)
  1103. gridSizer.Add(item = vSizer, flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  1104. pos = (1, 1), span = (1, 5))
  1105. # display
  1106. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1107. label = _("Display")),
  1108. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL |
  1109. wx.ALIGN_LEFT)
  1110. display = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  1111. choices = [_("on surface(s):"),
  1112. _("flat")])
  1113. self.win['vector']['lines']['flat'] = display.GetId()
  1114. display.Bind(wx.EVT_CHOICE, self.OnVectorDisplay)
  1115. gridSizer.Add(item = display, flag = wx.ALIGN_CENTER_VERTICAL |
  1116. wx.ALIGN_LEFT|wx.EXPAND, pos = (2, 1), span = (1,4))
  1117. # height
  1118. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1119. label = _("Height above surface:")),
  1120. pos = (3, 5), flag = wx.ALIGN_BOTTOM|wx.EXPAND)
  1121. surface = wx.CheckListBox(parent = panel, id = wx.ID_ANY, size = (-1, 60),
  1122. choices = [], style = wx.LB_NEEDED_SB)
  1123. surface.Bind(wx.EVT_CHECKLISTBOX, self.OnVectorSurface)
  1124. self.win['vector']['lines']['surface'] = surface.GetId()
  1125. gridSizer.Add(item = surface,
  1126. pos = (3, 0), span = (3, 5),
  1127. flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
  1128. self._createControl(panel, data = self.win['vector']['lines'], name = 'height', size = -1,
  1129. range = (0, 500), sliderHor = True,
  1130. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightText))
  1131. self.FindWindowById(self.win['vector']['lines']['height']['slider']).SetValue(0)
  1132. self.FindWindowById(self.win['vector']['lines']['height']['text']).SetValue(0)
  1133. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['slider']),
  1134. pos = (4, 5), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  1135. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['text']),
  1136. pos = (5, 5),
  1137. flag = wx.ALIGN_CENTER)
  1138. 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. gridSizer.AddGrowableCol(0)
  1160. gridSizer.AddGrowableCol(2)
  1161. gridSizer.AddGrowableCol(4)
  1162. gridSizer.AddGrowableCol(6)
  1163. # icon size
  1164. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1165. label = _("Icon:")),
  1166. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1167. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1168. label = _("size:")),
  1169. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  1170. wx.ALIGN_RIGHT)
  1171. if fs:
  1172. isize = fs.FloatSpin(parent = panel, id = wx.ID_ANY,
  1173. min_val = 0, max_val = 1e6,
  1174. increment = 1, value = 1, style = fs.FS_RIGHT)
  1175. isize.SetFormat("%f")
  1176. isize.SetDigits(1)
  1177. isize.Bind(fs.EVT_FLOATSPIN, self.OnVectorPoints)
  1178. else:
  1179. isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  1180. initial = 1,
  1181. min = 1,
  1182. max = 1e6)
  1183. isize.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  1184. isize.SetName('value')
  1185. isize.SetValue(100)
  1186. self.win['vector']['points']['size'] = isize.GetId()
  1187. gridSizer.Add(item = isize, pos = (0, 2),
  1188. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1189. # icon color
  1190. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1191. label = _("color:")),
  1192. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  1193. wx.ALIGN_RIGHT)
  1194. icolor = csel.ColourSelect(panel, id = wx.ID_ANY,
  1195. size = globalvar.DIALOG_COLOR_SIZE)
  1196. icolor.SetName("color")
  1197. icolor.SetColour((0,0,255))
  1198. self.win['vector']['points']['color'] = icolor.GetId()
  1199. icolor.Bind(csel.EVT_COLOURSELECT, self.OnVectorPoints)
  1200. gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL |
  1201. wx.ALIGN_LEFT,
  1202. pos = (0, 4))
  1203. # icon width - seems to do nothing
  1204. ## gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1205. ## label = _("width")),
  1206. ## pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  1207. ## wx.ALIGN_RIGHT)
  1208. ##
  1209. ## iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  1210. ## initial = 1,
  1211. ## min = 1,
  1212. ## max = 1e6)
  1213. ## iwidth.SetName('value')
  1214. ## iwidth.SetValue(100)
  1215. ## self.win['vector']['points']['width'] = iwidth.GetId()
  1216. ## iwidth.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  1217. ## iwidth.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  1218. ## gridSizer.Add(item = iwidth, pos = (1, 2),
  1219. ## flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1220. # icon symbol
  1221. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1222. label = _("symbol:")),
  1223. pos = (0, 5), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  1224. isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  1225. choices = UserSettings.Get(group = 'nviz', key = 'vector',
  1226. subkey = ['points', 'marker'], internal = True))
  1227. isym.SetName("selection")
  1228. self.win['vector']['points']['marker'] = isym.GetId()
  1229. isym.Bind(wx.EVT_CHOICE, self.OnVectorPoints)
  1230. gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  1231. pos = (0, 6))
  1232. # thematic mapping
  1233. self.win['vector']['points']['thematic'] = {}
  1234. checkThematicColor = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1235. label = _("use color for thematic mapping"))
  1236. checkThematicSize = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1237. label = _("use size for thematic mapping"))
  1238. self.win['vector']['points']['thematic']['checkcolor'] = checkThematicColor.GetId()
  1239. self.win['vector']['points']['thematic']['checksize'] = checkThematicSize.GetId()
  1240. checkThematicColor.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
  1241. checkThematicSize.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
  1242. checkThematicColor.SetValue(False)
  1243. checkThematicSize.SetValue(False)
  1244. gridSizer.Add(item = checkThematicColor, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  1245. pos = (1, 1), span = (1, 5))
  1246. setThematic = wx.Button(parent = panel, id = wx.ID_ANY,
  1247. label = _("Set options..."))
  1248. self.win['vector']['points']['thematic']['buttoncolor'] = setThematic.GetId()
  1249. setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
  1250. gridSizer.Add(item = setThematic, flag = wx.ALIGN_CENTER_VERTICAL,
  1251. pos = (1, 6))
  1252. gridSizer.Add(item = checkThematicSize, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  1253. pos = (2, 1), span = (1, 5))
  1254. setThematic = wx.Button(parent = panel, id = wx.ID_ANY,
  1255. label = _("Set options..."))
  1256. self.win['vector']['points']['thematic']['buttonsize'] = setThematic.GetId()
  1257. setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
  1258. gridSizer.Add(item = setThematic, flag = wx.ALIGN_CENTER_VERTICAL,
  1259. pos = (2, 6))
  1260. vertSizer.Add(gridSizer, proportion = 0, flag = wx.EXPAND, border = 0)
  1261. # high
  1262. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  1263. gridSizer.AddGrowableCol(1)
  1264. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1265. label = _("Display on surface(s):")),
  1266. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1267. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1268. label = _("Height above surface:")),
  1269. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1270. surface = wx.CheckListBox(parent = panel, id = wx.ID_ANY, size = (-1, 60),
  1271. choices = [], style = wx.LB_NEEDED_SB)
  1272. surface.Bind(wx.EVT_CHECKLISTBOX, self.OnVectorSurface)
  1273. self.win['vector']['points']['surface'] = surface.GetId()
  1274. gridSizer.Add(item = surface,
  1275. pos = (1, 0), span = (3, 1),
  1276. flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
  1277. self._createControl(panel, data = self.win['vector']['points'], name = 'height', size = -1,
  1278. range = (0, 500),
  1279. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightText))
  1280. self.FindWindowById(self.win['vector']['points']['height']['slider']).SetValue(0)
  1281. self.FindWindowById(self.win['vector']['points']['height']['text']).SetValue(0)
  1282. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['slider']),
  1283. pos = (2, 1),flag = wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)
  1284. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['text']),
  1285. pos = (3, 1),
  1286. flag = wx.ALIGN_CENTER)
  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. gridSizer.AddGrowableCol(3)
  1451. # position
  1452. self._createControl(panel, data = self.win['volume'], name = 'position',
  1453. range = (-10000, 10000), floatSlider = True,
  1454. bind = (self.OnVolumePosition, self.OnVolumePositionChanged, self.OnVolumePositionText))
  1455. axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
  1456. choices = ["X",
  1457. "Y",
  1458. "Z"])
  1459. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  1460. reset.SetToolTipString(_("Reset to default position"))
  1461. reset.Bind(wx.EVT_BUTTON, self.OnResetVolumePosition)
  1462. self.win['volume']['position']['reset'] = reset.GetId()
  1463. self.win['volume']['position']['axis'] = axis.GetId()
  1464. axis.SetSelection(2) # Z
  1465. axis.Bind(wx.EVT_CHOICE, self.OnVolumeAxis)
  1466. pslide = self.FindWindowById(self.win['volume']['position']['slider'])
  1467. ptext = self.FindWindowById(self.win['volume']['position']['text'])
  1468. ptext.SetValue('0')
  1469. gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  1470. gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
  1471. gridSizer.Add(item = ptext, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
  1472. gridSizer.Add(item = reset, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, pos = (0, 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, event):
  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 event.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, event):
  1913. """!Animation: frame index changed"""
  1914. if event.mode == 'record':
  1915. self.UpdateFrameCount()
  1916. elif event.mode == 'play':
  1917. self.UpdateFrameIndex(index = event.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. gridSizer.AddGrowableCol(0,1)
  2154. gridSizer.AddGrowableCol(1,2)
  2155. gridSizer.AddGrowableCol(2,2)
  2156. # text labels
  2157. for i in range(2):
  2158. label = wx.StaticText(parent = panel, id = wx.ID_ANY)
  2159. label.SetName('label_edge_' + str(i))
  2160. gridSizer.Add(item = label, pos = (0, i + 1),
  2161. flag = wx.ALIGN_CENTER)
  2162. for i in range(2,4):
  2163. label = wx.StaticText(parent = panel, id = wx.ID_ANY)
  2164. label.SetName('label_edge_' + str(i))
  2165. gridSizer.Add(item = label, pos = (3, i -1),
  2166. flag = wx.ALIGN_CENTER)
  2167. for i in range(2):
  2168. label = wx.StaticText(parent = panel, id = wx.ID_ANY)
  2169. label.SetName('label_coord_' + str(i))
  2170. gridSizer.Add(item = label, pos = (i + 1, 0),
  2171. flag = wx.ALIGN_CENTER_VERTICAL)
  2172. label = wx.StaticText(parent = panel, id = wx.ID_ANY)
  2173. label.SetName('label_coord_2')
  2174. gridSizer.Add(item = label, pos = (4, 0),
  2175. flag = wx.ALIGN_CENTER_VERTICAL)
  2176. # sliders
  2177. for i, coord in enumerate(('x1', 'x2')):
  2178. slider = wx.Slider(parent = panel, id = wx.ID_ANY, minValue = 0, maxValue = 100, value = 0)
  2179. self.win['volume']['slice']['slider_' + coord] = slider.GetId()
  2180. slider.Bind(wx.EVT_SPIN, self.OnSlicePositionChange)
  2181. slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, self.OnSlicePositionChanged)
  2182. gridSizer.Add(item = slider, pos = (1, i + 1),
  2183. flag = wx.ALIGN_CENTER|wx.EXPAND)
  2184. for i, coord in enumerate(('y1', 'y2')):
  2185. slider = wx.Slider(parent = panel, id = wx.ID_ANY, minValue = 0, maxValue = 100, value = 0)
  2186. self.win['volume']['slice']['slider_' + coord] = slider.GetId()
  2187. slider.Bind(wx.EVT_SPIN, self.OnSlicePositionChange)
  2188. slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, self.OnSlicePositionChanged)
  2189. gridSizer.Add(item = slider, pos = (2, i + 1),
  2190. flag = wx.ALIGN_CENTER|wx.EXPAND)
  2191. for i, coord in enumerate(('z1', 'z2')):
  2192. slider = wx.Slider(parent = panel, id = wx.ID_ANY, minValue = 0, maxValue = 100, value = 0)
  2193. self.win['volume']['slice']['slider_' + coord] = slider.GetId()
  2194. slider.Bind(wx.EVT_SPIN, self.OnSlicePositionChange)
  2195. slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, self.OnSlicePositionChanged)
  2196. gridSizer.Add(item = slider, pos = (4,i+1),
  2197. flag = wx.ALIGN_CENTER|wx.EXPAND)
  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. self.AdjustSliderRange(slider = slider, value = value)
  2411. if winName == 'height':
  2412. view = self.mapWindow.iview # internal
  2413. else:
  2414. view = self.mapWindow.view
  2415. if winName == 'z-exag' and value >= 0:
  2416. self.PostViewEvent(zExag = True)
  2417. else:
  2418. self.PostViewEvent(zExag = False)
  2419. if winName in ('persp', 'twist'):
  2420. convert = int
  2421. else:
  2422. convert = float
  2423. view[winName]['value'] = convert(value)
  2424. for win in self.win['view'][winName].itervalues():
  2425. self.FindWindowById(win).SetValue(value)
  2426. self.mapWindow.iview['dir']['use'] = False
  2427. self.mapWindow.render['quick'] = True
  2428. if self.mapDisplay.IsAutoRendered():
  2429. self.mapWindow.Refresh(False)
  2430. event.Skip()
  2431. def OnViewChanged(self, event):
  2432. """!View changed, render in full resolution"""
  2433. self.mapWindow.render['quick'] = False
  2434. self.mapWindow.Refresh(False)
  2435. self.UpdateSettings()
  2436. try:# when calling event = None
  2437. event.Skip()
  2438. except AttributeError:
  2439. pass
  2440. def OnViewChangedText(self, event):
  2441. """!View changed, render in full resolution"""
  2442. self.mapWindow.render['quick'] = False
  2443. self.OnViewChange(event)
  2444. self.OnViewChanged(None)
  2445. self.Update()
  2446. event.Skip()
  2447. def OnLookAt(self, event):
  2448. """!Look here/center"""
  2449. name = self.FindWindowById(event.GetId()).GetName()
  2450. if name == 'center':
  2451. self._display.LookAtCenter()
  2452. focus = self.mapWindow.iview['focus']
  2453. focus['x'], focus['y'], focus['z'] = self._display.GetFocus()
  2454. self.mapWindow.saveHistory = True
  2455. self.mapWindow.Refresh(False)
  2456. elif name == 'top':
  2457. self.mapWindow.view['position']['x'] = 0.5
  2458. self.mapWindow.view['position']['y'] = 0.5
  2459. self.PostViewEvent(zExag = True)
  2460. self.UpdateSettings()
  2461. self.mapWindow.Refresh(False)
  2462. else: # here
  2463. if self.FindWindowById(event.GetId()).GetValue():
  2464. self.mapDisplay.Raise()
  2465. self.mapWindow.mouse['use'] = 'lookHere'
  2466. self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
  2467. else:
  2468. self.mapWindow.mouse['use'] = 'default'
  2469. self.mapWindow.SetCursor(self.mapWindow.cursors['default'])
  2470. def OnResetView(self, event):
  2471. """!Reset to default view (view page)"""
  2472. self.mapWindow.ResetView()
  2473. self.UpdateSettings()
  2474. self.mapWindow.Refresh(False)
  2475. def OnResetSurfacePosition(self, event):
  2476. """!Reset position of surface"""
  2477. for win in self.win['surface']['position'].itervalues():
  2478. if win == self.win['surface']['position']['axis']:
  2479. self.FindWindowById(win).SetSelection(2) # Z
  2480. elif win == self.win['surface']['position']['reset']:
  2481. continue
  2482. else:
  2483. self.FindWindowById(win).SetValue(0)
  2484. data = self.GetLayerData('surface')
  2485. data['surface']['position']['x'] = 0
  2486. data['surface']['position']['y'] = 0
  2487. data['surface']['position']['z'] = 0
  2488. data['surface']['position']['update'] = None
  2489. # update properties
  2490. event = wxUpdateProperties(data = data)
  2491. wx.PostEvent(self.mapWindow, event)
  2492. if self.mapDisplay.IsAutoRendered():
  2493. self.mapWindow.Refresh(False)
  2494. def OnLookFrom(self, event):
  2495. """!Position of view/light changed by buttons"""
  2496. name = self.FindWindowById(event.GetId()).GetName()
  2497. buttonName = name.split('_')[1]
  2498. if name.split('_')[0] == 'view':
  2499. type = 'view'
  2500. data = self.mapWindow.view
  2501. else:
  2502. type = 'light'
  2503. data = self.mapWindow.light
  2504. if buttonName == 'n': # north
  2505. data['position']['x'] = 0.5
  2506. data['position']['y'] = 0.0
  2507. elif buttonName == 's': # south
  2508. data['position']['x'] = 0.5
  2509. data['position']['y'] = 1.0
  2510. elif buttonName == 'e': # east
  2511. data['position']['x'] = 1.0
  2512. data['position']['y'] = 0.5
  2513. elif buttonName =='w': # west
  2514. data['position']['x'] = 0.0
  2515. data['position']['y'] = 0.5
  2516. elif buttonName == 'nw': # north-west
  2517. data['position']['x'] = 0.0
  2518. data['position']['y'] = 0.0
  2519. elif buttonName == 'ne': # north-east
  2520. data['position']['x'] = 1.0
  2521. data['position']['y'] = 0.0
  2522. elif buttonName == 'se': # south-east
  2523. data['position']['x'] = 1.0
  2524. data['position']['y'] = 1.0
  2525. elif buttonName == 'sw': # south-west
  2526. data['position']['x'] = 0.0
  2527. data['position']['y'] = 1.0
  2528. if type == 'view':
  2529. self.PostViewEvent(zExag = True)
  2530. self.UpdateSettings()
  2531. else:
  2532. self.PostLightEvent()
  2533. lightWin = self.FindWindowById(self.win['light']['position'])
  2534. x, y = lightWin.UpdatePos(self.mapWindow.light['position']['x'],
  2535. self.mapWindow.light['position']['y'])
  2536. lightWin.Draw(pos = (x, y), scale = True)
  2537. lightWin.Refresh(False)
  2538. self.mapWindow.render['quick'] = False
  2539. self.mapWindow.Refresh(False)
  2540. def OnMapObjUse(self, event):
  2541. """!Set surface attribute -- use -- map/constant"""
  2542. if not self.mapWindow.init:
  2543. return
  2544. wx.Yield()
  2545. # find attribute row
  2546. attrb = self.__GetWindowName(self.win['surface'], event.GetId())
  2547. if not attrb:
  2548. attrb = self.__GetWindowName(self.win['volume'], event.GetId())
  2549. nvizType = 'volume'
  2550. else:
  2551. nvizType = 'surface'
  2552. selection = event.GetSelection()
  2553. if self.win[nvizType][attrb]['required']: # no 'unset'
  2554. selection += 1
  2555. if selection == 0: # unset
  2556. useMap = None
  2557. value = ''
  2558. elif selection == 1: # map
  2559. useMap = True
  2560. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  2561. elif selection == 2: # constant
  2562. useMap = False
  2563. if attrb == 'color':
  2564. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  2565. value = self._getColorString(value)
  2566. else:
  2567. value = self._getPercent(self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue(), toPercent = False)
  2568. self.SetMapObjUseMap(nvizType = nvizType,
  2569. attrb = attrb, map = useMap)
  2570. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  2571. if nvizType == 'surface':
  2572. data = self._getLayerPropertiesByName(name, mapType = 'raster')
  2573. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  2574. 'value' : str(value),
  2575. 'update' : None }
  2576. else: # volume / isosurface
  2577. data = self._getLayerPropertiesByName(name, mapType = '3d-raster')
  2578. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2579. id = list.GetSelection()
  2580. if id != -1:
  2581. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  2582. 'value' : str(value),
  2583. 'update' : None }
  2584. # update properties
  2585. event = wxUpdateProperties(data = data)
  2586. wx.PostEvent(self.mapWindow, event)
  2587. if self.mapDisplay.IsAutoRendered():
  2588. self.mapWindow.Refresh(False)
  2589. def EnablePage(self, name, enabled = True):
  2590. """!Enable/disable all widgets on page"""
  2591. for key, item in self.win[name].iteritems():
  2592. if key in ('map', 'surface', 'new','planes'):
  2593. continue
  2594. if type(item) == types.DictType:
  2595. for skey, sitem in self.win[name][key].iteritems():
  2596. if type(sitem) == types.DictType:
  2597. for ssitem in self.win[name][key][skey].itervalues():
  2598. if type(ssitem) == types.IntType:
  2599. self.FindWindowById(ssitem).Enable(enabled)
  2600. else:
  2601. if type(sitem) == types.IntType:
  2602. self.FindWindowById(sitem).Enable(enabled)
  2603. else:
  2604. if type(item) == types.IntType:
  2605. self.FindWindowById(item).Enable(enabled)
  2606. def SetMapObjUseMap(self, nvizType, attrb, map = None):
  2607. """!Update dialog widgets when attribute type changed"""
  2608. if attrb in ('topo', 'color', 'shine'):
  2609. incSel = -1 # decrement selection (no 'unset')
  2610. else:
  2611. incSel = 0
  2612. if nvizType == 'volume' and attrb == 'topo':
  2613. return
  2614. if map is True: # map
  2615. if attrb != 'topo': # changing map topography not allowed
  2616. # not sure why, but here must be disabled both ids, should be fixed!
  2617. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(True)
  2618. if self.win[nvizType][attrb]['const']:
  2619. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  2620. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(1 + incSel)
  2621. elif map is False: # const
  2622. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  2623. if self.win[nvizType][attrb]['const']:
  2624. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(True)
  2625. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(2 + incSel)
  2626. else: # unset
  2627. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(0)
  2628. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  2629. if self.win[nvizType][attrb]['const']:
  2630. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  2631. def OnSurfaceMap(self, event):
  2632. """!Set surface attribute"""
  2633. if self.vetoGSelectEvt:
  2634. self.vetoGSelectEvt = False
  2635. return
  2636. self.SetMapObjAttrb(nvizType = 'surface', winId = event.GetId())
  2637. def SetMapObjAttrb(self, nvizType, winId):
  2638. """!Set map object (surface/isosurface) attribute (map/constant)"""
  2639. if not self.mapWindow.init:
  2640. return
  2641. attrb = self.__GetWindowName(self.win[nvizType], winId)
  2642. if not attrb:
  2643. return
  2644. if not (nvizType == 'volume' and attrb == 'topo'):
  2645. selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
  2646. if self.win[nvizType][attrb]['required']:
  2647. selection += 1
  2648. if selection == 0: # unset
  2649. useMap = None
  2650. value = ''
  2651. elif selection == 1: # map
  2652. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  2653. useMap = True
  2654. else: # constant
  2655. if attrb == 'color':
  2656. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  2657. # tuple to string
  2658. value = self._getColorString(value)
  2659. else:
  2660. value = self._getPercent(
  2661. self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue(), toPercent = False)
  2662. useMap = False
  2663. else:
  2664. useMap = None
  2665. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  2666. if not self.pageChanging:
  2667. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  2668. if nvizType == 'surface':
  2669. data = self._getLayerPropertiesByName(name, mapType = 'raster')
  2670. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  2671. 'value' : str(value),
  2672. 'update' : None }
  2673. else:
  2674. data = self._getLayerPropertiesByName(name, mapType = '3d-raster')
  2675. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2676. id = list.GetSelection()
  2677. if id > -1:
  2678. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  2679. 'value' : str(value),
  2680. 'update' : None }
  2681. if attrb == 'topo':
  2682. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2683. sel = list.GetSelection()
  2684. list.SetString(sel, "%s %s" % (_("Level"), str(value)))
  2685. list.Check(sel)
  2686. # update properties
  2687. event = wxUpdateProperties(data = data)
  2688. wx.PostEvent(self.mapWindow, event)
  2689. if self.mapDisplay.IsAutoRendered():
  2690. self.mapWindow.Refresh(False)
  2691. def OnSurfaceResolution(self, event):
  2692. """!Draw resolution changed"""
  2693. self.SetSurfaceResolution()
  2694. if self.mapDisplay.IsAutoRendered():
  2695. self.mapWindow.Refresh(False)
  2696. def SetSurfaceResolution(self):
  2697. """!Set draw resolution"""
  2698. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  2699. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  2700. data = self.GetLayerData('surface')
  2701. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  2702. 'fine' : fine,
  2703. 'update' : None }
  2704. # update properties
  2705. event = wxUpdateProperties(data = data)
  2706. wx.PostEvent(self.mapWindow, event)
  2707. def SetSurfaceMode(self):
  2708. """!Set draw mode"""
  2709. mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
  2710. style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
  2711. if style == 0: # wire
  2712. self.FindWindowById(self.win['surface']['draw']['wire-color']).Enable(True)
  2713. elif style == 1: # surface
  2714. self.FindWindowById(self.win['surface']['draw']['wire-color']).Enable(False)
  2715. shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
  2716. value, desc = self.mapWindow.nvizDefault.GetDrawMode(mode, style, shade)
  2717. return value, desc
  2718. def OnSurfaceMode(self, event):
  2719. """!Set draw mode"""
  2720. value, desc = self.SetSurfaceMode()
  2721. data = self.GetLayerData('surface')
  2722. data['surface']['draw']['mode'] = { 'value' : value,
  2723. 'desc' : desc,
  2724. 'update' : None }
  2725. # update properties
  2726. event = wxUpdateProperties(data = data)
  2727. wx.PostEvent(self.mapWindow, event)
  2728. if self.mapDisplay.IsAutoRendered():
  2729. self.mapWindow.Refresh(False)
  2730. def OnSurfaceModeAll(self, event):
  2731. """!Set draw mode (including wire color) for all loaded surfaces"""
  2732. value, desc = self.SetSurfaceMode()
  2733. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  2734. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  2735. color = self.FindWindowById(self.win['surface']['draw']['wire-color']).GetColour()
  2736. cvalue = self._getColorString(color)
  2737. for name in self.mapWindow.GetLayerNames(type = 'raster'):
  2738. data = self._getLayerPropertiesByName(name, mapType = 'raster')
  2739. if not data:
  2740. continue # shouldy no happen
  2741. data['surface']['draw']['all'] = True
  2742. data['surface']['draw']['mode'] = { 'value' : value,
  2743. 'desc' : desc,
  2744. 'update' : None }
  2745. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  2746. 'fine' : fine,
  2747. 'update' : None }
  2748. data['surface']['draw']['wire-color'] = { 'value' : cvalue,
  2749. 'update' : None }
  2750. # update properties
  2751. event = wxUpdateProperties(data = data)
  2752. wx.PostEvent(self.mapWindow, event)
  2753. if self.mapDisplay.IsAutoRendered():
  2754. self.mapWindow.Refresh(False)
  2755. def _getColorString(self, color):
  2756. """!Convert color tuple to R:G:B format
  2757. @param color tuple
  2758. @return string R:G:B
  2759. """
  2760. return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2761. def _getColorFromString(self, color, delim = ':'):
  2762. """!Convert color string (R:G:B) to wx.Color
  2763. @param color string
  2764. @param delim delimiter
  2765. @return wx.Color instance
  2766. """
  2767. return wx.Color(*map(int, color.split(delim)))
  2768. def _get3dRange(self, name):
  2769. """!Gelper func for getting range of 3d map"""
  2770. ret = RunCommand('r3.info', read = True, flags = 'r', map = name)
  2771. if ret:
  2772. range = []
  2773. for value in ret.strip('\n').split('\n'):
  2774. range.append(float(value.split('=')[1]))
  2775. return range
  2776. return -1e6, 1e6
  2777. def _getPercent(self, value, toPercent = True):
  2778. """!Convert values 0 - 255 to percents and vice versa"""
  2779. value = int(value)
  2780. if toPercent:
  2781. value = int(value/255. * 100)
  2782. else:
  2783. value = int(value/100. * 255)
  2784. return value
  2785. def OnSurfaceWireColor(self, event):
  2786. """!Set wire color"""
  2787. data = self.GetLayerData('surface')
  2788. value = self._getColorString(event.GetValue())
  2789. data['surface']['draw']['wire-color'] = { 'value' : value,
  2790. 'update' : None }
  2791. # update properties
  2792. event = wxUpdateProperties(data = data)
  2793. wx.PostEvent(self.mapWindow, event)
  2794. if self.mapDisplay.IsAutoRendered():
  2795. self.mapWindow.Refresh(False)
  2796. def OnSurfaceAxis(self, event):
  2797. """!Surface position, axis changed"""
  2798. data = self.GetLayerData('surface')
  2799. id = data['surface']['object']['id']
  2800. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  2801. slider = self.FindWindowById(self.win['surface']['position']['slider'])
  2802. text = self.FindWindowById(self.win['surface']['position']['text'])
  2803. xydim = self._display.GetLongDim()
  2804. zdim = self._display.GetZRange()
  2805. zdim = zdim[1] - zdim[0]
  2806. x, y, z = self._display.GetSurfacePosition(id)
  2807. if axis == 0: # x
  2808. slider.SetRange(-3 * xydim, 3 * xydim)
  2809. slider.SetValue(x)
  2810. text.SetValue(x)
  2811. elif axis == 1: # y
  2812. slider.SetRange(-3 * xydim, 3 * xydim)
  2813. slider.SetValue(y)
  2814. text.SetValue(y)
  2815. else: # z
  2816. slider.SetRange(-3 * zdim, 3 * zdim)
  2817. slider.SetValue(z)
  2818. text.SetValue(z)
  2819. def OnSurfacePosition(self, event):
  2820. """!Surface position"""
  2821. winName = self.__GetWindowName(self.win['surface'], event.GetId())
  2822. if not winName:
  2823. return
  2824. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  2825. value = self.FindWindowById(event.GetId()).GetValue()
  2826. slider = self.FindWindowById(self.win['surface'][winName]['slider'])
  2827. self.AdjustSliderRange(slider = slider, value = value)
  2828. for win in self.win['surface']['position'].itervalues():
  2829. if win in (self.win['surface']['position']['axis'],
  2830. self.win['surface']['position']['reset']):
  2831. continue
  2832. else:
  2833. self.FindWindowById(win).SetValue(value)
  2834. data = self.GetLayerData('surface')
  2835. id = data['surface']['object']['id']
  2836. x, y, z = self._display.GetSurfacePosition(id)
  2837. if axis == 0: # x
  2838. x = value
  2839. elif axis == 1: # y
  2840. y = value
  2841. else: # z
  2842. z = value
  2843. data['surface']['position']['x'] = x
  2844. data['surface']['position']['y'] = y
  2845. data['surface']['position']['z'] = z
  2846. data['surface']['position']['update'] = None
  2847. # update properties
  2848. event = wxUpdateProperties(data = data)
  2849. wx.PostEvent(self.mapWindow, event)
  2850. self.mapWindow.render['quick'] = True
  2851. if self.mapDisplay.IsAutoRendered():
  2852. self.mapWindow.Refresh(False)
  2853. # self.UpdatePage('surface')
  2854. def OnSurfacePositionChanged(self, event):
  2855. """!Surface position changed"""
  2856. self.mapWindow.render['quick'] = False
  2857. self.mapWindow.Refresh(False)
  2858. def OnSurfacePositionText(self, event):
  2859. """!Surface position changed by textctrl"""
  2860. self.OnSurfacePosition(event)
  2861. self.OnSurfacePositionChanged(None)
  2862. def UpdateVectorShow(self, vecType, enabled):
  2863. """!Enable/disable lines/points widgets
  2864. @param vecType vector type (lines, points)
  2865. """
  2866. if vecType != 'lines' and vecType != 'points':
  2867. return False
  2868. for win in self.win['vector'][vecType].keys():
  2869. if win == 'show':
  2870. continue
  2871. if type(self.win['vector'][vecType][win]) == type({}):
  2872. for swin in self.win['vector'][vecType][win].keys():
  2873. if enabled:
  2874. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
  2875. else:
  2876. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
  2877. else:
  2878. if enabled:
  2879. self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
  2880. else:
  2881. self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
  2882. return True
  2883. def OnVectorShow(self, event):
  2884. """!Show vector lines/points"""
  2885. winId = event.GetId()
  2886. if winId == self.win['vector']['lines']['show']:
  2887. vecType = 'lines'
  2888. points = False
  2889. else: # points
  2890. vecType = 'points'
  2891. points = True
  2892. checked = event.IsChecked()
  2893. name = self.FindWindowById(self.win['vector']['map']).GetValue()
  2894. items = self.parent.GetLayerTree().FindItemByData(key = 'name', value = name)
  2895. for item in items:
  2896. if self.parent.GetLayerTree().GetLayerInfo(item, key = 'type') == 'vector':
  2897. break
  2898. data = self.GetLayerData('vector')['vector']
  2899. if checked:
  2900. self.mapWindow.LoadVector(item, points = points, append = False)
  2901. else:
  2902. self.mapWindow.UnloadVector(item, points = points, remove = False)
  2903. self.UpdateVectorShow(vecType, checked)
  2904. if checked:
  2905. try:
  2906. id = data[vecType]['object']['id']
  2907. except KeyError:
  2908. id = -1
  2909. if id > 0:
  2910. self.mapWindow.SetMapObjProperties(item, id, vecType)
  2911. # update properties
  2912. event = wxUpdateProperties(data = data)
  2913. wx.PostEvent(self.mapWindow, event)
  2914. if self.mapDisplay.IsAutoRendered():
  2915. self.mapWindow.Refresh(False)
  2916. event.Skip()
  2917. def OnVectorDisplay(self, event):
  2918. """!Display vector lines on surface/flat"""
  2919. rasters = self.mapWindow.GetLayerNames('raster')
  2920. if event.GetSelection() == 0: # surface
  2921. if len(rasters) < 1:
  2922. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  2923. self.FindWindowById(self.win['vector']['lines']['flat']).SetSelection(1)
  2924. return
  2925. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(True)
  2926. # set first found surface
  2927. data = self.GetLayerData('vector')
  2928. data['vector']['lines']['mode']['surface'] = rasters[0]
  2929. self.FindWindowById(self.win['vector']['lines']['surface']).SetStringSelection( \
  2930. rasters[0])
  2931. else: # flat
  2932. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  2933. self.OnVectorLines(event)
  2934. event.Skip()
  2935. def OnVectorLines(self, event):
  2936. """!Set vector lines mode, apply changes if auto-rendering is enabled"""
  2937. data = self.GetLayerData('vector')
  2938. width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
  2939. mode = {}
  2940. if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
  2941. mode['type'] = 'surface'
  2942. mode['surface'] = {}
  2943. checklist = self.FindWindowById(self.win['vector']['lines']['surface'])
  2944. value = list()
  2945. checked = list()
  2946. for surface in range(checklist.GetCount()):
  2947. value.append(checklist.GetString(surface))
  2948. checked.append(checklist.IsChecked(surface))
  2949. mode['surface']['value'] = value
  2950. mode['surface']['show'] = checked
  2951. else:
  2952. mode['type'] = 'flat'
  2953. for attrb in ('width', 'mode'):
  2954. data['vector']['lines'][attrb]['update'] = None
  2955. data['vector']['lines']['width']['value'] = width
  2956. data['vector']['lines']['mode'] = mode
  2957. color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
  2958. if isinstance(color, csel.ColourSelect):
  2959. pass #color picker not yet instantiated
  2960. else:
  2961. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2962. data['vector']['lines']['color']['update'] = None
  2963. data['vector']['lines']['color']['value'] = color
  2964. # update properties
  2965. event = wxUpdateProperties(data = data)
  2966. wx.PostEvent(self.mapWindow, event)
  2967. if self.mapDisplay.IsAutoRendered():
  2968. self.mapWindow.Refresh(False)
  2969. def OnVectorHeight(self, event):
  2970. id = event.GetId()
  2971. if id in self.win['vector']['lines']['height'].values():
  2972. vtype = 'lines'
  2973. else:
  2974. vtype = 'points'
  2975. value = self.FindWindowById(id).GetValue()
  2976. slider = self.FindWindowById(self.win['vector'][vtype]['height']['slider'])
  2977. self.AdjustSliderRange(slider = slider, value = value)
  2978. for win in self.win['vector'][vtype]['height'].itervalues():
  2979. self.FindWindowById(win).SetValue(value)
  2980. data = self.GetLayerData('vector')
  2981. data['vector'][vtype]['height'] = { 'value' : value,
  2982. 'update' : None }
  2983. # update properties
  2984. event = wxUpdateProperties(data = data)
  2985. wx.PostEvent(self.mapWindow, event)
  2986. self.mapWindow.render['quick'] = True
  2987. self.mapWindow.render['v' + vtype] = True
  2988. self.mapWindow.Refresh(False)
  2989. event.Skip()
  2990. def OnVectorHeightFull(self, event):
  2991. """!Vector height changed, render in full resolution"""
  2992. self.OnVectorHeight(event)
  2993. ## self.OnVectorSurface(event)
  2994. id = event.GetId()
  2995. if id in self.win['vector']['lines']['height'].values():
  2996. vtype = 'lines'
  2997. else:
  2998. vtype = 'points'
  2999. self.mapWindow.render['quick'] = False
  3000. self.mapWindow.render['v' + vtype] = False
  3001. self.mapWindow.Refresh(False)
  3002. def OnVectorHeightText(self, event):
  3003. """!Vector height changed, render in full resolution"""
  3004. # self.OnVectorHeight(event)
  3005. self.OnVectorHeightFull(event)
  3006. def OnVectorSurface(self, event):
  3007. """!Reference surface for vector map (lines/points)"""
  3008. id = event.GetId()
  3009. if id == self.win['vector']['lines']['surface']:
  3010. vtype = 'lines'
  3011. else:
  3012. vtype = 'points'
  3013. checkList = self.FindWindowById(self.win['vector'][vtype]['surface'])
  3014. checked = []
  3015. surfaces = []
  3016. for items in range(checkList.GetCount()):
  3017. checked.append(checkList.IsChecked(items))
  3018. surfaces.append(checkList.GetString(items))
  3019. data = self.GetLayerData('vector')
  3020. data['vector'][vtype]['mode']['surface'] = { 'value' : surfaces,
  3021. 'show' : checked}
  3022. data['vector'][vtype]['mode']['update'] = None
  3023. # update properties
  3024. event = wxUpdateProperties(data = data)
  3025. wx.PostEvent(self.mapWindow, event)
  3026. if self.mapDisplay.IsAutoRendered():
  3027. self.mapWindow.Refresh(False)
  3028. def OnVectorPoints(self, event):
  3029. """!Set vector points mode, apply changes if auto-rendering is enabled"""
  3030. data = self.GetLayerData('vector')
  3031. size = self.FindWindowById(self.win['vector']['points']['size']).GetValue()
  3032. marker = self.FindWindowById(self.win['vector']['points']['marker']).GetSelection()
  3033. # width = self.FindWindowById(self.win['vector']['points']['width']).GetValue()
  3034. for attrb in ('size', 'marker'):
  3035. data['vector']['points'][attrb]['update'] = None
  3036. data['vector']['points']['size']['value'] = size
  3037. # data['vector']['points']['width']['value'] = width
  3038. data['vector']['points']['marker']['value'] = marker
  3039. color = self.FindWindowById(self.win['vector']['points']['color']).GetColour()
  3040. if isinstance(color, csel.ColourSelect):
  3041. pass #color picker not yet instantiated
  3042. else:
  3043. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  3044. data['vector']['points']['color']['update'] = None
  3045. data['vector']['points']['color']['value'] = color
  3046. # update properties
  3047. event = wxUpdateProperties(data = data)
  3048. wx.PostEvent(self.mapWindow, event)
  3049. if self.mapDisplay.IsAutoRendered():
  3050. self.mapWindow.Refresh(False)
  3051. def OnCheckThematic(self, event):
  3052. """!Switch on/off thematic mapping"""
  3053. # can be called with no event to enable/disable button
  3054. if not event:
  3055. ids = (self.win['vector']['points']['thematic']['checkcolor'],
  3056. self.win['vector']['lines']['thematic']['checkcolor'],
  3057. self.win['vector']['points']['thematic']['checksize'],
  3058. self.win['vector']['lines']['thematic']['checkwidth'])
  3059. else:
  3060. ids = (event.GetId(),)
  3061. for id in ids:
  3062. if id in self.win['vector']['points']['thematic'].values():
  3063. vtype = 'points'
  3064. if id == self.win['vector'][vtype]['thematic']['checkcolor']:
  3065. attrType = 'color'
  3066. else:
  3067. attrType = 'size'
  3068. else:
  3069. vtype = 'lines'
  3070. if id == self.win['vector'][vtype]['thematic']['checkcolor']:
  3071. attrType = 'color'
  3072. else:
  3073. attrType = 'width'
  3074. check = self.win['vector'][vtype]['thematic']['check' + attrType]
  3075. button = self.win['vector'][vtype]['thematic']['button' + attrType]
  3076. if self.FindWindowById(check).GetValue():
  3077. checked = True
  3078. else:
  3079. checked = False
  3080. self.FindWindowById(button).Enable(checked)
  3081. data = self.GetLayerData('vector')
  3082. # decide if use GRASSRGB column
  3083. if attrType == 'color':
  3084. name = self.FindWindowById(self.win['vector']['map']).GetValue()
  3085. if not data['vector'][vtype]['thematic']['rgbcolumn']:
  3086. try:
  3087. id = data['vector'][vtype]['object']['id']
  3088. # if GRASSRGB exists and color table doesn't, use GRGB
  3089. if self.HasGRASSRGB(name) and \
  3090. not self._display.CheckColorTable(id = id, type = vtype):
  3091. data['vector'][vtype]['thematic']['rgbcolumn'] = 'GRASSRGB'
  3092. except KeyError:
  3093. pass
  3094. data['vector'][vtype]['thematic']['use' + attrType] = checked
  3095. data['vector'][vtype]['thematic']['update'] = None
  3096. # update properties
  3097. event = wxUpdateProperties(data = data)
  3098. wx.PostEvent(self.mapWindow, event)
  3099. if self.mapDisplay.IsAutoRendered():
  3100. self.mapWindow.Refresh(False)
  3101. def HasGRASSRGB(self, name):
  3102. """!Check if GRASSRGB column exist."""
  3103. column = False
  3104. dbInfo = VectorDBInfo(name)
  3105. if len(dbInfo.layers):
  3106. table = dbInfo.layers[1]['table']
  3107. if 'GRASSRGB' in dbInfo.GetTableDesc(table):
  3108. column = True
  3109. return column
  3110. def OnSetThematic(self, event):
  3111. """!Set options for thematic points"""
  3112. if event.GetId() in self.win['vector']['points']['thematic'].values():
  3113. vtype = 'points'
  3114. else:
  3115. vtype = 'lines'
  3116. if event.GetId() == self.win['vector'][vtype]['thematic']['buttoncolor']:
  3117. attrType = 'color'
  3118. elif vtype == 'points':
  3119. attrType = 'size'
  3120. else:
  3121. attrType = 'width'
  3122. ctable = ThematicVectorTable(self, vtype, attributeType = attrType)
  3123. ctable.CentreOnScreen()
  3124. ctable.Show()
  3125. def UpdateIsosurfButtons(self, list):
  3126. """!Enable/disable buttons 'add', 'delete',
  3127. 'move up', 'move down'"""
  3128. nitems = list.GetCount()
  3129. add = self.parent.FindWindowById(self.win['volume']['btnAdd'])
  3130. delete = self.parent.FindWindowById(self.win['volume']['btnDelete'])
  3131. moveDown = self.parent.FindWindowById(self.win['volume']['btnMoveDown'])
  3132. moveUp = self.parent.FindWindowById(self.win['volume']['btnMoveUp'])
  3133. if nitems >= wxnviz.MAX_ISOSURFS:
  3134. # disable add button on max
  3135. add.Enable(False)
  3136. else:
  3137. add.Enable(True)
  3138. if nitems < 1:
  3139. # disable 'delete' if only one item in the lis
  3140. delete.Enable(False)
  3141. else:
  3142. delete.Enable(True)
  3143. if list.GetSelection() >= nitems - 1:
  3144. # disable 'move-down' if last
  3145. moveDown.Enable(False)
  3146. else:
  3147. moveDown.Enable(True)
  3148. if list.GetSelection() < 1:
  3149. # disable 'move-up' if first
  3150. moveUp.Enable(False)
  3151. else:
  3152. moveUp.Enable(True)
  3153. def OnVolumeMode(self, event):
  3154. """!Change mode isosurfaces/slices"""
  3155. mode = self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection()
  3156. data = self.GetLayerData('volume')['volume']
  3157. sizer = self.isoPanel.GetContainingSizer()
  3158. sizer = self.slicePanel.GetContainingSizer()
  3159. listBox = self.FindWindowByName('listStaticBox')
  3160. if mode == 0:
  3161. sizer.Show(self.isoPanel)
  3162. sizer.Hide(self.slicePanel)
  3163. listBox.SetLabel(" %s " % _("List of isosurfaces"))
  3164. data['draw']['mode']['value'] = 0
  3165. data['draw']['mode']['desc'] = 'isosurface'
  3166. else:
  3167. sizer.Hide(self.isoPanel)
  3168. sizer.Show(self.slicePanel)
  3169. listBox.SetLabel(" %s " % _("List of slices"))
  3170. data['draw']['mode']['value'] = 1
  3171. data['draw']['mode']['desc'] = 'slice'
  3172. if event:
  3173. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3174. layer = self._getMapLayerByName(name, mapType = '3d-raster')
  3175. self.UpdateVolumePage(layer, data, updateName = False)
  3176. sizer.Layout()
  3177. listBox.GetParent().Fit()
  3178. def OnVolumeDrawMode(self, event):
  3179. """!Set isosurface/slice draw mode"""
  3180. self.SetVolumeDrawMode(event.GetSelection())
  3181. def OnVolumeDrawBox(self, event):
  3182. """!Set wire box drawing"""
  3183. data = self.GetLayerData('volume')['volume']
  3184. vid = data['object']['id']
  3185. checked = self.FindWindowById(self.win['volume']['draw']['box']).GetValue()
  3186. self._display.SetVolumeDrawBox(vid, checked)
  3187. data['draw']['box']['enabled'] = checked
  3188. if self.mapDisplay.IsAutoRendered():
  3189. self.mapWindow.Refresh(False)
  3190. def SetVolumeDrawMode(self, selection):
  3191. """!Set isosurface draw mode"""
  3192. data = self.GetLayerData('volume')['volume']
  3193. id = data['object']['id']
  3194. mode = 0
  3195. if selection == 0:
  3196. mode |= wxnviz.DM_FLAT
  3197. else:
  3198. mode |= wxnviz.DM_GOURAUD
  3199. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  3200. self._display.SetIsosurfaceMode(id, mode)
  3201. data['draw']['shading']['isosurface']['desc'] = 'gouraud'
  3202. data['draw']['shading']['isosurface']['value'] = mode
  3203. else:
  3204. self._display.SetSliceMode(id, mode)
  3205. data['draw']['shading']['slice']['desc'] = 'flat'
  3206. data['draw']['shading']['slice']['value'] = mode
  3207. if self.mapDisplay.IsAutoRendered():
  3208. self.mapWindow.Refresh(False)
  3209. def OnVolumeResolution(self, event):
  3210. """!Set isosurface/slice draw resolution"""
  3211. self.SetVolumeResolution(event.GetInt())
  3212. def SetVolumeResolution(self, res):
  3213. """!Set isosurface draw resolution"""
  3214. data = self.GetLayerData('volume')['volume']
  3215. id = data['object']['id']
  3216. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  3217. self._display.SetIsosurfaceRes(id, res)
  3218. data['draw']['resolution']['isosurface']['value'] = res
  3219. else:
  3220. self._display.SetSliceRes(id, res)
  3221. data['draw']['resolution']['slice']['value'] = res
  3222. if self.mapDisplay.IsAutoRendered():
  3223. self.mapWindow.Refresh(False)
  3224. def OnInOutMode(self, event):
  3225. """!Change isosurfaces mode inout"""
  3226. data = self.GetLayerData('volume')['volume']
  3227. id = data['object']['id']
  3228. isosurfId = self.FindWindowById(self.win['volume']['isosurfs']).GetSelection()
  3229. ret = self._display.SetIsosurfaceInOut(id, isosurfId, event.GetInt())
  3230. if ret == 1:
  3231. data['isosurface'][isosurfId]['inout'] = event.GetInt()
  3232. if self.mapDisplay.IsAutoRendered():
  3233. self.mapWindow.Refresh(False)
  3234. def OnVolumeIsosurfMap(self, event):
  3235. """!Set surface attribute"""
  3236. if self.vetoGSelectEvt:
  3237. self.vetoGSelectEvt = False
  3238. return
  3239. self.SetMapObjAttrb(nvizType = 'volume', winId = event.GetId())
  3240. def OnVolumeCheck(self, event):
  3241. """!Isosurface/slice checked (->load) or unchecked (->unload)"""
  3242. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  3243. mode = 'isosurf'
  3244. else:
  3245. mode = 'slice'
  3246. index = event.GetSelection()
  3247. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3248. data = self.GetLayerData('volume')['volume']
  3249. vid = data['object']['id']
  3250. id = event.GetSelection()
  3251. if mode == 'isosurf':
  3252. if list.IsChecked(index):
  3253. if 'transp' in data['isosurface'][id] and\
  3254. data['isosurface'][id]['transp']['map'] is not None:
  3255. if data['isosurface'][id]['transp']['map']:
  3256. map = True
  3257. value = data['isosurface'][id]['transp']['value']
  3258. elif data['isosurface'][id]['transp']['map'] is not None:
  3259. map = False
  3260. value = data['isosurface'][id]['transp']['value']
  3261. self._display.SetIsosurfaceTransp(vid, id, map, value)
  3262. else:
  3263. self._display.SetIsosurfaceTransp(vid, id, False, "0")
  3264. else:
  3265. # disable -> make transparent
  3266. self._display.SetIsosurfaceTransp(vid, id, False, "255")
  3267. else:
  3268. if list.IsChecked(index):
  3269. value = data['slice'][id]['transp']['value']
  3270. self._display.SetSliceTransp(vid, id, value)
  3271. else:
  3272. # disable -> make transparent
  3273. self._display.SetSliceTransp(vid, id, 255)
  3274. if self.mapDisplay.IsAutoRendered():
  3275. self.mapWindow.Refresh(False)
  3276. def OnVolumeSelect(self, event):
  3277. """!Isosurface/Slice item selected"""
  3278. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  3279. mode = 'isosurf'
  3280. else:
  3281. mode = 'slice'
  3282. winUp = self.FindWindowById(self.win['volume']['btnMoveUp'])
  3283. winDown = self.FindWindowById(self.win['volume']['btnMoveDown'])
  3284. selection = event.GetSelection()
  3285. if selection == -1:
  3286. return
  3287. elif selection == 0:
  3288. winUp.Enable(False)
  3289. if not winDown.IsEnabled():
  3290. winDown.Enable()
  3291. elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
  3292. winDown.Enable(False)
  3293. if not winUp.IsEnabled():
  3294. winUp.Enable()
  3295. else:
  3296. if not winDown.IsEnabled():
  3297. winDown.Enable()
  3298. if not winUp.IsEnabled():
  3299. winUp.Enable()
  3300. # update dialog
  3301. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3302. layer = self._getMapLayerByName(name, mapType = '3d-raster')
  3303. if mode == 'isosurf':
  3304. data = self.GetLayerData('volume')['volume']['isosurface'][selection]
  3305. self.UpdateVolumeIsosurfPage(data)
  3306. else:
  3307. data = self.GetLayerData('volume')['volume']['slice'][selection]
  3308. self.UpdateVolumeSlicePage(data)
  3309. def OnVolumeAdd(self, event):
  3310. """!Add new isosurface/slice to the list"""
  3311. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  3312. mode = 'isosurf'
  3313. else:
  3314. mode = 'slice'
  3315. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3316. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3317. layer = self._getMapLayerByName(name, mapType = '3d-raster')
  3318. data = self.GetLayerData('volume')['volume']
  3319. id = data['object']['id']
  3320. sel = list.GetSelection()
  3321. if mode == 'isosurf':
  3322. isosurfData = self.mapWindow.nvizDefault.SetIsosurfaceDefaultProp()
  3323. if isosurfData['color']['map']:
  3324. isosurfData['color']['value'] = layer.name
  3325. level = isosurfData['topo']['value'] = round(self._get3dRange(name = layer.name)[0], 2)
  3326. if sel < 0 or sel >= list.GetCount() - 1:
  3327. item = list.Append(item = "%s %s" % (_("Level"), str(level)))
  3328. else:
  3329. list.Insert(item = "%s %s" % (_("Level"), str(level)),
  3330. pos = sel+1) # append
  3331. item = sel + 1
  3332. else:
  3333. sliceData = self.mapWindow.nvizDefault.SetSliceDefaultProp()
  3334. axis = ("X", "Y", "Z")[sliceData['position']['axis']]
  3335. if sel < 0 or sel >= list.GetCount() - 1:
  3336. item = list.Append(item = "%s %s" % (_("Slice parallel to"), axis))
  3337. else:
  3338. list.Insert(item = "%s" % (_("Slice parallel to"), axis),
  3339. pos = sel+1) # append
  3340. item = sel + 1
  3341. list.Check(item)
  3342. list.SetSelection(item)
  3343. if mode == 'isosurf':
  3344. data['isosurface'].insert(item, isosurfData)
  3345. # add isosurface
  3346. self._display.AddIsosurface(id, float(level))
  3347. else:
  3348. data['slice'].insert(item, sliceData)
  3349. # add isosurface
  3350. nslice = self._display.AddSlice(id)
  3351. self._display.SetSlicePosition(id, nslice -1, sliceData['position']['x1'], sliceData['position']['x2'],
  3352. sliceData['position']['y1'], sliceData['position']['y2'],
  3353. sliceData['position']['z1'], sliceData['position']['z2'],
  3354. sliceData['position']['axis'])
  3355. # update properties
  3356. event = wxUpdateProperties(data = data)
  3357. wx.PostEvent(self.mapWindow, event)
  3358. # update buttons
  3359. self.UpdateIsosurfButtons(list)
  3360. if mode == 'isosurf':
  3361. self.UpdateVolumeIsosurfPage(isosurfData)
  3362. else:
  3363. self.UpdateVolumeSlicePage(sliceData)
  3364. if self.mapDisplay.IsAutoRendered():
  3365. self.mapWindow.Refresh(False)
  3366. event.Skip()
  3367. def OnVolumeDelete(self, event):
  3368. """!Remove isosurface/slice from list"""
  3369. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  3370. mode = 'isosurf'
  3371. else:
  3372. mode = 'slice'
  3373. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3374. # remove item from list
  3375. id = list.GetSelection()
  3376. list.Delete(id)
  3377. # select last item
  3378. if list.GetCount() > 0:
  3379. list.SetSelection(list.GetCount()-1)
  3380. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3381. layer = self._getMapLayerByName(name, mapType = '3d-raster')
  3382. data = self.GetLayerData('volume')['volume']
  3383. vid = data['object']['id']
  3384. # delete isosurface
  3385. if mode == 'isosurf':
  3386. del data['isosurface'][id]
  3387. self._display.DeleteIsosurface(vid, id)
  3388. else:
  3389. del data['slice'][id]
  3390. self._display.DeleteSlice(vid, id)
  3391. # update buttons
  3392. if list.GetCount() > 0:
  3393. if mode == 'isosurf':
  3394. self.UpdateVolumeIsosurfPage(data['isosurface'][list.GetSelection()])
  3395. else:
  3396. self.UpdateVolumeSlicePage(data['slice'][list.GetSelection()])
  3397. else:
  3398. if mode == 'isosurf':
  3399. self.UpdateVolumeIsosurfPage(data['attribute'])
  3400. else:
  3401. self.UpdateVolumeSlicePage(None)
  3402. self.UpdateIsosurfButtons(list)
  3403. if self.mapDisplay.IsAutoRendered():
  3404. self.mapWindow.Refresh(False)
  3405. event.Skip()
  3406. def OnVolumeMoveUp(self, event):
  3407. """!Move isosurface/slice up in the list"""
  3408. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  3409. mode = 'isosurf'
  3410. else:
  3411. mode = 'slice'
  3412. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3413. sel = list.GetSelection()
  3414. if sel < 1:
  3415. return # this should not happen
  3416. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3417. layer = self._getMapLayerByName(name, mapType = '3d-raster')
  3418. data = self.GetLayerData('volume')['volume']
  3419. id = data['object']['id']
  3420. # move item up
  3421. text = list.GetStringSelection()
  3422. list.Insert(item = text, pos = sel-1)
  3423. list.Check(sel-1)
  3424. list.SetSelection(sel-1)
  3425. list.Delete(sel+1)
  3426. if mode == 'isosurf':
  3427. data['isosurface'].insert(sel-1, data['isosurface'][sel])
  3428. del data['isosurface'][sel+1]
  3429. self._display.MoveIsosurface(id, sel, True)
  3430. else:
  3431. data['slice'].insert(sel-1, data['slice'][sel])
  3432. del data['slice'][sel+1]
  3433. self._display.MoveSlice(id, sel, True)
  3434. # update buttons
  3435. self.UpdateIsosurfButtons(list)
  3436. if self.mapDisplay.IsAutoRendered():
  3437. self.mapWindow.Refresh(False)
  3438. event.Skip()
  3439. def OnVolumeMoveDown(self, event):
  3440. """!Move isosurface/slice down in the list"""
  3441. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  3442. mode = 'isosurf'
  3443. else:
  3444. mode = 'slice'
  3445. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3446. sel = list.GetSelection()
  3447. if sel >= list.GetCount() - 1:
  3448. return # this should not happen
  3449. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3450. layer = self._getMapLayerByName(name, mapType = '3d-raster')
  3451. data = self.GetLayerData('volume')['volume']
  3452. id = data['object']['id']
  3453. # move item up
  3454. text = list.GetStringSelection()
  3455. list.Insert(item = text, pos = sel+2)
  3456. list.Check(sel+2)
  3457. list.SetSelection(sel+2)
  3458. list.Delete(sel)
  3459. if mode == 'isosurf':
  3460. data['isosurface'].insert(sel+2, data['isosurface'][sel])
  3461. del data['isosurface'][sel]
  3462. self._display.MoveIsosurface(id, sel, False)
  3463. else:
  3464. data['slice'].insert(sel+2, data['slice'][sel])
  3465. del data['slice'][sel]
  3466. self._display.MoveSlice(id, sel, False)
  3467. # update buttons
  3468. self.UpdateIsosurfButtons(list)
  3469. if self.mapDisplay.IsAutoRendered():
  3470. self.mapWindow.Refresh(False)
  3471. event.Skip()
  3472. def OnVolumePositionChanged(self, event):
  3473. """!Volume position changed"""
  3474. self.mapWindow.render['quick'] = False
  3475. self.mapWindow.Refresh(False)
  3476. def OnVolumePosition(self, event):
  3477. """!Volume position"""
  3478. winName = self.__GetWindowName(self.win['volume'], event.GetId())
  3479. if not winName:
  3480. return
  3481. axis = self.FindWindowById(self.win['volume']['position']['axis']).GetSelection()
  3482. value = self.FindWindowById(event.GetId()).GetValue()
  3483. slider = self.FindWindowById(self.win['volume'][winName]['slider'])
  3484. self.AdjustSliderRange(slider = slider, value = value)
  3485. for win in self.win['volume']['position'].itervalues():
  3486. if win in (self.win['volume']['position']['axis'],
  3487. self.win['volume']['position']['reset']):
  3488. continue
  3489. else:
  3490. self.FindWindowById(win).SetValue(value)
  3491. data = self.GetLayerData('volume')
  3492. id = data['volume']['object']['id']
  3493. x, y, z = self._display.GetVolumePosition(id)
  3494. if axis == 0: # x
  3495. x = value
  3496. elif axis == 1: # y
  3497. y = value
  3498. else: # z
  3499. z = value
  3500. data['volume']['position']['x'] = x
  3501. data['volume']['position']['y'] = y
  3502. data['volume']['position']['z'] = z
  3503. data['volume']['position']['update'] = None
  3504. # update properties
  3505. event = wxUpdateProperties(data = data)
  3506. wx.PostEvent(self.mapWindow, event)
  3507. self.mapWindow.render['quick'] = True
  3508. if self.mapDisplay.IsAutoRendered():
  3509. self.mapWindow.Refresh(False)
  3510. def OnVolumeAxis(self, event):
  3511. """!Volume position, axis changed"""
  3512. data = self.GetLayerData('volume')
  3513. id = data['volume']['object']['id']
  3514. axis = self.FindWindowById(self.win['volume']['position']['axis']).GetSelection()
  3515. slider = self.FindWindowById(self.win['volume']['position']['slider'])
  3516. text = self.FindWindowById(self.win['volume']['position']['text'])
  3517. xydim = self._display.GetLongDim()
  3518. zdim = self._display.GetZRange()
  3519. zdim = zdim[1] - zdim[0]
  3520. x, y, z = self._display.GetVolumePosition(id)
  3521. if axis == 0: # x
  3522. slider.SetRange(-3 * xydim, 3 * xydim)
  3523. slider.SetValue(x)
  3524. text.SetValue(x)
  3525. elif axis == 1: # y
  3526. slider.SetRange(-3 * xydim, 3 * xydim)
  3527. slider.SetValue(y)
  3528. text.SetValue(y)
  3529. else: # z
  3530. slider.SetRange(-3 * zdim, 3 * zdim)
  3531. slider.SetValue(z)
  3532. text.SetValue(z)
  3533. def OnVolumePositionText(self, event):
  3534. """!Volume position changed by textctrl"""
  3535. self.OnVolumePosition(event)
  3536. self.OnVolumePositionChanged(None)
  3537. def OnResetVolumePosition(self, event):
  3538. """!Reset position of volume"""
  3539. for win in self.win['volume']['position'].itervalues():
  3540. if win == self.win['volume']['position']['axis']:
  3541. self.FindWindowById(win).SetSelection(2) # Z
  3542. elif win == self.win['volume']['position']['reset']:
  3543. continue
  3544. else:
  3545. self.FindWindowById(win).SetValue(0)
  3546. data = self.GetLayerData('volume')
  3547. data['volume']['position']['x'] = 0
  3548. data['volume']['position']['y'] = 0
  3549. data['volume']['position']['z'] = 0
  3550. data['volume']['position']['update'] = None
  3551. # update properties
  3552. event = wxUpdateProperties(data = data)
  3553. wx.PostEvent(self.mapWindow, event)
  3554. if self.mapDisplay.IsAutoRendered():
  3555. self.mapWindow.Refresh(False)
  3556. def OnVolumeSliceAxes(self, event):
  3557. """!Slice axis changed"""
  3558. self.UpdateSliceLabels()
  3559. data = self.GetLayerData('volume')
  3560. list = self.FindWindowById(self.win['volume']['slices'])
  3561. sel = list.GetSelection()
  3562. if sel < 0:
  3563. return
  3564. axis = self.FindWindowById(self.win['volume']['slice']['axes']).GetSelection()
  3565. data['volume']['slice'][sel]['position']['axis'] = axis
  3566. data['volume']['slice'][sel]['position']['update'] = None
  3567. axis = ("X", "Y", "Z")[axis]
  3568. list.SetString(sel, "%s %s" % (_("Slice parallel to"), axis))
  3569. list.Check(sel)
  3570. # update properties
  3571. event = wxUpdateProperties(data = data)
  3572. wx.PostEvent(self.mapWindow, event)
  3573. if self.mapDisplay.IsAutoRendered():
  3574. self.mapWindow.Refresh(False)
  3575. def OnSliceTransparency(self, event):
  3576. """!Slice transparency changed"""
  3577. data = self.GetLayerData('volume')
  3578. list = self.FindWindowById(self.win['volume']['slices'])
  3579. sel = list.GetSelection()
  3580. if sel < 0:
  3581. return
  3582. val = self.FindWindowById(self.win['volume']['slice']['transp']).GetValue()
  3583. data['volume']['slice'][sel]['transp']['value'] = self._getPercent(val, toPercent = False)
  3584. data['volume']['slice'][sel]['transp']['update'] = None
  3585. # update properties
  3586. event = wxUpdateProperties(data = data)
  3587. wx.PostEvent(self.mapWindow, event)
  3588. if self.mapDisplay.IsAutoRendered():
  3589. self.mapWindow.Refresh(False)
  3590. def OnSliceReset(self, event):
  3591. """!Slice position reset"""
  3592. data = self.GetLayerData('volume')
  3593. list = self.FindWindowById(self.win['volume']['slices'])
  3594. sel = list.GetSelection()
  3595. if sel < 0:
  3596. return
  3597. for coord, val in zip(('x1', 'x2', 'y1', 'y2', 'z1', 'z2'),(0, 1, 0, 1, 0, 1, 0)):
  3598. data['volume']['slice'][sel]['position'][coord] = val
  3599. data['volume']['slice'][sel]['position']['update'] = None
  3600. self.UpdateVolumeSlicePage(data['volume']['slice'][sel])
  3601. # update properties
  3602. event = wxUpdateProperties(data = data)
  3603. wx.PostEvent(self.mapWindow, event)
  3604. if self.mapDisplay.IsAutoRendered():
  3605. self.mapWindow.Refresh(False)
  3606. def OnSlicePositionChange(self, event):
  3607. """!Slice position is changing"""
  3608. data = self.GetLayerData('volume')
  3609. list = self.FindWindowById(self.win['volume']['slices'])
  3610. sel = list.GetSelection()
  3611. if sel < 0:
  3612. return
  3613. win = self.win['volume']['slice']
  3614. winId = event.GetId()
  3615. value = event.GetInt()/100.
  3616. for coord in ('x1', 'x2', 'y1', 'y2', 'z1', 'z2'):
  3617. if win['slider_' + coord] == winId:
  3618. data['volume']['slice'][sel]['position'][coord] = value
  3619. data['volume']['slice'][sel]['position']['update'] = None
  3620. break
  3621. self.mapWindow.render['quick'] = True
  3622. # update properties
  3623. event = wxUpdateProperties(data = data)
  3624. wx.PostEvent(self.mapWindow, event)
  3625. if self.mapDisplay.IsAutoRendered():
  3626. self.mapWindow.Refresh(False)
  3627. def OnSlicePositionChanged(self, event):
  3628. """!Slice position is changed"""
  3629. self.mapWindow.render['quick'] = False
  3630. if self.mapDisplay.IsAutoRendered():
  3631. self.mapWindow.Refresh(False)
  3632. def OnCPlaneSelection(self, event):
  3633. """!Cutting plane selected"""
  3634. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  3635. try:
  3636. planeIndex = int(plane.split()[-1]) - 1
  3637. self.EnablePage("cplane", enabled = True)
  3638. except:
  3639. planeIndex = -1
  3640. self.EnablePage("cplane", enabled = False)
  3641. self.mapWindow.SelectCPlane(planeIndex)
  3642. if planeIndex >= 0:
  3643. self.mapWindow.UpdateCPlane(planeIndex, changes = ['rotation', 'position', 'shading'])
  3644. if self.mapDisplay.IsAutoRendered():
  3645. self.mapWindow.Refresh(False)
  3646. self.UpdateCPlanePage(planeIndex)
  3647. def OnCPlaneChanging(self, event):
  3648. """!Cutting plane is changing"""
  3649. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  3650. try:
  3651. planeIndex = int(plane.split()[-1]) - 1
  3652. except:#TODO disabled page
  3653. planeIndex = -1
  3654. if event.GetId() in (self.win['cplane']['rotation']['rot'].values() +
  3655. self.win['cplane']['rotation']['tilt'].values()):
  3656. action = 'rotation'
  3657. else:
  3658. action = 'position'
  3659. data = self.mapWindow.cplanes[planeIndex][action]
  3660. self.OnScroll(event, self.win['cplane'][action], data)
  3661. self.mapWindow.render['quick'] = True
  3662. event = wxUpdateCPlane(update = (action,), current = planeIndex)
  3663. wx.PostEvent(self.mapWindow, event)
  3664. if self.mapDisplay.IsAutoRendered():
  3665. self.mapWindow.Refresh(False)
  3666. def OnCPlaneChangeDone(self, event):
  3667. """!Cutting plane change done"""
  3668. self.mapWindow.render['quick'] = False
  3669. if self.mapDisplay.IsAutoRendered():
  3670. self.mapWindow.Refresh(False)
  3671. def OnCPlaneChangeText(self, event):
  3672. """!Cutting plane changed by textctrl"""
  3673. for axis in ('x', 'y', 'z'):
  3674. if event.GetId() == self.win['cplane']['position'][axis]['text']:
  3675. value = self.FindWindowById(event.GetId()).GetValue()
  3676. slider = self.FindWindowById(self.win['cplane']['position'][axis]['slider'])
  3677. self.AdjustSliderRange(slider = slider, value = value)
  3678. self.OnCPlaneChanging(event = event)
  3679. self.OnCPlaneChangeDone(None)
  3680. def OnCPlaneShading(self, event):
  3681. """!Cutting plane shading changed"""
  3682. shading = self.FindWindowById(self.win['cplane']['shading']).GetSelection()
  3683. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  3684. try:
  3685. planeIndex = int(plane.split()[-1]) - 1
  3686. except:#TODO disabled page
  3687. planeIndex = -1
  3688. self.mapWindow.cplanes[planeIndex]['shading'] = shading
  3689. event = wxUpdateCPlane(update = ('shading',), current = planeIndex)
  3690. wx.PostEvent(self.mapWindow, event)
  3691. self.OnCPlaneChangeDone(None)
  3692. def OnCPlaneReset(self, event):
  3693. """!Reset current cutting plane"""
  3694. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  3695. try:
  3696. planeIndex = int(plane.split()[-1]) - 1
  3697. except:#TODO disabled page
  3698. planeIndex = -1
  3699. self.mapWindow.cplanes[planeIndex] = copy.deepcopy(UserSettings.Get(group = 'nviz',
  3700. key = 'cplane'))
  3701. self.mapWindow.cplanes[planeIndex]['on'] = True
  3702. event = wxUpdateCPlane(update = ('position','rotation','shading'), current = planeIndex)
  3703. wx.PostEvent(self.mapWindow, event)
  3704. self.OnCPlaneChangeDone(None)
  3705. self.UpdateCPlanePage(planeIndex)
  3706. def OnDecorationPlacement(self, event):
  3707. """!Place an arrow/scalebar by clicking on display"""
  3708. if event.GetId() == self.win['decoration']['arrow']['place']:
  3709. type = 'arrow'
  3710. elif event.GetId() == self.win['decoration']['scalebar']['place']:
  3711. type = 'scalebar'
  3712. else: return
  3713. if event.GetInt():
  3714. self.mapDisplay.Raise()
  3715. self.mapWindow.mouse['use'] = type
  3716. self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
  3717. else:
  3718. self.mapWindow.mouse['use'] = 'default'
  3719. self.mapWindow.SetCursor(self.mapWindow.cursors["default"])
  3720. def OnArrowDelete(self, event):
  3721. """!Delete arrow"""
  3722. self._display.DeleteArrow()
  3723. self.mapWindow.decoration['arrow']['show'] = False
  3724. self.FindWindowById( self.win['decoration']['arrow']['delete']).Disable()
  3725. self.mapWindow.Refresh(False)
  3726. def OnScalebarDelete(self, event):
  3727. """!Delete scalebar"""
  3728. choice = self.FindWindowById(self.win['decoration']['scalebar']['choice'])
  3729. choiceIndex = choice.GetSelection()
  3730. index = choice.GetClientData(choiceIndex)
  3731. if index == wx.NOT_FOUND:
  3732. return
  3733. self._display.DeleteScalebar(id = index)
  3734. self.FindWindowById(self.win['decoration']['scalebar']['choice']).Delete(choiceIndex)
  3735. if not choice.IsEmpty():
  3736. choice.SetSelection(choice.GetCount() - 1)
  3737. self.DisableScalebarControls()
  3738. self.mapWindow.Refresh(False)
  3739. def AddScalebar(self, scalebarNum):
  3740. choice = self.FindWindowById(self.win['decoration']['scalebar']['choice'])
  3741. choice.Append(_("Scalebar %d") % (scalebarNum + 1), scalebarNum)
  3742. choice.SetSelection(choice.GetCount() - 1)
  3743. self.DisableScalebarControls()
  3744. def AddArrow(self):
  3745. self.FindWindowById( self.win['decoration']['arrow']['delete']).Enable()
  3746. def DisableScalebarControls(self):
  3747. choice = self.FindWindowById(self.win['decoration']['scalebar']['choice'])
  3748. self.FindWindowById(self.win['decoration']['scalebar']['delete']).Enable(not choice.IsEmpty())
  3749. self.FindWindowById(self.win['decoration']['scalebar']['choice']).Enable(not choice.IsEmpty())
  3750. def OnDecorationProp(self, event):
  3751. """!Set arrow/scalebar properties"""
  3752. if event.GetId() in self.win['decoration']['arrow'].values():
  3753. type = 'arrow'
  3754. elif event.GetId() in self.win['decoration']['scalebar'].values():
  3755. type = 'scalebar'
  3756. else: return
  3757. color = self.FindWindowById(self.win['decoration'][type]['color']).GetValue()
  3758. size = self.FindWindowById(self.win['decoration'][type]['size']).GetValue()
  3759. if type == 'arrow':
  3760. self.mapWindow.decoration[type]['color'] = self._getColorString(color)
  3761. self.mapWindow.decoration[type]['size'] = size
  3762. elif type == 'scalebar'and self.mapWindow.decoration['scalebar']:
  3763. for scalebar in self.mapWindow.decoration[type]:
  3764. scalebar['color'] = self._getColorString(color)
  3765. scalebar['size'] = size
  3766. if type == 'arrow' and self.mapWindow.decoration['arrow']['show']:
  3767. self._display.SetArrow(self.mapWindow.decoration['arrow']['position']['x'],
  3768. self.mapWindow.decoration['arrow']['position']['y'],
  3769. self.mapWindow.decoration['arrow']['size'],
  3770. self.mapWindow.decoration['arrow']['color'])
  3771. self._display.DrawArrow()
  3772. elif type == 'scalebar' and self.mapWindow.decoration['scalebar']:
  3773. ids = []
  3774. choice = self.FindWindowById(self.win['decoration']['scalebar']['choice'])
  3775. for index in range(choice.GetCount()):
  3776. ids.append(choice.GetClientData(index))
  3777. for scalebar in self.mapWindow.decoration[type]:
  3778. if scalebar['id'] in ids:
  3779. self._display.SetScalebar(scalebar['id'],
  3780. scalebar['position']['x'],
  3781. scalebar['position']['y'],
  3782. scalebar['size'],
  3783. scalebar['color'])
  3784. self._display.DrawScalebar()
  3785. self.mapWindow.Refresh(False)
  3786. def UpdatePage(self, pageId):
  3787. """!Update dialog (selected page)"""
  3788. self.pageChanging = True
  3789. Debug.msg(1, "NvizToolWindow.UpdatePage(): %s", pageId)
  3790. if pageId == 'view':
  3791. self.SetPage('view')
  3792. hmin = self.mapWindow.iview['height']['min']
  3793. hmax = self.mapWindow.iview['height']['max']
  3794. hval = self.mapWindow.iview['height']['value']
  3795. zmin = self.mapWindow.view['z-exag']['min']
  3796. zmax = self.mapWindow.view['z-exag']['max']
  3797. zval = self.mapWindow.view['z-exag']['value']
  3798. for control in ('slider','text'):
  3799. self.FindWindowById(self.win['view']['height'][control]).SetRange(
  3800. hmin,hmax)
  3801. self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(
  3802. zmin, zmax)
  3803. self.FindWindowById(self.win['view']['height'][control]).SetValue(hval)
  3804. self.FindWindowById(self.win['view']['z-exag'][control]).SetValue(zval)
  3805. self.FindWindowById(self.win['view']['background']['color']).SetColour(\
  3806. self.mapWindow.view['background']['color'])
  3807. tval = self.mapWindow.view['twist']['value']
  3808. pval = self.mapWindow.view['persp']['value']
  3809. for control in ('slider','text'):
  3810. self.FindWindowById(self.win['view']['twist'][control]).SetValue(tval)
  3811. self.FindWindowById(self.win['view']['persp'][control]).SetValue(pval)
  3812. elif pageId in ('surface', 'vector', 'volume'):
  3813. name = self.FindWindowById(self.win[pageId]['map']).GetValue()
  3814. data = self.GetLayerData(pageId)
  3815. if data:
  3816. if pageId == 'surface':
  3817. layer = self._getMapLayerByName(name, mapType = 'raster')
  3818. self.UpdateSurfacePage(layer, data['surface'])
  3819. elif pageId == 'vector':
  3820. layer = self._getMapLayerByName(name, mapType = 'vector')
  3821. self.UpdateVectorPage(layer, data['vector'])
  3822. elif pageId == 'volume':
  3823. layer = self._getMapLayerByName(name, mapType = '3d-raster')
  3824. self.UpdateVolumePage(layer, data['volume'])
  3825. elif pageId == 'light':
  3826. zval = self.mapWindow.light['position']['z']
  3827. bval = self.mapWindow.light['bright']
  3828. aval = self.mapWindow.light['ambient']
  3829. for control in ('slider','text'):
  3830. self.FindWindowById(self.win['light']['z'][control]).SetValue(zval)
  3831. self.FindWindowById(self.win['light']['bright'][control]).SetValue(bval)
  3832. self.FindWindowById(self.win['light']['ambient'][control]).SetValue(aval)
  3833. self.FindWindowById(self.win['light']['color']).SetColour(self.mapWindow.light['color'])
  3834. self.FindWindowById(self.win['light']['position']).PostDraw()
  3835. elif pageId == 'fringe':
  3836. win = self.FindWindowById(self.win['fringe']['map'])
  3837. win.SetValue(self.FindWindowById(self.win['surface']['map']).GetValue())
  3838. elif pageId == 'decoration':
  3839. win = self.FindWindowById(self.win['decoration']['arrow']['size'])
  3840. win.SetValue(self.mapWindow.decoration['arrow']['size'])
  3841. win = self.FindWindowById(self.win['decoration']['scalebar']['size'])
  3842. win.SetValue(self.mapWindow._getDecorationSize())
  3843. elif pageId == 'constant':
  3844. if self.mapWindow.constants:
  3845. surface = self.FindWindowById(self.win['constant']['surface'])
  3846. for item in self.mapWindow.constants:
  3847. surface.Append(_("constant#") + str(item['constant']['object']['name']))
  3848. surface.SetSelection(0)
  3849. self.OnConstantSelection(None)
  3850. self.EnablePage('constant', True)
  3851. elif pageId == 'cplane':
  3852. count = self._display.GetCPlanesCount()
  3853. choices = [_("None"),]
  3854. for plane in range(count):
  3855. choices.append("%s %i" % (_("Plane"), plane+1))
  3856. self.FindWindowById(self.win['cplane']['planes']).SetItems(choices)
  3857. current = 0
  3858. for i, cplane in enumerate(self.mapWindow.cplanes):
  3859. if cplane['on']:
  3860. current = i + 1
  3861. self.FindWindowById(self.win['cplane']['planes']).SetSelection(current)
  3862. xyRange, zRange = self._display.GetXYRange(), self._display.GetZRange()
  3863. if xyRange > 0: # GTK warning
  3864. self.FindWindowById(self.win['cplane']['position']['x']['slider']).SetRange(
  3865. -xyRange/2., xyRange/2.)
  3866. self.FindWindowById(self.win['cplane']['position']['y']['slider']).SetRange(
  3867. -xyRange/2., xyRange/2.)
  3868. if zRange[0] - zRange[1] > 0:
  3869. self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetRange(zRange[0], zRange[1])
  3870. self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetValue(zRange[0])
  3871. self.FindWindowById(self.win['cplane']['position']['z']['text']).SetValue(zRange[0])
  3872. self.OnCPlaneSelection(None)
  3873. elif pageId == 'animation':
  3874. self.UpdateAnimationPage()
  3875. self.Update()
  3876. self.pageChanging = False
  3877. def UpdateAnimationPage(self):
  3878. """!Update animation page"""
  3879. # wrap help text according to tool window
  3880. help = self.FindWindowById(self.win['anim']['help'])
  3881. width = help.GetGrandParent().GetSizeTuple()[0]
  3882. help.Wrap(width - 15)
  3883. anim = self.mapWindow.GetAnimation()
  3884. if anim.Exists():
  3885. self.FindWindowById(self.win['anim']['play']).Enable()
  3886. else:
  3887. self.UpdateFrameIndex(index = 0)
  3888. self.UpdateFrameCount()
  3889. self.FindWindowById(self.win['anim']['play']).Disable()
  3890. self.FindWindowById(self.win['anim']['record']).Enable()
  3891. self.FindWindowById(self.win['anim']['pause']).Disable()
  3892. self.FindWindowById(self.win['anim']['stop']).Disable()
  3893. self.FindWindowById(self.win['anim']['frameIndex']['slider']).Disable()
  3894. self.FindWindowById(self.win['anim']['frameIndex']['text']).Disable()
  3895. def UpdateCPlanePage(self, index):
  3896. """!Update widgets according to selected clip plane"""
  3897. if index == -1:
  3898. return
  3899. data = self.mapWindow.cplanes[index]
  3900. for widget in ('text', 'slider'):
  3901. for axes in ('x', 'y', 'z'):
  3902. self.FindWindowById(self.win['cplane']['position'][axes][widget]).SetValue(data['position'][axes])
  3903. for each in ('tilt', 'rot'):
  3904. self.FindWindowById(self.win['cplane']['rotation'][each][widget]).SetValue(data['rotation'][each])
  3905. self.FindWindowById(self.win['cplane']['shading']).SetSelection(data['shading'])
  3906. def UpdateSurfacePage(self, layer, data, updateName = True):
  3907. """!Update surface page"""
  3908. desc = grass.raster_info(layer.name)['title']
  3909. if updateName:
  3910. self.FindWindowById(self.win['surface']['map']).SetValue(layer.name)
  3911. self.FindWindowById(self.win['surface']['desc']).SetLabel(desc)
  3912. # attributes
  3913. if layer and layer.type == 'raster':
  3914. self.vetoGSelectEvt = True
  3915. self.FindWindowById(self.win['surface']['color']['map']).SetValue(layer.name)
  3916. else:
  3917. self.FindWindowById(self.win['surface']['color']['map']).SetValue('')
  3918. self.SetMapObjUseMap(nvizType = 'surface',
  3919. attrb = 'color', map = True) # -> map
  3920. if 'color' in data['attribute']:
  3921. value = data['attribute']['color']['value']
  3922. if data['attribute']['color']['map']:
  3923. self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
  3924. else: # constant
  3925. color = map(int, value.split(':'))
  3926. self.FindWindowById(self.win['surface']['color']['const']).SetColour(color)
  3927. self.SetMapObjUseMap(nvizType = 'surface',
  3928. attrb = 'color', map = data['attribute']['color']['map'])
  3929. self.SetMapObjUseMap(nvizType = 'surface',
  3930. attrb = 'shine', map = data['attribute']['shine']['map'])
  3931. value = data['attribute']['shine']['value']
  3932. if data['attribute']['shine']['map']:
  3933. self.FindWindowById(self.win['surface']['shine']['map']).SetValue(value)
  3934. else:
  3935. self.FindWindowById(self.win['surface']['shine']['const']).SetValue(self._getPercent(value))
  3936. if 'transp' in data['attribute']:
  3937. value = data['attribute']['transp']['value']
  3938. if data['attribute']['transp']['map']:
  3939. self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
  3940. else:
  3941. self.FindWindowById(self.win['surface']['transp']['const']).SetValue(self._getPercent(value))
  3942. self.SetMapObjUseMap(nvizType = 'surface', attrb = 'transp', map = data['attribute']['transp']['map'])
  3943. else:
  3944. self.SetMapObjUseMap(nvizType = 'surface', attrb = 'transp', map = None)
  3945. #
  3946. # draw
  3947. #
  3948. for control, drawData in data['draw'].iteritems():
  3949. if control == 'all': # skip 'all' property
  3950. continue
  3951. if control == 'resolution':
  3952. self.FindWindowById(self.win['surface']['draw']['res-coarse']).SetValue(drawData['coarse'])
  3953. self.FindWindowById(self.win['surface']['draw']['res-fine']).SetValue(drawData['fine'])
  3954. continue
  3955. if control == 'mode':
  3956. if drawData['desc']['mode'] == 'coarse':
  3957. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(0)
  3958. elif drawData['desc']['mode'] == 'fine':
  3959. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(1)
  3960. else: # both
  3961. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(2)
  3962. if drawData['desc']['style'] == 'wire':
  3963. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(0)
  3964. else: # surface
  3965. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(1)
  3966. if drawData['desc']['shading'] == 'flat':
  3967. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(0)
  3968. else: # gouraud
  3969. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(1)
  3970. continue
  3971. value = drawData['value']
  3972. win = self.FindWindowById(self.win['surface']['draw'][control])
  3973. name = win.GetName()
  3974. if name == "selection":
  3975. win.SetSelection(value)
  3976. elif name == "colour":
  3977. color = map(int, value.split(':'))
  3978. win.SetColour(color)
  3979. else:
  3980. win.SetValue(value)
  3981. #
  3982. # position
  3983. #
  3984. self.OnSurfaceAxis(None)
  3985. # enable/disable res widget + set draw mode
  3986. self.OnSurfaceMode(event = None)
  3987. def VectorInfo(self, layer):
  3988. """!Get number of points/lines
  3989. @param layer MapLayer instance
  3990. @return num of points/features (expect of points)
  3991. @return None
  3992. """
  3993. vInfo = grass.vector_info_topo(layer.GetName())
  3994. if not vInfo:
  3995. return None
  3996. nprimitives = 0
  3997. for key, value in vInfo.iteritems():
  3998. if key in ('points',
  3999. 'lines',
  4000. 'boundaries',
  4001. 'centroids',
  4002. 'faces',
  4003. 'kernels'):
  4004. nprimitives += value
  4005. return (vInfo['points'], vInfo['lines'], nprimitives, vInfo['map3d'])
  4006. def UpdateVectorPage(self, layer, data, updateName = True):
  4007. """!Update vector page"""
  4008. npoints, nlines, nfeatures, mapIs3D = self.VectorInfo(layer)
  4009. if mapIs3D:
  4010. desc = _("Vector map is 3D")
  4011. enable = False
  4012. else:
  4013. desc = _("Vector map is 2D")
  4014. enable = True
  4015. desc += " - " + _("%(features)d features (%(points)d points)") % \
  4016. { 'features' : nfeatures, 'points' : npoints }
  4017. if updateName:
  4018. self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
  4019. self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
  4020. self.FindWindowById(self.win['vector']['lines']['flat']).Enable(enable)
  4021. for v in ('lines', 'points'):
  4022. self.FindWindowById(self.win['vector'][v]['surface']).Enable(enable)
  4023. self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
  4024. self.FindWindowById(self.win['vector'][v]['height']['text']).Enable(enable)
  4025. if data[v]['thematic']['usecolor']:
  4026. check = self.FindWindowById(self.win['vector'][v]['thematic']['checkcolor'])
  4027. check.SetValue(data[v]['thematic']['usecolor'])
  4028. if 'usesize' in data[v]['thematic'] and data[v]['thematic']['usesize']:
  4029. check = self.FindWindowById(self.win['vector'][v]['thematic']['checksize'])
  4030. check.SetValue(data[v]['thematic']['usesize'])
  4031. elif 'usewidth' in data[v]['thematic'] and data[v]['thematic']['usewidth']:
  4032. check = self.FindWindowById(self.win['vector'][v]['thematic']['checkwidth'])
  4033. check.SetValue(data[v]['thematic']['usewidth'])
  4034. self.OnCheckThematic(None)
  4035. #
  4036. # lines
  4037. #
  4038. showLines = self.FindWindowById(self.win['vector']['lines']['show'])
  4039. if 'object' in data['lines']:
  4040. showLines.SetValue(True)
  4041. else:
  4042. showLines.SetValue(False)
  4043. if nlines > 0:
  4044. showLines.Enable(True)
  4045. else:
  4046. showLines.Enable(False)
  4047. self.UpdateVectorShow('lines',
  4048. showLines.IsChecked())
  4049. width = self.FindWindowById(self.win['vector']['lines']['width'])
  4050. width.SetValue(data['lines']['width']['value'])
  4051. color = self.FindWindowById(self.win['vector']['lines']['color'])
  4052. color.SetValue(map(int, data['lines']['color']['value'].split(':')))
  4053. for vtype in ('lines', 'points'):
  4054. if vtype == 'lines':
  4055. display = self.FindWindowById(self.win['vector']['lines']['flat'])
  4056. if data[vtype]['mode']['type'] == 'flat':
  4057. display.SetSelection(1)
  4058. else:
  4059. display.SetSelection(0)
  4060. if data[vtype]['mode']['type'] == 'surface':
  4061. rasters = self.mapWindow.GetLayerNames('raster')
  4062. constants = self.mapWindow.GetLayerNames('constant')
  4063. surfaces = rasters + constants
  4064. surfaceWin = self.FindWindowById(self.win['vector'][vtype]['surface'])
  4065. surfaceWin.SetItems(surfaces)
  4066. for idx, surface in enumerate(surfaces):
  4067. try:# TODO fix this mess
  4068. selected = data[vtype]['mode']['surface']['show'][idx]
  4069. except (TypeError, IndexError, KeyError):
  4070. selected = False
  4071. surfaceWin.Check(idx, selected)
  4072. for type in ('slider', 'text'):
  4073. win = self.FindWindowById(self.win['vector']['lines']['height'][type])
  4074. win.SetValue(data['lines']['height']['value'])
  4075. #
  4076. # points
  4077. #
  4078. showPoints = self.FindWindowById(self.win['vector']['points']['show'])
  4079. if 'object' in data['points']:
  4080. showPoints.SetValue(True)
  4081. else:
  4082. showPoints.SetValue(False)
  4083. if npoints > 0:
  4084. showPoints.Enable(True)
  4085. else:
  4086. showPoints.Enable(False)
  4087. self.UpdateVectorShow('points',
  4088. showPoints.IsChecked())
  4089. # size, width, marker, color
  4090. for prop in ('size', 'marker', 'color'):
  4091. win = self.FindWindowById(self.win['vector']['points'][prop])
  4092. name = win.GetName()
  4093. if name == 'selection':
  4094. win.SetSelection(data['points'][prop]['value'])
  4095. elif name == 'color':
  4096. color = map(int, data['points'][prop]['value'].split(':'))
  4097. win.SetValue(color)
  4098. else:
  4099. win.SetValue(data['points'][prop]['value'])
  4100. ## self.OnCheckThematic(None)
  4101. # height
  4102. for type in ('slider', 'text'):
  4103. win = self.FindWindowById(self.win['vector']['points']['height'][type])
  4104. win.SetValue(data['points']['height']['value'])
  4105. def UpdateVolumePage(self, layer, data, updateName = True):
  4106. """!Update volume page"""
  4107. if updateName:
  4108. self.FindWindowById(self.win['volume']['map']).SetValue(layer.name)
  4109. # draw
  4110. for control, idata in data['draw'].iteritems():
  4111. if control == 'all': # skip 'all' property
  4112. continue
  4113. win = self.FindWindowById(self.win['volume']['draw'][control])
  4114. if control == 'mode':
  4115. value = data['draw']['mode']['value']
  4116. if control == 'shading':
  4117. if data['draw']['shading'][data['draw']['mode']['desc']]['desc'] == 'flat':
  4118. value = 0
  4119. else:
  4120. value = 1
  4121. if control == 'resolution':
  4122. value = idata[data['draw']['mode']['desc']]['value']
  4123. if control == 'box':
  4124. value = idata['enabled']
  4125. if win.GetName() == "selection":
  4126. win.SetSelection(value)
  4127. else:
  4128. win.SetValue(value)
  4129. self.OnVolumeMode(None)
  4130. id = data['object']['id']
  4131. if data['draw']['mode']['desc'] == 'isosurface':
  4132. self._display.SetIsosurfaceMode(id, data['draw']['shading']['isosurface']['value'])
  4133. self._display.SetIsosurfaceRes(id, data['draw']['resolution']['isosurface']['value'])
  4134. else:
  4135. self._display.SetSliceMode(id, data['draw']['shading']['slice']['value'])
  4136. self._display.SetSliceRes(id, data['draw']['resolution']['slice']['value'])
  4137. box = self.FindWindowById(self.win['volume']['isosurfs'])
  4138. if data['draw']['mode']['desc'] == 'isosurface':
  4139. isosurfaces = []
  4140. for iso in data['isosurface']:
  4141. level = iso['topo']['value']
  4142. isosurfaces.append("%s %s" % (_("Level"), level))
  4143. box.Set(isosurfaces)
  4144. for i in range(len(isosurfaces)):
  4145. box.Check(i)
  4146. if data['isosurface']:
  4147. box.SetSelection(0)
  4148. self.UpdateVolumeIsosurfPage(data['isosurface'][0])
  4149. else:
  4150. self.UpdateVolumeIsosurfPage(data['attribute'])
  4151. else:
  4152. slices = []
  4153. for slice in data['slice']:
  4154. axis = ("X", "Y", "Z")[slice['position']['axis']]
  4155. slices.append("%s %s" % (_("Slice parallel to"), axis))
  4156. box.Set(slices)
  4157. for i in range(len(slices)):
  4158. box.Check(i)
  4159. if data['slice']:
  4160. box.SetSelection(0)
  4161. self.UpdateVolumeSlicePage(data['slice'][0])
  4162. else:
  4163. self.UpdateVolumeSlicePage(None)
  4164. #
  4165. # position
  4166. #
  4167. if 'z' in data['position']:
  4168. zval = data['position']['z']
  4169. self.FindWindowById(self.win['volume']['position']['axis']).SetSelection(2)
  4170. for control in ('slider','text'):
  4171. self.FindWindowById(self.win['volume']['position'][control]).SetValue(zval)
  4172. # set topo range
  4173. mapRange = self._get3dRange(name = layer.name)
  4174. desc = self.FindWindowById(self.win['volume']['desc'])
  4175. desc.SetLabel("%s %.2f - %.2f" % (_("range:"), mapRange[0], mapRange[1]))
  4176. def UpdateVolumeIsosurfPage(self, data):
  4177. """!Update dialog -- isosurface attributes"""
  4178. #
  4179. # isosurface attributes
  4180. #
  4181. for attrb in ('topo', 'color', 'mask',
  4182. 'transp', 'shine'):
  4183. # skip empty attributes
  4184. if attrb not in data:
  4185. self.SetMapObjUseMap(nvizType = 'volume', attrb = attrb, map = None)
  4186. continue
  4187. value = data[attrb]['value']
  4188. if attrb == 'color':
  4189. if data[attrb]['map']:
  4190. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(value)
  4191. else: # constant
  4192. color = map(int, value.split(':'))
  4193. self.FindWindowById(self.win['volume'][attrb]['const']).SetColour(color)
  4194. else:
  4195. if data[attrb]['map']:
  4196. self.vetoGSelectEvt = True
  4197. win = self.FindWindowById(self.win['volume'][attrb]['map'])
  4198. win.SetValue(value)
  4199. else:
  4200. if value:
  4201. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  4202. if attrb == 'topo':
  4203. win.SetValue(float(value))
  4204. else:
  4205. win.SetValue(self._getPercent(value))
  4206. self.SetMapObjUseMap(nvizType = 'volume',
  4207. attrb = attrb, map = data[attrb]['map'])
  4208. # set inout
  4209. if 'inout' in data:
  4210. self.FindWindowById(self.win['volume']['inout']).SetValue(data['inout'])
  4211. def UpdateVolumeSlicePage(self, data):
  4212. """!Update dialog -- slice attributes"""
  4213. if data:
  4214. for coord in ('x1', 'x2', 'y1', 'y2', 'z1', 'z2'):
  4215. win = self.FindWindowById(self.win['volume']['slice']['slider_' + coord])
  4216. win.Enable()
  4217. win.SetValue(data['position'][coord] * 100)
  4218. win = self.FindWindowById(self.win['volume']['slice']['axes'])
  4219. win.SetSelection(data['position']['axis'])
  4220. win.Enable()
  4221. win = self.FindWindowById(self.win['volume']['slice']['transp'])
  4222. win.SetValue(self._getPercent(data['transp']['value']))
  4223. win.Enable()
  4224. self.FindWindowById(self.win['volume']['slice']['reset']).Enable()
  4225. else:
  4226. for coord in ('x1', 'x2', 'y1', 'y2', 'z1', 'z2'):
  4227. self.FindWindowById(self.win['volume']['slice']['slider_' + coord]).Disable()
  4228. self.FindWindowById(self.win['volume']['slice']['axes']).Disable()
  4229. self.FindWindowById(self.win['volume']['slice']['transp']).Disable()
  4230. self.FindWindowById(self.win['volume']['slice']['reset']).Disable()
  4231. self.UpdateSliceLabels()
  4232. def UpdateSliceLabels(self):
  4233. """!Update text labels of slice controls according to axis"""
  4234. sel = self.FindWindowById(self.win['volume']['slice']['axes']).GetSelection()
  4235. if sel == 0:
  4236. self.FindWindowByName('label_edge_0').SetLabel(_("North edge:"))
  4237. self.FindWindowByName('label_edge_1').SetLabel(_("South edge:"))
  4238. self.FindWindowByName('label_edge_2').SetLabel(_("West edge:"))
  4239. self.FindWindowByName('label_edge_3').SetLabel(_("East edge:"))
  4240. self.FindWindowByName('label_coord_0').SetLabel(_("Northing (Y):"))
  4241. self.FindWindowByName('label_coord_1').SetLabel(_("Height (Z):"))
  4242. self.FindWindowByName('label_coord_2').SetLabel(_("Easting (X):"))
  4243. elif sel == 1:
  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(_("North edge:"))
  4247. self.FindWindowByName('label_edge_3').SetLabel(_("South edge:"))
  4248. self.FindWindowByName('label_coord_0').SetLabel(_("Easting (X):"))
  4249. self.FindWindowByName('label_coord_1').SetLabel(_("Height (Z):"))
  4250. self.FindWindowByName('label_coord_2').SetLabel(_("Northing (Y):"))
  4251. else:
  4252. self.FindWindowByName('label_edge_0').SetLabel(_("West edge:"))
  4253. self.FindWindowByName('label_edge_1').SetLabel(_("East edge:"))
  4254. self.FindWindowByName('label_edge_2').SetLabel(_("Bottom edge:"))
  4255. self.FindWindowByName('label_edge_3').SetLabel(_("Top edge:"))
  4256. self.FindWindowByName('label_coord_0').SetLabel(_("Easting (X):"))
  4257. self.FindWindowByName('label_coord_1').SetLabel(_("Northing (Y):"))
  4258. self.FindWindowByName('label_coord_2').SetLabel(_("Height (Z):"))
  4259. def SetPage(self, name):
  4260. """!Get named page"""
  4261. if name == 'view':
  4262. self.SetSelection(0)
  4263. elif name in ('surface', 'vector', 'volume'):
  4264. self.SetSelection(1)
  4265. else:
  4266. self.SetSelection(2)
  4267. win = self.FindWindowById(self.page[name]['notebook'])
  4268. try:
  4269. win.Expand(win.GetFoldPanel(self.page[name]['id']))
  4270. self.UpdateScrolling((win.GetFoldPanel(self.page[name]['id']).GetGrandParent(),))
  4271. except AttributeError:
  4272. win.SetSelection(self.page[name]['id'])
  4273. class PositionWindow(wx.Window):
  4274. """!Abstract position control window, see subclasses
  4275. ViewPostionWindow and LightPositionWindow"""
  4276. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  4277. **kwargs):
  4278. self.mapWindow = mapwindow
  4279. self.quick = True
  4280. wx.Window.__init__(self, parent, id, **kwargs)
  4281. self.SetBackgroundColour("WHITE")
  4282. self.pdc = wx.PseudoDC()
  4283. self.pdc.SetBrush(wx.Brush(colour = 'dark green', style = wx.SOLID))
  4284. self.pdc.SetPen(wx.Pen(colour = 'dark green', width = 2, style = wx.SOLID))
  4285. self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
  4286. self.Bind(wx.EVT_PAINT, self.OnPaint)
  4287. # self.Bind(wx.EVT_MOTION, self.OnMouse)
  4288. self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
  4289. def Draw(self, pos, scale = False):
  4290. w, h = self.GetClientSize()
  4291. x, y = pos
  4292. if scale:
  4293. x = x * w
  4294. y = y * h
  4295. self.pdc.Clear()
  4296. self.pdc.BeginDrawing()
  4297. self.pdc.DrawLine(w / 2, h / 2, x, y)
  4298. self.pdc.DrawCircle(x, y, 5)
  4299. self.pdc.EndDrawing()
  4300. def OnPaint(self, event):
  4301. dc = wx.BufferedPaintDC(self)
  4302. dc.SetBackground(wx.Brush("White"))
  4303. dc.Clear()
  4304. # probably does nothing, removed from wxPython 2.9
  4305. # self.PrepareDC(dc)
  4306. self.pdc.DrawToDC(dc)
  4307. def UpdatePos(self, xcoord, ycoord):
  4308. """!Update position coordinates (origin: UL)"""
  4309. if xcoord < 0.0:
  4310. xcoord = 0.0
  4311. elif xcoord > 1.0:
  4312. xcoord = 1.0
  4313. if ycoord < 0.0:
  4314. ycoord = 0.0
  4315. elif ycoord > 1.0:
  4316. ycoord = 1.0
  4317. x, y = self.TransformCoordinates(xcoord, ycoord)
  4318. self.data['position']['x'] = x
  4319. self.data['position']['y'] = y
  4320. return xcoord, ycoord
  4321. def OnMouse(self, event):
  4322. if event.LeftIsDown():
  4323. x, y = event.GetPosition()
  4324. self.Draw(pos = (x, y))
  4325. w, h = self.GetClientSize()
  4326. x = float(x) / w
  4327. y = float(y) / h
  4328. self.UpdatePos(x, y)
  4329. self.Refresh(False)
  4330. event.Skip()
  4331. def PostDraw(self):
  4332. x, y = self.UpdatePos(self.data['position']['x'],
  4333. self.data['position']['y'])
  4334. self.Draw(pos = (x,y), scale = True)
  4335. class ViewPositionWindow(PositionWindow):
  4336. """!View position control widget"""
  4337. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  4338. **kwargs):
  4339. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  4340. self.SetToolTipString(_("Adjusts the distance and direction of the image viewpoint"))
  4341. self.data = self.mapWindow.view
  4342. self.PostDraw()
  4343. def UpdatePos(self, xcoord, ycoord):
  4344. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  4345. event = wxUpdateView(zExag = True)
  4346. wx.PostEvent(self.mapWindow, event)
  4347. return x, y
  4348. def TransformCoordinates(self, x, y, toLight = True):
  4349. return x, y
  4350. def OnMouse(self, event):
  4351. self.mapWindow.iview['dir']['use'] = False # use focus instead of viewdir
  4352. PositionWindow.OnMouse(self, event)
  4353. if event.LeftIsDown():
  4354. self.mapWindow.render['quick'] = self.quick
  4355. self.mapWindow.Refresh(eraseBackground = False)
  4356. elif event.LeftUp():
  4357. self.mapWindow.render['quick'] = False
  4358. self.mapWindow.Refresh(eraseBackground = False)
  4359. event.Skip()
  4360. class LightPositionWindow(PositionWindow):
  4361. """!Light position control widget"""
  4362. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  4363. **kwargs):
  4364. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  4365. self.SetToolTipString(_("Adjusts the light direction. "
  4366. "Click and drag the puck to change the light direction."))
  4367. self.data = self.mapWindow.light
  4368. self.quick = False
  4369. self.PostDraw()
  4370. def UpdatePos(self, xcoord, ycoord):
  4371. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  4372. event = wxUpdateLight(refresh = False)
  4373. wx.PostEvent(self.mapWindow, event)
  4374. return x, y
  4375. def TransformCoordinates(self, x, y, toLight = True):
  4376. if toLight:
  4377. x = 2 * x - 1
  4378. y = -2 * y + 1
  4379. else:
  4380. x = (x + 1)/2
  4381. y = (1 - y)/2
  4382. return x, y
  4383. def PostDraw(self):
  4384. event = wxUpdateLight(refresh = True)
  4385. wx.PostEvent(self.mapWindow, event)
  4386. x, y = self.data['position']['x'], self.data['position']['y']
  4387. x, y = self.TransformCoordinates(x, y, toLight = False)
  4388. self.Draw(pos = (x,y), scale = True)
  4389. def OnMouse(self, event):
  4390. PositionWindow.OnMouse(self, event)
  4391. if event.LeftUp():
  4392. self.mapWindow.render['quick'] = False
  4393. self.mapWindow.Refresh(eraseBackground = False)