Support second Altium BOM format
[eda-utils.git] / bomgen / bomgen.php
index a1fc03b..de00211 100755 (executable)
@@ -50,8 +50,8 @@ $csv_infos =
                                   "width" => 30),
         COMPANY_PN_COL_NAME => array("nom"   => "LSI P/N",
                                   "width" => 15),
-        "PatternName"    => array("nom"   => "Footprint",
-                                  "width" => 20),
+        FOOTPRINT_COL_NAME => array("nom"   => "Footprint",
+                                    "width" => 20),
         ASSEMBLY_COL_NAME => array("nom"   => "Assembly",
                                   "width" => 0),
         "UnitCost"       => array("nom"   => "Unit Cost",
@@ -307,23 +307,36 @@ if (($handle = fopen($src, "r")) !== FALSE) {
 /* Combinaison de plusieurs lignes en une seule pour PCAD. */
 refdes_combine($data, $num, $col_num_to_id, $col_id_to_num);
 
+$voltage_present = false;
+
 /* Génère une liste des colonnes pour le tri. */
 foreach ($data as $key => $row) {
   $sort_type[$key]  = $row[$col_id_to_num['Type']];
   $sort_desc[$key] = $row[$col_id_to_num['Description']];
   $sort_val[$key] = $row[$col_id_to_num['Value']];
-  $sort_volt[$key] = $row[$col_id_to_num['Voltage']];
+
+  if (isset($col_id_to_num['Voltage'])) {
+    $voltage_present = true;
+    $sort_volt[$key] = $row[$col_id_to_num['Voltage']];
+  }
 }
 
 /*
  * Triage des lignes selon la référence (colonne DESIGNATOR_COL_NAME),
  * et ensuite selon la description, la valeur et enfin le voltage.
  */
-array_multisort($sort_type, SORT_ASC, SORT_STRING,
-                $sort_desc, SORT_ASC, SORT_STRING,
-                $sort_val,  SORT_ASC, SORT_NUMERIC,
-                $sort_volt, SORT_ASC, SORT_NUMERIC,
-                $data);
+if ($voltage_present) {
+  array_multisort($sort_type, SORT_ASC, SORT_STRING,
+                  $sort_desc, SORT_ASC, SORT_STRING,
+                  $sort_val,  SORT_ASC, SORT_NUMERIC,
+                  $sort_volt, SORT_ASC, SORT_NUMERIC,
+                  $data);
+} else {
+  array_multisort($sort_type, SORT_ASC, SORT_STRING,
+                  $sort_desc, SORT_ASC, SORT_STRING,
+                  $sort_val,  SORT_ASC, SORT_NUMERIC,
+                  $data);
+}
 
 if ($digikey_bom) {
   /* Exportation BOM digikey. */