Permalink
Browse files

Merge branch 'master' into syntax_highlighting

  • Loading branch information...
kintel committed Dec 26, 2011
2 parents aaaed1e + 4ff2d1a commit 8ce250b2b1d3f7d40600a5046064fcaf69698294
Binary file not shown.
View
Binary file not shown.
View
@@ -187,20 +187,14 @@ HEADERS += src/renderer.h \
src/system-gl.h \
src/stl-utils.h
-SOURCES += src/openscad.cc \
- src/mainwin.cc \
+SOURCES += src/mathc99.cc \
+ src/linalg.cc \
src/handle_dep.cc \
- src/renderer.cc \
- src/rendersettings.cc \
- src/ThrownTogetherRenderer.cc \
- src/glview.cc \
- src/export.cc \
src/value.cc \
src/expr.cc \
src/func.cc \
src/module.cc \
src/node.cc \
- src/builtin.cc \
src/context.cc \
src/csgterm.cc \
src/polyset.cc \
@@ -213,28 +207,38 @@ SOURCES += src/openscad.cc \
src/surface.cc \
src/control.cc \
src/render.cc \
- src/import.cc \
src/dxfdata.cc \
- src/dxftess.cc \
- src/dxftess-glu.cc \
- src/dxftess-cgal.cc \
src/dxfdim.cc \
src/linearextrude.cc \
src/rotateextrude.cc \
- src/highlighter.cc \
src/printutils.cc \
+ src/progress.cc \
+ \
+ src/nodedumper.cc \
+ src/traverser.cc \
+ src/PolySetEvaluator.cc \
+ src/PolySetCache.cc \
+ src/Tree.cc \
+ \
+ src/rendersettings.cc \
+ src/highlighter.cc \
src/Preferences.cc \
src/OpenCSGWarningDialog.cc \
- src/progress.cc \
src/editor.cc \
- src/traverser.cc \
- src/nodedumper.cc \
+ src/glview.cc \
+ \
+ src/builtin.cc \
+ src/export.cc \
+ src/import.cc \
+ src/renderer.cc \
+ src/ThrownTogetherRenderer.cc \
+ src/dxftess.cc \
+ src/dxftess-glu.cc \
+ src/dxftess-cgal.cc \
src/CSGTermEvaluator.cc \
- src/Tree.cc \
- src/mathc99.cc \
- src/linalg.cc \
- src/PolySetCache.cc \
- src/PolySetEvaluator.cc
+ \
+ src/openscad.cc \
+ src/mainwin.cc
opencsg {
HEADERS += src/OpenCSGRenderer.h
View
@@ -99,7 +99,7 @@ CGAL_Nef_polyhedron CGALEvaluator::applyToChildren(const AbstractNode &node, CGA
const AbstractNode *chnode = item.first;
const CGAL_Nef_polyhedron &chN = item.second;
// FIXME: Don't use deep access to modinst members
- if (chnode->modinst->tag_background) continue;
+ if (chnode->modinst->isBackground()) continue;
// NB! We insert into the cache here to ensure that all children of
// a node is a valid object. If we inserted as we created them, the
@@ -127,7 +127,7 @@ CGAL_Nef_polyhedron CGALEvaluator::applyHull(const CgaladvNode &node)
const AbstractNode *chnode = item.first;
const CGAL_Nef_polyhedron &chN = item.second;
// FIXME: Don't use deep access to modinst members
- if (chnode->modinst->tag_background) continue;
+ if (chnode->modinst->isBackground()) continue;
if (dim == 0) {
dim = chN.dim;
}
View
@@ -56,10 +56,10 @@ void CSGTermEvaluator::applyToChildren(const AbstractNode &node, CSGTermEvaluato
}
}
}
- if (t1 && node.modinst->tag_highlight) {
+ if (t1 && node.modinst->isHighlight()) {
this->highlights.push_back(t1);
}
- if (t1 && node.modinst->tag_background) {
+ if (t1 && node.modinst->isBackground()) {
this->background.push_back(t1);
t1.reset(); // don't propagate background tagged nodes
}
@@ -94,10 +94,10 @@ static shared_ptr<CSGTerm> evaluate_csg_term_from_ps(const State &state,
std::stringstream stream;
stream << node.name() << node.index();
shared_ptr<CSGTerm> t(new CSGTerm(ps, state.matrix(), state.color(), stream.str()));
- if (modinst->tag_highlight) {
+ if (modinst->isHighlight()) {
highlights.push_back(t);
}
- if (modinst->tag_background) {
+ if (modinst->isBackground()) {
background.push_back(t);
t.reset();
}
@@ -26,7 +26,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node)
// Before projecting, union all children
CGAL_Nef_polyhedron sum;
BOOST_FOREACH (AbstractNode * v, node.getChildren()) {
- if (v->modinst->tag_background) continue;
+ if (v->modinst->isBackground()) continue;
CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(*v);
if (N.dim == 3) {
if (sum.empty()) sum = N.copy();
@@ -259,7 +259,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const LinearExtrudeNode &node)
// to a single DxfData, then tesselate this into a PolySet
CGAL_Nef_polyhedron sum;
BOOST_FOREACH (AbstractNode * v, node.getChildren()) {
- if (v->modinst->tag_background) continue;
+ if (v->modinst->isBackground()) continue;
CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(*v);
if (N.dim != 2) {
PRINT("ERROR: linear_extrude() is not defined for 3D child objects!");
@@ -357,7 +357,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const RotateExtrudeNode &node)
// to a single DxfData, then tesselate this into a PolySet
CGAL_Nef_polyhedron sum;
BOOST_FOREACH (AbstractNode * v, node.getChildren()) {
- if (v->modinst->tag_background) continue;
+ if (v->modinst->isBackground()) continue;
CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(*v);
if (N.dim != 2) {
PRINT("ERROR: rotate_extrude() is not defined for 3D child objects!");
View
@@ -7,8 +7,8 @@
/*!
The task of PolySetEvaluator is to create, keep track of and cache PolySet instances.
- All instances of PolySet which are not strictly temporary should be requested through this
- class.
+ All instances of PolySet which are not strictly temporary should be
+ requested through this class.
*/
/*!
View
@@ -45,6 +45,7 @@ Context::Context(const Context *parent, const Module *library)
ctx_stack.push_back(this);
if (parent) document_path = parent->document_path;
if (library) {
+ // FIXME: Don't access module members directly
this->functions_p = &library->functions;
this->modules_p = &library->modules;
this->usedlibs_p = &library->usedlibs;
@@ -148,24 +149,24 @@ Value Context::evaluate_function(const std::string &name,
AbstractNode *Context::evaluate_module(const ModuleInstantiation &inst) const
{
- if (this->modules_p && this->modules_p->find(inst.modname) != this->modules_p->end()) {
- AbstractModule *m = this->modules_p->find(inst.modname)->second;
- std::string replacement = Builtins::instance()->isDeprecated(inst.modname);
+ if (this->modules_p && this->modules_p->find(inst.name()) != this->modules_p->end()) {
+ AbstractModule *m = this->modules_p->find(inst.name())->second;
+ std::string replacement = Builtins::instance()->isDeprecated(inst.name());
if (!replacement.empty()) {
- PRINTF("DEPRECATED: The %s() module will be removed in future releases. Use %s() instead.", inst.modname.c_str(), replacement.c_str());
+ PRINTF("DEPRECATED: The %s() module will be removed in future releases. Use %s() instead.", inst.name().c_str(), replacement.c_str());
}
return m->evaluate(this, &inst);
}
if (this->usedlibs_p) {
BOOST_FOREACH(const ModuleContainer::value_type &m, *this->usedlibs_p) {
- if (m.second->modules.find(inst.modname) != m.second->modules.end()) {
+ if (m.second->modules.find(inst.name()) != m.second->modules.end()) {
Context ctx(this->parent, m.second);
- return m.second->modules[inst.modname]->evaluate(&ctx, &inst);
+ return m.second->modules[inst.name()]->evaluate(&ctx, &inst);
}
}
}
if (this->parent) return this->parent->evaluate_module(inst);
- PRINTF("WARNING: Ignoring unknown module '%s'.", inst.modname.c_str());
+ PRINTF("WARNING: Ignoring unknown module '%s'.", inst.name().c_str());
return NULL;
}
View
@@ -42,6 +42,20 @@
#include <QDir>
#include "value.h"
+/*! \class DxfData
+
+ The DxfData class fulfils multiple tasks, partially for historical reasons.
+ FIXME: It's a bit messy and is a prime target for refactoring.
+
+ 1) Read DXF file from disk
+ 2) Store contents of DXF files as points, paths and dims
+ 3) Store 2D polygons, both from the polygon() module and from 2D CSG operations.
+ Used for tesselation into triangles
+ 4) Store 2D polygons before exporting to DXF
+
+
+ */
+
struct Line {
int idx[2]; // indices into DxfData::points
bool disabled;
View
@@ -102,6 +102,9 @@ void export_stl(CGAL_Nef_polyhedron *root_N, std::ostream &output, QProgressDial
double ny = dn[2]*dn[3] - dn[0]*dn[5];
double nz = dn[0]*dn[4] - dn[1]*dn[3];
double nlength = sqrt(nx*nx + ny*ny + nz*nz);
+ // Avoid generating normals for polygons with zero area
+ double eps = 0.000001;
+ if (nlength < eps) nlength = 1.0;
output << " facet normal "
<< nx / nlength << " "
<< ny / nlength << " "
View
@@ -586,7 +586,7 @@ void MainWindow::load()
AbstractNode *MainWindow::find_root_tag(AbstractNode *n)
{
BOOST_FOREACH (AbstractNode *v, n->children) {
- if (v->modinst->tag_root) return v;
+ if (v->modinst->isRoot()) return v;
if (AbstractNode *vroot = find_root_tag(v)) return vroot;
}
return NULL;
@@ -1510,7 +1510,7 @@ void MainWindow::actionFlushCaches()
#endif
dxf_dim_cache.clear();
dxf_cross_cache.clear();
- Module::libs_cache.clear();
+ Module::clear_library_cache();
}
void MainWindow::viewModeActionsUncheck()
View
@@ -68,7 +68,6 @@ std::string ModuleInstantiation::dump(const std::string &indent) const
{
std::stringstream dump;
dump << indent;
- if (!label.empty()) dump << label <<": ";
dump << modname + "(";
for (size_t i=0; i < argnames.size(); i++) {
if (i > 0) dump << ", ";
@@ -96,10 +95,11 @@ AbstractNode *ModuleInstantiation::evaluate(const Context *ctx) const
if (this->ctx) {
PRINTF("WARNING: Ignoring recursive module instantiation of '%s'.", modname.c_str());
} else {
+ // FIXME: Casting away const..
ModuleInstantiation *that = (ModuleInstantiation*)this;
that->argvalues.clear();
- BOOST_FOREACH (Expression *v, that->argexpr) {
- that->argvalues.push_back(v->evaluate(ctx));
+ BOOST_FOREACH (Expression *expr, that->argexpr) {
+ that->argvalues.push_back(expr->evaluate(ctx));
}
that->ctx = ctx;
node = ctx->evaluate_module(*this);
@@ -113,9 +113,9 @@ std::vector<AbstractNode*> ModuleInstantiation::evaluateChildren(const Context *
{
if (!ctx) ctx = this->ctx;
std::vector<AbstractNode*> childnodes;
- BOOST_FOREACH (ModuleInstantiation *v, this->children) {
- AbstractNode *n = v->evaluate(ctx);
- if (n != NULL) childnodes.push_back(n);
+ BOOST_FOREACH (ModuleInstantiation *modinst, this->children) {
+ AbstractNode *node = modinst->evaluate(ctx);
+ if (node) childnodes.push_back(node);
}
return childnodes;
}
@@ -124,9 +124,9 @@ std::vector<AbstractNode*> IfElseModuleInstantiation::evaluateElseChildren(const
{
if (!ctx) ctx = this->ctx;
std::vector<AbstractNode*> childnodes;
- BOOST_FOREACH (ModuleInstantiation *v, this->else_children) {
- AbstractNode *n = v->evaluate(this->ctx);
- if (n != NULL) childnodes.push_back(n);
+ BOOST_FOREACH (ModuleInstantiation *modinst, this->else_children) {
+ AbstractNode *node = modinst->evaluate(ctx);
+ if (node != NULL) childnodes.push_back(node);
}
return childnodes;
}
@@ -200,3 +200,8 @@ std::string Module::dump(const std::string &indent, const std::string &name) con
}
return dump.str();
}
+
+void Module::clear_library_cache()
+{
+ Module::libs_cache.clear();
+}
Oops, something went wrong.

0 comments on commit 8ce250b

Please sign in to comment.