Add parameter to keep trailing digits in object name of copy, other little fix
This commit is contained in:
parent
555c7ca516
commit
f19a0d20da
|
@ -1484,15 +1484,18 @@ void Document::breakDependency(DocumentObject* pcObject, bool clear)
|
|||
}
|
||||
|
||||
DocumentObject* Document::_copyObject(DocumentObject* obj, std::map<DocumentObject*,
|
||||
DocumentObject*>& 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<DocumentObje
|
|||
static_cast<PropertyLink*>(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<PropertyLink*>(it->second)->setValue(link_copy);
|
||||
}
|
||||
|
@ -1531,7 +1534,7 @@ DocumentObject* Document::_copyObject(DocumentObject* obj, std::map<DocumentObje
|
|||
links_copy.push_back(pt->second);
|
||||
}
|
||||
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<DocumentObje
|
|||
return copy;
|
||||
}
|
||||
|
||||
DocumentObject* Document::copyObject(DocumentObject* obj, bool recursive)
|
||||
DocumentObject* Document::copyObject(DocumentObject* obj, bool recursive, bool keepdigitsatend)
|
||||
{
|
||||
std::map<DocumentObject*, DocumentObject*> copy_map;
|
||||
DocumentObject* copy = _copyObject(obj, copy_map, recursive);
|
||||
DocumentObject* copy = _copyObject(obj, copy_map, recursive, keepdigitsatend);
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<DocumentObject*,
|
||||
DocumentObject*>&, 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);
|
||||
|
|
|
@ -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<DocumentObjectPy*>(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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user