diff --git a/src/Mod/Assembly/App/BomObject.cpp b/src/Mod/Assembly/App/BomObject.cpp index 59c6c8cccf..1e966e5ed0 100644 --- a/src/Mod/Assembly/App/BomObject.cpp +++ b/src/Mod/Assembly/App/BomObject.cpp @@ -46,9 +46,6 @@ #include "AssemblyObject.h" -#include "BomGroup.h" -#include "JointGroup.h" -#include "ViewGroup.h" #include "BomObject.h" #include "BomObjectPy.h" @@ -141,6 +138,7 @@ void BomObject::generateBOM() { saveCustomColumnData(); clearAll(); + obj_list.clear(); size_t row = 0; size_t col = 0; @@ -168,7 +166,7 @@ void BomObject::addObjectChildrenToBom(std::vector objs, int quantityColIndex = getColumnIndex("Quantity"); bool hasQuantityCol = hasQuantityColumn(); - int siblingsInitialRow = row; + size_t siblingsInitialRow = row; if (index != "") { index = index + "."; @@ -177,24 +175,30 @@ void BomObject::addObjectChildrenToBom(std::vector objs, size_t sub_i = 1; for (auto* child : objs) { + if (!child) { + continue; + } if (child->isDerivedFrom()) { child = static_cast(child)->getLinkedObject(); + if (!child) { + continue; + } } - if (child->isDerivedFrom() || child->isDerivedFrom() - || child->isDerivedFrom()) { + if (!child->isDerivedFrom() && !child->isDerivedFrom() + && !(child->isDerivedFrom() && !onlyParts.getValue())) { continue; } - if (hasQuantityCol) { + if (hasQuantityCol && row != siblingsInitialRow) { // Check if the object is not already in (case of links). And if so just increment. // Note: an object can be used in several parts. In which case we do no want to blindly // increment. bool found = false; for (size_t i = siblingsInitialRow; i <= row; ++i) { - std::string childName = child->Label.getValue(); + size_t idInList = i - 1; // -1 for the header + if (idInList < obj_list.size() && child == obj_list[idInList]) { - if (childName == getText(i, nameColIndex) && childName != "") { int qty = std::stoi(getText(i, quantityColIndex)) + 1; setCell(App::CellAddress(i, quantityColIndex), std::to_string(qty).c_str()); found = true; @@ -206,27 +210,22 @@ void BomObject::addObjectChildrenToBom(std::vector objs, } } - if (child->isDerivedFrom() - || child->isDerivedFrom() || child->isDerivedFrom() - || (child->isDerivedFrom() && !onlyParts.getValue())) { + std::string sub_index = index + std::to_string(sub_i); + ++sub_i; - std::string sub_index = index + std::to_string(sub_i); - ++sub_i; + addObjectToBom(child, row, sub_index); + ++row; - addObjectToBom(child, row, sub_index); - ++row; - - if (child->isDerivedFrom() - || (child->isDerivedFrom() && detailSubAssemblies.getValue()) - || (child->isDerivedFrom() && detailParts.getValue())) { - addObjectChildrenToBom(child->getOutList(), row, sub_index); - } + if ((child->isDerivedFrom() && detailSubAssemblies.getValue()) + || (child->isDerivedFrom() && detailParts.getValue())) { + addObjectChildrenToBom(child->getOutList(), row, sub_index); } } } void BomObject::addObjectToBom(App::DocumentObject* obj, size_t row, std::string index) { + obj_list.push_back(obj); size_t col = 0; for (auto& columnName : columnsNames.getValues()) { if (columnName == "Index") { diff --git a/src/Mod/Assembly/App/BomObject.h b/src/Mod/Assembly/App/BomObject.h index 0dadccfe1e..9b6666878d 100644 --- a/src/Mod/Assembly/App/BomObject.h +++ b/src/Mod/Assembly/App/BomObject.h @@ -93,6 +93,7 @@ public: App::PropertyBool onlyParts; std::vector dataElements; + std::vector obj_list; };