summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/context.cc7
-rw-r--r--src/dxfdim.cc17
-rw-r--r--src/handle_dep.cc13
-rw-r--r--src/import.cc78
-rw-r--r--src/linearextrude.cc2
-rw-r--r--src/rotateextrude.cc2
-rw-r--r--src/surface.cc55
7 files changed, 104 insertions, 70 deletions
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++;
}
contact: Jan Huwald // Impressum