r5331 - developers/werner/fped

werner at docs.openmoko.org werner at docs.openmoko.org
Tue Jul 28 21:50:12 CEST 2009


Author: werner
Date: 2009-07-28 21:50:12 +0200 (Tue, 28 Jul 2009)
New Revision: 5331

Added:
   developers/werner/fped/cpp.c
   developers/werner/fped/cpp.h
Modified:
   developers/werner/fped/Makefile
   developers/werner/fped/TODO
   developers/werner/fped/fpd.y
   developers/werner/fped/fped.c
   developers/werner/fped/gui_canvas.c
   developers/werner/fped/gui_inst.c
   developers/werner/fped/inst.c
   developers/werner/fped/qfn.fpd
Log:
- added continuous coordinate display and user coordinates
- corrected calculation of second angle in arc
- circles were stored and rendered incorrectly
- we now run CPP on the input file
- enabled more compiler warnings



Modified: developers/werner/fped/Makefile
===================================================================
--- developers/werner/fped/Makefile	2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/Makefile	2009-07-28 19:50:12 UTC (rev 5331)
@@ -1,12 +1,27 @@
-OBJS = fped.o expr.o coord.o obj.o inst.o util.o error.o lex.yy.o y.tab.o \
+#
+# Makefile - Makefile of fped, the footprint editor
+#
+# Written 2009 by Werner Almesberger
+# Copyright 2009 by Werner Almesberger
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+
+OBJS = fped.o expr.o coord.o obj.o inst.o util.o error.o \
+       cpp.o lex.yy.o y.tab.o \
        gui.o gui_style.o gui_inst.o gui_status.o gui_canvas.o
 
 CFLAGS_GTK = `pkg-config --cflags gtk+-2.0`
 LIBS_GTK = `pkg-config --libs gtk+-2.0`
 
-CFLAGS=-Wall -g $(CFLAGS_GTK)
-CFLAGS_LEX=-g
-CFLAGS_YACC=-g
+CFLAGS_WARN=-Wall -Wshadow -Wmissing-prototypes \
+            -Wmissing-declarations
+CFLAGS=-g $(CFLAGS_GTK) -DCPP='"cpp"' $(CFLAGS_WARN)
+SLOPPY=-Wno-unused -Wno-implicit-function-declaration -Wno-missing-prototypes \
+       -Wno-missing-declarations
 LDLIBS = -lm -lfl $(LIBS_GTK)
 YACC=bison -y
 YYFLAGS=-v
@@ -20,13 +35,13 @@
 		$(LEX) fpd.l
 
 lex.yy.o:	lex.yy.c y.tab.h
-		$(CC) -c $(CFLAGS_LEX) lex.yy.c
+		$(CC) -c $(CFLAGS) $(SLOPPY) lex.yy.c
 
 y.tab.c y.tab.h: fpd.y
 		$(YACC) $(YYFLAGS) -d fpd.y
 
 y.tab.o:	y.tab.c
-		$(CC) -c $(CFLAGS_YACC) y.tab.c
+		$(CC) -c $(CFLAGS) $(SLOPPY) y.tab.c
 
 # ----- Dependencies ----------------------------------------------------------
 

Modified: developers/werner/fped/TODO
===================================================================
--- developers/werner/fped/TODO	2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/TODO	2009-07-28 19:50:12 UTC (rev 5331)
@@ -8,9 +8,7 @@
 - stack elements (3): circle on top of vec
 - detect recursive evaluation (through variables)
 - eliminate duplicate instances
-- populate input area
-- bug: center moves in qfn.fpd
-- bug: pad and silk geometry doesn't match in qfn.fpd
+- populate input area (still needed: mm/mil, rezoom)
 - add vec editor
 - add obj editor
 - decide on table presentation
@@ -21,6 +19,8 @@
 - consider adding auto/mm/mil selection for each dimension
 - syntax seems a little cryptic. too many dots and at signs.
 - add measurements
-- add continuous coordinate display
-- add user coordinates. hide if inactive ?
 - arc syntax is weird, with comma where we use spaces
+- Q: allow reassignment of vector names ?
+- add KiCad output
+- add postscript output
+- add option to include/omit helper vecs and frames (display and postscript)

