nviz_tools.py 108 KB

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