nviz_tools.py 173 KB

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