1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./style.css" />
7 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./design.css" />
8 <link rel=
"stylesheet" media=
"print" type=
"text/css" href=
"./print.css" />
10 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
15 <h1 class=
"sectionedit302"><a name=
"hooks_scheme_extension_howto" id=
"hooks_scheme_extension_howto">Hooks/Scheme Extension HOWTO
</a></h1>
17 <pre class=
"code">gEDA - GPL Electronic Design Automation
19 HOOKS AND SCHEME EXTENSION IN GSCHEM
20 ====================================
22 Copyright (C)
2000 Stefan Petersen
24 This program is free software; you can redistribute it and/or modify
25 it under the terms of the GNU General Public License as published by
26 the Free Software Foundation; either version
2 of the License, or
27 (at your option) any later version.
29 This program is distributed in the hope that it will be useful,
30 but WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 GNU General Public License for more details.
34 You should have received a copy of the GNU General Public License
35 along with this program; if not, write to the Free Software
36 Foundation, Inc.,
675 Mass Ave, Cambridge, MA
02139, USA.
41 gschem has a scheme interpreter (called Guile) built in. Though not
42 complete, there are extensions to this interpreter to get access to
43 different parts of the schematic.
45 There are a couple of other scheme extensions available that will not be
46 described here. They belong mainly to rc-files (resource files in
47 gEDA programs are really scheme scripts) and to the keymapping system
48 (described in separate keymapping documentation).
50 The rest I will try to describe here.
55 There are two function available for handling attributes in the schematic.
57 * get-attribute-name-value
58 Inparameter : an attribute
59 Outparameter : a pair with the name of the attribute as string in the
60 car element and the value of the attribute in the cdr
62 Description : Simply an accessor to the information hidden in the type
63 attribute. The functionality of this is placed in libgeda
64 since the C-type ATTRIBUTE is defined there.
66 * set-attribute-value!
67 Inparameter : an attribute and a string.
68 Outparameter : undefined.
69 Description : Sets a new value to an attribute. The attribute must
70 be defined, the function can
't create a new attribute.
71 Defined both in gschem and libgeda, mainly because
72 where different variables and information are available.
77 Hooks are a way to define functions that will be called during different
78 part of a programs execution. In gschem there are (currently) three
79 different hooks available:
84 As their name indicate, they are called at different occasions. When
85 you add a component add-component-hook is called, etc.
87 To add a function to be called you simply use the Guile funtion add-hook!.
88 An example; to run the function auto-uref when you add a component you
89 simply add the following line, preferrably in ${HOME}/.gEDA/gschemrc:
90 (add-hook! add-component-hook auto-uref)
92 The function to be called from a hook (for example auto-uref above) has
93 to accept one parameter, a list of attributes.
95 A small example that prints all attributes on a component to be placed:
97 (define (print-all-attributes attribute-list)
98 (foreach (lambda (attribute) (display attribute)) attribute-list))
103 The most complete example utilizing all of the above functions are in fact
104 the auto-uref scheme script that currently is part of the gschem distribution.
105 You can find it
<where gschem is installed
>/share/gEDA/scheme/auto-uref.scm.
106 Uninstalled it
's available at gschem/scheme/auto-uref.scm
108 All components have a reference designator that must be unique so
109 gnetlist can handle it properly. By automatically assigning a number
110 to each instance of a component when you place and copy it, you can
111 simplify the naming operation.
113 All components has, per default, an uref attribute, for example uref=R?.
114 The letter varies with component type. The auto-uref script enumerates
115 uref based on what prefix the component has and assigns a number.
117 For example, the first component you place has per default uref=U? gets
118 the attribute uref=U1. Next component with uref=U? gets uref=U2 and so on.
120 To be able to use the auto-uref script you simply add two lines in
121 ${HOME}/.gEDA/gschemrc. They are:
122 (load
"<where gschem is installed
>/share/gEDA/scheme/auto-uref.scm
")
123 (add-hook! add-component-hook auto-uref)
125 If you want auto enumeration to work when you copy the component too, you
126 simply add the following line:
127 (add-hook! copy-component-hook auto-uref)