2010-07-15 04:48:00 +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-07-15 04:48:00 +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"
|
2011-09-09 07:53:05 +04:00
|
|
|
#include "PolySetEvaluator.h"
|
2011-08-04 07:11:48 +04:00
|
|
|
#include "CSGTermEvaluator.h"
|
2010-07-15 04:48:00 +04:00
|
|
|
#include "openscad.h"
|
2011-12-25 01:02:37 +04:00
|
|
|
#include "parsersettings.h"
|
2010-07-15 04:48:00 +04:00
|
|
|
#include "node.h"
|
|
|
|
#include "module.h"
|
|
|
|
#include "context.h"
|
|
|
|
#include "value.h"
|
|
|
|
#include "export.h"
|
|
|
|
#include "builtin.h"
|
|
|
|
#include "Tree.h"
|
2010-08-28 23:35:48 +04:00
|
|
|
#include "csgterm.h"
|
2010-07-15 04:48:00 +04:00
|
|
|
|
|
|
|
#include <QApplication>
|
2011-10-11 06:46:27 +04:00
|
|
|
#ifndef _MSC_VER
|
2010-07-15 04:48:00 +04:00
|
|
|
#include <getopt.h>
|
2011-10-11 06:46:27 +04:00
|
|
|
#endif
|
2010-07-15 04:48:00 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <iostream>
|
2011-09-04 02:03:16 +04:00
|
|
|
#include <sstream>
|
2011-10-16 07:59:54 +04:00
|
|
|
#include <fstream>
|
2010-07-15 04:48:00 +04:00
|
|
|
|
2011-12-25 03:22:03 +04:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
namespace fs = boost::filesystem;
|
2010-08-28 23:35:48 +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-07-15 04:48:00 +04:00
|
|
|
QString examplesdir;
|
|
|
|
|
2011-12-25 03:22:03 +04:00
|
|
|
using std::cout;
|
|
|
|
|
2010-07-15 04:48:00 +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-07-15 04:48:00 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *filename = argv[1];
|
2011-10-16 07:59:54 +04:00
|
|
|
const char *outfilename = argv[2];
|
2010-07-15 04:48:00 +04:00
|
|
|
|
|
|
|
int rc = 0;
|
|
|
|
|
2011-11-06 21:37:12 +04:00
|
|
|
Builtins::instance()->initialize();
|
2010-07-15 04:48:00 +04:00
|
|
|
|
|
|
|
QApplication app(argc, argv, false);
|
2011-12-25 03:22:03 +04:00
|
|
|
fs::path original_path = fs::current_path();
|
2010-07-15 04:48:00 +04:00
|
|
|
|
2011-12-25 03:22:03 +04:00
|
|
|
currentdir = fs::current_path().generic_string();
|
2010-07-15 04:48:00 +04:00
|
|
|
|
2011-12-25 18:09:52 +04:00
|
|
|
parser_init(QApplication::instance()->applicationDirPath().toStdString());
|
2010-07-15 04:48:00 +04:00
|
|
|
|
|
|
|
Context root_ctx;
|
2011-11-05 20:05:30 +04:00
|
|
|
register_builtin(root_ctx);
|
2010-07-15 04:48:00 +04:00
|
|
|
|
|
|
|
AbstractModule *root_module;
|
|
|
|
ModuleInstantiation root_inst;
|
2011-08-28 02:11:47 +04:00
|
|
|
const AbstractNode *root_node;
|
2010-07-15 04:48:00 +04:00
|
|
|
|
2011-11-05 22:38:03 +04:00
|
|
|
root_module = parsefile(filename);
|
|
|
|
if (!root_module) {
|
2010-07-15 04:48:00 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-12-25 03:22:03 +04:00
|
|
|
fs::current_path(fs::path(filename).parent_path());
|
2010-07-15 04:48:00 +04:00
|
|
|
|
|
|
|
AbstractNode::resetIndexCounter();
|
|
|
|
root_node = root_module->evaluate(&root_ctx, &root_inst);
|
|
|
|
|
2010-11-08 06:54:41 +03:00
|
|
|
Tree tree(root_node);
|
2010-07-15 04:48:00 +04:00
|
|
|
|
2010-08-28 23:35:48 +04:00
|
|
|
// cout << tree.getString(*root_node) << "\n";
|
2010-07-15 04:48:00 +04:00
|
|
|
|
2011-12-06 04:16:54 +04:00
|
|
|
std::vector<shared_ptr<CSGTerm> > highlights;
|
|
|
|
std::vector<shared_ptr<CSGTerm> > background;
|
2011-09-09 07:53:05 +04:00
|
|
|
PolySetEvaluator psevaluator(tree);
|
|
|
|
CSGTermEvaluator evaluator(tree, &psevaluator);
|
2011-12-06 04:16:54 +04:00
|
|
|
shared_ptr<CSGTerm> root_term = evaluator.evaluateCSGTerm(*root_node, highlights, background);
|
2010-08-28 23:35:48 +04:00
|
|
|
|
2011-08-04 07:11:48 +04:00
|
|
|
// cout << "Stored terms: " << evaluator.stored_term.size() << "\n";
|
|
|
|
// for (map<int, class CSGTerm*>::iterator iter = evaluator.stored_term.begin();
|
|
|
|
// iter != evaluator.stored_term.end();
|
2010-08-28 23:35:48 +04:00
|
|
|
// iter++) {
|
|
|
|
// cout << iter->first << ":" << (iter->second ? iter->second->label : "NULL") << "\n";
|
|
|
|
// }
|
|
|
|
|
2011-08-04 07:11:48 +04:00
|
|
|
// if (evaluator.background) cout << "Background terms: " << evaluator.background->size() << "\n";
|
|
|
|
// if (evaluator.highlights) cout << "Highlights terms: " << evaluator.highlights->size() << "\n";
|
2010-08-28 23:35:48 +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);
|
2010-08-28 23:35:48 +04:00
|
|
|
if (root_term) {
|
2011-10-16 07:59:54 +04:00
|
|
|
outfile << root_term->dump() << "\n";
|
2010-08-28 23:35:48 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-10-16 07:59:54 +04:00
|
|
|
outfile << "No top-level CSG object\n";
|
2010-08-28 23:35:48 +04:00
|
|
|
}
|
2011-10-16 07:59:54 +04:00
|
|
|
outfile.close();
|
2010-07-15 04:48:00 +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-07-15 04:48:00 +04:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|