nviz_tools.py 173 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004
  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. self.precision = kwargs.pop('prec')
  83. wx.TextCtrl.__init__(self, parent = parent,
  84. validator = NTCValidator(flag = 'DIGIT_ONLY'), **kwargs)
  85. def SetValue(self, value):
  86. super(NumTextCtrl, self).SetValue(("%." + str(self.precision) + "f") % float(value))
  87. def GetValue(self):
  88. val = super(NumTextCtrl, self).GetValue()
  89. if val == '':
  90. val = '0'
  91. try:
  92. return float(val)
  93. except ValueError:
  94. val = ''.join(''.join(val.split('-')).split('.'))
  95. return float(val)
  96. def SetRange(self, min, max):
  97. pass
  98. class NvizToolWindow(FN.FlatNotebook):
  99. """!Nviz (3D view) tools panel
  100. """
  101. def __init__(self, parent, display, id = wx.ID_ANY,
  102. style = globalvar.FNPageStyle|FN.FNB_NO_X_BUTTON|FN.FNB_NO_NAV_BUTTONS,
  103. **kwargs):
  104. Debug.msg(5, "NvizToolWindow.__init__()")
  105. self.parent = parent # GMFrame
  106. self.mapDisplay = display
  107. self.mapWindow = display.GetWindow()
  108. self._display = self.mapWindow.GetDisplay()
  109. if globalvar.hasAgw:
  110. kwargs['agwStyle'] = style
  111. else:
  112. kwargs['style'] = style
  113. FN.FlatNotebook.__init__(self, parent, id, **kwargs)
  114. self.SetTabAreaColour(globalvar.FNPageColor)
  115. self.win = {} # window ids
  116. self.page = {} # page ids
  117. # view page
  118. self.AddPage(page = self._createViewPage(),
  119. text = " %s " % _("View"))
  120. # data page
  121. self.AddPage(page = self._createDataPage(),
  122. text = " %s " % _("Data"))
  123. # appearance page
  124. self.AddPage(page = self._createAppearancePage(),
  125. text = " %s " % _("Appearance"))
  126. # analysis page
  127. self.AddPage(page = self._createAnalysisPage(),
  128. text = " %s " % _("Analysis"))
  129. self.UpdateSettings()
  130. self.pageChanging = False
  131. self.vetoGSelectEvt = False #when setting map, event is invoked
  132. self.mapWindow.render['quick'] = False
  133. self.mapWindow.Refresh(False)
  134. # bindings
  135. self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
  136. self.Bind(wx.EVT_SIZE, self.OnSize)
  137. Debug.msg(3, "NvizToolWindow.__init__()")
  138. self.Update()
  139. wx.CallAfter(self.SetPage, 'view')
  140. wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear,
  141. self.foldpanelAnalysis))
  142. wx.CallAfter(self.SetInitialMaps)
  143. def SetInitialMaps(self):
  144. """!Set initial raster and vector map"""
  145. for l_type in ('raster', 'vector', '3d-raster'):
  146. selectedLayer = self.mapWindow.GetSelectedLayer()
  147. layers = self.mapWindow.Map.GetListOfLayers(l_type = l_type, l_active = True)
  148. if selectedLayer in layers:
  149. selection = selectedLayer.GetName()
  150. else:
  151. try:
  152. selection = layers[0].GetName()
  153. except:
  154. continue
  155. if l_type == 'raster':
  156. self.FindWindowById(self.win['surface']['map']).SetValue(selection)
  157. self.FindWindowById(self.win['fringe']['map']).SetValue(selection)
  158. elif l_type == 'vector':
  159. self.FindWindowById(self.win['vector']['map']).SetValue(selection)
  160. elif l_type == '3d-raster':
  161. self.FindWindowById(self.win['volume']['map']).SetValue(selection)
  162. def UpdateState(self, **kwargs):
  163. if 'view' in kwargs:
  164. self.mapWindow.view = kwargs['view']
  165. self.FindWindowById(self.win['view']['position']).data = kwargs['view']
  166. if 'iview' in kwargs:
  167. self.mapWindow.iview = kwargs['iview']
  168. if 'light' in kwargs:
  169. self.mapWindow.light = kwargs['light']
  170. self.FindWindowById(self.win['light']['position']).data = kwargs['light']
  171. def OnPageChanged(self, event):
  172. new = event.GetSelection()
  173. # self.ChangeSelection(new)
  174. def PostViewEvent(self, zExag = False):
  175. """!Change view settings"""
  176. event = wxUpdateView(zExag = zExag)
  177. wx.PostEvent(self.mapWindow, event)
  178. def OnSize(self, event):
  179. """!After window is resized, update scrolling"""
  180. # workaround to resize captionbars of foldpanelbar
  181. wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear,
  182. self.foldpanelAnalysis))
  183. event.Skip()
  184. def OnPressCaption(self, event):
  185. """!When foldpanel item collapsed/expanded, update scrollbars"""
  186. foldpanel = event.GetBar().GetGrandParent().GetParent()
  187. wx.CallAfter(self.UpdateScrolling, (foldpanel,))
  188. event.Skip()
  189. def UpdateScrolling(self, foldpanels):
  190. """!Update scrollbars in foldpanel"""
  191. for foldpanel in foldpanels:
  192. length = foldpanel.GetPanelsLength(collapsed = 0, expanded = 0)
  193. # virtual width is set to fixed value to suppress GTK warning
  194. foldpanel.GetParent().SetVirtualSize((100, length[2]))
  195. foldpanel.GetParent().Layout()
  196. def _createViewPage(self):
  197. """!Create view settings page"""
  198. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  199. panel.SetupScrolling(scroll_x = False)
  200. self.page['view'] = { 'id' : 0,
  201. 'notebook' : self.GetId()}
  202. pageSizer = wx.BoxSizer(wx.VERTICAL)
  203. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  204. label = " %s " % (_("Control View")))
  205. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  206. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 10)
  207. self.win['view'] = {}
  208. # position
  209. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  210. self._createCompass(panel = panel, sizer = posSizer, type = 'view')
  211. view = ViewPositionWindow(panel, size = (175, 175),
  212. mapwindow = self.mapWindow)
  213. self.win['view']['position'] = view.GetId()
  214. posSizer.Add(item = view,
  215. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  216. gridSizer.Add(item = posSizer, pos = (0, 0))
  217. # perspective
  218. # set initial defaults here (or perhaps in a default values file), not in user settings
  219. self._createControl(panel, data = self.win['view'], name = 'persp',
  220. range = (1,100),
  221. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  222. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Perspective:")),
  223. pos = (1, 0), flag = wx.ALIGN_CENTER)
  224. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['slider']), pos = (2, 0),
  225. flag = wx.ALIGN_CENTER)
  226. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['text']), pos = (3, 0),
  227. flag = wx.ALIGN_CENTER)
  228. # twist
  229. self._createControl(panel, data = self.win['view'], name = 'twist',
  230. range = (-180,180),
  231. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  232. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Twist:")),
  233. pos = (1, 1), flag = wx.ALIGN_CENTER)
  234. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['slider']), pos = (2, 1))
  235. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['text']), pos = (3, 1),
  236. flag = wx.ALIGN_CENTER)
  237. # height + z-exag
  238. self._createControl(panel, data = self.win['view'], name = 'height', sliderHor = False,
  239. range = (0, 1),
  240. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  241. self._createControl(panel, data = self.win['view'], name = 'z-exag', sliderHor = False,
  242. range = (0, 5), prec = 1,
  243. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  244. self.FindWindowById(self.win['view']['z-exag']['slider']).SetValue(1)
  245. self.FindWindowById(self.win['view']['z-exag']['text']).SetValue(1)
  246. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  247. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  248. pos = (0, 0), flag = wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, span = (1, 2))
  249. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['slider']),
  250. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  251. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['text']),
  252. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT, pos = (1, 1))
  253. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Z-exag:")),
  254. pos = (0, 2), flag = wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, span = (1, 2))
  255. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['slider']),
  256. flag = wx.ALIGN_RIGHT, pos = (1, 2))
  257. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['text']),
  258. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  259. wx.BOTTOM | wx.RIGHT, pos = (1, 3))
  260. gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_CENTER)
  261. # view setup + reset
  262. viewSizer = wx.BoxSizer(wx.HORIZONTAL)
  263. viewSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY,
  264. label = _("Look:")),
  265. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  266. border = 5)
  267. here = wx.ToggleButton(panel, id = wx.ID_ANY, label = _("here"))
  268. here.Bind(wx.EVT_TOGGLEBUTTON, self.OnLookAt)
  269. here.SetName('here')
  270. viewSizer.Add(item = here, flag = wx.TOP|wx.BOTTOM|wx.LEFT|wx.ALIGN_CENTER_VERTICAL,
  271. border = 5)
  272. center = wx.Button(panel, id = wx.ID_ANY, label = _("center"))
  273. center.Bind(wx.EVT_BUTTON, self.OnLookAt)
  274. center.SetName('center')
  275. viewSizer.Add(item = center, flag = wx.TOP|wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL,
  276. border = 5)
  277. top = wx.Button(panel, id = wx.ID_ANY, label = _("top"))
  278. top.Bind(wx.EVT_BUTTON, self.OnLookAt)
  279. top.SetName('top')
  280. viewSizer.Add(item = top, flag = wx.TOP|wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL,
  281. border = 5)
  282. reset = wx.Button(panel, id = wx.ID_ANY, label = _("reset"))
  283. reset.SetToolTipString(_("Reset to default view"))
  284. reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  285. viewSizer.Add(item = reset, proportion = 0,
  286. flag = wx.TOP|wx.BOTTOM|wx.RIGHT| wx.ALIGN_RIGHT,
  287. border = 5)
  288. gridSizer.AddGrowableCol(2)
  289. gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 3),
  290. flag = wx.EXPAND)
  291. # body
  292. boxSizer.Add(item = gridSizer, proportion = 1,
  293. flag = wx.ALL | wx.EXPAND, border = 2)
  294. pageSizer.Add(item = boxSizer, proportion = 0,
  295. flag = wx.EXPAND | wx.ALL,
  296. border = 3)
  297. box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  298. label = " %s " % (_("Image Appearance")))
  299. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  300. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  301. gridSizer.AddGrowableCol(0)
  302. # background color
  303. self.win['view']['background'] = {}
  304. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  305. label = _("Background color:")),
  306. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  307. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  308. colour = UserSettings.Get(group = 'nviz', key = 'view',
  309. subkey = ['background', 'color']),
  310. size = globalvar.DIALOG_COLOR_SIZE)
  311. self.win['view']['background']['color'] = color.GetId()
  312. color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
  313. gridSizer.Add(item = color, pos = (0, 1))
  314. boxSizer.Add(item = gridSizer, proportion = 1,
  315. flag = wx.ALL | wx.EXPAND, border = 3)
  316. pageSizer.Add(item = boxSizer, proportion = 0,
  317. flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
  318. border = 3)
  319. panel.SetSizer(pageSizer)
  320. return panel
  321. def _createDataPage(self):
  322. """!Create data (surface, vector, volume) settings page"""
  323. self.mainPanelData = ScrolledPanel(parent = self)
  324. self.mainPanelData.SetupScrolling(scroll_x = False)
  325. ## style = fpb.CaptionBarStyle()
  326. ## style.SetCaptionStyle(fpb.CAPTIONBAR_FILLED_RECTANGLE)
  327. ## style.SetFirstColour(wx.Color(250,250,250))
  328. self.foldpanelData = fpb.FoldPanelBar(parent = self.mainPanelData, id = wx.ID_ANY,
  329. style = fpb.FPB_SINGLE_FOLD)
  330. self.foldpanelData.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  331. # surface page
  332. self.surfacePanel = self.foldpanelData.AddFoldPanel(_("Surface"), collapsed = False)
  333. self.foldpanelData.AddFoldPanelWindow(self.surfacePanel,
  334. window = self._createSurfacePage(parent = self.surfacePanel), flags = fpb.FPB_ALIGN_WIDTH)
  335. self.EnablePage("surface", enabled = False)
  336. # constant page
  337. constantPanel = self.foldpanelData.AddFoldPanel(_("Constant surface"), collapsed = True)
  338. self.foldpanelData.AddFoldPanelWindow(constantPanel,
  339. window = self._createConstantPage(parent = constantPanel), flags = fpb.FPB_ALIGN_WIDTH)
  340. self.EnablePage("constant", enabled = False)
  341. # vector page
  342. vectorPanel = self.foldpanelData.AddFoldPanel(_("Vector"), collapsed = True)
  343. self.foldpanelData.AddFoldPanelWindow(vectorPanel,
  344. window = self._createVectorPage(parent = vectorPanel), flags = fpb.FPB_ALIGN_WIDTH)
  345. self.EnablePage("vector", enabled = False)
  346. # volume page
  347. volumePanel = self.foldpanelData.AddFoldPanel(_("Volume"), collapsed = True)
  348. self.foldpanelData.AddFoldPanelWindow(volumePanel,
  349. window = self._createVolumePage(parent = volumePanel), flags = fpb.FPB_ALIGN_WIDTH)
  350. self.EnablePage("volume", enabled = False)
  351. ## self.foldpanelData.ApplyCaptionStyleAll(style)
  352. sizer = wx.BoxSizer(wx.VERTICAL)
  353. sizer.Add(self.foldpanelData, proportion = 1, flag = wx.EXPAND)
  354. self.mainPanelData.SetSizer(sizer)
  355. self.mainPanelData.Layout()
  356. self.mainPanelData.Fit()
  357. return self.mainPanelData
  358. def _createAppearancePage(self):
  359. """!Create data (surface, vector, volume) settings page"""
  360. self.mainPanelAppear = ScrolledPanel(parent = self)
  361. self.mainPanelAppear.SetupScrolling(scroll_x = False)
  362. self.foldpanelAppear = fpb.FoldPanelBar(parent = self.mainPanelAppear, id = wx.ID_ANY,
  363. style = fpb.FPB_SINGLE_FOLD)
  364. self.foldpanelAppear.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  365. # light page
  366. lightPanel = self.foldpanelAppear.AddFoldPanel(_("Lighting"), collapsed = False)
  367. self.foldpanelAppear.AddFoldPanelWindow(lightPanel,
  368. window = self._createLightPage(parent = lightPanel), flags = fpb.FPB_ALIGN_WIDTH)
  369. # fringe page
  370. fringePanel = self.foldpanelAppear.AddFoldPanel(_("Fringe"), collapsed = True)
  371. self.foldpanelAppear.AddFoldPanelWindow(fringePanel,
  372. window = self._createFringePage(parent = fringePanel), flags = fpb.FPB_ALIGN_WIDTH)
  373. self.EnablePage('fringe', False)
  374. # decoration page
  375. decorationPanel = self.foldpanelAppear.AddFoldPanel(_("Decorations"), collapsed = True)
  376. self.foldpanelAppear.AddFoldPanelWindow(decorationPanel,
  377. window = self._createDecorationPage(parent = decorationPanel), flags = fpb.FPB_ALIGN_WIDTH)
  378. sizer = wx.BoxSizer(wx.VERTICAL)
  379. sizer.Add(self.foldpanelAppear, proportion = 1, flag = wx.EXPAND)
  380. self.mainPanelAppear.SetSizer(sizer)
  381. self.mainPanelAppear.Layout()
  382. self.mainPanelAppear.Fit()
  383. return self.mainPanelAppear
  384. def _createAnalysisPage(self):
  385. """!Create data analysis (cutting planes, ...) page"""
  386. self.mainPanelAnalysis = ScrolledPanel(parent = self)
  387. self.mainPanelAnalysis.SetupScrolling(scroll_x = False)
  388. self.foldpanelAnalysis = fpb.FoldPanelBar(parent = self.mainPanelAnalysis, id = wx.ID_ANY,
  389. style = fpb.FPB_SINGLE_FOLD)
  390. self.foldpanelAnalysis.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  391. # cutting planes page
  392. cplanePanel = self.foldpanelAnalysis.AddFoldPanel(_("Cutting planes"), collapsed = False)
  393. self.foldpanelAnalysis.AddFoldPanelWindow(cplanePanel,
  394. window = self._createCPlanePage(parent = cplanePanel), flags = fpb.FPB_ALIGN_WIDTH)
  395. sizer = wx.BoxSizer(wx.VERTICAL)
  396. sizer.Add(self.foldpanelAnalysis, proportion = 1, flag = wx.EXPAND)
  397. self.mainPanelAnalysis.SetSizer(sizer)
  398. self.mainPanelAnalysis.Layout()
  399. self.mainPanelAnalysis.Fit()
  400. return self.mainPanelAnalysis
  401. def _createSurfacePage(self, parent):
  402. """!Create view settings page"""
  403. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  404. self.page['surface'] = { 'id' : 0,
  405. 'notebook' : self.foldpanelData.GetId() }
  406. pageSizer = wx.BoxSizer(wx.VERTICAL)
  407. self.win['surface'] = {}
  408. # selection
  409. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  410. label = " %s " % (_("Raster map")))
  411. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  412. rmaps = gselect.Select(parent = panel, type = 'raster',
  413. onPopup = self.GselectOnPopup)
  414. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster)
  415. self.win['surface']['map'] = rmaps.GetId()
  416. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  417. self.win['surface']['desc'] = desc.GetId()
  418. boxSizer.Add(item = rmaps, proportion = 0,
  419. flag = wx.ALL,
  420. border = 3)
  421. boxSizer.Add(item = desc, proportion = 0,
  422. flag = wx.ALL,
  423. border = 3)
  424. pageSizer.Add(item = boxSizer, proportion = 0,
  425. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  426. border = 3)
  427. #
  428. # draw
  429. #
  430. self.win['surface']['draw'] = {}
  431. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  432. label = " %s " % (_("Draw")))
  433. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  434. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  435. gridSizer.AddGrowableCol(3)
  436. # mode
  437. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  438. label = _("Mode:")),
  439. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  440. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  441. choices = [_("coarse"),
  442. _("fine"),
  443. _("both")])
  444. mode.SetName("selection")
  445. mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  446. self.win['surface']['draw']['mode'] = mode.GetId()
  447. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
  448. pos = (0, 1),span = (1, 2))
  449. # shading
  450. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  451. label = _("Shading:")),
  452. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  453. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  454. choices = [_("flat"),
  455. _("gouraud")])
  456. shade.SetName("selection")
  457. self.win['surface']['draw']['shading'] = shade.GetId()
  458. shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  459. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  460. pos = (0, 4))
  461. # set to all
  462. all = wx.Button(panel, id = wx.ID_ANY, label = _("Set to all"))
  463. all.SetToolTipString(_("Use draw settings for all loaded surfaces"))
  464. all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
  465. gridSizer.Add(item = all, flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  466. pos = (3, 4))
  467. self.win['surface']['all'] = all.GetId()
  468. # resolution coarse
  469. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  470. label = _("Coarse mode:")),
  471. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  472. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  473. label = _("resolution:")),
  474. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  475. resC = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  476. initial = 6,
  477. min = 1,
  478. max = 100)
  479. resC.SetName("value")
  480. self.win['surface']['draw']['res-coarse'] = resC.GetId()
  481. resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  482. gridSizer.Add(item = resC, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  483. # Coarse style
  484. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  485. label = _("style:")),
  486. pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  487. style = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  488. choices = [_("wire"),
  489. _("surface")])
  490. style.SetName("selection")
  491. self.win['surface']['draw']['style'] = style.GetId()
  492. style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  493. gridSizer.Add(item = style, flag = wx.ALIGN_CENTER_VERTICAL,
  494. pos = (3, 2))
  495. # color
  496. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  497. size = globalvar.DIALOG_COLOR_SIZE)
  498. color.SetName("colour")
  499. color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
  500. color.SetToolTipString(_("Change wire color"))
  501. self.win['surface']['draw']['wire-color'] = color.GetId()
  502. gridSizer.Add(item = color, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  503. pos = (3, 3))
  504. # resolution fine
  505. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  506. label = _("Fine mode:")),
  507. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  508. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  509. label = _("resolution:")),
  510. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  511. resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  512. initial = 3,
  513. min = 1,
  514. max = 100)
  515. resF.SetName("value")
  516. self.win['surface']['draw']['res-fine'] = resF.GetId()
  517. resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  518. gridSizer.Add(item = resF, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  519. boxSizer.Add(item = gridSizer, proportion = 1,
  520. flag = wx.ALL | wx.EXPAND, border = 3)
  521. pageSizer.Add(item = boxSizer, proportion = 0,
  522. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  523. border = 3)
  524. #
  525. # surface attributes
  526. #
  527. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  528. label = " %s " % (_("Surface attributes")))
  529. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  530. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  531. gridSizer.AddGrowableCol(2)
  532. # type
  533. self.win['surface']['attr'] = {}
  534. row = 0
  535. for code, attrb in (('color', _("Color")),
  536. ('mask', _("Mask")),
  537. ('transp', _("Transparency")),
  538. ('shine', _("Shininess"))):
  539. self.win['surface'][code] = {}
  540. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  541. label = attrb + ':'),
  542. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  543. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  544. choices = [_("map")])
  545. if code not in ('color', 'shine'):
  546. use.Insert(item = _("unset"), pos = 0)
  547. self.win['surface'][code]['required'] = False
  548. else:
  549. self.win['surface'][code]['required'] = True
  550. if code != 'mask':
  551. use.Append(item = _('constant'))
  552. self.win['surface'][code]['use'] = use.GetId()
  553. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  554. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  555. pos = (row, 1))
  556. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  557. # size = globalvar.DIALOG_GSELECT_SIZE,
  558. size = (-1, -1),
  559. type = "raster")
  560. self.win['surface'][code]['map'] = map.GetId() - 1 # FIXME
  561. map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  562. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
  563. pos = (row, 2))
  564. if code == 'color':
  565. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  566. colour = (0,0,0),
  567. size = globalvar.DIALOG_COLOR_SIZE)
  568. value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
  569. elif code == 'mask':
  570. value = None
  571. else:
  572. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  573. initial = 0)
  574. value.SetRange(minVal = 0, maxVal = 100)
  575. value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  576. if value:
  577. self.win['surface'][code]['const'] = value.GetId()
  578. value.Enable(False)
  579. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  580. pos = (row, 3))
  581. else:
  582. self.win['surface'][code]['const'] = None
  583. self.SetMapObjUseMap(nvizType = 'surface',
  584. attrb = code) # -> enable map / disable constant
  585. row += 1
  586. boxSizer.Add(item = gridSizer, proportion = 0,
  587. flag = wx.ALL | wx.EXPAND, border = 3)
  588. pageSizer.Add(item = boxSizer, proportion = 0,
  589. flag = wx.EXPAND | wx.ALL,
  590. border = 3)
  591. #
  592. # position
  593. #
  594. self.win['surface']['position'] = {}
  595. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  596. label = " %s " % (_("Position")))
  597. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  598. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  599. gridSizer.AddGrowableCol(3)
  600. # position
  601. self._createControl(panel, data = self.win['surface'], name = 'position',
  602. range = (-10000, 10000),
  603. bind = (self.OnSurfacePosition, self.OnSurfacePositionChanged, self.OnSurfacePositionText))
  604. axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
  605. choices = ["X",
  606. "Y",
  607. "Z"])
  608. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  609. reset.SetToolTipString(_("Reset to default position"))
  610. reset.Bind(wx.EVT_BUTTON, self.OnResetSurfacePosition)
  611. self.win['surface']['position']['reset'] = reset.GetId()
  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 = (-1, -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. inout = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1205. label = _("toggle normal direction"))
  1206. gridSizer.Add(item = inout, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL)
  1207. inout.Bind(wx.EVT_CHECKBOX, self.OnInOutMode)
  1208. self.win['volume']['inout'] = inout.GetId()
  1209. row = 1
  1210. for code, attrb in (('topo', _("Topography level")),
  1211. ('color', _("Color")),
  1212. ('mask', _("Mask")),
  1213. ('transp', _("Transparency")),
  1214. ('shine', _("Shininess"))):
  1215. self.win['volume'][code] = {}
  1216. # label
  1217. colspan = 1
  1218. if code == 'topo':
  1219. colspan = 2
  1220. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1221. label = attrb + ':'),
  1222. pos = (row, 0), span = (1, colspan),flag = wx.ALIGN_CENTER_VERTICAL)
  1223. if code != 'topo':
  1224. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  1225. choices = [_("map")])
  1226. else:
  1227. use = None
  1228. # check for required properties
  1229. if code not in ('topo', 'color', 'shine'):
  1230. use.Insert(item = _("unset"), pos = 0)
  1231. self.win['volume'][code]['required'] = False
  1232. else:
  1233. self.win['volume'][code]['required'] = True
  1234. if use and code != 'mask':
  1235. use.Append(item = _('constant'))
  1236. if use:
  1237. self.win['volume'][code]['use'] = use.GetId()
  1238. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  1239. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  1240. pos = (row, 1))
  1241. if code != 'topo':
  1242. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  1243. # size = globalvar.DIALOG_GSELECT_SIZE,
  1244. size = (200, -1),
  1245. type = "grid3")
  1246. self.win['volume'][code]['map'] = map.GetId() - 1 # FIXME
  1247. map.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  1248. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
  1249. pos = (row, 2))
  1250. else:
  1251. map = None
  1252. if code == 'color':
  1253. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  1254. colour = (0,0,0),
  1255. size = globalvar.DIALOG_COLOR_SIZE)
  1256. value.Bind(csel.EVT_COLOURSELECT, self.OnVolumeIsosurfMap)
  1257. value.SetName('color')
  1258. elif code == 'mask':
  1259. value = None
  1260. elif code == 'topo':
  1261. prec = 2 # do settings?
  1262. value = NumTextCtrl(parent = panel, id = wx.ID_ANY, size = (200, -1),
  1263. style = wx.TE_PROCESS_ENTER, prec = prec)
  1264. value.Bind(wx.EVT_TEXT_ENTER, self.OnVolumeIsosurfMap)
  1265. value.Bind(wx.EVT_KILL_FOCUS, self.OnVolumeIsosurfMap)
  1266. else:
  1267. size = (65, -1)
  1268. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = size,
  1269. initial = 0)
  1270. if code == 'topo':
  1271. value.SetRange(minVal = -1e9, maxVal = 1e9)
  1272. elif code in ('shine', 'transp'):
  1273. value.SetRange(minVal = 0, maxVal = 100)
  1274. value.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfMap)
  1275. value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  1276. if value:
  1277. self.win['volume'][code]['const'] = value.GetId()
  1278. if code == 'topo':
  1279. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  1280. pos = (row, 2))
  1281. else:
  1282. value.Enable(False)
  1283. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  1284. pos = (row, 3))
  1285. else:
  1286. self.win['volume'][code]['const'] = None
  1287. if code != 'topo':
  1288. self.SetMapObjUseMap(nvizType = 'volume',
  1289. attrb = code) # -> enable map / disable constant
  1290. row += 1
  1291. boxSizer.Add(item = gridSizer, proportion = 1,
  1292. flag = wx.ALL | wx.EXPAND, border = 3)
  1293. pageSizer.Add(item = boxSizer, proportion = 0,
  1294. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1295. border = 3)
  1296. #
  1297. # position
  1298. #
  1299. self.win['volume']['position'] = {}
  1300. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1301. label = " %s " % (_("Position")))
  1302. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1303. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1304. gridSizer.AddGrowableCol(3)
  1305. # position
  1306. self._createControl(panel, data = self.win['volume'], name = 'position',
  1307. range = (-10000, 10000),
  1308. bind = (self.OnVolumePosition, self.OnVolumePositionChanged, self.OnVolumePositionText))
  1309. axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
  1310. choices = ["X",
  1311. "Y",
  1312. "Z"])
  1313. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  1314. reset.SetToolTipString(_("Reset to default position"))
  1315. reset.Bind(wx.EVT_BUTTON, self.OnResetVolumePosition)
  1316. self.win['volume']['position']['reset'] = reset.GetId()
  1317. self.win['volume']['position']['axis'] = axis.GetId()
  1318. axis.SetSelection(0)
  1319. axis.Bind(wx.EVT_CHOICE, self.OnVolumeAxis)
  1320. pslide = self.FindWindowById(self.win['volume']['position']['slider'])
  1321. ptext = self.FindWindowById(self.win['volume']['position']['text'])
  1322. ptext.SetValue('0')
  1323. gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  1324. gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
  1325. gridSizer.Add(item = ptext, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
  1326. gridSizer.Add(item = reset, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, pos = (0, 3))
  1327. boxSizer.Add(item = gridSizer, proportion = 1,
  1328. flag = wx.ALL | wx.EXPAND, border = 3)
  1329. pageSizer.Add(item = boxSizer, proportion = 1,
  1330. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1331. border = 3)
  1332. panel.SetSizer(pageSizer)
  1333. panel.Fit()
  1334. return panel
  1335. def _createLightPage(self, parent):
  1336. """!Create light page"""
  1337. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1338. self.page['light'] = { 'id' : 0,
  1339. 'notebook' : self.foldpanelAppear.GetId() }
  1340. self.win['light'] = {}
  1341. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1342. show = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1343. label = _("Show light model"))
  1344. show.Bind(wx.EVT_CHECKBOX, self.OnShowLightModel)
  1345. show.SetValue(True)
  1346. self._display.showLight = True
  1347. pageSizer.Add(item = show, proportion = 0,
  1348. flag = wx.ALL, border = 3)
  1349. ## surface = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1350. ## label = _("Follow source viewpoint"))
  1351. ## pageSizer.Add(item = surface, proportion = 0,
  1352. ## flag = wx.ALL, border = 3)
  1353. # position
  1354. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1355. label = " %s " % (_("Light source position")))
  1356. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1357. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1358. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1359. self._createCompass(panel = panel, sizer = posSizer, type = 'light')
  1360. pos = LightPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
  1361. mapwindow = self.mapWindow)
  1362. self.win['light']['position'] = pos.GetId()
  1363. posSizer.Add(item = pos,
  1364. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  1365. gridSizer.Add(item = posSizer, pos = (0, 0))
  1366. # height
  1367. self._createControl(panel, data = self.win['light'], name = 'z', sliderHor = False,
  1368. range = (0, 100),
  1369. bind = (self.OnLightChange, self.OnLightChanged, self.OnLightChange))
  1370. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1371. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  1372. pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
  1373. heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['slider']),
  1374. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  1375. heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['text']),
  1376. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  1377. wx.BOTTOM | wx.RIGHT, pos = (1, 1))
  1378. gridSizer.Add(item = heightSizer, pos = (0, 2), flag = wx.ALIGN_RIGHT)
  1379. boxSizer.Add(item = gridSizer, proportion = 1,
  1380. flag = wx.ALL | wx.EXPAND, border = 2)
  1381. pageSizer.Add(item = boxSizer, proportion = 0,
  1382. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1383. border = 3)
  1384. # position
  1385. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1386. label = " %s " % (_("Light color and intensity")))
  1387. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1388. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1389. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:")),
  1390. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1391. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  1392. colour = UserSettings.Get(group = 'nviz', key = 'light',
  1393. subkey = 'color'),
  1394. size = globalvar.DIALOG_COLOR_SIZE)
  1395. self.win['light']['color'] = color.GetId()
  1396. color.Bind(csel.EVT_COLOURSELECT, self.OnLightColor)
  1397. gridSizer.Add(item = color, pos = (0, 2))
  1398. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Brightness:")),
  1399. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1400. self._createControl(panel, data = self.win['light'], name = 'bright', size = 300,
  1401. range = (0, 100),
  1402. bind = (self.OnLightValue, self.OnLightChanged, self.OnLightValue))
  1403. gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['slider']),
  1404. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1405. gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['text']),
  1406. pos = (1, 2),
  1407. flag = wx.ALIGN_CENTER)
  1408. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Ambient:")),
  1409. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1410. self._createControl(panel, data = self.win['light'], name = 'ambient', size = 300,
  1411. range = (0, 100),
  1412. bind = (self.OnLightValue, self.OnLightChanged, self.OnLightValue))
  1413. gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['slider']),
  1414. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1415. gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['text']),
  1416. pos = (2, 2),
  1417. flag = wx.ALIGN_CENTER)
  1418. boxSizer.Add(item = gridSizer, proportion = 1,
  1419. flag = wx.ALL | wx.EXPAND, border = 2)
  1420. pageSizer.Add(item = boxSizer, proportion = 0,
  1421. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1422. border = 3)
  1423. # reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  1424. # reset.SetToolTipString(_("Reset to default view"))
  1425. # # self.win['reset'] = reset.GetId()
  1426. # reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  1427. # viewSizer.Add(item = reset, proportion = 1,
  1428. # flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT,
  1429. # border = 5)
  1430. # gridSizer.AddGrowableCol(3)
  1431. # gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
  1432. # flag = wx.EXPAND)
  1433. panel.SetSizer(pageSizer)
  1434. panel.Layout()
  1435. panel.Fit()
  1436. return panel
  1437. def _createFringePage(self, parent):
  1438. """!Create fringe page"""
  1439. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1440. self.page['fringe'] = { 'id' : 1,
  1441. 'notebook' : self.foldpanelAppear.GetId() }
  1442. self.win['fringe'] = {}
  1443. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1444. # selection
  1445. rbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1446. label = " %s " % (_("Surface")))
  1447. rboxSizer = wx.StaticBoxSizer(rbox, wx.VERTICAL)
  1448. rmaps = gselect.Select(parent = panel, type = 'raster',
  1449. onPopup = self.GselectOnPopup)
  1450. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetSurface)
  1451. self.win['fringe']['map'] = rmaps.GetId()
  1452. rboxSizer.Add(item = rmaps, proportion = 0,
  1453. flag = wx.ALL,
  1454. border = 3)
  1455. pageSizer.Add(item = rboxSizer, proportion = 0,
  1456. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1457. border = 3)
  1458. ebox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1459. label = " %s " % (_("Edges with fringe")))
  1460. eboxSizer = wx.StaticBoxSizer(ebox, wx.HORIZONTAL)
  1461. for edge in [(_("N && W"), "nw"),
  1462. (_("N && E"), "ne"),
  1463. (_("S && W"), "sw"),
  1464. (_("S && E"), "se")]:
  1465. chkbox = wx.CheckBox(parent = panel,
  1466. label = edge[0],
  1467. name = edge[1])
  1468. self.win['fringe'][edge[1]] = chkbox.GetId()
  1469. eboxSizer.Add(item = chkbox, proportion = 0,
  1470. flag = wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT, border = 5)
  1471. chkbox.Bind(wx.EVT_CHECKBOX, self.OnFringe)
  1472. pageSizer.Add(item = eboxSizer, proportion = 0,
  1473. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1474. border = 3)
  1475. sbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1476. label = " %s " % (_("Settings")))
  1477. sboxSizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
  1478. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  1479. # elevation
  1480. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1481. label = _("Elevation of fringe from bottom:")),
  1482. pos = (0, 0),
  1483. flag = wx.ALIGN_CENTER_VERTICAL)
  1484. spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
  1485. size = (65, -1), min = -1e6, max = 1e6)
  1486. spin.SetValue(UserSettings.Get(group = 'nviz', key = 'fringe', subkey = 'elev'))
  1487. spin.Bind(wx.EVT_SPINCTRL, self.OnFringe)
  1488. self.win['fringe']['elev'] = spin.GetId()
  1489. gridSizer.Add(item = spin, pos = (0, 1))
  1490. # color
  1491. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1492. label = _("Color:")),
  1493. pos = (1, 0),
  1494. flag = wx.ALIGN_CENTER_VERTICAL)
  1495. color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  1496. size = globalvar.DIALOG_COLOR_SIZE)
  1497. color.SetColour(UserSettings.Get(group = 'nviz', key = 'fringe',
  1498. subkey = 'color'))
  1499. color.Bind(csel.EVT_COLOURSELECT, self.OnFringe)
  1500. self.win['fringe']['color'] = color.GetId()
  1501. gridSizer.Add(item = color, pos = (1, 1))
  1502. sboxSizer.Add(item = gridSizer, proportion = 1,
  1503. flag = wx.ALL | wx.EXPAND, border = 3)
  1504. pageSizer.Add(item = sboxSizer, proportion = 0,
  1505. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1506. border = 3)
  1507. panel.SetSizer(pageSizer)
  1508. panel.Layout()
  1509. panel.Fit()
  1510. return panel
  1511. def _createDecorationPage(self, parent):
  1512. """!Create decoration (north arrow, scalebar, legend) page"""
  1513. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1514. self.page['decoration'] = { 'id' : 2,
  1515. 'notebook' : self.foldpanelAppear.GetId()}
  1516. self.win['decoration'] = {}
  1517. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1518. #
  1519. # north arrow
  1520. #
  1521. self.win['decoration']['arrow'] = {}
  1522. nabox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1523. label = " %s " % (_("North Arrow")))
  1524. naboxSizer = wx.StaticBoxSizer(nabox, wx.VERTICAL)
  1525. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  1526. # size
  1527. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1528. label = _("Arrow size (in map units):")),
  1529. pos = (0,0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  1530. sizeSpin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  1531. min = 0, max = 1e6, initial = 1000)
  1532. gridSizer.Add(sizeSpin, pos = (0, 2))
  1533. self.win['decoration']['arrow']['size'] = sizeSpin.GetId()
  1534. sizeSpin.Bind(wx.EVT_SPINCTRL, self.OnArrowProp)
  1535. # color
  1536. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1537. label = _("Arrow color:")),
  1538. pos = (1,0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  1539. color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  1540. size = globalvar.DIALOG_COLOR_SIZE)
  1541. gridSizer.Add(color, pos = (1, 2))
  1542. self.win['decoration']['arrow']['color'] = color.GetId()
  1543. color.Bind(csel.EVT_COLOURSELECT, self.OnArrowProp)
  1544. # control
  1545. toggle = wx.ToggleButton(parent = panel, id = wx.ID_ANY, label = _("Place arrow"))
  1546. gridSizer.Add(item = toggle, pos = (2, 0))
  1547. toggle.Bind(wx.EVT_TOGGLEBUTTON, self.OnArrowPlacement)
  1548. toggle.SetName('placeArrow')
  1549. delete = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Delete"))
  1550. gridSizer.Add(item = delete, pos = (2, 1))
  1551. delete.Bind(wx.EVT_BUTTON, self.OnArrowDelete)
  1552. naboxSizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND, border = 3)
  1553. pageSizer.Add(item = naboxSizer, proportion = 0,
  1554. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1555. border = 3)
  1556. panel.SetSizer(pageSizer)
  1557. panel.Layout()
  1558. panel.Fit()
  1559. return panel
  1560. def GetLayerData(self, nvizType):
  1561. """!Get nviz data"""
  1562. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1563. if nvizType == 'surface' or nvizType == 'fringe':
  1564. return self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1565. elif nvizType == 'vector':
  1566. return self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')
  1567. elif nvizType == 'volume':
  1568. return self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  1569. return None
  1570. def OnNewConstant(self, event):
  1571. """!Create new surface with constant value"""
  1572. #TODO settings
  1573. name = self.mapWindow.NewConstant()
  1574. win = self.FindWindowById(self.win['constant']['surface'])
  1575. name = _("constant#") + str(name)
  1576. win.Append(name)
  1577. win.SetStringSelection(name)
  1578. self.OnConstantSelection(None)
  1579. self.EnablePage(name = 'constant', enabled = True)
  1580. self.mapWindow.Refresh(eraseBackground = False)
  1581. # need to update list of surfaces in vector page
  1582. for vtype in ('points', 'lines'):
  1583. checklist = self.FindWindowById(self.win['vector'][vtype]['surface'])
  1584. checklist.Append(name)
  1585. win = self.FindWindowById(self.win['vector']['map'])
  1586. win.SetValue(win.GetValue())
  1587. def OnDeleteConstant(self, event):
  1588. """!Delete selected constant surface"""
  1589. layerIdx = self.FindWindowById(self.win['constant']['surface']).GetSelection()
  1590. if layerIdx == wx.NOT_FOUND:
  1591. return
  1592. name = self.FindWindowById(self.win['constant']['surface']).GetStringSelection()
  1593. self.mapWindow.DeleteConstant(layerIdx)
  1594. win = self.FindWindowById(self.win['constant']['surface'])
  1595. win.Delete(layerIdx)
  1596. if win.IsEmpty():
  1597. win.SetValue("")
  1598. self.EnablePage(name = 'constant', enabled = False)
  1599. else:
  1600. win.SetSelection(0)
  1601. self.OnConstantSelection(None)
  1602. # need to update list of surfaces in vector page
  1603. for vtype in ('points', 'lines'):
  1604. checklist = self.FindWindowById(self.win['vector'][vtype]['surface'])
  1605. checklist.Delete(checklist.FindString(name))
  1606. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1607. self.mapWindow.Refresh(False)
  1608. def OnConstantSelection(self, event):
  1609. """!Constant selected"""
  1610. layerIdx = self.FindWindowById(self.win['constant']['surface']).GetSelection()
  1611. if layerIdx == wx.NOT_FOUND:
  1612. return
  1613. name = _("constant#") + str(layerIdx + 1)
  1614. data = self.mapWindow.constants[layerIdx]
  1615. for attr, value in data['constant'].iteritems():
  1616. if attr == 'color':
  1617. value = self._getColorFromString(value)
  1618. if attr in ('color', 'value', 'resolution'):
  1619. self.FindWindowById(self.win['constant'][attr]).SetValue(value)
  1620. def OnSetConstantProp(self, event):
  1621. """!Change properties (color, value, resolution)
  1622. of currently selected constant surface"""
  1623. layerIdx = self.FindWindowById(self.win['constant']['surface']).GetSelection()
  1624. if layerIdx == wx.NOT_FOUND:
  1625. return
  1626. data = self.mapWindow.constants[layerIdx]
  1627. for attr in ('resolution', 'value'):
  1628. data['constant'][attr] = self.FindWindowById(self.win['constant'][attr]).GetValue()
  1629. data['constant']['color'] = self._getColorString(
  1630. self.FindWindowById(self.win['constant']['color']).GetValue())
  1631. # update properties
  1632. event = wxUpdateProperties(data = data)
  1633. wx.PostEvent(self.mapWindow, event)
  1634. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1635. self.mapWindow.Refresh(False)
  1636. def OnFringe(self, event):
  1637. """!Show/hide fringe"""
  1638. data = self.GetLayerData('fringe')['surface']
  1639. sid = data['object']['id']
  1640. elev = self.FindWindowById(self.win['fringe']['elev']).GetValue()
  1641. color = self.FindWindowById(self.win['fringe']['color']).GetValue()
  1642. self._display.SetFringe(sid, color, elev,
  1643. self.FindWindowById(self.win['fringe']['nw']).IsChecked(),
  1644. self.FindWindowById(self.win['fringe']['ne']).IsChecked(),
  1645. self.FindWindowById(self.win['fringe']['sw']).IsChecked(),
  1646. self.FindWindowById(self.win['fringe']['se']).IsChecked())
  1647. self.mapWindow.Refresh(False)
  1648. def OnScroll(self, event, win, data):
  1649. """!Generic scrolling handler"""
  1650. winName = self.__GetWindowName(win, event.GetId())
  1651. if not winName:
  1652. return
  1653. data[winName] = self.FindWindowById(event.GetId()).GetValue()
  1654. for w in win[winName].itervalues():
  1655. self.FindWindowById(w).SetValue(data[winName])
  1656. event.Skip()
  1657. def AdjustSliderRange(self, slider, value):
  1658. minim, maxim = slider.GetRange()
  1659. if not (minim <= value <= maxim):
  1660. slider.SetRange(min(minim, value), max(maxim, value))
  1661. def _createControl(self, parent, data, name, range, bind = (None, None, None),
  1662. sliderHor = True, size = 200, prec = 0):
  1663. """!Add control (Slider + TextCtrl)"""
  1664. data[name] = dict()
  1665. if sliderHor:
  1666. style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  1667. wx.SL_BOTTOM
  1668. sizeW = (size, -1)
  1669. else:
  1670. style = wx.SL_VERTICAL | wx.SL_AUTOTICKS | \
  1671. wx.SL_INVERSE
  1672. sizeW = (-1, size)
  1673. slider = wx.Slider(parent = parent, id = wx.ID_ANY,
  1674. minValue = range[0],
  1675. maxValue = range[1],
  1676. style = style,
  1677. size = sizeW)
  1678. slider.SetName('slider')
  1679. if bind[0]:
  1680. #EVT_SCROLL emits event after slider is released, EVT_SPIN not
  1681. slider.Bind(wx.EVT_SPIN, bind[0])
  1682. if bind[1]:
  1683. slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, bind[1])
  1684. data[name]['slider'] = slider.GetId()
  1685. text = NumTextCtrl(parent = parent, id = wx.ID_ANY, size = (65, -1),
  1686. style = wx.TE_PROCESS_ENTER, prec = prec)
  1687. text.SetName('text')
  1688. if bind[2]:
  1689. text.Bind(wx.EVT_TEXT_ENTER, bind[2])
  1690. text.Bind(wx.EVT_KILL_FOCUS, bind[2])
  1691. data[name]['text'] = text.GetId()
  1692. def _createCompass(self, panel, sizer, type):
  1693. """!Create 'compass' widget for light and view page"""
  1694. w = wx.Button(panel, id = wx.ID_ANY, label = _("W"))
  1695. n = wx.Button(panel, id = wx.ID_ANY, label = _("N"))
  1696. s = wx.Button(panel, id = wx.ID_ANY, label = _("S"))
  1697. e = wx.Button(panel, id = wx.ID_ANY, label = _("E"))
  1698. nw = wx.Button(panel, id = wx.ID_ANY, label = _("NW"))
  1699. ne = wx.Button(panel, id = wx.ID_ANY, label = _("NE"))
  1700. se = wx.Button(panel, id = wx.ID_ANY, label = _("SE"))
  1701. sw = wx.Button(panel, id = wx.ID_ANY, label = _("SW"))
  1702. minWidth = sw.GetTextExtent(sw.GetLabel())[0] + 15
  1703. for win, name in zip((w, n, s, e, nw, ne, se, sw),
  1704. ('w', 'n', 's', 'e', 'nw', 'ne', 'se', 'sw')):
  1705. win.SetMinSize((minWidth, -1))
  1706. win.Bind(wx.EVT_BUTTON, self.OnLookFrom)
  1707. win.SetName(type + '_' + name)
  1708. sizer.Add(item = nw, pos = (0, 0), flag = wx.ALIGN_CENTER)
  1709. sizer.Add(item = n, pos = (0, 1), flag = wx.ALIGN_CENTER)
  1710. sizer.Add(item = ne, pos = (0, 2), flag = wx.ALIGN_CENTER)
  1711. sizer.Add(item = e, pos = (1, 2), flag = wx.ALIGN_CENTER)
  1712. sizer.Add(item = se, pos = (2, 2), flag = wx.ALIGN_CENTER)
  1713. sizer.Add(item = s, pos = (2, 1), flag = wx.ALIGN_CENTER)
  1714. sizer.Add(item = sw, pos = (2, 0), flag = wx.ALIGN_CENTER)
  1715. sizer.Add(item = w, pos = (1, 0), flag = wx.ALIGN_CENTER)
  1716. def __GetWindowName(self, data, id):
  1717. for name in data.iterkeys():
  1718. if type(data[name]) is type({}):
  1719. for win in data[name].itervalues():
  1720. if win == id:
  1721. return name
  1722. else:
  1723. if data[name] == id:
  1724. return name
  1725. return None
  1726. def UpdateSettings(self):
  1727. """!Update view from settings values
  1728. stored in self.mapWindow.view dictionary"""
  1729. for control in ('height',
  1730. 'persp',
  1731. 'twist',
  1732. 'z-exag'):
  1733. for win in self.win['view'][control].itervalues():
  1734. try:
  1735. if control == 'height':
  1736. value = self.mapWindow.iview[control]['value']
  1737. else:
  1738. value = self.mapWindow.view[control]['value']
  1739. except KeyError:
  1740. value = -1
  1741. self.FindWindowById(win).SetValue(value)
  1742. viewWin = self.FindWindowById(self.win['view']['position'])
  1743. x, y = viewWin.UpdatePos(self.mapWindow.view['position']['x'],
  1744. self.mapWindow.view['position']['y'])
  1745. viewWin.Draw(pos = (x, y), scale = True)
  1746. viewWin.Refresh(False)
  1747. color = self._getColorString(self.mapWindow.view['background']['color'])
  1748. self._display.SetBgColor(str(color))
  1749. self.Update()
  1750. self.mapWindow.Refresh(eraseBackground = False)
  1751. self.mapWindow.render['quick'] = False
  1752. self.mapWindow.Refresh(True)
  1753. def OnShowLightModel(self, event):
  1754. """!Show light model"""
  1755. self._display.showLight = event.IsChecked()
  1756. self._display.DrawLightingModel()
  1757. def OnLightChange(self, event):
  1758. """!Position of the light changed"""
  1759. winName = self.__GetWindowName(self.win['light'], event.GetId())
  1760. if not winName:
  1761. return
  1762. value = self.FindWindowById(event.GetId()).GetValue()
  1763. self.mapWindow.light['position']['z'] = value
  1764. for win in self.win['light'][winName].itervalues():
  1765. self.FindWindowById(win).SetValue(value)
  1766. event = wxUpdateLight()
  1767. wx.PostEvent(self.mapWindow, event)
  1768. event.Skip()
  1769. def OnLightChanged(self, event):
  1770. """!Light"""
  1771. self.mapWindow.Refresh(False)
  1772. def OnLightColor(self, event):
  1773. """!Color of the light changed"""
  1774. self.mapWindow.light['color'] = tuple(event.GetValue())
  1775. event = wxUpdateLight(refresh = True)
  1776. wx.PostEvent(self.mapWindow, event)
  1777. event.Skip()
  1778. def OnLightValue(self, event):
  1779. """!Light brightness changed"""
  1780. data = self.mapWindow.light
  1781. self.OnScroll(event, self.win['light'], data)
  1782. event = wxUpdateLight()
  1783. wx.PostEvent(self.mapWindow, event)
  1784. event.Skip()
  1785. def OnBgColor(self, event):
  1786. """!Background color changed"""
  1787. color = event.GetValue()
  1788. self.mapWindow.view['background']['color'] = tuple(color)
  1789. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1790. self._display.SetBgColor(str(color))
  1791. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1792. self.mapWindow.Refresh(False)
  1793. def OnSetSurface(self, event):
  1794. """!Surface selected, currently used for fringes"""
  1795. name = event.GetString()
  1796. try:
  1797. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
  1798. except:
  1799. self.EnablePage('fringe', False)
  1800. return
  1801. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  1802. self.EnablePage('fringe', True)
  1803. def OnSetRaster(self, event):
  1804. """!Raster map selected, update surface page"""
  1805. name = event.GetString()
  1806. try:
  1807. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
  1808. except:
  1809. self.EnablePage('surface', False)
  1810. return
  1811. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  1812. self.EnablePage('surface', True)
  1813. self.UpdateSurfacePage(layer, data, updateName = False)
  1814. def OnSetVector(self, event):
  1815. """!Vector map selected, update properties page"""
  1816. name = event.GetString()
  1817. try:
  1818. data = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')['vector']
  1819. except:
  1820. self.EnablePage('vector', False)
  1821. return
  1822. layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
  1823. self.EnablePage('vector', True)
  1824. self.UpdateVectorPage(layer, data, updateName = False)
  1825. def OnSetRaster3D(self, event):
  1826. """!3D Raster map selected, update surface page"""
  1827. name = event.GetString()
  1828. try:
  1829. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')['volume']
  1830. except:
  1831. self.EnablePage('volume', False)
  1832. return
  1833. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  1834. self.EnablePage('volume', True)
  1835. self.UpdateVolumePage(layer, data, updateName = False)
  1836. def OnViewChange(self, event):
  1837. """!Change view, render in quick mode"""
  1838. # find control
  1839. winName = self.__GetWindowName(self.win['view'], event.GetId())
  1840. if not winName:
  1841. return
  1842. value = self.FindWindowById(event.GetId()).GetValue()
  1843. slider = self.FindWindowById(self.win['view'][winName]['slider'])
  1844. self.AdjustSliderRange(slider = slider, value = value)
  1845. if winName == 'height':
  1846. view = self.mapWindow.iview # internal
  1847. else:
  1848. view = self.mapWindow.view
  1849. if winName == 'z-exag' and value >= 0:
  1850. self.PostViewEvent(zExag = True)
  1851. else:
  1852. self.PostViewEvent(zExag = False)
  1853. if winName in ('persp', 'twist'):
  1854. convert = int
  1855. else:
  1856. convert = float
  1857. view[winName]['value'] = convert(value)
  1858. for win in self.win['view'][winName].itervalues():
  1859. self.FindWindowById(win).SetValue(value)
  1860. self.mapWindow.render['quick'] = True
  1861. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1862. self.mapWindow.Refresh(False)
  1863. event.Skip()
  1864. def OnViewChanged(self, event):
  1865. """!View changed, render in full resolution"""
  1866. self.mapWindow.render['quick'] = False
  1867. self.mapWindow.Refresh(False)
  1868. self.UpdateSettings()
  1869. try:# when calling event = None
  1870. event.Skip()
  1871. except AttributeError:
  1872. pass
  1873. def OnViewChangedText(self, event):
  1874. """!View changed, render in full resolution"""
  1875. self.mapWindow.render['quick'] = False
  1876. self.OnViewChange(event)
  1877. self.OnViewChanged(None)
  1878. self.Update()
  1879. event.Skip()
  1880. def OnLookAt(self, event):
  1881. """!Look here/center"""
  1882. name = self.FindWindowById(event.GetId()).GetName()
  1883. if name == 'center':
  1884. self._display.LookAtCenter()
  1885. focus = self.mapWindow.iview['focus']
  1886. focus['x'], focus['y'], focus['z'] = self._display.GetFocus()
  1887. self.mapWindow.Refresh(False)
  1888. elif name == 'top':
  1889. self.mapWindow.view['position']['x'] = 0.5
  1890. self.mapWindow.view['position']['y'] = 0.5
  1891. self.PostViewEvent(zExag = True)
  1892. self.UpdateSettings()
  1893. self.mapWindow.Refresh(False)
  1894. else: # here
  1895. if self.FindWindowById(event.GetId()).GetValue():
  1896. self.mapWindow.mouse['use'] = 'lookHere'
  1897. self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
  1898. else:
  1899. self.mapWindow.mouse['use'] = 'default'
  1900. self.mapWindow.SetCursor(self.mapWindow.cursors['default'])
  1901. def OnResetView(self, event):
  1902. """!Reset to default view (view page)"""
  1903. self.mapWindow.ResetView()
  1904. self.UpdateSettings()
  1905. self.mapWindow.Refresh(False)
  1906. def OnResetSurfacePosition(self, event):
  1907. """!Reset position of surface"""
  1908. for win in self.win['surface']['position'].itervalues():
  1909. if win == self.win['surface']['position']['axis']:
  1910. self.FindWindowById(win).SetSelection(0)
  1911. elif win == self.win['surface']['position']['reset']:
  1912. continue
  1913. else:
  1914. self.FindWindowById(win).SetValue(0)
  1915. data = self.GetLayerData('surface')
  1916. data['surface']['position']['x'] = 0
  1917. data['surface']['position']['y'] = 0
  1918. data['surface']['position']['z'] = 0
  1919. data['surface']['position']['update'] = None
  1920. # update properties
  1921. event = wxUpdateProperties(data = data)
  1922. wx.PostEvent(self.mapWindow, event)
  1923. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1924. self.mapWindow.Refresh(False)
  1925. def OnLookFrom(self, event):
  1926. """!Position of view/light changed by buttons"""
  1927. name = self.FindWindowById(event.GetId()).GetName()
  1928. buttonName = name.split('_')[1]
  1929. if name.split('_')[0] == 'view':
  1930. type = 'view'
  1931. data = self.mapWindow.view
  1932. else:
  1933. type = 'light'
  1934. data = self.mapWindow.light
  1935. if buttonName == 'n': # north
  1936. data['position']['x'] = 0.5
  1937. data['position']['y'] = 0.0
  1938. elif buttonName == 's': # south
  1939. data['position']['x'] = 0.5
  1940. data['position']['y'] = 1.0
  1941. elif buttonName == 'e': # east
  1942. data['position']['x'] = 1.0
  1943. data['position']['y'] = 0.5
  1944. elif buttonName =='w': # west
  1945. data['position']['x'] = 0.0
  1946. data['position']['y'] = 0.5
  1947. elif buttonName == 'nw': # north-west
  1948. data['position']['x'] = 0.0
  1949. data['position']['y'] = 0.0
  1950. elif buttonName == 'ne': # north-east
  1951. data['position']['x'] = 1.0
  1952. data['position']['y'] = 0.0
  1953. elif buttonName == 'se': # south-east
  1954. data['position']['x'] = 1.0
  1955. data['position']['y'] = 1.0
  1956. elif buttonName == 'sw': # south-west
  1957. data['position']['x'] = 0.0
  1958. data['position']['y'] = 1.0
  1959. if type == 'view':
  1960. self.PostViewEvent(zExag = True)
  1961. self.UpdateSettings()
  1962. else:
  1963. event = wxUpdateLight()
  1964. wx.PostEvent(self.mapWindow, event)
  1965. lightWin = self.FindWindowById(self.win['light']['position'])
  1966. x, y = lightWin.UpdatePos(self.mapWindow.light['position']['x'],
  1967. self.mapWindow.light['position']['y'])
  1968. lightWin.Draw(pos = (x, y), scale = True)
  1969. lightWin.Refresh(False)
  1970. self.mapWindow.render['quick'] = False
  1971. self.mapWindow.Refresh(False)
  1972. def OnMapObjUse(self, event):
  1973. """!Set surface attribute -- use -- map/constant"""
  1974. if not self.mapWindow.init:
  1975. return
  1976. wx.Yield()
  1977. # find attribute row
  1978. attrb = self.__GetWindowName(self.win['surface'], event.GetId())
  1979. if not attrb:
  1980. attrb = self.__GetWindowName(self.win['volume'], event.GetId())
  1981. nvizType = 'volume'
  1982. else:
  1983. nvizType = 'surface'
  1984. selection = event.GetSelection()
  1985. if self.win[nvizType][attrb]['required']: # no 'unset'
  1986. selection += 1
  1987. if selection == 0: # unset
  1988. useMap = None
  1989. value = ''
  1990. elif selection == 1: # map
  1991. useMap = True
  1992. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1993. elif selection == 2: # constant
  1994. useMap = False
  1995. if attrb == 'color':
  1996. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1997. value = self._getColorString(value)
  1998. else:
  1999. value = self._getPercent(self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue(), toPercent = False)
  2000. self.SetMapObjUseMap(nvizType = nvizType,
  2001. attrb = attrb, map = useMap)
  2002. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  2003. if nvizType == 'surface':
  2004. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  2005. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  2006. 'value' : str(value),
  2007. 'update' : None }
  2008. else: # volume / isosurface
  2009. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  2010. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2011. id = list.GetSelection()
  2012. if id != -1:
  2013. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  2014. 'value' : str(value),
  2015. 'update' : None }
  2016. # update properties
  2017. event = wxUpdateProperties(data = data)
  2018. wx.PostEvent(self.mapWindow, event)
  2019. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2020. self.mapWindow.Refresh(False)
  2021. def EnablePage(self, name, enabled = True):
  2022. """!Enable/disable all widgets on page"""
  2023. for key, item in self.win[name].iteritems():
  2024. if key in ('map', 'surface', 'new','planes'):
  2025. continue
  2026. if type(item) == types.DictType:
  2027. for skey, sitem in self.win[name][key].iteritems():
  2028. if type(sitem) == types.DictType:
  2029. for ssitem in self.win[name][key][skey].itervalues():
  2030. if type(ssitem) == types.IntType:
  2031. self.FindWindowById(ssitem).Enable(enabled)
  2032. else:
  2033. if type(sitem) == types.IntType:
  2034. self.FindWindowById(sitem).Enable(enabled)
  2035. else:
  2036. if type(item) == types.IntType:
  2037. self.FindWindowById(item).Enable(enabled)
  2038. def SetMapObjUseMap(self, nvizType, attrb, map = None):
  2039. """!Update dialog widgets when attribute type changed"""
  2040. if attrb in ('topo', 'color', 'shine'):
  2041. incSel = -1 # decrement selection (no 'unset')
  2042. else:
  2043. incSel = 0
  2044. if nvizType == 'volume' and attrb == 'topo':
  2045. return
  2046. if map is True: # map
  2047. if attrb != 'topo': # changing map topography not allowed
  2048. # not sure why, but here must be disabled both ids, should be fixed!
  2049. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(True)
  2050. if self.win[nvizType][attrb]['const']:
  2051. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  2052. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(1 + incSel)
  2053. elif map is False: # const
  2054. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  2055. if self.win[nvizType][attrb]['const']:
  2056. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(True)
  2057. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(2 + incSel)
  2058. else: # unset
  2059. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(0)
  2060. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  2061. if self.win[nvizType][attrb]['const']:
  2062. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  2063. def OnSurfaceMap(self, event):
  2064. """!Set surface attribute"""
  2065. if self.vetoGSelectEvt:
  2066. self.vetoGSelectEvt = False
  2067. return
  2068. self.SetMapObjAttrb(nvizType = 'surface', winId = event.GetId())
  2069. def SetMapObjAttrb(self, nvizType, winId):
  2070. """!Set map object (surface/isosurface) attribute (map/constant)"""
  2071. if not self.mapWindow.init:
  2072. return
  2073. attrb = self.__GetWindowName(self.win[nvizType], winId)
  2074. if not attrb:
  2075. return
  2076. if not (nvizType == 'volume' and attrb == 'topo'):
  2077. selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
  2078. if self.win[nvizType][attrb]['required']:
  2079. selection += 1
  2080. if selection == 0: # unset
  2081. useMap = None
  2082. value = ''
  2083. elif selection == 1: # map
  2084. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  2085. useMap = True
  2086. else: # constant
  2087. if attrb == 'color':
  2088. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  2089. # tuple to string
  2090. value = self._getColorString(value)
  2091. else:
  2092. value = self._getPercent(
  2093. self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue(), toPercent = False)
  2094. useMap = False
  2095. else:
  2096. useMap = None
  2097. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  2098. if not self.pageChanging:
  2099. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  2100. if nvizType == 'surface':
  2101. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  2102. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  2103. 'value' : str(value),
  2104. 'update' : None }
  2105. else:
  2106. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  2107. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2108. id = list.GetSelection()
  2109. if id > -1:
  2110. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  2111. 'value' : str(value),
  2112. 'update' : None }
  2113. if attrb == 'topo':
  2114. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2115. sel = list.GetSelection()
  2116. list.SetString(sel, "%s %.1f" % (_("Level"), value))
  2117. list.Check(sel)
  2118. # update properties
  2119. event = wxUpdateProperties(data = data)
  2120. wx.PostEvent(self.mapWindow, event)
  2121. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2122. self.mapWindow.Refresh(False)
  2123. def OnSurfaceResolution(self, event):
  2124. """!Draw resolution changed"""
  2125. self.SetSurfaceResolution()
  2126. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2127. self.mapWindow.Refresh(False)
  2128. def SetSurfaceResolution(self):
  2129. """!Set draw resolution"""
  2130. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  2131. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  2132. data = self.GetLayerData('surface')
  2133. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  2134. 'fine' : fine,
  2135. 'update' : None }
  2136. # update properties
  2137. event = wxUpdateProperties(data = data)
  2138. wx.PostEvent(self.mapWindow, event)
  2139. def SetSurfaceMode(self):
  2140. """!Set draw mode"""
  2141. mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
  2142. style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
  2143. if style == 0: # wire
  2144. self.FindWindowById(self.win['surface']['draw']['wire-color']).Enable(True)
  2145. elif style == 1: # surface
  2146. self.FindWindowById(self.win['surface']['draw']['wire-color']).Enable(False)
  2147. shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
  2148. value, desc = self.mapWindow.nvizDefault.GetDrawMode(mode, style, shade)
  2149. return value, desc
  2150. def OnSurfaceMode(self, event):
  2151. """!Set draw mode"""
  2152. value, desc = self.SetSurfaceMode()
  2153. data = self.GetLayerData('surface')
  2154. data['surface']['draw']['mode'] = { 'value' : value,
  2155. 'desc' : desc,
  2156. 'update' : None }
  2157. # update properties
  2158. event = wxUpdateProperties(data = data)
  2159. wx.PostEvent(self.mapWindow, event)
  2160. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2161. self.mapWindow.Refresh(False)
  2162. def OnSurfaceModeAll(self, event):
  2163. """!Set draw mode (including wire color) for all loaded surfaces"""
  2164. value, desc = self.SetSurfaceMode()
  2165. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  2166. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  2167. color = self.FindWindowById(self.win['surface']['draw']['wire-color']).GetColour()
  2168. cvalue = self._getColorString(color)
  2169. for name in self.mapWindow.GetLayerNames(type = 'raster'):
  2170. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  2171. if not data:
  2172. continue # shouldy no happen
  2173. data['surface']['draw']['all'] = True
  2174. data['surface']['draw']['mode'] = { 'value' : value,
  2175. 'desc' : desc,
  2176. 'update' : None }
  2177. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  2178. 'fine' : fine,
  2179. 'update' : None }
  2180. data['surface']['draw']['wire-color'] = { 'value' : cvalue,
  2181. 'update' : None }
  2182. # update properties
  2183. event = wxUpdateProperties(data = data)
  2184. wx.PostEvent(self.mapWindow, event)
  2185. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2186. self.mapWindow.Refresh(False)
  2187. def _getColorString(self, color):
  2188. """!change color to R:G:B format"""
  2189. return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2190. def _getColorFromString(self, color, delim = ':'):
  2191. """!change color from R:G:B format to wx.Color"""
  2192. return wx.Color(*map(int, color.split(delim)))
  2193. def _get3dRange(self, name):
  2194. """!helper func for getting range of 3d map"""
  2195. ret = gcmd.RunCommand('r3.info', read = True, flags = 'r', map = name)
  2196. if ret:
  2197. range = []
  2198. for value in ret.strip('\n').split('\n'):
  2199. range.append(float(value.split('=')[1]))
  2200. return range
  2201. return -1e6, 1e6
  2202. def _getPercent(self, value, toPercent = True):
  2203. """!Convert values 0 - 255 to percents and vice versa"""
  2204. value = int(value)
  2205. if toPercent:
  2206. value = int(value/255. * 100)
  2207. else:
  2208. value = int(value/100. * 255)
  2209. return value
  2210. def OnSurfaceWireColor(self, event):
  2211. """!Set wire color"""
  2212. data = self.GetLayerData('surface')
  2213. value = self._getColorString(event.GetValue())
  2214. data['surface']['draw']['wire-color'] = { 'value' : value,
  2215. 'update' : None }
  2216. # update properties
  2217. event = wxUpdateProperties(data = data)
  2218. wx.PostEvent(self.mapWindow, event)
  2219. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2220. self.mapWindow.Refresh(False)
  2221. def OnSurfaceAxis(self, event):
  2222. """!Surface position, axis changed"""
  2223. data = self.GetLayerData('surface')
  2224. id = data['surface']['object']['id']
  2225. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  2226. slider = self.FindWindowById(self.win['surface']['position']['slider'])
  2227. text = self.FindWindowById(self.win['surface']['position']['text'])
  2228. x, y, z = self._display.GetSurfacePosition(id)
  2229. if axis == 0: # x
  2230. slider.SetValue(x)
  2231. text.SetValue(x)
  2232. elif axis == 1: # y
  2233. slider.SetValue(y)
  2234. text.SetValue(y)
  2235. else: # z
  2236. slider.SetValue(z)
  2237. text.SetValue(z)
  2238. def OnSurfacePosition(self, event):
  2239. """!Surface position"""
  2240. winName = self.__GetWindowName(self.win['surface'], event.GetId())
  2241. if not winName:
  2242. return
  2243. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  2244. value = self.FindWindowById(event.GetId()).GetValue()
  2245. slider = self.FindWindowById(self.win['surface'][winName]['slider'])
  2246. self.AdjustSliderRange(slider = slider, value = value)
  2247. for win in self.win['surface']['position'].itervalues():
  2248. if win in (self.win['surface']['position']['axis'],
  2249. self.win['surface']['position']['reset']):
  2250. continue
  2251. else:
  2252. self.FindWindowById(win).SetValue(value)
  2253. data = self.GetLayerData('surface')
  2254. id = data['surface']['object']['id']
  2255. x, y, z = self._display.GetSurfacePosition(id)
  2256. if axis == 0: # x
  2257. x = value
  2258. elif axis == 1: # y
  2259. y = value
  2260. else: # z
  2261. z = value
  2262. data['surface']['position']['x'] = x
  2263. data['surface']['position']['y'] = y
  2264. data['surface']['position']['z'] = z
  2265. data['surface']['position']['update'] = None
  2266. # update properties
  2267. event = wxUpdateProperties(data = data)
  2268. wx.PostEvent(self.mapWindow, event)
  2269. self.mapWindow.render['quick'] = True
  2270. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2271. self.mapWindow.Refresh(False)
  2272. # self.UpdatePage('surface')
  2273. def OnSurfacePositionChanged(self, event):
  2274. """!Surface position changed"""
  2275. self.mapWindow.render['quick'] = False
  2276. self.mapWindow.Refresh(False)
  2277. def OnSurfacePositionText(self, event):
  2278. """!Surface position changed by textctrl"""
  2279. self.OnSurfacePosition(event)
  2280. self.OnSurfacePositionChanged(None)
  2281. def UpdateVectorShow(self, vecType, enabled):
  2282. """!Enable/disable lines/points widgets
  2283. @param vecType vector type (lines, points)
  2284. """
  2285. if vecType != 'lines' and vecType != 'points':
  2286. return False
  2287. for win in self.win['vector'][vecType].keys():
  2288. if win == 'show':
  2289. continue
  2290. if type(self.win['vector'][vecType][win]) == type({}):
  2291. for swin in self.win['vector'][vecType][win].keys():
  2292. if enabled:
  2293. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
  2294. else:
  2295. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
  2296. else:
  2297. if enabled:
  2298. self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
  2299. else:
  2300. self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
  2301. return True
  2302. def OnVectorShow(self, event):
  2303. """!Show vector lines/points"""
  2304. winId = event.GetId()
  2305. if winId == self.win['vector']['lines']['show']:
  2306. vecType = 'lines'
  2307. points = False
  2308. else: # points
  2309. vecType = 'points'
  2310. points = True
  2311. checked = event.IsChecked()
  2312. name = self.FindWindowById(self.win['vector']['map']).GetValue()
  2313. item = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'item')
  2314. data = self.GetLayerData('vector')['vector']
  2315. if checked:
  2316. self.mapWindow.LoadVector(item, points = points)
  2317. else:
  2318. self.mapWindow.UnloadVector(item, points = points)
  2319. self.UpdateVectorShow(vecType, checked)
  2320. if checked:
  2321. try:
  2322. id = data[vecType]['object']['id']
  2323. except KeyError:
  2324. id = -1
  2325. if id > 0:
  2326. self.mapWindow.SetMapObjProperties(item, id, vecType)
  2327. # update properties
  2328. event = wxUpdateProperties(data = data)
  2329. wx.PostEvent(self.mapWindow, event)
  2330. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2331. self.mapWindow.Refresh(False)
  2332. event.Skip()
  2333. def OnVectorDisplay(self, event):
  2334. """!Display vector lines on surface/flat"""
  2335. rasters = self.mapWindow.GetLayerNames('raster')
  2336. if event.GetSelection() == 0: # surface
  2337. if len(rasters) < 1:
  2338. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  2339. self.FindWindowById(self.win['vector']['lines']['flat']).SetSelection(1)
  2340. return
  2341. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(True)
  2342. # set first found surface
  2343. data = self.GetLayerData('vector')
  2344. data['vector']['lines']['mode']['surface'] = rasters[0]
  2345. self.FindWindowById(self.win['vector']['lines']['surface']).SetStringSelection( \
  2346. rasters[0])
  2347. else: # flat
  2348. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  2349. self.OnVectorLines(event)
  2350. event.Skip()
  2351. def OnVectorLines(self, event):
  2352. """!Set vector lines mode, apply changes if auto-rendering is enabled"""
  2353. data = self.GetLayerData('vector')
  2354. width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
  2355. mode = {}
  2356. if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
  2357. mode['type'] = 'surface'
  2358. mode['surface'] = {}
  2359. checklist = self.FindWindowById(self.win['vector']['lines']['surface'])
  2360. value = list()
  2361. checked = list()
  2362. for surface in range(checklist.GetCount()):
  2363. value.append(checklist.GetString(surface))
  2364. checked.append(checklist.IsChecked(surface))
  2365. mode['surface']['value'] = value
  2366. mode['surface']['show'] = checked
  2367. else:
  2368. mode['type'] = 'flat'
  2369. for attrb in ('width', 'mode'):
  2370. data['vector']['lines'][attrb]['update'] = None
  2371. data['vector']['lines']['width']['value'] = width
  2372. data['vector']['lines']['mode'] = mode
  2373. color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
  2374. if isinstance(color, csel.ColourSelect):
  2375. pass #color picker not yet instantiated
  2376. else:
  2377. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2378. data['vector']['lines']['color']['update'] = None
  2379. data['vector']['lines']['color']['value'] = color
  2380. # update properties
  2381. event = wxUpdateProperties(data = data)
  2382. wx.PostEvent(self.mapWindow, event)
  2383. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2384. self.mapWindow.Refresh(False)
  2385. def OnVectorHeight(self, event):
  2386. id = event.GetId()
  2387. if id in self.win['vector']['lines']['height'].values():
  2388. vtype = 'lines'
  2389. else:
  2390. vtype = 'points'
  2391. value = self.FindWindowById(id).GetValue()
  2392. slider = self.FindWindowById(self.win['vector'][vtype]['height']['slider'])
  2393. self.AdjustSliderRange(slider = slider, value = value)
  2394. for win in self.win['vector'][vtype]['height'].itervalues():
  2395. self.FindWindowById(win).SetValue(value)
  2396. data = self.GetLayerData('vector')
  2397. data['vector'][vtype]['height'] = { 'value' : value,
  2398. 'update' : None }
  2399. # update properties
  2400. event = wxUpdateProperties(data = data)
  2401. wx.PostEvent(self.mapWindow, event)
  2402. self.mapWindow.render['quick'] = True
  2403. self.mapWindow.render['v' + vtype] = True
  2404. self.mapWindow.Refresh(False)
  2405. event.Skip()
  2406. def OnVectorHeightFull(self, event):
  2407. """!Vector height changed, render in full resolution"""
  2408. self.OnVectorHeight(event)
  2409. ## self.OnVectorSurface(event)
  2410. id = event.GetId()
  2411. if id in self.win['vector']['lines']['height'].values():
  2412. vtype = 'lines'
  2413. else:
  2414. vtype = 'points'
  2415. self.mapWindow.render['quick'] = False
  2416. self.mapWindow.render['v' + vtype] = False
  2417. self.mapWindow.Refresh(False)
  2418. def OnVectorHeightText(self, event):
  2419. """!Vector height changed, render in full resolution"""
  2420. # self.OnVectorHeight(event)
  2421. self.OnVectorHeightFull(event)
  2422. def OnVectorSurface(self, event):
  2423. """!Reference surface for vector map (lines/points)"""
  2424. id = event.GetId()
  2425. if id == self.win['vector']['lines']['surface']:
  2426. vtype = 'lines'
  2427. else:
  2428. vtype = 'points'
  2429. checkList = self.FindWindowById(self.win['vector'][vtype]['surface'])
  2430. checked = []
  2431. surfaces = []
  2432. for items in range(checkList.GetCount()):
  2433. checked.append(checkList.IsChecked(items))
  2434. surfaces.append(checkList.GetString(items))
  2435. data = self.GetLayerData('vector')
  2436. data['vector'][vtype]['mode']['surface'] = { 'value' : surfaces,
  2437. 'show' : checked}
  2438. data['vector'][vtype]['mode']['update'] = None
  2439. # update properties
  2440. event = wxUpdateProperties(data = data)
  2441. wx.PostEvent(self.mapWindow, event)
  2442. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2443. self.mapWindow.Refresh(False)
  2444. def OnVectorPoints(self, event):
  2445. """!Set vector points mode, apply changes if auto-rendering is enabled"""
  2446. data = self.GetLayerData('vector')
  2447. size = self.FindWindowById(self.win['vector']['points']['size']).GetValue()
  2448. marker = self.FindWindowById(self.win['vector']['points']['marker']).GetSelection()
  2449. # width = self.FindWindowById(self.win['vector']['points']['width']).GetValue()
  2450. for attrb in ('size', 'marker'):
  2451. data['vector']['points'][attrb]['update'] = None
  2452. data['vector']['points']['size']['value'] = size
  2453. # data['vector']['points']['width']['value'] = width
  2454. data['vector']['points']['marker']['value'] = marker
  2455. color = self.FindWindowById(self.win['vector']['points']['color']).GetColour()
  2456. if isinstance(color, csel.ColourSelect):
  2457. pass #color picker not yet instantiated
  2458. else:
  2459. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2460. data['vector']['points']['color']['update'] = None
  2461. data['vector']['points']['color']['value'] = color
  2462. # update properties
  2463. event = wxUpdateProperties(data = data)
  2464. wx.PostEvent(self.mapWindow, event)
  2465. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2466. self.mapWindow.Refresh(False)
  2467. def UpdateIsosurfButtons(self, list):
  2468. """!Enable/disable buttons 'add', 'delete',
  2469. 'move up', 'move down'"""
  2470. nitems = list.GetCount()
  2471. add = self.parent.FindWindowById(self.win['volume']['btnIsosurfAdd'])
  2472. delete = self.parent.FindWindowById(self.win['volume']['btnIsosurfDelete'])
  2473. moveDown = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
  2474. moveUp = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
  2475. if nitems >= wxnviz.MAX_ISOSURFS:
  2476. # disable add button on max
  2477. add.Enable(False)
  2478. else:
  2479. add.Enable(True)
  2480. if nitems < 1:
  2481. # disable 'delete' if only one item in the lis
  2482. delete.Enable(False)
  2483. else:
  2484. delete.Enable(True)
  2485. if list.GetSelection() >= nitems - 1:
  2486. # disable 'move-down' if last
  2487. moveDown.Enable(False)
  2488. else:
  2489. moveDown.Enable(True)
  2490. if list.GetSelection() < 1:
  2491. # disable 'move-up' if first
  2492. moveUp.Enable(False)
  2493. else:
  2494. moveUp.Enable(True)
  2495. def OnVolumeIsosurfMode(self, event):
  2496. """!Set isosurface draw mode"""
  2497. self.SetIsosurfaceMode(event.GetSelection())
  2498. def SetIsosurfaceMode(self, selection):
  2499. """!Set isosurface draw mode"""
  2500. data = self.GetLayerData('volume')['volume']
  2501. id = data['object']['id']
  2502. mode = 0
  2503. if selection == 0:
  2504. mode |= wxnviz.DM_FLAT
  2505. else:
  2506. mode |= wxnviz.DM_GOURAUD
  2507. self._display.SetIsosurfaceMode(id, mode)
  2508. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2509. self.mapWindow.Refresh(False)
  2510. def OnVolumeIsosurfResolution(self, event):
  2511. """!Set isosurface draw resolution"""
  2512. self.SetIsosurfaceResolution(event.GetInt())
  2513. def SetIsosurfaceResolution(self, res):
  2514. """!Set isosurface draw resolution"""
  2515. data = self.GetLayerData('volume')['volume']
  2516. id = data['object']['id']
  2517. self._display.SetIsosurfaceRes(id, res)
  2518. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2519. self.mapWindow.Refresh(False)
  2520. def OnInOutMode(self, event):
  2521. """!Change isosurfaces mode inout"""
  2522. data = self.GetLayerData('volume')['volume']
  2523. id = data['object']['id']
  2524. isosurfId = self.FindWindowById(self.win['volume']['isosurfs']).GetSelection()
  2525. ret = self._display.SetIsosurfaceInOut(id, isosurfId, event.GetInt())
  2526. if ret == 1:
  2527. data['isosurface'][isosurfId]['inout'] = event.GetInt()
  2528. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2529. self.mapWindow.Refresh(False)
  2530. def OnVolumeIsosurfMap(self, event):
  2531. """!Set surface attribute"""
  2532. if self.vetoGSelectEvt:
  2533. self.vetoGSelectEvt = False
  2534. return
  2535. self.SetMapObjAttrb(nvizType = 'volume', winId = event.GetId())
  2536. def OnVolumeIsosurfCheck(self, event):
  2537. """!Isosurface checked (->load) or unchecked (->unload)"""
  2538. index = event.GetSelection()
  2539. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2540. data = self.GetLayerData('volume')['volume']
  2541. id = data['object']['id']
  2542. isosurfId = event.GetSelection()
  2543. if list.IsChecked(index):
  2544. if 'transp' in data['isosurface'][isosurfId] and\
  2545. data['isosurface'][isosurfId]['transp']['map'] is not None:
  2546. if data['isosurface'][isosurfId]['transp']['map']:
  2547. map = True
  2548. value = data['isosurface'][isosurfId]['transp']['value']
  2549. elif data['isosurface'][isosurfId]['transp']['map'] is not None:
  2550. map = False
  2551. value = data['isosurface'][isosurfId]['transp']['value']
  2552. self._display.SetIsosurfaceTransp(id, isosurfId, map, value)
  2553. else:
  2554. self._display.SetIsosurfaceTransp(id, isosurfId, False, "0")
  2555. else:
  2556. # disable -> make transparent
  2557. self._display.SetIsosurfaceTransp(id, isosurfId, False, "255")
  2558. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2559. self.mapWindow.Refresh(False)
  2560. def OnVolumeIsosurfSelect(self, event):
  2561. """!Isosurface item selected"""
  2562. winUp = self.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
  2563. winDown = self.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
  2564. selection = event.GetSelection()
  2565. if selection == -1:
  2566. return
  2567. elif selection == 0:
  2568. winUp.Enable(False)
  2569. if not winDown.IsEnabled():
  2570. winDown.Enable()
  2571. elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
  2572. winDown.Enable(False)
  2573. if not winUp.IsEnabled():
  2574. winUp.Enable()
  2575. else:
  2576. if not winDown.IsEnabled():
  2577. winDown.Enable()
  2578. if not winUp.IsEnabled():
  2579. winUp.Enable()
  2580. # update dialog
  2581. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2582. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2583. data = self.GetLayerData('volume')['volume']['isosurface'][selection]
  2584. self.UpdateVolumeIsosurfPage(layer, data)
  2585. def OnVolumeIsosurfAdd(self, event):
  2586. """!Add new isosurface to the list"""
  2587. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2588. isosurfData = self.mapWindow.nvizDefault.SetIsosurfaceDefaultProp()
  2589. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2590. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2591. data = self.GetLayerData('volume')['volume']
  2592. id = data['object']['id']
  2593. if isosurfData['color']['map']:
  2594. isosurfData['color']['value'] = layer.name
  2595. prec = 2
  2596. level = isosurfData['topo']['value'] = round(self._get3dRange(name = layer.name)[0], prec)
  2597. sel = list.GetSelection()
  2598. if sel < 0 or sel >= list.GetCount() - 1:
  2599. item = list.Append(item = "%s %s" % (_("Level"), str(level)))
  2600. else:
  2601. list.Insert(item = "%s %s" % (_("Level"), str(level)),
  2602. pos = sel+1) # append
  2603. item = sel + 1
  2604. list.Check(item)
  2605. list.SetSelection(item)
  2606. data['isosurface'].insert(item, isosurfData)
  2607. # add isosurface
  2608. self._display.AddIsosurface(id, float(level))
  2609. # update properties
  2610. event = wxUpdateProperties(data = data)
  2611. wx.PostEvent(self.mapWindow, event)
  2612. # update buttons
  2613. self.UpdateIsosurfButtons(list)
  2614. self.UpdateVolumeIsosurfPage(layer, isosurfData)
  2615. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2616. self.mapWindow.Refresh(False)
  2617. event.Skip()
  2618. def OnVolumeIsosurfDelete(self, event):
  2619. """!Remove isosurface from list"""
  2620. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2621. # remove item from list
  2622. isosurfId = list.GetSelection()
  2623. list.Delete(isosurfId)
  2624. # select last item
  2625. if list.GetCount() > 0:
  2626. list.SetSelection(list.GetCount()-1)
  2627. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2628. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2629. data = self.GetLayerData('volume')['volume']
  2630. id = data['object']['id']
  2631. # delete isosurface
  2632. del data['isosurface'][isosurfId]
  2633. self._display.DeleteIsosurface(id, isosurfId)
  2634. # update buttons
  2635. self.UpdateIsosurfButtons(list)
  2636. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2637. self.mapWindow.Refresh(False)
  2638. event.Skip()
  2639. def OnVolumeIsosurfMoveUp(self, event):
  2640. """!Move isosurface up in the list"""
  2641. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2642. sel = list.GetSelection()
  2643. if sel < 1:
  2644. return # this should not happen
  2645. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2646. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2647. data = self.GetLayerData('volume')['volume']
  2648. id = data['object']['id']
  2649. # move item up
  2650. text = list.GetStringSelection()
  2651. list.Insert(item = text, pos = sel-1)
  2652. list.Check(sel-1)
  2653. list.SetSelection(sel-1)
  2654. list.Delete(sel+1)
  2655. data['isosurface'].insert(sel-1, data['isosurface'][sel])
  2656. del data['isosurface'][sel+1]
  2657. self._display.MoveIsosurface(id, sel, True)
  2658. # update buttons
  2659. self.UpdateIsosurfButtons(list)
  2660. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2661. self.mapWindow.Refresh(False)
  2662. event.Skip()
  2663. def OnVolumeIsosurfMoveDown(self, event):
  2664. """!Move isosurface dowm in the list"""
  2665. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2666. sel = list.GetSelection()
  2667. if sel >= list.GetCount() - 1:
  2668. return # this should not happen
  2669. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2670. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2671. data = self.GetLayerData('volume')['volume']
  2672. id = data['object']['id']
  2673. # move item up
  2674. text = list.GetStringSelection()
  2675. list.Insert(item = text, pos = sel+2)
  2676. list.Check(sel+2)
  2677. list.SetSelection(sel+2)
  2678. list.Delete(sel)
  2679. data['isosurface'].insert(sel+2, data['isosurface'][sel])
  2680. del data['isosurface'][sel]
  2681. self._display.MoveIsosurface(id, sel, False)
  2682. # update buttons
  2683. self.UpdateIsosurfButtons(list)
  2684. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2685. self.mapWindow.Refresh(False)
  2686. event.Skip()
  2687. def OnVolumePositionChanged(self, event):
  2688. """!Volume position changed"""
  2689. self.mapWindow.render['quick'] = False
  2690. self.mapWindow.Refresh(False)
  2691. def OnVolumePosition(self, event):
  2692. """!Volume position"""
  2693. winName = self.__GetWindowName(self.win['volume'], event.GetId())
  2694. if not winName:
  2695. return
  2696. axis = self.FindWindowById(self.win['volume']['position']['axis']).GetSelection()
  2697. value = self.FindWindowById(event.GetId()).GetValue()
  2698. slider = self.FindWindowById(self.win['volume'][winName]['slider'])
  2699. self.AdjustSliderRange(slider = slider, value = value)
  2700. for win in self.win['volume']['position'].itervalues():
  2701. if win in (self.win['volume']['position']['axis'],
  2702. self.win['volume']['position']['reset']):
  2703. continue
  2704. else:
  2705. self.FindWindowById(win).SetValue(value)
  2706. data = self.GetLayerData('volume')
  2707. id = data['volume']['object']['id']
  2708. x, y, z = self._display.GetVolumePosition(id)
  2709. if axis == 0: # x
  2710. x = value
  2711. elif axis == 1: # y
  2712. y = value
  2713. else: # z
  2714. z = value
  2715. data['volume']['position']['x'] = x
  2716. data['volume']['position']['y'] = y
  2717. data['volume']['position']['z'] = z
  2718. data['volume']['position']['update'] = None
  2719. # update properties
  2720. event = wxUpdateProperties(data = data)
  2721. wx.PostEvent(self.mapWindow, event)
  2722. self.mapWindow.render['quick'] = True
  2723. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2724. self.mapWindow.Refresh(False)
  2725. def OnVolumeAxis(self, event):
  2726. """!Volume position, axis changed"""
  2727. data = self.GetLayerData('volume')
  2728. id = data['volume']['object']['id']
  2729. axis = self.FindWindowById(self.win['volume']['position']['axis']).GetSelection()
  2730. slider = self.FindWindowById(self.win['volume']['position']['slider'])
  2731. text = self.FindWindowById(self.win['volume']['position']['text'])
  2732. x, y, z = self._display.GetVolumePosition(id)
  2733. if axis == 0: # x
  2734. slider.SetValue(x)
  2735. text.SetValue(x)
  2736. elif axis == 1: # y
  2737. slider.SetValue(y)
  2738. text.SetValue(y)
  2739. else: # z
  2740. slider.SetValue(z)
  2741. text.SetValue(z)
  2742. def OnVolumePositionText(self, event):
  2743. """!Volume position changed by textctrl"""
  2744. self.OnVolumePosition(event)
  2745. self.OnVolumePositionChanged(None)
  2746. def OnResetVolumePosition(self, event):
  2747. """!Reset position of volume"""
  2748. for win in self.win['volume']['position'].itervalues():
  2749. if win == self.win['volume']['position']['axis']:
  2750. self.FindWindowById(win).SetSelection(0)
  2751. elif win == self.win['volume']['position']['reset']:
  2752. continue
  2753. else:
  2754. self.FindWindowById(win).SetValue(0)
  2755. data = self.GetLayerData('volume')
  2756. data['volume']['position']['x'] = 0
  2757. data['volume']['position']['y'] = 0
  2758. data['volume']['position']['z'] = 0
  2759. data['volume']['position']['update'] = None
  2760. # update properties
  2761. event = wxUpdateProperties(data = data)
  2762. wx.PostEvent(self.mapWindow, event)
  2763. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2764. self.mapWindow.Refresh(False)
  2765. def OnCPlaneSelection(self, event):
  2766. """!Cutting plane selected"""
  2767. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  2768. try:
  2769. planeIndex = int(plane.split()[1])
  2770. self.EnablePage("cplane", enabled = True)
  2771. except:
  2772. planeIndex = -1
  2773. self.EnablePage("cplane", enabled = False)
  2774. self.mapWindow.SelectCPlane(planeIndex)
  2775. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2776. self.mapWindow.Refresh(False)
  2777. self.UpdateCPlanePage(planeIndex)
  2778. def OnCPlaneChanging(self, event):
  2779. """!Cutting plane is changing"""
  2780. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  2781. try:
  2782. planeIndex = int(plane.split()[1])
  2783. except:#TODO disabled page
  2784. planeIndex = -1
  2785. if event.GetId() in (self.win['cplane']['rotation']['rot'].values() +
  2786. self.win['cplane']['rotation']['tilt'].values()):
  2787. action = 'rotation'
  2788. else:
  2789. action = 'position'
  2790. data = self.mapWindow.cplanes[planeIndex][action]
  2791. self.OnScroll(event, self.win['cplane'][action], data)
  2792. self.mapWindow.render['quick'] = True
  2793. event = wxUpdateCPlane(update = (action,), current = planeIndex)
  2794. wx.PostEvent(self.mapWindow, event)
  2795. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2796. self.mapWindow.Refresh(False)
  2797. def OnCPlaneChangeDone(self, event):
  2798. """!Cutting plane change done"""
  2799. self.mapWindow.render['quick'] = False
  2800. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2801. self.mapWindow.Refresh(False)
  2802. def OnCPlaneChangeText(self, event):
  2803. """!Cutting plane changed by textctrl"""
  2804. for axis in ('x', 'y', 'z'):
  2805. if event.GetId() == self.win['cplane']['position'][axis]['text']:
  2806. value = self.FindWindowById(event.GetId()).GetValue()
  2807. slider = self.FindWindowById(self.win['cplane']['position'][axis]['slider'])
  2808. self.AdjustSliderRange(slider = slider, value = value)
  2809. self.OnCPlaneChanging(event = event)
  2810. self.OnCPlaneChangeDone(None)
  2811. def OnCPlaneShading(self, event):
  2812. """!Cutting plane shading changed"""
  2813. shading = self.FindWindowById(self.win['cplane']['shading']).GetSelection()
  2814. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  2815. try:
  2816. planeIndex = int(plane.split()[1])
  2817. except:#TODO disabled page
  2818. planeIndex = -1
  2819. self.mapWindow.cplanes[planeIndex]['shading'] = shading
  2820. event = wxUpdateCPlane(update = ('shading',), current = planeIndex)
  2821. wx.PostEvent(self.mapWindow, event)
  2822. self.OnCPlaneChangeDone(None)
  2823. def OnCPlaneReset(self, event):
  2824. """!Reset current cutting plane"""
  2825. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  2826. try:
  2827. planeIndex = int(plane.split()[1])
  2828. except:#TODO disabled page
  2829. planeIndex = -1
  2830. self.mapWindow.cplanes[planeIndex] = copy.deepcopy(UserSettings.Get(group = 'nviz',
  2831. key = 'cplane'))
  2832. event = wxUpdateCPlane(update = ('position','rotation','shading'), current = planeIndex)
  2833. wx.PostEvent(self.mapWindow, event)
  2834. self.OnCPlaneChangeDone(None)
  2835. self.UpdateCPlanePage(planeIndex)
  2836. def OnCPlanePos(self, event):
  2837. """!Place cutting plane rotation center interactively"""
  2838. self.mapWindow.mouse['use'] = 'cplane'
  2839. self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
  2840. self.parent.curr_page.maptree.mapdisplay.SetFocus()
  2841. self.parent.curr_page.maptree.mapdisplay.Raise()
  2842. def OnArrowPlacement(self, event):
  2843. """!Place an arrow by clicking on display"""
  2844. if event.GetInt():
  2845. self.mapWindow.mouse['use'] = 'arrow'
  2846. self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
  2847. else:
  2848. self.mapWindow.mouse['use'] = 'default'
  2849. self.mapWindow.SetCursor(self.mapWindow.cursors["default"])
  2850. def OnArrowDelete(self, event):
  2851. """!Delete arrow"""
  2852. self._display.DeleteArrow()
  2853. self.mapWindow.decoration['arrow']['show'] = False
  2854. self.mapWindow.Refresh(False)
  2855. def OnArrowProp(self, event):
  2856. """!Set arrow properties"""
  2857. color = self.FindWindowById(self.win['decoration']['arrow']['color']).GetValue()
  2858. self.mapWindow.decoration['arrow']['color'] = self._getColorString(color)
  2859. size = self.FindWindowById(self.win['decoration']['arrow']['size']).GetValue()
  2860. self.mapWindow.decoration['arrow']['size'] = size
  2861. if self.mapWindow.decoration['arrow']['show']:
  2862. self._display.SetArrow(self.mapWindow.decoration['arrow']['position']['x'],
  2863. self.mapWindow.decoration['arrow']['position']['y'],
  2864. self.mapWindow.decoration['arrow']['size'],
  2865. self.mapWindow.decoration['arrow']['color'])
  2866. self._display.DrawArrow()
  2867. self.mapWindow.Refresh(False)
  2868. def UpdatePage(self, pageId):
  2869. """!Update dialog (selected page)"""
  2870. self.pageChanging = True
  2871. Debug.msg(1, "NvizToolWindow.UpdatePage(): %s", pageId)
  2872. if pageId == 'view':
  2873. self.SetPage('view')
  2874. hmin = self.mapWindow.iview['height']['min']
  2875. hmax = self.mapWindow.iview['height']['max']
  2876. hval = self.mapWindow.iview['height']['value']
  2877. zmin = self.mapWindow.view['z-exag']['min']
  2878. zmax = self.mapWindow.view['z-exag']['max']
  2879. zval = self.mapWindow.view['z-exag']['value']
  2880. for control in ('slider','text'):
  2881. self.FindWindowById(self.win['view']['height'][control]).SetRange(
  2882. hmin,hmax)
  2883. self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(
  2884. zmin, zmax)
  2885. self.FindWindowById(self.win['view']['height'][control]).SetValue(hval)
  2886. self.FindWindowById(self.win['view']['z-exag'][control]).SetValue(zval)
  2887. self.FindWindowById(self.win['view']['background']['color']).SetColour(\
  2888. self.mapWindow.view['background']['color'])
  2889. tval = self.mapWindow.view['twist']['value']
  2890. pval = self.mapWindow.view['persp']['value']
  2891. for control in ('slider','text'):
  2892. self.FindWindowById(self.win['view']['twist'][control]).SetValue(tval)
  2893. self.FindWindowById(self.win['view']['persp'][control]).SetValue(pval)
  2894. elif pageId in ('surface', 'vector', 'volume'):
  2895. name = self.FindWindowById(self.win[pageId]['map']).GetValue()
  2896. data = self.GetLayerData(pageId)
  2897. if data:
  2898. if pageId == 'surface':
  2899. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  2900. self.UpdateSurfacePage(layer, data['surface'])
  2901. elif pageId == 'vector':
  2902. layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
  2903. self.UpdateVectorPage(layer, data['vector'])
  2904. elif pageId == 'volume':
  2905. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2906. self.UpdateVolumePage(layer, data['volume'])
  2907. elif pageId == 'light':
  2908. zval = self.mapWindow.light['position']['z']
  2909. bval = self.mapWindow.light['bright']
  2910. aval = self.mapWindow.light['ambient']
  2911. for control in ('slider','text'):
  2912. self.FindWindowById(self.win['light']['z'][control]).SetValue(zval)
  2913. self.FindWindowById(self.win['light']['bright'][control]).SetValue(bval)
  2914. self.FindWindowById(self.win['light']['ambient'][control]).SetValue(aval)
  2915. self.FindWindowById(self.win['light']['color']).SetColour(self.mapWindow.light['color'])
  2916. self.FindWindowById(self.win['light']['position']).PostDraw()
  2917. elif pageId == 'fringe':
  2918. win = self.FindWindowById(self.win['fringe']['map'])
  2919. win.SetValue(self.FindWindowById(self.win['surface']['map']).GetValue())
  2920. elif pageId == 'decoration':
  2921. win = self.FindWindowById(self.win['decoration']['arrow']['size'])
  2922. win.SetValue(self.mapWindow.decoration['arrow']['size'])
  2923. elif pageId == 'constant':
  2924. if self.mapWindow.constants:
  2925. surface = self.FindWindowById(self.win['constant']['surface'])
  2926. for item in self.mapWindow.constants:
  2927. surface.Append(_("constant#") + str(item['constant']['object']['name']))
  2928. surface.SetSelection(0)
  2929. self.OnConstantSelection(None)
  2930. self.EnablePage('constant', True)
  2931. elif pageId == 'cplane':
  2932. count = self._display.GetCPlanesCount()
  2933. choices = [_("None"),]
  2934. for plane in range(count):
  2935. choices.append("%s %i" % (_("Plane"), plane))
  2936. self.FindWindowById(self.win['cplane']['planes']).SetItems(choices)
  2937. self.FindWindowById(self.win['cplane']['planes']).SetSelection(0)
  2938. xyRange, zRange = self._display.GetXYRange(), self._display.GetZRange()
  2939. if xyRange > 0: # GTK warning
  2940. self.FindWindowById(self.win['cplane']['position']['x']['slider']).SetRange(-xyRange/2., xyRange/2.)
  2941. self.FindWindowById(self.win['cplane']['position']['y']['slider']).SetRange(-xyRange/2., xyRange/2.)
  2942. if zRange[0] - zRange[1] > 0:
  2943. self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetRange(zRange[0], zRange[1])
  2944. self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetValue(zRange[0])
  2945. self.FindWindowById(self.win['cplane']['position']['z']['text']).SetValue(zRange[0])
  2946. self.OnCPlaneSelection(None)
  2947. self.Update()
  2948. self.pageChanging = False
  2949. def UpdateCPlanePage(self, index):
  2950. """!Update widgets according to selected clip plane"""
  2951. if index == -1:
  2952. return
  2953. data = self.mapWindow.cplanes[index]
  2954. for widget in ('text', 'slider'):
  2955. for axes in ('x', 'y', 'z'):
  2956. self.FindWindowById(self.win['cplane']['position'][axes][widget]).SetValue(data['position'][axes])
  2957. for each in ('tilt', 'rot'):
  2958. self.FindWindowById(self.win['cplane']['rotation'][each][widget]).SetValue(data['rotation'][each])
  2959. self.FindWindowById(self.win['cplane']['shading']).SetSelection(data['shading'])
  2960. def UpdateSurfacePage(self, layer, data, updateName = True):
  2961. """!Update surface page"""
  2962. ret = gcmd.RunCommand('r.info',
  2963. read = True,
  2964. flags = 'm',
  2965. map = layer.name)
  2966. if ret:
  2967. desc = ret.split('=')[1].rstrip('\n')
  2968. else:
  2969. desc = None
  2970. if updateName:
  2971. self.FindWindowById(self.win['surface']['map']).SetValue(layer.name)
  2972. self.FindWindowById(self.win['surface']['desc']).SetLabel(desc)
  2973. # attributes
  2974. if layer and layer.type == 'raster':
  2975. self.vetoGSelectEvt = True
  2976. self.FindWindowById(self.win['surface']['color']['map']).SetValue(layer.name)
  2977. else:
  2978. self.FindWindowById(self.win['surface']['color']['map']).SetValue('')
  2979. self.SetMapObjUseMap(nvizType = 'surface',
  2980. attrb = 'color', map = True) # -> map
  2981. if 'color' in data['attribute']:
  2982. value = data['attribute']['color']['value']
  2983. if data['attribute']['color']['map']:
  2984. self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
  2985. else: # constant
  2986. color = map(int, value.split(':'))
  2987. self.FindWindowById(self.win['surface']['color']['const']).SetColour(color)
  2988. self.SetMapObjUseMap(nvizType = 'surface',
  2989. attrb = 'color', map = data['attribute']['color']['map'])
  2990. self.SetMapObjUseMap(nvizType = 'surface',
  2991. attrb = 'shine', map = data['attribute']['shine']['map'])
  2992. value = data['attribute']['shine']['value']
  2993. if data['attribute']['shine']['map']:
  2994. self.FindWindowById(self.win['surface']['shine']['map']).SetValue(value)
  2995. else:
  2996. self.FindWindowById(self.win['surface']['shine']['const']).SetValue(self._getPercent(value))
  2997. if 'transp' in data['attribute']:
  2998. value = data['attribute']['transp']['value']
  2999. if data['attribute']['transp']['map']:
  3000. self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
  3001. else:
  3002. self.FindWindowById(self.win['surface']['transp']['const']).SetValue(self._getPercent(value))
  3003. self.SetMapObjUseMap(nvizType = 'surface', attrb = 'transp', map = data['attribute']['transp']['map'])
  3004. else:
  3005. self.SetMapObjUseMap(nvizType = 'surface', attrb = 'transp', map = None)
  3006. #
  3007. # draw
  3008. #
  3009. for control, drawData in data['draw'].iteritems():
  3010. if control == 'all': # skip 'all' property
  3011. continue
  3012. if control == 'resolution':
  3013. self.FindWindowById(self.win['surface']['draw']['res-coarse']).SetValue(drawData['coarse'])
  3014. self.FindWindowById(self.win['surface']['draw']['res-fine']).SetValue(drawData['fine'])
  3015. continue
  3016. if control == 'mode':
  3017. if drawData['desc']['mode'] == 'coarse':
  3018. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(0)
  3019. elif drawData['desc']['mode'] == 'fine':
  3020. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(1)
  3021. else: # both
  3022. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(2)
  3023. if drawData['desc']['style'] == 'wire':
  3024. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(0)
  3025. else: # surface
  3026. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(1)
  3027. if drawData['desc']['shading'] == 'flat':
  3028. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(0)
  3029. else: # gouraud
  3030. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(1)
  3031. continue
  3032. value = drawData['value']
  3033. win = self.FindWindowById(self.win['surface']['draw'][control])
  3034. name = win.GetName()
  3035. if name == "selection":
  3036. win.SetSelection(value)
  3037. elif name == "colour":
  3038. color = map(int, value.split(':'))
  3039. win.SetColour(color)
  3040. else:
  3041. win.SetValue(value)
  3042. #
  3043. # position
  3044. #
  3045. if 'x' in data['position']:
  3046. xval = data['position']['x']
  3047. self.FindWindowById(self.win['surface']['position']['axis']).SetSelection(0)
  3048. for control in ('slider','text'):
  3049. self.FindWindowById(self.win['surface']['position'][control]).SetValue(xval)
  3050. # enable/disable res widget + set draw mode
  3051. self.OnSurfaceMode(event = None)
  3052. def VectorInfo(self, layer):
  3053. """!Get number of points/lines
  3054. @param layer MapLayer instance
  3055. @return num of points/features (expect of points)
  3056. @return None
  3057. """
  3058. vInfo = grass.vector_info_topo(layer.GetName())
  3059. if not vInfo:
  3060. return None
  3061. nprimitives = 0
  3062. for key, value in vInfo.iteritems():
  3063. if key in ('points',
  3064. 'lines',
  3065. 'boundaries',
  3066. 'centroids',
  3067. 'faces',
  3068. 'kernels'):
  3069. nprimitives += value
  3070. return (vInfo['points'], vInfo['lines'], nprimitives, vInfo['map3d'])
  3071. def UpdateVectorPage(self, layer, data, updateName = True):
  3072. """!Update vector page"""
  3073. npoints, nlines, nfeatures, mapIs3D = self.VectorInfo(layer)
  3074. if mapIs3D:
  3075. desc = _("Vector map is 3D")
  3076. enable = False
  3077. else:
  3078. desc = _("Vector map is 2D")
  3079. enable = True
  3080. desc += " - " + _("%(features)d features (%(points)d points)") % \
  3081. { 'features' : nfeatures, 'points' : npoints }
  3082. if updateName:
  3083. self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
  3084. self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
  3085. self.FindWindowById(self.win['vector']['lines']['flat']).Enable(enable)
  3086. for v in ('lines', 'points'):
  3087. self.FindWindowById(self.win['vector'][v]['surface']).Enable(enable)
  3088. self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
  3089. self.FindWindowById(self.win['vector'][v]['height']['text']).Enable(enable)
  3090. #
  3091. # lines
  3092. #
  3093. showLines = self.FindWindowById(self.win['vector']['lines']['show'])
  3094. if 'object' in data['lines']:
  3095. showLines.SetValue(True)
  3096. else:
  3097. showLines.SetValue(False)
  3098. if nlines > 0:
  3099. showLines.Enable(True)
  3100. else:
  3101. showLines.Enable(False)
  3102. self.UpdateVectorShow('lines',
  3103. showLines.IsChecked())
  3104. width = self.FindWindowById(self.win['vector']['lines']['width'])
  3105. width.SetValue(data['lines']['width']['value'])
  3106. color = self.FindWindowById(self.win['vector']['lines']['color'])
  3107. color.SetValue(map(int, data['lines']['color']['value'].split(':')))
  3108. for vtype in ('lines', 'points'):
  3109. if vtype == 'lines':
  3110. display = self.FindWindowById(self.win['vector']['lines']['flat'])
  3111. if data[vtype]['mode']['type'] == 'flat':
  3112. display.SetSelection(1)
  3113. else:
  3114. display.SetSelection(0)
  3115. if data[vtype]['mode']['type'] == 'surface':
  3116. rasters = self.mapWindow.GetLayerNames('raster')
  3117. constants = self.mapWindow.GetLayerNames('constant')
  3118. surfaces = rasters + constants
  3119. surfaceWin = self.FindWindowById(self.win['vector'][vtype]['surface'])
  3120. surfaceWin.SetItems(surfaces)
  3121. for idx, surface in enumerate(surfaces):
  3122. try:# TODO fix this mess
  3123. selected = data[vtype]['mode']['surface']['show'][idx]
  3124. except (TypeError, IndexError, KeyError):
  3125. selected = False
  3126. surfaceWin.Check(idx, selected)
  3127. for type in ('slider', 'text'):
  3128. win = self.FindWindowById(self.win['vector']['lines']['height'][type])
  3129. win.SetValue(data['lines']['height']['value'])
  3130. #
  3131. # points
  3132. #
  3133. showPoints = self.FindWindowById(self.win['vector']['points']['show'])
  3134. if 'object' in data['points']:
  3135. showPoints.SetValue(True)
  3136. else:
  3137. showPoints.SetValue(False)
  3138. if npoints > 0:
  3139. showPoints.Enable(True)
  3140. else:
  3141. showPoints.Enable(False)
  3142. self.UpdateVectorShow('points',
  3143. showPoints.IsChecked())
  3144. # size, width, marker, color
  3145. for prop in ('size', 'marker', 'color'):
  3146. win = self.FindWindowById(self.win['vector']['points'][prop])
  3147. name = win.GetName()
  3148. if name == 'selection':
  3149. win.SetSelection(data['points'][prop]['value'])
  3150. elif name == 'color':
  3151. color = map(int, data['points'][prop]['value'].split(':'))
  3152. win.SetValue(color)
  3153. else:
  3154. win.SetValue(data['points'][prop]['value'])
  3155. # height
  3156. for type in ('slider', 'text'):
  3157. win = self.FindWindowById(self.win['vector']['points']['height'][type])
  3158. win.SetValue(data['points']['height']['value'])
  3159. def UpdateVolumePage(self, layer, data, updateName = True):
  3160. """!Update volume page"""
  3161. if updateName:
  3162. self.FindWindowById(self.win['volume']['map']).SetValue(layer.name)
  3163. # draw
  3164. for control, idata in data['draw'].iteritems():
  3165. if control == 'all': # skip 'all' property
  3166. continue
  3167. win = self.FindWindowById(self.win['volume']['draw'][control])
  3168. if control == 'shading':
  3169. if data['draw']['shading']['desc'] == 'flat':
  3170. value = 0
  3171. else:
  3172. value = 1
  3173. else:
  3174. value = idata['value']
  3175. if win.GetName() == "selection":
  3176. win.SetSelection(value)
  3177. else:
  3178. win.SetValue(value)
  3179. self.SetIsosurfaceMode(data['draw']['shading']['value'])
  3180. self.SetIsosurfaceResolution(data['draw']['resolution']['value'])
  3181. isobox = self.FindWindowById(self.win['volume']['isosurfs'])
  3182. isosurfaces = []
  3183. for iso in data['isosurface']:
  3184. level = iso['topo']['value']
  3185. isosurfaces.append("%s %s" % (_("Level"), level))
  3186. isobox.Set(isosurfaces)
  3187. isobox.SetChecked(range(len(isosurfaces)))
  3188. if data['isosurface']:
  3189. isobox.SetSelection(0)
  3190. self.UpdateVolumeIsosurfPage(layer, data['isosurface'][0])
  3191. else:
  3192. self.UpdateVolumeIsosurfPage(layer, data['attribute'])
  3193. #
  3194. # position
  3195. #
  3196. if 'x' in data['position']:
  3197. xval = data['position']['x']
  3198. self.FindWindowById(self.win['volume']['position']['axis']).SetSelection(0)
  3199. for control in ('slider','text'):
  3200. self.FindWindowById(self.win['volume']['position'][control]).SetValue(xval)
  3201. def UpdateVolumeIsosurfPage(self, layer, data):
  3202. """!Update dialog -- isosurface attributes"""
  3203. #
  3204. # isosurface attributes
  3205. #
  3206. for attrb in ('topo', 'color', 'mask',
  3207. 'transp', 'shine'):
  3208. # check required first
  3209. if attrb == 'color':
  3210. if layer and layer.type == '3d-raster':
  3211. self.vetoGSelectEvt = True
  3212. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(layer.name)
  3213. else:
  3214. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue('')
  3215. self.SetMapObjUseMap(nvizType = 'volume',
  3216. attrb = attrb, map = True) # -> map
  3217. #continue
  3218. # skip empty attributes
  3219. if attrb not in data:
  3220. self.SetMapObjUseMap(nvizType = 'volume',
  3221. attrb = attrb, map = None)
  3222. continue
  3223. value = data[attrb]['value']
  3224. if attrb == 'color':
  3225. if data[attrb]['map']:
  3226. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(value)
  3227. else: # constant
  3228. color = map(int, value.split(':'))
  3229. self.FindWindowById(self.win['volume'][attrb]['const']).SetColour(color)
  3230. else:
  3231. if data[attrb]['map']:
  3232. self.vetoGSelectEvt = True
  3233. win = self.FindWindowById(self.win['volume'][attrb]['map'])
  3234. win.SetValue(value)
  3235. else:
  3236. if value:
  3237. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  3238. if attrb == 'topo':
  3239. win.SetValue(float(value))
  3240. else:
  3241. win.SetValue(self._getPercent(value))
  3242. self.SetMapObjUseMap(nvizType = 'volume',
  3243. attrb = attrb, map = data[attrb]['map'])
  3244. # set topo range
  3245. range = self._get3dRange(name = layer.name)
  3246. desc = self.FindWindowById(self.win['volume']['desc'])
  3247. desc.SetLabel("%s %.3f - %.3f" % (_("range:"), range[0], range[1]))
  3248. # set inout
  3249. if 'inout' in data:
  3250. self.FindWindowById(self.win['volume']['inout']).SetValue(data['inout'])
  3251. def SetPage(self, name):
  3252. """!Get named page"""
  3253. if name == 'view':
  3254. self.SetSelection(0)
  3255. elif name in ('surface', 'vector', 'volume'):
  3256. self.SetSelection(1)
  3257. else:
  3258. self.SetSelection(2)
  3259. win = self.FindWindowById(self.page[name]['notebook'])
  3260. try:
  3261. win.Expand(win.GetFoldPanel(self.page[name]['id']))
  3262. except AttributeError:
  3263. win.SetSelection(self.page[name]['id'])
  3264. class PositionWindow(wx.Window):
  3265. """!Abstract position control window, see subclasses
  3266. ViewPostionWindow and LightPositionWindow"""
  3267. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  3268. **kwargs):
  3269. self.mapWindow = mapwindow
  3270. self.quick = True
  3271. wx.Window.__init__(self, parent, id, **kwargs)
  3272. self.SetBackgroundColour("WHITE")
  3273. self.pdc = wx.PseudoDC()
  3274. self.pdc.SetBrush(wx.Brush(colour = 'dark green', style = wx.SOLID))
  3275. self.pdc.SetPen(wx.Pen(colour = 'dark green', width = 2, style = wx.SOLID))
  3276. self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
  3277. self.Bind(wx.EVT_PAINT, self.OnPaint)
  3278. # self.Bind(wx.EVT_MOTION, self.OnMouse)
  3279. self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
  3280. def Draw(self, pos, scale = False):
  3281. w, h = self.GetClientSize()
  3282. x, y = pos
  3283. if scale:
  3284. x = x * w
  3285. y = y * h
  3286. self.pdc.Clear()
  3287. self.pdc.BeginDrawing()
  3288. self.pdc.DrawLine(w / 2, h / 2, x, y)
  3289. self.pdc.DrawCircle(x, y, 5)
  3290. self.pdc.EndDrawing()
  3291. def OnPaint(self, event):
  3292. dc = wx.BufferedPaintDC(self)
  3293. dc.SetBackground(wx.Brush("White"))
  3294. dc.Clear()
  3295. self.PrepareDC(dc)
  3296. self.pdc.DrawToDC(dc)
  3297. def UpdatePos(self, xcoord, ycoord):
  3298. """!Update position coordinates (origin: UL)"""
  3299. if xcoord < 0.0:
  3300. xcoord = 0.0
  3301. elif xcoord > 1.0:
  3302. xcoord = 1.0
  3303. if ycoord < 0.0:
  3304. ycoord = 0.0
  3305. elif ycoord > 1.0:
  3306. ycoord = 1.0
  3307. x, y = self.TransformCoordinates(xcoord, ycoord)
  3308. self.data['position']['x'] = x
  3309. self.data['position']['y'] = y
  3310. return xcoord, ycoord
  3311. def OnMouse(self, event):
  3312. if event.LeftIsDown():
  3313. x, y = event.GetPosition()
  3314. self.Draw(pos = (x, y))
  3315. w, h = self.GetClientSize()
  3316. x = float(x) / w
  3317. y = float(y) / h
  3318. self.UpdatePos(x, y)
  3319. self.Refresh(False)
  3320. event.Skip()
  3321. def PostDraw(self):
  3322. x, y = self.UpdatePos(self.data['position']['x'],
  3323. self.data['position']['y'])
  3324. self.Draw(pos = (x,y), scale = True)
  3325. class ViewPositionWindow(PositionWindow):
  3326. """!View position control widget"""
  3327. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  3328. **kwargs):
  3329. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  3330. self.data = self.mapWindow.view
  3331. self.PostDraw()
  3332. def UpdatePos(self, xcoord, ycoord):
  3333. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  3334. event = wxUpdateView(zExag = True)
  3335. wx.PostEvent(self.mapWindow, event)
  3336. return x, y
  3337. def TransformCoordinates(self, x, y, toLight = True):
  3338. return x, y
  3339. def OnMouse(self, event):
  3340. PositionWindow.OnMouse(self, event)
  3341. if event.LeftIsDown():
  3342. self.mapWindow.render['quick'] = self.quick
  3343. self.mapWindow.Refresh(eraseBackground = False)
  3344. elif event.LeftUp():
  3345. self.mapWindow.render['quick'] = False
  3346. self.mapWindow.Refresh(eraseBackground = False)
  3347. event.Skip()
  3348. class LightPositionWindow(PositionWindow):
  3349. """!Light position control widget"""
  3350. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  3351. **kwargs):
  3352. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  3353. self.data = self.mapWindow.light
  3354. self.quick = False
  3355. self.PostDraw()
  3356. def UpdatePos(self, xcoord, ycoord):
  3357. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  3358. event = wxUpdateLight()
  3359. wx.PostEvent(self.mapWindow, event)
  3360. return x, y
  3361. def TransformCoordinates(self, x, y, toLight = True):
  3362. if toLight:
  3363. x = 2 * x - 1
  3364. y = -2 * y + 1
  3365. else:
  3366. x = (x + 1)/2
  3367. y = (1 - y)/2
  3368. return x, y
  3369. def PostDraw(self):
  3370. event = wxUpdateLight(refresh = True)
  3371. wx.PostEvent(self.mapWindow, event)
  3372. x, y = self.data['position']['x'], self.data['position']['y']
  3373. x, y = self.TransformCoordinates(x, y, toLight = False)
  3374. self.Draw(pos = (x,y), scale = True)
  3375. def OnMouse(self, event):
  3376. PositionWindow.OnMouse(self, event)
  3377. if event.LeftUp():
  3378. self.mapWindow.render['quick'] = False
  3379. self.mapWindow.Refresh(eraseBackground = False)