Looks like the reworked C++ preferences start to work again.

This commit is contained in:
bubnikv 2017-11-02 16:21:34 +01:00
parent 95c284c764
commit e8b6d92d4d
26 changed files with 469 additions and 512 deletions

View file

@ -207,15 +207,15 @@ public:
void resize(size_t n, const ConfigOption *opt_default = nullptr) override
{
assert(opt_default == nullptr || opt_default->is_vector());
assert(opt_default == nullptr || dynamic_cast<ConfigOptionVector<T>>(opt_default));
// assert(opt_default == nullptr || dynamic_cast<ConfigOptionVector<T>>(opt_default));
assert(! this->values.empty() || opt_default != nullptr);
if (n == 0)
this->values.clear();
else if (n < this->values.size())
this->values.erase(this->values.begin() + n, this->values.end());
else if (n > this->values.size())
else if (n > this->values.size()) {
if (this->values.empty()) {
if (opt_default == nullptr) {
if (opt_default == nullptr)
throw std::runtime_error("ConfigOptionVector::resize(): No default value provided.");
if (opt_default->type() != this->type())
throw std::runtime_error("ConfigOptionVector::resize(): Extending with an incompatible type.");

View file

@ -25,7 +25,6 @@ std::string config_path(const std::string &file_name);
// The suffix ".ini" will be added if it is missing in the name.
std::string config_path(const std::string &section, const std::string &name);
extern std::locale locale_utf8;
extern std::string encode_path(const char *src);
extern std::string decode_path(const char *src);
extern std::string normalize_utf8_nfc(const char *src);

View file

@ -103,14 +103,14 @@ const std::string& data_dir()
std::string config_path(const std::string &file_name)
{
auto file = boost::filesystem::canonical(boost::filesystem::path(g_data_dir) / file_name).make_preferred();
auto file = (boost::filesystem::path(g_data_dir) / file_name).make_preferred();
return file.string();
}
std::string config_path(const std::string &section, const std::string &name)
{
auto file_name = boost::algorithm::iends_with(name, ".ini") ? name : name + ".ini";
auto file = boost::filesystem::canonical(boost::filesystem::path(g_data_dir) / file_name).make_preferred();
auto file = (boost::filesystem::path(g_data_dir) / section / file_name).make_preferred();
return file.string();
}
@ -228,10 +228,9 @@ std::string decode_path(const char *src)
#endif /* WIN32 */
}
std::locale locale_utf8(boost::locale::generator().generate(""));
std::string normalize_utf8_nfc(const char *src)
{
static std::locale locale_utf8(boost::locale::generator().generate(""));
return boost::locale::normalize(src, boost::locale::norm_nfc, locale_utf8);
}

View file

@ -27,9 +27,7 @@ void AppConfig::reset()
// Override missing or keys with their defaults.
void AppConfig::set_defaults()
{
// 2) Reset to defaults.
if (get("version_check").empty())
set("version_check", "1");
// Reset the empty fields to defaults.
if (get("autocenter").empty())
set("autocenter", "1");
// Disable background processing by default as it is not stable.
@ -38,10 +36,13 @@ void AppConfig::set_defaults()
// If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden.
// By default, Prusa has the controller hidden.
if (get("no_controller").empty())
set("no_controller", "0");
set("no_controller", "1");
// If set, the "- default -" selections of print/filament/printer are suppressed, if there is a valid preset available.
if (get("no_defaults").empty())
set("no_defaults", "1");
// Version check is enabled by default in the config, but it is not implemented yet.
if (get("version_check").empty())
set("version_check", "1");
}
void AppConfig::load()
@ -114,13 +115,11 @@ std::string AppConfig::get_last_dir() const
void AppConfig::update_config_dir(const std::string &dir)
{
this->set("recent", "config_directory", dir);
this->save();
}
void AppConfig::update_skein_dir(const std::string &dir)
{
this->set("recent", "skein_directory", dir);
this->save();
}
std::string AppConfig::get_last_output_dir(const std::string &alt) const
@ -138,7 +137,6 @@ std::string AppConfig::get_last_output_dir(const std::string &alt) const
void AppConfig::update_last_output_dir(const std::string &dir)
{
this->set("", "last_output_path", dir);
this->save();
}
std::string AppConfig::config_path()

View file

@ -1,9 +1,14 @@
#include "GUI.hpp"
#include <assert.h>
#include <boost/algorithm/string/predicate.hpp>
#if __APPLE__
#import <IOKit/pwr_mgt/IOPMLib.h>
#elif _WIN32
#include <Windows.h>
#include "boost/nowide/convert.hpp"
#pragma comment(lib, "user32.lib")
#endif
@ -34,6 +39,82 @@ void enable_screensaver()
#endif
}
std::vector<std::string> scan_serial_ports()
{
std::vector<std::string> out;
#ifdef _WIN32
// 1) Open the registry key SERIALCOM.
HKEY hKey;
LONG lRes = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ, &hKey);
assert(lRes == ERROR_SUCCESS);
if (lRes == ERROR_SUCCESS) {
// 2) Get number of values of SERIALCOM key.
DWORD cValues; // number of values for key
{
TCHAR achKey[255]; // buffer for subkey name
DWORD cbName; // size of name string
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
DWORD cchClassName = MAX_PATH; // size of class string
DWORD cSubKeys=0; // number of subkeys
DWORD cbMaxSubKey; // longest subkey size
DWORD cchMaxClass; // longest class string
DWORD cchMaxValue; // longest value name
DWORD cbMaxValueData; // longest value data
DWORD cbSecurityDescriptor; // size of security descriptor
FILETIME ftLastWriteTime; // last write time
// Get the class name and the value count.
lRes = RegQueryInfoKey(
hKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime); // last write time
assert(lRes == ERROR_SUCCESS);
}
// 3) Read the SERIALCOM values.
{
DWORD dwIndex = 0;
for (int i = 0; i < cValues; ++ i, ++ dwIndex) {
wchar_t valueName[2048];
DWORD valNameLen = 2048;
DWORD dataType;
wchar_t data[2048];
DWORD dataSize = 4096;
lRes = ::RegEnumValueW(hKey, dwIndex, valueName, &valNameLen, nullptr, &dataType, (BYTE*)&data, &dataSize);
if (lRes == ERROR_SUCCESS && dataType == REG_SZ && valueName[0] != 0)
out.emplace_back(boost::nowide::narrow(data));
}
}
::RegCloseKey(hKey);
}
#else
// UNIX and OS X
boost::filesystem::recursive_directory_iterator end;
std::initializer_list<const char*> prefixes { "ttyUSB" , "ttyACM", "tty.", "cu.", "rfcomm" };
for (boost::filesystem::recursive_directory_iterator it_path(boost::filesystem::path("/dev"));
it_path != end; ++ it_path)
for (const char *prefix : prefixes)
if (boost::starts_with(it_path->string(), std::string("/dev/") + prefix)) {
out.emplace_back(path);
break;
}
#endif
out.erase(std::remove_if(out.begin(), out.end(),
[](const std::string &key){
return boost::starts_with(key, "Bluetooth") || boost::starts_with(key, "FireFly");
}),
out.end());
return out;
}
bool debugged()
{
#ifdef _WIN32

View file

@ -1,10 +1,14 @@
#ifndef slic3r_GUI_hpp_
#define slic3r_GUI_hpp_
#include <string>
#include <vector>
namespace Slic3r { namespace GUI {
void disable_screensaver();
void enable_screensaver();
std::vector<std::string> scan_serial_ports();
bool debugged();
void break_to_debugger();

View file

@ -1,3 +1,6 @@
//#undef NDEBUG
#include <cassert>
#include "Preset.hpp"
#include <fstream>
@ -16,16 +19,9 @@
#include <wx/bmpcbox.h>
#include <wx/wupdlock.h>
#include "../../libslic3r/libslic3r.h"
#include "../../libslic3r/Utils.hpp"
#if 0
#define DEBUG
#define _DEBUG
#undef NDEBUG
#endif
#include <assert.h>
namespace Slic3r {
ConfigFileType guess_config_file_type(const boost::property_tree::ptree &tree)
@ -94,6 +90,19 @@ void Preset::normalize(DynamicPrintConfig &config)
if (nozzle_diameter != nullptr)
// Loaded the Printer settings. Verify, that all extruder dependent values have enough values.
set_num_extruders(config, (unsigned int)nozzle_diameter->values.size());
if (config.option("filament_diameter") != nullptr) {
// This config contains single or multiple filament presets.
// Ensure that the filament preset vector options contain the correct number of values.
size_t n = (nozzle_diameter == nullptr) ? 1 : nozzle_diameter->values.size();
const auto &defaults = FullPrintConfig::defaults();
for (const std::string &key : Preset::filament_options()) {
auto *opt = config.option(key, false);
assert(opt != nullptr);
assert(opt->is_vector());
if (opt != nullptr && opt->is_vector())
static_cast<ConfigOptionVectorBase*>(opt)->resize(n, defaults.option(key));
}
}
}
// Load a config file, return a C++ class Slic3r::DynamicPrintConfig with $keys initialized from the config file.
@ -247,27 +256,29 @@ void PresetCollection::load_presets(const std::string &dir_path, const std::stri
}
}
std::sort(m_presets.begin() + 1, m_presets.end());
m_presets.front().is_visible = ! m_default_suppressed || m_presets.size() > 1;
this->select_preset(first_visible_idx());
}
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
// and select it, losing previous modifications.
Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select)
{
DynamicPrintConfig cfg(this->default_preset().config);
cfg.apply(config, true);
return this->load_preset(path, name, std::move(cfg));
}
Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select)
{
Preset key(m_type, name);
auto it = std::lower_bound(m_presets.begin(), m_presets.end(), key);
if (it != m_presets.end() && it->name == name) {
// The preset with the same name was found.
it->is_dirty = false;
} else {
if (it == m_presets.end() || it->name != name)
it = m_presets.emplace(it, Preset(m_type, name, false));
}
Preset &preset = *it;
preset.file = path;
preset.config = this->default_preset().config;
preset.config = std::move(config);
preset.loaded = true;
this->get_selected_preset().is_dirty = false;
preset.is_dirty = false;
if (select)
this->select_preset_by_name(name, true);
return preset;
@ -275,6 +286,8 @@ Preset& PresetCollection::load_preset(const std::string &path, const std::string
void PresetCollection::save_current_preset(const std::string &new_name)
{
// 1) Find the preset with a new_name or create a new one,
// initialize it with the edited config.
Preset key(m_type, new_name, false);
auto it = std::lower_bound(m_presets.begin(), m_presets.end(), key);
if (it != m_presets.end() && it->name == key.name) {
@ -285,37 +298,39 @@ void PresetCollection::save_current_preset(const std::string &new_name)
return;
// Overwriting an existing preset.
preset.config = std::move(m_edited_preset.config);
m_idx_selected = it - m_presets.begin();
} else {
// Creating a new preset.
m_idx_selected = m_presets.insert(it, m_edited_preset) - m_presets.begin();
Preset &preset = m_presets[m_idx_selected];
Preset &preset = *m_presets.insert(it, m_edited_preset);
std::string file_name = new_name;
if (! boost::iends_with(file_name, ".ini"))
file_name += ".ini";
preset.name = new_name;
preset.file = (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
}
m_edited_preset = m_presets[m_idx_selected];
m_presets[m_idx_selected].save();
m_presets.front().is_visible = ! m_default_suppressed || m_idx_selected > 0;
// 2) Activate the saved preset.
this->select_preset_by_name(new_name, true);
// 2) Store the active preset to disk.
this->get_selected_preset().save();
}
void PresetCollection::delete_current_preset()
{
const Preset &selected = this->get_selected_preset();
if (selected.is_default || selected.is_external)
if (selected.is_default)
return;
// Erase the preset file.
boost::nowide::remove(selected.file.c_str());
if (! selected.is_external) {
// Erase the preset file.
boost::nowide::remove(selected.file.c_str());
}
// Remove the preset from the list.
m_presets.erase(m_presets.begin() + m_idx_selected);
// Find the next visible preset.
m_presets.front().is_visible = ! m_default_suppressed || m_presets.size() > 1;
for (; m_idx_selected < m_presets.size() && ! m_presets[m_idx_selected].is_visible; ++ m_idx_selected) ;
if (m_idx_selected == m_presets.size())
m_idx_selected = this->first_visible_idx();
m_edited_preset = m_presets[m_idx_selected];
size_t new_selected_idx = m_idx_selected;
if (new_selected_idx < m_presets.size())
for (; new_selected_idx < m_presets.size() && ! m_presets[new_selected_idx].is_visible; ++ new_selected_idx) ;
if (new_selected_idx == m_presets.size())
for (--new_selected_idx; new_selected_idx > 0 && !m_presets[new_selected_idx].is_visible; --new_selected_idx);
this->select_preset(new_selected_idx);
}
bool PresetCollection::load_bitmap_default(const std::string &file_name)
@ -337,7 +352,7 @@ Preset* PresetCollection::find_preset(const std::string &name, bool first_visibl
// Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible.
size_t PresetCollection::first_visible_idx() const
{
size_t idx = 0;
size_t idx = m_default_suppressed ? 1 : 0;
for (; idx < this->m_presets.size(); ++ idx)
if (m_presets[idx].is_visible)
break;
@ -438,11 +453,13 @@ bool PresetCollection::update_dirty_ui(wxChoice *ui)
Preset& PresetCollection::select_preset(size_t idx)
{
for (Preset &preset : m_presets)
preset.is_dirty = false;
if (idx >= m_presets.size())
idx = first_visible_idx();
m_idx_selected = idx;
m_edited_preset = m_presets[idx];
m_presets.front().is_visible = ! m_default_suppressed || m_idx_selected > 0;
m_presets.front().is_visible = ! m_default_suppressed || m_idx_selected == 0;
return m_presets[idx];
}
@ -458,7 +475,7 @@ bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, b
idx = it - m_presets.begin();
else {
// Find the first visible preset.
for (size_t i = 0; i < m_presets.size(); ++ i)
for (size_t i = m_default_suppressed ? 1 : 0; i < m_presets.size(); ++ i)
if (m_presets[i].is_visible) {
idx = i;
break;

View file

@ -121,6 +121,7 @@ public:
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
// and select it, losing previous modifications.
Preset& load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select = true);
Preset& load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select = true);
// Save the preset under a new name. If the name is different from the old one,
// a new preset is stored into the list of presets.

View file

@ -1,3 +1,6 @@
//#undef NDEBUGc
#include <cassert>
#include "PresetBundle.hpp"
#include <fstream>
@ -17,10 +20,10 @@
#include <wx/bmpcbox.h>
#include <wx/wupdlock.h>
#include "../../libslic3r/libslic3r.h"
#include "../../libslic3r/PlaceholderParser.hpp"
#include "../../libslic3r/Utils.hpp"
#include <assert.h>
namespace Slic3r {
PresetBundle::PresetBundle() :
@ -117,6 +120,15 @@ void PresetBundle::export_selections(AppConfig &config)
config.set("presets", "printer", printers.get_selected_preset().name);
}
void PresetBundle::export_selections(PlaceholderParser &pp)
{
assert(filament_presets.size() >= 1);
assert(filament_presets.size() > 1 || filaments.get_selected_preset().name == filament_presets.front());
pp.set("print_preset", prints.get_selected_preset().name);
pp.set("filament_preset", filament_presets);
pp.set("printer_preset", printers.get_selected_preset().name);
}
bool PresetBundle::load_compatible_bitmaps(const std::string &path_bitmap_compatible, const std::string &path_bitmap_incompatible)
{
bool loaded_compatible = m_bitmapCompatible ->LoadFile(
@ -193,6 +205,15 @@ DynamicPrintConfig PresetBundle::full_config() const
// If the file is loaded successfully, its print / filament / printer profiles will be activated.
void PresetBundle::load_config_file(const std::string &path)
{
if (boost::iends_with(path, ".gcode") || boost::iends_with(path, ".g")) {
DynamicPrintConfig config;
config.apply(FullPrintConfig::defaults());
config.load_from_gcode(path);
Preset::normalize(config);
load_config_file_config(path, std::move(config));
return;
}
// 1) Try to load the config file into a boost property tree.
boost::property_tree::ptree tree;
try {
@ -211,36 +232,37 @@ void PresetBundle::load_config_file(const std::string &path)
throw std::runtime_error(std::string("Unknown configuration file type: ") + path);
case CONFIG_FILE_TYPE_APP_CONFIG:
throw std::runtime_error(std::string("Invalid configuration file: ") + path + ". This is an application config file.");
case CONFIG_FILE_TYPE_CONFIG:
load_config_file_config(path, tree);
break;
case CONFIG_FILE_TYPE_CONFIG:
{
// Initialize a config from full defaults.
DynamicPrintConfig config;
config.apply(FullPrintConfig::defaults());
config.load(tree);
Preset::normalize(config);
load_config_file_config(path, std::move(config));
break;
}
case CONFIG_FILE_TYPE_CONFIG_BUNDLE:
load_config_file_config_bundle(path, tree);
load_config_file_config_bundle(path, tree);
break;
}
}
// Load a config file from a boost property_tree. This is a private method called from load_config_file.
void PresetBundle::load_config_file_config(const std::string &path, const boost::property_tree::ptree &tree)
void PresetBundle::load_config_file_config(const std::string &path, const DynamicPrintConfig &config)
{
// 1) Initialize a config from full defaults.
DynamicPrintConfig config;
config.apply(FullPrintConfig());
config.load(tree);
Preset::normalize(config);
// 2) Create a name from the file name.
// 1) Create a name from the file name.
// Keep the suffix (.ini, .gcode, .amf, .3mf etc) to differentiate it from the normal profiles.
std::string name = boost::filesystem::path(path).filename().string();
// 3) If the loading succeeded, split and load the config into print / filament / printer settings.
// 2) If the loading succeeded, split and load the config into print / filament / printer settings.
// First load the print and printer presets.
for (size_t i_group = 0; i_group < 2; ++ i_group) {
PresetCollection &presets = (i_group == 0) ? this->prints : this->printers;
presets.load_preset(path, name, config).is_external = true;
}
// Now load the filaments. If there are multiple filament presets, split them and load them.
// 3) Now load the filaments. If there are multiple filament presets, split them and load them.
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(config.option("nozzle_diameter"));
auto *filament_diameter = dynamic_cast<const ConfigOptionFloats*>(config.option("filament_diameter"));
size_t num_extruders = std::min(nozzle_diameter->values.size(), filament_diameter->values.size());
@ -253,7 +275,7 @@ void PresetBundle::load_config_file_config(const std::string &path, const boost:
std::vector<DynamicPrintConfig> configs(num_extruders, this->filaments.default_preset().config);
// loop through options and scatter them into configs.
for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) {
const ConfigOption *other_opt = config.option(key, false);
const ConfigOption *other_opt = config.option(key);
if (other_opt == nullptr)
continue;
if (other_opt->is_scalar()) {
@ -273,7 +295,7 @@ void PresetBundle::load_config_file_config(const std::string &path, const boost:
else
sprintf(suffix, " (%d)", i);
// Load all filament presets, but only select the first one in the preset dialog.
this->filaments.load_preset(path, name + suffix, configs[i], i == 0).is_external = true;
this->filaments.load_preset(path, name + suffix, std::move(configs[i]), i == 0).is_external = true;
filament_presets.emplace_back(name + suffix);
}
}
@ -301,7 +323,7 @@ void PresetBundle::load_config_file_config_bundle(const std::string &path, const
// Generate a new unique name.
}
if (! new_name.empty())
this->prints.load_preset(path, new_name, tmp_bundle.prints.get_selected_preset().config);
this->prints.load_preset(path, new_name, std::move(tmp_bundle.prints.get_selected_preset().config));
}
}
@ -369,8 +391,9 @@ size_t PresetBundle::load_configbundle(const std::string &path)
DynamicPrintConfig config(presets->default_preset().config);
for (auto &kvp : section.second)
config.set_deserialize(kvp.first, kvp.second.data());
Preset::normalize(config);
// Load the preset into the list of presets, save it to disk.
presets->load_preset(Slic3r::config_path(presets->name(), preset_name), preset_name, config, false).save();
presets->load_preset(Slic3r::config_path(presets->name(), preset_name), preset_name, std::move(config), false).save();
++ presets_loaded;
}
}
@ -386,7 +409,7 @@ size_t PresetBundle::load_configbundle(const std::string &path)
this->update_multi_material_filament_presets();
for (size_t i = 0; i < std::min(this->filament_presets.size(), active_filaments.size()); ++ i)
this->filament_presets[i] = filaments.first_visible().name;
this->filament_presets[i] = filaments.find_preset(active_filaments[i], true)->name;
return presets_loaded;
}
@ -396,7 +419,6 @@ void PresetBundle::update_multi_material_filament_presets()
auto *nozzle_diameter = static_cast<const ConfigOptionFloats*>(printers.get_edited_preset().config.option("nozzle_diameter"));
size_t num_extruders = nozzle_diameter->values.size();
// Verify validity of the current filament presets.
printf("PresetBundle::update_multi_material_filament_presets, old: %d, new: %d\n", int(this->filament_presets.size()), int(num_extruders));
for (size_t i = 0; i < std::min(this->filament_presets.size(), num_extruders); ++ i)
this->filament_presets[i] = this->filaments.find_preset(this->filament_presets[i], true)->name;
// Append the rest of filament presets.

View file

@ -6,6 +6,8 @@
namespace Slic3r {
class PlaceholderParser;
// Bundle of Print + Filament + Printer presets.
class PresetBundle
{
@ -23,6 +25,8 @@ public:
void load_selections(const AppConfig &config);
// Export selections (current print, current filaments, current printer) into config.ini
void export_selections(AppConfig &config);
// Export selections (current print, current filaments, current printer) into a placeholder parser.
void export_selections(PlaceholderParser &pp);
PresetCollection prints;
PresetCollection filaments;
@ -31,6 +35,9 @@ public:
// extruders.size() should be the same as printers.get_edited_preset().config.nozzle_diameter.size()
std::vector<std::string> filament_presets;
bool has_defauls_only() const
{ return prints.size() <= 1 && filaments.size() <= 1 && printers.size() <= 1; }
DynamicPrintConfig full_config() const;
// Load an external config file containing the print, filament and printer presets.
@ -66,7 +73,7 @@ public:
void update_multi_material_filament_presets();
private:
void load_config_file_config(const std::string &path, const boost::property_tree::ptree &tree);
void load_config_file_config(const std::string &path, const DynamicPrintConfig &config);
void load_config_file_config_bundle(const std::string &path, const boost::property_tree::ptree &tree);
bool load_compatible_bitmaps(const std::string &path_bitmap_compatible, const std::string &path_bitmap_incompatible);

View file

@ -14,6 +14,9 @@ void disable_screensaver()
void enable_screensaver()
%code{% Slic3r::GUI::enable_screensaver(); %};
std::vector<std::string> scan_serial_ports()
%code{% RETVAL=Slic3r::GUI::scan_serial_ports(); %};
bool debugged()
%code{% RETVAL=Slic3r::GUI::debugged(); %};

View file

@ -13,8 +13,22 @@
void reset();
void set_defaults();
void load();
void save();
void load()
%code%{
try {
THIS->load();
} catch (std::exception& e) {
croak("Loading an application config file failed:\n%s\n", e.what());
}
%};
void save()
%code%{
try {
THIS->save();
} catch (std::exception& e) {
croak("Saving an application config file failed:\n%s\n", e.what());
}
%};
bool exists();
bool dirty();

View file

@ -52,10 +52,25 @@
bool update_dirty_ui(SV *ui)
%code%{ RETVAL = THIS->update_dirty_ui((wxChoice*)wxPli_sv_2_object(aTHX_ ui, "Wx::Choice")); %};
void select_preset(int idx);
bool select_preset_by_name(char *name) %code%{ RETVAL = THIS->select_preset_by_name(name, true); %};
void save_current_preset(char *new_name);
void delete_current_preset();
void save_current_preset(char *new_name)
%code%{
try {
THIS->save_current_preset(new_name);
} catch (std::exception& e) {
croak("Error saving a preset %s:\n%s\n", new_name, e.what());
}
%};
void delete_current_preset()
%code%{
try {
THIS->delete_current_preset();
} catch (std::exception& e) {
croak("Error deleting a preset file %s:\n%s\n", THIS->get_selected_preset().file.c_str(), e.what());
}
%};
%{
@ -88,24 +103,61 @@ PresetCollection::presets_hash()
%}
};
%name{Slic3r::GUI::PresetBundle} class PresetBundle {
PresetBundle();
~PresetBundle();
void setup_directories();
void load_presets(const char *dir_path);
void load_config_file(const char *path);
size_t load_configbundle(const char *path);
void export_configbundle(char *path);
void setup_directories()
%code%{
try {
THIS->setup_directories();
} catch (std::exception& e) {
croak("Cannot create configuration directories:\n%s\n", e.what());
}
%};
void load_presets(const char *dir_path)
%code%{
try {
THIS->load_presets(dir_path);
} catch (std::exception& e) {
croak("Loading of Slic3r presets from %s failed:\n%s\n", dir_path, e.what());
}
%};
void load_config_file(const char *path)
%code%{
try {
THIS->load_config_file(path);
} catch (std::exception& e) {
croak("Loading a configuration file %s failed:\n%s\n", path, e.what());
}
%};
size_t load_configbundle(const char *path)
%code%{
try {
RETVAL = THIS->load_configbundle(path);
} catch (std::exception& e) {
croak("Loading of a config bundle %s failed:\n%s\n", path, e.what());
}
%};
void export_configbundle(char *path)
%code%{
try {
THIS->export_configbundle(path);
} catch (std::exception& e) {
croak("Export of a config bundle %s failed:\n%s\n", path, e.what());
}
%};
void set_default_suppressed(bool default_suppressed);
void load_selections (AppConfig *config) %code%{ THIS->load_selections(*config); %};
void export_selections(AppConfig *config) %code%{ THIS->export_selections(*config); %};
void export_selections_pp(PlaceholderParser *pp) %code%{ THIS->export_selections(*pp); %};
Ref<PresetCollection> print() %code%{ RETVAL = &THIS->prints; %};
Ref<PresetCollection> filament() %code%{ RETVAL = &THIS->filaments; %};
Ref<PresetCollection> printer() %code%{ RETVAL = &THIS->printers; %};
bool has_defauls_only();
std::vector<std::string> filament_presets() %code%{ RETVAL = THIS->filament_presets; %};
void set_filament_preset(int idx, const char *name);