nviz_tools.py 124 KB

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