2013-10-14 19:31:42 +03:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# fped2stl.pl - Convert fped 2D stacks to STL meshes
|
|
|
|
#
|
|
|
|
# Written 2013 by Werner Almesberger
|
|
|
|
# Copyright 2013 Werner Almesberger
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
use POSIX;
|
|
|
|
|
|
|
|
sub usage
|
|
|
|
{
|
|
|
|
print STDERR "usage: $0 prefix [file ...]\n\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub flush
|
|
|
|
{
|
|
|
|
local ($z1) = sprintf("%e", $_[0]);
|
|
|
|
|
|
|
|
$z = sprintf("%e", $z);
|
|
|
|
return unless defined $s;
|
|
|
|
print STDERR "$name $z ...\n";
|
|
|
|
$^F = 20;
|
|
|
|
pipe SR, SW;
|
|
|
|
pipe RR, RW;
|
|
|
|
$pid = fork();
|
|
|
|
if (!$pid) {
|
|
|
|
close SW;
|
|
|
|
close RR;
|
|
|
|
$sn = fileno SR;
|
|
|
|
$rn = fileno RW;
|
|
|
|
open(PIPE, "|cameo >/dev/fd/$rn") || die "cameo: $!";
|
|
|
|
print PIPE "gnuplot 0mm /dev/fd/$sn\n";
|
|
|
|
print PIPE "stl\n";
|
|
|
|
close PIPE;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
close SR;
|
|
|
|
close RW;
|
|
|
|
|
|
|
|
print SW $s;
|
|
|
|
close SW;
|
|
|
|
|
|
|
|
while (<RR>) {
|
|
|
|
s/cameo/$name/;
|
2013-11-02 02:15:43 +02:00
|
|
|
s/(vertex.*)0\.0*e\+00$/$1$z/ || s/(vertex.*)1\.0*e\+00$/$1$z1/;
|
2013-10-14 19:31:42 +03:00
|
|
|
print;
|
|
|
|
}
|
|
|
|
close RR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
&usage if $ARGV[0] =~ /^-[^0-9]/;
|
|
|
|
|
|
|
|
$pfx = shift @ARGV;
|
|
|
|
&usage unless defined $pfx;
|
|
|
|
|
|
|
|
$skip = 1;
|
|
|
|
while (<>) {
|
|
|
|
if (/^# $pfx(.*?)-(\d+(\.\d*)?)\s*$/) {
|
|
|
|
&flush($2);
|
|
|
|
$name = $1;
|
|
|
|
$z = $2;
|
|
|
|
undef $s;
|
|
|
|
$skip = 0;
|
|
|
|
} elsif (/^# /) {
|
|
|
|
$skip = 1;
|
|
|
|
}
|
|
|
|
next if $skip;
|
|
|
|
next if /^#/;
|
|
|
|
$s .= $_;
|
|
|
|
}
|
|
|
|
&flush(0);
|