Code refactoring: AppConfig.cpp(hpp) are removed from the GUI to libslic3r

This commit is contained in:
YuSanka 2020-08-08 17:03:20 +02:00
parent afcc14861f
commit f9e47b2702
17 changed files with 27 additions and 21 deletions

View File

@ -44,6 +44,7 @@
#include "libslic3r/Format/OBJ.hpp"
#include "libslic3r/Format/SL1.hpp"
#include "libslic3r/Utils.hpp"
#include "libslic3r/AppConfig.hpp"
#include "PrusaSlicer.hpp"
@ -52,7 +53,6 @@
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/3DScene.hpp"
#include "slic3r/GUI/InstanceCheck.hpp"
#include "slic3r/GUI/AppConfig.hpp"
#include "slic3r/GUI/MainFrame.hpp"
#include "slic3r/GUI/Plater.hpp"
#endif /* SLIC3R_GUI */

View File

@ -15,8 +15,8 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/format/format_fwd.hpp>
#include <wx/string.h>
#include "I18N.hpp"
//#include <wx/string.h>
//#include "I18N.hpp"
namespace Slic3r {
@ -110,7 +110,7 @@ void AppConfig::set_defaults()
erase("", "object_settings_size");
}
void AppConfig::load()
std::string AppConfig::load()
{
// 1) Read the complete config file into a boost::property_tree.
namespace pt = boost::property_tree;
@ -120,10 +120,15 @@ void AppConfig::load()
pt::read_ini(ifs, tree);
} catch (pt::ptree_error& ex) {
// Error while parsing config file. We'll customize the error message and rethrow to be displayed.
// ! But to avoid the use of _utf8 (related to use of wxWidgets)
// we will rethrow this exception from the place of load() call, if returned value wouldn't be empty
/*
throw std::runtime_error(
_utf8(L("Error parsing PrusaSlicer config file, it is probably corrupted. "
"Try to manually delete the file to recover from the error. Your user profiles will not be affected.")) +
"\n\n" + AppConfig::config_path() + "\n\n" + ex.what());
*/
return ex.what();
}
// 2) Parse the property_tree, extract the sections and key / value pairs.
@ -169,6 +174,7 @@ void AppConfig::load()
// Override missing or keys with their defaults.
this->set_defaults();
m_dirty = false;
return "";
}
void AppConfig::save()

View File

@ -29,7 +29,8 @@ public:
void set_defaults();
// Load the slic3r.ini from a user profile directory (or a datadir, if configured).
void load();
// return error string or empty strinf
std::string load();
// Store the slic3r.ini into a user profile directory (or a datadir, if configured).
void save();

View File

@ -151,6 +151,8 @@ add_library(libslic3r STATIC
Preset.hpp
PresetBundle.cpp
PresetBundle.hpp
AppConfig.cpp
AppConfig.hpp
Print.cpp
Print.hpp
PrintBase.cpp

View File

@ -1,7 +1,7 @@
#include <cassert>
#include "Preset.hpp"
#include "slic3r/GUI/AppConfig.hpp"
#include "AppConfig.hpp"
#ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN

View File

@ -2,13 +2,12 @@
#define slic3r_PresetBundle_hpp_
#include "Preset.hpp"
#include "AppConfig.hpp"
#include <memory>
#include <unordered_map>
#include <boost/filesystem/path.hpp>
#include "slic3r/GUI/AppConfig.hpp"
namespace Slic3r {
// Bundle of Print + Filament + Printer presets.

View File

@ -12,8 +12,6 @@ set(SLIC3R_GUI_SOURCES
GUI/SysInfoDialog.hpp
GUI/KBShortcutsDialog.cpp
GUI/KBShortcutsDialog.hpp
GUI/AppConfig.cpp
GUI/AppConfig.hpp
GUI/BackgroundSlicingProcess.cpp
GUI/BackgroundSlicingProcess.hpp
GUI/BitmapCache.cpp

View File

@ -1,5 +1,4 @@
#include "Snapshot.hpp"
#include "../GUI/AppConfig.hpp"
#include <time.h>

View File

@ -10,7 +10,6 @@
#if ENABLE_ENVIRONMENT_MAP
#include "GUI_App.hpp"
#include "Plater.hpp"
#include "AppConfig.hpp"
#endif // ENABLE_ENVIRONMENT_MAP
#include "libslic3r/ExtrusionEntity.hpp"
@ -24,6 +23,7 @@
#include "slic3r/GUI/BitmapCache.hpp"
#include "libslic3r/Format/STL.hpp"
#include "libslic3r/Utils.hpp"
#include "libslic3r/AppConfig.hpp"
#include <stdio.h>
#include <stdlib.h>

View File

@ -1,8 +1,8 @@
#include "libslic3r/libslic3r.h"
#include "libslic3r/AppConfig.hpp"
#include "Camera.hpp"
#include "GUI_App.hpp"
#include "AppConfig.hpp"
#if ENABLE_CAMERA_STATISTICS
#include "Mouse3DController.hpp"
#endif // ENABLE_CAMERA_STATISTICS

View File

@ -22,7 +22,6 @@
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/PresetBundle.hpp"
#include "slic3r/Utils/PresetUpdater.hpp"
#include "AppConfig.hpp"
#include "BedShapeDialog.hpp"
#include "GUI.hpp"
#include "wxExtensions.hpp"

View File

@ -38,7 +38,6 @@
#include "GUI.hpp"
#include "GUI_Utils.hpp"
#include "AppConfig.hpp"
#include "3DScene.hpp"
#include "MainFrame.hpp"
#include "Plater.hpp"
@ -326,7 +325,13 @@ void GUI_App::init_app_config()
// load settings
app_conf_exists = app_config->exists();
if (app_conf_exists) {
app_config->load();
std::string error = app_config->load();
if (!error.empty())
// Error while parsing config file. We'll customize the error message and rethrow to be displayed.
throw std::runtime_error(
_u8L("Error parsing PrusaSlicer config file, it is probably corrupted. "
"Try to manually delete the file to recover from the error. Your user profiles will not be affected.") +
"\n\n" + AppConfig::config_path() + "\n\n" + error);
}
}

View File

@ -2,7 +2,6 @@
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/AppConfig.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/GUI_ObjectList.hpp"
#include "slic3r/Utils/SLAImport.hpp"

View File

@ -20,7 +20,6 @@
#include "Tab.hpp"
#include "ProgressStatusBar.hpp"
#include "3DScene.hpp"
#include "AppConfig.hpp"
#include "PrintHostDialogs.hpp"
#include "wxExtensions.hpp"
#include "GUI_ObjectList.hpp"

View File

@ -4,7 +4,6 @@
#include "Camera.hpp"
#include "GUI_App.hpp"
#include "AppConfig.hpp"
#include "GLCanvas3D.hpp"
#include "Plater.hpp"
#include "NotificationManager.hpp"

View File

@ -1,8 +1,8 @@
#include "Preferences.hpp"
#include "AppConfig.hpp"
#include "OptionsGroup.hpp"
#include "GUI_App.hpp"
#include "I18N.hpp"
#include "libslic3r/AppConfig.hpp"
namespace Slic3r {
namespace GUI {

View File

@ -15,11 +15,11 @@
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "AppConfig.hpp"
#include "MsgDialog.hpp"
#include "I18N.hpp"
#include "../Utils/PrintHost.hpp"
#include "wxExtensions.hpp"
#include "libslic3r/AppConfig.hpp"
namespace fs = boost::filesystem;