diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dxfrotextrude.cc | 15 | ||||
| -rw-r--r-- | src/grid.h | 14 | ||||
| -rw-r--r-- | src/lexer.l | 7 | ||||
| -rw-r--r-- | src/openscad.cc | 181 | ||||
| -rw-r--r-- | src/parser.y | 2 | ||||
| -rw-r--r-- | src/primitives.cc | 11 | 
6 files changed, 141 insertions, 89 deletions
| diff --git a/src/dxfrotextrude.cc b/src/dxfrotextrude.cc index a7a6cf1..1be2265 100644 --- a/src/dxfrotextrude.cc +++ b/src/dxfrotextrude.cc @@ -159,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; @@ -203,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())); @@ -2,7 +2,11 @@  #define GRID_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/lexer.l b/src/lexer.l index 985dbbe..0da3f5d 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -32,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/openscad.cc b/src/openscad.cc index 7bae683..bc1d845 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -33,6 +33,9 @@  #include "export.h"  #include "builtin.h" +#include <string> +#include <vector> +  #ifdef ENABLE_CGAL  #include "cgal.h"  #include <CGAL/assertions_behaviour.h> @@ -43,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);  } @@ -72,6 +81,9 @@ QString currentdir;  QString examplesdir;  QString librarydir; +using std::string; +using std::vector; +  void handle_dep(QString filename)  {  	if (filename.startsWith("/")) @@ -123,76 +135,72 @@ 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>(), "make file") +		("D", po::value<vector<string> >(), "var=val") +		; + +	po::positional_options_description p; +	p.add("input-file", -1); + +	po::variables_map vm; +	po::store(po::command_line_parser(argc, argv).options(desc).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(); @@ -205,16 +213,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 @@ -224,16 +232,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)  	{ @@ -338,8 +346,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-files"].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/parser.y b/src/parser.y index 26cd118..aad5ba0 100644 --- a/src/parser.y +++ b/src/parser.y @@ -35,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/primitives.cc b/src/primitives.cc index cdbb18e..1e411e0 100644 --- a/src/primitives.cc +++ b/src/primitives.cc @@ -57,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; @@ -105,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"); | 
