Creation by jobs
This commit is contained in:
parent
53ee0092b0
commit
d10fd37b2f
4 changed files with 324 additions and 379 deletions
|
@ -1,7 +1,9 @@
|
|||
#ifndef slic3r_EmbossJob_hpp_
|
||||
#define slic3r_EmbossJob_hpp_
|
||||
|
||||
#include "libslic3r/Emboss.hpp"
|
||||
#include <libslic3r/Emboss.hpp>
|
||||
#include <libslic3r/ModelVolumeType.hpp>
|
||||
#include "slic3r/Utils/RaycastManager.hpp"
|
||||
#include "Job.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
@ -11,42 +13,119 @@ class TriangleMesh;
|
|||
|
||||
namespace Slic3r::GUI {
|
||||
|
||||
struct EmbossData
|
||||
struct EmbossDataUpdate;
|
||||
struct EmbossDataCreate;
|
||||
|
||||
class EmbossUpdateJob : public Job
|
||||
{
|
||||
std::unique_ptr<EmbossDataUpdate> m_input;
|
||||
TriangleMesh m_result;
|
||||
public:
|
||||
EmbossUpdateJob(std::unique_ptr<EmbossDataUpdate> input) : m_input(std::move(input)) {}
|
||||
void process(Ctl &ctl) override;
|
||||
void finalize(bool canceled, std::exception_ptr &) override;
|
||||
};
|
||||
|
||||
class EmbossCreateJob : public Job
|
||||
{
|
||||
std::unique_ptr<EmbossDataCreate> m_input;
|
||||
TriangleMesh m_result;
|
||||
Transform3d m_transformation;
|
||||
public:
|
||||
EmbossCreateJob(std::unique_ptr<EmbossDataCreate> input): m_input(std::move(input)){}
|
||||
void process(Ctl &ctl) override;
|
||||
void finalize(bool canceled, std::exception_ptr &) override;
|
||||
|
||||
private:
|
||||
static TriangleMesh create_default_mesh();
|
||||
|
||||
/// <summary>
|
||||
/// Create mesh from text
|
||||
/// </summary>
|
||||
/// <param name="text">Text to convert on mesh</param>
|
||||
/// <param name="font">Define shape of characters.
|
||||
/// NOTE: Can't be const cache glyphs</param>
|
||||
/// <param name="font_prop">Property of font</param>
|
||||
/// <returns>Triangle mesh model</returns>
|
||||
static TriangleMesh create_mesh(const char * text,
|
||||
Emboss::FontFile &font,
|
||||
const FontProp & font_prop);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Base data holder for embossing
|
||||
/// </summary>
|
||||
struct EmbossDataBase
|
||||
{
|
||||
// Pointer on Data of font (glyph shapes)
|
||||
std::shared_ptr<Emboss::FontFile> font;
|
||||
std::shared_ptr<Emboss::FontFile> font_file;
|
||||
// font item is not used for create object
|
||||
TextConfiguration text_configuration;
|
||||
// new volume name created from text
|
||||
std::string volume_name;
|
||||
EmbossDataBase(std::shared_ptr<Emboss::FontFile> font_file,
|
||||
TextConfiguration text_configuration,
|
||||
std::string volume_name)
|
||||
: font_file(std::move(font_file))
|
||||
, text_configuration(text_configuration)
|
||||
, volume_name(volume_name)
|
||||
{}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Hold neccessary data to update embossed text object in job
|
||||
/// </summary>
|
||||
struct EmbossDataUpdate : public EmbossDataBase
|
||||
{
|
||||
// unique identifier of volume to change
|
||||
// I can't proove of alive pointer
|
||||
ModelVolume *volume;
|
||||
|
||||
// unique identifier of volume to change
|
||||
// Change of volume change id, last change could disapear
|
||||
//ObjectID volume_id;
|
||||
|
||||
EmbossData(std::shared_ptr<Emboss::FontFile> font,
|
||||
TextConfiguration text_configuration,
|
||||
std::string volume_name,
|
||||
ModelVolume * volume)
|
||||
: font(std::move(font))
|
||||
, text_configuration(text_configuration)
|
||||
, volume_name(volume_name)
|
||||
// ObjectID volume_id;
|
||||
EmbossDataUpdate(std::shared_ptr<Emboss::FontFile> font_file,
|
||||
TextConfiguration text_configuration,
|
||||
std::string volume_name,
|
||||
ModelVolume * volume)
|
||||
: EmbossDataBase(std::move(font_file), text_configuration, volume_name)
|
||||
, volume(volume)
|
||||
{}
|
||||
};
|
||||
|
||||
class EmbossJob : public Job
|
||||
/// <summary>
|
||||
/// Hold neccessary data to create embossed text object in job
|
||||
/// </summary>
|
||||
struct EmbossDataCreate: public EmbossDataBase
|
||||
{
|
||||
std::unique_ptr<EmbossData> m_input;
|
||||
TriangleMesh m_result;
|
||||
public:
|
||||
EmbossJob(std::unique_ptr<EmbossData> input) : m_input(std::move(input)) {}
|
||||
void process(Ctl &ctl) override;
|
||||
void finalize(bool canceled, std::exception_ptr &) override;
|
||||
// define embossed volume type
|
||||
ModelVolumeType volume_type;
|
||||
|
||||
// define position on screen where to create object
|
||||
Vec2d screen_coor;
|
||||
|
||||
// when exist ModelObject where to create volume
|
||||
std::optional<int> object_idx;
|
||||
|
||||
// used to find point on surface where to create new object
|
||||
RaycastManager *raycast_manager;
|
||||
// It is inside of GLGizmoEmboss object,
|
||||
// so I hope it will survive
|
||||
|
||||
EmbossDataCreate(std::shared_ptr<Emboss::FontFile> font_file,
|
||||
const TextConfiguration & text_configuration,
|
||||
const std::string & volume_name,
|
||||
ModelVolumeType volume_type,
|
||||
Vec2d screen_coor,
|
||||
std::optional<int> object_idx,
|
||||
RaycastManager * raycast_manager)
|
||||
: EmbossDataBase(std::move(font_file), text_configuration, volume_name)
|
||||
, volume_type(volume_type)
|
||||
, screen_coor(screen_coor)
|
||||
, object_idx(object_idx)
|
||||
, raycast_manager(raycast_manager)
|
||||
{}
|
||||
};
|
||||
|
||||
} // namespace Slic3r::GUI
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue