nviz_tools.py 139 KB

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