summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dxfdata.cc50
-rw-r--r--dxfdim.cc92
-rw-r--r--func.cc19
-rw-r--r--openscad.h16
-rw-r--r--openscad.pro3
5 files changed, 167 insertions, 13 deletions
diff --git a/dxfdata.cc b/dxfdata.cc
index 750f879..773f8d9 100644
--- a/dxfdata.cc
+++ b/dxfdata.cc
@@ -44,9 +44,16 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
lines.append(Line(p(_p1x, _p1y), p(_p2x, _p2y))); \
} while (0)
- QString mode, layer;
+ QString mode, layer, name;
+ int dimtype = 0;
+ double coords[7][2];
double x1 = 0, x2 = 0, y1 = 0, y2 = 0;
double radius = 0, start_angle = 0, stop_angle = 0;
+
+ for (int i = 0; i < 7; i++)
+ for (int j = 0; j < 2; j++)
+ coords[i][j] = 0;
+
bool in_entities_section = false;
QHash<QString, int> unsupported_entities_list;
@@ -61,6 +68,20 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
if (!status)
break;
+ if (id >= 10 && id <= 16) {
+ if (id == 11 || id == 12 || id == 16)
+ coords[id-10][0] = data.toDouble() * scale;
+ else
+ coords[id-10][0] = (data.toDouble() - xorigin) * scale;
+ }
+
+ if (id >= 20 && id <= 26) {
+ if (id == 21 || id == 22 || id == 26)
+ coords[id-20][0] = data.toDouble() * scale;
+ else
+ coords[id-20][0] = (data.toDouble() - yorigin) * scale;
+ }
+
switch (id)
{
case 0:
@@ -93,16 +114,38 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
cos(a2)*radius + x1, sin(a2)*radius + y1);
}
}
+ if (in_entities_section && mode == "DIMENSION" &&
+ (layername.isNull() || layername == layer)) {
+ dims.append(Dim());
+ dims.last().type = dimtype;
+ for (int i = 0; i < 7; i++)
+ for (int j = 0; j < 2; j++)
+ dims.last().coords[i][j] = coords[i][j];
+ dims.last().angle = start_angle;
+ dims.last().name = name;
+ }
if (in_entities_section &&
(layername.isNull() || layername == layer)) {
- if (mode != "SECTION" && mode != "ENDSEC" &&
+ if (mode != "SECTION" && mode != "ENDSEC" && mode != "DIMENSION" &&
mode != "LINE" && mode != "ARC" && mode != "CIRCLE")
unsupported_entities_list[mode]++;
}
mode = data;
+ layer = QString();
+ name = QString();
+ dimtype = 0;
+ for (int i = 0; i < 7; i++)
+ for (int j = 0; j < 2; j++)
+ coords[i][j] = 0;
+ x1 = x2 = y1 = y2 = 0;
+ radius = start_angle = stop_angle = 0;
+ break;
+ case 1:
+ name = data;
break;
case 2:
in_entities_section = data == "ENTITIES";
+ break;
case 8:
layer = data;
break;
@@ -127,6 +170,9 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
case 51:
stop_angle = data.toDouble();
break;
+ case 70:
+ dimtype = data.toInt();
+ break;
}
}
diff --git a/dxfdim.cc b/dxfdim.cc
new file mode 100644
index 0000000..0ae879a
--- /dev/null
+++ b/dxfdim.cc
@@ -0,0 +1,92 @@
+/*
+ * OpenSCAD (www.openscad.at)
+ * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "openscad.h"
+
+Value builtin_dxf_dim(const QVector<QString> &argnames, const QVector<Value> &args)
+{
+ QString filename;
+ QString layername;
+ QString name;
+ double xorigin = 0;
+ double yorigin = 0;
+ double scale = 1;
+
+ for (int i = 0; i < argnames.count() && i < args.count(); i++) {
+ if (argnames[i] == "file")
+ filename = args[i].text;
+ if (argnames[i] == "layer")
+ filename = args[i].text;
+ if (argnames[i] == "origin")
+ args[i].getv2(xorigin, yorigin);
+ if (argnames[i] == "scale")
+ args[i].getnum(scale);
+ if (argnames[i] == "name")
+ name = args[i].text;
+ }
+
+ DxfData dxf(36, 0, 0, filename, layername, xorigin, yorigin, scale);
+
+ for (int i = 0; i < dxf.dims.count(); i++)
+ {
+ if (!name.isNull() && dxf.dims[i].name != name)
+ continue;
+
+ DxfData::Dim *d = &dxf.dims[i];
+ int type = d->type & 7;
+
+ if (type == 0) {
+ // Rotated, horizontal or vertical
+ double x = d->coords[4][0] - d->coords[3][0];
+ double y = d->coords[4][1] - d->coords[3][1];
+ double angle = d->angle;
+ double distance_projected_on_line = fabs(x * sin(angle*M_PI/180) + y * cos(angle*M_PI/180));
+ return Value(distance_projected_on_line);
+ }
+ if (type == 1) {
+ // Aligned
+ }
+ if (type == 2) {
+ // Angular
+ }
+ if (type == 3) {
+ // Diameter
+ }
+ if (type == 4) {
+ // Radius
+ }
+ if (type == 5) {
+ // Angular 3 Point
+ }
+
+ PRINTA("WARINING: Dimension `%1' in `%2', layer `%3' has unsupported type!", name, filename, layername);
+ return Value();
+ }
+
+ PRINTA("WARINING: Can't find dimension `%1' in `%2', layer `%3'!", name, filename, layername);
+
+ return Value();
+}
+
+void initialize_builtin_dxf_dim()
+{
+ builtin_functions["dxf_dim"] = new BuiltinFunction(&builtin_dxf_dim);
+}
+
diff --git a/func.cc b/func.cc
index 07171b6..352f0ae 100644
--- a/func.cc
+++ b/func.cc
@@ -70,9 +70,9 @@ BuiltinFunction::~BuiltinFunction()
{
}
-Value BuiltinFunction::evaluate(const Context*, const QVector<QString>&, const QVector<Value> &call_argvalues) const
+Value BuiltinFunction::evaluate(const Context*, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const
{
- return eval_func(call_argvalues);
+ return eval_func(call_argnames, call_argvalues);
}
QString BuiltinFunction::dump(QString indent, QString name) const
@@ -100,49 +100,49 @@ static double rad2deg(double x)
return x;
}
-Value builtin_sin(const QVector<Value> &args)
+Value builtin_sin(const QVector<QString>&, const QVector<Value> &args)
{
if (args[0].type == Value::NUMBER)
return Value(sin(deg2rad(args[0].num)));
return Value();
}
-Value builtin_cos(const QVector<Value> &args)
+Value builtin_cos(const QVector<QString>&, const QVector<Value> &args)
{
if (args[0].type == Value::NUMBER)
return Value(cos(deg2rad(args[0].num)));
return Value();
}
-Value builtin_asin(const QVector<Value> &args)
+Value builtin_asin(const QVector<QString>&, const QVector<Value> &args)
{
if (args[0].type == Value::NUMBER)
return Value(rad2deg(asin(args[0].num)));
return Value();
}
-Value builtin_acos(const QVector<Value> &args)
+Value builtin_acos(const QVector<QString>&, const QVector<Value> &args)
{
if (args[0].type == Value::NUMBER)
return Value(rad2deg(acos(args[0].num)));
return Value();
}
-Value builtin_tan(const QVector<Value> &args)
+Value builtin_tan(const QVector<QString>&, const QVector<Value> &args)
{
if (args[0].type == Value::NUMBER)
return Value(tan(deg2rad(args[0].num)));
return Value();
}
-Value builtin_atan(const QVector<Value> &args)
+Value builtin_atan(const QVector<QString>&, const QVector<Value> &args)
{
if (args[0].type == Value::NUMBER)
return Value(rad2deg(atan(args[0].num)));
return Value();
}
-Value builtin_atan2(const QVector<Value> &args)
+Value builtin_atan2(const QVector<QString>&, const QVector<Value> &args)
{
if (args[0].type == Value::NUMBER && args[1].type == Value::NUMBER)
return Value(rad2deg(atan2(args[0].num, args[1].num)));
@@ -158,6 +158,7 @@ void initialize_builtin_functions()
builtin_functions["tan"] = new BuiltinFunction(&builtin_tan);
builtin_functions["atan"] = new BuiltinFunction(&builtin_atan);
builtin_functions["atan2"] = new BuiltinFunction(&builtin_atan2);
+ initialize_builtin_dxf_dim();
}
void destroy_builtin_functions()
diff --git a/openscad.h b/openscad.h
index 5e56618..b6a3a1d 100644
--- a/openscad.h
+++ b/openscad.h
@@ -285,7 +285,7 @@ public:
class BuiltinFunction : public AbstractFunction
{
public:
- typedef Value (*eval_func_t)(const QVector<Value> &args);
+ typedef Value (*eval_func_t)(const QVector<QString> &argnames, const QVector<Value> &args);
eval_func_t eval_func;
BuiltinFunction(eval_func_t f) : eval_func(f) { }
@@ -312,6 +312,7 @@ public:
extern QHash<QString, AbstractFunction*> builtin_functions;
extern void initialize_builtin_functions();
+extern void initialize_builtin_dxf_dim();
extern void destroy_builtin_functions();
class AbstractModule
@@ -419,9 +420,22 @@ public:
bool is_closed, is_inner;
Path() : is_closed(false), is_inner(false) { }
};
+ struct Dim {
+ unsigned int type;
+ double coords[7][2];
+ double angle;
+ QString name;
+ Dim() {
+ for (int i = 0; i < 7; i++)
+ for (int j = 0; j < 2; j++)
+ coords[i][j] = 0;
+ type = 0;
+ }
+ };
QList<Point> points;
QList<Path> paths;
+ QList<Dim> dims;
DxfData(double fn, double fs, double fa, QString filename, QString layername = QString(), double xorigin = 0.0, double yorigin = 0.0, double scale = 1.0);
diff --git a/openscad.pro b/openscad.pro
index cb162d5..d5adb7a 100644
--- a/openscad.pro
+++ b/openscad.pro
@@ -16,7 +16,8 @@ SOURCES += openscad.cc mainwin.cc glview.cc
SOURCES += value.cc expr.cc func.cc module.cc context.cc
SOURCES += csgterm.cc polyset.cc csgops.cc transform.cc
SOURCES += primitives.cc control.cc render.cc
-SOURCES += dxfdata.cc dxftess.cc dxflinextrude.cc dxfrotextrude.cc
+SOURCES += dxfdata.cc dxftess.cc dxfdim.cc
+SOURCES += dxflinextrude.cc dxfrotextrude.cc
QMAKE_CXXFLAGS += -O0
// QMAKE_CXXFLAGS += -O3 -march=pentium
contact: Jan Huwald // Impressum