initial support (disabled) for keepout regions in IDF files.

pull/753/head
phkahler 2020-10-19 13:57:37 -04:00
parent b12bcc5889
commit b28499ea48
1 changed files with 59 additions and 38 deletions

View File

@ -236,18 +236,15 @@ static void MakeBeziersForArcs(SBezierList *sbl, Vector center, Vector pa, Vecto
Vector u = q.RotationU(), v = q.RotationV(); Vector u = q.RotationU(), v = q.RotationV();
double r = pa.Minus(center).Magnitude(); double r = pa.Minus(center).Magnitude();
double thetaa, thetab, dtheta; double theta, dtheta;
if(angle == 360.0) { if(angle == 360.0) {
thetaa = 0; theta = 0;
thetab = 2*PI;
} else { } else {
Point2d c2 = center.Project2d(u, v); Point2d c2 = center.Project2d(u, v);
Point2d pa2 = (pa.Project2d(u, v)).Minus(c2); Point2d pa2 = (pa.Project2d(u, v)).Minus(c2);
Point2d pb2 = (pb.Project2d(u, v)).Minus(c2);
thetaa = atan2(pa2.y, pa2.x); theta = atan2(pa2.y, pa2.x);
thetab = atan2(pb2.y, pb2.x);
} }
dtheta = angle * PI/180; dtheta = angle * PI/180;
@ -266,17 +263,17 @@ static void MakeBeziersForArcs(SBezierList *sbl, Vector center, Vector pa, Vecto
for(i = 0; i < n; i++) { for(i = 0; i < n; i++) {
double s, c; double s, c;
c = cos(thetaa); c = cos(theta);
s = sin(thetaa); s = sin(theta);
// The start point of the curve, and the tangent vector at // The start point of the curve, and the tangent vector at
// that start point. // that start point.
Vector p0 = center.Plus(u.ScaledBy( r*c)).Plus(v.ScaledBy(r*s)), Vector p0 = center.Plus(u.ScaledBy( r*c)).Plus(v.ScaledBy(r*s)),
t0 = u.ScaledBy(-r*s). Plus(v.ScaledBy(r*c)); t0 = u.ScaledBy(-r*s). Plus(v.ScaledBy(r*c));
thetaa += dtheta; theta += dtheta;
c = cos(thetaa); c = cos(theta);
s = sin(thetaa); s = sin(theta);
Vector p2 = center.Plus(u.ScaledBy( r*c)).Plus(v.ScaledBy(r*s)), Vector p2 = center.Plus(u.ScaledBy( r*c)).Plus(v.ScaledBy(r*s)),
t2 = u.ScaledBy(-r*s). Plus(v.ScaledBy(r*c)); t2 = u.ScaledBy(-r*s). Plus(v.ScaledBy(r*c));
@ -335,6 +332,7 @@ bool LinkIDF(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s
double board_thickness = 10.0; double board_thickness = 10.0;
double scale = 1.0; //mm double scale = 1.0; //mm
bool topEntities, bottomEntities;
Quaternion normal = Quaternion::From(Vector::From(1,0,0), Vector::From(0,1,0)); Quaternion normal = Quaternion::From(Vector::From(1,0,0), Vector::From(0,1,0));
hEntity hnorm = newNormal(el, &entityCount, normal); hEntity hnorm = newNormal(el, &entityCount, normal);
@ -347,6 +345,7 @@ bool LinkIDF(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s
for(std::string line; getline( stream, line ); ) { for(std::string line; getline( stream, line ); ) {
if (line.find(".END_") == 0) { if (line.find(".END_") == 0) {
section = none; section = none;
curve = -1;
} }
switch (section) { switch (section) {
case none: case none:
@ -356,6 +355,10 @@ bool LinkIDF(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s
} else if (line.find(".BOARD_OUTLINE") == 0) { } else if (line.find(".BOARD_OUTLINE") == 0) {
section = board_outline; section = board_outline;
record_number = 1; record_number = 1;
// no keepouts for now - they should also be shown as construction?
// } else if (line.find(".ROUTE_KEEPOUT") == 0) {
// section = routing_keepout;
// record_number = 1;
} else if(line.find(".DRILLED_HOLES") == 0) { } else if(line.find(".DRILLED_HOLES") == 0) {
section = drilled_holes; section = drilled_holes;
record_number = 1; record_number = 1;
@ -376,10 +379,22 @@ bool LinkIDF(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s
} }
break; break;
case routing_keepout:
case board_outline: case board_outline:
if (record_number == 2) { if (record_number == 2) {
if(section == board_outline) {
topEntities = true;
bottomEntities = true;
board_thickness = std::stod(line) * scale; board_thickness = std::stod(line) * scale;
dbp("IDF board thickness: %lf", board_thickness); dbp("IDF board thickness: %lf", board_thickness);
} else if (section == routing_keepout) {
topEntities = false;
bottomEntities = false;
if(line.find("TOP") == 0 || line.find("BOTH") == 0)
topEntities = true;
if(line.find("BOTTOM") == 0 || line.find("BOTH") == 0)
bottomEntities = true;
}
} else { // records 3+ are lines, arcs, and circles } else { // records 3+ are lines, arcs, and circles
std::vector <std::string> values = splitString(line); std::vector <std::string> values = splitString(line);
if(values.size() != 4) continue; if(values.size() != 4) continue;
@ -391,11 +406,14 @@ bool LinkIDF(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s
Vector pTop = Vector::From(x,y,board_thickness); Vector pTop = Vector::From(x,y,board_thickness);
if(c != curve) { // start a new curve if(c != curve) { // start a new curve
curve = c; curve = c;
if (bottomEntities)
hprev = newPoint(el, &entityCount, point, /*visible=*/false); hprev = newPoint(el, &entityCount, point, /*visible=*/false);
if (topEntities)
hprevTop = newPoint(el, &entityCount, pTop, /*visible=*/false); hprevTop = newPoint(el, &entityCount, pTop, /*visible=*/false);
pprev = point; pprev = point;
pprevTop = pTop; pprevTop = pTop;
} else { } else {
if(section == board_outline) {
// create a bezier for the extrusion // create a bezier for the extrusion
if (ang == 0) { if (ang == 0) {
// straight lines // straight lines
@ -409,18 +427,22 @@ bool LinkIDF(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s
// circles // circles
MakeBeziersForArcs(&sbl, point, pprev, pprev, normal, ang); MakeBeziersForArcs(&sbl, point, pprev, pprev, normal, ang);
} }
}
// next create the entities // next create the entities
// only curves and points at circle centers will be visible // only curves and points at circle centers will be visible
bool vis = (ang == 360.0); bool vis = (ang == 360.0);
if (bottomEntities) {
hEntity hp = newPoint(el, &entityCount, point, /*visible=*/vis); hEntity hp = newPoint(el, &entityCount, point, /*visible=*/vis);
CreateEntity(el, &entityCount, hprev, hp, hnorm, pprev, point, ang); CreateEntity(el, &entityCount, hprev, hp, hnorm, pprev, point, ang);
pprev = point; pprev = point;
hprev = hp; hprev = hp;
hp = newPoint(el, &entityCount, pTop, /*visible=*/vis); }
if (topEntities) {
hEntity hp = newPoint(el, &entityCount, pTop, /*visible=*/vis);
CreateEntity(el, &entityCount, hprevTop, hp, hnorm, pprevTop, pTop, ang); CreateEntity(el, &entityCount, hprevTop, hp, hnorm, pprevTop, pTop, ang);
pprevTop = pTop; pprevTop = pTop;
hprevTop = hp; hprevTop = hp;
}
} }
} }
break; break;
@ -428,7 +450,6 @@ bool LinkIDF(const Platform::Path &filename, EntityList *el, SMesh *m, SShell *s
case other_outline: case other_outline:
case routing_outline: case routing_outline:
case placement_outline: case placement_outline:
case routing_keepout:
case via_keepout: case via_keepout:
case placement_group: case placement_group:
break; break;