nviz_tools.py 205 KB

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