diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/export.cc | 53 | ||||
-rw-r--r-- | src/lexer.l | 1 | ||||
-rw-r--r-- | src/mainwin.cc | 8 |
3 files changed, 41 insertions, 21 deletions
diff --git a/src/export.cc b/src/export.cc index 71ebe8f..215f936 100644 --- a/src/export.cc +++ b/src/export.cc @@ -154,6 +154,20 @@ void export_off(CGAL_Nef_polyhedron*, QTextStream&, QProgressDialog*) void export_dxf(CGAL_Nef_polyhedron *root_N, QTextStream &output, QProgressDialog *) { setlocale(LC_NUMERIC, "C"); // Ensure radix is . (not ,) in output + + // Some importers (e.g. QCAD) needs a HEADER section specifying AutoCAD 2000 as + // the file format for LWPOLYLINE entities to work + output << " 0\n" + << "SECTION\n" + << " 2\n" + << "HEADER\n" + << " 9\n" + << "$ACADVER\n" + << " 1\n" + << "AC1015\n" + << " 0\n" + << "ENDSEC\n"; + // Some importers (e.g. Inkscape) needs a BLOCKS section to be present output << " 0\n" << "SECTION\n" @@ -169,26 +183,27 @@ void export_dxf(CGAL_Nef_polyhedron *root_N, QTextStream &output, QProgressDialo DxfData dd(*root_N); for (int i=0; i<dd.paths.size(); i++) { - for (int j=1; j<dd.paths[i].points.size(); j++) { - DxfData::Point *p1 = dd.paths[i].points[j-1]; - DxfData::Point *p2 = dd.paths[i].points[j]; - double x1 = p1->x; - double y1 = p1->y; - double x2 = p2->x; - double y2 = p2->y; - output << " 0\n" - << "LINE\n"; - // Some importers (e.g. Inkscape) needs a layer to be specified - output <<" 8\n" - << "0\n" - << " 10\n" - << x1 << "\n" - << " 11\n" - << x2 << "\n" + if (dd.paths[i].points.size() < 2) { + // not a valid polygon + continue; + } + // Use the LWPOLYLINE class - this makes it easier to handle complete + // objects (as paths) in Inkscape. + output << " 0\n" + << "LWPOLYLINE\n" + << " 8\n" // Some importers (e.g. Inkscape) need a layer to be specified + << "0\n" + << " 90\n" // number of vertices + << dd.paths[i].points.size() << "\n" + << " 70\n" // polygon flag (closed, ...) + << (dd.paths[i].is_closed ? 1 : 0) << "\n"; + // add all points + for (int j=0; j<dd.paths[i].points.size(); j++) { + DxfData::Point *p = dd.paths[i].points[j]; + output <<" 10\n" + << p->x << "\n" << " 20\n" - << y1 << "\n" - << " 21\n" - << y2 << "\n"; + << p->y << "\n"; } } diff --git a/src/lexer.l b/src/lexer.l index 9e8aaf8..932711b 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -202,6 +202,7 @@ void includefile() yyin = fopen(finfo.absoluteFilePath().toLocal8Bit(), "r"); if (!yyin) { PRINTA("WARNING: Can't open input file `%1'.", filename); + path_stack.pop(); return; } filename.clear(); diff --git a/src/mainwin.cc b/src/mainwin.cc index eeb7923..e7014fa 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -1311,8 +1311,10 @@ void MainWindow::actionExportSTLorOFF(bool) return; } + QString suffix = stl_mode ? ".stl" : ".off"; QString stl_filename = QFileDialog::getSaveFileName(this, - stl_mode ? "Export STL File" : "Export OFF File", "", + stl_mode ? "Export STL File" : "Export OFF File", + this->fileName.isEmpty() ? "Untitled"+suffix : QFileInfo(this->fileName).baseName()+suffix, stl_mode ? "STL Files (*.stl)" : "OFF Files (*.off)"); if (stl_filename.isEmpty()) { PRINTF("No filename specified. %s export aborted.", stl_mode ? "STL" : "OFF"); @@ -1374,7 +1376,9 @@ void MainWindow::actionExportDXF() } QString dxf_filename = QFileDialog::getSaveFileName(this, - "Export DXF File", "", "DXF Files (*.dxf)"); + "Export DXF File", + this->fileName.isEmpty() ? "Untitled.dxf" : QFileInfo(this->fileName).baseName()+".dxf", + "DXF Files (*.dxf)"); if (dxf_filename.isEmpty()) { PRINTF("No filename specified. DXF export aborted."); clearCurrentOutput(); |