nviz_tools.py 145 KB

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