mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 22:16:09 +08:00
Remove unnecessary ctors of data types,
no more need to use unique ptr to data
This commit is contained in:
parent
ef420c9b72
commit
3772b3d0b5
@ -153,10 +153,12 @@ void GLGizmoEmboss::create_volume(ModelVolumeType volume_type, const Vec2d& mous
|
||||
const Camera &camera = plater->get_camera();
|
||||
const Pointfs &bed_shape = plater->build_volume().bed_shape();
|
||||
auto &worker = plater->get_ui_job_worker();
|
||||
auto data = std::make_unique<EmbossDataCreateObject>(
|
||||
m_font_manager.get_font().font_file_with_cache,
|
||||
create_configuration(), create_volume_name(),
|
||||
screen_coor, camera, bed_shape);
|
||||
EmbossDataCreateObject data{m_font_manager.get_font().font_file_with_cache,
|
||||
create_configuration(),
|
||||
create_volume_name(),
|
||||
screen_coor,
|
||||
camera,
|
||||
bed_shape};
|
||||
queue_job(worker, std::make_unique<EmbossCreateObjectJob>(std::move(data)));
|
||||
}
|
||||
|
||||
@ -656,11 +658,16 @@ bool GLGizmoEmboss::start_volume_creation(ModelVolumeType volume_type,
|
||||
|
||||
// create volume
|
||||
auto &worker = plater->get_ui_job_worker();
|
||||
auto data = std::make_unique<EmbossDataCreateVolume>(
|
||||
m_font_manager.get_font().font_file_with_cache,
|
||||
create_configuration(), create_volume_name(), volume_type,
|
||||
screen_coor, object_idx, camera, *hit, hit_object_trmat,
|
||||
hit_instance_trmat);
|
||||
EmbossDataCreateVolume data{m_font_manager.get_font().font_file_with_cache,
|
||||
create_configuration(),
|
||||
create_volume_name(),
|
||||
volume_type,
|
||||
screen_coor,
|
||||
object_idx_signed,
|
||||
camera,
|
||||
*hit,
|
||||
hit_object_trmat,
|
||||
hit_instance_trmat};
|
||||
queue_job(worker, std::make_unique<EmbossCreateVolumeJob>(std::move(data)));
|
||||
return true;
|
||||
}
|
||||
@ -741,9 +748,9 @@ bool GLGizmoEmboss::process()
|
||||
|
||||
// IMPROVE: Cancel only EmbossUpdateJob no others
|
||||
worker.cancel();
|
||||
auto data = std::make_unique<EmbossDataUpdate>(
|
||||
font, create_configuration(), create_volume_name(),
|
||||
m_volume->id(), m_update_job_cancel);
|
||||
EmbossDataUpdate data{font, create_configuration(), create_volume_name(),
|
||||
m_volume->id(), m_update_job_cancel};
|
||||
|
||||
queue_job(worker, std::make_unique<EmbossUpdateJob>(std::move(data)));
|
||||
|
||||
// notification is removed befor object is changed by job
|
||||
|
@ -44,17 +44,17 @@ static TriangleMesh create_default_mesh();
|
||||
|
||||
/////////////////
|
||||
/// Update Volume
|
||||
EmbossUpdateJob::EmbossUpdateJob(std::unique_ptr<EmbossDataUpdate> input)
|
||||
EmbossUpdateJob::EmbossUpdateJob(EmbossDataUpdate&& input)
|
||||
: m_input(std::move(input))
|
||||
{}
|
||||
|
||||
void EmbossUpdateJob::process(Ctl &ctl)
|
||||
{
|
||||
// check if exist valid font
|
||||
if (!m_input->font_file.has_value()) return;
|
||||
if (!m_input.font_file.has_value()) return;
|
||||
|
||||
const TextConfiguration &cfg = m_input->text_configuration;
|
||||
m_result = priv::create_mesh(cfg.text.c_str(), m_input->font_file,
|
||||
const TextConfiguration &cfg = m_input.text_configuration;
|
||||
m_result = priv::create_mesh(cfg.text.c_str(), m_input.font_file,
|
||||
cfg.font_item.prop, ctl);
|
||||
if (m_result.its.empty()) return;
|
||||
if (ctl.was_canceled()) return;
|
||||
@ -66,7 +66,7 @@ void EmbossUpdateJob::process(Ctl &ctl)
|
||||
|
||||
void EmbossUpdateJob::finalize(bool canceled, std::exception_ptr &)
|
||||
{
|
||||
if (canceled || *m_input->cancel) return;
|
||||
if (canceled || *m_input.cancel) return;
|
||||
|
||||
// for sure that some object is created from shape
|
||||
if (m_result.its.indices.empty()) return;
|
||||
@ -80,14 +80,14 @@ void EmbossUpdateJob::finalize(bool canceled, std::exception_ptr &)
|
||||
// Check emboss gizmo is still open
|
||||
if (manager.get_current_type() != GLGizmosManager::Emboss) return;
|
||||
|
||||
std::string snap_name = GUI::format(_L("Text: %1%"), m_input->text_configuration.text);
|
||||
std::string snap_name = GUI::format(_L("Text: %1%"), m_input.text_configuration.text);
|
||||
Plater::TakeSnapshot snapshot(plater, snap_name, UndoRedo::SnapshotType::GizmoAction);
|
||||
|
||||
ModelVolume *volume = nullptr;
|
||||
Model &model = plater->model();
|
||||
for (auto obj : model.objects)
|
||||
for (auto vol : obj->volumes)
|
||||
if (vol->id() == m_input->volume_id) {
|
||||
if (vol->id() == m_input.volume_id) {
|
||||
volume = vol;
|
||||
break;
|
||||
}
|
||||
@ -101,8 +101,8 @@ void EmbossUpdateJob::finalize(bool canceled, std::exception_ptr &)
|
||||
volume->set_new_unique_id();
|
||||
volume->calculate_convex_hull();
|
||||
volume->get_object()->invalidate_bounding_box();
|
||||
volume->name = m_input->volume_name;
|
||||
volume->text_configuration = m_input->text_configuration;
|
||||
volume->name = m_input.volume_name;
|
||||
volume->text_configuration = m_input.text_configuration;
|
||||
|
||||
// update volume in right panel( volume / object name)
|
||||
const Selection &selection = canvas->get_selection();
|
||||
@ -124,29 +124,28 @@ void EmbossUpdateJob::finalize(bool canceled, std::exception_ptr &)
|
||||
|
||||
/////////////////
|
||||
/// Create Volume
|
||||
EmbossCreateVolumeJob::EmbossCreateVolumeJob(
|
||||
std::unique_ptr<EmbossDataCreateVolume> input)
|
||||
EmbossCreateVolumeJob::EmbossCreateVolumeJob(EmbossDataCreateVolume &&input)
|
||||
: m_input(std::move(input))
|
||||
{}
|
||||
|
||||
void EmbossCreateVolumeJob::process(Ctl &ctl) {
|
||||
// It is neccessary to create some shape
|
||||
// Emboss text window is opened by creation new emboss text object
|
||||
const char *text = m_input->text_configuration.text.c_str();
|
||||
FontProp &prop = m_input->text_configuration.font_item.prop;
|
||||
const char *text = m_input.text_configuration.text.c_str();
|
||||
FontProp &prop = m_input.text_configuration.font_item.prop;
|
||||
|
||||
m_result = priv::create_mesh(text, m_input->font_file, prop, ctl);
|
||||
m_result = priv::create_mesh(text, m_input.font_file, prop, ctl);
|
||||
if (m_result.its.empty()) m_result = priv::create_default_mesh();
|
||||
|
||||
if (ctl.was_canceled()) return;
|
||||
|
||||
// Create new volume inside of object
|
||||
const FontProp &font_prop = m_input->text_configuration.font_item.prop;
|
||||
const FontProp &font_prop = m_input.text_configuration.font_item.prop;
|
||||
Transform3d surface_trmat = Emboss::create_transformation_onto_surface(
|
||||
m_input->hit.position, m_input->hit.normal);
|
||||
m_input.hit.position, m_input.hit.normal);
|
||||
Emboss::apply_transformation(font_prop, surface_trmat);
|
||||
m_transformation = m_input->hit_instance_tr.inverse() *
|
||||
m_input->hit_object_tr * surface_trmat;
|
||||
m_transformation = m_input.hit_instance_tr.inverse() *
|
||||
m_input.hit_object_tr * surface_trmat;
|
||||
}
|
||||
|
||||
void EmbossCreateVolumeJob::finalize(bool canceled, std::exception_ptr &) {
|
||||
@ -159,14 +158,14 @@ void EmbossCreateVolumeJob::finalize(bool canceled, std::exception_ptr &) {
|
||||
Model &model = plater->model();
|
||||
|
||||
// create volume in object
|
||||
size_t object_idx = m_input->object_idx;
|
||||
size_t object_idx = m_input.object_idx;
|
||||
assert(model.objects.size() > object_idx);
|
||||
if (model.objects.size() <= object_idx) return;
|
||||
|
||||
Plater::TakeSnapshot snapshot(plater, _L("Add Emboss text Volume"));
|
||||
|
||||
ModelObject *obj = model.objects[object_idx];
|
||||
ModelVolumeType type = m_input->volume_type;
|
||||
ModelVolumeType type = m_input.volume_type;
|
||||
ModelVolume *volume = obj->add_volume(std::move(m_result), type);
|
||||
|
||||
// set a default extruder value, since user can't add it manually
|
||||
@ -175,8 +174,8 @@ void EmbossCreateVolumeJob::finalize(bool canceled, std::exception_ptr &) {
|
||||
// do not allow model reload from disk
|
||||
volume->source.is_from_builtin_objects = true;
|
||||
|
||||
volume->name = m_input->volume_name;
|
||||
volume->text_configuration = std::move(m_input->text_configuration);
|
||||
volume->name = m_input.volume_name;
|
||||
volume->text_configuration = std::move(m_input.text_configuration);
|
||||
volume->set_transformation(m_transformation);
|
||||
|
||||
// update volume name in object list
|
||||
@ -209,8 +208,7 @@ void EmbossCreateVolumeJob::finalize(bool canceled, std::exception_ptr &) {
|
||||
|
||||
/////////////////
|
||||
/// Create Object
|
||||
EmbossCreateObjectJob::EmbossCreateObjectJob(
|
||||
std::unique_ptr<EmbossDataCreateObject> input)
|
||||
EmbossCreateObjectJob::EmbossCreateObjectJob(EmbossDataCreateObject &&input)
|
||||
: m_input(std::move(input))
|
||||
{}
|
||||
|
||||
@ -218,10 +216,10 @@ void EmbossCreateObjectJob::process(Ctl &ctl)
|
||||
{
|
||||
// It is neccessary to create some shape
|
||||
// Emboss text window is opened by creation new emboss text object
|
||||
const char *text = m_input->text_configuration.text.c_str();
|
||||
FontProp &prop = m_input->text_configuration.font_item.prop;
|
||||
const char *text = m_input.text_configuration.text.c_str();
|
||||
FontProp &prop = m_input.text_configuration.font_item.prop;
|
||||
|
||||
m_result = priv::create_mesh(text, m_input->font_file, prop, ctl);
|
||||
m_result = priv::create_mesh(text, m_input.font_file, prop, ctl);
|
||||
if (m_result.its.empty()) m_result = priv::create_default_mesh();
|
||||
|
||||
if (ctl.was_canceled()) return;
|
||||
@ -230,19 +228,19 @@ void EmbossCreateObjectJob::process(Ctl &ctl)
|
||||
// calculate X,Y offset position for lay on platter in place of
|
||||
// mouse click
|
||||
Vec2d bed_coor = CameraUtils::get_z0_position(
|
||||
m_input->camera, m_input->screen_coor);
|
||||
m_input.camera, m_input.screen_coor);
|
||||
|
||||
// check point is on build plate:
|
||||
Points bed_shape_;
|
||||
bed_shape_.reserve(m_input->bed_shape.size());
|
||||
for (const Vec2d &p : m_input->bed_shape)
|
||||
bed_shape_.reserve(m_input.bed_shape.size());
|
||||
for (const Vec2d &p : m_input.bed_shape)
|
||||
bed_shape_.emplace_back(p.cast<int>());
|
||||
Polygon bed(bed_shape_);
|
||||
if (!bed.contains(bed_coor.cast<int>()))
|
||||
// mouse pose is out of build plate so create object in center of plate
|
||||
bed_coor = bed.centroid().cast<double>();
|
||||
|
||||
double z = m_input->text_configuration.font_item.prop.emboss / 2;
|
||||
double z = m_input.text_configuration.font_item.prop.emboss / 2;
|
||||
Vec3d offset(bed_coor.x(), bed_coor.y(), z);
|
||||
offset -= m_result.center();
|
||||
Transform3d::TranslationType tt(offset.x(), offset.y(), offset.z());
|
||||
@ -262,8 +260,8 @@ void EmbossCreateObjectJob::finalize(bool canceled, std::exception_ptr &)
|
||||
|
||||
// Create new object and change selection
|
||||
bool center = false;
|
||||
obj_list->load_mesh_object(std::move(m_result), m_input->volume_name,
|
||||
center, &m_input->text_configuration,
|
||||
obj_list->load_mesh_object(std::move(m_result), m_input.volume_name,
|
||||
center, &m_input.text_configuration,
|
||||
&m_transformation);
|
||||
|
||||
// When add new object selection is empty.
|
||||
|
@ -14,63 +14,6 @@ class TriangleMesh;
|
||||
|
||||
namespace Slic3r::GUI {
|
||||
|
||||
struct EmbossDataUpdate;
|
||||
struct EmbossDataCreateVolume;
|
||||
struct EmbossDataCreateObject;
|
||||
|
||||
/// <summary>
|
||||
/// Update text shape in existing text volume
|
||||
/// </summary>
|
||||
class EmbossUpdateJob : public Job
|
||||
{
|
||||
std::unique_ptr<EmbossDataUpdate> m_input;
|
||||
TriangleMesh m_result;
|
||||
|
||||
public:
|
||||
EmbossUpdateJob(std::unique_ptr<EmbossDataUpdate> input);
|
||||
void process(Ctl &ctl) override;
|
||||
|
||||
/// <summary>
|
||||
/// Update volume - change object_id
|
||||
/// </summary>
|
||||
/// <param name="canceled">Was process canceled.
|
||||
/// NOTE: Be carefull it doesn't care about
|
||||
/// time between finished process and started finalize part.</param>
|
||||
/// <param name="">unused</param>
|
||||
void finalize(bool canceled, std::exception_ptr &) override;
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create new TextVolume on the surface of ModelObject
|
||||
/// </summary>
|
||||
class EmbossCreateVolumeJob : public Job
|
||||
{
|
||||
std::unique_ptr<EmbossDataCreateVolume> m_input;
|
||||
TriangleMesh m_result;
|
||||
Transform3d m_transformation;
|
||||
|
||||
public:
|
||||
EmbossCreateVolumeJob(std::unique_ptr<EmbossDataCreateVolume> input);
|
||||
void process(Ctl &ctl) override;
|
||||
void finalize(bool canceled, std::exception_ptr &) override;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Create new TextObject on the platter
|
||||
/// </summary>
|
||||
class EmbossCreateObjectJob : public Job
|
||||
{
|
||||
std::unique_ptr<EmbossDataCreateObject> m_input;
|
||||
TriangleMesh m_result;
|
||||
Transform3d m_transformation;
|
||||
|
||||
public:
|
||||
EmbossCreateObjectJob(std::unique_ptr<EmbossDataCreateObject> input);
|
||||
void process(Ctl &ctl) override;
|
||||
void finalize(bool canceled, std::exception_ptr &) override;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Base data holder for embossing
|
||||
/// </summary>
|
||||
@ -82,13 +25,6 @@ struct EmbossDataBase
|
||||
TextConfiguration text_configuration;
|
||||
// new volume name created from text
|
||||
std::string volume_name;
|
||||
EmbossDataBase(Emboss::FontFileWithCache font_file,
|
||||
TextConfiguration text_configuration,
|
||||
std::string volume_name)
|
||||
: font_file(font_file)
|
||||
, text_configuration(text_configuration)
|
||||
, volume_name(volume_name)
|
||||
{}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@ -102,19 +38,6 @@ struct EmbossDataUpdate : public EmbossDataBase
|
||||
// flag that job is canceled
|
||||
// for time after process.
|
||||
std::shared_ptr<bool> cancel;
|
||||
|
||||
// unique identifier of volume to change
|
||||
// Change of volume change id, last change could disapear
|
||||
// ObjectID volume_id;
|
||||
EmbossDataUpdate(Emboss::FontFileWithCache font_file,
|
||||
TextConfiguration text_configuration,
|
||||
std::string volume_name,
|
||||
ObjectID volume_id,
|
||||
std::shared_ptr<bool> cancel)
|
||||
: EmbossDataBase(font_file, text_configuration, volume_name)
|
||||
, volume_id(volume_id)
|
||||
, cancel(std::move(cancel))
|
||||
{}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@ -139,26 +62,6 @@ struct EmbossDataCreateVolume : public EmbossDataBase
|
||||
RaycastManager::SurfacePoint hit;
|
||||
Transform3d hit_object_tr;
|
||||
Transform3d hit_instance_tr;
|
||||
|
||||
EmbossDataCreateVolume(Emboss::FontFileWithCache font_file,
|
||||
const TextConfiguration &text_configuration,
|
||||
const std::string &volume_name,
|
||||
ModelVolumeType volume_type,
|
||||
Vec2d screen_coor,
|
||||
int object_idx,
|
||||
const Camera &camera,
|
||||
const RaycastManager::SurfacePoint &hit,
|
||||
const Transform3d &hit_object_tr,
|
||||
const Transform3d &hit_instance_tr)
|
||||
: EmbossDataBase(font_file, text_configuration, volume_name)
|
||||
, volume_type(volume_type)
|
||||
, screen_coor(screen_coor)
|
||||
, object_idx(object_idx)
|
||||
, camera(camera)
|
||||
, hit(hit)
|
||||
, hit_object_tr(hit_object_tr)
|
||||
, hit_instance_tr(hit_instance_tr)
|
||||
{}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@ -176,18 +79,59 @@ struct EmbossDataCreateObject : public EmbossDataBase
|
||||
|
||||
// shape of bed in case of create volume on bed
|
||||
std::vector<Vec2d> bed_shape;
|
||||
};
|
||||
|
||||
EmbossDataCreateObject(Emboss::FontFileWithCache font_file,
|
||||
const TextConfiguration &text_configuration,
|
||||
const std::string &volume_name,
|
||||
Vec2d screen_coor,
|
||||
const Camera &camera,
|
||||
const std::vector<Vec2d> &bed_shape)
|
||||
: EmbossDataBase(font_file, text_configuration, volume_name)
|
||||
, screen_coor(screen_coor)
|
||||
, camera(camera)
|
||||
, bed_shape(bed_shape)
|
||||
{}
|
||||
/// <summary>
|
||||
/// Update text shape in existing text volume
|
||||
/// </summary>
|
||||
class EmbossUpdateJob : public Job
|
||||
{
|
||||
EmbossDataUpdate m_input;
|
||||
TriangleMesh m_result;
|
||||
|
||||
public:
|
||||
EmbossUpdateJob(EmbossDataUpdate&& input);
|
||||
void process(Ctl &ctl) override;
|
||||
|
||||
/// <summary>
|
||||
/// Update volume - change object_id
|
||||
/// </summary>
|
||||
/// <param name="canceled">Was process canceled.
|
||||
/// NOTE: Be carefull it doesn't care about
|
||||
/// time between finished process and started finalize part.</param>
|
||||
/// <param name="">unused</param>
|
||||
void finalize(bool canceled, std::exception_ptr &) override;
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create new TextVolume on the surface of ModelObject
|
||||
/// </summary>
|
||||
class EmbossCreateVolumeJob : public Job
|
||||
{
|
||||
EmbossDataCreateVolume m_input;
|
||||
TriangleMesh m_result;
|
||||
Transform3d m_transformation;
|
||||
|
||||
public:
|
||||
EmbossCreateVolumeJob(EmbossDataCreateVolume&& input);
|
||||
void process(Ctl &ctl) override;
|
||||
void finalize(bool canceled, std::exception_ptr &) override;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Create new TextObject on the platter
|
||||
/// </summary>
|
||||
class EmbossCreateObjectJob : public Job
|
||||
{
|
||||
EmbossDataCreateObject m_input;
|
||||
TriangleMesh m_result;
|
||||
Transform3d m_transformation;
|
||||
|
||||
public:
|
||||
EmbossCreateObjectJob(EmbossDataCreateObject&& input);
|
||||
void process(Ctl &ctl) override;
|
||||
void finalize(bool canceled, std::exception_ptr &) override;
|
||||
};
|
||||
|
||||
} // namespace Slic3r::GUI
|
||||
|
Loading…
x
Reference in New Issue
Block a user