[GRASS-SVN] r42070 - grass-addons/gui/wxpython/data_catalog

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 1 05:30:33 EDT 2010


Author: rashadkm
Date: 2010-05-01 05:30:31 -0400 (Sat, 01 May 2010)
New Revision: 42070

Modified:
   grass-addons/gui/wxpython/data_catalog/LayerTree.py
   grass-addons/gui/wxpython/data_catalog/mapdisplay.py
Log:
fixed multiple location issues

Modified: grass-addons/gui/wxpython/data_catalog/LayerTree.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/LayerTree.py	2010-05-01 08:57:41 UTC (rev 42069)
+++ grass-addons/gui/wxpython/data_catalog/LayerTree.py	2010-05-01 09:30:31 UTC (rev 42070)
@@ -55,8 +55,12 @@
         self.ID_COPY = wx.NewId()
         self.ID_DEL = wx.NewId()
         self.ID_OSSIM = wx.NewId()
+        self.ID_OSSIM2 = wx.NewId()
         self.ID_INFO = wx.NewId()
         self.ID_REPORT = wx.NewId()
+        self.ID_AREA = 200
+        self.ID_LENGTH = 201
+        self.ID_COOR = 202
 
         acel = wx.AcceleratorTable([ 
 		        (wx.ACCEL_CTRL,  ord('R'), self.ID_REN ) ,
@@ -68,6 +72,9 @@
 
         self.dict = {}
 
+        self.colour = '0:0:0'  #default colour for vector lines
+        self.colour_selected = False
+
         self.layer = []
         self.maplayer = None
 
@@ -82,8 +89,8 @@
 
         self.MapWindow = self.mapdisplay.MapWindow2D
         self.Bind(CT.EVT_TREE_ITEM_CHECKED,     self.OnLayerChecked)
+        self.Bind(CT.EVT_TREE_ITEM_ACTIVATED,     self.ChooseColour)
 
-
         self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK,self.OnTreePopUp)
         self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnEndRename)
         self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnBeginRename)
@@ -93,10 +100,41 @@
         self.Bind(wx.EVT_MENU,self.OnRename,id=self.ID_REN)
         self.Bind(wx.EVT_MENU,self.OnDelete,id=self.ID_DEL)
         self.Bind(wx.EVT_MENU,self.OnOssim,id=self.ID_OSSIM)
+        self.Bind(wx.EVT_MENU,self.OnOssim2,id=self.ID_OSSIM2)
         self.Bind(wx.EVT_MENU,self.OnInfo,id=self.ID_INFO)
         self.Bind(wx.EVT_MENU,self.OnReport,id=self.ID_REPORT)
+        self.Bind(wx.EVT_MENU,self.OnvReport,id=self.ID_AREA)
+        self.Bind(wx.EVT_MENU,self.OnvReport,id=self.ID_LENGTH)
+        self.Bind(wx.EVT_MENU,self.OnvReport,id=self.ID_COOR)
 
 
+    def ChooseColour(self,event):
+
+        colourdialog = wx.ColourDialog(self)
+        colourdialog.ShowModal()
+        rgb = colourdialog.GetColourData().GetColour()
+        rgb = str(rgb)
+        self.colour = rgb.replace(',',':')
+        self.colour = self.colour.strip('(')
+        self.colour = self.colour.strip(')')
+
+        item = event.GetItem()
+        col = colourdialog.GetColourData().GetColour()
+
+        self.SetHilightFocusColour(col)
+        self.SetItemTextColour(item,col)
+        item =  event.GetItem()
+        parent = self.GetItemParent(item)
+        if self.IsItemChecked(parent):
+            self.colour_selected = True
+            self.CheckItem(parent)
+        else:
+            self.CheckItem(parent)
+        
+   
+
+
+
     def OnInfo(self,event):
 
         item =  self.GetSelection()
@@ -127,7 +165,6 @@
         notebook = leftpanel.GetParent()
         frame = notebook.GetParent()
 
-        notebook.SetSelection(2)
         
         if not self.ItemHasChildren(item):
             self.mapname =  self.GetItemText(item) + "@" + frame.cmbMapset.GetValue()
@@ -135,15 +172,38 @@
             if pText == "Raster Map" :
                 command = ["r.report", 'map=' +  self.mapname]
                 frame.goutput.RunCmd(command)
-            if pText == "Vector Map" :
-                command = ["v.report", 'map=' +  self.mapname]
-                frame.goutput.RunCmd(command)
+#            if pText == "Vector Map" :
+#                command = ["v.report", 'map=' +  self.mapname]
+#                frame.goutput.RunCmd(command)
 
         
+    def OnvReport(self,event):
 
