From 90f58ced7dd48c5df7be89a875c092e69f91e72d Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Wed, 5 Nov 2014 21:24:09 +0400 Subject: [PATCH] Allow preview of designs with only background or highlight objects. Fixes #1005 --- src/CsgInfo.h | 26 +++++----- src/OpenCSGRenderer.cc | 16 +++---- src/mainwin.cc | 105 ++++++++++++++++++++--------------------- 3 files changed, 74 insertions(+), 73 deletions(-) diff --git a/src/CsgInfo.h b/src/CsgInfo.h index bb054aea..c50ab4d4 100644 --- a/src/CsgInfo.h +++ b/src/CsgInfo.h @@ -43,8 +43,8 @@ public: CSGTermEvaluator evaluator(tree, &geomevaluator); boost::shared_ptr root_raw_term = evaluator.evaluateCSGTerm( *root_node, this->highlight_terms, this->background_terms ); - if (!root_raw_term) { - PRINT("Error: CSG generation failed! (no top level object found)"); + if (!root_raw_term && this->background_terms.empty()) { + PRINT("Error: CSG generation failed! (no objects found)"); call_progress_function(); return false; } @@ -52,16 +52,18 @@ public: PRINT("Compiling design (CSG Products normalization)..."); call_progress_function(); CSGTermNormalizer normalizer( normalizelimit ); - this->root_norm_term = normalizer.normalize(root_raw_term); - if (this->root_norm_term) { - this->root_chain = new CSGChain(); - this->root_chain->import(this->root_norm_term); - PRINTB("Normalized CSG tree has %d elements", int(this->root_chain->objects.size())); - } - else { - this->root_chain = NULL; - PRINT("WARNING: CSG normalization resulted in an empty tree"); - call_progress_function(); + if (root_raw_term) { + this->root_norm_term = normalizer.normalize(root_raw_term); + if (this->root_norm_term) { + this->root_chain = new CSGChain(); + this->root_chain->import(this->root_norm_term); + PRINTB("Normalized CSG tree has %d elements", int(this->root_chain->objects.size())); + } + else { + this->root_chain = NULL; + PRINT("WARNING: CSG normalization resulted in an empty tree"); + call_progress_function(); + } } if (this->highlight_terms.size() > 0) { diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc index 4c41e059..3c6f0b48 100644 --- a/src/OpenCSGRenderer.cc +++ b/src/OpenCSGRenderer.cc @@ -58,16 +58,16 @@ OpenCSGRenderer::OpenCSGRenderer(CSGChain *root_chain, CSGChain *highlights_chai void OpenCSGRenderer::draw(bool /*showfaces*/, bool showedges) const { + GLint *shaderinfo = this->shaderinfo; + if (!shaderinfo[0]) shaderinfo = NULL; if (this->root_chain) { - GLint *shaderinfo = this->shaderinfo; - if (!shaderinfo[0]) shaderinfo = NULL; renderCSGChain(this->root_chain, showedges ? shaderinfo : NULL, false, false); - if (this->background_chain) { - renderCSGChain(this->background_chain, showedges ? shaderinfo : NULL, false, true); - } - if (this->highlights_chain) { - renderCSGChain(this->highlights_chain, showedges ? shaderinfo : NULL, true, false); - } + } + if (this->background_chain) { + renderCSGChain(this->background_chain, showedges ? shaderinfo : NULL, false, true); + } + if (this->highlights_chain) { + renderCSGChain(this->highlights_chain, showedges ? shaderinfo : NULL, true, false); } } diff --git a/src/mainwin.cc b/src/mainwin.cc index cd61ec8a..223e7727 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -1031,8 +1031,8 @@ void MainWindow::compileCSG(bool procevents) CSGTermEvaluator csgrenderer(this->tree, &geomevaluator); if (procevents) QApplication::processEvents(); this->root_raw_term = csgrenderer.evaluateCSGTerm(*root_node, highlight_terms, background_terms); - if (!root_raw_term) { - PRINT("ERROR: CSG generation failed! (no top level object found)"); + if (!root_raw_term && background_terms.empty()) { + PRINT("ERROR: CSG generation failed! (no objects found)"); } GeometryCache::instance()->print(); #ifdef ENABLE_CGAL @@ -1048,12 +1048,13 @@ void MainWindow::compileCSG(bool procevents) delete this->progresswidget; this->progresswidget = NULL; - if (root_raw_term) { - PRINT("Compiling design (CSG Products normalization)..."); - if (procevents) QApplication::processEvents(); + PRINT("Compiling design (CSG Products normalization)..."); + if (procevents) QApplication::processEvents(); - size_t normalizelimit = 2 * Preferences::inst()->getValue("advanced/openCSGLimit").toUInt(); - CSGTermNormalizer normalizer(normalizelimit); + size_t normalizelimit = 2 * Preferences::inst()->getValue("advanced/openCSGLimit").toUInt(); + CSGTermNormalizer normalizer(normalizelimit); + + if (root_raw_term) { this->root_norm_term = normalizer.normalize(this->root_raw_term); if (this->root_norm_term) { this->root_chain = new CSGChain(); @@ -1064,53 +1065,51 @@ void MainWindow::compileCSG(bool procevents) PRINT("WARNING: CSG normalization resulted in an empty tree"); if (procevents) QApplication::processEvents(); } - - if (highlight_terms.size() > 0) - { - PRINTB("Compiling highlights (%d CSG Trees)...", highlight_terms.size()); - if (procevents) QApplication::processEvents(); - - highlights_chain = new CSGChain(); - for (unsigned int i = 0; i < highlight_terms.size(); i++) { - highlight_terms[i] = normalizer.normalize(highlight_terms[i]); - highlights_chain->import(highlight_terms[i]); - } - } - - if (background_terms.size() > 0) - { - PRINTB("Compiling background (%d CSG Trees)...", background_terms.size()); - if (procevents) QApplication::processEvents(); - - background_chain = new CSGChain(); - for (unsigned int i = 0; i < background_terms.size(); i++) { - background_terms[i] = normalizer.normalize(background_terms[i]); - background_chain->import(background_terms[i]); - } - } - - if (this->root_chain && - (this->root_chain->objects.size() > - Preferences::inst()->getValue("advanced/openCSGLimit").toUInt())) { - PRINTB("WARNING: Normalized tree has %d elements!", this->root_chain->objects.size()); - PRINT("WARNING: OpenCSG rendering has been disabled."); - } - else { - PRINTB("Normalized CSG tree has %d elements", - (this->root_chain ? this->root_chain->objects.size() : 0)); - this->opencsgRenderer = new OpenCSGRenderer(this->root_chain, - this->highlights_chain, - this->background_chain, - this->qglview->shaderinfo); - } - this->thrownTogetherRenderer = new ThrownTogetherRenderer(this->root_chain, - this->highlights_chain, - this->background_chain); - PRINT("CSG generation finished."); - int s = t.elapsed() / 1000; - PRINTB("Total rendering time: %d hours, %d minutes, %d seconds", (s / (60*60)) % ((s / 60) % 60) % (s % 60)); - if (procevents) QApplication::processEvents(); } + + if (highlight_terms.size() > 0) { + PRINTB("Compiling highlights (%d CSG Trees)...", highlight_terms.size()); + if (procevents) QApplication::processEvents(); + + highlights_chain = new CSGChain(); + for (unsigned int i = 0; i < highlight_terms.size(); i++) { + highlight_terms[i] = normalizer.normalize(highlight_terms[i]); + highlights_chain->import(highlight_terms[i]); + } + } + + if (background_terms.size() > 0) { + PRINTB("Compiling background (%d CSG Trees)...", background_terms.size()); + if (procevents) QApplication::processEvents(); + + background_chain = new CSGChain(); + for (unsigned int i = 0; i < background_terms.size(); i++) { + background_terms[i] = normalizer.normalize(background_terms[i]); + background_chain->import(background_terms[i]); + } + } + + if (this->root_chain && + (this->root_chain->objects.size() > + Preferences::inst()->getValue("advanced/openCSGLimit").toUInt())) { + PRINTB("WARNING: Normalized tree has %d elements!", this->root_chain->objects.size()); + PRINT("WARNING: OpenCSG rendering has been disabled."); + } + else { + PRINTB("Normalized CSG tree has %d elements", + (this->root_chain ? this->root_chain->objects.size() : 0)); + this->opencsgRenderer = new OpenCSGRenderer(this->root_chain, + this->highlights_chain, + this->background_chain, + this->qglview->shaderinfo); + } + this->thrownTogetherRenderer = new ThrownTogetherRenderer(this->root_chain, + this->highlights_chain, + this->background_chain); + PRINT("CSG generation finished."); + int s = t.elapsed() / 1000; + PRINTB("Total rendering time: %d hours, %d minutes, %d seconds", (s / (60*60)) % ((s / 60) % 60) % (s % 60)); + if (procevents) QApplication::processEvents(); } void MainWindow::actionUpdateCheck()