From 11239b034ca8cb5b76738931ae922109ecd90b5a Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 29 Apr 2015 16:33:20 +0200 Subject: [PATCH] + always keep digits at end when using copyObject, remove deprecated third parameter --- src/App/Document.cpp | 21 ++++++++++++--------- src/App/Document.h | 2 +- src/App/DocumentPyImp.cpp | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index f651e9b06..4f04be915 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -890,6 +890,7 @@ void Document::writeObjects(const std::vector& obj, std::vector Document::readObjects(Base::XMLReader& reader) { + bool keepDigits = d->keepTrailingDigits; d->keepTrailingDigits = !reader.doNameMapping(); std::vector objs; @@ -919,6 +920,7 @@ Document::readObjects(Base::XMLReader& reader) } } reader.readEndElement("Objects"); + d->keepTrailingDigits = keepDigits; // read the features itself reader.readElement("ObjectData"); @@ -1757,7 +1759,7 @@ void Document::breakDependency(DocumentObject* pcObject, bool clear) } } -DocumentObject* Document::copyObject(DocumentObject* obj, bool recursive, bool /*keepdigitsatend*/) +DocumentObject* Document::copyObject(DocumentObject* obj, bool recursive) { std::vector objs; objs.push_back(obj); @@ -1862,14 +1864,6 @@ std::string Document::getUniqueObjectName(const char *Name) const if (!Name || *Name == '\0') return std::string(); std::string CleanName = Base::Tools::getIdentifier(Name); - // remove also trailing digits from clean name which is to avoid to create lengthy names - // like 'Box001001' - if (!d->keepTrailingDigits) { - std::string::size_type index = CleanName.find_last_not_of("0123456789"); - if (index+1 < CleanName.size()) { - CleanName = CleanName.substr(0,index+1); - } - } // name in use? std::map::const_iterator pos; @@ -1880,6 +1874,15 @@ std::string Document::getUniqueObjectName(const char *Name) const return CleanName; } else { + // remove also trailing digits from clean name which is to avoid to create lengthy names + // like 'Box001001' + if (!d->keepTrailingDigits) { + std::string::size_type index = CleanName.find_last_not_of("0123456789"); + if (index+1 < CleanName.size()) { + CleanName = CleanName.substr(0,index+1); + } + } + std::vector names; names.reserve(d->objectMap.size()); for (pos = d->objectMap.begin();pos != d->objectMap.end();++pos) { diff --git a/src/App/Document.h b/src/App/Document.h index af1acb71e..b882ec694 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -168,7 +168,7 @@ public: * are copied as well. By default \a recursive is false. * Returns the copy of the object or 0 if the creation failed. */ - DocumentObject* copyObject(DocumentObject* obj, bool recursive=false, bool keepdigitsatend=false); + DocumentObject* copyObject(DocumentObject* obj, bool recursive=false); /** Move an object from another document to this document * If \a recursive is true then all objects this object depends on * are moved as well. By default \a recursive is false. diff --git a/src/App/DocumentPyImp.cpp b/src/App/DocumentPyImp.cpp index e377eaf70..8fcf53547 100644 --- a/src/App/DocumentPyImp.cpp +++ b/src/App/DocumentPyImp.cpp @@ -242,14 +242,14 @@ PyObject* DocumentPy::removeObject(PyObject *args) PyObject* DocumentPy::copyObject(PyObject *args) { + // 'keep' is not needed any more but leave it there for backward compatibility PyObject *obj, *rec=Py_False, *keep=Py_False; if (!PyArg_ParseTuple(args, "O!|O!O!",&(DocumentObjectPy::Type),&obj,&PyBool_Type,&rec,&PyBool_Type,&keep)) return NULL; // NULL triggers exception DocumentObjectPy* docObj = static_cast(obj); DocumentObject* copy = getDocumentPtr()->copyObject(docObj->getDocumentObjectPtr(), - PyObject_IsTrue(rec) ? true : false, - PyObject_IsTrue(keep)? true : false); + PyObject_IsTrue(rec) ? true : false); if (copy) { return copy->getPyObject(); }