+ avoid code duplication

This commit is contained in:
wmayer 2016-05-05 18:38:36 +02:00
parent f5b48a636d
commit 133ff16d0a
3 changed files with 11 additions and 49 deletions

View File

@ -838,44 +838,6 @@ void PropertyLinkSubList::Restore(Base::XMLReader &reader)
setValues(values,SubNames);
}
void PropertyLinkSubList::RestoreFromLinkSub(XMLReader &reader)
{
//Copy-paste from PropertyLinkSub::Restore()
// read my element
reader.readElement("LinkSub");
// get the values of my attributes
std::string name = reader.getAttribute("value");
int count = reader.getAttributeAsInteger("count");
// Property not in a DocumentObject!
assert(getContainer()->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId()) );
std::vector<std::string> values(count);
for (int i = 0; i < count; i++) {
reader.readElement("Sub");
values[i] = reader.getAttribute("value");
}
reader.readEndElement("LinkSub");
DocumentObject *pcObject;
if (name != ""){
App::Document* document = static_cast<DocumentObject*>(getContainer())->getDocument();
pcObject = document ? document->getObject(name.c_str()) : 0;
if (!pcObject) {
if (reader.isVerbose()) {
Base::Console().Warning("Lost link to '%s' while loading, maybe "
"an object was not loaded correctly\n",name.c_str());
}
}
setValue(pcObject,values);
}
else {
setValue(0);
}
}
Property *PropertyLinkSubList::Copy(void) const
{
PropertyLinkSubList *p = new PropertyLinkSubList();

View File

@ -279,7 +279,6 @@ public:
virtual void Save (Base::Writer &writer) const;
virtual void Restore(Base::XMLReader &reader);
virtual void RestoreFromLinkSub(Base::XMLReader &reader);
virtual Property *Copy(void) const;
virtual void Paste(const Property &from);

View File

@ -196,14 +196,14 @@ bool Part2DObject::seekTrimPoints(const std::vector<Geometry *> &geomlist,
}
}
if (GeoId1 < 0 && GeoId2 < 0)
return false;
if (GeoId1 < 0 && GeoId2 < 0)
return false;
if (GeoId1 >= 0)
intersect1 = Base::Vector3d(p1.X(),p1.Y(),0.f);
if (GeoId2 >= 0)
intersect2 = Base::Vector3d(p2.X(),p2.Y(),0.f);
return true;
if (GeoId1 >= 0)
intersect1 = Base::Vector3d(p1.X(),p1.Y(),0.f);
if (GeoId2 >= 0)
intersect2 = Base::Vector3d(p2.X(),p2.Y(),0.f);
return true;
}
void Part2DObject::acceptGeometry()
@ -227,16 +227,17 @@ void Part2DObject::Restore(Base::XMLReader &reader)
// 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.
// Exception: PropertyLinkSubList can read PropertyLinkSub
try {
if(prop){
if (strcmp(prop->getTypeId().getName(), TypeName) == 0){
prop->Restore(reader);
} else if (prop->isDerivedFrom(App::PropertyLinkSubList::getClassTypeId())){
//reading legacy Support - when the Support could only be a single flat face.
App::PropertyLinkSub tmp;//getTypeId() is not static =(
App::PropertyLinkSub tmp;
if (0 == strcmp(tmp.getTypeId().getName(),TypeName)) {
static_cast<App::PropertyLinkSubList*>(prop)->RestoreFromLinkSub(reader);
tmp.setContainer(this);
tmp.Restore(reader);
static_cast<App::PropertyLinkSubList*>(prop)->setValue(tmp.getValue(), tmp.getSubValues());
}
this->MapMode.setValue(Attacher::mmFlatFace);
}