nviz.py 115 KB

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