nviz_tools.py 142 KB

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