nviz_tools.py 156 KB

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