mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 08:47:52 -06:00
Completed implementation of 'File->GCode preview...' command
This commit is contained in:
parent
e010d287c5
commit
2f9dd9d9e8
3 changed files with 87 additions and 44 deletions
|
@ -140,37 +140,57 @@ int CLI::run(int argc, char **argv)
|
||||||
m_print_config.apply(config);
|
m_print_config.apply(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read input file(s) if any.
|
#if ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
for (const std::string &file : m_input_files) {
|
// are we starting as gcodeviewer ?
|
||||||
if (! boost::filesystem::exists(file)) {
|
for (auto it = m_actions.begin(); it != m_actions.end(); ++it) {
|
||||||
boost::nowide::cerr << "No such file: " << file << std::endl;
|
if (*it == "gcodeviewer") {
|
||||||
exit(1);
|
start_gui = true;
|
||||||
|
start_as_gcodeviewer = true;
|
||||||
|
m_actions.erase(it);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
Model model;
|
}
|
||||||
try {
|
#endif // ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
// When loading an AMF or 3MF, config is imported as well, including the printer technology.
|
|
||||||
DynamicPrintConfig config;
|
// Read input file(s) if any.
|
||||||
model = Model::read_from_file(file, &config, true);
|
#if ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
PrinterTechnology other_printer_technology = Slic3r::printer_technology(config);
|
if (!start_as_gcodeviewer) {
|
||||||
if (printer_technology == ptUnknown) {
|
#endif // ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
printer_technology = other_printer_technology;
|
for (const std::string& file : m_input_files) {
|
||||||
} else if (printer_technology != other_printer_technology && other_printer_technology != ptUnknown) {
|
if (!boost::filesystem::exists(file)) {
|
||||||
boost::nowide::cerr << "Mixing configurations for FFF and SLA technologies" << std::endl;
|
boost::nowide::cerr << "No such file: " << file << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
Model model;
|
||||||
|
try {
|
||||||
|
// When loading an AMF or 3MF, config is imported as well, including the printer technology.
|
||||||
|
DynamicPrintConfig config;
|
||||||
|
model = Model::read_from_file(file, &config, true);
|
||||||
|
PrinterTechnology other_printer_technology = Slic3r::printer_technology(config);
|
||||||
|
if (printer_technology == ptUnknown) {
|
||||||
|
printer_technology = other_printer_technology;
|
||||||
|
}
|
||||||
|
else if (printer_technology != other_printer_technology && other_printer_technology != ptUnknown) {
|
||||||
|
boost::nowide::cerr << "Mixing configurations for FFF and SLA technologies" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
// config is applied to m_print_config before the current m_config values.
|
||||||
|
config += std::move(m_print_config);
|
||||||
|
m_print_config = std::move(config);
|
||||||
|
}
|
||||||
|
catch (std::exception& e) {
|
||||||
|
boost::nowide::cerr << file << ": " << e.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// config is applied to m_print_config before the current m_config values.
|
if (model.objects.empty()) {
|
||||||
config += std::move(m_print_config);
|
boost::nowide::cerr << "Error: file is empty: " << file << std::endl;
|
||||||
m_print_config = std::move(config);
|
continue;
|
||||||
} catch (std::exception &e) {
|
}
|
||||||
boost::nowide::cerr << file << ": " << e.what() << std::endl;
|
m_models.push_back(model);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
if (model.objects.empty()) {
|
#if ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
boost::nowide::cerr << "Error: file is empty: " << file << std::endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
m_models.push_back(model);
|
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
|
|
||||||
// Apply command line options to a more specific DynamicPrintConfig which provides normalize()
|
// Apply command line options to a more specific DynamicPrintConfig which provides normalize()
|
||||||
// (command line options override --load files)
|
// (command line options override --load files)
|
||||||
|
@ -529,9 +549,11 @@ int CLI::run(int argc, char **argv)
|
||||||
<< " (" << print.total_extruded_volume()/1000 << "cm3)" << std::endl;
|
<< " (" << print.total_extruded_volume()/1000 << "cm3)" << std::endl;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
#if !ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
} else if (opt_key == "gcodeviewer") {
|
} else if (opt_key == "gcodeviewer") {
|
||||||
start_gui = true;
|
start_gui = true;
|
||||||
start_as_gcodeviewer = true;
|
start_as_gcodeviewer = true;
|
||||||
|
#endif // !ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
} else {
|
} else {
|
||||||
boost::nowide::cerr << "error: option not supported yet: " << opt_key << std::endl;
|
boost::nowide::cerr << "error: option not supported yet: " << opt_key << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -555,28 +577,43 @@ int CLI::run(int argc, char **argv)
|
||||||
|
|
||||||
// gui->autosave = m_config.opt_string("autosave");
|
// gui->autosave = m_config.opt_string("autosave");
|
||||||
GUI::GUI_App::SetInstance(gui);
|
GUI::GUI_App::SetInstance(gui);
|
||||||
|
#if ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
|
gui->CallAfter([gui, this, &load_configs, start_as_gcodeviewer] {
|
||||||
|
#else
|
||||||
gui->CallAfter([gui, this, &load_configs] {
|
gui->CallAfter([gui, this, &load_configs] {
|
||||||
|
#endif // ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
|
|
||||||
if (!gui->initialized()) {
|
if (!gui->initialized()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
|
if (start_as_gcodeviewer) {
|
||||||
|
if (!m_input_files.empty())
|
||||||
|
gui->plater()->load_gcode(wxString::FromUTF8(m_input_files[0]));
|
||||||
|
} else {
|
||||||
|
#endif // ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
#if 0
|
#if 0
|
||||||
// Load the cummulative config over the currently active profiles.
|
// Load the cummulative config over the currently active profiles.
|
||||||
//FIXME if multiple configs are loaded, only the last one will have an effect.
|
//FIXME if multiple configs are loaded, only the last one will have an effect.
|
||||||
// We need to decide what to do about loading of separate presets (just print preset, just filament preset etc).
|
// We need to decide what to do about loading of separate presets (just print preset, just filament preset etc).
|
||||||
// As of now only the full configs are supported here.
|
// As of now only the full configs are supported here.
|
||||||
if (!m_print_config.empty())
|
if (!m_print_config.empty())
|
||||||
gui->mainframe->load_config(m_print_config);
|
gui->mainframe->load_config(m_print_config);
|
||||||
#endif
|
#endif
|
||||||
if (! load_configs.empty())
|
if (!load_configs.empty())
|
||||||
// Load the last config to give it a name at the UI. The name of the preset may be later
|
// Load the last config to give it a name at the UI. The name of the preset may be later
|
||||||
// changed by loading an AMF or 3MF.
|
// changed by loading an AMF or 3MF.
|
||||||
//FIXME this is not strictly correct, as one may pass a print/filament/printer profile here instead of a full config.
|
//FIXME this is not strictly correct, as one may pass a print/filament/printer profile here instead of a full config.
|
||||||
gui->mainframe->load_config_file(load_configs.back());
|
gui->mainframe->load_config_file(load_configs.back());
|
||||||
// If loading a 3MF file, the config is loaded from the last one.
|
// If loading a 3MF file, the config is loaded from the last one.
|
||||||
if (! m_input_files.empty())
|
if (!m_input_files.empty())
|
||||||
gui->plater()->load_files(m_input_files, true, true);
|
gui->plater()->load_files(m_input_files, true, true);
|
||||||
if (! m_extra_config.empty())
|
if (!m_extra_config.empty())
|
||||||
gui->mainframe->load_config(m_extra_config);
|
gui->mainframe->load_config(m_extra_config);
|
||||||
|
#if ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
|
}
|
||||||
|
#endif // ENABLE_GCODE_VIEWER_AS_STANDALONE_APPLICATION
|
||||||
});
|
});
|
||||||
int result = wxEntry(argc, argv);
|
int result = wxEntry(argc, argv);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#include "GCodeReader.hpp"
|
#include "GCodeReader.hpp"
|
||||||
#include <boost/algorithm/string/classification.hpp>
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
#include <boost/algorithm/string/split.hpp>
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#if ENABLE_GCODE_VIEWER
|
||||||
|
#include <boost/nowide/fstream.hpp>
|
||||||
|
#endif // ENABLE_GCODE_VIEWER
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
@ -113,7 +116,11 @@ void GCodeReader::update_coordinates(GCodeLine &gline, std::pair<const char*, co
|
||||||
|
|
||||||
void GCodeReader::parse_file(const std::string &file, callback_t callback)
|
void GCodeReader::parse_file(const std::string &file, callback_t callback)
|
||||||
{
|
{
|
||||||
|
#if ENABLE_GCODE_VIEWER
|
||||||
|
boost::nowide::ifstream f(file);
|
||||||
|
#else
|
||||||
std::ifstream f(file);
|
std::ifstream f(file);
|
||||||
|
#endif // ENABLE_GCODE_VIEWER
|
||||||
std::string line;
|
std::string line;
|
||||||
#if ENABLE_GCODE_VIEWER
|
#if ENABLE_GCODE_VIEWER
|
||||||
m_parsing_file = true;
|
m_parsing_file = true;
|
||||||
|
|
|
@ -228,7 +228,6 @@ public:
|
||||||
memDC.SelectObject(wxNullBitmap);
|
memDC.SelectObject(wxNullBitmap);
|
||||||
SetBmp(bitmap);
|
SetBmp(bitmap);
|
||||||
}
|
}
|
||||||
wxYield();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetBmp(wxBitmap& bmp)
|
void SetBmp(wxBitmap& bmp)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue