From 0c4c3cc7865f01d78be6fd093e587145d2dbd864 Mon Sep 17 00:00:00 2001 From: andrea Date: Mon, 11 Jul 2022 16:04:39 +0200 Subject: [PATCH] Remove unused code into App --- src/App/Application.cpp | 16 ------- src/App/ApplicationPy.cpp | 33 -------------- src/App/Document.cpp | 23 ---------- src/App/DocumentObject.cpp | 58 ------------------------ src/App/DocumentObjectPyImp.cpp | 78 +-------------------------------- src/App/FeatureTest.cpp | 37 ---------------- src/App/GroupExtension.cpp | 10 ----- src/App/MergeDocuments.cpp | 52 ---------------------- src/App/PropertyLinks.cpp | 41 ----------------- src/App/PropertyStandard.cpp | 19 -------- 10 files changed, 2 insertions(+), 365 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 30816239d5..96d14e975e 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -412,25 +412,9 @@ void Application::setupPythonException(PyObject* module) /// get called by the document when the name is changing void Application::renameDocument(const char *OldName, const char *NewName) { -#if 1 (void)OldName; (void)NewName; throw Base::RuntimeError("Renaming document internal name is no longer allowed!"); -#else - std::map::iterator pos; - pos = DocMap.find(OldName); - - if (pos != DocMap.end()) { - Document* temp; - temp = pos->second; - DocMap.erase(pos); - DocMap[NewName] = temp; - signalRenameDocument(*temp); - } - else { - throw Base::RuntimeError("Application::renameDocument(): no document with this name to rename!"); - } -#endif } Document* Application::newDocument(const char * Name, const char * UserName, bool createView, bool tempDoc) diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index 83ac48a225..f73d04776e 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -343,25 +343,7 @@ PyObject* Application::sSaveDocument(PyObject * /*self*/, PyObject *args) Py_Return; } -#if 0 -PyObject* Application::sSaveDocumentAs(PyObject * /*self*/, PyObject *args) -{ - char *pDoc, *pFileName; - if (!PyArg_ParseTuple(args, "ss", &pDoc, &pFileName)) - return nullptr; - Document* doc = GetApplication().getDocument(pDoc); - if (doc) { - doc->saveAs( pFileName ); - } - else { - PyErr_Format(PyExc_NameError, "Unknown document '%s'", pDoc); - return NULL; - } - - Py_Return; -} -#endif PyObject* Application::sActiveDocument(PyObject * /*self*/, PyObject *args) { if (!PyArg_ParseTuple(args, "")) @@ -843,21 +825,6 @@ PyObject *Application::sGetLogLevel(PyObject * /*self*/, PyObject *args) } // For performance reason, we only output integer value return Py_BuildValue("i",Base::Console().LogLevel(l)); - - // switch(l) { - // case FC_LOGLEVEL_LOG: - // return Py_BuildValue("s","Log"); - // case FC_LOGLEVEL_WARN: - // return Py_BuildValue("s","Warning"); - // case FC_LOGLEVEL_ERR: - // return Py_BuildValue("s","Error"); - // case FC_LOGLEVEL_MSG: - // return Py_BuildValue("s","Message"); - // case FC_LOGLEVEL_TRACE: - // return Py_BuildValue("s","Trace"); - // default: - // return Py_BuildValue("i",l); - // } } PY_CATCH; } diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 2f491650ac..f963ba961c 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -3891,8 +3891,6 @@ DocumentObject * Document::addObject(const char* sType, const char* pObjectName, pcObject->pcNameInDocument = &(d->objectMap.find(ObjectName)->first); // insert in the vector d->objectArray.push_back(pcObject); - // insert in the adjacence list and reference through the ConectionMap - //_DepConMap[pcObject] = add_vertex(_DepList); // If we are restoring, don't set the Label object now; it will be restored later. This is to avoid potential duplicate // label conflicts later. @@ -4134,27 +4132,6 @@ void Document::removeObject(const char* sName) _checkTransaction(pos->second,nullptr,__LINE__); -#if 0 - if(!d->rollback && d->activeUndoTransaction && pos->second->hasChildElement()) { - // Preserve link group sub object global visibilities. Normally those - // claimed object should be hidden in global coordinate space. However, - // when the group is deleted, the user will naturally try to show the - // children, which may now in the global space. When the parent is - // undeleted, having its children shown in both the local and global - // coordinate space is very confusing. Hence, we preserve the visibility - // here - for(auto &sub : pos->second->getSubObjects()) { - if(sub.empty()) - continue; - if(sub[sub.size()-1]!='.') - sub += '.'; - auto sobj = pos->second->getSubObject(sub.c_str()); - if(sobj && sobj->getDocument()==this && !sobj->Visibility.getValue()) - d->activeUndoTransaction->addObjectChange(sobj,&sobj->Visibility); - } - } -#endif - if (d->activeObject == pos->second) d->activeObject = nullptr; diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 0ee1d368ae..b7cccf2880 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -100,7 +100,6 @@ App::DocumentObjectExecReturn *DocumentObject::recompute(void) { //check if the links are valid before making the recompute if(!GeoFeatureGroupExtension::areLinksValid(this)) { -#if 1 // Get objects that have invalid link scope, and print their names. // Truncate the invalid object list name strings for readability, if they happen to be very long. std::vector invalid_linkobjs; @@ -133,9 +132,6 @@ App::DocumentObjectExecReturn *DocumentObject::recompute(void) scopenames.pop_back(); } Base::Console().Warning("%s: Link(s) to object(s) '%s' go out of the allowed scope '%s'. Instead, the linked object(s) reside within '%s'.\n", getTypeId().getName(), objnames.c_str(), getNameInDocument(), scopenames.c_str()); -#else - return new App::DocumentObjectExecReturn("Links go out of the allowed scope", this); -#endif } // set/unset the execution bit @@ -387,42 +383,6 @@ const std::vector &DocumentObject::getInList(void) const #endif // if USE_OLD_DAG -#if 0 - -void _getInListRecursive(std::set& objSet, - const DocumentObject* obj, - const DocumentObject* checkObj, int depth) -{ - for (const auto objIt : obj->getInList()) { - // if the check object is in the recursive inList we have a cycle! - if (objIt == checkObj || depth <= 0) { - throw Base::BadGraphError("DocumentObject::getInListRecursive(): cyclic dependency detected!"); - } - - // if the element was already in the set then there is no need to process it again - auto pair = objSet.insert(objIt); - if (pair.second) - _getInListRecursive(objSet, objIt, checkObj, depth-1); - } -} - -std::vector DocumentObject::getInListRecursive(void) const -{ - // number of objects in document is a good estimate in result size - // int maxDepth = getDocument()->countObjects() +2; - int maxDepth = GetApplication().checkLinkDepth(0); - std::vector result; - result.reserve(maxDepth); - - // using a rcursie helper to collect all InLists - _getInListRecursive(result, this, this, maxDepth); - - std::vector array; - array.insert(array.begin(), result.begin(), result.end()); - return array; -} - -#else // The original algorithm is highly inefficient in some special case. // Considering an object is linked by every other objects. After excluding this // object, there is another object linked by every other of the remaining @@ -438,7 +398,6 @@ std::vector DocumentObject::getInListRecursive(void) const return res; } -#endif // More efficient algorithm to find the recursive inList of an object, // including possible external parents. One shortcoming of this algorithm is @@ -569,12 +528,7 @@ bool _isInInListRecursive(const DocumentObject* act, bool DocumentObject::isInInListRecursive(DocumentObject *linkTo) const { -#if 0 - int maxDepth = getDocument()->countObjects() + 2; - return _isInInListRecursive(this, linkTo, maxDepth); -#else return this==linkTo || getInListEx(true).count(linkTo); -#endif } bool DocumentObject::isInInList(DocumentObject *linkTo) const @@ -641,24 +595,12 @@ bool DocumentObject::testIfLinkDAGCompatible(DocumentObject *linkTo) const bool DocumentObject::testIfLinkDAGCompatible(const std::vector &linksTo) const { -#if 0 - Document* doc = this->getDocument(); - if (!doc) - throw Base::RuntimeError("DocumentObject::testIfLinkIsDAG: object is not in any document."); - std::vector deplist = doc->getDependencyList(linksTo); - if( std::find(deplist.begin(),deplist.end(),this) != deplist.end() ) - //found this in dependency list - return false; - else - return true; -#else auto inLists = getInListEx(true); inLists.emplace(const_cast(this)); for(auto obj : linksTo) if(inLists.count(obj)) return false; return true; -#endif } bool DocumentObject::testIfLinkDAGCompatible(PropertyLinkSubList &linksTo) const diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index 314936b57a..d962857c9e 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -709,88 +709,14 @@ PyObject* DocumentObjectPy::getPathsByOutList(PyObject *args) throw Py::RuntimeError(e.what()); } } - +//remove PyObject *DocumentObjectPy::getCustomAttributes(const char* attr) const { - // Dynamic property is now directly supported in PropertyContainer. So we - // can comment out here and let PropertyContainerPy handle it. -#if 1 - (void)attr; -#else - // search for dynamic property - Property* prop = getDocumentObjectPtr()->getDynamicPropertyByName(attr); - if (prop) - return prop->getPyObject(); - else -#endif return nullptr; } - +//remove int DocumentObjectPy::setCustomAttributes(const char* attr, PyObject *obj) { - // The following code is practically the same as in PropertyContainerPy, - // especially since now dynamic property is directly supported in - // PropertyContainer. So we can comment out here and let PropertyContainerPy - // handle it. -#if 1 - (void)attr; - (void)obj; -#else - // explicitly search for dynamic property - try { - Property* prop = getDocumentObjectPtr()->getDynamicPropertyByName(attr); - if (prop) { - if(prop->testStatus(Property::Immutable)) { - std::stringstream s; - s << "'DocumentObject' attribute '" << attr << "' is read-only"; - throw Py::AttributeError(s.str()); - } - prop->setPyObject(obj); - return 1; - } - } - catch (Base::ValueError &exc) { - std::stringstream s; - s << "Property '" << attr << "': " << exc.what(); - throw Py::ValueError(s.str()); - } - catch (Base::Exception &exc) { - std::stringstream s; - s << "Attribute (Name: " << attr << ") error: '" << exc.what() << "' "; - throw Py::AttributeError(s.str()); - } - catch (Py::AttributeError &) { - throw; - }catch (...) { - std::stringstream s; - s << "Unknown error in attribute " << attr; - throw Py::AttributeError(s.str()); - } - - // search in PropertyList - Property *prop = getDocumentObjectPtr()->getPropertyByName(attr); - if (prop) { - // Read-only attributes must not be set over its Python interface - if(prop->testStatus(Property::Immutable) || - (getDocumentObjectPtr()->getPropertyType(prop) & Prop_ReadOnly)) - { - std::stringstream s; - s << "'DocumentObject' attribute '" << attr << "' is read-only"; - throw Py::AttributeError(s.str()); - } - - try { - prop->setPyObject(obj); - } - catch (const Base::TypeError& e) { - std::stringstream s; - s << "Property '" << prop->getName() << "': " << e.what(); - throw Py::TypeError(s.str()); - } - return 1; - } -#endif - return 0; } diff --git a/src/App/FeatureTest.cpp b/src/App/FeatureTest.cpp index 430bcc5e97..62c9a62668 100644 --- a/src/App/FeatureTest.cpp +++ b/src/App/FeatureTest.cpp @@ -109,11 +109,6 @@ FeatureTest::FeatureTest() QuantityLength.setUnit(Base::Unit::Length); ADD_PROPERTY(QuantityOther,(5.0)); QuantityOther.setUnit(Base::Unit(-3,1)); - //ADD_PROPERTY(QuantityMass,(1.0)); - //QuantityMass.setUnit(Base::Unit::Mass); - //ADD_PROPERTY(QuantityAngle,(1.0)); - //QuantityAngle.setUnit(Base::Unit::Angle); - } FeatureTest::~FeatureTest() @@ -161,31 +156,7 @@ DocumentObjectExecReturn *FeatureTest::execute() list.emplace_back("World"); enumObj6.setEnums(list); enumObj6.setValue(list.back()); - /* -doc=App.newDocument() -obj=doc.addObject("App::FeatureTest") -obj.ExceptionType=0 # good -doc.recompute() - -obj.ExceptionType=1 # unknown exception -doc.recompute() - -obj.ExceptionType=2 # Runtime error -doc.recompute() - -obj.ExceptionType=3 # segfault -doc.recompute() - -obj.ExceptionType=4 # segfault -doc.recompute() - -obj.ExceptionType=5 # int division by zero -doc.recompute() - -obj.ExceptionType=6 # float division by zero -doc.recompute() - */ int *i=nullptr,j; float f; void *s; @@ -198,15 +169,7 @@ doc.recompute() case 0: break; case 1: throw std::runtime_error("Test Exception"); case 2: throw Base::RuntimeError("FeatureTestException::execute(): Testexception"); -#if 0 // only allow these error types on purpose - case 3: *i=0;printf("%i",*i);break; // seg-fault - case 4: t = nullptr; break; // seg-fault - case 5: j=0; printf("%i",1/j); break; // int division by zero - case 6: f=0.0; printf("%f",1/f); break; // float division by zero - case 7: s = malloc(3600000000ul); free(s); break; // out-of-memory -#else default: (void)i; (void)j; (void)f; (void)s; (void)t; break; -#endif } ExecCount.setValue(ExecCount.getValue() + 1); diff --git a/src/App/GroupExtension.cpp b/src/App/GroupExtension.cpp index 2b70446f0b..2a0bae34ea 100644 --- a/src/App/GroupExtension.cpp +++ b/src/App/GroupExtension.cpp @@ -148,7 +148,6 @@ std::vector< DocumentObject* > GroupExtension::removeObjects(std::vector< Docume void GroupExtension::removeObjectsFromDocument() { -#if 1 while (Group.getSize() > 0) { // Remove the objects step by step because it can happen // that an object is part of several groups and thus a @@ -156,15 +155,6 @@ void GroupExtension::removeObjectsFromDocument() const std::vector & grp = Group.getValues(); removeObjectFromDocument(grp.front()); } -#else - const std::vector & grp = Group.getValues(); - // Use set so iterate on each linked object exactly one time (in case of multiple links to the same document) - std::set grpSet (grp.begin(), grp.end()); - - for (std::set::iterator it = grpSet.begin(); it != grpSet.end(); ++it) { - removeObjectFromDocument(*it); - } -#endif } void GroupExtension::removeObjectFromDocument(DocumentObject* obj) diff --git a/src/App/MergeDocuments.cpp b/src/App/MergeDocuments.cpp index 4726a9e975..842edd1c46 100644 --- a/src/App/MergeDocuments.cpp +++ b/src/App/MergeDocuments.cpp @@ -63,58 +63,6 @@ public: } protected: - // It is not safe to change potential object name reference at this level. - // For example, a LinkSub with sub element name Face1 may also be some - // object's name that may potentially be mapped. In addition, with the - // introduction of full qualified SubName reference, the Sub value inside - // LinkSub may require customized mapping. So we move the mapping logic to - // various link property's Restore() function. -#if 0 - void startElement(const XMLCh* const uri, const XMLCh* const localname, - const XMLCh* const qname, - const XERCES_CPP_NAMESPACE_QUALIFIER Attributes& attrs) - { - Base::XMLReader::startElement(uri, localname, qname, attrs); - if (LocalName == "Property") - propertyStack.push(std::make_pair(AttrMap["name"],AttrMap["type"])); - - if (!propertyStack.empty()) { - // replace the stored object name with the real one - if (LocalName == "Link" || LocalName == "LinkSub" || (LocalName == "String" && propertyStack.top().first == "Label")) { - for (std::map::iterator it = AttrMap.begin(); it != AttrMap.end(); ++it) { - std::map::const_iterator jt = nameMap.find(it->second); - if (jt != nameMap.end()) - it->second = jt->second; - } - } - // update the expression if name of the object is used - else if (LocalName == "Expression") { - std::map::iterator it = AttrMap.find("expression"); - if (it != AttrMap.end()) { - // search for the part before the first dot that should be the object name. - std::string expression = it->second; - std::string::size_type dotpos = expression.find_first_of("."); - if (dotpos != std::string::npos) { - std::string name = expression.substr(0, dotpos); - std::map::const_iterator jt = nameMap.find(name); - if (jt != nameMap.end()) { - std::string newexpression = jt->second; - newexpression += expression.substr(dotpos); - it->second = newexpression; - } - } - } - } - } - } - - void endElement(const XMLCh* const uri, const XMLCh *const localname, const XMLCh *const qname) - { - Base::XMLReader::endElement(uri, localname, qname); - if (LocalName == "Property") - propertyStack.pop(); - } -#endif private: std::map& nameMap; diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index e3b1abee3a..ee4abf7b6b 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -293,17 +293,6 @@ PropertyLinkBase::tryReplaceLink(const PropertyContainer *owner, DocumentObject if(oldObj == obj) { if(owner == parent) { - // Do not throw on sub object error yet. It's better to let - // recompute find out the error and point out the affected objects - // to user. -#if 0 - if(subname && subname[0] && !newObj->getSubObject(subname)) { - FC_THROWM(Base::RuntimeError, - "Sub-object '" << newObj->getFullName() - << '.' << subname << "' not found when replacing link in " - << owner->getFullName() << '.' << getName()); - } -#endif res.first = newObj; if(subname) res.second = subname; return res; @@ -326,14 +315,6 @@ PropertyLinkBase::tryReplaceLink(const PropertyContainer *owner, DocumentObject break; if(sobj == oldObj) { if(prev == parent) { -#if 0 - if(sub[pos] && !newObj->getSubObject(sub.c_str()+pos)) { - FC_THROWM(Base::RuntimeError, - "Sub-object '" << newObj->getFullName() - << '.' << (sub.c_str()+pos) << "' not found when replacing link in " - << owner->getFullName() << '.' << getName()); - } -#endif if(sub[prevPos] == '$') sub.replace(prevPos+1,pos-1-prevPos,newObj->Label.getValue()); else @@ -1998,7 +1979,6 @@ std::vector PropertyLinkSubList::getSubListValues(b PyObject *PropertyLinkSubList::getPyObject(void) { -#if 1 std::vector subLists = getSubListValues(); std::size_t count = subLists.size(); #if 0//FIXME: Should switch to tuple @@ -2021,24 +2001,6 @@ PyObject *PropertyLinkSubList::getPyObject(void) } return Py::new_reference_to(sequence); -#else - unsigned int count = getSize(); -#if 0//FIXME: Should switch to tuple - Py::Tuple sequence(count); -#else - Py::List sequence(count); -#endif - for (unsigned int i = 0; igetPyObject()); - std::string subItem; - if (_lSubList.size() > i) - subItem = _lSubList[i]; - tup[1] = Py::String(subItem); - sequence[i] = tup; - } - return Py::new_reference_to(sequence); -#endif } void PropertyLinkSubList::setPyObject(PyObject *value) @@ -2675,7 +2637,6 @@ public: if (path.startsWith(QLatin1String("https://"))) return path; else { - // return QFileInfo(path).canonicalFilePath(); return QFileInfo(path).absoluteFilePath(); } } @@ -2685,7 +2646,6 @@ public: if (path.startsWith(QLatin1String("https://"))) return path; else { - // return QFileInfo(myPos->first).canonicalFilePath(); return QFileInfo(myPos->first).absoluteFilePath(); } } @@ -2832,7 +2792,6 @@ public: return; QFileInfo info(myPos->first); - // QString path(info.canonicalFilePath()); QString path(info.absoluteFilePath()); const char *filename = doc.getFileName(); QString docPath(getFullPath(filename)); diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 4246380bf4..c7e8a2d151 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -311,19 +311,7 @@ void PropertyEnumeration::setEnums(const char **plEnums) void PropertyEnumeration::setEnums(const std::vector &Enums) { - // _enum.setEnums() will preserve old value possible, so no need to do it - // here -#if 0 - if (_enum.isValid()) { - const std::string &index = getValueAsString(); - _enum.setEnums(Enums); - setValue(index.c_str()); - } else { - _enum.setEnums(Enums); - } -#else setEnumVector(Enums); -#endif } void PropertyEnumeration::setValue(const char *value) @@ -459,13 +447,6 @@ void PropertyEnumeration::Restore(Base::XMLReader &reader) PyObject * PropertyEnumeration::getPyObject() { if (!_enum.isValid()) { - // There is legimate use case of having an empty PropertyEnumeration and - // set its enumeration items later. Returning error here cause hasattr() - // to return False even though the property exists. - // - // PyErr_SetString(PyExc_AssertionError, "The enum is empty"); - // return 0; - // Py_Return; }