nviz_tools.py 209 KB

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