nviz_tools.py 167 KB

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