mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 02:05:58 +08:00
Refactor CutID - first part (SPE-2519)
This commit is contained in:
parent
c3ca39d5c5
commit
5cd697bdc2
@ -1191,7 +1191,7 @@ namespace Slic3r {
|
||||
for (const auto& obj_cut_info : object_tree) {
|
||||
if (obj_cut_info.first == "cut_id") {
|
||||
pt::ptree cut_id_tree = obj_cut_info.second;
|
||||
cut_id = CutObjectBase(ObjectID( cut_id_tree.get<size_t>("<xmlattr>.id")),
|
||||
cut_id = CutObjectBase(cut_id_tree.get<size_t>("<xmlattr>.id"),
|
||||
cut_id_tree.get<size_t>("<xmlattr>.check_sum"),
|
||||
cut_id_tree.get<size_t>("<xmlattr>.connectors_cnt"));
|
||||
}
|
||||
@ -3360,7 +3360,7 @@ namespace Slic3r {
|
||||
pt::ptree& cut_id_tree = obj_tree.add("cut_id", "");
|
||||
|
||||
// store cut_id atributes
|
||||
cut_id_tree.put("<xmlattr>.id", object->cut_id.id().id);
|
||||
cut_id_tree.put("<xmlattr>.id", object->cut_id.id());
|
||||
cut_id_tree.put("<xmlattr>.check_sum", object->cut_id.check_sum());
|
||||
cut_id_tree.put("<xmlattr>.connectors_cnt", object->cut_id.connectors_cnt());
|
||||
|
||||
|
@ -678,7 +678,7 @@ ModelObject& ModelObject::assign_copy(const ModelObject &rhs)
|
||||
this->layer_height_profile = rhs.layer_height_profile;
|
||||
this->printable = rhs.printable;
|
||||
this->origin_translation = rhs.origin_translation;
|
||||
this->cut_id.copy(rhs.cut_id);
|
||||
this->cut_id = rhs.cut_id;
|
||||
this->copy_transformation_caches(rhs);
|
||||
|
||||
this->clear_volumes();
|
||||
|
@ -506,7 +506,7 @@ public:
|
||||
bool has_negative_volume_mesh() const;
|
||||
// Detect if object has at least one sla drain hole
|
||||
bool has_sla_drain_holes() const { return !sla_drain_holes.empty(); }
|
||||
bool is_cut() const { return cut_id.id().valid(); }
|
||||
bool is_cut() const { return cut_id.valid(); }
|
||||
bool has_connectors() const;
|
||||
|
||||
private:
|
||||
|
@ -140,61 +140,38 @@ private:
|
||||
template<class Archive> void serialize(Archive &ar) { ar(m_timestamp); }
|
||||
};
|
||||
|
||||
class CutObjectBase : public ObjectBase
|
||||
class CutObjectBase
|
||||
{
|
||||
// check sum of CutParts in initial Object
|
||||
size_t m_check_sum{ 1 };
|
||||
// connectors count
|
||||
size_t m_connectors_cnt{ 0 };
|
||||
size_t m_unique_id; // 0 = invalid
|
||||
size_t m_check_sum; // check sum of CutParts in initial Object
|
||||
size_t m_connectors_cnt; // connectors count
|
||||
|
||||
public:
|
||||
// Default Constructor to assign an invalid ID
|
||||
CutObjectBase() : ObjectBase(-1) {}
|
||||
// Constructor with ignored int parameter to assign an invalid ID, to be replaced
|
||||
// by an existing ID copied from elsewhere.
|
||||
CutObjectBase(int) : ObjectBase(-1) {}
|
||||
// Constructor to initialize full information from 3mf
|
||||
CutObjectBase(ObjectID id, size_t check_sum, size_t connectors_cnt) : ObjectBase(id), m_check_sum(check_sum), m_connectors_cnt(connectors_cnt) {}
|
||||
// The class tree will have virtual tables and type information.
|
||||
virtual ~CutObjectBase() = default;
|
||||
|
||||
bool operator<(const CutObjectBase& other) const { return other.id() > this->id(); }
|
||||
bool operator==(const CutObjectBase& other) const { return other.id() == this->id(); }
|
||||
|
||||
void copy(const CutObjectBase& rhs) {
|
||||
this->copy_id(rhs);
|
||||
this->m_check_sum = rhs.check_sum();
|
||||
this->m_connectors_cnt = rhs.connectors_cnt() ;
|
||||
}
|
||||
CutObjectBase& operator=(const CutObjectBase& other) {
|
||||
this->copy(other);
|
||||
return *this;
|
||||
}
|
||||
CutObjectBase() { invalidate(); }
|
||||
CutObjectBase(size_t id, size_t check_sum, size_t connectors_cnt) :
|
||||
m_unique_id{ id }, m_check_sum{ check_sum }, m_connectors_cnt{ connectors_cnt } {}
|
||||
|
||||
void invalidate() {
|
||||
set_invalid_id();
|
||||
m_unique_id = 0;
|
||||
m_check_sum = 1;
|
||||
m_connectors_cnt = 0;
|
||||
}
|
||||
|
||||
void init() { this->set_new_unique_id(); }
|
||||
bool has_same_id(const CutObjectBase& rhs) { return this->id() == rhs.id(); }
|
||||
bool is_equal(const CutObjectBase& rhs) { return this->id() == rhs.id() &&
|
||||
this->check_sum() == rhs.check_sum() &&
|
||||
this->connectors_cnt() == rhs.connectors_cnt() ; }
|
||||
|
||||
void init() { m_unique_id = 1 + rand(); }
|
||||
bool has_same_id(const CutObjectBase& rhs) const { return id() == rhs.id(); }
|
||||
bool is_equal(const CutObjectBase& rhs) const { return id() == rhs.id() &&
|
||||
check_sum() == rhs.check_sum() &&
|
||||
connectors_cnt() == rhs.connectors_cnt() ; }
|
||||
size_t id() const { return m_unique_id; }
|
||||
bool valid() const { return m_unique_id != 0; }
|
||||
size_t check_sum() const { return m_check_sum; }
|
||||
void set_check_sum(size_t cs) { m_check_sum = cs; }
|
||||
void increase_check_sum(size_t cnt) { m_check_sum += cnt; }
|
||||
|
||||
size_t connectors_cnt() const { return m_connectors_cnt; }
|
||||
void increase_connectors_cnt(size_t connectors_cnt) { m_connectors_cnt += connectors_cnt; }
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template<class Archive> void serialize(Archive &ar) {
|
||||
ar(cereal::base_class<ObjectBase>(this));
|
||||
ar(m_check_sum, m_connectors_cnt);
|
||||
ar(m_unique_id, m_check_sum, m_connectors_cnt);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user