List Info

Thread: Re: Multi-channel amplifier board




Re: Multi-channel amplifier board
country flaguser name
United States
2007-10-23 07:29:27


> Is this a good approach or is there a better way to do this ?

The following Perl script may help. It will array the modules and
tracks of a .brd file and, by default, increment the reference
designators for the components.

Try placing the amp section as sub-pages and create corresponding brd
file for the section. Then use the schematic editor's annotation tool
to renumber, which seems to stack the numbering in such a way that
the resulting netlist will match the module numbering in the output,
duplicated brd file.

---8<--- KDupe.pl ---8<------8<---
#!/usr/bin/perl

# KDupe
#
# Given a KiCad .brd file that contains a collection of components,
# produce a new .brd file with that collection duplicated to a
rectangular
# array with the reference designators incremented appropriately for
# each collection.
#
# Arguments: [input filename] [columns] [rows] [x-offset] [y-offset]
# Output is the input filename with a -blk appended to the base name.
#
# Example: perl dupe.pl test.brd 8 1 1 0
# duplicates the contents of test.brd 8 times in the x direction,
# each offset by 1 unit in the new file test-blk.brd.
#
# Example: perl dupe.pl test.brd 4 2 1 2
# places the contents of test.brd into a 4 column, 2 row array
# offset by 1 unit in the x direction, 2 in the y.
#
# Note: the "units" are based on the internal units found in the
# .brd file's $SETUP section.
#
# Note: The netlist section is passed through unchanged. Be sure to
# re-read the netlist upon opening the modified board file.
#
# Reference designators may start at an arbitrary value. Offset values
# in the duplicated components start at one greater than the highest
# value of that type in the base component.
# U1, U2, U3 -> U4, U5, U6 and U7, U8, U9 and so on ...
#
# Reference designators are assumed to be a single alpha character
# followed by a number consisting of one or more digits.
#
# A trailing "r&quot; or "R&quot; after the offset arguments indicates that
# the refrence designators should NOT be adjusted.
#
#
# KDupe is Copyright (C) 2007 Richard Webb
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA

use warnings;

# For those who never read comments or who <ahem&gt; forget the syntax
# after a while:

