17 #include "crosshair.h"
27 #include "../hidint.h"
31 #if !GTK_CHECK_VERSION(2,8,0) && defined(HAVE_GDK_GDKX_H)
35 #ifdef HAVE_LIBDMALLOC
46 static void zoom_to (double factor
, int x
, int y
);
47 static void zoom_by (double factor
, int x
, int y
);
49 /* Sets gport->u_gc to the "right" GC to use (wrt mask or window)
51 #define USE_GC(gc) if (!use_gc(gc)) return
53 static int cur_mask
= -1;
54 static int mask_seq
= 0;
56 int ghid_flip_x
= 0, ghid_flip_y
= 0;
58 /* ------------------------------------------------------------ */
60 /* Px converts view->pcb, Vx converts pcb->view */
67 rv
= (PCB
->MaxWidth
- x
- gport
->view_x0
) / gport
->zoom
+ 0.5;
69 rv
= (x
- gport
->view_x0
) / gport
->zoom
+ 0.5;
76 return (x
- gport
->view_x0
) / gport
->zoom
+ 0.5;
84 rv
= (PCB
->MaxHeight
- y
- gport
->view_y0
) / gport
->zoom
+ 0.5;
86 rv
= (y
- gport
->view_y0
) / gport
->zoom
+ 0.5;
93 return (y
- gport
->view_y0
) / gport
->zoom
+ 0.5;
99 return z
/ gport
->zoom
+ 0.5;
105 int rv
= x
* gport
->zoom
+ gport
->view_x0
;
107 rv
= PCB
->MaxWidth
- (x
* gport
->zoom
+ gport
->view_x0
);
114 int rv
= y
* gport
->zoom
+ gport
->view_y0
;
116 rv
= PCB
->MaxHeight
- (y
* gport
->zoom
+ gport
->view_y0
);
120 /* ------------------------------------------------------------ */
122 static const char zoom_syntax
[] =
127 static const char zoom_help
[] =
128 "Various zoom factor changes.";
130 /* %start-doc actions Zoom
131 Changes the zoom (magnification) of the view of the board. If no
132 arguments are passed, the view is scaled such that the board just fits
133 inside the visible window (i.e. ``view all''). Otherwise,
134 @var{factor} specifies a change in zoom factor. It may be prefixed by
135 @code{+}, @code{-}, or @code{=} to change how the zoom factor is
136 modified. The @var{factor} is a floating point number, such as
137 @code{1.5} or @code{0.75}.
142 Values greater than 1.0 cause the board to be drawn smaller; more of
143 the board will be visible. Values between 0.0 and 1.0 cause the board
144 to be drawn bigger; less of the board will be visible.
147 Values greater than 1.0 cause the board to be drawn bigger; less of
148 the board will be visible. Values between 0.0 and 1.0 cause the board
149 to be drawn smaller; more of the board will be visible.
153 The @var{factor} is an absolute zoom factor; the unit for this value
154 is "PCB units per screen pixel". Since PCB units are 0.01 mil, a
155 @var{factor} of 1000 means 10 mils (0.01 in) per pixel, or 100 DPI,
156 about the actual resolution of most screens - resulting in an "actual
157 size" board. Similarly, a @var{factor} of 100 gives you a 10x actual
162 Note that zoom factors of zero are silently ignored.
169 Zoom (int argc
, char **argv
, int x
, int y
)
178 if (x
== 0 && y
== 0)
180 x
= gport
->view_width
/ 2;
181 y
= gport
->view_height
/ 2;
185 /* Px converts view->pcb, Vx converts pcb->view */
192 zoom_to (1000000, 0, 0);
197 if (*vp
== '+' || *vp
== '-' || *vp
== '=')
206 zoom_by (1 / v
, x
, y
);
214 /* this needs to set the scale factor absolutely*/
225 zoom_to (double new_zoom
, int x
, int y
)
227 double max_zoom
, xfrac
, yfrac
;
231 * zoom value is PCB units per screen pixel. Larger numbers mean zooming
232 * out - the largest value means you are looking at the whole board.
234 * PCB units per screen pixel
236 * gport->view_width and gport->view_height are in PCB coordinates
240 printf ("\nzoom_to( %g, %d, %d)\n", new_zoom
, x
, y
);
243 xfrac
= (double) x
/ (double) gport
->view_width
;
244 yfrac
= (double) y
/ (double) gport
->view_height
;
251 /* Find the zoom that would just make the entire board fit */
252 max_zoom
= PCB
->MaxWidth
/ gport
->width
;
253 if (max_zoom
< PCB
->MaxHeight
/ gport
->height
)
254 max_zoom
= PCB
->MaxHeight
/ gport
->height
;
257 printf ("zoom_to(): max_zoom = %g\n", max_zoom
);
261 * clip the zooming so we can never have more than 1 pixel per PCB
262 * unit and never zoom out more than viewing the entire board
267 if (new_zoom
> max_zoom
)
271 printf ("max_zoom = %g, xfrac = %g, yfrac = %g, new_zoom = %g\n",
272 max_zoom
, xfrac
, yfrac
, new_zoom
);
275 /* find center x and y */
276 cx
= gport
->view_x0
+ gport
->view_width
* xfrac
* gport
->zoom
;
277 cy
= gport
->view_y0
+ gport
->view_height
* yfrac
* gport
->zoom
;
280 printf ("zoom_to(): x0 = %d, cx = %d\n", gport
->view_x0
, cx
);
281 printf ("zoom_to(): y0 = %d, cy = %d\n", gport
->view_y0
, cy
);
284 if (gport
->zoom
!= new_zoom
)
289 xtmp
= (gport
->view_x
- gport
->view_x0
) / (gdouble
) gport
->view_width
;
290 ytmp
= (gport
->view_y
- gport
->view_y0
) / (gdouble
) gport
->view_height
;
292 gport
->zoom
= new_zoom
;
293 pixel_slop
= new_zoom
;
294 ghid_port_ranges_scale(FALSE
);
296 x0
= gport
->view_x
- xtmp
* gport
->view_width
;
301 y0
= gport
->view_y
- ytmp
* gport
->view_height
;
306 ghidgui
->adjustment_changed_holdoff
= TRUE
;
307 gtk_range_set_value (GTK_RANGE (ghidgui
->h_range
), gport
->view_x0
);
308 gtk_range_set_value (GTK_RANGE (ghidgui
->v_range
), gport
->view_y0
);
309 ghidgui
->adjustment_changed_holdoff
= FALSE
;
311 ghid_port_ranges_changed();
315 printf ("zoom_to(): new x0 = %d\n", gport
->view_x0
);
316 printf ("zoom_to(): new y0 = %d\n", gport
->view_y0
);
318 ghid_set_status_line_label ();
322 zoom_by (double factor
, int x
, int y
)
325 printf ("\nzoom_by( %g, %d, %d). old gport->zoom = %g\n",
326 factor
, x
, y
, gport
->zoom
);
328 zoom_to (gport
->zoom
* factor
, x
, y
);
331 /* ------------------------------------------------------------ */
336 static GdkPoint
*points
= 0;
337 static int npoints
= 0;
338 int x1
, y1
, x2
, y2
, n
, i
;
341 if (!Settings
.DrawGrid
)
343 if (Vz (PCB
->Grid
) < MIN_GRID_DISTANCE
)
347 if (gdk_color_parse (Settings
.GridColor
, &gport
->grid_color
))
349 gport
->grid_color
.red
^= gport
->bg_color
.red
;
350 gport
->grid_color
.green
^= gport
->bg_color
.green
;
351 gport
->grid_color
.blue
^= gport
->bg_color
.blue
;
352 gdk_color_alloc (gport
->colormap
, &gport
->grid_color
);
354 gport
->grid_gc
= gdk_gc_new (gport
->drawable
);
355 gdk_gc_set_function (gport
->grid_gc
, GDK_XOR
);
356 gdk_gc_set_foreground (gport
->grid_gc
, &gport
->grid_color
);
358 x1
= GRIDFIT_X (SIDE_X (gport
->view_x0
), PCB
->Grid
);
359 y1
= GRIDFIT_Y (SIDE_Y (gport
->view_y0
), PCB
->Grid
);
360 x2
= GRIDFIT_X (SIDE_X (gport
->view_x0
+ gport
->view_width
- 1), PCB
->Grid
);
361 y2
= GRIDFIT_Y (SIDE_Y (gport
->view_y0
+ gport
->view_height
- 1), PCB
->Grid
);
378 if (Vx (x2
) >= gport
->width
)
380 if (Vy (y2
) >= gport
->height
)
382 n
= (int) ((x2
- x1
) / PCB
->Grid
+ 0.5) + 1;
387 MyRealloc (points
, npoints
* sizeof (GdkPoint
), "gtk_draw_grid");
390 for (x
= x1
; x
<= x2
; x
+= PCB
->Grid
)
392 points
[n
].x
= Vx (x
);
395 for (y
= y1
; y
<= y2
; y
+= PCB
->Grid
)
398 for (i
= 0; i
< n
; i
++)
400 gdk_draw_points (gport
->drawable
, gport
->grid_gc
, points
, n
);
404 /* ------------------------------------------------------------ */
407 ghid_get_export_options (int *n_ret
)
414 ghid_invalidate_wh (int x
, int y
, int width
, int height
, int last
)
416 ghid_invalidate_all ();
420 ghid_invalidate_lr (int left
, int right
, int top
, int bottom
, int last
)
422 ghid_invalidate_all ();
426 ghid_draw_bg_image(void)
428 static GdkPixbuf
*pixbuf
;
429 GdkInterpType interp_type
;
430 gint x
, y
, w
, h
, w_src
, h_src
;
431 static gint w_scaled
, h_scaled
;
433 if (!ghidgui
->bg_pixbuf
)
436 w
= PCB
->MaxWidth
/ gport
->zoom
;
437 h
= PCB
->MaxHeight
/ gport
->zoom
;
438 x
= gport
->view_x0
/ gport
->zoom
;
439 y
= gport
->view_y0
/ gport
->zoom
;
441 if (w_scaled
!= w
|| h_scaled
!= h
)
444 g_object_unref(G_OBJECT(pixbuf
));
446 w_src
= gdk_pixbuf_get_width(ghidgui
->bg_pixbuf
);
447 h_src
= gdk_pixbuf_get_height(ghidgui
->bg_pixbuf
);
448 if (w
> w_src
&& h
> h_src
)
449 interp_type
= GDK_INTERP_NEAREST
;
451 interp_type
= GDK_INTERP_BILINEAR
;
453 pixbuf
= gdk_pixbuf_scale_simple(ghidgui
->bg_pixbuf
, w
, h
, interp_type
);
458 gdk_pixbuf_render_to_drawable(pixbuf
, gport
->drawable
, gport
->bg_gc
,
460 w
- x
, h
- y
, GDK_RGB_DITHER_NORMAL
, 0, 0);
464 ghid_invalidate_all ()
466 int eleft
, eright
, etop
, ebottom
;
472 region
.X1
= MIN(Px(0), Px(gport
->width
+ 1));
473 region
.Y1
= MIN(Py(0), Py(gport
->height
+ 1));
474 region
.X2
= MAX(Px(0), Px(gport
->width
+ 1));
475 region
.Y2
= MAX(Py(0), Py(gport
->height
+ 1));
478 eright
= Vx (PCB
->MaxWidth
);
480 ebottom
= Vy (PCB
->MaxHeight
);
495 gdk_draw_rectangle (gport
->drawable
, gport
->offlimits_gc
,
496 1, 0, 0, eleft
, gport
->height
);
499 if (eright
< gport
->width
)
500 gdk_draw_rectangle (gport
->drawable
, gport
->offlimits_gc
,
501 1, eright
, 0, gport
->width
- eright
, gport
->height
);
503 eright
= gport
->width
;
505 gdk_draw_rectangle (gport
->drawable
, gport
->offlimits_gc
,
506 1, eleft
, 0, eright
- eleft
+ 1, etop
);
509 if (ebottom
< gport
->height
)
510 gdk_draw_rectangle (gport
->drawable
, gport
->offlimits_gc
,
511 1, eleft
, ebottom
, eright
- eleft
+ 1,
512 gport
->height
- ebottom
);
514 ebottom
= gport
->height
;
516 gdk_draw_rectangle (gport
->drawable
, gport
->bg_gc
, 1,
517 eleft
, etop
, eright
- eleft
+ 1, ebottom
- etop
+ 1);
519 ghid_draw_bg_image();
521 hid_expose_callback (&ghid_hid
, ®ion
, 0);
523 if (ghidgui
->need_restore_crosshair
)
524 RestoreCrosshair (FALSE
);
525 ghidgui
->need_restore_crosshair
= FALSE
;
526 ghid_screen_update ();
531 ghid_pinout_redraw (PinoutType
* po
)
534 int da_w
, da_h
, save_left
, save_top
, save_width
, save_height
;
537 GdkWindow
*window
= po
->drawing_area
->window
;
538 GdkDrawable
*save_drawable
;
543 save_zoom
= gport
->zoom
;
544 save_left
= gport
->view_x0
;
545 save_top
= gport
->view_y0
;
546 save_width
= gport
->view_width
;
547 save_height
= gport
->view_height
;
549 /* Setup drawable and zoom factor for drawing routines
551 save_drawable
= gport
->drawable
;
553 gdk_window_get_geometry (window
, 0, 0, &da_w
, &da_h
, 0);
554 xz
= (double) po
->x_max
/ da_w
;
555 yz
= (double) po
->y_max
/ da_h
;
561 gport
->drawable
= window
;
562 gport
->view_x0
= gport
->view_y0
= 0;
563 gport
->view_width
= da_w
* gport
->zoom
;
564 gport
->view_height
= da_h
* gport
->zoom
;
566 /* clear background call the drawing routine */
567 gdk_draw_rectangle (window
, gport
->bg_gc
, TRUE
, 0, 0, MAX_COORD
, MAX_COORD
);
569 DrawElement (&po
->element
, 0);
571 gport
->zoom
= save_zoom
;
572 gport
->drawable
= save_drawable
;
573 gport
->view_x0
= save_left
;
574 gport
->view_y0
= save_top
;
575 gport
->view_width
= save_width
;;
576 gport
->view_height
= save_height
;
580 ghid_set_layer (const char *name
, int group
)
582 int idx
= (group
>= 0
584 max_layer
) ? PCB
->LayerGroups
.Entries
[group
][0] : group
;
586 if (idx
>= 0 && idx
< max_layer
+ 2)
587 return /*pinout ? 1 : */ PCB
->Data
->Layer
[idx
].On
;
590 switch (SL_TYPE (idx
))
593 return /* pinout ? 0 : */ PCB
->InvisibleObjectsOn
;
595 if (SL_MYSIDE (idx
) /*&& !pinout */ )
596 return TEST_FLAG (SHOWMASKFLAG
, PCB
);
599 if (SL_MYSIDE (idx
) /*|| pinout */ )
600 return PCB
->ElementOn
;
612 #define WHICH_GC(gc) (cur_mask == HID_MASK_CLEAR ? gport->mask_gc : (gc)->gc)
615 ghid_use_mask (int use_it
)
617 static int mask_seq_id
= 0;
622 if (use_it
== cur_mask
)
627 gport
->drawable
= gport
->pixmap
;
631 case HID_MASK_BEFORE
:
632 printf ("gtk doesn't support mask_before!\n");
637 gport
->mask
= gdk_pixmap_new (0, gport
->width
, gport
->height
, 1);
638 gport
->drawable
= gport
->mask
;
642 gport
->mask_gc
= gdk_gc_new (gport
->drawable
);
645 gdk_gc_set_foreground (gport
->mask_gc
, &color
);
646 gdk_draw_rectangle (gport
->drawable
, gport
->mask_gc
, TRUE
, 0, 0,
647 gport
->width
, gport
->height
);
649 gdk_gc_set_foreground (gport
->mask_gc
, &color
);
656 mask_seq
= mask_seq_id
;
658 gport
->drawable
= gport
->pixmap
;
666 ghid_extents_use_mask (int use_it
)
680 /* Config helper functions for when the user changes color preferences.
681 | set_special colors used in the gtkhid.
684 set_special_grid_color (void)
686 if (!gport
->colormap
)
688 gport
->grid_color
.red
^= gport
->bg_color
.red
;
689 gport
->grid_color
.green
^= gport
->bg_color
.green
;
690 gport
->grid_color
.blue
^= gport
->bg_color
.blue
;
691 gdk_color_alloc (gport
->colormap
, &gport
->grid_color
);
693 gdk_gc_set_foreground (gport
->grid_gc
, &gport
->grid_color
);
697 ghid_set_special_colors (HID_Attribute
* ha
)
699 if (!ha
->name
|| !ha
->value
)
701 if (!strcmp (ha
->name
, "background-color") && gport
->bg_gc
)
703 ghid_map_color_string (*(char **) ha
->value
, &gport
->bg_color
);
704 gdk_gc_set_foreground (gport
->bg_gc
, &gport
->bg_color
);
705 set_special_grid_color ();
707 else if (!strcmp (ha
->name
, "off-limit-color") && gport
->offlimits_gc
)
709 ghid_map_color_string (*(char **) ha
->value
, &gport
->offlimits_color
);
710 gdk_gc_set_foreground (gport
->offlimits_gc
, &gport
->offlimits_color
);
712 else if (!strcmp (ha
->name
, "grid-color") && gport
->grid_gc
)
714 ghid_map_color_string (*(char **) ha
->value
, &gport
->grid_color
);
715 set_special_grid_color ();
720 ghid_set_color (hidGC gc
, const char *name
)
722 static void *cache
= 0;
727 fprintf (stderr
, "%s(): name = NULL, setting to magenta\n",
732 gc
->colorname
= (char *) name
;
735 if (gport
->colormap
== 0)
736 gport
->colormap
= gtk_widget_get_colormap (gport
->top_window
);
738 if (strcmp (name
, "erase") == 0)
740 gdk_gc_set_foreground (gc
->gc
, &gport
->bg_color
);
743 else if (strcmp (name
, "drill") == 0)
745 gdk_gc_set_foreground (gc
->gc
, &gport
->offlimits_color
);
751 if (hid_cache_color (0, name
, &cval
, &cache
))
752 cc
= (ColorCache
*) cval
.ptr
;
755 cc
= (ColorCache
*) malloc (sizeof (ColorCache
));
756 memset (cc
, 0, sizeof (*cc
));
758 hid_cache_color (1, name
, &cval
, &cache
);
763 if (gdk_color_parse (name
, &cc
->color
))
764 gdk_color_alloc (gport
->colormap
, &cc
->color
);
766 gdk_color_white (gport
->colormap
, &cc
->color
);
773 cc
->xor_color
.red
= cc
->color
.red
^ gport
->bg_color
.red
;
774 cc
->xor_color
.green
= cc
->color
.green
^ gport
->bg_color
.green
;
775 cc
->xor_color
.blue
= cc
->color
.blue
^ gport
->bg_color
.blue
;
776 gdk_color_alloc (gport
->colormap
, &cc
->xor_color
);
779 gdk_gc_set_foreground (gc
->gc
, &cc
->xor_color
);
783 gdk_gc_set_foreground (gc
->gc
, &cc
->color
);
791 ghid_set_line_cap (hidGC gc
, EndCapStyle style
)
798 gc
->cap
= GDK_CAP_ROUND
;
799 gc
->join
= GDK_JOIN_ROUND
;
803 gc
->cap
= GDK_CAP_PROJECTING
;
804 gc
->join
= GDK_JOIN_MITER
;
808 gdk_gc_set_line_attributes (WHICH_GC (gc
),
809 Vz (gc
->width
), GDK_LINE_SOLID
,
814 ghid_set_line_width (hidGC gc
, int width
)
819 gdk_gc_set_line_attributes (WHICH_GC (gc
),
820 Vz (gc
->width
), GDK_LINE_SOLID
,
825 ghid_set_draw_xor (hidGC gc
, int xor)
830 gdk_gc_set_function (gc
->gc
, xor ? GDK_XOR
: GDK_COPY
);
831 ghid_set_color (gc
, gc
->colorname
);
835 ghid_set_draw_faded (hidGC gc
, int faded
)
837 printf ("ghid_set_draw_faded(%p,%d) -- not implemented\n", gc
, faded
);
841 ghid_set_line_cap_angle (hidGC gc
, int x1
, int y1
, int x2
, int y2
)
843 printf ("ghid_set_line_cap_angle() -- not implemented\n");
853 gc
->gc
= gdk_gc_new (gport
->top_window
->window
);
854 ghid_set_color (gc
, gc
->colorname
);
855 ghid_set_line_width (gc
, gc
->width
);
856 ghid_set_line_cap (gc
, gc
->cap
);
857 ghid_set_draw_xor (gc
, gc
->xor);
859 if (gc
->mask_seq
!= mask_seq
)
862 gdk_gc_set_clip_mask (gc
->gc
, gport
->mask
);
864 gdk_gc_set_clip_mask (gc
->gc
, NULL
);
865 gc
->mask_seq
= mask_seq
;
867 gport
->u_gc
= WHICH_GC (gc
);
872 ghid_draw_line (hidGC gc
, int x1
, int y1
, int x2
, int y2
)
874 double dx1
, dy1
, dx2
, dy2
;
876 dx1
= Vx ((double)x1
);
877 dy1
= Vy ((double)y1
);
878 dx2
= Vx ((double)x2
);
879 dy2
= Vy ((double)y2
);
881 if (! ClipLine (0, 0, gport
->width
, gport
->height
,
882 &dx1
, &dy1
, &dx2
, &dy2
, gc
->width
/ gport
->zoom
))
886 gdk_draw_line (gport
->drawable
, gport
->u_gc
, dx1
, dy1
, dx2
, dy2
);
890 ghid_draw_arc (hidGC gc
, int cx
, int cy
,
891 int xradius
, int yradius
, int start_angle
, int delta_angle
)
896 w
= gport
->width
* gport
->zoom
;
897 h
= gport
->height
* gport
->zoom
;
898 radius
= (xradius
> yradius
) ? xradius
: yradius
;
899 if (SIDE_X (cx
) < gport
->view_x0
- radius
900 || SIDE_X (cx
) > gport
->view_x0
+ w
+ radius
901 || SIDE_Y (cy
) < gport
->view_y0
- radius
902 || SIDE_Y (cy
) > gport
->view_y0
+ h
+ radius
)
910 /* make sure we fall in the -180 to +180 range */
911 start_angle
= (start_angle
+ 360 + 180) % 360 - 180;
914 start_angle
= 180 - start_angle
;
915 delta_angle
= - delta_angle
;
919 start_angle
= - start_angle
;
920 delta_angle
= - delta_angle
;
923 gdk_draw_arc (gport
->drawable
, gport
->u_gc
, 0,
924 Vx (cx
) - vrx
, Vy (cy
) - vry
,
925 vrx
* 2, vry
* 2, (start_angle
+ 180) * 64, delta_angle
* 64);
929 ghid_draw_rect (hidGC gc
, int x1
, int y1
, int x2
, int y2
)
934 w
= gport
->width
* gport
->zoom
;
935 h
= gport
->height
* gport
->zoom
;
937 if ((SIDE_X (x1
) < gport
->view_x0
- lw
938 && SIDE_X (x2
) < gport
->view_x0
- lw
)
939 || (SIDE_X (x1
) > gport
->view_x0
+ w
+ lw
940 && SIDE_X (x2
) > gport
->view_x0
+ w
+ lw
)
941 || (SIDE_Y (y1
) < gport
->view_y0
- lw
942 && SIDE_Y (y2
) < gport
->view_y0
- lw
)
943 || (SIDE_Y (y1
) > gport
->view_y0
+ h
+ lw
944 && SIDE_Y (y2
) > gport
->view_y0
+ h
+ lw
))
952 if (x1
> x2
) { gint xt
= x1
; x1
= x2
; x2
= xt
; }
953 if (y1
> y2
) { gint yt
= y1
; y1
= y2
; y2
= yt
; }
956 gdk_draw_rectangle (gport
->drawable
, gport
->u_gc
, FALSE
,
957 x1
, y1
, x2
- x1
+ 1, y2
- y1
+ 1);
962 ghid_fill_circle (hidGC gc
, int cx
, int cy
, int radius
)
966 w
= gport
->width
* gport
->zoom
;
967 h
= gport
->height
* gport
->zoom
;
968 if (SIDE_X (cx
) < gport
->view_x0
- radius
969 || SIDE_X (cx
) > gport
->view_x0
+ w
+ radius
970 || SIDE_Y (cy
) < gport
->view_y0
- radius
971 || SIDE_Y (cy
) > gport
->view_y0
+ h
+ radius
)
976 gdk_draw_arc (gport
->drawable
, gport
->u_gc
, TRUE
,
977 Vx (cx
) - vr
, Vy (cy
) - vr
,
978 vr
* 2, vr
* 2, 0, 360 * 64);
982 ghid_fill_polygon (hidGC gc
, int n_coords
, int *x
, int *y
)
984 static GdkPoint
*points
= 0;
985 static int npoints
= 0;
989 if (npoints
< n_coords
)
991 npoints
= n_coords
+ 1;
992 points
= MyRealloc (points
,
993 npoints
* sizeof (GdkPoint
), (char *) __FUNCTION__
);
995 for (i
= 0; i
< n_coords
; i
++)
997 points
[i
].x
= Vx (x
[i
]);
998 points
[i
].y
= Vy (y
[i
]);
1000 gdk_draw_polygon (gport
->drawable
, gport
->u_gc
, 1, points
, n_coords
);
1004 ghid_fill_rect (hidGC gc
, int x1
, int y1
, int x2
, int y2
)
1009 w
= gport
->width
* gport
->zoom
;
1010 h
= gport
->height
* gport
->zoom
;
1012 if ((SIDE_X (x1
) < gport
->view_x0
- lw
1013 && SIDE_X (x2
) < gport
->view_x0
- lw
)
1014 || (SIDE_X (x1
) > gport
->view_x0
+ w
+ lw
1015 && SIDE_X (x2
) > gport
->view_x0
+ w
+ lw
)
1016 || (SIDE_Y (y1
) < gport
->view_y0
- lw
1017 && SIDE_Y (y2
) < gport
->view_y0
- lw
)
1018 || (SIDE_Y (y1
) > gport
->view_y0
+ h
+ lw
1019 && SIDE_Y (y2
) > gport
->view_y0
+ h
+ lw
))
1033 gdk_draw_rectangle (gport
->drawable
, gport
->u_gc
, TRUE
,
1034 x1
, y1
, x2
- x1
+ 1, y2
- y1
+ 1);
1038 ghid_extents_draw_line (hidGC gc
, int x1
, int y1
, int x2
, int y2
)
1040 printf ("ghid_extents_draw_line() -- not implemented\n");
1044 ghid_extents_draw_arc (hidGC gc
, int cx
, int cy
,
1045 int xradius
, int yradius
,
1046 int start_angle
, int delta_angle
)
1048 printf ("ghid_extents_draw_arc() -- not implemented\n");
1052 ghid_extents_draw_rect (hidGC gc
, int x1
, int y1
, int x2
, int y2
)
1054 printf ("ghid_extents_draw_rect() -- not implemented\n");
1058 ghid_extents_fill_circle (hidGC gc
, int cx
, int cy
, int radius
)
1060 printf ("ghid_extents_fill_circle() -- not implemented\n");
1064 ghid_extents_fill_polygon (hidGC gc
, int n_coords
, int *x
, int *y
)
1066 printf ("ghid_extents_fill_polygon() -- not implemented\n");
1070 ghid_extents_fill_rect (hidGC gc
, int x1
, int y1
, int x2
, int y2
)
1072 printf ("ghid_extents_fill_rect() -- not implemented\n");
1076 ghid_calibrate (double xval
, double yval
)
1078 printf ("ghid_calibrate() -- not implemented\n");
1082 ghid_shift_is_pressed ()
1084 GdkModifierType mask
;
1085 GHidPort
*out
= &ghid_port
;
1087 gdk_window_get_pointer (out
->drawing_area
->window
, NULL
, NULL
, &mask
);
1088 return (mask
& GDK_SHIFT_MASK
) ? TRUE
: FALSE
;
1092 ghid_control_is_pressed ()
1094 GdkModifierType mask
;
1095 GHidPort
*out
= &ghid_port
;
1097 gdk_window_get_pointer (out
->drawing_area
->window
, NULL
, NULL
, &mask
);
1098 return (mask
& GDK_CONTROL_MASK
) ? TRUE
: FALSE
;
1102 ghid_set_crosshair (int x
, int y
, int action
)
1104 ghid_set_cursor_position_labels ();
1105 gport
->x_crosshair
= x
;
1106 gport
->y_crosshair
= y
;
1117 /* We need a wrapper around the hid timer because a gtk timer needs
1118 | to return FALSE else the timer will be restarted.
1121 ghid_timer (GuiTimer
* timer
)
1123 (*timer
->func
) (timer
->user_data
);
1124 ghid_mode_cursor (Settings
.Mode
);
1125 return FALSE
; /* Turns timer off */
1129 ghid_add_timer (void (*func
) (hidval user_data
),
1130 unsigned long milliseconds
, hidval user_data
)
1132 GuiTimer
*timer
= g_new0 (GuiTimer
, 1);
1136 timer
->user_data
= user_data
;
1137 timer
->id
= gtk_timeout_add (milliseconds
, (GtkFunction
) ghid_timer
, timer
);
1138 ret
.ptr
= (void *) timer
;
1143 ghid_stop_timer (hidval timer
)
1145 void *ptr
= timer
.ptr
;
1147 gtk_timeout_remove (((GuiTimer
*) ptr
)->id
);
1153 void (*func
) ( hidval
, int, unsigned int, hidval
);
1156 GIOChannel
*channel
;
1161 /* We need a wrapper around the hid file watch to pass the correct flags
1164 ghid_watch (GIOChannel
*source
, GIOCondition condition
, gpointer data
)
1166 unsigned int pcb_condition
= 0;
1168 GuiWatch
*watch
= (GuiWatch
*)data
;
1170 if (condition
& G_IO_IN
)
1171 pcb_condition
|= PCB_WATCH_READABLE
;
1172 if (condition
& G_IO_OUT
)
1173 pcb_condition
|= PCB_WATCH_WRITABLE
;
1174 if (condition
& G_IO_ERR
)
1175 pcb_condition
|= PCB_WATCH_ERROR
;
1176 if (condition
& G_IO_HUP
)
1177 pcb_condition
|= PCB_WATCH_HANGUP
;
1179 x
.ptr
= (void *) watch
;
1180 watch
->func (x
, watch
->fd
, pcb_condition
, watch
->user_data
);
1181 ghid_mode_cursor (Settings
.Mode
);
1183 return TRUE
; /* Leave watch on */
1187 ghid_watch_file (int fd
, unsigned int condition
, void (*func
) (hidval watch
, int fd
, unsigned int condition
, hidval user_data
),
1190 GuiWatch
*watch
= g_new0 (GuiWatch
, 1);
1192 unsigned int glib_condition
= 0;
1194 if (condition
& PCB_WATCH_READABLE
)
1195 glib_condition
|= G_IO_IN
;
1196 if (condition
& PCB_WATCH_WRITABLE
)
1197 glib_condition
|= G_IO_OUT
;
1198 if (condition
& PCB_WATCH_ERROR
)
1199 glib_condition
|= G_IO_ERR
;
1200 if (condition
& PCB_WATCH_HANGUP
)
1201 glib_condition
|= G_IO_HUP
;
1204 watch
->user_data
= user_data
;
1206 watch
->channel
= g_io_channel_unix_new( fd
);
1207 watch
->id
= g_io_add_watch( watch
->channel
, glib_condition
, ghid_watch
, watch
);
1209 ret
.ptr
= (void *) watch
;
1214 ghid_unwatch_file (hidval data
)
1216 GuiWatch
*watch
= (GuiWatch
*)data
.ptr
;
1218 g_io_channel_shutdown( watch
->channel
, TRUE
, NULL
);
1219 g_io_channel_unref( watch
->channel
);
1226 void (*func
) (hidval user_data
);
1230 static gboolean
ghid_block_hook_prepare (GSource
*source
,
1232 static gboolean
ghid_block_hook_check (GSource
*source
);
1233 static gboolean
ghid_block_hook_dispatch (GSource
*source
,
1234 GSourceFunc callback
,
1235 gpointer user_data
);
1237 static GSourceFuncs ghid_block_hook_funcs
= {
1238 ghid_block_hook_prepare
,
1239 ghid_block_hook_check
,
1240 ghid_block_hook_dispatch
,
1241 NULL
// No destroy notification
1245 ghid_block_hook_prepare (GSource
*source
,
1248 hidval data
= ((BlockHookSource
*)source
)->user_data
;
1249 ((BlockHookSource
*)source
)->func( data
);
1254 ghid_block_hook_check (GSource
*source
)
1260 ghid_block_hook_dispatch (GSource
*source
,
1261 GSourceFunc callback
,
1268 ghid_add_block_hook (void (*func
) (hidval data
),
1272 BlockHookSource
*source
;
1274 source
= (BlockHookSource
*)g_source_new (&ghid_block_hook_funcs
, sizeof( BlockHookSource
));
1276 source
->func
= func
;
1277 source
->user_data
= user_data
;
1279 g_source_attach ((GSource
*)source
, NULL
);
1281 ret
.ptr
= (void *) source
;
1286 ghid_stop_block_hook (hidval mlpoll
)
1288 GSource
*source
= (GSource
*)mlpoll
.ptr
;
1289 g_source_destroy( source
);
1293 ghid_confirm_dialog (char *msg
, ...)
1297 /* FIXME -- deal with the ... part! */
1298 rv
= ghid_dialog_confirm (msg
);
1304 ghid_report_dialog (char *title
, char *msg
)
1306 ghid_dialog_report (title
, msg
);
1310 ghid_prompt_for (char *msg
, char *default_string
)
1314 rv
= ghid_dialog_input (msg
, default_string
);
1319 ghid_attribute_dialog (HID_Attribute
* attrs
,
1320 int n_attrs
, HID_Attr_Val
* results
)
1322 printf ("ghid_attribute_dialog() -- not implemented yet\n");
1327 ghid_show_item (void *item
)
1329 ghid_pinout_window_show (&ghid_port
, (ElementTypePtr
) item
);
1339 ghid_progress (int so_far
, int total
, const char *message
)
1344 /* ---------------------------------------------------------------------- */
1349 "Gtk - The Gimp Toolkit",
1353 0, /* poly before */
1357 ghid_get_export_options
,
1359 ghid_parse_arguments
,
1363 ghid_invalidate_all
,
1370 ghid_set_line_width
,
1372 ghid_set_draw_faded
,
1373 ghid_set_line_cap_angle
,
1382 ghid_shift_is_pressed
,
1383 ghid_control_is_pressed
,
1390 ghid_add_block_hook
,
1391 ghid_stop_block_hook
,
1395 ghid_confirm_dialog
,
1398 ghid_attribute_dialog
,
1404 HID ghid_extents
= {
1407 "used to calculate extents",
1411 0, /* poly before */
1415 0 /* ghid_get_export_options */ ,
1416 0 /* ghid_do_export */ ,
1417 0 /* ghid_parse_arguments */ ,
1419 0 /* ghid_invalidate_wh */ ,
1420 0 /* ghid_invalidate_lr */ ,
1421 0 /* ghid_invalidate_all */ ,
1422 0 /* ghid_set_layer */ ,
1423 0 /* ghid_make_gc */ ,
1424 0 /* ghid_destroy_gc */ ,
1425 ghid_extents_use_mask
,
1426 0 /* ghid_set_color */ ,
1427 0 /* ghid_set_line_cap */ ,
1428 0 /* ghid_set_line_width */ ,
1429 0 /* ghid_set_draw_xor */ ,
1430 0 /* ghid_set_draw_faded */ ,
1431 0 /* ghid_set_line_cap_angle */ ,
1432 ghid_extents_draw_line
,
1433 ghid_extents_draw_arc
,
1434 ghid_extents_draw_rect
,
1435 ghid_extents_fill_circle
,
1436 ghid_extents_fill_polygon
,
1437 ghid_extents_fill_rect
,
1439 0 /* ghid_calibrate */ ,
1440 0 /* ghid_shift_is_pressed */ ,
1441 0 /* ghid_control_is_pressed */ ,
1442 0 /* ghid_get_coords */ ,
1443 0 /* ghid_set_crosshair */ ,
1444 0 /* ghid_add_timer */ ,
1445 0 /* ghid_stop_timer */ ,
1446 0 /* ghid_watch_file */ ,
1447 0 /* ghid_unwatch_file */ ,
1448 0 /* ghid_add_block_hook */ ,
1449 0 /* ghid_stop_block_hook */ ,
1453 0 /* ghid_confirm_dialog */ ,
1454 0 /* ghid_report_dialog */ ,
1455 0 /* ghid_prompt_for */ ,
1456 0 /* ghid_attribute_dialog */ ,
1457 0 /* ghid_show_item */ ,
1459 0 /* ghid_progress */
1462 /* ------------------------------------------------------------
1464 * Actions specific to the GTK HID follow from here
1469 /* ------------------------------------------------------------ */
1470 static const char about_syntax
[] =
1473 static const char about_help
[] =
1474 "Tell the user about this version of PCB.";
1476 /* %start-doc actions About
1478 This just pops up a dialog telling the user which version of
1479 @code{pcb} they're running.
1485 About (int argc
, char **argv
, int x
, int y
)
1487 ghid_dialog_about ();
1491 /* ------------------------------------------------------------ */
1492 static const char getxy_syntax
[] =
1495 static const char getxy_help
[] =
1496 "Get a coordinate.";
1498 /* %start-doc actions GetXY
1500 Prompts the user for a coordinate, if one is not already selected.
1505 GetXY (int argc
, char **argv
, int x
, int y
)
1510 /* ---------------------------------------------------------------------- */
1512 static int PointCursor (int argc
, char **argv
, int x
, int y
)
1518 ghid_point_cursor ();
1520 ghid_mode_cursor (Settings
.Mode
);
1524 /* ---------------------------------------------------------------------- */
1527 RouteStylesChanged (int argc
, char **argv
, int x
, int y
)
1531 if (PCB
&& PCB
->RouteStyle
[0].Name
)
1532 for (n
= 0; n
< NUM_STYLES
; ++n
)
1533 ghid_route_style_set_button_label ((&PCB
->RouteStyle
[n
])->Name
, n
);
1537 /* ---------------------------------------------------------------------- */
1540 PCBChanged (int argc
, char **argv
, int x
, int y
)
1545 ghid_window_set_name_label (PCB
->Name
);
1549 RouteStylesChanged (0, NULL
, 0, 0);
1550 ghid_port_ranges_scale (TRUE
);
1551 ghid_port_ranges_pan (0, 0, FALSE
);
1552 ghid_port_ranges_zoom (0);
1553 ghid_port_ranges_changed ();
1554 ghid_sync_with_new_layout ();
1558 /* ---------------------------------------------------------------------- */
1561 LayerGroupsChanged (int argc
, char **argv
, int x
, int y
)
1563 printf ("LayerGroupsChanged -- not implemented\n");
1567 /* ---------------------------------------------------------------------- */
1570 LibraryChanged (int argc
, char **argv
, int x
, int y
)
1572 ghid_library_window_show (&ghid_port
, FALSE
);
1576 /* ---------------------------------------------------------------------- */
1579 Command (int argc
, char **argv
, int x
, int y
)
1581 ghid_handle_user_command (FALSE
);
1585 /* ---------------------------------------------------------------------- */
1588 Load (int argc
, char **argv
, int x
, int y
)
1593 static gchar
*current_element_dir
= NULL
;
1594 static gchar
*current_layout_dir
= NULL
;
1595 static gchar
*current_netlist_dir
= NULL
;
1597 /* we've been given the file name */
1599 return hid_actionv ("LoadFrom", argc
, argv
);
1601 function
= argc
? argv
[0] : "Layout";
1603 if (strcasecmp (function
, "Netlist") == 0)
1605 name
= ghid_dialog_file_select_open (_("Load netlist file"),
1606 ¤t_netlist_dir
,
1609 else if (strcasecmp (function
, "ElementToBuffer") == 0)
1611 name
= ghid_dialog_file_select_open (_("Load element to buffer"),
1612 ¤t_element_dir
,
1613 Settings
.LibraryTree
);
1615 else if (strcasecmp (function
, "LayoutToBuffer") == 0)
1617 name
= ghid_dialog_file_select_open (_("Load layout file to buffer"),
1618 ¤t_layout_dir
,
1621 else if (strcasecmp (function
, "Layout") == 0)
1623 name
= ghid_dialog_file_select_open (_("Load layout file"),
1624 ¤t_layout_dir
,
1630 if (Settings
.verbose
)
1631 fprintf (stderr
, "%s: Calling LoadFrom(%s, %s)\n", __FUNCTION__
,
1633 hid_actionl ("LoadFrom", function
, name
, NULL
);
1640 /* ---------------------------------------------------------------------- */
1643 LoadVendor (int argc
, char **argv
, int x
, int y
)
1646 static gchar
*current_vendor_dir
= NULL
;
1649 return hid_actionv ("LoadVendorFrom", argc
, argv
);
1651 name
= ghid_dialog_file_select_open (_("Load vendor file"),
1652 ¤t_vendor_dir
,
1657 if (Settings
.verbose
)
1658 fprintf (stderr
, "%s: Calling LoadVendorFrom(%s)\n", __FUNCTION__
,
1660 hid_actionl ("LoadVendorFrom", name
, NULL
);
1667 /* ---------------------------------------------------------------------- */
1670 Save (int argc
, char **argv
, int x
, int y
)
1674 static gchar
*current_dir
= NULL
;
1677 return hid_actionv ("SaveTo", argc
, argv
);
1679 function
= argc
? argv
[0] : "Layout";
1681 if (strcasecmp (function
, "Layout") == 0)
1683 return hid_actionl ("SaveTo", "Layout", PCB
->Filename
, NULL
);
1685 name
= ghid_dialog_file_select_save (_("Save layout as"),
1687 PCB
->Filename
, Settings
.FilePath
);
1692 exist
= fopen (name
, "r");
1696 if (ghid_dialog_confirm (_("File exists! Ok to overwrite?")))
1698 if (Settings
.verbose
)
1699 fprintf (stderr
, "Overwriting %s\n", name
);
1708 if (Settings
.verbose
)
1709 fprintf (stderr
, "%s: Calling SaveTo(%s, %s)\n", __FUNCTION__
, function
,
1713 * if we got this far and the function is Layout, then
1714 * we really needed it to be a LayoutAs. Otherwise
1715 * ActionSaveTo() will ignore the new file name we
1718 if (strcasecmp (function
, "Layout") == 0)
1719 hid_actionl ("SaveTo", "LayoutAs", name
, NULL
);
1721 hid_actionl ("SaveTo", function
, name
, NULL
);
1728 /* ---------------------------------------------------------------------- */
1729 static const char swapsides_syntax
[] =
1730 "SwapSides(|v|h|r)";
1732 static const char swapsides_help
[] =
1733 "Swaps the side of the board you're looking at.";
1735 /* %start-doc actions SwapSides
1737 This action changes the way you view the board.
1742 Flips the board over vertically (up/down).
1745 Flips the board over horizontally (left/right), like flipping pages in
1749 Rotates the board 180 degrees without changing sides.
1753 If no argument is given, the board isn't moved but the opposite side
1756 Normally, this action changes which pads and silk layer are drawn as
1757 true silk, and which are drawn as the "invisible" layer. It also
1758 determines which solder mask you see.
1760 As a special case, if the layer group for the side you're looking at
1761 is visible and currently active, and the layer group for the opposite
1762 is not visible (i.e. disabled), then this action will also swap which
1763 layer group is visible and active, effectively swapping the ``working
1764 side'' of the board.
1770 SwapSides (int argc
, char **argv
, int x
, int y
)
1773 int comp_group
= GetLayerGroupNumberByNumber (max_layer
+ COMPONENT_LAYER
);
1774 int solder_group
= GetLayerGroupNumberByNumber (max_layer
+ SOLDER_LAYER
);
1775 int active_group
= GetLayerGroupNumberByNumber (LayerStack
[0]);
1777 PCB
->Data
->Layer
[PCB
->LayerGroups
.Entries
[comp_group
][0]].On
;
1778 int solder_showing
=
1779 PCB
->Data
->Layer
[PCB
->LayerGroups
.Entries
[solder_group
][0]].On
;
1784 switch (argv
[0][0]) {
1787 ghid_flip_x
= ! ghid_flip_x
;
1791 ghid_flip_y
= ! ghid_flip_y
;
1795 ghid_flip_x
= ! ghid_flip_x
;
1796 ghid_flip_y
= ! ghid_flip_y
;
1801 /* SwapSides will swap this */
1802 Settings
.ShowSolderSide
= (ghid_flip_x
== ghid_flip_y
);
1805 Settings
.ShowSolderSide
= !Settings
.ShowSolderSide
;
1806 if (Settings
.ShowSolderSide
)
1808 if (active_group
== comp_group
&& comp_showing
&& !solder_showing
)
1810 ChangeGroupVisibility (PCB
->LayerGroups
.Entries
[comp_group
][0], 0,
1812 ChangeGroupVisibility (PCB
->LayerGroups
.Entries
[solder_group
][0], 1,
1818 if (active_group
== solder_group
&& solder_showing
&& !comp_showing
)
1820 ChangeGroupVisibility (PCB
->LayerGroups
.Entries
[solder_group
][0], 0,
1822 ChangeGroupVisibility (PCB
->LayerGroups
.Entries
[comp_group
][0], 1,
1827 /* what does this do? */
1828 dx
= PCB
->MaxWidth
/ 2 - gport
->view_x
;
1829 ghid_port_ranges_pan (2 * dx
, 0, TRUE
);
1831 ghid_invalidate_all ();
1836 Print (int argc
, char **argv
, int x
, int y
)
1840 HID
*printer
= NULL
;
1842 hids
= hid_enumerate ();
1843 for (i
= 0; hids
[i
]; i
++)
1845 if (hids
[i
]->printer
)
1849 if (printer
== NULL
)
1851 gui
->log (_("Can't find a suitable printer HID"));
1855 /* check if layout is empty */
1856 if (!IsDataEmpty (PCB
->Data
))
1858 ghid_dialog_print (printer
);
1861 gui
->log (_("Can't print empty layout"));
1867 Export (int argc
, char **argv
, int x
, int y
)
1870 /* check if layout is empty */
1871 if (!IsDataEmpty (PCB
->Data
))
1873 ghid_dialog_export ();
1876 gui
->log (_("Can't export empty layout"));
1882 Benchmark (int argc
, char **argv
, int x
, int y
)
1887 GdkDisplay
*display
;
1889 display
= gdk_drawable_get_display (gport
->drawable
);
1893 region
.X2
= PCB
->MaxWidth
;
1894 region
.Y2
= PCB
->MaxHeight
;
1896 gdk_display_sync (display
);
1900 hid_expose_callback (&ghid_hid
, ®ion
, 0);
1901 gdk_display_sync (display
);
1905 while (end
- start
< 10);
1907 printf ("%g redraws per second\n", i
/ 10.0);
1912 /* ------------------------------------------------------------ */
1914 static const char center_syntax
[] =
1917 static const char center_help
[] =
1918 "Moves the pointer to the center of the window.";
1920 /* %start-doc actions Center
1922 Move the pointer to the center of the window, but only if it's
1923 currently within the window already.
1928 Center(int argc
, char **argv
, int x
, int y
)
1930 int x0
, y0
, w2
, h2
, dx
, dy
;
1935 x
= GRIDFIT_X (SIDE_X (x
), PCB
->Grid
);
1936 y
= GRIDFIT_Y (SIDE_Y (y
), PCB
->Grid
);
1938 w2
= gport
->view_width
/ 2;
1939 h2
= gport
->view_height
/ 2;
1955 dx
= (x0
- gport
->view_x0
) / gport
->zoom
;
1956 dy
= (y0
- gport
->view_y0
) / gport
->zoom
;
1957 gport
->view_x0
= x0
;
1958 gport
->view_y0
= y0
;
1961 /* FIXME -- do I need something like the pan_fixup here? */
1962 /* lesstif_pan_fixup (); */
1964 /* Move the pointer to the center of the window, but only if it's
1965 currently within the window already. Watch out for edges,
1968 #if GTK_CHECK_VERSION(2,8,0)
1970 GdkDisplay
*display
;
1974 display
= gdk_display_get_default ();
1975 screen
= gdk_display_get_default_screen (display
);
1977 /* figure out where the pointer is and then move it from there by the specified delta */
1978 gdk_display_get_pointer (display
, NULL
, &cx
, &cy
, NULL
);
1979 gdk_display_warp_pointer (display
, screen
, cx
- dx
, cy
- dy
);
1982 * Note that under X11, gdk_display_warp_pointer is just a wrapper around XWarpPointer, but
1983 * hopefully by avoiding the direct call to an X function we might still work under windows
1984 * and other non-X11 based gdk's
1988 # ifdef HAVE_GDK_GDKX_H
1991 Window w_src
, w_dst
;
1992 w_src
= GDK_WINDOW_XID (gport
->drawing_area
->window
);
1995 /* don't warp with the auto drc - that creates auto-scroll chaos */
1996 if (TEST_FLAG (AUTODRCFLAG
, PCB
) && Settings
.Mode
== LINE_MODE
1997 && Crosshair
.AttachedLine
.State
!= STATE_FIRST
)
2000 XWarpPointer (GDK_DRAWABLE_XDISPLAY (gport
->drawing_area
->window
),
2005 /* XWarpPointer creates Motion events normally bound to
2006 * EventMoveCrosshair.
2007 * We don't do any updates when EventMoveCrosshair
2008 * is called the next time to prevent from rounding errors
2011 * IgnoreMotionEvents = ignore;
2019 /* ------------------------------------------------------------ */
2021 static const char dowindows_syntax
[] =
2022 "DoWindows(1|2|3|4)\n"
2023 "DoWindows(Layout|Library|Log|Netlist|Preferences)";
2025 static const char dowindows_help
[] =
2026 "Open various GUI windows.";
2028 /* %start-doc actions DoWindows
2034 Open the layout window. Since the layout window is always shown
2035 anyway, this has no effect.
2039 Open the library window.
2043 Open the log window.
2047 Open the netlist window.
2051 Open the preferences window.
2058 DoWindows (int argc
, char **argv
, int x
, int y
)
2060 char *a
= argc
== 1 ? argv
[0] : "";
2062 if (strcmp (a
, "1") == 0 || strcasecmp (a
, "Layout") == 0)
2065 else if (strcmp (a
, "2") == 0 || strcasecmp (a
, "Library") == 0)
2067 ghid_library_window_show (gport
, TRUE
);
2069 else if (strcmp (a
, "3") == 0 || strcasecmp (a
, "Log") == 0)
2071 ghid_log_window_show (TRUE
);
2073 else if (strcmp (a
, "4") == 0 || strcasecmp (a
, "Netlist") == 0)
2075 ghid_netlist_window_show (gport
, TRUE
);
2077 else if (strcmp (a
, "5") == 0 || strcasecmp (a
, "Preferences") == 0)
2079 ghid_config_window_show ();
2089 /* ------------------------------------------------------------ */
2090 static const char setunits_syntax
[] =
2093 static const char setunits_help
[] =
2094 "Set the default measurement units.";
2096 /* %start-doc actions SetUnits
2101 Sets the display units to mils (1/1000 inch).
2104 Sets the display units to millimeters.
2111 SetUnits (int argc
, char **argv
, int x
, int y
)
2115 if (strcmp (argv
[0], "mil") == 0)
2116 Settings
.grid_units_mm
= 0;
2117 if (strcmp (argv
[0], "mm") == 0)
2118 Settings
.grid_units_mm
= 1;
2120 ghid_config_handle_units_changed ();
2122 ghid_set_status_line_label ();
2125 * lesstif_sizes_reset ();
2126 * lesstif_styles_update_values ();
2131 /* ------------------------------------------------------------ */
2132 static const char popup_syntax
[] =
2133 "Popup(MenuName, [Button])";
2135 static const char popup_help
[] =
2136 "Bring up the popup menu specified by @code{MenuName}.\n"
2137 "If called by a mouse event then the mouse button number\n"
2138 "must be specified as the optional second argument.";
2140 /* %start-doc actions Popup
2142 This just pops up the specified menu. The menu must have been defined
2143 as a named subresource of the Popups resource in the menu resource
2144 file. If called as a response to a mouse button click, the mouse
2145 button number must be specified as the second argument.
2151 Popup (int argc
, char **argv
, int x
, int y
)
2157 if (argc
!= 1 && argc
!= 2)
2163 button
= atoi (argv
[1]);
2165 if ( (element
= (char *) malloc ( (strlen (argv
[0]) + 2) * sizeof (char))) == NULL
)
2167 fprintf (stderr
, "Popup(): malloc failed\n");
2171 sprintf (element
, "/%s", argv
[0]);
2172 printf ("Loading popup \"%s\". Button = %u\n", element
, button
);
2174 menu
= gtk_ui_manager_get_widget (ghidgui
->ui_manager
, element
);
2177 if (! GTK_IS_MENU (menu
))
2179 Message ("The specified popup menu \"%s\" has not been defined.\n", argv
[0]);
2184 ghidgui
->in_popup
= TRUE
;
2185 gtk_widget_grab_focus (ghid_port
.drawing_area
);
2186 gtk_menu_popup (GTK_MENU (menu
), NULL
, NULL
, NULL
, NULL
, 0,
2187 gtk_get_current_event_time());
2193 Busy (int argc
, char **argv
, int x
, int y
)
2195 ghid_watch_cursor ();
2199 HID_Action ghid_main_action_list
[] = {
2200 {"About", 0, About
, about_help
, about_syntax
},
2201 {"Benchmark", 0, Benchmark
},
2203 {"Center", "Click on a location to center", Center
, center_help
, center_syntax
},
2204 {"Command", 0, Command
},
2205 {"DoWindows", 0, DoWindows
, dowindows_help
, dowindows_syntax
},
2206 {"Export", 0, Export
},
2207 {"GetXY", "", GetXY
, getxy_help
, getxy_syntax
},
2208 {"LayerGroupsChanged", 0, LayerGroupsChanged
},
2209 {"LibraryChanged", 0, LibraryChanged
},
2211 {"LoadVendor", 0, LoadVendor
},
2212 {"PCBChanged", 0, PCBChanged
},
2213 {"PointCursor", 0, PointCursor
},
2214 {"Popup", 0, Popup
, popup_help
, popup_syntax
},
2215 {"Print", 0, Print
},
2216 {"RouteStylesChanged", 0, RouteStylesChanged
},
2218 {"SetUnits", 0, SetUnits
, setunits_help
, setunits_syntax
},
2219 {"SwapSides", 0, SwapSides
, swapsides_help
, swapsides_syntax
},
2220 {"Zoom", "Click on zoom focus", Zoom
, zoom_help
, zoom_syntax
}
2223 REGISTER_ACTIONS (ghid_main_action_list
)
2237 HID_Flag ghid_main_flag_list
[] = {
2238 {"flip_x", flag_flipx
, 0},
2239 {"flip_y", flag_flipy
, 0}
2242 REGISTER_FLAGS (ghid_main_flag_list
)
2244 #include "dolists.h"
2247 * We will need these for finding the windows installation
2248 * directory. Without that we can't find our fonts and
2249 * footprint libraries.
2252 #include <windows.h>
2264 tmps
= g_win32_get_package_installation_directory (PACKAGE
"-" VERSION
, NULL
);
2265 #define REST_OF_PATH G_DIR_SEPARATOR_S "share" G_DIR_SEPARATOR_S PACKAGE
2266 share_dir
= (char *) malloc(strlen(tmps
) +
2267 strlen(REST_OF_PATH
) +
2269 sprintf (share_dir
, "%s%s", tmps
, REST_OF_PATH
);
2272 printf ("\"Share\" installation path is \"%s\"\n", share_dir
);
2275 hid_register_hid (&ghid_hid
);
2276 apply_default_hid (&ghid_extents
, &ghid_hid
);
2277 #include "gtk_lists.h"