From 3d5b844679871131e299fd335f998e994edae31f Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 3 Jan 2014 02:08:50 -0500 Subject: Keep cmd-line and GUI separate in terms of preferences, handle experimental tests separately, minor cleanups diff --git a/src/Preferences.cc b/src/Preferences.cc index 9eef43a..591ccf6 100644 --- a/src/Preferences.cc +++ b/src/Preferences.cc @@ -33,9 +33,9 @@ #include #include "PolySetCache.h" #include "AutoUpdater.h" +#include "feature.h" #ifdef ENABLE_CGAL #include "CGALCache.h" -#include "feature.h" #endif Preferences *Preferences::instance = NULL; @@ -204,7 +204,7 @@ void Preferences::featuresCheckBoxToggled(bool state) Feature *feature = v.value(); feature->enable(state); QSettings settings; - settings.setValue(feature->get_name().c_str(), state); + settings.setValue(QString("feature/%1").arg(QString::fromStdString(feature->get_name())), state); } /** @@ -220,37 +220,29 @@ Preferences::setupFeaturesPage() { int row = 0; for (Feature::iterator it = Feature::begin();it != Feature::end();it++) { - Feature * feature = (*it); - // setup default with the current value coming from commandline - this->defaultmap[feature->get_name().c_str()] = false; + Feature *feature = *it; + QString featurekey = QString("feature/%1").arg(QString::fromStdString(feature->get_name())); + this->defaultmap[featurekey] = false; + // spacer item between the features, just for some optical separation gridLayoutExperimentalFeatures->addItem(new QSpacerItem(1, 8, QSizePolicy::Expanding, QSizePolicy::Fixed), row, 1, 1, 1, Qt::AlignCenter); row++; - std::string text(feature->get_name()); - QCheckBox *cb = new QCheckBox(text.c_str(), pageFeatures); + QCheckBox *cb = new QCheckBox(QString::fromStdString(feature->get_name()), pageFeatures); QFont bold_font(cb->font()); bold_font.setBold(true); cb->setFont(bold_font); - if (feature->is_enabled()) { - // if enabled from command line, that has priority - cb->setChecked(true); - cb->setEnabled(false); - std::string text_cl = text + " (enabled on commandline)"; - cb->setText(text_cl.c_str()); - } else { - // synchronize Qt settings with the feature settings - bool value = getValue(feature->get_name().c_str()).toBool(); - feature->enable(value); - cb->setChecked(value); - } + // synchronize Qt settings with the feature settings + bool value = getValue(featurekey).toBool(); + feature->enable(value); + cb->setChecked(value); cb->setProperty(featurePropertyName, QVariant::fromValue(feature)); connect(cb, SIGNAL(toggled(bool)), this, SLOT(featuresCheckBoxToggled(bool))); gridLayoutExperimentalFeatures->addWidget(cb, row, 0, 1, 2, Qt::AlignLeading); row++; - QLabel *l = new QLabel(feature->get_description().c_str(), pageFeatures); + QLabel *l = new QLabel(QString::fromStdString(feature->get_description()), pageFeatures); l->setTextFormat(Qt::RichText); gridLayoutExperimentalFeatures->addWidget(l, row, 1, 1, 1, Qt::AlignLeading); row++; diff --git a/src/Preferences.h b/src/Preferences.h index 6310622..ef8835a 100644 --- a/src/Preferences.h +++ b/src/Preferences.h @@ -21,7 +21,7 @@ public: public slots: void actionTriggered(class QAction *); - void featuresCheckBoxToggled(bool); + void featuresCheckBoxToggled(bool); void on_colorSchemeChooser_itemSelectionChanged(); void on_fontChooser_activated(const QString &); void on_fontSize_editTextChanged(const QString &); @@ -45,15 +45,15 @@ private: void keyPressEvent(QKeyEvent *e); void updateGUI(); void removeDefaultSettings(); - void setupFeaturesPage(); - void addPrefPage(QActionGroup *group, QAction *action, QWidget *widget); + void setupFeaturesPage(); + void addPrefPage(QActionGroup *group, QAction *action, QWidget *widget); QSettings::SettingsMap defaultmap; QHash > colorschemes; - QHash prefPages; + QHash prefPages; static Preferences *instance; - static const char *featurePropertyName; + static const char *featurePropertyName; }; #endif diff --git a/src/feature.cc b/src/feature.cc index 7f36547..80d7887 100644 --- a/src/feature.cc +++ b/src/feature.cc @@ -18,11 +18,12 @@ Feature::list_t Feature::feature_list; * argument to enable the option and for saving the option value in GUI * context. */ -const Feature Feature::ExperimentalConcatFunction("experimental/concat-function", "Enable the concat() function."); +const Feature Feature::ExperimentalConcatFunction("concat", "Enable the concat() function."); -Feature::Feature(const std::string name, const std::string description) : enabled_cmdline(false), enabled_options(false), name(name), description(description) +Feature::Feature(const std::string &name, const std::string &description) + : enabled(false), name(name), description(description) { - feature_map[name] = this; + feature_map[name] = this; feature_list.push_back(this); } @@ -30,57 +31,36 @@ Feature::~Feature() { } -const std::string& Feature::get_name() const +const std::string &Feature::get_name() const { - return name; + return name; } -const std::string& Feature::get_description() const +const std::string &Feature::get_description() const { - return description; + return description; } -void Feature::set_enable_cmdline() -{ - enabled_cmdline = true; -} - -void Feature::set_enable_options(bool status) -{ - enabled_options = status; -} - bool Feature::is_enabled() const { - if (enabled_cmdline) { - return true; - } - return enabled_options; + return enabled; } void Feature::enable(bool status) { - set_enable_options(status); + enabled = status; } -void Feature::enable_feature(std::string feature_name) +void Feature::enable_feature(const std::string &feature_name, bool status) { map_t::iterator it = feature_map.find(feature_name); if (it != feature_map.end()) { - (*it).second->set_enable_cmdline(); + it->second->enable(status); } else { PRINTB("WARNING: Ignoring request to enable unknown feature '%s'.", feature_name); } } -void Feature::enable_feature(std::string feature_name, bool status) -{ - map_t::iterator it = feature_map.find(feature_name); - if (it != feature_map.end()) { - (*it).second->set_enable_options(status); - } -} - Feature::iterator Feature::begin() { return feature_list.begin(); @@ -94,6 +74,6 @@ Feature::iterator Feature::end() void Feature::dump_features() { for (map_t::iterator it = feature_map.begin(); it != feature_map.end(); it++) { - std::cout << "Feature('" << (*it).first << "') = " << ((*it).second->is_enabled() ? "enabled" : "disabled") << std::endl; + std::cout << "Feature('" << it->first << "') = " << (it->second->is_enabled() ? "enabled" : "disabled") << std::endl; } } diff --git a/src/feature.h b/src/feature.h index 77e283c..20b4f16 100644 --- a/src/feature.h +++ b/src/feature.h @@ -7,50 +7,38 @@ #include #include -class Feature { +class Feature +{ public: - typedef std::vector list_t; - typedef list_t::iterator iterator; + typedef std::vector list_t; + typedef list_t::iterator iterator; -private: - /** - * Set to true in case the matching feature was given as commandline - * argument. - */ - bool enabled_cmdline; - /** - * Set from the GUI options. This will not be set in case the GUI is - * not started at all. - */ - bool enabled_options; - - const std::string name; - const std::string description; + static const Feature ExperimentalConcatFunction; - typedef std::map map_t; - static map_t feature_map; - static list_t feature_list; + const std::string& get_name() const; + const std::string& get_description() const; - Feature(std::string name, std::string description); - virtual ~Feature(); - virtual void set_enable_cmdline(); - virtual void set_enable_options(bool status); + bool is_enabled() const; + void enable(bool status); -public: - static const Feature ExperimentalConcatFunction; + static iterator begin(); + static iterator end(); - const std::string& get_name() const; - const std::string& get_description() const; - - bool is_enabled() const; - void enable(bool status); + static void dump_features(); + static void enable_feature(const std::string &feature_name, bool status = true); - static iterator begin(); - static iterator end(); +private: + bool enabled; + + const std::string name; + const std::string description; + + typedef std::map map_t; + static map_t feature_map; + static list_t feature_list; - static void dump_features(); - static void enable_feature(std::string feature_name); - static void enable_feature(std::string feature_name, bool status); + Feature(const std::string &name, const std::string &description); + virtual ~Feature(); }; #endif diff --git a/src/openscad.cc b/src/openscad.cc index 574e87b..16a6e89 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -112,6 +112,7 @@ static void help(const char *progname) "%2% --camera=eyex,y,z,centerx,y,z ] \\\n" "%2%[ --imgsize=width,height ] [ --projection=(o)rtho|(p)ersp] \\\n" "%2%[ --render | --preview[=throwntogether] ] \\\n" + "%2%[ --enable= \\\n" "%2%filename\n", progname % (const char *)tabstr); exit(1); @@ -589,7 +590,7 @@ int main(int argc, char **argv) ("d,d", po::value(), "deps-file") ("m,m", po::value(), "makefile") ("D,D", po::value >(), "var=val") - ("enable-feature", po::value >(), "enable experimental features"); + ("enable", po::value >(), "enable experimental features"); po::options_description hidden("Hidden options"); hidden.add_options() @@ -653,8 +654,8 @@ int main(int argc, char **argv) commandline_commands += ";\n"; } } - if (vm.count("enable-feature")) { - BOOST_FOREACH(const string &feature, vm["enable-feature"].as >()) { + if (vm.count("enable")) { + BOOST_FOREACH(const string &feature, vm["enable"].as >()) { Feature::enable_feature(feature); } } diff --git a/testdata/scad/experimental/concat-tests.scad b/testdata/scad/experimental/concat-tests.scad new file mode 100644 index 0000000..0bcb903 --- /dev/null +++ b/testdata/scad/experimental/concat-tests.scad @@ -0,0 +1,53 @@ +u = undef; + +echo("--- empty"); +echo(concat()); +echo(concat([])); +echo(concat([], [])); +echo(concat([], [], [])); + +echo("--- single elements"); +echo(concat(u)); +echo(concat(true)); +echo(concat(3)); +echo(concat("abc")); +echo(concat([0:1:10])); + +echo("--- single vectors"); +echo(concat([1, 2, 3])); +echo(concat([[1, 2, 3]])); +echo(concat([[[1, 2, 3]]])); +echo(concat([[[1, 2, [3, 4], 5]]])); + +echo("--- multiple elements"); +echo(concat(3, 3)); +echo(concat(1, 2, 3)); +echo(concat(1, 2, 3, 4, 5)); +echo(concat(1, "text", false, [1:0.5:3])); + +echo("--- vector / element"); +echo(concat([3, 4], u)); +echo(concat([3, 4, 5], 6)); +echo(concat([3, 4, 5, 6], true)); +echo(concat([3, 4, "5", 6], "test")); +echo(concat([3, 4, true, 6], [4:1:3])); + +echo("--- element / vector"); +echo(concat(3, [])); +echo(concat(3, [3, 4])); +echo(concat(true, [3, [4]])); +echo(concat("9", [1, 2, 3])); +echo(concat([6:2:9], [3, [4]])); + +echo("--- vector / vector"); +echo(concat([], [3, 4])); +echo(concat([[]], [3, 4])); +echo(concat([[2, 4]], [3, 4])); +echo(concat([5, 6], ["d", [3, 4]])); +echo(concat([[1, 0, 0], [2, 0, 0]], [3, 0, 0])); +echo(concat([[1, 0, 0], [2, 0, 0]], [[3, 0, 0]])); +echo(concat([[1, 0, 0], [2, 0, 0], [3, 0, 0]], [[4, 4, 4], [5, 5, 5]])); + +echo("--- recursive function"); +function r(i) = i > 0 ? concat(r(i - 1), [[i, i * i]]) : []; +echo(r(10)); diff --git a/testdata/scad/functions/concat-tests.scad b/testdata/scad/functions/concat-tests.scad deleted file mode 100644 index 0bcb903..0000000 --- a/testdata/scad/functions/concat-tests.scad +++ /dev/null @@ -1,53 +0,0 @@ -u = undef; - -echo("--- empty"); -echo(concat()); -echo(concat([])); -echo(concat([], [])); -echo(concat([], [], [])); - -echo("--- single elements"); -echo(concat(u)); -echo(concat(true)); -echo(concat(3)); -echo(concat("abc")); -echo(concat([0:1:10])); - -echo("--- single vectors"); -echo(concat([1, 2, 3])); -echo(concat([[1, 2, 3]])); -echo(concat([[[1, 2, 3]]])); -echo(concat([[[1, 2, [3, 4], 5]]])); - -echo("--- multiple elements"); -echo(concat(3, 3)); -echo(concat(1, 2, 3)); -echo(concat(1, 2, 3, 4, 5)); -echo(concat(1, "text", false, [1:0.5:3])); - -echo("--- vector / element"); -echo(concat([3, 4], u)); -echo(concat([3, 4, 5], 6)); -echo(concat([3, 4, 5, 6], true)); -echo(concat([3, 4, "5", 6], "test")); -echo(concat([3, 4, true, 6], [4:1:3])); - -echo("--- element / vector"); -echo(concat(3, [])); -echo(concat(3, [3, 4])); -echo(concat(true, [3, [4]])); -echo(concat("9", [1, 2, 3])); -echo(concat([6:2:9], [3, [4]])); - -echo("--- vector / vector"); -echo(concat([], [3, 4])); -echo(concat([[]], [3, 4])); -echo(concat([[2, 4]], [3, 4])); -echo(concat([5, 6], ["d", [3, 4]])); -echo(concat([[1, 0, 0], [2, 0, 0]], [3, 0, 0])); -echo(concat([[1, 0, 0], [2, 0, 0]], [[3, 0, 0]])); -echo(concat([[1, 0, 0], [2, 0, 0], [3, 0, 0]], [[4, 4, 4], [5, 5, 5]])); - -echo("--- recursive function"); -function r(i) = i > 0 ? concat(r(i - 1), [[i, i * i]]) : []; -echo(r(10)); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 70e56c6..d2d9e68 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -516,6 +516,7 @@ set(CORE_SOURCES ../src/context.cc ../src/modcontext.cc ../src/evalcontext.cc + ../src/feature.cc ../src/csgterm.cc ../src/csgtermnormalizer.cc ../src/polyset.cc @@ -974,6 +975,11 @@ add_cmdline_test(throwntogethertest EXE ${OPENSCAD_BINPATH} ARGS --preview=throw # with anything. It's self-contained and returns != 0 on error add_cmdline_test(cgalstlsanitytest EXE ${CMAKE_SOURCE_DIR}/cgalstlsanitytest SUFFIX txt ARGS ${OPENSCAD_BINPATH} FILES ${CGALSTLSANITYTEST_FILES}) +# Add experimental tests + +add_cmdline_test(echotest EXE ${OPENSCAD_BINPATH} ARGS --enable=concat -o SUFFIX echo FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/experimental/concat-tests.scad) + + # Tests using the actual OpenSCAD binary # non-ASCII filenames -- cgit v0.10.1