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:
parent
19fbae5b66
commit
3b3b7fe680
36
export.cpp
36
export.cpp
|
@ -319,9 +319,13 @@ VectorFileWriter *VectorFileWriter::ForFile(char *filename) {
|
||||||
} else if(StringEndsIn(filename, ".plt")||StringEndsIn(filename, ".hpgl")) {
|
} else if(StringEndsIn(filename, ".plt")||StringEndsIn(filename, ".hpgl")) {
|
||||||
static HpglFileWriter HpglWriter;
|
static HpglFileWriter HpglWriter;
|
||||||
ret = &HpglWriter;
|
ret = &HpglWriter;
|
||||||
|
} else if(StringEndsIn(filename, ".step")||StringEndsIn(filename, ".stp")) {
|
||||||
|
static Step2dFileWriter Step2dWriter;
|
||||||
|
ret = &Step2dWriter;
|
||||||
} else {
|
} else {
|
||||||
Error("Can't identify output file type from file extension of "
|
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);
|
filename);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -979,6 +983,36 @@ void HpglFileWriter::FinishAndCloseFile(void) {
|
||||||
fclose(f);
|
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
|
// Export the mesh as an STL file; it should always be vertex-to-vertex and
|
||||||
// not self-intersecting, so not much to do.
|
// not self-intersecting, so not much to do.
|
||||||
|
|
|
@ -57,6 +57,9 @@ void StepFileWriter::WriteHeader(void) {
|
||||||
"#173=CARTESIAN_POINT('',(0.,0.,0.));\n"
|
"#173=CARTESIAN_POINT('',(0.,0.,0.));\n"
|
||||||
"\n"
|
"\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Start the ID somewhere beyond the header IDs.
|
||||||
|
id = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
int StepFileWriter::ExportCurve(SBezier *sb) {
|
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);
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
||||||
shell = &(g->runningShell);
|
shell = &(g->runningShell);
|
||||||
if(shell->surface.n == 0) {
|
if(shell->surface.n == 0) {
|
||||||
|
@ -340,8 +352,6 @@ void StepFileWriter::ExportTo(char *file) {
|
||||||
|
|
||||||
WriteHeader();
|
WriteHeader();
|
||||||
|
|
||||||
id = 200;
|
|
||||||
|
|
||||||
ZERO(&advancedFaces);
|
ZERO(&advancedFaces);
|
||||||
|
|
||||||
SSurface *ss;
|
SSurface *ss;
|
||||||
|
@ -364,14 +374,26 @@ void StepFileWriter::ExportTo(char *file) {
|
||||||
fprintf(f, "#%d=SHAPE_REPRESENTATION_RELATIONSHIP($,$,#169,#%d);\n",
|
fprintf(f, "#%d=SHAPE_REPRESENTATION_RELATIONSHIP($,$,#169,#%d);\n",
|
||||||
id+3, id+2);
|
id+3, id+2);
|
||||||
|
|
||||||
fprintf(f,
|
WriteFooter();
|
||||||
"\n"
|
|
||||||
"ENDSEC;\n"
|
|
||||||
"\n"
|
|
||||||
"END-ISO-10303-21;\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
advancedFaces.Clear();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,12 @@ void Group::MenuGroup(int id) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GraphicsWindow::MNU_GROUP_EXTRUDE:
|
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.type = EXTRUDE;
|
||||||
g.opA = SS.GW.activeGroup;
|
g.opA = SS.GW.activeGroup;
|
||||||
g.predef.entityB = SS.GW.ActiveWorkplane();
|
g.predef.entityB = SS.GW.ActiveWorkplane();
|
||||||
|
|
|
@ -403,7 +403,7 @@ void SolveSpace::MenuFile(int id) {
|
||||||
if(!GetSaveFile(exportFile, SRF_EXT, SRF_PATTERN)) break;
|
if(!GetSaveFile(exportFile, SRF_EXT, SRF_PATTERN)) break;
|
||||||
StepFileWriter sfw;
|
StepFileWriter sfw;
|
||||||
ZERO(&sfw);
|
ZERO(&sfw);
|
||||||
sfw.ExportTo(exportFile);
|
sfw.ExportSurfacesTo(exportFile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
44
solvespace.h
44
solvespace.h
|
@ -84,13 +84,14 @@ int SaveFileYesNoCancel(void);
|
||||||
#define SRF_PATTERN "STEP File (*.step;*.stp)\0*.step;*.stp\0" \
|
#define SRF_PATTERN "STEP File (*.step;*.stp)\0*.step;*.stp\0" \
|
||||||
"All Files(*)\0*\0\0"
|
"All Files(*)\0*\0\0"
|
||||||
#define SRF_EXT "step"
|
#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" \
|
"Encapsulated PostScript (*.eps;*.ps)\0*.eps;*.ps\0" \
|
||||||
"PDF File (*.pdf)\0*.pdf\0" \
|
|
||||||
"Scalable Vector Graphics (*.svg)\0*.svg\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" \
|
"HPGL File (*.plt;*.hpgl)\0*.plt;*.hpgl\0" \
|
||||||
"All Files (*)\0*\0\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_PATTERN "CSV File (*.csv)\0*.csv\0All Files (*)\0*\0\0"
|
||||||
#define CSV_EXT "csv"
|
#define CSV_EXT "csv"
|
||||||
#define LICENSE_PATTERN \
|
#define LICENSE_PATTERN \
|
||||||
|
@ -361,6 +362,23 @@ public:
|
||||||
SBezierList *sbl, Vector origin, Vector u, Vector v);
|
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 {
|
class VectorFileWriter {
|
||||||
public:
|
public:
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
@ -426,19 +444,13 @@ public:
|
||||||
void StartFile(void);
|
void StartFile(void);
|
||||||
void FinishAndCloseFile(void);
|
void FinishAndCloseFile(void);
|
||||||
};
|
};
|
||||||
|
class Step2dFileWriter : public VectorFileWriter {
|
||||||
class StepFileWriter {
|
StepFileWriter sfw;
|
||||||
public:
|
void LineSegment(double x0, double y0, double x1, double y1);
|
||||||
void ExportTo(char *filename);
|
void Triangle(STriangle *tr);
|
||||||
void WriteHeader(void);
|
void Bezier(SBezier *sb);
|
||||||
int ExportCurve(SBezier *sb);
|
void StartFile(void);
|
||||||
int ExportCurveLoop(SBezierLoop *loop, bool inner);
|
void FinishAndCloseFile(void);
|
||||||
void ExportSurface(SSurface *ss);
|
|
||||||
|
|
||||||
List<int> advancedFaces;
|
|
||||||
SShell *shell;
|
|
||||||
FILE *f;
|
|
||||||
int id;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef LIBRARY
|
#ifdef LIBRARY
|
||||||
|
|
Loading…
Reference in New Issue
Block a user