nviz_tools.py 157 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652
  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 seznam.cz> (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. from preferences import globalSettings as UserSettings
  41. try:
  42. from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties,\
  43. wxUpdateCPlane
  44. import wxnviz
  45. except ImportError:
  46. pass
  47. from debug import Debug
  48. class ScrolledPanel(SP.ScrolledPanel):
  49. """!Custom ScrolledPanel to avoid strange behaviour concerning focus"""
  50. def __init__(self, parent):
  51. SP.ScrolledPanel.__init__(self, parent = parent, id = wx.ID_ANY)
  52. def OnChildFocus(self, event):
  53. pass
  54. class NTCValidator(wx.PyValidator):
  55. """!validates input in textctrls, taken from wxpython demo"""
  56. def __init__(self, flag = None):
  57. wx.PyValidator.__init__(self)
  58. self.flag = flag
  59. self.Bind(wx.EVT_CHAR, self.OnChar)
  60. def Clone(self):
  61. return NTCValidator(self.flag)
  62. def OnChar(self, event):
  63. key = event.GetKeyCode()
  64. if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
  65. event.Skip()
  66. return
  67. if self.flag == 'DIGIT_ONLY' and chr(key) in string.digits + '.-':
  68. event.Skip()
  69. return
  70. if not wx.Validator_IsSilent():
  71. wx.Bell()
  72. # Returning without calling even.Skip eats the event before it
  73. # gets to the text control
  74. return
  75. class NumTextCtrl(wx.TextCtrl):
  76. """!Class derived from wx.TextCtrl for numerical values only"""
  77. def __init__(self, parent, **kwargs):
  78. wx.TextCtrl.__init__(self, parent = parent,
  79. validator = NTCValidator(flag = 'DIGIT_ONLY'), **kwargs)
  80. def SetValue(self, value):
  81. super(NumTextCtrl, self).SetValue(str(int(value)))
  82. def GetValue(self):
  83. val = super(NumTextCtrl, self).GetValue()
  84. if val == '':
  85. val = '0'
  86. try:
  87. return int(float(val))
  88. except ValueError:
  89. val = ''.join(''.join(val.split('-')).split('.'))
  90. return int(float(val))
  91. def SetRange(self, min, max):
  92. pass
  93. class NvizToolWindow(FN.FlatNotebook):
  94. """!Nviz (3D view) tools panel
  95. """
  96. def __init__(self, parent, display, id = wx.ID_ANY,
  97. style = globalvar.FNPageStyle|FN.FNB_NO_X_BUTTON|FN.FNB_NO_NAV_BUTTONS,
  98. **kwargs):
  99. Debug.msg(5, "NvizToolWindow.__init__()")
  100. self.parent = parent # GMFrame
  101. self.mapDisplay = display
  102. self.mapWindow = display.GetWindow()
  103. self._display = self.mapWindow.GetDisplay()
  104. if globalvar.hasAgw:
  105. kwargs['agwStyle'] = style
  106. else:
  107. kwargs['style'] = style
  108. FN.FlatNotebook.__init__(self, parent, id, **kwargs)
  109. self.SetTabAreaColour(globalvar.FNPageColor)
  110. self.win = {} # window ids
  111. self.page = {} # page ids
  112. # view page
  113. self.AddPage(page = self._createViewPage(),
  114. text = " %s " % _("View"))
  115. # data page
  116. self.AddPage(page = self._createDataPage(),
  117. text = " %s " % _("Data"))
  118. # appearance page
  119. self.AddPage(page = self._createAppearancePage(),
  120. text = " %s " % _("Appearance"))
  121. # analysis page
  122. self.AddPage(page = self._createAnalysisPage(),
  123. text = " %s " % _("Analysis"))
  124. self.UpdateSettings()
  125. self.pageChanging = False
  126. self.vetoGSelectEvt = False #when setting map, event is invoked
  127. self.mapWindow.render['quick'] = False
  128. self.mapWindow.Refresh(False)
  129. # bindings
  130. self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
  131. self.Bind(wx.EVT_SIZE, self.OnSize)
  132. Debug.msg(3, "NvizToolWindow.__init__()")
  133. self.Update()
  134. wx.CallAfter(self.SetPage, 'view')
  135. wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear,
  136. self.foldpanelAnalysis))
  137. wx.CallAfter(self.SetInitialMaps)
  138. def SetInitialMaps(self):
  139. """!Set initial raster and vector map"""
  140. for l_type in ('raster', 'vector'):
  141. selectedLayer = self.mapWindow.GetSelectedLayer()
  142. layers = self.mapWindow.Map.GetListOfLayers(l_type = l_type, l_active = True)
  143. if selectedLayer in layers:
  144. selection = selectedLayer.GetName()
  145. else:
  146. try:
  147. selection = layers[0].GetName()
  148. except:
  149. return
  150. if l_type == 'raster':
  151. self.FindWindowById(self.win['surface']['map']).SetValue(selection)
  152. self.FindWindowById(self.win['fringe']['map']).SetValue(selection)
  153. elif l_type == 'vector':
  154. self.FindWindowById(self.win['vector']['map']).SetValue(selection)
  155. def UpdateState(self, **kwargs):
  156. if 'view' in kwargs:
  157. self.mapWindow.view = kwargs['view']
  158. self.FindWindowById(self.win['view']['position']).data = kwargs['view']
  159. if 'iview' in kwargs:
  160. self.mapWindow.iview = kwargs['iview']
  161. if 'light' in kwargs:
  162. self.mapWindow.light = kwargs['light']
  163. self.FindWindowById(self.win['light']['position']).data = kwargs['light']
  164. def OnPageChanged(self, event):
  165. new = event.GetSelection()
  166. # self.ChangeSelection(new)
  167. def PostViewEvent(self, zExag = False):
  168. """!Change view settings"""
  169. event = wxUpdateView(zExag = zExag)
  170. wx.PostEvent(self.mapWindow, event)
  171. def OnSize(self, event):
  172. """!After window is resized, update scrolling"""
  173. # workaround to resize captionbars of foldpanelbar
  174. wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear,
  175. self.foldpanelAnalysis))
  176. event.Skip()
  177. def OnPressCaption(self, event):
  178. """!When foldpanel item collapsed/expanded, update scrollbars"""
  179. foldpanel = event.GetBar().GetGrandParent().GetParent()
  180. wx.CallAfter(self.UpdateScrolling, (foldpanel,))
  181. event.Skip()
  182. def UpdateScrolling(self, foldpanels):
  183. """!Update scrollbars in foldpanel"""
  184. for foldpanel in foldpanels:
  185. length = foldpanel.GetPanelsLength(collapsed = 0, expanded = 0)
  186. # virtual width is set to fixed value to suppress GTK warning
  187. foldpanel.GetParent().SetVirtualSize((100, length[2]))
  188. foldpanel.GetParent().Layout()
  189. def _createViewPage(self):
  190. """!Create view settings page"""
  191. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  192. panel.SetupScrolling(scroll_x = False)
  193. self.page['view'] = { 'id' : 0,
  194. 'notebook' : self.GetId()}
  195. pageSizer = wx.BoxSizer(wx.VERTICAL)
  196. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  197. label = " %s " % (_("Control View")))
  198. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  199. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 10)
  200. self.win['view'] = {}
  201. # position
  202. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  203. self._createCompass(panel = panel, sizer = posSizer, type = 'view')
  204. view = ViewPositionWindow(panel, size = (175, 175),
  205. mapwindow = self.mapWindow)
  206. self.win['view']['position'] = view.GetId()
  207. posSizer.Add(item = view,
  208. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  209. gridSizer.Add(item = posSizer, pos = (0, 0))
  210. # perspective
  211. # set initial defaults here (or perhaps in a default values file), not in user settings
  212. self._createControl(panel, data = self.win['view'], name = 'persp',
  213. range = (1,100),
  214. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  215. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Perspective:")),
  216. pos = (1, 0), flag = wx.ALIGN_CENTER)
  217. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['slider']), pos = (2, 0),
  218. flag = wx.ALIGN_CENTER)
  219. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['text']), pos = (3, 0),
  220. flag = wx.ALIGN_CENTER)
  221. # twist
  222. self._createControl(panel, data = self.win['view'], name = 'twist',
  223. range = (-180,180),
  224. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  225. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Twist:")),
  226. pos = (1, 1), flag = wx.ALIGN_CENTER)
  227. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['slider']), pos = (2, 1))
  228. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['text']), pos = (3, 1),
  229. flag = wx.ALIGN_CENTER)
  230. # height + z-exag
  231. self._createControl(panel, data = self.win['view'], name = 'height', sliderHor = False,
  232. range = (0, 1),
  233. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  234. self._createControl(panel, data = self.win['view'], name = 'z-exag', sliderHor = False,
  235. range = (0, 5),
  236. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  237. self.FindWindowById(self.win['view']['z-exag']['slider']).SetValue(1)
  238. self.FindWindowById(self.win['view']['z-exag']['text']).SetValue(1)
  239. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  240. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  241. pos = (0, 0), flag = wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, span = (1, 2))
  242. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['slider']),
  243. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  244. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['text']),
  245. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT, pos = (1, 1))
  246. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Z-exag:")),
  247. pos = (0, 2), flag = wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, span = (1, 2))
  248. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['slider']),
  249. flag = wx.ALIGN_RIGHT, pos = (1, 2))
  250. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['text']),
  251. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  252. wx.BOTTOM | wx.RIGHT, pos = (1, 3))
  253. gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_CENTER)
  254. # view setup + reset
  255. viewSizer = wx.BoxSizer(wx.HORIZONTAL)
  256. viewSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY,
  257. label = _("Look:")),
  258. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  259. border = 5)
  260. here = wx.ToggleButton(panel, id = wx.ID_ANY, label = _("here"))
  261. here.Bind(wx.EVT_TOGGLEBUTTON, self.OnLookAt)
  262. here.SetName('here')
  263. viewSizer.Add(item = here, flag = wx.TOP|wx.BOTTOM|wx.LEFT|wx.ALIGN_CENTER_VERTICAL,
  264. border = 5)
  265. center = wx.Button(panel, id = wx.ID_ANY, label = _("center"))
  266. center.Bind(wx.EVT_BUTTON, self.OnLookAt)
  267. center.SetName('center')
  268. viewSizer.Add(item = center, flag = wx.TOP|wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL,
  269. border = 5)
  270. top = wx.Button(panel, id = wx.ID_ANY, label = _("top"))
  271. top.Bind(wx.EVT_BUTTON, self.OnLookAt)
  272. top.SetName('top')
  273. viewSizer.Add(item = top, flag = wx.TOP|wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL,
  274. border = 5)
  275. reset = wx.Button(panel, id = wx.ID_ANY, label = _("reset"))
  276. reset.SetToolTipString(_("Reset to default view"))
  277. reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  278. viewSizer.Add(item = reset, proportion = 0,
  279. flag = wx.TOP|wx.BOTTOM|wx.RIGHT| wx.ALIGN_RIGHT,
  280. border = 5)
  281. gridSizer.AddGrowableCol(2)
  282. gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 3),
  283. flag = wx.EXPAND)
  284. # body
  285. boxSizer.Add(item = gridSizer, proportion = 1,
  286. flag = wx.ALL | wx.EXPAND, border = 2)
  287. pageSizer.Add(item = boxSizer, proportion = 0,
  288. flag = wx.EXPAND | wx.ALL,
  289. border = 3)
  290. box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  291. label = " %s " % (_("Image Appearance")))
  292. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  293. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  294. gridSizer.AddGrowableCol(0)
  295. # background color
  296. self.win['view']['background'] = {}
  297. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  298. label = _("Background color:")),
  299. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  300. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  301. colour = UserSettings.Get(group = 'nviz', key = 'view',
  302. subkey = ['background', 'color']),
  303. size = globalvar.DIALOG_COLOR_SIZE)
  304. self.win['view']['background']['color'] = color.GetId()
  305. color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
  306. gridSizer.Add(item = color, pos = (0, 1))
  307. boxSizer.Add(item = gridSizer, proportion = 1,
  308. flag = wx.ALL | wx.EXPAND, border = 3)
  309. pageSizer.Add(item = boxSizer, proportion = 0,
  310. flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
  311. border = 3)
  312. panel.SetSizer(pageSizer)
  313. return panel
  314. def _createDataPage(self):
  315. """!Create data (surface, vector, volume) settings page"""
  316. self.mainPanelData = ScrolledPanel(parent = self)
  317. self.mainPanelData.SetupScrolling(scroll_x = False)
  318. ## style = fpb.CaptionBarStyle()
  319. ## style.SetCaptionStyle(fpb.CAPTIONBAR_FILLED_RECTANGLE)
  320. ## style.SetFirstColour(wx.Color(250,250,250))
  321. self.foldpanelData = fpb.FoldPanelBar(parent = self.mainPanelData, id = wx.ID_ANY,
  322. style = fpb.FPB_SINGLE_FOLD)
  323. self.foldpanelData.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  324. # surface page
  325. self.surfacePanel = self.foldpanelData.AddFoldPanel(_("Surface"), collapsed = False)
  326. self.foldpanelData.AddFoldPanelWindow(self.surfacePanel,
  327. window = self._createSurfacePage(parent = self.surfacePanel), flags = fpb.FPB_ALIGN_WIDTH)
  328. self.EnablePage("surface", enabled = False)
  329. # constant page
  330. constantPanel = self.foldpanelData.AddFoldPanel(_("Constant surface"), collapsed = True)
  331. self.foldpanelData.AddFoldPanelWindow(constantPanel,
  332. window = self._createConstantPage(parent = constantPanel), flags = fpb.FPB_ALIGN_WIDTH)
  333. self.EnablePage("constant", enabled = False)
  334. # vector page
  335. vectorPanel = self.foldpanelData.AddFoldPanel(_("Vector"), collapsed = True)
  336. self.foldpanelData.AddFoldPanelWindow(vectorPanel,
  337. window = self._createVectorPage(parent = vectorPanel), flags = fpb.FPB_ALIGN_WIDTH)
  338. self.EnablePage("vector", enabled = False)
  339. # volume page
  340. volumePanel = self.foldpanelData.AddFoldPanel(_("Volume"), collapsed = True)
  341. self.foldpanelData.AddFoldPanelWindow(volumePanel,
  342. window = self._createVolumePage(parent = volumePanel), flags = fpb.FPB_ALIGN_WIDTH)
  343. self.EnablePage("volume", enabled = False)
  344. ## self.foldpanelData.ApplyCaptionStyleAll(style)
  345. sizer = wx.BoxSizer(wx.VERTICAL)
  346. sizer.Add(self.foldpanelData, proportion = 1, flag = wx.EXPAND)
  347. self.mainPanelData.SetSizer(sizer)
  348. self.mainPanelData.Layout()
  349. self.mainPanelData.Fit()
  350. return self.mainPanelData
  351. def _createAppearancePage(self):
  352. """!Create data (surface, vector, volume) settings page"""
  353. self.mainPanelAppear = ScrolledPanel(parent = self)
  354. self.mainPanelAppear.SetupScrolling(scroll_x = False)
  355. self.foldpanelAppear = fpb.FoldPanelBar(parent = self.mainPanelAppear, id = wx.ID_ANY,
  356. style = fpb.FPB_SINGLE_FOLD)
  357. self.foldpanelAppear.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  358. # light page
  359. lightPanel = self.foldpanelAppear.AddFoldPanel(_("Lighting"), collapsed = False)
  360. self.foldpanelAppear.AddFoldPanelWindow(lightPanel,
  361. window = self._createLightPage(parent = lightPanel), flags = fpb.FPB_ALIGN_WIDTH)
  362. # fringe page
  363. fringePanel = self.foldpanelAppear.AddFoldPanel(_("Fringe"), collapsed = True)
  364. self.foldpanelAppear.AddFoldPanelWindow(fringePanel,
  365. window = self._createFringePage(parent = fringePanel), flags = fpb.FPB_ALIGN_WIDTH)
  366. self.EnablePage('fringe', False)
  367. sizer = wx.BoxSizer(wx.VERTICAL)
  368. sizer.Add(self.foldpanelAppear, proportion = 1, flag = wx.EXPAND)
  369. self.mainPanelAppear.SetSizer(sizer)
  370. self.mainPanelAppear.Layout()
  371. self.mainPanelAppear.Fit()
  372. return self.mainPanelAppear
  373. def _createAnalysisPage(self):
  374. """!Create data analysis (cutting planes, ...) page"""
  375. self.mainPanelAnalysis = ScrolledPanel(parent = self)
  376. self.mainPanelAnalysis.SetupScrolling(scroll_x = False)
  377. self.foldpanelAnalysis = fpb.FoldPanelBar(parent = self.mainPanelAnalysis, id = wx.ID_ANY,
  378. style = fpb.FPB_SINGLE_FOLD)
  379. self.foldpanelAnalysis.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  380. # cutting planes page
  381. cplanePanel = self.foldpanelAnalysis.AddFoldPanel(_("Cutting planes"), collapsed = False)
  382. self.foldpanelAnalysis.AddFoldPanelWindow(cplanePanel,
  383. window = self._createCPlanePage(parent = cplanePanel), flags = fpb.FPB_ALIGN_WIDTH)
  384. sizer = wx.BoxSizer(wx.VERTICAL)
  385. sizer.Add(self.foldpanelAnalysis, proportion = 1, flag = wx.EXPAND)
  386. self.mainPanelAnalysis.SetSizer(sizer)
  387. self.mainPanelAnalysis.Layout()
  388. self.mainPanelAnalysis.Fit()
  389. return self.mainPanelAnalysis
  390. def _createSurfacePage(self, parent):
  391. """!Create view settings page"""
  392. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  393. self.page['surface'] = { 'id' : 0,
  394. 'notebook' : self.foldpanelData.GetId() }
  395. pageSizer = wx.BoxSizer(wx.VERTICAL)
  396. self.win['surface'] = {}
  397. # selection
  398. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  399. label = " %s " % (_("Raster map")))
  400. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  401. rmaps = gselect.Select(parent = panel, type = 'raster',
  402. onPopup = self.GselectOnPopup)
  403. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster)
  404. self.win['surface']['map'] = rmaps.GetId()
  405. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  406. self.win['surface']['desc'] = desc.GetId()
  407. boxSizer.Add(item = rmaps, proportion = 0,
  408. flag = wx.ALL,
  409. border = 3)
  410. boxSizer.Add(item = desc, proportion = 0,
  411. flag = wx.ALL,
  412. border = 3)
  413. pageSizer.Add(item = boxSizer, proportion = 0,
  414. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  415. border = 3)
  416. #
  417. # draw
  418. #
  419. self.win['surface']['draw'] = {}
  420. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  421. label = " %s " % (_("Draw")))
  422. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  423. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  424. gridSizer.AddGrowableCol(3)
  425. # mode
  426. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  427. label = _("Mode:")),
  428. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  429. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  430. choices = [_("coarse"),
  431. _("fine"),
  432. _("both")])
  433. mode.SetName("selection")
  434. mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  435. self.win['surface']['draw']['mode'] = mode.GetId()
  436. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
  437. pos = (0, 1),span = (1, 2))
  438. # shading
  439. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  440. label = _("Shading:")),
  441. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  442. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  443. choices = [_("flat"),
  444. _("gouraud")])
  445. shade.SetName("selection")
  446. self.win['surface']['draw']['shading'] = shade.GetId()
  447. shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  448. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  449. pos = (0, 4))
  450. # set to all
  451. all = wx.Button(panel, id = wx.ID_ANY, label = _("Set to all"))
  452. all.SetToolTipString(_("Use draw settings for all loaded surfaces"))
  453. all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
  454. gridSizer.Add(item = all, flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  455. pos = (3, 4))
  456. # resolution coarse
  457. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  458. label = _("Coarse mode:")),
  459. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  460. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  461. label = _("resolution:")),
  462. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  463. resC = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  464. initial = 6,
  465. min = 1,
  466. max = 100)
  467. resC.SetName("value")
  468. self.win['surface']['draw']['res-coarse'] = resC.GetId()
  469. resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  470. gridSizer.Add(item = resC, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  471. # Coarse style
  472. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  473. label = _("style:")),
  474. pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  475. style = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  476. choices = [_("wire"),
  477. _("surface")])
  478. style.SetName("selection")
  479. self.win['surface']['draw']['style'] = style.GetId()
  480. style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  481. gridSizer.Add(item = style, flag = wx.ALIGN_CENTER_VERTICAL,
  482. pos = (3, 2))
  483. # color
  484. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  485. size = globalvar.DIALOG_COLOR_SIZE)
  486. color.SetName("colour")
  487. color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
  488. color.SetToolTipString(_("Change wire color"))
  489. self.win['surface']['draw']['wire-color'] = color.GetId()
  490. gridSizer.Add(item = color, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  491. pos = (3, 3))
  492. # resolution fine
  493. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  494. label = _("Fine mode:")),
  495. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  496. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  497. label = _("resolution:")),
  498. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  499. resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  500. initial = 3,
  501. min = 1,
  502. max = 100)
  503. resF.SetName("value")
  504. self.win['surface']['draw']['res-fine'] = resF.GetId()
  505. resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  506. gridSizer.Add(item = resF, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  507. boxSizer.Add(item = gridSizer, proportion = 1,
  508. flag = wx.ALL | wx.EXPAND, border = 3)
  509. pageSizer.Add(item = boxSizer, proportion = 0,
  510. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  511. border = 3)
  512. #
  513. # surface attributes
  514. #
  515. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  516. label = " %s " % (_("Surface attributes")))
  517. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  518. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  519. gridSizer.AddGrowableCol(2)
  520. # type
  521. self.win['surface']['attr'] = {}
  522. row = 0
  523. for code, attrb in (('color', _("Color")),
  524. ('mask', _("Mask")),
  525. ('transp', _("Transparency")),
  526. ('shine', _("Shininess"))):
  527. self.win['surface'][code] = {}
  528. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  529. label = attrb + ':'),
  530. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  531. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  532. choices = [_("map")])
  533. if code not in ('color', 'shine'):
  534. use.Insert(item = _("unset"), pos = 0)
  535. self.win['surface'][code]['required'] = False
  536. else:
  537. self.win['surface'][code]['required'] = True
  538. if code != 'mask':
  539. use.Append(item = _('constant'))
  540. self.win['surface'][code]['use'] = use.GetId()
  541. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  542. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  543. pos = (row, 1))
  544. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  545. # size = globalvar.DIALOG_GSELECT_SIZE,
  546. size = (-1, -1),
  547. type = "raster")
  548. self.win['surface'][code]['map'] = map.GetId() - 1 # FIXME
  549. map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  550. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
  551. pos = (row, 2))
  552. if code == 'color':
  553. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  554. colour = (0,0,0),
  555. size = globalvar.DIALOG_COLOR_SIZE)
  556. value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
  557. elif code == 'mask':
  558. value = None
  559. else:
  560. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  561. initial = 0)
  562. if code in ('shine', 'transp'):
  563. value.SetRange(minVal = 0, maxVal = 255)
  564. else:
  565. value.SetRange(minVal = 0, maxVal = 100)
  566. value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  567. if value:
  568. self.win['surface'][code]['const'] = value.GetId()
  569. value.Enable(False)
  570. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  571. pos = (row, 3))
  572. else:
  573. self.win['surface'][code]['const'] = None
  574. self.SetMapObjUseMap(nvizType = 'surface',
  575. attrb = code) # -> enable map / disable constant
  576. row += 1
  577. boxSizer.Add(item = gridSizer, proportion = 0,
  578. flag = wx.ALL | wx.EXPAND, border = 3)
  579. pageSizer.Add(item = boxSizer, proportion = 0,
  580. flag = wx.EXPAND | wx.ALL,
  581. border = 3)
  582. #
  583. # position
  584. #
  585. self.win['surface']['position'] = {}
  586. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  587. label = " %s " % (_("Position")))
  588. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  589. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  590. gridSizer.AddGrowableCol(3)
  591. # position
  592. self._createControl(panel, data = self.win['surface'], name = 'position',
  593. range = (-10000, 10000),
  594. bind = (self.OnSurfacePosition, self.OnSurfacePositionChanged, self.OnSurfacePosition))
  595. axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
  596. choices = ["X",
  597. "Y",
  598. "Z"])
  599. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  600. reset.SetToolTipString(_("Reset to default position"))
  601. reset.Bind(wx.EVT_BUTTON, self.OnResetSurfacePosition)
  602. self.win['surface']['position']['axis'] = axis.GetId()
  603. axis.SetSelection(0)
  604. axis.Bind(wx.EVT_CHOICE, self.OnSurfaceAxis)
  605. pslide = self.FindWindowById(self.win['surface']['position']['slider'])
  606. ptext = self.FindWindowById(self.win['surface']['position']['text'])
  607. ptext.SetValue('0')
  608. gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  609. gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
  610. gridSizer.Add(item = ptext, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
  611. gridSizer.Add(item = reset, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, pos = (0, 3))
  612. boxSizer.Add(item = gridSizer, proportion = 1,
  613. flag = wx.ALL | wx.EXPAND, border = 3)
  614. box.SetSizer(boxSizer)
  615. box.Layout()
  616. pageSizer.Add(item = boxSizer, proportion = 1,
  617. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  618. border = 3)
  619. #
  620. # mask
  621. #
  622. ## box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  623. ## label = " %s " % (_("Mask")))
  624. ## boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  625. ## gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  626. ##
  627. ## gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  628. ## label = _("Mask zeros:")),
  629. ## pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  630. ##
  631. ## elev = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  632. ## label = _("by elevation"))
  633. ## elev.Enable(False) # TODO: not implemented yet
  634. ## gridSizer.Add(item = elev, pos = (0, 1))
  635. ##
  636. ## color = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  637. ## label = _("by color"))
  638. ## color.Enable(False) # TODO: not implemented yet
  639. ## gridSizer.Add(item = color, pos = (0, 2))
  640. ##
  641. ## boxSizer.Add(item = gridSizer, proportion = 1,
  642. ## flag = wx.ALL | wx.EXPAND, border = 3)
  643. ## pageSizer.Add(item = boxSizer, proportion = 0,
  644. ## flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  645. ## border = 3)
  646. panel.SetSizer(pageSizer)
  647. panel.Layout()
  648. panel.Fit()
  649. return panel
  650. def _createCPlanePage(self, parent):
  651. """!Create cutting planes page"""
  652. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  653. self.page['cplane'] = { 'id' : 4,
  654. 'notebook' : self.foldpanelData.GetId() }
  655. self.win['cplane'] = {}
  656. pageSizer = wx.BoxSizer(wx.VERTICAL)
  657. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  658. label = " %s " % (_("Cutting planes")))
  659. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  660. horSizer = wx.BoxSizer(wx.HORIZONTAL)
  661. # planes
  662. horSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  663. label = _("Active cutting plane:")),
  664. flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  665. choice = wx.Choice(parent = panel, id = wx.ID_ANY, choices = [])
  666. self.win['cplane']['planes'] = choice.GetId()
  667. choice.Bind(wx.EVT_CHOICE, self.OnCPlaneSelection)
  668. horSizer.Add(item = choice, flag = wx.ALL, border = 5)
  669. # shading
  670. horSizer.Add(item = wx.Size(-1, -1), proportion = 1)
  671. horSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  672. label = _("Shading:")),
  673. flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  674. choices = [_("clear"),
  675. _("top color"),
  676. _("bottom color"),
  677. _("blend"),
  678. _("shaded")]
  679. choice = wx.Choice(parent = panel, id = wx.ID_ANY, choices = choices)
  680. self.win['cplane']['shading'] = choice.GetId()
  681. choice.Bind(wx.EVT_CHOICE, self.OnCPlaneShading)
  682. horSizer.Add(item = choice, flag = wx.ALL, border = 5)
  683. boxSizer.Add(item = horSizer, flag = wx.EXPAND)
  684. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  685. # XYZ position
  686. self.win['cplane']['position'] = {}
  687. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  688. label = _("X:")),
  689. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  690. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  691. label = _("Y:")),
  692. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  693. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  694. label = _("Height:")),
  695. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  696. self._createControl(panel, data = self.win['cplane']['position'], name = 'x', size = 250,
  697. range = (-1000, 1000), sliderHor = True,
  698. bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  699. self.FindWindowById(self.win['cplane']['position']['x']['slider']).SetValue(0)
  700. self.FindWindowById(self.win['cplane']['position']['x']['text']).SetValue(0)
  701. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['x']['slider']),
  702. pos = (0, 1), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  703. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['x']['text']),
  704. pos = (0, 2),
  705. flag = wx.ALIGN_CENTER)
  706. self._createControl(panel, data = self.win['cplane']['position'], name = 'y', size = 250,
  707. range = (-1000, 1000), sliderHor = True,
  708. bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  709. self.FindWindowById(self.win['cplane']['position']['y']['slider']).SetValue(0)
  710. self.FindWindowById(self.win['cplane']['position']['y']['text']).SetValue(0)
  711. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['y']['slider']),
  712. pos = (1, 1), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  713. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['y']['text']),
  714. pos = (1, 2),
  715. flag = wx.ALIGN_CENTER)
  716. self._createControl(panel, data = self.win['cplane']['position'], name = 'z', size = 250,
  717. range = (-1000, 1000), sliderHor = True,
  718. bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  719. self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetValue(0)
  720. self.FindWindowById(self.win['cplane']['position']['z']['text']).SetValue(0)
  721. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['z']['slider']),
  722. pos = (2, 1), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  723. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['z']['text']),
  724. pos = (2, 2),
  725. flag = wx.ALIGN_CENTER)
  726. # rotation
  727. self.win['cplane']['rotation'] = {}
  728. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  729. label = _("Rotation:")),
  730. pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  731. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  732. label = _("Tilt:")),
  733. pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  734. self._createControl(panel, data = self.win['cplane']['rotation'], name = 'rot', size = 250,
  735. range = (0, 360), sliderHor = True,
  736. bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  737. self.FindWindowById(self.win['cplane']['rotation']['rot']['slider']).SetValue(0)
  738. self.FindWindowById(self.win['cplane']['rotation']['rot']['text']).SetValue(0)
  739. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['rot']['slider']),
  740. pos = (3, 1), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  741. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['rot']['text']),
  742. pos = (3, 2),
  743. flag = wx.ALIGN_CENTER)
  744. self._createControl(panel, data = self.win['cplane']['rotation'], name = 'tilt', size = 250,
  745. range = (0, 360), sliderHor = True,
  746. bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  747. self.FindWindowById(self.win['cplane']['rotation']['tilt']['slider']).SetValue(0)
  748. self.FindWindowById(self.win['cplane']['rotation']['tilt']['text']).SetValue(0)
  749. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['tilt']['slider']),
  750. pos = (4, 1), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  751. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['tilt']['text']),
  752. pos = (4, 2),
  753. flag = wx.ALIGN_CENTER)
  754. boxSizer.Add(gridSizer, proportion = 0, flag = wx.EXPAND|wx.ALL, border = 5)
  755. horSizer = wx.BoxSizer(wx.HORIZONTAL)
  756. horSizer.Add(item = wx.Size(-1, -1), proportion = 1, flag = wx.ALL, border = 5)
  757. # reset
  758. reset = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Reset"))
  759. self.win['cplane']['reset'] = reset.GetId()
  760. reset.Bind(wx.EVT_BUTTON, self.OnCPlaneReset)
  761. horSizer.Add(item = reset, flag = wx.ALL, border = 5)
  762. boxSizer.Add(horSizer, proportion = 0, flag = wx.EXPAND)
  763. pageSizer.Add(boxSizer, proportion = 0, flag = wx.EXPAND)
  764. panel.SetSizer(pageSizer)
  765. panel.Fit()
  766. return panel
  767. def _createConstantPage(self, parent):
  768. """!Create constant page"""
  769. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  770. self.page['constant'] = { 'id' : 1,
  771. 'notebook' : self.foldpanelData.GetId() }
  772. self.win['constant'] = {}
  773. pageSizer = wx.BoxSizer(wx.VERTICAL)
  774. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  775. label = " %s " % (_("Constant surface")))
  776. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  777. horsizer = wx.BoxSizer(wx.HORIZONTAL)
  778. surface = wx.ComboBox(parent = panel, id = wx.ID_ANY,
  779. style = wx.CB_SIMPLE | wx.CB_READONLY,
  780. choices = [])
  781. self.win['constant']['surface'] = surface.GetId()
  782. surface.Bind(wx.EVT_COMBOBOX, self.OnConstantSelection)
  783. horsizer.Add(surface, proportion = 1, flag = wx.EXPAND|wx.RIGHT, border = 20)
  784. addNew = wx.Button(panel, id = wx.ID_ANY, label = _("New"))
  785. addNew.Bind(wx.EVT_BUTTON, self.OnNewConstant)
  786. self.win['constant']['new'] = addNew.GetId()
  787. delete = wx.Button(panel, id = wx.ID_ANY, label = _("Delete"))
  788. delete.Bind(wx.EVT_BUTTON, self.OnDeleteConstant)
  789. self.win['constant']['delete'] = delete.GetId()
  790. horsizer.Add(item = addNew, proportion = 0, flag = wx.RIGHT|wx.LEFT, border = 3)
  791. horsizer.Add(item = delete, proportion = 0, flag = wx.RIGHT|wx.LEFT, border = 3)
  792. boxSizer.Add(item = horsizer, proportion = 0, flag = wx.ALL|wx.EXPAND,
  793. border = 5)
  794. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  795. # fine resolution
  796. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  797. label = _("Fine resolution:")),
  798. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  799. resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  800. initial = 3,
  801. min = 1,
  802. max = 100)
  803. resF.SetName("value")
  804. self.win['constant']['resolution'] = resF.GetId()
  805. resF.Bind(wx.EVT_SPINCTRL, self.OnSetConstantProp)
  806. gridSizer.Add(item = resF, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  807. # value
  808. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  809. label = _("Value:")), pos = (1, 0),
  810. flag = wx.ALIGN_CENTER_VERTICAL)
  811. value = wx.SpinCtrl(panel, id = wx.ID_ANY,
  812. min = -1e9, max = 1e9,
  813. size = (65, -1))
  814. self.win['constant']['value'] = value.GetId()
  815. value.Bind(wx.EVT_SPINCTRL, self.OnSetConstantProp)
  816. gridSizer.Add(item = value, pos = (1, 1))
  817. # color
  818. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  819. label = _("Color:")), pos = (2, 0),
  820. flag = wx.ALIGN_CENTER_VERTICAL)
  821. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  822. colour = (0,0,0),
  823. size = globalvar.DIALOG_COLOR_SIZE)
  824. self.win['constant']['color'] = color.GetId()
  825. color.Bind(csel.EVT_COLOURSELECT, self.OnSetConstantProp)
  826. gridSizer.Add(item = color, pos = (2, 1))
  827. boxSizer.Add(item = gridSizer, proportion = 0, flag = wx.ALL,
  828. border = 5)
  829. pageSizer.Add(item = boxSizer, proportion = 0,
  830. flag = wx.EXPAND | wx.ALL,
  831. border = 3)
  832. panel.SetSizer(pageSizer)
  833. panel.Fit()
  834. return panel
  835. def _createVectorPage(self, parent):
  836. """!Create view settings page"""
  837. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  838. self.page['vector'] = { 'id' : 2,
  839. 'notebook' : self.foldpanelData.GetId() }
  840. pageSizer = wx.BoxSizer(wx.VERTICAL)
  841. self.win['vector'] = {}
  842. # selection
  843. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  844. label = " %s " % (_("Vector map")))
  845. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  846. vmaps = gselect.Select(parent = panel, type = 'vector',
  847. onPopup = self.GselectOnPopup)
  848. vmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetVector)
  849. self.win['vector']['map'] = vmaps.GetId()
  850. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  851. self.win['vector']['desc'] = desc.GetId()
  852. boxSizer.Add(item = vmaps, proportion = 0,
  853. flag = wx.ALL,
  854. border = 3)
  855. boxSizer.Add(item = desc, proportion = 0,
  856. flag = wx.ALL,
  857. border = 3)
  858. pageSizer.Add(item = boxSizer, proportion = 0,
  859. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  860. border = 3)
  861. #
  862. # vector lines
  863. #
  864. self.win['vector']['lines'] = {}
  865. showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  866. label = _("Show vector lines"))
  867. showLines.SetValue(True)
  868. self.win['vector']['lines']['show'] = showLines.GetId()
  869. showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  870. pageSizer.Add(item = showLines, proportion = 0,
  871. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  872. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  873. label = " %s " % (_("Vector lines")))
  874. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  875. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  876. gridSizer.AddGrowableCol(5)
  877. # width
  878. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  879. label = _("Line:")),
  880. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  881. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  882. label = _("width:")),
  883. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  884. wx.ALIGN_RIGHT)
  885. width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  886. initial = 1,
  887. min = 0,
  888. max = 100)
  889. width.SetValue(1)
  890. self.win['vector']['lines']['width'] = width.GetId()
  891. width.Bind(wx.EVT_SPINCTRL, self.OnVectorLines)
  892. gridSizer.Add(item = width, pos = (0, 2),
  893. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  894. # color
  895. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  896. label = _("color:")),
  897. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  898. wx.ALIGN_RIGHT)
  899. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  900. colour = (0,0,0),
  901. size = globalvar.DIALOG_COLOR_SIZE)
  902. self.win['vector']['lines']['color'] = color.GetId()
  903. color.Bind(csel.EVT_COLOURSELECT, self.OnVectorLines)
  904. gridSizer.Add(item = color, pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL |
  905. wx.ALIGN_LEFT)
  906. # display
  907. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  908. label = _("Display")),
  909. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL |
  910. wx.ALIGN_LEFT)
  911. display = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  912. choices = [_("on surface(s):"),
  913. _("flat")])
  914. self.win['vector']['lines']['flat'] = display.GetId()
  915. display.Bind(wx.EVT_CHOICE, self.OnVectorDisplay)
  916. gridSizer.Add(item = display, flag = wx.ALIGN_CENTER_VERTICAL |
  917. wx.ALIGN_LEFT|wx.EXPAND, pos = (1, 1), span = (1,4))
  918. # height
  919. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  920. label = _("Height above surface:")),
  921. pos = (2, 5), flag = wx.ALIGN_BOTTOM|wx.EXPAND)
  922. surface = wx.CheckListBox(parent = panel, id = wx.ID_ANY, size = (-1, 60),
  923. choices = [], style = wx.LB_NEEDED_SB)
  924. surface.Bind(wx.EVT_CHECKLISTBOX, self.OnVectorSurface)
  925. self.win['vector']['lines']['surface'] = surface.GetId()
  926. gridSizer.Add(item = surface,
  927. pos = (2, 0), span = (3, 5),
  928. flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
  929. self._createControl(panel, data = self.win['vector']['lines'], name = 'height', size = -1,
  930. range = (0, 500), sliderHor = True,
  931. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightText))
  932. self.FindWindowById(self.win['vector']['lines']['height']['slider']).SetValue(0)
  933. self.FindWindowById(self.win['vector']['lines']['height']['text']).SetValue(0)
  934. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['slider']),
  935. pos = (3, 5), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  936. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['text']),
  937. pos = (4, 5),
  938. flag = wx.ALIGN_CENTER)
  939. boxSizer.Add(item = gridSizer, proportion = 1,
  940. flag = wx.ALL | wx.EXPAND, border = 3)
  941. pageSizer.Add(item = boxSizer, proportion = 0,
  942. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  943. border = 3)
  944. #
  945. # vector points
  946. #
  947. self.win['vector']['points'] = {}
  948. showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  949. label = _("Show vector points"))
  950. showPoints.SetValue(True)
  951. self.win['vector']['points']['show'] = showPoints.GetId()
  952. showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  953. pageSizer.Add(item = showPoints, proportion = 0,
  954. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  955. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  956. label = " %s " % (_("Vector points")))
  957. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  958. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  959. gridSizer.AddGrowableCol(5)
  960. # icon size
  961. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  962. label = _("Icon:")),
  963. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  964. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  965. label = _("size:")),
  966. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  967. wx.ALIGN_RIGHT)
  968. isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  969. initial = 1,
  970. min = 1,
  971. max = 1e6)
  972. isize.SetName('value')
  973. isize.SetValue(100)
  974. self.win['vector']['points']['size'] = isize.GetId()
  975. isize.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  976. isize.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  977. gridSizer.Add(item = isize, pos = (0, 2),
  978. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  979. # icon color
  980. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  981. label = _("color:")),
  982. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  983. wx.ALIGN_RIGHT)
  984. icolor = csel.ColourSelect(panel, id = wx.ID_ANY,
  985. size = globalvar.DIALOG_COLOR_SIZE)
  986. icolor.SetName("color")
  987. icolor.SetColour((0,0,255))
  988. self.win['vector']['points']['color'] = icolor.GetId()
  989. icolor.Bind(csel.EVT_COLOURSELECT, self.OnVectorPoints)
  990. gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL |
  991. wx.ALIGN_LEFT,
  992. pos = (0, 4))
  993. # icon width
  994. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  995. label = _("width")),
  996. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  997. wx.ALIGN_RIGHT)
  998. iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  999. initial = 1,
  1000. min = 1,
  1001. max = 1e6)
  1002. iwidth.SetName('value')
  1003. iwidth.SetValue(100)
  1004. self.win['vector']['points']['width'] = iwidth.GetId()
  1005. iwidth.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  1006. iwidth.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  1007. gridSizer.Add(item = iwidth, pos = (1, 2),
  1008. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1009. # icon symbol
  1010. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1011. label = _("symbol:")),
  1012. pos = (1, 3), flag = wx.ALIGN_CENTER_VERTICAL)
  1013. isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  1014. choices = UserSettings.Get(group = 'nviz', key = 'vector',
  1015. subkey = ['points', 'marker'], internal = True))
  1016. isym.SetName("selection")
  1017. self.win['vector']['points']['marker'] = isym.GetId()
  1018. isym.Bind(wx.EVT_CHOICE, self.OnVectorPoints)
  1019. gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL,
  1020. pos = (1, 4))
  1021. # high
  1022. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1023. label = _("Display on surface(s):")),
  1024. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL,
  1025. span = (1, 5))
  1026. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1027. label = _("Height above surface:")),
  1028. pos = (3, 5), flag = wx.ALIGN_CENTER_VERTICAL)
  1029. surface = wx.CheckListBox(parent = panel, id = wx.ID_ANY, size = (-1, 60),
  1030. choices = [], style = wx.LB_NEEDED_SB)
  1031. surface.Bind(wx.EVT_CHECKLISTBOX, self.OnVectorSurface)
  1032. self.win['vector']['points']['surface'] = surface.GetId()
  1033. gridSizer.Add(item = surface,
  1034. pos = (3, 0), span = (3, 5),
  1035. flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
  1036. self._createControl(panel, data = self.win['vector']['points'], name = 'height', size = -1,
  1037. range = (0, 500),
  1038. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightText))
  1039. self.FindWindowById(self.win['vector']['points']['height']['slider']).SetValue(0)
  1040. self.FindWindowById(self.win['vector']['points']['height']['text']).SetValue(0)
  1041. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['slider']),
  1042. pos = (4, 5),flag = wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)
  1043. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['text']),
  1044. pos = (5, 5),
  1045. flag = wx.ALIGN_CENTER)
  1046. boxSizer.Add(item = gridSizer, proportion = 1,
  1047. flag = wx.ALL | wx.EXPAND, border = 3)
  1048. pageSizer.Add(item = boxSizer, proportion = 0,
  1049. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1050. border = 3)
  1051. panel.SetSizer(pageSizer)
  1052. panel.Fit()
  1053. return panel
  1054. def GselectOnPopup(self, ltype, exclude = False):
  1055. """Update gselect.Select() items"""
  1056. maps = list()
  1057. for layer in self.mapWindow.Map.GetListOfLayers(l_type = ltype, l_active = True):
  1058. maps.append(layer.GetName())
  1059. return maps, exclude
  1060. def _createVolumePage(self, parent):
  1061. """!Create view settings page"""
  1062. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1063. self.page['volume'] = { 'id' : 3,
  1064. 'notebook' : self.foldpanelData.GetId() }
  1065. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1066. self.win['volume'] = {}
  1067. # selection
  1068. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1069. label = " %s " % (_("3D raster map")))
  1070. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1071. rmaps = gselect.Select(parent = panel, type = 'raster3D',
  1072. onPopup = self.GselectOnPopup)
  1073. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster3D)
  1074. self.win['volume']['map'] = rmaps.GetId()
  1075. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  1076. self.win['volume']['desc'] = desc.GetId()
  1077. boxSizer.Add(item = rmaps, proportion = 0,
  1078. flag = wx.ALL,
  1079. border = 3)
  1080. boxSizer.Add(item = desc, proportion = 0,
  1081. flag = wx.ALL,
  1082. border = 3)
  1083. pageSizer.Add(item = boxSizer, proportion = 0,
  1084. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1085. border = 3)
  1086. #
  1087. # draw
  1088. #
  1089. self.win['volume']['draw'] = {}
  1090. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1091. label = " %s " % (_("Draw")))
  1092. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1093. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  1094. gridSizer.AddGrowableCol(4)
  1095. # mode
  1096. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1097. label = _("Mode:")),
  1098. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1099. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (150, -1),
  1100. choices = [_("isosurfaces"),
  1101. _("slides")])
  1102. mode.SetSelection(0)
  1103. mode.SetName("selection")
  1104. # mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  1105. self.win['volume']['draw']['mode'] = mode.GetId()
  1106. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
  1107. pos = (0, 1))
  1108. # shading
  1109. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1110. label = _("Shading:")),
  1111. pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  1112. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  1113. choices = [_("flat"),
  1114. _("gouraud")])
  1115. shade.SetName("selection")
  1116. self.win['volume']['draw']['shading'] = shade.GetId()
  1117. shade.Bind(wx.EVT_CHOICE, self.OnVolumeIsosurfMode)
  1118. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  1119. pos = (0, 3))
  1120. # resolution (mode)
  1121. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1122. label = _("Resolution:")),
  1123. pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL)
  1124. resol = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  1125. initial = 1,
  1126. min = 1,
  1127. max = 100)
  1128. resol.SetName("value")
  1129. self.win['volume']['draw']['resolution'] = resol.GetId()
  1130. resol.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfResolution)
  1131. resol.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfResolution)
  1132. gridSizer.Add(item = resol, pos = (0, 5))
  1133. boxSizer.Add(item = gridSizer, proportion = 1,
  1134. flag = wx.ALL | wx.EXPAND, border = 3)
  1135. pageSizer.Add(item = boxSizer, proportion = 0,
  1136. flag = wx.EXPAND | wx.ALL,
  1137. border = 3)
  1138. #
  1139. # manage isosurfaces
  1140. #
  1141. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1142. label = " %s " % (_("List of isosurfaces")))
  1143. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1144. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1145. # list
  1146. isolevel = wx.CheckListBox(parent = panel, id = wx.ID_ANY,
  1147. size = (300, 150))
  1148. self.Bind(wx.EVT_CHECKLISTBOX, self.OnVolumeIsosurfCheck, isolevel)
  1149. self.Bind(wx.EVT_LISTBOX, self.OnVolumeIsosurfSelect, isolevel)
  1150. self.win['volume']['isosurfs'] = isolevel.GetId()
  1151. gridSizer.Add(item = isolevel, pos = (0, 0), span = (4, 1))
  1152. # buttons (add, delete, move up, move down)
  1153. btnAdd = wx.Button(parent = panel, id = wx.ID_ADD)
  1154. self.win['volume']['btnIsosurfAdd'] = btnAdd.GetId()
  1155. btnAdd.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfAdd)
  1156. gridSizer.Add(item = btnAdd,
  1157. pos = (0, 1))
  1158. btnDelete = wx.Button(parent = panel, id = wx.ID_DELETE)
  1159. self.win['volume']['btnIsosurfDelete'] = btnDelete.GetId()
  1160. btnDelete.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfDelete)
  1161. btnDelete.Enable(False)
  1162. gridSizer.Add(item = btnDelete,
  1163. pos = (1, 1))
  1164. btnMoveUp = wx.Button(parent = panel, id = wx.ID_UP)
  1165. self.win['volume']['btnIsosurfMoveUp'] = btnMoveUp.GetId()
  1166. btnMoveUp.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveUp)
  1167. btnMoveUp.Enable(False)
  1168. gridSizer.Add(item = btnMoveUp,
  1169. pos = (2, 1))
  1170. btnMoveDown = wx.Button(parent = panel, id = wx.ID_DOWN)
  1171. self.win['volume']['btnIsosurfMoveDown'] = btnMoveDown.GetId()
  1172. btnMoveDown.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveDown)
  1173. btnMoveDown.Enable(False)
  1174. gridSizer.Add(item = btnMoveDown,
  1175. pos = (3, 1))
  1176. boxSizer.Add(item = gridSizer, proportion = 1,
  1177. flag = wx.ALL | wx.EXPAND, border = 3)
  1178. pageSizer.Add(item = boxSizer, proportion = 0,
  1179. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1180. border = 3)
  1181. #
  1182. # isosurface attributes
  1183. #
  1184. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1185. label = " %s " % (_("Isosurface attributes")))
  1186. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1187. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1188. self.win['volume']['attr'] = {}
  1189. row = 0
  1190. for code, attrb in (('topo', _("Topography level")),
  1191. ('color', _("Color")),
  1192. ('mask', _("Mask")),
  1193. ('transp', _("Transparency")),
  1194. ('shine', _("Shininess")),
  1195. ('emit', _("Emission"))):
  1196. self.win['volume'][code] = {}
  1197. # label
  1198. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1199. label = attrb + ':'),
  1200. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1201. if code != 'topo':
  1202. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  1203. choices = [_("map")])
  1204. else:
  1205. use = None
  1206. # check for required properties
  1207. if code not in ('topo', 'color', 'shine'):
  1208. use.Insert(item = _("unset"), pos = 0)
  1209. self.win['volume'][code]['required'] = False
  1210. else:
  1211. self.win['volume'][code]['required'] = True
  1212. if use and code != 'mask':
  1213. use.Append(item = _('constant'))
  1214. if use:
  1215. self.win['volume'][code]['use'] = use.GetId()
  1216. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  1217. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  1218. pos = (row, 1))
  1219. if code != 'topo':
  1220. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  1221. # size = globalvar.DIALOG_GSELECT_SIZE,
  1222. size = (200, -1),
  1223. type = "grid3")
  1224. self.win['volume'][code]['map'] = map.GetId() - 1 # FIXME
  1225. map.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  1226. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
  1227. pos = (row, 2))
  1228. else:
  1229. map = None
  1230. if code == 'color':
  1231. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  1232. colour = (0,0,0),
  1233. size = globalvar.DIALOG_COLOR_SIZE)
  1234. value.Bind(csel.EVT_COLOURSELECT, self.OnVolumeIsosurfMap)
  1235. elif code == 'mask':
  1236. value = None
  1237. else:
  1238. if code == 'topo':
  1239. size = (200, -1)
  1240. else:
  1241. size = (65, -1)
  1242. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = size,
  1243. initial = 0)
  1244. if code == 'topo':
  1245. value.SetRange(minVal = -1e9, maxVal = 1e9)
  1246. elif code in ('shine', 'transp', 'emit'):
  1247. value.SetRange(minVal = 0, maxVal = 255)
  1248. else:
  1249. value.SetRange(minVal = 0, maxVal = 100)
  1250. value.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfMap)
  1251. value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  1252. if value:
  1253. self.win['volume'][code]['const'] = value.GetId()
  1254. if code == 'topo':
  1255. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  1256. pos = (row, 2))
  1257. else:
  1258. value.Enable(False)
  1259. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  1260. pos = (row, 3))
  1261. else:
  1262. self.win['volume'][code]['const'] = None
  1263. if code != 'topo':
  1264. self.SetMapObjUseMap(nvizType = 'volume',
  1265. attrb = code) # -> enable map / disable constant
  1266. row += 1
  1267. boxSizer.Add(item = gridSizer, proportion = 1,
  1268. flag = wx.ALL | wx.EXPAND, border = 3)
  1269. pageSizer.Add(item = boxSizer, proportion = 0,
  1270. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1271. border = 3)
  1272. panel.SetSizer(pageSizer)
  1273. panel.Fit()
  1274. return panel
  1275. def _createLightPage(self, parent):
  1276. """!Create light page"""
  1277. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1278. self.page['light'] = { 'id' : 0,
  1279. 'notebook' : self.foldpanelAppear.GetId() }
  1280. self.win['light'] = {}
  1281. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1282. show = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1283. label = _("Show light model"))
  1284. show.Bind(wx.EVT_CHECKBOX, self.OnShowLightModel)
  1285. show.SetValue(True)
  1286. self._display.showLight = True
  1287. pageSizer.Add(item = show, proportion = 0,
  1288. flag = wx.ALL, border = 3)
  1289. ## surface = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1290. ## label = _("Follow source viewpoint"))
  1291. ## pageSizer.Add(item = surface, proportion = 0,
  1292. ## flag = wx.ALL, border = 3)
  1293. # position
  1294. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1295. label = " %s " % (_("Light source position")))
  1296. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1297. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1298. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1299. self._createCompass(panel = panel, sizer = posSizer, type = 'light')
  1300. pos = LightPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
  1301. mapwindow = self.mapWindow)
  1302. self.win['light']['position'] = pos.GetId()
  1303. posSizer.Add(item = pos,
  1304. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  1305. gridSizer.Add(item = posSizer, pos = (0, 0))
  1306. # height
  1307. self._createControl(panel, data = self.win['light'], name = 'z', sliderHor = False,
  1308. range = (0, 100),
  1309. bind = (self.OnLightChange, self.OnLightChanged, self.OnLightChange))
  1310. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1311. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  1312. pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
  1313. heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['slider']),
  1314. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  1315. heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['text']),
  1316. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  1317. wx.BOTTOM | wx.RIGHT, pos = (1, 1))
  1318. gridSizer.Add(item = heightSizer, pos = (0, 2), flag = wx.ALIGN_RIGHT)
  1319. boxSizer.Add(item = gridSizer, proportion = 1,
  1320. flag = wx.ALL | wx.EXPAND, border = 2)
  1321. pageSizer.Add(item = boxSizer, proportion = 0,
  1322. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1323. border = 3)
  1324. # position
  1325. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1326. label = " %s " % (_("Light color and intensity")))
  1327. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1328. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1329. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:")),
  1330. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1331. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  1332. colour = UserSettings.Get(group = 'nviz', key = 'light',
  1333. subkey = 'color'),
  1334. size = globalvar.DIALOG_COLOR_SIZE)
  1335. self.win['light']['color'] = color.GetId()
  1336. color.Bind(csel.EVT_COLOURSELECT, self.OnLightColor)
  1337. gridSizer.Add(item = color, pos = (0, 2))
  1338. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Brightness:")),
  1339. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1340. self._createControl(panel, data = self.win['light'], name = 'bright', size = 300,
  1341. range = (0, 100),
  1342. bind = (self.OnLightValue, self.OnLightChanged, self.OnLightValue))
  1343. gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['slider']),
  1344. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1345. gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['text']),
  1346. pos = (1, 2),
  1347. flag = wx.ALIGN_CENTER)
  1348. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Ambient:")),
  1349. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1350. self._createControl(panel, data = self.win['light'], name = 'ambient', size = 300,
  1351. range = (0, 100),
  1352. bind = (self.OnLightValue, self.OnLightChanged, self.OnLightValue))
  1353. gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['slider']),
  1354. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1355. gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['text']),
  1356. pos = (2, 2),
  1357. flag = wx.ALIGN_CENTER)
  1358. boxSizer.Add(item = gridSizer, proportion = 1,
  1359. flag = wx.ALL | wx.EXPAND, border = 2)
  1360. pageSizer.Add(item = boxSizer, proportion = 0,
  1361. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1362. border = 3)
  1363. # reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  1364. # reset.SetToolTipString(_("Reset to default view"))
  1365. # # self.win['reset'] = reset.GetId()
  1366. # reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  1367. # viewSizer.Add(item = reset, proportion = 1,
  1368. # flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT,
  1369. # border = 5)
  1370. # gridSizer.AddGrowableCol(3)
  1371. # gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
  1372. # flag = wx.EXPAND)
  1373. panel.SetSizer(pageSizer)
  1374. panel.Layout()
  1375. panel.Fit()
  1376. return panel
  1377. def _createFringePage(self, parent):
  1378. """!Create fringe page"""
  1379. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1380. self.page['fringe'] = { 'id' : 1,
  1381. 'notebook' : self.foldpanelAppear.GetId() }
  1382. self.win['fringe'] = {}
  1383. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1384. # selection
  1385. rbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1386. label = " %s " % (_("Surface")))
  1387. rboxSizer = wx.StaticBoxSizer(rbox, wx.VERTICAL)
  1388. rmaps = gselect.Select(parent = panel, type = 'raster',
  1389. onPopup = self.GselectOnPopup)
  1390. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetSurface)
  1391. self.win['fringe']['map'] = rmaps.GetId()
  1392. rboxSizer.Add(item = rmaps, proportion = 0,
  1393. flag = wx.ALL,
  1394. border = 3)
  1395. pageSizer.Add(item = rboxSizer, proportion = 0,
  1396. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1397. border = 3)
  1398. ebox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1399. label = " %s " % (_("Edges with fringe")))
  1400. eboxSizer = wx.StaticBoxSizer(ebox, wx.HORIZONTAL)
  1401. for edge in [(_("N && W"), "nw"),
  1402. (_("N && E"), "ne"),
  1403. (_("S && W"), "sw"),
  1404. (_("S && E"), "se")]:
  1405. chkbox = wx.CheckBox(parent = panel,
  1406. label = edge[0],
  1407. name = edge[1])
  1408. self.win['fringe'][edge[1]] = chkbox.GetId()
  1409. eboxSizer.Add(item = chkbox, proportion = 0,
  1410. flag = wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT, border = 5)
  1411. chkbox.Bind(wx.EVT_CHECKBOX, self.OnFringe)
  1412. pageSizer.Add(item = eboxSizer, proportion = 0,
  1413. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1414. border = 3)
  1415. sbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1416. label = " %s " % (_("Settings")))
  1417. sboxSizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
  1418. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  1419. # elevation
  1420. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1421. label = _("Elevation of fringe from bottom:")),
  1422. pos = (0, 0),
  1423. flag = wx.ALIGN_CENTER_VERTICAL)
  1424. spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
  1425. size = (65, -1), min = -1e6, max = 1e6)
  1426. spin.SetValue(UserSettings.Get(group = 'nviz', key = 'fringe', subkey = 'elev'))
  1427. spin.Bind(wx.EVT_SPINCTRL, self.OnFringe)
  1428. self.win['fringe']['elev'] = spin.GetId()
  1429. gridSizer.Add(item = spin, pos = (0, 1))
  1430. # color
  1431. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1432. label = _("Color:")),
  1433. pos = (1, 0),
  1434. flag = wx.ALIGN_CENTER_VERTICAL)
  1435. color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  1436. size = globalvar.DIALOG_COLOR_SIZE)
  1437. color.SetColour(UserSettings.Get(group = 'nviz', key = 'fringe',
  1438. subkey = 'color'))
  1439. color.Bind(csel.EVT_COLOURSELECT, self.OnFringe)
  1440. self.win['fringe']['color'] = color.GetId()
  1441. gridSizer.Add(item = color, pos = (1, 1))
  1442. sboxSizer.Add(item = gridSizer, proportion = 1,
  1443. flag = wx.ALL | wx.EXPAND, border = 3)
  1444. pageSizer.Add(item = sboxSizer, proportion = 0,
  1445. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1446. border = 3)
  1447. panel.SetSizer(pageSizer)
  1448. panel.Layout()
  1449. panel.Fit()
  1450. return panel
  1451. def GetLayerData(self, nvizType):
  1452. """!Get nviz data"""
  1453. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1454. if nvizType == 'surface' or nvizType == 'fringe':
  1455. return self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1456. elif nvizType == 'vector':
  1457. return self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')
  1458. elif nvizType == 'volume':
  1459. return self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  1460. return None
  1461. def OnNewConstant(self, event):
  1462. """!Create new surface with constant value"""
  1463. #TODO settings
  1464. name = self.mapWindow.NewConstant()
  1465. win = self.FindWindowById(self.win['constant']['surface'])
  1466. name = _("constant#") + str(name)
  1467. win.Append(name)
  1468. win.SetStringSelection(name)
  1469. self.OnConstantSelection(None)
  1470. self.EnablePage(name = 'constant', enabled = True)
  1471. self.mapWindow.Refresh(eraseBackground = False)
  1472. # need to update list of surfaces in vector page
  1473. for vtype in ('points', 'lines'):
  1474. checklist = self.FindWindowById(self.win['vector'][vtype]['surface'])
  1475. checklist.Append(name)
  1476. win = self.FindWindowById(self.win['vector']['map'])
  1477. win.SetValue(win.GetValue())
  1478. def OnDeleteConstant(self, event):
  1479. """!Delete selected constant surface"""
  1480. layerIdx = self.FindWindowById(self.win['constant']['surface']).GetSelection()
  1481. if layerIdx == wx.NOT_FOUND:
  1482. return
  1483. name = self.FindWindowById(self.win['constant']['surface']).GetStringSelection()
  1484. self.mapWindow.DeleteConstant(layerIdx)
  1485. win = self.FindWindowById(self.win['constant']['surface'])
  1486. win.Delete(layerIdx)
  1487. if win.IsEmpty():
  1488. win.SetValue("")
  1489. self.EnablePage(name = 'constant', enabled = False)
  1490. else:
  1491. win.SetSelection(0)
  1492. self.OnConstantSelection(None)
  1493. # need to update list of surfaces in vector page
  1494. for vtype in ('points', 'lines'):
  1495. checklist = self.FindWindowById(self.win['vector'][vtype]['surface'])
  1496. checklist.Delete(checklist.FindString(name))
  1497. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1498. self.mapWindow.Refresh(False)
  1499. def OnConstantSelection(self, event):
  1500. """!Constant selected"""
  1501. layerIdx = self.FindWindowById(self.win['constant']['surface']).GetSelection()
  1502. if layerIdx == wx.NOT_FOUND:
  1503. return
  1504. name = _("constant#") + str(layerIdx + 1)
  1505. data = self.mapWindow.constants[layerIdx]
  1506. for attr, value in data['constant'].iteritems():
  1507. if attr == 'color':
  1508. value = self._getColorFromString(value)
  1509. if attr in ('color', 'value', 'resolution'):
  1510. self.FindWindowById(self.win['constant'][attr]).SetValue(value)
  1511. def OnSetConstantProp(self, event):
  1512. """!Change properties (color, value, resolution)
  1513. of currently selected constant surface"""
  1514. layerIdx = self.FindWindowById(self.win['constant']['surface']).GetSelection()
  1515. if layerIdx == wx.NOT_FOUND:
  1516. return
  1517. data = self.mapWindow.constants[layerIdx]
  1518. for attr in ('resolution', 'value'):
  1519. data['constant'][attr] = self.FindWindowById(self.win['constant'][attr]).GetValue()
  1520. data['constant']['color'] = self._getColorString(
  1521. self.FindWindowById(self.win['constant']['color']).GetValue())
  1522. # update properties
  1523. event = wxUpdateProperties(data = data)
  1524. wx.PostEvent(self.mapWindow, event)
  1525. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1526. self.mapWindow.Refresh(False)
  1527. def OnFringe(self, event):
  1528. """!Show/hide fringe"""
  1529. data = self.GetLayerData('fringe')['surface']
  1530. sid = data['object']['id']
  1531. elev = self.FindWindowById(self.win['fringe']['elev']).GetValue()
  1532. color = self.FindWindowById(self.win['fringe']['color']).GetValue()
  1533. self._display.SetFringe(sid, color, elev,
  1534. self.FindWindowById(self.win['fringe']['nw']).IsChecked(),
  1535. self.FindWindowById(self.win['fringe']['ne']).IsChecked(),
  1536. self.FindWindowById(self.win['fringe']['sw']).IsChecked(),
  1537. self.FindWindowById(self.win['fringe']['se']).IsChecked())
  1538. self.mapWindow.Refresh(False)
  1539. def OnScroll(self, event, win, data):
  1540. """!Generic scrolling handler"""
  1541. winName = self.__GetWindowName(win, event.GetId())
  1542. if not winName:
  1543. return
  1544. data[winName] = self.FindWindowById(event.GetId()).GetValue()
  1545. for w in win[winName].itervalues():
  1546. self.FindWindowById(w).SetValue(data[winName])
  1547. event.Skip()
  1548. def AdjustSliderRange(self, slider, value):
  1549. minim, maxim = slider.GetRange()
  1550. if not (minim <= value <= maxim):
  1551. slider.SetRange(min(minim, value), max(maxim, value))
  1552. def _createControl(self, parent, data, name, range, bind = (None, None, None),
  1553. sliderHor = True, size = 200):
  1554. """!Add control (Slider + TextCtrl)"""
  1555. data[name] = dict()
  1556. if sliderHor:
  1557. style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  1558. wx.SL_BOTTOM
  1559. sizeW = (size, -1)
  1560. else:
  1561. style = wx.SL_VERTICAL | wx.SL_AUTOTICKS | \
  1562. wx.SL_INVERSE
  1563. sizeW = (-1, size)
  1564. slider = wx.Slider(parent = parent, id = wx.ID_ANY,
  1565. minValue = range[0],
  1566. maxValue = range[1],
  1567. style = style,
  1568. size = sizeW)
  1569. slider.SetName('slider')
  1570. if bind[0]:
  1571. #EVT_SCROLL emits event after slider is released, EVT_SPIN not
  1572. slider.Bind(wx.EVT_SPIN, bind[0])
  1573. if bind[1]:
  1574. slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, bind[1])
  1575. data[name]['slider'] = slider.GetId()
  1576. text = NumTextCtrl(parent = parent, id = wx.ID_ANY, size = (65, -1),
  1577. style = wx.TE_PROCESS_ENTER)
  1578. text.SetName('text')
  1579. if bind[2]:
  1580. text.Bind(wx.EVT_TEXT_ENTER, bind[2])
  1581. text.Bind(wx.EVT_KILL_FOCUS, bind[2])
  1582. data[name]['text'] = text.GetId()
  1583. def _createCompass(self, panel, sizer, type):
  1584. """!Create 'compass' widget for light and view page"""
  1585. w = wx.Button(panel, id = wx.ID_ANY, label = _("W"))
  1586. n = wx.Button(panel, id = wx.ID_ANY, label = _("N"))
  1587. s = wx.Button(panel, id = wx.ID_ANY, label = _("S"))
  1588. e = wx.Button(panel, id = wx.ID_ANY, label = _("E"))
  1589. nw = wx.Button(panel, id = wx.ID_ANY, label = _("NW"))
  1590. ne = wx.Button(panel, id = wx.ID_ANY, label = _("NE"))
  1591. se = wx.Button(panel, id = wx.ID_ANY, label = _("SE"))
  1592. sw = wx.Button(panel, id = wx.ID_ANY, label = _("SW"))
  1593. minWidth = sw.GetTextExtent(sw.GetLabel())[0] + 15
  1594. for win, name in zip((w, n, s, e, nw, ne, se, sw),
  1595. ('w', 'n', 's', 'e', 'nw', 'ne', 'se', 'sw')):
  1596. win.SetMinSize((minWidth, -1))
  1597. win.Bind(wx.EVT_BUTTON, self.OnLookFrom)
  1598. win.SetName(type + '_' + name)
  1599. sizer.Add(item = nw, pos = (0, 0), flag = wx.ALIGN_CENTER)
  1600. sizer.Add(item = n, pos = (0, 1), flag = wx.ALIGN_CENTER)
  1601. sizer.Add(item = ne, pos = (0, 2), flag = wx.ALIGN_CENTER)
  1602. sizer.Add(item = e, pos = (1, 2), flag = wx.ALIGN_CENTER)
  1603. sizer.Add(item = se, pos = (2, 2), flag = wx.ALIGN_CENTER)
  1604. sizer.Add(item = s, pos = (2, 1), flag = wx.ALIGN_CENTER)
  1605. sizer.Add(item = sw, pos = (2, 0), flag = wx.ALIGN_CENTER)
  1606. sizer.Add(item = w, pos = (1, 0), flag = wx.ALIGN_CENTER)
  1607. def __GetWindowName(self, data, id):
  1608. for name in data.iterkeys():
  1609. if type(data[name]) is type({}):
  1610. for win in data[name].itervalues():
  1611. if win == id:
  1612. return name
  1613. else:
  1614. if data[name] == id:
  1615. return name
  1616. return None
  1617. def UpdateSettings(self):
  1618. """!Update view from settings values
  1619. stored in self.mapWindow.view dictionary"""
  1620. for control in ('height',
  1621. 'persp',
  1622. 'twist',
  1623. 'z-exag'):
  1624. for win in self.win['view'][control].itervalues():
  1625. try:
  1626. if control == 'height':
  1627. value = self.mapWindow.iview[control]['value']
  1628. else:
  1629. value = self.mapWindow.view[control]['value']
  1630. except KeyError:
  1631. value = -1
  1632. self.FindWindowById(win).SetValue(value)
  1633. viewWin = self.FindWindowById(self.win['view']['position'])
  1634. x, y = viewWin.UpdatePos(self.mapWindow.view['position']['x'],
  1635. self.mapWindow.view['position']['y'])
  1636. viewWin.Draw(pos = (x, y), scale = True)
  1637. viewWin.Refresh(False)
  1638. color = self._getColorString(self.mapWindow.view['background']['color'])
  1639. self._display.SetBgColor(str(color))
  1640. self.Update()
  1641. self.mapWindow.Refresh(eraseBackground = False)
  1642. self.mapWindow.render['quick'] = False
  1643. self.mapWindow.Refresh(True)
  1644. def OnShowLightModel(self, event):
  1645. """!Show light model"""
  1646. self._display.showLight = event.IsChecked()
  1647. self._display.DrawLightingModel()
  1648. def OnLightChange(self, event):
  1649. """!Position of the light changed"""
  1650. winName = self.__GetWindowName(self.win['light'], event.GetId())
  1651. if not winName:
  1652. return
  1653. value = self.FindWindowById(event.GetId()).GetValue()
  1654. self.mapWindow.light['position']['z'] = value
  1655. for win in self.win['light'][winName].itervalues():
  1656. self.FindWindowById(win).SetValue(value)
  1657. event = wxUpdateLight()
  1658. wx.PostEvent(self.mapWindow, event)
  1659. event.Skip()
  1660. def OnLightChanged(self, event):
  1661. """!Light"""
  1662. self.mapWindow.Refresh(False)
  1663. def OnLightColor(self, event):
  1664. """!Color of the light changed"""
  1665. self.mapWindow.light['color'] = tuple(event.GetValue())
  1666. event = wxUpdateLight(refresh = True)
  1667. wx.PostEvent(self.mapWindow, event)
  1668. event.Skip()
  1669. def OnLightValue(self, event):
  1670. """!Light brightness changed"""
  1671. data = self.mapWindow.light
  1672. self.OnScroll(event, self.win['light'], data)
  1673. event = wxUpdateLight()
  1674. wx.PostEvent(self.mapWindow, event)
  1675. event.Skip()
  1676. def OnBgColor(self, event):
  1677. """!Background color changed"""
  1678. color = event.GetValue()
  1679. self.mapWindow.view['background']['color'] = tuple(color)
  1680. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1681. self._display.SetBgColor(str(color))
  1682. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1683. self.mapWindow.Refresh(False)
  1684. def OnSetSurface(self, event):
  1685. """!Surface selected, currently used for fringes"""
  1686. name = event.GetString()
  1687. try:
  1688. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
  1689. except:
  1690. self.EnablePage('fringe', False)
  1691. return
  1692. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  1693. self.EnablePage('fringe', True)
  1694. def OnSetRaster(self, event):
  1695. """!Raster map selected, update surface page"""
  1696. name = event.GetString()
  1697. try:
  1698. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
  1699. except:
  1700. self.EnablePage('surface', False)
  1701. return
  1702. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  1703. self.EnablePage('surface', True)
  1704. self.UpdateSurfacePage(layer, data, updateName = False)
  1705. def OnSetVector(self, event):
  1706. """!Vector map selected, update properties page"""
  1707. name = event.GetString()
  1708. try:
  1709. data = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')['vector']
  1710. except:
  1711. self.EnablePage('vector', False)
  1712. return
  1713. layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
  1714. self.EnablePage('vector', True)
  1715. self.UpdateVectorPage(layer, data, updateName = False)
  1716. def OnSetRaster3D(self, event):
  1717. """!3D Raster map selected, update surface page"""
  1718. name = event.GetString()
  1719. try:
  1720. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')['volume']
  1721. except:
  1722. self.EnablePage('volume', False)
  1723. return
  1724. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  1725. self.EnablePage('volume', True)
  1726. self.UpdateVolumePage(layer, data, updateName = False)
  1727. def OnViewChange(self, event):
  1728. """!Change view, render in quick mode"""
  1729. # find control
  1730. winName = self.__GetWindowName(self.win['view'], event.GetId())
  1731. if not winName:
  1732. return
  1733. value = self.FindWindowById(event.GetId()).GetValue()
  1734. slider = self.FindWindowById(self.win['view'][winName]['slider'])
  1735. self.AdjustSliderRange(slider = slider, value = value)
  1736. if winName == 'height':
  1737. view = self.mapWindow.iview # internal
  1738. else:
  1739. view = self.mapWindow.view
  1740. if winName == 'z-exag' and value >= 0:
  1741. self.PostViewEvent(zExag = True)
  1742. else:
  1743. self.PostViewEvent(zExag = False)
  1744. view[winName]['value'] = value
  1745. for win in self.win['view'][winName].itervalues():
  1746. self.FindWindowById(win).SetValue(value)
  1747. self.mapWindow.render['quick'] = True
  1748. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1749. self.mapWindow.Refresh(False)
  1750. event.Skip()
  1751. def OnViewChanged(self, event):
  1752. """!View changed, render in full resolution"""
  1753. self.mapWindow.render['quick'] = False
  1754. self.mapWindow.Refresh(False)
  1755. self.UpdateSettings()
  1756. try:# when calling event = None
  1757. event.Skip()
  1758. except AttributeError:
  1759. pass
  1760. def OnViewChangedText(self, event):
  1761. """!View changed, render in full resolution"""
  1762. self.mapWindow.render['quick'] = False
  1763. self.OnViewChange(event)
  1764. self.OnViewChanged(None)
  1765. self.Update()
  1766. event.Skip()
  1767. def OnLookAt(self, event):
  1768. """!Look here/center"""
  1769. name = self.FindWindowById(event.GetId()).GetName()
  1770. if name == 'center':
  1771. self._display.LookAtCenter()
  1772. focus = self.mapWindow.iview['focus']
  1773. focus['x'], focus['y'], focus['z'] = self._display.GetFocus()
  1774. self.mapWindow.Refresh(False)
  1775. elif name == 'top':
  1776. self.mapWindow.view['position']['x'] = 0.5
  1777. self.mapWindow.view['position']['y'] = 0.5
  1778. self.PostViewEvent(zExag = True)
  1779. self.UpdateSettings()
  1780. self.mapWindow.Refresh(False)
  1781. else: # here
  1782. if self.FindWindowById(event.GetId()).GetValue():
  1783. self.mapWindow.mouse['use'] = 'lookHere'
  1784. self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
  1785. else:
  1786. self.mapWindow.mouse['use'] = 'default'
  1787. self.mapWindow.SetCursor(self.mapWindow.cursors['default'])
  1788. def OnResetView(self, event):
  1789. """!Reset to default view (view page)"""
  1790. self.mapWindow.ResetView()
  1791. self.UpdateSettings()
  1792. self.mapWindow.Refresh(False)
  1793. def OnResetSurfacePosition(self, event):
  1794. """!Reset position of surface"""
  1795. for win in self.win['surface']['position'].itervalues():
  1796. if win == self.win['surface']['position']['axis']:
  1797. self.FindWindowById(win).SetSelection(0)
  1798. else:
  1799. self.FindWindowById(win).SetValue(0)
  1800. data = self.GetLayerData('surface')
  1801. data['surface']['position']['x'] = 0
  1802. data['surface']['position']['y'] = 0
  1803. data['surface']['position']['z'] = 0
  1804. data['surface']['position']['update'] = None
  1805. # update properties
  1806. event = wxUpdateProperties(data = data)
  1807. wx.PostEvent(self.mapWindow, event)
  1808. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1809. self.mapWindow.Refresh(False)
  1810. def OnLookFrom(self, event):
  1811. """!Position of view/light changed by buttons"""
  1812. name = self.FindWindowById(event.GetId()).GetName()
  1813. buttonName = name.split('_')[1]
  1814. if name.split('_')[0] == 'view':
  1815. type = 'view'
  1816. data = self.mapWindow.view
  1817. else:
  1818. type = 'light'
  1819. data = self.mapWindow.light
  1820. if buttonName == 'n': # north
  1821. data['position']['x'] = 0.5
  1822. data['position']['y'] = 0.0
  1823. elif buttonName == 's': # south
  1824. data['position']['x'] = 0.5
  1825. data['position']['y'] = 1.0
  1826. elif buttonName == 'e': # east
  1827. data['position']['x'] = 1.0
  1828. data['position']['y'] = 0.5
  1829. elif buttonName =='w': # west
  1830. data['position']['x'] = 0.0
  1831. data['position']['y'] = 0.5
  1832. elif buttonName == 'nw': # north-west
  1833. data['position']['x'] = 0.0
  1834. data['position']['y'] = 0.0
  1835. elif buttonName == 'ne': # north-east
  1836. data['position']['x'] = 1.0
  1837. data['position']['y'] = 0.0
  1838. elif buttonName == 'se': # south-east
  1839. data['position']['x'] = 1.0
  1840. data['position']['y'] = 1.0
  1841. elif buttonName == 'sw': # south-west
  1842. data['position']['x'] = 0.0
  1843. data['position']['y'] = 1.0
  1844. if type == 'view':
  1845. self.PostViewEvent(zExag = True)
  1846. self.UpdateSettings()
  1847. else:
  1848. event = wxUpdateLight()
  1849. wx.PostEvent(self.mapWindow, event)
  1850. lightWin = self.FindWindowById(self.win['light']['position'])
  1851. x, y = lightWin.UpdatePos(self.mapWindow.light['position']['x'],
  1852. self.mapWindow.light['position']['y'])
  1853. lightWin.Draw(pos = (x, y), scale = True)
  1854. lightWin.Refresh(False)
  1855. self.mapWindow.render['quick'] = False
  1856. self.mapWindow.Refresh(False)
  1857. def OnMapObjUse(self, event):
  1858. """!Set surface attribute -- use -- map/constant"""
  1859. if not self.mapWindow.init:
  1860. return
  1861. wx.Yield()
  1862. # find attribute row
  1863. attrb = self.__GetWindowName(self.win['surface'], event.GetId())
  1864. if not attrb:
  1865. attrb = self.__GetWindowName(self.win['volume'], event.GetId())
  1866. nvizType = 'volume'
  1867. else:
  1868. nvizType = 'surface'
  1869. selection = event.GetSelection()
  1870. if self.win[nvizType][attrb]['required']: # no 'unset'
  1871. selection += 1
  1872. if selection == 0: # unset
  1873. useMap = None
  1874. value = ''
  1875. elif selection == 1: # map
  1876. useMap = True
  1877. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1878. elif selection == 2: # constant
  1879. useMap = False
  1880. if attrb == 'color':
  1881. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1882. value = self._getColorString(value)
  1883. else:
  1884. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  1885. self.SetMapObjUseMap(nvizType = nvizType,
  1886. attrb = attrb, map = useMap)
  1887. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1888. if nvizType == 'surface':
  1889. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1890. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  1891. 'value' : str(value),
  1892. 'update' : None }
  1893. else: # volume / isosurface
  1894. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  1895. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1896. id = list.GetSelection()
  1897. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  1898. 'value' : str(value),
  1899. 'update' : None }
  1900. # update properties
  1901. event = wxUpdateProperties(data = data)
  1902. wx.PostEvent(self.mapWindow, event)
  1903. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1904. self.mapWindow.Refresh(False)
  1905. def EnablePage(self, name, enabled = True):
  1906. """!Enable/disable all widgets on page"""
  1907. for key, item in self.win[name].iteritems():
  1908. if key in ('map', 'surface', 'new','planes'):
  1909. continue
  1910. if type(item) == types.DictType:
  1911. for skey, sitem in self.win[name][key].iteritems():
  1912. if type(sitem) == types.DictType:
  1913. for ssitem in self.win[name][key][skey].itervalues():
  1914. if type(ssitem) == types.IntType:
  1915. self.FindWindowById(ssitem).Enable(enabled)
  1916. else:
  1917. if type(sitem) == types.IntType:
  1918. self.FindWindowById(sitem).Enable(enabled)
  1919. else:
  1920. if type(item) == types.IntType:
  1921. self.FindWindowById(item).Enable(enabled)
  1922. def SetMapObjUseMap(self, nvizType, attrb, map = None):
  1923. """!Update dialog widgets when attribute type changed"""
  1924. if attrb in ('topo', 'color', 'shine'):
  1925. incSel = -1 # decrement selection (no 'unset')
  1926. else:
  1927. incSel = 0
  1928. if map is True: # map
  1929. if attrb != 'topo': # changing map topography not allowed
  1930. # not sure why, but here must be disabled both ids, should be fixed!
  1931. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(True)
  1932. if self.win[nvizType][attrb]['const']:
  1933. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  1934. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(1 + incSel)
  1935. elif map is False: # const
  1936. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  1937. if self.win[nvizType][attrb]['const']:
  1938. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(True)
  1939. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(2 + incSel)
  1940. else: # unset
  1941. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  1942. if self.win[nvizType][attrb]['const']:
  1943. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  1944. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(0)
  1945. def OnSurfaceMap(self, event):
  1946. """!Set surface attribute"""
  1947. if self.vetoGSelectEvt:
  1948. self.vetoGSelectEvt = False
  1949. return
  1950. self.SetMapObjAttrb(nvizType = 'surface', winId = event.GetId())
  1951. def SetMapObjAttrb(self, nvizType, winId):
  1952. """!Set map object (surface/isosurface) attribute (map/constant)"""
  1953. if not self.mapWindow.init:
  1954. return
  1955. attrb = self.__GetWindowName(self.win[nvizType], winId)
  1956. if not attrb:
  1957. return
  1958. if nvizType == 'volume' and attrb == 'topo':
  1959. return
  1960. selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
  1961. if self.win[nvizType][attrb]['required']:
  1962. selection += 1
  1963. if selection == 0: # unset
  1964. useMap = None
  1965. value = ''
  1966. elif selection == 1: # map
  1967. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1968. useMap = True
  1969. else: # constant
  1970. if attrb == 'color':
  1971. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1972. # tuple to string
  1973. value = self._getColorString(value)
  1974. else:
  1975. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  1976. useMap = False
  1977. if not self.pageChanging:
  1978. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1979. if nvizType == 'surface':
  1980. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1981. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  1982. 'value' : str(value),
  1983. 'update' : None }
  1984. else:
  1985. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  1986. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1987. id = list.GetSelection()
  1988. if id > -1:
  1989. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  1990. 'value' : str(value),
  1991. 'update' : None }
  1992. # update properties
  1993. event = wxUpdateProperties(data = data)
  1994. wx.PostEvent(self.mapWindow, event)
  1995. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1996. self.mapWindow.Refresh(False)
  1997. def OnSurfaceResolution(self, event):
  1998. """!Draw resolution changed"""
  1999. self.SetSurfaceResolution()
  2000. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2001. self.mapWindow.Refresh(False)
  2002. def SetSurfaceResolution(self):
  2003. """!Set draw resolution"""
  2004. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  2005. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  2006. data = self.GetLayerData('surface')
  2007. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  2008. 'fine' : fine,
  2009. 'update' : None }
  2010. # update properties
  2011. event = wxUpdateProperties(data = data)
  2012. wx.PostEvent(self.mapWindow, event)
  2013. def SetSurfaceMode(self):
  2014. """!Set draw mode"""
  2015. mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
  2016. style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
  2017. if style == 0: # wire
  2018. self.FindWindowById(self.win['surface']['draw']['wire-color']).Enable(True)
  2019. elif style == 1: # surface
  2020. self.FindWindowById(self.win['surface']['draw']['wire-color']).Enable(False)
  2021. shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
  2022. value, desc = self.mapWindow.nvizDefault.GetDrawMode(mode, style, shade)
  2023. return value, desc
  2024. def OnSurfaceMode(self, event):
  2025. """!Set draw mode"""
  2026. value, desc = self.SetSurfaceMode()
  2027. data = self.GetLayerData('surface')
  2028. data['surface']['draw']['mode'] = { 'value' : value,
  2029. 'desc' : desc,
  2030. 'update' : None }
  2031. # update properties
  2032. event = wxUpdateProperties(data = data)
  2033. wx.PostEvent(self.mapWindow, event)
  2034. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2035. self.mapWindow.Refresh(False)
  2036. def OnSurfaceModeAll(self, event):
  2037. """!Set draw mode (including wire color) for all loaded surfaces"""
  2038. value, desc = self.SetSurfaceMode()
  2039. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  2040. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  2041. color = self.FindWindowById(self.win['surface']['draw']['wire-color']).GetColour()
  2042. cvalue = self._getColorString(color)
  2043. for name in self.mapWindow.GetLayerNames(type = 'raster'):
  2044. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  2045. if not data:
  2046. continue # shouldy no happen
  2047. data['surface']['draw']['all'] = True
  2048. data['surface']['draw']['mode'] = { 'value' : value,
  2049. 'desc' : desc,
  2050. 'update' : None }
  2051. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  2052. 'fine' : fine,
  2053. 'update' : None }
  2054. data['surface']['draw']['wire-color'] = { 'value' : cvalue,
  2055. 'update' : None }
  2056. # update properties
  2057. event = wxUpdateProperties(data = data)
  2058. wx.PostEvent(self.mapWindow, event)
  2059. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2060. self.mapWindow.Refresh(False)
  2061. def _getColorString(self, color):
  2062. """!change color to R:G:B format"""
  2063. return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2064. def _getColorFromString(self, color, delim = ':'):
  2065. """!change color from R:G:B format to wx.Color"""
  2066. return wx.Color(*map(int, color.split(delim)))
  2067. def OnSurfaceWireColor(self, event):
  2068. """!Set wire color"""
  2069. data = self.GetLayerData('surface')
  2070. value = self._getColorString(event.GetValue())
  2071. data['surface']['draw']['wire-color'] = { 'value' : value,
  2072. 'update' : None }
  2073. # update properties
  2074. event = wxUpdateProperties(data = data)
  2075. wx.PostEvent(self.mapWindow, event)
  2076. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2077. self.mapWindow.Refresh(False)
  2078. def OnSurfaceAxis(self, event):
  2079. """!Surface position, axis changed"""
  2080. data = self.GetLayerData('surface')
  2081. id = data['surface']['object']['id']
  2082. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  2083. slider = self.FindWindowById(self.win['surface']['position']['slider'])
  2084. text = self.FindWindowById(self.win['surface']['position']['text'])
  2085. x, y, z = self._display.GetSurfacePosition(id)
  2086. if axis == 0: # x
  2087. slider.SetValue(x)
  2088. text.SetValue(x)
  2089. elif axis == 1: # y
  2090. slider.SetValue(y)
  2091. text.SetValue(y)
  2092. else: # z
  2093. slider.SetValue(z)
  2094. text.SetValue(z)
  2095. def OnSurfacePosition(self, event):
  2096. """!Surface position"""
  2097. winName = self.__GetWindowName(self.win['surface'], event.GetId())
  2098. if not winName:
  2099. return
  2100. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  2101. value = self.FindWindowById(event.GetId()).GetValue()
  2102. slider = self.FindWindowById(self.win['surface'][winName]['slider'])
  2103. self.AdjustSliderRange(slider = slider, value = value)
  2104. for win in self.win['surface']['position'].itervalues():
  2105. if win == self.win['surface']['position']['axis']:
  2106. continue
  2107. else:
  2108. self.FindWindowById(win).SetValue(value)
  2109. data = self.GetLayerData('surface')
  2110. id = data['surface']['object']['id']
  2111. x, y, z = self._display.GetSurfacePosition(id)
  2112. if axis == 0: # x
  2113. x = value
  2114. elif axis == 1: # y
  2115. y = value
  2116. else: # z
  2117. z = value
  2118. data['surface']['position']['x'] = x
  2119. data['surface']['position']['y'] = y
  2120. data['surface']['position']['z'] = z
  2121. data['surface']['position']['update'] = None
  2122. # update properties
  2123. event = wxUpdateProperties(data = data)
  2124. wx.PostEvent(self.mapWindow, event)
  2125. self.mapWindow.render['quick'] = True
  2126. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2127. self.mapWindow.Refresh(False)
  2128. # self.UpdatePage('surface')
  2129. def OnSurfacePositionChanged(self, event):
  2130. """!Surface position changed"""
  2131. self.mapWindow.render['quick'] = False
  2132. self.mapWindow.Refresh(False)
  2133. def UpdateVectorShow(self, vecType, enabled):
  2134. """!Enable/disable lines/points widgets
  2135. @param vecType vector type (lines, points)
  2136. """
  2137. if vecType != 'lines' and vecType != 'points':
  2138. return False
  2139. for win in self.win['vector'][vecType].keys():
  2140. if win == 'show':
  2141. continue
  2142. if type(self.win['vector'][vecType][win]) == type({}):
  2143. for swin in self.win['vector'][vecType][win].keys():
  2144. if enabled:
  2145. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
  2146. else:
  2147. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
  2148. else:
  2149. if enabled:
  2150. self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
  2151. else:
  2152. self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
  2153. return True
  2154. def OnVectorShow(self, event):
  2155. """!Show vector lines/points"""
  2156. winId = event.GetId()
  2157. if winId == self.win['vector']['lines']['show']:
  2158. vecType = 'lines'
  2159. points = False
  2160. else: # points
  2161. vecType = 'points'
  2162. points = True
  2163. checked = event.IsChecked()
  2164. name = self.FindWindowById(self.win['vector']['map']).GetValue()
  2165. item = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'item')
  2166. data = self.GetLayerData('vector')['vector']
  2167. if checked:
  2168. self.mapWindow.LoadVector(item, points = points)
  2169. else:
  2170. self.mapWindow.UnloadVector(item, points = points)
  2171. self.UpdateVectorShow(vecType, checked)
  2172. if checked:
  2173. try:
  2174. id = data[vecType]['object']['id']
  2175. except KeyError:
  2176. id = -1
  2177. if id > 0:
  2178. self.mapWindow.SetMapObjProperties(item, id, vecType)
  2179. # update properties
  2180. event = wxUpdateProperties(data = data)
  2181. wx.PostEvent(self.mapWindow, event)
  2182. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2183. self.mapWindow.Refresh(False)
  2184. event.Skip()
  2185. def OnVectorDisplay(self, event):
  2186. """!Display vector lines on surface/flat"""
  2187. rasters = self.mapWindow.GetLayerNames('raster')
  2188. if event.GetSelection() == 0: # surface
  2189. if len(rasters) < 1:
  2190. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  2191. self.FindWindowById(self.win['vector']['lines']['flat']).SetSelection(1)
  2192. return
  2193. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(True)
  2194. # set first found surface
  2195. data = self.GetLayerData('vector')
  2196. data['vector']['lines']['mode']['surface'] = rasters[0]
  2197. self.FindWindowById(self.win['vector']['lines']['surface']).SetStringSelection( \
  2198. rasters[0])
  2199. else: # flat
  2200. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  2201. self.OnVectorLines(event)
  2202. event.Skip()
  2203. def OnVectorLines(self, event):
  2204. """!Set vector lines mode, apply changes if auto-rendering is enabled"""
  2205. data = self.GetLayerData('vector')
  2206. width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
  2207. mode = {}
  2208. if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
  2209. mode['type'] = 'surface'
  2210. mode['surface'] = {}
  2211. checklist = self.FindWindowById(self.win['vector']['lines']['surface'])
  2212. value = list()
  2213. checked = list()
  2214. for surface in range(checklist.GetCount()):
  2215. value.append(checklist.GetString(surface))
  2216. checked.append(checklist.IsChecked(surface))
  2217. mode['surface']['value'] = value
  2218. mode['surface']['show'] = checked
  2219. else:
  2220. mode['type'] = 'flat'
  2221. for attrb in ('width', 'mode'):
  2222. data['vector']['lines'][attrb]['update'] = None
  2223. data['vector']['lines']['width']['value'] = width
  2224. data['vector']['lines']['mode'] = mode
  2225. color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
  2226. if isinstance(color, csel.ColourSelect):
  2227. pass #color picker not yet instantiated
  2228. else:
  2229. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2230. data['vector']['lines']['color']['update'] = None
  2231. data['vector']['lines']['color']['value'] = color
  2232. # update properties
  2233. event = wxUpdateProperties(data = data)
  2234. wx.PostEvent(self.mapWindow, event)
  2235. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2236. self.mapWindow.Refresh(False)
  2237. def OnVectorHeight(self, event):
  2238. id = event.GetId()
  2239. if id in self.win['vector']['lines']['height'].values():
  2240. vtype = 'lines'
  2241. else:
  2242. vtype = 'points'
  2243. value = self.FindWindowById(id).GetValue()
  2244. slider = self.FindWindowById(self.win['vector'][vtype]['height']['slider'])
  2245. self.AdjustSliderRange(slider = slider, value = value)
  2246. for win in self.win['vector'][vtype]['height'].itervalues():
  2247. self.FindWindowById(win).SetValue(value)
  2248. data = self.GetLayerData('vector')
  2249. data['vector'][vtype]['height'] = { 'value' : value,
  2250. 'update' : None }
  2251. # update properties
  2252. event = wxUpdateProperties(data = data)
  2253. wx.PostEvent(self.mapWindow, event)
  2254. self.mapWindow.render['quick'] = True
  2255. self.mapWindow.render['v' + vtype] = True
  2256. self.mapWindow.Refresh(False)
  2257. event.Skip()
  2258. def OnVectorHeightFull(self, event):
  2259. """!Vector height changed, render in full resolution"""
  2260. self.OnVectorHeight(event)
  2261. ## self.OnVectorSurface(event)
  2262. id = event.GetId()
  2263. if id in self.win['vector']['lines']['height'].values():
  2264. vtype = 'lines'
  2265. else:
  2266. vtype = 'points'
  2267. self.mapWindow.render['quick'] = False
  2268. self.mapWindow.render['v' + vtype] = False
  2269. self.mapWindow.Refresh(False)
  2270. def OnVectorHeightText(self, event):
  2271. """!Vector height changed, render in full resolution"""
  2272. # self.OnVectorHeight(event)
  2273. self.OnVectorHeightFull(event)
  2274. def OnVectorSurface(self, event):
  2275. """!Reference surface for vector map (lines/points)"""
  2276. id = event.GetId()
  2277. if id == self.win['vector']['lines']['surface']:
  2278. vtype = 'lines'
  2279. else:
  2280. vtype = 'points'
  2281. checkList = self.FindWindowById(self.win['vector'][vtype]['surface'])
  2282. checked = []
  2283. surfaces = []
  2284. for items in range(checkList.GetCount()):
  2285. checked.append(checkList.IsChecked(items))
  2286. surfaces.append(checkList.GetString(items))
  2287. data = self.GetLayerData('vector')
  2288. data['vector'][vtype]['mode']['surface'] = { 'value' : surfaces,
  2289. 'show' : checked}
  2290. data['vector'][vtype]['mode']['update'] = None
  2291. # update properties
  2292. event = wxUpdateProperties(data = data)
  2293. wx.PostEvent(self.mapWindow, event)
  2294. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2295. self.mapWindow.Refresh(False)
  2296. def OnVectorPoints(self, event):
  2297. """!Set vector points mode, apply changes if auto-rendering is enabled"""
  2298. data = self.GetLayerData('vector')
  2299. size = self.FindWindowById(self.win['vector']['points']['size']).GetValue()
  2300. marker = self.FindWindowById(self.win['vector']['points']['marker']).GetSelection()
  2301. # width = self.FindWindowById(self.win['vector']['points']['width']).GetValue()
  2302. for attrb in ('size', 'marker'):
  2303. data['vector']['points'][attrb]['update'] = None
  2304. data['vector']['points']['size']['value'] = size
  2305. # data['vector']['points']['width']['value'] = width
  2306. data['vector']['points']['marker']['value'] = marker
  2307. color = self.FindWindowById(self.win['vector']['points']['color']).GetColour()
  2308. if isinstance(color, csel.ColourSelect):
  2309. pass #color picker not yet instantiated
  2310. else:
  2311. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2312. data['vector']['points']['color']['update'] = None
  2313. data['vector']['points']['color']['value'] = color
  2314. # update properties
  2315. event = wxUpdateProperties(data = data)
  2316. wx.PostEvent(self.mapWindow, event)
  2317. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2318. self.mapWindow.Refresh(False)
  2319. def UpdateIsosurfButtons(self, list):
  2320. """!Enable/disable buttons 'add', 'delete',
  2321. 'move up', 'move down'"""
  2322. nitems = list.GetCount()
  2323. add = self.parent.FindWindowById(self.win['volume']['btnIsosurfAdd'])
  2324. delete = self.parent.FindWindowById(self.win['volume']['btnIsosurfDelete'])
  2325. moveDown = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
  2326. moveUp = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
  2327. if nitems >= wxnviz.MAX_ISOSURFS:
  2328. # disable add button on max
  2329. add.Enable(False)
  2330. else:
  2331. add.Enable(True)
  2332. if nitems < 1:
  2333. # disable 'delete' if only one item in the lis
  2334. delete.Enable(False)
  2335. else:
  2336. delete.Enable(True)
  2337. if list.GetSelection() >= nitems - 1:
  2338. # disable 'move-down' if last
  2339. moveDown.Enable(False)
  2340. else:
  2341. moveDown.Enable(True)
  2342. if list.GetSelection() < 1:
  2343. # disable 'move-up' if first
  2344. moveUp.Enable(False)
  2345. else:
  2346. moveUp.Enable(True)
  2347. def OnVolumeIsosurfMode(self, event):
  2348. """!Set isosurface draw mode"""
  2349. self.SetIsosurfaceMode(event.GetSelection())
  2350. def SetIsosurfaceMode(self, selection):
  2351. """!Set isosurface draw mode"""
  2352. data = self.GetLayerData('volume')['volume']
  2353. id = data['object']['id']
  2354. mode = 0
  2355. if selection == 0:
  2356. mode |= wxnviz.DM_FLAT
  2357. else:
  2358. mode |= wxnviz.DM_GOURAUD
  2359. self._display.SetIsosurfaceMode(id, mode)
  2360. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2361. self.mapWindow.Refresh(False)
  2362. def OnVolumeIsosurfResolution(self, event):
  2363. """!Set isosurface draw resolution"""
  2364. self.SetIsosurfaceResolution(event.GetInt())
  2365. def SetIsosurfaceResolution(self, res):
  2366. """!Set isosurface draw resolution"""
  2367. data = self.GetLayerData('volume')['volume']
  2368. id = data['object']['id']
  2369. self._display.SetIsosurfaceRes(id, res)
  2370. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2371. self.mapWindow.Refresh(False)
  2372. def OnVolumeIsosurfMap(self, event):
  2373. """!Set surface attribute"""
  2374. self.SetMapObjAttrb(nvizType = 'volume', winId = event.GetId())
  2375. def OnVolumeIsosurfCheck(self, event):
  2376. """!Isosurface checked (->load) or unchecked (->unload)"""
  2377. index = event.GetSelection()
  2378. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2379. data = self.GetLayerData('volume')['volume']
  2380. id = data['object']['id']
  2381. isosurfId = event.GetSelection()
  2382. if list.IsChecked(index):
  2383. self._display.SetIsosurfaceTransp(id, isosurfId, False, "0")
  2384. else:
  2385. # disable -> make transparent
  2386. self._display.SetIsosurfaceTransp(id, isosurfId, False, "255")
  2387. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2388. self.mapWindow.Refresh(False)
  2389. def OnVolumeIsosurfSelect(self, event):
  2390. """!Isosurface item selected"""
  2391. winUp = self.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
  2392. winDown = self.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
  2393. selection = event.GetSelection()
  2394. if selection == 0:
  2395. winUp.Enable(False)
  2396. if not winDown.IsEnabled():
  2397. winDown.Enable()
  2398. elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
  2399. winDown.Enable(False)
  2400. if not winUp.IsEnabled():
  2401. winUp.Enable()
  2402. else:
  2403. if not winDown.IsEnabled():
  2404. winDown.Enable()
  2405. if not winUp.IsEnabled():
  2406. winUp.Enable()
  2407. # update dialog
  2408. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2409. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2410. data = self.GetLayerData('volume')['volume']['isosurface'][selection]
  2411. self.UpdateVolumeIsosurfPage(layer, data)
  2412. def OnVolumeIsosurfAdd(self, event):
  2413. """!Add new isosurface to the list"""
  2414. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2415. level = self.FindWindowById(self.win['volume']['topo']['const']).GetValue()
  2416. sel = list.GetSelection()
  2417. if sel < 0 or sel >= list.GetCount() - 1:
  2418. item = list.Append(item = "%s %s" % (_("Level"), str(level)))
  2419. else:
  2420. list.Insert(item = "%s %s" % (_("Level"), str(level)),
  2421. pos = sel+1) # append
  2422. item = sel + 1
  2423. list.Check(item)
  2424. list.SetSelection(item)
  2425. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2426. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2427. data = self.GetLayerData('volume')['volume']
  2428. id = data['object']['id']
  2429. # collect properties
  2430. isosurfData = {}
  2431. for attrb in ('topo', 'color', 'mask',
  2432. 'transp', 'shine', 'emit'):
  2433. if attrb == 'topo':
  2434. isosurfData[attrb] = {}
  2435. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  2436. isosurfData[attrb]['value'] = win.GetValue()
  2437. else:
  2438. uwin = self.FindWindowById(self.win['volume'][attrb]['use'])
  2439. sel = uwin.GetSelection()
  2440. if self.win['volume'][attrb]['required']:
  2441. sel += 1
  2442. if sel == 0: # unset
  2443. continue
  2444. isosurfData[attrb] = {}
  2445. if sel == 1: # map
  2446. isosurfData[attrb]['map'] = True
  2447. vwin = self.FindWindowById(self.win['volume'][attrb]['map'])
  2448. value = vwin.GetValue()
  2449. else: # const
  2450. isosurfData[attrb]['map'] = False
  2451. vwin = self.FindWindowById(self.win['volume'][attrb]['const'])
  2452. if vwin.GetName() == "color":
  2453. value = self._getColorString(vwin.GetValue())
  2454. else:
  2455. value = vwin.GetValue()
  2456. isosurfData[attrb]['value'] = value
  2457. data['isosurface'].insert(item, isosurfData)
  2458. # add isosurface
  2459. self._display.AddIsosurface(id, level)
  2460. # use by default 3d raster map for color
  2461. self._display.SetIsosurfaceColor(id, item, True, str(layer.name))
  2462. # update buttons
  2463. self.UpdateIsosurfButtons(list)
  2464. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2465. self.mapWindow.Refresh(False)
  2466. event.Skip()
  2467. def OnVolumeIsosurfDelete(self, event):
  2468. """!Remove isosurface from list"""
  2469. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2470. # remove item from list
  2471. isosurfId = list.GetSelection()
  2472. list.Delete(isosurfId)
  2473. # select last item
  2474. if list.GetCount() > 0:
  2475. list.SetSelection(list.GetCount()-1)
  2476. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2477. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2478. data = self.GetLayerData('volume')['volume']
  2479. id = data['object']['id']
  2480. # delete isosurface
  2481. del data['isosurface'][isosurfId]
  2482. self._display.DeleteIsosurface(id, isosurfId)
  2483. # update buttons
  2484. self.UpdateIsosurfButtons(list)
  2485. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2486. self.mapWindow.Refresh(False)
  2487. event.Skip()
  2488. def OnVolumeIsosurfMoveUp(self, event):
  2489. """!Move isosurface up in the list"""
  2490. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2491. sel = list.GetSelection()
  2492. if sel < 1:
  2493. return # this should not happen
  2494. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2495. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2496. data = self.GetLayerData('volume')['volume']
  2497. id = data['object']['id']
  2498. # move item up
  2499. text = list.GetStringSelection()
  2500. list.Insert(item = text, pos = sel-1)
  2501. list.Check(sel-1)
  2502. list.SetSelection(sel-1)
  2503. list.Delete(sel+1)
  2504. data['isosurface'].insert(sel-1, data['isosurface'][sel])
  2505. del data['isosurface'][sel+1]
  2506. self._display.MoveIsosurface(id, sel, True)
  2507. # update buttons
  2508. self.UpdateIsosurfButtons(list)
  2509. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2510. self.mapWindow.Refresh(False)
  2511. event.Skip()
  2512. def OnVolumeIsosurfMoveDown(self, event):
  2513. """!Move isosurface dowm in the list"""
  2514. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2515. sel = list.GetSelection()
  2516. if sel >= list.GetCount() - 1:
  2517. return # this should not happen
  2518. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2519. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2520. data = self.GetLayerData('volume')['volume']
  2521. id = data['object']['id']
  2522. # move item up
  2523. text = list.GetStringSelection()
  2524. list.Insert(item = text, pos = sel+2)
  2525. list.Check(sel+2)
  2526. list.SetSelection(sel+2)
  2527. list.Delete(sel)
  2528. data['isosurface'].insert(sel+2, data['isosurface'][sel])
  2529. del data['isosurface'][sel]
  2530. self._display.MoveIsosurface(id, sel, False)
  2531. # update buttons
  2532. self.UpdateIsosurfButtons(list)
  2533. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2534. self.mapWindow.Refresh(False)
  2535. event.Skip()
  2536. def OnCPlaneSelection(self, event):
  2537. """!Cutting plane selected"""
  2538. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  2539. try:
  2540. planeIndex = int(plane.split()[1])
  2541. self.EnablePage("cplane", enabled = True)
  2542. except:
  2543. planeIndex = -1
  2544. self.EnablePage("cplane", enabled = False)
  2545. self.mapWindow.SelectCPlane(planeIndex)
  2546. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2547. self.mapWindow.Refresh(False)
  2548. self.UpdateCPlanePage(planeIndex)
  2549. def OnCPlaneChanging(self, event):
  2550. """!Cutting plane is changing"""
  2551. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  2552. try:
  2553. planeIndex = int(plane.split()[1])
  2554. except:#TODO disabled page
  2555. planeIndex = -1
  2556. if event.GetId() in (self.win['cplane']['rotation']['rot'].values() +
  2557. self.win['cplane']['rotation']['tilt'].values()):
  2558. action = 'rotation'
  2559. else:
  2560. action = 'position'
  2561. data = self.mapWindow.cplanes[planeIndex][action]
  2562. self.OnScroll(event, self.win['cplane'][action], data)
  2563. self.mapWindow.render['quick'] = True
  2564. event = wxUpdateCPlane(update = (action,), current = planeIndex)
  2565. wx.PostEvent(self.mapWindow, event)
  2566. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2567. self.mapWindow.Refresh(False)
  2568. def OnCPlaneChangeDone(self, event):
  2569. """!Cutting plane change done"""
  2570. self.mapWindow.render['quick'] = False
  2571. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2572. self.mapWindow.Refresh(False)
  2573. def OnCPlaneChangeText(self, event):
  2574. """!Cutting plane changed by textctrl"""
  2575. for axis in ('x', 'y', 'z'):
  2576. if event.GetId() == self.win['cplane']['position'][axis]['text']:
  2577. value = self.FindWindowById(event.GetId()).GetValue()
  2578. slider = self.FindWindowById(self.win['cplane']['position'][axis]['slider'])
  2579. self.AdjustSliderRange(slider = slider, value = value)
  2580. self.OnCPlaneChanging(event = event)
  2581. self.OnCPlaneChangeDone(None)
  2582. def OnCPlaneShading(self, event):
  2583. """!Cutting plane shading changed"""
  2584. shading = self.FindWindowById(self.win['cplane']['shading']).GetSelection()
  2585. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  2586. try:
  2587. planeIndex = int(plane.split()[1])
  2588. except:#TODO disabled page
  2589. planeIndex = -1
  2590. self.mapWindow.cplanes[planeIndex]['shading'] = shading
  2591. event = wxUpdateCPlane(update = ('shading',), current = planeIndex)
  2592. wx.PostEvent(self.mapWindow, event)
  2593. self.OnCPlaneChangeDone(None)
  2594. def OnCPlaneReset(self, event):
  2595. """!Reset current cutting plane"""
  2596. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  2597. try:
  2598. planeIndex = int(plane.split()[1])
  2599. except:#TODO disabled page
  2600. planeIndex = -1
  2601. self.mapWindow.cplanes[planeIndex] = copy.deepcopy(UserSettings.Get(group = 'nviz',
  2602. key = 'cplane'))
  2603. event = wxUpdateCPlane(update = ('position','rotation','shading'), current = planeIndex)
  2604. wx.PostEvent(self.mapWindow, event)
  2605. self.OnCPlaneChangeDone(None)
  2606. self.UpdateCPlanePage(planeIndex)
  2607. def UpdatePage(self, pageId):
  2608. """!Update dialog (selected page)"""
  2609. self.pageChanging = True
  2610. Debug.msg(1, "NvizToolWindow.UpdatePage(): %s", pageId)
  2611. if pageId == 'view':
  2612. self.SetPage('view')
  2613. hmin = self.mapWindow.iview['height']['min']
  2614. hmax = self.mapWindow.iview['height']['max']
  2615. hval = self.mapWindow.iview['height']['value']
  2616. zmin = self.mapWindow.view['z-exag']['min']
  2617. zmax = self.mapWindow.view['z-exag']['max']
  2618. zval = self.mapWindow.view['z-exag']['value']
  2619. for control in ('slider','text'):
  2620. self.FindWindowById(self.win['view']['height'][control]).SetRange(
  2621. hmin,hmax)
  2622. self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(
  2623. zmin, zmax)
  2624. self.FindWindowById(self.win['view']['height'][control]).SetValue(hval)
  2625. self.FindWindowById(self.win['view']['z-exag'][control]).SetValue(zval)
  2626. self.FindWindowById(self.win['view']['background']['color']).SetColour(\
  2627. self.mapWindow.view['background']['color'])
  2628. tval = self.mapWindow.view['twist']['value']
  2629. pval = self.mapWindow.view['persp']['value']
  2630. for control in ('slider','text'):
  2631. self.FindWindowById(self.win['view']['twist'][control]).SetValue(tval)
  2632. self.FindWindowById(self.win['view']['persp'][control]).SetValue(pval)
  2633. elif pageId in ('surface', 'vector', 'volume'):
  2634. name = self.FindWindowById(self.win[pageId]['map']).GetValue()
  2635. data = self.GetLayerData(pageId)
  2636. if data:
  2637. if pageId == 'surface':
  2638. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  2639. self.UpdateSurfacePage(layer, data['surface'])
  2640. elif pageId == 'vector':
  2641. layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
  2642. self.UpdateVectorPage(layer, data['vector'])
  2643. elif pageId == 'volume':
  2644. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2645. self.UpdateVectorPage(layer, data['vector'])
  2646. elif pageId == 'light':
  2647. zval = self.mapWindow.light['position']['z']
  2648. bval = self.mapWindow.light['bright']
  2649. aval = self.mapWindow.light['ambient']
  2650. for control in ('slider','text'):
  2651. self.FindWindowById(self.win['light']['z'][control]).SetValue(zval)
  2652. self.FindWindowById(self.win['light']['bright'][control]).SetValue(bval)
  2653. self.FindWindowById(self.win['light']['ambient'][control]).SetValue(aval)
  2654. self.FindWindowById(self.win['light']['color']).SetColour(self.mapWindow.light['color'])
  2655. self.FindWindowById(self.win['light']['position']).PostDraw()
  2656. elif pageId == 'fringe':
  2657. win = self.FindWindowById(self.win['fringe']['map'])
  2658. win.SetValue(self.FindWindowById(self.win['surface']['map']).GetValue())
  2659. elif pageId == 'constant':
  2660. if self.mapWindow.constants:
  2661. surface = self.FindWindowById(self.win['constant']['surface'])
  2662. for item in self.mapWindow.constants:
  2663. surface.Append(_("constant#") + str(item['constant']['object']['name']))
  2664. surface.SetSelection(0)
  2665. self.OnConstantSelection(None)
  2666. self.EnablePage('constant', True)
  2667. elif pageId == 'cplane':
  2668. count = self._display.GetCPlanesCount()
  2669. choices = [_("None"),]
  2670. for plane in range(count):
  2671. choices.append("%s %i" % (_("Plane"), plane))
  2672. self.FindWindowById(self.win['cplane']['planes']).SetItems(choices)
  2673. self.FindWindowById(self.win['cplane']['planes']).SetSelection(0)
  2674. xyRange, zRange = self._display.GetXYRange(), self._display.GetZRange()
  2675. if xyRange > 0: # GTK warning
  2676. self.FindWindowById(self.win['cplane']['position']['x']['slider']).SetRange(-xyRange/2., xyRange/2.)
  2677. self.FindWindowById(self.win['cplane']['position']['y']['slider']).SetRange(-xyRange/2., xyRange/2.)
  2678. if zRange[0] - zRange[1] > 0:
  2679. self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetRange(zRange[0], zRange[1])
  2680. self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetValue(zRange[0])
  2681. self.FindWindowById(self.win['cplane']['position']['z']['text']).SetValue(zRange[0])
  2682. self.OnCPlaneSelection(None)
  2683. self.Update()
  2684. self.pageChanging = False
  2685. def UpdateCPlanePage(self, index):
  2686. """!Update widgets according to selected clip plane"""
  2687. if index == -1:
  2688. return
  2689. data = self.mapWindow.cplanes[index]
  2690. for widget in ('text', 'slider'):
  2691. for axes in ('x', 'y', 'z'):
  2692. self.FindWindowById(self.win['cplane']['position'][axes][widget]).SetValue(data['position'][axes])
  2693. for each in ('tilt', 'rot'):
  2694. self.FindWindowById(self.win['cplane']['rotation'][each][widget]).SetValue(data['rotation'][each])
  2695. self.FindWindowById(self.win['cplane']['shading']).SetSelection(data['shading'])
  2696. def UpdateSurfacePage(self, layer, data, updateName = True):
  2697. """!Update surface page"""
  2698. ret = gcmd.RunCommand('r.info',
  2699. read = True,
  2700. flags = 'm',
  2701. map = layer.name)
  2702. if ret:
  2703. desc = ret.split('=')[1].rstrip('\n')
  2704. else:
  2705. desc = None
  2706. if updateName:
  2707. self.FindWindowById(self.win['surface']['map']).SetValue(layer.name)
  2708. self.FindWindowById(self.win['surface']['desc']).SetLabel(desc)
  2709. # attributes
  2710. if layer and layer.type == 'raster':
  2711. self.vetoGSelectEvt = True
  2712. self.FindWindowById(self.win['surface']['color']['map']).SetValue(layer.name)
  2713. else:
  2714. self.FindWindowById(self.win['surface']['color']['map']).SetValue('')
  2715. self.SetMapObjUseMap(nvizType = 'surface',
  2716. attrb = 'color', map = True) # -> map
  2717. if 'color' in data['attribute']:
  2718. value = data['attribute']['color']['value']
  2719. if data['attribute']['color']['map']:
  2720. self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
  2721. else: # constant
  2722. color = map(int, value.split(':'))
  2723. self.FindWindowById(self.win['surface']['color']['const']).SetColour(color)
  2724. self.SetMapObjUseMap(nvizType = 'surface',
  2725. attrb = 'color', map = data['attribute']['color']['map'])
  2726. self.SetMapObjUseMap(nvizType = 'surface',
  2727. attrb = 'shine', map = data['attribute']['shine']['map'])
  2728. value = data['attribute']['shine']['value']
  2729. if data['attribute']['shine']['map']:
  2730. self.FindWindowById(self.win['surface']['shine']['map']).SetValue(value)
  2731. else:
  2732. self.FindWindowById(self.win['surface']['shine']['const']).SetValue(value)
  2733. #
  2734. # draw
  2735. #
  2736. for control, drawData in data['draw'].iteritems():
  2737. if control == 'all': # skip 'all' property
  2738. continue
  2739. if control == 'resolution':
  2740. self.FindWindowById(self.win['surface']['draw']['res-coarse']).SetValue(drawData['coarse'])
  2741. self.FindWindowById(self.win['surface']['draw']['res-fine']).SetValue(drawData['fine'])
  2742. continue
  2743. if control == 'mode':
  2744. if drawData['desc']['mode'] == 'coarse':
  2745. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(0)
  2746. elif drawData['desc']['mode'] == 'fine':
  2747. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(1)
  2748. else: # both
  2749. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(2)
  2750. if drawData['desc']['style'] == 'wire':
  2751. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(0)
  2752. else: # surface
  2753. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(1)
  2754. if drawData['desc']['shading'] == 'flat':
  2755. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(0)
  2756. else: # gouraud
  2757. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(1)
  2758. continue
  2759. value = drawData['value']
  2760. win = self.FindWindowById(self.win['surface']['draw'][control])
  2761. name = win.GetName()
  2762. if name == "selection":
  2763. win.SetSelection(value)
  2764. elif name == "colour":
  2765. color = map(int, value.split(':'))
  2766. win.SetColour(color)
  2767. else:
  2768. win.SetValue(value)
  2769. #
  2770. # position
  2771. #
  2772. if 'x' in data['position']:
  2773. xval = data['position']['x']
  2774. self.FindWindowById(self.win['surface']['position']['axis']).SetSelection(0)
  2775. for control in ('slider','text'):
  2776. self.FindWindowById(self.win['surface']['position'][control]).SetValue(xval)
  2777. # enable/disable res widget + set draw mode
  2778. self.OnSurfaceMode(event = None)
  2779. def VectorInfo(self, layer):
  2780. """!Get number of points/lines
  2781. @param layer MapLayer instance
  2782. @return num of points/features (expect of points)
  2783. @return None
  2784. """
  2785. vInfo = grass.vector_info_topo(layer.GetName())
  2786. if not vInfo:
  2787. return None
  2788. nprimitives = 0
  2789. for key, value in vInfo.iteritems():
  2790. if key in ('points',
  2791. 'lines',
  2792. 'boundaries',
  2793. 'centroids',
  2794. 'faces',
  2795. 'kernels'):
  2796. nprimitives += value
  2797. return (vInfo['points'], vInfo['lines'], nprimitives, vInfo['map3d'])
  2798. def UpdateVectorPage(self, layer, data, updateName = True):
  2799. """!Update vector page"""
  2800. npoints, nlines, nfeatures, mapIs3D = self.VectorInfo(layer)
  2801. if mapIs3D:
  2802. desc = _("Vector map is 3D")
  2803. enable = False
  2804. else:
  2805. desc = _("Vector map is 2D")
  2806. enable = True
  2807. desc += " - " + _("%(features)d features (%(points)d points)") % \
  2808. { 'features' : nfeatures, 'points' : npoints }
  2809. if updateName:
  2810. self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
  2811. self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
  2812. self.FindWindowById(self.win['vector']['lines']['flat']).Enable(enable)
  2813. for v in ('lines', 'points'):
  2814. self.FindWindowById(self.win['vector'][v]['surface']).Enable(enable)
  2815. self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
  2816. self.FindWindowById(self.win['vector'][v]['height']['text']).Enable(enable)
  2817. #
  2818. # lines
  2819. #
  2820. showLines = self.FindWindowById(self.win['vector']['lines']['show'])
  2821. if 'object' in data['lines']:
  2822. showLines.SetValue(True)
  2823. else:
  2824. showLines.SetValue(False)
  2825. if nlines > 0:
  2826. showLines.Enable(True)
  2827. else:
  2828. showLines.Enable(False)
  2829. self.UpdateVectorShow('lines',
  2830. showLines.IsChecked())
  2831. width = self.FindWindowById(self.win['vector']['lines']['width'])
  2832. width.SetValue(data['lines']['width']['value'])
  2833. color = self.FindWindowById(self.win['vector']['lines']['color'])
  2834. color.SetValue(map(int, data['lines']['color']['value'].split(':')))
  2835. for vtype in ('lines', 'points'):
  2836. if vtype == 'lines':
  2837. display = self.FindWindowById(self.win['vector']['lines']['flat'])
  2838. if data[vtype]['mode']['type'] == 'flat':
  2839. display.SetSelection(1)
  2840. else:
  2841. display.SetSelection(0)
  2842. if data[vtype]['mode']['type'] == 'surface':
  2843. rasters = self.mapWindow.GetLayerNames('raster')
  2844. constants = self.mapWindow.GetLayerNames('constant')
  2845. surfaces = rasters + constants
  2846. surfaceWin = self.FindWindowById(self.win['vector'][vtype]['surface'])
  2847. surfaceWin.SetItems(surfaces)
  2848. for idx, surface in enumerate(surfaces):
  2849. try:# TODO fix this mess
  2850. selected = data[vtype]['mode']['surface']['show'][idx]
  2851. except (TypeError, IndexError, KeyError):
  2852. selected = False
  2853. surfaceWin.Check(idx, selected)
  2854. for type in ('slider', 'text'):
  2855. win = self.FindWindowById(self.win['vector']['lines']['height'][type])
  2856. win.SetValue(data['lines']['height']['value'])
  2857. #
  2858. # points
  2859. #
  2860. showPoints = self.FindWindowById(self.win['vector']['points']['show'])
  2861. if 'object' in data['points']:
  2862. showPoints.SetValue(True)
  2863. else:
  2864. showPoints.SetValue(False)
  2865. if npoints > 0:
  2866. showPoints.Enable(True)
  2867. else:
  2868. showPoints.Enable(False)
  2869. self.UpdateVectorShow('points',
  2870. showPoints.IsChecked())
  2871. # size, width, marker, color
  2872. for prop in ('size', 'marker', 'color'):
  2873. win = self.FindWindowById(self.win['vector']['points'][prop])
  2874. name = win.GetName()
  2875. if name == 'selection':
  2876. win.SetSelection(data['points'][prop]['value'])
  2877. elif name == 'color':
  2878. color = map(int, data['points'][prop]['value'].split(':'))
  2879. win.SetValue(color)
  2880. else:
  2881. win.SetValue(data['points'][prop]['value'])
  2882. # height
  2883. for type in ('slider', 'text'):
  2884. win = self.FindWindowById(self.win['vector']['points']['height'][type])
  2885. win.SetValue(data['points']['height']['value'])
  2886. def UpdateVolumePage(self, layer, data, updateName = True):
  2887. """!Update volume page"""
  2888. if updateName:
  2889. self.FindWindowById(self.win['volume']['map']).SetValue(layer.name)
  2890. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2891. # draw
  2892. for control, idata in data['draw'].iteritems():
  2893. if control == 'all': # skip 'all' property
  2894. continue
  2895. win = self.FindWindowById(self.win['volume']['draw'][control])
  2896. if control == 'shading':
  2897. if data['draw']['shading']['desc'] == 'flat':
  2898. value = 0
  2899. else:
  2900. value = 1
  2901. else:
  2902. value = idata['value']
  2903. if win.GetName() == "selection":
  2904. win.SetSelection(value)
  2905. else:
  2906. win.SetValue(value)
  2907. self.SetIsosurfaceMode(data['draw']['shading']['value'])
  2908. self.SetIsosurfaceResolution(data['draw']['resolution']['value'])
  2909. self.UpdateVolumeIsosurfPage(layer, data['attribute'])
  2910. def UpdateVolumeIsosurfPage(self, layer, data):
  2911. """!Update dialog -- isosurface attributes"""
  2912. #
  2913. # isosurface attributes
  2914. #
  2915. for attrb in ('topo', 'color', 'mask',
  2916. 'transp', 'shine', 'emit'):
  2917. # check required first
  2918. if attrb == 'topo':
  2919. self.FindWindowById(self.win['volume'][attrb]['const']).SetValue(0)
  2920. continue
  2921. if attrb == 'color':
  2922. if layer and layer.type == '3d-raster':
  2923. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(layer.name)
  2924. else:
  2925. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue('')
  2926. self.SetMapObjUseMap(nvizType = 'volume',
  2927. attrb = attrb, map = True) # -> map
  2928. continue
  2929. # skip empty attributes
  2930. if attrb not in data:
  2931. continue
  2932. value = data[attrb]['value']
  2933. if attrb == 'color':
  2934. if data[attrb]['map']:
  2935. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(value)
  2936. else: # constant
  2937. color = map(int, value.split(':'))
  2938. self.FindWindowById(self.win['volume'][attrb]['const']).SetColour(color)
  2939. else:
  2940. if data[attrb]['map']:
  2941. win = self.FindWindowById(self.win['volume'][attrb]['map'])
  2942. else:
  2943. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  2944. win.SetValue(value)
  2945. self.SetMapObjUseMap(nvizType = 'volume',
  2946. attrb = attrb, map = data[attrb]['map'])
  2947. def SetPage(self, name):
  2948. """!Get named page"""
  2949. if name == 'view':
  2950. self.SetSelection(0)
  2951. elif name in ('surface', 'vector', 'volume'):
  2952. self.SetSelection(1)
  2953. else:
  2954. self.SetSelection(2)
  2955. win = self.FindWindowById(self.page[name]['notebook'])
  2956. try:
  2957. win.Expand(win.GetFoldPanel(self.page[name]['id']))
  2958. except AttributeError:
  2959. win.SetSelection(self.page[name]['id'])
  2960. class PositionWindow(wx.Window):
  2961. """!Abstract position control window, see subclasses
  2962. ViewPostionWindow and LightPositionWindow"""
  2963. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  2964. **kwargs):
  2965. self.mapWindow = mapwindow
  2966. self.quick = True
  2967. wx.Window.__init__(self, parent, id, **kwargs)
  2968. self.SetBackgroundColour("WHITE")
  2969. self.pdc = wx.PseudoDC()
  2970. self.pdc.SetBrush(wx.Brush(colour = 'dark green', style = wx.SOLID))
  2971. self.pdc.SetPen(wx.Pen(colour = 'dark green', width = 2, style = wx.SOLID))
  2972. self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
  2973. self.Bind(wx.EVT_PAINT, self.OnPaint)
  2974. # self.Bind(wx.EVT_MOTION, self.OnMouse)
  2975. self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
  2976. def Draw(self, pos, scale = False):
  2977. w, h = self.GetClientSize()
  2978. x, y = pos
  2979. if scale:
  2980. x = x * w
  2981. y = y * h
  2982. self.pdc.Clear()
  2983. self.pdc.BeginDrawing()
  2984. self.pdc.DrawLine(w / 2, h / 2, x, y)
  2985. self.pdc.DrawCircle(x, y, 5)
  2986. self.pdc.EndDrawing()
  2987. def OnPaint(self, event):
  2988. dc = wx.BufferedPaintDC(self)
  2989. dc.SetBackground(wx.Brush("White"))
  2990. dc.Clear()
  2991. self.PrepareDC(dc)
  2992. self.pdc.DrawToDC(dc)
  2993. def UpdatePos(self, xcoord, ycoord):
  2994. """!Update position coordinates (origin: UL)"""
  2995. if xcoord < 0.0:
  2996. xcoord = 0.0
  2997. elif xcoord > 1.0:
  2998. xcoord = 1.0
  2999. if ycoord < 0.0:
  3000. ycoord = 0.0
  3001. elif ycoord > 1.0:
  3002. ycoord = 1.0
  3003. x, y = self.TransformCoordinates(xcoord, ycoord)
  3004. self.data['position']['x'] = x
  3005. self.data['position']['y'] = y
  3006. return xcoord, ycoord
  3007. def OnMouse(self, event):
  3008. if event.LeftIsDown():
  3009. x, y = event.GetPosition()
  3010. self.Draw(pos = (x, y))
  3011. w, h = self.GetClientSize()
  3012. x = float(x) / w
  3013. y = float(y) / h
  3014. self.UpdatePos(x, y)
  3015. self.Refresh(False)
  3016. event.Skip()
  3017. def PostDraw(self):
  3018. x, y = self.UpdatePos(self.data['position']['x'],
  3019. self.data['position']['y'])
  3020. self.Draw(pos = (x,y), scale = True)
  3021. class ViewPositionWindow(PositionWindow):
  3022. """!View position control widget"""
  3023. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  3024. **kwargs):
  3025. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  3026. self.data = self.mapWindow.view
  3027. self.PostDraw()
  3028. def UpdatePos(self, xcoord, ycoord):
  3029. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  3030. event = wxUpdateView(zExag = True)
  3031. wx.PostEvent(self.mapWindow, event)
  3032. return x, y
  3033. def TransformCoordinates(self, x, y, toLight = True):
  3034. return x, y
  3035. def OnMouse(self, event):
  3036. PositionWindow.OnMouse(self, event)
  3037. if event.LeftIsDown():
  3038. self.mapWindow.render['quick'] = self.quick
  3039. self.mapWindow.Refresh(eraseBackground = False)
  3040. elif event.LeftUp():
  3041. self.mapWindow.render['quick'] = False
  3042. self.mapWindow.Refresh(eraseBackground = False)
  3043. event.Skip()
  3044. class LightPositionWindow(PositionWindow):
  3045. """!Light position control widget"""
  3046. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  3047. **kwargs):
  3048. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  3049. self.data = self.mapWindow.light
  3050. self.quick = False
  3051. self.PostDraw()
  3052. def UpdatePos(self, xcoord, ycoord):
  3053. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  3054. event = wxUpdateLight()
  3055. wx.PostEvent(self.mapWindow, event)
  3056. return x, y
  3057. def TransformCoordinates(self, x, y, toLight = True):
  3058. if toLight:
  3059. x = 2 * x - 1
  3060. y = -2 * y + 1
  3061. else:
  3062. x = (x + 1)/2
  3063. y = (1 - y)/2
  3064. return x, y
  3065. def PostDraw(self):
  3066. event = wxUpdateLight(refresh = True)
  3067. wx.PostEvent(self.mapWindow, event)
  3068. x, y = self.data['position']['x'], self.data['position']['y']
  3069. x, y = self.TransformCoordinates(x, y, toLight = False)
  3070. self.Draw(pos = (x,y), scale = True)
  3071. def OnMouse(self, event):
  3072. PositionWindow.OnMouse(self, event)
  3073. if event.LeftUp():
  3074. self.mapWindow.render['quick'] = False
  3075. self.mapWindow.Refresh(eraseBackground = False)