diff options
Diffstat (limited to 'src')
40 files changed, 513 insertions, 265 deletions
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 829bc84..dd797fd 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 @@ -33,12 +34,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 @@ -124,6 +127,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); } #ifdef ENABLE_CGAL @@ -173,6 +177,29 @@ CGAL_Nef_polyhedron CgaladvNode::render_cgal_nef_polyhedron() const PRINT("WARNING: subdiv() is not implemented yet!"); } + if (type == HULL) + { + std::list<CGAL_Nef_polyhedron2> polys; + bool all2d = true; + foreach(AbstractNode * v, children) { + if (v->modinst->tag_background) + continue; + N = v->render_cgal_nef_polyhedron(); + if (N.dim == 3) { + //polys.push_back(tmp.p3); + PRINT("WARNING: hull() is not implemented yet for 3D objects!"); + all2d=false; + } + if (N.dim == 2) { + polys.push_back(N.p2); + } + v->progress_report(); + } + + if (all2d) + N.p2 = convexhull2(polys); + } + cgal_nef_cache.insert(cache_id, new cgal_nef_cache_entry(N), N.weight()); print_messages_pop(); progress_report(); @@ -191,6 +218,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; } @@ -198,7 +228,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; } @@ -216,6 +246,8 @@ QString CgaladvNode::dump(QString indent) const } if (type == SUBDIV) text.sprintf("subdiv(level = %d, convexity = %d) {\n", this->level, this->convexity); + if (type == HULL) + text.sprintf("hull() {\n"); foreach (AbstractNode *v, this->children) text += v->dump(indent + QString("\t")); text += indent + "}\n"; 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 cc9ef00..f270de2 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 5aec712b..bfe9eb6 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 5b7e1b1..ae1d654 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 ae97085..55d91d2 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 942aba6..6dd3bd5 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 02a1274..4c53d86 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 = 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 83c3d9c..9661066 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 @@ -34,13 +35,11 @@ #include "progress.h" #include "openscad.h" // get_fragments_from_r() -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - #include <QApplication> #include <QTime> #include <QProgressDialog> +#include <QDateTime> +#include <QFileInfo> class DxfLinearExtrudeModule : public AbstractModule { @@ -320,14 +319,12 @@ QString DxfLinearExtrudeNode::dump(QString indent) const { if (dump_cache.isEmpty()) { QString text; - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(filename.toAscii().data(), &st); + QFileInfo fileInfo(filename); text.sprintf("linear_extrude(file = \"%s\", cache = \"%x.%x\", layer = \"%s\", " "height = %g, origin = [ %g %g ], scale = %g, center = %s, convexity = %d", - filename.toAscii().data(), (int)st.st_mtime, (int)st.st_size, - layername.toAscii().data(), height, origin_x, origin_y, scale, - center ? "true" : "false", convexity); + filename.toAscii().data(), (int)fileInfo.lastModified().toTime_t(), + (int)fileInfo.size(), layername.toAscii().data(), height, origin_x, + origin_y, scale, center ? "true" : "false", convexity); if (has_twist) { QString t2; t2.sprintf(", twist = %g, slices = %d", twist, slices); diff --git a/src/dxfrotextrude.cc b/src/dxfrotextrude.cc index ea603f0..1be2265 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 @@ -33,13 +34,11 @@ #include "progress.h" #include "openscad.h" // get_fragments_from_r() -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - #include <QTime> #include <QApplication> #include <QProgressDialog> +#include <QDateTime> +#include <QFileInfo> class DxfRotateExtrudeModule : public AbstractModule { @@ -160,7 +159,13 @@ PolySet *DxfRotateExtrudeNode::render_polyset(render_mode_e) const int fragments = get_fragments_from_r(max_x, fn, fs, 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; @@ -204,6 +209,13 @@ PolySet *DxfRotateExtrudeNode::render_polyset(render_mode_e) const } } } + + 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; } PolySet::ps_cache.insert(key, new PolySet::ps_cache_entry(ps->link())); @@ -217,15 +229,13 @@ QString DxfRotateExtrudeNode::dump(QString indent) const { if (dump_cache.isEmpty()) { QString text; - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(filename.toAscii().data(), &st); + QFileInfo fileInfo(filename); text.sprintf("rotate_extrude(file = \"%s\", cache = \"%x.%x\", layer = \"%s\", " "origin = [ %g %g ], scale = %g, convexity = %d, " "$fn = %g, $fa = %g, $fs = %g) {\n", - filename.toAscii().data(), (int)st.st_mtime, (int)st.st_size, - layername.toAscii().data(), origin_x, origin_y, scale, convexity, - fn, fa, fs); + filename.toAscii().data(), (int)fileInfo.lastModified().toTime_t(), + (int)fileInfo.size(),layername.toAscii().data(), origin_x, origin_y, + scale, convexity, fn, fa, fs); foreach (AbstractNode *v, children) text += v->dump(indent + QString("\t")); text += indent + "}\n"; 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 2b474f6..884e139 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 23bcc32..50950d0 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 e8ff54a..2608960 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,7 +29,8 @@ #include "context.h" #include "dxfdim.h" #include "builtin.h" -#include <math.h> +#include "mathc99.h" +#include <time.h> AbstractFunction::~AbstractFunction() { @@ -289,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 d51714b..870a1c9 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 @@ -31,7 +32,7 @@ #include <QMouseEvent> #include <QMessageBox> #include <QTimer> -#include <math.h> +#include "mathc99.h" #include <stdio.h> #define FAR_FAR_AWAY 100000.0 @@ -1,8 +1,12 @@ #ifndef GRID_H_ #define GRID_H_ -#include <math.h> +#include "mathc99.h" +#ifdef WIN32 +typedef __int64 int64_t; +#else #include <stdint.h> +#endif #include <stdlib.h> #include <QHash> @@ -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 bab13ae..a924e24 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 @@ -173,13 +174,24 @@ PolySet *ImportNode::render_polyset(render_mode_e) const { 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 ef738fc..e217b1f 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 @@ -72,13 +73,6 @@ #include "qlanguagefactory.h" #endif -//for chdir -#include <unistd.h> - -// for stat() -#include <sys/types.h> -#include <sys/stat.h> - #ifdef ENABLE_CGAL #if 1 @@ -117,7 +111,7 @@ static char helptitle[] = QUOTED(OPENSCAD_VERSION) " (www.openscad.org)\n"; 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" @@ -992,10 +986,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; @@ -1473,7 +1465,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 1a1e30e..54b151c 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 44d7561..320d6b8 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 @@ -38,7 +39,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 87a7051..87b3c2b 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 bf24c9f..aa0188c 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 @@ -32,6 +33,9 @@ #include "export.h" #include "builtin.h" +#include <string> +#include <vector> + #ifdef ENABLE_CGAL #include "cgal.h" #include <CGAL/assertions_behaviour.h> @@ -42,17 +46,23 @@ #include <QDir> #include <QSet> #include <QSettings> -#include <getopt.h> +#include <boost/program_options.hpp> #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); } @@ -71,6 +81,9 @@ QString currentdir; QString examplesdir; QString librarydir; +using std::string; +using std::vector; + void handle_dep(QString filename) { if (filename.startsWith("/")) @@ -122,76 +135,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(); @@ -204,16 +219,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 @@ -223,16 +238,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(); + } if (stl_output_file || off_output_file || dxf_output_file) { @@ -337,8 +352,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 0cace25..aad5ba0 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 d438769..cccdaad 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 @@ -149,7 +150,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 */ } @@ -158,8 +159,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 */ } @@ -167,8 +168,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 */ } @@ -176,8 +177,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 ac1f0a3..5ba32fe 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 @@ -56,6 +57,7 @@ class PrimitiveNode : public AbstractPolyNode 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; @@ -104,6 +106,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"); @@ -278,7 +290,7 @@ PolySet *PrimitiveNode::render_polyset(render_mode_e) const }; int rings = get_fragments_from_r(r1, fn, fs, 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; @@ -332,6 +344,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 (type == CYLINDER && h > 0 && r1 >=0 && r2 >= 0 && (r1 > 0 || r2 > 0)) @@ -351,8 +365,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; @@ -399,6 +413,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 (type == POLYHEDRON) @@ -444,22 +461,13 @@ sphere_next_r2: { int fragments = get_fragments_from_r(r1, fn, fs, 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 = r1*cos(phi); - circle[i].y = r1*sin(phi); + p->append_vertex(r1*cos(phi), 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 (type == POLYGON) diff --git a/src/projection.cc b/src/projection.cc index 7a3f77a..f41ba56 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 @@ -39,9 +40,6 @@ # include <CGAL/exceptions.h> #endif -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> #include <assert.h> #include <QApplication> diff --git a/src/render.cc b/src/render.cc index d851fc8..9fa7ab6 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 ddcd3a6..92b661f 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 746283e..e841ef0 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 a237c5a..b0a79a4 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" Value::Value() { |