2010-03-28 20:13:43 +04:00
|
|
|
/*
|
2011-11-05 22:01:19 +04:00
|
|
|
* OpenSCAD (www.openscad.org)
|
|
|
|
* Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and
|
|
|
|
* Marius Kintel <marius@kintel.net>
|
2010-03-28 20:13:43 +04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-11-05 22:38:03 +04:00
|
|
|
#include "tests-common.h"
|
2010-04-12 04:16:36 +04:00
|
|
|
#include "CSGTextRenderer.h"
|
2010-04-12 08:57:02 +04:00
|
|
|
#include "CSGTextCache.h"
|
2010-03-28 20:13:43 +04:00
|
|
|
#include "openscad.h"
|
2011-12-25 01:02:37 +04:00
|
|
|
#include "parsersettings.h"
|
2010-03-28 20:13:43 +04:00
|
|
|
#include "node.h"
|
|
|
|
#include "module.h"
|
2013-04-09 08:28:16 +04:00
|
|
|
#include "modcontext.h"
|
2010-03-28 20:13:43 +04:00
|
|
|
#include "value.h"
|
|
|
|
#include "export.h"
|
|
|
|
#include "builtin.h"
|
2010-04-12 04:16:36 +04:00
|
|
|
#include "Tree.h"
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2011-10-11 06:46:27 +04:00
|
|
|
#ifndef _MSC_VER
|
2010-03-28 20:13:43 +04:00
|
|
|
#include <getopt.h>
|
2011-10-11 06:46:27 +04:00
|
|
|
#endif
|
2010-04-12 04:16:36 +04:00
|
|
|
#include <assert.h>
|
2010-03-28 20:13:43 +04:00
|
|
|
#include <iostream>
|
2011-09-04 02:03:16 +04:00
|
|
|
#include <sstream>
|
2011-10-16 07:59:54 +04:00
|
|
|
#include <fstream>
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2011-12-25 03:22:03 +04:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
namespace fs = boost::filesystem;
|
2012-01-14 08:02:15 +04:00
|
|
|
#include "boosty.h"
|
2011-12-25 03:22:03 +04:00
|
|
|
|
2011-09-04 02:03:16 +04:00
|
|
|
std::string commandline_commands;
|
2011-12-25 03:22:03 +04:00
|
|
|
std::string currentdir;
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2010-04-12 08:57:02 +04:00
|
|
|
void csgTree(CSGTextCache &cache, const AbstractNode &root)
|
2010-04-12 04:16:36 +04:00
|
|
|
{
|
2010-04-12 08:57:02 +04:00
|
|
|
CSGTextRenderer renderer(cache);
|
|
|
|
Traverser render(renderer, root, Traverser::PRE_AND_POSTFIX);
|
2010-04-12 04:16:36 +04:00
|
|
|
render.execute();
|
|
|
|
}
|
|
|
|
|
2010-03-28 20:13:43 +04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2011-10-16 07:59:54 +04:00
|
|
|
if (argc != 3) {
|
|
|
|
fprintf(stderr, "Usage: %s <file.scad> <output.txt>\n", argv[0]);
|
2010-03-28 20:13:43 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *filename = argv[1];
|
2011-10-16 07:59:54 +04:00
|
|
|
const char *outfilename = argv[2];
|
2010-03-28 20:13:43 +04:00
|
|
|
|
|
|
|
int rc = 0;
|
|
|
|
|
2011-11-06 21:37:12 +04:00
|
|
|
Builtins::instance()->initialize();
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2011-12-25 03:22:03 +04:00
|
|
|
fs::path original_path = fs::current_path();
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2012-01-14 08:02:15 +04:00
|
|
|
currentdir = boosty::stringy( fs::current_path() );
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2013-10-08 02:47:08 +04:00
|
|
|
parser_init(boosty::stringy(fs::path(argv[0]).branch_path()), false);
|
2013-03-12 09:14:58 +04:00
|
|
|
add_librarydir(boosty::stringy(fs::path(argv[0]).branch_path() / "../libraries"));
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2013-04-24 17:17:25 +04:00
|
|
|
ModuleContext top_ctx;
|
|
|
|
top_ctx.registerBuiltin();
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2013-04-24 17:17:25 +04:00
|
|
|
FileModule *root_module;
|
2013-04-09 08:28:16 +04:00
|
|
|
ModuleInstantiation root_inst("group");
|
2010-03-28 20:13:43 +04:00
|
|
|
AbstractNode *root_node;
|
|
|
|
|
2011-11-05 22:38:03 +04:00
|
|
|
root_module = parsefile(filename);
|
|
|
|
if (!root_module) {
|
2010-03-28 20:13:43 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-03-20 15:05:18 +04:00
|
|
|
if (fs::path(filename).has_parent_path()) {
|
|
|
|
fs::current_path(fs::path(filename).parent_path());
|
|
|
|
}
|
2010-03-28 20:13:43 +04:00
|
|
|
|
|
|
|
AbstractNode::resetIndexCounter();
|
2013-04-24 17:17:25 +04:00
|
|
|
root_node = root_module->instantiate(&top_ctx, &root_inst);
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2010-04-12 04:16:36 +04:00
|
|
|
Tree tree;
|
|
|
|
tree.setRoot(root_node);
|
2010-04-12 08:57:02 +04:00
|
|
|
CSGTextCache csgcache(tree);
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2010-04-12 08:57:02 +04:00
|
|
|
csgTree(csgcache, *root_node);
|
2010-07-07 03:46:24 +04:00
|
|
|
// std::cout << tree.getString(*root_node) << "\n";
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2011-12-25 03:22:03 +04:00
|
|
|
current_path(original_path);
|
2011-10-16 07:59:54 +04:00
|
|
|
std::ofstream outfile;
|
|
|
|
outfile.open(outfilename);
|
|
|
|
outfile << csgcache[*root_node] << "\n";
|
|
|
|
outfile.close();
|
2010-03-28 20:13:43 +04:00
|
|
|
|
2011-11-27 08:20:18 +04:00
|
|
|
delete root_node;
|
|
|
|
delete root_module;
|
|
|
|
|
2011-11-06 21:37:12 +04:00
|
|
|
Builtins::instance(true);
|
2010-03-28 20:13:43 +04:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|