tools.py 228 KB

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