[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: Christmas wishlist



Peter Clifton:
> On Sat, 2010-12-25 at 16:06 +0100, Karl Hammar wrote:
...
> > Like, here is a led and resistor, we want to feed it with 12V, 5V etc.,
> > or is that more a job for gschem?
> That is beyond what we probably want to teach gschem.

Ok.

> Explicit parameter passing between hierarchy modules is probably a good
> idea though,
...

Yes, I think so.

...
> Personally, I see this kind of tool as more of a pre-schematic stage,
...

  Ok, just tossing ideas with a preprocessor, take e.g. a fuse holder:

Element["" "stelvio_ptf_15" "" "" 0 0 0 0 0 100 ""]
(
	Pin [ -44500 0 3.75mm 0.5mm 3.9mm 1.5mm "1" "1" "" ]
	Pin [  44500 0 3.75mm 0.5mm 3.9mm 1.5mm "2" "2" "" ]

	ElementLine [-43000 -17700   43000 -17700 1200]
	ElementLine [ 43000 -17700   43000  17700 1200]
	ElementLine [ 43000  17700  -43000  17700 1200]
	ElementLine [-43000  17700  -43000 -17700 1200]
)

  This could be written as:

$ cat tt.h
#define pin_dim 3.75mm 0.5mm 3.9mm 1.5mm
#define x 43000
#define y 17700
#define w 1200

Element["" "stelvio_ptf_15" "" "" 0 0 0 0 0 100 ""]
(
	Pin [ -44500 0 pin_dim "1" "1" "" ]
	Pin [  44500 0 pin_dim "2" "2" "" ]

	ElementLine [-x -y   x -y  w]
	ElementLine [ x -y   x  y  w]
	ElementLine [ x  y  -x  y  w]
	ElementLine [-x  y  -x -y  w]
)

  which is easier to read and to write. Using gcc one get:

$ gcc -E tt.h
# 1 "tt.h"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "tt.h"





Element["" "stelvio_ptf_15" "" "" 0 0 0 0 0 100 ""]
(
 Pin [ -44500 0 3.75mm 0.5mm 3.9mm 1.5mm "1" "1" "" ]
 Pin [ 44500 0 3.75mm 0.5mm 3.9mm 1.5mm "2" "2" "" ]

 ElementLine [-43000 -17700 43000 -17700 1200]
 ElementLine [ 43000 -17700 43000 17700 1200]
 ElementLine [ 43000 17700 -43000 17700 1200]
 ElementLine [-43000 17700 -43000 -17700 1200]
)

  but doing:

#define box(x,y) \
	ElementLine [-x -y   x -y w] \
	ElementLine [ x -y   x  y w] \
	ElementLine [ x  y  -x  y w] \
	ElementLine [-x  y  -x -y w] \

  does not help, since that will give us:

 ElementLine [-43000 -17700 43000 -17700 1200] ElementLine [ 43000 -17700 43000 17700 1200] ElementLine [ 43000 17700 -43000 17700 1200] ElementLine [-43000 17700 -43000 -17700 1200]

 which (all in one line) is not what we wanted.

 One could use m4 or some other macro language, but generally one don't
 want to use a preprocessor since that generally munges up error
 reporting and tracking things back to the "source" file.
 But a preprocessor could be a good way to prototype this with and test
 ideas.

***

Doing simplistic wariable substitution is simple enougth:

$ cat tt.test
clearance = 0.5mm
pin_dim = 3.75mm clearance 3.9mm 1.5mm
w = 1200

silk_box(x1,y1, x2, x2) {
  ElementLine [ x1  y1  x2  y1 w]
  ElementLine [ x2  y1  x2  y2 w]
  ElementLine [ x2  y2  x1  y2 w]
  ElementLine [ x1  y2  x1  y1 w]
}

Element["" "stelvio_ptf_15" "" "" 0 0 0 0 0 100 ""]
(
	Pin [ -44500 0 pin_dim "1" "1" "" ]
	Pin [  44500 0 pin_dim "2" "2" "" ]

	silk_box(-4300, -1770, 4300, 1770)
)
$ cat pp1.pl
#!/usr/bin/perl -w

use strict;

my %var  = ();
my %func = ();

sub eval_var($) {
  my $str = shift;

  my $key;
  for $key (keys(%var)) {
    my $val = $var{$key};
    $str =~ s/$key/$val/g;
  }

  $str;
}

while (<>) {
  tr/ \t/ /s;
  if (m/^([a-z][-_0-1a-z]*) ?= ?(.*)$/) {
    $var{$1} = eval_var($2);
    #print "$1 = $2\n";
  } else {
    $_ = eval_var($_);
  }
  print;
}

$ ./pp1.pl tt.test
clearance = 0.5mm
pin_dim = 3.75mm clearance 3.9mm 1.5mm
w = 1200

silk_box(x1,y1, x2, x2) {
 ElementLine [ x1 y1 x2 y1 1200]
 ElementLine [ x2 y1 x2 y2 1200]
 ElementLine [ x2 y2 x1 y2 1200]
 ElementLine [ x1 y2 x1 y1 1200]
}

Element["" "stelvio_ptf_15" "" "" 0 0 0 0 0 100 ""]
(
 Pin [ -44500 0 3.75mm 0.5mm 3.9mm 1.5mm "1" "1" "" ]
 Pin [ 44500 0 3.75mm 0.5mm 3.9mm 1.5mm "2" "2" "" ]

 silk_box(-4300, -1770, 4300, 1770)
)
$

I'll come back later with a preprocessor that handles the above.

***

...
> All ideas.. I'm not coding anything on this in the foreseeable future ;)

That's fine with me!

Regards,
/Karl Hammar

-----------------------------------------------------------------------
Aspö Data
Lilla Aspö 148
S-742 94 Östhammar
Sweden
+46 173 140 57




_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user