Part: move handling of changed properties of the Primitive class to handleChangedPropertyName and handleChangedPropertyType
This commit is contained in:
@@ -132,59 +132,33 @@ PyObject* Primitive::getPyObject()
|
||||
|
||||
void Primitive::Restore(Base::XMLReader &reader)
|
||||
{
|
||||
reader.readElement("Properties");
|
||||
int Cnt = reader.getAttributeAsInteger("Count");
|
||||
Part::Feature::Restore(reader);
|
||||
}
|
||||
|
||||
for (int i=0 ;i<Cnt ;i++) {
|
||||
reader.readElement("Property");
|
||||
const char* PropName = reader.getAttribute("name");
|
||||
const char* TypeName = reader.getAttribute("type");
|
||||
App::Property* prop = getPropertyByName(PropName);
|
||||
// For #0001652 the property types of many primitive features have changed
|
||||
// from PropertyFloat or PropertyFloatConstraint to a more meaningful type.
|
||||
// In order to load older project files there must be checked in case the
|
||||
// types don't match if both inherit from PropertyFloat because all derived
|
||||
// classes do not re-implement the Save/Restore methods.
|
||||
try {
|
||||
if (prop && strcmp(prop->getTypeId().getName(), TypeName) == 0) {
|
||||
prop->Restore(reader);
|
||||
}
|
||||
else if (prop) {
|
||||
Base::Type inputType = Base::Type::fromName(TypeName);
|
||||
if (prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId()) &&
|
||||
inputType.isDerivedFrom(App::PropertyFloat::getClassTypeId())) {
|
||||
// Do not directly call the property's Restore method in case the implementation
|
||||
// has changed. So, create a temporary PropertyFloat object and assign the value.
|
||||
App::PropertyFloat floatProp;
|
||||
floatProp.Restore(reader);
|
||||
static_cast<App::PropertyFloat*>(prop)->setValue(floatProp.getValue());
|
||||
}
|
||||
}
|
||||
else {
|
||||
extHandleChangedPropertyName(reader, TypeName, PropName); // AttachExtension
|
||||
}
|
||||
}
|
||||
catch (const Base::XMLParseException&) {
|
||||
throw; // re-throw
|
||||
}
|
||||
catch (const Base::Exception &e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
}
|
||||
catch (const char* e) {
|
||||
Base::Console().Error("%s\n", e);
|
||||
}
|
||||
#ifndef FC_DEBUG
|
||||
catch (...) {
|
||||
Base::Console().Error("Primitive::Restore: Unknown C++ exception thrown\n");
|
||||
}
|
||||
#endif
|
||||
void Primitive::handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName)
|
||||
{
|
||||
extHandleChangedPropertyName(reader, TypeName, PropName); // AttachExtension
|
||||
}
|
||||
|
||||
reader.readEndElement("Property");
|
||||
void Primitive::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop)
|
||||
{
|
||||
// For #0001652 the property types of many primitive features have changed
|
||||
// from PropertyFloat or PropertyFloatConstraint to a more meaningful type.
|
||||
// In order to load older project files there must be checked in case the
|
||||
// types don't match if both inherit from PropertyFloat because all derived
|
||||
// classes do not re-implement the Save/Restore methods.
|
||||
Base::Type inputType = Base::Type::fromName(TypeName);
|
||||
if (prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId()) &&
|
||||
inputType.isDerivedFrom(App::PropertyFloat::getClassTypeId())) {
|
||||
// Do not directly call the property's Restore method in case the implementation
|
||||
// has changed. So, create a temporary PropertyFloat object and assign the value.
|
||||
App::PropertyFloat floatProp;
|
||||
floatProp.Restore(reader);
|
||||
static_cast<App::PropertyFloat*>(prop)->setValue(floatProp.getValue());
|
||||
}
|
||||
else {
|
||||
Part::Feature::handleChangedPropertyType(reader, TypeName, prop);
|
||||
}
|
||||
reader.readEndElement("Properties");
|
||||
}
|
||||
|
||||
void Primitive::onChanged(const App::Property* prop)
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
protected:
|
||||
void Restore(Base::XMLReader &reader) override;
|
||||
void onChanged (const App::Property* prop) override;
|
||||
virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName) override;
|
||||
virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop) override;
|
||||
};
|
||||
|
||||
class PartExport Vertex : public Part::Primitive
|
||||
|
||||
Reference in New Issue
Block a user