nviz_tools.py 123 KB

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