pcb 4.1.1
An interactive printed circuit board layout editor.

layerflags.c

Go to the documentation of this file.
00001 
00031 #ifdef HAVE_CONFIG_H
00032 #include "config.h"
00033 #endif
00034 
00035 #include <stdio.h>
00036 #include <ctype.h>
00037 #ifdef HAVE_STDLIB_H
00038 #include <stdlib.h>
00039 #endif
00040 #ifdef HAVE_STRING_H
00041 #include <string.h>
00042 #endif
00043 
00044 #include "globalconst.h"
00045 #include "global.h"
00046 #include "compat.h"
00047 #include "data.h"
00048 #include "error.h"
00049 #include "hid.h"
00050 #include "strflags.h"
00051 #include "layerflags.h"
00052 
00053 
00060 static char *layertype_name[LT_NUM_LAYERTYPES + 1] = {
00061   "copper",       /* LT_COPPER */
00062   "silk",         /* LT_SILK */
00063   "mask",         /* LT_MASK */
00064   "paste",        /* LT_PASTE */
00065   "outline",      /* LT_OUTLINE */
00066   "route",        /* LT_ROUTE */
00067   "keepout",      /* LT_KEEPOUT */
00068   "fab",          /* LT_FAB */
00069   "assy",         /* LT_ASSY */
00070   "notes",        /* LT_NOTES */
00071   "no_type"       /* LT_NUM_LAYERTYPES */
00072 };
00073 
00074 
00075 LayertypeType
00076 string_to_layertype (const char *flagstring,
00077                      int (*error) (const char *msg))
00078 {
00079   LayertypeType type = 0;
00080 
00081   if (*flagstring == '"')
00082     flagstring++;
00083 
00084   while (flagstring > (char *)1 && strlen (flagstring) > 1)
00085     {
00086       for (type = 0; type < LT_NUM_LAYERTYPES; type++)
00087         {
00088           if (strcmp (flagstring, layertype_name[type]) == 0)
00089             break;
00090         }
00091 
00092       if (type == LT_NUM_LAYERTYPES)
00093         flagstring = strchr (flagstring, ',') + 1;
00094       else
00095         break;
00096     }
00097 
00098   return type;
00099 }
00100 
00101 const char *
00102 layertype_to_string (LayertypeType type)
00103 {
00104   const char *rv = "";
00105 
00106   if (type < LT_NUM_LAYERTYPES)
00107     rv = layertype_name[type];
00108 
00109   return rv;
00110 }
00111 
00119 LayertypeType
00120 guess_layertype (const char *name, int layer_number, DataType *data)
00121 {
00122   LayertypeType type;
00123 
00124   /* First try to find known (partial) matches. */
00125   for (type = 0; type < LT_NUM_LAYERTYPES; type++)
00126     {
00127       if (strcasestr (name, layertype_name[type]))
00128         break;
00129     }
00130 
00131   /* Nothing found? Then it's likely copper. */
00132   if (type == LT_NUM_LAYERTYPES)
00133     type = LT_COPPER;
00134 
00135   return type;
00136 }
00137 
00138 /* --------------------------------------------------------------------------- */
00139 
00140 static const char listlayertypes_syntax[] =
00141   N_("ListLayertypes()");
00142 
00143 static const char listlayertypes_help[] =
00144   N_("List all available layertypes.\n");
00145 
00146 /* %start-doc actions ListLayertypes
00147 
00148 Lists all available layer types. These are the valid types for the second
00149 argument of @pxref{SetLayertype Action} or when editing the layout file with
00150 a text editor.
00151 
00152 %end-doc */
00153 
00154 static int
00155 ActionListLayertypes (int argc, char **argv, Coord x, Coord y)
00156 {
00157   LayertypeType type;
00158 
00159   Message (N_("Available layer types:\n"));
00160   for (type = 0; type < LT_NUM_LAYERTYPES; type++)
00161     Message ("    %s (%d)\n", layertype_name[type], type);
00162 
00163   return 0;
00164 }
00165 
00166 /* --------------------------------------------------------------------------- */
00167 
00168 static const char setlayertype_syntax[] =
00169   N_("SetLayertype(layer, type)");
00170 
00171 static const char setlayertype_help[] =
00172   N_("Sets the type of a layer. Type can be given by name or by number.\n"
00173      "For a list of available types, run ListLayertypes().");
00174 
00175 /* %start-doc actions SetLayertype
00176 
00177 Layers can have various types, like @emph{copper}, @emph{silk} or
00178 @emph{outline}. Behaviour of GUI and exporters largely depend on these types.
00179 For example, searching for electrical connections searches only layers of type
00180 @emph{copper}, all other layers are ignored.
00181 
00182 For a list of available types see @pxref{ListLayertypes Action}.
00183 
00184 %end-doc */
00185 
00186 int
00187 ActionSetLayertype (int argc, char **argv, Coord x, Coord y)
00188 {
00189   int index;
00190   LayertypeType type;
00191 
00192   if (argc != 2)
00193     AFAIL (setlayertype);
00194 
00195   /* layer array is zero-based, file format counts layers starting at 1. */
00196   index = atoi (argv[0]) - 1;
00197   if (index < 0 || index >= max_copper_layer + SILK_LAYER)
00198     {
00199       Message (N_("Layer index %d out of range, must be 0 ... %d\n"),
00200                index + 1, max_copper_layer + SILK_LAYER);
00201       return 1;
00202     }
00203 
00204   if (isdigit (argv[1][0]))
00205     type = atoi (argv[1]);
00206   else
00207     type = string_to_layertype (argv[1], NULL);
00208 
00209   if (type < 0 || type >= LT_NUM_LAYERTYPES)
00210     {
00211       Message (N_("Invalid layer type (%d) requested. "
00212                   "See ListLayertypes() for a list.\n"), type);
00213       return 1;
00214     }
00215 
00216   PCB->Data->Layer[index].Type = type;
00217 
00218   return 0;
00219 }
00220 
00221 HID_Action layerflags_action_list[] = {
00222   {"ListLayertypes", 0, ActionListLayertypes,
00223    listlayertypes_help, listlayertypes_syntax}
00224   ,
00225   {"SetLayertype", 0, ActionSetLayertype,
00226    setlayertype_help, setlayertype_syntax}
00227 };
00228 
00229 REGISTER_ACTIONS (layerflags_action_list)