nviz_tools.py 108 KB

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