wizard.py 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  1. """
  2. @package rlisetup.py
  3. @brief GUI per r.li.setup module
  4. Classes:
  5. - RLiSetupFrame (first frame to show existing conf file and choose some
  6. operation)
  7. - RLIWizard (the main wizard)
  8. - FirstPage (first page of wizard, choose name of conf file, raster, vector,
  9. sampling region)
  10. - Keyboard (page to insert region areas from keyboard)
  11. - SamplingAreas (define sampling area)
  12. - SummaryPage (show choosen options)
  13. (C) 2011 by the GRASS Development Team
  14. This program is free software under the GNU General Public License
  15. (>=v2). Read the file COPYING that comes with GRASS for details.
  16. @author Luca Delucchi <lucadeluge gmail com>
  17. """
  18. import os
  19. import wx
  20. import wx.wizard as wiz
  21. import wx.lib.scrolledpanel as scrolled
  22. from gui_core import gselect
  23. from core.utils import _
  24. from location_wizard.wizard import TitledPage as TitledPage
  25. from rlisetup.functions import checkValue, retRLiPath
  26. from rlisetup.sampling_frame import RLiSetupMapPanel
  27. from grass.script import core as grass
  28. from grass.script import raster as grast
  29. from grass.script import vector as gvect
  30. from grass.exceptions import CalledModuleError
  31. from functions import SamplingType, sampleAreaVector, convertFeature
  32. from functions import obtainAreaVector, obtainCategories
  33. from core.gcmd import GError, GMessage, RunCommand
  34. class RLIWizard(object):
  35. """
  36. !Start wizard here and finish wizard here
  37. """
  38. def __init__(self, parent):
  39. self.parent = parent
  40. self.wizard = wiz.Wizard(parent=parent, id=wx.ID_ANY,
  41. title=_("Create new configuration file for "
  42. "r.li modules"))
  43. self.rlipath = retRLiPath()
  44. self.msAreaList = []
  45. # pages
  46. self.startpage = FirstPage(self.wizard, self)
  47. self.drawsampleframepage = DrawSampleFramePage(self.wizard, self)
  48. self.keyboardpage = KeyboardPage(self.wizard, self)
  49. self.samplingareapage = SamplingAreasPage(self.wizard, self)
  50. self.summarypage = SummaryPage(self.wizard, self)
  51. self.units = SampleUnitsKeyPage(self.wizard, self)
  52. self.drawunits = UnitsMousePage(self.wizard, self)
  53. self.drawsampleunitspage = DrawSampleUnitsPage(self.wizard, self)
  54. self.vectorareas = VectorAreasPage(self.wizard, self)
  55. self.moving = MovingKeyPage(self.wizard, self)
  56. self.regions = DrawRegionsPage(self.wizard, self)
  57. # order of pages
  58. self.startpage.SetNext(self.samplingareapage)
  59. self.keyboardpage.SetPrev(self.startpage)
  60. self.keyboardpage.SetNext(self.samplingareapage)
  61. self.drawsampleframepage.SetNext(self.samplingareapage)
  62. self.drawsampleframepage.SetPrev(self.startpage)
  63. self.samplingareapage.SetPrev(self.startpage)
  64. self.samplingareapage.SetNext(self.summarypage)
  65. self.regions.SetPrev(self.samplingareapage)
  66. self.regions.SetNext(self.summarypage)
  67. self.units.SetPrev(self.samplingareapage)
  68. self.units.SetNext(self.summarypage)
  69. self.drawunits.SetPrev(self.samplingareapage)
  70. self.drawunits.SetNext(self.drawsampleunitspage)
  71. self.drawsampleunitspage.SetPrev(self.drawunits)
  72. self.drawsampleunitspage.SetNext(self.summarypage)
  73. self.moving.SetPrev(self.samplingareapage)
  74. self.moving.SetNext(self.summarypage)
  75. self.vectorareas.SetPrev(self.samplingareapage)
  76. self.vectorareas.SetNext(self.summarypage)
  77. self.summarypage.SetPrev(self.samplingareapage)
  78. # layout
  79. self.startpage.DoLayout()
  80. self.drawsampleframepage.DoLayout()
  81. self.keyboardpage.DoLayout()
  82. self.samplingareapage.DoLayout()
  83. self.summarypage.DoLayout()
  84. self.units.DoLayout()
  85. self.drawunits.DoLayout()
  86. self.drawsampleunitspage.DoLayout()
  87. self.regions.DoLayout()
  88. self.moving.DoLayout()
  89. self.vectorareas.DoLayout()
  90. self.wizard.FitToPage(self.startpage)
  91. # run_wizard
  92. if self.wizard.RunWizard(self.startpage):
  93. dlg = wx.MessageDialog(parent=self.parent,
  94. message=_("Do you want to create r.li "
  95. "configuration file <%s>?") % self.startpage.conf_name,
  96. caption=_("Create new r.li configuration file?"),
  97. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  98. if dlg.ShowModal() == wx.ID_NO:
  99. self._cleanup()
  100. else:
  101. self._write_confile()
  102. self._cleanup()
  103. dlg.Destroy()
  104. else:
  105. self.wizard.Destroy()
  106. GMessage(parent=self.parent,
  107. message=_("r.li.setup wizard canceled. "
  108. "Configuration file not created."))
  109. self._cleanup()
  110. def _write_confile(self):
  111. """Write the configuration file"""
  112. f = open(os.path.join(self.rlipath, self.startpage.conf_name), 'wb')
  113. self.rasterinfo = grast.raster_info(self.startpage.rast)
  114. self._write_region(f)
  115. self._write_area(f)
  116. f.close()
  117. def _temp_region(self):
  118. # save current settings:
  119. grass.use_temp_region()
  120. # Temporarily aligning region resolution to $RASTER resolution
  121. # keep boundary settings
  122. grass.run_command('g.region', raster=self.startpage.rast)
  123. self.gregion = grass.region()
  124. self.SF_NSRES = self.gregion['nsres']
  125. self.SF_EWRES = self.gregion['ewres']
  126. def _write_region(self, fil):
  127. """Write the region"""
  128. if self.startpage.region == 'whole':
  129. fil.write("SAMPLINGFRAME 0|0|1|1\n")
  130. self._temp_region()
  131. self.SF_X = 0.0
  132. self.SF_Y = 0.0
  133. self.SF_RL = abs(int(float(self.gregion['s'] - self.gregion['n'])
  134. / float(self.gregion['nsres'])))
  135. self.SF_CL = abs(int(float(self.gregion['e'] - self.gregion['w'])
  136. / float(self.gregion['ewres'])))
  137. self.SF_N = self.gregion['n']
  138. self.SF_S = self.gregion['s']
  139. self.SF_E = self.gregion['e']
  140. self.SF_W = self.gregion['w']
  141. self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
  142. self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
  143. self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
  144. self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
  145. elif self.startpage.region == 'key':
  146. self._temp_region()
  147. self.SF_X = float(self.keyboardpage.col_up)
  148. self.SF_Y = float(self.keyboardpage.row_up)
  149. self.SF_RL = float(self.keyboardpage.row_len)
  150. self.SF_CL = float(self.keyboardpage.col_len)
  151. self.SF_N = self.gregion['n'] - (self.SF_NSRES * self.SF_Y)
  152. self.SF_S = self.gregion['n'] - (self.SF_NSRES * self.SF_Y + self.SF_RL)
  153. self.SF_W = self.gregion['w'] + (self.SF_EWRES * self.SF_X)
  154. self.SF_E = self.gregion['w'] + (self.SF_EWRES * self.SF_X + self.SF_CL)
  155. self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
  156. self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
  157. self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
  158. self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
  159. fil.write("SAMPLINGFRAME %r|%r|%r|%r\n" % (self.per_x, self.per_y,
  160. self.per_rl,
  161. self.per_cl))
  162. elif self.startpage.region == 'draw':
  163. self._temp_region()
  164. tregion = self.drawsampleframepage.tregion
  165. # should we call this? with align param?
  166. RunCommand('g.region', align=self.startpage.rast, n=tregion['n'],
  167. s=tregion['s'], w=tregion['w'], e=tregion['e'])
  168. newreg = grass.region()
  169. self.SF_N = newreg['n'] # set env(SF_N) $n
  170. self.SF_S = newreg['s'] # set env(SF_S) $s
  171. self.SF_E = newreg['e'] # set env(SF_E) $e
  172. self.SF_W = newreg['w'] # set env(SF_W) $w
  173. self.SF_Y = abs(round(self.gregion['n'] - newreg['n']) / newreg['nsres'])
  174. # set env(SF_Y) [expr abs(round(($s_n - $n) / $nres)) ]
  175. self.SF_X = abs(round(self.gregion['w'] - newreg['w']) / newreg['ewres'])
  176. # set env(SF_X) [expr abs(round(($s_w - $w) / $sres)) ]
  177. self.SF_RL = abs(round(newreg['n'] - newreg['s']) / newreg['nsres'])
  178. # set env(SF_RL) [expr abs(round(($n - $s) / $nres)) ]
  179. self.SF_CL = abs(round(newreg['e'] - newreg['w']) / newreg['ewres'])
  180. # set env(SF_CL) [expr abs(round(($e - $w) / $sres)) ]
  181. self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
  182. # double($env(SF_X)) / double($cols)
  183. self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
  184. # double($env(SF_Y)) / double($rows)
  185. self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
  186. # double($env(SF_RL)) / double($rows)
  187. self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
  188. # double($env(SF_CL)) / double($cols)
  189. fil.write("SAMPLINGFRAME %r|%r|%r|%r\n" % (self.per_x, self.per_y,
  190. self.per_rl, self.per_cl))
  191. def _value_for_circle(self, radius):
  192. self.CIR_RL = round((2 * float(radius)) / float(self.rasterinfo['ewres']))
  193. self.CIR_CL = round((2 * float(radius)) / float(self.rasterinfo['nsres']))
  194. if not self.CIR_RL % 2:
  195. self.CIR_RL += 1
  196. if not self.CIR_CL % 2:
  197. self.CIR_CL += 1
  198. return
  199. def _circle(self, radius, mask):
  200. """Create a circle mask"""
  201. self._value_for_circle(radius)
  202. eastEdge = float(self.SF_W + (self.CIR_RL * self.SF_EWRES))
  203. southEdge = float(self.SF_N - (self.CIR_CL * self.SF_NSRES))
  204. grass.del_temp_region()
  205. grass.use_temp_region()
  206. grass.run_command('g.region', n=self.SF_N, s=southEdge, e=eastEdge,
  207. w=self.SF_W)
  208. xcenter = grass.region(complete=True)['center_easting']
  209. ycenter = grass.region(complete=True)['center_northing']
  210. grass.run_command('r.circle', flags='b', out=mask, max=radius,
  211. coordinate=[xcenter, ycenter], quiet=True)
  212. grass.del_temp_region()
  213. grass.use_temp_region()
  214. grass.run_command('g.region', raster=self.startpage.rast)
  215. def getSamplingType(self):
  216. """Obtain the sampling type"""
  217. devicetype = self.samplingareapage.regionbox
  218. samplingtype = self.samplingareapage.samplingtype
  219. shapetype = self.units.boxtype
  220. if samplingtype == SamplingType.UNITS:
  221. if devicetype == 'mouse':
  222. if shapetype == 'circle':
  223. samtype = SamplingType.MUNITSC
  224. else:
  225. samtype = SamplingType.MUNITSR
  226. elif devicetype == 'keyboard':
  227. if shapetype == 'circle':
  228. samtype = SamplingType.KUNITSC
  229. else:
  230. samtype = SamplingType.KUNITSR
  231. elif samplingtype == SamplingType.MVWIN:
  232. if devicetype == 'mouse':
  233. if shapetype == 'circle':
  234. samtype = SamplingType.MMVWINC
  235. else:
  236. samtype = SamplingType.MMVWINR
  237. elif devicetype == 'keyboard':
  238. if shapetype == 'circle':
  239. samtype = SamplingType.KMVWINC
  240. else:
  241. samtype = SamplingType.KMVWINR
  242. elif samplingtype == SamplingType.WHOLE:
  243. samtype = SamplingType.WHOLE
  244. elif samplingtype == SamplingType.REGIONS:
  245. samtype = SamplingType.REGIONS
  246. elif samplingtype == SamplingType.VECT:
  247. samtype = SamplingType.VECT
  248. else:
  249. samtype = samplingtype
  250. return samtype
  251. def _write_area(self, fil):
  252. """Write the area according the type"""
  253. samtype = self.getSamplingType()
  254. #sampling type is whole
  255. if samtype == SamplingType.WHOLE:
  256. cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
  257. rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
  258. #this two variable are unused, problably to remove
  259. x = float(self.SF_X) / float(self.rasterinfo['cols'])
  260. y = float(self.SF_Y) / float(self.rasterinfo['rows'])
  261. fil.write("SAMPLEAREA %r|%r|%r|%r\n" % (self.per_x, self.per_y,
  262. rl, cl))
  263. ##KMWINC = samplingtype=moving, regionbox=keyboard, shape=circle
  264. elif samtype == SamplingType.KMVWINC:
  265. self._circle(self.moving.width, self.moving.height)
  266. cl = float(self.CIR_CL) / float(self.rasterinfo['cols'])
  267. rl = float(self.CIR_RL) / float(self.rasterinfo['rows'])
  268. fil.write("MASKEDSAMPLEAREA -1|-1|%r|%r" % (rl, cl))
  269. fil.write("|%s" % self.moving.height)
  270. fil.write("\nMOVINGWINDOW\n")
  271. ##KMWINR = samplingtype moving, regionbox=keyboard, shape=rectangle
  272. elif samtype == SamplingType.KMVWINR:
  273. cl = float(self.moving.width) / float(self.rasterinfo['cols'])
  274. rl = float(self.moving.height) / float(self.rasterinfo['rows'])
  275. fil.write("SAMPLEAREA -1|-1|%r|%r" % (rl, cl))
  276. fil.write("\nMOVINGWINDOW\n")
  277. ##MMVWINR = samplingtype moving, regionbox=mouse, shape=rectangle
  278. elif samtype == SamplingType.MMVWINR:
  279. cl = float(self.msAreaList[0]['cols']) / float(self.rasterinfo['cols'])
  280. rl = float(self.msAreaList[0]['rows']) / float(self.rasterinfo['rows'])
  281. fil.write("SAMPLEAREA -1|-1|%r|%r" % (rl, cl))
  282. fil.write("\nMOVINGWINDOW\n")
  283. ##MMVWINR = samplingtype moving, regionbox=mouse, shape=circle
  284. elif samtype == SamplingType.MMVWINC:
  285. self._value_for_circle(self.msAreaList[0].radius)
  286. cl = float(self.CIR_CL) / float(self.rasterinfo['cols'])
  287. rl = float(self.CIR_RL) / float(self.rasterinfo['rows'])
  288. fil.write("SAMPLEAREA -1|-1|%r|%r" % (rl, cl))
  289. fil.write("|%s" % self.msAreaList[0].raster)
  290. fil.write("\nMOVINGWINDOW\n")
  291. ##KUNITSC = samplingtype=units, regionbox=keyboard, shape=cirlce
  292. ##KUNITSR = samplingtype=units, regionbox=keyboard, shape=rectangle
  293. elif samtype == SamplingType.KUNITSC or samtype == SamplingType.KUNITSR:
  294. if samtype == SamplingType.KUNITSC:
  295. self._circle(self.units.width, self.units.height)
  296. cl = float(self.CIR_CL) / float(self.rasterinfo['cols'])
  297. rl = float(self.CIR_RL) / float(self.rasterinfo['rows'])
  298. else:
  299. cl = float(self.moving.width) / float(self.rasterinfo['cols'])
  300. rl = float(self.moving.height) / float(self.rasterinfo['rows'])
  301. fil.write("SAMPLEAREA -1|-1|%r|%r\n" % (rl, cl))
  302. if self.units.distrtype == 'non_overlapping':
  303. fil.write("RANDOMNONOVERLAPPING %s\n" % self.units.distr1)
  304. elif self.units.distrtype == 'systematic_contiguos':
  305. fil.write("SYSTEMATICCONTIGUOUS\n")
  306. elif self.units.distrtype == 'stratified_random':
  307. fil.write("STRATIFIEDRANDOM %s|%s\n" % (self.units.distr1,
  308. self.units.distr2))
  309. elif self.units.distrtype == 'systematic_noncontiguos':
  310. fil.write("SYSTEMATICNONCONTIGUOUS %s\n" % self.units.distr1)
  311. elif self.units.distrtype == 'centered_oversites':
  312. fil.write("")
  313. #elif self.samplingareapage.samplingtype == SamplingType.UNITS and self.samplingareapage.regionbox=='mouse':
  314. ##MUNITSC = samplingtype=units, regionbox=mouse, shape=cirlce
  315. ##MUNITSR = samplingtype=units, regionbox=mouse, shape=rectangle
  316. elif self.samplingareapage.samplingtype in [SamplingType.MUNITSR,
  317. SamplingType.MUNITSC]:
  318. # get the raster region into rastregion
  319. grass.use_temp_region()
  320. grass.run_command('g.region', raster=self.startpage.rast)
  321. rastregion = grass.region()
  322. s_n = rastregion['n']
  323. s_w = rastregion['w']
  324. rows = float(self.rasterinfo['rows'])
  325. cols = float(self.rasterinfo['cols'])
  326. for tregion in self.msAreaList:
  327. if self.samplingareapage.samplingtype == SamplingType.MUNITSC:
  328. tregion = tregion.region
  329. abs_y = abs(round((float(s_n) - tregion['n']) / tregion['nsres']))
  330. abs_x = abs(round((float(s_w) - tregion['w']) / tregion['ewres']))
  331. abs_rl = abs(round((tregion['n'] - tregion['s']) / tregion['nsres']))
  332. abs_cl = abs(round((tregion['e'] - tregion['w']) / tregion['ewres']))
  333. x = float(abs_x) / float(cols)
  334. y = float(abs_y) / float(rows)
  335. rl = float(abs_rl) / float(rows)
  336. cl = float(abs_cl) / float(cols)
  337. sarea = str(x) + "|" + str(y) + "|" + str(rl) + "|" + str(cl)
  338. if self.samplingareapage.samplingtype == SamplingType.MUNITSR:
  339. fil.write("SQUAREAREA %s\n" % sarea)
  340. elif self.samplingareapage.samplingtype == SamplingType.MUNITSC:
  341. fil.write("MASKEDSAMPLEAREA %s" % sarea)
  342. fil.write("|%s\n" % self.msAreaList[0].raster)
  343. elif self.samplingareapage.samplingtype == SamplingType.REGIONS:
  344. rows = float(self.rasterinfo['rows'])
  345. cols = float(self.rasterinfo['cols'])
  346. for marea in self.msAreaList:
  347. gregion = marea.region
  348. abs_y = self.SF_Y + abs(round((self.SF_N - gregion['n']) / self.SF_NSRES))
  349. abs_x = self.SF_X + abs(round((self.SF_W - gregion['w']) / self.SF_EWRES))
  350. abs_rl = abs(round(gregion['n'] - gregion['s']) / self.SF_NSRES)
  351. abs_cl = abs(round(gregion['e'] - gregion['w']) / self.SF_EWRES)
  352. x = float(abs_x) / float(cols)
  353. y = float(abs_y) / float(rows)
  354. rl = float(abs_rl) / float(rows)
  355. cl = float(abs_cl) / float(cols)
  356. maskArea = str(x) + "|" + str(y) + "|" + str(rl) + "|" + str(cl) + "|" + marea.raster
  357. fil.write("SQUAREAREA %s\n" % maskArea)
  358. elif self.samplingareapage.samplingtype == SamplingType.VECT:
  359. for marea in self.msAreaList:
  360. fil.write(marea)
  361. fil.write("RASTERMAP {name}\n".format(name=self.startpage.rast))
  362. fil.write("VECTORMAP {name}\n".format(name=self.startpage.vect))
  363. def _cleanup(self):
  364. """Clean all the variables to save into configuration file"""
  365. self.startpage.conf_name = ''
  366. self.startpage.rast = ''
  367. self.startpage.vect = ''
  368. self.startpage.region = 'whole'
  369. self.keyboardpage.col_len = ''
  370. self.keyboardpage.col_up = ''
  371. self.keyboardpage.row_len = ''
  372. self.keyboardpage.row_up = ''
  373. self.samplingareapage.samplingtype = 'whole'
  374. self.units.width = ''
  375. self.units.height = ''
  376. self.units.boxtype = ''
  377. self.regions.numregions = 0
  378. self.moving.width = ''
  379. self.moving.height = ''
  380. self.moving.boxtype = ''
  381. class FirstPage(TitledPage):
  382. """
  383. !Set name of configuration file, choose raster and optionally vector/sites
  384. """
  385. def __init__(self, wizard, parent):
  386. TitledPage.__init__(self, wizard, _("Select maps and define name"))
  387. self.region = 'whole'
  388. self.rast = ''
  389. self.conf_name = ''
  390. self.vect = ''
  391. self.VectorEnabled = True
  392. self.parent = parent
  393. #name of output configuration file
  394. self.newconflabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  395. label=_('Name for new configuration file to create'))
  396. self.newconftxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  397. size=(250, -1))
  398. wx.CallAfter(self.newconftxt.SetFocus)
  399. self.sizer.Add(item=self.newconflabel, border=5, pos=(0, 0),
  400. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  401. self.sizer.Add(item=self.newconftxt, border=5, pos=(0, 1),
  402. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  403. #raster
  404. self.mapsellabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  405. label=_('Raster map to use to select areas'))
  406. self.mapselect = gselect.Select(parent=self, id=wx.ID_ANY,
  407. size=(250, -1), type='cell',
  408. multiple=False)
  409. self.sizer.Add(item=self.mapsellabel, border=5, pos=(1, 0),
  410. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  411. self.sizer.Add(item=self.mapselect, border=5, pos=(1, 1),
  412. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  413. #vector
  414. self.vectsellabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  415. label=_('Vector map to use to select areas'))
  416. self.vectselect = gselect.Select(parent=self, id=wx.ID_ANY,
  417. size=(250, -1), type='vector',
  418. multiple=False)
  419. self.sizer.Add(item=self.vectsellabel, border=5, pos=(2, 0),
  420. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  421. self.sizer.Add(item=self.vectselect, border=5, pos=(2, 1),
  422. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  423. #vector layer
  424. self.vectlaylabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  425. label=_('Vector map layer to use to select areas'))
  426. self.vectlayer = wx.ComboBox(parent = self, id = wx.ID_ANY,
  427. size=(250, -1))
  428. self.sizer.Add(item=self.vectlaylabel, border=5, pos=(3, 0),
  429. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  430. self.sizer.Add(item=self.vectlayer, border=5, pos=(3, 1),
  431. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  432. #define sampling region
  433. self.sampling_reg = wx.RadioBox(parent=self, id=wx.ID_ANY,
  434. label=" %s " % _("Define sampling "
  435. "region (region for analysis)"),
  436. choices=[_('Whole map layer'),
  437. _('Keyboard setting'),
  438. _('Draw the sampling frame')],
  439. majorDimension=1,
  440. style=wx.RA_SPECIFY_ROWS)
  441. self.sizer.Add(item=self.sampling_reg,
  442. flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
  443. pos=(5, 0), span=(1, 2))
  444. self.infoError = wx.StaticText(self, label='')
  445. self.infoError.SetForegroundColour(wx.RED)
  446. self.sizer.Add(item=self.infoError,
  447. flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
  448. pos=(6, 0), span=(1, 2))
  449. #bindings
  450. self.sampling_reg.Bind(wx.EVT_RADIOBOX, self.OnSampling)
  451. self.newconftxt.Bind(wx.EVT_KILL_FOCUS, self.OnName)
  452. self.newconftxt.Bind(wx.EVT_TEXT, self.OnNameChanged)
  453. self.vectselect.Bind(wx.EVT_TEXT, self.OnVector)
  454. self.mapselect.Bind(wx.EVT_TEXT, self.OnRast)
  455. self.vectlayer.Bind(wx.EVT_TEXT, self.OnLayer)
  456. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  457. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  458. wx.CallAfter(wx.FindWindowById(wx.ID_FORWARD).Enable, False)
  459. def OnSampling(self, event):
  460. """Change region type"""
  461. if event.GetInt() == 0:
  462. self.region = 'whole'
  463. self.SetNext(self.parent.samplingareapage)
  464. elif event.GetInt() == 1:
  465. self.region = 'key'
  466. self.SetNext(self.parent.keyboardpage)
  467. elif event.GetInt() == 2: # currently disabled
  468. self.region = 'draw'
  469. self.SetNext(self.parent.drawsampleframepage)
  470. def OnName(self, event):
  471. """Sets the name of configuration file"""
  472. if self.conf_name in self.parent.parent.listfiles:
  473. GMessage(parent=self, message=_("The configuration file %s "
  474. "already exists, please change name") % self.conf_name)
  475. self.newconftxt.SetValue('')
  476. self.conf_name = ''
  477. def OnNameChanged(self, event):
  478. """Name of configuration file has changed"""
  479. self.conf_name = self.newconftxt.GetValue()
  480. next = wx.FindWindowById(wx.ID_FORWARD)
  481. next.Enable(self.CheckInput())
  482. def OnRast(self, event):
  483. """Sets raster map"""
  484. self.rast = self.mapselect.GetValue()
  485. next = wx.FindWindowById(wx.ID_FORWARD)
  486. next.Enable(self.CheckInput())
  487. def OnVector(self, event):
  488. """Sets vector map"""
  489. self.vect = self.vectselect.GetValue()
  490. if self.vect:
  491. self.VectorEnabled, layers = self.CheckVector(self.vect)
  492. if self.VectorEnabled:
  493. self.vectlayer.SetItems(layers)
  494. self.vectlayer.SetSelection(0)
  495. self.vectorlayer = self.vectlayer.GetValue()
  496. self.infoError.SetLabel('')
  497. else:
  498. self.vectlayer.Clear()
  499. self.vectlayer.SetValue('')
  500. self.vect = ''
  501. else:
  502. self.infoError.SetLabel('')
  503. self.vectlayer.Clear()
  504. self.vectlayer.SetValue('')
  505. next = wx.FindWindowById(wx.ID_FORWARD)
  506. next.Enable(self.CheckInput())
  507. def OnLayer(self, event):
  508. try:
  509. self.vectorlayer = self.vectlayer.GetValue()
  510. except:
  511. self.vectorlayer = None
  512. next = wx.FindWindowById(wx.ID_FORWARD)
  513. next.Enable(self.CheckInput())
  514. def OnEnterPage(self, event):
  515. """Sets the default values, for the entire map
  516. """
  517. next = wx.FindWindowById(wx.ID_FORWARD)
  518. next.Enable(self.CheckInput())
  519. wx.CallAfter(wx.FindWindowById(wx.ID_FORWARD).Enable,
  520. self.CheckInput())
  521. def CheckVector(self, vector):
  522. """Check if the type of vector is area and return the number of
  523. vector's layer"""
  524. try:
  525. areas = gvect.vector_info_topo(vector)['areas']
  526. except CalledModuleError:
  527. self.infoError.SetLabel(_("Vector %s was not found, please "
  528. "select another vector") % vector)
  529. return False, []
  530. if areas == 0:
  531. self.infoError.SetLabel(_("Vector %s has no areas, please "
  532. "select another vector") % vector)
  533. return False, []
  534. links = gvect.vector_info(vector)['num_dblinks']
  535. if links == 0:
  536. self.infoError.SetLabel(_("Vector %s has no table connected, "
  537. "please select another vector") % vector)
  538. return False, []
  539. elif links > 0:
  540. layers = []
  541. for i in range(1, links + 1):
  542. layers.append(str(i))
  543. return True, layers
  544. else:
  545. return False, []
  546. def CheckInput(self):
  547. """Check input fields.
  548. :return: True if configuration file is given and raster xor vector map,
  549. False otherwise
  550. """
  551. return bool(self.conf_name and bool(self.rast and
  552. bool(self.VectorEnabled)))
  553. def OnExitPage(self, event=None):
  554. """Function during exiting"""
  555. next = wx.FindWindowById(wx.ID_FORWARD)
  556. next.Enable(self.CheckInput())
  557. if event.GetDirection():
  558. if self.region == 'key':
  559. self.SetNext(self.parent.keyboardpage)
  560. self.parent.samplingareapage.SetPrev(self.parent.keyboardpage)
  561. elif self.region == 'whole':
  562. self.SetNext(self.parent.samplingareapage)
  563. self.parent.samplingareapage.SetPrev(self)
  564. elif self.region == 'draw':
  565. self.SetNext(self.parent.drawsampleframepage)
  566. self.parent.samplingareapage.SetPrev(self.parent.drawsampleframepage)
  567. return
  568. class KeyboardPage(TitledPage):
  569. """
  570. !Choose the region setting the values of border using the keyboard
  571. """
  572. def __init__(self, wizard, parent):
  573. TitledPage.__init__(self, wizard, _("Insert sampling frame parameter"))
  574. self.parent = parent
  575. self.col_len = ''
  576. self.row_len = ''
  577. self.col_up = '0'
  578. self.row_up = '0'
  579. #column up/left
  580. self.ColUpLeftlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  581. label=_("Column of upper left "
  582. "corner"))
  583. self.ColUpLefttxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  584. size=(250, -1))
  585. wx.CallAfter(self.ColUpLeftlabel.SetFocus)
  586. self.sizer.Add(item=self.ColUpLeftlabel, border=5, pos=(1, 1),
  587. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  588. self.sizer.Add(item=self.ColUpLefttxt, border=5, pos=(1, 2),
  589. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  590. self.sizer.AddGrowableCol(2)
  591. #row up/left
  592. self.RowUpLeftlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  593. label=_('Row of upper left corner'))
  594. self.RowUpLefttxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  595. size=(250, -1))
  596. wx.CallAfter(self.RowUpLeftlabel.SetFocus)
  597. self.sizer.Add(item=self.RowUpLeftlabel, border=5, pos=(2, 1),
  598. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  599. self.sizer.Add(item=self.RowUpLefttxt, border=5, pos=(2, 2),
  600. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  601. #row lenght
  602. self.RowLenlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  603. label=_('Row lenght of sampling frame'))
  604. self.RowLentxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  605. wx.CallAfter(self.RowLenlabel.SetFocus)
  606. self.sizer.Add(item=self.RowLenlabel, border=5, pos=(3, 1),
  607. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  608. self.sizer.Add(item=self.RowLentxt, border=5, pos=(3, 2),
  609. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  610. #column lenght
  611. self.ColLenlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  612. label=_('Row lenght of sampling frame'))
  613. self.ColLentxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  614. wx.CallAfter(self.ColLenlabel.SetFocus)
  615. self.sizer.Add(item=self.ColLenlabel, border=5, pos=(4, 1),
  616. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  617. self.sizer.Add(item=self.ColLentxt, border=5, pos=(4, 2),
  618. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  619. self.ColUpLefttxt.SetValue(self.col_up)
  620. self.RowUpLefttxt.SetValue(self.row_up)
  621. self.ColUpLefttxt.Bind(wx.EVT_KILL_FOCUS, self.OnColLeft)
  622. self.RowUpLefttxt.Bind(wx.EVT_KILL_FOCUS, self.OnRowLeft)
  623. self.ColLentxt.Bind(wx.EVT_KILL_FOCUS, self.OnColLen)
  624. self.RowLentxt.Bind(wx.EVT_KILL_FOCUS, self.OnRowLen)
  625. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  626. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  627. def OnColLeft(self, event):
  628. """Sets the name of configuration file"""
  629. self.col_up = self.ColUpLefttxt.GetValue()
  630. checkValue(self.col_up)
  631. def OnRowLeft(self, event):
  632. """Sets the name of configuration file"""
  633. self.row_up = self.RowUpLefttxt.GetValue()
  634. checkValue(self.row_up)
  635. def OnColLen(self, event):
  636. """Sets the name of configuration file"""
  637. self.col_len = self.ColLentxt.GetValue()
  638. checkValue(self.col_len)
  639. def OnRowLen(self, event):
  640. """Sets the name of configuration file"""
  641. self.row_len = self.RowLentxt.GetValue()
  642. checkValue(self.row_len)
  643. def OnEnterPage(self, event):
  644. """Sets the default values, for the entire map
  645. """
  646. #R# check if raster exists before anything
  647. if self.col_len == '' and self.row_len == '':
  648. rastinfo = grast.raster_info(self.parent.startpage.rast)
  649. self.col_len = rastinfo['cols']
  650. self.row_len = rastinfo['rows']
  651. self.ColLentxt.SetValue(self.col_len)
  652. self.RowLentxt.SetValue(self.row_len)
  653. def OnExitPage(self, event=None):
  654. """Function during exiting"""
  655. if self.row_len == '' or self.col_len == '' or self.row_up == '' or self.col_up == '':
  656. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  657. else:
  658. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  659. class DrawSampleFramePage(TitledPage):
  660. """Choose the region setting the values drawing a box"""
  661. def __init__(self, wizard, parent):
  662. TitledPage.__init__(self, wizard, _("Draw sampling frame"))
  663. self.parent = parent
  664. self.mapPanel = None
  665. self.tregion = None
  666. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  667. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  668. def SampleFrameChanged(self, region):
  669. """"Enables the next dialog when region is set"""
  670. if region:
  671. self.tregion = region
  672. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  673. else:
  674. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  675. def OnEnterPage(self, event):
  676. """Function during entering"""
  677. if self.mapPanel is None:
  678. self.mapPanel = RLiSetupMapPanel(self, samplingType='drawFrame')
  679. self.mapPanel.sampleFrameChanged.connect(self.SampleFrameChanged)
  680. self.sizer.Add(item=self.mapPanel, flag=wx.EXPAND, pos=(0, 0))
  681. self.sizer.AddGrowableCol(0)
  682. self.sizer.AddGrowableRow(0)
  683. self._raster = None
  684. else:
  685. self.mapPanel._region = {}
  686. self.SampleFrameChanged(region=None)
  687. rast = self.parent.startpage.rast
  688. if self._raster != rast:
  689. map_ = self.mapPanel.GetMap()
  690. map_.DeleteAllLayers()
  691. cmdlist = ['d.rast', 'map=%s' % rast]
  692. map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  693. name=rast, hidden=False, opacity=1.0, render=True)
  694. def OnExitPage(self, event=None):
  695. """Function during exiting"""
  696. if event.GetDirection():
  697. self.SetNext(self.parent.samplingareapage)
  698. self.parent.samplingareapage.SetPrev(self)
  699. else:
  700. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  701. class SamplingAreasPage(TitledPage):
  702. """
  703. Set name of configuration file, choose raster and optionally vector/sites.
  704. This is coming after choose the region
  705. """
  706. def __init__(self, wizard, parent):
  707. TitledPage.__init__(self, wizard, _("Insert sampling areas"))
  708. self.samplingtype = 'whole'
  709. self.parent = parent
  710. self.overwriteTemp = False
  711. # toggles
  712. self.radioBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  713. label="",
  714. choices=[_("Whole map layer"),
  715. _("Regions"),
  716. _("Sample units"),
  717. _("Moving window"),
  718. _("Select areas from the\n"
  719. "overlayed vector map")],
  720. majorDimension=1,
  721. style=wx.RA_SPECIFY_COLS | wx.NO_BORDER)
  722. # layout
  723. self.sizer.SetVGap(10)
  724. self.sizer.Add(item=self.radioBox, flag=wx.ALIGN_LEFT, pos=(0, 0))
  725. self.regionBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  726. label=_("Choose a method"),
  727. choices=[_('Use keyboard to enter sampling area'),
  728. _('Use mouse to draw sampling area')],
  729. majorDimension=1,
  730. style=wx.RA_SPECIFY_ROWS)
  731. #self.regionBox.EnableItem(1, False)
  732. self.regionBox.SetItemToolTip(1, _("This option is not supported yet"))
  733. self.sizer.Add(self.regionBox, flag=wx.ALIGN_CENTER, pos=(1, 0))
  734. # bindings
  735. self.radioBox.Bind(wx.EVT_RADIOBOX, self.SetVal)
  736. self.regionBox.Bind(wx.EVT_RADIOBOX, self.OnRegionDraw)
  737. self.regionbox = 'keyboard'
  738. self.regionPanelSizer = wx.GridBagSizer(1, 2)
  739. self.regionNumPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  740. self.regionNumLabel = wx.StaticText(parent=self.regionNumPanel,
  741. id=wx.ID_ANY,
  742. label=_('Number of regions to draw:'))
  743. self.regionNumTxt = wx.TextCtrl(parent=self.regionNumPanel,
  744. id=wx.ID_ANY, size=(50, -1))
  745. self.regionPanelSizer.Add(self.regionNumLabel, flag=wx.ALIGN_CENTER,
  746. pos=(0, 0))
  747. self.regionPanelSizer.Add(self.regionNumTxt, flag=wx.ALIGN_CENTER,
  748. pos=(0, 1))
  749. self.regionNumPanel.SetSizer(self.regionPanelSizer)
  750. self.sizer.Add(self.regionNumPanel, flag=wx.ALIGN_CENTER, pos=(2, 0))
  751. self.areaPanelSizer = wx.GridBagSizer(2, 3)
  752. self.areaPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  753. self.overwriteText = wx.StaticText(parent=self.areaPanel, id=wx.ID_ANY,
  754. label=_('Do you want to overwrite existing'
  755. ' temporal maps if they exist?'))
  756. self.overwriteCheck = wx.CheckBox(parent=self.areaPanel, id=wx.ID_ANY)
  757. self.areaText = wx.StaticText(parent=self.areaPanel, id=wx.ID_ANY,
  758. label=_('Do you want to check vector areas?'))
  759. self.areaOK = wx.Button(self.areaPanel, wx.ID_ANY, 'Yes', (50, 80))
  760. self.areaOK.SetToolTip(wx.ToolTip(_("Select if use area by area")))
  761. self.areaNO = wx.Button(self.areaPanel, wx.ID_ANY, 'No', (50, 80))
  762. self.areaNO.SetToolTip(wx.ToolTip(_("All the features will be used")))
  763. self.areaOK.Bind(wx.EVT_BUTTON, self.OnVectYes)
  764. self.areaNO.Bind(wx.EVT_BUTTON, self.OnVectNo)
  765. self.overwriteCheck.Bind(wx.EVT_CHECKBOX, self.OnOverwrite)
  766. self.areaPanelSizer.Add(self.overwriteText, flag=wx.ALIGN_CENTER,
  767. pos=(0, 0))
  768. self.areaPanelSizer.Add(self.overwriteCheck, flag=wx.ALIGN_CENTER,
  769. pos=(0, 1))
  770. self.areaPanelSizer.Add(self.areaText, flag=wx.ALIGN_CENTER,
  771. pos=(1, 0))
  772. self.areaPanelSizer.Add(self.areaOK, flag=wx.ALIGN_CENTER, pos=(1, 1))
  773. self.areaPanelSizer.Add(self.areaNO, flag=wx.ALIGN_CENTER, pos=(1, 2))
  774. self.areaPanel.SetSizer(self.areaPanelSizer)
  775. self.sizer.Add(self.areaPanel, flag=wx.ALIGN_CENTER, pos=(3, 0))
  776. self.calculatingAreas = wx.StaticText(parent=self, id=wx.ID_ANY,
  777. label=_('Analysing all vector features...'))
  778. self.sizer.Add(self.calculatingAreas, flag=wx.ALIGN_CENTER, pos=(4, 0))
  779. self.numregions = ''
  780. self.regionNumTxt.Bind(wx.EVT_TEXT, self.OnNumRegions)
  781. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  782. def OnNumRegions(self, event):
  783. """Obtain the number of regions"""
  784. if self.regionNumTxt.GetValue():
  785. self.SetNext(self.parent.regions)
  786. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  787. self.numregions = self.regionNumTxt.GetValue()
  788. else:
  789. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  790. def OnEnterPage(self, event):
  791. """Insert values into text controls for summary of location
  792. creation options
  793. """
  794. self.SetVal(None)
  795. if self.parent.startpage.vect:
  796. self.radioBox.ShowItem(4, True)
  797. self.vect_data = []
  798. else:
  799. self.radioBox.ShowItem(4, False)
  800. self.sizer.Layout()
  801. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  802. def SetVal(self, event):
  803. """Choose method"""
  804. radio = self.radioBox.GetSelection()
  805. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  806. if radio == 0:
  807. self.samplingtype = SamplingType.WHOLE
  808. self.DrawNothing()
  809. elif radio == 1:
  810. self.samplingtype = SamplingType.REGIONS
  811. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  812. elif radio == 2:
  813. self.samplingtype = SamplingType.UNITS
  814. regtype = self.regionBox.GetSelection()
  815. self.RegionDraw(regtype)
  816. elif radio == 3:
  817. self.samplingtype = SamplingType.MVWIN
  818. regtype = self.regionBox.GetSelection()
  819. self.RegionDraw(regtype)
  820. elif radio == 4:
  821. self.samplingtype = SamplingType.VECT
  822. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  823. self.ShowExtraOptions(self.samplingtype)
  824. def ShowExtraOptions(self, samtype):
  825. """Show some extra options for some sampling type"""
  826. if samtype == SamplingType.REGIONS:
  827. self.sizer.Hide(self.regionBox)
  828. self.sizer.Hide(self.areaPanel)
  829. self.sizer.Hide(self.calculatingAreas)
  830. self.sizer.Show(self.regionNumPanel)
  831. elif samtype == SamplingType.UNITS or samtype == SamplingType.MVWIN:
  832. self.sizer.Hide(self.regionNumPanel)
  833. self.sizer.Hide(self.areaPanel)
  834. self.sizer.Hide(self.calculatingAreas)
  835. self.sizer.Show(self.regionBox)
  836. elif samtype == SamplingType.VECT:
  837. self.sizer.Hide(self.regionBox)
  838. self.sizer.Hide(self.regionNumPanel)
  839. self.sizer.Hide(self.calculatingAreas)
  840. self.sizer.Show(self.areaPanel)
  841. self.sizer.Layout()
  842. def OnRegionDraw(self, event):
  843. self.RegionDraw(event.GetInt())
  844. return
  845. def OnOverwrite(self, event):
  846. self.overwriteTemp = self.overwriteCheck.GetValue()
  847. return
  848. def OnVectYes(self, event):
  849. """The user choose to select the vector areas, this function set the
  850. next page to VectorAreasPage"""
  851. self.SetNext(self.parent.vectorareas)
  852. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  853. self.parent.wizard.ShowPage(self.parent.vectorareas)
  854. def OnVectNo(self, event):
  855. """The user choose to use all the vector areas, this function analyses
  856. all the vector areas and fill the msAreaList variable"""
  857. self.sizer.Show(self.calculatingAreas)
  858. self.sizer.Hide(self.regionNumPanel)
  859. self.sizer.Hide(self.regionBox)
  860. self.sizer.Hide(self.areaPanel)
  861. self.SetNext(self.parent.summarypage)
  862. vect_cats = obtainCategories(self.parent.startpage.vect,
  863. self.parent.startpage.vectorlayer)
  864. self._progressDlg = wx.ProgressDialog(title=_("Analysing vector"),
  865. message="Analysing vector",
  866. maximum=len(vect_cats),
  867. parent=self,
  868. style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL |
  869. wx.PD_AUTO_HIDE | wx.PD_SMOOTH)
  870. self._progressDlgMax = len(vect_cats)
  871. grass.use_temp_region()
  872. self.parent.msAreaList = sampleAreaVector(self.parent.startpage.vect,
  873. self.parent.startpage.rast,
  874. vect_cats,
  875. self.parent.startpage.vectorlayer,
  876. self.overwriteTemp,
  877. self._progressDlg)
  878. grass.del_temp_region()
  879. if self.parent.msAreaList:
  880. self.calculatingAreas.SetLabel(_("All feature are been analyzed."))
  881. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  882. self.parent.wizard.ShowPage(self.parent.summarypage)
  883. else:
  884. self.calculatingAreas.SetLabel(_("An error occurred"))
  885. self._progressDlg.Destroy()
  886. self._progressDlg = None
  887. def RegionDraw(self, regtype):
  888. """Set the next page to units or drawunits"""
  889. if regtype == 0:
  890. self.regionbox = 'keyboard'
  891. if self.samplingtype == SamplingType.UNITS:
  892. self.SetNext(self.parent.units)
  893. elif self.samplingtype == SamplingType.MVWIN:
  894. self.SetNext(self.parent.moving)
  895. elif regtype == 1:
  896. self.regionbox = 'mouse'
  897. self.SetNext(self.parent.drawunits)
  898. def DrawNothing(self):
  899. """Remove all the optional choices. Used also when the wizard enter in
  900. SamplingAreasPage, all the optional choices should be hide here"""
  901. self.sizer.Hide(self.regionNumPanel)
  902. self.sizer.Hide(self.regionBox)
  903. self.sizer.Hide(self.areaPanel)
  904. self.sizer.Hide(self.calculatingAreas)
  905. self.sizer.Layout()
  906. self.SetNext(self.parent.summarypage)
  907. class DrawRegionsPage(TitledPage):
  908. def __init__(self, wizard, parent):
  909. self.parent = parent
  910. TitledPage.__init__(self, wizard, _("Draw sampling regions"))
  911. self.regioncount = 0
  912. self.mapPanel = None
  913. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  914. #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  915. def afterRegionDrawn(self, marea):
  916. if marea:
  917. self.parent.msAreaList.append(marea)
  918. self.regioncount = self.regioncount + 1
  919. numregions = int(self.parent.samplingareapage.numregions)
  920. if self.regioncount > numregions:
  921. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  922. self.parent.wizard.ShowPage(self.parent.summarypage)
  923. else:
  924. self.title.SetLabel(_('Draw sample region ' +
  925. str(self.regioncount) + ' of ' +
  926. str(numregions)))
  927. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  928. def OnEnterPage(self, event):
  929. """Function during entering"""
  930. if self.parent.samplingareapage.samplingtype == SamplingType.WHOLE:
  931. self.title.SetLabel(_("Draw moving windows region"))
  932. elif self.parent.samplingareapage.samplingtype == SamplingType.UNITS:
  933. self.title.SetLabel(_("Draw sampling region"))
  934. if self.mapPanel is None:
  935. self.mapPanel = RLiSetupMapPanel(self,
  936. samplingType=self.parent.samplingareapage.samplingtype,
  937. )
  938. self.mapPanel.afterRegionDrawn.connect(self.afterRegionDrawn)
  939. self.sizer.Add(item=self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
  940. self.sizer.AddGrowableCol(0)
  941. self.sizer.AddGrowableRow(1)
  942. self._raster = None
  943. rast = self.parent.startpage.rast
  944. self.afterRegionDrawn(marea=None)
  945. if self._raster != rast:
  946. map_ = self.mapPanel.GetMap()
  947. map_.DeleteAllLayers()
  948. cmdlist = ['d.rast', 'map=%s' % rast]
  949. map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  950. name=rast, hidden=False, opacity=1.0, render=True)
  951. #def OnExitPage(self, event=None):
  952. #!Function during exiting
  953. #print event.GetDirection()
  954. #if event.GetDirection():
  955. # self.SetNext(self.parent.samplingareapage)
  956. # self.parent.samplingareapage.SetPrev(self)
  957. class SampleUnitsKeyPage(TitledPage):
  958. """Set values from keyboard for sample units
  959. It is used if you choose keyboard from Sampling Units or Moving windows
  960. in sampling areas page
  961. """
  962. def __init__(self, wizard, parent):
  963. TitledPage.__init__(self, wizard, _("Select sample units from keyboard"))
  964. self.parent = parent
  965. self.scrollPanel = scrolled.ScrolledPanel(parent=self, id=wx.ID_ANY)
  966. self.scrollPanel.SetupScrolling(scroll_x=False)
  967. self.panelSizer = wx.GridBagSizer(5, 5)
  968. self.width = ''
  969. self.height = ''
  970. self.boxtype = 'rectangle'
  971. self.distrtype = 'non_overlapping'
  972. # type of shape
  973. self.typeBox = wx.RadioBox(parent=self.scrollPanel, id=wx.ID_ANY,
  974. majorDimension=1, style=wx.RA_SPECIFY_COLS,
  975. label=" %s " % _("Select type of shape"),
  976. choices=[_('Rectangle'), _('Circle'),
  977. ('None')])
  978. self.panelSizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(0, 0),
  979. span=(1, 2))
  980. self.widthLabel = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
  981. self.widthTxt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  982. size=(250, -1))
  983. self.panelSizer.Add(item=self.widthLabel, pos=(1, 0),
  984. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  985. self.panelSizer.Add(item=self.widthTxt, pos=(1, 1),
  986. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  987. self.heightLabel = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
  988. self.heightTxt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  989. size=(250, -1))
  990. self.panelSizer.Add(item=self.heightLabel, pos=(2, 0),
  991. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  992. self.panelSizer.Add(item=self.heightTxt, pos=(2, 1),
  993. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  994. self.widthLabels = [_('Width size (in cells)? '),
  995. _('What radius size (in meters)? ')]
  996. self.heightLabels = [_('Height size (in cells)? '),
  997. _('Name of the circle mask')]
  998. self.distributionBox = wx.RadioBox(parent=self.scrollPanel,
  999. id=wx.ID_ANY,
  1000. majorDimension=1,
  1001. style=wx.RA_SPECIFY_COLS,
  1002. label= " %s " % _("Select method of sampling unit distribution"),
  1003. choices=[_('Random non overlapping'),
  1004. _('Systematic contiguos'),
  1005. _('Stratified random'),
  1006. _('Systematic non contiguos'),
  1007. _('Centered over sites')]
  1008. )
  1009. self.panelSizer.Add(item=self.distributionBox, pos=(3, 0), span=(1, 2),
  1010. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1011. self.distr1Label = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
  1012. label=_("What number of Sampling "
  1013. "Units to use?"))
  1014. self.distr1Txt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  1015. size=(250, -1))
  1016. self.panelSizer.Add(item=self.distr1Label, pos=(4, 0),
  1017. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1018. self.panelSizer.Add(item=self.distr1Txt, pos=(4, 1),
  1019. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1020. self.distr2Label = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
  1021. label="")
  1022. self.distr2Txt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  1023. size=(250, -1))
  1024. self.panelSizer.Add(item=self.distr2Label, pos=(5, 0),
  1025. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1026. self.panelSizer.Add(item=self.distr2Txt, pos=(5, 1),
  1027. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1028. self.panelSizer.Hide(self.distr2Txt)
  1029. self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
  1030. self.distributionBox.Bind(wx.EVT_RADIOBOX, self.OnDistr)
  1031. self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
  1032. self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
  1033. self.distr1Txt.Bind(wx.EVT_TEXT, self.OnDistr1)
  1034. self.distr2Txt.Bind(wx.EVT_TEXT, self.OnDistr2)
  1035. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1036. self.sizer.Add(item=self.scrollPanel, pos=(0, 0), flag=wx.EXPAND)
  1037. self.sizer.AddGrowableCol(0)
  1038. self.sizer.AddGrowableRow(0)
  1039. self.scrollPanel.SetSizer(self.panelSizer)
  1040. #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  1041. self.OnType(None)
  1042. def OnEnterPage(self, event=None):
  1043. """Function during entering"""
  1044. # This is an hack to force the user to choose Rectangle or Circle
  1045. self.typeBox.SetSelection(2),
  1046. self.typeBox.ShowItem(2, False)
  1047. self.panelSizer.Layout()
  1048. def OnExitPage(self, event=None):
  1049. """Function during exiting"""
  1050. if event.GetDirection():
  1051. self.SetNext(self.parent.summarypage)
  1052. self.SetPrev(self.parent.samplingareapage)
  1053. def OnType(self, event):
  1054. """Set if rectangle or circle will be used"""
  1055. chosen = self.typeBox.GetSelection()
  1056. self.widthLabel.SetLabel(self.widthLabels[chosen])
  1057. self.heightLabel.SetLabel(self.heightLabels[chosen])
  1058. self.panelSizer.Layout()
  1059. if chosen == 0:
  1060. self.boxtype = 'rectangle'
  1061. else:
  1062. self.boxtype = 'circle'
  1063. def OnDistr(self, event):
  1064. chosen = self.distributionBox.GetSelection()
  1065. if chosen == 0:
  1066. self.distrtype = 'non_overlapping'
  1067. self.distr1Label.SetLabel(_("What number of Sampling Units to use?"))
  1068. self.panelSizer.Show(self.distr1Txt)
  1069. self.distr2Label.SetLabel("")
  1070. self.panelSizer.Hide(self.distr2Txt)
  1071. self.panelSizer.Layout()
  1072. elif chosen == 1:
  1073. self.distrtype = 'systematic_contiguos'
  1074. self.distr1Label.SetLabel("")
  1075. self.distr2Label.SetLabel("")
  1076. self.panelSizer.Hide(self.distr1Txt)
  1077. self.panelSizer.Hide(self.distr2Txt)
  1078. self.panelSizer.Layout()
  1079. elif chosen == 2:
  1080. self.distrtype = 'stratified_random'
  1081. self.distr1Label.SetLabel(_("Insert number of row strates"))
  1082. self.distr2Label.SetLabel(_("Insert number of column strates"))
  1083. self.panelSizer.Show(self.distr1Txt)
  1084. self.panelSizer.Show(self.distr2Txt)
  1085. self.panelSizer.Layout()
  1086. elif chosen == 3:
  1087. self.distrtype = 'systematic_noncontiguos'
  1088. self.distr1Label.SetLabel(_("Insert distance between units"))
  1089. self.panelSizer.Show(self.distr1Txt)
  1090. self.distr2Label.SetLabel("")
  1091. self.panelSizer.Hide(self.distr2Txt)
  1092. self.panelSizer.Layout()
  1093. elif chosen == 4:
  1094. self.distrtype = 'centered_oversites'
  1095. self.distr1Label.SetLabel("")
  1096. self.distr2Label.SetLabel("")
  1097. self.panelSizer.Hide(self.distr2Txt)
  1098. self.panelSizer.Hide(self.distr1Txt)
  1099. self.panelSizer.Layout()
  1100. def OnWidth(self, event):
  1101. self.width = self.widthTxt.GetValue()
  1102. def OnHeight(self, event):
  1103. self.height = self.heightTxt.GetValue()
  1104. def OnDistr1(self, event):
  1105. self.distr1 = self.distr1Txt.GetValue()
  1106. def OnDistr2(self, event):
  1107. self.distr2 = self.distr2Txt.GetValue()
  1108. class MovingKeyPage(TitledPage):
  1109. """Set values from keyboard for sample units"""
  1110. def __init__(self, wizard, parent):
  1111. TitledPage.__init__(self, wizard, _("Set sample units"))
  1112. self.parent = parent
  1113. self.width = ''
  1114. self.height = ''
  1115. self.boxtype = 'rectangle'
  1116. # type of shape
  1117. self.typeBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  1118. label=" %s " % _("Select type of shape"),
  1119. choices=[_('Rectangle'), _('Circle')],
  1120. # ('None')],
  1121. majorDimension=1,
  1122. style=wx.RA_SPECIFY_COLS)
  1123. self.sizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(1, 1))
  1124. self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
  1125. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1126. self.widthLabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1127. label=_('Width size (in cells) ?'))
  1128. self.widthTxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  1129. self.sizer.Add(item=self.widthLabel, border=5, pos=(2, 1),
  1130. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1131. self.sizer.Add(item=self.widthTxt, border=5, pos=(2, 2),
  1132. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1133. self.heightLabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1134. label=_('Height size (in cells) ?'))
  1135. self.heightTxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  1136. self.sizer.Add(item=self.heightLabel, border=5, pos=(3, 1),
  1137. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1138. self.sizer.Add(item=self.heightTxt, border=5, pos=(3, 2),
  1139. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1140. self.sizer.AddGrowableCol(2)
  1141. self.widthLabels = [_('Width size (in cells) ?'),
  1142. _('What radius size (in meters) ?')]
  1143. self.heightLabels = [_('Height size (in cells) ?'),
  1144. _('Name of the circle mask')]
  1145. self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
  1146. self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
  1147. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1148. def OnEnterPage(self, event):
  1149. # This is an hack to force the user to choose Rectangle or Circle
  1150. # self.typeBox.SetSelection(2),
  1151. # self.typeBox.ShowItem(2, False)
  1152. if self.parent.samplingareapage.samplingtype == SamplingType.MVWIN:
  1153. self.title.SetLabel(_("Set moving windows"))
  1154. self.OnType(None)
  1155. def OnType(self, event):
  1156. chosen = self.typeBox.GetSelection()
  1157. self.widthLabel.SetLabel(self.widthLabels[chosen])
  1158. self.heightLabel.SetLabel(self.heightLabels[chosen])
  1159. self.sizer.Layout()
  1160. if chosen == 0:
  1161. self.parent.samplingareapage.samplingtype = SamplingType.KMVWINR
  1162. self.boxtype = 'rectangle'
  1163. elif chosen == 1:
  1164. self.parent.samplingareapage.samplingtype = SamplingType.KMVWINC
  1165. self.boxtype = 'circle'
  1166. def CheckInput(self):
  1167. """Check input fields.
  1168. :return: True if configuration file is given and raster xor
  1169. vector map, False otherwise
  1170. """
  1171. return bool(self.width and bool(self.height))
  1172. def OnWidth(self, event):
  1173. self.width = self.widthTxt.GetValue()
  1174. next = wx.FindWindowById(wx.ID_FORWARD)
  1175. next.Enable(self.CheckInput())
  1176. def OnHeight(self, event):
  1177. self.height = self.heightTxt.GetValue()
  1178. next = wx.FindWindowById(wx.ID_FORWARD)
  1179. next.Enable(self.CheckInput())
  1180. class UnitsMousePage(TitledPage):
  1181. """Choose the sampling area setting the values using the mouse drawing the
  1182. areas with rectangle or circle. It is used both from 'Moving windows'
  1183. and 'Sample units'.
  1184. """
  1185. def __init__(self, wizard, parent):
  1186. self.parent = parent
  1187. self.wizard = wizard
  1188. TitledPage.__init__(self, self.wizard, _("Draw sampling units"))
  1189. self.numregions = ''
  1190. self.mapPanel = None
  1191. # type of shape
  1192. self.typeBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  1193. majorDimension=1, style=wx.RA_SPECIFY_COLS,
  1194. label=" %s " % _("Select type of shape"),
  1195. choices=[_('Rectangle'), _('Circle'), ('')])
  1196. # This is an hack to force the user to choose Rectangle or Circle
  1197. self.typeBox.SetSelection(2),
  1198. self.typeBox.ShowItem(2, False)
  1199. self.sizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(0, 0),
  1200. span=(1, 2))
  1201. self.regionPanelSizer = wx.GridBagSizer(1, 2)
  1202. self.regionNumPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  1203. self.regionNumLabel = wx.StaticText(parent=self.regionNumPanel,
  1204. id=wx.ID_ANY,
  1205. label=_('Number of sampling area to draw:'))
  1206. self.regionNumTxt = wx.TextCtrl(parent=self.regionNumPanel,
  1207. id=wx.ID_ANY, size=(50, -1))
  1208. self.regionPanelSizer.Add(self.regionNumLabel, flag=wx.ALIGN_CENTER,
  1209. pos=(0, 0))
  1210. self.regionPanelSizer.Add(self.regionNumTxt, flag=wx.ALIGN_CENTER,
  1211. pos=(0, 1))
  1212. self.regionNumPanel.SetSizer(self.regionPanelSizer)
  1213. self.sizer.Add(self.regionNumPanel, flag=wx.ALIGN_LEFT, pos=(1, 0),
  1214. span=(1, 2))
  1215. self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
  1216. self.regionNumTxt.Bind(wx.EVT_TEXT, self.OnNumRegions)
  1217. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1218. self.sizer.AddGrowableCol(0)
  1219. self.OnType(None)
  1220. self.regionNumTxt.SetValue('')
  1221. def OnEnterPage(self, event):
  1222. """Function during entering"""
  1223. if self.numregions:
  1224. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1225. else:
  1226. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1227. if self.parent.samplingareapage.samplingtype in [SamplingType.MVWIN,
  1228. SamplingType.MMVWINR,
  1229. SamplingType.MMVWINC]:
  1230. self.title.SetLabel(_("Draw moving windows region"))
  1231. self.sizer.Hide(self.regionNumPanel)
  1232. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1233. elif self.parent.samplingareapage.samplingtype in [SamplingType.UNITS,
  1234. SamplingType.MUNITSR,
  1235. SamplingType.MUNITSC]:
  1236. self.title.SetLabel(_("Draw sampling region"))
  1237. self.sizer.Show(self.regionNumPanel)
  1238. if self.typeBox.GetSelection() == 2:
  1239. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1240. self.sizer.Layout()
  1241. def OnType(self, event):
  1242. chosen = self.typeBox.GetSelection()
  1243. if chosen == 0:
  1244. if self.parent.samplingareapage.samplingtype in [SamplingType.MVWIN,
  1245. SamplingType.MMVWINR,
  1246. SamplingType.MMVWINC]:
  1247. self.parent.samplingareapage.samplingtype = SamplingType.MMVWINR
  1248. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1249. else:
  1250. self.parent.samplingareapage.samplingtype = SamplingType.MUNITSR
  1251. self.drawtype = 'rectangle'
  1252. else:
  1253. if self.parent.samplingareapage.samplingtype in [SamplingType.MVWIN,
  1254. SamplingType.MMVWINR,
  1255. SamplingType.MMVWINC]:
  1256. self.parent.samplingareapage.samplingtype = SamplingType.MMVWINC
  1257. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1258. else:
  1259. self.parent.samplingareapage.samplingtype = SamplingType.MUNITSC
  1260. self.drawtype = 'circle'
  1261. def OnNumRegions(self, event):
  1262. """Set the number of region"""
  1263. if self.regionNumTxt.GetValue():
  1264. self.SetNext(self.parent.drawsampleunitspage)
  1265. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1266. self.numregions = self.regionNumTxt.GetValue()
  1267. else:
  1268. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1269. def OnExitPage(self, event=None):
  1270. """Function during exiting"""
  1271. if event.GetDirection():
  1272. self.SetNext(self.drawsampleunitspage)
  1273. self.SetPrev(self.samplingareapage)
  1274. class DrawSampleUnitsPage(TitledPage):
  1275. """Choose the sampling area drawing them"""
  1276. def __init__(self, wizard, parent):
  1277. TitledPage.__init__(self, wizard, _("Draw sampling units"))
  1278. self.parent = parent
  1279. self.mapPanel = None
  1280. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1281. #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  1282. def SampleFrameChanged(self, region):
  1283. #region = self.GetSampleUnitRegion()
  1284. if region:
  1285. self.parent.msAreaList.append(region)
  1286. self.regioncount = self.regioncount + 1
  1287. drawtype = self.parent.drawunits.drawtype
  1288. if self.regioncount > self.numregions:
  1289. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1290. self.parent.wizard.ShowPage(self.parent.summarypage)
  1291. else:
  1292. self.title.SetLabel(_('Draw Sampling ' + drawtype + ' ' \
  1293. + str(self.regioncount) + ' of ' \
  1294. + str(self.numregions)))
  1295. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1296. def OnEnterPage(self, event):
  1297. """Function during entering"""
  1298. if self.parent.samplingareapage.samplingtype in [SamplingType.MVWIN,
  1299. SamplingType.MMVWINC,
  1300. SamplingType.MMVWINR]:
  1301. self.numregions = 1
  1302. else:
  1303. self.numregions = int(self.parent.drawunits.numregions)
  1304. self.regioncount = 0
  1305. if self.mapPanel:
  1306. self.sizer.Remove(self.mapPanel)
  1307. gtype = self.parent.drawunits.drawtype
  1308. self.mapPanel = RLiSetupMapPanel(self,
  1309. samplingType=self.parent.samplingareapage.samplingtype,
  1310. )
  1311. if gtype == 'circle':
  1312. self.mapPanel.afterCircleDrawn.connect(self.SampleFrameChanged)
  1313. else:
  1314. self.mapPanel.sampleFrameChanged.connect(self.SampleFrameChanged)
  1315. self.sizer.Add(item=self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
  1316. self.sizer.AddGrowableCol(0)
  1317. self.sizer.AddGrowableRow(1)
  1318. self._raster = None
  1319. self.SampleFrameChanged(region=None)
  1320. rast = self.parent.startpage.rast
  1321. if self._raster != rast:
  1322. map_ = self.mapPanel.GetMap()
  1323. map_.DeleteAllLayers()
  1324. cmdlist = ['d.rast', 'map=%s' % rast]
  1325. map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  1326. name=rast, hidden=False, opacity=1.0, render=True)
  1327. def OnExitPage(self, event=None):
  1328. #!Function during exiting
  1329. print event.GetDirection()
  1330. #if event.GetDirection():
  1331. # self.SetNext(self.parent.samplingareapage)
  1332. # self.parent.samplingareapage.SetPrev(self)
  1333. class VectorAreasPage(TitledPage):
  1334. """Choose the sampling area using the vector features"""
  1335. def __init__(self, wizard, parent):
  1336. TitledPage.__init__(self, wizard, _("Select sampling areas"))
  1337. self.parent = parent
  1338. self.areascount = 0
  1339. self.mapPanel = None
  1340. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1341. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  1342. self.areaPanelSizer = wx.GridBagSizer(1, 3)
  1343. self.areaPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  1344. self.areaText = wx.StaticText(parent=self.areaPanel, id=wx.ID_ANY,
  1345. label=_('Is this area ok?'))
  1346. self.areaOK = wx.Button(self.areaPanel, wx.ID_ANY, 'Yes', (50, 80))
  1347. self.areaNO = wx.Button(self.areaPanel, wx.ID_ANY, 'No', (50, 80))
  1348. self.areaOK.Bind(wx.EVT_BUTTON, self.OnYes)
  1349. self.areaNO.Bind(wx.EVT_BUTTON, self.OnNo)
  1350. self.areaPanelSizer.Add(self.areaText, flag=wx.ALIGN_CENTER,
  1351. pos=(0, 0))
  1352. self.areaPanelSizer.Add(self.areaOK, flag=wx.ALIGN_CENTER,
  1353. pos=(0, 1))
  1354. self.areaPanelSizer.Add(self.areaNO, flag=wx.ALIGN_CENTER,
  1355. pos=(0, 2))
  1356. self.areaPanel.SetSizer(self.areaPanelSizer)
  1357. self.sizer.Add(self.areaPanel, flag=wx.ALIGN_CENTER, pos=(2, 0))
  1358. def afterRegionDrawn(self):
  1359. """Function to update the title and the number of selected area"""
  1360. self.areascount = self.areascount + 1
  1361. if self.areascount == self.areanum:
  1362. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1363. self.areaOK.Enable(False)
  1364. self.areaNO.Enable(False)
  1365. return True
  1366. else:
  1367. self.title.SetLabel(_('Select sample area ' + str(self.areascount + 1) \
  1368. + ' of ' + str(self.areanum)))
  1369. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1370. return False
  1371. def OnYes(self, event):
  1372. """Function to create the string for the conf file if the area
  1373. is selected"""
  1374. self.parent.msAreaList.append(obtainAreaVector(self.outname))
  1375. if not self.afterRegionDrawn():
  1376. self.newCat()
  1377. def OnNo(self, event):
  1378. """Function to pass to the next feature if it is not selected"""
  1379. if not self.afterRegionDrawn():
  1380. self.newCat()
  1381. def newCat(self):
  1382. """Convert to raster and draw the new feature"""
  1383. cat = self.vect_cats[self.areascount]
  1384. self.outpref = "{rast}_{vect}_".format(vect=self.vect.split('@')[0],
  1385. rast=self.rast.split('@')[0])
  1386. self.outname = "{pref}{cat}".format(pref=self.outpref, cat=cat)
  1387. # check if raster already axist
  1388. if len(grass.list_strings('raster', pattern=self.outname, mapset='.')) == 1 \
  1389. and not self.parent.samplingareapage.overwriteTemp:
  1390. GError(parent=self, message=_("The raster map <%s> already exists."
  1391. " Please remove or rename the maps "
  1392. "with the prefix '%s' or select the "
  1393. "option to overwrite existing maps"
  1394. % (self.outname, self.outpref)))
  1395. self.parent.wizard.ShowPage(self.parent.samplingareapage)
  1396. return
  1397. convertFeature(self.vect, self.outname, cat, self.rast,
  1398. self.parent.startpage.vectorlayer,
  1399. self.parent.samplingareapage.overwriteTemp)
  1400. cmdlistcat = ['d.rast', 'map=%s' % self.outname]
  1401. self.map_.AddLayer(ltype='raster', command=cmdlistcat, active=True,
  1402. name=self.outname, hidden=False, opacity=1.0,
  1403. render=True)
  1404. for l in self.map_.GetListOfLayers():
  1405. if l.name == self.outname:
  1406. self.mapPanel.mapWindow.ZoomToMap(layers=[l], render=True,
  1407. ignoreNulls=True)
  1408. elif l.name != self.rast:
  1409. self.map_.DeleteLayer(l)
  1410. self.areaText.SetLabel("Is this area (cat={n}) ok?".format(n=cat))
  1411. def OnEnterPage(self, event):
  1412. """Function during entering: draw the raster map and the first vector
  1413. feature"""
  1414. print self.parent.samplingareapage.overwriteTemp
  1415. if self.mapPanel is None:
  1416. self.mapPanel = RLiSetupMapPanel(self, samplingType=self.parent.samplingareapage.samplingtype)
  1417. self.sizer.Add(item=self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
  1418. self.sizer.AddGrowableCol(0)
  1419. self.sizer.AddGrowableRow(1)
  1420. self._raster = None
  1421. self.rast = self.parent.startpage.rast
  1422. self.vect = self.parent.startpage.vect
  1423. self.vect_cats = obtainCategories(self.vect,
  1424. layer=self.parent.startpage.vectorlayer)
  1425. self.areanum = len(self.vect_cats)
  1426. if self.areanum == 0:
  1427. GError(parent=self, message=_("The polygon seems to have 0 areas"))
  1428. self.parent.wizard.ShowPage(self.parent.samplingareapage)
  1429. return
  1430. self.title.SetLabel(_('Select sample area 1 of ' + str(self.areanum)))
  1431. grass.use_temp_region()
  1432. if self._raster != self.rast:
  1433. self.map_ = self.mapPanel.GetMap()
  1434. self.map_.DeleteAllLayers()
  1435. cmdlist = ['d.rast', 'map=%s' % self.rast]
  1436. self.map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  1437. name=self.rast, hidden=False, opacity=1.0,
  1438. render=True)
  1439. self.newCat()
  1440. def OnExitPage(self, event=None):
  1441. """Function during exiting"""
  1442. grass.del_temp_region()
  1443. # if event.GetDirection():
  1444. # self.SetNext(self.parent.samplingareapage)
  1445. # self.parent.samplingareapage.SetPrev(self)
  1446. class SummaryPage(TitledPage):
  1447. """Shows summary result of choosing data"""
  1448. def __init__(self, wizard, parent):
  1449. TitledPage.__init__(self, wizard, _("Summary"))
  1450. global rlisettings
  1451. self.parent = parent
  1452. #configuration file name
  1453. self.conflabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1454. label=_('Configuration file name:'))
  1455. self.conftxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1456. label="")
  1457. self.sizer.Add(item=self.conflabel, border=5, pos=(0, 0),
  1458. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1459. self.sizer.Add(item=self.conftxt, border=5, pos=(0, 1),
  1460. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1461. #raster name
  1462. self.rastlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1463. label=_('Raster name:'))
  1464. self.rasttxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1465. label="")
  1466. self.sizer.Add(item=self.rastlabel, border=5, pos=(1, 0),
  1467. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1468. self.sizer.Add(item=self.rasttxt, border=5, pos=(1, 1),
  1469. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1470. #vector name
  1471. self.vectlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1472. label=_('Vector name:'))
  1473. self.vecttxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1474. self.sizer.Add(item=self.vectlabel, border=5, pos=(2, 0),
  1475. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1476. self.sizer.Add(item=self.vecttxt, border=5, pos=(2, 1),
  1477. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1478. #region type name
  1479. self.regionlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1480. label=_('Region type:'))
  1481. self.regiontxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1482. self.sizer.Add(item=self.regionlabel, border=5, pos=(3, 0),
  1483. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1484. self.sizer.Add(item=self.regiontxt, border=5, pos=(3, 1),
  1485. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1486. #region keyboard
  1487. self.regionkeylabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1488. label="")
  1489. self.regionkeytxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1490. self.sizer.Add(item=self.regionkeylabel, border=5, pos=(4, 0),
  1491. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1492. self.sizer.Add(item=self.regionkeytxt, border=5, pos=(4, 1),
  1493. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1494. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1495. #sampling area
  1496. self.samplinglabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1497. label=_('Sampling area type:'))
  1498. self.samplingtxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1499. self.sizer.Add(item=self.samplinglabel, border=5, pos=(5, 0),
  1500. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1501. self.sizer.Add(item=self.samplingtxt, border=5, pos=(5, 1),
  1502. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1503. #shapetype
  1504. self.shapelabel = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1505. self.shapetxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1506. self.sizer.Add(item=self.shapelabel, border=5, pos=(6, 0),
  1507. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1508. self.sizer.Add(item=self.shapetxt, border=5, pos=(6, 1),
  1509. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1510. #shapedim
  1511. self.shapewidthlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1512. label="")
  1513. self.shapewidthtxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1514. label="")
  1515. self.sizer.Add(item=self.shapewidthlabel, border=5, pos=(7, 0),
  1516. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1517. self.sizer.Add(item=self.shapewidthtxt, border=5, pos=(7, 1),
  1518. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1519. self.shapeheightlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1520. label="")
  1521. self.shapeheighttxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1522. label="")
  1523. self.sizer.Add(item=self.shapeheightlabel, border=5, pos=(8, 0),
  1524. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1525. self.sizer.Add(item=self.shapeheighttxt, border=5, pos=(8, 1),
  1526. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1527. #units type
  1528. self.unitslabel = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1529. self.unitstxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1530. self.sizer.Add(item=self.unitslabel, border=5, pos=(9, 0),
  1531. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1532. self.sizer.Add(item=self.unitstxt, border=5, pos=(9, 1),
  1533. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1534. self.unitsmorelabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1535. label="")
  1536. self.unitsmoretxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1537. self.sizer.Add(item=self.unitsmorelabel, border=5, pos=(10, 0),
  1538. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1539. self.sizer.Add(item=self.unitsmoretxt, border=5, pos=(10, 1),
  1540. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1541. self.unitsmorelabel2 = wx.StaticText(parent=self, id=wx.ID_ANY,
  1542. label="")
  1543. self.unitsmoretxt2 = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1544. self.sizer.Add(item=self.unitsmorelabel2, border=5, pos=(11, 0),
  1545. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1546. self.sizer.Add(item=self.unitsmoretxt2, border=5, pos=(11, 1),
  1547. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1548. def OnEnterPage(self, event):
  1549. """Insert values into text controls for summary of location
  1550. creation options
  1551. """
  1552. self.conftxt.SetLabel(self.parent.startpage.conf_name)
  1553. self.rasttxt.SetLabel(self.parent.startpage.rast)
  1554. self.samplingtxt.SetLabel(self.parent.samplingareapage.samplingtype)
  1555. self.regiontxt.SetLabel(self.parent.startpage.region)
  1556. self.vecttxt.SetLabel(self.parent.startpage.vect)
  1557. if self.parent.startpage.region == 'key':
  1558. #region keyboard values
  1559. self.regionkeylabel.SetLabel(_('Region keyboard values:'))
  1560. regKeyVals = "Column left up: %s - Row left up: %s\n" \
  1561. "Column length: %s - Row length: %s\n" % (
  1562. self.parent.keyboardpage.col_up,
  1563. self.parent.keyboardpage.row_up,
  1564. self.parent.keyboardpage.col_len,
  1565. self.parent.keyboardpage.row_len)
  1566. self.regionkeytxt.SetLabel(regKeyVals)
  1567. else:
  1568. self.regionkeylabel.SetLabel("")
  1569. self.regionkeytxt.SetLabel("")
  1570. if self.parent.samplingareapage.samplingtype == SamplingType.UNITS \
  1571. and self.parent.samplingareapage.regionbox == 'keyboard':
  1572. self.shapelabel.SetLabel(_('Type of shape:'))
  1573. self.shapetxt.SetLabel(self.parent.units.boxtype)
  1574. if self.parent.units.boxtype == 'circle':
  1575. self.shapewidthlabel.SetLabel(_("Radius size:"))
  1576. self.shapeheightlabel.SetLabel(_("Name circle mask:"))
  1577. else:
  1578. self.shapewidthlabel.SetLabel(_("Width size:"))
  1579. self.shapeheightlabel.SetLabel(_("Heigth size:"))
  1580. self.shapewidthtxt.SetLabel(self.parent.units.width)
  1581. self.shapeheighttxt.SetLabel(self.parent.units.height)
  1582. self.unitslabel.SetLabel(_("Method of distribution:"))
  1583. self.unitstxt.SetLabel(self.parent.units.distrtype)
  1584. if self.parent.units.distrtype == 'non_overlapping':
  1585. self.unitsmorelabel.SetLabel(_("Number sampling units:"))
  1586. self.unitsmoretxt.SetLabel(self.parent.units.distr1)
  1587. elif self.parent.units.distrtype == 'systematic_noncontiguos':
  1588. self.unitsmorelabel.SetLabel(_("Distance between units:"))
  1589. self.unitsmoretxt.SetLabel(self.parent.units.distr1)
  1590. elif self.parent.units.distrtype == 'stratified_random':
  1591. self.unitsmorelabel.SetLabel(_("Number row strates:"))
  1592. self.unitsmoretxt.SetLabel(self.parent.units.distr1)
  1593. self.unitsmorelabel2.SetLabel(_("Number column strates:"))
  1594. self.unitsmoretxt2.SetLabel(self.parent.units.distr2)
  1595. elif self.parent.samplingareapage.samplingtype == SamplingType.UNITS \
  1596. and self.parent.samplingareapage.regionbox == 'mouse':
  1597. self.shapelabel.SetLabel(_('Type of shape:'))
  1598. self.shapetxt.SetLabel(self.parent.units.boxtype)
  1599. self.unitstxt.SetLabel('by mouse')
  1600. elif self.parent.samplingareapage.samplingtype == 'moving':
  1601. self.shapelabel.SetLabel(_('Type of shape:'))
  1602. self.shapetxt.SetLabel(self.parent.moving.boxtype)
  1603. if self.parent.moving.boxtype == 'circle':
  1604. self.shapewidthlabel.SetLabel(_("Radius size:"))
  1605. self.shapeheightlabel.SetLabel(_("Name circle mask:"))
  1606. else:
  1607. self.shapewidthlabel.SetLabel(_("Width size:"))
  1608. self.shapeheightlabel.SetLabel(_("Heigth size:"))
  1609. self.shapewidthtxt.SetLabel(self.parent.moving.width)
  1610. self.shapeheighttxt.SetLabel(self.parent.moving.height)
  1611. else:
  1612. self.shapelabel.SetLabel("")
  1613. self.shapetxt.SetLabel("")
  1614. self.shapewidthlabel.SetLabel("")
  1615. self.shapewidthtxt.SetLabel("")
  1616. self.shapeheightlabel.SetLabel("")
  1617. self.shapeheighttxt.SetLabel("")