Advertisement
Guest User

Untitled

a guest
Apr 1st, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.69 KB | None | 0 0
  1. <?php
  2.  
  3. $db = new SQLite3('/home/nicolas/Documents/tk106/tk106.sqlite');
  4. $db->loadExtension('libspatialite.so.3');
  5.  
  6.  
  7. $traces = array();
  8. $vias = array();
  9. $noeuds = array();
  10.  
  11. $nlayers = 4;
  12.  
  13. for ($layer=1; $layer<=$nlayers; $layer++) {
  14.   $traces[$layer] = array();
  15. }
  16.  
  17. for ($layer=1; $layer<=$nlayers; $layer++) {
  18.    
  19.   if ($layer == 1 || $layer == $nlayers) {
  20.    
  21.     $sql  = 'SELECT p.pkuid as pin, nomcomp, nompin, t.pkuid as trace ';
  22.     $sql .= "FROM `pins{$layer}` as p, `traces{$layer}` as t ";
  23.     $sql .= 'WHERE ST_Within(p.geometry, t.geometry) = 1';
  24.  
  25.     $results = $db->query($sql);
  26.     while ($r = $results->fetchArray()) {
  27.      
  28.       $tid = $r['trace'];
  29.      
  30.       if (array_key_exists($tid, $traces[$layer])) {
  31.     $noeud = $traces[$layer][$tid];
  32.       } else {
  33.     $noeud = count($noeuds);
  34.     $traces[$layer][$tid] = $noeud;
  35.    
  36.     $tracesToAnalyse = array(array('layer'=>$layer, 'id'=>$tid));
  37.    
  38.     while (count($tracesToAnalyse) != 0) {
  39.       $t = array_pop($tracesToAnalyse);
  40.      
  41.       foreach (getVias($t['layer'], $t['id']) as $newVia) {
  42.         if (array_key_exists($newVia, $vias)) continue;
  43.         for ($i=1; $i<=$nlayers; $i++) {
  44.           foreach(getTraces($i, $newVia) as $newTrace) {
  45.         if (array_key_exists($newTrace, $traces[$i])) continue;
  46.         $tracesToAnalyse[] = array('layer'=>$i, 'id'=>$newTrace);
  47.         $traces[$i][$newTrace] = $noeud;
  48.           }
  49.         }
  50.         $vias[$newVia] = $noeud;
  51.       }
  52.      
  53.     }
  54.    
  55.       } // end if traces
  56.       $noeuds[$noeud][$r['nomcomp']][$r['pin']] = $r['nompin'];
  57.     } // end while fetch comp
  58.   } // end if layers 1 & last
  59. } // end for layers
  60.  
  61. $txt = '';
  62. foreach ($noeuds as $ni=>$n) {
  63.   $npins = 0;
  64.   $txtnoeud = "noeud #$ni -------------------------\n";
  65.   foreach ($n as $nomcomp=>$pins) {
  66.     $nom = strtoupper($nomcomp);
  67.     foreach ($pins as $pi=>$nompin) {
  68.       $txtnoeud .= "  $nom [$pi] $nompin\n";
  69.       $npins++;
  70.     }
  71.   }
  72.   $txtnoeud .= "\n";
  73.   if ($npins > 1) $txt .=  $txtnoeud;
  74. }
  75.  
  76. file_put_contents('parts.txt', $txt);
  77.  
  78. function getVias($layer, $trace) {
  79.   global $db;
  80.   $vias = array();
  81.  
  82.   $sql  = "SELECT v.pkuid as via FROM traces{$layer} as t, vias as v ";
  83.   $sql .= "WHERE t.pkuid={$trace} AND ST_Within (v.geometry, t.geometry)";
  84.   $results = $db->query($sql);
  85.  
  86.   while ($r = $results->fetchArray()) {
  87.     $vias[] = $r['via'];
  88.   }
  89.  
  90.   return $vias;
  91. }
  92.  
  93. function getTraces($layer, $via) {
  94.   global $db;
  95.   $traces = array();
  96.  
  97.   $sql  = "SELECT t.pkuid as trace FROM traces{$layer} as t, vias as v ";
  98.   $sql .= "WHERE v.pkuid={$via} AND ST_Within (v.geometry, t.geometry)";
  99.   $results = $db->query($sql);
  100.  
  101.   while ($r = $results->fetchArray()) {
  102.     $traces[] = $r['trace'];
  103.   }
  104.  
  105.   return $traces;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement