nviz_tools.py 139 KB

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