Assemble the group polygon ourselves when exporting a DXF; that
lets us export open curves, if the user drew them that way. Also increase the limits on how many pwls we will generate for a single curve. [git-p4: depot-paths = "//depot/solvespace/": change = 1854]
This commit is contained in:
parent
0c10efdab6
commit
22b78e4427
@ -155,9 +155,9 @@ void Entity::BezierPwl(double ta, double tb,
|
|||||||
double d = max(pm1.DistanceToLine(pa, pb.Minus(pa)),
|
double d = max(pm1.DistanceToLine(pa, pb.Minus(pa)),
|
||||||
pm2.DistanceToLine(pa, pb.Minus(pa)));
|
pm2.DistanceToLine(pa, pb.Minus(pa)));
|
||||||
|
|
||||||
double tol = 0.5*SS.chordTol/SS.GW.scale;
|
double tol = SS.chordTol/SS.GW.scale;
|
||||||
|
|
||||||
if((tb - ta) < 0.05 || d < tol) {
|
if((tb - ta) < 0.01 || d < tol) {
|
||||||
LineDrawOrGetDistanceOrEdge(pa, pb);
|
LineDrawOrGetDistanceOrEdge(pa, pb);
|
||||||
} else {
|
} else {
|
||||||
double tm = (ta + tb) / 2;
|
double tm = (ta + tb) / 2;
|
||||||
|
28
export.cpp
28
export.cpp
@ -2,9 +2,8 @@
|
|||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
void SolveSpace::ExportDxfTo(char *filename) {
|
void SolveSpace::ExportDxfTo(char *filename) {
|
||||||
SPolygon *sp;
|
SPolygon sp;
|
||||||
SPolygon spa;
|
ZERO(&sp);
|
||||||
ZERO(&spa);
|
|
||||||
|
|
||||||
Vector gn = (SS.GW.projRight).Cross(SS.GW.projUp);
|
Vector gn = (SS.GW.projRight).Cross(SS.GW.projUp);
|
||||||
gn = gn.WithMagnitude(1);
|
gn = gn.WithMagnitude(1);
|
||||||
@ -19,17 +18,21 @@ void SolveSpace::ExportDxfTo(char *filename) {
|
|||||||
Vector p, u, v, n;
|
Vector p, u, v, n;
|
||||||
double d;
|
double d;
|
||||||
|
|
||||||
if(gs.n == 0 && !(g->poly.IsEmpty())) {
|
// Don't use the assembled polygon from the group data structure; that
|
||||||
|
// one gets cleared if the curves aren't all closed.
|
||||||
|
g->AssemblePolygon(&sp, NULL);
|
||||||
|
|
||||||
|
if(gs.n == 0 && !(sp.IsEmpty())) {
|
||||||
// Easiest case--export the polygon drawn in this group
|
// Easiest case--export the polygon drawn in this group
|
||||||
sp = &(g->poly);
|
p = sp.AnyPoint();
|
||||||
p = sp->AnyPoint();
|
n = (sp.ComputeNormal()).WithMagnitude(1);
|
||||||
n = (sp->ComputeNormal()).WithMagnitude(1);
|
|
||||||
if(n.Dot(gn) < 0) n = n.ScaledBy(-1);
|
if(n.Dot(gn) < 0) n = n.ScaledBy(-1);
|
||||||
u = n.Normal(0);
|
u = n.Normal(0);
|
||||||
v = n.Normal(1);
|
v = n.Normal(1);
|
||||||
d = p.Dot(n);
|
d = p.Dot(n);
|
||||||
goto havepoly;
|
goto havepoly;
|
||||||
}
|
}
|
||||||
|
sp.Clear();
|
||||||
|
|
||||||
if(g->runningMesh.l.n > 0 &&
|
if(g->runningMesh.l.n > 0 &&
|
||||||
((gs.n == 0 && g->activeWorkplane.v != Entity::FREE_IN_3D.v) ||
|
((gs.n == 0 && g->activeWorkplane.v != Entity::FREE_IN_3D.v) ||
|
||||||
@ -93,8 +96,7 @@ void SolveSpace::ExportDxfTo(char *filename) {
|
|||||||
SEdgeList el;
|
SEdgeList el;
|
||||||
ZERO(&el);
|
ZERO(&el);
|
||||||
root->MakeCertainEdgesInto(&el, false);
|
root->MakeCertainEdgesInto(&el, false);
|
||||||
el.AssemblePolygon(&spa, NULL);
|
el.AssemblePolygon(&sp, NULL);
|
||||||
sp = &spa;
|
|
||||||
|
|
||||||
el.Clear();
|
el.Clear();
|
||||||
m.Clear();
|
m.Clear();
|
||||||
@ -111,7 +113,7 @@ havepoly:
|
|||||||
FILE *f = fopen(filename, "wb");
|
FILE *f = fopen(filename, "wb");
|
||||||
if(!f) {
|
if(!f) {
|
||||||
Error("Couldn't write to '%s'", filename);
|
Error("Couldn't write to '%s'", filename);
|
||||||
spa.Clear();
|
sp.Clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,8 +161,8 @@ havepoly:
|
|||||||
"ENTITIES\r\n");
|
"ENTITIES\r\n");
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
for(i = 0; i < sp->l.n; i++) {
|
for(i = 0; i < sp.l.n; i++) {
|
||||||
SContour *sc = &(sp->l.elem[i]);
|
SContour *sc = &(sp.l.elem[i]);
|
||||||
|
|
||||||
for(j = 1; j < sc->l.n; j++) {
|
for(j = 1; j < sc->l.n; j++) {
|
||||||
Vector p0 = sc->l.elem[j-1].p,
|
Vector p0 = sc->l.elem[j-1].p,
|
||||||
@ -200,7 +202,7 @@ havepoly:
|
|||||||
" 0\r\n"
|
" 0\r\n"
|
||||||
"EOF\r\n" );
|
"EOF\r\n" );
|
||||||
|
|
||||||
spa.Clear();
|
sp.Clear();
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,22 +2,27 @@
|
|||||||
|
|
||||||
#define gs (SS.GW.gs)
|
#define gs (SS.GW.gs)
|
||||||
|
|
||||||
|
bool Group::AssemblePolygon(SPolygon *p, SEdge *error) {
|
||||||
|
SEdgeList edges; ZERO(&edges);
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < SS.entity.n; i++) {
|
||||||
|
Entity *e = &(SS.entity.elem[i]);
|
||||||
|
if(e->group.v != h.v) continue;
|
||||||
|
|
||||||
|
e->GenerateEdges(&edges);
|
||||||
|
}
|
||||||
|
bool ret = edges.AssemblePolygon(p, error);
|
||||||
|
edges.Clear();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void Group::GeneratePolygon(void) {
|
void Group::GeneratePolygon(void) {
|
||||||
poly.Clear();
|
poly.Clear();
|
||||||
|
|
||||||
if(type == DRAWING_3D || type == DRAWING_WORKPLANE ||
|
if(type == DRAWING_3D || type == DRAWING_WORKPLANE ||
|
||||||
type == ROTATE || type == TRANSLATE)
|
type == ROTATE || type == TRANSLATE)
|
||||||
{
|
{
|
||||||
SEdgeList edges; ZERO(&edges);
|
if(AssemblePolygon(&poly, &(polyError.notClosedAt))) {
|
||||||
int i;
|
|
||||||
for(i = 0; i < SS.entity.n; i++) {
|
|
||||||
Entity *e = &(SS.entity.elem[i]);
|
|
||||||
if(e->group.v != h.v) continue;
|
|
||||||
|
|
||||||
e->GenerateEdges(&edges);
|
|
||||||
}
|
|
||||||
SEdge error;
|
|
||||||
if(edges.AssemblePolygon(&poly, &error)) {
|
|
||||||
polyError.how = POLY_GOOD;
|
polyError.how = POLY_GOOD;
|
||||||
poly.normal = poly.ComputeNormal();
|
poly.normal = poly.ComputeNormal();
|
||||||
poly.FixContourDirections();
|
poly.FixContourDirections();
|
||||||
@ -29,10 +34,8 @@ void Group::GeneratePolygon(void) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
polyError.how = POLY_NOT_CLOSED;
|
polyError.how = POLY_NOT_CLOSED;
|
||||||
polyError.notClosedAt = error;
|
|
||||||
poly.Clear();
|
poly.Clear();
|
||||||
}
|
}
|
||||||
edges.Clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
sketch.h
1
sketch.h
@ -197,6 +197,7 @@ public:
|
|||||||
void GenerateEquations(IdList<Equation,hEquation> *l);
|
void GenerateEquations(IdList<Equation,hEquation> *l);
|
||||||
|
|
||||||
// Assembling piecewise linear sections into polygons
|
// Assembling piecewise linear sections into polygons
|
||||||
|
bool AssemblePolygon(SPolygon *p, SEdge *error);
|
||||||
void GeneratePolygon(void);
|
void GeneratePolygon(void);
|
||||||
// And the mesh stuff
|
// And the mesh stuff
|
||||||
SMesh *PreviousGroupMesh(void);
|
SMesh *PreviousGroupMesh(void);
|
||||||
|
@ -129,7 +129,7 @@ int SolveSpace::CircleSides(double r) {
|
|||||||
double tol = chordTol/GW.scale;
|
double tol = chordTol/GW.scale;
|
||||||
int n = 3 + (int)(PI/sqrt(2*tol/r));
|
int n = 3 + (int)(PI/sqrt(2*tol/r));
|
||||||
|
|
||||||
return max(7, min(n, 40));
|
return max(7, min(n, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SolveSpace::MmToString(double v) {
|
char *SolveSpace::MmToString(double v) {
|
||||||
|
4
ttf.cpp
4
ttf.cpp
@ -704,9 +704,9 @@ void TtfFont::BezierPwl(double ta, double tb, Vector p0, Vector p1, Vector p2) {
|
|||||||
|
|
||||||
Vector pm = BezierEval(tm, p0, p1, p2);
|
Vector pm = BezierEval(tm, p0, p1, p2);
|
||||||
|
|
||||||
double tol = 0.5*SS.chordTol/SS.GW.scale;
|
double tol = SS.chordTol/SS.GW.scale;
|
||||||
|
|
||||||
if((tb - ta) < 0.05 || pm.DistanceToLine(pa, pb.Minus(pa)) < tol) {
|
if((tb - ta) < 0.01 || pm.DistanceToLine(pa, pb.Minus(pa)) < tol) {
|
||||||
Entity *e = SS.GetEntity(entity);
|
Entity *e = SS.GetEntity(entity);
|
||||||
e->LineDrawOrGetDistanceOrEdge(pa, pb);
|
e->LineDrawOrGetDistanceOrEdge(pa, pb);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user