From 730bb8f73efcc656d78429a93cd2d635423f0aa4 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Mon, 12 Oct 2009 01:28:34 -0800 Subject: [PATCH] Make the export scale factor affect the surfaces in a STEP file, and lay groundwork for wireframe export. [git-p4: depot-paths = "//depot/solvespace/": change = 2052] --- confscreen.cpp | 6 +++--- exportstep.cpp | 37 ++++++++++++++++++++++++------------- graphicswin.cpp | 1 + solvespace.h | 3 +-- srf/curve.cpp | 14 ++++++++++++++ srf/surface.cpp | 9 +++++++++ srf/surface.h | 3 +++ ui.h | 1 + 8 files changed, 56 insertions(+), 18 deletions(-) diff --git a/confscreen.cpp b/confscreen.cpp index 1cb9c8b..77c9d71 100644 --- a/confscreen.cpp +++ b/confscreen.cpp @@ -61,7 +61,7 @@ void TextWindow::ScreenChangeExportScale(int link, DWORD v) { char str[1024]; sprintf(str, "%.3f", (double)SS.exportScale); - ShowTextEditControl(57, 3, str); + ShowTextEditControl(57, 5, str); SS.TW.edit.meaning = EDIT_EXPORT_SCALE; } @@ -174,8 +174,8 @@ void TextWindow::ShowConfiguration(void) { &ScreenChangeGridSpacing, 0); Printf(false, ""); - Printf(false, "%Ft export scale factor (1.0=mm, 25.4=inch)"); - Printf(false, "%Ba %# %Fl%Ll%f%D[change]%E", + Printf(false, "%Ft export scale factor (1:1=mm, 1:25.4=inch)"); + Printf(false, "%Ba 1:%# %Fl%Ll%f%D[change]%E", (double)SS.exportScale, &ScreenChangeExportScale, 0); Printf(false, "%Ft cutter radius offset (0=no offset) "); diff --git a/exportstep.cpp b/exportstep.cpp index d43c380..f53158d 100644 --- a/exportstep.cpp +++ b/exportstep.cpp @@ -158,7 +158,7 @@ int StepFileWriter::ExportCurveLoop(SBezierLoop *loop, bool inner) { return fb; } -void StepFileWriter::ExportSurface(SSurface *ss) { +void StepFileWriter::ExportSurface(SSurface *ss, SBezierList *sbl) { int i, j, srfid = id; fprintf(f, "#%d=(\n", srfid); @@ -205,17 +205,14 @@ void StepFileWriter::ExportSurface(SSurface *ss) { id = srfid + 1 + (ss->degm + 1)*(ss->degn + 1); - // Get all of the loops of Beziers that trim our surface (with each - // Bezier split so that we use the section as t goes from 0 to 1), and - // the piecewise linearization of those loops in xyz space. - SBezierList sbl; - SPolygon sp; - ZERO(&sbl); - ZERO(&sp); - SEdge errorAt; bool allClosed; - ss->MakeSectionEdgesInto(shell, NULL, &sbl); - SBezierLoopSet sbls = SBezierLoopSet::From(&sbl, &sp, &allClosed, &errorAt); + SEdge errorAt; + SPolygon sp; + ZERO(&sp); + // Assemble the Bezier trim curves into closed loops; we also get the + // piecewise linearization of the curves (in the SPolygon sp), as a + // calculation aid for the loop direction. + SBezierLoopSet sbls = SBezierLoopSet::From(sbl, &sp, &allClosed, &errorAt); // Convert the xyz piecewise linear to uv piecewise linear. SContour *contour; @@ -334,7 +331,8 @@ void StepFileWriter::WriteFooter(void) { void StepFileWriter::ExportSurfacesTo(char *file) { Group *g = SK.GetGroup(SS.GW.activeGroup); - shell = &(g->runningShell); + SShell *shell = &(g->runningShell); + if(shell->surface.n == 0) { Error("The model does not contain any surfaces to export.%s", g->runningMesh.l.n > 0 ? @@ -358,7 +356,20 @@ void StepFileWriter::ExportSurfacesTo(char *file) { for(ss = shell->surface.First(); ss; ss = shell->surface.NextAfter(ss)) { if(ss->trim.n == 0) continue; - ExportSurface(ss); + // Get all of the loops of Beziers that trim our surface (with each + // Bezier split so that we use the section as t goes from 0 to 1), and + // the piecewise linearization of those loops in xyz space. + SBezierList sbl; + ZERO(&sbl); + ss->MakeSectionEdgesInto(shell, NULL, &sbl); + + // Apply the export scale factor. + ss->ScaleSelfBy(1.0/SS.exportScale); + sbl.ScaleSelfBy(1.0/SS.exportScale); + + ExportSurface(ss, &sbl); + + sbl.Clear(); } fprintf(f, "#%d=CLOSED_SHELL('',(", id); diff --git a/graphicswin.cpp b/graphicswin.cpp index ec85ebb..406e1fb 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -22,6 +22,7 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = { { 1, "Export &Image...", MNU_EXPORT_PNG, 0, mFile }, { 1, "Export 2d &View...", MNU_EXPORT_VIEW, 0, mFile }, { 1, "Export 2d &Section...", MNU_EXPORT_SECTION, 0, mFile }, +{ 1, "Export 3d &Wireframe...", MNU_EXPORT_WIREFRAME, 0, mFile }, { 1, "Export Triangle &Mesh...", MNU_EXPORT_MESH, 0, mFile }, { 1, "Export &Surfaces...", MNU_EXPORT_SURFACES,0, mFile }, { 1, NULL, 0, 0, NULL }, diff --git a/solvespace.h b/solvespace.h index 0874a97..52900a0 100644 --- a/solvespace.h +++ b/solvespace.h @@ -378,13 +378,12 @@ public: void WriteHeader(void); int ExportCurve(SBezier *sb); int ExportCurveLoop(SBezierLoop *loop, bool inner); - void ExportSurface(SSurface *ss); + void ExportSurface(SSurface *ss, SBezierList *sbl); void WriteWireframe(void); void WriteFooter(void); List curves; List advancedFaces; - SShell *shell; FILE *f; int id; }; diff --git a/srf/curve.cpp b/srf/curve.cpp index 14301f4..1b58128 100644 --- a/srf/curve.cpp +++ b/srf/curve.cpp @@ -77,6 +77,13 @@ void SBezier::Reverse(void) { } } +void SBezier::ScaleSelfBy(double s) { + int i; + for(i = 0; i <= deg; i++) { + ctrl[i] = ctrl[i].ScaledBy(s); + } +} + void SBezier::GetBoundingProjd(Vector u, Vector orig, double *umin, double *umax) { @@ -202,6 +209,13 @@ void SBezierList::Clear(void) { l.Clear(); } +void SBezierList::ScaleSelfBy(double s) { + SBezier *sb; + for(sb = l.First(); sb; sb = l.NextAfter(sb)) { + sb->ScaleSelfBy(s); + } +} + //----------------------------------------------------------------------------- // If our list contains multiple identical Beziers (in either forward or // reverse order), then cull them. diff --git a/srf/surface.cpp b/srf/surface.cpp index 0f52347..c6051af 100644 --- a/srf/surface.cpp +++ b/srf/surface.cpp @@ -471,6 +471,15 @@ void SSurface::Reverse(void) { } } +void SSurface::ScaleSelfBy(double s) { + int i, j; + for(i = 0; i <= degm; i++) { + for(j = 0; j <= degn; j++) { + ctrl[i][j] = ctrl[i][j].ScaledBy(s); + } + } +} + void SSurface::Clear(void) { trim.Clear(); } diff --git a/srf/surface.h b/srf/surface.h index 06b3891..a0cabad 100644 --- a/srf/surface.h +++ b/srf/surface.h @@ -92,6 +92,7 @@ public: SBezier TransformedBy(Vector t, Quaternion q, bool mirror); SBezier InPerspective(Vector u, Vector v, Vector n, Vector origin, double cameraTan); + void ScaleSelfBy(double s); static SBezier From(Vector p0, Vector p1, Vector p2, Vector p3); static SBezier From(Vector p0, Vector p1, Vector p2); @@ -106,6 +107,7 @@ public: List l; void Clear(void); + void ScaleSelfBy(double s); void CullIdenticalBeziers(void); void AllIntersectionsWith(SBezierList *sblb, SPointList *spl); }; @@ -239,6 +241,7 @@ public: static SSurface FromTransformationOf(SSurface *a, Vector t, Quaternion q, bool mirror, bool includingTrims); + void ScaleSelfBy(double s); void EdgeNormalsWithinSurface(Point2d auv, Point2d buv, Vector *pt, Vector *enin, Vector *enout, diff --git a/ui.h b/ui.h index ce372c6..5666694 100644 --- a/ui.h +++ b/ui.h @@ -217,6 +217,7 @@ public: MNU_EXPORT_SURFACES, MNU_EXPORT_VIEW, MNU_EXPORT_SECTION, + MNU_EXPORT_WIREFRAME, MNU_EXIT, // View MNU_ZOOM_IN,