6 /* Human Interface Device */
10 The way the HID layer works is that you instantiate a HID device
11 structure, and invoke functions through its members. Code in the
12 common part of PCB may *not* rely on *anything* other than what's
13 defined in this file. Code in the HID layers *may* rely on data and
14 functions in the common code (like, board size and such) but it's
15 considered bad form to do so when not needed.
17 Coordinates are ALWAYS in pcb's default resolution (1/100 mil at the
18 moment). Positive X is right, positive Y is down. Angles are
19 degrees, with 0 being right (positive X) and 90 being up (negative Y).
20 All zoom, scaling, panning, and conversions are hidden inside the HID
23 The main structure is at the end of this file.
25 Data structures passed to the HIDs will be copied if the HID needs to
26 save them. Data structures retured from the HIDs must not be freed,
27 and may be changed by the HID in response to new information.
31 #if defined(__cplusplus) && __cplusplus
36 /* Like end cap styles. The cap *always* extends beyond the
37 coordinates given, by half the width of the line. Beveled ends can
38 used to make octagonal pads by giving the same x,y coordinate
42 Trace_Cap
, /* This means we're drawing a trace, which has round caps. */
43 Square_Cap
, /* Square pins or pads. */
44 Round_Cap
, /* Round pins or round-ended pads, thermals. */
45 Beveled_Cap
/* Octagon pins or bevel-cornered pads. */
48 /* The HID may need something more than an "int" for colors, timers,
49 etc. So it passes/returns one of these, which is castable to a
57 /* This graphics context is an semi-opaque pointer defined by the HID.
58 GCs are HID-specific; attempts to use one HID's GC for a different
59 HID will result in a fatal error. Certain elements are defined in
60 hid_draw.h are visible for use in draw.c, but the full structure
61 size may not be determined from that definition. */
62 typedef struct hid_gc_struct
*hidGC
;
64 #define HIDCONCAT(a,b) a##b
66 /* This is used to register the action callbacks (for menus and
67 whatnot). HID assumes the following actions are available for its
74 /* This is matched against action names in the GUI configuration */
76 /* If this string is non-NULL, the action needs to know the X,Y
77 coordinates to act on, and this string may be used to prompt
78 the user to select a coordinate. If NULL, the coordinates may
79 be 0,0 if none are known. */
80 const char *need_coord_msg
;
81 /* Called when the action is triggered. If this function returns
82 non-zero, no further actions will be invoked for this key/mouse
84 int (*trigger_cb
) (int argc
, char **argv
, Coord x
, Coord y
);
85 /* Short description that sometimes accompanies the name. */
86 const char *description
;
87 /* Full allowed syntax; use \n to separate lines. */
91 extern void hid_register_action (HID_Action
*);
93 extern void hid_register_actions (HID_Action
*, int);
94 #define REGISTER_ACTIONS(a) HIDCONCAT(void register_,a) ()\
95 { hid_register_actions(a, sizeof(a)/sizeof(a[0])); }
97 /* Note that PCB expects the gui to provide the following actions:
101 NetlistChanged() (but core should call "void NetlistChanged(int);" in netlist.c)
107 extern const char pcbchanged_help
[];
108 extern const char pcbchanged_syntax
[];
109 extern const char routestyleschanged_help
[];
110 extern const char routestyleschanged_syntax
[];
111 extern const char netlistchanged_help
[];
112 extern const char netlistchanged_syntax
[];
113 extern const char layerschanged_help
[];
114 extern const char layerschanged_syntax
[];
115 extern const char librarychanged_help
[];
116 extern const char librarychanged_syntax
[];
118 int hid_action (const char *action_
);
119 int hid_actionl (const char *action_
, ...); /* NULL terminated */
120 int hid_actionv (const char *action_
, int argc_
, char **argv_
);
121 void hid_save_settings (int);
122 void hid_load_settings (void);
124 /* Parse the given command string into action calls, and call
125 hid_actionv for each action found. Accepts both "action(arg1,
126 arg2)" and command-style "action arg1 arg2", allowing only one
127 action in the later case. Returns nonzero if the action handler(s)
129 int hid_parse_command (const char *str_
);
131 /* Parse the given string into action calls, and call
132 hid_actionv for each action found. Accepts only
133 "action(arg1, arg2)" */
134 int hid_parse_actions (const char *str_
);
138 /* Name of the flag */
140 /* Function to call to get the value of the flag. */
141 int (*function
) (void *);
142 /* Additional parameter to pass to that function. */
146 extern void hid_register_flags (HID_Flag
*, int);
147 #define REGISTER_FLAGS(a) HIDCONCAT(void register_,a) ()\
148 { hid_register_flags(a, sizeof(a)/sizeof(a[0])); }
150 /* Looks up one of the flags registered above. If the flag is
151 unknown, returns zero. */
152 int hid_get_flag (const char *name_
);
154 /* Used for HID attributes (exporting and printing, mostly).
155 HA_boolean uses int_value, HA_enum sets int_value to the index and
156 str_value to the enumeration string. HID_Label just shows the
157 default str_value. HID_Mixed is a real_value followed by an enum,
158 like 0.5in or 100mm. */
162 const char *str_value
;
168 { HID_Label
, HID_Integer
, HID_Real
, HID_String
,
169 HID_Boolean
, HID_Enum
, HID_Mixed
, HID_Path
,
176 /* If the help_text is this, usage() won't show this option */
177 #define ATTR_UNDOCUMENTED ((char *)(1))
180 int min_val
, max_val
; /* for integer and real */
181 HID_Attr_Val default_val
; /* Also actual value for global attributes. */
182 const char **enumerations
;
183 /* If set, this is used for global attributes (i.e. those set
184 statically with REGISTER_ATTRIBUTES below) instead of changing
185 the default_val. Note that a HID_Mixed attribute must specify a
186 pointer to HID_Attr_Val here, and HID_Boolean assumes this is
187 "char *" so the value should be initialized to zero, and may be
188 set to non-zero (not always one). */
190 int hash
; /* for detecting changes. */
193 extern void hid_register_attributes (HID_Attribute
*, int);
194 #define REGISTER_ATTRIBUTES(a) HIDCONCAT(void register_,a) ()\
195 { hid_register_attributes(a, sizeof(a)/sizeof(a[0])); }
197 /* These three are set by hid_parse_command_line(). */
198 extern char *program_name
;
199 extern char *program_directory
;
200 extern char *program_basename
;
202 #define SL_0_SIDE 0x0000
203 #define SL_TOP_SIDE 0x0001
204 #define SL_BOTTOM_SIDE 0x0002
205 #define SL_SILK 0x0010
206 #define SL_MASK 0x0020
207 #define SL_PDRILL 0x0030
208 #define SL_UDRILL 0x0040
209 #define SL_PASTE 0x0050
210 #define SL_INVISIBLE 0x0060
211 #define SL_FAB 0x0070
212 #define SL_ASSY 0x0080
213 #define SL_RATS 0x0090
214 /* Callers should use this. */
215 #define SL(type,side) (~0xfff | SL_##type | SL_##side##_SIDE)
217 /* File Watch flags */
218 /* Based upon those in dbus/dbus-connection.h */
221 PCB_WATCH_READABLE
= 1 << 0, /**< As in POLLIN */
222 PCB_WATCH_WRITABLE
= 1 << 1, /**< As in POLLOUT */
223 PCB_WATCH_ERROR
= 1 << 2, /**< As in POLLERR */
224 PCB_WATCH_HANGUP
= 1 << 3 /**< As in POLLHUP */
230 int log_drc_overview
;
231 int log_drc_violations
;
232 void (*reset_drc_dialog_message
) (void);
233 void (*append_drc_violation
) (DrcViolationType
*violation
);
234 int (*throw_drc_dialog
) (void);
237 typedef struct hid_st HID
;
238 typedef struct hid_draw_st HID_DRAW
;
240 /* This is the main HID structure. */
243 /* The size of this structure. We use this as a compatibility
244 check; a HID built with a different hid.h than we're expecting
245 should have a different size here. */
248 /* The name of this HID. This should be suitable for
249 command line options, multi-selection menus, file names,
253 /* Likewise, but allowed to be longer and more descriptive. */
254 const char *description
;
256 /* If set, this is the GUI HID. Exactly one of these three flags
257 must be set; setting "gui" lets the expose callback optimize and
258 coordinate itself. */
261 /* If set, this is the printer-class HID. The common part of PCB
262 may use this to do command-line printing, without having
263 instantiated any GUI HIDs. Only one printer HID is normally
264 defined at a time. */
267 /* If set, this HID provides an export option, and should be used as
268 part of the File->Export menu option. Examples are PNG, Gerber,
269 and EPS exporters. */
272 /* Returns a set of resources describing options the export or print
273 HID supports. In GUI mode, the print/export dialogs use this to
274 set up the selectable options. In command line mode, these are
275 used to interpret command line options. If n_ret is non-NULL,
276 the number of attributes is stored there. */
277 HID_Attribute
*(*get_export_options
) (int *n_ret_
);
279 /* Export (or print) the current PCB. The options given represent
280 the choices made from the options returned from
281 get_export_options. Call with options == NULL to start the
282 primary GUI (create a main window, print, export, etc) */
283 void (*do_export
) (HID_Attr_Val
* options_
);
285 /* Parse the command line. Call this early for whatever HID will be
286 the primary HID, as it will set all the registered attributes.
287 The HID should remove all arguments, leaving any possible file
289 void (*parse_arguments
) (int *argc_
, char ***argv_
);
291 /* This may be called to ask the GUI to force a redraw of a given area */
292 void (*invalidate_lr
) (int left_
, int right_
, int top_
, int bottom_
);
293 void (*invalidate_all
) (void);
294 void (*notify_crosshair_change
) (bool changes_complete
);
295 void (*notify_mark_change
) (bool changes_complete
);
297 /* This is for the printer. If you call this for the GUI, xval and
298 yval are ignored, and a dialog pops up to lead you through the
299 calibration procedure. For the printer, if xval and yval are
300 zero, a calibration page is printed with instructions for
301 calibrating your printer. After calibrating, nonzero xval and
302 yval are passed according to the instructions. Metric is nonzero
303 if the user prefers metric units, else inches are used. */
304 void (*calibrate
) (double xval_
, double yval_
);
307 /* GUI layout functions. Not used or defined for print/export
311 int (*shift_is_pressed
) (void);
312 int (*control_is_pressed
) (void);
313 int (*mod1_is_pressed
) (void);
314 void (*get_coords
) (const char *msg_
, Coord
*x_
, Coord
*y_
);
316 /* Sets the crosshair, which may differ from the pointer depending
317 on grid and pad snap. Note that the HID is responsible for
318 hiding, showing, redrawing, etc. The core just tells it what
319 coordinates it's actually using. Note that this routine may
320 need to know what "pcb units" are so it can display them in mm
321 or mils accordingly. If cursor_action is set, the cursor or
322 screen may be adjusted so that the cursor and the crosshair are
323 at the same point on the screen. */
324 void (*set_crosshair
) (int x_
, int y_
, int cursor_action_
);
325 #define HID_SC_DO_NOTHING 0
326 #define HID_SC_WARP_POINTER 1
327 #define HID_SC_PAN_VIEWPORT 2
329 /* Causes func to be called at some point in the future. Timers are
330 only good for *one* call; if you want it to repeat, add another
331 timer during the callback for the first. user_data can be
332 anything, it's just passed to func. Times are not guaranteed to
334 hidval (*add_timer
) (void (*func
) (hidval user_data_
),
335 unsigned long milliseconds_
, hidval user_data_
);
336 /* Use this to stop a timer that hasn't triggered yet. */
337 void (*stop_timer
) (hidval timer_
);
339 /* Causes func to be called when some condition occurs on the file
340 descriptor passed. Conditions include data for reading, writing,
341 hangup, and errors. user_data can be anything, it's just passed
343 hidval (*watch_file
) (int fd_
, unsigned int condition_
, void (*func_
) (hidval watch_
, int fd_
, unsigned int condition_
, hidval user_data_
),
345 /* Use this to stop a file watch. */
346 void (*unwatch_file
) (hidval watch_
);
348 /* Causes func to be called in the mainloop prior to blocking */
349 hidval (*add_block_hook
) (void (*func_
) (hidval data_
), hidval data_
);
350 /* Use this to stop a mainloop block hook. */
351 void (*stop_block_hook
) (hidval block_hook_
);
353 /* Various dialogs */
355 /* Log a message to the log window. */
356 void (*log
) (const char *fmt_
, ...);
357 void (*logv
) (const char *fmt_
, va_list args_
);
359 /* A generic yes/no dialog. Returns zero if the cancel button is
360 pressed, one for the ok button. If you specify alternate labels
361 for ..., they are used instead of the default OK/Cancel ones, and
362 the return value is the index of the label chosen. You MUST pass
363 NULL as the last parameter to this. */
364 int (*confirm_dialog
) (char *msg_
, ...);
366 /* A close confirmation dialog for unsaved pages, for example, with
367 options "Close without saving", "Cancel" and "Save". Returns zero
368 if the close is cancelled, or one if it should proceed. The HID
369 is responsible for any "Save" action the user may wish before
370 confirming the close.
372 int (*close_confirm_dialog
) ();
373 #define HID_CLOSE_CONFIRM_CANCEL 0
374 #define HID_CLOSE_CONFIRM_OK 1
376 /* Just prints text. */
377 void (*report_dialog
) (char *title_
, char *msg_
);
379 /* Prompts the user to enter a string, returns the string. If
380 default_string isn't NULL, the form is pre-filled with this
381 value. "msg" is like "Enter value:". */
382 char *(*prompt_for
) (const char *msg_
, const char *default_string_
);
384 /* Prompts the user for a filename or directory name. For GUI
385 HID's this would mean a file select dialog box. The 'flags'
386 argument is the bitwise OR of the following values. */
387 #define HID_FILESELECT_READ 0x01
389 /* The function calling hid->fileselect will deal with the case
390 where the selected file already exists. If not given, then the
391 gui will prompt with an "overwrite?" prompt. Only used when
394 #define HID_FILESELECT_MAY_NOT_EXIST 0x02
396 /* The call is supposed to return a file template (for gerber
397 output for example) instead of an actual file. Only used when
400 #define HID_FILESELECT_IS_TEMPLATE 0x04
402 /* title may be used as a dialog box title. Ignored if NULL.
404 * descr is a longer help string. Ignored if NULL.
406 * default_file is the default file name. Ignored if NULL.
408 * default_ext is the default file extension, like ".pdf".
411 * history_tag may be used by the GUI to keep track of file
412 * history. Examples would be "board", "vendor", "renumber",
413 * etc. If NULL, no specific history is kept.
415 * flags are the bitwise or of the HID_FILESELECT defines above
418 char *(*fileselect
) (const char *title_
, const char *descr_
,
419 char *default_file_
, char *default_ext_
,
420 const char *history_tag_
, int flags_
);
422 /* A generic dialog to ask for a set of attributes. If n_attrs is
423 zero, attrs(.name) must be NULL terminated. Returns non-zero if
424 an error occurred (usually, this means the user cancelled the
425 dialog or something). title is the title of the dialog box
426 descr (if not NULL) can be a longer description of what the
427 attributes are used for. The HID may choose to ignore it or it
428 may use it for a tooltip or text in a dialog box, or a help
431 int (*attribute_dialog
) (HID_Attribute
* attrs_
,
432 int n_attrs_
, HID_Attr_Val
* results_
,
433 const char * title_
, const char * descr_
);
435 /* This causes a second window to display, which only shows the
436 selected item. The expose callback is called twice; once to size
437 the extents of the item, and once to draw it. To pass magic
438 values, pass the address of a variable created for this
440 void (*show_item
) (void *item_
);
442 /* Something to alert the user. */
445 /* Used by optimizers and autorouter to show progress to the user.
446 Pass all zeros to flush display and remove any dialogs.
447 Returns nonzero if the user wishes to cancel the operation. */
448 int (*progress
) (int so_far_
, int total_
, const char *message_
);
450 HID_DRC_GUI
*drc_gui
;
452 void (*edit_attributes
) (char *owner
, AttributeListType
*attrlist_
);
454 /* Debug drawing support. These APIs must be implemented (non NULL),
455 * but they do not have to be functional. request_debug_draw can
456 * return NULL to indicate debug drawing is not permitted.
458 * Debug drawing is not gauranteed to be re-entrant.
459 * The caller must not nest requests for debug drawing.
462 /* Request permission for debug drawing
464 * Returns a HID_DRAW pointer which should be used rather than the global
465 * gui->graphics-> for making drawing calls. If the return value is NULL,
466 * then permission has been denied, and the drawing must not continue.
468 HID_DRAW
*(*request_debug_draw
) (void);
470 /* Flush pending drawing to the screen
472 * May be implemented as a NOOP if the GUI has chosen to send the
473 * debug drawing directly to the screen.
475 void (*flush_debug_draw
) (void);
477 /* When finished, the user must inform the GUI to clean up resources
479 * Any remaining rendering will be flushed to the screen.
481 void (*finish_debug_draw
) (void);
483 /* Notification to the GUI around saving the PCB file.
485 * Called with a false parameter before the save, called again
486 * with true after the save.
488 * Allows GUIs which watch for file-changes on disk to ignore
489 * our deliberate changes.
491 void (*notify_save_pcb
) (const char *filename
, bool done
);
493 /* Notification to the GUI that the PCB file has been renamed. */
494 void (*notify_filename_changed
) (void);
497 /* Call this as soon as possible from main(). No other HID calls are
498 valid until this is called. */
499 void hid_init (void);
501 /* When PCB runs in interactive mode, this is called to instantiate
502 one GUI HID which happens to be the GUI. This HID is the one that
503 interacts with the mouse and keyboard. */
504 HID
*hid_find_gui ();
506 /* Finds the one printer HID and instantiates it. */
507 HID
*hid_find_printer (void);
509 /* Finds the indicated exporter HID and instantiates it. */
510 HID
*hid_find_exporter (const char *);
512 /* This returns a NULL-terminated array of available HIDs. The only
513 real reason to use this is to locate all the export-style HIDs. */
514 HID
**hid_enumerate (void);
516 /* This function (in the common code) will be called whenever the GUI
517 needs to redraw the screen, print the board, or export a layer. If
518 item is not NULL, only draw the given item. Item is only non-NULL
519 if the HID was created via show_item.
521 Each time func is called, it should do the following:
523 * allocate any colors needed, via get_color.
525 * cycle through the layers, calling set_layer for each layer to be
526 drawn, and only drawing elements (all or specified) of desired
529 Do *not* assume that the hid that is passed is the GUI hid. This
530 callback is also used for printing and exporting. */
531 void hid_expose_callback (HID_DRAW
*hid_draw
, struct BoxType
*region_
, void *item_
);
533 /* This is initially set to a "no-gui" gui, and later reset by
534 main. hid_expose_callback also temporarily set it for drawing. */
537 /* This is either NULL or points to the current HID that is being called to
538 do the exporting. The gui HIDs set and unset this var.*/
539 extern HID
*exporter
;
541 /* This is either NULL or points to the current HID_Action that is being
542 called. The action launcher sets and unsets this variable. */
543 extern HID_Action
*current_action
;
545 /* The GUI may set this to be approximately the PCB size of a pixel,
546 to allow for near-misses in selection and changes in drawing items
547 smaller than a screen pixel. */
548 extern int pixel_slop
;
550 #if defined(__cplusplus) && __cplusplus