Move splitSubName from AssemblyObject to Base::Tools
This commit is contained in:
@@ -372,3 +372,24 @@ std::string Base::Tools::currentDateTimeString()
|
||||
.toString(Qt::ISODate)
|
||||
.toStdString();
|
||||
}
|
||||
|
||||
std::vector<std::string> Base::Tools::splitSubName(const std::string& subname)
|
||||
{
|
||||
// Turns 'Part.Part001.Body.Pad.Edge1'
|
||||
// Into ['Part', 'Part001', 'Body', 'Pad', 'Edge1']
|
||||
std::vector<std::string> subNames;
|
||||
std::string subName;
|
||||
std::istringstream subNameStream(subname);
|
||||
while (std::getline(subNameStream, subName, '.')) {
|
||||
subNames.push_back(subName);
|
||||
}
|
||||
|
||||
// Check if the last character of the input string is the delimiter.
|
||||
// If so, add an empty string to the subNames vector.
|
||||
// Because the last subname is the element name and can be empty.
|
||||
if (!subname.empty() && subname.back() == '.') {
|
||||
subNames.push_back(""); // Append empty string for trailing dot.
|
||||
}
|
||||
|
||||
return subNames;
|
||||
}
|
||||
|
||||
@@ -325,6 +325,8 @@ struct BaseExport Tools
|
||||
static std::string joinList(const std::vector<std::string>& vec, const std::string& sep = ", ");
|
||||
|
||||
static std::string currentDateTimeString();
|
||||
|
||||
static std::vector<std::string> splitSubName(const std::string& subname);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2105,7 +2105,7 @@ Base::Placement AssemblyObject::getGlobalPlacement(App::DocumentObject* targetOb
|
||||
if (!targetObj || !rootObj || sub == "") {
|
||||
return Base::Placement();
|
||||
}
|
||||
std::vector<std::string> names = splitSubName(sub);
|
||||
std::vector<std::string> names = Base::Tools::splitSubName(sub);
|
||||
|
||||
App::Document* doc = rootObj->getDocument();
|
||||
Base::Placement plc = getPlacementFromProp(rootObj, "Placement");
|
||||
@@ -2193,7 +2193,7 @@ std::vector<std::string> AssemblyObject::getSubAsList(App::PropertyXLinkSub* pro
|
||||
return {};
|
||||
}
|
||||
|
||||
return splitSubName(subs[0]);
|
||||
return Base::Tools::splitSubName(subs[0]);
|
||||
}
|
||||
|
||||
std::vector<std::string> AssemblyObject::getSubAsList(App::DocumentObject* obj, const char* pName)
|
||||
@@ -2203,27 +2203,6 @@ std::vector<std::string> AssemblyObject::getSubAsList(App::DocumentObject* obj,
|
||||
return getSubAsList(prop);
|
||||
}
|
||||
|
||||
std::vector<std::string> AssemblyObject::splitSubName(const std::string& sub)
|
||||
{
|
||||
// Turns 'Part.Part001.Body.Pad.Edge1'
|
||||
// Into ['Part', 'Part001','Body','Pad','Edge1']
|
||||
std::vector<std::string> subNames;
|
||||
std::string subName;
|
||||
std::istringstream subNameStream(sub);
|
||||
while (std::getline(subNameStream, subName, '.')) {
|
||||
subNames.push_back(subName);
|
||||
}
|
||||
|
||||
// Check if the last character of the input string is the delimiter.
|
||||
// If so, add an empty string to the subNames vector.
|
||||
// Because the last subname is the element name and can be empty.
|
||||
if (!sub.empty() && sub.back() == '.') {
|
||||
subNames.push_back(""); // Append empty string for trailing dot.
|
||||
}
|
||||
|
||||
return subNames;
|
||||
}
|
||||
|
||||
std::string AssemblyObject::getElementFromProp(App::DocumentObject* obj, const char* pName)
|
||||
{
|
||||
std::vector<std::string> names = getSubAsList(obj, pName);
|
||||
@@ -2370,7 +2349,7 @@ App::DocumentObject* AssemblyObject::getMovingPartFromRef(App::DocumentObject* o
|
||||
|
||||
App::Document* doc = obj->getDocument();
|
||||
|
||||
std::vector<std::string> names = splitSubName(sub);
|
||||
std::vector<std::string> names = Base::Tools::splitSubName(sub);
|
||||
names.insert(names.begin(), obj->getNameInDocument());
|
||||
|
||||
bool assemblyPassed = false;
|
||||
|
||||
@@ -280,7 +280,6 @@ public:
|
||||
const char* propName);
|
||||
static std::vector<std::string> getSubAsList(App::PropertyXLinkSub* prop);
|
||||
static std::vector<std::string> getSubAsList(App::DocumentObject* joint, const char* propName);
|
||||
static std::vector<std::string> splitSubName(const std::string& subName);
|
||||
static Base::Placement getPlacementFromProp(App::DocumentObject* obj, const char* propName);
|
||||
|
||||
static Base::Placement getGlobalPlacement(App::DocumentObject* targetObj,
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/Part.h>
|
||||
|
||||
#include <Base/Tools.h>
|
||||
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/CommandT.h>
|
||||
@@ -618,7 +620,7 @@ bool ViewProviderAssembly::getSelectedObjectsWithinAssembly(bool addPreselection
|
||||
|
||||
std::vector<std::string> objsSubNames = selObj.getSubNames();
|
||||
for (auto& subNamesStr : objsSubNames) {
|
||||
std::vector<std::string> subNames = AssemblyObject::splitSubName(subNamesStr);
|
||||
std::vector<std::string> subNames = Base::Tools::splitSubName(subNamesStr);
|
||||
if (subNames.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user