diff options
-rw-r--r-- | boost.pri | 6 | ||||
-rwxr-xr-x | scripts/macosx-build-dependencies.sh | 4 | ||||
-rw-r--r-- | src/context.cc | 7 | ||||
-rw-r--r-- | src/dxfdim.cc | 17 | ||||
-rw-r--r-- | src/handle_dep.cc | 13 | ||||
-rw-r--r-- | src/import.cc | 78 | ||||
-rw-r--r-- | src/linearextrude.cc | 2 | ||||
-rw-r--r-- | src/rotateextrude.cc | 2 | ||||
-rw-r--r-- | src/surface.cc | 55 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 2 |
10 files changed, 111 insertions, 75 deletions
@@ -10,7 +10,7 @@ boost { } win32:!CONFIG(mingw-cross-env) { - 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 } CONFIG(mingw-cross-env) { @@ -26,14 +26,14 @@ boost { BMT_TEST3 = $$BOOST_DIR/lib/libboost*thread-mt* exists($$BMT_TEST1)|exists($$BMT_TEST2)|exists($$BMT_TEST3) { - LIBS += -lboost_thread-mt -lboost_program_options-mt + LIBS += -lboost_thread-mt -lboost_program_options-mt -lboost_filesystem-mt -lboost_system-mt -lboost_regex-mt BOOST_IS_MT = true } } unix|macx { isEmpty(BOOST_IS_MT) { - LIBS += -lboost_thread -lboost_program_options + 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 bc42058..42dbaac 100755 --- a/scripts/macosx-build-dependencies.sh +++ b/scripts/macosx-build-dependencies.sh @@ -140,12 +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 + ./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/src/context.cc b/src/context.cc index 6d0cb3a..df884de 100644 --- a/src/context.cc +++ b/src/context.cc @@ -30,9 +30,9 @@ #include "module.h" #include "builtin.h" #include "printutils.h" -#include <QFileInfo> -#include <QDir> #include <boost/foreach.hpp> +#include <boost/filesystem.hpp> +using namespace boost::filesystem; std::vector<const Context*> 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 <QDateTime> -#include <QFileInfo> #include <sstream> +#include <boost/filesystem.hpp> +using namespace boost::filesystem; + boost::unordered_map<std::string,Value> dxf_dim_cache; boost::unordered_map<std::string,Value> dxf_cross_cache; @@ -62,12 +63,10 @@ Value builtin_dxf_dim(const Context *ctx, const std::vector<std::string> &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<std::string> &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 <string> #include <sstream> #include <QString> -#include <QDir> -#include <QSet> #include <stdlib.h> // for system() #include <boost/unordered_set.hpp> #include <boost/foreach.hpp> +#include <boost/filesystem.hpp> +using namespace boost::filesystem; boost::unordered_set<std::string> 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/src/import.cc b/src/import.cc index b77c120..07100e3 100644 --- a/src/import.cc +++ b/src/import.cc @@ -46,6 +46,11 @@ #include <fstream> #include <sstream> #include <assert.h> +#include <boost/algorithm/string.hpp> +#include <boost/regex.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/filesystem.hpp> +using namespace boost::filesystem; #include <boost/assign/std/vector.hpp> using namespace boost::assign; // bring 'operator+=()' into scope @@ -79,10 +84,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); @@ -117,41 +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(); - 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+"); - f.readLine(); - while (!f.atEnd()) - { - QString line = QString(f.readLine()).remove("\n").remove("\r"); - 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 (line.contains("outer loop")) { + } + if (boost::regex_search(line, ex_outer)) { +// if (line.contains("outer loop")) { i = 0; continue; } - 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<double>(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]); @@ -162,6 +188,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *evaluator) const } else { +/* f.read(80-5+4); while (1) { #ifdef _MSC_VER @@ -189,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); } +*/ } } 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 <boost/assign/std/vector.hpp> using namespace boost::assign; // bring 'operator+=()' into scope -#include <QFileInfo> - 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 <boost/assign/std/vector.hpp> using namespace boost::assign; // bring 'operator+=()' into scope -#include <QFileInfo> - class RotateExtrudeModule : public AbstractModule { public: diff --git a/src/surface.cc b/src/surface.cc index 39d1972..fe1c6aa 100644 --- a/src/surface.cc +++ b/src/surface.cc @@ -33,11 +33,13 @@ #include "handle_dep.h" // handle_dep() #include "visitor.h" -#include <QFile> -#include <QRegExp> -#include <QStringList> #include <sstream> +#include <fstream> +#include <boost/foreach.hpp> #include <boost/unordered_map.hpp> +#include <boost/tokenizer.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/algorithm/string.hpp> #include <boost/assign/std/vector.hpp> 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<std::pair<int,int>,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<boost::char_separator<char> > tokenizer; + boost::char_separator<char> 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<double>(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++; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a8ab9b9..c6db700 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -89,7 +89,7 @@ endif() # Update this if FindBoost.cmake gets out of sync with the current boost release # set(Boost_ADDITIONAL_VERSIONS "1.47.0" "1.46.0") -find_package( Boost 1.35.0 COMPONENTS thread program_options REQUIRED) +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:") |