nviz.py 117 KB

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