[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: PCB step and repeat for hierarchy
On Tue, Feb 17, 2009 at 04:42:12PM +0000, carzrgr8@xxxxxxxxxxxxx wrote:
>
> So here's the plan:
> 1. Place and route all the parts of one hierarchical block, for example S1/S101.
> 2. Select all the parts from S2/S101 and delete them ( I don't think there's a 'delete
> selected' menu, but 'cut to buffer' should work out).
> 3. Copy/paste S1/S101. For now, there's going to be 2 copies of S1/S101/partNum.
> 4. Select the copied section.
> 5. Save the layout. I noticed that the .pcb file retains the the attribute 'selected' which will
> help me filter the file.
> 6. Filter the file, renaming all the 'selected' parts that match 'S1/S101' with 'S2/S101'.
I planned my subcircuit layout in Inkscape (free vector drawing program)
because I wanted a graphical representation anyway. When it came time to
place the subcircuits, I decided to try to re-use the drawing. It's saved
as SVG (XML) and SVG::Parser makes it pretty easy to work with in perl.
Inkscape has a 'label' attribute for objects (becomes 'inkscape:label' in
the XML). My script looks for objects with labels and creates a copy of
the subcircuit with the refdes's modified for each one. At the same time
it makes a PCB script (for use with :ExecuteFile()) to place all of the
copies. I never did work out exactly what the 'mark' was in a pasted file,
but it didn't matter much for my application.
I've attached the script.
--
Ben Jackson AD7GD
<ben@xxxxxxx>
http://www.ben.com/
#!/usr/bin/perl
use warnings;
use strict;
use SVG::Parser;
use Data::Dumper;
# px to mil, 90 dpi
sub S { $_[0] / 90 * 1000 }
my $xml = do { local $/ = undef; <> };
my $parser = new SVG::Parser();
my $svg = $parser->parse($xml);
open PCB_SRC, "onekey.pcb" || die "can't open src: $!";
my $pcb_src = do { local $/ = undef; <PCB_SRC> };
my @rects = $svg->getElements('rect');
foreach my $r (@rects) {
my $refdes = $r->getAttribute('inkscape:label');
my $x = S($r->getAttribute('x'));
my $y = S($r->getAttribute('y'));
my $w = S($r->getAttribute('width'));
my $h = S($r->getAttribute('height'));
#print "$refdes ($x, $y) $w x $h\n";
$x = $x + $w / 2;
$y = $y + $h / 2 + 2000 + 1000;
my $wide = ($w > 1400);
my $pcb_copy = $pcb_src;
$pcb_copy =~ s/"X\?/"$refdes/g;
open COPY, ">tmp/copy_$refdes.pcb";
print COPY $pcb_copy;
close COPY;
printf "LoadFrom(LayoutToBuffer, tmp/copy_$refdes.pcb)\n";
printf "PasteBuffer(ToLayout,%d,%d,mil)\n", int($x), int($y)+2;
}
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user