Add STEP file export for 2d curves too, and disable extrusion not

normal to the sketch.

[git-p4: depot-paths = "//depot/solvespace/": change = 1981]
This commit is contained in:
Jonathan Westhues 2009-06-10 21:57:23 -08:00
parent 19fbae5b66
commit 3b3b7fe680
5 changed files with 101 additions and 27 deletions

View File

@ -319,9 +319,13 @@ VectorFileWriter *VectorFileWriter::ForFile(char *filename) {
} else if(StringEndsIn(filename, ".plt")||StringEndsIn(filename, ".hpgl")) {
static HpglFileWriter HpglWriter;
ret = &HpglWriter;
} else if(StringEndsIn(filename, ".step")||StringEndsIn(filename, ".stp")) {
static Step2dFileWriter Step2dWriter;
ret = &Step2dWriter;
} else {
Error("Can't identify output file type from file extension of "
"filename '%s'; try .dxf, .svg, .plt, .hpgl, .pdf, .eps, or .ps.",
"filename '%s'; try .step, .stp, .dxf, .svg, .plt, .hpgl, .pdf, "
".eps, or .ps.",
filename);
return NULL;
}
@ -979,6 +983,36 @@ void HpglFileWriter::FinishAndCloseFile(void) {
fclose(f);
}
//-----------------------------------------------------------------------------
// Routine for STEP output; just a wrapper around the general STEP stuff that
// can also be used for surfaces or 3d curves.
//-----------------------------------------------------------------------------
void Step2dFileWriter::StartFile(void) {
ZERO(&sfw);
sfw.f = f;
sfw.WriteHeader();
}
void Step2dFileWriter::Triangle(STriangle *tr) {
}
void Step2dFileWriter::LineSegment(double x0, double y0, double x1, double y1) {
SBezier sb = SBezier::From(Vector::From(x0, y0, 0),
Vector::From(x1, y1, 0));
Bezier(&sb);
}
void Step2dFileWriter::Bezier(SBezier *sb) {
int c = sfw.ExportCurve(sb);
sfw.curves.Add(&c);
}
void Step2dFileWriter::FinishAndCloseFile(void) {
sfw.WriteWireframe();
sfw.WriteFooter();
fclose(f);
}
//-----------------------------------------------------------------------------
// Export the mesh as an STL file; it should always be vertex-to-vertex and
// not self-intersecting, so not much to do.

View File

