mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-23 22:54:08 -06:00
NEW: add text gizmo tool
Signed-off-by: yifan.wu <yifan.wu@bambulab.com> Change-Id: I77fdf64340f580e6baa3260101fa1c6db7a4ab2d (cherry picked from commit 2147c55134b4d9d1018d7e9f4f8d1a4d50c065f6)
This commit is contained in:
parent
65ba9cafb3
commit
b068389d4c
11 changed files with 448 additions and 1 deletions
|
@ -129,6 +129,8 @@ set(SLIC3R_GUI_SOURCES
|
|||
GUI/Gizmos/GLGizmoFaceDetector.hpp
|
||||
GUI/Gizmos/GLGizmoSeam.cpp
|
||||
GUI/Gizmos/GLGizmoSeam.hpp
|
||||
GUI/Gizmos/GLGizmoText.cpp
|
||||
GUI/Gizmos/GLGizmoText.hpp
|
||||
GUI/GLSelectionRectangle.cpp
|
||||
GUI/GLSelectionRectangle.hpp
|
||||
GUI/Gizmos/GizmoObjectManipulation.cpp
|
||||
|
|
|
@ -2069,6 +2069,45 @@ void ObjectList::load_mesh_object(const TriangleMesh &mesh, const wxString &name
|
|||
#endif /* _DEBUG */
|
||||
}
|
||||
|
||||
void ObjectList::load_mesh_part(const TriangleMesh& mesh, const wxString& name, bool center)
|
||||
{
|
||||
wxDataViewItem item = GetSelection();
|
||||
// we can add volumes for Object or Instance
|
||||
if (!item || !(m_objects_model->GetItemType(item) & (itObject | itInstance)))
|
||||
return;
|
||||
const int obj_idx = m_objects_model->GetObjectIdByItem(item);
|
||||
|
||||
if (obj_idx < 0) return;
|
||||
|
||||
// Get object item, if Instance is selected
|
||||
if (m_objects_model->GetItemType(item) & itInstance)
|
||||
item = m_objects_model->GetItemById(obj_idx);
|
||||
|
||||
take_snapshot("Load Mesh Part");
|
||||
|
||||
ModelObject* mo = (*m_objects)[obj_idx];
|
||||
ModelVolume* mv = mo->add_volume(mesh);
|
||||
mv->name = name.ToStdString();
|
||||
|
||||
std::vector<ModelVolume*> volumes;
|
||||
volumes.push_back(mv);
|
||||
wxDataViewItemArray items = reorder_volumes_and_get_selection(obj_idx, [volumes](const ModelVolume* volume) {
|
||||
return std::find(volumes.begin(), volumes.end(), volume) != volumes.end(); });
|
||||
|
||||
wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_object((size_t)obj_idx);
|
||||
|
||||
if (items.size() > 1) {
|
||||
m_selection_mode = smVolume;
|
||||
m_last_selected_item = wxDataViewItem(nullptr);
|
||||
}
|
||||
select_items(items);
|
||||
|
||||
selection_changed();
|
||||
|
||||
//BBS: notify partplate the modify
|
||||
notify_instance_updated(obj_idx);
|
||||
}
|
||||
|
||||
//BBS
|
||||
void ObjectList::del_object(const int obj_idx, bool refresh_immediately)
|
||||
{
|
||||
|
|
|
@ -281,6 +281,8 @@ public:
|
|||
void load_generic_subobject(const std::string& type_name, const ModelVolumeType type);
|
||||
void load_shape_object(const std::string &type_name);
|
||||
void load_mesh_object(const TriangleMesh &mesh, const wxString &name, bool center = true);
|
||||
// BBS
|
||||
void load_mesh_part(const TriangleMesh& mesh, const wxString& name, bool center = true);
|
||||
void del_object(const int obj_idx, bool refresh_immediately = true);
|
||||
void del_subobject_item(wxDataViewItem& item);
|
||||
void del_settings_from_config(const wxDataViewItem& parent_item);
|
||||
|
|
137
src/slic3r/GUI/Gizmos/GLGizmoText.cpp
Normal file
137
src/slic3r/GUI/Gizmos/GLGizmoText.cpp
Normal file
|
@ -0,0 +1,137 @@
|
|||
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
|
||||
#include "GLGizmoText.hpp"
|
||||
#include "slic3r/GUI/GLCanvas3D.hpp"
|
||||
#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp"
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/ImGuiWrapper.hpp"
|
||||
#include "slic3r/GUI/GUI_ObjectList.hpp"
|
||||
|
||||
#include "libslic3r/Geometry/ConvexHull.hpp"
|
||||
#include "libslic3r/Model.hpp"
|
||||
|
||||
#include "libslic3r/Shape/TextShape.hpp"
|
||||
|
||||
#include <numeric>
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
static double g_normal_precise = 0.0015;
|
||||
|
||||
GLGizmoText::GLGizmoText(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
|
||||
: GLGizmoBase(parent, icon_filename, sprite_id)
|
||||
{
|
||||
}
|
||||
|
||||
bool GLGizmoText::on_init()
|
||||
{
|
||||
m_avail_font_names = init_occt_fonts();
|
||||
m_shortcut_key = WXK_CONTROL_T;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoText::on_set_state()
|
||||
{
|
||||
}
|
||||
|
||||
CommonGizmosDataID GLGizmoText::on_get_requirements() const
|
||||
{
|
||||
return CommonGizmosDataID::SelectionInfo;
|
||||
}
|
||||
|
||||
std::string GLGizmoText::on_get_name() const
|
||||
{
|
||||
return _u8L("Text shape");
|
||||
}
|
||||
|
||||
bool GLGizmoText::on_is_activable() const
|
||||
{
|
||||
// This is assumed in GLCanvas3D::do_rotate, do not change this
|
||||
// without updating that function too.
|
||||
return m_parent.get_selection().is_single_full_instance();
|
||||
}
|
||||
|
||||
void GLGizmoText::on_render()
|
||||
{
|
||||
// TODO:
|
||||
}
|
||||
|
||||
void GLGizmoText::on_render_for_picking()
|
||||
{
|
||||
// TODO:
|
||||
}
|
||||
|
||||
// BBS
|
||||
void GLGizmoText::on_render_input_window(float x, float y, float bottom_limit)
|
||||
{
|
||||
static float last_y = 0.0f;
|
||||
static float last_h = 0.0f;
|
||||
|
||||
float space_size = m_imgui->get_style_scaling() * 8;
|
||||
float font_cap = m_imgui->calc_text_size("Font ").x;
|
||||
float size_cap = m_imgui->calc_text_size("Size ").x;
|
||||
float thickness_cap = m_imgui->calc_text_size("Thickness ").x;
|
||||
float caption_size = std::max(std::max(font_cap, size_cap), thickness_cap) + 2 * space_size;
|
||||
|
||||
m_imgui->begin(_L("Text"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
|
||||
|
||||
// adjust window position to avoid overlap the view toolbar
|
||||
const float win_h = ImGui::GetWindowHeight();
|
||||
y = std::min(y, bottom_limit - win_h);
|
||||
ImGui::SetWindowPos(ImVec2(x, y), ImGuiCond_Always);
|
||||
if (last_h != win_h || last_y != y) {
|
||||
// ask canvas for another frame to render the window in the correct position
|
||||
m_imgui->set_requires_extra_frame();
|
||||
if (last_h != win_h)
|
||||
last_h = win_h;
|
||||
if (last_y != y)
|
||||
last_y = y;
|
||||
}
|
||||
|
||||
ImGui::AlignTextToFramePadding();
|
||||
|
||||
const char** cstr_font_names = (const char**)calloc(m_avail_font_names.size(), sizeof(const char*));
|
||||
for (int i = 0; i < m_avail_font_names.size(); i++)
|
||||
cstr_font_names[i] = m_avail_font_names[i].c_str();
|
||||
|
||||
ImGui::InputText("", m_text, sizeof(m_text));
|
||||
|
||||
ImGui::PushItemWidth(caption_size);
|
||||
ImGui::Text("Font ");
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(150);
|
||||
ImGui::Combo("##Font", &m_curr_font_idx, cstr_font_names, m_avail_font_names.size());
|
||||
|
||||
ImGui::PushItemWidth(caption_size);
|
||||
ImGui::Text("Size ");
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(150);
|
||||
ImGui::InputFloat("###font_size", &m_font_size);
|
||||
|
||||
ImGui::PushItemWidth(caption_size);
|
||||
ImGui::Text("Thickness ");
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(150);
|
||||
ImGui::InputFloat("###text_thickness", &m_thickness);
|
||||
|
||||
ImGui::Checkbox("Bold", &m_bold);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Italic", &m_italic);
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
bool add_clicked = m_imgui->button(_L("Add"));
|
||||
if (add_clicked) {
|
||||
TriangleMesh mesh;
|
||||
load_text_shape(m_text, m_font_name.c_str(), m_font_size, m_thickness, m_bold, m_italic, mesh);
|
||||
ObjectList* obj_list = wxGetApp().obj_list();
|
||||
obj_list->load_mesh_part(mesh, "text_shape");
|
||||
}
|
||||
|
||||
m_imgui->end();
|
||||
}
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
43
src/slic3r/GUI/Gizmos/GLGizmoText.hpp
Normal file
43
src/slic3r/GUI/Gizmos/GLGizmoText.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#ifndef slic3r_GLGizmoText_hpp_
|
||||
#define slic3r_GLGizmoText_hpp_
|
||||
|
||||
#include "GLGizmoBase.hpp"
|
||||
#include "slic3r/GUI/3DScene.hpp"
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
enum class ModelVolumeType : int;
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class GLGizmoText : public GLGizmoBase
|
||||
{
|
||||
private:
|
||||
std::vector<std::string> m_avail_font_names;
|
||||
char m_text[256] = { 0 };
|
||||
std::string m_font_name;
|
||||
float m_font_size = 16.f;
|
||||
int m_curr_font_idx = 0;
|
||||
bool m_bold = true;
|
||||
bool m_italic = false;
|
||||
float m_thickness = 2.f;
|
||||
|
||||
public:
|
||||
GLGizmoText(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
|
||||
|
||||
protected:
|
||||
virtual bool on_init() override;
|
||||
virtual std::string on_get_name() const override;
|
||||
virtual bool on_is_activable() const override;
|
||||
virtual void on_render() override;
|
||||
virtual void on_render_for_picking() override;
|
||||
virtual void on_set_state() override;
|
||||
virtual CommonGizmosDataID on_get_requirements() const override;
|
||||
virtual void on_render_input_window(float x, float y, float bottom_limit);
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif // slic3r_GLGizmoText_hpp_
|
|
@ -22,6 +22,7 @@
|
|||
#include "slic3r/GUI/Gizmos/GLGizmoSeam.hpp"
|
||||
#include "slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp"
|
||||
#include "slic3r/GUI/Gizmos/GLGizmoSimplify.hpp"
|
||||
#include "slic3r/GUI/Gizmos/GLGizmoText.hpp"
|
||||
|
||||
#include "libslic3r/format.hpp"
|
||||
#include "libslic3r/Model.hpp"
|
||||
|
@ -146,6 +147,7 @@ bool GLGizmosManager::init()
|
|||
m_gizmos.emplace_back(new GLGizmoAdvancedCut(m_parent, "toolbar_cut.svg", EType::Cut));
|
||||
m_gizmos.emplace_back(new GLGizmoFdmSupports(m_parent, "toolbar_support.svg", EType::FdmSupports));
|
||||
m_gizmos.emplace_back(new GLGizmoSeam(m_parent, "toolbar_seam.svg", EType::Seam));
|
||||
m_gizmos.emplace_back(new GLGizmoText(m_parent, "toolbar_text.svg", EType::Text));
|
||||
m_gizmos.emplace_back(new GLGizmoMmuSegmentation(m_parent, "mmu_segmentation.svg", EType::MmuSegmentation));
|
||||
m_gizmos.emplace_back(new GLGizmoSimplify(m_parent, "reduce_triangles.svg", EType::Simplify));
|
||||
//m_gizmos.emplace_back(new GLGizmoSlaSupports(m_parent, "sla_supports.svg", sprite_id++));
|
||||
|
|
|
@ -72,6 +72,8 @@ public:
|
|||
Cut,
|
||||
FdmSupports,
|
||||
Seam,
|
||||
// BBS
|
||||
Text,
|
||||
MmuSegmentation,
|
||||
Simplify,
|
||||
SlaSupports,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue