nviz_tools.py 164 KB

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