nviz_tools.py 139 KB

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