nviz.py 119 KB

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