nviz_tools.py 122 KB

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