diff options
author | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-01-10 13:32:22 (GMT) |
---|---|---|
committer | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-01-10 13:32:22 (GMT) |
commit | e3f339813c3a286eb4ac438aa32e2003b6ecab8a (patch) | |
tree | 277fe3bb4a831535ee47eea844dec1e1395d7025 | |
parent | 53f26d0308501ebf1d755553f8680bef6f838344 (diff) |
Clifford Wolf:
Cache dxf_dim and dxf_cross results
(massive speedup in designs using this functions)
git-svn-id: http://svn.clifford.at/openscad/trunk@261 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r-- | dxfdim.cc | 33 | ||||
-rw-r--r-- | mainwin.cc | 2 | ||||
-rw-r--r-- | openscad.h | 3 |
3 files changed, 35 insertions, 3 deletions
@@ -21,6 +21,13 @@ #include "openscad.h" #include "printutils.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +QHash<QString,Value> dxf_dim_cache; +QHash<QString,Value> dxf_cross_cache; + Value builtin_dxf_dim(const QVector<QString> &argnames, const QVector<Value> &args) { QString filename; @@ -43,6 +50,16 @@ Value builtin_dxf_dim(const QVector<QString> &argnames, const QVector<Value> &ar name = args[i].text; } + struct stat st; + memset(&st, 0, sizeof(struct stat)); + stat(filename.toAscii().data(), &st); + + QString key = filename + "|" + layername + "|" + name + "|" + QString::number(xorigin) + "|" + QString::number(yorigin) + + "|" + QString::number(scale) + "|" + QString::number(st.st_mtime) + "|" + QString::number(st.st_size); + + if (dxf_dim_cache.contains(key)) + return dxf_dim_cache[key]; + DxfData dxf(36, 0, 0, filename, layername, xorigin, yorigin, scale); for (int i = 0; i < dxf.dims.count(); i++) @@ -59,7 +76,7 @@ Value builtin_dxf_dim(const QVector<QString> &argnames, const QVector<Value> &ar double y = d->coords[4][1] - d->coords[3][1]; double angle = d->angle; double distance_projected_on_line = fabs(x * cos(angle*M_PI/180) + y * sin(angle*M_PI/180)); - return Value(distance_projected_on_line); + return dxf_dim_cache[key] = Value(distance_projected_on_line); } if (type == 1) { // Aligned @@ -68,7 +85,7 @@ Value builtin_dxf_dim(const QVector<QString> &argnames, const QVector<Value> &ar // Angular double a1 = atan2(d->coords[0][0] - d->coords[5][0], d->coords[0][1] - d->coords[5][1]); double a2 = atan2(d->coords[4][0] - d->coords[3][0], d->coords[4][1] - d->coords[3][1]); - return Value(fabs(a1 - a2) * 180 / M_PI); + return dxf_dim_cache[key] = Value(fabs(a1 - a2) * 180 / M_PI); } if (type == 3) { // Diameter @@ -108,6 +125,16 @@ Value builtin_dxf_cross(const QVector<QString> &argnames, const QVector<Value> & args[i].getnum(scale); } + struct stat st; + memset(&st, 0, sizeof(struct stat)); + stat(filename.toAscii().data(), &st); + + QString key = filename + "|" + layername + "|" + QString::number(xorigin) + "|" + QString::number(yorigin) + + "|" + QString::number(scale) + "|" + QString::number(st.st_mtime) + "|" + QString::number(st.st_size); + + if (dxf_cross_cache.contains(key)) + return dxf_cross_cache[key]; + DxfData dxf(36, 0, 0, filename, layername, xorigin, yorigin, scale); double coords[4][2]; @@ -136,7 +163,7 @@ Value builtin_dxf_cross(const QVector<QString> &argnames, const QVector<Value> & ret.type = Value::VECTOR; ret.vec.append(new Value(x)); ret.vec.append(new Value(y)); - return ret; + return dxf_cross_cache[key] = ret; } } @@ -1133,6 +1133,8 @@ void MainWindow::actionFlushCaches() { PolySet::ps_cache.clear(); AbstractNode::cgal_nef_cache.clear(); + dxf_dim_cache.clear(); + dxf_cross_cache.clear(); } void MainWindow::viewModeActionsUncheck() @@ -684,6 +684,9 @@ public: static CSGTerm *render_csg_term_from_ps(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, PolySet *ps, const ModuleInstantiation *modinst, int idx); }; +extern QHash<QString,Value> dxf_dim_cache; +extern QHash<QString,Value> dxf_cross_cache; + extern int progress_report_count; extern void (*progress_report_f)(const class AbstractNode*, void*, int); extern void *progress_report_vp; |