nviz_tools.py 120 KB

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