nviz_tools.py 125 KB

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