Toponaming: refactor getExportElementName to separate method

This commit is contained in:
bgbsww
2024-07-18 09:25:54 -04:00
parent 52294ce8c1
commit 16b8d99d62
3 changed files with 19 additions and 10 deletions

View File

@@ -148,8 +148,12 @@ std::pair<std::string, std::string> Feature::getElementName(const char* name,
if (!prop) {
return App::GeoFeature::getElementName(name, type);
}
return getExportElementName(prop->getShape(), name);
}
TopoShape shape = prop->getShape();
std::pair<std::string, std::string> Feature::getExportElementName(TopoShape shape,
const char* name) const
{
Data::MappedElement mapped = shape.getElementName(name);
auto res = shape.shapeTypeAndIndex(mapped.index);
static const int MinLowerTopoNames = 3;
@@ -259,10 +263,10 @@ std::pair<std::string, std::string> Feature::getElementName(const char* name,
// disambiguation.
auto it = std::find(ancestors.begin(), ancestors.end(), res.second);
if (it == ancestors.end()) {
assert(0 && "ancestor not found"); // this shouldn't happened
assert(0 && "ancestor not found"); // this shouldn't happen
}
else {
op = Data::POSTFIX_TAG + std::to_string(it - ancestors.begin());
op = Data::POSTFIX_INDEX + std::to_string(it - ancestors.begin());
}
}
@@ -284,10 +288,8 @@ std::pair<std::string, std::string> Feature::getElementName(const char* name,
}
}
}
return App::GeoFeature::_getElementName(name, mapped);
}
if (!res.second && mapped.name) {
else if (!res.second && mapped.name) {
const char* dot = strchr(name, '.');
if (dot) {
++dot;
@@ -350,7 +352,6 @@ std::pair<std::string, std::string> Feature::getElementName(const char* name,
if (ancestors.size() == 1) {
idxName.setIndex(ancestors.front());
mapped.index = idxName;
return App::GeoFeature::_getElementName(name, mapped);
}
}
}

View File

@@ -171,6 +171,17 @@ protected:
void registerElementCache(const std::string &prefix, PropertyPartShape *prop);
/** Helper function to obtain mapped and indexed element name from a shape
* @params shape: source shape
* @param name: the input name, can be either mapped or indexed name
* @return Returns both the indexed and mapped name
*
* If the 'name' referencing a non-primary shape type, i.e. not
* Vertex/Edge/Face, this function will auto generate a name from primary
* sub-shapes.
*/
std::pair<std::string,std::string> getExportElementName(TopoShape shape, const char *name) const;
/**
* Build a history of changes
* MakeShape: The operation that created the changes, e.g. BRepAlgoAPI_Common

View File

@@ -59,10 +59,7 @@ void ExternalGeometryExtension::restoreAttributes(Base::XMLReader& reader)
void ExternalGeometryExtension::saveAttributes(Base::Writer& writer) const
{
Part::GeometryPersistenceExtension::saveAttributes(writer);
// For compatibility with upstream FreeCAD, always save 'Ref' and 'Flags'.
// if (Ref.size())
writer.Stream() << "\" Ref=\"" << Base::Persistence::encodeAttribute(Ref);
// if (Flags.any())
writer.Stream() << "\" Flags=\"" << Flags.to_ulong();
if (RefIndex >= 0) {
writer.Stream() << "\" RefIndex=\"" << RefIndex;