From dccc039211eebe3f69c935557bd56abae323c26f Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 12 Mar 2013 01:14:58 -0400 Subject: Got rid of remaining Qt dependencies. The test framework should now be Qt-free diff --git a/openscad.pro b/openscad.pro index d9442d4..42b8ef0 100644 --- a/openscad.pro +++ b/openscad.pro @@ -247,6 +247,7 @@ HEADERS += src/version_check.h \ src/Camera.h \ src/system-gl.h \ src/stl-utils.h \ + src/boost-utils.h \ src/svg.h \ \ src/lodepng.h \ @@ -291,6 +292,7 @@ SOURCES += src/version_check.cc \ src/progress.cc \ src/parsersettings.cc \ src/stl-utils.cc \ + src/boost-utils.cc \ \ src/nodedumper.cc \ src/traverser.cc \ diff --git a/src/boost-utils.cc b/src/boost-utils.cc new file mode 100644 index 0000000..f81917a --- /dev/null +++ b/src/boost-utils.cc @@ -0,0 +1,42 @@ +#include "boost-utils.h" +#include +#include + +fs::path relativePath(const fs::path &path, const fs::path &relative_to) +{ + // create absolute paths + fs::path p = fs::absolute(path); + fs::path r = fs::absolute(relative_to); + + // if root paths are different, return absolute path + if (p.root_path() != r.root_path()) + return p; + + // initialize relative path + fs::path result; + + // find out where the two paths diverge + fs::path::const_iterator itr_path = p.begin(); + fs::path::const_iterator itr_relative_to = r.begin(); + while (*itr_path == *itr_relative_to && itr_path != p.end() && itr_relative_to != r.end()) { + ++itr_path; + ++itr_relative_to; + } + + // add "../" for each remaining token in relative_to + if (itr_relative_to != r.end()) { + ++itr_relative_to; + while (itr_relative_to != r.end()) { + result /= ".."; + ++itr_relative_to; + } + } + + // add remaining path + while (itr_path != p.end()) { + result /= *itr_path; + ++itr_path; + } + + return result; +} diff --git a/src/boost-utils.h b/src/boost-utils.h new file mode 100644 index 0000000..c431857 --- /dev/null +++ b/src/boost-utils.h @@ -0,0 +1,8 @@ +#ifndef BOOST_UTILS_H_ +#define BOOST_UTILS_H_ + +#include +namespace fs = boost::filesystem; +fs::path relativePath(const fs::path &path, const fs::path &relative_to); + +#endif diff --git a/src/dxfdata.cc b/src/dxfdata.cc index f34af51..be982ff 100644 --- a/src/dxfdata.cc +++ b/src/dxfdata.cc @@ -41,8 +41,9 @@ #include #include -#include #include "value.h" +#include "boost-utils.h" +#include "boosty.h" /*! \class DxfData @@ -389,10 +390,10 @@ DxfData::DxfData(double fn, double fs, double fa, BOOST_FOREACH(const EntityList::value_type &i, unsupported_entities_list) { if (layername.empty()) { PRINTB("WARNING: Unsupported DXF Entity '%s' (%x) in %s.", - i.first % i.second % QuotedString(QDir::current().relativeFilePath(QString::fromLocal8Bit(filename.c_str())).toLocal8Bit().constData())); + i.first % i.second % QuotedString(boosty::stringy(relativePath(filename, fs::current_path())))); } else { PRINTB("WARNING: Unsupported DXF Entity '%s' (%x) in layer '%s' of %s.", - i.first % i.second % layername % QuotedString(QDir::current().relativeFilePath(QString::fromLocal8Bit(filename.c_str())).toLocal8Bit().constData())); + i.first % i.second % layername % QuotedString(boosty::stringy(relativePath(filename, fs::current_path())))); } } diff --git a/src/dxftess-glu.cc b/src/dxftess-glu.cc index 1a8bfa5..941dbed 100644 --- a/src/dxftess-glu.cc +++ b/src/dxftess-glu.cc @@ -3,14 +3,11 @@ #include "polyset.h" #include "grid.h" #include +#include #include "system-gl.h" #include "mathc99.h" -#include -#include -#include - #ifdef WIN32 # define STDCALL __stdcall #else @@ -31,7 +28,7 @@ struct tess_triangle { static GLenum tess_type; static int tess_count; -static QVector tess_tri; +static std::vector tess_tri; static GLdouble *tess_p1, *tess_p2; static void STDCALL tess_vertex(void *vertex_data) @@ -48,7 +45,7 @@ static void STDCALL tess_vertex(void *vertex_data) tess_p2 = p; } if (tess_count > 1) { - tess_tri.append(tess_triangle(tess_p1, tess_p2, p)); + tess_tri.push_back(tess_triangle(tess_p1, tess_p2, p)); tess_p2 = p; } } @@ -61,9 +58,9 @@ static void STDCALL tess_vertex(void *vertex_data) } if (tess_count > 1) { if (tess_count % 2 == 1) { - tess_tri.append(tess_triangle(tess_p2, tess_p1, p)); + tess_tri.push_back(tess_triangle(tess_p2, tess_p1, p)); } else { - tess_tri.append(tess_triangle(tess_p1, tess_p2, p)); + tess_tri.push_back(tess_triangle(tess_p1, tess_p2, p)); } tess_p1 = tess_p2; tess_p2 = p; @@ -77,7 +74,7 @@ static void STDCALL tess_vertex(void *vertex_data) tess_p2 = p; } if (tess_count == 2) { - tess_tri.append(tess_triangle(tess_p1, tess_p2, p)); + tess_tri.push_back(tess_triangle(tess_p1, tess_p2, p)); tess_count = -1; } } @@ -214,7 +211,7 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_trian tess_tri.clear(); - QList vl; + std::list vl; gluTessBeginPolygon(tobj, NULL); @@ -225,7 +222,7 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_trian gluTessNormal(tobj, 0, 0, +1); } - Grid3d< QPair > point_to_path(GRID_COARSE); + Grid3d< std::pair > point_to_path(GRID_COARSE); for (int i = 0; i < dxf.paths.size(); i++) { if (!dxf.paths[i].is_closed) @@ -234,12 +231,12 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_trian for (int j = 1; j < dxf.paths[i].indices.size(); j++) { point_to_path.data(dxf.points[dxf.paths[i].indices[j]][0], dxf.points[dxf.paths[i].indices[j]][1], - h) = QPair(i, j); - vl.append(tess_vdata()); - vl.last().v[0] = dxf.points[dxf.paths[i].indices[j]][0]; - vl.last().v[1] = dxf.points[dxf.paths[i].indices[j]][1]; - vl.last().v[2] = h; - gluTessVertex(tobj, vl.last().v, vl.last().v); + h) = std::pair(i, j); + vl.push_back(tess_vdata()); + vl.back().v[0] = dxf.points[dxf.paths[i].indices[j]][0]; + vl.back().v[1] = dxf.points[dxf.paths[i].indices[j]][1]; + vl.back().v[2] = h; + gluTessVertex(tobj, vl.back().v, vl.back().v); } gluTessEndContour(tobj); } @@ -263,7 +260,7 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_trian point_on_line(tess_tri[i].p[1], tess_tri[i].p[2], tess_tri[i].p[0]) || point_on_line(tess_tri[i].p[2], tess_tri[i].p[0], tess_tri[i].p[1])) { // printf("DEBUG: Removed triangle\n"); - tess_tri.remove(i--); + tess_tri.erase(tess_tri.begin() + i--); } } @@ -277,13 +274,13 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_trian if (do_triangle_splitting) { bool added_triangles = true; - typedef QPair QPair_ii; - QHash tri_by_atan2; + typedef std::pair pair_ii; + boost::unordered_multimap tri_by_atan2; for (int i = 0; i < tess_tri.size(); i++) for (int j = 0; j < 3; j++) { int ai = (int)round(atan2(fabs(tess_tri[i].p[(j+1)%3][0] - tess_tri[i].p[j][0]), fabs(tess_tri[i].p[(j+1)%3][1] - tess_tri[i].p[j][1])) / 0.001); - tri_by_atan2.insertMulti(ai, QPair(i, j)); + tri_by_atan2.emplace(ai, std::pair(i, j)); } while (added_triangles) { @@ -294,20 +291,23 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_trian for (int i = 0; i < tess_tri.size(); i++) for (int k = 0; k < 3; k++) { - QHash possible_neigh; + boost::unordered_map possible_neigh; int ai = (int)floor(atan2(fabs(tess_tri[i].p[(k+1)%3][0] - tess_tri[i].p[k][0]), fabs(tess_tri[i].p[(k+1)%3][1] - tess_tri[i].p[k][1])) / 0.001 - 0.5); for (int j = 0; j < 2; j++) { - foreach (const QPair_ii &jl, tri_by_atan2.values(ai+j)) - if (i != jl.first) - possible_neigh[jl] = jl; + for (boost::unordered_multimap::iterator it = tri_by_atan2.find(ai+j); + it != tri_by_atan2.end(); + it++) { + if (i != it->first) possible_neigh[it->second] = it->second; + } } #ifdef DEBUG_TRIANGLE_SPLITTING printf("%d/%d: %d\n", i, k, possible_neigh.size()); #endif - foreach (const QPair_ii &jl, possible_neigh) { - int j = jl.first; - for (int l = jl.second; l != (jl.second + 2) % 3; l = (l + 1) % 3) + typedef std::pair ElemPair; + BOOST_FOREACH (const ElemPair &elem, possible_neigh) { + int j = elem.first.first; + for (int l = elem.first.second; l != (elem.first.second + 2) % 3; l = (l + 1) % 3) if (point_on_line(tess_tri[i].p[k], tess_tri[j].p[l], tess_tri[i].p[(k+1)%3])) { #ifdef DEBUG_TRIANGLE_SPLITTING printf("%% %f %f %f %f %f %f [%d %d]\n", @@ -316,18 +316,18 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_trian tess_tri[i].p[(k+1)%3][0], tess_tri[i].p[(k+1)%3][1], i, j); #endif - tess_tri.append(tess_triangle(tess_tri[j].p[l], + tess_tri.push_back(tess_triangle(tess_tri[j].p[l], tess_tri[i].p[(k+1)%3], tess_tri[i].p[(k+2)%3])); for (int m = 0; m < 2; m++) { - int ai = (int)round(atan2(fabs(tess_tri.last().p[(m+1)%3][0] - tess_tri.last().p[m][0]), - fabs(tess_tri.last().p[(m+1)%3][1] - tess_tri.last().p[m][1])) / 0.001 ); - tri_by_atan2.insertMulti(ai, QPair(tess_tri.size()-1, m)); + int ai = (int)round(atan2(fabs(tess_tri.back().p[(m+1)%3][0] - tess_tri.back().p[m][0]), + fabs(tess_tri.back().p[(m+1)%3][1] - tess_tri.back().p[m][1])) / 0.001 ); + tri_by_atan2.emplace(ai, std::pair(tess_tri.size()-1, m)); } tess_tri[i].p[(k+1)%3] = tess_tri[j].p[l]; for (int m = 0; m < 2; m++) { int ai = (int)round(atan2(fabs(tess_tri[i].p[(m+1)%3][0] - tess_tri[i].p[m][0]), fabs(tess_tri[i].p[(m+1)%3][1] - tess_tri[i].p[m][1])) / 0.001 ); - tri_by_atan2.insertMulti(ai, QPair(i, m)); + tri_by_atan2.emplace(ai, std::pair(i, m)); } added_triangles = true; } diff --git a/src/parsersettings.cc b/src/parsersettings.cc index a757ba1..8d82744 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -3,8 +3,9 @@ #include #include "boosty.h" #include -#include // Needed for Q_ defines - move the offending code somewhere else +#ifdef __APPLE__ #include "CocoaUtils.h" +#endif namespace fs = boost::filesystem; diff --git a/src/value.cc b/src/value.cc index f14f826..bec803a 100644 --- a/src/value.cc +++ b/src/value.cc @@ -34,12 +34,12 @@ #include #include #include - -#include +#include "boost-utils.h" +#include "boosty.h" std::ostream &operator<<(std::ostream &stream, const Filename &filename) { - stream << QuotedString(QDir::current().relativeFilePath(QString::fromLocal8Bit(filename.c_str())).toLocal8Bit().constData()); + stream << QuotedString(boosty::stringy(relativePath(filename, fs::current_path()))); return stream; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5eecaae..8fd079f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -179,28 +179,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") FIND_LIBRARY(COCOA_LIBRARY Cocoa REQUIRED) endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") -# Qt4 - -set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON) -find_package(OpenGL REQUIRED) -if ( "${OPENGL_glu_LIBRARY}" MATCHES "NOTFOUND" ) - # GLU and Mesa split in late 2012 so some systems dont have GLU - find_library(OPENGL_glu_LIBRARY GLU HINTS "$ENV{OPENSCAD_LIBRARIES}/lib" REQUIRED) - set( OPENGL_LIBRARY ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARY} ) -endif() - -if (MINGW_CROSS_ENV_DIR) - mingw_cross_env_find_qt() - mingw_cross_env_info() - include_directories( ${QT_INCLUDE_DIRS} ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QT_CFLAGS_OTHER}") -else() - find_package(Qt4 COMPONENTS QtCore REQUIRED) - include(${QT_USE_FILE}) -endif() - -set(CMAKE_INCLUDE_DIRECTORIES_BEFORE OFF) - # Eigen @@ -268,6 +246,8 @@ else() inclusion(EIGEN_DIR EIGEN_INCLUDE_DIR) endif() +# OpenGL +find_package(OpenGL REQUIRED) # OpenCSG if (NOT $ENV{OPENCSGDIR} STREQUAL "") @@ -444,6 +424,7 @@ set(CORE_SOURCES ../src/rotateextrude.cc ../src/printutils.cc ../src/progress.cc + ../src/boost-utils.cc ${FLEX_OpenSCADlexer_OUTPUTS} ${BISON_OpenSCADparser_OUTPUTS}) diff --git a/tests/cgalcachetest.cc b/tests/cgalcachetest.cc index 3a0a855..b7e51b5 100644 --- a/tests/cgalcachetest.cc +++ b/tests/cgalcachetest.cc @@ -40,7 +40,6 @@ #include "PolySetCGALEvaluator.h" #include "CGALCache.h" -#include #ifndef _MSC_VER #include #endif @@ -57,7 +56,6 @@ namespace po = boost::program_options; std::string commandline_commands; std::string currentdir; -QString examplesdir; using std::string; @@ -124,13 +122,12 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); - QCoreApplication app(argc, argv); fs::path original_path = fs::current_path(); - currentdir = boosty::stringy( fs::current_path() ); + currentdir = boosty::stringy(fs::current_path()); - parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); + add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index 52205fd..947a231 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -43,7 +43,6 @@ #include "cgal.h" #include "OffscreenView.h" -#include #ifndef _MSC_VER #include #endif @@ -57,7 +56,6 @@ namespace fs = boost::filesystem; std::string commandline_commands; std::string currentdir; -QString examplesdir; using std::string; @@ -97,13 +95,12 @@ int main(int argc, char **argv) #endif Builtins::instance()->initialize(); - QCoreApplication app(argc, argv); fs::path original_path = fs::current_path(); currentdir = boosty::stringy( fs::current_path() ); - parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); + add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgalstlsanitytest.cc b/tests/cgalstlsanitytest.cc index 2815463..228bfde 100644 --- a/tests/cgalstlsanitytest.cc +++ b/tests/cgalstlsanitytest.cc @@ -38,11 +38,6 @@ #include "CGALEvaluator.h" #include "PolySetCGALEvaluator.h" -#include -#include -#include -#include -#include #ifndef _MSC_VER #include #endif @@ -56,7 +51,6 @@ namespace fs = boost::filesystem; std::string commandline_commands; std::string currentdir; -QString examplesdir; using std::string; @@ -83,13 +77,12 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); - QCoreApplication app(argc, argv); fs::path original_path = fs::current_path(); currentdir = boosty::stringy( fs::current_path() ); - parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); + add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc index 4a15050..9c8c090 100644 --- a/tests/cgaltest.cc +++ b/tests/cgaltest.cc @@ -38,7 +38,6 @@ #include "CGALEvaluator.h" #include "PolySetCGALEvaluator.h" -#include #ifndef _MSC_VER #include #endif @@ -52,7 +51,6 @@ namespace fs = boost::filesystem; std::string commandline_commands; std::string currentdir; -QString examplesdir; using std::string; @@ -76,13 +74,12 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); - QCoreApplication app(argc, argv); fs::path original_path = fs::current_path(); currentdir = boosty::stringy( fs::current_path() ); - parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); + add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index e793c4a..864ba5d 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -38,7 +38,6 @@ #include "Tree.h" #include "csgterm.h" -#include #ifndef _MSC_VER #include #endif @@ -53,7 +52,6 @@ namespace fs = boost::filesystem; std::string commandline_commands; std::string currentdir; -QString examplesdir; using std::cout; @@ -71,13 +69,12 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); - QCoreApplication app(argc, argv); fs::path original_path = fs::current_path(); currentdir = boosty::stringy( fs::current_path() ); - parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); + add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 7583a41..1e518e2 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -23,9 +23,6 @@ #include "csgtermnormalizer.h" #include "OffscreenView.h" -#include -#include - #include #include @@ -128,14 +125,12 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) Builtins::instance()->initialize(); - QCoreApplication app(argc, argv); - fs::path original_path = fs::current_path(); std::string currentdir = boosty::stringy( fs::current_path() ); - parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); + add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index e050232..6a72dff 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -37,7 +37,6 @@ #include "builtin.h" #include "Tree.h" -#include #ifndef _MSC_VER #include #endif @@ -52,7 +51,6 @@ namespace fs = boost::filesystem; std::string commandline_commands; std::string currentdir; -QString examplesdir; void csgTree(CSGTextCache &cache, const AbstractNode &root) { @@ -75,13 +73,12 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); - QCoreApplication app(argc, argv); fs::path original_path = fs::current_path(); currentdir = boosty::stringy( fs::current_path() ); - parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); + add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/dumptest.cc b/tests/dumptest.cc index b75a2e2..4ddefe2 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -35,7 +35,6 @@ #include "builtin.h" #include "Tree.h" -#include #ifndef _MSC_VER #include #endif @@ -50,7 +49,6 @@ namespace fs = boost::filesystem; std::string commandline_commands; std::string currentdir; -QString examplesdir; using std::string; @@ -81,13 +79,12 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); - QCoreApplication app(argc, argv); fs::path original_path = fs::current_path(); currentdir = boosty::stringy(fs::current_path()); - parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); + add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/echotest.cc b/tests/echotest.cc index bf2f4a4..af4942b 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -34,7 +34,6 @@ #include "builtin.h" #include "printutils.h" -#include #ifndef _MSC_VER #include #endif @@ -49,7 +48,6 @@ namespace fs = boost::filesystem; std::string commandline_commands; std::string currentdir; -QString examplesdir; using std::string; @@ -83,13 +81,12 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); - QCoreApplication app(argc, argv); fs::path original_path = fs::current_path(); currentdir = boosty::stringy( fs::current_path() ); - parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); + add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/modulecachetest.cc b/tests/modulecachetest.cc index 0028114..1103720 100644 --- a/tests/modulecachetest.cc +++ b/tests/modulecachetest.cc @@ -35,7 +35,6 @@ #include "builtin.h" #include "Tree.h" -#include #ifndef _MSC_VER #include #endif @@ -50,7 +49,6 @@ namespace fs = boost::filesystem; std::string commandline_commands; std::string currentdir; -QString examplesdir; using std::string; @@ -71,13 +69,12 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); - QCoreApplication app(argc, argv); fs::path original_path = fs::current_path(); currentdir = boosty::stringy( fs::current_path() ); - parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + parser_init(boosty::stringy(fs::path(argv[0]).branch_path())); + add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries")); Context root_ctx; register_builtin(root_ctx); -- cgit v0.10.1 From 5628a18f6a0fcf2dd170cac31e386f1ad4f97c0c Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 12 Mar 2013 12:35:32 -0400 Subject: boostfs_relative_path was buggy, replaced with boostfs_uncomplete for now diff --git a/src/boost-utils.cc b/src/boost-utils.cc index f81917a..5127047 100644 --- a/src/boost-utils.cc +++ b/src/boost-utils.cc @@ -2,10 +2,12 @@ #include #include -fs::path relativePath(const fs::path &path, const fs::path &relative_to) +// If the given (absolute) path is relative to the relative_to path, return a new +// relative path. Will normalize the given path first +fs::path boostfs_relative_path(const fs::path &path, const fs::path &relative_to) { // create absolute paths - fs::path p = fs::absolute(path); + fs::path p = fs::absolute(boostfs_normalize(path)); fs::path r = fs::absolute(relative_to); // if root paths are different, return absolute path @@ -40,3 +42,125 @@ fs::path relativePath(const fs::path &path, const fs::path &relative_to) return result; } + +// Will normalize the given path, i.e. remove any redundant ".." path elements. +fs::path boostfs_normalize(const fs::path &path) +{ + fs::path absPath = absolute(path); + fs::path::iterator it = absPath.begin(); + fs::path result = *it++; + + // Get canonical version of the existing part + for(;exists(result) && it != absPath.end(); ++it) { + result /= *it; + } + result = canonical(result.parent_path()); + --it; + + // For the rest remove ".." and "." in a path with no symlinks + for (; it != absPath.end(); ++it) { + // Just move back on ../ + if (*it == "..") { + result = result.parent_path(); + } + // Ignore "." + else if (*it != ".") { + // Just cat other path entries + result /= *it; + } + } + + return result; +} + +/** + * https://svn.boost.org/trac/boost/ticket/1976#comment:2 + * + * "The idea: uncomplete(/foo/new, /foo/bar) => ../new + * The use case for this is any time you get a full path (from an open dialog, perhaps) + * and want to store a relative path so that the group of files can be moved to a different + * directory without breaking the paths. An IDE would be a simple example, so that the + * project file could be safely checked out of subversion." + * + * ALGORITHM: + * iterate path and base + * compare all elements so far of path and base + * whilst they are the same, no write to output +x2 * when they change, or one runs out: + * write to output, ../ times the number of remaining elements in base + * write to output, the remaining elements in path + */ +fs::path +boostfs_uncomplete(fs::path const p, fs::path const base) +{ + if (p == base) return "./"; + /*!! this breaks stuff if path is a filename rather than a directory, + which it most likely is... but then base shouldn't be a filename so... */ + + // create absolute paths + fs::path abs_p = fs::absolute(boostfs_normalize(p)); + fs::path abs_base = fs::absolute(base); + + fs::path from_path, from_base, output; + + fs::path::iterator path_it = abs_p.begin(), path_end = abs_p.end(); + fs::path::iterator base_it = abs_base.begin(), base_end = abs_base.end(); + + // check for emptiness + if ((path_it == path_end) || (base_it == base_end)) { + throw std::runtime_error("path or base was empty; couldn't generate relative path"); + } + +#ifdef WIN32 + // drive letters are different; don't generate a relative path + if (*path_it != *base_it) return p; + + // now advance past drive letters; relative paths should only go up + // to the root of the drive and not past it + ++path_it, ++base_it; +#endif + + // Cache system-dependent dot, double-dot and slash strings + const std::string _dot = "."; + const std::string _dots = ".."; + const std::string _sep = "/"; + + // iterate over path and base + while (true) { + + // compare all elements so far of path and base to find greatest common root; + // when elements of path and base differ, or run out: + if ((path_it == path_end) || (base_it == base_end) || (*path_it != *base_it)) { + + // write to output, ../ times the number of remaining elements in base; + // this is how far we've had to come down the tree from base to get to the common root + for (; base_it != base_end; ++base_it) { + if (*base_it == _dot) + continue; + else if (*base_it == _sep) + continue; + + output /= "../"; + } + + // write to output, the remaining elements in path; + // this is the path relative from the common root + fs::path::iterator path_it_start = path_it; + for (; path_it != path_end; ++path_it) { + if (path_it != path_it_start) output /= "/"; + if (*path_it == _dot) continue; + if (*path_it == _sep) continue; + output /= *path_it; + } + break; + } + + // add directory level to both paths and continue iteration + from_path /= fs::path(*path_it); + from_base /= fs::path(*base_it); + + ++path_it, ++base_it; + } + + return output; +} diff --git a/src/boost-utils.h b/src/boost-utils.h index c431857..3678ecc 100644 --- a/src/boost-utils.h +++ b/src/boost-utils.h @@ -3,6 +3,11 @@ #include namespace fs = boost::filesystem; -fs::path relativePath(const fs::path &path, const fs::path &relative_to); + +// FIXME: boostfs_relative_path() has been replaced by +// boostfs_uncomplete(), but kept around for now. +fs::path boostfs_relative_path(const fs::path &path, const fs::path &relative_to); +fs::path boostfs_normalize(const fs::path &path); +fs::path boostfs_uncomplete(fs::path const p, fs::path const base); #endif diff --git a/src/dxfdata.cc b/src/dxfdata.cc index be982ff..8415228 100644 --- a/src/dxfdata.cc +++ b/src/dxfdata.cc @@ -390,10 +390,10 @@ DxfData::DxfData(double fn, double fs, double fa, BOOST_FOREACH(const EntityList::value_type &i, unsupported_entities_list) { if (layername.empty()) { PRINTB("WARNING: Unsupported DXF Entity '%s' (%x) in %s.", - i.first % i.second % QuotedString(boosty::stringy(relativePath(filename, fs::current_path())))); + i.first % i.second % QuotedString(boosty::stringy(boostfs_uncomplete(filename, fs::current_path())))); } else { PRINTB("WARNING: Unsupported DXF Entity '%s' (%x) in layer '%s' of %s.", - i.first % i.second % layername % QuotedString(boosty::stringy(relativePath(filename, fs::current_path())))); + i.first % i.second % layername % QuotedString(boosty::stringy(boostfs_uncomplete(filename, fs::current_path())))); } } diff --git a/src/value.cc b/src/value.cc index bec803a..ae810a2 100644 --- a/src/value.cc +++ b/src/value.cc @@ -39,7 +39,7 @@ std::ostream &operator<<(std::ostream &stream, const Filename &filename) { - stream << QuotedString(boosty::stringy(relativePath(filename, fs::current_path()))); + stream << QuotedString(boosty::stringy(boostfs_uncomplete(filename, fs::current_path()))); return stream; } -- cgit v0.10.1 From 5edc8c57da6eb8bfb7725ac51c4b87edd950e847 Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 16 Mar 2013 21:55:38 +0100 Subject: update cmakelist for building tests in same dir as gui binary diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5eecaae..6178c3a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -604,6 +604,10 @@ else() set(GUI_BINPATH "${CMAKE_CURRENT_SOURCE_DIR}/../openscad") endif() +if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/openscad") + set(GUI_BINPATH "${CMAKE_CURRENT_BINARY_DIR}/openscad") +endif() + if(EXISTS "${GUI_BINPATH}") message(STATUS "Found OpenSCAD GUI binary: ${GUI_BINPATH}") else() -- cgit v0.10.1 From 100b1733df981aa542675d2dad198a259a61ccd2 Mon Sep 17 00:00:00 2001 From: don bright Date: Sun, 17 Mar 2013 18:34:47 +0100 Subject: backport boost functions to pre-1.48 diff --git a/scripts/uni-build-dependencies.sh b/scripts/uni-build-dependencies.sh index dc61f74..784a191 100755 --- a/scripts/uni-build-dependencies.sh +++ b/scripts/uni-build-dependencies.sh @@ -513,7 +513,7 @@ if [ $1 ]; then exit $? fi if [ $1 = "cgal" ]; then - build_cgal 4.0.2 use-sys-libs + build_cgal 4.1 use-sys-libs exit $? fi if [ $1 = "opencsg" ]; then diff --git a/src/boost-utils.cc b/src/boost-utils.cc index 5127047..534cbaa 100644 --- a/src/boost-utils.cc +++ b/src/boost-utils.cc @@ -1,3 +1,4 @@ +#include "boosty.h" #include "boost-utils.h" #include #include @@ -7,8 +8,8 @@ fs::path boostfs_relative_path(const fs::path &path, const fs::path &relative_to) { // create absolute paths - fs::path p = fs::absolute(boostfs_normalize(path)); - fs::path r = fs::absolute(relative_to); + fs::path p = boosty::absolute(boostfs_normalize(path)); + fs::path r = boosty::absolute(relative_to); // if root paths are different, return absolute path if (p.root_path() != r.root_path()) @@ -46,16 +47,17 @@ fs::path boostfs_relative_path(const fs::path &path, const fs::path &relative_to // Will normalize the given path, i.e. remove any redundant ".." path elements. fs::path boostfs_normalize(const fs::path &path) { - fs::path absPath = absolute(path); + fs::path absPath = boosty::absolute(path); fs::path::iterator it = absPath.begin(); - fs::path result = *it++; + fs::path result = *it; + if (it!=absPath.end()) it++; // Get canonical version of the existing part for(;exists(result) && it != absPath.end(); ++it) { result /= *it; } - result = canonical(result.parent_path()); - --it; + result = boosty::canonical(result.parent_path()); + if (it!=absPath.begin()) it--; // For the rest remove ".." and "." in a path with no symlinks for (; it != absPath.end(); ++it) { @@ -98,8 +100,8 @@ boostfs_uncomplete(fs::path const p, fs::path const base) which it most likely is... but then base shouldn't be a filename so... */ // create absolute paths - fs::path abs_p = fs::absolute(boostfs_normalize(p)); - fs::path abs_base = fs::absolute(base); + fs::path abs_p = boosty::absolute(boostfs_normalize(p)); + fs::path abs_base = boosty::absolute(base); fs::path from_path, from_base, output; diff --git a/src/boosty.h b/src/boosty.h index 6ec417a..5c82002 100644 --- a/src/boosty.h +++ b/src/boosty.h @@ -10,9 +10,8 @@ versions of boost found on popular versions of linux, circa early 2012. design - hope that the user is compiling with boost>1.46 + filesystem v3 - if not, fall back to older deprecated functions, and rely on - testing to find bugs. implement the minimum needed by OpenSCAD and no more. + the boost filsystem changed around 1.46-1.48. we do a large #ifdef + based on boost version that wraps various functions appropriately. in a few years, this file should be deleted as unnecessary. see also @@ -28,6 +27,7 @@ #include #include namespace fs = boost::filesystem; +#include "printutils.h" namespace boosty { @@ -77,6 +77,62 @@ inline std::string extension_str( fs::path p) #endif + + + + +#if BOOST_VERSION >= 104800 + +inline fs::path canonical( fs::path p, fs::path p2 ) +{ + return fs::canonical( p, p2, NULL ); +} + +inline fs::path canonical( fs::path p ) +{ + return fs::canonical( p, fs::current_path(), NULL ); +} + +#else + +inline fs::path canonical( fs::path p, fs::path p2 ) +{ + // dotpath: win32/mac builds will be using newer versions of boost + // so we can treat this as though it is unix only + const fs::path dot_path("."); + const fs::path dot_dot_path(".."); + fs::path result; + if (p=="") + { + p=p2; + } + for (fs::path::iterator itr = p.begin(); itr != p.end(); itr++) + { + if (*itr == dot_path) continue; + if (*itr == dot_dot_path) + { + result.remove_filename(); + continue; + } + result /= *itr; + if (fs::is_symlink(result)) + { + PRINT("WARNING: canonical() wrapper can't do symlinks. upgrade boost to >1.48"); + } + } + return result; +} + +inline fs::path canonical( fs::path p ) +{ + return canonical( p, fs::current_path() ); +} + +#endif + + + + } // namespace #endif diff --git a/src/value.cc b/src/value.cc index ae810a2..ebb825d 100644 --- a/src/value.cc +++ b/src/value.cc @@ -39,7 +39,9 @@ std::ostream &operator<<(std::ostream &stream, const Filename &filename) { - stream << QuotedString(boosty::stringy(boostfs_uncomplete(filename, fs::current_path()))); + fs::path fnpath = fs::path( (std::string)filename ); + fs::path fpath = boostfs_uncomplete(fnpath, fs::current_path()); + stream << QuotedString(boosty::stringy( fpath )); return stream; } -- cgit v0.10.1 From c8c749de1893d76966d924e22276b3d7d58f3b58 Mon Sep 17 00:00:00 2001 From: don bright Date: Sun, 17 Mar 2013 11:21:15 -0700 Subject: fix some bugs in wrapper of canonical() diff --git a/src/boosty.h b/src/boosty.h index 5c82002..6dc9858 100644 --- a/src/boosty.h +++ b/src/boosty.h @@ -85,12 +85,12 @@ inline std::string extension_str( fs::path p) inline fs::path canonical( fs::path p, fs::path p2 ) { - return fs::canonical( p, p2, NULL ); + return fs::canonical( p, p2 ); } inline fs::path canonical( fs::path p ) { - return fs::canonical( p, fs::current_path(), NULL ); + return fs::canonical( p ); } #else -- cgit v0.10.1 From f40942441882823f9b432c57eead64a89507e577 Mon Sep 17 00:00:00 2001 From: don bright Date: Sun, 17 Mar 2013 11:57:29 -0700 Subject: update to match Marius' version diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 308bbe9..9e2da81 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -20,7 +20,6 @@ o Changed multmatrix floating-point output to improve dumptest portability o Regression test auto-starts & stops Xvfb / Xvnc if on headless unix machine o CGAL triangulation more lenient- enables partial rendering of 'bad' DXF data o Fixes problem where local changes are overwritten on automatic reload when included files has changed. -o Non-ascii filenames are now allowed OpenSCAD 2013.01 ================ -- cgit v0.10.1 From 1949403689f9cc6f5c5b59e27176518fac4426b9 Mon Sep 17 00:00:00 2001 From: don bright Date: Sun, 17 Mar 2013 11:58:53 -0700 Subject: boost s/b >=1.48 not >1.48 diff --git a/src/boosty.h b/src/boosty.h index 6dc9858..2b5ab38 100644 --- a/src/boosty.h +++ b/src/boosty.h @@ -117,7 +117,7 @@ inline fs::path canonical( fs::path p, fs::path p2 ) result /= *itr; if (fs::is_symlink(result)) { - PRINT("WARNING: canonical() wrapper can't do symlinks. upgrade boost to >1.48"); + PRINT("WARNING: canonical() wrapper can't do symlinks. upgrade boost to >=1.48"); } } return result; -- cgit v0.10.1 From 8e32cef0a8c52742bf12cafd2aa9dafd1efe764e Mon Sep 17 00:00:00 2001 From: don bright Date: Sun, 17 Mar 2013 12:29:02 -0700 Subject: more accurate help message diff --git a/src/boosty.h b/src/boosty.h index 2b5ab38..8b0c93e 100644 --- a/src/boosty.h +++ b/src/boosty.h @@ -117,7 +117,8 @@ inline fs::path canonical( fs::path p, fs::path p2 ) result /= *itr; if (fs::is_symlink(result)) { - PRINT("WARNING: canonical() wrapper can't do symlinks. upgrade boost to >=1.48"); + PRINT("WARNING: canonical() wrapper can't do symlinks. rebuild openscad with boost >=1.48"); + PRINT("WARNING: or don't use symbolic links"); } } return result; -- cgit v0.10.1 From 3d9a7c91e0189019a9a7bd3b6da67f3e619a5622 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 17 Mar 2013 17:29:57 -0500 Subject: Bumped mpfr to 3.1.2 diff --git a/scripts/macosx-build-dependencies.sh b/scripts/macosx-build-dependencies.sh index 11d9919..9814987 100755 --- a/scripts/macosx-build-dependencies.sh +++ b/scripts/macosx-build-dependencies.sh @@ -412,7 +412,7 @@ mkdir -p $SRCDIR $DEPLOYDIR build_qt 4.8.4 build_eigen 3.1.2 build_gmp 5.1.1 -build_mpfr 3.1.1 +build_mpfr 3.1.2 build_boost 1.53.0 # NB! For CGAL, also update the actual download URL in the function build_cgal 4.1 -- cgit v0.10.1 From d545a227260ddd72b1fdb5c3dc2ebb1bae36c410 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 17 Mar 2013 17:30:29 -0500 Subject: Updated dependencies diff --git a/README.md b/README.md index c3e2e36..9449a91 100644 --- a/README.md +++ b/README.md @@ -84,15 +84,15 @@ libraries from aptitude. If you're using Mac, or an older Linux/BSD, there are build scripts that download and compile the libraries from source. Follow the instructions for the platform you're compiling on below. -* [Qt4 (4.4 - 4.7)](http://www.qt.nokia.com/) -* [CGAL (3.6 - 4.0.2)](http://www.cgal.org/) - * [GMP (5.0.x)](http://www.gmplib.org/) - * [cmake (2.6 - 2.8, required by CGAL and the test framework)](http://www.cmake.org/) +* [Qt4 (4.4 - 4.8)](http://www.qt.nokia.com/) +* [CGAL (3.6 - 4.1)](http://www.cgal.org/) + * [GMP (5.x)](http://www.gmplib.org/) + * [cmake (2.8, required by CGAL and the test framework)](http://www.cmake.org/) * [MPFR (3.x)](http://www.mpfr.org/) - * [boost (1.35 - 1.47)](http://www.boost.org/) + * [boost (1.35 - 1.53)](http://www.boost.org/) * [OpenCSG (1.3.2)](http://www.opencsg.org/) * [GLEW (1.5.4 ->)](http://glew.sourceforge.net/) -* [Eigen (2.0.13->3.1.1)](http://eigen.tuxfamily.org/) +* [Eigen (2.0.x->3.x)](http://eigen.tuxfamily.org/) * [GCC C++ Compiler (4.2 ->)](http://gcc.gnu.org/) * [Bison (2.4)](http://www.gnu.org/software/bison/) * [Flex (2.5.35)](http://flex.sourceforge.net/) -- cgit v0.10.1