Removed display_flip_xy and added display_orientation instead.

When starting Slic3r and the profile is FDM type than it yields an assertion failure for wx. See Tab::update_page_tree_visibility() line 2371
This commit is contained in:
tamasmeszaros 2018-12-13 12:42:45 +01:00
parent 1dad58e60c
commit 310adc18c6
8 changed files with 75 additions and 26 deletions

View file

@ -2389,12 +2389,14 @@ void PrintConfigDef::init_sla_params()
def->min = 100; def->min = 100;
def->default_value = new ConfigOptionInt(1440); def->default_value = new ConfigOptionInt(1440);
def = this->add("display_flip_xy", coBool); def = this->add("display_orientation", coEnum);
def->label = ("Flip X and Y axis"); def->label = L("Display orientation");
def->tooltip = L("Flip X and Y axis in the output raster"); def->tooltip = L("Display orientation");
def->cli = "display-flip-xy=i"; def->cli = "display-orientation=s";
def->min = 0; def->enum_keys_map = &ConfigOptionEnum<SLADisplayOrientation>::get_enum_values();
def->default_value = new ConfigOptionBool(true); def->enum_values.push_back("Landscape");
def->enum_values.push_back("Portrait");
def->default_value = new ConfigOptionEnum<SLADisplayOrientation>(sladoPortrait);
def = this->add("printer_correction", coFloats); def = this->add("printer_correction", coFloats);
def->full_label = L("Printer scaling correction"); def->full_label = L("Printer scaling correction");

View file

@ -56,6 +56,11 @@ enum FilamentType {
ftPLA, ftABS, ftPET, ftHIPS, ftFLEX, ftSCAFF, ftEDGE, ftNGEN, ftPVA ftPLA, ftABS, ftPET, ftHIPS, ftFLEX, ftSCAFF, ftEDGE, ftNGEN, ftPVA
}; };
enum SLADisplayOrientation {
sladoLandscape,
sladoPortrait
};
template<> inline const t_config_enum_values& ConfigOptionEnum<PrinterTechnology>::get_enum_values() { template<> inline const t_config_enum_values& ConfigOptionEnum<PrinterTechnology>::get_enum_values() {
static t_config_enum_values keys_map; static t_config_enum_values keys_map;
if (keys_map.empty()) { if (keys_map.empty()) {
@ -148,6 +153,15 @@ template<> inline const t_config_enum_values& ConfigOptionEnum<FilamentType>::ge
return keys_map; return keys_map;
} }
template<> inline const t_config_enum_values& ConfigOptionEnum<SLADisplayOrientation>::get_enum_values() {
static const t_config_enum_values keys_map = {
{ "Landscape", sladoLandscape},
{ "Portrait", sladoPortrait}
};
return keys_map;
}
// Defines each and every confiuration option of Slic3r, including the properties of the GUI dialogs. // Defines each and every confiuration option of Slic3r, including the properties of the GUI dialogs.
// Does not store the actual values, but defines default values. // Does not store the actual values, but defines default values.
class PrintConfigDef : public ConfigDef class PrintConfigDef : public ConfigDef
@ -1035,7 +1049,7 @@ public:
ConfigOptionFloat display_height; ConfigOptionFloat display_height;
ConfigOptionInt display_pixels_x; ConfigOptionInt display_pixels_x;
ConfigOptionInt display_pixels_y; ConfigOptionInt display_pixels_y;
ConfigOptionBool display_flip_xy; ConfigOptionEnum<SLADisplayOrientation> display_orientation;
ConfigOptionFloats printer_correction; ConfigOptionFloats printer_correction;
protected: protected:
void initialize(StaticCacheBase &cache, const char *base_ptr) void initialize(StaticCacheBase &cache, const char *base_ptr)
@ -1047,7 +1061,7 @@ protected:
OPT_PTR(display_height); OPT_PTR(display_height);
OPT_PTR(display_pixels_x); OPT_PTR(display_pixels_x);
OPT_PTR(display_pixels_y); OPT_PTR(display_pixels_y);
OPT_PTR(display_flip_xy); OPT_PTR(display_orientation);
OPT_PTR(printer_correction); OPT_PTR(printer_correction);
} }
}; };

View file

@ -116,6 +116,7 @@ template<> class FilePrinter<FilePrinterFormat::SLA_PNGZIP>
Raster::PixelDim m_pxdim; Raster::PixelDim m_pxdim;
double m_exp_time_s = .0, m_exp_time_first_s = .0; double m_exp_time_s = .0, m_exp_time_first_s = .0;
double m_layer_height = .0; double m_layer_height = .0;
Raster::Origin m_o = Raster::Origin::TOP_LEFT;
std::string createIniContent(const std::string& projectname) { std::string createIniContent(const std::string& projectname) {
double layer_height = m_layer_height; double layer_height = m_layer_height;
@ -145,19 +146,41 @@ template<> class FilePrinter<FilePrinterFormat::SLA_PNGZIP>
+layerh_str+"+printer=DWARF3\n"; +layerh_str+"+printer=DWARF3\n";
} }
// The PNG format has its origin in the top left corner.
static const Raster::Origin ORIGIN = Raster::Origin::TOP_LEFT;
public: public:
enum RasterOrientation {
RO_LANDSCAPE,
RO_PORTRAIT
};
// We will play with the raster's coordinate origin parameter. When the
// printer should print in landscape mode it should have the Y axis flipped
// because the layers should be displayed upside down. PNG has its
// coordinate origin in the top-left corner so normally the Raster objects
// should be instantiated with the TOP_LEFT flag. However, in landscape mode
// we do want the pictures to be upside down so we will make BOTTOM_LEFT
// type rasters and the PNG format will do the flipping automatically.
// In case of portrait images, we have to rotate the image by a 90 degrees
// and flip the y axis. To get the correct upside-down orientation of the
// slice images, we can flip the x and y coordinates of the input polygons
// and do the Y flipping of the image. This will generate the correct
// orientation in portrait mode.
inline FilePrinter(double width_mm, double height_mm, inline FilePrinter(double width_mm, double height_mm,
unsigned width_px, unsigned height_px, unsigned width_px, unsigned height_px,
double layer_height, double layer_height,
double exp_time, double exp_time_first): double exp_time, double exp_time_first,
RasterOrientation ro = RO_PORTRAIT):
m_res(width_px, height_px), m_res(width_px, height_px),
m_pxdim(width_mm/width_px, height_mm/height_px), m_pxdim(width_mm/width_px, height_mm/height_px),
m_exp_time_s(exp_time), m_exp_time_s(exp_time),
m_exp_time_first_s(exp_time_first), m_exp_time_first_s(exp_time_first),
m_layer_height(layer_height) m_layer_height(layer_height),
// Here is the trick with the orientation.
m_o(ro == RO_LANDSCAPE? Raster::Origin::BOTTOM_LEFT :
Raster::Origin::TOP_LEFT )
{ {
} }
@ -177,12 +200,12 @@ public:
inline void begin_layer(unsigned lyr) { inline void begin_layer(unsigned lyr) {
if(m_layers_rst.size() <= lyr) m_layers_rst.resize(lyr+1); if(m_layers_rst.size() <= lyr) m_layers_rst.resize(lyr+1);
m_layers_rst[lyr].first.reset(m_res, m_pxdim, ORIGIN); m_layers_rst[lyr].first.reset(m_res, m_pxdim, m_o);
} }
inline void begin_layer() { inline void begin_layer() {
m_layers_rst.emplace_back(); m_layers_rst.emplace_back();
m_layers_rst.front().first.reset(m_res, m_pxdim, ORIGIN); m_layers_rst.front().first.reset(m_res, m_pxdim, m_o);
} }
inline void finish_layer(unsigned lyr_id) { inline void finish_layer(unsigned lyr_id) {

View file

@ -392,7 +392,7 @@ struct Pillar {
void add_base(double height = 3, double radius = 2) { void add_base(double height = 3, double radius = 2) {
if(height <= 0) return; if(height <= 0) return;
assert(steps > 0); assert(steps >= 0);
auto last = int(steps - 1); auto last = int(steps - 1);
if(radius < r ) radius = r; if(radius < r ) radius = r;
@ -1293,7 +1293,7 @@ bool SLASupportTree::generate(const PointSet &points,
return distance(Vec2d(p1(X), p1(Y)), Vec2d(p2(X), p2(Y))); return distance(Vec2d(p1(X), p1(Y)), Vec2d(p2(X), p2(Y)));
}); });
assert(lcid > 0); assert(lcid >= 0);
auto cid = unsigned(lcid); auto cid = unsigned(lcid);
cl_centroids.push_back(unsigned(cid)); cl_centroids.push_back(unsigned(cid));
@ -1454,7 +1454,7 @@ bool SLASupportTree::generate(const PointSet &points,
SpatIndex innerring; SpatIndex innerring;
for(unsigned i : newring) { for(unsigned i : newring) {
const Pillar& pill = result.head_pillar(gndidx[i]); const Pillar& pill = result.head_pillar(gndidx[i]);
assert(pill.id > 0); assert(pill.id >= 0);
innerring.insert(pill.endpoint, unsigned(pill.id)); innerring.insert(pill.endpoint, unsigned(pill.id));
} }

View file

@ -413,6 +413,12 @@ sla::SupportConfig make_support_cfg(const SLAPrintObjectConfig& c) {
return scfg; return scfg;
} }
void swapXY(ExPolygon& expoly) {
for(auto& p : expoly.contour.points) std::swap(p(X), p(Y));
for(auto& h : expoly.holes) for(auto& p : h.points) std::swap(p(X), p(Y));
}
} }
void SLAPrint::process() void SLAPrint::process()
@ -715,7 +721,9 @@ void SLAPrint::process()
std::vector<long long> keys; keys.reserve(levels.size()); std::vector<long long> keys; keys.reserve(levels.size());
for(auto& e : levels) keys.emplace_back(e.first); for(auto& e : levels) keys.emplace_back(e.first);
bool flpXY = m_printer_config.display_flip_xy.getBool(); // If the raster has vertical orientation, we will flip the coordinates
bool flpXY = m_printer_config.display_orientation.getInt() ==
SLADisplayOrientation::sladoPortrait;
{ // create a raster printer for the current print parameters { // create a raster printer for the current print parameters
// I don't know any better // I don't know any better
@ -733,7 +741,9 @@ void SLAPrint::process()
if(flpXY) { std::swap(w, h); std::swap(pw, ph); } if(flpXY) { std::swap(w, h); std::swap(pw, ph); }
m_printer.reset(new SLAPrinter(w, h, pw, ph, lh, exp_t, iexp_t)); m_printer.reset(new SLAPrinter(w, h, pw, ph, lh, exp_t, iexp_t,
flpXY? SLAPrinter::RO_PORTRAIT :
SLAPrinter::RO_LANDSCAPE));
} }
// Allocate space for all the layers // Allocate space for all the layers
@ -770,10 +780,7 @@ void SLAPrint::process()
// apply rotation before translation... // apply rotation before translation...
slice.rotate(double(cp.rotation)); slice.rotate(double(cp.rotation));
slice.translate(cp.shift(X), cp.shift(Y)); slice.translate(cp.shift(X), cp.shift(Y));
if(flpXY) { if(flpXY) swapXY(slice);
for(auto& p : slice.contour.points) std::swap(p(X), p(Y));
for(auto& h : slice.holes) for(auto& p : h.points) std::swap(p(X), p(Y));
}
printer.draw_polygon(slice, level_id); printer.draw_polygon(slice, level_id);
} }
} }

