Skip to content

Commit

Permalink
Toponaming: bring in missing code fragments in Sketcher
Browse files Browse the repository at this point in the history
  • Loading branch information
bgbsww authored and chennes committed May 13, 2024
1 parent 0e24e12 commit 869cb1f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 20 deletions.
81 changes: 61 additions & 20 deletions src/Mod/Sketcher/App/SketchObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9551,45 +9551,86 @@ void SketchObject::setExpression(const App::ObjectIdentifier& path,
}
}

const std::string &SketchObject::internalPrefix()
{
static std::string _prefix("Internal");
return _prefix;
}

const char *SketchObject::convertInternalName(const char *name)
{
if (name && boost::starts_with(name, internalPrefix()))
return name + internalPrefix().size();
return nullptr;
}

std::pair<std::string,std::string> SketchObject::getElementName(
const char *name, ElementNameType type) const
{
// Todo: Toponaming Project March 2024: This method override breaks the sketcher - selection and deletion
// of constraints ceases to work. See #13169. We need to prove that this works before
// enabling it. For now, bypass it.
// enabling it. This appears to be okay now.
#ifndef FC_USE_TNP_FIX
return Part2DObject::getElementName(name,type);

#endif
std::pair<std::string, std::string> ret;
if(!name) return ret;

if(hasSketchMarker(name))
return Part2DObject::getElementName(name,type);

const char *mapped = Data::isMappedElement(name);
Data::IndexedName index = checkSubName(name);
index.appendToStringBuffer(ret.second);
if (auto realName = convertInternalName(ret.second.c_str())) {
Data::MappedElement mappedElement;
// Todo: Do we need to add the InternalShape?
// if (mapped)
// mappedElement = InternalShape.getShape().getElementName(name);
// else if (type == ElementNameType::Export)
// ret.first = getExportElementName(InternalShape.getShape(), realName).first;
// else
// mappedElement = InternalShape.getShape().getElementName(realName);

if (mapped || type != ElementNameType::Export) {
if (mappedElement.index) {
ret.second = internalPrefix();
mappedElement.index.appendToStringBuffer(ret.second);
}
if (mappedElement.name) {
ret.first = Data::ComplexGeoData::elementMapPrefix();
mappedElement.name.appendToBuffer(ret.first);
}
else if (mapped)
ret.first = name;
}

if (ret.first.size()) {
if (auto dot = strrchr(ret.first.c_str(), '.'))
ret.first.resize(dot+1-ret.first.c_str());
else
ret.first += ".";
ret.first += ret.second;
}
if (mapped && (!mappedElement.index || !mappedElement.name))
ret.second.insert(0, Data::MISSING_PREFIX);
return ret;
}

if(!mapped) {
auto occindex = Part::TopoShape::shapeTypeAndIndex(name);
if (occindex.second)
return Part2DObject::getElementName(name,type);

Data::IndexedName index = checkSubName(name);
ret.first = convertSubName(index, true);
if(!Data::isMappedElement(ret.first.c_str()))
ret.first.clear();
index.appendToStringBuffer(ret.second);
return ret;
}

Data::IndexedName index = checkSubName(name);
if(index) {
index.appendToStringBuffer(ret.second);
ret.first = convertSubName(index, true);
if(type==ElementNameType::Export) {
if(boost::starts_with(ret.second,"Vertex"))
ret.second[0] = 'v';
else if(boost::starts_with(ret.second,"Edge"))
ret.second[0] = 'e';
}
if(index && type==ElementNameType::Export) {
if(boost::starts_with(ret.second,"Vertex"))
ret.second[0] = 'v';
else if(boost::starts_with(ret.second,"Edge"))
ret.second[0] = 'e';
}
ret.first = convertSubName(index, true);
if(!Data::isMappedElement(ret.first.c_str()))
ret.first.clear();
return ret;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Sketcher/App/SketchObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,9 @@ class SketcherExport SketchObject: public Part::Part2DObject
return convertSubName(subname.c_str(), postfix);
}

static const std::string& internalPrefix();
static const char* convertInternalName(const char* name);

std::string convertSubName(const Data::IndexedName&, bool postfix = true) const;

std::pair<std::string, std::string> getElementName(const char* name,
Expand Down

0 comments on commit 869cb1f

Please sign in to comment.