clean emboss from add volume
This commit is contained in:
parent
eaaa59be86
commit
93131ab69c
4 changed files with 23 additions and 115 deletions
|
@ -475,75 +475,10 @@ bool GLGizmoEmboss::process()
|
||||||
data.volume_name = create_volume_name();
|
data.volume_name = create_volume_name();
|
||||||
data.volume_ptr = m_volume;
|
data.volume_ptr = m_volume;
|
||||||
data.object_idx = m_parent.get_selection().get_object_idx();
|
data.object_idx = m_parent.get_selection().get_object_idx();
|
||||||
|
|
||||||
m_job->restart(data);
|
m_job->restart(data);
|
||||||
return true;
|
|
||||||
|
|
||||||
ExPolygons shapes = Emboss::text2shapes(*m_font, m_text.c_str(), m_font_prop);
|
// notification is removed befor object is changed by job
|
||||||
// exist 2d shape made by text ?
|
|
||||||
// (no shape means that font doesnt have any of text symbols)
|
|
||||||
if (shapes.empty()) return false;
|
|
||||||
|
|
||||||
// after applied another font notification is no more valid
|
|
||||||
remove_notification_not_valid_font();
|
remove_notification_not_valid_font();
|
||||||
|
|
||||||
float scale = m_font_prop.size_in_mm / m_font->ascent;
|
|
||||||
auto project = std::make_unique<Emboss::ProjectScale>(
|
|
||||||
std::make_unique<Emboss::ProjectZ>(m_font_prop.emboss / scale), scale);
|
|
||||||
indexed_triangle_set its = Emboss::polygons2model(shapes, *project);
|
|
||||||
return add_volume(create_volume_name(), its);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GLGizmoEmboss::add_volume(const std::string & name,
|
|
||||||
indexed_triangle_set &its)
|
|
||||||
{
|
|
||||||
if (its.indices.empty()) return false;
|
|
||||||
// add object
|
|
||||||
TriangleMesh tm(std::move(its));
|
|
||||||
// center triangle mesh
|
|
||||||
Vec3d shift = tm.bounding_box().center();
|
|
||||||
tm.translate(-shift.cast<float>());
|
|
||||||
|
|
||||||
GUI_App &app = wxGetApp();
|
|
||||||
Plater * plater = app.plater();
|
|
||||||
plater->take_snapshot(_L("Emboss text") + ": " + name);
|
|
||||||
if (m_volume == nullptr) {
|
|
||||||
// decide to add as volume or new object
|
|
||||||
const Selection &selection = m_parent.get_selection();
|
|
||||||
if (selection.is_empty() || selection.get_object_idx() < 0) {
|
|
||||||
TextConfiguration text_configuration = create_configuration();
|
|
||||||
// create new object
|
|
||||||
app.obj_list()->load_mesh_object(tm, name, true, &text_configuration);
|
|
||||||
app.mainframe->update_title();
|
|
||||||
|
|
||||||
// load mesh cause close gizmo, on windows but not on linux
|
|
||||||
// Open gizmo again when it is closed
|
|
||||||
GLGizmosManager& mng = m_parent.get_gizmos_manager();
|
|
||||||
if (mng.get_current_type() != GLGizmosManager::Emboss)
|
|
||||||
mng.open_gizmo(GLGizmosManager::Emboss);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
// create new volume inside of object
|
|
||||||
int object_idx = selection.get_object_idx();
|
|
||||||
ModelObject *obj = plater->model().objects[object_idx];
|
|
||||||
m_volume = obj->add_volume(std::move(tm));
|
|
||||||
// set a default extruder value, since user can't add it manually
|
|
||||||
m_volume->config.set_key_value("extruder", new ConfigOptionInt(0));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// update volume
|
|
||||||
m_volume->set_mesh(std::move(tm));
|
|
||||||
m_volume->set_new_unique_id();
|
|
||||||
m_volume->calculate_convex_hull();
|
|
||||||
m_volume->get_object()->invalidate_bounding_box();
|
|
||||||
}
|
|
||||||
m_volume->name = name;
|
|
||||||
m_volume->text_configuration = create_configuration();
|
|
||||||
|
|
||||||
// update volume name in object list
|
|
||||||
refresh_object_list();
|
|
||||||
|
|
||||||
m_parent.reload_scene(true);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,14 +542,16 @@ void GLGizmoEmboss::draw_font_list()
|
||||||
} else if (ImGui::IsItemHovered())
|
} else if (ImGui::IsItemHovered())
|
||||||
ImGui::SetTooltip(
|
ImGui::SetTooltip(
|
||||||
_u8L("Choose from installed font inside dialog.").c_str());
|
_u8L("Choose from installed font inside dialog.").c_str());
|
||||||
|
|
||||||
|
#ifdef ALLOW_DEBUG_MODE
|
||||||
|
ImGui::SameLine();
|
||||||
// select font file by file browser
|
// select font file by file browser
|
||||||
// if (ImGui::Button(_u8L("Add File").c_str())) {
|
if (ImGui::Button(_u8L("Add File").c_str())) {
|
||||||
// choose_true_type_file();
|
choose_true_type_file();
|
||||||
// store_font_list();
|
store_font_list();
|
||||||
// ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
//} else if (ImGui::IsItemHovered()) ImGui::SetTooltip(_u8L("add file
|
} else if (ImGui::IsItemHovered()) ImGui::SetTooltip(_u8L("add file with font(.ttf, .ttc)").c_str());
|
||||||
//with font(.ttf, .ttc)").c_str());
|
#endif // ALLOW_DEBUG_MODE
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
|
@ -807,29 +744,6 @@ bool GLGizmoEmboss::create_default_model_object()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoEmboss::refresh_object_list()
|
|
||||||
{
|
|
||||||
const Selection &selection = m_parent.get_selection();
|
|
||||||
if (selection.is_empty() ||
|
|
||||||
selection.get_object_idx() < 0 ||
|
|
||||||
m_volume == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ObjectList * obj_list = wxGetApp().obj_list();
|
|
||||||
ModelVolume *volume = m_volume; // copy for lambda
|
|
||||||
|
|
||||||
// select only actual volume
|
|
||||||
// when new volume is created change selection to this volume
|
|
||||||
auto add_to_selection = [volume](const ModelVolume *vol) { return vol == volume;};
|
|
||||||
wxDataViewItemArray sel = obj_list->reorder_volumes_and_get_selection(
|
|
||||||
selection.get_object_idx(), add_to_selection);
|
|
||||||
|
|
||||||
if (!sel.IsEmpty())
|
|
||||||
obj_list->select_item(sel.front());
|
|
||||||
|
|
||||||
obj_list->selection_changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GLGizmoEmboss::load_font(size_t font_index)
|
bool GLGizmoEmboss::load_font(size_t font_index)
|
||||||
{
|
{
|
||||||
std::swap(font_index, m_font_selected);
|
std::swap(font_index, m_font_selected);
|
||||||
|
@ -1070,7 +984,7 @@ bool GLGizmoEmboss::choose_svg_file()
|
||||||
// for (auto &poly : polys) poly.scale(1e5);
|
// for (auto &poly : polys) poly.scale(1e5);
|
||||||
// SVG svg("converted.svg", BoundingBox(polys.front().contour.points));
|
// SVG svg("converted.svg", BoundingBox(polys.front().contour.points));
|
||||||
// svg.draw(polys);
|
// svg.draw(polys);
|
||||||
return add_volume(name, its);
|
//return add_volume(name, its);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextConfiguration GLGizmoEmboss::create_configuration()
|
TextConfiguration GLGizmoEmboss::create_configuration()
|
||||||
|
|
|
@ -51,7 +51,6 @@ private:
|
||||||
static ModelVolume *get_selected_volume(const Selection &selection, const ModelObjectPtrs objects);
|
static ModelVolume *get_selected_volume(const Selection &selection, const ModelObjectPtrs objects);
|
||||||
// create volume from text - main functionality
|
// create volume from text - main functionality
|
||||||
bool process();
|
bool process();
|
||||||
bool add_volume(const std::string& name, indexed_triangle_set& its);
|
|
||||||
void close();
|
void close();
|
||||||
void draw_window();
|
void draw_window();
|
||||||
void draw_font_list();
|
void draw_font_list();
|
||||||
|
@ -59,7 +58,6 @@ private:
|
||||||
void draw_advanced();
|
void draw_advanced();
|
||||||
|
|
||||||
bool create_default_model_object();
|
bool create_default_model_object();
|
||||||
void refresh_object_list();
|
|
||||||
|
|
||||||
bool load_font();
|
bool load_font();
|
||||||
// try to set font_index
|
// try to set font_index
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "libslic3r/Model.hpp"
|
#include "libslic3r/Model.hpp"
|
||||||
|
|
||||||
#include "slic3r/GUI/Plater.hpp"
|
#include "slic3r/GUI/Plater.hpp"
|
||||||
|
#include "slic3r/GUI/NotificationManager.hpp"
|
||||||
#include "slic3r/GUI/GLCanvas3D.hpp"
|
#include "slic3r/GUI/GLCanvas3D.hpp"
|
||||||
#include "slic3r/GUI/GUI_ObjectList.hpp"
|
#include "slic3r/GUI/GUI_ObjectList.hpp"
|
||||||
#include "slic3r/GUI/MainFrame.hpp"
|
#include "slic3r/GUI/MainFrame.hpp"
|
||||||
|
@ -82,11 +83,10 @@ void EmbossJob::finalize() {
|
||||||
Vec3d shift = tm.bounding_box().center();
|
Vec3d shift = tm.bounding_box().center();
|
||||||
tm.translate(-shift.cast<float>());
|
tm.translate(-shift.cast<float>());
|
||||||
|
|
||||||
GUI_App &app = wxGetApp();
|
GUI_App & app = wxGetApp();
|
||||||
Plater * plater = app.plater();
|
Plater * plater = app.plater();
|
||||||
GLCanvas3D *canvas = plater->canvas3D();
|
GLCanvas3D *canvas = plater->canvas3D();
|
||||||
std::string name = m_data->volume_name;
|
const std::string &name = m_data->volume_name;
|
||||||
|
|
||||||
|
|
||||||
plater->take_snapshot(_L("Emboss text") + ": " + name);
|
plater->take_snapshot(_L("Emboss text") + ": " + name);
|
||||||
ModelVolume *volume = m_data->volume_ptr;
|
ModelVolume *volume = m_data->volume_ptr;
|
||||||
|
@ -106,12 +106,12 @@ void EmbossJob::finalize() {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// create new volume inside of object
|
// create new volume inside of object
|
||||||
Model & model = wxGetApp().plater()->model();
|
Model &model = plater->model();
|
||||||
|
if (model.objects.size() <= m_data->object_idx) return;
|
||||||
ModelObject *obj = model.objects[m_data->object_idx];
|
ModelObject *obj = model.objects[m_data->object_idx];
|
||||||
volume = obj->add_volume(std::move(tm));
|
volume = obj->add_volume(std::move(tm));
|
||||||
|
|
||||||
// set a default extruder value, since user can't add it manually
|
// set a default extruder value, since user can't add it manually
|
||||||
volume->config.set_key_value("extruder", new ConfigOptionInt(0));
|
volume->config.set_key_value("extruder", new ConfigOptionInt(0));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// update volume
|
// update volume
|
||||||
|
@ -125,13 +125,9 @@ void EmbossJob::finalize() {
|
||||||
volume->text_configuration = m_data->text_configuration;
|
volume->text_configuration = m_data->text_configuration;
|
||||||
|
|
||||||
// update volume name in object list
|
// update volume name in object list
|
||||||
select_volume(volume);
|
// updata selection after new volume added
|
||||||
|
// change name of volume in right panel
|
||||||
//ObjectList *obj_list = wxGetApp().obj_list();
|
select_volume(volume);
|
||||||
//obj_list->selection_changed();
|
|
||||||
|
|
||||||
// after applied another font notification is no more valid
|
|
||||||
//remove_notification_not_valid_font();
|
|
||||||
|
|
||||||
// Job promiss to refresh is not working
|
// Job promiss to refresh is not working
|
||||||
canvas->reload_scene(true);
|
canvas->reload_scene(true);
|
||||||
|
|
|
@ -22,7 +22,7 @@ class EmbossJob : protected Job
|
||||||
public:
|
public:
|
||||||
struct Data
|
struct Data
|
||||||
{
|
{
|
||||||
// Pointer on Data of font(glyoh shapes)
|
// Pointer on Data of font (glyph shapes)
|
||||||
std::shared_ptr<Emboss::Font> font;
|
std::shared_ptr<Emboss::Font> font;
|
||||||
// font item is not used for create object
|
// font item is not used for create object
|
||||||
TextConfiguration text_configuration;
|
TextConfiguration text_configuration;
|
||||||
|
@ -31,7 +31,7 @@ public:
|
||||||
// when volume_ptr == nullptr than new volume will be created
|
// when volume_ptr == nullptr than new volume will be created
|
||||||
ModelVolume *volume_ptr;
|
ModelVolume *volume_ptr;
|
||||||
// when volume_ptr == nullptr && object_idx < 0 than new object will be created
|
// when volume_ptr == nullptr && object_idx < 0 than new object will be created
|
||||||
int object_idx;
|
int object_idx;
|
||||||
};
|
};
|
||||||
EmbossJob();
|
EmbossJob();
|
||||||
void restart(const Data &data);
|
void restart(const Data &data);
|
||||||
|
|
Loading…
Reference in a new issue