nviz_tools.py 140 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309
  1. """!
  2. @package nviz_tools.py
  3. @brief Nviz (3D view) tools window
  4. Classes:
  5. - NvizToolWindow
  6. - PositionWindow
  7. - ViewPositionWindow
  8. - LightPositionWindow
  9. (C) 2008-2011 by the GRASS Development Team
  10. This program is free software under the GNU General Public
  11. License (>=v2). Read the file COPYING that comes with GRASS
  12. for details.
  13. @author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  14. @author Enhancements by Michael Barton <michael.barton asu.edu>
  15. @author Anna Kratochvilova <KratochAnna seznam.cz> (Google SoC 2011)
  16. """
  17. import os
  18. import sys
  19. import copy
  20. import types
  21. import string
  22. import wx
  23. import wx.lib.colourselect as csel
  24. import wx.lib.scrolledpanel as SP
  25. try:
  26. import wx.lib.agw.flatnotebook as FN
  27. except ImportError:
  28. import wx.lib.flatnotebook as FN
  29. try:
  30. from agw import foldpanelbar as fpb
  31. except ImportError: # if it's not there locally, try the wxPython lib.
  32. try:
  33. import wx.lib.agw.foldpanelbar as fpb
  34. except ImportError:
  35. import wx.lib.foldpanelbar as fpb # versions <=2.5.5.1
  36. import grass.script as grass
  37. import globalvar
  38. import gselect
  39. import gcmd
  40. from preferences import globalSettings as UserSettings
  41. try:
  42. from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties
  43. import wxnviz
  44. except ImportError:
  45. pass
  46. from debug import Debug
  47. class ScrolledPanel(SP.ScrolledPanel):
  48. """!Custom ScrolledPanel to avoid strange behaviour concerning focus"""
  49. def __init__(self, parent):
  50. SP.ScrolledPanel.__init__(self, parent = parent, id=wx.ID_ANY)
  51. def OnChildFocus(self, event):
  52. pass
  53. class NTCValidator(wx.PyValidator):
  54. """!validates input in textctrls, taken from wxpython demo"""
  55. def __init__(self, flag = None):
  56. wx.PyValidator.__init__(self)
  57. self.flag = flag
  58. self.Bind(wx.EVT_CHAR, self.OnChar)
  59. def Clone(self):
  60. return NTCValidator(self.flag)
  61. def OnChar(self, event):
  62. key = event.GetKeyCode()
  63. if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
  64. event.Skip()
  65. return
  66. if self.flag == 'DIGIT_ONLY' and chr(key) in string.digits + '.-':
  67. event.Skip()
  68. return
  69. if not wx.Validator_IsSilent():
  70. wx.Bell()
  71. # Returning without calling even.Skip eats the event before it
  72. # gets to the text control
  73. return
  74. class NumTextCtrl(wx.TextCtrl):
  75. """!Class derived from wx.TextCtrl for numerical values only"""
  76. def __init__(self, parent, **kwargs):
  77. wx.TextCtrl.__init__(self, parent = parent,
  78. validator = NTCValidator(flag = 'DIGIT_ONLY'), **kwargs)
  79. def SetValue(self, value):
  80. super(NumTextCtrl, self).SetValue(str(int(value)))
  81. def GetValue(self):
  82. val = super(NumTextCtrl, self).GetValue()
  83. if val == '':
  84. val = '0'
  85. try:
  86. return int(float(val))
  87. except ValueError:
  88. val = ''.join(''.join(val.split('-')).split('.'))
  89. return int(float(val))
  90. def SetRange(self, min, max):
  91. pass
  92. class NvizToolWindow(FN.FlatNotebook):
  93. """!Nviz (3D view) tools panel
  94. """
  95. def __init__(self, parent, display, id = wx.ID_ANY,
  96. style = globalvar.FNPageStyle|FN.FNB_NO_X_BUTTON|FN.FNB_NO_NAV_BUTTONS,
  97. **kwargs):
  98. self.parent = parent # GMFrame
  99. self.mapDisplay = display
  100. self.mapWindow = display.GetWindow()
  101. self._display = self.mapWindow.GetDisplay()
  102. if globalvar.hasAgw:
  103. kwargs['agwStyle'] = style
  104. else:
  105. kwargs['style'] = style
  106. FN.FlatNotebook.__init__(self, parent, id, **kwargs)
  107. self.SetTabAreaColour(globalvar.FNPageColor)
  108. self.win = {} # window ids
  109. self.page = {} # page ids
  110. self.constantIndex = len(self.mapWindow.constants) # index of constant surface
  111. # view page
  112. self.AddPage(page = self._createViewPage(),
  113. text = " %s " % _("View"))
  114. # data page
  115. self.AddPage(page = self._createDataPage(),
  116. text = " %s " % _("Data"))
  117. # appearance page
  118. self.AddPage(page = self._createAppearancePage(),
  119. text = " %s " % _("Appearance"))
  120. self.UpdateSettings()
  121. self.pageChanging = False
  122. self.vetoGSelectEvt = False #when setting map, event is invoked
  123. self.mapWindow.render['quick'] = False
  124. self.mapWindow.Refresh(False)
  125. # bindings
  126. self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
  127. self.Bind(wx.EVT_SIZE, self.OnSize)
  128. Debug.msg(3, "NvizToolWindow.__init__()")
  129. self.Update()
  130. wx.CallAfter(self.SetPage, 'view')
  131. wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear))
  132. wx.CallAfter(self.SetInitialMaps)
  133. def SetInitialMaps(self):
  134. """!Set initial raster and vector map"""
  135. try:
  136. selectedRaster = self.mapWindow.Map.GetListOfLayers(l_type = 'raster')[0].GetName()
  137. self.FindWindowById(self.win['surface']['map']).SetValue(selectedRaster)
  138. self.FindWindowById(self.win['fringe']['map']).SetValue(selectedRaster)
  139. except IndexError:
  140. pass
  141. try:
  142. selectedVector = self.mapWindow.Map.GetListOfLayers(l_type = 'vector')[0].GetName()
  143. self.FindWindowById(self.win['vector']['map']).SetValue(selectedVector)
  144. except IndexError:
  145. pass
  146. def OnPageChanged(self, event):
  147. new = event.GetSelection()
  148. # self.ChangeSelection(new)
  149. def PostViewEvent(self, zExag = False):
  150. """!Change view settings"""
  151. event = wxUpdateView(zExag = zExag)
  152. wx.PostEvent(self.mapWindow, event)
  153. def OnSize(self, event):
  154. """!After window is resized, update scrolling"""
  155. # workaround to resize captionbars of foldpanelbar
  156. wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear))
  157. event.Skip()
  158. def OnPressCaption(self, event):
  159. """!When foldpanel item collapsed/expanded, update scrollbars"""
  160. foldpanel = event.GetBar().GetGrandParent().GetParent()
  161. wx.CallAfter(self.UpdateScrolling, (foldpanel,))
  162. event.Skip()
  163. def UpdateScrolling(self, foldpanels):
  164. """!Update scrollbars in foldpanel"""
  165. for foldpanel in foldpanels:
  166. length = foldpanel.GetPanelsLength(collapsed = 0, expanded = 0)
  167. # virtual width is set to fixed value to suppress GTK warning
  168. foldpanel.GetParent().SetVirtualSize((100, length[2]))
  169. foldpanel.GetParent().Layout()
  170. def _createViewPage(self):
  171. """!Create view settings page"""
  172. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  173. panel.SetupScrolling(scroll_x = False)
  174. self.page['view'] = { 'id' : 0,
  175. 'notebook' : self.GetId()}
  176. pageSizer = wx.BoxSizer(wx.VERTICAL)
  177. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  178. label = " %s " % (_("Control View")))
  179. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  180. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  181. self.win['view'] = {}
  182. # position
  183. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  184. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("W")),
  185. pos = (1, 0), flag = wx.ALIGN_CENTER)
  186. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
  187. pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
  188. view = ViewPositionWindow(panel, size = (175, 175),
  189. mapwindow = self.mapWindow)
  190. self.win['view']['position'] = view.GetId()
  191. posSizer.Add(item = view,
  192. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  193. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
  194. pos = (2, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_TOP)
  195. posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("E")),
  196. pos = (1, 2), flag = wx.ALIGN_CENTER)
  197. gridSizer.Add(item = posSizer, pos = (0, 0))
  198. # perspective
  199. # set initial defaults here (or perhaps in a default values file), not in user settings
  200. self._createControl(panel, data = self.win['view'], name = 'persp',
  201. range = (1,100),
  202. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  203. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Perspective:")),
  204. pos = (1, 0), flag = wx.ALIGN_CENTER)
  205. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['slider']), pos = (2, 0))
  206. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['text']), pos = (3, 0),
  207. flag = wx.ALIGN_CENTER)
  208. # twist
  209. self._createControl(panel, data = self.win['view'], name = 'twist',
  210. range = (-180,180),
  211. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  212. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Twist:")),
  213. pos = (1, 1), flag = wx.ALIGN_CENTER)
  214. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['slider']), pos = (2, 1))
  215. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['text']), pos = (3, 1),
  216. flag = wx.ALIGN_CENTER)
  217. # height + z-exag
  218. self._createControl(panel, data = self.win['view'], name = 'height', sliderHor = False,
  219. range = (0, 1),
  220. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  221. self._createControl(panel, data = self.win['view'], name = 'z-exag', sliderHor = False,
  222. range = (0, 5),
  223. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  224. self.FindWindowById(self.win['view']['z-exag']['slider']).SetValue(1)
  225. self.FindWindowById(self.win['view']['z-exag']['text']).SetValue(1)
  226. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  227. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  228. pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
  229. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['slider']),
  230. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  231. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['text']),
  232. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  233. wx.BOTTOM | wx.RIGHT, pos = (1, 1))
  234. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Z-exag:")),
  235. pos = (0, 2), flag = wx.ALIGN_LEFT, span = (1, 2))
  236. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['slider']),
  237. flag = wx.ALIGN_RIGHT, pos = (1, 2))
  238. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['text']),
  239. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  240. wx.BOTTOM | wx.RIGHT, pos = (1, 3))
  241. gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_RIGHT)
  242. # view setup + reset
  243. viewSizer = wx.BoxSizer(wx.HORIZONTAL)
  244. viewSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY,
  245. label = _("Look at:")),
  246. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  247. border = 5)
  248. viewType = wx.Choice (parent = panel, id = wx.ID_ANY, size = (125, -1),
  249. choices = [_(""),
  250. _("here"),
  251. _("top"),
  252. _("north"),
  253. _("south"),
  254. _("east"),
  255. _("west"),
  256. _("north-west"),
  257. _("north-east"),
  258. _("south-east"),
  259. _("south-west")])
  260. viewType.SetSelection(0)
  261. viewType.Bind(wx.EVT_CHOICE, self.OnLookAt)
  262. self.win['view']['lookAt'] = viewType.GetId()
  263. viewSizer.Add(item = viewType,
  264. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  265. border = 5)
  266. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  267. reset.SetToolTipString(_("Reset to default view"))
  268. # self.win['reset'] = reset.GetId()
  269. reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  270. viewSizer.Add(item = wx.Size(-1, -1), proportion = 1,
  271. flag = wx.EXPAND)
  272. viewSizer.Add(item = reset, proportion = 0,
  273. flag = wx.ALL | wx.ALIGN_RIGHT,
  274. border = 5)
  275. gridSizer.AddGrowableCol(2)
  276. gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
  277. flag = wx.EXPAND)
  278. # body
  279. boxSizer.Add(item = gridSizer, proportion = 1,
  280. flag = wx.ALL | wx.EXPAND, border = 2)
  281. pageSizer.Add(item = boxSizer, proportion = 0,
  282. flag = wx.EXPAND | wx.ALL,
  283. border = 3)
  284. box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  285. label = " %s " % (_("Image Appearance")))
  286. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  287. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  288. gridSizer.AddGrowableCol(0)
  289. # background color
  290. self.win['view']['background'] = {}
  291. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  292. label = _("Background color:")),
  293. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  294. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  295. colour = UserSettings.Get(group = 'nviz', key = 'view',
  296. subkey = ['background', 'color']),
  297. size = globalvar.DIALOG_COLOR_SIZE)
  298. self.win['view']['background']['color'] = color.GetId()
  299. color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
  300. gridSizer.Add(item = color, pos = (0, 1))
  301. boxSizer.Add(item = gridSizer, proportion = 1,
  302. flag = wx.ALL | wx.EXPAND, border = 3)
  303. pageSizer.Add(item = boxSizer, proportion = 0,
  304. flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
  305. border = 3)
  306. panel.SetSizer(pageSizer)
  307. return panel
  308. def _createDataPage(self):
  309. """!Create data (surface, vector, volume) settings page"""
  310. self.mainPanelData = ScrolledPanel(parent = self)
  311. self.mainPanelData.SetupScrolling(scroll_x = False)
  312. ## style = fpb.CaptionBarStyle()
  313. ## style.SetCaptionStyle(fpb.CAPTIONBAR_FILLED_RECTANGLE)
  314. ## style.SetFirstColour(wx.Color(250,250,250))
  315. self.foldpanelData = fpb.FoldPanelBar(parent = self.mainPanelData, id = wx.ID_ANY,
  316. style = fpb.FPB_DEFAULT_STYLE, extraStyle = fpb.FPB_SINGLE_FOLD)
  317. self.foldpanelData.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  318. # surface page
  319. self.surfacePanel = self.foldpanelData.AddFoldPanel(_("Surface"), collapsed = False)
  320. self.foldpanelData.AddFoldPanelWindow(self.surfacePanel,
  321. window = self._createSurfacePage(parent = self.surfacePanel), flags = fpb.FPB_ALIGN_WIDTH)
  322. self.EnablePage("surface", enabled = False)
  323. # constant page
  324. constantPanel = self.foldpanelData.AddFoldPanel(_("Constant surface"), collapsed = True)
  325. self.foldpanelData.AddFoldPanelWindow(constantPanel,
  326. window = self._createConstantPage(parent = constantPanel), flags = fpb.FPB_ALIGN_WIDTH)
  327. self.EnablePage("constant", enabled = False)
  328. # vector page
  329. vectorPanel = self.foldpanelData.AddFoldPanel(_("Vector"), collapsed = True)
  330. self.foldpanelData.AddFoldPanelWindow(vectorPanel,
  331. window = self._createVectorPage(parent = vectorPanel), flags = fpb.FPB_ALIGN_WIDTH)
  332. self.EnablePage("vector", enabled = False)
  333. # volume page
  334. volumePanel = self.foldpanelData.AddFoldPanel(_("Volume"), collapsed = True)
  335. self.foldpanelData.AddFoldPanelWindow(volumePanel,
  336. window = self._createVolumePage(parent = volumePanel), flags = fpb.FPB_ALIGN_WIDTH)
  337. self.EnablePage("volume", enabled = False)
  338. ## self.foldpanelData.ApplyCaptionStyleAll(style)
  339. sizer = wx.BoxSizer(wx.VERTICAL)
  340. sizer.Add(self.foldpanelData, proportion = 1, flag = wx.EXPAND)
  341. self.mainPanelData.SetSizer(sizer)
  342. self.mainPanelData.Layout()
  343. self.mainPanelData.Fit()
  344. return self.mainPanelData
  345. def _createAppearancePage(self):
  346. """!Create data (surface, vector, volume) settings page"""
  347. self.mainPanelAppear = ScrolledPanel(parent = self)
  348. self.mainPanelAppear.SetupScrolling(scroll_x = False)
  349. self.foldpanelAppear = fpb.FoldPanelBar(parent = self.mainPanelAppear, id = wx.ID_ANY,
  350. style = fpb.FPB_DEFAULT_STYLE, extraStyle = fpb.FPB_SINGLE_FOLD)
  351. self.foldpanelAppear.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  352. # light page
  353. lightPanel = self.foldpanelAppear.AddFoldPanel(_("Lighting"), collapsed = False)
  354. self.foldpanelAppear.AddFoldPanelWindow(lightPanel,
  355. window = self._createLightPage(parent = lightPanel), flags = fpb.FPB_ALIGN_WIDTH)
  356. # fringe page
  357. fringePanel = self.foldpanelAppear.AddFoldPanel(_("Fringe"), collapsed = True)
  358. self.foldpanelAppear.AddFoldPanelWindow(fringePanel,
  359. window = self._createFringePage(parent = fringePanel), flags = fpb.FPB_ALIGN_WIDTH)
  360. self.EnablePage('fringe', False)
  361. sizer = wx.BoxSizer(wx.VERTICAL)
  362. sizer.Add(self.foldpanelAppear, proportion = 1, flag = wx.EXPAND)
  363. self.mainPanelAppear.SetSizer(sizer)
  364. self.mainPanelAppear.Layout()
  365. self.mainPanelAppear.Fit()
  366. return self.mainPanelAppear
  367. def _createSurfacePage(self, parent):
  368. """!Create view settings page"""
  369. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  370. self.page['surface'] = { 'id' : 0,
  371. 'notebook' : self.foldpanelData.GetId() }
  372. pageSizer = wx.BoxSizer(wx.VERTICAL)
  373. self.win['surface'] = {}
  374. # selection
  375. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  376. label = " %s " % (_("Raster map")))
  377. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  378. rmaps = gselect.Select(parent = panel, type = 'raster',
  379. onPopup = self.GselectOnPopup)
  380. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster)
  381. self.win['surface']['map'] = rmaps.GetId()
  382. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  383. self.win['surface']['desc'] = desc.GetId()
  384. boxSizer.Add(item = rmaps, proportion = 0,
  385. flag = wx.ALL,
  386. border = 3)
  387. boxSizer.Add(item = desc, proportion = 0,
  388. flag = wx.ALL,
  389. border = 3)
  390. pageSizer.Add(item = boxSizer, proportion = 0,
  391. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  392. border = 3)
  393. #
  394. # draw
  395. #
  396. self.win['surface']['draw'] = {}
  397. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  398. label = " %s " % (_("Draw")))
  399. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  400. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  401. gridSizer.AddGrowableCol(3)
  402. # mode
  403. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  404. label = _("Mode:")),
  405. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  406. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  407. choices = [_("coarse"),
  408. _("fine"),
  409. _("both")])
  410. mode.SetName("selection")
  411. mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  412. self.win['surface']['draw']['mode'] = mode.GetId()
  413. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
  414. pos = (0, 1),span = (1, 2))
  415. # shading
  416. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  417. label = _("Shading:")),
  418. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  419. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  420. choices = [_("flat"),
  421. _("gouraud")])
  422. shade.SetName("selection")
  423. self.win['surface']['draw']['shading'] = shade.GetId()
  424. shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  425. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  426. pos = (0, 4))
  427. # set to all
  428. all = wx.Button(panel, id = wx.ID_ANY, label = _("Set to all"))
  429. all.SetToolTipString(_("Use draw settings for all loaded surfaces"))
  430. all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
  431. gridSizer.Add(item = all, flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  432. pos = (4, 4))
  433. # resolution coarse
  434. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  435. label = _("Coarse mode:")),
  436. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  437. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  438. label = _("resolution:")),
  439. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  440. resC = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  441. initial = 6,
  442. min = 1,
  443. max = 100)
  444. resC.SetName("value")
  445. self.win['surface']['draw']['res-coarse'] = resC.GetId()
  446. resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  447. gridSizer.Add(item = resC, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  448. # Coarse style
  449. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  450. label = _("style:")),
  451. pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  452. style = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  453. choices = [_("wire"),
  454. _("surface")])
  455. style.SetName("selection")
  456. self.win['surface']['draw']['style'] = style.GetId()
  457. style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  458. gridSizer.Add(item = style, flag = wx.ALIGN_CENTER_VERTICAL,
  459. pos = (3, 2))
  460. # color
  461. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  462. label = _("wire color:")),
  463. pos = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT)
  464. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  465. size = globalvar.DIALOG_COLOR_SIZE)
  466. color.SetName("colour")
  467. color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
  468. self.win['surface']['draw']['wire-color'] = color.GetId()
  469. gridSizer.Add(item = color, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  470. pos = (4, 2))
  471. # resolution fine
  472. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  473. label = _("Fine mode:")),
  474. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  475. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  476. label = _("resolution:")),
  477. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  478. resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  479. initial = 3,
  480. min = 1,
  481. max = 100)
  482. resF.SetName("value")
  483. self.win['surface']['draw']['res-fine'] = resF.GetId()
  484. resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  485. gridSizer.Add(item = resF, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  486. boxSizer.Add(item = gridSizer, proportion = 1,
  487. flag = wx.ALL | wx.EXPAND, border = 3)
  488. pageSizer.Add(item = boxSizer, proportion = 0,
  489. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  490. border = 3)
  491. #
  492. # surface attributes
  493. #
  494. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  495. label = " %s " % (_("Surface attributes")))
  496. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  497. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  498. gridSizer.AddGrowableCol(2)
  499. # type
  500. self.win['surface']['attr'] = {}
  501. row = 0
  502. for code, attrb in (('color', _("Color")),
  503. ('mask', _("Mask")),
  504. ('transp', _("Transparency")),
  505. ('shine', _("Shininess")),
  506. ('emit', _("Emission"))):
  507. self.win['surface'][code] = {}
  508. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  509. label = attrb + ':'),
  510. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  511. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  512. choices = [_("map")])
  513. if code not in ('color', 'shine'):
  514. use.Insert(item = _("unset"), pos = 0)
  515. self.win['surface'][code]['required'] = False
  516. else:
  517. self.win['surface'][code]['required'] = True
  518. if code != 'mask':
  519. use.Append(item = _('constant'))
  520. self.win['surface'][code]['use'] = use.GetId()
  521. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  522. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  523. pos = (row, 1))
  524. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  525. # size = globalvar.DIALOG_GSELECT_SIZE,
  526. size = (-1, -1),
  527. type = "raster")
  528. self.win['surface'][code]['map'] = map.GetId() - 1 # FIXME
  529. map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  530. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
  531. pos = (row, 2))
  532. if code == 'color':
  533. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  534. colour = (0,0,0),
  535. size = globalvar.DIALOG_COLOR_SIZE)
  536. value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
  537. elif code == 'mask':
  538. value = None
  539. else:
  540. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  541. initial = 0)
  542. if code in ('shine', 'transp', 'emit'):
  543. value.SetRange(minVal = 0, maxVal = 255)
  544. else:
  545. value.SetRange(minVal = 0, maxVal = 100)
  546. value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  547. if value:
  548. self.win['surface'][code]['const'] = value.GetId()
  549. value.Enable(False)
  550. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  551. pos = (row, 3))
  552. else:
  553. self.win['surface'][code]['const'] = None
  554. self.SetMapObjUseMap(nvizType = 'surface',
  555. attrb = code) # -> enable map / disable constant
  556. row += 1
  557. boxSizer.Add(item = gridSizer, proportion = 0,
  558. flag = wx.ALL | wx.EXPAND, border = 3)
  559. pageSizer.Add(item = boxSizer, proportion = 0,
  560. flag = wx.EXPAND | wx.ALL,
  561. border = 3)
  562. #
  563. # position
  564. #
  565. self.win['surface']['position'] = {}
  566. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  567. label = " %s " % (_("Position")))
  568. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  569. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  570. gridSizer.AddGrowableCol(3)
  571. # position
  572. self._createControl(panel, data = self.win['surface'], name = 'position',
  573. range = (-10000, 10000),
  574. bind = (self.OnSurfacePosition, self.OnSurfacePositionChanged, self.OnSurfacePosition))
  575. axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
  576. choices = ["X",
  577. "Y",
  578. "Z"])
  579. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  580. reset.SetToolTipString(_("Reset to default position"))
  581. reset.Bind(wx.EVT_BUTTON, self.OnResetSurfacePosition)
  582. self.win['surface']['position']['axis'] = axis.GetId()
  583. axis.SetSelection(0)
  584. axis.Bind(wx.EVT_CHOICE, self.OnSurfaceAxis)
  585. pslide = self.FindWindowById(self.win['surface']['position']['slider'])
  586. ptext = self.FindWindowById(self.win['surface']['position']['text'])
  587. ptext.SetValue('0')
  588. gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  589. gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
  590. gridSizer.Add(item = ptext, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
  591. gridSizer.Add(item = reset, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, pos = (0, 3))
  592. boxSizer.Add(item = gridSizer, proportion = 1,
  593. flag = wx.ALL | wx.EXPAND, border = 3)
  594. box.SetSizer(boxSizer)
  595. box.Layout()
  596. pageSizer.Add(item = boxSizer, proportion = 1,
  597. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  598. border = 3)
  599. #
  600. # mask
  601. #
  602. ## box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  603. ## label = " %s " % (_("Mask")))
  604. ## boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  605. ## gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  606. ##
  607. ## gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  608. ## label = _("Mask zeros:")),
  609. ## pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  610. ##
  611. ## elev = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  612. ## label = _("by elevation"))
  613. ## elev.Enable(False) # TODO: not implemented yet
  614. ## gridSizer.Add(item = elev, pos = (0, 1))
  615. ##
  616. ## color = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  617. ## label = _("by color"))
  618. ## color.Enable(False) # TODO: not implemented yet
  619. ## gridSizer.Add(item = color, pos = (0, 2))
  620. ##
  621. ## boxSizer.Add(item = gridSizer, proportion = 1,
  622. ## flag = wx.ALL | wx.EXPAND, border = 3)
  623. ## pageSizer.Add(item = boxSizer, proportion = 0,
  624. ## flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  625. ## border = 3)
  626. panel.SetSizer(pageSizer)
  627. panel.Layout()
  628. panel.Fit()
  629. return panel
  630. def _createConstantPage(self, parent):
  631. """!Create constant page"""
  632. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  633. self.page['constant'] = { 'id' : 1,
  634. 'notebook' : self.foldpanelData.GetId() }
  635. self.win['constant'] = {}
  636. pageSizer = wx.BoxSizer(wx.VERTICAL)
  637. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  638. label = " %s " % (_("Constant surface")))
  639. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  640. horsizer = wx.BoxSizer(wx.HORIZONTAL)
  641. surface = wx.ComboBox(parent = panel, id = wx.ID_ANY,
  642. style = wx.CB_SIMPLE | wx.CB_READONLY,
  643. choices = [])
  644. self.win['constant']['surface'] = surface.GetId()
  645. surface.Bind(wx.EVT_COMBOBOX, self.OnConstantSelection)
  646. horsizer.Add(surface, proportion = 1, flag = wx.EXPAND|wx.RIGHT, border = 20)
  647. addNew = wx.Button(panel, id = wx.ID_ANY, label = _("New"))
  648. addNew.Bind(wx.EVT_BUTTON, self.OnNewConstant)
  649. self.win['constant']['new'] = addNew.GetId()
  650. delete = wx.Button(panel, id = wx.ID_ANY, label = _("Delete"))
  651. delete.Bind(wx.EVT_BUTTON, self.OnDeleteConstant)
  652. self.win['constant']['delete'] = delete.GetId()
  653. horsizer.Add(item = addNew, proportion = 0, flag = wx.RIGHT|wx.LEFT, border = 3)
  654. horsizer.Add(item = delete, proportion = 0, flag = wx.RIGHT|wx.LEFT, border = 3)
  655. boxSizer.Add(item = horsizer, proportion = 0, flag = wx.ALL|wx.EXPAND,
  656. border = 5)
  657. # value
  658. horsizer = wx.BoxSizer(wx.HORIZONTAL)
  659. horsizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  660. label = _("Value:")),
  661. flag = wx.ALIGN_CENTER_VERTICAL|wx.RIGHT,
  662. border = 15)
  663. value = wx.SpinCtrl(panel, id = wx.ID_ANY,
  664. min = -1e9, max = 1e9,
  665. size = (65, -1))
  666. self.win['constant']['value'] = value.GetId()
  667. value.Bind(wx.EVT_SPINCTRL, self.OnConstantValue)
  668. horsizer.Add(item = value, flag = wx.RIGHT, border = 5)
  669. boxSizer.Add(item = horsizer, proportion = 0, flag = wx.ALL,
  670. border = 5)
  671. # color
  672. horsizer = wx.BoxSizer(wx.HORIZONTAL)
  673. horsizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  674. label = _("Color:")),
  675. flag = wx.ALIGN_CENTER_VERTICAL|wx.RIGHT,
  676. border = 15)
  677. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  678. colour = (0,0,0),
  679. size = globalvar.DIALOG_COLOR_SIZE)
  680. self.win['constant']['color'] = color.GetId()
  681. color.Bind(csel.EVT_COLOURSELECT, self.OnConstantColor)
  682. horsizer.Add(item = color, flag = wx.RIGHT, border = 5)
  683. boxSizer.Add(item = horsizer, proportion = 0, flag = wx.ALL,
  684. border = 5)
  685. pageSizer.Add(item = boxSizer, proportion = 0,
  686. flag = wx.EXPAND | wx.ALL,
  687. border = 3)
  688. panel.SetSizer(pageSizer)
  689. panel.Fit()
  690. return panel
  691. def _createVectorPage(self, parent):
  692. """!Create view settings page"""
  693. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  694. self.page['vector'] = { 'id' : 2,
  695. 'notebook' : self.foldpanelData.GetId() }
  696. pageSizer = wx.BoxSizer(wx.VERTICAL)
  697. self.win['vector'] = {}
  698. # selection
  699. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  700. label = " %s " % (_("Vector map")))
  701. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  702. vmaps = gselect.Select(parent = panel, type = 'vector',
  703. onPopup = self.GselectOnPopup)
  704. vmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetVector)
  705. self.win['vector']['map'] = vmaps.GetId()
  706. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  707. self.win['vector']['desc'] = desc.GetId()
  708. boxSizer.Add(item = vmaps, proportion = 0,
  709. flag = wx.ALL,
  710. border = 3)
  711. boxSizer.Add(item = desc, proportion = 0,
  712. flag = wx.ALL,
  713. border = 3)
  714. pageSizer.Add(item = boxSizer, proportion = 0,
  715. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  716. border = 3)
  717. #
  718. # vector lines
  719. #
  720. self.win['vector']['lines'] = {}
  721. showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  722. label = _("Show vector lines"))
  723. showLines.SetValue(True)
  724. self.win['vector']['lines']['show'] = showLines.GetId()
  725. showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  726. pageSizer.Add(item = showLines, proportion = 0,
  727. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  728. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  729. label = " %s " % (_("Vector lines")))
  730. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  731. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  732. gridSizer.AddGrowableCol(5)
  733. # width
  734. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  735. label = _("Line:")),
  736. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  737. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  738. label = _("width:")),
  739. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  740. wx.ALIGN_RIGHT)
  741. width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  742. initial = 1,
  743. min = 0,
  744. max = 100)
  745. width.SetValue(1)
  746. self.win['vector']['lines']['width'] = width.GetId()
  747. width.Bind(wx.EVT_SPINCTRL, self.OnVectorLines)
  748. gridSizer.Add(item = width, pos = (0, 2),
  749. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  750. # color
  751. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  752. label = _("color:")),
  753. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  754. wx.ALIGN_RIGHT)
  755. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  756. colour = (0,0,0),
  757. size = globalvar.DIALOG_COLOR_SIZE)
  758. self.win['vector']['lines']['color'] = color.GetId()
  759. color.Bind(csel.EVT_COLOURSELECT, self.OnVectorLines)
  760. gridSizer.Add(item = color, pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL |
  761. wx.ALIGN_LEFT)
  762. # display
  763. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  764. label = _("Display")),
  765. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL |
  766. wx.ALIGN_LEFT)
  767. display = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  768. choices = [_("on surface(s):"),
  769. _("flat")])
  770. self.win['vector']['lines']['flat'] = display.GetId()
  771. display.Bind(wx.EVT_CHOICE, self.OnVectorDisplay)
  772. gridSizer.Add(item = display, flag = wx.ALIGN_CENTER_VERTICAL |
  773. wx.ALIGN_LEFT|wx.EXPAND, pos = (1, 1), span = (1,4))
  774. # height
  775. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  776. label = _("Height above surface:")),
  777. pos = (2, 5), flag = wx.ALIGN_BOTTOM|wx.EXPAND)
  778. surface = wx.CheckListBox(parent = panel, id = wx.ID_ANY, size = (-1, 60),
  779. choices = [], style = wx.LB_NEEDED_SB)
  780. surface.Bind(wx.EVT_CHECKLISTBOX, self.OnVectorSurface)
  781. self.win['vector']['lines']['surface'] = surface.GetId()
  782. gridSizer.Add(item = surface,
  783. pos = (2, 0), span = (3, 5),
  784. flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
  785. self._createControl(panel, data = self.win['vector']['lines'], name = 'height', size = -1,
  786. range = (0, 500), sliderHor = True,
  787. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightText))
  788. self.FindWindowById(self.win['vector']['lines']['height']['slider']).SetValue(0)
  789. self.FindWindowById(self.win['vector']['lines']['height']['text']).SetValue(0)
  790. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['slider']),
  791. pos = (3, 5), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  792. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['text']),
  793. pos = (4, 5),
  794. flag = wx.ALIGN_CENTER)
  795. boxSizer.Add(item = gridSizer, proportion = 1,
  796. flag = wx.ALL | wx.EXPAND, border = 3)
  797. pageSizer.Add(item = boxSizer, proportion = 0,
  798. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  799. border = 3)
  800. #
  801. # vector points
  802. #
  803. self.win['vector']['points'] = {}
  804. showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  805. label = _("Show vector points"))
  806. showPoints.SetValue(True)
  807. self.win['vector']['points']['show'] = showPoints.GetId()
  808. showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  809. pageSizer.Add(item = showPoints, proportion = 0,
  810. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  811. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  812. label = " %s " % (_("Vector points")))
  813. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  814. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  815. gridSizer.AddGrowableCol(5)
  816. # icon size
  817. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  818. label = _("Icon:")),
  819. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  820. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  821. label = _("size:")),
  822. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  823. wx.ALIGN_RIGHT)
  824. isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  825. initial = 1,
  826. min = 1,
  827. max = 1e6)
  828. isize.SetName('value')
  829. isize.SetValue(100)
  830. self.win['vector']['points']['size'] = isize.GetId()
  831. isize.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  832. isize.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  833. gridSizer.Add(item = isize, pos = (0, 2),
  834. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  835. # icon color
  836. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  837. label = _("color:")),
  838. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  839. wx.ALIGN_RIGHT)
  840. icolor = csel.ColourSelect(panel, id = wx.ID_ANY,
  841. size = globalvar.DIALOG_COLOR_SIZE)
  842. icolor.SetName("color")
  843. icolor.SetColour((0,0,255))
  844. self.win['vector']['points']['color'] = icolor.GetId()
  845. icolor.Bind(csel.EVT_COLOURSELECT, self.OnVectorPoints)
  846. gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL |
  847. wx.ALIGN_LEFT,
  848. pos = (0, 4))
  849. # icon width
  850. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  851. label = _("width")),
  852. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  853. wx.ALIGN_RIGHT)
  854. iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  855. initial = 1,
  856. min = 1,
  857. max = 1e6)
  858. iwidth.SetName('value')
  859. iwidth.SetValue(100)
  860. self.win['vector']['points']['width'] = iwidth.GetId()
  861. iwidth.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  862. iwidth.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  863. gridSizer.Add(item = iwidth, pos = (1, 2),
  864. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  865. # icon symbol
  866. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  867. label = _("symbol:")),
  868. pos = (1, 3), flag = wx.ALIGN_CENTER_VERTICAL)
  869. isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  870. choices = UserSettings.Get(group = 'nviz', key = 'vector',
  871. subkey = ['points', 'marker'], internal = True))
  872. isym.SetName("selection")
  873. self.win['vector']['points']['marker'] = isym.GetId()
  874. isym.Bind(wx.EVT_CHOICE, self.OnVectorPoints)
  875. gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL,
  876. pos = (1, 4))
  877. # high
  878. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  879. label = _("Display on surface(s):")),
  880. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL,
  881. span = (1, 5))
  882. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  883. label = _("Height above surface:")),
  884. pos = (3, 5), flag = wx.ALIGN_CENTER_VERTICAL)
  885. surface = wx.CheckListBox(parent = panel, id = wx.ID_ANY, size = (-1, 60),
  886. choices = [], style = wx.LB_NEEDED_SB)
  887. surface.Bind(wx.EVT_CHECKLISTBOX, self.OnVectorSurface)
  888. self.win['vector']['points']['surface'] = surface.GetId()
  889. gridSizer.Add(item = surface,
  890. pos = (3, 0), span = (3, 5),
  891. flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
  892. self._createControl(panel, data = self.win['vector']['points'], name = 'height', size = -1,
  893. range = (0, 500),
  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 = (4, 5),flag = wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)
  899. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['text']),
  900. pos = (5, 5),
  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. try:# when calling event = None
  1593. event.Skip()
  1594. except AttributeError:
  1595. pass
  1596. def OnViewChangedText(self, event):
  1597. """!View changed, render in full resolution"""
  1598. self.mapWindow.render['quick'] = False
  1599. self.OnViewChange(event)
  1600. self.OnViewChanged(None)
  1601. self.Update()
  1602. event.Skip()
  1603. def OnResetView(self, event):
  1604. """!Reset to default view (view page)"""
  1605. self.mapWindow.ResetView()
  1606. self.UpdateSettings()
  1607. self.mapWindow.Refresh(False)
  1608. def OnResetSurfacePosition(self, event):
  1609. """!Reset position of surface"""
  1610. for win in self.win['surface']['position'].itervalues():
  1611. if win == self.win['surface']['position']['axis']:
  1612. self.FindWindowById(win).SetSelection(0)
  1613. else:
  1614. self.FindWindowById(win).SetValue(0)
  1615. data = self.GetLayerData('surface')
  1616. data['surface']['position']['x'] = 0
  1617. data['surface']['position']['y'] = 0
  1618. data['surface']['position']['z'] = 0
  1619. data['surface']['position']['update'] = None
  1620. # update properties
  1621. event = wxUpdateProperties(data = data)
  1622. wx.PostEvent(self.mapWindow, event)
  1623. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1624. self.mapWindow.Refresh(False)
  1625. def OnLookAt(self, event):
  1626. """!Look at (view page)"""
  1627. sel = event.GetSelection()
  1628. if sel == 0: # nothing
  1629. pass
  1630. elif sel == 1:
  1631. self.mapWindow.mouse['use'] = 'lookHere'
  1632. self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
  1633. elif sel == 2: # top
  1634. self.mapWindow.view['position']['x'] = 0.5
  1635. self.mapWindow.view['position']['y'] = 0.5
  1636. elif sel == 3: # north
  1637. self.mapWindow.view['position']['x'] = 0.5
  1638. self.mapWindow.view['position']['y'] = 0.0
  1639. elif sel == 4: # south
  1640. self.mapWindow.view['position']['x'] = 0.5
  1641. self.mapWindow.view['position']['y'] = 1.0
  1642. elif sel == 5: # east
  1643. self.mapWindow.view['position']['x'] = 1.0
  1644. self.mapWindow.view['position']['y'] = 0.5
  1645. elif sel == 6: # west
  1646. self.mapWindow.view['position']['x'] = 0.0
  1647. self.mapWindow.view['position']['y'] = 0.5
  1648. elif sel == 7: # north-west
  1649. self.mapWindow.view['position']['x'] = 0.0
  1650. self.mapWindow.view['position']['y'] = 0.0
  1651. elif sel == 8: # north-east
  1652. self.mapWindow.view['position']['x'] = 1.0
  1653. self.mapWindow.view['position']['y'] = 0.0
  1654. elif sel == 9: # south-east
  1655. self.mapWindow.view['position']['x'] = 1.0
  1656. self.mapWindow.view['position']['y'] = 1.0
  1657. elif sel == 10: # south-west
  1658. self.mapWindow.view['position']['x'] = 0.0
  1659. self.mapWindow.view['position']['y'] = 1.0
  1660. if sel >= 2:
  1661. self.PostViewEvent(zExag = True)
  1662. self.UpdateSettings()
  1663. self.mapWindow.render['quick'] = False
  1664. self.mapWindow.Refresh(False)
  1665. self.FindWindowById(event.GetId()).SetSelection(0)
  1666. def OnMapObjUse(self, event):
  1667. """!Set surface attribute -- use -- map/constant"""
  1668. if not self.mapWindow.init:
  1669. return
  1670. wx.Yield()
  1671. # find attribute row
  1672. attrb = self.__GetWindowName(self.win['surface'], event.GetId())
  1673. if not attrb:
  1674. attrb = self.__GetWindowName(self.win['volume'], event.GetId())
  1675. nvizType = 'volume'
  1676. else:
  1677. nvizType = 'surface'
  1678. selection = event.GetSelection()
  1679. if self.win[nvizType][attrb]['required']: # no 'unset'
  1680. selection += 1
  1681. if selection == 0: # unset
  1682. useMap = None
  1683. value = ''
  1684. elif selection == 1: # map
  1685. useMap = True
  1686. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1687. elif selection == 2: # constant
  1688. useMap = False
  1689. if attrb == 'color':
  1690. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1691. value = self._getColorString(value)
  1692. else:
  1693. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  1694. self.SetMapObjUseMap(nvizType = nvizType,
  1695. attrb = attrb, map = useMap)
  1696. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1697. if nvizType == 'surface':
  1698. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1699. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  1700. 'value' : str(value),
  1701. 'update' : None }
  1702. else: # volume / isosurface
  1703. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  1704. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1705. id = list.GetSelection()
  1706. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  1707. 'value' : str(value),
  1708. 'update' : None }
  1709. # update properties
  1710. event = wxUpdateProperties(data = data)
  1711. wx.PostEvent(self.mapWindow, event)
  1712. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1713. self.mapWindow.Refresh(False)
  1714. def EnablePage(self, name, enabled = True):
  1715. """!Enable/disable all widgets on page"""
  1716. for key, item in self.win[name].iteritems():
  1717. if key in ('map', 'surface', 'new'):
  1718. continue
  1719. if type(item) == types.DictType:
  1720. for sitem in self.win[name][key].itervalues():
  1721. if type(sitem) == types.IntType:
  1722. self.FindWindowById(sitem).Enable(enabled)
  1723. else:
  1724. if type(item) == types.IntType:
  1725. self.FindWindowById(item).Enable(enabled)
  1726. def SetMapObjUseMap(self, nvizType, attrb, map = None):
  1727. """!Update dialog widgets when attribute type changed"""
  1728. if attrb in ('topo', 'color', 'shine'):
  1729. incSel = -1 # decrement selection (no 'unset')
  1730. else:
  1731. incSel = 0
  1732. if map is True: # map
  1733. if attrb != 'topo': # changing map topography not allowed
  1734. # not sure why, but here must be disabled both ids, should be fixed!
  1735. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(True)
  1736. if self.win[nvizType][attrb]['const']:
  1737. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  1738. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(1 + incSel)
  1739. elif map is False: # const
  1740. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  1741. if self.win[nvizType][attrb]['const']:
  1742. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(True)
  1743. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(2 + incSel)
  1744. else: # unset
  1745. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  1746. if self.win[nvizType][attrb]['const']:
  1747. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  1748. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(0)
  1749. def OnSurfaceMap(self, event):
  1750. """!Set surface attribute"""
  1751. if self.vetoGSelectEvt:
  1752. self.vetoGSelectEvt = False
  1753. return
  1754. self.SetMapObjAttrb(nvizType = 'surface', winId = event.GetId())
  1755. def SetMapObjAttrb(self, nvizType, winId):
  1756. """!Set map object (surface/isosurface) attribute (map/constant)"""
  1757. if not self.mapWindow.init:
  1758. return
  1759. attrb = self.__GetWindowName(self.win[nvizType], winId)
  1760. if not attrb:
  1761. return
  1762. if nvizType == 'volume' and attrb == 'topo':
  1763. return
  1764. selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
  1765. if self.win[nvizType][attrb]['required']:
  1766. selection += 1
  1767. if selection == 0: # unset
  1768. useMap = None
  1769. value = ''
  1770. elif selection == 1: # map
  1771. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1772. useMap = True
  1773. else: # constant
  1774. if attrb == 'color':
  1775. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1776. # tuple to string
  1777. value = self._getColorString(value)
  1778. else:
  1779. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  1780. useMap = False
  1781. if not self.pageChanging:
  1782. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1783. if nvizType == 'surface':
  1784. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1785. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  1786. 'value' : str(value),
  1787. 'update' : None }
  1788. else:
  1789. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  1790. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1791. id = list.GetSelection()
  1792. if id > -1:
  1793. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  1794. 'value' : str(value),
  1795. 'update' : None }
  1796. # update properties
  1797. event = wxUpdateProperties(data = data)
  1798. wx.PostEvent(self.mapWindow, event)
  1799. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1800. self.mapWindow.Refresh(False)
  1801. def OnSurfaceResolution(self, event):
  1802. """!Draw resolution changed"""
  1803. self.SetSurfaceResolution()
  1804. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1805. self.mapWindow.Refresh(False)
  1806. def SetSurfaceResolution(self):
  1807. """!Set draw resolution"""
  1808. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  1809. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  1810. data = self.GetLayerData('surface')
  1811. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  1812. 'fine' : fine,
  1813. 'update' : None }
  1814. # update properties
  1815. event = wxUpdateProperties(data = data)
  1816. wx.PostEvent(self.mapWindow, event)
  1817. def SetSurfaceMode(self):
  1818. """!Set draw mode"""
  1819. mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
  1820. style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
  1821. if style == 0: # wire
  1822. self.FindWindowById(self.win['surface']['draw']['wire-color']).Enable(True)
  1823. ## self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(False)
  1824. elif style == 1: # surface
  1825. self.FindWindowById(self.win['surface']['draw']['wire-color']).Enable(False)
  1826. ## self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
  1827. ## else: # both
  1828. ## self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
  1829. ## self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
  1830. ##
  1831. ## style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
  1832. shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
  1833. value, desc = self.mapWindow.nvizDefault.GetDrawMode(mode, style, shade)
  1834. return value, desc
  1835. def OnSurfaceMode(self, event):
  1836. """!Set draw mode"""
  1837. value, desc = self.SetSurfaceMode()
  1838. data = self.GetLayerData('surface')
  1839. data['surface']['draw']['mode'] = { 'value' : value,
  1840. 'desc' : desc,
  1841. 'update' : None }
  1842. # update properties
  1843. event = wxUpdateProperties(data = data)
  1844. wx.PostEvent(self.mapWindow, event)
  1845. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1846. self.mapWindow.Refresh(False)
  1847. def OnSurfaceModeAll(self, event):
  1848. """!Set draw mode (including wire color) for all loaded surfaces"""
  1849. value, desc = self.SetSurfaceMode()
  1850. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  1851. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  1852. color = self.FindWindowById(self.win['surface']['draw']['wire-color']).GetColour()
  1853. cvalue = self._getColorString(color)
  1854. for name in self.mapWindow.GetLayerNames(type = 'raster'):
  1855. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1856. if not data:
  1857. continue # shouldy no happen
  1858. data['surface']['draw']['all'] = True
  1859. data['surface']['draw']['mode'] = { 'value' : value,
  1860. 'desc' : desc,
  1861. 'update' : None }
  1862. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  1863. 'fine' : fine,
  1864. 'update' : None }
  1865. data['surface']['draw']['wire-color'] = { 'value' : cvalue,
  1866. 'update' : None }
  1867. # update properties
  1868. event = wxUpdateProperties(data = data)
  1869. wx.PostEvent(self.mapWindow, event)
  1870. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1871. self.mapWindow.Refresh(False)
  1872. def _getColorString(self, color):
  1873. """!change color to R:G:B format"""
  1874. return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1875. def _getColorFromString(self, color, delim = ':'):
  1876. """!change color from R:G:B format to wx.Color"""
  1877. return wx.Color(*map(int, color.split(delim)))
  1878. def OnSurfaceWireColor(self, event):
  1879. """!Set wire color"""
  1880. data = self.GetLayerData('surface')
  1881. value = self._getColorString(event.GetValue())
  1882. data['surface']['draw']['wire-color'] = { 'value' : value,
  1883. 'update' : None }
  1884. # update properties
  1885. event = wxUpdateProperties(data = data)
  1886. wx.PostEvent(self.mapWindow, event)
  1887. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1888. self.mapWindow.Refresh(False)
  1889. def OnSurfaceAxis(self, event):
  1890. """!Surface position, axis changed"""
  1891. data = self.GetLayerData('surface')
  1892. id = data['surface']['object']['id']
  1893. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  1894. slider = self.FindWindowById(self.win['surface']['position']['slider'])
  1895. text = self.FindWindowById(self.win['surface']['position']['text'])
  1896. x, y, z = self._display.GetSurfacePosition(id)
  1897. if axis == 0: # x
  1898. slider.SetValue(x)
  1899. text.SetValue(x)
  1900. elif axis == 1: # y
  1901. slider.SetValue(y)
  1902. text.SetValue(y)
  1903. else: # z
  1904. slider.SetValue(z)
  1905. text.SetValue(z)
  1906. def OnSurfacePosition(self, event):
  1907. """!Surface position"""
  1908. winName = self.__GetWindowName(self.win['surface'], event.GetId())
  1909. if not winName:
  1910. return
  1911. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  1912. value = self.FindWindowById(event.GetId()).GetValue()
  1913. slider = self.FindWindowById(self.win['surface'][winName]['slider'])
  1914. self.AdjustSliderRange(slider = slider, value = value)
  1915. for win in self.win['surface']['position'].itervalues():
  1916. if win == self.win['surface']['position']['axis']:
  1917. continue
  1918. else:
  1919. self.FindWindowById(win).SetValue(value)
  1920. data = self.GetLayerData('surface')
  1921. id = data['surface']['object']['id']
  1922. x, y, z = self._display.GetSurfacePosition(id)
  1923. if axis == 0: # x
  1924. x = value
  1925. elif axis == 1: # y
  1926. y = value
  1927. else: # z
  1928. z = value
  1929. data['surface']['position']['x'] = x
  1930. data['surface']['position']['y'] = y
  1931. data['surface']['position']['z'] = z
  1932. data['surface']['position']['update'] = None
  1933. # update properties
  1934. event = wxUpdateProperties(data = data)
  1935. wx.PostEvent(self.mapWindow, event)
  1936. self.mapWindow.render['quick'] = True
  1937. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1938. self.mapWindow.Refresh(False)
  1939. # self.UpdatePage('surface')
  1940. def OnSurfacePositionChanged(self, event):
  1941. """!Surface position changed"""
  1942. self.mapWindow.render['quick'] = False
  1943. self.mapWindow.Refresh(False)
  1944. def UpdateVectorShow(self, vecType, enabled):
  1945. """!Enable/disable lines/points widgets
  1946. @param vecType vector type (lines, points)
  1947. """
  1948. if vecType != 'lines' and vecType != 'points':
  1949. return False
  1950. for win in self.win['vector'][vecType].keys():
  1951. if win == 'show':
  1952. continue
  1953. if type(self.win['vector'][vecType][win]) == type({}):
  1954. for swin in self.win['vector'][vecType][win].keys():
  1955. if enabled:
  1956. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
  1957. else:
  1958. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
  1959. else:
  1960. if enabled:
  1961. self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
  1962. else:
  1963. self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
  1964. return True
  1965. def OnVectorShow(self, event):
  1966. """!Show vector lines/points"""
  1967. winId = event.GetId()
  1968. if winId == self.win['vector']['lines']['show']:
  1969. vecType = 'lines'
  1970. points = False
  1971. else: # points
  1972. vecType = 'points'
  1973. points = True
  1974. checked = event.IsChecked()
  1975. name = self.FindWindowById(self.win['vector']['map']).GetValue()
  1976. item = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'item')
  1977. data = self.GetLayerData('vector')['vector']
  1978. if checked:
  1979. self.mapWindow.LoadVector(item, points = points)
  1980. else:
  1981. self.mapWindow.UnloadVector(item, points = points)
  1982. self.UpdateVectorShow(vecType, checked)
  1983. if checked:
  1984. try:
  1985. id = data[vecType]['object']['id']
  1986. except KeyError:
  1987. id = -1
  1988. if id > 0:
  1989. self.mapWindow.SetMapObjProperties(item, id, vecType)
  1990. # update properties
  1991. event = wxUpdateProperties(data = data)
  1992. wx.PostEvent(self.mapWindow, event)
  1993. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1994. self.mapWindow.Refresh(False)
  1995. event.Skip()
  1996. def OnVectorDisplay(self, event):
  1997. """!Display vector lines on surface/flat"""
  1998. rasters = self.mapWindow.GetLayerNames('raster')
  1999. if event.GetSelection() == 0: # surface
  2000. if len(rasters) < 1:
  2001. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  2002. self.FindWindowById(self.win['vector']['lines']['flat']).SetSelection(1)
  2003. return
  2004. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(True)
  2005. # set first found surface
  2006. data = self.GetLayerData('vector')
  2007. data['vector']['lines']['mode']['surface'] = rasters[0]
  2008. self.FindWindowById(self.win['vector']['lines']['surface']).SetStringSelection( \
  2009. rasters[0])
  2010. else: # flat
  2011. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  2012. self.OnVectorLines(event)
  2013. event.Skip()
  2014. def OnVectorLines(self, event):
  2015. """!Set vector lines mode, apply changes if auto-rendering is enabled"""
  2016. data = self.GetLayerData('vector')
  2017. width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
  2018. mode = {}
  2019. if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
  2020. mode['type'] = 'surface'
  2021. mode['surface'] = {}
  2022. checklist = self.FindWindowById(self.win['vector']['lines']['surface'])
  2023. value = list()
  2024. checked = list()
  2025. for surface in range(checklist.GetCount()):
  2026. value.append(checklist.GetString(surface))
  2027. checked.append(checklist.IsChecked(surface))
  2028. mode['surface']['value'] = value
  2029. mode['surface']['show'] = checked
  2030. mode['surface']['update'] = None
  2031. else:
  2032. mode['type'] = 'flat'
  2033. for attrb in ('width', 'mode'):
  2034. data['vector']['lines'][attrb]['update'] = None
  2035. data['vector']['lines']['width']['value'] = width
  2036. data['vector']['lines']['mode']['value'] = mode
  2037. color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
  2038. if isinstance(color, csel.ColourSelect):
  2039. pass #color picker not yet instantiated
  2040. else:
  2041. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2042. data['vector']['lines']['color']['update'] = None
  2043. data['vector']['lines']['color']['value'] = color
  2044. # update properties
  2045. event = wxUpdateProperties(data = data)
  2046. wx.PostEvent(self.mapWindow, event)
  2047. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2048. self.mapWindow.Refresh(False)
  2049. def OnVectorHeight(self, event):
  2050. id = event.GetId()
  2051. if id in self.win['vector']['lines']['height'].values():
  2052. vtype = 'lines'
  2053. else:
  2054. vtype = 'points'
  2055. value = self.FindWindowById(id).GetValue()
  2056. slider = self.FindWindowById(self.win['vector'][vtype]['height']['slider'])
  2057. self.AdjustSliderRange(slider = slider, value = value)
  2058. for win in self.win['vector'][vtype]['height'].itervalues():
  2059. self.FindWindowById(win).SetValue(value)
  2060. data = self.GetLayerData('vector')
  2061. data['vector'][vtype]['height'] = { 'value' : value,
  2062. 'update' : None }
  2063. # update properties
  2064. event = wxUpdateProperties(data = data)
  2065. wx.PostEvent(self.mapWindow, event)
  2066. self.mapWindow.render['quick'] = True
  2067. self.mapWindow.render['v' + vtype] = True
  2068. self.mapWindow.Refresh(False)
  2069. event.Skip()
  2070. def OnVectorHeightFull(self, event):
  2071. """!Vector height changed, render in full resolution"""
  2072. self.OnVectorHeight(event)
  2073. ## self.OnVectorSurface(event)
  2074. id = event.GetId()
  2075. if id in self.win['vector']['lines']['height'].values():
  2076. vtype = 'lines'
  2077. else:
  2078. vtype = 'points'
  2079. self.mapWindow.render['quick'] = False
  2080. self.mapWindow.render['v' + vtype] = False
  2081. self.mapWindow.Refresh(False)
  2082. def OnVectorHeightText(self, event):
  2083. """!Vector height changed, render in full resolution"""
  2084. # self.OnVectorHeight(event)
  2085. self.OnVectorHeightFull(event)
  2086. def OnVectorSurface(self, event):
  2087. """!Reference surface for vector map (lines/points)"""
  2088. id = event.GetId()
  2089. if id == self.win['vector']['lines']['surface']:
  2090. vtype = 'lines'
  2091. else:
  2092. vtype = 'points'
  2093. checkList = self.FindWindowById(self.win['vector'][vtype]['surface'])
  2094. checked = checkList.IsChecked(event.GetInt())
  2095. surface = checkList.GetString(event.GetInt())
  2096. data = self.GetLayerData('vector')
  2097. data['vector'][vtype]['mode']['surface'] = { 'value' : (surface,),
  2098. 'show' : (checked,),
  2099. 'update': None }
  2100. # update properties
  2101. event = wxUpdateProperties(data = data)
  2102. wx.PostEvent(self.mapWindow, event)
  2103. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2104. self.mapWindow.Refresh(False)
  2105. def OnVectorPoints(self, event):
  2106. """!Set vector points mode, apply changes if auto-rendering is enabled"""
  2107. data = self.GetLayerData('vector')
  2108. size = self.FindWindowById(self.win['vector']['points']['size']).GetValue()
  2109. marker = self.FindWindowById(self.win['vector']['points']['marker']).GetSelection()
  2110. # width = self.FindWindowById(self.win['vector']['points']['width']).GetValue()
  2111. for attrb in ('size', 'marker'):
  2112. data['vector']['points'][attrb]['update'] = None
  2113. data['vector']['points']['size']['value'] = size
  2114. # data['vector']['points']['width']['value'] = width
  2115. data['vector']['points']['marker']['value'] = marker
  2116. color = self.FindWindowById(self.win['vector']['points']['color']).GetColour()
  2117. if isinstance(color, csel.ColourSelect):
  2118. pass #color picker not yet instantiated
  2119. else:
  2120. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2121. data['vector']['points']['color']['update'] = None
  2122. data['vector']['points']['color']['value'] = color
  2123. # update properties
  2124. event = wxUpdateProperties(data = data)
  2125. wx.PostEvent(self.mapWindow, event)
  2126. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2127. self.mapWindow.Refresh(False)
  2128. def UpdateIsosurfButtons(self, list):
  2129. """!Enable/disable buttons 'add', 'delete',
  2130. 'move up', 'move down'"""
  2131. nitems = list.GetCount()
  2132. add = self.parent.FindWindowById(self.win['volume']['btnIsosurfAdd'])
  2133. delete = self.parent.FindWindowById(self.win['volume']['btnIsosurfDelete'])
  2134. moveDown = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
  2135. moveUp = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
  2136. if nitems >= wxnviz.MAX_ISOSURFS:
  2137. # disable add button on max
  2138. add.Enable(False)
  2139. else:
  2140. add.Enable(True)
  2141. if nitems < 1:
  2142. # disable 'delete' if only one item in the lis
  2143. delete.Enable(False)
  2144. else:
  2145. delete.Enable(True)
  2146. if list.GetSelection() >= nitems - 1:
  2147. # disable 'move-down' if last
  2148. moveDown.Enable(False)
  2149. else:
  2150. moveDown.Enable(True)
  2151. if list.GetSelection() < 1:
  2152. # disable 'move-up' if first
  2153. moveUp.Enable(False)
  2154. else:
  2155. moveUp.Enable(True)
  2156. def OnVolumeIsosurfMode(self, event):
  2157. """!Set isosurface draw mode"""
  2158. self.SetIsosurfaceMode(event.GetSelection())
  2159. def SetIsosurfaceMode(self, selection):
  2160. """!Set isosurface draw mode"""
  2161. data = self.GetLayerData('volume')['volume']
  2162. id = data['object']['id']
  2163. mode = 0
  2164. if selection == 0:
  2165. mode |= wxnviz.DM_FLAT
  2166. else:
  2167. mode |= wxnviz.DM_GOURAUD
  2168. self._display.SetIsosurfaceMode(id, mode)
  2169. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2170. self.mapWindow.Refresh(False)
  2171. def OnVolumeIsosurfResolution(self, event):
  2172. """!Set isosurface draw resolution"""
  2173. self.SetIsosurfaceResolution(event.GetInt())
  2174. def SetIsosurfaceResolution(self, res):
  2175. """!Set isosurface draw resolution"""
  2176. data = self.GetLayerData('volume')['volume']
  2177. id = data['object']['id']
  2178. self._display.SetIsosurfaceRes(id, res)
  2179. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2180. self.mapWindow.Refresh(False)
  2181. def OnVolumeIsosurfMap(self, event):
  2182. """!Set surface attribute"""
  2183. self.SetMapObjAttrb(nvizType = 'volume', winId = event.GetId())
  2184. def OnVolumeIsosurfCheck(self, event):
  2185. """!Isosurface checked (->load) or unchecked (->unload)"""
  2186. index = event.GetSelection()
  2187. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2188. data = self.GetLayerData('volume')['volume']
  2189. id = data['object']['id']
  2190. isosurfId = event.GetSelection()
  2191. if list.IsChecked(index):
  2192. self._display.SetIsosurfaceTransp(id, isosurfId, False, "0")
  2193. else:
  2194. # disable -> make transparent
  2195. self._display.SetIsosurfaceTransp(id, isosurfId, False, "255")
  2196. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2197. self.mapWindow.Refresh(False)
  2198. def OnVolumeIsosurfSelect(self, event):
  2199. """!Isosurface item selected"""
  2200. winUp = self.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
  2201. winDown = self.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
  2202. selection = event.GetSelection()
  2203. if selection == 0:
  2204. winUp.Enable(False)
  2205. if not winDown.IsEnabled():
  2206. winDown.Enable()
  2207. elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
  2208. winDown.Enable(False)
  2209. if not winUp.IsEnabled():
  2210. winUp.Enable()
  2211. else:
  2212. if not winDown.IsEnabled():
  2213. winDown.Enable()
  2214. if not winUp.IsEnabled():
  2215. winUp.Enable()
  2216. # update dialog
  2217. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2218. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2219. data = self.GetLayerData('volume')['volume']['isosurface'][selection]
  2220. self.UpdateVolumeIsosurfPage(layer, data)
  2221. def OnVolumeIsosurfAdd(self, event):
  2222. """!Add new isosurface to the list"""
  2223. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2224. level = self.FindWindowById(self.win['volume']['topo']['const']).GetValue()
  2225. sel = list.GetSelection()
  2226. if sel < 0 or sel >= list.GetCount() - 1:
  2227. item = list.Append(item = "%s %s" % (_("Level"), str(level)))
  2228. else:
  2229. list.Insert(item = "%s %s" % (_("Level"), str(level)),
  2230. pos = sel+1) # append
  2231. item = sel + 1
  2232. list.Check(item)
  2233. list.SetSelection(item)
  2234. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2235. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2236. data = self.GetLayerData('volume')['volume']
  2237. id = data['object']['id']
  2238. # collect properties
  2239. isosurfData = {}
  2240. for attrb in ('topo', 'color', 'mask',
  2241. 'transp', 'shine', 'emit'):
  2242. if attrb == 'topo':
  2243. isosurfData[attrb] = {}
  2244. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  2245. isosurfData[attrb]['value'] = win.GetValue()
  2246. else:
  2247. uwin = self.FindWindowById(self.win['volume'][attrb]['use'])
  2248. sel = uwin.GetSelection()
  2249. if self.win['volume'][attrb]['required']:
  2250. sel += 1
  2251. if sel == 0: # unset
  2252. continue
  2253. isosurfData[attrb] = {}
  2254. if sel == 1: # map
  2255. isosurfData[attrb]['map'] = True
  2256. vwin = self.FindWindowById(self.win['volume'][attrb]['map'])
  2257. value = vwin.GetValue()
  2258. else: # const
  2259. isosurfData[attrb]['map'] = False
  2260. vwin = self.FindWindowById(self.win['volume'][attrb]['const'])
  2261. if vwin.GetName() == "color":
  2262. value = self._getColorString(vwin.GetValue())
  2263. else:
  2264. value = vwin.GetValue()
  2265. isosurfData[attrb]['value'] = value
  2266. data['isosurface'].insert(item, isosurfData)
  2267. # add isosurface
  2268. self._display.AddIsosurface(id, level)
  2269. # use by default 3d raster map for color
  2270. self._display.SetIsosurfaceColor(id, item, True, str(layer.name))
  2271. # update buttons
  2272. self.UpdateIsosurfButtons(list)
  2273. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2274. self.mapWindow.Refresh(False)
  2275. event.Skip()
  2276. def OnVolumeIsosurfDelete(self, event):
  2277. """!Remove isosurface from list"""
  2278. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2279. # remove item from list
  2280. isosurfId = list.GetSelection()
  2281. list.Delete(isosurfId)
  2282. # select last item
  2283. if list.GetCount() > 0:
  2284. list.SetSelection(list.GetCount()-1)
  2285. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2286. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2287. data = self.GetLayerData('volume')['volume']
  2288. id = data['object']['id']
  2289. # delete isosurface
  2290. del data['isosurface'][isosurfId]
  2291. self._display.DeleteIsosurface(id, isosurfId)
  2292. # update buttons
  2293. self.UpdateIsosurfButtons(list)
  2294. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2295. self.mapWindow.Refresh(False)
  2296. event.Skip()
  2297. def OnVolumeIsosurfMoveUp(self, event):
  2298. """!Move isosurface up in the list"""
  2299. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2300. sel = list.GetSelection()
  2301. if sel < 1:
  2302. return # this should not happen
  2303. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2304. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2305. data = self.GetLayerData('volume')['volume']
  2306. id = data['object']['id']
  2307. # move item up
  2308. text = list.GetStringSelection()
  2309. list.Insert(item = text, pos = sel-1)
  2310. list.Check(sel-1)
  2311. list.SetSelection(sel-1)
  2312. list.Delete(sel+1)
  2313. data['isosurface'].insert(sel-1, data['isosurface'][sel])
  2314. del data['isosurface'][sel+1]
  2315. self._display.MoveIsosurface(id, sel, True)
  2316. # update buttons
  2317. self.UpdateIsosurfButtons(list)
  2318. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2319. self.mapWindow.Refresh(False)
  2320. event.Skip()
  2321. def OnVolumeIsosurfMoveDown(self, event):
  2322. """!Move isosurface dowm in the list"""
  2323. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2324. sel = list.GetSelection()
  2325. if sel >= list.GetCount() - 1:
  2326. return # this should not happen
  2327. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2328. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2329. data = self.GetLayerData('volume')['volume']
  2330. id = data['object']['id']
  2331. # move item up
  2332. text = list.GetStringSelection()
  2333. list.Insert(item = text, pos = sel+2)
  2334. list.Check(sel+2)
  2335. list.SetSelection(sel+2)
  2336. list.Delete(sel)
  2337. data['isosurface'].insert(sel+2, data['isosurface'][sel])
  2338. del data['isosurface'][sel]
  2339. self._display.MoveIsosurface(id, sel, False)
  2340. # update buttons
  2341. self.UpdateIsosurfButtons(list)
  2342. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2343. self.mapWindow.Refresh(False)
  2344. event.Skip()
  2345. def UpdatePage(self, pageId):
  2346. """!Update dialog (selected page)"""
  2347. self.pageChanging = True
  2348. Debug.msg(1, "NvizToolWindow.UpdatePage(): %s", pageId)
  2349. if pageId == 'view':
  2350. self.SetPage('view')
  2351. hmin = self.mapWindow.iview['height']['min']
  2352. hmax = self.mapWindow.iview['height']['max']
  2353. hval = self.mapWindow.iview['height']['value']
  2354. zmin = self.mapWindow.view['z-exag']['min']
  2355. zmax = self.mapWindow.view['z-exag']['max']
  2356. zval = self.mapWindow.view['z-exag']['value']
  2357. for control in ('slider','text'):
  2358. self.FindWindowById(self.win['view']['height'][control]).SetRange(
  2359. hmin,hmax)
  2360. self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(
  2361. zmin, zmax)
  2362. self.FindWindowById(self.win['view']['height'][control]).SetValue(hval)
  2363. self.FindWindowById(self.win['view']['z-exag'][control]).SetValue(zval)
  2364. self.FindWindowById(self.win['view']['background']['color']).SetColour(\
  2365. self.mapWindow.view['background']['color'])
  2366. elif pageId in ('surface', 'vector', 'volume'):
  2367. name = self.FindWindowById(self.win[pageId]['map']).GetValue()
  2368. data = self.GetLayerData(pageId)
  2369. if data:
  2370. if pageId == 'surface':
  2371. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  2372. self.UpdateSurfacePage(layer, data['surface'])
  2373. elif pageId == 'vector':
  2374. layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
  2375. self.UpdateVectorPage(layer, data['vector'])
  2376. elif pageId == 'volume':
  2377. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2378. self.UpdateVectorPage(layer, data['vector'])
  2379. elif pageId == 'light':
  2380. zval = self.mapWindow.light['position']['z']
  2381. bval = self.mapWindow.light['bright']
  2382. aval = self.mapWindow.light['ambient']
  2383. for control in ('slider','text'):
  2384. self.FindWindowById(self.win['light']['z'][control]).SetValue(zval)
  2385. self.FindWindowById(self.win['light']['bright'][control]).SetValue(bval)
  2386. self.FindWindowById(self.win['light']['ambient'][control]).SetValue(aval)
  2387. self.FindWindowById(self.win['light']['color']).SetColour(self.mapWindow.light['color'])
  2388. elif pageId == 'fringe':
  2389. win = self.FindWindowById(self.win['fringe']['map'])
  2390. win.SetValue(self.FindWindowById(self.win['surface']['map']).GetValue())
  2391. elif pageId == 'constant':
  2392. if self.mapWindow.constants:
  2393. surface = self.FindWindowById(self.win['constant']['surface'])
  2394. for item in self.mapWindow.constants:
  2395. surface.Append(item['name'])
  2396. surface.SetSelection(0)
  2397. self.OnConstantSelection(None)
  2398. self.EnablePage('constant', True)
  2399. self.Update()
  2400. self.pageChanging = False
  2401. def UpdateSurfacePage(self, layer, data, updateName = True):
  2402. """!Update surface page"""
  2403. ret = gcmd.RunCommand('r.info',
  2404. read = True,
  2405. flags = 'm',
  2406. map = layer.name)
  2407. if ret:
  2408. desc = ret.split('=')[1].rstrip('\n')
  2409. else:
  2410. desc = None
  2411. if updateName:
  2412. self.FindWindowById(self.win['surface']['map']).SetValue(layer.name)
  2413. self.FindWindowById(self.win['surface']['desc']).SetLabel(desc)
  2414. # attributes
  2415. if layer and layer.type == 'raster':
  2416. self.vetoGSelectEvt = True
  2417. self.FindWindowById(self.win['surface']['color']['map']).SetValue(layer.name)
  2418. else:
  2419. self.FindWindowById(self.win['surface']['color']['map']).SetValue('')
  2420. self.SetMapObjUseMap(nvizType = 'surface',
  2421. attrb = 'color', map = True) # -> map
  2422. if 'color' in data['attribute']:
  2423. value = data['attribute']['color']['value']
  2424. if data['attribute']['color']['map']:
  2425. self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
  2426. else: # constant
  2427. color = map(int, value.split(':'))
  2428. self.FindWindowById(self.win['surface']['color']['const']).SetColour(color)
  2429. self.SetMapObjUseMap(nvizType = 'surface',
  2430. attrb = attr, map = data['attribute']['color']['map'])
  2431. self.SetMapObjUseMap(nvizType = 'surface',
  2432. attrb = 'shine', map = data['attribute']['shine']['map'])
  2433. value = data['attribute']['shine']['value']
  2434. if data['attribute']['shine']['map']:
  2435. self.FindWindowById(self.win['surface']['shine']['map']).SetValue(value)
  2436. else:
  2437. self.FindWindowById(self.win['surface']['shine']['const']).SetValue(value)
  2438. #
  2439. # draw
  2440. #
  2441. for control, data in data['draw'].iteritems():
  2442. if control == 'all': # skip 'all' property
  2443. continue
  2444. if control == 'resolution':
  2445. self.FindWindowById(self.win['surface']['draw']['res-coarse']).SetValue(data['coarse'])
  2446. self.FindWindowById(self.win['surface']['draw']['res-fine']).SetValue(data['fine'])
  2447. continue
  2448. if control == 'mode':
  2449. if data['desc']['mode'] == 'coarse':
  2450. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(0)
  2451. elif data['desc']['mode'] == 'fine':
  2452. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(1)
  2453. else: # both
  2454. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(2)
  2455. if data['desc']['style'] == 'wire':
  2456. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(0)
  2457. else: # surface
  2458. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(1)
  2459. if data['desc']['shading'] == 'flat':
  2460. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(0)
  2461. else: # gouraud
  2462. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(1)
  2463. continue
  2464. value = data['value']
  2465. win = self.FindWindowById(self.win['surface']['draw'][control])
  2466. name = win.GetName()
  2467. if name == "selection":
  2468. win.SetSelection(value)
  2469. elif name == "colour":
  2470. color = map(int, value.split(':'))
  2471. win.SetColour(color)
  2472. else:
  2473. win.SetValue(value)
  2474. # enable/disable res widget + set draw mode
  2475. self.OnSurfaceMode(event = None)
  2476. def VectorInfo(self, layer):
  2477. """!Get number of points/lines
  2478. @param layer MapLayer instance
  2479. @return num of points/features (expect of points)
  2480. @return None
  2481. """
  2482. vInfo = grass.vector_info_topo(layer.GetName())
  2483. if not vInfo:
  2484. return None
  2485. nprimitives = 0
  2486. for key, value in vInfo.iteritems():
  2487. if key in ('points',
  2488. 'lines',
  2489. 'boundaries',
  2490. 'centroids',
  2491. 'faces',
  2492. 'kernels'):
  2493. nprimitives += value
  2494. return (vInfo['points'], vInfo['lines'], nprimitives, vInfo['map3d'])
  2495. def UpdateVectorPage(self, layer, data, updateName = True):
  2496. """!Update vector page"""
  2497. npoints, nlines, nfeatures, mapIs3D = self.VectorInfo(layer)
  2498. if mapIs3D:
  2499. desc = _("Vector map is 3D")
  2500. enable = False
  2501. else:
  2502. desc = _("Vector map is 2D")
  2503. enable = True
  2504. desc += " - " + _("%(features)d features (%(points)d points)") % \
  2505. { 'features' : nfeatures, 'points' : npoints }
  2506. if updateName:
  2507. self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
  2508. self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
  2509. self.FindWindowById(self.win['vector']['lines']['flat']).Enable(enable)
  2510. for v in ('lines', 'points'):
  2511. self.FindWindowById(self.win['vector'][v]['surface']).Enable(enable)
  2512. self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
  2513. self.FindWindowById(self.win['vector'][v]['height']['text']).Enable(enable)
  2514. #
  2515. # lines
  2516. #
  2517. showLines = self.FindWindowById(self.win['vector']['lines']['show'])
  2518. if 'object' in data['lines']:
  2519. showLines.SetValue(True)
  2520. else:
  2521. showLines.SetValue(False)
  2522. if nlines > 0:
  2523. showLines.Enable(True)
  2524. else:
  2525. showLines.Enable(False)
  2526. self.UpdateVectorShow('lines',
  2527. showLines.IsChecked())
  2528. width = self.FindWindowById(self.win['vector']['lines']['width'])
  2529. width.SetValue(data['lines']['width']['value'])
  2530. color = self.FindWindowById(self.win['vector']['lines']['color'])
  2531. color.SetValue(map(int, data['lines']['color']['value'].split(':')))
  2532. for vtype in ('lines', 'points'):
  2533. if vtype == 'lines':
  2534. display = self.FindWindowById(self.win['vector']['lines']['flat'])
  2535. if data[vtype]['mode']['type'] == 'flat':
  2536. display.SetSelection(1)
  2537. else:
  2538. display.SetSelection(0)
  2539. if data[vtype]['mode']['type'] == 'surface':
  2540. rasters = self.mapWindow.GetLayerNames('raster')
  2541. surface = self.FindWindowById(self.win['vector'][vtype]['surface'])
  2542. surface.SetItems(rasters)
  2543. if len(rasters) > 0:
  2544. for item in range(len(rasters)):
  2545. try:
  2546. surface.Check(item, data[vtype]['mode']['surface']['show'][item])
  2547. except (TypeError, IndexError, KeyError):
  2548. surface.Check(item, True)
  2549. for type in ('slider', 'text'):
  2550. win = self.FindWindowById(self.win['vector']['lines']['height'][type])
  2551. win.SetValue(data['lines']['height']['value'])
  2552. #
  2553. # points
  2554. #
  2555. showPoints = self.FindWindowById(self.win['vector']['points']['show'])
  2556. if 'object' in data['points']:
  2557. showPoints.SetValue(True)
  2558. else:
  2559. showPoints.SetValue(False)
  2560. if npoints > 0:
  2561. showPoints.Enable(True)
  2562. else:
  2563. showPoints.Enable(False)
  2564. self.UpdateVectorShow('points',
  2565. showPoints.IsChecked())
  2566. # size, width, marker, color
  2567. for prop in ('size', 'marker', 'color'):
  2568. win = self.FindWindowById(self.win['vector']['points'][prop])
  2569. name = win.GetName()
  2570. if name == 'selection':
  2571. win.SetSelection(data['points'][prop]['value'])
  2572. elif name == 'color':
  2573. color = map(int, data['points'][prop]['value'].split(':'))
  2574. win.SetValue(color)
  2575. else:
  2576. win.SetValue(data['points'][prop]['value'])
  2577. # height
  2578. for type in ('slider', 'text'):
  2579. win = self.FindWindowById(self.win['vector']['points']['height'][type])
  2580. win.SetValue(data['points']['height']['value'])
  2581. def UpdateVolumePage(self, layer, data, updateName = True):
  2582. """!Update volume page"""
  2583. if updateName:
  2584. self.FindWindowById(self.win['volume']['map']).SetValue(layer.name)
  2585. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2586. # draw
  2587. for control, idata in data['draw'].iteritems():
  2588. if control == 'all': # skip 'all' property
  2589. continue
  2590. win = self.FindWindowById(self.win['volume']['draw'][control])
  2591. if control == 'shading':
  2592. if data['draw']['shading']['desc'] == 'flat':
  2593. value = 0
  2594. else:
  2595. value = 1
  2596. else:
  2597. value = idata['value']
  2598. if win.GetName() == "selection":
  2599. win.SetSelection(value)
  2600. else:
  2601. win.SetValue(value)
  2602. self.SetIsosurfaceMode(data['draw']['shading']['value'])
  2603. self.SetIsosurfaceResolution(data['draw']['resolution']['value'])
  2604. self.UpdateVolumeIsosurfPage(layer, data['attribute'])
  2605. def UpdateVolumeIsosurfPage(self, layer, data):
  2606. """!Update dialog -- isosurface attributes"""
  2607. #
  2608. # isosurface attributes
  2609. #
  2610. for attrb in ('topo', 'color', 'mask',
  2611. 'transp', 'shine', 'emit'):
  2612. # check required first
  2613. if attrb == 'topo':
  2614. self.FindWindowById(self.win['volume'][attrb]['const']).SetValue(0)
  2615. continue
  2616. if attrb == 'color':
  2617. if layer and layer.type == '3d-raster':
  2618. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(layer.name)
  2619. else:
  2620. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue('')
  2621. self.SetMapObjUseMap(nvizType = 'volume',
  2622. attrb = attrb, map = True) # -> map
  2623. continue
  2624. # skip empty attributes
  2625. if attrb not in data:
  2626. continue
  2627. value = data[attrb]['value']
  2628. if attrb == 'color':
  2629. if data[attrb]['map']:
  2630. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(value)
  2631. else: # constant
  2632. color = map(int, value.split(':'))
  2633. self.FindWindowById(self.win['volume'][attrb]['const']).SetColour(color)
  2634. else:
  2635. if data[attrb]['map']:
  2636. win = self.FindWindowById(self.win['volume'][attrb]['map'])
  2637. else:
  2638. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  2639. win.SetValue(value)
  2640. self.SetMapObjUseMap(nvizType = 'volume',
  2641. attrb = attrb, map = data[attrb]['map'])
  2642. def SetPage(self, name):
  2643. """!Get named page"""
  2644. if name == 'view':
  2645. self.SetSelection(0)
  2646. elif name in ('surface', 'vector', 'volume'):
  2647. self.SetSelection(1)
  2648. else:
  2649. self.SetSelection(2)
  2650. win = self.FindWindowById(self.page[name]['notebook'])
  2651. try:
  2652. win.Expand(win.GetFoldPanel(self.page[name]['id']))
  2653. except AttributeError:
  2654. win.SetSelection(self.page[name]['id'])
  2655. class PositionWindow(wx.Window):
  2656. """!Abstract position control window, see subclasses
  2657. ViewPostionWindow and LightPositionWindow"""
  2658. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  2659. **kwargs):
  2660. self.mapWindow = mapwindow
  2661. self.quick = True
  2662. wx.Window.__init__(self, parent, id, **kwargs)
  2663. self.SetBackgroundColour("WHITE")
  2664. self.pdc = wx.PseudoDC()
  2665. self.pdc.SetBrush(wx.Brush(colour = 'dark green', style = wx.SOLID))
  2666. self.pdc.SetPen(wx.Pen(colour = 'dark green', width = 2, style = wx.SOLID))
  2667. self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
  2668. self.Bind(wx.EVT_PAINT, self.OnPaint)
  2669. # self.Bind(wx.EVT_MOTION, self.OnMouse)
  2670. self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
  2671. def Draw(self, pos, scale = False):
  2672. w, h = self.GetClientSize()
  2673. x, y = pos
  2674. if scale:
  2675. x = x * w
  2676. y = y * h
  2677. self.pdc.Clear()
  2678. self.pdc.BeginDrawing()
  2679. self.pdc.DrawLine(w / 2, h / 2, x, y)
  2680. self.pdc.DrawCircle(x, y, 5)
  2681. self.pdc.EndDrawing()
  2682. def OnPaint(self, event):
  2683. dc = wx.BufferedPaintDC(self)
  2684. dc.SetBackground(wx.Brush("White"))
  2685. dc.Clear()
  2686. self.PrepareDC(dc)
  2687. self.pdc.DrawToDC(dc)
  2688. def UpdatePos(self, xcoord, ycoord):
  2689. """!Update position coordinates (origin: UL)"""
  2690. if xcoord < 0.0:
  2691. xcoord = 0.0
  2692. elif xcoord > 1.0:
  2693. xcoord = 1.0
  2694. if ycoord < 0.0:
  2695. ycoord = 0.0
  2696. elif ycoord > 1.0:
  2697. ycoord = 1.0
  2698. x, y = self.TransformCoordinates(xcoord, ycoord)
  2699. self.data['position']['x'] = x
  2700. self.data['position']['y'] = y
  2701. return xcoord, ycoord
  2702. def OnMouse(self, event):
  2703. if event.LeftIsDown():
  2704. x, y = event.GetPosition()
  2705. self.Draw(pos = (x, y))
  2706. w, h = self.GetClientSize()
  2707. x = float(x) / w
  2708. y = float(y) / h
  2709. self.UpdatePos(x, y)
  2710. self.Refresh(False)
  2711. event.Skip()
  2712. def PostDraw(self):
  2713. x, y = self.UpdatePos(self.data['position']['x'],
  2714. self.data['position']['y'])
  2715. self.Draw(pos = (x,y), scale = True)
  2716. class ViewPositionWindow(PositionWindow):
  2717. """!View position control widget"""
  2718. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  2719. **kwargs):
  2720. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  2721. self.data = self.mapWindow.view
  2722. self.PostDraw()
  2723. def UpdatePos(self, xcoord, ycoord):
  2724. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  2725. event = wxUpdateView(zExag = True)
  2726. wx.PostEvent(self.mapWindow, event)
  2727. return x, y
  2728. def TransformCoordinates(self, x, y, toLight = True):
  2729. return x, y
  2730. def OnMouse(self, event):
  2731. PositionWindow.OnMouse(self, event)
  2732. if event.LeftIsDown():
  2733. self.mapWindow.render['quick'] = self.quick
  2734. self.mapWindow.Refresh(eraseBackground = False)
  2735. elif event.LeftUp():
  2736. self.mapWindow.render['quick'] = False
  2737. self.mapWindow.Refresh(eraseBackground = False)
  2738. event.Skip()
  2739. class LightPositionWindow(PositionWindow):
  2740. """!Light position control widget"""
  2741. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  2742. **kwargs):
  2743. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  2744. self.data = self.mapWindow.light
  2745. self.quick = False
  2746. self.PostDraw()
  2747. def UpdatePos(self, xcoord, ycoord):
  2748. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  2749. event = wxUpdateLight()
  2750. wx.PostEvent(self.mapWindow, event)
  2751. return x, y
  2752. def TransformCoordinates(self, x, y, toLight = True):
  2753. if toLight:
  2754. x = 2 * x - 1
  2755. y = -2 * y + 1
  2756. else:
  2757. x = (x + 1)/2
  2758. y = (1 - y)/2
  2759. return x, y
  2760. def PostDraw(self):
  2761. event = wxUpdateLight(refresh = True)
  2762. wx.PostEvent(self.mapWindow, event)
  2763. x, y = self.data['position']['x'], self.data['position']['y']
  2764. x, y = self.TransformCoordinates(x, y, toLight = False)
  2765. self.Draw(pos = (x,y), scale = True)
  2766. def OnMouse(self, event):
  2767. PositionWindow.OnMouse(self, event)
  2768. if event.LeftUp():
  2769. self.mapWindow.render['quick'] = False
  2770. self.mapWindow.Refresh(eraseBackground = False)