nviz.py 116 KB

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