Update wiki pages
[geda-gaf.git] / docs / wiki / geda-pcb_developer_introduction.html
blob91092ee4099285d442a215b3def8dfeac87a8391
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html>
4 <head>
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" />
10 </head>
11 <body>
13 <h1 class="sectionedit1" id="pcb_development_introduction">PCB Development Introduction</h1>
14 <div class="level1">
16 <p>
17 I started this document to get an insight in the structure/architecture of the PCB program. The main objective is to get up to speed so we are able to start contributing to the PCB program.
18 </p>
20 <p>
21 This document is work in progress.
22 </p>
24 </div>
25 <!-- EDIT1 SECTION "PCB Development Introduction" [1-271] -->
26 <h2 class="sectionedit2" id="get_information">Get Information</h2>
27 <div class="level2">
29 <p>
30 These links help to get an understanding of PCB:
31 </p>
32 <div class="table sectionedit3"><table class="inline">
33 <thead>
34 <tr class="row0">
35 <th class="col0 leftalign">Link </th><th class="col1 leftalign">Remark </th>
36 </tr>
37 </thead>
38 <tr class="row1">
39 <td class="col0"><a href="http://pcb.geda-project.org/manual.html" class="urlextern" title="http://pcb.geda-project.org/manual.html" rel="nofollow">http://pcb.geda-project.org/manual.html</a></td><td class="col1 leftalign">As always read the manual first. </td>
40 </tr>
41 <tr class="row2">
42 <td class="col0 leftalign"><a href="http://pcb.geda-project.org/faq.html" class="urlextern" title="http://pcb.geda-project.org/faq.html" rel="nofollow">http://pcb.geda-project.org/faq.html</a> </td><td class="col1"> </td>
43 </tr>
44 <tr class="row3">
45 <td class="col0 leftalign"><a href="http://www.delorie.com/pcb/docs/gs/gs.html#Terminology" class="urlextern" title="http://www.delorie.com/pcb/docs/gs/gs.html#Terminology" rel="nofollow">http://www.delorie.com/pcb/docs/gs/gs.html#Terminology</a> </td><td class="col1 leftalign">Knowing the terminology helps in understanding the code </td>
46 </tr>
47 <tr class="row4">
48 <td class="col0 leftalign"><a href="http://wiki.geda-project.org/geda:pcb-quick_reference" class="urlextern" title="http://wiki.geda-project.org/geda:pcb-quick_reference" rel="nofollow">http://wiki.geda-project.org/geda:pcb-quick_reference</a> </td><td class="col1"> </td>
49 </tr>
50 <tr class="row5">
51 <td class="col0 leftalign"><a href="http://wiki.geda-project.org/geda:pcb_footprints" class="urlextern" title="http://wiki.geda-project.org/geda:pcb_footprints" rel="nofollow">http://wiki.geda-project.org/geda:pcb_footprints</a> </td><td class="col1"> </td>
52 </tr>
53 <tr class="row6">
54 <td class="col0 leftalign"><a href="http://wiki.geda-project.org/geda:pcb_tips" class="urlextern" title="http://wiki.geda-project.org/geda:pcb_tips" rel="nofollow">http://wiki.geda-project.org/geda:pcb_tips</a> </td><td class="col1"> </td>
55 </tr>
56 <tr class="row7">
57 <td class="col0"><a href="http://wiki.geda-project.org/geda:documentation" class="urlextern" title="http://wiki.geda-project.org/geda:documentation" rel="nofollow">http://wiki.geda-project.org/geda:documentation</a> </td><td class="col1"> </td>
58 </tr>
59 </table></div>
60 <!-- EDIT3 TABLE [349-848] -->
61 </div>
62 <!-- EDIT2 SECTION "Get Information" [272-849] -->
63 <h2 class="sectionedit4" id="root_directory_structure">root Directory structure</h2>
64 <div class="level2">
66 <p>
67 This is the ~/pcb directory
68 </p>
69 <div class="table sectionedit5"><table class="inline">
70 <tr class="row0">
71 <td class="col0"> </td><td class="col1 rightalign"> data</td><td class="col2">PCB layout and gerber icons and mime registration data</td>
72 </tr>
73 <tr class="row1">
74 <td class="col0"> </td><td class="col1 rightalign"> doc</td><td class="col2">All files used to generate the documentation</td>
75 </tr>
76 <tr class="row2">
77 <td class="col0"> </td><td class="col1 rightalign"> example</td><td class="col2">Speaks for it self, examples how to use PCB</td>
78 </tr>
79 <tr class="row3">
80 <td class="col0"> </td><td class="col1 rightalign"> gts</td><td class="col2">This directory/library is only used by the toporouter (toporouter.h includes gts.h)</td>
81 </tr>
82 <tr class="row4">
83 <td class="col0">*</td><td class="col1 rightalign"> intl</td><td class="col2">Internationalization - it handles conversions to non-English languages. It is for i18n, l10n and related stuff. See the <em><strong>ABOUT-NLS</strong></em> text file in the root directory for more information.</td>
84 </tr>
85 <tr class="row5">
86 <td class="col0"> </td><td class="col1 rightalign"> lib</td><td class="col2">The M4 library stores the footprints as M4 macros</td>
87 </tr>
88 <tr class="row6">
89 <td class="col0"> </td><td class="col1 rightalign"> m4</td><td class="col2">Some additional m4 scripts used by configure</td>
90 </tr>
91 <tr class="row7">
92 <td class="col0"> </td><td class="col1 rightalign"> newlib</td><td class="col2">File to make newlib library components</td>
93 </tr>
94 <tr class="row8">
95 <td class="col0"> </td><td class="col1 rightalign"> po</td><td class="col2">Translation files</td>
96 </tr>
97 <tr class="row9">
98 <td class="col0"> </td><td class="col1 rightalign"> README_FILES</td><td class="col2 leftalign">Information in this directory is obsolete and/or very old. Just ignore it. </td>
99 </tr>
100 <tr class="row10">
101 <td class="col0"> </td><td class="col1 rightalign"> src</td><td class="col2">The source code</td>
102 </tr>
103 <tr class="row11">
104 <td class="col0"> </td><td class="col1 rightalign"> tests</td><td class="col2">File to test the build during make</td>
105 </tr>
106 <tr class="row12">
107 <td class="col0"> </td><td class="col1 rightalign"> tools</td><td class="col2">Build tools</td>
108 </tr>
109 <tr class="row13">
110 <td class="col0"> </td><td class="col1 rightalign"> tutorial</td><td class="col2"> </td>
111 </tr>
112 <tr class="row14">
113 <td class="col0"> </td><td class="col1 rightalign"> utils</td><td class="col2">Build tools</td>
114 </tr>
115 <tr class="row15">
116 <td class="col0"> </td><td class="col1 rightalign"> w32</td><td class="col2">File needed to build for Windows</td>
117 </tr>
118 <tr class="row16">
119 <td class="col0" colspan="3"> </td>
120 </tr>
121 <tr class="row17">
122 <td class="col0">*</td><td class="col1" colspan="2">This directory is no part of the git repository it is added by the <code>./autogen.sh</code> script</td>
123 </tr>
124 </table></div>
125 <!-- EDIT5 TABLE [917-1964] -->
126 </div>
127 <!-- EDIT4 SECTION "root Directory structure" [850-1966] -->
128 <h2 class="sectionedit6" id="src_directory_structure">src Directory structure</h2>
129 <div class="level2">
132 This is the ~/pcb/src directory
133 </p>
134 <div class="table sectionedit7"><table class="inline">
135 <tr class="row0">
136 <td class="col0">src/hid</td><td class="col1"> </td><td class="col2">Human Interface Device layer. The basic idea is that every action outside the core is treated as a separate human interface device.</td>
137 </tr>
138 <tr class="row1">
139 <td class="col0"> </td><td class="col1 leftalign">src/hid/batch </td><td class="col2">Batch mode</td>
140 </tr>
141 <tr class="row2">
142 <td class="col0"> </td><td class="col1 leftalign">src/hid/bom </td><td class="col2">Export a bill of materials</td>
143 </tr>
144 <tr class="row3">
145 <td class="col0"> </td><td class="col1 leftalign">src/hid/common </td><td class="col2"> </td>
146 </tr>
147 <tr class="row4">
148 <td class="col0"> </td><td class="col1 leftalign">src/hid/gcode </td><td class="col2">Export to G-Code</td>
149 </tr>
150 <tr class="row5">
151 <td class="col0"> </td><td class="col1 leftalign">src/hid/gerber </td><td class="col2">Export RS-274X (Gerber)</td>
152 </tr>
153 <tr class="row6">
154 <td class="col0"> </td><td class="col1 leftalign">src/hid/gtk </td><td class="col2">Graphical User Interface based on GTK2</td>
155 </tr>
156 <tr class="row7">
157 <td class="col0"> </td><td class="col1 leftalign">src/hid/lesstif </td><td class="col2">Graphical User Interface based on lessif</td>
158 </tr>
159 <tr class="row8">
160 <td class="col0"> </td><td class="col1 leftalign">src/hid/lpr </td><td class="col2">Printer driver</td>
161 </tr>
162 <tr class="row9">
163 <td class="col0"> </td><td class="col1 leftalign">src/hid/nelma </td><td class="col2">Numerical analysis package export</td>
164 </tr>
165 <tr class="row10">
166 <td class="col0"> </td><td class="col1 leftalign">src/hid/png </td><td class="col2">export GIF/JPEG/PNG</td>
167 </tr>
168 <tr class="row11">
169 <td class="col0"> </td><td class="col1 leftalign">src/hid/ps </td><td class="col2">export postscript /encapsulated postscript</td>
170 </tr>
171 <tr class="row12">
172 <td class="col0"> </td><td class="col1 leftalign">src/hid/hidint.h </td><td class="col2">HID internal interfaces. These may ONLY be called from the HID modules, not from the common PCB code.</td>
173 </tr>
174 <tr class="row13">
175 <td class="col0" colspan="3">src/icons</td>
176 </tr>
177 </table></div>
178 <!-- EDIT7 TABLE [2037-2819] -->
179 </div>
180 <!-- EDIT6 SECTION "src Directory structure" [1967-2820] -->
181 <h2 class="sectionedit8" id="src_directory_file_list">src Directory file list</h2>
182 <div class="level2">
185 These are the files in the ~/pcb/src directory
186 </p>
187 <div class="table sectionedit9"><table class="inline">
188 <thead>
189 <tr class="row0">
190 <th class="col0"> _*_ </th><th class="col1 leftalign">File </th><th class="col2 leftalign">Short description </th><th class="col3">Comment / Explanation </th>
191 </tr>
192 </thead>
193 <tr class="row1">
194 <td class="col0">H</td><td class="col1">action.*</td><td class="col2 leftalign">action routines for output window </td><td class="col3">This is one of the top files. A lot of the functionality will start here. This is a good place to start your digging work when learning the PCB code.<br/>
195 This file also contains a lot of documentation generating code.<br/>
196 This means two things:<br/>
197 - Look at the PCB manual for a description of all actions (manual is in doc directory after make)<br/>
198 - Take this as an example how to add documentation to the code.</td>
199 </tr>
200 <tr class="row2">
201 <td class="col0">H</td><td class="col1">autoplace.*</td><td class="col2 leftalign">functions used to autoplace elements. </td><td class="col3"> </td>
202 </tr>
203 <tr class="row3">
204 <td class="col0">H</td><td class="col1">autoroute.*</td><td class="col2 leftalign">functions used to autoroute nets. </td><td class="col3"> </td>
205 </tr>
206 <tr class="row4">
207 <td class="col0">C</td><td class="col1">box.h</td><td class="col2 leftalign">random box-related utilities. </td><td class="col3"> </td>
208 </tr>
209 <tr class="row5">
210 <td class="col0">C</td><td class="col1">buffer.*</td><td class="col2 leftalign">functions used by paste- and move/copy buffer </td><td class="col3"> </td>
211 </tr>
212 <tr class="row6">
213 <td class="col0">D</td><td class="col1">change.*</td><td class="col2 leftalign">functions used to change object properties </td><td class="col3"> </td>
214 </tr>
215 <tr class="row7">
216 <td class="col0"> </td><td class="col1">check_icon.data</td><td class="col2"> </td><td class="col3"> </td>
217 </tr>
218 <tr class="row8">
219 <td class="col0"> </td><td class="col1">clip.*</td><td class="col2 leftalign">Clip the line to the clipBox </td><td class="col3"> </td>
220 </tr>
221 <tr class="row9">
222 <td class="col0">C</td><td class="col1">command.*</td><td class="col2 leftalign">executes commands from user </td><td class="col3">That is, some commands, only the short-hand vi compatible commands like l, le, m, q, w, s and rn.<br/>
223 See pcb manual for the explanation.<br/>
224 See action.c for the other commands.</td>
225 </tr>
226 <tr class="row10">
227 <td class="col0">C</td><td class="col1">compat.*</td><td class="col2"> </td><td class="col3">This file is for compatibility across operating systems; we can define functions there that might be missing elsewhere (like linux-specific things) or broken elsewhere. Mostly it&#039;s for unix-vs-windows.</td>
228 </tr>
229 <tr class="row11">
230 <td class="col0"> </td><td class="col1">const.h</td><td class="col2 leftalign">global source constants </td><td class="col3"> </td>
231 </tr>
232 <tr class="row12">
233 <td class="col0">D</td><td class="col1">copy.*</td><td class="col2 leftalign">functions used to copy pins, elements … </td><td class="col3"> </td>
234 </tr>
235 <tr class="row13">
236 <td class="col0">D</td><td class="col1">create.*</td><td class="col2 leftalign">functions used to create vias, pins … </td><td class="col3"> </td>
237 </tr>
238 <tr class="row14">
239 <td class="col0">H</td><td class="col1">crosshair.*</td><td class="col2 leftalign">crosshair stuff </td><td class="col3">is for the board&#039;s crosshair; this handles (for example) grid snapping. This is *not* the same as the <abbr title="Graphical User Interface">GUI</abbr>&#039;s mouse cursor. For the GKT <abbr title="Graphical User Interface">GUI</abbr> the crosshair will follow the mouse if its over the board-space/canvas.</td>
240 </tr>
241 <tr class="row15">
242 <td class="col0">C</td><td class="col1">data.*</td><td class="col2 leftalign">just defines common identifiers </td><td class="col3"> </td>
243 </tr>
244 <tr class="row16">
245 <td class="col0">C</td><td class="col1">dbus.*</td><td class="col2 leftalign">Interprocess communication (IPC) </td><td class="col3">D-Bus is a system for interprocess communication (IPC). D-Bus code originally derived from example-service.c in the dbus-glib bindings.<br/>
246 The dbus was added to provide some communications between gschem and pcb, and to provide some remote-control options for pcb. Not sure if anything uses it at the moment.<br/>
247 If you&#039;re not interested in connecting to other programs just ignore the files.</td>
248 </tr>
249 <tr class="row17">
250 <td class="col0">C</td><td class="col1">dbus-pcbmain.*</td><td class="col2 leftalign">PCB HID main loop integration. </td><td class="col3"> </td>
251 </tr>
252 <tr class="row18">
253 <td class="col0">C</td><td class="col1">default_font</td><td class="col2"> </td><td class="col3">From the PCB documentation: A number of user defined Symbols are called a font. There is only one per layout. All symbols are made of lines. See the file &#039;default_font&#039; as an example.<br/>
254 Fontmode.c is linked with this file.</td>
255 </tr>
256 <tr class="row19">
257 <td class="col0">D</td><td class="col1">djopt.*</td><td class="col2">optimize functions</td><td class="col3">is for the “Connects→Optimize Routed Tracks” functions.</td>
258 </tr>
259 <tr class="row20">
260 <td class="col0">C</td><td class="col1">dolists.h</td><td class="col2"> </td><td class="col3">REGISTER_*(a) macro in dolists.h will be expanded by the preprocessor to the actual calling of these functions.</td>
261 </tr>
262 <tr class="row21">
263 <td class="col0">H</td><td class="col1">draw.*</td><td class="col2 leftalign">drawing routines </td><td class="col3"> </td>
264 </tr>
265 <tr class="row22">
266 <td class="col0">H</td><td class="col1">drill.*</td><td class="col2 leftalign">functions to generate drill information </td><td class="col3">is for generating drill report information.</td>
267 </tr>
268 <tr class="row23">
269 <td class="col0" rowspan="3">H</td><td class="col1">edif.*</td><td class="col2 leftalign">EDIF stands for Electronic Design Interchange Format. </td><td class="col3" rowspan="3">These files are associated with only one action “LoadFrom(Netlist)”. This will call the function ImportNetlist() in file.c. If the first line of the netlist file contains “edif” it will use these files to parse the EDIF 2.0.0 formatted file. A little googling learns that the EDIF 2.0.0 file format was approved in March 1988. File format EDIF 4.0.0 was released in August 1996. The PCB documentation doesn&#039;t say anything about EDIF. <br/>
270 The files are here to be backwards compatible, so we are able to read files generated many year ago. It doesn&#039;t hurt so just ignore it.</td>
271 </tr>
272 <tr class="row24">
273 <td class="col0">edif_parse.h</td><td class="col1 leftalign">This file defines the interface to the outside world. </td>
274 </tr>
275 <tr class="row25">
276 <td class="col0">edif.y</td><td class="col1 leftalign">file says: A Bison parser, used in with edif.c. EDIF stands for Electronic Design Interchange Format. </td>
277 </tr>
278 <tr class="row26">
279 <td class="col0">C</td><td class="col1">error.*</td><td class="col2 leftalign">error and debug functions </td><td class="col3"> </td>
280 </tr>
281 <tr class="row27">
282 <td class="col0">C</td><td class="col1">file.*</td><td class="col2 leftalign">file save, load, merge … routines </td><td class="col3"> </td>
283 </tr>
284 <tr class="row28">
285 <td class="col0">D</td><td class="col1">find.*</td><td class="col2 leftalign">routines to find connections between pins, vias, lines… </td><td class="col3"> </td>
286 </tr>
287 <tr class="row29">
288 <td class="col0">C</td><td class="col1">flags.*</td><td class="col2 leftalign">routines to initialize and use flags </td><td class="col3">flags.c functions are used by some of the HIDs to mark menu entries as “checked” vs “unchecked” when they refer to flags. That&#039;s why they&#039;re registered, too, there&#039;s a list with <abbr title="American Standard Code for Information Interchange">ASCII</abbr> names that hids can refer to.</td>
289 </tr>
290 <tr class="row30">
291 <td class="col0">H</td><td class="col1">fontmode.c</td><td class="col2 leftalign">routines to edit the font in PCB </td><td class="col3">There are two actions: <br/>
292 FontEdit() and FontSave() <br/>
293 Font editing draws one of each character on the screen as a PCB. You edit the PCB. Then it reads the traces from the PCB and turns it back into a font. You can then cut/paste the font section out of that pcb to default_font.<br/>
294 default_font is linked with this file.</td>
295 </tr>
296 <tr class="row31">
297 <td class="col0">C</td><td class="col1">free_atexit.*</td><td class="col2 leftalign">some routines to free memory </td><td class="col3"> </td>
298 </tr>
299 <tr class="row32">
300 <td class="col0"> </td><td class="col1">gather-actions</td><td class="col2 leftalign">shell script used during build. </td><td class="col3">Probably a leftover from an old build script, I can&#039;t find where it is called. Think the script isn&#039;t used. <br/>
301 Just ignore it.</td>
302 </tr>
303 <tr class="row33">
304 <td class="col0"> </td><td class="col1">gettext.h</td><td class="col2"> </td><td class="col3">Used if –enable-nls option is configured. Takes care of internationalization.</td>
305 </tr>
306 <tr class="row34">
307 <td class="col0">C</td><td class="col1">global.h</td><td class="col2"> </td><td class="col3">The big include just about everything include file</td>
308 </tr>
309 <tr class="row35">
310 <td class="col0">H</td><td class="col1">gpcb-menu.res</td><td class="col2"> </td><td class="col3"> </td>
311 </tr>
312 <tr class="row36">
313 <td class="col0">C</td><td class="col1">heap.*</td><td class="col2"> </td><td class="col3">The heap functions seem to be associated mainly with the two autorouters. Additionally the file polygon1.c makes use of a heap in one of its functions</td>
314 </tr>
315 <tr class="row37">
316 <td class="col0">H</td><td class="col1">hid_draw.h</td><td class="col2 leftalign">Low level drawing <abbr title="Application Programming Interface">API</abbr>. </td><td class="col3"> </td>
317 </tr>
318 <tr class="row38">
319 <td class="col0">H</td><td class="col1">hid.h</td><td class="col2 leftalign">Human Interface Device layer. </td><td class="col3">This is one of the top files.<br/>
320 This is a good place to start looking if you want to know what&#039;s-what.</td>
321 </tr>
322 <tr class="row39">
323 <td class="col0"> </td><td class="col1">icon.data</td><td class="col2"> </td><td class="col3"> </td>
324 </tr>
325 <tr class="row40">
326 <td class="col0">D</td><td class="col1">insert.*</td><td class="col2 leftalign">functions used to insert points into objects </td><td class="col3"> </td>
327 </tr>
328 <tr class="row41">
329 <td class="col0">D</td><td class="col1">intersect.*</td><td class="col2 leftalign">rectangle intersection/union routines. </td><td class="col3"> </td>
330 </tr>
331 <tr class="row42">
332 <td class="col0">D</td><td class="col1">line.*</td><td class="col2">line routines</td><td class="col3"> </td>
333 </tr>
334 <tr class="row43">
335 <td class="col0"> </td><td class="col1">lrealpath.*</td><td class="col2 leftalign">Libiberty realpath. Like realpath, but more consistent behaviour </td><td class="col3"> </td>
336 </tr>
337 <tr class="row44">
338 <td class="col0">C</td><td class="col1">macro.h</td><td class="col2 leftalign">some commonly used macros not related to a special C-file the file is included by global.h after const.h </td><td class="col3"> </td>
339 </tr>
340 <tr class="row45">
341 <td class="col0">C</td><td class="col1">main.c</td><td class="col2"> </td><td class="col3">It all starts here</td>
342 </tr>
343 <tr class="row46">
344 <td class="col0"> </td><td class="col1">main-test.c</td><td class="col2"> </td><td class="col3"> </td>
345 </tr>
346 <tr class="row47">
347 <td class="col0">D</td><td class="col1">mirror.*</td><td class="col2 leftalign">functions used to change the mirror flag of an object </td><td class="col3"> </td>
348 </tr>
349 <tr class="row48">
350 <td class="col0">C</td><td class="col1">misc.*</td><td class="col2"> </td><td class="col3"> </td>
351 </tr>
352 <tr class="row49">
353 <td class="col0"> </td><td class="col1">mode_icon.data</td><td class="col2"> </td><td class="col3">Icons used in the <abbr title="Graphical User Interface">GUI</abbr></td>
354 </tr>
355 <tr class="row50">
356 <td class="col0">D</td><td class="col1">move.*</td><td class="col2 leftalign">functions used to move pins, elements … </td><td class="col3"> </td>
357 </tr>
358 <tr class="row51">
359 <td class="col0">C</td><td class="col1">mtspace.*</td><td class="col2 leftalign">implementation for “empty space” routines (needed for via-space tracking in the auto-router. </td><td class="col3"> </td>
360 </tr>
361 <tr class="row52">
362 <td class="col0">C</td><td class="col1">mymem.*</td><td class="col2 leftalign">memory management functions </td><td class="col3"> </td>
363 </tr>
364 <tr class="row53">
365 <td class="col0">H</td><td class="col1">netlist.c</td><td class="col2"> </td><td class="col3"> </td>
366 </tr>
367 <tr class="row54">
368 <td class="col0" rowspan="2">C</td><td class="col1">parse_l.*</td><td class="col2 leftalign">lexical definitions to parse <abbr title="American Standard Code for Information Interchange">ASCII</abbr> input of PCB and Element description </td><td class="col3" rowspan="2">Parse an element file or layout file. This is either a footprint file or our PCB layout file</td>
369 </tr>
370 <tr class="row55">
371 <td class="col0">parse_y.*</td><td class="col1 leftalign">grammar to parse <abbr title="American Standard Code for Information Interchange">ASCII</abbr> input of PCB description </td>
372 </tr>
373 <tr class="row56">
374 <td class="col0">H</td><td class="col1">pcb-menu.res</td><td class="col2"> </td><td class="col3"> </td>
375 </tr>
376 <tr class="row57">
377 <td class="col0">C</td><td class="col1">pcb-printf.*</td><td class="col2 leftalign">Implementation of printf wrapper to output pcb coords and angles. </td><td class="col3"> </td>
378 </tr>
379 <tr class="row58">
380 <td class="col0"> </td><td class="col1">pcbtest.sh.in</td><td class="col2 leftalign">Used during the build to test the program </td><td class="col3"> </td>
381 </tr>
382 <tr class="row59">
383 <td class="col0" rowspan="3">D</td><td class="col1">polyarea.h</td><td class="col2 leftalign">file says: poly_Boolean: a polygon clip library. </td><td class="col3">Used in polygon.c, polygon1.c and thermal.c</td>
384 </tr>
385 <tr class="row60">
386 <td class="col0">polygon1.c</td><td class="col1 leftalign">polygon clipping functions </td><td class="col2"> </td>
387 </tr>
388 <tr class="row61">
389 <td class="col0">polygon.*</td><td class="col1 leftalign">special polygon editing routines </td><td class="col2"> </td>
390 </tr>
391 <tr class="row62">
392 <td class="col0">H</td><td class="col1">print.*</td><td class="col2 leftalign">printing routines </td><td class="col3">Looks like it is used to “print” the fabrication layer. print.c generates a layer to be used as a fabrication drawing. Whether the HID uses that or not (and what it does with it) is a Separate question. At least, both ps and gerber need that layer. Since the layer is created in “pcb unit space” it&#039;s in the core. HID things tend to happen in “hid unit space” instead.</td>
393 </tr>
394 <tr class="row63">
395 <td class="col0">H</td><td class="col1">puller.c</td><td class="col2 leftalign">PCB HID Project - Puller </td><td class="col3">See <a href="http://www.delorie.com/pcb/puller" class="urlextern" title="http://www.delorie.com/pcb/puller" rel="nofollow">http://www.delorie.com/pcb/puller</a> for more information.</td>
396 </tr>
397 <tr class="row64">
398 <td class="col0">H</td><td class="col1">rats.*</td><td class="col2 leftalign">rats nest routines </td><td class="col3"> </td>
399 </tr>
400 <tr class="row65">
401 <td class="col0">D</td><td class="col1">remove.*</td><td class="col2 leftalign">functions used to remove vias, pins … </td><td class="col3"> </td>
402 </tr>
403 <tr class="row66">
404 <td class="col0">H</td><td class="col1">report.*</td><td class="col2 leftalign">Tell the user what he/she must know </td><td class="col3">See PCB manual for the options.</td>
405 </tr>
406 <tr class="row67">
407 <td class="col0" rowspan="2">H</td><td class="col1">res_lex.*</td><td class="col2"> </td><td class="col3" rowspan="2">These files are used to parse the pcb-menu.res and gpcb-menu.res files. This defines the menu structure of PCB. res_* is a generic resource parser. Both gtk and lesstif hids use them.</td>
408 </tr>
409 <tr class="row68">
410 <td class="col0">res_parse.*</td><td class="col1 leftalign">A parser, to read the resource (menu items etc) form PCB </td>
411 </tr>
412 <tr class="row69">
413 <td class="col0">H</td><td class="col1">resource.h</td><td class="col2"> </td><td class="col3"> </td>
414 </tr>
415 <tr class="row70">
416 <td class="col0">D</td><td class="col1">rotate.*</td><td class="col2 leftalign">functions used to rotate pins, elements … </td><td class="col3"> </td>
417 </tr>
418 <tr class="row71">
419 <td class="col0">C</td><td class="col1">rtree.*</td><td class="col2 leftalign">r-tree functions </td><td class="col3">a way to quickly find 2-D objects in a 2-D space</td>
420 </tr>
421 <tr class="row72">
422 <td class="col0"> </td><td class="col1">rubberband.*</td><td class="col2 leftalign">functions used by &#039;rubberband moves&#039; </td><td class="col3"> </td>
423 </tr>
424 <tr class="row73">
425 <td class="col0">C</td><td class="col1">search.*</td><td class="col2 leftalign">search routines some of the functions use dummy parameters </td><td class="col3"> </td>
426 </tr>
427 <tr class="row74">
428 <td class="col0">C</td><td class="col1">select.*</td><td class="col2 leftalign">select routines </td><td class="col3"> </td>
429 </tr>
430 <tr class="row75">
431 <td class="col0">C</td><td class="col1">set.*</td><td class="col2 leftalign">routines to update widgets and global settings (except output window and dialogs) </td><td class="col3"> </td>
432 </tr>
433 <tr class="row76">
434 <td class="col0">C</td><td class="col1">strflags.*</td><td class="col2 leftalign">Some flags routines </td><td class="col3"> </td>
435 </tr>
436 <tr class="row77">
437 <td class="col0">C</td><td class="col1">thermal.*</td><td class="col2 leftalign">negative thermal finger polygons </td><td class="col3"> </td>
438 </tr>
439 <tr class="row78">
440 <td class="col0"> </td><td class="col1">toporouter.*</td><td class="col2 leftalign">This file implements a topological autorouter. </td><td class="col3">Please take a look inside the file for some literature references on the toporouter.</td>
441 </tr>
442 <tr class="row79">
443 <td class="col0">C</td><td class="col1">undo.*</td><td class="col2 leftalign">functions used to undo operations </td><td class="col3"> </td>
444 </tr>
445 <tr class="row80">
446 <td class="col0">C</td><td class="col1">vector.*</td><td class="col2 leftalign">operations on vectors. </td><td class="col3"> </td>
447 </tr>
448 <tr class="row81">
449 <td class="col0">H</td><td class="col1">vendor.*</td><td class="col2 leftalign">routines to generate vendor specific output </td><td class="col3">vendor.c is used to load vendor-specific DRC rules and apply them.</td>
450 </tr>
451 </table></div>
452 <!-- EDIT9 TABLE [2906-11399] -->
454 D = These files have there focus on the Data Functionality. They manipulate the <a href="geda-pcb_developer_introduction.html#pcbtype" class="wikilink1" title="geda-pcb_developer_introduction.html">PCBType</a> or <a href="geda-pcb_developer_introduction.html#datatype" class="wikilink1" title="geda-pcb_developer_introduction.html">DataType</a> structure.
455 </p>
458 C = These files have there focus on the Core Functionality. They support the overall working of the program.
459 </p>
462 H = These files have there focus on the HID Functionality. They support the HID actions and requests.
463 </p>
465 </div>
466 <!-- EDIT8 SECTION "src Directory file list" [2821-11804] -->
467 <h2 class="sectionedit10" id="build_system">Build system</h2>
468 <div class="level2">
471 You must have a working build system before you even can think about hacking the source code. Make sure you can build a git clone.<br/>
473 Try building the sources from git before you try anything else.<br/>
475 The wiki page <a href="http://wiki.geda-project.org/geda:developer" class="urlextern" title="http://wiki.geda-project.org/geda:developer" rel="nofollow">http://wiki.geda-project.org/geda:developer</a> shows the git command to get the geda-gaf repository. We are talking about pcb here.<br/>
476 For pcb we need to do:
477 </p>
478 <pre class="code">git clone git://git.geda-project.org/pcb.git</pre>
481 For the other repositories take a look at <a href="http://git.geda-project.org/" class="urlextern" title="http://git.geda-project.org/" rel="nofollow">http://git.geda-project.org/</a>
482 </p>
485 Next get your build system working. <a href="http://wiki.geda-project.org/geda:gaf_building_git_version" class="urlextern" title="http://wiki.geda-project.org/geda:gaf_building_git_version" rel="nofollow">http://wiki.geda-project.org/geda:gaf_building_git_version</a>
486 </p>
489 While working on the pcb sources remember that PCB uses The AutoTools as there build system.<br/>
490 This isn&#039;t as daunting as it sounds, for the newbie developer.<br/>
491 The PCB development team has made it easy for us.
492 </p>
495 Generally just run:
496 </p>
497 <pre class="code">./autogen.sh</pre>
500 and the scary part is over <img src="images/smileys/icon_wink.gif" align="middle" alt=";-)" />
501 </p>
504 Then do the usual:
505 </p>
506 <pre class="code">./configure
507 make</pre>
510 The autogen.sh script is usually only needed once, after a git clone or if a file is added to be build into PCB. See <a href="geda-pcb_developer_introduction.html#example" class="wikilink1" title="geda-pcb_developer_introduction.html">Example</a> on when to use the autogen.sh script.
511 </p>
514 For more information on the AutoTools take a look at: <a href="https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html" class="urlextern" title="https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html" rel="nofollow">https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html</a>
515 </p>
518 If you want to know more about git take a look at: <a href="https://git-scm.com/docs/gittutorial" class="urlextern" title="https://git-scm.com/docs/gittutorial" rel="nofollow">https://git-scm.com/docs/gittutorial</a>
519 </p>
521 </div>
522 <!-- EDIT10 SECTION "Build system" [11805-13196] -->
523 <h2 class="sectionedit11" id="dependencies">Dependencies</h2>
524 <div class="level2">
527 PCB is a open source program and it uses open source libraries and tools to do what it does.
528 Doing a <code>repoquery –requires pcb</code> on my Fedora 20 system show the following dependencies:
529 </p>
530 <div class="table sectionedit12"><table class="inline">
531 <tr class="row0">
532 <td class="col0 rightalign"> perl</td><td class="col1 rightalign"> libdl.so.2()</td><td class="col2 rightalign"> libm.so.6(GLIBC_2.2.5)</td>
533 </tr>
534 <tr class="row1">
535 <td class="col0 rightalign"> wish</td><td class="col1 rightalign"> libdl.so.2(GLIBC_2.2.5)</td><td class="col2 rightalign"> libpango-1.0.so.0()</td>
536 </tr>
537 <tr class="row2">
538 <td class="col0 rightalign"> libGL.so.1()</td><td class="col1 rightalign"> libfontconfig.so.1()</td><td class="col2 rightalign"> libpangocairo-1.0.so.0()</td>
539 </tr>
540 <tr class="row3">
541 <td class="col0 rightalign"> libGLU.so.1()</td><td class="col1 rightalign"> libfreetype.so.6()</td><td class="col2 rightalign"> libpangoft2-1.0.so.0()</td>
542 </tr>
543 <tr class="row4">
544 <td class="col0 rightalign"> libICE.so.6()</td><td class="col1 rightalign"> libgd.so.3()</td><td class="col2 rightalign"> libpangox-1.0.so.0()</td>
545 </tr>
546 <tr class="row5">
547 <td class="col0 rightalign"> libSM.so.6()</td><td class="col1 rightalign"> libgdk-x11-2.0.so.0()</td><td class="col2 rightalign"> libpng16.so.16()</td>
548 </tr>
549 <tr class="row6">
550 <td class="col0 rightalign"> libX11.so.6()</td><td class="col1 rightalign"> libgdk_pixbuf-2.0.so.0()</td><td class="col2 rightalign"> libpthread.so.0()</td>
551 </tr>
552 <tr class="row7">
553 <td class="col0 rightalign"> libXinerama.so.1()</td><td class="col1 rightalign"> libgdkglext-x11-1.0.so.0()</td><td class="col2 rightalign"> libpthread.so.0(GLIBC_2.2.5)</td>
554 </tr>
555 <tr class="row8">
556 <td class="col0 rightalign"> libXmu.so.6()</td><td class="col1 rightalign"> libgio-2.0.so.0()</td><td class="col2 rightalign"> libtiff.so.5()</td>
557 </tr>
558 <tr class="row9">
559 <td class="col0 rightalign"> libXpm.so.4()</td><td class="col1 rightalign"> libglib-2.0.so.0()</td><td class="col2 rightalign"> libvpx.so.1()</td>
560 </tr>
561 <tr class="row10">
562 <td class="col0 rightalign"> libXrender.so.1()</td><td class="col1 rightalign"> libgmodule-2.0.so.0()</td><td class="col2 rightalign"> libz.so.1()</td>
563 </tr>
564 <tr class="row11">
565 <td class="col0 rightalign"> libXt.so.6()</td><td class="col1 rightalign"> libgobject-2.0.so.0()</td><td class="col2 rightalign"> m4</td>
566 </tr>
567 <tr class="row12">
568 <td class="col0 rightalign"> libatk-1.0.so.0()</td><td class="col1 rightalign"> libgtk-x11-2.0.so.0()</td><td class="col2 rightalign"> perl(File::Basename)</td>
569 </tr>
570 <tr class="row13">
571 <td class="col0 rightalign"> libc.so.6(GLIBC_2.14)</td><td class="col1 rightalign"> libgtkglext-x11-1.0.so.0()</td><td class="col2 rightalign"> perl(File::Copy)</td>
572 </tr>
573 <tr class="row14">
574 <td class="col0 rightalign"> libcairo.so.2()</td><td class="col1 rightalign"> libjpeg.so.62()</td><td class="col2 rightalign"> rtld(GNU_HASH)</td>
575 </tr>
576 <tr class="row15">
577 <td class="col0 rightalign"> libdbus-1.so.3()</td><td class="col1 rightalign"> libm.so.6()</td><td class="col2"> </td>
578 </tr>
579 </table></div>
580 <!-- EDIT12 TABLE [13410-14361] -->
581 </div>
582 <!-- EDIT11 SECTION "Dependencies" [13197-14362] -->
583 <h2 class="sectionedit13" id="trace_an_action">Trace an action</h2>
584 <div class="level2">
587 Here is a short introduction where to start if you want to trace an action down into the source code:
588 Lets draw a line in the (GTK) <abbr title="Graphical User Interface">GUI</abbr>.
589 </p>
592 If we start pcb the default mode is the select mode, in order to draw a trace we need to switch to the LINE mode. We do that by pressing <kbd>F2</kbd>. Next we use the mouse to select a starting point and do a left click of the mouse button. Now we can start drawing a trace.
593 </p>
596 So what happens in the source code? PCB uses a flexible way of implementing menu structures and it uses a flexible way to implement actions the program should do. All this flexibility made it a bit difficult for me to see where to start.
597 </p>
599 </div>
600 <!-- EDIT13 SECTION "Trace an action" [14363-15045] -->
601 <h3 class="sectionedit14" id="f2_key">F2 key</h3>
602 <div class="level3">
605 First let&#039;s trace the LINE mode selecting by pressing <kbd>F2</kbd>.
606 </p>
609 In the file <em><strong>gpcb-menu.res</strong></em> we look for our <kbd>F2</kbd> key and we find
610 </p>
611 <pre class="code">{&quot;Line&quot; checked=linemode,1 Mode(Line) a={&quot;F2&quot; &quot;&lt;Key&gt;F2&quot;}}</pre>
614 In the file <em><strong>action.c</strong></em> we find
615 </p>
616 <pre class="code">HID_Action action_action_list[] {&quot;Mode&quot;, 0, ActionMode, mode_help, mode_syntax}</pre>
619 The action_action_list defines that the <strong>Mode</strong> event is translated into the <em class="u">ActionMode</em> function. So the function called when we press <kbd>F2</kbd> is <code>ActionMode(Line)</code>.
620 </p>
623 ActionMode is a generic function and therefore it will need to find what to do.
624 </p>
625 <pre class="code c">ActionMode <span class="br0">&#40;</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> Coord x<span class="sy0">,</span> Coord y<span class="br0">&#41;</span></pre>
628 It will do that by calling <code>GetFunctionID (AGV[0])</code> in this example AGV[0] = Line. The function ID will tell it to do the function <code>SetMode (LINE_MODE);</code>
629 </p>
632 That function will set the variable <strong>Settings.Mode</strong> to LINE_MODE
633 </p>
636 <a href="media/devel_intro/set_mode.png" class="media" target="_blank" title="devel_intro:set_mode.png"><img src="media/devel_intro/set_mode.png" class="media" alt="" /></a>
637 </p>
639 </div>
640 <!-- EDIT14 SECTION "F2 key" [15046-16000] -->
641 <h3 class="sectionedit15" id="mouse_click">Mouse click</h3>
642 <div class="level3">
645 Next we trace down what will happen if we left click the mouse button to start drawing a track.<br/>
646 Please note this is a very simplified call graph.
647 </p>
650 <a href="media/devel_intro/draw_line.png" class="media" target="_blank" title="devel_intro:draw_line.png"><img src="media/devel_intro/draw_line.png" class="media" alt="" /></a>
651 </p>
654 In the file <em><strong>gpcb-menu.res</strong></em> Left mouse click Mouse = Left ⇒ points to Mode(Notify)
655 </p>
658 [*1] Mode(Notify)
659 </p>
662 <strong>Mode</strong> translates in the action_action_list into _ActionMode_
663 </p>
666 [*2] Left mouse click translates into calling function ActionMode(Notify)
667 </p>
670 [*3] The program will go back and forth between NotifyMode and NotifyLine until [*4].<br/>
672 In the function NotifyLine all the dynamic processing is done, meaning that here the limitations and restrictions are check realtime. e.g. if the Auto force DRC check flag is checked, this function checks if we try to draw over existing copper.
673 </p>
676 [*4]if two points are selected we can create a line
677 </p>
680 [*5] We need to free memory-space and add our new Line into the linked list. This is done through the GLIB Library.
681 Next our newly created LINE object is filled with the relevant data.
682 Basically we are done, the line is added to the data structure. However there is one more thing to do.
683 </p>
686 [*6] Our new line is stored into the main PCBType data structure (actually in the DataType sub structure). Now there is one more administrative task to do, the newly created line must be add to the rtree data structure. Every item that is added to the data structure is also added to the rtree data structure. The R-TREE data structure makes it easy to search for free or occupied areas on a layer.
687 </p>
690 This is in a very simplified description on what happens and the path the software takes to draw a line.
691 </p>
693 </div>
694 <!-- EDIT15 SECTION "Mouse click" [16001-17637] -->
695 <h2 class="sectionedit16" id="crosshair">Crosshair</h2>
696 <div class="level2">
699 From: <a href="http://www.delorie.com/pcb/docs/gs/gs.html#Terminology" class="urlextern" title="http://www.delorie.com/pcb/docs/gs/gs.html#Terminology" rel="nofollow">http://www.delorie.com/pcb/docs/gs/gs.html#Terminology</a>
700 </p>
703 <em>crosshair</em>
704 </p>
707 This is the actual location on the <a href="http://www.delorie.com/pcb/docs/gs/gs.html#board" class="urlextern" title="http://www.delorie.com/pcb/docs/gs/gs.html#board" rel="nofollow">board</a> which is used when you perform an <a href="http://www.delorie.com/pcb/docs/gs/gs.html#action" class="urlextern" title="http://www.delorie.com/pcb/docs/gs/gs.html#action" rel="nofollow">action</a>. If <a href="http://www.delorie.com/pcb/docs/gs/gs.html#grid" class="urlextern" title="http://www.delorie.com/pcb/docs/gs/gs.html#grid" rel="nofollow">grid</a> snap is active, the crosshair reflects the grid point closest to the <a href="http://www.delorie.com/pcb/docs/gs/gs.html#cursor" class="urlextern" title="http://www.delorie.com/pcb/docs/gs/gs.html#cursor" rel="nofollow">cursor</a>, else the crosshair reflects the <a href="http://www.delorie.com/pcb/docs/gs/gs.html#cursor" class="urlextern" title="http://www.delorie.com/pcb/docs/gs/gs.html#cursor" rel="nofollow">cursor</a> itself.
708 </p>
711 So the crosshair is the X Y position on the PCB canvas. When grid is enabled the crosshair is automatically snapped to the grid.<br/>
712 Let&#039;s see how that works:
713 </p>
716 Open the file <em><strong>crosshair.c</strong></em> with your favourite text editor and look for the function <code>FitCrosshairIntoGrid.</code> In my version its around line 920.
717 </p>
720 Add the debug code into the function:
721 </p>
722 <pre class="code c"><span class="coMULTI">/* ---------------------------------------------------------------------------
723 * recalculates the passed coordinates to fit the current grid setting
724 */</span>
725 <span class="kw4">void</span>
726 FitCrosshairIntoGrid <span class="br0">&#40;</span>Coord X<span class="sy0">,</span> Coord Y<span class="br0">&#41;</span>
727 <span class="br0">&#123;</span>
728 Coord nearest_grid_x<span class="sy0">,</span> nearest_grid_y<span class="sy0">;</span>
729 <span class="kw4">void</span> <span class="sy0">*</span>ptr1<span class="sy0">,</span> <span class="sy0">*</span>ptr2<span class="sy0">,</span> <span class="sy0">*</span>ptr3<span class="sy0">;</span>
730 <span class="kw4">struct</span> snap_data snap_data<span class="sy0">;</span>
731 <span class="kw4">int</span> ans<span class="sy0">;</span>
732 &nbsp;
733 <span class="coMULTI">/* Add the next two lines */</span>
734 <span class="coMULTI">/* RZE: Debug code please remove if I forget */</span>
735 pcb_printf<span class="br0">&#40;</span><span class="st0">&quot;X=%d, Y=%d<span class="es1">\n</span>&quot;</span><span class="sy0">,</span> Crosshair.<span class="me1">X</span><span class="sy0">,</span> Crosshair.<span class="me1">Y</span><span class="br0">&#41;</span><span class="sy0">;</span>
736 &nbsp;
737 Crosshair.<span class="me1">X</span> <span class="sy0">=</span> CLAMP <span class="br0">&#40;</span>X<span class="sy0">,</span> Crosshair.<span class="me1">MinX</span><span class="sy0">,</span> Crosshair.<span class="me1">MaxX</span><span class="br0">&#41;</span><span class="sy0">;</span><span class="st0">''</span>
738 Crosshair.<span class="me1">Y</span> <span class="sy0">=</span> CLAMP <span class="br0">&#40;</span>Y<span class="sy0">,</span> Crosshair.<span class="me1">MinY</span><span class="sy0">,</span> Crosshair.<span class="me1">MaxY</span><span class="br0">&#41;</span><span class="sy0">;</span><span class="st0">''</span></pre>
741 Try!
742 From the command-line terminal do:
743 </p>
744 <pre class="code">cd &lt;to_pcb_source_directory&gt;
745 ./configure
746 make
747 src/pcb</pre>
750 In your terminal you will see the X and Y coordinates of the crosshair.<br/>
751 Please note that they are rounded numbers.<br/>
752 Turn off grid snapping and watch the numbers.
753 </p>
756 Congratulations, you just hacked into the PCB source code <img src="images/smileys/icon_wink.gif" align="middle" alt=";-)" />
757 </p>
759 </div>
760 <!-- EDIT16 SECTION "Crosshair" [17638-19499] -->
761 <h2 class="sectionedit17" id="example">Example</h2>
762 <div class="level2">
765 As an exercise let&#039;s do something easy, like adding an action to PCB.
766 </p>
769 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>
770 It is essential that you have a working build system.
771 </p>
774 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.
775 </p>
778 First make a file called <em><strong>example.c</strong></em> and add:
779 </p>
780 <pre class="code c"><span class="coMULTI">/*!
781 * =====================================================================================
783 * COPYRIGHT
784 * Example action implementation for PCB.
785 * Copyright (C) 2015 Robert Zeegers
787 * This program is free software; you can redistribute it and/or
788 * modify it under the terms of the GNU General Public License
789 * as published by the Free Software Foundation; either version 2
790 * of the License, or (at your option) any later version.
792 * This program is distributed in the hope that it will be useful,
793 * but WITHOUT ANY WARRANTY; without even the implied warranty of
794 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
795 * GNU General Public License for more details.
797 * You should have received a copy of the GNU General Public License
798 * along with this program; if not, write to the Free Software
799 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
801 * \File: example.c
802 * \Brief: Example on how to implement a action in the PCB program.
803 * \par Description
804 * Example action implementation for PCB, interactive printed circuit board design
805 * \copyright (C) 2015 Robert Zeegers
807 * \Version: 1.0
808 * Created: 24/07/15
810 * \Todo: nothing
811 * \Bug: not that I know of
813 * =====================================================================================
814 */</span>
815 &nbsp;
816 <span class="coMULTI">/* First thing todo is include global.h */</span>
817 <span class="coMULTI">/* This will automatically also include const.h and macro.h */</span>
818 <span class="co2">#include &quot;global.h&quot;</span>
819 &nbsp;
820 <span class="coMULTI">/* Second we include hid.h because we want to register our action to the HID */</span>
821 <span class="co2">#include &quot;hid.h&quot;</span>
822 &nbsp;
823 <span class="coMULTI">/* We are going to add an action and therefore we want it to show-up in the PCB manual, */</span>
824 <span class="coMULTI">/* so we add some documentation comments */</span>
825 <span class="coMULTI">/* For the documentation style see the &quot;extract-docs&quot; perl script in the doc directory */</span>
826 &nbsp;
827 <span class="coMULTI">/* %start-doc actions DoSilly
828 This function doesn't do anything useful.
829 &nbsp;
830 @example
831 DoSilly()
832 @end example
833 &nbsp;
834 %end-doc */</span>
835 &nbsp;
836 <span class="coMULTI">/* All action entry functions must have the same syntax as defined in */</span>
837 <span class="coMULTI">/* typedef struct HID_Action (hid.h) */</span>
838 <span class="kw4">static</span> <span class="kw4">int</span>
839 ExampleDo <span class="br0">&#40;</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">&#41;</span>
840 <span class="br0">&#123;</span>
841 <span class="coMULTI">/* It should do something, so let's do something silly */</span>
842 <span class="coMULTI">/* Let's write a Dutch songtext to the Message Log window */</span>
843 <span class="coMULTI">/* The struct HID is defined in hid.h */</span>
844 <span class="coMULTI">/* and the variable gui is made available there by &quot;extern HID *gui;&quot; */</span>
845 <span class="coMULTI">/* First we check if we have a gui. */</span>
846 <span class="kw1">if</span><span class="br0">&#40;</span> <span class="nu0">1</span> <span class="sy0">==</span> gui<span class="sy0">-&gt;</span>gui <span class="br0">&#41;</span>
847 <span class="br0">&#123;</span>
848 <span class="coMULTI">/* if we have one let's write the songtext */</span>
849 gui<span class="sy0">-&gt;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/log.html"><span class="kw3">log</span></a> <span class="br0">&#40;</span>_<span class="br0">&#40;</span><span class="st0">&quot;Iedereen is van de wereld en de wereld is van iedereen!<span class="es1">\n</span>&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
850 <span class="br0">&#125;</span>
851 <span class="br0">&#125;</span>
852 &nbsp;
853 <span class="coMULTI">/* Now we have to make an action list. */</span>
854 <span class="coMULTI">/* Here we make the connection between our command &quot;DoSilly()&quot; and */</span>
855 <span class="coMULTI">/* the actual function which should be executed ExampleDo().*/</span>
856 <span class="kw4">static</span> HID_Action exampledo_action_list<span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#123;</span>
857 <span class="br0">&#123;</span><span class="st0">&quot;DoSilly&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Example action&quot;</span><span class="sy0">,</span> ExampleDo<span class="sy0">,</span> <span class="st0">&quot;Always provide some help&quot;</span><span class="sy0">,</span> <span class="st0">&quot;DoSilly()&quot;</span><span class="br0">&#125;</span>
858 <span class="br0">&#125;</span><span class="sy0">;</span>
859 &nbsp;
860 <span class="coMULTI">/* Next a macro to register the action in the HID */</span>
861 <span class="coMULTI">/* Note the missing ; at the end, that's correct ;-) */</span>
862 REGISTER_ACTIONS <span class="br0">&#40;</span>exampledo_action_list<span class="br0">&#41;</span></pre>
865 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>.
866 </p>
869 Next we need to add our file to the build system.<br/>
871 We do that in the file <em><strong>MakeFile.am</strong></em>.<br/>
872 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.
873 </p>
876 Clean your build directory by doing:
877 </p>
878 <pre class="code">make distclean</pre>
881 Then do:
882 </p>
883 <pre class="code">./autogen.sh</pre>
886 Now our file is in <em><strong>MakeFile.in</strong></em>
887 </p>
890 Next do:
891 </p>
892 <pre class="code">./configure
893 make</pre>
896 Run:
897 </p>
898 <pre class="code">src/pcb</pre>
901 In the PCB program type “:DoSilly()” and watch the message log window.
902 </p>
905 And do check out the pcb manual in doc/pcb.pdf search for “DoSilly”
906 </p>
908 </div>
909 <!-- EDIT17 SECTION "Example" [19500-23774] -->
910 <h2 class="sectionedit18" id="register">REGISTER</h2>
911 <div class="level2">
914 <strong>REGISTER_ACTIONS - REGISTER_FLAGS - REGISTER_ATTRIBUTES</strong>
915 </p>
918 Every action file must register its actions in the HID.
919 The action file will have an
920 </p>
921 <pre class="code c"><span class="co2">#include &quot;hid.h&quot;</span></pre>
924 which define the REGISTER_* macros.
925 Then somewhere in the file you add:
926 </p>
927 <pre class="code">REGISTER_ACTIONS(exampledo_action_list)</pre>
930 This will be expanded by the preprocessor into:
931 </p>
932 <pre class="code c"><span class="kw4">void</span> register_exampledo_action_list<span class="br0">&#40;</span><span class="br0">&#41;</span>
933 <span class="br0">&#123;</span> hid_register_actions<span class="br0">&#40;</span>exampledo_action_list<span class="sy0">,</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="br0">&#125;</span></pre>
936 During the build process the files <em><strong>core_lists.h</strong></em> and <em><strong>gtk_lists.h</strong></em> are created. These files contain nothing more than a collection of REGISTER_* instructions it found in its source files.<br/>
937 So <em><strong>core_lists.h</strong></em> and <em><strong>gtk_lists.h</strong></em> will contain:
938 </p>
939 <pre class="code">REGISTER_ACTION(exampledo_action_list)</pre>
942 In the file <em><strong>main.c</strong></em> around the <em class="u">main</em> functions we find the instruction:
943 </p>
944 <pre class="code c"><span class="co2">#include &quot;dolists.h&quot;</span></pre>
947 And soon after that we find
948 </p>
949 <pre class="code c"><span class="co2">#include &quot;core_lists.h&quot;</span></pre>
952 Because <em><strong>dolists.h</strong></em> redefines the REGISTER_* macros, the macros in <em><strong>core_lists.h</strong></em>
953 </p>
954 <pre class="code">REGISTER_ACTIONS(exampledo_action_list)</pre>
957 will be expanded by the preprocessor into:
958 </p>
959 <pre class="code c">external <span class="kw4">void</span> register_exampledo_action_list<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
960 register_exampledo_action_list<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre>
963 And therefore it will call all functions to register the actions at the beginning of the main function.
964 </p>
966 </div>
967 <!-- EDIT18 SECTION "REGISTER" [23775-25153] -->
968 <h3 class="sectionedit19" id="options">Options</h3>
969 <div class="level3">
970 <div class="table sectionedit20"><table class="inline">
971 <tr class="row0">
972 <td class="col0">REGISTER_ACTIONS</td><td class="col1">These actions can be called though the user command window (start with “:” in the PCB program.</td>
973 </tr>
974 <tr class="row1">
975 <td class="col0">REGISTER_FLAGS</td><td class="col1">These flags initiate a functions when set or unset.<br/>
976 E.g. in file <em><strong>flags.c</strong></em> we find <pre class="code c">HID_Flag flags_flag_list<span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#123;</span>
977 <span class="br0">&#123;</span><span class="st0">&quot;style&quot;</span><span class="sy0">,</span> FlagCurrentStyle<span class="sy0">,</span> NULL<span class="br0">&#125;</span><span class="sy0">,</span>
978 <span class="br0">&#123;</span><span class="st0">&quot;grid&quot;</span><span class="sy0">,</span> FlagGrid<span class="sy0">,</span> NULL<span class="br0">&#125;</span><span class="sy0">,</span></pre>
981 The “grid” flags is associated with the menu flag: <strong>View→enable visible grid</strong> and makes the connection to the <code>FlagGrid()</code> function.<br/>
982 If you select <strong>View→enable visible grid</strong> the function <code>FlagGrid</code> will be called.
983 </p>
984 </td>
985 </tr>
986 <tr class="row2">
987 <td class="col0">REGISTER_ATTRIBUTES</td><td class="col1">In <em><strong>main.c</strong></em> there is a call to this macro: <code>REGISTER_ATTRIBUTES (main_attribute_list)</code><br/>
988 The main_attribute_list defines the command-line options.<br/>
989 Most of the HID also use this macro, to add their command line options as well.</td>
990 </tr>
991 </table></div>
992 <!-- EDIT20 TABLE [25173-26028] -->
993 </div>
994 <!-- EDIT19 SECTION "Options" [25154-26029] -->
995 <h2 class="sectionedit21" id="pcbtype">PCBType</h2>
996 <div class="level2">
999 PCBType is the main data structure
1000 </p>
1003 PCBType contain all the general information used in the program and it contains a pointer to the DataType
1004 </p>
1007 <a href="media/devel_intro/structpcbtype_graph.png" class="media" target="_blank" title="devel_intro:structpcbtype_graph.png"><img src="media/devel_intro/structpcbtype_graph.png" class="media" alt="" /></a>
1008 </p>
1010 </div>
1011 <!-- EDIT21 SECTION "PCBType" [26030-26235] -->
1012 <h2 class="sectionedit22" id="datatype">DataType</h2>
1013 <div class="level2">
1016 The DataType contains the actual data that defines our printed circuit board.
1017 </p>
1020 DataType is what&#039;s stored in the Buffers when you do cut/paste.
1021 </p>
1022 <div class="table sectionedit23"><table class="inline">
1023 <thead>
1024 <tr class="row0">
1025 <th class="col0">Data Fields </th><th class="col1" colspan="2"> </th>
1026 </tr>
1027 </thead>
1028 <tr class="row1">
1029 <td class="col0">Cardinal</td><td class="col1">ViaN</td><td class="col2"> </td>
1030 </tr>
1031 <tr class="row2">
1032 <td class="col0">Cardinal</td><td class="col1">ElementN</td><td class="col2"> </td>
1033 </tr>
1034 <tr class="row3">
1035 <td class="col0">Cardinal</td><td class="col1">RatN</td><td class="col2"> </td>
1036 </tr>
1037 <tr class="row4">
1038 <td class="col0">int</td><td class="col1">LayerN</td><td class="col2"> </td>
1039 </tr>
1040 <tr class="row5">
1041 <td class="col0">GList *</td><td class="col1">Via</td><td class="col2">Layer independent via&#039;s</td>
1042 </tr>
1043 <tr class="row6">
1044 <td class="col0">GList *</td><td class="col1">Element</td><td class="col2">Layer independent elements</td>
1045 </tr>
1046 <tr class="row7">
1047 <td class="col0">GList *</td><td class="col1">Rat</td><td class="col2">Layer independent rat-lines</td>
1048 </tr>
1049 <tr class="row8">
1050 <td class="col0">rtree_t *</td><td class="col1">via_tree</td><td class="col2"> </td>
1051 </tr>
1052 <tr class="row9">
1053 <td class="col0">rtree_t *</td><td class="col1">element_tree</td><td class="col2"> </td>
1054 </tr>
1055 <tr class="row10">
1056 <td class="col0">rtree_t *</td><td class="col1">pin_tree</td><td class="col2"> </td>
1057 </tr>
1058 <tr class="row11">
1059 <td class="col0">rtree_t *</td><td class="col1">pad_tree</td><td class="col2"> </td>
1060 </tr>
1061 <tr class="row12">
1062 <td class="col0">rtree_t *</td><td class="col1">name_tree [3]</td><td class="col2"> </td>
1063 </tr>
1064 <tr class="row13">
1065 <td class="col0">rtree_t *</td><td class="col1">rat_tree</td><td class="col2"> </td>
1066 </tr>
1067 <tr class="row14">
1068 <td class="col0">struct PCBType *</td><td class="col1">pcb</td><td class="col2">A pointer back to the main data structure</td>
1069 </tr>
1070 <tr class="row15">
1071 <td class="col0">LayerType</td><td class="col1">Layer [MAX_LAYER+2]</td><td class="col2">All layer dependent items</td>
1072 </tr>
1073 <tr class="row16">
1074 <td class="col0">int</td><td class="col1">polyClip</td><td class="col2"> </td>
1075 </tr>
1076 </table></div>
1077 <!-- EDIT23 TABLE [26402-26904] -->
1079 The actual data is stored in the <a href="geda-pcb_developer_introduction.html#glist" class="wikilink1" title="geda-pcb_developer_introduction.html">GList</a> data elements. The rest is there for administrative purposes, to keep track of it all.
1080 Here I like to specially mention the rtree_t* data members. Although they have an administrative character the <a href="geda-pcb_developer_introduction.html#r-tree" class="wikilink1" title="geda-pcb_developer_introduction.html">R-TREE</a> data structure is heavily used in the PCB program.
1081 </p>
1083 </div>
1084 <!-- EDIT22 SECTION "DataType" [26236-27276] -->
1085 <h2 class="sectionedit24" id="glist">GList</h2>
1086 <div class="level2">
1087 <pre class="code c"><span class="kw4">struct</span> GList <span class="br0">&#123;</span>
1088 gpointer data<span class="sy0">;</span>
1089 GList <span class="sy0">*</span>next<span class="sy0">;</span>
1090 GList <span class="sy0">*</span>prev<span class="sy0">;</span>
1091 <span class="br0">&#125;</span><span class="sy0">;</span> </pre>
1094 The GList struct is used for each element in a doubly-linked list.
1095 </p>
1098 Members:
1099 </p>
1100 <div class="table sectionedit25"><table class="inline">
1101 <tr class="row0">
1102 <td class="col0">gpointer data</td><td class="col1">holds the element&#039;s data , which can be a pointer to any kind of data.</td>
1103 </tr>
1104 <tr class="row1">
1105 <td class="col0">GList *next</td><td class="col1">contains the link to the next element in the list</td>
1106 </tr>
1107 <tr class="row2">
1108 <td class="col0">GList *prev;</td><td class="col1">contains the link to the previous element in the list</td>
1109 </tr>
1110 </table></div>
1111 <!-- EDIT25 TABLE [27458-27677] -->
1113 gpointer ⇒
1114 </p>
1115 <pre class="code c"><span class="kw4">typedef</span> <span class="kw4">void</span><span class="sy0">*</span> gpointer<span class="sy0">;</span></pre>
1118 An untyped pointer. <code>gpointer</code> looks better and is easier to use than <code>void*</code>.
1119 </p>
1121 </div>
1122 <!-- EDIT24 SECTION "GList" [27277-27816] -->
1123 <h2 class="sectionedit26" id="r-tree">R-TREE</h2>
1124 <div class="level2">
1127 From Wikipedia:
1128 The key idea of the r-tree data structure is to group nearby objects and represent them with their minimum bounding rectangle in the next higher level of the tree; the “R” in R-tree is for rectangle. Since all objects lie within this bounding rectangle, a query that does not intersect the bounding rectangle also cannot intersect any of the contained objects. At the leaf level, each rectangle describes a single object; at higher levels the aggregation of an increasing number of objects. This can also be seen as an increasingly coarse approximation of the data set.
1129 </p>
1132 A general r-tree will look like this:
1133 </p>
1136 <a href="media/devel_intro/rtree.png" class="media" target="_blank" title="devel_intro:rtree.png"><img src="media/devel_intro/rtree.png" class="media" alt="" /></a>
1137 </p>
1140 The bottom row of records are called leafs.
1141 </p>
1144 The rtree data structure PCB uses is:
1145 </p>
1148 <a href="media/devel_intro/structrtree.png" class="media" target="_blank" title="devel_intro:structrtree.png"><img src="media/devel_intro/structrtree.png" class="media" alt="" /></a>
1149 </p>
1152 The r-tree data structure hold a copy of the where&#039;s what data. Meaning that it holds a list of every item on our canvas arranged in successively smaller boxes.
1153 <a href="media/devel_intro/rtreepicture.png" class="media" target="_blank" title="devel_intro:rtreepicture.png"><img src="media/devel_intro/rtreepicture.png" class="media" alt="" /></a>
1154 </p>
1156 </div>
1157 <!-- EDIT26 SECTION "R-TREE" [27817-28805] -->
1158 <h2 class="sectionedit27" id="more_in-depth_explanations">More in-depth explanations:</h2>
1159 <div class="level2">
1160 <ol>
1161 <li class="level1"><div class="li"> DRC</div>
1162 </li>
1163 <li class="level1"><div class="li"> ?</div>
1164 </li>
1165 </ol>
1167 </div>
1168 <!-- EDIT27 SECTION "More in-depth explanations:" [28806-] --></body>
1169 </html>