diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/context.cc | 5 | ||||
-rw-r--r-- | src/dxfdata.cc | 4 | ||||
-rw-r--r-- | src/mainwin.cc | 39 | ||||
-rw-r--r-- | src/module.cc | 10 | ||||
-rw-r--r-- | src/module.h | 5 | ||||
-rw-r--r-- | src/openscad.cc | 7 | ||||
-rw-r--r-- | src/parser.y | 17 | ||||
-rw-r--r-- | src/value.cc | 2 |
8 files changed, 44 insertions, 45 deletions
diff --git a/src/context.cc b/src/context.cc index a2a8d13..97ea5b9 100644 --- a/src/context.cc +++ b/src/context.cc @@ -51,9 +51,8 @@ Context::Context(const Context *parent, const Module *library) this->functions_p = &library->functions; this->modules_p = &library->modules; this->usedlibs_p = &library->usedlibs; - for (size_t j = 0; j < library->assignments_var.size(); j++) { - this->set_variable(library->assignments_var[j], - library->assignments_expr[j]->evaluate(this)); + BOOST_FOREACH(const std::string &var, library->assignments_var) { + this->set_variable(var, library->assignments.at(var)->evaluate(this)); } } else { 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 c82e949..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(); @@ -1040,8 +1040,9 @@ bool MainWindow::compileTopLevelDocument(bool reload) { bool shouldcompiletoplevel = !reload; - if ((reload && fileChangedOnDisk() && checkEditorModified()) || - includesChanged()) { + if (includesChanged()) shouldcompiletoplevel = true; + + if (reload && fileChangedOnDisk() && checkEditorModified()) { shouldcompiletoplevel = true; refreshDocument(); } @@ -1053,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; @@ -1292,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..."); } @@ -1310,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..."); } @@ -1327,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(); @@ -1375,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); @@ -1428,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); @@ -1461,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"; @@ -1481,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; @@ -1831,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/module.cc b/src/module.cc index cfd73cc..e6dcb57 100644 --- a/src/module.cc +++ b/src/module.cc @@ -136,7 +136,7 @@ std::vector<AbstractNode*> IfElseModuleInstantiation::evaluateElseChildren(const Module::~Module() { - BOOST_FOREACH (Expression *v, assignments_expr) delete v; + BOOST_FOREACH (const AssignmentContainer::value_type &v, assignments) delete v.second; BOOST_FOREACH (FunctionContainer::value_type &f, functions) delete f.second; BOOST_FOREACH (AbstractModuleContainer::value_type &m, modules) delete m.second; BOOST_FOREACH (ModuleInstantiation *v, children) delete v; @@ -158,8 +158,8 @@ AbstractNode *Module::evaluate(const Context *ctx, const ModuleInstantiation *in else c.usedlibs_p = NULL; - for (size_t i = 0; i < assignments_var.size(); i++) { - c.set_variable(assignments_var[i], assignments_expr[i]->evaluate(&c)); + BOOST_FOREACH(const std::string &var, assignments_var) { + c.set_variable(var, assignments.at(var)->evaluate(&c)); } AbstractNode *node = new AbstractNode(inst); @@ -192,8 +192,8 @@ std::string Module::dump(const std::string &indent, const std::string &name) con BOOST_FOREACH(const AbstractModuleContainer::value_type &m, modules) { dump << m.second->dump(indent + tab, m.first); } - for (size_t i = 0; i < assignments_var.size(); i++) { - dump << indent << tab << assignments_var[i] << " = " << *assignments_expr[i] << ";\n"; + BOOST_FOREACH(const std::string &var, assignments_var) { + dump << indent << tab << var << " = " << *assignments.at(var) << ";\n"; } for (size_t i = 0; i < children.size(); i++) { dump << children[i]->dump(indent + tab); diff --git a/src/module.h b/src/module.h index 879d249..cc82f81 100644 --- a/src/module.h +++ b/src/module.h @@ -74,8 +74,9 @@ public: bool is_handling_dependencies; bool handleDependencies(); - std::vector<std::string> assignments_var; - std::vector<Expression*> assignments_expr; + std::list<std::string> assignments_var; + typedef boost::unordered_map<std::string, Expression*> AssignmentContainer; + AssignmentContainer assignments; typedef boost::unordered_map<std::string, class AbstractFunction*> FunctionContainer; FunctionContainer functions; diff --git a/src/openscad.cc b/src/openscad.cc index 682ccb7..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::fromStdString(boosty::stringy(boosty::absolute(filename))); + 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::fromStdString(boosty::stringy((original_path / *infile)))); + new MainWindow(QString::fromLocal8Bit(boosty::stringy(original_path / *infile).c_str())); } } app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); diff --git a/src/parser.y b/src/parser.y index 3e485ff..536f4ef 100644 --- a/src/parser.y +++ b/src/parser.y @@ -151,19 +151,10 @@ statement: } } | TOK_ID '=' expr ';' { - bool add_new_assignment = true; - for (size_t i = 0; i < currmodule->assignments_var.size(); i++) { - if (currmodule->assignments_var[i] != $1) - continue; - delete currmodule->assignments_expr[i]; - currmodule->assignments_expr[i] = $3; - add_new_assignment = false; - } - if (add_new_assignment) { - currmodule->assignments_var.push_back($1); - currmodule->assignments_expr.push_back($3); - free($1); - } + std::list<std::string>::iterator found = std::find(currmodule->assignments_var.begin(), currmodule->assignments_var.end(),$1); + if (found != currmodule->assignments_var.end()) currmodule->assignments_var.erase(found); + currmodule->assignments_var.push_back($1); + currmodule->assignments[$1] = $3; } | TOK_MODULE TOK_ID '(' arguments_decl optional_commas ')' { Module *p = currmodule; 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; } |