72{
73
75
77
78#ifdef __WXGTK__
79
80
81
82 ::setenv("GDK_BACKEND", "x11", true);
83#endif
84
85
86 try {
88 } catch (const std::runtime_error& ex) {
89 std::string caption = std::string(SLIC3R_APP_NAME) + " Error";
90 std::string text = std::string("An error occured while setting up locale.\n") + (
91#if !defined(_WIN32) && !defined(__APPLE__)
92
93 "You may need to reconfigure the missing locales, likely by running the \"locale-gen\" and \"dpkg-reconfigure locales\" commands.\n"
94#endif
95 SLIC3R_APP_NAME " will now terminate.\n\n") + ex.what();
96 #if defined(_WIN32) && defined(SLIC3R_GUI)
98
99 MessageBoxA(NULL, text.c_str(), caption.c_str(), MB_OK | MB_ICONERROR);
100 #endif
101 boost::nowide::cerr << text.c_str() << std::endl;
102 return 1;
103 }
104
105 if (! this->
setup(argc, argv))
106 return 1;
107
110
112
114
118 bool start_downloader = false;
119 bool delete_after_load = false;
120 std::string download_url;
121 bool start_as_gcodeviewer =
122#ifdef _WIN32
123 false;
124#else
125
126 boost::algorithm::iends_with(boost::filesystem::path(argv[0]).filename().string(), "gcodeviewer");
127#endif
128#if ENABLE_GL_CORE_PROFILE
129 std::pair<int, int> opengl_version = { 0, 0 };
130#if ENABLE_OPENGL_DEBUG_OPTION
131 bool opengl_debug = false;
132#endif
133#endif
134
137
138
139 for (auto const &file : load_configs) {
140 if (! boost::filesystem::exists(file)) {
142 continue;
143 } else {
144 boost::nowide::cerr << "No such file: " << file << std::endl;
145 return 1;
146 }
147 }
150 try {
151 config_substitutions = config.
load(file, config_substitution_rule);
152 } catch (std::exception &ex) {
153 boost::nowide::cerr << "Error while reading config file \"" << file << "\": " << ex.what() << std::endl;
154 return 1;
155 }
156 if (! config_substitutions.empty()) {
157 boost::nowide::cout << "The following configuration values were substituted when loading \" << file << \":\n";
159 boost::nowide::cout <<
"\tkey = \"" << subst.opt_def->opt_key <<
"\"\t loaded = \"" << subst.old_value <<
"\tsubstituted = \"" << subst.new_value->
serialize() <<
"\"\n";
160 }
166 boost::nowide::cerr << "Mixing configurations for FFF and SLA technologies" << std::endl;
167 return 1;
168 }
170 }
171
172#if ENABLE_GL_CORE_PROFILE
173
176 start_gui = true;
177 start_as_gcodeviewer = true;
179 }
180
186 boost::nowide::cerr << "Found invalid OpenGL version: " << opengl_version_str << std::endl;
187 opengl_version_str.clear();
188 }
189 }
190
191 if (!opengl_version_str.empty()) {
192 std::vector<std::string> tokens;
193 boost::split(tokens, opengl_version_str, boost::is_any_of("."), boost::token_compress_on);
194 opengl_version.first = std::stoi(tokens[0].c_str());
195 opengl_version.second = std::stoi(tokens[1].c_str());
196 }
197 start_gui = true;
199 }
200
203 start_gui = true;
204#if ENABLE_OPENGL_DEBUG_OPTION
205 opengl_debug = true;
206#endif
208 }
209#else
210
212 if (*it == "gcodeviewer") {
213 start_gui = true;
214 start_as_gcodeviewer = true;
216 break;
217 }
218 }
219#endif
220
221
224 start_as_gcodeviewer = true;
225 break;
226 }
227 if (!start_as_gcodeviewer) {
229 if (boost::starts_with(file, "prusaslicer://")) {
230 start_downloader = true;
231 download_url = file;
232 continue;
233 }
234 if (!boost::filesystem::exists(file)) {
235 boost::nowide::cerr << "No such file: " << file << std::endl;
236 exit(1);
237 }
239 try {
240
243
248 }
250 boost::nowide::cerr << "Mixing configurations for FFF and SLA technologies" << std::endl;
251 return 1;
252 }
253 if (! config_substitutions.substitutions.empty()) {
254 boost::nowide::cout << "The following configuration values were substituted when loading \" << file << \":\n";
256 boost::nowide::cout <<
"\tkey = \"" << subst.opt_def->opt_key <<
"\"\t loaded = \"" << subst.old_value <<
"\tsubstituted = \"" << subst.new_value->
serialize() <<
"\"\n";
257 }
258
261 }
262 catch (std::exception& e) {
263 boost::nowide::cerr << file << ": " << e.what() << std::endl;
264 return 1;
265 }
267 boost::nowide::cerr << "Error: file is empty: " << file << std::endl;
268 continue;
269 }
271 }
272 }
273
274
275
277
279
283
284
285 FullPrintConfig fff_print_config;
286 SLAFullPrintConfig sla_print_config;
287
288
292 } else {
294 sla_print_config.output_filename_format.value = "[input_filename_base].sl1";
295
296
297
298 double w = sla_print_config.display_width.getFloat();
299 double h = sla_print_config.display_height.getFloat();
301
304 }
305
306 {
308 if (! validity.empty()) {
309 boost::nowide::cerr << "Error: The composite configation is not valid: " << validity << std::endl;
310 return 1;
311 }
312 }
313
314
315 bool user_center_specified = false;
319
321 if (opt_key == "merge") {
325 m.add_object(*o);
326
331 else
333 }
335 m_models.emplace_back(std::move(m));
336 } else if (opt_key == "duplicate") {
338 const bool all_objects_have_instances = std::none_of(
341 );
342
345
346 try {
347 if (dups > 1) {
348
349 duplicate(model,
size_t(dups), bed, arrange_cfg);
350 } else {
352 }
353 } catch (std::exception &ex) {
354 boost::nowide::cerr << "error: " << ex.what() << std::endl;
355 return 1;
356 }
357 }
358 } else if (opt_key == "duplicate_grid") {
360 const int x = ints.size() > 0 ? ints.at(0) : 1;
361 const int y = ints.size() > 1 ? ints.at(1) : 1;
362 const double distance = fff_print_config.duplicate_distance.
value;
365 } else if (opt_key == "center") {
366 user_center_specified = true;
369
371
372
373
376
377 bbox.
merge(model_object->instance_bounding_box(0, false));
379 for (
ModelInstance *model_instance : model_object->instances)
380 model_instance->set_offset(
Z, model_instance->get_offset(
Z) - bbox.
min.z());
381 }
382 } else if (opt_key == "align_xy") {
386
388 }
389 } else if (opt_key == "dont_arrange") {
390
391 } else if (opt_key == "ensure_on_bed") {
392
393 } else if (opt_key == "rotate") {
395 for (auto &o : model.objects)
396
398 } else if (opt_key == "rotate_x") {
400 for (auto &o : model.objects)
401
403 } else if (opt_key == "rotate_y") {
405 for (auto &o : model.objects)
406
408 } else if (opt_key == "scale") {
410 for (auto &o : model.objects)
411
413 } else if (opt_key == "scale_to_fit") {
415 if (opt.x() <= 0 || opt.y() <= 0 || opt.z() <= 0) {
416 boost::nowide::cerr << "--scale-to-fit requires a positive volume" << std::endl;
417 return 1;
418 }
420 for (auto &o : model.objects)
421
422 o->scale_to_fit(opt);
423 } else if (opt_key == "cut" || opt_key == "cut_x" || opt_key == "cut_y") {
424 std::vector<Model> new_models;
427 size_t num_objects = model.
objects.size();
428 for (size_t i = 0; i < num_objects; ++ i) {
429
430#if 0
431 if (opt_key == "cut_x") {
433 } else if (opt_key == "cut_y") {
435 } else if (opt_key == "cut") {
437 }
438#else
439
442#endif
444 }
445 }
446
447
449
452 }
453#if 0
454 else if (opt_key == "cut_grid") {
455 std::vector<Model> new_models;
458 mesh.repair();
459
461 size_t i = 0;
466 o->input_file += "_" + std::to_string(i++);
467 delete m;
468 }
469 }
470
471
473
476 }
477#endif
478 else if (opt_key == "split") {
480 size_t num_objects = model.
objects.size();
481 for (size_t i = 0; i < num_objects; ++ i) {
483 model.
objects.front()->split(&new_objects);
485 }
486 }
487 } else if (opt_key == "repair") {
488
489
490
491
492 } else if (opt_key == "delete-after-load") {
493 delete_after_load = true;
494 } else {
495 boost::nowide::cerr << "error: option not implemented yet: " << opt_key << std::endl;
496 return 1;
497 }
498 }
499
500
501
504 for (auto &o : model.objects)
505 o->ensure_on_bed();
506
507
509 if (opt_key == "help") {
511 } else if (opt_key == "help_fff") {
513 } else if (opt_key == "help_sla") {
515 } else if (opt_key == "save") {
516
517
519 } else if (opt_key == "info") {
520
524 }
525 } else if (opt_key == "export_stl") {
527 model.add_default_instances();
529 return 1;
530 } else if (opt_key == "export_obj") {
532 model.add_default_instances();
534 return 1;
535 } else if (opt_key == "export_amf") {
537 return 1;
538 } else if (opt_key == "export_3mf") {
540 return 1;
541 } else if (opt_key == "export_gcode" || opt_key == "export_sla" || opt_key == "slice") {
543 boost::nowide::cerr << "error: cannot export G-code for an FFF configuration" << std::endl;
544 return 1;
546 boost::nowide::cerr << "error: cannot export SLA slices for a SLA configuration" << std::endl;
547 return 1;
548 }
549
550
552 bool make_copy = &opt_key != &
m_actions.back();
554 if (make_copy)
555 model_copy = model_in;
556 Model &model = make_copy ? model_copy : model_in;
557
558
559
560
566 {
568 printf(
"%3d%s %s\n", s.
percent,
"% =>", s.
text.c_str());
569 });
570
573 if (user_center_specified) {
576 } else
578 }
580 for (auto* mo : model.objects)
581 fff_print.auto_assign_extruders(mo);
582 }
584 std::string err = print->
validate();
585 if (! err.empty()) {
586 boost::nowide::cerr << err << std::endl;
587 return 1;
588 }
590 boost::nowide::cout << "Nothing to print for " << outfile << " . Either the print is empty or no object is fully inside the print volume." << std::endl;
591 else
592 try {
593 std::string outfile_final;
596
597 outfile = fff_print.
export_gcode(outfile,
nullptr,
nullptr);
599 } else {
601
604 }
605 if (outfile != outfile_final) {
607 boost::nowide::cerr << "Renaming file " << outfile << " to " << outfile_final << " failed" << std::endl;
608 return 1;
609 }
610 outfile = outfile_final;
611 }
612
614 boost::nowide::cout << "Slicing result exported to " << outfile << std::endl;
615 } catch (const std::exception &ex) {
616 boost::nowide::cerr << ex.what() << std::endl;
617 return 1;
618 }
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649 }
650 } else {
651 boost::nowide::cerr << "error: option not supported yet: " << opt_key << std::endl;
652 return 1;
653 }
654 }
655
656
657 if (start_gui) {
658#ifdef SLIC3R_GUI
659 #if !defined(_WIN32) && !defined(__APPLE__)
660
661 const char *display = boost::nowide::getenv("DISPLAY");
662
663
664 if (! (display && *display)) {
665
666 boost::nowide::cerr << "DISPLAY not set, GUI mode not available." << std::endl << std::endl;
668
669 return 1;
670 }
671 #endif
682#if ENABLE_GL_CORE_PROFILE
683#if ENABLE_OPENGL_DEBUG_OPTION
684 params.opengl_version = opengl_version;
685 params.opengl_debug = opengl_debug;
686#endif
687#endif
689#else
690
692
693 return (argc == 0) ? 0 : 1;
694#endif
695 }
696
697 return 0;
698}
void serialize(Archive &ar, FacenamesSerializer &t, const std::uint32_t version)
Definition GLGizmoEmboss.cpp:1562
static PrinterTechnology get_printer_technology(const DynamicConfig &config)
Definition PrusaSlicer.cpp:65
int scale(const int val)
Definition WipeTowerDialog.cpp:14
PointType min
Definition BoundingBox.hpp:16
Definition BoundingBox.hpp:221
std::vector< std::string > m_input_files
Definition PrusaSlicer.hpp:28
bool has_print_action() const
Definition PrusaSlicer.hpp:41
DynamicPrintConfig m_extra_config
Definition PrusaSlicer.hpp:27
std::vector< std::string > m_actions
Definition PrusaSlicer.hpp:29
bool export_models(IO::ExportFormat format)
Exports loaded models to a file of the specified format, according to the options affecting output fi...
Definition PrusaSlicer.cpp:850
bool setup(int argc, char **argv)
Definition PrusaSlicer.cpp:700
void print_help(bool include_print_options=false, PrinterTechnology printer_technology=ptAny) const
Prints usage of the CLI.
Definition PrusaSlicer.cpp:805
DynamicPrintConfig m_print_config
Definition PrusaSlicer.hpp:26
std::vector< std::string > m_transforms
Definition PrusaSlicer.hpp:30
ConfigSubstitutions load(const std::string &file, ForwardCompatibilitySubstitutionRule compatibility_rule)
Definition Config.cpp:723
void apply(const ConfigBase &other, bool ignore_nonexistent=false)
Definition Config.hpp:2209
void save(const std::string &file) const
Definition Config.cpp:1030
double & opt_float(const t_config_option_key &opt_key)
Definition Config.hpp:2281
ConfigOption * option(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2169
int & opt_int(const t_config_option_key &opt_key)
Definition Config.hpp:2286
T * opt(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2196
Definition Config.hpp:1501
Definition Config.hpp:761
Definition Config.hpp:1311
Definition Config.hpp:1200
T value
Definition Config.hpp:305
Definition Config.hpp:879
Definition PrintConfig.hpp:212
std::string validate()
Definition PrintConfig.cpp:4427
void normalize_fdm()
Definition PrintConfig.cpp:4332
void delete_object(size_t idx)
Definition Model.cpp:233
static Model read_from_file(const std::string &input_file, DynamicPrintConfig *config=nullptr, ConfigSubstitutionContext *config_substitutions=nullptr, LoadAttributes options=LoadAttribute::AddDefaultInstances)
Definition Model.cpp:104
void print_info() const
Definition Model.hpp:1337
ModelObjectPtrs objects
Definition Model.hpp:1254
void translate(coordf_t x, coordf_t y, coordf_t z)
Definition Model.hpp:1320
ModelObject * add_object()
Definition Model.cpp:189
bool add_default_instances()
Definition Model.cpp:318
bool center_instances_around_point(const Vec2d &point)
Definition Model.cpp:360
BoundingBoxf3 bounding_box_exact() const
Definition Model.cpp:336
TriangleMesh mesh() const
Definition Model.cpp:382
Definition Model.hpp:1120
ModelVolume * add_volume(const TriangleMesh &mesh)
Definition Model.cpp:717
Printing involves slicing and export of device dependent instructions.
Definition PrintBase.hpp:405
virtual bool empty() const =0
virtual ApplyStatus apply(const Model &model, DynamicPrintConfig config)=0
virtual std::string validate(std::vector< std::string > *warnings=nullptr) const
Definition PrintBase.hpp:421
const DynamicPrintConfig & full_print_config() const
Definition PrintBase.hpp:523
void set_status_callback(status_callback_type cb)
Definition PrintBase.hpp:490
std::string output_filepath(const std::string &path, const std::string &filename_base=std::string()) const
Definition PrintBase.cpp:84
const PrintStatistics & print_statistics() const
Definition Print.hpp:632
std::string export_gcode(const std::string &path_template, GCodeProcessorResult *result, ThumbnailsGeneratorCallback thumbnail_cb=nullptr)
Definition Print.cpp:984
This class is the high level FSM for the SLA printing process.
Definition SLAPrint.hpp:440
const SLAPrintStatistics & print_statistics() const
Definition SLAPrint.hpp:495
void export_print(const std::string &fname, const std::string &projectname="")
Definition SLAPrint.hpp:541
Definition TriangleMesh.hpp:88
if(!(yy_init))
Definition lexer.c:1190
int exists(char *filename)
Definition loaddrv.c:45
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() min(const half &a, const half &b)
Definition Half.h:507
const Scalar & y
Definition MathFunctions.h:552
std::vector< std::string > input_files
Definition GUI_Init.hpp:30
bool start_as_gcodeviewer
Definition GUI_Init.hpp:32
int argc
Definition GUI_Init.hpp:22
bool delete_after_load
Definition GUI_Init.hpp:34
DynamicPrintConfig extra_config
Definition GUI_Init.hpp:29
int GUI_Run(GUI_InitParams ¶ms)
Definition GUI_Init.cpp:35
bool start_downloader
Definition GUI_Init.hpp:33
char ** argv
Definition GUI_Init.hpp:23
std::string download_url
Definition GUI_Init.hpp:35
std::vector< std::string > load_configs
Definition GUI_Init.hpp:28
Definition GUI_Init.hpp:21
void translation_transform(Transform3d &transform, const Vec3d &translation)
Definition Geometry.cpp:328
ForwardCompatibilitySubstitutionRule
Definition Config.hpp:217
BoundingBox scaled(const BoundingBoxf &bb)
Definition BoundingBox.hpp:240
bool run_post_process_scripts(std::string &src_path, bool make_copy, const std::string &host, std::string &output_name, const DynamicPrintConfig &config)
Definition PostProcessor.cpp:198
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:51
void duplicate(Model &model, Slic3r::arrangement::ArrangePolygons &copies, VirtualBedFn vfn)
Definition ModelArrange.cpp:57
PrinterTechnology
Definition Config.hpp:205
@ ptSLA
Definition Config.hpp:209
@ ptFFF
Definition Config.hpp:207
@ ptUnknown
Definition Config.hpp:211
void save_main_thread_id()
Definition Thread.cpp:197
bool arrange_objects(Model &model, const TBed &bed, const ArrangeParams ¶ms, VirtualBedFn vfn=throw_if_out_of_bed)
Definition ModelArrange.hpp:34
bool is_gcode_file(const std::string &path)
Definition utils.cpp:783
bool set_current_thread_name(const char *thread_name)
Definition Thread.cpp:178
Points get_bed_shape(const DynamicPrintConfig &config)
Definition PrintConfig.cpp:4936
std::vector< ConfigSubstitution > ConfigSubstitutions
Definition Config.hpp:246
std::error_code rename_file(const std::string &from, const std::string &to)
Definition utils.cpp:468
std::vector< ModelObject * > ModelObjectPtrs
Definition Model.hpp:105
@ Y
Definition libslic3r.h:99
@ Z
Definition libslic3r.h:100
@ X
Definition libslic3r.h:98
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:58
double min_object_distance(const ConfigBase &cfg)
Definition PrintConfig.cpp:4306
Definition Config.hpp:240
double deg2rad(double deg)
Definition agg_basics.h:271
void nowide_filesystem()
Instal utf8_codecvt facet into boost::filesystem::path such all char strings are interpreted as utf-8...
Definition filesystem.hpp:18
TMultiShape< PolygonImpl > merge(const TMultiShape< PolygonImpl > &shapes)
Definition geometries.hpp:259
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297
double distance(const P &p1, const P &p2)
Definition geometry_traits.hpp:329
S::iterator begin(S &sh, const PathTag &)
Definition geometry_traits.hpp:614
S::iterator end(S &sh, const PathTag &)
Definition geometry_traits.hpp:620
void rotate(Slic3r::ExPolygon &sh, const Radians &rads)
Definition geometries.hpp:248
Definition Config.hpp:251
static const std::vector< std::string > precore_str
Definition GUI_Init.hpp:14
static const std::vector< std::string > core_str
Definition GUI_Init.hpp:13
Definition PrintBase.hpp:458
int percent
Definition PrintBase.hpp:464
std::string text
Definition PrintBase.hpp:465
std::string finalize_output_path(const std::string &path_in) const
Definition Print.cpp:1585
std::string finalize_output_path(const std::string &path_in) const
Definition SLAPrint.cpp:1147
Definition Arrange.hpp:130
coord_t min_obj_distance
The minimum distance which is allowed for any pair of items on the print bed in any direction.
Definition Arrange.hpp:134
Representing an unbounded bed.
Definition Arrange.hpp:16