summaryrefslogtreecommitdiff
path: root/tests/csgtestcore.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/csgtestcore.cc')
-rw-r--r--tests/csgtestcore.cc97
1 files changed, 87 insertions, 10 deletions
diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc
index 034084c..a3d5097 100644
--- a/tests/csgtestcore.cc
+++ b/tests/csgtestcore.cc
@@ -25,8 +25,15 @@
#include <QDir>
#include <QSet>
#include <QTimer>
+
#include <sstream>
+#include <vector>
+
+#include <boost/program_options.hpp>
+namespace po = boost::program_options;
+using std::string;
+using std::vector;
using std::cerr;
using std::cout;
@@ -41,9 +48,9 @@ public:
CsgInfo();
CSGTerm *root_norm_term; // Normalized CSG products
class CSGChain *root_chain;
- std::vector<CSGTerm*> highlight_terms;
+ vector<CSGTerm*> highlight_terms;
CSGChain *highlights_chain;
- std::vector<CSGTerm*> background_terms;
+ vector<CSGTerm*> background_terms;
CSGChain *background_chain;
OffscreenView *glview;
};
@@ -51,9 +58,9 @@ public:
CsgInfo::CsgInfo() {
root_norm_term = NULL;
root_chain = NULL;
- highlight_terms = std::vector<CSGTerm*>();
+ highlight_terms = vector<CSGTerm*>();
highlights_chain = NULL;
- background_terms = std::vector<CSGTerm*>();
+ background_terms = vector<CSGTerm*>();
background_chain = NULL;
glview = NULL;
}
@@ -67,16 +74,81 @@ AbstractNode *find_root_tag(AbstractNode *n)
return NULL;
}
+string info_dump(OffscreenView *glview)
+{
+ assert(glview);
+
+#ifdef __GNUG__
+#define compiler_info "GCC " << __VERSION__
+#elif defined(_MSC_VER)
+#define compiler_info "MSVC " << _MSC_FULL_VER
+#else
+#define compiler_info "unknown compiler"
+#endif
+
+ std::stringstream out;
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+ out << "\nOpenSCAD Version: " << TOSTRING(OPENSCAD_VERSION)
+ << "\nCompiled by: " << compiler_info
+ << "\nCompile date: " << __DATE__
+ << "\nBoost version: " << BOOST_LIB_VERSION
+ << "\nEigen version: " << EIGEN_WORLD_VERSION << "."
+ << EIGEN_MAJOR_VERSION << "." << EIGEN_MINOR_VERSION
+ // << "\nCGAL version: " << CGAL_VERSION ???
+ // << "\nOpenCSG" << ???
+ << "\n" << glview->getInfo()
+ << "\n";
+
+ return out.str();
+}
+
+po::variables_map parse_options(int argc, char *argv[])
+{
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("help,h", "help message")//;
+ ("info,i", "information on GLEW, OpenGL, OpenSCAD, and OS")//;
+
+// po::options_description hidden("Hidden options");
+// hidden.add_options()
+ ("input-file", po::value< vector<string> >(), "input file")
+ ("output-file", po::value< vector<string> >(), "ouput file");
+
+ po::positional_options_description p;
+ p.add("input-file", 1).add("output-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);
+
+ return vm;
+}
+
int csgtestcore(int argc, char *argv[], test_type_e test_type)
{
- if (argc != 3) {
- fprintf(stderr, "Usage: %s <file.scad> <output.png>\n", argv[0]);
+ bool sysinfo_dump = false;
+ const char *filename, *outfilename = NULL;
+ po::variables_map vm;
+ try {
+ vm = parse_options(argc, argv);
+ } catch ( po::error e ) {
+ cerr << "error parsing options\n";
+ }
+ if (vm.count("info")) sysinfo_dump = true;
+ if (vm.count("input-file"))
+ filename = vm["input-file"].as< vector<string> >().begin()->c_str();
+ if (vm.count("output-file"))
+ outfilename = vm["output-file"].as< vector<string> >().begin()->c_str();
+
+ if ((!filename || !outfilename) && !sysinfo_dump) {
+ cerr << "Usage: " << argv[0] << " <file.scad> <output.png>\n";
exit(1);
}
- const char *filename = argv[1];
- const char *outfilename = argv[2];
-
Builtins::instance()->initialize();
QApplication app(argc, argv, false);
@@ -110,7 +182,11 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type)
AbstractModule *root_module;
ModuleInstantiation root_inst;
- root_module = parsefile(filename);
+ if (sysinfo_dump)
+ root_module = parse("sphere();","",false);
+ else
+ root_module = parsefile(filename);
+
if (!root_module) {
exit(1);
}
@@ -194,6 +270,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type)
fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i. Exiting.\n", error);
exit(1);
}
+ if (sysinfo_dump) cout << info_dump(csgInfo.glview);
BoundingBox bbox = csgInfo.root_chain->getBoundingBox();
Vector3d center = (bbox.min() + bbox.max()) / 2;
contact: Jan Huwald // Impressum