nviz_tools.py 125 KB

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