nviz.py 114 KB

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