~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to gui/wxpython/rlisetup/wizard.py

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

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