@ -57,6 +57,9 @@ void StepFileWriter::WriteHeader(void) {
"#173=CARTESIAN_POINT('',(0.,0.,0.));\n"
"\n"
);
// Start the ID somewhere beyond the header IDs.
id = 200;
}
int StepFileWriter::ExportCurve(SBezier *sb) {
@ -320,7 +323,16 @@ void StepFileWriter::ExportSurface(SSurface *ss) {
}
}
void StepFileWriter::ExportTo(char *file) {
void StepFileWriter::WriteFooter(void) {
fprintf(f,
"\n"
"ENDSEC;\n"
"\n"
"END-ISO-10303-21;\n"
);
}
void StepFileWriter::ExportSurfacesTo(char *file) {
Group *g = SK.GetGroup(SS.GW.activeGroup);
shell = &(g->runningShell);
if(shell->surface.n == 0) {
@ -340,8 +352,6 @@ void StepFileWriter::ExportTo(char *file) {
WriteHeader();
id = 200;
ZERO(&advancedFaces);
SSurface *ss;
@ -364,14 +374,26 @@ void StepFileWriter::ExportTo(char *file) {
fprintf(f, "#%d=SHAPE_REPRESENTATION_RELATIONSHIP($,$,#169,#%d);\n",
id+3, id+2);
fprintf(f,
"\n"
"ENDSEC;\n"
"\n"
"END-ISO-10303-21;\n"
);
WriteFooter();
fclose(f);
advancedFaces.Clear();
}
void StepFileWriter::WriteWireframe(void) {
fprintf(f, "#%d=GEOMETRIC_CURVE_SET('curves',(", id);
int *c;
for(c = curves.First(); c; c = curves.NextAfter(c)) {
fprintf(f, "#%d", *c);
if(curves.NextAfter(c) != NULL) fprintf(f, ",");
}
fprintf(f, "));\n");
fprintf(f, "#%d=GEOMETRICALLY_BOUNDED_WIREFRAME_SHAPE_REPRESENTATION"
"('',(#%d,#170),#168);\n", id+1, id);
fprintf(f, "#%d=SHAPE_REPRESENTATION_RELATIONSHIP($,$,#169,#%d);\n",
id+2, id+1);
id += 3;
curves.Clear();
}

View File

@ -78,6 +78,12 @@ void Group::MenuGroup(int id) {
break;
case GraphicsWindow::MNU_GROUP_EXTRUDE:
if(!SS.GW.LockedInWorkplane()) {
Error("Select a workplane (Sketch -> In Workplane) before "
"extruding. The sketch will be extruded normal to the "
"workplane.");
return;
}
g.type = EXTRUDE;
g.opA = SS.GW.activeGroup;
g.predef.entityB = SS.GW.ActiveWorkplane();

View File

@ -403,7 +403,7 @@ void SolveSpace::MenuFile(int id) {
if(!GetSaveFile(exportFile, SRF_EXT, SRF_PATTERN)) break;
StepFileWriter sfw;
ZERO(&sfw);
sfw.ExportTo(exportFile);
sfw.ExportSurfacesTo(exportFile);
break;
}

View File

@ -84,13 +84,14 @@ int SaveFileYesNoCancel(void);
#define SRF_PATTERN "STEP File (*.step;*.stp)\0*.step;*.stp\0" \
"All Files(*)\0*\0\0"
#define SRF_EXT "step"
#define VEC_PATTERN "DXF File (*.dxf)\0*.dxf\0" \
#define VEC_PATTERN "PDF File (*.pdf)\0*.pdf\0" \
"Encapsulated PostScript (*.eps;*.ps)\0*.eps;*.ps\0" \
"PDF File (*.pdf)\0*.pdf\0" \
"Scalable Vector Graphics (*.svg)\0*.svg\0" \
"STEP File (*.step;*.stp)\0*.step;*.stp\0" \
"DXF File (*.dxf)\0*.dxf\0" \
"HPGL File (*.plt;*.hpgl)\0*.plt;*.hpgl\0" \
"All Files (*)\0*\0\0"
#define VEC_EXT "dxf"
#define VEC_EXT "pdf"
#define CSV_PATTERN "CSV File (*.csv)\0*.csv\0All Files (*)\0*\0\0"
#define CSV_EXT "csv"
#define LICENSE_PATTERN \
@ -361,6 +362,23 @@ public:
SBezierList *sbl, Vector origin, Vector u, Vector v);
};
class StepFileWriter {
public:
void ExportSurfacesTo(char *filename);
void WriteHeader(void);
int ExportCurve(SBezier *sb);
int ExportCurveLoop(SBezierLoop *loop, bool inner);
void ExportSurface(SSurface *ss);
void WriteWireframe(void);
void WriteFooter(void);
List<int> curves;
List<int> advancedFaces;
SShell *shell;
FILE *f;
int id;
};
class VectorFileWriter {
public:
FILE *f;
@ -426,19 +444,13 @@ public:
void StartFile(void);
void FinishAndCloseFile(void);
};
class StepFileWriter {
public:
void ExportTo(char *filename);
void WriteHeader(void);
int ExportCurve(SBezier *sb);
int ExportCurveLoop(SBezierLoop *loop, bool inner);
void ExportSurface(SSurface *ss);
List<int> advancedFaces;
SShell *shell;
FILE *f;
int id;
class Step2dFileWriter : public VectorFileWriter {
StepFileWriter sfw;
void LineSegment(double x0, double y0, double x1, double y1);
void Triangle(STriangle *tr);
void Bezier(SBezier *sb);
void StartFile(void);
void FinishAndCloseFile(void);
};
#ifdef LIBRARY