summaryrefslogtreecommitdiff
path: root/mainwin.cc
diff options
context:
space:
mode:
Diffstat (limited to 'mainwin.cc')
-rw-r--r--mainwin.cc87
1 files changed, 18 insertions, 69 deletions
diff --git a/mainwin.cc b/mainwin.cc
index 98e82f7..6dba9c8 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -787,7 +787,7 @@ void MainWindow::actionDisplayCSGProducts()
current_win = NULL;
}
-void MainWindow::actionExportSTL()
+void MainWindow::actionExportSTLorOFF(bool stl_mode)
{
current_win = this;
@@ -804,94 +804,43 @@ void MainWindow::actionExportSTL()
return;
}
- QString stl_filename = QFileDialog::getSaveFileName(this, "Export STL File", "", "STL Files (*.stl)");
+ QString stl_filename = QFileDialog::getSaveFileName(this,
+ stl_mode ? "Export STL File" : "Export OFF File", "",
+ stl_mode ? "STL Files (*.stl)" : "OFF Files (*.off)");
if (stl_filename.isEmpty()) {
- PRINT("No filename specified. STL export aborted.");
+ PRINTF("No filename specified. %s export aborted.", stl_mode ? "STL" : "OFF");
current_win = NULL;
return;
}
- CGAL_Polyhedron P;
- root_N->convert_to_Polyhedron(P);
-
- typedef CGAL_Polyhedron::Vertex Vertex;
- typedef CGAL_Polyhedron::Vertex_const_iterator VCI;
- typedef CGAL_Polyhedron::Facet_const_iterator FCI;
- typedef CGAL_Polyhedron::Halfedge_around_facet_const_circulator HFCC;
-
- FILE *f = fopen(stl_filename.toAscii().data(), "w");
- if (!f) {
- PRINT("Can't open STL file for STL export.");
- current_win = NULL;
- return;
- }
- fprintf(f, "solid\n");
-
- QProgressDialog *pd = new QProgressDialog("Exporting object to STL file...",
+ QProgressDialog *pd = new QProgressDialog(
+ stl_mode ? "Exporting object to STL file..." : "Exporting object to OFF file...",
QString(), 0, root_N->number_of_facets() + 1);
pd->setValue(0);
pd->setAutoClose(false);
pd->show();
QApplication::processEvents();
- int facet_count = 0;
- for (FCI fi = P.facets_begin(); fi != P.facets_end(); ++fi) {
- HFCC hc = fi->facet_begin();
- HFCC hc_end = hc;
- Vertex v1, v2, v3;
- v1 = *VCI((hc++)->vertex());
- v3 = *VCI((hc++)->vertex());
- do {
- v2 = v3;
- v3 = *VCI((hc++)->vertex());
- double x1 = CGAL::to_double(v1.point().x());
- double y1 = CGAL::to_double(v1.point().y());
- double z1 = CGAL::to_double(v1.point().z());
- double x2 = CGAL::to_double(v2.point().x());
- double y2 = CGAL::to_double(v2.point().y());
- double z2 = CGAL::to_double(v2.point().z());
- double x3 = CGAL::to_double(v3.point().x());
- double y3 = CGAL::to_double(v3.point().y());
- double z3 = CGAL::to_double(v3.point().z());
- QString vs1, vs2, vs3;
- vs1.sprintf("%f %f %f", x1, y1, z1);
- vs2.sprintf("%f %f %f", x2, y2, z2);
- vs3.sprintf("%f %f %f", x3, y3, z3);
- if (vs1 != vs2 && vs1 != vs3 && vs2 != vs3) {
-
- double nx = (y1-y2)*(z1-z3) - (z1-z2)*(y1-y3);
- double ny = (z1-z2)*(x1-x3) - (x1-x2)*(z1-z3);
- double nz = (x1-x2)*(y1-y3) - (y1-y2)*(x1-x3);
- double n_scale = 1 / sqrt(nx*nx + ny*ny + nz*nz);
- fprintf(f, " facet normal %f %f %f\n",
- nx * n_scale, ny * n_scale, nz * n_scale);
- fprintf(f, " outer loop\n");
- fprintf(f, " vertex %s\n", vs1.toAscii().data());
- fprintf(f, " vertex %s\n", vs2.toAscii().data());
- fprintf(f, " vertex %s\n", vs3.toAscii().data());
- fprintf(f, " endloop\n");
- fprintf(f, " endfacet\n");
- }
- } while (hc != hc_end);
- pd->setValue(facet_count++);
- QApplication::processEvents();
- }
-
- fprintf(f, "endsolid\n");
- fclose(f);
+ if (stl_mode)
+ export_stl(root_N, stl_filename, pd);
+ else
+ export_off(root_N, stl_filename, pd);
- PRINT("STL export finished.");
+ PRINTF("%s export finished.", stl_mode ? "STL" : "OFF");
delete pd;
#endif /* ENABLE_CGAL */
current_win = NULL;
}
+void MainWindow::actionExportSTL()
+{
+ actionExportSTLorOFF(true);
+}
+
void MainWindow::actionExportOFF()
{
- current_win = this;
- PRINTA("Function %1 is not implemented yet!", QString(__PRETTY_FUNCTION__));
- current_win = NULL;
+ actionExportSTLorOFF(false);
}
void MainWindow::viewModeActionsUncheck()
contact: Jan Huwald // Impressum