From c4c1b7a1a343f37fe5e143e85a02ade29279fbd5 Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Thu, 10 Apr 2025 14:12:25 +0200 Subject: [PATCH 1/8] Assembly: BOM custom columns can now return property values --- src/Mod/Assembly/App/BomObject.cpp | 52 ++++++++++++++++++++++++++++++ src/Mod/Assembly/App/BomObject.h | 3 ++ 2 files changed, 55 insertions(+) diff --git a/src/Mod/Assembly/App/BomObject.cpp b/src/Mod/Assembly/App/BomObject.cpp index 49dc7e2a1f..d6aaf051e2 100644 --- a/src/Mod/Assembly/App/BomObject.cpp +++ b/src/Mod/Assembly/App/BomObject.cpp @@ -239,6 +239,16 @@ void BomObject::addObjectToBom(App::DocumentObject* obj, size_t row, std::string else if (columnName == "Quantity") { setCell(App::CellAddress(row, col), std::to_string(1).c_str()); } + else if (columnName.starts_with(".")) { + // Column names that start with a dot are considered property names + // Extract the property name + std::string baseName = columnName.substr(1); + + auto propertyValue = getBomPropertyValue(obj, baseName); + if (!propertyValue.empty()) { + setCell(App::CellAddress(row, col), propertyValue.c_str()); + } + } else { // load custom data if any. for (auto& el : dataElements) { @@ -252,6 +262,48 @@ void BomObject::addObjectToBom(App::DocumentObject* obj, size_t row, std::string } } +std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, std::string baseName) +{ + App::Property* prop = obj->getPropertyByName(baseName.c_str()); + + if (!prop) { + Base::Console().Warning("Property not found: %s\n", baseName.c_str()); + return "N/A"; + } + + // Only support a subset of property types for BOM + if (auto propStr = dynamic_cast(prop)) { + return propStr->getValue(); + } + else if (auto propLength = dynamic_cast(prop)) { + auto unit = propLength->getUnit().getString(); + auto value = std::to_string(propLength->getValue()); + return value + " " + unit; + } + else if (auto propVolume = dynamic_cast(prop)) { + auto unit = propVolume->getUnit().getString(); + auto value = std::to_string(propVolume->getValue()); + return value + " " + unit; + } + else if (auto propQuantity = dynamic_cast(prop)) { + auto unit = propQuantity->getUnit().getString(); + auto value = std::to_string(propQuantity->getValue()); + return value + " " + unit; + } + else if (auto propFloat = dynamic_cast(prop)) { + return std::to_string(propFloat->getValue()); + } + else if (auto propInt = dynamic_cast(prop)) { + return std::to_string(propInt->getValue()); + } + else if (auto propBool = dynamic_cast(prop)) { + return propBool->getValue() ? "True" : "False"; + } + + Base::Console().Warning("Property type not supported for: %s\n", prop->getName()); + return "Not supported"; +} + AssemblyObject* BomObject::getAssembly() { for (auto& obj : getInList()) { diff --git a/src/Mod/Assembly/App/BomObject.h b/src/Mod/Assembly/App/BomObject.h index 9b6666878d..e93cae4188 100644 --- a/src/Mod/Assembly/App/BomObject.h +++ b/src/Mod/Assembly/App/BomObject.h @@ -94,6 +94,9 @@ public: std::vector dataElements; std::vector obj_list; + +private: + std::string getBomPropertyValue(App::DocumentObject* obj, std::string baseName); }; From 3871379ad23a8ecaa416733c2840f57f9aca8f49 Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Thu, 10 Apr 2025 14:20:11 +0200 Subject: [PATCH 2/8] Assembly: BOM properties, update help message --- src/Mod/Assembly/CommandCreateBom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Assembly/CommandCreateBom.py b/src/Mod/Assembly/CommandCreateBom.py index 6b5a55621c..af4eee28a1 100644 --- a/src/Mod/Assembly/CommandCreateBom.py +++ b/src/Mod/Assembly/CommandCreateBom.py @@ -402,7 +402,7 @@ class TaskAssemblyCreateBom(QtCore.QObject): " - " + translate( "Assembly", - "Custom columns : 'Description' and other custom columns you add by clicking on 'Add column' will not have their data overwritten. These columns can be renamed by double-clicking or pressing F2 (Renaming a column will currently lose its data).", + "Custom columns : 'Description' and other custom columns you add by clicking on 'Add column' will not have their data overwritten. If a column name starts with '.' followed by a property name (e.g. '.Length'), it will be auto-populated with that property value. These columns can be renamed by double-clicking or pressing F2 (Renaming a column will currently lose its data).", ) + "\n" "\n" From ed518f5c4454df867547c9ad171a6ca3aa11a61e Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Thu, 10 Apr 2025 14:50:58 +0200 Subject: [PATCH 3/8] Assembly: BOM, internationalize strings --- src/Mod/Assembly/App/BomObject.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Mod/Assembly/App/BomObject.cpp b/src/Mod/Assembly/App/BomObject.cpp index d6aaf051e2..0353cee2e1 100644 --- a/src/Mod/Assembly/App/BomObject.cpp +++ b/src/Mod/Assembly/App/BomObject.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -268,7 +269,7 @@ std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, std::string if (!prop) { Base::Console().Warning("Property not found: %s\n", baseName.c_str()); - return "N/A"; + return QObject::tr("N/A").toStdString(); } // Only support a subset of property types for BOM @@ -301,7 +302,7 @@ std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, std::string } Base::Console().Warning("Property type not supported for: %s\n", prop->getName()); - return "Not supported"; + return QObject::tr("Not supported").toStdString(); } AssemblyObject* BomObject::getAssembly() From 242c724be27520a64e221172b715b77c76dc357e Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Tue, 22 Apr 2025 16:20:05 +0200 Subject: [PATCH 4/8] Assembly: BOM, apply suggestion: do not copy baseName Co-authored-by: Kacper Donat --- src/Mod/Assembly/App/BomObject.cpp | 2 +- src/Mod/Assembly/App/BomObject.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/Assembly/App/BomObject.cpp b/src/Mod/Assembly/App/BomObject.cpp index 0353cee2e1..ca75e95e18 100644 --- a/src/Mod/Assembly/App/BomObject.cpp +++ b/src/Mod/Assembly/App/BomObject.cpp @@ -263,7 +263,7 @@ void BomObject::addObjectToBom(App::DocumentObject* obj, size_t row, std::string } } -std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, std::string baseName) +std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, const std::string& baseName) { App::Property* prop = obj->getPropertyByName(baseName.c_str()); diff --git a/src/Mod/Assembly/App/BomObject.h b/src/Mod/Assembly/App/BomObject.h index e93cae4188..7d0950830d 100644 --- a/src/Mod/Assembly/App/BomObject.h +++ b/src/Mod/Assembly/App/BomObject.h @@ -96,7 +96,7 @@ public: std::vector obj_list; private: - std::string getBomPropertyValue(App::DocumentObject* obj, std::string baseName); + std::string getBomPropertyValue(App::DocumentObject* obj, const std::string& baseName); }; From ce4b0205a827948c7bc54a93a75fb1572b8a1f15 Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Tue, 22 Apr 2025 17:53:18 +0200 Subject: [PATCH 5/8] Assembly: BOM, support superset property type only --- src/Mod/Assembly/App/BomObject.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Mod/Assembly/App/BomObject.cpp b/src/Mod/Assembly/App/BomObject.cpp index ca75e95e18..70b4981f12 100644 --- a/src/Mod/Assembly/App/BomObject.cpp +++ b/src/Mod/Assembly/App/BomObject.cpp @@ -276,16 +276,6 @@ std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, const std:: if (auto propStr = dynamic_cast(prop)) { return propStr->getValue(); } - else if (auto propLength = dynamic_cast(prop)) { - auto unit = propLength->getUnit().getString(); - auto value = std::to_string(propLength->getValue()); - return value + " " + unit; - } - else if (auto propVolume = dynamic_cast(prop)) { - auto unit = propVolume->getUnit().getString(); - auto value = std::to_string(propVolume->getValue()); - return value + " " + unit; - } else if (auto propQuantity = dynamic_cast(prop)) { auto unit = propQuantity->getUnit().getString(); auto value = std::to_string(propQuantity->getValue()); From 323bcb019e789acdee84f7342c51db0af8bf6593 Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Tue, 22 Apr 2025 18:01:17 +0200 Subject: [PATCH 6/8] Assembly: BOM, use freecad_cast --- src/Mod/Assembly/App/BomObject.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Mod/Assembly/App/BomObject.cpp b/src/Mod/Assembly/App/BomObject.cpp index 70b4981f12..028dfa291c 100644 --- a/src/Mod/Assembly/App/BomObject.cpp +++ b/src/Mod/Assembly/App/BomObject.cpp @@ -273,21 +273,21 @@ std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, const std:: } // Only support a subset of property types for BOM - if (auto propStr = dynamic_cast(prop)) { + if (auto propStr = freecad_cast(prop)) { return propStr->getValue(); } - else if (auto propQuantity = dynamic_cast(prop)) { + else if (auto propQuantity = freecad_cast(prop)) { auto unit = propQuantity->getUnit().getString(); auto value = std::to_string(propQuantity->getValue()); return value + " " + unit; } - else if (auto propFloat = dynamic_cast(prop)) { + else if (auto propFloat = freecad_cast(prop)) { return std::to_string(propFloat->getValue()); } - else if (auto propInt = dynamic_cast(prop)) { + else if (auto propInt = freecad_cast(prop)) { return std::to_string(propInt->getValue()); } - else if (auto propBool = dynamic_cast(prop)) { + else if (auto propBool = freecad_cast(prop)) { return propBool->getValue() ? "True" : "False"; } From 160916cba38a0f08dba3236248df9ea52c293901 Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Tue, 22 Apr 2025 18:03:27 +0200 Subject: [PATCH 7/8] Assembly: BOM, use getUserString to simplify code --- src/Mod/Assembly/App/BomObject.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Mod/Assembly/App/BomObject.cpp b/src/Mod/Assembly/App/BomObject.cpp index 028dfa291c..8b0da1b42c 100644 --- a/src/Mod/Assembly/App/BomObject.cpp +++ b/src/Mod/Assembly/App/BomObject.cpp @@ -277,9 +277,7 @@ std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, const std:: return propStr->getValue(); } else if (auto propQuantity = freecad_cast(prop)) { - auto unit = propQuantity->getUnit().getString(); - auto value = std::to_string(propQuantity->getValue()); - return value + " " + unit; + return propQuantity->getQuantityValue().getUserString(); } else if (auto propFloat = freecad_cast(prop)) { return std::to_string(propFloat->getValue()); From 8dfa7a9a6344f7ffb858175e63710be3062313ab Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Fri, 25 Apr 2025 01:53:11 +0200 Subject: [PATCH 8/8] Assembly: BOM, handle enumerations as well --- src/Mod/Assembly/App/BomObject.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Mod/Assembly/App/BomObject.cpp b/src/Mod/Assembly/App/BomObject.cpp index 8b0da1b42c..673a9bfbc6 100644 --- a/src/Mod/Assembly/App/BomObject.cpp +++ b/src/Mod/Assembly/App/BomObject.cpp @@ -279,6 +279,9 @@ std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, const std:: else if (auto propQuantity = freecad_cast(prop)) { return propQuantity->getQuantityValue().getUserString(); } + else if (auto propEnum = freecad_cast(prop)) { + return propEnum->getValueAsString(); + } else if (auto propFloat = freecad_cast(prop)) { return std::to_string(propFloat->getValue()); }