From f19a0d20dacfebb8587155de1935e6dd3941cc5f Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 25 May 2012 12:12:30 +0200 Subject: [PATCH] Add parameter to keep trailing digits in object name of copy, other little fix --- src/App/Document.cpp | 13 ++++++++----- src/App/Document.h | 4 ++-- src/App/DocumentPyImp.cpp | 6 +++--- src/Mod/Part/Gui/Command.cpp | 2 -- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index f130bb35a..61d1b7921 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1484,15 +1484,18 @@ void Document::breakDependency(DocumentObject* pcObject, bool clear) } DocumentObject* Document::_copyObject(DocumentObject* obj, std::map& copy_map, bool recursive) + DocumentObject*>& copy_map, bool recursive, + bool keepdigitsatend) { if (!obj) return 0; // remove number from end to avoid lengthy names std::string objname = obj->getNameInDocument(); + if (!keepdigitsatend) { size_t lastpos = objname.length()-1; while (objname[lastpos] >= 48 && objname[lastpos] <= 57) lastpos--; objname = objname.substr(0, lastpos+1); + } DocumentObject* copy = addObject(obj->getTypeId().getName(),objname.c_str()); if (!copy) return 0; copy->addDynamicProperties(obj); @@ -1512,7 +1515,7 @@ DocumentObject* Document::_copyObject(DocumentObject* obj, std::map(it->second)->setValue(pt->second); } else if (recursive) { - DocumentObject* link_copy = _copyObject(link, copy_map, recursive); + DocumentObject* link_copy = _copyObject(link, copy_map, recursive, keepdigitsatend); copy_map[link] = link_copy; static_cast(it->second)->setValue(link_copy); } @@ -1531,7 +1534,7 @@ DocumentObject* Document::_copyObject(DocumentObject* obj, std::mapsecond); } else { - links_copy.push_back(_copyObject(*jt, copy_map, recursive)); + links_copy.push_back(_copyObject(*jt, copy_map, recursive, keepdigitsatend)); copy_map[*jt] = links_copy.back(); } } @@ -1561,10 +1564,10 @@ DocumentObject* Document::_copyObject(DocumentObject* obj, std::map copy_map; - DocumentObject* copy = _copyObject(obj, copy_map, recursive); + DocumentObject* copy = _copyObject(obj, copy_map, recursive, keepdigitsatend); return copy; } diff --git a/src/App/Document.h b/src/App/Document.h index d1675001e..38b247a20 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -140,7 +140,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); + DocumentObject* copyObject(DocumentObject* obj, bool recursive=false, bool keepdigitsatend=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. @@ -261,7 +261,7 @@ protected: void _remObject(DocumentObject* pcObject); void _addObject(DocumentObject* pcObject, const char* pObjectName); DocumentObject* _copyObject(DocumentObject* obj, std::map&, bool recursive=false); + DocumentObject*>&, bool recursive=false, bool keepdigitsatend=false); /// checks if a valid transaction is open void _checkTransaction(void); void breakDependency(DocumentObject* pcObject, bool clear); diff --git a/src/App/DocumentPyImp.cpp b/src/App/DocumentPyImp.cpp index 6bd02f51c..64b04d8b9 100644 --- a/src/App/DocumentPyImp.cpp +++ b/src/App/DocumentPyImp.cpp @@ -163,12 +163,12 @@ PyObject* DocumentPy::removeObject(PyObject *args) PyObject* DocumentPy::copyObject(PyObject *args) { - PyObject *obj, *rec=0; - if (!PyArg_ParseTuple(args, "O!|O!",&(DocumentObjectPy::Type),&obj,&PyBool_Type,&rec)) + PyObject *obj, *rec=0, *keep=0; + 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(), rec==Py_True); + DocumentObject* copy = getDocumentPtr()->copyObject(docObj->getDocumentObjectPtr(), rec==Py_True, keep==Py_True); if (copy) { return copy->getPyObject(); } diff --git a/src/Mod/Part/Gui/Command.cpp b/src/Mod/Part/Gui/Command.cpp index 1b616525a..33cd008ee 100644 --- a/src/Mod/Part/Gui/Command.cpp +++ b/src/Mod/Part/Gui/Command.cpp @@ -511,7 +511,6 @@ void CmdPartExport::activated(int iMsg) if (!fn.isEmpty()) { App::Document* pDoc = getDocument(); if (!pDoc) return; // no document - openCommand("Import Part"); QString ext = QFileInfo(fn).suffix().toLower(); if (ext == QLatin1String("step") || ext == QLatin1String("stp") || @@ -522,7 +521,6 @@ void CmdPartExport::activated(int iMsg) else { Gui::Application::Instance->exportTo((const char*)fn.toUtf8(),pDoc->getName(),"Part"); } - commitCommand(); } }