Toponaming/Part: trasnfer in getElementName
This commit is contained in:
@@ -4054,6 +4054,87 @@ Data::MappedName TopoShape::setElementComboName(const Data::IndexedName& element
|
||||
return elementMap()->setElementName(element, newName, Tag, &sids);
|
||||
}
|
||||
|
||||
std::vector<Data::MappedName>
|
||||
TopoShape::decodeElementComboName(const Data::IndexedName &element,
|
||||
const Data::MappedName &name,
|
||||
const char *marker,
|
||||
std::string *postfix) const
|
||||
{
|
||||
std::vector<Data::MappedName> names;
|
||||
if (!element)
|
||||
return names;
|
||||
if (!marker)
|
||||
marker = "";
|
||||
int plen = (int)elementMapPrefix().size();
|
||||
int markerLen = strlen(marker);
|
||||
int len;
|
||||
int pos = name.findTagInElementName(nullptr, &len);
|
||||
if (pos < 0) {
|
||||
// It is possible to encode combo name without using a tag, e.g.
|
||||
// Sketcher object creates wire using edges that are created by itself,
|
||||
// so there will be no tag to encode.
|
||||
//
|
||||
// In this case, just search for the brackets
|
||||
len = name.find("(");
|
||||
if (len < 0) {
|
||||
// No bracket is also possible, if there is only one name in the combo
|
||||
pos = len = name.size();
|
||||
} else {
|
||||
pos = name.find(")");
|
||||
if (pos < 0) {
|
||||
// non closing bracket?
|
||||
return {};
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
if (len <= (int)markerLen)
|
||||
return {};
|
||||
len -= markerLen+plen;
|
||||
}
|
||||
|
||||
if (name.find(elementMapPrefix(), len) != len
|
||||
|| name.find(marker, len+plen) != len+plen)
|
||||
return {};
|
||||
|
||||
names.emplace_back(name, 0, len);
|
||||
|
||||
std::string text;
|
||||
len += plen + markerLen;
|
||||
name.toString(text, len, pos-len);
|
||||
|
||||
if (this->Hasher) {
|
||||
if (auto id = App::StringID::fromString(names.back().toRawBytes())) {
|
||||
if (App::StringIDRef sid = this->Hasher->getID(id)) {
|
||||
names.pop_back();
|
||||
names.emplace_back(sid);
|
||||
}
|
||||
else
|
||||
return names;
|
||||
}
|
||||
if (auto id = App::StringID::fromString(text.c_str())) {
|
||||
if (App::StringIDRef sid = this->Hasher->getID(id))
|
||||
text = sid.dataToText();
|
||||
else
|
||||
return names;
|
||||
}
|
||||
}
|
||||
if (text.empty() || text[0] != '(')
|
||||
return names;
|
||||
auto endPos = text.rfind(')');
|
||||
if (endPos == std::string::npos)
|
||||
return names;
|
||||
|
||||
if (postfix)
|
||||
*postfix = text.substr(endPos+1);
|
||||
|
||||
text.resize(endPos);
|
||||
std::istringstream iss(text.c_str()+1);
|
||||
std::string token;
|
||||
while(std::getline(iss, token, '|'))
|
||||
names.emplace_back(token);
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorient the outer and inner wires of the TopoShape
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user