nviz_tools.py 157 KB

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