Added: developers/werner/fped/cpp.c
===================================================================
--- developers/werner/fped/cpp.c	                        (rev 0)
+++ developers/werner/fped/cpp.c	2009-07-28 19:50:12 UTC (rev 5331)
@@ -0,0 +1,217 @@
+/*
+ * cpp.c - CPP subprocess
+ *
+ * Written 2002-2004, 2006, 2008 by Werner Almesberger
+ * Copyright 2002, 2003 California Institute of Technology
+ * Copyright 2004, 2006 Werner Almesberger
+ * Copyright 2008 by OpenMoko, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "cpp.h"
+
+
+const char *cpp_command = CPP;
+
+static pid_t cpp_pid;
+static int cpp_argc = 0;
+static const char **cpp_argv = NULL;
+static int real_stdin = -1;
+
+
+void add_cpp_arg(const char *arg)
+{
+    if (!cpp_argc)
+	cpp_argc = 1;
+    cpp_argv = realloc(cpp_argv,sizeof(const char *)*(cpp_argc+1));
+    if (!cpp_argv) {
+	perror("realloc");
+	exit(1);
+    }
+    if (cpp_argc == 1)
+	cpp_argv[0] = cpp_command;
+    if (arg) {
+	arg = strdup(arg);
+	if (!arg) {
+	    perror("strdup");
+	    exit(1);
+	}
+    }
+    cpp_argv[cpp_argc++] = arg;
+}
+
+
+void add_cpp_Wp(const char *arg)
+{
+    char *tmp = strdup(arg);
+    char *curr,*end;
+
+    if (!tmp) {
+	perror("strdup");
+	exit(1);
+    }
+    curr = tmp;
+    do {
+	end = strchr(curr,',');
+	if (end)
+	    *end++ = 0;
+	add_cpp_arg(curr);
+	curr = end;
+    }
+    while (end);
+    free(tmp);
+}
+
+
+static void kill_cpp(void)
+{
+    if (cpp_pid)
+	(void) kill(cpp_pid,SIGTERM);
+}
+
+
+static void run_cpp(const char *name,int fd,int close_fd)
+{
+    char **arg;
+    int fds[2];
+
+    if (pipe(fds) < 0) {
+        perror("pipe");
+        exit(1);
+    }
+    if (name)
+	add_cpp_arg(name);
+    add_cpp_arg(NULL);
+    cpp_pid = fork();
+    if (cpp_pid < 0) {
+        perror("fork");
+        exit(1);
+    }
+    if (!cpp_pid) {
+	if (close(fds[0]) < 0) {
+	    perror("close");
+	    exit(1);
+	}
+	if (close_fd != -1 && close(close_fd) < 0) {
+	    perror("close");
+	    exit(1);
+	}
+	if (fd != -1 && dup2(fd,0) < 0) {
+	    perror("dup2");
+	    exit(1);
+	}
+	if (dup2(fds[1],1) < 0) {
+	    perror("dup2");
+	    exit(1);
+	}
+	if (execvp(cpp_command,(char **) cpp_argv) < 0) {
+	  /* prototype is weird */
+	    perror(cpp_command);
+	    exit(1);
+	}
+	/* not reached */
+    }
+    if (close(fds[1]) < 0) {
+	perror("close");
+	exit(1);
+    }
+    real_stdin = dup(0);
+    if (real_stdin < 0) {
+	perror("dup");
+	exit(1);
+    }
+    if (fd != -1 && close(fd) < 0) {
+	perror("close");
+	exit(1);
+    }
+    if (dup2(fds[0],0) < 0) {
+	perror("dup2");
+	exit(1);
+    }
+    for (arg = (char **) cpp_argv+1; *arg; arg++)
+	free(*arg);
+    free(cpp_argv);
+    cpp_argv = NULL;
+    cpp_argc = 0;
+}
+
+
+void run_cpp_on_file(const char *name)
+{
+    run_cpp(name,name ? -1 : 0,-1);
+    atexit(kill_cpp);
+}
+
+
+void run_cpp_on_string(const char *str)
+{
+    int fds[2];
+    pid_t pid;
+    int left,wrote;
+
+    if (pipe(fds) < 0) {
+        perror("pipe");
+        exit(1);
+    }
+    run_cpp(NULL,fds[0],fds[1]);
+    pid = fork();
+    if (pid < 0) {
+	perror("fork");
+	exit(1);
+    }
+    if (!pid) {
+	for (left = strlen(str); left; left -= wrote) {
+	    wrote = write(fds[1],str,left);
+	    if (wrote < 0)
+		break; /* die silently */
+	    str += wrote;
+	}
+	exit(0);
+    }
+    if (close(fds[1]) < 0) {
+	perror("close");
+	exit(1);
+    }
+    atexit(kill_cpp);
+}
+
+
+void reap_cpp(void)
+{
+    int status;
+
+    cpp_pid = 0;
+    if (waitpid(cpp_pid,&status,0) < 0) {
+	perror("waitpid");
+	exit(1);
+    }
+    if (!status) {
+	if (dup2(real_stdin,0) < 0) {
+	    perror("dup2");
+	    exit(1);
+	}
+	return;
+    }
+    if (WIFEXITED(status))
+	exit(WEXITSTATUS(status));
+    if (WIFSIGNALED(status))
+	fprintf(stderr,"cpp terminated with signal %d\n",WTERMSIG(status));
+    else
+	fprintf(stderr,"cpp terminated with incomprehensible status %d\n",
+	  status);
+    exit(1);
+}

