nviz_tools.py 209 KB

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