nviz_tools.py 163 KB

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