+        item =  self.GetSelection()
+        Id = event.GetId()
+        if Id == 200:
+            option = 'area'
+        elif Id == 201:
+            option = 'length'
+        elif Id == 202:
+            option = 'coor'
+        parent = self.GetItemParent(item)
+        pText = self.GetItemText(parent)
 
+        leftpanel=self.GetParent()
+        notebook = leftpanel.GetParent()
+        frame = notebook.GetParent()
 
+        
+        #if not self.ItemHasChildren(item):
+        self.mapname =  self.GetItemText(item) + "@" + frame.cmbMapset.GetValue()
+        command = ["v.report", 'map=' +  self.mapname,'option=' + str(option)]
+        frame.goutput.RunCmd(command)
 
+
+
+
+
     def OnLayerChecked(self, event):
         """!Enable/disable data layer"""
 
@@ -159,44 +219,54 @@
         frame = notebook.GetParent()
 
 
-        if not self.ItemHasChildren(item):
-            self.mapname =  self.GetItemText(item) + "@" + frame.cmbMapset.GetValue()
-            #for f in frames:
-            #    print f.GetName()     
-            #maptree = mapframe.maptree
 
-            if pText == "Raster Map" :
+
+
+        self.mapname =  self.GetItemText(item) + "@" + frame.cmbMapset.GetValue()
+        #for f in frames:
+        #    print f.GetName()     
+        #maptree = mapframe.maptree
+
+        if pText == "Raster Map" :
+            if checked == True:
                 self.cmd= ['d.rast', str("map=" + self.mapname)]
-                l_type='raster'
-                
-                self.maplayer = self.MapWindow.Map.AddLayer(type='raster', name=self.mapname, command=self.cmd)
-               
+                maplayer = self.MapWindow.Map.AddLayer(type='raster', name=self.mapname, command=self.cmd)
+                self.layer_selected = maplayer
+                self.type = 'raster'
+            else:
+                layers =  self.MapWindow.Map.GetListOfLayers( l_type='raster', l_name=self.mapname)
+                for layer in layers:
+                    self.MapWindow.Map.DeleteLayer(layer)
+                    self.MapWindow.EraseMap()
+        
+        
 
-                #layer = maptree.PrependItem(parent=maptree.root, text=self.mapname, ct_type=1)
-                #maptree.first = True
-                #maptree.layer_selected = layer
-                #maptree.CheckItem(layer)
-                #self.layer.append(self.maplayer)
-                #maptree.PlusLayer(self.maplayer)
 
+        if pText == "Vector Map" :
+            if checked == True:
+                self.cmd= ['d.vect', str("map=" + self.mapname),str('color=' +  self.colour)]
+                if self.colour_selected == False:
+                    maplayer = self.MapWindow.Map.AddLayer(type='vector', name=self.mapname, command=self.cmd)
+                else:
+                    self.colour_selected = False
+                    layers =  self.MapWindow.Map.GetListOfLayers( l_type='vector', l_name=self.mapname)
+                    for layer in layers:
+                        maplayer=layer.__init__(type='vector', name=self.mapname, cmd=self.cmd)
+                self.layer_selected = maplayer
+                self.type = 'vector'
+            else:
+                layers =  self.MapWindow.Map.GetListOfLayers( l_type='vector', l_name=self.mapname)
+                for layer in layers:
+                    self.MapWindow.Map.DeleteLayer(layer)
+                    self.MapWindow.EraseMap()
+        
+        self.MapWindow.Map.region = self.MapWindow.Map.GetRegion()
+        self.MapWindow.flag = True
+        self.MapWindow.UpdateMap(render=True)
+        self.MapWindow.flag = False
 
-            if pText == "Vector Map" :
-                self.cmd= ['d.vect', str("map=" + self.mapname)]
-                l_type='vector'
-                
-                self.maplayer = self.MapWindow.Map.AddLayer(type='vector', name=self.mapname, command=self.cmd)
 
 
-            self.MapWindow.Map.region = self.MapWindow.Map.GetRegion()
-            self.MapWindow.flag = True
-            self.MapWindow.UpdateMap(render=True)
-            self.MapWindow.flag = False
-                #layer = maptree.PrependItem(parent=maptree.root, text=self.mapname, ct_type=1)
-                #maptree.first = True
-                #maptree.layer_selected = layer
-                #maptree.CheckItem(layer)
-                #self.layer.append(self.maplayer)
-                #maptree.PlusLayer(self.maplayer)
 
 
 
@@ -217,15 +287,16 @@
         glocs = glob.glob(os.path.join(self.gisdbase,location, mapset,"*"))
         for gloc in glocs:
             if not os.path.isfile(gloc) and os.path.isdir(gloc):
