factor out set_extruders() to an STL-style template function. Added set<T> method as well.

This commit is contained in:
Joseph Lenox 2018-07-16 17:10:37 -05:00
parent b0d734e164
commit 11bb5c3117
4 changed files with 44 additions and 30 deletions

View File

@ -233,22 +233,6 @@ GCode::apply_print_config(const PrintConfig &print_config)
this->config.apply(print_config);
}
void
GCode::set_extruders(const std::vector<unsigned int> &extruder_ids)
{
this->writer.set_extruders(extruder_ids);
// enable wipe path generation if any extruder has wipe enabled
this->wipe.enable = false;
for (std::vector<unsigned int>::const_iterator it = extruder_ids.begin();
it != extruder_ids.end(); ++it) {
if (this->config.wipe.get_at(*it)) {
this->wipe.enable = true;
break;
}
}
}
void
GCode::set_origin(const Pointf &pointf)
{

View File

@ -12,6 +12,8 @@
#include "PrintConfig.hpp"
#include "ConditionalGCode.hpp"
#include <string>
#include <vector>
#include <set>
namespace Slic3r {
@ -98,7 +100,30 @@ class GCode {
void set_last_pos(const Point &pos);
bool last_pos_defined() const;
void apply_print_config(const PrintConfig &print_config);
void set_extruders(const std::vector<unsigned int> &extruder_ids);
/// Template function.
template <typename Iter>
void set_extruders(Iter begin, Iter end) {
this->writer.set_extruders(begin, end);
// enable wipe path generation if any extruder has wipe enabled
this->wipe.enable = false;
for (Iter it = begin; it != end; ++it) {
if (this->config.wipe.get_at(*it)) {
this->wipe.enable = true;
break;
}
}
}
template <typename T>
void set_extruders(const std::vector<T> &extruder_ids) {
this->set_extruders(extruder_ids.cbegin(), extruder_ids.cend());
}
template <typename T>
void set_extruders(const std::set<T> &extruder_ids) {
this->set_extruders(extruder_ids.cbegin(), extruder_ids.cend());
}
void set_origin(const Pointf &pointf);
std::string preamble();
std::string notes();

View File

@ -21,18 +21,6 @@ GCodeWriter::apply_print_config(const PrintConfig &print_config)
this->_extrusion_axis = this->config.get_extrusion_axis();
}
void
GCodeWriter::set_extruders(const std::vector<unsigned int> &extruder_ids)
{
for (std::vector<unsigned int>::const_iterator i = extruder_ids.begin(); i != extruder_ids.end(); ++i)
this->extruders.insert( std::pair<unsigned int,Extruder>(*i, Extruder(*i, &this->config)) );
/* we enable support for multiple extruder if any extruder greater than 0 is used
(even if prints only uses that one) since we need to output Tx commands
first extruder has index 0 */
this->multiple_extruders = (*std::max_element(extruder_ids.begin(), extruder_ids.end())) > 0;
}
std::string
GCodeWriter::notes()
{

View File

@ -22,7 +22,24 @@ public:
Extruder* extruder() const { return this->_extruder; }
std::string extrusion_axis() const { return this->_extrusion_axis; }
void apply_print_config(const PrintConfig &print_config);
void set_extruders(const std::vector<unsigned int> &extruder_ids);
template <typename Iter>
void set_extruders(Iter begin, Iter end) {
for (auto i = begin; i != end; ++i)
this->extruders.insert( std::pair<unsigned int,Extruder>(*i, Extruder(*i, &this->config)) );
/* we enable support for multiple extruder if any extruder greater than 0 is used
(even if prints only uses that one) since we need to output Tx commands
first extruder has index 0 */
this->multiple_extruders = (*std::max_element(begin, end)) > 0;
}
template <typename T>
void set_extruders(const std::vector<T> &extruder_ids) { this->set_extruders(extruder_ids.cbegin(), extruder_ids.cend()); }
template <typename T>
void set_extruders(const std::set<T> &extruder_ids) { this->set_extruders(extruder_ids.cbegin(), extruder_ids.cend()); }
/// Write any notes provided by the user as comments in the gcode header.
std::string notes();