nviz_tools.py 125 KB

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