summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.txt2
-rw-r--r--csgops.cc10
-rw-r--r--dxflinextrude.cc9
-rw-r--r--dxfrotextrude.cc11
-rw-r--r--module.cc14
-rw-r--r--openscad.h29
-rw-r--r--polyset.cc19
-rw-r--r--printutils.cc46
-rw-r--r--printutils.h9
-rw-r--r--render.cc24
-rw-r--r--transform.cc10
11 files changed, 136 insertions, 47 deletions
diff --git a/TODO.txt b/TODO.txt
index f8e7c02..dba3d8f 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -43,6 +43,4 @@ o DXF Import
- Support for ELLIPSE entity
- Support for POLYLINE entity
- Support for SPLINE entity
-o Diagnostics
- - Cache Errors/WARNING for every cached compiler/renderer results
diff --git a/csgops.cc b/csgops.cc
index c6b3742..f4e945d 100644
--- a/csgops.cc
+++ b/csgops.cc
@@ -21,6 +21,7 @@
#define INCLUDE_ABSTRACT_NODE_DETAILS
#include "openscad.h"
+#include "printutils.h"
enum csg_type_e {
CSG_TYPE_UNION,
@@ -66,9 +67,12 @@ CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const
QString cache_id = mk_cache_id();
if (cgal_nef_cache.contains(cache_id)) {
progress_report();
- return *cgal_nef_cache[cache_id];
+ PRINT(cgal_nef_cache[cache_id]->msg);
+ return cgal_nef_cache[cache_id]->N;
}
+ print_messages_push();
+
bool first = true;
CGAL_Nef_polyhedron N;
foreach (AbstractNode *v, children) {
@@ -97,8 +101,10 @@ CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const
}
}
- cgal_nef_cache.insert(cache_id, new CGAL_Nef_polyhedron(N), N.weight());
+ cgal_nef_cache.insert(cache_id, new cgal_nef_cache_entry(N), N.weight());
+ print_messages_pop();
progress_report();
+
return N;
}
diff --git a/dxflinextrude.cc b/dxflinextrude.cc
index 06d7891..928bf5c 100644
--- a/dxflinextrude.cc
+++ b/dxflinextrude.cc
@@ -159,9 +159,12 @@ static void add_slice(PolySet *ps, DxfData::Path *pt, double rot1, double rot2,
PolySet *DxfLinearExtrudeNode::render_polyset(render_mode_e) const
{
QString key = mk_cache_id();
- if (PolySet::ps_cache.contains(key))
+ if (PolySet::ps_cache.contains(key)) {
+ PRINT(PolySet::ps_cache[key]->msg);
return PolySet::ps_cache[key]->ps->link();
+ }
+ print_messages_push();
DxfData dxf(fn, fs, fa, filename, layername, origin_x, origin_y, scale);
PolySet *ps = new PolySet();
@@ -225,7 +228,9 @@ PolySet *DxfLinearExtrudeNode::render_polyset(render_mode_e) const
}
}
- PolySet::ps_cache.insert(key, new PolySetPtr(ps->link()));
+ PolySet::ps_cache.insert(key, new PolySet::ps_cache_entry(ps->link()));
+ print_messages_pop();
+
return ps;
}
diff --git a/dxfrotextrude.cc b/dxfrotextrude.cc
index e2aca98..9855b91 100644
--- a/dxfrotextrude.cc
+++ b/dxfrotextrude.cc
@@ -21,6 +21,7 @@
#define INCLUDE_ABSTRACT_NODE_DETAILS
#include "openscad.h"
+#include "printutils.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -92,10 +93,12 @@ void register_builtin_dxf_rotate_extrude()
PolySet *DxfRotateExtrudeNode::render_polyset(render_mode_e) const
{
QString key = mk_cache_id();
-
- if (PolySet::ps_cache.contains(key))
+ if (PolySet::ps_cache.contains(key)) {
+ PRINT(PolySet::ps_cache[key]->msg);
return PolySet::ps_cache[key]->ps->link();
+ }
+ print_messages_push();
DxfData dxf(fn, fs, fa, filename, layername, origin_x, origin_y, scale);
PolySet *ps = new PolySet();
@@ -156,7 +159,9 @@ PolySet *DxfRotateExtrudeNode::render_polyset(render_mode_e) const
}
}
- PolySet::ps_cache.insert(key, new PolySetPtr(ps->link()));
+ PolySet::ps_cache.insert(key, new PolySet::ps_cache_entry(ps->link()));
+ print_messages_pop();
+
return ps;
}
diff --git a/module.cc b/module.cc
index 2ddfaa4..84db4a4 100644
--- a/module.cc
+++ b/module.cc
@@ -231,16 +231,22 @@ QString AbstractNode::mk_cache_id() const
#ifdef ENABLE_CGAL
-QCache<QString, CGAL_Nef_polyhedron> AbstractNode::cgal_nef_cache(100000);
+AbstractNode::cgal_nef_cache_entry::cgal_nef_cache_entry(CGAL_Nef_polyhedron N) :
+ N(N), msg(print_messages_stack.last()) { };
+
+QCache<QString, AbstractNode::cgal_nef_cache_entry> AbstractNode::cgal_nef_cache(100000);
static CGAL_Nef_polyhedron render_cgal_nef_polyhedron_backend(const AbstractNode *that, bool intersect)
{
QString cache_id = that->mk_cache_id();
if (that->cgal_nef_cache.contains(cache_id)) {
that->progress_report();
- return *that->cgal_nef_cache[cache_id];
+ PRINT(that->cgal_nef_cache[cache_id]->msg);
+ return that->cgal_nef_cache[cache_id]->N;
}
+ print_messages_push();
+
bool first = true;
CGAL_Nef_polyhedron N;
foreach (AbstractNode *v, that->children) {
@@ -263,8 +269,10 @@ static CGAL_Nef_polyhedron render_cgal_nef_polyhedron_backend(const AbstractNode
}
}
- that->cgal_nef_cache.insert(cache_id, new CGAL_Nef_polyhedron(N), N.weight());
+ that->cgal_nef_cache.insert(cache_id, new AbstractNode::cgal_nef_cache_entry(N), N.weight());
that->progress_report();
+ print_messages_pop();
+
return N;
}
diff --git a/openscad.h b/openscad.h
index 50f5bf7..6350e08 100644
--- a/openscad.h
+++ b/openscad.h
@@ -63,7 +63,6 @@ class Module;
class Context;
class PolySet;
-class PolySetPtr;
class CSGTerm;
class CSGChain;
class AbstractNode;
@@ -559,7 +558,14 @@ public:
CSGMODE_HIGHLIGHT_DIFFERENCE = 22
};
- static QCache<QString,PolySetPtr> ps_cache;
+ struct ps_cache_entry {
+ PolySet *ps;
+ QString msg;
+ ps_cache_entry(PolySet *ps);
+ ~ps_cache_entry();
+ };
+
+ static QCache<QString,ps_cache_entry> ps_cache;
void render_surface(colormode_e colormode, csgmode_e csgmode, GLint *shaderinfo = NULL) const;
void render_edges(colormode_e colormode, csgmode_e csgmode) const;
@@ -573,18 +579,6 @@ public:
void unlink();
};
-class PolySetPtr
-{
-public:
- PolySet *ps;
- PolySetPtr(PolySet *ps) {
- this->ps = ps;
- }
- ~PolySetPtr() {
- ps->unlink();
- }
-};
-
class CSGTerm
{
public:
@@ -647,7 +641,12 @@ public:
virtual ~AbstractNode();
virtual QString mk_cache_id() const;
#ifdef ENABLE_CGAL
- static QCache<QString, CGAL_Nef_polyhedron> cgal_nef_cache;
+ struct cgal_nef_cache_entry {
+ CGAL_Nef_polyhedron N;
+ QString msg;
+ cgal_nef_cache_entry(CGAL_Nef_polyhedron N);
+ };
+ static QCache<QString, cgal_nef_cache_entry> cgal_nef_cache;
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
#endif
virtual CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
diff --git a/polyset.cc b/polyset.cc
index 38e1026..d11f958 100644
--- a/polyset.cc
+++ b/polyset.cc
@@ -21,8 +21,16 @@
#define INCLUDE_ABSTRACT_NODE_DETAILS
#include "openscad.h"
+#include "printutils.h"
-QCache<QString,PolySetPtr> PolySet::ps_cache(100);
+QCache<QString,PolySet::ps_cache_entry> PolySet::ps_cache(100);
+
+PolySet::ps_cache_entry::ps_cache_entry(PolySet *ps) :
+ ps(ps), msg(print_messages_stack.last()) { }
+
+PolySet::ps_cache_entry::~ps_cache_entry() {
+ ps->unlink();
+}
PolySet::PolySet()
{
@@ -421,14 +429,19 @@ CGAL_Nef_polyhedron AbstractPolyNode::render_cgal_nef_polyhedron() const
QString cache_id = mk_cache_id();
if (cgal_nef_cache.contains(cache_id)) {
progress_report();
- return *cgal_nef_cache[cache_id];
+ PRINT(cgal_nef_cache[cache_id]->msg);
+ return cgal_nef_cache[cache_id]->N;
}
+ print_messages_push();
+
PolySet *ps = render_polyset(RENDER_CGAL);
CGAL_Nef_polyhedron N = ps->render_cgal_nef_polyhedron();
- cgal_nef_cache.insert(cache_id, new CGAL_Nef_polyhedron(N), N.weight());
+ cgal_nef_cache.insert(cache_id, new cgal_nef_cache_entry(N), N.weight());
+ print_messages_pop();
progress_report();
+
ps->unlink();
return N;
}
diff --git a/printutils.cc b/printutils.cc
index 8f53cd3..a75cf14 100644
--- a/printutils.cc
+++ b/printutils.cc
@@ -1,14 +1,44 @@
#include "printutils.h"
#include "MainWindow.h"
+QList<QString> print_messages_stack;
+
+void print_messages_push()
+{
+ print_messages_stack.append(QString());
+}
+
+void print_messages_pop()
+{
+ QString msg = print_messages_stack.last();
+ print_messages_stack.removeLast();
+ if (print_messages_stack.size() > 0 && !msg.isNull()) {
+ if (!print_messages_stack.last().isEmpty())
+ print_messages_stack.last() += "\n";
+ print_messages_stack.last() += msg;
+ }
+}
+
void PRINT(const QString &msg)
{
- do {
- if (MainWindow::current_win.isNull()) {
- fprintf(stderr, "%s\n", msg.toAscii().data());
- }
- else {
- MainWindow::current_win->console->append(msg);
- }
- } while (0);
+ if (msg.isNull())
+ return;
+ if (print_messages_stack.size() > 0) {
+ if (!print_messages_stack.last().isEmpty())
+ print_messages_stack.last() += "\n";
+ print_messages_stack.last() += msg;
+ }
+ PRINT_NOCACHE(msg);
}
+
+void PRINT_NOCACHE(const QString &msg)
+{
+ if (msg.isNull())
+ return;
+ if (MainWindow::current_win.isNull()) {
+ fprintf(stderr, "%s\n", msg.toAscii().data());
+ } else {
+ MainWindow::current_win->console->append(msg);
+ }
+}
+
diff --git a/printutils.h b/printutils.h
index 9fce113..18cef93 100644
--- a/printutils.h
+++ b/printutils.h
@@ -2,9 +2,18 @@
#define PRINTUTILS_H_
#include <QString>
+#include <QList>
+
+extern QList<QString> print_messages_stack;
+void print_messages_push();
+void print_messages_pop();
void PRINT(const QString &msg);
#define PRINTF(_fmt, ...) do { QString _m; _m.sprintf(_fmt, ##__VA_ARGS__); PRINT(_m); } while (0)
#define PRINTA(_fmt, ...) do { QString _m = QString(_fmt).arg(__VA_ARGS__); PRINT(_m); } while (0)
+void PRINT_NOCACHE(const QString &msg);
+#define PRINTF_NOCACHE(_fmt, ...) do { QString _m; _m.sprintf(_fmt, ##__VA_ARGS__); PRINT_NOCACHE(_m); } while (0)
+#define PRINTA_NOCACHE(_fmt, ...) do { QString _m = QString(_fmt).arg(__VA_ARGS__); PRINT_NOCACHE(_m); } while (0)
+
#endif
diff --git a/render.cc b/render.cc
index 23f7352..2f1e849 100644
--- a/render.cc
+++ b/render.cc
@@ -81,9 +81,12 @@ CGAL_Nef_polyhedron RenderNode::render_cgal_nef_polyhedron() const
QString cache_id = mk_cache_id();
if (cgal_nef_cache.contains(cache_id)) {
progress_report();
- return *cgal_nef_cache[cache_id];
+ PRINT(cgal_nef_cache[cache_id]->msg);
+ return cgal_nef_cache[cache_id]->N;
}
+ print_messages_push();
+
bool first = true;
CGAL_Nef_polyhedron N;
foreach(AbstractNode * v, children)
@@ -101,8 +104,10 @@ CGAL_Nef_polyhedron RenderNode::render_cgal_nef_polyhedron() const
}
}
- cgal_nef_cache.insert(cache_id, new CGAL_Nef_polyhedron(N), N.weight());
+ cgal_nef_cache.insert(cache_id, new cgal_nef_cache_entry(N), N.weight());
+ print_messages_pop();
progress_report();
+
return N;
}
@@ -120,20 +125,24 @@ static void report_func(const class AbstractNode*, void *vp, int mark)
CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
{
QString key = mk_cache_id();
- if (PolySet::ps_cache.contains(key))
+ if (PolySet::ps_cache.contains(key)) {
+ PRINT(PolySet::ps_cache[key]->msg);
return AbstractPolyNode::render_csg_term_from_ps(m, highlights, background,
PolySet::ps_cache[key]->ps->link(), modinst, idx);
+ }
+ print_messages_push();
CGAL_Nef_polyhedron N;
QString cache_id = mk_cache_id();
if (cgal_nef_cache.contains(cache_id))
{
- N = *cgal_nef_cache[cache_id];
+ PRINT(cgal_nef_cache[cache_id]->msg);
+ N = cgal_nef_cache[cache_id]->N;
}
else
{
- PRINT("Processing uncached render statement...");
+ PRINT_NOCACHE("Processing uncached render statement...");
// PRINTA("Cache ID: %1", cache_id);
QApplication::processEvents();
@@ -151,7 +160,7 @@ CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights
progress_report_fin();
int s = t.elapsed() / 1000;
- PRINTF("..rendering time: %d hours, %d minutes, %d seconds", s / (60*60), (s / 60) % 60, s % 60);
+ PRINTF_NOCACHE("..rendering time: %d hours, %d minutes, %d seconds", s / (60*60), (s / 60) % 60, s % 60);
delete pd;
}
@@ -201,7 +210,7 @@ CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights
if (ps)
{
ps->convexity = convexity;
- PolySet::ps_cache.insert(key, new PolySetPtr(ps->link()));
+ PolySet::ps_cache.insert(key, new PolySet::ps_cache_entry(ps->link()));
CSGTerm *term = new CSGTerm(ps, m, QString("n%1").arg(idx));
if (modinst->tag_highlight && highlights)
@@ -212,6 +221,7 @@ CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights
}
return term;
}
+ print_messages_pop();
return NULL;
}
diff --git a/transform.cc b/transform.cc
index 4e9ce0b..27a3d66 100644
--- a/transform.cc
+++ b/transform.cc
@@ -21,6 +21,7 @@
#define INCLUDE_ABSTRACT_NODE_DETAILS
#include "openscad.h"
+#include "printutils.h"
enum transform_type_e {
SCALE,
@@ -189,9 +190,12 @@ CGAL_Nef_polyhedron TransformNode::render_cgal_nef_polyhedron() const
QString cache_id = mk_cache_id();
if (cgal_nef_cache.contains(cache_id)) {
progress_report();
- return *cgal_nef_cache[cache_id];
+ PRINT(cgal_nef_cache[cache_id]->msg);
+ return cgal_nef_cache[cache_id]->N;
}
+ print_messages_push();
+
bool first = true;
CGAL_Nef_polyhedron N;
@@ -242,8 +246,10 @@ CGAL_Nef_polyhedron TransformNode::render_cgal_nef_polyhedron() const
N.p3.transform(t);
}
- cgal_nef_cache.insert(cache_id, new CGAL_Nef_polyhedron(N), N.weight());
+ cgal_nef_cache.insert(cache_id, new cgal_nef_cache_entry(N), N.weight());
+ print_messages_pop();
progress_report();
+
return N;
}
contact: Jan Huwald // Impressum