nviz_tools.py 108 KB

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