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" />
14 As an exercise let
's do something easy, like adding an action to PCB.
18 Before you start coding take a look at:
<a href=
"geda-pcb_developer_introduction.html#build_system" class=
"wikilink1" title=
"geda-pcb_developer_introduction.html">Build system
</a>
19 It is essential that you have a working build system.
23 When working on the source code of PCB then please make use of lots and lots of comments (preferably doxygen style). In trying to understand the code I was very grateful for every piece of comment the developer had written.
27 First make a file called
<em><strong>example.c
</strong></em> and add:
29 <pre class=
"code c"><span class=
"coMULTI">/*!
30 * =====================================================================================
33 * Example action implementation for PCB.
34 * Copyright (C)
2015 Robert Zeegers
36 * This program is free software; you can redistribute it and/or
37 * modify it under the terms of the GNU General Public License
38 * as published by the Free Software Foundation; either version
2
39 * of the License, or (at your option) any later version.
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
46 * You should have received a copy of the GNU General Public License
47 * along with this program; if not, write to the Free Software
48 * Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA
02110-
1301, USA.
51 * \Brief: Example on how to implement a action in the PCB program.
53 * Example action implementation for PCB, interactive printed circuit board design
54 * \copyright (C)
2015 Robert Zeegers
60 * \Bug: not that I know of
62 * =====================================================================================
65 <span class=
"coMULTI">/* First thing todo is include global.h */
</span>
66 <span class=
"coMULTI">/* This will automatically also include const.h and macro.h */
</span>
67 <span class=
"co2">#include
"global.h
"</span>
69 <span class=
"coMULTI">/* Second we include hid.h because we want to register our action to the HID */
</span>
70 <span class=
"co2">#include
"hid.h
"</span>
72 <span class=
"coMULTI">/* We are going to add an action and therefore we want it to show-up in the PCB manual, */
</span>
73 <span class=
"coMULTI">/* so we add some documentation comments */
</span>
74 <span class=
"coMULTI">/* For the documentation style see the
"extract-docs
" perl script in the doc directory */
</span>
76 <span class=
"coMULTI">/* %start-doc actions DoSilly
77 This function doesn't do anything useful.
85 <span class=
"coMULTI">/* All action entry functions must have the same syntax as defined in */
</span>
86 <span class=
"coMULTI">/* typedef struct HID_Action (hid.h) */
</span>
87 <span class=
"kw4">static
</span> <span class=
"kw4">int
</span>
88 ExampleDo
<span class=
"br0">(</span><span class=
"kw4">int
</span> argc
<span class=
"sy0">,
</span> <span class=
"kw4">char
</span> <span class=
"sy0">**
</span>argv
<span class=
"sy0">,
</span> <span class=
"kw4">int
</span> x
<span class=
"sy0">,
</span> <span class=
"kw4">int
</span> y
<span class=
"br0">)</span>
89 <span class=
"br0">{</span>
90 <span class=
"coMULTI">/* It should do something, so let's do something silly */
</span>
91 <span class=
"coMULTI">/* Let's write a Dutch songtext to the Message Log window */
</span>
92 <span class=
"coMULTI">/* The struct HID is defined in hid.h */
</span>
93 <span class=
"coMULTI">/* and the variable gui is made available there by
"extern HID *gui;
" */
</span>
94 <span class=
"coMULTI">/* First we check if we have a gui. */
</span>
95 <span class=
"kw1">if
</span><span class=
"br0">(</span> <span class=
"nu0">1</span> <span class=
"sy0">==
</span> gui
<span class=
"sy0">-
></span>gui
<span class=
"br0">)</span>
96 <span class=
"br0">{</span>
97 <span class=
"coMULTI">/* if we have one let's write the songtext */
</span>
98 gui
<span class=
"sy0">-
></span><a href=
"http://www.opengroup.org/onlinepubs/009695399/functions/log.html"><span class=
"kw3">log
</span></a> <span class=
"br0">(</span>_
<span class=
"br0">(</span><span class=
"st0">"Iedereen is van de wereld en de wereld is van iedereen!
<span class=
"es1">\n
</span>"</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"sy0">;
</span>
99 <span class=
"br0">}</span>
100 <span class=
"br0">}</span>
102 <span class=
"coMULTI">/* Now we have to make an action list. */
</span>
103 <span class=
"coMULTI">/* Here we make the connection between our command
"DoSilly()
" and */
</span>
104 <span class=
"coMULTI">/* the actual function which should be executed ExampleDo().*/
</span>
105 <span class=
"kw4">static
</span> HID_Action exampledo_action_list
<span class=
"br0">[</span><span class=
"br0">]</span> <span class=
"sy0">=
</span> <span class=
"br0">{</span>
106 <span class=
"br0">{</span><span class=
"st0">"DoSilly
"</span><span class=
"sy0">,
</span> <span class=
"st0">"Example action
"</span><span class=
"sy0">,
</span> ExampleDo
<span class=
"sy0">,
</span> <span class=
"st0">"Always provide some help
"</span><span class=
"sy0">,
</span> <span class=
"st0">"DoSilly()
"</span><span class=
"br0">}</span>
107 <span class=
"br0">}</span><span class=
"sy0">;
</span>
109 <span class=
"coMULTI">/* Next a macro to register the action in the HID */
</span>
110 <span class=
"coMULTI">/* Note the missing ; at the end, that's correct ;-) */
</span>
111 REGISTER_ACTIONS
<span class=
"br0">(</span>exampledo_action_list
<span class=
"br0">)</span></pre>
114 For an explanation on the
<code>REGISTER_ACTION
</code> macro see paragraph
<a href=
"geda-pcb_developer_introduction.html#register" class=
"wikilink1" title=
"geda-pcb_developer_introduction.html">REGISTER
</a>.
118 Next we need to add our file to the build system.
<br/>
120 We do that in the file
<em><strong>MakeFile.am
</strong></em>.
<br/>
121 Open
<em><strong>MakeFile.am
</strong></em> and look for the variable
<em class=
"u">PCB_SRCS
</em> and add the file
<em><strong>example.c
</strong></em> there like the others.
125 Clean your build directory by doing:
127 <pre class=
"code">make distclean
</pre>
132 <pre class=
"code">./autogen.sh
</pre>
135 Now our file is in
<em><strong>MakeFile.in
</strong></em>
141 <pre class=
"code">./configure
147 <pre class=
"code">src/pcb
</pre>
150 In the PCB program type “:DoSilly()” and watch the message log window.
154 And do check out the pcb manual in doc/pcb.pdf search for “DoSilly”