From ae2390fecd48b427ee349edb9a274009a4ee6d1e Mon Sep 17 00:00:00 2001 From: Jan Orend <56254096+3dJan@users.noreply.github.com> Date: Thu, 1 Feb 2024 09:50:54 +0100 Subject: [PATCH] Breaking change: Adding implicit namespace with prefix "i", writing and reading considers the namespace. Writing explicitly the default channel name for volumedata:boundary --- Include/Model/Classes/NMR_ModelConstants.h | 4 +++ .../v100/NMR_ModelWriterNode100_Model.h | 3 +- .../v100/NMR_ModelReaderNode100_Resources.cpp | 10 +++++++ .../Writer/NMR_ModelWriterNode_Implicit.cpp | 29 ++++++++++++------- .../v100/NMR_ModelWriterNode100_Mesh.cpp | 4 +++ .../v100/NMR_ModelWriterNode100_Model.cpp | 8 ++++- 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/Include/Model/Classes/NMR_ModelConstants.h b/Include/Model/Classes/NMR_ModelConstants.h index bc22d2db9..a477d789b 100644 --- a/Include/Model/Classes/NMR_ModelConstants.h +++ b/Include/Model/Classes/NMR_ModelConstants.h @@ -85,6 +85,7 @@ These are given by the 3MF Standard #define XML_3MF_NAMESPACE_DIGITALSIGNATURESPEC "http://www.w3.org/2000/09/xmldsig#" #define XML_3MF_NAMESPACE_CIPHERVALUESPEC "http://www.w3.org/2001/04/xmlenc#" #define XML_3MF_NAMESPACE_VOLUMETRICSPEC "http://schemas.microsoft.com/3dmanufacturing/volumetric/2022/01" +#define XML_3MF_NAMESPACE_IMPLICITSPEC "http://schemas.microsoft.com/3dmanufacturing/implicit/2024/02" #define XML_3MF_NAMESPACEPREFIX_MATERIAL "m" #define XML_3MF_NAMESPACEPREFIX_PRODUCTION "p" @@ -92,6 +93,7 @@ These are given by the 3MF Standard #define XML_3MF_NAMESPACEPREFIX_SLICE "s" #define XML_3MF_NAMESPACEPREFIX_SECURECONTENT "sc" #define XML_3MF_NAMESPACEPREFIX_VOLUMETRIC "v" +#define XML_3MF_NAMESPACEPREFIX_IMPLICIT "i" #define XML_3MF_ATTRIBUTE_XMLNS "xmlns" #define XML_3MF_ATTRIBUTE_PREFIX_XML "xml" @@ -357,6 +359,8 @@ These are given by the 3MF Standard #define XML_3MF_ATTRIBUTE_VOLUMEDATA_BOUNDARY_MESHBBONLY "meshbboxonly" +#define XML_3MF_VOLUMEDATACHANNEL_BOUNDARY_DEFAULT "shape" + // Voumeteric/Implicit #define XML_3MF_ELEMENT_IMPLICIT_FUNCTION "function" diff --git a/Include/Model/Writer/v100/NMR_ModelWriterNode100_Model.h b/Include/Model/Writer/v100/NMR_ModelWriterNode100_Model.h index 0676434c0..5c54fe002 100644 --- a/Include/Model/Writer/v100/NMR_ModelWriterNode100_Model.h +++ b/Include/Model/Writer/v100/NMR_ModelWriterNode100_Model.h @@ -62,8 +62,9 @@ namespace NMR { nfBool m_bIsRootModel; nfBool m_bWriteCustomNamespaces; nfBool m_bWriteVolumetricExtension; + nfBool m_bWriteImplicitExtension; - void writeModelMetaData(); + void writeModelMetaData(); void writeMetaData(_In_ PModelMetaData pMetaData); void writeMetaDataGroup(_In_ PModelMetaDataGroup pMetaDataGroup); diff --git a/Source/Model/Reader/v100/NMR_ModelReaderNode100_Resources.cpp b/Source/Model/Reader/v100/NMR_ModelReaderNode100_Resources.cpp index 8670148d8..74760a48c 100644 --- a/Source/Model/Reader/v100/NMR_ModelReaderNode100_Resources.cpp +++ b/Source/Model/Reader/v100/NMR_ModelReaderNode100_Resources.cpp @@ -166,6 +166,16 @@ namespace NMR { m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ELEMENT), mrwInvalidOptionalValue); } + if (strcmp(pNameSpace, XML_3MF_NAMESPACE_IMPLICITSPEC) == 0) { + if (strcmp(pChildName, XML_3MF_ELEMENT_IMPLICIT_FUNCTION) == 0) + { + PModelReaderNode_ImplicitFunction pXMLNode = std::make_shared(m_pModel, m_pWarnings); + pXMLNode->parseXML(pXMLReader); + } + else + m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ELEMENT), mrwInvalidOptionalValue); + } + } diff --git a/Source/Model/Writer/NMR_ModelWriterNode_Implicit.cpp b/Source/Model/Writer/NMR_ModelWriterNode_Implicit.cpp index 5c24d93f9..2b2eb2e6c 100644 --- a/Source/Model/Writer/NMR_ModelWriterNode_Implicit.cpp +++ b/Source/Model/Writer/NMR_ModelWriterNode_Implicit.cpp @@ -60,7 +60,7 @@ namespace NMR } writeStartElementWithPrefix(XML_3MF_ELEMENT_IMPLICIT_FUNCTION, - XML_3MF_NAMESPACEPREFIX_VOLUMETRIC); + XML_3MF_NAMESPACEPREFIX_IMPLICIT); { writeIntAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_FUNCTION_ID, pFunction->getPackageResourceID()->getModelResourceID()); @@ -107,7 +107,8 @@ namespace NMR { auto name = m_nodeTypes.getNodeType(node.getNodeType()).getName(); - writeStartElement(name.c_str()); + writeStartElementWithPrefix(name.c_str(), + XML_3MF_NAMESPACEPREFIX_IMPLICIT); { writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_NODE_ID, node.getIdentifier()); writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_NODE_DISPLAY_NAME, @@ -145,14 +146,16 @@ namespace NMR auto inputs = node.getInputs(); if (!inputs->empty()) { - writeStartElement(XML_3MF_ELEMENT_IMPLICIT_NODE_INPUT); + writeStartElementWithPrefix(XML_3MF_ELEMENT_IMPLICIT_NODE_INPUT, + XML_3MF_NAMESPACEPREFIX_IMPLICIT); { writeImplicitInputs(*inputs); } writeFullEndElement(); } - writeStartElement(XML_3MF_ELEMENT_IMPLICIT_NODE_OUTPUT); + writeStartElementWithPrefix(XML_3MF_ELEMENT_IMPLICIT_NODE_OUTPUT, + XML_3MF_NAMESPACEPREFIX_IMPLICIT); { auto outputs = node.getOutputs(); writeImplicitOutputs(*outputs); @@ -183,7 +186,8 @@ namespace NMR { for (auto & port : ports) { - writeStartElement(portTypeToRefName(port->getType())); + writeStartElementWithPrefix(portTypeToRefName(port->getType()), + XML_3MF_NAMESPACEPREFIX_IMPLICIT); { writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_PORT_ID, port->getIdentifier()); writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_PORT_DISPLAY_NAME, @@ -214,11 +218,13 @@ namespace NMR void CModelWriterNode_Implicit::writeImplicitFunctionInputs(NMR::Ports & ports) { - writeStartElement(XML_3MF_ELEMENT_IMPLICIT_FUNCTION_INPUT); + writeStartElementWithPrefix(XML_3MF_ELEMENT_IMPLICIT_FUNCTION_INPUT, + XML_3MF_NAMESPACEPREFIX_IMPLICIT); for (auto & port : ports) { - writeStartElement(portTypeToName(port->getType())); + writeStartElementWithPrefix(portTypeToName(port->getType()), + XML_3MF_NAMESPACEPREFIX_IMPLICIT); { writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_PORT_ID, port->getIdentifier()); writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_PORT_DISPLAY_NAME, @@ -231,11 +237,13 @@ namespace NMR void CModelWriterNode_Implicit::writeImplicitFunctionOutputs(NMR::Ports & ports) { - writeStartElement(XML_3MF_ELEMENT_IMPLICIT_FUNCTION_OUTPUT); + writeStartElementWithPrefix(XML_3MF_ELEMENT_IMPLICIT_FUNCTION_OUTPUT, + XML_3MF_NAMESPACEPREFIX_IMPLICIT); for (auto & port : ports) { - writeStartElement(portTypeToRefName(port->getType())); + writeStartElementWithPrefix(portTypeToRefName(port->getType()), + XML_3MF_NAMESPACEPREFIX_IMPLICIT); { writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_PORT_ID, port->getIdentifier()); writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_PORT_DISPLAY_NAME, @@ -252,7 +260,8 @@ namespace NMR { for (auto & port : ports) { - writeStartElement(portTypeToName(port->getType())); + writeStartElementWithPrefix(portTypeToName(port->getType()), + XML_3MF_NAMESPACEPREFIX_IMPLICIT); { writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_PORT_ID, port->getIdentifier()); writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_PORT_DISPLAY_NAME, diff --git a/Source/Model/Writer/v100/NMR_ModelWriterNode100_Mesh.cpp b/Source/Model/Writer/v100/NMR_ModelWriterNode100_Mesh.cpp index 2b1b86a6f..c29cebf9e 100644 --- a/Source/Model/Writer/v100/NMR_ModelWriterNode100_Mesh.cpp +++ b/Source/Model/Writer/v100/NMR_ModelWriterNode100_Mesh.cpp @@ -392,6 +392,10 @@ namespace NMR { { writeStringAttribute(XML_3MF_ATTRIBUTE_VOLUMEDATA_CHANNEL, pBoundary->getChannelName()); } + else + { + writeStringAttribute(XML_3MF_ATTRIBUTE_VOLUMEDATA_CHANNEL, XML_3MF_VOLUMEDATACHANNEL_BOUNDARY_DEFAULT); + } writeStringAttribute(XML_3MF_ATTRIBUTE_VOLUMEDATA_BOUNDARY_MESHBBONLY, pBoundary->getMeshBBoxOnly() ? "true" : "false"); if (pBoundary->getMinFeatureSize() != 0.0) { diff --git a/Source/Model/Writer/v100/NMR_ModelWriterNode100_Model.cpp b/Source/Model/Writer/v100/NMR_ModelWriterNode100_Model.cpp index 237651a85..08ee924d0 100644 --- a/Source/Model/Writer/v100/NMR_ModelWriterNode100_Model.cpp +++ b/Source/Model/Writer/v100/NMR_ModelWriterNode100_Model.cpp @@ -76,6 +76,7 @@ namespace NMR { m_bWriteBaseMaterials = true; m_bWriteObjects = true; m_bWriteVolumetricExtension = true; + m_bWriteImplicitExtension = true; m_bWriteCustomNamespaces = true; @@ -171,6 +172,10 @@ namespace NMR { writeConstPrefixedStringAttribute(XML_3MF_ATTRIBUTE_XMLNS, XML_3MF_NAMESPACEPREFIX_VOLUMETRIC, XML_3MF_NAMESPACE_VOLUMETRICSPEC); } + if (m_bWriteImplicitExtension) { + writeConstPrefixedStringAttribute(XML_3MF_ATTRIBUTE_XMLNS, XML_3MF_NAMESPACEPREFIX_IMPLICIT, XML_3MF_NAMESPACE_IMPLICITSPEC); + } + if (m_bWriteCustomNamespaces) { nfUint32 nNSCount = m_pXMLWriter->GetNamespaceCount(); for (nfUint32 iNSCount = 0; iNSCount < nNSCount; iNSCount++) { @@ -886,8 +891,9 @@ namespace NMR { if (m_bWriteVolumetricExtension) { writeImage3Ds(); writeFunctionsFromImage3D(); + } + if (m_bWriteImplicitExtension) { writeImplicitFunctions(); - } if (m_bWriteObjects) writeObjects();