Skip to content

Commit

Permalink
+ always keep digits at end when using copyObject, remove deprecated …
Browse files Browse the repository at this point in the history
…third parameter
  • Loading branch information
wwmayer committed Apr 29, 2015
1 parent 1811795 commit 11239b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
21 changes: 12 additions & 9 deletions src/App/Document.cpp
Expand Up @@ -890,6 +890,7 @@ void Document::writeObjects(const std::vector<App::DocumentObject*>& obj,
std::vector<App::DocumentObject*>
Document::readObjects(Base::XMLReader& reader)
{
bool keepDigits = d->keepTrailingDigits;
d->keepTrailingDigits = !reader.doNameMapping();
std::vector<App::DocumentObject*> objs;

Expand Down Expand Up @@ -919,6 +920,7 @@ Document::readObjects(Base::XMLReader& reader)
}
}
reader.readEndElement("Objects");
d->keepTrailingDigits = keepDigits;

// read the features itself
reader.readElement("ObjectData");
Expand Down Expand Up @@ -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<DocumentObject*> objs;
objs.push_back(obj);
Expand Down Expand Up @@ -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<std::string,DocumentObject*>::const_iterator pos;
Expand All @@ -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<std::string> names;
names.reserve(d->objectMap.size());
for (pos = d->objectMap.begin();pos != d->objectMap.end();++pos) {
Expand Down
2 changes: 1 addition & 1 deletion src/App/Document.h
Expand Up @@ -168,7 +168,7 @@ class AppExport Document : public App::PropertyContainer
* 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.
Expand Down
4 changes: 2 additions & 2 deletions src/App/DocumentPyImp.cpp
Expand Up @@ -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<DocumentObjectPy*>(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();
}
Expand Down

0 comments on commit 11239b0

Please sign in to comment.