Ported currentdir handling from Qt to boost filesystem

felipesanches-svg
Marius Kintel 2011-12-25 00:22:03 +01:00
parent a5ea98c4a4
commit 9293b591c7
11 changed files with 78 additions and 87 deletions

View File

@ -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 {

View File

@ -48,12 +48,7 @@
#endif
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QSet>
#include <QSettings>
#include <QTextStream>
#include <boost/program_options.hpp>
#include <sstream>
#ifdef Q_WS_MAC
@ -61,11 +56,15 @@
#include "AppleEvents.h"
#endif
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
#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<string> inputFiles;
if (vm.count("input-file")) {
inputFiles = vm["input-file"].as<vector<string> >();
for (vector<string>::const_iterator i = inputFiles.begin()+1; i != inputFiles.end(); i++) {
new MainWindow(QFileInfo(original_path, i->c_str()).absoluteFilePath());
for (vector<string>::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()));

View File

@ -36,7 +36,7 @@ extern std::string commandline_commands;
#include <QString>
// 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;

View File

@ -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<Module*>(parse(text.str().c_str(), absolute(filename).generic_string().c_str(), 0));
Module *lib_mod = dynamic_cast<Module*>(parse(text.str().c_str(), path(filename).parent_path().generic_string().c_str(), 0));
module = backup_mod;
if (lib_mod) {

View File

@ -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 <QApplication>
#include <QFile>
#include <QDir>
#include <QSet>
#include <QTextStream>
#ifndef _MSC_VER
#include <getopt.h>
#endif
@ -54,8 +51,11 @@
#include <assert.h>
#include <sstream>
#include <boost/filesystem.hpp>
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 = QDir::currentPath();
currentdir = fs::current_path().generic_string();
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 {

View File

@ -39,10 +39,6 @@
#include "PolySetCGALEvaluator.h"
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QSet>
#include <QTextStream>
#ifndef _MSC_VER
#include <getopt.h>
#endif
@ -50,8 +46,11 @@
#include <assert.h>
#include <sstream>
#include <boost/filesystem.hpp>
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);
}

View File

@ -39,9 +39,6 @@
#include "csgterm.h"
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QSet>
#ifndef _MSC_VER
#include <getopt.h>
#endif
@ -50,12 +47,15 @@
#include <sstream>
#include <fstream>
using std::cout;
#include <boost/filesystem.hpp>
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) {

View File

@ -23,16 +23,16 @@
#include "OffscreenView.h"
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QSet>
#include <QTimer>
#include <sstream>
#include <vector>
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
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);

View File

@ -38,9 +38,6 @@
#include "Tree.h"
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QSet>
#ifndef _MSC_VER
#include <getopt.h>
#endif
@ -49,8 +46,11 @@
#include <sstream>
#include <fstream>
#include <boost/filesystem.hpp>
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";

View File

@ -36,9 +36,6 @@
#include "Tree.h"
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QSet>
#ifndef _MSC_VER
#include <getopt.h>
#endif
@ -47,12 +44,15 @@
#include <sstream>
#include <fstream>
using std::string;
#include <boost/filesystem.hpp>
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);

View File

@ -35,9 +35,6 @@
#include "printutils.h"
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QSet>
#ifndef _MSC_VER
#include <getopt.h>
#endif
@ -46,12 +43,15 @@
#include <sstream>
#include <fstream>
using std::string;
#include <boost/filesystem.hpp>
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<std::ostream*>(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);