hid/gtk (GL): I think the polygon renderer works in mask mode now
[geda-pcb/pcjc2.git] / src / hid / batch / batch.c
blob72c49e06c7813b10cf31f5105f6b50b8512d04ea
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
5 #include <stdio.h>
6 #include <stdarg.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
11 #include "global.h"
12 #include "hid.h"
13 #include "data.h"
14 #include "misc.h"
15 #include "hid.h"
16 #include "hid_draw.h"
17 #include "../hidint.h"
18 #include "pcb-printf.h"
20 #include "hid/common/draw_helpers.h"
21 #include "hid/common/hidnogui.h"
22 #include "hid/common/actions.h"
23 #include "hid/common/hidinit.h"
25 #ifdef HAVE_LIBDMALLOC
26 #include <dmalloc.h>
27 #endif
29 /* This is a text-line "batch" HID, which exists for scripting and
30 non-GUI needs. */
33 static HID_Attribute *
34 batch_get_export_options (int *n_ret)
36 return 0;
39 /* ----------------------------------------------------------------------------- */
41 static char *prompt = "pcb";
43 static int
44 nop (int argc, char **argv, Coord x, Coord y)
46 return 0;
49 static int
50 PCBChanged (int argc, char **argv, Coord x, Coord y)
52 if (PCB && PCB->Filename)
54 prompt = strrchr(PCB->Filename, '/');
55 if (prompt)
56 prompt ++;
57 else
58 prompt = PCB->Filename;
60 else
61 prompt = "no-board";
62 return 0;
65 static int
66 help (int argc, char **argv, Coord x, Coord y)
68 print_actions ();
69 return 0;
72 static int
73 info (int argc, char **argv, Coord x, Coord y)
75 int i, j;
76 int top_group, bottom_group;
77 if (!PCB || !PCB->Data || !PCB->Filename)
79 printf("No PCB loaded.\n");
80 return 0;
82 printf("Filename: %s\n", PCB->Filename);
83 pcb_printf("Size: %ml x %ml mils, %mm x %mm mm\n",
84 PCB->MaxWidth, PCB->MaxHeight,
85 PCB->MaxWidth, PCB->MaxHeight);
86 top_group = GetLayerGroupNumberBySide (TOP_SIDE);
87 bottom_group = GetLayerGroupNumberBySide (BOTTOM_SIDE);
88 for (i=0; i<MAX_LAYER; i++)
91 int lg = GetLayerGroupNumberByNumber (i);
92 for (j = 0; j < MAX_GROUP; j++)
93 putchar(j==lg ? '#' : '-');
94 printf(" %c %s\n", lg == top_group ? 'c' : lg == bottom_group ? 's' : '-',
95 PCB->Data->Layer[i].Name);
97 return 0;
101 HID_Action batch_action_list[] = {
102 {"PCBChanged", 0, PCBChanged },
103 {"RouteStylesChanged", 0, nop },
104 {"NetlistChanged", 0, nop },
105 {"LayersChanged", 0, nop },
106 {"LibraryChanged", 0, nop },
107 {"Busy", 0, nop },
108 {"Help", 0, help },
109 {"Info", 0, info }
112 REGISTER_ACTIONS (batch_action_list)
115 /* ----------------------------------------------------------------------------- */
117 static void
118 batch_do_export (HID_Attr_Val * options)
120 int interactive;
121 char line[1000];
123 if (isatty (0))
124 interactive = 1;
125 else
126 interactive = 0;
128 if (interactive)
130 printf("Entering %s version %s batch mode.\n", PACKAGE, VERSION);
131 printf("See http://pcb.geda-project.org for project information\n");
133 while (1)
135 if (interactive)
137 printf("%s> ", prompt);
138 fflush(stdout);
140 if (fgets(line, sizeof(line)-1, stdin) == NULL)
141 return;
142 hid_parse_command (line);
146 static void
147 batch_parse_arguments (int *argc, char ***argv)
149 hid_parse_command_line (argc, argv);
152 static void
153 batch_invalidate_lr (int l, int r, int t, int b)
157 static void
158 batch_invalidate_all (void)
162 static int
163 batch_set_layer (const char *name, int idx, int empty)
165 return 0;
168 static hidGC
169 batch_make_gc (void)
171 return 0;
174 static void
175 batch_destroy_gc (hidGC gc)
179 static void
180 batch_use_mask (enum mask_mode mode)
184 static void
185 batch_set_color (hidGC gc, const char *name)
189 static void
190 batch_set_line_cap (hidGC gc, EndCapStyle style)
194 static void
195 batch_set_line_width (hidGC gc, Coord width)
199 static void
200 batch_set_draw_xor (hidGC gc, int xor_set)
204 static void
205 batch_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
209 static void
210 batch_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height,
211 Angle start_angle, Angle end_angle)
215 static void
216 batch_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
220 static void
221 batch_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
225 static void
226 batch_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
230 static void
231 batch_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
235 static void
236 batch_calibrate (double xval, double yval)
240 static int
241 batch_shift_is_pressed (void)
243 return 0;
246 static int
247 batch_control_is_pressed (void)
249 return 0;
252 static int
253 batch_mod1_is_pressed (void)
255 return 0;
258 static void
259 batch_get_coords (const char *msg, Coord *x, Coord *y)
263 static void
264 batch_set_crosshair (int x, int y, int action)
268 static hidval
269 batch_add_timer (void (*func) (hidval user_data),
270 unsigned long milliseconds, hidval user_data)
272 hidval rv;
273 rv.lval = 0;
274 return rv;
277 static void
278 batch_stop_timer (hidval timer)
282 hidval
283 batch_watch_file (int fd, unsigned int condition, void (*func) (hidval watch, int fd, unsigned int condition, hidval user_data),
284 hidval user_data)
286 hidval ret;
287 ret.ptr = NULL;
288 return ret;
291 void
292 batch_unwatch_file (hidval data)
296 static hidval
297 batch_add_block_hook (void (*func) (hidval data), hidval user_data )
299 hidval ret;
300 ret.ptr = NULL;
301 return ret;
304 static void
305 batch_stop_block_hook (hidval mlpoll)
309 static int
310 batch_attribute_dialog (HID_Attribute * attrs_,
311 int n_attrs_, HID_Attr_Val * results_,
312 const char *title_, const char *descr_)
314 return 0;
317 static void
318 batch_show_item (void *item)
322 #include "dolists.h"
324 static HID batch_hid;
325 static HID_DRAW batch_graphics;
326 static HID_DRAW_CLASS batch_graphics_class;
328 void
329 hid_batch_init ()
331 memset (&batch_hid, 0, sizeof (HID));
332 memset (&batch_graphics, 0, sizeof (HID_DRAW));
333 memset (&batch_graphics_class, 0, sizeof (HID_DRAW_CLASS));
335 common_nogui_init (&batch_hid);
337 batch_hid.struct_size = sizeof (HID);
338 batch_hid.name = "batch";
339 batch_hid.description = "Batch-mode GUI for non-interactive use.";
340 batch_hid.gui = 1;
342 batch_hid.get_export_options = batch_get_export_options;
343 batch_hid.do_export = batch_do_export;
344 batch_hid.parse_arguments = batch_parse_arguments;
345 batch_hid.invalidate_lr = batch_invalidate_lr;
346 batch_hid.invalidate_all = batch_invalidate_all;
347 batch_hid.calibrate = batch_calibrate;
348 batch_hid.shift_is_pressed = batch_shift_is_pressed;
349 batch_hid.control_is_pressed = batch_control_is_pressed;
350 batch_hid.mod1_is_pressed = batch_mod1_is_pressed;
351 batch_hid.get_coords = batch_get_coords;
352 batch_hid.set_crosshair = batch_set_crosshair;
353 batch_hid.add_timer = batch_add_timer;
354 batch_hid.stop_timer = batch_stop_timer;
355 batch_hid.watch_file = batch_watch_file;
356 batch_hid.unwatch_file = batch_unwatch_file;
357 batch_hid.add_block_hook = batch_add_block_hook;
358 batch_hid.stop_block_hook = batch_stop_block_hook;
359 batch_hid.attribute_dialog = batch_attribute_dialog;
360 batch_hid.show_item = batch_show_item;
362 common_nogui_graphics_class_init (&batch_graphics_class);
363 common_draw_helpers_class_init (&batch_graphics_class);
365 batch_graphics_class.set_layer = batch_set_layer;
366 batch_graphics_class.make_gc = batch_make_gc;
367 batch_graphics_class.destroy_gc = batch_destroy_gc;
368 batch_graphics_class.use_mask = batch_use_mask;
369 batch_graphics_class.set_color = batch_set_color;
370 batch_graphics_class.set_line_cap = batch_set_line_cap;
371 batch_graphics_class.set_line_width = batch_set_line_width;
372 batch_graphics_class.set_draw_xor = batch_set_draw_xor;
373 batch_graphics_class.draw_line = batch_draw_line;
374 batch_graphics_class.draw_arc = batch_draw_arc;
375 batch_graphics_class.draw_rect = batch_draw_rect;
376 batch_graphics_class.fill_circle = batch_fill_circle;
377 batch_graphics_class.fill_polygon = batch_fill_polygon;
378 batch_graphics_class.fill_rect = batch_fill_rect;
380 batch_graphics.klass = &batch_graphics_class;
381 common_nogui_graphics_init (&batch_graphics);
382 common_draw_helpers_init (&batch_graphics);
384 hid_register_hid (&batch_hid);
385 #include "batch_lists.h"