png export recovered

This commit is contained in:
tamasmeszaros 2018-08-27 16:58:20 +02:00
parent 1c4574d42e
commit b990b36da7

View File

@ -260,124 +260,111 @@ void PrintController::slice()
void PrintController::slice_to_png() void PrintController::slice_to_png()
{ {
std::vector<ExPolygons> ground_layers; using Pointf3 = Vec3d;
ground_layers.reserve(print_->objects.size());
for(auto o : print_->objects) { auto exd = query_png_export_data();
ModelObject *mo = o->model_object();
ground_layers.emplace_back(); if(exd.zippath.empty()) return;
sla::ground_layer(mo->mesh(), ground_layers.back());
auto presetbundle = GUI::get_preset_bundle();
assert(presetbundle);
auto conf = presetbundle->full_config();
conf.validate();
try {
print_->apply_config(conf);
print_->validate();
} catch(std::exception& e) {
report_issue(IssueType::ERR, e.what(), "Error");
return;
} }
for(auto& lyr : ground_layers) { // TODO: copy the model and work with the copy only
TriangleMesh mesh; bool correction = false;
sla::create_base_pool(lyr, mesh); if(exd.corr_x != 1.0 || exd.corr_y != 1.0 || exd.corr_z != 1.0) {
mesh.write_ascii("out.stl"); correction = true;
print_->invalidate_all_steps();
for(auto po : print_->objects) {
po->model_object()->scale(
Pointf3(exd.corr_x, exd.corr_y, exd.corr_z)
);
po->model_object()->invalidate_bounding_box();
po->reload_model_instances();
po->invalidate_all_steps();
}
} }
// Turn back the correction scaling on the model.
auto scale_back = [this, correction, exd]() {
if(correction) { // scale the model back
print_->invalidate_all_steps();
for(auto po : print_->objects) {
po->model_object()->scale(
Pointf3(1.0/exd.corr_x, 1.0/exd.corr_y, 1.0/exd.corr_z)
);
po->model_object()->invalidate_bounding_box();
po->reload_model_instances();
po->invalidate_all_steps();
}
}
};
// auto exd = query_png_export_data(); auto print_bb = print_->bounding_box();
Vec2d punsc = unscale(print_bb.size());
// if(exd.zippath.empty()) return; // If the print does not fit into the print area we should cry about it.
if(px(punsc) > exd.width_mm || py(punsc) > exd.height_mm) {
std::stringstream ss;
// auto presetbundle = GUI::get_preset_bundle(); ss << _(L("Print will not fit and will be truncated!")) << "\n"
<< _(L("Width needed: ")) << px(punsc) << " mm\n"
<< _(L("Height needed: ")) << py(punsc) << " mm\n";
// assert(presetbundle); if(!report_issue(IssueType::WARN_Q, ss.str(), _(L("Warning")))) {
scale_back();
return;
}
}
// auto conf = presetbundle->full_config(); // std::async(supports_asynch()? std::launch::async : std::launch::deferred,
// [this, exd, scale_back]()
// {
// conf.validate(); auto pri = create_progress_indicator(
200, _(L("Slicing to zipped png files...")));
// try { try {
// print_->apply_config(conf); pri->update(0, _(L("Slicing...")));
// print_->validate(); slice(pri);
// } catch(std::exception& e) { } catch (std::exception& e) {
// report_issue(IssueType::ERR, e.what(), "Error"); pri->cancel();
// return; report_issue(IssueType::ERR, e.what(), _(L("Exception occured")));
// } scale_back();
return;
}
// // TODO: copy the model and work with the copy only auto pbak = print_->progressindicator;
// bool correction = false; print_->progressindicator = pri;
// if(exd.corr_x != 1.0 || exd.corr_y != 1.0 || exd.corr_z != 1.0) {
// correction = true;
// print_->invalidate_all_steps();
// for(auto po : print_->objects) { try {
// po->model_object()->scale( print_to<FilePrinterFormat::PNG>( *print_, exd.zippath,
// Pointf3(exd.corr_x, exd.corr_y, exd.corr_z) exd.width_mm, exd.height_mm,
// ); exd.width_px, exd.height_px,
// po->model_object()->invalidate_bounding_box(); exd.exp_time_s, exd.exp_time_first_s);
// po->reload_model_instances();
// po->invalidate_all_steps();
// }
// }
// // Turn back the correction scaling on the model. } catch (std::exception& e) {
// auto scale_back = [this, correction, exd]() { pri->cancel();
// if(correction) { // scale the model back report_issue(IssueType::ERR, e.what(), _(L("Exception occured")));
// print_->invalidate_all_steps(); }
// for(auto po : print_->objects) {
// po->model_object()->scale(
// Pointf3(1.0/exd.corr_x, 1.0/exd.corr_y, 1.0/exd.corr_z)
// );
// po->model_object()->invalidate_bounding_box();
// po->reload_model_instances();
// po->invalidate_all_steps();
// }
// }
// };
// auto print_bb = print_->bounding_box(); print_->progressindicator = pbak;
scale_back();
// // If the print does not fit into the print area we should cry about it. // });
// if(unscale(print_bb.size().x) > exd.width_mm ||
// unscale(print_bb.size().y) > exd.height_mm) {
// std::stringstream ss;
// ss << _(L("Print will not fit and will be truncated!")) << "\n"
// << _(L("Width needed: ")) << unscale(print_bb.size().x) << " mm\n"
// << _(L("Height needed: ")) << unscale(print_bb.size().y) << " mm\n";
// if(!report_issue(IssueType::WARN_Q, ss.str(), _(L("Warning")))) {
// scale_back();
// return;
// }
// }
//// std::async(supports_asynch()? std::launch::async : std::launch::deferred,
//// [this, exd, scale_back]()
//// {
// auto pri = create_progress_indicator(
// 200, _(L("Slicing to zipped png files...")));
// try {
// pri->update(0, _(L("Slicing...")));
// slice(pri);
// } catch (std::exception& e) {
// pri->cancel();
// report_issue(IssueType::ERR, e.what(), _(L("Exception occured")));
// scale_back();
// return;
// }
// auto pbak = print_->progressindicator;
// print_->progressindicator = pri;
// try {
// print_to<FilePrinterFormat::PNG>( *print_, exd.zippath,
// exd.width_mm, exd.height_mm,
// exd.width_px, exd.height_px,
// exd.exp_time_s, exd.exp_time_first_s);
// } catch (std::exception& e) {
// pri->cancel();
// report_issue(IssueType::ERR, e.what(), _(L("Exception occured")));
// }
// print_->progressindicator = pbak;
// scale_back();
//// });
} }
void IProgressIndicator::message_fmt( void IProgressIndicator::message_fmt(