ENH: Tolerance of the connectors in mm instead of percents

github issue #1644

Change-Id: I7d7bd02f7b695108abbcbdb0c077d2c1ce911af4
(cherry picked from commit fd89cbdba2bd4a9808d43e8ad2d68b60d076ddb8)
This commit is contained in:
zhimin.zeng 2023-04-21 15:35:45 +08:00 committed by Lane.Wei
parent 2b9f3c9912
commit c720e1eb0f
4 changed files with 40 additions and 15 deletions

View File

@ -734,6 +734,8 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
{
int volume_id;
int type;
float radius;
float height;
float r_tolerance;
float h_tolerance;
};
@ -1938,7 +1940,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
for (auto connector : cut_object_info->second.connectors) {
assert(0 <= connector.volume_id && connector.volume_id <= int(model_object->volumes.size()));
model_object->volumes[connector.volume_id]->cut_info =
ModelVolume::CutInfo(CutConnectorType(connector.type), connector.r_tolerance, connector.h_tolerance, true);
ModelVolume::CutInfo(CutConnectorType(connector.type), connector.radius, connector.height, connector.r_tolerance, connector.h_tolerance, true);
}
}
}
@ -2341,6 +2343,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
if (cut_connector.first != "connector") continue;
pt::ptree connector_tree = cut_connector.second;
CutObjectInfo::Connector connector = {connector_tree.get<int>("<xmlattr>.volume_id"), connector_tree.get<int>("<xmlattr>.type"),
connector_tree.get<float>("<xmlattr>.radius", 0.f), connector_tree.get<float>("<xmlattr>.height", 0.f),
connector_tree.get<float>("<xmlattr>.r_tolerance"), connector_tree.get<float>("<xmlattr>.h_tolerance")};
connectors.emplace_back(connector);
}
@ -7124,6 +7127,8 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
pt::ptree &connectors_tree = obj_tree.add("connectors.connector", "");
connectors_tree.put("<xmlattr>.volume_id", volume_idx);
connectors_tree.put("<xmlattr>.type", int(volume->cut_info.connector_type));
connectors_tree.put("<xmlattr>.radius", volume->cut_info.radius);
connectors_tree.put("<xmlattr>.height", volume->cut_info.height);
connectors_tree.put("<xmlattr>.r_tolerance", volume->cut_info.radius_tolerance);
connectors_tree.put("<xmlattr>.h_tolerance", volume->cut_info.height_tolerance);
}

View File

@ -1694,7 +1694,7 @@ void ModelObject::apply_cut_connectors(const std::string &name)
// Transform the new modifier to be aligned inside the instance
new_volume->set_transformation(translate_transform * connector.rotation_m * scale_transform);
new_volume->cut_info = {connector.attribs.type, connector.radius_tolerance, connector.height_tolerance};
new_volume->cut_info = {connector.attribs.type, connector.radius, connector.height, connector.radius_tolerance, connector.height_tolerance};
new_volume->name = name + "-" + std::to_string(++connector_id);
}
cut_id.increase_connectors_cnt(cut_connectors.size());
@ -2736,11 +2736,23 @@ void ModelVolume::apply_tolerance()
Vec3d sf = get_scaling_factor();
// make a "hole" wider
sf[X] *= 1. + double(cut_info.radius_tolerance);
sf[Y] *= 1. + double(cut_info.radius_tolerance);
double size_scale = 1.f;
if (abs(cut_info.radius - 0) < EPSILON) // For compatibility with old files
size_scale = 1.f + double(cut_info.radius_tolerance);
else
size_scale = (double(cut_info.radius) + double(cut_info.radius_tolerance)) / double(cut_info.radius);
sf[X] *= size_scale;
sf[Y] *= size_scale;
// make a "hole" dipper
sf[Z] *= 1. + double(cut_info.height_tolerance);
double height_scale = 1.f;
if (abs(cut_info.height - 0) < EPSILON) // For compatibility with old files
height_scale = 1.f + double(cut_info.height_tolerance);
else
height_scale = (double(cut_info.height) + double(cut_info.height_tolerance)) / double(cut_info.height);
sf[Z] *= height_scale;
set_scaling_factor(sf);
}

View File

@ -836,12 +836,15 @@ public:
bool is_connector{false};
bool is_processed{true};
CutConnectorType connector_type{CutConnectorType::Plug};
float radius{0.f};
float height{0.f};
float radius_tolerance{0.f}; // [0.f : 1.f]
float height_tolerance{0.f}; // [0.f : 1.f]
CutInfo() = default;
CutInfo(CutConnectorType type, float rad_tolerance, float h_tolerance, bool processed = false)
: is_connector(true), is_processed(processed), connector_type(type), radius_tolerance(rad_tolerance), height_tolerance(h_tolerance)
CutInfo(CutConnectorType type, float radius_, float height_, float rad_tolerance, float h_tolerance, bool processed = false)
: is_connector(true), is_processed(processed), connector_type(type)
, radius(radius_), height(height_), radius_tolerance(rad_tolerance), height_tolerance(h_tolerance)
{}
void set_processed() { is_processed = true; }

View File

@ -1728,11 +1728,13 @@ bool GLGizmoAdvancedCut::render_combo(const std::string &label, const std::vecto
bool GLGizmoAdvancedCut::render_slider_double_input(const std::string &label, float &value_in, float &tolerance_in)
{
// -------- [ ] -------- [ ]
// slider_with + item_in_gap + first_input_width + item_out_gap + slider_with + item_in_gap + second_input_width
double slider_with = 0.24 * m_editing_window_width; // m_control_width * 0.35;
double item_in_gap = 0.01 * m_editing_window_width;
double item_out_gap = 0.02 * m_editing_window_width;
double first_input_width = 0.33 * m_editing_window_width;
double second_input_width = 0.15 * m_editing_window_width;
double item_out_gap = 0.01 * m_editing_window_width;
double first_input_width = 0.29 * m_editing_window_width;
double second_input_width = 0.29 * m_editing_window_width;
ImGui::AlignTextToFramePadding();
m_imgui->text(label);
@ -1770,18 +1772,21 @@ bool GLGizmoAdvancedCut::render_slider_double_input(const std::string &label, fl
ImGui::SameLine(left_width);
ImGui::PushItemWidth(slider_with);
float old_tolerance, tolerance = old_tolerance = tolerance_in * 100.f;
std::string format_t = tolerance_in < 0.f ? " " : "%.f %%";
float tolerance = tolerance_in;
if (m_imperial_units)
tolerance *= float(units_mm_to_in);
float old_tolerance = tolerance;
//std::string format_t = tolerance_in < 0.f ? " " : "%.f %%";
float min_tolerance = tolerance_in < 0.f ? UndefMinVal : 0.f;
m_imgui->bbl_slider_float_style(("##tolerance_" + label).c_str(), &tolerance, min_tolerance, 20.f, format_t.c_str(), 1.f, true, _L("Tolerance"));
m_imgui->bbl_slider_float_style(("##tolerance_" + label).c_str(), &tolerance, min_tolerance, 2.f, format.c_str(), 1.f, true, _L("Tolerance"));
left_width += (slider_with + item_in_gap);
ImGui::SameLine(left_width);
ImGui::PushItemWidth(second_input_width);
ImGui::BBLDragFloat(("##tolerance_input_" + label).c_str(), &tolerance, 0.05f, min_tolerance, 20.f, format_t.c_str());
ImGui::BBLDragFloat(("##tolerance_input_" + label).c_str(), &tolerance, 0.05f, min_tolerance, 2.f, format.c_str());
tolerance_in = tolerance * 0.01f;
tolerance_in = tolerance * float(m_imperial_units ? units_in_to_mm : 1.0);
return !is_approx(old_val, value) || !is_approx(old_tolerance, tolerance);
}