pcb 4.1.1
An interactive printed circuit board layout editor.

batch.c

Go to the documentation of this file.
00001 
00036 #ifdef HAVE_CONFIG_H
00037 #include "config.h"
00038 #endif
00039 
00040 #include <stdio.h>
00041 #include <stdarg.h>
00042 #include <stdlib.h>
00043 #include <string.h>
00044 #include <unistd.h>
00045 
00046 #include "global.h"
00047 #include "crosshair.h"
00048 #include "hid.h"
00049 #include "data.h"
00050 #include "misc.h"
00051 #include "hid.h"
00052 #include "hid_draw.h"
00053 #include "../hidint.h"
00054 #include "pcb-printf.h"
00055 
00056 #include "hid/common/draw_helpers.h"
00057 #include "hid/common/hidnogui.h"
00058 #include "hid/common/actions.h"
00059 #include "hid/common/hidinit.h"
00060 
00061 #ifdef HAVE_LIBDMALLOC
00062 #include <dmalloc.h>
00063 #endif
00064 
00065 typedef struct hid_gc_struct
00066 {
00067   int nothing_interesting_here;
00068 } hid_gc_struct;
00069 
00070 static HID_Attribute *
00071 batch_get_export_options (int *n_ret)
00072 {
00073   return 0;
00074 }
00075 
00076 /* ----------------------------------------------------------------------------- */
00077 
00078 static char *prompt = "pcb";
00079 
00080 static int
00081 nop (int argc, char **argv, Coord x, Coord y)
00082 {
00083   return 0;
00084 }
00085 
00086 static int
00087 PCBChanged (int argc, char **argv, Coord x, Coord y)
00088 {
00089   if (PCB && PCB->Filename)
00090     {
00091       prompt = strrchr(PCB->Filename, '/');
00092       if (prompt)
00093         prompt ++;
00094       else
00095         prompt = PCB->Filename;
00096     }
00097   else
00098     prompt = "no-board";
00099   crosshair_update_range();
00100   return 0;
00101 }
00102 
00103 static int
00104 help (int argc, char **argv, Coord x, Coord y)
00105 {
00106   print_actions ();
00107   return 0;
00108 }
00109 
00110 static int
00111 info (int argc, char **argv, Coord x, Coord y)
00112 {
00113   int i, j;
00114   int top_group, bottom_group;
00115   if (!PCB || !PCB->Data || !PCB->Filename)
00116     {
00117       printf("No PCB loaded.\n");
00118       return 0;
00119     }
00120   printf("Filename: %s\n", PCB->Filename);
00121   pcb_printf("Size: %ml x %ml mils, %mm x %mm mm\n",
00122          PCB->MaxWidth, PCB->MaxHeight,
00123          PCB->MaxWidth, PCB->MaxHeight);
00124   top_group = GetLayerGroupNumberBySide (TOP_SIDE);
00125   bottom_group = GetLayerGroupNumberBySide (BOTTOM_SIDE);
00126   for (i=0; i<MAX_LAYER; i++)
00127     {
00128       
00129       int lg = GetLayerGroupNumberByNumber (i);
00130       for (j = 0; j < MAX_GROUP; j++)
00131         putchar(j==lg ? '#' : '-');
00132       printf(" %c %s\n", lg == top_group ? 'c' : lg == bottom_group ? 's' : '-',
00133              PCB->Data->Layer[i].Name);
00134     }
00135   return 0;
00136 }
00137 
00138 
00139 HID_Action batch_action_list[] = {
00140   {"PCBChanged", 0, PCBChanged },
00141   {"RouteStylesChanged", 0, nop },
00142   {"NetlistChanged", 0, nop },
00143   {"LayersChanged", 0, nop },
00144   {"LibraryChanged", 0, nop },
00145   {"Busy", 0, nop },
00146   {"Help", 0, help },
00147   {"Info", 0, info }
00148 };
00149 
00150 REGISTER_ACTIONS (batch_action_list)
00151 
00152 
00153 /* ----------------------------------------------------------------------------- */
00154 
00155 static void
00156 batch_do_export (HID_Attr_Val * options)
00157 {
00158   int interactive;
00159   char line[1000];
00160 
00161   if (isatty (0))
00162     interactive = 1;
00163   else
00164     interactive = 0;
00165 
00166   if (interactive)
00167     {
00168       printf("Entering %s version %s batch mode.\n", PACKAGE, VERSION);
00169       printf("See http://pcb.geda-project.org for project information\n");
00170     }
00171   while (1)
00172     {
00173       if (interactive)
00174         {
00175           printf("%s> ", prompt);
00176           fflush(stdout);
00177         }
00178       if (fgets(line, sizeof(line)-1, stdin) == NULL)
00179         return;
00180       hid_parse_command (line);
00181     }
00182 }
00183 
00184 static void
00185 batch_parse_arguments (int *argc, char ***argv)
00186 {
00187   hid_parse_command_line (argc, argv);
00188 }
00189 
00190 static void
00191 batch_invalidate_lr (Coord l, Coord r, Coord t, Coord b)
00192 {
00193 }
00194 
00195 static void
00196 batch_invalidate_all (void)
00197 {
00198 }
00199 
00200 static int
00201 batch_set_layer (const char *name, int idx, int empty)
00202 {
00203   return 0;
00204 }
00205 
00206 static hidGC
00207 batch_make_gc (void)
00208 {
00209   return 0;
00210 }
00211 
00212 static void
00213 batch_destroy_gc (hidGC gc)
00214 {
00215 }
00216 
00217 static void
00218 batch_use_mask (enum mask_mode mode)
00219 {
00220 }
00221 
00222 static void
00223 batch_set_color (hidGC gc, const char *name)
00224 {
00225 }
00226 
00227 static void
00228 batch_set_line_cap (hidGC gc, EndCapStyle style)
00229 {
00230 }
00231 
00232 static void
00233 batch_set_line_width (hidGC gc, Coord width)
00234 {
00235 }
00236 
00237 static void
00238 batch_set_draw_xor (hidGC gc, int xor_set)
00239 {
00240 }
00241 
00242 static void
00243 batch_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
00244 {
00245 }
00246 
00247 static void
00248 batch_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height,
00249                 Angle start_angle, Angle end_angle)
00250 {
00251 }
00252 
00253 static void
00254 batch_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
00255 {
00256 }
00257 
00258 static void
00259 batch_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
00260 {
00261 }
00262 
00263 static void
00264 batch_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
00265 {
00266 }
00267 
00268 static void
00269 batch_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
00270 {
00271 }
00272 
00273 static void
00274 batch_calibrate (double xval, double yval)
00275 {
00276 }
00277 
00278 static int
00279 batch_shift_is_pressed (void)
00280 {
00281   return 0;
00282 }
00283 
00284 static int
00285 batch_control_is_pressed (void)
00286 {
00287   return 0;
00288 }
00289 
00290 static int
00291 batch_mod1_is_pressed (void)
00292 {
00293   return 0;
00294 }
00295 
00296 static void
00297 batch_get_coords (const char *msg, Coord *x, Coord *y)
00298 {
00299 }
00300 
00301 static void
00302 batch_set_crosshair (int x, int y, int action)
00303 {
00304 }
00305 
00306 static hidval
00307 batch_add_timer (void (*func) (hidval user_data),
00308                  unsigned long milliseconds, hidval user_data)
00309 {
00310   hidval rv;
00311   rv.lval = 0;
00312   return rv;
00313 }
00314 
00315 static void
00316 batch_stop_timer (hidval timer)
00317 {
00318 }
00319 
00320 hidval
00321 batch_watch_file (int fd, unsigned int condition, void (*func) (hidval watch, int fd, unsigned int condition, hidval user_data),
00322     hidval user_data)
00323 {
00324   hidval ret;
00325   ret.ptr = NULL;
00326   return ret;
00327 }
00328 
00329 void
00330 batch_unwatch_file (hidval data)
00331 {
00332 }
00333 
00334 static hidval
00335 batch_add_block_hook (void (*func) (hidval data), hidval user_data )
00336 {
00337   hidval ret;
00338   ret.ptr = NULL;
00339   return ret;
00340 }
00341 
00342 static void
00343 batch_stop_block_hook (hidval mlpoll)
00344 {
00345 }
00346 
00347 static int
00348 batch_attribute_dialog (HID_Attribute * attrs_,
00349                         int n_attrs_, HID_Attr_Val * results_,
00350                         const char *title_, const char *descr_)
00351 {
00352   return 0;
00353 }
00354 
00355 static void
00356 batch_show_item (void *item)
00357 {
00358 }
00359 
00360 #include "dolists.h"
00361 
00362 static HID batch_hid;
00363 static HID_DRAW batch_graphics;
00364 
00365 void
00366 hid_batch_init ()
00367 {
00368   memset (&batch_hid, 0, sizeof (HID));
00369   memset (&batch_graphics, 0, sizeof (HID_DRAW));
00370 
00371   common_nogui_init (&batch_hid);
00372   common_draw_helpers_init (&batch_graphics);
00373 
00374   batch_hid.struct_size           = sizeof (HID);
00375   batch_hid.name                  = "batch";
00376   batch_hid.description           = "Batch-mode GUI for non-interactive use.";
00377   batch_hid.gui                   = 1;
00378 
00379   batch_hid.get_export_options    = batch_get_export_options;
00380   batch_hid.do_export             = batch_do_export;
00381   batch_hid.parse_arguments       = batch_parse_arguments;
00382   batch_hid.invalidate_lr         = batch_invalidate_lr;
00383   batch_hid.invalidate_all        = batch_invalidate_all;
00384   batch_hid.set_layer             = batch_set_layer;
00385   batch_hid.calibrate             = batch_calibrate;
00386   batch_hid.shift_is_pressed      = batch_shift_is_pressed;
00387   batch_hid.control_is_pressed    = batch_control_is_pressed;
00388   batch_hid.mod1_is_pressed       = batch_mod1_is_pressed;
00389   batch_hid.get_coords            = batch_get_coords;
00390   batch_hid.set_crosshair         = batch_set_crosshair;
00391   batch_hid.add_timer             = batch_add_timer;
00392   batch_hid.stop_timer            = batch_stop_timer;
00393   batch_hid.watch_file            = batch_watch_file;
00394   batch_hid.unwatch_file          = batch_unwatch_file;
00395   batch_hid.add_block_hook        = batch_add_block_hook;
00396   batch_hid.stop_block_hook       = batch_stop_block_hook;
00397   batch_hid.attribute_dialog      = batch_attribute_dialog;
00398   batch_hid.show_item             = batch_show_item;
00399 
00400   batch_hid.graphics              = &batch_graphics;
00401 
00402   batch_graphics.make_gc          = batch_make_gc;
00403   batch_graphics.destroy_gc       = batch_destroy_gc;
00404   batch_graphics.use_mask         = batch_use_mask;
00405   batch_graphics.set_color        = batch_set_color;
00406   batch_graphics.set_line_cap     = batch_set_line_cap;
00407   batch_graphics.set_line_width   = batch_set_line_width;
00408   batch_graphics.set_draw_xor     = batch_set_draw_xor;
00409   batch_graphics.draw_line        = batch_draw_line;
00410   batch_graphics.draw_arc         = batch_draw_arc;
00411   batch_graphics.draw_rect        = batch_draw_rect;
00412   batch_graphics.fill_circle      = batch_fill_circle;
00413   batch_graphics.fill_polygon     = batch_fill_polygon;
00414   batch_graphics.fill_rect        = batch_fill_rect;
00415 
00416   hid_register_hid (&batch_hid);
00417 #include "batch_lists.h"
00418 }