diff options
author | Marius Kintel <marius@kintel.net> | 2011-04-12 18:35:44 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-04-12 18:35:44 (GMT) |
commit | d24b3cc84d0701a5423925765e515db7df9614c5 (patch) | |
tree | 0d63867d8b5a3c6ffe107371caa6b29cf8ad0f02 /src | |
parent | 633343c47e0d2bced64d47f62e814489b8e76dc2 (diff) | |
parent | 1754a970a76c071fff91cc7c716aa0b78b4ac6be (diff) |
Ported recent changes to master into the visitor branch
Diffstat (limited to 'src')
44 files changed, 495 insertions, 260 deletions
diff --git a/src/CGALRenderer.cc b/src/CGALRenderer.cc index 4963814..f5bcbda 100644 --- a/src/CGALRenderer.cc +++ b/src/CGALRenderer.cc @@ -60,6 +60,11 @@ void CGALRenderer::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedro case MINKOWSKI: target.p2 = minkowski2(target.p2, src.p2); break; + case HULL: + //FIXME: Port convex hull to a binary operator or process it all in the end somehow + // target.p2 = convexhull2(target.p2, src.p2); + // target.p2 = convexhull2(polys); + break; } } else if (target.dim == 3) { @@ -76,6 +81,9 @@ void CGALRenderer::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedro case MINKOWSKI: target.p3 = minkowski3(target.p3, src.p3); break; + case HULL: + // FIXME: Print warning: hull() not supported in 3D + break; } } } diff --git a/src/CGALRenderer.h b/src/CGALRenderer.h index def07a6..045691a 100644 --- a/src/CGALRenderer.h +++ b/src/CGALRenderer.h @@ -22,7 +22,7 @@ using std::pair; class CGALRenderer : public Visitor { public: - enum CsgOp {UNION, INTERSECTION, DIFFERENCE, MINKOWSKI}; + enum CsgOp {UNION, INTERSECTION, DIFFERENCE, MINKOWSKI, HULL}; // FIXME: If a cache is not given, we need to fix this ourselves CGALRenderer(QHash<string, CGAL_Nef_polyhedron> &cache, const Tree &tree) : cache(cache), tree(tree), psrenderer(*this) {} virtual ~CGALRenderer() {} diff --git a/src/CSGTermRenderer.cc b/src/CSGTermRenderer.cc index 0f5910f..648783a 100644 --- a/src/CSGTermRenderer.cc +++ b/src/CSGTermRenderer.cc @@ -201,6 +201,9 @@ CSGTerm *CgaladvNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlight if (type == SUBDIV) return render_csg_term_from_nef(m, highlights, background, "subdiv", this->convexity); + if (type == HULL) + return render_csg_term_from_nef(m, highlights, background, "hull", this->convexity); + return NULL; } @@ -208,7 +211,7 @@ CSGTerm *CgaladvNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlight CSGTerm *CgaladvNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const { - PRINT("WARNING: Found minkowski(), glide() or subdiv() statement but compiled without CGAL support!"); + PRINT("WARNING: Found minkowski(), glide(), subdiv() or hull() statement but compiled without CGAL support!"); return NULL; } diff --git a/src/PolySetCGALRenderer.cc b/src/PolySetCGALRenderer.cc index 95e4806..71a8056 100644 --- a/src/PolySetCGALRenderer.cc +++ b/src/PolySetCGALRenderer.cc @@ -360,7 +360,13 @@ PolySet *PolySetCGALRenderer::renderPolySet(const DxfRotateExtrudeNode &node, int fragments = get_fragments_from_r(max_x, node.fn, node.fs, node.fa); - double points[fragments][dxf->paths[i].points.count()][3]; + double ***points; + points = new double**[fragments]; + for (int j=0; j < fragments; j++) { + points[j] = new double*[dxf->paths[i].points.count()]; + for (int k=0; k < dxf->paths[i].points.count(); k++) + points[j][k] = new double[3]; + } for (int j = 0; j < fragments; j++) { double a = (j*2*M_PI) / fragments; @@ -404,6 +410,13 @@ PolySet *PolySetCGALRenderer::renderPolySet(const DxfRotateExtrudeNode &node, } } } + + for (int j=0; j < fragments; j++) { + for (int k=0; k < dxf->paths[i].points.count(); k++) + delete[] points[j][k]; + delete[] points[j]; + } + delete[] points; } delete dxf; diff --git a/src/Preferences.cc b/src/Preferences.cc index 236a73c..6419944 100644 --- a/src/Preferences.cc +++ b/src/Preferences.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -10,6 +10,9 @@ #include <CGAL/Polyhedron_3.h> #include <CGAL/Nef_polyhedron_3.h> #include <CGAL/IO/Polyhedron_iostream.h> +#include <CGAL/Exact_predicates_exact_constructions_kernel.h> +#include <CGAL/Polygon_2.h> +#include <CGAL/Polygon_with_holes_2.h> typedef CGAL::Extended_cartesian<CGAL::Gmpq> CGAL_Kernel2; typedef CGAL::Nef_polyhedron_2<CGAL_Kernel2> CGAL_Nef_polyhedron2; @@ -24,6 +27,9 @@ typedef CGAL_Nef_polyhedron3::Aff_transformation_3 CGAL_Aff_transformation; typedef CGAL_Nef_polyhedron3::Vector_3 CGAL_Vector; typedef CGAL_Nef_polyhedron3::Plane_3 CGAL_Plane; typedef CGAL_Nef_polyhedron3::Point_3 CGAL_Point; +typedef CGAL::Exact_predicates_exact_constructions_kernel CGAL_ExactKernel2; +typedef CGAL::Polygon_2<CGAL_ExactKernel2> CGAL_Poly2; +typedef CGAL::Polygon_with_holes_2<CGAL_ExactKernel2> CGAL_Poly2h; struct CGAL_Nef_polyhedron { diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 0e89ed5..50d2a15 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,12 +37,14 @@ #ifdef ENABLE_CGAL extern CGAL_Nef_polyhedron3 minkowski3(CGAL_Nef_polyhedron3 a, CGAL_Nef_polyhedron3 b); extern CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b); +extern CGAL_Nef_polyhedron2 convexhull2(std::list<CGAL_Nef_polyhedron2> a); #endif enum cgaladv_type_e { MINKOWSKI, GLIDE, - SUBDIV + SUBDIV, + HULL }; class CgaladvModule : public AbstractModule @@ -143,6 +146,7 @@ void register_builtin_cgaladv() builtin_modules["minkowski"] = new CgaladvModule(MINKOWSKI); builtin_modules["glide"] = new CgaladvModule(GLIDE); builtin_modules["subdiv"] = new CgaladvModule(SUBDIV); + builtin_modules["hull"] = new CgaladvModule(HULL); } std::string CgaladvNode::toString() const @@ -160,6 +164,9 @@ std::string CgaladvNode::toString() const case SUBDIV: stream << "(level = " << this->level << ", convexity = " << this->convexity << ")"; break; + case HULL: + stream << "()"; + break; default: assert(false); } diff --git a/src/cgaladv_convexhull2.cc b/src/cgaladv_convexhull2.cc new file mode 100644 index 0000000..448dd4b --- /dev/null +++ b/src/cgaladv_convexhull2.cc @@ -0,0 +1,55 @@ +/* + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * As a special exception, you have permission to link this program + * with the CGAL library and distribute executables, as long as you + * follow the requirements of the GNU GPL in regard to all of the + * software in the executable aside from CGAL. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifdef ENABLE_CGAL + +#include "cgal.h" +#include <CGAL/convex_hull_2.h> + +extern CGAL_Nef_polyhedron2 convexhull2(std::list<CGAL_Nef_polyhedron2> a); +extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p); + +CGAL_Nef_polyhedron2 convexhull2(std::list<CGAL_Nef_polyhedron2> a) +{ + std::list<CGAL_Nef_polyhedron2::Point> points; + + std::list<CGAL_Nef_polyhedron2>::iterator i; + for (i=a.begin(); i!=a.end(); i++) { + CGAL_Poly2 ap=nef2p2(*i); + for (size_t j=0;j<ap.size();j++) { + double x=to_double(ap[j].x()),y=to_double(ap[j].y()); + CGAL_Nef_polyhedron2::Point p=CGAL_Nef_polyhedron2::Point(x,y); + points.push_back(p); + } + } + + std::list<CGAL_Nef_polyhedron2::Point> result; + CGAL::convex_hull_2(points.begin(),points.end(),std::back_inserter(result)); + + return CGAL_Nef_polyhedron2(result.begin(),result.end(),CGAL_Nef_polyhedron2::INCLUDED); +} + +#endif diff --git a/src/cgaladv_minkowski2.cc b/src/cgaladv_minkowski2.cc index 85a0b2b..8d0bf62 100644 --- a/src/cgaladv_minkowski2.cc +++ b/src/cgaladv_minkowski2.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,20 +31,53 @@ #include "grid.h" #include "cgal.h" -#if 0 -#include <CGAL/Exact_predicates_exact_constructions_kernel.h> #include <CGAL/minkowski_sum_2.h> extern CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b); +extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p); -struct K2 : public CGAL::Exact_predicates_exact_constructions_kernel {}; -typedef CGAL::Polygon_2<K2> Poly2; -typedef CGAL::Polygon_with_holes_2<K2> Poly2h; +//----------------------------------------------------------------------------- +// Pretty-print a CGAL polygon. +// +template<class Kernel, class Container> +void print_polygon (const CGAL::Polygon_2<Kernel, Container>& P) +{ + typename CGAL::Polygon_2<Kernel, Container>::Vertex_const_iterator vit; + + std::cout << "[ " << P.size() << " vertices:"; + for (vit = P.vertices_begin(); vit != P.vertices_end(); ++vit) + std::cout << " (" << *vit << ')'; + std::cout << " ]" << std::endl; +} -static Poly2 nef2p2(CGAL_Nef_polyhedron2 p) +//----------------------------------------------------------------------------- +// Pretty-print a polygon with holes. +// +template<class Kernel, class Container> +void print_polygon_with_holes (const CGAL::Polygon_with_holes_2<Kernel, Container>& pwh) { + if (! pwh.is_unbounded()) { + std::cout << "{ Outer boundary = "; + print_polygon (pwh.outer_boundary()); + } else + std::cout << "{ Unbounded polygon." << std::endl; + + typename CGAL::Polygon_with_holes_2<Kernel,Container>::Hole_const_iterator hit; + unsigned int k = 1; + + std::cout << " " << pwh.number_of_holes() << " holes:" << std::endl; + for (hit = pwh.holes_begin(); hit != pwh.holes_end(); ++hit, ++k) { + std::cout << " Hole #" << k << " = "; + print_polygon (*hit); + } + std::cout << " }" << std::endl; + + return; +} + +CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p) { - std::list<K2::Point_2> points; + std::list<CGAL_ExactKernel2::Point_2> points; Grid2d<int> grid(GRID_COARSE); typedef CGAL_Nef_polyhedron2::Explorer Explorer; @@ -53,7 +87,11 @@ static Poly2 nef2p2(CGAL_Nef_polyhedron2 p) for (fci_t fit = E.faces_begin(), fend = E.faces_end(); fit != fend; ++fit) { - if (fit != E.faces_begin()) { + if (!E.mark(fit)) { + continue; + } + //if (fit != E.faces_begin()) { + if (points.size() != 0) { PRINT("WARNING: minkowski() is not implemented for 2d objects with holes!"); break; } @@ -64,33 +102,41 @@ static Poly2 nef2p2(CGAL_Nef_polyhedron2 p) Explorer::Point ep = E.point(E.target(fcirc)); double x = to_double(ep.x()), y = to_double(ep.y()); grid.align(x, y); - points.push_back(K2::Point_2(x, y)); + points.push_back(CGAL_ExactKernel2::Point_2(x, y)); } } } - return Poly2(points.begin(), points.end()); + return CGAL_Poly2(points.begin(), points.end()); } - -CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b) -{ - Poly2 ap = nef2p2(a), bp = nef2p2(b); - Poly2h x = minkowski_sum_2(ap, bp); - /** FIXME **/ - - PRINT("WARNING: minkowski() is not implemented yet for 2d objects!"); - return CGAL_Nef_polyhedron2(); +static CGAL_Nef_polyhedron2 p2nef2(CGAL_Poly2 p2) { + std::list<CGAL_Nef_polyhedron2::Point> points; + for (size_t j = 0; j < p2.size(); j++) { + double x = to_double(p2[j].x()); + double y = to_double(p2[j].y()); + CGAL_Nef_polyhedron2::Point p = CGAL_Nef_polyhedron2::Point(x, y); + points.push_back(p); + } + return CGAL_Nef_polyhedron2(points.begin(), points.end(), CGAL_Nef_polyhedron2::INCLUDED); } -#else - -CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2, CGAL_Nef_polyhedron2) +CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b) { - PRINT("WARNING: minkowski() is not implemented yet for 2d objects!"); - return CGAL_Nef_polyhedron2(); + CGAL_Poly2 ap = nef2p2(a), bp = nef2p2(b); + + if (ap.size() == 0) { + PRINT("WARNING: minkowski() could not get any points from object 1!"); + return CGAL_Nef_polyhedron2(); + } else if (bp.size() == 0) { + PRINT("WARNING: minkowski() could not get any points from object 2!"); + return CGAL_Nef_polyhedron2(); + } else { + CGAL_Poly2h x = minkowski_sum_2(ap, bp); + + // Make a CGAL_Nef_polyhedron2 out of just the boundary for starters + return p2nef2(x.outer_boundary()); + } } #endif -#endif - diff --git a/src/cgaladv_minkowski3.cc b/src/cgaladv_minkowski3.cc index c8bf66b..f12ce21 100644 --- a/src/cgaladv_minkowski3.cc +++ b/src/cgaladv_minkowski3.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/context.cc b/src/context.cc index 65d5e23..ba2690c 100644 --- a/src/context.cc +++ b/src/context.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/control.cc b/src/control.cc index 7b631f9..ca1a4c6 100644 --- a/src/control.cc +++ b/src/control.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/csgops.cc b/src/csgops.cc index c7251f8..53e9ed6 100644 --- a/src/csgops.cc +++ b/src/csgops.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/csgterm.cc b/src/csgterm.cc index 0fd4196..930a540 100644 --- a/src/csgterm.cc +++ b/src/csgterm.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/dxfdata.cc b/src/dxfdata.cc index dc3e8a1..55d00b4 100644 --- a/src/dxfdata.cc +++ b/src/dxfdata.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,7 +33,7 @@ #include <QTextStream> #include <QHash> #include <QVector> -#include <math.h> +#include "mathc99.h" #include <assert.h> struct Line { diff --git a/src/dxfdim.cc b/src/dxfdim.cc index e1444c7..f8008f5 100644 --- a/src/dxfdim.cc +++ b/src/dxfdim.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,11 +32,10 @@ #include "printutils.h" #include "context.h" -#include <math.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> +#include "mathc99.h" #include <QHash> +#include <QDateTime> +#include <QFileInfo> QHash<QString,Value> dxf_dim_cache; QHash<QString,Value> dxf_cross_cache; @@ -62,12 +62,10 @@ Value builtin_dxf_dim(const Context *ctx, const QVector<QString> &argnames, cons name = QString::fromStdString(args[i].text); } - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(filename.toAscii().data(), &st); + QFileInfo fileInfo(filename); QString key = filename + "|" + layername + "|" + name + "|" + QString::number(xorigin) + "|" + QString::number(yorigin) + - "|" + QString::number(scale) + "|" + QString::number(st.st_mtime) + "|" + QString::number(st.st_size); + "|" + QString::number(scale) + "|" + QString::number(fileInfo.lastModified().toTime_t()) + "|" + QString::number(fileInfo.size()); if (dxf_dim_cache.contains(key)) return dxf_dim_cache[key]; @@ -144,12 +142,10 @@ Value builtin_dxf_cross(const Context *ctx, const QVector<QString> &argnames, co args[i].getnum(scale); } - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(filename.toAscii().data(), &st); + QFileInfo fileInfo(filename); QString key = filename + "|" + layername + "|" + QString::number(xorigin) + "|" + QString::number(yorigin) + - "|" + QString::number(scale) + "|" + QString::number(st.st_mtime) + "|" + QString::number(st.st_size); + "|" + QString::number(scale) + "|" + QString::number(fileInfo.lastModified().toTime_t()) + "|" + QString::number(fileInfo.size()); if (dxf_cross_cache.contains(key)) return dxf_cross_cache[key]; diff --git a/src/dxflinextrude.cc b/src/dxflinextrude.cc index aa45d79..40ddbb7 100644 --- a/src/dxflinextrude.cc +++ b/src/dxflinextrude.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,14 +38,13 @@ #include "PolySetRenderer.h" #include "openscad.h" // get_fragments_from_r() -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> #include <sstream> #include <QApplication> #include <QTime> #include <QProgressDialog> +#include <QDateTime> +#include <QFileInfo> class DxfLinearExtrudeModule : public AbstractModule { @@ -150,13 +150,11 @@ std::string DxfLinearExtrudeNode::toString() const std::stringstream stream; QString text; - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(this->filename.toAscii().data(), &st); + QFileInfo fileInfo(this->filename); stream << this->name() << "(" "file = \"" << this->filename << "\", " - "cache = \"" << std::hex << (int)st.st_mtime << "." << (int)st.st_size << "\", " + "cache = \"" << std::hex << (int)fileInfo.lastModified().toTime_t() << "." << (int)fileInfo.size() << "\", " "layer = \"" << this->layername << "\", " "height = " << std::dec << this->height << ", " "origin = [ " << this->origin_x << " " << this->origin_y << " ], " diff --git a/src/dxfrotextrude.cc b/src/dxfrotextrude.cc index b59270f..7b89676 100644 --- a/src/dxfrotextrude.cc +++ b/src/dxfrotextrude.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,14 +36,13 @@ #include "PolySetRenderer.h" #include "openscad.h" // get_fragments_from_r() -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> #include <sstream> #include <QTime> #include <QApplication> #include <QProgressDialog> +#include <QDateTime> +#include <QFileInfo> class DxfRotateExtrudeModule : public AbstractModule { @@ -125,12 +125,10 @@ std::string DxfRotateExtrudeNode::toString() const { std::stringstream stream; - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(filename.toAscii().data(), &st); + QFileInfo fileInfo(this->filename); stream << this->name() << "(" "file = \"" << this->filename << "\", " - "cache = \"" << std::hex << (int)st.st_mtime << "." << (int)st.st_size << "\", " + "cache = \"" << std::hex << (int)fileInfo.lastModified().toTime_t() << "." << (int)fileInfo.size() << "\", " "layer = \"" << this->layername << "\", " "origin = [ " << std::dec << this->origin_x << " " << this->origin_y << " ], " "scale = " << this->scale << ", " diff --git a/src/dxftess-glu.cc b/src/dxftess-glu.cc index ca12ea9..63fa2e5 100644 --- a/src/dxftess-glu.cc +++ b/src/dxftess-glu.cc @@ -9,7 +9,7 @@ # include <GL/glew.h> #endif #include <qgl.h> -#include <math.h> +#include "mathc99.h" #ifdef WIN32 # define STDCALL __stdcall diff --git a/src/dxftess.cc b/src/dxftess.cc index e145391..03ed244 100644 --- a/src/dxftess.cc +++ b/src/dxftess.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/export.cc b/src/export.cc index 215f936..f4572bc 100644 --- a/src/export.cc +++ b/src/export.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/expr.cc b/src/expr.cc index 1cfe627..72f92a0 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/func.cc b/src/func.cc index 40512a4..fd4bd7e 100644 --- a/src/func.cc +++ b/src/func.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,8 +29,8 @@ #include "context.h" #include "dxfdim.h" #include "builtin.h" -#include <math.h> #include <sstream> +#include "mathc99.h" AbstractFunction::~AbstractFunction() { @@ -290,7 +291,7 @@ Value builtin_log(const Context *, const QVector<QString>&, const QVector<Value> if (args.size() == 2 && args[0].type == Value::NUMBER && args[1].type == Value::NUMBER) return Value(log(args[1].num) / log(args[0].num)); if (args.size() == 1 && args[0].type == Value::NUMBER) - return Value(log(args[0].num) / log(10)); + return Value(log(args[0].num) / log(10.0)); return Value(); } diff --git a/src/glview.cc b/src/glview.cc index f4b2ccf..a7f3cd9 100644 --- a/src/glview.cc +++ b/src/glview.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,7 +33,7 @@ #include <QMouseEvent> #include <QMessageBox> #include <QTimer> -#include <math.h> +#include "mathc99.h" #include <stdio.h> #define FAR_FAR_AWAY 100000.0 @@ -2,8 +2,12 @@ #define GRID_H_ #include <QHash> -#include <math.h> +#include "mathc99.h" +#ifdef WIN32 +typedef __int64 int64_t; +#else #include <stdint.h> +#endif #include <stdlib.h> const double GRID_COARSE = 0.001; @@ -33,8 +37,9 @@ public: for (int64_t jy = iy - 1; jy <= iy + 1; jy++) { if (!db.contains(QPair<int64_t,int64_t>(jx, jy))) continue; - if (abs(ix-jx) + abs(iy-jy) < dist) { - dist = abs(ix-jx) + abs(iy-jy); + int d = abs(int(ix-jx)) + abs(int(iy-jy)); + if (d < dist) { + dist = d; ix = jx; iy = jy; } @@ -92,8 +97,9 @@ public: for (int64_t jz = iz - 1; jz <= iz + 1; jz++) { if (!db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(jx, jy), jz))) continue; - if (abs(ix-jx) + abs(iy-jy) + abs(iz-jz) < dist) { - dist = abs(ix-jx) + abs(iy-jy) + abs(iz-jz); + int d = abs(int(ix-jx)) + abs(int(iy-jy)) + abs(int(iz-jz)); + if (d < dist) { + dist = d; ix = jx; iy = jy; iz = jz; diff --git a/src/highlighter.cc b/src/highlighter.cc index aa21e38..759826c 100644 --- a/src/highlighter.cc +++ b/src/highlighter.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/import.cc b/src/import.cc index ba65cbb..4586237 100644 --- a/src/import.cc +++ b/src/import.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -158,13 +159,24 @@ PolySet *ImportNode::render_polyset(render_mode_e, class PolySetRenderer *) cons { f.read(80-5+4); while (1) { +#ifdef _MSC_VER +#pragma pack(push,1) +#endif struct { float i, j, k; float x1, y1, z1; float x2, y2, z2; float x3, y3, z3; unsigned short acount; - } __attribute__ ((packed)) data; + } +#ifdef __GNUC__ + __attribute__ ((packed)) +#endif + data; +#ifdef _MSC_VER +#pragma pack(pop) +#endif + if (f.read((char*)&data, sizeof(data)) != sizeof(data)) break; p->append_poly(); diff --git a/src/lexer.l b/src/lexer.l index 932711b..0da3f5d 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +32,13 @@ #include <QStack> #include <QFileInfo> #include <QDir> + +//isatty for visual c++ +#ifdef _MSC_VER +int __cdecl _isatty(int _FileHandle); +#define isatty _isatty +#endif + QString* stringcontents; int lexerget_lineno(void); #ifdef __GNUC__ diff --git a/src/mainwin.cc b/src/mainwin.cc index e7014fa..c500938 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -80,13 +81,6 @@ #include <boost/lambda/bind.hpp> using namespace boost::lambda; -//for chdir -#include <unistd.h> - -// for stat() -#include <sys/types.h> -#include <sys/stat.h> - #ifdef ENABLE_CGAL #if 1 @@ -127,7 +121,7 @@ static char helptitle[] = "OpenSCAD " QUOTED(OPENSCAD_VERSION) " (www.openscad.org)\n" "Visitor refactored version"; static char copyrighttext[] = - "Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>\n" + "Copyright (C) 2009-2011 Marius Kintel <marius@kintel.net> and Clifford Wolf <clifford@clifford.at>\n" "\n" "This program is free software; you can redistribute it and/or modify" "it under the terms of the GNU General Public License as published by" @@ -1009,10 +1003,8 @@ void MainWindow::pasteViewportRotation() void MainWindow::checkAutoReload() { QString new_stinfo; - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(this->fileName.toAscii().data(), &st); - new_stinfo.sprintf("%x.%x", (int)st.st_mtime, (int)st.st_size); + QFileInfo finfo(this->fileName); + new_stinfo = QString::number(finfo.size()) + QString::number(finfo.lastModified().toTime_t()); if (new_stinfo != autoReloadInfo) actionReloadCompile(); autoReloadInfo = new_stinfo; @@ -1526,7 +1518,7 @@ static void renderGLviaCGAL(void *vp) glColor3f(col2.redF(), col2.greenF(), col2.blueF()); // Extract the boundary, including inner boundaries of the polygons - for (fci_t fit = E.faces_begin(), fend = E.faces_end(); fit != fend; ++fit) + for (fci_t fit = E.faces_begin(), facesend = E.faces_end(); fit != facesend; ++fit) { bool fset = false; double fx = 0.0, fy = 0.0; diff --git a/src/mathc99.cc b/src/mathc99.cc new file mode 100644 index 0000000..335446e --- /dev/null +++ b/src/mathc99.cc @@ -0,0 +1,18 @@ +#include "mathc99.h"
+
+#ifdef WIN32
+#include <algorithm>
+
+double round(double a) {
+ return a > 0 ? floor(a+0.5) : ceil(a-0.5);
+}
+
+float fmin(float a, float b) {
+ return std::min(a,b);
+}
+
+float fmax(float a, float b) {
+ return std::max(a,b);
+}
+
+#endif
diff --git a/src/mathc99.h b/src/mathc99.h new file mode 100644 index 0000000..ebc2d66 --- /dev/null +++ b/src/mathc99.h @@ -0,0 +1,18 @@ +#ifndef MATHC99_H_
+#define MATHC99_H_
+
+#ifdef WIN32
+
+#include <cmath>
+//for native win32 builds we need to provide C99 math functions by ourselves
+double round(double a);
+float fmin(float a, float b);
+float fmax(float a, float b);
+
+#else
+
+#include <math.h>
+
+#endif
+
+#endif
diff --git a/src/module.cc b/src/module.cc index 49a599a..efe98e4 100644 --- a/src/module.cc +++ b/src/module.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/nef2dxf.cc b/src/nef2dxf.cc index 4c57e39..b22e605 100644 --- a/src/nef2dxf.cc +++ b/src/nef2dxf.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,7 +40,7 @@ DxfData::DxfData(const struct CGAL_Nef_polyhedron &N) typedef Explorer::Halfedge_around_face_const_circulator heafcc_t; Explorer E = N.p2.explorer(); - for (fci_t fit = E.faces_begin(), fend = E.faces_end(); fit != fend; ++fit) + for (fci_t fit = E.faces_begin(), facesend = E.faces_end(); fit != facesend; ++fit) { heafcc_t fcirc(E.halfedge(fit)), fend(fcirc); int first_point = -1, last_point = -1; diff --git a/src/node.cc b/src/node.cc index 884e983..3bc8d7b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/openscad.cc b/src/openscad.cc index be5b716..b37de12 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,6 +37,9 @@ #include "PolySetCGALRenderer.h" #include "printutils.h" +#include <string> +#include <vector> + #ifdef ENABLE_CGAL #include "cgal.h" #include <CGAL/assertions_behaviour.h> @@ -47,18 +51,24 @@ #include <QSet> #include <QSettings> #include <QTextStream> +#include <boost/program_options.hpp> -#include <getopt.h> #ifdef Q_WS_MAC #include "EventFilter.h" #include "AppleEvents.h" #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + +namespace po = boost::program_options; + static void help(const char *progname) { fprintf(stderr, "Usage: %s [ { -s stl_file | -o off_file | -x dxf_file } [ -d deps_file ] ]\\\n" - "%*s[ -m make_command ] [ -D var=val [..] ] filename\n", - progname, int(strlen(progname))+8, ""); + "%*s[ -m make_command ] [ -D var=val [..] ] filename\n", + progname, int(strlen(progname))+8, ""); exit(1); } @@ -77,6 +87,9 @@ QString currentdir; QString examplesdir; QString librarydir; +using std::string; +using std::vector; + void handle_dep(QString filename) { if (filename.startsWith("/")) @@ -128,76 +141,78 @@ int main(int argc, char **argv) const char *off_output_file = NULL; const char *dxf_output_file = NULL; const char *deps_output_file = NULL; + + po::options_description desc("Allowed options"); + desc.add_options() + ("help,h", "help message") + ("version,v", "print the version") + ("s", po::value<string>(), "stl-file") + ("o", po::value<string>(), "off-file") + ("x", po::value<string>(), "dxf-file") + ("d", po::value<string>(), "deps-file") + ("m", po::value<string>(), "makefile") + ("D", po::value<vector<string> >(), "var=val"); + + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value< vector<string> >(), "input file"); + + po::positional_options_description p; + p.add("input-file", -1); + + po::options_description all_options; + all_options.add(desc).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(all_options).positional(p).run(), vm); +// po::notify(vm); - static struct option long_options[] = - { - {"version", no_argument, 0, 'v'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} - }; - int option_index = 0; - - int opt; - while ((opt = getopt_long(argc, argv, "s:o:x:d:m:D:vh", long_options, &option_index)) != -1) - { - switch (opt) - { - case 0: - switch (option_index) - { - case 'v': - version(); - break; - case 'h': - help(argv[0]); - break; - } - break; - case 'v': - version(); - break; - case 'h': + if (vm.count("help")) help(argv[0]); + if (vm.count("version")) version(); + + if (vm.count("s")) { + if (stl_output_file || off_output_file || dxf_output_file) help(argv[0]); - break; - case 's': - if (stl_output_file || off_output_file || dxf_output_file) - help(argv[0]); - stl_output_file = optarg; - break; - case 'o': - if (stl_output_file || off_output_file || dxf_output_file) - help(argv[0]); - off_output_file = optarg; - break; - case 'x': - if (stl_output_file || off_output_file || dxf_output_file) - help(argv[0]); - dxf_output_file = optarg; - break; - case 'd': - if (deps_output_file) - help(argv[0]); - deps_output_file = optarg; - break; - case 'm': - if (make_command) - help(argv[0]); - make_command = optarg; - break; - case 'D': - commandline_commands += QString(optarg) + QString(";\n"); - break; - default: + stl_output_file = vm["s"].as<string>().c_str(); + } + if (vm.count("o")) { + if (stl_output_file || off_output_file || dxf_output_file) help(argv[0]); + off_output_file = vm["o"].as<string>().c_str(); + } + if (vm.count("x")) { + if (stl_output_file || off_output_file || dxf_output_file) + help(argv[0]); + dxf_output_file = vm["x"].as<string>().c_str(); + } + if (vm.count("d")) { + if (deps_output_file) + help(argv[0]); + deps_output_file = vm["d"].as<string>().c_str(); + } + if (vm.count("m")) { + if (make_command) + help(argv[0]); + make_command = vm["m"].as<string>().c_str(); + } + + if (vm.count("D")) { + const vector<string> &commands = vm["D"].as<vector<string> >(); + + for (vector<string>::const_iterator i = commands.begin(); i != commands.end(); i++) { + commandline_commands.append(i->c_str()); + commandline_commands.append(";\n"); } } - if (optind < argc) - filename = argv[optind++]; + if (vm.count("input-file")) { + filename = vm["input-file"].as< vector<string> >().begin()->c_str(); + } #ifndef ENABLE_MDI - if (optind != argc) + if (vm.count("input-file") > 1) { help(argv[0]); + } #endif currentdir = QDir::currentPath(); @@ -210,16 +225,16 @@ int main(int argc, char **argv) if (exdir.cd("../share/openscad/examples")) { examplesdir = exdir.path(); } else - if (exdir.cd("../../share/openscad/examples")) { - examplesdir = exdir.path(); - } else - if (exdir.cd("../../examples")) { - examplesdir = exdir.path(); - } else + if (exdir.cd("../../share/openscad/examples")) { + examplesdir = exdir.path(); + } else + if (exdir.cd("../../examples")) { + examplesdir = exdir.path(); + } else #endif - if (exdir.cd("examples")) { - examplesdir = exdir.path(); - } + if (exdir.cd("examples")) { + examplesdir = exdir.path(); + } QDir libdir(QApplication::instance()->applicationDirPath()); #ifdef Q_WS_MAC @@ -229,16 +244,16 @@ int main(int argc, char **argv) if (libdir.cd("../share/openscad/libraries")) { librarydir = libdir.path(); } else - if (libdir.cd("../../share/openscad/libraries")) { - librarydir = libdir.path(); - } else - if (libdir.cd("../../libraries")) { - librarydir = libdir.path(); - } else + if (libdir.cd("../../share/openscad/libraries")) { + librarydir = libdir.path(); + } else + if (libdir.cd("../../libraries")) { + librarydir = libdir.path(); + } else #endif - if (libdir.cd("libraries")) { - librarydir = libdir.path(); - } + if (libdir.cd("libraries")) { + librarydir = libdir.path(); + } // Initialize global visitors NodeCache nodecache; @@ -378,8 +393,13 @@ int main(int argc, char **argv) #endif #ifdef ENABLE_MDI new MainWindow(qfilename); - while (optind < argc) - new MainWindow(QFileInfo(original_path, argv[optind++]).absoluteFilePath()); + vector<string> inputFiles; + if (vm.count("input-file")) { + inputFiles = vm["input-file"].as<vector<string> >(); + for (vector<string>::const_iterator i = inputFiles.begin()+1; i != inputFiles.end(); i++) { + new MainWindow(QFileInfo(original_path, i->c_str()).absoluteFilePath()); + } + } app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); #else MainWindow *m = new MainWindow(qfilename); diff --git a/src/openscad.h b/src/openscad.h index 5a1e793..e022668 100644 --- a/src/openscad.h +++ b/src/openscad.h @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/parser.y b/src/parser.y index f0a06f5..2bd425f 100644 --- a/src/parser.y +++ b/src/parser.y @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,7 +35,9 @@ #include <sys/types.h> #include <sys/stat.h> +#ifndef _MSC_VER #include <unistd.h> +#endif #include "module.h" #include "expression.h" diff --git a/src/polyset.cc b/src/polyset.cc index 5bfabaa..eda6304 100644 --- a/src/polyset.cc +++ b/src/polyset.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -143,7 +144,7 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m #ifdef ENABLE_OPENCSG if (shaderinfo) { glUniform4f(shaderinfo[1], col.redF(), col.greenF(), col.blueF(), 1.0f); - glUniform4f(shaderinfo[2], 255 / 255.0, 236 / 255.0, 94 / 255.0, 1.0); + glUniform4f(shaderinfo[2], 255 / 255.0f, 236 / 255.0f, 94 / 255.0f, 1.0f); } #endif /* ENABLE_OPENCSG */ } @@ -154,8 +155,8 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m glColor3f(col.redF(), col.greenF(), col.blueF()); #ifdef ENABLE_OPENCSG if (shaderinfo) { - glUniform4f(shaderinfo[1], 157 / 255.0, 203 / 255.0, 81 / 255.0, 1.0); - glUniform4f(shaderinfo[2], 171 / 255.0, 216 / 255.0, 86 / 255.0, 1.0); + glUniform4f(shaderinfo[1], 157 / 255.0f, 203 / 255.0f, 81 / 255.0f, 1.0f); + glUniform4f(shaderinfo[2], 171 / 255.0f, 216 / 255.0f, 86 / 255.0f, 1.0f); } #endif /* ENABLE_OPENCSG */ } @@ -163,8 +164,8 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m glColor4ub(255, 157, 81, 128); #ifdef ENABLE_OPENCSG if (shaderinfo) { - glUniform4f(shaderinfo[1], 255 / 255.0, 157 / 255.0, 81 / 255.0, 0.5); - glUniform4f(shaderinfo[2], 255 / 255.0, 171 / 255.0, 86 / 255.0, 0.5); + glUniform4f(shaderinfo[1], 255 / 255.0f, 157 / 255.0f, 81 / 255.0f, 0.5f); + glUniform4f(shaderinfo[2], 255 / 255.0f, 171 / 255.0f, 86 / 255.0f, 0.5f); } #endif /* ENABLE_OPENCSG */ } @@ -172,8 +173,8 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m glColor4ub(180, 180, 180, 128); #ifdef ENABLE_OPENCSG if (shaderinfo) { - glUniform4f(shaderinfo[1], 180 / 255.0, 180 / 255.0, 180 / 255.0, 0.5); - glUniform4f(shaderinfo[2], 150 / 255.0, 150 / 255.0, 150 / 255.0, 0.5); + glUniform4f(shaderinfo[1], 180 / 255.0f, 180 / 255.0f, 180 / 255.0f, 0.5f); + glUniform4f(shaderinfo[2], 150 / 255.0f, 150 / 255.0f, 150 / 255.0f, 0.5f); } #endif /* ENABLE_OPENCSG */ } diff --git a/src/primitives.cc b/src/primitives.cc index 2c1cf1f..7232dc2 100644 --- a/src/primitives.cc +++ b/src/primitives.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -93,6 +94,7 @@ public: bool center; double x, y, z, h, r1, r2; + static const double F_MINIMUM = 0.01; double fn, fs, fa; primitive_type_e type; int convexity; @@ -143,6 +145,16 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstanti node->fs = c.lookup_variable("$fs").num; node->fa = c.lookup_variable("$fa").num; + if (node->fs < PrimitiveNode::F_MINIMUM) { + PRINTF("WARNING: $fs too small - clamping to %f", PrimitiveNode::F_MINIMUM); + node->fs = PrimitiveNode::F_MINIMUM; + } + if (node->fa < PrimitiveNode::F_MINIMUM) { + PRINTF("WARNING: $fa too small - clamping to %f", PrimitiveNode::F_MINIMUM); + node->fa = PrimitiveNode::F_MINIMUM; + } + + if (type == CUBE) { Value size = c.lookup_variable("size"); Value center = c.lookup_variable("center"); @@ -317,7 +329,7 @@ PolySet *PrimitiveNode::render_polyset(render_mode_e, class PolySetRenderer *) c }; int rings = get_fragments_from_r(this->r1, this->fn, this->fs, this->fa); - ring_s ring[rings]; + ring_s *ring = new ring_s[rings]; for (int i = 0; i < rings; i++) { double phi = (M_PI * (i + 0.5)) / rings; @@ -370,6 +382,8 @@ sphere_next_r2: p->append_poly(); for (int i = 0; i < ring[rings-1].fragments; i++) p->insert_vertex(ring[rings-1].points[i].x, ring[rings-1].points[i].y, ring[rings-1].z); + + delete[] ring; } if (this->type == CYLINDER && @@ -390,8 +404,8 @@ sphere_next_r2: double x, y; }; - point2d circle1[fragments]; - point2d circle2[fragments]; + point2d *circle1 = new point2d[fragments]; + point2d *circle2 = new point2d[fragments]; for (int i=0; i<fragments; i++) { double phi = (M_PI*2*i) / fragments; @@ -438,6 +452,9 @@ sphere_next_r2: for (int i=0; i<fragments; i++) p->append_vertex(circle2[i].x, circle2[i].y, z2); } + + delete[] circle1; + delete[] circle2; } if (this->type == POLYHEDRON) @@ -483,22 +500,13 @@ sphere_next_r2: { int fragments = get_fragments_from_r(this->r1, this->fn, this->fs, this->fa); - struct point2d { - double x, y; - }; - - point2d circle[fragments]; + p->is2d = true; + p->append_poly(); - for (int i=0; i<fragments; i++) { + for (int i=0; i < fragments; i++) { double phi = (M_PI*2*i) / fragments; - circle[i].x = this->r1*cos(phi); - circle[i].y = this->r1*sin(phi); + p->append_vertex(this->r1*cos(phi), this->r1*sin(phi)); } - - p->is2d = true; - p->append_poly(); - for (int i=0; i<fragments; i++) - p->append_vertex(circle[i].x, circle[i].y); } if (this->type == POLYGON) diff --git a/src/projection.cc b/src/projection.cc index b999d9b..125607d 100644 --- a/src/projection.cc +++ b/src/projection.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,9 +42,6 @@ # include <CGAL/exceptions.h> #endif -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> #include <assert.h> #include <sstream> diff --git a/src/render.cc b/src/render.cc index 8a58b7c..cac03c3 100644 --- a/src/render.cc +++ b/src/render.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/surface.cc b/src/surface.cc index c1cbe07..8bad3e5 100644 --- a/src/surface.cc +++ b/src/surface.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/transform.cc b/src/transform.cc index ccfc1aa..4238250 100644 --- a/src/transform.cc +++ b/src/transform.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/value.cc b/src/value.cc index b5c4afe..139bd1c 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +25,7 @@ */ #include "value.h" -#include <math.h> +#include "mathc99.h" #include <assert.h> #include <sstream> |