AppConfig modified to generate a separate config file for the standalone gcodeviewer
This commit is contained in:
parent
6a12e75194
commit
c94fb13369
@ -37,6 +37,9 @@ void AppConfig::reset()
|
||||
// Override missing or keys with their defaults.
|
||||
void AppConfig::set_defaults()
|
||||
{
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
if (m_mode == EAppMode::Editor) {
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
// Reset the empty fields to defaults.
|
||||
if (get("autocenter").empty())
|
||||
set("autocenter", "0");
|
||||
@ -70,8 +73,10 @@ void AppConfig::set_defaults()
|
||||
set("use_retina_opengl", "1");
|
||||
#endif
|
||||
|
||||
#if !ENABLE_GCODE_APP_CONFIG
|
||||
if (get("single_instance").empty())
|
||||
set("single_instance", "0");
|
||||
#endif // !ENABLE_GCODE_APP_CONFIG
|
||||
|
||||
if (get("remember_output_path").empty())
|
||||
set("remember_output_path", "1");
|
||||
@ -79,6 +84,36 @@ void AppConfig::set_defaults()
|
||||
if (get("remember_output_path_removable").empty())
|
||||
set("remember_output_path_removable", "1");
|
||||
|
||||
#if !ENABLE_GCODE_APP_CONFIG
|
||||
if (get("use_custom_toolbar_size").empty())
|
||||
set("use_custom_toolbar_size", "0");
|
||||
|
||||
if (get("custom_toolbar_size").empty())
|
||||
set("custom_toolbar_size", "100");
|
||||
|
||||
if (get("auto_toolbar_size").empty())
|
||||
set("auto_toolbar_size", "100");
|
||||
|
||||
if (get("use_perspective_camera").empty())
|
||||
set("use_perspective_camera", "1");
|
||||
|
||||
if (get("use_free_camera").empty())
|
||||
set("use_free_camera", "0");
|
||||
#endif // !ENABLE_GCODE_APP_CONFIG
|
||||
|
||||
#if ENABLE_ENVIRONMENT_MAP
|
||||
if (get("use_environment_map").empty())
|
||||
set("use_environment_map", "0");
|
||||
#endif // ENABLE_ENVIRONMENT_MAP
|
||||
|
||||
if (get("use_inches").empty())
|
||||
set("use_inches", "0");
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
}
|
||||
|
||||
if (get("single_instance").empty())
|
||||
set("single_instance", "0");
|
||||
|
||||
if (get("use_custom_toolbar_size").empty())
|
||||
set("use_custom_toolbar_size", "0");
|
||||
|
||||
@ -93,14 +128,7 @@ void AppConfig::set_defaults()
|
||||
|
||||
if (get("use_free_camera").empty())
|
||||
set("use_free_camera", "0");
|
||||
|
||||
#if ENABLE_ENVIRONMENT_MAP
|
||||
if (get("use_environment_map").empty())
|
||||
set("use_environment_map", "0");
|
||||
#endif // ENABLE_ENVIRONMENT_MAP
|
||||
|
||||
if (get("use_inches").empty())
|
||||
set("use_inches", "0");
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
|
||||
if (get("show_splash_screen").empty())
|
||||
set("show_splash_screen", "1");
|
||||
@ -184,8 +212,10 @@ std::string AppConfig::load()
|
||||
void AppConfig::save()
|
||||
{
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
#if !ENABLE_GCODE_APP_CONFIG
|
||||
if (!m_save_enabled)
|
||||
return;
|
||||
#endif // !ENABLE_GCODE_APP_CONFIG
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
|
||||
// The config is first written to a file with a PID suffix and then moved
|
||||
@ -195,7 +225,14 @@ void AppConfig::save()
|
||||
|
||||
boost::nowide::ofstream c;
|
||||
c.open(path_pid, std::ios::out | std::ios::trunc);
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
if (m_mode == EAppMode::Editor)
|
||||
c << "# " << Slic3r::header_slic3r_generated() << std::endl;
|
||||
else
|
||||
c << "# " << Slic3r::header_gcodeviewer_generated() << std::endl;
|
||||
#else
|
||||
c << "# " << Slic3r::header_slic3r_generated() << std::endl;
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
// Make sure the "no" category is written first.
|
||||
for (const std::pair<std::string, std::string> &kvp : m_storage[""])
|
||||
c << kvp.first << " = " << kvp.second << std::endl;
|
||||
@ -395,7 +432,15 @@ void AppConfig::reset_selections()
|
||||
|
||||
std::string AppConfig::config_path()
|
||||
{
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
std::string path = (m_mode == EAppMode::Editor) ?
|
||||
(boost::filesystem::path(Slic3r::data_dir()) / (SLIC3R_APP_KEY ".ini")).make_preferred().string() :
|
||||
(boost::filesystem::path(Slic3r::data_dir()) / (GCODEVIEWER_APP_KEY ".ini")).make_preferred().string();
|
||||
|
||||
return path;
|
||||
#else
|
||||
return (boost::filesystem::path(Slic3r::data_dir()) / (SLIC3R_APP_KEY ".ini")).make_preferred().string();
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
}
|
||||
|
||||
std::string AppConfig::version_check_url() const
|
||||
@ -406,7 +451,11 @@ std::string AppConfig::version_check_url() const
|
||||
|
||||
bool AppConfig::exists()
|
||||
{
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
return boost::filesystem::exists(config_path());
|
||||
#else
|
||||
return boost::filesystem::exists(AppConfig::config_path());
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
}
|
||||
|
||||
}; // namespace Slic3r
|
||||
|
@ -15,11 +15,25 @@ namespace Slic3r {
|
||||
class AppConfig
|
||||
{
|
||||
public:
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
enum class EAppMode : unsigned char
|
||||
{
|
||||
Editor,
|
||||
GCodeViewer
|
||||
};
|
||||
|
||||
explicit AppConfig(EAppMode mode) :
|
||||
#else
|
||||
AppConfig() :
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
m_dirty(false),
|
||||
m_orig_version(Semver::invalid()),
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
m_mode(mode),
|
||||
#else
|
||||
m_save_enabled(true),
|
||||
#endif // !ENABLE_GCODE_APP_CONFIG
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
m_legacy_datadir(false)
|
||||
{
|
||||
@ -125,7 +139,11 @@ public:
|
||||
void reset_selections();
|
||||
|
||||
// Get the default config path from Slic3r::data_dir().
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
std::string config_path();
|
||||
#else
|
||||
static std::string config_path();
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
|
||||
// Returns true if the user's data directory comes from before Slic3r 1.40.0 (no updating)
|
||||
bool legacy_datadir() const { return m_legacy_datadir; }
|
||||
@ -140,7 +158,11 @@ public:
|
||||
Semver orig_version() const { return m_orig_version; }
|
||||
|
||||
// Does the config file exist?
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
bool exists();
|
||||
#else
|
||||
static bool exists();
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
|
||||
std::vector<std::string> get_recent_projects() const;
|
||||
void set_recent_projects(const std::vector<std::string>& recent_projects);
|
||||
@ -161,7 +183,9 @@ public:
|
||||
{ return get_3dmouse_device_numeric_value(name, "swap_yz", swap); }
|
||||
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
#if !ENABLE_GCODE_APP_CONFIG
|
||||
void enable_save(bool enable) { m_save_enabled = enable; }
|
||||
#endif // !ENABLE_GCODE_APP_CONFIG
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
|
||||
static const std::string SECTION_FILAMENTS;
|
||||
@ -182,6 +206,10 @@ private:
|
||||
return true;
|
||||
}
|
||||
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
EAppMode m_mode { EAppMode::Editor };
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
|
||||
// Map of section, name -> value
|
||||
std::map<std::string, std::map<std::string, std::string>> m_storage;
|
||||
// Map of enabled vendors / models / variants
|
||||
@ -191,8 +219,10 @@ private:
|
||||
// Original version found in the ini file before it was overwritten
|
||||
Semver m_orig_version;
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
#if !ENABLE_GCODE_APP_CONFIG
|
||||
// Whether or not calls to save() should take effect
|
||||
bool m_save_enabled;
|
||||
#endif // !ENABLE_GCODE_APP_CONFIG
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
// Whether the existing version is before system profiles & configuration updating
|
||||
bool m_legacy_datadir;
|
||||
|
@ -56,6 +56,7 @@
|
||||
#define ENABLE_GCODE_VIEWER_STATISTICS (0 && ENABLE_GCODE_VIEWER)
|
||||
#define ENABLE_GCODE_VIEWER_DATA_CHECKING (0 && ENABLE_GCODE_VIEWER)
|
||||
#define ENABLE_GCODE_VIEWER_TASKBAR_ICON (0 && ENABLE_GCODE_VIEWER)
|
||||
#define ENABLE_GCODE_APP_CONFIG (1 && ENABLE_GCODE_VIEWER)
|
||||
#define ENABLE_GCODE_DRAG_AND_DROP_GCODE_FILES (1 && ENABLE_GCODE_VIEWER)
|
||||
|
||||
#endif // _prusaslicer_technologies_h_
|
||||
|
@ -107,6 +107,12 @@ std::string string_printf(const char *format, ...);
|
||||
// to be placed at the top of Slic3r generated files.
|
||||
std::string header_slic3r_generated();
|
||||
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
// Standard "generated by PrusaGCodeViewer version xxx timestamp xxx" header string,
|
||||
// to be placed at the top of Slic3r generated files.
|
||||
std::string header_gcodeviewer_generated();
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
|
||||
// getpid platform wrapper
|
||||
extern unsigned get_current_pid();
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define SLIC3R_BUILD_ID "@SLIC3R_BUILD_ID@"
|
||||
|
||||
#define GCODEVIEWER_APP_NAME "@GCODEVIEWER_APP_NAME@"
|
||||
#define GCODEVIEWER_APP_KEY "@GCODEVIEWER_APP_KEY@"
|
||||
#define GCODEVIEWER_BUILD_ID "@GCODEVIEWER_BUILD_ID@"
|
||||
|
||||
#endif /* __SLIC3R_VERSION_H */
|
||||
|
@ -607,6 +607,13 @@ std::string header_slic3r_generated()
|
||||
return std::string("generated by " SLIC3R_APP_NAME " " SLIC3R_VERSION " on " ) + Utils::utc_timestamp();
|
||||
}
|
||||
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
std::string header_gcodeviewer_generated()
|
||||
{
|
||||
return std::string("generated by " GCODEVIEWER_APP_NAME " " SLIC3R_VERSION " on ") + Utils::utc_timestamp();
|
||||
}
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
|
||||
unsigned get_current_pid()
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
@ -557,6 +557,9 @@ struct ConfigWizard::priv
|
||||
|
||||
priv(ConfigWizard *q)
|
||||
: q(q)
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
, appconfig_new(AppConfig::EAppMode::Editor)
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
, filaments(T_FFF)
|
||||
, sla_materials(T_SLA)
|
||||
{}
|
||||
|
@ -634,24 +634,48 @@ void GUI_App::init_app_config()
|
||||
set_data_dir(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data());
|
||||
|
||||
if (!app_config)
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
app_config = new AppConfig(is_editor() ? AppConfig::EAppMode::Editor : AppConfig::EAppMode::GCodeViewer);
|
||||
#else
|
||||
app_config = new AppConfig();
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
#if !ENABLE_GCODE_APP_CONFIG
|
||||
if (is_gcode_viewer())
|
||||
// disable config save to avoid to mess it up for the editor
|
||||
app_config->enable_save(false);
|
||||
#endif // !ENABLE_GCODE_APP_CONFIG
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
|
||||
// load settings
|
||||
app_conf_exists = app_config->exists();
|
||||
if (app_conf_exists) {
|
||||
std::string error = app_config->load();
|
||||
#if ENABLE_GCODE_APP_CONFIG
|
||||
if (!error.empty()) {
|
||||
// Error while parsing config file. We'll customize the error message and rethrow to be displayed.
|
||||
if (is_editor()) {
|
||||
throw Slic3r::RuntimeError(
|
||||
_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" + app_config->config_path() + "\n\n" + error);
|
||||
}
|
||||
else {
|
||||
throw Slic3r::RuntimeError(
|
||||
_u8L("Error parsing PrusaGCodeViewer config file, it is probably corrupted. "
|
||||
"Try to manually delete the file to recover from the error.") +
|
||||
"\n\n" + app_config->config_path() + "\n\n" + error);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (!error.empty())
|
||||
// Error while parsing config file. We'll customize the error message and rethrow to be displayed.
|
||||
throw Slic3r::RuntimeError(
|
||||
_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);
|
||||
#endif // ENABLE_GCODE_APP_CONFIG
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,4 +9,5 @@ set(SLIC3R_RC_VERSION "2,3,0,0")
|
||||
set(SLIC3R_RC_VERSION_DOTS "2.3.0.0")
|
||||
|
||||
set(GCODEVIEWER_APP_NAME "Prusa GCode Viewer")
|
||||
set(GCODEVIEWER_APP_KEY "PrusaGCodeViewer")
|
||||
set(GCODEVIEWER_BUILD_ID "Prusa GCode Viewer-${SLIC3R_VERSION}+UNKNOWN")
|
||||
|
Loading…
Reference in New Issue
Block a user