Fix of G-code Viewer not loading .gco files #5536
".gcode", ".gco", ".g" and ".ngc" were considered to be G-code file extensions by the G-code import / export file dialogs, but not by various other functions. Now the G-code extension is tested by a single function is_gcode_file(string).
This commit is contained in:
parent
b93c2aea44
commit
fb29325b14
@ -150,15 +150,11 @@ int CLI::run(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read input file(s) if any.
|
// Read input file(s) if any.
|
||||||
for (const std::string& file : m_input_files) {
|
for (const std::string& file : m_input_files)
|
||||||
std::string ext = boost::filesystem::path(file).extension().string();
|
if (is_gcode_file(file) && boost::filesystem::exists(file)) {
|
||||||
if (ext == ".gcode" || ext == ".g") {
|
|
||||||
if (boost::filesystem::exists(file)) {
|
|
||||||
start_as_gcodeviewer = true;
|
start_as_gcodeviewer = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!start_as_gcodeviewer) {
|
if (!start_as_gcodeviewer) {
|
||||||
for (const std::string& file : m_input_files) {
|
for (const std::string& file : m_input_files) {
|
||||||
if (!boost::filesystem::exists(file)) {
|
if (!boost::filesystem::exists(file)) {
|
||||||
|
@ -589,7 +589,7 @@ void ConfigBase::setenv_() const
|
|||||||
|
|
||||||
void ConfigBase::load(const std::string &file)
|
void ConfigBase::load(const std::string &file)
|
||||||
{
|
{
|
||||||
if (boost::iends_with(file, ".gcode") || boost::iends_with(file, ".g"))
|
if (is_gcode_file(file))
|
||||||
this->load_from_gcode_file(file);
|
this->load_from_gcode_file(file);
|
||||||
else
|
else
|
||||||
this->load_from_ini(file);
|
this->load_from_ini(file);
|
||||||
|
@ -667,7 +667,7 @@ DynamicPrintConfig PresetBundle::full_sla_config() const
|
|||||||
// If the file is loaded successfully, its print / filament / printer profiles will be activated.
|
// If the file is loaded successfully, its print / filament / printer profiles will be activated.
|
||||||
void PresetBundle::load_config_file(const std::string &path)
|
void PresetBundle::load_config_file(const std::string &path)
|
||||||
{
|
{
|
||||||
if (boost::iends_with(path, ".gcode") || boost::iends_with(path, ".g")) {
|
if (is_gcode_file(path)) {
|
||||||
DynamicPrintConfig config;
|
DynamicPrintConfig config;
|
||||||
config.apply(FullPrintConfig::defaults());
|
config.apply(FullPrintConfig::defaults());
|
||||||
config.load_from_gcode_file(path);
|
config.load_from_gcode_file(path);
|
||||||
|
@ -90,6 +90,7 @@ extern CopyFileResult check_copy(const std::string& origin, const std::string& c
|
|||||||
extern bool is_plain_file(const boost::filesystem::directory_entry &path);
|
extern bool is_plain_file(const boost::filesystem::directory_entry &path);
|
||||||
extern bool is_ini_file(const boost::filesystem::directory_entry &path);
|
extern bool is_ini_file(const boost::filesystem::directory_entry &path);
|
||||||
extern bool is_idx_file(const boost::filesystem::directory_entry &path);
|
extern bool is_idx_file(const boost::filesystem::directory_entry &path);
|
||||||
|
extern bool is_gcode_file(const std::string &path);
|
||||||
|
|
||||||
// File path / name / extension splitting utilities, working with UTF-8,
|
// File path / name / extension splitting utilities, working with UTF-8,
|
||||||
// to be published to Perl.
|
// to be published to Perl.
|
||||||
|
@ -522,6 +522,12 @@ bool is_idx_file(const boost::filesystem::directory_entry &dir_entry)
|
|||||||
return is_plain_file(dir_entry) && strcasecmp(dir_entry.path().extension().string().c_str(), ".idx") == 0;
|
return is_plain_file(dir_entry) && strcasecmp(dir_entry.path().extension().string().c_str(), ".idx") == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_gcode_file(const std::string &path)
|
||||||
|
{
|
||||||
|
return boost::iends_with(path, ".gcode") || boost::iends_with(path, ".gco") ||
|
||||||
|
boost::iends_with(path, ".g") || boost::iends_with(path, ".ngc");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -1866,11 +1866,9 @@ bool GUI_App::OnExceptionInMainLoop()
|
|||||||
void GUI_App::OSXStoreOpenFiles(const wxArrayString &fileNames)
|
void GUI_App::OSXStoreOpenFiles(const wxArrayString &fileNames)
|
||||||
{
|
{
|
||||||
size_t num_gcodes = 0;
|
size_t num_gcodes = 0;
|
||||||
for (const wxString &filename : fileNames) {
|
for (const wxString &filename : fileNames)
|
||||||
wxString fn = filename.Upper();
|
if (is_gcode_file(into_u8(filename)))
|
||||||
if (fn.EndsWith(".G") || fn.EndsWith(".GCODE"))
|
|
||||||
++ num_gcodes;
|
++ num_gcodes;
|
||||||
}
|
|
||||||
if (fileNames.size() == num_gcodes) {
|
if (fileNames.size() == num_gcodes) {
|
||||||
// Opening PrusaSlicer by drag & dropping a G-Code onto PrusaSlicer icon in Finder,
|
// Opening PrusaSlicer by drag & dropping a G-Code onto PrusaSlicer icon in Finder,
|
||||||
// just G-codes were passed. Switch to G-code viewer mode.
|
// just G-codes were passed. Switch to G-code viewer mode.
|
||||||
@ -1890,8 +1888,7 @@ void GUI_App::MacOpenFiles(const wxArrayString &fileNames)
|
|||||||
std::vector<wxString> gcode_files;
|
std::vector<wxString> gcode_files;
|
||||||
std::vector<wxString> non_gcode_files;
|
std::vector<wxString> non_gcode_files;
|
||||||
for (const auto& filename : fileNames) {
|
for (const auto& filename : fileNames) {
|
||||||
wxString fn = filename.Upper();
|
if (is_gcode_file(into_u8(filename)))
|
||||||
if (fn.EndsWith(".G") || fn.EndsWith(".GCODE"))
|
|
||||||
gcode_files.emplace_back(filename);
|
gcode_files.emplace_back(filename);
|
||||||
else {
|
else {
|
||||||
files.emplace_back(into_u8(filename));
|
files.emplace_back(into_u8(filename));
|
||||||
|
@ -4847,9 +4847,7 @@ void Plater::load_gcode()
|
|||||||
|
|
||||||
void Plater::load_gcode(const wxString& filename)
|
void Plater::load_gcode(const wxString& filename)
|
||||||
{
|
{
|
||||||
if (filename.empty() ||
|
if (! is_gcode_file(into_u8(filename)) || m_last_loaded_gcode == filename)
|
||||||
(!filename.Lower().EndsWith(".gcode") && !filename.Lower().EndsWith(".g")) ||
|
|
||||||
m_last_loaded_gcode == filename)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_last_loaded_gcode = filename;
|
m_last_loaded_gcode = filename;
|
||||||
|
Loading…
Reference in New Issue
Block a user