Skip to content

Commit

Permalink
implemented #100 : Warn if exporting a non-watertight mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
Evil-Spirit committed Nov 14, 2016
1 parent a3f9a4e commit 05d3a7b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ void SolveSpaceUI::ExportMeshTo(const std::string &filename) {
Error("Couldn't write to '%s'", filename.c_str());
return;
}

ShowNakedEdges(/*reportOnlyWhenNotOkay=*/true);
if(FilenameHasExtension(filename, ".stl")) {
ExportMeshAsStlTo(f, m);
} else if(FilenameHasExtension(filename, ".obj")) {
Expand Down
63 changes: 35 additions & 28 deletions src/solvespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,34 +605,7 @@ void SolveSpaceUI::MenuAnalyze(Command id) {
break;

case Command::NAKED_EDGES: {
SS.nakedEdges.Clear();

Group *g = SK.GetGroup(SS.GW.activeGroup);
SMesh *m = &(g->displayMesh);
SKdNode *root = SKdNode::From(m);
bool inters, leaks;
root->MakeCertainEdgesInto(&(SS.nakedEdges),
EdgeKind::NAKED_OR_SELF_INTER, /*coplanarIsInter=*/true, &inters, &leaks);

InvalidateGraphics();

const char *intersMsg = inters ?
"The mesh is self-intersecting (NOT okay, invalid)." :
"The mesh is not self-intersecting (okay, valid).";
const char *leaksMsg = leaks ?
"The mesh has naked edges (NOT okay, invalid)." :
"The mesh is watertight (okay, valid).";

std::string cntMsg = ssprintf("\n\nThe model contains %d triangles, from "
"%d surfaces.", g->displayMesh.l.n, g->runningShell.surface.n);

if(SS.nakedEdges.l.n == 0) {
Message("%s\n\n%s\n\nZero problematic edges, good.%s",
intersMsg, leaksMsg, cntMsg.c_str());
} else {
Error("%s\n\n%s\n\n%d problematic edges, bad.%s",
intersMsg, leaksMsg, SS.nakedEdges.l.n, cntMsg.c_str());
}
ShowNakedEdges(/*reportOnlyWhenNotOkay=*/false);
break;
}

Expand Down Expand Up @@ -820,6 +793,40 @@ void SolveSpaceUI::MenuAnalyze(Command id) {
}
}

void SolveSpaceUI::ShowNakedEdges(bool reportOnlyWhenNotOkay) {
SS.nakedEdges.Clear();

Group *g = SK.GetGroup(SS.GW.activeGroup);
SMesh *m = &(g->displayMesh);
SKdNode *root = SKdNode::From(m);
bool inters, leaks;
root->MakeCertainEdgesInto(&(SS.nakedEdges),
EdgeKind::NAKED_OR_SELF_INTER, /*coplanarIsInter=*/true, &inters, &leaks);

if(reportOnlyWhenNotOkay && !inters && !leaks && SS.nakedEdges.l.n == 0) {
return;
}
InvalidateGraphics();

const char *intersMsg = inters ?
"The mesh is self-intersecting (NOT okay, invalid)." :
"The mesh is not self-intersecting (okay, valid).";
const char *leaksMsg = leaks ?
"The mesh has naked edges (NOT okay, invalid)." :
"The mesh is watertight (okay, valid).";

std::string cntMsg = ssprintf("\n\nThe model contains %d triangles, from "
"%d surfaces.", g->displayMesh.l.n, g->runningShell.surface.n);

if(SS.nakedEdges.l.n == 0) {
Message("%s\n\n%s\n\nZero problematic edges, good.%s",
intersMsg, leaksMsg, cntMsg.c_str());
} else {
Error("%s\n\n%s\n\n%d problematic edges, bad.%s",
intersMsg, leaksMsg, SS.nakedEdges.l.n, cntMsg.c_str());
}
}

void SolveSpaceUI::MenuHelp(Command id) {
switch(id) {
case Command::WEBSITE:
Expand Down
1 change: 1 addition & 0 deletions src/solvespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ class SolveSpaceUI {
bool PruneGroups(hGroup hg);
bool PruneRequests(hGroup hg);
bool PruneConstraints(hGroup hg);
static void ShowNakedEdges(bool reportOnlyWhenNotOkay);

enum class Generate : uint32_t {
DIRTY,
Expand Down

0 comments on commit 05d3a7b

Please sign in to comment.