nviz.py 132 KB

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