summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2010-01-06 02:04:49 (GMT)
committerclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2010-01-06 02:04:49 (GMT)
commit255826eeb598081ab65c4a339d818bf8d8709934 (patch)
tree909507085a6ccf91313eaec3ae3b79b909e5ee08
parente71c3ce4c9ac506a1138c87df829bb0b187fe056 (diff)
Clifford Wolf:
Added DXF export for 2d data (command line and GUI) git-svn-id: http://svn.clifford.at/openscad/trunk@208 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r--MainWindow.h1
-rw-r--r--MainWindow.ui8
-rw-r--r--export.cc46
-rw-r--r--mainwin.cc38
-rw-r--r--openscad.cc19
-rw-r--r--openscad.h1
6 files changed, 105 insertions, 8 deletions
diff --git a/MainWindow.h b/MainWindow.h
index 0638719..c02162a 100644
--- a/MainWindow.h
+++ b/MainWindow.h
@@ -92,6 +92,7 @@ private slots:
void actionExportSTLorOFF(bool stl_mode);
void actionExportSTL();
void actionExportOFF();
+ void actionExportDXF();
public:
void viewModeActionsUncheck();
diff --git a/MainWindow.ui b/MainWindow.ui
index 6eda078..0a296a4 100644
--- a/MainWindow.ui
+++ b/MainWindow.ui
@@ -98,7 +98,7 @@
<x>0</x>
<y>0</y>
<width>681</width>
- <height>25</height>
+ <height>27</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
@@ -153,6 +153,7 @@
<addaction name="designActionDisplayCSGProducts"/>
<addaction name="designActionExportSTL"/>
<addaction name="designActionExportOFF"/>
+ <addaction name="designActionExportDXF"/>
</widget>
<widget class="QMenu" name="menu_View">
<property name="title">
@@ -588,6 +589,11 @@
<string>Clear Recent</string>
</property>
</action>
+ <action name="designActionExportDXF">
+ <property name="text">
+ <string>Export as DXF...</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
diff --git a/export.cc b/export.cc
index 9154f49..cdfbef6 100644
--- a/export.cc
+++ b/export.cc
@@ -101,5 +101,51 @@ void export_off(CGAL_Nef_polyhedron*, QString, QProgressDialog*)
PRINTF("WARNING: OFF import is not implemented yet.");
}
+void export_dxf(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *)
+{
+ FILE *f = fopen(filename.toUtf8().data(), "w");
+ if (!f) {
+ PRINTA("Can't open DXF file \"%1\" for DXF export: %2",
+ filename, QString(strerror(errno)));
+ MainWindow::current_win = NULL;
+ return;
+ }
+
+ fprintf(f, " 0\n");
+ fprintf(f, "SECTION\n");
+ fprintf(f, " 2\n");
+ fprintf(f, "ENTITIES\n");
+
+ 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;
+ fprintf(f, " 0\n");
+ fprintf(f, "LINE\n");
+ fprintf(f, " 10\n");
+ fprintf(f, "%f\n", x1);
+ fprintf(f, " 11\n");
+ fprintf(f, "%f\n", x2);
+ fprintf(f, " 20\n");
+ fprintf(f, "%f\n", y1);
+ fprintf(f, " 21\n");
+ fprintf(f, "%f\n", y2);
+ }
+ }
+
+ fprintf(f, " 0\n");
+ fprintf(f, "ENDSEC\n");
+ fprintf(f, " 0\n");
+ fprintf(f, "EOF\n");
+
+ fclose(f);
+}
+
#endif
diff --git a/mainwin.cc b/mainwin.cc
index 2e7bbe2..43fd329 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -193,6 +193,7 @@ MainWindow::MainWindow(const char *filename)
connect(this->designActionDisplayCSGProducts, SIGNAL(triggered()), this, SLOT(actionDisplayCSGProducts()));
connect(this->designActionExportSTL, SIGNAL(triggered()), this, SLOT(actionExportSTL()));
connect(this->designActionExportOFF, SIGNAL(triggered()), this, SLOT(actionExportOFF()));
+ connect(this->designActionExportDXF, SIGNAL(triggered()), this, SLOT(actionExportDXF()));
// View menu
#ifndef ENABLE_OPENCSG
@@ -1022,9 +1023,9 @@ void MainWindow::actionExportSTLorOFF(bool stl_mode)
void MainWindow::actionExportSTLorOFF(bool)
#endif
{
+#ifdef ENABLE_CGAL
current_win = this;
-#ifdef ENABLE_CGAL
if (!root_N) {
PRINT("Nothing to export! Try building first (press F6).");
current_win = NULL;
@@ -1068,8 +1069,9 @@ void MainWindow::actionExportSTLorOFF(bool)
PRINTF("%s export finished.", stl_mode ? "STL" : "OFF");
delete pd;
-#endif /* ENABLE_CGAL */
+
current_win = NULL;
+#endif /* ENABLE_CGAL */
}
void MainWindow::actionExportSTL()
@@ -1082,6 +1084,38 @@ void MainWindow::actionExportOFF()
actionExportSTLorOFF(false);
}
+void MainWindow::actionExportDXF()
+{
+#ifdef ENABLE_CGAL
+ current_win = this;
+
+ if (!root_N) {
+ PRINT("Nothing to export! Try building first (press F6).");
+ current_win = NULL;
+ return;
+ }
+
+ if (root_N->dim != 2) {
+ PRINT("Current top level object is not a 2D object.");
+ current_win = NULL;
+ return;
+ }
+
+ QString stl_filename = QFileDialog::getSaveFileName(this,
+ "Export DXF File", "", "DXF Files (*.dxf)");
+ if (stl_filename.isEmpty()) {
+ PRINTF("No filename specified. DXF export aborted.");
+ current_win = NULL;
+ return;
+ }
+
+ export_dxf(root_N, stl_filename, NULL);
+ PRINTF("DXF export finished.");
+
+ current_win = NULL;
+#endif /* ENABLE_CGAL */
+}
+
void MainWindow::viewModeActionsUncheck()
{
viewActionOpenCSG->setChecked(false);
diff --git a/openscad.cc b/openscad.cc
index c22a083..edc94b4 100644
--- a/openscad.cc
+++ b/openscad.cc
@@ -35,7 +35,7 @@
static void help(const char *progname)
{
- fprintf(stderr, "Usage: %s [ { -s stl_file | -o off_file } [ -d deps_file ] ]\\\n"
+ fprintf(stderr, "Usage: %s [ { -s stl_file | -o off_file | -x dxf_file } [ -d deps_file ] ]\\\n"
"%*s[ -m make_command ] [ -D var=val [..] ] filename\n",
progname, strlen(progname)+8, "");
exit(1);
@@ -90,24 +90,30 @@ int main(int argc, char **argv)
const char *filename = NULL;
const char *stl_output_file = NULL;
const char *off_output_file = NULL;
+ const char *dxf_output_file = NULL;
const char *deps_output_file = NULL;
int opt;
- while ((opt = getopt(argc, argv, "s:o:d:m:D:")) != -1)
+ while ((opt = getopt(argc, argv, "s:o:x:d:m:D:")) != -1)
{
switch (opt)
{
case 's':
- if (stl_output_file || off_output_file)
+ if (stl_output_file || off_output_file || dxf_output_file)
help(argv[0]);
stl_output_file = optarg;
break;
case 'o':
- if (stl_output_file || off_output_file)
+ if (stl_output_file || off_output_file || dxf_output_file)
help(argv[0]);
off_output_file = optarg;
break;
+ case 'x':
+ if (stl_output_file || off_output_file || dxf_output_file)
+ help(argv[0]);
+ dxf_output_file = optarg;
+ break;
case 'd':
if (deps_output_file)
help(argv[0]);
@@ -134,7 +140,7 @@ int main(int argc, char **argv)
help(argv[0]);
#endif
- if (stl_output_file || off_output_file)
+ if (stl_output_file || off_output_file || dxf_output_file)
{
if (!filename)
help(argv[0]);
@@ -209,6 +215,9 @@ int main(int argc, char **argv)
if (off_output_file)
export_off(root_N, off_output_file, NULL);
+ if (dxf_output_file)
+ export_dxf(root_N, dxf_output_file, NULL);
+
delete root_node;
delete root_N;
#else
diff --git a/openscad.h b/openscad.h
index c27d85d..d78453b 100644
--- a/openscad.h
+++ b/openscad.h
@@ -707,6 +707,7 @@ extern int parser_error_pos;
#ifdef ENABLE_CGAL
void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd);
void export_off(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd);
+void export_dxf(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd);
#endif
extern void handle_dep(QString filename);
contact: Jan Huwald // Impressum