diff options
| -rw-r--r-- | src/dxfdim.cc | 17 | ||||
| -rw-r--r-- | src/import.cc | 2 | ||||
| -rw-r--r-- | src/linearextrude.cc | 2 | ||||
| -rw-r--r-- | src/module.cc | 22 | ||||
| -rw-r--r-- | src/module.h | 8 | ||||
| -rw-r--r-- | src/parser.y | 50 | ||||
| -rw-r--r-- | src/rotateextrude.cc | 2 | ||||
| -rw-r--r-- | src/surface.cc | 2 | ||||
| -rw-r--r-- | testdata/scad/misc/localfiles-test.scad | 3 | ||||
| -rw-r--r-- | testdata/scad/misc/localfiles_dir/localfile.dat | 2 | ||||
| -rw-r--r-- | testdata/scad/misc/localfiles_dir/localfile.dxf | 1968 | ||||
| -rw-r--r-- | testdata/scad/misc/localfiles_dir/localfiles_module.scad | 10 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | tests/dumptest.cc | 10 | ||||
| -rw-r--r-- | tests/regression/cgalpngtest/localfiles-test-expected.png | bin | 0 -> 8454 bytes | |||
| -rw-r--r-- | tests/regression/dumptest/localfiles-test-expected.txt | 17 | ||||
| -rw-r--r-- | tests/regression/opencsgtest/localfiles-test-expected.png | bin | 0 -> 8844 bytes | |||
| -rw-r--r-- | tests/regression/throwntogethertest/localfiles-test-expected.png | bin | 0 -> 8844 bytes | 
18 files changed, 2080 insertions, 42 deletions
| diff --git a/src/dxfdim.cc b/src/dxfdim.cc index 1ed37fa..53bc480 100644 --- a/src/dxfdim.cc +++ b/src/dxfdim.cc @@ -49,6 +49,9 @@ Value builtin_dxf_dim(const Context *ctx, const std::vector<std::string> &argnam  	double yorigin = 0;  	double scale = 1; +  // FIXME: We don't lookup the file relative to where this function was instantiated +	// since the path is only available for ModuleInstantiations, not function expressions. +	// See isse #217  	for (size_t i = 0; i < argnames.size() && i < args.size(); i++) {  		if (argnames[i] == "file")  			filename = ctx->getAbsolutePath(args[i].toString()); @@ -63,9 +66,16 @@ Value builtin_dxf_dim(const Context *ctx, const std::vector<std::string> &argnam  	}  	std::stringstream keystream; +	fs::path filepath(filename); +	uintmax_t filesize = -1; +	time_t lastwritetime = -1; +	if (fs::exists(filepath) && fs::is_regular_file(filepath)) { +		filesize = fs::file_size(filepath); +		lastwritetime = fs::last_write_time(filepath); +	}  	keystream << filename << "|" << layername << "|" << name << "|" << xorigin -						<< "|" << yorigin <<"|" << scale << "|" << fs::last_write_time(filename) -						<< "|" << fs::file_size(filename); +						<< "|" << yorigin <<"|" << scale << "|" << lastwritetime +						<< "|" << filesize;  	std::string key = keystream.str();  	if (dxf_dim_cache.find(key) != dxf_dim_cache.end())  		return dxf_dim_cache.find(key)->second; @@ -133,6 +143,9 @@ Value builtin_dxf_cross(const Context *ctx, const std::vector<std::string> &argn  	double yorigin = 0;  	double scale = 1; +  // FIXME: We don't lookup the file relative to where this function was instantiated +	// since the path is only available for ModuleInstantiations, not function expressions. +	// See isse #217  	for (size_t i = 0; i < argnames.size() && i < args.size(); i++) {  		if (argnames[i] == "file")  			filename = ctx->getAbsolutePath(args[i].toString()); diff --git a/src/import.cc b/src/import.cc index 32d4fed..bbf5a6e 100644 --- a/src/import.cc +++ b/src/import.cc @@ -80,7 +80,7 @@ AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiati  	c.args(argnames, argexpr, inst_argnames, inst->argvalues);  	Value v = c.lookup_variable("file"); -	std::string filename = c.getAbsolutePath(v.isUndefined() ? "" : v.toString()); +	std::string filename = inst->getAbsolutePath(v.isUndefined() ? "" : v.toString());  	import_type_e actualtype = this->type;  	if (actualtype == TYPE_UNKNOWN) {  		std::string extraw = boosty::extension_str( fs::path(filename) ); diff --git a/src/linearextrude.cc b/src/linearextrude.cc index 43db907..ff9682e 100644 --- a/src/linearextrude.cc +++ b/src/linearextrude.cc @@ -75,7 +75,7 @@ AbstractNode *LinearExtrudeModule::evaluate(const Context *ctx, const ModuleInst  	if (!file.isUndefined()) {  		PRINT("DEPRECATED: Support for reading files in linear_extrude will be removed in future releases. Use a child import() instead."); -		node->filename = c.getAbsolutePath(file.toString()); +		node->filename = inst->getAbsolutePath(file.toString());  	}  	// if height not given, and first argument is a number, diff --git a/src/module.cc b/src/module.cc index e6dcb57..322085b 100644 --- a/src/module.cc +++ b/src/module.cc @@ -32,6 +32,9 @@  #include "function.h"  #include "printutils.h" +#include <boost/filesystem.hpp> +namespace fs = boost::filesystem; +#include "boosty.h"  #include <boost/foreach.hpp>  #include <sstream>  #include <sys/stat.h> @@ -67,6 +70,19 @@ IfElseModuleInstantiation::~IfElseModuleInstantiation()  	BOOST_FOREACH (ModuleInstantiation *v, else_children) delete v;  } +/*! +	Returns the absolute path to the given filename, unless it's empty. + */ +std::string ModuleInstantiation::getAbsolutePath(const std::string &filename) const +{ +	if (!filename.empty() && !boosty::is_absolute(fs::path(filename))) { +		return boosty::absolute(fs::path(this->modpath) / filename).string(); +	} +	else { +		return filename; +	} +} +  std::string ModuleInstantiation::dump(const std::string &indent) const  {  	std::stringstream dump; @@ -152,15 +168,15 @@ AbstractNode *Module::evaluate(const Context *ctx, const ModuleInstantiation *in  	c.functions_p = &functions;  	c.modules_p = &modules; - +	  	if (!usedlibs.empty())  		c.usedlibs_p = &usedlibs;  	else  		c.usedlibs_p = NULL; - +	  	BOOST_FOREACH(const std::string &var, assignments_var) {  		c.set_variable(var, assignments.at(var)->evaluate(&c)); -	} +  }  	AbstractNode *node = new AbstractNode(inst);  	for (size_t i = 0; i < children.size(); i++) { diff --git a/src/module.h b/src/module.h index cc82f81..1f9e303 100644 --- a/src/module.h +++ b/src/module.h @@ -10,7 +10,7 @@  class ModuleInstantiation  {  public: -	ModuleInstantiation(const std::string &name = "")  +	ModuleInstantiation(const std::string &name = "")  	: ctx(NULL),   		tag_root(false), tag_highlight(false), tag_background(false), modname(name) { }  	virtual ~ModuleInstantiation(); @@ -19,6 +19,10 @@ public:  	class AbstractNode *evaluate(const class Context *ctx) const;  	std::vector<AbstractNode*> evaluateChildren(const Context *ctx = NULL) const; +	void setPath(const std::string &path) { this->modpath = path; } +	const std::string &path() const { return this->modpath; } +	std::string getAbsolutePath(const std::string &filename) const; +  	const std::string &name() const { return this->modname; }  	bool isBackground() const { return this->tag_background; }  	bool isHighlight() const { return this->tag_highlight; } @@ -35,6 +39,7 @@ public:  	bool tag_background;  protected:  	std::string modname; +	std::string modpath;  	friend class Module;  }; @@ -61,6 +66,7 @@ class Module : public AbstractModule  public:  	Module() : is_handling_dependencies(false) { }  	virtual ~Module(); +  	virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;  	virtual std::string dump(const std::string &indent, const std::string &name) const; diff --git a/src/parser.y b/src/parser.y index 536f4ef..70aebba 100644 --- a/src/parser.y +++ b/src/parser.y @@ -58,6 +58,12 @@ int lexerlex(void);  std::vector<Module*> module_stack;  Module *currmodule; +extern void lexerdestroy(); +extern FILE *lexerin; +extern const char *parser_input_buffer; +const char *parser_input_buffer; +std::string parser_source_path; +  class ArgContainer {  public:   	std::string argname; @@ -77,6 +83,7 @@ public:  	class Value *value;  	class Expression *expr;  	class ModuleInstantiation *inst; +	std::vector<ModuleInstantiation*> *instvec;  	class IfElseModuleInstantiation *ifelse;  	class ArgContainer *arg;  	class ArgsContainer *args; @@ -117,8 +124,8 @@ public:  %type <inst> module_instantiation  %type <ifelse> if_statement  %type <ifelse> ifelse_statement -%type <inst> children_instantiation -%type <inst> module_instantiation_list +%type <instvec> children_instantiation +%type <instvec> module_instantiation_list  %type <inst> single_module_instantiation  %type <args> arguments_call @@ -182,9 +189,9 @@ statement:  /* Will return a dummy parent node with zero or more children */  children_instantiation:  	module_instantiation { -		$$ = new ModuleInstantiation(); +		$$ = new std::vector<ModuleInstantiation*>;  		if ($1) {  -			$$->children.push_back($1); +			$$->push_back($1);  		}  	} |  	'{' module_instantiation_list '}' { @@ -196,14 +203,14 @@ if_statement:  		$$ = new IfElseModuleInstantiation();  		$$->argnames.push_back("");  		$$->argexpr.push_back($3); +                $$->setPath(parser_source_path);  		if ($$) { -			$$->children = $5->children; +                  $$->children = *$5;  		} else { -			for (size_t i = 0; i < $5->children.size(); i++) -				delete $5->children[i]; +			for (size_t i = 0; i < $5->size(); i++) +                          delete (*$5)[i];  		} -		$5->children.clear();  		delete $5;  	} ; @@ -214,12 +221,11 @@ ifelse_statement:  	if_statement TOK_ELSE children_instantiation {  		$$ = $1;  		if ($$) { -			$$->else_children = $3->children; +                  $$->else_children = *$3;  		} else { -			for (size_t i = 0; i < $3->children.size(); i++) -				delete $3->children[i]; +			for (size_t i = 0; i < $3->size(); i++) +                          delete (*$3)[i];  		} -		$3->children.clear();  		delete $3;  	} ; @@ -246,12 +252,11 @@ module_instantiation:  	single_module_instantiation children_instantiation {  		$$ = $1;  		if ($$) { -			$$->children = $2->children; +			$$->children = *$2;  		} else { -			for (size_t i = 0; i < $2->children.size(); i++) -				delete $2->children[i]; +			for (size_t i = 0; i < $2->size(); i++) +                          delete (*$2)[i];  		} -		$2->children.clear();  		delete $2;  	} |  	ifelse_statement { @@ -260,12 +265,12 @@ module_instantiation:  module_instantiation_list:  	/* empty */ { -		$$ = new ModuleInstantiation(); +		$$ = new std::vector<ModuleInstantiation*>;  	} |  	module_instantiation_list module_instantiation {  		$$ = $1;  		if ($$) { -			if ($2) $$->children.push_back($2); +			if ($2) $$->push_back($2);  		} else {  			delete $2;  		} @@ -276,6 +281,7 @@ single_module_instantiation:  		$$ = new ModuleInstantiation($1);  		$$->argnames = $3->argnames;  		$$->argexpr = $3->argexpr; +                $$->setPath(parser_source_path);  		free($1);  		delete $3;  	} @@ -536,18 +542,12 @@ void yyerror (char const *s)  	currmodule = NULL;  } -extern void lexerdestroy(); -extern FILE *lexerin; -extern const char *parser_input_buffer; -const char *parser_input_buffer; -std::string parser_source_path; -  Module *parse(const char *text, const char *path, int debug)  {  	lexerin = NULL;  	parser_error_pos = -1;  	parser_input_buffer = text; -	parser_source_path = std::string(path); +	parser_source_path = boosty::absolute(std::string(path)).string();  	module_stack.clear();  	Module *rootmodule = currmodule = new Module(); diff --git a/src/rotateextrude.cc b/src/rotateextrude.cc index dc8ea34..c4d9342 100644 --- a/src/rotateextrude.cc +++ b/src/rotateextrude.cc @@ -71,7 +71,7 @@ AbstractNode *RotateExtrudeModule::evaluate(const Context *ctx, const ModuleInst  	if (!file.isUndefined()) {  		PRINT("DEPRECATED: Support for reading files in rotate_extrude will be removed in future releases. Use a child import() instead."); -		node->filename = c.getAbsolutePath(file.toString()); +		node->filename = inst->getAbsolutePath(file.toString());  	}  	node->layername = layer.isUndefined() ? "" : layer.toString(); diff --git a/src/surface.cc b/src/surface.cc index 4339ead..ca5031e 100644 --- a/src/surface.cc +++ b/src/surface.cc @@ -83,7 +83,7 @@ AbstractNode *SurfaceModule::evaluate(const Context *ctx, const ModuleInstantiat  	c.args(argnames, argexpr, inst->argnames, inst->argvalues);  	Value fileval = c.lookup_variable("file"); -	node->filename = c.getAbsolutePath(fileval.isUndefined() ? "" : fileval.toString()); +	node->filename = inst->getAbsolutePath(fileval.isUndefined() ? "" : fileval.toString());  	Value center = c.lookup_variable("center", true);  	if (center.type() == Value::BOOL) { diff --git a/testdata/scad/misc/localfiles-test.scad b/testdata/scad/misc/localfiles-test.scad new file mode 100644 index 0000000..31efe96 --- /dev/null +++ b/testdata/scad/misc/localfiles-test.scad @@ -0,0 +1,3 @@ +use <localfiles_dir/localfiles_module.scad> + +localfiles_module(); diff --git a/testdata/scad/misc/localfiles_dir/localfile.dat b/testdata/scad/misc/localfiles_dir/localfile.dat new file mode 100644 index 0000000..32eba08 --- /dev/null +++ b/testdata/scad/misc/localfiles_dir/localfile.dat @@ -0,0 +1,2 @@ +0 1 +2 3 diff --git a/testdata/scad/misc/localfiles_dir/localfile.dxf b/testdata/scad/misc/localfiles_dir/localfile.dxf new file mode 100644 index 0000000..933e263 --- /dev/null +++ b/testdata/scad/misc/localfiles_dir/localfile.dxf @@ -0,0 +1,1968 @@ +999 +dxflib 2.2.0.0 +  0 +SECTION +  2 +HEADER +  9 +$ACADVER +  1 +AC1015 +  9 +$HANDSEED +  5 +FFFF +  9 +$DIMASZ + 40 +2.5 +  9 +$PLIMMIN + 10 +0.0 + 20 +0.0 +  9 +$DIMEXE + 40 +1.25 +  9 +$DIMGAP + 40 +0.625 +  9 +$PLIMMAX + 10 +210.0 + 20 +297.0 +  9 +$INSUNITS + 70 +4 +  9 +$DIMSTYLE +  2 +Standard +  9 +$CLAYER +  8 +0 +  9 +$DIMEXO + 40 +0.625 +  9 +$DIMTXT + 40 +2.5 +  9 +$CLAYER +  8 +0 +  0 +ENDSEC +  0 +SECTION +  2 +TABLES +  0 +TABLE +  2 +VPORT +  5 +8 +100 +AcDbSymbolTable + 70 +1 +  0 +VPORT +  5 +30 +100 +AcDbSymbolTableRecord +100 +AcDbViewportTableRecord +  2 +*Active + 70 +0 + 10 +0.0 + 20 +0.0 + 11 +1.0 + 21 +1.0 + 12 +286.3055555555554861 + 22 +148.5 + 13 +0.0 + 23 +0.0 + 14 +10.0 + 24 +10.0 + 15 +10.0 + 25 +10.0 + 16 +0.0 + 26 +0.0 + 36 +1.0 + 17 +0.0 + 27 +0.0 + 37 +0.0 + 40 +297.0 + 41 +1.92798353909465 + 42 +50.0 + 43 +0.0 + 44 +0.0 + 50 +0.0 + 51 +0.0 + 71 +0 + 72 +100 + 73 +1 + 74 +3 + 75 +1 + 76 +1 + 77 +0 + 78 +0 +281 +0 + 65 +1 +110 +0.0 +120 +0.0 +130 +0.0 +111 +1.0 +121 +0.0 +131 +0.0 +112 +0.0 +122 +1.0 +132 +0.0 + 79 +0 +146 +0.0 +  0 +ENDTAB +  0 +TABLE +  2 +LTYPE +  5 +5 +100 +AcDbSymbolTable + 70 +21 +  0 +LTYPE +  5 +14 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +ByBlock + 70 +0 +  3 + + 72 +65 + 73 +0 + 40 +0.0 +  0 +LTYPE +  5 +15 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +ByLayer + 70 +0 +  3 + + 72 +65 + 73 +0 + 40 +0.0 +  0 +LTYPE +  5 +16 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +CONTINUOUS + 70 +0 +  3 +Solid line + 72 +65 + 73 +0 + 40 +0.0 +  0 +LTYPE +  5 +31 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DOT + 70 +0 +  3 +Dot . . . . . . . . . . . . . . . . . . . . . . + 72 +65 + 73 +2 + 40 +6.3499999999999996 + 49 +0.0 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 +  0 +LTYPE +  5 +32 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DOT2 + 70 +0 +  3 +Dot (.5x) ..................................... + 72 +65 + 73 +2 + 40 +3.1749999999999998 + 49 +0.0 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 +  0 +LTYPE +  5 +33 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DOTX2 + 70 +0 +  3 +Dot (2x) .  .  .  .  .  .  .  .  .  .  .  .  . + 72 +65 + 73 +2 + 40 +12.6999999999999993 + 49 +0.0 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 +  0 +LTYPE +  5 +34 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DASHED + 70 +0 +  3 +Dashed __ __ __ __ __ __ __ __ __ __ __ __ __ _ + 72 +65 + 73 +2 + 40 +19.0500000000000007 + 49 +12.6999999999999993 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 +  0 +LTYPE +  5 +35 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DASHED2 + 70 +0 +  3 +Dashed (.5x) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + 72 +65 + 73 +2 + 40 +9.5250000000000004 + 49 +6.3499999999999996 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 +  0 +LTYPE +  5 +36 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DASHEDX2 + 70 +0 +  3 +Dashed (2x) ____  ____  ____  ____  ____  ___ + 72 +65 + 73 +2 + 40 +38.1000000000000014 + 49 +25.3999999999999986 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 +  0 +LTYPE +  5 +37 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DASHDOT + 70 +0 +  3 +Dash dot __ . __ . __ . __ . __ . __ . __ . __ + 72 +65 + 73 +4 + 40 +25.3999999999999986 + 49 +12.6999999999999993 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 +  0 +LTYPE +  5 +38 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DASHDOT2 + 70 +0 +  3 +Dash dot (.5x) _._._._._._._._._._._._._._._. + 72 +65 + 73 +4 + 40 +12.6999999999999993 + 49 +6.3499999999999996 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 +  0 +LTYPE +  5 +39 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DASHDOTX2 + 70 +0 +  3 +Dash dot (2x) ____  .  ____  .  ____  .  ___ + 72 +65 + 73 +4 + 40 +50.7999999999999972 + 49 +25.3999999999999986 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 +  0 +LTYPE +  5 +3A +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DIVIDE + 70 +0 +  3 +Divide ____ . . ____ . . ____ . . ____ . . ____ + 72 +65 + 73 +6 + 40 +31.75 + 49 +12.6999999999999993 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 +  0 +LTYPE +  5 +3B +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DIVIDE2 + 70 +0 +  3 +Divide (.5x) __..__..__..__..__..__..__..__.._ + 72 +65 + 73 +6 + 40 +15.875 + 49 +6.3499999999999996 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 +  0 +LTYPE +  5 +3C +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +DIVIDEX2 + 70 +0 +  3 +Divide (2x) ________  .  .  ________  .  .  _ + 72 +65 + 73 +6 + 40 +63.5 + 49 +25.3999999999999986 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 +  0 +LTYPE +  5 +3D +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +CENTER + 70 +0 +  3 +Center ____ _ ____ _ ____ _ ____ _ ____ _ ____ + 72 +65 + 73 +4 + 40 +50.7999999999999972 + 49 +31.75 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 + 49 +6.3499999999999996 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 +  0 +LTYPE +  5 +3E +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +CENTER2 + 70 +0 +  3 +Center (.5x) ___ _ ___ _ ___ _ ___ _ ___ _ ___ + 72 +65 + 73 +4 + 40 +28.5749999999999993 + 49 +19.0500000000000007 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 + 49 +3.1749999999999998 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 +  0 +LTYPE +  5 +3F +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +CENTERX2 + 70 +0 +  3 +Center (2x) ________  __  ________  __  _____ + 72 +65 + 73 +4 + 40 +101.5999999999999943 + 49 +63.5 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 + 49 +12.6999999999999993 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 +  0 +LTYPE +  5 +40 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +BORDER + 70 +0 +  3 +Border __ __ . __ __ . __ __ . __ __ . __ __ . + 72 +65 + 73 +6 + 40 +44.4500000000000028 + 49 +12.6999999999999993 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 + 49 +12.6999999999999993 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-6.3499999999999996 + 74 +0 +  0 +LTYPE +  5 +41 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +BORDER2 + 70 +0 +  3 +Border (.5x) __.__.__.__.__.__.__.__.__.__.__. + 72 +65 + 73 +6 + 40 +22.2250000000000014 + 49 +6.3499999999999996 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 + 49 +6.3499999999999996 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-3.1749999999999998 + 74 +0 +  0 +LTYPE +  5 +42 +100 +AcDbSymbolTableRecord +100 +AcDbLinetypeTableRecord +  2 +BORDERX2 + 70 +0 +  3 +Border (2x) ____  ____  .  ____  ____  .  ___ + 72 +65 + 73 +6 + 40 +88.9000000000000057 + 49 +25.3999999999999986 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 + 49 +25.3999999999999986 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 + 49 +0.0 + 74 +0 + 49 +-12.6999999999999993 + 74 +0 +  0 +ENDTAB +  0 +TABLE +  2 +LAYER +  5 +2 +100 +AcDbSymbolTable + 70 +1 +  0 +LAYER +  5 +10 +100 +AcDbSymbolTableRecord +100 +AcDbLayerTableRecord +  2 +0 + 70 +0 + 62 +7 +420 +0 +  6 +CONTINUOUS +370 +25 +390 +F +  0 +ENDTAB +  0 +TABLE +  2 +STYLE +  5 +3 +100 +AcDbSymbolTable + 70 +1 +  0 +STYLE +  5 +11 +100 +AcDbSymbolTableRecord +100 +AcDbTextStyleTableRecord +  2 +Standard + 70 +0 + 40 +0.0 + 41 +0.75 + 50 +0.0 + 71 +0 + 42 +2.5 +  3 +txt +  4 + +  0 +ENDTAB +  0 +TABLE +  2 +VIEW +  5 +6 +100 +AcDbSymbolTable + 70 +0 +  0 +ENDTAB +  0 +TABLE +  2 +UCS +  5 +7 +100 +AcDbSymbolTable + 70 +0 +  0 +ENDTAB +  0 +TABLE +  2 +APPID +  5 +9 +100 +AcDbSymbolTable + 70 +1 +  0 +APPID +  5 +12 +100 +AcDbSymbolTableRecord +100 +AcDbRegAppTableRecord +  2 +ACAD + 70 +0 +  0 +ENDTAB +  0 +TABLE +  2 +DIMSTYLE +  5 +A +100 +AcDbSymbolTable + 70 +1 +100 +AcDbDimStyleTable + 71 +0 +  0 +DIMSTYLE +105 +27 +100 +AcDbSymbolTableRecord +100 +AcDbDimStyleTableRecord +  2 +Standard + 41 +2.5 + 42 +0.625 + 43 +3.75 + 44 +1.25 + 70 +0 + 73 +0 + 74 +0 + 77 +1 + 78 +8 +140 +2.5 +141 +2.5 +143 +0.03937007874016 +147 +0.625 +171 +3 +172 +1 +271 +2 +272 +2 +274 +3 +278 +44 +283 +0 +284 +8 +340 +11 +  0 +ENDTAB +  0 +TABLE +  2 +BLOCK_RECORD +  5 +1 +100 +AcDbSymbolTable + 70 +1 +  0 +BLOCK_RECORD +  5 +1F +100 +AcDbSymbolTableRecord +100 +AcDbBlockTableRecord +  2 +*Model_Space +340 +22 +  0 +BLOCK_RECORD +  5 +1B +100 +AcDbSymbolTableRecord +100 +AcDbBlockTableRecord +  2 +*Paper_Space +340 +1E +  0 +BLOCK_RECORD +  5 +23 +100 +AcDbSymbolTableRecord +100 +AcDbBlockTableRecord +  2 +*Paper_Space0 +340 +26 +  0 +ENDTAB +  0 +ENDSEC +  0 +SECTION +  2 +BLOCKS +  0 +BLOCK +  5 +20 +100 +AcDbEntity +  8 +0 +100 +AcDbBlockBegin +  2 +*Model_Space + 70 +0 + 10 +0.0 + 20 +0.0 + 30 +0.0 +  3 +*Model_Space +  1 + +  0 +ENDBLK +  5 +21 +100 +AcDbEntity +  8 +0 +100 +AcDbBlockEnd +  0 +BLOCK +  5 +1C +100 +AcDbEntity + 67 +1 +  8 +0 +100 +AcDbBlockBegin +  2 +*Paper_Space + 70 +0 + 10 +0.0 + 20 +0.0 + 30 +0.0 +  3 +*Paper_Space +  1 + +  0 +ENDBLK +  5 +1D +100 +AcDbEntity + 67 +1 +  8 +0 +100 +AcDbBlockEnd +  0 +BLOCK +  5 +24 +100 +AcDbEntity +  8 +0 +100 +AcDbBlockBegin +  2 +*Paper_Space0 + 70 +0 + 10 +0.0 + 20 +0.0 + 30 +0.0 +  3 +*Paper_Space0 +  1 + +  0 +ENDBLK +  5 +25 +100 +AcDbEntity +  8 +0 +100 +AcDbBlockEnd +  0 +ENDSEC +  0 +SECTION +  2 +ENTITIES +  0 +LINE +  5 +43 +100 +AcDbEntity +100 +AcDbLine +  8 +0 + 62 +256 +370 +-1 +  6 +ByLayer + 10 +10.0 + 20 +100.0 + 30 +0.0 + 11 +210.0 + 21 +100.0 + 31 +0.0 +  0 +LINE +  5 +44 +100 +AcDbEntity +100 +AcDbLine +  8 +0 + 62 +256 +370 +-1 +  6 +ByLayer + 10 +210.0 + 20 +100.0 + 30 +0.0 + 11 +210.0 + 21 +-100.0 + 31 +0.0 +  0 +LINE +  5 +45 +100 +AcDbEntity +100 +AcDbLine +  8 +0 + 62 +256 +370 +-1 +  6 +ByLayer + 10 +210.0 + 20 +-100.0 + 30 +0.0 + 11 +10.0 + 21 +-100.0 + 31 +0.0 +  0 +LINE +  5 +46 +100 +AcDbEntity +100 +AcDbLine +  8 +0 + 62 +256 +370 +-1 +  6 +ByLayer + 10 +10.0 + 20 +-100.0 + 30 +0.0 + 11 +10.0 + 21 +100.0 + 31 +0.0 +  0 +DIMENSION +  5 +47 +100 +AcDbEntity +  8 +0 + 62 +256 +370 +-1 +  6 +ByLayer +100 +AcDbDimension + 10 +10.0000000000000018 + 20 +150.0 + 30 +0.0 + 11 +110.0 + 21 +151.875 + 31 +0.0 + 70 +1 + 71 +5 + 72 +1 + 41 +1.0 + 42 +0.0 +  1 +localfile +  3 +Standard +100 +AcDbAlignedDimension + 13 +10.0 + 23 +130.0 + 33 +0.0 + 14 +210.0 + 24 +130.0 + 34 +0.0 +  0 +ENDSEC +  0 +SECTION +  2 +OBJECTS +  0 +DICTIONARY +  5 +C +100 +AcDbDictionary +280 +0 +281 +1 +  3 +ACAD_GROUP +350 +D +  3 +ACAD_LAYOUT +350 +1A +  3 +ACAD_MLINESTYLE +350 +17 +  3 +ACAD_PLOTSETTINGS +350 +19 +  3 +ACAD_PLOTSTYLENAME +350 +E +  3 +AcDbVariableDictionary +350 +48 +  0 +DICTIONARY +  5 +D +100 +AcDbDictionary +280 +0 +281 +1 +  0 +ACDBDICTIONARYWDFLT +  5 +E +100 +AcDbDictionary +281 +1 +  3 +Normal +350 +F +100 +AcDbDictionaryWithDefault +340 +F +  0 +ACDBPLACEHOLDER +  5 +F +  0 +DICTIONARY +  5 +17 +100 +AcDbDictionary +280 +0 +281 +1 +  3 +Standard +350 +18 +  0 +MLINESTYLE +  5 +18 +100 +AcDbMlineStyle +  2 +STANDARD + 70 +0 +  3 + + 62 +256 + 51 +90.0 + 52 +90.0 + 71 +2 + 49 +0.5 + 62 +256 +  6 +BYLAYER + 49 +-0.5 + 62 +256 +  6 +BYLAYER +  0 +DICTIONARY +  5 +19 +100 +AcDbDictionary +280 +0 +281 +1 +  0 +DICTIONARY +  5 +1A +100 +AcDbDictionary +281 +1 +  3 +Layout1 +350 +1E +  3 +Layout2 +350 +26 +  3 +Model +350 +22 +  0 +LAYOUT +  5 +1E +100 +AcDbPlotSettings +  1 + +  2 +C:\Program Files\AutoCAD 2002\plotters\DWF ePlot (optimized for plotting).pc3 +  4 + +  6 + + 40 +0.0 + 41 +0.0 + 42 +0.0 + 43 +0.0 + 44 +0.0 + 45 +0.0 + 46 +0.0 + 47 +0.0 + 48 +0.0 + 49 +0.0 +140 +0.0 +141 +0.0 +142 +1.0 +143 +1.0 + 70 +688 + 72 +0 + 73 +0 + 74 +5 +  7 + + 75 +16 +147 +1.0 +148 +0.0 +149 +0.0 +100 +AcDbLayout +  1 +Layout1 + 70 +1 + 71 +1 + 10 +0.0 + 20 +0.0 + 11 +420.0 + 21 +297.0 + 12 +0.0 + 22 +0.0 + 32 +0.0 + 14 +100000000000000000000.0 + 24 +100000000000000000000.0 + 34 +100000000000000000000.0 + 15 +-100000000000000000000.0 + 25 +-100000000000000000000.0 + 35 +-100000000000000000000.0 +146 +0.0 + 13 +0.0 + 23 +0.0 + 33 +0.0 + 16 +1.0 + 26 +0.0 + 36 +0.0 + 17 +0.0 + 27 +1.0 + 37 +0.0 + 76 +0 +330 +1B +  0 +LAYOUT +  5 +22 +100 +AcDbPlotSettings +  1 + +  2 +C:\Program Files\AutoCAD 2002\plotters\DWF ePlot (optimized for plotting).pc3 +  4 + +  6 + + 40 +0.0 + 41 +0.0 + 42 +0.0 + 43 +0.0 + 44 +0.0 + 45 +0.0 + 46 +0.0 + 47 +0.0 + 48 +0.0 + 49 +0.0 +140 +0.0 +141 +0.0 +142 +1.0 +143 +1.0 + 70 +1712 + 72 +0 + 73 +0 + 74 +0 +  7 + + 75 +0 +147 +1.0 +148 +0.0 +149 +0.0 +100 +AcDbLayout +  1 +Model + 70 +1 + 71 +0 + 10 +0.0 + 20 +0.0 + 11 +12.0 + 21 +9.0 + 12 +0.0 + 22 +0.0 + 32 +0.0 + 14 +0.0 + 24 +0.0 + 34 +0.0 + 15 +0.0 + 25 +0.0 + 35 +0.0 +146 +0.0 + 13 +0.0 + 23 +0.0 + 33 +0.0 + 16 +1.0 + 26 +0.0 + 36 +0.0 + 17 +0.0 + 27 +1.0 + 37 +0.0 + 76 +0 +330 +1F +  0 +LAYOUT +  5 +26 +100 +AcDbPlotSettings +  1 + +  2 +C:\Program Files\AutoCAD 2002\plotters\DWF ePlot (optimized for plotting).pc3 +  4 + +  6 + + 40 +0.0 + 41 +0.0 + 42 +0.0 + 43 +0.0 + 44 +0.0 + 45 +0.0 + 46 +0.0 + 47 +0.0 + 48 +0.0 + 49 +0.0 +140 +0.0 +141 +0.0 +142 +1.0 +143 +1.0 + 70 +688 + 72 +0 + 73 +0 + 74 +5 +  7 + + 75 +16 +147 +1.0 +148 +0.0 +149 +0.0 +100 +AcDbLayout +  1 +Layout2 + 70 +1 + 71 +2 + 10 +0.0 + 20 +0.0 + 11 +12.0 + 21 +9.0 + 12 +0.0 + 22 +0.0 + 32 +0.0 + 14 +0.0 + 24 +0.0 + 34 +0.0 + 15 +0.0 + 25 +0.0 + 35 +0.0 +146 +0.0 + 13 +0.0 + 23 +0.0 + 33 +0.0 + 16 +1.0 + 26 +0.0 + 36 +0.0 + 17 +0.0 + 27 +1.0 + 37 +0.0 + 76 +0 +330 +23 +  0 +DICTIONARY +  5 +48 +100 +AcDbDictionary +281 +1 +  3 +DIMASSOC +350 +4A +  3 +HIDETEXT +350 +49 +  0 +DICTIONARYVAR +  5 +49 +100 +DictionaryVariables +280 +0 +  1 +2 +  0 +DICTIONARYVAR +  5 +4A +100 +DictionaryVariables +280 +0 +  1 +1 +  0 +ENDSEC +  0 +EOF diff --git a/testdata/scad/misc/localfiles_dir/localfiles_module.scad b/testdata/scad/misc/localfiles_dir/localfiles_module.scad new file mode 100644 index 0000000..b98a49b --- /dev/null +++ b/testdata/scad/misc/localfiles_dir/localfiles_module.scad @@ -0,0 +1,10 @@ +module localfiles_module() +{ +  linear_extrude(h=100) import("localfile.dxf"); +  translate([-250,0,0]) linear_extrude(file="localfile.dxf"); +  translate([0,350,0]) rotate_extrude(file="localfile.dxf"); +  translate([250,0,0]) scale([200,200,50]) surface("localfile.dat"); + +  // This is not supported: +  // echo(dxf_dim(file="localfile.dxf", name="localfile")); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5eecaae..a0d8f6b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -769,12 +769,15 @@ list(APPEND ECHO_FILES ${FUNCTION_FILES}  list(APPEND DUMPTEST_FILES ${MINIMAL_FILES} ${FEATURES_FILES} ${EXAMPLE_FILES})  list(APPEND DUMPTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/escape-test.scad                             ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad -                           ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad) +                           ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad +                           ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles-test.scad)  list(APPEND CGALPNGTEST_FILES ${FEATURES_FILES} ${SCAD_DXF_FILES} ${EXAMPLE_FILES})  list(APPEND CGALPNGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad                             ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad -                           ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/transform-nan-inf-tests.scad) +                           ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/transform-nan-inf-tests.scad +                           ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles-test.scad) +  list(APPEND OPENCSGTEST_FILES ${CGALPNGTEST_FILES})  list(APPEND OPENCSGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/bbox-transform-bug.scad)  list(APPEND OPENCSGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/intersection-prune-test.scad) diff --git a/tests/dumptest.cc b/tests/dumptest.cc index b75a2e2..3627608 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -118,7 +118,6 @@ int main(int argc, char **argv)  		exit(1);  	} -	fs::current_path(original_path);  	std::ofstream outfile;  	outfile.open(outfilename);  	outfile << dumpstdstr << "\n"; @@ -127,21 +126,22 @@ int main(int argc, char **argv)  	delete root_node;  	delete root_module; +	fs::current_path(original_path);  	root_module = parsefile(outfilename);  	if (!root_module) {  		fprintf(stderr, "Error: Unable to read back dumped file\n");  		exit(1);  	} -	if (fs::path(filename).has_parent_path()) { -		fs::current_path(fs::path(filename).parent_path()); -	} -  	AbstractNode::resetIndexCounter();  	root_node = root_module->evaluate(&root_ctx, &root_inst);  	tree.setRoot(root_node); +	if (fs::path(outfilename).has_parent_path()) { +		fs::current_path(fs::path(outfilename).parent_path()); +	} +  	string readbackstr = dumptree(tree, *root_node);  	if (dumpstdstr != readbackstr) {  		fprintf(stderr, "Error: Readback is different from original dump:\n"); diff --git a/tests/regression/cgalpngtest/localfiles-test-expected.png b/tests/regression/cgalpngtest/localfiles-test-expected.pngBinary files differ new file mode 100644 index 0000000..3ad3d96 --- /dev/null +++ b/tests/regression/cgalpngtest/localfiles-test-expected.png diff --git a/tests/regression/dumptest/localfiles-test-expected.txt b/tests/regression/dumptest/localfiles-test-expected.txt new file mode 100644 index 0000000..acdf7e7 --- /dev/null +++ b/tests/regression/dumptest/localfiles-test-expected.txt @@ -0,0 +1,17 @@ +	group() { +		linear_extrude(height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2) { +			import(file = "localfiles_dir/localfile.dxf", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); +		} +		multmatrix([[1, 0, 0, -250], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { +			linear_extrude(file = "localfiles_dir/localfile.dxf", layer = "", origin = [0, 0], scale = 1, height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2); +		} +		multmatrix([[1, 0, 0, 0], [0, 1, 0, 350], [0, 0, 1, 0], [0, 0, 0, 1]]) { +			rotate_extrude(file = "localfiles_dir/localfile.dxf", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); +		} +		multmatrix([[1, 0, 0, 250], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { +			multmatrix([[200, 0, 0, 0], [0, 200, 0, 0], [0, 0, 50, 0], [0, 0, 0, 1]]) { +				surface(file = "localfiles_dir/localfile.dat", center = false); +			} +		} +	} + diff --git a/tests/regression/opencsgtest/localfiles-test-expected.png b/tests/regression/opencsgtest/localfiles-test-expected.pngBinary files differ new file mode 100644 index 0000000..7bc7909 --- /dev/null +++ b/tests/regression/opencsgtest/localfiles-test-expected.png diff --git a/tests/regression/throwntogethertest/localfiles-test-expected.png b/tests/regression/throwntogethertest/localfiles-test-expected.pngBinary files differ new file mode 100644 index 0000000..7bc7909 --- /dev/null +++ b/tests/regression/throwntogethertest/localfiles-test-expected.png | 