-	            if(os.path.basename(gloc)=='cellhd'):
-		            for rast in glob.glob(os.path.join(self.gisdbase,location, mapset,gloc, "*")):
-			            self.PrependItem(node_raster, os.path.basename(rast),ct_type=1)
-	            elif(os.path.basename(gloc)=='vector'):
-		            for vect in glob.glob(os.path.join(self.gisdbase,location, mapset,gloc, "*")):
-			            self.PrependItem(node_vector, os.path.basename(vect),ct_type=1)
-	            elif(os.path.basename(gloc)=='dbf'):
-		            for dfile in glob.glob(os.path.join(self.gisdbase,location, mapset,gloc, "*")):
-			            self.PrependItem(node_dbf, os.path.basename(dfile),ct_type=1)
+                if(os.path.basename(gloc)=='cellhd'):
+                    for rast in glob.glob(os.path.join(self.gisdbase,location, mapset,gloc, "*")):
+	                    self.PrependItem(node_raster, os.path.basename(rast),ct_type=1)
+                elif(os.path.basename(gloc)=='vector'):
+                    for vect in glob.glob(os.path.join(self.gisdbase,location, mapset,gloc, "*")):
+                        vectormap = self.PrependItem(node_vector, os.path.basename(vect),ct_type=1)
+                        self.PrependItem(vectormap, "colour")
+                elif(os.path.basename(gloc)=='dbf'):
+                    for dfile in glob.glob(os.path.join(self.gisdbase,location, mapset,gloc, "*")):
+	                    self.PrependItem(node_dbf, os.path.basename(dfile),ct_type=1)
 
         #Nodes with no children are given an italic type font
         for node in treeNodes: 
@@ -243,13 +314,7 @@
         self.SortChildren(node_vector)
         self.SortChildren(node_dbf)
 
-    def OnToggleExpand(self,event):  
-	    if self.treeExpand.GetValue() == True:
-		    self.ExpandAll()
-	    else: 
-		    self.CollapseAll()
 
-
     def OnBeginRename(self,event):
 
         item = self.GetItemText(event.GetItem())
@@ -283,16 +348,34 @@
         Display a popupMenu for copy,rename & delete operations
         """
         item =  event.GetItem()
-        if not self.ItemHasChildren(item) and \
-               self.GetItemFont(item) != self.itemFont:
-
+        parent = self.GetItemParent(item)
+        pText = self.GetItemText(parent)
+      #  if not self.ItemHasChildren(item) and \
+      #         self.GetItemFont(item) != self.itemFont:
+        if self.GetItemText(item)!='Raster Map' and \
+                self.GetItemText(item)!='Vector Map' and \
+                self.GetItemText(item)!='DBF' and \
+                self.GetItemText(item)!='colour' and \
+                self.GetItemFont(item) != self.itemFont:
             self.popupmenu = wx.Menu()
             mnuCopy = self.popupmenu.Append(self.ID_COPY,'&Copy\tCtrl+C')
             mnuRename = self.popupmenu.Append(self.ID_REN,'&Rename\tCtrl-R')
             mnuDel = self.popupmenu.Append(self.ID_DEL,'&Delete\tDEL')
-            mnuOssim = self.popupmenu.Append(self.ID_OSSIM,'&send to OssimPlanet')
+            #self.popupmenu.AppendSeperator()
+            mnuOssim = self.popupmenu.Append(self.ID_OSSIM,'&Send to OssimPlanet')
+            mnuOssim = self.popupmenu.Append(self.ID_OSSIM2,'&Remove from OssimPlanet')
+            #self.popupmenu.AppendSeperator()
             mnuInfo = self.popupmenu.Append(self.ID_INFO,'&Info')
-            mnuReport = self.popupmenu.Append(self.ID_REPORT,'&Report')
+
+            if pText == 'Vector Map':
+                mnuReport = wx.Menu()
+                mnuReport.Append(self.ID_AREA, 'Area')
+                mnuReport.Append(self.ID_LENGTH, 'Length')
+                mnuReport.Append(self.ID_COOR, 'Coordinate')
+                self.popupmenu.AppendMenu(wx.ID_ANY, 'Report', mnuReport)
+            else:
+                mnuReport =self.popupmenu.Append(self.ID_REPORT,'&Report')
+
             self.PopupMenu(self.popupmenu)
 
 
@@ -399,23 +482,58 @@
 
     def OnOssim( self,event ):
         """
