Merge pull request #15520 from Ondsel-Development/asm_bom_same_name_bug
Assembly: BOM: Fix same name different doc issue.
This commit is contained in:
@@ -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<App::DocumentObject*> 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<App::DocumentObject*> objs,
|
||||
size_t sub_i = 1;
|
||||
|
||||
for (auto* child : objs) {
|
||||
if (!child) {
|
||||
continue;
|
||||
}
|
||||
if (child->isDerivedFrom<App::Link>()) {
|
||||
child = static_cast<App::Link*>(child)->getLinkedObject();
|
||||
if (!child) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (child->isDerivedFrom<BomGroup>() || child->isDerivedFrom<JointGroup>()
|
||||
|| child->isDerivedFrom<ViewGroup>()) {
|
||||
if (!child->isDerivedFrom<AssemblyObject>() && !child->isDerivedFrom<App::Part>()
|
||||
&& !(child->isDerivedFrom<Part::Feature>() && !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<App::DocumentObject*> objs,
|
||||
}
|
||||
}
|
||||
|
||||
if (child->isDerivedFrom<App::DocumentObjectGroup>()
|
||||
|| child->isDerivedFrom<AssemblyObject>() || child->isDerivedFrom<App::Part>()
|
||||
|| (child->isDerivedFrom<Part::Feature>() && !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<App::DocumentObjectGroup>()
|
||||
|| (child->isDerivedFrom<AssemblyObject>() && detailSubAssemblies.getValue())
|
||||
|| (child->isDerivedFrom<App::Part>() && detailParts.getValue())) {
|
||||
addObjectChildrenToBom(child->getOutList(), row, sub_index);
|
||||
}
|
||||
if ((child->isDerivedFrom<AssemblyObject>() && detailSubAssemblies.getValue())
|
||||
|| (child->isDerivedFrom<App::Part>() && 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") {
|
||||
|
||||
@@ -93,6 +93,7 @@ public:
|
||||
App::PropertyBool onlyParts;
|
||||
|
||||
std::vector<BomDataElement> dataElements;
|
||||
std::vector<App::DocumentObject*> obj_list;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user