Merge branch 'fs_emboss' of https://github.com/prusa3d/PrusaSlicer into fs_emboss

This commit is contained in:
Filip Sykala 2021-10-21 16:04:09 +02:00
commit 081abc2560
12 changed files with 225 additions and 104 deletions
src/slic3r/GUI/Gizmos

View file

@ -207,7 +207,7 @@ bool GLGizmoEmboss::on_init()
std::string GLGizmoEmboss::on_get_name() const
{
return (_L("Emboss")).ToUTF8().data();
return _u8L("Emboss");
}
void GLGizmoEmboss::on_render() {}
@ -409,6 +409,26 @@ bool GLGizmoEmboss::process()
return add_volume(create_volume_name(), its);
}
void GLGizmoEmboss::set_volume_type(ModelVolumeType volume_type)
{
m_volume_type = volume_type; // fsFIXME - may be it's no needed
const Selection& selection = m_parent.get_selection();
if (selection.is_empty() || selection.get_object_idx() < 0)
return;
m_volume->set_type(volume_type);
ObjectList* obj_list = wxGetApp().obj_list();
ModelVolume* volume = m_volume; // copy pointer for lambda
wxDataViewItemArray sel = obj_list->reorder_volumes_and_get_selection(selection.get_object_idx(), [volume](const ModelVolume* vol) { return vol == volume; });
if (!sel.IsEmpty())
obj_list->select_item(sel.front());
obj_list->selection_changed();
m_parent.reload_scene(true);
}
bool GLGizmoEmboss::add_volume(const std::string &name, indexed_triangle_set &its)
{
if (its.indices.empty()) return false;
@ -453,32 +473,6 @@ bool GLGizmoEmboss::add_volume(const std::string &name, indexed_triangle_set &it
m_volume->config.set_key_value("extruder", new ConfigOptionInt(0));
m_volume->text_configuration = create_configuration();
// select new added volume
ModelObject *mo = m_volume->get_object();
// Editing object volume change its name
if (mo->volumes.size() == 1) mo->name = name;
ObjectList * obj_list = app.obj_list();
const ModelObjectPtrs &objs = *obj_list->objects();
auto item = find(objs.begin(), objs.end(), mo);
assert(item != objs.end());
int object_idx = item - objs.begin();
ModelVolume *new_volume = m_volume; // copy pointer for lambda
obj_list->select_item([new_volume, object_idx, obj_list]() {
wxDataViewItemArray items = obj_list->reorder_volumes_and_get_selection(
object_idx, [new_volume](const ModelVolume *volume) {
return volume == new_volume;
});
if (items.IsEmpty()) return wxDataViewItem();
return items.front();
});
if (m_volume->type() == ModelVolumeType::MODEL_PART)
// update printable state on canvas
m_parent.update_instance_printable_state_for_object(
(size_t) object_idx);
obj_list->selection_changed();
m_parent.reload_scene(true);
return true;
}
@ -500,22 +494,22 @@ void GLGizmoEmboss::draw_window()
#endif // ALLOW_DEBUG_MODE
if (!m_font.has_value()) {
ImGui::Text(_L("Warning: No font is selected. Select correct one.").c_str());
ImGui::Text(_u8L("Warning: No font is selected. Select correct one.").c_str());
}
draw_font_list();
draw_text_input();
static bool advanced = false;
ImGui::Checkbox(_L("Advance").c_str(), &advanced);
ImGui::Checkbox(_u8L("Advance").c_str(), &advanced);
if (advanced) draw_advanced();
if (ImGui::Button(_L("Close").c_str())) close();
if (ImGui::Button(_u8L("Close").c_str())) close();
// Option to create text volume when reselecting volumes
m_imgui->disabled_begin(!m_font.has_value());
if (m_volume == nullptr) {
ImGui::SameLine();
if (ImGui::Button(_L("Generate preview").c_str())) process();
if (ImGui::Button(_u8L("Generate preview").c_str())) process();
}
m_imgui->disabled_end();
}
@ -529,18 +523,18 @@ void GLGizmoEmboss::draw_font_list()
if (ImGui::BeginCombo("##font_selector", current_name.c_str())) {
// first line
#ifdef USE_FONT_DIALOG
if (ImGui::Button(_L("Choose font").c_str())) {
if (ImGui::Button(_u8L("Choose font").c_str())) {
choose_font_by_wxdialog();
store_font_list();
ImGui::CloseCurrentPopup();
} else if (ImGui::IsItemHovered()) ImGui::SetTooltip(_L("Choose from installed font in dialog.").c_str());
} else if (ImGui::IsItemHovered()) ImGui::SetTooltip(_u8L("Choose from installed font in dialog.").c_str());
ImGui::SameLine();
#endif // USE_FONT_DIALOG
if (ImGui::Button(_L("Add File").c_str())) {
if (ImGui::Button(_u8L("Add File").c_str())) {
choose_true_type_file();
store_font_list();
ImGui::CloseCurrentPopup();
} else if (ImGui::IsItemHovered()) ImGui::SetTooltip(_L("add file with font(.ttf, .ttc)").c_str());
} else if (ImGui::IsItemHovered()) ImGui::SetTooltip(_u8L("add file with font(.ttf, .ttc)").c_str());
ImGui::Separator();
@ -626,24 +620,24 @@ void GLGizmoEmboss::draw_text_input()
}
void GLGizmoEmboss::draw_advanced() {
if (ImGui::InputFloat(_L("Size[in mm]").c_str(), &m_font_prop.size_in_mm)) {
if (ImGui::InputFloat(_u8L("Size[in mm]").c_str(), &m_font_prop.size_in_mm)) {
if (m_font_prop.size_in_mm < 0.1) m_font_prop.size_in_mm = 10;
load_imgui_font();
process();
}
if (ImGui::InputFloat(_L("Emboss[in mm]").c_str(), &m_font_prop.emboss)) process();
if (ImGui::InputFloat(_L("Flatness").c_str(), &m_font_prop.flatness)) {
if (ImGui::InputFloat(_u8L("Emboss[in mm]").c_str(), &m_font_prop.emboss)) process();
if (ImGui::InputFloat(_u8L("Flatness").c_str(), &m_font_prop.flatness)) {
if (m_font.has_value()) m_font->cache.clear();
process();
}
if (ImGui::InputInt(_L("CharGap[in font points]").c_str(), &m_font_prop.char_gap))
if (ImGui::InputInt(_u8L("CharGap[in font points]").c_str(), &m_font_prop.char_gap))
process();
if (ImGui::InputInt(_L("LineGap[in font points]").c_str(), &m_font_prop.line_gap))
if (ImGui::InputInt(_u8L("LineGap[in font points]").c_str(), &m_font_prop.line_gap))
process();
// when more collection add selector
if (m_font.has_value() && m_font->count > 1) {
if (ImGui::BeginCombo(_L("Font collection").c_str(),
if (ImGui::BeginCombo(_u8L("Font collection").c_str(),
std::to_string(m_font->index).c_str())) {
for (unsigned int i = 0; i < m_font->count; ++i) {
ImGui::PushID(1 << 10 + i);
@ -1100,7 +1094,7 @@ bool GLGizmoEmboss::draw_button(IconType icon, bool disable)
if (disable) {
draw_icon(icon, IconState::disabled);
if (ImGui::IsItemHovered() && icon == IconType::erase)
ImGui::SetTooltip(_L("Active font can't be removed").c_str());
ImGui::SetTooltip(_u8L("Active font can't be removed").c_str());
return false;
}
@ -1110,8 +1104,8 @@ bool GLGizmoEmboss::draw_button(IconType icon, bool disable)
if (ImGui::IsItemClicked()) return true;
if (ImGui::IsItemHovered()) {
switch (icon) {
case IconType::rename: ImGui::SetTooltip(_L("rename").c_str()); break;
case IconType::erase: ImGui::SetTooltip(_L("delete").c_str()); break;
case IconType::rename: ImGui::SetTooltip(_u8L("rename").c_str()); break;
case IconType::erase: ImGui::SetTooltip(_u8L("delete").c_str()); break;
default: break;
}
// redraw image over previous