nviz_tools.py 125 KB

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