Mesh: Add object name attribute to 3MF export

Export mesh object names as 'name' attribute in 3MF files according to
the 3MF specification. This allows downstream tools to identify objects
by their original FreeCAD names.

Changes:
- Moved Exporter::xmlEscape() to Base XMLTools::escapeXml() for shared XML entity escaping
- Update Writer3MF::AddMesh() to accept and output object names with default "" where no attribute will be added
- Updated all codepaths leading to 3mf exports to include the object name
This commit is contained in:
Tom Stein
2026-01-21 16:23:27 +01:00
committed by Chris Hennes
parent 44fd6754d8
commit 49c80ebe5c
7 changed files with 56 additions and 23 deletions

View File

@@ -117,6 +117,44 @@ std::basic_string<XMLCh> XMLTools::toXMLString(const char* const fromTranscode)
return str;
}
/*!
* \brief Escape special XML characters in a string.
*
* Replaces XML special characters (&, <, >, ", ') with their entity equivalents
* (&amp;, &lt;, &gt;, &quot;, &apos;).
*
* \param input The string to escape
* \return The escaped string safe for use in XML content or attributes
*/
std::string XMLTools::escapeXml(const std::string& input)
{
std::string output;
output.reserve(input.size());
for (char ch : input) {
switch (ch) {
case '&':
output.append("&amp;");
break;
case '<':
output.append("&lt;");
break;
case '>':
output.append("&gt;");
break;
case '"':
output.append("&quot;");
break;
case '\'':
output.append("&apos;");
break;
default:
output.push_back(ch);
break;
}
}
return output;
}
void XMLTools::terminate()
{
transcoder.reset();

View File

@@ -47,6 +47,7 @@ class BaseExport XMLTools
public:
static std::string toStdString(const XMLCh* const toTranscode);
static std::basic_string<XMLCh> toXMLString(const char* const fromTranscode);
static std::string escapeXml(const std::string& input);
static void initialize();
static void terminate();