Clean up EmbossJob

This commit is contained in:
Filip Sykala - NTB T15p 2023-03-16 15:23:29 +01:00
parent 6807615c75
commit 61fa3e8844
7 changed files with 629 additions and 656 deletions

View File

@ -7235,10 +7235,10 @@ const ModelVolume *get_model_volume(const GLVolume &v, const Model &model)
return ret; return ret;
} }
const ModelVolume *get_model_volume(const ObjectID &volume_id, const ModelObjectPtrs &objects) ModelVolume *get_model_volume(const ObjectID &volume_id, const ModelObjectPtrs &objects)
{ {
for (const ModelObject *obj : objects) for (const ModelObject *obj : objects)
for (const ModelVolume *vol : obj->volumes) for (ModelVolume *vol : obj->volumes)
if (vol->id() == volume_id) if (vol->id() == volume_id)
return vol; return vol;
return nullptr; return nullptr;

View File

@ -1069,7 +1069,7 @@ private:
}; };
const ModelVolume *get_model_volume(const GLVolume &v, const Model &model); const ModelVolume *get_model_volume(const GLVolume &v, const Model &model);
const ModelVolume *get_model_volume(const ObjectID &volume_id, const ModelObjectPtrs &objects); ModelVolume *get_model_volume(const ObjectID &volume_id, const ModelObjectPtrs &objects);
ModelVolume *get_model_volume(const GLVolume &v, const ModelObjectPtrs &objects); ModelVolume *get_model_volume(const GLVolume &v, const ModelObjectPtrs &objects);
ModelVolume *get_model_volume(const GLVolume &v, const ModelObject &object); ModelVolume *get_model_volume(const GLVolume &v, const ModelObject &object);

View File

@ -15,9 +15,7 @@
#include "slic3r/Utils/WxFontUtils.hpp" #include "slic3r/Utils/WxFontUtils.hpp"
#include "slic3r/Utils/UndoRedo.hpp" #include "slic3r/Utils/UndoRedo.hpp"
// TODO: remove include #include "libslic3r/Geometry.hpp" // to range pi pi
#include "libslic3r/SVG.hpp" // debug store
#include "libslic3r/Geometry.hpp" // covex hull 2d
#include "libslic3r/Timer.hpp" #include "libslic3r/Timer.hpp"
#include "libslic3r/NSVGUtils.hpp" #include "libslic3r/NSVGUtils.hpp"
@ -92,16 +90,12 @@ using namespace priv;
GLGizmoEmboss::GLGizmoEmboss(GLCanvas3D &parent) GLGizmoEmboss::GLGizmoEmboss(GLCanvas3D &parent)
: GLGizmoBase(parent, M_ICON_FILENAME, -2) : GLGizmoBase(parent, M_ICON_FILENAME, -2)
, m_volume(nullptr)
, m_is_unknown_font(false)
, m_rotate_gizmo(parent, GLGizmoRotate::Axis::Z) // grab id = 2 (Z axis)
, m_style_manager(m_imgui->get_glyph_ranges(), create_default_styles) , m_style_manager(m_imgui->get_glyph_ranges(), create_default_styles)
, m_job_cancel(nullptr) , m_rotate_gizmo(parent, GLGizmoRotate::Axis::Z) // grab id = 2 (Z axis)
{ {
m_rotate_gizmo.set_group_id(0); m_rotate_gizmo.set_group_id(0);
m_rotate_gizmo.set_force_local_coordinate(true); m_rotate_gizmo.set_force_local_coordinate(true);
// TODO: add suggestion to use https://fontawesome.com/ // to use https://fontawesome.com/ (copy & paste) unicode symbols from web
// (copy & paste) unicode symbols from web
// paste HEX unicode into notepad move cursor after unicode press [alt] + [x] // paste HEX unicode into notepad move cursor after unicode press [alt] + [x]
} }
@ -160,14 +154,25 @@ const IconManager::Icon &get_icon(const IconManager::VIcons& icons, IconType typ
static bool draw_button(const IconManager::VIcons& icons, IconType type, bool disable = false); static bool draw_button(const IconManager::VIcons& icons, IconType type, bool disable = false);
} // namespace priv } // namespace priv
CreateVolumeParams create_input(GLCanvas3D &canvas, StyleManager &styler, RaycastManager& raycaster, ModelVolumeType volume_type)
{
auto gizmo = static_cast<unsigned char>(GLGizmosManager::Emboss);
const GLVolume *gl_volume = get_first_hovered_gl_volume(canvas);
const FontProp &fp = styler.get_style().prop;
Plater *plater = wxGetApp().plater();
return CreateVolumeParams{canvas, plater->get_camera(), plater->build_volume(),
plater->get_ui_job_worker(), volume_type, raycaster, gizmo, gl_volume, fp.distance, fp.angle};
}
bool GLGizmoEmboss::create_volume(ModelVolumeType volume_type, const Vec2d& mouse_pos) bool GLGizmoEmboss::create_volume(ModelVolumeType volume_type, const Vec2d& mouse_pos)
{ {
m_style_manager.discard_style_changes(); m_style_manager.discard_style_changes();
set_default_text(); set_default_text();
// NOTE: change style manager - be carefull with order changes
DataBasePtr base = priv::create_emboss_data_base(m_text, m_style_manager, m_job_cancel); DataBasePtr base = priv::create_emboss_data_base(m_text, m_style_manager, m_job_cancel);
Plater *plater_ptr = wxGetApp().plater(); CreateVolumeParams input = create_input(m_parent, m_style_manager, m_raycast_manager, volume_type);
const FontProp &fp = m_style_manager.get_style().prop; return start_create_volume(input, std::move(base), mouse_pos);
return start_create_volume(plater_ptr, std::move(base), volume_type, m_raycast_manager, GLGizmosManager::Emboss, mouse_pos, fp.distance, fp.angle);
} }
// Designed for create volume without information of mouse in scene // Designed for create volume without information of mouse in scene
@ -175,11 +180,11 @@ bool GLGizmoEmboss::create_volume(ModelVolumeType volume_type)
{ {
m_style_manager.discard_style_changes(); m_style_manager.discard_style_changes();
set_default_text(); set_default_text();
std::unique_ptr<DataBase> emboss_data = priv::create_emboss_data_base(m_text, m_style_manager, m_job_cancel);
Plater *plater_ptr = wxGetApp().plater(); // NOTE: change style manager - be carefull with order changes
const FontProp &fp = m_style_manager.get_style().prop; DataBasePtr base = priv::create_emboss_data_base(m_text, m_style_manager, m_job_cancel);
return start_create_volume_without_position(plater_ptr, std::move(emboss_data), CreateVolumeParams input = create_input(m_parent, m_style_manager, m_raycast_manager, volume_type);
volume_type, m_raycast_manager, GLGizmosManager::Emboss, fp.distance, fp.angle); return start_create_volume_without_position(input, std::move(base));
} }
bool GLGizmoEmboss::on_mouse_for_rotation(const wxMouseEvent &mouse_event) bool GLGizmoEmboss::on_mouse_for_rotation(const wxMouseEvent &mouse_event)

