1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./style.css" />
6 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./design.css" />
7 <link rel=
"stylesheet" media=
"print" type=
"text/css" href=
"./print.css" />
9 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
13 <h1 class=
"sectionedit1" id=
"getting_started_with_xorn">Getting started with Xorn
</h1>
17 1. First, make sure that you have the latest version of gEDA/gaf installed (version
1.10.0 or later). When invoking the Python interpreter directly from a non-standard prefix, you have to add the correct PYTHONPATH (see below): either the subdirectory
<code>built-packages
</code> in the build tree, or the appropriate
<code>site-packages
</code> directory in the installation.
21 2.
<em>(no longer applicable)
</em>
25 <!-- EDIT1 SECTION "Getting started with Xorn" [1-432] -->
26 <h2 class=
"sectionedit2" id=
"xorn_as_a_command-line_utility">Xorn as a command-line utility
</h2>
30 3a. Invoke the “
<code>xorn
</code>” executable with the option “
<code>--help
</code>” to see a list of subcommands:
32 <pre class=
"code"> xorn/src/command/xorn --help
</pre>
35 (or “
<code>src/command/xorn --help
</code>” if you downloaded the Xorn tarball, or just “
<code>xorn --help
</code>” if you installed Xorn to your
<code>PATH
</code>)
39 3b. Run the subcommand “
<code>xorn netlist
</code>” with the options “
<code>--help
</code>” and “
<code>--list-backends
</code>” to print a list of options and available backends.
41 <pre class=
"code"> xorn/src/command/xorn netlist --help
42 xorn/src/command/xorn netlist --list-backends
</pre>
45 3c. Process a schematic with “
<code>xorn netlist
</code>” (using the “
<code>PCB
</code>” backend as an example):
47 <pre class=
"code"> xorn/src/command/xorn netlist \
48 --symbol-library-search=/usr/share/gEDA/sym \
49 -g PCB some-schematic.sch
</pre>
52 <!-- EDIT2 SECTION "Xorn as a command-line utility" [433-1221] -->
53 <h2 class=
"sectionedit3" id=
"interacting_with_xorn_in_a_c_program">Interacting with Xorn in a C program
</h2>
57 4. Write a C program using libxornstorage and link it against the library:
59 <pre class=
"code"> $ cat
> example.c
60 #include
<stdio.h
>
61 #include
<stdlib.h
>
62 #include
<string.h
>
63 #include
<xornstorage.h
>
69 struct xornsch_net net_data;
70 xorn_object_t *objects;
73 rev = xorn_new_revision(NULL);
75 memset(
&net_data,
0, sizeof net_data);
78 net_data.size.x =
100;
81 net_ob = xornsch_add_net(rev,
&net_data);
83 xorn_finalize_revision(rev);
85 xorn_get_objects(rev,
&objects,
&count);
86 printf(
"%d object(s) found\n
", count);
89 xorn_free_revision(rev);
93 $ gcc -I xorn/include -c example.c
94 $ ./libtool --mode=link gcc -o example \
95 example.o xorn/src/storage/libxornstorage.la
100 If you are using a separate build directory, replace “
<code>-I xorn/include
</code>” with the path to the subdirectory “
<code>xorn/include
</code>” in the source directory.
104 For more information, see the
<a href=
"http://hedmen.org/xorn/doc/api/html/xornstorage_8h.html" class=
"urlextern" title=
"http://hedmen.org/xorn/doc/api/html/xornstorage_8h.html" rel=
"nofollow">libxornstorage API documentation
</a> (
<a href=
"http://hedmen.org/xorn/doc/api/html/storage.html" class=
"urlextern" title=
"http://hedmen.org/xorn/doc/api/html/storage.html" rel=
"nofollow">overview
</a>).
108 <!-- EDIT3 SECTION "Interacting with Xorn in a C program" [1222-2685] -->
109 <h2 class=
"sectionedit4" id=
"using_xorn_as_a_library">Using Xorn as a library
</h2>
113 5. Run the Python
2.7 interpreter with the subdirectory “
<code>xorn/built-packages
</code>” added to the environment variable “
<code>PYTHONPATH
</code>”.
115 <pre class=
"code"> $ PYTHONPATH=xorn/built-packages python2.7
116 Python
2.7.9 (default, Mar
1 2015,
18:
22:
53)
117 [GCC
4.9.2] on linux2
118 Type
"help
",
"copyright
",
"credits
" or
"license
" for more information.
122 Import the module “
<code>xorn.storage
</code>” and experiment a bit with the
<abbr title=
"Application Programming Interface">API
</abbr>. Here is how to perform the operations equivalent to the C program above:
124 <pre class=
"code"> >>> import xorn.storage
125 >>> rev = xorn.storage.Revision()
126 >>> net_data = xorn.storage.Net(
127 x =
0, y =
200, width =
100, height =
0, color =
4)
128 >>> net_ob = rev.add_object(net_data)
129 >>> rev.finalize()
130 >>> rev.get_objects()
131 [
<xorn.storage.Object object at ...
>]
</pre>
134 Import the module “
<code>xorn.geda.read
</code>” and load a schematic or symbol file:
136 <pre class=
"code"> >>> import xorn.geda.read
137 >>> rev = xorn.geda.read.read(
138 '/usr/share/gEDA/sym/analog/resistor-
1.sym
')
139 >>> for ob in rev.toplevel_objects():
141 ... if isinstance(data, xorn.storage.Text):
150 For more information, see the
<abbr title=
"Application Programming Interface">API
</abbr> documentation of
<a href=
"http://hedmen.org/xorn/doc/api/html/namespacexorn_1_1storage.html" class=
"urlextern" title=
"http://hedmen.org/xorn/doc/api/html/namespacexorn_1_1storage.html" rel=
"nofollow">xorn.storage
</a> and
<a href=
"http://hedmen.org/xorn/doc/api/html/namespacexorn_1_1geda.html" class=
"urlextern" title=
"http://hedmen.org/xorn/doc/api/html/namespacexorn_1_1geda.html" rel=
"nofollow">xorn.geda
</a>.
154 6. Write and execute a Python program which uses the
<code>xorn
</code> package:
156 <pre class=
"code"> $ cat
> print-attributes.py
157 #!/usr/bin/env python2
160 import xorn.geda.read
162 rev = xorn.geda.read.read(sys.argv[
1])
163 for ob in rev.toplevel_objects():
165 if isinstance(data, xorn.storage.Text):
168 $ chmod +x print-attributes.py
169 $ PYTHONPATH=xorn/built-packages ./print-attributes.py \
170 /usr/share/gEDA/sym/analog/resistor-
1.sym
177 <!-- EDIT4 SECTION "Using Xorn as a library" [2686-4757] -->
178 <h2 class=
"sectionedit5" id=
"writing_custom_netlist_backends">Writing custom netlist backends
</h2>
182 7. Invoke “
<code>xorn netlist
</code>” on your schematic as above, but instead of specifying a netlist backend, use the option “
<code>-i
</code>”:
184 <pre class=
"code"> $ xorn/src/command/xorn netlist \
185 --symbol-library-search=/usr/share/gEDA/sym \
186 -i some-schematic.sch
187 Python
2.7.9 (default, Mar
1 2015,
18:
22:
53)
188 [GCC
4.9.2] on linux2
189 Type
"help
",
"copyright
",
"credits
" or
"license
" for more information.
194 This option causes “
<code>xorn netlist
</code>” to enter interactive mode. You are now in an interactive Python interpreter session, just like above, but have the additional global variable “
<code>netlist
</code>” available which contains the netlist
's contents.
196 <pre class=
"code"> >>> netlist
197 <xorn.geda.netlist.netlist.Netlist instance at ...
>
198 >>> netlist.nets
199 [
<xorn.geda.netlist.net.Net instance at ...
>, ...]
200 >>> [net.name for net in netlist.nets]
201 [...,
'GND
', ...]
202 >>> netlist.nets_by_name[
'GND
']
203 <xorn.geda.netlist.net.Net instance at ...
>
204 >>> netlist.nets_by_name[
'GND
'].name
206 >>> netlist.nets_by_name[
'GND
'].connections
207 [
<xorn.geda.netlist.package.PackagePin instance at ...
>, ...]
208 >>> netlist.nets_by_name[
'GND
'].connections[
0].package
209 <xorn.geda.netlist.package.Package instance at ...
>
210 >>> netlist.nets_by_name[
'GND
'].connections[
0].package.refdes
212 >>> netlist.nets_by_name[
'GND
'].connections[
0].number
215 >>> netlist.packages
216 [
<xorn.geda.netlist.package.Package instance at ...
>]
217 >>> netlist.packages_by_refdes
218 {...,
'U100
':
<xorn.geda.netlist.package.Package instance at ...
>, ...}
219 >>> netlist.packages_by_refdes[
'U100
'].get_attribute(
'device
')
221 >>> netlist.packages_by_refdes[
'U100
'].pins
222 [
<xorn.geda.netlist.package.PackagePin instance at ...
>, ...]
223 >>> netlist.packages_by_refdes[
'U100
'].pins_by_number
224 {...,
'7':
<xorn.geda.netlist.package.PackagePin instance at ...
>, ...}
225 >>> netlist.packages_by_refdes[
'U100
'].pins_by_number[
'7'].net
226 <xorn.geda.netlist.net.Net instance at ...
>
227 >>> netlist.packages_by_refdes[
'U100
'].pins_by_number[
'7'].net.name
228 'GND
'</pre>
231 8. Write a Python module whose name starts with “
<code>gnet_
</code>” and which contains a function “
<code>run(f, netlist)
</code>”. Use this module as a netlist backend:
233 <pre class=
"code"> $ cat
> gnet_count.py
235 f.write(
"%d packages found\n
" % len(netlist.packages))
236 f.write(
"%d nets found\n
" % len(netlist.nets))
238 $ xorn/src/command/xorn netlist \
239 --symbol-library-search=/usr/share/gEDA/sym \
240 -L . -g count some-schematic.sch
245 <!-- EDIT5 SECTION "Writing custom netlist backends" [4758-] --></body>