[GRASS-SVN] r57363 - in grass/trunk/gui/wxpython: . lmgr mapdisp vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 2 03:21:30 PDT 2013


Author: martinl
Date: 2013-08-02 03:21:30 -0700 (Fri, 02 Aug 2013)
New Revision: 57363

Modified:
   grass/trunk/gui/wxpython/Makefile
   grass/trunk/gui/wxpython/lmgr/frame.py
   grass/trunk/gui/wxpython/mapdisp/frame.py
   grass/trunk/gui/wxpython/mapdisp/toolbars.py
   grass/trunk/gui/wxpython/vdigit/toolbars.py
   grass/trunk/gui/wxpython/vdigit/wxdigit.py
Log:
wxGUI: launch gdal/ogr GUI front-end dialog also from cmd, autogenerated dialog can be launch by --ui switch (TODO: rewrite mechanism to prefer front-ends)

Modified: grass/trunk/gui/wxpython/Makefile
===================================================================
--- grass/trunk/gui/wxpython/Makefile	2013-08-02 09:50:13 UTC (rev 57362)
+++ grass/trunk/gui/wxpython/Makefile	2013-08-02 10:21:30 UTC (rev 57363)
@@ -13,7 +13,7 @@
 	$(wildcard animation/* core/*.py dbmgr/* gcp/*.py gmodeler/* \
 	gui_core/*.py iclass/* lmgr/*.py location_wizard/*.py mapdisp/*.py \
 	mapswipe/* modules/*.py nviz/*.py psmap/* rlisetup/* vdigit/* \
-	vnet/*.py web_services/*.py wxplot/*.py) \
+	vnet/*.py web_services/*.py wxplot/*.py scatt_plot/*.py) \
 	gis_set.py gis_set_error.py wxgui.py README
 
 DSTFILES := $(patsubst %,$(ETCDIR)/%,$(SRCFILES)) \
@@ -21,7 +21,7 @@
 
 PYDSTDIRS := $(patsubst %,$(ETCDIR)/%,animation core dbmgr gcp gmodeler \
 	gui_core iclass lmgr location_wizard mapdisp modules nviz psmap \
-	mapswipe vdigit wxplot web_services rlisetup vnet)
+	mapswipe vdigit wxplot web_services rlisetup vnet scatt_plot)
 
 DSTDIRS := $(patsubst %,$(ETCDIR)/%,icons scripts xml)
 

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2013-08-02 09:50:13 UTC (rev 57362)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2013-08-02 10:21:30 UTC (rev 57363)
@@ -279,7 +279,8 @@
         
         # create 'command output' text area
         self._gconsole = GConsole(guiparent = self, giface = self._giface,
-                                  ignoredCmdPattern = '^d\..*|^r[3]?\.mapcalc$|^i.group')
+                                  ignoredCmdPattern = '^d\..*|^r[3]?\.mapcalc$|^i.group|^r.in.gdal|^r.external|^r.external.out|'
+                                  '^v.in.ogr|^v.external|^v.external.out')
         self.goutput = GConsoleWindow(parent = self, gconsole = self._gconsole,
                                       menuModel=self._moduleTreeBuilder.GetModel(),
                                       gcstyle = GC_PROMPT)
@@ -607,6 +608,19 @@
             self.OnMapCalculator(event = None, cmd = command)
         elif command[0] == 'i.group':
             self.OnEditImageryGroups(event = None, cmd = command)
+        elif command[0] == 'r.in.gdal':
+            self.OnImportGdalLayers(event = None, cmd = command)
+        elif command[0] == 'r.external':
+            self.OnLinkGdalLayers(event = None, cmd = command)
+        elif command[0] == 'r.external.out':
+             self.OnRasterOutputFormat(event = None)
+        elif command[0] == 'v.in.ogr':
+            self.OnImportOgrLayers(event = None, cmd = command)
+        elif command[0] == 'v.external':
+            self.OnLinkOgrLayers(event = None, cmd = command)
+        elif command[0] == 'v.external.out':
+             self.OnVectorOutputFormat(event = None)
+
         else:
             raise ValueError('Layer Manager special command (%s)'
                              ' not supported.' % ' '.join(command))

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2013-08-02 09:50:13 UTC (rev 57362)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2013-08-02 10:21:30 UTC (rev 57363)
@@ -216,6 +216,7 @@
         #
         self.dialogs = {}
         self.dialogs['attributes'] = None
+        self.dialogs['scatt_plot'] = None
         self.dialogs['category'] = None
         self.dialogs['barscale'] = None
         self.dialogs['legend'] = None
@@ -1305,6 +1306,19 @@
         """!Returns toolbar with zooming tools"""
         return self.toolbars['map']
 
+    def OnScatterplot2(self, event):
+        """!Init interactive scatterplot tools
+        """
+        if self.dialogs['scatt_plot']:
+            self.dialogs['scatt_plot'].Raise()
+            return
+
+        from scatt_plot.dialogs import ScattPlotMainDialog
+        self.dialogs['scatt_plot'] = ScattPlotMainDialog(parent=self, giface=self._giface)
+        
+        self.dialogs['scatt_plot'].CenterOnScreen()
+        self.dialogs['scatt_plot'].Show()
+
     def OnVNet(self, event):
         """!Dialog for v.net* modules 
         """

Modified: grass/trunk/gui/wxpython/mapdisp/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/toolbars.py	2013-08-02 09:50:13 UTC (rev 57362)
+++ grass/trunk/gui/wxpython/mapdisp/toolbars.py	2013-08-02 10:21:30 UTC (rev 57363)
@@ -243,7 +243,8 @@
                       (MapIcons["scatter"],     self.parent.OnScatterplot),
                       (MapIcons["histogram"],   self.parent.OnHistogramPyPlot),
                       (BaseIcons["histogramD"], self.parent.OnHistogram),
-                      (MapIcons["vnet"],        self.parent.OnVNet)))
+                      (MapIcons["vnet"],        self.parent.OnVNet),
+                      (MapIcons["scatter"],     self.parent.OnScatterplot2)))
         
     def OnDecoration(self, event):
         """!Decorations overlay menu

Modified: grass/trunk/gui/wxpython/vdigit/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/toolbars.py	2013-08-02 09:50:13 UTC (rev 57362)
+++ grass/trunk/gui/wxpython/vdigit/toolbars.py	2013-08-02 10:21:30 UTC (rev 57363)
@@ -17,6 +17,7 @@
 import wx
 
 from grass.script import core as grass
+from grass.pydispatch.signal import Signal
 
 from gui_core.toolbars  import BaseToolbar, BaseIcons
 from gui_core.dialogs   import CreateNewVector
@@ -42,6 +43,8 @@
         self.digit         = None
         self._giface       = giface
         
+        self.editingStarted = Signal("VDigitToolbar.editingStarted")
+
         # currently selected map layer for editing (reference to MapLayer instance)
         self.mapLayer = None
         # list of vector layers from Layer Manager (only in the current mapset)
@@ -820,6 +823,7 @@
             alpha = int(opacity * 255)
             self.digit.GetDisplay().UpdateSettings(alpha = alpha)
         
+        self.editingStarted.emit(vectMap = mapLayer.GetName())
         return True
 
     def StopEditing(self):

Modified: grass/trunk/gui/wxpython/vdigit/wxdigit.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/wxdigit.py	2013-08-02 09:50:13 UTC (rev 57362)
+++ grass/trunk/gui/wxpython/vdigit/wxdigit.py	2013-08-02 10:21:30 UTC (rev 57363)
@@ -17,7 +17,7 @@
 (and NumPy would be an excellent candidate for acceleration via
 e.g. OpenCL or CUDA; I'm surprised it hasn't happened already).
 
-(C) 2007-2011 by the GRASS Development Team
+(C) 2007-2011, 2013 by the GRASS Development Team
 
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -27,6 +27,8 @@
 
 import grass.script.core as grass
 
+from grass.pydispatch.signal import Signal
+
 from core.gcmd        import GError
 from core.debug       import Debug
 from core.settings    import UserSettings
@@ -176,7 +178,17 @@
         
         if self.poMapInfo:
             self.InitCats()
-        
+
+        #TODO signal for errors?
+        self.featureAdded = Signal('IVDigit.featureAdded')
+        self.areasDeleted = Signal('IVDigit.areasDeleted')
+        self.vertexMoved = Signal('IVDigit.vertexMoved')
+        self.vertexAdded = Signal('IVDigit.vertexAdded')
+        self.vertexRemoved = Signal('IVDigit.vertexRemoved')
+        self.featuresDeleted = Signal('IVDigit.featuresDeleted')
+        self.featuresMoved = Signal('IVDigit.featuresMoved')
+        self.lineEdited = Signal('IVDigit.lineEdited')
+
     def __del__(self):
         Debug.msg(1, "IVDigit.__del__()")
         Vect_destroy_line_struct(self.poPoints)
@@ -394,7 +406,6 @@
         
         @return tuple (number of added features, feature ids)
         """
-        
         layer = self._getNewFeaturesLayer()
         cat = self._getNewFeaturesCat()
         
@@ -419,10 +430,14 @@
             return (-1, None)
         
         self.toolbar.EnableUndo()
-        
-        return self._addFeature(vtype, points, layer, cat,
-                                self._getSnapMode(), self._display.GetThreshold())
-    
+
+        ret = self._addFeature(vtype, points, layer, cat,
+                               self._getSnapMode(), self._display.GetThreshold())
+        if ret[0] > -1:
+            self.featureAdded.emit(new_geom = points, cat = {layer : [cat]})
+
+        return ret
+
     def DeleteSelectedLines(self):
         """!Delete selected features
 
@@ -434,16 +449,25 @@
         # colect categories for delete if requested
         deleteRec = UserSettings.Get(group = 'vdigit', key = 'delRecord', subkey = 'enabled')
         catDict = dict()
+
+        old_geoms = []
+        old_areas_cats = []
         if deleteRec:
             for i in self._display.selected['ids']:
+                
                 if Vect_read_line(self.poMapInfo, None, self.poCats, i) < 0:
                     self._error.ReadLine(i)
                 
+                old_geoms.append(self._getGeom(i))
+                old_areas_cats.append(self._getLineAreasCategories(i))
+                
                 cats = self.poCats.contents
-                for j in range(cats.n_cats):
-                    if cats.field[j] not in catDict.keys():
-                        catDict[cats.field[j]] = list()
-                    catDict[cats.field[j]].append(cats.cat[j])
+
+                # catDict was not used -> put into comment
+                #for j in range(cats.n_cats):
+                #    if cats.field[j] not in catDict.keys():
+                #        catDict[cats.field[j]] = list()
+                #    catDict[cats.field[j]].append(cats.cat[j])
         
         poList = self._display.GetSelectedIList()
         nlines = Vedit_delete_lines(self.poMapInfo, poList)
@@ -456,7 +480,8 @@
                 self._deleteRecords(cats)
             self._addChangeset()
             self.toolbar.EnableUndo()
-        
+            self.featuresDeleted.emit(old_geoms = old_geoms, old_areas_cats = old_areas_cats)
+
         return nlines
             
     def _deleteRecords(self, cats):
@@ -512,22 +537,123 @@
 
         @return number of deleted 
         """
+        if len(self._display.selected['ids']) < 1:
+            return 0
+        
         poList = self._display.GetSelectedIList()
         cList  = poList.contents
         
         nareas = 0
+        old_geoms = []
+        old_areas_cats = []
+
         for i in range(cList.n_values):
+
             if Vect_get_line_type(self.poMapInfo, cList.value[i]) != GV_CENTROID:
                 continue
-            
+
+            area = Vect_get_centroid_area(self.poMapInfo, cList.value[i]);
+            if area > 0: 
+                geoms, cats = self._getaAreaGeomsCats(area)
+                old_geoms += geoms
+                old_areas_cats += cats
+
             nareas += Vedit_delete_area_centroid(self.poMapInfo, cList.value[i])
         
         if nareas > 0:
             self._addChangeset()
             self.toolbar.EnableUndo()
+            self.areasDeleted.emit(old_geoms = old_geoms, old_areas_cats = old_areas_cats)        
+
+        return nareas
+   
+
+    def _getaAreaGeomsCats(self, area):
+
+        po_b_list = Vect_new_list()
+        Vect_get_area_boundaries(self.poMapInfo, area, po_b_list);
+        b_list = po_b_list.contents
+
+        geoms = []
+        areas_cats = []
+
+        if b_list.n_values > 0:
+            for i_line in  range(b_list.n_values):
+
+                line = b_list.value[i_line];
+
+                geoms.append(self._getGeom(abs(line)))
+                areas_cats.append(self._getLineAreasCategories(abs(line)))
         
-        return nareas
+        Vect_destroy_list(po_b_list);
+
+        return geoms, areas_cats
+
+    def _getLineAreasCategories(self, ln_id):
+
+        ltype = Vect_read_line(self.poMapInfo, None, None, ln_id)
+        if ltype != GV_BOUNDARY:
+            return []
+
+        cats = [None, None]
+
+        left = c_int()
+        right = c_int()
+
+        if Vect_get_line_areas(self.poMapInfo, ln_id, pointer(left), pointer(right)) == 1:
+            areas = [left.value, right.value]
+
+            for i, a in enumerate(areas):
+                if a > 0: 
+                    centroid = Vect_get_area_centroid(self.poMapInfo, a)
+                    if centroid <= 0:
+                        continue
+                    c = self._getCategories(centroid)
+                    if c:
+                        cats[i] = c
+
+        return cats
+
+    def _getCategories(self, ln_id):
+        
+        poCats = Vect_new_cats_struct()
+        if Vect_read_line(self.poMapInfo, None, poCats, ln_id) < 0:
+            Vect_destroy_cats_struct(poCats)
+            return None
+
+        cCats = poCats.contents
+
+        cats = {}
+        for j in range(cCats.n_cats):
+            if cats.has_key(cCats.field[j]):
+                cats[cCats.field[j]].append(cCats.cat[j])
+            else:
+                cats[cCats.field[j]] = [cCats.cat[j]]
     
+        Vect_destroy_cats_struct(poCats)
+        return cats
+
+    def _getGeom(self, ln_id):
+
+        poPoints = Vect_new_line_struct()
+        if Vect_read_line(self.poMapInfo, poPoints, None, ln_id) < 0:
+            Vect_destroy_line_struct(poPoints)
+            return None
+
+        geom = self._convertGeom(poPoints)
+        Vect_destroy_line_struct(poPoints)
+        return geom
+
+    def _convertGeom(self, poPoints):
+
+        Points = poPoints.contents
+
+        pts_geom = []
+        for j in range(Points.n_points):
+            pts_geom.append((Points.x[j], Points.y[j]))
+
+        return pts_geom
+
     def MoveSelectedLines(self, move):
         """!Move selected features
 
@@ -536,16 +662,39 @@
         if not self._checkMap():
             return -1
         
+        nsel = len(self._display.selected['ids'])
+        if nsel < 1:
+            return -1   
+        
         thresh = self._display.GetThreshold()
         snap   = self._getSnapMode()
         
         poList = self._display.GetSelectedIList()
+
+        old_geoms = []
+        old_areas_cats = []
+        for sel_id in self._display.selected['ids']:
+            old_geoms.append(self._getGeom(sel_id))
+            old_areas_cats.append(self._getLineAreasCategories(sel_id))
+
+        poNewIds = Vect_new_list()
         nlines = Vedit_move_lines(self.poMapInfo, self.popoBgMapInfo, int(self.poBgMapInfo is not None),
                                   poList,
                                   move[0], move[1], 0,
-                                  snap, thresh)
+                                  snap, thresh, poNewIds)
+
         Vect_destroy_list(poList)
         
+        cList = poNewIds.contents
+
+        if nlines > 0:
+            new_areas_cats = []
+            for i in range(cList.n_values):
+                new_id = cList.value[i]
+                new_areas_cats.append(self._getLineAreasCategories(new_id))
+
+        Vect_destroy_list(poNewIds)
+
         if nlines > 0 and self._settings['breakLines']:
             for i in range(1, nlines):
                 self._breakLineAtIntersection(nlines + i, None, changeset)
@@ -553,7 +702,11 @@
         if nlines > 0:
             self._addChangeset()
             self.toolbar.EnableUndo()
-        
+ 
+            self.featuresMoved.emit(move = move, 
+                                    old_geoms = old_geoms, 
+                                    old_areas_cats = old_areas_cats, 
+                                    new_areas_cats = new_areas_cats)
         return nlines
 
     def MoveSelectedVertex(self, point, move):
@@ -571,20 +724,33 @@
         
         if len(self._display.selected['ids']) != 1:
             return -1
-        
+
+        # move only first found vertex in bbox 
+        poList = self._display.GetSelectedIList()
+
+        cList = poList.contents
+        old_geom = self._getGeom(cList.value[0])
+        old_areas_cats = self._getLineAreasCategories(cList.value[0])
+
         Vect_reset_line(self.poPoints)
         Vect_append_point(self.poPoints, point[0], point[1], 0.0)
-        
-        # move only first found vertex in bbox 
-        poList = self._display.GetSelectedIList()
+
+        poNewIds = Vect_new_list()
         moved = Vedit_move_vertex(self.poMapInfo, self.popoBgMapInfo, int(self.poBgMapInfo is not None),
                                   poList, self.poPoints,
                                   self._display.GetThreshold(type = 'selectThresh'),
                                   self._display.GetThreshold(),
                                   move[0], move[1], 0.0,
-                                  1, self._getSnapMode())
+                                  1, self._getSnapMode(), poNewIds)
         Vect_destroy_list(poList)
-        
+
+        new_id = poNewIds.contents.value[0]
+        Vect_destroy_list(poNewIds)
+
+        if new_id > -1:
+            new_geom = self._getGeom(new_id)
+            new_areas_cats = self._getLineAreasCategories(new_id)
+
         if moved > 0 and self._settings['breakLines']:
             self._breakLineAtIntersection(Vect_get_num_lines(self.poMapInfo),
                                           None)
@@ -592,7 +758,13 @@
         if moved > 0:
             self._addChangeset()
             self.toolbar.EnableUndo()
-        
+
+        if new_id > -1:
+            self.vertexMoved.emit(new_geom = new_geom,  
+                                  new_areas_cats = new_areas_cats, 
+                                  old_areas_cats = old_areas_cats, 
+                                  old_geom = old_geom)
+
         return moved
 
     def AddVertex(self, coords):
@@ -681,6 +853,9 @@
             self._error.ReadLine(line)
             return -1
         
+        old_geom = self._getGeom(line)
+        old_areas_cats = self._getLineAreasCategories(line)
+
         # build feature geometry
         Vect_reset_line(self.poPoints)
         for p in coords:
@@ -703,7 +878,15 @@
         if newline > 0:
             self._addChangeset()
             self.toolbar.EnableUndo()
-        
+
+            new_geom = self._getGeom(newline)
+            new_areas_cats = self._getLineAreasCategories(newline)
+    
+            self.lineEdited.emit(old_geom = old_geom, 
+                                 old_areas_cats = old_areas_cats, 
+                                 new_geom = new_geom, 
+                                 new_areas_cats = new_areas_cats)
+
         return newline
 
     def FlipLine(self):
@@ -1510,26 +1693,49 @@
             return 0
         
         poList  = self._display.GetSelectedIList()
+        cList = poList.contents
+        
+        old_geom = self._getGeom(cList.value[0])
+        old_areas_cats = self._getLineAreasCategories(cList.value[0])
+
         Vect_reset_line(self.poPoints)
         Vect_append_point(self.poPoints, coords[0], coords[1], 0.0)
         
         thresh = self._display.GetThreshold(type = 'selectThresh')
         
+        poNewIds = Vect_new_list()
+
         if add:
             ret = Vedit_add_vertex(self.poMapInfo, poList,
-                                   self.poPoints, thresh)
+                                   self.poPoints, thresh, poNewIds)
         else:
             ret = Vedit_remove_vertex(self.poMapInfo, poList,
-                                      self.poPoints, thresh)
+                                      self.poPoints, thresh, poNewIds)
+
+        new_id = poNewIds.contents.value[0]
+        Vect_destroy_list(poNewIds)
         Vect_destroy_list(poList)
+
+        if new_id > -1:
+            new_geom = self._getGeom(new_id)
+            new_areas_cats = self._getLineAreasCategories(new_id)
         
         if not add and ret > 0 and self._settings['breakLines']:
             self._breakLineAtIntersection(Vect_get_num_lines(self.poMapInfo),
                                           None)
-        
+
         if ret > 0:
             self._addChangeset()
-                
+
+        if new_id > -1:
+            if add:
+                self.vertexAdded.emit(old_geom = old_geom, new_geom = new_geom)
+            else:
+                self.vertexRemoved.emit(old_geom = old_geom, 
+                                        new_geom = new_geom,
+                                        old_areas_cats = old_areas_cats,
+                                        new_areas_cats = new_areas_cats)
+
         return 1
     
     def GetLineCats(self, line):



More information about the grass-commit mailing list