From 133ff16d0abea474356b90837713282380a922e7 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 5 May 2016 18:38:36 +0200 Subject: [PATCH] + avoid code duplication --- src/App/PropertyLinks.cpp | 38 ------------------------------- src/App/PropertyLinks.h | 1 - src/Mod/Part/App/Part2DObject.cpp | 21 +++++++++-------- 3 files changed, 11 insertions(+), 49 deletions(-) diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 4277e1177..79aa219f7 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -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 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(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(); diff --git a/src/App/PropertyLinks.h b/src/App/PropertyLinks.h index 42a8ce85b..c91a06884 100644 --- a/src/App/PropertyLinks.h +++ b/src/App/PropertyLinks.h @@ -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); diff --git a/src/Mod/Part/App/Part2DObject.cpp b/src/Mod/Part/App/Part2DObject.cpp index 41b46b575..c02b930a0 100644 --- a/src/Mod/Part/App/Part2DObject.cpp +++ b/src/Mod/Part/App/Part2DObject.cpp @@ -196,14 +196,14 @@ bool Part2DObject::seekTrimPoints(const std::vector &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(prop)->RestoreFromLinkSub(reader); + tmp.setContainer(this); + tmp.Restore(reader); + static_cast(prop)->setValue(tmp.getValue(), tmp.getSubValues()); } this->MapMode.setValue(Attacher::mmFlatFace); }