Skip to content

Commit

Permalink
Breaking change: Adding implicit namespace with prefix "i", writing a…
Browse files Browse the repository at this point in the history
…nd reading considers the namespace. Writing explicitly the default channel name for volumedata:boundary
  • Loading branch information
3dJan committed Feb 1, 2024
1 parent cf554e0 commit ae2390f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Include/Model/Classes/NMR_ModelConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ 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"
#define XML_3MF_NAMESPACEPREFIX_BEAMLATTICE "b"
#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"
Expand Down Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion Include/Model/Writer/v100/NMR_ModelWriterNode100_Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions Source/Model/Reader/v100/NMR_ModelReaderNode100_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CModelReaderNode_ImplicitFunction>(m_pModel, m_pWarnings);
pXMLNode->parseXML(pXMLReader);
}
else
m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ELEMENT), mrwInvalidOptionalValue);
}

}


Expand Down
29 changes: 19 additions & 10 deletions Source/Model/Writer/NMR_ModelWriterNode_Implicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions Source/Model/Writer/v100/NMR_ModelWriterNode100_Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion Source/Model/Writer/v100/NMR_ModelWriterNode100_Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace NMR {
m_bWriteBaseMaterials = true;
m_bWriteObjects = true;
m_bWriteVolumetricExtension = true;
m_bWriteImplicitExtension = true;

m_bWriteCustomNamespaces = true;

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -886,8 +891,9 @@ namespace NMR {
if (m_bWriteVolumetricExtension) {
writeImage3Ds();
writeFunctionsFromImage3D();
}
if (m_bWriteImplicitExtension) {
writeImplicitFunctions();

}
if (m_bWriteObjects)
writeObjects();
Expand Down

0 comments on commit ae2390f

Please sign in to comment.