nviz_tools.py 156 KB

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