Clifford Wolf:

Added rotation extrude
	Added dxf extrude example



git-svn-id: http://svn.clifford.at/openscad/trunk@58 b57f626f-c46c-0410-a088-ec61d464b74c
stl_dim
clifford 2009-07-17 00:34:15 +00:00
parent d05ea4453b
commit 6de5c3dc35
7 changed files with 2611 additions and 7 deletions

View File

@ -176,12 +176,18 @@ DxfData::DxfData(double /* fn */, double /* fs */, double /* fa */, QString file
}
// rotate points if the path is not in non-standard rotation
int b = min_x_point;
int a = b == 0 ? paths[i].points.count() - 1 : b - 1;
int c = b == paths[i].points.count() - 1 ? 0 : b + 1;
int a = b == 0 ? paths[i].points.count() - 2 : b - 1;
int c = b == paths[i].points.count() - 1 ? 1 : b + 1;
double ax = paths[i].points[a]->x - paths[i].points[b]->x;
double ay = paths[i].points[a]->y - paths[i].points[b]->y;
double cx = paths[i].points[c]->x - paths[i].points[c]->x;
double cy = paths[i].points[c]->y - paths[i].points[c]->y;
double cx = paths[i].points[c]->x - paths[i].points[b]->x;
double cy = paths[i].points[c]->y - paths[i].points[b]->y;
#if 0
printf("Rotate check:\n");
printf(" a/b/c indices = %d %d %d\n", a, b, c);
printf(" b->a vector = %f %f (%f)\n", ax, ay, atan2(ax, ay));
printf(" b->c vector = %f %f (%f)\n", cx, cy, atan2(cx, cy));
#endif
if (atan2(ax, ay) < atan2(cx, cy)) {
for (int j = 0; j < paths[i].points.count()/2; j++)
paths[i].points.swap(j, paths[i].points.count()-1-j);
@ -193,7 +199,8 @@ DxfData::DxfData(double /* fn */, double /* fs */, double /* fa */, QString file
#if 0
printf("----- DXF Data -----\n");
for (int i = 0; i < paths.count(); i++) {
printf("Path %d (%s, %s):\n", i, paths[i].is_closed ? "closed" : "open", paths[i].is_inner ? "inner" : "outer");
printf("Path %d (%s, %s):\n", i, paths[i].is_closed ? "closed" : "open",
paths[i].is_inner ? "inner" : "outer");
for (int j = 0; j < paths[i].points.count(); j++)
printf(" %f %f\n", paths[i].points[j]->x, paths[i].points[j]->y);
}

152
dxfrotextrude.cc Normal file
View File

@ -0,0 +1,152 @@
/*
* 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
*
*/
#define INCLUDE_ABSTRACT_NODE_DETAILS
#include "openscad.h"
class DxfRotateExtrudeModule : public AbstractModule
{
public:
DxfRotateExtrudeModule() { }
virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstanciation *inst) const;
};
class DxfRotateExtrudeNode : public AbstractPolyNode
{
public:
int convexity;
double fn, fs, fa;
QString filename, layername;
DxfRotateExtrudeNode(const ModuleInstanciation *mi) : AbstractPolyNode(mi) { }
virtual PolySet *render_polyset(render_mode_e mode) const;
virtual QString dump(QString indent) const;
};
AbstractNode *DxfRotateExtrudeModule::evaluate(const Context *ctx, const ModuleInstanciation *inst) const
{
DxfRotateExtrudeNode *node = new DxfRotateExtrudeNode(inst);
QVector<QString> argnames = QVector<QString>() << "file" << "layer";
QVector<Expression*> argexpr;
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
node->fn = c.lookup_variable("$fn").num;
node->fs = c.lookup_variable("$fs").num;
node->fa = c.lookup_variable("$fa").num;
Value file = c.lookup_variable("file");
Value layer = c.lookup_variable("layer");
Value convexity = c.lookup_variable("convexity");
node->filename = file.text;
node->layername = layer.text;
node->convexity = convexity.num;
if (node->convexity <= 0)
node->convexity = 1;
return node;
}
void register_builtin_dxf_rotate_extrude()
{
builtin_modules["dxf_rotate_extrude"] = new DxfRotateExtrudeModule();
}
PolySet *DxfRotateExtrudeNode::render_polyset(render_mode_e) const
{
DxfData dxf(fn, fs, fa, filename, layername);
PolySet *ps = new PolySet();
ps->convexity = convexity;
for (int i = 0; i < dxf.paths.count(); i++)
{
double max_x = 0;
for (int j = 0; j < dxf.paths[i].points.count(); j++) {
max_x = fmax(max_x, dxf.paths[i].points[j]->x);
}
int fragments = get_fragments_from_r(max_x, fn, fs, fa);
double points[fragments][dxf.paths[i].points.count()][3];
for (int j = 0; j < fragments; j++) {
double a = (j*2*M_PI) / fragments;
for (int k = 0; k < dxf.paths[i].points.count(); k++) {
if (dxf.paths[i].points[k]->x == 0) {
points[j][k][0] = 0;
points[j][k][1] = 0;
} else {
points[j][k][0] = dxf.paths[i].points[k]->x * sin(a);
points[j][k][1] = dxf.paths[i].points[k]->x * cos(a);
}
points[j][k][2] = dxf.paths[i].points[k]->y;
}
}
for (int j = 0; j < fragments; j++) {
int j1 = j + 1 < fragments ? j + 1 : 0;
for (int k = 0; k < dxf.paths[i].points.count(); k++) {
int k1 = k + 1 < dxf.paths[i].points.count() ? k + 1 : 0;
if (points[j][k][0] != points[j1][k][0] ||
points[j][k][1] != points[j1][k][1] ||
points[j][k][2] != points[j1][k][2]) {
ps->append_poly();
ps->append_vertex(points[j ][k ][0],
points[j ][k ][1], points[j ][k ][2]);
ps->append_vertex(points[j1][k ][0],
points[j1][k ][1], points[j1][k ][2]);
ps->append_vertex(points[j ][k1][0],
points[j ][k1][1], points[j ][k1][2]);
}
if (points[j][k1][0] != points[j1][k1][0] ||
points[j][k1][1] != points[j1][k1][1] ||
points[j][k1][2] != points[j1][k1][2]) {
ps->append_poly();
ps->append_vertex(points[j ][k1][0],
points[j ][k1][1], points[j ][k1][2]);
ps->append_vertex(points[j1][k ][0],
points[j1][k ][1], points[j1][k ][2]);
ps->append_vertex(points[j1][k1][0],
points[j1][k1][1], points[j1][k1][2]);
}
}
}
}
return ps;
}
QString DxfRotateExtrudeNode::dump(QString indent) const
{
if (dump_cache.isEmpty()) {
QString text;
text.sprintf("dxf_rotate_extrude(file = \"%s\", layer = \"%s\", "
"$fn = %f, $fa = %f, $fs = %f);\n",
filename.toAscii().data(), layername.toAscii().data(),fn, fs, fa);
((AbstractNode*)this)->dump_cache = indent + QString("n%1: ").arg(idx) + text;
}
return dump_cache;
}

2410
examples/example007.dxf Normal file

File diff suppressed because it is too large Load Diff

33
examples/example007.scad Normal file
View File

@ -0,0 +1,33 @@
module cutout()
{
intersection()
{
rotate(90, [1 0 0])
translate([0 0 -50])
dxf_linear_extrude(
file = "example007.dxf",
layer = "cutout1",
height = 100,
convexity = 1);
rotate(90, [0 0 1])
rotate(90, [1 0 0])
translate([0 0 -50])
dxf_linear_extrude(
file = "example007.dxf",
layer = "cutout2",
height = 100,
convexity = 2);
}
}
difference() {
dxf_rotate_extrude(
file = "example007.dxf",
layer="dorn",
convexity = 3);
for (r = [0 90])
rotate(r, [0 0 1])
cutout();
}

View File

@ -192,6 +192,7 @@ void initialize_builtin_modules()
register_builtin_control();
register_builtin_render();
register_builtin_dxf_linear_extrude();
register_builtin_dxf_rotate_extrude();
}
void destroy_builtin_modules()

View File

@ -265,6 +265,7 @@ extern void register_builtin_primitives();
extern void register_builtin_control();
extern void register_builtin_render();
extern void register_builtin_dxf_linear_extrude();
extern void register_builtin_dxf_rotate_extrude();
class Context
{
@ -593,6 +594,7 @@ private slots:
};
extern AbstractModule *parse(const char *text, int debug);
extern int get_fragments_from_r(double r, double fn, double fs, double fa);
extern QPointer<MainWindow> current_win;

View File

@ -16,11 +16,10 @@ 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 dxflinextrude.cc
SOURCES += dxfdata.cc dxflinextrude.cc dxfrotextrude.cc
QMAKE_CXXFLAGS += -O0
// QMAKE_CXXFLAGS += -O3 -march=pentium
// QMAKE_CXXFLAGS += -O3 -march=athlon64
QT += opengl