mirror of https://github.com/vitalif/openscad
Keep cmd-line and GUI separate in terms of preferences, handle experimental tests separately, minor cleanups
parent
9caa2dcfa5
commit
3d5b844679
|
@ -33,9 +33,9 @@
|
|||
#include <QStatusBar>
|
||||
#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 *>();
|
||||
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 *>(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++;
|
||||
|
|
|
@ -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<QString, std::map<RenderSettings::RenderColor, Color4f> > colorschemes;
|
||||
QHash<const QAction *, QWidget *> prefPages;
|
||||
QHash<const QAction *, QWidget *> prefPages;
|
||||
|
||||
static Preferences *instance;
|
||||
static const char *featurePropertyName;
|
||||
static const char *featurePropertyName;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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 <code>concat()</code> function.");
|
||||
const Feature Feature::ExperimentalConcatFunction("concat", "Enable the <code>concat()</code> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,50 +7,38 @@
|
|||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class Feature {
|
||||
class Feature
|
||||
{
|
||||
public:
|
||||
typedef std::vector<Feature *> list_t;
|
||||
typedef list_t::iterator iterator;
|
||||
typedef std::vector<Feature *> list_t;
|
||||
typedef list_t::iterator iterator;
|
||||
|
||||
static const Feature ExperimentalConcatFunction;
|
||||
|
||||
const std::string& get_name() const;
|
||||
const std::string& get_description() const;
|
||||
|
||||
bool is_enabled() const;
|
||||
void enable(bool status);
|
||||
|
||||
static iterator begin();
|
||||
static iterator end();
|
||||
|
||||
static void dump_features();
|
||||
static void enable_feature(const std::string &feature_name, bool status = true);
|
||||
|
||||
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;
|
||||
bool enabled;
|
||||
|
||||
const std::string name;
|
||||
const std::string description;
|
||||
|
||||
const std::string name;
|
||||
const std::string description;
|
||||
typedef std::map<std::string, Feature *> map_t;
|
||||
static map_t feature_map;
|
||||
static list_t feature_list;
|
||||
|
||||
typedef std::map<std::string, Feature *> map_t;
|
||||
static map_t feature_map;
|
||||
static list_t feature_list;
|
||||
|
||||
Feature(std::string name, std::string description);
|
||||
virtual ~Feature();
|
||||
virtual void set_enable_cmdline();
|
||||
virtual void set_enable_options(bool status);
|
||||
|
||||
public:
|
||||
static const Feature ExperimentalConcatFunction;
|
||||
|
||||
const std::string& get_name() const;
|
||||
const std::string& get_description() const;
|
||||
|
||||
bool is_enabled() const;
|
||||
void enable(bool status);
|
||||
|
||||
static iterator begin();
|
||||
static iterator end();
|
||||
|
||||
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
|
||||
|
|
|
@ -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=<feature> \\\n"
|
||||
"%2%filename\n",
|
||||
progname % (const char *)tabstr);
|
||||
exit(1);
|
||||
|
@ -589,7 +590,7 @@ int main(int argc, char **argv)
|
|||
("d,d", po::value<string>(), "deps-file")
|
||||
("m,m", po::value<string>(), "makefile")
|
||||
("D,D", po::value<vector<string> >(), "var=val")
|
||||
("enable-feature", po::value<vector<string> >(), "enable experimental features");
|
||||
("enable", po::value<vector<string> >(), "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<vector<string> >()) {
|
||||
if (vm.count("enable")) {
|
||||
BOOST_FOREACH(const string &feature, vm["enable"].as<vector<string> >()) {
|
||||
Feature::enable_feature(feature);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue