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:
@@ -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
|
||||
* (&, <, >, ", ').
|
||||
*
|
||||
* \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("&");
|
||||
break;
|
||||
case '<':
|
||||
output.append("<");
|
||||
break;
|
||||
case '>':
|
||||
output.append(">");
|
||||
break;
|
||||
case '"':
|
||||
output.append(""");
|
||||
break;
|
||||
case '\'':
|
||||
output.append("'");
|
||||
break;
|
||||
default:
|
||||
output.push_back(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void XMLTools::terminate()
|
||||
{
|
||||
transcoder.reset();
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user