Skip to content

Commit

Permalink
PD: fix ProfileBased::Restore to not affect sub-classes that need to …
Browse files Browse the repository at this point in the history
…handle changed property types/names
  • Loading branch information
wwmayer committed Sep 15, 2021
1 parent e273954 commit 9fe1f56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 49 deletions.
73 changes: 24 additions & 49 deletions src/Mod/PartDesign/App/FeatureSketchBased.cpp
Expand Up @@ -1196,57 +1196,32 @@ Base::Vector3d ProfileBased::getProfileNormal() const {
return SketchVector;
}

void ProfileBased::Restore(Base::XMLReader& reader)
{
PartDesign::FeatureAddSub::Restore(reader);
}

void ProfileBased::Restore(Base::XMLReader& reader) {

reader.readElement("Properties");
int Cnt = reader.getAttributeAsInteger("Count");

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);
// NOTE: We must also check the type of the current property because a
// subclass of PropertyContainer might change the type of a property but
// not its name. In this case we would force to read-in a wrong property
// type and the behaviour would be undefined.
try {
//check if we load the old sketch property
if(!prop && (strcmp("Sketch", PropName) == 0) && (strcmp("App::PropertyLink", TypeName) == 0)) {

std::vector<std::string> vec;
// read my element
reader.readElement("Link");
// get the value of my attribute
std::string name = reader.getAttribute("value");

if (name != "") {
App::Document* document = getDocument();
DocumentObject* object = document ? document->getObject(name.c_str()) : 0;
Profile.setValue(object, vec);
}
else {
Profile.setValue(0, vec);
}
}
else if (prop && strcmp(prop->getTypeId().getName(), TypeName) == 0)
prop->Restore(reader);
}
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());
void ProfileBased::handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName)
{
//check if we load the old sketch property
if ((strcmp("Sketch", PropName) == 0) && (strcmp("App::PropertyLink", TypeName) == 0)) {

std::vector<std::string> vec;
// read my element
reader.readElement("Link");
// get the value of my attribute
std::string name = reader.getAttribute("value");

if (name != "") {
App::Document* document = getDocument();
DocumentObject* object = document ? document->getObject(name.c_str()) : 0;
Profile.setValue(object, vec);
}
catch (const char* e) {
Base::Console().Error("%s\n", e);
else {
Profile.setValue(0, vec);
}

reader.readEndElement("Property");
}
reader.readEndElement("Properties");
else {
PartDesign::FeatureAddSub::handleChangedPropertyName(reader, TypeName, PropName);
}
}
1 change: 1 addition & 0 deletions src/Mod/PartDesign/App/FeatureSketchBased.h
Expand Up @@ -112,6 +112,7 @@ class PartDesignExport ProfileBased : public PartDesign::FeatureAddSub

//backwards compatibility: profile property was renamed and has different type now
virtual void Restore(Base::XMLReader& reader);
virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName);

// calculate the through all length
double getThroughAllLength() const;
Expand Down

0 comments on commit 9fe1f56

Please sign in to comment.