Pārlūkot izejas kodu

Removed global variables from GUI and core scripts.

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57134 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anne Ghisla 12 gadi atpakaļ
vecāks
revīzija
61e2f94062
3 mainītis faili ar 32 papildinājumiem un 25 dzēšanām
  1. 5 6
      gui/wxpython/scripts/vkrige.py
  2. 2 2
      scripts/Makefile
  3. 25 17
      scripts/v.krige/v.krige.py

+ 5 - 6
gui/wxpython/scripts/vkrige.py

@@ -463,14 +463,13 @@ class RBookgstatPanel(RBookPanel):
         column = self.parent.InputDataColumn.GetValue()
         
         # import data or pick them up
-        if globals()["InputData"] is None:
-            globals()["InputData"] = controller.ImportMap(map = map,
+        if self.controller.InputData is None:
+            self.controller.InputData = controller.ImportMap(map = map,
                                                           column = column)
         # fit the variogram or pick it up
         Formula = controller.ComposeFormula(column = column,
                                             isblock = self.KrigingRadioBox.GetStringSelection() == "Block kriging",
-                                            inputdata = globals()['InputData'])
-        #if globals()["Variogram"] is None:
+                                            inputdata = self.controller.InputData)
         if hasattr(self, 'VariogramCheckBox') and self.VariogramCheckBox.IsChecked():
             self.model = ''
             for each in ("Sill","Nugget","Range"):
@@ -484,8 +483,8 @@ class RBookgstatPanel(RBookPanel):
                 if getattr(self, each+'ChextBox').IsChecked(): #@FIXME will be removed when chextboxes will be frozen
                     setattr(self, each.lower(), getattr(self, each+"Ctrl").GetValue())
             
-        globals()["Variogram"] = controller.FitVariogram(Formula,
-                                                         InputData,
+        self.controller.Variogram = controller.FitVariogram(Formula,
+                                                         self.controller.InputData,
                                                          model = self.model,
                                                          sill = self.sill,
                                                          nugget = self.nugget,

+ 2 - 2
scripts/Makefile

@@ -68,9 +68,9 @@ SUBDIRS = \
 	v.pack \
 	v.unpack \
 	v.what.vect \
-	wxpyimgview
+	wxpyimgview \
 
-#        v.krige \
+	v.krige \
 
 #	r.mapcalculator \
 #	r3.mapcalculator \

+ 25 - 17
scripts/v.krige/v.krige.py

@@ -124,18 +124,26 @@ except ImportError:
 
 # globals
 
-Command = None
-InputData = None
-Variogram = None
-VariogramFunction = None
-robjects = None
-rinterface = None
+#~ Command = None
+#~ InputData = None
+#~ Variogram = None
+#~ VariogramFunction = None
+#~ robjects = None
+#~ rinterface = None
 
 #classes in alphabetical order. methods in logical order :)
 
 # <2.5 class definition, without () - please test 
 class Controller:
     """ Executes analysis. For the moment, only with gstat functions."""
+    # moved here the global variables
+    def __init__(self):
+        #~ self.Command = None
+        self.InputData = None
+        self.Variogram = None
+        #~ VariogramFunction = None
+        #~ robjects = None
+        #~ rinterface = None
     
     def ImportMap(self, map, column):
         """ Imports GRASS map as SpatialPointsDataFrame and adds x/y columns to attribute table.
@@ -252,20 +260,20 @@ class Controller:
                          "exponentially with resolution." % grass.region()['cells']))
         logger.message(_("Importing data..."))
 
-        if globals()["InputData"] is None:
-            globals()["InputData"] = self.ImportMap(input, column)
+        if self.InputData is None:
+            self.InputData = self.ImportMap(input, column)
         # and from here over, InputData refers to the global variable
         #print(robjects.r.slot(InputData, 'data').names)
         logger.message(_("Data successfully imported."))
         
-        GridPredicted = self.CreateGrid(InputData)
+        GridPredicted = self.CreateGrid(self.InputData)
         
         logger.message(_("Fitting variogram..."))
         isblock = block is not ''
-        Formula = self.ComposeFormula(column, isblock, InputData)
-        if globals()["Variogram"] is None:
-            globals()["Variogram"] = self.FitVariogram(Formula,
-                                          InputData,
+        Formula = self.ComposeFormula(column, isblock, self.InputData)
+        if self.Variogram is None:
+            self.Variogram = self.FitVariogram(Formula,
+                                          self.InputData,
                                           model = model,
                                           sill = sill,
                                           nugget = nugget,
@@ -273,8 +281,8 @@ class Controller:
         logger.message(_("Variogram fitting complete."))
         
         logger.message(_("Kriging..."))
-        KrigingResult = self.DoKriging(Formula, InputData,
-                 GridPredicted, Variogram['variogrammodel'], block) # using global ones
+        KrigingResult = self.DoKriging(Formula, self.InputData,
+                 GridPredicted, self.Variogram['variogrammodel'], block) # using global ones
         logger.message(_("Kriging complete."))
         
         self.ExportMap(map = KrigingResult,
@@ -282,14 +290,14 @@ class Controller:
                        name = output,
                        overwrite = overwrite,
                        command = command,
-                       variograms = Variogram)
+                       variograms = self.Variogram)
         if output_var is not '':
             self.ExportMap(map = KrigingResult,
                            column='var1.var',
                            name = output_var,
                            overwrite = overwrite,
                            command = command,
-                           variograms = Variogram)
+                           variograms = self.Variogram)
         
 def main(argv = None):
     """ Main. Calls either GUI or CLI, depending on arguments provided. """