diff --git a/src/Mod/Assembly/App/BomObject.cpp b/src/Mod/Assembly/App/BomObject.cpp index 59c6c8cccf..2467f39505 100644 --- a/src/Mod/Assembly/App/BomObject.cpp +++ b/src/Mod/Assembly/App/BomObject.cpp @@ -141,6 +141,7 @@ void BomObject::generateBOM() { saveCustomColumnData(); clearAll(); + obj_list.clear(); size_t row = 0; size_t col = 0; @@ -168,7 +169,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,8 +178,14 @@ 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() @@ -186,15 +193,15 @@ void BomObject::addObjectChildrenToBom(std::vector objs, 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; @@ -227,6 +234,7 @@ void BomObject::addObjectChildrenToBom(std::vector objs, 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; };