tools.py 229 KB

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