mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-09-23 05:43:16 +08:00
FIX: Disable print button when gcode has conflict
Also fix a crash bug due to setStarted and setDone. Change-Id: Ib9b069fe4b7e5d1fc359f48e44b4032dd8249428 (cherry picked from commit 9ef190ed3ecd66d12617ad96e927ff34251395a2)
This commit is contained in:
parent
e002885efc
commit
d72b4c1bfe
@ -201,6 +201,7 @@ ConflictRet ConflictChecker::find_inter_of_lines(const LineWithIDs &lines)
|
|||||||
|
|
||||||
ConflictRet ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectPtrs objs) // find the first intersection point of lines in different objects
|
ConflictRet ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectPtrs objs) // find the first intersection point of lines in different objects
|
||||||
{
|
{
|
||||||
|
if (objs.size() <= 1) { return {}; }
|
||||||
LinesBucketQueue conflictQueue;
|
LinesBucketQueue conflictQueue;
|
||||||
for (PrintObject *obj : objs) {
|
for (PrintObject *obj : objs) {
|
||||||
auto layers = getAllLayersExtrusionPathsFromObject(obj);
|
auto layers = getAllLayersExtrusionPathsFromObject(obj);
|
||||||
|
@ -90,6 +90,29 @@ namespace Slic3r {
|
|||||||
|
|
||||||
struct GCodeProcessorResult
|
struct GCodeProcessorResult
|
||||||
{
|
{
|
||||||
|
//BBS
|
||||||
|
struct ConflictResult
|
||||||
|
{
|
||||||
|
bool conflicted;
|
||||||
|
std::string obj1Name;
|
||||||
|
std::string obj2Name;
|
||||||
|
|
||||||
|
void set(const std::string &o1, const std::string &o2)
|
||||||
|
{
|
||||||
|
conflicted = true;
|
||||||
|
obj1Name = o1;
|
||||||
|
obj2Name = o2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
conflicted = false;
|
||||||
|
obj1Name.clear();
|
||||||
|
obj2Name.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConflictResult() = default;
|
||||||
|
ConflictResult(const ConflictResult &) = default;
|
||||||
|
}conflict_result;
|
||||||
|
|
||||||
struct SettingsIds
|
struct SettingsIds
|
||||||
{
|
{
|
||||||
|
@ -1669,20 +1669,20 @@ void Print::process(bool use_cache)
|
|||||||
// BBS
|
// BBS
|
||||||
if(!m_no_check)
|
if(!m_no_check)
|
||||||
{
|
{
|
||||||
this->set_started(psConflictCheck);
|
|
||||||
this->set_status(70, L("Checking gcode path conflicts."));
|
|
||||||
using Clock = std::chrono::high_resolution_clock;
|
using Clock = std::chrono::high_resolution_clock;
|
||||||
auto startTime = Clock::now();
|
auto startTime = Clock::now();
|
||||||
auto conflictRes = ConflictChecker::find_inter_of_lines_in_diff_objs(m_objects);
|
auto conflictRes = ConflictChecker::find_inter_of_lines_in_diff_objs(m_objects);
|
||||||
auto endTime = Clock::now();
|
auto endTime = Clock::now();
|
||||||
volatile double seconds = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() / (double) 1000;
|
volatile double seconds = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() / (double) 1000;
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "gcode path conflicts check takes " << seconds << " secs.";
|
||||||
|
|
||||||
if (conflictRes.has_value()) {
|
if (conflictRes.has_value()) {
|
||||||
|
m_conflict_result.set(conflictRes.value()._obj1, conflictRes.value()._obj2);
|
||||||
auto objName1 = conflictRes.value()._obj1->m_model_object->name;
|
auto objName1 = conflictRes.value()._obj1->m_model_object->name;
|
||||||
auto objName2 = conflictRes.value()._obj2->m_model_object->name;
|
auto objName2 = conflictRes.value()._obj2->m_model_object->name;
|
||||||
//throw Slic3r::SlicingError((boost::format(L("Conflicts of gcode paths have been found. Please separate the conflicted objects (%s + %s) farther.")) % objName1% objName2).str());
|
} else {
|
||||||
this->active_step_add_warning(PrintStateBase::WarningLevel::CRITICAL, (boost::format(L("Conflicts of gcode paths have been found. Please separate the conflicted objects (%s <-> %s) farther.")) % objName1 % objName2).str());
|
m_conflict_result.reset();
|
||||||
}
|
}
|
||||||
this->set_done(psConflictCheck);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << "Slicing process finished." << log_memory_info();
|
BOOST_LOG_TRIVIAL(info) << "Slicing process finished." << log_memory_info();
|
||||||
@ -1713,6 +1713,12 @@ std::string Print::export_gcode(const std::string& path_template, GCodeProcessor
|
|||||||
const Vec3d origin = this->get_plate_origin();
|
const Vec3d origin = this->get_plate_origin();
|
||||||
gcode.set_gcode_offset(origin(0), origin(1));
|
gcode.set_gcode_offset(origin(0), origin(1));
|
||||||
gcode.do_export(this, path.c_str(), result, thumbnail_cb);
|
gcode.do_export(this, path.c_str(), result, thumbnail_cb);
|
||||||
|
//BBS
|
||||||
|
if (m_conflict_result.conflicted) {
|
||||||
|
result->conflict_result.set(m_conflict_result.obj1->m_model_object->name, m_conflict_result.obj2->m_model_object->name);
|
||||||
|
} else {
|
||||||
|
result->conflict_result.reset();
|
||||||
|
}
|
||||||
return path.c_str();
|
return path.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,6 +774,28 @@ private:
|
|||||||
Vec3d m_origin;
|
Vec3d m_origin;
|
||||||
//BBS: modified_count
|
//BBS: modified_count
|
||||||
int m_modified_count {0};
|
int m_modified_count {0};
|
||||||
|
//BBS
|
||||||
|
struct ConflictResult
|
||||||
|
{
|
||||||
|
bool conflicted;
|
||||||
|
PrintObject *obj1;
|
||||||
|
PrintObject *obj2;
|
||||||
|
//TODO
|
||||||
|
//the actual loaction
|
||||||
|
|
||||||
|
void set(PrintObject *o1, PrintObject *o2)
|
||||||
|
{
|
||||||
|
conflicted = true;
|
||||||
|
obj1 = o1;
|
||||||
|
obj2 = o2;
|
||||||
|
}
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
conflicted = false;
|
||||||
|
obj1 = nullptr;
|
||||||
|
obj2 = nullptr;
|
||||||
|
}
|
||||||
|
}m_conflict_result;
|
||||||
|
|
||||||
// To allow GCode to set the Print's GCodeExport step status.
|
// To allow GCode to set the Print's GCodeExport step status.
|
||||||
friend class GCode;
|
friend class GCode;
|
||||||
|
@ -1097,6 +1097,9 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
|
|||||||
m_layers_slider->set_as_dirty();
|
m_layers_slider->set_as_dirty();
|
||||||
m_moves_slider->set_as_dirty();
|
m_moves_slider->set_as_dirty();
|
||||||
|
|
||||||
|
//BBS
|
||||||
|
m_conflict_result = gcode_result.conflict_result;
|
||||||
|
|
||||||
//BBS: add mutex for protection of gcode result
|
//BBS: add mutex for protection of gcode result
|
||||||
gcode_result.unlock();
|
gcode_result.unlock();
|
||||||
//BBS: add logs
|
//BBS: add logs
|
||||||
|
@ -722,6 +722,9 @@ public:
|
|||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//BBS
|
||||||
|
GCodeProcessorResult::ConflictResult m_conflict_result;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<int> m_plater_extruder;
|
std::vector<int> m_plater_extruder;
|
||||||
bool m_gl_data_initialized{ false };
|
bool m_gl_data_initialized{ false };
|
||||||
|
@ -2706,6 +2706,7 @@ void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, co
|
|||||||
//BBS: always load shell at preview, do this in load_shells
|
//BBS: always load shell at preview, do this in load_shells
|
||||||
//m_gcode_viewer.update_shells_color_by_extruder(m_config);
|
//m_gcode_viewer.update_shells_color_by_extruder(m_config);
|
||||||
_set_warning_notification_if_needed(EWarning::ToolpathOutside);
|
_set_warning_notification_if_needed(EWarning::ToolpathOutside);
|
||||||
|
_set_warning_notification_if_needed(EWarning::GCodeConflict);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_gcode_viewer.refresh(gcode_result, str_tool_colors);
|
m_gcode_viewer.refresh(gcode_result, str_tool_colors);
|
||||||
@ -8785,7 +8786,10 @@ void GLCanvas3D::_set_warning_notification_if_needed(EWarning warning)
|
|||||||
else {
|
else {
|
||||||
if (wxGetApp().is_editor()) {
|
if (wxGetApp().is_editor()) {
|
||||||
if (current_printer_technology() != ptSLA)
|
if (current_printer_technology() != ptSLA)
|
||||||
show = m_gcode_viewer.has_data() && !m_gcode_viewer.is_contained_in_bed();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8824,6 +8828,13 @@ void GLCanvas3D::_set_warning_notification(EWarning warning, bool state)
|
|||||||
std::string text;
|
std::string text;
|
||||||
ErrorType error = ErrorType::PLATER_WARNING;
|
ErrorType error = ErrorType::PLATER_WARNING;
|
||||||
switch (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(L("Conflicts of gcode paths have been found. Please separate the conflicted objects farther (%s <-> %s).")) % objName1 % objName2).str();
|
||||||
|
error = ErrorType::SLICING_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case EWarning::ObjectOutside: text = _u8L("An object is layed over the boundary of plate."); break;
|
case EWarning::ObjectOutside: text = _u8L("An object is layed over the boundary of plate."); break;
|
||||||
case EWarning::ToolpathOutside: text = _u8L("A G-code path goes beyond the boundary of plate."); error = ErrorType::SLICING_ERROR; break;
|
case EWarning::ToolpathOutside: text = _u8L("A G-code path goes beyond the boundary of plate."); error = ErrorType::SLICING_ERROR; break;
|
||||||
// BBS: remove _u8L() for SLA
|
// BBS: remove _u8L() for SLA
|
||||||
|
@ -372,7 +372,8 @@ class GLCanvas3D
|
|||||||
ToolpathOutside,
|
ToolpathOutside,
|
||||||
SlaSupportsOutside,
|
SlaSupportsOutside,
|
||||||
SomethingNotShown,
|
SomethingNotShown,
|
||||||
ObjectClashed
|
ObjectClashed,
|
||||||
|
GCodeConflict
|
||||||
};
|
};
|
||||||
|
|
||||||
class RenderStats
|
class RenderStats
|
||||||
|
@ -381,7 +381,7 @@ public:
|
|||||||
{
|
{
|
||||||
bool result = m_slice_result_valid;
|
bool result = m_slice_result_valid;
|
||||||
if (result)
|
if (result)
|
||||||
result = m_gcode_result ? (!m_gcode_result->toolpath_outside) : false;
|
result = m_gcode_result ? (!m_gcode_result->toolpath_outside && !m_gcode_result->conflict_result.conflicted) : false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user