From 02112071d4772adfe36ada87c586439065f9382e Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 6 Dec 2011 04:07:58 +0100 Subject: Removed unused Qt include diff --git a/src/linearextrude.cc b/src/linearextrude.cc index bc11629..775eeb0 100644 --- a/src/linearextrude.cc +++ b/src/linearextrude.cc @@ -38,8 +38,6 @@ #include using namespace boost::assign; // bring 'operator+=()' into scope -#include - class LinearExtrudeModule : public AbstractModule { public: diff --git a/src/rotateextrude.cc b/src/rotateextrude.cc index 4e2db9e..0da30ce 100644 --- a/src/rotateextrude.cc +++ b/src/rotateextrude.cc @@ -38,8 +38,6 @@ #include using namespace boost::assign; // bring 'operator+=()' into scope -#include - class RotateExtrudeModule : public AbstractModule { public: -- cgit v0.10.1 From 0d6b87dd0e28e53ec4601443c7d06dbb66628d47 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 6 Dec 2011 04:08:32 +0100 Subject: Ported surface parser away from Qt diff --git a/src/surface.cc b/src/surface.cc index 1a5f9bd..2af09dc 100644 --- a/src/surface.cc +++ b/src/surface.cc @@ -33,11 +33,13 @@ #include "handle_dep.h" // handle_dep() #include "visitor.h" -#include -#include -#include #include +#include +#include #include +#include +#include +#include #include using namespace boost::assign; // bring 'operator+=()' into scope @@ -95,9 +97,9 @@ AbstractNode *SurfaceModule::evaluate(const Context *ctx, const ModuleInstantiat PolySet *SurfaceNode::evaluate_polyset(class PolySetEvaluator *) const { handle_dep(filename); - QFile f(QString::fromStdString(filename)); + std::ifstream stream(filename.c_str()); - if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { + if (!stream.good()) { PRINTF("WARNING: Can't open DAT file `%s'.", filename.c_str()); return NULL; } @@ -107,23 +109,34 @@ PolySet *SurfaceNode::evaluate_polyset(class PolySetEvaluator *) const boost::unordered_map,double> data; double min_val = 0; - while (!f.atEnd()) - { - QString line = QString(f.readLine()).remove("\n").remove("\r"); - line.replace(QRegExp("^[ \t]+"), ""); - line.replace(QRegExp("[ \t]+$"), ""); - - if (line.startsWith("#")) - continue; - - QStringList fields = line.split(QRegExp("[ \t]+")); - for (int i = 0; i < fields.count(); i++) { - if (i >= columns) - columns = i + 1; - double v = fields[i].toDouble(); - data[std::make_pair(lines, i)] = v; - min_val = fmin(v-1, min_val); + typedef boost::tokenizer > tokenizer; + boost::char_separator sep(" \t"); + + while (!stream.eof()) { + std::string line; + while (!stream.eof() && (line.size() == 0 || line[0] == '#')) { + std::getline(stream, line); + boost::trim(line); } + if (stream.eof()) break; + + int col = 0; + tokenizer tokens(line, sep); + try { + BOOST_FOREACH(const std::string &token, tokens) { + double v = boost::lexical_cast(token); + data[std::make_pair(lines, col++)] = v; + if (col > columns) columns = col; + min_val = std::min(v-1, min_val); + } + } + catch (boost::bad_lexical_cast &blc) { + if (!stream.eof()) { + PRINTF("WARNING: Illegal value in '%s': %s", filename.c_str(), blc.what()); + } + break; + } + lines++; } -- cgit v0.10.1 From ae30a7978475f8e5bc8272fd1e073fae7f4bd3ed Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 6 Dec 2011 04:09:39 +0100 Subject: Ported from QFileInfo to boost::filesystem diff --git a/boost.pri b/boost.pri index d93b738..97beb7f 100644 --- a/boost.pri +++ b/boost.pri @@ -15,14 +15,14 @@ boost { DEFINES += BOOST_STATIC DEFINES += BOOST_THREAD_USE_LIB DEFINES += Boost_USE_STATIC_LIBS - LIBS += -lboost_thread_win32-mt -lboost_program_options-mt + LIBS += -lboost_thread_win32-mt -lboost_program_options-mt -lboost_filesystem-mt -lboost_system-mt } else { win32 { - LIBS += -llibboost_thread-vc90-mt-s-1_46_1 -llibboost_program_options-vc90-mt-s-1_46_1 + LIBS += -llibboost_thread-vc90-mt-s-1_46_1 -llibboost_program_options-vc90-mt-s-1_46_1 -llibboost_filesystem-vc90-mt-s-1_46_1 -llibboost_system-vc90-mt-s-1_46_1 } else { # some platforms have only '-mt' versions. uncomment if needed. # LIBS += -lboost_thread-mt -lboost_program_options-mt - LIBS += -lboost_thread -lboost_program_options + LIBS += -lboost_thread -lboost_program_options -lboost_filesystem -lboost_system } } } diff --git a/scripts/macosx-build-dependencies.sh b/scripts/macosx-build-dependencies.sh index e69d594..903c7de 100755 --- a/scripts/macosx-build-dependencies.sh +++ b/scripts/macosx-build-dependencies.sh @@ -140,12 +140,13 @@ build_boost() tar xjf boost_$bversion.tar.bz2 cd boost_$bversion # We only need the thread and program_options libraries - ./bootstrap.sh --prefix=$DEPLOYDIR --with-libraries=thread,program_options,filesystem + ./bootstrap.sh --prefix=$DEPLOYDIR --with-libraries=thread,program_options,filesystem,system ./bjam cflags="-mmacosx-version-min=10.5 -arch i386 -arch x86_64" linkflags="-mmacosx-version-min=10.5 -arch i386 -arch x86_64" ./bjam install install_name_tool -id $DEPLOYDIR/lib/libboost_thread.dylib $DEPLOYDIR/lib/libboost_thread.dylib install_name_tool -id $DEPLOYDIR/lib/libboost_program_options.dylib $DEPLOYDIR/lib/libboost_program_options.dylib install_name_tool -id $DEPLOYDIR/lib/libboost_filesystem.dylib $DEPLOYDIR/lib/libboost_filesystem.dylib + install_name_tool -id $DEPLOYDIR/lib/libboost_system.dylib $DEPLOYDIR/lib/libboost_system.dylib } build_cgal() diff --git a/src/context.cc b/src/context.cc index bd97f8f..176bf8d 100644 --- a/src/context.cc +++ b/src/context.cc @@ -30,9 +30,9 @@ #include "module.h" #include "builtin.h" #include "printutils.h" -#include -#include #include +#include +using namespace boost::filesystem; std::vector Context::ctx_stack; @@ -175,8 +175,7 @@ AbstractNode *Context::evaluate_module(const ModuleInstantiation &inst) const std::string Context::getAbsolutePath(const std::string &filename) const { if (!filename.empty()) { - return QFileInfo(QDir(QString::fromStdString(this->document_path)), - QString::fromStdString(filename)).absoluteFilePath().toStdString(); + return absolute(path(this->document_path) / filename).native(); } else { return filename; diff --git a/src/dxfdim.cc b/src/dxfdim.cc index c696226..44b5d73 100644 --- a/src/dxfdim.cc +++ b/src/dxfdim.cc @@ -33,10 +33,11 @@ #include "context.h" #include "mathc99.h" -#include -#include #include +#include +using namespace boost::filesystem; + boost::unordered_map dxf_dim_cache; boost::unordered_map dxf_cross_cache; @@ -62,12 +63,10 @@ Value builtin_dxf_dim(const Context *ctx, const std::vector &argnam name = args[i].text; } - QFileInfo fileInfo(QString::fromStdString(filename)); - std::stringstream keystream; keystream << filename << "|" << layername << "|" << name << "|" << xorigin - << "|" << yorigin <<"|" << scale << "|" << fileInfo.lastModified().toTime_t() - << "|" << fileInfo.size(); + << "|" << yorigin <<"|" << scale << "|" << last_write_time(filename) + << "|" << file_size(filename); std::string key = keystream.str(); if (dxf_dim_cache.find(key) != dxf_dim_cache.end()) return dxf_dim_cache.find(key)->second; @@ -144,12 +143,10 @@ Value builtin_dxf_cross(const Context *ctx, const std::vector &argn args[i].getnum(scale); } - QFileInfo fileInfo(QString::fromStdString(filename)); - std::stringstream keystream; keystream << filename << "|" << layername << "|" << xorigin << "|" << yorigin - << "|" << scale << "|" << fileInfo.lastModified().toTime_t() - << "|" << fileInfo.size(); + << "|" << scale << "|" << last_write_time(filename) + << "|" << file_size(filename); std::string key = keystream.str(); if (dxf_cross_cache.find(key) != dxf_cross_cache.end()) diff --git a/src/handle_dep.cc b/src/handle_dep.cc index d4380f5..99a0df7 100644 --- a/src/handle_dep.cc +++ b/src/handle_dep.cc @@ -2,24 +2,25 @@ #include #include #include -#include -#include #include // for system() #include #include +#include +using namespace boost::filesystem; boost::unordered_set dependencies; const char *make_command = NULL; void handle_dep(const std::string &filename) { - if (filename[0] == '/') + path filepath(filename); + if (filepath.is_absolute()) { dependencies.insert(filename); + } else { - QString dep = QDir::currentPath() + QString("/") + QString::fromStdString(filename); - dependencies.insert(dep.toStdString()); + dependencies.insert((current_path() / filepath).native()); } - if (!QFile(QString::fromStdString(filename)).exists() && make_command) { + if (!exists(filepath) && make_command) { std::stringstream buf; buf << make_command << " '" << QString::fromStdString(filename).replace("'", "'\\''").toUtf8().data() << "'"; system(buf.str().c_str()); // FIXME: Handle error diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 29f8b25..df9598e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -79,7 +79,7 @@ if(BOOST_ROOT) #set(Boost_DEBUG TRUE) set(Boost_NO_SYSTEM_PATHS TRUE) set(Boost_ADDITIONAL_VERSIONS "1.47.0") - find_package( Boost 1.35.0 COMPONENTS thread program_options ) + find_package( Boost 1.35.0 COMPONENTS thread program_options filesystem system ) if(Boost_FOUND) message(STATUS "Boost includes found: " ${Boost_INCLUDE_DIRS}) message(STATUS "Boost libraries found:") -- cgit v0.10.1 From d9d584ff106d0fb9cfd538cc83f94f9356287c54 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 6 Dec 2011 04:10:32 +0100 Subject: Started on porting import() away from Qt diff --git a/src/import.cc b/src/import.cc index b77c120..63bdb86 100644 --- a/src/import.cc +++ b/src/import.cc @@ -46,6 +46,10 @@ #include #include #include +#include +#include +#include +using namespace boost::filesystem; #include using namespace boost::assign; // bring 'operator+=()' into scope @@ -79,10 +83,10 @@ AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiati std::string filename = c.getAbsolutePath(v.text); import_type_e actualtype = this->type; if (actualtype == TYPE_UNKNOWN) { - QFileInfo fi(QString::fromStdString(filename)); - if (fi.suffix().toLower() == "stl") actualtype = TYPE_STL; - else if (fi.suffix().toLower() == "off") actualtype = TYPE_OFF; - else if (fi.suffix().toLower() == "dxf") actualtype = TYPE_DXF; + std::string ext = boost::algorithm::to_lower_copy(path(filename).extension().native()); + if (ext == ".stl") actualtype = TYPE_STL; + else if (ext == ".off") actualtype = TYPE_OFF; + else if (ext == ".dxf") actualtype = TYPE_DXF; } ImportNode *node = new ImportNode(inst, actualtype); @@ -124,22 +128,36 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const } p = new PolySet(); + + // char data[5]; + // f.read(data, 5); + // if (!f.eof() && memcmp(data, "solid", 5)) { QByteArray data = f.read(5); - if (data.size() == 5 && QString(data) == QString("solid")) - { + if (data.size() == 5 && QString(data) == QString("solid")) { int i = 0; double vdata[3][3]; QRegExp splitre = QRegExp("\\s*(vertex)?\\s+"); + // std::string line; + // std::getline(f, line); f.readLine(); - while (!f.atEnd()) - { +// while (!f.eof()) { +// boost::regex ex_sfe("solid|facet|endloop"); +// boost::regex ex_outer("outer loop"); +// boost::regex ex_vertex("vertex"); + while (!f.atEnd()) { + // std::getline(f, line); + // boost::trim(line); QString line = QString(f.readLine()).remove("\n").remove("\r"); - if (line.contains("solid") || line.contains("facet") || line.contains("endloop")) +// if (boost.regex_search(line, ex_sfe)) { + if (line.contains("solid") || line.contains("facet") || line.contains("endloop")) { continue; + } +// if (boost.regex_search(line, ex_outer)) { if (line.contains("outer loop")) { i = 0; continue; } +// if (boost.regex_search(line, ex_vertex)) { if (line.contains("vertex")) { QStringList tokens = line.split(splitre); bool ok[3] = { false, false, false }; -- cgit v0.10.1 From b3fa4d98a41b32547e1ec661f826913d3540c929 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 6 Dec 2011 22:34:43 +0100 Subject: Added regex to boost build diff --git a/boost.pri b/boost.pri index 97beb7f..400300b 100644 --- a/boost.pri +++ b/boost.pri @@ -22,7 +22,7 @@ boost { } else { # some platforms have only '-mt' versions. uncomment if needed. # LIBS += -lboost_thread-mt -lboost_program_options-mt - LIBS += -lboost_thread -lboost_program_options -lboost_filesystem -lboost_system + LIBS += -lboost_thread -lboost_program_options -lboost_filesystem -lboost_system -lboost_regex } } } diff --git a/scripts/macosx-build-dependencies.sh b/scripts/macosx-build-dependencies.sh index 903c7de..cd2b07f 100755 --- a/scripts/macosx-build-dependencies.sh +++ b/scripts/macosx-build-dependencies.sh @@ -140,13 +140,14 @@ build_boost() tar xjf boost_$bversion.tar.bz2 cd boost_$bversion # We only need the thread and program_options libraries - ./bootstrap.sh --prefix=$DEPLOYDIR --with-libraries=thread,program_options,filesystem,system + ./bootstrap.sh --prefix=$DEPLOYDIR --with-libraries=thread,program_options,filesystem,system,regex ./bjam cflags="-mmacosx-version-min=10.5 -arch i386 -arch x86_64" linkflags="-mmacosx-version-min=10.5 -arch i386 -arch x86_64" ./bjam install install_name_tool -id $DEPLOYDIR/lib/libboost_thread.dylib $DEPLOYDIR/lib/libboost_thread.dylib install_name_tool -id $DEPLOYDIR/lib/libboost_program_options.dylib $DEPLOYDIR/lib/libboost_program_options.dylib install_name_tool -id $DEPLOYDIR/lib/libboost_filesystem.dylib $DEPLOYDIR/lib/libboost_filesystem.dylib install_name_tool -id $DEPLOYDIR/lib/libboost_system.dylib $DEPLOYDIR/lib/libboost_system.dylib + install_name_tool -id $DEPLOYDIR/lib/libboost_regex.dylib $DEPLOYDIR/lib/libboost_regex.dylib } build_cgal() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index df9598e..75fb99c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -79,7 +79,7 @@ if(BOOST_ROOT) #set(Boost_DEBUG TRUE) set(Boost_NO_SYSTEM_PATHS TRUE) set(Boost_ADDITIONAL_VERSIONS "1.47.0") - find_package( Boost 1.35.0 COMPONENTS thread program_options filesystem system ) + find_package( Boost 1.35.0 COMPONENTS thread program_options filesystem system regex ) if(Boost_FOUND) message(STATUS "Boost includes found: " ${Boost_INCLUDE_DIRS}) message(STATUS "Boost libraries found:") -- cgit v0.10.1 From 33a2b0e502ae893c1f3a1c2927eab30de3737e58 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 6 Dec 2011 22:35:03 +0100 Subject: Ported away more of the STL parser from Qt diff --git a/src/import.cc b/src/import.cc index 63bdb86..07100e3 100644 --- a/src/import.cc +++ b/src/import.cc @@ -48,6 +48,7 @@ #include #include #include +#include #include using namespace boost::filesystem; #include @@ -121,55 +122,62 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const if (this->type == TYPE_STL) { handle_dep(this->filename); - QFile f(QString::fromStdString(this->filename)); - if (!f.open(QIODevice::ReadOnly)) { + std::ifstream f(this->filename.c_str()); + if (!f.good()) { +// QFile f(QString::fromStdString(this->filename)); +// if (!f.open(QIODevice::ReadOnly)) { PRINTF("WARNING: Can't open import file `%s'.", this->filename.c_str()); return p; } p = new PolySet(); - // char data[5]; - // f.read(data, 5); - // if (!f.eof() && memcmp(data, "solid", 5)) { - QByteArray data = f.read(5); - if (data.size() == 5 && QString(data) == QString("solid")) { + boost::regex ex_sfe("solid|facet|endloop"); + boost::regex ex_outer("outer loop"); + boost::regex ex_vertex("vertex"); + boost::regex ex_vertices("\\s*vertex\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)"); + + char data[5]; + f.read(data, 5); + if (!f.eof() && !memcmp(data, "solid", 5)) { +// QByteArray data = f.read(5); +// if (data.size() == 5 && QString(data) == QString("solid")) { int i = 0; double vdata[3][3]; QRegExp splitre = QRegExp("\\s*(vertex)?\\s+"); - // std::string line; - // std::getline(f, line); - f.readLine(); -// while (!f.eof()) { -// boost::regex ex_sfe("solid|facet|endloop"); -// boost::regex ex_outer("outer loop"); -// boost::regex ex_vertex("vertex"); - while (!f.atEnd()) { - // std::getline(f, line); - // boost::trim(line); - QString line = QString(f.readLine()).remove("\n").remove("\r"); -// if (boost.regex_search(line, ex_sfe)) { - if (line.contains("solid") || line.contains("facet") || line.contains("endloop")) { + std::string line; + std::getline(f, line); +// f.readLine(); + while (!f.eof()) { + +// while (!f.atEnd()) { + std::getline(f, line); + boost::trim(line); +// QString line = QString(f.readLine()).remove("\n").remove("\r"); + if (boost::regex_search(line, ex_sfe)) { +// if (line.contains("solid") || line.contains("facet") || line.contains("endloop")) { continue; } -// if (boost.regex_search(line, ex_outer)) { - if (line.contains("outer loop")) { + if (boost::regex_search(line, ex_outer)) { +// if (line.contains("outer loop")) { i = 0; continue; } -// if (boost.regex_search(line, ex_vertex)) { - if (line.contains("vertex")) { - QStringList tokens = line.split(splitre); - bool ok[3] = { false, false, false }; - if (tokens.size() == 4) { - vdata[i][0] = tokens[1].toDouble(&ok[0]); - vdata[i][1] = tokens[2].toDouble(&ok[1]); - vdata[i][2] = tokens[3].toDouble(&ok[2]); + boost::smatch results; + if (boost::regex_search(line, results, ex_vertices)) { +// if (line.contains("vertex")) { +// QStringList tokens = QString::fromStdString(line).split(splitre); + try { + for (int v=0;v<3;v++) { + vdata[i][v] = boost::lexical_cast(results[v+1]); + } } - if (!ok[0] || !ok[1] || !ok[2]) { - PRINTF("WARNING: Can't parse vertex line `%s'.", line.toAscii().data()); + catch (boost::bad_lexical_cast &blc) { + PRINTF("WARNING: Can't parse vertex line `%s'.", line.c_str()); i = 10; - } else if (++i == 3) { + continue; + } + if (++i == 3) { p->append_poly(); p->append_vertex(vdata[0][0], vdata[0][1], vdata[0][2]); p->append_vertex(vdata[1][0], vdata[1][1], vdata[1][2]); @@ -180,6 +188,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const } else { +/* f.read(80-5+4); while (1) { #ifdef _MSC_VER @@ -207,6 +216,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const p->append_vertex(data.x2, data.y2, data.z2); p->append_vertex(data.x3, data.y3, data.z3); } +*/ } } -- cgit v0.10.1 From ba1f0b7489dd5fa9bdc8c44068040f13113b40d0 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 19 Dec 2011 15:36:52 +0100 Subject: simple surface test diff --git a/testdata/scad/features/surface-simple.dat b/testdata/scad/features/surface-simple.dat new file mode 100644 index 0000000..32eba08 --- /dev/null +++ b/testdata/scad/features/surface-simple.dat @@ -0,0 +1,2 @@ +0 1 +2 3 diff --git a/testdata/scad/features/surface-simple.scad b/testdata/scad/features/surface-simple.scad new file mode 100644 index 0000000..9659143 --- /dev/null +++ b/testdata/scad/features/surface-simple.scad @@ -0,0 +1 @@ +surface("surface-simple.dat", center=true); -- cgit v0.10.1 From 195137324af28f84c1fafc85080b093d2fe50f32 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 23 Dec 2011 22:00:53 +0100 Subject: Handle internal boost dependencies diff --git a/scripts/macosx-build-dependencies.sh b/scripts/macosx-build-dependencies.sh index 42dbaac..3940b06 100755 --- a/scripts/macosx-build-dependencies.sh +++ b/scripts/macosx-build-dependencies.sh @@ -146,8 +146,11 @@ build_boost() install_name_tool -id $DEPLOYDIR/lib/libboost_thread.dylib $DEPLOYDIR/lib/libboost_thread.dylib install_name_tool -id $DEPLOYDIR/lib/libboost_program_options.dylib $DEPLOYDIR/lib/libboost_program_options.dylib install_name_tool -id $DEPLOYDIR/lib/libboost_filesystem.dylib $DEPLOYDIR/lib/libboost_filesystem.dylib + install_name_tool -change libboost_system.dylib $DEPLOYDIR/lib/libboost_system.dylib $DEPLOYDIR/lib/libboost_filesystem.dylib install_name_tool -id $DEPLOYDIR/lib/libboost_system.dylib $DEPLOYDIR/lib/libboost_system.dylib install_name_tool -id $DEPLOYDIR/lib/libboost_regex.dylib $DEPLOYDIR/lib/libboost_regex.dylib + + } build_cgal() -- cgit v0.10.1 From dc4bc159251e8300fa51554f50008d8c59a50a02 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 23 Dec 2011 22:01:19 +0100 Subject: Ported binary STL file reader away from Qt diff --git a/src/import.cc b/src/import.cc index 07100e3..a95fce7 100644 --- a/src/import.cc +++ b/src/import.cc @@ -115,7 +115,7 @@ AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiati return node; } -PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const +PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const { PolySet *p = NULL; @@ -188,8 +188,8 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const } else { -/* - f.read(80-5+4); + f.ignore(80-5+4); + int total = 84; while (1) { #ifdef _MSC_VER #pragma pack(push,1) @@ -204,19 +204,18 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const #ifdef __GNUC__ __attribute__ ((packed)) #endif - data; + stldata; #ifdef _MSC_VER #pragma pack(pop) #endif - if (f.read((char*)&data, sizeof(data)) != sizeof(data)) - break; + f.read((char*)&stldata, sizeof(stldata)); + if (f.eof()) break; p->append_poly(); - p->append_vertex(data.x1, data.y1, data.z1); - p->append_vertex(data.x2, data.y2, data.z2); - p->append_vertex(data.x3, data.y3, data.z3); + p->append_vertex(stldata.x1, stldata.y1, stldata.z1); + p->append_vertex(stldata.x2, stldata.y2, stldata.z2); + p->append_vertex(stldata.x3, stldata.y3, stldata.z3); } -*/ } } diff --git a/testdata/scad/features/import_stl-tests.scad b/testdata/scad/features/import_stl-tests.scad index b634d12..7104078 100644 --- a/testdata/scad/features/import_stl-tests.scad +++ b/testdata/scad/features/import_stl-tests.scad @@ -1 +1,3 @@ import_stl("import.stl"); +translate([2,0,0]) import("import.stl"); +translate([4,0,0]) import("import_bin.stl"); diff --git a/tests/regression/cgalpngtest/import_stl-tests-expected.png b/tests/regression/cgalpngtest/import_stl-tests-expected.png index 31395c2..08aa225 100644 Binary files a/tests/regression/cgalpngtest/import_stl-tests-expected.png and b/tests/regression/cgalpngtest/import_stl-tests-expected.png differ diff --git a/tests/regression/dumptest/import_stl-tests-expected.txt b/tests/regression/dumptest/import_stl-tests-expected.txt index ac702f6..648a207 100644 --- a/tests/regression/dumptest/import_stl-tests-expected.txt +++ b/tests/regression/dumptest/import_stl-tests-expected.txt @@ -1,2 +1,8 @@ import(file = "import.stl", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); + multmatrix([[1, 0, 0, 2], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + import(file = "import.stl", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); + } + multmatrix([[1, 0, 0, 4], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + import(file = "import_bin.stl", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); + } diff --git a/tests/regression/opencsgtest/import_stl-tests-expected.png b/tests/regression/opencsgtest/import_stl-tests-expected.png index e6fdbca..19e233a 100644 Binary files a/tests/regression/opencsgtest/import_stl-tests-expected.png and b/tests/regression/opencsgtest/import_stl-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/import_stl-tests-expected.png b/tests/regression/throwntogethertest/import_stl-tests-expected.png index e6fdbca..19e233a 100644 Binary files a/tests/regression/throwntogethertest/import_stl-tests-expected.png and b/tests/regression/throwntogethertest/import_stl-tests-expected.png differ -- cgit v0.10.1 From 0ab51d2d23045021aed225dec8d3c3003316a124 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 24 Dec 2011 22:02:37 +0100 Subject: Extracted librarydir initialization to separate function diff --git a/openscad.pro b/openscad.pro index 50a419d..80e2b80 100644 --- a/openscad.pro +++ b/openscad.pro @@ -134,7 +134,8 @@ FORMS += src/MainWindow.ui \ src/Preferences.ui \ src/OpenCSGWarningDialog.ui -HEADERS += src/renderer.h \ +HEADERS += src/parsersettings.h \ + src/renderer.h \ src/rendersettings.h \ src/ThrownTogetherRenderer.h \ src/CGAL_renderer.h \ @@ -187,7 +188,8 @@ HEADERS += src/renderer.h \ src/system-gl.h \ src/stl-utils.h -SOURCES += src/openscad.cc \ +SOURCES += src/parsersettings.cc \ + src/openscad.cc \ src/mainwin.cc \ src/handle_dep.cc \ src/renderer.cc \ diff --git a/src/highlighter.cc b/src/highlighter.cc index 759826c..64ea980 100644 --- a/src/highlighter.cc +++ b/src/highlighter.cc @@ -25,7 +25,7 @@ */ #include "highlighter.h" -#include "openscad.h" // extern int parser_error_pos; +#include "parsersettings.h" // extern int parser_error_pos; #ifdef _QCODE_EDIT_ Highlighter::Highlighter(QDocument *parent) diff --git a/src/lexer.l b/src/lexer.l index c799028..2102642 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -27,8 +27,8 @@ %{ #include "handle_dep.h" -#include "openscad.h" // librarydir #include "printutils.h" +#include "parsersettings.h" #include "parser_yacc.h" #include #include diff --git a/src/mainwin.cc b/src/mainwin.cc index 3243847..6ef7777 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -27,6 +27,7 @@ #include "PolySetCache.h" #include "MainWindow.h" #include "openscad.h" // examplesdir +#include "parsersettings.h" #include "Preferences.h" #include "printutils.h" #include "node.h" diff --git a/src/openscad.cc b/src/openscad.cc index 0d5b25e..8b81f48 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -35,6 +35,7 @@ #include "nodedumper.h" #include "printutils.h" #include "handle_dep.h" +#include "parsersettings.h" #include #include @@ -85,7 +86,6 @@ static void version() std::string commandline_commands; QString currentdir; QString examplesdir; -QString librarydir; using std::string; using std::vector; @@ -221,24 +221,7 @@ int main(int argc, char **argv) examplesdir = exdir.path(); } - QDir libdir(QApplication::instance()->applicationDirPath()); -#ifdef Q_WS_MAC - libdir.cd("../Resources"); // Libraries can be bundled - if (!libdir.exists("libraries")) libdir.cd("../../.."); -#elif defined(Q_OS_UNIX) - if (libdir.cd("../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); - } else -#endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); - } + parser_init(); // Initialize global visitors NodeCache nodecache; diff --git a/src/openscad.h b/src/openscad.h index 61aec0e..23ae4da 100644 --- a/src/openscad.h +++ b/src/openscad.h @@ -32,7 +32,6 @@ extern int get_fragments_from_r(double r, double fn, double fs, double fa); #include extern std::string commandline_commands; -extern int parser_error_pos; #include // The CWD when application started. We shouldn't change CWD, but until we stop @@ -40,7 +39,6 @@ extern int parser_error_pos; extern QString currentdir; extern QString examplesdir; -extern QString librarydir; #endif diff --git a/src/parsersettings.cc b/src/parsersettings.cc new file mode 100644 index 0000000..bdd5eeb --- /dev/null +++ b/src/parsersettings.cc @@ -0,0 +1,25 @@ +#include "parsersettings.h" +#include +#include + +QString librarydir; + +void parser_init() +{ + QDir libdir(QApplication::instance()->applicationDirPath()); +#ifdef Q_WS_MAC + libdir.cd("../Resources"); // Libraries can be bundled + if (!libdir.exists("libraries")) libdir.cd("../../.."); +#elif defined(Q_OS_UNIX) + if (libdir.cd("../share/openscad/libraries")) { + librarydir = libdir.path(); + } else if (libdir.cd("../../share/openscad/libraries")) { + librarydir = libdir.path(); + } else if (libdir.cd("../../libraries")) { + librarydir = libdir.path(); + } else +#endif + if (libdir.cd("libraries")) { + librarydir = libdir.path(); + } +} diff --git a/src/parsersettings.h b/src/parsersettings.h new file mode 100644 index 0000000..7089df9 --- /dev/null +++ b/src/parsersettings.h @@ -0,0 +1,11 @@ +#ifndef PARSERSETTINGS_H_ +#define PARSERSETTINGS_H_ + +#include + +extern QString librarydir; +extern int parser_error_pos; + +void parser_init(); + +#endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c6db700..dd4e6a8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -243,6 +243,7 @@ add_definitions(-DOPENSCAD_TESTING) set(CORE_SOURCES tests-common.cc + ../src/parsersettings.cc ../src/mathc99.cc ../src/linalg.cc ../src/handle_dep.cc diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index 800a829..59f0d53 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -57,7 +57,6 @@ std::string commandline_commands; QString currentdir; QString examplesdir; -QString librarydir; using std::string; @@ -111,25 +110,6 @@ int main(int argc, char **argv) currentdir = QDir::currentPath(); - QDir libdir(QApplication::instance()->applicationDirPath()); -#ifdef Q_WS_MAC - libdir.cd("../Resources"); // Libraries can be bundled - if (!libdir.exists("libraries")) libdir.cd("../../.."); -#elif defined(Q_OS_UNIX) - if (libdir.cd("../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); - } else -#endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); - } - Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc index 055e970..6412338 100644 --- a/tests/cgaltest.cc +++ b/tests/cgaltest.cc @@ -26,6 +26,7 @@ #include "tests-common.h" #include "openscad.h" +#include "parsersettings.h" #include "node.h" #include "module.h" #include "context.h" @@ -52,7 +53,6 @@ std::string commandline_commands; QString currentdir; QString examplesdir; -QString librarydir; using std::string; @@ -90,24 +90,7 @@ int main(int argc, char **argv) currentdir = QDir::currentPath(); - QDir libdir(QApplication::instance()->applicationDirPath()); -#ifdef Q_WS_MAC - libdir.cd("../Resources"); // Libraries can be bundled - if (!libdir.exists("libraries")) libdir.cd("../../.."); -#elif defined(Q_OS_UNIX) - if (libdir.cd("../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); - } else -#endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); - } + parser_init(); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index aabbc05..52e55c4 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -28,6 +28,7 @@ #include "PolySetEvaluator.h" #include "CSGTermEvaluator.h" #include "openscad.h" +#include "parsersettings.h" #include "node.h" #include "module.h" #include "context.h" @@ -54,7 +55,6 @@ using std::cout; std::string commandline_commands; QString currentdir; QString examplesdir; -QString librarydir; int main(int argc, char **argv) { @@ -75,24 +75,7 @@ int main(int argc, char **argv) currentdir = QDir::currentPath(); - QDir libdir(QApplication::instance()->applicationDirPath()); -#ifdef Q_WS_MAC - libdir.cd("../Resources"); // Libraries can be bundled - if (!libdir.exists("libraries")) libdir.cd("../../.."); -#elif defined(Q_OS_UNIX) - if (libdir.cd("../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); - } else -#endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); - } + parser_init(); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index c2be326..7ad0a35 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -4,6 +4,7 @@ #include "tests-common.h" #include "system-gl.h" #include "openscad.h" +#include "parsersettings.h" #include "builtin.h" #include "context.h" #include "node.h" @@ -39,7 +40,6 @@ using std::cerr; using std::cout; std::string commandline_commands; -QString librarydir; //#define DEBUG @@ -255,24 +255,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) QString currentdir = QDir::currentPath(); - QDir libdir(QApplication::instance()->applicationDirPath()); -#ifdef Q_WS_MAC - libdir.cd("../Resources"); // Libraries can be bundled - if (!libdir.exists("libraries")) libdir.cd("../../.."); -#elif defined(Q_OS_UNIX) - if (libdir.cd("../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); - } else -#endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); - } + parser_init(); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index d7f94f1..2c54ed4 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -28,6 +28,7 @@ #include "CSGTextRenderer.h" #include "CSGTextCache.h" #include "openscad.h" +#include "parsersettings.h" #include "node.h" #include "module.h" #include "context.h" @@ -51,7 +52,6 @@ std::string commandline_commands; QString currentdir; QString examplesdir; -QString librarydir; void csgTree(CSGTextCache &cache, const AbstractNode &root) { @@ -79,24 +79,7 @@ int main(int argc, char **argv) currentdir = QDir::currentPath(); - QDir libdir(QApplication::instance()->applicationDirPath()); -#ifdef Q_WS_MAC - libdir.cd("../Resources"); // Libraries can be bundled - if (!libdir.exists("libraries")) libdir.cd("../../.."); -#elif defined(Q_OS_UNIX) - if (libdir.cd("../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); - } else -#endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); - } + parser_init(); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/dumptest.cc b/tests/dumptest.cc index 22dd96c..4b1d907 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -26,6 +26,7 @@ #include "tests-common.h" #include "openscad.h" +#include "parsersettings.h" #include "node.h" #include "module.h" #include "context.h" @@ -51,7 +52,6 @@ using std::string; std::string commandline_commands; QString currentdir; QString examplesdir; -QString librarydir; string dumptree(const Tree &tree, const AbstractNode &node) { @@ -86,24 +86,7 @@ int main(int argc, char **argv) currentdir = QDir::currentPath(); - QDir libdir(QApplication::instance()->applicationDirPath()); -#ifdef Q_WS_MAC - libdir.cd("../Resources"); // Libraries can be bundled - if (!libdir.exists("libraries")) libdir.cd("../../.."); -#elif defined(Q_OS_UNIX) - if (libdir.cd("../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); - } else -#endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); - } + parser_init(); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/echotest.cc b/tests/echotest.cc index afa3d03..9569f09 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -26,6 +26,7 @@ #include "tests-common.h" #include "openscad.h" +#include "parsersettings.h" #include "node.h" #include "module.h" #include "context.h" @@ -50,7 +51,6 @@ using std::string; std::string commandline_commands; QString currentdir; QString examplesdir; -QString librarydir; static void outfile_handler(const std::string &msg, void *userdata) { std::ostream *str = static_cast(userdata); @@ -87,24 +87,7 @@ int main(int argc, char **argv) currentdir = QDir::currentPath(); - QDir libdir(QApplication::instance()->applicationDirPath()); -#ifdef Q_WS_MAC - libdir.cd("../Resources"); // Libraries can be bundled - if (!libdir.exists("libraries")) libdir.cd("../../.."); -#elif defined(Q_OS_UNIX) - if (libdir.cd("../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); - } else -#endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); - } + parser_init(); Context root_ctx; register_builtin(root_ctx); -- cgit v0.10.1 From bafbc89aa07f984ac74a3dded0f67158fe225a81 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 24 Dec 2011 23:08:38 +0100 Subject: Ported lexer code from QFile to boost filesystem diff --git a/src/lexer.l b/src/lexer.l index 2102642..fd9ca3e 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -30,10 +30,11 @@ #include "printutils.h" #include "parsersettings.h" #include "parser_yacc.h" -#include -#include -#include #include +#include +#include +#include +using namespace boost::filesystem; //isatty for visual c++ and mingw-cross-env #if defined __WIN32__ && ! defined _MSC_VER @@ -44,7 +45,7 @@ extern "C" int __cdecl _isatty(int _FileHandle); #define isatty _isatty #endif -QString* stringcontents; +std::string stringcontents; int lexerget_lineno(void); #ifdef __GNUC__ static void yyunput(int, char*) __attribute__((unused)); @@ -73,12 +74,12 @@ extern const char *parser_source_path; } void includefile(); -QDir sourcepath(); -QStack path_stack; -QStack openfiles; +path sourcepath(); +std::vector path_stack; +std::vector openfiles; -QString filename; -QString filepath; +std::string filename; +std::string filepath; %} @@ -87,6 +88,7 @@ QString filepath; %x comment string %x include +%x use D [0-9] E [Ee][+-]?{D}+ @@ -101,34 +103,36 @@ include[ \t\r\n>]*"<" { BEGIN(include); } } -use[ \t\r\n>]*"<"[^\t\r\n>]+">" { - QString filename(yytext); - filename.remove(QRegExp("^use[ \t\r\n>]*<")); - filename.remove(QRegExp(">$")); - QFileInfo finfo(QDir(parser_source_path), filename); - if (!finfo.exists()) { - finfo = QFileInfo(QDir(librarydir), filename); +use[ \t\r\n>]*"<" { BEGIN(use); } +{ +[^\t\r\n>]+ { filename = yytext; } + ">" { + BEGIN(INITIAL); + path usepath = path(parser_source_path) / filename; + if (!exists(usepath)) { + usepath = librarydir / filename; } - handle_dep(finfo.absoluteFilePath().toStdString()); - parserlval.text = strdup(finfo.absoluteFilePath().toLocal8Bit()); + handle_dep(absolute(usepath).generic_string()); + parserlval.text = strdup(absolute(usepath).c_str()); return TOK_USE; + } } "<"[^ \t\r\n>]+">" { char *filename = strdup(yytext+1); filename[strlen(filename)-1] = 0; - QFileInfo finfo(QDir(parser_source_path), filename); - if (!finfo.exists()) { - finfo = QFileInfo(QDir(librarydir), filename); + path incpath = path(parser_source_path) / filename; + if (!exists(incpath)) { + incpath = librarydir / filename; } PRINTF("DEPRECATED: Support for implicit include will be removed in future releases. Use `include ' instead."); - handle_dep(finfo.absoluteFilePath().toStdString()); - yyin = fopen(finfo.absoluteFilePath().toLocal8Bit(), "r"); + handle_dep(absolute(incpath).generic_string()); + yyin = fopen(absolute(incpath).c_str(), "r"); if (!yyin) { PRINTF("WARNING: Can't open input file `%s'.", filename); } else { - openfiles.append(yyin); + openfiles.push_back(yyin); yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE )); BEGIN(INITIAL); } @@ -136,11 +140,11 @@ use[ \t\r\n>]*"<"[^\t\r\n>]+">" { } <> { - if(!path_stack.empty()) - path_stack.pop(); + if(!path_stack.empty()) path_stack.pop_back(); if (yyin && yyin != stdin) { assert(!openfiles.empty()); - fclose(openfiles.pop()); + fclose(openfiles.back()); + openfiles.pop_back(); } yypop_buffer_state(); if (!YY_CURRENT_BUFFER) @@ -158,20 +162,19 @@ use[ \t\r\n>]*"<"[^\t\r\n>]+">" { {D}+{E}? | {D}*\.{D}+{E}? | -{D}+\.{D}*{E}? { parserlval.number = QString(yytext).toDouble(); return TOK_NUMBER; } +{D}+\.{D}*{E}? { parserlval.number = boost::lexical_cast(yytext); return TOK_NUMBER; } "$"?[a-zA-Z0-9_]+ { parserlval.text = strdup(yytext); return TOK_ID; } -\" { BEGIN(string); stringcontents = new QString(); } +\" { BEGIN(string); stringcontents.clear(); } { -\\n { stringcontents->append('\n'); } -\\t { stringcontents->append('\t'); } -\\r { stringcontents->append('\r'); } -\\\\ { stringcontents->append('\\'); } -\\\" { stringcontents->append('"'); } -[^\\\n\"]+ { stringcontents->append(lexertext); } +\\n { stringcontents += '\n'; } +\\t { stringcontents += '\t'; } +\\r { stringcontents += '\r'; } +\\\\ { stringcontents += '\\'; } +\\\" { stringcontents += '"'; } +[^\\\n\"]+ { stringcontents += lexertext; } \" { BEGIN(INITIAL); - parserlval.text = strdup(stringcontents->toLocal8Bit()); - delete stringcontents; + parserlval.text = strdup(stringcontents.c_str()); return TOK_STRING; } } @@ -192,12 +195,11 @@ use[ \t\r\n>]*"<"[^\t\r\n>]+">" { %% -QDir sourcepath() +path sourcepath() { - if(!path_stack.empty()) - return path_stack.top(); - - return QDir(parser_source_path); + if (!path_stack.empty()) return path_stack.back(); + + return path(parser_source_path); } /* @@ -207,29 +209,29 @@ QDir sourcepath() */ void includefile() { - if (filename.isEmpty()) return; + if (filename.empty()) return; - QDir dirinfo(sourcepath()); - if (!filepath.isEmpty()) { - dirinfo.cd(filepath); + path dirinfo = sourcepath(); + if (!filepath.empty()) { + dirinfo /= filepath; } - QFileInfo finfo(dirinfo, filename); - if (!finfo.exists()) { - finfo = QFileInfo(QFileInfo(QDir(librarydir), filepath).dir(), filename); + path finfo = dirinfo / filename; + if (!exists(finfo)) { + finfo = librarydir / filepath / filename; } filepath.clear(); - path_stack.push(dirinfo); + path_stack.push_back(dirinfo); - handle_dep(finfo.absoluteFilePath().toStdString()); - yyin = fopen(finfo.absoluteFilePath().toLocal8Bit(), "r"); + handle_dep(absolute(finfo).generic_string()); + yyin = fopen(absolute(finfo).c_str(), "r"); if (!yyin) { - PRINTA("WARNING: Can't open input file `%1'.", filename); - path_stack.pop(); + PRINTF("WARNING: Can't open input file `%s'.", filename.c_str()); + path_stack.pop_back(); return; } - openfiles.append(yyin); + openfiles.push_back(yyin); filename.clear(); yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE)); @@ -241,7 +243,7 @@ void includefile() */ void lexerdestroy() { - foreach (FILE *f, openfiles) fclose(f); + BOOST_FOREACH (FILE *f, openfiles) fclose(f); openfiles.clear(); path_stack.clear(); } diff --git a/src/parsersettings.cc b/src/parsersettings.cc index bdd5eeb..e9dc4a7 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -1,25 +1,29 @@ #include "parsersettings.h" #include #include +#include -QString librarydir; +using namespace boost::filesystem; + +std::string librarydir; void parser_init() { - QDir libdir(QApplication::instance()->applicationDirPath()); + path libdir(QApplication::instance()->applicationDirPath().toStdString()); + path tmpdir; #ifdef Q_WS_MAC - libdir.cd("../Resources"); // Libraries can be bundled - if (!libdir.exists("libraries")) libdir.cd("../../.."); + libdir /= "../Resources"; // Libraries can be bundled + if (!is_directory(libdir / "libraries")) libdir /= "../../.."; #elif defined(Q_OS_UNIX) - if (libdir.cd("../share/openscad/libraries")) { - librarydir = libdir.path(); - } else if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); + if (is_directory(tmpdir = libdir / "../share/openscad/libraries")) { + librarydir = tmpdir.generic_string(); + } else if (is_directory(tmpdir = libdir / "../../share/openscad/libraries")) { + librarydir = tmpdir.generic_string(); + } else if (is_directory(tmpdir = libdir / "../../libraries")) { + librarydir = tmpdir.generic_string(); } else #endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); + if (is_directory(tmpdir = libdir / "libraries")) { + librarydir = tmpdir.generic_string(); } } diff --git a/src/parsersettings.h b/src/parsersettings.h index 7089df9..e08e581 100644 --- a/src/parsersettings.h +++ b/src/parsersettings.h @@ -1,9 +1,9 @@ #ifndef PARSERSETTINGS_H_ #define PARSERSETTINGS_H_ -#include +#include -extern QString librarydir; +extern std::string librarydir; extern int parser_error_pos; void parser_init(); -- cgit v0.10.1 From a5ea98c4a499bdc534d58ecf4881d6ce435d3bd5 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 24 Dec 2011 23:27:44 +0100 Subject: Ported parser code from QFile to boost filesystem diff --git a/src/module.h b/src/module.h index c28ab34..93eafa5 100644 --- a/src/module.h +++ b/src/module.h @@ -56,7 +56,7 @@ public: std::string cache_id, msg; }; static boost::unordered_map libs_cache; - static Module *compile_library(std::string filename); + static Module *compile_library(const std::string &filename); std::vector argnames; std::vector argexpr; diff --git a/src/parser.y b/src/parser.y index d703a81..2fb0c3f 100644 --- a/src/parser.y +++ b/src/parser.y @@ -28,11 +28,6 @@ %{ -#include -#include -#include -#include - #include #include #ifndef _MSC_VER @@ -46,6 +41,9 @@ #include "printutils.h" #include #include +#include + +using namespace boost::filesystem; int parser_error_pos = -1; @@ -613,7 +611,7 @@ AbstractModule *parse(const char *text, const char *path, int debug) boost::unordered_map Module::libs_cache; -Module *Module::compile_library(std::string filename) +Module *Module::compile_library(const std::string &filename) { struct stat st; memset(&st, 0, sizeof(struct stat)); @@ -628,12 +626,19 @@ Module *Module::compile_library(std::string filename) return &(*libs_cache[filename].mod); } - QFile f(QString::fromStdString(filename)); - if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { - PRINTF("WARNING: Can't open library file `%s'.", filename.c_str()); - return NULL; - } - QString text = QTextStream(&f).readAll(); + FILE *fp = fopen(filename.c_str(), "rt"); + if (!fp) { + fprintf(stderr, "WARNING: Can't open library file '%s'\n", filename.c_str()); + return NULL; + } + std::stringstream text; + char buffer[513]; + int ret; + while ((ret = fread(buffer, 1, 512, fp)) > 0) { + buffer[ret] = 0; + text << buffer; + } + fclose(fp); print_messages_push(); @@ -644,7 +649,7 @@ Module *Module::compile_library(std::string filename) libs_cache[filename] = e; Module *backup_mod = module; - Module *lib_mod = dynamic_cast(parse(text.toLocal8Bit(), QFileInfo(QString::fromStdString(filename)).absoluteDir().absolutePath().toLocal8Bit(), 0)); + Module *lib_mod = dynamic_cast(parse(text.str().c_str(), absolute(filename).generic_string().c_str(), 0)); module = backup_mod; if (lib_mod) { -- cgit v0.10.1 From 9293b591c720d2021be15b3bed56633d2ac17a8d Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 25 Dec 2011 00:22:03 +0100 Subject: Ported currentdir handling from Qt to boost filesystem diff --git a/src/mainwin.cc b/src/mainwin.cc index 6ef7777..3567ddd 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -490,7 +490,7 @@ MainWindow::setFileName(const QString &filename) { if (filename.isEmpty()) { this->fileName.clear(); - this->root_ctx.setDocumentPath(currentdir.toStdString()); + this->root_ctx.setDocumentPath(currentdir); setWindowTitle("OpenSCAD - New Document[*]"); } else { diff --git a/src/openscad.cc b/src/openscad.cc index 8b81f48..f65b311 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -48,12 +48,7 @@ #endif #include -#include #include -#include -#include -#include -#include #include #ifdef Q_WS_MAC @@ -61,11 +56,15 @@ #include "AppleEvents.h" #endif +#include +#include + #ifdef _MSC_VER #define snprintf _snprintf #endif namespace po = boost::program_options; +namespace fs = boost::filesystem; static void help(const char *progname) { @@ -84,7 +83,7 @@ static void version() } std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; using std::string; @@ -115,7 +114,7 @@ int main(int argc, char **argv) #ifdef Q_WS_MAC app.installEventFilter(new EventFilter(&app)); #endif - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); // set up groups for QSettings QCoreApplication::setOrganizationName("OpenSCAD"); @@ -200,7 +199,7 @@ int main(int argc, char **argv) } #endif - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); QDir exdir(QApplication::instance()->applicationDirPath()); #ifdef Q_WS_MAC @@ -259,7 +258,6 @@ int main(int argc, char **argv) ModuleInstantiation root_inst; AbstractNode *root_node; - QFileInfo fileInfo(filename); handle_dep(filename); FILE *fp = fopen(filename, "rt"); if (!fp) { @@ -275,18 +273,17 @@ int main(int argc, char **argv) } fclose(fp); text << commandline_commands; - root_module = parse(text.str().c_str(), fileInfo.absolutePath().toLocal8Bit(), false); + root_module = parse(text.str().c_str(), fs::absolute(filename).generic_string().c_str(), false); if (!root_module) exit(1); } - QDir::setCurrent(fileInfo.absolutePath()); - + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); tree.setRoot(root_node); if (csg_output_file) { - QDir::setCurrent(original_path.absolutePath()); + fs::current_path(original_path); std::ofstream fstream(csg_output_file); if (!fstream.is_open()) { PRINTF("Can't open file \"%s\" for export", csg_output_file); @@ -299,7 +296,7 @@ int main(int argc, char **argv) else { CGAL_Nef_polyhedron root_N = cgalevaluator.evaluateCGALMesh(*tree.root()); - QDir::setCurrent(original_path.absolutePath()); + fs::current_path(original_path); if (deps_output_file) { if (!write_deps(deps_output_file, @@ -370,7 +367,7 @@ int main(int argc, char **argv) #endif QString qfilename; - if (filename) qfilename = QFileInfo(original_path, filename).absoluteFilePath(); + if (filename) qfilename = QString::fromStdString((original_path / filename).generic_string()); #if 0 /*** disabled by clifford wolf: adds rendering artefacts with OpenCSG ***/ // turn on anti-aliasing @@ -384,8 +381,8 @@ int main(int argc, char **argv) vector inputFiles; if (vm.count("input-file")) { inputFiles = vm["input-file"].as >(); - for (vector::const_iterator i = inputFiles.begin()+1; i != inputFiles.end(); i++) { - new MainWindow(QFileInfo(original_path, i->c_str()).absoluteFilePath()); + for (vector::const_iterator infile = inputFiles.begin()+1; infile != inputFiles.end(); infile++) { + new MainWindow(QString::fromStdString((original_path / *infile).generic_string())); } } app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); diff --git a/src/openscad.h b/src/openscad.h index 23ae4da..dab14cd 100644 --- a/src/openscad.h +++ b/src/openscad.h @@ -36,7 +36,7 @@ extern std::string commandline_commands; #include // The CWD when application started. We shouldn't change CWD, but until we stop // doing this, use currentdir to get the original CWD. -extern QString currentdir; +extern std::string currentdir; extern QString examplesdir; diff --git a/src/parser.y b/src/parser.y index 2fb0c3f..b8da50d 100644 --- a/src/parser.y +++ b/src/parser.y @@ -649,7 +649,7 @@ Module *Module::compile_library(const std::string &filename) libs_cache[filename] = e; Module *backup_mod = module; - Module *lib_mod = dynamic_cast(parse(text.str().c_str(), absolute(filename).generic_string().c_str(), 0)); + Module *lib_mod = dynamic_cast(parse(text.str().c_str(), path(filename).parent_path().generic_string().c_str(), 0)); module = backup_mod; if (lib_mod) { diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index 59f0d53..7aa740d 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -26,6 +26,7 @@ #include "tests-common.h" #include "openscad.h" +#include "parsersettings.h" #include "node.h" #include "module.h" #include "polyset.h" @@ -43,10 +44,6 @@ #include "OffscreenView.h" #include -#include -#include -#include -#include #ifndef _MSC_VER #include #endif @@ -54,8 +51,11 @@ #include #include +#include +namespace fs = boost::filesystem; + std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; using std::string; @@ -106,9 +106,11 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); + + currentdir = fs::current_path().generic_string(); - currentdir = QDir::currentPath(); + parser_init(); Context root_ctx; register_builtin(root_ctx); @@ -121,8 +123,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); AbstractNode *absolute_root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -138,7 +139,7 @@ int main(int argc, char **argv) CGAL_Nef_polyhedron N = cgalevaluator.evaluateCGALMesh(*root_node); - QDir::setCurrent(original_path.absolutePath()); + current_path(original_path); // match with csgtest ends try { diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc index 6412338..8bdf417 100644 --- a/tests/cgaltest.cc +++ b/tests/cgaltest.cc @@ -39,10 +39,6 @@ #include "PolySetCGALEvaluator.h" #include -#include -#include -#include -#include #ifndef _MSC_VER #include #endif @@ -50,8 +46,11 @@ #include #include +#include +namespace fs = boost::filesystem; + std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; using std::string; @@ -86,9 +85,9 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); parser_init(); @@ -103,8 +102,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); AbstractNode *absolute_root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -119,7 +117,7 @@ int main(int argc, char **argv) CGAL_Nef_polyhedron N = cgalevaluator.evaluateCGALMesh(*root_node); - QDir::setCurrent(original_path.absolutePath()); + current_path(original_path); if (!N.empty()) { export_stl(&N, std::cout, NULL); } diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index 52e55c4..7fae3fb 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -39,9 +39,6 @@ #include "csgterm.h" #include -#include -#include -#include #ifndef _MSC_VER #include #endif @@ -50,12 +47,15 @@ #include #include -using std::cout; +#include +namespace fs = boost::filesystem; std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; +using std::cout; + int main(int argc, char **argv) { if (argc != 3) { @@ -71,9 +71,9 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); parser_init(); @@ -89,8 +89,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -115,7 +114,7 @@ int main(int argc, char **argv) // if (evaluator.background) cout << "Background terms: " << evaluator.background->size() << "\n"; // if (evaluator.highlights) cout << "Highlights terms: " << evaluator.highlights->size() << "\n"; - QDir::setCurrent(original_path.absolutePath()); + current_path(original_path); std::ofstream outfile; outfile.open(outfilename); if (root_term) { diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 7ad0a35..4cb612a 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -23,16 +23,16 @@ #include "OffscreenView.h" #include -#include -#include -#include #include #include #include #include +#include + namespace po = boost::program_options; +namespace fs = boost::filesystem; using std::string; using std::vector; @@ -251,9 +251,9 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - QString currentdir = QDir::currentPath(); + std::string currentdir = fs::current_path().generic_string(); parser_init(); @@ -273,8 +273,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) } if (!sysinfo_dump) { - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); } AbstractNode::resetIndexCounter(); @@ -339,7 +338,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) } } - QDir::setCurrent(original_path.absolutePath()); + fs::current_path(original_path); try { csgInfo.glview = new OffscreenView(512,512); diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index 2c54ed4..d0d27ce 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -38,9 +38,6 @@ #include "Tree.h" #include -#include -#include -#include #ifndef _MSC_VER #include #endif @@ -49,8 +46,11 @@ #include #include +#include +namespace fs = boost::filesystem; + std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; void csgTree(CSGTextCache &cache, const AbstractNode &root) @@ -75,9 +75,9 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); parser_init(); @@ -93,8 +93,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -106,7 +105,7 @@ int main(int argc, char **argv) csgTree(csgcache, *root_node); // std::cout << tree.getString(*root_node) << "\n"; - QDir::setCurrent(original_path.absolutePath()); + current_path(original_path); std::ofstream outfile; outfile.open(outfilename); outfile << csgcache[*root_node] << "\n"; diff --git a/tests/dumptest.cc b/tests/dumptest.cc index 4b1d907..bc48011 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -36,9 +36,6 @@ #include "Tree.h" #include -#include -#include -#include #ifndef _MSC_VER #include #endif @@ -47,12 +44,15 @@ #include #include -using std::string; +#include +namespace fs = boost::filesystem; std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; +using std::string; + string dumptree(const Tree &tree, const AbstractNode &node) { std::stringstream str; @@ -82,9 +82,9 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); parser_init(); @@ -100,8 +100,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -116,7 +115,7 @@ int main(int argc, char **argv) exit(1); } - QDir::setCurrent(original_path.absolutePath()); + fs::current_path(original_path); std::ofstream outfile; outfile.open(outfilename); outfile << dumpstdstr << "\n"; @@ -130,7 +129,7 @@ int main(int argc, char **argv) fprintf(stderr, "Error: Unable to read back dumped file\n"); exit(1); } - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(original_path); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); diff --git a/tests/echotest.cc b/tests/echotest.cc index 9569f09..7f05149 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -35,9 +35,6 @@ #include "printutils.h" #include -#include -#include -#include #ifndef _MSC_VER #include #endif @@ -46,12 +43,15 @@ #include #include -using std::string; +#include +namespace fs = boost::filesystem; std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; +using std::string; + static void outfile_handler(const std::string &msg, void *userdata) { std::ostream *str = static_cast(userdata); *str << msg << std::endl; @@ -83,9 +83,9 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); parser_init(); @@ -101,8 +101,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); -- cgit v0.10.1 From c9d08ae246029ea06568c3cd02c7c1716deb40a4 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 25 Dec 2011 14:22:42 +0100 Subject: Ported QString replace to boost::regex diff --git a/src/handle_dep.cc b/src/handle_dep.cc index 99a0df7..da95a67 100644 --- a/src/handle_dep.cc +++ b/src/handle_dep.cc @@ -1,10 +1,10 @@ #include "handle_dep.h" #include #include -#include #include // for system() #include #include +#include #include using namespace boost::filesystem; @@ -22,7 +22,7 @@ void handle_dep(const std::string &filename) } if (!exists(filepath) && make_command) { std::stringstream buf; - buf << make_command << " '" << QString::fromStdString(filename).replace("'", "'\\''").toUtf8().data() << "'"; + buf << make_command << " '" << boost::regex_replace(filename, boost::regex("'"), "'\\''") << "'"; system(buf.str().c_str()); // FIXME: Handle error } } -- cgit v0.10.1 From 541d170ae3c9de60284ea193edbdced917c8fb3a Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 25 Dec 2011 14:22:55 +0100 Subject: Removed unused include diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 684ab42..5384cf7 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -32,7 +32,6 @@ #include #include #include -#include #include #include -- cgit v0.10.1 From 8f3a0d4dce57687cf208ee49b7858bf1310d1937 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 25 Dec 2011 14:23:24 +0100 Subject: Added FIXME for potential beautification diff --git a/src/value.cc b/src/value.cc index 5ea766c..2cc6244 100644 --- a/src/value.cc +++ b/src/value.cc @@ -435,6 +435,7 @@ std::ostream &operator<<(std::ostream &stream, const Filename &filename) return stream; } +// FIXME: This could probably be done more elegantly using boost::regex std::ostream &operator<<(std::ostream &stream, const QuotedString &s) { stream << '"'; -- cgit v0.10.1 From 0dff9f4fa556999c640c342b9f4d832b44a24092 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 25 Dec 2011 15:06:38 +0100 Subject: Removed last traces of Qt diff --git a/src/import.cc b/src/import.cc index a95fce7..c55c983 100644 --- a/src/import.cc +++ b/src/import.cc @@ -39,9 +39,6 @@ #include "cgalutils.h" #endif -#include -#include -#include #include #include #include @@ -124,8 +121,6 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const handle_dep(this->filename); std::ifstream f(this->filename.c_str()); if (!f.good()) { -// QFile f(QString::fromStdString(this->filename)); -// if (!f.open(QIODevice::ReadOnly)) { PRINTF("WARNING: Can't open import file `%s'.", this->filename.c_str()); return p; } @@ -140,33 +135,23 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const char data[5]; f.read(data, 5); if (!f.eof() && !memcmp(data, "solid", 5)) { -// QByteArray data = f.read(5); -// if (data.size() == 5 && QString(data) == QString("solid")) { int i = 0; double vdata[3][3]; - QRegExp splitre = QRegExp("\\s*(vertex)?\\s+"); std::string line; std::getline(f, line); -// f.readLine(); while (!f.eof()) { -// while (!f.atEnd()) { std::getline(f, line); boost::trim(line); -// QString line = QString(f.readLine()).remove("\n").remove("\r"); if (boost::regex_search(line, ex_sfe)) { -// if (line.contains("solid") || line.contains("facet") || line.contains("endloop")) { continue; } if (boost::regex_search(line, ex_outer)) { -// if (line.contains("outer loop")) { i = 0; continue; } boost::smatch results; if (boost::regex_search(line, results, ex_vertices)) { -// if (line.contains("vertex")) { -// QStringList tokens = QString::fromStdString(line).split(splitre); try { for (int v=0;v<3;v++) { vdata[i][v] = boost::lexical_cast(results[v+1]); @@ -189,7 +174,6 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const else { f.ignore(80-5+4); - int total = 84; while (1) { #ifdef _MSC_VER #pragma pack(push,1) -- cgit v0.10.1 From d71ec2a3dbdac8e6b1c2c114d439d9caccff1fa2 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 25 Dec 2011 15:08:42 +0100 Subject: Removed unused include diff --git a/src/polyset.cc b/src/polyset.cc index 481cbec..09d3ea8 100644 --- a/src/polyset.cc +++ b/src/polyset.cc @@ -29,7 +29,6 @@ // #include "Preferences.h" #include "linalg.h" #include -#include PolySet::PolySet() : grid(GRID_FINE), is2d(false), convexity(1) { -- cgit v0.10.1 From 312a25f2708fcef22e300f7bd2c1aaed61d3095d Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 25 Dec 2011 15:09:52 +0100 Subject: Removed Qt dependency from parser_init() diff --git a/src/openscad.cc b/src/openscad.cc index f65b311..6f4d7c7 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -220,7 +220,7 @@ int main(int argc, char **argv) examplesdir = exdir.path(); } - parser_init(); + parser_init(QApplication::instance()->applicationDirPath().toStdString()); // Initialize global visitors NodeCache nodecache; diff --git a/src/parsersettings.cc b/src/parsersettings.cc index e9dc4a7..2d0b1b3 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -1,15 +1,13 @@ #include "parsersettings.h" -#include -#include #include using namespace boost::filesystem; std::string librarydir; -void parser_init() +void parser_init(const std::string &applicationpath) { - path libdir(QApplication::instance()->applicationDirPath().toStdString()); + path libdir(applicationpath); path tmpdir; #ifdef Q_WS_MAC libdir /= "../Resources"; // Libraries can be bundled diff --git a/src/parsersettings.h b/src/parsersettings.h index e08e581..61dcf99 100644 --- a/src/parsersettings.h +++ b/src/parsersettings.h @@ -6,6 +6,6 @@ extern std::string librarydir; extern int parser_error_pos; -void parser_init(); +void parser_init(const std::string &applicationpath); #endif diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index 7aa740d..ca37572 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -110,7 +110,7 @@ int main(int argc, char **argv) currentdir = fs::current_path().generic_string(); - parser_init(); + parser_init(QApplication::instance()->applicationDirPath().toStdString()); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc index 8bdf417..956bf43 100644 --- a/tests/cgaltest.cc +++ b/tests/cgaltest.cc @@ -89,7 +89,7 @@ int main(int argc, char **argv) currentdir = fs::current_path().generic_string(); - parser_init(); + parser_init(QApplication::instance()->applicationDirPath().toStdString()); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index 7fae3fb..016285e 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -75,7 +75,7 @@ int main(int argc, char **argv) currentdir = fs::current_path().generic_string(); - parser_init(); + parser_init(QApplication::instance()->applicationDirPath().toStdString()); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 4cb612a..2406349 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -255,7 +255,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) std::string currentdir = fs::current_path().generic_string(); - parser_init(); + parser_init(QApplication::instance()->applicationDirPath().toStdString()); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index d0d27ce..daed4e4 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -79,7 +79,7 @@ int main(int argc, char **argv) currentdir = fs::current_path().generic_string(); - parser_init(); + parser_init(QApplication::instance()->applicationDirPath().toStdString()); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/dumptest.cc b/tests/dumptest.cc index bc48011..cca4d82 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -86,7 +86,7 @@ int main(int argc, char **argv) currentdir = fs::current_path().generic_string(); - parser_init(); + parser_init(QApplication::instance()->applicationDirPath().toStdString()); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/echotest.cc b/tests/echotest.cc index 7f05149..96b8d1c 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -87,7 +87,7 @@ int main(int argc, char **argv) currentdir = fs::current_path().generic_string(); - parser_init(); + parser_init(QApplication::instance()->applicationDirPath().toStdString()); Context root_ctx; register_builtin(root_ctx); -- cgit v0.10.1 From 01103c44c04a10c2f1a507f6d318abd041f22437 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Wed, 4 Jan 2012 23:19:19 +0100 Subject: Added BBEdit/TextWrangler syntax highlighting module by Mike Thomson diff --git a/contrib/BBEdit-TextWrangler.txt b/contrib/BBEdit-TextWrangler.txt new file mode 100644 index 0000000..e15a980 --- /dev/null +++ b/contrib/BBEdit-TextWrangler.txt @@ -0,0 +1,5 @@ +BBEdit: +Install OpenSCAD.plist into ~/Library/Application Support/BBEdit/Language Modules + +TextWrangler: +Install OpenSCAD.plist into ~/Library/Application Support/TextWrangler/Language Modules diff --git a/contrib/OpenSCAD.plist b/contrib/OpenSCAD.plist new file mode 100644 index 0000000..2f8860c --- /dev/null +++ b/contrib/OpenSCAD.plist @@ -0,0 +1,119 @@ + + + + + BBEditDocumentType + CodelessLanguageModule + BBLMCanSpellCheckCodeRuns + + BBLMColorsSyntax + + BBLMIsCaseSensitive + + BBLMKeywordList + + ! + # + $fa + $fn + $fs + $t + % + * + assign + center + circle + color + cube + cylinder + difference + echo + for + function + hull + if + import_dxf + import_stl + include + intersection + intersection_for + linear_extrude + minkowski + mirror + module + multmatrix + polygon + polyhedron + projection + render + rotate + rotate_extrude + scale + sphere + square + str + surface + translate + union + use + + BBLMLanguageCode + Oscd + BBLMLanguageDisplayName + OpenSCAD + BBLMScansFunctions + + BBLMSuffixMap + + + BBLMLanguageSuffix + .scad + + + BBLMSupportsTextCompletion + + Language Features + + Close Block Comments + */ + Close Parameter Lists + ) + Close Statement Blocks + } + Close Strings 1 + " + Close Strings 2 + ' + End-of-line Ends Strings 1 + + End-of-line Ends Strings 2 + + Escape Char in Strings 1 + + Escape Char in Strings 2 + + Identifier and Keyword Characters + !$%*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz + Open Block Comments + /* + Open Line Comments + // + Open Parameter Lists + ( + Open Statement Blocks + { + Open Strings 1 + " + Open Strings 2 + ' + Prefix for Functions + function + Prefix for Procedures + module + Terminator for Prototypes 1 + + Terminator for Prototypes 2 + + + + -- cgit v0.10.1 From 666621e220dadfa5372661bdd35b2cb7d8098cca Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Wed, 4 Jan 2012 23:27:59 +0100 Subject: Additional fixes after merging with master diff --git a/tests/cgalstlsanitytest.cc b/tests/cgalstlsanitytest.cc index a078dff..e537b4a 100644 --- a/tests/cgalstlsanitytest.cc +++ b/tests/cgalstlsanitytest.cc @@ -26,6 +26,7 @@ #include "tests-common.h" #include "openscad.h" +#include "parsersettings.h" #include "node.h" #include "module.h" #include "context.h" @@ -49,10 +50,12 @@ #include #include +#include +namespace fs = boost::filesystem; + std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; -QString librarydir; using std::string; @@ -89,28 +92,11 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); - - currentdir = QDir::currentPath(); - - QDir libdir(QApplication::instance()->applicationDirPath()); -#ifdef Q_WS_MAC - libdir.cd("../Resources"); // Libraries can be bundled - if (!libdir.exists("libraries")) libdir.cd("../../.."); -#elif defined(Q_OS_UNIX) - if (libdir.cd("../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); - } else -#endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); - } + fs::path original_path = fs::current_path(); + + currentdir = fs::current_path().generic_string(); + + parser_init(QApplication::instance()->applicationDirPath().toStdString()); Context root_ctx; register_builtin(root_ctx); @@ -123,8 +109,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); AbstractNode *absolute_root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -139,7 +124,7 @@ int main(int argc, char **argv) CGAL_Nef_polyhedron N = cgalevaluator.evaluateCGALMesh(*root_node); - QDir::setCurrent(original_path.absolutePath()); + current_path(original_path); if (!N.empty()) { std::ofstream outfile; outfile.open(outfilename); -- cgit v0.10.1 From 11fb1f71dad9c7d744ff5bbe7c3ee017ed67ff41 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Wed, 4 Jan 2012 23:28:16 +0100 Subject: Additional fixes after merging with master diff --git a/src/module.h b/src/module.h index 557b7c5..6c6529b 100644 --- a/src/module.h +++ b/src/module.h @@ -65,7 +65,7 @@ public: void addChild(ModuleInstantiation *ch) { this->children.push_back(ch); } - static Module *compile_library(std::string filename); + static Module *compile_library(const std::string &filename); static void clear_library_cache(); typedef boost::unordered_map ModuleContainer; -- cgit v0.10.1 From 9495f11be0c8b36801016f881733d7b6617d184a Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Thu, 5 Jan 2012 00:00:29 +0100 Subject: Added Linux desktop icon and .desktop file from chrysn diff --git a/icons/icon-alpha.png b/icons/icon-alpha.png index 67b6e63..192e5f1 100644 Binary files a/icons/icon-alpha.png and b/icons/icon-alpha.png differ diff --git a/icons/icon.png b/icons/icon.png index 7912038..837ead9 100644 Binary files a/icons/icon.png and b/icons/icon.png differ diff --git a/icons/mask.png b/icons/mask.png index eea1027..15ce869 100644 Binary files a/icons/mask.png and b/icons/mask.png differ diff --git a/icons/openscad.desktop b/icons/openscad.desktop new file mode 100644 index 0000000..07df5aa --- /dev/null +++ b/icons/openscad.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Application +Version=1.0 +Name=OpenSCAD +Icon=openscad +Exec=openscad %f +Categories=Graphics;3DGraphics;Engineering; diff --git a/icons/openscad.png b/icons/openscad.png new file mode 100644 index 0000000..192e5f1 Binary files /dev/null and b/icons/openscad.png differ diff --git a/openscad.pro b/openscad.pro index b26122a..e980085 100644 --- a/openscad.pro +++ b/openscad.pro @@ -294,3 +294,11 @@ INSTALLS += examples libraries.path = $$PREFIX/share/openscad/libraries/ libraries.files = libraries/* INSTALLS += libraries + +applications.path = $$PREFIX/share/applications +applications.files = icons/openscad.desktop +INSTALLS += applications + +icons.path = $$PREFIX/share/pixmaps +icons.files = icons/openscad.png +INSTALLS += icons -- cgit v0.10.1 From 1acfe4e10be18c18762764c280fa07464c7a0a6c Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Thu, 5 Jan 2012 00:20:11 +0100 Subject: Added some recent bugfixes diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 295f6f4..59bb54b 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,6 +1,10 @@ OpenSCAD 2012.XX ================ +Bugfixes: +o use'ing an non-existing file sometimes crashed under Windows +o Better font handling: Ensure a monospace font is chosen as default + Deprecations: o The old include syntax "" without the include keyword is no longer supported and will cause a syntax error. -- cgit v0.10.1 From a7bb2229dc4a36b272fc60bb8244c125efef0032 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Wed, 4 Jan 2012 19:53:46 -0600 Subject: Use Qt's fontfind algorithm for default, so that QFontComboBox works properly diff --git a/src/Preferences.cc b/src/Preferences.cc index 4c43f2d..e05106b 100644 --- a/src/Preferences.cc +++ b/src/Preferences.cc @@ -47,16 +47,24 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent) // Setup default settings this->defaultmap["3dview/colorscheme"] = this->colorSchemeChooser->currentItem()->text(); + this->defaultmap["advanced/opencsg_show_warning"] = true; + this->defaultmap["advanced/enable_opencsg_opengl1x"] = true; + + // Setup default font (Try to use a nice monospace font) + QString fontfamily; #ifdef Q_WS_X11 - this->defaultmap["editor/fontfamily"] = "Mono"; + fontfamily = "Mono"; #elif defined (Q_WS_WIN) - this->defaultmap["editor/fontfamily"] = "Console"; + fontfamily = "Console"; #elif defined (Q_WS_MAC) - this->defaultmap["editor/fontfamily"] = "Monaco"; + fontfamily = "Monaco"; #endif + QFont font; + font.setStyleHint(QFont::TypeWriter); + font.setFamily(fontfamily); // this runs Qt's font matching algorithm + QString found_family(QFontInfo(font).family()); + this->defaultmap["editor/fontfamily"] = found_family; this->defaultmap["editor/fontsize"] = 12; - this->defaultmap["advanced/opencsg_show_warning"] = true; - this->defaultmap["advanced/enable_opencsg_opengl1x"] = true; // Toolbar QActionGroup *group = new QActionGroup(this); -- cgit v0.10.1 From c3a2dfcf47d3a88723dfcaa81ce35363a0d41b20 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Fri, 6 Jan 2012 18:56:03 -0600 Subject: fix typo in path to CMingw-cross-env.cmake in instructions diff --git a/tests/CMingw-cross-env.cmake b/tests/CMingw-cross-env.cmake index 09ec1d1..7dd2a05 100644 --- a/tests/CMingw-cross-env.cmake +++ b/tests/CMingw-cross-env.cmake @@ -10,7 +10,7 @@ # http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Cross-compiling_for_Windows_on_Linux_or_Mac_OS_X # - cross-compile openscad.exe, to verify your installation works properly. # - cd openscad/tests && mkdir build-mingw32 && cd build-mingw32 -# - cmake .. -DCMAKE_TOOLCHAIN_FILE=CMingw-cross-env.cmake \ +# - cmake .. -DCMAKE_TOOLCHAIN_FILE=../CMingw-cross-env.cmake \ # -DMINGW_CROSS_ENV_DIR= # - make should proceed as normal. # - now run 'ctest' on your *nix machine. -- cgit v0.10.1 From 7af27e183817181ec60b59b1d3270abd5f43f072 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sat, 7 Jan 2012 07:15:49 -0600 Subject: add CMAKE_RC_COMPILER to fix bug report by Brad Pitcher diff --git a/tests/CMingw-cross-env.cmake b/tests/CMingw-cross-env.cmake index 7dd2a05..7063be4 100644 --- a/tests/CMingw-cross-env.cmake +++ b/tests/CMingw-cross-env.cmake @@ -78,6 +78,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_C_COMPILER ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-gcc) set(CMAKE_CXX_COMPILER ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-g++) +set(CMAKE_RC_COMPILER ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-windres) set(QT_QMAKE_EXECUTABLE ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-qmake) set(PKG_CONFIG_EXECUTABLE ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-pkg-config) set(CMAKE_BUILD_TYPE RelWithDebInfo) -- cgit v0.10.1 From 1ff36169651f78e4810e1c2f5f5a19dc6c30a00d Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 8 Jan 2012 04:42:24 +0100 Subject: Drop possibly corrupt polyhedron after a minkowski error diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index a6b2f06..cc1c749 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -86,6 +86,11 @@ void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedr // union && difference assert triggered by testdata/scad/bugs/rotate-diff-nonmanifold-crash.scad std::string opstr = op == CGE_UNION ? "union" : op == CGE_INTERSECTION ? "intersection" : op == CGE_DIFFERENCE ? "difference" : op == CGE_MINKOWSKI ? "minkowski" : "UNKNOWN"; PRINTF("CGAL error in CGAL_Nef_polyhedron's %s operator: %s", opstr.c_str(), e.what()); + + // Minkowski errors can result in corrupt polyhedrons + if (op == CGE_MINKOWSKI) { + target = src; + } } CGAL::set_error_behaviour(old_behaviour); } -- cgit v0.10.1 From e20a7c261a9671d05d1cd4cea7334f2051123dfa Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 8 Jan 2012 13:27:31 +0100 Subject: Added test model causing a minkowski assert with a subsequent corrupt polyhedron diff --git a/testdata/scad/bugs/minkowski-crash.scad b/testdata/scad/bugs/minkowski-crash.scad new file mode 100644 index 0000000..46419ba --- /dev/null +++ b/testdata/scad/bugs/minkowski-crash.scad @@ -0,0 +1,26 @@ +/* + Originally reported by nop head 20120107: + This causes a CGAL assertion in minkowski on some platforms and CGAL versions: + o CGAL-3.6, 3.8 Linux + o Windows (OpenSCAD-2011.12 binaries) + + The problem is that minkowski leaves the target polyhedron in a corrupt state + causing a crash. This is worked around in CGALEvaluator::process(). + + CGAL-3.9 appears to just process forever. +*/ +$fn = 30; +minkowski() { + union() { + cube([10, 10, 10], center=true); + + cylinder(r=2, h=15, center=true); + + rotate([90, 0, 0]) + cylinder(r=2, h=15, center=true); + + rotate([0, 90, 0]) + cylinder(r=2, h=15, center=true); + } + sphere(3); +} -- cgit v0.10.1 From a5d3086dda34525c0a2529bb778590ff4f88e6db Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 8 Jan 2012 13:41:33 +0100 Subject: Mentioned confusing error reporting with errors in included files diff --git a/doc/TODO.txt b/doc/TODO.txt index 8f6d257..9479e69 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -175,10 +175,12 @@ o Misc - Is there a reason why modules like echo, empty if, empty for loop returns an empty AbstractNode instead of being ignored? - Dependency tracking of libraries (USE'd modules) isn't implemented. See Mail from nophead 20110823. -o Grammar +o Grammar/Parser - dim->name -> dim->label - A random(seed) function - linear_extrude()/rotate_extrude(): Cumbersome names? -> (extrude, revolve, lathe, sweep ?) + - If a compile error occurs in an included file, line numbers are global + and doesn't say in which file the error occurred. o Hollow donut problem When extruding a 2D CSG tree (e.g. a polygon with a hole), the hole information is lost when performing the extrusion. For linear -- cgit v0.10.1 From e271e958dcb09bfa2e02866e87a88a12c7464f91 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 8 Jan 2012 18:30:22 +0100 Subject: Force test output to fixed notation, otherwise the clamping will give wrong results for output in scientific notation diff --git a/src/value.cc b/src/value.cc index 5ea766c..1dcfa98 100644 --- a/src/value.cc +++ b/src/value.cc @@ -369,6 +369,7 @@ std::string Value::toString() const { std::stringstream tmp; tmp.precision(16); + tmp.setf(std::ios_base::fixed); tmp << this->num; std::string tmpstr = tmp.str(); if (tmpstr.size() > 16) tmpstr.erase(16); -- cgit v0.10.1 From c08f3afbbb76948f3c142dfac57d6663c0d102b3 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 8 Jan 2012 18:31:09 +0100 Subject: bugfix: Infinite loop in deg2rad/rad2deg when giving it an inf number, e.g. 1/0. Reported by Triffid Hunter. diff --git a/src/func.cc b/src/func.cc index 1138173..6686cb9 100644 --- a/src/func.cc +++ b/src/func.cc @@ -96,24 +96,14 @@ std::string BuiltinFunction::dump(const std::string &indent, const std::string & return dump.str(); } -static double deg2rad(double x) +static inline double deg2rad(double x) { - while (x < 0.0) - x += 360.0; - while (x >= 360.0) - x -= 360.0; - x = x * M_PI * 2.0 / 360.0; - return x; + return x * M_PI / 180.0; } -static double rad2deg(double x) +static inline double rad2deg(double x) { - x = x * 360.0 / (M_PI * 2.0); - while (x < 0.0) - x += 360.0; - while (x >= 360.0) - x -= 360.0; - return x; + return x * 180.0 / M_PI; } Value builtin_abs(const Context *, const std::vector&, const std::vector &args) -- cgit v0.10.1 From f3e6e8168bac6b14383d1d321de7dcf122e0b7de Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 8 Jan 2012 18:34:17 +0100 Subject: Added notes about two recent bugfixes diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 59bb54b..e025d9b 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -4,6 +4,8 @@ OpenSCAD 2012.XX Bugfixes: o use'ing an non-existing file sometimes crashed under Windows o Better font handling: Ensure a monospace font is chosen as default +o Division by zero caused hang in some cases (e.g. sin(1/0)) +o Larger minkowski operations sometimes caused a crash after a CGAL assert was thrown Deprecations: o The old include syntax "" without the include keyword is no -- cgit v0.10.1 From 28f5f7a91025a077dad07fe4c86f079ab9c735b7 Mon Sep 17 00:00:00 2001 From: Brad Pitcher Date: Sun, 8 Jan 2012 11:40:04 -0800 Subject: added tests passing infinity to various functions diff --git a/testdata/scad/misc/inf-tests.scad b/testdata/scad/misc/inf-tests.scad new file mode 100644 index 0000000..87b6823 --- /dev/null +++ b/testdata/scad/misc/inf-tests.scad @@ -0,0 +1,23 @@ +echo(1/0); +echo(-1/0); +echo(sin(1/0)); +echo(cos(1/0)); +echo(tan(1/0)); +echo(asin(1/0)); +echo(acos(1/0)); +echo(atan(1/0)); +echo(atan(-1/0)); +echo(atan2(1/0, -1/0)); +echo(ceil(1/0)); +echo(floor(1/0)); +echo(exp(2, 1/0)); +echo(ln(1/0)); +echo(log(1/0)); +echo(max(-1/0, 1/0)); +echo(min(-1/0, 1/0)); +echo(pow(2, 1/0)); +echo(round(1/0)); +echo(sign(1/0)); +echo(sign(-1/0)); +echo(sqrt(1/0)); +echo(sqrt(-1/0)); \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index edab744..5343252 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -599,7 +599,8 @@ list(APPEND ECHO_FILES ${FUNCTION_FILES} ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/builtin-tests.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/dim-all.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-test.scad - ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-indexing.scad) + ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-indexing.scad + ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/inf-tests.scad) list(APPEND DUMPTEST_FILES ${MINIMAL_FILES} ${FEATURES_FILES} ${EXAMPLE_FILES}) list(APPEND DUMPTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/escape-test.scad) diff --git a/tests/regression/echotest/inf-tests-expected.txt b/tests/regression/echotest/inf-tests-expected.txt new file mode 100644 index 0000000..adac240 --- /dev/null +++ b/tests/regression/echotest/inf-tests-expected.txt @@ -0,0 +1,23 @@ +ECHO: inf +ECHO: -inf +ECHO: -nan +ECHO: -nan +ECHO: -nan +ECHO: nan +ECHO: nan +ECHO: 90.0000000000000 +ECHO: -90.000000000000 +ECHO: 135.000000000000 +ECHO: inf +ECHO: inf +ECHO: undef +ECHO: inf +ECHO: inf +ECHO: inf +ECHO: -inf +ECHO: inf +ECHO: inf +ECHO: 1.00000000000000 +ECHO: -1.0000000000000 +ECHO: inf +ECHO: -nan -- cgit v0.10.1 From ad338d3e46eac0d0277a7000c48972d47f6c0091 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 9 Jan 2012 01:44:01 +0100 Subject: Another try at fixing double-to-text conversion for testing diff --git a/src/value.cc b/src/value.cc index c9440ae..47fac1e 100644 --- a/src/value.cc +++ b/src/value.cc @@ -368,11 +368,17 @@ std::string Value::toString() const // across platforms for testing purposes. { std::stringstream tmp; - tmp.precision(16); + tmp.precision(12); tmp.setf(std::ios_base::fixed); tmp << this->num; std::string tmpstr = tmp.str(); - if (tmpstr.size() > 16) tmpstr.erase(16); + size_t endpos = tmpstr.find_last_not_of('0'); + if (endpos >= 0 && tmpstr[endpos] == '.') endpos--; + tmpstr = tmpstr.substr(0, endpos+1); + size_t dotpos = tmpstr.find('.'); + if (dotpos != std::string::npos) { + if (tmpstr.size() - dotpos > 12) tmpstr.erase(dotpos + 12); + } stream << tmpstr; } #else diff --git a/testdata/scad/functions/inf-tests.scad b/testdata/scad/functions/inf-tests.scad new file mode 100644 index 0000000..87b6823 --- /dev/null +++ b/testdata/scad/functions/inf-tests.scad @@ -0,0 +1,23 @@ +echo(1/0); +echo(-1/0); +echo(sin(1/0)); +echo(cos(1/0)); +echo(tan(1/0)); +echo(asin(1/0)); +echo(acos(1/0)); +echo(atan(1/0)); +echo(atan(-1/0)); +echo(atan2(1/0, -1/0)); +echo(ceil(1/0)); +echo(floor(1/0)); +echo(exp(2, 1/0)); +echo(ln(1/0)); +echo(log(1/0)); +echo(max(-1/0, 1/0)); +echo(min(-1/0, 1/0)); +echo(pow(2, 1/0)); +echo(round(1/0)); +echo(sign(1/0)); +echo(sign(-1/0)); +echo(sqrt(1/0)); +echo(sqrt(-1/0)); \ No newline at end of file diff --git a/testdata/scad/misc/inf-tests.scad b/testdata/scad/misc/inf-tests.scad deleted file mode 100644 index 87b6823..0000000 --- a/testdata/scad/misc/inf-tests.scad +++ /dev/null @@ -1,23 +0,0 @@ -echo(1/0); -echo(-1/0); -echo(sin(1/0)); -echo(cos(1/0)); -echo(tan(1/0)); -echo(asin(1/0)); -echo(acos(1/0)); -echo(atan(1/0)); -echo(atan(-1/0)); -echo(atan2(1/0, -1/0)); -echo(ceil(1/0)); -echo(floor(1/0)); -echo(exp(2, 1/0)); -echo(ln(1/0)); -echo(log(1/0)); -echo(max(-1/0, 1/0)); -echo(min(-1/0, 1/0)); -echo(pow(2, 1/0)); -echo(round(1/0)); -echo(sign(1/0)); -echo(sign(-1/0)); -echo(sqrt(1/0)); -echo(sqrt(-1/0)); \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e2f5699..6a3b432 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -600,8 +600,7 @@ list(APPEND ECHO_FILES ${FUNCTION_FILES} ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/builtin-tests.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/dim-all.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-test.scad - ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-indexing.scad - ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/inf-tests.scad) + ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-indexing.scad) list(APPEND DUMPTEST_FILES ${MINIMAL_FILES} ${FEATURES_FILES} ${EXAMPLE_FILES}) list(APPEND DUMPTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/escape-test.scad) diff --git a/tests/regression/echotest/builtin-tests-expected.txt b/tests/regression/echotest/builtin-tests-expected.txt index 0e8d1a7..385b0dc 100644 --- a/tests/regression/echotest/builtin-tests-expected.txt +++ b/tests/regression/echotest/builtin-tests-expected.txt @@ -1 +1 @@ -ECHO: 3.14159265358979 +ECHO: 3.14159265359 diff --git a/tests/regression/echotest/dim-all-expected.txt b/tests/regression/echotest/dim-all-expected.txt index d8c3269..60f36d5 100644 --- a/tests/regression/echotest/dim-all-expected.txt +++ b/tests/regression/echotest/dim-all-expected.txt @@ -1,16 +1,16 @@ WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: linearX = 51.4495755427526 +ECHO: linearX = 51.44957554275 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: linearY = 29.1302546743484 +ECHO: linearY = 29.13025467434 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: aligned = 60.0000000000000 +ECHO: aligned = 60 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: ordinateX = -49.175424457247 +ECHO: ordinateX = -49.17542445724 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: ordinateY = 30.8697453256515 +ECHO: ordinateY = 30.86974532565 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. ECHO: radius = 60 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. ECHO: diameter = 120 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: arc = 59.0362434679264 +ECHO: arc = 59.03624346792 diff --git a/tests/regression/echotest/inf-tests-expected.txt b/tests/regression/echotest/inf-tests-expected.txt index adac240..7ac4fe9 100644 --- a/tests/regression/echotest/inf-tests-expected.txt +++ b/tests/regression/echotest/inf-tests-expected.txt @@ -1,13 +1,13 @@ ECHO: inf ECHO: -inf -ECHO: -nan -ECHO: -nan -ECHO: -nan ECHO: nan ECHO: nan -ECHO: 90.0000000000000 -ECHO: -90.000000000000 -ECHO: 135.000000000000 +ECHO: nan +ECHO: nan +ECHO: nan +ECHO: 90 +ECHO: -90 +ECHO: 135 ECHO: inf ECHO: inf ECHO: undef @@ -17,7 +17,7 @@ ECHO: inf ECHO: -inf ECHO: inf ECHO: inf -ECHO: 1.00000000000000 -ECHO: -1.0000000000000 +ECHO: 1 +ECHO: -1 ECHO: inf -ECHO: -nan +ECHO: nan diff --git a/tests/regression/echotest/parser-tests-expected.txt b/tests/regression/echotest/parser-tests-expected.txt index fb04907..615726a 100644 --- a/tests/regression/echotest/parser-tests-expected.txt +++ b/tests/regression/echotest/parser-tests-expected.txt @@ -2,4 +2,4 @@ ECHO: 0.1 ECHO: 2 ECHO: 1100 ECHO: 0.021 -ECHO: 1.1e-13 +ECHO: 0 -- cgit v0.10.1 From 19ea0f0427a40068a2ee31127c5103a5cc55f5b9 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 9 Jan 2012 03:06:44 +0100 Subject: Don't use native() to extract strings from boost::filesystem::path() since that will use wchar under Windows diff --git a/src/context.cc b/src/context.cc index 57df902..354195f 100644 --- a/src/context.cc +++ b/src/context.cc @@ -176,7 +176,7 @@ AbstractNode *Context::evaluate_module(const ModuleInstantiation &inst) const std::string Context::getAbsolutePath(const std::string &filename) const { if (!filename.empty()) { - return absolute(path(this->document_path) / filename).native(); + return absolute(path(this->document_path) / filename).string(); } else { return filename; diff --git a/src/handle_dep.cc b/src/handle_dep.cc index da95a67..d642555 100644 --- a/src/handle_dep.cc +++ b/src/handle_dep.cc @@ -18,7 +18,7 @@ void handle_dep(const std::string &filename) dependencies.insert(filename); } else { - dependencies.insert((current_path() / filepath).native()); + dependencies.insert((current_path() / filepath).string()); } if (!exists(filepath) && make_command) { std::stringstream buf; diff --git a/src/import.cc b/src/import.cc index c55c983..435d06d 100644 --- a/src/import.cc +++ b/src/import.cc @@ -81,7 +81,7 @@ AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiati std::string filename = c.getAbsolutePath(v.text); import_type_e actualtype = this->type; if (actualtype == TYPE_UNKNOWN) { - std::string ext = boost::algorithm::to_lower_copy(path(filename).extension().native()); + std::string ext = boost::algorithm::to_lower_copy(path(filename).extension().string()); if (ext == ".stl") actualtype = TYPE_STL; else if (ext == ".off") actualtype = TYPE_OFF; else if (ext == ".dxf") actualtype = TYPE_DXF; -- cgit v0.10.1 From da9e545366ba9c0ec9fd7117e9fa3c9cacaad7f8 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 9 Jan 2012 03:11:53 +0100 Subject: updated diff --git a/libraries/MCAD b/libraries/MCAD index f32906a..83205f0 160000 --- a/libraries/MCAD +++ b/libraries/MCAD @@ -1 +1 @@ -Subproject commit f32906ae90b1326a2d7241994e18c6f796799a95 +Subproject commit 83205f0511a8dafbc1f03ef8444b33db862d283f -- cgit v0.10.1 From 5044ea928d72da800d11b2b80f6148265c13d10f Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 9 Jan 2012 03:20:27 +0100 Subject: typo: ouput->output diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index fcf88d8..65e9127 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -116,7 +116,7 @@ po::variables_map parse_options(int argc, char *argv[]) // po::options_description hidden("Hidden options"); // hidden.add_options() ("input-file", po::value< vector >(), "input file") - ("output-file", po::value< vector >(), "ouput file"); + ("output-file", po::value< vector >(), "output file"); po::positional_options_description p; p.add("input-file", 1).add("output-file", 1); -- cgit v0.10.1