Merge branch 'cppgui'

This commit is contained in:
Joseph Lenox 2018-08-05 20:52:49 -05:00
commit 16ec67322a
6 changed files with 99 additions and 9 deletions

View File

@ -305,7 +305,7 @@ set(LIBSLIC3R_DEPENDS
${Boost_LIBRARIES} ${Boost_LIBRARIES}
) )
IF(wxWidgets_FOUND) IF(wxWidgets_FOUND AND Enable_GUI)
MESSAGE("wx found!") MESSAGE("wx found!")
INCLUDE("${wxWidgets_USE_FILE}") INCLUDE("${wxWidgets_USE_FILE}")
@ -379,11 +379,13 @@ IF(wxWidgets_FOUND)
add_test(NAME TestGUI COMMAND gui_test) add_test(NAME TestGUI COMMAND gui_test)
target_link_libraries(gui_test PUBLIC libslic3r slic3r_gui Catch ${wxWidgets_LIBRARIES} ${LIBSLIC3R_DEPENDS} ${OPENGL_LIBRARIES}) target_link_libraries(gui_test PUBLIC libslic3r slic3r_gui Catch ${wxWidgets_LIBRARIES} ${LIBSLIC3R_DEPENDS} ${OPENGL_LIBRARIES})
endif() endif()
ELSE(wxWidgets_FOUND) ELSE(wxWidgets_FOUND AND Enable_GUI)
# For convenience. When we cannot continue, inform the user # For convenience. When we cannot continue, inform the user
MESSAGE("wx not found!") if (Enable_GUI)
MESSAGE("wx not found!")
endif (Enable_GUI)
#skip gui when no wx included #skip gui when no wx included
ENDIF(wxWidgets_FOUND) ENDIF(wxWidgets_FOUND AND Enable_GUI)
target_link_libraries (slic3r libslic3r ${LIBSLIC3R_DEPENDS}) target_link_libraries (slic3r libslic3r ${LIBSLIC3R_DEPENDS})

View File

