Part/Sketcher: Refactor Geometry Extensions copy/save/restore AND attachment notification

=========================================================================================

- Long overdue refactor to avoid repetition during save/restore and copy.
- New interface to notify an extension when it is attached. It also enables the extension to gain
a pointer to the geometry container. This is intended to extend the functionality already existing
in Part::Geometry.
This commit is contained in:
Abdullah Tahiri
2021-01-08 14:18:52 +01:00
committed by abdullahtahiriyo
parent 927fdc9edc
commit e6af511f39
14 changed files with 141 additions and 84 deletions

View File

@@ -45,12 +45,39 @@ PyObject* GeometryExtension::copyPyObject() const
return static_cast<GeometryExtensionPy *>(obj.ptr())->copy(tuple.ptr());
}
void GeometryExtension::copyAttributes(Part::GeometryExtension * cpy) const
{
cpy->setName(this->getName()); // Base Class
}
TYPESYSTEM_SOURCE_ABSTRACT(Part::GeometryPersistenceExtension,Part::GeometryExtension)
void GeometryPersistenceExtension::restoreNameAttribute(Base::XMLReader &reader)
void GeometryPersistenceExtension::restoreAttributes(Base::XMLReader &reader)
{
if(reader.hasAttribute("name")) {
std::string name = reader.getAttribute("name");
setName(name);
}
}
void GeometryPersistenceExtension::saveAttributes(Base::Writer &writer) const
{
const std::string name = getName();
if(name.size() > 0)
writer.Stream() << "\" name=\"" << name;
}
void GeometryPersistenceExtension::Save(Base::Writer &writer) const
{
writer.Stream() << writer.ind() << "<GeoExtension type=\"" << this->getTypeId().getName();
saveAttributes(writer);
writer.Stream() << "\"/>" << std::endl;
}
void GeometryPersistenceExtension::Restore(Base::XMLReader &reader)
{
restoreAttributes(reader);
}