summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fileutils.cc35
-rw-r--r--src/fileutils.h9
-rw-r--r--tests/regression/cgalpngtest/localfiles-compatibility-test-expected.pngbin0 -> 11732 bytes
-rw-r--r--tests/regression/dumptest/localfiles-compatibility-test-expected.txt20
-rw-r--r--tests/regression/opencsgtest/localfiles-compatibility-test-expected.pngbin0 -> 12657 bytes
-rw-r--r--tests/regression/throwntogethertest/localfiles-compatibility-test-expected.pngbin0 -> 12657 bytes
6 files changed, 64 insertions, 0 deletions
diff --git a/src/fileutils.cc b/src/fileutils.cc
new file mode 100644
index 0000000..b844b4a
--- /dev/null
+++ b/src/fileutils.cc
@@ -0,0 +1,35 @@
+#include "fileutils.h"
+#include "printutils.h"
+
+#include <boost/filesystem.hpp>
+namespace fs = boost::filesystem;
+#include "boosty.h"
+
+/*!
+ Returns the absolute path to the given filename, unless it's empty.
+ If the file isn't found in the given path, the fallback path will be
+ used to be backwards compatible with <= 2013.01 (see issue #217).
+*/
+std::string lookup_file(const std::string &filename,
+ const std::string &path, const std::string &fallbackpath)
+{
+ std::string resultfile;
+ if (!filename.empty() && !boosty::is_absolute(fs::path(filename))) {
+ fs::path absfile;
+ if (!path.empty()) absfile = boosty::absolute(fs::path(path) / filename);
+ fs::path absfile_fallback;
+ if (!fallbackpath.empty()) absfile_fallback = boosty::absolute(fs::path(fallbackpath) / filename);
+
+ if (!fs::exists(absfile) && fs::exists(absfile_fallback)) {
+ resultfile = absfile_fallback.string();
+ PRINTB("WARNING: Imported file (%s) found in document root instead of relative to the importing module. This behavior is deprecated", filename);
+ }
+ else {
+ resultfile = absfile.string();
+ }
+ }
+ else {
+ resultfile = filename;
+ }
+ return resultfile;
+}
diff --git a/src/fileutils.h b/src/fileutils.h
new file mode 100644
index 0000000..1f68cdb
--- /dev/null
+++ b/src/fileutils.h
@@ -0,0 +1,9 @@
+#ifndef FILEUTILS_H_
+#define FILEUTILS_H_
+
+#include <string>
+
+std::string lookup_file(const std::string &filename,
+ const std::string &path, const std::string &fallbackpath);
+
+#endif
diff --git a/tests/regression/cgalpngtest/localfiles-compatibility-test-expected.png b/tests/regression/cgalpngtest/localfiles-compatibility-test-expected.png
new file mode 100644
index 0000000..d0cfd50
--- /dev/null
+++ b/tests/regression/cgalpngtest/localfiles-compatibility-test-expected.png
Binary files differ
diff --git a/tests/regression/dumptest/localfiles-compatibility-test-expected.txt b/tests/regression/dumptest/localfiles-compatibility-test-expected.txt
new file mode 100644
index 0000000..8725061
--- /dev/null
+++ b/tests/regression/dumptest/localfiles-compatibility-test-expected.txt
@@ -0,0 +1,20 @@
+ group() {
+ linear_extrude(height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2) {
+ import(file = "localfile.dxf", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2);
+ }
+ multmatrix([[1, 0, 0, -250], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ linear_extrude(file = "localfile.dxf", layer = "", origin = [0, 0], scale = 1, height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2);
+ }
+ multmatrix([[1, 0, 0, 0], [0, 1, 0, 350], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ rotate_extrude(file = "localfile.dxf", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2);
+ }
+ multmatrix([[1, 0, 0, 250], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ multmatrix([[200, 0, 0, 0], [0, 200, 0, 0], [0, 0, 50, 0], [0, 0, 0, 1]]) {
+ surface(file = "localfile.dat", center = false);
+ }
+ }
+ multmatrix([[1, 0, 0, 0], [0, 1, 0, -200], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ sphere($fn = 0, $fa = 12, $fs = 2, r = 100);
+ }
+ }
+
diff --git a/tests/regression/opencsgtest/localfiles-compatibility-test-expected.png b/tests/regression/opencsgtest/localfiles-compatibility-test-expected.png
new file mode 100644
index 0000000..f280efd
--- /dev/null
+++ b/tests/regression/opencsgtest/localfiles-compatibility-test-expected.png
Binary files differ
diff --git a/tests/regression/throwntogethertest/localfiles-compatibility-test-expected.png b/tests/regression/throwntogethertest/localfiles-compatibility-test-expected.png
new file mode 100644
index 0000000..f280efd
--- /dev/null
+++ b/tests/regression/throwntogethertest/localfiles-compatibility-test-expected.png
Binary files differ
contact: Jan Huwald // Impressum