diff options
-rw-r--r-- | dxflinextrude.cc | 8 | ||||
-rw-r--r-- | dxfrotextrude.cc | 8 | ||||
-rw-r--r-- | mainwin.cc | 49 | ||||
-rw-r--r-- | openscad.h | 10 | ||||
-rw-r--r-- | polyset.cc | 7 | ||||
-rw-r--r-- | render.cc | 7 | ||||
-rw-r--r-- | viewoff.cc | 66 |
7 files changed, 55 insertions, 100 deletions
diff --git a/dxflinextrude.cc b/dxflinextrude.cc index 01c0319..ef54aa3 100644 --- a/dxflinextrude.cc +++ b/dxflinextrude.cc @@ -155,13 +155,11 @@ static void add_slice(PolySet *ps, DxfData::Path *pt, double rot1, double rot2, } } -static QCache<QString,PolySetPtr> ps_cache(100); - PolySet *DxfLinearExtrudeNode::render_polyset(render_mode_e) const { QString key = mk_cache_id(); - if (ps_cache.contains(key)) - return ps_cache[key]->ps->link(); + if (PolySet::ps_cache.contains(key)) + return PolySet::ps_cache[key]->ps->link(); DxfData dxf(fn, fs, fa, filename, layername, origin_x, origin_y, scale); @@ -226,7 +224,7 @@ PolySet *DxfLinearExtrudeNode::render_polyset(render_mode_e) const } } - ps_cache.insert(key, new PolySetPtr(ps->link())); + PolySet::ps_cache.insert(key, new PolySetPtr(ps->link())); return ps; } diff --git a/dxfrotextrude.cc b/dxfrotextrude.cc index 955dbc8..7af70f3 100644 --- a/dxfrotextrude.cc +++ b/dxfrotextrude.cc @@ -89,14 +89,12 @@ void register_builtin_dxf_rotate_extrude() builtin_modules["dxf_rotate_extrude"] = new DxfRotateExtrudeModule(); } -static QCache<QString,PolySetPtr> ps_cache(100); - PolySet *DxfRotateExtrudeNode::render_polyset(render_mode_e) const { QString key = mk_cache_id(); - if (ps_cache.contains(key)) - return ps_cache[key]->ps->link(); + if (PolySet::ps_cache.contains(key)) + return PolySet::ps_cache[key]->ps->link(); DxfData dxf(fn, fs, fa, filename, layername, origin_x, origin_y, scale); @@ -158,7 +156,7 @@ PolySet *DxfRotateExtrudeNode::render_polyset(render_mode_e) const } } - ps_cache.insert(key, new PolySetPtr(ps->link())); + PolySet::ps_cache.insert(key, new PolySetPtr(ps->link())); return ps; } @@ -60,7 +60,7 @@ MainWindow::MainWindow(const char *filename) tval = 0; fps = 0; - fstep = 1; + fsteps = 1; s1 = new QSplitter(Qt::Horizontal, this); editor = new QTextEdit(s1); @@ -90,8 +90,8 @@ MainWindow::MainWindow(const char *filename) l2->addWidget(e_fps = new QLineEdit("0", w2)); connect(e_fps, SIGNAL(textChanged(QString)), this, SLOT(updatedFps())); - l2->addWidget(new QLabel("Step:", w2)); - l2->addWidget(e_fstep = new QLineEdit("0", w2)); + l2->addWidget(new QLabel("Steps:", w2)); + l2->addWidget(e_fsteps = new QLineEdit("100", w2)); animate_panel = w2; animate_panel->hide(); @@ -223,10 +223,8 @@ void MainWindow::updatedFps() bool fps_ok; double fps = e_fps->text().toDouble(&fps_ok); if (!fps_ok || fps <= 0) { - // printf("-- stop --\n"); animate_timer->stop(); } else { - // printf("-- start --\n"); animate_timer->setInterval(1000 / e_fps->text().toDouble()); animate_timer->start(); } @@ -234,10 +232,11 @@ void MainWindow::updatedFps() void MainWindow::updateTVal() { - double t = e_tval->text().toDouble(); - double s = e_fstep->text().toDouble(); - e_tval->setText(QString::number(t + s)); - // printf("-- %f + %f => %s --\n", t, s, e_tval->text().toAscii().data()); + double s = e_fsteps->text().toDouble(); + double t = e_tval->text().toDouble() + 1/s; + QString txt; + txt.sprintf("%.5f", t >= 1.0 ? 0.0 : t); + e_tval->setText(txt); } void MainWindow::load() @@ -289,10 +288,11 @@ void MainWindow::find_root_tag(AbstractNode *n) } } -void MainWindow::compile() +void MainWindow::compile(bool procevents) { PRINT("Parsing design (AST generation)..."); - QApplication::processEvents(); + if (procevents) + QApplication::processEvents(); if (root_module) { delete root_module; @@ -345,7 +345,8 @@ void MainWindow::compile() goto fail; PRINT("Compiling design (CSG Tree generation)..."); - QApplication::processEvents(); + if (procevents) + QApplication::processEvents(); AbstractNode::idx_counter = 1; { @@ -362,7 +363,8 @@ void MainWindow::compile() root_node->dump(""); PRINT("Compiling design (CSG Products generation)..."); - QApplication::processEvents(); + if (procevents) + QApplication::processEvents(); double m[16]; @@ -375,7 +377,8 @@ void MainWindow::compile() goto fail; PRINT("Compiling design (CSG Products normalization)..."); - QApplication::processEvents(); + if (procevents) + QApplication::processEvents(); root_norm_term = root_raw_term->link(); @@ -403,7 +406,8 @@ void MainWindow::compile() if (highlight_terms.size() > 0) { PRINTF("Compiling highlights (%d CSG Trees)...", highlight_terms.size()); - QApplication::processEvents(); + if (procevents) + QApplication::processEvents(); highlights_chain = new CSGChain(); for (int i = 0; i < highlight_terms.size(); i++) { @@ -421,7 +425,8 @@ void MainWindow::compile() if (background_terms.size() > 0) { PRINTF("Compiling background (%d CSG Trees)...", background_terms.size()); - QApplication::processEvents(); + if (procevents) + QApplication::processEvents(); background_chain = new CSGChain(); for (int i = 0; i < background_terms.size(); i++) { @@ -438,11 +443,13 @@ void MainWindow::compile() if (1) { PRINT("Compilation finished."); - QApplication::processEvents(); + if (procevents) + QApplication::processEvents(); } else { fail: PRINT("ERROR: Compilation failed!"); - QApplication::processEvents(); + if (procevents) + QApplication::processEvents(); } } @@ -590,7 +597,7 @@ void MainWindow::actionReloadCompile() console->clear(); load(); - compile(); + compile(true); #ifdef ENABLE_OPENCSG if (!actViewModeOpenCSG->isChecked() && !actViewModeThrownTogether->isChecked()) { @@ -609,7 +616,7 @@ void MainWindow::actionCompile() current_win = this; console->clear(); - compile(); + compile(!actViewModeAnimate->isChecked()); #ifdef ENABLE_OPENCSG if (!actViewModeOpenCSG->isChecked() && !actViewModeThrownTogether->isChecked()) { @@ -641,7 +648,7 @@ void MainWindow::actionRenderCGAL() current_win = this; console->clear(); - compile(); + compile(true); if (!root_module || !root_node) return; @@ -64,6 +64,7 @@ class Module; class Context; class PolySet; +class PolySetPtr; class CSGTerm; class CSGChain; class AbstractNode; @@ -506,6 +507,8 @@ public: COLOR_BACKGROUND }; + static QCache<QString,PolySetPtr> ps_cache; + void render_surface(colormode_e colormode, GLint *shaderinfo = NULL) const; void render_edges(colormode_e colormode) const; @@ -612,6 +615,7 @@ public: 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; + static CSGTerm *render_csg_term_from_ps(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, PolySet *ps, const ModuleInstanciation *modinst, int idx); }; extern int progress_report_count; @@ -676,8 +680,8 @@ public: QWidget *animate_panel; QTimer *animate_timer; - double tval, fps, fstep; - QLineEdit *e_tval, *e_fps, *e_fstep; + double tval, fps, fsteps; + QLineEdit *e_tval, *e_fps, *e_fsteps; Context root_ctx; AbstractModule *root_module; @@ -707,7 +711,7 @@ private: void load(); void maybe_change_dir(); void find_root_tag(AbstractNode *n); - void compile(); + void compile(bool procevents); private slots: void actionNew(); @@ -22,6 +22,8 @@ #include "openscad.h" +QCache<QString,PolySetPtr> PolySet::ps_cache(100); + PolySet::PolySet() { convexity = 1; @@ -323,6 +325,11 @@ CGAL_Nef_polyhedron AbstractPolyNode::render_cgal_nef_polyhedron() const CSGTerm *AbstractPolyNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const { PolySet *ps = render_polyset(RENDER_OPENCSG); + return render_csg_term_from_ps(m, highlights, background, ps, modinst, idx); +} + +CSGTerm *AbstractPolyNode::render_csg_term_from_ps(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, PolySet *ps, const ModuleInstanciation *modinst, int idx) +{ CSGTerm *t = new CSGTerm(ps, m, QString("n%1").arg(idx)); if (modinst->tag_highlight && highlights) highlights->append(t->link()); @@ -114,6 +114,11 @@ 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)) + return AbstractPolyNode::render_csg_term_from_ps(m, highlights, background, + PolySet::ps_cache[key]->ps->link(), modinst, idx); + CGAL_Nef_polyhedron N; QString cache_id = mk_cache_id(); @@ -175,6 +180,8 @@ CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights } while (hc != hc_end); } + PolySet::ps_cache.insert(key, new PolySetPtr(ps->link())); + CSGTerm *term = new CSGTerm(ps, m, QString("n%1").arg(idx)); if (modinst->tag_highlight && highlights) highlights->append(term->link()); diff --git a/viewoff.cc b/viewoff.cc deleted file mode 100644 index 2b45e20..0000000 --- a/viewoff.cc +++ /dev/null @@ -1,66 +0,0 @@ - -// g++ -o viewoff -lCGAL -lCGAL_Qt3 -lmpfr -I/opt/qt3/include/ -L/opt/qt3/lib/ -lqt viewoff.cc - -#include <CGAL/Cartesian.h> -#include <CGAL/IO/Nef_polyhedron_iostream_3.h> -#include <CGAL/IO/Polyhedron_VRML_1_ostream.h> -#include <CGAL/IO/Polyhedron_iostream.h> -#include <CGAL/Nef_polyhedron_3.h> -#include <CGAL/Polyhedron_3.h> -#include <CGAL/Simple_cartesian.h> -#include <fstream> -#include <iostream> -#include <CGAL/IO/Qt_widget_Nef_3.h> -#include <qapplication.h> - -#define VERBOSE 0 - -typedef CGAL::Cartesian<CGAL::Gmpq> Kernel; -typedef CGAL::Polyhedron_3<Kernel> Polyhedron; -typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron; - -int main(int argc, char **argv) -{ - QApplication a(argc, argv); - - for (int i=1; i<argc; i++) { - std::ifstream inFile(argv[i]); - if (inFile.fail()) { - std::cerr << "unable to open file " << argv[i] << " for reading!" << std::endl; - exit(1); - } -#if VERBOSE - printf("--- %s ---\n", argv[i]); -#endif - Polyhedron P; - CGAL::scan_OFF(inFile, P, true); - if (inFile.bad()) { - std::cerr << "failed reading OFF file " << argv[i] << "!" << std::endl; - exit(1); - } -#if VERBOSE - printf("P: Closed: %6s\n", P.is_closed() ? "yes" : "no"); - printf("P: Vertices: %6d\n", (int)P.size_of_vertices()); - printf("P: Halfedges: %6d\n", (int)P.size_of_halfedges()); - printf("P: Facets: %6d\n", (int)P.size_of_facets()); -#endif - Nef_polyhedron NP(P); -#if VERBOSE - printf("NP: Simple: %6s\n", NP.is_simple() ? "yes" : "no"); - printf("NP: Valid: %6s\n", NP.is_valid() ? "yes" : "no"); - printf("NP: Vertices: %6d\n", (int)NP.number_of_vertices()); - printf("NP: Halfedges: %6d\n", (int)NP.number_of_halfedges()); - printf("NP: Edges: %6d\n", (int)NP.number_of_edges()); - printf("NP: Halffacets: %6d\n", (int)NP.number_of_halffacets()); - printf("NP: Facets: %6d\n", (int)NP.number_of_facets()); - printf("NP: Volumes: %6d\n", (int)NP.number_of_volumes()); -#endif - CGAL::Qt_widget_Nef_3<Nef_polyhedron>* w = new CGAL::Qt_widget_Nef_3<Nef_polyhedron>(NP); - if (i == 1) - a.setMainWidget(w); - w->show(); - } - - return a.exec(); -} - |