nviz_tools.py 123 KB

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