nviz_tools.py 210 KB

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