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. wx.CallAfter(self.notebookData.SetSelection, 0)
  70. wx.CallAfter(self.notebookAppearance.SetSelection, 0)
  71. def OnPageChanged(self, event):
  72. new = event.GetSelection()
  73. # self.ChangeSelection(new)
  74. def PostViewEvent(self, zExag = False):
  75. """!Change view settings"""
  76. event = wxUpdateView(zExag = zExag)
  77. wx.PostEvent(self.mapWindow, event)
  78. def _createViewPage(self):
  79. """!Create view settings page"""
  80. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  81. panel.SetupScrolling(scroll_x = False)
  82. self.page['view'] = { 'id' : 0 }
  83. pageSizer = wx.BoxSizer(wx.VERTICAL)
  84. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  85. label = " %s " % (_("Control View")))
  86. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  87. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  88. self.win['view'] = {}
  89. # position
  90. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  91. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("W")),
  92. pos = (1, 0), flag = wx.ALIGN_CENTER)
  93. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
  94. pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
  95. view = ViewPositionWindow(panel, size = (175, 175),
  96. mapwindow = self.mapWindow)
  97. self.win['view']['position'] = view.GetId()
  98. posSizer.Add(item = view,
  99. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  100. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
  101. pos = (2, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_TOP)
  102. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("E")),
  103. pos = (1, 2), flag = wx.ALIGN_CENTER)
  104. gridSizer.Add(item = posSizer, pos = (0, 0))
  105. # perspective
  106. # set initial defaults here (or perhaps in a default values file), not in user settings
  107. self._createControl(panel, data = self.win['view'], name = 'persp',
  108. range = (1,100),
  109. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  110. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Perspective:")),
  111. pos = (1, 0), flag = wx.ALIGN_CENTER)
  112. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['slider']), pos = (2, 0))
  113. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['spin']), pos = (3, 0),
  114. flag = wx.ALIGN_CENTER)
  115. # twist
  116. self._createControl(panel, data = self.win['view'], name = 'twist',
  117. range = (-180,180),
  118. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  119. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Twist:")),
  120. pos = (1, 1), flag = wx.ALIGN_CENTER)
  121. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['slider']), pos = (2, 1))
  122. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['spin']), pos = (3, 1),
  123. flag = wx.ALIGN_CENTER)
  124. # height + z-exag
  125. self._createControl(panel, data = self.win['view'], name = 'height', sliderHor = False,
  126. range = (0, 1),
  127. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  128. self._createControl(panel, data = self.win['view'], name = 'z-exag', sliderHor = False,
  129. range = (0, 5),
  130. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  131. self.FindWindowById(self.win['view']['z-exag']['slider']).SetValue(1)
  132. self.FindWindowById(self.win['view']['z-exag']['spin']).SetValue(1)
  133. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  134. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  135. pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
  136. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['slider']),
  137. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  138. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['spin']),
  139. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  140. wx.BOTTOM | wx.RIGHT, pos = (1, 1))
  141. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Z-exag:")),
  142. pos = (0, 2), flag = wx.ALIGN_LEFT, span = (1, 2))
  143. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['slider']),
  144. flag = wx.ALIGN_RIGHT, pos = (1, 2))
  145. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['spin']),
  146. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  147. wx.BOTTOM | wx.RIGHT, pos = (1, 3))
  148. gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_RIGHT)
  149. # view setup + reset
  150. viewSizer = wx.BoxSizer(wx.HORIZONTAL)
  151. viewSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY,
  152. label = _("Look at:")),
  153. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  154. border = 5)
  155. viewType = wx.Choice (parent = panel, id = wx.ID_ANY, size = (125, -1),
  156. choices = [_("top"),
  157. _("north"),
  158. _("south"),
  159. _("east"),
  160. _("west"),
  161. _("north-west"),
  162. _("north-east"),
  163. _("south-east"),
  164. _("south-west")])
  165. viewType.SetSelection(0)
  166. viewType.Bind(wx.EVT_CHOICE, self.OnLookAt)
  167. # self.win['lookAt'] = viewType.GetId()
  168. viewSizer.Add(item = viewType,
  169. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  170. border = 5)
  171. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  172. reset.SetToolTipString(_("Reset to default view"))
  173. # self.win['reset'] = reset.GetId()
  174. reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  175. viewSizer.Add(item = wx.Size(-1, -1), proportion = 1,
  176. flag = wx.EXPAND)
  177. viewSizer.Add(item = reset, proportion = 0,
  178. flag = wx.ALL | wx.ALIGN_RIGHT,
  179. border = 5)
  180. gridSizer.AddGrowableCol(2)
  181. gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
  182. flag = wx.EXPAND)
  183. # body
  184. boxSizer.Add(item = gridSizer, proportion = 1,
  185. flag = wx.ALL | wx.EXPAND, border = 2)
  186. pageSizer.Add(item = boxSizer, proportion = 0,
  187. flag = wx.EXPAND | wx.ALL,
  188. border = 3)
  189. box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  190. label = " %s " % (_("Image Appearance")))
  191. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  192. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  193. gridSizer.AddGrowableCol(0)
  194. # background color
  195. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  196. label = _("Background color:")),
  197. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  198. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  199. colour = UserSettings.Get(group = 'nviz', key = 'view',
  200. subkey = ['background', 'color']),
  201. size = globalvar.DIALOG_COLOR_SIZE)
  202. self.win['view']['bgcolor'] = color.GetId()
  203. color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
  204. gridSizer.Add(item = color, pos = (0, 1))
  205. boxSizer.Add(item = gridSizer, proportion = 1,
  206. flag = wx.ALL | wx.EXPAND, border = 3)
  207. pageSizer.Add(item = boxSizer, proportion = 0,
  208. flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
  209. border = 3)
  210. panel.SetSizer(pageSizer)
  211. return panel
  212. def _createDataPage(self):
  213. """!Create data (surface, vector, volume) settings page"""
  214. if globalvar.hasAgw:
  215. self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
  216. agwStyle = globalvar.FNPageDStyle)
  217. else:
  218. self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
  219. style = globalvar.FNPageDStyle)
  220. # surface page
  221. self.notebookData.AddPage(page = self._createSurfacePage(),
  222. text = " %s " % _("Surface"))
  223. self.EnablePage('surface', False)
  224. # vector page
  225. self.notebookData.AddPage(page = self._createVectorPage(),
  226. text = " %s " % _("Vector"))
  227. self.EnablePage('vector', False)
  228. # volume page
  229. self.notebookData.AddPage(page = self._createVolumePage(),
  230. text = " %s " % _("Volume"))
  231. self.EnablePage('volume', False)
  232. return self.notebookData
  233. def _createAppearancePage(self):
  234. """!Create data (surface, vector, volume) settings page"""
  235. if globalvar.hasAgw:
  236. self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
  237. agwStyle = globalvar.FNPageDStyle)
  238. else:
  239. self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
  240. style = globalvar.FNPageDStyle)
  241. # light page
  242. self.notebookAppearance.AddPage(page = self._createLightPage(),
  243. text = " %s " % _("Lighting"))
  244. # fringe page
  245. self.notebookAppearance.AddPage(page = self._createFringePage(),
  246. text = " %s " % _("Fringe"))
  247. return self.notebookAppearance
  248. def _createSurfacePage(self):
  249. """!Create view settings page"""
  250. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  251. panel.SetupScrolling(scroll_x = False)
  252. self.page['surface'] = {}
  253. self.page['surface']['id'] = 1
  254. self.page['surface']['panel'] = panel.GetId()
  255. pageSizer = wx.BoxSizer(wx.VERTICAL)
  256. self.win['surface'] = {}
  257. # selection
  258. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  259. label = " %s " % (_("Raster map")))
  260. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  261. rmaps = gselect.Select(parent = panel, type = 'raster',
  262. onPopup = self.GselectOnPopup)
  263. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster)
  264. self.win['surface']['map'] = rmaps.GetId()
  265. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  266. self.win['surface']['desc'] = desc.GetId()
  267. boxSizer.Add(item = rmaps, proportion = 0,
  268. flag = wx.ALL,
  269. border = 3)
  270. boxSizer.Add(item = desc, proportion = 0,
  271. flag = wx.ALL,
  272. border = 3)
  273. pageSizer.Add(item = boxSizer, proportion = 0,
  274. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  275. border = 3)
  276. #
  277. # surface attributes
  278. #
  279. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  280. label = " %s " % (_("Surface attributes")))
  281. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  282. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  283. # type
  284. self.win['surface']['attr'] = {}
  285. row = 0
  286. for code, attrb in (('topo', _("Topography")),
  287. ('color', _("Color")),
  288. ('mask', _("Mask")),
  289. ('transp', _("Transparency")),
  290. ('shine', _("Shininess")),
  291. ('emit', _("Emission"))):
  292. self.win['surface'][code] = {}
  293. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  294. label = attrb + ':'),
  295. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  296. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  297. choices = [_("map")])
  298. if code not in ('topo', 'color', 'shine'):
  299. use.Insert(item = _("unset"), pos = 0)
  300. self.win['surface'][code]['required'] = False
  301. else:
  302. self.win['surface'][code]['required'] = True
  303. if code != 'mask':
  304. use.Append(item = _('constant'))
  305. self.win['surface'][code]['use'] = use.GetId()
  306. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  307. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  308. pos = (row, 1))
  309. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  310. # size = globalvar.DIALOG_GSELECT_SIZE,
  311. size = (200, -1),
  312. type = "raster")
  313. self.win['surface'][code]['map'] = map.GetId() - 1 # FIXME
  314. map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  315. # changing map topography not allowed
  316. if code == 'topo':
  317. map.Enable(False)
  318. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
  319. pos = (row, 2))
  320. if code == 'color':
  321. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  322. colour = (0,0,0),
  323. size = globalvar.DIALOG_COLOR_SIZE)
  324. value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
  325. elif code == 'mask':
  326. value = None
  327. else:
  328. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  329. initial = 0)
  330. if code == 'topo':
  331. value.SetRange(minVal = -1e9, maxVal = 1e9)
  332. elif code in ('shine', 'transp', 'emit'):
  333. value.SetRange(minVal = 0, maxVal = 255)
  334. else:
  335. value.SetRange(minVal = 0, maxVal = 100)
  336. value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  337. if value:
  338. self.win['surface'][code]['const'] = value.GetId()
  339. value.Enable(False)
  340. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  341. pos = (row, 3))
  342. else:
  343. self.win['surface'][code]['const'] = None
  344. self.SetMapObjUseMap(nvizType = 'surface',
  345. attrb = code) # -> enable map / disable constant
  346. row += 1
  347. boxSizer.Add(item = gridSizer, proportion = 1,
  348. flag = wx.ALL | wx.EXPAND, border = 3)
  349. pageSizer.Add(item = boxSizer, proportion = 0,
  350. flag = wx.EXPAND | wx.ALL,
  351. border = 3)
  352. #
  353. # draw
  354. #
  355. self.win['surface']['draw'] = {}
  356. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  357. label = " %s " % (_("Draw")))
  358. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  359. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  360. gridSizer.AddGrowableCol(6)
  361. # mode
  362. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  363. label = _("Mode:")),
  364. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  365. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  366. choices = [_("coarse"),
  367. _("fine"),
  368. _("both")])
  369. mode.SetSelection(0)
  370. mode.SetName("selection")
  371. mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  372. self.win['surface']['draw']['mode'] = mode.GetId()
  373. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
  374. pos = (0, 1))
  375. # shading
  376. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  377. label = _("Shading:")),
  378. pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  379. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  380. choices = [_("flat"),
  381. _("gouraud")])
  382. shade.SetName("selection")
  383. self.win['surface']['draw']['shading'] = shade.GetId()
  384. shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  385. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  386. pos = (0, 3))
  387. # set to all
  388. all = wx.Button(panel, id = wx.ID_ANY, label = _("Set to all"))
  389. all.SetToolTipString(_("Use draw settings for all loaded surfaces"))
  390. all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
  391. gridSizer.Add(item = all, flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  392. pos = (0, 4), span = (1,2), border = 3 )
  393. # resolution coarse
  394. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  395. label = _("Coarse:")),
  396. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  397. resSizer = wx.BoxSizer(wx.HORIZONTAL)
  398. resSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  399. label = _("res.")),
  400. flag = wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL,
  401. border = 3)
  402. resC = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  403. initial = 6,
  404. min = 1,
  405. max = 100)
  406. resC.SetName("value")
  407. resC.SetValue(6)
  408. self.win['surface']['draw']['res-coarse'] = resC.GetId()
  409. resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  410. resSizer.Add(item = resC, flag = wx.ALL | wx.ALIGN_LEFT |
  411. wx.ALIGN_CENTER_VERTICAL, border = 3)
  412. gridSizer.Add(item = resSizer, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  413. # Coarse style
  414. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  415. label = _("style")),
  416. pos = (1, 2), flag = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
  417. style = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  418. choices = [_("wire"),
  419. _("surface")])
  420. style.SetName("selection")
  421. self.win['surface']['draw']['style'] = style.GetId()
  422. style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  423. gridSizer.Add(item = style, flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  424. pos = (1, 3))
  425. # color
  426. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  427. label = _("wire color")),
  428. pos = (1, 4), flag = wx.ALIGN_CENTER_VERTICAL |
  429. wx.ALIGN_RIGHT | wx.LEFT, border = 3)
  430. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  431. size = globalvar.DIALOG_COLOR_SIZE)
  432. color.SetColour((136,136,136))
  433. color.SetName("colour")
  434. color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
  435. self.win['surface']['draw']['wire-color'] = color.GetId()
  436. gridSizer.Add(item = color, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  437. pos = (1, 5))
  438. # resolution fine
  439. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  440. label = _("Fine:")),
  441. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  442. resSizer = wx.BoxSizer(wx.HORIZONTAL)
  443. resSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  444. label = _("res.")),
  445. flag = wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL,
  446. border = 3)
  447. resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  448. initial = 3,
  449. min = 1,
  450. max = 100)
  451. resF.SetName("value")
  452. resF.SetValue(3)
  453. self.win['surface']['draw']['res-fine'] = resF.GetId()
  454. resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  455. resSizer.Add(item = resF, flag = wx.ALL | wx.ALIGN_LEFT |
  456. wx.ALIGN_CENTER_VERTICAL, border = 3)
  457. gridSizer.Add(item = resSizer, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  458. boxSizer.Add(item = gridSizer, proportion = 1,
  459. flag = wx.ALL | wx.EXPAND, border = 3)
  460. pageSizer.Add(item = boxSizer, proportion = 0,
  461. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  462. border = 3)
  463. #
  464. # mask
  465. #
  466. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  467. label = " %s " % (_("Mask")))
  468. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  469. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  470. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  471. label = _("Mask zeros:")),
  472. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  473. elev = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  474. label = _("by elevation"))
  475. elev.Enable(False) # TODO: not implemented yet
  476. gridSizer.Add(item = elev, pos = (0, 1))
  477. color = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  478. label = _("by color"))
  479. color.Enable(False) # TODO: not implemented yet
  480. gridSizer.Add(item = color, pos = (0, 2))
  481. boxSizer.Add(item = gridSizer, proportion = 1,
  482. flag = wx.ALL | wx.EXPAND, border = 3)
  483. pageSizer.Add(item = boxSizer, proportion = 0,
  484. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  485. border = 3)
  486. #
  487. # position
  488. #
  489. self.win['surface']['position'] = {}
  490. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  491. label = " %s " % (_("Position")))
  492. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  493. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  494. # position
  495. self._createControl(panel, data = self.win['surface'], name = 'position',
  496. range = (-10000, 10000),
  497. bind = (self.OnSurfacePosition, self.OnSurfacePosition, self.OnSurfacePosition))
  498. axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
  499. choices = ["X",
  500. "Y",
  501. "Z"])
  502. self.win['surface']['position']['axis'] = axis.GetId()
  503. axis.SetSelection(0)
  504. axis.Bind(wx.EVT_CHOICE, self.OnSurfaceAxis)
  505. pslide = self.FindWindowById(self.win['surface']['position']['slider'])
  506. pspin = self.FindWindowById(self.win['surface']['position']['spin'])
  507. gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  508. gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
  509. gridSizer.Add(item = pspin, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
  510. boxSizer.Add(item = gridSizer, proportion = 1,
  511. flag = wx.ALL | wx.EXPAND, border = 3)
  512. box.SetSizer(boxSizer)
  513. box.Layout()
  514. pageSizer.Add(item = boxSizer, proportion = 0,
  515. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  516. border = 3)
  517. panel.SetSizer(pageSizer)
  518. return panel
  519. def _createVectorPage(self):
  520. """!Create view settings page"""
  521. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  522. panel.SetupScrolling(scroll_x = False)
  523. self.page['vector'] = {}
  524. self.page['vector']['id'] = 2
  525. self.page['vector']['panel'] = panel.GetId()
  526. pageSizer = wx.BoxSizer(wx.VERTICAL)
  527. self.win['vector'] = {}
  528. # selection
  529. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  530. label = " %s " % (_("Vector map")))
  531. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  532. vmaps = gselect.Select(parent = panel, type = 'vector',
  533. onPopup = self.GselectOnPopup)
  534. vmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetVector)
  535. self.win['vector']['map'] = vmaps.GetId()
  536. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  537. self.win['vector']['desc'] = desc.GetId()
  538. boxSizer.Add(item = vmaps, proportion = 0,
  539. flag = wx.ALL,
  540. border = 3)
  541. boxSizer.Add(item = desc, proportion = 0,
  542. flag = wx.ALL,
  543. border = 3)
  544. pageSizer.Add(item = boxSizer, proportion = 0,
  545. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  546. border = 3)
  547. #
  548. # vector lines
  549. #
  550. self.win['vector']['lines'] = {}
  551. showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  552. label = _("Show vector lines"))
  553. showLines.SetValue(True)
  554. self.win['vector']['lines']['show'] = showLines.GetId()
  555. showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  556. pageSizer.Add(item = showLines, proportion = 0,
  557. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  558. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  559. label = " %s " % (_("Vector lines")))
  560. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  561. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  562. # width
  563. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  564. label = _("Line:")),
  565. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  566. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  567. label = _("width")),
  568. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  569. wx.ALIGN_RIGHT)
  570. width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  571. initial = 1,
  572. min = 0,
  573. max = 100)
  574. width.SetValue(1)
  575. self.win['vector']['lines']['width'] = width.GetId()
  576. width.Bind(wx.EVT_SPINCTRL, self.OnVectorLines)
  577. gridSizer.Add(item = width, pos = (0, 2),
  578. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  579. # color
  580. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  581. label = _("color")),
  582. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  583. wx.ALIGN_RIGHT)
  584. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  585. colour = (0,0,0),
  586. size = globalvar.DIALOG_COLOR_SIZE)
  587. self.win['vector']['lines']['color'] = color.GetId()
  588. color.Bind(csel.EVT_COLOURSELECT, self.OnVectorLines)
  589. gridSizer.Add(item = color, pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL |
  590. wx.ALIGN_LEFT)
  591. # display
  592. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  593. label = _("display")),
  594. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  595. wx.ALIGN_RIGHT)
  596. display = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  597. choices = [_("on surface"),
  598. _("flat")])
  599. self.win['vector']['lines']['flat'] = display.GetId()
  600. display.Bind(wx.EVT_CHOICE, self.OnVectorDisplay)
  601. gridSizer.Add(item = display, flag = wx.ALIGN_CENTER_VERTICAL |
  602. wx.ALIGN_LEFT, pos = (1, 2), span = (1,2))
  603. # height
  604. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  605. label = _("Height above surface:")),
  606. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL,
  607. span = (1, 3))
  608. surface = wx.ComboBox(parent = panel, id = wx.ID_ANY, size = (250, -1),
  609. style = wx.CB_SIMPLE | wx.CB_READONLY,
  610. choices = [])
  611. surface.Bind(wx.EVT_COMBOBOX, self.OnVectorSurface)
  612. self.win['vector']['lines']['surface'] = surface.GetId()
  613. gridSizer.Add(item = surface,
  614. pos = (2, 3), span = (1, 6),
  615. flag = wx.ALIGN_CENTER_VERTICAL)
  616. self._createControl(panel, data = self.win['vector']['lines'], name = 'height', size = 300,
  617. range = (0, 1000),
  618. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
  619. self.FindWindowById(self.win['vector']['lines']['height']['slider']).SetValue(0)
  620. self.FindWindowById(self.win['vector']['lines']['height']['spin']).SetValue(0)
  621. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['slider']),
  622. pos = (3, 0), span = (1, 7))
  623. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['spin']),
  624. pos = (3, 7),
  625. flag = wx.ALIGN_CENTER)
  626. boxSizer.Add(item = gridSizer, proportion = 1,
  627. flag = wx.ALL | wx.EXPAND, border = 3)
  628. pageSizer.Add(item = boxSizer, proportion = 0,
  629. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  630. border = 3)
  631. #
  632. # vector points
  633. #
  634. self.win['vector']['points'] = {}
  635. showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  636. label = _("Show vector points"))
  637. showPoints.SetValue(True)
  638. self.win['vector']['points']['show'] = showPoints.GetId()
  639. showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  640. pageSizer.Add(item = showPoints, proportion = 0,
  641. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  642. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  643. label = " %s " % (_("Vector points")))
  644. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  645. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  646. # icon size
  647. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  648. label = _("Icon:")),
  649. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  650. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  651. label = _("size")),
  652. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  653. wx.ALIGN_RIGHT)
  654. isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  655. initial = 1,
  656. min = 1,
  657. max = 1e6)
  658. isize.SetName('value')
  659. isize.SetValue(100)
  660. self.win['vector']['points']['size'] = isize.GetId()
  661. isize.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  662. isize.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  663. gridSizer.Add(item = isize, pos = (0, 2),
  664. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  665. # icon color
  666. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  667. label = _("color")),
  668. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  669. wx.ALIGN_RIGHT)
  670. icolor = csel.ColourSelect(panel, id = wx.ID_ANY,
  671. size = globalvar.DIALOG_COLOR_SIZE)
  672. icolor.SetName("color")
  673. icolor.SetColour((0,0,255))
  674. self.win['vector']['points']['color'] = icolor.GetId()
  675. icolor.Bind(csel.EVT_COLOURSELECT, self.OnVectorPoints)
  676. gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL |
  677. wx.ALIGN_LEFT,
  678. pos = (0, 4))
  679. # icon width
  680. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  681. label = _("width")),
  682. pos = (0, 5), flag = wx.ALIGN_CENTER_VERTICAL |
  683. wx.ALIGN_RIGHT)
  684. iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  685. initial = 1,
  686. min = 1,
  687. max = 1e6)
  688. iwidth.SetName('value')
  689. iwidth.SetValue(100)
  690. self.win['vector']['points']['width'] = iwidth.GetId()
  691. iwidth.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  692. iwidth.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  693. gridSizer.Add(item = iwidth, pos = (0, 6),
  694. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  695. # icon symbol
  696. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  697. label = _("symbol")),
  698. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  699. isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  700. choices = UserSettings.Get(group = 'nviz', key = 'vector',
  701. subkey = ['points', 'marker'], internal = True))
  702. isym.SetName("selection")
  703. self.win['vector']['points']['marker'] = isym.GetId()
  704. isym.Bind(wx.EVT_CHOICE, self.OnVectorPoints)
  705. gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL,
  706. pos = (1, 2), span = (1,2))
  707. # high
  708. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  709. label = _("Height above surface:")),
  710. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL,
  711. span = (1, 3))
  712. surface = wx.ComboBox(parent = panel, id = wx.ID_ANY, size = (250, -1),
  713. style = wx.CB_SIMPLE | wx.CB_READONLY,
  714. choices = [])
  715. surface.Bind(wx.EVT_COMBOBOX, self.OnVectorSurface)
  716. self.win['vector']['points']['surface'] = surface.GetId()
  717. gridSizer.Add(item = surface,
  718. pos = (2, 3), span = (1, 5),
  719. flag = wx.ALIGN_CENTER_VERTICAL)
  720. self._createControl(panel, data = self.win['vector']['points'], name = 'height', size = 300,
  721. range = (0, 1000),
  722. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
  723. self.FindWindowById(self.win['vector']['points']['height']['slider']).SetValue(0)
  724. self.FindWindowById(self.win['vector']['points']['height']['spin']).SetValue(0)
  725. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['slider']),
  726. pos = (3, 0), span = (1, 7))
  727. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['spin']),
  728. pos = (3, 7),
  729. flag = wx.ALIGN_CENTER)
  730. boxSizer.Add(item = gridSizer, proportion = 1,
  731. flag = wx.ALL | wx.EXPAND, border = 3)
  732. pageSizer.Add(item = boxSizer, proportion = 0,
  733. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  734. border = 3)
  735. panel.SetSizer(pageSizer)
  736. return panel
  737. def GselectOnPopup(self, ltype, exclude = False):
  738. """Update gselect.Select() items"""
  739. maps = list()
  740. for layer in self.mapWindow.Map.GetListOfLayers(l_type = ltype):
  741. maps.append(layer.GetName())
  742. return maps, exclude
  743. def _createVolumePage(self):
  744. """!Create view settings page"""
  745. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  746. panel.SetupScrolling(scroll_x = False)
  747. self.page['volume'] = {}
  748. self.page['volume']['id'] = 3
  749. self.page['volume']['panel'] = panel.GetId()
  750. pageSizer = wx.BoxSizer(wx.VERTICAL)
  751. self.win['volume'] = {}
  752. # selection
  753. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  754. label = " %s " % (_("3D Raster map")))
  755. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  756. rmaps = gselect.Select(parent = panel, type = 'raster3d',
  757. onPopup = self.GselectOnPopup)
  758. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster3D)
  759. self.win['volume']['map'] = rmaps.GetId()
  760. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  761. self.win['volume']['desc'] = desc.GetId()
  762. boxSizer.Add(item = rmaps, proportion = 0,
  763. flag = wx.ALL,
  764. border = 3)
  765. boxSizer.Add(item = desc, proportion = 0,
  766. flag = wx.ALL,
  767. border = 3)
  768. pageSizer.Add(item = boxSizer, proportion = 0,
  769. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  770. border = 3)
  771. #
  772. # draw
  773. #
  774. self.win['volume']['draw'] = {}
  775. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  776. label = " %s " % (_("Draw")))
  777. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  778. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  779. gridSizer.AddGrowableCol(4)
  780. # mode
  781. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  782. label = _("Mode:")),
  783. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  784. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (150, -1),
  785. choices = [_("isosurfaces"),
  786. _("slides")])
  787. mode.SetSelection(0)
  788. mode.SetName("selection")
  789. # mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  790. self.win['volume']['draw']['mode'] = mode.GetId()
  791. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
  792. pos = (0, 1))
  793. # shading
  794. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  795. label = _("Shading:")),
  796. pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  797. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  798. choices = [_("flat"),
  799. _("gouraud")])
  800. shade.SetName("selection")
  801. self.win['volume']['draw']['shading'] = shade.GetId()
  802. shade.Bind(wx.EVT_CHOICE, self.OnVolumeIsosurfMode)
  803. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  804. pos = (0, 3))
  805. # resolution (mode)
  806. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  807. label = _("Resolution:")),
  808. pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL)
  809. resol = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  810. initial = 1,
  811. min = 1,
  812. max = 100)
  813. resol.SetName("value")
  814. self.win['volume']['draw']['resolution'] = resol.GetId()
  815. resol.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfResolution)
  816. resol.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfResolution)
  817. gridSizer.Add(item = resol, pos = (0, 5))
  818. boxSizer.Add(item = gridSizer, proportion = 1,
  819. flag = wx.ALL | wx.EXPAND, border = 3)
  820. pageSizer.Add(item = boxSizer, proportion = 0,
  821. flag = wx.EXPAND | wx.ALL,
  822. border = 3)
  823. #
  824. # manage isosurfaces
  825. #
  826. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  827. label = " %s " % (_("List of isosurfaces")))
  828. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  829. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  830. # list
  831. isolevel = wx.CheckListBox(parent = panel, id = wx.ID_ANY,
  832. size = (300, 150))
  833. self.Bind(wx.EVT_CHECKLISTBOX, self.OnVolumeIsosurfCheck, isolevel)
  834. self.Bind(wx.EVT_LISTBOX, self.OnVolumeIsosurfSelect, isolevel)
  835. self.win['volume']['isosurfs'] = isolevel.GetId()
  836. gridSizer.Add(item = isolevel, pos = (0, 0), span = (4, 1))
  837. # buttons (add, delete, move up, move down)
  838. btnAdd = wx.Button(parent = panel, id = wx.ID_ADD)
  839. self.win['volume']['btnIsosurfAdd'] = btnAdd.GetId()
  840. btnAdd.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfAdd)
  841. gridSizer.Add(item = btnAdd,
  842. pos = (0, 1))
  843. btnDelete = wx.Button(parent = panel, id = wx.ID_DELETE)
  844. self.win['volume']['btnIsosurfDelete'] = btnDelete.GetId()
  845. btnDelete.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfDelete)
  846. btnDelete.Enable(False)
  847. gridSizer.Add(item = btnDelete,
  848. pos = (1, 1))
  849. btnMoveUp = wx.Button(parent = panel, id = wx.ID_UP)
  850. self.win['volume']['btnIsosurfMoveUp'] = btnMoveUp.GetId()
  851. btnMoveUp.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveUp)
  852. btnMoveUp.Enable(False)
  853. gridSizer.Add(item = btnMoveUp,
  854. pos = (2, 1))
  855. btnMoveDown = wx.Button(parent = panel, id = wx.ID_DOWN)
  856. self.win['volume']['btnIsosurfMoveDown'] = btnMoveDown.GetId()
  857. btnMoveDown.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveDown)
  858. btnMoveDown.Enable(False)
  859. gridSizer.Add(item = btnMoveDown,
  860. pos = (3, 1))
  861. boxSizer.Add(item = gridSizer, proportion = 1,
  862. flag = wx.ALL | wx.EXPAND, border = 3)
  863. pageSizer.Add(item = boxSizer, proportion = 0,
  864. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  865. border = 3)
  866. #
  867. # isosurface attributes
  868. #
  869. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  870. label = " %s " % (_("Isosurface attributes")))
  871. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  872. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  873. self.win['volume']['attr'] = {}
  874. row = 0
  875. for code, attrb in (('topo', _("Topography level")),
  876. ('color', _("Color")),
  877. ('mask', _("Mask")),
  878. ('transp', _("Transparency")),
  879. ('shine', _("Shininess")),
  880. ('emit', _("Emission"))):
  881. self.win['volume'][code] = {}
  882. # label
  883. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  884. label = attrb + ':'),
  885. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  886. if code != 'topo':
  887. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  888. choices = [_("map")])
  889. else:
  890. use = None
  891. # check for required properties
  892. if code not in ('topo', 'color', 'shine'):
  893. use.Insert(item = _("unset"), pos = 0)
  894. self.win['volume'][code]['required'] = False
  895. else:
  896. self.win['volume'][code]['required'] = True
  897. if use and code != 'mask':
  898. use.Append(item = _('constant'))
  899. if use:
  900. self.win['volume'][code]['use'] = use.GetId()
  901. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  902. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  903. pos = (row, 1))
  904. if code != 'topo':
  905. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  906. # size = globalvar.DIALOG_GSELECT_SIZE,
  907. size = (200, -1),
  908. type = "grid3")
  909. self.win['volume'][code]['map'] = map.GetId() - 1 # FIXME
  910. map.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  911. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
  912. pos = (row, 2))
  913. else:
  914. map = None
  915. if code == 'color':
  916. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  917. colour = (0,0,0),
  918. size = globalvar.DIALOG_COLOR_SIZE)
  919. value.Bind(csel.EVT_COLOURSELECT, self.OnVolumeIsosurfMap)
  920. elif code == 'mask':
  921. value = None
  922. else:
  923. if code == 'topo':
  924. size = (200, -1)
  925. else:
  926. size = (65, -1)
  927. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = size,
  928. initial = 0)
  929. if code == 'topo':
  930. value.SetRange(minVal = -1e9, maxVal = 1e9)
  931. elif code in ('shine', 'transp', 'emit'):
  932. value.SetRange(minVal = 0, maxVal = 255)
  933. else:
  934. value.SetRange(minVal = 0, maxVal = 100)
  935. value.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfMap)
  936. value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  937. if value:
  938. self.win['volume'][code]['const'] = value.GetId()
  939. if code == 'topo':
  940. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  941. pos = (row, 2))
  942. else:
  943. value.Enable(False)
  944. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  945. pos = (row, 3))
  946. else:
  947. self.win['volume'][code]['const'] = None
  948. if code != 'topo':
  949. self.SetMapObjUseMap(nvizType = 'volume',
  950. attrb = code) # -> enable map / disable constant
  951. row += 1
  952. boxSizer.Add(item = gridSizer, proportion = 1,
  953. flag = wx.ALL | wx.EXPAND, border = 3)
  954. pageSizer.Add(item = boxSizer, proportion = 0,
  955. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  956. border = 3)
  957. panel.SetSizer(pageSizer)
  958. return panel
  959. def _createLightPage(self):
  960. """!Create light page"""
  961. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  962. panel.SetupScrolling(scroll_x = False)
  963. self.page['light'] = { 'id' : 4 }
  964. self.win['light'] = {}
  965. pageSizer = wx.BoxSizer(wx.VERTICAL)
  966. show = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  967. label = _("Show light model"))
  968. show.Bind(wx.EVT_CHECKBOX, self.OnShowLightModel)
  969. pageSizer.Add(item = show, proportion = 0,
  970. flag = wx.ALL, border = 3)
  971. surface = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  972. label = _("Follow source viewpoint"))
  973. pageSizer.Add(item = surface, proportion = 0,
  974. flag = wx.ALL, border = 3)
  975. # position
  976. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  977. label = " %s " % (_("Light source position")))
  978. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  979. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  980. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  981. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("W")),
  982. pos = (1, 0), flag = wx.ALIGN_CENTER)
  983. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
  984. pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
  985. pos = LightPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
  986. mapwindow = self.mapWindow)
  987. self.win['light']['position'] = pos.GetId()
  988. posSizer.Add(item = pos,
  989. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  990. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
  991. pos = (2, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_TOP)
  992. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("E")),
  993. pos = (1, 2), flag = wx.ALIGN_CENTER)
  994. gridSizer.Add(item = posSizer, pos = (0, 0))
  995. # height
  996. self._createControl(panel, data = self.win['light'], name = 'z', sliderHor = False,
  997. range = (0, 100),
  998. bind = (self.OnLightChange, None, self.OnLightChange))
  999. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1000. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  1001. pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
  1002. heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['slider']),
  1003. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  1004. heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['spin']),
  1005. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  1006. wx.BOTTOM | wx.RIGHT, pos = (1, 1))
  1007. gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_RIGHT)
  1008. boxSizer.Add(item = gridSizer, proportion = 1,
  1009. flag = wx.ALL | wx.EXPAND, border = 2)
  1010. pageSizer.Add(item = boxSizer, proportion = 0,
  1011. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1012. border = 3)
  1013. # position
  1014. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1015. label = " %s " % (_("Light color and intensity")))
  1016. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1017. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1018. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:")),
  1019. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1020. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  1021. colour = UserSettings.Get(group = 'nviz', key = 'light',
  1022. subkey = 'color'),
  1023. size = globalvar.DIALOG_COLOR_SIZE)
  1024. color.Bind(csel.EVT_COLOURSELECT, self.OnLightColor)
  1025. gridSizer.Add(item = color, pos = (0, 2))
  1026. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Brightness:")),
  1027. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1028. self._createControl(panel, data = self.win['light'], name = 'bright', size = 300,
  1029. range = (0, 100),
  1030. bind = (self.OnLightValue, None, self.OnLightValue))
  1031. gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['slider']),
  1032. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1033. gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['spin']),
  1034. pos = (1, 2),
  1035. flag = wx.ALIGN_CENTER)
  1036. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Ambient:")),
  1037. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1038. self._createControl(panel, data = self.win['light'], name = 'ambient', size = 300,
  1039. range = (0, 100),
  1040. bind = (self.OnLightValue, None, self.OnLightValue))
  1041. gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['slider']),
  1042. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1043. gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['spin']),
  1044. pos = (2, 2),
  1045. flag = wx.ALIGN_CENTER)
  1046. boxSizer.Add(item = gridSizer, proportion = 1,
  1047. flag = wx.ALL | wx.EXPAND, border = 2)
  1048. pageSizer.Add(item = boxSizer, proportion = 0,
  1049. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1050. border = 3)
  1051. # reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  1052. # reset.SetToolTipString(_("Reset to default view"))
  1053. # # self.win['reset'] = reset.GetId()
  1054. # reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  1055. # viewSizer.Add(item = reset, proportion = 1,
  1056. # flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT,
  1057. # border = 5)
  1058. # gridSizer.AddGrowableCol(3)
  1059. # gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
  1060. # flag = wx.EXPAND)
  1061. panel.SetSizer(pageSizer)
  1062. return panel
  1063. def _createFringePage(self):
  1064. """!Create fringe page"""
  1065. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  1066. panel.SetupScrolling(scroll_x = False)
  1067. self.page['fringe'] = { 'id' : 2 }
  1068. self.win['fringe'] = {}
  1069. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1070. # selection
  1071. rbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1072. label = " %s " % (_("Surface")))
  1073. rboxSizer = wx.StaticBoxSizer(rbox, wx.VERTICAL)
  1074. rmaps = gselect.Select(parent = panel, type = 'raster',
  1075. onPopup = self.GselectOnPopup)
  1076. self.win['fringe']['surface'] = rmaps.GetId()
  1077. rboxSizer.Add(item = rmaps, proportion = 0,
  1078. flag = wx.ALL,
  1079. border = 3)
  1080. pageSizer.Add(item = rboxSizer, proportion = 0,
  1081. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1082. border = 3)
  1083. ebox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1084. label = " %s " % (_("Edges with fringe")))
  1085. eboxSizer = wx.StaticBoxSizer(ebox, wx.HORIZONTAL)
  1086. for edge in [(_("N && W"), "nw"),
  1087. (_("N && E"), "ne"),
  1088. (_("S && W"), "sw"),
  1089. (_("S && E"), "se")]:
  1090. chkbox = wx.CheckBox(parent = panel,
  1091. label = edge[0],
  1092. name = edge[1])
  1093. self.win['fringe'][edge[1]] = chkbox.GetId()
  1094. eboxSizer.Add(item = chkbox, proportion = 0,
  1095. flag = wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT, border = 5)
  1096. chkbox.Bind(wx.EVT_CHECKBOX, self.OnFringe)
  1097. pageSizer.Add(item = eboxSizer, proportion = 0,
  1098. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1099. border = 3)
  1100. sbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1101. label = " %s " % (_("Settings")))
  1102. sboxSizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
  1103. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  1104. # elevation
  1105. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1106. label = _("Elevation of fringe from bottom:")),
  1107. pos = (0, 0),
  1108. flag = wx.ALIGN_CENTER_VERTICAL)
  1109. spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
  1110. size = (65, -1), min = -1e6, max = 1e6)
  1111. spin.SetValue(UserSettings.Get(group = 'nviz', key = 'fringe', subkey = 'elev'))
  1112. spin.Bind(wx.EVT_SPINCTRL, self.OnFringe)
  1113. self.win['fringe']['elev'] = spin.GetId()
  1114. gridSizer.Add(item = spin, pos = (0, 1))
  1115. # color
  1116. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1117. label = _("Color:")),
  1118. pos = (1, 0),
  1119. flag = wx.ALIGN_CENTER_VERTICAL)
  1120. color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  1121. size = globalvar.DIALOG_COLOR_SIZE)
  1122. color.SetColour(UserSettings.Get(group = 'nviz', key = 'fringe',
  1123. subkey = 'color'))
  1124. color.Bind(csel.EVT_COLOURSELECT, self.OnFringe)
  1125. self.win['fringe']['color'] = color.GetId()
  1126. gridSizer.Add(item = color, pos = (1, 1))
  1127. sboxSizer.Add(item = gridSizer, proportion = 1,
  1128. flag = wx.ALL | wx.EXPAND, border = 3)
  1129. pageSizer.Add(item = sboxSizer, proportion = 0,
  1130. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1131. border = 3)
  1132. panel.SetSizer(pageSizer)
  1133. return panel
  1134. def GetLayerData(self, nvizType):
  1135. """!Get nviz data"""
  1136. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1137. if nvizType == 'surface':
  1138. return self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1139. elif nvizType == 'vector':
  1140. return self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')
  1141. elif nvizType == 'volume':
  1142. return self.mapWindow.GetLayerByName(name, mapType = 'raster3d', dataType = 'nviz')
  1143. return None
  1144. def OnFringe(self, event):
  1145. """!Show/hide fringe"""
  1146. enabled = event.IsChecked()
  1147. win = self.FindWindowById(event.GetId())
  1148. data = self.GetLayerData('surface')['surface']
  1149. sid = data['object']['id']
  1150. elev = self.FindWindowById(self.win['fringe']['elev']).GetValue()
  1151. color = self.FindWindowById(self.win['fringe']['color']).GetValue()
  1152. self._display.SetFringe(sid, color, elev,
  1153. self.FindWindowById(self.win['fringe']['nw']).IsChecked(),
  1154. self.FindWindowById(self.win['fringe']['ne']).IsChecked(),
  1155. self.FindWindowById(self.win['fringe']['sw']).IsChecked(),
  1156. self.FindWindowById(self.win['fringe']['se']).IsChecked())
  1157. self.mapWindow.Refresh(False)
  1158. def OnScroll(self, event, win, data):
  1159. """!Generic scrolling handler"""
  1160. winName = self.__GetWindowName(win, event.GetId())
  1161. if not winName:
  1162. return
  1163. data[winName] = event.GetInt()
  1164. for w in win[winName].itervalues():
  1165. self.FindWindowById(w).SetValue(data[winName])
  1166. event.Skip()
  1167. def _createControl(self, parent, data, name, range, bind = (None, None, None),
  1168. sliderHor = True, size = 200):
  1169. """!Add control (Slider + SpinCtrl)"""
  1170. data[name] = dict()
  1171. if sliderHor:
  1172. style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  1173. wx.SL_BOTTOM
  1174. sizeW = (size, -1)
  1175. else:
  1176. style = wx.SL_VERTICAL | wx.SL_AUTOTICKS | \
  1177. wx.SL_INVERSE
  1178. sizeW = (-1, size)
  1179. slider = wx.Slider(parent = parent, id = wx.ID_ANY,
  1180. minValue = range[0],
  1181. maxValue = range[1],
  1182. style = style,
  1183. size = sizeW)
  1184. slider.SetName('slider')
  1185. if bind[0]:
  1186. slider.Bind(wx.EVT_SCROLL, bind[0])
  1187. # slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, bind[1])
  1188. if bind[1]:
  1189. slider.Bind(wx.EVT_SCROLL_CHANGED, bind[1]) # this only works in MSW
  1190. data[name]['slider'] = slider.GetId()
  1191. spin = wx.SpinCtrl(parent = parent, id = wx.ID_ANY, size = (65, -1),
  1192. min = range[0],
  1193. max = range[1])
  1194. # no 'changed' event ... (FIXME)
  1195. spin.SetName('spin')
  1196. if bind[2]:
  1197. spin.Bind(wx.EVT_SPINCTRL, bind[2])
  1198. data[name]['spin'] = spin.GetId()
  1199. def __GetWindowName(self, data, id):
  1200. for name in data.iterkeys():
  1201. if type(data[name]) is type({}):
  1202. for win in data[name].itervalues():
  1203. if win == id:
  1204. return name
  1205. else:
  1206. if data[name] == id:
  1207. return name
  1208. return None
  1209. def UpdateSettings(self):
  1210. """!Update view from settings values
  1211. stored in self.mapWindow.view dictionary"""
  1212. for control in ('height',
  1213. 'persp',
  1214. 'twist',
  1215. 'z-exag'):
  1216. for win in self.win['view'][control].itervalues():
  1217. if control == 'height':
  1218. value = UserSettings.Get(group = 'nviz', key = 'view',
  1219. subkey = ['height', 'value'], internal = True)
  1220. else:
  1221. try:
  1222. value = self.mapWindow.view[control]['value']
  1223. except KeyError:
  1224. value = -1
  1225. self.FindWindowById(win).SetValue(value)
  1226. viewWin = self.FindWindowById(self.win['view']['position'])
  1227. x, y = viewWin.UpdatePos(self.mapWindow.view['position']['x'],
  1228. self.mapWindow.view['position']['y'])
  1229. viewWin.Draw(pos = (x, y), scale = True)
  1230. viewWin.Refresh(False)
  1231. # bgcolor = self.FindWindowById(self.win['settings']['general']['bgcolor']).GetColour()
  1232. # self.OnBgColor(event = bgcolor)
  1233. self.Update()
  1234. self.mapWindow.Refresh(eraseBackground = False)
  1235. self.mapWindow.render['quick'] = False
  1236. self.mapWindow.Refresh(False)
  1237. def OnShowLightModel(self, event):
  1238. """!Show light model"""
  1239. self._display.showLight = event.IsChecked()
  1240. self._display.DrawLightingModel()
  1241. def OnLightChange(self, event):
  1242. """!Position of the light changed"""
  1243. winName = self.__GetWindowName(self.win['light'], event.GetId())
  1244. if not winName:
  1245. return
  1246. val = event.GetInt()
  1247. self.mapWindow.light['position']['z'] = val / 100.
  1248. for win in self.win['light'][winName].itervalues():
  1249. self.FindWindowById(win).SetValue(val)
  1250. event = wxUpdateLight()
  1251. wx.PostEvent(self.mapWindow, event)
  1252. event.Skip()
  1253. def OnLightColor(self, event):
  1254. """!Color of the light changed"""
  1255. self.mapWindow.light['color'] = event.GetValue()
  1256. event = wxUpdateLight()
  1257. wx.PostEvent(self.mapWindow, event)
  1258. event.Skip()
  1259. def OnLightValue(self, event):
  1260. """!Light brightness changed"""
  1261. data = self.mapWindow.light
  1262. self.OnScroll(event, self.win['light'], data)
  1263. event = wxUpdateLight()
  1264. wx.PostEvent(self.mapWindow, event)
  1265. event.Skip()
  1266. def OnBgColor(self, event):
  1267. """!Background color changed"""
  1268. color = event.GetValue()
  1269. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1270. self._display.SetBgColor(str(color))
  1271. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1272. self.mapWindow.Refresh(False)
  1273. def OnSetRaster(self, event):
  1274. """!Raster map selected, update surface page"""
  1275. name = event.GetString()
  1276. try:
  1277. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
  1278. except:
  1279. self.EnablePage('surface', False)
  1280. return
  1281. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  1282. self.EnablePage('surface', True)
  1283. self.UpdateSurfacePage(layer, data, updateName = False)
  1284. def OnSetVector(self, event):
  1285. """!Vector map selected, update properties page"""
  1286. name = event.GetString()
  1287. try:
  1288. data = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')['vector']
  1289. except:
  1290. self.EnablePage('vector', False)
  1291. return
  1292. layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
  1293. self.EnablePage('vector', True)
  1294. self.UpdateVectorPage(layer, data, updateName = False)
  1295. def OnSetRaster3D(self, event):
  1296. """!3D Raster map selected, update surface page"""
  1297. name = event.GetString()
  1298. try:
  1299. data = self.mapWindow.GetLayerByName(name, mapType = 'raster3d', dataType = 'nviz')['surface']
  1300. except:
  1301. self.EnablePage('volume', False)
  1302. return
  1303. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster3d')
  1304. self.EnablePage('volume', True)
  1305. self.UpdateVolumePage(layer, data, updateName = False)
  1306. def OnViewChange(self, event):
  1307. """!Change view, render in quick mode"""
  1308. # find control
  1309. winName = self.__GetWindowName(self.win['view'], event.GetId())
  1310. if not winName:
  1311. return
  1312. if winName == 'height':
  1313. view = self.mapWindow.iview # internal
  1314. else:
  1315. view = self.mapWindow.view
  1316. if winName == 'z-exag' and event.GetInt() >= 0:
  1317. self.PostViewEvent(zExag = True)
  1318. else:
  1319. self.PostViewEvent(zExag = False)
  1320. view[winName]['value'] = event.GetInt()
  1321. for win in self.win['view'][winName].itervalues():
  1322. self.FindWindowById(win).SetValue(view[winName]['value'])
  1323. self.mapWindow.render['quick'] = True
  1324. self.mapWindow.Refresh(False)
  1325. event.Skip()
  1326. def OnViewChanged(self, event):
  1327. """!View changed, render in full resolution"""
  1328. self.mapWindow.render['quick'] = False
  1329. self.mapWindow.Refresh(False)
  1330. self.UpdateSettings()
  1331. def OnViewChangedSpin(self, event):
  1332. """!View changed, render in full resolution"""
  1333. self.mapWindow.render['quick'] = False
  1334. self.OnViewChange(event)
  1335. self.OnViewChanged(None)
  1336. self.Update()
  1337. event.Skip()
  1338. def OnResetView(self, event):
  1339. """!Reset to default view (view page)"""
  1340. self.mapWindow.ResetView()
  1341. self.UpdateSettings()
  1342. self.mapWindow.Refresh(False)
  1343. def OnLookAt(self, event):
  1344. """!Look at (view page)"""
  1345. sel = event.GetSelection()
  1346. if sel == 0: # top
  1347. self.mapWindow.view['position']['x'] = 0.5
  1348. self.mapWindow.view['position']['y'] = 0.5
  1349. elif sel == 1: # north
  1350. self.mapWindow.view['position']['x'] = 0.5
  1351. self.mapWindow.view['position']['y'] = 0.0
  1352. elif sel == 2: # south
  1353. self.mapWindow.view['position']['x'] = 0.5
  1354. self.mapWindow.view['position']['y'] = 1.0
  1355. elif sel == 3: # east
  1356. self.mapWindow.view['position']['x'] = 1.0
  1357. self.mapWindow.view['position']['y'] = 0.5
  1358. elif sel == 4: # west
  1359. self.mapWindow.view['position']['x'] = 0.0
  1360. self.mapWindow.view['position']['y'] = 0.5
  1361. elif sel == 5: # north-west
  1362. self.mapWindow.view['position']['x'] = 0.0
  1363. self.mapWindow.view['position']['y'] = 0.0
  1364. elif sel == 6: # north-east
  1365. self.mapWindow.view['position']['x'] = 1.0
  1366. self.mapWindow.view['position']['y'] = 0.0
  1367. elif sel == 7: # south-east
  1368. self.mapWindow.view['position']['x'] = 1.0
  1369. self.mapWindow.view['position']['y'] = 1.0
  1370. elif sel == 8: # south-west
  1371. self.mapWindow.view['position']['x'] = 0.0
  1372. self.mapWindow.view['position']['y'] = 1.0
  1373. self.PostViewEvent(zExag = True)
  1374. self.UpdateSettings()
  1375. self.mapWindow.render['quick'] = False
  1376. self.mapWindow.Refresh(False)
  1377. def OnClose(self, event):
  1378. """!Close button pressed
  1379. Close dialog
  1380. """
  1381. self.Hide()
  1382. def OnMapObjUse(self, event):
  1383. """!Set surface attribute -- use -- map/constant"""
  1384. if not self.mapWindow.init:
  1385. return
  1386. wx.Yield()
  1387. # find attribute row
  1388. attrb = self.__GetWindowName(self.win['surface'], event.GetId())
  1389. if not attrb:
  1390. attrb = self.__GetWindowName(self.win['volume'], event.GetId())
  1391. nvizType = 'volume'
  1392. else:
  1393. nvizType = 'surface'
  1394. selection = event.GetSelection()
  1395. if self.win[nvizType][attrb]['required']: # no 'unset'
  1396. selection += 1
  1397. if selection == 0: # unset
  1398. useMap = None
  1399. value = ''
  1400. elif selection == 1: # map
  1401. useMap = True
  1402. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1403. elif selection == 2: # constant
  1404. useMap = False
  1405. if attrb == 'color':
  1406. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1407. value = self._getColorString(value)
  1408. else:
  1409. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  1410. self.SetMapObjUseMap(nvizType = nvizType,
  1411. attrb = attrb, map = useMap)
  1412. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1413. if nvizType == 'surface':
  1414. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1415. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  1416. 'value' : str(value),
  1417. 'update' : None }
  1418. else: # volume / isosurface
  1419. data = self.mapWindow.GetLayerByName(name, mapType = 'raster3d', dataType = 'nviz')
  1420. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1421. id = list.GetSelection()
  1422. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  1423. 'value' : str(value),
  1424. 'update' : None }
  1425. # update properties
  1426. event = wxUpdateProperties(data = data)
  1427. wx.PostEvent(self.mapWindow, event)
  1428. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1429. self.mapWindow.Refresh(False)
  1430. def EnablePage(self, name, enabled = True):
  1431. """!Enable/disable all widgets on page"""
  1432. for key, item in self.win[name].iteritems():
  1433. if key == 'map':
  1434. continue
  1435. if type(item) == types.DictType:
  1436. for sitem in self.win[name][key].itervalues():
  1437. if type(sitem) == types.IntType:
  1438. self.FindWindowById(sitem).Enable(enabled)
  1439. else:
  1440. if type(item) == types.IntType:
  1441. self.FindWindowById(item).Enable(enabled)
  1442. def SetMapObjUseMap(self, nvizType, attrb, map = None):
  1443. """!Update dialog widgets when attribute type changed"""
  1444. if attrb in ('topo', 'color', 'shine'):
  1445. incSel = -1 # decrement selection (no 'unset')
  1446. else:
  1447. incSel = 0
  1448. if map is True: # map
  1449. if attrb != 'topo': # changing map topography not allowed
  1450. # not sure why, but here must be disabled both ids, should be fixed!
  1451. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(True)
  1452. if self.win[nvizType][attrb]['const']:
  1453. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  1454. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(1 + incSel)
  1455. elif map is False: # const
  1456. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  1457. if self.win[nvizType][attrb]['const']:
  1458. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(True)
  1459. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(2 + incSel)
  1460. else: # unset
  1461. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  1462. if self.win[nvizType][attrb]['const']:
  1463. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  1464. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(0)
  1465. def OnSurfaceMap(self, event):
  1466. """!Set surface attribute"""
  1467. self.SetMapObjAttrb(nvizType = 'surface', winId = event.GetId())
  1468. def SetMapObjAttrb(self, nvizType, winId):
  1469. """!Set map object (surface/isosurface) attribute (map/constant)"""
  1470. if not self.mapWindow.init:
  1471. return
  1472. attrb = self.__GetWindowName(self.win[nvizType], winId)
  1473. if not attrb:
  1474. return
  1475. if nvizType == 'volume' and attrb == 'topo':
  1476. return
  1477. selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
  1478. if self.win[nvizType][attrb]['required']:
  1479. selection += 1
  1480. if selection == 0: # unset
  1481. useMap = None
  1482. value = ''
  1483. elif selection == 1: # map
  1484. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1485. useMap = True
  1486. else: # constant
  1487. if attrb == 'color':
  1488. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1489. # tuple to string
  1490. value = self._getColorString(value)
  1491. else:
  1492. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  1493. useMap = False
  1494. if not self.pageChanging:
  1495. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1496. if nvizType == 'surface':
  1497. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1498. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  1499. 'value' : str(value),
  1500. 'update' : None }
  1501. else:
  1502. data = self.mapWindow.GetLayerByName(name, mapType = 'raster3d', dataType = 'nviz')
  1503. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1504. id = list.GetSelection()
  1505. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  1506. 'value' : str(value),
  1507. 'update' : None }
  1508. # update properties
  1509. event = wxUpdateProperties(data = data)
  1510. wx.PostEvent(self.mapWindow, event)
  1511. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1512. self.mapWindow.Refresh(False)
  1513. def OnSurfaceResolution(self, event):
  1514. """!Draw resolution changed"""
  1515. self.SetSurfaceResolution()
  1516. if apply and self.mapDisplay.statusbarWin['render'].IsChecked():
  1517. self.mapWindow.Refresh(False)
  1518. def SetSurfaceResolution(self):
  1519. """!Set draw resolution"""
  1520. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  1521. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  1522. data = self.GetLayerData('surface')
  1523. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  1524. 'fine' : fine,
  1525. 'update' : None }
  1526. # update properties
  1527. event = wxUpdateProperties(data = data)
  1528. wx.PostEvent(self.mapWindow, event)
  1529. def SetSurfaceMode(self):
  1530. """!Set draw mode
  1531. @param apply allow auto-rendering
  1532. """
  1533. mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
  1534. if mode == 0: # coarse
  1535. self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
  1536. self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(False)
  1537. elif mode == 1: # fine
  1538. self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(False)
  1539. self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
  1540. else: # both
  1541. self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
  1542. self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
  1543. style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
  1544. shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
  1545. value, desc = self.mapWindow.nvizDefault.GetDrawMode(mode, style, shade)
  1546. return value, desc
  1547. def OnSurfaceMode(self, event):
  1548. """!Set draw mode"""
  1549. value, desc = self.SetSurfaceMode()
  1550. data = self.GetLayerData('surface')
  1551. data['surface']['draw']['mode'] = { 'value' : value,
  1552. 'desc' : desc,
  1553. 'update' : None }
  1554. # update properties
  1555. event = wxUpdateProperties(data = data)
  1556. wx.PostEvent(self.mapWindow, event)
  1557. if apply and self.mapDisplay.statusbarWin['render'].IsChecked():
  1558. self.mapWindow.Refresh(False)
  1559. def OnSurfaceModeAll(self, event):
  1560. """!Set draw mode (including wire color) for all loaded surfaces"""
  1561. value, desc = self.SetSurfaceMode()
  1562. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  1563. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  1564. color = self.FindWindowById(self.win['surface']['draw']['wire-color']).GetColour()
  1565. cvalue = self._getColorString(color)
  1566. for name in self.mapWindow.GetLayerNames(type = 'raster'):
  1567. data = self.GetLayerData('surface')
  1568. if not data:
  1569. continue # shouldy no happen
  1570. data['surface']['draw']['mode'] = { 'value' : value,
  1571. 'desc' : desc,
  1572. 'update' : None }
  1573. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  1574. 'fine' : fine,
  1575. 'update' : None }
  1576. data['surface']['draw']['wire-color'] = { 'value' : cvalue,
  1577. 'update' : None }
  1578. # update properties
  1579. event = wxUpdateProperties(data = data)
  1580. wx.PostEvent(self.mapWindow, event)
  1581. if apply and self.mapDisplay.statusbarWin['render'].IsChecked():
  1582. self.mapWindow.Refresh(False)
  1583. def _getColorString(self, color):
  1584. """!Set wire color"""
  1585. return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1586. def OnSurfaceWireColor(self, event):
  1587. """!Set wire color"""
  1588. data = self.GetLayerData('surface')
  1589. value = self._getColorString(event.GetValue())
  1590. data['surface']['draw']['wire-color'] = { 'value' : value,
  1591. 'update' : None }
  1592. # update properties
  1593. event = wxUpdateProperties(data = data)
  1594. wx.PostEvent(self.mapWindow, event)
  1595. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1596. self.mapWindow.Refresh(False)
  1597. def OnSurfaceAxis(self, event):
  1598. """!Surface position, axis changed"""
  1599. data = self.GetLayerData('surface')
  1600. id = data['surface']['object']['id']
  1601. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  1602. slider = self.FindWindowById(self.win['surface']['position']['slider'])
  1603. spin = self.FindWindowById(self.win['surface']['position']['spin'])
  1604. x, y, z = self._display.GetSurfacePosition(id)
  1605. if axis == 0: # x
  1606. slider.SetValue(x)
  1607. spin.SetValue(x)
  1608. elif axis == 1: # y
  1609. slider.SetValue(y)
  1610. spin.SetValue(y)
  1611. else: # z
  1612. slider.SetValue(z)
  1613. spin.SetValue(z)
  1614. def OnSurfacePosition(self, event):
  1615. """!Surface position"""
  1616. winName = self.__GetWindowName(self.win['surface'], event.GetId())
  1617. if not winName:
  1618. return
  1619. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  1620. value = event.GetInt()
  1621. for win in self.win['surface']['position'].itervalues():
  1622. if win == self.win['surface']['position']['axis']:
  1623. continue
  1624. else:
  1625. self.FindWindowById(win).SetValue(value)
  1626. data = self.GetLayerData('surface')
  1627. id = data['surface']['object']['id']
  1628. x, y, z = self._display.GetSurfacePosition(id)
  1629. if axis == 0: # x
  1630. x = value
  1631. elif axis == 1: # y
  1632. y = value
  1633. else: # z
  1634. z = value
  1635. data = self.GetLayerData('surface')
  1636. data['surface']['position']['x'] = x
  1637. data['surface']['position']['y'] = y
  1638. data['surface']['position']['z'] = z
  1639. data['surface']['position']['update'] = None
  1640. # update properties
  1641. event = wxUpdateProperties(data = data)
  1642. wx.PostEvent(self.mapWindow, event)
  1643. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1644. self.mapWindow.Refresh(False)
  1645. # self.UpdatePage('surface')
  1646. def UpdateVectorShow(self, vecType, enabled):
  1647. """!Enable/disable lines/points widgets
  1648. @param vecType vector type (lines, points)
  1649. """
  1650. if vecType != 'lines' and vecType != 'points':
  1651. return False
  1652. for win in self.win['vector'][vecType].keys():
  1653. if win == 'show':
  1654. continue
  1655. if type(self.win['vector'][vecType][win]) == type({}):
  1656. for swin in self.win['vector'][vecType][win].keys():
  1657. if enabled:
  1658. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
  1659. else:
  1660. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
  1661. else:
  1662. if enabled:
  1663. self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
  1664. else:
  1665. self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
  1666. return True
  1667. def OnVectorShow(self, event):
  1668. """!Show vector lines/points"""
  1669. winId = event.GetId()
  1670. if winId == self.win['vector']['lines']['show']:
  1671. vecType = 'lines'
  1672. points = False
  1673. else: # points
  1674. vecType = 'points'
  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, points = points)
  1682. else:
  1683. self.mapWindow.UnloadVector(item, 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, mapIs3D)
  2191. def UpdateVectorPage(self, layer, data, updateName = True):
  2192. """!Update vector page"""
  2193. npoints, nlines, nfeatures, mapIs3D = 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)