Added: developers/werner/fped/cpp.h
===================================================================
--- developers/werner/fped/cpp.h	                        (rev 0)
+++ developers/werner/fped/cpp.h	2009-07-28 19:50:12 UTC (rev 5331)
@@ -0,0 +1,26 @@
+/*
+ * cpp.h - CPP subprocess
+ *
+ * Written 2002, 2003, 2008 by Werner Almesberger
+ * Copyright 2002, 2003 Caltech Netlab FAST project
+ * Copyright 2008 by OpenMoko, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef CPP_H
+#define CPP_H
+
+
+extern const char *cpp_command;
+
+void add_cpp_arg(const char *arg);
+void add_cpp_Wp(const char *arg);
+void run_cpp_on_file(const char *name); /* NULL for stdin */
+void run_cpp_on_string(const char *str);
+void reap_cpp(void);
+
+#endif /* CPP_H */

Modified: developers/werner/fped/fpd.y
===================================================================
--- developers/werner/fped/fpd.y	2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/fpd.y	2009-07-28 19:50:12 UTC (rev 5331)
@@ -356,7 +356,7 @@
 			$$ = new_obj(ot_arc);
 			$$->base = $2;
 			$$->u.arc.start = $3;
-			$$->u.arc.end = $3;
+			$$->u.arc.end = $4 ? $4 : $3;
 		}
 	| TOK_FRAME ID base
 		{

Modified: developers/werner/fped/fped.c
===================================================================
--- developers/werner/fped/fped.c	2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/fped.c	2009-07-28 19:50:12 UTC (rev 5331)
@@ -11,13 +11,8 @@
  */
 
 
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
 
-
+#include "cpp.h"
 #include "obj.h"
 #include "inst.h"
 #include "gui.h"
@@ -28,17 +23,7 @@
 
 static void load_file(const char *name)
 {
-	int fd;
-
-	fd = open(name, O_RDONLY);
-	if (fd < 0) {
-		perror(name);
-		exit(1);
-	}
-	if (dup2(fd, 0) < 0) {
-		perror("dup2");
-		exit(1);
-	}
+	run_cpp_on_file(name);
 	(void) yyparse();
 }
 

Modified: developers/werner/fped/gui_canvas.c
===================================================================
--- developers/werner/fped/gui_canvas.c	2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/gui_canvas.c	2009-07-28 19:50:12 UTC (rev 5331)
@@ -20,12 +20,15 @@
 #include "gui_style.h"
 #include "gui_status.h"
 #include "gui.h"
+#include "gui_canvas.h"
 
 
 static struct draw_ctx ctx;
+static struct coord curr_pos;
+static struct coord user_origin = { 0, 0 };
 
 
-/* ----- zoom display ------------------------------------------------------ */
+/* ----- status display ---------------------------------------------------- */
 
 
 static void update_zoom(void)
@@ -34,6 +37,15 @@
 }
 
 
+static void update_pos(struct coord pos)
+{
+	status_set_sys_pos("%5.2lf %5.2lf mm",
+	    units_to_mm(pos.x), units_to_mm(pos.y));
+	status_set_user_pos("%5.2lf %5.2lf mm",
+	    units_to_mm(pos.x-user_origin.x), units_to_mm(pos.y-user_origin.y));
+}
+
+
 /* ----- coordinate system ------------------------------------------------- */
 
 
@@ -106,10 +118,13 @@
 {
 	struct coord pos = canvas_to_coord(&ctx, event->x, event->y);
 
+	curr_pos.x = event->x;
+	curr_pos.y = event->y;
 	if (event->state & GDK_BUTTON1_MASK)
 		drag_left(pos);
 	if (event->state & GDK_BUTTON2_MASK)
 		drag_middle(pos);
+	update_pos(pos);
 	return TRUE;
 }
 
