Implement drawing of APs from database
authorjaviplx <javiplx@gmail.com>
Mon, 11 Oct 2010 21:29:01 +0000 (21:29 +0000)
committerjaviplx <javiplx@gmail.com>
Mon, 11 Oct 2010 21:29:01 +0000 (21:29 +0000)
git-svn-id: file:///svnroot/wifihood/trunk@55 c51dfc6a-5949-4919-9c8e-f207a149c383

wifiscanner/wifiview

index a1bbd8c..185ca13 100755 (executable)
@@ -12,7 +12,7 @@ import math
 
 import os
 
-import wifimap.config
+import wifimap.config , wifimap.db
 
 class mapWidget ( gtk.Image ) :
 
@@ -53,6 +53,16 @@ class mapWidget ( gtk.Image ) :
     tiley = math.pi * ( 1 - 2 * ( tiley + pixy/self.tile_size ) / 2.0 ** zoom )
     return math.degrees( math.atan( math.sinh( tiley ) ) )
 
+  def gps2pix ( self , ( lat , lon ) , ( center_x , center_y ) ) :
+
+    x_pos = self.lon2tilex( lon , self.conf.zoom )
+    y_pos = self.lat2tiley( lat , self.conf.zoom )
+
+    dest_x = self.tile_size * ( x_pos[0] - self.reftile_x ) + center_x + x_pos[1]
+    dest_y = self.tile_size * ( y_pos[0] - self.reftile_y ) + center_y + y_pos[1]
+
+    return dest_x , dest_y
+
   def composeMap( self ) :
     center_x , center_y = self.win_x / 2 , self.win_y / 2
 
@@ -115,20 +125,23 @@ class mapWidget ( gtk.Image ) :
     blue = pixmap.new_gc()
     blue.foreground = pixmap.get_colormap().alloc_color("blue")
 
-    filename = "/tmp/vale/wiscan_gui.campus.info"
+    filename = "data/wiscan_gui.info.old"
     fd = open( filename )
     for line in fd.readlines() :
         values = line.split()
-
-        x_pos = self.lon2tilex( float(values[6]) , self.conf.zoom )
-        y_pos = self.lat2tiley( float(values[5]) , self.conf.zoom )
-
-        dest_x = self.tile_size * ( x_pos[0] - self.reftile_x ) + center_x + x_pos[1]
-        dest_y = self.tile_size * ( y_pos[0] - self.reftile_y ) + center_y + y_pos[1]
-
-        pixmap.draw_rectangle(blue, True , dest_x , dest_y , 3 , 3 )
+        if values[1] == "FIX" :
+            dest_x , dest_y = self.gps2pix( ( float(values[5]) , float(values[6]) ) , ( center_x , center_y ) )
+            pixmap.draw_rectangle(blue, True , dest_x , dest_y , 3 , 3 )
     fd.close()
 
+    db = wifimap.db.database( os.path.join( self.conf.homedir , self.conf.dbname ) )
+    db.open()
+    for ap in db.execute( "SELECT * FROM ap" ) :
+        if ap[3] > 1 :
+            dest_x , dest_y = self.gps2pix( ( ap[4]/ap[3] , ap[5]/ap[3] ) , ( center_x , center_y ) )
+            pixmap.draw_rectangle(red, True , dest_x , dest_y , 3 , 3 )
+    db.close()
+
     self.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.win_x, self.win_y )