summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-03-12 02:14:00 (GMT)
committerMarius Kintel <marius@kintel.net>2013-03-12 02:14:00 (GMT)
commit6b8a5e266ca1725e35e76aef0caa639fe77fdc48 (patch)
tree393a8feff35b0970b3b7da62334c0200a5081b4c
parent5f03fbee6bbaf411e2bd4095c9911fe8dc6df210 (diff)
Handle files with non-ascii filenames. Only rudimentary tested. Fixes #113 #290
-rw-r--r--src/dxfdata.cc4
-rw-r--r--src/mainwin.cc34
-rw-r--r--src/openscad.cc7
-rw-r--r--src/value.cc2
-rw-r--r--testdata/scad/misc/sfære.scad2
-rw-r--r--testdata/scad/misc/størrelse.scad1
-rw-r--r--tests/CMakeLists.txt8
-rw-r--r--tests/regression/openscad-nonascii/sfære-expected.csg3
8 files changed, 41 insertions, 20 deletions
diff --git a/src/dxfdata.cc b/src/dxfdata.cc
index 2fd40ab..f34af51 100644
--- a/src/dxfdata.cc
+++ b/src/dxfdata.cc
@@ -389,10 +389,10 @@ DxfData::DxfData(double fn, double fs, double fa,
BOOST_FOREACH(const EntityList::value_type &i, unsupported_entities_list) {
if (layername.empty()) {
PRINTB("WARNING: Unsupported DXF Entity '%s' (%x) in %s.",
- i.first % i.second % QuotedString(QDir::current().relativeFilePath(QString::fromStdString(filename)).toStdString()));
+ i.first % i.second % QuotedString(QDir::current().relativeFilePath(QString::fromLocal8Bit(filename.c_str())).toLocal8Bit().constData()));
} else {
PRINTB("WARNING: Unsupported DXF Entity '%s' (%x) in layer '%s' of %s.",
- i.first % i.second % layername % QuotedString(QDir::current().relativeFilePath(QString::fromStdString(filename)).toStdString()));
+ i.first % i.second % layername % QuotedString(QDir::current().relativeFilePath(QString::fromLocal8Bit(filename.c_str())).toLocal8Bit().constData()));
}
}
diff --git a/src/mainwin.cc b/src/mainwin.cc
index 9cb59dd..dd855fb 100644
--- a/src/mainwin.cc
+++ b/src/mainwin.cc
@@ -522,7 +522,7 @@ MainWindow::setFileName(const QString &filename)
this->fileName = fileinfo.fileName();
}
- this->root_ctx.setDocumentPath(fileinfo.dir().absolutePath().toStdString());
+ this->root_ctx.setDocumentPath(fileinfo.dir().absolutePath().toLocal8Bit().constData());
QDir::setCurrent(fileinfo.dir().absolutePath());
}
@@ -586,13 +586,13 @@ void MainWindow::refreshDocument()
QFile file(this->fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
PRINTB("Failed to open file %s: %s",
- this->fileName.toStdString() % file.errorString().toStdString());
+ this->fileName.toLocal8Bit().constData() % file.errorString().toLocal8Bit().constData());
}
else {
QTextStream reader(&file);
reader.setCodec("UTF-8");
QString text = reader.readAll();
- PRINTB("Loaded design '%s'.", this->fileName.toStdString());
+ PRINTB("Loaded design '%s'.", this->fileName.toLocal8Bit().constData());
editor->setPlainText(text);
}
}
@@ -904,13 +904,13 @@ void MainWindow::actionSave()
setCurrentOutput();
QFile file(this->fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
- PRINTB("Failed to open file for writing: %s (%s)", this->fileName.toStdString() % file.errorString().toStdString());
+ PRINTB("Failed to open file for writing: %s (%s)", this->fileName.toLocal8Bit().constData() % file.errorString().toLocal8Bit().constData());
}
else {
QTextStream writer(&file);
writer.setCodec("UTF-8");
writer << this->editor->toPlainText();
- PRINTB("Saved design '%s'.", this->fileName.toStdString());
+ PRINTB("Saved design '%s'.", this->fileName.toLocal8Bit().constData());
this->editor->setContentModified(false);
}
clearCurrentOutput();
@@ -1054,7 +1054,8 @@ bool MainWindow::compileTopLevelDocument(bool reload)
this->last_compiled_doc = editor->toPlainText();
std::string fulltext =
- this->last_compiled_doc.toStdString() + "\n" + commandline_commands;
+ std::string(this->last_compiled_doc.toLocal8Bit().constData()) +
+ "\n" + commandline_commands;
delete this->root_module;
this->root_module = NULL;
@@ -1293,7 +1294,7 @@ void MainWindow::actionDisplayAST()
e->setWindowTitle("AST Dump");
e->setReadOnly(true);
if (root_module) {
- e->setPlainText(QString::fromStdString(root_module->dump("", "")));
+ e->setPlainText(QString::fromLocal8Bit(root_module->dump("", "").c_str()));
} else {
e->setPlainText("No AST to dump. Please try compiling first...");
}
@@ -1311,7 +1312,7 @@ void MainWindow::actionDisplayCSGTree()
e->setWindowTitle("CSG Tree Dump");
e->setReadOnly(true);
if (this->root_node) {
- e->setPlainText(QString::fromStdString(this->tree.getString(*this->root_node)));
+ e->setPlainText(QString::fromLocal8Bit(this->tree.getString(*this->root_node).c_str()));
} else {
e->setPlainText("No CSG to dump. Please try compiling first...");
}
@@ -1328,7 +1329,12 @@ void MainWindow::actionDisplayCSGProducts()
e->setTabStopWidth(30);
e->setWindowTitle("CSG Products Dump");
e->setReadOnly(true);
- e->setPlainText(QString("\nCSG before normalization:\n%1\n\n\nCSG after normalization:\n%2\n\n\nCSG rendering chain:\n%3\n\n\nHighlights CSG rendering chain:\n%4\n\n\nBackground CSG rendering chain:\n%5\n").arg(root_raw_term ? QString::fromStdString(root_raw_term->dump()) : "N/A", root_norm_term ? QString::fromStdString(root_norm_term->dump()) : "N/A", this->root_chain ? QString::fromStdString(this->root_chain->dump()) : "N/A", highlights_chain ? QString::fromStdString(highlights_chain->dump()) : "N/A", background_chain ? QString::fromStdString(background_chain->dump()) : "N/A"));
+ e->setPlainText(QString("\nCSG before normalization:\n%1\n\n\nCSG after normalization:\n%2\n\n\nCSG rendering chain:\n%3\n\n\nHighlights CSG rendering chain:\n%4\n\n\nBackground CSG rendering chain:\n%5\n")
+ .arg(root_raw_term ? QString::fromLocal8Bit(root_raw_term->dump().c_str()) : "N/A",
+ root_norm_term ? QString::fromLocal8Bit(root_norm_term->dump().c_str()) : "N/A",
+ this->root_chain ? QString::fromLocal8Bit(this->root_chain->dump().c_str()) : "N/A",
+ highlights_chain ? QString::fromLocal8Bit(highlights_chain->dump().c_str()) : "N/A",
+ background_chain ? QString::fromLocal8Bit(background_chain->dump().c_str()) : "N/A"));
e->show();
e->resize(600, 400);
clearCurrentOutput();
@@ -1376,7 +1382,7 @@ void MainWindow::actionExportSTLorOFF(bool)
std::ofstream fstream(stl_filename.toUtf8());
if (!fstream.is_open()) {
- PRINTB("Can't open file \"%s\" for export", stl_filename.toStdString());
+ PRINTB("Can't open file \"%s\" for export", stl_filename.toLocal8Bit().constData());
}
else {
if (stl_mode) export_stl(this->root_N, fstream);
@@ -1429,7 +1435,7 @@ void MainWindow::actionExportDXF()
std::ofstream fstream(dxf_filename.toUtf8());
if (!fstream.is_open()) {
- PRINTB("Can't open file \"%s\" for export", dxf_filename.toStdString());
+ PRINTB("Can't open file \"%s\" for export", dxf_filename.toLocal8Bit().constData());
}
else {
export_dxf(this->root_N, fstream);
@@ -1462,7 +1468,7 @@ void MainWindow::actionExportCSG()
std::ofstream fstream(csg_filename.toUtf8());
if (!fstream.is_open()) {
- PRINTB("Can't open file \"%s\" for export", csg_filename.toStdString());
+ PRINTB("Can't open file \"%s\" for export", csg_filename.toLocal8Bit().constData());
}
else {
fstream << this->tree.getString(*this->root_node) << "\n";
@@ -1482,7 +1488,7 @@ void MainWindow::actionExportImage()
if (img_filename.isEmpty()) {
PRINT("No filename specified. Image export aborted.");
} else {
- qglview->save(img_filename.toStdString().c_str());
+ qglview->save(img_filename.toLocal8Bit().constData());
}
clearCurrentOutput();
return;
@@ -1832,7 +1838,7 @@ void MainWindow::consoleOutput(const std::string &msg, void *userdata)
// originates in a worker thread.
MainWindow *thisp = static_cast<MainWindow*>(userdata);
QMetaObject::invokeMethod(thisp->console, "append", Qt::QueuedConnection,
- Q_ARG(QString, QString::fromStdString(msg)));
+ Q_ARG(QString, QString::fromLocal8Bit(msg.c_str())));
}
void MainWindow::setCurrentOutput()
diff --git a/src/openscad.cc b/src/openscad.cc
index 138c689..f7cc48e 100644
--- a/src/openscad.cc
+++ b/src/openscad.cc
@@ -49,6 +49,7 @@
#endif
#include <QApplication>
+#include <QString>
#include <QDir>
#include <sstream>
@@ -294,7 +295,7 @@ int main(int argc, char **argv)
examplesdir = exdir.path();
}
- parser_init(QApplication::instance()->applicationDirPath().toStdString());
+ parser_init(QApplication::instance()->applicationDirPath().toLocal8Bit().constData());
// Initialize global visitors
NodeCache nodecache;
@@ -492,7 +493,7 @@ int main(int argc, char **argv)
#endif
QString qfilename;
- if (filename) qfilename = QString::fromUtf8(boosty::stringy(boosty::absolute(filename)).c_str());
+ if (filename) qfilename = QString::fromLocal8Bit(boosty::stringy(boosty::absolute(filename)).c_str());
#if 0 /*** disabled by clifford wolf: adds rendering artefacts with OpenCSG ***/
// turn on anti-aliasing
@@ -507,7 +508,7 @@ int main(int argc, char **argv)
if (vm.count("input-file")) {
inputFiles = vm["input-file"].as<vector<string> >();
for (vector<string>::const_iterator infile = inputFiles.begin()+1; infile != inputFiles.end(); infile++) {
- new MainWindow(QString::fromUtf8(boosty::stringy((original_path / *infile).c_str()));
+ new MainWindow(QString::fromLocal8Bit(boosty::stringy(original_path / *infile).c_str()));
}
}
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
diff --git a/src/value.cc b/src/value.cc
index 5712e33..f14f826 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -39,7 +39,7 @@
std::ostream &operator<<(std::ostream &stream, const Filename &filename)
{
- stream << QuotedString(QDir::current().relativeFilePath(QString::fromStdString(filename)).toStdString());
+ stream << QuotedString(QDir::current().relativeFilePath(QString::fromLocal8Bit(filename.c_str())).toLocal8Bit().constData());
return stream;
}
diff --git a/testdata/scad/misc/sfære.scad b/testdata/scad/misc/sfære.scad
new file mode 100644
index 0000000..df47b51
--- /dev/null
+++ b/testdata/scad/misc/sfære.scad
@@ -0,0 +1,2 @@
+include <størrelse.scad>
+sphere(radius);
diff --git a/testdata/scad/misc/størrelse.scad b/testdata/scad/misc/størrelse.scad
new file mode 100644
index 0000000..508de48
--- /dev/null
+++ b/testdata/scad/misc/størrelse.scad
@@ -0,0 +1 @@
+radius=10;
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6a5ec74..5eecaae 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -920,6 +920,14 @@ add_cmdline_test(throwntogethertest SUFFIX png FILES ${THROWNTOGETHERTEST_FILES}
add_cmdline_test(cgalstlsanitytest SUFFIX txt FILES ${CGALSTLSANITYTEST_FILES})
# Tests using the actual OpenSCAD binary
+
+# non-ASCII filenames
+add_cmdline_test(openscad-nonascii EXE ${GUI_BINPATH} ARGS -o
+ SUFFIX csg
+ FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/sfære.scad)
+
+
+# Image output
add_cmdline_test(openscad-cgalpng EXE ${GUI_BINPATH} ARGS --render -o
EXPECTEDDIR cgalpngtest SUFFIX png
FILES ${OPENSCAD-CGALPNG_FILES})
diff --git a/tests/regression/openscad-nonascii/sfære-expected.csg b/tests/regression/openscad-nonascii/sfære-expected.csg
new file mode 100644
index 0000000..e1ee757
--- /dev/null
+++ b/tests/regression/openscad-nonascii/sfære-expected.csg
@@ -0,0 +1,3 @@
+group() {
+ sphere($fn = 0, $fa = 12, $fs = 2, r = 10);
+}
contact: Jan Huwald // Impressum