tools.py 223 KB

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