mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2025-04-21 12:27:27 +03:00
cameo: added "rotate" command
- lang.l, lang.y (rotate): added command "rotate", with cumulative rotation - README: documented "rotate" - README: corrected typo in description of the translation commands
This commit is contained in:
38
cameo/lang.y
38
cameo/lang.y
@@ -13,6 +13,8 @@
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "path.h"
|
||||
#include "ops.h"
|
||||
@@ -23,7 +25,8 @@
|
||||
#include "y.tab.h"
|
||||
|
||||
|
||||
static double xo = 0, yo = 0, zo = 0;
|
||||
static double xo = 0, yo = 0, zo = 0; /* origin */
|
||||
static double rot = 0;
|
||||
static struct path *paths = NULL;
|
||||
static struct path *remain = NULL;
|
||||
|
||||
@@ -55,6 +58,27 @@ static void translate(struct path *list, double x, double y, double z)
|
||||
}
|
||||
|
||||
|
||||
static void rotate(struct path *list, double angle)
|
||||
{
|
||||
double m[2][2], tmp;
|
||||
struct point *p;
|
||||
|
||||
angle = angle/180.0*M_PI;
|
||||
m[0][0] = cos(angle);
|
||||
m[0][1] = -sin(angle);
|
||||
m[1][0] = -m[0][1];
|
||||
m[1][1] = m[0][0];
|
||||
while (list) {
|
||||
for (p = list->first; p; p = p->next) {
|
||||
tmp = p->x*m[0][0]+p->y*m[0][1];
|
||||
p->y = p->x*m[1][0]+p->y*m[1][1];
|
||||
p->x = tmp;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static double ref_pick_1(int ref, double a, double b)
|
||||
{
|
||||
switch (ref) {
|
||||
@@ -151,7 +175,7 @@ static struct path **classify(struct path **anchor, struct path *path)
|
||||
|
||||
%token TOK_ALIGN TOK_ARRAY TOK_CLEAR TOK_DRILL TOK_EMPTY
|
||||
%token TOK_MILL TOK_OFFSET TOK_OPTIMIZE TOK_REMAINDER TOK_RESET
|
||||
%token TOK_TRANSLATE TOK_Z
|
||||
%token TOK_ROTATE TOK_TRANSLATE TOK_Z
|
||||
%token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE
|
||||
%token TOK_DOG TOK_INSIDE
|
||||
|
||||
@@ -201,7 +225,7 @@ command:
|
||||
}
|
||||
| TOK_RESET
|
||||
{
|
||||
xo = yo = 0;
|
||||
xo = yo = rot = 0;
|
||||
}
|
||||
| TOK_OFFSET offset_options
|
||||
{
|
||||
@@ -212,6 +236,11 @@ command:
|
||||
{
|
||||
paths = optimize_paths(paths);
|
||||
}
|
||||
| TOK_ROTATE number
|
||||
{
|
||||
rotate(paths, $2);
|
||||
rot += $2;
|
||||
}
|
||||
| TOK_TRANSLATE dimen dimen
|
||||
{
|
||||
translate(paths, $2, $3, 0);
|
||||
@@ -231,6 +260,7 @@ command:
|
||||
struct path *new;
|
||||
|
||||
new = gerber_read($3, $2/2);
|
||||
rotate(new, rot);
|
||||
translate(new, xo, yo, 0);
|
||||
add_paths(new);
|
||||
}
|
||||
@@ -239,6 +269,7 @@ command:
|
||||
struct path *new;
|
||||
|
||||
new = gnuplot_read($3, $2/2);
|
||||
rotate(new, rot);
|
||||
translate(new, xo, yo, 0);
|
||||
add_paths(new);
|
||||
}
|
||||
@@ -247,6 +278,7 @@ command:
|
||||
struct path *new;
|
||||
|
||||
new = excellon_read($2);
|
||||
rotate(new, rot);
|
||||
translate(new, xo, yo, 0);
|
||||
add_paths(new);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user