nviz_tools.py 145 KB

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