Handle files with non-ascii filenames. Only rudimentary tested. Fixes #113 #290

felipesanches-svg
Marius Kintel 2013-03-11 22:14:00 -04:00
parent 5f03fbee6b
commit 6b8a5e266c
8 changed files with 41 additions and 20 deletions

View File

@ -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()));
}
}

View File

@ -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()

View File

@ -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()));

View File

@ -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;
}

2
testdata/scad/misc/sfære.scad vendored Normal file
View File

@ -0,0 +1,2 @@
include <størrelse.scad>
sphere(radius);

1
testdata/scad/misc/størrelse.scad vendored Normal file
View File

@ -0,0 +1 @@
radius=10;

View File

@ -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})

View File

@ -0,0 +1,3 @@
group() {
sphere($fn = 0, $fa = 12, $fs = 2, r = 10);
}