only add properties with property creator when they not already exist

This commit is contained in:
Max Lyon
2021-03-02 01:22:56 +01:00
parent a1b3729d32
commit 414c3507f2
2 changed files with 33 additions and 15 deletions

View File

@@ -829,31 +829,44 @@ size_t _OMReader_::restore_binary_custom_data(std::istream& _is, BaseProperty* _
//--------------------------------helper //--------------------------------helper
void _OMReader_:: add_generic_property(OMFormat::Chunk::PropertyName& _property_type, BaseImporter& _bi) const void _OMReader_:: add_generic_property(OMFormat::Chunk::PropertyName& _property_type, BaseImporter& _bi) const
{ {
// We want to support the old way of restoring properties, ie.
// the user has manually created the corresponding property.
// In that case the property does not need be registered.
// However, the _bi.kerne()->_get_prop(property_name_) checks below
// May return a property with the correct name but the wrong type.
// For now we will have to live with that.
PropertyCreationManager& manager = PropertyCreationManager::instance(); PropertyCreationManager& manager = PropertyCreationManager::instance();
switch (chunk_header_.entity_) switch (chunk_header_.entity_)
{ {
case OMFormat::Chunk::Entity_Vertex: case OMFormat::Chunk::Entity_Vertex:
{ {
if (_bi.kernel()->_get_vprop(property_name_) == nullptr)
manager.create_property<OpenMesh::VertexHandle>(*_bi.kernel(), _property_type, property_name_); manager.create_property<OpenMesh::VertexHandle>(*_bi.kernel(), _property_type, property_name_);
break; break;
} }
case OMFormat::Chunk::Entity_Face: case OMFormat::Chunk::Entity_Face:
{ {
if (_bi.kernel()->_get_fprop(property_name_) == nullptr)
manager.create_property<OpenMesh::FaceHandle>(*_bi.kernel(), _property_type, property_name_); manager.create_property<OpenMesh::FaceHandle>(*_bi.kernel(), _property_type, property_name_);
break; break;
} }
case OMFormat::Chunk::Entity_Edge: case OMFormat::Chunk::Entity_Edge:
{ {
if (_bi.kernel()->_get_eprop(property_name_) == nullptr)
manager.create_property<OpenMesh::EdgeHandle>(*_bi.kernel(), _property_type, property_name_); manager.create_property<OpenMesh::EdgeHandle>(*_bi.kernel(), _property_type, property_name_);
break; break;
} }
case OMFormat::Chunk::Entity_Halfedge: case OMFormat::Chunk::Entity_Halfedge:
{ {
if (_bi.kernel()->_get_hprop(property_name_) == nullptr)
manager.create_property<OpenMesh::HalfedgeHandle>(*_bi.kernel(), _property_type, property_name_); manager.create_property<OpenMesh::HalfedgeHandle>(*_bi.kernel(), _property_type, property_name_);
break; break;
} }
case OMFormat::Chunk::Entity_Mesh: case OMFormat::Chunk::Entity_Mesh:
{ {
if (_bi.kernel()->_get_mprop(property_name_) == nullptr)
manager.create_property<OpenMesh::MeshHandle>(*_bi.kernel(), _property_type, property_name_); manager.create_property<OpenMesh::MeshHandle>(*_bi.kernel(), _property_type, property_name_);
break; break;
} }

View File

@@ -116,16 +116,21 @@ class PropertyCreatorImpl : public PropertyCreator
{ {
public: public:
std::string type_id_string() override { return get_type_name<typename PropertyCreatorT::type>(); } std::string type_id_string() override { return get_type_name<typename PropertyCreatorT::type>(); }
void create_vertex_property (BaseKernel& _mesh, const std::string& _property_name) override { VPropHandleT<typename PropertyCreatorT::type> prop;
_mesh.add_property(prop, _property_name); } template <typename HandleT, typename PropT>
void create_halfedge_property(BaseKernel& _mesh, const std::string& _property_name) override { HPropHandleT<typename PropertyCreatorT::type> prop; void create_prop(BaseKernel& _mesh, const std::string& _property_name)
_mesh.add_property(prop, _property_name); } {
void create_edge_property (BaseKernel& _mesh, const std::string& _property_name) override { EPropHandleT<typename PropertyCreatorT::type> prop; using PHandle = typename PropHandle<HandleT>::template type<PropT>;
_mesh.add_property(prop, _property_name); } PHandle prop;
void create_face_property (BaseKernel& _mesh, const std::string& _property_name) override { FPropHandleT<typename PropertyCreatorT::type> prop; if (!_mesh.get_property_handle(prop, _property_name))
_mesh.add_property(prop, _property_name); } _mesh.add_property(prop, _property_name);
void create_mesh_property (BaseKernel& _mesh, const std::string& _property_name) override { MPropHandleT<typename PropertyCreatorT::type> prop; }
_mesh.add_property(prop, _property_name); }
void create_vertex_property (BaseKernel& _mesh, const std::string& _property_name) override { create_prop<VertexHandle , typename PropertyCreatorT::type>(_mesh, _property_name); }
void create_halfedge_property(BaseKernel& _mesh, const std::string& _property_name) override { create_prop<HalfedgeHandle, typename PropertyCreatorT::type>(_mesh, _property_name);}
void create_edge_property (BaseKernel& _mesh, const std::string& _property_name) override { create_prop<EdgeHandle , typename PropertyCreatorT::type>(_mesh, _property_name);}
void create_face_property (BaseKernel& _mesh, const std::string& _property_name) override { create_prop<FaceHandle , typename PropertyCreatorT::type>(_mesh, _property_name);}
void create_mesh_property (BaseKernel& _mesh, const std::string& _property_name) override { create_prop<MeshHandle , typename PropertyCreatorT::type>(_mesh, _property_name);}
~PropertyCreatorImpl() override {} ~PropertyCreatorImpl() override {}
protected: protected: