ENH: show the layer and height of conflict position

Change-Id: If80e81b5556f5afc3228a00edc2593bd8cfe63e4
(cherry picked from commit 895e0f2ecf8e259cfdb7c27081b767bfbaa3ffb6)
This commit is contained in:
manch1n 2023-04-14 20:23:46 +08:00 committed by Lane.Wei
parent 98f3aaa4bf
commit 87eb0f3665
9 changed files with 99 additions and 90 deletions

View file

@ -1095,6 +1095,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
//BBS
m_conflict_result = gcode_result.conflict_result;
if (m_conflict_result) { m_conflict_result.value().layer = m_layers.get_l_at(m_conflict_result.value()._height); }
//BBS: add mutex for protection of gcode result
gcode_result.unlock();

View file

@ -490,6 +490,11 @@ class GCodeViewer
std::vector<Endpoints>& get_endpoints() { return m_endpoints; }
double get_z_at(unsigned int id) const { return (id < m_zs.size()) ? m_zs[id] : 0.0; }
Endpoints get_endpoints_at(unsigned int id) const { return (id < m_endpoints.size()) ? m_endpoints[id] : Endpoints(); }
int get_l_at(double z) const
{
auto iter = std::upper_bound(m_zs.begin(), m_zs.end(), z);
return std::distance(m_zs.begin(), iter);
}
bool operator != (const Layers& other) const {
if (m_zs != other.m_zs)
@ -728,7 +733,7 @@ public:
};
//BBS
GCodeProcessorResult::ConflictResult m_conflict_result;
ConflictResultOpt m_conflict_result;
private:
std::vector<int> m_plater_extruder;

View file

@ -8846,7 +8846,7 @@ void GLCanvas3D::_set_warning_notification_if_needed(EWarning warning)
if (warning == EWarning::ToolpathOutside)
show = m_gcode_viewer.has_data() && !m_gcode_viewer.is_contained_in_bed();
else if (warning==EWarning::GCodeConflict)
show = m_gcode_viewer.has_data() && m_gcode_viewer.is_contained_in_bed() && m_gcode_viewer.m_conflict_result.conflicted;
show = m_gcode_viewer.has_data() && m_gcode_viewer.is_contained_in_bed() && m_gcode_viewer.m_conflict_result.has_value();
}
}
@ -8886,9 +8886,14 @@ void GLCanvas3D::_set_warning_notification(EWarning warning, bool state)
ErrorType error = ErrorType::PLATER_WARNING;
switch (warning) {
case EWarning::GCodeConflict: {
std::string objName1 = m_gcode_viewer.m_conflict_result.obj1Name;
std::string objName2 = m_gcode_viewer.m_conflict_result.obj2Name;
text = (boost::format(_u8L("Conflicts of gcode paths have been found. Please separate the conflicted objects farther (%s <-> %s).")) % objName1 % objName2).str();
if (!m_gcode_viewer.m_conflict_result) { break; }
std::string objName1 = m_gcode_viewer.m_conflict_result.value()._objName1;
std::string objName2 = m_gcode_viewer.m_conflict_result.value()._objName2;
double height = m_gcode_viewer.m_conflict_result.value()._height;
int layer = m_gcode_viewer.m_conflict_result.value().layer;
text = (boost::format(_u8L("Conflicts of gcode paths have been found at layer %d, z = %.2lf mm. Please separate the conflicted objects farther (%s <-> %s).")) % layer %
height % objName1 % objName2)
.str();
error = ErrorType::SLICING_ERROR;
break;
}
@ -8907,6 +8912,26 @@ void GLCanvas3D::_set_warning_notification(EWarning warning, bool state)
if (!wxGetApp().plater())
return;
auto& notification_manager = *wxGetApp().plater()->get_notification_manager();
if (warning == EWarning::GCodeConflict && m_gcode_viewer.m_conflict_result) {
const PrintObject *obj2 = reinterpret_cast<const PrintObject *>(m_gcode_viewer.m_conflict_result.value()._obj2);
auto mo = obj2->model_object();
ObjectID id = mo->id();
auto action_fn = [id](wxEvtHandler *) {
auto &objects = wxGetApp().model().objects;
auto iter = id.id ? std::find_if(objects.begin(), objects.end(), [id](auto o) { return o->id() == id; }) : objects.end();
if (iter != objects.end()) {
wxGetApp().mainframe->select_tab(MainFrame::tp3DEditor);
wxGetApp().obj_list()->select_items({{*iter, nullptr}});
}
return false;
};
auto hypertext = _u8L("Jump to");
hypertext += std::string(" [") + mo->name + "]";
notification_manager.push_notification(NotificationType::PlaterError, NotificationManager::NotificationLevel::ErrorNotificationLevel, _u8L("ERROR:") + "\n" + text,
hypertext, action_fn);
return;
}
switch (error)
{
case PLATER_WARNING:

View file

@ -381,7 +381,7 @@ public:
{
bool result = m_slice_result_valid;
if (result)
result = m_gcode_result ? (!m_gcode_result->toolpath_outside && !m_gcode_result->conflict_result.conflicted) : false;
result = m_gcode_result ? (!m_gcode_result->toolpath_outside && !m_gcode_result->conflict_result.has_value()) : false;
return result;
}