Merge branch 'master' of https://github.com/prusa3d/Slic3r into et_canvas_gui_refactoring

This commit is contained in:
Enrico Turri 2019-03-18 08:23:05 +01:00
commit 131193a682
14 changed files with 490 additions and 158 deletions

View file

@ -15,6 +15,7 @@
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/nowide/cenv.hpp>
#include <boost/nowide/iostream.hpp>
#include <boost/nowide/fstream.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/format.hpp>
@ -713,11 +714,8 @@ bool DynamicConfig::read_cli(int argc, char** argv, t_config_option_keys* extra,
// Look for the cli -> option mapping.
const auto it = opts.find(token);
if (it == opts.end()) {
printf("Warning: unknown option --%s\n", token.c_str());
// instead of continuing, return false to caller
// to stop execution and print usage
return false;
//continue;
boost::nowide::cerr << "Unknown option --" << token.c_str() << std::endl;
return false;
}
const t_config_option_key opt_key = it->second;
const ConfigOptionDef &optdef = this->def()->options.at(opt_key);
@ -725,8 +723,8 @@ bool DynamicConfig::read_cli(int argc, char** argv, t_config_option_keys* extra,
// look for it in the next token.
if (optdef.type != coBool && optdef.type != coBools && value.empty()) {
if (i == (argc-1)) {
printf("No value supplied for --%s\n", token.c_str());
continue;
boost::nowide::cerr << "No value supplied for --" << token.c_str() << std::endl;
return false;
}
value = argv[++ i];
}
@ -759,7 +757,10 @@ bool DynamicConfig::read_cli(int argc, char** argv, t_config_option_keys* extra,
static_cast<ConfigOptionString*>(opt_base)->value = value;
} else {
// Any scalar value of a type different from Bool and String.
this->set_deserialize(opt_key, value, false);
if (! this->set_deserialize(opt_key, value, false)) {
boost::nowide::cerr << "Invalid value supplied for --" << token.c_str() << std::endl;
return false;
}
}
}
return true;

View file

@ -716,7 +716,7 @@ public:
assert(it != m_heads.end());
const Head& h = it->second;
assert(h.pillar_id >= 0 && h.pillar_id < long(m_pillars.size()));
return m_pillars[size_t(h.pillar_id)];
return pillar(h.pillar_id);
}
template<class...Args> const Junction& add_junction(Args&&... args) {
@ -755,6 +755,10 @@ public:
return m_compact_bridges;
}
template<class T> inline
typename std::enable_if<std::is_integral<T>::value, const Pillar&>::type
pillar(T id) const { assert(id >= 0); return m_pillars.at(size_t(id)); }
const Pad& create_pad(const TriangleMesh& object_supports,
const ExPolygons& baseplate,
const PoolConfig& cfg) {
@ -1242,12 +1246,14 @@ class SLASupportTree::Algorithm {
}
// For connecting a head to a nearby pillar.
bool connect_to_nearpillar(const Head& head, const Pillar& nearpillar) {
if(nearpillar.bridges > m_cfg.max_bridges_on_pillar) return false;
bool connect_to_nearpillar(const Head& head, long nearpillar_id) {
auto nearpillar = [this, nearpillar_id]() { return m_result.pillar(nearpillar_id); };
if(nearpillar().bridges > m_cfg.max_bridges_on_pillar) return false;
Vec3d headjp = head.junction_point();
Vec3d nearjp_u = nearpillar.startpoint();
Vec3d nearjp_l = nearpillar.endpoint();
Vec3d nearjp_u = nearpillar().startpoint();
Vec3d nearjp_l = nearpillar().endpoint();
double r = head.r_back_mm;
double d2d = distance(to_2d(headjp), to_2d(nearjp_u));
@ -1308,7 +1314,7 @@ class SLASupportTree::Algorithm {
}
m_result.add_bridge(bridgestart, bridgeend, r);
m_result.increment_bridges(nearpillar);
m_result.increment_bridges(nearpillar());
return true;
}
@ -1336,8 +1342,7 @@ class SLASupportTree::Algorithm {
if(nearest_id >= 0) {
auto nearpillarID = unsigned(nearest_id);
if(nearpillarID < m_result.pillars().size()) {
const Pillar& nearpillar = m_result.pillars()[nearpillarID];
if(!connect_to_nearpillar(head, nearpillar)) {
if(!connect_to_nearpillar(head, nearpillarID)) {
nearest_id = -1; // continue searching
spindex.remove(ne); // without the current pillar
}
@ -1649,7 +1654,7 @@ public:
// central position where the pillar can be placed. this way
// the weight is distributed more effectively on the pillar.
const Pillar& centerpillar = m_result.head_pillar(cidx);
auto centerpillarID = m_result.head_pillar(cidx).id;
for(auto c : cl) { m_thr();
if(c == cidx) continue;
@ -1657,7 +1662,7 @@ public:
auto& sidehead = m_result.head(c);
sidehead.transform();
if(!connect_to_nearpillar(sidehead, centerpillar) &&
if(!connect_to_nearpillar(sidehead, centerpillarID) &&
!search_pillar_and_connect(sidehead))
{
Vec3d pstart = sidehead.junction_point();
@ -1859,7 +1864,7 @@ public:
}
for(auto pillid : modelpillars) {
auto& pillar = m_result.pillars()[pillid];
auto& pillar = m_result.pillar(pillid);
m_pillar_index.insert(pillar.endpoint(), pillid);
}
}
@ -1886,7 +1891,7 @@ public:
{
Vec3d qp = el.first;
const Pillar& pillar = m_result.pillars()[el.second];
const Pillar& pillar = m_result.pillar(el.second);
unsigned neighbors = m_cfg.pillar_cascade_neighbors;
@ -1946,15 +1951,15 @@ public:
size_t pillarcount = m_result.pillars().size();
for(size_t pid = 0; pid < pillarcount; pid++) {
const Pillar& pillar = m_result.pillars()[pid];
auto pillar = [this, pid]() { return m_result.pillar(pid); };
unsigned needpillars = 0;
if(pillar.bridges > m_cfg.max_bridges_on_pillar) needpillars = 3;
else if(pillar.links < 2 && pillar.height > H2) {
if(pillar().bridges > m_cfg.max_bridges_on_pillar) needpillars = 3;
else if(pillar().links < 2 && pillar().height > H2) {
// Not enough neighbors to support this pillar
needpillars = 2 - pillar.links;
needpillars = 2 - pillar().links;
}
else if(pillar.links < 1 && pillar.height > H1) {
else if(pillar().links < 1 && pillar().height > H1) {
// No neighbors could be found and the pillar is too long.
needpillars = 1;
}
@ -1963,7 +1968,7 @@ public:
bool found = false;
double alpha = 0; // goes to 2Pi
double r = 2 * m_cfg.base_radius_mm;
Vec3d pillarsp = pillar.startpoint();
Vec3d pillarsp = pillar().startpoint();
Vec3d sp(pillarsp(X), pillarsp(Y), pillarsp(Z) - r);
std::vector<bool> tv(needpillars, false);
std::vector<Vec3d> spts(needpillars);
@ -1976,7 +1981,7 @@ public:
s(X) += std::cos(a) * r;
s(Y) += std::sin(a) * r;
spts[n] = s;
auto hr = bridge_mesh_intersect(s, {0, 0, -1}, pillar.r);
auto hr = bridge_mesh_intersect(s, {0, 0, -1}, pillar().r);
tv[n] = std::isinf(hr.distance());
}
@ -1991,33 +1996,33 @@ public:
if(found) for(unsigned n = 0; n < needpillars; n++) {
Vec3d s = spts[n]; double gnd = m_result.ground_level;
Pillar p(s, Vec3d(s(X), s(Y), gnd), pillar.r);
Pillar p(s, Vec3d(s(X), s(Y), gnd), pillar().r);
p.add_base(m_cfg.base_height_mm, m_cfg.base_radius_mm);
if(interconnect(pillar, p)) {
if(interconnect(pillar(), p)) {
Pillar& pp = m_result.add_pillar(p);
m_pillar_index.insert(pp.endpoint(), unsigned(pp.id));
m_result.add_junction(s, pillar.r);
m_result.add_junction(s, pillar().r);
double t = bridge_mesh_intersect(pillarsp,
dirv(pillarsp, s),
pillar.r);
pillar().r);
if(distance(pillarsp, s) < t)
m_result.add_bridge(pillarsp, s, pillar.r);
m_result.add_bridge(pillarsp, s, pillar().r);
if(pillar.endpoint()(Z) > m_result.ground_level)
m_result.add_junction(pillar.endpoint(), pillar.r);
if(pillar().endpoint()(Z) > m_result.ground_level)
m_result.add_junction(pillar().endpoint(), pillar().r);
newpills.emplace_back(pp.id);
m_result.increment_links(pillar);
m_result.increment_links(pillar());
}
}
if(!newpills.empty()) {
for(auto it = newpills.begin(), nx = std::next(it);
nx != newpills.end(); ++it, ++nx) {
const Pillar& itpll = m_result.pillars()[size_t(*it)];
const Pillar& nxpll = m_result.pillars()[size_t(*nx)];
const Pillar& itpll = m_result.pillar(*it);
const Pillar& nxpll = m_result.pillar(*nx);
if(interconnect(itpll, nxpll)) {
m_result.increment_links(itpll);
m_result.increment_links(nxpll);

View file

@ -523,6 +523,8 @@ bool CLI::setup(int argc, char **argv)
// If any option is unsupported, print usage and abort immediately.
t_config_option_keys opt_order;
if (! m_config.read_cli(argc, argv, &m_input_files, &opt_order)) {
// Separate error message reported by the CLI parser from the help.
boost::nowide::cerr << std::endl;
this->print_help();
return false;
}
@ -615,7 +617,7 @@ std::string CLI::output_filepath(const Model &model, IO::ExportFormat format) co
};
auto proposed_path = boost::filesystem::path(model.propose_export_file_name_and_path(ext));
// use --output when available
std::string cmdline_param = m_config.opt_string("output", false);
std::string cmdline_param = m_config.opt_string("output");
if (! cmdline_param.empty()) {
// if we were supplied a directory, use it and append our automatically generated filename
boost::filesystem::path cmdline_path(cmdline_param);

View file

@ -38,7 +38,7 @@ static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_eve
text += wxString("<font size=\"5\"><b>") + (snapshot_active ? _(L("Active: ")) : "") +
Utils::format_local_date_time(snapshot.time_captured) + ": " + format_reason(snapshot.reason);
if (! snapshot.comment.empty())
text += " (" + snapshot.comment + ")";
text += " (" + wxString::FromUTF8(snapshot.comment.data()) + ")";
text += "</b></font><br>";
// End of row header.
text += _(L("slic3r version")) + ": " + snapshot.slic3r_version_captured.to_string() + "<br>";

View file

@ -1954,7 +1954,8 @@ void GLGizmoSlaSupports::render_points(const GLCanvas3D::Selection& selection, b
bool GLGizmoSlaSupports::is_mesh_update_necessary() const
{
return (m_state == On) && (m_model_object != m_old_model_object) && (m_model_object != nullptr) && !m_model_object->instances.empty();
return ((m_state == On) && (m_model_object != nullptr) && !m_model_object->instances.empty())
&& ((m_model_object != m_old_model_object) || m_V.size()==0);
//if (m_state != On || !m_model_object || m_model_object->instances.empty() || ! m_instance_matrix.isApprox(m_source_data.matrix))
// return false;

View file

@ -148,9 +148,6 @@ void config_wizard(int reason)
_(L("Please check and fix your object list.")),
_(L("Attention!")));
}
// Load the currently selected preset into the GUI, update the preset selection box.
// wxGetApp().load_current_presets(); // #ys_FIXME_to_delete presets are loaded now in select_preset function
}
// opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element)

View file

@ -95,7 +95,7 @@ bool GUI_App::OnInit()
wxCHECK_MSG(m_imgui->init(), false, "Failed to initialize ImGui");
#endif // ENABLE_IMGUI
SetAppName("Slic3rPE-alpha");
SetAppName("Slic3rPE-beta");
SetAppDisplayName("Slic3r Prusa Edition");
// Slic3r::debugf "wxWidgets version %s, Wx version %s\n", wxVERSION_STRING, wxVERSION;

View file

@ -51,8 +51,6 @@ public:
int get_extruder_idx() const { return extruder_idx; }
void check_selection();
std::string selected_preset_name;
private:
typedef std::size_t Marker;
enum { LABEL_ITEM_MARKER = 0x4d };

View file

@ -879,8 +879,7 @@ size_t PresetCollection::update_compatible_internal(const Preset &active_printer
// Hide the
void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui)
{
if (ui == nullptr ||
ui->selected_preset_name == this->get_selected_preset().name)
if (ui == nullptr)
return;
// Otherwise fill in the list from scratch.
@ -951,8 +950,6 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui)
ui->SetSelection(selected_preset_item);
ui->SetToolTip(ui->GetString(selected_preset_item));
ui->Thaw();
ui->selected_preset_name = this->get_selected_preset().name;
}
size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompatible)

View file

@ -1436,8 +1436,7 @@ bool PresetBundle::parse_color(const std::string &scolor, unsigned char *rgb_out
void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::PresetComboBox *ui)
{
if (ui == nullptr || this->printers.get_edited_preset().printer_technology() == ptSLA ||
this->filament_presets.size() <= idx_extruder ||
ui->selected_preset_name == this->filaments.find_preset(this->filament_presets[idx_extruder])->name)
this->filament_presets.size() <= idx_extruder )
return;
unsigned char rgb[3];
@ -1526,8 +1525,6 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr
ui->SetSelection(selected_preset_item);
ui->SetToolTip(ui->GetString(selected_preset_item));
ui->Thaw();
ui->selected_preset_name = this->filaments.find_preset(this->filament_presets[idx_extruder])->name;
}
void PresetBundle::set_default_suppressed(bool default_suppressed)

View file

@ -2594,7 +2594,7 @@ void Tab::select_preset(std::string preset_name)
} else {
if (current_dirty)
m_presets->discard_current_changes();
m_presets->select_preset_by_name(preset_name, false);
const bool is_selected = m_presets->select_preset_by_name(preset_name, false);
// Mark the print & filament enabled if they are compatible with the currently selected preset.
// The following method should not discard changes of current print or filament presets on change of a printer profile,
// if they are compatible with the current printer.
@ -2603,6 +2603,28 @@ void Tab::select_preset(std::string preset_name)
// Initialize the UI from the current preset.
if (printer_tab)
static_cast<TabPrinter*>(this)->update_pages();
if (!is_selected && printer_tab)
{
/* There is a case, when :
* after Config Wizard applying we try to select previously selected preset, but
* in a current configuration this one:
* 1. doesn't exist now,
* 2. have another printer_technology
* So, it is necessary to update list of dependent tabs
* to the corresponding printer_technology
*/
const PrinterTechnology printer_technology = m_presets->get_edited_preset().printer_technology();
if (printer_technology == ptFFF && m_dependent_tabs.front() != Preset::Type::TYPE_PRINT ||
printer_technology == ptSLA && m_dependent_tabs.front() != Preset::Type::TYPE_SLA_PRINT )
{
m_dependent_tabs.clear();
if (printer_technology == ptFFF)
m_dependent_tabs = { Preset::Type::TYPE_PRINT, Preset::Type::TYPE_FILAMENT };
else
m_dependent_tabs = { Preset::Type::TYPE_SLA_PRINT, Preset::Type::TYPE_SLA_MATERIAL };
}
}
load_current_preset();
}
}