AppConfig modified to generate a separate config file for the standalone gcodeviewer

This commit is contained in:
enricoturri1966 2020-10-05 15:42:35 +02:00
parent 6a12e75194
commit c94fb13369
9 changed files with 166 additions and 44 deletions

View File

@ -37,47 +37,82 @@ void AppConfig::reset()
// Override missing or keys with their defaults.
void AppConfig::set_defaults()
{
// Reset the empty fields to defaults.
if (get("autocenter").empty())
set("autocenter", "0");
// Disable background processing by default as it is not stable.
if (get("background_processing").empty())
set("background_processing", "0");
// 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", "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");
if (get("show_incompatible_presets").empty())
set("show_incompatible_presets", "0");
#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");
// Disable background processing by default as it is not stable.
if (get("background_processing").empty())
set("background_processing", "0");
// 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", "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");
if (get("show_incompatible_presets").empty())
set("show_incompatible_presets", "0");
if (get("version_check").empty())
set("version_check", "1");
if (get("preset_update").empty())
set("preset_update", "1");
if (get("version_check").empty())
set("version_check", "1");
if (get("preset_update").empty())
set("preset_update", "1");
if (get("export_sources_full_pathnames").empty())
set("export_sources_full_pathnames", "0");
if (get("export_sources_full_pathnames").empty())
set("export_sources_full_pathnames", "0");
// remove old 'use_legacy_opengl' parameter from this config, if present
if (!get("use_legacy_opengl").empty())
erase("", "use_legacy_opengl");
// remove old 'use_legacy_opengl' parameter from this config, if present
if (!get("use_legacy_opengl").empty())
erase("", "use_legacy_opengl");
#ifdef __APPLE__
if (get("use_retina_opengl").empty())
set("use_retina_opengl", "1");
if (get("use_retina_opengl").empty())
set("use_retina_opengl", "1");
#endif
if (get("single_instance").empty())
set("single_instance", "0");
#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");
if (get("remember_output_path").empty())
set("remember_output_path", "1");
if (get("remember_output_path_removable").empty())
set("remember_output_path_removable", "1");
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()
{
return (boost::filesystem::path(Slic3r::data_dir()) / (SLIC3R_APP_KEY ".ini")).make_preferred().string();
#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

View File

@ -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;

View File

@ -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_

View File

@ -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();

View File

@ -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 */

View File

@ -604,9 +604,16 @@ std::string string_printf(const char *format, ...)
std::string header_slic3r_generated()
{
return std::string("generated by " SLIC3R_APP_NAME " " SLIC3R_VERSION " on " ) + Utils::utc_timestamp();
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

View File

@ -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)
{}

View File

@ -634,25 +634,49 @@ void GUI_App::init_app_config()
set_data_dir(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data());
if (!app_config)
app_config = new AppConfig();
#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
}
}
void GUI_App::init_single_instance_checker(const std::string &name, const std::string &path)

View File

@ -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")