nviz_tools.py 123 KB

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