View file

@ -554,6 +554,9 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
else if (opt_key.compare("host_type") == 0) { else if (opt_key.compare("host_type") == 0) {
ret = static_cast<int>(config.option<ConfigOptionEnum<PrintHostType>>(opt_key)->value); ret = static_cast<int>(config.option<ConfigOptionEnum<PrintHostType>>(opt_key)->value);
} }
else if (opt_key.compare("display_orientation") == 0) {
ret = static_cast<int>(config.option<ConfigOptionEnum<SLADisplayOrientation>>(opt_key)->value);
}
} }
break; break;
case coPoints: case coPoints:

View file

@ -453,7 +453,7 @@ const std::vector<std::string>& Preset::sla_printer_options()
"printer_technology", "printer_technology",
"bed_shape", "max_print_height", "bed_shape", "max_print_height",
"display_width", "display_height", "display_pixels_x", "display_pixels_y", "display_width", "display_height", "display_pixels_x", "display_pixels_y",
"display_flip_xy", "display_orientation",
"printer_correction", "printer_correction",
"printer_notes", "printer_notes",
"inherits" "inherits"

View file

@ -1883,7 +1883,7 @@ void TabPrinter::build_sla()
line.append_option(option); line.append_option(option);
line.append_option(optgroup->get_option("display_pixels_y")); line.append_option(optgroup->get_option("display_pixels_y"));
optgroup->append_line(line); optgroup->append_line(line);
optgroup->append_single_option_line("display_flip_xy"); optgroup->append_single_option_line("display_orientation");
optgroup = page->new_optgroup(_(L("Corrections"))); optgroup = page->new_optgroup(_(L("Corrections")));
line = Line{ m_config->def()->get("printer_correction")->full_label, "" }; line = Line{ m_config->def()->get("printer_correction")->full_label, "" };