Added gerb_freset() to be able to reset file pointer to start of file.
[geda-gerbv/spe.git] / doc / example-code / example4.c
blob2791af717e791a7da0382345b6093ff0ee8c62b7
1 /*------------------------------------------------------------------------------
2 Filename: example4.c
4 Description: Loads example4-input.gbx, searches through the file and
5 removes any entities with a width less than 60mils, and re-exports
6 the modified image to a new RS274X file.
8 Instructions: Make sure you are in the example-code directory, and compile
9 this program with the following command:
11 gcc -Wall -g `pkg-config --cflags libgerbv` `pkg-config --libs libgerbv` example4.c -o example4
13 Run with the following command:
15 ./example4
17 Common compiling problems:
18 1. If you are compiling gerbv from source, make sure you run
19 "make install" before trying to compile this example. This
20 ensures libgerbv is correctly installed and can be found.
21 2. If you installed gerbv to "/usr/local" (the default), many
22 distributions don't correctly point pkgconfig to this target.
23 To fix this, add the following to your ~/.bashrc file:
25 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:/usr/lib/pkgconfig/
26 ------------------------------------------------------------------------------*/
28 #include "gerbv.h"
30 int
31 main(int argc, char *argv[]) {
32 gerbv_image_t *workingImage;
33 gerbv_net_t *currentNet;
35 /* parse and create the image */
36 workingImage = gerbv_create_rs274x_image_from_filename ("example4-input.gbx");
38 /* make sure we parsed the file */
39 if (workingImage == NULL)
40 g_error ("There was an error parsing the file.");
42 /* run through all the nets in the layer */
43 for (currentNet = workingImage->netlist; currentNet; currentNet = currentNet->next){
44 /* check if the net aperture is a circle and has diameter < 0.060 inches */
45 if ((currentNet->aperture_state != GERBV_APERTURE_STATE_OFF) &&
46 (workingImage->aperture[currentNet->aperture] != NULL) &&
47 (workingImage->aperture[currentNet->aperture]->type == GERBV_APTYPE_CIRCLE) &&
48 (workingImage->aperture[currentNet->aperture]->parameter[0] < 0.060)){
49 /* we found a path which meets the criteria, so delete the net for
50 demostration purposes */
51 gerbv_image_delete_net (currentNet);
55 /* export the modified image to a new rs274x file */
56 gerbv_export_rs274x_file_from_image ("example4-output.gbx", workingImage, NULL);
58 /* destroy all created structures */
59 gerbv_destroy_image (workingImage);
60 return 0;