Remove custom supports/seams after mesh repair

The repair can remove some of the triangles, so the custom data would make no sense.
This will hopefully fix #5458

Also, show a notification with a hyperlink to undo just before the repair.
This commit is contained in:
Lukas Matena 2020-12-14 14:23:05 +01:00
parent 5553762d9c
commit 1249fdb71d
4 changed files with 61 additions and 20 deletions

View File

@ -1011,7 +1011,13 @@ void NotificationManager::push_notification(const std::string& text, int timesta
{
push_notification_data({ NotificationType::CustomNotification, NotificationLevel::RegularNotification, 10, text }, timestamp);
}
void NotificationManager::push_notification(const std::string& text, NotificationManager::NotificationLevel level, int timestamp)
void NotificationManager::push_notification(NotificationType type,
NotificationLevel level,
const std::string& text,
const std::string& hypertext,
std::function<bool(wxEvtHandler*)> callback,
int timestamp)
{
int duration = 0;
switch (level) {
@ -1022,7 +1028,7 @@ void NotificationManager::push_notification(const std::string& text, Notificatio
assert(false);
return;
}
push_notification_data({ NotificationType::CustomNotification, level, duration, text }, timestamp);
push_notification_data({ type, level, duration, text, hypertext, callback }, timestamp);
}
void NotificationManager::push_slicing_error_notification(const std::string& text)
{

View File

@ -67,7 +67,9 @@ enum class NotificationType
// Progress bar instead of text.
ProgressBar,
// Notification, when Color Change G-code is empty and user try to add color change on DoubleSlider.
EmptyColorChangeCode
EmptyColorChangeCode,
// Notification that custom supports/seams were deleted after mesh repair.
CustomSupportsAndSeamRemovedAfterRepair
};
class NotificationManager
@ -97,7 +99,8 @@ public:
void push_notification(const std::string& text, int timestamp = 0);
// Push a NotificationType::CustomNotification with provided notification level and 10s for RegularNotification.
// ErrorNotification and ImportantNotification are never faded out.
void push_notification(const std::string& text, NotificationLevel level, int timestamp = 0);
void push_notification(NotificationType type, NotificationLevel level, const std::string& text, const std::string& hypertext = "",
std::function<bool(wxEvtHandler*)> callback = std::function<bool(wxEvtHandler*)>(), int timestamp = 0);
// Creates Slicing Error notification with a custom text and no fade out.
void push_slicing_error_notification(const std::string& text);
// Creates Slicing Warning notification with a custom text and no fade out.

View File

@ -2124,11 +2124,15 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
if (evt.data.second) {
this->show_action_buttons(this->ready_to_slice);
notification_manager->close_notification_of_type(NotificationType::ExportFinished);
notification_manager->push_notification(format(_L("Successfully unmounted. The device %s(%s) can now be safely removed from the computer."), evt.data.first.name, evt.data.first.path),
NotificationManager::NotificationLevel::RegularNotification);
notification_manager->push_notification(NotificationType::CustomNotification,
NotificationManager::NotificationLevel::RegularNotification,
format(_L("Successfully unmounted. The device %s(%s) can now be safely removed from the computer."), evt.data.first.name, evt.data.first.path)
);
} else {
notification_manager->push_notification(format(_L("Ejecting of device %s(%s) has failed."), evt.data.first.name, evt.data.first.path),
NotificationManager::NotificationLevel::ErrorNotification);
notification_manager->push_notification(NotificationType::CustomNotification,
NotificationManager::NotificationLevel::ErrorNotification,
format(_L("Ejecting of device %s(%s) has failed."), evt.data.first.name, evt.data.first.path)
);
}
});
this->q->Bind(EVT_REMOVABLE_DRIVES_CHANGED, [this, q](RemovableDrivesChangedEvent &) {
@ -3361,10 +3365,38 @@ void Plater::priv::fix_through_netfabb(const int obj_idx, const int vol_idx/* =
if (obj_idx < 0)
return;
Plater::TakeSnapshot snapshot(q, _L("Fix Throught NetFabb"));
size_t snapshot_time = undo_redo_stack().active_snapshot_time();
Plater::TakeSnapshot snapshot(q, _L("Fix through NetFabb"));
fix_model_by_win10_sdk_gui(*model.objects[obj_idx], vol_idx);
sla::reproject_points_and_holes(model.objects[obj_idx]);
ModelObject* mo = model.objects[obj_idx];
// If there are custom supports/seams, remove them. Fixed mesh
// may be different and they would make no sense.
bool paint_removed = false;
for (ModelVolume* mv : mo->volumes) {
paint_removed |= ! mv->supported_facets.empty() || ! mv->seam_facets.empty();
mv->supported_facets.clear();
mv->seam_facets.clear();
}
if (paint_removed) {
// snapshot_time is captured by copy so the lambda knows where to undo/redo to.
notification_manager->push_notification(
NotificationType::CustomSupportsAndSeamRemovedAfterRepair,
NotificationManager::NotificationLevel::RegularNotification,
_u8L("Custom supports and seams were removed after repairing the mesh."),
_u8L("Undo the repair"),
[this, snapshot_time](wxEvtHandler*){
if (undo_redo_stack().has_undo_snapshot(snapshot_time))
undo_redo_to(snapshot_time);
else
notification_manager->push_notification(
_u8L("Cannot undo to before the mesh repair!"));
return true;
});
}
fix_model_by_win10_sdk_gui(*mo, vol_idx);
sla::reproject_points_and_holes(mo);
this->update();
this->object_list_changed();
this->schedule_background_process();

View File

@ -36,6 +36,15 @@
namespace Slic3r {
namespace UndoRedo {
#ifdef SLIC3R_UNDOREDO_DEBUG
static inline std::string ptr_to_string(const void* ptr)
{
char buf[64];
sprintf(buf, "%p", ptr);
return buf;
}
#endif
SnapshotData::SnapshotData() : printer_technology(ptUnknown), flags(0), layer_range_idx(-1)
{
}
@ -368,15 +377,6 @@ private:
MutableHistoryInterval& operator=(const MutableHistoryInterval &rhs);
};
#ifdef SLIC3R_UNDOREDO_DEBUG
static inline std::string ptr_to_string(const void* ptr)
{
char buf[64];
sprintf(buf, "%p", ptr);
return buf;
}
#endif
// Smaller objects (Model, ModelObject, ModelInstance, ModelVolume, DynamicPrintConfig)
// are mutable and there is not tracking of the changes, therefore a snapshot needs to be
// taken every time and compared to the previous data at the Undo / Redo stack.