@@ -125,6 +140,7 @@
 	switch (event->button) {
 	case 1:
 		/* select */ ;
+		break;
 	case 2:
 		ctx.center = pos;
 		redraw();
@@ -137,7 +153,6 @@
 static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
      gpointer data)
 {
-printf("R %d\n", event->button);
 	return TRUE;
 }
 
@@ -195,6 +210,24 @@
 }
 
 
+/* ----- keys -------------------------------------------------------------- */
+
+
+static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
+     gpointer data)
+{
+	struct coord pos = canvas_to_coord(&ctx, curr_pos.x, curr_pos.y);
+
+	switch (event->keyval) {
+	case ' ':
+		user_origin = pos;
+		update_pos(pos);
+		break;
+	}
+	return TRUE;
+}
+
+
 /* ----- expose event ------------------------------------------------------ */
 
 
@@ -216,6 +249,24 @@
 }
 
 
+/* ----- enter/leave ------------------------------------------------------- */
+
+
+static gboolean enter_notify_event(GtkWidget *widget, GdkEventCrossing *event,
+     gpointer data)
+{
+	gtk_widget_grab_focus(widget);
+	return TRUE;
+}
+
+
+static gboolean leave_notify_event(GtkWidget *widget, GdkEventCrossing *event,
+     gpointer data)
+{
+	return TRUE;
+}
+
+
 /* ----- canvas setup ------------------------------------------------------ */
 
 
@@ -239,11 +290,21 @@
 	g_signal_connect(G_OBJECT(canvas), "scroll_event",
 	    G_CALLBACK(scroll_event), NULL);
 
+	GTK_WIDGET_SET_FLAGS(canvas, GTK_CAN_FOCUS);
+
+	g_signal_connect(G_OBJECT(canvas), "key_press_event",
+	    G_CALLBACK(key_press_event), NULL);
+
 	g_signal_connect(G_OBJECT(canvas), "expose_event",
 	    G_CALLBACK(expose_event), NULL);
+	g_signal_connect(G_OBJECT(canvas), "enter_notify_event",
+	    G_CALLBACK(enter_notify_event), NULL);
+	g_signal_connect(G_OBJECT(canvas), "leave_notify_event",
+	    G_CALLBACK(leave_notify_event), NULL);
 
 	gtk_widget_set_events(canvas,
-	    GDK_EXPOSE | GDK_LEAVE_NOTIFY_MASK |
+	    GDK_EXPOSE | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
+	    GDK_KEY_PRESS_MASK |
 	    GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
 	    GDK_SCROLL |
 	    GDK_POINTER_MOTION_MASK);

Modified: developers/werner/fped/gui_inst.c
===================================================================
--- developers/werner/fped/gui_inst.c	2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/gui_inst.c	2009-07-28 19:50:12 UTC (rev 5331)
@@ -56,7 +56,9 @@
 static void draw_arc(struct draw_ctx *ctx, GdkGC *gc, int fill,
     int x, int y, int r, double a1, double a2)
 {
-	gdk_draw_arc(DA, gc, fill, x-r, y-r, 2*r, 2*r, a1*64, a2*64);
+	if (a1 == a2)
+		a2 = a1+360;
+	gdk_draw_arc(DA, gc, fill, x-r, y-r, 2*r, 2*r, a1*64, (a2-a1)*64);
 }
 
 

Modified: developers/werner/fped/inst.c
===================================================================
--- developers/werner/fped/inst.c	2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/inst.c	2009-07-28 19:50:12 UTC (rev 5331)
@@ -199,13 +199,13 @@
 	double r, a1, a2;
 
 	inst = add_inst(&arc_ops, center);
-	r =hypot(start.x-center.x, start.y-center.y);
+	r = hypot(start.x-center.x, start.y-center.y);
 	a1 = atan2(start.y-center.y, start.x-center.x)/M_PI*180.0;
 	a2 = atan2(end.y-center.y, end.x-center.x)/M_PI*180.0;
 	if (a1 < 0)
 		a1 += 360.0;
 	if (a2 < 0)
-		a2 += 2*M_PI;
+		a2 += 360.0;
 	inst->u.arc.r = r;
 	inst->u.arc.a1 = a1;
 	inst->u.arc.a2 = a2;

Modified: developers/werner/fped/qfn.fpd
===================================================================
--- developers/werner/fped/qfn.fpd	2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/qfn.fpd	2009-07-28 19:50:12 UTC (rev 5331)
@@ -32,3 +32,6 @@
 r = .vec c 0mm, 0.5mm
 e = .vec c -0.5mm, 0mm
 .arc c r, e
+
+r2 = .vec c 0mm, 0.8mm
+.arc c r2




More information about the commitlog mailing list