mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2025-01-03 22:00:14 +02: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:
parent
45ee739c3b
commit
6f30bab648
12
cameo/README
12
cameo/README
@ -88,6 +88,7 @@ Horizontal adjustments:
|
|||||||
align <ref> <x0> <y0> <x1> <y1>
|
align <ref> <x0> <y0> <x1> <y1>
|
||||||
array <x-step> <y-step> <x-index> <y-index>
|
array <x-step> <y-step> <x-index> <y-index>
|
||||||
translate <x> <y>
|
translate <x> <y>
|
||||||
|
rotate <angle>
|
||||||
reset
|
reset
|
||||||
|
|
||||||
"translate" shifts the currently loaded paths by the specified distance.
|
"translate" shifts the currently loaded paths by the specified distance.
|
||||||
@ -110,12 +111,19 @@ The reference point is specified with a number as follows:
|
|||||||
two arguments define the step between pieces while the second two
|
two arguments define the step between pieces while the second two
|
||||||
arguments define how many steps in each direction are taken.
|
arguments define how many steps in each direction are taken.
|
||||||
|
|
||||||
"align" sets moves the toolpath to an absolute position while "array" and
|
"align" moves the toolpath to an absolute position while "array" and
|
||||||
"translate" move relative to the current position. The total translation
|
"translate" move relative to the current position. The total translation
|
||||||
is remembered also across "clean", so that an alignment can be applied to
|
is remembered also across "clean", so that an alignment can be applied to
|
||||||
multiple toolpaths.
|
multiple toolpaths.
|
||||||
|
|
||||||
"reset" sets the translation to zero. The way "reset" is currently
|
"rotate" rotates the currenly loaded paths by the specified number of
|
||||||
|
degrees in a counter-clockwise direction. Like translations, rotations
|
||||||
|
are accumulated and are automatically applied to files loaded later.
|
||||||
|
Note that rotation is applied before translation. Therefore, using
|
||||||
|
"rotate" after "translate", "array", or "align" may yield unexpected
|
||||||
|
results.
|
||||||
|
|
||||||
|
"reset" sets translation and rotation to zero. The way "reset" is currently
|
||||||
implemented, it does not affect the currently loaded toolpath. (But it's
|
implemented, it does not affect the currently loaded toolpath. (But it's
|
||||||
better to use it only with "clean".)
|
better to use it only with "clean".)
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ NUM -?[0-9]+\.?[0-9]*
|
|||||||
<INITIAL>optimize return TOK_OPTIMIZE;
|
<INITIAL>optimize return TOK_OPTIMIZE;
|
||||||
<INITIAL>remainder return TOK_REMAINDER;
|
<INITIAL>remainder return TOK_REMAINDER;
|
||||||
<INITIAL>reset return TOK_RESET;
|
<INITIAL>reset return TOK_RESET;
|
||||||
|
<INITIAL>rotate return TOK_ROTATE;
|
||||||
<INITIAL>translate return TOK_TRANSLATE;
|
<INITIAL>translate return TOK_TRANSLATE;
|
||||||
<INITIAL>z return TOK_Z;
|
<INITIAL>z return TOK_Z;
|
||||||
|
|
||||||
|
38
cameo/lang.y
38
cameo/lang.y
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "ops.h"
|
#include "ops.h"
|
||||||
@ -23,7 +25,8 @@
|
|||||||
#include "y.tab.h"
|
#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 *paths = NULL;
|
||||||
static struct path *remain = 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)
|
static double ref_pick_1(int ref, double a, double b)
|
||||||
{
|
{
|
||||||
switch (ref) {
|
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_ALIGN TOK_ARRAY TOK_CLEAR TOK_DRILL TOK_EMPTY
|
||||||
%token TOK_MILL TOK_OFFSET TOK_OPTIMIZE TOK_REMAINDER TOK_RESET
|
%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_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE
|
||||||
%token TOK_DOG TOK_INSIDE
|
%token TOK_DOG TOK_INSIDE
|
||||||
|
|
||||||
@ -201,7 +225,7 @@ command:
|
|||||||
}
|
}
|
||||||
| TOK_RESET
|
| TOK_RESET
|
||||||
{
|
{
|
||||||
xo = yo = 0;
|
xo = yo = rot = 0;
|
||||||
}
|
}
|
||||||
| TOK_OFFSET offset_options
|
| TOK_OFFSET offset_options
|
||||||
{
|
{
|
||||||
@ -212,6 +236,11 @@ command:
|
|||||||
{
|
{
|
||||||
paths = optimize_paths(paths);
|
paths = optimize_paths(paths);
|
||||||
}
|
}
|
||||||
|
| TOK_ROTATE number
|
||||||
|
{
|
||||||
|
rotate(paths, $2);
|
||||||
|
rot += $2;
|
||||||
|
}
|
||||||
| TOK_TRANSLATE dimen dimen
|
| TOK_TRANSLATE dimen dimen
|
||||||
{
|
{
|
||||||
translate(paths, $2, $3, 0);
|
translate(paths, $2, $3, 0);
|
||||||
@ -231,6 +260,7 @@ command:
|
|||||||
struct path *new;
|
struct path *new;
|
||||||
|
|
||||||
new = gerber_read($3, $2/2);
|
new = gerber_read($3, $2/2);
|
||||||
|
rotate(new, rot);
|
||||||
translate(new, xo, yo, 0);
|
translate(new, xo, yo, 0);
|
||||||
add_paths(new);
|
add_paths(new);
|
||||||
}
|
}
|
||||||
@ -239,6 +269,7 @@ command:
|
|||||||
struct path *new;
|
struct path *new;
|
||||||
|
|
||||||
new = gnuplot_read($3, $2/2);
|
new = gnuplot_read($3, $2/2);
|
||||||
|
rotate(new, rot);
|
||||||
translate(new, xo, yo, 0);
|
translate(new, xo, yo, 0);
|
||||||
add_paths(new);
|
add_paths(new);
|
||||||
}
|
}
|
||||||
@ -247,6 +278,7 @@ command:
|
|||||||
struct path *new;
|
struct path *new;
|
||||||
|
|
||||||
new = excellon_read($2);
|
new = excellon_read($2);
|
||||||
|
rotate(new, rot);
|
||||||
translate(new, xo, yo, 0);
|
translate(new, xo, yo, 0);
|
||||||
add_paths(new);
|
add_paths(new);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user