-        Performs grass command for deleting a map
+        Performs grass command for adding a map
         """
         item =  self.GetSelection()
-        
+        cmdflag = None
         parent  =self.GetItemParent(item) 
         if self.GetItemText(parent) == "Raster Map" :
             cmdflag = 'r.planet.py -a map=' + str(self.GetItemText(item))
-        elif self.GetItemText(parent) == "Vector Map" :
-            cmdflag = 'v.planet.py -a map=' + str(self.GetItemText(item))
+        else:
+            if self.GetItemText(item) == 'colour':
+                col=self.GetItemTextColour(item)
+                mapname = self.GetItemParent(item)
+            else:
+                child,cookie = self.GetFirstChild(item)
+                mapname = item
+                col = self.GetItemTextColour(child)
+            if col.IsOk() is True:
+                col=str(col)
+                col = col.replace('(','')
+                col = col.replace(')','')
+                col = col.split(',')
 
-        if cmdflag:
-            
-            #command = ["r.planet.py", cmdflag]
-            #gcmd.CommandThread(command,stdout=None,stderr=None).run()
+                cmdflag = 'v.planet.py -a map=' + str(self.GetItemText(mapname)) + \
+                            ' brush=' + str(col[0].strip()+','+col[1].strip()+','+col[2].strip()) + \
+                            ' pen=' + str(col[0].strip()+','+col[1].strip()+','+col[2].strip()) + \
+                            ' size=' +str('1,1')
+                #print cmdflag
+
+        if cmdflag is not None:        
             current = OssimPlanet(cmdflag)
             current.start()
 
+
+
+    def OnOssim2( self,event ):
+        """
+        Performs grass command for deleting a map
+        """
+        item =  self.GetSelection()
+        cmdflag = None
+        parent  =self.GetItemParent(item) 
+        if self.GetItemText(parent) == "Raster Map" :
+            cmdflag = 'r.planet.py -r map=' + str(self.GetItemText(item))
+        else:
+            if self.GetItemText(item) == 'colour':
+                previtem = self.GetItemParent(item)
+                cmdflag = 'v.planet.py -r map=' + str(self.GetItemText(previtem))
+            else:
+                cmdflag = 'v.planet.py -r map=' + str(self.GetItemText(item))
+
+        if cmdflag is not None:
+            current = OssimPlanet(cmdflag)
+            current.start()
         
 
     def OnDisplay(self, event):

Modified: grass-addons/gui/wxpython/data_catalog/mapdisplay.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/mapdisplay.py	2010-05-01 08:57:41 UTC (rev 42069)
+++ grass-addons/gui/wxpython/data_catalog/mapdisplay.py	2010-05-01 09:30:31 UTC (rev 42070)
@@ -76,6 +76,8 @@
 from debug import Debug
 from preferences import globalSettings as UserSettings
 
+from tcp4ossim import zoomto 
+
 from LayerTree import LayerTree
 
 from threading import Thread
@@ -2430,7 +2432,8 @@
         self.MapWindow2D = BufferedWindow(self, id=wx.ID_ANY,   Map=self.Map, tree=self.tree, gismgr=self._layerManager)
         # default is 2D display mode
         self.MapWindow = self.MapWindow2D
-        #self.MapWindow.Bind(wx.EVT_MOTION, self.OnMotion)
+        self.MapWindow.Bind(wx.EVT_MOTION, self.OnMotion)
+        self.MapWindow.Bind(wx.EVT_LEFT_DOWN, self.OnClick) 
         self.MapWindow.SetCursor(self.cursors["default"])
         # used by Nviz (3D display mode)
         self.MapWindow3D = None 
@@ -2528,6 +2531,27 @@
 
         #r.rightSizer.Add(self.maptree)
 
+    def OnClick(self,event): 
+	 	        if self.frame.radiobox.GetSelection() == 0: 
+	 	            x, y = self.MapWindow.Pixel2Cell(event.GetPosition()) 
+	 	            out = subprocess.Popen(['m.proj', '-o'], stdout=subprocess.PIPE,  stdin=subprocess.PIPE).communicate("%s %s" % (x,y))[0] 
+	 	            f = out.replace("'"," ").replace('d',' ').replace('"',' ').replace('\n','').split('\t') 
+	 	            lon = f[0].split(' ') 
+	 	            lat = f[1].split(' ')[:-1] 
+	 	            if lat[-1] == 'N': 
+	 	                signlat = 1 
+	 	            if lat[-1] == 'S': 
+	 	                signlat = -1 
+	 	            if lon[-1] == 'E': 
+	 	                signlon = 1 
+	 	            if lon[-1] == 'W': 
+	 	                signlon = -1 
+	 	            lat = (float(lat[0]) + (float(lat[1]) / 60) + float(lat[2]) / 3600) * float(signlat) 
+	 	            lon = (float(lon[0]) + (float(lon[1]) / 60) + float(lon[2]) / 3600) * float(signlon) 
+	 	            self.frame.mInfo.SetValue(str(lat) + ' , ' + str(lon)) 
+	 	            zoomto(str(lon),str(lat),15000) 
+	 	        event.Skip() 
+
     def read_gisrc(self):
 	    """
 	    Read variables gisrc file



More information about the grass-commit mailing list