tools.py 231 KB

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