View File

@ -147,7 +147,7 @@ private:
bool on_mouse_for_translate(const wxMouseEvent &mouse_event); bool on_mouse_for_translate(const wxMouseEvent &mouse_event);
// When open text loaded from .3mf it could be written with unknown font // When open text loaded from .3mf it could be written with unknown font
bool m_is_unknown_font; bool m_is_unknown_font = false;
void create_notification_not_valid_font(const TextConfiguration& tc); void create_notification_not_valid_font(const TextConfiguration& tc);
void remove_notification_not_valid_font(); void remove_notification_not_valid_font();
@ -272,7 +272,8 @@ private:
// filtration pattern // filtration pattern
std::string search = ""; std::string search = "";
std::vector<bool> hide; // result of filtration std::vector<bool> hide; // result of filtration
} m_face_names; };
Facenames m_face_names;
static bool store(const Facenames &facenames); static bool store(const Facenames &facenames);
static bool load(Facenames &facenames); static bool load(Facenames &facenames);
@ -287,7 +288,7 @@ private:
// current selected volume // current selected volume
// NOTE: Be carefull could be uninitialized (removed from Model) // NOTE: Be carefull could be uninitialized (removed from Model)
ModelVolume *m_volume; ModelVolume *m_volume = nullptr;
// When work with undo redo stack there could be situation that // When work with undo redo stack there could be situation that
// m_volume point to unexisting volume so One need also objectID // m_volume point to unexisting volume so One need also objectID
@ -297,7 +298,7 @@ private:
bool m_text_contain_unknown_glyph = false; bool m_text_contain_unknown_glyph = false;
// cancel for previous update of volume to cancel finalize part // cancel for previous update of volume to cancel finalize part
std::shared_ptr<std::atomic<bool>> m_job_cancel; std::shared_ptr<std::atomic<bool>> m_job_cancel = nullptr;
// Rotation gizmo // Rotation gizmo
GLGizmoRotate m_rotate_gizmo; GLGizmoRotate m_rotate_gizmo;

View File

