1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-08-23 00:43:41 +03:00

sch2fig/: support arcs

This commit is contained in:
Werner Almesberger 2016-07-25 02:59:33 -03:00
parent e37765fd12
commit b903f53c3f
3 changed files with 90 additions and 11 deletions

View File

@ -341,7 +341,7 @@ void fig_poly(int points, int x[points], int y[points],
void fig_circ(int x, int y, int r, int color, int fill_color, unsigned layer)
{
// Type Thick Depth StyleV Cx Rx Sx Ex
// Type Thick Depth StyleV Cx Rx Sx Ex
// SubTy Color Pen Dir Cy Ry Sy Ey
// Style FillCol AreaFil Angle
printf("1 3 0 %d %d %d %d -1 %d 0.0 1 0.0 %d %d %d %d %d %d %d %d\n",
@ -352,6 +352,41 @@ void fig_circ(int x, int y, int r, int color, int fill_color, unsigned layer)
}
static int ax(int x, int y, int r, int angle)
{
float a = angle / 180.0 * M_PI;
return cx(x + r * cos(a));
}
static int ay(int x, int y, int r, int angle)
{
float a = angle / 180.0 * M_PI;
return cy(y - r * sin(a));
}
void fig_arc(int x, int y, int r, int sa, int ea,
int color, int fill_color, unsigned layer)
{
int ma = (sa + ea) / 2;
// Type Thick Depth StyleV FwdAr
// SubTy Color Pen Cap BwdAr
// Style FillCol AreaFil Dir points
printf("5 1 0 %d %d %d %d -1 %d 0.0 1 0 0 0 %d %d %d %d %d %d %d %d\n",
color == -1 ? 0 : WIDTH_COMP_DWG, color, fill_color, layer,
fill_color == -1 ? -1 : 20,
cx(x), cy(y),
ax(x, y, r, sa), ay(x, y, r, sa),
ax(x, y, r, ma), ay(x, y, r, ma),
ax(x, y, r, ea), ay(x, y, r, ea));
/* @@@ Note: with y flipped, we counter-clockwise becomes clockwise */
}
void fig_text(int x, int y, const char *s, unsigned size,
enum text_align align, int rot, unsigned color, unsigned layer)
{

View File

@ -46,6 +46,8 @@ void fig_rect(int sx, int sy, int ex, int ey,
void fig_poly(int points, int x[points], int y[points],
int color, int fill_color, unsigned layer);
void fig_circ(int x, int y, int r, int color, int fill_color, unsigned layer);
void fig_arc(int x, int y, int r, int sa, int ea,
int color, int fill_color, unsigned layer);
void fig_text(int x, int y, const char *s, unsigned size,
enum text_align align, int rot, unsigned color, unsigned layer);

View File

@ -14,6 +14,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include "util.h"
@ -59,6 +60,13 @@ struct obj {
int thick;
char fill;
} circ;
struct arc_obj {
int x, y;
int r;
int start_a, end_a;
int thick;
char fill;
} arc;
struct text_obj {
int orient;
int x, y;
@ -188,6 +196,21 @@ static void draw_circ(const struct circ_obj *circ, int m[6])
}
static void draw_arc(const struct arc_obj *arc, int m[6])
{
int a = matrix_to_angle(m);
int x = mx(arc->x, arc->y, m);
int y = my(arc->x, arc->y, m);
int sa = angle_add(arc->start_a, a);
int ea = angle_add(arc->end_a, a);
fig_arc(x, y, arc->r, sa, ea,
COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
assert(arc->fill == 'N');
}
static void draw_pin(const struct comp *comp, const struct pin_obj *pin,
int m[6])
{
@ -314,7 +337,7 @@ static void draw(const struct comp *comp, const struct obj *obj, int m[6])
draw_circ(&obj->u.circ, m);
break;
case obj_arc:
unsupported("arc");
draw_arc(&obj->u.arc, m);
break;
case obj_text:
draw_text(&obj->u.text, m);
@ -372,20 +395,20 @@ static enum text_style decode_style(const char *s)
/* ----- Polygons ---------------------------------------------------------- */
static bool parse_poly(struct obj *obj, const char *line, int points)
static bool parse_poly(struct poly_obj *poly, const char *line, int points)
{
int i, n;
obj->u.poly.points = points;
obj->u.poly.x = alloc_size(sizeof(int) * points);
obj->u.poly.y = alloc_size(sizeof(int) * points);
poly->points = points;
poly->x = alloc_size(sizeof(int) * points);
poly->y = alloc_size(sizeof(int) * points);
for (i = 0; i != points; i++) {
if (sscanf(line, "%d %d %n",
obj->u.poly.x + i, obj->u.poly.y + i, &n) != 2)
poly->x + i, poly->y + i, &n) != 2)
return 0;
line += n;
}
if (sscanf(line, "%c", &obj->u.poly.fill) != 1)
if (sscanf(line, "%c", &poly->fill) != 1)
return 0;
return 1;
}
@ -425,6 +448,25 @@ static bool parse_def(const char *line)
}
/* ----- Arcs -------------------------------------------------------------- */
static bool parse_arc(struct obj *obj, const char *line)
{
struct arc_obj *arc = &obj->u.arc;
int a1, a2;
if (sscanf(line, "A %d %d %d %d %d %u %u %u %c",
&arc->x, &arc->y, &arc->r, &a1, &a2, &obj->unit, &obj->convert,
&arc->thick, &arc->fill) != 9)
return 0;
arc->start_a = a1 / 10;
arc->end_a = a2 / 10;
return 1;
}
/* ----- Library parser ---------------------------------------------------- */
@ -475,7 +517,7 @@ bool lib_parse(struct lib_ctx *ctx, const char *line)
&points, &obj->unit, &obj->convert, &obj->u.poly.thick,
&n) == 4) {
obj->type = obj_poly;
if (parse_poly(obj, line + n, points))
if (parse_poly(&obj->u.poly, line + n, points))
return 1;
break;
}
@ -493,9 +535,9 @@ bool lib_parse(struct lib_ctx *ctx, const char *line)
obj->type = obj_circ;
return 1;
}
if (sscanf(line, "A %n", &n) == 0 && n) {
if (parse_arc(obj, line)) {
obj->type = obj_arc;
return 1; // @@@
return 1;
}
n = sscanf(line,
"T %d %d %d %d %u %u %u \"%m[^\"]\" %ms %u %c %c",