if ($#ARGV != 4 && $#ARGV != 5) {
print(&quot;Given a KiCad .brd file that contains a collection of
components,n";);
print(&quot;produce a new .brd file with that collection duplicated to
a rectangularn");
print(&quot;array with the reference designators incremented
appropriately forn");
print(&quot;each collection.n");
print(&quot;nArguments: [input filename] [columns] [rows] [x-
offset] [y-offset] n");
print(&quot;Output is the input filename with a -blk appended to the
base name.n&quot;);
print(&quot;nExample: perl dupe.pl test.brd 8 1 1 0n");
print(&quot;duplicates the contents of test.brd 8 times in the x
direction,n");
print(&quot;each offset by 1 unit in the new file test-blk.brd.n");
print(&quot;nExample: perl dupe.pl test.brd 4 2 1 2n");
print(&quot;places the contents of test.brd into a 4 column, 2 row
arrayn&quot;);
print(&quot;offset by 1 unit in the x direction, 2 in the y.n");
print(&quot;nNote: the "units" are based on the internal units
found in then");
print(&quot;.brd file's $SETUP section.n&quot;);
print(&quot;n");
print(&quot;Note: The netlist section is passed through unchanged. Be
sure ton");
print(&quot;re-read the netlist upon opening the modified board
file.n&quot;);
print(&quot;nReference designators may start at an arbitrary value.
Offset valuesn&quot;);
print(&quot;in the duplicated components start at one greater than the
highestn");
print(&quot;value of that type in the base component.n");
print(&quot;U1, U2, U3 -> U4, U5, U6 and U7, U8, U9 and so on ...n");
print(&quot;nReference designators are assumed to be a single alpha
charactern");
print(&quot;followed by a number consisting of one or more
digits.nn");
print(&quot;A trailing "r&quot; or "R&quot; after the offset arguments
indicates thatn";);
print(&quot;the refrence designators should NOT be adjusted.n");
exit;
}

open (IFILE, $ARGV[0]) or die "$ARGV[0]: $!";
$extpos = rindex($ARGV[0], ".brd");
if ($extpos == -1) {
printf(&quot;%s: not a .brd filen";, $ARGV[0]);
exit();
}
$oname = substr($ARGV[0], 0, $extpos) . "-blk.brd";
open (OFILE, "> " . $oname) or die "$oname: $!";

$mod_count = 0;
$state = 0;

$cols = $ARGV[1];
$rows = $ARGV[2];
$xoff = $ARGV[3];
$yoff = $ARGV[4];

if ($#ARGV == 5 && ($ARGV[5] eq 'r' || $ARGV[5] eq 'R')) {
$adjust = 0;
} else {
$adjust = 1;
}

if ($cols <= 0 || $rows <= 0) {
printf(&quot;rows and cols must each be >= 1n");
exit;
}

while (<IFILE>) {
if (/^InternalUnit/) {
args = split(/ /);
$scale = $args[1];
}

if ($state == 0) {
# pre-module, so just copy input to output
if (/^$MODULE/) {
$state = 1;
} else {
printf(OFILE "%s&quot;, $_);
}
}
if ($state == 1) {
# handle the module section
if (/^$MODULE/) {
# save each module, keep track of the ref desigs
push mods, ( $_ );
} elsif (/^$EndMODULE/) {
push mods, ( $_ );
++$mod_count;
} elsif (/^$TRACK/) {
# Here is where the duplicate modules are created and
written
# to the output file.
# When we're done here, we'll do the tracks.
$modcount = 0;
for $r (0 .. $rows - 1) {
for $c (0 .. $cols - 1) {
$x_offset = $c * $xoff / $scale;
$y_offset = $r * $yoff / $scale;
$inmodule = 0;
foreach $m (mods) {
if ($m =~ /^Po/) {
if ($inmodule == 0) {
$inmodule = 1;
args = split(/ /, $m);
$x = $args[1] + $x_offset;
$y = $args[2] + $y_offset;
printf(OFILE "%s %d %d %s %s %s %s
%s",
$args[0], $x, $y, $args[3],
$args[4],
$args[5], $args[6], $args[7]);
} else {
printf(OFILE "%s&quot;, $m);
}
} elsif ($m =~ /^T0/) {
if ($adjust) {
args = split(/&quot;/, $m);
$aref = substr($args[1], 0, 1);
$adesig = substr($args[1], 1);
$adesig +=
$modcount * (1 + $rmax{$aref} -
$rmin{$aref});
printf(OFILE "%s "%s%d"n&quot;,
$args[0], $aref, $adesig);
} else {
printf(OFILE "%s&quot;, $m);
}
} else {
printf(OFILE "%s&quot;, $m);
}
if ($m =~ /^$EndMODULE/) {
$inmodule = 0;
}
}
++$modcount;
}
}
printf(OFILE "%s&quot;, $_);
$state = 2;
} else {
push mods, $_;
if (/^T0/) {
# grab the reference designators here
args = split(/&quot;/);
$rd = $args[1];
$ref = substr($rd, 0, 1);
$desig = substr($rd, 1);

if (!exists $refs{$ref}) {
$refs{$ref} = 1;
$rmax{$ref} = $desig;
$rmin{$ref} = $desig;
} else {
if ($desig > $rmax{$ref}) {
$rmax{$ref} = $desig;
} elsif ($desig < $rmin{$ref}) {
$rmin{$ref} = $desig;
}
}
}
}
}
if ($state == 2) {
# do similar tricks for the tracks
# collect the info here
if (!/^$/) {
push tracks, ( $_ );
}
if (/^$EndTRACK/) {
# now emit it
for $r (0 .. $rows - 1) {
for $c (0 .. $cols - 1) {
$x_offset = $c * $xoff / $scale;
$y_offset = $r * $yoff / $scale;
foreach $t (tracks) {
if ($t =~ /^Po/) {
args = split(/ /, $t);
$x0 = $args[2] + $x_offset;
$y0 = $args[3] + $y_offset;
$x1 = $args[4] + $x_offset;
$y1 = $args[5] + $y_offset;
printf(OFILE "%s %s %d %d %d %d %s %s",
$args[0], $args[1], $x0, $y0, $x1,
$y1,
$args[6], $args[7]);
} else {
printf(OFILE "%s&quot;, $t);
}
}
}
}
$state = 3;
}
}
if ($state == 3) {
# Zones are not handled
printf(OFILE "%s&quot;, $_);
if (/^$EndBOARD/) {
$state = 4;
}
}
if ($state == 4) {
printf("Done. Wrote %s.n", $oname);
# optional
if (0) {
printf(&quot;Original ref desig ranges:n&quot;, $oname);
foreach $key (keys %refs) {
printf(" %s %d-%dn&quot;, $key, $rmin{$key},
$rmax{$key});
}
}
$state = 5; # trap dangling lines
}
}
---8<------8<------8<---

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )