[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: PCB: Stale rat's nest?
Vanessa Dannenberg wrote:
What would cause PCB to not properly maintain it's rats nest and/or netlist?  
In particular, over the course of adding rats to a board I'm working on, 
moving parts, changing out parts for others, etc., PCB has made a mess of the 
netlist it saves with the board.  The rats themselves *look* right when 
they're drawn, but the list data doesn't match what's being drawn.
In the Netlist window, I find several duplicate entries, for example 
"ratDrawn1" appears several times, each time with a different pin list, some 
of which are outdated.  I've had to erase all of the rats and the netlist 
section from the PCB drawing file using a text editor, and start over from 
scratch.
This board was not created using gEDA's schematic capture tools, rather I 
decided to lay it out manually (gschema is too buggy right now, sorry).
Hi Vanessa,
I looked into this a bit and here is what I found.
Everytime pcb is exited and started again, the variable which keeps 
track of the # in ratDrawn# gets reset!  So if you exit, get back in, 
and draw more nets, you'll get duplicate names.  Now, it does appear 
that this is largely cosmetic meaning that I can't find where the name 
is used except in the netlist window.
I'm attaching two things.  The first is an awk script which will 
hopefully repair your .pcb file.  Please, please, please keep a backup! 
 Run it with
./fixnets.awk mydesign.pcb > fixed.pcb
The second is a patch to pcb which should correct this behaviour.  Now 
when it makes the decision to create a brand new net, it checks for name 
collisions and will keep incrementing the ratDrawn# counter until it 
finds a free number.
Please let me know if this fixes the problem for you.
Oh, the other question I have for you is can you elaborate on the bugs 
in gschem?  I've used it for a few years now and have found it to be 
quite stable.
-Dan
Index: rats.c
===================================================================
RCS file: /cvsroot/pcb/pcb/src/rats.c,v
retrieving revision 1.20
diff -u -2 -r1.20 rats.c
--- rats.c	2 Dec 2005 23:29:54 -0000	1.20
+++ rats.c	2 Mar 2006 22:16:56 -0000
@@ -786,4 +786,23 @@
 
 
+/*
+ * Check to see if a particular name is the name of an already existing rats
+ * line
+ */
+static int
+rat_used (char *name)
+{
+  if (name == NULL) 
+    return -1;
+
+  MENU_LOOP (&PCB->NetlistLib);
+  {
+    if (menu->Name && (strcmp(menu->Name, name) == 0) )
+      return 1;
+  }
+  END_LOOP;
+
+  return 0;
+}
 
   /* These next two functions moved from the original netlist.c as part of the
@@ -867,6 +886,16 @@
     }
   /* neither belong to a net, so create a new one */
-  menu = GetLibraryMenuMemory (&PCB->NetlistLib);
+
+  /*
+   * before creating a new rats here, we need to search
+   * for a unique name.
+   */
   sprintf (ratname, "  ratDrawn%i", ++ratDrawn);
+  while ( rat_used (ratname) )
+  {
+    sprintf (ratname, "  ratDrawn%i", ++ratDrawn);
+  }
+
+  menu = GetLibraryMenuMemory (&PCB->NetlistLib);
   menu->Name = MyStrdup (ratname, "AddNet");
   entry = GetLibraryEntryMemory (menu);
#!/usr/bin/awk -f
#
# Search for lines like:
#
#          Net("ratDrawn2" "(unknown)")
#
BEGIN {
  dcnt = 1;
}
/^[ \t]Net\(/ {
  # extract the name like ratDrawn2 (without the quotes)
  name = $0; 
  gsub(/^[ \t]Net\(\"/, "", name); 
  gsub(/\".*/, "",  name);
  style = $2;
  gsub(/\)$/, "", style);
  if( name ~ /ratDrawn[0-9]+/ ) {
    name = sprintf("ratDrawn%d", dcnt);
    dcnt++;
  }
  printf("\tNet(\"%s\" %s)\n", name, style);
  next;
}
{
  print;
}