@ -99,21 +99,30 @@ static std::string get_file_name(const std::string &file_path);
/// <returns>Name for volume</returns> /// <returns>Name for volume</returns>
static std::string volume_name(const EmbossShape& shape); static std::string volume_name(const EmbossShape& shape);
static CreateVolumeParams create_input(GLCanvas3D &canvas, RaycastManager &raycaster, ModelVolumeType volume_type);
} // namespace priv } // namespace priv
CreateVolumeParams priv::create_input(GLCanvas3D &canvas, RaycastManager& raycaster, ModelVolumeType volume_type)
{
auto gizmo = static_cast<unsigned char>(GLGizmosManager::Svg);
const GLVolume *gl_volume = get_first_hovered_gl_volume(canvas);
Plater *plater = wxGetApp().plater();
return CreateVolumeParams{canvas, plater->get_camera(), plater->build_volume(),
plater->get_ui_job_worker(), volume_type, raycaster, gizmo, gl_volume};
}
bool GLGizmoSVG::create_volume(ModelVolumeType volume_type, const Vec2d &mouse_pos) bool GLGizmoSVG::create_volume(ModelVolumeType volume_type, const Vec2d &mouse_pos)
{ {
CreateVolumeParams input = priv::create_input(m_parent, m_raycast_manager, volume_type);
DataBasePtr base = priv::create_emboss_data_base(m_job_cancel); DataBasePtr base = priv::create_emboss_data_base(m_job_cancel);
Plater *plater_ptr = wxGetApp().plater(); return start_create_volume(input, std::move(base), mouse_pos);
return start_create_volume(plater_ptr, std::move(base), volume_type, m_raycast_manager, GLGizmosManager::Svg, mouse_pos);
} }
bool GLGizmoSVG::create_volume(ModelVolumeType volume_type) bool GLGizmoSVG::create_volume(ModelVolumeType volume_type)
{ {
CreateVolumeParams input = priv::create_input(m_parent, m_raycast_manager, volume_type);
DataBasePtr base = priv::create_emboss_data_base(m_job_cancel); DataBasePtr base = priv::create_emboss_data_base(m_job_cancel);
Plater *plater_ptr = wxGetApp().plater(); return start_create_volume_without_position(input, std::move(base));
return start_create_volume_without_position(plater_ptr, std::move(base), volume_type, m_raycast_manager, GLGizmosManager::Svg);
} }
bool GLGizmoSVG::is_svg(const ModelVolume &volume) { bool GLGizmoSVG::is_svg(const ModelVolume &volume) {

File diff suppressed because it is too large Load Diff

View File

@ -19,9 +19,12 @@ namespace Slic3r {
class TriangleMesh; class TriangleMesh;
class ModelVolume; class ModelVolume;
enum class ModelVolumeType : int; enum class ModelVolumeType : int;
class BuildVolume;
namespace GUI { namespace GUI {
class RaycastManager; class RaycastManager;
class Plater; class Plater;
class GLCanvas3D;
class Worker;
}} }}
namespace Slic3r::GUI::Emboss { namespace Slic3r::GUI::Emboss {
@ -160,6 +163,42 @@ public:
/// <returns>Source data for cut surface from</returns> /// <returns>Source data for cut surface from</returns>
SurfaceVolumeData::ModelSources create_volume_sources(const ModelVolume &volume); SurfaceVolumeData::ModelSources create_volume_sources(const ModelVolume &volume);
/// <summary>
/// shorten params for start_crate_volume functions
/// </summary>
struct CreateVolumeParams
{
GLCanvas3D &canvas;
// Direction of ray into scene
const Camera &camera;
// To put new object on the build volume
const BuildVolume &build_volume;
// used to emplace job for execution
Worker &worker;
// New created volume type
ModelVolumeType volume_type;
// Contain AABB trees from scene
RaycastManager &raycaster;
// Define which gizmo open on the success
unsigned char gizmo; // GLGizmosManager::EType
// Volume define object to add new volume
const GLVolume *gl_volume;
// Wanted additionl move in Z(emboss) direction of new created volume
std::optional<float> distance = {};
// Wanted additionl rotation around Z of new created volume
std::optional<float> angle = {};
};
/// <summary> /// <summary>
/// Create new volume on position of mouse cursor /// Create new volume on position of mouse cursor
/// </summary> /// </summary>
@ -172,27 +211,13 @@ SurfaceVolumeData::ModelSources create_volume_sources(const ModelVolume &volume)
/// <param name="distance">Wanted additionl move in Z(emboss) direction of new created volume</param> /// <param name="distance">Wanted additionl move in Z(emboss) direction of new created volume</param>
/// <param name="angle">Wanted additionl rotation around Z of new created volume</param> /// <param name="angle">Wanted additionl rotation around Z of new created volume</param>
/// <returns>True on success otherwise False</returns> /// <returns>True on success otherwise False</returns>
bool start_create_volume(Plater *plater_ptr, bool start_create_volume(CreateVolumeParams &input, DataBasePtr data, const Vec2d &mouse_pos);
DataBasePtr data,
ModelVolumeType volume_type,
RaycastManager &raycaster,
unsigned char gizmo,
const Vec2d &mouse_pos,
const std::optional<float> &distance = {},
const std::optional<float> &angle = {});
/// <summary> /// <summary>
/// Same as previous function but without mouse position /// Same as previous function but without mouse position
/// Need to suggest position or put near the selection /// Need to suggest position or put near the selection
/// </summary> /// </summary>
bool start_create_volume_without_position(Plater *plater_ptr, bool start_create_volume_without_position(CreateVolumeParams &input, DataBasePtr data);
DataBasePtr data,
ModelVolumeType volume_type,
RaycastManager &raycaster,
unsigned char gizmo,
const std::optional<float> &distance = {},
const std::optional<float> &angle = {});
} // namespace Slic3r::GUI } // namespace Slic3r::GUI
#endif // slic3r_EmbossJob_hpp_ #endif // slic3r_EmbossJob_hpp_