nviz_tools.py 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923
  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-2010 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. """
  16. import os
  17. import sys
  18. import copy
  19. import types
  20. import wx
  21. import wx.lib.colourselect as csel
  22. import wx.lib.scrolledpanel as SP
  23. try:
  24. import wx.lib.agw.flatnotebook as FN
  25. except ImportError:
  26. import wx.lib.flatnotebook as FN
  27. import globalvar
  28. import gselect
  29. import gcmd
  30. from preferences import globalSettings as UserSettings
  31. from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties
  32. from debug import Debug
  33. import wxnviz
  34. class NvizToolWindow(FN.FlatNotebook):
  35. """!Nviz (3D view) tools panel
  36. """
  37. def __init__(self, parent, display, id = wx.ID_ANY,
  38. style = globalvar.FNPageStyle, **kwargs):
  39. self.parent = parent # GMFrame
  40. self.mapDisplay = display
  41. self.mapWindow = display.GetWindow()
  42. self._display = self.mapWindow.GetDisplay()
  43. if globalvar.hasAgw:
  44. kwargs['agwStyle'] = style
  45. else:
  46. kwargs['style'] = style
  47. FN.FlatNotebook.__init__(self, parent, id, **kwargs)
  48. self.SetTabAreaColour(globalvar.FNPageColor)
  49. self.win = {} # window ids
  50. self.page = {} # page ids
  51. # view page
  52. self.AddPage(page = self._createViewPage(),
  53. text = " %s " % _("View"))
  54. # data page
  55. self.AddPage(page = self._createDataPage(),
  56. text = " %s " % _("Data"))
  57. # appearance page
  58. self.AddPage(page = self._createAppearancePage(),
  59. text = " %s " % _("Appearance"))
  60. self.UpdateSettings()
  61. self.pageChanging = False
  62. self.mapWindow.render['quick'] = False
  63. self.mapWindow.Refresh(False)
  64. # bindings
  65. self.Bind(wx.EVT_CLOSE, self.OnClose)
  66. self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
  67. self.Update()
  68. wx.CallAfter(self.SetPage, 'view')
  69. wx.CallAfter(self.notebookData.SetSelection, 0)
  70. wx.CallAfter(self.notebookAppearance.SetSelection, 0)
  71. def OnPageChanged(self, event):
  72. new = event.GetSelection()
  73. # self.ChangeSelection(new)
  74. def PostViewEvent(self, zExag = False):
  75. """!Change view settings"""
  76. event = wxUpdateView(zExag = zExag)
  77. wx.PostEvent(self.mapWindow, event)
  78. def _createViewPage(self):
  79. """!Create view settings page"""
  80. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  81. panel.SetupScrolling(scroll_x = False)
  82. self.page['view'] = { 'id' : 0,
  83. 'notebook' : self.GetId()}
  84. pageSizer = wx.BoxSizer(wx.VERTICAL)
  85. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  86. label = " %s " % (_("Control View")))
  87. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  88. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  89. self.win['view'] = {}
  90. # position
  91. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  92. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("W")),
  93. pos = (1, 0), flag = wx.ALIGN_CENTER)
  94. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
  95. pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
  96. view = ViewPositionWindow(panel, size = (175, 175),
  97. mapwindow = self.mapWindow)
  98. self.win['view']['position'] = view.GetId()
  99. posSizer.Add(item = view,
  100. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  101. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
  102. pos = (2, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_TOP)
  103. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("E")),
  104. pos = (1, 2), flag = wx.ALIGN_CENTER)
  105. gridSizer.Add(item = posSizer, pos = (0, 0))
  106. # perspective
  107. # set initial defaults here (or perhaps in a default values file), not in user settings
  108. self._createControl(panel, data = self.win['view'], name = 'persp',
  109. range = (1,100),
  110. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  111. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Perspective:")),
  112. pos = (1, 0), flag = wx.ALIGN_CENTER)
  113. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['slider']), pos = (2, 0))
  114. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['spin']), pos = (3, 0),
  115. flag = wx.ALIGN_CENTER)
  116. # twist
  117. self._createControl(panel, data = self.win['view'], name = 'twist',
  118. range = (-180,180),
  119. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  120. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Twist:")),
  121. pos = (1, 1), flag = wx.ALIGN_CENTER)
  122. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['slider']), pos = (2, 1))
  123. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['spin']), pos = (3, 1),
  124. flag = wx.ALIGN_CENTER)
  125. # height + z-exag
  126. self._createControl(panel, data = self.win['view'], name = 'height', sliderHor = False,
  127. range = (0, 1),
  128. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  129. self._createControl(panel, data = self.win['view'], name = 'z-exag', sliderHor = False,
  130. range = (0, 5),
  131. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  132. self.FindWindowById(self.win['view']['z-exag']['slider']).SetValue(1)
  133. self.FindWindowById(self.win['view']['z-exag']['spin']).SetValue(1)
  134. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  135. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  136. pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
  137. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['slider']),
  138. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  139. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['spin']),
  140. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  141. wx.BOTTOM | wx.RIGHT, pos = (1, 1))
  142. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Z-exag:")),
  143. pos = (0, 2), flag = wx.ALIGN_LEFT, span = (1, 2))
  144. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['slider']),
  145. flag = wx.ALIGN_RIGHT, pos = (1, 2))
  146. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['spin']),
  147. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  148. wx.BOTTOM | wx.RIGHT, pos = (1, 3))
  149. gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_RIGHT)
  150. # view setup + reset
  151. viewSizer = wx.BoxSizer(wx.HORIZONTAL)
  152. viewSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY,
  153. label = _("Look at:")),
  154. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  155. border = 5)
  156. viewType = wx.Choice (parent = panel, id = wx.ID_ANY, size = (125, -1),
  157. choices = [_("top"),
  158. _("north"),
  159. _("south"),
  160. _("east"),
  161. _("west"),
  162. _("north-west"),
  163. _("north-east"),
  164. _("south-east"),
  165. _("south-west")])
  166. viewType.SetSelection(0)
  167. viewType.Bind(wx.EVT_CHOICE, self.OnLookAt)
  168. # self.win['lookAt'] = viewType.GetId()
  169. viewSizer.Add(item = viewType,
  170. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  171. border = 5)
  172. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  173. reset.SetToolTipString(_("Reset to default view"))
  174. # self.win['reset'] = reset.GetId()
  175. reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  176. viewSizer.Add(item = wx.Size(-1, -1), proportion = 1,
  177. flag = wx.EXPAND)
  178. viewSizer.Add(item = reset, proportion = 0,
  179. flag = wx.ALL | wx.ALIGN_RIGHT,
  180. border = 5)
  181. gridSizer.AddGrowableCol(2)
  182. gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
  183. flag = wx.EXPAND)
  184. # body
  185. boxSizer.Add(item = gridSizer, proportion = 1,
  186. flag = wx.ALL | wx.EXPAND, border = 2)
  187. pageSizer.Add(item = boxSizer, proportion = 0,
  188. flag = wx.EXPAND | wx.ALL,
  189. border = 3)
  190. box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  191. label = " %s " % (_("Image Appearance")))
  192. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  193. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  194. gridSizer.AddGrowableCol(0)
  195. # background color
  196. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  197. label = _("Background color:")),
  198. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  199. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  200. colour = UserSettings.Get(group = 'nviz', key = 'view',
  201. subkey = ['background', 'color']),
  202. size = globalvar.DIALOG_COLOR_SIZE)
  203. self.win['view']['bgcolor'] = color.GetId()
  204. color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
  205. gridSizer.Add(item = color, pos = (0, 1))
  206. boxSizer.Add(item = gridSizer, proportion = 1,
  207. flag = wx.ALL | wx.EXPAND, border = 3)
  208. pageSizer.Add(item = boxSizer, proportion = 0,
  209. flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
  210. border = 3)
  211. panel.SetSizer(pageSizer)
  212. return panel
  213. def _createDataPage(self):
  214. """!Create data (surface, vector, volume) settings page"""
  215. if globalvar.hasAgw:
  216. self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
  217. agwStyle = globalvar.FNPageDStyle)
  218. else:
  219. self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
  220. style = globalvar.FNPageDStyle)
  221. # surface page
  222. self.notebookData.AddPage(page = self._createSurfacePage(),
  223. text = " %s " % _("Surface"))
  224. self.EnablePage('surface', False)
  225. # vector page
  226. self.notebookData.AddPage(page = self._createVectorPage(),
  227. text = " %s " % _("Vector"))
  228. self.EnablePage('vector', False)
  229. # volume page
  230. self.notebookData.AddPage(page = self._createVolumePage(),
  231. text = " %s " % _("Volume"))
  232. self.EnablePage('volume', False)
  233. return self.notebookData
  234. def _createAppearancePage(self):
  235. """!Create data (surface, vector, volume) settings page"""
  236. if globalvar.hasAgw:
  237. self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
  238. agwStyle = globalvar.FNPageDStyle)
  239. else:
  240. self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
  241. style = globalvar.FNPageDStyle)
  242. # light page
  243. self.notebookAppearance.AddPage(page = self._createLightPage(),
  244. text = " %s " % _("Lighting"))
  245. # fringe page
  246. self.notebookAppearance.AddPage(page = self._createFringePage(),
  247. text = " %s " % _("Fringe"))
  248. return self.notebookAppearance
  249. def _createSurfacePage(self):
  250. """!Create view settings page"""
  251. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  252. panel.SetupScrolling(scroll_x = False)
  253. self.page['surface'] = { 'id' : 0,
  254. 'panel' : panel.GetId(),
  255. 'notebook' : self.notebookData.GetId() }
  256. pageSizer = wx.BoxSizer(wx.VERTICAL)
  257. self.win['surface'] = {}
  258. # selection
  259. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  260. label = " %s " % (_("Raster map")))
  261. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  262. rmaps = gselect.Select(parent = panel, type = 'raster',
  263. onPopup = self.GselectOnPopup)
  264. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster)
  265. self.win['surface']['map'] = rmaps.GetId()
  266. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  267. self.win['surface']['desc'] = desc.GetId()
  268. boxSizer.Add(item = rmaps, proportion = 0,
  269. flag = wx.ALL,
  270. border = 3)
  271. boxSizer.Add(item = desc, proportion = 0,
  272. flag = wx.ALL,
  273. border = 3)
  274. pageSizer.Add(item = boxSizer, proportion = 0,
  275. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  276. border = 3)
  277. #
  278. # surface attributes
  279. #
  280. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  281. label = " %s " % (_("Surface attributes")))
  282. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  283. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  284. # type
  285. self.win['surface']['attr'] = {}
  286. row = 0
  287. for code, attrb in (('topo', _("Topography")),
  288. ('color', _("Color")),
  289. ('mask', _("Mask")),
  290. ('transp', _("Transparency")),
  291. ('shine', _("Shininess")),
  292. ('emit', _("Emission"))):
  293. self.win['surface'][code] = {}
  294. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  295. label = attrb + ':'),
  296. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  297. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  298. choices = [_("map")])
  299. if code not in ('topo', 'color', 'shine'):
  300. use.Insert(item = _("unset"), pos = 0)
  301. self.win['surface'][code]['required'] = False
  302. else:
  303. self.win['surface'][code]['required'] = True
  304. if code != 'mask':
  305. use.Append(item = _('constant'))
  306. self.win['surface'][code]['use'] = use.GetId()
  307. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  308. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  309. pos = (row, 1))
  310. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  311. # size = globalvar.DIALOG_GSELECT_SIZE,
  312. size = (200, -1),
  313. type = "raster")
  314. self.win['surface'][code]['map'] = map.GetId() - 1 # FIXME
  315. map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  316. # changing map topography not allowed
  317. if code == 'topo':
  318. map.Enable(False)
  319. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
  320. pos = (row, 2))
  321. if code == 'color':
  322. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  323. colour = (0,0,0),
  324. size = globalvar.DIALOG_COLOR_SIZE)
  325. value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
  326. elif code == 'mask':
  327. value = None
  328. else:
  329. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  330. initial = 0)
  331. if code == 'topo':
  332. value.SetRange(minVal = -1e9, maxVal = 1e9)
  333. elif code in ('shine', 'transp', 'emit'):
  334. value.SetRange(minVal = 0, maxVal = 255)
  335. else:
  336. value.SetRange(minVal = 0, maxVal = 100)
  337. value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  338. if value:
  339. self.win['surface'][code]['const'] = value.GetId()
  340. value.Enable(False)
  341. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  342. pos = (row, 3))
  343. else:
  344. self.win['surface'][code]['const'] = None
  345. self.SetMapObjUseMap(nvizType = 'surface',
  346. attrb = code) # -> enable map / disable constant
  347. row += 1
  348. boxSizer.Add(item = gridSizer, proportion = 1,
  349. flag = wx.ALL | wx.EXPAND, border = 3)
  350. pageSizer.Add(item = boxSizer, proportion = 0,
  351. flag = wx.EXPAND | wx.ALL,
  352. border = 3)
  353. #
  354. # draw
  355. #
  356. self.win['surface']['draw'] = {}
  357. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  358. label = " %s " % (_("Draw")))
  359. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  360. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  361. gridSizer.AddGrowableCol(6)
  362. # mode
  363. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  364. label = _("Mode:")),
  365. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  366. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  367. choices = [_("coarse"),
  368. _("fine"),
  369. _("both")])
  370. mode.SetSelection(0)
  371. mode.SetName("selection")
  372. mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  373. self.win['surface']['draw']['mode'] = mode.GetId()
  374. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
  375. pos = (0, 1))
  376. # shading
  377. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  378. label = _("Shading:")),
  379. pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  380. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  381. choices = [_("flat"),
  382. _("gouraud")])
  383. shade.SetName("selection")
  384. self.win['surface']['draw']['shading'] = shade.GetId()
  385. shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  386. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  387. pos = (0, 3))
  388. # set to all
  389. all = wx.Button(panel, id = wx.ID_ANY, label = _("Set to all"))
  390. all.SetToolTipString(_("Use draw settings for all loaded surfaces"))
  391. all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
  392. gridSizer.Add(item = all, flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  393. pos = (0, 4), span = (1,2), border = 3 )
  394. # resolution coarse
  395. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  396. label = _("Coarse:")),
  397. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  398. resSizer = wx.BoxSizer(wx.HORIZONTAL)
  399. resSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  400. label = _("res.")),
  401. flag = wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL,
  402. border = 3)
  403. resC = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  404. initial = 6,
  405. min = 1,
  406. max = 100)
  407. resC.SetName("value")
  408. resC.SetValue(6)
  409. self.win['surface']['draw']['res-coarse'] = resC.GetId()
  410. resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  411. resSizer.Add(item = resC, flag = wx.ALL | wx.ALIGN_LEFT |
  412. wx.ALIGN_CENTER_VERTICAL, border = 3)
  413. gridSizer.Add(item = resSizer, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  414. # Coarse style
  415. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  416. label = _("style")),
  417. pos = (1, 2), flag = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
  418. style = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  419. choices = [_("wire"),
  420. _("surface")])
  421. style.SetName("selection")
  422. self.win['surface']['draw']['style'] = style.GetId()
  423. style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  424. gridSizer.Add(item = style, flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  425. pos = (1, 3))
  426. # color
  427. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  428. label = _("wire color")),
  429. pos = (1, 4), flag = wx.ALIGN_CENTER_VERTICAL |
  430. wx.ALIGN_RIGHT | wx.LEFT, border = 3)
  431. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  432. size = globalvar.DIALOG_COLOR_SIZE)
  433. color.SetColour((136,136,136))
  434. color.SetName("colour")
  435. color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
  436. self.win['surface']['draw']['wire-color'] = color.GetId()
  437. gridSizer.Add(item = color, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  438. pos = (1, 5))
  439. # resolution fine
  440. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  441. label = _("Fine:")),
  442. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  443. resSizer = wx.BoxSizer(wx.HORIZONTAL)
  444. resSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  445. label = _("res.")),
  446. flag = wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL,
  447. border = 3)
  448. resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  449. initial = 3,
  450. min = 1,
  451. max = 100)
  452. resF.SetName("value")
  453. resF.SetValue(3)
  454. self.win['surface']['draw']['res-fine'] = resF.GetId()
  455. resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  456. resSizer.Add(item = resF, flag = wx.ALL | wx.ALIGN_LEFT |
  457. wx.ALIGN_CENTER_VERTICAL, border = 3)
  458. gridSizer.Add(item = resSizer, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  459. boxSizer.Add(item = gridSizer, proportion = 1,
  460. flag = wx.ALL | wx.EXPAND, border = 3)
  461. pageSizer.Add(item = boxSizer, proportion = 0,
  462. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  463. border = 3)
  464. #
  465. # mask
  466. #
  467. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  468. label = " %s " % (_("Mask")))
  469. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  470. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  471. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  472. label = _("Mask zeros:")),
  473. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  474. elev = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  475. label = _("by elevation"))
  476. elev.Enable(False) # TODO: not implemented yet
  477. gridSizer.Add(item = elev, pos = (0, 1))
  478. color = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  479. label = _("by color"))
  480. color.Enable(False) # TODO: not implemented yet
  481. gridSizer.Add(item = color, pos = (0, 2))
  482. boxSizer.Add(item = gridSizer, proportion = 1,
  483. flag = wx.ALL | wx.EXPAND, border = 3)
  484. pageSizer.Add(item = boxSizer, proportion = 0,
  485. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  486. border = 3)
  487. #
  488. # position
  489. #
  490. self.win['surface']['position'] = {}
  491. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  492. label = " %s " % (_("Position")))
  493. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  494. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  495. # position
  496. self._createControl(panel, data = self.win['surface'], name = 'position',
  497. range = (-10000, 10000),
  498. bind = (self.OnSurfacePosition, self.OnSurfacePosition, self.OnSurfacePosition))
  499. axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
  500. choices = ["X",
  501. "Y",
  502. "Z"])
  503. self.win['surface']['position']['axis'] = axis.GetId()
  504. axis.SetSelection(0)
  505. axis.Bind(wx.EVT_CHOICE, self.OnSurfaceAxis)
  506. pslide = self.FindWindowById(self.win['surface']['position']['slider'])
  507. pspin = self.FindWindowById(self.win['surface']['position']['spin'])
  508. gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  509. gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
  510. gridSizer.Add(item = pspin, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
  511. boxSizer.Add(item = gridSizer, proportion = 1,
  512. flag = wx.ALL | wx.EXPAND, border = 3)
  513. box.SetSizer(boxSizer)
  514. box.Layout()
  515. pageSizer.Add(item = boxSizer, proportion = 0,
  516. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  517. border = 3)
  518. panel.SetSizer(pageSizer)
  519. return panel
  520. def _createVectorPage(self):
  521. """!Create view settings page"""
  522. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  523. panel.SetupScrolling(scroll_x = False)
  524. self.page['vector'] = { 'id' : 1,
  525. 'panel' : panel.GetId(),
  526. 'notebook' : self.notebookData.GetId() }
  527. pageSizer = wx.BoxSizer(wx.VERTICAL)
  528. self.win['vector'] = {}
  529. # selection
  530. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  531. label = " %s " % (_("Vector map")))
  532. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  533. vmaps = gselect.Select(parent = panel, type = 'vector',
  534. onPopup = self.GselectOnPopup)
  535. vmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetVector)
  536. self.win['vector']['map'] = vmaps.GetId()
  537. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  538. self.win['vector']['desc'] = desc.GetId()
  539. boxSizer.Add(item = vmaps, proportion = 0,
  540. flag = wx.ALL,
  541. border = 3)
  542. boxSizer.Add(item = desc, proportion = 0,
  543. flag = wx.ALL,
  544. border = 3)
  545. pageSizer.Add(item = boxSizer, proportion = 0,
  546. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  547. border = 3)
  548. #
  549. # vector lines
  550. #
  551. self.win['vector']['lines'] = {}
  552. showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  553. label = _("Show vector lines"))
  554. showLines.SetValue(True)
  555. self.win['vector']['lines']['show'] = showLines.GetId()
  556. showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  557. pageSizer.Add(item = showLines, proportion = 0,
  558. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  559. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  560. label = " %s " % (_("Vector lines")))
  561. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  562. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  563. # width
  564. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  565. label = _("Line:")),
  566. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  567. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  568. label = _("width")),
  569. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  570. wx.ALIGN_RIGHT)
  571. width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  572. initial = 1,
  573. min = 0,
  574. max = 100)
  575. width.SetValue(1)
  576. self.win['vector']['lines']['width'] = width.GetId()
  577. width.Bind(wx.EVT_SPINCTRL, self.OnVectorLines)
  578. gridSizer.Add(item = width, pos = (0, 2),
  579. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  580. # color
  581. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  582. label = _("color")),
  583. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  584. wx.ALIGN_RIGHT)
  585. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  586. colour = (0,0,0),
  587. size = globalvar.DIALOG_COLOR_SIZE)
  588. self.win['vector']['lines']['color'] = color.GetId()
  589. color.Bind(csel.EVT_COLOURSELECT, self.OnVectorLines)
  590. gridSizer.Add(item = color, pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL |
  591. wx.ALIGN_LEFT)
  592. # display
  593. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  594. label = _("display")),
  595. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  596. wx.ALIGN_RIGHT)
  597. display = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  598. choices = [_("on surface"),
  599. _("flat")])
  600. self.win['vector']['lines']['flat'] = display.GetId()
  601. display.Bind(wx.EVT_CHOICE, self.OnVectorDisplay)
  602. gridSizer.Add(item = display, flag = wx.ALIGN_CENTER_VERTICAL |
  603. wx.ALIGN_LEFT, pos = (1, 2), span = (1,2))
  604. # height
  605. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  606. label = _("Height above surface:")),
  607. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL,
  608. span = (1, 3))
  609. surface = wx.ComboBox(parent = panel, id = wx.ID_ANY, size = (250, -1),
  610. style = wx.CB_SIMPLE | wx.CB_READONLY,
  611. choices = [])
  612. surface.Bind(wx.EVT_COMBOBOX, self.OnVectorSurface)
  613. self.win['vector']['lines']['surface'] = surface.GetId()
  614. gridSizer.Add(item = surface,
  615. pos = (2, 3), span = (1, 6),
  616. flag = wx.ALIGN_CENTER_VERTICAL)
  617. self._createControl(panel, data = self.win['vector']['lines'], name = 'height', size = 300,
  618. range = (0, 1000),
  619. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
  620. self.FindWindowById(self.win['vector']['lines']['height']['slider']).SetValue(0)
  621. self.FindWindowById(self.win['vector']['lines']['height']['spin']).SetValue(0)
  622. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['slider']),
  623. pos = (3, 0), span = (1, 7))
  624. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['spin']),
  625. pos = (3, 7),
  626. flag = wx.ALIGN_CENTER)
  627. boxSizer.Add(item = gridSizer, proportion = 1,
  628. flag = wx.ALL | wx.EXPAND, border = 3)
  629. pageSizer.Add(item = boxSizer, proportion = 0,
  630. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  631. border = 3)
  632. #
  633. # vector points
  634. #
  635. self.win['vector']['points'] = {}
  636. showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  637. label = _("Show vector points"))
  638. showPoints.SetValue(True)
  639. self.win['vector']['points']['show'] = showPoints.GetId()
  640. showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  641. pageSizer.Add(item = showPoints, proportion = 0,
  642. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  643. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  644. label = " %s " % (_("Vector points")))
  645. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  646. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  647. # icon size
  648. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  649. label = _("Icon:")),
  650. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  651. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  652. label = _("size")),
  653. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  654. wx.ALIGN_RIGHT)
  655. isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  656. initial = 1,
  657. min = 1,
  658. max = 1e6)
  659. isize.SetName('value')
  660. isize.SetValue(100)
  661. self.win['vector']['points']['size'] = isize.GetId()
  662. isize.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  663. isize.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  664. gridSizer.Add(item = isize, pos = (0, 2),
  665. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  666. # icon color
  667. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  668. label = _("color")),
  669. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  670. wx.ALIGN_RIGHT)
  671. icolor = csel.ColourSelect(panel, id = wx.ID_ANY,
  672. size = globalvar.DIALOG_COLOR_SIZE)
  673. icolor.SetName("color")
  674. icolor.SetColour((0,0,255))
  675. self.win['vector']['points']['color'] = icolor.GetId()
  676. icolor.Bind(csel.EVT_COLOURSELECT, self.OnVectorPoints)
  677. gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL |
  678. wx.ALIGN_LEFT,
  679. pos = (0, 4))
  680. # icon width
  681. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  682. label = _("width")),
  683. pos = (0, 5), flag = wx.ALIGN_CENTER_VERTICAL |
  684. wx.ALIGN_RIGHT)
  685. iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  686. initial = 1,
  687. min = 1,
  688. max = 1e6)
  689. iwidth.SetName('value')
  690. iwidth.SetValue(100)
  691. self.win['vector']['points']['width'] = iwidth.GetId()
  692. iwidth.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  693. iwidth.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  694. gridSizer.Add(item = iwidth, pos = (0, 6),
  695. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  696. # icon symbol
  697. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  698. label = _("symbol")),
  699. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  700. isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  701. choices = UserSettings.Get(group = 'nviz', key = 'vector',
  702. subkey = ['points', 'marker'], internal = True))
  703. isym.SetName("selection")
  704. self.win['vector']['points']['marker'] = isym.GetId()
  705. isym.Bind(wx.EVT_CHOICE, self.OnVectorPoints)
  706. gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL,
  707. pos = (1, 2), span = (1,2))
  708. # high
  709. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  710. label = _("Height above surface:")),
  711. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL,
  712. span = (1, 3))
  713. surface = wx.ComboBox(parent = panel, id = wx.ID_ANY, size = (250, -1),
  714. style = wx.CB_SIMPLE | wx.CB_READONLY,
  715. choices = [])
  716. surface.Bind(wx.EVT_COMBOBOX, self.OnVectorSurface)
  717. self.win['vector']['points']['surface'] = surface.GetId()
  718. gridSizer.Add(item = surface,
  719. pos = (2, 3), span = (1, 5),
  720. flag = wx.ALIGN_CENTER_VERTICAL)
  721. self._createControl(panel, data = self.win['vector']['points'], name = 'height', size = 300,
  722. range = (0, 1000),
  723. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
  724. self.FindWindowById(self.win['vector']['points']['height']['slider']).SetValue(0)
  725. self.FindWindowById(self.win['vector']['points']['height']['spin']).SetValue(0)
  726. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['slider']),
  727. pos = (3, 0), span = (1, 7))
  728. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['spin']),
  729. pos = (3, 7),
  730. flag = wx.ALIGN_CENTER)
  731. boxSizer.Add(item = gridSizer, proportion = 1,
  732. flag = wx.ALL | wx.EXPAND, border = 3)
  733. pageSizer.Add(item = boxSizer, proportion = 0,
  734. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  735. border = 3)
  736. panel.SetSizer(pageSizer)
  737. return panel
  738. def GselectOnPopup(self, ltype, exclude = False):
  739. """Update gselect.Select() items"""
  740. maps = list()
  741. for layer in self.mapWindow.Map.GetListOfLayers(l_type = ltype):
  742. maps.append(layer.GetName())
  743. return maps, exclude
  744. def _createVolumePage(self):
  745. """!Create view settings page"""
  746. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  747. panel.SetupScrolling(scroll_x = False)
  748. self.page['volume'] = { 'id' : 2,
  749. 'panel' : panel.GetId(),
  750. 'notebook' : self.notebookData.GetId() }
  751. pageSizer = wx.BoxSizer(wx.VERTICAL)
  752. self.win['volume'] = {}
  753. # selection
  754. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  755. label = " %s " % (_("3D raster map")))
  756. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  757. rmaps = gselect.Select(parent = panel, type = 'raster3D',
  758. onPopup = self.GselectOnPopup)
  759. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster3D)
  760. self.win['volume']['map'] = rmaps.GetId()
  761. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  762. self.win['volume']['desc'] = desc.GetId()
  763. boxSizer.Add(item = rmaps, proportion = 0,
  764. flag = wx.ALL,
  765. border = 3)
  766. boxSizer.Add(item = desc, proportion = 0,
  767. flag = wx.ALL,
  768. border = 3)
  769. pageSizer.Add(item = boxSizer, proportion = 0,
  770. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  771. border = 3)
  772. #
  773. # draw
  774. #
  775. self.win['volume']['draw'] = {}
  776. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  777. label = " %s " % (_("Draw")))
  778. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  779. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  780. gridSizer.AddGrowableCol(4)
  781. # mode
  782. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  783. label = _("Mode:")),
  784. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  785. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (150, -1),
  786. choices = [_("isosurfaces"),
  787. _("slides")])
  788. mode.SetSelection(0)
  789. mode.SetName("selection")
  790. # mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  791. self.win['volume']['draw']['mode'] = mode.GetId()
  792. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
  793. pos = (0, 1))
  794. # shading
  795. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  796. label = _("Shading:")),
  797. pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  798. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  799. choices = [_("flat"),
  800. _("gouraud")])
  801. shade.SetName("selection")
  802. self.win['volume']['draw']['shading'] = shade.GetId()
  803. shade.Bind(wx.EVT_CHOICE, self.OnVolumeIsosurfMode)
  804. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  805. pos = (0, 3))
  806. # resolution (mode)
  807. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  808. label = _("Resolution:")),
  809. pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL)
  810. resol = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  811. initial = 1,
  812. min = 1,
  813. max = 100)
  814. resol.SetName("value")
  815. self.win['volume']['draw']['resolution'] = resol.GetId()
  816. resol.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfResolution)
  817. resol.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfResolution)
  818. gridSizer.Add(item = resol, pos = (0, 5))
  819. boxSizer.Add(item = gridSizer, proportion = 1,
  820. flag = wx.ALL | wx.EXPAND, border = 3)
  821. pageSizer.Add(item = boxSizer, proportion = 0,
  822. flag = wx.EXPAND | wx.ALL,
  823. border = 3)
  824. #
  825. # manage isosurfaces
  826. #
  827. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  828. label = " %s " % (_("List of isosurfaces")))
  829. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  830. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  831. # list
  832. isolevel = wx.CheckListBox(parent = panel, id = wx.ID_ANY,
  833. size = (300, 150))
  834. self.Bind(wx.EVT_CHECKLISTBOX, self.OnVolumeIsosurfCheck, isolevel)
  835. self.Bind(wx.EVT_LISTBOX, self.OnVolumeIsosurfSelect, isolevel)
  836. self.win['volume']['isosurfs'] = isolevel.GetId()
  837. gridSizer.Add(item = isolevel, pos = (0, 0), span = (4, 1))
  838. # buttons (add, delete, move up, move down)
  839. btnAdd = wx.Button(parent = panel, id = wx.ID_ADD)
  840. self.win['volume']['btnIsosurfAdd'] = btnAdd.GetId()
  841. btnAdd.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfAdd)
  842. gridSizer.Add(item = btnAdd,
  843. pos = (0, 1))
  844. btnDelete = wx.Button(parent = panel, id = wx.ID_DELETE)
  845. self.win['volume']['btnIsosurfDelete'] = btnDelete.GetId()
  846. btnDelete.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfDelete)
  847. btnDelete.Enable(False)
  848. gridSizer.Add(item = btnDelete,
  849. pos = (1, 1))
  850. btnMoveUp = wx.Button(parent = panel, id = wx.ID_UP)
  851. self.win['volume']['btnIsosurfMoveUp'] = btnMoveUp.GetId()
  852. btnMoveUp.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveUp)
  853. btnMoveUp.Enable(False)
  854. gridSizer.Add(item = btnMoveUp,
  855. pos = (2, 1))
  856. btnMoveDown = wx.Button(parent = panel, id = wx.ID_DOWN)
  857. self.win['volume']['btnIsosurfMoveDown'] = btnMoveDown.GetId()
  858. btnMoveDown.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveDown)
  859. btnMoveDown.Enable(False)
  860. gridSizer.Add(item = btnMoveDown,
  861. pos = (3, 1))
  862. boxSizer.Add(item = gridSizer, proportion = 1,
  863. flag = wx.ALL | wx.EXPAND, border = 3)
  864. pageSizer.Add(item = boxSizer, proportion = 0,
  865. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  866. border = 3)
  867. #
  868. # isosurface attributes
  869. #
  870. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  871. label = " %s " % (_("Isosurface attributes")))
  872. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  873. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  874. self.win['volume']['attr'] = {}
  875. row = 0
  876. for code, attrb in (('topo', _("Topography level")),
  877. ('color', _("Color")),
  878. ('mask', _("Mask")),
  879. ('transp', _("Transparency")),
  880. ('shine', _("Shininess")),
  881. ('emit', _("Emission"))):
  882. self.win['volume'][code] = {}
  883. # label
  884. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  885. label = attrb + ':'),
  886. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  887. if code != 'topo':
  888. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  889. choices = [_("map")])
  890. else:
  891. use = None
  892. # check for required properties
  893. if code not in ('topo', 'color', 'shine'):
  894. use.Insert(item = _("unset"), pos = 0)
  895. self.win['volume'][code]['required'] = False
  896. else:
  897. self.win['volume'][code]['required'] = True
  898. if use and code != 'mask':
  899. use.Append(item = _('constant'))
  900. if use:
  901. self.win['volume'][code]['use'] = use.GetId()
  902. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  903. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  904. pos = (row, 1))
  905. if code != 'topo':
  906. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  907. # size = globalvar.DIALOG_GSELECT_SIZE,
  908. size = (200, -1),
  909. type = "grid3")
  910. self.win['volume'][code]['map'] = map.GetId() - 1 # FIXME
  911. map.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  912. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
  913. pos = (row, 2))
  914. else:
  915. map = None
  916. if code == 'color':
  917. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  918. colour = (0,0,0),
  919. size = globalvar.DIALOG_COLOR_SIZE)
  920. value.Bind(csel.EVT_COLOURSELECT, self.OnVolumeIsosurfMap)
  921. elif code == 'mask':
  922. value = None
  923. else:
  924. if code == 'topo':
  925. size = (200, -1)
  926. else:
  927. size = (65, -1)
  928. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = size,
  929. initial = 0)
  930. if code == 'topo':
  931. value.SetRange(minVal = -1e9, maxVal = 1e9)
  932. elif code in ('shine', 'transp', 'emit'):
  933. value.SetRange(minVal = 0, maxVal = 255)
  934. else:
  935. value.SetRange(minVal = 0, maxVal = 100)
  936. value.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfMap)
  937. value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  938. if value:
  939. self.win['volume'][code]['const'] = value.GetId()
  940. if code == 'topo':
  941. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  942. pos = (row, 2))
  943. else:
  944. value.Enable(False)
  945. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  946. pos = (row, 3))
  947. else:
  948. self.win['volume'][code]['const'] = None
  949. if code != 'topo':
  950. self.SetMapObjUseMap(nvizType = 'volume',
  951. attrb = code) # -> enable map / disable constant
  952. row += 1
  953. boxSizer.Add(item = gridSizer, proportion = 1,
  954. flag = wx.ALL | wx.EXPAND, border = 3)
  955. pageSizer.Add(item = boxSizer, proportion = 0,
  956. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  957. border = 3)
  958. panel.SetSizer(pageSizer)
  959. return panel
  960. def _createLightPage(self):
  961. """!Create light page"""
  962. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  963. panel.SetupScrolling(scroll_x = False)
  964. self.page['light'] = { 'id' : 0,
  965. 'notebook' : self.notebookAppearance.GetId() }
  966. self.win['light'] = {}
  967. pageSizer = wx.BoxSizer(wx.VERTICAL)
  968. show = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  969. label = _("Show light model"))
  970. show.Bind(wx.EVT_CHECKBOX, self.OnShowLightModel)
  971. pageSizer.Add(item = show, proportion = 0,
  972. flag = wx.ALL, border = 3)
  973. surface = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  974. label = _("Follow source viewpoint"))
  975. pageSizer.Add(item = surface, proportion = 0,
  976. flag = wx.ALL, border = 3)
  977. # position
  978. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  979. label = " %s " % (_("Light source position")))
  980. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  981. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  982. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  983. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("W")),
  984. pos = (1, 0), flag = wx.ALIGN_CENTER)
  985. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
  986. pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
  987. pos = LightPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
  988. mapwindow = self.mapWindow)
  989. self.win['light']['position'] = pos.GetId()
  990. posSizer.Add(item = pos,
  991. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  992. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
  993. pos = (2, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_TOP)
  994. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("E")),
  995. pos = (1, 2), flag = wx.ALIGN_CENTER)
  996. gridSizer.Add(item = posSizer, pos = (0, 0))
  997. # height
  998. self._createControl(panel, data = self.win['light'], name = 'z', sliderHor = False,
  999. range = (0, 100),
  1000. bind = (self.OnLightChange, None, self.OnLightChange))
  1001. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1002. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  1003. pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
  1004. heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['slider']),
  1005. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  1006. heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['spin']),
  1007. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  1008. wx.BOTTOM | wx.RIGHT, pos = (1, 1))
  1009. gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_RIGHT)
  1010. boxSizer.Add(item = gridSizer, proportion = 1,
  1011. flag = wx.ALL | wx.EXPAND, border = 2)
  1012. pageSizer.Add(item = boxSizer, proportion = 0,
  1013. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1014. border = 3)
  1015. # position
  1016. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1017. label = " %s " % (_("Light color and intensity")))
  1018. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1019. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1020. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:")),
  1021. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1022. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  1023. colour = UserSettings.Get(group = 'nviz', key = 'light',
  1024. subkey = 'color'),
  1025. size = globalvar.DIALOG_COLOR_SIZE)
  1026. color.Bind(csel.EVT_COLOURSELECT, self.OnLightColor)
  1027. gridSizer.Add(item = color, pos = (0, 2))
  1028. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Brightness:")),
  1029. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1030. self._createControl(panel, data = self.win['light'], name = 'bright', size = 300,
  1031. range = (0, 100),
  1032. bind = (self.OnLightValue, None, self.OnLightValue))
  1033. gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['slider']),
  1034. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1035. gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['spin']),
  1036. pos = (1, 2),
  1037. flag = wx.ALIGN_CENTER)
  1038. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Ambient:")),
  1039. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1040. self._createControl(panel, data = self.win['light'], name = 'ambient', size = 300,
  1041. range = (0, 100),
  1042. bind = (self.OnLightValue, None, self.OnLightValue))
  1043. gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['slider']),
  1044. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1045. gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['spin']),
  1046. pos = (2, 2),
  1047. flag = wx.ALIGN_CENTER)
  1048. boxSizer.Add(item = gridSizer, proportion = 1,
  1049. flag = wx.ALL | wx.EXPAND, border = 2)
  1050. pageSizer.Add(item = boxSizer, proportion = 0,
  1051. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1052. border = 3)
  1053. # reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  1054. # reset.SetToolTipString(_("Reset to default view"))
  1055. # # self.win['reset'] = reset.GetId()
  1056. # reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  1057. # viewSizer.Add(item = reset, proportion = 1,
  1058. # flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT,
  1059. # border = 5)
  1060. # gridSizer.AddGrowableCol(3)
  1061. # gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
  1062. # flag = wx.EXPAND)
  1063. panel.SetSizer(pageSizer)
  1064. return panel
  1065. def _createFringePage(self):
  1066. """!Create fringe page"""
  1067. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  1068. panel.SetupScrolling(scroll_x = False)
  1069. self.page['fringe'] = { 'id' : 1,
  1070. 'notebook' : self.notebookAppearance.GetId() }
  1071. self.win['fringe'] = {}
  1072. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1073. # selection
  1074. rbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1075. label = " %s " % (_("Surface")))
  1076. rboxSizer = wx.StaticBoxSizer(rbox, wx.VERTICAL)
  1077. rmaps = gselect.Select(parent = panel, type = 'raster',
  1078. onPopup = self.GselectOnPopup)
  1079. self.win['fringe']['surface'] = rmaps.GetId()
  1080. rboxSizer.Add(item = rmaps, proportion = 0,
  1081. flag = wx.ALL,
  1082. border = 3)
  1083. pageSizer.Add(item = rboxSizer, proportion = 0,
  1084. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1085. border = 3)
  1086. ebox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1087. label = " %s " % (_("Edges with fringe")))
  1088. eboxSizer = wx.StaticBoxSizer(ebox, wx.HORIZONTAL)
  1089. for edge in [(_("N && W"), "nw"),
  1090. (_("N && E"), "ne"),
  1091. (_("S && W"), "sw"),
  1092. (_("S && E"), "se")]:
  1093. chkbox = wx.CheckBox(parent = panel,
  1094. label = edge[0],
  1095. name = edge[1])
  1096. self.win['fringe'][edge[1]] = chkbox.GetId()
  1097. eboxSizer.Add(item = chkbox, proportion = 0,
  1098. flag = wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT, border = 5)
  1099. chkbox.Bind(wx.EVT_CHECKBOX, self.OnFringe)
  1100. pageSizer.Add(item = eboxSizer, proportion = 0,
  1101. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1102. border = 3)
  1103. sbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1104. label = " %s " % (_("Settings")))
  1105. sboxSizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
  1106. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  1107. # elevation
  1108. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1109. label = _("Elevation of fringe from bottom:")),
  1110. pos = (0, 0),
  1111. flag = wx.ALIGN_CENTER_VERTICAL)
  1112. spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
  1113. size = (65, -1), min = -1e6, max = 1e6)
  1114. spin.SetValue(UserSettings.Get(group = 'nviz', key = 'fringe', subkey = 'elev'))
  1115. spin.Bind(wx.EVT_SPINCTRL, self.OnFringe)
  1116. self.win['fringe']['elev'] = spin.GetId()
  1117. gridSizer.Add(item = spin, pos = (0, 1))
  1118. # color
  1119. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1120. label = _("Color:")),
  1121. pos = (1, 0),
  1122. flag = wx.ALIGN_CENTER_VERTICAL)
  1123. color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  1124. size = globalvar.DIALOG_COLOR_SIZE)
  1125. color.SetColour(UserSettings.Get(group = 'nviz', key = 'fringe',
  1126. subkey = 'color'))
  1127. color.Bind(csel.EVT_COLOURSELECT, self.OnFringe)
  1128. self.win['fringe']['color'] = color.GetId()
  1129. gridSizer.Add(item = color, pos = (1, 1))
  1130. sboxSizer.Add(item = gridSizer, proportion = 1,
  1131. flag = wx.ALL | wx.EXPAND, border = 3)
  1132. pageSizer.Add(item = sboxSizer, proportion = 0,
  1133. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1134. border = 3)
  1135. panel.SetSizer(pageSizer)
  1136. return panel
  1137. def GetLayerData(self, nvizType):
  1138. """!Get nviz data"""
  1139. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1140. if nvizType == 'surface':
  1141. return self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1142. elif nvizType == 'vector':
  1143. return self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')
  1144. elif nvizType == 'volume':
  1145. return self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  1146. return None
  1147. def OnFringe(self, event):
  1148. """!Show/hide fringe"""
  1149. enabled = event.IsChecked()
  1150. win = self.FindWindowById(event.GetId())
  1151. data = self.GetLayerData('surface')['surface']
  1152. sid = data['object']['id']
  1153. elev = self.FindWindowById(self.win['fringe']['elev']).GetValue()
  1154. color = self.FindWindowById(self.win['fringe']['color']).GetValue()
  1155. self._display.SetFringe(sid, color, elev,
  1156. self.FindWindowById(self.win['fringe']['nw']).IsChecked(),
  1157. self.FindWindowById(self.win['fringe']['ne']).IsChecked(),
  1158. self.FindWindowById(self.win['fringe']['sw']).IsChecked(),
  1159. self.FindWindowById(self.win['fringe']['se']).IsChecked())
  1160. self.mapWindow.Refresh(False)
  1161. def OnScroll(self, event, win, data):
  1162. """!Generic scrolling handler"""
  1163. winName = self.__GetWindowName(win, event.GetId())
  1164. if not winName:
  1165. return
  1166. data[winName] = event.GetInt()
  1167. for w in win[winName].itervalues():
  1168. self.FindWindowById(w).SetValue(data[winName])
  1169. event.Skip()
  1170. def _createControl(self, parent, data, name, range, bind = (None, None, None),
  1171. sliderHor = True, size = 200):
  1172. """!Add control (Slider + SpinCtrl)"""
  1173. data[name] = dict()
  1174. if sliderHor:
  1175. style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  1176. wx.SL_BOTTOM
  1177. sizeW = (size, -1)
  1178. else:
  1179. style = wx.SL_VERTICAL | wx.SL_AUTOTICKS | \
  1180. wx.SL_INVERSE
  1181. sizeW = (-1, size)
  1182. slider = wx.Slider(parent = parent, id = wx.ID_ANY,
  1183. minValue = range[0],
  1184. maxValue = range[1],
  1185. style = style,
  1186. size = sizeW)
  1187. slider.SetName('slider')
  1188. if bind[0]:
  1189. slider.Bind(wx.EVT_SCROLL, bind[0])
  1190. # slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, bind[1])
  1191. if bind[1]:
  1192. slider.Bind(wx.EVT_SCROLL_CHANGED, bind[1]) # this only works in MSW
  1193. data[name]['slider'] = slider.GetId()
  1194. spin = wx.SpinCtrl(parent = parent, id = wx.ID_ANY, size = (65, -1),
  1195. min = range[0],
  1196. max = range[1])
  1197. # no 'changed' event ... (FIXME)
  1198. spin.SetName('spin')
  1199. if bind[2]:
  1200. spin.Bind(wx.EVT_SPINCTRL, bind[2])
  1201. data[name]['spin'] = spin.GetId()
  1202. def __GetWindowName(self, data, id):
  1203. for name in data.iterkeys():
  1204. if type(data[name]) is type({}):
  1205. for win in data[name].itervalues():
  1206. if win == id:
  1207. return name
  1208. else:
  1209. if data[name] == id:
  1210. return name
  1211. return None
  1212. def UpdateSettings(self):
  1213. """!Update view from settings values
  1214. stored in self.mapWindow.view dictionary"""
  1215. for control in ('height',
  1216. 'persp',
  1217. 'twist',
  1218. 'z-exag'):
  1219. for win in self.win['view'][control].itervalues():
  1220. if control == 'height':
  1221. value = UserSettings.Get(group = 'nviz', key = 'view',
  1222. subkey = ['height', 'value'], internal = True)
  1223. else:
  1224. try:
  1225. value = self.mapWindow.view[control]['value']
  1226. except KeyError:
  1227. value = -1
  1228. self.FindWindowById(win).SetValue(value)
  1229. viewWin = self.FindWindowById(self.win['view']['position'])
  1230. x, y = viewWin.UpdatePos(self.mapWindow.view['position']['x'],
  1231. self.mapWindow.view['position']['y'])
  1232. viewWin.Draw(pos = (x, y), scale = True)
  1233. viewWin.Refresh(False)
  1234. # bgcolor = self.FindWindowById(self.win['settings']['general']['bgcolor']).GetColour()
  1235. # self.OnBgColor(event = bgcolor)
  1236. self.Update()
  1237. self.mapWindow.Refresh(eraseBackground = False)
  1238. self.mapWindow.render['quick'] = False
  1239. self.mapWindow.Refresh(False)
  1240. def OnShowLightModel(self, event):
  1241. """!Show light model"""
  1242. self._display.showLight = event.IsChecked()
  1243. self._display.DrawLightingModel()
  1244. def OnLightChange(self, event):
  1245. """!Position of the light changed"""
  1246. winName = self.__GetWindowName(self.win['light'], event.GetId())
  1247. if not winName:
  1248. return
  1249. val = event.GetInt()
  1250. self.mapWindow.light['position']['z'] = val / 100.
  1251. for win in self.win['light'][winName].itervalues():
  1252. self.FindWindowById(win).SetValue(val)
  1253. event = wxUpdateLight()
  1254. wx.PostEvent(self.mapWindow, event)
  1255. event.Skip()
  1256. def OnLightColor(self, event):
  1257. """!Color of the light changed"""
  1258. self.mapWindow.light['color'] = event.GetValue()
  1259. event = wxUpdateLight()
  1260. wx.PostEvent(self.mapWindow, event)
  1261. event.Skip()
  1262. def OnLightValue(self, event):
  1263. """!Light brightness changed"""
  1264. data = self.mapWindow.light
  1265. self.OnScroll(event, self.win['light'], data)
  1266. event = wxUpdateLight()
  1267. wx.PostEvent(self.mapWindow, event)
  1268. event.Skip()
  1269. def OnBgColor(self, event):
  1270. """!Background color changed"""
  1271. color = event.GetValue()
  1272. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1273. self._display.SetBgColor(str(color))
  1274. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1275. self.mapWindow.Refresh(False)
  1276. def OnSetRaster(self, event):
  1277. """!Raster map selected, update surface page"""
  1278. name = event.GetString()
  1279. try:
  1280. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
  1281. except:
  1282. self.EnablePage('surface', False)
  1283. return
  1284. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  1285. self.EnablePage('surface', True)
  1286. self.UpdateSurfacePage(layer, data, updateName = False)
  1287. def OnSetVector(self, event):
  1288. """!Vector map selected, update properties page"""
  1289. name = event.GetString()
  1290. try:
  1291. data = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')['vector']
  1292. except:
  1293. self.EnablePage('vector', False)
  1294. return
  1295. layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
  1296. self.EnablePage('vector', True)
  1297. self.UpdateVectorPage(layer, data, updateName = False)
  1298. def OnSetRaster3D(self, event):
  1299. """!3D Raster map selected, update surface page"""
  1300. name = event.GetString()
  1301. try:
  1302. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')['volume']
  1303. except:
  1304. self.EnablePage('volume', False)
  1305. return
  1306. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  1307. self.EnablePage('volume', True)
  1308. self.UpdateVolumePage(layer, data, updateName = False)
  1309. def OnViewChange(self, event):
  1310. """!Change view, render in quick mode"""
  1311. # find control
  1312. winName = self.__GetWindowName(self.win['view'], event.GetId())
  1313. if not winName:
  1314. return
  1315. if winName == 'height':
  1316. view = self.mapWindow.iview # internal
  1317. else:
  1318. view = self.mapWindow.view
  1319. if winName == 'z-exag' and event.GetInt() >= 0:
  1320. self.PostViewEvent(zExag = True)
  1321. else:
  1322. self.PostViewEvent(zExag = False)
  1323. view[winName]['value'] = event.GetInt()
  1324. for win in self.win['view'][winName].itervalues():
  1325. self.FindWindowById(win).SetValue(view[winName]['value'])
  1326. self.mapWindow.render['quick'] = True
  1327. self.mapWindow.Refresh(False)
  1328. event.Skip()
  1329. def OnViewChanged(self, event):
  1330. """!View changed, render in full resolution"""
  1331. self.mapWindow.render['quick'] = False
  1332. self.mapWindow.Refresh(False)
  1333. self.UpdateSettings()
  1334. def OnViewChangedSpin(self, event):
  1335. """!View changed, render in full resolution"""
  1336. self.mapWindow.render['quick'] = False
  1337. self.OnViewChange(event)
  1338. self.OnViewChanged(None)
  1339. self.Update()
  1340. event.Skip()
  1341. def OnResetView(self, event):
  1342. """!Reset to default view (view page)"""
  1343. self.mapWindow.ResetView()
  1344. self.UpdateSettings()
  1345. self.mapWindow.Refresh(False)
  1346. def OnLookAt(self, event):
  1347. """!Look at (view page)"""
  1348. sel = event.GetSelection()
  1349. if sel == 0: # top
  1350. self.mapWindow.view['position']['x'] = 0.5
  1351. self.mapWindow.view['position']['y'] = 0.5
  1352. elif sel == 1: # north
  1353. self.mapWindow.view['position']['x'] = 0.5
  1354. self.mapWindow.view['position']['y'] = 0.0
  1355. elif sel == 2: # south
  1356. self.mapWindow.view['position']['x'] = 0.5
  1357. self.mapWindow.view['position']['y'] = 1.0
  1358. elif sel == 3: # east
  1359. self.mapWindow.view['position']['x'] = 1.0
  1360. self.mapWindow.view['position']['y'] = 0.5
  1361. elif sel == 4: # west
  1362. self.mapWindow.view['position']['x'] = 0.0
  1363. self.mapWindow.view['position']['y'] = 0.5
  1364. elif sel == 5: # north-west
  1365. self.mapWindow.view['position']['x'] = 0.0
  1366. self.mapWindow.view['position']['y'] = 0.0
  1367. elif sel == 6: # north-east
  1368. self.mapWindow.view['position']['x'] = 1.0
  1369. self.mapWindow.view['position']['y'] = 0.0
  1370. elif sel == 7: # south-east
  1371. self.mapWindow.view['position']['x'] = 1.0
  1372. self.mapWindow.view['position']['y'] = 1.0
  1373. elif sel == 8: # south-west
  1374. self.mapWindow.view['position']['x'] = 0.0
  1375. self.mapWindow.view['position']['y'] = 1.0
  1376. self.PostViewEvent(zExag = True)
  1377. self.UpdateSettings()
  1378. self.mapWindow.render['quick'] = False
  1379. self.mapWindow.Refresh(False)
  1380. def OnClose(self, event):
  1381. """!Close button pressed
  1382. Close dialog
  1383. """
  1384. self.Hide()
  1385. def OnMapObjUse(self, event):
  1386. """!Set surface attribute -- use -- map/constant"""
  1387. if not self.mapWindow.init:
  1388. return
  1389. wx.Yield()
  1390. # find attribute row
  1391. attrb = self.__GetWindowName(self.win['surface'], event.GetId())
  1392. if not attrb:
  1393. attrb = self.__GetWindowName(self.win['volume'], event.GetId())
  1394. nvizType = 'volume'
  1395. else:
  1396. nvizType = 'surface'
  1397. selection = event.GetSelection()
  1398. if self.win[nvizType][attrb]['required']: # no 'unset'
  1399. selection += 1
  1400. if selection == 0: # unset
  1401. useMap = None
  1402. value = ''
  1403. elif selection == 1: # map
  1404. useMap = True
  1405. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1406. elif selection == 2: # constant
  1407. useMap = False
  1408. if attrb == 'color':
  1409. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1410. value = self._getColorString(value)
  1411. else:
  1412. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  1413. self.SetMapObjUseMap(nvizType = nvizType,
  1414. attrb = attrb, map = useMap)
  1415. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1416. if nvizType == 'surface':
  1417. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1418. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  1419. 'value' : str(value),
  1420. 'update' : None }
  1421. else: # volume / isosurface
  1422. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  1423. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1424. id = list.GetSelection()
  1425. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  1426. 'value' : str(value),
  1427. 'update' : None }
  1428. # update properties
  1429. event = wxUpdateProperties(data = data)
  1430. wx.PostEvent(self.mapWindow, event)
  1431. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1432. self.mapWindow.Refresh(False)
  1433. def EnablePage(self, name, enabled = True):
  1434. """!Enable/disable all widgets on page"""
  1435. for key, item in self.win[name].iteritems():
  1436. if key == 'map':
  1437. continue
  1438. if type(item) == types.DictType:
  1439. for sitem in self.win[name][key].itervalues():
  1440. if type(sitem) == types.IntType:
  1441. self.FindWindowById(sitem).Enable(enabled)
  1442. else:
  1443. if type(item) == types.IntType:
  1444. self.FindWindowById(item).Enable(enabled)
  1445. def SetMapObjUseMap(self, nvizType, attrb, map = None):
  1446. """!Update dialog widgets when attribute type changed"""
  1447. if attrb in ('topo', 'color', 'shine'):
  1448. incSel = -1 # decrement selection (no 'unset')
  1449. else:
  1450. incSel = 0
  1451. if map is True: # map
  1452. if attrb != 'topo': # changing map topography not allowed
  1453. # not sure why, but here must be disabled both ids, should be fixed!
  1454. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(True)
  1455. if self.win[nvizType][attrb]['const']:
  1456. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  1457. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(1 + incSel)
  1458. elif map is False: # const
  1459. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  1460. if self.win[nvizType][attrb]['const']:
  1461. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(True)
  1462. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(2 + incSel)
  1463. else: # unset
  1464. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  1465. if self.win[nvizType][attrb]['const']:
  1466. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  1467. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(0)
  1468. def OnSurfaceMap(self, event):
  1469. """!Set surface attribute"""
  1470. self.SetMapObjAttrb(nvizType = 'surface', winId = event.GetId())
  1471. def SetMapObjAttrb(self, nvizType, winId):
  1472. """!Set map object (surface/isosurface) attribute (map/constant)"""
  1473. if not self.mapWindow.init:
  1474. return
  1475. attrb = self.__GetWindowName(self.win[nvizType], winId)
  1476. if not attrb:
  1477. return
  1478. if nvizType == 'volume' and attrb == 'topo':
  1479. return
  1480. selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
  1481. if self.win[nvizType][attrb]['required']:
  1482. selection += 1
  1483. if selection == 0: # unset
  1484. useMap = None
  1485. value = ''
  1486. elif selection == 1: # map
  1487. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1488. useMap = True
  1489. else: # constant
  1490. if attrb == 'color':
  1491. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1492. # tuple to string
  1493. value = self._getColorString(value)
  1494. else:
  1495. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  1496. useMap = False
  1497. if not self.pageChanging:
  1498. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1499. if nvizType == 'surface':
  1500. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1501. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  1502. 'value' : str(value),
  1503. 'update' : None }
  1504. else:
  1505. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  1506. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1507. id = list.GetSelection()
  1508. if id > -1:
  1509. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  1510. 'value' : str(value),
  1511. 'update' : None }
  1512. # update properties
  1513. event = wxUpdateProperties(data = data)
  1514. wx.PostEvent(self.mapWindow, event)
  1515. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1516. self.mapWindow.Refresh(False)
  1517. def OnSurfaceResolution(self, event):
  1518. """!Draw resolution changed"""
  1519. self.SetSurfaceResolution()
  1520. if apply and self.mapDisplay.statusbarWin['render'].IsChecked():
  1521. self.mapWindow.Refresh(False)
  1522. def SetSurfaceResolution(self):
  1523. """!Set draw resolution"""
  1524. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  1525. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  1526. data = self.GetLayerData('surface')
  1527. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  1528. 'fine' : fine,
  1529. 'update' : None }
  1530. # update properties
  1531. event = wxUpdateProperties(data = data)
  1532. wx.PostEvent(self.mapWindow, event)
  1533. def SetSurfaceMode(self):
  1534. """!Set draw mode
  1535. @param apply allow auto-rendering
  1536. """
  1537. mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
  1538. if mode == 0: # coarse
  1539. self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
  1540. self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(False)
  1541. elif mode == 1: # fine
  1542. self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(False)
  1543. self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
  1544. else: # both
  1545. self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
  1546. self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
  1547. style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
  1548. shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
  1549. value, desc = self.mapWindow.nvizDefault.GetDrawMode(mode, style, shade)
  1550. return value, desc
  1551. def OnSurfaceMode(self, event):
  1552. """!Set draw mode"""
  1553. value, desc = self.SetSurfaceMode()
  1554. data = self.GetLayerData('surface')
  1555. data['surface']['draw']['mode'] = { 'value' : value,
  1556. 'desc' : desc,
  1557. 'update' : None }
  1558. # update properties
  1559. event = wxUpdateProperties(data = data)
  1560. wx.PostEvent(self.mapWindow, event)
  1561. if apply and self.mapDisplay.statusbarWin['render'].IsChecked():
  1562. self.mapWindow.Refresh(False)
  1563. def OnSurfaceModeAll(self, event):
  1564. """!Set draw mode (including wire color) for all loaded surfaces"""
  1565. value, desc = self.SetSurfaceMode()
  1566. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  1567. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  1568. color = self.FindWindowById(self.win['surface']['draw']['wire-color']).GetColour()
  1569. cvalue = self._getColorString(color)
  1570. for name in self.mapWindow.GetLayerNames(type = 'raster'):
  1571. data = self.GetLayerData('surface')
  1572. if not data:
  1573. continue # shouldy no happen
  1574. data['surface']['draw']['mode'] = { 'value' : value,
  1575. 'desc' : desc,
  1576. 'update' : None }
  1577. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  1578. 'fine' : fine,
  1579. 'update' : None }
  1580. data['surface']['draw']['wire-color'] = { 'value' : cvalue,
  1581. 'update' : None }
  1582. # update properties
  1583. event = wxUpdateProperties(data = data)
  1584. wx.PostEvent(self.mapWindow, event)
  1585. if apply and self.mapDisplay.statusbarWin['render'].IsChecked():
  1586. self.mapWindow.Refresh(False)
  1587. def _getColorString(self, color):
  1588. """!Set wire color"""
  1589. return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1590. def OnSurfaceWireColor(self, event):
  1591. """!Set wire color"""
  1592. data = self.GetLayerData('surface')
  1593. value = self._getColorString(event.GetValue())
  1594. data['surface']['draw']['wire-color'] = { 'value' : value,
  1595. 'update' : None }
  1596. # update properties
  1597. event = wxUpdateProperties(data = data)
  1598. wx.PostEvent(self.mapWindow, event)
  1599. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1600. self.mapWindow.Refresh(False)
  1601. def OnSurfaceAxis(self, event):
  1602. """!Surface position, axis changed"""
  1603. data = self.GetLayerData('surface')
  1604. id = data['surface']['object']['id']
  1605. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  1606. slider = self.FindWindowById(self.win['surface']['position']['slider'])
  1607. spin = self.FindWindowById(self.win['surface']['position']['spin'])
  1608. x, y, z = self._display.GetSurfacePosition(id)
  1609. if axis == 0: # x
  1610. slider.SetValue(x)
  1611. spin.SetValue(x)
  1612. elif axis == 1: # y
  1613. slider.SetValue(y)
  1614. spin.SetValue(y)
  1615. else: # z
  1616. slider.SetValue(z)
  1617. spin.SetValue(z)
  1618. def OnSurfacePosition(self, event):
  1619. """!Surface position"""
  1620. winName = self.__GetWindowName(self.win['surface'], event.GetId())
  1621. if not winName:
  1622. return
  1623. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  1624. value = event.GetInt()
  1625. for win in self.win['surface']['position'].itervalues():
  1626. if win == self.win['surface']['position']['axis']:
  1627. continue
  1628. else:
  1629. self.FindWindowById(win).SetValue(value)
  1630. data = self.GetLayerData('surface')
  1631. id = data['surface']['object']['id']
  1632. x, y, z = self._display.GetSurfacePosition(id)
  1633. if axis == 0: # x
  1634. x = value
  1635. elif axis == 1: # y
  1636. y = value
  1637. else: # z
  1638. z = value
  1639. data = self.GetLayerData('surface')
  1640. data['surface']['position']['x'] = x
  1641. data['surface']['position']['y'] = y
  1642. data['surface']['position']['z'] = z
  1643. data['surface']['position']['update'] = None
  1644. # update properties
  1645. event = wxUpdateProperties(data = data)
  1646. wx.PostEvent(self.mapWindow, event)
  1647. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1648. self.mapWindow.Refresh(False)
  1649. # self.UpdatePage('surface')
  1650. def UpdateVectorShow(self, vecType, enabled):
  1651. """!Enable/disable lines/points widgets
  1652. @param vecType vector type (lines, points)
  1653. """
  1654. if vecType != 'lines' and vecType != 'points':
  1655. return False
  1656. for win in self.win['vector'][vecType].keys():
  1657. if win == 'show':
  1658. continue
  1659. if type(self.win['vector'][vecType][win]) == type({}):
  1660. for swin in self.win['vector'][vecType][win].keys():
  1661. if enabled:
  1662. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
  1663. else:
  1664. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
  1665. else:
  1666. if enabled:
  1667. self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
  1668. else:
  1669. self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
  1670. return True
  1671. def OnVectorShow(self, event):
  1672. """!Show vector lines/points"""
  1673. winId = event.GetId()
  1674. if winId == self.win['vector']['lines']['show']:
  1675. vecType = 'lines'
  1676. points = False
  1677. else: # points
  1678. vecType = 'points'
  1679. points = True
  1680. checked = event.IsChecked()
  1681. name = self.FindWindowById(self.win['vector']['map']).GetValue()
  1682. item = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'item')
  1683. data = self.GetLayerData('vector')['vector']
  1684. if checked:
  1685. self.mapWindow.LoadVector(item, points = points)
  1686. else:
  1687. self.mapWindow.UnloadVector(item, points = points)
  1688. self.UpdateVectorShow(vecType, checked)
  1689. if checked:
  1690. try:
  1691. id = data[vecType]['object']['id']
  1692. except KeyError:
  1693. id = -1
  1694. if id > 0:
  1695. self.mapWindow.SetMapObjProperties(item, id, vecType)
  1696. # update properties
  1697. event = wxUpdateProperties(data = data)
  1698. wx.PostEvent(self.mapWindow, event)
  1699. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1700. self.mapWindow.Refresh(False)
  1701. event.Skip()
  1702. def OnVectorDisplay(self, event):
  1703. """!Display vector lines on surface/flat"""
  1704. rasters = self.mapWindow.GetLayerNames('raster')
  1705. if event.GetSelection() == 0: # surface
  1706. if len(rasters) < 1:
  1707. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  1708. self.FindWindowById(self.win['vector']['lines']['flat']).SetSelection(1)
  1709. return
  1710. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(True)
  1711. # set first found surface
  1712. data = self.GetLayerData('vector')
  1713. data['vector']['lines']['mode']['surface'] = rasters[0]
  1714. self.FindWindowById(self.win['vector']['lines']['surface']).SetStringSelection( \
  1715. rasters[0])
  1716. else: # flat
  1717. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  1718. self.OnVectorLines(event)
  1719. event.Skip()
  1720. def OnVectorLines(self, event):
  1721. """!Set vector lines mode, apply changes if auto-rendering is enabled"""
  1722. data = self.GetLayerData('vector')
  1723. width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
  1724. mode = {}
  1725. if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
  1726. mode['type'] = 'surface'
  1727. mode['surface'] = self.FindWindowById(self.win['vector']['lines']['surface']).GetValue()
  1728. mode['update'] = None
  1729. else:
  1730. mode['type'] = 'flat'
  1731. for attrb in ('width', 'mode'):
  1732. data['vector']['lines'][attrb]['update'] = None
  1733. data['vector']['lines']['width']['value'] = width
  1734. data['vector']['lines']['mode']['value'] = mode
  1735. color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
  1736. if isinstance(color, csel.ColourSelect):
  1737. pass #color picker not yet instantiated
  1738. else:
  1739. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1740. data['vector']['lines']['color']['update'] = None
  1741. data['vector']['lines']['color']['value'] = color
  1742. # update properties
  1743. event = wxUpdateProperties(data = data)
  1744. wx.PostEvent(self.mapWindow, event)
  1745. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1746. self.mapWindow.Refresh(False)
  1747. def OnVectorHeight(self, event):
  1748. value = event.GetInt()
  1749. id = event.GetId()
  1750. if id == self.win['vector']['lines']['height']['spin'] or \
  1751. id == self.win['vector']['lines']['height']['slider']:
  1752. vtype = 'lines'
  1753. else:
  1754. vtype = 'points'
  1755. if type(event) == type(wx.ScrollEvent()):
  1756. # slider
  1757. win = self.FindWindowById(self.win['vector'][vtype]['height']['spin'])
  1758. else:
  1759. # spin
  1760. win = self.FindWindowById(self.win['vector'][vtype]['height']['slider'])
  1761. win.SetValue(value)
  1762. data = self.GetLayerData('vector')['vector'][vtype]
  1763. data['height'] = { 'value' : value,
  1764. 'update' : None }
  1765. # update properties
  1766. event = wxUpdateProperties(data = data)
  1767. wx.PostEvent(self.mapWindow, event)
  1768. self.mapWindow.render['quick'] = True
  1769. self.mapWindow.render['v' + vtype] = True
  1770. self.mapWindow.Refresh(False)
  1771. event.Skip()
  1772. def OnVectorHeightFull(self, event):
  1773. """!Vector height changed, render in full resolution"""
  1774. self.OnVectorHeight(event)
  1775. self.OnVectorSurface(event)
  1776. id = event.GetId()
  1777. if id == self.win['vector']['lines']['height']['spin'] or \
  1778. id == self.win['vector']['lines']['height']['slider']:
  1779. vtype = 'lines'
  1780. else:
  1781. vtype = 'points'
  1782. self.mapWindow.render['quick'] = False
  1783. self.mapWindow.render['v' + vtype] = False
  1784. self.mapWindow.Refresh(False)
  1785. def OnVectorHeightSpin(self, event):
  1786. """!Vector height changed, render in full resolution"""
  1787. # TODO: use step value instead
  1788. # self.OnVectorHeight(event)
  1789. self.OnVectorHeightFull(event)
  1790. def OnVectorSurface(self, event):
  1791. """!Reference surface for vector map (lines/points)"""
  1792. id = event.GetId()
  1793. if id == self.win['vector']['lines']['surface']:
  1794. vtype = 'lines'
  1795. else:
  1796. vtype = 'points'
  1797. data = self.GetLayerData('vector')
  1798. data['vector'][vtype]['mode']['surface'] = { 'value' : event.GetString(),
  1799. 'update' : None }
  1800. # update properties
  1801. event = wxUpdateProperties(data = data)
  1802. wx.PostEvent(self.mapWindow, event)
  1803. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1804. self.mapWindow.Refresh(False)
  1805. def OnVectorPoints(self, event):
  1806. """!Set vector points mode, apply changes if auto-rendering is enabled"""
  1807. data = self.GetLayerData('vector')
  1808. size = self.FindWindowById(self.win['vector']['points']['size']).GetValue()
  1809. marker = self.FindWindowById(self.win['vector']['points']['marker']).GetSelection()
  1810. # width = self.FindWindowById(self.win['vector']['points']['width']).GetValue()
  1811. for attrb in ('size', 'marker'):
  1812. data['vector']['points'][attrb]['update'] = None
  1813. data['vector']['points']['size']['value'] = size
  1814. # data['vector']['points']['width']['value'] = width
  1815. data['vector']['points']['marker']['value'] = marker
  1816. color = self.FindWindowById(self.win['vector']['points']['color']).GetColour()
  1817. if isinstance(color, csel.ColourSelect):
  1818. pass #color picker not yet instantiated
  1819. else:
  1820. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1821. data['vector']['points']['color']['update'] = None
  1822. data['vector']['points']['color']['value'] = color
  1823. # update properties
  1824. event = wxUpdateProperties(data = data)
  1825. wx.PostEvent(self.mapWindow, event)
  1826. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1827. self.mapWindow.Refresh(False)
  1828. def UpdateIsosurfButtons(self, list):
  1829. """!Enable/disable buttons 'add', 'delete',
  1830. 'move up', 'move down'"""
  1831. nitems = list.GetCount()
  1832. add = self.parent.FindWindowById(self.win['volume']['btnIsosurfAdd'])
  1833. delete = self.parent.FindWindowById(self.win['volume']['btnIsosurfDelete'])
  1834. moveDown = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
  1835. moveUp = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
  1836. if nitems >= wxnviz.MAX_ISOSURFS:
  1837. # disable add button on max
  1838. add.Enable(False)
  1839. else:
  1840. add.Enable(True)
  1841. if nitems < 1:
  1842. # disable 'delete' if only one item in the lis
  1843. delete.Enable(False)
  1844. else:
  1845. delete.Enable(True)
  1846. if list.GetSelection() >= nitems - 1:
  1847. # disable 'move-down' if last
  1848. moveDown.Enable(False)
  1849. else:
  1850. moveDown.Enable(True)
  1851. if list.GetSelection() < 1:
  1852. # disable 'move-up' if first
  1853. moveUp.Enable(False)
  1854. else:
  1855. moveUp.Enable(True)
  1856. def OnVolumeIsosurfMode(self, event):
  1857. """!Set isosurface draw mode"""
  1858. self.SetIsosurfaceMode(event.GetSelection())
  1859. def SetIsosurfaceMode(self, selection):
  1860. """!Set isosurface draw mode"""
  1861. data = self.GetLayerData('volume')['volume']
  1862. id = data['object']['id']
  1863. mode = 0
  1864. if selection == 0:
  1865. mode |= wxnviz.DM_FLAT
  1866. else:
  1867. mode |= wxnviz.DM_GOURAUD
  1868. self._display.SetIsosurfaceMode(id, mode)
  1869. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1870. self.mapWindow.Refresh(False)
  1871. def OnVolumeIsosurfResolution(self, event):
  1872. """!Set isosurface draw resolution"""
  1873. self.SetIsosurfaceResolution(event.GetInt())
  1874. def SetIsosurfaceResolution(self, res):
  1875. """!Set isosurface draw resolution"""
  1876. data = self.GetLayerData('volume')['volume']
  1877. id = data['object']['id']
  1878. self._display.SetIsosurfaceRes(id, res)
  1879. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1880. self.mapWindow.Refresh(False)
  1881. def OnVolumeIsosurfMap(self, event):
  1882. """!Set surface attribute"""
  1883. self.SetMapObjAttrb(nvizType = 'volume', winId = event.GetId())
  1884. def OnVolumeIsosurfCheck(self, event):
  1885. """!Isosurface checked (->load) or unchecked (->unload)"""
  1886. index = event.GetSelection()
  1887. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1888. data = self.GetLayerData('volume')['volume']
  1889. id = data['object']['id']
  1890. isosurfId = event.GetSelection()
  1891. if list.IsChecked(index):
  1892. self._display.SetIsosurfaceTransp(id, isosurfId, False, "0")
  1893. else:
  1894. # disable -> make transparent
  1895. self._display.SetIsosurfaceTransp(id, isosurfId, False, "255")
  1896. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1897. self.mapWindow.Refresh(False)
  1898. def OnVolumeIsosurfSelect(self, event):
  1899. """!Isosurface item selected"""
  1900. winUp = self.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
  1901. winDown = self.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
  1902. selection = event.GetSelection()
  1903. if selection == 0:
  1904. winUp.Enable(False)
  1905. if not winDown.IsEnabled():
  1906. winDown.Enable()
  1907. elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
  1908. winDown.Enable(False)
  1909. if not winUp.IsEnabled():
  1910. winUp.Enable()
  1911. else:
  1912. if not winDown.IsEnabled():
  1913. winDown.Enable()
  1914. if not winUp.IsEnabled():
  1915. winUp.Enable()
  1916. # update dialog
  1917. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  1918. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  1919. data = self.GetLayerData('volume')['volume']['isosurface'][selection]
  1920. self.UpdateVolumeIsosurfPage(layer, data)
  1921. def OnVolumeIsosurfAdd(self, event):
  1922. """!Add new isosurface to the list"""
  1923. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1924. level = self.FindWindowById(self.win['volume']['topo']['const']).GetValue()
  1925. sel = list.GetSelection()
  1926. if sel < 0 or sel >= list.GetCount() - 1:
  1927. item = list.Append(item = "%s %s" % (_("Level"), str(level)))
  1928. else:
  1929. list.Insert(item = "%s %s" % (_("Level"), str(level)),
  1930. pos = sel+1) # append
  1931. item = sel + 1
  1932. list.Check(item)
  1933. list.SetSelection(item)
  1934. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  1935. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  1936. data = self.GetLayerData('volume')['volume']
  1937. id = data['object']['id']
  1938. # collect properties
  1939. isosurfData = {}
  1940. for attrb in ('topo', 'color', 'mask',
  1941. 'transp', 'shine', 'emit'):
  1942. if attrb == 'topo':
  1943. isosurfData[attrb] = {}
  1944. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  1945. isosurfData[attrb]['value'] = win.GetValue()
  1946. else:
  1947. uwin = self.FindWindowById(self.win['volume'][attrb]['use'])
  1948. sel = uwin.GetSelection()
  1949. if self.win['volume'][attrb]['required']:
  1950. sel += 1
  1951. if sel == 0: # unset
  1952. continue
  1953. isosurfData[attrb] = {}
  1954. if sel == 1: # map
  1955. isosurfData[attrb]['map'] = True
  1956. vwin = self.FindWindowById(self.win['volume'][attrb]['map'])
  1957. value = vwin.GetValue()
  1958. else: # const
  1959. isosurfData[attrb]['map'] = False
  1960. vwin = self.FindWindowById(self.win['volume'][attrb]['const'])
  1961. if vwin.GetName() == "color":
  1962. value = self._getColorString(vwin.GetValue())
  1963. else:
  1964. value = vwin.GetValue()
  1965. isosurfData[attrb]['value'] = value
  1966. data['isosurface'].insert(item, isosurfData)
  1967. # add isosurface
  1968. self._display.AddIsosurface(id, level)
  1969. # use by default 3d raster map for color
  1970. self._display.SetIsosurfaceColor(id, item, True, str(layer.name))
  1971. # update buttons
  1972. self.UpdateIsosurfButtons(list)
  1973. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1974. self.mapWindow.Refresh(False)
  1975. event.Skip()
  1976. def OnVolumeIsosurfDelete(self, event):
  1977. """!Remove isosurface from list"""
  1978. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1979. # remove item from list
  1980. isosurfId = list.GetSelection()
  1981. list.Delete(isosurfId)
  1982. # select last item
  1983. if list.GetCount() > 0:
  1984. list.SetSelection(list.GetCount()-1)
  1985. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  1986. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  1987. data = self.GetLayerData('volume')['volume']
  1988. id = data['object']['id']
  1989. # delete isosurface
  1990. del data['isosurface'][isosurfId]
  1991. self._display.DeleteIsosurface(id, isosurfId)
  1992. # update buttons
  1993. self.UpdateIsosurfButtons(list)
  1994. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1995. self.mapWindow.Refresh(False)
  1996. event.Skip()
  1997. def OnVolumeIsosurfMoveUp(self, event):
  1998. """!Move isosurface up in the list"""
  1999. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2000. sel = list.GetSelection()
  2001. if sel < 1:
  2002. return # this should not happen
  2003. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2004. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2005. data = self.GetLayerData('volume')['volume']
  2006. id = data['object']['id']
  2007. # move item up
  2008. text = list.GetStringSelection()
  2009. list.Insert(item = text, pos = sel-1)
  2010. list.Check(sel-1)
  2011. list.SetSelection(sel-1)
  2012. list.Delete(sel+1)
  2013. data['isosurface'].insert(sel-1, data['isosurface'][sel])
  2014. del data['isosurface'][sel+1]
  2015. self._display.MoveIsosurface(id, sel, True)
  2016. # update buttons
  2017. self.UpdateIsosurfButtons(list)
  2018. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2019. self.mapWindow.Refresh(False)
  2020. event.Skip()
  2021. def OnVolumeIsosurfMoveDown(self, event):
  2022. """!Move isosurface dowm in the list"""
  2023. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2024. sel = list.GetSelection()
  2025. if sel >= list.GetCount() - 1:
  2026. return # this should not happen
  2027. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2028. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2029. data = self.GetLayerData('volume')['volume']
  2030. id = data['object']['id']
  2031. # move item up
  2032. text = list.GetStringSelection()
  2033. list.Insert(item = text, pos = sel+2)
  2034. list.Check(sel+2)
  2035. list.SetSelection(sel+2)
  2036. list.Delete(sel)
  2037. data['isosurface'].insert(sel+2, data['isosurface'][sel])
  2038. del data['isosurface'][sel]
  2039. self._display.MoveIsosurface(id, sel, False)
  2040. # update buttons
  2041. self.UpdateIsosurfButtons(list)
  2042. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2043. self.mapWindow.Refresh(False)
  2044. event.Skip()
  2045. def UpdatePage(self, pageId):
  2046. """!Update dialog (selected page)"""
  2047. self.pageChanging = True
  2048. Debug.msg(1, "NvizToolWindow.UpdatePage(): %s", pageId)
  2049. if pageId == 'view':
  2050. self.SetPage('view')
  2051. hmin = self.mapWindow.iview['height']['min']
  2052. hmax = self.mapWindow.iview['height']['max']
  2053. hval = self.mapWindow.iview['height']['value']
  2054. zmin = self.mapWindow.view['z-exag']['min']
  2055. zmax = self.mapWindow.view['z-exag']['max']
  2056. zval = self.mapWindow.view['z-exag']['value']
  2057. for control in ('spin', 'slider'):
  2058. self.FindWindowById(self.win['view']['height'][control]).SetRange(hmin,
  2059. hmax)
  2060. self.FindWindowById(self.win['view']['height'][control]).SetValue(hval)
  2061. self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(zmin,
  2062. zmax)
  2063. self.FindWindowById(self.win['view']['z-exag'][control]).SetValue(zval)
  2064. elif pageId in ('surface', 'vector', 'volume'):
  2065. name = self.FindWindowById(self.win[pageId]['map']).GetValue()
  2066. data = self.GetLayerData(pageId)
  2067. if data:
  2068. if pageId == 'surface':
  2069. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  2070. self.UpdateSurfacePage(layer, data['surface'])
  2071. elif pageId == 'vector':
  2072. layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
  2073. self.UpdateVectorPage(layer, data['vector'])
  2074. elif pageId == 'volume':
  2075. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2076. self.UpdateVectorPage(layer, data['vector'])
  2077. elif pageId == 'light':
  2078. zval = self.mapWindow.light['position']['z']
  2079. bval = self.mapWindow.light['bright']
  2080. aval = self.mapWindow.light['ambient']
  2081. for control in ('spin', 'slider'):
  2082. self.FindWindowById(self.win['light']['z'][control]).SetValue(zval)
  2083. self.FindWindowById(self.win['light']['bright'][control]).SetValue(bval)
  2084. self.FindWindowById(self.win['light']['ambient'][control]).SetValue(aval)
  2085. elif pageId == 'fringe':
  2086. win = self.FindWindowById(self.win['fringe']['surface'])
  2087. win.SetValue(self.FindWindowById(self.win['surface']['map']).GetValue())
  2088. self.Update()
  2089. self.pageChanging = False
  2090. def UpdateSurfacePage(self, layer, data, updateName = True):
  2091. """!Update surface page"""
  2092. ret = gcmd.RunCommand('r.info',
  2093. read = True,
  2094. flags = 'm',
  2095. map = layer.name)
  2096. if ret:
  2097. desc = ret.split('=')[1].rstrip('\n')
  2098. else:
  2099. desc = None
  2100. if updateName:
  2101. self.FindWindowById(self.win['surface']['map']).SetValue(layer.name)
  2102. self.FindWindowById(self.win['surface']['desc']).SetLabel(desc)
  2103. # attributes
  2104. for attr in ('topo', 'color'): # required
  2105. if layer and layer.type == 'raster':
  2106. self.FindWindowById(self.win['surface'][attr]['map']).SetValue(layer.name)
  2107. else:
  2108. self.FindWindowById(self.win['surface'][attr]['map']).SetValue('')
  2109. self.SetMapObjUseMap(nvizType = 'surface',
  2110. attrb = attr, map = True) # -> map
  2111. if data['attribute'].has_key('color'):
  2112. value = data['attribute']['color']['value']
  2113. if data['attribute']['color']['map']:
  2114. self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
  2115. else: # constant
  2116. color = map(int, value.split(':'))
  2117. self.FindWindowById(self.win['surface']['color']['const']).SetColour(color)
  2118. self.SetMapObjUseMap(nvizType = 'surface',
  2119. attrb = attr, map = data['attribute']['color']['map'])
  2120. self.SetMapObjUseMap(nvizType = 'surface',
  2121. attrb = 'shine', map = data['attribute']['shine']['map'])
  2122. value = data['attribute']['shine']['value']
  2123. if data['attribute']['shine']['map']:
  2124. self.FindWindowById(self.win['surface']['shine']['map']).SetValue(value)
  2125. else:
  2126. self.FindWindowById(self.win['surface']['shine']['const']).SetValue(value)
  2127. #
  2128. # draw
  2129. #
  2130. for control, data in data['draw'].iteritems():
  2131. if control == 'all': # skip 'all' property
  2132. continue
  2133. if control == 'resolution':
  2134. self.FindWindowById(self.win['surface']['draw']['res-coarse']).SetValue(data['coarse'])
  2135. self.FindWindowById(self.win['surface']['draw']['res-fine']).SetValue(data['fine'])
  2136. continue
  2137. if control == 'mode':
  2138. if data['desc']['mode'] == 'coarse':
  2139. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(0)
  2140. elif data['desc']['mode'] == 'fine':
  2141. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(1)
  2142. else: # both
  2143. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(2)
  2144. if data['desc']['style'] == 'wire':
  2145. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(0)
  2146. else: # surface
  2147. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(1)
  2148. if data['desc']['shading'] == 'flat':
  2149. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(0)
  2150. else: # gouraud
  2151. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(1)
  2152. continue
  2153. value = data['value']
  2154. win = self.FindWindowById(self.win['surface']['draw'][control])
  2155. name = win.GetName()
  2156. if name == "selection":
  2157. win.SetSelection(value)
  2158. elif name == "colour":
  2159. color = map(int, value.split(':'))
  2160. win.SetColour(color)
  2161. else:
  2162. win.SetValue(value)
  2163. # enable/disable res widget + set draw mode
  2164. self.SetSurfaceMode()
  2165. color = self.FindWindowById(self.win['surface']['draw']['wire-color'])
  2166. def VectorInfo(self, layer):
  2167. """!Get number of points/lines
  2168. @param layer MapLayer instance
  2169. @return num of points/features (expect of points)
  2170. @return None
  2171. """
  2172. vInfo = gcmd.RunCommand('v.info',
  2173. parent = self,
  2174. read = True,
  2175. flags = 't',
  2176. map = layer.GetName())
  2177. if not vInfo:
  2178. return None
  2179. npoints = nlines = nprimitives = 0
  2180. for line in vInfo.splitlines():
  2181. key, value = line.split('=')
  2182. if key == 'map3d':
  2183. mapIs3D = int(value)
  2184. elif key == 'points':
  2185. npoints = int(value)
  2186. nprimitives += npoints
  2187. elif key == 'lines':
  2188. nlines = int(value)
  2189. nprimitives += nlines
  2190. elif key in ('boundaries',
  2191. 'centroids',
  2192. 'faces',
  2193. 'kernels'):
  2194. nprimitives += int(value)
  2195. return (npoints, nlines, nprimitives, mapIs3D)
  2196. def UpdateVectorPage(self, layer, data, updateName = True):
  2197. """!Update vector page"""
  2198. npoints, nlines, nfeatures, mapIs3D = self.VectorInfo(layer)
  2199. if mapIs3D:
  2200. desc = _("Vector map is 3D")
  2201. enable = False
  2202. else:
  2203. desc = _("Vector map is 2D")
  2204. enable = True
  2205. desc += " - " + _("%(features)d features (%(points)d points)") % \
  2206. { 'features' : nfeatures, 'points' : npoints }
  2207. if updateName:
  2208. self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
  2209. self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
  2210. self.FindWindowById(self.win['vector']['lines']['flat']).Enable(enable)
  2211. for v in ('lines', 'points'):
  2212. self.FindWindowById(self.win['vector'][v]['surface']).Enable(enable)
  2213. self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
  2214. self.FindWindowById(self.win['vector'][v]['height']['spin']).Enable(enable)
  2215. #
  2216. # lines
  2217. #
  2218. showLines = self.FindWindowById(self.win['vector']['lines']['show'])
  2219. if data['lines'].has_key('object'):
  2220. showLines.SetValue(True)
  2221. else:
  2222. showLines.SetValue(False)
  2223. if nlines > 0:
  2224. showLines.Enable(True)
  2225. else:
  2226. showLines.Enable(False)
  2227. self.UpdateVectorShow('lines',
  2228. showLines.IsChecked())
  2229. width = self.FindWindowById(self.win['vector']['lines']['width'])
  2230. width.SetValue(data['lines']['width']['value'])
  2231. color = self.FindWindowById(self.win['vector']['lines']['color'])
  2232. color.SetValue(map(int, data['lines']['color']['value'].split(':')))
  2233. for vtype in ('lines', 'points'):
  2234. if vtype == 'lines':
  2235. display = self.FindWindowById(self.win['vector']['lines']['flat'])
  2236. if data[vtype]['mode']['type'] == 'flat':
  2237. display.SetSelection(1)
  2238. else:
  2239. display.SetSelection(0)
  2240. if data[vtype]['mode']['type'] == 'surface':
  2241. rasters = self.mapWindow.GetLayerNames('raster')
  2242. surface = self.FindWindowById(self.win['vector'][vtype]['surface'])
  2243. surface.SetItems(rasters)
  2244. if len(rasters) > 0:
  2245. try:
  2246. surface.SetStringSelection(data[vtype]['mode']['surface'])
  2247. except:
  2248. pass
  2249. for type in ('slider', 'spin'):
  2250. win = self.FindWindowById(self.win['vector']['lines']['height'][type])
  2251. win.SetValue(data['lines']['height']['value'])
  2252. #
  2253. # points
  2254. #
  2255. showPoints = self.FindWindowById(self.win['vector']['points']['show'])
  2256. if data['points'].has_key('object'):
  2257. showPoints.SetValue(True)
  2258. else:
  2259. showPoints.SetValue(False)
  2260. if npoints > 0:
  2261. showPoints.Enable(True)
  2262. else:
  2263. showPoints.Enable(False)
  2264. self.UpdateVectorShow('points',
  2265. showPoints.IsChecked())
  2266. # size, width, marker, color
  2267. for prop in ('size', 'marker', 'color'):
  2268. win = self.FindWindowById(self.win['vector']['points'][prop])
  2269. name = win.GetName()
  2270. if name == 'selection':
  2271. win.SetSelection(data['points'][prop]['value'])
  2272. elif name == 'color':
  2273. color = map(int, data['points'][prop]['value'].split(':'))
  2274. win.SetValue(color)
  2275. else:
  2276. win.SetValue(data['points'][prop]['value'])
  2277. # height
  2278. for type in ('slider', 'spin'):
  2279. win = self.FindWindowById(self.win['vector']['points']['height'][type])
  2280. win.SetValue(data['points']['height']['value'])
  2281. def UpdateVolumePage(self, layer, data, updateName = True):
  2282. """!Update volume page"""
  2283. if updateName:
  2284. self.FindWindowById(self.win['volume']['map']).SetValue(layer.name)
  2285. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2286. # draw
  2287. for control, idata in data['draw'].iteritems():
  2288. if control == 'all': # skip 'all' property
  2289. continue
  2290. win = self.FindWindowById(self.win['volume']['draw'][control])
  2291. if control == 'shading':
  2292. if data['draw']['shading']['desc'] == 'flat':
  2293. value = 0
  2294. else:
  2295. value = 1
  2296. else:
  2297. value = idata['value']
  2298. if win.GetName() == "selection":
  2299. win.SetSelection(value)
  2300. else:
  2301. win.SetValue(value)
  2302. self.SetIsosurfaceMode(data['draw']['shading']['value'])
  2303. self.SetIsosurfaceResolution(data['draw']['resolution']['value'])
  2304. self.UpdateVolumeIsosurfPage(layer, data['attribute'])
  2305. def UpdateVolumeIsosurfPage(self, layer, data):
  2306. """!Update dialog -- isosurface attributes"""
  2307. #
  2308. # isosurface attributes
  2309. #
  2310. for attrb in ('topo', 'color', 'mask',
  2311. 'transp', 'shine', 'emit'):
  2312. # check required first
  2313. if attrb == 'topo':
  2314. self.FindWindowById(self.win['volume'][attrb]['const']).SetValue(0)
  2315. continue
  2316. if attrb == 'color':
  2317. if layer and layer.type == '3d-raster':
  2318. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(layer.name)
  2319. else:
  2320. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue('')
  2321. self.SetMapObjUseMap(nvizType = 'volume',
  2322. attrb = attrb, map = True) # -> map
  2323. continue
  2324. # skip empty attributes
  2325. if not data.has_key(attrb):
  2326. continue
  2327. value = data[attrb]['value']
  2328. if attrb == 'color':
  2329. if data[attrb]['map']:
  2330. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(value)
  2331. else: # constant
  2332. color = map(int, value.split(':'))
  2333. self.FindWindowById(self.win['volume'][attrb]['const']).SetColour(color)
  2334. else:
  2335. if data[attrb]['map']:
  2336. win = self.FindWindowById(self.win['volume'][attrb]['map'])
  2337. else:
  2338. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  2339. win.SetValue(value)
  2340. self.SetMapObjUseMap(nvizType = 'volume',
  2341. attrb = attrb, map = data[attrb]['map'])
  2342. def SetPage(self, name):
  2343. """!Get named page"""
  2344. if name == 'view':
  2345. self.SetSelection(0)
  2346. elif name in ('surface', 'vector', 'volume'):
  2347. self.SetSelection(1)
  2348. else:
  2349. self.SetSelection(2)
  2350. win = self.FindWindowById(self.page[name]['notebook'])
  2351. win.SetSelection(self.page[name]['id'])
  2352. class PositionWindow(wx.Window):
  2353. """!Abstract position control window, see subclasses
  2354. ViewPostionWindow and LightPositionWindow"""
  2355. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  2356. **kwargs):
  2357. self.mapWindow = mapwindow
  2358. self.quick = True
  2359. wx.Window.__init__(self, parent, id, **kwargs)
  2360. self.SetBackgroundColour("WHITE")
  2361. self.pdc = wx.PseudoDC()
  2362. self.pdc.SetBrush(wx.Brush(colour = 'dark green', style = wx.SOLID))
  2363. self.pdc.SetPen(wx.Pen(colour = 'dark green', width = 2, style = wx.SOLID))
  2364. self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
  2365. self.Bind(wx.EVT_PAINT, self.OnPaint)
  2366. # self.Bind(wx.EVT_MOTION, self.OnMouse)
  2367. self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
  2368. def Draw(self, pos, scale = False):
  2369. w, h = self.GetClientSize()
  2370. x, y = pos
  2371. if scale:
  2372. x = x * w
  2373. y = y * h
  2374. self.pdc.Clear()
  2375. self.pdc.BeginDrawing()
  2376. self.pdc.DrawLine(w / 2, h / 2, x, y)
  2377. self.pdc.DrawCircle(x, y, 5)
  2378. self.pdc.EndDrawing()
  2379. def OnPaint(self, event):
  2380. dc = wx.BufferedPaintDC(self)
  2381. dc.SetBackground(wx.Brush("White"))
  2382. dc.Clear()
  2383. self.PrepareDC(dc)
  2384. self.pdc.DrawToDC(dc)
  2385. def UpdatePos(self, xcoord, ycoord):
  2386. """!Update position coordinates (origin: UL)"""
  2387. if xcoord < 0.0:
  2388. xcoord = 0.0
  2389. elif xcoord > 1.0:
  2390. xcoord = 1.0
  2391. if ycoord < 0.0:
  2392. ycoord = 0.0
  2393. elif ycoord > 1.0:
  2394. ycoord = 1.0
  2395. self.data['position']['x'] = xcoord
  2396. self.data['position']['y'] = ycoord
  2397. return xcoord, ycoord
  2398. def OnMouse(self, event):
  2399. if event.LeftIsDown():
  2400. x, y = event.GetPosition()
  2401. self.Draw(pos = (x, y))
  2402. w, h = self.GetClientSize()
  2403. x = float(x) / w
  2404. y = float(y) / h
  2405. self.UpdatePos(x, y)
  2406. self.Refresh(False)
  2407. event.Skip()
  2408. def PostDraw(self):
  2409. x, y = self.UpdatePos(self.data['position']['x'],
  2410. self.data['position']['y'])
  2411. self.Draw(pos = (x, y), scale = True)
  2412. class ViewPositionWindow(PositionWindow):
  2413. """!View position control widget"""
  2414. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  2415. **kwargs):
  2416. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  2417. self.data = self.mapWindow.view
  2418. self.PostDraw()
  2419. def UpdatePos(self, xcoord, ycoord):
  2420. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  2421. event = wxUpdateView(zExag = True)
  2422. wx.PostEvent(self.mapWindow, event)
  2423. return x, y
  2424. def OnMouse(self, event):
  2425. PositionWindow.OnMouse(self, event)
  2426. if event.LeftIsDown():
  2427. self.mapWindow.render['quick'] = self.quick
  2428. self.mapWindow.Refresh(eraseBackground = False)
  2429. elif event.LeftUp():
  2430. self.mapWindow.render['quick'] = False
  2431. self.mapWindow.Refresh(eraseBackground = False)
  2432. event.Skip()
  2433. class LightPositionWindow(PositionWindow):
  2434. """!Light position control widget"""
  2435. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  2436. **kwargs):
  2437. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  2438. self.data = self.mapWindow.light
  2439. self.quick = False
  2440. self.PostDraw()
  2441. def UpdatePos(self, xcoord, ycoord):
  2442. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  2443. event = wxUpdateLight()
  2444. wx.PostEvent(self.mapWindow, event)
  2445. return x, y
  2446. def OnMouse(self, event):
  2447. PositionWindow.OnMouse(self, event)
  2448. if event.LeftUp():
  2449. self.mapWindow.render['quick'] = False
  2450. self.mapWindow.Refresh(eraseBackground = False)