Merge branch 'dk_notifications'

This commit is contained in:
David Kocik 2021-08-11 09:29:13 +02:00
commit 7c1f1b36d5
5 changed files with 50 additions and 21 deletions

View File

@ -2517,7 +2517,7 @@ wxDataViewItem ObjectList::add_settings_item(wxDataViewItem parent_item, const D
}
void ObjectList::update_info_items(size_t obj_idx, wxDataViewItemArray* selections/* = nullptr*/)
void ObjectList::update_info_items(size_t obj_idx, wxDataViewItemArray* selections/* = nullptr*/, bool added_object/* = false*/)
{
const ModelObject* model_object = (*m_objects)[obj_idx];
wxDataViewItem item_obj = m_objects_model->GetItemById(obj_idx);
@ -2561,8 +2561,8 @@ void ObjectList::update_info_items(size_t obj_idx, wxDataViewItemArray* selectio
if (! shows && should_show) {
m_objects_model->AddInfoChild(item_obj, type);
Expand(item_obj);
wxGetApp().notification_manager()->push_updated_item_info_notification(type);
if (added_object)
wxGetApp().notification_manager()->push_updated_item_info_notification(type);
}
else if (shows && ! should_show) {
if (!selections)
@ -2594,7 +2594,7 @@ void ObjectList::add_object_to_list(size_t obj_idx, bool call_selection_changed)
model_object->config.has("extruder") ? model_object->config.extruder() : 0,
get_mesh_errors_count(obj_idx) > 0);
update_info_items(obj_idx);
update_info_items(obj_idx, nullptr, true);
// add volumes to the object
if (model_object->volumes.size() > 1) {

View File

@ -350,7 +350,7 @@ public:
void update_and_show_object_settings_item();
void update_settings_item_and_selection(wxDataViewItem item, wxDataViewItemArray& selections);
void update_object_list_by_printer_technology();
void update_info_items(size_t obj_idx, wxDataViewItemArray* selections = nullptr);
void update_info_items(size_t obj_idx, wxDataViewItemArray* selections = nullptr, bool added_object = false);
void instances_to_separated_object(const int obj_idx, const std::set<int>& inst_idx);
void instances_to_separated_objects(const int obj_idx);

View File

@ -61,7 +61,7 @@ static const std::map<const wchar_t, std::string> font_icons_large = {
{ImGui::SinkingObjectMarker , "move" },
{ImGui::CustomSupportsMarker , "fdm_supports" },
{ImGui::CustomSeamMarker , "seam" },
{ImGui::MmuSegmentationMarker , "move" },
{ImGui::MmuSegmentationMarker , "fdm_supports" },
{ImGui::VarLayerHeightMarker , "layers" },
{ImGui::DocumentationButton , "notification_documentation" },
{ImGui::DocumentationHoverButton, "notification_documentation_hover"},

View File

@ -1074,10 +1074,39 @@ void NotificationManager::UpdatedItemsInfoNotification::count_spaces()
m_window_width_offset = m_left_indentation + m_line_height * 3.f;
m_window_width = m_line_height * 25;
}
void NotificationManager::UpdatedItemsInfoNotification::add_type(InfoItemType type)
{
std::vector<std::pair<InfoItemType, size_t>>::iterator it = m_types_and_counts.begin();
for (; it != m_types_and_counts.end(); ++it) {
if ((*it).first == type) {
(*it).second++;
break;
}
}
if (it == m_types_and_counts.end())
m_types_and_counts.emplace_back(type, 1);
std::string text;
for (it = m_types_and_counts.begin(); it != m_types_and_counts.end(); ++it) {
text += std::to_string((*it).second);
text += _L_PLURAL(" Object was loaded with "," Objects were loaded with ", (*it).second).ToUTF8().data();
switch ((*it).first) {
case InfoItemType::CustomSupports: text += _utf8("custom supports.\n"); break;
case InfoItemType::CustomSeam: text += _utf8("custom seam.\n"); break;
case InfoItemType::MmuSegmentation: text += _utf8("multimaterial painting.\n"); break;
case InfoItemType::VariableLayerHeight: text += _utf8("variable layer height.\n"); break;
case InfoItemType::Sinking: text += _utf8("Partial sinking.\n"); break;
default: text.clear(); break;
}
}
NotificationData data { get_data().type, get_data().level , get_data().duration, text };
update(data);
}
void NotificationManager::UpdatedItemsInfoNotification::render_left_sign(ImGuiWrapper& imgui)
{
std::string text;
switch (m_info_item_type) {
InfoItemType type = (m_types_and_counts.empty() ? InfoItemType::CustomSupports : m_types_and_counts[0].first);
switch (type) {
case InfoItemType::CustomSupports: text = ImGui::CustomSupportsMarker; break;
case InfoItemType::CustomSeam: text = ImGui::CustomSeamMarker; break;
case InfoItemType::MmuSegmentation: text = ImGui::MmuSegmentationMarker; break;
@ -1349,7 +1378,6 @@ void NotificationManager::upload_job_notification_show_error(int id, const std::
}
void NotificationManager::push_hint_notification(bool open_next)
{
for (std::unique_ptr<PopNotification>& notification : m_pop_notifications) {
if (notification->get_type() == NotificationType::DidYouKnowHint) {
if (open_next)
@ -1375,19 +1403,19 @@ bool NotificationManager::is_hint_notification_open()
void NotificationManager::push_updated_item_info_notification(InfoItemType type)
{
std::string text = _utf8("Object(s) were loaded with ");
switch (type) {
case InfoItemType::CustomSupports: text += _utf8("custom supports."); break;
case InfoItemType::CustomSeam: text += _utf8("custom seam."); break;
case InfoItemType::MmuSegmentation: text += _utf8("multimaterial painting."); break;
case InfoItemType::VariableLayerHeight: text += _utf8("variable layer height."); break;
case InfoItemType::Sinking: text = _utf8("Partially sinking object(s) were loaded."); break;
default: text.clear(); break;
for (std::unique_ptr<PopNotification>& notification : m_pop_notifications) {
if (notification->get_type() == NotificationType::UpdatedItemsInfo) {
(dynamic_cast<UpdatedItemsInfoNotification*>(notification.get()))->add_type(type);
return;
}
}
if (!text.empty()) {
NotificationData data{ NotificationType::UpdatedItemsInfo, NotificationLevel::RegularNotification, 10, text };
push_notification_data(std::make_unique<NotificationManager::UpdatedItemsInfoNotification>(data, m_id_provider, m_evt_handler, type), 0);
NotificationData data{ NotificationType::UpdatedItemsInfo, NotificationLevel::RegularNotification, 5, "" };
auto notification = std::make_unique<NotificationManager::UpdatedItemsInfoNotification>(data, m_id_provider, m_evt_handler, type);
if (push_notification_data(std::move(notification), 0)) {
(dynamic_cast<UpdatedItemsInfoNotification*>(m_pop_notifications.back().get()))->add_type(type);
}
}
bool NotificationManager::push_notification_data(const NotificationData& notification_data, int timestamp)
{

View File

@ -499,13 +499,14 @@ private:
public:
UpdatedItemsInfoNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler, InfoItemType info_item_type)
: PopNotification(n, id_provider, evt_handler)
, m_info_item_type(info_item_type)
{
//m_types_and_counts.emplace_back(info_item_type, 1);
}
void count_spaces() override;
void add_type(InfoItemType type);
protected:
void render_left_sign(ImGuiWrapper& imgui) override;
InfoItemType m_info_item_type;
std::vector<std::pair<InfoItemType, size_t>> m_types_and_counts;
};
// in HintNotification.hpp