@ -3,6 +3,7 @@
#include "IO.hpp" #include "IO.hpp"
#include "Model.hpp" #include "Model.hpp"
#include "SLAPrint.hpp" #include "SLAPrint.hpp"
#include "Print.hpp"
#include "TriangleMesh.hpp" #include "TriangleMesh.hpp"
#include "libslic3r.h" #include "libslic3r.h"
#include <cstdio> #include <cstdio>
@ -44,10 +45,16 @@ main(int argc, char **argv)
DynamicPrintConfig print_config; DynamicPrintConfig print_config;
#ifdef USE_WX #ifdef USE_WX
GUI::App *gui = new GUI::App(); if (cli_config.gui) {
GUI::App *gui = new GUI::App();
GUI::App::SetInstance(gui);
wxEntry(argc, argv); GUI::App::SetInstance(gui);
wxEntry(argc, argv);
}
#else
if (cli_config.gui) {
std::cout << "GUI support has not been built." << "\n";
}
#endif #endif
// load config files supplied via --load // load config files supplied via --load
for (const std::string &file : cli_config.load.values) { for (const std::string &file : cli_config.load.values) {
@ -113,6 +120,14 @@ main(int argc, char **argv)
// TODO: handle --merge // TODO: handle --merge
models.push_back(model); models.push_back(model);
} }
if (cli_config.help) {
std::cout << "Slic3r " << SLIC3R_VERSION << " is a STL-to-GCODE translator for RepRap 3D printers" << "\n"
<< "written by Alessandro Ranellucci <aar@cpan.org> - http://slic3r.org/ - https://github.com/slic3r/Slic3r" << "\n"
<< "Git Version " << BUILD_COMMIT << "\n\n"
<< "Usage: slic3r.pl [ OPTIONS ] [ file.stl ] [ file2.stl ] ..." << "\n";
print_cli_options(boost::nowide::cout);
return 0;
}
for (Model &model : models) { for (Model &model : models) {
if (cli_config.info) { if (cli_config.info) {
@ -199,6 +214,23 @@ main(int argc, char **argv)
IO::STL::write(*m, ss.str()); IO::STL::write(*m, ss.str());
delete m; delete m;
} }
} else if (cli_config.slice) {
std::string outfile = cli_config.output.value;
Print print;
model.arrange_objects(print.config.min_object_distance());
model.center_instances_around_point(cli_config.center);
if (outfile.empty()) outfile = model.objects.front()->input_file + ".gcode";
print.apply_config(print_config);
for (auto* mo : model.objects) {
print.auto_assign_extruders(mo);
print.add_model_object(mo);
}
print.validate();
print.export_gcode(outfile);
} else { } else {
boost::nowide::cerr << "error: command not supported" << std::endl; boost::nowide::cerr << "error: command not supported" << std::endl;
return 1; return 1;

View File

@ -376,7 +376,7 @@ SCENARIO( "TriangleMeshSlicer: Cut behavior.") {
} }
} }
} }
#ifdef TEST_PERFORMANCE
TEST_CASE("Regression test for issue #4486 - files take forever to slice") { TEST_CASE("Regression test for issue #4486 - files take forever to slice") {
TriangleMesh mesh; TriangleMesh mesh;
auto config {Slic3r::Config::new_from_defaults()}; auto config {Slic3r::Config::new_from_defaults()};
@ -401,6 +401,7 @@ TEST_CASE("Regression test for issue #4486 - files take forever to slice") {
REQUIRE(timedout == false); REQUIRE(timedout == false);
} }
#endif // TEST_PERFORMANCE
#ifdef BUILD_PROFILE #ifdef BUILD_PROFILE
TEST_CASE("Profile test for issue #4486 - files take forever to slice") { TEST_CASE("Profile test for issue #4486 - files take forever to slice") {

View File

@ -717,6 +717,14 @@ Print::export_gcode(std::ostream& output, bool quiet)
} }
void
Print::export_gcode(const std::string& outfile, bool quiet)
{
std::ofstream outstream(outfile);
this->export_gcode(outstream);
}
bool bool
Print::apply_config(config_ptr config) { Print::apply_config(config_ptr config) {
// dereference the stored pointer and pass the resulting data to apply_config() // dereference the stored pointer and pass the resulting data to apply_config()

View File

@ -1605,6 +1605,7 @@ PrintConfigDef::PrintConfigDef()
def->label = "Threads"; def->label = "Threads";
def->tooltip = "Threads are used to parallelize long-running tasks. Optimal threads number is slightly above the number of available cores/processors."; def->tooltip = "Threads are used to parallelize long-running tasks. Optimal threads number is slightly above the number of available cores/processors.";
def->readonly = true; def->readonly = true;
def->cli = "threads=i";
def->min = 1; def->min = 1;
{ {
unsigned int threads = boost::thread::hardware_concurrency(); unsigned int threads = boost::thread::hardware_concurrency();
@ -1942,6 +1943,24 @@ CLIConfigDef::CLIConfigDef()
def->tooltip = "Slice the model and export slices as 3MF."; def->tooltip = "Slice the model and export slices as 3MF.";
def->cli = "export-3mf"; def->cli = "export-3mf";
def->default_value = new ConfigOptionBool(false); def->default_value = new ConfigOptionBool(false);
def = this->add("slice", coBool);
def->label = "Slice";
def->tooltip = "Slice the model and export gcode.";
def->cli = "slice";
def->default_value = new ConfigOptionBool(false);
def = this->add("help", coBool);
def->label = "Help";
def->tooltip = "Show this help.";
def->cli = "help";
def->default_value = new ConfigOptionBool(false);
def = this->add("gui", coBool);
def->label = "Use GUI";
def->tooltip = "Start the Slic3r GUI.";
def->cli = "gui";
def->default_value = new ConfigOptionBool(false);
def = this->add("info", coBool); def = this->add("info", coBool);
def->label = "Output Model Info"; def->label = "Output Model Info";
@ -1996,8 +2015,27 @@ CLIConfigDef::CLIConfigDef()
def->tooltip = "Scale to fit the given volume."; def->tooltip = "Scale to fit the given volume.";
def->cli = "scale-to-fit"; def->cli = "scale-to-fit";
def->default_value = new ConfigOptionPoint3(Pointf3(0,0,0)); def->default_value = new ConfigOptionPoint3(Pointf3(0,0,0));
def = this->add("center", coPoint3);
def->label = "Center";
def->tooltip = "Center the print around the given center (default: 100, 100).";
def->cli = "center";
def->default_value = new ConfigOptionPoint(Pointf(100,100));
} }
const CLIConfigDef cli_config_def; const CLIConfigDef cli_config_def;
std::ostream&
print_cli_options(std::ostream& out) {
for (const auto& opt : print_config_def.options) {
out << "\t" << std::left << std::setw(40) << std::string("--") + opt.second.cli;
out << "\t" << opt.second.tooltip << "\n";
if (opt.second.default_value != nullptr)
out << "\t" << std::setw(40) << " " << "\t" << " (default: " << opt.second.default_value->serialize() << ")";
out << "\n";
}
std::cerr << std::endl;
return out;
}
} }

View File

@ -659,7 +659,9 @@ class CLIConfig
ConfigOptionBool export_pov; ConfigOptionBool export_pov;
ConfigOptionBool export_svg; ConfigOptionBool export_svg;
ConfigOptionBool export_3mf; ConfigOptionBool export_3mf;
ConfigOptionBool gui;
ConfigOptionBool info; ConfigOptionBool info;
ConfigOptionBool help;
ConfigOptionStrings load; ConfigOptionStrings load;
ConfigOptionString output; ConfigOptionString output;
ConfigOptionFloat rotate; ConfigOptionFloat rotate;
@ -668,6 +670,8 @@ class CLIConfig
ConfigOptionString save; ConfigOptionString save;
ConfigOptionFloat scale; ConfigOptionFloat scale;
ConfigOptionPoint3 scale_to_fit; ConfigOptionPoint3 scale_to_fit;
ConfigOptionPoint center;
ConfigOptionBool slice;
ConfigOptionBool threads; ConfigOptionBool threads;
CLIConfig() : ConfigBase(), StaticConfig() { CLIConfig() : ConfigBase(), StaticConfig() {
@ -684,6 +688,8 @@ class CLIConfig
OPT_PTR(export_pov); OPT_PTR(export_pov);
OPT_PTR(export_svg); OPT_PTR(export_svg);
OPT_PTR(export_3mf); OPT_PTR(export_3mf);
OPT_PTR(gui);
OPT_PTR(help);
OPT_PTR(info); OPT_PTR(info);
OPT_PTR(load); OPT_PTR(load);
OPT_PTR(output); OPT_PTR(output);
@ -693,12 +699,15 @@ class CLIConfig
OPT_PTR(save); OPT_PTR(save);
OPT_PTR(scale); OPT_PTR(scale);
OPT_PTR(scale_to_fit); OPT_PTR(scale_to_fit);
OPT_PTR(slice);
OPT_PTR(threads); OPT_PTR(threads);
return NULL; return NULL;
}; };
}; };
/// Iterate through all of the options and write them to a stream.
std::ostream& print_cli_options(std::ostream& out);
} }
#endif #endif