mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 19:28:14 -06:00
New C++ class AppConfig for maintaining the config.ini
New helper function for generating a unified "generated by slic3r" header.
This commit is contained in:
parent
835e5b71a8
commit
1fee3633a0
11 changed files with 107 additions and 51 deletions
|
@ -373,19 +373,6 @@ bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, b
|
|||
return false;
|
||||
}
|
||||
|
||||
bool PresetCollection::select_by_name_ui(char *name, wxItemContainer *ui)
|
||||
{
|
||||
this->select_preset_by_name(name, true);
|
||||
//FIXME this is not finished yet.
|
||||
//this->update_platter_ui(wxChoice *ui)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PresetCollection::select_by_name_ui(char *name, wxChoice *ui)
|
||||
{
|
||||
return this->select_by_name_ui(name, dynamic_cast<wxItemContainer*>(ui));
|
||||
}
|
||||
|
||||
PresetBundle::PresetBundle() :
|
||||
prints(Preset::TYPE_PRINT, print_options()),
|
||||
filaments(Preset::TYPE_FILAMENT, filament_options()),
|
||||
|
@ -423,6 +410,20 @@ PresetBundle::~PresetBundle()
|
|||
delete bitmap.second;
|
||||
}
|
||||
|
||||
void PresetBundle::setup_directories()
|
||||
{
|
||||
boost::filesystem::path dir = boost::filesystem::canonical(Slic3r::data_dir());
|
||||
if (! boost::filesystem::is_directory(dir))
|
||||
throw std::runtime_error(std::string("datadir does not exist: ") + Slic3r::data_dir());
|
||||
std::initializer_list<const char*> names = { "print", "filament", "printer" };
|
||||
for (const char *name : names) {
|
||||
boost::filesystem::path subdir = (dir / subdir).make_preferred();
|
||||
if (! boost::filesystem::is_directory(subdir) &&
|
||||
! boost::filesystem::create_directory(subdir))
|
||||
throw std::runtime_error(std::string("Slic3r was unable to create its data directory at ") + subdir.string());
|
||||
}
|
||||
}
|
||||
|
||||
void PresetBundle::load_presets(const std::string &dir_path)
|
||||
{
|
||||
this->prints .load_presets(dir_path, "print");
|
||||
|
@ -431,6 +432,36 @@ void PresetBundle::load_presets(const std::string &dir_path)
|
|||
this->update_multi_material_filament_presets();
|
||||
}
|
||||
|
||||
// Load selections (current print, current filaments, current printer) from config.ini
|
||||
// This is done just once on application start up.
|
||||
void PresetBundle::load_selections(const AppConfig &config)
|
||||
{
|
||||
prints.select_preset_by_name(config.get("presets", "print"), true);
|
||||
filaments.select_preset_by_name(config.get("presets", "filament"), true);
|
||||
this->set_filament_preset(0, filaments.get_selected_preset().name);
|
||||
for (int i = 1; i < 1000; ++ i) {
|
||||
char name[64];
|
||||
sprintf(name, "filament_%d", i);
|
||||
if (! config.has("presets", name))
|
||||
break;
|
||||
this->set_filament_preset(i, name);
|
||||
}
|
||||
printers.select_preset_by_name(config.get("presets", "printer"), true);
|
||||
}
|
||||
|
||||
// Export selections (current print, current filaments, current printer) into config.ini
|
||||
void PresetBundle::export_selections(AppConfig &config)
|
||||
{
|
||||
config.set("presets", "print", prints .get_selected_preset().name);
|
||||
config.set("presets", "filament", filaments.get_selected_preset().name);
|
||||
for (int i = 1; i < 1000; ++ i) {
|
||||
char name[64];
|
||||
sprintf(name, "filament_%d", i);
|
||||
config.set("presets", name, filament_presets[i]);
|
||||
}
|
||||
config.set("presets", "printer", 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(
|
||||
|
@ -579,7 +610,7 @@ std::string PresetCollection::name() const
|
|||
// of the local configuration directory.
|
||||
size_t PresetBundle::load_configbundle(const std::string &path)
|
||||
{
|
||||
// 1) Read the complete config file into the boost::property_tree.
|
||||
// 1) Read the complete config file into a boost::property_tree.
|
||||
namespace pt = boost::property_tree;
|
||||
pt::ptree tree;
|
||||
boost::nowide::ifstream ifs(path);
|
||||
|
@ -679,13 +710,7 @@ void PresetBundle::export_configbundle(const std::string &path, const DynamicPri
|
|||
c.open(path, std::ios::out | std::ios::trunc);
|
||||
|
||||
// Put a comment at the first line including the time stamp and Slic3r version.
|
||||
{
|
||||
std::time_t now;
|
||||
time(&now);
|
||||
char buf[sizeof "0000-00-00 00:00:00"];
|
||||
strftime(buf, sizeof(buf), "%F %T", gmtime(&now));
|
||||
c << "# generated by Slic3r " << SLIC3R_VERSION << " on " << buf << std::endl;
|
||||
}
|
||||
c << "# " << Slic3r::header_slic3r_generated() << std::endl;
|
||||
|
||||
// Export the print, filament and printer profiles.
|
||||
for (size_t i_group = 0; i_group < 3; ++ i_group) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue